diff --git a/gtk2_ardour/ardour_ui.h b/gtk2_ardour/ardour_ui.h index d1af28e322..82b4bb8654 100644 --- a/gtk2_ardour/ardour_ui.h +++ b/gtk2_ardour/ardour_ui.h @@ -240,17 +240,17 @@ class ARDOUR_UI : public Gtkmm2ext::UI, public ARDOUR::SessionHandlePtr uint32_t _ignore_changes; WavesDropdown* _sample_rate_dropdown; - void on_sample_rate_dropdown_item_clicked (WavesDropdown* from_which, void* my_cookie); + void on_sample_rate_dropdown_item_clicked (WavesDropdown*, int); void sample_rate_changed(); ARDOUR::framecnt_t get_sample_rate () const; void populate_sample_rate_dropdown (); WavesDropdown* _display_format_dropdown; - void on_display_format_dropdown_item_clicked (WavesDropdown* from_which, void* my_cookie); + void on_display_format_dropdown_item_clicked (WavesDropdown*, int); void populate_display_format_dropdown (); WavesDropdown* _timecode_source_dropdown; - void on_timecode_source_dropdown_item_clicked (WavesDropdown* from_which, void* my_cookie); + void on_timecode_source_dropdown_item_clicked (WavesDropdown*, int); void populate_timecode_source_dropdown (); void update_bit_depth_button (); diff --git a/gtk2_ardour/ardour_ui_ed.cc b/gtk2_ardour/ardour_ui_ed.cc index 037b3a67dd..5660753831 100644 --- a/gtk2_ardour/ardour_ui_ed.cc +++ b/gtk2_ardour/ardour_ui_ed.cc @@ -179,9 +179,13 @@ ARDOUR_UI::populate_timecode_source_dropdown () } void -ARDOUR_UI::on_display_format_dropdown_item_clicked (WavesDropdown* from_which, void* my_cookie) +ARDOUR_UI::on_display_format_dropdown_item_clicked (WavesDropdown* dropdown, int el_number) { - string format = *((string*)my_cookie); + void* data = dropdown->get_item_associated_data(el_number); + assert(data); + + string format = *(string*)data; + AudioClock::Mode mode; if( format == "Timecode" ) @@ -198,9 +202,12 @@ ARDOUR_UI::on_display_format_dropdown_item_clicked (WavesDropdown* from_which, v } void -ARDOUR_UI::on_timecode_source_dropdown_item_clicked (WavesDropdown* from_which, void* my_cookie) +ARDOUR_UI::on_timecode_source_dropdown_item_clicked (WavesDropdown* dropdown, int el_number) { - string timecode_source = *((string*)my_cookie); + void* data = dropdown->get_item_associated_data(el_number); + assert(data); + + string timecode_source = *(string*)data; if ( timecode_source == "Intermal" ) { @@ -315,9 +322,12 @@ ARDOUR_UI::sample_rate_changed() } void -ARDOUR_UI::on_sample_rate_dropdown_item_clicked (WavesDropdown* from_which, void* my_cookie) +ARDOUR_UI::on_sample_rate_dropdown_item_clicked (WavesDropdown* dropdown, int el_number) { - float sample_rate = *((float*)my_cookie); + void* data = dropdown->get_item_associated_data(el_number); + assert(data); + + framecnt_t sample_rate = *(float*)data; if (EngineStateController::instance()->set_new_sample_rate_in_controller( sample_rate ) ) { diff --git a/gtk2_ardour/editor.h b/gtk2_ardour/editor.h index 8c8d245b7e..466759b0bd 100644 --- a/gtk2_ardour/editor.h +++ b/gtk2_ardour/editor.h @@ -2158,8 +2158,8 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD WavesDropdown& _midi_input_dropdown; WavesDropdown& _midi_output_dropdown; - void midi_input_chosen (WavesDropdown*, void*); - void midi_output_chosen (WavesDropdown*, void*); + void midi_input_chosen (WavesDropdown*, int); + void midi_output_chosen (WavesDropdown*, int); void populate_midi_inout_dropdowns (); void populate_midi_inout_dropdown (bool playback); diff --git a/gtk2_ardour/editor_markers.cc b/gtk2_ardour/editor_markers.cc index a3348915fd..0f8ec7ed90 100644 --- a/gtk2_ardour/editor_markers.cc +++ b/gtk2_ardour/editor_markers.cc @@ -1382,31 +1382,35 @@ Editor::reset_marker_midi_images (bool input) /* MIDI/scene change Markers */ void -Editor::midi_input_chosen (WavesDropdown*, void* full_name_of_chosen_port) +Editor::midi_input_chosen (WavesDropdown* dropdown, int el_number) { - if (!_session) { - return; - } - - _session->scene_in()->disconnect_all (); - - if (full_name_of_chosen_port != 0) { - _session->scene_in()->connect ((char*) full_name_of_chosen_port); - } + void* data = dropdown->get_item_associated_data(el_number); + + if (!_session) { + return; + } + + _session->scene_in()->disconnect_all (); + + if (data) { + _session->scene_in()->connect ((char*) data); + } } void -Editor::midi_output_chosen (WavesDropdown*, void* full_name_of_chosen_port) +Editor::midi_output_chosen (WavesDropdown* dropdown, int el_number) { - if (!_session) { - return; - } - - _session->scene_out()->disconnect_all (); - - if (full_name_of_chosen_port != 0) { - _session->scene_out()->connect ((char *) full_name_of_chosen_port); - } + void* data = dropdown->get_item_associated_data(el_number); + + if (!_session) { + return; + } + + _session->scene_out()->disconnect_all (); + + if (data) { + _session->scene_out()->connect ((char *) data); + } } void diff --git a/gtk2_ardour/tracks_control_panel.logic.cc b/gtk2_ardour/tracks_control_panel.logic.cc index c5a87c8f3a..127a869447 100644 --- a/gtk2_ardour/tracks_control_panel.logic.cc +++ b/gtk2_ardour/tracks_control_panel.logic.cc @@ -1075,7 +1075,7 @@ void TracksControlPanel::save_general_preferences () } -void TracksControlPanel::on_engine_dropdown_item_clicked (WavesDropdown*, void*) +void TracksControlPanel::on_engine_dropdown_item_clicked (WavesDropdown*, int) { if (_ignore_changes) { return; @@ -1094,7 +1094,7 @@ void TracksControlPanel::on_engine_dropdown_item_clicked (WavesDropdown*, void*) } void -TracksControlPanel::on_device_dropdown_item_clicked (WavesDropdown*, void*) +TracksControlPanel::on_device_dropdown_item_clicked (WavesDropdown*, int) { if (_ignore_changes) { return; @@ -1218,7 +1218,7 @@ TracksControlPanel::on_all_outputs_off_button(WavesButton*) } void -TracksControlPanel::on_file_type_dropdown_item_clicked (WavesDropdown*, void*) +TracksControlPanel::on_file_type_dropdown_item_clicked (WavesDropdown*, int) { if (_ignore_changes) { return; @@ -1232,7 +1232,7 @@ TracksControlPanel::on_file_type_dropdown_item_clicked (WavesDropdown*, void*) } void -TracksControlPanel::on_bit_depth_dropdown_item_clicked (WavesDropdown*, void*) +TracksControlPanel::on_bit_depth_dropdown_item_clicked (WavesDropdown*, int) { if (_ignore_changes) { return; @@ -1246,7 +1246,7 @@ TracksControlPanel::on_bit_depth_dropdown_item_clicked (WavesDropdown*, void*) } void -TracksControlPanel::on_frame_rate_item_clicked (WavesDropdown*, void*) +TracksControlPanel::on_frame_rate_item_clicked (WavesDropdown*, int) { if (_ignore_changes) { return; @@ -1260,7 +1260,7 @@ TracksControlPanel::on_frame_rate_item_clicked (WavesDropdown*, void*) } void -TracksControlPanel::on_buffer_size_dropdown_item_clicked (WavesDropdown*, void*) +TracksControlPanel::on_buffer_size_dropdown_item_clicked (WavesDropdown*, int) { if (_ignore_changes) { return; @@ -1285,7 +1285,7 @@ TracksControlPanel::on_buffer_size_dropdown_item_clicked (WavesDropdown*, void*) } void -TracksControlPanel::on_sample_rate_dropdown_item_clicked (WavesDropdown*, void*) +TracksControlPanel::on_sample_rate_dropdown_item_clicked (WavesDropdown*, int) { if (_ignore_changes) { return; @@ -1761,38 +1761,11 @@ TracksControlPanel::get_sample_rate () const { const std::string sample_rate = _sample_rate_dropdown.get_text (); - if ( "44.1 kHz" == sample_rate ) - { - return 44100; - } else if ( "48 kHz" == sample_rate ) - { - return 48000; - } else if ( "88.2 kHz" == sample_rate ) - { - return 88200; - } else if ( "96 kHz" == sample_rate ) - { - return 96000; - } else if ( "172.4 kHz" == sample_rate ) - { - return 172400; - } else if ( "192 kHz" == sample_rate ) - { - return 192000; - } - - float r = atof (sample_rate); - - /* the std::string may have been translated with an abbreviation for - * thousands, so use a crude heuristic to fix this. - */ - if (r < 1000.0) { - r *= 1000.0; - } - return r; + return ARDOUR_UI_UTILS::string_as_rate (sample_rate); } -pframes_t TracksControlPanel::get_buffer_size() const +pframes_t +TracksControlPanel::get_buffer_size() const { std::string bs_text = _buffer_size_dropdown.get_text (); pframes_t samples = atoi (bs_text); /* will ignore trailing text */ diff --git a/gtk2_ardour/tracks_control_panel.logic.h b/gtk2_ardour/tracks_control_panel.logic.h index 4da8bf433d..4913386292 100644 --- a/gtk2_ardour/tracks_control_panel.logic.h +++ b/gtk2_ardour/tracks_control_panel.logic.h @@ -73,17 +73,17 @@ void on_control_panel_button(WavesButton*); ARDOUR::TracksAutoNamingRule _tracks_naming_rule; - void on_engine_dropdown_item_clicked (WavesDropdown*, void*); - void on_device_dropdown_item_clicked (WavesDropdown*, void*); + void on_engine_dropdown_item_clicked (WavesDropdown*, int); + void on_device_dropdown_item_clicked (WavesDropdown*, int); void device_changed (); void buffer_size_changed (); - void on_buffer_size_dropdown_item_clicked (WavesDropdown*, void*); - void on_sample_rate_dropdown_item_clicked (WavesDropdown*, void*); + void on_buffer_size_dropdown_item_clicked (WavesDropdown*, int); + void on_sample_rate_dropdown_item_clicked (WavesDropdown*, int); void engine_running (); void engine_stopped (); - void on_file_type_dropdown_item_clicked (WavesDropdown*, void*); - void on_bit_depth_dropdown_item_clicked (WavesDropdown*, void*); - void on_frame_rate_item_clicked (WavesDropdown*, void*); + void on_file_type_dropdown_item_clicked (WavesDropdown*, int); + void on_bit_depth_dropdown_item_clicked (WavesDropdown*, int); + void on_frame_rate_item_clicked (WavesDropdown*, int); void populate_engine_dropdown (); void populate_device_dropdown (); diff --git a/gtk2_ardour/utils.cc b/gtk2_ardour/utils.cc index 8b22431271..850a5d285a 100644 --- a/gtk2_ardour/utils.cc +++ b/gtk2_ardour/utils.cc @@ -980,6 +980,40 @@ ARDOUR_UI_UTILS::rate_as_string (float r) return buf; } +framecnt_t +ARDOUR_UI_UTILS::string_as_rate (const std::string& string_sr) +{ + if ( "44.1 kHz" == string_sr ) + { + return 44100; + } else if ( "48 kHz" == string_sr ) + { + return 48000; + } else if ( "88.2 kHz" == string_sr ) + { + return 88200; + } else if ( "96 kHz" == string_sr ) + { + return 96000; + } else if ( "172.4 kHz" == string_sr ) + { + return 172400; + } else if ( "192 kHz" == string_sr ) + { + return 192000; + } + + float r = atof (string_sr); + + /* the std::string may have been translated with an abbreviation for + * thousands, so use a crude heuristic to fix this. + */ + if (r < 1000.0) { + r *= 1000.0; + } + return r; +} + string ARDOUR_UI_UTILS::track_number_to_string ( diff --git a/gtk2_ardour/utils.h b/gtk2_ardour/utils.h index 59f986e81d..bafb855f8d 100644 --- a/gtk2_ardour/utils.h +++ b/gtk2_ardour/utils.h @@ -97,6 +97,7 @@ std::string escape_angled_brackets (std::string const &); Gdk::Color unique_random_color (std::list &); std::string rate_as_string (float r); +ARDOUR::framecnt_t string_as_rate (const std::string& string_sr); std::string track_number_to_string (int64_t tracknumber, std::string sep = "", std::string postfix = ""); diff --git a/gtk2_ardour/waves_dropdown.cc b/gtk2_ardour/waves_dropdown.cc index 9cb337d6ef..818eb68ad0 100644 --- a/gtk2_ardour/waves_dropdown.cc +++ b/gtk2_ardour/waves_dropdown.cc @@ -19,6 +19,8 @@ #include "waves_dropdown.h" +char* WavesDropdown::menu_item_data_key = "waves_dropdown_item_cookie"; + WavesDropdown::WavesDropdown (const std::string& title) : WavesIconButton (title) , _current_item_number (-1) @@ -37,6 +39,26 @@ WavesDropdown::clear_items () _menu.items().clear (); } +void* +WavesDropdown::get_item_associated_data(int item_number) +{ + Gtk::Menu_Helpers::MenuList& items = _menu.items (); + Gtk::Menu_Helpers::MenuList::iterator i = items.begin(); + std::advance (i, item_number); + + return (*i).get_data (menu_item_data_key); +} + +Gtk::MenuItem* +WavesDropdown::get_item (int item_number) +{ + Gtk::Menu_Helpers::MenuList& items = _menu.items (); + Gtk::Menu_Helpers::MenuList::iterator i = items.begin(); + std::advance (i, item_number); + + return &(*i); +} + void WavesDropdown::set_current_item (int current_item_number) { @@ -71,7 +93,7 @@ WavesDropdown::set_current_item (int current_item_number) check_menu_item->set_active (true); } - _on_menu_item (current_item_number, (*i).get_data ("waves_dropdown_item_cookie")); + _on_menu_item (current_item_number, (*i).get_data (menu_item_data_key)); } Gtk::MenuItem& @@ -88,7 +110,7 @@ WavesDropdown::add_menu_item (const std::string& item, void* cookie) child->set_style (get_style()); } - menuitem.set_data ("waves_dropdown_item_cookie", cookie); + menuitem.set_data (menu_item_data_key, cookie); return menuitem; } @@ -98,14 +120,14 @@ WavesDropdown::add_radio_menu_item (const std::string& item, void* cookie) { Gtk::Menu_Helpers::MenuList& items = _menu.items (); - if (items.empty()) { - Gtk::RadioMenuItem::Group group; - items.push_back (Gtk::Menu_Helpers::RadioMenuElem (group, item, sigc::bind (sigc::mem_fun(*this, &WavesDropdown::_on_menu_item), items.size (), cookie))); - } else { - Gtk::RadioMenuItem* first = dynamic_cast (&_menu.items ().front ()); - Gtk::RadioMenuItem::Group group = first->get_group(); - items.push_back (Gtk::Menu_Helpers::RadioMenuElem (group, item, sigc::bind (sigc::mem_fun(*this, &WavesDropdown::_on_menu_item), items.size (), cookie))); - } + if (items.empty()) { + Gtk::RadioMenuItem::Group group; + items.push_back (Gtk::Menu_Helpers::RadioMenuElem (group, item, sigc::bind (sigc::mem_fun(*this, &WavesDropdown::_on_menu_item), items.size (), cookie))); + } else { + Gtk::RadioMenuItem* first = dynamic_cast (&_menu.items ().front ()); + Gtk::RadioMenuItem::Group group = first->get_group(); + items.push_back (Gtk::Menu_Helpers::RadioMenuElem (group, item, sigc::bind (sigc::mem_fun(*this, &WavesDropdown::_on_menu_item), items.size (), cookie))); + } Gtk::RadioMenuItem& menuitem = *dynamic_cast (&_menu.items ().back ()); ensure_style(); @@ -114,7 +136,7 @@ WavesDropdown::add_radio_menu_item (const std::string& item, void* cookie) child->set_style (get_style()); } - menuitem.set_data ("waves_dropdown_item_cookie", cookie); + menuitem.set_data (menu_item_data_key, cookie); return menuitem; } @@ -133,7 +155,7 @@ WavesDropdown::add_check_menu_item (const std::string& item, void* cookie) child->set_style (get_style()); } - menuitem.set_data ("waves_dropdown_item_cookie", cookie); + menuitem.set_data (menu_item_data_key, cookie); return menuitem; } @@ -147,7 +169,7 @@ WavesDropdown::_on_menu_item (int item_number, void* cookie) Gtk::Menu_Helpers::MenuList::iterator i = items.begin(); std::advance (i, _current_item_number); set_text ((*i).get_label()); - selected_item_changed (this, cookie); + selected_item_changed (this, item_number); } void diff --git a/gtk2_ardour/waves_dropdown.h b/gtk2_ardour/waves_dropdown.h index fc8833efe3..d9784a1733 100644 --- a/gtk2_ardour/waves_dropdown.h +++ b/gtk2_ardour/waves_dropdown.h @@ -27,23 +27,27 @@ using namespace ArdourCanvas::XMLUI; class WavesDropdown : public WavesIconButton { public: - + WavesDropdown (const std::string& title = ""); virtual ~WavesDropdown (); Gtk::Menu& get_menu () { return _menu; } void clear_items (); + int get_current_item () { return _current_item_number; } - void set_current_item (int current_item_number); - + + void* get_item_associated_data (int); + Gtk::MenuItem* get_item (int); + Gtk::MenuItem& add_menu_item (const std::string& item, void* cookie = 0); Gtk::RadioMenuItem& add_radio_menu_item (const std::string& item, void* cookie = 0); Gtk::CheckMenuItem& add_check_menu_item (const std::string& item, void* cookie = 0); - sigc::signal2 selected_item_changed; + sigc::signal2 selected_item_changed; private: + static char* menu_item_data_key; Gtk::Menu _menu; int _current_item_number; void _on_menu_item (int item_number, void* cookie);