many changes, read the diffs
[ardour.git] / gtk2_ardour / ardour_ui_dialogs.cc
1 /*
2     Copyright (C) 2000 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 */
19
20 /* This file contains any ARDOUR_UI methods that require knowledge of
21    the various dialog boxes, and exists so that no compilation dependency 
22    exists between the main ARDOUR_UI modules and their respective classes.
23    This is to cut down on the compile times.  It also helps with my sanity.
24 */
25
26 #include <ardour/session.h>
27
28 #include "actions.h"
29 #include "ardour_ui.h"
30 #include "connection_editor.h"
31 #include "location_ui.h"
32 #include "mixer_ui.h"
33 #include "option_editor.h"
34 #include "public_editor.h"
35 #include "route_params_ui.h"
36 #include "sfdb_ui.h"
37
38 #include "i18n.h"
39
40 using namespace ARDOUR;
41 using namespace Glib;
42 using namespace Gtk;
43 using namespace Gtkmm2ext;
44
45 void
46 ARDOUR_UI::connect_to_session (Session *s)
47 {
48         session = s;
49
50         session->HaltOnXrun.connect (mem_fun(*this, &ARDOUR_UI::halt_on_xrun_message));
51
52         /* sensitize menu bar options that are now valid */
53
54         ActionManager::set_sensitive (ActionManager::session_sensitive_actions, true);
55
56         rec_button.set_sensitive (true);
57         shuttle_box.set_sensitive (true);
58         
59         if (session->n_diskstreams() == 0) {
60                 session->DiskStreamAdded.connect (mem_fun(*this, &ARDOUR_UI::diskstream_added));
61         }
62
63         if (connection_editor) {
64                 connection_editor->set_session (s);
65         }
66
67         if (location_ui) {
68                 location_ui->set_session(s);
69         }
70
71         if (route_params) {
72                 route_params->set_session (s);
73         }
74
75         if (option_editor) {
76                 option_editor->set_session (s);
77         }
78
79
80         Blink.connect (mem_fun(*this, &ARDOUR_UI::transport_rec_enable_blink));
81         Blink.connect (mem_fun(*this, &ARDOUR_UI::solo_blink));
82         Blink.connect (mem_fun(*this, &ARDOUR_UI::audition_blink));
83
84         /* these are all need to be handled in an RT-safe and MT way, so don't
85            do any GUI work, just queue it for handling by the GUI thread.
86         */
87
88         session->TransportStateChange.connect (mem_fun(*this, &ARDOUR_UI::queue_transport_change));
89         session->ControlChanged.connect (mem_fun(*this, &ARDOUR_UI::queue_map_control_change));
90
91         /* alert the user to these things happening */
92
93         session->AuditionActive.connect (mem_fun(*this, &ARDOUR_UI::auditioning_changed));
94         session->SoloActive.connect (mem_fun(*this, &ARDOUR_UI::soloing_changed));
95
96         solo_alert_button.set_active (session->soloing());
97
98         /* can't be auditioning here */
99
100         primary_clock.set_session (s);
101         secondary_clock.set_session (s);
102         big_clock.set_session (s);
103         preroll_clock.set_session (s);
104         postroll_clock.set_session (s);
105
106         /* Clocks are on by default after we are connected to a session, so show that here.
107         */
108         
109         map_button_state ();
110
111         connect_dependents_to_session (s);
112         
113         start_clocking ();
114         start_blinking ();
115
116         if (editor) {
117                 editor->present();
118         }
119
120         transport_stopped ();
121
122         second_connection = Glib::signal_timeout().connect (mem_fun(*this, &ARDOUR_UI::every_second), 1000);
123         point_one_second_connection = Glib::signal_timeout().connect (mem_fun(*this, &ARDOUR_UI::every_point_one_seconds), 100);
124         point_zero_one_second_connection = Glib::signal_timeout().connect (mem_fun(*this, &ARDOUR_UI::every_point_zero_one_seconds), 40);
125 }
126
127 int
128 ARDOUR_UI::unload_session ()
129 {
130         if (session && session->dirty()) {
131                 switch (ask_about_saving_session (_("close session"))) {
132                 case -1:
133                         return 1;
134                         
135                 case 1:
136                         session->save_state ("");
137                         break;
138                 }
139         }
140
141         second_connection.disconnect ();
142         point_one_second_connection.disconnect ();
143         point_zero_one_second_connection.disconnect();
144
145         ActionManager::set_sensitive (ActionManager::session_sensitive_actions, false);
146         
147         rec_button.set_sensitive (false);
148         shuttle_box.set_sensitive (false);
149
150         stop_blinking ();
151         stop_clocking ();
152
153         /* drop everything attached to the blink signal */
154
155         Blink.clear ();
156
157         primary_clock.set_session (0);
158         secondary_clock.set_session (0);
159         big_clock.set_session (0);
160         preroll_clock.set_session (0);
161         postroll_clock.set_session (0);
162
163         if (option_editor) {
164                 option_editor->set_session (0);
165         }
166
167         if (mixer) {
168                 mixer->hide_all ();
169         }
170
171         delete session;
172         session = 0;
173
174         update_buffer_load ();
175         // update_disk_rate ();
176
177         return 0;
178 }
179
180 int
181 ARDOUR_UI::create_connection_editor ()
182 {
183 #if 0
184         if (connection_editor == 0) {
185                 connection_editor = new ConnectionEditor ();
186                 connection_editor->signal_unmap().connect (sigc::bind (ptr_fun(&ActionManager::uncheck_toggleaction), X_("<Actions>/Common/ToggleConnections")));
187         }
188
189         if (session) {
190                 connection_editor->set_session (session);
191         }
192 #endif
193
194         return 0;
195 }
196
197 void
198 ARDOUR_UI::toggle_connection_editor ()
199 {
200         if (create_connection_editor()) {
201                 return;
202         }
203
204 #if 0
205         RefPtr<Action> act = ActionManager::get_action (X_("Common"), X_("ToggleConnections"));
206         if (act) {
207                 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
208         
209                 if (tact->get_active()) {
210                         connection_editor->show_all ();
211                         connection_editor->present ();
212                 } else {
213                         connection_editor->hide ();
214                 } 
215         }
216 #endif
217 }
218
219 void
220 ARDOUR_UI::toggle_big_clock_window ()
221 {
222         RefPtr<Action> act = ActionManager::get_action (X_("Common"), X_("ToggleBigClock"));
223         if (act) {
224                 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
225         
226                 if (tact->get_active()) {
227                         big_clock_window->show_all ();
228                         big_clock_window->present ();
229                 } else {
230                         big_clock_window->hide ();
231                 } 
232         }
233 }
234
235 void
236 ARDOUR_UI::toggle_options_window ()
237 {
238         if (option_editor == 0) {
239                 option_editor = new OptionEditor (*this, *editor, *mixer);
240                 option_editor->signal_unmap().connect(sigc::bind (sigc::ptr_fun(&ActionManager::uncheck_toggleaction), X_("<Actions>/Common/ToggleOptionsEditor")));
241                 option_editor->set_session (session);
242         } 
243
244         RefPtr<Action> act = ActionManager::get_action (X_("Common"), X_("ToggleOptionsEditor"));
245         if (act) {
246                 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
247         
248                 if (tact->get_active()) {
249                         option_editor->show_all ();
250                         option_editor->present ();
251                 } else {
252                         option_editor->hide ();
253                 } 
254         }
255 }
256
257 void
258 ARDOUR_UI::toggle_auto_input ()
259
260 {
261         toggle_some_session_state (auto_input_button,
262                                    &Session::get_auto_input,
263                                    &Session::set_auto_input);
264 }
265
266 int
267 ARDOUR_UI::create_location_ui ()
268 {
269         if (location_ui == 0) {
270                 location_ui = new LocationUI ();
271                 location_ui->set_session (session);
272                 location_ui->signal_unmap().connect (sigc::bind (sigc::ptr_fun(&ActionManager::uncheck_toggleaction), X_("<Actions>/Common/ToggleLocations")));
273         }
274         return 0;
275 }
276
277 void
278 ARDOUR_UI::toggle_location_window ()
279 {
280         if (create_location_ui()) {
281                 return;
282         }
283
284         RefPtr<Action> act = ActionManager::get_action (X_("Common"), X_("ToggleLocations"));
285         if (act) {
286                 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
287         
288                 if (tact->get_active()) {
289                         location_ui->show_all ();
290                         location_ui->present ();
291                 } else {
292                         location_ui->hide ();
293                 } 
294         }
295 }
296
297 int
298 ARDOUR_UI::create_route_params ()
299 {
300         if (route_params == 0) {
301                 route_params = new RouteParams_UI (*engine);
302                 route_params->set_session (session);
303                 route_params->signal_unmap().connect (sigc::bind(sigc::ptr_fun(&ActionManager::uncheck_toggleaction), X_("<Actions>/Common/ToggleInspector")));
304         }
305         return 0;
306 }
307
308 void
309 ARDOUR_UI::toggle_route_params_window ()
310 {
311         if (create_route_params ()) {
312                 return;
313         }
314
315         RefPtr<Action> act = ActionManager::get_action (X_("Common"), X_("ToggleInspector"));
316         if (act) {
317                 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
318         
319                 if (tact->get_active()) {
320                         route_params->show_all ();
321                         route_params->present ();
322                 } else {
323                         route_params->hide ();
324                 } 
325         }
326 }
327
328 int
329 ARDOUR_UI::create_sound_file_browser ()
330 {
331         if (sfdb == 0) {
332                 sfdb = new SoundFileBrowser (_("Sound File Browser"));
333                 sfdb->set_session (session);
334                 sfdb->signal_unmap().connect (sigc::bind(sigc::ptr_fun(&ActionManager::uncheck_toggleaction), X_("<Actions>/Common/ToggleSoundFileBrowser")));
335         }
336         return 0;
337 }
338         
339 void
340 ARDOUR_UI::toggle_sound_file_browser ()
341 {
342         if (create_sound_file_browser()) {
343                 return;
344         }
345
346         RefPtr<Action> act = ActionManager::get_action (X_("Common"), X_("ToggleSoundFileBrowser"));
347         if (act) {
348                 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
349         
350                 if (tact->get_active()) {
351                         sfdb->present();
352                 } else {
353                         sfdb->hide ();
354                 }
355         }
356 }