--- linuxsampler/trunk/src/linuxsampler.cpp 2006/01/08 20:19:49 826 +++ linuxsampler/trunk/src/linuxsampler.cpp 2007/10/03 18:41:09 1375 @@ -2,8 +2,8 @@ * * * LinuxSampler - modular, streaming capable sampler * * * - * Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * - * Copyright (C) 2005, 2006 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 * @@ -26,6 +26,7 @@ #include "Sampler.h" #include "engines/EngineFactory.h" +#include "plugins/InstrumentEditorFactory.h" #include "drivers/midi/MidiInputDeviceFactory.h" #include "drivers/audio/AudioOutputDeviceFactory.h" #include "engines/gig/Profiler.h" @@ -57,8 +58,6 @@ main_pid = getpid(); main_thread = pthread_self(); - - // setting signal handler for catching SIGINT (thus e.g. ) signal(SIGINT, signal_handler); @@ -82,8 +81,8 @@ 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, 2006 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 @@ -98,8 +97,10 @@ 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())); + dmsg(1,("Registered instrument editors: %s\n", InstrumentEditorFactory::AvailableEditorsAsString().c_str())); // start LSCP network server struct in_addr addr; @@ -113,9 +114,9 @@ if (profile) { dmsg(1,("Calibrating profiler...")); - gig::Profiler::Calibrate(); - gig::Profiler::Reset(); - gig::Profiler::enable(); + LinuxSampler::gig::Profiler::Calibrate(); + LinuxSampler::gig::Profiler::Reset(); + LinuxSampler::gig::Profiler::enable(); dmsg(1,("OK\n")); } @@ -129,7 +130,7 @@ 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; @@ -145,7 +146,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); @@ -164,10 +165,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())); - LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_total_voice_count, pSampler->GetVoiceCount())); + pSampler->fireVoiceCountChanged(iter->first, pEngineChannel->GetVoiceCount()); + pSampler->fireStreamCountChanged(iter->first, pEngineChannel->GetDiskStreamCount()); + pSampler->fireBufferFillChanged(iter->first, pEngine->DiskStreamBufferFillPercentage()); + pSampler->fireTotalVoiceCountChanged(pSampler->GetVoiceCount()); } LSCPServer::UnlockRTNotify(); } @@ -181,11 +182,14 @@ switch (iSignal) { case SIGINT: { if (pthread_equal(pthread_self(), main_thread)) { - if (pLSCPServer) { - pLSCPServer->StopThread(); - delete pLSCPServer; - } + 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); } @@ -236,6 +240,8 @@ {"profile",0,0,0}, {"no-tune",0,0,0}, {"statistics",0,0,0}, + {"instruments-db-location",1,0,0}, + {"create-instruments-db",1,0,0}, {"lscp-addr",1,0,0}, {"lscp-port",1,0,0}, {0,0,0,0} @@ -252,13 +258,15 @@ 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 periodically prints statistics\n"); - printf("--lscp-addr set LSCP address (default: any)\n"); - printf("--lscp-port set LSCP port (default: 8888)\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"); + printf("--instruments-db-location specifies the instruments DB file\n"); exit(EXIT_SUCCESS); break; case 1: // --version @@ -274,19 +282,75 @@ case 4: // --statistics bPrintStatistics = true; break; - case 5: // --lscp-addr - struct in_addr addr; - if (inet_aton(optarg, &addr) == 0) - printf("WARNING: Failed to parse lscp-addr argument, ignoring!\n"); - else - lscp_addr = addr.s_addr; + case 5: // --instruments-db-location +#if HAVE_SQLITE3 + try { + if (optarg) { + struct stat statBuf; + int res = stat(optarg, &statBuf); + + if (res) { + std::stringstream ss; + ss << "Failed to stat `" << optarg << "`: " << strerror(errno); + throw Exception(ss.str()); + } + + if (!S_ISREG(statBuf.st_mode)) { + std::stringstream ss; + ss << "`" << optarg << "` is not a regular file"; + throw Exception(ss.str()); + } + + InstrumentsDb::GetInstrumentsDb()->SetDbFile(String(optarg)); + } + } catch(Exception e) { + std::cerr << "Could not open instruments DB file: " + << e.Message() << std::endl; + exit(EXIT_FAILURE); + } + break; +#else + std::cerr << "LinuxSampler was not build with "; + std::cerr << "instruments database support!\n"; + exit(EXIT_FAILURE); + break; +#endif + case 6: // --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!\n"; + exit(EXIT_FAILURE); + return; +#endif + case 7: // --lscp-addr + struct in_addr addr; + if (inet_aton(optarg, &addr) == 0) + printf("WARNING: Failed to parse lscp-addr argument, ignoring!\n"); + else + lscp_addr = addr.s_addr; break; - case 6: // --lscp-port - long unsigned int port = 0; - if ((sscanf(optarg, "%u", &port) != 1) || (port == 0) || (port > 65535)) - printf("WARNING: Failed to parse lscp-port argument, ignoring!\n"); - else - lscp_port = htons(port); + case 8: // --lscp-port + long unsigned int port = 0; + if ((sscanf(optarg, "%u", &port) != 1) || (port == 0) || (port > 65535)) + printf("WARNING: Failed to parse lscp-port argument, ignoring!\n"); + else + lscp_port = htons(port); break; } }