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 * |
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 "drivers/midi/MidiInputDeviceFactory.h" |
28 |
#include "audiothread.h" |
#include "drivers/audio/AudioOutputDeviceFactory.h" |
|
#include "alsaio.h" |
|
|
#include "jackio.h" |
|
|
#include "midiin.h" |
|
|
#include "stream.h" |
|
|
#include "RIFF.h" |
|
|
#include "gig.h" |
|
29 |
#include "network/lscpserver.h" |
#include "network/lscpserver.h" |
30 |
|
|
31 |
#define AUDIO_CHANNELS 2 // stereo |
using namespace LinuxSampler; |
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 |
Sampler* pSampler = NULL; |
34 |
#define AUDIO_SAMPLERATE 44100 // Hz |
LSCPServer* pLSCPServer = NULL; |
35 |
|
pthread_t signalhandlerthread; |
|
enum patch_format_t { |
|
|
patch_format_unknown, |
|
|
patch_format_gig, |
|
|
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; |
|
36 |
|
|
37 |
void parse_options(int argc, char **argv); |
void parse_options(int argc, char **argv); |
38 |
void signal_handler(int signal); |
void signal_handler(int signal); |
44 |
signal(SIGINT, signal_handler); |
signal(SIGINT, signal_handler); |
45 |
|
|
46 |
// parse and assign command line options |
// parse and assign command line options |
47 |
parse_options(argc, argv); |
//parse_options(argc, argv); |
|
|
|
|
if (patch_format != patch_format_gig) { |
|
|
printf("Sorry only Gigasampler loading migrated in LinuxSampler so far, use --gig to load a .gig file!\n"); |
|
|
printf("Use 'linuxsampler --help' to see all available options.\n"); |
|
|
return EXIT_FAILURE; |
|
|
} |
|
|
|
|
|
int error = 1; |
|
|
#if HAVE_JACK |
|
|
if (use_jack) { |
|
|
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; |
|
|
} |
|
|
dmsg(1,("OK\n")); |
|
48 |
|
|
49 |
AudioThread* pEngine = new AudioThread(pAudioIO); |
dmsg(1,("LinuxSampler %s\n", VERSION)); |
50 |
MidiIn* pMidiInThread = new MidiIn(pEngine); |
dmsg(1,("Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck\n")); |
51 |
|
|
52 |
// Loading gig file |
// create LinuxSampler instance |
53 |
result_t result = pEngine->LoadInstrument(argv[argc - 1], instrument_index); |
dmsg(1,("Creating Sampler...")); |
54 |
if (result.type == result_type_error) return EXIT_FAILURE; |
pSampler = new Sampler; |
|
pEngine->Volume = volume; |
|
|
|
|
|
dmsg(1,("Starting MIDI in thread...")); |
|
|
if (input_client.size() > 0) pMidiInThread->SubscribeToClient(input_client.c_str()); |
|
|
pMidiInThread->StartThread(); |
|
55 |
dmsg(1,("OK\n")); |
dmsg(1,("OK\n")); |
56 |
|
|
57 |
sleep(1); |
dmsg(1,("Registered MIDI input drivers: %s\n", MidiInputDeviceFactory::AvailableDriversAsString().c_str())); |
58 |
|
dmsg(1,("Registered audio output drivers: %s\n", AudioOutputDeviceFactory::AvailableDriversAsString().c_str())); |
59 |
|
|
60 |
dmsg(1,("Starting audio thread...")); |
// start LSCP network server |
61 |
pAudioIO->AssignEngine(pEngine); |
dmsg(1,("Starting LSCP network server...")); |
62 |
pAudioIO->Activate(); |
pLSCPServer = new LSCPServer(pSampler); |
63 |
|
pLSCPServer->StartThread(); |
64 |
|
pLSCPServer->WaitUntilInitialized(); |
65 |
dmsg(1,("OK\n")); |
dmsg(1,("OK\n")); |
66 |
|
|
|
if (run_server) { |
|
|
dmsg(1,("Starting network server...")); |
|
|
pLSCPServer = new LSCPServer(pEngine); |
|
|
pLSCPServer->StartThread(); |
|
|
dmsg(1,("OK\n")); |
|
|
} |
|
|
|
|
67 |
printf("LinuxSampler initialization completed.\n"); |
printf("LinuxSampler initialization completed.\n"); |
68 |
|
|
69 |
while(true) { |
while(true) { |
70 |
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", |
71 |
pEngine->ActiveVoiceCount, pEngine->ActiveVoiceCountMax, |
pEngine->ActiveVoiceCount, pEngine->ActiveVoiceCountMax, |
72 |
pEngine->pDiskThread->ActiveStreamCount, pEngine->pDiskThread->ActiveStreamCountMax, Stream::GetUnusedStreams()); |
pEngine->pDiskThread->ActiveStreamCount, pEngine->pDiskThread->ActiveStreamCountMax, Stream::GetUnusedStreams()); |
73 |
fflush(stdout); |
fflush(stdout);*/ |
74 |
usleep(500000); |
usleep(500000); |
75 |
} |
} |
76 |
|
|
79 |
|
|
80 |
void signal_handler(int signal) { |
void signal_handler(int signal) { |
81 |
if (pthread_equal(pthread_self(), signalhandlerthread) && signal == SIGINT) { |
if (pthread_equal(pthread_self(), signalhandlerthread) && signal == SIGINT) { |
82 |
// stop all threads |
if (pLSCPServer) { |
83 |
if (pAudioIO) pAudioIO->Close(); |
pLSCPServer->StopThread(); |
84 |
if (pMidiInThread) pMidiInThread->StopThread(); |
delete pLSCPServer; |
85 |
|
} |
86 |
// free all resources |
if (pSampler) delete pSampler; |
|
if (pMidiInThread) delete pMidiInThread; |
|
|
if (pEngine) delete pEngine; |
|
|
if (pAudioIO) delete pAudioIO; |
|
|
|
|
87 |
printf("LinuxSampler stopped due to SIGINT\n"); |
printf("LinuxSampler stopped due to SIGINT\n"); |
88 |
exit(EXIT_SUCCESS); |
exit(EXIT_SUCCESS); |
89 |
} |
} |
90 |
} |
} |
91 |
|
|
92 |
void parse_options(int argc, char **argv) { |
/*void parse_options(int argc, char **argv) { |
93 |
int res; |
int res; |
94 |
int option_index = 0; |
int option_index = 0; |
95 |
static struct option long_options[] = |
static struct option long_options[] = |
191 |
} |
} |
192 |
} |
} |
193 |
} |
} |
194 |
} |
}*/ |