/[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 123 - (show annotations) (download) (as text)
Mon Jun 14 19:33:16 2004 UTC (19 years, 10 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 6328 byte(s)
* src/common: added template class 'optional<>' which can be used e.g. as
  return type whenever a value might be returned, but don't has to; this
  template class pretty much acts like a pointer of the given type, but is
  much more safer than a simple pointer
* src/audiodriver: added static class AudioDeviceFactory to create audio
  devices at runtime by using a string and to obtain driver informations
  of drivers at runtime, driver classes should simply use the macro
  REGISTER_AUDIO_OUTPUT_DRIVER(DriverName,DriverClass) in their cpp file
  to register the driver to LinuxSampler (no changes needed anymore in the
  LS code to add a new audio output driver)
* src/drivers: added classes to dynamically manage driver parameters; there
  are two different kinds of parameters: parameters which are need to
  create a new device (DeviceCreationParameterX) used to e.g. create an
  audio output device or a MIDI input device and parameters which are only
  available at runtime, means when a device is already created
  (DeviceRuntimeParameterX) which will be e.g. used as audio channel
  parameters and MIDI port parameters
* src/linuxsampler.cpp: all registered audio output drivers will be shown
  on the console on startup
* src/network: implemented configuration of audio output devices via LSCP

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 <netinet/in.h>
30 #include <netinet/tcp.h>
31 #include <arpa/inet.h>
32 #include <netdb.h>
33
34 #include "lscp.h"
35 #include "lscpparser.h"
36 #include "../Sampler.h"
37 #include "../common/Thread.h"
38
39 /// TCP Port on which the server should listen for connection requests.
40 #define LSCP_PORT 8888
41
42 using namespace LinuxSampler;
43
44 /// 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).
45 extern int hSession;
46
47 // External references to the main scanner and parser functions
48 extern int yyparse(void* YYPARSE_PARAM);
49 extern int yylex_init(yyscan_t* scanner);
50 extern int yylex_destroy(yyscan_t yyscanner);
51
52 /**
53 * Network server for the LinuxSampler Control Protocol (LSCP).
54 */
55 class LSCPServer : public Thread {
56 public:
57 LSCPServer(Sampler* pSampler);
58
59 // Methods called by the parser
60 String CreateAudioOutputDevice(String Driver, std::map<String,String> Parameters);
61 String DestroyAudioOutputDevice(uint DeviceIndex);
62 String LoadInstrument(String Filename, uint uiInstrument, uint uiSamplerChannel);
63 String LoadEngine(String EngineName, uint uiSamplerChannel);
64 String GetChannels();
65 String AddChannel();
66 String RemoveChannel(uint uiSamplerChannel);
67 String GetAvailableEngines();
68 String GetEngineInfo(String EngineName);
69 String GetChannelInfo(uint uiSamplerChannel);
70 String GetVoiceCount(uint uiSamplerChannel);
71 String GetStreamCount(uint uiSamplerChannel);
72 String GetBufferFill(fill_response_t ResponseType, uint uiSamplerChannel);
73 String GetAvailableAudioOutputDrivers();
74 String GetAudioOutputDriverInfo(String Driver);
75 #ifdef __GNUC__
76 typedef std::map<String,String> StringMap; // nasty workaround for a GCC bug (see GCC bug #15980, #57)
77 String GetAudioOutputDriverParameterInfo(String Driver, String Parameter, std::map<String,String> DependencyList = StringMap());
78 #else
79 String GetAudioOutputDriverParameterInfo(String Driver, String Parameter, std::map<String,String> DependencyList = std::map<String,String>());
80 #endif // __GNUC__
81 String GetAudioOutputDeviceCount();
82 String GetAudioOutputDevices();
83 String GetAudioOutputDeviceInfo(uint DeviceIndex);
84 String GetAudioOutputChannelInfo(uint DeviceId, uint ChannelId);
85 String GetAudioOutputChannelParameterInfo(uint DeviceId, uint ChannelId, String ParameterName);
86 String SetAudioOutputChannelParameter(uint DeviceId, uint ChannelId, String ParamKey, String ParamVal);
87 String SetAudioOutputDeviceParameter(uint DeviceIndex, String ParamKey, String ParamVal);
88 String SetAudioOutputChannel(uint ChannelAudioOutputChannel, uint AudioOutputDeviceInputChannel, uint uiSamplerChannel);
89 String SetMIDIInputType(String MidiInputDriver, uint uiSamplerChannel);
90 String SetMIDIInputPort(String MIDIInputPort, uint uiSamplerchannel);
91 String SetMIDIInputChannel(uint MIDIChannel, uint uiSamplerChannel);
92 String SetAudioOutputDevice(uint AudioDeviceId, uint SamplerChannel);
93 String SetVolume(double Volume, uint uiSamplerChannel);
94 String ResetChannel(uint uiSamplerChannel);
95 String SubscribeNotification(uint UDPPort);
96 String UnsubscribeNotification(String SessionID);
97 void AnswerClient(String ReturnMessage);
98 protected:
99 int hSocket;
100 sockaddr_in SocketAddress;
101 Sampler* pSampler;
102
103 int Main(); ///< Implementation of virtual method from class Thread
104 private:
105 /**
106 * Converts a result_t structure into a valid LSCP answer message.
107 */
108 inline String ConvertResult(result_t result) {
109 switch (result.type) {
110 case result_type_success: {
111 return "OK\r\n";
112 }
113 case result_type_warning: {
114 std::stringstream ss;
115 ss << "WRN:" << result.code << ":" << result.message << "\r\n";
116 return ss.str();
117 }
118 case result_type_error: {
119 std::stringstream ss;
120 ss << "ERR:" << result.code << ":" << result.message << "\r\n";
121 return ss.str();
122 }
123 }
124 }
125
126 template<class T> inline String ToString(T o) {
127 std::stringstream ss;
128 ss << o;
129 return ss.str();
130 }
131 };
132
133 #endif // __LSCPSERVER_H_

  ViewVC Help
Powered by ViewVC