]> git.sesse.net Git - nageru/blob - midi_mapping_dialog.h
f2cd0bfe3e490a3eccaefac757c8d7d4da3c56b2
[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         void save_clicked();
41         void load_clicked();
42
43 private:
44         static constexpr unsigned num_buses = 8;
45
46         void add_bank_selector(QTreeWidgetItem *item, const MIDIMappingProto &mapping_proto, int bank_field_number);
47         
48         enum class ControlType { CONTROLLER, BUTTON };
49         void add_controls(const std::string &heading, ControlType control_type,
50                           const MIDIMappingProto &mapping_proto, const std::vector<Control> &controls);
51         void fill_controls_from_mapping(const MIDIMappingProto &mapping_proto);
52
53         std::unique_ptr<MIDIMappingProto> construct_mapping_proto_from_ui();
54
55
56         Ui::MIDIMappingDialog *ui;
57         MIDIMapper *mapper;
58
59         // All controllers actually laid out on the grid (we need to store them
60         // so that we can move values back and forth between the controls and
61         // the protobuf on save/load).
62         struct InstantiatedSpinner {
63                 QSpinBox *spinner;
64                 unsigned bus_idx;
65                 int field_number;  // In MIDIMappingBusProto.
66         };
67         struct InstantiatedComboBox {
68                 QComboBox *combo_box;
69                 int field_number;  // In MIDIMappingProto.
70         };
71         std::vector<InstantiatedSpinner> controller_spinners;
72         std::vector<InstantiatedSpinner> button_spinners;
73         std::vector<InstantiatedComboBox> bank_combo_boxes;
74 };
75
76 #endif  // !defined(_MIDI_MAPPING_DIALOG_H)