/[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 123 by schoenebeck, Mon Jun 14 19:33:16 2004 UTC revision 319 by schoenebeck, Mon Dec 13 00:46:42 2004 UTC
# Line 24  Line 24 
24  #include <signal.h>  #include <signal.h>
25    
26  #include "Sampler.h"  #include "Sampler.h"
27  #include "audiodriver/AudioOutputDeviceFactory.h"  #include "drivers/midi/MidiInputDeviceFactory.h"
28    #include "drivers/audio/AudioOutputDeviceFactory.h"
29  #include "network/lscpserver.h"  #include "network/lscpserver.h"
30    #include "common/stacktrace.h"
31  #if 0  #include "common/Features.h"
 #define AUDIO_CHANNELS          2     // stereo  
 #define AUDIO_FRAGMENTS         3     // 3 fragments, if it does not work set it to 2  
 #define AUDIO_FRAGMENTSIZE      512   // each fragment has 512 frames  
 #define AUDIO_SAMPLERATE        44100 // Hz  
 #endif  
32    
33  using namespace LinuxSampler;  using namespace LinuxSampler;
34    
35  /*enum patch_format_t {  Sampler*    pSampler    = NULL;
36      patch_format_unknown,  LSCPServer* pLSCPServer = NULL;
37      patch_format_gig,  pthread_t   main_thread;
     patch_format_dls  
 } patch_format = patch_format_unknown;*/  
   
 Sampler*     pSampler         = NULL;  
 LSCPServer*  pLSCPServer      = NULL;  
 pthread_t    signalhandlerthread;  
 /*AudioThread* pEngine          = NULL;  
 uint         instrument_index = 0;  
 double       volume           = 0.25;  
 int          num_fragments    = AUDIO_FRAGMENTS;  
 int          fragmentsize     = AUDIO_FRAGMENTSIZE;  
 uint         samplerate       = AUDIO_SAMPLERATE;  
 String       input_client;  
 String       alsaout          = "0,0"; // default card  
 String       jack_playback[2] = { "", "" };  
 bool         use_jack         = true;  
 bool         run_server       = false;*/  
   
38    
39  void parse_options(int argc, char **argv);  void parse_options(int argc, char **argv);
40  void signal_handler(int signal);  void signal_handler(int signal);
41    void kill_app();
42    
43  int main(int argc, char **argv) {  int main(int argc, char **argv) {
44    
45        // initialize the stack trace mechanism with our binary file
46        StackTraceInit(argv[0], -1);
47    
48        main_thread = pthread_self();
49    
50      // setting signal handler for catching SIGINT (thus e.g. <CTRL><C>)      // setting signal handler for catching SIGINT (thus e.g. <CTRL><C>)
     signalhandlerthread = pthread_self();  
51      signal(SIGINT, signal_handler);      signal(SIGINT, signal_handler);
52    
53        // register signal handler for all unusual signals
54        // (we will print the stack trace and exit)
55        struct sigaction sact;
56        sigemptyset(&sact.sa_mask);
57        sact.sa_flags   = 0;
58        sact.sa_handler = signal_handler;
59        sigaction(SIGSEGV, &sact, NULL);
60        sigaction(SIGBUS,  &sact, NULL);
61        sigaction(SIGILL,  &sact, NULL);
62        sigaction(SIGFPE,  &sact, NULL);
63        sigaction(SIGUSR1, &sact, NULL);
64        sigaction(SIGUSR2, &sact, NULL);
65    
66      // parse and assign command line options      // parse and assign command line options
67      //parse_options(argc, argv);      //parse_options(argc, argv);
68    
69      /*if (patch_format != patch_format_gig) {      dmsg(1,("LinuxSampler %s\n", VERSION));
70          printf("Sorry only Gigasampler loading migrated in LinuxSampler so far, use --gig to load a .gig file!\n");      dmsg(1,("Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck\n"));
         printf("Use 'linuxsampler --help' to see all available options.\n");  
         return EXIT_FAILURE;  
     }*/  
71    
72        // detect and print system / CPU specific features
73        String sFeatures;
74        Features::detect();
75        #if ARCH_X86
76        if (Features::supportsMMX()) sFeatures += " MMX";
77        if (Features::supportsSSE()) sFeatures += " SSE";
78        #endif // ARCH_X86
79        if (!sFeatures.size()) sFeatures = " None";
80        dmsg(1,("Detected features:%s\n",sFeatures.c_str()));
81    
82      // create LinuxSampler instance      // create LinuxSampler instance
83      dmsg(1,("Creating Sampler..."));      dmsg(1,("Creating Sampler..."));
84      pSampler = new Sampler;      pSampler = new Sampler;
85      dmsg(1,("OK\n"));      dmsg(1,("OK\n"));
86    
87        dmsg(1,("Registered MIDI input drivers: %s\n", MidiInputDeviceFactory::AvailableDriversAsString().c_str()));
88      dmsg(1,("Registered audio output drivers: %s\n", AudioOutputDeviceFactory::AvailableDriversAsString().c_str()));      dmsg(1,("Registered audio output drivers: %s\n", AudioOutputDeviceFactory::AvailableDriversAsString().c_str()));
89    
     // create an audio output device  
    /* bool no_jack = true;  
 #if HAVE_JACK  
     if (use_jack) {  
         dmsg(1,("Creating audio output device (Jack)..."));  
         try {  
             pSampler->CreateAudioOutputDevice(audio_output_type_jack);  
             no_jack = false;  
         }  
         catch (AudioOutputException aoe) {  
             aoe.PrintMessage();  
             dmsg(1,("Trying to create Alsa output device instead.\n"));  
         }  
     }  
 #endif // HAVE_JACK  
     if (no_jack) {  
         dmsg(1,("Creating audio output device (Alsa)..."));  
         try {  
             pSampler->CreateAudioOutputDevice(audio_output_type_alsa);  
         }  
         catch (AudioOutputException aoe) {  
             aoe.PrintMessage();  
             dmsg(1,("Trying to create Alsa output device instead.\n"));  
             return EXIT_FAILURE;  
         }  
     }  
     dmsg(1,("OK\n"));*/  
   
90      // start LSCP network server      // start LSCP network server
91      dmsg(1,("Starting network server..."));      dmsg(1,("Starting LSCP network server (on TCP port %d)...", LSCP_PORT));
92      pLSCPServer = new LSCPServer(pSampler);      pLSCPServer = new LSCPServer(pSampler);
93      pLSCPServer->StartThread();      pLSCPServer->StartThread();
94        pLSCPServer->WaitUntilInitialized();
95      dmsg(1,("OK\n"));      dmsg(1,("OK\n"));
96    
97      printf("LinuxSampler initialization completed.\n");      printf("LinuxSampler initialization completed.\n");
# Line 131  int main(int argc, char **argv) { Line 107  int main(int argc, char **argv) {
107      return EXIT_SUCCESS;      return EXIT_SUCCESS;
108  }  }
109    
110  void signal_handler(int signal) {  void signal_handler(int iSignal) {
111      if (pthread_equal(pthread_self(), signalhandlerthread) && signal == SIGINT) {      switch (iSignal) {
112          if (pLSCPServer) {          case SIGINT: {
113              pLSCPServer->StopThread();              if (pthread_equal(pthread_self(), main_thread)) {
114              delete pLSCPServer;                  if (pLSCPServer) {
115                        pLSCPServer->StopThread();
116                        delete pLSCPServer;
117                    }
118                    if (pSampler) delete pSampler;
119                    printf("LinuxSampler stopped due to SIGINT.\n");
120                    exit(EXIT_SUCCESS);
121                }
122                return;
123            }
124            case SIGSEGV:
125                std::cerr << ">>> FATAL ERROR: Segmentation fault (SIGSEGV) occured! <<<\n" << std::flush;
126                break;
127            case SIGBUS:
128                std::cerr << ">>> FATAL ERROR: Access to undefined portion of a memory object (SIGBUS) occured! <<<\n" << std::flush;
129                break;
130            case SIGILL:
131                std::cerr << ">>> FATAL ERROR: Illegal instruction (SIGILL) occured! <<<\n" << std::flush;
132                break;
133            case SIGFPE:
134                std::cerr << ">>> FATAL ERROR: Erroneous arithmetic operation (SIGFPE) occured! <<<\n" << std::flush;
135                break;
136            case SIGUSR1:
137                std::cerr << ">>> User defined signal 1 (SIGUSR1) received <<<\n" << std::flush;
138                break;
139            case SIGUSR2:
140                std::cerr << ">>> User defined signal 2 (SIGUSR2) received <<<\n" << std::flush;
141                break;
142            default: { // this should never happen, as we register for the signals we want
143                std::cerr << ">>> FATAL ERROR: Unknown signal received! <<<\n" << std::flush;
144                break;
145          }          }
         if (pSampler) delete pSampler;  
         printf("LinuxSampler stopped due to SIGINT\n");  
         exit(EXIT_SUCCESS);  
146      }      }
147        signal(iSignal, SIG_DFL); // Reinstall default handler to prevent race conditions
148        std::cerr << "Showing stack trace...\n" << std::flush;
149        StackTrace();
150        sleep(2);
151        std::cerr << "Killing LinuxSampler...\n" << std::flush;
152        kill_app(); // Use abort() if we want to generate a core dump.
153    }
154    
155    void kill_app() {
156        kill(main_thread, SIGKILL);
157  }  }
158    
159  /*void parse_options(int argc, char **argv) {  /*void parse_options(int argc, char **argv) {

Legend:
Removed from v.123  
changed lines
  Added in v.319

  ViewVC Help
Powered by ViewVC