1 // Licensed GNU LGPL v3 or later: http://www.gnu.org/licenses/lgpl.html 2 3 #ifndef SPECTMORPH_CONTROL_VIEW_HH 4 #define SPECTMORPH_CONTROL_VIEW_HH 5 6 namespace SpectMorph 7 { 8 9 class ControlView : public SignalReceiver 10 { 11 struct Entry 12 { 13 MorphOperator::ControlType ctype; 14 std::string text; 15 }; 16 const std::vector<Entry> entries = 17 { 18 { MorphOperator::CONTROL_GUI, "Gui Slider"}, 19 { MorphOperator::CONTROL_SIGNAL_1, "Control Signal #1"}, 20 { MorphOperator::CONTROL_SIGNAL_2, "Control Signal #2"}, 21 { MorphOperator::CONTROL_SIGNAL_3, "Control Signal #3"}, 22 { MorphOperator::CONTROL_SIGNAL_4, "Control Signal #4"} 23 }; 24 ComboBoxOperator *control_combobox = nullptr; 25 public: 26 ComboBoxOperator * create_combobox(Widget * parent,MorphOperator * op,MorphOperator::ControlType initial_type,MorphOperator * initial_op)27 create_combobox (Widget *parent, MorphOperator *op, MorphOperator::ControlType initial_type, MorphOperator *initial_op) 28 { 29 auto control_operator_filter = ComboBoxOperator::make_filter (op, MorphOperator::OUTPUT_CONTROL); 30 control_combobox = new ComboBoxOperator (parent, op->morph_plan(), control_operator_filter); 31 32 for (auto entry : entries) 33 { 34 control_combobox->add_str_choice (entry.text); 35 if (entry.ctype == initial_type) 36 control_combobox->set_active_str_choice (entry.text); 37 } 38 if (initial_type == MorphOperator::CONTROL_OP) 39 control_combobox->set_active (initial_op); 40 control_combobox->set_none_ok (false); 41 42 connect (control_combobox->signal_item_changed, [this]() { signal_control_changed(); }); 43 return control_combobox; 44 } 45 MorphOperator * op() const46 op() const 47 { 48 return control_combobox->active(); 49 } 50 MorphOperator::ControlType control_type()51 control_type() 52 { 53 if (control_combobox->active()) 54 return MorphOperator::CONTROL_OP; 55 56 std::string active_text = control_combobox->active_str_choice(); 57 for (auto entry : entries) 58 { 59 if (entry.text == active_text) 60 return entry.ctype; 61 } 62 /* in principle this cannot be reached but we want to fail gracefully */ 63 return MorphOperator::CONTROL_GUI; 64 } 65 Signal<> signal_control_changed; 66 }; 67 68 } 69 70 #endif 71