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