bb292b418be354fe71392a45918772cbbdfee26d
[ardour.git] / libs / surfaces / push2 / track_mix.cc
1 /*
2   Copyright (C) 2016 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 #include <pangomm/layout.h>
20
21 #include "pbd/compose.h"
22 #include "pbd/convert.h"
23 #include "pbd/debug.h"
24 #include "pbd/failed_constructor.h"
25 #include "pbd/file_utils.h"
26 #include "pbd/search_path.h"
27 #include "pbd/enumwriter.h"
28
29 #include "midi++/parser.h"
30 #include "timecode/time.h"
31 #include "timecode/bbt_time.h"
32
33 #include "ardour/async_midi_port.h"
34 #include "ardour/audioengine.h"
35 #include "ardour/debug.h"
36 #include "ardour/filesystem_paths.h"
37 #include "ardour/midiport_manager.h"
38 #include "ardour/midi_track.h"
39 #include "ardour/midi_port.h"
40 #include "ardour/session.h"
41 #include "ardour/tempo.h"
42
43 #include "menu.h"
44 #include "push2.h"
45 #include "track_mix.h"
46
47 #include "i18n.h"
48
49 using namespace ARDOUR;
50 using namespace std;
51 using namespace PBD;
52 using namespace Glib;
53 using namespace ArdourSurface;
54
55 TrackMixLayout::TrackMixLayout (Push2& p, Session& s, Cairo::RefPtr<Cairo::Context> context)
56         : Push2Layout (p, s)
57         , _dirty (false)
58 {
59         name_layout = Pango::Layout::create (context);
60
61         Pango::FontDescription fd ("Sans Bold 24");
62         name_layout->set_font_description (fd);
63
64         Pango::FontDescription fd2 ("Sans 10");
65         for (int n = 0; n < 8; ++n) {
66                 upper_layout[n] = Pango::Layout::create (context);
67                 upper_layout[n]->set_font_description (fd2);
68                 upper_layout[n]->set_text ("solo");
69                 lower_layout[n] = Pango::Layout::create (context);
70                 lower_layout[n]->set_font_description (fd2);
71                 lower_layout[n]->set_text ("mute");
72         }
73
74 }
75
76 TrackMixLayout::~TrackMixLayout ()
77 {
78 }
79
80 bool
81 TrackMixLayout::redraw (Cairo::RefPtr<Cairo::Context> context) const
82 {
83         if (!_dirty) {
84                 return false;
85         }
86
87         context->set_source_rgb (0.764, 0.882, 0.882);
88         context->rectangle (0, 0, 960, 160);
89         context->fill ();
90
91         context->set_source_rgb (0.23, 0.0, 0.349);
92         context->move_to (10, 2);
93         name_layout->update_from_cairo_context (context);
94         name_layout->show_in_cairo_context (context);
95
96         return true;
97 }
98
99 void
100 TrackMixLayout::button_upper (uint32_t n)
101 {
102 }
103
104 void
105 TrackMixLayout::button_lower (uint32_t n)
106 {
107 }
108
109 void
110 TrackMixLayout::strip_vpot (int n, int delta)
111 {
112 }
113
114 void
115 TrackMixLayout::strip_vpot_touch (int, bool)
116 {
117 }
118
119 void
120 TrackMixLayout::set_stripable (boost::shared_ptr<Stripable> s)
121 {
122         stripable = s;
123
124         if (stripable) {
125                 stripable->DropReferences.connect (stripable_connections, MISSING_INVALIDATOR, boost::bind (&TrackMixLayout::drop_stripable, this), &p2);
126
127                 stripable->PropertyChanged.connect (stripable_connections, MISSING_INVALIDATOR, boost::bind (&TrackMixLayout::stripable_property_change, this, _1), &p2);
128                 stripable->presentation_info().PropertyChanged.connect (stripable_connections, MISSING_INVALIDATOR, boost::bind (&TrackMixLayout::stripable_property_change, this, _1), &p2);
129
130                 name_changed ();
131                 color_changed ();
132         }
133
134         _dirty = true;
135 }
136
137 void
138 TrackMixLayout::drop_stripable ()
139 {
140         stripable_connections.drop_connections ();
141         stripable.reset ();
142         _dirty = true;
143 }
144
145 void
146 TrackMixLayout::name_changed ()
147 {
148         name_layout->set_text (stripable->name());
149         _dirty = true;
150 }
151
152 void
153 TrackMixLayout::color_changed ()
154 {
155         uint32_t rgb = stripable->presentation_info().color();
156         uint8_t index = p2.get_color_index (rgb);
157
158         Push2::Button* b = p2.button_by_id (Push2::Upper1);
159         b->set_color (index);
160         b->set_state (Push2::LED::OneShot24th);
161         p2.write (b->state_msg ());
162 }
163
164 void
165 TrackMixLayout::stripable_property_change (PropertyChange const& what_changed)
166 {
167         if (what_changed.contains (Properties::color)) {
168                 color_changed ();
169         }
170         if (what_changed.contains (Properties::name)) {
171                 name_changed ();
172         }
173 }