Mercurial > hg > audiodb
diff audioDB.cpp @ 409:99e6cbad7f76 api-inversion
The lesser of two evils, part 2.
Implement paths through audiodb_insert_datum_internal() for databases
with O2_FLAG_LARGE_ADB, including in some of the helper functions. Most
of the nasty stuff is concentrated in writing out the paths in what is
now step 6, and everything else looks much as before, apart from a
renumbering of the steps taken.
Now we can implement audiodb_insert() for O2_FLAG_LARGE_ADB databases;
we need to construct an adb_datum_internal_t from our adb_insert_t, but
that's straightforward -- even just about straightforward enough to do
it inline.
Then audioDB::batchinsert() can be rewritten completely in terms of API
functions, and doesn't need any kind of special treatment for the large
case. Hooray. The real point of that is of course that we can now
delete wodges of dead code, and move out audioDB::insert and
audioDB::batchinsert into audioDB.cpp, because all they're doing now is
dealing with command-line logic.
This point marks the limit of what can be achieved in terms of "API
inversion" at this time; the only remaining function,
audiodb_query() / audioDB::query cannot be inverted because its
API implementation is incomplete.
Future plans, in some order:
- merge this branch to trunk (check with current API/ABI clients);
- complete audiodb_query() implementation;
- invert audioDB::query / audiodb_query();
- MORE TESTS;
- remove audioDB.cpp from list of files compiled into the library;
- implement missing API functions (index, liszt, sample) directly;
- source code rearrangement into library and command-line directories;
- include bindings to library for some plausible candidate environments
(Perl, Python, Lisp, Pd, Max/MSP) as examples;
- API documentation.
author | mas01cr |
---|---|
date | Tue, 09 Dec 2008 22:48:30 +0000 |
parents | ef4792df8f93 |
children | a7d61291fbda |
line wrap: on
line diff
--- a/audioDB.cpp Tue Dec 09 20:53:39 2008 +0000 +++ b/audioDB.cpp Tue Dec 09 22:48:30 2008 +0000 @@ -733,6 +733,108 @@ status(dbName); } +void audioDB::insert(const char* dbName, const char* inFile) { + if(!adb) { + if(!(adb = audiodb_open(dbName, O_RDWR))) { + error("failed to open database", dbName); + } + } + + /* at this point, we have powerfd (an fd), timesFile (a + * std::ifstream *) and inFile (a char *). Wacky, huh? Ignore + * the wackiness and just use the names. */ + adb_insert_t insert; + insert.features = inFile; + insert.times = timesFileName; + insert.power = powerFileName; + insert.key = key; + + if(audiodb_insert(adb, &insert)) { + error("insertion failure", inFile); + } + status(dbName); +} + +void audioDB::batchinsert(const char* dbName, const char* inFile) { + if(!adb) { + if(!(adb = audiodb_open(dbName, O_RDWR))) { + error("failed to open database", dbName); + } + } + + if(!key) + key=inFile; + std::ifstream *filesIn = 0; + std::ifstream *keysIn = 0; + + if(!(filesIn = new std::ifstream(inFile))) + error("Could not open batch in file", inFile); + if(key && key!=inFile) + if(!(keysIn = new std::ifstream(key))) + error("Could not open batch key file",key); + + unsigned totalVectors=0; + char *thisFile = new char[MAXSTR]; + char *thisKey = 0; + if (key && (key != inFile)) { + thisKey = new char[MAXSTR]; + } + char *thisTimesFileName = new char[MAXSTR]; + char *thisPowerFileName = new char[MAXSTR]; + + do { + filesIn->getline(thisFile,MAXSTR); + if(key && key!=inFile) { + keysIn->getline(thisKey,MAXSTR); + } else { + thisKey = thisFile; + } + if(usingTimes) { + timesFile->getline(thisTimesFileName,MAXSTR); + } + if(usingPower) { + powerFile->getline(thisPowerFileName, MAXSTR); + } + + if(filesIn->eof()) { + break; + } + if(usingTimes){ + if(timesFile->eof()) { + error("not enough timestamp files in timesList", timesFileName); + } + } + if (usingPower) { + if(powerFile->eof()) { + error("not enough power files in powerList", powerFileName); + } + } + adb_insert_t insert; + insert.features = thisFile; + insert.times = usingTimes ? thisTimesFileName : NULL; + insert.power = usingPower ? thisPowerFileName : NULL; + insert.key = thisKey; + if(audiodb_insert(adb, &insert)) { + error("insertion failure", thisFile); + } + } while(!filesIn->eof()); + + VERB_LOG(0, "%s %s %u vectors %ju bytes.\n", COM_BATCHINSERT, dbName, totalVectors, (intmax_t) (totalVectors * dbH->dim * sizeof(double))); + + delete [] thisPowerFileName; + if(key && (key != inFile)) { + delete [] thisKey; + } + delete [] thisFile; + delete [] thisTimesFileName; + + delete filesIn; + delete keysIn; + + // Report status + status(dbName); +} + // This entry point is visited once per instance // so it is a good place to set any global state variables int main(const int argc, const char* argv[]){