use new method in MidiPatchManager to use MIDNAM data when setting a MidiTimeAxisView
[ardour.git] / gtk2_ardour / editor_group_tabs.cc
1 /*
2  * Copyright (C) 2009-2011 Carl Hetherington <carl@carlh.net>
3  * Copyright (C) 2009-2011 David Robillard <d@drobilla.net>
4  * Copyright (C) 2011-2016 Paul Davis <paul@linuxaudiosystems.com>
5  * Copyright (C) 2014-2017 Robin Gareus <robin@gareus.org>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along
18  * with this program; if not, write to the Free Software Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20  */
21
22 #include "gtkmm2ext/utils.h"
23
24 #include "ardour/route_group.h"
25
26 #include "gtkmm2ext/colors.h"
27
28 #include "editor.h"
29 #include "editor_group_tabs.h"
30 #include "editor_route_groups.h"
31 #include "editor_routes.h"
32 #include "rgb_macros.h"
33 #include "route_time_axis.h"
34 #include "ui_config.h"
35 #include "utils.h"
36
37 #include "pbd/i18n.h"
38
39 using namespace std;
40 using namespace ARDOUR;
41 using namespace ARDOUR_UI_UTILS;
42
43 EditorGroupTabs::EditorGroupTabs (Editor* e)
44         : EditorComponent (e)
45 {
46
47 }
48
49 list<GroupTabs::Tab>
50 EditorGroupTabs::compute_tabs () const
51 {
52         list<Tab> tabs;
53
54         Tab tab;
55         tab.from = 0;
56         tab.group = 0;
57
58         int32_t y = 0;
59         for (TrackViewList::iterator i = _editor->track_views.begin(); i != _editor->track_views.end(); ++i) {
60
61                 if ((*i)->marked_for_display() == false) {
62                         continue;
63                 }
64
65                 RouteGroup* g = (*i)->route_group ();
66
67                 if (g != tab.group) {
68                         if (tab.group) {
69                                 tab.to = y;
70                                 tabs.push_back (tab);
71                         }
72
73                         tab.from = y;
74                         tab.group = g;
75                         if (g) {
76                                 tab.color = group_color (g);
77                         }
78                 }
79
80                 y += (*i)->effective_height ();
81         }
82
83         if (tab.group) {
84                 tab.to = y;
85                 tabs.push_back (tab);
86         }
87
88         return tabs;
89 }
90
91 void
92 EditorGroupTabs::draw_tab (cairo_t* cr, Tab const & tab)
93 {
94         double const arc_radius = get_width();
95         double r, g, b, a;
96
97         if (tab.group && tab.group->is_active()) {
98                 Gtkmm2ext::color_to_rgba (tab.color, r, g, b, a);
99         } else {
100                 Gtkmm2ext::color_to_rgba (UIConfiguration::instance().color ("inactive group tab"), r, g, b, a);
101         }
102
103         a = 1.0;
104
105         cairo_set_source_rgba (cr, r, g, b, a);
106         cairo_move_to (cr, 0, tab.from + arc_radius);
107         cairo_arc (cr, get_width(), tab.from + arc_radius, arc_radius, M_PI, 3 * M_PI / 2);
108         cairo_line_to (cr, get_width(), tab.to);
109         cairo_arc (cr, get_width(), tab.to - arc_radius, arc_radius, M_PI / 2, M_PI);
110         cairo_line_to (cr, 0, tab.from + arc_radius);
111         cairo_fill (cr);
112
113         if (tab.group && (tab.to - tab.from) > arc_radius) {
114                 int text_width, text_height;
115
116                 Glib::RefPtr<Pango::Layout> layout;
117                 layout = Pango::Layout::create (get_pango_context ());
118                 layout->set_ellipsize (Pango::ELLIPSIZE_MIDDLE);
119
120                 layout->set_text (tab.group->name ());
121                 layout->set_width ((tab.to - tab.from - arc_radius) * PANGO_SCALE);
122                 layout->get_pixel_size (text_width, text_height);
123
124                 cairo_move_to (cr, (get_width() - text_height) * .5, (text_width + tab.to + tab.from) * .5);
125
126                 Gtkmm2ext::Color c = Gtkmm2ext::contrasting_text_color (Gtkmm2ext::rgba_to_color (r, g, b, a));
127                 Gtkmm2ext::color_to_rgba (c, r, g, b, a);
128                 cairo_set_source_rgb (cr, r, g, b);
129
130                 cairo_save (cr);
131                 cairo_rotate (cr, M_PI * -.5);
132                 pango_cairo_show_layout (cr, layout->gobj ());
133                 cairo_restore (cr);
134         }
135 }
136
137 double
138 EditorGroupTabs::primary_coordinate (double, double y) const
139 {
140         return y;
141 }
142
143 RouteList
144 EditorGroupTabs::routes_for_tab (Tab const * t) const
145 {
146         RouteList routes;
147         int32_t y = 0;
148
149         for (TrackViewList::iterator i = _editor->track_views.begin(); i != _editor->track_views.end(); ++i) {
150
151                 if ((*i)->marked_for_display() == false) {
152                         continue;
153                 }
154
155                 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*> (*i);
156                 if (rtv) {
157
158                         if (y >= t->to) {
159                                 /* tab finishes before this track starts */
160                                 break;
161                         }
162
163                         double const h = y + (*i)->effective_height() / 2;
164
165                         if (t->from < h && t->to > h) {
166                                 routes.push_back (rtv->route ());
167                         }
168                 }
169
170                 y += (*i)->effective_height ();
171         }
172
173         return routes;
174 }
175
176
177 void
178 EditorGroupTabs::add_menu_items (Gtk::Menu* m, RouteGroup* g)
179 {
180         using namespace Gtk::Menu_Helpers;
181
182         if (g) {
183                 MenuList& items = m->items ();
184                 items.push_back (MenuElem (_("Fit to Window"), sigc::bind (sigc::mem_fun (*_editor, &Editor::fit_route_group), g)));
185         }
186 }
187
188 RouteList
189 EditorGroupTabs::selected_routes () const
190 {
191         RouteList rl;
192
193         for (TrackSelection::iterator i = _editor->get_selection().tracks.begin(); i != _editor->get_selection().tracks.end(); ++i) {
194                 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*> (*i);
195                 if (rtv) {
196                         rl.push_back (rtv->route());
197                 }
198         }
199
200         return rl;
201 }
202