]> git.sesse.net Git - nageru/blob - input_mapping_dialog.cpp
Tweak the look of the input mapping dialog box a bit.
[nageru] / input_mapping_dialog.cpp
1 #include "input_mapping_dialog.h"
2
3 #include "ui_input_mapping.h"
4
5 #include <QComboBox>
6
7 using namespace std;
8
9 InputMappingDialog::InputMappingDialog()
10         : ui(new Ui::InputMappingDialog)
11 {
12         ui->setupUi(this);
13
14         //connect(ui->button_box, &QDialogButtonBox::accepted, [this]{ this->close(); });
15         vector<string> card_names = global_mixer->get_audio_mixer()->get_names();
16         fill_ui_from_mapping(global_mixer->get_audio_mixer()->get_input_mapping(), card_names);
17 }
18
19 void InputMappingDialog::fill_ui_from_mapping(const InputMapping &mapping, const vector<string> &card_names)
20 {
21         ui->table->verticalHeader()->hide();
22         ui->table->horizontalHeader()->setSectionResizeMode(1, QHeaderView::ResizeToContents);
23         ui->table->horizontalHeader()->setSectionResizeMode(2, QHeaderView::ResizeToContents);
24         ui->table->horizontalHeader()->setSectionResizeMode(3, QHeaderView::ResizeToContents);
25         ui->table->horizontalHeader()->setSectionsClickable(false);
26
27         ui->table->setRowCount(mapping.inputs.size());
28         for (unsigned row = 0; row < mapping.inputs.size(); ++row) {
29                 // TODO: Mark as some sort of header (by means of background color, probably).
30                 QString name(QString::fromStdString(mapping.inputs[row].name));
31                 ui->table->setItem(row, 0, new QTableWidgetItem(name));
32
33                 // Card choices.
34                 QComboBox *card_combo = new QComboBox;
35                 card_combo->addItem(QString("(none)   "));
36                 for (const string &name : card_names) {
37                         card_combo->addItem(QString::fromStdString(name + "   "));
38                 }
39                 switch (mapping.inputs[row].input_source_type) {
40                 case InputSourceType::SILENCE:
41                         card_combo->setCurrentIndex(0);
42                         break;
43                 case InputSourceType::CAPTURE_CARD:
44                         card_combo->setCurrentIndex(mapping.inputs[row].input_source_index + 1);
45                         break;
46                 default:
47                         assert(false);
48                 }
49                 ui->table->setCellWidget(row, 1, card_combo);
50
51                 // Left and right channel.
52                 fill_channel_ui_from_mapping(row, mapping.inputs[row]);
53         }
54 }
55
56 void InputMappingDialog::fill_channel_ui_from_mapping(unsigned row, const InputMapping::Input &input)
57 {
58         for (unsigned channel = 0; channel < 2; ++channel) {
59                 QComboBox *channel_combo = new QComboBox;
60                 channel_combo->addItem(QString("(none)"));
61                 if (input.input_source_type == InputSourceType::CAPTURE_CARD) {
62                         for (unsigned source = 0; source < 8; ++source) {  // TODO: Ask the card about number of channels, and names.
63                                 char buf[256];
64                                 snprintf(buf, sizeof(buf), "Channel %u   ", source + 1);
65                                 channel_combo->addItem(QString(buf));
66                         }
67                 }
68                 channel_combo->setCurrentIndex(input.source_channel[channel] + 1);
69                 ui->table->setCellWidget(row, 2 + channel, channel_combo);
70         }
71 }