# HG changeset patch # User Matti Hamalainen # Date 1352280104 -7200 # Node ID 02512cbc6d9fc02cb6e5a5ba07badbc98ca1cd59 # Parent dfda3d47baf792979e20283ebf6dea264826808a Cleanup, mostly cosmetic. diff -r dfda3d47baf7 -r 02512cbc6d9f src/xmms-sid.c --- a/src/xmms-sid.c Wed Nov 07 11:05:42 2012 +0200 +++ b/src/xmms-sid.c Wed Nov 07 11:21:44 2012 +0200 @@ -128,10 +128,13 @@ /* Stop playing, if we are */ XS_MUTEX_LOCK(xs_status); - if (xs_status.isPlaying) { + if (xs_status.isPlaying) + { XS_MUTEX_UNLOCK(xs_status); xs_stop(); - } else { + } + else + { XS_MUTEX_UNLOCK(xs_status); } @@ -174,13 +177,15 @@ /* Initialize song-length database */ xs_songlen_close(); - if (xs_cfg.songlenDBEnable && (xs_songlen_init() != 0)) { + if (xs_cfg.songlenDBEnable && (xs_songlen_init() != 0)) + { xs_error("Error initializing song-length database!\n"); } /* Initialize STIL database */ xs_stil_close(); - if (xs_cfg.stilDBEnable && (xs_stil_init() != 0)) { + if (xs_cfg.stilDBEnable && (xs_stil_init() != 0)) + { xs_error("Error initializing STIL database!\n"); } } @@ -243,9 +248,11 @@ return FALSE; /* Try to detect via detection routine, if required */ - if (xs_cfg.detectMagic) { + if (xs_cfg.detectMagic) + { XSFile *f; - if ((f = xs_fopen(filename, "rb")) != NULL) { + if ((f = xs_fopen(filename, "rb")) != NULL) + { if (xs_status.engine->plrProbe(f)) return TRUE; xs_fclose(f); @@ -254,22 +261,24 @@ /* Detect just by checking filename extension */ ext = strrchr(filename, '.'); - if (ext) { + if (ext) + { ext++; - switch (xs_cfg.playerEngine) { - case XS_ENG_SIDPLAY1: - case XS_ENG_SIDPLAY2: - if (!g_strcasecmp(ext, "psid")) - return TRUE; - if (!g_strcasecmp(ext, "sid")) - return TRUE; - if (!g_strcasecmp(ext, "dat")) - return TRUE; - if (!g_strcasecmp(ext, "inf")) - return TRUE; - if (!g_strcasecmp(ext, "info")) - return TRUE; - break; + switch (xs_cfg.playerEngine) + { + case XS_ENG_SIDPLAY1: + case XS_ENG_SIDPLAY2: + if (!g_strcasecmp(ext, "psid")) + return TRUE; + if (!g_strcasecmp(ext, "sid")) + return TRUE; + if (!g_strcasecmp(ext, "dat")) + return TRUE; + if (!g_strcasecmp(ext, "inf")) + return TRUE; + if (!g_strcasecmp(ext, "info")) + return TRUE; + break; } } @@ -301,7 +310,8 @@ /* Allocate audio buffer */ audioBuffer = (gchar *) g_malloc(XS_AUDIOBUF_SIZE); - if (audioBuffer == NULL) { + if (audioBuffer == NULL) + { xs_error("Couldn't allocate memory for audio data buffer!\n"); goto xs_err_exit; } @@ -311,39 +321,48 @@ */ audioOpen = FALSE; doPlay = TRUE; - while (xs_status.isPlaying && doPlay) { + while (xs_status.isPlaying && doPlay) + { /* Automatic sub-tune change logic */ XS_MUTEX_LOCK(xs_cfg); XS_MUTEX_LOCK(xs_status); myStatus.isPlaying = TRUE; - if (xs_status.currSong < 1 || myStatus.currSong < 1) { + 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)) { + if (xs_cfg.subAutoEnable && (myStatus.currSong == xs_status.currSong)) + { /* Check if currently selected sub-tune has been played already */ - if (myTune->subTunes[myStatus.currSong-1].tunePlayed) { + 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; i = 0; - while (!isFound && (++i <= myTune->nsubTunes)) { - if (xs_cfg.subAutoMinOnly) { + while (!isFound && (++i <= myTune->nsubTunes)) + { + if (xs_cfg.subAutoMinOnly) + { /* A tune with minimum length must be found */ if (!myTune->subTunes[i-1].tunePlayed && myTune->subTunes[i-1].tuneLength >= xs_cfg.subAutoMinTime) isFound = TRUE; - } else { + } + else + { /* Any unplayed tune is okay */ if (!myTune->subTunes[i-1].tunePlayed) isFound = TRUE; } } - if (isFound) { + if (isFound) + { /* Set the new sub-tune */ XSDEBUG("found #%i\n", i); xs_status.currSong = i; @@ -371,13 +390,15 @@ /* Check minimum playtime */ songLength = myTune->subTunes[myStatus.currSong-1].tuneLength; - if (xs_cfg.playMinTimeEnable && (songLength >= 0)) { + if (xs_cfg.playMinTimeEnable && songLength >= 0) + { if (songLength < xs_cfg.playMinTime) songLength = xs_cfg.playMinTime; } /* Initialize song */ - if (!myStatus.engine->plrInitSong(&myStatus)) { + if (!myStatus.engine->plrInitSong(&myStatus)) + { xs_error("Couldn't initialize SID-tune '%s' (sub-tune #%i)!\n", myTune->sidFilename, myStatus.currSong); goto xs_err_exit; @@ -388,7 +409,8 @@ myStatus.audioFormat, myStatus.audioFrequency, myStatus.audioChannels); if (!xs_plugin_ip.output-> - open_audio(myStatus.audioFormat, myStatus.audioFrequency, myStatus.audioChannels)) { + open_audio(myStatus.audioFormat, myStatus.audioFrequency, myStatus.audioChannels)) + { xs_error("Couldn't open XMMS audio output (fmt=%x, freq=%i, nchan=%i)!\n", myStatus.audioFormat, myStatus.audioFrequency, @@ -443,18 +465,23 @@ xs_plugin_ip.output->write_audio(audioBuffer, audioGot); /* Check if we have played enough */ - if (xs_cfg.playMaxTimeEnable) { - if (xs_cfg.playMaxTimeUnknown) { + if (xs_cfg.playMaxTimeEnable) + { + if (xs_cfg.playMaxTimeUnknown) + { if (songLength < 0 && xs_plugin_ip.output->output_time() >= xs_cfg.playMaxTime * 1000) myStatus.isPlaying = FALSE; - } else { + } + else + { if (xs_plugin_ip.output->output_time() >= xs_cfg.playMaxTime * 1000) myStatus.isPlaying = FALSE; } } - if (songLength >= 0) { + if (songLength >= 0) + { if (xs_plugin_ip.output->output_time() >= songLength * 1000) myStatus.isPlaying = FALSE; } @@ -463,7 +490,8 @@ XSDEBUG("subtune ended/stopped\n"); /* Close audio output plugin */ - if (audioOpen) { + if (audioOpen) + { XSDEBUG("close audio #1\n"); xs_plugin_ip.output->close_audio(); audioOpen = FALSE; @@ -479,7 +507,8 @@ XSDEBUG("out of playing loop\n"); /* Close audio output plugin */ - if (audioOpen) { + if (audioOpen) + { XSDEBUG("close audio #2\n"); xs_plugin_ip.output->close_audio(); XSDEBUG("closed\n"); @@ -520,7 +549,8 @@ return; /* Initialize the tune */ - if (!xs_status.engine->plrLoadSID(&xs_status, filename)) { + if (!xs_status.engine->plrLoadSID(&xs_status, filename)) + { xs_tuneinfo_free(xs_status.tuneInfo); xs_status.tuneInfo = NULL; return; @@ -534,7 +564,8 @@ xs_status.currSong = xs_status.tuneInfo->startTune; /* Start the playing thread! */ - if (pthread_create(&xs_decode_thread, NULL, xs_playthread, NULL) < 0) { + if (pthread_create(&xs_decode_thread, NULL, xs_playthread, NULL) < 0) + { xs_error("Couldn't create playing thread!\n"); xs_tuneinfo_free(xs_status.tuneInfo); xs_status.tuneInfo = NULL; @@ -568,12 +599,15 @@ /* Lock xs_status and stop playing thread */ XS_MUTEX_LOCK(xs_status); - if (xs_status.isPlaying) { + if (xs_status.isPlaying) + { XSDEBUG("stopping...\n"); xs_status.isPlaying = FALSE; XS_MUTEX_UNLOCK(xs_status); XS_THREAD_JOIN(xs_decode_thread); - } else { + } + else + { XS_MUTEX_UNLOCK(xs_status); } @@ -621,9 +655,10 @@ XS_MUTEX_LOCK(xs_status); XS_MUTEX_LOCK(xs_subctrl); - if (xs_status.tuneInfo && xs_status.isPlaying) { + if (xs_status.tuneInfo && xs_status.isPlaying) + { n = (gint) GTK_ADJUSTMENT(xs_subctrl_adj)->value; - if ((n >= 1) && (n <= xs_status.tuneInfo->nsubTunes)) + if (n >= 1 && n <= xs_status.tuneInfo->nsubTunes) xs_status.currSong = n; } @@ -636,7 +671,8 @@ { XS_MUTEX_LOCK(xs_status); - if (xs_status.tuneInfo && xs_status.isPlaying) { + if (xs_status.tuneInfo && xs_status.isPlaying) + { if (xs_status.currSong > 1) xs_status.currSong--; } @@ -651,7 +687,8 @@ { XS_MUTEX_LOCK(xs_status); - if (xs_status.tuneInfo && xs_status.isPlaying) { + if (xs_status.tuneInfo && xs_status.isPlaying) + { if (xs_status.currSong < xs_status.tuneInfo->nsubTunes) xs_status.currSong++; } @@ -670,8 +707,10 @@ XS_MUTEX_LOCK(xs_subctrl); /* Check if control window exists, we are currently playing and have a tune */ - if (xs_subctrl) { - if (xs_status.tuneInfo && xs_status.isPlaying) { + if (xs_subctrl) + { + if (xs_status.tuneInfo && xs_status.isPlaying) + { tmpAdj = GTK_ADJUSTMENT(xs_subctrl_adj); tmpAdj->value = xs_status.currSong; @@ -680,12 +719,16 @@ XS_MUTEX_UNLOCK(xs_status); XS_MUTEX_UNLOCK(xs_subctrl); gtk_adjustment_value_changed(tmpAdj); - } else { + } + else + { XS_MUTEX_UNLOCK(xs_status); XS_MUTEX_UNLOCK(xs_subctrl); xs_subctrl_close(); } - } else { + } + else + { XS_MUTEX_UNLOCK(xs_subctrl); XS_MUTEX_UNLOCK(xs_status); } @@ -698,7 +741,8 @@ { XS_MUTEX_LOCK(xs_subctrl); - if (xs_subctrl) { + if (xs_subctrl) + { gtk_widget_destroy(xs_subctrl); xs_subctrl = NULL; } @@ -723,11 +767,10 @@ 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)) { - XS_MUTEX_UNLOCK(xs_subctrl); - return; - } + xs_subctrl || xs_status.tuneInfo->nsubTunes <= 1) + goto out; /* Create the pop-up window */ xs_subctrl = gtk_window_new(GTK_WINDOW_DIALOG); @@ -779,6 +822,7 @@ gtk_widget_show_all(xs_subctrl); +out: XS_MUTEX_UNLOCK(xs_subctrl); } @@ -794,38 +838,40 @@ */ void xs_seek(gint time) { - /* Check status */ XS_MUTEX_LOCK(xs_status); - if (!xs_status.tuneInfo || !xs_status.isPlaying) { - XS_MUTEX_UNLOCK(xs_status); - return; - } + if (!xs_status.tuneInfo || !xs_status.isPlaying) + goto out; - /* Act according to settings */ - switch (xs_cfg.subsongControl) { - case XS_SSC_SEEK: - if (time < xs_status.lastTime) { - if (xs_status.currSong > 1) - xs_status.currSong--; - } else if (time > xs_status.lastTime) { - if (xs_status.currSong < xs_status.tuneInfo->nsubTunes) - xs_status.currSong++; - } - break; + switch (xs_cfg.subsongControl) + { + case XS_SSC_SEEK: + if (time < xs_status.lastTime) + { + if (xs_status.currSong > 1) + xs_status.currSong--; + } + else + if (time > xs_status.lastTime) + { + if (xs_status.currSong < xs_status.tuneInfo->nsubTunes) + xs_status.currSong++; + } + break; - case XS_SSC_POPUP: - xs_subctrl_open(); - break; + case XS_SSC_POPUP: + xs_subctrl_open(); + break; /* If we have song-position patch, check settings */ #ifdef HAVE_SONG_POSITION - case XS_SSC_PATCH: - if ((time > 0) && (time <= xs_status.tuneInfo->nsubTunes)) - xs_status.currSong = time; - break; + case XS_SSC_PATCH: + if (time > 0 && time <= xs_status.tuneInfo->nsubTunes) + xs_status.currSong = time; + break; #endif } +out: XS_MUTEX_UNLOCK(xs_status); } @@ -839,35 +885,34 @@ */ gint xs_get_time(void) { + int err; + /* If errorflag is set, return -2 to signal it to XMMS's idle callback */ XS_MUTEX_LOCK(xs_status); - if (xs_status.isError) { - XS_MUTEX_UNLOCK(xs_status); - return -2; + if (xs_status.isError) + { + err = -2; + goto error; } - /* If there is no tune, return -1 */ - if (!xs_status.tuneInfo) { - XS_MUTEX_UNLOCK(xs_status); - return -1; - } - - /* If tune has ended, return -1 */ - if (!xs_status.isPlaying) { - XS_MUTEX_UNLOCK(xs_status); - return -1; + /* If there is no tune or tune has ended, return -1 */ + if (!xs_status.tuneInfo || !xs_status.isPlaying) + { + err = -1; + goto error; } /* Let's see what we do */ - switch (xs_cfg.subsongControl) { - case XS_SSC_SEEK: - xs_status.lastTime = (xs_plugin_ip.output->output_time() / 1000); - break; + switch (xs_cfg.subsongControl) + { + case XS_SSC_SEEK: + xs_status.lastTime = (xs_plugin_ip.output->output_time() / 1000); + break; #ifdef HAVE_SONG_POSITION - case XS_SSC_PATCH: - set_song_position(xs_status.currSong, 1, xs_status.tuneInfo->nsubTunes); - break; + case XS_SSC_PATCH: + set_song_position(xs_status.currSong, 1, xs_status.tuneInfo->nsubTunes); + break; #endif } @@ -875,6 +920,10 @@ /* Return output time reported by audio output plugin */ return xs_plugin_ip.output->output_time(); + +error: + XS_MUTEX_UNLOCK(xs_status); + return err; } @@ -886,33 +935,30 @@ { XSTuneInfo *info; + XS_MUTEX_LOCK(xs_status); + if (xs_status.engine == NULL) - return; - - XS_MUTEX_LOCK(xs_status); + goto out; /* Get tune information from emulation engine */ info = xs_status.engine->plrGetSIDInfo(songFilename); - if (!info) { - XS_MUTEX_UNLOCK(xs_status); - return; - } + if (!info) + goto out; /* Get sub-tune information, if available */ - if ((info->startTune > 0) && (info->startTune <= info->nsubTunes)) { - gint tmpInt; - + if (info->startTune > 0 && info->startTune <= info->nsubTunes) + { + gint length; + (*songTitle) = xs_make_titlestring(info, info->startTune); - tmpInt = info->subTunes[info->startTune-1].tuneLength; - if (tmpInt < 0) - (*songLength) = -1; - else - (*songLength) = (tmpInt * 1000); + length = info->subTunes[info->startTune-1].tuneLength; + (*songLength) = length < 0 ? -1 : length * 1000; } /* Free tune information */ xs_tuneinfo_free(info); + +out: XS_MUTEX_UNLOCK(xs_status); } -