Rect fix
[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
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_auto_loop()) {
58                 session->request_auto_loop (false);
59         } else {
60                 session->request_auto_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         jack_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_auto_loop()) {
110                 session->request_auto_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         session->save_history("");
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         session->set_punch_in (!session->get_punch_in());
213 }
214
215 void
216 BasicUI::toggle_punch_out ()
217 {
218         session->set_punch_out (!session->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 jack_nframes_t
238 BasicUI::transport_frame ()
239 {
240         return session->transport_frame();
241 }
242
243 void
244 BasicUI::locate (jack_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 jack_nframes_t
262 BasicUI::smpte_frames_per_hour ()
263 {
264         return session->smpte_frames_per_hour ();
265 }
266
267 void
268 BasicUI::smpte_time (jack_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, jack_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 (jack_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 }