From dd51b638bccec5282617e6f82ee7664d5c2a13cc Mon Sep 17 00:00:00 2001 From: VKamyshniy Date: Sun, 20 Jul 2014 18:02:36 +0300 Subject: [PATCH] [Summary] Progressing embedded meterbridge --- gtk2_ardour/compact_meter_bridge.cc | 2 +- gtk2_ardour/compact_meter_strip.cc | 48 ++++++++++----- gtk2_ardour/compact_meter_strip.h | 7 ++- gtk2_ardour/editor.cc | 46 -------------- gtk2_ardour/editor.h | 3 - gtk2_ardour/ui/compact_meter_bridge.xml | 2 +- gtk2_ardour/ui/compact_meter_strip.xml | 11 +++- libs/gtkmm2ext/fastmeter.cc | 81 +++++++++++-------------- libs/gtkmm2ext/gtkmm2ext/fastmeter.h | 11 ++-- 9 files changed, 89 insertions(+), 122 deletions(-) diff --git a/gtk2_ardour/compact_meter_bridge.cc b/gtk2_ardour/compact_meter_bridge.cc index 6122c7a9a5..d77d3a70b5 100644 --- a/gtk2_ardour/compact_meter_bridge.cc +++ b/gtk2_ardour/compact_meter_bridge.cc @@ -180,7 +180,7 @@ CompactMeterbridge::remove_strip (CompactMeterStrip* strip) } for (list::iterator i = _strips.begin(); i != _strips.end(); ++i) { - if ( (*i) == strip) { + if ((*i) == strip) { _strips.erase (i); break; } diff --git a/gtk2_ardour/compact_meter_strip.cc b/gtk2_ardour/compact_meter_strip.cc index 115a44399f..6ef7d89a1c 100644 --- a/gtk2_ardour/compact_meter_strip.cc +++ b/gtk2_ardour/compact_meter_strip.cc @@ -17,6 +17,7 @@ */ #include "ardour/meter.h" +#include "ardour/track.h" #include "ardour_ui.h" #include "gui_thread.h" #include "meter_patterns.h" @@ -38,24 +39,42 @@ CompactMeterStrip::CompactMeterStrip (Session* sess, boost::shared_ptrroot (), XMLNodeMap ()); + const XMLNode& definition = *xml_tree ()->root (); + XMLNodeMap nothing; + set_attributes (*this, *xml_tree ()->root (), nothing); - level_meter.set_meter (_route->shared_peak_meter().get()); - level_meter.clear_meters(); - level_meter.set_type (_route->meter_type()); - level_meter.setup_meters (__meter_width, __meter_width); - level_meter_home.add (level_meter); + _level_meter.set_meter (_route->shared_peak_meter().get()); + _level_meter.clear_meters(); + _level_meter.set_type (_route->meter_type()); + _level_meter.setup_meters (__meter_width, __meter_width); + _level_meter_home.add (_level_meter); - _route->shared_peak_meter()->ConfigurationChanged.connect ( - route_connections, invalidator (*this), boost::bind (&CompactMeterStrip::meter_configuration_changed, this, _1), gui_context() - ); + _route->shared_peak_meter()->ConfigurationChanged.connect (_route_connections, + invalidator (*this), + boost::bind (&CompactMeterStrip::meter_configuration_changed, + this, + _1), + gui_context()); meter_configuration_changed (_route->shared_peak_meter()->input_streams ()); - _route->DropReferences.connect (route_connections, invalidator (*this), boost::bind (&CompactMeterStrip::self_delete, this), gui_context()); + _route->DropReferences.connect (_route_connections, + invalidator (*this), + boost::bind (&CompactMeterStrip::self_delete, + this), + gui_context()); + boost::shared_ptr t = boost::dynamic_pointer_cast (_route); + if (t) { + t->RecordEnableChanged.connect (_route_connections, + invalidator (*this), + boost::bind (&CompactMeterStrip::update_rec_display, + this), gui_context()); + update_rec_display (); + } } CompactMeterStrip::~CompactMeterStrip () @@ -72,17 +91,18 @@ CompactMeterStrip::self_delete () void CompactMeterStrip::update_rec_display () { + _record_indicator.set_state ((_route && _route->record_enabled ()) ? Gtk::STATE_ACTIVE : Gtk::STATE_NORMAL); } void CompactMeterStrip::fast_update () { - level_meter.update_meters(); + _level_meter.update_meters(); } void CompactMeterStrip::meter_configuration_changed (ChanCount c) { - level_meter.setup_meters (__meter_width, __meter_width); + _level_meter.setup_meters (__meter_width, __meter_width); } diff --git a/gtk2_ardour/compact_meter_strip.h b/gtk2_ardour/compact_meter_strip.h index 986180345f..50944c2a01 100644 --- a/gtk2_ardour/compact_meter_strip.h +++ b/gtk2_ardour/compact_meter_strip.h @@ -43,9 +43,10 @@ class CompactMeterStrip :public Gtk::EventBox, public WavesUI void self_delete (); private: - Gtk::Box& level_meter_home; - LevelMeterHBox level_meter; - PBD::ScopedConnectionList route_connections; + Gtk::Box& _level_meter_home; + LevelMeterHBox _level_meter; + Gtk::EventBox& _record_indicator; + PBD::ScopedConnectionList _route_connections; static int __meter_width; void meter_configuration_changed (ARDOUR::ChanCount); void update_rec_display (); diff --git a/gtk2_ardour/editor.cc b/gtk2_ardour/editor.cc index 56161e9dd3..c0f683b1a8 100644 --- a/gtk2_ardour/editor.cc +++ b/gtk2_ardour/editor.cc @@ -646,12 +646,10 @@ Editor::Editor () Glib::PropertyProxy proxy = edit_pane.property_position(); proxy.signal_changed().connect (bind (sigc::ptr_fun (pane_size_watcher), static_cast (&edit_pane))); - top_hbox.pack_start (toolbar_frame); HBox *hbox = manage (new HBox); hbox->pack_start (edit_pane, true, true); - global_vpacker.pack_start (top_hbox, false, false); global_vpacker.pack_start (*hbox, true, true); set_name ("EditorWindow"); @@ -3003,15 +3001,6 @@ Editor::setup_toolbar () _mouse_mode_tearoff->set_can_be_torn_off (false); } - _mouse_mode_tearoff->Detach.connect (sigc::bind (sigc::mem_fun(*this, &Editor::detach_tearoff), static_cast(&toolbar_hbox), - &_mouse_mode_tearoff->tearoff_window())); - _mouse_mode_tearoff->Attach.connect (sigc::bind (sigc::mem_fun(*this, &Editor::reattach_tearoff), static_cast (&toolbar_hbox), - &_mouse_mode_tearoff->tearoff_window(), 1)); - _mouse_mode_tearoff->Hidden.connect (sigc::bind (sigc::mem_fun(*this, &Editor::detach_tearoff), static_cast(&toolbar_hbox), - &_mouse_mode_tearoff->tearoff_window())); - _mouse_mode_tearoff->Visible.connect (sigc::bind (sigc::mem_fun(*this, &Editor::reattach_tearoff), static_cast (&toolbar_hbox), - &_mouse_mode_tearoff->tearoff_window(), 1)); - /* Zoom */ _zoom_box.set_spacing (2); @@ -3085,14 +3074,6 @@ Editor::setup_toolbar () if (!ARDOUR::Profile->get_trx()) { _zoom_tearoff = manage (new TearOff (_zoom_box)); - _zoom_tearoff->Detach.connect (sigc::bind (sigc::mem_fun(*this, &Editor::detach_tearoff), static_cast(&toolbar_hbox), - &_zoom_tearoff->tearoff_window())); - _zoom_tearoff->Attach.connect (sigc::bind (sigc::mem_fun(*this, &Editor::reattach_tearoff), static_cast (&toolbar_hbox), - &_zoom_tearoff->tearoff_window(), 0)); - _zoom_tearoff->Hidden.connect (sigc::bind (sigc::mem_fun(*this, &Editor::detach_tearoff), static_cast(&toolbar_hbox), - &_zoom_tearoff->tearoff_window())); - _zoom_tearoff->Visible.connect (sigc::bind (sigc::mem_fun(*this, &Editor::reattach_tearoff), static_cast (&toolbar_hbox), - &_zoom_tearoff->tearoff_window(), 0)); } snap_box.set_spacing (2); @@ -3144,15 +3125,6 @@ Editor::setup_toolbar () _tools_tearoff->set_can_be_torn_off (false); } - _tools_tearoff->Detach.connect (sigc::bind (sigc::mem_fun(*this, &Editor::detach_tearoff), static_cast(&toolbar_hbox), - &_tools_tearoff->tearoff_window())); - _tools_tearoff->Attach.connect (sigc::bind (sigc::mem_fun(*this, &Editor::reattach_tearoff), static_cast (&toolbar_hbox), - &_tools_tearoff->tearoff_window(), 0)); - _tools_tearoff->Hidden.connect (sigc::bind (sigc::mem_fun(*this, &Editor::detach_tearoff), static_cast(&toolbar_hbox), - &_tools_tearoff->tearoff_window())); - _tools_tearoff->Visible.connect (sigc::bind (sigc::mem_fun(*this, &Editor::reattach_tearoff), static_cast (&toolbar_hbox), - &_tools_tearoff->tearoff_window(), 0)); - toolbar_hbox.set_spacing (10); toolbar_hbox.set_border_width (1); @@ -3929,24 +3901,6 @@ Editor::pane_allocation_handler (Allocation &alloc, Paned* which) } } -void -Editor::detach_tearoff (Box* /*b*/, Window* /*w*/) -{ - if ((_tools_tearoff->torn_off() || !_tools_tearoff->visible()) && - (_mouse_mode_tearoff->torn_off() || !_mouse_mode_tearoff->visible()) && - (_zoom_tearoff && (_zoom_tearoff->torn_off() || !_zoom_tearoff->visible()))) { - top_hbox.remove (toolbar_frame); - } -} - -void -Editor::reattach_tearoff (Box* /*b*/, Window* /*w*/, int32_t /*n*/) -{ - if (toolbar_frame.get_parent() == 0) { - top_hbox.pack_end (toolbar_frame); - } -} - void Editor::set_show_measures (bool yn) { diff --git a/gtk2_ardour/editor.h b/gtk2_ardour/editor.h index 74c2931c93..3efad7934b 100644 --- a/gtk2_ardour/editor.h +++ b/gtk2_ardour/editor.h @@ -959,7 +959,6 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD std::vector region_boundary_cache; void build_region_boundary_cache (); - Gtk::HBox top_hbox; Gtk::HBox bottom_hbox; Gtk::Table edit_packer; @@ -1912,8 +1911,6 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD void cms_new (boost::shared_ptr); void current_mixer_strip_hidden (); - void detach_tearoff (Gtk::Box* b, Gtk::Window* w); - void reattach_tearoff (Gtk::Box* b, Gtk::Window* w, int32_t n); #ifdef GTKOSX void ensure_all_elements_drawn (); #endif diff --git a/gtk2_ardour/ui/compact_meter_bridge.xml b/gtk2_ardour/ui/compact_meter_bridge.xml index e95ab18888..c245860ec8 100644 --- a/gtk2_ardour/ui/compact_meter_bridge.xml +++ b/gtk2_ardour/ui/compact_meter_bridge.xml @@ -6,7 +6,7 @@ - + diff --git a/gtk2_ardour/ui/compact_meter_strip.xml b/gtk2_ardour/ui/compact_meter_strip.xml index 625aeca34e..0bad97080b 100644 --- a/gtk2_ardour/ui/compact_meter_strip.xml +++ b/gtk2_ardour/ui/compact_meter_strip.xml @@ -1,7 +1,12 @@ - - - + + + + diff --git a/libs/gtkmm2ext/fastmeter.cc b/libs/gtkmm2ext/fastmeter.cc index 5972779271..a8a46bfbb2 100644 --- a/libs/gtkmm2ext/fastmeter.cc +++ b/libs/gtkmm2ext/fastmeter.cc @@ -504,7 +504,7 @@ FastMeter::vertical_size_allocate (Gtk::Allocation &alloc) pixwidth = request_width; } - DrawingArea::on_size_allocate (alloc); + CairoWidget::on_size_allocate (alloc); } void @@ -529,31 +529,28 @@ FastMeter::horizontal_size_allocate (Gtk::Allocation &alloc) pixheight = request_height; } - DrawingArea::on_size_allocate (alloc); + CairoWidget::on_size_allocate (alloc); } -bool -FastMeter::on_expose_event (GdkEventExpose* ev) +void +FastMeter::render (cairo_t* cr) { if (orientation == Vertical) { - return vertical_expose (ev); + vertical_render (cr); } else { - return horizontal_expose (ev); + horizontal_render (cr); } } -bool -FastMeter::vertical_expose (GdkEventExpose* ev) +void +FastMeter::vertical_render (cairo_t* cr) { - Glib::RefPtr win = get_window (); gint top_of_meter; GdkRectangle intersection; GdkRectangle background; - cairo_t* cr = gdk_cairo_create (get_window ()->gobj()); - - cairo_rectangle (cr, ev->area.x, ev->area.y, ev->area.width, ev->area.height); - cairo_clip (cr); + //cairo_rectangle (cr, ev->area.x, ev->area.y, ev->area.width, ev->area.height); + //cairo_clip (cr); //cairo_set_source_rgb (cr, 0, 0, 0); // black //rounded_rectangle (cr, 0, 0, pixwidth + 2, pixheight + 2, 2); @@ -572,19 +569,22 @@ FastMeter::vertical_expose (GdkEventExpose* ev) background.width = pixrect.width; background.height = pixheight - top_of_meter; - if (gdk_rectangle_intersect (&background, &ev->area, &intersection)) { - cairo_set_source (cr, bgpattern->cobj()); - cairo_rectangle (cr, intersection.x, intersection.y, intersection.width, intersection.height); - cairo_fill (cr); - } + // Switching to CAIRO we would like to draw on the container's bkg. + //if (gdk_rectangle_intersect (&background, &ev->area, &intersection)) { + // cairo_set_source (cr, bgpattern->cobj()); + // cairo_rectangle (cr, intersection.x, intersection.y, intersection.width, intersection.height); + // cairo_fill (cr); + //} - if (gdk_rectangle_intersect (&pixrect, &ev->area, &intersection)) { + // MEMO: Normaly MATURE OS clips so called invalidated rects itself making APP free of + // heavy operations which OS does with graphic HW + //if (gdk_rectangle_intersect (&pixrect, &ev->area, &intersection)) { // draw the part of the meter image that we need. the area we draw is bounded "in reverse" (top->bottom) //cairo_set_source (cr, fgpattern->cobj()); cairo_set_source_rgba (cr, 0.69, 0.69, 0.69, 1); - cairo_rectangle (cr, intersection.x, intersection.y, intersection.width, intersection.height); + cairo_rectangle (cr, pixrect.x, pixrect.y, pixrect.width, pixrect.height); cairo_fill (cr); - } + //} // draw peak bar @@ -611,24 +611,17 @@ FastMeter::vertical_expose (GdkEventExpose* ev) last_peak_rect.width = 0; last_peak_rect.height = 0; } - - cairo_destroy (cr); - - return TRUE; } -bool -FastMeter::horizontal_expose (GdkEventExpose* ev) +void +FastMeter::horizontal_render (cairo_t* cr) { - Glib::RefPtr win = get_window (); gint right_of_meter; GdkRectangle intersection; GdkRectangle background; - cairo_t* cr = gdk_cairo_create (get_window ()->gobj()); - - cairo_rectangle (cr, ev->area.x, ev->area.y, ev->area.width, ev->area.height); - cairo_clip (cr); + //cairo_rectangle (cr, ev->area.x, ev->area.y, ev->area.width, ev->area.height); + //cairo_clip (cr); //cairo_set_source_rgb (cr, 0, 0, 0); // black //rounded_rectangle (cr, 0, 0, pixwidth + 2, pixheight + 2, 2); @@ -646,17 +639,17 @@ FastMeter::horizontal_expose (GdkEventExpose* ev) background.width = pixwidth - right_of_meter; background.height = pixheight; - if (gdk_rectangle_intersect (&background, &ev->area, &intersection)) { - cairo_set_source (cr, bgpattern->cobj()); - cairo_rectangle (cr, intersection.x, intersection.y, intersection.width, intersection.height); - cairo_fill (cr); - } + //if (gdk_rectangle_intersect (&background, &ev->area, &intersection)) { + // cairo_set_source (cr, bgpattern->cobj()); + // cairo_rectangle (cr, intersection.x, intersection.y, intersection.width, intersection.height); + // cairo_fill (cr); + //} - if (gdk_rectangle_intersect (&pixrect, &ev->area, &intersection)) { - cairo_set_source (cr, fgpattern->cobj()); - cairo_rectangle (cr, intersection.x, intersection.y, intersection.width, intersection.height); - cairo_fill (cr); - } + //if (gdk_rectangle_intersect (&pixrect, &ev->area, &intersection)) { + // cairo_set_source (cr, fgpattern->cobj()); + // cairo_rectangle (cr, intersection.x, intersection.y, intersection.width, intersection.height); + // cairo_fill (cr); + //} // draw peak bar @@ -684,10 +677,6 @@ FastMeter::horizontal_expose (GdkEventExpose* ev) last_peak_rect.width = 0; last_peak_rect.height = 0; } - - cairo_destroy (cr); - - return TRUE; } void diff --git a/libs/gtkmm2ext/gtkmm2ext/fastmeter.h b/libs/gtkmm2ext/gtkmm2ext/fastmeter.h index c3b8e093aa..78440eac34 100644 --- a/libs/gtkmm2ext/gtkmm2ext/fastmeter.h +++ b/libs/gtkmm2ext/gtkmm2ext/fastmeter.h @@ -24,14 +24,14 @@ #include #include #include -#include #include +#include "gtkmm2ext/cairo_widget.h" #include "gtkmm2ext/visibility.h" namespace Gtkmm2ext { -class LIBGTKMM2EXT_API FastMeter : public Gtk::DrawingArea { +class LIBGTKMM2EXT_API FastMeter : public CairoWidget { public: enum Orientation { Horizontal, @@ -67,7 +67,8 @@ class LIBGTKMM2EXT_API FastMeter : public Gtk::DrawingArea { bool get_highlight () { return highlight; } protected: - bool on_expose_event (GdkEventExpose*); + //bool on_expose_event (GdkEventExpose*); + void render (cairo_t* cr); void on_size_request (GtkRequisition*); void on_size_allocate (Gtk::Allocation&); private: @@ -96,12 +97,12 @@ private: float current_user_level; bool highlight; - bool vertical_expose (GdkEventExpose*); + void vertical_render (cairo_t* cr); void vertical_size_request (GtkRequisition*); void vertical_size_allocate (Gtk::Allocation&); void queue_vertical_redraw (const Glib::RefPtr&, float); - bool horizontal_expose (GdkEventExpose*); + void horizontal_render (cairo_t* cr); void horizontal_size_request (GtkRequisition*); void horizontal_size_allocate (Gtk::Allocation&); void queue_horizontal_redraw (const Glib::RefPtr&, float);