Browse Source

Put midi in namespace

tags/v1.0.0
Andrew Belt 5 years ago
parent
commit
00d039c465
17 changed files with 145 additions and 134 deletions
  1. +4
    -2
      include/app/MidiWidget.hpp
  2. +4
    -4
      include/bridge.hpp
  3. +4
    -4
      include/gamepad.hpp
  4. +4
    -4
      include/keyboard.hpp
  5. +39
    -36
      include/midi.hpp
  6. +4
    -4
      include/rtmidi.hpp
  7. +3
    -3
      src/Core/MIDICCToCVInterface.cpp
  8. +5
    -5
      src/Core/MIDIToCVInterface.cpp
  9. +3
    -3
      src/Core/MIDITriggerToCVInterface.cpp
  10. +4
    -4
      src/Core/QuadMIDIToCVInterface.cpp
  11. +3
    -3
      src/app/MidiWidget.cpp
  12. +7
    -7
      src/bridge.cpp
  13. +7
    -7
      src/gamepad.cpp
  14. +7
    -7
      src/keyboard.cpp
  15. +2
    -1
      src/main.cpp
  16. +38
    -33
      src/midi.cpp
  17. +7
    -7
      src/rtmidi.cpp

+ 4
- 2
include/app/MidiWidget.hpp View File

