/[svn]/linuxsampler/trunk/src/network/lscpserver.h
ViewVC logotype

Contents of /linuxsampler/trunk/src/network/lscpserver.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 209 - (show annotations) (download) (as text)
Sun Jul 18 00:29:39 2004 UTC (19 years, 8 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 8239 byte(s)
* src/Sampler.cpp: changed sampler channel index allocation from consistent
channel index allocation to incrementing channel index allocation, that is
it doesn't fill channel index gaps anymore (to avoid race conditions)
* implemented "LIST CHANNELS" LSCP command

1 /***************************************************************************
2 * *
3 * LinuxSampler - modular, streaming capable sampler *
4 * *
5 * Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck *
6 * *
7 * This program is free software; you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation; either version 2 of the License, or *
10 * (at your option) any later version. *
11 * *
12 * This program is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU General Public License *
18 * along with this program; if not, write to the Free Software *
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, *
20 * MA 02111-1307 USA *
21 ***************************************************************************/
22
23 #ifndef __LSCPSERVER_H_
24 #define __LSCPSERVER_H_
25
26 #include <unistd.h>
27 #include <sys/types.h>
28 #include <sys/socket.h>
29 #include <sys/select.h>
30 #include <sys/time.h>
31 #include <netinet/in.h>
32 #include <netinet/tcp.h>
33 #include <arpa/inet.h>
34 #include <netdb.h>
35
36 #include <list>
37
38 #include "lscp.h"
39 #include "lscpparser.h"
40 #include "lscp.h"
41 #include "lscpevent.h"
42 #include "../Sampler.h"
43 #include "../common/Thread.h"
44 #include "../common/Mutex.h"
45
46 /// TCP Port on which the server should listen for connection requests.
47 #define LSCP_PORT 8888
48
49 using namespace LinuxSampler;
50
51 // External references to the main scanner and parser functions
52 extern int yyparse(void* YYPARSE_PARAM);
53 extern int yylex_init(yyscan_t* scanner);
54 extern int yylex_destroy(yyscan_t yyscanner);
55
56 /**
57 * Network server for the LinuxSampler Control Protocol (LSCP).
58 */
59 class LSCPServer : public Thread {
60 public:
61 LSCPServer(Sampler* pSampler);
62
63 // Methods called by the parser
64 String DestroyAudioOutputDevice(uint DeviceIndex);
65 String DestroyMidiInputDevice(uint DeviceIndex);
66 String LoadInstrument(String Filename, uint uiInstrument, uint uiSamplerChannel, bool bBackground = false);
67 String LoadEngine(String EngineName, uint uiSamplerChannel);
68 String GetChannels();
69 String ListChannels();
70 String AddChannel();
71 String RemoveChannel(uint uiSamplerChannel);
72 String GetAvailableEngines();
73 String GetEngineInfo(String EngineName);
74 String GetChannelInfo(uint uiSamplerChannel);
75 String GetVoiceCount(uint uiSamplerChannel);
76 String GetStreamCount(uint uiSamplerChannel);
77 String GetBufferFill(fill_response_t ResponseType, uint uiSamplerChannel);
78 String GetAvailableAudioOutputDrivers();
79 String GetAvailableMidiInputDrivers();
80 String GetAudioOutputDriverInfo(String Driver);
81 String GetMidiInputDriverInfo(String Driver);
82 #ifdef __GNUC__
83 typedef std::map<String,String> StringMap; // nasty workaround for a GCC bug (see GCC bug #15980, #57)
84 String GetAudioOutputDriverParameterInfo(String Driver, String Parameter, std::map<String,String> DependencyList = StringMap());
85 String GetMidiInputDriverParameterInfo(String Driver, String Parameter, std::map<String,String> DependencyList = StringMap());
86 String CreateAudioOutputDevice(String Driver, std::map<String,String> Parameters = StringMap());
87 String CreateMidiInputDevice(String Driver, std::map<String,String> Parameters = StringMap());
88 #else
89 String GetAudioOutputDriverParameterInfo(String Driver, String Parameter, std::map<String,String> DependencyList = std::map<String,String>());
90 String GetMidiInputDriverParameterInfo(String Driver, String Parameter, std::map<String,String> DependencyList = std::map<String,String>());
91 String CreateAudioOutputDevice(String Driver, std::map<String,String> Parameters = std::map<String,String>());
92 String CreateMidiInputDevice(String Driver, std::map<String,String> Parameters = std::map<String,String>());
93 #endif // __GNUC__
94 String GetAudioOutputDeviceCount();
95 String GetMidiInputDeviceCount();
96 String GetAudioOutputDevices();
97 String GetMidiInputDevices();
98 String GetAudioOutputDeviceInfo(uint DeviceIndex);
99 String GetMidiInputDeviceInfo(uint DeviceIndex);
100 String GetMidiInputPortInfo(uint DeviceIndex, uint PortIndex);
101 String GetMidiInputPortParameterInfo(uint DeviceId, uint PortId, String ParameterName);
102 String GetAudioOutputChannelInfo(uint DeviceId, uint ChannelId);
103 String GetAudioOutputChannelParameterInfo(uint DeviceId, uint ChannelId, String ParameterName);
104 String SetAudioOutputChannelParameter(uint DeviceId, uint ChannelId, String ParamKey, String ParamVal);
105 String SetAudioOutputDeviceParameter(uint DeviceIndex, String ParamKey, String ParamVal);
106 String SetMidiInputDeviceParameter(uint DeviceIndex, String ParamKey, String ParamVal);
107 String SetMidiInputPortParameter(uint DeviceIndex, uint PortIndex, String ParamKey, String ParamVal);
108 String SetAudioOutputChannel(uint ChannelAudioOutputChannel, uint AudioOutputDeviceInputChannel, uint uiSamplerChannel);
109 String SetAudioOutputDevice(uint AudioDeviceId, uint SamplerChannel);
110 String SetAudioOutputType(String AudioOutputDriver, uint uiSamplerChannel);
111 String SetMIDIInputPort(uint MIDIPort, uint uiSamplerChannel);
112 String SetMIDIInputChannel(uint MIDIChannel, uint uiSamplerChannel);
113 String SetMIDIInputDevice(uint MIDIDeviceId, uint uiSamplerChannel);
114 String SetMIDIInputType(String MidiInputDriver, uint uiSamplerChannel);
115 String SetMIDIInput(uint MIDIDeviceId, uint MIDIPort, uint MIDIChannel, uint uiSamplerChannel);
116 String SetVolume(double Volume, uint uiSamplerChannel);
117 String ResetChannel(uint uiSamplerChannel);
118 String SubscribeNotification(LSCPEvent::event_t);
119 String UnsubscribeNotification(LSCPEvent::event_t);
120 void AnswerClient(String ReturnMessage);
121
122 static int currentSocket;
123 static std::map<int,String> bufferedCommands;
124
125 static void SendLSCPNotify( LSCPEvent Event );
126
127 protected:
128 int hSocket;
129 sockaddr_in SocketAddress;
130 Sampler* pSampler;
131
132 int Main(); ///< Implementation of virtual method from class Thread
133
134 private:
135
136 /**
137 * Find a created audio output device index.
138 */
139 int GetAudioOutputDeviceIndex (AudioOutputDevice *pDevice);
140
141 /**
142 * Find a created midi input device index.
143 */
144 int GetMidiInputDeviceIndex (MidiInputDevice *pDevice);
145
146 static std::map<int,String> bufferedNotifies;
147 static Mutex NotifyMutex;
148 static Mutex NotifyBufferMutex;
149 static bool GetLSCPCommand( std::vector<int>::iterator iter );
150 static void CloseConnection( std::vector<int>::iterator iter );
151 static std::vector<int> hSessions;
152 static Mutex SubscriptionMutex;
153 static std::map< LSCPEvent::event_t, std::list<int> > eventSubscriptions;
154 static fd_set fdSet;
155 };
156
157 /**
158 * Instrument loader thread for the LinuxSampler Control Protocol (LSCP).
159 */
160 class LSCPLoadInstrument : public Thread {
161
162 public:
163 LSCPLoadInstrument(Engine* pEngine, String Filename, uint uiInstrument);
164
165 protected:
166 // Instance variables.
167 Engine* pEngine;
168 String Filename;
169 uint uiInstrument;
170
171 // Implementation of virtual method from class Thread.
172 int Main();
173 };
174
175 #endif // __LSCPSERVER_H_

  ViewVC Help
Powered by ViewVC