744a9bd031560686260287994d346bca580e2244
[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 "mixer_ui.h"
30 #include "meter_bridge.h"
31 #include "connection_editor.h"
32 #include "public_editor.h"
33 #include "option_editor.h"
34 #include "location_ui.h"
35 #include "route_params_ui.h"
36 #include "library_ui.h"
37
38 #include "i18n.h"
39
40 using namespace ARDOUR;
41 using namespace Gtk;
42 using namespace Gtkmmext;
43
44 void
45 ARDOUR_UI::connect_to_session (Session *s)
46 {
47         session = s;
48
49         session->HaltOnXrun.connect (slot (*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 (slot (*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 (slot (*this, &ARDOUR_UI::transport_rec_enable_blink));
108         Blink.connect (slot (*this, &ARDOUR_UI::solo_blink));
109         Blink.connect (slot (*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 (slot (*this, &ARDOUR_UI::queue_transport_change));
116         session->ControlChanged.connect (slot (*this, &ARDOUR_UI::queue_map_control_change));
117
118         /* alert the user to these things happening */
119
120         session->AuditionActive.connect (slot (*this, &ARDOUR_UI::auditioning_changed));
121         session->SoloActive.connect (slot (*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->window().realize();
145         }
146
147         transport_stopped ();
148
149         second_connection = Main::timeout.connect (slot (*this, &ARDOUR_UI::every_second), 1000);
150         point_one_second_connection = Main::timeout.connect (slot (*this, &ARDOUR_UI::every_point_one_seconds), 100);
151         point_zero_one_second_connection = Main::timeout.connect (slot (*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->Hiding.connect (slot (*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                 connection_editor = new ConnectionEditor ();
251                 connection_editor->Hiding.connect (slot (*this, &ARDOUR_UI::connection_editor_hiding));
252         }
253
254         if (session) {
255                 connection_editor->set_session (session);
256         }
257
258         return 0;
259 }
260
261 void
262 ARDOUR_UI::toggle_connection_editor ()
263 {
264         if (create_connection_editor()) {
265                 return;
266         }
267
268         if (connection_editor->within_hiding()) {
269                 return;
270         }
271                                                       
272
273         if (connection_editor_check->get_active()){
274                 connection_editor->show_all();
275         } else {
276                 connection_editor->hide_all();
277         }
278 }
279
280 void
281 ARDOUR_UI::connection_editor_hiding()
282 {
283         connection_editor_check->set_active(false);
284 }
285
286 void
287 ARDOUR_UI::big_clock_hiding()
288 {
289         big_clock_check->set_active(false);
290 }
291
292 void
293 ARDOUR_UI::toggle_big_clock_window ()
294 {
295         if (big_clock_window->within_hiding()) {
296                 return;
297         }
298
299         if (big_clock_window->is_visible()) {
300                 big_clock_window->hide_all ();
301         } else {
302                 big_clock_window->show_all ();
303         }
304 }
305
306 void
307 ARDOUR_UI::toggle_options_window ()
308 {
309         if (option_editor == 0) {
310                 option_editor = new OptionEditor (*this, *editor, *mixer);
311                 option_editor->Hiding.connect(slot(*this, &ARDOUR_UI::option_hiding));
312                 option_editor->set_session (session);
313         } else if (option_editor->within_hiding()) {
314                 return;
315         }
316
317         if (option_editor->is_visible()) {
318                 option_editor->hide_all ();
319         } else {
320                 option_editor->show_all ();
321         }
322 }
323
324 void
325 ARDOUR_UI::option_hiding ()
326 {
327         options_window_check->set_active(false);
328 }
329
330 void
331 ARDOUR_UI::toggle_auto_input ()
332
333 {
334         toggle_some_session_state (auto_input_button,
335                                    &Session::get_auto_input,
336                                    &Session::set_auto_input);
337         
338         meter_bridge->clear_all_meters ();
339 }
340
341 void
342 ARDOUR_UI::toggle_metering ()
343 {
344 #if 0
345         if (global_meter_button.get_active()) {
346                 meter_bridge->toggle_metering ();
347         }
348 #endif
349 }
350
351 int
352 ARDOUR_UI::create_location_ui ()
353 {
354         if (location_ui == 0) {
355                 location_ui = new LocationUI ();
356                 location_ui->set_session (session);
357                 location_ui->Hiding.connect (slot (*this, &ARDOUR_UI::location_ui_hiding));
358         } 
359         return 0;
360 }
361
362 void
363 ARDOUR_UI::toggle_location_window ()
364 {
365         if (create_location_ui()) {
366                 return;
367         }
368
369         if (location_ui->within_hiding()) {
370                 return;
371         }
372
373         if (location_ui->is_visible()) {
374                 location_ui->hide_all();
375         } else {
376                 location_ui->show_all();
377         }
378 }
379
380 void
381 ARDOUR_UI::location_ui_hiding()
382 {
383         locations_dialog_check->set_active(false);
384 }
385
386 int
387 ARDOUR_UI::create_route_params ()
388 {
389         if (route_params == 0) {
390                 route_params = new RouteParams_UI (*engine);
391                 route_params->set_session (session);
392                 route_params->Hiding.connect (slot (*this, &ARDOUR_UI::route_params_hiding));
393         }
394         return 0;
395 }
396
397 void
398 ARDOUR_UI::toggle_route_params_window ()
399 {
400         if (create_route_params ()) {
401                 return;
402         }
403
404         if (route_params->within_hiding()) {
405                 return;
406         }
407
408         if (route_params->is_visible ()) {
409                 route_params->hide_all ();
410         } else {
411                 route_params->show_all ();
412         }
413 }
414         
415 void
416 ARDOUR_UI::route_params_hiding ()
417 {
418         route_params_check->set_active (false);
419 }
420
421 SoundFileSelector&
422 ARDOUR_UI::get_sfdb_window ()
423 {
424         if (sfdb_window == 0) {
425                 sfdb_window = new SoundFileSelector ();
426                 sfdb_window->Hiding.connect (slot (*this, &ARDOUR_UI::sfdb_hiding));
427                 sfdb_window->hide_all ();
428         }
429         
430         return *sfdb_window;
431 }
432
433 void
434 ARDOUR_UI::toggle_sfdb_window ()
435 {
436         get_sfdb_window ();
437
438         if (sfdb_window->within_hiding()) {
439                 return;
440         }
441
442         if (sfdb_window->is_visible ()) {
443                 sfdb_window->hide_all ();
444         } else {
445                 sfdb_window->show_all ();
446                 sfdb_window->hide_import_stuff();
447         }
448 }
449
450 void
451 ARDOUR_UI::sfdb_hiding ()
452 {
453         sfdb_check->set_active (false);
454 }