--- linuxsampler/trunk/src/network/lscpserver.h 2004/04/26 17:15:51 53 +++ linuxsampler/trunk/src/network/lscpserver.h 2004/07/03 20:08:07 170 @@ -2,7 +2,7 @@ * * * LinuxSampler - modular, streaming capable sampler * * * - * Copyright (C) 2003 by Benno Senoner and Christian Schoenebeck * + * Copyright (C) 2003, 2004 by Benno Senoner and 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,24 +26,28 @@ #include #include #include +#include +#include #include #include #include #include +#include + #include "lscp.h" #include "lscpparser.h" +#include "lscp.h" +#include "lscpevent.h" #include "../Sampler.h" #include "../common/Thread.h" +#include "../common/Mutex.h" /// TCP Port on which the server should listen for connection requests. #define LSCP_PORT 8888 using namespace LinuxSampler; -/// Handle for a client connection (FIXME: doesn't work for more than one network connections of course, thus has to be included to the yyparse() parameters instead). -extern int hSession; - // External references to the main scanner and parser functions extern int yyparse(void* YYPARSE_PARAM); extern int yylex_init(yyscan_t* scanner); @@ -57,7 +61,9 @@ LSCPServer(Sampler* pSampler); // Methods called by the parser - String LoadInstrument(String Filename, uint uiInstrument, uint uiSamplerChannel); + String DestroyAudioOutputDevice(uint DeviceIndex); + String DestroyMidiInputDevice(uint DeviceIndex); + String LoadInstrument(String Filename, uint uiInstrument, uint uiSamplerChannel, bool bBackground = false); String LoadEngine(String EngineName, uint uiSamplerChannel); String GetChannels(); String AddChannel(); @@ -68,49 +74,99 @@ String GetVoiceCount(uint uiSamplerChannel); String GetStreamCount(uint uiSamplerChannel); String GetBufferFill(fill_response_t ResponseType, uint uiSamplerChannel); - String SetAudioOutputType(audio_output_type_t AudioOutputType, uint uiSamplerChannel); - String SetAudioOutputChannel(uint AudioOutputChannel, uint uiSamplerChannel); - String SetMIDIInputType(midi_input_type_t MidiInputType, uint uiSamplerChannel); - String SetMIDIInputPort(String MIDIInputPort, uint uiSamplerchannel); + String GetAvailableAudioOutputDrivers(); + String GetAvailableMidiInputDrivers(); + String GetAudioOutputDriverInfo(String Driver); + String GetMidiInputDriverInfo(String Driver); +#ifdef __GNUC__ + typedef std::map StringMap; // nasty workaround for a GCC bug (see GCC bug #15980, #57) + String GetAudioOutputDriverParameterInfo(String Driver, String Parameter, std::map DependencyList = StringMap()); + String GetMidiInputDriverParameterInfo(String Driver, String Parameter, std::map DependencyList = StringMap()); + String CreateAudioOutputDevice(String Driver, std::map Parameters = StringMap()); + String CreateMidiInputDevice(String Driver, std::map Parameters = StringMap()); +#else + String GetAudioOutputDriverParameterInfo(String Driver, String Parameter, std::map DependencyList = std::map()); + String GetMidiInputDriverParameterInfo(String Driver, String Parameter, std::map DependencyList = std::map()); + String CreateAudioOutputDevice(String Driver, std::map Parameters = std::map()); + String CreateMidiInputDevice(String Driver, std::map Parameters = std::map()); +#endif // __GNUC__ + String GetAudioOutputDeviceCount(); + String GetMidiInputDeviceCount(); + String GetAudioOutputDevices(); + String GetMidiInputDevices(); + String GetAudioOutputDeviceInfo(uint DeviceIndex); + String GetMidiInputDeviceInfo(uint DeviceIndex); + String GetMidiInputPortInfo(uint DeviceIndex, uint PortIndex); + String GetAudioOutputChannelInfo(uint DeviceId, uint ChannelId); + String GetAudioOutputChannelParameterInfo(uint DeviceId, uint ChannelId, String ParameterName); + String SetAudioOutputChannelParameter(uint DeviceId, uint ChannelId, String ParamKey, String ParamVal); + String SetAudioOutputDeviceParameter(uint DeviceIndex, String ParamKey, String ParamVal); + String SetMidiInputDeviceParameter(uint DeviceIndex, String ParamKey, String ParamVal); + String SetMidiInputPortParameter(uint DeviceIndex, uint PortIndex, String ParamKey, String ParamVal); + String SetAudioOutputChannel(uint ChannelAudioOutputChannel, uint AudioOutputDeviceInputChannel, uint uiSamplerChannel); + String SetAudioOutputDevice(uint AudioDeviceId, uint SamplerChannel); + String SetAudioOutputType(String AudioOutputDriver, uint uiSamplerChannel); + String SetMIDIInputPort(uint MIDIPort, uint uiSamplerChannel); String SetMIDIInputChannel(uint MIDIChannel, uint uiSamplerChannel); + String SetMIDIInputDevice(uint MIDIDeviceId, uint uiSamplerChannel); + String SetMIDIInputType(String MidiInputDriver, uint uiSamplerChannel); + String SetMIDIInput(uint MIDIDeviceId, uint MIDIPort, uint MIDIChannel, uint uiSamplerChannel); String SetVolume(double Volume, uint uiSamplerChannel); String ResetChannel(uint uiSamplerChannel); - String SubscribeNotification(uint UDPPort); - String UnsubscribeNotification(String SessionID); + String SubscribeNotification(LSCPEvent::event_t); + String UnsubscribeNotification(LSCPEvent::event_t); void AnswerClient(String ReturnMessage); + + static int currentSocket; + static std::map bufferedCommands; protected: int hSocket; sockaddr_in SocketAddress; Sampler* pSampler; int Main(); ///< Implementation of virtual method from class Thread + + static void SendLSCPNotify( LSCPEvent Event ); + private: + + /** + * Find a created audio output device index. + */ + int GetAudioOutputDeviceIndex (AudioOutputDevice *pDevice); + /** - * Converts a result_t structure into a valid LSCP answer message. + * Find a created midi input device index. */ - inline String ConvertResult(result_t result) { - switch (result.type) { - case result_type_success: { - return "OK\r\n"; - } - case result_type_warning: { - std::stringstream ss; - ss << "WRN:" << result.code << ":" << result.message << "\r\n"; - return ss.str(); - } - case result_type_error: { - std::stringstream ss; - ss << "ERR:" << result.code << ":" << result.message << "\r\n"; - return ss.str(); - } - } - } - - template inline String ToString(T o) { - std::stringstream ss; - ss << o; - return ss.str(); - } + int GetMidiInputDeviceIndex (MidiInputDevice *pDevice); + + static std::map bufferedNotifies; + static Mutex NotifyMutex; + static Mutex NotifyBufferMutex; + static bool GetLSCPCommand( std::vector::iterator iter ); + static void CloseConnection( std::vector::iterator iter ); + static std::vector hSessions; + static Mutex SubscriptionMutex; + static std::map< LSCPEvent::event_t, std::list > eventSubscriptions; + static fd_set fdSet; +}; + +/** + * Instrument loader thread for the LinuxSampler Control Protocol (LSCP). + */ +class LSCPLoadInstrument : public Thread { + + public: + LSCPLoadInstrument(Engine* pEngine, String Filename, uint uiInstrument); + + protected: + // Instance variables. + Engine* pEngine; + String Filename; + uint uiInstrument; + + // Implementation of virtual method from class Thread. + int Main(); }; #endif // __LSCPSERVER_H_