ardour
editor_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 "gtkmm2ext/utils.h"
21 
22 #include "ardour/route_group.h"
23 
24 #include "canvas/colors.h"
25 
26 #include "ardour_ui.h"
27 #include "editor.h"
28 #include "editor_group_tabs.h"
29 #include "editor_route_groups.h"
30 #include "editor_routes.h"
31 #include "rgb_macros.h"
32 #include "route_time_axis.h"
33 #include "utils.h"
34 
35 #include "i18n.h"
36 
37 using namespace std;
38 using namespace ARDOUR;
39 using namespace ARDOUR_UI_UTILS;
40 
42  : EditorComponent (e)
43 {
44 
45 }
46 
47 list<GroupTabs::Tab>
49 {
50  list<Tab> tabs;
51 
52  Tab tab;
53  tab.from = 0;
54  tab.group = 0;
55 
56  int32_t y = 0;
57  for (TrackViewList::iterator i = _editor->track_views.begin(); i != _editor->track_views.end(); ++i) {
58 
59  if ((*i)->marked_for_display() == false) {
60  continue;
61  }
62 
63  RouteGroup* g = (*i)->route_group ();
64 
65  if (g != tab.group) {
66  if (tab.group) {
67  tab.to = y;
68  tabs.push_back (tab);
69  }
70 
71  tab.from = y;
72  tab.group = g;
73  if (g) {
74  tab.color = group_color (g);
75  }
76  }
77 
78  y += (*i)->effective_height ();
79  }
80 
81  if (tab.group) {
82  tab.to = y;
83  tabs.push_back (tab);
84  }
85 
86  return tabs;
87 }
88 
89 void
90 EditorGroupTabs::draw_tab (cairo_t* cr, Tab const & tab) const
91 {
92  double const arc_radius = get_width();
93  double r, g, b, a;
94 
95  if (tab.group && tab.group->is_active()) {
96  ArdourCanvas::color_to_rgba (tab.color, r, g, b, a);
97  } else {
98  ArdourCanvas::color_to_rgba (ARDOUR_UI::config()->color ("inactive group tab"), r, g, b, a);
99  }
100 
101  a = 1.0;
102 
103  cairo_set_source_rgba (cr, r, g, b, a);
104  cairo_move_to (cr, 0, tab.from + arc_radius);
105  cairo_arc (cr, get_width(), tab.from + arc_radius, arc_radius, M_PI, 3 * M_PI / 2);
106  cairo_line_to (cr, get_width(), tab.to);
107  cairo_arc (cr, get_width(), tab.to - arc_radius, arc_radius, M_PI / 2, M_PI);
108  cairo_line_to (cr, 0, tab.from + arc_radius);
109  cairo_fill (cr);
110 
111  if (tab.group) {
112  pair<string, double> const f = Gtkmm2ext::fit_to_pixels (cr, tab.group->name(), tab.to - tab.from - arc_radius * 2);
113 
114  cairo_text_extents_t ext;
115  cairo_text_extents (cr, tab.group->name().c_str(), &ext);
116 
117  ArdourCanvas::Color c = ArdourCanvas::contrasting_text_color (ArdourCanvas::rgba_to_color (r, g, b, a));
118  ArdourCanvas::color_to_rgba (c, r, g, b, a);
119 
120  cairo_set_source_rgb (cr, r, g, b);
121  cairo_move_to (cr, get_width() - ext.height / 2, tab.from + (f.second + tab.to - tab.from) / 2);
122  cairo_save (cr);
123  cairo_rotate (cr, - M_PI / 2);
124  cairo_show_text (cr, f.first.c_str());
125  cairo_restore (cr);
126  }
127 }
128 
129 double
130 EditorGroupTabs::primary_coordinate (double, double y) const
131 {
132  return y;
133 }
134 
135 RouteList
137 {
138  RouteList routes;
139  int32_t y = 0;
140 
141  for (TrackViewList::iterator i = _editor->track_views.begin(); i != _editor->track_views.end(); ++i) {
142 
143  if ((*i)->marked_for_display() == false) {
144  continue;
145  }
146 
147  RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*> (*i);
148  if (rtv) {
149 
150  if (y >= t->to) {
151  /* tab finishes before this track starts */
152  break;
153  }
154 
155  double const h = y + (*i)->effective_height() / 2;
156 
157  if (t->from < h && t->to > h) {
158  routes.push_back (rtv->route ());
159  }
160  }
161 
162  y += (*i)->effective_height ();
163  }
164 
165  return routes;
166 }
167 
168 
169 void
171 {
172  using namespace Gtk::Menu_Helpers;
173 
174  if (g) {
175  MenuList& items = m->items ();
176  items.push_back (MenuElem (_("Fit to Window"), sigc::bind (sigc::mem_fun (*_editor, &Editor::fit_route_group), g)));
177  }
178 }
179 
180 RouteList
182 {
183  RouteList rl;
184 
185  for (TrackSelection::iterator i = _editor->get_selection().tracks.begin(); i != _editor->get_selection().tracks.end(); ++i) {
186  RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*> (*i);
187  if (rtv) {
188  rl.push_back (rtv->route());
189  }
190  }
191 
192  return rl;
193 }
194 
195 void
197 {
199 }
void sync_order_keys_from_treeview()
uint32_t effective_height() const
EditorRoutes * _routes
Definition: editor.h:1862
ARDOUR::RouteList selected_routes() const
std::list< Tab > compute_tabs() const
tuple f
Definition: signals.py:35
Definition: Beats.hpp:239
void fit_route_group(ARDOUR::RouteGroup *)
Definition: editor.cc:5433
void add_menu_items(Gtk::Menu *, ARDOUR::RouteGroup *)
#define _(Text)
Definition: i18n.h:11
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
EditorGroupTabs(Editor *)
void draw_tab(cairo_t *, Tab const &) const
static uint32_t group_color(ARDOUR::RouteGroup *)
Definition: group_tabs.cc:616
Definition: editor.h:134
ARDOUR::RouteGroup * group
route group
Definition: group_tabs.h:65
std::string name() const
TrackSelection tracks
Definition: selection.h:81
static UIConfiguration * config()
Definition: ardour_ui.h:188
Selection & get_selection() const
Definition: editor.h:244
TrackViewList track_views
Definition: editor.h:1135
double primary_coordinate(double, double) const
std::list< boost::shared_ptr< Route > > RouteList
Definition: types.h:532
ARDOUR::RouteList routes_for_tab(Tab const *) const
boost::shared_ptr< ARDOUR::Route > route() const
Definition: route_ui.h:76
LIBARDOUR_API PBD::PropertyDescriptor< bool > color
Definition: route_group.cc:50