~ubuntu-branches/ubuntu/utopic/glame/utopic

« back to all changes in this revision

Viewing changes to src/gui/main.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Kobras
  • Date: 2002-04-09 17:14:12 UTC
  • Revision ID: james.westby@ubuntu.com-20020409171412-jzpnov7mbz2w6zsr
Tags: upstream-0.6.2
ImportĀ upstreamĀ versionĀ 0.6.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * main.c
 
3
 *
 
4
 * $Id: main.c,v 1.97.2.8 2002/03/11 13:02:18 richi Exp $
 
5
 *
 
6
 * Copyright (C) 2001 Johannes Hirche, Richard Guenther
 
7
 *
 
8
 * This program is free software; you can redistribute it and/or modify
 
9
 * it under the terms of the GNU General Public License as published by
 
10
 * the Free Software Foundation; either version 2 of the License, or
 
11
 * (at your option) any later version.
 
12
 *
 
13
 * This program is distributed in the hope that it will be useful,
 
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
 * GNU General Public License for more details.
 
17
 *
 
18
 * You should have received a copy of the GNU General Public License
 
19
 * along with this program; if not, write to the Free Software
 
20
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
21
 *
 
22
 */
 
23
 
 
24
#ifdef HAVE_CONFIG_H
 
25
#include <config.h>
 
26
#endif
 
27
 
 
28
#include <stdlib.h>
 
29
#include <unistd.h>
 
30
#ifdef HAVE_LIBGLADE
 
31
#include <glade/glade.h>
 
32
#endif
 
33
#include <libintl.h>
 
34
#include "swapfile.h"
 
35
#include "glmid.h"
 
36
#include "swapfilegui.h"
 
37
#include "waveeditgui.h"
 
38
#include "timeline/timeline.h"
 
39
#include "edit_filter/filtereditgui.h"
 
40
#include "util/glame_gui_utils.h"
 
41
#include "gltreeitem.h"
 
42
#include "gpsm.h"
 
43
#include "clipboard.h"
 
44
#include "glame_accelerator.h"
 
45
#include "glame_console.h"
 
46
#include "network_utils.h"
 
47
#include "glconfig.h"
 
48
#include "importexport.h"
 
49
 
 
50
/* HACK */
 
51
extern void swcluster_set_cache(int, int, int, size_t);
 
52
 
 
53
 
 
54
/* Globals. */
 
55
static GtkWidget *swapfile;
 
56
static GtkWidget *app;
 
57
GtkWidget *glame_appbar;
 
58
 
 
59
extern long nPopupTimeout;
 
60
extern long bMac;
 
61
 
 
62
/* Forward declarations. */
 
63
static void create_new_project_cb(GtkWidget *menu, void * blah);
 
64
static void edit_file_cb(GtkWidget *menu, void *data);
 
65
static void import_cb(GtkWidget *menu, void *data);
 
66
static void show_console_cb(GtkWidget *menu, void *blah);
 
67
static void emptytrash_cb(GtkWidget *menu, void *blah);
 
68
static void sync_cb(GtkWidget *menu, void *blah);
 
69
static void gui_quit(GtkWidget *widget, gpointer data);
 
70
static int preferences_cb(GtkWidget *menu,void *blah);
 
71
static GtkWidget* glame_about(void);
 
72
/* Menus. */
 
73
static GnomeUIInfo swapfile_menu_uiinfo[] = {
 
74
        GNOMEUIINFO_MENU_NEW_ITEM (N_("_New Project"), N_("Creates a new Project group"), create_new_project_cb, NULL),
 
75
        GNOMEUIINFO_ITEM (N_("Edit File..."), N_("Imports a file and opens the waveedit window"), edit_file_cb, NULL),
 
76
        GNOMEUIINFO_ITEM (N_("Import..."), N_("Imports a file"), import_cb, NULL),
 
77
        GNOMEUIINFO_SEPARATOR,
 
78
        GNOMEUIINFO_ITEM (N_("Empty [deleted]"), N_("Kills [deleted] folder"), emptytrash_cb, NULL),
 
79
        GNOMEUIINFO_SEPARATOR,
 
80
        GNOMEUIINFO_ITEM (N_("Show _console"), N_("Shows the GLAME console"), show_console_cb, NULL),
 
81
        GNOMEUIINFO_ITEM (N_("Sync"), N_("Syncs meta to disk"), sync_cb, NULL),
 
82
        GNOMEUIINFO_SEPARATOR,
 
83
        GNOMEUIINFO_MENU_EXIT_ITEM (gui_quit, NULL),
 
84
        GNOMEUIINFO_END
 
85
};
 
86
 
 
87
static void new_network_cb(GtkWidget *menu, void *blah);
 
88
extern void glame_load_network(GtkWidget *bla, void *blu);
 
89
static void load_plugin_cb(GtkWidget* foo, void *bar);
 
90
static GnomeUIInfo filter_menu_uiinfo[] = {
 
91
        GNOMEUIINFO_MENU_NEW_ITEM(N_("New Filternetwork"), N_("Creates a new filternetwork"), new_network_cb, NULL),
 
92
        GNOMEUIINFO_MENU_OPEN_ITEM(glame_load_network, NULL),
 
93
        GNOMEUIINFO_SEPARATOR,
 
94
        GNOMEUIINFO_ITEM(N_("Load Plugin"),N_("Loads and registers a plugin"), load_plugin_cb,NULL),
 
95
        GNOMEUIINFO_END
 
96
};
 
97
 
 
98
static GnomeUIInfo help_menu_uiinfo[] =
 
99
{
 
100
        GNOMEUIINFO_ITEM_DATA(N_("_Help"),N_("Opens a gnome help browser"),gnome_help_goto,"info:glame",NULL),
 
101
        GNOMEUIINFO_ITEM_DATA(N_("Quick Start Guide"), N_("Opens a gnome help browser with the quick start guide"), gnome_help_goto, "info:glame#Quick_Start_Guide", NULL),
 
102
        GNOMEUIINFO_ITEM_DATA(N_("List key-bindings"), N_("Lists the current key-bindings"), glame_accel_widget_data_cb, "list_keybindings", NULL),
 
103
        GNOMEUIINFO_SEPARATOR,
 
104
        GNOMEUIINFO_MENU_ABOUT_ITEM (glame_about, NULL),
 
105
        GNOMEUIINFO_END
 
106
};
 
