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

Diff of /linuxsampler/trunk/src/network/lscpserver.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 35 by schoenebeck, Fri Mar 5 13:46:15 2004 UTC revision 53 by schoenebeck, Mon Apr 26 17:15:51 2004 UTC
# Line 22  Line 22 
22    
23  #include "lscpserver.h"  #include "lscpserver.h"
24    
25  LSCPServer::LSCPServer(AudioThread* pEngine) : Thread(false, 0, -4) {  #include "../engines/gig/Engine.h"
26      this->pEngine = pEngine;  
27    LSCPServer::LSCPServer(Sampler* pSampler) : Thread(false, 0, -4) {
28        this->pSampler = pSampler;
29  }  }
30    
31  int LSCPServer::Main() {  int LSCPServer::Main() {
32      hSocket = socket(AF_INET, SOCK_STREAM, 0);      hSocket = socket(AF_INET, SOCK_STREAM, 0);
33      if (hSocket < 0) {      if (hSocket < 0) {
34          std::cerr << "LSCPServer: Could not create server socket." << std::endl;          std::cerr << "LSCPServer: Could not create server socket." << std::endl;
35          return -1;          //return -1;
36            exit(EXIT_FAILURE);
37      }      }
38    
39      SocketAddress.sin_family      = AF_INET;      SocketAddress.sin_family      = AF_INET;
# Line 40  int LSCPServer::Main() { Line 43  int LSCPServer::Main() {
43      if (bind(hSocket, (sockaddr*) &SocketAddress, sizeof(sockaddr_in)) < 0) {      if (bind(hSocket, (sockaddr*) &SocketAddress, sizeof(sockaddr_in)) < 0) {
44          std::cerr << "LSCPServer: Could not bind server socket." << std::endl;          std::cerr << "LSCPServer: Could not bind server socket." << std::endl;
45          close(hSocket);          close(hSocket);
46          return -1;          //return -1;
47            exit(EXIT_FAILURE);
48      }      }
49    
50      listen(hSocket, 1);      listen(hSocket, 1);
# Line 54  int LSCPServer::Main() { Line 58  int LSCPServer::Main() {
58          if (hSession < 0) {          if (hSession < 0) {
59              std::cerr << "LSCPServer: Client connection failed." << std::endl;              std::cerr << "LSCPServer: Client connection failed." << std::endl;
60              close(hSocket);              close(hSocket);
61              return -1;              //return -1;
62                exit(EXIT_FAILURE);
63          }          }
64    
65          dmsg(1,("LSCPServer: Client connection established.\n"));          dmsg(1,("LSCPServer: Client connection established.\n"));
# Line 86  void LSCPServer::AnswerClient(String Ret Line 91  void LSCPServer::AnswerClient(String Ret
91  /**  /**
92   * Will be called by the parser to load an instrument.   * Will be called by the parser to load an instrument.
93   */   */
94  String LSCPServer::LoadInstrument(String Filename, uint Instrument, uint SamplerChannel) {  String LSCPServer::LoadInstrument(String Filename, uint uiInstrument, uint uiSamplerChannel) {
95      dmsg(2,("LSCPServer: LoadInstrument(Filename=%s,Instrument=%d,SamplerChannel=%d)\n", Filename.c_str(), Instrument, SamplerChannel));      dmsg(2,("LSCPServer: LoadInstrument(Filename=%s,Instrument=%d,SamplerChannel=%d)\n", Filename.c_str(), uiInstrument, uiSamplerChannel));
96      result_t res = pEngine->LoadInstrument(Filename.c_str(), Instrument);      result_t result;
97      return ConvertResult(res);      try {
98            SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
99            if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");
100            Engine* pEngine = pSamplerChannel->GetEngine();
101            if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");
102            pEngine->LoadInstrument(Filename.c_str(), uiInstrument);
103            result.type = result_type_success;
104        }
105        catch (LinuxSamplerException e) {
106             e.PrintMessage();
107             result.type    = result_type_error;
108             result.code    = LSCP_ERR_UNKNOWN;
109             result.message = e.Message();
110        }
111        return ConvertResult(result);
112  }  }
113    
114  /**  /**
115   * Will be called by the parser to load and deploy an engine.   * Will be called by the parser to load and deploy an engine.
116   */   */
117  String LSCPServer::LoadEngine(String EngineName, uint SamplerChannel) {  String LSCPServer::LoadEngine(String EngineName, uint uiSamplerChannel) {
118      dmsg(2,("LSCPServer: LoadEngine(EngineName=%s,SamplerChannel=%d)\n", EngineName.c_str(), SamplerChannel));      dmsg(2,("LSCPServer: LoadEngine(EngineName=%s,SamplerChannel=%d)\n", EngineName.c_str(), uiSamplerChannel));
119      return "ERR:0:Not implemented yet.\r\n";      result_t result;
120        try {
121            engine_type_t type;
122            if (EngineName == "gig") type = engine_type_gig;
123            else throw LinuxSamplerException("Unknown engine type");
124            SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
125            if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");
126            pSamplerChannel->LoadEngine(type);
127            result.type = result_type_success;
128        }
129        catch (LinuxSamplerException e) {
130             e.PrintMessage();
131             result.type    = result_type_error;
132             result.code    = LSCP_ERR_UNKNOWN;
133             result.message = e.Message();
134        }
135        return ConvertResult(result);
136  }  }
137    
138  /**  /**
# Line 105  String LSCPServer::LoadEngine(String Eng Line 140  String LSCPServer::LoadEngine(String Eng
140   */   */
141  String LSCPServer::GetChannels() {  String LSCPServer::GetChannels() {
142      dmsg(2,("LSCPServer: GetChannels()\n"));      dmsg(2,("LSCPServer: GetChannels()\n"));
143      return "1\r\n";      return ToString(pSampler->SamplerChannels()) + "\r\n";
144  }  }
145    
146  /**  /**
# Line 113  String LSCPServer::GetChannels() { Line 148  String LSCPServer::GetChannels() {
148   */   */
149  String LSCPServer::AddChannel() {  String LSCPServer::AddChannel() {
150      dmsg(2,("LSCPServer: AddChannel()\n"));      dmsg(2,("LSCPServer: AddChannel()\n"));
151      return "ERR:0:Not implemented yet.\r\n";      SamplerChannel* pSamplerChannel = pSampler->AddSamplerChannel();
152        return "OK[" + ToString(pSamplerChannel->Index()) + "]\r\n";
153  }  }
154    
155  /**  /**
156   * Will be called by the parser to remove a sampler channel.   * Will be called by the parser to remove a sampler channel.
157   */   */
158  String LSCPServer::RemoveChannel(uint SamplerChannel) {  String LSCPServer::RemoveChannel(uint uiSamplerChannel) {
159      dmsg(2,("LSCPServer: RemoveChannel(SamplerChannel=%d)\n", SamplerChannel));      dmsg(2,("LSCPServer: RemoveChannel(SamplerChannel=%d)\n", uiSamplerChannel));
160      return "ERR:0:Not implemented yet.\r\n";      pSampler->RemoveSamplerChannel(uiSamplerChannel);
161        return "OK\r\n";
162  }  }
163    
164  /**  /**
# Line 129  String LSCPServer::RemoveChannel(uint Sa Line 166  String LSCPServer::RemoveChannel(uint Sa
166   */   */
167  String LSCPServer::GetAvailableEngines() {  String LSCPServer::GetAvailableEngines() {
168      dmsg(2,("LSCPServer: GetAvailableEngines()\n"));      dmsg(2,("LSCPServer: GetAvailableEngines()\n"));
169      return "ERR:0:Not implemented yet.\r\n";      return "gig\r\n";
170  }  }
171    
172  /**  /**
# Line 137  String LSCPServer::GetAvailableEngines() Line 174  String LSCPServer::GetAvailableEngines()
174   */   */
175  String LSCPServer::GetEngineInfo(String EngineName) {  String LSCPServer::GetEngineInfo(String EngineName) {
176      dmsg(2,("LSCPServer: GetEngineInfo(EngineName=%s)\n", EngineName.c_str()));      dmsg(2,("LSCPServer: GetEngineInfo(EngineName=%s)\n", EngineName.c_str()));
177      return "ERR:0:Not implemented yet.\r\n";      result_t result;
178        try {
179            if (EngineName == "gig") {
180                Engine* pEngine = new LinuxSampler::gig::Engine;
181                String info = pEngine->Description() + "\r\n";
182                delete pEngine;
183                return info; // success
184            }
185            else throw LinuxSamplerException("Unknown engine type");
186        }
187        catch (LinuxSamplerException e) {
188             e.PrintMessage();
189             result.type    = result_type_error;
190             result.code    = LSCP_ERR_UNKNOWN;
191             result.message = e.Message();
192        }
193        return ConvertResult(result);
194  }  }
195    
196  /**  /**
197   * Will be called by the parser to get informations about a particular   * Will be called by the parser to get informations about a particular
198   * sampler channel.   * sampler channel.
199   */   */
200  String LSCPServer::GetChannelInfo(uint SamplerChannel) {  String LSCPServer::GetChannelInfo(uint uiSamplerChannel) {
201      dmsg(2,("LSCPServer: GetChannelInfo(SamplerChannel=%d)\n", SamplerChannel));      dmsg(2,("LSCPServer: GetChannelInfo(SamplerChannel=%d)\n", uiSamplerChannel));
202      return "ERR:0:Not implemented yet.\r\n";      return "ERR:0:Not implemented yet.\r\n";
203  }  }
204    
# Line 153  String LSCPServer::GetChannelInfo(uint S Line 206  String LSCPServer::GetChannelInfo(uint S
206   * Will be called by the parser to get the amount of active voices on a   * Will be called by the parser to get the amount of active voices on a
207   * particular sampler channel.   * particular sampler channel.
208   */   */
209  String LSCPServer::GetVoiceCount(uint SamplerChannel) {  String LSCPServer::GetVoiceCount(uint uiSamplerChannel) {
210      dmsg(2,("LSCPServer: GetVoiceCount(SamplerChannel=%d)\n", SamplerChannel));      dmsg(2,("LSCPServer: GetVoiceCount(SamplerChannel=%d)\n", uiSamplerChannel));
211      return ToString(pEngine->ActiveVoiceCount) + "\r\n";      result_t result;
212        try {
213            SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
214            if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");
215            Engine* pEngine = pSamplerChannel->GetEngine();
216            if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");
217            return ToString(pEngine->VoiceCount()) + "\r\n"; // success
218        }
219        catch (LinuxSamplerException e) {
220             e.PrintMessage();
221             result.type    = result_type_error;
222             result.code    = LSCP_ERR_UNKNOWN;
223             result.message = e.Message();
224        }
225        return ConvertResult(result);
226  }  }
227    
228  /**  /**
229   * Will be called by the parser to get the amount of active disk streams on a   * Will be called by the parser to get the amount of active disk streams on a
230   * particular sampler channel.   * particular sampler channel.
231   */   */
232  String LSCPServer::GetStreamCount(uint SamplerChannel) {  String LSCPServer::GetStreamCount(uint uiSamplerChannel) {
233      dmsg(2,("LSCPServer: GetStreamCount(SamplerChannel=%d)\n", SamplerChannel));      dmsg(2,("LSCPServer: GetStreamCount(SamplerChannel=%d)\n", uiSamplerChannel));
234      return ToString(pEngine->pDiskThread->ActiveStreamCount) + "\r\n";      result_t result;
235        try {
236            SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
237            if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");
238            Engine* pEngine = pSamplerChannel->GetEngine();
239            if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");
240            return ToString(pEngine->DiskStreamCount()) + "\r\n"; // success
241        }
242        catch (LinuxSamplerException e) {
243             e.PrintMessage();
244             result.type    = result_type_error;
245             result.code    = LSCP_ERR_UNKNOWN;
246             result.message = e.Message();
247        }
248        return ConvertResult(result);
249  }  }
250    
251  /**  /**
252   * Will be called by the parser to get the buffer fill states of all disk   * Will be called by the parser to get the buffer fill states of all disk
253   * streams on a particular sampler channel.   * streams on a particular sampler channel.
254   */   */
255  String LSCPServer::GetBufferFill(fill_response_t ResponseType, uint SamplerChannel) {  String LSCPServer::GetBufferFill(fill_response_t ResponseType, uint uiSamplerChannel) {
256      dmsg(2,("LSCPServer: GetBufferFill(ResponseType=%d, SamplerChannel=%d)\n", ResponseType, SamplerChannel));      dmsg(2,("LSCPServer: GetBufferFill(ResponseType=%d, SamplerChannel=%d)\n", ResponseType, uiSamplerChannel));
257      return (ResponseType == fill_response_bytes) ? pEngine->pDiskThread->GetBufferFillBytes() + "\r\n"      result_t result;
258                                                   : pEngine->pDiskThread->GetBufferFillPercentage() + "\r\n";      try {
259            SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
260            if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");
261            Engine* pEngine = pSamplerChannel->GetEngine();
262            if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");
263            if (!pEngine->DiskStreamSupported()) return "NA\r\n";
264            switch (ResponseType) {
265                case fill_response_bytes:
266                    return ToString(pEngine->DiskStreamBufferFillBytes()) + "\r\n"; // success
267                case fill_response_percentage:
268                    return ToString(pEngine->DiskStreamBufferFillPercentage()) + "\r\n"; // success
269                default:
270                    throw LinuxSamplerException("Unknown fill response type");
271            }
272        }
273        catch (LinuxSamplerException e) {
274             e.PrintMessage();
275             result.type    = result_type_error;
276             result.code    = LSCP_ERR_UNKNOWN;
277             result.message = e.Message();
278        }
279        return ConvertResult(result);
280  }  }
281    
282  /**  /**
283   * Will be called by the parser to change the audio output type on a   * Will be called by the parser to change the audio output type on a
284   * particular sampler channel.   * particular sampler channel.
285   */   */
286  String LSCPServer::SetAudioOutputType(audio_output_type_t AudioOutputType, uint SamplerChannel) {  String LSCPServer::SetAudioOutputType(audio_output_type_t AudioOutputType, uint uiSamplerChannel) {
287      dmsg(2,("LSCPServer: SetAudioOutputType(AudioOutputType=%d, SamplerChannel=%d)\n", AudioOutputType, SamplerChannel));      dmsg(2,("LSCPServer: SetAudioOutputType(AudioOutputType=%d, SamplerChannel=%d)\n", AudioOutputType, uiSamplerChannel));
288      return "ERR:0:Not implemented yet.\r\n";      result_t result;
289        try {
290            SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
291            if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");
292            pSamplerChannel->SetAudioOutputDevice(AudioOutputType);
293            result.type = result_type_success;
294        }
295        catch (LinuxSamplerException e) {
296             e.PrintMessage();
297             result.type    = result_type_error;
298             result.code    = LSCP_ERR_UNKNOWN;
299             result.message = e.Message();
300        }
301        return ConvertResult(result);
302  }  }
303    
304  /**  /**
305   * Will be called by the parser to change the audio output channel for   * Will be called by the parser to change the audio output channel for
306   * playback on a particular sampler channel.   * playback on a particular sampler channel.
307   */   */
308  String LSCPServer::SetAudioOutputChannel(uint AudioOutputChannel, uint SamplerChannel) {  String LSCPServer::SetAudioOutputChannel(uint AudioOutputChannel, uint uiSamplerChannel) {
309      dmsg(2,("LSCPServer: SetAudioOutputChannel(AudioOutputChannel=%d, SamplerChannel=%d)\n", AudioOutputChannel, SamplerChannel));      dmsg(2,("LSCPServer: SetAudioOutputChannel(AudioOutputChannel=%d, SamplerChannel=%d)\n", AudioOutputChannel, uiSamplerChannel));
310      return "ERR:0:Not implemented yet.\r\n";      return "ERR:0:Not implemented yet.\r\n";
311  }  }
312    
313    String LSCPServer::SetMIDIInputType(midi_input_type_t MidiInputType, uint uiSamplerChannel) {
314        dmsg(2,("LSCPServer: SetMIDIInputType(MidiInputType=%d, SamplerChannel=%d)\n", MidiInputType, uiSamplerChannel));
315        result_t result;
316        try {
317            SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
318            if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");
319            pSamplerChannel->SetMidiInputDevice(MidiInputType);
320            result.type = result_type_success;
321        }
322        catch (LinuxSamplerException e) {
323             e.PrintMessage();
324             result.type    = result_type_error;
325             result.code    = LSCP_ERR_UNKNOWN;
326             result.message = e.Message();
327        }
328        return ConvertResult(result);
329    }
330    
331  /**  /**
332   * Will be called by the parser to change the MIDI input port on which the   * Will be called by the parser to change the MIDI input port on which the
333   * engine of a particular sampler channel should listen to.   * engine of a particular sampler channel should listen to.
334   */   */
335  String LSCPServer::SetMIDIInputPort(String MIDIInputPort, uint Samplerchannel) {  String LSCPServer::SetMIDIInputPort(String MIDIInputPort, uint uiSamplerchannel) {
336      dmsg(2,("LSCPServer: SetMIDIInputPort(MIDIInputPort=%s, Samplerchannel=%d)\n", MIDIInputPort.c_str(), Samplerchannel));      dmsg(2,("LSCPServer: SetMIDIInputPort(MIDIInputPort=%s, Samplerchannel=%d)\n", MIDIInputPort.c_str(), uiSamplerchannel));
337      return "ERR:0:Not implemented yet.\r\n";      return "ERR:0:Not implemented yet.\r\n";
338  }  }
339    
# Line 208  String LSCPServer::SetMIDIInputPort(Stri Line 341  String LSCPServer::SetMIDIInputPort(Stri
341   * Will be called by the parser to change the MIDI input channel on which the   * Will be called by the parser to change the MIDI input channel on which the
342   * engine of a particular sampler channel should listen to.   * engine of a particular sampler channel should listen to.
343   */   */
344  String LSCPServer::SetMIDIInputChannel(uint MIDIChannel, uint SamplerChannel) {  String LSCPServer::SetMIDIInputChannel(uint MIDIChannel, uint uiSamplerChannel) {
345      dmsg(2,("LSCPServer: SetMIDIInputChannel(MIDIChannel=%d, SamplerChannel=%d)\n", MIDIChannel, SamplerChannel));      dmsg(2,("LSCPServer: SetMIDIInputChannel(MIDIChannel=%d, SamplerChannel=%d)\n", MIDIChannel, uiSamplerChannel));
346      return "ERR:0:Not implemented yet.\r\n";      return "ERR:0:Not implemented yet.\r\n";
347  }  }
348    
# Line 217  String LSCPServer::SetMIDIInputChannel(u Line 350  String LSCPServer::SetMIDIInputChannel(u
350   * Will be called by the parser to change the global volume factor on a   * Will be called by the parser to change the global volume factor on a
351   * particular sampler channel.   * particular sampler channel.
352   */   */
353  String LSCPServer::SetVolume(double Volume, uint SamplerChannel) {  String LSCPServer::SetVolume(double Volume, uint uiSamplerChannel) {
354      dmsg(2,("LSCPServer: SetVolume(Volume=%f, SamplerChannel=%d)\n", Volume, SamplerChannel));      dmsg(2,("LSCPServer: SetVolume(Volume=%f, SamplerChannel=%d)\n", Volume, uiSamplerChannel));
355      pEngine->Volume = Volume;      result_t result;
356      return "OK\r\n";      try {
357            SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
358            if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");
359            Engine* pEngine = pSamplerChannel->GetEngine();
360            if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");
361            pEngine->Volume(Volume);
362            result.type = result_type_success;
363        }
364        catch (LinuxSamplerException e) {
365             e.PrintMessage();
366             result.type    = result_type_error;
367             result.code    = LSCP_ERR_UNKNOWN;
368             result.message = e.Message();
369        }
370        return ConvertResult(result);
371  }  }
372    
373  /**  /**
374   * Will be called by the parser to reset a particular sampler channel.   * Will be called by the parser to reset a particular sampler channel.
375   */   */
376  String LSCPServer::ResetChannel(uint SamplerChannel) {  String LSCPServer::ResetChannel(uint uiSamplerChannel) {
377      dmsg(2,("LSCPServer: ResetChannel(SamplerChannel=%d)\n", SamplerChannel));      dmsg(2,("LSCPServer: ResetChannel(SamplerChannel=%d)\n", uiSamplerChannel));
378      pEngine->Reset();      result_t result;
379      return "OK\r\n";      try {
380            SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
381            if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");
382            Engine* pEngine = pSamplerChannel->GetEngine();
383            if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");
384            pEngine->Reset();
385            result.type = result_type_success;
386        }
387        catch (LinuxSamplerException e) {
388             e.PrintMessage();
389             result.type    = result_type_error;
390             result.code    = LSCP_ERR_UNKNOWN;
391             result.message = e.Message();
392        }
393        return ConvertResult(result);
394  }  }
395    
396  /**  /**

Legend:
Removed from v.35  
changed lines
  Added in v.53

  ViewVC Help
Powered by ViewVC