s/ParamID/Parameter/
[ardour.git] / gtk2_ardour / gain_meter.cc
index 0262a90224c9c60767652d298fa3b708c864b939..a1ecd8586d879229cca27f55eb8d6a59291e1622 100644 (file)
 #include <ardour/session_route.h>
 #include <ardour/dB.h>
 
+#include <gtkmm/style.h>
+#include <gdkmm/color.h>
 #include <gtkmm2ext/utils.h>
 #include <gtkmm2ext/fastmeter.h>
 #include <gtkmm2ext/stop_signal.h>
 #include <gtkmm2ext/barcontroller.h>
+#include <gtkmm2ext/gtk_ui.h>
 #include <midi++/manager.h>
 #include <pbd/fastlog.h>
 
@@ -43,6 +46,7 @@
 
 #include <ardour/session.h>
 #include <ardour/route.h>
+#include <ardour/meter.h>
 
 #include "i18n.h"
 
@@ -83,10 +87,11 @@ GainMeter::GainMeter (boost::shared_ptr<IO> io, Session& s)
        ignore_toggle = false;
        meter_menu = 0;
        next_release_selects = false;
+       style_changed = true;
 
        gain_slider = manage (new VSliderController (slider,
                                                     &gain_adjustment,
-                                                    _io->gain_control(),
+                                                    *_io->gain_control().get(),
                                                     false));
 
        gain_slider->signal_button_press_event().connect (mem_fun(*this, &GainMeter::start_gain_touch));
@@ -100,6 +105,7 @@ GainMeter::GainMeter (boost::shared_ptr<IO> io, Session& s)
        gain_display.signal_focus_in_event().connect (mem_fun (*this, &GainMeter::gain_focused), false);
        gain_display.signal_focus_out_event().connect (mem_fun (*this, &GainMeter::gain_focused), false);
 
+       gain_display_box.set_name ("MeterMetricsStrip");
        gain_display_box.set_homogeneous (true);
        gain_display_box.set_spacing (2);
        gain_display_box.pack_start (gain_display, true, true);
@@ -137,33 +143,40 @@ GainMeter::GainMeter (boost::shared_ptr<IO> io, Session& s)
        fader_vbox->pack_start (*fader_centering_box, false, false, 0);
 
        hbox.set_spacing (2);
-       hbox.pack_start (*fader_vbox, true, true);
 
-       set_width(Narrow);
+       if (_io->default_type() == ARDOUR::DataType::AUDIO) {
+               hbox.pack_start (*fader_vbox, true, true);
+       }
+       
+       set_width (Narrow);
 
        Route* r;
 
        if ((r = dynamic_cast<Route*> (_io.get())) != 0) {
 
-               /* 
+               /* 
                   if we have a route (ie. we're not the click), 
                   pack some route-dependent stuff.
                */
 
-               gain_display_box.pack_end (peak_display, true, true);
+               gain_display_box.pack_end (peak_display, true, true);
 
                hbox.pack_end (meter_packer, true, true);
 
                using namespace Menu_Helpers;
        
                gain_astate_menu.items().push_back (MenuElem (_("Manual"), 
-                                                     bind (mem_fun (*_io, &IO::set_gain_automation_state), (AutoState) Off)));
+                                                     bind (mem_fun (*_io, &IO::set_parameter_automation_state),
+                                                                 Parameter(GainAutomation), (AutoState) Off)));
                gain_astate_menu.items().push_back (MenuElem (_("Play"),
-                                                     bind (mem_fun (*_io, &IO::set_gain_automation_state), (AutoState) Play)));
+                                                     bind (mem_fun (*_io, &IO::set_parameter_automation_state),
+                                                                 Parameter(GainAutomation), (AutoState) Play)));
                gain_astate_menu.items().push_back (MenuElem (_("Write"),
-                                                     bind (mem_fun (*_io, &IO::set_gain_automation_state), (AutoState) Write)));
+                                                     bind (mem_fun (*_io, &IO::set_parameter_automation_state),
+                                                                 Parameter(GainAutomation), (AutoState) Write)));
                gain_astate_menu.items().push_back (MenuElem (_("Touch"),
-                                                     bind (mem_fun (*_io, &IO::set_gain_automation_state), (AutoState) Touch)));
+                                                     bind (mem_fun (*_io, &IO::set_parameter_automation_state),
+                                                                 Parameter(GainAutomation), (AutoState) Touch)));
        
                gain_astyle_menu.items().push_back (MenuElem (_("Trim")));
                gain_astyle_menu.items().push_back (MenuElem (_("Abs")));
