provide limited momentary note on/off MIDI binding option; remove some debugging...
[ardour.git] / libs / surfaces / control_protocol / basic_ui.cc
1 /*
2     Copyright (C) 2006 Paul Davis 
3
4     This program is free software; you can redistribute it
5     and/or modify it under the terms of the GNU Lesser
6     General Public License as published by the Free Software
7     Foundation; either version 2 of the License, or (at your
8     option) any later version.
9
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14
15     You should have received a copy of the GNU General Public License
16     along with this program; if not, write to the Free Software
17     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18
19 */
20
21 #include "pbd/pthread_utils.h"
22
23 #include "ardour/session.h"
24 #include "ardour/location.h"
25
26 #include "control_protocol/basic_ui.h"
27
28 #include "i18n.h"
29
30 using namespace ARDOUR;
31 using ARDOUR::nframes_t;
32
33 PBD::Signal2<void,std::string,std::string> BasicUI::AccessAction;
34
35 BasicUI::BasicUI (Session& s)
36         : session (&s)
37 {
38 }
39
40 BasicUI::BasicUI ()
41         : session (0)
42 {
43 }
44
45 BasicUI::~BasicUI ()
46 {
47         
48 }
49
50 void
51 BasicUI::register_thread (std::string name)
52 {
53         std::string pool_name = name;
54         pool_name += " events";
55
56         SessionEvent::create_per_thread_pool (pool_name, 64);
57 }
58
59 void
60 BasicUI::access_action ( std::string action_path ) 
61 {
62         int split_at = action_path.find( "/" );
63         std::string group = action_path.substr( 0, split_at );
64         std::string item = action_path.substr( split_at + 1 );
65
66         AccessAction( group, item );
67 }
68
69 void
70 BasicUI::loop_toggle () 
71 {
72         if (session->get_play_loop()) {
73                 session->request_play_loop (false);
74         } else {
75                 session->request_play_loop (true);
76                 if (!session->transport_rolling()) {
77                         session->request_transport_speed (1.0);
78                 }
79         }
80 }
81
82 void
83 BasicUI::goto_start ()
84 {
85         session->goto_start ();
86 }
87
88 void
89 BasicUI::goto_end ()
90 {
91         session->goto_end ();
92 }
93
94 void       
95 BasicUI::add_marker ()
96 {
97         nframes_t when = session->audible_frame();
98         session->locations()->add (new Location (when, when, _("unnamed"), Location::IsMark));
99 }
100
101 void
102 BasicUI::rewind ()
103 {
104         session->request_transport_speed (-2.0f);
105 }
106
107 void
108 BasicUI::ffwd ()
109 {
110         session->request_transport_speed (2.0f);
111 }
112
113 void
114 BasicUI::transport_stop ()
115 {
116         session->request_transport_speed (0.0);
117 }
118
119 void
120 BasicUI::transport_play (bool from_last_start)
121 {
122         bool rolling = session->transport_rolling ();
123
124         if (session->get_play_loop()) {
125                 session->request_play_loop (false);
126         } 
127
128         if (session->get_play_range ()) {
129                 session->request_play_range (false);
130         }
131         
132         if (from_last_start && rolling) {
133                 session->request_locate (session->last_transport_start(), true);
134
135         }
136
137         session->request_transport_speed (1.0f);
138 }
139
140 void
141 BasicUI::rec_enable_toggle ()
142 {
143         switch (session->record_status()) {
144         case Session::Disabled:
145                 if (session->ntracks() == 0) {
146                         // string txt = _("Please create 1 or more track\nbefore trying to record.\nCheck the Session menu.");
147                         // MessageDialog msg (*editor, txt);
148                         // msg.run ();
149                         return;
150                 }
151                 session->maybe_enable_record ();
152                 break;
153         case Session::Recording:
154         case Session::Enabled:
155                 session->disable_record (true);
156         }
157 }
158
159 void
160 BasicUI::save_state ()
161 {
162         session->save_state ("");
163 }
164
165 void
166 BasicUI::prev_marker ()
167 {
168         Location *location = session->locations()->first_location_before (session->transport_frame());
169         
170         if (location) {
171                 session->request_locate (location->start(), session->transport_rolling());
172         } else {
173                 session->goto_start ();
174         }
175 }
176
177 void
178 BasicUI::next_marker ()
179 {
180         Location *location = session->locations()->first_location_after (session->transport_frame());
181
182         if (location) {
183                 session->request_locate (location->start(), session->transport_rolling());
184         } else {
185                 session->request_locate (session->current_end_frame());
186         }
187 }
188
189 void
190 BasicUI::set_transport_speed (double speed)
191 {
192         session->request_transport_speed (speed);
193 }
194
195 double
196 BasicUI::get_transport_speed ()
197 {
198         return session->transport_speed ();
199 }
200
201 void
202 BasicUI::undo ()
203 {
204         session->undo (1);
205 }
206
207 void
208 BasicUI::redo ()
209 {
210         session->redo (1);
211 }
212
213 void
214 BasicUI::toggle_all_rec_enables ()
215 {
216         if (session->get_record_enabled()) {
217                 // session->record_disenable_all ();
218         } else {
219                 // session->record_enable_all ();
220         }
221 }
222
223 void
224 BasicUI::toggle_punch_in ()
225 {
226         session->config.set_punch_in (!session->config.get_punch_in());
227 }
228
229 void
230 BasicUI::toggle_punch_out ()
231 {
232         session->config.set_punch_out (!session->config.get_punch_out());
233 }
234
235 bool
236 BasicUI::get_record_enabled ()
237 {
238         return session->get_record_enabled();
239 }
240
241 void
242 BasicUI::set_record_enable (bool yn)
243 {
244         if (yn) {
245                 session->maybe_enable_record ();
246         } else {
247                 session->disable_record (false, true);
248         }
249 }
250
251 nframes_t
252 BasicUI::transport_frame ()
253 {
254         return session->transport_frame();
255 }
256
257 void
258 BasicUI::locate (nframes_t where, bool roll_after_locate)
259 {
260         session->request_locate (where, roll_after_locate);
261 }
262
263 bool
264 BasicUI::locating ()
265 {
266         return session->locate_pending();
267 }
268
269 bool
270 BasicUI::locked ()
271 {
272         return session->transport_locked ();
273 }
274
275 nframes_t
276 BasicUI::timecode_frames_per_hour ()
277 {
278         return session->timecode_frames_per_hour ();
279 }
280
281 void
282 BasicUI::timecode_time (nframes_t where, Timecode::Time& timecode)
283 {
284         session->timecode_time (where, *((Timecode::Time *) &timecode));
285 }
286
287 void 
288 BasicUI::timecode_to_sample (Timecode::Time& timecode, nframes_t& sample, bool use_offset, bool use_subframes) const
289 {
290         session->timecode_to_sample (*((Timecode::Time*)&timecode), sample, use_offset, use_subframes);
291 }
292
293 void 
294 BasicUI::sample_to_timecode (nframes_t sample, Timecode::Time& timecode, bool use_offset, bool use_subframes) const
295 {
296         session->sample_to_timecode (sample, *((Timecode::Time*)&timecode), use_offset, use_subframes);
297 }
298
299 #if 0
300 this stuff is waiting to go in so that all UI's can offer complex solo/mute functionality
301
302 void
303 BasicUI::solo_release (boost::shared_ptr<Route> r)
304 {
305 }
306
307 void
308 BasicUI::solo_press (boost::shared_ptr<Route> r, bool momentary, bool global, bool exclusive, bool isolate, bool solo_group)
309 {
310         if (momentary) {
311                 _solo_release = new SoloMuteRelease (_route->soloed());
312         }
313         
314         if (global) {
315                 
316                 if (_solo_release) {
317                         _solo_release->routes = _session->get_routes ();
318                 }
319                 
320                 if (Config->get_solo_control_is_listen_control()) {
321                         _session->set_listen (_session->get_routes(), !_route->listening(),  Session::rt_cleanup, true);
322                 } else {
323                         _session->set_solo (_session->get_routes(), !_route->soloed(),  Session::rt_cleanup, true);
324                 }
325                 
326         } else if (exclusive) {
327                 
328                 if (_solo_release) {
329                         _solo_release->exclusive = true;
330                         
331                         boost::shared_ptr<RouteList> routes = _session->get_routes();
332                         
333                         for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
334                                 if ((*i)->soloed ()) {
335                                         _solo_release->routes_on->push_back (*i);
336                                 } else {
337                                         _solo_release->routes_off->push_back (*i);
338                                 }
339                         }
340                 }
341                 
342                 if (Config->get_solo_control_is_listen_control()) {
343                         /* ??? we need a just_one_listen() method */
344                 } else {
345                         _session->set_just_one_solo (_route, true);
346                 }
347                 
348         } else if (isolate) {
349                 
350                 // shift-click: toggle solo isolated status
351                 
352                 _route->set_solo_isolated (!_route->solo_isolated(), this);
353                 delete _solo_release;
354                 _solo_release = 0;
355                 
356         } else if (solo_group) {
357                 
358                 /* Primary-button1: solo mix group.
359                    NOTE: Primary-button2 is MIDI learn.
360                 */
361                 
362                 if (_route->route_group()) {
363                         
364                         if (_solo_release) {
365                                 _solo_release->routes = _route->route_group()->route_list();
366                         }
367                         
368                         if (Config->get_solo_control_is_listen_control()) {
369                                 _session->set_listen (_route->route_group()->route_list(), !_route->listening(),  Session::rt_cleanup, true);
370                         } else {
371                                 _session->set_solo (_route->route_group()->route_list(), !_route->soloed(),  Session::rt_cleanup, true);
372                         }
373                 }
374                 
375         } else {
376                 
377                 /* click: solo this route */
378                 
379                 boost::shared_ptr<RouteList> rl (new RouteList);
380                 rl->push_back (route());
381                 
382                 if (_solo_release) {
383                         _solo_release->routes = rl;
384                 }
385                 
386                 if (Config->get_solo_control_is_listen_control()) {
387                         _session->set_listen (rl, !_route->listening());
388                 } else {
389                         _session->set_solo (rl, !_route->soloed());
390                 }
391         }
392 }
393 #endif