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

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

  ViewVC Help
Powered by ViewVC