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); } } }
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; }
// Create a new Output Port and saves the Ruby Callback proc. static VALUE t_create_output_port(VALUE self, VALUE client_instance, VALUE port_name) { MIDIPortRef out_port; RbMIDIClient* client; Data_Get_Struct(client_instance, RbMIDIClient, client); CFStringRef port_str = CFStringCreateWithCString(kCFAllocatorDefault, RSTRING(port_name)->ptr, kCFStringEncodingASCII); MIDIOutputPortCreate(client->client, port_str, &out_port); CFRelease(port_str); VALUE outputport_instance = rb_class_new_instance(0, 0, cOutputPort); if( outputport_instance == Qnil ) { free_objects(); rb_fatal("Couldn't create an instance of OutputPort!"); } RbOutputPort* port_struct; Data_Get_Struct(outputport_instance, RbOutputPort, port_struct); port_struct->output_port = out_port; return outputport_instance; }
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)); }
static int findLaunchpadPro() { // find the input hardware port for (ItemCount i=0; i < MIDIGetNumberOfSources(); ++i) { MIDIEndpointRef endpoint = MIDIGetSource(i); if (endpoint) { // get the endpoint name (always available) CFStringRef endpointName = NULL; if (noErr != MIDIObjectGetStringProperty(endpoint, kMIDIPropertyName, &endpointName)) { return -1; } if (CFStringCompare(endpointName, CFSTR("Standalone Port"), kCFCompareCaseInsensitive) == 0) { // found it! open the endpoint. if (noErr != MIDIInputPortCreate(g_client, CFSTR("In"), readProc, NULL, &g_inDevPort)) { return -1; } if (noErr != MIDIPortConnectSource(g_inDevPort, endpoint, NULL)) { return -1; } } } } // now find the output for (ItemCount i=0; i < MIDIGetNumberOfDestinations(); ++i) { MIDIEndpointRef endpoint = MIDIGetDestination(i); if (endpoint) { // get the endpoint name (always available) CFStringRef endpointName = NULL; if (noErr != MIDIObjectGetStringProperty(endpoint, kMIDIPropertyName, &endpointName)) { return -1; } if (CFStringCompare(endpointName, CFSTR("Standalone Port"), kCFCompareCaseInsensitive) == 0) { // found it! open the endpoint. if (noErr != MIDIOutputPortCreate(g_client, CFSTR("Out"), &g_outDevPort)) { return -1; } g_outDevEndpoint = endpoint; } } } return !(g_inDevPort && g_outDevPort); }
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; }
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); }
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); }
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 ); }
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); } }
/** * @brief Create a MIDIDriverCoreMIDI instance. * Allocate space and initialize an MIDIDriverCoreMIDI instance. * @public @memberof MIDIDriverCoreMIDI * @return a pointer to the created driver structure on success. * @return a @c NULL pointer if the driver could not created. */ struct MIDIDriverCoreMIDI * MIDIDriverCoreMIDICreate( char * name, MIDIClientRef client ) { struct MIDIDriverCoreMIDI * driver; CFStringRef in_name, out_name; driver = malloc( sizeof( struct MIDIDriverCoreMIDI ) ); MIDIPrecondReturn( driver != NULL, ENOMEM, NULL ); MIDIDriverInit( &(driver->base), name, COREMIDI_CLOCK_RATE ); driver->client = client; in_name = CFStringCreateWithFormat( NULL, NULL, CFSTR("MIDIKit %s input"), name ); out_name = CFStringCreateWithFormat( NULL, NULL, CFSTR("MIDIKit %s input"), name ); MIDIInputPortCreate( client, in_name, &_coremidi_readproc, driver, &(driver->cm_in_port) ); MIDIOutputPortCreate( client, out_name, &(driver->cm_out_port) ); return driver; }
void CoreMidiOutputDevice::open() { qDebug() << Q_FUNC_INFO; // Don't open twice if (m_outPort != 0) return; OSStatus s = MIDIOutputPortCreate(m_client, CFSTR("QLC Input Port"), &m_outPort); if (s != 0) { qWarning() << Q_FUNC_INFO << "Unable to make an output port for" << name() << ":" << s; m_outPort = 0; } else { m_destination = MIDIEntityGetDestination(m_entity, 0); } }
/***************************************************************************** * File operations *****************************************************************************/ bool MIDIDevice::open() { MIDIOut* plugin; OSStatus s; plugin = qobject_cast<MIDIOut*> (parent()); Q_ASSERT(plugin != 0); /* Don't open twice */ if (m_outPort != 0) return true; /* Use the first destination */ if (MIDIEntityGetNumberOfDestinations(m_entity) > 0) { /* Make an output port */ s = MIDIOutputPortCreate(plugin->client(), CFSTR("QLC Output Port"), &m_outPort); if (s != 0) { qWarning() << "Unable to make an output port for" << name() << s; m_outPort = 0; m_destination = 0; } else { /* Use the first destination */ m_destination = MIDIEntityGetDestination(m_entity, 0); } return true; } else { m_outPort = 0; m_destination = 0; qWarning() << "MIDI entity has no destinations"; return false; } }
int MidiDriver_CoreMIDI::open() { if (mDest) return MERR_ALREADY_OPEN; OSStatus err = noErr; mOutPort = 0; int dests = MIDIGetNumberOfDestinations(); if (dests > 0 && mClient) { mDest = MIDIGetDestination(0); err = MIDIOutputPortCreate( mClient, CFSTR("scummvm_output_port"), &mOutPort); } else { return MERR_DEVICE_NOT_AVAILABLE; } if (err != noErr) return MERR_CANNOT_CONNECT; return 0; }
void MidiApple::openMidiReference( MIDIEndpointRef reference, QString refName, bool isIn ) { char * registeredName = (char*) malloc(refName.length()+1); sprintf(registeredName, "%s",refName.toLatin1().constData()); qDebug("openMidiReference refName '%s'",refName.toLatin1().constData()); MIDIClientRef mClient = getMidiClientRef(); MIDIPortRef mPort = 0; CFStringRef inName = CFStringCreateWithCString(0, registeredName, kCFStringEncodingASCII); if(isIn) { MIDIInputPortCreate(mClient, inName, &MidiApple::ReadCallback, this, &mPort); } else { MIDIOutputPortCreate(mClient, inName, &mPort); } MIDIPortConnectSource(mPort, reference, (void *)registeredName); m_sourcePortRef.insert(reference, mPort); CFRelease(inName); qDebug("openMidiReference registeredName '%s'",registeredName); }
LONG CoreAudio_MIDIInit(void) { int i; CHAR szPname[MAXPNAMELEN] = {0}; int numDest = MIDIGetNumberOfDestinations(); CFStringRef name = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR("wineMIDIClient.%d"), getpid()); wineMIDIClient = CoreMIDI_CreateClient( name ); if (wineMIDIClient == NULL) { CFRelease(name); ERR("can't create wineMIDIClient\n"); return DRV_FAILURE; } CFRelease(name); MIDIOut_NumDevs = MAX_MIDI_SYNTHS; MIDIOut_NumDevs += numDest; MIDIIn_NumDevs = MIDIGetNumberOfSources(); TRACE("MIDIOut_NumDevs %d MIDIIn_NumDevs %d\n", MIDIOut_NumDevs, MIDIIn_NumDevs); destinations = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, MIDIOut_NumDevs * sizeof(MIDIDestination)); sources = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, MIDIIn_NumDevs * sizeof(MIDISource)); if (MIDIIn_NumDevs > 0) { InitializeCriticalSection(&midiInLock); MIDIInThreadPortName = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR("MIDIInThreadPortName.%u"), getpid()); CreateThread(NULL, 0, MIDIIn_MessageThread, NULL, 0, NULL); name = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR("WineInputPort.%u"), getpid()); MIDIInputPortCreate(wineMIDIClient, name, MIDIIn_ReadProc, NULL, &MIDIInPort); CFRelease(name); } if (numDest > 0) { name = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR("WineOutputPort.%u"), getpid()); MIDIOutputPortCreate(wineMIDIClient, name, &MIDIOutPort); CFRelease(name); } /* initialize sources */ for (i = 0; i < MIDIIn_NumDevs; i++) { sources[i].wDevID = i; sources[i].source = MIDIGetSource(i); CoreMIDI_GetObjectName(sources[i].source, szPname, sizeof(szPname)); MultiByteToWideChar(CP_ACP, 0, szPname, -1, sources[i].caps.szPname, sizeof(sources[i].caps.szPname)/sizeof(WCHAR)); MIDIPortConnectSource(MIDIInPort, sources[i].source, &sources[i].wDevID); sources[i].state = 0; /* FIXME */ sources[i].caps.wMid = 0x00FF; /* Manufac ID */ sources[i].caps.wPid = 0x0001; /* Product ID */ sources[i].caps.vDriverVersion = 0x0001; sources[i].caps.dwSupport = 0; } /* initialise MIDI synths */ for (i = 0; i < MAX_MIDI_SYNTHS; i++) { snprintf(szPname, sizeof(szPname), "CoreAudio MIDI Synth %d", i); MultiByteToWideChar(CP_ACP, 0, szPname, -1, destinations[i].caps.szPname, sizeof(destinations[i].caps.szPname)/sizeof(WCHAR)); destinations[i].caps.wTechnology = MOD_SYNTH; destinations[i].caps.wChannelMask = 0xFFFF; destinations[i].caps.wMid = 0x00FF; /* Manufac ID */ destinations[i].caps.wPid = 0x0001; /* Product ID */ destinations[i].caps.vDriverVersion = 0x0001; destinations[i].caps.dwSupport = MIDICAPS_VOLUME; destinations[i].caps.wVoices = 16; destinations[i].caps.wNotes = 16; } /* initialise available destinations */ for (i = MAX_MIDI_SYNTHS; i < numDest + MAX_MIDI_SYNTHS; i++) { destinations[i].dest = MIDIGetDestination(i - MAX_MIDI_SYNTHS); CoreMIDI_GetObjectName(destinations[i].dest, szPname, sizeof(szPname)); MultiByteToWideChar(CP_ACP, 0, szPname, -1, destinations[i].caps.szPname, sizeof(destinations[i].caps.szPname)/sizeof(WCHAR)); destinations[i].caps.wTechnology = MOD_MIDIPORT; destinations[i].caps.wChannelMask = 0xFFFF; destinations[i].caps.wMid = 0x00FF; /* Manufac ID */ destinations[i].caps.wPid = 0x0001; destinations[i].caps.vDriverVersion = 0x0001; destinations[i].caps.dwSupport = 0; destinations[i].caps.wVoices = 0; destinations[i].caps.wNotes = 0; } return DRV_SUCCESS; }
int main(int argc, char *argv[]) { if (argc >= 2) { // first argument, if present, is the MIDI channel number to echo to (1-16) sscanf(argv[1], "%d", &gChannel); if (gChannel < 1) gChannel = 1; else if (gChannel > 16) gChannel = 16; --gChannel; // convert to 0-15 } // create client and ports MIDIClientRef client = NULL; MIDIClientCreate(CFSTR("MIDI Echo"), NULL, NULL, &client); MIDIPortRef inPort = NULL; MIDIInputPortCreate(client, CFSTR("Input port"), MyReadProc, NULL, &inPort); MIDIOutputPortCreate(client, CFSTR("Output port"), &gOutPort); // enumerate devices (not really related to purpose of the echo program // but shows how to get information about devices) int i, n; CFStringRef pname, pmanuf, pmodel; char name[64], manuf[64], model[64]; n = MIDIGetNumberOfDevices(); for (i = 0; i < n; ++i) { MIDIDeviceRef dev = MIDIGetDevice(i); MIDIObjectGetStringProperty(dev, kMIDIPropertyName, &pname); MIDIObjectGetStringProperty(dev, kMIDIPropertyManufacturer, &pmanuf); MIDIObjectGetStringProperty(dev, kMIDIPropertyModel, &pmodel); CFStringGetCString(pname, name, sizeof(name), 0); CFStringGetCString(pmanuf, manuf, sizeof(manuf), 0); CFStringGetCString(pmodel, model, sizeof(model), 0); CFRelease(pname); CFRelease(pmanuf); CFRelease(pmodel); printf("name=%s, manuf=%s, model=%s\n", name, manuf, model); } // open connections from all sources n = MIDIGetNumberOfSources(); printf("%d sources\n", n); for (i = 0; i < n; ++i) { MIDIEndpointRef src = MIDIGetSource(i); MIDIPortConnectSource(inPort, src, NULL); } // find the first destination n = MIDIGetNumberOfDestinations(); if (n > 0) gDest = MIDIGetDestination(0); if (gDest != NULL) { MIDIObjectGetStringProperty(gDest, kMIDIPropertyName, &pname); CFStringGetCString(pname, name, sizeof(name), 0); CFRelease(pname); printf("Echoing to channel %d of %s\n", gChannel + 1, name); } else { printf("No MIDI destinations present\n"); } CFRunLoopRun(); // run until aborted with control-C return 0; }