/[svn]/linuxsampler/trunk/src/network/lscpserver.cpp
ViewVC logotype

Diff of /linuxsampler/trunk/src/network/lscpserver.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 376 by senkov, Sat Feb 12 23:48:50 2005 UTC revision 401 by schoenebeck, Tue Feb 22 14:09:26 2005 UTC
# Line 3  Line 3 
3   *   LinuxSampler - modular, streaming capable sampler                     *   *   LinuxSampler - modular, streaming capable sampler                     *
4   *                                                                         *   *                                                                         *
5   *   Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck   *   *   Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck   *
6     *   Copyright (C) 2005 Christian Schoenebeck                              *
7   *                                                                         *   *                                                                         *
8   *   This program is free software; you can redistribute it and/or modify  *   *   This library is free software; you can redistribute it and/or modify  *
9   *   it under the terms of the GNU General Public License as published by  *   *   it under the terms of the GNU General Public License as published by  *
10   *   the Free Software Foundation; either version 2 of the License, or     *   *   the Free Software Foundation; either version 2 of the License, or     *
11   *   (at your option) any later version.                                   *   *   (at your option) any later version.                                   *
12   *                                                                         *   *                                                                         *
13   *   This program is distributed in the hope that it will be useful,       *   *   This library is distributed in the hope that it will be useful,       *
14   *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *   *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
15   *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *   *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
16   *   GNU General Public License for more details.                          *   *   GNU General Public License for more details.                          *
17   *                                                                         *   *                                                                         *
18   *   You should have received a copy of the GNU General Public License     *   *   You should have received a copy of the GNU General Public License     *
19   *   along with this program; if not, write to the Free Software           *   *   along with this library; if not, write to the Free Software           *
20   *   Foundation, Inc., 59 Temple Place, Suite 330, Boston,                 *   *   Foundation, Inc., 59 Temple Place, Suite 330, Boston,                 *
21   *   MA  02111-1307  USA                                                   *   *   MA  02111-1307  USA                                                   *
22   ***************************************************************************/   ***************************************************************************/
# Line 23  Line 24 
24  #include "lscpserver.h"  #include "lscpserver.h"
25  #include "lscpresultset.h"  #include "lscpresultset.h"
26  #include "lscpevent.h"  #include "lscpevent.h"
27    //#include "../common/global.h"
28    
29    #if HAVE_SQLITE3
30    # include "sqlite3.h"
31    #endif
32    
33  #include "../engines/gig/Engine.h"  #include "../engines/gig/Engine.h"
34  #include "../drivers/audio/AudioOutputDeviceFactory.h"  #include "../drivers/audio/AudioOutputDeviceFactory.h"
# Line 52  Mutex LSCPServer::NotifyBufferMutex = Mu Line 58  Mutex LSCPServer::NotifyBufferMutex = Mu
58  Mutex LSCPServer::SubscriptionMutex = Mutex();  Mutex LSCPServer::SubscriptionMutex = Mutex();
59  Mutex LSCPServer::RTNotifyMutex = Mutex();  Mutex LSCPServer::RTNotifyMutex = Mutex();
60    
61  LSCPServer::LSCPServer(Sampler* pSampler) : Thread(false, 0, -4) {  LSCPServer::LSCPServer(Sampler* pSampler) : Thread(true, false, 0, -4) {
62      this->pSampler = pSampler;      this->pSampler = pSampler;
63      LSCPEvent::RegisterEvent(LSCPEvent::event_channels, "CHANNELS");      LSCPEvent::RegisterEvent(LSCPEvent::event_channels, "CHANNELS");
64      LSCPEvent::RegisterEvent(LSCPEvent::event_voice_count, "VOICE_COUNT");      LSCPEvent::RegisterEvent(LSCPEvent::event_voice_count, "VOICE_COUNT");
# Line 451  String LSCPServer::LoadInstrument(String Line 457  String LSCPServer::LoadInstrument(String
457          if (!pSamplerChannel->GetAudioOutputDevice())          if (!pSamplerChannel->GetAudioOutputDevice())
458              throw LinuxSamplerException("No audio output device connected to sampler channel");              throw LinuxSamplerException("No audio output device connected to sampler channel");
459          if (bBackground) {          if (bBackground) {
460              LSCPLoadInstrument *pLoadInstrument = new LSCPLoadInstrument(pEngine, Filename.c_str(), uiInstrument);              InstrumentLoader.StartNewLoad(Filename, uiInstrument, pEngine);
461              pLoadInstrument->StartThread();          }
462            else {
463                // tell the engine which instrument to load
464                pEngine->PrepareLoadInstrument(Filename.c_str(), uiInstrument);
465                // actually start to load the instrument (blocks until completed)
466                pEngine->LoadInstrument();
467          }          }
         else pEngine->LoadInstrument(Filename.c_str(), uiInstrument);  
468      }      }
469      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
470           result.Error(e);           result.Error(e);
# Line 1388  String LSCPServer::UnsubscribeNotificati Line 1398  String LSCPServer::UnsubscribeNotificati
1398      return result.Produce();      return result.Produce();
1399  }  }
1400    
1401    static int select_callback(void * lscpResultSet, int argc,
1402                            char **argv, char **azColName)
1403    {
1404        LSCPResultSet* resultSet = (LSCPResultSet*) lscpResultSet;
1405        resultSet->Add(argc, argv);
1406        return 0;
1407    }
1408    
1409    String LSCPServer::QueryDatabase(String query) {
1410        LSCPResultSet result;
1411    #if HAVE_SQLITE3
1412        char* zErrMsg = NULL;
1413        sqlite3 *db;
1414        String selectStr = "SELECT " + query;
1415    
1416        int rc = sqlite3_open("linuxsampler.db", &db);
1417        if (rc == SQLITE_OK)
1418        {
1419                rc = sqlite3_exec(db, selectStr.c_str(), select_callback, &result, &zErrMsg);
1420        }
1421        if ( rc != SQLITE_OK )
1422        {
1423                result.Error(String(zErrMsg), rc);
1424        }
1425        sqlite3_close(db);
1426    #else
1427        result.Error(String("SQLITE3 was not installed when linuxsampler was built. SELECT statement is not available."), 0);
1428    #endif
1429        return result.Produce();
1430    }
1431    
1432  /**  /**
1433   * Will be called by the parser to enable or disable echo mode; if echo   * Will be called by the parser to enable or disable echo mode; if echo
1434   * mode is enabled, all commands from the client will (immediately) be   * mode is enabled, all commands from the client will (immediately) be
# Line 1406  String LSCPServer::SetEcho(yyparse_param Line 1447  String LSCPServer::SetEcho(yyparse_param
1447      }      }
1448      return result.Produce();      return result.Produce();
1449  }  }
   
 // 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;  
 }  

Legend:
Removed from v.376  
changed lines
  Added in v.401

  ViewVC Help
Powered by ViewVC