99ba92ab0b3b4e9ce988de634fa03ecc36cff017
[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 "ardour_ui.h"
29 #include "connection_editor.h"
30 #include "location_ui.h"
31 #include "meter_bridge.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 Gtk;
42 using namespace Gtkmm2ext;
43
44 void
45 ARDOUR_UI::connect_to_session (Session *s)
46 {
47         session = s;
48
49         session->HaltOnXrun.connect (mem_fun(*this, &ARDOUR_UI::halt_on_xrun_message));
50
51         /* sensitize menu bar options that are now valid */
52
53 //      save_as_item->set_sensitive (true);
54         save_template_item->set_sensitive (true);
55         snapshot_item->set_sensitive (true);
56         save_item->set_sensitive (true);
57         add_track_item->set_sensitive (true);
58         export_item->set_sensitive (true);
59         close_item->set_sensitive (true);
60         locations_dialog_check->set_sensitive (true);
61         route_params_check->set_sensitive (true);
62         connection_editor_check->set_sensitive (true);
63
64         cleanup_item->set_sensitive (true);
65
66         /* sensitize transport bar */
67
68         goto_start_button.set_sensitive (true);
69         goto_end_button.set_sensitive (true);
70         roll_button.set_sensitive (true);
71         stop_button.set_sensitive (true);
72         play_selection_button.set_sensitive (true);
73         rec_button.set_sensitive (true);
74         auto_loop_button.set_sensitive (true);
75         shuttle_box.set_sensitive (true);
76         
77         /* <CMT Additions> */
78         if (image_compositor_item) {
79                 image_compositor_item->set_sensitive(true) ;
80         }
81         /* </CMT Additions> */
82         
83
84         if (session->n_diskstreams()) {
85                 // meter_bridge_dialog_check->set_sensitive (true);
86         } else {
87                 session->DiskStreamAdded.connect (mem_fun(*this, &ARDOUR_UI::diskstream_added));
88         }
89
90         if (connection_editor) {
91                 connection_editor->set_session (s);
92         }
93
94         if (location_ui) {
95                 location_ui->set_session(s);
96         }
97
98         if (route_params) {
99                 route_params->set_session (s);
100         }
101
102         if (option_editor) {
103                 option_editor->set_session (s);
104         }
105
106
107         Blink.connect (mem_fun(*this, &ARDOUR_UI::transport_rec_enable_blink));
108         Blink.connect (mem_fun(*this, &ARDOUR_UI::solo_blink));
109         Blink.connect (mem_fun(*this, &ARDOUR_UI::audition_blink));
110
111         /* these are all need to be handled in an RT-safe and MT way, so don't
112            do any GUI work, just queue it for handling by the GUI thread.
113         */
114
115         session->TransportStateChange.connect (mem_fun(*this, &ARDOUR_UI::queue_transport_change));
116         session->ControlChanged.connect (mem_fun(*this, &ARDOUR_UI::queue_map_control_change));
117
118         /* alert the user to these things happening */
119
120         session->AuditionActive.connect (mem_fun(*this, &ARDOUR_UI::auditioning_changed));
121         session->SoloActive.connect (mem_fun(*this, &ARDOUR_UI::soloing_changed));
122
123         solo_alert_button.set_active (session->soloing());
124
125         /* can't be auditioning here */
126
127         primary_clock.set_session (s);
128         secondary_clock.set_session (s);
129         big_clock.set_session (s);
130         preroll_clock.set_session (s);
131         postroll_clock.set_session (s);
132
133         /* Clocks are on by default after we are connected to a session, so show that here.
134         */
135         
136         map_button_state ();
137
138         connect_dependents_to_session (s);
139         
140         start_clocking ();
141         start_blinking ();
142
143         if (editor) {
144                 editor->present();
145         }
146
147         transport_stopped ();
148
149         second_connection = Glib::signal_timeout().connect (mem_fun(*this, &ARDOUR_UI::every_second), 1000);
150         point_one_second_connection = Glib::signal_timeout().connect (mem_fun(*this, &ARDOUR_UI::every_point_one_seconds), 100);
151         point_zero_one_second_connection = Glib::signal_timeout().connect (mem_fun(*this, &ARDOUR_UI::every_point_zero_one_seconds), 40);
152 }
153
154 int
155 ARDOUR_UI::unload_session ()
156 {
157         if (session && session->dirty()) {
158                 switch (ask_about_saving_session (_("close session"))) {
159                 case -1:
160                         return 1;
161                         
162                 case 1:
163                         session->save_state ("");
164                         break;
165                 }
166         }
167
168         second_connection.disconnect ();
169         point_one_second_connection.disconnect ();
170         point_zero_one_second_connection.disconnect();
171
172         /* desensitize menu bar options that are now invalid */
173
174 //      save_as_item->set_sensitive (false);
175         save_template_item->set_sensitive (false);
176         snapshot_item->set_sensitive (false);
177         save_item->set_sensitive (false);
178         add_track_item->set_sensitive (false);
179         export_item->set_sensitive (false);
180         close_item->set_sensitive (false);
181         // meter_bridge_dialog_check->set_sensitive (false);
182         connection_editor_check->set_sensitive (false);
183         locations_dialog_check->set_sensitive (false);
184         // meter_bridge_dialog_check->set_active(false);
185         connection_editor_check->set_active(false);
186         locations_dialog_check->set_active(false);
187         route_params_check->set_sensitive (false);
188
189         /* desensitize transport bar */
190
191         goto_start_button.set_sensitive (false);
192         goto_end_button.set_sensitive (false);
193         roll_button.set_sensitive (false);
194         stop_button.set_sensitive (false);
195         play_selection_button.set_sensitive (false);
196         rec_button.set_sensitive (false);
197         auto_loop_button.set_sensitive (false);
198         shuttle_box.set_sensitive (false);
199
200         stop_blinking ();
201         stop_clocking ();
202
203         /* drop everything attached to the blink signal */
204
205         Blink.clear ();
206
207         primary_clock.set_session (0);
208         secondary_clock.set_session (0);
209         big_clock.set_session (0);
210         preroll_clock.set_session (0);
211         postroll_clock.set_session (0);
212
213         if (option_editor) {
214                 option_editor->set_session (0);
215         }
216
217         if (mixer) {
218                 mixer->hide_all ();
219         }
220
221         delete session;
222         session = 0;
223
224         update_buffer_load ();
225         // update_disk_rate ();
226
227         return 0;
228 }
229
230 int
231 ARDOUR_UI::create_meter_bridge ()
232 {
233         if (meter_bridge == 0) {
234                 meter_bridge = new MeterBridge ();
235                 meter_bridge->signal_unmap().connect (mem_fun(*this, &ARDOUR_UI::meter_bridge_hiding));
236         }
237         return 0;
238 }
239
240 void
241 ARDOUR_UI::meter_bridge_hiding()
242 {
243         // meter_bridge_dialog_check->set_active(false);
244 }
245
246 int
247 ARDOUR_UI::create_connection_editor ()
248 {
249         if (connection_editor == 0) {
250                 // GTK2FIX
251                 // connection_editor = new ConnectionEditor ();
252                 // connection_editor->signal_unmap().connect (mem_fun(*this, &ARDOUR_UI::connection_editor_hiding));
253         }
254
255         if (session) {
256                 // connection_editor->set_session (session);
257         }
258
259         return 0;
260 }
261
262 void
263 ARDOUR_UI::toggle_connection_editor ()
264 {
265         if (create_connection_editor()) {
266                 return;
267         }
268
269         //GTK2FIX
270 #if 0
271
272         if (connection_editor->within_hiding()) {
273                 return;
274         }
275                                                       
276
277         if (connection_editor_check->get_active()){
278                 connection_editor->show_all();
279         } else {
280                 connection_editor->hide_all();
281         }
282 #endif
283 }
284
285 void
286 ARDOUR_UI::connection_editor_hiding()
287 {
288         //GTK2FIX
289         // connection_editor_check->set_active(false);
290 }
291
292 void
293 ARDOUR_UI::big_clock_hiding()
294 {
295         big_clock_check->set_active(false);
296 }
297
298 void
299 ARDOUR_UI::toggle_big_clock_window ()
300 {
301         if (big_clock_window->within_hiding()) {
302                 return;
303         }
304
305         if (big_clock_window->is_visible()) {
306                 big_clock_window->hide_all ();
307         } else {
308                 big_clock_window->show_all ();
309         }
310 }
311
312 void
313 ARDOUR_UI::toggle_options_window ()
314 {
315         if (option_editor == 0) {
316                 option_editor = new OptionEditor (*this, *editor, *mixer);
317                 option_editor->signal_unmap().connect(mem_fun(*this, &ARDOUR_UI::option_hiding));
318                 option_editor->set_session (session);
319         } else if (option_editor->within_hiding()) {
320                 return;
321         }
322
323         if (option_editor->is_visible()) {
324                 option_editor->hide_all ();
325         } else {
326                 option_editor->show_all ();
327         }
328 }
329
330 void
331 ARDOUR_UI::option_hiding ()
332 {
333         options_window_check->set_active(false);
334 }
335
336 void
337 ARDOUR_UI::toggle_auto_input ()
338
339 {
340         toggle_some_session_state (auto_input_button,
341                                    &Session::get_auto_input,
342                                    &Session::set_auto_input);
343         
344         meter_bridge->clear_all_meters ();
345 }
346
347 void
348 ARDOUR_UI::toggle_metering ()
349 {
350 #if 0
351         if (global_meter_button.get_active()) {
352                 meter_bridge->toggle_metering ();
353         }
354 #endif
355 }
356
357 int
358 ARDOUR_UI::create_location_ui ()
359 {
360         if (location_ui == 0) {
361                 location_ui = new LocationUI ();
362                 location_ui->set_session (session);
363                 location_ui->signal_unmap().connect (mem_fun(*this, &ARDOUR_UI::location_ui_hiding));
364         } 
365         return 0;
366 }
367
368 void
369 ARDOUR_UI::toggle_location_window ()
370 {
371         if (create_location_ui()) {
372                 return;
373         }
374
375         if (location_ui->within_hiding()) {
376                 return;
377         }
378
379         if (location_ui->is_visible()) {
380                 location_ui->hide_all();
381         } else {
382                 location_ui->show_all();
383         }
384 }
385
386 void
387 ARDOUR_UI::location_ui_hiding()
388 {
389         locations_dialog_check->set_active(false);
390 }
391
392 int
393 ARDOUR_UI::create_route_params ()
394 {
395         if (route_params == 0) {
396                 route_params = new RouteParams_UI (*engine);
397                 route_params->set_session (session);
398                 route_params->signal_unmap().connect (mem_fun(*this, &ARDOUR_UI::route_params_hiding));
399         }
400         return 0;
401 }
402
403 void
404 ARDOUR_UI::toggle_route_params_window ()
405 {
406         if (create_route_params ()) {
407                 return;
408         }
409
410         if (route_params->within_hiding()) {
411                 return;
412         }
413
414         if (route_params->is_visible ()) {
415                 route_params->hide_all ();
416         } else {
417                 route_params->show_all ();
418         }
419 }
420         
421 void
422 ARDOUR_UI::route_params_hiding ()
423 {
424         route_params_check->set_active (false);
425 }
426
427 void
428 ARDOUR_UI::toggle_sound_file_browser ()
429 {
430         if (sfdb_check->get_active()) {
431                 SoundFileBrowser sfdb(_("Sound File Browser"));
432
433                 sfdb_check->signal_toggled().connect (bind (mem_fun (sfdb, &Gtk::Dialog::response), Gtk::RESPONSE_CANCEL));
434                 sfdb.run();
435                 sfdb_check->set_active(false);
436         }
437 }
438