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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 35 - (hide annotations) (download)
Fri Mar 5 13:46:15 2004 UTC (20 years ago) by schoenebeck
File size: 9714 byte(s)
* implemented parser for the LinuxSampler control protocol (LSCP) by using
  flex / bison (where src/network/lscp.l is the input file for lex / flex
  and src/network/lscp.y is the input file for yacc / bison), parser and
  scanner can be regenerated by 'make parser'
* implemented LSCP network server (only single threaded so far), LSCP
  server will be launched if LinuxSampler was started with "--server" flag,
  implemented the following LSCP commands so far: "LOAD INSTRUMENT", "GET
  CHANNEL VOICE_COUNT", "GET CHANNEL STREAM_COUNT", "GET CHANNEL
  BUFFER_FILL", "SET CHANNEL VOLUME" and "RESET CHANNEL"
* disk thread now started within the engine

1 schoenebeck 35 /***************************************************************************
2     * *
3     * LinuxSampler - modular, streaming capable sampler *
4     * *
5     * Copyright (C) 2003 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     #include "lscpserver.h"
24    
25     LSCPServer::LSCPServer(AudioThread* pEngine) : Thread(false, 0, -4) {
26     this->pEngine = pEngine;
27     }
28    
29     int LSCPServer::Main() {
30     hSocket = socket(AF_INET, SOCK_STREAM, 0);
31     if (hSocket < 0) {
32     std::cerr << "LSCPServer: Could not create server socket." << std::endl;
33     return -1;
34     }
35    
36     SocketAddress.sin_family = AF_INET;
37     SocketAddress.sin_port = htons(LSCP_PORT);
38     SocketAddress.sin_addr.s_addr = htonl(INADDR_ANY);
39    
40     if (bind(hSocket, (sockaddr*) &SocketAddress, sizeof(sockaddr_in)) < 0) {
41     std::cerr << "LSCPServer: Could not bind server socket." << std::endl;
42     close(hSocket);
43     return -1;
44     }
45    
46     listen(hSocket, 1);
47     dmsg(1,("LSCPServer: Server running.\n")); // server running
48    
49     // now wait for client connections and handle their requests
50     sockaddr_in client;
51     int length = sizeof(client);
52     while (true) {
53     hSession = accept(hSocket, (sockaddr*) &client, (socklen_t*) &length);
54     if (hSession < 0) {
55     std::cerr << "LSCPServer: Client connection failed." << std::endl;
56     close(hSocket);
57     return -1;
58     }
59    
60     dmsg(1,("LSCPServer: Client connection established.\n"));
61     //send(hSession, "Welcome!\r\n", 10, 0);
62    
63     // Parser invocation
64     yyparse_param_t yyparse_param;
65     yyparse_param.pServer = this;
66     yylex_init(&yyparse_param.pScanner);
67     while (yyparse(&yyparse_param) == LSCP_SYNTAX_ERROR); // recall parser in case of syntax error
68     yylex_destroy(yyparse_param.pScanner);
69    
70     close(hSession);
71     dmsg(1,("LSCPServer: Client connection terminated.\n"));
72     }
73     }
74    
75     /**
76     * Will be called by the parser whenever it wants to send an answer to the
77     * client / frontend.
78     *
79     * @param ReturnMessage - message that will be send to the client
80     */
81     void LSCPServer::AnswerClient(String ReturnMessage) {
82     dmsg(2,("LSCPServer::AnswerClient(ReturnMessage=%s)", ReturnMessage.c_str()));
83     send(hSession, ReturnMessage.c_str(), ReturnMessage.size(), 0);
84     }
85    
86     /**
87     * Will be called by the parser to load an instrument.
88     */
89     String LSCPServer::LoadInstrument(String Filename, uint Instrument, uint SamplerChannel) {
90     dmsg(2,("LSCPServer: LoadInstrument(Filename=%s,Instrument=%d,SamplerChannel=%d)\n", Filename.c_str(), Instrument, SamplerChannel));
91     result_t res = pEngine->LoadInstrument(Filename.c_str(), Instrument);
92     return ConvertResult(res);
93     }
94    
95     /**
96     * Will be called by the parser to load and deploy an engine.
97     */
98     String LSCPServer::LoadEngine(String EngineName, uint SamplerChannel) {
99     dmsg(2,("LSCPServer: LoadEngine(EngineName=%s,SamplerChannel=%d)\n", EngineName.c_str(), SamplerChannel));
100     return "ERR:0:Not implemented yet.\r\n";
101     }
102    
103     /**
104     * Will be called by the parser to get the amount of sampler channels.
105     */
106     String LSCPServer::GetChannels() {
107     dmsg(2,("LSCPServer: GetChannels()\n"));
108     return "1\r\n";
109     }
110    
111     /**
112     * Will be called by the parser to add a sampler channel.
113     */
114     String LSCPServer::AddChannel() {
115     dmsg(2,("LSCPServer: AddChannel()\n"));
116     return "ERR:0:Not implemented yet.\r\n";
117     }
118    
119     /**
120     * Will be called by the parser to remove a sampler channel.
121     */
122     String LSCPServer::RemoveChannel(uint SamplerChannel) {
123     dmsg(2,("LSCPServer: RemoveChannel(SamplerChannel=%d)\n", SamplerChannel));
124     return "ERR:0:Not implemented yet.\r\n";
125     }
126    
127     /**
128     * Will be called by the parser to get all available engines.
129     */
130     String LSCPServer::GetAvailableEngines() {
131     dmsg(2,("LSCPServer: GetAvailableEngines()\n"));
132     return "ERR:0:Not implemented yet.\r\n";
133     }
134    
135     /**
136     * Will be called by the parser to get descriptions for a particular engine.
137     */
138     String LSCPServer::GetEngineInfo(String EngineName) {
139     dmsg(2,("LSCPServer: GetEngineInfo(EngineName=%s)\n", EngineName.c_str()));
140     return "ERR:0:Not implemented yet.\r\n";
141     }
142    
143     /**
144     * Will be called by the parser to get informations about a particular
145     * sampler channel.
146     */
147     String LSCPServer::GetChannelInfo(uint SamplerChannel) {
148     dmsg(2,("LSCPServer: GetChannelInfo(SamplerChannel=%d)\n", SamplerChannel));
149     return "ERR:0:Not implemented yet.\r\n";
150     }
151    
152     /**
153     * Will be called by the parser to get the amount of active voices on a
154     * particular sampler channel.
155     */
156     String LSCPServer::GetVoiceCount(uint SamplerChannel) {
157     dmsg(2,("LSCPServer: GetVoiceCount(SamplerChannel=%d)\n", SamplerChannel));
158     return ToString(pEngine->ActiveVoiceCount) + "\r\n";
159     }
160    
161     /**
162     * Will be called by the parser to get the amount of active disk streams on a
163     * particular sampler channel.
164     */
165     String LSCPServer::GetStreamCount(uint SamplerChannel) {
166     dmsg(2,("LSCPServer: GetStreamCount(SamplerChannel=%d)\n", SamplerChannel));
167     return ToString(pEngine->pDiskThread->ActiveStreamCount) + "\r\n";
168     }
169    
170     /**
171     * Will be called by the parser to get the buffer fill states of all disk
172     * streams on a particular sampler channel.
173     */
174     String LSCPServer::GetBufferFill(fill_response_t ResponseType, uint SamplerChannel) {
175     dmsg(2,("LSCPServer: GetBufferFill(ResponseType=%d, SamplerChannel=%d)\n", ResponseType, SamplerChannel));
176     return (ResponseType == fill_response_bytes) ? pEngine->pDiskThread->GetBufferFillBytes() + "\r\n"
177     : pEngine->pDiskThread->GetBufferFillPercentage() + "\r\n";
178     }
179    
180     /**
181     * Will be called by the parser to change the audio output type on a
182     * particular sampler channel.
183     */
184     String LSCPServer::SetAudioOutputType(audio_output_type_t AudioOutputType, uint SamplerChannel) {
185     dmsg(2,("LSCPServer: SetAudioOutputType(AudioOutputType=%d, SamplerChannel=%d)\n", AudioOutputType, SamplerChannel));
186     return "ERR:0:Not implemented yet.\r\n";
187     }
188    
189     /**
190     * Will be called by the parser to change the audio output channel for
191     * playback on a particular sampler channel.
192     */
193     String LSCPServer::SetAudioOutputChannel(uint AudioOutputChannel, uint SamplerChannel) {
194     dmsg(2,("LSCPServer: SetAudioOutputChannel(AudioOutputChannel=%d, SamplerChannel=%d)\n", AudioOutputChannel, SamplerChannel));
195     return "ERR:0:Not implemented yet.\r\n";
196     }
197    
198     /**
199     * Will be called by the parser to change the MIDI input port on which the
200     * engine of a particular sampler channel should listen to.
201     */
202     String LSCPServer::SetMIDIInputPort(String MIDIInputPort, uint Samplerchannel) {
203     dmsg(2,("LSCPServer: SetMIDIInputPort(MIDIInputPort=%s, Samplerchannel=%d)\n", MIDIInputPort.c_str(), Samplerchannel));
204     return "ERR:0:Not implemented yet.\r\n";
205     }
206    
207     /**
208     * Will be called by the parser to change the MIDI input channel on which the
209     * engine of a particular sampler channel should listen to.
210     */
211     String LSCPServer::SetMIDIInputChannel(uint MIDIChannel, uint SamplerChannel) {
212     dmsg(2,("LSCPServer: SetMIDIInputChannel(MIDIChannel=%d, SamplerChannel=%d)\n", MIDIChannel, SamplerChannel));
213     return "ERR:0:Not implemented yet.\r\n";
214     }
215    
216     /**
217     * Will be called by the parser to change the global volume factor on a
218     * particular sampler channel.
219     */
220     String LSCPServer::SetVolume(double Volume, uint SamplerChannel) {
221     dmsg(2,("LSCPServer: SetVolume(Volume=%f, SamplerChannel=%d)\n", Volume, SamplerChannel));
222     pEngine->Volume = Volume;
223     return "OK\r\n";
224     }
225    
226     /**
227     * Will be called by the parser to reset a particular sampler channel.
228     */
229     String LSCPServer::ResetChannel(uint SamplerChannel) {
230     dmsg(2,("LSCPServer: ResetChannel(SamplerChannel=%d)\n", SamplerChannel));
231     pEngine->Reset();
232     return "OK\r\n";
233     }
234    
235     /**
236     * Will be called by the parser to subscribe a client (frontend) on the
237     * server for receiving event messages.
238     */
239     String LSCPServer::SubscribeNotification(uint UDPPort) {
240     dmsg(2,("LSCPServer: SubscribeNotification(UDPPort=%d)\n", UDPPort));
241     return "ERR:0:Not implemented yet.\r\n";
242     }
243    
244     /**
245     * Will be called by the parser to unsubscribe a client on the server
246     * for not receiving further event messages.
247     */
248     String LSCPServer::UnsubscribeNotification(String SessionID) {
249     dmsg(2,("LSCPServer: UnsubscribeNotification(SessionID=%s)\n", SessionID.c_str()));
250     return "ERR:0:Not implemented yet.\r\n";
251     }

  ViewVC Help
Powered by ViewVC