]> git.sesse.net Git - nageru/blob - futatabi/midi_mapping_dialog.h
Move VADisplayWithCleanup into its own header file, in shared/.
[nageru] / futatabi / midi_mapping_dialog.h
1 #ifndef _MIDI_MAPPING_DIALOG_H
2 #define _MIDI_MAPPING_DIALOG_H
3
4 #include <stdbool.h>
5 #include <QDialog>
6 #include <QString>
7 #include <map>
8 #include <memory>
9 #include <string>
10 #include <utility>
11 #include <vector>
12
13 #include "midi_mapper.h"
14
15 class QEvent;
16 class QObject;
17
18 namespace Ui {
19 class MIDIMappingDialog;
20 }  // namespace Ui
21
22 class MIDIMappingProto;
23 class QComboBox;
24 class QSpinBox;
25 class QTreeWidgetItem;
26
27 class MIDIMappingDialog : public QDialog, public ControllerReceiver
28 {
29         Q_OBJECT
30
31 public:
32         MIDIMappingDialog(MIDIMapper *mapper);
33         ~MIDIMappingDialog();
34
35         // For use in midi_mapping_dialog.cpp only.
36         struct Control {
37                 std::string label;
38                 int field_number;  // In MIDIMappingBusProto.
39                 int bank_field_number;  // In MIDIMappingProto.
40         };
41
42         // ControllerReceiver interface. We only implement the raw events.
43         void preview() override {}
44         void queue() override {}
45         void play() override {}
46         void next() override {}
47         void toggle_lock() override {}
48         void jog(int delta) override {}
49         void switch_camera(unsigned camera_idx) override {}
50         void set_master_speed(float speed) override {}
51         void cue_in() override {}
52         void cue_out() override {}
53
54         // Raw events; used for the editor dialog only.
55         void controller_changed(unsigned controller) override;
56         void note_on(unsigned note) override;
57
58 private:
59         void ok_clicked();
60         void cancel_clicked();
61         void save_clicked();
62         void load_clicked();
63
64         void add_bank_selector(QTreeWidgetItem *item, const MIDIMappingProto &mapping_proto, int bank_field_number);
65         
66         enum class ControlType { CONTROLLER, CONTROLLER_LIGHT, BUTTON, BUTTON_LIGHT, CAMERA_BUTTON, CAMERA_BUTTON_LIGHT };
67         void add_controls(const std::string &heading, ControlType control_type,
68                           const MIDIMappingProto &mapping_proto, const std::vector<Control> &controls);
69         void fill_controls_from_mapping(const MIDIMappingProto &mapping_proto);
70
71         std::unique_ptr<MIDIMappingProto> construct_mapping_proto_from_ui();
72
73         Ui::MIDIMappingDialog *ui;
74         MIDIMapper *mapper;
75         ControllerReceiver *old_receiver;
76
77         // All controllers actually laid out on the grid (we need to store them
78         // so that we can move values back and forth between the controls and
79         // the protobuf on save/load).
80         struct InstantiatedSpinner {
81                 QSpinBox *spinner;
82                 QSpinBox *spinner2;  // Value for button lights, min value for controller lights.
83                 QSpinBox *spinner3;  // Max value for controller lights.
84                 int field_number;  // In MIDIMappingBusProto.
85         };
86         struct InstantiatedComboBox {
87                 QComboBox *combo_box;
88                 int field_number;  // In MIDIMappingProto.
89         };
90         std::vector<InstantiatedSpinner> controller_spinners;
91         std::vector<InstantiatedSpinner> controller_light_spinners;
92         std::vector<InstantiatedSpinner> button_spinners;
93         std::vector<InstantiatedSpinner> button_light_spinners;
94         std::vector<InstantiatedSpinner> camera_button_spinners;  // One per camera.
95         std::vector<InstantiatedSpinner> camera_button_light_spinners;  // One per camera.
96         std::vector<InstantiatedComboBox> bank_combo_boxes;
97
98         // Keyed on field number.
99         std::map<unsigned, QSpinBox *> spinners;
100 };
101
102 #endif  // !defined(_MIDI_MAPPING_DIALOG_H)