Requested updates

This commit is contained in:
Bruce Brown 2018-01-05 19:50:16 -08:00
parent 7476de60ce
commit f233c93aaa
2 changed files with 85 additions and 74 deletions

View file

@ -65,86 +65,87 @@ std::vector<HMIDIOUT> midihout;
void CALLBACK MidiInProc(HMIDIIN hMidiIn, UINT wMsg, DWORD_PTR dwInstance, DWORD_PTR dwParam1, DWORD_PTR dwParam2) {
switch (wMsg) {
case MIM_OPEN:
// message not used
break;
case MIM_CLOSE:
for (int i = 0; i < midihin.size(); i++) {
if (midihin[i] == hMidiIn) {
midihin[i] = NULL;
instance->allNotesOff();
instance->midiHardwareChange();
case MIM_OPEN:
// message not used
break;
case MIM_CLOSE:
for (int i = 0; i < midihin.size(); i++) {
if (midihin[i] == hMidiIn) {
midihin[i] = NULL;
instance->allNotesOff();
instance->midiHardwareChange();
}
}
}
break;
case MIM_DATA: {
int device = -1;
for (int i = 0; i < midihin.size(); i++) {
if (midihin[i] == hMidiIn) {
device = i;
break;
case MIM_DATA: {
int device = -1;
for (int i = 0; i < midihin.size(); i++) {
if (midihin[i] == hMidiIn) {
device = i;
}
}
int raw = dwParam1;
int channel = (MIDI_NIBBLE_MASK & dwParam1) + 1;
int status = MIDI_BYTE_MASK & dwParam1;
int type = MIDI_NIBBLE_MASK & (dwParam1 >> MIDI_SHIFT_STATUS);
int note = MIDI_BYTE_MASK & (dwParam1 >> MIDI_SHIFT_NOTE);
int velocity = MIDI_BYTE_MASK & (dwParam1 >> MIDI_SHIFT_VELOCITY);
int bend = 0;
int program = 0;
if (!typeNoteOffEnabled && type == MIDI_NOTE_OFF) {
return;
}
if (!typeNoteOnEnabled && type == MIDI_NOTE_ON) {
return;
}
if (!typePolyKeyPressureEnabled && type == MIDI_POLYPHONIC_KEY_PRESSURE) {
return;
}
if (!typeControlChangeEnabled && type == MIDI_CONTROL_CHANGE) {
return;
}
if (typeProgramChangeEnabled && type == MIDI_PROGRAM_CHANGE) {
program = note;
note = 0;
}
if (typeChanPressureEnabled && type == MIDI_CHANNEL_PRESSURE) {
velocity = note;
note = 0;
}
if (typePitchBendEnabled && type == MIDI_PITCH_BEND_CHANGE) {
bend = ((MIDI_BYTE_MASK & (dwParam1 >> MIDI_SHIFT_NOTE)) |
(MIDI_PITCH_BEND_MASK & (dwParam1 >> MIDI_SHIFT_PITCH_BEND))) - 8192;
channel = 0; // Weird values on different instruments
note = 0;
velocity = 0;
}
if (!typeSystemMessageEnabled && type == MIDI_SYSTEM_MESSAGE) {
return;
}
if (thruModeEnabled) {
instance->sendNote(status, note, velocity); // relay the message on to all other midi devices.
}
instance->rawMidiReceived(device, raw); // notify the javascript
instance->midiReceived(device, raw, channel, status, type, note, velocity, bend, program); // notify the javascript
break;
}
int raw = dwParam1;
int channel = (MIDI_NIBBLE_MASK & dwParam1) + 1;
int status = MIDI_BYTE_MASK & dwParam1;
int type = MIDI_NIBBLE_MASK & (dwParam1 >> MIDI_SHIFT_STATUS);
int note = MIDI_BYTE_MASK & (dwParam1 >> MIDI_SHIFT_NOTE);
int velocity = MIDI_BYTE_MASK & (dwParam1 >> MIDI_SHIFT_VELOCITY);
int bend = 0;
int program = 0;
if (!typeNoteOffEnabled && type == MIDI_NOTE_OFF) {
return;
}
if (!typeNoteOnEnabled && type == MIDI_NOTE_ON) {
return;
}
if (!typePolyKeyPressureEnabled && type == MIDI_POLYPHONIC_KEY_PRESSURE) {
return;
}
if (!typeControlChangeEnabled && type == MIDI_CONTROL_CHANGE) {
return;
}
if (typeProgramChangeEnabled && type == MIDI_PROGRAM_CHANGE) {
program = note;
note = 0;
}
if (typeChanPressureEnabled && type == MIDI_CHANNEL_PRESSURE) {
velocity = note;
note = 0;
}
if (typePitchBendEnabled && type == MIDI_PITCH_BEND_CHANGE) {
bend = ((MIDI_BYTE_MASK & (dwParam1 >> MIDI_SHIFT_NOTE)) | (MIDI_PITCH_BEND_MASK & (dwParam1 >> MIDI_SHIFT_PITCH_BEND))) - 8192;
channel = 0; // Weird values on different instruments
note = 0;
velocity = 0;
}
if (!typeSystemMessageEnabled && type == MIDI_SYSTEM_MESSAGE) {
return;
}
if (thruModeEnabled) {
instance->sendNote(status, note, velocity); // relay the message on to all other midi devices.
}
instance->rawMidiReceived(device, raw); // notify the javascript
instance->midiReceived(device, raw, channel, status, type, note, velocity, bend, program); // notify the javascript
break;
}
}
}
void CALLBACK MidiOutProc(HMIDIOUT hmo, UINT wMsg, DWORD_PTR dwInstance, DWORD_PTR dwParam1, DWORD_PTR dwParam2) {
switch (wMsg) {
case MOM_OPEN:
// message not used
break;
case MOM_CLOSE:
for (int i = 0; i < midihout.size(); i++) {
if (midihout[i] == hmo) {
midihout[i] = NULL;
instance->allNotesOff();
instance->midiHardwareChange();
case MOM_OPEN:
// message not used
break;
case MOM_CLOSE:
for (int i = 0; i < midihout.size(); i++) {
if (midihout[i] == hmo) {
midihout[i] = NULL;
instance->allNotesOff();
instance->midiHardwareChange();
}
}
}
break;
break;
}
}

View file

@ -22,7 +22,7 @@
class Midi : public QObject, public Dependency {
Q_OBJECT
SINGLETON_DEPENDENCY
SINGLETON_DEPENDENCY
public:
void rawMidiReceived(int device, int raw); //relay raw midi data to Javascript
@ -50,16 +50,26 @@ signals:
public slots:
// Send Raw Midi Packet to all connected devices
Q_INVOKABLE void sendRawDword(int device, int raw);
/// Send Raw Midi message to selected device
/// @param {int} device: device number
/// @param {int} raw: raw midi message (DWORD)
// Send Midi Message to all connected devices
Q_INVOKABLE void sendMidiMessage(int device, int channel, int type, int note, int velocity);
/// Send midi message to selected device/devices
/// @param {int} device: device number
/// @param {int} channel: channel number
/// @param {int} type: 0x8 is noteoff, 0x9 is noteon (if velocity=0, noteoff), etc
/// @param {int} note: midi note number
/// @param {int} velocity: note velocity (0 means noteoff)
// Send Midi Message to all connected devices
Q_INVOKABLE void playMidiNote(int status, int note, int velocity);
/// play a note on all connected devices
/// @param {int} status: 0x80 is noteoff, 0x90 is noteon (if velocity=0, noteoff), etc
/// @param {int} note: midi note number
/// @param {int} velocity: note velocity (0 means noteoff)
Q_INVOKABLE void playMidiNote(int status, int note, int velocity);
/// turn off all notes on all connected devices
Q_INVOKABLE void allNotesOff();