fix rules for optional plugins.
[galan.git] / src / galan.c
blob26f949a99061e061459a81fab9752b663ebccc86
1 /* gAlan - Graphical Audio Language
2 * Copyright (C) 1999 Tony Garnock-Jones
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.
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.
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #include <stdlib.h>
20 #include <stdio.h>
21 #include <string.h>
23 #include <gdk/gdk.h>
24 #include <gtk/gtk.h>
25 #include <glib.h>
27 #include "global.h"
28 #include "generator.h"
29 #include "plugin.h"
30 #include "gui.h"
31 #include "comp.h"
32 #include "gencomp.h"
33 #include "iscomp.h"
34 #include "cocomp.h"
35 #include "sheet.h"
36 #include "shcomp.h"
37 #include "control.h"
38 #include "prefs.h"
39 #include "galan_jack.h"
40 #include "galan_lash.h"
42 //PRIVATE GStaticMutex malloc_mutex = G_STATIC_MUTEX_INIT;
43 PUBLIC GThread *main_thread;
45 PUBLIC char *safe_string_dup(const char *str) {
46 char *n;
48 if (str == NULL)
49 return NULL;
51 n = safe_malloc(strlen(str) + 1);
52 strcpy(n, str);
53 return n;
56 PUBLIC void *safe_malloc(size_t size) {
57 void *result;
59 //g_static_mutex_lock( &malloc_mutex );
61 result = malloc(size);
63 //printf( "malloc size = %d\n", size );
64 //printf( "malloc\n" );
65 //g_static_mutex_unlock( &malloc_mutex );
68 if (result == NULL)
69 g_error("Out of memory mallocing %d bytes...", (int) size);
71 return result;
74 PUBLIC void *safe_calloc(int nelems, size_t size) {
75 void *result;
77 //g_static_mutex_lock( &malloc_mutex );
79 result = calloc(nelems, size);
81 //g_static_mutex_unlock( &malloc_mutex );
84 if (result == NULL)
85 g_error("Out of memory callocing %d bytes...", (int) size);
87 return result;
90 PUBLIC void *safe_realloc( gpointer mem, gsize nbytes ) {
92 void *result;
94 //g_static_mutex_lock( &malloc_mutex );
96 result = realloc(mem, nbytes);
98 //g_static_mutex_unlock( &malloc_mutex );
100 return result;
103 PUBLIC void safe_free( void *ptr ) {
104 //g_static_mutex_lock( &malloc_mutex );
106 free(ptr);
108 //g_static_mutex_unlock( &malloc_mutex );
111 PUBLIC void lock_malloc_lock( void ) {
112 //g_static_mutex_lock( &malloc_mutex );
115 PUBLIC void unlock_malloc_lock( void ) {
116 //g_static_mutex_unlock( &malloc_mutex );
119 /* Called by main() in main.c */
120 PUBLIC int galan_main(int argc, char *argv[]) {
122 //GMemVTable vtable = { safe_malloc, safe_realloc, safe_free, NULL, NULL, NULL };
123 //g_mem_set_vtable( &vtable );
124 g_thread_init(NULL);
126 gdk_threads_init();
127 gdk_threads_enter();
128 main_thread = g_thread_self();
129 gtk_set_locale();
130 gtk_init(&argc, &argv);
131 gdk_rgb_init();
133 gtk_rc_parse_string( "style \"trans\" { bg_pixmap[NORMAL] = \"<parent>\" } \nwidget \"control_panel.GtkNotebook.GtkScrolledWindow.GtkLayout.*\" style \"trans\" " );
135 init_jack();
136 init_lash( argc, argv );
137 init_generator();
138 init_event();
139 init_clock();
140 init_control();
141 init_gui();
142 init_comp();
143 init_gencomp();
144 init_iscomp();
145 init_cocomp();
146 init_shcomp();
147 init_prefs();
148 init_objectstore();
149 init_plugins();
151 run_jack();
153 //gui_add_comps();
155 init_generator_thread();
156 init_control_thread();
158 if( argc > 1 )
159 if( ! g_path_is_absolute( argv[1] ) ) {
160 char *cwd = g_get_current_dir();
161 char *absname = g_build_filename( cwd, argv[1], NULL );
162 load_sheet_from_name( absname );
163 free( absname );
164 free( cwd );
165 } else
166 load_sheet_from_name( argv[1] );
167 else {
168 Sheet *s = create_sheet();
169 s->control_panel = control_panel_new( s->name, TRUE, s );
170 gui_register_sheet( s );
175 gtk_main();
176 gdk_threads_leave();
178 done_objectstore();
179 done_prefs();
180 done_shcomp();
181 done_iscomp();
182 done_cocomp();
183 done_gencomp();
184 done_comp();
185 done_gui();
186 done_clock();
187 done_generator();
188 done_lash();
189 done_jack();
191 return EXIT_SUCCESS;