Mercurial > audlegacy-plugins
changeset 1552:96f83b3872ea
Automated merge with ssh://hg.atheme.org//hg/audacious-plugins
author | Sascha Hlusiak <contact@saschahlusiak.de> |
---|---|
date | Sat, 01 Sep 2007 11:18:52 +0200 |
parents | a9af4f1aede9 (current diff) a9d7b36cc6af (diff) |
children | 22f1948c9c28 |
files | |
diffstat | 5 files changed, 64 insertions(+), 231 deletions(-) [+] |
line wrap: on
line diff
--- a/src/modplug/modplugbmp.cxx Fri Aug 31 23:21:30 2007 +0200 +++ b/src/modplug/modplugbmp.cxx Sat Sep 01 11:18:52 2007 +0200 @@ -21,6 +21,16 @@ #include "audacious/vfs.h" } +static char* format_and_free_ti( Tuple* ti, int* length ) +{ + char* result = tuple_formatter_make_title_string(ti, get_gentitle_format()); + if ( result ) + *length = tuple_get_int(ti, "length"); + tuple_free((void *) ti); + + return result; +} + // ModplugXMMS member functions =============================== // operations ---------------------------------------- @@ -317,6 +327,8 @@ void ModplugXMMS::PlayFile(const string& aFilename, InputPlayback *ipb) { + int32 aLength; + char *aModName; mStopped = true; mPaused = false; @@ -401,34 +413,15 @@ mArchive->Size() ); mPlayed = 0; - - bool useFilename = mModProps.mUseFilename; - - if(!useFilename) - { - strncpy(mModName, mSoundFile->GetTitle(), 100); - - for(int i = 0; mModName[i] == ' ' || mModName[i] == 0; i++) - { - if(mModName[i] == 0) - { - useFilename = true; //mod name is blank -- use filename - break; - } - } - } - - if(useFilename) - { - strncpy(mModName, strrchr(aFilename.c_str(), '/') + 1, 100); - char* ext = strrchr(mModName, '.'); - if(ext) *ext = '\0'; - } - + + Tuple* ti = GetSongTuple( aFilename ); + if ( ti ) + aModName = format_and_free_ti( ti, &aLength ); + mInPlug->set_info ( - mModName, - mSoundFile->GetSongTime() * 1000, + aModName, + aLength, mSoundFile->GetNumChannels() * 1000, mModProps.mFrequency, mModProps.mChannels @@ -501,143 +494,11 @@ void ModplugXMMS::GetSongInfo(const string& aFilename, char*& aTitle, int32& aLength) { aLength = -1; - fstream lTestFile; - string lError; - bool lDone; - - lTestFile.open(aFilename.c_str(), ios::in); - if(!lTestFile) - { - lError = "**no such file: "; - lError += strrchr(aFilename.c_str(), '/') + 1; - aTitle = new char[lError.length() + 1]; - strcpy(aTitle, lError.c_str()); - return; - } - - lTestFile.close(); - - if(mModProps.mFastinfo) - { - if(mModProps.mUseFilename) - { - //Use filename as name - aTitle = new char[aFilename.length() + 1]; - strcpy(aTitle, strrchr(aFilename.c_str(), '/') + 1); - *strrchr(aTitle, '.') = '\0'; - return; - } - - fstream lModFile; - string lExt; - uint32 lPos; - - lDone = true; - - // previously ios::nocreate was used (X Standard C++ Library) - lModFile.open(aFilename.c_str(), ios::in); - - lPos = aFilename.find_last_of('.'); - if((int)lPos == 0) - return; - lExt = aFilename.substr(lPos); - for(uint32 i = 0; i < lExt.length(); i++) - lExt[i] = tolower(lExt[i]); - - if (lExt == ".mod") - { - lModFile.read(mModName, 20); - mModName[20] = 0; - } - else if (lExt == ".s3m") - { - lModFile.read(mModName, 28); - mModName[28] = 0; - } - else if (lExt == ".xm") - { - lModFile.seekg(17); - lModFile.read(mModName, 20); - mModName[20] = 0; - } - else if (lExt == ".it") - { - lModFile.seekg(4); - lModFile.read(mModName, 28); - mModName[28] = 0; - } - else - lDone = false; //fall back to slow info + *aTitle = NULL; - lModFile.close(); - - if(lDone) - { - for(int i = 0; mModName[i] != 0; i++) - { - if(mModName[i] != ' ') - { - aTitle = new char[strlen(mModName) + 1]; - strcpy(aTitle, mModName); - - return; - } - } - - //mod name is blank. Use filename instead. - aTitle = new char[aFilename.length() + 1]; - strcpy(aTitle, strrchr(aFilename.c_str(), '/') + 1); - *strrchr(aTitle, '.') = '\0'; - return; - } - } - - Archive* lArchive; - CSoundFile* lSoundFile; - const char* lTitle; - - //open and mmap the file - lArchive = OpenArchive(aFilename); - if(lArchive->Size() == 0) - { - lError = "**bad mod file: "; - lError += strrchr(aFilename.c_str(), '/') + 1; - aTitle = new char[lError.length() + 1]; - strcpy(aTitle, lError.c_str()); - delete lArchive; - return; - } - - lSoundFile = new CSoundFile; - lSoundFile->Create((uchar*)lArchive->Map(), lArchive->Size()); - - if(!mModProps.mUseFilename) - { - lTitle = lSoundFile->GetTitle(); - - for(int i = 0; lTitle[i] != 0; i++) - { - if(lTitle[i] != ' ') - { - aTitle = new char[strlen(lTitle) + 1]; - strcpy(aTitle, lTitle); - goto therest; //sorry - } - } - } - - //mod name is blank, or user wants the filename to be used as the title. - aTitle = new char[aFilename.length() + 1]; - strcpy(aTitle, strrchr(aFilename.c_str(), '/') + 1); - *strrchr(aTitle, '.') = '\0'; - -therest: - aLength = lSoundFile->GetSongTime() * 1000; //It wants milliseconds!?! - - //unload the file - lSoundFile->Destroy(); - delete lSoundFile; - delete lArchive; + Tuple* ti = GetSongTuple( aFilename ); + if ( ti ) + aTitle = format_and_free_ti( ti, &aLength ); } Tuple* ModplugXMMS::GetSongTuple(const string& aFilename)
--- a/src/sid/xs_config.c Fri Aug 31 23:21:30 2007 +0200 +++ b/src/sid/xs_config.c Sat Sep 01 11:18:52 2007 +0200 @@ -299,7 +299,7 @@ if (!XS_CFG_GET_STRING(cfg, XS_CONFIG_IDENT, tmpKey, &tmpStr)) return FALSE; - pResult->name = strdup(tmpStr); + pResult->name = g_strdup(tmpStr); if (pResult->name == NULL) { g_free(pResult); return FALSE;
--- a/src/sid/xs_support.h Fri Aug 31 23:21:30 2007 +0200 +++ b/src/sid/xs_support.h Sat Sep 01 11:18:52 2007 +0200 @@ -17,6 +17,7 @@ #include <audacious/output.h> #include <audacious/util.h> #include <audacious/tuple.h> +#define HAVE_MEMSET #else #include <xmms/plugin.h> #include <xmms/util.h>
--- a/src/sid/xs_title.c Fri Aug 31 23:21:30 2007 +0200 +++ b/src/sid/xs_title.c Sat Sep 01 11:18:52 2007 +0200 @@ -54,7 +54,8 @@ static t_xs_tuple * xs_get_titletuple(gchar *tmpFilename, gchar *tmpFilePath, gchar *tmpFileExt, t_xs_tuneinfo *p, gint subTune) { - t_xs_tuple *pResult; + t_xs_tuple *pResult; + #ifdef AUDACIOUS_PLUGIN pResult = tuple_new(); tuple_associate_string(pResult, "title", p->sidName); @@ -138,14 +139,14 @@ /* Check if the titles are overridden or not */ #if defined(AUDACIOUS_PLUGIN) - if (!xs_cfg.titleOverride) { + if (!xs_cfg.titleOverride) { t_xs_tuple *pTuple = xs_get_titletuple( tmpFilename, tmpFilePath, tmpFileExt, p, subTune); pcResult = tuple_formatter_make_title_string(pTuple, get_gentitle_format()); tuple_free(pTuple); } else #elif defined(HAVE_XMMSEXTRA) - if (!xs_cfg.titleOverride) { + if (!xs_cfg.titleOverride) { t_xs_tuple *pTuple = xs_get_titletuple( tmpFilename, tmpFilePath, tmpFileExt, p, subTune);
--- a/src/xspf/xspf.c Fri Aug 31 23:21:30 2007 +0200 +++ b/src/xspf/xspf.c Sat Sep 01 11:18:52 2007 +0200 @@ -138,7 +138,7 @@ else if(nptr->type == XML_ELEMENT_NODE && !xmlStrcmp(nptr->name, (xmlChar *)"annotation")) { xmlChar *str = xmlNodeGetContent(nptr); - tuple_associate_string(tuple, "comment", (gchar *) str); + tuple_associate_string(tuple, "comment", (gchar *) str); xmlFree(str); } else if(nptr->type == XML_ELEMENT_NODE @@ -328,7 +328,7 @@ if (title && *title) { gchar *old = plist->title; plist->title = g_strdup((gchar*)title); - if(old) g_free(old); + g_free(old); } xmlFree(title); } @@ -476,6 +476,9 @@ PlaylistEntry *entry = PLAYLIST_ENTRY(node->data); xmlNodePtr track, location; gchar *filename = NULL; + const gchar *scratch; + gchar tmps[64]; + gint tmpi; track = xmlNewNode(NULL, (xmlChar *)"track"); location = xmlNewNode(NULL, (xmlChar *)"location"); @@ -487,12 +490,10 @@ filename = g_strdup(entry->filename + baselen); // entry->filename is always uri now. } else { /* local file (obsolete) */ - gchar *tmp = - (gchar *)audPathToURI((const xmlChar *)entry->filename + baselen); + gchar *tmp = (gchar *)audPathToURI((const xmlChar *)entry->filename + baselen); if(base) { /* relative */ filename = g_strdup_printf("%s", tmp); - } - else { + } else { #ifdef DEBUG printf("absolute and local (obsolete)\n"); #endif @@ -510,55 +511,46 @@ /* do we have a tuple? */ if(entry->tuple != NULL) { - const gchar *scratch; if((scratch = tuple_get_string(entry->tuple, "title")) != NULL && - g_utf8_validate(scratch, -1, NULL)) { + g_utf8_validate(scratch, -1, NULL)) { tmp = xmlNewNode(NULL, (xmlChar *)"title"); xmlAddChild(tmp, xmlNewText((xmlChar *) scratch)); xmlAddChild(track, tmp); } if((scratch = tuple_get_string(entry->tuple, "artist")) != NULL && - g_utf8_validate(scratch, -1, NULL)) { + g_utf8_validate(scratch, -1, NULL)) { tmp = xmlNewNode(NULL, (xmlChar *)"creator"); xmlAddChild(tmp, xmlNewText((xmlChar *) scratch)); xmlAddChild(track, tmp); } if((scratch = tuple_get_string(entry->tuple, "comment")) != NULL && - g_utf8_validate(scratch, -1, NULL)) { + g_utf8_validate(scratch, -1, NULL)) { tmp = xmlNewNode(NULL, (xmlChar *)"annotation"); xmlAddChild(tmp, xmlNewText((xmlChar *) scratch)); xmlAddChild(track, tmp); } if((scratch = tuple_get_string(entry->tuple, "album")) != NULL && - g_utf8_validate(scratch, -1, NULL)) { + g_utf8_validate(scratch, -1, NULL)) { tmp = xmlNewNode(NULL, (xmlChar *)"album"); xmlAddChild(tmp, xmlNewText((xmlChar *) scratch)); xmlAddChild(track, tmp); } - if(tuple_get_int(entry->tuple, "track-number") != 0) { - gchar *str; - str = g_malloc(TMP_BUF_LEN); + if((tmpi = tuple_get_int(entry->tuple, "track-number")) != 0) { tmp = xmlNewNode(NULL, (xmlChar *)"trackNum"); - sprintf(str, "%d", tuple_get_int(entry->tuple, "track-number")); - xmlAddChild(tmp, xmlNewText((xmlChar *)str)); - g_free(str); - str = NULL; + g_snprintf(tmps, sizeof(tmps), "%d", tmpi); + xmlAddChild(tmp, xmlNewText((xmlChar *) tmps)); xmlAddChild(track, tmp); } - if(tuple_get_int(entry->tuple, "length") > 0) { - gchar *str; - str = g_malloc(TMP_BUF_LEN); + if((tmpi = tuple_get_int(entry->tuple, "length")) > 0) { tmp = xmlNewNode(NULL, (xmlChar *)"duration"); - sprintf(str, "%d", tuple_get_int(entry->tuple, "length")); - xmlAddChild(tmp, xmlNewText((xmlChar *) str)); - g_free(str); - str = NULL; + g_snprintf(tmps, sizeof(tmps), "%d", tmpi); + xmlAddChild(tmp, xmlNewText((xmlChar *) tmps)); xmlAddChild(track, tmp); } @@ -568,20 +560,16 @@ // year, date, genre, formatter, mtime // - if(tuple_get_int(entry->tuple, "year") != 0) { - gchar *str; - str = g_malloc(TMP_BUF_LEN); + if((tmpi = tuple_get_int(entry->tuple, "year")) != 0) { tmp = xmlNewNode(NULL, (xmlChar *)"meta"); xmlSetProp(tmp, (xmlChar *)"rel", (xmlChar *)"year"); - sprintf(str, "%d", tuple_get_int(entry->tuple, "year")); - xmlAddChild(tmp, xmlNewText((xmlChar *)str)); + g_snprintf(tmps, sizeof(tmps), "%d", tmpi); + xmlAddChild(tmp, xmlNewText((xmlChar *) tmps)); xmlAddChild(track, tmp); - g_free(str); - str = NULL; } if((scratch = tuple_get_string(entry->tuple, "date")) != NULL && - g_utf8_validate(scratch, -1, NULL)) { + g_utf8_validate(scratch, -1, NULL)) { tmp = xmlNewNode(NULL, (xmlChar *)"meta"); xmlSetProp(tmp, (xmlChar *)"rel", (xmlChar *)"date"); xmlAddChild(tmp, xmlNewText((xmlChar *) scratch)); @@ -589,7 +577,7 @@ } if((scratch = tuple_get_string(entry->tuple, "genre")) != NULL && - g_utf8_validate(scratch, -1, NULL)) { + g_utf8_validate(scratch, -1, NULL)) { tmp = xmlNewNode(NULL, (xmlChar *)"meta"); xmlSetProp(tmp, (xmlChar *)"rel", (xmlChar *)"genre"); xmlAddChild(tmp, xmlNewText((xmlChar *) scratch)); @@ -597,7 +585,7 @@ } if((scratch = tuple_get_string(entry->tuple, "formatter")) != NULL && - g_utf8_validate(scratch, -1, NULL)) { + g_utf8_validate(scratch, -1, NULL)) { tmp = xmlNewNode(NULL, (xmlChar *)"meta"); xmlSetProp(tmp, (xmlChar *)"rel", (xmlChar *)"formatter"); xmlAddChild(tmp, xmlNewText((xmlChar *) scratch)); @@ -605,18 +593,11 @@ } // mtime: write mtime unconditionally to support staticlist. - { - gchar *str = g_malloc(TMP_BUF_LEN); - tmp = xmlNewNode(NULL, (xmlChar *)"meta"); - xmlSetProp(tmp, (xmlChar *)"rel", (xmlChar *)"mtime"); - sprintf(str, "%ld", (long) tuple_get_int(entry->tuple, "mtime")); - - xmlAddChild(tmp, xmlNewText((xmlChar *)str)); - xmlAddChild(track, tmp); - g_free(str); - str = NULL; - } - + tmp = xmlNewNode(NULL, (xmlChar *)"meta"); + xmlSetProp(tmp, (xmlChar *)"rel", (xmlChar *)"mtime"); + g_snprintf(tmps, sizeof(tmps), "%ld", (long) tuple_get_int(entry->tuple, "mtime")); + xmlAddChild(tmp, xmlNewText((xmlChar *) tmps)); + xmlAddChild(track, tmp); } /* tuple */ else { @@ -627,29 +608,18 @@ } if(entry->length > 0) { - gchar *str; - str = g_malloc(TMP_BUF_LEN); tmp = xmlNewNode(NULL, (xmlChar *)"duration"); - sprintf(str, "%d", entry->length); - xmlAddChild(tmp, xmlNewText((xmlChar *)str)); - g_free(str); - str = NULL; + g_snprintf(tmps, sizeof(tmps), "%d", entry->length); + xmlAddChild(tmp, xmlNewText((xmlChar *) tmps)); xmlAddChild(track, tmp); } /* add mtime of -1 */ - { - gchar *str = g_malloc(TMP_BUF_LEN); - tmp = xmlNewNode(NULL, (xmlChar *)"meta"); - xmlSetProp(tmp, (xmlChar *)"rel", (xmlChar *)"mtime"); - sprintf(str, "%ld", -1L); - - xmlAddChild(tmp, xmlNewText((xmlChar *)str)); - xmlAddChild(track, tmp); - g_free(str); - str = NULL; - } - + tmp = xmlNewNode(NULL, (xmlChar *)"meta"); + xmlSetProp(tmp, (xmlChar *)"rel", (xmlChar *)"mtime"); + g_snprintf(tmps, sizeof(tmps), "%ld", -1L); + xmlAddChild(tmp, xmlNewText((xmlChar *) tmps)); + xmlAddChild(track, tmp); } /* no tuple */ g_free(filename);