Пример #1
0
MIDIClient::MIDIClient(CFStringRef name, bool verbose) {
    this->debuggingEnabled = verbose;
    
    _c(MIDIClientCreate, MIDIClientCreate(name, &MIDIClient::MIDINotifyProc, this, &client))
    _c(MIDIInputPortCreate, MIDIInputPortCreate(client, name, &MIDIClient::MIDIReadProc, this, &inPort));
    _c(MIDIOutputPortCreate, MIDIOutputPortCreate(client, name, &outPort));
}
void setupMIDI(MyMIDIPlayer *player) {
	
	MIDIClientRef client;
	CheckError (MIDIClientCreate(CFSTR("Core MIDI to System Sounds Demo"), MyMIDINotifyProc, player, &client),
				"Couldn't create MIDI client");
	
	MIDIPortRef inPort;
	CheckError (MIDIInputPortCreate(client, CFSTR("Input port"), MyMIDIReadProc, player, &inPort),
				"Couldn't create MIDI input port");
	
	unsigned long sourceCount = MIDIGetNumberOfSources();
	printf ("%ld sources\n", sourceCount);
	for (int i = 0; i < sourceCount; ++i) {
		MIDIEndpointRef src = MIDIGetSource(i);
		CFStringRef endpointName = NULL;
		CheckError(MIDIObjectGetStringProperty(src, kMIDIPropertyName, &endpointName),
				   "Couldn't get endpoint name");
		char endpointNameC[255];
		CFStringGetCString(endpointName, endpointNameC, 255, kCFStringEncodingUTF8);
		printf("  source %d: %s\n", i, endpointNameC);
		CheckError (MIDIPortConnectSource(inPort, src, NULL),
					"Couldn't connect MIDI port");
	}
	
	
}
Пример #3
0
MidiInput::MidiInput(std::vector<unsigned int> sources)
{
	if(OSStatus status = MIDIClientCreate(CFSTR("March"), 0, 0, &_midi_client))
	{   
		std::cerr << "Couldn't create MIDI client: " << status << std::endl;
#ifdef GetMacOSStatusErrorString
		std::cerr << GetMacOSStatusErrorString(status) << std::endl;
#endif
		throw "Couldn't create MIDI client.";
	}   

	if(OSStatus status = MIDIInputPortCreate(_midi_client, CFSTR("March Input"), MidiInput::read, this, &_midi_in))
	{
		std::cerr << "Couldn't create MIDI input port: " << status << std::endl;
#ifdef GetMacOSStatusErrorString
		std::cerr << GetMacOSStatusErrorString(status) << std::endl;
#endif
		throw "Couldn't create MIDI input port.";
	}

	for(std::vector<unsigned int>::iterator it = sources.begin(); it != sources.end(); it++)
	{
		MIDIEndpointRef src = MIDIGetSource(*it);
		std::cout << "Using source " << *it << " (" << sourceName(src) << ", " << sourceModel(src) << ", " << sourceManufacturer(src) << ")" << std::endl;
		MIDIPortConnectSource(_midi_in, src, 0);
	}
}
Пример #4
0
int macosx_midi_setup(void)
{
	static struct midi_driver driver;

	memset(&driver,0,sizeof(driver));
	driver.flags = MIDI_PORT_CAN_SCHEDULE;
	driver.poll = _macosx_poll;
	driver.thread = NULL;
	driver.enable = _macosx_start;
	driver.disable = _macosx_stop;
	driver.send = _macosx_send;
	driver.drain = _macosx_drain;

	if (MIDIClientCreate(CFSTR("Schism Tracker"), NULL, NULL, &client) != noErr) {
		return 0;
	}
	if (MIDIInputPortCreate(client, CFSTR("Input port"), readProc, NULL, &portIn) != noErr) {
		return 0;
	}
	if (MIDIOutputPortCreate(client, CFSTR("Output port"), &portOut) != noErr) {
		return 0;
	}

	if (!midi_provider_register("Mac OS X", &driver)) return 0;

	return 1;
}
static void midiInit() {
    if (client) {
        return;
    }

    OSStatus err = noErr;

    err = MIDIClientCreate(CFSTR("MIDI Client"), NULL, NULL, &client);
    if (err != noErr) { goto Exit; }

    // This just creates an input port through which the client may receive
    // incoming MIDI messages from any MIDI source.
    err = MIDIInputPortCreate(client, CFSTR("MIDI Input Port"), midiReadProc, NULL, &inPort);
    if (err != noErr) { goto Exit; }

    err = MIDIOutputPortCreate(client, CFSTR("MIDI Output Port"), &outPort);
    if (err != noErr) { goto Exit; }

Exit:
    if (err != noErr) {
        const char* s = MIDI_Utils_GetErrorMsg(err);
        if (s != NULL) {
            printf("%s\n", s);
        }
    }
}
Пример #6
0
int main(void) {

   // Prepare MIDI Interface Client/Port for writing MIDI data:
   MIDIClientRef midiclient;
   MIDIPortRef   midiin;
   OSStatus status;
   if (status = MIDIClientCreate(CFSTR("TeStInG"), NULL, NULL, &midiclient)) {
      printf("Error trying to create MIDI Client structure: %d\n", status);
      printf("%s\n", GetMacOSStatusErrorString(status));
      exit(status);
   }
   if (status = MIDIInputPortCreate(midiclient, CFSTR("InPuT"), myReadProc, 
         NULL, &midiin)) {
      printf("Error trying to create MIDI output port: %d\n", status);
      printf("%s\n", GetMacOSStatusErrorString(status));
      exit(status);
   }

   ItemCount nSrcs = MIDIGetNumberOfSources();
   ItemCount iSrc;
   for (iSrc=0; iSrc<nSrcs; iSrc++) {
      MIDIEndpointRef src = MIDIGetSource(iSrc);
      MIDIPortConnectSource(midiin, src, NULL);
   }
   t = lo_address_new(NULL, "7777");

   CFRunLoopRef runLoop;
   runLoop = CFRunLoopGetCurrent();
   CFRunLoopRun();

   return 0;
}
Пример #7
0
Error MIDIDriverCoreMidi::open() {

	CFStringRef name = CFStringCreateWithCString(NULL, "Godot", kCFStringEncodingASCII);
	OSStatus result = MIDIClientCreate(name, NULL, NULL, &client);
	CFRelease(name);
	if (result != noErr) {
		ERR_PRINTS("MIDIClientCreate failed, code: " + itos(result));
		return ERR_CANT_OPEN;
	}

	result = MIDIInputPortCreate(client, CFSTR("Godot Input"), MIDIDriverCoreMidi::read, (void *)this, &port_in);
	if (result != noErr) {
		ERR_PRINTS("MIDIInputPortCreate failed, code: " + itos(result));
		return ERR_CANT_OPEN;
	}

	int sources = MIDIGetNumberOfSources();
	for (int i = 0; i < sources; i++) {

		MIDIEndpointRef source = MIDIGetSource(i);
		if (source) {
			MIDIPortConnectSource(port_in, source, (void *)this);
			connected_sources.insert(i, source);
		}
	}

	return OK;
}
Пример #8
0
int initMIDI(int numIn, int numOut)
{
	midiCleanUp();
	numIn = sc_clip(numIn, 1, kMaxMidiPorts);
	numOut = sc_clip(numOut, 1, kMaxMidiPorts);

	int enc = kCFStringEncodingMacRoman;
	CFAllocatorRef alloc = CFAllocatorGetDefault();

	CFStringRef clientName = CFStringCreateWithCString(alloc, "SuperCollider", enc);

	OSStatus err = MIDIClientCreate(clientName, midiNotifyProc, nil, &gMIDIClient);
	if (err) {
		post("Could not create MIDI client. error %d\n", err);
		return errFailed;
	}
	CFRelease(clientName);

	for (int i=0; i<numIn; ++i) {
		char str[32];
		sprintf(str, "in%d\n", i);
		CFStringRef inputPortName = CFStringCreateWithCString(alloc, str, enc);

		err = MIDIInputPortCreate(gMIDIClient, inputPortName, midiReadProc, &i, gMIDIInPort+i);
		if (err) {
			gNumMIDIInPorts = i;
			post("Could not create MIDI port %s. error %d\n", str, err);
			return errFailed;
		}
		CFRelease(inputPortName);
	}

	/*int n = MIDIGetNumberOfSources();
	printf("%d sources\n", n);
	for (i = 0; i < n; ++i) {
		MIDIEndpointRef src = MIDIGetSource(i);
		MIDIPortConnectSource(inPort, src, NULL);
	}*/

	gNumMIDIInPorts = numIn;

	for (int i=0; i<numOut; ++i) {
		char str[32];
		sprintf(str, "out%d\n", i);
		CFStringRef outputPortName = CFStringCreateWithCString(alloc, str, enc);

		err = MIDIOutputPortCreate(gMIDIClient, outputPortName, gMIDIOutPort+i);
		if (err) {
			gNumMIDIOutPorts = i;
			post("Could not create MIDI out port. error %d\n", err);
			return errFailed;
		}

		CFRelease(outputPortName);
	}
	gNumMIDIOutPorts = numOut;
	return errNone;
}
Пример #9
0
// ----------------------------------------------------------
ofxAudioUnitMidiReceiver::ofxAudioUnitMidiReceiver(string clientName)
: _client(NULL), _endpoint(NULL), _port(NULL), _unit(NULL)
// ----------------------------------------------------------
{
	CFStringRef cName = CFStringCreateWithCString(kCFAllocatorDefault, clientName.c_str(), kCFStringEncodingUTF8);
	OFXAU_PRINT(MIDIClientCreate(cName, ofxAudioUnitMidiInputProc, this, &_client), 
				"creating MIDI client");
	CFRelease(cName);
}
Пример #10
0
MIDIClientRef CoreMIDI_CreateClient(CFStringRef name)
{
    MIDIClientRef client = NULL;

    if (MIDIClientCreate(name, NULL /* FIXME use notify proc */, NULL, &client) != noErr)
        return NULL;

    return client;
}
Пример #11
0
Файл: midi.c Проект: huangjs/cl
int mus_midi_open_write(const char *name)
{
  init_midi();
  if (us == NULL) 
    MIDIClientCreate(CFSTR("MIDI Write"), NULL, NULL, &us);
  if (outp == NULL)
    MIDIOutputPortCreate(us, CFSTR("Output port"), &outp);
  return(1);
}
Пример #12
0
MidiEnumeratorPrivate::MidiEnumeratorPrivate(MidiEnumerator* parent)
    : QObject(parent)
{
    qDebug() << Q_FUNC_INFO;

    OSStatus s = MIDIClientCreate(CFSTR("QLC MIDI Plugin"), onMIDINotify, this, &m_client);
    if (s != 0)
        qWarning() << Q_FUNC_INFO << "Unable to create a MIDI client!";
}
Пример #13
0
Файл: midi.c Проект: huangjs/cl
int mus_midi_open_read(const char *name)
{
  init_midi();
  if (us == NULL) 
    MIDIClientCreate(CFSTR("MIDI Read"), NULL, NULL, &us);
  if (inp == NULL)
    MIDIInputPortCreate(us, CFSTR("Input port"), midi_read_callback, NULL, &inp);
  MIDIPortConnectSource(inp, MIDIGetSource(0), NULL);
  return(0);
}
Пример #14
0
void _lp_ctx_create() {
    if(!_lp_ctx.client)
        MIDIClientCreate(CFSTR("liblunchpad"), _lp_midi_cb, NULL, &_lp_ctx.client);
    
    if(!_lp_ctx.inport)
        MIDIInputPortCreate(_lp_ctx.client, CFSTR("liblunchpad-in"), _lp_msg_in_cb, NULL, &_lp_ctx.inport);
    
    if(!_lp_ctx.outport)
        MIDIOutputPortCreate(_lp_ctx.client, CFSTR("liblunchpad-out"), &_lp_ctx.outport);
}
Пример #15
0
MIDIClientRef MidiApple::getMidiClientRef()
{
	if(mClient==0)
	{
		CFStringRef deviceClientName = CFSTR("MIDI In Device Client");
		MIDIClientCreate(deviceClientName, NotifyCallback, this, &mClient);
		CFRelease(deviceClientName);
	}
	return mClient;
}
Пример #16
0
MidiIn::MidiIn(int index, MIDIINCALLBACK callback) :
    callback(callback), handle(0)
{
    if (!midiInClient)
        MIDIClientCreate(CFSTR("OPA Editor"), NULL, NULL, &midiInClient);
    MIDIPortRef port;
    MIDIInputPortCreate(midiInClient, CFSTR("input"), coreMIDIListener, this, &port);
    fflush(stdout);
    MIDIPortConnectSource(port, MIDIGetSource(index), (void *) index);
    handle = (uint64_t) port;
}
Пример #17
0
void CoreMidiManager::InitializeMIDI()
{
  midimsg_attempt(MIDIClientCreate
		  (CFStringCreateWithCString(NULL, "Manta", kCFStringEncodingASCII), 
		   NULL, NULL, &m_midiclient), "creating OS-X MIDI client object.");
  
  midimsg_attempt(MIDISourceCreate
		  (m_midiclient, 
		   CFStringCreateWithCString(NULL, "Manta", kCFStringEncodingASCII), 
		   &m_midiendpoint), "creating OS-X virtual MIDI source.");
}
Пример #18
0
CoreMidiDriver::CoreMidiDriver()
		: MidiInput( __class_name ) ,MidiOutput( __class_name ), Object( __class_name )
		, m_bRunning( false )
{
	INFOLOG( "INIT" );
	OSStatus err = noErr;

	QString sMidiPortName = Preferences::get_instance()->m_sMidiPortName;
	err = MIDIClientCreate ( CFSTR( "h2MIDIClient" ), NULL, NULL, &h2MIDIClient );
	err = MIDIInputPortCreate ( h2MIDIClient, CFSTR( "h2InputPort" ), midiProc, this, &h2InputRef );
	err = MIDIOutputPortCreate ( h2MIDIClient, CFSTR( "h2OutputPort" ), &h2OutputRef );
}
Пример #19
0
void MIDIOut::init()
{
    OSStatus s;

    m_client = NULL;
    s = MIDIClientCreate(CFSTR("QLC MIDI Output Plugin"), NULL, NULL,
                         &m_client);
    if (s != 0)
        qWarning() << "Unable to create a MIDI Client!";
    else
        rescanDevices();
}
Пример #20
0
bool Midi_CoreMidi::start() {
  OSStatus err;
  MIDIPortRef mport;
  err = MIDIClientCreate(CFSTR("murth"), 0, NULL, &mcli);
  CHECK_ERR("MIDIClientCreate");
  err = MIDIInputPortCreate(mcli, CFSTR("input"), midiread_cb, this, &mport);
  CHECK_ERR("MIDIInputPortCreate");
  
  unsigned long midi_sources = MIDIGetNumberOfSources();
  for (int i = 0; i < midi_sources; ++i)
    MIDIPortConnectSource(mport, MIDIGetSource(i), 0);
  return true;
}
Пример #21
0
    static MIDIClientRef getGlobalMidiClient()
    {
        static MIDIClientRef globalMidiClient = 0;

        if (globalMidiClient == 0)
        {
            // Since OSX 10.6, the MIDIClientCreate function will only work
            // correctly when called from the message thread!
            jassert (MessageManager::getInstance()->isThisTheMessageThread());

            CoreMidiHelpers::ScopedCFString name;
            name.cfString = getGlobalMidiClientName().toCFString();
            CHECK_ERROR (MIDIClientCreate (name.cfString, &globalSystemChangeCallback, nullptr, &globalMidiClient));
        }

        return globalMidiClient;
    }
