implement meterbridge & meter-strip
authorRobin Gareus <robin@gareus.org>
Sun, 23 Jun 2013 14:05:52 +0000 (16:05 +0200)
committerRobin Gareus <robin@gareus.org>
Wed, 10 Jul 2013 13:27:02 +0000 (15:27 +0200)
gtk2_ardour/ardour_ui_dependents.cc
gtk2_ardour/ardour_ui_ed.cc
gtk2_ardour/gain_meter.h
gtk2_ardour/meter_strip.cc [new file with mode: 0644]
gtk2_ardour/meter_strip.h [new file with mode: 0644]
gtk2_ardour/meterbridge.cc [new file with mode: 0644]
gtk2_ardour/meterbridge.h [new file with mode: 0644]
gtk2_ardour/wscript

index 5269bb93ed575dd94831ac01c6c854d9090b65a1..821382717fea91570302bb6fe6c4d68a79887c20 100644 (file)
@@ -78,6 +78,7 @@ ARDOUR_UI::connect_dependents_to_session (ARDOUR::Session *s)
        editor->set_session (s);
        BootMessage (_("Setup Mixer"));
        mixer->set_session (s);
+       meterbridge->set_session (s);
 
        /* its safe to do this now */
 
index c5a9ee0775cf3d15bd87ed4c113bd1cc443976f4..94cb9f2c177d2fff26192422197292d55905628f 100644 (file)
@@ -658,10 +658,12 @@ ARDOUR_UI::save_ardour_state ()
 
        XMLNode& enode (static_cast<Stateful*>(editor)->get_state());
        XMLNode& mnode (mixer->get_state());