107
 
 
108
static GnomeUIInfo glame_setting_uiinfo[] =
 
109
{
 
110
        GNOMEUIINFO_MENU_PREFERENCES_ITEM (preferences_cb, NULL),
 
111
        GNOMEUIINFO_END
 
112
};
 
113
 
 
114
 
 
115
static GnomeUIInfo menubar_uiinfo[] =
 
116
{
 
117
  {
 
118
    GNOME_APP_UI_SUBTREE, N_("_Project"),
 
119
    NULL,
 
120
    swapfile_menu_uiinfo, NULL, NULL,
 
121
    GNOME_APP_PIXMAP_NONE, NULL,
 
122
    0, 0, NULL
 
123
  },
 
124
  {
 
125
    GNOME_APP_UI_SUBTREE, N_("_Filternetwork"),
 
126
    NULL,
 
127
    filter_menu_uiinfo, NULL, NULL,
 
128
    GNOME_APP_PIXMAP_NONE, NULL,
 
129
    0, 0, NULL
 
130
  },
 
131
  GNOMEUIINFO_MENU_SETTINGS_TREE (glame_setting_uiinfo),
 
132
  GNOMEUIINFO_MENU_HELP_TREE (help_menu_uiinfo),
 
133
  GNOMEUIINFO_END
 
134
};
 
135
 
 
136
 
 
137
static void show_console_cb(GtkWidget *menu, void * blah)
 
138
{
 
139
        glame_console_show();
 
140
}
 
141
 
 
142
static void sync_cb(GtkWidget *menu, void * blah)
 
143
{
 
144
        gpsm_sync();
 
145
}
 
146
 
 
147
static void emptytrash_cb(GtkWidget *menu, void * blah)
 
148
{
 
149
        gpsm_grp_t *deleted;
 
150
 
 
151
        if (!(deleted = gpsm_find_grp_label(gpsm_root(), NULL, GPSM_GRP_DELETED_LABEL)))
 
152
                return;
 
153
        gpsm_item_destroy((gpsm_item_t *)deleted);
 
154
        gpsm_sync();
 
155
}
 
156
 
 
157
static void new_network_cb(GtkWidget *menu, void * blah)
 
158
{
 
159
        GtkWidget *feg;
 
160
        feg = glame_filtereditgui_new(NULL, FALSE);
 
161
        gtk_quit_add_destroy(1, GTK_OBJECT(feg));
 
162
        gtk_widget_show(feg);
 
163
}
 
164
 
 
165
extern void edit_tree_label(GlameTreeItem * item);
 
166
static void create_new_project_cb(GtkWidget *menu, void * blah)
 
167
{
 
168
        gpsm_grp_t *grp, *deleted;
 
169
        GlameTreeItem *grpw;
 
170
 
 
171
        if ((deleted = gpsm_find_grp_label(gpsm_root(), NULL, GPSM_GRP_DELETED_LABEL)))
 
172
                gpsm_item_remove((gpsm_item_t *)deleted);
 
173
 
 
174
        /* Create new gpsm group. */
 
175
        grp = gpsm_newgrp(_("Unnamed"));
 
176
        if (gpsm_item_place(gpsm_root(), (gpsm_item_t *)grp,
 
177
                            0, gpsm_item_vsize(gpsm_root())) == -1)
 
178
                DPRINTF("Cannot insert new group!?\n");
 
179
        if (deleted)
 
180
                gpsm_item_place(gpsm_root(), (gpsm_item_t *)deleted,
 
181
                                0, GPSM_GRP_DELETED_VPOS);
 
182
 
 
183
        /* Find out which widget it got. */
 
184
        grpw = glame_tree_find_gpsm_item(
 
185
                GTK_OBJECT(SWAPFILE_GUI(swapfile)->tree), (gpsm_item_t *)grp);
 
186
        if (!grpw) {
 
187
                DPRINTF("Umm, cant find widget for new project.\n");
 
188
                return;
 
189
        }
 
190
        edit_tree_label(grpw);
 
191
}
 
192
 
 
193
static void edit_file_cleanup_cb(GtkObject *widget, gpsm_item_t *file)
 
194
{
 
195
        gpsm_item_destroy(file);
 
196
}
 
197
static void edit_file_mark_modified_cb(glsig_handler_t *h, long sig, va_list va)
 
198
{
 
199
        WaveeditGui *we = WAVEEDIT_GUI(glsig_handler_private(h));
 
200
        we->modified = 1;
 
201
}
 
202
static void edit_file_cb(GtkWidget *menu, void *data)
 
203
{
 
204
        gpsm_item_t *file, *item;
 
205
        WaveeditGui *we;
 
206
 
 
207
        /* Run the import dialog. */
 
208
        file = glame_import_dialog(NULL);
 
209
        if (!file)
 
210
                return;
 
211
 
 
212
        /* Open the waveedit window and register a handler for gpsm
 
213
         * deletion after widget destroy. Also register handlers for
 
214
         * track modification to update bool. */
 
215
        we = glame_waveedit_gui_new(gpsm_item_label(file), file);
 
216
        if (!we) {
 
217
                gnome_dialog_run_and_close(GNOME_DIALOG(
 
218
                        gnome_error_dialog(_("Cannot open wave editor"))));
 
219
                gpsm_item_destroy(file);
 
220
                return;
 
221
        }
 
222
        gtk_signal_connect(GTK_OBJECT(we), "destroy",
 
223
                           (GtkSignalFunc)edit_file_cleanup_cb, file);
 
224
        gpsm_grp_foreach_item(file, item)
 
225
                glsig_add_handler(gpsm_item_emitter(item), GPSM_SIG_SWFILE_CHANGED|GPSM_SIG_SWFILE_CUT|GPSM_SIG_SWFILE_INSERT,
 
226
                                  edit_file_mark_modified_cb, we);
 
227
        gtk_quit_add_destroy(1, GTK_OBJECT(we));
 
228
        gtk_widget_show_all(GTK_WIDGET(we));
 
229
}
 
