Browse Source

Fix incorrect channel count display in AudioWidget.

tags/v2.0.0
Andrew Belt 3 years ago
parent
commit
b458c189a0
3 changed files with 16 additions and 13 deletions
  1. +1
    -0
      include/audio.hpp
  2. +13
    -11
      src/app/AudioWidget.cpp
  3. +2
    -2
      src/audio.cpp

+ 1
- 0
include/audio.hpp View File

@@ -173,6 +173,7 @@ struct Port {
int getBlockSize(); int getBlockSize();
void setBlockSize(int blockSize); void setBlockSize(int blockSize);


/** Returns the number of active Port inputs, considering inputOffset and maxInputs. */
int getNumInputs(); int getNumInputs();
int getNumOutputs(); int getNumOutputs();




+ 13
- 11
src/app/AudioWidget.cpp View File

@@ -8,17 +8,17 @@ namespace rack {
namespace app { namespace app {




static std::string getDetailTemplate(std::string name, int numInputs, int inputOffset, int maxInputs, int numOutputs, int outputOffset, int maxOutputs) {
static std::string getDetailTemplate(std::string name, int numInputs, int inputOffset, int numOutputs, int outputOffset) {
std::string text = name; std::string text = name;
text += " ("; text += " (";
if (inputOffset < numInputs) {
text += string::f("%d-%d in", inputOffset + 1, std::min(inputOffset + maxInputs, numInputs));
if (numInputs > 0) {
text += string::f("%d-%d in", inputOffset + 1, inputOffset + numInputs + 1);
} }
if (inputOffset < numInputs && outputOffset < numOutputs) {
if (numInputs > 0 && numOutputs > 0) {
text += ", "; text += ", ";
} }
if (outputOffset < numOutputs) {
text += string::f("%d-%d out", outputOffset + 1, std::min(outputOffset + maxOutputs, numOutputs));
if (numOutputs > 0) {
text += string::f("%d-%d out", outputOffset + 1, outputOffset + numOutputs + 1);
} }
text += ")"; text += ")";
return text; return text;
@@ -107,23 +107,25 @@ static void appendAudioDeviceMenu(ui::Menu* menu, audio::Port* port) {
} }


for (int deviceId : port->getDeviceIds()) { for (int deviceId : port->getDeviceIds()) {
int numInputs = port->getDeviceNumInputs(deviceId);
int numOutputs = port->getDeviceNumOutputs(deviceId);
int numDeviceInputs = port->getDeviceNumInputs(deviceId);
int numDeviceOutputs = port->getDeviceNumOutputs(deviceId);
std::string name = port->getDeviceName(deviceId); std::string name = port->getDeviceName(deviceId);


// Display only 8 channel offsets per device, because some virtual devices (e.g. ALSA) can have thousands of useless channels. // Display only 8 channel offsets per device, because some virtual devices (e.g. ALSA) can have thousands of useless channels.
for (int i = 0; i < 8; i++) { for (int i = 0; i < 8; i++) {
int inputOffset = i * port->maxInputs; int inputOffset = i * port->maxInputs;
int outputOffset = i * port->maxOutputs; int outputOffset = i * port->maxOutputs;
if (inputOffset >= numInputs && outputOffset >= numOutputs)
if (inputOffset >= numDeviceInputs && outputOffset >= numDeviceOutputs)
break; break;
int numInputs = math::clamp(numDeviceInputs - inputOffset, 0, port->maxInputs);
int numOutputs = math::clamp(numDeviceOutputs - outputOffset, 0, port->maxOutputs);


AudioDeviceValueItem* item = new AudioDeviceValueItem; AudioDeviceValueItem* item = new AudioDeviceValueItem;
item->port = port; item->port = port;
item->deviceId = deviceId; item->deviceId = deviceId;
item->inputOffset = inputOffset; item->inputOffset = inputOffset;
item->outputOffset = outputOffset; item->outputOffset = outputOffset;
item->text = getDetailTemplate(name, numInputs, inputOffset, port->maxInputs, numOutputs, outputOffset, port->maxOutputs);
item->text = getDetailTemplate(name, numInputs, inputOffset, numOutputs, outputOffset);
item->rightText = CHECKMARK(deviceId == port->getDeviceId() && inputOffset == port->inputOffset && outputOffset == port->outputOffset); item->rightText = CHECKMARK(deviceId == port->getDeviceId() && inputOffset == port->inputOffset && outputOffset == port->outputOffset);
menu->addChild(item); menu->addChild(item);
} }
@@ -144,7 +146,7 @@ struct AudioDeviceChoice : LedDisplayChoice {
text += "Device: "; text += "Device: ";
std::string detail = ""; std::string detail = "";
if (port && port->getDevice()) if (port && port->getDevice())
detail = getDetailTemplate(port->getDevice()->getName(), port->getNumInputs(), port->inputOffset, port->maxInputs, port->getNumOutputs(), port->outputOffset, port->maxOutputs);
detail = getDetailTemplate(port->getDevice()->getName(), port->getNumInputs(), port->inputOffset, port->getNumOutputs(), port->outputOffset);


if (detail != "") { if (detail != "") {
text += detail; text += detail;


+ 2
- 2
src/audio.cpp View File

@@ -288,7 +288,7 @@ int Port::getNumInputs() {
if (!device) if (!device)
return 0; return 0;
try { try {
return std::min(device->getNumInputs() - inputOffset, maxInputs);
return std::min(std::max(device->getNumInputs() - inputOffset, 0), maxInputs);
} }
catch (Exception& e) { catch (Exception& e) {
WARN("Audio port could not get device number of inputs: %s", e.what()); WARN("Audio port could not get device number of inputs: %s", e.what());
@@ -300,7 +300,7 @@ int Port::getNumOutputs() {
if (!device) if (!device)
return 0; return 0;
try { try {
return std::min(device->getNumOutputs() - outputOffset, maxOutputs);
return std::min(std::max(device->getNumOutputs() - outputOffset, 0), maxOutputs);
} }
catch (Exception& e) { catch (Exception& e) {
WARN("Audio port could not get device number of outputs: %s", e.what()); WARN("Audio port could not get device number of outputs: %s", e.what());


Loading…
Cancel
Save