/[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 1541 by iliev, Tue Dec 4 18:09:26 2007 UTC revision 1830 by schoenebeck, Sat Jan 31 11:31:41 2009 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-2009 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 63  pid_t       main_pid; Line 63  pid_t       main_pid;
63  bool bPrintStatistics = false;  bool bPrintStatistics = false;
64  bool profile = false;  bool profile = false;
65  bool tune = true;  bool tune = true;
66    static bool bShowStackTrace = false;
67  unsigned long int lscp_addr;  unsigned long int lscp_addr;
68  unsigned short int lscp_port;  unsigned short int lscp_port;
69    
# Line 73  static atomic_t running = ATOMIC_INIT(1) Line 74  static atomic_t running = ATOMIC_INIT(1)
74    
75  int main(int argc, char **argv) {  int main(int argc, char **argv) {
76    
77        lscp_addr = htonl(LSCP_ADDR);
78        lscp_port = htons(LSCP_PORT);
79    
80        #if !defined(WIN32)
81        main_pid = getpid();
82        #endif
83    
84        // parse and assign command line options
85        parse_options(argc, argv);
86    
87        // setting signal handler for catching SIGINT (thus e.g. <CTRL><C>)
88        signal(SIGINT, signal_handler);
89    
90      // initialize the stack trace mechanism with our binary file      // initialize the stack trace mechanism with our binary file
91      StackTraceInit(argv[0], -1);      // (if requested by command line option)
92        if (bShowStackTrace) {
93            #if defined(WIN32)
94            // FIXME: sigaction() not supported on WIN32, we ignore it for now
95            #else
96            StackTraceInit(argv[0], -1);
97            // register signal handler for all unusual signals
98            // (we will print the stack trace and exit)
99            struct sigaction sact;
100            sigemptyset(&sact.sa_mask);
101            sact.sa_flags   = 0;
102            sact.sa_handler = signal_handler;
103            sigaction(SIGSEGV, &sact, NULL);
104            sigaction(SIGBUS,  &sact, NULL);
105            sigaction(SIGILL,  &sact, NULL);
106            sigaction(SIGFPE,  &sact, NULL);
107            sigaction(SIGUSR1, &sact, NULL);
108            sigaction(SIGUSR2, &sact, NULL);
109            #endif
110        }
111    
112        dmsg(1,("LinuxSampler %s\n", VERSION));
113        dmsg(1,("Copyright (C) 2003,2004 by Benno Senoner and Christian Schoenebeck\n"));
114        dmsg(1,("Copyright (C) 2005-2009 Christian Schoenebeck\n"));
115    
116      #if defined(WIN32)      #if defined(WIN32)
117      // some WIN32 memory info code which tries to determine the maximum lockable amount of memory (for debug purposes)      // some WIN32 memory info code which tries to determine the maximum lockable amount of memory (for debug purposes)
# Line 122  int main(int argc, char **argv) { Line 159  int main(int argc, char **argv) {
159      }      }
160    
161      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));
162      #endif      #endif // WIN32
   
     #if !defined(WIN32)  
     main_pid = getpid();  
     #endif  
   
     // setting signal handler for catching SIGINT (thus e.g. <CTRL><C>)  
     signal(SIGINT, signal_handler);  
   
     #if defined(WIN32)  
     // FIXME: sigaction() not supported on WIN32, we ignore it for now  
     #else  
     // register signal handler for all unusual signals  
     // (we will print the stack trace and exit)  
     struct sigaction sact;  
     sigemptyset(&sact.sa_mask);  
     sact.sa_flags   = 0;  
     sact.sa_handler = signal_handler;  
     sigaction(SIGSEGV, &sact, NULL);  
     sigaction(SIGBUS,  &sact, NULL);  
     sigaction(SIGILL,  &sact, NULL);  
     sigaction(SIGFPE,  &sact, NULL);  
     sigaction(SIGUSR1, &sact, NULL);  
     sigaction(SIGUSR2, &sact, NULL);  
     #endif  
   
     lscp_addr = htonl(LSCP_ADDR);  
     lscp_port = htons(LSCP_PORT);  
   
     // parse and assign command line options  
     parse_options(argc, argv);  
   
     dmsg(1,("LinuxSampler %s\n", VERSION));  
     dmsg(1,("Copyright (C) 2003,2004 by Benno Senoner and Christian Schoenebeck\n"));  
     dmsg(1,("Copyright (C) 2005-2007 Christian Schoenebeck\n"));  
