/[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 143 - (show annotations) (download) (as text)
Wed Jun 23 18:54:08 2004 UTC (19 years, 10 months ago) by capela
File MIME type: text/x-c++hdr
File size: 7160 byte(s)
* SET CHANNEL AUDIO_OUTPUT_TYPE <chan> <driver> command is back!
  creates an audio output device instance of the given driver type
  ('Jack' or 'Alsa') with default parameters if none exists,
  otherwise it just picks the first available device and assign
  it to the intended sampler channel.

* The AudioOutputDevice class get's a new pure virtual method,
  Driver(), which is implemented on both of the existing inherited
  classes, AudioOutputDeviceAlsa and AudioOutputDeviceJack, with
  the sole purpose to return the driver type name as a String
  ('Alsa' and 'Jack', respectively).

* The quoting on the filename argument for the LOAD INSTRUMENT
  command has been made optional; you can have both ways, with
  single quotes or none, keeping compability with older LSCP
  specification.

* An additional sanity check is made on LOAD INSTRUMENT, whether
  the sampler channel has an audio output device assigned, thus
  preventing the server from crashing on instrument file load.

* The GET AUDIO_OUTPUT_DEVICE INFO now includes the missing
  'driver' item, as predicted by the draft protocol document.

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 DestroyAudioOutputDevice(uint DeviceIndex);
61 String LoadInstrument(String Filename, uint uiInstrument, uint uiSamplerChannel, bool bBackground = false);
62 String LoadEngine(String EngineName, uint uiSamplerChannel);
63 String GetChannels();
64 String AddChannel();
65 String RemoveChannel(uint uiSamplerChannel);
66 String GetAvailableEngines();
67 String GetEngineInfo(String EngineName);
68 String GetChannelInfo(uint uiSamplerChannel);
69 String GetVoiceCount(uint uiSamplerChannel);
70 String GetStreamCount(uint uiSamplerChannel);
71 String GetBufferFill(fill_response_t ResponseType, uint uiSamplerChannel);
72 String GetAvailableAudioOutputDrivers();
73 String GetAudioOutputDriverInfo(String Driver);
74 #ifdef __GNUC__
75 typedef std::map<String,String> StringMap; // nasty workaround for a GCC bug (see GCC bug #15980, #57)
76 String GetAudioOutputDriverParameterInfo(String Driver, String Parameter, std::map<String,String> DependencyList = StringMap());
77 String CreateAudioOutputDevice(String Driver, std::map<String,String> Parameters = StringMap());
78 #else
79 String GetAudioOutputDriverParameterInfo(String Driver, String Parameter, std::map<String,String> DependencyList = std::map<String,String>());
80 String CreateAudioOutputDevice(String Driver, std::map<String,String> Parameters = std::map<String,String>());
81 #endif // __GNUC__
82 String GetAudioOutputDeviceCount();
83 String GetAudioOutputDevices();
84 String GetAudioOutputDeviceInfo(uint DeviceIndex);
85 String GetAudioOutputChannelInfo(uint DeviceId, uint ChannelId);
86 String GetAudioOutputChannelParameterInfo(uint DeviceId, uint ChannelId, String ParameterName);
87 String SetAudioOutputChannelParameter(uint DeviceId, uint ChannelId, String ParamKey, String ParamVal);
88 String SetAudioOutputDeviceParameter(uint DeviceIndex, String ParamKey, String ParamVal);
89 String SetAudioOutputChannel(uint ChannelAudioOutputChannel, uint AudioOutputDeviceInputChannel, uint uiSamplerChannel);
90 String SetAudioOutputType(String AudioOutputDriver, uint uiSamplerChannel);
91 String SetMIDIInputType(String MidiInputDriver, uint uiSamplerChannel);
92 String SetMIDIInputPort(String MIDIInputPort, uint uiSamplerchannel);
93 String SetMIDIInputChannel(uint MIDIChannel, uint uiSamplerChannel);
94 String SetAudioOutputDevice(uint AudioDeviceId, uint SamplerChannel);
95 String SetVolume(double Volume, uint uiSamplerChannel);
96 String ResetChannel(uint uiSamplerChannel);
97 String SubscribeNotification(event_t Event);
98 String UnsubscribeNotification(event_t Event);
99 void AnswerClient(String ReturnMessage);
100 protected:
101 int hSocket;
102 sockaddr_in SocketAddress;
103 Sampler* pSampler;
104
105 int Main(); ///< Implementation of virtual method from class Thread
106 private:
107
108 /**
109 * Find a created audio output device index.
110 */
111 int GetAudioOutputDeviceIndex (AudioOutputDevice *pDevice);
112
113 /**
114 * Converts a result_t structure into a valid LSCP answer message.
115 */
116 inline String ConvertResult(result_t result) {
117 switch (result.type) {
118 case result_type_success: {
119 return "OK\r\n";
120 }
121 case result_type_warning: {
122 std::stringstream ss;
123 ss << "WRN:" << result.code << ":" << result.message << "\r\n";
124 return ss.str();
125 }
126 case result_type_error: {
127 std::stringstream ss;
128 ss << "ERR:" << result.code << ":" << result.message << "\r\n";
129 return ss.str();
130 }
131 }
132 }
133
134 template<class T> inline String ToString(T o) {
135 std::stringstream ss;
136 ss << o;
137 return ss.str();
138 }
139 };
140
141
142 /**
143 * Instrument loader thread for the LinuxSampler Control Protocol (LSCP).
144 */
145 class LSCPLoadInstrument : public Thread {
146
147 public:
148 LSCPLoadInstrument(Engine* pEngine, String Filename, uint uiInstrument);
149
150 protected:
151 // Instance variables.
152 Engine* pEngine;
153 String Filename;
154 uint uiInstrument;
155
156 // Implementation of virtual method from class Thread.
157 int Main();
158 };
159
160 #endif // __LSCPSERVER_H_

  ViewVC Help
Powered by ViewVC