]> git.sesse.net Git - nageru/blob - midi_mapping_dialog.h
Implement auto-training controllers in the MIDI input mapping dialog.
[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 "midi_mapper.h"
11 #include "mixer.h"
12
13 namespace Ui {
14 class MIDIMappingDialog;
15 }  // namespace Ui
16
17 class MIDIMapper;
18 class MIDIMappingProto;
19 class QComboBox;
20 class QSpinBox;
21 class QTreeWidgetItem;
22
23 class MIDIMappingDialog : public QDialog, public ControllerReceiver
24 {
25         Q_OBJECT
26
27 public:
28         MIDIMappingDialog(MIDIMapper *mapper);
29         ~MIDIMappingDialog();
30
31         // For use in midi_mapping_dialog.cpp only.
32         struct Control {
33                 std::string label;
34                 int field_number;  // In MIDIMappingBusProto.
35                 int bank_field_number;  // In MIDIMappingProto.
36         };
37
38         // ControllerReceiver interface. We only implement the raw events.
39         // All values are [0.0, 1.0].
40         void set_locut(float value) override {}
41         void set_limiter_threshold(float value) override {}
42         void set_makeup_gain(float value) override {}
43
44         void set_treble(unsigned bus_idx, float value) override {}
45         void set_mid(unsigned bus_idx, float value) override {}
46         void set_bass(unsigned bus_idx, float value) override {}
47         void set_gain(unsigned bus_idx, float value) override {}
48         void set_compressor_threshold(unsigned bus_idx, float value) override {}
49         void set_fader(unsigned bus_idx, float value) override {}
50
51         void toggle_locut(unsigned bus_idx) override {}
52         void toggle_auto_gain_staging(unsigned bus_idx) override {}
53         void toggle_compressor(unsigned bus_idx) override {}
54         void clear_peak(unsigned bus_idx) override {}
55
56         // Raw events; used for the editor dialog only.
57         void controller_changed(unsigned controller) override;
58         void note_on(unsigned note) override;
59
60 public slots:
61         void ok_clicked();
62         void cancel_clicked();
63         void save_clicked();
64         void load_clicked();
65
66 private:
67         static constexpr unsigned num_buses = 8;
68
69         void add_bank_selector(QTreeWidgetItem *item, const MIDIMappingProto &mapping_proto, int bank_field_number);
70         
71         enum class ControlType { CONTROLLER, BUTTON };
72         void add_controls(const std::string &heading, ControlType control_type,
73                           const MIDIMappingProto &mapping_proto, const std::vector<Control> &controls);
74         void fill_controls_from_mapping(const MIDIMappingProto &mapping_proto);
75
76         std::unique_ptr<MIDIMappingProto> construct_mapping_proto_from_ui();
77
78         Ui::MIDIMappingDialog *ui;
79         MIDIMapper *mapper;
80         ControllerReceiver *old_receiver;
81
82         // All controllers actually laid out on the grid (we need to store them
83         // so that we can move values back and forth between the controls and
84         // the protobuf on save/load).
85         struct InstantiatedSpinner {
86                 QSpinBox *spinner;
87                 unsigned bus_idx;
88                 int field_number;  // In MIDIMappingBusProto.
89         };
90         struct InstantiatedComboBox {
91                 QComboBox *combo_box;
92                 int field_number;  // In MIDIMappingProto.
93         };
94         std::vector<InstantiatedSpinner> controller_spinners;
95         std::vector<InstantiatedSpinner> button_spinners;
96         std::vector<InstantiatedComboBox> bank_combo_boxes;
97 };
98
99 #endif  // !defined(_MIDI_MAPPING_DIALOG_H)