/[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 271 by schoenebeck, Fri Oct 8 20:51:39 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"
 #if 0  
 #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  
31    
32  using namespace LinuxSampler;  using namespace LinuxSampler;
33    
34  /*enum patch_format_t {  Sampler*    pSampler    = NULL;
35      patch_format_unknown,  LSCPServer* pLSCPServer = NULL;
36      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;*/  
   
37    
38  void parse_options(int argc, char **argv);  void parse_options(int argc, char **argv);
39  void signal_handler(int signal);  void signal_handler(int signal);
40    void kill_app();
41    
42  int main(int argc, char **argv) {  int main(int argc, char **argv) {
43    
44        // initialize the stack trace mechanism with our binary file
45        StackTraceInit(argv[0], -1);
46    
47        main_thread = pthread_self();
48    
49      // 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();  
50      signal(SIGINT, signal_handler);      signal(SIGINT, signal_handler);
51    
52        // register signal handler for all unusual signals
53        // (we will print the stack trace and exit)
54        struct sigaction sact;
55        sigemptyset(&sact.sa_mask);
56        sact.sa_flags   = 0;
57        sact.sa_handler = signal_handler;
58        sigaction(SIGSEGV, &sact, NULL);
59        sigaction(SIGBUS,  &sact, NULL);
60        sigaction(SIGILL,  &sact, NULL);
61        sigaction(SIGFPE,  &sact, NULL);
62        sigaction(SIGUSR1, &sact, NULL);
63        sigaction(SIGUSR2, &sact, NULL);
64    
65      // parse and assign command line options      // parse and assign command line options
66      //parse_options(argc, argv);      //parse_options(argc, argv);
67    
68      /*if (patch_format != patch_format_gig) {      dmsg(1,("LinuxSampler %s\n", VERSION));
69          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;  
     }*/  
   
70    
71      // create LinuxSampler instance      // create LinuxSampler instance
72      dmsg(1,("Creating Sampler..."));      dmsg(1,("Creating Sampler..."));
73      pSampler = new Sampler;      pSampler = new Sampler;
74      dmsg(1,("OK\n"));      dmsg(1,("OK\n"));
75    
76        dmsg(1,("Registered MIDI input drivers: %s\n", MidiInputDeviceFactory::AvailableDriversAsString().c_str()));
77      dmsg(1,("Registered audio output drivers: %s\n", AudioOutputDeviceFactory::AvailableDriversAsString().c_str()));      dmsg(1,("Registered audio output drivers: %s\n", AudioOutputDeviceFactory::AvailableDriversAsString().c_str()));
78    
     // 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"));*/  
   
79      // start LSCP network server      // start LSCP network server
80      dmsg(1,("Starting network server..."));      dmsg(1,("Starting LSCP network server (on TCP port %d)...", LSCP_PORT));
81      pLSCPServer = new LSCPServer(pSampler);      pLSCPServer = new LSCPServer(pSampler);
82      pLSCPServer->StartThread();      pLSCPServer->StartThread();
83        pLSCPServer->WaitUntilInitialized();
84      dmsg(1,("OK\n"));      dmsg(1,("OK\n"));
85    
86      printf("LinuxSampler initialization completed.\n");      printf("LinuxSampler initialization completed.\n");
# Line 131  int main(int argc, char **argv) { Line 96  int main(int argc, char **argv) {
96      return EXIT_SUCCESS;      return EXIT_SUCCESS;
97  }  }
98    
99  void signal_handler(int signal) {  void signal_handler(int iSignal) {
100      if (pthread_equal(pthread_self(), signalhandlerthread) && signal == SIGINT) {      switch (iSignal) {
101          if (pLSCPServer) {          case SIGINT: {
102              pLSCPServer->StopThread();              if (pthread_equal(pthread_self(), main_thread)) {
103              delete pLSCPServer;                  if (pLSCPServer) {
104                        pLSCPServer->StopThread();
105                        delete pLSCPServer;
106                    }
107                    if (pSampler) delete pSampler;
108                    printf("LinuxSampler stopped due to SIGINT.\n");
109                    exit(EXIT_SUCCESS);
110                }
111                return;
112            }
113            case SIGSEGV:
114                std::cerr << ">>> FATAL ERROR: Segmentation fault (SIGSEGV) occured! <<<\n" << std::flush;
115                break;
116            case SIGBUS:
117                std::cerr << ">>> FATAL ERROR: Access to undefined portion of a memory object (SIGBUS) occured! <<<\n" << std::flush;
118                break;
119            case SIGILL:
120                std::cerr << ">>> FATAL ERROR: Illegal instruction (SIGILL) occured! <<<\n" << std::flush;
121                break;
122            case SIGFPE:
123                std::cerr << ">>> FATAL ERROR: Erroneous arithmetic operation (SIGFPE) occured! <<<\n" << std::flush;
124                break;
125            case SIGUSR1:
126                std::cerr << ">>> User defined signal 1 (SIGUSR1) received <<<\n" << std::flush;
127                break;
128            case SIGUSR2:
129                std::cerr << ">>> User defined signal 2 (SIGUSR2) received <<<\n" << std::flush;
130                break;
131            default: { // this should never happen, as we register for the signals we want
132                std::cerr << ">>> FATAL ERROR: Unknown signal received! <<<\n" << std::flush;
133                break;
134          }          }
         if (pSampler) delete pSampler;  
         printf("LinuxSampler stopped due to SIGINT\n");  
         exit(EXIT_SUCCESS);  
135      }      }
136        signal(iSignal, SIG_DFL); // Reinstall default handler to prevent race conditions
137        std::cerr << "Showing stack trace...\n" << std::flush;
138        StackTrace();
139        sleep(2);
140        std::cerr << "Killing LinuxSampler...\n" << std::flush;
141        kill_app(); // Use abort() if we want to generate a core dump.
142    }
143    
144    void kill_app() {
145        kill(main_thread, SIGKILL);
146  }  }
147    
148  /*void parse_options(int argc, char **argv) {  /*void parse_options(int argc, char **argv) {

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

  ViewVC Help
Powered by ViewVC