finish commit from yesterday ... sorry folks
[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 "location_ui.h"
31 #include "mixer_ui.h"
32 #include "rc_option_editor.h"
33 #include "session_option_editor.h"
34 #include "public_editor.h"
35 #include "route_params_ui.h"
36 #include "sfdb_ui.h"
37 #include "theme_manager.h"
38 #include "bundle_manager.h"
39 #include "keyeditor.h"
40 #include "gui_thread.h"
41
42 #include "i18n.h"
43
44 using namespace ARDOUR;
45 using namespace PBD;
46 using namespace Glib;
47 using namespace Gtk;
48 using namespace Gtkmm2ext;
49
50 void
51 ARDOUR_UI::set_session (Session *s)
52 {
53         SessionHandlePtr::set_session (s);
54
55         if (!_session) {
56                 return;
57         }
58
59         if (location_ui) {
60                 location_ui->set_session(s);
61         }
62
63         if (route_params) {
64                 route_params->set_session (s);
65         }
66
67         primary_clock.set_session (s);
68         secondary_clock.set_session (s);
69         big_clock.set_session (s);
70         preroll_clock.set_session (s);
71         postroll_clock.set_session (s);
72         
73         /* sensitize menu bar options that are now valid */
74
75         ActionManager::set_sensitive (ActionManager::session_sensitive_actions, true);
76         ActionManager::set_sensitive (ActionManager::write_sensitive_actions, _session->writable());
77
78         if (_session->locations()->num_range_markers()) {
79                 ActionManager::set_sensitive (ActionManager::range_sensitive_actions, true);
80         } else {
81                 ActionManager::set_sensitive (ActionManager::range_sensitive_actions, false);
82         }
83
84         if (!_session->monitor_out()) {
85                 Glib::RefPtr<Action> act = ActionManager::get_action (X_("options"), X_("SoloViaBus"));
86                 if (act) {
87                         act->set_sensitive (false);
88                 }
89         }
90
91         /* allow wastebasket flush again */
92
93         Glib::RefPtr<Action> act = ActionManager::get_action (X_("Main"), X_("FlushWastebasket"));
94         if (act) {
95                 act->set_sensitive (true);
96         }
97
98         /* there are never any selections on startup */
99
100         ActionManager::set_sensitive (ActionManager::time_selection_sensitive_actions, false);
101         ActionManager::set_sensitive (ActionManager::track_selection_sensitive_actions, false);
102         ActionManager::set_sensitive (ActionManager::line_selection_sensitive_actions, false);
103         ActionManager::set_sensitive (ActionManager::point_selection_sensitive_actions, false);
104         ActionManager::set_sensitive (ActionManager::playlist_selection_sensitive_actions, false);
105
106         rec_button.set_sensitive (true);
107         shuttle_box.set_sensitive (true);
108         solo_alert_button.set_active (_session->soloing());
109
110         setup_session_options ();
111
112         Blink.connect (sigc::mem_fun(*this, &ARDOUR_UI::transport_rec_enable_blink));
113         Blink.connect (sigc::mem_fun(*this, &ARDOUR_UI::solo_blink));
114         Blink.connect (sigc::mem_fun(*this, &ARDOUR_UI::sync_blink));
115         Blink.connect (sigc::mem_fun(*this, &ARDOUR_UI::audition_blink));
116
117         _session->RecordStateChanged.connect (_session_connections, boost::bind (&ARDOUR_UI::record_state_changed, this), gui_context());
118         _session->TransportStateChange.connect (_session_connections, boost::bind (&ARDOUR_UI::map_transport_state, this), gui_context());
119         _session->DirtyChanged.connect (_session_connections, boost::bind (&ARDOUR_UI::update_autosave, this), gui_context());
120
121         _session->Xrun.connect (_session_connections, ui_bind (&ARDOUR_UI::xrun_handler, this, _1), gui_context());
122         _session->SoloActive.connect (_session_connections, ui_bind (&ARDOUR_UI::soloing_changed, this, _1), gui_context());
123         _session->AuditionActive.connect (_session_connections, ui_bind (&ARDOUR_UI::auditioning_changed, this, _1), gui_context());
124         _session->locations()->added.connect (_session_connections, ui_bind (&ARDOUR_UI::handle_locations_change, this, _1), gui_context());
125         _session->locations()->removed.connect (_session_connections, ui_bind (&ARDOUR_UI::handle_locations_change, this, _1), gui_context());
126
127         /* Clocks are on by default after we are connected to a session, so show that here.
128         */
129
130         connect_dependents_to_session (s);
131
132         /* listen to clock mode changes. don't do this earlier because otherwise as the clocks
133            restore their modes or are explicitly set, we will cause the "new" mode to be saved
134            back to the session XML ("Extra") state.
135          */
136
137         AudioClock::ModeChanged.connect (sigc::mem_fun (*this, &ARDOUR_UI::store_clock_modes));
138
139         Glib::signal_idle().connect (sigc::mem_fun (*this, &ARDOUR_UI::first_idle));
140
141         start_clocking ();
142         start_blinking ();
143
144         map_transport_state ();
145
146         second_connection = Glib::signal_timeout().connect (sigc::mem_fun(*this, &ARDOUR_UI::every_second), 1000);
147         point_one_second_connection = Glib::signal_timeout().connect (sigc::mem_fun(*this, &ARDOUR_UI::every_point_one_seconds), 100);
148         point_zero_one_second_connection = Glib::signal_timeout().connect (sigc::mem_fun(*this, &ARDOUR_UI::every_point_zero_one_seconds), 40);
149 }
150
151 int
152 ARDOUR_UI::unload_session (bool hide_stuff)
153 {
154         if (_session && _session->dirty()) {
155                 switch (ask_about_saving_session (_("close"))) {
156                 case -1:
157                         // cancel
158                         return 1;
159
160                 case 1:
161                         _session->save_state ("");
162                         break;
163                 }
164         }
165
166         if (hide_stuff) {
167                 editor->hide ();
168                 mixer->hide ();
169                 theme_manager->hide ();
170         }
171
172         second_connection.disconnect ();
173         point_one_second_connection.disconnect ();
174         point_oh_five_second_connection.disconnect ();
175         point_zero_one_second_connection.disconnect();
176
177         ActionManager::set_sensitive (ActionManager::session_sensitive_actions, false);
178
179         rec_button.set_sensitive (false);
180         shuttle_box.set_sensitive (false);
181
182         stop_blinking ();
183         stop_clocking ();
184
185         /* drop everything attached to the blink signal */
186
187         Blink.clear ();
188
189         delete _session;
190
191         update_buffer_load ();
192
193         return 0;
194 }
195
196 void
197 ARDOUR_UI::toggle_big_clock_window ()
198 {
199         RefPtr<Action> act = ActionManager::get_action (X_("Common"), X_("ToggleBigClock"));
200         if (act) {
201                 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
202
203                 if (tact->get_active()) {
204                         big_clock_window->show_all ();
205                         big_clock_window->present ();
206                 } else {
207                         big_clock_window->hide ();
208                 }
209         }
210 }
211
212 void
213 ARDOUR_UI::toggle_rc_options_window ()
214 {
215         if (rc_option_editor == 0) {
216                 rc_option_editor = new RCOptionEditor;
217                 rc_option_editor->signal_unmap().connect(sigc::bind (sigc::ptr_fun(&ActionManager::uncheck_toggleaction), X_("<Actions>/Common/ToggleRCOptionsEditor")));
218                 rc_option_editor->set_session (_session);
219         }
220
221         RefPtr<Action> act = ActionManager::get_action (X_("Common"), X_("ToggleRCOptionsEditor"));
222         if (act) {
223                 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
224
225                 if (tact->get_active()) {
226                         rc_option_editor->show_all ();
227                         rc_option_editor->present ();
228                 } else {
229                         rc_option_editor->hide ();
230                 }
231         }
232 }
233
234 void
235 ARDOUR_UI::toggle_session_options_window ()
236 {
237         if (session_option_editor == 0) {
238                 session_option_editor = new SessionOptionEditor (_session);
239                 session_option_editor->signal_unmap().connect(sigc::bind (sigc::ptr_fun(&ActionManager::uncheck_toggleaction), X_("<Actions>/Common/ToggleSessionOptionsEditor")));
240         }
241
242         RefPtr<Action> act = ActionManager::get_action (X_("Common"), X_("ToggleSessionOptionsEditor"));
243         if (act) {
244                 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic (act);
245
246                 if (tact->get_active()) {
247                         session_option_editor->show_all ();
248                         session_option_editor->present ();
249                 } else {
250                         session_option_editor->hide ();
251                 }
252         }
253 }
254
255 int
256 ARDOUR_UI::create_location_ui ()
257 {
258         if (location_ui == 0) {
259                 location_ui = new LocationUIWindow ();
260                 location_ui->set_session (_session);
261                 location_ui->signal_unmap().connect (sigc::bind (sigc::ptr_fun(&ActionManager::uncheck_toggleaction), X_("<Actions>/Common/ToggleLocations")));
262         }
263         return 0;
264 }
265
266 void
267 ARDOUR_UI::toggle_location_window ()
268 {
269         if (create_location_ui()) {
270                 return;
271         }
272
273         RefPtr<Action> act = ActionManager::get_action (X_("Common"), X_("ToggleLocations"));
274         if (act) {
275                 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
276
277                 if (tact->get_active()) {
278                         location_ui->show_all ();
279                         location_ui->present ();
280                 } else {
281                         location_ui->hide ();
282                 }
283         }
284 }
285
286 void
287 ARDOUR_UI::toggle_key_editor ()
288 {
289         if (key_editor == 0) {
290                 key_editor = new KeyEditor;
291                 key_editor->signal_unmap().connect (sigc::bind (sigc::ptr_fun(&ActionManager::uncheck_toggleaction), X_("<Actions>/Common/ToggleKeyEditor")));
292         }
293
294         RefPtr<Action> act = ActionManager::get_action (X_("Common"), X_("ToggleKeyEditor"));
295         if (act) {
296                 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
297
298                 if (tact->get_active()) {
299                         key_editor->show_all ();
300                         key_editor->present ();
301                 } else {
302                         key_editor->hide ();
303                 }
304         }
305 }
306
307 void
308 ARDOUR_UI::toggle_theme_manager ()
309 {
310         RefPtr<Action> act = ActionManager::get_action (X_("Common"), X_("ToggleThemeManager"));
311         if (act) {
312                 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
313
314                 if (tact->get_active()) {
315                         theme_manager->show_all ();
316                         theme_manager->present ();
317                 } else {
318                         theme_manager->hide ();
319                 }
320         }
321 }
322
323 void
324 ARDOUR_UI::create_bundle_manager ()
325 {
326         if (bundle_manager == 0) {
327                 bundle_manager = new BundleManager (_session);
328                 bundle_manager->signal_unmap().connect (sigc::bind (sigc::ptr_fun (&ActionManager::uncheck_toggleaction), X_("<Actions>/Common/ToggleBundleManager")));
329         }
330 }
331
332 void
333 ARDOUR_UI::toggle_bundle_manager ()
334 {
335         create_bundle_manager ();
336
337         RefPtr<Action> act = ActionManager::get_action (X_("Common"), X_("ToggleBundleManager"));
338         if (act) {
339                 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic (act);
340
341                 if (tact->get_active()) {
342                         bundle_manager->show_all ();
343                         bundle_manager->present ();
344                 } else {
345                         bundle_manager->hide ();
346                 }
347         }
348 }
349
350 int
351 ARDOUR_UI::create_route_params ()
352 {
353         if (route_params == 0) {
354                 route_params = new RouteParams_UI ();
355                 route_params->set_session (_session);
356                 route_params->signal_unmap().connect (sigc::bind(sigc::ptr_fun(&ActionManager::uncheck_toggleaction), X_("<Actions>/Common/ToggleInspector")));
357         }
358         return 0;
359 }
360
361 void
362 ARDOUR_UI::toggle_route_params_window ()
363 {
364         if (create_route_params ()) {
365                 return;
366         }
367
368         RefPtr<Action> act = ActionManager::get_action (X_("Common"), X_("ToggleInspector"));
369         if (act) {
370                 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
371
372                 if (tact->get_active()) {
373                         route_params->show_all ();
374                         route_params->present ();
375                 } else {
376                         route_params->hide ();
377                 }
378         }
379 }
380
381 void
382 ARDOUR_UI::handle_locations_change (Location *)
383 {
384         if (_session) {
385                 if (_session->locations()->num_range_markers()) {
386                         ActionManager::set_sensitive (ActionManager::range_sensitive_actions, true);
387                 } else {
388                         ActionManager::set_sensitive (ActionManager::range_sensitive_actions, false);
389                 }
390         }
391 }
392
393 bool
394 ARDOUR_UI::main_window_state_event_handler (GdkEventWindowState* ev, bool window_was_editor)
395 {
396         if (window_was_editor) {
397
398                 if ((ev->changed_mask & GDK_WINDOW_STATE_FULLSCREEN) &&
399                     (ev->new_window_state & GDK_WINDOW_STATE_FULLSCREEN)) {
400                         float_big_clock (editor);
401                 }
402
403         } else {
404
405                 if ((ev->changed_mask & GDK_WINDOW_STATE_FULLSCREEN) &&
406                     (ev->new_window_state & GDK_WINDOW_STATE_FULLSCREEN)) {
407                         float_big_clock (mixer);
408                 }
409         }
410
411         return false;
412 }