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

« back to all changes in this revision

Viewing changes to interface/gtk2/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
 *  Copyright (C) 2007 Madej
 
5
 *
 
6
 *  This file is part of AlsaPlayer.
 
7
 *
 
8
 *  AlsaPlayer 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 3 of the License, or
 
11
 *  (at your option) any later version.
 
12
 *
 
13
 *  AlsaPlayer 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, see <http://www.gnu.org/licenses/>.
 
20
 *
 
21
*/ 
 
22
 
 
23
#include <cstdio>
 
24
#include <cstdlib>
 
25
#include <csignal>
 
26
#include <cassert>
 
27
#include <unistd.h>
 
28
#include <cstring>
 
29
#include <sys/types.h>
 
30
#include <dirent.h>
 
31
#include <sys/stat.h>
 
32
#include <sys/time.h>
 
33
#include <sys/ioctl.h>
 
34
#include <fcntl.h>
 
35
#include <dlfcn.h>
 
36
#include <cmath>
 
37
#include <glib.h>
 
38
 
 
39
#include "config.h"
 
40
 
 
41
#include "AlsaPlayer.h"
 
42
#include "SampleBuffer.h"
 
43
#include "CorePlayer.h"
 
44
#include "Playlist.h"
 
45
#include "ScopesWindow.h"
 
46
#include "gtk_interface.h"
 
47
#include "utilities.h"
 
48
#include "interface_plugin.h"
 
49
#include "alsaplayer_error.h"
 
50
 
 
51
static char addon_dir[1024];
 
52
 
 
53
static AlsaSubscriber *scopes = NULL;
 
54
 
 
55
static CorePlayer *the_coreplayer = NULL;
 
56
 
 
57
void unload_scope_addons()
 
58
{
 
59
        if (scopes)
 
60
                delete scopes;
 
61
        apUnregiserScopePlugins();
 
62
}
 
63
 
 
64
void load_scope_addons()
 
65
{
 
66
        char path[1024];
 
67
        struct stat buf;
 
68
        scope_plugin *tmp;
 
69
 
 
70
        scope_plugin_info_type scope_plugin_info;
 
71
 
 
72
        snprintf(path, sizeof(path)-1, "%s/scopes2", addon_dir);
 
73
 
 
74
        DIR *dir = opendir(path);
 
75
        dirent *entry;
 
76
 
 
77
        if (dir) {
 
78
                while ((entry = readdir(dir)) != NULL) { // For each file in scopes
 
79
                        if (strcmp(entry->d_name, ".") == 0 ||
 
80
                                strcmp(entry->d_name, "..") == 0) {
 
81
                                continue;
 
82
                        }
 
83
                        sprintf(path, "%s/scopes2/%s", addon_dir, entry->d_name);
 
84
                        //alsaplayer_error(path);
 
85
                        if (stat(path, &buf)) continue;
 
86
                        if (S_ISREG(buf.st_mode)) {
 
87
                                void *handle;
 
88
 
 
89
                                char *ext = strrchr(path, '.');
 
90
                                if (!ext)
 
91
                                        continue;
 
92
                                ext++;
 
93
                                if (strcasecmp(ext, "so"))
 
94
                                        continue;
 
95
                                if ((handle = dlopen(path, RTLD_NOW |RTLD_GLOBAL))) {
 
96
                                        scope_plugin_info = (scope_plugin_info_type) dlsym(handle, "scope_plugin_info");
 
97
                                        if (scope_plugin_info) { 
 
98
#ifdef DEBUG                                    
 
99
                                                alsaplayer_error("Loading scope addon: %s\n", path);
 
100
#endif
 
101
                                                tmp = scope_plugin_info();
 
102
                                                if (tmp) {
 
103
                                                                tmp->handle = handle;
 
104
                                                                if (apRegisterScopePlugin(tmp) == -1) {
 
105
                                                                        alsaplayer_error("%s is deprecated", path);
 
106
                                                                }
 
107
                                                }               
 
108
                                        } else {
 
109
                                                dlclose(handle);
 
110
                                        }
 
111
                                } else {
 
112
                                        printf("%s\n", dlerror());
 
113
                                }
 
114
                        }
 
115
                }
 
116
                closedir(dir);
 
117
        }       
 
118
}
 
119
 
 
120
int interface_gtk_init()
 
121
{
 
122
        strcpy(addon_dir, ADDON_DIR);
 
123
        return 1;
 
124
}
 
125
 
 
126
 
 
127
int interface_gtk_running()
 
128
{
 
129
        return 1;
 
130
}
 
131
 
 
132
 
 
133
int interface_gtk_stop()
 
134
{
 
135
        global_update = -1;
 
136
        
 
137
        GDK_THREADS_ENTER();
 
138
 
 
139
        gdk_flush();
 
140
        gtk_exit(0); // This is *NOT* clean :-(
 
141
        GDK_THREADS_LEAVE();
 
142
        return 1;
 
143
}
 
144
 
 
145
void interface_gtk_close()
 
146
{
 
147
        return;
 
148
}
 
149
 
 
150
 
 
151
void dl_close_scopes();
 
152
 
 
153
int interface_gtk_start(Playlist *playlist, int argc, char **argv)
 
154
{
 
155
        char path[256];
 
156
        char *home;
 
157
 
 
158
        the_coreplayer = playlist->GetCorePlayer();
 
159
 
 
160
        g_thread_init(NULL);
 
161
        if (!g_thread_supported()) {
 
162
                alsaplayer_error("Sorry - this interface requires working threads.\n");
 
163
                return 1;
 
164
        }
 
165
 
 
166
        gdk_threads_init();
 
167
 
 
168
        // Scope functions
 
169
        scopes = new AlsaSubscriber();
 
170
        scopes->Subscribe(the_coreplayer->GetNode(), POS_END);
 
171
        scopes->EnterStream(scope_feeder_func, the_coreplayer);
 
172
 
 
173
        gtk_set_locale();
 
174
        gtk_init(&argc, &argv);
 
175
        gdk_rgb_init();
 
176
 
 
177
        home = getenv("HOME");
 
178
        if (home) {
 
179
                snprintf(path, 255, "%s/.gtkrc-2.0", home);
 
180
                gtk_rc_parse(path);
 
181
        }
 
182
 
 
183
        // Scope addons
 
184
        gdk_flush();
 
185
        GDK_THREADS_ENTER();
 
186
        init_main_window(playlist);
 
187
        load_scope_addons();
 
188
        gdk_flush();
 
189
        gtk_main();
 
190
        gdk_flush();
 
191
        GDK_THREADS_LEAVE();
 
192
        unload_scope_addons();
 
193
        destroy_scopes_window();
 
194
        GDK_THREADS_ENTER();
 
195
        gdk_flush();
 
196
        GDK_THREADS_LEAVE();
 
197
 
 
198
        playlist->Pause();
 
199
 
 
200
        dl_close_scopes();
 
201
        return 0;
 
202
}
 
203
 
 
204
 
 
205
interface_plugin default_plugin =
 
206
{
 
207
        INTERFACE_PLUGIN_VERSION,
 
208
        "GTK+-2.x interface",
 
209
        "Andy Lo A Foe/Madej",
 
210
        NULL,
 
211
        interface_gtk_init,
 
212
        interface_gtk_start,
 
213
        interface_gtk_running,
 
214
        interface_gtk_stop,
 
215
        interface_gtk_close
 
216
};
 
217
 
 
218
extern "C" {
 
219
 
 
220
interface_plugin *interface_plugin_info()
 
221
{
 
222
        return &default_plugin;
 
223
}
 
224
 
 
225
}