/[svn]/linuxsampler/trunk/src/linuxsampler.cpp
ViewVC logotype

Annotation of /linuxsampler/trunk/src/linuxsampler.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 203 - (hide annotations) (download)
Tue Jul 13 22:44:13 2004 UTC (19 years, 9 months ago) by schoenebeck
File size: 10580 byte(s)
forgot to change some things which was mandatory due to the recent
directory movements ('/src/audiodriver' -> '/src/drivers/audio',
'/src/mididriver' -> '/src/drivers/midi')

1 schoenebeck 9 /***************************************************************************
2     * *
3     * LinuxSampler - modular, streaming capable sampler *
4     * *
5 schoenebeck 61 * Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck *
6 schoenebeck 9 * *
7     * 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 *
9     * the Free Software Foundation; either version 2 of the License, or *
10     * (at your option) any later version. *
11     * *
12     * This program is distributed in the hope that it will be useful, *
13     * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15     * GNU General Public License for more details. *
16     * *
17     * You should have received a copy of the GNU General Public License *
18     * along with this program; if not, write to the Free Software *
19     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, *
20     * MA 02111-1307 USA *
21     ***************************************************************************/
22    
23     #include <getopt.h>
24     #include <signal.h>
25    
26 schoenebeck 53 #include "Sampler.h"
27 schoenebeck 203 #include "drivers/audio/AudioOutputDeviceFactory.h"
28 schoenebeck 35 #include "network/lscpserver.h"
29 schoenebeck 9
30 schoenebeck 53 #if 0
31 schoenebeck 9 #define AUDIO_CHANNELS 2 // stereo
32     #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
34     #define AUDIO_SAMPLERATE 44100 // Hz
35 schoenebeck 53 #endif
36 schoenebeck 9
37 schoenebeck 53 using namespace LinuxSampler;
38    
39     /*enum patch_format_t {
40 schoenebeck 9 patch_format_unknown,
41     patch_format_gig,
42     patch_format_dls
43 schoenebeck 53 } patch_format = patch_format_unknown;*/
44 schoenebeck 9
45 schoenebeck 53 Sampler* pSampler = NULL;
46 schoenebeck 35 LSCPServer* pLSCPServer = NULL;
47 schoenebeck 53 pthread_t signalhandlerthread;
48     /*AudioThread* pEngine = NULL;
49 schoenebeck 35 uint instrument_index = 0;
50     double volume = 0.25;
51     int num_fragments = AUDIO_FRAGMENTS;
52     int fragmentsize = AUDIO_FRAGMENTSIZE;
53     uint samplerate = AUDIO_SAMPLERATE;
54     String input_client;
55     String alsaout = "0,0"; // default card
56     String jack_playback[2] = { "", "" };
57     bool use_jack = true;
58 schoenebeck 53 bool run_server = false;*/
59 schoenebeck 9
60 schoenebeck 53
61 schoenebeck 9 void parse_options(int argc, char **argv);
62     void signal_handler(int signal);
63    
64     int main(int argc, char **argv) {
65    
66     // setting signal handler for catching SIGINT (thus e.g. <CTRL><C>)
67 schoenebeck 13 signalhandlerthread = pthread_self();
68 schoenebeck 9 signal(SIGINT, signal_handler);
69    
70     // parse and assign command line options
71 schoenebeck 53 //parse_options(argc, argv);
72 schoenebeck 9
73 schoenebeck 53 /*if (patch_format != patch_format_gig) {
74 schoenebeck 12 printf("Sorry only Gigasampler loading migrated in LinuxSampler so far, use --gig to load a .gig file!\n");
75 schoenebeck 20 printf("Use 'linuxsampler --help' to see all available options.\n");
76 schoenebeck 9 return EXIT_FAILURE;
77 schoenebeck 53 }*/
78 schoenebeck 9
79 schoenebeck 123
80 schoenebeck 53 // create LinuxSampler instance
81 schoenebeck 123 dmsg(1,("Creating Sampler..."));
82 schoenebeck 53 pSampler = new Sampler;
83 schoenebeck 123 dmsg(1,("OK\n"));
84 schoenebeck 53
85 schoenebeck 123 dmsg(1,("Registered audio output drivers: %s\n", AudioOutputDeviceFactory::AvailableDriversAsString().c_str()));
86    
87 schoenebeck 53 // create an audio output device
88     /* bool no_jack = true;
89 schoenebeck 31 #if HAVE_JACK
90 schoenebeck 33 if (use_jack) {
91 schoenebeck 53 dmsg(1,("Creating audio output device (Jack)..."));
92     try {
93     pSampler->CreateAudioOutputDevice(audio_output_type_jack);
94     no_jack = false;
95     }
96     catch (AudioOutputException aoe) {
97     aoe.PrintMessage();
98     dmsg(1,("Trying to create Alsa output device instead.\n"));
99     }
100 schoenebeck 33 }
101     #endif // HAVE_JACK
102 schoenebeck 53 if (no_jack) {
103     dmsg(1,("Creating audio output device (Alsa)..."));
104     try {
105     pSampler->CreateAudioOutputDevice(audio_output_type_alsa);
106     }
107     catch (AudioOutputException aoe) {
108     aoe.PrintMessage();
109     dmsg(1,("Trying to create Alsa output device instead.\n"));
110     return EXIT_FAILURE;
111     }
112 schoenebeck 31 }
113 schoenebeck 53 dmsg(1,("OK\n"));*/
114 schoenebeck 9
115 schoenebeck 53 // start LSCP network server
116     dmsg(1,("Starting network server..."));
117     pLSCPServer = new LSCPServer(pSampler);
118     pLSCPServer->StartThread();
119 schoenebeck 12 dmsg(1,("OK\n"));
120 schoenebeck 9
121     printf("LinuxSampler initialization completed.\n");
122    
123 senoner 10 while(true) {
124 schoenebeck 53 /*printf("Voices: %3.3d (Max: %3.3d) Streams: %3.3d (Max: %3.3d, Unused: %3.3d)\r",
125 schoenebeck 35 pEngine->ActiveVoiceCount, pEngine->ActiveVoiceCountMax,
126     pEngine->pDiskThread->ActiveStreamCount, pEngine->pDiskThread->ActiveStreamCountMax, Stream::GetUnusedStreams());
127 schoenebeck 53 fflush(stdout);*/
128 senoner 10 usleep(500000);
129     }
130    
131 schoenebeck 9 return EXIT_SUCCESS;
132     }
133    
134     void signal_handler(int signal) {
135 schoenebeck 20 if (pthread_equal(pthread_self(), signalhandlerthread) && signal == SIGINT) {
136 schoenebeck 53 if (pLSCPServer) {
137     pLSCPServer->StopThread();
138     delete pLSCPServer;
139     }
140     if (pSampler) delete pSampler;
141 schoenebeck 9 printf("LinuxSampler stopped due to SIGINT\n");
142     exit(EXIT_SUCCESS);
143     }
144     }
145    
146 schoenebeck 53 /*void parse_options(int argc, char **argv) {
147 schoenebeck 9 int res;
148     int option_index = 0;
149     static struct option long_options[] =
150     {
151     {"numfragments",1,0,0},
152     {"fragmentsize",1,0,0},
153 schoenebeck 20 {"volume",1,0,0},
154 schoenebeck 9 {"dls",0,0,0},
155     {"gig",0,0,0},
156 schoenebeck 20 {"instrument",1,0,0},
157     {"inputclient",1,0,0},
158 schoenebeck 33 {"alsaout",1,0,0},
159     {"jackout",1,0,0},
160     {"samplerate",1,0,0},
161 schoenebeck 35 {"server",0,0,0},
162 schoenebeck 9 {"help",0,0,0},
163     {0,0,0,0}
164     };
165    
166     while (true) {
167     res = getopt_long_only(argc, argv, "", long_options, &option_index);
168     if(res == -1) break;
169     if (res == 0) {
170     switch(option_index) {
171 schoenebeck 33 case 0: // --numfragments
172 schoenebeck 9 num_fragments = atoi(optarg);
173     break;
174 schoenebeck 33 case 1: // --fragmentsize
175 schoenebeck 9 fragmentsize = atoi(optarg);
176     break;
177 schoenebeck 33 case 2: // --volume
178 schoenebeck 20 volume = atof(optarg);
179     break;
180 schoenebeck 33 case 3: // --dls
181 schoenebeck 9 patch_format = patch_format_dls;
182     break;
183 schoenebeck 33 case 4: // --gig
184 schoenebeck 9 patch_format = patch_format_gig;
185     break;
186 schoenebeck 33 case 5: // --instrument
187 schoenebeck 20 instrument_index = atoi(optarg);
188     break;
189 schoenebeck 33 case 6: // --inputclient
190 schoenebeck 20 input_client = optarg;
191     break;
192 schoenebeck 33 case 7: // --alsaout
193     alsaout = optarg;
194     use_jack = false; // If this option is specified do not connect to jack
195     break;
196     case 8: { // --jackout
197     try {
198     String arg(optarg);
199     // remove outer apostrophes
200     arg = arg.substr(arg.find('\'') + 1, arg.rfind('\'') - (arg.find('\'') + 1));
201     // split in two arguments
202     jack_playback[0] = arg.substr(0, arg.find("\' "));
203     jack_playback[1] = arg.substr(arg.find("\' ") + 2, arg.size() - (arg.find("\' ") + 2));
204     // remove inner apostrophes
205     jack_playback[0] = jack_playback[0].substr(0, jack_playback[0].find('\''));
206     jack_playback[1] = jack_playback[1].substr(jack_playback[1].find('\'') + 1, jack_playback[1].size() - jack_playback[1].find('\''));
207     // this is the default but set it up anyway in case alsa_card was also used.
208     use_jack = true;
209     }
210     catch (...) {
211     fprintf(stderr, "Invalid argument '%s' for parameter --jackout\n", optarg);
212     exit(EXIT_FAILURE);
213     }
214     break;
215     }
216     case 9: // --samplerate
217     samplerate = atoi(optarg);
218     break;
219 schoenebeck 35 case 10: // --server
220     run_server = true;
221     break;
222     case 11: // --help
223 schoenebeck 9 printf("usage: linuxsampler [OPTIONS] <INSTRUMENTFILE>\n\n");
224 schoenebeck 20 printf("--gig loads a Gigasampler instrument\n");
225     printf("--dls loads a DLS instrument\n");
226     printf("--instrument index of the instrument in the instrument file if it\n");
227     printf(" contains more than one (default: 0)\n");
228 schoenebeck 9 printf("--numfragments sets the number of audio fragments\n");
229     printf("--fragmentsize sets the fragment size\n");
230 schoenebeck 20 printf("--volume sets global volume gain factor (a value > 1.0 means\n");
231     printf(" amplification, a value < 1.0 means attenuation,\n");
232     printf(" default: 0.25)\n");
233     printf("--inputclient connects to an Alsa sequencer input client on startup\n");
234     printf(" (e.g. 64:0 to connect to a client with ID 64 and port 0)\n");
235 schoenebeck 33 printf("--alsaout connects to the given Alsa sound device on startup\n");
236     printf(" (e.g. 0,0 to connect to hw:0,0 or plughw:0,0)\n");
237     printf("--jackout connects to the given Jack playback ports on startup\n");
238     printf(" (e.g. \"\'alsa_pcm:playback_1\' \'alsa_pcm:playback_2\'\"\n");
239     printf(" in case of stereo output)\n");
240     printf("--samplerate sets sample rate if supported by audio output system\n");
241     printf(" (e.g. 44100)\n");
242 schoenebeck 35 printf("--server launch network server for remote control\n");
243 schoenebeck 33 exit(EXIT_SUCCESS);
244 schoenebeck 9 break;
245     }
246     }
247     }
248 schoenebeck 53 }*/

  ViewVC Help
Powered by ViewVC