--- linuxsampler/trunk/src/network/lscpserver.cpp 2005/02/12 23:48:50 376 +++ linuxsampler/trunk/src/network/lscpserver.cpp 2005/02/21 04:28:50 397 @@ -3,19 +3,20 @@ * LinuxSampler - modular, streaming capable sampler * * * * Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * + * Copyright (C) 2005 Christian Schoenebeck * * * - * This program is free software; you can redistribute it and/or modify * + * This library is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * - * This program is distributed in the hope that it will be useful, * + * This library is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the Free Software * + * along with this library; if not, write to the Free Software * * Foundation, Inc., 59 Temple Place, Suite 330, Boston, * * MA 02111-1307 USA * ***************************************************************************/ @@ -23,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" @@ -52,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"); @@ -451,10 +457,14 @@ if (!pSamplerChannel->GetAudioOutputDevice()) throw LinuxSamplerException("No audio output device connected to sampler channel"); if (bBackground) { - LSCPLoadInstrument *pLoadInstrument = new LSCPLoadInstrument(pEngine, Filename.c_str(), uiInstrument); - pLoadInstrument->StartThread(); + InstrumentLoader.StartNewLoad(Filename, uiInstrument, pEngine); + } + 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(); } - else pEngine->LoadInstrument(Filename.c_str(), uiInstrument); } catch (LinuxSamplerException e) { result.Error(e); @@ -1388,6 +1398,38 @@ 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); + result.Error(selectStr, 666); + } + 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 @@ -1406,30 +1448,3 @@ } return result.Produce(); } - -// Instrument loader constructor. -LSCPLoadInstrument::LSCPLoadInstrument(Engine* pEngine, String Filename, uint uiInstrument) - : Thread(false, 0, -4) -{ - this->pEngine = pEngine; - this->Filename = Filename; - this->uiInstrument = uiInstrument; -} - -// Instrument loader process. -int LSCPLoadInstrument::Main() -{ - try { - pEngine->LoadInstrument(Filename.c_str(), uiInstrument); - } - - catch (LinuxSamplerException e) { - e.PrintMessage(); - } - - // Always re-enable the engine. - pEngine->Enable(); - - // FIXME: Shoot ourselves on the foot? - delete this; -}