2 |
* * |
* * |
3 |
* LinuxSampler - modular, streaming capable sampler * |
* LinuxSampler - modular, streaming capable sampler * |
4 |
* * |
* * |
5 |
* Copyright (C) 2003-2004 by Benno Senoner and Christian Schoenebeck * |
* Copyright (C) 2003-2004 by Benno Senoner and Christian Schoenebeck * |
6 |
* Copyright (C) 2005-2007 Christian Schoenebeck * |
* 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 * |
39 |
#include "network/lscpserver.h" |
#include "network/lscpserver.h" |
40 |
#include "common/stacktrace.h" |
#include "common/stacktrace.h" |
41 |
#include "common/Features.h" |
#include "common/Features.h" |
42 |
|
#include "common/atomic.h" |
43 |
|
|
44 |
using namespace LinuxSampler; |
using namespace LinuxSampler; |
45 |
|
|
57 |
return (addr->s_addr == INADDR_NONE) ? 0 : 1; |
return (addr->s_addr == INADDR_NONE) ? 0 : 1; |
58 |
} |
} |
59 |
|
|
|
DWORD main_thread; |
|
60 |
#else |
#else |
|
pthread_t main_thread; |
|
61 |
pid_t main_pid; |
pid_t main_pid; |
62 |
#endif |
#endif |
63 |
bool bPrintStatistics = false; |
bool bPrintStatistics = false; |
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(); |
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 |
|
|
124 |
dmsg(1,("AFTER GetProcessWorkingSetSize: res = %d MinimumWorkingSetSize=%d, MaximumWorkingSetSize=%d\n", res,MinimumWorkingSetSize, MaximumWorkingSetSize)); |
dmsg(1,("AFTER GetProcessWorkingSetSize: res = %d MinimumWorkingSetSize=%d, MaximumWorkingSetSize=%d\n", res,MinimumWorkingSetSize, MaximumWorkingSetSize)); |
125 |
#endif |
#endif |
126 |
|
|
127 |
#if defined(WIN32) |
#if !defined(WIN32) |
|
main_thread = GetCurrentThreadId(); |
|
|
#else |
|
128 |
main_pid = getpid(); |
main_pid = getpid(); |
|
main_thread = pthread_self(); |
|
129 |
#endif |
#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>) |
156 |
|
|
157 |
dmsg(1,("LinuxSampler %s\n", VERSION)); |
dmsg(1,("LinuxSampler %s\n", VERSION)); |
158 |
dmsg(1,("Copyright (C) 2003,2004 by Benno Senoner and Christian Schoenebeck\n")); |
dmsg(1,("Copyright (C) 2003,2004 by Benno Senoner and Christian Schoenebeck\n")); |
159 |
dmsg(1,("Copyright (C) 2005-2007 Christian Schoenebeck\n")); |
dmsg(1,("Copyright (C) 2005-2008 Christian Schoenebeck\n")); |
160 |
|
|
161 |
if (tune) { |
if (tune) { |
162 |
// detect and print system / CPU specific features |
// detect and print system / CPU specific features |
196 |
|
|
197 |
printf("LinuxSampler initialization completed. :-)\n\n"); |
printf("LinuxSampler initialization completed. :-)\n\n"); |
198 |
|
|
199 |
std::list<LSCPEvent::event_t> rtEvents; |
while (atomic_read(&running)) { |
|
rtEvents.push_back(LSCPEvent::event_voice_count); |
|
|
rtEvents.push_back(LSCPEvent::event_stream_count); |
|
|
rtEvents.push_back(LSCPEvent::event_buffer_fill); |
|
|
rtEvents.push_back(LSCPEvent::event_total_voice_count); |
|
|
|
|
|
while (true) { |
|
200 |
if (bPrintStatistics) { |
if (bPrintStatistics) { |
201 |
const std::set<Engine*>& engines = EngineFactory::EngineInstances(); |
const std::set<Engine*>& engines = EngineFactory::EngineInstances(); |
202 |
std::set<Engine*>::iterator itEngine = engines.begin(); |
std::set<Engine*>::iterator itEngine = engines.begin(); |
210 |
} |
} |
211 |
} |
} |
212 |
|
|
213 |
sleep(1); |
sleep(1); |
214 |
if (profile) |
if (profile) |
215 |
{ |
{ |
216 |
unsigned int samplingFreq = 48000; //FIXME: hardcoded for now |
unsigned int samplingFreq = 48000; //FIXME: hardcoded for now |
217 |
unsigned int bv = LinuxSampler::gig::Profiler::GetBogoVoices(samplingFreq); |
unsigned int bv = LinuxSampler::gig::Profiler::GetBogoVoices(samplingFreq); |
218 |
if (bv != 0) |
if (bv != 0) |
219 |
{ |
{ |
220 |
printf(" BogoVoices: %i \r", bv); |
printf(" BogoVoices: %i \r", bv); |
221 |
fflush(stdout); |
fflush(stdout); |
222 |
} |
} |
223 |
} |
} |
|
|
|
|
if (LSCPServer::EventSubscribers(rtEvents)) |
|
|
{ |
|
|
LSCPServer::LockRTNotify(); |
|
|
std::map<uint,SamplerChannel*> channels = pSampler->GetSamplerChannels(); |
|
|
std::map<uint,SamplerChannel*>::iterator iter = channels.begin(); |
|
|
for (; iter != channels.end(); iter++) { |
|
|
SamplerChannel* pSamplerChannel = iter->second; |
|
|
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
|
|
if (!pEngineChannel) continue; |
|
|
Engine* pEngine = pEngineChannel->GetEngine(); |
|
|
if (!pEngine) continue; |
|
|
pSampler->fireVoiceCountChanged(iter->first, pEngineChannel->GetVoiceCount()); |
|
|
pSampler->fireStreamCountChanged(iter->first, pEngineChannel->GetDiskStreamCount()); |
|
|
pSampler->fireBufferFillChanged(iter->first, pEngine->DiskStreamBufferFillPercentage()); |
|
|
pSampler->fireTotalVoiceCountChanged(pSampler->GetVoiceCount()); |
|
|
} |
|
|
LSCPServer::UnlockRTNotify(); |
|
|
} |
|
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 iSignal) { |
void signal_handler(int iSignal) { |
237 |
switch (iSignal) { |
switch (iSignal) { |
238 |
case SIGINT: { |
case SIGINT: |
239 |
#if defined(WIN32) |
atomic_set(&running, 0); |
|
if( GetCurrentThreadId() == main_thread ) { |
|
|
#else |
|
|
if (pthread_equal(pthread_self(), main_thread)) { |
|
|
#endif |
|
|
if (pLSCPServer) pLSCPServer->StopThread(); |
|
|
// the delete order here is important: the Sampler |
|
|
// destructor sends notifications to the lscpserver |
|
|
if (pSampler) delete pSampler; |
|
|
if (pLSCPServer) delete pLSCPServer; |
|
|
#if HAVE_SQLITE3 |
|
|
InstrumentsDb::Destroy(); |
|
|
#endif |
|
|
printf("LinuxSampler stopped due to SIGINT.\n"); |
|
|
exit(EXIT_SUCCESS); |
|
|
} |
|
240 |
return; |
return; |
|
} |
|
241 |
#if defined(WIN32) |
#if defined(WIN32) |
242 |
// FIXME: under WIN32 we ignore the signals below due to the missing sigaction call |
// FIXME: under WIN32 we ignore the signals below due to the missing sigaction call |
243 |
#else |
#else |
373 |
if (optarg) { |
if (optarg) { |
374 |
std::cout << "Creating instruments database..." << std::endl; |
std::cout << "Creating instruments database..." << std::endl; |
375 |
InstrumentsDb::CreateInstrumentsDb(String(optarg)); |
InstrumentsDb::CreateInstrumentsDb(String(optarg)); |
|
InstrumentsDb::Destroy(); |
|
376 |
std::cout << "Done" << std::endl; |
std::cout << "Done" << std::endl; |
377 |
} |
} |
378 |
} catch(Exception e) { |
} catch(Exception e) { |