71d579480589e050d59ee253ee539d7e9b637b3e
[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 sigc::signal<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         PBD::ThreadCreated (pthread_self(), name);
54 }
55
56
57 void
58 BasicUI::access_action ( std::string action_path ) 
59 {
60         int split_at = action_path.find( "/" );
61         std::string group = action_path.substr( 0, split_at );
62         std::string item = action_path.substr( split_at + 1 );
63
64         AccessAction( group, item );
65 }
66
67 void
68 BasicUI::loop_toggle () 
69 {
70         if (session->get_play_loop()) {
71                 session->request_play_loop (false);
72         } else {
73                 session->request_play_loop (true);
74                 if (!session->transport_rolling()) {
75                         session->request_transport_speed (1.0);
76                 }
77         }
78 }
79
80 void
81 BasicUI::goto_start ()
82 {
83         session->goto_start ();
84 }
85
86 void
87 BasicUI::goto_end ()
88 {
89         session->goto_end ();
90 }
91
92 void       
93 BasicUI::add_marker ()
94 {
95         nframes_t when = session->audible_frame();
96         session->locations()->add (new Location (when, when, _("unnamed"), Location::IsMark));
97 }
98
99 void
100 BasicUI::rewind ()
101 {
102         session->request_transport_speed (-2.0f);
103 }
104
105 void
106 BasicUI::ffwd ()
107 {
108         session->request_transport_speed (2.0f);
109 }
110
111 void
112 BasicUI::transport_stop ()
113 {
114         session->request_transport_speed (0.0);
115 }
116
117 void
118 BasicUI::transport_play (bool from_last_start)
119 {
120         bool rolling = session->transport_rolling ();
121
122         if (session->get_play_loop()) {
123                 session->request_play_loop (false);
124         } 
125
126         if (session->get_play_range ()) {
127                 session->request_play_range (false);
128         }
129         
130         if (from_last_start && rolling) {
131                 session->request_locate (session->last_transport_start(), true);
132
133         }
134
135         session->request_transport_speed (1.0f);
136 }
137
138 void
139 BasicUI::rec_enable_toggle ()
140 {
141         switch (session->record_status()) {
142         case Session::Disabled:
143                 if (session->ntracks() == 0) {
144                         // string txt = _("Please create 1 or more track\nbefore trying to record.\nCheck the Session menu.");
145                         // MessageDialog msg (*editor, txt);
146                         // msg.run ();
147                         return;
148                 }
149                 session->maybe_enable_record ();
150                 break;
151         case Session::Recording:
152         case Session::Enabled:
153                 session->disable_record (true);
154         }
155 }
156
157 void
158 BasicUI::save_state ()
159 {
160         session->save_state ("");
161 }
162
163 void
164 BasicUI::prev_marker ()
165 {
166         Location *location = session->locations()->first_location_before (session->transport_frame());
167         
168         if (location) {
169                 session->request_locate (location->start(), session->transport_rolling());
170         } else {
171                 session->goto_start ();
172         }
173 }
174
175 void
176 BasicUI::next_marker ()
177 {
178         Location *location = session->locations()->first_location_after (session->transport_frame());
179
180         if (location) {
181                 session->request_locate (location->start(), session->transport_rolling());
182         } else {
183                 session->request_locate (session->current_end_frame());
184         }
185 }
186
187 void
188 BasicUI::set_transport_speed (float speed)
189 {
190         session->request_transport_speed (speed);
191 }
192
193 float
194 BasicUI::get_transport_speed ()
195 {
196         return session->transport_speed ();
197 }
198
199 void
200 BasicUI::undo ()
201 {
202         session->undo (1);
203 }
204
205 void
206 BasicUI::redo ()
207 {
208         session->redo (1);
209 }
210
211 void
212 BasicUI::toggle_all_rec_enables ()
213 {
214         if (session->get_record_enabled()) {
215                 session->record_disenable_all ();
216         } else {
217                 session->record_enable_all ();
218         }
219 }
220
221 void
222 BasicUI::toggle_punch_in ()
223 {
224         Config->set_punch_in (!Config->get_punch_in());
225 }
226
227 void
228 BasicUI::toggle_punch_out ()
229 {
230         Config->set_punch_out (!Config->get_punch_out());
231 }
232
233 bool
234 BasicUI::get_record_enabled ()
235 {
236         return session->get_record_enabled();
237 }
238
239 void
240 BasicUI::set_record_enable (bool yn)
241 {
242         if (yn) {
243                 session->maybe_enable_record ();
244         } else {
245                 session->disable_record (false, true);
246         }
247 }
248
249 nframes_t
250 BasicUI::transport_frame ()
251 {
252         return session->transport_frame();
253 }
254
255 void
256 BasicUI::locate (nframes_t where, bool roll_after_locate)
257 {
258         session->request_locate (where, roll_after_locate);
259 }
260
261 bool
262 BasicUI::locating ()
263 {
264         return session->locate_pending();
265 }
266
267 bool
268 BasicUI::locked ()
269 {
270         return session->transport_locked ();
271 }
272
273 nframes_t
274 BasicUI::smpte_frames_per_hour ()
275 {
276         return session->smpte_frames_per_hour ();
277 }
278
279 void
280 BasicUI::smpte_time (nframes_t where, SMPTE::Time& smpte)
281 {
282         session->smpte_time (where, *((SMPTE::Time *) &smpte));
283 }
284
285 void 
286 BasicUI::smpte_to_sample (SMPTE::Time& smpte, nframes_t& sample, bool use_offset, bool use_subframes) const
287 {
288         session->smpte_to_sample (*((SMPTE::Time*)&smpte), sample, use_offset, use_subframes);
289 }
290
291 void 
292 BasicUI::sample_to_smpte (nframes_t sample, SMPTE::Time& smpte, bool use_offset, bool use_subframes) const
293 {
294         session->sample_to_smpte (sample, *((SMPTE::Time*)&smpte), use_offset, use_subframes);
295 }