/[svn]/linuxsampler/trunk/src/network/lscp.y
ViewVC logotype

Contents of /linuxsampler/trunk/src/network/lscp.y

Parent Directory Parent Directory | Revision Log Revision Log


Revision 35 - (show annotations) (download)
Fri Mar 5 13:46:15 2004 UTC (20 years, 1 month ago) by schoenebeck
File size: 9353 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 /***************************************************************************
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 %{
24
25 #include "lscpparser.h"
26 #include "lscpserver.h"
27
28 // as we need an reentrant scanner, we have to pass the pointer to the scanner with each yylex() call
29 #define YYLEX_PARAM ((yyparse_param_t*) yyparse_param)->pScanner
30
31 // to save us typing work in the rules action definitions
32 #define LSCPSERVER ((yyparse_param_t*) yyparse_param)->pServer
33
34 // clears input buffer and restarts scanner.
35 void restart(yyparse_param_t* pparam, int& yychar);
36 #define RESTART restart((yyparse_param_t*) YYPARSE_PARAM, yychar)
37
38 // external reference to the main scanner function yylex()
39 extern YY_DECL;
40
41 // external reference to restart the lex scanner
42 extern void yyrestart(FILE* input_file, yyscan_t yyscanner);
43
44 // we provide our own version of yyerror() so we don't have to link against the yacc library
45 void yyerror(const char* s);
46
47 %}
48
49 // reentrant parser
50 %pure_parser
51
52 %token <Char> CHAR
53 %token <Dotnum> DOTNUM
54 %token <Number> NUMBER
55 %token SP LF CR
56 %token ADD GET LOAD REMOVE SET SUBSCRIBE UNSUBSCRIBE RESET QUIT
57 %token CHANNEL NOTIFICATION
58 %token AVAILABLE_ENGINES CHANNELS INFO BUFFER_FILL STREAM_COUNT VOICE_COUNT
59 %token INSTRUMENT ENGINE
60 %token AUDIO_OUTPUT_CHANNEL AUDIO_OUTPUT_TYPE MIDI_INPUT_PORT MIDI_INPUT_CHANNEL MIDI_INPUT_TYPE VOLUME
61 %token BYTES PERCENTAGE
62 %token ALSA JACK
63
64 %type <Dotnum> volume
65 %type <Number> sampler_channel instrument_index udp_port audio_output_channel midi_input_channel midi_input_type
66 %type <String> string alpha_num_string filename engine_name session_id midi_input_port command get_instruction load_instruction set_chan_instruction load_instr_args load_engine_args
67 %type <FillResponse> buffer_size_type
68 %type <AudioOutput> audio_output_type
69
70 %start input
71
72 %%
73
74 //TODO: return more meaningful error messages
75
76 input : line
77 | input LF line
78 | input CR LF line
79 ;
80
81 line : /* epsilon (empty line ignored) */
82 | command { LSCPSERVER->AnswerClient($1); }
83 | error { LSCPSERVER->AnswerClient("Err:0:Unknown command.\r\n"); RESTART; return LSCP_SYNTAX_ERROR; }
84 ;
85
86 command : ADD SP CHANNEL { $$ = LSCPSERVER->AddChannel(); }
87 | GET SP get_instruction { $$ = $3; }
88 | LOAD SP load_instruction { $$ = $3; }
89 | REMOVE SP CHANNEL SP sampler_channel { $$ = LSCPSERVER->RemoveChannel($5); }
90 | SET SP CHANNEL SP set_chan_instruction { $$ = $5; }
91 | SUBSCRIBE SP NOTIFICATION SP udp_port { $$ = LSCPSERVER->SubscribeNotification($5); }
92 | UNSUBSCRIBE SP NOTIFICATION SP session_id { $$ = LSCPSERVER->UnsubscribeNotification($5); }
93 | RESET SP CHANNEL SP sampler_channel { $$ = LSCPSERVER->ResetChannel($5); }
94 | QUIT { LSCPSERVER->AnswerClient("Bye!\r\n"); return 0; }
95 ;
96
97 get_instruction : AVAILABLE_ENGINES { $$ = LSCPSERVER->GetAvailableEngines(); }
98 | CHANNELS { $$ = LSCPSERVER->GetChannels(); }
99 | CHANNEL SP INFO SP sampler_channel { $$ = LSCPSERVER->GetChannelInfo($5); }
100 | CHANNEL SP BUFFER_FILL SP buffer_size_type SP sampler_channel { $$ = LSCPSERVER->GetBufferFill($5, $7); }
101 | CHANNEL SP STREAM_COUNT SP sampler_channel { $$ = LSCPSERVER->GetStreamCount($5); }
102 | CHANNEL SP VOICE_COUNT SP sampler_channel { $$ = LSCPSERVER->GetVoiceCount($5); }
103 | ENGINE SP INFO SP engine_name { $$ = LSCPSERVER->GetEngineInfo($5); }
104 ;
105
106 load_instruction : INSTRUMENT SP load_instr_args { $$ = $3; }
107 | ENGINE SP load_engine_args { $$ = $3; }
108 ;
109
110 set_chan_instruction : AUDIO_OUTPUT_CHANNEL SP sampler_channel SP audio_output_channel { $$ = LSCPSERVER->SetAudioOutputChannel($5, $3); }
111 | AUDIO_OUTPUT_TYPE SP sampler_channel SP audio_output_type { $$ = LSCPSERVER->SetAudioOutputType($5, $3); }
112 | MIDI_INPUT_PORT SP sampler_channel SP midi_input_port { $$ = LSCPSERVER->SetMIDIInputPort($5, $3); }
113 | MIDI_INPUT_CHANNEL SP sampler_channel SP midi_input_channel { $$ = LSCPSERVER->SetMIDIInputChannel($5, $3); }
114 | MIDI_INPUT_TYPE SP sampler_channel SP midi_input_type { $$ = "Err:0:Not implemented yet\r\n"; }
115 | VOLUME SP sampler_channel SP volume { $$ = LSCPSERVER->SetVolume($5, $3); }
116 ;
117
118 buffer_size_type : BYTES { $$ = fill_response_bytes; }
119 | PERCENTAGE { $$ = fill_response_percentage; }
120 ;
121
122 load_instr_args : filename SP instrument_index SP sampler_channel { $$ = LSCPSERVER->LoadInstrument($1, $3, $5); }
123 ;
124
125 load_engine_args : engine_name SP sampler_channel { $$ = LSCPSERVER->LoadEngine($1, $3); }
126 ;
127
128 audio_output_type : ALSA { $$ = audio_output_type_alsa; }
129 | JACK { $$ = audio_output_type_jack; }
130 ;
131
132 midi_input_type : ALSA { $$ = ALSA; }
133 ;
134
135 volume : DOTNUM
136 | NUMBER { $$ = $1; }
137 ;
138
139 sampler_channel : NUMBER
140 ;
141
142 instrument_index : NUMBER
143 ;
144
145 udp_port : NUMBER
146 ;
147
148 audio_output_channel : NUMBER
149 ;
150
151 midi_input_channel : NUMBER
152 ;
153
154 session_id : alpha_num_string
155 ;
156
157 engine_name : string
158 ;
159
160 midi_input_port : alpha_num_string
161 ;
162
163 filename : alpha_num_string
164 | filename SP alpha_num_string { $$ = $1 + ' ' + $3; }
165 ;
166
167 alpha_num_string : string { $$ = $1; }
168 | NUMBER { std::stringstream ss; ss << $1; $$ = ss.str(); }
169 | alpha_num_string string { $$ = $1 + $2; }
170 | alpha_num_string NUMBER { std::stringstream ss; ss << $1 << $2; $$ = ss.str(); }
171 ;
172
173 string : CHAR { std::string s; s = $1; $$ = s; }
174 | string CHAR { $$ = $1 + $2; }
175 ;
176
177 %%
178
179 /**
180 * Will be called when an error occured (usually syntax error).
181 */
182 void yyerror(const char* s) {
183 dmsg(2,("LSCPParser: %s\n", s));
184 }
185
186 /**
187 * Clears input buffer and restarts scanner.
188 */
189 void restart(yyparse_param_t* pparam, int& yychar) {
190 // restart scanner
191 yyrestart(stdin, pparam->pScanner);
192 // flush input buffer
193 static char buf[1024];
194 while(recv(hSession, buf, 1024, MSG_DONTWAIT) > 0);
195 // reset lookahead symbol
196 yyclearin;
197 }

  ViewVC Help
Powered by ViewVC