--- linuxsampler/trunk/src/network/lscpserver.h 2007/09/17 23:15:25 1353 +++ linuxsampler/trunk/src/network/lscpserver.h 2009/02/28 21:23:06 1848 @@ -3,7 +3,7 @@ * LinuxSampler - modular, streaming capable sampler * * * * Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * - * Copyright (C) 2005 - 2007 Christian Schoenebeck * + * Copyright (C) 2005 - 2008 Christian Schoenebeck * * * * This library is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * @@ -24,6 +24,10 @@ #ifndef __LSCPSERVER_H_ #define __LSCPSERVER_H_ +#if defined(WIN32) +#include +typedef int socklen_t; +#else #include #include #include @@ -33,20 +37,21 @@ #include #include #include +#endif #include #include "lscp.h" #include "lscpparser.h" -#include "lscp.h" #include "lscpevent.h" #include "../Sampler.h" #include "../common/Thread.h" #include "../common/Mutex.h" #include "../common/Condition.h" -#include "../common/global.h" +#include "../common/global_private.h" #include "../drivers/midi/MidiInstrumentMapper.h" +#include "../drivers/midi/VirtualMidiDevice.h" #if HAVE_SQLITE3 #include "../db/InstrumentsDb.h" @@ -59,10 +64,11 @@ /// try up to 3 minutes to bind server socket #define LSCP_SERVER_BIND_TIMEOUT 180 -using namespace LinuxSampler; - // External references to the main scanner and parser functions extern int yyparse(void* YYPARSE_PARAM); + +namespace LinuxSampler { + extern void restart(yyparse_param_t* pparam, int& yychar); /** @@ -73,6 +79,7 @@ LSCPServer(Sampler* pSampler, long int addr, short int port); virtual ~LSCPServer(); int WaitUntilInitialized(long TimeoutSeconds = 0L, long TimeoutNanoSeconds = 0L); + void RemoveListeners(); // Methods called by the parser String DestroyAudioOutputDevice(uint DeviceIndex); @@ -170,7 +177,7 @@ String SetDbInstrumentDirectoryDescription(String Dir, String Desc); String FindDbInstrumentDirectories(String Dir, std::map Parameters, bool Recursive = true); String AddDbInstruments(String DbDir, String FilePath, int Index = -1, bool bBackground = false); - String AddDbInstruments(String ScanMode, String DbDir, String FsDir, bool bBackground = false); + String AddDbInstruments(String ScanMode, String DbDir, String FsDir, bool bBackground = false, bool insDir = false); String RemoveDbInstrument(String Instr); String GetDbInstrumentCount(String Dir, bool Recursive = false); String GetDbInstruments(String Dir, bool Recursive = false); @@ -179,6 +186,8 @@ String MoveDbInstrument(String Instr, String Dst); String CopyDbInstrument(String Instr, String Dst); String SetDbInstrumentDescription(String Instr, String Desc); + String SetDbInstrumentFilePath(String OldPath, String NewPath); + String FindLostDbInstrumentFiles(); String FindDbInstruments(String Dir, std::map Parameters, bool Recursive = true); String FormatInstrumentsDb(); String EditSamplerChannelInstrument(uint uiSamplerChannel); @@ -186,22 +195,32 @@ String ResetChannel(uint uiSamplerChannel); String ResetSampler(); String GetServerInfo(); + String GetTotalStreamCount(); String GetTotalVoiceCount(); String GetTotalVoiceCountMax(); + String GetGlobalMaxVoices(); + String SetGlobalMaxVoices(int iVoices); + String GetGlobalMaxStreams(); + String SetGlobalMaxStreams(int iStreams); String GetGlobalVolume(); String SetGlobalVolume(double dVolume); + String GetFileInstruments(String Filename); + String ListFileInstruments(String Filename); + String GetFileInstrumentInfo(String Filename, uint InstrumentID); + String SendChannelMidiData(String MidiMsg, uint uiSamplerChannel, uint Arg1, uint Arg2); String SubscribeNotification(LSCPEvent::event_t); String UnsubscribeNotification(LSCPEvent::event_t); String SetEcho(yyparse_param_t* pSession, double boolean_value); void AnswerClient(String ReturnMessage); + void CloseAllConnections(); static int currentSocket; static std::map bufferedCommands; static void SendLSCPNotify( LSCPEvent Event ); static int EventSubscribers( std::list events ); - static void LockRTNotify( void ) { RTNotifyMutex.Lock(); } - static void UnlockRTNotify( void ) { RTNotifyMutex.Unlock(); } + static void LockRTNotify(); + static void UnlockRTNotify(); static String FilterEndlines(String s); protected: @@ -235,6 +254,12 @@ void MuteNonSoloChannels(); void UnmuteChannels(); + /** + * Throws an exception if the specified file is not found or + * if directory is specified. + */ + static void VerifyFile(String Filename); + static std::map bufferedNotifies; static Mutex NotifyMutex; static Mutex NotifyBufferMutex; @@ -254,15 +279,20 @@ public MidiDeviceCountListener, public MidiInstrumentCountListener, public MidiInstrumentInfoListener, public MidiInstrumentMapCountListener, public MidiInstrumentMapInfoListener, public FxSendCountListener, - public VoiceCountListener, public StreamCountListener, - public BufferFillListener, public TotalVoiceCountListener { + public VoiceCountListener, public StreamCountListener, public BufferFillListener, + public TotalStreamCountListener, public TotalVoiceCountListener, + public EngineChangeListener, public MidiPortCountListener { public: + EventHandler(LSCPServer* pParent); + /** * Invoked when the number of sampler channels has changed. * @param NewCount The new number of sampler channels. */ virtual void ChannelCountChanged(int NewCount); + virtual void ChannelAdded(SamplerChannel* pChannel); + virtual void ChannelToBeRemoved(SamplerChannel* pChannel); /** * Invoked when the number of audio output devices has changed. @@ -277,6 +307,40 @@ virtual void MidiDeviceCountChanged(int NewCount); /** + * Invoked right before the supplied MIDI input device is going + * to be destroyed. + * @param pDevice MidiInputDevice to be deleted + */ + virtual void MidiDeviceToBeDestroyed(MidiInputDevice* pDevice); + + /** + * Invoked to inform that a new MidiInputDevice has just been + * created. + * @param pDevice newly created MidiInputDevice + */ + virtual void MidiDeviceCreated(MidiInputDevice* pDevice); + + /** + * Invoked when the number of MIDI input ports has changed. + * @param NewCount The new number of MIDI input ports. + */ + virtual void MidiPortCountChanged(int NewCount); + + /** + * Invoked right before the supplied MIDI input port is going + * to be destroyed. + * @param pPort MidiInputPort to be deleted + */ + virtual void MidiPortToBeRemoved(MidiInputPort* pPort); + + /** + * Invoked to inform that a new MidiInputPort has just been + * added. + * @param pPort newly created MidiInputPort + */ + virtual void MidiPortAdded(MidiInputPort* pPort); + + /** * Invoked when the number of MIDI instruments has changed. * @param MapId The numerical ID of the MIDI instrument map. * @param NewCount The new number of MIDI instruments. @@ -340,6 +404,31 @@ * @param NewCount The new number of active voices. */ virtual void TotalVoiceCountChanged(int NewCount); + virtual void TotalStreamCountChanged(int NewCount); + + virtual void EngineToBeChanged(int ChannelId); + virtual void EngineChanged(int ChannelId); + + virtual ~EventHandler(); + + struct midi_listener_entry { + SamplerChannel* pSamplerChannel; + EngineChannel* pEngineChannel; + VirtualMidiDevice* pMidiListener; + }; + + std::vector channelMidiListeners; + + struct device_midi_listener_entry { + MidiInputPort* pPort; + VirtualMidiDevice* pMidiListener; + uint uiDeviceID; + }; + + std::vector deviceMidiListeners; + + private: + LSCPServer* pParent; } eventHandler; #if HAVE_SQLITE3 @@ -356,4 +445,6 @@ #endif // HAVE_SQLITE3 }; +} + #endif // __LSCPSERVER_H_