return samples_out;
}
-vector<string> AudioMixer::get_names() const
+map<DeviceSpec, string> AudioMixer::get_names() const
{
lock_guard<mutex> lock(audio_mutex);
- vector<string> names;
+ map<DeviceSpec, string> names;
for (unsigned card_index = 0; card_index < num_cards; ++card_index) {
+ const DeviceSpec spec{ InputSourceType::CAPTURE_CARD, card_index };
const AudioDevice *device = &cards[card_index];
- names.push_back(device->name);
+ names.insert(make_pair(spec, device->name));
}
return names;
}
InputSourceType type;
unsigned index;
+ bool operator== (const DeviceSpec &other) const {
+ return type == other.type && index == other.index;
+ }
+
bool operator< (const DeviceSpec &other) const {
if (type != other.type)
return type < other.type;
}
};
+static inline uint64_t DeviceSpec_to_key(const DeviceSpec &device_spec)
+{
+ return (uint64_t(device_spec.type) << 32) | device_spec.index;
+}
+
+static inline DeviceSpec key_to_DeviceSpec(uint64_t key)
+{
+ return DeviceSpec{ InputSourceType(key >> 32), unsigned(key & 0xffffffff) };
+}
+
struct InputMapping {
struct Bus {
std::string name;
void set_current_loudness(double level_lufs) { loudness_lufs = level_lufs; }
void set_fader_volume(unsigned bus_index, float level_db) { fader_volume_db[bus_index] = level_db; }
- std::vector<std::string> get_names() const;
+ std::map<DeviceSpec, std::string> get_names() const;
void set_name(DeviceSpec device_spec, const std::string &name);
void set_input_mapping(const InputMapping &input_mapping);
// Card choices.
QComboBox *card_combo = new QComboBox;
+ unsigned current_index = 0;
card_combo->addItem(QString("(none) "));
- for (const string &name : card_names) {
- card_combo->addItem(QString::fromStdString(name + " "));
- }
- switch (bus.device.type) {
- case InputSourceType::SILENCE:
- card_combo->setCurrentIndex(0);
- break;
- case InputSourceType::CAPTURE_CARD:
- card_combo->setCurrentIndex(mapping.buses[row].device.index + 1);
- break;
- default:
- assert(false);
+ for (const auto &spec_and_name : card_names) {
+ ++current_index;
+ card_combo->addItem(
+ QString::fromStdString(spec_and_name.second + " "),
+ qulonglong(DeviceSpec_to_key(spec_and_name.first)));
+ if (bus.device == spec_and_name.first) {
+ card_combo->setCurrentIndex(current_index);
+ }
}
connect(card_combo, static_cast<void(QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
- bind(&InputMappingDialog::card_selected, this, row, _1));
+ bind(&InputMappingDialog::card_selected, this, card_combo, row, _1));
ui->table->setCellWidget(row, 1, card_combo);
setup_channel_choices_from_bus(row, bus);
mapping.buses[row].name = ui->table->item(row, column)->text().toStdString();
}
-void InputMappingDialog::card_selected(unsigned row, int index)
+void InputMappingDialog::card_selected(QComboBox *card_combo, unsigned row, int index)
{
- if (index == 0) {
- mapping.buses[row].device.type = InputSourceType::SILENCE;
- } else {
- mapping.buses[row].device.type = InputSourceType::CAPTURE_CARD;
- mapping.buses[row].device.index = index - 1;
- }
+ uint64_t key = card_combo->itemData(index).toULongLong();
+ mapping.buses[row].device = key_to_DeviceSpec(key);
setup_channel_choices_from_bus(row, mapping.buses[row]);
}
class InputMappingDialog;
} // namespace Ui
+class QComboBox;
+
class InputMappingDialog : public QDialog
{
Q_OBJECT
void fill_row_from_bus(unsigned row, const InputMapping::Bus &bus);
void setup_channel_choices_from_bus(unsigned row, const InputMapping::Bus &bus);
void cell_changed(int row, int column);
- void card_selected(unsigned row, int index);
+ void card_selected(QComboBox *card_combo, unsigned row, int index);
void channel_selected(unsigned row, unsigned channel, int index);
void ok_clicked();
void cancel_clicked();
// held forever).
InputMapping old_mapping;
- const std::vector<std::string> card_names;
+ const std::map<DeviceSpec, std::string> card_names;
};
#endif // !defined(_INPUT_MAPPING_DIALOG_H)