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

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

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

revision 1502 by senoner, Wed Nov 21 07:29:52 2007 UTC revision 1644 by persson, Sat Jan 19 16:55:03 2008 UTC
# Line 2  Line 2 
2   *                                                                         *   *                                                                         *
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-2007 Christian Schoenebeck                        *   *   Copyright (C) 2005-2008 Christian Schoenebeck                         *
7   *                                                                         *   *                                                                         *
8   *   This program is free software; you can redistribute it and/or modify  *   *   This program 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  *
# Line 39  Line 39 
39  #include "network/lscpserver.h"  #include "network/lscpserver.h"
40  #include "common/stacktrace.h"  #include "common/stacktrace.h"
41  #include "common/Features.h"  #include "common/Features.h"
42    #include "common/atomic.h"
43    
44  using namespace LinuxSampler;  using namespace LinuxSampler;
45    
# Line 56  int inet_aton(const char *cp, struct in_ Line 57  int inet_aton(const char *cp, struct in_
57      return (addr->s_addr == INADDR_NONE) ? 0 : 1;      return (addr->s_addr == INADDR_NONE) ? 0 : 1;
58  }  }
59    
 DWORD main_thread;  
60  #else  #else
 pthread_t   main_thread;  
61  pid_t       main_pid;  pid_t       main_pid;
62  #endif  #endif
63  bool bPrintStatistics = false;  bool bPrintStatistics = false;
# Line 70  unsigned short int lscp_port; Line 69  unsigned short int lscp_port;
69  void parse_options(int argc, char **argv);  void parse_options(int argc, char **argv);
70  void signal_handler(int signal);  void signal_handler(int signal);
71  void kill_app();  void kill_app();
72    static atomic_t running = ATOMIC_INIT(1);
73    
74  int main(int argc, char **argv) {  int main(int argc, char **argv) {
75    
# Line 124  int main(int argc, char **argv) { Line 124  int main(int argc, char **argv) {
124      dmsg(1,("AFTER GetProcessWorkingSetSize: res = %d  MinimumWorkingSetSize=%d, MaximumWorkingSetSize=%d\n", res,MinimumWorkingSetSize, MaximumWorkingSetSize));      dmsg(1,("AFTER GetProcessWorkingSetSize: res = %d  MinimumWorkingSetSize=%d, MaximumWorkingSetSize=%d\n", res,MinimumWorkingSetSize, MaximumWorkingSetSize));
125      #endif      #endif
126    
127      #if defined(WIN32)      #if !defined(WIN32)
     main_thread = GetCurrentThreadId();  
     #else  
128      main_pid = getpid();      main_pid = getpid();
     main_thread = pthread_self();  
129      #endif      #endif
130    
131      // setting signal handler for catching SIGINT (thus e.g. <CTRL><C>)      // setting signal handler for catching SIGINT (thus e.g. <CTRL><C>)
# Line 205  int main(int argc, char **argv) { Line 202  int main(int argc, char **argv) {
202      rtEvents.push_back(LSCPEvent::event_buffer_fill);      rtEvents.push_back(LSCPEvent::event_buffer_fill);
203      rtEvents.push_back(LSCPEvent::event_total_voice_count);      rtEvents.push_back(LSCPEvent::event_total_voice_count);
204    
205      while (true) {      while (atomic_read(&running)) {
206          if (bPrintStatistics) {          if (bPrintStatistics) {
207              const std::set<Engine*>& engines = EngineFactory::EngineInstances();              const std::set<Engine*>& engines = EngineFactory::EngineInstances();
208              std::set<Engine*>::iterator itEngine = engines.begin();              std::set<Engine*>::iterator itEngine = engines.begin();
# Line 219  int main(int argc, char **argv) { Line 216  int main(int argc, char **argv) {
216              }              }
217          }          }
218    
219        sleep(1);          sleep(1);
220        if (profile)          if (profile)
221        {          {
222            unsigned int samplingFreq = 48000; //FIXME: hardcoded for now              unsigned int samplingFreq = 48000; //FIXME: hardcoded for now
223            unsigned int bv = LinuxSampler::gig::Profiler::GetBogoVoices(samplingFreq);              unsigned int bv = LinuxSampler::gig::Profiler::GetBogoVoices(samplingFreq);
224            if (bv != 0)              if (bv != 0)
225            {              {
226                printf("       BogoVoices: %i         \r", bv);                  printf("       BogoVoices: %i         \r", bv);
227                fflush(stdout);                  fflush(stdout);
228            }              }
229        }          }
   
       if (LSCPServer::EventSubscribers(rtEvents))  
       {  
           LSCPServer::LockRTNotify();  
           std::map<uint,SamplerChannel*> channels = pSampler->GetSamplerChannels();  
           std::map<uint,SamplerChannel*>::iterator iter = channels.begin();  
           for (; iter != channels.end(); iter++) {  
               SamplerChannel* pSamplerChannel = iter->second;  
               EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();  
               if (!pEngineChannel) continue;  
               Engine* pEngine = pEngineChannel->GetEngine();  
               if (!pEngine) continue;  
               pSampler->fireVoiceCountChanged(iter->first, pEngineChannel->GetVoiceCount());  
               pSampler->fireStreamCountChanged(iter->first, pEngineChannel->GetDiskStreamCount());  
               pSampler->fireBufferFillChanged(iter->first, pEngine->DiskStreamBufferFillPercentage());  
               pSampler->fireTotalVoiceCountChanged(pSampler->GetVoiceCount());  
           }  
           LSCPServer::UnlockRTNotify();  
       }  
230    
231            if (LSCPServer::EventSubscribers(rtEvents))
232            {
233                LSCPServer::LockRTNotify();
234                std::map<uint,SamplerChannel*> channels = pSampler->GetSamplerChannels();
235                std::map<uint,SamplerChannel*>::iterator iter = channels.begin();
236                for (; iter != channels.end(); iter++) {
237                    SamplerChannel* pSamplerChannel = iter->second;
238                    EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
239                    if (!pEngineChannel) continue;
240                    Engine* pEngine = pEngineChannel->GetEngine();
241                    if (!pEngine) continue;
242                    pSampler->fireVoiceCountChanged(iter->first, pEngineChannel->GetVoiceCount());
243                    pSampler->fireStreamCountChanged(iter->first, pEngineChannel->GetDiskStreamCount());
244                    pSampler->fireBufferFillChanged(iter->first, pEngine->DiskStreamBufferFillPercentage());
245                    pSampler->fireTotalStreamCountChanged(pSampler->GetDiskStreamCount());
246                    pSampler->fireTotalVoiceCountChanged(pSampler->GetVoiceCount());
247                }
248                LSCPServer::UnlockRTNotify();
249            }
250      }      }
251        if (pLSCPServer) pLSCPServer->StopThread();
252        // the delete order here is important: the Sampler
253        // destructor sends notifications to the lscpserver
254        if (pSampler) delete pSampler;
255        if (pLSCPServer) delete pLSCPServer;
256        printf("LinuxSampler stopped due to SIGINT.\n");
257      return EXIT_SUCCESS;      return EXIT_SUCCESS;
258  }  }
259    
260  void signal_handler(int iSignal) {  void signal_handler(int iSignal) {
261      switch (iSignal) {      switch (iSignal) {
262          case SIGINT: {          case SIGINT:
263              #if defined(WIN32)              atomic_set(&running, 0);
             if( GetCurrentThreadId() == main_thread ) {  
             #else  
             if (pthread_equal(pthread_self(), main_thread)) {  
             #endif  
                 if (pLSCPServer) pLSCPServer->StopThread();  
                 // the delete order here is important: the Sampler  
                 // destructor sends notifications to the lscpserver  
                 if (pSampler) delete pSampler;  
                 if (pLSCPServer) delete pLSCPServer;  
 #if HAVE_SQLITE3  
                 InstrumentsDb::Destroy();  
 #endif  
                 printf("LinuxSampler stopped due to SIGINT.\n");  
                 exit(EXIT_SUCCESS);  
             }  
264              return;              return;
         }  
265          #if defined(WIN32)          #if defined(WIN32)
266          // FIXME: under WIN32 we ignore the signals below due to the missing sigaction call          // FIXME: under WIN32 we ignore the signals below due to the missing sigaction call
267          #else          #else
# Line 411  void parse_options(int argc, char **argv Line 397  void parse_options(int argc, char **argv
397                          if (optarg) {                          if (optarg) {
398                              std::cout << "Creating instruments database..." << std::endl;                              std::cout << "Creating instruments database..." << std::endl;
399                              InstrumentsDb::CreateInstrumentsDb(String(optarg));                              InstrumentsDb::CreateInstrumentsDb(String(optarg));
                             InstrumentsDb::Destroy();  
400                              std::cout << "Done" << std::endl;                              std::cout << "Done" << std::endl;
401                          }                          }
402                      } catch(Exception e) {                      } catch(Exception e) {

Legend:
Removed from v.1502  
changed lines
  Added in v.1644

  ViewVC Help
Powered by ViewVC