163    
164      if (tune) {      if (tune) {
165          // detect and print system / CPU specific features          // detect and print system / CPU specific features
# Line 166  int main(int argc, char **argv) { Line 169  int main(int argc, char **argv) {
169          Features::enableDenormalsAreZeroMode();          Features::enableDenormalsAreZeroMode();
170      }      }
171    
172        dmsg(1,("Automatic Stacktrace: %s\n", (bShowStackTrace) ? "On" : "Off"));
173    
174      // create LinuxSampler instance      // create LinuxSampler instance
175      dmsg(1,("Creating Sampler..."));      dmsg(1,("Creating Sampler..."));
176      pSampler = new Sampler;      pSampler = new Sampler;
# Line 196  int main(int argc, char **argv) { Line 201  int main(int argc, char **argv) {
201    
202      printf("LinuxSampler initialization completed. :-)\n\n");      printf("LinuxSampler initialization completed. :-)\n\n");
203    
     std::list<LSCPEvent::event_t> rtEvents;  
     rtEvents.push_back(LSCPEvent::event_voice_count);  
     rtEvents.push_back(LSCPEvent::event_stream_count);  
     rtEvents.push_back(LSCPEvent::event_buffer_fill);  
     rtEvents.push_back(LSCPEvent::event_total_voice_count);  
   
204      while (atomic_read(&running)) {      while (atomic_read(&running)) {
205          if (bPrintStatistics) {          if (bPrintStatistics) {
206              const std::set<Engine*>& engines = EngineFactory::EngineInstances();              const std::set<Engine*>& engines = EngineFactory::EngineInstances();
# Line 228  int main(int argc, char **argv) { Line 227  int main(int argc, char **argv) {
227              }              }
228          }          }
229    
230          if (LSCPServer::EventSubscribers(rtEvents))          pSampler->fireStatistics();
         {  
             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->fireTotalStreamCountChanged(pSampler->GetDiskStreamCount());  
                 pSampler->fireTotalVoiceCountChanged(pSampler->GetVoiceCount());  
             }  
             LSCPServer::UnlockRTNotify();  
         }  
231      }      }
232      if (pLSCPServer) pLSCPServer->StopThread();      if (pLSCPServer) pLSCPServer->StopThread();
233      // the delete order here is important: the Sampler      // the delete order here is important: the Sampler
234      // destructor sends notifications to the lscpserver      // destructor sends notifications to the lscpserver
235      if (pSampler) delete pSampler;      if (pSampler) delete pSampler;
236      if (pLSCPServer) delete pLSCPServer;      if (pLSCPServer) delete pLSCPServer;
 #if HAVE_SQLITE3  
     InstrumentsDb::Destroy();  
 #endif  
