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