Пример #22
0
MIDIChango::MIDIChango(Mahalo *M){

  fprintf(stderr,"DOING THE MIDI THING!\n");
  MIDIClientRef client;
  MIDIClientCreate(
  CFStringCreateWithCString(NULL, "D-Ball's Client", kCFStringEncodingASCII),
  NULL,
  NULL,
  &client);

  MIDIOutputPortCreate(client, CFSTR("My output port"), &outputPort);
  for(int i = 0 ; i < 6; i++){
    eps[i] = MIDIGetDestination(i);
  }


}
Пример #23
0
    static MIDIClientRef getGlobalMidiClient()
    {
        static MIDIClientRef globalMidiClient = 0;

        if (globalMidiClient == 0)
        {
            // Since OSX 10.6, the MIDIClientCreate function will only work
            // correctly when called from the message thread!
            jassert (MessageManager::getInstance()->isThisTheMessageThread());

            CFStringRef name = getGlobalMidiClientName().toCFString();
            CHECK_ERROR (MIDIClientCreate (name, &globalSystemChangeCallback, 0, &globalMidiClient));
            CFRelease (name);
        }

        return globalMidiClient;
    }
Пример #24
0
    MIDIClientRef getGlobalMidiClient()
    {
        static MIDIClientRef globalMidiClient = 0;

        if (globalMidiClient == 0)
        {
            String name ("JUCE");

            if (JUCEApplication::getInstance() != 0)
                name = JUCEApplication::getInstance()->getApplicationName();

            CFStringRef appName = PlatformUtilities::juceStringToCFString (name);
            CHECK_ERROR (MIDIClientCreate (appName, 0, 0, &globalMidiClient));
            CFRelease (appName);
        }

        return globalMidiClient;
    }