+       XMLNode& bnode (meterbridge->get_state());
 
        if (_session) {
                _session->add_instant_xml (enode);
                _session->add_instant_xml (mnode);
+               _session->add_instant_xml (bnode);
                if (location_ui) {
                        _session->add_instant_xml (location_ui->ui().get_state ());
                }
index cec844184aaacb3b5d8295999d5bcd7c9ffe1cfa..d23c9051b9736a170368bb235428e8c0f26e6e19 100644 (file)
@@ -99,6 +99,7 @@ class GainMeterBase : virtual public sigc::trackable, ARDOUR::SessionHandlePtr
   protected:
 
        friend class MixerStrip;
+       friend class MeterStrip;
        boost::shared_ptr<ARDOUR::Route> _route;
        boost::shared_ptr<ARDOUR::PeakMeter> _meter;
        boost::shared_ptr<ARDOUR::Amp> _amp;
diff --git a/gtk2_ardour/meter_strip.cc b/gtk2_ardour/meter_strip.cc
new file mode 100644 (file)
index 0000000..ab80aa6
--- /dev/null
@@ -0,0 +1,95 @@
+/*
+    Copyright (C) 2013 Paul Davis
+    Author: Robin Gareus
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+#include <list>
+
+#include <sigc++/bind.h>
+
+#include "ardour/session.h"
+#include "ardour/route.h"
+#include "ardour/route_group.h"
+
+#include <gtkmm2ext/gtk_ui.h>
+
+#include "ardour_ui.h"
+#include "gui_thread.h"
+#include "ardour_window.h"
+
+#include "meterbridge.h"
+#include "meter_strip.h"
+
+#include "i18n.h"
+
+using namespace ARDOUR;
+using namespace PBD;
+using namespace Gtk;
+using namespace Gtkmm2ext;
+using namespace std;
+
+PBD::Signal1<void,MeterStrip*> MeterStrip::CatchDeletion;
+
+MeterStrip::MeterStrip (Meterbridge& mtr, Session* sess, boost::shared_ptr<ARDOUR::Route> rt)
+       : _meterbridge(mtr)
+{
+       _route = rt;
+
+       level_meter = new LevelMeter(sess);
+       level_meter->set_meter (rt->shared_peak_meter().get());
+       level_meter->clear_meters();
+       level_meter->setup_meters (350, 6);
+
+       rt->DropReferences.connect (route_connections, invalidator (*this), boost::bind (&MeterStrip::self_delete, this), gui_context());
+       rt->PropertyChanged.connect (route_connections, invalidator (*this), boost::bind (&MeterStrip::strip_property_changed, this, _1), gui_context());
+
+
+       pack_start (*level_meter, true, true);
+       level_meter->show();
+
+       label = manage(new Gtk::Label(rt->name().c_str()));
+       pack_start (*label, true, true);
+       label->show();
+}
+
+void
+MeterStrip::fast_update ()
+{
+       float mpeak = level_meter->update_meters();
+}
+
+MeterStrip::~MeterStrip ()
+{
+       delete level_meter;
+       CatchDeletion (this);
+}
+
+void
+MeterStrip::self_delete ()
+{
+       delete this;
+}
+
+void
+MeterStrip::strip_property_changed (const PropertyChange& what_changed)
+{
+       if (!what_changed.contains (ARDOUR::Properties::name)) {
+               return;
+       }
+       ENSURE_GUI_THREAD (*this, &MeterStrip::strip_name_changed, what_changed)
+       label->set_text(_route->name());
+}
diff --git a/gtk2_ardour/meter_strip.h b/gtk2_ardour/meter_strip.h
new file mode 100644 (file)
index 0000000..f74093b
--- /dev/null
@@ -0,0 +1,72 @@
+/*
+    Copyright (C) 2013 Paul Davis
+    Author: Robin Gareus
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+#ifndef __ardour_meter_strip__
+#define __ardour_meter_strip__
+
+#include <vector>
+
+#include <cmath>
+
+#include "pbd/stateful.h"
+
+#include "ardour/types.h"
+#include "ardour/ardour.h"
+
+#include "level_meter.h"
+
+namespace ARDOUR {
+       class Route;
+       class Session;
+}
+namespace Gtk {
+       class Window;
+       class Style;
+}
+
+class Meterbridge;
+
+class MeterStrip : public Gtk::VBox
+{
+  public:
+       MeterStrip (Meterbridge&, ARDOUR::Session*, boost::shared_ptr<ARDOUR::Route>);
+       ~MeterStrip ();
+
+       void fast_update ();
+
+       static PBD::Signal1<void,MeterStrip*> CatchDeletion;
+
+  protected:
+       boost::shared_ptr<ARDOUR::Route> _route;
+       PBD::ScopedConnectionList route_connections;
+       void self_delete ();
+
+  private:
+       Meterbridge& _meterbridge;
+       Gtk::Label *label;
+
+       LevelMeter   *level_meter;
+       void meter_changed ();
+
+       PBD::ScopedConnection _config_connection;
+       void strip_property_changed (const PBD::PropertyChange&);
+
+};
+
+#endif /* __ardour_mixer_strip__ */
diff --git a/gtk2_ardour/meterbridge.cc b/gtk2_ardour/meterbridge.cc
new file mode 100644 (file)
index 0000000..3eeb640
--- /dev/null
@@ -0,0 +1,367 @@
+/*
+    Copyright (C) 2012 Paul Davis
+    Author: Robin Gareus
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+#ifdef WAF_BUILD
+#include "gtk2ardour-config.h"
+#endif
+
+#include <map>
+#include <sigc++/bind.h>
+
+#include <gtkmm/accelmap.h>
+
+#include <glibmm/threads.h>
+
+#include <gtkmm2ext/gtk_ui.h>
+#include <gtkmm2ext/utils.h>
+#include <gtkmm2ext/window_title.h>
+
+#include "ardour/debug.h"
+#include "ardour/midi_track.h"
+#include "ardour/route_group.h"
+#include "ardour/session.h"
+
+#include "meterbridge.h"
+
+#include "monitor_section.h"
+#include "public_editor.h"
+#include "ardour_ui.h"
+#include "utils.h"
+#include "route_sorter.h"
+#include "actions.h"
+#include "gui_thread.h"
+
+#include "i18n.h"
+
+using namespace ARDOUR;
+using namespace PBD;
+using namespace Gtk;
+using namespace Glib;
+using namespace Gtkmm2ext;
+using namespace std;
+
+using PBD::atoi;
+
+Meterbridge* Meterbridge::_instance = 0;
+
+Meterbridge*
+Meterbridge::instance ()
+{
+       if (!_instance) {
+               _instance  = new Meterbridge;
+       }
+
+       return _instance;
+}
+
+Meterbridge::Meterbridge ()
+       : Window (Gtk::WINDOW_TOPLEVEL)
+       , VisibilityTracker (*((Gtk::Window*) this))
+       , _visible (false)
+{
+       set_name ("Meter Bridge");
+
+       set_wmclass (X_("ardour_mixer"), PROGRAM_NAME);
+
+       signal_delete_event().connect (sigc::mem_fun (*this, &Meterbridge::hide_window));
+       signal_configure_event().connect (sigc::mem_fun (*ARDOUR_UI::instance(), &ARDOUR_UI::configure_handler));
+
+       MeterStrip::CatchDeletion.connect (*this, invalidator (*this), boost::bind (&Meterbridge::remove_strip, this, _1), gui_context());
+
+       global_hpacker.set_spacing(1);
+       scroller.add (global_hpacker);
+       scroller.set_policy (Gtk::POLICY_AUTOMATIC, Gtk::POLICY_NEVER);
+       global_vpacker.pack_start (scroller, true, true);
+       add (global_vpacker);
+
+       global_hpacker.show();
+       global_vpacker.show();
+       scroller.show();
+}
+
+Meterbridge::~Meterbridge ()
+{
+}
+
+void
+Meterbridge::show_window ()
+{
+       present();
+       if (!_visible) {
+               set_window_pos_and_size ();
+       }
+       _visible = true;
+}
+
+void
+Meterbridge::set_window_pos_and_size ()
+{
+       resize (m_width, m_height);
+       move (m_root_x, m_root_y);
+}
+
+void
+Meterbridge::get_window_pos_and_size ()
+{
+       get_position(m_root_x, m_root_y);
+       get_size(m_width, m_height);
+}
+
+bool
+Meterbridge::hide_window (GdkEventAny *ev)
+{
+       get_window_pos_and_size();
+       _visible = false;
+       return just_hide_it(ev, static_cast<Gtk::Window *>(this));
+}
+
+bool
+Meterbridge::on_key_press_event (GdkEventKey* ev)
+{
+       if (gtk_window_propagate_key_event (GTK_WINDOW(gobj()), ev)) {
+               return true;
+       }
+       return forward_key_press (ev);
+}
+
+bool
+Meterbridge::on_key_release_event (GdkEventKey* ev)
+{
+       if (gtk_window_propagate_key_event (GTK_WINDOW(gobj()), ev)) {
+               return true;
+       }
+       /* don't forward releases */
+       return true;
+}
+
+
+// copy from gtk2_ardour/mixer_ui.cc 
+struct SignalOrderRouteSorter {
+    bool operator() (boost::shared_ptr<Route> a, boost::shared_ptr<Route> b) {
+           if (a->is_master() || a->is_monitor()) {
+                   /* "a" is a special route (master, monitor, etc), and comes
+                    * last in the mixer ordering
+                    */
+                   return false;
+           } else if (b->is_master() || b->is_monitor()) {
+                   /* everything comes before b */
+                   return true;
+           }
+           return a->order_key (MixerSort) < b->order_key (MixerSort);
+    }
+};
+
+void
+Meterbridge::set_session (Session* s)
+{
+       SessionHandlePtr::set_session (s);
+
+       if (!_session) {
+               return;
+       }
+
+       XMLNode* node = _session->instant_xml(X_("Meterbridge"));
+       if (node) {
+               set_state (*node);
+       }
+
+       SignalOrderRouteSorter sorter;
+       boost::shared_ptr<RouteList> routes = _session->get_routes();
+
+       RouteList copy(*routes);
+       copy.sort(sorter);
+       add_strips(copy);
+
+       _session->RouteAdded.connect (_session_connections, invalidator (*this), boost::bind (&Meterbridge::add_strips, this, _1), gui_context());
+
+       _session->config.ParameterChanged.connect (_session_connections, invalidator (*this), boost::bind (&Meterbridge::parameter_changed, this, _1), gui_context());
+
+       if (_visible) {
+               show_window();
+               ActionManager::check_toggleaction ("<Actions>/Common/toggle-meterbridge");
+       }
+       start_updating ();
+}
+
+void
+Meterbridge::session_going_away ()
+{
+       ENSURE_GUI_THREAD (*this, &Meterbridge::session_going_away);
+
+       for (list<MeterStrip *>::iterator i = strips.begin(); i != strips.end(); ++i) {
+               delete (*i);
+       }
+
+       strips.clear ();
+       stop_updating ();
+
+       SessionHandlePtr::session_going_away ();
+
+       _session = 0;
+}
+
+int
+Meterbridge::set_state (const XMLNode& node)
+{
+       const XMLProperty* prop;
+       XMLNode* geometry;
+
+       m_width = default_width;
+       m_height = default_height;
+       m_root_x = 1;
+       m_root_y = 1;
+
+       if ((geometry = find_named_node (node, "geometry")) != 0) {
+
+               XMLProperty* prop;
+
+               if ((prop = geometry->property("x_size")) == 0) {
+                       prop = geometry->property ("x-size");
+               }
+               if (prop) {
+                       m_width = atoi(prop->value());
+               }
+               if ((prop = geometry->property("y_size")) == 0) {
+                       prop = geometry->property ("y-size");
+               }
+               if (prop) {
+                       m_height = atoi(prop->value());
+               }
+
+               if ((prop = geometry->property ("x_pos")) == 0) {
+                       prop = geometry->property ("x-pos");
+               }
+               if (prop) {
+                       m_root_x = atoi (prop->value());
+
+               }
+               if ((prop = geometry->property ("y_pos")) == 0) {
+                       prop = geometry->property ("y-pos");
+               }
+               if (prop) {
+                       m_root_y = atoi (prop->value());
+               }
+       }
+
+       set_window_pos_and_size ();
+
+       if ((prop = node.property ("show-meterbridge"))) {
+               if (string_is_affirmative (prop->value())) {
+                      _visible = true;
+               }
+       }
+
+       return 0;
+}
+
+XMLNode&
+Meterbridge::get_state (void)
+{
+       XMLNode* node = new XMLNode ("Meterbridge");
+
+       if (is_realized()) {
+               Glib::RefPtr<Gdk::Window> win = get_window();
+
+               get_window_pos_and_size ();
+
+               XMLNode* geometry = new XMLNode ("geometry");
+               char buf[32];
+               snprintf(buf, sizeof(buf), "%d", m_width);
+               geometry->add_property(X_("x_size"), string(buf));
+               snprintf(buf, sizeof(buf), "%d", m_height);
+               geometry->add_property(X_("y_size"), string(buf));
+               snprintf(buf, sizeof(buf), "%d", m_root_x);
+               geometry->add_property(X_("x_pos"), string(buf));
+               snprintf(buf, sizeof(buf), "%d", m_root_y);
+               geometry->add_property(X_("y_pos"), string(buf));
+               node->add_child_nocopy (*geometry);
+       }
+
+       node->add_property ("show-meterbridge", _visible ? "yes" : "no");
+       return *node;
+}
+
+
+gint
+Meterbridge::start_updating ()
+{
+       fast_screen_update_connection = ARDOUR_UI::instance()->SuperRapidScreenUpdate.connect (sigc::mem_fun(*this, &Meterbridge::fast_update_strips));
+       return 0;
+}
+
+gint
+Meterbridge::stop_updating ()
+{
+       fast_screen_update_connection.disconnect();
+       return 0;
+}
+
+void
+Meterbridge::fast_update_strips ()
+{
+       if (!is_mapped () || !_session) {
+               return;
+       }
+       for (list<MeterStrip *>::iterator i = strips.begin(); i != strips.end(); ++i) {
+               (*i)->fast_update ();
+       }
+}
+
+void
+Meterbridge::add_strips (RouteList& routes)
+{
+       MeterStrip* strip;
+       for (RouteList::iterator x = routes.begin(); x != routes.end(); ++x) {
+               boost::shared_ptr<Route> route = (*x);
+               if (route->is_auditioner()) {
+                       continue;
+               }
+               if (route->is_monitor()) {
+                       continue;
+               }
+
+               strip = new MeterStrip (*this, _session, route);
+               strips.push_back (strip);
+
+               // TODO sort-routes, insert at proper position
+               // order_key
+
+               global_hpacker.pack_start (*strip, false, false);
+               strip->show();
+       }
+}
+
+void
+Meterbridge::remove_strip (MeterStrip* strip)
+{
+       if (_session && _session->deletion_in_progress()) {
+               return;
+       }
+
+       list<MeterStrip *>::iterator i;
+       if ((i = find (strips.begin(), strips.end(), strip)) != strips.end()) {
+               strips.erase (i);
+       }
+}
+
+void
+Meterbridge::parameter_changed (string const & p)
+{
+}
diff --git a/gtk2_ardour/meterbridge.h b/gtk2_ardour/meterbridge.h
new file mode 100644 (file)
index 0000000..3bdf048
--- /dev/null
@@ -0,0 +1,94 @@
+/*
+    Copyright (C) 2012 Paul Davis
+    Author: Robin Gareus
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+#ifndef __ardour_meterbridge_h__
+#define __ardour_meterbridge_h__
+
+#include <gtkmm/box.h>
+#include <gtkmm/scrolledwindow.h>
+#include <gtkmm/label.h>
+#include <gtkmm/window.h>
+
+#include "ardour/ardour.h"
+#include "ardour/types.h"
+#include "ardour/session_handle.h"
+
+#include "pbd/stateful.h"
+#include "pbd/signals.h"
+
+#include "gtkmm2ext/visibility_tracker.h"
+
+#include "meter_strip.h"
+
+class Meterbridge :
+       public Gtk::Window,
+       public PBD::ScopedConnectionList,
+       public ARDOUR::SessionHandlePtr,
+       public Gtkmm2ext::VisibilityTracker
+{
+  public:
+       static Meterbridge* instance();
+       ~Meterbridge();
+
+       void set_session (ARDOUR::Session *);
+
+       XMLNode& get_state (void);
+       int set_state (const XMLNode& );
+
+       void show_window ();
+       bool hide_window (GdkEventAny *ev);
+
+  private:
+       Meterbridge ();
+       static Meterbridge* _instance;
+
+       bool _visible;
+
+       Gtk::ScrolledWindow scroller;
+       Gtk::HBox global_hpacker;
+       Gtk::VBox global_vpacker;
+
+       gint start_updating ();
+       gint stop_updating ();
+
+       sigc::connection fast_screen_update_connection;
+       void fast_update_strips ();
+
+       void add_strips (ARDOUR::RouteList&);
+       void remove_strip (MeterStrip *);
+
+       void parameter_changed (std::string const &);
+
+       void session_going_away ();
+
+       std::list<MeterStrip *> strips;
+
+       static const int32_t default_width = 300;
+       static const int32_t default_height = 400;
+       // for restoring window geometry.
+       int m_root_x, m_root_y, m_width, m_height;
+
+       void set_window_pos_and_size ();
+       void get_window_pos_and_size ();
+
+       bool on_key_press_event (GdkEventKey*);
+       bool on_key_release_event (GdkEventKey*);
+};
+
+#endif
index 325f0eac629096cc6b0e5a2f419286452d09befa..6bdbdc16a1d089a1350ddb557b6788bad4b6045b 100644 (file)
@@ -146,6 +146,7 @@ gtk2_ardour_sources = [
         'mixer_strip.cc',
         'mixer_ui.cc',
         'meterbridge.cc',
+        'meter_strip.cc',
         'monitor_section.cc',
         'mono_panner.cc',
         'mono_panner_editor.cc',