Mercurial > hg > xmms-sid
diff src/xmms-sid.c @ 402:f997b79a7251
More work on merging of improved STIL/SLDB handling code with completely
dynamic memory allocation.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Thu, 01 Jun 2006 02:18:02 +0000 |
parents | b09d74eb71e6 |
children | b2d233cd01ba |
line wrap: on
line diff
--- a/src/xmms-sid.c Wed May 31 22:52:00 2006 +0000 +++ b/src/xmms-sid.c Thu Jun 01 02:18:02 2006 +0000 @@ -38,6 +38,7 @@ #include "xs_config.h" #include "xs_length.h" #include "xs_stil.h" +#include "xs_title.h" #include "xs_filter.h" #include "xs_fileinfo.h" #include "xs_interface.h" @@ -308,10 +309,10 @@ XS_MUTEX_LOCK(xs_status); memcpy(&myStatus, &xs_status, sizeof(t_xs_status)); myTune = xs_status.tuneInfo; + for (i = 0; i <= myTune->nsubTunes; i++) + myTune->subTunes[i].tunePlayed = FALSE; XS_MUTEX_UNLOCK(xs_status); - xs_memset(&playedTune, 0, sizeof(playedTune)); - /* Allocate audio buffer */ audioBuffer = (gchar *) g_malloc(XS_AUDIOBUF_SIZE); if (audioBuffer == NULL) { @@ -336,13 +337,17 @@ /* Automatic sub-tune change logic */ XS_MUTEX_LOCK(xs_cfg); XS_MUTEX_LOCK(xs_status); - assert(xs_status.currSong >= 1); - assert(xs_status.currSong <= XS_STIL_MAXENTRY); myStatus.isPlaying = TRUE; - + + if (xs_status.currSong < 1 || myStatus.currSong < 1) { + XS_MUTEX_UNLOCK(xs_status); + XS_MUTEX_UNLOCK(xs_cfg); + goto xs_err_exit; + } + if (xs_cfg.subAutoEnable && (myStatus.currSong == xs_status.currSong)) { /* Check if currently selected sub-tune has been played already */ - if (playedTune[myStatus.currSong]) { + if (myTune->subTunes[myStatus.currSong-1].tunePlayed) { /* Find a tune that has not been played */ XSDEBUG("tune #%i already played, finding next match ...\n", myStatus.currSong); isFound = FALSE; @@ -350,12 +355,12 @@ while (!isFound && (++i <= myTune->nsubTunes)) { if (xs_cfg.subAutoMinOnly) { /* A tune with minimum length must be found */ - if (!playedTune[i] - && myTune->subTunes[i].tuneLength >= xs_cfg.subAutoMinTime) + if (!myTune->subTunes[i-1].tunePlayed && + myTune->subTunes[i-1].tuneLength >= xs_cfg.subAutoMinTime) isFound = TRUE; } else { /* Any unplayed tune is okay */ - if (!playedTune[i]) + if (!myTune->subTunes[i-1].tunePlayed) isFound = TRUE; } } @@ -376,7 +381,7 @@ /* Tell that we are initializing, update sub-tune controls */ myStatus.currSong = xs_status.currSong; - playedTune[myStatus.currSong] = TRUE; + myTune->subTunes[myStatus.currSong-1].tunePlayed = TRUE; XS_MUTEX_UNLOCK(xs_status); XS_MUTEX_UNLOCK(xs_cfg); @@ -387,7 +392,7 @@ GDK_THREADS_LEAVE(); /* Check minimum playtime */ - songLength = myTune->subTunes[myStatus.currSong - 1].tuneLength; + songLength = myTune->subTunes[myStatus.currSong-1].tuneLength; if (xs_cfg.playMinTimeEnable && (songLength >= 0)) { if (songLength < xs_cfg.playMinTime) songLength = xs_cfg.playMinTime; @@ -416,11 +421,11 @@ audioOpen = TRUE; /* Set song information for current subtune */ - xs_plugin_ip.set_info(myTune->subTunes[myStatus.currSong - 1].tuneTitle, - (songLength > 0) ? (songLength * 1000) : 0, - (myTune->subTunes[myStatus.currSong - 1].tuneSpeed > - 0) ? (myTune->subTunes[myStatus.currSong - 1].tuneSpeed * 1000) : -1, - myStatus.audioFrequency, myStatus.audioChannels); + xs_plugin_ip.set_info(myTune->subTunes[myStatus.currSong-1].tuneTitle, + (songLength > 0) ? (songLength * 1000) : 0, + (myTune->subTunes[myStatus.currSong-1].tuneSpeed > 0) ? + (myTune->subTunes[myStatus.currSong-1].tuneSpeed * 1000) : -1, + myStatus.audioFrequency, myStatus.audioChannels); XSDEBUG("playing\n"); @@ -497,7 +502,7 @@ doPlay = FALSE; } - xs_err_exit: +xs_err_exit: /* Close audio output plugin */ if (audioOpen) { XSDEBUG("close audio #2\n"); @@ -736,7 +741,8 @@ GtkWidget *frame25, *hbox15, *subctrl_prev, *subctrl_current, *subctrl_next; XS_MUTEX_LOCK(xs_subctrl); - if (!xs_status.tuneInfo || !xs_status.isPlaying || xs_subctrl || (xs_status.tuneInfo->nsubTunes <= 1)) { + if (!xs_status.tuneInfo || !xs_status.isPlaying || + xs_subctrl || (xs_status.tuneInfo->nsubTunes <= 1)) { XS_MUTEX_UNLOCK(xs_subctrl); return; } @@ -902,7 +908,6 @@ void xs_get_song_info(gchar * songFilename, gchar ** songTitle, gint * songLength) { t_xs_tuneinfo *pInfo; - gint tmpInt; /* Get tune information from emulation engine */ pInfo = xs_status.sidPlayer->plrGetSIDInfo(songFilename); @@ -911,9 +916,11 @@ /* Get sub-tune information, if available */ if ((pInfo->startTune > 0) && (pInfo->startTune <= pInfo->nsubTunes)) { - (*songTitle) = g_strdup(pInfo->subTunes[pInfo->startTune - 1].tuneTitle); + gint tmpInt; + + (*songTitle) = g_strdup(pInfo->subTunes[pInfo->startTune-1].tuneTitle); - tmpInt = pInfo->subTunes[pInfo->startTune - 1].tuneLength; + tmpInt = pInfo->subTunes[pInfo->startTune-1].tuneLength; if (tmpInt < 0) (*songLength) = -1; else @@ -927,11 +934,15 @@ /* Allocate a new tune information structure */ -t_xs_tuneinfo *xs_tuneinfo_new(gchar * pcFilename, gint nsubTunes, gint startTune, - gchar * sidName, gchar * sidComposer, gchar * sidCopyright, - gint loadAddr, gint initAddr, gint playAddr, gint dataFileLen) +t_xs_tuneinfo *xs_tuneinfo_new(const gchar * pcFilename, + gint nsubTunes, gint startTune, const gchar * sidName, + const gchar * sidComposer, const gchar * sidCopyright, + gint loadAddr, gint initAddr, gint playAddr, + gint dataFileLen, const gchar *sidFormat) { t_xs_tuneinfo *pResult; + t_xs_sldb_node *tmpLength; + gint i; /* Allocate structure */ pResult = (t_xs_tuneinfo *) g_malloc0(sizeof(t_xs_tuneinfo)); @@ -948,15 +959,14 @@ } /* Allocate space for subtune information */ - if (nsubTunes > 0) { - pResult->subTunes = g_malloc0(sizeof(t_xs_subtuneinfo) * nsubTunes); - if (!pResult->subTunes) { - xs_error("Could not allocate memory for t_xs_subtuneinfo ('%s', %i)\n", pcFilename, nsubTunes); + pResult->subTunes = g_malloc0(sizeof(t_xs_subtuneinfo) * (nsubTunes + 1)); + if (!pResult->subTunes) { + xs_error("Could not allocate memory for t_xs_subtuneinfo ('%s', %i)\n", + pcFilename, nsubTunes); - g_free(pResult->sidFilename); - g_free(pResult); - return NULL; - } + g_free(pResult->sidFilename); + g_free(pResult); + return NULL; } /* The following allocations don't matter if they fail */ @@ -971,7 +981,21 @@ pResult->initAddr = initAddr; pResult->playAddr = playAddr; pResult->dataFileLen = dataFileLen; + pResult->sidFormat = g_strdup(sidFormat); + /* Get length information (NOTE: Do not free this!) */ + tmpLength = xs_songlen_get(pcFilename); + + /* Fill in sub-tune information */ + for (i = 0; i < pResult->nsubTunes; i++) { + if (tmpLength && (i < tmpLength->nLengths)) + pResult->subTunes[i].tuneLength = tmpLength->sLengths[i]; + else + pResult->subTunes[i].tuneLength = -1; + + pResult->subTunes[i].tuneTitle = xs_make_titlestring(pResult, i); + } + return pResult; } @@ -981,23 +1005,19 @@ void xs_tuneinfo_free(t_xs_tuneinfo * pTune) { gint i; - if (!pTune) - return; - for (i = 0; i < pTune->nsubTunes; i++) { + if (!pTune) return; + + for (i = 1; i < pTune->nsubTunes; i++) { g_free(pTune->subTunes[i].tuneTitle); pTune->subTunes[i].tuneTitle = NULL; } g_free(pTune->subTunes); - pTune->nsubTunes = 0; g_free(pTune->sidFilename); - pTune->sidFilename = NULL; g_free(pTune->sidName); - pTune->sidName = NULL; g_free(pTune->sidComposer); - pTune->sidComposer = NULL; g_free(pTune->sidCopyright); - pTune->sidCopyright = NULL; + g_free(pTune->sidFormat); g_free(pTune); }