// Create a new Input Port and saves the Ruby Callback proc. static VALUE t_create_input_port(VALUE self, VALUE client_instance, VALUE port_name) { MIDIPortRef in_port; RbMIDIClient* client; Data_Get_Struct(client_instance, RbMIDIClient, client); CFStringRef port_str = CFStringCreateWithCString(kCFAllocatorDefault, RSTRING(port_name)->as.heap.ptr, kCFStringEncodingASCII); MIDIInputPortCreate(client->client, port_str, RbMIDIReadProc, NULL, &in_port); CFRelease(port_str); VALUE inputport_instance = rb_class_new_instance(0, 0, cInputPort); if( inputport_instance == Qnil ) { free_objects(); rb_fatal("Couldn't create an instance of InputPort!"); } RbInputPort* port_struct; Data_Get_Struct(inputport_instance, RbInputPort, port_struct); port_struct->input_port = in_port; return inputport_instance; }
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); } } }
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); } }
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)); }
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; }
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"); } }
bool CoreMidiInputDevice::open() { qDebug() << Q_FUNC_INFO; // Don't open twice if (m_inPort != 0) return false; OSStatus s = MIDIInputPortCreate(m_client, CFSTR("QLC Input Port"), MidiInProc, this, &m_inPort); if (s != 0) { qWarning() << Q_FUNC_INFO << "Unable to make an input port for" << name() << ":" << s; m_inPort = 0; } else { // Connect the input port to the first source m_source = MIDIEntityGetSource(m_entity, 0); s = MIDIPortConnectSource(m_inPort, m_source, this); if (s != 0) { qWarning() << Q_FUNC_INFO << "Unable to connect input port to source for" << name() << ":" << s; s = MIDIPortDispose(m_inPort); if (s != 0) qWarning() << "Unable to dispose of input port in" << name(); m_inPort = 0; } } return true; }
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; }
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_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); }
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); }
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; }
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 ); }
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; }
// ---------------------------------------------------------- bool ofxAudioUnitMidiReceiver::connectToMidiSource(unsigned long midiSourceIndex) // ---------------------------------------------------------- { if(!_port) { OSStatus s = MIDIInputPortCreate(_client, CFSTR("oF MIDI Input Port"), ofxAudioUnitMidiReadProc, &_unit, &_port); if(s != noErr) return false; } OFXAU_RET_BOOL(MIDIPortConnectSource(_port, MIDIGetSource(midiSourceIndex), NULL), "connecting MIDI receiver to source"); }
/** * @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 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; } }
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); } }
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; }
int main(int argc, char *argv[]) { OSStatus err = noErr; // Set up signaling stuff first signal(SIGHUP, &quit); signal(SIGINT, &quit); signal(SIGILL, &quit); signal(SIGTRAP, &quit); signal(SIGABRT, &quit); signal(SIGEMT, &quit); signal(SIGFPE, &quit); signal(SIGBUS, &quit); signal(SIGSEGV, &quit); signal(SIGPIPE, &quit); signal(SIGALRM, &quit); signal(SIGTERM, &quit); signal(SIGURG, &quit); char path[MAX_PATH], tmp[MAX_PATH]; if(getPluginBundleDir(DEF_BUNDLE_STRING, tmp)) { snprintf(path, MAX_PATH, "%s%c%s%c%s%s", tmp, DEF_DELIMITER, DEF_RESOURCE_PATH, DEF_DELIMITER, DEF_PRODUCT, DEF_EXTENSION); } #if USE_PC_MIDI /* MIDIClientRef mc; if(MIDIClientCreate(CFSTR(DEF_PRODUCT), NULL, NULL, &mc) != noErr) { printf("Could not initialize MIDI subsystem\n"); } printf("%d extern devices, %d devs\n", MIDIGetNumberOfDevices()); for(int i = 0; i < MIDIGetNumberOfDevices(); ++i) { MIDIDeviceRef dev = MIDIGetDevice(i); printf("Device %d has %d entities\n", i, MIDIDeviceGetNumberOfEntities(dev)); for(int j = 0; j < MIDIDeviceGetNumberOfEntities(dev); ++j) { MIDIEntityRef entity = MIDIDeviceGetEntity(dev, j); CFPropertyListRef props; MIDIObjectGetProperties(entity, &props, true); printf("Entity has %d prop keys\n", CFDictionaryGetCount((CFDictionaryRef)props)); int size = CFDictionaryGetCount((CFDictionaryRef)props); const void **keys = (const void **)malloc (sizeof(void *) * size); const void **vals = (const void **)malloc (sizeof(void *) * size); CFDictionaryGetKeysAndValues((CFDictionaryRef)props, keys, vals); for(int k = 0; k < size; ++k) { printf("KEY: %s' - VAL: %s\n", CFStringGetCStringPtr((CFStringRef)keys[i], 0), "hi"); } free(keys); free(vals); } } MIDIClientDispose(mc); */ #endif vstLoader *plug = new vstLoader(); if(!plug->setPath(path)) { return 1; } else { plug->setName(); } if(!plug->loadPlugin()) { delete plug; return 1; } if(!plug->initialize()) { delete plug; return 1; } // Set up time info for the plug _TIME.samplePos = 0; _TIME.sampleRate = DEF_SAMPLE_RATE; _TIME.nanoSeconds = 0; _TIME.ppqPos = 0; _TIME.tempo = DEF_TEMPO; _TIME.barStartPos = 0; _TIME.cycleStartPos = 0; _TIME.cycleEndPos = 0; _TIME.timeSigNumerator = DEF_TIMESIG_NUMER; _TIME.timeSigDenominator = DEF_TIMESIG_DENOM; _TIME.smpteOffset = 0; _TIME.smpteFrameRate = 0; _TIME.samplesToNextClock = 0; _TIME.flags = 0; // Set other plugin environment variables if(!plug->setSampleRate(DEF_SAMPLE_RATE)) { return 1; } if(!plug->setBlocksize(DEF_BLOCKSIZE)) { return 1; } // Initialize midi stuff MIDIClientRef mc; if(MIDIClientCreate(CFSTR(DEF_PRODUCT), NULL, NULL, &mc) != noErr) { debug(LOG_ERROR, "Could not initialize MIDI subsystem"); } MIDIPortRef port; err = MIDIInputPortCreate(mc, CFSTR(DEF_PRODUCT), processMidi, plug, &port); MIDIEndpointRef endpoint = MIDIGetSource(0); err = MIDIPortConnectSource(port, endpoint, NULL); int result = 0; pthread_t run_thread; result = pthread_create(&run_thread, NULL, runPluginLoop, (void*)plug); openEditor(plug->getPluginPtr()); pthread_kill(run_thread, SIGINT); MIDIPortDisconnectSource(port, endpoint); MIDIClientDispose(mc); delete plug; return 0; }