Browse Source

Bridge port mapping

tags/v0.6.0
Andrew Belt 6 years ago
parent
commit
baadbda40d
3 changed files with 24 additions and 14 deletions
  1. +4
    -0
      src/Core/AudioInterface.cpp
  2. +3
    -6
      src/audio.cpp
  3. +17
    -8
      src/bridge.cpp

+ 4
- 0
src/Core/AudioInterface.cpp View File

@@ -78,6 +78,10 @@ struct AudioInterfaceIO : AudioIO {
inputBuffer.clear();
outputBuffer.clear();
}

void onChannelsChange() override {
debug("Channels changed %d %d", numOutputs, numInputs);
}
};




+ 3
- 6
src/audio.cpp View File

@@ -203,8 +203,7 @@ void AudioIO::openStream() {
if (rtAudio->isStreamOpen())
return;

numOutputs = clamp((int) deviceInfo.outputChannels - offset, 0, maxChannels);
numInputs = clamp((int) deviceInfo.inputChannels - offset, 0, maxChannels);
setChannels(clamp((int) deviceInfo.outputChannels - offset, 0, maxChannels), clamp((int) deviceInfo.inputChannels - offset, 0, maxChannels));

if (numOutputs == 0 && numInputs == 0) {
warn("RtAudio device %d has 0 inputs and 0 outputs");
@@ -258,8 +257,7 @@ void AudioIO::openStream() {
onOpenStream();
}
if (driver == BRIDGE_DRIVER) {
numOutputs = 0;
numInputs = 0;
setChannels(0, 0);
// TEMP
sampleRate = 44100;
blockSize = 256;
@@ -268,8 +266,7 @@ void AudioIO::openStream() {
}

void AudioIO::closeStream() {
numOutputs = 0;
numInputs = 0;
setChannels(0, 0);

if (rtAudio) {
if (rtAudio->isStreamRunning()) {


+ 17
- 8
src/bridge.cpp View File

@@ -57,6 +57,10 @@ struct BridgeClientConnection {
int audioBufferLength = -1;
bool audioActive = false;

~BridgeClientConnection() {
setPort(-1);
}

void send(const uint8_t *buffer, int length) {
if (length <= 0)
return;
@@ -66,7 +70,8 @@ struct BridgeClientConnection {
int sendFlags = 0;
#endif
ssize_t written = ::send(client, (const char*) buffer, length, sendFlags);
if (written < 0)
// We must write the entire buffer
if (written < length)
closeRequested = true;
}

@@ -163,7 +168,7 @@ struct BridgeClientConnection {
if (recvQueue.size() >= 3) {
uint8_t midiBuffer[3];
recvQueue.shiftBuffer(midiBuffer, 3);
debug("MIDI: %02x %02x %02x", midiBuffer[0], midiBuffer[1], midiBuffer[2]);
// debug("MIDI: %02x %02x %02x", midiBuffer[0], midiBuffer[1], midiBuffer[2]);
currentCommand = NO_COMMAND;
return true;
}
@@ -225,12 +230,14 @@ struct BridgeClientConnection {
case AUDIO_ACTIVATE: {
audioActive = true;
refreshAudioActive();
currentCommand = NO_COMMAND;
return true;
} break;

case AUDIO_DEACTIVATE: {
audioActive = false;
refreshAudioActive();
currentCommand = NO_COMMAND;
return true;
} break;

@@ -245,20 +252,18 @@ struct BridgeClientConnection {
}

void setPort(int newPort) {
if (!(0 <= newPort && newPort < BRIDGE_NUM_PORTS))
return;
// Unbind from existing port
if (connections[port] == this) {
if (port >= 0 && connections[port] == this) {
if (audioListeners[port])
audioListeners[port]->setChannels(0, 0);
connections[port] = NULL;
}

port = newPort;
// Bind to new port
if (!connections[port]) {
connections[port] = this;
if (newPort >= 0 && !connections[newPort]) {
connections[newPort] = this;
refreshAudioActive();
port = newPort;
}
else {
port = -1;
@@ -271,9 +276,12 @@ struct BridgeClientConnection {
if (!audioListeners[port])
return;
audioListeners[port]->processStream(input, output, frames);
debug("%d frames", frames);
}

void refreshAudioActive() {
if (!(0 <= port && port < BRIDGE_NUM_PORTS))
return;
if (!audioListeners[port])
return;
if (audioActive)
@@ -426,6 +434,7 @@ void bridgeDestroy() {
void bridgeAudioSubscribe(int port, AudioIO *audio) {
if (!(0 <= port && port < BRIDGE_NUM_PORTS))
return;
// Check if an Audio is already subscribed on the port
if (audioListeners[port])
return;
audioListeners[port] = audio;


Loading…
Cancel
Save