annotate Plugins/Visualization/paranormal/client.c @ 1532:f74a6ba233c2 trunk

[svn] - allow configdb::pnxmms::preset to set what pn preset to load on start
author nenolod
date Tue, 08 Aug 2006 02:19:55 -0700
parents bdb22d1e6302
children 984c99a1fb2e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1521
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
1 /* pnxmms - An xmms visualization plugin using the Paranormal
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
2 * audio visualization library
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
3 *
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
4 * Copyright (C) 2001 Jamie Gennis <jgennis@mindspring.com>
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
5 *
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
6 * This library is free software; you can redistribute it and/or
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
7 * modify it under the terms of the GNU Library General Public
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
8 * License as published by the Free Software Foundation; either
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
9 * version 2 of the License, or (at your option) any later version.
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
10 *
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
11 * This library is distributed in the hope that it will be useful,
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
14 * Library General Public License for more details.
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
15 *
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
16 * You should have received a copy of the GNU Library General Public
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
17 * License along with this library; if not, write to the Free
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
18 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
19 */
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
20
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
21 #ifdef HAVE_CONFIG_H
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
22 #include <config.h>
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
23 #endif
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
24
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
25 #include <sys/types.h>
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
26 #include <sys/stat.h>
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
27 #include <unistd.h>
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
28 #include <stdio.h>
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
29 #include <errno.h>
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
30
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
31 #include <gtk/gtk.h>
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
32 #include <audacious/plugin.h>
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
33 #include <audacious/configdb.h>
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
34 #include <SDL/SDL.h>
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
35 #include <SDL/SDL_thread.h>
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
36
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
37 #include "pn.h"
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
38
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
39 /* Paranormal visualization object */
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
40 static PnVis *vis;
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
41
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
42 /* Paranormal audio data object */
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
43 static PnAudioData *audio_data;
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
44
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
45 /* SDL window's surface */
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
46 static SDL_Surface *screen;
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
47
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
48 /* Synchronization stuffs */
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
49 static SDL_Thread *render_thread;
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
50 static int render_func (void *data);
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
51 static gboolean kill_render_thread;
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
52 static gboolean quit_timeout_func (gpointer data);
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
53 static guint quit_timeout;
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
54 static gboolean render_thread_finished;
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
55
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
56 static SDL_mutex *vis_mutex;
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
57 static SDL_mutex *audio_data_mutex;
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
58 static gfloat intermediate_pcm_data[3][512];
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
59 static gfloat intermediate_freq_data[3][256];
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
60
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
61 /* PNXMMS Options */
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
62 static gboolean options_read = FALSE;
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
63 static gboolean preset_changed = FALSE;
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
64 static gchar *preset;
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
65 static guint image_width = 320;
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
66 static guint image_height = 240;
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
67
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
68 /* Config dialog */
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
69 GtkWidget *config_dialog;
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
70 GtkWidget *load_button;
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
71
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
72 /* Config functions */
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
73 static void read_options (void);
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
74 static void write_options (void);
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
75 static void load_default_vis (void);
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
76 static void create_config_dialog (void);
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
77
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
78 /* Rendering functions */
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
79 static void draw_image (PnImage *image);
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
80
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
81 /* XMMS interface */
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
82 static void pn_xmms_init (void);
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
83 static void pn_xmms_cleanup (void);
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
84 static void pn_xmms_about (void);
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
85 static void pn_xmms_configure (void);
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
86 static void pn_xmms_render_pcm (gint16 data[2][512]);
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
87 static void pn_xmms_render_freq (gint16 data[2][256]);
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
88
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
89 static VisPlugin pn_xmms_vp =
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
90 {
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
91 NULL, /* handle */
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
92 NULL, /* filename */
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
93 0, /* xmms_session */
1524
a2a3fd886132 [svn] - some cleanups
nenolod
parents: 1522
diff changeset
94 "Paranormal Visualization Studio " VERSION,
1521
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
95 2,
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
96 2,
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
97 pn_xmms_init,
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
98 pn_xmms_cleanup,
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
99 NULL, /* pn_xmms_about, */
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
100 pn_xmms_configure,
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
101 NULL, /* disable_plugin */
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
102 NULL, /* playback_start */
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
103 NULL, /* pkayback_stop */
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
104 pn_xmms_render_pcm,
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
105 pn_xmms_render_freq
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
106 };
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
107
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
108 VisPlugin*
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
109 get_vplugin_info (void)
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
110 {
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
111 return &pn_xmms_vp;
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
112 }
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
113
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
114 static void
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
115 pn_xmms_init (void)
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
116 {
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
117 /* Load the saved options */
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
118 read_options ();
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
119
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
120 /* Initialize SDL */
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
121 if (SDL_Init (SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE) < 0)
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
122 {
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
123 g_warning ("Unable to initialize SDL: %s\n", SDL_GetError ());
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
124 pn_xmms_vp.disable_plugin (&pn_xmms_vp);
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
125 }
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
126
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
127 screen = SDL_SetVideoMode (image_width, image_height, 32, SDL_HWSURFACE | SDL_DOUBLEBUF | SDL_RESIZABLE);
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
128 if (! screen)
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
129 {
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
130 g_warning ("Unable to create a new SDL window: %s\n", SDL_GetError ());
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
131 pn_xmms_vp.disable_plugin (&pn_xmms_vp);
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
132 }
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
133
1524
a2a3fd886132 [svn] - some cleanups
nenolod
parents: 1522
diff changeset
134 SDL_WM_SetCaption ("Paranormal Visualization Studio " VERSION, PACKAGE);
1521
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
135
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
136 /* Initialize Paranormal */
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
137 pn_init ();
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
138
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
139 /* Set up the visualization objects */
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
140 vis = pn_vis_new (image_width, image_height);
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
141 pn_object_ref (PN_OBJECT (vis));
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
142 pn_object_sink (PN_OBJECT (vis));
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
143
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
144 if (! preset || ! pn_vis_load_from_file (vis, preset))
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
145 load_default_vis ();
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
146
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
147 audio_data = pn_audio_data_new ();
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
148 pn_object_ref (PN_OBJECT (audio_data));
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
149 pn_object_sink (PN_OBJECT (audio_data));
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
150 pn_audio_data_set_stereo (audio_data, FALSE);
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
151 pn_audio_data_set_pcm_samples (audio_data, 512);
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
152 pn_audio_data_set_freq_bands (audio_data, 256);
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
153
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
154 /* Set up the render thread */
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
155 audio_data_mutex = SDL_CreateMutex ();
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
156 vis_mutex = SDL_CreateMutex ();
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
157 if (! audio_data_mutex || ! vis_mutex)
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
158 {
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
159 g_warning ("Unable to create mutex: %s\n", SDL_GetError ());
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
160 pn_xmms_vp.disable_plugin (&pn_xmms_vp);
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
161 }
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
162
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
163 kill_render_thread = FALSE;
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
164 render_thread_finished = FALSE;
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
165 render_thread = SDL_CreateThread (render_func, NULL);
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
166 if (! render_thread)
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
167 {
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
168 g_warning ("Unable to create render thread: %s\n", SDL_GetError ());
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
169 pn_xmms_vp.disable_plugin (&pn_xmms_vp);
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
170 }
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
171
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
172 /* Create the quit-checker timeout */
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
173 quit_timeout = gtk_timeout_add (500, quit_timeout_func, NULL);
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
174 }
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
175
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
176 static void
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
177 pn_xmms_cleanup (void)
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
178 {
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
179 if (quit_timeout != 0)
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
180 {
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
181 gtk_timeout_remove (quit_timeout);
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
182 quit_timeout = 0;
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
183 }
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
184
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
185 if (render_thread)
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
186 {
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
187 kill_render_thread = TRUE;
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
188 SDL_WaitThread (render_thread, NULL);
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
189 render_thread = NULL;
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
190 }
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
191
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
192 if (audio_data_mutex)
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
193 {
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
194 SDL_DestroyMutex (audio_data_mutex);
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
195 audio_data_mutex = NULL;
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
196 }
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
197
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
198 if (screen)
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
199 {
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
200 SDL_FreeSurface (screen);
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
201 screen = NULL;
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
202 }
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
203 SDL_Quit ();
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
204
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
205 if (vis)
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
206 {
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
207 pn_object_unref (PN_OBJECT (vis));
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
208 vis = NULL;
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
209 }
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
210
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
211 write_options ();
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
212 }
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
213
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
214 static void
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
215 pn_xmms_about (void)
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
216 {
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
217 /* FIXME: This needs to wait until XMMS supports GTK+ 2.0 */
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
218 }
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
219
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
220 static void
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
221 pn_xmms_configure (void)
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
222 {
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
223 read_options ();
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
224 create_config_dialog ();
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
225 }
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
226
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
227 static void
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
228 pn_xmms_render_pcm (gint16 data[2][512])
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
229 {
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
230 guint i;
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
231
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
232 /* Set up the audio data */
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
233 for (i=0; i<512; i++)
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
234 {
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
235 intermediate_pcm_data[PN_CHANNEL_LEFT][i] = (gfloat)(data[0][i]) / 32768.0;
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
236 intermediate_pcm_data[PN_CHANNEL_RIGHT][i] = (gfloat)(data[0][i]) / 32768.0;
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
237 intermediate_pcm_data[PN_CHANNEL_CENTER][i] = .5 * (intermediate_pcm_data[PN_CHANNEL_LEFT][i]
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
238 + intermediate_pcm_data[PN_CHANNEL_RIGHT][i]);
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
239 }
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
240 }
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
241
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
242 static void
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
243 pn_xmms_render_freq (gint16 data[2][256])
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
244 {
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
245 guint i;
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
246
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
247 /* Set up the audio data */
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
248 for (i=0; i<256; i++)
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
249 {
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
250 intermediate_freq_data[PN_CHANNEL_LEFT][i] = (gfloat)(data[0][i]) / 32768.0;
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
251 intermediate_freq_data[PN_CHANNEL_RIGHT][i] = (gfloat)(data[0][i]) / 32768.0;
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
252 intermediate_freq_data[PN_CHANNEL_CENTER][i] = .5 * (intermediate_freq_data[PN_CHANNEL_LEFT][i]
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
253 + intermediate_freq_data[PN_CHANNEL_RIGHT][i]);
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
254 }
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
255 }
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
256
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
257 static gboolean
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
258 quit_timeout_func (gpointer data)
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
259 {
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
260 if (render_thread_finished)
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
261 {
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
262 pn_xmms_vp.disable_plugin (&pn_xmms_vp);
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
263 quit_timeout = 0;
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
264 return FALSE;
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
265 }
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
266 return TRUE;
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
267 }
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
268
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
269 static int
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
270 render_func (void *data)
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
271 {
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
272 guint i;
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
273 PnImage *image;
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
274 guint last_time = 0, last_second = 0;
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
275 gfloat fps = 0.0;
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
276 guint this_time;
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
277 SDL_Event event;
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
278
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
279 while (! kill_render_thread)
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
280 {
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
281 /* Lock & copy the audio data */
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
282 SDL_mutexP (audio_data_mutex);
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
283
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
284 for (i=0; i<3; i++)
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
285 {
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
286 memcpy (PN_AUDIO_DATA_PCM_DATA (audio_data, i), intermediate_pcm_data[i], 512 * sizeof (gfloat));
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
287 memcpy (PN_AUDIO_DATA_FREQ_DATA (audio_data, i), intermediate_freq_data[i], 256 * sizeof (gfloat));
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
288 }
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
289
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
290 SDL_mutexV (audio_data_mutex);
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
291
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
292 pn_audio_data_update (audio_data);
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
293
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
294 /* Render the image */
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
295 SDL_mutexP (vis_mutex);
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
296 image = pn_vis_render (vis, audio_data);
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
297 SDL_mutexV (vis_mutex);
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
298
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
299 /* Draw the image */
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
300 draw_image (image);
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
301
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
302 /* Compute the FPS */
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
303 this_time = SDL_GetTicks ();
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
304
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
305 fps = fps * .95 + (1000.0 / (gfloat) (this_time - last_time)) * .05;
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
306 if (this_time > 2000 + last_second)
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
307 {
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
308 last_second = this_time;
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
309 printf ("paranormal fps: %f\n", fps);
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
310 }
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
311 last_time = this_time;
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
312
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
313 /* Handle window events */
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
314 while (SDL_PollEvent (&event))
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
315 {
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
316 switch (event.type)
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
317 {
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
318 case SDL_QUIT:
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
319 render_thread_finished = TRUE;
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
320 return 0;
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
321
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
322 case SDL_VIDEORESIZE:
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
323 image_width = event.resize.w;
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
324 image_height = event.resize.h;
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
325 screen = SDL_SetVideoMode (image_width, image_height, 32,
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
326 SDL_HWSURFACE | SDL_DOUBLEBUF | SDL_RESIZABLE);
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
327 printf ("changed to: w: %u, h: %u\n", image_width, image_height);
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
328 pn_vis_set_image_size (vis, image_width, image_height);
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
329 break;
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
330
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
331 case SDL_KEYDOWN:
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
332 switch (event.key.keysym.sym)
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
333 {
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
334 case SDLK_ESCAPE:
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
335 render_thread_finished = TRUE;
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
336 return 0;
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
337
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
338 case SDLK_RETURN:
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
339 if (event.key.keysym.mod & (KMOD_ALT | KMOD_META))
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
340 {
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
341 /* Toggle fullscreen */
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
342 SDL_WM_ToggleFullScreen (screen);
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
343 if (SDL_ShowCursor (SDL_QUERY) == SDL_ENABLE)
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
344 SDL_ShowCursor (SDL_DISABLE);
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
345 else
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
346 SDL_ShowCursor (SDL_ENABLE);
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
347 }
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
348 break;
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
349 case SDLK_BACKQUOTE:
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
350 {
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
351 char fname[20];
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
352 int i = 0;
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
353 struct stat buf;
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
354
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
355 do
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
356 {
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
357 sprintf (fname, "pnxmms_ss_%05u.bmp", i++);
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
358 } while(!(stat(fname, &buf) != 0 && errno == ENOENT ));
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
359 SDL_SaveBMP(screen, fname);
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
360 }
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
361 break;
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
362
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
363 default:
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
364 break;
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
365 }
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
366 break;
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
367 }
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
368 }
1530
bdb22d1e6302 [svn] - don't peg the CPU
nenolod
parents: 1525
diff changeset
369
bdb22d1e6302 [svn] - don't peg the CPU
nenolod
parents: 1525
diff changeset
370 /* don't lock the CPU :P */
bdb22d1e6302 [svn] - don't peg the CPU
nenolod
parents: 1525
diff changeset
371 g_usleep(10000);
1521
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
372 }
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
373
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
374 return 0;
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
375 }
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
376
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
377 static void
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
378 draw_image (PnImage *image)
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
379 {
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
380 guint width, height, src_stride, dest_stride;
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
381 guint i;
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
382 register PnColor *src;
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
383 register Uint32 *dest;
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
384
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
385 /* Lock the SDL surface */
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
386 SDL_LockSurface (screen);
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
387
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
388 /* Get the dimentions */
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
389 width = pn_image_get_width (image);
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
390 height = pn_image_get_height (image);
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
391
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
392 src_stride = pn_image_get_pitch (image) >> 2;
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
393 dest_stride = screen->pitch >> 2;
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
394
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
395 src = pn_image_get_image_buffer (image);
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
396 dest = (Uint32 *) screen->pixels;
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
397
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
398 /* Copy the pixel data */
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
399 while (--height > 0)
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
400 {
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
401 for (i=0; i<width; i++)
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
402 dest[i] = SDL_MapRGB (screen->format, src[i].red, src[i].green, src[i].blue);
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
403 dest += dest_stride;
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
404 src += src_stride;
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
405 }
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
406
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
407 /* Unlock the SDL surface */
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
408 SDL_UnlockSurface (screen);
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
409
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
410 /* Draw it to the screen */
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
411 SDL_Flip (screen);
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
412 }
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
413
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
414 static void
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
415 read_options (void)
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
416 {
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
417 ConfigDb *cfg;
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
418 gint i;
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
419
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
420 if (options_read == TRUE)
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
421 return;
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
422
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
423 cfg = bmp_cfg_db_open ();
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
424 if (!cfg)
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
425 return;
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
426
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
427 if (bmp_cfg_db_get_int (cfg, "pnxmms", "image_width", &i))
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
428 image_width = i;
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
429
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
430 if (bmp_cfg_db_get_int (cfg, "pnxmms", "image_height", &i))
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
431 image_height = i;
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
432
1532
f74a6ba233c2 [svn] - allow configdb::pnxmms::preset to set what pn preset to load on start
nenolod
parents: 1530
diff changeset
433 bmp_cfg_db_get_string (cfg, "pnxmms", "preset", &preset);
f74a6ba233c2 [svn] - allow configdb::pnxmms::preset to set what pn preset to load on start
nenolod
parents: 1530
diff changeset
434
1521
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
435 bmp_cfg_db_close (cfg);
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
436
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
437 return;
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
438 }
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
439
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
440 static void
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
441 write_options (void)
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
442 {
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
443 ConfigDb *cfg;
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
444
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
445 cfg = bmp_cfg_db_open ();
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
446 if (!cfg)
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
447 fprintf (stderr, "PNXMMS: Unable to open XMMS config file!\n");
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
448
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
449 bmp_cfg_db_set_int (cfg, "pnxmms", "image_width", image_width);
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
450 bmp_cfg_db_set_int (cfg, "pnxmms", "image_height", image_height);
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
451
1532
f74a6ba233c2 [svn] - allow configdb::pnxmms::preset to set what pn preset to load on start
nenolod
parents: 1530
diff changeset
452 if (preset)
f74a6ba233c2 [svn] - allow configdb::pnxmms::preset to set what pn preset to load on start
nenolod
parents: 1530
diff changeset
453 bmp_cfg_db_set_string (cfg, "pnxmms", "preset", preset);
f74a6ba233c2 [svn] - allow configdb::pnxmms::preset to set what pn preset to load on start
nenolod
parents: 1530
diff changeset
454
1521
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
455 bmp_cfg_db_close (cfg);
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
456 }
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
457
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
458 static void
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
459 load_default_vis (void)
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
460 {
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
461 PnContainer *container;
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
462 PnActuator *actuator;
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
463 PnOption *option;
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
464
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
465 /* Actuator List */
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
466 container = (PnContainer *) pn_actuator_list_new ();
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
467
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
468 /* Scope */
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
469 actuator = (PnActuator *) pn_scope_new ();
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
470 option = pn_actuator_get_option_by_name (actuator, "init_script");
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
471 pn_string_option_set_value (PN_STRING_OPTION (option), "samples = width/2;");
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
472 option = pn_actuator_get_option_by_name (actuator, "frame_script");
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
473 pn_string_option_set_value (PN_STRING_OPTION (option),
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
474 "base = base + .04;\n"
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
475 "red = abs (sin (.5 * pi + .1 * base));\n"
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
476 "green = .5 * abs (sin (.5 * pi - .2 * base));\n"
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
477 "blue = abs (sin (.5 * pi + .3 * base));");
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
478 option = pn_actuator_get_option_by_name (actuator, "sample_script");
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
479 pn_string_option_set_value (PN_STRING_OPTION (option),
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
480 "x = 2 * iteration - 1;\n"
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
481 "y = value;");
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
482 option = pn_actuator_get_option_by_name (actuator, "draw_method");
1522
95e71054ecbd [svn] - gah
nenolod
parents: 1521
diff changeset
483 pn_list_option_set_index (PN_LIST_OPTION (option), 1);
1521
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
484 pn_container_add_actuator (container, actuator, PN_POSITION_TAIL);
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
485
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
486 /* Distortion */
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
487 actuator = (PnActuator *) pn_distortion_new ();
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
488 option = pn_actuator_get_option_by_name (actuator, "distortion_script");
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
489 pn_string_option_set_value (PN_STRING_OPTION (option),
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
490 "intensity = .99 + .08 * r;\n"
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
491 "r = .98 * atan (r);\n"
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
492 "theta = theta + .01;");
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
493 option = pn_actuator_get_option_by_name (actuator, "polar_coords");
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
494 pn_boolean_option_set_value (PN_BOOLEAN_OPTION (option), TRUE);
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
495 pn_container_add_actuator (container, actuator, PN_POSITION_TAIL);
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
496
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
497 /* Add the actuator list to the vis */
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
498 pn_vis_set_root_actuator (vis, PN_ACTUATOR (container));
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
499 }
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
500
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
501 static void
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
502 apply_settings (void)
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
503 {
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
504 if (preset_changed)
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
505 {
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
506 preset_changed = FALSE;
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
507 SDL_mutexP (vis_mutex);
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
508 pn_vis_load_from_file (vis, preset);
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
509 SDL_mutexV (vis_mutex);
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
510 }
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
511
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
512 write_options ();
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
513 }
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
514
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
515 static void
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
516 destroy_config_dialog (GtkObject *user_data, gpointer data)
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
517 {
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
518 gtk_widget_destroy (GTK_WIDGET(config_dialog));
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
519 config_dialog = NULL;
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
520 }
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
521
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
522 static void
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
523 apply_button_cb (GtkButton *button, gpointer data)
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
524 {
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
525 apply_settings ();
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
526 }
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
527
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
528 static void
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
529 ok_button_cb (GtkButton *button, gpointer data)
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
530 {
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
531 apply_settings ();
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
532 destroy_config_dialog (NULL, NULL);
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
533 }
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
534
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
535 static void
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
536 cancel_button_cb (GtkButton *button, gpointer data)
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
537 {
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
538 destroy_config_dialog (NULL, NULL);
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
539 }
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
540
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
541 /* If selector != NULL, then it's 'OK', otherwise it's 'Cancel' */
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
542 static void
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
543 load_preset_cb (GtkButton *button, GtkFileSelection *selector)
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
544 {
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
545 if (selector)
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
546 {
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
547 if (preset)
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
548 g_free (preset);
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
549 preset = g_strdup (gtk_file_selection_get_filename (selector));
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
550 gtk_label_set_text (GTK_LABEL (GTK_BIN (load_button)->child), preset);
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
551 preset_changed = TRUE;
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
552 }
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
553
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
554 gtk_widget_set_sensitive (config_dialog, TRUE);
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
555 }
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
556
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
557 static void
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
558 load_preset_button_cb (GtkButton *button, gpointer data)
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
559 {
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
560 GtkWidget *selector;
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
561
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
562 selector = gtk_file_selection_new ("Load Preset");
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
563
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
564 gtk_signal_connect (GTK_OBJECT (GTK_FILE_SELECTION (selector)->ok_button),
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
565 "clicked", GTK_SIGNAL_FUNC (load_preset_cb), selector);
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
566 gtk_signal_connect (GTK_OBJECT (GTK_FILE_SELECTION (selector)->cancel_button),
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
567 "clicked", GTK_SIGNAL_FUNC (load_preset_cb), NULL);
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
568
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
569 gtk_signal_connect_object (GTK_OBJECT (GTK_FILE_SELECTION (selector)->ok_button),
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
570 "clicked", GTK_SIGNAL_FUNC (gtk_widget_destroy),
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
571 (gpointer) selector);
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
572 gtk_signal_connect_object (GTK_OBJECT (GTK_FILE_SELECTION (selector)->cancel_button),
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
573 "clicked", GTK_SIGNAL_FUNC (gtk_widget_destroy),
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
574 (gpointer) selector);
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
575
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
576 gtk_widget_set_sensitive (config_dialog, FALSE);
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
577 gtk_widget_show (selector);
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
578 }
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
579
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
580 static void
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
581 create_config_dialog (void)
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
582 {
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
583 GtkWidget *bbox, *button, *vbox, *frame, *table, *label;
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
584
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
585 if (config_dialog != NULL)
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
586 return;
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
587
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
588 /* Create the dialog */
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
589 config_dialog = gtk_dialog_new ();
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
590 gtk_window_set_title (GTK_WINDOW (config_dialog), PACKAGE " " VERSION
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
591 " - Configuration");
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
592 gtk_widget_set_usize (config_dialog, 500, 300);
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
593 gtk_container_border_width (GTK_CONTAINER (config_dialog), 8);
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
594 gtk_signal_connect_object (GTK_OBJECT (config_dialog), "delete-event",
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
595 destroy_config_dialog, NULL);
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
596
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
597 /* OK / Cancel / Apply */
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
598 bbox = gtk_hbutton_box_new ();
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
599 gtk_widget_show (bbox);
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
600 gtk_button_box_set_layout (GTK_BUTTON_BOX (bbox), GTK_BUTTONBOX_END);
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
601 gtk_button_box_set_spacing (GTK_BUTTON_BOX (bbox), 8);
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
602 gtk_button_box_set_child_size (GTK_BUTTON_BOX (bbox), 64, 0);
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
603 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (config_dialog)->action_area),
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
604 bbox, FALSE, FALSE, 0);
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
605 button = gtk_button_new_with_label ("OK");
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
606 gtk_widget_show (button);
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
607 gtk_button_set_relief (GTK_BUTTON (button), GTK_RELIEF_NORMAL);
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
608 gtk_signal_connect (GTK_OBJECT (button), "clicked",
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
609 GTK_SIGNAL_FUNC (ok_button_cb), NULL);
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
610 gtk_box_pack_start (GTK_BOX (bbox), button, FALSE, FALSE, 0);
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
611 button = gtk_button_new_with_label ("Cancel");
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
612 gtk_widget_show (button);
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
613 gtk_button_set_relief (GTK_BUTTON (button), GTK_RELIEF_NORMAL);
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
614 gtk_signal_connect (GTK_OBJECT (button), "clicked",
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
615 GTK_SIGNAL_FUNC (cancel_button_cb), NULL);
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
616 gtk_box_pack_start (GTK_BOX (bbox), button, FALSE, FALSE, 0);
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
617 button = gtk_button_new_with_label ("Apply");
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
618 gtk_widget_show (button);
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
619 gtk_button_set_relief (GTK_BUTTON (button), GTK_RELIEF_NORMAL);
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
620 gtk_signal_connect (GTK_OBJECT (button), "clicked",
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
621 GTK_SIGNAL_FUNC (apply_button_cb), NULL);
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
622 gtk_box_pack_start (GTK_BOX (bbox), button, FALSE, FALSE, 0);
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
623
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
624
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
625 /* The vertical box */
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
626 vbox = gtk_vbox_new (FALSE, 1);
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
627 gtk_widget_show (vbox);
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
628 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (config_dialog)->vbox), vbox,
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
629 TRUE, TRUE, 0);
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
630
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
631 /* General options */
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
632 frame = gtk_frame_new (NULL);
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
633 gtk_widget_show (frame);
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
634 gtk_box_pack_start (GTK_BOX (vbox), frame, TRUE, TRUE, 0);
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
635 gtk_frame_set_label (GTK_FRAME (frame), "General");
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
636 table = gtk_table_new (2, 1, TRUE);
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
637 gtk_widget_show (table);
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
638 gtk_container_add (GTK_CONTAINER (frame), table);
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
639 label = gtk_label_new ("Preset File: ");
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
640 gtk_widget_show (label);
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
641 gtk_table_attach (GTK_TABLE (table), label, 0, 1, 0, 1,
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
642 GTK_FILL, 0, 3, 3);
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
643 load_button = gtk_button_new_with_label (preset ? preset : "<default>");
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
644 gtk_widget_show (load_button);
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
645 gtk_table_attach (GTK_TABLE (table), load_button, 1, 2, 0, 1,
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
646 GTK_EXPAND | GTK_FILL, 0, 3, 3);
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
647 gtk_signal_connect (GTK_OBJECT (load_button), "clicked",
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
648 GTK_SIGNAL_FUNC (load_preset_button_cb), NULL);
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
649
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
650 /* Show it all */
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
651 gtk_widget_show (config_dialog);
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
652 gtk_widget_grab_focus (config_dialog);
752f35f5a799 [svn] - paranormal in theory works on audacious
nenolod
parents:
diff changeset
653 }