237      printf("LinuxSampler stopped due to SIGINT.\n");      printf("LinuxSampler stopped due to SIGINT.\n");
238      return EXIT_SUCCESS;      return EXIT_SUCCESS;
239  }  }
# Line 293  void signal_handler(int iSignal) { Line 271  void signal_handler(int iSignal) {
271          }          }
272      }      }
273      signal(iSignal, SIG_DFL); // Reinstall default handler to prevent race conditions      signal(iSignal, SIG_DFL); // Reinstall default handler to prevent race conditions
274      std::cerr << "Showing stack trace...\n" << std::flush;      if (bShowStackTrace) {
275      StackTrace();          std::cerr << "Showing stack trace...\n" << std::flush;
276      sleep(2);          StackTrace();
277            sleep(2);
278        }
279      std::cerr << "Killing LinuxSampler...\n" << std::flush;      std::cerr << "Killing LinuxSampler...\n" << std::flush;
280      kill_app(); // Use abort() if we want to generate a core dump.      kill_app(); // Use abort() if we want to generate a core dump.
281  }  }
# Line 323  void parse_options(int argc, char **argv Line 303  void parse_options(int argc, char **argv
303              {"create-instruments-db",1,0,0},              {"create-instruments-db",1,0,0},
304              {"lscp-addr",1,0,0},              {"lscp-addr",1,0,0},
305              {"lscp-port",1,0,0},              {"lscp-port",1,0,0},
306                {"stacktrace",0,0,0},
307              {0,0,0,0}              {0,0,0,0}
308          };          };
309    
# Line 346  void parse_options(int argc, char **argv Line 327  void parse_options(int argc, char **argv
327                      printf("--lscp-port                 set LSCP port (default: 8888)\n");                      printf("--lscp-port                 set LSCP port (default: 8888)\n");
328                      printf("--create-instruments-db     creates an instruments DB\n");                      printf("--create-instruments-db     creates an instruments DB\n");
329                      printf("--instruments-db-location   specifies the instruments DB file\n");                      printf("--instruments-db-location   specifies the instruments DB file\n");
330                        printf("--stacktrace                automatically shows stacktrace if crashes\n");
331                        printf("                            (broken on most systems at the moment)\n");
332                      exit(EXIT_SUCCESS);                      exit(EXIT_SUCCESS);
333                      break;                      break;
334                  case 1: // --version                  case 1: // --version
# Line 400  void parse_options(int argc, char **argv Line 383  void parse_options(int argc, char **argv
383                          if (optarg) {                          if (optarg) {
384                              std::cout << "Creating instruments database..." << std::endl;                              std::cout << "Creating instruments database..." << std::endl;
385                              InstrumentsDb::CreateInstrumentsDb(String(optarg));                              InstrumentsDb::CreateInstrumentsDb(String(optarg));
                             InstrumentsDb::Destroy();  
386                              std::cout << "Done" << std::endl;                              std::cout << "Done" << std::endl;
387                          }                          }
388                      } catch(Exception e) {                      } catch(Exception e) {
# Line 417  void parse_options(int argc, char **argv Line 399  void parse_options(int argc, char **argv
399                      exit(EXIT_FAILURE);                      exit(EXIT_FAILURE);
400                      return;                      return;
401  #endif  #endif
402                  case 7: // --lscp-addr                  case 7: { // --lscp-addr
403                      struct in_addr addr;                      struct in_addr addr;
404                      if (inet_aton(optarg, &addr) == 0)                      if (inet_aton(optarg, &addr) == 0)
405                          printf("WARNING: Failed to parse lscp-addr argument, ignoring!\n");                          printf("WARNING: Failed to parse lscp-addr argument, ignoring!\n");
406                      else                      else
407                          lscp_addr = addr.s_addr;                          lscp_addr = addr.s_addr;
408                      break;                      break;
409                  case 8: // --lscp-port                  }
410                    case 8: {// --lscp-port
411                      long unsigned int port = 0;                      long unsigned int port = 0;
412                      if ((sscanf(optarg, "%u", &port) != 1) || (port == 0) || (port > 65535))                      if ((sscanf(optarg, "%u", &port) != 1) || (port == 0) || (port > 65535))
413                          printf("WARNING: Failed to parse lscp-port argument, ignoring!\n");                          printf("WARNING: Failed to parse lscp-port argument, ignoring!\n");
414                      else                      else
415                          lscp_port = htons(port);                          lscp_port = htons(port);
416                      break;                      break;
417                    }
418                    case 9: // --stacktrace
419                        bShowStackTrace = true;
420                        break;
421              }              }
422          }          }
423      }      }

Legend:
Removed from v.1541  
changed lines
  Added in v.1830

  ViewVC Help
Powered by ViewVC