/[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 33 by schoenebeck, Mon Feb 16 19:30:42 2004 UTC revision 207 by schoenebeck, Thu Jul 15 21:51:15 2004 UTC
# Line 2  Line 2 
2   *                                                                         *   *                                                                         *
3   *   LinuxSampler - modular, streaming capable sampler                     *   *   LinuxSampler - modular, streaming capable sampler                     *
4   *                                                                         *   *                                                                         *
5   *   Copyright (C) 2003 by Benno Senoner and Christian Schoenebeck         *   *   Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck   *
6   *                                                                         *   *                                                                         *
7   *   This program is free software; you can redistribute it and/or modify  *   *   This program is free software; you can redistribute it and/or modify  *
8   *   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 20  Line 20 
20   *   MA  02111-1307  USA                                                   *   *   MA  02111-1307  USA                                                   *
21   ***************************************************************************/   ***************************************************************************/
22    
 #include <stdio.h>  
 #include <stdlib.h>  
 #include <unistd.h>  
23  #include <getopt.h>  #include <getopt.h>
24  #include <signal.h>  #include <signal.h>
 #include <pthread.h>  
25    
26  #include "global.h"  #include "Sampler.h"
27  #include "diskthread.h"  #include "drivers/midi/MidiInputDeviceFactory.h"
28  #include "audiothread.h"  #include "drivers/audio/AudioOutputDeviceFactory.h"
29  #include "alsaio.h"  #include "network/lscpserver.h"
 #include "jackio.h"  
 #include "midiin.h"  
 #include "stream.h"  
 #include "RIFF.h"  
 #include "gig.h"  
30    
31    #if 0
32  #define AUDIO_CHANNELS          2     // stereo  #define AUDIO_CHANNELS          2     // stereo
33  #define AUDIO_FRAGMENTS         3     // 3 fragments, if it does not work set it to 2  #define AUDIO_FRAGMENTS         3     // 3 fragments, if it does not work set it to 2
34  #define AUDIO_FRAGMENTSIZE      512   // each fragment has 512 frames  #define AUDIO_FRAGMENTSIZE      512   // each fragment has 512 frames
35  #define AUDIO_SAMPLERATE        44100 // Hz  #define AUDIO_SAMPLERATE        44100 // Hz
36    #endif
37    
38  enum patch_format_t {  using namespace LinuxSampler;
39    
40    /*enum patch_format_t {
41      patch_format_unknown,      patch_format_unknown,
42      patch_format_gig,      patch_format_gig,
43      patch_format_dls      patch_format_dls
44  } patch_format;  } patch_format = patch_format_unknown;*/
45    
46    Sampler*     pSampler         = NULL;
47    LSCPServer*  pLSCPServer      = NULL;
48    pthread_t    signalhandlerthread;
49    /*AudioThread* pEngine          = NULL;
50    uint         instrument_index = 0;
51    double       volume           = 0.25;
52    int          num_fragments    = AUDIO_FRAGMENTS;
53    int          fragmentsize     = AUDIO_FRAGMENTSIZE;
54    uint         samplerate       = AUDIO_SAMPLERATE;
55    String       input_client;
56    String       alsaout          = "0,0"; // default card
57    String       jack_playback[2] = { "", "" };
58    bool         use_jack         = true;
59    bool         run_server       = false;*/
60    
 AudioIO*         pAudioIO;  
 DiskThread*      pDiskThread;  
 AudioThread*     pAudioThread;  
 MidiIn*          pMidiInThread;  
 RIFF::File*      pRIFF;  
 gig::File*       pGig;  
 gig::Instrument* pInstrument;  
 uint             instrument_index;  
 double           volume;  
 int              num_fragments;  
 int              fragmentsize;  
 String           input_client;  
 String           alsaout;  
 String           jack_playback[2];  
 bool             use_jack;  
 pthread_t        signalhandlerthread;  
 uint             samplerate;  
61    
62  void parse_options(int argc, char **argv);  void parse_options(int argc, char **argv);
63  void signal_handler(int signal);  void signal_handler(int signal);
64    
65  int main(int argc, char **argv) {  int main(int argc, char **argv) {
     pAudioIO = NULL;  
     pRIFF    = NULL;  
     pGig     = NULL;  
66    
67      // setting signal handler for catching SIGINT (thus e.g. <CTRL><C>)      // setting signal handler for catching SIGINT (thus e.g. <CTRL><C>)
68      signalhandlerthread = pthread_self();      signalhandlerthread = pthread_self();
69      signal(SIGINT, signal_handler);      signal(SIGINT, signal_handler);
70    
     patch_format      = patch_format_unknown;  
     instrument_index  = 0;  
     num_fragments     = AUDIO_FRAGMENTS;  
     fragmentsize      = AUDIO_FRAGMENTSIZE;  
     volume            = 0.25; // default volume  
     alsaout           = "0,0"; // default card  
     jack_playback[0]  = "";  
     jack_playback[1]  = "";  
     samplerate        = AUDIO_SAMPLERATE;  
     use_jack          = true;  
   
71      // parse and assign command line options      // parse and assign command line options
72      parse_options(argc, argv);      //parse_options(argc, argv);
73    
74      if (patch_format != patch_format_gig) {      /*if (patch_format != patch_format_gig) {
75          printf("Sorry only Gigasampler loading migrated in LinuxSampler so far, use --gig to load a .gig file!\n");          printf("Sorry only Gigasampler loading migrated in LinuxSampler so far, use --gig to load a .gig file!\n");
76          printf("Use 'linuxsampler --help' to see all available options.\n");          printf("Use 'linuxsampler --help' to see all available options.\n");
77          return EXIT_FAILURE;          return EXIT_FAILURE;
78      }      }*/
79    
80        dmsg(1,("LinuxSampler %s\n", VERSION));
81        dmsg(1,("Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck\n"));
82    
83        // create LinuxSampler instance
84        dmsg(1,("Creating Sampler..."));
85        pSampler = new Sampler;
86        dmsg(1,("OK\n"));
87    
88      int error = 1;      dmsg(1,("Registered MIDI input drivers: %s\n", MidiInputDeviceFactory::AvailableDriversAsString().c_str()));
89        dmsg(1,("Registered audio output drivers: %s\n", AudioOutputDeviceFactory::AvailableDriversAsString().c_str()));
90    
91        // create an audio output device
92       /* bool no_jack = true;
93  #if HAVE_JACK  #if HAVE_JACK
94      if (use_jack) {      if (use_jack) {
95          dmsg(1,("Initializing audio output (Jack)..."));          dmsg(1,("Creating audio output device (Jack)..."));
96          pAudioIO = new JackIO();          try {
97          error = ((JackIO*)pAudioIO)->Initialize(AUDIO_CHANNELS, jack_playback);              pSampler->CreateAudioOutputDevice(audio_output_type_jack);
98          if (error) dmsg(1,("Trying Alsa output instead.\n"));              no_jack = false;
99            }
100            catch (AudioOutputException aoe) {
101                aoe.PrintMessage();
102                dmsg(1,("Trying to create Alsa output device instead.\n"));
103            }
104      }      }
105  #endif // HAVE_JACK  #endif // HAVE_JACK
106      if (error) {      if (no_jack) {
107          dmsg(1,("Initializing audio output (Alsa)..."));          dmsg(1,("Creating audio output device (Alsa)..."));
108          pAudioIO = new AlsaIO();          try {
109          int error = ((AlsaIO*)pAudioIO)->Initialize(AUDIO_CHANNELS, samplerate, num_fragments, fragmentsize, alsaout);              pSampler->CreateAudioOutputDevice(audio_output_type_alsa);
110          if (error) return EXIT_FAILURE;          }
111      }          catch (AudioOutputException aoe) {
112      dmsg(1,("OK\n"));              aoe.PrintMessage();
113                dmsg(1,("Trying to create Alsa output device instead.\n"));
114      // Loading gig file              return EXIT_FAILURE;
     try {  
         printf("Loading gig file...");  
         fflush(stdout);  
         pRIFF       = new RIFF::File(argv[argc - 1]);  
         pGig        = new gig::File(pRIFF);  
         pInstrument = pGig->GetInstrument(instrument_index);  
         if (!pInstrument) {  
             printf("there's no instrument with index %d.\n", instrument_index);  
             exit(EXIT_FAILURE);  
115          }          }
         pGig->GetFirstSample(); // just to complete instrument loading before we enter the realtime part  
         printf("OK\n");  
         fflush(stdout);  
     }  
     catch (RIFF::Exception e) {  
         e.PrintMessage();  
         return EXIT_FAILURE;  
     }  
     catch (...) {  
         printf("Unknown exception while trying to parse gig file.\n");  
         return EXIT_FAILURE;  
116      }      }
117        dmsg(1,("OK\n"));*/
118    
119      DiskThread*  pDiskThread   = new DiskThread(((pAudioIO->MaxSamplesPerCycle() << MAX_PITCH) << 1) + 6); //FIXME: assuming stereo      // start LSCP network server
120      AudioThread* pAudioThread  = new AudioThread(pAudioIO, pDiskThread, pInstrument);      dmsg(1,("Starting LSCP network server..."));
121      MidiIn*      pMidiInThread = new MidiIn(pAudioThread);      pLSCPServer = new LSCPServer(pSampler);
122        pLSCPServer->StartThread();
     dmsg(1,("Starting disk thread..."));  
     pDiskThread->StartThread();  
     dmsg(1,("OK\n"));  
     dmsg(1,("Starting MIDI in thread..."));  
     if (input_client.size() > 0) pMidiInThread->SubscribeToClient(input_client.c_str());  
     pMidiInThread->StartThread();  
     dmsg(1,("OK\n"));  
   
     sleep(1);  
     dmsg(1,("Starting audio thread..."));  
     pAudioThread->Volume = volume;  
     pAudioIO->AssignEngine(pAudioThread);  
     pAudioIO->Activate();  
123      dmsg(1,("OK\n"));      dmsg(1,("OK\n"));
124    
125      printf("LinuxSampler initialization completed.\n");      printf("LinuxSampler initialization completed.\n");
126    
127      while(true)  {      while(true)  {
128        printf("Voices: %3.3d (Max: %3.3d) Streams: %3.3d (Max: %3.3d, Unused: %3.3d)\r",        /*printf("Voices: %3.3d (Max: %3.3d) Streams: %3.3d (Max: %3.3d, Unused: %3.3d)\r",
129              pAudioThread->ActiveVoiceCount, pAudioThread->ActiveVoiceCountMax,              pEngine->ActiveVoiceCount, pEngine->ActiveVoiceCountMax,
130              pDiskThread->ActiveStreamCount, pDiskThread->ActiveStreamCountMax, Stream::GetUnusedStreams());              pEngine->pDiskThread->ActiveStreamCount, pEngine->pDiskThread->ActiveStreamCountMax, Stream::GetUnusedStreams());
131        fflush(stdout);        fflush(stdout);*/
132        usleep(500000);        usleep(500000);
133      }      }
134    
# Line 173  int main(int argc, char **argv) { Line 137  int main(int argc, char **argv) {
137    
138  void signal_handler(int signal) {  void signal_handler(int signal) {
139      if (pthread_equal(pthread_self(), signalhandlerthread) && signal == SIGINT) {      if (pthread_equal(pthread_self(), signalhandlerthread) && signal == SIGINT) {
140          // stop all threads          if (pLSCPServer) {
141          if (pAudioIO)      pAudioIO->Close();              pLSCPServer->StopThread();
142          if (pMidiInThread) pMidiInThread->StopThread();              delete pLSCPServer;
143          if (pDiskThread)   pDiskThread->StopThread();          }
144            if (pSampler) delete pSampler;
         // free all resources  
         if (pMidiInThread) delete pMidiInThread;  
         if (pAudioThread)  delete pAudioThread;  
         if (pDiskThread)   delete pDiskThread;  
         if (pGig)          delete pGig;  
         if (pRIFF)         delete pRIFF;  
         if (pAudioIO)      delete pAudioIO;  
   
145          printf("LinuxSampler stopped due to SIGINT\n");          printf("LinuxSampler stopped due to SIGINT\n");
146          exit(EXIT_SUCCESS);          exit(EXIT_SUCCESS);
147      }      }
148  }  }
149    
150  void parse_options(int argc, char **argv) {  /*void parse_options(int argc, char **argv) {
151      int res;      int res;
152      int option_index = 0;      int option_index = 0;
153      static struct option long_options[] =      static struct option long_options[] =
# Line 206  void parse_options(int argc, char **argv Line 162  void parse_options(int argc, char **argv
162              {"alsaout",1,0,0},              {"alsaout",1,0,0},
163              {"jackout",1,0,0},              {"jackout",1,0,0},
164              {"samplerate",1,0,0},              {"samplerate",1,0,0},
165                {"server",0,0,0},
166              {"help",0,0,0},              {"help",0,0,0},
167              {0,0,0,0}              {0,0,0,0}
168          };          };
# Line 263  void parse_options(int argc, char **argv Line 220  void parse_options(int argc, char **argv
220                  case 9: // --samplerate                  case 9: // --samplerate
221                      samplerate = atoi(optarg);                      samplerate = atoi(optarg);
222                      break;                      break;
223                  case 10: // --help                  case 10: // --server
224                        run_server = true;
225                        break;
226                    case 11: // --help
227                      printf("usage: linuxsampler [OPTIONS] <INSTRUMENTFILE>\n\n");                      printf("usage: linuxsampler [OPTIONS] <INSTRUMENTFILE>\n\n");
228                      printf("--gig              loads a Gigasampler instrument\n");                      printf("--gig              loads a Gigasampler instrument\n");
229                      printf("--dls              loads a DLS instrument\n");                      printf("--dls              loads a DLS instrument\n");
# Line 283  void parse_options(int argc, char **argv Line 243  void parse_options(int argc, char **argv
243                      printf("                   in case of stereo output)\n");                      printf("                   in case of stereo output)\n");
244                      printf("--samplerate       sets sample rate if supported by audio output system\n");                      printf("--samplerate       sets sample rate if supported by audio output system\n");
245                      printf("                   (e.g. 44100)\n");                      printf("                   (e.g. 44100)\n");
246                        printf("--server           launch network server for remote control\n");
247                      exit(EXIT_SUCCESS);                      exit(EXIT_SUCCESS);
248                      break;                      break;
249              }              }
250          }          }
251      }      }
252  }  }*/

Legend:
Removed from v.33  
changed lines
  Added in v.207

  ViewVC Help
Powered by ViewVC