1 /*
2 * Copyright (C) 2020 Robin Gareus <robin@gareus.org>
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 along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 */
18
19 #include "recorder_group_tabs.h"
20 #include "recorder_ui.h"
21 #include "track_record_axis.h"
22 #include "ui_config.h"
23
24 #ifdef WAF_BUILD
25 #include "gtk2ardour-config.h"
26 #endif
27
28 using namespace ARDOUR;
29
RecorderGroupTabs(RecorderUI * parent)30 RecorderGroupTabs::RecorderGroupTabs (RecorderUI* parent)
31 : _recorder (parent)
32 {
33 }
34
35 double
primary_coordinate(double,double y) const36 RecorderGroupTabs::primary_coordinate (double, double y) const
37 {
38 return y;
39 }
40
41 double
extent() const42 RecorderGroupTabs::extent () const
43 {
44 return get_height ();
45 }
46
47 std::list<GroupTabs::Tab>
compute_tabs() const48 RecorderGroupTabs::compute_tabs () const
49 {
50 std::list<Tab> tabs;
51
52 Tab tab;
53 tab.from = 0;
54 tab.group = 0;
55 int32_t y = 0;
56
57 std::list<TrackRecordAxis*> recorders = _recorder->visible_recorders ();
58 for (std::list<TrackRecordAxis*>::const_iterator i = recorders.begin (); i != recorders.end (); ++i) {
59 if ((*i)->route ()->presentation_info ().hidden ()) { // marked_for_display ()
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)->get_height ();
79 }
80
81 if (tab.group) {
82 tab.to = y;
83 tabs.push_back (tab);
84 }
85
86 return tabs;
87 }
88
89 RouteList
routes_for_tab(Tab const * t) const90 RecorderGroupTabs::routes_for_tab (Tab const* t) const
91 {
92 RouteList routes;
93 int32_t y = 0;
94
95 std::list<TrackRecordAxis*> recorders = _recorder->visible_recorders ();
96 for (std::list<TrackRecordAxis*>::const_iterator i = recorders.begin (); i != recorders.end (); ++i) {
97 if (y >= t->to) {
98 /* tab finishes before this track starts */
99 break;
100 }
101
102 double const h = y + (*i)->get_height () / 2;
103 if (t->from < h && t->to > h) {
104 routes.push_back ((*i)->route ());
105 }
106 y += (*i)->get_height ();
107 }
108
109 return routes;
110 }
111
112 void
draw_tab(cairo_t * cr,Tab const & tab)113 RecorderGroupTabs::draw_tab (cairo_t* cr, Tab const& tab)
114 {
115 double const arc_radius = get_width ();
116 double r, g, b, a;
117
118 if (tab.group && tab.group->is_active ()) {
119 Gtkmm2ext::color_to_rgba (tab.color, r, g, b, a);
120 } else {
121 Gtkmm2ext::color_to_rgba (UIConfiguration::instance ().color ("inactive group tab"), r, g, b, a);
122 }
123
124 a = 1.0;
125
126 cairo_set_source_rgba (cr, r, g, b, a);
127 cairo_move_to (cr, 0, tab.from + arc_radius);
128 cairo_arc (cr, get_width (), tab.from + arc_radius, arc_radius, M_PI, 3 * M_PI / 2);
129 cairo_line_to (cr, get_width (), tab.to);
130 cairo_arc (cr, get_width (), tab.to - arc_radius, arc_radius, M_PI / 2, M_PI);
131 cairo_line_to (cr, 0, tab.from + arc_radius);
132 cairo_fill (cr);
133
134 if (tab.group && (tab.to - tab.from) > arc_radius) {
135 int text_width, text_height;
136
137 Glib::RefPtr<Pango::Layout> layout;
138 layout = Pango::Layout::create (get_pango_context ());
139 layout->set_ellipsize (Pango::ELLIPSIZE_MIDDLE);
140
141 layout->set_text (tab.group->name ());
142 layout->set_width ((tab.to - tab.from - arc_radius) * PANGO_SCALE);
143 layout->get_pixel_size (text_width, text_height);
144
145 cairo_move_to (cr, (get_width () - text_height) * .5, (text_width + tab.to + tab.from) * .5);
146
147 Gtkmm2ext::Color c = Gtkmm2ext::contrasting_text_color (Gtkmm2ext::rgba_to_color (r, g, b, a));
148 Gtkmm2ext::color_to_rgba (c, r, g, b, a);
149 cairo_set_source_rgb (cr, r, g, b);
150
151 cairo_save (cr);
152 cairo_rotate (cr, M_PI * -.5);
153 pango_cairo_show_layout (cr, layout->gobj ());
154 cairo_restore (cr);
155 }
156 }
157
158 RouteList
selected_routes() const159 RecorderGroupTabs::selected_routes () const
160 {
161 RouteList rl;
162 return rl;
163 }
164