~ubuntu-branches/ubuntu/wily/alsaplayer/wily

« back to all changes in this revision

Viewing changes to interface/gtk/gtk.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Hubert Chathi
  • Date: 2007-10-10 15:33:10 UTC
  • mto: (9.2.5 sid)
  • mto: This revision was merged to the branch mainline in revision 15.
  • Revision ID: james.westby@ubuntu.com-20071010153310-h3holq75eu2cigb0
Tags: upstream-0.99.80~rc4
ImportĀ upstreamĀ versionĀ 0.99.80~rc4

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 *  gtk.cpp - GTK interface plugin main file
3
 
 *  Copyright (C) 2001 Andy Lo A Foe <andy@alsaplayer.org>
4
 
 *
5
 
 *  This program is free software; you can redistribute it and/or modify
6
 
 *  it under the terms of the GNU General Public License as published by
7
 
 *  the Free Software Foundation; either version 2 of the License, or
8
 
 *  (at your option) any later version.
9
 
 *
10
 
 *  This program is distributed in the hope that it will be useful,
11
 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
 *  GNU General Public License for more details.
14
 
 *
15
 
 *  You should have received a copy of the GNU General Public License
16
 
 *  along with this program; if not, write to the Free Software
17
 
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
 
*/ 
19
 
 
20
 
#include <cstdio>
21
 
#include <cstdlib>
22
 
#include <csignal>
23
 
#include <cassert>
24
 
#include <unistd.h>
25
 
#include <cstring>
26
 
#include <sys/types.h>
27
 
#include <dirent.h>
28
 
#include <sys/stat.h>
29
 
#include <sys/time.h>
30
 
#include <sys/ioctl.h>
31
 
#include <fcntl.h>
32
 
#include <dlfcn.h>
33
 
#include <cmath>
34
 
#include <glib.h>
35
 
 
36
 
#include "config.h"
37
 
 
38
 
#include "AlsaPlayer.h"
39
 
#include "SampleBuffer.h"
40
 
#include "CorePlayer.h"
41
 
#include "Playlist.h"
42
 
#include "ScopesWindow.h"
43
 
#include "gtk_interface.h"
44
 
#include "utilities.h"
45
 
#include "interface_plugin.h"
46
 
#include "alsaplayer_error.h"
47
 
 
48
 
static char addon_dir[1024];
49
 
 
50
 
static AlsaSubscriber *scopes = NULL;
51
 
 
52
 
static CorePlayer *the_coreplayer = NULL;
53
 
 
54
 
void unload_scope_addons()
55
 
{
56
 
        if (scopes)
57
 
                delete scopes;
58
 
        apUnregiserScopePlugins();
59
 
}
60
 
 
61
 
void load_scope_addons()
62
 
{
63
 
        char path[1024];
64
 
        struct stat buf;
65
 
        scope_plugin *tmp;
66
 
 
67
 
        scope_plugin_info_type scope_plugin_info;
68
 
 
69
 
        snprintf(path, sizeof(path)-1, "%s/scopes", addon_dir);
70
 
 
71
 
        DIR *dir = opendir(path);
72
 
        dirent *entry;
73
 
 
74
 
        if (dir) {
75
 
                while ((entry = readdir(dir)) != NULL) { // For each file in scopes
76
 
                        if (strcmp(entry->d_name, ".") == 0 ||
77
 
                                strcmp(entry->d_name, "..") == 0) {
78
 
                                continue;
79
 
                        }
80
 
                        sprintf(path, "%s/scopes/%s", addon_dir, entry->d_name);
81
 
                        //alsaplayer_error(path);
82
 
                        if (stat(path, &buf)) continue;
83
 
                        if (S_ISREG(buf.st_mode)) {
84
 
                                void *handle;
85
 
 
86
 
                                char *ext = strrchr(path, '.');
87
 
                                if (!ext)
88
 
                                        continue;
89
 
                                ext++;
90
 
                                if (strcasecmp(ext, "so"))
91
 
                                        continue;
92
 
                                if ((handle = dlopen(path, RTLD_NOW |RTLD_GLOBAL))) {
93
 
                                        scope_plugin_info = (scope_plugin_info_type) dlsym(handle, "scope_plugin_info");
94
 
                                        if (scope_plugin_info) { 
95
 
#ifdef DEBUG                                    
96
 
                                                alsaplayer_error("Loading scope addon: %s\n", path);
97
 
#endif
98
 
                                                tmp = scope_plugin_info();
99
 
                                                if (tmp) {
100
 
                                                                tmp->handle = handle;
101
 
                                                                if (apRegisterScopePlugin(tmp) == -1) {
102
 
                                                                        alsaplayer_error("%s is deprecated", path);
103
 
                                                                }
104
 
                                                }               
105
 
                                        } else {
106
 
                                                dlclose(handle);
107
 
                                        }
108
 
                                } else {
109
 
                                        printf("%s\n", dlerror());
110
 
                                }
111
 
                        }
112
 
                }
113
 
                closedir(dir);
114
 
        }       
115
 
}
116
 
 
117
 
