Mercurial > audlegacy
annotate Plugins/Input/console/Audacious_Driver.cpp @ 109:c4876d6c9cc0 trunk
[svn] Add about box.
author | nenolod |
---|---|
date | Wed, 02 Nov 2005 22:07:17 -0800 |
parents | cde5ca21ddc3 |
children | 3fb426494de8 |
rev | line source |
---|---|
90
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
1 /* |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
2 * Audacious: Cross platform multimedia player |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
3 * Copyright (c) 2005 Audacious Team |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
4 * |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
5 * Driver for Game_Music_Emu library. See details at: |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
6 * http://www.slack.net/~ant/libs/ |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
7 */ |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
8 |
94 | 9 #include "Audacious_Driver.h" |
90
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
10 |
98
e42694a28331
[svn] More progress -- now loads as an audacious module. :)
nenolod
parents:
96
diff
changeset
|
11 extern "C" { |
e42694a28331
[svn] More progress -- now loads as an audacious module. :)
nenolod
parents:
96
diff
changeset
|
12 |
109 | 13 #include <glib.h> |
96 | 14 #include <glib/gi18n.h> |
109 | 15 #include <gtk/gtk.h> |
94 | 16 #include "libaudacious/configfile.h" |
17 #include "libaudacious/util.h" | |
18 #include "libaudacious/titlestring.h" | |
95 | 19 #include "audacious/output.h" |
94 | 20 |
98
e42694a28331
[svn] More progress -- now loads as an audacious module. :)
nenolod
parents:
96
diff
changeset
|
21 }; |
e42694a28331
[svn] More progress -- now loads as an audacious module. :)
nenolod
parents:
96
diff
changeset
|
22 |
94 | 23 #include <cstring> |
24 | |
101
59ba6595fdf1
[svn] More accurate sound reproduction, but there is warbling. Still locks up player on completion.
nenolod
parents:
100
diff
changeset
|
25 #ifdef WORDS_BIGENDIAN |
59ba6595fdf1
[svn] More accurate sound reproduction, but there is warbling. Still locks up player on completion.
nenolod
parents:
100
diff
changeset
|
26 # define MY_FMT FMT_S16_BE |
59ba6595fdf1
[svn] More accurate sound reproduction, but there is warbling. Still locks up player on completion.
nenolod
parents:
100
diff
changeset
|
27 #else |
59ba6595fdf1
[svn] More accurate sound reproduction, but there is warbling. Still locks up player on completion.
nenolod
parents:
100
diff
changeset
|
28 # define MY_FMT FMT_S16_LE |
59ba6595fdf1
[svn] More accurate sound reproduction, but there is warbling. Still locks up player on completion.
nenolod
parents:
100
diff
changeset
|
29 #endif |
59ba6595fdf1
[svn] More accurate sound reproduction, but there is warbling. Still locks up player on completion.
nenolod
parents:
100
diff
changeset
|
30 |
94 | 31 static Spc_Emu *spc = NULL; |
95 | 32 static GThread *decode_thread; |
33 | |
34 static void *play_loop(gpointer arg); | |
100 | 35 static void console_init(void); |
109 | 36 extern "C" void console_aboutbox(void); |
96 | 37 static void console_stop(void); |
38 static void console_pause(gshort p); | |
39 static int get_time(void); | |
103 | 40 static gboolean console_ip_is_going; |
94 | 41 |
100 | 42 extern InputPlugin console_ip; |
43 | |
94 | 44 static int is_our_file(gchar *filename) |
45 { | |
46 gchar *ext; | |
47 | |
48 ext = strrchr(filename, '.'); | |
49 | |
50 if (ext) | |
51 { | |
52 if (!strcasecmp(ext, ".spc")) | |
53 return 1; | |
54 } | |
55 | |
56 return 0; | |
57 } | |
58 | |
59 static gchar *get_title(gchar *filename) | |
60 { | |
61 gchar *title; | |
62 Emu_Std_Reader reader; | |
63 Spc_Emu::header_t header; | |
64 | |
65 reader.open(filename); | |
66 reader.read(&header, sizeof(header)); | |
67 | |
104 | 68 if (header.song) |
69 { | |
70 TitleInput *tinput; | |
71 | |
72 tinput = bmp_title_input_new(); | |
73 | |
105
18fe59468510
[svn] Use header.game, over header.author, as most SPC files do not contain the composer information.
nenolod
parents:
104
diff
changeset
|
74 tinput->performer = g_strdup(header.game); |
104 | 75 tinput->album_name = g_strdup(header.game); |
76 tinput->track_name = g_strdup(header.song); | |
94 | 77 |
104 | 78 tinput->file_name = g_path_get_basename(filename); |
79 tinput->file_path = g_path_get_dirname(filename); | |
80 | |
81 title = xmms_get_titlestring(xmms_get_gentitle_format(), | |
82 tinput); | |
83 | |
84 g_free(tinput); | |
85 } | |
86 else | |
87 title = g_strdup(filename); | |
99 | 88 |
94 | 89 return title; |
90 } | |
95 | 91 |
92 static void get_song_info(char *filename, char **title, int *length) | |
93 { | |
94 (*title) = get_title(filename); | |
95 (*length) = -1; | |
96 } | |
97 | |
98 static void play_file(char *filename) | |
99 { | |
106
d2b88d78ccd7
[svn] Tell the player that the decoder has fired up :)
nenolod
parents:
105
diff
changeset
|
100 gchar *name; |
95 | 101 Emu_Std_Reader reader; |
102 Spc_Emu::header_t header; | |
103 | |
104 reader.open(filename); | |
105 reader.read(&header, sizeof(header)); | |
106 | |
107 spc = new Spc_Emu; | |
101
59ba6595fdf1
[svn] More accurate sound reproduction, but there is warbling. Still locks up player on completion.
nenolod
parents:
100
diff
changeset
|
108 spc->init(32000); |
95 | 109 spc->load(header, reader); |
110 spc->start_track(0); | |
111 | |
103 | 112 console_ip_is_going = TRUE; |
113 | |
106
d2b88d78ccd7
[svn] Tell the player that the decoder has fired up :)
nenolod
parents:
105
diff
changeset
|
114 name = get_title(filename); |
d2b88d78ccd7
[svn] Tell the player that the decoder has fired up :)
nenolod
parents:
105
diff
changeset
|
115 |
109 | 116 console_ip.set_info(name, -1, spc->voice_count(), 32000, 2); |
106
d2b88d78ccd7
[svn] Tell the player that the decoder has fired up :)
nenolod
parents:
105
diff
changeset
|
117 |
d2b88d78ccd7
[svn] Tell the player that the decoder has fired up :)
nenolod
parents:
105
diff
changeset
|
118 g_free(name); |
d2b88d78ccd7
[svn] Tell the player that the decoder has fired up :)
nenolod
parents:
105
diff
changeset
|
119 |
99 | 120 decode_thread = g_thread_create(play_loop, spc, TRUE, NULL); |
121 | |
102
de414e40f772
[svn] Normal sound decoding, now to just figure out how to stop the decode_thread when we need to.
nenolod
parents:
101
diff
changeset
|
122 if (!console_ip.output->open_audio(MY_FMT, 32000, 2)) |
100 | 123 return; |
95 | 124 } |
125 | |
96 | 126 static void seek(gint time) |
127 { | |
128 // XXX: Not yet implemented | |
129 } | |
130 | |
131 InputPlugin console_ip = { | |
132 NULL, | |
133 NULL, | |
134 NULL, | |
135 console_init, | |
109 | 136 console_aboutbox, |
96 | 137 NULL, |
138 is_our_file, | |
139 NULL, | |
140 play_file, | |
141 console_stop, | |
142 console_pause, | |
143 seek, | |
144 NULL, | |
145 get_time, | |
146 NULL, | |
147 NULL, | |
148 NULL, | |
149 NULL, | |
150 NULL, | |
151 NULL, | |
152 NULL, | |
104 | 153 get_song_info, |
96 | 154 NULL, |
155 NULL | |
156 }; | |
157 | |
158 static void console_stop(void) | |
159 { | |
103 | 160 console_ip_is_going = FALSE; |
96 | 161 g_thread_join(decode_thread); |
162 console_ip.output->close_audio(); | |
163 } | |
164 | |
98
e42694a28331
[svn] More progress -- now loads as an audacious module. :)
nenolod
parents:
96
diff
changeset
|
165 extern "C" InputPlugin *get_iplugin_info(void) |
96 | 166 { |
109 | 167 console_ip.description = g_strdup_printf(_("SPC, GYM, NSF, VGM and GBS module decoder")); |
96 | 168 return &console_ip; |
169 } | |
170 | |
171 static void console_pause(gshort p) | |
172 { | |
173 console_ip.output->pause(p); | |
174 } | |
175 | |
95 | 176 static void *play_loop(gpointer arg) |
177 { | |
99 | 178 Spc_Emu *my_spc = (Spc_Emu *) arg; |
108 | 179 Music_Emu::sample_t buf[1024]; |
95 | 180 |
108 | 181 while (my_spc->play(1024, buf) == NULL && console_ip_is_going == TRUE) |
96 | 182 { |
100 | 183 console_ip.add_vis_pcm(console_ip.output->written_time(), |
108 | 184 MY_FMT, 1, 2048, buf); |
185 while(console_ip.output->buffer_free() < 2048) | |
101
59ba6595fdf1
[svn] More accurate sound reproduction, but there is warbling. Still locks up player on completion.
nenolod
parents:
100
diff
changeset
|
186 xmms_usleep(10000); |
108 | 187 console_ip.output->write_audio(buf, 2048); |
100 | 188 } |
95 | 189 |
96 | 190 delete spc; |
191 g_thread_exit(NULL); | |
95 | 192 |
96 | 193 return NULL; |
95 | 194 } |
195 | |
96 | 196 static int get_time(void) |
197 { | |
198 return console_ip.output->output_time(); | |
199 } | |
95 | 200 |
100 | 201 static void console_init(void) |
202 { | |
203 | |
204 } | |
205 | |
109 | 206 extern "C" void console_aboutbox(void) |
207 { | |
208 xmms_show_message(_("About the Console Music Decoder"), | |
209 _("Console music decoder engine based on Game_Music_Emu 0.2.4.\n" | |
210 "Audacious implementation by: William Pitcock <nenolod@nenolod.net>"), | |
211 _("Ok"), | |
212 FALSE, NULL, NULL); | |
213 } |