X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=input_mapping_dialog.cpp;h=2d40cc2a500a839557e46aef541fa1c52677a86f;hb=95c6bc9d8e340b02112f713389390102d547cc4c;hp=a34b6cb955ec8705d1108bca47d60bdc871e0741;hpb=c013fcb39c018410ce49333d5665f9bc682de1db;p=nageru diff --git a/input_mapping_dialog.cpp b/input_mapping_dialog.cpp index a34b6cb..2d40cc2 100644 --- a/input_mapping_dialog.cpp +++ b/input_mapping_dialog.cpp @@ -11,7 +11,7 @@ InputMappingDialog::InputMappingDialog() : ui(new Ui::InputMappingDialog), mapping(global_mixer->get_audio_mixer()->get_input_mapping()), old_mapping(mapping), - card_names(global_mixer->get_audio_mixer()->get_names()) + devices(global_mixer->get_audio_mixer()->get_devices()) { ui->setupUi(this); ui->table->setSelectionBehavior(QAbstractItemView::SelectRows); @@ -51,22 +51,19 @@ void InputMappingDialog::fill_row_from_bus(unsigned row, const InputMapping::Bus // 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.input_source_type) { - case InputSourceType::SILENCE: - card_combo->setCurrentIndex(0); - break; - case InputSourceType::CAPTURE_CARD: - card_combo->setCurrentIndex(mapping.buses[row].input_source_index + 1); - break; - default: - assert(false); + for (const auto &spec_and_info : devices) { + ++current_index; + card_combo->addItem( + QString::fromStdString(spec_and_info.second.name + " "), + qulonglong(DeviceSpec_to_key(spec_and_info.first))); + if (bus.device == spec_and_info.first) { + card_combo->setCurrentIndex(current_index); + } } connect(card_combo, static_cast(&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); @@ -78,8 +75,11 @@ void InputMappingDialog::setup_channel_choices_from_bus(unsigned row, const Inpu for (unsigned channel = 0; channel < 2; ++channel) { QComboBox *channel_combo = new QComboBox; channel_combo->addItem(QString("(none)")); - if (bus.input_source_type == InputSourceType::CAPTURE_CARD) { - for (unsigned source = 0; source < 8; ++source) { // TODO: Ask the card about number of channels, and names. + if (bus.device.type == InputSourceType::CAPTURE_CARD) { + auto device_it = devices.find(bus.device); + assert(device_it != devices.end()); + unsigned num_device_channels = device_it->second.num_channels; + for (unsigned source = 0; source < num_device_channels; ++source) { char buf[256]; snprintf(buf, sizeof(buf), "Channel %u ", source + 1); channel_combo->addItem(QString(buf)); @@ -115,14 +115,10 @@ void InputMappingDialog::cell_changed(int row, int column) 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].input_source_type = InputSourceType::SILENCE; - } else { - mapping.buses[row].input_source_type = InputSourceType::CAPTURE_CARD; - mapping.buses[row].input_source_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]); } @@ -138,7 +134,7 @@ void InputMappingDialog::add_clicked() InputMapping::Bus new_bus; new_bus.name = "New input"; - new_bus.input_source_type = InputSourceType::SILENCE; + new_bus.device.type = InputSourceType::SILENCE; mapping.buses.push_back(new_bus); ui->table->setRowCount(mapping.buses.size());