Mercurial > hg > xmms-sid
comparison src/xmms-sid.cc @ 69:bf6a524cf7ca dev-0-8-0a1
Fixes, cleanups, etc.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 30 Jun 2003 17:16:02 +0000 |
parents | bf7b647b3239 |
children |
comparison
equal
deleted
inserted
replaced
68:20695d619300 | 69:bf6a524cf7ca |
---|---|
133 return; | 133 return; |
134 } | 134 } |
135 #endif | 135 #endif |
136 | 136 |
137 /* Read song-length database */ | 137 /* Read song-length database */ |
138 if (xs_cfg.songlenDBEnable) | 138 if (xs_cfg.songlenDBEnable && (xs_songlen_init() < 0)) |
139 if (xs_songlen_init() < 0) | |
140 { | 139 { |
141 XSERR("Error initializing song-length database!\n"); | 140 XSERR("Error initializing song-length database!\n"); |
142 } | 141 } |
143 | 142 |
144 /* Initialize STIL structures */ | 143 /* Initialize STIL structures */ |
145 | 144 |
146 // xs_ctrlwin_open(); | 145 // xs_ctrlwin_open(); |
147 | 146 |
148 // FIXME FIXME FIx ME | 147 // FIXME FIXME FIx ME |
149 | 148 |
150 XSDEBUG("xs_init() done\n"); | 149 XSDEBUG("OK\n"); |
151 } | 150 } |
152 | 151 |
153 | 152 |
154 /* | 153 /* |
155 * Shut down XMMS-SID | 154 * Shut down XMMS-SID |
187 t_xs_tune *testTune; | 186 t_xs_tune *testTune; |
188 | 187 |
189 /* Check the filename */ | 188 /* Check the filename */ |
190 if (pcFileName == NULL) | 189 if (pcFileName == NULL) |
191 return FALSE; | 190 return FALSE; |
192 | |
193 XSDEBUG("testFile('%s')\n", pcFileName); | |
194 | 191 |
195 /* Try to detect via libSIDPlay's detection routine, if required */ | 192 /* Try to detect via libSIDPlay's detection routine, if required */ |
196 if (xs_cfg.detectMagic) | 193 if (xs_cfg.detectMagic) |
197 { | 194 { |
198 testTune = new t_xs_tune(pcFileName); | 195 testTune = new t_xs_tune(pcFileName); |
199 if (testTune == NULL) return FALSE; | 196 if (testTune == NULL) return FALSE; |
200 if (testTune->getStatus()) | 197 if (testTune->getStatus()) |
201 { | 198 { |
202 delete testTune; | 199 delete testTune; |
203 XSDEBUG("file = OK\n"); | |
204 return TRUE; | 200 return TRUE; |
205 } | 201 } |
206 | 202 |
207 /* We DON'T fall back to filename extension checking ... */ | 203 /* We DON'T fall back to filename extension checking ... */ |
208 delete testTune; | 204 delete testTune; |
209 XSDEBUG("file = kyrpe\n"); | |
210 return FALSE; | 205 return FALSE; |
211 } | 206 } |
212 | 207 |
213 /* Detect just by checking filename extension */ | 208 /* Detect just by checking filename extension */ |
214 pcExt = xs_strrchr(pcFileName, '.'); | 209 pcExt = xs_strrchr(pcFileName, '.'); |
220 if (!g_strcasecmp(pcExt, "dat")) return TRUE; | 215 if (!g_strcasecmp(pcExt, "dat")) return TRUE; |
221 if (!g_strcasecmp(pcExt, "inf")) return TRUE; | 216 if (!g_strcasecmp(pcExt, "inf")) return TRUE; |
222 if (!g_strcasecmp(pcExt, "info")) return TRUE; | 217 if (!g_strcasecmp(pcExt, "info")) return TRUE; |
223 } | 218 } |
224 | 219 |
225 XSDEBUG("file was KYRPE\n"); | |
226 return FALSE; | 220 return FALSE; |
227 } | 221 } |
228 | 222 |
229 | 223 |
230 /* | 224 /* |
236 t_xs_tuneinfo tuneInfo; | 230 t_xs_tuneinfo tuneInfo; |
237 gboolean audioOpen; | 231 gboolean audioOpen; |
238 gint audioFreq, audioChannels, songLength; | 232 gint audioFreq, audioChannels, songLength; |
239 enum AFormat audioFmt; | 233 enum AFormat audioFmt; |
240 gchar audioBuffer[XS_BUFSIZE]; | 234 gchar audioBuffer[XS_BUFSIZE]; |
241 | 235 gchar *tmpStr; |
242 /* Check status */ | 236 |
237 | |
238 pthread_mutex_lock(&xs_mutex); | |
243 XSDEBUG("entering play thread\n"); | 239 XSDEBUG("entering play thread\n"); |
244 pthread_mutex_lock(&xs_mutex); | 240 |
241 /* No idea, if this is really required here, but better be | |
242 * careful since we're dealing with EVIL threads ... | |
243 */ | |
245 if (!xs_status.allowNext) | 244 if (!xs_status.allowNext) |
246 { | 245 { |
247 pthread_mutex_unlock(&xs_mutex); | 246 pthread_mutex_unlock(&xs_mutex); |
248 pthread_exit(NULL); | 247 pthread_exit(NULL); |
249 } | 248 } |
251 /* Don't allow next song to be set yet */ | 250 /* Don't allow next song to be set yet */ |
252 xs_status.allowNext = FALSE; | 251 xs_status.allowNext = FALSE; |
253 xs_status.isPlaying = TRUE; | 252 xs_status.isPlaying = TRUE; |
254 memcpy(&myStatus, &xs_status, sizeof(t_xs_status)); | 253 memcpy(&myStatus, &xs_status, sizeof(t_xs_status)); |
255 pthread_mutex_unlock(&xs_mutex); | 254 pthread_mutex_unlock(&xs_mutex); |
255 | |
256 | 256 |
257 /* Copy and check audio options here (they might change in config while running) */ | 257 /* Copy and check audio options here (they might change in config while running) */ |
258 #ifdef HAVE_UNSIGNEDPCM | 258 #ifdef HAVE_UNSIGNEDPCM |
259 audioFmt = (xs_cfg.fmtBitsPerSample == XS_RES_16BIT) ? FMT_U16_NE : FMT_U8; | 259 audioFmt = (xs_cfg.fmtBitsPerSample == XS_RES_16BIT) ? FMT_U16_NE : FMT_U8; |
260 #else | 260 #else |
269 */ | 269 */ |
270 while (xs_status.isPlaying) | 270 while (xs_status.isPlaying) |
271 { | 271 { |
272 pthread_mutex_lock(&xs_mutex); | 272 pthread_mutex_lock(&xs_mutex); |
273 myStatus.currSong = xs_status.currSong; | 273 myStatus.currSong = xs_status.currSong; |
274 myStatus.isPlaying = TRUE; | |
274 pthread_mutex_unlock(&xs_mutex); | 275 pthread_mutex_unlock(&xs_mutex); |
275 | 276 |
276 XSDEBUG("sub-song %i selected, initializing...\n", myStatus.currSong); | 277 XSDEBUG("subtune #%i selected, initializing...\n", myStatus.currSong); |
278 | |
277 | 279 |
278 /* Get song length for current subtune */ | 280 /* Get song length for current subtune */ |
279 songLength = xs_songlen_get(myStatus.currFileName, myStatus.currSong); | 281 songLength = xs_songlen_get(myStatus.currFileName, myStatus.currSong); |
280 | 282 |
281 /* Initialize song */ | 283 /* Initialize song */ |
285 #endif | 287 #endif |
286 #ifdef HAVE_SIDPLAY2 | 288 #ifdef HAVE_SIDPLAY2 |
287 if () | 289 if () |
288 #endif | 290 #endif |
289 { | 291 { |
290 XSERR("Couldn't initialize SID-tune!\n"); | 292 XSERR("Couldn't initialize SID-tune '%s' (sub-tune #%i)!\n", |
291 pthread_mutex_lock(&xs_mutex); | 293 myStatus.currFileName, myStatus.currSong); |
292 xs_status.isError = TRUE; | |
293 pthread_mutex_unlock(&xs_mutex); | |
294 goto err_exit; | 294 goto err_exit; |
295 } | 295 } |
296 | 296 |
297 myStatus.currTune->getInfo(tuneInfo); | 297 myStatus.currTune->getInfo(tuneInfo); |
298 | |
299 | |
300 /* Set information for current sub-tune */ | |
301 tmpStr = xs_filetitle_get(myStatus.currFileName, &tuneInfo, myStatus.currSong); | |
302 | |
303 xs_plugin_ip.set_info(tmpStr, (songLength > 0) ? songLength * 1000 : -1, | |
304 1000 * (tuneInfo.songSpeed ? tuneInfo.songSpeed : (tuneInfo.clockSpeed == SIDTUNE_CLOCK_NTSC) ? 60 : 50), | |
305 audioFreq, audioChannels); | |
306 g_free(tmpStr); | |
298 | 307 |
299 /* Open the audio output */ | 308 /* Open the audio output */ |
300 if (!xs_plugin_ip.output->open_audio(audioFmt, audioFreq, audioChannels)) | 309 if (!xs_plugin_ip.output->open_audio(audioFmt, audioFreq, audioChannels)) |
301 { | 310 { |
302 XSERR("Couldn't open XMMS audio output!\n"); | 311 XSERR("Couldn't open XMMS audio output!\n"); |
306 goto err_exit; | 315 goto err_exit; |
307 } | 316 } |
308 | 317 |
309 audioOpen = TRUE; | 318 audioOpen = TRUE; |
310 | 319 |
311 /* Set some infoz */ | 320 /* |
312 xs_plugin_ip.set_info(tuneInfo.infoString[0], (songLength > 0) ? songLength * 1000 : -1, | 321 * Play the subtune |
313 1000 * (tuneInfo.songSpeed ? tuneInfo.songSpeed : (tuneInfo.clockSpeed == SIDTUNE_CLOCK_NTSC) ? 60 : 50), | 322 */ |
314 audioFreq, audioChannels); | 323 while (xs_status.isPlaying && myStatus.isPlaying && (xs_status.currSong == myStatus.currSong)) |
315 | 324 { |
316 XSDEBUG("rendering audio...\n"); | 325 /* Render audio data */ |
317 | |
318 /* Play the tune */ | |
319 while (xs_status.isPlaying && (xs_status.currSong == myStatus.currSong)) | |
320 { | |
321 #ifdef HAVE_SIDPLAY1 | 326 #ifdef HAVE_SIDPLAY1 |
322 sidEmuFillBuffer(xs_emuEngine, *myStatus.currTune, audioBuffer, XS_BUFSIZE); | 327 sidEmuFillBuffer(xs_emuEngine, *myStatus.currTune, audioBuffer, XS_BUFSIZE); |
323 #endif | 328 #endif |
324 | |
325 #ifdef HAVE_SIDPLAY2 | 329 #ifdef HAVE_SIDPLAY2 |
326 #endif | 330 #endif |
327 | 331 |
328 /* Visualice/haujobb */ | 332 /* I <3 visualice/haujobb */ |
329 xs_plugin_ip.add_vis_pcm( | 333 xs_plugin_ip.add_vis_pcm( |
330 xs_plugin_ip.output->written_time(), | 334 xs_plugin_ip.output->written_time(), |
331 audioFmt, audioChannels, XS_BUFSIZE, audioBuffer); | 335 audioFmt, audioChannels, XS_BUFSIZE, audioBuffer); |
332 | 336 |
333 /* Wait a little */ | 337 /* Wait a little */ |
345 { | 349 { |
346 if (xs_cfg.playMaxTimeUnknown) | 350 if (xs_cfg.playMaxTimeUnknown) |
347 { | 351 { |
348 if ((songLength == -1) && | 352 if ((songLength == -1) && |
349 (xs_plugin_ip.output->output_time() >= (xs_cfg.playMaxTime * 1000))) | 353 (xs_plugin_ip.output->output_time() >= (xs_cfg.playMaxTime * 1000))) |
350 xs_status.isPlaying = FALSE; | 354 myStatus.isPlaying = FALSE; |
351 } else { | 355 } else { |
352 if (xs_plugin_ip.output->output_time() >= (xs_cfg.playMaxTime * 1000)) | 356 if (xs_plugin_ip.output->output_time() >= (xs_cfg.playMaxTime * 1000)) |
353 xs_status.isPlaying = FALSE; | 357 myStatus.isPlaying = FALSE; |
354 } | 358 } |
355 } | 359 } |
356 | 360 |
357 if (songLength > 0) | 361 if (songLength > 0) |
358 { | 362 { |
359 if (xs_plugin_ip.output->output_time() >= (songLength * 1000)) | 363 if (xs_plugin_ip.output->output_time() >= (songLength * 1000)) |
360 xs_status.isPlaying = FALSE; | 364 myStatus.isPlaying = FALSE; |
361 } | 365 } |
362 } | 366 } |
363 | 367 |
364 XSDEBUG("tune ended/stopped\n"); | 368 XSDEBUG("subtune ended/stopped\n"); |
365 | 369 |
366 /* Close audio */ | 370 /* Close audio */ |
367 if (audioOpen) | 371 if (audioOpen) |
368 { | 372 { |
369 XSDEBUG("close audio #1\n"); | 373 XSDEBUG("close audio #1\n"); |
370 xs_plugin_ip.output->close_audio(); | 374 xs_plugin_ip.output->close_audio(); |
371 audioOpen = FALSE; | 375 audioOpen = FALSE; |
372 } | 376 } |
377 | |
378 /* Now determine if we continue by selecting other subtune or something */ | |
379 if (!myStatus.isPlaying) xs_status.isPlaying = FALSE; | |
373 } | 380 } |
374 | 381 |
375 /* When exiting, delete data */ | 382 /* When exiting, delete data */ |
376 err_exit: | 383 err_exit: |
377 pthread_mutex_lock(&xs_mutex); | 384 pthread_mutex_lock(&xs_mutex); |
392 | 399 |
393 g_free(myStatus.currFileName); | 400 g_free(myStatus.currFileName); |
394 | 401 |
395 /* Exit the playing thread */ | 402 /* Exit the playing thread */ |
396 XSDEBUG("exiting thread, bye.\n"); | 403 XSDEBUG("exiting thread, bye.\n"); |
404 | |
405 /* Last thing we do is set allowNext to TRUE to flag | |
406 * that we have ended all action in the thread | |
407 */ | |
397 pthread_mutex_lock(&xs_mutex); | 408 pthread_mutex_lock(&xs_mutex); |
398 xs_status.allowNext = TRUE; | 409 xs_status.allowNext = TRUE; |
399 pthread_mutex_unlock(&xs_mutex); | 410 pthread_mutex_unlock(&xs_mutex); |
400 | 411 |
401 pthread_exit(NULL); | 412 pthread_exit(NULL); |
412 | 423 |
413 /* Can we set the next tune? */ | 424 /* Can we set the next tune? */ |
414 XSDEBUG("request to play '%s'\n", pcFileName); | 425 XSDEBUG("request to play '%s'\n", pcFileName); |
415 | 426 |
416 /* Try to get the tune */ | 427 /* Try to get the tune */ |
417 XSDEBUG("initializing tune from file\n"); | |
418 newTune = new t_xs_tune(pcFileName); | 428 newTune = new t_xs_tune(pcFileName); |
419 if (newTune == NULL) return; | 429 if (newTune == NULL) return; |
420 | |
421 XSDEBUG("status: allowNext=%i, isPlaying=%i\n", xs_status.allowNext, xs_status.isPlaying); | |
422 | 430 |
423 #ifdef HAVE_SIDPLAY1 | 431 #ifdef HAVE_SIDPLAY1 |
424 /* Get current configuration */ | 432 /* Get current configuration */ |
425 xs_emuEngine.getConfig(xs_emuConf); | 433 xs_emuEngine.getConfig(xs_emuConf); |
426 | 434 |
639 * Set the time-seek position | 647 * Set the time-seek position |
640 * (the playing thread will do the "seeking" aka song-change) | 648 * (the playing thread will do the "seeking" aka song-change) |
641 */ | 649 */ |
642 void xs_seek(gint iTime) | 650 void xs_seek(gint iTime) |
643 { | 651 { |
652 /* If we have song-position patch, check settings */ | |
644 #ifdef HAVE_SONG_POSITION | 653 #ifdef HAVE_SONG_POSITION |
645 pthread_mutex_lock(&xs_mutex); | 654 pthread_mutex_lock(&xs_mutex); |
646 | 655 |
647 if ((iTime > 0) && (iTime <= xs_status.nSongs) && xs_status.isPlaying) | 656 if ((iTime > 0) && (iTime <= xs_status.nSongs) && xs_status.isPlaying) |
648 { | |
649 xs_status.currSong = iTime; | 657 xs_status.currSong = iTime; |
650 } | |
651 | 658 |
652 pthread_mutex_unlock(&xs_mutex); | 659 pthread_mutex_unlock(&xs_mutex); |
653 #endif | 660 #endif |
654 } | 661 } |
655 | 662 |
657 /* | 664 /* |
658 * Return the playing "position/time" | 665 * Return the playing "position/time" |
659 */ | 666 */ |
660 gint xs_get_time(void) | 667 gint xs_get_time(void) |
661 { | 668 { |
662 XSDEBUG("kyrve? %i : %i\n", xs_status.isError, xs_status.isPlaying); | 669 /* If errorflag is set, return -2 to signal it to XMMS's idle callback */ |
663 if (xs_status.isError) | 670 if (xs_status.isError) |
664 return -2; | 671 return -2; |
665 | 672 |
666 if (!xs_status.isPlaying) | 673 /* If tune has ended, return -1 */ |
674 if (xs_status.allowNext && !xs_status.isPlaying) | |
667 return -1; | 675 return -1; |
668 | 676 |
669 | 677 /* Obsolete? */ |
670 #ifdef HAVE_SONG_POSITION | 678 #ifdef HAVE_SONG_POSITION |
671 pthread_mutex_lock(&xs_mutex); | 679 pthread_mutex_lock(&xs_mutex); |
672 set_song_position(xs_status.currSong, 1, xs_status.nSongs); | 680 set_song_position(xs_status.currSong, 1, xs_status.nSongs); |
673 pthread_mutex_unlock(&xs_mutex); | 681 pthread_mutex_unlock(&xs_mutex); |
674 #endif | 682 #endif |
675 | 683 |
684 /* Else, return output time reported by audio output plugin */ | |
676 return xs_plugin_ip.output->output_time(); | 685 return xs_plugin_ip.output->output_time(); |
677 } | 686 } |
678 | 687 |
679 | 688 |
680 /* | 689 /* |
721 gchar *pcStr, *pcResult; | 730 gchar *pcStr, *pcResult; |
722 #ifdef HAVE_XMMSEXTRA | 731 #ifdef HAVE_XMMSEXTRA |
723 TitleInput *ptInput; | 732 TitleInput *ptInput; |
724 #endif | 733 #endif |
725 | 734 |
726 // FIXME FIXME: get STIL-info | 735 /* FIXME FIXME: get STIL-information */ |
727 | 736 |
728 | 737 |
729 /* Check the info strings */ | 738 /* Check the info strings */ |
730 if (pfInfo->numberOfInfoStrings < 3) | 739 if (pfInfo->numberOfInfoStrings < 3) |
731 { | 740 { |