230
 
 
231
static void import_cb(GtkWidget *menu, void *data)
 
232
{
 
233
        gpsm_item_t *file;
 
234
        gpsm_grp_t *deleted;
 
235
        int res;
 
236
 
 
237
        /* Run the import dialog. */
 
238
        file = glame_import_dialog(NULL);
 
239
        if (!file)
 
240
                return;
 
241
 
 
242
        if ((deleted = gpsm_find_grp_label(gpsm_root(), NULL, GPSM_GRP_DELETED_LABEL)))
 
243
                gpsm_item_remove((gpsm_item_t *)deleted);
 
244
        res = gpsm_vbox_insert(gpsm_root(), file,
 
245
                               0, gpsm_item_vsize(gpsm_root()));
 
246
        if (deleted)
 
247
                gpsm_item_place(gpsm_root(), (gpsm_item_t *)deleted,
 
248
                                0, GPSM_GRP_DELETED_VPOS);
 
249
        if (res == -1) {
 
250
                gnome_dialog_run_and_close(GNOME_DIALOG(gnome_error_dialog(_("Cannot place imported wave"))));
 
251
                gpsm_item_destroy(file);
 
252
        }
 
253
}
 
254
 
 
255
static void load_plugin_cb(GtkWidget*bla,void*blu)
 
256
{
 
257
        GtkWidget *dialog;
 
258
        char filenamebuffer[256];
 
259
 
 
260
        filenamebuffer[0] = '\0';
 
261
        dialog = glame_dialog_file_request(_("Load Plugin"),
 
262
                                           "main:load_plugin", _("Filename"),
 
263
                                           NULL, filenamebuffer);
 
264
        if (!gnome_dialog_run_and_close(GNOME_DIALOG(dialog))
 
265
            || !*filenamebuffer)
 
266
                return;
 
267
 
 
268
        if (glame_load_plugin(filenamebuffer) == -1)
 
269
                gnome_dialog_run_and_close(GNOME_DIALOG(
 
270
                        gnome_error_dialog(_("Error loading plugin"))));
 
271
}
 
272
 
 
273
 
 
274
 
 
275
/* Update globals derived from preferences and provide defaults to
 
276
 * all configurables.
 
277
 * Returns -1 if it seems we didnt have a valid config for now. */
 
278
static int update_preferences()
 
279
{
 
280
        filter_t *filter;
 
281
        char *swappath = NULL;
 
282
        char *ainplugin = NULL, *aindev = NULL;
 
283
        char *aoutplugin = NULL, *aoutdev = NULL;
 
284
        char s[256];
 
285
        long maxundo, res = 0;
 
286
        long wbufsize, maxlru, maxfds, maxmaps, maxvm;
 
287
        long rate;
 
288
 
 
289
        /* Check, if we have anything configured already. */
 
290
        if (glame_config_get_string("swapfile/defaultpath", &swappath) == -1)
 
291
                res = -1;
 
292
        else
 
293
                free(swappath);
 
294
 
 
295
        /* Set default swapfile path and max. undo depth */
 
296
        snprintf(s, 255, "%s/.glameswap", g_get_home_dir());
 
297
        swappath = glame_config_get_string_with_default("swapfile/defaultpath", s);
 
298
 
 
299
        glame_config_get_long("swapfile/maxundo", &maxundo);
 
300
        gpsm_set_max_saved_ops(maxundo);
 
301
 
 
302
        maxlru = glame_config_get_long_with_default("swapfile/maxlru", 2048);
 
303
        maxfds = glame_config_get_long_with_default("swapfile/maxfds", 128);
 
304
        maxmaps = glame_config_get_long_with_default("swapfile/maxmaps", 256);
 
305
        maxvm = glame_config_get_long_with_default("swapfile/maxvm", 256*1024*1024);
 
306
        swcluster_set_cache(maxlru, maxfds, maxmaps, maxvm);
 
307
 
 
308
        /* GLAME_WBUFSIZE */
 
309
        glame_config_get_long("filter/wbufsize", &wbufsize);
 
310
        _GLAME_WBUFSIZE = wbufsize;
 
311
 
 
312
        /* Update IO plugin setup - audio_out */
 
313
        aoutplugin = glame_config_get_string_with_default(
 
314
                "audio_io/output_plugin", "audio_out");
 
315
        if (!plugin_get(aoutplugin)) {
 
316
                DPRINTF("No plugin %s - using audio_out\n", aoutplugin);
 
317
                free(aoutplugin);
 
318
                aoutplugin = strdup("audio_out");
 
319
                if (!plugin_get(aoutplugin))
 
320
                        goto ain;
 
321
        }
 
322
        aoutdev = filterparam_val_string(filterparamdb_get_param(filter_paramdb((filter_t *)plugin_query(plugin_get(aoutplugin), PLUGIN_FILTER)), "device"));
 
323
        snprintf(s, 255, "%s", aoutdev ? aoutdev : "");
 
324
        aoutdev = glame_config_get_string_with_default("audio_io/output_dev", s);
 
325
        filter = filter_instantiate(plugin_get(aoutplugin));
 
326
        if (filter) {
 
327
                filterparam_set(filterparamdb_get_param(filter_paramdb(filter),
 
328
                                                        "device"), &aoutdev);
 
329
                filter_register(filter, plugin_get("audio_out"));
 
330
        }
 
331
 
 
332
 ain:
 
333
        /* Update IO plugin setup - audio_in */
 
334
        rate = glame_config_get_long_with_default(
 
335
                "audio_io/input_rate", GLAME_DEFAULT_SAMPLERATE);
 
336
        ainplugin = glame_config_get_string_with_default(
 
337
                "audio_io/input_plugin", "audio_in");
 
338
        if (!plugin_get(ainplugin)) {
 
339
                DPRINTF("No plugin %s - using audio_in\n", ainplugin);
 
340
                free(ainplugin);
 
341
                ainplugin = strdup("audio_in");
 
342
                if (!plugin_get(ainplugin))
 
343
                        goto sync;
 
344
        }
 
345
        aindev = filterparam_val_string(filterparamdb_get_param(filter_paramdb((filter_t *)plugin_query(plugin_get(ainplugin), PLUGIN_FILTER)), "device"));
 
346
        snprintf(s, 255, "%s", aindev ? aindev : "");
 
347
        aindev = glame_config_get_string_with_default("audio_io/input_dev", s);
 
348
        filter = filter_instantiate(plugin_get(ainplugin));
 
349
        if (filter) {
 
350
                filterparam_set(filterparamdb_get_param(filter_paramdb(filter),
 
351
                                                        "device"), &aindev);
 
352
                filterparam_set(filterparamdb_get_param(filter_paramdb(filter),
 
353
                                                        "rate"), &rate);
 
354
                filter_register(filter, plugin_get("audio_in"));
 
355
        }
 
356
 
 
357
 sync:
 
358
        /* Sync changes. */
 
359
        glame_config_sync();
 
360
 
 
361
        /* Display summary. */
 
362
        DPRINTF(
 
363
"Preferences:\n"
 
364
"\tSwapfile directory %s\n"
 
365
"\tUndo stack depth is %li\n"
 
366
"\tAudio input plugin %s, device \"%s\", rate %li\n"
 
367
"\tAudio output plugin %s, device \"%s\"\n"
 
368
"\tGLAME_WBUFSIZE %i\n"
 
369
"\tPopup timeout is %lims\n"
 
370
"\tMac mode is %s\n",
 
371
                swappath, maxundo, ainplugin, aindev, rate, aoutplugin, aoutdev, _GLAME_WBUFSIZE,
 
372
                nPopupTimeout, bMac ? "on" : "off");
 
373
 
 
374
        /* Free temp. storage. */
 
375
        g_free(swappath);
 
376
        g_free(aoutplugin);
 
377
        if (aoutdev)
 
378
                g_free(aoutdev);
 
379
        g_free(ainplugin);
 
380
        if (aindev)
 
381
                g_free(aindev);
 
382
 
 
383
        return res;
 
384
}
 
