# HG changeset patch # User Chris Cannam # Date 1287694296 -3600 # Node ID 816e95ed0b0dde6d170e6c30bdb89939d55379a2 # Parent 9fe53dd1c41a379321fb76d5c944d8db64e7e8d2# Parent 608b0c8ad3f894353872a3874d4a6b1faebf321e Merge diff -r 9fe53dd1c41a -r 816e95ed0b0d chromamethods.cpp --- a/chromamethods.cpp Thu Oct 21 20:56:27 2010 +0100 +++ b/chromamethods.cpp Thu Oct 21 21:51:36 2010 +0100 @@ -208,15 +208,87 @@ return retval; } +static +std::vector +getPluginPath() +{ + //!!! This is duplicated from PluginHostAdapter::getPluginPath, + //!!! which is not available to us in the plugin (only to the + //!!! host) + + std::vector path; + std::string envPath; + + char *cpath = getenv("VAMP_PATH"); + if (cpath) envPath = cpath; + +#ifdef _WIN32 +#define PATH_SEPARATOR ';' +#define DEFAULT_VAMP_PATH "%ProgramFiles%\\Vamp Plugins" +#else +#define PATH_SEPARATOR ':' +#ifdef __APPLE__ +#define DEFAULT_VAMP_PATH "$HOME/Library/Audio/Plug-Ins/Vamp:/Library/Audio/Plug-Ins/Vamp" +#else +#define DEFAULT_VAMP_PATH "$HOME/vamp:$HOME/.vamp:/usr/local/lib/vamp:/usr/lib/vamp" +#endif +#endif + + if (envPath == "") { + envPath = DEFAULT_VAMP_PATH; + char *chome = getenv("HOME"); + if (chome) { + std::string home(chome); + std::string::size_type f; + while ((f = envPath.find("$HOME")) != std::string::npos && + f < envPath.length()) { + envPath.replace(f, 5, home); + } + } +#ifdef _WIN32 + char *cpfiles = getenv("ProgramFiles"); + if (!cpfiles) cpfiles = (char *)"C:\\Program Files"; + std::string pfiles(cpfiles); + std::string::size_type f; + while ((f = envPath.find("%ProgramFiles%")) != std::string::npos && + f < envPath.length()) { + envPath.replace(f, 14, pfiles); + } +#endif + } + + std::string::size_type index = 0, newindex = 0; + + while ((newindex = envPath.find(PATH_SEPARATOR, index)) < envPath.size()) { + path.push_back(envPath.substr(index, newindex - index)); + index = newindex + 1; + } + + path.push_back(envPath.substr(index)); + + return path; +} vector chordDictionary(vector *mchorddict) { - // ifstream chordDictFile; - string chordDictFilename(get_env_var("VAMP_PATH")+"/chord.dict"); - // string instring[] = ",1,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,1,0,0,0,0\nm,1,0,0,0,0,0,0,0,0,0,0,0,1,0,0,1,0,0,0,1,0,0,0,0\n6,1,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,1,0,1,0,0\n7,1,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,1,0,0,1,0\nmaj7,1,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,1,0,0,0,1\nmin7,1,0,0,0,0,0,0,0,0,0,0,0,1,0,0,1,0,0,0,1,0,0,1,0\n,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,1,0,0,1,0,0,0,0\n,0,0,0,0,0,0,0,1,0,0,0,0,1,0,0,0,1,0,0,1,0,0,0,0\ndim,1,0,0,0,0,0,0,0,0,0,0,0,1,0,0,1,0,0,1,0,0,0,0,0\naug,1,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0\n"; + typedef tokenizer > Tok; - // char_separator sep; // default constructed char_separator sep(",; ","="); - iostreams::stream chordDictFile(chordDictFilename.c_str()); + + string chordDictBase("chord.dict"); + string chordDictFilename; + + vector ppath = getPluginPath(); + for (int i = 0; i < ppath.size(); ++i) { + chordDictFilename = ppath[i] + "/" + chordDictBase; + cerr << "Looking for chord.dict in " << chordDictFilename << "..." << endl; + if (iostreams::stream(chordDictFilename.c_str()) + .is_open()) { + cerr << "(Success)" << endl; + break; + } + } + + iostreams::stream chordDictFile(chordDictFilename); string line; int iElement = 0; int nChord = 0;