Пример #25
0
void OpenMIDIHardware(MADDriverRec *rec)
{
	if(MIDIHardware || MIDIHardwareAlreadyOpen == FALSE) {
		OSStatus MIDIErr = MIDIClientCreate(CFSTR("PlayerPRO"), MADMIDINotifyProc, rec, &MADMIDICliRef);
		if(MIDIErr == noErr) {
			MIDIHardware = TRUE;
			MIDIHardwareAlreadyOpen = TRUE;
			MIDIErr = MIDIInputPortCreate(MADMIDICliRef, CFSTR("PlayerPRO Keyboard In"), MADMIDIPortProc, rec, &MADMIDIPortInRef);
			if (MIDIErr == noErr) {
				MIDIErr = MIDIDestinationCreate(MADMIDICliRef, CFSTR("PlayerPRO destination"), MADMIDIPortProc, rec, &MADMIDIKeyboardEndRef);
			}
			if (MIDIErr == noErr) {
				MIDIErr = MIDIPortConnectSource(MADMIDIPortInRef, MADMIDIKeyboardEndRef, rec);
			}
		} else
			MIDIHardware = FALSE;
	}
}
Пример #26
0
void Input::initialize()
{
	MIDIEndpointRef source = NULL;
	
	ItemCount sourceCount = MIDIGetNumberOfSources();
	for (ItemCount i = 0; i < sourceCount; i++) {
		MIDIEndpointRef src = MIDIGetSource(i);
		source = src;
		break;
	}
	if (source) {
		MIDIClientRef client;
		MIDIClientCreate(CFSTR("Greg"), Input::notifyProc, NULL, &client);
		MIDIPortRef inputPort;
		MIDIInputPortCreate(client, CFSTR("Greg Input"), Input::readProc, NULL, &inputPort);
		MIDIPortConnectSource(inputPort, source, NULL);
	}
}
Пример #27
0
//------------------------------------------------------------------------
bool TJackSynchro::Open()
{
    OSStatus err;

    if ((fClient = jack_client_new("JackSynchro")) == 0) {
        fprintf (stderr, "jack server not running?\n");
        return false;
    }

    jack_set_process_callback(fClient, Process, this);
    jack_set_sync_callback(fClient, SyncCallback, this);
    jack_on_shutdown(fClient, Shutdown, 0);

    if (jack_activate(fClient)) {
        fprintf (stderr, "cannot activate client");
        return false;
    }

    DBUG(("MIDIClientCreate \n"));
    err = MIDIClientCreate(CFSTR("JAS Sync"), NotifyProc, NULL, &fMidiClient);
    if (!fClient) {
        printf("Can not open Midi client\n");
        goto error;
    }

    err = MIDIDestinationCreate(fMidiClient, CFSTR("Jack Sync In"), ReadSyncProc, this, &fDestination);
    if (!fDestination) {
        printf("Can not open create destination \n");
        goto error;
    }
    DBUG(("MIDIDestinationCreate OK\n"));

    DBUG(("MIDISourceCreate \n"));
    err = MIDISourceCreate(fMidiClient, CFSTR("Jack Sync Out"), &fSource);
    if (!fSource) {
        printf("Can not open create source \n");
        goto error;
    }
    return true;

error:
    Close();
    return false;
}
Пример #28
0
static VALUE t_create_client(VALUE self, VALUE client_name)
{    
    VALUE midiclient_instance = rb_class_new_instance(0, 0, cMIDIClient);
    if( midiclient_instance == Qnil )
    {
        free_objects();
        rb_fatal("Couldn't create an instance of MIDIClient!");
    }
    
    MIDIClientRef midi_client;
    
    CFStringRef client_str = CFStringCreateWithCString(kCFAllocatorDefault, RSTRING(client_name)->as.heap.ptr, kCFStringEncodingASCII);
    MIDIClientCreate(client_str, NULL, NULL, &midi_client);
    CFRelease(client_str);
    
    RbMIDIClient* client_struct;
    Data_Get_Struct(midiclient_instance, RbMIDIClient, client_struct);
    
    client_struct->client = midi_client;
    
    return midiclient_instance;
}
Пример #29
0
int main(int argc, char * argv[])
{
	// open MIDI ports and wire them up
	CFStringRef strName = CFStringCreateWithCString(NULL, "Launchpad Pro Simulator", kCFStringEncodingASCII);
	if (noErr == MIDIClientCreate(strName, NULL, NULL, &g_client))
	{
		CFRelease(strName);
	}
	else
	{
		// failed to open MIDI client
		return -1;
	}
	
	if (findLaunchpadPro())
	{
		// no Launchpad Pro connected
		return -2;
	}

	// now start things up
	app_init();
	
    // start a timer loop
    CFRunLoopSourceContext source_context;
    bzero(&source_context, sizeof(source_context));
    CFRunLoopSourceRef source = CFRunLoopSourceCreate(NULL, 0, & source_context);
    CFRunLoopAddSource(CFRunLoopGetCurrent(), source, kCFRunLoopCommonModes);
    
    CFRunLoopTimerContext timer_context;
    bzero(&timer_context, sizeof(timer_context));
    timer_context.info = source;
    CFRunLoopTimerRef timer = CFRunLoopTimerCreate(NULL, CFAbsoluteTimeGetCurrent(), TIMER_INTERVAL_S, 0, 0, timerCallback, &timer_context);
    CFRunLoopAddTimer(CFRunLoopGetCurrent(), timer, kCFRunLoopCommonModes);
    
    CFRunLoopRun();
    
    return EXIT_SUCCESS;
}
Пример #30
0
MidiDriver_CoreMIDI::MidiDriver_CoreMIDI()
	: mClient(0), mOutPort(0), mDest(0) {

	OSStatus err;
	err = MIDIClientCreate(CFSTR("ScummVM MIDI Driver for OS X"), NULL, NULL, &mClient);
}