comparison src/xs_sidplayfp.cpp @ 869:3a9bf45178ff

Use xs_fload_buffer() again, to support potential VFS backends.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 09 Nov 2012 04:00:27 +0200
parents fa926296e161
children d03e5c73eb51
comparison
equal deleted inserted replaced
868:3c3569894b23 869:3a9bf45178ff
362 /* Load a given SID-tune file 362 /* Load a given SID-tune file
363 */ 363 */
364 gboolean xs_sidplayfp_load(XSEngineState * state, gchar * filename) 364 gboolean xs_sidplayfp_load(XSEngineState * state, gchar * filename)
365 { 365 {
366 XSSIDPlayFP *engine = (XSSIDPlayFP *) state->internal; 366 XSSIDPlayFP *engine = (XSSIDPlayFP *) state->internal;
367 367 gboolean res = FALSE;
368 if (!engine || !filename) 368 guint8 *buf = NULL;
369 return FALSE; 369 size_t bufSize;
370
371 if (!engine)
372 return FALSE;
373
374 if (!xs_fload_buffer(filename, &buf, &bufSize, XS_SIDBUF_SIZE, TRUE))
375 goto error;
376
377 engine->tune.read(buf, bufSize);
370 378
371 engine->tune.load(filename);
372 #ifdef HAVE_SIDPLAYFP_V1 379 #ifdef HAVE_SIDPLAYFP_V1
373 if (!engine->tune.getStatus()) 380 if (!engine->tune.getStatus())
374 #else 381 #else
375 if (!engine->tune) 382 if (!engine->tune)
376 #endif 383 #endif
377 { 384 {
378 xs_error("Could not load file '%s'\n", filename); 385 xs_error("Could not load file '%s'\n", filename);
379 return FALSE; 386 goto error;
380 } 387 }
381 388
382 return TRUE; 389 res = TRUE;
390
391 error:
392 g_free(buf);
393 return res;
383 } 394 }
384 395
385 396
386 /* Delete INTERNAL information 397 /* Delete INTERNAL information
387 */ 398 */
411 * (those variables that are only set by libSIDPlay when tune is initialized). 422 * (those variables that are only set by libSIDPlay when tune is initialized).
412 * Rest of the information is acquired in xs_sidplayfp_updateinfo() 423 * Rest of the information is acquired in xs_sidplayfp_updateinfo()
413 */ 424 */
414 XSTuneInfo *xs_sidplayfp_getinfo(const gchar *filename) 425 XSTuneInfo *xs_sidplayfp_getinfo(const gchar *filename)
415 { 426 {
416 XSTuneInfo *res; 427 XSTuneInfo *res = NULL;
417 SidTune *tune; 428 SidTune *tune = NULL;
429 guint8 *buf = NULL;
430 size_t bufSize;
418 431
419 /* Check if the tune exists and is readable */ 432 /* Check if the tune exists and is readable */
420 if ((tune = new SidTune(filename)) == NULL) 433 if (!xs_fload_buffer(filename, &buf, &bufSize, XS_SIDBUF_SIZE, TRUE))
434 {
435 XSDEBUG("could not load file '%s'.\n", filename);
436 goto error;
437 }
438
439 if ((tune = new SidTune(buf, bufSize)) == NULL)
421 { 440 {
422 XSDEBUG("could not initialize tune from '%s'.\n", filename); 441 XSDEBUG("could not initialize tune from '%s'.\n", filename);
423 return NULL; 442 goto error;
424 } 443 }
425 444
426 if (!tune->getStatus()) 445 if (!tune->getStatus())
427 { 446 {
428 XSDEBUG("tune->getStatus() returned false for '%s'.\n", filename); 447 XSDEBUG("tune->getStatus() returned false for '%s'.\n", filename);
429 delete tune; 448 goto error;
430 return NULL;
431 } 449 }
432 450
433 /* Get general tune information */ 451 /* Get general tune information */
452 {
434 #ifdef HAVE_SIDPLAYFP_V1 453 #ifdef HAVE_SIDPLAYFP_V1
435 const SidTuneInfo *info = tune->getInfo(); 454 const SidTuneInfo *info = tune->getInfo();
436 455
437 res = xs_tuneinfo_new(filename, 456 res = xs_tuneinfo_new(filename,
438 info->songs(), info->startSong(), 457 info->songs(), info->startSong(),
450 info.loadAddr, info.initAddr, info.playAddr, 469 info.loadAddr, info.initAddr, info.playAddr,
451 info.dataFileLen, info.formatString, 470 info.dataFileLen, info.formatString,
452 info.sidModel1 471 info.sidModel1
453 ); 472 );
454 #endif 473 #endif
455 474 }
456 delete tune; 475
476 error:
477 if (tune)
478 delete tune;
479
480 g_free(buf);
457 return res; 481 return res;
458 } 482 }
459 483
460 484
461 /* Updates the information of currently playing tune 485 /* Updates the information of currently playing tune