37#if defined(H2CORE_HAVE_COREMIDI) || _DOXYGEN_
43static void midiProc (
const MIDIPacketList * pktlist,
44 void * readProcRefCon,
45 void * srcConnRefCon )
49 MIDIPacket* packet = ( MIDIPacket * )pktlist->packet;
52 for ( uint i = 0; i < pktlist->numPackets; i++ ) {
54 int nEventType = packet->data[0];
57 if ( nEventType == 240 ) {
60 for (
int i = 0; i < packet->length; i++ ) {
70 packet = MIDIPacketNext( packet );
81 err = MIDIClientCreate ( CFSTR(
"h2MIDIClient" ), NULL, NULL, &
h2MIDIClient );
83 ERRORLOG( QString(
"Cannot create CoreMIDI client: %1" ).arg( err ));
88 ERRORLOG( QString(
"Cannot create CoreMIDI input port: %1" ).arg( err ));
93 ERRORLOG( QString(
"Cannot create CoreMIDI output port: %1" ).arg( err ));
98 ERRORLOG( QString(
"Cannot create CoreMIDI virtual output: %1" ).arg( err ));
119 OSStatus err = noErr;
126 CFStringRef H2MidiNames;
130 err = MIDIObjectGetStringProperty(
cmH2Src, kMIDIPropertyName, &H2MidiNames );
132 err = CFStringGetCString( H2MidiNames, cmName, 64, kCFStringEncodingASCII );
133 QString h2MidiPortName = cmName;
134 if ( h2MidiPortName == sMidiPortName &&
140 CFRelease ( H2MidiNames );
143 int n = MIDIGetNumberOfDestinations();
145 cmH2Dst = MIDIGetDestination(0);
149 CFStringRef H2MidiNames;
151 MIDIObjectGetStringProperty(
cmH2Dst, kMIDIPropertyName, &H2MidiNames);
155 if( H2MidiNames != NULL){
156 CFRelease( H2MidiNames );
165 OSStatus err = noErr;
176 INFOLOG(
"retrieving output list" );
177 OSStatus err = noErr;
179 std::vector<QString> cmPortList;
181 cmSources = MIDIGetNumberOfDestinations();
183 INFOLOG (
"Getting number of MIDI sources . . .\n" );
187 CFStringRef H2MidiNames;
188 cmH2Src = MIDIGetDestination( i );
190 ERRORLOG(
"Could not open output device" );
193 err = MIDIObjectGetStringProperty(
cmH2Src, kMIDIPropertyName, &H2MidiNames );
194 INFOLOG (
"Getting MIDI object string property . . .\n" );
196 CFStringGetCString( H2MidiNames, cmName, 64, kCFStringEncodingASCII );
197 INFOLOG (
"Getting MIDI object name . . .\n" );
198 QString h2MidiPortName = cmName;
199 cmPortList.push_back( h2MidiPortName );
201 CFRelease( H2MidiNames );
209 INFOLOG(
"retrieving output list" );
210 OSStatus err = noErr;
212 std::vector<QString> cmPortList;
215 INFOLOG (
"Getting number of MIDI sources . . .\n" );
219 CFStringRef H2MidiNames;
222 ERRORLOG(
"Could not open input device" );
225 err = MIDIObjectGetStringProperty(
cmH2Src, kMIDIPropertyName, &H2MidiNames );
226 INFOLOG (
"Getting MIDI object string property . . .\n" );
228 CFStringGetCString( H2MidiNames, cmName, 64, kCFStringEncodingASCII );
229 INFOLOG (
"Getting MIDI object name . . .\n" );
230 QString h2MidiPortName = cmName;
231 cmPortList.push_back( h2MidiPortName );
233 CFRelease( H2MidiNames );
254 MIDIPacketList packetList;
255 packetList.numPackets = 1;
257 packetList.packet->timeStamp = 0;
258 packetList.packet->length = 3;
259 packetList.packet->data[0] = 0x80 | channel;
260 packetList.packet->data[1] = key;
261 packetList.packet->data[2] = velocity;
265 packetList.packet->data[0] = 0x90 | channel;
266 packetList.packet->data[1] = key;
267 packetList.packet->data[2] = velocity;
287 MIDIPacketList packetList;
288 packetList.numPackets = 1;
290 packetList.packet->timeStamp = 0;
291 packetList.packet->length = 3;
292 packetList.packet->data[0] = 0x80 | channel;
293 packetList.packet->data[1] = key;
294 packetList.packet->data[2] = velocity;
308 unsigned int numInstruments = instList->size();
309 for (
int index = 0; index < numInstruments; ++index) {
310 auto curInst = instList->get(index);
312 int channel = curInst->get_midi_out_channel();
316 int key = curInst->get_midi_out_note();
318 MIDIPacketList packetList;
319 packetList.numPackets = 1;
321 packetList.packet->timeStamp = 0;
322 packetList.packet->length = 3;
323 packetList.packet->data[0] = 0x80 | channel;
324 packetList.packet->data[1] = key;
325 packetList.packet->data[2] = 0;
342 MIDIPacketList packetList;
343 packetList.numPackets = 1;
345 packetList.packet->timeStamp = 0;
346 packetList.packet->length = 3;
347 packetList.packet->data[0] = 0xB0 | channel;
348 packetList.packet->data[1] = param;
349 packetList.packet->data[2] = value;
357 OSStatus err = noErr;
360 if ( err != noErr ) {
361 ERRORLOG( QString(
"Cannot send MIDI packet to output port: %1" ).arg( err ));
365 if ( err != noErr ) {
366 ERRORLOG( QString(
"Cannot send MIDI packet to virtual output: %1" ).arg( err ));
MIDIClientRef h2MIDIClient
virtual void open() override
MIDIEndpointRef h2VirtualOut
virtual std::vector< QString > getInputPortList() override
virtual void close() override
virtual void handleQueueNoteOff(int channel, int key, int velocity) override
virtual std::vector< QString > getOutputPortList() override
virtual void handleQueueAllNoteOff() override
virtual void handleOutgoingControlChange(int param, int value, int channel) override
void sendMidiPacket(MIDIPacketList *packetList)
virtual void handleQueueNote(Note *pNote) override
std::shared_ptr< Song > getSong() const
Get the current song.
static Hydrogen * get_instance()
Returns the current Hydrogen instance __instance.
void setType(int nStatusByte)
Derives and set m_type (and if applicable m_nChannel) using the statusByte of an incoming MIDI messag...
std::vector< unsigned char > m_sysexData
A note plays an associated instrument with a velocity left and right pan.
std::shared_ptr< Instrument > get_instrument()
__instrument accessor
int get_midi_key() const
return scaled key for midi output, !
int get_midi_velocity() const
midi velocity accessor
static Preferences * get_instance()
Returns a pointer to the current Preferences singleton stored in __instance.
static QString getNullMidiPort()
Choice of m_sMidiPortName and m_sMidiOutputPortName in case no port/device was selected.
static void midiProc(const MIDIPacketList *pktlist, void *readProcRefCon, void *srcConnRefCon)