Add files via upload

This commit is contained in:
Bruce Brown 2017-12-29 12:28:31 -08:00 committed by GitHub
parent 0eacac60c1
commit 6d0cac83c4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 520 additions and 520 deletions

View file

@ -1,420 +1,420 @@
// //
// Midi.cpp // Midi.cpp
// libraries/midi/src // libraries/midi/src
// //
// Created by Burt Sloane // Created by Burt Sloane
// Modified by Bruce Brown // Modified by Bruce Brown
// Copyright 2015 High Fidelity, Inc. // Copyright 2015 High Fidelity, Inc.
// //
// Distributed under the Apache License, Version 2.0. // Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
// //
#include "Midi.h" #include "Midi.h"
#include <QtCore/QLoggingCategory> #include <QtCore/QLoggingCategory>
#if defined Q_OS_WIN32 #if defined Q_OS_WIN32
#include "Windows.h" #include "Windows.h"
#endif #endif
#if defined Q_OS_WIN32 #if defined Q_OS_WIN32
const int MIDI_BYTE_MASK = 0x0FF; const int MIDI_BYTE_MASK = 0x0FF;
const int MIDI_NIBBLE_MASK = 0x00F; const int MIDI_NIBBLE_MASK = 0x00F;
const int MIDI_PITCH_BEND_MASK = 0x3F80; const int MIDI_PITCH_BEND_MASK = 0x3F80;
const int MIDI_SHIFT_STATUS = 4; const int MIDI_SHIFT_STATUS = 4;
const int MIDI_SHIFT_NOTE = 8; const int MIDI_SHIFT_NOTE = 8;
const int MIDI_SHIFT_VELOCITY = 16; const int MIDI_SHIFT_VELOCITY = 16;
const int MIDI_SHIFT_PITCH_BEND = 9; const int MIDI_SHIFT_PITCH_BEND = 9;
#endif #endif
// Status Decode // Status Decode
const int MIDI_NOTE_OFF = 0x8; const int MIDI_NOTE_OFF = 0x8;
const int MIDI_NOTE_ON = 0x9; const int MIDI_NOTE_ON = 0x9;
const int MIDI_POLYPHONIC_KEY_PRESSURE = 0xa; const int MIDI_POLYPHONIC_KEY_PRESSURE = 0xa;
const int MIDI_CONTROL_CHANGE = 0xb; const int MIDI_CONTROL_CHANGE = 0xb;
const int MIDI_PROGRAM_CHANGE = 0xc; const int MIDI_PROGRAM_CHANGE = 0xc;
const int MIDI_CHANNEL_PRESSURE = 0xd; const int MIDI_CHANNEL_PRESSURE = 0xd;
const int MIDI_PITCH_BEND_CHANGE = 0xe; const int MIDI_PITCH_BEND_CHANGE = 0xe;
const int MIDI_SYSTEM_MESSAGE = 0xf; const int MIDI_SYSTEM_MESSAGE = 0xf;
const int MIDI_CHANNEL_MODE_ALL_NOTES_OFF = 0x07b; const int MIDI_CHANNEL_MODE_ALL_NOTES_OFF = 0x07b;
static Midi* instance = NULL; // communicate this to non-class callbacks static Midi* instance = NULL; // communicate this to non-class callbacks
static bool thruModeEnabled = false; static bool thruModeEnabled = false;
static bool broadcastEnabled = false; static bool broadcastEnabled = false;
static bool typeNoteOffEnabled = true; static bool typeNoteOffEnabled = true;
static bool typeNoteOnEnabled = true; static bool typeNoteOnEnabled = true;
static bool typePolyKeyPressureEnabled = false; static bool typePolyKeyPressureEnabled = false;
static bool typeControlChangeEnabled = true; static bool typeControlChangeEnabled = true;
static bool typeProgramChangeEnabled = true; static bool typeProgramChangeEnabled = true;
static bool typeChanPressureEnabled = false; static bool typeChanPressureEnabled = false;
static bool typePitchBendEnabled = true; static bool typePitchBendEnabled = true;
static bool typeSystemMessageEnabled = false; static bool typeSystemMessageEnabled = false;
std::vector<QString> Midi::midiinexclude; std::vector<QString> Midi::midiinexclude;
std::vector<QString> Midi::midioutexclude; std::vector<QString> Midi::midioutexclude;
#if defined Q_OS_WIN32 #if defined Q_OS_WIN32
#pragma comment(lib, "Winmm.lib") #pragma comment(lib, "Winmm.lib")
// //
std::vector<HMIDIIN> midihin; std::vector<HMIDIIN> midihin;
std::vector<HMIDIOUT> midihout; std::vector<HMIDIOUT> midihout;
void CALLBACK MidiInProc(HMIDIIN hMidiIn, UINT wMsg, DWORD_PTR dwInstance, DWORD_PTR dwParam1, DWORD_PTR dwParam2) { void CALLBACK MidiInProc(HMIDIIN hMidiIn, UINT wMsg, DWORD_PTR dwInstance, DWORD_PTR dwParam1, DWORD_PTR dwParam2) {
switch (wMsg) { switch (wMsg) {
case MIM_OPEN: case MIM_OPEN:
// message not used // message not used
break; break;
case MIM_CLOSE: case MIM_CLOSE:
for (int i = 0; i < midihin.size(); i++) { for (int i = 0; i < midihin.size(); i++) {
if (midihin[i] == hMidiIn) { if (midihin[i] == hMidiIn) {
midihin[i] = NULL; midihin[i] = NULL;
instance->allNotesOff(); instance->allNotesOff();
instance->midiHardwareChange(); instance->midiHardwareChange();
} }
} }
break; break;
case MIM_DATA: { case MIM_DATA: {
int device = -1; int device = -1;
for (int i = 0; i < midihin.size(); i++) { for (int i = 0; i < midihin.size(); i++) {
if (midihin[i] == hMidiIn) { if (midihin[i] == hMidiIn) {
device = i; device = i;
} }
} }
int raw = dwParam1; int raw = dwParam1;
int channel = (MIDI_NIBBLE_MASK & dwParam1) + 1; int channel = (MIDI_NIBBLE_MASK & dwParam1) + 1;
int status = MIDI_BYTE_MASK & dwParam1; int status = MIDI_BYTE_MASK & dwParam1;
int type = MIDI_NIBBLE_MASK & (dwParam1 >> MIDI_SHIFT_STATUS); int type = MIDI_NIBBLE_MASK & (dwParam1 >> MIDI_SHIFT_STATUS);
int note = MIDI_BYTE_MASK & (dwParam1 >> MIDI_SHIFT_NOTE); int note = MIDI_BYTE_MASK & (dwParam1 >> MIDI_SHIFT_NOTE);
int velocity = MIDI_BYTE_MASK & (dwParam1 >> MIDI_SHIFT_VELOCITY); int velocity = MIDI_BYTE_MASK & (dwParam1 >> MIDI_SHIFT_VELOCITY);
int bend = 0; int bend = 0;
int program = 0; int program = 0;
if (!typeNoteOffEnabled && type == MIDI_NOTE_OFF) { if (!typeNoteOffEnabled && type == MIDI_NOTE_OFF) {
return; return;
} }
if (!typeNoteOnEnabled && type == MIDI_NOTE_ON) { if (!typeNoteOnEnabled && type == MIDI_NOTE_ON) {
return; return;
} }
if (!typePolyKeyPressureEnabled && type == MIDI_POLYPHONIC_KEY_PRESSURE) { if (!typePolyKeyPressureEnabled && type == MIDI_POLYPHONIC_KEY_PRESSURE) {
return; return;
} }
if (!typeControlChangeEnabled && type == MIDI_CONTROL_CHANGE) { if (!typeControlChangeEnabled && type == MIDI_CONTROL_CHANGE) {
return; return;
} }
if (typeProgramChangeEnabled && type == MIDI_PROGRAM_CHANGE) { if (typeProgramChangeEnabled && type == MIDI_PROGRAM_CHANGE) {
program = note; program = note;
note = 0; note = 0;
} }
if (typeChanPressureEnabled && type == MIDI_CHANNEL_PRESSURE) { if (typeChanPressureEnabled && type == MIDI_CHANNEL_PRESSURE) {
velocity = note; velocity = note;
note = 0; note = 0;
} }
if (typePitchBendEnabled && type == MIDI_PITCH_BEND_CHANGE) { 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; 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 channel = 0; // Weird values on different instruments
note = 0; note = 0;
velocity = 0; velocity = 0;
} }
if (!typeSystemMessageEnabled && type == MIDI_SYSTEM_MESSAGE) { if (!typeSystemMessageEnabled && type == MIDI_SYSTEM_MESSAGE) {
return; return;
} }
if (thruModeEnabled) { if (thruModeEnabled) {
instance->sendNote(status, note, velocity); // relay the message on to all other midi devices. instance->sendNote(status, note, velocity); // relay the message on to all other midi devices.
} }
instance->rawMidiReceived(device, raw); // notify the javascript instance->rawMidiReceived(device, raw); // notify the javascript
instance->midiReceived(device, raw, channel, status, type, note, velocity, bend, program); // notify the javascript instance->midiReceived(device, raw, channel, status, type, note, velocity, bend, program); // notify the javascript
break; break;
} }
} }
} }
void CALLBACK MidiOutProc(HMIDIOUT hmo, UINT wMsg, DWORD_PTR dwInstance, DWORD_PTR dwParam1, DWORD_PTR dwParam2) { void CALLBACK MidiOutProc(HMIDIOUT hmo, UINT wMsg, DWORD_PTR dwInstance, DWORD_PTR dwParam1, DWORD_PTR dwParam2) {
switch (wMsg) { switch (wMsg) {
case MOM_OPEN: case MOM_OPEN:
// message not used // message not used
break; break;
case MOM_CLOSE: case MOM_CLOSE:
for (int i = 0; i < midihout.size(); i++) { for (int i = 0; i < midihout.size(); i++) {
if (midihout[i] == hmo) { if (midihout[i] == hmo) {
midihout[i] = NULL; midihout[i] = NULL;
instance->allNotesOff(); instance->allNotesOff();
instance->midiHardwareChange(); instance->midiHardwareChange();
} }
} }
break; break;
} }
} }
void Midi::sendRawMessage(int device, int raw) { void Midi::sendRawMessage(int device, int raw) {
if (broadcastEnabled) { if (broadcastEnabled) {
for (int i = 0; i < midihout.size(); i++) { for (int i = 0; i < midihout.size(); i++) {
if (midihout[i] != NULL) { if (midihout[i] != NULL) {
midiOutShortMsg(midihout[i], raw); midiOutShortMsg(midihout[i], raw);
} }
} }
} else { } else {
midiOutShortMsg(midihout[device], raw); midiOutShortMsg(midihout[device], raw);
} }
} }
void Midi::sendMessage(int device, int channel, int type, int note, int velocity) { void Midi::sendMessage(int device, int channel, int type, int note, int velocity) {
int message = (channel - 1) | (type << MIDI_SHIFT_STATUS); int message = (channel - 1) | (type << MIDI_SHIFT_STATUS);
if (broadcastEnabled) { if (broadcastEnabled) {
for (int i = 0; i < midihout.size(); i++) { for (int i = 0; i < midihout.size(); i++) {
if (midihout[i] != NULL) { if (midihout[i] != NULL) {
midiOutShortMsg(midihout[i], message + (note << MIDI_SHIFT_NOTE) + (velocity << MIDI_SHIFT_VELOCITY)); midiOutShortMsg(midihout[i], message + (note << MIDI_SHIFT_NOTE) + (velocity << MIDI_SHIFT_VELOCITY));
} }
} }
} else { } else {
midiOutShortMsg(midihout[device], message + (note << MIDI_SHIFT_NOTE) + (velocity << MIDI_SHIFT_VELOCITY)); midiOutShortMsg(midihout[device], message + (note << MIDI_SHIFT_NOTE) + (velocity << MIDI_SHIFT_VELOCITY));
} }
} }
void Midi::sendNote(int status, int note, int velocity) { void Midi::sendNote(int status, int note, int velocity) {
for (int i = 0; i < midihout.size(); i++) { for (int i = 0; i < midihout.size(); i++) {
if (midihout[i] != NULL) { if (midihout[i] != NULL) {
midiOutShortMsg(midihout[i], status + (note << MIDI_SHIFT_NOTE) + (velocity << MIDI_SHIFT_VELOCITY)); midiOutShortMsg(midihout[i], status + (note << MIDI_SHIFT_NOTE) + (velocity << MIDI_SHIFT_VELOCITY));
} }
} }
} }
void Midi::MidiSetup() { void Midi::MidiSetup() {
midihin.clear(); midihin.clear();
midihout.clear(); midihout.clear();
MIDIINCAPS incaps; MIDIINCAPS incaps;
for (unsigned int i = 0; i < midiInGetNumDevs(); i++) { for (unsigned int i = 0; i < midiInGetNumDevs(); i++) {
midiInGetDevCaps(i, &incaps, sizeof(MIDIINCAPS)); midiInGetDevCaps(i, &incaps, sizeof(MIDIINCAPS));
bool found = false; bool found = false;
for (int j = 0; j < midiinexclude.size(); j++) { for (int j = 0; j < midiinexclude.size(); j++) {
if (midiinexclude[j].toStdString().compare(incaps.szPname) == 0) { if (midiinexclude[j].toStdString().compare(incaps.szPname) == 0) {
found = true; found = true;
break; break;
} }
} }
if (!found) { // EXCLUDE AN INPUT BY NAME if (!found) { // EXCLUDE AN INPUT BY NAME
HMIDIIN tmphin; HMIDIIN tmphin;
midiInOpen(&tmphin, i, (DWORD_PTR)MidiInProc, NULL, CALLBACK_FUNCTION); midiInOpen(&tmphin, i, (DWORD_PTR)MidiInProc, NULL, CALLBACK_FUNCTION);
midiInStart(tmphin); midiInStart(tmphin);
midihin.push_back(tmphin); midihin.push_back(tmphin);
} }
} }
MIDIOUTCAPS outcaps; MIDIOUTCAPS outcaps;
for (unsigned int i = 0; i < midiOutGetNumDevs(); i++) { for (unsigned int i = 0; i < midiOutGetNumDevs(); i++) {
midiOutGetDevCaps(i, &outcaps, sizeof(MIDIINCAPS)); midiOutGetDevCaps(i, &outcaps, sizeof(MIDIINCAPS));
bool found = false; bool found = false;
for (int j = 0; j < midioutexclude.size(); j++) { for (int j = 0; j < midioutexclude.size(); j++) {
if (midioutexclude[j].toStdString().compare(outcaps.szPname) == 0) { if (midioutexclude[j].toStdString().compare(outcaps.szPname) == 0) {
found = true; found = true;
break; break;
} }
} }
if (!found) { // EXCLUDE AN OUTPUT BY NAME if (!found) { // EXCLUDE AN OUTPUT BY NAME
HMIDIOUT tmphout; HMIDIOUT tmphout;
midiOutOpen(&tmphout, i, (DWORD_PTR)MidiOutProc, NULL, CALLBACK_FUNCTION); midiOutOpen(&tmphout, i, (DWORD_PTR)MidiOutProc, NULL, CALLBACK_FUNCTION);
midihout.push_back(tmphout); midihout.push_back(tmphout);
} }
} }
allNotesOff(); allNotesOff();
} }
void Midi::MidiCleanup() { void Midi::MidiCleanup() {
allNotesOff(); allNotesOff();
for (int i = 0; i < midihin.size(); i++) { for (int i = 0; i < midihin.size(); i++) {
if (midihin[i] != NULL) { if (midihin[i] != NULL) {
midiInStop(midihin[i]); midiInStop(midihin[i]);
midiInClose(midihin[i]); midiInClose(midihin[i]);
} }
} }
for (int i = 0; i < midihout.size(); i++) { for (int i = 0; i < midihout.size(); i++) {
if (midihout[i] != NULL) { if (midihout[i] != NULL) {
midiOutClose(midihout[i]); midiOutClose(midihout[i]);
} }
} }
midihin.clear(); midihin.clear();
midihout.clear(); midihout.clear();
} }
#else #else
void Midi::sendRaw(int device, int raw) { void Midi::sendRaw(int device, int raw) {
} }
void Midi::sendNote(int status, int note, int velocity) { void Midi::sendNote(int status, int note, int velocity) {
} }
void Midi::sendMessage(int device, int channel, int type, int note, int velocity) void Midi::sendMessage(int device, int channel, int type, int note, int velocity)
} }
void Midi::MidiSetup() { void Midi::MidiSetup() {
allNotesOff(); allNotesOff();
} }
void Midi::MidiCleanup() { void Midi::MidiCleanup() {
allNotesOff(); allNotesOff();
} }
#endif #endif
void Midi::rawMidiReceived(int device, int raw) { void Midi::rawMidiReceived(int device, int raw) {
QVariantMap eventData; QVariantMap eventData;
eventData["device"] = device; eventData["device"] = device;
eventData["raw"] = raw; eventData["raw"] = raw;
emit midiRaw(eventData); emit midiRaw(eventData);
} }
void Midi::midiReceived(int device, int raw, int channel, int status, int type, int note, int velocity, int bend, int program) { void Midi::midiReceived(int device, int raw, int channel, int status, int type, int note, int velocity, int bend, int program) {
QVariantMap eventData; QVariantMap eventData;
eventData["device"] = device; eventData["device"] = device;
eventData["raw"] = raw; eventData["raw"] = raw;
eventData["channel"] = channel; eventData["channel"] = channel;
eventData["status"] = status; eventData["status"] = status;
eventData["type"] = type; eventData["type"] = type;
eventData["note"] = note; eventData["note"] = note;
eventData["velocity"] = velocity; eventData["velocity"] = velocity;
eventData["bend"] = bend; eventData["bend"] = bend;
eventData["program"] = program; eventData["program"] = program;
emit midiNote(eventData);// Legacy emit midiNote(eventData);// Legacy
emit midiMessage(eventData); emit midiMessage(eventData);
} }
void Midi::midiHardwareChange() { void Midi::midiHardwareChange() {
emit midiReset(); emit midiReset();
} }
// //
Midi::Midi() { Midi::Midi() {
instance = this; instance = this;
#if defined Q_OS_WIN32 #if defined Q_OS_WIN32
midioutexclude.push_back("Microsoft GS Wavetable Synth"); // we don't want to hear this thing (Lags) midioutexclude.push_back("Microsoft GS Wavetable Synth"); // we don't want to hear this thing (Lags)
#endif #endif
MidiSetup(); MidiSetup();
} }
Midi::~Midi() { Midi::~Midi() {
} }
void Midi::sendRawDword(int device, int raw) { void Midi::sendRawDword(int device, int raw) {
sendRawMessage(device, raw); sendRawMessage(device, raw);
} }
void Midi::playMidiNote(int status, int note, int velocity) { void Midi::playMidiNote(int status, int note, int velocity) {
sendNote(status, note, velocity); sendNote(status, note, velocity);
} }
void Midi::sendMidiMessage(int device, int channel, int type, int note, int velocity) { void Midi::sendMidiMessage(int device, int channel, int type, int note, int velocity) {
sendMessage(device, channel, type, note, velocity); sendMessage(device, channel, type, note, velocity);
} }
void Midi::allNotesOff() { void Midi::allNotesOff() {
sendNote(MIDI_CONTROL_CHANGE, MIDI_CHANNEL_MODE_ALL_NOTES_OFF, 0); // all notes off sendNote(MIDI_CONTROL_CHANGE, MIDI_CHANNEL_MODE_ALL_NOTES_OFF, 0); // all notes off
} }
void Midi::resetDevices() { void Midi::resetDevices() {
MidiCleanup(); MidiCleanup();
MidiSetup(); MidiSetup();
} }
void Midi::USBchanged() { void Midi::USBchanged() {
instance->MidiCleanup(); instance->MidiCleanup();
instance->MidiSetup(); instance->MidiSetup();
instance->midiHardwareChange(); instance->midiHardwareChange();
} }
// //
QStringList Midi::listMidiDevices(bool output) { QStringList Midi::listMidiDevices(bool output) {
QStringList rv; QStringList rv;
#if defined Q_OS_WIN32 #if defined Q_OS_WIN32
if (output) { if (output) {
MIDIOUTCAPS outcaps; MIDIOUTCAPS outcaps;
for (unsigned int i = 0; i < midiOutGetNumDevs(); i++) { for (unsigned int i = 0; i < midiOutGetNumDevs(); i++) {
midiOutGetDevCaps(i, &outcaps, sizeof(MIDIINCAPS)); midiOutGetDevCaps(i, &outcaps, sizeof(MIDIINCAPS));
rv.append(outcaps.szPname); rv.append(outcaps.szPname);
} }
} }
else { else {
MIDIINCAPS incaps; MIDIINCAPS incaps;
for (unsigned int i = 0; i < midiInGetNumDevs(); i++) { for (unsigned int i = 0; i < midiInGetNumDevs(); i++) {
midiInGetDevCaps(i, &incaps, sizeof(MIDIINCAPS)); midiInGetDevCaps(i, &incaps, sizeof(MIDIINCAPS));
rv.append(incaps.szPname); rv.append(incaps.szPname);
} }
} }
#endif #endif
return rv; return rv;
} }
void Midi::unblockMidiDevice(QString name, bool output) { void Midi::unblockMidiDevice(QString name, bool output) {
if (output) { if (output) {
for (unsigned long i = 0; i < midioutexclude.size(); i++) { for (unsigned long i = 0; i < midioutexclude.size(); i++) {
if (midioutexclude[i].toStdString().compare(name.toStdString()) == 0) { if (midioutexclude[i].toStdString().compare(name.toStdString()) == 0) {
midioutexclude.erase(midioutexclude.begin() + i); midioutexclude.erase(midioutexclude.begin() + i);
break; break;
} }
} }
} }
else { else {
for (unsigned long i = 0; i < midiinexclude.size(); i++) { for (unsigned long i = 0; i < midiinexclude.size(); i++) {
if (midiinexclude[i].toStdString().compare(name.toStdString()) == 0) { if (midiinexclude[i].toStdString().compare(name.toStdString()) == 0) {
midiinexclude.erase(midiinexclude.begin() + i); midiinexclude.erase(midiinexclude.begin() + i);
break; break;
} }
} }
} }
} }
void Midi::blockMidiDevice(QString name, bool output) { void Midi::blockMidiDevice(QString name, bool output) {
unblockMidiDevice(name, output); // make sure it's only in there once unblockMidiDevice(name, output); // make sure it's only in there once
if (output) { if (output) {
midioutexclude.push_back(name); midioutexclude.push_back(name);
} }
else { else {
midiinexclude.push_back(name); midiinexclude.push_back(name);
} }
} }
void Midi::thruModeEnable(bool enable) { void Midi::thruModeEnable(bool enable) {
thruModeEnabled = enable; thruModeEnabled = enable;
} }
void Midi::broadcastEnable(bool enable) { void Midi::broadcastEnable(bool enable) {
broadcastEnabled = enable; broadcastEnabled = enable;
} }
void Midi::typeNoteOffEnable(bool enable) { void Midi::typeNoteOffEnable(bool enable) {
typeNoteOffEnabled = enable; typeNoteOffEnabled = enable;
} }
void Midi::typeNoteOnEnable(bool enable) { void Midi::typeNoteOnEnable(bool enable) {
typeNoteOnEnabled = enable; typeNoteOnEnabled = enable;
} }
void Midi::typePolyKeyPressureEnable(bool enable) { void Midi::typePolyKeyPressureEnable(bool enable) {
typePolyKeyPressureEnabled = enable; typePolyKeyPressureEnabled = enable;
} }
void Midi::typeControlChangeEnable(bool enable) { void Midi::typeControlChangeEnable(bool enable) {
typeControlChangeEnabled = enable; typeControlChangeEnabled = enable;
} }
void Midi::typeProgramChangeEnable(bool enable) { void Midi::typeProgramChangeEnable(bool enable) {
typeProgramChangeEnabled = enable; typeProgramChangeEnabled = enable;
} }
void Midi::typeChanPressureEnable(bool enable) { void Midi::typeChanPressureEnable(bool enable) {
typeChanPressureEnabled = enable; typeChanPressureEnabled = enable;
} }
void Midi::typePitchBendEnable(bool enable) { void Midi::typePitchBendEnable(bool enable) {
typePitchBendEnabled = enable; typePitchBendEnabled = enable;
} }
void Midi::typeSystemMessageEnable(bool enable) { void Midi::typeSystemMessageEnable(bool enable) {
typeSystemMessageEnabled = enable; typeSystemMessageEnabled = enable;
} }