int interface_gtk_init()
118
 
{
119
 
        strcpy(addon_dir, ADDON_DIR);
120
 
        return 1;
121
 
}
122
 
 
123
 
 
124
 
int interface_gtk_running()
125
 
{
126
 
        return 1;
127
 
}
128
 
 
129
 
 
130
 
int interface_gtk_stop()
131
 
{
132
 
        global_update = -1;
133
 
        
134
 
        GDK_THREADS_ENTER();
135
 
 
136
 
        gdk_flush();
137
 
        gtk_exit(0); // This is *NOT* clean :-(
138
 
        GDK_THREADS_LEAVE();
139
 
        return 1;
140
 
}
141
 
 
142
 
void interface_gtk_close()
143
 
{
144
 
        return;
145
 
}
146
 
 
147
 
 
148
 
void dl_close_scopes();
149
 
 
150
 
int interface_gtk_start(Playlist *playlist, int argc, char **argv)
151
 
{
152
 
        char path[256];
153
 
        char *home;
154
 
 
155
 
        the_coreplayer = playlist->GetCorePlayer();
156
 
 
157
 
        g_thread_init(NULL);
158
 
        if (!g_thread_supported()) {
159
 
                alsaplayer_error("Sorry - this interface requires working threads.\n");
160
 
                return 1;
161
 
        }
162
 
 
163
 
        // Scope functions
164
 
        scopes = new AlsaSubscriber();
165
 
        scopes->Subscribe(the_coreplayer->GetNode(), POS_END);
166
 
        scopes->EnterStream(scope_feeder_func, the_coreplayer);
167
 
 
168
 
        gtk_set_locale();
169
 
        gtk_init(&argc, &argv);
170
 
        gdk_rgb_init();
171
 
 
172
 
        home = getenv("HOME");
173
 
        if (home) {
174
 
                snprintf(path, 255, "%s/.gtkrc", home);
175
 
                gtk_rc_parse(path);
176
 
        }
177
 
 
178
 
        if (playlist->Length())
179
 
                playlist->UnPause();
180
 
        // Scope addons
181
 
        gdk_flush();
182
 
        GDK_THREADS_ENTER();
183
 
        init_main_window(playlist);
184
 
        load_scope_addons();
185
 
        gdk_flush();
186
 
        gtk_main();
187
 
        gdk_flush();
188
 
        GDK_THREADS_LEAVE();
189
 
        unload_scope_addons();
190
 
        destroy_scopes_window();
191
 
        GDK_THREADS_ENTER();
192
 
        gdk_flush();
193
 
        GDK_THREADS_LEAVE();
194
 
 
195
 
        playlist->Pause();
196
 
 
197
 
        dl_close_scopes();
198
 
        return 0;
199
 
}
200
 
 
201
 
 
202
 
interface_plugin default_plugin =
203
 
{
204
 
        INTERFACE_PLUGIN_VERSION,
205
 
        "GTK+ interface v1.2",
206
 
        "Andy Lo A Foe",
207
 
        NULL,
208
 
        interface_gtk_init,
209
 
        interface_gtk_start,
210
 
        interface_gtk_running,
211
 
        interface_gtk_stop,
212
 
        interface_gtk_close
213
 
};
214
 
 
215
 
extern "C" {
216
 
 
217
 
interface_plugin *interface_plugin_info()
218
 
{
219
 
        return &default_plugin;
220
 
}
221
 
 
222
 
}