1 #ifndef _MIDI_MAPPING_DIALOG_H
2 #define _MIDI_MAPPING_DIALOG_H
10 #include "audio_mixer.h"
11 #include "midi_mapper.h"
15 class MIDIMappingDialog;
19 class MIDIMappingProto;
22 class QTreeWidgetItem;
24 class MIDIMappingDialog : public QDialog, public ControllerReceiver
29 MIDIMappingDialog(MIDIMapper *mapper);
32 bool eventFilter(QObject *obj, QEvent *event) override;
34 // For use in midi_mapping_dialog.cpp only.
37 int field_number; // In MIDIMappingBusProto.
38 int bank_field_number; // In MIDIMappingProto.
41 // ControllerReceiver interface. We only implement the raw events.
42 // All values are [0.0, 1.0].
43 void set_locut(float value) override {}
44 void set_limiter_threshold(float value) override {}
45 void set_makeup_gain(float value) override {}
47 void set_treble(unsigned bus_idx, float value) override {}
48 void set_mid(unsigned bus_idx, float value) override {}
49 void set_bass(unsigned bus_idx, float value) override {}
50 void set_gain(unsigned bus_idx, float value) override {}
51 void set_compressor_threshold(unsigned bus_idx, float value) override {}
52 void set_fader(unsigned bus_idx, float value) override {}
54 void toggle_locut(unsigned bus_idx) override {}
55 void toggle_auto_gain_staging(unsigned bus_idx) override {}
56 void toggle_compressor(unsigned bus_idx) override {}
57 void clear_peak(unsigned bus_idx) override {}
59 // Raw events; used for the editor dialog only.
60 void controller_changed(unsigned controller) override;
61 void note_on(unsigned note) override;
66 void cancel_clicked();
71 static constexpr unsigned num_buses = 8;
73 void add_bank_selector(QTreeWidgetItem *item, const MIDIMappingProto &mapping_proto, int bank_field_number);
75 enum class ControlType { CONTROLLER, BUTTON };
76 void add_controls(const std::string &heading, ControlType control_type,
77 const MIDIMappingProto &mapping_proto, const std::vector<Control> &controls);
78 void fill_controls_from_mapping(const MIDIMappingProto &mapping_proto);
80 // Tries to find a source bus and an offset to it that would give
81 // a consistent offset for the rest of the mappings in this bus.
82 // Returns -1 for the bus (the first element) if no consistent offset
84 std::pair<int, int> guess_offset(unsigned bus_idx);
85 bool bus_is_empty(unsigned bus_idx);
87 void update_guess_button_state();
90 std::unique_ptr<MIDIMappingProto> construct_mapping_proto_from_ui();
92 Ui::MIDIMappingDialog *ui;
94 ControllerReceiver *old_receiver;
95 int last_focus_bus_idx{-1};
97 // All controllers actually laid out on the grid (we need to store them
98 // so that we can move values back and forth between the controls and
99 // the protobuf on save/load).
100 struct InstantiatedSpinner {
103 int field_number; // In MIDIMappingBusProto.
105 struct InstantiatedComboBox {
106 QComboBox *combo_box;
107 int field_number; // In MIDIMappingProto.
109 std::vector<InstantiatedSpinner> controller_spinners;
110 std::vector<InstantiatedSpinner> button_spinners;
111 std::vector<InstantiatedComboBox> bank_combo_boxes;
113 // Keyed on bus index, then field number.
114 std::map<unsigned, std::map<unsigned, QSpinBox *>> spinners;
117 #endif // !defined(_MIDI_MAPPING_DIALOG_H)