a8aa6d015005eaa37d0d32e298dd8a577a33fbe1
[ardour.git] / libs / surfaces / push2 / buttons.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 "ardour/mute_control.h"
20 #include "ardour/session.h"
21 #include "ardour/solo_control.h"
22
23 #include "push2.h"
24
25 using namespace ArdourSurface;
26 using namespace ARDOUR;
27
28 void
29 Push2::button_play ()
30 {
31         if (session->transport_rolling ()) {
32                 transport_stop ();
33         } else {
34                 transport_play ();
35         }
36 }
37
38 void
39 Push2::button_recenable ()
40 {
41         rec_enable_toggle ();
42 }
43
44 void
45 Push2::button_up ()
46 {
47         scroll_up_1_track ();
48 }
49
50 void
51 Push2::button_down ()
52 {
53         scroll_dn_1_track ();
54 }
55
56 void
57 Push2::button_right ()
58 {
59         ScrollTimeline (0.75);
60 }
61
62 void
63 Push2::button_left ()
64 {
65         ScrollTimeline (-0.75);
66 }
67
68 void
69 Push2::button_repeat ()
70 {
71         loop_toggle ();
72 }
73
74 void
75 Push2::button_metronome ()
76 {
77         toggle_click ();
78 }
79
80 void
81 Push2::button_solo ()
82 {
83         cancel_all_solo ();
84 }
85
86 void
87 Push2::button_new ()
88 {
89         access_action ("Editor/start-range-from-playhead");
90
91         id_button_map[New]->set_color (LED::White);
92         id_button_map[New]->set_state (LED::NoTransition);
93         write (id_button_map[New]->state_msg());
94
95         /* blink the button for the other half of this operation */
96
97         id_button_map[FixedLength]->set_color (LED::White);
98         id_button_map[FixedLength]->set_state (LED::Blinking4th);
99         write (id_button_map[FixedLength]->state_msg());
100 }
101
102
103 void
104 Push2::button_fixed_length ()
105 {
106         access_action ("Editor/finish-range-from-playhead");
107
108         /* turn off both buttons for this operation */
109
110         id_button_map[New]->set_color (LED::Black);
111         id_button_map[New]->set_state (LED::NoTransition);
112         write (id_button_map[New]->state_msg());
113         id_button_map[FixedLength]->set_color (LED::Black);
114         id_button_map[FixedLength]->set_state (LED::NoTransition);
115         write (id_button_map[FixedLength]->state_msg());
116 }
117
118 void
119 Push2::button_shift_press ()
120 {
121         modifier_state = ModifierState (modifier_state | ModShift);
122 }
123
124 void
125 Push2::button_shift_release ()
126 {
127         modifier_state = ModifierState (modifier_state & ~ModShift);
128 }
129
130 void
131 Push2::button_browse ()
132 {
133         switch_bank (max (0, bank_start - 8));
134 }
135
136 void
137 Push2::button_clip ()
138 {
139         switch_bank (max (0, bank_start + 8));
140 }
141
142 void
143 Push2::button_upper (uint32_t n)
144 {
145         if (!stripable[n]) {
146                 return;
147         }
148
149         boost::shared_ptr<SoloControl> sc = stripable[n]->solo_control ();
150         if (sc) {
151                 sc->set_value (!sc->get_value(), PBD::Controllable::UseGroup);
152         }
153 }
154
155 void
156 Push2::button_lower (uint32_t n)
157 {
158         if (!stripable[n]) {
159                 return;
160         }
161
162         boost::shared_ptr<MuteControl> mc = stripable[n]->mute_control ();
163
164         if (mc) {
165                 mc->set_value (!mc->get_value(), PBD::Controllable::UseGroup);
166         }
167 }
168
169 void
170 Push2::button_undo ()
171 {
172         if (modifier_state & ModShift) {
173                 ControlProtocol::Redo ();
174         } else {
175                 ControlProtocol::Undo ();
176         }
177 }
178
179 void
180 Push2::button_fwd32t ()
181 {
182         const int n = (modifier_state & ModShift) ? 8 : 0;
183         goto_nth_marker (0+n);
184 }
185
186 void
187 Push2::button_fwd32 ()
188 {
189         const int n = (modifier_state & ModShift) ? 8 : 0;
190         goto_nth_marker (1+n);
191 }
192
193 void
194 Push2::button_fwd16t ()
195 {
196         const int n = (modifier_state & ModShift) ? 8 : 0;
197         goto_nth_marker (2+n);
198 }
199
200 void
201 Push2::button_fwd16 ()
202 {
203         const int n = (modifier_state & ModShift) ? 8 : 0;
204         goto_nth_marker (3+n);
205 }
206
207 void
208 Push2::button_fwd8t ()
209 {
210         const int n = (modifier_state & ModShift) ? 8 : 0;
211         goto_nth_marker (4+n);
212 }
213
214 void
215 Push2::button_fwd8 ()
216 {
217         const int n = (modifier_state & ModShift) ? 8 : 0;
218         goto_nth_marker (5+n);
219 }
220
221 void
222 Push2::button_fwd4t ()
223 {
224         const int n = (modifier_state & ModShift) ? 8 : 0;
225         goto_nth_marker (6+n);
226 }
227
228 void
229 Push2::button_fwd4 ()
230 {
231         const int n = (modifier_state & ModShift) ? 8 : 0;
232         goto_nth_marker (7+n);
233 }
234