385
 
 
386
 
 
387
static void
 
388
setBoolean(GtkWidget * foo, gboolean * bar)
 
389
{
 
390
        *bar = TRUE;
 
391
}
 
392
static void
 
393
toggle_cb(GtkWidget*foo, gboolean *bar)
 
394
{
 
395
        *bar = (*bar)?FALSE:TRUE;
 
396
}
 
397
 
 
398
 
 
399
static GtkWidget *preferences_tab_filteredit(long *fe_popup_timeout, long *fe_mac)
 
400
{
 
401
        GtkWidget *vbox, *macMode;
 
402
 
 
403
        vbox = gtk_vbox_new(FALSE, 1);
 
404
 
 
405
        glame_config_get_long("edit_filter/popupTimeout", fe_popup_timeout);
 
406
        create_label_long_pair(vbox, _("Property popup timeout [ms]"),
 
407
                               fe_popup_timeout, 50, 1000);
 
408
 
 
409
        glame_config_get_long("edit_filter/macMode", fe_mac);
 
410
        macMode = gtk_check_button_new();
 
411
        gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(macMode), *fe_mac);
 
412
        gtk_signal_connect(GTK_OBJECT(macMode), "toggled", (GtkSignalFunc)toggle_cb, fe_mac);
 
413
        create_label_widget_pair(vbox, _("Mac mode (one mouse button mode)"), macMode);
 
414
        gtk_widget_show_all(vbox);
 
415
        return vbox;
 
416
}
 
417
 
 
418
static GtkWidget *preferences_tab_waveedit(long *we_scroll)
 
419
{
 
420
        GtkWidget *vbox, *macMode;
 
421
 
 
422
        vbox = gtk_vbox_new(FALSE, 1);
 
423
 
 
424
        glame_config_get_long("waveedit/scroll", we_scroll);
 
425
        macMode = gtk_check_button_new();
 
426
        gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(macMode), *we_scroll);
 
427
        gtk_signal_connect(GTK_OBJECT(macMode), "toggled", (GtkSignalFunc)toggle_cb, we_scroll);
 
428
        create_label_widget_pair(vbox, _("Scroll wave while playing"), macMode);
 
429
        gtk_widget_show_all(vbox);
 
430
        return vbox;
 
431
}
 
432
 
 
433
static GtkWidget *preferences_tab_swapfile(char *sw_path,
 
434
                                           long *sw_maxvm,
 
435
                                           long *sw_maxundo)
 
436
{
 
437
        GtkWidget *vbox, *entry;
 
438
        char *cfg;
 
439
 
 
440
        vbox = gtk_vbox_new(FALSE, 1);
 
441
 
 
442
        gtk_container_add(GTK_CONTAINER(vbox), gtk_label_new(
 
443
            _("You need lots of diskspace available at the swapfile location.")));
 
444
        gtk_container_add(GTK_CONTAINER(vbox), gtk_label_new(
 
445
            _("GLAME doesnt handle running out of disk space very well.")));
 
446
 
 
447
        entry = gnome_file_entry_new("swapfilepath", _("Swapfile Path"));
 
448
        create_label_widget_pair(vbox, _("Swapfile Path"), entry);
 
449
        glame_config_get_string("swapfile/defaultpath", &cfg);
 
450
        strncpy(sw_path, cfg, 255);
 
451
        g_free(cfg);
 
452
        gtk_entry_set_text(GTK_ENTRY(gnome_file_entry_gtk_entry(GNOME_FILE_ENTRY(entry))), sw_path);
 
453
        gtk_signal_connect(GTK_OBJECT(gnome_file_entry_gtk_entry(GNOME_FILE_ENTRY(entry))), "changed", (GtkSignalFunc)changeString, sw_path);
 
454
 
 
455
        glame_config_get_long("swapfile/maxvm", sw_maxvm);
 
456
        *sw_maxvm /= 1024*1024;
 
457
        create_label_long_pair(vbox, _("Maximum virtual memory used for caching [MB]"), sw_maxvm, 32, 512);
 
458
 
 
459
        gtk_container_add(GTK_CONTAINER(vbox), gtk_label_new(
 
460
            _("NOTE: Swapfile settings take effect after restart only")));
 
461
 
 
462
        gtk_container_add(GTK_CONTAINER(vbox), gtk_hseparator_new());
 
463
 
 
464
        glame_config_get_long("swapfile/maxundo", sw_maxundo);
 
465
        create_label_long_pair(vbox, _("Depth of undo stack"), sw_maxundo, 1, 32);
 
466
 
 
467
        gtk_widget_show_all(vbox);
 
468
        return vbox;
 
469
}
 
