3 |
* LinuxSampler - modular, streaming capable sampler * |
* LinuxSampler - modular, streaming capable sampler * |
4 |
* * |
* * |
5 |
* Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * |
* Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * |
6 |
* Copyright (C) 2005 - 2008 Christian Schoenebeck * |
* Copyright (C) 2005 - 2009 Christian Schoenebeck * |
7 |
* * |
* * |
8 |
* This program is free software; you can redistribute it and/or modify * |
* This program is free software; you can redistribute it and/or modify * |
9 |
* it under the terms of the GNU General Public License as published by * |
* it under the terms of the GNU General Public License as published by * |
89 |
String MidiInputDeviceMme::ParameterPorts::Name() { |
String MidiInputDeviceMme::ParameterPorts::Name() { |
90 |
return "PORTS"; |
return "PORTS"; |
91 |
} |
} |
92 |
|
|
93 |
// the MME driver supports only one port so to manage multiple MME MIDI ports the user just creates several MME drivers and connects each one to the desired MME port |
// the MME driver supports only one port so to manage multiple MME MIDI ports the user just creates several MME drivers and connects each one to the desired MME port |
94 |
|
|
95 |
|
|
96 |
|
|
97 |
// *************** ParameterPort *************** |
// *************** ParameterPort *************** |
203 |
if(res != MMSYSERR_NOERROR) { |
if(res != MMSYSERR_NOERROR) { |
204 |
throw MidiInputException("MIDI port connect failed. midiInOpen error"); |
throw MidiInputException("MIDI port connect failed. midiInOpen error"); |
205 |
} |
} |
206 |
|
|
207 |
MidiInOpened = true; |
MidiInOpened = true; |
208 |
|
|
209 |
/* Store pointer to our input buffer for System Exclusive messages in MIDIHDR */ |
/* Store pointer to our input buffer for System Exclusive messages in MIDIHDR */ |
221 |
CloseMmeMidiPort(); |
CloseMmeMidiPort(); |
222 |
throw MidiInputException("MIDI port connect failed. midiInPrepareHeader error"); |
throw MidiInputException("MIDI port connect failed. midiInPrepareHeader error"); |
223 |
} |
} |
224 |
|
|
225 |
/* Queue MIDI input buffer */ |
/* Queue MIDI input buffer */ |
226 |
res = midiInAddBuffer(MidiInHandle, &midiHdr, sizeof(MIDIHDR)); |
res = midiInAddBuffer(MidiInHandle, &midiHdr, sizeof(MIDIHDR)); |
227 |
if(res != MMSYSERR_NOERROR) { |
if(res != MMSYSERR_NOERROR) { |
229 |
throw MidiInputException("MIDI port connect failed. midiInAddBuffer error"); |
throw MidiInputException("MIDI port connect failed. midiInAddBuffer error"); |
230 |
} |
} |
231 |
|
|
232 |
|
|
233 |
res = midiInStart(MidiInHandle); |
res = midiInStart(MidiInHandle); |
234 |
if(res != MMSYSERR_NOERROR) { |
if(res != MMSYSERR_NOERROR) { |
235 |
CloseMmeMidiPort(); |
CloseMmeMidiPort(); |
237 |
} |
} |
238 |
|
|
239 |
} |
} |
240 |
|
|
241 |
void MidiInputDeviceMme::MidiInputPortMme::MmeCallbackDispatcher(HMIDIIN handle, UINT uMsg, DWORD dwParam1, DWORD dwParam2) { |
void MidiInputDeviceMme::MidiInputPortMme::MmeCallbackDispatcher(HMIDIIN handle, UINT uMsg, DWORD dwParam1, DWORD dwParam2) { |
242 |
|
|
243 |
unsigned char *DataPtr; // pointer to SysEx data |
unsigned char *DataPtr; // pointer to SysEx data |
247 |
|
|
248 |
switch(uMsg) { |
switch(uMsg) { |
249 |
case MIM_DATA: |
case MIM_DATA: |
250 |
switch(data[0] & 0xF0) { // status byte |
DispatchRaw(data); |
|
|
|
|
case 0xB0: |
|
|
if (data[1] == 0) |
|
|
DispatchBankSelectMsb(data[2], data[0] & 0x0F); |
|
|
else if (data[1] == 32) |
|
|
DispatchBankSelectLsb(data[2], data[0] & 0x0F); |
|
|
DispatchControlChange(data[1], data[2], data[0] & 0x0F); |
|
|
break; |
|
|
|
|
|
case 0xD0: |
|
|
DispatchControlChange(128, data[1], data[0] & 0x0F); |
|
|
break; |
|
|
|
|
|
case 0xE0: |
|
|
DispatchPitchbend(data[1], data[0] & 0x0F); |
|
|
break; |
|
|
|
|
|
case 0x90: |
|
|
if (data[1] < 0x80) { |
|
|
if (data[2] > 0){ |
|
|
DispatchNoteOn(data[1], data[2], data[0] & 0x0F); |
|
|
}else{ |
|
|
DispatchNoteOff(data[1], data[2], data[0] & 0x0F); |
|
|
} |
|
|
} |
|
|
break; |
|
|
|
|
|
case 0x80: |
|
|
if (data[1] < 0x80) { |
|
|
DispatchNoteOff(data[1], data[2], data[0] & 0x0F); |
|
|
} |
|
|
break; |
|
|
|
|
|
case 0xC0: |
|
|
if (data[1] < 0x80) { |
|
|
DispatchProgramChange(data[1], data[0] & 0x0F); |
|
|
} |
|
|
break; |
|
|
} |
|
|
|
|
251 |
break; |
break; |
252 |
|
|
253 |
case MIM_LONGDATA: |
case MIM_LONGDATA: |
254 |
if(!ExitFlag) { |
if(!ExitFlag) { |
255 |
LPMIDIHDR lpMIDIHeader = (LPMIDIHDR)dwParam1; |
LPMIDIHDR lpMIDIHeader = (LPMIDIHDR)dwParam1; |
276 |
|
|
277 |
if(SysExMsgComplete) DispatchSysex(SysExBuf, SysExOffset); |
if(SysExMsgComplete) DispatchSysex(SysExBuf, SysExOffset); |
278 |
|
|
279 |
/* Queue the MIDIHDR for more input, only if ExitFlag was not set otherwise we risk an infinite loop |
/* Queue the MIDIHDR for more input, only if ExitFlag was not set otherwise we risk an infinite loop |
280 |
because when we call midiInReset() below, Windows will send a final MIM_LONGDATA message to that callback. |
because when we call midiInReset() below, Windows will send a final MIM_LONGDATA message to that callback. |
281 |
*/ |
*/ |
282 |
midiInAddBuffer(MidiInHandle, lpMIDIHeader, sizeof(MIDIHDR)); |
midiInAddBuffer(MidiInHandle, lpMIDIHeader, sizeof(MIDIHDR)); |
283 |
} |
} |
284 |
break; |
break; |
285 |
} |
} |
286 |
|
|
334 |
} |
} |
335 |
|
|
336 |
String MidiInputDeviceMme::Version() { |
String MidiInputDeviceMme::Version() { |
337 |
String s = "$Revision: 1.3 $"; |
String s = "$Revision: 1.4 $"; |
338 |
return s.substr(11, s.size() - 13); // cut dollar signs, spaces and CVS macro keyword |
return s.substr(11, s.size() - 13); // cut dollar signs, spaces and CVS macro keyword |
339 |
} |
} |
340 |
|
|
341 |
|
|
342 |
|
|
343 |
} // namespace LinuxSampler |
} // namespace LinuxSampler |