Mercurial > hg > xmms-sid
view src/xs_sidplay.h @ 112:fb16fc1fd506 dev-0_8_0b7
Minor updates to docs, added reference to IRC-channel
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 12 Jan 2004 01:54:01 +0000 |
parents | 98a72c44f56b |
children | 54e4557859dc |
line wrap: on
line source
/* * Here comes the really ugly code... * * Create the SID-tune description string from the tune's information * formatted by the user-specified format-string. */ #define VBUFSIZE (1024) #define VPUTCH(MCH) if (iIndex < VBUFSIZE) tmpBuf[iIndex++] = MCH; #define VPUTSTR(MSTR) {if (MSTR) {if ((iIndex + strlen(MSTR) + 1) < VBUFSIZE){strcpy(&tmpBuf[iIndex], MSTR);iIndex += strlen(MSTR); } else iIndex = VBUFSIZE;}} gchar * TFUNCTION1(gchar *pcFilename, TTUNEINFO *pfInfo, gint iSubTune) { gchar *sFileName, *sFilePath, *sFileExt, *pcStr, *pcResult, tmpStr[VBUFSIZE], tmpBuf[VBUFSIZE]; gint iIndex; #ifdef HAVE_XMMSEXTRA TitleInput *ptInput; #endif /* Check the info strings */ if (pfInfo->numberOfInfoStrings < 3) { if (pfInfo->numberOfInfoStrings < 1) return 0; return g_strdup(pfInfo->infoString[0]); } /* Split the filename into path */ sFilePath = g_strdup(pcFilename); sFileName = strrchr(sFilePath, '/'); if (sFileName) sFileName[1] = 0; /* Filename */ sFileName = strrchr(pcFilename, '/'); if (sFileName) sFileName = g_strdup(sFileName + 1); else sFileName = g_strdup(pcFilename); sFileExt = strrchr(sFileName, '.'); sFileExt[0] = 0; /* Extension */ sFileExt = strrchr(pcFilename, '.'); /* FIXME FIXME: get STIL-information */ #ifdef HAVE_XMMSEXTRA /* Check if the titles are overridden or not */ if (!xs_cfg.titleOverride) { /* Use generic XMMS titles */ /* XMMS_NEW_TITLEINPUT(ptInput); * We duplicate and add typecast to the code here due to XMMS's braindead headers */ ptInput = (TitleInput *) g_malloc0(sizeof(TitleInput)); ptInput->__size = XMMS_TITLEINPUT_SIZE; ptInput->__version = XMMS_TITLEINPUT_VERSION; /* Create the input fields */ ptInput->file_name = sFileName; ptInput->file_ext = sFileExt; ptInput->file_path = sFilePath; ptInput->track_name = pfInfo->infoString[0]; ptInput->track_number = iSubTune; ptInput->album_name = NULL; ptInput->performer = pfInfo->infoString[1]; ptInput->date = g_strdup((pfInfo->sidModel == SIDTUNE_SIDMODEL_6581) ? "6581" : "8580"); ptInput->year = 0; ptInput->genre = g_strdup("SID-tune"); ptInput->comment = pfInfo->infoString[2]; /* Create the string */ pcResult = xmms_get_titlestring(xmms_get_gentitle_format(), ptInput); /* Dispose all allocated memory */ g_free(ptInput->date); g_free(ptInput->genre); g_free(ptInput); } else #endif { /* Create the string */ pcStr = xs_cfg.titleFormat; iIndex = 0; while (*pcStr && (iIndex < VBUFSIZE)) { if (*pcStr == '%') { pcStr++; switch (*pcStr) { case '%': VPUTCH('%'); break; case 'f': VPUTSTR(sFileName); break; case 'F': VPUTSTR(sFilePath); break; case 'e': VPUTSTR(sFileExt); break; case 'p': VPUTSTR(pfInfo->infoString[1]); break; case 't': VPUTSTR(pfInfo->infoString[0]); break; case 'c': VPUTSTR(pfInfo->infoString[2]); break; case 's': VPUTSTR(pfInfo->formatString); break; case 'n': snprintf(tmpStr, VBUFSIZE, "%i", iSubTune); VPUTSTR(tmpStr); break; } } else { VPUTCH(*pcStr); } pcStr++; } tmpBuf[iIndex] = 0; /* Make resulting string */ pcResult = g_strdup(tmpBuf); } /* Free temporary strings */ g_free(sFileName); g_free(sFilePath); return pcResult; } /* * Get all SID-tune information (for all sub-tunes) including name, length, etc. */ t_xs_tune * TFUNCTION2(gchar *pcFilename) { t_xs_sldb_node *tuneLen = NULL; t_xs_tune *pResult; TTUNEINFO tuneInfo; TTUNE *testTune; gboolean haveInfo = TRUE; gint i; /* Check if the tune exists and is readable */ if ((testTune = new TTUNE(pcFilename)) == NULL) return NULL; if (!testTune->getStatus()) { delete testTune; return NULL; } /* Get general tune information */ #ifdef _XS_SIDPLAY1_H haveInfo = testTune->getInfo(tuneInfo); #endif #ifdef _XS_SIDPLAY2_H testTune->getInfo(tuneInfo); haveInfo = TRUE; #endif /* Get length information (NOTE: Do not free this!) */ tuneLen = xs_songlen_get(pcFilename); /* Allocate tuneinfo structure */ pResult = xs_tune_new(pcFilename, tuneInfo.songs, tuneInfo.startSong, tuneInfo.infoString[0], tuneInfo.infoString[1], tuneInfo.infoString[2]); if (!pResult) { delete testTune; return NULL; } /* Get information for subtunes */ for (i = 0; i < pResult->nsubTunes; i++) { /* Make the title */ if (haveInfo) pResult->subTunes[i].tuneTitle = TFUNCTION1(pcFilename, &tuneInfo, i+1); else pResult->subTunes[i].tuneTitle = g_strdup(pcFilename); /* Get song length */ if (tuneLen && (i < tuneLen->nLengths)) pResult->subTunes[i].tuneLength = tuneLen->sLengths[i]; else pResult->subTunes[i].tuneLength = -1; } delete testTune; return pResult; } /* Undefine these */ #undef TFUNCTION1 #undef TFUNCTION2 #undef TTUNEINFO #undef TTUNE