470
 
 
471
static GtkWidget *preferences_tab_audioio(char *ainplugin, char *aindev,
 
472
                                          char *aoutplugin, char *aoutdev,
 
473
                                          long *rate, long *wbufsize)
 
474
{
 
475
        GtkWidget *vbox, *combo;
 
476
        GList *combo_items;
 
477
        char *cfg;
 
478
 
 
479
        vbox = gtk_vbox_new(FALSE, 1);
 
480
 
 
481
        /* input filter */
 
482
        combo_items = NULL;
 
483
        if (plugin_get("oss_audio_in"))
 
484
                combo_items = g_list_append(combo_items, "oss_audio_in");
 
485
        if (plugin_get("esd_audio_in"))
 
486
                combo_items = g_list_append(combo_items, "esd_audio_in");
 
487
        if (plugin_get("alsa_audio_in"))
 
488
                combo_items = g_list_append(combo_items, "alsa_audio_in");
 
489
        if (plugin_get("sgi_audio_in"))
 
490
                combo_items = g_list_append(combo_items, "sgi_audio_in");
 
491
        if (combo_items) {
 
492
                combo = gtk_combo_new();
 
493
                gtk_combo_set_popdown_strings(GTK_COMBO(combo), combo_items);
 
494
                g_list_free(combo_items);
 
495
                gtk_widget_show(combo);
 
496
                glame_config_get_string("audio_io/input_plugin", &cfg);
 
497
                strncpy(ainplugin, cfg, 255);
 
498
                g_free(cfg);
 
499
                gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(combo)->entry), ainplugin);
 
500
                gtk_signal_connect(GTK_OBJECT(GTK_COMBO(combo)->entry), "changed", (GtkSignalFunc)changeString, ainplugin);
 
501
                gtk_widget_show(GTK_COMBO(combo)->entry);
 
502
                create_label_widget_pair(vbox, _("Default input plugin (audio_in)"), combo);
 
503
 
 
504
                /* input device */
 
505
                glame_config_get_string("audio_io/input_dev", &cfg);
 
506
                strncpy(aindev, cfg, 255);
 
507
                g_free(cfg);
 
508
                create_label_edit_pair(vbox, _("Default input device"), "aindev", aindev);
 
509
        } else {
 
510
                gtk_container_add(GTK_CONTAINER(vbox),
 
511
                                  gtk_label_new(_("No audio input plugin")));
 
512
        }
 
513
        /* sample rate */
 
514
        glame_config_get_long("audio_io/input_rate", rate);
 
515
        create_label_long_pair(vbox, _("Default input sample rate"), rate, 11025, 48000);
 
516
 
 
517
        gtk_container_add(GTK_CONTAINER(vbox), gtk_hseparator_new());
 
518
 
 
519
        /* output filter */
 
520
        combo_items = NULL;
 
521
        if (plugin_get("oss_audio_out"))
 
522
                combo_items = g_list_append(combo_items, "oss_audio_out");
 
523
        if (plugin_get("esd_audio_out"))
 
524
                combo_items = g_list_append(combo_items, "esd_audio_out");
 
525
        if (plugin_get("alsa_audio_out"))
 
526
                combo_items = g_list_append(combo_items, "alsa_audio_out");
 
527
        if (plugin_get("sgi_audio_out"))
 
528
                combo_items = g_list_append(combo_items, "sgi_audio_out");
 
529
        if (combo_items) {
 
530
                combo = gtk_combo_new();
 
531
                gtk_combo_set_popdown_strings(GTK_COMBO(combo), combo_items);
 
532
                g_list_free(combo_items);
 
533
                glame_config_get_string("audio_io/output_plugin", &cfg);
 
534
                strncpy(aoutplugin, cfg, 255);
 
535
                g_free(cfg);
 
536
                gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(combo)->entry), aoutplugin);
 
537
                gtk_signal_connect(GTK_OBJECT(GTK_COMBO(combo)->entry), "changed", (GtkSignalFunc)changeString, aoutplugin);
 
538
                create_label_widget_pair(vbox, _("Default output plugin (audio_out)"), combo);
 
539
 
 
540
                /* output device */
 
541
                glame_config_get_string("audio_io/output_dev", &cfg);
 
542
                strncpy(aoutdev, cfg, 255);
 
543
                g_free(cfg);
 
544
                create_label_edit_pair(vbox, _("Default output device"),
 
545
                                       "aoutdev", aoutdev);
 
546
        } else {
 
547
                gtk_container_add(GTK_CONTAINER(vbox),
 
548
                                  gtk_label_new(_("No audio output plugin")));
 
549
        }
 
550
 
 
551
        gtk_container_add(GTK_CONTAINER(vbox), gtk_hseparator_new());
 
552
 
 
553
        /* GLAME_WBUFSIZE */
 
554
        glame_config_get_long("filter/wbufsize", wbufsize);
 
555
        create_label_long_pair(vbox, _("Size hint for audio buffers [samples]"),
 
556
                               wbufsize, 64, 4096);
 
557
 
 
558
        gtk_widget_show_all(vbox);
 
559
        return vbox;
 
560
}
 
561
 
 
562
static int
 
563
preferences_cb(GtkWidget * wid, void * bla)
 
