| 92 | }; |
| 93 | |
| 94 | static void appendAudioDeviceMenu(ui::Menu* menu, audio::Port* port) { |
| 95 | if (!port) |
| 96 | return; |
| 97 | |
| 98 | { |
| 99 | AudioDeviceValueItem* item = new AudioDeviceValueItem; |
| 100 | item->port = port; |
| 101 | item->deviceId = -1; |
| 102 | item->text = "(" + string::translate("AudioDisplay.noDevice") + ")"; |
| 103 | item->rightText = CHECKMARK(item->deviceId == port->getDeviceId()); |
| 104 | menu->addChild(item); |
| 105 | } |
| 106 | |
| 107 | for (int deviceId : port->getDeviceIds()) { |
| 108 | int numDeviceInputs = port->getDeviceNumInputs(deviceId); |
| 109 | int numDeviceOutputs = port->getDeviceNumOutputs(deviceId); |
| 110 | std::string name = port->getDeviceName(deviceId); |
| 111 | |
| 112 | // Display only 32 channel offsets per device, because some virtual devices (e.g. ALSA) can have thousands of useless channels. |
| 113 | for (int i = 0; i < 32; i++) { |
| 114 | int inputOffset = i * port->maxInputs; |
| 115 | int outputOffset = i * port->maxOutputs; |
| 116 | if (inputOffset >= numDeviceInputs && outputOffset >= numDeviceOutputs) |
| 117 | break; |
| 118 | int numInputs = math::clamp(numDeviceInputs - inputOffset, 0, port->maxInputs); |
| 119 | int numOutputs = math::clamp(numDeviceOutputs - outputOffset, 0, port->maxOutputs); |
| 120 | |
| 121 | AudioDeviceValueItem* item = new AudioDeviceValueItem; |
| 122 | item->port = port; |
| 123 | item->deviceId = deviceId; |
| 124 | item->inputOffset = inputOffset; |
| 125 | item->outputOffset = outputOffset; |
| 126 | item->text = getDetailTemplate(name, numInputs, inputOffset, numOutputs, outputOffset); |
| 127 | item->rightText = CHECKMARK(deviceId == port->getDeviceId() && inputOffset == port->inputOffset && outputOffset == port->outputOffset); |
| 128 | menu->addChild(item); |
| 129 | } |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | void AudioDeviceChoice::onAction(const ActionEvent& e) { |
| 134 | ui::Menu* menu = createMenu(); |
no test coverage detected