Fix various crashes on session close.
[ardour.git] / gtk2_ardour / ardour_ui_dependents.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 exists solely to break compilation dependencies that
21    would connect changes to the mixer or editor objects.
22 */
23
24 #include <cstdio>
25
26 #include "pbd/error.h"
27
28 #include "ardour/session.h"
29
30 #include "ardour_ui.h"
31 #include "public_editor.h"
32 #include "mixer_ui.h"
33 #include "keyboard.h"
34 #include "splash.h"
35 #include "route_params_ui.h"
36 #include "opts.h"
37 #include "i18n.h"
38
39 using namespace sigc;
40 using namespace Gtk;
41 using namespace PBD;
42
43 namespace ARDOUR {
44         class Session;
45         class Route;
46 }
47
48 using namespace ARDOUR;
49
50 void
51 ARDOUR_UI::shutdown ()
52 {
53         ui_config->save_state();
54 }
55
56 void
57 ARDOUR_UI::we_have_dependents ()
58 {
59         install_actions ();
60         ProcessorBox::register_actions ();
61
62         Keyboard::setup_keybindings ();
63
64         editor->UpdateAllTransportClocks.connect (mem_fun (*this, &ARDOUR_UI::update_transport_clocks));
65 }
66
67 void
68 ARDOUR_UI::connect_dependents_to_session (ARDOUR::Session *s)
69 {
70         BootMessage (_("Setup Editor"));
71         editor->connect_to_session (s);
72         BootMessage (_("Setup Mixer"));
73         mixer->connect_to_session (s);
74
75         /* its safe to do this now */
76
77         BootMessage (_("Reload Session History"));
78         s->restore_history ("");
79 }
80
81 static bool
82 _hide_splash (gpointer arg)
83 {
84         ((ARDOUR_UI*)arg)->hide_splash();
85         return false;
86 }
87
88 void
89 ARDOUR_UI::goto_editor_window ()
90 {
91         if (splash && splash->is_visible()) {
92                 // in 2 seconds, hide the splash screen
93                 Glib::signal_timeout().connect (bind (sigc::ptr_fun (_hide_splash), this), 2000);
94         }
95
96         editor->show_window ();
97         editor->present ();
98         _mixer_on_top = false;
99         flush_pending ();
100 }
101
102 void
103 ARDOUR_UI::goto_mixer_window ()
104 {
105         mixer->show_window ();
106         mixer->present ();
107         _mixer_on_top = true;
108         flush_pending ();
109 }
110
111 void
112 ARDOUR_UI::toggle_editor_mixer_on_top ()
113 {
114         if (_mixer_on_top) {
115                 goto_editor_window ();
116         } else {
117                 goto_mixer_window ();
118         }
119 }
120
121 /** The main editor window has been closed */
122 gint
123 ARDOUR_UI::exit_on_main_window_close (GdkEventAny * /*ev*/)
124 {
125 #ifdef TOP_MENUBAR
126         /* just hide the window, and return - the top menu stays up */
127         editor->hide ();
128         return TRUE;
129 #else
130         /* time to get out of here */
131         finish();
132         return TRUE;
133 #endif
134 }