1 |
/*************************************************************************** |
2 |
* * |
3 |
* LinuxSampler - modular, streaming capable sampler * |
4 |
* * |
5 |
* Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * |
6 |
* * |
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 |
#include "Sampler.h" |
27 |
#include "drivers/midi/MidiInputDeviceFactory.h" |
28 |
#include "drivers/audio/AudioOutputDeviceFactory.h" |
29 |
#include "network/lscpserver.h" |
30 |
|
31 |
#if 0 |
32 |
#define AUDIO_CHANNELS 2 // stereo |
33 |
#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 |
35 |
#define AUDIO_SAMPLERATE 44100 // Hz |
36 |
#endif |
37 |
|
38 |
using namespace LinuxSampler; |
39 |
|
40 |
/*enum patch_format_t { |
41 |
patch_format_unknown, |
42 |
patch_format_gig, |
43 |
patch_format_dls |
44 |
} 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 |
|
61 |
|
62 |
void parse_options(int argc, char **argv); |
63 |
void signal_handler(int signal); |
64 |
|
65 |
int main(int argc, char **argv) { |
66 |
|
67 |
// setting signal handler for catching SIGINT (thus e.g. <CTRL><C>) |
68 |
signalhandlerthread = pthread_self(); |
69 |
signal(SIGINT, signal_handler); |
70 |
|
71 |
// parse and assign command line options |
72 |
//parse_options(argc, argv); |
73 |
|
74 |
/*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"); |
76 |
printf("Use 'linuxsampler --help' to see all available options.\n"); |
77 |
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 |
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 |
94 |
if (use_jack) { |
95 |
dmsg(1,("Creating audio output device (Jack)...")); |
96 |
try { |
97 |
pSampler->CreateAudioOutputDevice(audio_output_type_jack); |
98 |
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 |
106 |
if (no_jack) { |
107 |
dmsg(1,("Creating audio output device (Alsa)...")); |
108 |
try { |
109 |
pSampler->CreateAudioOutputDevice(audio_output_type_alsa); |
110 |
} |
111 |
catch (AudioOutputException aoe) { |
112 |
aoe.PrintMessage(); |
113 |
dmsg(1,("Trying to create Alsa output device instead.\n")); |
114 |
return EXIT_FAILURE; |
115 |
} |
116 |
} |
117 |
dmsg(1,("OK\n"));*/ |
118 |
|
119 |
// start LSCP network server |
120 |
dmsg(1,("Starting LSCP network server...")); |
121 |
pLSCPServer = new LSCPServer(pSampler); |
122 |
pLSCPServer->StartThread(); |
123 |
dmsg(1,("OK\n")); |
124 |
|
125 |
printf("LinuxSampler initialization completed.\n"); |
126 |
|
127 |
while(true) { |
128 |
/*printf("Voices: %3.3d (Max: %3.3d) Streams: %3.3d (Max: %3.3d, Unused: %3.3d)\r", |
129 |
pEngine->ActiveVoiceCount, pEngine->ActiveVoiceCountMax, |
130 |
pEngine->pDiskThread->ActiveStreamCount, pEngine->pDiskThread->ActiveStreamCountMax, Stream::GetUnusedStreams()); |
131 |
fflush(stdout);*/ |
132 |
usleep(500000); |
133 |
} |
134 |
|
135 |
return EXIT_SUCCESS; |
136 |
} |
137 |
|
138 |
void signal_handler(int signal) { |
139 |
if (pthread_equal(pthread_self(), signalhandlerthread) && signal == SIGINT) { |
140 |
if (pLSCPServer) { |
141 |
pLSCPServer->StopThread(); |
142 |
delete pLSCPServer; |
143 |
} |
144 |
if (pSampler) delete pSampler; |
145 |
printf("LinuxSampler stopped due to SIGINT\n"); |
146 |
exit(EXIT_SUCCESS); |
147 |
} |
148 |
} |
149 |
|
150 |
/*void parse_options(int argc, char **argv) { |
151 |
int res; |
152 |
int option_index = 0; |
153 |
static struct option long_options[] = |
154 |
{ |
155 |
{"numfragments",1,0,0}, |
156 |
{"fragmentsize",1,0,0}, |
157 |
{"volume",1,0,0}, |
158 |
{"dls",0,0,0}, |
159 |
{"gig",0,0,0}, |
160 |
{"instrument",1,0,0}, |
161 |
{"inputclient",1,0,0}, |
162 |
{"alsaout",1,0,0}, |
163 |
{"jackout",1,0,0}, |
164 |
{"samplerate",1,0,0}, |
165 |
{"server",0,0,0}, |
166 |
{"help",0,0,0}, |
167 |
{0,0,0,0} |
168 |
}; |
169 |
|
170 |
while (true) { |
171 |
res = getopt_long_only(argc, argv, "", long_options, &option_index); |
172 |
if(res == -1) break; |
173 |
if (res == 0) { |
174 |
switch(option_index) { |
175 |
case 0: // --numfragments |
176 |
num_fragments = atoi(optarg); |
177 |
break; |
178 |
case 1: // --fragmentsize |
179 |
fragmentsize = atoi(optarg); |
180 |
break; |
181 |
case 2: // --volume |
182 |
volume = atof(optarg); |
183 |
break; |
184 |
case 3: // --dls |
185 |
patch_format = patch_format_dls; |
186 |
break; |
187 |
case 4: // --gig |
188 |
patch_format = patch_format_gig; |
189 |
break; |
190 |
case 5: // --instrument |
191 |
instrument_index = atoi(optarg); |
192 |
break; |
193 |
case 6: // --inputclient |
194 |
input_client = optarg; |
195 |
break; |
196 |
case 7: // --alsaout |
197 |
alsaout = optarg; |
198 |
use_jack = false; // If this option is specified do not connect to jack |
199 |
break; |
200 |
case 8: { // --jackout |
201 |
try { |
202 |
String arg(optarg); |
203 |
// remove outer apostrophes |
204 |
arg = arg.substr(arg.find('\'') + 1, arg.rfind('\'') - (arg.find('\'') + 1)); |
205 |
// split in two arguments |
206 |
jack_playback[0] = arg.substr(0, arg.find("\' ")); |
207 |
jack_playback[1] = arg.substr(arg.find("\' ") + 2, arg.size() - (arg.find("\' ") + 2)); |
208 |
// remove inner apostrophes |
209 |
jack_playback[0] = jack_playback[0].substr(0, jack_playback[0].find('\'')); |
210 |
jack_playback[1] = jack_playback[1].substr(jack_playback[1].find('\'') + 1, jack_playback[1].size() - jack_playback[1].find('\'')); |
211 |
// this is the default but set it up anyway in case alsa_card was also used. |
212 |
use_jack = true; |
213 |
} |
214 |
catch (...) { |
215 |
fprintf(stderr, "Invalid argument '%s' for parameter --jackout\n", optarg); |
216 |
exit(EXIT_FAILURE); |
217 |
} |
218 |
break; |
219 |
} |
220 |
case 9: // --samplerate |
221 |
samplerate = atoi(optarg); |
222 |
break; |
223 |
case 10: // --server |
224 |
run_server = true; |
225 |
break; |
226 |
case 11: // --help |
227 |
printf("usage: linuxsampler [OPTIONS] <INSTRUMENTFILE>\n\n"); |
228 |
printf("--gig loads a Gigasampler instrument\n"); |
229 |
printf("--dls loads a DLS instrument\n"); |
230 |
printf("--instrument index of the instrument in the instrument file if it\n"); |
231 |
printf(" contains more than one (default: 0)\n"); |
232 |
printf("--numfragments sets the number of audio fragments\n"); |
233 |
printf("--fragmentsize sets the fragment size\n"); |
234 |
printf("--volume sets global volume gain factor (a value > 1.0 means\n"); |
235 |
printf(" amplification, a value < 1.0 means attenuation,\n"); |
236 |
printf(" default: 0.25)\n"); |
237 |
printf("--inputclient connects to an Alsa sequencer input client on startup\n"); |
238 |
printf(" (e.g. 64:0 to connect to a client with ID 64 and port 0)\n"); |
239 |
printf("--alsaout connects to the given Alsa sound device on startup\n"); |
240 |
printf(" (e.g. 0,0 to connect to hw:0,0 or plughw:0,0)\n"); |
241 |
printf("--jackout connects to the given Jack playback ports on startup\n"); |
242 |
printf(" (e.g. \"\'alsa_pcm:playback_1\' \'alsa_pcm:playback_2\'\"\n"); |
243 |
printf(" in case of stereo output)\n"); |
244 |
printf("--samplerate sets sample rate if supported by audio output system\n"); |
245 |
printf(" (e.g. 44100)\n"); |
246 |
printf("--server launch network server for remote control\n"); |
247 |
exit(EXIT_SUCCESS); |
248 |
break; |
249 |
} |
250 |
} |
251 |
} |
252 |
}*/ |