564
{
 
565
        GtkWidget *prop_box, *tablabel, *vbox;
 
566
        char aio_inplugin[256], aio_outplugin[256];
 
567
        char aio_indevice[256], aio_outdevice[256];
 
568
        long aio_wbufsize, aio_rate; 
 
569
        char sw_path[256];
 
570
        long sw_maxundo, sw_maxlru, sw_maxfds, sw_maxmaps, sw_maxvm;
 
571
        long fe_popup_timeout;
 
572
        long fe_mac, we_scroll;
 
573
        gboolean ok = FALSE;
 
574
 
 
575
        /* New box. */
 
576
        prop_box = gnome_property_box_new();
 
577
 
 
578
        /* Swapfile with
 
579
         * - swapfile location */
 
580
        tablabel = gtk_label_new(_("Swapfile"));
 
581
        vbox = preferences_tab_swapfile(sw_path, &sw_maxvm, &sw_maxundo);
 
582
        gnome_property_box_append_page(GNOME_PROPERTY_BOX(prop_box),
 
583
                                       vbox, tablabel);
 
584
 
 
585
        /* Edit Filter with
 
586
         * - popup timeout
 
587
         * - mac mode */
 
588
        tablabel = gtk_label_new(_("Filternetwork"));
 
589
        vbox = preferences_tab_filteredit(&fe_popup_timeout, &fe_mac);
 
590
        gnome_property_box_append_page(GNOME_PROPERTY_BOX(prop_box),
 
591
                                       vbox, tablabel);
 
592
 
 
593
        /* Waveedit with
 
594
         * - scrolling */
 
595
        tablabel = gtk_label_new(_("Waveedit"));
 
596
        vbox = preferences_tab_waveedit(&we_scroll);
 
597
        gnome_property_box_append_page(GNOME_PROPERTY_BOX(prop_box),
 
598
                                       vbox, tablabel);
 
599
 
 
600
        /* Audio I/O with
 
601
         * - input device
 
602
         * - output device */
 
603
        tablabel = gtk_label_new(_("Audio I/O"));
 
604
        vbox = preferences_tab_audioio(aio_inplugin, aio_indevice,
 
605
                                       aio_outplugin, aio_outdevice,
 
606
                                       &aio_rate, &aio_wbufsize);
 
607
        gnome_property_box_append_page(GNOME_PROPERTY_BOX(prop_box), vbox,
 
608
                                       tablabel);
 
609
 
 
610
        /* Finish. */
 
611
        gtk_signal_connect(GTK_OBJECT(GNOME_PROPERTY_BOX(prop_box)->ok_button),"clicked",(GtkSignalFunc)setBoolean,&ok);
 
612
        gtk_object_destroy(GTK_OBJECT(GNOME_PROPERTY_BOX(prop_box)->apply_button));
 
613
        gtk_object_destroy(GTK_OBJECT(GNOME_PROPERTY_BOX(prop_box)->help_button));
 
614
        gtk_widget_show(prop_box);
 
615
 
 
616
 
 
617
        /* Run the dialog. */
 
618
        gnome_dialog_run_and_close(GNOME_DIALOG(prop_box));
 
619
        if(!ok)
 
620
                return 0;
 
621
 
 
622
        /* Update glame config.
 
623
         */
 
624
        glame_config_set_string("swapfile/defaultpath", sw_path);
 
625
        glame_config_set_long("swapfile/maxundo", sw_maxundo);
 
626
        /* Do some magic with sw_maxvm number to derive the rest. */
 
627
        sw_maxlru = 2048 * sw_maxvm / 256;
 
628
        sw_maxfds = 128 * sw_maxvm / 256;
 
629
        sw_maxmaps = 256 * sw_maxvm / 256;
 
630
        sw_maxvm *= 1024*1024;
 
631
        glame_config_set_long("swapfile/maxlru", sw_maxlru);
 
632
        glame_config_set_long("swapfile/maxfds", sw_maxfds);
 
633
        glame_config_set_long("swapfile/maxmaps", sw_maxmaps);
 
634
        glame_config_set_long("swapfile/maxvm", sw_maxvm);
 
635
        /* Filteredit */
 
636
        nPopupTimeout = fe_popup_timeout;
 
637
        glame_config_set_long("edit_filter/popupTimeout", nPopupTimeout);
 
638
        bMac = fe_mac;
 
639
        glame_config_set_long("edit_filter/macMode", bMac);
 
640
        /* Waveedit */
 
641
        glame_config_set_long("waveedit/scroll", we_scroll);
 
642
        /* Audio I/O */
 
643
        glame_config_set_string("audio_io/input_dev", aio_indevice);
 
644
        glame_config_set_string("audio_io/input_plugin", aio_inplugin);
 
645
        glame_config_set_long("audio_io/input_rate", aio_rate);
 
646
        glame_config_set_string("audio_io/output_dev", aio_outdevice);
 
647
        glame_config_set_string("audio_io/output_plugin", aio_outplugin);
 
648
        glame_config_set_long("filter/wbufsize", aio_wbufsize);
 
649
        glame_config_sync();
 
650
 
 
651
        /* Update config derived stuff. */
 
652
        update_preferences();
 
653
 
 
654
        return 1;
 
655
}
 
656
 
 
657
 
 
658
 
 
659
/*
 
660
 * The GLAME About dialog.
 
661
 */
 
662
 
 
663
static GtkWidget* glame_about(void)
 