@@ -174,8 +187,8 @@ GainMeter::GainMeter (boost::shared_ptr<IO> io, Session& s)
                gain_automation_style_button.signal_button_press_event().connect (mem_fun(*this, &GainMeter::gain_automation_style_button_event), false);
                gain_automation_state_button.signal_button_press_event().connect (mem_fun(*this, &GainMeter::gain_automation_state_button_event), false);
                
-               r->gain_automation_curve().automation_state_changed.connect (mem_fun(*this, &GainMeter::gain_automation_state_changed));
-               r->gain_automation_curve().automation_style_changed.connect (mem_fun(*this, &GainMeter::gain_automation_style_changed));
+               r->gain_control()->list()->automation_state_changed.connect (mem_fun(*this, &GainMeter::gain_automation_state_changed));
+               r->gain_control()->list()->automation_style_changed.connect (mem_fun(*this, &GainMeter::gain_automation_style_changed));
                fader_vbox->pack_start (gain_automation_state_button, false, false, 0);
 
                gain_automation_state_changed ();
@@ -186,7 +199,7 @@ GainMeter::GainMeter (boost::shared_ptr<IO> io, Session& s)
        pack_start (gain_display_box, Gtk::PACK_SHRINK);
        pack_start (hbox, Gtk::PACK_SHRINK);
 
-       _io->gain_changed.connect (mem_fun(*this, &GainMeter::gain_changed));
+       _io->gain_control()->Changed.connect (mem_fun(*this, &GainMeter::gain_changed));
 
        meter_metric_area.signal_expose_event().connect (mem_fun(*this, &GainMeter::meter_metrics_expose));
        gain_adjustment.signal_value_changed().connect (mem_fun(*this, &GainMeter::gain_adjusted));
@@ -195,13 +208,15 @@ GainMeter::GainMeter (boost::shared_ptr<IO> io, Session& s)
 
        Config->ParameterChanged.connect (mem_fun (*this, &GainMeter::parameter_changed));
 
-       gain_changed (0);
+       gain_changed ();
        show_gain ();
 
        update_gain_sensitive ();
        
        ResetAllPeakDisplays.connect (mem_fun(*this, &GainMeter::reset_peak_display));
        ResetGroupPeakDisplays.connect (mem_fun(*this, &GainMeter::reset_group_peak_display));
+
+       UI::instance()->theme_changed.connect (mem_fun(*this, &GainMeter::on_theme_changed));
 }
 
 void
