| | 147 | |
| | 148 | int n = MIDIGetNumberOfDestinations(); |
| | 149 | if (n > 0) { |
| | 150 | cmH2Dst = MIDIGetDestination(0); |
| | 151 | } |
| | 152 | |
| | 153 | if (cmH2Dst != NULL) { |
| | 154 | CFStringRef H2MidiNames; |
| | 155 | |
| | 156 | MIDIObjectGetStringProperty(cmH2Dst, kMIDIPropertyName, &H2MidiNames); |
| | 157 | CFStringGetCString(pname, name, sizeof(name), 0); |
| | 158 | //MIDIPortConnectSource ( h2OutputRef, cmH2Dst, NULL ); |
| | 159 | CFRelease( H2MidiNames ); |
| | 160 | } |
| | 207 | } |
| | 208 | |
| | 209 | void CoreMidiDriver::handleQueueNote(Note* pNote) |
| | 210 | { |
| | 211 | if (cmH2Dst == NULL ) { |
| | 212 | ERRORLOG( "cmH2Dst = NULL " ); |
| | 213 | return; |
| | 214 | } |
| | 215 | |
| | 216 | int channel = pNote->get_instrument()->get_midi_out_channel(); |
| | 217 | if (channel < 0) { |
| | 218 | return; |
| | 219 | } |
| | 220 | |
| | 221 | int key = pNote->get_instrument()->get_midi_out_note(); |
| | 222 | int velocity = pNote->get_velocity() * 127; |
| | 223 | |
| | 224 | MIDIPacketList packetList; |
| | 225 | packetList.numPackets = 1; |
| | 226 | |
| | 227 | packetList.packet.timeStamp = 0; |
| | 228 | packetList.packet.length = 3; |
| | 229 | packetList.packet.data[0] = 0x80 | channel; |
| | 230 | packetList.packet.data[1] = key; |
| | 231 | packetList.packet.data[2] = velocity; |
| | 232 | |
| | 233 | |
| | 234 | MIDISend(h2OutputRef, cmH2Dst, &packetList); |
| | 235 | |
| | 236 | packetList.packet.data[0] = 0x90 | channel; |
| | 237 | packetList.packet.data[1] = key; |
| | 238 | packetList.packet.data[2] = velocity; |
| | 239 | |
| | 240 | MIDISend(h2OutputRef, cmH2Dst, &packetList); |
| | 241 | } |
| | 242 | |
| | 243 | void CoreMidiDriver::handleQueueAllNoteOff() |
| | 244 | { |
| | 245 | if (cmH2Dst == NULL ) { |
| | 246 | ERRORLOG( "cmH2Dst = NULL " ); |
| | 247 | return; |
| | 248 | } |
| | 249 | |
| | 250 | InstrumentList *instList = Hydrogen::get_instance()->getSong()->get_instrument_list(); |
| | 251 | |
| | 252 | unsigned int numInstruments = instList->get_size(); |
| | 253 | for (int index = 0; index < numInstruments; ++index) { |
| | 254 | Instrument *curInst = instList->get(index); |
| | 255 | |
| | 256 | int channel = curInst->get_midi_out_channel(); |
| | 257 | if (channel < 0) { |
| | 258 | continue; |
| | 259 | } |
| | 260 | int key = curInst->get_midi_out_note(); |
| | 261 | |
| | 262 | MIDIPacketList packetList; |
| | 263 | packetList.numPackets = 1; |
| | 264 | |
| | 265 | packetList.packet.timeStamp = 0; |
| | 266 | packetList.packet.length = 3; |
| | 267 | packetList.packet.data[0] = 0x80 | channel; |
| | 268 | packetList.packet.data[1] = key; |
| | 269 | packetList.packet.data[2] = 0; |
| | 270 | |
| | 271 | MIDISend(h2OutputRef, cmH2Dst, &packetList); |
| | 272 | |
| | 273 | } |