Merge edit and mix groups to just being route groups. Add properties to route groups...
[ardour.git] / gtk2_ardour / editor_group_tabs.cc
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 "ardour/route_group.h"
21 #include "editor_group_tabs.h"
22 #include "editor.h"
23 #include "time_axis_view.h"
24 #include "utils.h"
25
26 using namespace std;
27 using namespace ARDOUR;
28
29 EditorGroupTabs::EditorGroupTabs (Editor* e)
30         : _editor (e)
31 {
32         
33 }
34
35 void
36 EditorGroupTabs::render (cairo_t* cr)
37 {
38         /* background */
39         
40         cairo_set_source_rgb (cr, 0, 0, 0);
41         cairo_rectangle (cr, 0, 0, _width, _height);
42         cairo_fill (cr);
43
44         int32_t curr_start = 0;
45         RouteGroup* curr_group = 0;
46         Gdk::Color curr_colour;
47
48         int32_t y = 0;
49         for (Editor::TrackViewList::iterator i = _editor->track_views.begin(); i != _editor->track_views.end(); ++i) {
50
51                 if ((*i)->marked_for_display() == false) {
52                         continue;
53                 }
54                 
55                 RouteGroup* g = (*i)->route_group ();
56
57                 if (g != curr_group) {
58                         if (curr_group) {
59                                 draw_group (cr, curr_start, y, curr_group, curr_colour);
60                         }
61
62                         curr_start = y;
63                         curr_group = g;
64                         curr_colour = (*i)->color ();
65                 }
66
67                 y += (*i)->effective_height ();
68         }
69
70         if (curr_group) {
71                 draw_group (cr, curr_start, y, curr_group, curr_colour);
72         }
73 }
74
75 void
76 EditorGroupTabs::draw_group (cairo_t* cr, int32_t y1, int32_t y2, RouteGroup* g, Gdk::Color const & colour)
77 {
78         double const arc_radius = _width;
79
80         if (g->is_active()) {
81                 cairo_set_source_rgba (cr, colour.get_red_p (), colour.get_green_p (), colour.get_blue_p (), 1);
82         } else {
83                 cairo_set_source_rgba (cr, 1, 1, 1, 0.2);
84         }
85         
86         cairo_move_to (cr, 0, y1 + arc_radius);
87         cairo_arc (cr, _width, y1 + arc_radius, arc_radius, M_PI, 3 * M_PI / 2);
88         cairo_line_to (cr, _width, y2);
89         cairo_arc (cr, _width, y2 - arc_radius, arc_radius, M_PI / 2, M_PI);
90         cairo_line_to (cr, 0, y1 + arc_radius);
91         cairo_fill (cr);
92
93         pair<string, double> const f = fit_to_pixels (cr, g->name(), y2 - y1 - arc_radius * 2);
94
95         cairo_text_extents_t ext;
96         cairo_text_extents (cr, g->name().c_str(), &ext);
97
98         cairo_set_source_rgb (cr, 1, 1, 1);
99         cairo_move_to (cr, _width - ext.height / 2, y1 + (f.second + y2 - y1) / 2);
100         cairo_save (cr);
101         cairo_rotate (cr, - M_PI / 2);
102         cairo_show_text (cr, f.first.c_str());
103         cairo_restore (cr);
104 }
105
106 RouteGroup*
107 EditorGroupTabs::click_to_route_group (GdkEventButton* ev)
108 {
109         int32_t y = 0;
110         Editor::TrackViewList::iterator i = _editor->track_views.begin();
111         while (y < ev->y && i != _editor->track_views.end()) {
112
113                 if ((*i)->marked_for_display()) {
114                         y += (*i)->effective_height ();
115                 }
116                 
117                 if (y < ev->y) {
118                         ++i;
119                 }
120         }
121         
122         if (i == _editor->track_views.end()) {
123                 return 0;
124         }
125         
126         return (*i)->route_group ();
127 }