Update GPL boilerplate and (C)
[ardour.git] / gtk2_ardour / mixer_ui.cc
index 8909b116504264848310607522a16c771e28bf08..db904ddf97775b8355b7241f0159eca366d00be2 100644 (file)
@@ -1,21 +1,29 @@
 /*
-    Copyright (C) 2000-2004 Paul Davis
-
-    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.
-
-*/
+ * Copyright (C) 2005-2006 Taybin Rutkin <taybin@taybin.com>
+ * Copyright (C) 2005-2018 Paul Davis <paul@linuxaudiosystems.com>
+ * Copyright (C) 2006-2007 Doug McLain <doug@nostar.net>
+ * Copyright (C) 2007-2012 Carl Hetherington <carl@carlh.net>
+ * Copyright (C) 2007-2012 David Robillard <d@drobilla.net>
+ * Copyright (C) 2007-2016 Tim Mayberry <mojofunk@gmail.com>
+ * Copyright (C) 2013-2015 Nick Mainsbridge <mainsbridge@gmail.com>
+ * Copyright (C) 2013-2019 Robin Gareus <robin@gareus.org>
+ * Copyright (C) 2014-2018 Ben Loftis <ben@harrisonconsoles.com>
+ * Copyright (C) 2016-2018 Len Ovens <len@ovenwerks.net>
+ *
+ * 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.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
 
 #ifdef WAF_BUILD
 #include "gtk2ardour-config.h"
@@ -30,6 +38,7 @@
 #include <glibmm/threads.h>
 
 #include <gtkmm/accelmap.h>
+#include <gtkmm/offscreenwindow.h>
 #include <gtkmm/stock.h>
 
 #include "pbd/convert.h"
@@ -160,15 +169,14 @@ Mixer_UI::Mixer_UI ()
 #endif
 
        _group_tabs = new MixerGroupTabs (this);
-       VBox* b = manage (new VBox);
-       b->set_spacing (0);
-       b->set_border_width (0);
-       b->pack_start (*_group_tabs, PACK_SHRINK);
-       b->pack_start (strip_packer);
-       b->show_all ();
-       b->signal_scroll_event().connect (sigc::mem_fun (*this, &Mixer_UI::on_scroll_event), false);
-
-       scroller.add (*b);
+       strip_group_box.set_spacing (0);
+       strip_group_box.set_border_width (0);
+       strip_group_box.pack_start (*_group_tabs, PACK_SHRINK);
+       strip_group_box.pack_start (strip_packer);
+       strip_group_box.show_all ();
+       strip_group_box.signal_scroll_event().connect (sigc::mem_fun (*this, &Mixer_UI::on_scroll_event), false);
+
+       scroller.add (strip_group_box);
        scroller.set_policy (Gtk::POLICY_ALWAYS, Gtk::POLICY_AUTOMATIC);
 
        setup_track_display ();
@@ -1641,15 +1649,56 @@ Mixer_UI::track_display_button_press (GdkEventButton* ev)
        return false;
 }
 
