Browse Source

Merge branch 'master' of github.com:VCVRack/Rack

tags/v0.6.0
Andrew Belt 6 years ago
parent
commit
20bb0a95c9
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(); inputBuffer.clear();
outputBuffer.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()) if (rtAudio->isStreamOpen())
return; 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) { if (numOutputs == 0 && numInputs == 0) {
warn("RtAudio device %d has 0 inputs and 0 outputs"); warn("RtAudio device %d has 0 inputs and 0 outputs");
@@ -258,8 +257,7 @@ void AudioIO::openStream() {
onOpenStream(); onOpenStream();
} }
if (driver == BRIDGE_DRIVER) { if (driver == BRIDGE_DRIVER) {
numOutputs = 0;
numInputs = 0;
setChannels(0, 0);
// TEMP // TEMP
sampleRate = 44100; sampleRate = 44100;
blockSize = 256; blockSize = 256;
@@ -268,8 +266,7 @@ void AudioIO::openStream() {
} }


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


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


+ 17
- 8
src/bridge.cpp View File

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


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

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


@@ -163,7 +168,7 @@ struct BridgeClientConnection {
if (recvQueue.size() >= 3) { if (recvQueue.size() >= 3) {
uint8_t midiBuffer[3]; uint8_t midiBuffer[3];
recvQueue.shiftBuffer(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; currentCommand = NO_COMMAND;
return true; return true;
} }
@@ -225,12 +230,14 @@ struct BridgeClientConnection {
case AUDIO_ACTIVATE: { case AUDIO_ACTIVATE: {
audioActive = true; audioActive = true;
refreshAudioActive(); refreshAudioActive();
currentCommand = NO_COMMAND;
return true; return true;
} break; } break;


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


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


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


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


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


Loading…
Cancel
Save