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