opaque xfade patch + a version of the editor ruler/playhead/click patch
[ardour.git] / gtk2_ardour / main.cc
1 /*
2     Copyright (C) 2001-2007 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 #include <cstdlib>
21
22 #include <sigc++/bind.h>
23 #include <gtkmm/settings.h>
24 #include <glibmm/ustring.h>
25
26 #include <pbd/error.h>
27 #include <pbd/textreceiver.h>
28 #include <pbd/failed_constructor.h>
29 #include <pbd/pthread_utils.h>
30
31 #include <jack/jack.h>
32
33 #include <ardour/version.h>
34 #include <ardour/ardour.h>
35 #include <ardour/audioengine.h>
36
37 #include <gtkmm/main.h>
38 #include <gtkmm2ext/popup.h>
39 #include <gtkmm2ext/utils.h>
40
41 #include "svn_revision.h"
42 #include "version.h"
43 #include "ardour_ui.h"
44 #include "opts.h"
45 #include "enums.h"
46
47 #include "i18n.h"
48
49 using namespace Gtk;
50 using namespace ARDOUR_COMMAND_LINE;
51 using namespace ARDOUR;
52 using namespace PBD;
53 using namespace sigc;
54
55 TextReceiver text_receiver ("ardour");
56
57 extern int curvetest (string);
58
59 static ARDOUR_UI  *ui = 0;
60 static char* localedir = LOCALEDIR;
61
62 gint
63 show_ui_callback (void *arg)
64 {
65         ARDOUR_UI * ui = (ARDOUR_UI *) arg;
66
67         ui->hide_splash();
68         
69         return FALSE;
70 }
71
72 #ifdef __APPLE__
73
74 #include <mach-o/dyld.h>
75 #include <sys/param.h>
76 #include <fstream>
77
78 void
79 fixup_bundle_environment ()
80 {
81         char execpath[MAXPATHLEN+1];
82         uint32_t pathsz = sizeof (execpath);
83
84         _NSGetExecutablePath (execpath, &pathsz);
85
86         Glib::ustring exec_path (execpath);
87         Glib::ustring dir_path = Glib::path_get_dirname (exec_path);
88         Glib::ustring path;
89
90         path = dir_path;
91         path += "/../Resources";
92         path += dir_path;
93         path += "/../Resources/Surfaces";
94         path += dir_path;
95         path += "/../Resources/Panners";
96
97         setenv ("ARDOUR_MODULE_PATH", path.c_str(), 1);
98
99         path = dir_path;
100         path += "/../Resources/icons:";
101         path += dir_path;
102         path += "/../Resources/pixmaps:";
103         path += dir_path;
104         path += "/../Resources/share:";
105         path += dir_path;
106         path += "/../Resources";
107
108         setenv ("ARDOUR_PATH", path.c_str(), 1);
109         setenv ("ARDOUR_CONFIG_PATH", path.c_str(), 1);
110         setenv ("ARDOUR_DATA_PATH", path.c_str(), 1);
111
112         path = dir_path;
113         path += "/../Frameworks/clearlooks";
114
115         setenv ("GTK_PATH", path.c_str(), 1);
116
117         path = dir_path;
118         path += "/../Resources/locale";
119         
120         localedir = strdup (path.c_str());
121
122         /* write a pango.rc file and tell pango to use it */
123
124         path = dir_path;
125         path += "/../Resources/pango.rc";
126
127         std::ofstream pangorc (path.c_str());
128         if (!pangorc) {
129                 error << string_compose (_("cannot open pango.rc file %1") , path) << endmsg;
130         } else {
131                 pangorc << "[Pango]\nModuleFiles=";
132                 Glib::ustring mpath = dir_path;
133                 mpath += "/../Resources/pango.modules";
134                 pangorc << mpath << endl;
135                 
136                 pangorc.close ();
137                 setenv ("PANGO_RC_FILE", path.c_str(), 1);
138         }
139
140         // gettext charset aliases
141
142         setenv ("CHARSETALIASDIR", path.c_str(), 1);
143
144         // font config
145         
146         path = dir_path;
147         path += "/../Resources/fonts.conf";
148
149         setenv ("FONTCONFIG_FILE", path.c_str(), 1);
150
151         // GDK Pixbuf loader module file
152
153         path = dir_path;
154         path += "/../Resources/gdk-pixbuf.loaders";
155
156         setenv ("GDK_PIXBUF_MODULE_FILE", path.c_str(), 1);
157
158         if (getenv ("ARDOUR_WITH_JACK")) {
159                 // JACK driver dir
160                 
161                 path = dir_path;
162                 path += "/../Frameworks";
163                 
164                 setenv ("JACK_DRIVER_DIR", path.c_str(), 1);
165         }
166 }
167 #endif
168
169 #ifdef VST_SUPPORT
170 /* this is called from the entry point of a wine-compiled
171    executable that is linked against gtk2_ardour built
172    as a shared library.
173 */
174 extern "C" {
175 int ardour_main (int argc, char *argv[])
176 #else
177 int main (int argc, char* argv[])
178 #endif
179 {
180         vector<Glib::ustring> null_file_list;
181
182 #ifdef __APPLE__
183         fixup_bundle_environment ();
184 #endif
185
186         Glib::thread_init();
187         gtk_set_locale ();
188
189         (void) bindtextdomain (PACKAGE, localedir);
190         /* our i18n translations are all in UTF-8, so make sure
191            that even if the user locale doesn't specify UTF-8,
192            we use that when handling them.
193         */
194         (void) bind_textdomain_codeset (PACKAGE,"UTF-8");
195         (void) textdomain (PACKAGE);
196
197         pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS, 0);
198
199         // catch error message system signals ();
200
201         text_receiver.listen_to (error);
202         text_receiver.listen_to (info);
203         text_receiver.listen_to (fatal);
204         text_receiver.listen_to (warning);
205
206         if (parse_opts (argc, argv)) {
207                 exit (1);
208         }
209
210         if (curvetest_file) {
211                 return curvetest (curvetest_file);
212         }
213         
214         cout << _("Ardour/GTK ") 
215              << VERSIONSTRING
216              << _("\n   (built using ")
217              << ardour_svn_revision
218 #ifdef __GNUC__
219              << _(" and GCC version ") << __VERSION__ 
220 #endif
221              << ')'
222              << endl;
223         
224         if (just_version) {
225                 exit (0);
226         }
227
228         if (no_splash) {
229                 cerr << _("Copyright (C) 1999-2007 Paul Davis") << endl
230                      << _("Some portions Copyright (C) Steve Harris, Ari Johnson, Brett Viren, Joel Baker") << endl
231                      << endl
232                      << _("Ardour comes with ABSOLUTELY NO WARRANTY") << endl
233                      << _("not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.") << endl
234                      << _("This is free software, and you are welcome to redistribute it ") << endl
235                      << _("under certain conditions; see the source for copying conditions.")
236                      << endl;
237         }
238
239         /* some GUI objects need this */
240
241         PBD::ID::init ();
242
243         try { 
244                 ui = new ARDOUR_UI (&argc, &argv);
245         } catch (failed_constructor& err) {
246                 error << _("could not create ARDOUR GUI") << endmsg;
247                 exit (1);
248         }
249
250         if (!no_splash) {
251                 ui->show_splash ();
252                 if (session_name.length()) {  
253                         g_timeout_add (4000, show_ui_callback, ui);
254                 }
255         }
256
257         if (!keybindings_path.empty()) {
258                 ui->set_keybindings_path (keybindings_path);
259         }
260
261         ui->run (text_receiver);
262         ui = 0;
263
264         ARDOUR::cleanup ();
265         pthread_cancel_all ();
266         return 0;
267 }
268 #ifdef VST_SUPPORT
269 } // end of extern C block
270 #endif
271