more tranzport lowlevel fixes and rebinding
[ardour.git] / libs / ardour / basic_ui.cc
1 /*
2     Copyright (C) 2006 Paul Davis 
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18     $Id$
19 */
20
21 #include <ardour/basic_ui.h>
22 #include <ardour/session.h>
23 #include <ardour/location.h>
24
25 #include "i18n.h"
26
27 using namespace ARDOUR;
28
29 BasicUI::BasicUI (Session& s)
30         : session (s)
31 {
32 }
33
34 BasicUI::~BasicUI ()
35 {
36         
37 }
38
39 void
40 BasicUI::loop_toggle () 
41 {
42         if (session.get_auto_loop()) {
43                 session.request_auto_loop (false);
44         } else {
45                 session.request_auto_loop (true);
46                 if (!session.transport_rolling()) {
47                         session.request_transport_speed (1.0);
48                 }
49         }
50 }
51
52 void
53 BasicUI::goto_start ()
54 {
55         session.goto_start ();
56 }
57
58 void
59 BasicUI::goto_end ()
60 {
61         session.goto_end ();
62 }
63
64 void       
65 BasicUI::add_marker ()
66 {
67         jack_nframes_t when = session.audible_frame();
68         session.locations()->add (new Location (when, when, _("unnamed"), Location::IsMark));
69 }
70
71 void
72 BasicUI::rewind ()
73 {
74         session.request_transport_speed (-2.0f);
75 }
76
77 void
78 BasicUI::ffwd ()
79 {
80         session.request_transport_speed (2.0f);
81 }
82
83 void
84 BasicUI::transport_stop ()
85 {
86         session.request_transport_speed (0.0);
87 }
88
89 void
90 BasicUI::transport_play ()
91 {
92         bool rolling = session.transport_rolling ();
93
94         if (session.get_auto_loop()) {
95                 session.request_auto_loop (false);
96         } 
97
98         if (session.get_play_range ()) {
99                 session.request_play_range (false);
100         }
101         
102         if (rolling) {
103                 session.request_locate (session.last_transport_start(), true);
104
105         }
106
107         session.request_transport_speed (1.0f);
108 }
109
110 void
111 BasicUI::rec_enable_toggle ()
112 {
113         switch (session.record_status()) {
114         case Session::Disabled:
115                 if (session.ntracks() == 0) {
116                         // string txt = _("Please create 1 or more track\nbefore trying to record.\nCheck the Session menu.");
117                         // MessageDialog msg (*editor, txt);
118                         // msg.run ();
119                         return;
120                 }
121                 session.maybe_enable_record ();
122                 break;
123         case Session::Recording:
124         case Session::Enabled:
125                 session.disable_record (true);
126         }
127 }
128
129 void
130 BasicUI::save_state ()
131 {
132         session.save_state ("");
133 }
134
135 void
136 BasicUI::prev_marker ()
137 {
138         Location *location = session.locations()->first_location_before (session.transport_frame());
139         
140         if (location) {
141                 session.request_locate (location->start(), session.transport_rolling());
142         } else {
143                 session.goto_start ();
144         }
145 }
146
147 void
148 BasicUI::next_marker ()
149 {
150         Location *location = session.locations()->first_location_after (session.transport_frame());
151
152         if (location) {
153                 session.request_locate (location->start(), session.transport_rolling());
154         } else {
155                 session.request_locate (session.current_end_frame());
156         }
157 }
158
159 void
160 BasicUI::move_at (float speed)
161 {
162         session.request_transport_speed (speed);
163 }
164
165 void
166 BasicUI::undo ()
167 {
168         session.undo (1);
169 }
170
171 void
172 BasicUI::redo ()
173 {
174         session.redo (1);
175 }
176
177 void
178 BasicUI::toggle_all_rec_enables ()
179 {
180         if (session.get_record_enabled()) {
181                 session.record_disenable_all ();
182         } else {
183                 session.record_enable_all ();
184         }
185 }
186
187 void
188 BasicUI::toggle_punch_in ()
189 {
190         session.set_punch_in (!session.get_punch_in());
191 }
192
193 void
194 BasicUI::toggle_punch_out ()
195 {
196         session.set_punch_out (!session.get_punch_out());
197 }