@@ -1 +1 @@ | |||||
Subproject commit b7066201022a757cbcbd986d8c91d565e4daef90 | |||||
Subproject commit 383f24f6ed41facf25eda0d32b0f6bc9aee96e53 |
@@ -9,8 +9,8 @@ namespace rack { | |||||
void bridgeInit(); | void bridgeInit(); | ||||
void bridgeDestroy(); | 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 bridgeAudioSubscribe(int channel, AudioIO *audio); | ||||
void bridgeAudioUnsubscribe(int channel, AudioIO *audio); | void bridgeAudioUnsubscribe(int channel, AudioIO *audio); | ||||
@@ -58,10 +58,9 @@ struct MidiIO { | |||||
void setDevice(int device); | void setDevice(int device); | ||||
std::string getChannelName(int channel); | std::string getChannelName(int channel); | ||||
/** Returns whether the audio stream is open and running */ | |||||
bool isActive(); | |||||
json_t *toJson(); | json_t *toJson(); | ||||
void fromJson(json_t *rootJ); | void fromJson(json_t *rootJ); | ||||
virtual void onMessage(MidiMessage message) {} | |||||
}; | }; | ||||
@@ -70,7 +69,6 @@ struct MidiInput : MidiIO { | |||||
MidiInput(); | MidiInput(); | ||||
~MidiInput(); | ~MidiInput(); | ||||
void setDriver(int driver) override; | void setDriver(int driver) override; | ||||
virtual void onMessage(MidiMessage message) {} | |||||
}; | }; | ||||
@@ -23,7 +23,7 @@ namespace rack { | |||||
struct BridgeClientConnection; | struct BridgeClientConnection; | ||||
static BridgeClientConnection *connections[BRIDGE_NUM_PORTS] = {}; | static BridgeClientConnection *connections[BRIDGE_NUM_PORTS] = {}; | ||||
static AudioIO *audioListeners[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 std::thread serverThread; | ||||
static bool serverRunning = false; | static bool serverRunning = false; | ||||
@@ -377,7 +377,7 @@ void bridgeDestroy() { | |||||
serverThread.join(); | serverThread.join(); | ||||
} | } | ||||
void bridgeMidiSubscribe(int port, MidiInput *midi) { | |||||
void bridgeMidiSubscribe(int port, MidiIO *midi) { | |||||
if (!(0 <= port && port < BRIDGE_NUM_PORTS)) | if (!(0 <= port && port < BRIDGE_NUM_PORTS)) | ||||
return; | return; | ||||
// Check if a Midi is already subscribed on the port | // Check if a Midi is already subscribed on the port | ||||
@@ -388,7 +388,7 @@ void bridgeMidiSubscribe(int port, MidiInput *midi) { | |||||
connections[port]->refreshAudio(); | connections[port]->refreshAudio(); | ||||
} | } | ||||
void bridgeMidiUnsubscribe(int port, MidiInput *midi) { | |||||
void bridgeMidiUnsubscribe(int port, MidiIO *midi) { | |||||
if (!(0 <= port && port < BRIDGE_NUM_PORTS)) | if (!(0 <= port && port < BRIDGE_NUM_PORTS)) | ||||
return; | return; | ||||
if (midiListeners[port] != midi) | if (midiListeners[port] != midi) | ||||
@@ -39,18 +39,25 @@ int MidiIO::getDeviceCount() { | |||||
if (rtMidi) { | if (rtMidi) { | ||||
return rtMidi->getPortCount(); | return rtMidi->getPortCount(); | ||||
} | } | ||||
else if (driver == BRIDGE_DRIVER) { | |||||
return BRIDGE_NUM_PORTS; | |||||
} | |||||
return 0; | return 0; | ||||
} | } | ||||
std::string MidiIO::getDeviceName(int device) { | std::string MidiIO::getDeviceName(int device) { | ||||
if (device < 0) | |||||
return ""; | |||||
if (rtMidi) { | if (rtMidi) { | ||||
if (device < 0) | |||||
return ""; | |||||
if (device == this->device) | if (device == this->device) | ||||
return deviceName; | return deviceName; | ||||
else | else | ||||
return rtMidi->getPortName(device); | return rtMidi->getPortName(device); | ||||
} | } | ||||
else if (driver == BRIDGE_DRIVER) { | |||||
return stringf("Port %d", device + 1); | |||||
} | |||||
return ""; | return ""; | ||||
} | } | ||||
@@ -64,6 +71,15 @@ void MidiIO::setDevice(int device) { | |||||
} | } | ||||
this->device = 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) { | std::string MidiIO::getChannelName(int channel) { | ||||
@@ -73,12 +89,6 @@ std::string MidiIO::getChannelName(int channel) { | |||||
return stringf("Channel %d", channel + 1); | return stringf("Channel %d", channel + 1); | ||||
} | } | ||||
bool MidiIO::isActive() { | |||||
if (rtMidi) | |||||
return rtMidi->isPortOpen(); | |||||
return false; | |||||
} | |||||
json_t *MidiIO::toJson() { | json_t *MidiIO::toJson() { | ||||
json_t *rootJ = json_object(); | json_t *rootJ = json_object(); | ||||
json_object_set_new(rootJ, "driver", json_integer(driver)); | json_object_set_new(rootJ, "driver", json_integer(driver)); | ||||
@@ -156,7 +166,7 @@ void MidiInput::setDriver(int driver) { | |||||
this->driver = rtMidiIn->getCurrentApi(); | this->driver = rtMidiIn->getCurrentApi(); | ||||
} | } | ||||
else if (driver == BRIDGE_DRIVER) { | else if (driver == BRIDGE_DRIVER) { | ||||
this->driver = BRIDGE_DRIVER; | |||||
} | } | ||||
} | } | ||||