/[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 41 by schoenebeck, Wed Mar 31 10:28:42 2004 UTC revision 53 by schoenebeck, Mon Apr 26 17:15:51 2004 UTC
# Line 23  Line 23 
23  #include <getopt.h>  #include <getopt.h>
24  #include <signal.h>  #include <signal.h>
25    
26  #include "global.h"  #include "Sampler.h"
 #include "diskthread.h"  
 #include "audiothread.h"  
 #include "alsaio.h"  
 #include "jackio.h"  
 #include "midiin.h"  
 #include "stream.h"  
 #include "RIFF.h"  
 #include "gig.h"  
27  #include "network/lscpserver.h"  #include "network/lscpserver.h"
28    
29    #if 0
30  #define AUDIO_CHANNELS          2     // stereo  #define AUDIO_CHANNELS          2     // stereo
31  #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
32  #define AUDIO_FRAGMENTSIZE      512   // each fragment has 512 frames  #define AUDIO_FRAGMENTSIZE      512   // each fragment has 512 frames
33  #define AUDIO_SAMPLERATE        44100 // Hz  #define AUDIO_SAMPLERATE        44100 // Hz
34    #endif
35    
36  enum patch_format_t {  using namespace LinuxSampler;
37    
38    /*enum patch_format_t {
39      patch_format_unknown,      patch_format_unknown,
40      patch_format_gig,      patch_format_gig,
41      patch_format_dls      patch_format_dls
42  } patch_format = patch_format_unknown;  } patch_format = patch_format_unknown;*/
43    
44  AudioIO*     pAudioIO         = NULL;  Sampler*     pSampler         = NULL;
 MidiIn*      pMidiInThread    = NULL;  
45  LSCPServer*  pLSCPServer      = NULL;  LSCPServer*  pLSCPServer      = NULL;
46  AudioThread* pEngine          = NULL;  pthread_t    signalhandlerthread;
47    /*AudioThread* pEngine          = NULL;
48  uint         instrument_index = 0;  uint         instrument_index = 0;
49  double       volume           = 0.25;  double       volume           = 0.25;
50  int          num_fragments    = AUDIO_FRAGMENTS;  int          num_fragments    = AUDIO_FRAGMENTS;
# Line 58  String       input_client; Line 54  String       input_client;
54  String       alsaout          = "0,0"; // default card  String       alsaout          = "0,0"; // default card
55  String       jack_playback[2] = { "", "" };  String       jack_playback[2] = { "", "" };
56  bool         use_jack         = true;  bool         use_jack         = true;
57  bool         run_server       = false;  bool         run_server       = false;*/
58  pthread_t    signalhandlerthread;  
59    
60  void parse_options(int argc, char **argv);  void parse_options(int argc, char **argv);
61  void signal_handler(int signal);  void signal_handler(int signal);
# Line 71  int main(int argc, char **argv) { Line 67  int main(int argc, char **argv) {
67      signal(SIGINT, signal_handler);      signal(SIGINT, signal_handler);
68    
69      // parse and assign command line options      // parse and assign command line options
70      parse_options(argc, argv);      //parse_options(argc, argv);
71    
72      if (patch_format != patch_format_gig) {      /*if (patch_format != patch_format_gig) {
73          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");
74          printf("Use 'linuxsampler --help' to see all available options.\n");          printf("Use 'linuxsampler --help' to see all available options.\n");
75          return EXIT_FAILURE;          return EXIT_FAILURE;
76      }      }*/
77    
78      int error = 1;      // create LinuxSampler instance
79        pSampler = new Sampler;
80    
81        // create an audio output device
82       /* bool no_jack = true;
83  #if HAVE_JACK  #if HAVE_JACK
84      if (use_jack) {      if (use_jack) {
85          dmsg(1,("Initializing audio output (Jack)..."));          dmsg(1,("Creating audio output device (Jack)..."));
86          pAudioIO = new JackIO();          try {
87          error = ((JackIO*)pAudioIO)->Initialize(AUDIO_CHANNELS, jack_playback);              pSampler->CreateAudioOutputDevice(audio_output_type_jack);
88          if (error) dmsg(1,("Trying Alsa output instead.\n"));              no_jack = false;
89            }
90            catch (AudioOutputException aoe) {
91                aoe.PrintMessage();
92                dmsg(1,("Trying to create Alsa output device instead.\n"));
93            }
94      }      }
95  #endif // HAVE_JACK  #endif // HAVE_JACK
96      if (error) {      if (no_jack) {
97          dmsg(1,("Initializing audio output (Alsa)..."));          dmsg(1,("Creating audio output device (Alsa)..."));
98          pAudioIO = new AlsaIO();          try {
99          int error = ((AlsaIO*)pAudioIO)->Initialize(AUDIO_CHANNELS, samplerate, num_fragments, fragmentsize, alsaout);              pSampler->CreateAudioOutputDevice(audio_output_type_alsa);
100          if (error) return EXIT_FAILURE;          }
101            catch (AudioOutputException aoe) {
102                aoe.PrintMessage();
103                dmsg(1,("Trying to create Alsa output device instead.\n"));
104                return EXIT_FAILURE;
105            }
106      }      }
107      dmsg(1,("OK\n"));      dmsg(1,("OK\n"));*/
   
     AudioThread* pEngine       = new AudioThread(pAudioIO);  
     MidiIn*      pMidiInThread = new MidiIn(pEngine);  
   
     // Loading gig file  
     result_t result = pEngine->LoadInstrument(argv[argc - 1], instrument_index);  
     if (result.type == result_type_error) return EXIT_FAILURE;  
     pEngine->Volume = volume;  
   
     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);  
108    
109      dmsg(1,("Starting audio thread..."));      // start LSCP network server
110      pAudioIO->AssignEngine(pEngine);      dmsg(1,("Starting network server..."));
111      pAudioIO->Activate();      pLSCPServer = new LSCPServer(pSampler);
112        pLSCPServer->StartThread();
113      dmsg(1,("OK\n"));      dmsg(1,("OK\n"));
114    
     if (run_server) {  
         dmsg(1,("Starting network server..."));  
         pLSCPServer = new LSCPServer(pEngine);  
         pLSCPServer->StartThread();  
         dmsg(1,("OK\n"));  
     }  
   
115      printf("LinuxSampler initialization completed.\n");      printf("LinuxSampler initialization completed.\n");
116    
117      while(true)  {      while(true)  {
118        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",
119              pEngine->ActiveVoiceCount, pEngine->ActiveVoiceCountMax,              pEngine->ActiveVoiceCount, pEngine->ActiveVoiceCountMax,
120              pEngine->pDiskThread->ActiveStreamCount, pEngine->pDiskThread->ActiveStreamCountMax, Stream::GetUnusedStreams());              pEngine->pDiskThread->ActiveStreamCount, pEngine->pDiskThread->ActiveStreamCountMax, Stream::GetUnusedStreams());
121        fflush(stdout);        fflush(stdout);*/
122        usleep(500000);        usleep(500000);
123      }      }
124    
# Line 138  int main(int argc, char **argv) { Line 127  int main(int argc, char **argv) {
127    
128  void signal_handler(int signal) {  void signal_handler(int signal) {
129      if (pthread_equal(pthread_self(), signalhandlerthread) && signal == SIGINT) {      if (pthread_equal(pthread_self(), signalhandlerthread) && signal == SIGINT) {
130          // stop all threads          if (pLSCPServer) {
131          if (pAudioIO)      pAudioIO->Close();              pLSCPServer->StopThread();
132          if (pMidiInThread) pMidiInThread->StopThread();              delete pLSCPServer;
133            }
134          // free all resources          if (pSampler) delete pSampler;
         if (pMidiInThread) delete pMidiInThread;  
         if (pEngine)       delete pEngine;  
         if (pAudioIO)      delete pAudioIO;  
   
135          printf("LinuxSampler stopped due to SIGINT\n");          printf("LinuxSampler stopped due to SIGINT\n");
136          exit(EXIT_SUCCESS);          exit(EXIT_SUCCESS);
137      }      }
138  }  }
139    
140  void parse_options(int argc, char **argv) {  /*void parse_options(int argc, char **argv) {
141      int res;      int res;
142      int option_index = 0;      int option_index = 0;
143      static struct option long_options[] =      static struct option long_options[] =
# Line 254  void parse_options(int argc, char **argv Line 239  void parse_options(int argc, char **argv
239              }              }
240          }          }
241      }      }
242  }  }*/

Legend:
Removed from v.41  
changed lines
  Added in v.53

  ViewVC Help
Powered by ViewVC