]> git.sesse.net Git - nageru/commitdiff
Prepare InputMappingDialog for arbitrary kinds of input source types, by storing...
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Mon, 8 Aug 2016 21:52:07 +0000 (23:52 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Wed, 19 Oct 2016 22:55:44 +0000 (00:55 +0200)
audio_mixer.cpp
audio_mixer.h
input_mapping_dialog.cpp
input_mapping_dialog.h

index db4b24d9bb0fdd6d3186b56daf968572911c2b26..93d59f4cc6f4017d9d43bc5ab45ff09b4710fe9f 100644 (file)
@@ -396,13 +396,14 @@ vector<float> AudioMixer::get_output(double pts, unsigned num_samples, Resamplin
        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;
 }
index 5ea79dea73713c82c6400c7855d53380cd3d844f..d45fd438153de3b6c768d59e760bb4c6b64c16d1 100644 (file)
@@ -36,6 +36,10 @@ struct DeviceSpec {
        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;
@@ -43,6 +47,16 @@ struct DeviceSpec {
        }
 };
 
+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;
@@ -67,7 +81,7 @@ public:
        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);
index 076cc2fb2202c6ae222cf4838f2e3d8d2c26e066..54936a8312a52114dde2e23b7887be79d8196c68 100644 (file)
@@ -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.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);
@@ -115,14 +112,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].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]);
 }
 
index 90be52acffa8bb82dddea0d8ef891cd1c88cd3b6..93a84b02d5c8d55c8465bec792de068f8f5a3dce 100644 (file)
@@ -12,6 +12,8 @@ namespace Ui {
 class InputMappingDialog;
 }  // namespace Ui
 
+class QComboBox;
+
 class InputMappingDialog : public QDialog
 {
        Q_OBJECT
@@ -24,7 +26,7 @@ private:
        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();
@@ -41,7 +43,7 @@ private:
        // 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)