diff --git a/include/audio.hpp b/include/audio.hpp index fedadd1a..9b7c5048 100644 --- a/include/audio.hpp +++ b/include/audio.hpp @@ -177,6 +177,9 @@ struct Port { int getBlockSize(); void setBlockSize(int blockSize); + int getOffset(); + void setOffset(int offset); + int getNumInputs(); int getNumOutputs(); diff --git a/src/app/AudioWidget.cpp b/src/app/AudioWidget.cpp index 51f6e836..4e0f7017 100644 --- a/src/app/AudioWidget.cpp +++ b/src/app/AudioWidget.cpp @@ -70,7 +70,7 @@ struct AudioDeviceValueItem : ui::MenuItem { int offset; void onAction(const event::Action& e) override { port->setDeviceId(deviceId); - port->offset = offset; + port->setOffset(offset); } }; @@ -99,7 +99,7 @@ static void appendAudioDeviceMenu(ui::Menu* menu, audio::Port* port) { item->deviceId = deviceId; item->offset = offset; item->text = port->getDeviceDetail(deviceId, offset); - item->rightText = CHECKMARK(item->deviceId == port->getDeviceId() && item->offset == port->offset); + item->rightText = CHECKMARK(item->deviceId == port->getDeviceId() && item->offset == port->getOffset()); menu->addChild(item); } } @@ -117,7 +117,7 @@ struct AudioDeviceChoice : LedDisplayChoice { text = ""; if (box.size.x >= 200.0) text += "Device: "; - std::string detail = (port && port->device) ? port->device->getDetail(port->offset, port->maxChannels) : ""; + std::string detail = (port && port->device) ? port->device->getDetail(port->getOffset(), port->maxChannels) : ""; if (detail != "") { text += detail; color.a = 1.0; diff --git a/src/audio.cpp b/src/audio.cpp index 9c71c982..1690684e 100644 --- a/src/audio.cpp +++ b/src/audio.cpp @@ -56,15 +56,15 @@ void Device::processBuffer(const float* input, int inputStride, float* output, i for (Port* port : subscribed) { // Setting the thread context should probably be the responsibility of Port, but because processInput() etc are overridden, this is the only good place for it. contextSet(port->context); - port->processInput(input + port->offset, inputStride, frames); + port->processInput(input + port->getOffset(), inputStride, frames); } for (Port* port : subscribed) { contextSet(port->context); - port->processBuffer(input + port->offset, inputStride, output + port->offset, outputStride, frames); + port->processBuffer(input + port->getOffset(), inputStride, output + port->getOffset(), outputStride, frames); } for (Port* port : subscribed) { contextSet(port->context); - port->processOutput(output + port->offset, outputStride, frames); + port->processOutput(output + port->getOffset(), outputStride, frames); } } @@ -103,7 +103,7 @@ void Port::reset() { firstDriverId = driverIds[0]; setDriverId(firstDriverId); - offset = 0; + setOffset(0); } Driver* Port::getDriver() { @@ -312,11 +312,20 @@ void Port::setBlockSize(int blockSize) { } } +int Port::getOffset() { + return offset; +} + +void Port::setOffset(int offset) { + this->offset = offset; +} + + int Port::getNumInputs() { if (!device) return 0; try { - return std::min(device->getNumInputs() - offset, maxChannels); + return std::min(device->getNumInputs() - getOffset(), maxChannels); } catch (Exception& e) { WARN("Audio port could not get device number of inputs: %s", e.what()); @@ -328,7 +337,7 @@ int Port::getNumOutputs() { if (!device) return 0; try { - return std::min(device->getNumOutputs() - offset, maxChannels); + return std::min(device->getNumOutputs() - getOffset(), maxChannels); } catch (Exception& e) { WARN("Audio port could not get device number of outputs: %s", e.what()); @@ -347,7 +356,7 @@ json_t* Port::toJson() { json_object_set_new(rootJ, "sampleRate", json_real(getSampleRate())); json_object_set_new(rootJ, "blockSize", json_integer(getBlockSize())); - json_object_set_new(rootJ, "offset", json_integer(offset)); + json_object_set_new(rootJ, "offset", json_integer(getOffset())); return rootJ; } @@ -385,7 +394,7 @@ void Port::fromJson(json_t* rootJ) { json_t* offsetJ = json_object_get(rootJ, "offset"); if (offsetJ) - offset = json_integer_value(offsetJ); + setOffset(json_integer_value(offsetJ)); } ////////////////////