ardour
mixer_group_tabs.cc
Go to the documentation of this file.
1 /*
2  Copyright (C) 2009 Paul Davis
3 
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or
7  (at your option) any later version.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program; if not, write to the Free Software
16  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 
18 */
19 
20 #include <boost/foreach.hpp>
21 
22 #include "gtkmm2ext/utils.h"
23 
24 #include "ardour/route_group.h"
25 
26 #include "canvas/colors.h"
27 
28 #include "ardour_ui.h"
29 #include "mixer_group_tabs.h"
30 #include "mixer_strip.h"
31 #include "mixer_ui.h"
32 #include "rgb_macros.h"
33 #include "route_group_dialog.h"
34 #include "utils.h"
35 
36 #include "i18n.h"
37 
38 using namespace std;
39 using namespace Gtk;
40 using namespace ARDOUR;
41 using namespace ARDOUR_UI_UTILS;
42 using namespace PBD;
43 
45  : _mixer (m)
46 {
47 
48 }
49 
50 
51 list<GroupTabs::Tab>
53 {
54  list<Tab> tabs;
55 
56  Tab tab;
57  tab.from = 0;
58  tab.group = 0;
59 
60  int32_t x = 0;
61  TreeModel::Children rows = _mixer->track_model->children ();
62  for (TreeModel::Children::iterator i = rows.begin(); i != rows.end(); ++i) {
63 
65 
66  if (s->route()->is_master() || s->route()->is_monitor() || !s->marked_for_display()) {
67  continue;
68  }
69 
70  RouteGroup* g = s->route_group ();
71 
72  if (g != tab.group) {
73  if (tab.group) {
74  tab.to = x;
75  tabs.push_back (tab);
76  }
77 
78  tab.from = x;
79  tab.group = g;
80 
81  if (g) {
82  tab.color = group_color (g);
83  }
84  }
85 
86  x += s->get_width ();
87  }
88 
89  if (tab.group) {
90  tab.to = x;
91  tabs.push_back (tab);
92  }
93 
94  return tabs;
95 }
96 
97 void
98 MixerGroupTabs::draw_tab (cairo_t* cr, Tab const & tab) const
99 {
100  double const arc_radius = get_height();
101  double r, g, b, a;
102 
103  if (tab.group && tab.group->is_active()) {
104  ArdourCanvas::color_to_rgba (tab.color, r, g, b, a);
105  } else {
106  ArdourCanvas::color_to_rgba (ARDOUR_UI::config()->color ("inactive group tab"), r, g, b, a);
107  }
108 
109  a = 1.0;
110 
111  cairo_set_source_rgba (cr, r, g, b, a);
112  cairo_arc (cr, tab.from + arc_radius, get_height(), arc_radius, M_PI, 3 * M_PI / 2);
113  cairo_line_to (cr, tab.to - arc_radius, 0);
114  cairo_arc (cr, tab.to - arc_radius, get_height(), arc_radius, 3 * M_PI / 2, 2 * M_PI);
115  cairo_line_to (cr, tab.from, get_height());
116  cairo_fill (cr);
117 
118  if (tab.group) {
119  pair<string, double> const f = Gtkmm2ext::fit_to_pixels (cr, tab.group->name(), tab.to - tab.from - arc_radius * 2);
120 
121  cairo_text_extents_t ext;
122  cairo_text_extents (cr, tab.group->name().c_str(), &ext);
123 
124  ArdourCanvas::Color c = ArdourCanvas::contrasting_text_color (ArdourCanvas::rgba_to_color (r, g, b, a));
125  ArdourCanvas::color_to_rgba (c, r, g, b, a);
126 
127  cairo_set_source_rgb (cr, r, g, b);
128  cairo_move_to (cr, tab.from + (tab.to - tab.from - f.second) / 2, get_height() - ext.height / 2);
129  cairo_save (cr);
130  cairo_show_text (cr, f.first.c_str());
131  cairo_restore (cr);
132  }
133 }
134 
135 double
136 MixerGroupTabs::primary_coordinate (double x, double) const
137 {
138  return x;
139 }
140 
141 RouteList
143 {
144  RouteList routes;
145  int32_t x = 0;
146 
147  TreeModel::Children rows = _mixer->track_model->children ();
148  for (TreeModel::Children::iterator i = rows.begin(); i != rows.end(); ++i) {
149 
150  MixerStrip* s = (*i)[_mixer->track_columns.strip];
151 
152  if (s->route()->is_master() || s->route()->is_monitor() || !s->marked_for_display()) {
153  continue;
154  }
155 
156  if (x >= t->to) {
157  /* tab finishes before this track starts */
158  break;
159  }
160 
161  double const h = x + s->get_width() / 2;
162 
163  if (t->from < h && t->to > h) {
164  routes.push_back (s->route ());
165  }
166 
167  x += s->get_width ();
168  }
169 
170  return routes;
171 }
172 
173 RouteList
175 {
176  RouteList rl;
177  BOOST_FOREACH (RouteUI* r, _mixer->selection().routes) {
179  if (rp) {
180  rl.push_back (rp);
181  }
182  }
183  return rl;
184 }
185 
186 void
188 {
190 }
TrackDisplayModelColumns track_columns
Definition: mixer_ui.h:244
std::list< Tab > compute_tabs() const
Glib::RefPtr< Gtk::ListStore > track_model
Definition: mixer_ui.h:250
RouteProcessorSelection & selection()
Definition: mixer_actor.h:38
Definition: ardour_ui.h:130
tuple f
Definition: signals.py:35
Definition: Beats.hpp:239
Gtk::TreeModelColumn< MixerStrip * > strip
Definition: mixer_ui.h:230
uint32_t contrasting_text_color(uint32_t c)
LIBGTKMM2EXT_API std::string fit_to_pixels(const std::string &, int pixel_width, Pango::FontDescription &font, int &actual_width, bool with_ellipses=false)
uint32_t color
color
Definition: group_tabs.h:64
Definition: amp.h:29
bool is_active() const
Definition: route_group.h:66
ARDOUR::RouteList routes_for_tab(Tab const *) const
ARDOUR::RouteGroup * route_group() const
Definition: route_ui.cc:2171
void draw_tab(cairo_t *, Tab const &) const
static uint32_t group_color(ARDOUR::RouteGroup *)
Definition: group_tabs.cc:616
bool is_master() const
Definition: route.h:111
ARDOUR::RouteGroup * group
route group
Definition: group_tabs.h:65
std::string name() const
static UIConfiguration * config()
Definition: ardour_ui.h:188
Definition: debug.h:30
ARDOUR::RouteList selected_routes() const
MixerGroupTabs(Mixer_UI *)
double primary_coordinate(double, double) const
bool marked_for_display() const
Definition: axis_view.cc:80
std::list< boost::shared_ptr< Route > > RouteList
Definition: types.h:532
boost::shared_ptr< ARDOUR::Route > route() const
Definition: route_ui.h:76
void sync_order_keys_from_treeview()
Definition: mixer_ui.cc:512
Mixer_UI * _mixer
bool is_monitor() const
Definition: route.h:112
LIBARDOUR_API PBD::PropertyDescriptor< bool > color
Definition: route_group.cc:50