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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 35 - (hide annotations) (download) (as text)
Fri Mar 5 13:46:15 2004 UTC (20 years, 1 month ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 5083 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     #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 "lscpparser.h"
35     #include "../thread.h"
36     #include "../audiothread.h"
37    
38     /// TCP Port on which the server should listen for connection requests.
39     #define LSCP_PORT 8888
40    
41     /// 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).
42     extern int hSession;
43    
44     // External references to the main scanner and parser functions
45     extern int yyparse(void* YYPARSE_PARAM);
46     extern int yylex_init(yyscan_t* scanner);
47     extern int yylex_destroy(yyscan_t yyscanner);
48    
49     /**
50     * Network server for the LinuxSampler Control Protocol (LSCP).
51     */
52     class LSCPServer : public Thread {
53     public:
54     LSCPServer(AudioThread* pEngine);
55    
56     // Methods called by the parser
57     String LoadInstrument(String Filename, uint Instrument, uint SamplerChannel);
58     String LoadEngine(String EngineName, uint SamplerChannel);
59     String GetChannels();
60     String AddChannel();
61     String RemoveChannel(uint SamplerChannel);
62     String GetAvailableEngines();
63     String GetEngineInfo(String EngineName);
64     String GetChannelInfo(uint SamplerChannel);
65     String GetVoiceCount(uint SamplerChannel);
66     String GetStreamCount(uint SamplerChannel);
67     String GetBufferFill(fill_response_t ResponseType, uint SamplerChannel);
68     String SetAudioOutputType(audio_output_type_t AudioOutputType, uint SamplerChannel);
69     String SetAudioOutputChannel(uint AudioOutputChannel, uint SamplerChannel);
70     String SetMIDIInputPort(String MIDIInputPort, uint Samplerchannel);
71     String SetMIDIInputChannel(uint MIDIChannel, uint SamplerChannel);
72     String SetVolume(double Volume, uint SamplerChannel);
73     String ResetChannel(uint SamplerChannel);
74     String SubscribeNotification(uint UDPPort);
75     String UnsubscribeNotification(String SessionID);
76     void AnswerClient(String ReturnMessage);
77     protected:
78     int hSocket;
79     sockaddr_in SocketAddress;
80     AudioThread* pEngine; // FIXME: as long as we only have one engine...
81    
82     int Main(); ///< Implementation of virtual method from class Thread
83     private:
84     /**
85     * Converts a result_t structure into a valid LSCP answer message.
86     */
87     inline String ConvertResult(result_t result) {
88     switch (result.type) {
89     case result_type_success: {
90     return "OK\r\n";
91     }
92     case result_type_warning: {
93     std::stringstream ss;
94     ss << "WRN:" << result.code << ":" << result.message << "\r\n";
95     return ss.str();
96     }
97     case result_type_error: {
98     std::stringstream ss;
99     ss << "ERR:" << result.code << ":" << result.message << "\r\n";
100     return ss.str();
101     }
102     }
103     }
104    
105     inline String ToString(int i) {
106     std::stringstream ss;
107     ss << i;
108     return ss.str();
109     }
110    
111     inline String ToString(double d) {
112     std::stringstream ss;
113     ss << d;
114     return ss.str();
115     }
116     };
117    
118     #endif // __LSCPSERVER_H_

  ViewVC Help
Powered by ViewVC