6b1d0224db06394a9940762df974049e288c329e
[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 #include "color_manager.h"
38
39 #include "i18n.h"
40
41 using namespace ARDOUR;
42 using namespace Glib;
43 using namespace Gtk;
44 using namespace Gtkmm2ext;
45
46 void
47 ARDOUR_UI::connect_to_session (Session *s)
48 {
49         session = s;
50
51         session->HaltOnXrun.connect (mem_fun(*this, &ARDOUR_UI::halt_on_xrun_message));
52
53         /* sensitize menu bar options that are now valid */
54
55         ActionManager::set_sensitive (ActionManager::session_sensitive_actions, true);
56         
57         if (session->locations()->num_range_markers()) {
58                 ActionManager::set_sensitive (ActionManager::range_sensitive_actions, true);
59         } else {
60                 ActionManager::set_sensitive (ActionManager::range_sensitive_actions, false);
61         }
62
63         /* there are never any selections on startup */
64
65         ActionManager::set_sensitive (ActionManager::region_selection_sensitive_actions, false);
66         ActionManager::set_sensitive (ActionManager::time_selection_sensitive_actions, false);
67         ActionManager::set_sensitive (ActionManager::track_selection_sensitive_actions, false);
68         ActionManager::set_sensitive (ActionManager::line_selection_sensitive_actions, false);
69         ActionManager::set_sensitive (ActionManager::point_selection_sensitive_actions, false);
70         ActionManager::set_sensitive (ActionManager::playlist_selection_sensitive_actions, false);
71
72         session->locations()->added.connect (mem_fun (*this, &ARDOUR_UI::handle_locations_change));
73         session->locations()->removed.connect (mem_fun (*this, &ARDOUR_UI::handle_locations_change));
74
75         rec_button.set_sensitive (true);
76         shuttle_box.set_sensitive (true);
77         
78         if (session->n_diskstreams() == 0) {
79                 session->DiskStreamAdded.connect (mem_fun(*this, &ARDOUR_UI::diskstream_added));
80         }
81
82         if (connection_editor) {
83                 connection_editor->set_session (s);
84         }
85
86         if (location_ui) {
87                 location_ui->set_session(s);
88         }
89
90         if (route_params) {
91                 route_params->set_session (s);
92         }
93
94         if (option_editor) {
95                 option_editor->set_session (s);
96         }
97
98         if (sfdb) {
99                 sfdb->set_session (s);
100         }
101
102         setup_session_options ();
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
114         /* alert the user to these things happening */
115
116         session->AuditionActive.connect (mem_fun(*this, &ARDOUR_UI::auditioning_changed));
117         session->SoloActive.connect (mem_fun(*this, &ARDOUR_UI::soloing_changed));
118
119         solo_alert_button.set_active (session->soloing());
120
121         /* can't be auditioning here */
122
123         primary_clock.set_session (s);
124         secondary_clock.set_session (s);
125         big_clock.set_session (s);
126         preroll_clock.set_session (s);
127         postroll_clock.set_session (s);
128
129         /* Clocks are on by default after we are connected to a session, so show that here.
130         */
131         
132         connect_dependents_to_session (s);
133
134         start_clocking ();
135         start_blinking ();
136
137         if (editor) {
138                 editor->present();
139         }
140
141         transport_stopped ();
142
143         second_connection = Glib::signal_timeout().connect (mem_fun(*this, &ARDOUR_UI::every_second), 1000);
144         point_one_second_connection = Glib::signal_timeout().connect (mem_fun(*this, &ARDOUR_UI::every_point_one_seconds), 100);
145         point_zero_one_second_connection = Glib::signal_timeout().connect (mem_fun(*this, &ARDOUR_UI::every_point_zero_one_seconds), 40);
146 }
147
148 int
149 ARDOUR_UI::unload_session ()
150 {
151         if (session && session->dirty()) {
152                 switch (ask_about_saving_session (_("close"))) {
153                 case -1:
154                         return 1;
155                         
156                 case 1:
157                         session->save_state ("");
158                         break;
159                 }
160         }
161         editor->hide ();
162         second_connection.disconnect ();
163         point_one_second_connection.disconnect ();
164         point_zero_one_second_connection.disconnect();
165
166         ActionManager::set_sensitive (ActionManager::session_sensitive_actions, false);
167         
168         rec_button.set_sensitive (false);
169         shuttle_box.set_sensitive (false);
170
171         stop_blinking ();
172         stop_clocking ();
173
174         /* drop everything attached to the blink signal */
175
176         Blink.clear ();
177
178         primary_clock.set_session (0);
179         secondary_clock.set_session (0);
180         big_clock.set_session (0);
181         preroll_clock.set_session (0);
182         postroll_clock.set_session (0);
183
184         if (option_editor) {
185                 option_editor->set_session (0);
186         }
187
188         if (mixer) {
189                 mixer->hide_all ();
190         }
191
192         delete session;
193         session = 0;
194
195         update_buffer_load ();
196
197         return 0;
198 }
199
200 int
201 ARDOUR_UI::create_connection_editor ()
202 {
203 #if 0
204         if (connection_editor == 0) {
205                 connection_editor = new ConnectionEditor ();
206                 connection_editor->signal_unmap().connect (sigc::bind (ptr_fun(&ActionManager::uncheck_toggleaction), X_("<Actions>/Common/ToggleConnections")));
207         }
208
209         if (session) {
210                 connection_editor->set_session (session);
211         }
212 #endif
213
214         return 0;
215 }
216
217 void
218 ARDOUR_UI::toggle_connection_editor ()
219 {
220         if (create_connection_editor()) {
221                 return;
222         }
223
224 #if 0
225         RefPtr<Action> act = ActionManager::get_action (X_("Common"), X_("ToggleConnections"));
226         if (act) {
227                 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
228         
229                 if (tact->get_active()) {
230                         connection_editor->show_all ();
231                         connection_editor->present ();
232                 } else {
233                         connection_editor->hide ();
234                 } 
235         }
236 #endif
237 }
238
239 void
240 ARDOUR_UI::toggle_big_clock_window ()
241 {
242         RefPtr<Action> act = ActionManager::get_action (X_("Common"), X_("ToggleBigClock"));
243         if (act) {
244                 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
245         
246                 if (tact->get_active()) {
247                         big_clock_window->show_all ();
248                         big_clock_window->present ();
249                 } else {
250                         big_clock_window->hide ();
251                 } 
252         }
253 }
254
255 void
256 ARDOUR_UI::toggle_options_window ()
257 {
258         if (option_editor == 0) {
259                 option_editor = new OptionEditor (*this, *editor, *mixer);
260                 option_editor->signal_unmap().connect(sigc::bind (sigc::ptr_fun(&ActionManager::uncheck_toggleaction), X_("<Actions>/Common/ToggleOptionsEditor")));
261                 option_editor->set_session (session);
262         } 
263
264         RefPtr<Action> act = ActionManager::get_action (X_("Common"), X_("ToggleOptionsEditor"));
265         if (act) {
266                 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
267         
268                 if (tact->get_active()) {
269                         option_editor->show_all ();
270                         option_editor->present ();
271                 } else {
272                         option_editor->hide ();
273                 } 
274         }
275 }
276
277 int
278 ARDOUR_UI::create_location_ui ()
279 {
280         if (location_ui == 0) {
281                 location_ui = new LocationUI ();
282                 location_ui->set_session (session);
283                 location_ui->signal_unmap().connect (sigc::bind (sigc::ptr_fun(&ActionManager::uncheck_toggleaction), X_("<Actions>/Common/ToggleLocations")));
284         }
285         return 0;
286 }
287
288 void
289 ARDOUR_UI::toggle_location_window ()
290 {
291         if (create_location_ui()) {
292                 return;
293         }
294
295         RefPtr<Action> act = ActionManager::get_action (X_("Common"), X_("ToggleLocations"));
296         if (act) {
297                 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
298         
299                 if (tact->get_active()) {
300                         location_ui->show_all ();
301                         location_ui->present ();
302                 } else {
303                         location_ui->hide ();
304                 } 
305         }
306 }
307
308 void
309 ARDOUR_UI::toggle_color_manager ()
310 {
311         RefPtr<Action> act = ActionManager::get_action (X_("Common"), X_("ToggleColorManager"));
312         if (act) {
313                 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
314         
315                 if (tact->get_active()) {
316                         color_manager->show_all ();
317                         color_manager->present ();
318                 } else {
319                         color_manager->hide ();
320                 } 
321         }
322 }
323
324 int
325 ARDOUR_UI::create_route_params ()
326 {
327         if (route_params == 0) {
328                 route_params = new RouteParams_UI (*engine);
329                 route_params->set_session (session);
330                 route_params->signal_unmap().connect (sigc::bind(sigc::ptr_fun(&ActionManager::uncheck_toggleaction), X_("<Actions>/Common/ToggleInspector")));
331         }
332         return 0;
333 }
334
335 void
336 ARDOUR_UI::toggle_route_params_window ()
337 {
338         if (create_route_params ()) {
339                 return;
340         }
341
342         RefPtr<Action> act = ActionManager::get_action (X_("Common"), X_("ToggleInspector"));
343         if (act) {
344                 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
345         
346                 if (tact->get_active()) {
347                         route_params->show_all ();
348                         route_params->present ();
349                 } else {
350                         route_params->hide ();
351                 } 
352         }
353 }
354
355 int
356 ARDOUR_UI::create_sound_file_browser ()
357 {
358         if (sfdb == 0) {
359                 sfdb = new SoundFileBrowser (_("Sound File Browser"), session);
360                 sfdb->signal_unmap().connect (sigc::bind(sigc::ptr_fun(&ActionManager::uncheck_toggleaction), X_("<Actions>/Common/ToggleSoundFileBrowser")));
361         }
362         return 0;
363 }
364         
365 void
366 ARDOUR_UI::toggle_sound_file_browser ()
367 {
368         if (create_sound_file_browser()) {
369                 return;
370         }
371
372         RefPtr<Action> act = ActionManager::get_action (X_("Common"), X_("ToggleSoundFileBrowser"));
373         if (act) {
374                 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
375         
376                 if (tact->get_active()) {
377                         sfdb->show_all();
378                         sfdb->present();
379                 } else {
380                         sfdb->hide ();
381                 }
382         }
383 }
384
385 void
386 ARDOUR_UI::handle_locations_change (Location* ignored)
387 {
388         if (session) {
389                 if (session->locations()->num_range_markers()) {
390                         ActionManager::set_sensitive (ActionManager::range_sensitive_actions, true);
391                 } else {
392                         ActionManager::set_sensitive (ActionManager::range_sensitive_actions, false);
393                 }
394         }
395 }