/[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 211 by schoenebeck, Sun Jul 25 23:27:41 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"
30  #include "jackio.h"  
31  #include "midiin.h"  using namespace LinuxSampler;
32  #include "stream.h"  
33  #include "RIFF.h"  Sampler*    pSampler    = NULL;
34  #include "gig.h"  LSCPServer* pLSCPServer = NULL;
35    pthread_t   signalhandlerthread;
 #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  
   
 enum patch_format_t {  
     patch_format_unknown,  
     patch_format_gig,  
     patch_format_dls  
 } patch_format;  
   
 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;  
36    
37  void parse_options(int argc, char **argv);  void parse_options(int argc, char **argv);
38  void signal_handler(int signal);  void signal_handler(int signal);
39    
40  int main(int argc, char **argv) {  int main(int argc, char **argv) {
     pAudioIO = NULL;  
     pRIFF    = NULL;  
     pGig     = NULL;  
41    
42      // setting signal handler for catching SIGINT (thus e.g. <CTRL><C>)      // setting signal handler for catching SIGINT (thus e.g. <CTRL><C>)
43      signalhandlerthread = pthread_self();      signalhandlerthread = pthread_self();
44      signal(SIGINT, signal_handler);      signal(SIGINT, signal_handler);
45    
     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;  
   
46      // parse and assign command line options      // parse and assign command line options
47      parse_options(argc, argv);      //parse_options(argc, argv);
48    
49      if (patch_format != patch_format_gig) {      dmsg(1,("LinuxSampler %s\n", VERSION));
50          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;  
     }  
51    
52      int error = 1;      // create LinuxSampler instance
53  #if HAVE_JACK      dmsg(1,("Creating Sampler..."));
54      if (use_jack) {      pSampler = new Sampler;
         dmsg(1,("Initializing audio output (Jack)..."));  
         pAudioIO = new JackIO();  
         error = ((JackIO*)pAudioIO)->Initialize(AUDIO_CHANNELS, jack_playback);  
         if (error) dmsg(1,("Trying Alsa output instead.\n"));  
     }  
 #endif // HAVE_JACK  
     if (error) {  
         dmsg(1,("Initializing audio output (Alsa)..."));  
         pAudioIO = new AlsaIO();  
         int error = ((AlsaIO*)pAudioIO)->Initialize(AUDIO_CHANNELS, samplerate, num_fragments, fragmentsize, alsaout);  
         if (error) return EXIT_FAILURE;  
     }  
55      dmsg(1,("OK\n"));      dmsg(1,("OK\n"));
56    
57      // Loading gig file      dmsg(1,("Registered MIDI input drivers: %s\n", MidiInputDeviceFactory::AvailableDriversAsString().c_str()));
58      try {      dmsg(1,("Registered audio output drivers: %s\n", AudioOutputDeviceFactory::AvailableDriversAsString().c_str()));
         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);  
         }  
         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;  
     }  
   
     DiskThread*  pDiskThread   = new DiskThread(((pAudioIO->MaxSamplesPerCycle() << MAX_PITCH) << 1) + 6); //FIXME: assuming stereo  
     AudioThread* pAudioThread  = new AudioThread(pAudioIO, pDiskThread, pInstrument);  
     MidiIn*      pMidiInThread = new MidiIn(pAudioThread);  
   
     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"));  
59    
60      sleep(1);      // start LSCP network server
61      dmsg(1,("Starting audio thread..."));      dmsg(1,("Starting LSCP network server..."));
62      pAudioThread->Volume = volume;      pLSCPServer = new LSCPServer(pSampler);
63      pAudioIO->AssignEngine(pAudioThread);      pLSCPServer->StartThread();
64      pAudioIO->Activate();      pLSCPServer->WaitUntilInitialized();
65      dmsg(1,("OK\n"));      dmsg(1,("OK\n"));
66    
67      printf("LinuxSampler initialization completed.\n");      printf("LinuxSampler initialization completed.\n");
68    
69      while(true)  {      while(true)  {
70        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",
71              pAudioThread->ActiveVoiceCount, pAudioThread->ActiveVoiceCountMax,              pEngine->ActiveVoiceCount, pEngine->ActiveVoiceCountMax,
72              pDiskThread->ActiveStreamCount, pDiskThread->ActiveStreamCountMax, Stream::GetUnusedStreams());              pEngine->pDiskThread->ActiveStreamCount, pEngine->pDiskThread->ActiveStreamCountMax, Stream::GetUnusedStreams());
73        fflush(stdout);        fflush(stdout);*/
74        usleep(500000);        usleep(500000);
75      }      }
76    
# Line 173  int main(int argc, char **argv) { Line 79  int main(int argc, char **argv) {
79    
80  void signal_handler(int signal) {  void signal_handler(int signal) {
81      if (pthread_equal(pthread_self(), signalhandlerthread) && signal == SIGINT) {      if (pthread_equal(pthread_self(), signalhandlerthread) && signal == SIGINT) {
82          // stop all threads          if (pLSCPServer) {
83          if (pAudioIO)      pAudioIO->Close();              pLSCPServer->StopThread();
84          if (pMidiInThread) pMidiInThread->StopThread();              delete pLSCPServer;
85          if (pDiskThread)   pDiskThread->StopThread();          }
86            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;  
   
87          printf("LinuxSampler stopped due to SIGINT\n");          printf("LinuxSampler stopped due to SIGINT\n");
88          exit(EXIT_SUCCESS);          exit(EXIT_SUCCESS);
89      }      }
90  }  }
91    
92  void parse_options(int argc, char **argv) {  /*void parse_options(int argc, char **argv) {
93      int res;      int res;
94      int option_index = 0;      int option_index = 0;
95      static struct option long_options[] =      static struct option long_options[] =
# Line 206  void parse_options(int argc, char **argv Line 104  void parse_options(int argc, char **argv
104              {"alsaout",1,0,0},              {"alsaout",1,0,0},
105              {"jackout",1,0,0},              {"jackout",1,0,0},
106              {"samplerate",1,0,0},              {"samplerate",1,0,0},
107                {"server",0,0,0},
108              {"help",0,0,0},              {"help",0,0,0},
109              {0,0,0,0}              {0,0,0,0}
110          };          };
# Line 263  void parse_options(int argc, char **argv Line 162  void parse_options(int argc, char **argv
162                  case 9: // --samplerate                  case 9: // --samplerate
163                      samplerate = atoi(optarg);                      samplerate = atoi(optarg);
164                      break;                      break;
165                  case 10: // --help                  case 10: // --server
166                        run_server = true;
167                        break;
168                    case 11: // --help
169                      printf("usage: linuxsampler [OPTIONS] <INSTRUMENTFILE>\n\n");                      printf("usage: linuxsampler [OPTIONS] <INSTRUMENTFILE>\n\n");
170                      printf("--gig              loads a Gigasampler instrument\n");                      printf("--gig              loads a Gigasampler instrument\n");
171                      printf("--dls              loads a DLS instrument\n");                      printf("--dls              loads a DLS instrument\n");
# Line 283  void parse_options(int argc, char **argv Line 185  void parse_options(int argc, char **argv
185                      printf("                   in case of stereo output)\n");                      printf("                   in case of stereo output)\n");
186                      printf("--samplerate       sets sample rate if supported by audio output system\n");                      printf("--samplerate       sets sample rate if supported by audio output system\n");
187                      printf("                   (e.g. 44100)\n");                      printf("                   (e.g. 44100)\n");
188                        printf("--server           launch network server for remote control\n");
189                      exit(EXIT_SUCCESS);                      exit(EXIT_SUCCESS);
190                      break;                      break;
191              }              }
192          }          }
193      }      }
194  }  }*/

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

  ViewVC Help
Powered by ViewVC