| 1 |
/* |
|---|
| 2 |
* Sweep, a sound wave editor. |
|---|
| 3 |
* |
|---|
| 4 |
* Copyright (C) 2000 Conrad Parker |
|---|
| 5 |
* |
|---|
| 6 |
* This program is free software; you can redistribute it and/or modify |
|---|
| 7 |
* it under the terms of the GNU General Public License as published by |
|---|
| 8 |
* the Free Software Foundation; either version 2 of the License, or |
|---|
| 9 |
* (at your option) any later version. |
|---|
| 10 |
* |
|---|
| 11 |
* This program is distributed in the hope that it will be useful, |
|---|
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 14 |
* GNU General Public License for more details. |
|---|
| 15 |
* |
|---|
| 16 |
* You should have received a copy of the GNU General Public License |
|---|
| 17 |
* along with this program; if not, write to the Free Software |
|---|
| 18 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|---|
| 19 |
*/ |
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
#ifdef HAVE_CONFIG_H |
|---|
| 23 |
# include <config.h> |
|---|
| 24 |
#endif |
|---|
| 25 |
|
|---|
| 26 |
#include <stdlib.h> |
|---|
| 27 |
#include <string.h> |
|---|
| 28 |
#include <time.h> |
|---|
| 29 |
|
|---|
| 30 |
#include <X11/Xlib.h> |
|---|
| 31 |
|
|---|
| 32 |
#include <glib.h> |
|---|
| 33 |
#include <gtk/gtk.h> |
|---|
| 34 |
|
|---|
| 35 |
#include <sweep/sweep_version.h> |
|---|
| 36 |
#include <sweep/sweep_i18n.h> |
|---|
| 37 |
#include <sweep/sweep_types.h> |
|---|
| 38 |
|
|---|
| 39 |
#include "preferences.h" |
|---|
| 40 |
#include "file_dialogs.h" |
|---|
| 41 |
#include "interface.h" |
|---|
| 42 |
#include "plugin.h" |
|---|
| 43 |
#include "cursors.h" |
|---|
| 44 |
#include "driver.h" |
|---|
| 45 |
#include "callbacks.h" |
|---|
| 46 |
#include "question_dialogs.h" |
|---|
| 47 |
#include "play.h" |
|---|
| 48 |
|
|---|
| 49 |
extern void sweep_timeouts_init (void); |
|---|
| 50 |
extern gboolean ignore_failed_tdb_lock; |
|---|
| 51 |
/* |
|---|
| 52 |
* initial_sample_load () |
|---|
| 53 |
* |
|---|
| 54 |
* a gtk_idle one-shot function. |
|---|
| 55 |
* |
|---|
| 56 |
* the initial loading of samples is deferred |
|---|
| 57 |
* to be processed by gtk_main, to allow the |
|---|
| 58 |
* toolbox window to be shown before having to |
|---|
| 59 |
* wait for potentially large samples to load. |
|---|
| 60 |
*/ |
|---|
| 61 |
static gint |
|---|
| 62 |
initial_sample_load (gpointer data) |
|---|
| 63 |
{ |
|---|
| 64 |
char * arg = (char *)data; |
|---|
| 65 |
gchar * pathname; |
|---|
| 66 |
|
|---|
| 67 |
if (!strncmp (g_dirname (arg), ".", 1)) { |
|---|
| 68 |
pathname = g_strdup_printf ("%s/%s", g_get_current_dir(), arg); |
|---|
| 69 |
} else { |
|---|
| 70 |
pathname = arg; |
|---|
| 71 |
} |
|---|
| 72 |
|
|---|
| 73 |
sample_load (pathname); |
|---|
| 74 |
|
|---|
| 75 |
return FALSE; |
|---|
| 76 |
} |
|---|
| 77 |
|
|---|
| 78 |
static gint |
|---|
| 79 |
initial_sample_ask (gpointer data) |
|---|
| 80 |
{ |
|---|
| 81 |
question_dialog_new (NULL, _("Welcome to Sweep"), |
|---|
| 82 |
_("Hello, my name is Scrubby. " |
|---|
| 83 |
"Welcome to Sweep!\n\n" |
|---|
| 84 |
"Would you like to create a new file or " |
|---|
| 85 |
"load an existing file?"), |
|---|
| 86 |
_("Create new file"), _("Load existing file"), |
|---|
| 87 |
G_CALLBACK (sample_new_empty_cb), NULL, G_CALLBACK (sample_load_cb), NULL, 0); |
|---|
| 88 |
|
|---|
| 89 |
return FALSE; |
|---|
| 90 |
} |
|---|
| 91 |
|
|---|
| 92 |
/* |
|---|
| 93 |
* main |
|---|
| 94 |
*/ |
|---|
| 95 |
int |
|---|
| 96 |
main (int argc, char *argv[]) |
|---|
| 97 |
{ |
|---|
| 98 |
int i; |
|---|
| 99 |
|
|---|
| 100 |
gboolean show_version = FALSE; |
|---|
| 101 |
gboolean show_help = FALSE; |
|---|
| 102 |
/* gboolean show_toolbox = TRUE;*/ |
|---|
| 103 |
|
|---|
| 104 |
gboolean no_files = TRUE; |
|---|
| 105 |
|
|---|
| 106 |
#ifdef HAVE_PUTENV |
|---|
| 107 |
gchar *display_env; |
|---|
| 108 |
#endif |
|---|
| 109 |
|
|---|
| 110 |
#ifdef ENABLE_NLS |
|---|
| 111 |
bindtextdomain (PACKAGE, PACKAGE_LOCALE_DIR); |
|---|
| 112 |
textdomain (PACKAGE); |
|---|
| 113 |
#endif |
|---|
| 114 |
|
|---|
| 115 |
gtk_set_locale (); |
|---|
| 116 |
|
|---|
| 117 |
#ifdef DEVEL_CODE |
|---|
| 118 |
g_print (_("WARNING: Build includes incomplete development code.\n")); |
|---|
| 119 |
#endif |
|---|
| 120 |
|
|---|
| 121 |
XInitThreads (); |
|---|
| 122 |
|
|---|
| 123 |
gtk_init (&argc, &argv); |
|---|
| 124 |
|
|---|
| 125 |
#ifdef HAVE_PUTENV |
|---|
| 126 |
display_env = g_strconcat ("DISPLAY=", gdk_get_display (), NULL); |
|---|
| 127 |
putenv (display_env); |
|---|
| 128 |
#endif |
|---|
| 129 |
|
|---|
| 130 |
g_thread_init (NULL); |
|---|
| 131 |
|
|---|
| 132 |
|
|---|
| 133 |
|
|---|
| 134 |
/* must be done before g_idle_add / g_timeout_add */ |
|---|
| 135 |
sweep_timeouts_init (); |
|---|
| 136 |
|
|---|
| 137 |
for(i = 1; i < argc; i++) { |
|---|
| 138 |
if ((strcmp (argv[i], "--help") == 0) || |
|---|
| 139 |
(strcmp (argv[i], "-h") == 0)) { |
|---|
| 140 |
show_help = TRUE; |
|---|
| 141 |
argv[i] = NULL; |
|---|
| 142 |
} else if ((strcmp (argv[i], "--version") == 0) || |
|---|
| 143 |
(strcmp (argv[i], "-v") == 0)) { |
|---|
| 144 |
show_version = TRUE; |
|---|
| 145 |
argv[i] = NULL; |
|---|
| 146 |
} else if ((strcmp (argv[i], "--ignore-failed-lock") == 0)) { |
|---|
| 147 |
ignore_failed_tdb_lock = TRUE; |
|---|
| 148 |
argv[i] = NULL; |
|---|
| 149 |
|
|---|
| 150 |
#ifdef DEVEL_CODE |
|---|
| 151 |
} else if (argv[i][0] == '-' && argv[i][1] != '\0') { |
|---|
| 152 |
/* check for unknown options, but allow "-" as stdin */ |
|---|
| 153 |
#else |
|---|
| 154 |
} else if (argv[i][0] == '-') { |
|---|
| 155 |
/* check for unknown options */ |
|---|
| 156 |
#endif |
|---|
| 157 |
show_help = TRUE; |
|---|
| 158 |
} else { |
|---|
| 159 |
g_idle_add ((GSourceFunc) initial_sample_load, argv[i]); |
|---|
| 160 |
no_files = FALSE; |
|---|
| 161 |
} |
|---|
| 162 |
} |
|---|
| 163 |
|
|---|
| 164 |
if (show_version) { |
|---|
| 165 |
g_print ( "%s %s\n", _("Sweep version"), VERSION); |
|---|
| 166 |
g_print ( "%s %d.%d.%d\n",_("Sweep plugin API version"), |
|---|
| 167 |
SWEEP_PLUGIN_API_MAJOR, SWEEP_PLUGIN_API_MINOR, |
|---|
| 168 |
SWEEP_PLUGIN_API_REVISION); |
|---|
| 169 |
} |
|---|
| 170 |
|
|---|
| 171 |
if (show_help) { |
|---|
| 172 |
g_print (_("Usage: %s [option ...] [files ...]\n"), argv[0]); |
|---|
| 173 |
g_print (_("Valid options are:\n")); |
|---|
| 174 |
g_print (_(" -h --help Output this help.\n")); |
|---|
| 175 |
g_print (_(" -v --version Output version info.\n")); |
|---|
| 176 |
g_print (_(" --display <display> Use the designated X display.\n")); |
|---|
| 177 |
g_print (_(" --ignore-failed-lock Continue when attempt to lock the\n" |
|---|
| 178 |
" preferences file fails. For use when\n" |
|---|
| 179 |
" the users home directory is on an NFS\n" |
|---|
| 180 |
" file system. (possibly unsafe) \n" )); |
|---|
| 181 |
|
|---|
| 182 |
} |
|---|
| 183 |
|
|---|
| 184 |
if (show_version || show_help) { |
|---|
| 185 |
exit (0); |
|---|
| 186 |
} |
|---|
| 187 |
|
|---|
| 188 |
srandom ((unsigned int)time(NULL)); |
|---|
| 189 |
|
|---|
| 190 |
|
|---|
| 191 |
if (no_files) { |
|---|
| 192 |
g_idle_add ((GSourceFunc)initial_sample_ask, NULL); |
|---|
| 193 |
} |
|---|
| 194 |
|
|---|
| 195 |
/* initialise preferences */ |
|---|
| 196 |
prefs_init (); |
|---|
| 197 |
|
|---|
| 198 |
/* initialise plugins */ |
|---|
| 199 |
init_plugins (); |
|---|
| 200 |
|
|---|
| 201 |
/* initialise cursors */ |
|---|
| 202 |
init_cursors (); |
|---|
| 203 |
|
|---|
| 204 |
/* initialise interface components */ |
|---|
| 205 |
init_ui (); |
|---|
| 206 |
|
|---|
| 207 |
/* initialise devices */ |
|---|
| 208 |
init_devices (); |
|---|
| 209 |
|
|---|
| 210 |
/* init playback subsystem */ |
|---|
| 211 |
init_playback (); |
|---|
| 212 |
|
|---|
| 213 |
|
|---|
| 214 |
gtk_main (); |
|---|
| 215 |
|
|---|
| 216 |
|
|---|
| 217 |
/* close preferences database */ |
|---|
| 218 |
prefs_close (); |
|---|
| 219 |
|
|---|
| 220 |
/* save key bindings */ |
|---|
| 221 |
save_accels (); |
|---|
| 222 |
|
|---|
| 223 |
/* initialise plugins */ |
|---|
| 224 |
release_plugins (); |
|---|
| 225 |
|
|---|
| 226 |
exit (0); |
|---|
| 227 |
} |
|---|