+void
+Mixer_UI::move_vca_into_view (boost::shared_ptr<ARDOUR::Stripable> s)
+{
+       if (!vca_scroller.get_hscrollbar()) {
+               return;
+       }
+
+       bool found = false;
+       int x0 = 0;
+       Gtk::Allocation alloc;
+
+       TreeModel::Children rows = track_model->children();
+       for (TreeModel::Children::const_iterator i = rows.begin(); i != rows.end(); ++i) {
+               AxisView* av = (*i)[stripable_columns.strip];
+               VCAMasterStrip* vms = dynamic_cast<VCAMasterStrip*> (av);
+               if (vms && vms->stripable () == s) {
+                       int y;
+                       found = true;
+                       vms->translate_coordinates (vca_hpacker, 0, 0, x0, y);
+                       alloc = vms->get_allocation ();
+                       break;
+               }
+       }
+
+       if (!found) {
+               return;
+       }
+
+       Adjustment* adj = vca_scroller.get_hscrollbar()->get_adjustment();
+
+       if (x0 < adj->get_value()) {
+               adj->set_value (max (adj->get_lower(), min (adj->get_upper(), (double) x0)));
+       } else if (x0 + alloc.get_width() >= adj->get_value() + adj->get_page_size()) {
+               int x1 = x0 + alloc.get_width() - adj->get_page_size();
+               adj->set_value (max (adj->get_lower(), min (adj->get_upper(), (double) x1)));
+       }
+}
+
 void
 Mixer_UI::move_stripable_into_view (boost::shared_ptr<ARDOUR::Stripable> s)
 {
        if (!scroller.get_hscrollbar()) {
                return;
        }
-       if (s->presentation_info().special () || s->presentation_info().flag_match (PresentationInfo::VCA)) {
+       if (s->presentation_info().special ()) {
                return;
        }
+       if (s->presentation_info().flag_match (PresentationInfo::VCA)) {
+               move_vca_into_view (s);
+       }
 #ifdef MIXBUS
        if (s->mixbus ()) {
                return;
@@ -3461,3 +3510,83 @@ Mixer_UI::vca_unassign (boost::shared_ptr<VCA> vca)
                }
        }
 }
+
+bool
+Mixer_UI::screenshot (std::string const& filename)
+{
+       if (!_session) {
+               return false;
+       }
+
+       int height = strip_packer.get_height();
+       bool with_vca = vca_vpacker.is_visible ();
+       MixerStrip* master = strip_by_route (_session->master_out ());
+
+       Gtk::OffscreenWindow osw;
+       Gtk::HBox b;
+       osw.add (b);
+       b.show ();
+
+       /* unpack widgets, add to OffscreenWindow */
+
+       strip_group_box.remove (strip_packer);
+       b.pack_start (strip_packer, false, false);
+       /* hide extra elements inside strip_packer */
+       add_button.hide ();
+       scroller_base.hide ();
+#ifdef MIXBUS
+       mb_shadow.hide();
+#endif
+
+       if (with_vca) {
+               /* work around Gtk::ScrolledWindow */
+               Gtk::Viewport* viewport = (Gtk::Viewport*) vca_scroller.get_child();
+               viewport->remove (); // << vca_hpacker
+               b.pack_start (vca_hpacker, false, false);
+               /* hide some growing widgets */
+               add_vca_button.hide ();
+               vca_scroller_base.hide();
+       }
+
+       if (master) {
+               out_packer.remove (*master);
+               b.pack_start (*master, false, false);
+               master->hide_master_spacer (true);
+       }
+
+       /* prepare the OffscreenWindow for rendering */
+       osw.set_size_request (-1, height);
+       osw.show ();
+       osw.queue_resize ();
+       osw.queue_draw ();
+       osw.get_window()->process_updates (true);
+
+       /* create screenshot */
+       Glib::RefPtr<Gdk::Pixbuf> pb = osw.get_pixbuf ();
+       pb->save (filename, "png");
+
+       /* unpack elements before destorying the Box & OffscreenWindow */
+       list<Gtk::Widget*> children = b.get_children();
+       for (list<Gtk::Widget*>::iterator child = children.begin(); child != children.end(); ++child) {
+               b.remove (**child);
+       }
+       osw.remove ();
+
+       /* now re-pack the widgets into the main mixer window */
+       add_button.show ();
+       scroller_base.show ();
+#ifdef MIXBUS
+       mb_shadow.show();
+#endif
+       strip_group_box.pack_start (strip_packer);
+       if (with_vca) {
+               add_vca_button.show ();
+               vca_scroller_base.show();
+               vca_scroller.add (vca_hpacker);
+       }
+       if (master) {
+               master->hide_master_spacer (false);
+               out_packer.pack_start (*master, false, false);
+       }
+       return true;
+}