Mercurial > hg > xmms-sid
view src/xs_sidplay.h @ 820:778531e968ed
Clean up tune loading.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Wed, 07 Nov 2012 16:08:40 +0200 |
parents | dfda3d47baf7 |
children | ae1f6418d093 |
line wrap: on
line source
/* XMMS-SID - SIDPlay input plugin for X MultiMedia System (XMMS) libSIDPlay skeleton functions used both by v1 and 2 of the backends Programmed and designed by Matti 'ccr' Hamalainen <ccr@tnsp.org> (C) Copyright 2005-2009 Tecnic Software productions (TNSP) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ /* This function gets most of the information, though we do miss some * (those variables that are only set by libSIDPlay when tune is initialized). * Rest of the information is acquired in TFUNCTION2() */ XSTuneInfo *TFUNCTION(const gchar *filename) { XSTuneInfo *res; TTUNEINFO info; TTUNE *tune; guint8 *buf = NULL; size_t bufSize = 0; /* Load file */ if (xs_fload_buffer(filename, &buf, &bufSize) != 0) return NULL; /* Check if the tune exists and is readable */ if ((tune = new TTUNE(buf, bufSize)) == NULL) { g_free(buf); return NULL; } g_free(buf); if (!tune->getStatus()) { delete tune; return NULL; } /* Get general tune information */ #ifdef XS_SIDPLAY1_H tune->getInfo(info); #endif #ifdef XS_SIDPLAY2_H info = tune->getInfo(); #endif /* Allocate tuneinfo structure and set information */ res = xs_tuneinfo_new(filename, info.songs, info.startSong, info.infoString[0], info.infoString[1], info.infoString[2], info.loadAddr, info.initAddr, info.playAddr, info.dataFileLen, info.formatString, #if defined(XS_SIDPLAY2_H) && defined(HAVE_SIDPLAY2_FP) info.sidModel1 #else info.sidModel #endif ); /* NOTICE! libSIDPlay[12] headers specifically state that sidModel, * songSpeed and clockSpeed are "undefined" before song initialization, * but in practice sidModel is known after getInfo() invocation... * This of course does not take the sub-tune specific changes into account, * but at least we have a reasonable guesstimate. */ delete tune; return res; } /* Updates the information of currently playing tune */ gboolean TFUNCTION2(XSEngineState *state) { TTUNEINFO info; TENGINE *engine; /* Check if we have required structures initialized */ if (!state || !state->tuneInfo || !state->internal) return FALSE; engine = (TENGINE *) state->internal; if (!(engine->tune)) return FALSE; /* Get currently playing tune information */ #ifdef XS_SIDPLAY1_H engine->tune->getInfo(info); #endif #ifdef XS_SIDPLAY2_H info = engine->tune.getInfo(); #endif /* NOTICE! Here we assume that libSIDPlay[12] headers define * SIDTUNE_SIDMODEL_* similarly to our enums in xs_config.h ... */ #if defined(XS_SIDPLAY2_H) && defined(HAVE_SIDPLAY2_FP) state->tuneInfo->sidModel = info.sidModel1; #else state->tuneInfo->sidModel = info.sidModel; #endif if (state->currSong > 0 && state->currSong <= state->tuneInfo->nsubTunes) { gint tmpSpeed = -1; switch (info.clockSpeed) { case SIDTUNE_CLOCK_PAL: tmpSpeed = XS_CLOCK_PAL; break; case SIDTUNE_CLOCK_NTSC: tmpSpeed = XS_CLOCK_NTSC; break; case SIDTUNE_CLOCK_ANY: tmpSpeed = XS_CLOCK_ANY; break; case SIDTUNE_CLOCK_UNKNOWN: switch (info.songSpeed) { case SIDTUNE_SPEED_VBI: tmpSpeed = XS_CLOCK_VBI; break; case SIDTUNE_SPEED_CIA_1A: tmpSpeed = XS_CLOCK_CIA; break; default: tmpSpeed = info.songSpeed; break; } default: tmpSpeed = info.clockSpeed; break; } state->tuneInfo->subTunes[state->currSong - 1].tuneSpeed = tmpSpeed; } return TRUE; } /* Undefine these */ #undef TFUNCTION #undef TFUNCTION2 #undef TTUNEINFO #undef TTUNE