--- linuxsampler/trunk/src/network/lscpserver.cpp 2005/02/17 02:53:45 385 +++ linuxsampler/trunk/src/network/lscpserver.cpp 2005/02/21 04:35:31 398 @@ -24,6 +24,11 @@ #include "lscpserver.h" #include "lscpresultset.h" #include "lscpevent.h" +//#include "../common/global.h" + +#ifdef HAVE_SQLITE3 +#include "sqlite3.h" +#endif #include "../engines/gig/Engine.h" #include "../drivers/audio/AudioOutputDeviceFactory.h" @@ -53,7 +58,7 @@ Mutex LSCPServer::SubscriptionMutex = Mutex(); Mutex LSCPServer::RTNotifyMutex = Mutex(); -LSCPServer::LSCPServer(Sampler* pSampler) : Thread(false, 0, -4) { +LSCPServer::LSCPServer(Sampler* pSampler) : Thread(true, false, 0, -4) { this->pSampler = pSampler; LSCPEvent::RegisterEvent(LSCPEvent::event_channels, "CHANNELS"); LSCPEvent::RegisterEvent(LSCPEvent::event_voice_count, "VOICE_COUNT"); @@ -454,7 +459,12 @@ if (bBackground) { InstrumentLoader.StartNewLoad(Filename, uiInstrument, pEngine); } - else pEngine->LoadInstrument(Filename.c_str(), uiInstrument); + else { + // tell the engine which instrument to load + pEngine->PrepareLoadInstrument(Filename.c_str(), uiInstrument); + // actually start to load the instrument (blocks until completed) + pEngine->LoadInstrument(); + } } catch (LinuxSamplerException e) { result.Error(e); @@ -1388,6 +1398,37 @@ return result.Produce(); } +static int select_callback(void * lscpResultSet, int argc, + char **argv, char **azColName) +{ + LSCPResultSet* resultSet = (LSCPResultSet*) lscpResultSet; + resultSet->Add(argc, argv); + return 0; +} + +String LSCPServer::QueryDatabase(String query) { + LSCPResultSet result; +#ifdef HAVE_SQLITE3 + char* zErrMsg = NULL; + sqlite3 *db; + String selectStr = "SELECT " + query; + + int rc = sqlite3_open("linuxsampler.db", &db); + if (rc == SQLITE_OK) + { + rc = sqlite3_exec(db, selectStr.c_str(), select_callback, &result, &zErrMsg); + } + if ( rc != SQLITE_OK ) + { + result.Error(String(zErrMsg), rc); + } + sqlite3_close(db); +#else + result.Error(String("SQLITE3 was not installed when linuxsampler was built. SELECT statement is not available."), 0); +#endif + return result.Produce(); +} + /** * Will be called by the parser to enable or disable echo mode; if echo * mode is enabled, all commands from the client will (immediately) be