664
{
 
665
        /* FIXME: gnome_about_new() apparently does not gettext() the
 
666
         * authors argument, and gettext() cannot handle argvz-style
 
667
         * string arrays. Looks like we might have to work around the
 
668
         * issue by allocating dynamically. But it sucks. Leave it
 
669
         * untranslated for now.
 
670
         */
 
671
        const gchar *authors[]={
 
672
                N_("Richard Guenther [Richi]"),
 
673
                N_("Alexander Ehlert [Mag]"),
 
674
                N_("Daniel Kobras [*nold]"),
 
675
                N_("Johannes Hirche [XWolf]"),
 
676
                N_("and others"),
 
677
                NULL
 
678
        };
 
679
        GtkWidget *about;
 
680
        char *logo;
 
681
 
 
682
        logo = GLAME_LOGO;
 
683
        if (access(logo, R_OK) == -1)
 
684
                logo = "../data/pixmaps/glame-logo.jpg";
 
685
        about = gnome_about_new ("GLAME", VERSION, 
 
686
                                 _("Copyright (C) 1999-2001 R. Guenther, A. Ehlert, J. Hirche, D. Kobras"),
 
687
                                 authors,
 
688
 
 
689
                                 _(
 
690
"This program is free software; you can redistribute it and/or modify"
 
691
"it under the terms of the GNU General Public License as published by"
 
692
"the Free Software Foundation; either version 2 of the License, or"
 
693
"(at your option) any later version.\n"
 
694
"This program is distributed in the hope that it will be useful,"
 
695
"but WITHOUT ANY WARRANTY; without even the implied warranty of"
 
696
"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the"
 
697
"GNU General Public License for more details.\n"
 
698
"You should have received a copy of the GNU General Public License"
 
699
"along with this program; if not, write to the Free Software"
 
700
"Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA"),
 
701
                                 logo);
 
702
        gtk_object_set_data (GTK_OBJECT (about), "about", about);
 
703
        gtk_window_set_modal (GTK_WINDOW (about), TRUE);
 
704
        gtk_window_set_wmclass (GTK_WINDOW (about), "Glameabout", "Glame");
 
705
        gtk_window_set_position (GTK_WINDOW (about), GTK_WIN_POS_CENTER_ALWAYS);
 
706
        gtk_widget_show(about);
 
707
        return about;
 
708
}
 
709
 
 
710
static gint glame_splash_timeout(GtkWidget *about)
 
711
{
 
712
        gtk_object_destroy(GTK_OBJECT(about));
 
713
        return FALSE;
 
714
}
 
715
static void glame_splash_destroy_cb(GtkWidget *about, gpointer tid)
 
716
{
 
717
        gtk_timeout_remove((guint)tid);
 
718
}
 
719
static void glame_splash(void)
 
720
{
 
721
        GtkWidget *about;
 
722
        guint tid;
 
723
 
 
724
        about = glame_about();
 
725
 
 
726
#ifdef DEBUG
 
727
        tid = gtk_timeout_add(1000, (GtkFunction)glame_splash_timeout, about);
 
728
#else
 
729
        tid = gtk_timeout_add(5000, (GtkFunction)glame_splash_timeout, about);
 
730
#endif
 
731
        gtk_signal_connect(GTK_OBJECT(about), "destroy",
 
732
                           (GtkSignalFunc)glame_splash_destroy_cb, (gpointer)tid);
 
733
}
 
734
 
 
735
 
 
736
/*
 
737
 * Real main and cleanup stuff.
 
738
 */
 
739
 
 
740
static void on_swapfile_panic(const char *msg)
 
741
{
 
742
        char message[1024];
 
743
 
 
744
        /* Tell the user what happened. */
 
745
        snprintf(message, 1023,
 
746
                 _("The GLAME swapfile subsystem is about to commit suicide.\n"
 
747
                 "The reason for this is:\n"
 
748
                 "    %s\n"
 
749
                 "The current pending libc error is:\n"
 
750
                 "    %s\n"
 
751
                 "Just restart GLAME after fixing the above (which may be\n"
 
752
                 "an internal GLAME error, too).\n\n"
 
753
                 "-- BYE BYE.\n"),
 
754
                 msg, strerror(errno));
 
755
        gnome_dialog_run_and_close(GNOME_DIALOG(gnome_error_dialog(message)));
 
756
 
 
757
        /* Try to save the current gpsm tree. May even lock up. Ugh. */
 
758
        gpsm_sync();
 
759
}
 
760
 
 
761
static void resize_horiz_cb(GtkWidget *widget, GtkRequisition *req,
 
762
                            GtkWidget *window)
 
763
{
 
764
        static int last_width = 0, last_height = 0;
 
765
        if (last_width == req->width && last_height == req->height)
 
766
                return;
 
767
        last_width = req->width;
 
768
        last_height = req->height;
 
769
        gtk_window_set_default_size(GTK_WINDOW(window),
 
770
                                    req->width + 10,
 
771
                                    window->allocation.height);
 
772
}
 
773
 
 
774
static void gui_quit(GtkWidget *widget, gpointer data)
 
775
{
 
776
        /* This doesnt seem to destroy windows "correctly"
 
777
         * - cleanup is still missing for Edit File... */
 
778
        gtk_main_quit();
 
779
}
 
780
 
 
781
static void gui_main()
 
