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 |
|
* Copyright (C) 2005-2008 Christian Schoenebeck * |
7 |
* * |
* * |
8 |
* This program is free software; you can redistribute it and/or modify * |
* This program is free software; you can redistribute it and/or modify * |
9 |
* 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 * |
21 |
* MA 02111-1307 USA * |
* MA 02111-1307 USA * |
22 |
***************************************************************************/ |
***************************************************************************/ |
23 |
|
|
|
#include <stdio.h> |
|
|
#include <stdlib.h> |
|
|
#include <unistd.h> |
|
24 |
#include <getopt.h> |
#include <getopt.h> |
25 |
#include <signal.h> |
#include <signal.h> |
|
#include <pthread.h> |
|
26 |
|
|
27 |
#include "global.h" |
#if defined(WIN32) |
28 |
#include "diskthread.h" |
// require at least Windows 2000 for the GlobalMemoryStatusEx() call |
29 |
#include "audiothread.h" |
#define _WIN32_WINNT 0x0500 |
30 |
#include "alsaio.h" |
#endif |
31 |
#include "jackio.h" |
|
32 |
#include "midiin.h" |
#include "Sampler.h" |
33 |
#include "stream.h" |
#include "common/global_private.h" |
34 |
#include "RIFF.h" |
#include "engines/EngineFactory.h" |
35 |
#include "gig.h" |
#include "plugins/InstrumentEditorFactory.h" |
36 |
|
#include "drivers/midi/MidiInputDeviceFactory.h" |
37 |
|
#include "drivers/audio/AudioOutputDeviceFactory.h" |
38 |
|
#include "engines/gig/Profiler.h" |
39 |
#include "network/lscpserver.h" |
#include "network/lscpserver.h" |
40 |
|
#include "common/stacktrace.h" |
41 |
|
#include "common/Features.h" |
42 |
|
#include "common/atomic.h" |
43 |
|
|
44 |
|
using namespace LinuxSampler; |
45 |
|
|
46 |
|
Sampler* pSampler = NULL; |
47 |
|
LSCPServer* pLSCPServer = NULL; |
48 |
|
#if defined(WIN32) |
49 |
|
// inet_aton seems missing under WIN32 |
50 |
|
#ifndef INADDR_NONE |
51 |
|
#define INADDR_NONE 0xffffffff |
52 |
|
#endif |
53 |
|
|
54 |
|
int inet_aton(const char *cp, struct in_addr *addr) |
55 |
|
{ |
56 |
|
addr->s_addr = inet_addr(cp); |
57 |
|
return (addr->s_addr == INADDR_NONE) ? 0 : 1; |
58 |
|
} |
59 |
|
|
60 |
#define AUDIO_CHANNELS 2 // stereo |
#else |
61 |
#define AUDIO_FRAGMENTS 3 // 3 fragments, if it does not work set it to 2 |
pid_t main_pid; |
62 |
#define AUDIO_FRAGMENTSIZE 512 // each fragment has 512 frames |
#endif |
63 |
#define AUDIO_SAMPLERATE 44100 // Hz |
bool bPrintStatistics = false; |
64 |
|
bool profile = false; |
65 |
enum patch_format_t { |
bool tune = true; |
66 |
patch_format_unknown, |
unsigned long int lscp_addr; |
67 |
patch_format_gig, |
unsigned short int lscp_port; |
|
patch_format_dls |
|
|
} patch_format = patch_format_unknown; |
|
|
|
|
|
AudioIO* pAudioIO = NULL; |
|
|
MidiIn* pMidiInThread = NULL; |
|
|
LSCPServer* pLSCPServer = NULL; |
|
|
AudioThread* pEngine = NULL; |
|
|
uint instrument_index = 0; |
|
|
double volume = 0.25; |
|
|
int num_fragments = AUDIO_FRAGMENTS; |
|
|
int fragmentsize = AUDIO_FRAGMENTSIZE; |
|
|
uint samplerate = AUDIO_SAMPLERATE; |
|
|
String input_client; |
|
|
String alsaout = "0,0"; // default card |
|
|
String jack_playback[2] = { "", "" }; |
|
|
bool use_jack = true; |
|
|
bool run_server = false; |
|
|
pthread_t signalhandlerthread; |
|
68 |
|
|
69 |
void parse_options(int argc, char **argv); |
void parse_options(int argc, char **argv); |
70 |
void signal_handler(int signal); |
void signal_handler(int signal); |
71 |
|
void kill_app(); |
72 |
|
static atomic_t running = ATOMIC_INIT(1); |
73 |
|
|
74 |
int main(int argc, char **argv) { |
int main(int argc, char **argv) { |
75 |
|
|
76 |
|
// initialize the stack trace mechanism with our binary file |
77 |
|
StackTraceInit(argv[0], -1); |
78 |
|
|
79 |
|
#if defined(WIN32) |
80 |
|
// some WIN32 memory info code which tries to determine the maximum lockable amount of memory (for debug purposes) |
81 |
|
SYSTEM_INFO siSysInfo; |
82 |
|
long physical_memory; |
83 |
|
GetSystemInfo(&siSysInfo); |
84 |
|
dmsg(1,("page size=%d\n", siSysInfo.dwPageSize)); |
85 |
|
|
86 |
|
MEMORYSTATUSEX statex; |
87 |
|
statex.dwLength = sizeof (statex); |
88 |
|
GlobalMemoryStatusEx (&statex); |
89 |
|
dmsg(1, ("There are %*I64d total Kbytes of physical memory.\n", |
90 |
|
8, statex.ullTotalPhys)); |
91 |
|
dmsg(1, ("There are %*I64d free Kbytes of physical memory.\n", |
92 |
|
8, statex.ullAvailPhys)); |
93 |
|
physical_memory = statex.ullTotalPhys; |
94 |
|
|
95 |
|
HANDLE hProcess = GetCurrentProcess(); |
96 |
|
|
97 |
|
unsigned long MinimumWorkingSetSize, MaximumWorkingSetSize; |
98 |
|
unsigned long DefaultMinimumWorkingSetSize, DefaultMaximumWorkingSetSize; |
99 |
|
unsigned long RequestedMinimumWorkingSetSize, RequestedMaximumWorkingSetSize; |
100 |
|
int res; |
101 |
|
|
102 |
|
res = GetProcessWorkingSetSize(hProcess, &DefaultMinimumWorkingSetSize, &DefaultMaximumWorkingSetSize); |
103 |
|
|
104 |
|
RequestedMaximumWorkingSetSize = physical_memory - 2*1024*1024; |
105 |
|
RequestedMinimumWorkingSetSize = RequestedMaximumWorkingSetSize; |
106 |
|
|
107 |
|
for(;;) { |
108 |
|
dmsg(2,("TRYING VALUES RequestedMinimumWorkingSetSize=%d, RequestedMaximumWorkingSetSize=%d\n", RequestedMinimumWorkingSetSize, RequestedMaximumWorkingSetSize)); |
109 |
|
res = SetProcessWorkingSetSize(hProcess, RequestedMinimumWorkingSetSize, RequestedMaximumWorkingSetSize); |
110 |
|
dmsg(2,("AFTER SET: res = %d RequestedMinimumWorkingSetSize=%d, RequestedMaximumWorkingSetSize=%d\n", res,RequestedMinimumWorkingSetSize, RequestedMaximumWorkingSetSize)); |
111 |
|
|
112 |
|
res = GetProcessWorkingSetSize(hProcess, &MinimumWorkingSetSize, &MaximumWorkingSetSize); |
113 |
|
dmsg(2,("AFTER GET: res = %d MinimumWorkingSetSize=%d, MaximumWorkingSetSize=%d\n", res,MinimumWorkingSetSize, MaximumWorkingSetSize)); |
114 |
|
|
115 |
|
if( RequestedMinimumWorkingSetSize == MinimumWorkingSetSize ) { |
116 |
|
dmsg(2,("RequestedMinimumWorkingSetSize == MinimumWorkingSetSize. OK !\n")); |
117 |
|
break; |
118 |
|
} |
119 |
|
|
120 |
|
RequestedMinimumWorkingSetSize -= 10*1024*1024; |
121 |
|
if(RequestedMinimumWorkingSetSize < DefaultMinimumWorkingSetSize) break; |
122 |
|
} |
123 |
|
|
124 |
|
dmsg(1,("AFTER GetProcessWorkingSetSize: res = %d MinimumWorkingSetSize=%d, MaximumWorkingSetSize=%d\n", res,MinimumWorkingSetSize, MaximumWorkingSetSize)); |
125 |
|
#endif |
126 |
|
|
127 |
|
#if !defined(WIN32) |
128 |
|
main_pid = getpid(); |
129 |
|
#endif |
130 |
|
|
131 |
// setting signal handler for catching SIGINT (thus e.g. <CTRL><C>) |
// setting signal handler for catching SIGINT (thus e.g. <CTRL><C>) |
|
signalhandlerthread = pthread_self(); |
|
132 |
signal(SIGINT, signal_handler); |
signal(SIGINT, signal_handler); |
133 |
|
|
134 |
|
#if defined(WIN32) |
135 |
|
// FIXME: sigaction() not supported on WIN32, we ignore it for now |
136 |
|
#else |
137 |
|
// register signal handler for all unusual signals |
138 |
|
// (we will print the stack trace and exit) |
139 |
|
struct sigaction sact; |
140 |
|
sigemptyset(&sact.sa_mask); |
141 |
|
sact.sa_flags = 0; |
142 |
|
sact.sa_handler = signal_handler; |
143 |
|
sigaction(SIGSEGV, &sact, NULL); |
144 |
|
sigaction(SIGBUS, &sact, NULL); |
145 |
|
sigaction(SIGILL, &sact, NULL); |
146 |
|
sigaction(SIGFPE, &sact, NULL); |
147 |
|
sigaction(SIGUSR1, &sact, NULL); |
148 |
|
sigaction(SIGUSR2, &sact, NULL); |
149 |
|
#endif |
150 |
|
|
151 |
|
lscp_addr = htonl(LSCP_ADDR); |
152 |
|
lscp_port = htons(LSCP_PORT); |
153 |
|
|
154 |
// parse and assign command line options |
// parse and assign command line options |
155 |
parse_options(argc, argv); |
parse_options(argc, argv); |
156 |
|
|
157 |
if (patch_format != patch_format_gig) { |
dmsg(1,("LinuxSampler %s\n", VERSION)); |
158 |
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")); |
159 |
printf("Use 'linuxsampler --help' to see all available options.\n"); |
dmsg(1,("Copyright (C) 2005-2008 Christian Schoenebeck\n")); |
160 |
return EXIT_FAILURE; |
|
161 |
|
if (tune) { |
162 |
|
// detect and print system / CPU specific features |
163 |
|
Features::detect(); |
164 |
|
dmsg(1,("Detected features: %s\n", Features::featuresAsString().c_str())); |
165 |
|
// prevent slow denormal FPU modes |
166 |
|
Features::enableDenormalsAreZeroMode(); |
167 |
} |
} |
168 |
|
|
169 |
int error = 1; |
// create LinuxSampler instance |
170 |
#if HAVE_JACK |
dmsg(1,("Creating Sampler...")); |
171 |
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; |
|
|
} |
|
172 |
dmsg(1,("OK\n")); |
dmsg(1,("OK\n")); |
173 |
|
|
174 |
AudioThread* pEngine = new AudioThread(pAudioIO); |
dmsg(1,("Registered sampler engines: %s\n", EngineFactory::AvailableEngineTypesAsString().c_str())); |
175 |
MidiIn* pMidiInThread = new MidiIn(pEngine); |
dmsg(1,("Registered MIDI input drivers: %s\n", MidiInputDeviceFactory::AvailableDriversAsString().c_str())); |
176 |
|
dmsg(1,("Registered audio output drivers: %s\n", AudioOutputDeviceFactory::AvailableDriversAsString().c_str())); |
177 |
// Loading gig file |
dmsg(1,("Registered instrument editors: %s\n", InstrumentEditorFactory::AvailableEditorsAsString().c_str())); |
178 |
result_t result = pEngine->LoadInstrument(argv[argc - 1], instrument_index); |
|
179 |
if (result.type == result_type_error) return EXIT_FAILURE; |
// start LSCP network server |
180 |
pEngine->Volume = volume; |
struct in_addr addr; |
181 |
|
addr.s_addr = lscp_addr; |
182 |
dmsg(1,("Starting MIDI in thread...")); |
dmsg(1,("Starting LSCP network server (%s:%d)...", inet_ntoa(addr), ntohs(lscp_port))); |
183 |
if (input_client.size() > 0) pMidiInThread->SubscribeToClient(input_client.c_str()); |
pLSCPServer = new LSCPServer(pSampler, lscp_addr, lscp_port); |
184 |
pMidiInThread->StartThread(); |
pLSCPServer->StartThread(); |
185 |
|
pLSCPServer->WaitUntilInitialized(); |
186 |
dmsg(1,("OK\n")); |
dmsg(1,("OK\n")); |
187 |
|
|
188 |
sleep(1); |
if (profile) |
189 |
|
{ |
190 |
dmsg(1,("Starting audio thread...")); |
dmsg(1,("Calibrating profiler...")); |
191 |
pAudioIO->AssignEngine(pEngine); |
LinuxSampler::gig::Profiler::Calibrate(); |
192 |
pAudioIO->Activate(); |
LinuxSampler::gig::Profiler::Reset(); |
193 |
dmsg(1,("OK\n")); |
LinuxSampler::gig::Profiler::enable(); |
|
|
|
|
if (run_server) { |
|
|
dmsg(1,("Starting network server...")); |
|
|
pLSCPServer = new LSCPServer(pEngine); |
|
|
pLSCPServer->StartThread(); |
|
194 |
dmsg(1,("OK\n")); |
dmsg(1,("OK\n")); |
195 |
} |
} |
196 |
|
|
197 |
printf("LinuxSampler initialization completed.\n"); |
printf("LinuxSampler initialization completed. :-)\n\n"); |
198 |
|
|
199 |
while(true) { |
while (atomic_read(&running)) { |
200 |
printf("Voices: %3.3d (Max: %3.3d) Streams: %3.3d (Max: %3.3d, Unused: %3.3d)\r", |
if (bPrintStatistics) { |
201 |
pEngine->ActiveVoiceCount, pEngine->ActiveVoiceCountMax, |
const std::set<Engine*>& engines = EngineFactory::EngineInstances(); |
202 |
pEngine->pDiskThread->ActiveStreamCount, pEngine->pDiskThread->ActiveStreamCountMax, Stream::GetUnusedStreams()); |
std::set<Engine*>::iterator itEngine = engines.begin(); |
203 |
fflush(stdout); |
for (int i = 0; itEngine != engines.end(); itEngine++, i++) { |
204 |
usleep(500000); |
Engine* pEngine = *itEngine; |
205 |
} |
printf("Engine %d) Voices: %3.3d (Max: %3.3d) Streams: %3.3d (Max: %3.3d)\n", i, |
206 |
|
pEngine->VoiceCount(), pEngine->VoiceCountMax(), |
207 |
|
pEngine->DiskStreamCount(), pEngine->DiskStreamCountMax() |
208 |
|
); |
209 |
|
fflush(stdout); |
210 |
|
} |
211 |
|
} |
212 |
|
|
213 |
|
sleep(1); |
214 |
|
if (profile) |
215 |
|
{ |
216 |
|
unsigned int samplingFreq = 48000; //FIXME: hardcoded for now |
217 |
|
unsigned int bv = LinuxSampler::gig::Profiler::GetBogoVoices(samplingFreq); |
218 |
|
if (bv != 0) |
219 |
|
{ |
220 |
|
printf(" BogoVoices: %i \r", bv); |
221 |
|
fflush(stdout); |
222 |
|
} |
223 |
|
} |
224 |
|
|
225 |
|
pSampler->fireStatistics(); |
226 |
|
} |
227 |
|
if (pLSCPServer) pLSCPServer->StopThread(); |
228 |
|
// the delete order here is important: the Sampler |
229 |
|
// destructor sends notifications to the lscpserver |
230 |
|
if (pSampler) delete pSampler; |
231 |
|
if (pLSCPServer) delete pLSCPServer; |
232 |
|
printf("LinuxSampler stopped due to SIGINT.\n"); |
233 |
return EXIT_SUCCESS; |
return EXIT_SUCCESS; |
234 |
} |
} |
235 |
|
|
236 |
void signal_handler(int signal) { |
void signal_handler(int iSignal) { |
237 |
if (pthread_equal(pthread_self(), signalhandlerthread) && signal == SIGINT) { |
switch (iSignal) { |
238 |
// stop all threads |
case SIGINT: |
239 |
if (pAudioIO) pAudioIO->Close(); |
atomic_set(&running, 0); |
240 |
if (pMidiInThread) pMidiInThread->StopThread(); |
return; |
241 |
|
#if defined(WIN32) |
242 |
// free all resources |
// FIXME: under WIN32 we ignore the signals below due to the missing sigaction call |
243 |
if (pMidiInThread) delete pMidiInThread; |
#else |
244 |
if (pEngine) delete pEngine; |
case SIGSEGV: |
245 |
if (pAudioIO) delete pAudioIO; |
std::cerr << ">>> FATAL ERROR: Segmentation fault (SIGSEGV) occured! <<<\n" << std::flush; |
246 |
|
break; |
247 |
printf("LinuxSampler stopped due to SIGINT\n"); |
case SIGBUS: |
248 |
exit(EXIT_SUCCESS); |
std::cerr << ">>> FATAL ERROR: Access to undefined portion of a memory object (SIGBUS) occured! <<<\n" << std::flush; |
249 |
|
break; |
250 |
|
case SIGILL: |
251 |
|
std::cerr << ">>> FATAL ERROR: Illegal instruction (SIGILL) occured! <<<\n" << std::flush; |
252 |
|
break; |
253 |
|
case SIGFPE: |
254 |
|
std::cerr << ">>> FATAL ERROR: Erroneous arithmetic operation (SIGFPE) occured! <<<\n" << std::flush; |
255 |
|
break; |
256 |
|
case SIGUSR1: |
257 |
|
std::cerr << ">>> User defined signal 1 (SIGUSR1) received <<<\n" << std::flush; |
258 |
|
break; |
259 |
|
case SIGUSR2: |
260 |
|
std::cerr << ">>> User defined signal 2 (SIGUSR2) received <<<\n" << std::flush; |
261 |
|
break; |
262 |
|
#endif |
263 |
|
default: { // this should never happen, as we register for the signals we want |
264 |
|
std::cerr << ">>> FATAL ERROR: Unknown signal received! <<<\n" << std::flush; |
265 |
|
break; |
266 |
|
} |
267 |
} |
} |
268 |
|
signal(iSignal, SIG_DFL); // Reinstall default handler to prevent race conditions |
269 |
|
std::cerr << "Showing stack trace...\n" << std::flush; |
270 |
|
StackTrace(); |
271 |
|
sleep(2); |
272 |
|
std::cerr << "Killing LinuxSampler...\n" << std::flush; |
273 |
|
kill_app(); // Use abort() if we want to generate a core dump. |
274 |
|
} |
275 |
|
|
276 |
|
void kill_app() { |
277 |
|
#if defined(WIN32) |
278 |
|
// FIXME: do we need to do anything at this point under WIN32 ? is exit(0) ok ? |
279 |
|
exit(0); |
280 |
|
#else |
281 |
|
kill(main_pid, SIGKILL); |
282 |
|
#endif |
283 |
} |
} |
284 |
|
|
285 |
void parse_options(int argc, char **argv) { |
void parse_options(int argc, char **argv) { |
287 |
int option_index = 0; |
int option_index = 0; |
288 |
static struct option long_options[] = |
static struct option long_options[] = |
289 |
{ |
{ |
|
{"numfragments",1,0,0}, |
|
|
{"fragmentsize",1,0,0}, |
|
|
{"volume",1,0,0}, |
|
|
{"dls",0,0,0}, |
|
|
{"gig",0,0,0}, |
|
|
{"instrument",1,0,0}, |
|
|
{"inputclient",1,0,0}, |
|
|
{"alsaout",1,0,0}, |
|
|
{"jackout",1,0,0}, |
|
|
{"samplerate",1,0,0}, |
|
|
{"server",0,0,0}, |
|
290 |
{"help",0,0,0}, |
{"help",0,0,0}, |
291 |
|
{"version",0,0,0}, |
292 |
|
{"profile",0,0,0}, |
293 |
|
{"no-tune",0,0,0}, |
294 |
|
{"statistics",0,0,0}, |
295 |
|
{"instruments-db-location",1,0,0}, |
296 |
|
{"create-instruments-db",1,0,0}, |
297 |
|
{"lscp-addr",1,0,0}, |
298 |
|
{"lscp-port",1,0,0}, |
299 |
{0,0,0,0} |
{0,0,0,0} |
300 |
}; |
}; |
301 |
|
|
302 |
while (true) { |
while (true) { |
303 |
res = getopt_long_only(argc, argv, "", long_options, &option_index); |
/* |
304 |
|
Stephane Letz : letz@grame.fr |
305 |
|
getopt_long_only does not exist on OSX : replaced by getopt_long for now. |
306 |
|
*/ |
307 |
|
res = getopt_long(argc, argv, "", long_options, &option_index); |
308 |
if(res == -1) break; |
if(res == -1) break; |
309 |
if (res == 0) { |
if (res == 0) { |
310 |
switch(option_index) { |
switch(option_index) { |
311 |
case 0: // --numfragments |
case 0: // --help |
312 |
num_fragments = atoi(optarg); |
printf("usage: linuxsampler [OPTIONS]\n\n"); |
313 |
break; |
printf("--help prints this message\n"); |
314 |
case 1: // --fragmentsize |
printf("--version prints version information\n"); |
315 |
fragmentsize = atoi(optarg); |
printf("--profile profile synthesis algorithms\n"); |
316 |
break; |
printf("--no-tune disable assembly optimization\n"); |
317 |
case 2: // --volume |
printf("--statistics periodically prints statistics\n"); |
318 |
volume = atof(optarg); |
printf("--lscp-addr set LSCP address (default: any)\n"); |
319 |
break; |
printf("--lscp-port set LSCP port (default: 8888)\n"); |
320 |
case 3: // --dls |
printf("--create-instruments-db creates an instruments DB\n"); |
321 |
patch_format = patch_format_dls; |
printf("--instruments-db-location specifies the instruments DB file\n"); |
322 |
|
exit(EXIT_SUCCESS); |
323 |
break; |
break; |
324 |
case 4: // --gig |
case 1: // --version |
325 |
patch_format = patch_format_gig; |
printf("LinuxSampler %s\n", VERSION); |
326 |
|
exit(EXIT_SUCCESS); |
327 |
break; |
break; |
328 |
case 5: // --instrument |
case 2: // --profile |
329 |
instrument_index = atoi(optarg); |
profile = true; |
330 |
break; |
break; |
331 |
case 6: // --inputclient |
case 3: // --no-tune |
332 |
input_client = optarg; |
tune = false; |
333 |
break; |
break; |
334 |
case 7: // --alsaout |
case 4: // --statistics |
335 |
alsaout = optarg; |
bPrintStatistics = true; |
|
use_jack = false; // If this option is specified do not connect to jack |
|
336 |
break; |
break; |
337 |
case 8: { // --jackout |
case 5: // --instruments-db-location |
338 |
|
#if HAVE_SQLITE3 |
339 |
try { |
try { |
340 |
String arg(optarg); |
if (optarg) { |
341 |
// remove outer apostrophes |
struct stat statBuf; |
342 |
arg = arg.substr(arg.find('\'') + 1, arg.rfind('\'') - (arg.find('\'') + 1)); |
int res = stat(optarg, &statBuf); |
343 |
// split in two arguments |
|
344 |
jack_playback[0] = arg.substr(0, arg.find("\' ")); |
if (res) { |
345 |
jack_playback[1] = arg.substr(arg.find("\' ") + 2, arg.size() - (arg.find("\' ") + 2)); |
std::stringstream ss; |
346 |
// remove inner apostrophes |
ss << "Failed to stat `" << optarg << "`: " << strerror(errno); |
347 |
jack_playback[0] = jack_playback[0].substr(0, jack_playback[0].find('\'')); |
throw Exception(ss.str()); |
348 |
jack_playback[1] = jack_playback[1].substr(jack_playback[1].find('\'') + 1, jack_playback[1].size() - jack_playback[1].find('\'')); |
} |
349 |
// this is the default but set it up anyway in case alsa_card was also used. |
|
350 |
use_jack = true; |
if (!S_ISREG(statBuf.st_mode)) { |
351 |
} |
std::stringstream ss; |
352 |
catch (...) { |
ss << "`" << optarg << "` is not a regular file"; |
353 |
fprintf(stderr, "Invalid argument '%s' for parameter --jackout\n", optarg); |
throw Exception(ss.str()); |
354 |
|
} |
355 |
|
|
356 |
|
InstrumentsDb::GetInstrumentsDb()->SetDbFile(String(optarg)); |
357 |
|
} |
358 |
|
} catch(Exception e) { |
359 |
|
std::cerr << "Could not open instruments DB file: " |
360 |
|
<< e.Message() << std::endl; |
361 |
exit(EXIT_FAILURE); |
exit(EXIT_FAILURE); |
362 |
} |
} |
363 |
break; |
break; |
364 |
} |
#else |
365 |
case 9: // --samplerate |
std::cerr << "LinuxSampler was not build with "; |
366 |
samplerate = atoi(optarg); |
std::cerr << "instruments database support!\n"; |
367 |
break; |
exit(EXIT_FAILURE); |
368 |
case 10: // --server |
break; |
369 |
run_server = true; |
#endif |
370 |
break; |
case 6: // --create-instruments-db |
371 |
case 11: // --help |
#if HAVE_SQLITE3 |
372 |
printf("usage: linuxsampler [OPTIONS] <INSTRUMENTFILE>\n\n"); |
try { |
373 |
printf("--gig loads a Gigasampler instrument\n"); |
if (optarg) { |
374 |
printf("--dls loads a DLS instrument\n"); |
std::cout << "Creating instruments database..." << std::endl; |
375 |
printf("--instrument index of the instrument in the instrument file if it\n"); |
InstrumentsDb::CreateInstrumentsDb(String(optarg)); |
376 |
printf(" contains more than one (default: 0)\n"); |
std::cout << "Done" << std::endl; |
377 |
printf("--numfragments sets the number of audio fragments\n"); |
} |
378 |
printf("--fragmentsize sets the fragment size\n"); |
} catch(Exception e) { |
379 |
printf("--volume sets global volume gain factor (a value > 1.0 means\n"); |
std::cerr << e.Message() << std::endl; |
380 |
printf(" amplification, a value < 1.0 means attenuation,\n"); |
exit(EXIT_FAILURE); |
381 |
printf(" default: 0.25)\n"); |
return; |
382 |
printf("--inputclient connects to an Alsa sequencer input client on startup\n"); |
} |
383 |
printf(" (e.g. 64:0 to connect to a client with ID 64 and port 0)\n"); |
|
|
printf("--alsaout connects to the given Alsa sound device on startup\n"); |
|
|
printf(" (e.g. 0,0 to connect to hw:0,0 or plughw:0,0)\n"); |
|
|
printf("--jackout connects to the given Jack playback ports on startup\n"); |
|
|
printf(" (e.g. \"\'alsa_pcm:playback_1\' \'alsa_pcm:playback_2\'\"\n"); |
|
|
printf(" in case of stereo output)\n"); |
|
|
printf("--samplerate sets sample rate if supported by audio output system\n"); |
|
|
printf(" (e.g. 44100)\n"); |
|
|
printf("--server launch network server for remote control\n"); |
|
384 |
exit(EXIT_SUCCESS); |
exit(EXIT_SUCCESS); |
385 |
|
return; |
386 |
|
#else |
387 |
|
std::cerr << "Failed to create the database. LinuxSampler was "; |
388 |
|
std::cerr << "not build with instruments database support!\n"; |
389 |
|
exit(EXIT_FAILURE); |
390 |
|
return; |
391 |
|
#endif |
392 |
|
case 7: // --lscp-addr |
393 |
|
struct in_addr addr; |
394 |
|
if (inet_aton(optarg, &addr) == 0) |
395 |
|
printf("WARNING: Failed to parse lscp-addr argument, ignoring!\n"); |
396 |
|
else |
397 |
|
lscp_addr = addr.s_addr; |
398 |
|
break; |
399 |
|
case 8: // --lscp-port |
400 |
|
long unsigned int port = 0; |
401 |
|
if ((sscanf(optarg, "%u", &port) != 1) || (port == 0) || (port > 65535)) |
402 |
|
printf("WARNING: Failed to parse lscp-port argument, ignoring!\n"); |
403 |
|
else |
404 |
|
lscp_port = htons(port); |
405 |
break; |
break; |
406 |
} |
} |
407 |
} |
} |