X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=gtk2_ardour%2Fgain_meter.cc;h=73d2ce648b8dcc73270637319344193562d70618;hb=fd9ba531bb9db001fea5105f0d374923ca9e6db4;hp=471239efdc41f2d42aa5aeaced2f340bd56ed0b3;hpb=ad0e7319c81360acd2d2054e5553eaa926b48813;p=ardour.git diff --git a/gtk2_ardour/gain_meter.cc b/gtk2_ardour/gain_meter.cc index 471239efdc..73d2ce648b 100644 --- a/gtk2_ardour/gain_meter.cc +++ b/gtk2_ardour/gain_meter.cc @@ -20,10 +20,7 @@ #include #include "ardour/amp.h" -#include "ardour/io.h" -#include "ardour/route.h" #include "ardour/route_group.h" -#include "ardour/session.h" #include "ardour/session_route.h" #include "ardour/dB.h" #include "ardour/utils.h" @@ -64,27 +61,14 @@ sigc::signal GainMeterBase::ResetAllPeakDisplays; sigc::signal GainMeterBase::ResetGroupPeakDisplays; GainMeter::MetricPatterns GainMeter::metric_patterns; -Glib::RefPtr GainMeter::slider; - - -void -GainMeter::setup_slider_pix () -{ - if ((slider = ::get_icon ("fader_belt")) == 0) { - throw failed_constructor(); - } -} -GainMeterBase::GainMeterBase (Session* s, - const Glib::RefPtr& pix, - bool horizontal, - int fader_length) +GainMeterBase::GainMeterBase (Session* s, bool horizontal, int fader_length, int fader_girth) : gain_adjustment (gain_to_slider_position_with_max (1.0, Config->get_max_gain()), 0.0, 1.0, 0.01, 0.1) , gain_automation_style_button ("") , gain_automation_state_button ("") , style_changed (false) , dpi_changed (false) - , _is_midi (false) + , _data_type (DataType::AUDIO) { using namespace Menu_Helpers; @@ -97,21 +81,19 @@ GainMeterBase::GainMeterBase (Session* s, _width = Wide; if (horizontal) { - gain_slider = manage (new HSliderController (pix, - &gain_adjustment, - fader_length, - false)); + gain_slider = manage (new HSliderController (&gain_adjustment, fader_length, fader_girth, false)); } else { - gain_slider = manage (new VSliderController (pix, - &gain_adjustment, - fader_length, - false)); + gain_slider = manage (new VSliderController (&gain_adjustment, fader_length, fader_girth, false)); } level_meter = new LevelMeter(_session); - gain_slider->signal_button_press_event().connect (sigc::mem_fun(*this, &GainMeter::gain_slider_button_press)); - gain_slider->signal_button_release_event().connect (sigc::mem_fun(*this, &GainMeter::gain_slider_button_release)); + level_meter->ButtonPress.connect_same_thread (_level_meter_connection, boost::bind (&GainMeterBase::level_meter_button_press, this, _1)); + meter_metric_area.signal_button_press_event().connect (sigc::mem_fun (*this, &GainMeterBase::level_meter_button_press)); + meter_metric_area.add_events (Gdk::BUTTON_PRESS_MASK); + + gain_slider->signal_button_press_event().connect (sigc::mem_fun(*this, &GainMeter::gain_slider_button_press), false); + gain_slider->signal_button_release_event().connect (sigc::mem_fun(*this, &GainMeter::gain_slider_button_release), false); gain_slider->set_name ("GainFader"); gain_display.set_name ("MixerStripGainDisplay"); @@ -126,8 +108,8 @@ GainMeterBase::GainMeterBase (Session* s, peak_display.set_label (_("-inf")); peak_display.unset_flags (Gtk::CAN_FOCUS); - gain_automation_style_button.set_name ("MixerAutomationModeButton"); - gain_automation_state_button.set_name ("MixerAutomationPlaybackButton"); + gain_automation_style_button.set_name ("mixer strip button"); + gain_automation_state_button.set_name ("mixer strip button"); ARDOUR_UI::instance()->set_tip (gain_automation_state_button, _("Fader automation mode")); ARDOUR_UI::instance()->set_tip (gain_automation_style_button, _("Fader automation type")); @@ -154,6 +136,16 @@ GainMeterBase::GainMeterBase (Session* s, UI::instance()->theme_changed.connect (sigc::mem_fun(*this, &GainMeterBase::on_theme_changed)); ColorsChanged.connect (sigc::bind(sigc::mem_fun (*this, &GainMeterBase::color_handler), false)); DPIReset.connect (sigc::bind(sigc::mem_fun (*this, &GainMeterBase::color_handler), true)); + +// PBD::ScopedConnection _config_connection; +// Config->ParameterChanged.connect ( _config_connection, MISSING_INVALIDATOR, boost::bind(&GainMeterBase::set_flat_buttons, this, _1), gui_context() ); +} + +void +GainMeterBase::set_flat_buttons () +{ +printf("set_flat_butt\n"); +// gain_slider->set_flat_buttons( ARDOUR_UI::config()->flat_buttons.get() ); } GainMeterBase::~GainMeterBase () @@ -188,21 +180,21 @@ GainMeterBase::set_controls (boost::shared_ptr r, if (amp) { amp->ConfigurationChanged.connect ( - model_connections, invalidator (*this), ui_bind (&GainMeterBase::setup_gain_adjustment, this), gui_context () + model_connections, invalidator (*this), boost::bind (&GainMeterBase::setup_gain_adjustment, this), gui_context () ); } setup_gain_adjustment (); - if (!_route || !_route->is_hidden()) { + if (!_route || !_route->is_auditioner()) { using namespace Menu_Helpers; gain_astate_menu.items().clear (); - gain_astate_menu.items().push_back (MenuElem (_("Manual"), + gain_astate_menu.items().push_back (MenuElem (S_("Automation|Manual"), sigc::bind (sigc::mem_fun (*(amp.get()), &Automatable::set_parameter_automation_state), - Evoral::Parameter(GainAutomation), (AutoState) Off))); + Evoral::Parameter(GainAutomation), (AutoState) ARDOUR::Off))); gain_astate_menu.items().push_back (MenuElem (_("Play"), sigc::bind (sigc::mem_fun (*(amp.get()), &Automatable::set_parameter_automation_state), Evoral::Parameter(GainAutomation), (AutoState) Play))); @@ -245,19 +237,19 @@ GainMeterBase::setup_gain_adjustment () ignore_toggle = true; if (_amp->output_streams().n_midi() == 0) { - _is_midi = false; + _data_type = DataType::AUDIO; gain_adjustment.set_lower (0.0); gain_adjustment.set_upper (1.0); gain_adjustment.set_step_increment (0.01); gain_adjustment.set_page_increment (0.1); gain_slider->set_default_value (gain_to_slider_position (1)); } else { - _is_midi = true; + _data_type = DataType::MIDI; gain_adjustment.set_lower (0.0); gain_adjustment.set_upper (2.0); - gain_adjustment.set_step_increment (0.05); - gain_adjustment.set_page_increment (0.1); - gain_slider->set_default_value (1); + gain_adjustment.set_step_increment (1.0/128.0); + gain_adjustment.set_page_increment (10.0/128.0); + gain_slider->set_default_value (1.0); } ignore_toggle = false; @@ -387,16 +379,40 @@ GainMeterBase::gain_activated () { float f; - if (sscanf (gain_display.get_text().c_str(), "%f", &f) == 1) { + { + // Switch to user's preferred locale so that + // if they use different LC_NUMERIC conventions, + // we will honor them. - /* clamp to displayable values */ + PBD::LocaleGuard lg (""); + if (sscanf (gain_display.get_text().c_str(), "%f", &f) != 1) { + return; + } + } + /* clamp to displayable values */ + if (_data_type == DataType::AUDIO) { f = min (f, 6.0f); - _amp->set_gain (dB_to_coefficient(f), this); + } else { + f = min (fabs (f), 2.0f); + _amp->set_gain (f, this); + } - if (gain_display.has_focus()) { - PublicEditor::instance().reset_focus(); + if (gain_display.has_focus()) { + Gtk::Widget* w = gain_display.get_toplevel(); + if (w) { + Gtk::Window* win = dynamic_cast (w); + + /* sigh. gtkmm doesn't wrap get_default_widget() */ + + if (win) { + GtkWidget* f = gtk_window_get_default_widget (win->gobj()); + if (f) { + gtk_widget_grab_focus (f); + return; + } + } } } } @@ -408,14 +424,17 @@ GainMeterBase::show_gain () float v = gain_adjustment.get_value(); - if (!_is_midi) { + switch (_data_type) { + case DataType::AUDIO: if (v == 0.0) { strcpy (buf, _("-inf")); } else { snprintf (buf, sizeof (buf), "%.1f", accurate_coefficient_to_dB (slider_position_to_gain_with_max (v, Config->get_max_gain()))); } - } else { + break; + case DataType::MIDI: snprintf (buf, sizeof (buf), "%.1f", v); + break; } gain_display.set_text (buf); @@ -424,15 +443,21 @@ GainMeterBase::show_gain () void GainMeterBase::gain_adjusted () { + gain_t value; + + /* convert from adjustment range (0..1) to gain coefficient */ + + if (_data_type == DataType::AUDIO) { + value = slider_position_to_gain_with_max (gain_adjustment.get_value(), Config->get_max_gain()); + } else { + value = gain_adjustment.get_value(); + } + if (!ignore_toggle) { if (_route && _route->amp() == _amp) { - if (_is_midi) { - _route->set_gain (gain_adjustment.get_value(), this); - } else { - _route->set_gain (slider_position_to_gain_with_max (gain_adjustment.get_value(), Config->get_max_gain()), this); - } + _route->set_gain (value, this); } else { - _amp->set_gain (slider_position_to_gain_with_max (gain_adjustment.get_value(), Config->get_max_gain()), this); + _amp->set_gain (value, this); } } @@ -442,12 +467,15 @@ GainMeterBase::gain_adjusted () void GainMeterBase::effective_gain_display () { - float value; + float value = 0.0; - if (!_is_midi) { + switch (_data_type) { + case DataType::AUDIO: value = gain_to_slider_position_with_max (_amp->gain(), Config->get_max_gain()); - } else { + break; + case DataType::MIDI: value = _amp->gain (); + break; } if (gain_adjustment.get_value() != value) { @@ -472,10 +500,7 @@ GainMeterBase::set_meter_strip_name (const char * name) void GainMeterBase::set_fader_name (const char * name) { - uint32_t rgb_active = rgba_from_style (name, 0xff, 0, 0xff, 0, "bg", STATE_ACTIVE, false); - uint32_t rgb_normal = rgba_from_style (name, 0xff, 0xff, 0, 0, "bg", STATE_NORMAL, false); - - gain_slider->set_border_colors (rgb_normal, rgb_active); + gain_slider->set_name (name); } void @@ -630,14 +655,14 @@ GainMeterBase::gain_slider_button_press (GdkEventButton* ev) return false; } - return true; + return false; } bool -GainMeterBase::gain_slider_button_release (GdkEventButton* ev) +GainMeterBase::gain_slider_button_release (GdkEventButton*) { _amp->gain_control()->stop_touch (false, _amp->session().transport_frame()); - return true; + return false; } gint @@ -693,7 +718,7 @@ GainMeterBase::_astate_string (AutoState state, bool shrt) string sstr; switch (state) { - case Off: + case ARDOUR::Off: sstr = (shrt ? "M" : _("M")); break; case Play: @@ -739,10 +764,10 @@ GainMeterBase::gain_automation_style_changed () { switch (_width) { case Wide: - gain_automation_style_button.set_label (astyle_string(_amp->gain_control()->alist()->automation_style())); + gain_automation_style_button.set_text (astyle_string(_amp->gain_control()->alist()->automation_style())); break; case Narrow: - gain_automation_style_button.set_label (short_astyle_string(_amp->gain_control()->alist()->automation_style())); + gain_automation_style_button.set_text (short_astyle_string(_amp->gain_control()->alist()->automation_style())); break; } } @@ -756,14 +781,14 @@ GainMeterBase::gain_automation_state_changed () switch (_width) { case Wide: - gain_automation_state_button.set_label (astate_string(_amp->gain_control()->alist()->automation_state())); + gain_automation_state_button.set_text (astate_string(_amp->gain_control()->alist()->automation_state())); break; case Narrow: - gain_automation_state_button.set_label (short_astate_string(_amp->gain_control()->alist()->automation_state())); + gain_automation_state_button.set_text (short_astate_string(_amp->gain_control()->alist()->automation_state())); break; } - x = (_amp->gain_control()->alist()->automation_state() != Off); + x = (_amp->gain_control()->alist()->automation_state() != ARDOUR::Off); if (gain_automation_state_button.get_active() != x) { ignore_toggle = true; @@ -825,17 +850,20 @@ GainMeterBase::on_theme_changed() } GainMeter::GainMeter (Session* s, int fader_length) - : GainMeterBase (s, slider, false, fader_length) + : GainMeterBase (s, false, fader_length, 24) , gain_display_box(true, 0) , hbox(true, 2) { + if (gain_display.get_parent()) { + gain_display.get_parent()->remove (gain_display); + } gain_display_box.pack_start (gain_display, true, true); meter_metric_area.set_name ("AudioTrackMetrics"); set_size_request_to_display_given_text (meter_metric_area, "-127", 0, 0); - gain_automation_style_button.set_name ("MixerAutomationModeButton"); - gain_automation_state_button.set_name ("MixerAutomationPlaybackButton"); + gain_automation_style_button.set_name ("mixer strip button"); + gain_automation_state_button.set_name ("mixer strip button"); ARDOUR_UI::instance()->set_tip (gain_automation_state_button, _("Fader automation mode")); ARDOUR_UI::instance()->set_tip (gain_automation_style_button, _("Fader automation type")); @@ -876,19 +904,15 @@ GainMeter::set_controls (boost::shared_ptr r, hbox.remove (meter_alignment); } - if (peak_display.get_parent()) { - gain_display_box.remove (peak_display); - } - - if (gain_automation_state_button.get_parent()) { - fader_vbox->remove (gain_automation_state_button); - } +// if (gain_automation_state_button.get_parent()) { +// fader_vbox->remove (gain_automation_state_button); +// } GainMeterBase::set_controls (r, meter, amp); if (_meter) { _meter->ConfigurationChanged.connect ( - model_connections, invalidator (*this), ui_bind (&GainMeter::meter_configuration_changed, this, _1), gui_context() + model_connections, invalidator (*this), boost::bind (&GainMeter::meter_configuration_changed, this, _1), gui_context() ); meter_configuration_changed (_meter->input_streams ()); @@ -900,12 +924,11 @@ GainMeter::set_controls (boost::shared_ptr r, pack some route-dependent stuff. */ - gain_display_box.pack_end (peak_display, true, true); hbox.pack_start (meter_alignment, true, true); - if (r && !r->is_hidden()) { - fader_vbox->pack_start (gain_automation_state_button, false, false, 0); - } +// if (r && !r->is_auditioner()) { +// fader_vbox->pack_start (gain_automation_state_button, false, false, 0); +// } setup_meters (); hbox.show_all (); @@ -1092,6 +1115,12 @@ GainMeterBase::get_controllable() } } +bool +GainMeterBase::level_meter_button_press (GdkEventButton* ev) +{ + return LevelMeterButtonPress (ev); /* EMIT SIGNAL */ +} + void GainMeter::meter_configuration_changed (ChanCount c) { @@ -1106,3 +1135,4 @@ GainMeter::meter_configuration_changed (ChanCount c) style_changed = true; meter_metric_area.queue_draw (); } +