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