@@ -223,6 +238,7 @@ GainMeter::set_width (Width w)
 Glib::RefPtr<Gdk::Pixmap>
 GainMeter::render_metrics (Gtk::Widget& w)
 {
+       //cerr << "GainMeter::render_metrics() called, red = " << w.get_style()->get_bg(Gtk::STATE_NORMAL).get_red() << endl;//DEBUG
        Glib::RefPtr<Gdk::Window> win (w.get_window());
        Glib::RefPtr<Gdk::GC> fg_gc (w.get_style()->get_fg_gc (Gtk::STATE_NORMAL));
        Glib::RefPtr<Gdk::GC> bg_gc (w.get_style()->get_bg_gc (Gtk::STATE_NORMAL));
@@ -264,9 +280,20 @@ GainMeter::render_metrics (Gtk::Widget& w)
 gint
 GainMeter::meter_metrics_expose (GdkEventExpose *ev)
 {
+       /* Only draw dB scale if we're metering audio */
+       if (_io->n_inputs().n_audio() + _io->n_outputs().n_audio() == 0)
+               return true;
+
+       static Glib::RefPtr<Gtk::Style> meter_style;
+       
+       if (style_changed) {
+               meter_style = meter_metric_area.get_style();
+       }
+               
        Glib::RefPtr<Gdk::Window> win (meter_metric_area.get_window());
-       Glib::RefPtr<Gdk::GC> fg_gc (meter_metric_area.get_style()->get_fg_gc (Gtk::STATE_NORMAL));
-       Glib::RefPtr<Gdk::GC> bg_gc (meter_metric_area.get_style()->get_bg_gc (Gtk::STATE_NORMAL));
+       Glib::RefPtr<Gdk::GC> fg_gc (meter_style->get_fg_gc (Gtk::STATE_NORMAL));
+       Glib::RefPtr<Gdk::GC> bg_gc (meter_style->get_bg_gc (Gtk::STATE_NORMAL));
+
        GdkRectangle base_rect;
        GdkRectangle draw_rect;
        gint width, height;
@@ -281,7 +308,7 @@ GainMeter::meter_metrics_expose (GdkEventExpose *ev)
        Glib::RefPtr<Gdk::Pixmap> pixmap;
        std::map<string,Glib::RefPtr<Gdk::Pixmap> >::iterator i = metric_pixmaps.find (meter_metric_area.get_name());
 
-       if (i == metric_pixmaps.end()) {
+       if (i == metric_pixmaps.end() || style_changed) {
                pixmap = render_metrics (meter_metric_area);
        } else {
                pixmap = i->second;
@@ -289,11 +316,18 @@ GainMeter::meter_metrics_expose (GdkEventExpose *ev)
 
        gdk_rectangle_intersect (&ev->area, &base_rect, &draw_rect);
        win->draw_rectangle (bg_gc, true, draw_rect.x, draw_rect.y, draw_rect.width, draw_rect.height);
-       win->draw_drawable (bg_gc, pixmap, draw_rect.x, draw_rect.y, draw_rect.x, draw_rect.y, draw_rect.width, draw_rect.height);
+       win->draw_drawable (fg_gc, pixmap, draw_rect.x, draw_rect.y, draw_rect.x, draw_rect.y, draw_rect.width, draw_rect.height);
        
+       style_changed = false;
        return true;
 }
 
+void
+GainMeter::on_theme_changed()
+{
+       style_changed = true;
+}
+
 GainMeter::~GainMeter ()
 {
        if (meter_menu) {
@@ -317,11 +351,11 @@ GainMeter::update_meters ()
        
        for (n = 0, i = meters.begin(); i != meters.end(); ++i, ++n) {
                if ((*i).packed) {
-                       peak = _io->peak_input_power (n);
+                       peak = _io->peak_meter().peak_power (n);
 
-                       (*i).meter->set (log_meter (peak), peak);
+                       (*i).meter->set (log_meter (peak));
 
-                       mpeak = _io->max_peak_power(n);
+                       mpeak = _io->peak_meter().max_peak_power(n);
                        
                        if (mpeak > max_peak) {
                                max_peak = mpeak;
@@ -385,7 +419,7 @@ GainMeter::hide_all_meters ()
 void
 GainMeter::setup_meters ()
 {
-       uint32_t nmeters = _io->n_outputs();
+       uint32_t nmeters = _io->n_outputs().n_total();
        guint16 width;
 
        hide_all_meters ();
@@ -395,18 +429,20 @@ GainMeter::setup_meters ()
        if ((r = dynamic_cast<Route*> (_io.get())) != 0) {
 
                switch (r->meter_point()) {
-               case MeterPreFader:
                case MeterInput:
-                       nmeters = r->n_inputs();
+                       nmeters = r->n_inputs().n_total();
+                       break;
+               case MeterPreFader:
+                       nmeters = r->pre_fader_streams().n_total();
                        break;
                case MeterPostFader:
-                       nmeters = r->n_outputs();
+                       nmeters = r->n_outputs().n_total();
                        break;
                }
 
        } else {
 
-               nmeters = _io->n_outputs();
+               nmeters = _io->n_outputs().n_total();
 
        }
 
@@ -427,7 +463,7 @@ GainMeter::setup_meters ()
        /* pack them backwards */
 
        if (_width == Wide) {
-               meter_packer.pack_end (meter_metric_area, false, false);
+               meter_packer.pack_end (meter_metric_area, false, false);
                meter_metric_area.show_all ();
        }
 
@@ -450,8 +486,7 @@ GainMeter::setup_meters ()
 int
 GainMeter::get_gm_width ()
 {
-       Gtk::Requisition sz;
-       hbox.size_request (sz);
+       Gtk::Requisition sz = hbox.size_request ();
        return sz.width;
 }
 
@@ -490,7 +525,7 @@ GainMeter::reset_peak_display ()
 {
        Route * r;
        if ((r = dynamic_cast<Route*> (_io.get())) != 0) {
-               r->reset_max_peak_meters();
+               r->peak_meter().reset_max();
        }
 
        max_peak = -INFINITY;
@@ -571,7 +606,7 @@ GainMeter::gain_activated ()
 
                f = min (f, 6.0f);
 
-               _io->set_gain (dB_to_coefficient(f), this);
+               _io->gain_control()->set_value (dB_to_coefficient(f));
 
                if (gain_display.has_focus()) {
                        PublicEditor::instance().reset_focus();
@@ -599,7 +634,7 @@ void
 GainMeter::gain_adjusted ()
 {
        if (!ignore_toggle) {
-               _io->set_gain (slider_position_to_gain (gain_adjustment.get_value()), this);
+               _io->gain_control()->set_value (slider_position_to_gain (gain_adjustment.get_value()));
        }
        show_gain ();
 }
@@ -617,7 +652,7 @@ GainMeter::effective_gain_display ()
 }
 
 void
-GainMeter::gain_changed (void *src)
+GainMeter::gain_changed ()
 {
        Gtkmm2ext::UI::instance()->call_slot (mem_fun(*this, &GainMeter::effective_gain_display));
 }
@@ -637,7 +672,7 @@ GainMeter::set_fader_name (const char * name)
 void
 GainMeter::update_gain_sensitive ()
 {
-       static_cast<Gtkmm2ext::SliderController*>(gain_slider)->set_sensitive (!(_io->gain_automation_state() & Play));
+       static_cast<Gtkmm2ext::SliderController*>(gain_slider)->set_sensitive (!(_io->gain_control()->list()->automation_state() & Play));
 }
 
 
@@ -780,14 +815,14 @@ GainMeter::meter_point_clicked ()
 gint
 GainMeter::start_gain_touch (GdkEventButton* ev)
 {
-       _io->start_gain_touch ();
+       _io->gain_control()->list()->start_touch ();
        return FALSE;
 }
 
 gint
 GainMeter::end_gain_touch (GdkEventButton* ev)
 {
-       _io->end_gain_touch ();
+       _io->gain_control()->list()->stop_touch ();
        return FALSE;
 }
 
@@ -845,7 +880,7 @@ GainMeter::_astate_string (AutoState state, bool shrt)
 
        switch (state) {
        case Off:
-               sstr = (shrt ? "O" : _("O"));
+               sstr = (shrt ? "M" : _("M"));
                break;
        case Play:
                sstr = (shrt ? "P" : _("P"));
@@ -891,10 +926,10 @@ GainMeter::gain_automation_style_changed ()
   // Route* _route = dynamic_cast<Route*>(&_io);
        switch (_width) {
        case Wide:
-               gain_automation_style_button.set_label (astyle_string(_io->gain_automation_curve().automation_style()));
+               gain_automation_style_button.set_label (astyle_string(_io->gain_control()->list()->automation_style()));
                break;
        case Narrow:
-               gain_automation_style_button.set_label  (short_astyle_string(_io->gain_automation_curve().automation_style()));
+               gain_automation_style_button.set_label  (short_astyle_string(_io->gain_control()->list()->automation_style()));
                break;
        }
 }
@@ -909,14 +944,14 @@ GainMeter::gain_automation_state_changed ()
 
        switch (_width) {
        case Wide:
-               gain_automation_state_button.set_label (astate_string(_io->gain_automation_curve().automation_state()));
+               gain_automation_state_button.set_label (astate_string(_io->gain_control()->list()->automation_state()));
                break;
        case Narrow:
-               gain_automation_state_button.set_label (short_astate_string(_io->gain_automation_curve().automation_state()));
+               gain_automation_state_button.set_label (short_astate_string(_io->gain_control()->list()->automation_state()));
                break;
        }
 
-       x = (_io->gain_automation_state() != Off);
+       x = (_io->gain_control()->list()->automation_state() != Off);
        
        if (gain_automation_state_button.get_active() != x) {
                ignore_toggle = true;