782
{
 
783
        GtkWidget *dock, *scrollview;
 
784
        char *path;
 
785
 
 
786
        /* Init GUI dependend subsystems. */
 
787
        glame_accel_init();
 
788
        glame_swapfilegui_init();
 
789
        glame_waveeditgui_init();
 
790
        glame_filtereditgui_init();
 
791
        glame_timeline_init();
 
792
 
 
793
        /* Update preferences. */
 
794
        if (update_preferences() == -1) {
 
795
                gnome_dialog_run_and_close(GNOME_DIALOG(gnome_ok_dialog(
 
796
_("Welcome first-time user of GLAME.\n"
 
797
"We need to do some basic setup stuff. Please run through\n"
 
798
"the preferences dialog and check the \"Swapfile Path\" and\n"
 
799
"\"Audio IO\" settings.\n"))));
 
800
        run_prefs:
 
801
                if (!preferences_cb(NULL, NULL)) {
 
802
                        gnome_dialog_run_and_close(
 
803
                                GNOME_DIALOG(gnome_error_dialog(_("You didnt change/check the configuration.\nGLAME is exiting now.\n"))));
 
804
                        exit(1);
 
805
                }
 
806
        }
 
807
 
 
808
        glame_config_get_string("swapfile/defaultpath", &path);
 
809
        DPRINTF("path: %s\n",path);
 
810
        if (!g_file_test(path,G_FILE_TEST_ISDIR)) {
 
811
                if (swapfile_creat(path, -1)) {
 
812
                        char msg[256];
 
813
                        char *errmsg = strerror(errno);
 
814
                        snprintf(msg, 255, _("GLAME was unable to create its swapfile\nbecause of \"%s\".\nPlease check the configuration.\n"), errmsg);
 
815
                        gnome_dialog_run_and_close(
 
816
                                GNOME_DIALOG(gnome_error_dialog(msg)));
 
817
                        goto run_prefs;
 
818
                }
 
819
        }
 
820
        if (gpsm_init(path) == -1) {
 
821
                char msg[256];
 
822
                char *errmsg = strerror(errno);
 
823
                snprintf(msg, 255, "GLAME was unable to open/init its swapfile\nbecause of \"%s\".\nPlease check the configuration and/or check for\nGLAME messages on the console.\n", errmsg);
 
824
                gnome_dialog_run_and_close(
 
825
                        GNOME_DIALOG(gnome_error_dialog(msg)));
 
826
                goto run_prefs;
 
827
        }
 
828
        g_free(path);
 
829
 
 
830
        /* Register a swapfile panic handler. */
 
831
        swapfile_register_panic_handler(on_swapfile_panic);
 
832
 
 
833
        /* create swapfile gui - in a scrolled window */
 
834
        swapfile = GTK_WIDGET(glame_swapfile_widget_new(gpsm_root()));
 
835
        if (!swapfile)
 
836
                return;
 
837
        scrollview = gtk_scrolled_window_new(NULL, NULL);
 
838
        gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrollview),
 
839
                                       GTK_POLICY_NEVER,
 
840
                                       GTK_POLICY_ALWAYS);
 
841
        gtk_scrolled_window_set_placement(GTK_SCROLLED_WINDOW(scrollview),
 
842
                                          GTK_CORNER_TOP_RIGHT);
 
843
        gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scrollview),
 
844
                                              swapfile);
 
845
        gtk_widget_show(swapfile);
 
846
        gtk_widget_show(scrollview);
 
847
 
 
848
        /* Create main window. */
 
849
        app = gnome_app_new ("glame0.5", NULL);
 
850
        gtk_object_set_data (GTK_OBJECT (app), "app", app);
 
851
        dock = GNOME_APP (app)->dock;
 
852
        gtk_widget_ref (dock);
 
853
        gtk_object_set_data_full (GTK_OBJECT (app), "dock", dock,
 
854
                                 (GtkDestroyNotify) gtk_widget_unref);
 
855
        gtk_widget_show (dock);
 
856
        gnome_app_create_menus (GNOME_APP (app), menubar_uiinfo);
 
857
        glame_appbar = gnome_appbar_new (TRUE, TRUE, GNOME_PREFERENCES_NEVER);
 
858
        gtk_widget_show (glame_appbar);
 
859
        gnome_app_set_statusbar (GNOME_APP (app), glame_appbar);
 
860
        gnome_app_install_menu_hints (GNOME_APP (app), menubar_uiinfo);
 
861
 
 
862
        /* Connect signals and insert swapfile gui into the main window. */
 
863
        gtk_signal_connect(GTK_OBJECT(app), "delete-event",
 
864
                           GTK_SIGNAL_FUNC(gui_quit), NULL);
 
865
        gnome_app_set_contents(GNOME_APP(app), scrollview);
 
866
        gtk_window_set_default_size(GTK_WINDOW(app), 300, 200);
 
867
        gtk_widget_show(app);
 
868
 
 
869
        /* Connect auto-horizontal-resize callback. */
 
870
        gtk_signal_connect(GTK_OBJECT(swapfile), "size_request",
 
871
                           (GtkSignalFunc)resize_horiz_cb, app);
 
872
 
 
873
        /* Register accelerators. */
 
874
        SWAPFILE_GUI(swapfile)->accel_handler =
 
875
                glame_accel_install(app, "swapfile", NULL);
 
876
        SWAPFILE_GUI(swapfile)->app = app;
 
877
 
 
878
        /* Pop up splash screen. */
 
879
        glame_splash();
 
880
 
 
881
        /* Pop up console. */
 
882
        glame_console_init();
 
883
        glame_console_printf("%s%s%s",
 
884
_("    GLAME version "), VERSION, _(", Copyright (C) 1999-2001 by\n"
 
885
"    Alexander Ehlert, Richard Guenther, Johannes Hirche,\n"
 
886
"    Daniel Kobras. GLAME comes with ABSOLUTELY NO\n"
 
887
"    WARRANTY. This is free software, and you are welcome to\n"
 
888
"    redistribute it under certain conditions.\n\n"));
 
889
#ifndef HAVE_LADSPA
 
890
        glame_console_printf("WARNING! This copy of GLAME was compiled without LADSPA plugin support\n");
 
891
#endif
 
892
#ifndef HAVE_LIBGLADE
 
893
        glame_console_printf("WARNING! This copy of GLAME was compiled without libglade support\n");
 
894
#endif
 
895
 
 
896
        /* Main event loop */
 
897
        gtk_main();
 
898
 
 
899
        /* Cleanup after gtk - tear down GLAME midlayer/backends. */
 
900
        clipboard_empty();
 
901
        gpsm_close();
 
902
        /* glame_accel_sync(); -- disabled, until we get GUI support */
 
903
 
 
904
        /* Exit to guile here - no way back. */
 
905
}
 
906
 
 
907
 
 
908
int main(int argc, char **argv)
 
909
{
 
910
        textdomain("glame");
 
911
 
 
912
        /* setup gnome/gtk  */
 
913
        gnome_init("glame", VERSION, argc, argv);
 
914
 
 
915
#ifdef HAVE_LIBGLADE
 
916
        glade_init();
 
917
#endif
 
918
 
 
919
        /* init glame */
 
920
        glame_init(gui_main, argc, argv);
 
921
 
 
922
        DPRINTF("Returned to main\n");
 
923
 
 
924
        return 1;
 
925
}