Browse Source

Add MIDI to Bridge

tags/v0.6.0
Andrew Belt 6 years ago
parent
commit
79158297bc
5 changed files with 26 additions and 18 deletions
  1. +1
    -1
      dep/oui-blendish
  2. +2
    -2
      include/bridge.hpp
  3. +1
    -3
      include/midi.hpp
  4. +3
    -3
      src/bridge.cpp
  5. +19
    -9
      src/midi.cpp

+ 1
- 1
dep/oui-blendish

@@ -1 +1 @@
Subproject commit b7066201022a757cbcbd986d8c91d565e4daef90
Subproject commit 383f24f6ed41facf25eda0d32b0f6bc9aee96e53

+ 2
- 2
include/bridge.hpp View File

@@ -9,8 +9,8 @@ namespace rack {

void bridgeInit();
void bridgeDestroy();
void bridgeMidiSubscribe(int channel, MidiInput *midi);
void bridgeMidiUnsubscribe(int channel, MidiInput *midi);
void bridgeMidiSubscribe(int channel, MidiIO *midi);
void bridgeMidiUnsubscribe(int channel, MidiIO *midi);
void bridgeAudioSubscribe(int channel, AudioIO *audio);
void bridgeAudioUnsubscribe(int channel, AudioIO *audio);



+ 1
- 3
include/midi.hpp View File

@@ -58,10 +58,9 @@ struct MidiIO {
void setDevice(int device);

std::string getChannelName(int channel);
/** Returns whether the audio stream is open and running */
bool isActive();
json_t *toJson();
void fromJson(json_t *rootJ);
virtual void onMessage(MidiMessage message) {}
};


@@ -70,7 +69,6 @@ struct MidiInput : MidiIO {
MidiInput();
~MidiInput();
void setDriver(int driver) override;
virtual void onMessage(MidiMessage message) {}
};




+ 3
- 3
src/bridge.cpp View File

@@ -23,7 +23,7 @@ namespace rack {
struct BridgeClientConnection;
static BridgeClientConnection *connections[BRIDGE_NUM_PORTS] = {};
static AudioIO *audioListeners[BRIDGE_NUM_PORTS] = {};
static MidiInput *midiListeners[BRIDGE_NUM_PORTS] = {};
static MidiIO *midiListeners[BRIDGE_NUM_PORTS] = {};
static std::thread serverThread;
static bool serverRunning = false;

@@ -377,7 +377,7 @@ void bridgeDestroy() {
serverThread.join();
}

void bridgeMidiSubscribe(int port, MidiInput *midi) {
void bridgeMidiSubscribe(int port, MidiIO *midi) {
if (!(0 <= port && port < BRIDGE_NUM_PORTS))
return;
// Check if a Midi is already subscribed on the port
@@ -388,7 +388,7 @@ void bridgeMidiSubscribe(int port, MidiInput *midi) {
connections[port]->refreshAudio();
}

void bridgeMidiUnsubscribe(int port, MidiInput *midi) {
void bridgeMidiUnsubscribe(int port, MidiIO *midi) {
if (!(0 <= port && port < BRIDGE_NUM_PORTS))
return;
if (midiListeners[port] != midi)


+ 19
- 9
src/midi.cpp View File

@@ -39,18 +39,25 @@ int MidiIO::getDeviceCount() {
if (rtMidi) {
return rtMidi->getPortCount();
}
else if (driver == BRIDGE_DRIVER) {
return BRIDGE_NUM_PORTS;
}
return 0;
}

std::string MidiIO::getDeviceName(int device) {
if (device < 0)
return "";

if (rtMidi) {
if (device < 0)
return "";
if (device == this->device)
return deviceName;
else
return rtMidi->getPortName(device);
}
else if (driver == BRIDGE_DRIVER) {
return stringf("Port %d", device + 1);
}
return "";
}

@@ -64,6 +71,15 @@ void MidiIO::setDevice(int device) {
}
this->device = device;
}
else if (driver == BRIDGE_DRIVER) {
if (device >= 0) {
bridgeMidiSubscribe(device, this);
}
else {
bridgeMidiUnsubscribe(device, this);
}
this->device = device;
}
}

std::string MidiIO::getChannelName(int channel) {
@@ -73,12 +89,6 @@ std::string MidiIO::getChannelName(int channel) {
return stringf("Channel %d", channel + 1);
}

bool MidiIO::isActive() {
if (rtMidi)
return rtMidi->isPortOpen();
return false;
}

json_t *MidiIO::toJson() {
json_t *rootJ = json_object();
json_object_set_new(rootJ, "driver", json_integer(driver));
@@ -156,7 +166,7 @@ void MidiInput::setDriver(int driver) {
this->driver = rtMidiIn->getCurrentApi();
}
else if (driver == BRIDGE_DRIVER) {
this->driver = BRIDGE_DRIVER;
}
}



Loading…
Cancel
Save