@@ -6,12 +6,14 @@
namespace rack {


struct MidiIO;
namespace midi {
struct IO;
}


struct MidiWidget : LedDisplay {
/** Not owned */
MidiIO *midiIO = NULL;
midi::IO *midiIO = NULL;
LedDisplayChoice *driverChoice;
LedDisplaySeparator *driverSeparator;
LedDisplayChoice *deviceChoice;


+ 4
- 4
include/bridge.hpp View File

@@ -7,18 +7,18 @@
namespace rack {


struct BridgeMidiInputDevice : MidiInputDevice {
struct BridgeMidiInputDevice : midi::InputDevice {
};


struct BridgeMidiDriver : MidiDriver {
struct BridgeMidiDriver : midi::Driver {
BridgeMidiInputDevice devices[16];
std::string getName() override {return "Bridge";}

std::vector<int> getInputDeviceIds() override;
std::string getInputDeviceName(int deviceId) override;
MidiInputDevice *subscribeInputDevice(int deviceId, MidiInput *midiInput) override;
void unsubscribeInputDevice(int deviceId, MidiInput *midiInput) override;
midi::InputDevice *subscribeInputDevice(int deviceId, midi::Input *input) override;
void unsubscribeInputDevice(int deviceId, midi::Input *input) override;
};




+ 4
- 4
include/gamepad.hpp View File

@@ -7,7 +7,7 @@ namespace rack {
namespace gamepad {


struct InputDevice : MidiInputDevice {
struct InputDevice : midi::InputDevice {
int deviceId;
std::vector<uint8_t> ccs;
std::vector<bool> states;
@@ -15,15 +15,15 @@ struct InputDevice : MidiInputDevice {
};


struct Driver : MidiDriver {
struct Driver : midi::Driver {
InputDevice devices[16];

Driver();
std::string getName() override {return "Gamepad";}
std::vector<int> getInputDeviceIds() override;
std::string getInputDeviceName(int deviceId) override;
MidiInputDevice *subscribeInputDevice(int deviceId, MidiInput *midiInput) override;
void unsubscribeInputDevice(int deviceId, MidiInput *midiInput) override;
midi::InputDevice *subscribeInputDevice(int deviceId, midi::Input *input) override;
void unsubscribeInputDevice(int deviceId, midi::Input *input) override;
};




+ 4
- 4
include/keyboard.hpp View File

@@ -8,7 +8,7 @@ namespace rack {
namespace keyboard {


struct InputDevice : MidiInputDevice {
struct InputDevice : midi::InputDevice {
int octave = 5;
std::map<int, int> pressedNotes;
void onKeyPress(int key);
@@ -16,14 +16,14 @@ struct InputDevice : MidiInputDevice {
};


struct Driver : MidiDriver {
struct Driver : midi::Driver {
InputDevice device;
std::string getName() override {return "Computer keyboard";}

std::vector<int> getInputDeviceIds() override;
std::string getInputDeviceName(int deviceId) override;
MidiInputDevice *subscribeInputDevice(int deviceId, MidiInput *midiInput) override;
void unsubscribeInputDevice(int deviceId, MidiInput *midiInput) override;
midi::InputDevice *subscribeInputDevice(int deviceId, midi::Input *input) override;
void unsubscribeInputDevice(int deviceId, midi::Input *input) override;
};




+ 39
- 36
include/midi.hpp View File

@@ -7,9 +7,10 @@


namespace rack {
namespace midi {


struct MidiMessage {
struct Message {
uint8_t cmd = 0x00;
uint8_t data1 = 0x00;
uint8_t data2 = 0x00;
@@ -29,50 +30,50 @@ struct MidiMessage {
};

////////////////////
// MidiDevice
// Device
////////////////////

struct MidiDevice {
virtual ~MidiDevice() {}
struct Device {
virtual ~Device() {}
};

struct MidiInput;
struct Input;

struct MidiInputDevice : MidiDevice {
std::set<MidiInput*> subscribed;
void subscribe(MidiInput *midiInput);
void unsubscribe(MidiInput *midiInput);
void onMessage(MidiMessage message);
struct InputDevice : Device {
std::set<Input*> subscribed;
void subscribe(Input *input);
void unsubscribe(Input *input);
void onMessage(Message message);
};

struct MidiOutputDevice : MidiDevice {
struct OutputDevice : Device {
// TODO
};

////////////////////
// MidiDriver
// Driver
////////////////////

struct MidiDriver {
virtual ~MidiDriver() {}
struct Driver {
virtual ~Driver() {}
virtual std::string getName() {return "";}

virtual std::vector<int> getInputDeviceIds() {return {};}
virtual std::string getInputDeviceName(int deviceId) {return "";}
virtual MidiInputDevice *subscribeInputDevice(int deviceId, MidiInput *midiInput) {return NULL;}
virtual void unsubscribeInputDevice(int deviceId, MidiInput *midiInput) {}
virtual InputDevice *subscribeInputDevice(int deviceId, Input *input) {return NULL;}
virtual void unsubscribeInputDevice(int deviceId, Input *input) {}

// virtual std::vector<int> getOutputDeviceIds() = 0;
// virtual std::string getOutputDeviceName(int deviceId) = 0;
// virtual MidiOutputDevice *subscribeOutputDevice(int deviceId, MidiOutput *midiOutput) = 0;
// virtual void unsubscribeOutputDevice(int deviceId, MidiOutput *midiOutput) = 0;
// virtual OutputDevice *subscribeOutputDevice(int deviceId, Output *midiOutput) = 0;
// virtual void unsubscribeOutputDevice(int deviceId, Output *midiOutput) = 0;
};

////////////////////
// MidiIO
// IO
////////////////////

struct MidiIO {
struct IO {
int driverId = -1;
int deviceId = -1;
/* For MIDI output, the channel to output messages.
@@ -82,9 +83,9 @@ struct MidiIO {
*/
int channel = -1;
/** Not owned */
MidiDriver *driver = NULL;
Driver *driver = NULL;

virtual ~MidiIO();
virtual ~IO();

std::vector<int> getDriverIds();
std::string getDriverName(int driverId);
@@ -100,36 +101,38 @@ struct MidiIO {
};


struct MidiInput : MidiIO {
MidiInput();
~MidiInput();
struct Input : IO {
Input();
~Input();

std::vector<int> getDeviceIds() override;
std::string getDeviceName(int deviceId) override;
void setDeviceId(int deviceId) override;
virtual void onMessage(MidiMessage message) {}
virtual void onMessage(Message message) {}
};


struct MidiInputQueue : MidiInput {
struct InputQueue : Input {
int queueMaxSize = 8192;
std::queue<MidiMessage> queue;
void onMessage(MidiMessage message) override;
/** If a MidiMessage is available, writes `message` and return true */
bool shift(MidiMessage *message);
std::queue<Message> queue;
void onMessage(Message message) override;
/** If a Message is available, writes `message` and return true */
bool shift(Message *message);
};


struct MidiOutput : MidiIO {
MidiOutput();
~MidiOutput();
struct Output : IO {
Output();
~Output();
void setDeviceId(int deviceId) override;
};


void midiDestroy();
void init();
void destroy();
/** Registers a new MIDI driver. Takes pointer ownership. */
void midiDriverAdd(int driverId, MidiDriver *driver);
void addDriver(int driverId, Driver *driver);


} // namespace midi
} // namespace rack

+ 4
- 4
include/rtmidi.hpp View File

@@ -14,7 +14,7 @@
namespace rack {


struct RtMidiInputDevice : MidiInputDevice {
struct RtMidiInputDevice : midi::InputDevice {
RtMidiIn *rtMidiIn;

RtMidiInputDevice(int driverId, int deviceId);
@@ -22,7 +22,7 @@ struct RtMidiInputDevice : MidiInputDevice {
};


struct RtMidiDriver : MidiDriver {
struct RtMidiDriver : midi::Driver {
int driverId;
/** Just for querying MIDI driver information */
RtMidiIn *rtMidiIn;
@@ -34,8 +34,8 @@ struct RtMidiDriver : MidiDriver {
std::string getName() override;
std::vector<int> getInputDeviceIds() override;
std::string getInputDeviceName(int deviceId) override;
MidiInputDevice *subscribeInputDevice(int deviceId, MidiInput *midiInput) override;
void unsubscribeInputDevice(int deviceId, MidiInput *midiInput) override;
midi::InputDevice *subscribeInputDevice(int deviceId, midi::Input *input) override;
void unsubscribeInputDevice(int deviceId, midi::Input *input) override;
};




+ 3
- 3
src/Core/MIDICCToCVInterface.cpp View File

@@ -18,7 +18,7 @@ struct MIDICCToCVInterface : Module {
NUM_LIGHTS
};

MidiInputQueue midiInput;
midi::InputQueue midiInput;
int8_t ccs[128];
ExponentialFilter ccFilters[16];

@@ -41,7 +41,7 @@ struct MIDICCToCVInterface : Module {
}

void step() override {
MidiMessage msg;
midi::Message msg;
while (midiInput.shift(&msg)) {
processMessage(msg);
}
@@ -55,7 +55,7 @@ struct MIDICCToCVInterface : Module {
}
}

void processMessage(MidiMessage msg) {
void processMessage(midi::Message msg) {
switch (msg.status()) {
// cc
case 0xb: {


+ 5
- 5
src/Core/MIDIToCVInterface.cpp View File

@@ -32,7 +32,7 @@ struct MIDIToCVInterface : Module {
NUM_LIGHTS
};

MidiInputQueue midiInput;
midi::InputQueue midiInput;

uint8_t mod = 0;
ExponentialFilter modFilter;
@@ -142,7 +142,7 @@ struct MIDIToCVInterface : Module {
}

void step() override {
MidiMessage msg;
midi::Message msg;
while (midiInput.shift(&msg)) {
processMessage(msg);
}
@@ -167,7 +167,7 @@ struct MIDIToCVInterface : Module {
outputs[CONTINUE_OUTPUT].value = continuePulse.process(deltaTime) ? 10.f : 0.f;
}

void processMessage(MidiMessage msg) {
void processMessage(midi::Message msg) {
// DEBUG("MIDI: %01x %01x %02x %02x", msg.status(), msg.channel(), msg.note(), msg.value());

switch (msg.status()) {
@@ -206,7 +206,7 @@ struct MIDIToCVInterface : Module {
}
}

void processCC(MidiMessage msg) {
void processCC(midi::Message msg) {
switch (msg.note()) {
// mod
case 0x01: {
@@ -223,7 +223,7 @@ struct MIDIToCVInterface : Module {
}
}

void processSystem(MidiMessage msg) {
void processSystem(midi::Message msg) {
switch (msg.channel()) {
// Timing
case 0x8: {


+ 3
- 3
src/Core/MIDITriggerToCVInterface.cpp View File

@@ -18,7 +18,7 @@ struct MIDITriggerToCVInterface : Module {
NUM_LIGHTS
};

MidiInputQueue midiInput;
midi::InputQueue midiInput;

bool gates[16];
float gateTimes[16];
@@ -67,7 +67,7 @@ struct MIDITriggerToCVInterface : Module {
}

void step() override {
MidiMessage msg;
midi::Message msg;
while (midiInput.shift(&msg)) {
processMessage(msg);
}
@@ -88,7 +88,7 @@ struct MIDITriggerToCVInterface : Module {
}
}

void processMessage(MidiMessage msg) {
void processMessage(midi::Message msg) {
switch (msg.status()) {
// note off
case 0x8: {


+ 4
- 4
src/Core/QuadMIDIToCVInterface.cpp View File

@@ -23,7 +23,7 @@ struct QuadMIDIToCVInterface : Module {
NUM_LIGHTS
};

MidiInputQueue midiInput;
midi::InputQueue midiInput;

enum PolyMode {
ROTATE_MODE,
@@ -243,7 +243,7 @@ struct QuadMIDIToCVInterface : Module {
}

void step() override {
MidiMessage msg;
midi::Message msg;
while (midiInput.shift(&msg)) {
processMessage(msg);
}
@@ -258,7 +258,7 @@ struct QuadMIDIToCVInterface : Module {
}
}

void processMessage(MidiMessage msg) {
void processMessage(midi::Message msg) {
switch (msg.status()) {
// note off
case 0x8: {
@@ -286,7 +286,7 @@ struct QuadMIDIToCVInterface : Module {
}
}

void processCC(MidiMessage msg) {
void processCC(midi::Message msg) {
switch (msg.note()) {
// sustain
case 0x40: {


+ 3
- 3
src/app/MidiWidget.cpp View File

@@ -7,7 +7,7 @@ namespace rack {


struct MidiDriverItem : MenuItem {
MidiIO *midiIO;
midi::IO *midiIO;
int driverId;
void onAction(event::Action &e) override {
midiIO->setDriverId(driverId);
@@ -41,7 +41,7 @@ struct MidiDriverChoice : LedDisplayChoice {
};

struct MidiDeviceItem : MenuItem {
MidiIO *midiIO;
midi::IO *midiIO;
int deviceId;
void onAction(event::Action &e) override {
midiIO->setDeviceId(deviceId);
@@ -83,7 +83,7 @@ struct MidiDeviceChoice : LedDisplayChoice {
};

struct MidiChannelItem : MenuItem {
MidiIO *midiIO;
midi::IO *midiIO;
int channel;
void onAction(event::Action &e) override {
midiIO->channel = channel;


+ 7
- 7
src/bridge.cpp View File

@@ -147,7 +147,7 @@ struct BridgeClientConnection {
} break;

case MIDI_MESSAGE_COMMAND: {
MidiMessage message;
midi::Message message;
if (!recv(&message, 3)) {
return;
}
@@ -203,7 +203,7 @@ struct BridgeClientConnection {
}
}

void processMidi(MidiMessage message) {
void processMidi(midi::Message message) {
if (!(0 <= port && port < BRIDGE_NUM_PORTS))
return;
if (!driver)
@@ -387,19 +387,19 @@ std::string BridgeMidiDriver::getInputDeviceName(int deviceId) {
return string::f("Port %d", deviceId + 1);
}

MidiInputDevice *BridgeMidiDriver::subscribeInputDevice(int deviceId, MidiInput *midiInput) {
midi::InputDevice *BridgeMidiDriver::subscribeInputDevice(int deviceId, midi::Input *input) {
if (!(0 <= deviceId && deviceId < 16))
return NULL;

devices[deviceId].subscribe(midiInput);
devices[deviceId].subscribe(input);
return &devices[deviceId];
}

void BridgeMidiDriver::unsubscribeInputDevice(int deviceId, MidiInput *midiInput) {
void BridgeMidiDriver::unsubscribeInputDevice(int deviceId, midi::Input *input) {
if (!(0 <= deviceId && deviceId < 16))
return;

devices[deviceId].unsubscribe(midiInput);
devices[deviceId].unsubscribe(input);
}


@@ -408,7 +408,7 @@ void bridgeInit() {
serverThread = std::thread(serverRun);

driver = new BridgeMidiDriver;
midiDriverAdd(BRIDGE_DRIVER, driver);
midi::addDriver(BRIDGE_DRIVER, driver);
}

void bridgeDestroy() {


+ 7
- 7
src/gamepad.cpp View File

@@ -29,7 +29,7 @@ void InputDevice::step() {
ccs[i] = cc;

// Send MIDI message
MidiMessage msg;
midi::Message msg;
// MIDI channel 1
msg.cmd = (0xb << 4) | 0;
msg.data1 = i;
@@ -45,7 +45,7 @@ void InputDevice::step() {
if (state != states[i]) {
states[i] = state;

MidiMessage msg;
midi::Message msg;
msg.cmd = ((state ? 0x9 : 0x8) << 4);
msg.data1 = i;
msg.data2 = 127;
@@ -82,25 +82,25 @@ std::string Driver::getInputDeviceName(int deviceId) {
return string::f(" %d (unavailable)", deviceId + 1);
}

MidiInputDevice *Driver::subscribeInputDevice(int deviceId, MidiInput *midiInput) {
midi::InputDevice *Driver::subscribeInputDevice(int deviceId, midi::Input *input) {
if (!(0 <= deviceId && deviceId < 16))
return NULL;

devices[deviceId].subscribe(midiInput);
devices[deviceId].subscribe(input);
return &devices[deviceId];
}

void Driver::unsubscribeInputDevice(int deviceId, MidiInput *midiInput) {
void Driver::unsubscribeInputDevice(int deviceId, midi::Input *input) {
if (!(0 <= deviceId && deviceId < 16))
return;

devices[deviceId].unsubscribe(midiInput);
devices[deviceId].unsubscribe(input);
}


void init() {
driver = new Driver;
midiDriverAdd(DRIVER, driver);
midi::addDriver(DRIVER, driver);
}

void step() {


+ 7
- 7
src/keyboard.cpp View File

@@ -69,7 +69,7 @@ void InputDevice::onKeyPress(int key) {
if (note > 127)
return;

MidiMessage msg;
midi::Message msg;
msg.cmd = 0x9 << 4;
msg.data1 = note;
msg.data2 = 127;
@@ -82,7 +82,7 @@ void InputDevice::onKeyRelease(int key) {
auto it = pressedNotes.find(key);
if (it != pressedNotes.end()) {
int note = it->second;
MidiMessage msg;
midi::Message msg;
msg.cmd = 0x8 << 4;
msg.data1 = note;
msg.data2 = 127;
@@ -103,25 +103,25 @@ std::string Driver::getInputDeviceName(int deviceId) {
return "";
}

MidiInputDevice *Driver::subscribeInputDevice(int deviceId, MidiInput *midiInput) {
midi::InputDevice *Driver::subscribeInputDevice(int deviceId, midi::Input *input) {
if (deviceId != 0)
return NULL;

device.subscribe(midiInput);
device.subscribe(input);
return &device;
}

void Driver::unsubscribeInputDevice(int deviceId, MidiInput *midiInput) {
void Driver::unsubscribeInputDevice(int deviceId, midi::Input *input) {
if (deviceId != 0)
return;

device.unsubscribe(midiInput);
device.unsubscribe(input);
}


void init() {
driver = new Driver;
midiDriverAdd(DRIVER, driver);
midi::addDriver(DRIVER, driver);
}

void press(int key) {


+ 2
- 1
src/main.cpp View File

@@ -65,6 +65,7 @@ int main(int argc, char *argv[]) {
asset::init(devMode);
logger::init(devMode);
tagsInit();
midi::init();
rtmidiInit();
bridgeInit();
keyboard::init();
@@ -130,7 +131,7 @@ int main(int argc, char *argv[]) {
plugin::destroy();
ui::destroy();
bridgeDestroy();
midiDestroy();
midi::destroy();
logger::destroy();

return 0;


+ 38
- 33
src/midi.cpp View File

@@ -4,52 +4,53 @@


namespace rack {
namespace midi {


static std::vector<int> driverIds;
static std::map<int, MidiDriver*> drivers;
static std::map<int, Driver*> drivers;


////////////////////
// MidiDevice
// Device
////////////////////

void MidiInputDevice::subscribe(MidiInput *midiInput) {
subscribed.insert(midiInput);
void InputDevice::subscribe(Input *input) {
subscribed.insert(input);
}

void MidiInputDevice::unsubscribe(MidiInput *midiInput) {
// Remove MidiInput from subscriptions
auto it = subscribed.find(midiInput);
void InputDevice::unsubscribe(Input *input) {
// Remove Input from subscriptions
auto it = subscribed.find(input);
if (it != subscribed.end())
subscribed.erase(it);
}

void MidiInputDevice::onMessage(MidiMessage message) {
for (MidiInput *midiInput : subscribed) {
midiInput->onMessage(message);
void InputDevice::onMessage(Message message) {
for (Input *input : subscribed) {
input->onMessage(message);
}
}

////////////////////
// MidiDriver
// Driver
////////////////////


////////////////////
// MidiIO
// IO
////////////////////

MidiIO::~MidiIO() {
IO::~IO() {
// Because of polymorphic destruction, descendants must call this in their own destructor
// setDriverId(-1);
}

std::vector<int> MidiIO::getDriverIds() {
std::vector<int> IO::getDriverIds() {
return driverIds;
}

std::string MidiIO::getDriverName(int driverId) {
std::string IO::getDriverName(int driverId) {
auto it = drivers.find(driverId);
if (it == drivers.end())
return "";
@@ -57,7 +58,7 @@ std::string MidiIO::getDriverName(int driverId) {
return it->second->getName();
}

void MidiIO::setDriverId(int driverId) {
void IO::setDriverId(int driverId) {
// Destroy driver
setDeviceId(-1);
if (driver) {
@@ -73,14 +74,14 @@ void MidiIO::setDriverId(int driverId) {
}
}

std::string MidiIO::getChannelName(int channel) {
std::string IO::getChannelName(int channel) {
if (channel == -1)
return "All channels";
else
return string::f("Channel %d", channel + 1);
}

json_t *MidiIO::toJson() {
json_t *IO::toJson() {
json_t *rootJ = json_object();
json_object_set_new(rootJ, "driver", json_integer(driverId));
std::string deviceName = getDeviceName(deviceId);
@@ -90,7 +91,7 @@ json_t *MidiIO::toJson() {
return rootJ;
}

void MidiIO::fromJson(json_t *rootJ) {
void IO::fromJson(json_t *rootJ) {
json_t *driverJ = json_object_get(rootJ, "driver");
if (driverJ)
setDriverId(json_integer_value(driverJ));
@@ -113,34 +114,34 @@ void MidiIO::fromJson(json_t *rootJ) {
}

////////////////////
// MidiInput
// Input
////////////////////

MidiInput::MidiInput() {
Input::Input() {
if (driverIds.size() >= 1) {
setDriverId(driverIds[0]);
}
}

MidiInput::~MidiInput() {
Input::~Input() {
setDriverId(-1);
}

std::vector<int> MidiInput::getDeviceIds() {
std::vector<int> Input::getDeviceIds() {
if (driver) {
return driver->getInputDeviceIds();
}
return {};
}

std::string MidiInput::getDeviceName(int deviceId) {
std::string Input::getDeviceName(int deviceId) {
if (driver) {
return driver->getInputDeviceName(deviceId);
}
return "";
}

void MidiInput::setDeviceId(int deviceId) {
void Input::setDeviceId(int deviceId) {
// Destroy device
if (driver && this->deviceId >= 0) {
driver->unsubscribeInputDevice(this->deviceId, this);
@@ -154,7 +155,7 @@ void MidiInput::setDeviceId(int deviceId) {
}
}

void MidiInputQueue::onMessage(MidiMessage message) {
void InputQueue::onMessage(Message message) {
// Filter channel
if (channel >= 0) {
if (message.status() != 0xf && message.channel() != channel)
@@ -166,7 +167,7 @@ void MidiInputQueue::onMessage(MidiMessage message) {
queue.push(message);
}

bool MidiInputQueue::shift(MidiMessage *message) {
bool InputQueue::shift(Message *message) {
if (!message)
return false;
if (!queue.empty()) {
@@ -178,17 +179,17 @@ bool MidiInputQueue::shift(MidiMessage *message) {
}

////////////////////
// MidiOutput
// Output
////////////////////

MidiOutput::MidiOutput() {
Output::Output() {
}

MidiOutput::~MidiOutput() {
Output::~Output() {
setDriverId(-1);
}

void MidiOutput::setDeviceId(int deviceId) {
void Output::setDeviceId(int deviceId) {
// TODO
}

@@ -196,7 +197,10 @@ void MidiOutput::setDeviceId(int deviceId) {
// midi
////////////////////

void midiDestroy() {
void init() {
}

void destroy() {
driverIds.clear();
for (auto &pair : drivers) {
delete pair.second;
@@ -204,11 +208,12 @@ void midiDestroy() {
drivers.clear();
}

void midiDriverAdd(int driverId, MidiDriver *driver) {
void addDriver(int driverId, Driver *driver) {
assert(driver);
driverIds.push_back(driverId);
drivers[driverId] = driver;
}


} // namespace midi
} // namespace rack

+ 7
- 7
src/rtmidi.cpp View File

@@ -11,7 +11,7 @@ static void midiInputCallback(double timeStamp, std::vector<unsigned char> *mess

RtMidiInputDevice *midiInputDevice = (RtMidiInputDevice*) userData;
if (!midiInputDevice) return;
MidiMessage msg;
midi::Message msg;
if (message->size() >= 1)
msg.cmd = (*message)[0];
if (message->size() >= 2)
@@ -77,7 +77,7 @@ std::string RtMidiDriver::getInputDeviceName(int deviceId) {
return "";
}

MidiInputDevice *RtMidiDriver::subscribeInputDevice(int deviceId, MidiInput *midiInput) {
midi::InputDevice *RtMidiDriver::subscribeInputDevice(int deviceId, midi::Input *input) {
if (!(0 <= deviceId && deviceId < (int) rtMidiIn->getPortCount()))
return NULL;
RtMidiInputDevice *device = devices[deviceId];
@@ -85,16 +85,16 @@ MidiInputDevice *RtMidiDriver::subscribeInputDevice(int deviceId, MidiInput *mid
devices[deviceId] = device = new RtMidiInputDevice(driverId, deviceId);
}

device->subscribe(midiInput);
device->subscribe(input);
return device;
}

void RtMidiDriver::unsubscribeInputDevice(int deviceId, MidiInput *midiInput) {
void RtMidiDriver::unsubscribeInputDevice(int deviceId, midi::Input *input) {
auto it = devices.find(deviceId);
if (it == devices.end())
return;
RtMidiInputDevice *device = it->second;
device->unsubscribe(midiInput);
device->unsubscribe(input);

// Destroy device if nothing is subscribed anymore
if (device->subscribed.empty()) {
@@ -109,8 +109,8 @@ void rtmidiInit() {
RtMidi::getCompiledApi(rtApis);
for (RtMidi::Api api : rtApis) {
int driverId = (int) api;
MidiDriver *driver = new RtMidiDriver(driverId);
midiDriverAdd(driverId, driver);
midi::Driver *driver = new RtMidiDriver(driverId);
midi::addDriver(driverId, driver);
}
}



Loading…
Cancel
Save