View file

@ -1,100 +1,100 @@
// //
// Midi.h // Midi.h
// libraries/midi/src // libraries/midi/src
// //
// Created by Burt Sloane // Created by Burt Sloane
// Modified by Bruce Brown // Modified by Bruce Brown
// Copyright 2015 High Fidelity, Inc. // Copyright 2015 High Fidelity, Inc.
// //
// Distributed under the Apache License, Version 2.0. // Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
// //
#ifndef hifi_Midi_h #ifndef hifi_Midi_h
#define hifi_Midi_h #define hifi_Midi_h
#include <QtCore/QObject> #include <QtCore/QObject>
#include <QAbstractNativeEventFilter> #include <QAbstractNativeEventFilter>
#include <DependencyManager.h> #include <DependencyManager.h>
#include <vector> #include <vector>
#include <string> #include <string>
class Midi : public QObject, public Dependency { class Midi : public QObject, public Dependency {
Q_OBJECT Q_OBJECT
SINGLETON_DEPENDENCY SINGLETON_DEPENDENCY
public: public:
void rawMidiReceived(int device, int raw); //relay raw midi data to Javascript void rawMidiReceived(int device, int raw); //relay raw midi data to Javascript
void midiReceived(int device, int raw, int channel, int status, int type, int note, int velocity, int bend, int program); // relay a note to Javascript void midiReceived(int device, int raw, int channel, int status, int type, int note, int velocity, int bend, int program); // relay a note to Javascript
void midiHardwareChange(); // relay hardware change to Javascript void midiHardwareChange(); // relay hardware change to Javascript
void sendRawMessage(int device, int raw); // relay midi message to MIDI outputs void sendRawMessage(int device, int raw); // relay midi message to MIDI outputs
void sendNote(int status, int note, int velocity); // relay a note to MIDI outputs void sendNote(int status, int note, int velocity); // relay a note to MIDI outputs
void sendMessage(int device, int channel, int type, int note, int velocity); // relay a message to MIDI outputs void sendMessage(int device, int channel, int type, int note, int velocity); // relay a message to MIDI outputs
static void USBchanged(); static void USBchanged();
private: private:
static std::vector<QString> midiinexclude; static std::vector<QString> midiinexclude;
static std::vector<QString> midioutexclude; static std::vector<QString> midioutexclude;
private: private:
void MidiSetup(); void MidiSetup();
void MidiCleanup(); void MidiCleanup();
signals: signals:
void midiNote(QVariantMap eventData); void midiNote(QVariantMap eventData);
void midiMessage(QVariantMap eventData); void midiMessage(QVariantMap eventData);
void midiRaw(QVariantMap eventData); void midiRaw(QVariantMap eventData);
void midiReset(); void midiReset();
public slots: public slots:
// Send Raw Midi Packet to all connected devices // Send Raw Midi Packet to all connected devices
Q_INVOKABLE void sendRawDword(int device, int raw); Q_INVOKABLE void sendRawDword(int device, int raw);
// Send Midi Message to all connected devices // Send Midi Message to all connected devices
Q_INVOKABLE void sendMidiMessage(int device, int channel, int type, int note, int velocity); Q_INVOKABLE void sendMidiMessage(int device, int channel, int type, int note, int velocity);
/// play a note on all connected devices /// play a note on all connected devices
/// @param {int} status: 0x80 is noteoff, 0x90 is noteon (if velocity=0, noteoff), etc /// @param {int} status: 0x80 is noteoff, 0x90 is noteon (if velocity=0, noteoff), etc
/// @param {int} note: midi note number /// @param {int} note: midi note number
/// @param {int} velocity: note velocity (0 means noteoff) /// @param {int} velocity: note velocity (0 means noteoff)
Q_INVOKABLE void playMidiNote(int status, int note, int velocity); Q_INVOKABLE void playMidiNote(int status, int note, int velocity);
/// turn off all notes on all connected devices /// turn off all notes on all connected devices
Q_INVOKABLE void allNotesOff(); Q_INVOKABLE void allNotesOff();
/// clean up and re-discover attached devices /// clean up and re-discover attached devices
Q_INVOKABLE void resetDevices(); Q_INVOKABLE void resetDevices();
/// ask for a list of inputs/outputs /// ask for a list of inputs/outputs
Q_INVOKABLE QStringList listMidiDevices(bool output); Q_INVOKABLE QStringList listMidiDevices(bool output);
/// block an input/output by name /// block an input/output by name
Q_INVOKABLE void blockMidiDevice(QString name, bool output); Q_INVOKABLE void blockMidiDevice(QString name, bool output);
/// unblock an input/output by name /// unblock an input/output by name
Q_INVOKABLE void unblockMidiDevice(QString name, bool output); Q_INVOKABLE void unblockMidiDevice(QString name, bool output);
/// repeat all incoming notes to all outputs (default disabled) /// repeat all incoming notes to all outputs (default disabled)
Q_INVOKABLE void thruModeEnable(bool enable); Q_INVOKABLE void thruModeEnable(bool enable);
/// broadcast on all unblocked devices /// broadcast on all unblocked devices
Q_INVOKABLE void broadcastEnable(bool enable); Q_INVOKABLE void broadcastEnable(bool enable);
/// filter by event types /// filter by event types
Q_INVOKABLE void typeNoteOffEnable(bool enable); Q_INVOKABLE void typeNoteOffEnable(bool enable);
Q_INVOKABLE void typeNoteOnEnable(bool enable); Q_INVOKABLE void typeNoteOnEnable(bool enable);
Q_INVOKABLE void typePolyKeyPressureEnable(bool enable); Q_INVOKABLE void typePolyKeyPressureEnable(bool enable);
Q_INVOKABLE void typeControlChangeEnable(bool enable); Q_INVOKABLE void typeControlChangeEnable(bool enable);
Q_INVOKABLE void typeProgramChangeEnable(bool enable); Q_INVOKABLE void typeProgramChangeEnable(bool enable);
Q_INVOKABLE void typeChanPressureEnable(bool enable); Q_INVOKABLE void typeChanPressureEnable(bool enable);
Q_INVOKABLE void typePitchBendEnable(bool enable); Q_INVOKABLE void typePitchBendEnable(bool enable);
Q_INVOKABLE void typeSystemMessageEnable(bool enable); Q_INVOKABLE void typeSystemMessageEnable(bool enable);
public: public:
Midi(); Midi();
virtual ~Midi(); virtual ~Midi();
}; };
#endif // hifi_Midi_h #endif // hifi_Midi_h