1 #ifndef _MIDI_MAPPING_DIALOG_H
2 #define _MIDI_MAPPING_DIALOG_H
13 #include "midi_mapper.h"
19 class MIDIMappingDialog;
22 class MIDIMappingProto;
25 class QTreeWidgetItem;
27 class MIDIMappingDialog : public QDialog, public ControllerReceiver
32 MIDIMappingDialog(MIDIMapper *mapper);
35 bool eventFilter(QObject *obj, QEvent *event) override;
37 // For use in midi_mapping_dialog.cpp only.
40 int field_number; // In MIDIMappingBusProto.
41 int bank_field_number; // In MIDIMappingProto.
44 // ControllerReceiver interface. We only implement the raw events.
45 // All values are [0.0, 1.0].
46 void set_locut(float value) override {}
47 void set_limiter_threshold(float value) override {}
48 void set_makeup_gain(float value) override {}
50 void set_stereo_width(unsigned bus_idx, float value) override {}
51 void set_treble(unsigned bus_idx, float value) override {}
52 void set_mid(unsigned bus_idx, float value) override {}
53 void set_bass(unsigned bus_idx, float value) override {}
54 void set_gain(unsigned bus_idx, float value) override {}
55 void set_compressor_threshold(unsigned bus_idx, float value) override {}
56 void set_fader(unsigned bus_idx, float value) override {}
58 void toggle_mute(unsigned bus_idx) override {}
59 void toggle_locut(unsigned bus_idx) override {}
60 void toggle_auto_gain_staging(unsigned bus_idx) override {}
61 void toggle_compressor(unsigned bus_idx) override {}
62 void clear_peak(unsigned bus_idx) override {}
63 void toggle_limiter() override {}
64 void toggle_auto_makeup_gain() override {}
66 void clear_all_highlights() override {}
68 void highlight_locut(bool highlight) override {}
69 void highlight_limiter_threshold(bool highlight) override {}
70 void highlight_makeup_gain(bool highlight) override {}
72 void highlight_stereo_width(unsigned bus_idx, bool highlight) override {}
73 void highlight_treble(unsigned bus_idx, bool highlight) override {}
74 void highlight_mid(unsigned bus_idx, bool highlight) override {}
75 void highlight_bass(unsigned bus_idx, bool highlight) override {}
76 void highlight_gain(unsigned bus_idx, bool highlight) override {}
77 void highlight_compressor_threshold(unsigned bus_idx, bool highlight) override {}
78 void highlight_fader(unsigned bus_idx, bool highlight) override {}
80 void highlight_mute(unsigned bus_idx, bool highlight) override {}
81 void highlight_toggle_locut(unsigned bus_idx, bool highlight) override {}
82 void highlight_toggle_auto_gain_staging(unsigned bus_idx, bool highlight) override {}
83 void highlight_toggle_compressor(unsigned bus_idx, bool highlight) override {}
84 void highlight_clear_peak(unsigned bus_idx, bool highlight) override {}
85 void highlight_toggle_limiter(bool highlight) override {}
86 void highlight_toggle_auto_makeup_gain(bool highlight) override {}
88 void switch_video_channel(int channel_number) override {}
89 void apply_transition(int transition_number) override {}
90 void prev_audio_view() override {}
91 void next_audio_view() override {}
92 void begin_new_segment() override {}
93 void exit() override {}
95 // Raw events; used for the editor dialog only.
96 void controller_changed(unsigned controller) override;
97 void note_on(unsigned note) override;
100 void guess_clicked(bool limit_to_group);
102 void cancel_clicked();
107 static constexpr unsigned num_buses = 8;
109 // Each spinner belongs to exactly one group, corresponding to the
110 // subheadings in the UI. This is so that we can extrapolate data
111 // across only single groups if need be.
112 enum class SpinnerGroup {
122 void add_bank_selector(QTreeWidgetItem *item, const MIDIMappingProto &mapping_proto, int bank_field_number);
124 enum class ControlType { CONTROLLER, BUTTON, LIGHT };
125 void add_controls(const std::string &heading, ControlType control_type,
126 SpinnerGroup spinner_group,
127 const MIDIMappingProto &mapping_proto, const std::vector<Control> &controls);
128 void fill_controls_from_mapping(const MIDIMappingProto &mapping_proto);
130 // Tries to find a source bus and an offset to it that would give
131 // a consistent offset for the rest of the mappings in this bus.
132 // Returns -1 for the bus if no consistent offset can be found.
133 std::pair<int, int> guess_offset(unsigned bus_idx, SpinnerGroup spinner_group);
134 bool bus_is_empty(unsigned bus_idx, SpinnerGroup spinner_group);
136 void update_guess_button_state();
138 int bus_idx; // -1 for none.
139 SpinnerGroup spinner_group;
142 FocusInfo find_focus() const;
144 std::unique_ptr<MIDIMappingProto> construct_mapping_proto_from_ui();
146 Ui::MIDIMappingDialog *ui;
148 ControllerReceiver *old_receiver;
149 FocusInfo last_focus{-1, SpinnerGroup::ALL_GROUPS, -1};
151 // All controllers actually laid out on the grid (we need to store them
152 // so that we can move values back and forth between the controls and
153 // the protobuf on save/load).
154 struct InstantiatedSpinner {
157 SpinnerGroup spinner_group;
158 int field_number; // In MIDIMappingBusProto.
160 struct InstantiatedComboBox {
161 QComboBox *combo_box;
162 int field_number; // In MIDIMappingProto.
164 std::vector<InstantiatedSpinner> controller_spinners;
165 std::vector<InstantiatedSpinner> button_spinners;
166 std::vector<InstantiatedSpinner> light_spinners;
167 std::vector<InstantiatedComboBox> bank_combo_boxes;
169 // Keyed on bus index, then field number.
170 struct SpinnerAndGroup {
174 std::map<unsigned, std::map<unsigned, SpinnerAndGroup>> spinners;
177 #endif // !defined(_MIDI_MAPPING_DIALOG_H)