--- linuxsampler/trunk/src/linuxsampler.cpp 2005/05/24 19:20:20 579 +++ linuxsampler/trunk/src/linuxsampler.cpp 2007/05/16 14:22:26 1187 @@ -2,8 +2,8 @@ * * * LinuxSampler - modular, streaming capable sampler * * * - * Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * - * Copyright (C) 2005 Christian Schoenebeck * + * Copyright (C) 2003-2004 by Benno Senoner and Christian Schoenebeck * + * Copyright (C) 2005-2007 Christian Schoenebeck * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * @@ -38,9 +38,12 @@ Sampler* pSampler = NULL; LSCPServer* pLSCPServer = NULL; pthread_t main_thread; +pid_t main_pid; bool bPrintStatistics = false; bool profile = false; bool tune = true; +unsigned long int lscp_addr; +unsigned short int lscp_port; void parse_options(int argc, char **argv); void signal_handler(int signal); @@ -51,6 +54,7 @@ // initialize the stack trace mechanism with our binary file StackTraceInit(argv[0], -1); + main_pid = getpid(); main_thread = pthread_self(); // setting signal handler for catching SIGINT (thus e.g. ) @@ -69,12 +73,15 @@ sigaction(SIGUSR1, &sact, NULL); sigaction(SIGUSR2, &sact, NULL); + lscp_addr = htonl(LSCP_ADDR); + lscp_port = htons(LSCP_PORT); + // parse and assign command line options parse_options(argc, argv); dmsg(1,("LinuxSampler %s\n", VERSION)); - dmsg(1,("Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck\n")); - dmsg(1,("Copyright (C) 2005 Christian Schoenebeck\n")); + dmsg(1,("Copyright (C) 2003,2004 by Benno Senoner and Christian Schoenebeck\n")); + dmsg(1,("Copyright (C) 2005-2007 Christian Schoenebeck\n")); if (tune) { // detect and print system / CPU specific features @@ -89,12 +96,15 @@ pSampler = new Sampler; dmsg(1,("OK\n")); + dmsg(1,("Registered sampler engines: %s\n", EngineFactory::AvailableEngineTypesAsString().c_str())); dmsg(1,("Registered MIDI input drivers: %s\n", MidiInputDeviceFactory::AvailableDriversAsString().c_str())); dmsg(1,("Registered audio output drivers: %s\n", AudioOutputDeviceFactory::AvailableDriversAsString().c_str())); // start LSCP network server - dmsg(1,("Starting LSCP network server (on TCP port %d)...", LSCP_PORT)); - pLSCPServer = new LSCPServer(pSampler); + struct in_addr addr; + addr.s_addr = lscp_addr; + dmsg(1,("Starting LSCP network server (%s:%d)...", inet_ntoa(addr), ntohs(lscp_port))); + pLSCPServer = new LSCPServer(pSampler, lscp_addr, lscp_port); pLSCPServer->StartThread(); pLSCPServer->WaitUntilInitialized(); dmsg(1,("OK\n")); @@ -102,8 +112,9 @@ if (profile) { dmsg(1,("Calibrating profiler...")); - gig::Profiler::Calibrate(); - gig::Profiler::Reset(); + LinuxSampler::gig::Profiler::Calibrate(); + LinuxSampler::gig::Profiler::Reset(); + LinuxSampler::gig::Profiler::enable(); dmsg(1,("OK\n")); } @@ -113,10 +124,11 @@ 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) { if (bPrintStatistics) { - std::set engines = EngineFactory::EngineInstances(); + const std::set& engines = EngineFactory::EngineInstances(); std::set::iterator itEngine = engines.begin(); for (int i = 0; itEngine != engines.end(); itEngine++, i++) { Engine* pEngine = *itEngine; @@ -132,7 +144,7 @@ if (profile) { unsigned int samplingFreq = 48000; //FIXME: hardcoded for now - unsigned int bv = gig::Profiler::GetBogoVoices(samplingFreq); + unsigned int bv = LinuxSampler::gig::Profiler::GetBogoVoices(samplingFreq); if (bv != 0) { printf(" BogoVoices: %i \r", bv); @@ -151,9 +163,10 @@ if (!pEngineChannel) continue; Engine* pEngine = pEngineChannel->GetEngine(); if (!pEngine) continue; - LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_voice_count, iter->first, pEngine->VoiceCount())); - LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_stream_count, iter->first, pEngine->DiskStreamCount())); - LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_buffer_fill, iter->first, pEngine->DiskStreamBufferFillPercentage())); + pSampler->fireVoiceCountChanged(iter->first, pEngine->VoiceCount()); + pSampler->fireStreamCountChanged(iter->first, pEngine->DiskStreamCount()); + pSampler->fireBufferFillChanged(iter->first, pEngine->DiskStreamBufferFillPercentage()); + pSampler->fireTotalVoiceCountChanged(pSampler->GetVoiceCount()); } LSCPServer::UnlockRTNotify(); } @@ -172,6 +185,9 @@ delete pLSCPServer; } if (pSampler) delete pSampler; +#if HAVE_SQLITE3 + InstrumentsDb::Destroy(); +#endif printf("LinuxSampler stopped due to SIGINT.\n"); exit(EXIT_SUCCESS); } @@ -209,7 +225,7 @@ } void kill_app() { - kill(main_thread, SIGKILL); + kill(main_pid, SIGKILL); } void parse_options(int argc, char **argv) { @@ -222,6 +238,9 @@ {"profile",0,0,0}, {"no-tune",0,0,0}, {"statistics",0,0,0}, + {"create-instruments-db",1,0,0}, + {"lscp-addr",1,0,0}, + {"lscp-port",1,0,0}, {0,0,0,0} }; @@ -236,11 +255,14 @@ switch(option_index) { case 0: // --help printf("usage: linuxsampler [OPTIONS]\n\n"); - printf("--help prints this message\n"); - printf("--version prints version information\n"); - printf("--profile profile synthesis algorithms\n"); - printf("--no-tune disable assembly optimization\n"); - printf("--statistics prints periodically statistics\n"); + printf("--help prints this message\n"); + printf("--version prints version information\n"); + printf("--profile profile synthesis algorithms\n"); + printf("--no-tune disable assembly optimization\n"); + printf("--statistics periodically prints statistics\n"); + printf("--lscp-addr set LSCP address (default: any)\n"); + printf("--lscp-port set LSCP port (default: 8888)\n"); + printf("--create-instruments-db creates an instruments DB\n"); exit(EXIT_SUCCESS); break; case 1: // --version @@ -256,6 +278,43 @@ case 4: // --statistics bPrintStatistics = true; break; + case 5: // --create-instruments-db +#if HAVE_SQLITE3 + try { + if (optarg) { + std::cout << "Creating instruments database..." << std::endl; + InstrumentsDb::CreateInstrumentsDb(String(optarg)); + InstrumentsDb::Destroy(); + std::cout << "Done" << std::endl; + } + } catch(Exception e) { + std::cerr << e.Message() << std::endl; + exit(EXIT_FAILURE); + return; + } + + exit(EXIT_SUCCESS); + return; +#else + std::cerr << "Failed to create the database. LinuxSampler was "; + std::cerr << "not build with instruments database support." < 65535)) + printf("WARNING: Failed to parse lscp-port argument, ignoring!\n"); + else + lscp_port = htons(port); + break; } } }