Example #1
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);
	}
}
Example #2
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;
}
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;
}
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");
	}
	
	
}
int prConnectMIDIIn(struct VMGlobals *g, int numArgsPushed)
{
	//PyrSlot *a = g->sp - 2;
	PyrSlot *b = g->sp - 1;
	PyrSlot *c = g->sp;

	int err, inputIndex, uid;
	err = slotIntVal(b, &inputIndex);
	if (err) return errWrongType;
	if (inputIndex < 0 || inputIndex >= gNumMIDIInPorts) return errIndexOutOfRange;

	err = slotIntVal(c, &uid);
	if (err) return errWrongType;

    size_t uid_t = uid;
    
	MIDIEndpointRef src=0;
	MIDIObjectType mtype;
	MIDIObjectFindByUniqueID(uid, (MIDIObjectRef*)&src, &mtype);
	if (mtype != kMIDIObjectType_Source) return errFailed;

	//pass the uid to the midiReadProc to identify the src

	MIDIPortConnectSource(gMIDIInPort[inputIndex], src, (void*)uid_t);

	return errNone;
}
INT32 MIDI_Utils_StartDevice(MacMidiDeviceHandle* handle) {
    OSStatus err = noErr;
    
    if (!handle || !handle->h.deviceHandle) {
        ERROR0("ERROR: MIDI_Utils_StartDevice: handle or native is NULL\n");
        return MIDI_INVALID_HANDLE;
    }

    // Clears all the events from the queue.
    MIDI_QueueClear(handle->h.queue);

    if (!handle->isStarted) {
        /* set the flag that we can now receive messages */
        handle->isStarted = TRUE;

        if (handle->direction == MIDI_IN) {
            // The handle->h.platformData field contains the (pthread_cond_t*)
            // associated with the source of the MIDI input stream, and is
            // used in the CoreMIDI's callback to signal the arrival of new
            // data.
            //
            // Similarly, handle->h.queue is used in the CoreMDID's callback
            // to dispatch the incoming messages to the appropriate queue.
            //
            err = MIDIPortConnectSource(inPort, (MIDIEndpointRef) (intptr_t) (handle->h.deviceHandle), (void*) handle);
        } else if (handle->direction == MIDI_OUT) {
            // Unschedules previous-sent packets.
            err = MIDIFlushOutput((MIDIEndpointRef) (intptr_t) handle->h.deviceHandle);
        }

        MIDI_CHECK_ERROR;
    }
    return MIDI_SUCCESS; /* don't fail */
}
Example #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;
}
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);
}
Example #9
0
void CoreMidiDriver::open()
{
	INFOLOG( "open" );

	OSStatus err = noErr;

	QString sMidiPortName = Preferences::get_instance()->m_sMidiPortName;

	cmSources = MIDIGetNumberOfSources();
	unsigned i;
	for ( i = 0; i < cmSources; i++ ) {
		CFStringRef H2MidiNames;
		cmH2Src = MIDIGetSource( i );

		if ( cmH2Src ) {
			err = MIDIObjectGetStringProperty( cmH2Src, kMIDIPropertyName, &H2MidiNames );
			char cmName[64];
			err = CFStringGetCString( H2MidiNames, cmName, 64, kCFStringEncodingASCII );
			QString h2MidiPortName = cmName;
			if ( h2MidiPortName == sMidiPortName ) {
				MIDIPortConnectSource ( h2InputRef, cmH2Src, NULL );
				m_bRunning = true;
			}
		}
		CFRelease ( H2MidiNames );
	}
	
	int n = MIDIGetNumberOfDestinations();
	if (n > 0) {
		cmH2Dst = MIDIGetDestination(0);
	}

	if (cmH2Dst != NULL) {
		CFStringRef H2MidiNames;
		
		MIDIObjectGetStringProperty(cmH2Dst, kMIDIPropertyName, &H2MidiNames);
		//CFStringGetCString(pname, name, sizeof(name), 0);
		//MIDIPortConnectSource ( h2OutputRef, cmH2Dst, NULL );
		MIDIPortConnectSource ( h2OutputRef, cmH2Dst, NULL );
		if( H2MidiNames != NULL){
		    CFRelease( H2MidiNames );
		}
	}
}
Example #10
0
File: midi.c Project: 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);
}
Example #11
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;
}
Example #12
0
// source is identified by the index in the array returned by get_sources
// input_port is an InputPort class
static VALUE t_connect_source_to_port(VALUE self, VALUE source_idx, VALUE input_port)
{
    RbInputPort* port;
    Data_Get_Struct(input_port, RbInputPort, port);
    
    MIDIEndpointRef source = MIDIGetSource(FIX2INT(source_idx));
    
    MIDIPortConnectSource(port->input_port, source, NULL);
    
    return Qtrue;
}
Example #13
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;
}
Example #14
0
static int _macosx_start(struct midi_port *p)
{
	struct macosx_midi *m;
	m = (struct macosx_midi *)p->userdata;

	if (p->io & MIDI_INPUT
	&& MIDIPortConnectSource(portIn, m->ep, (void*)p) != noErr) {
		return 0;
	}

	if (p->io & MIDI_OUTPUT) {
		m->pl = (MIDIPacketList*)m->packet;
		m->x = NULL;
	}
	return 1;
}
Example #15
0
// ----------------------------------------------------------
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");
}
Example #16
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);
	}
}
Example #17
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;
	}
}
Example #18
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);
}
Example #19
0
lp_device_t lp_get_device() {
    _lp_ctx_create();
    
    for(int i=0;i<MIDIGetNumberOfDevices();++i) {
        MIDIDeviceRef d = MIDIGetDevice(i);
        
        if(!_lp_is_launchpad(d) || !_lp_is_device_online(d))
            continue;
        
        MIDIEntityRef entity = MIDIDeviceGetEntity(d, 0);
        MIDIEndpointRef source = MIDIEntityGetSource(entity, 0);
        MIDIEndpointRef dest = MIDIEntityGetDestination(entity, 0);
        
        lp_device_t device = _lp_create_device(d, dest, 0);
        MIDIPortConnectSource(_lp_ctx.inport, source, device);
        
        _lp_set_is_s(device);
        lp_send_reset(device);
        
        return device;
    }
    
    return NULL;
}
Example #20
0
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;
}
Example #21
0
//_________________________________________________________
static void OpenInputSlot (SlotPtr slot)
{
	MIDIPortConnectSource(gInPort, slot->src,slot);  // connect source
}
Example #22
0
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;
}
Example #23
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;
}
Example #24
0
void MIDIClient::connectSource(MIDIEndpointRef source) {
    _c(MIDIPortConnectSource, MIDIPortConnectSource(inPort, source, this));
}