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