Mercurial > hg > xmms-sid
comparison src/xmms-sid.c @ 333:15c5b231efc9
- subTune -> subTunes
- adjust to struct size + 1 (XS_STIL_MAXENTRY change)
- misc cleanups
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Thu, 22 Sep 2005 01:55:01 +0000 |
parents | dd201740a720 |
children | ca351adcc8d6 |
comparison
equal
deleted
inserted
replaced
332:961212302eb9 | 333:15c5b231efc9 |
---|---|
301 void *xs_playthread(void *argPointer) | 301 void *xs_playthread(void *argPointer) |
302 { | 302 { |
303 t_xs_status myStatus; | 303 t_xs_status myStatus; |
304 t_xs_tuneinfo *myTune; | 304 t_xs_tuneinfo *myTune; |
305 gboolean audioOpen = FALSE, doPlay = FALSE, isFound = FALSE; | 305 gboolean audioOpen = FALSE, doPlay = FALSE, isFound = FALSE; |
306 gboolean playedTune[XS_STIL_MAXENTRY]; | 306 gboolean playedTune[XS_STIL_MAXENTRY + 1]; |
307 gint audioGot, songLength, i; | 307 gint audioGot, songLength, i; |
308 #ifdef XS_BUF_DYNAMIC | 308 #ifdef XS_BUF_DYNAMIC |
309 gchar *audioBuffer = NULL, *oversampleBuffer = NULL; | 309 gchar *audioBuffer = NULL, *oversampleBuffer = NULL; |
310 #else | 310 #else |
311 gchar audioBuffer[XS_AUDIOBUF_SIZE], oversampleBuffer[(XS_AUDIOBUF_SIZE * XS_MAX_OVERSAMPLE)]; | 311 gchar audioBuffer[XS_AUDIOBUF_SIZE], oversampleBuffer[(XS_AUDIOBUF_SIZE * XS_MAX_OVERSAMPLE)]; |
356 myStatus.isPlaying = TRUE; | 356 myStatus.isPlaying = TRUE; |
357 | 357 |
358 if (xs_cfg.subAutoEnable && (myStatus.currSong == xs_status.currSong)) | 358 if (xs_cfg.subAutoEnable && (myStatus.currSong == xs_status.currSong)) |
359 { | 359 { |
360 /* Check if currently selected sub-tune has been played already */ | 360 /* Check if currently selected sub-tune has been played already */ |
361 if (playedTune[myStatus.currSong - 1]) | 361 if (playedTune[myStatus.currSong]) |
362 { | 362 { |
363 /* Find a tune that has not been played */ | 363 /* Find a tune that has not been played */ |
364 XSDEBUG("tune #%i already played, finding next match ...\n", myStatus.currSong); | 364 XSDEBUG("tune #%i already played, finding next match ...\n", myStatus.currSong); |
365 isFound = FALSE; | 365 isFound = FALSE; |
366 i = 0; | 366 i = 0; |
367 while (!isFound && (i < myTune->nsubTunes)) | 367 while (!isFound && (i <= myTune->nsubTunes)) |
368 { | 368 { |
369 if (xs_cfg.subAutoMinOnly) | 369 if (xs_cfg.subAutoMinOnly) |
370 { | 370 { |
371 /* A tune with minimum length must be found */ | 371 /* A tune with minimum length must be found */ |
372 if (!playedTune[i] && myTune->subTunes[i].tuneLength >= xs_cfg.subAutoMinTime) | 372 if (!playedTune[i] && myTune->subTunes[i].tuneLength >= xs_cfg.subAutoMinTime) |
396 } | 396 } |
397 } | 397 } |
398 | 398 |
399 /* Tell that we are initializing, update sub-tune controls */ | 399 /* Tell that we are initializing, update sub-tune controls */ |
400 myStatus.currSong = xs_status.currSong; | 400 myStatus.currSong = xs_status.currSong; |
401 playedTune[myStatus.currSong - 1] = TRUE; | 401 playedTune[myStatus.currSong] = TRUE; |
402 XS_MUTEX_UNLOCK(xs_status); | 402 XS_MUTEX_UNLOCK(xs_status); |
403 XS_MUTEX_UNLOCK(xs_cfg); | 403 XS_MUTEX_UNLOCK(xs_cfg); |
404 | 404 |
405 XSDEBUG("subtune #%i selected, initializing...\n", myStatus.currSong); | 405 XSDEBUG("subtune #%i selected, initializing...\n", myStatus.currSong); |
406 | 406 |
889 break; | 889 break; |
890 | 890 |
891 /* If we have song-position patch, check settings */ | 891 /* If we have song-position patch, check settings */ |
892 #ifdef HAVE_SONG_POSITION | 892 #ifdef HAVE_SONG_POSITION |
893 case XS_SSC_PATCH: | 893 case XS_SSC_PATCH: |
894 if ((iTime >= 1) && (iTime <= xs_status.tuneInfo->nsubTunes)) | 894 if ((iTime > 0) && (iTime <= xs_status.tuneInfo->nsubTunes)) |
895 xs_status.currSong = iTime; | 895 xs_status.currSong = iTime; |
896 break; | 896 break; |
897 #endif | 897 #endif |
898 } | 898 } |
899 | 899 |
964 gint tmpInt; | 964 gint tmpInt; |
965 | 965 |
966 /* Get tune information from emulation engine */ | 966 /* Get tune information from emulation engine */ |
967 pInfo = xs_status.sidPlayer->plrGetSIDInfo(songFilename); | 967 pInfo = xs_status.sidPlayer->plrGetSIDInfo(songFilename); |
968 if (!pInfo) return; | 968 if (!pInfo) return; |
969 | 969 |
970 /* Get sub-tune information, if available */ | 970 /* Get sub-tune information, if available */ |
971 if ((pInfo->startTune >= 0) && (pInfo->startTune <= pInfo->nsubTunes)) | 971 if ((pInfo->startTune > 0) && (pInfo->startTune <= pInfo->nsubTunes)) |
972 { | 972 { |
973 (*songTitle) = g_strdup(pInfo->subTunes[pInfo->startTune - 1].tuneTitle); | 973 (*songTitle) = g_strdup(pInfo->subTunes[pInfo->startTune - 1].tuneTitle); |
974 | 974 |
975 tmpInt = pInfo->subTunes[pInfo->startTune - 1].tuneLength; | 975 tmpInt = pInfo->subTunes[pInfo->startTune - 1].tuneLength; |
976 if (tmpInt < 0) | 976 if (tmpInt < 0) |
990 gchar *sidName, gchar *sidComposer, gchar *sidCopyright, | 990 gchar *sidName, gchar *sidComposer, gchar *sidCopyright, |
991 gint loadAddr, gint initAddr, gint playAddr, gint dataFileLen) | 991 gint loadAddr, gint initAddr, gint playAddr, gint dataFileLen) |
992 { | 992 { |
993 t_xs_tuneinfo *pResult; | 993 t_xs_tuneinfo *pResult; |
994 | 994 |
995 /* Allocate structure */ | |
995 pResult = (t_xs_tuneinfo *) g_malloc0(sizeof(t_xs_tuneinfo)); | 996 pResult = (t_xs_tuneinfo *) g_malloc0(sizeof(t_xs_tuneinfo)); |
996 if (!pResult) return NULL; | 997 if (!pResult) |
998 { | |
999 XSERR("Could not allocate memory for t_xs_tuneinfo ('%s')\n", pcFilename); | |
1000 return NULL; | |
1001 } | |
997 | 1002 |
998 pResult->sidFilename = g_strdup(pcFilename); | 1003 pResult->sidFilename = g_strdup(pcFilename); |
999 if (!pResult->sidFilename) | 1004 if (!pResult->sidFilename) |
1000 { | 1005 { |
1006 XSERR("Could not allocate sidFilename ('%s')\n", pcFilename); | |
1001 g_free(pResult); | 1007 g_free(pResult); |
1002 return NULL; | 1008 return NULL; |
1003 } | 1009 } |
1004 | 1010 |
1011 /* Allocate space for subtune information */ | |
1012 if (nsubTunes > 0) | |
1013 { | |
1014 pResult->subTunes = g_malloc0(sizeof(t_xs_subtuneinfo) * nsubTunes); | |
1015 if (!pResult->subTunes) | |
1016 { | |
1017 XSERR("Could not allocate memory for t_xs_subtuneinfo ('%s', %i)\n", | |
1018 pcFilename, nsubTunes); | |
1019 | |
1020 g_free(pResult->sidFilename); | |
1021 g_free(pResult); | |
1022 return NULL; | |
1023 } | |
1024 } | |
1025 | |
1026 /* The following allocations don't matter if they fail */ | |
1005 pResult->sidName = g_strdup(sidName); | 1027 pResult->sidName = g_strdup(sidName); |
1006 pResult->sidComposer = g_strdup(sidComposer); | 1028 pResult->sidComposer = g_strdup(sidComposer); |
1007 pResult->sidCopyright = g_strdup(sidCopyright); | 1029 pResult->sidCopyright = g_strdup(sidCopyright); |
1030 | |
1008 pResult->nsubTunes = nsubTunes; | 1031 pResult->nsubTunes = nsubTunes; |
1009 pResult->startTune = startTune; | 1032 pResult->startTune = startTune; |
1010 | 1033 |
1011 pResult->loadAddr = loadAddr; | 1034 pResult->loadAddr = loadAddr; |
1012 pResult->initAddr = initAddr; | 1035 pResult->initAddr = initAddr; |
1022 void xs_tuneinfo_free(t_xs_tuneinfo *pTune) | 1045 void xs_tuneinfo_free(t_xs_tuneinfo *pTune) |
1023 { | 1046 { |
1024 gint i; | 1047 gint i; |
1025 if (!pTune) return; | 1048 if (!pTune) return; |
1026 | 1049 |
1050 for (i = 0; i < pTune->nsubTunes; i++) | |
1051 { | |
1052 g_free(pTune->subTunes[i].tuneTitle); | |
1053 pTune->subTunes[i].tuneTitle = NULL; | |
1054 } | |
1055 | |
1056 pTune->nsubTunes = 0; | |
1027 g_free(pTune->sidFilename); pTune->sidFilename = NULL; | 1057 g_free(pTune->sidFilename); pTune->sidFilename = NULL; |
1028 g_free(pTune->sidName); pTune->sidName = NULL; | 1058 g_free(pTune->sidName); pTune->sidName = NULL; |
1029 g_free(pTune->sidComposer); pTune->sidComposer = NULL; | 1059 g_free(pTune->sidComposer); pTune->sidComposer = NULL; |
1030 g_free(pTune->sidCopyright); pTune->sidCopyright = NULL; | 1060 g_free(pTune->sidCopyright); pTune->sidCopyright = NULL; |
1031 | |
1032 for (i = 0; i < pTune->nsubTunes; i++) | |
1033 { | |
1034 if (pTune->subTunes[i].tuneTitle) | |
1035 { | |
1036 g_free(pTune->subTunes[i].tuneTitle); | |
1037 pTune->subTunes[i].tuneTitle = NULL; | |
1038 } | |
1039 } | |
1040 | |
1041 g_free(pTune); | 1061 g_free(pTune); |
1042 } | 1062 } |
1043 | 1063 |