gearmulator

Emulation of classic VA synths of the late 90s/2000s that are based on Motorola 56300 family DSPs
Log | Files | Refs | Submodules | README | LICENSE

midiDevice.cpp (2188B)


      1 #include "midiDevice.h"
      2 
      3 #include "portmidi/pm_common/portmidi.h"
      4 
      5 namespace mqConsoleLib
      6 {
      7 
      8 #ifdef ANDROID
      9 extern "C"
     10 {
     11 	// nop implementation of PortMidi
     12 
     13 	PmError Pm_Initialize( void )
     14 	{
     15 		return pmHostError;
     16 	}
     17 	const PmDeviceInfo* Pm_GetDeviceInfo( PmDeviceID id)
     18 	{
     19 		return nullptr;
     20 	}
     21 	int Pm_CountDevices( void )
     22 	{
     23 		return 0;
     24 	}
     25 	PmDeviceID Pm_GetDefaultInputDeviceID( void )
     26 	{
     27 		return 0;
     28 	}
     29 	PmDeviceID Pm_GetDefaultOutputDeviceID( void )
     30 	{
     31 		return 0;
     32 	}
     33 	PmError Pm_Close( PortMidiStream* stream )
     34 	{
     35 		return pmNoError;
     36 	}
     37 	PmError Pm_WriteSysEx(PortMidiStream *stream, PmTimestamp when, unsigned char *msg)
     38 	{
     39 		return pmHostError;
     40 	}
     41 	const char *Pm_GetErrorText( PmError errnum )
     42 	{
     43 		return "Platform not supported";
     44 	}
     45 	PmError Pm_Write( PortMidiStream *stream, PmEvent *buffer, int32_t length)
     46 	{
     47 		return pmHostError;
     48 	}
     49 	PmError Pm_OpenOutput(PortMidiStream** stream, PmDeviceID outputDevice, void *outputDriverInfo,int32_t bufferSize, PmTimeProcPtr time_proc, void *time_info, int32_t latency )
     50 	{
     51 		return pmHostError;
     52 	}
     53 	PmError Pm_Poll( PortMidiStream *stream )
     54 	{
     55 		return pmNoData;
     56 	}
     57 	int Pm_Read(PortMidiStream *stream, PmEvent *buffer, int32_t length)
     58 	{
     59 		return 0;
     60 	}
     61 	PmError Pm_OpenInput(PortMidiStream** stream, PmDeviceID inputDevice, void *inputDriverInfo, int32_t bufferSize, PmTimeProcPtr time_proc, void *time_info)
     62 	{
     63 		return pmHostError;
     64 	}
     65 }
     66 #endif
     67 
     68 MidiDevice::MidiDevice(const std::string& _deviceName, bool _output): Device(_deviceName), m_output(_output)
     69 {
     70 	Pm_Initialize();
     71 }
     72 
     73 std::string MidiDevice::getDeviceNameFromId(const int _devId)
     74 {
     75 	const auto* di = Pm_GetDeviceInfo(_devId);
     76 	if(!di)
     77 		return {};
     78 	return di->name;
     79 }
     80 
     81 std::string MidiDevice::deviceNameFromId(const int _devId) const
     82 {
     83 	return getDeviceNameFromId(_devId);
     84 }
     85 
     86 int MidiDevice::deviceIdFromName(const std::string& _devName) const
     87 {
     88 	const auto count = Pm_CountDevices();
     89 
     90 	for(int i=0; i<count; ++i)
     91 	{
     92 		const auto* di = Pm_GetDeviceInfo(i);
     93 
     94 		if(m_output && !di->output)
     95 			continue;
     96 		if(!m_output && !di->input)
     97 			continue;
     98 
     99 		const auto name = deviceNameFromId(i);
    100 		if(name.empty())
    101 			continue;;
    102 		if(_devName == name)
    103 			return i;
    104 	}
    105 	return -1;
    106 }
    107 }