]> git.sesse.net Git - nageru/blob - midi_mapping_dialog.h
Add an editor for the MIDI mappings.
[nageru] / midi_mapping_dialog.h
1 #ifndef _MIDI_MAPPING_DIALOG_H
2 #define _MIDI_MAPPING_DIALOG_H
3
4 #include <QDialog>
5 #include <string>
6 #include <vector>
7 #include <sys/time.h>
8
9 #include "audio_mixer.h"
10 #include "mixer.h"
11
12 namespace Ui {
13 class MIDIMappingDialog;
14 }  // namespace Ui
15
16 class MIDIMapper;
17 class MIDIMappingProto;
18 class QComboBox;
19 class QSpinBox;
20 class QTreeWidgetItem;
21
22 class MIDIMappingDialog : public QDialog
23 {
24         Q_OBJECT
25
26 public:
27         MIDIMappingDialog(MIDIMapper *mapper);
28         ~MIDIMappingDialog();
29
30         // For use in midi_mapping_dialog.cpp only.
31         struct Control {
32                 std::string label;
33                 int field_number;  // In MIDIMappingBusProto.
34                 int bank_field_number;  // In MIDIMappingProto.
35         };
36
37 public slots:
38         void ok_clicked();
39         void cancel_clicked();
40
41 private:
42         static constexpr unsigned num_buses = 8;
43
44         void add_bank_selector(QTreeWidgetItem *item, const MIDIMappingProto &mapping_proto, int bank_field_number);
45         
46         enum class ControlType { CONTROLLER, BUTTON };
47         void add_controls(const std::string &heading, ControlType control_type,
48                           const MIDIMappingProto &mapping_proto, const std::vector<Control> &controls);
49
50         std::unique_ptr<MIDIMappingProto> construct_mapping_proto_from_ui();
51
52
53         Ui::MIDIMappingDialog *ui;
54         MIDIMapper *mapper;
55
56         // All controllers actually laid out on the grid (we need to store them
57         // so that we can read its values back into the new protobuf).
58         struct InstantiatedSpinner {
59                 QSpinBox *spinner;
60                 unsigned bus_idx;
61                 int field_number;  // In MIDIMappingBusProto.
62         };
63         struct InstantiatedComboBox {
64                 QComboBox *combo_box;
65                 int field_number;  // In MIDIMappingProto.
66         };
67         std::vector<InstantiatedSpinner> controller_spinners;
68         std::vector<InstantiatedSpinner> button_spinners;
69         std::vector<InstantiatedComboBox> bank_combo_boxes;
70 };
71
72 #endif  // !defined(_MIDI_MAPPING_DIALOG_H)