/[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 155 - (show annotations) (download)
Mon Jun 28 04:30:11 2004 UTC (19 years, 9 months ago) by senkov
File size: 16779 byte(s)
* Updated parser, lscp server and sampler class for new MIDI_INPUT
* Minor fixes (and major new bugs) here and there
* Consolidated 3 SET CHANNEL MIDI_xxx commands into one:
SET CHANNEL MIDI_INPUT

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 %{
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 <String> STRINGVAL
56 %token SP LF CR HASH EQ
57 %token ADD GET CREATE DESTROY LIST LOAD NON_MODAL REMOVE SET SUBSCRIBE UNSUBSCRIBE RESET QUIT
58 %token CHANNEL NOTIFICATION
59 %token AVAILABLE_ENGINES AVAILABLE_AUDIO_OUTPUT_DRIVERS CHANNELS INFO BUFFER_FILL STREAM_COUNT VOICE_COUNT
60 %token INSTRUMENT ENGINE
61 %token AUDIO_OUTPUT_CHANNEL AUDIO_OUTPUT_CHANNEL_PARAMETER AUDIO_OUTPUT_DEVICE AUDIO_OUTPUT_DEVICES AUDIO_OUTPUT_DEVICE_PARAMETER AUDIO_OUTPUT_DRIVER AUDIO_OUTPUT_DRIVER_PARAMETER AUDIO_OUTPUT_TYPE MIDI_INPUT MIDI_INPUT_TYPE MIDI_INPUT_PORT MIDI_INPUT_CHANNEL VOLUME
62 %token MIDI_INPUT_DRIVER MIDI_INPUT_DRIVER_PARAMETER AVAILABLE_MIDI_INPUT_DRIVERS MIDI_INPUT_DEVICE MIDI_INPUT_DEVICES MIDI_INPUT_DEVICE_PARAMETER MIDI_INPUT_PORT_PARAMETER
63 %token BYTES PERCENTAGE
64 %token MISCELLANEOUS
65
66 %type <Dotnum> volume
67 %type <Number> sampler_channel instrument_index audio_output_channel midi_input_channel midi_input_port midi_input_device
68 %type <String> string param_val filename engine_name command create_instruction destroy_instruction get_instruction list_instruction load_instruction set_chan_instruction load_instr_args load_engine_args audio_output_type midi_input_type set_instruction subscribe_event unsubscribe_event
69 %type <FillResponse> buffer_size_type
70 %type <KeyValList> key_val_list
71
72 %start input
73
74 %%
75
76 //TODO: return more meaningful error messages
77
78 input : line
79 | input LF line
80 | input CR LF line
81 ;
82
83 line : /* epsilon (empty line ignored) */
84 | comment
85 | command { LSCPSERVER->AnswerClient($1); }
86 | error { LSCPSERVER->AnswerClient("Err:0:Unknown command.\r\n"); RESTART; return LSCP_SYNTAX_ERROR; }
87 ;
88
89 comment : HASH
90 | comment HASH
91 | comment SP
92 | comment NUMBER
93 | comment string
94 ;
95
96 command : ADD SP CHANNEL { $$ = LSCPSERVER->AddChannel(); }
97 | GET SP get_instruction { $$ = $3; }
98 | CREATE SP create_instruction { $$ = $3; }
99 | DESTROY SP destroy_instruction { $$ = $3; }
100 | LIST SP list_instruction { $$ = $3; }
101 | LOAD SP load_instruction { $$ = $3; }
102 | REMOVE SP CHANNEL SP sampler_channel { $$ = LSCPSERVER->RemoveChannel($5); }
103 | SET SP set_instruction { $$ = $3; }
104 | SUBSCRIBE SP subscribe_event { $$ = $3; }
105 | UNSUBSCRIBE SP unsubscribe_event { $$ = $3; }
106 | RESET SP CHANNEL SP sampler_channel { $$ = LSCPSERVER->ResetChannel($5); }
107 | QUIT { LSCPSERVER->AnswerClient("Bye!\r\n"); return 0; }
108 ;
109
110 subscribe_event : CHANNELS { $$ = LSCPSERVER->SubscribeNotification(event_channels); }
111 | VOICE_COUNT { $$ = LSCPSERVER->SubscribeNotification(event_voice_count); }
112 | STREAM_COUNT { $$ = LSCPSERVER->SubscribeNotification(event_stream_count); }
113 | BUFFER_FILL { $$ = LSCPSERVER->SubscribeNotification(event_channel_buffer_fill); }
114 | INFO { $$ = LSCPSERVER->SubscribeNotification(event_channel_info); }
115 | MISCELLANEOUS { $$ = LSCPSERVER->SubscribeNotification(event_misc); }
116 ;
117
118 unsubscribe_event : CHANNELS { $$ = LSCPSERVER->UnsubscribeNotification(event_channels); }
119 | VOICE_COUNT { $$ = LSCPSERVER->UnsubscribeNotification(event_voice_count); }
120 | STREAM_COUNT { $$ = LSCPSERVER->UnsubscribeNotification(event_stream_count); }
121 | BUFFER_FILL { $$ = LSCPSERVER->UnsubscribeNotification(event_channel_buffer_fill); }
122 | INFO { $$ = LSCPSERVER->UnsubscribeNotification(event_channel_info); }
123 | MISCELLANEOUS { $$ = LSCPSERVER->UnsubscribeNotification(event_misc); }
124 ;
125
126 get_instruction : AVAILABLE_ENGINES { $$ = LSCPSERVER->GetAvailableEngines(); }
127 | AVAILABLE_MIDI_INPUT_DRIVERS { $$ = LSCPSERVER->GetAvailableMidiInputDrivers(); }
128 | MIDI_INPUT_DRIVER SP INFO SP string { $$ = LSCPSERVER->GetMidiInputDriverInfo($5); }
129 | MIDI_INPUT_DRIVER_PARAMETER SP INFO SP string SP string { $$ = LSCPSERVER->GetMidiInputDriverParameterInfo($5, $7); }
130 | MIDI_INPUT_DRIVER_PARAMETER SP INFO SP string SP string SP key_val_list { $$ = LSCPSERVER->GetMidiInputDriverParameterInfo($5, $7, $9); }
131 | AVAILABLE_AUDIO_OUTPUT_DRIVERS { $$ = LSCPSERVER->GetAvailableAudioOutputDrivers(); }
132 | AUDIO_OUTPUT_DRIVER SP INFO SP string { $$ = LSCPSERVER->GetAudioOutputDriverInfo($5); }
133 | AUDIO_OUTPUT_DRIVER_PARAMETER SP INFO SP string SP string { $$ = LSCPSERVER->GetAudioOutputDriverParameterInfo($5, $7); }
134 | AUDIO_OUTPUT_DRIVER_PARAMETER SP INFO SP string SP string SP key_val_list { $$ = LSCPSERVER->GetAudioOutputDriverParameterInfo($5, $7, $9); }
135 | AUDIO_OUTPUT_DEVICES { $$ = LSCPSERVER->GetAudioOutputDeviceCount(); }
136 | MIDI_INPUT_DEVICES { $$ = LSCPSERVER->GetMidiInputDeviceCount(); }
137 | AUDIO_OUTPUT_DEVICE SP INFO SP NUMBER { $$ = LSCPSERVER->GetAudioOutputDeviceInfo($5); }
138 | MIDI_INPUT_DEVICE SP INFO SP NUMBER { $$ = LSCPSERVER->GetMidiInputDeviceInfo($5); }
139 | MIDI_INPUT_PORT SP INFO SP NUMBER SP NUMBER { $$ = LSCPSERVER->GetMidiInputPortInfo($5, $7); }
140 | AUDIO_OUTPUT_CHANNEL SP INFO SP NUMBER SP NUMBER { $$ = LSCPSERVER->GetAudioOutputChannelInfo($5, $7); }
141 | AUDIO_OUTPUT_CHANNEL_PARAMETER SP INFO SP NUMBER SP NUMBER SP string { $$ = LSCPSERVER->GetAudioOutputChannelParameterInfo($5, $7, $9); }
142 | CHANNELS { $$ = LSCPSERVER->GetChannels(); }
143 | CHANNEL SP INFO SP sampler_channel { $$ = LSCPSERVER->GetChannelInfo($5); }
144 | CHANNEL SP BUFFER_FILL SP buffer_size_type SP sampler_channel { $$ = LSCPSERVER->GetBufferFill($5, $7); }
145 | CHANNEL SP STREAM_COUNT SP sampler_channel { $$ = LSCPSERVER->GetStreamCount($5); }
146 | CHANNEL SP VOICE_COUNT SP sampler_channel { $$ = LSCPSERVER->GetVoiceCount($5); }
147 | ENGINE SP INFO SP engine_name { $$ = LSCPSERVER->GetEngineInfo($5); }
148 ;
149
150 set_instruction : AUDIO_OUTPUT_DEVICE_PARAMETER SP NUMBER SP string EQ param_val { $$ = LSCPSERVER->SetAudioOutputDeviceParameter($3, $5, $7); }
151 | AUDIO_OUTPUT_CHANNEL_PARAMETER SP NUMBER SP NUMBER SP string EQ param_val { $$ = LSCPSERVER->SetAudioOutputChannelParameter($3, $5, $7, $9); }
152 | MIDI_INPUT_DEVICE_PARAMETER SP NUMBER SP string EQ param_val { $$ = LSCPSERVER->SetMidiInputDeviceParameter($3, $5, $7); }
153 | MIDI_INPUT_PORT_PARAMETER SP NUMBER SP NUMBER SP string EQ param_val { $$ = LSCPSERVER->SetMidiInputPortParameter($3, $5, $7, $9); }
154 | CHANNEL SP set_chan_instruction { $$ = $3; }
155 ;
156
157 create_instruction : AUDIO_OUTPUT_DEVICE SP string SP key_val_list { $$ = LSCPSERVER->CreateAudioOutputDevice($3,$5); }
158 | AUDIO_OUTPUT_DEVICE SP string { $$ = LSCPSERVER->CreateAudioOutputDevice($3); }
159 | MIDI_INPUT_DEVICE SP string { $$ = LSCPSERVER->CreateMidiInputDevice($3); }
160 ;
161
162 destroy_instruction : AUDIO_OUTPUT_DEVICE SP NUMBER { $$ = LSCPSERVER->DestroyAudioOutputDevice($3); }
163 | MIDI_INPUT_DEVICE SP NUMBER { $$ = LSCPSERVER->DestroyMidiInputDevice($3); }
164 ;
165
166 load_instruction : INSTRUMENT SP load_instr_args { $$ = $3; }
167 | ENGINE SP load_engine_args { $$ = $3; }
168 ;
169
170 set_chan_instruction : AUDIO_OUTPUT_DEVICE SP sampler_channel SP NUMBER { $$ = LSCPSERVER->SetAudioOutputDevice($5, $3); }
171 | AUDIO_OUTPUT_CHANNEL SP sampler_channel SP audio_output_channel SP audio_output_channel { $$ = LSCPSERVER->SetAudioOutputChannel($5, $7, $3); }
172 | AUDIO_OUTPUT_TYPE SP sampler_channel SP audio_output_type { $$ = LSCPSERVER->SetAudioOutputType($5, $3); }
173 | MIDI_INPUT SP sampler_channel SP midi_input_device SP midi_input_port SP midi_input_channel { $$ = LSCPSERVER->SetMIDIInput($5, $7, $9, $3); }
174 | MIDI_INPUT_TYPE SP sampler_channel SP midi_input_type { $$ = LSCPSERVER->SetMIDIInputType($5, $3); }
175 | VOLUME SP sampler_channel SP volume { $$ = LSCPSERVER->SetVolume($5, $3); }
176 ;
177
178 key_val_list : string EQ param_val { $$[$1] = $3; }
179 | key_val_list SP string EQ param_val { $$ = $1; $$[$3] = $5; }
180 ;
181
182 buffer_size_type : BYTES { $$ = fill_response_bytes; }
183 | PERCENTAGE { $$ = fill_response_percentage; }
184 ;
185
186 list_instruction : AUDIO_OUTPUT_DEVICES { $$ = LSCPSERVER->GetAudioOutputDevices(); }
187 | MIDI_INPUT_DEVICES { $$ = LSCPSERVER->GetMidiInputDevices(); }
188 ;
189
190 load_instr_args : filename SP instrument_index SP sampler_channel { $$ = LSCPSERVER->LoadInstrument($1, $3, $5); }
191 | NON_MODAL SP filename SP instrument_index SP sampler_channel { $$ = LSCPSERVER->LoadInstrument($3, $5, $7, true); }
192 ;
193
194 load_engine_args : engine_name SP sampler_channel { $$ = LSCPSERVER->LoadEngine($1, $3); }
195 ;
196
197 audio_output_type : string
198 ;
199
200 midi_input_device : NUMBER
201 ;
202
203 midi_input_port : NUMBER
204 ;
205
206 midi_input_channel : NUMBER
207 ;
208
209 midi_input_type : string
210 ;
211
212 volume : DOTNUM
213 | NUMBER { $$ = $1; }
214 ;
215
216 sampler_channel : NUMBER
217 ;
218
219 instrument_index : NUMBER
220 ;
221
222 audio_output_channel : NUMBER
223 ;
224
225 engine_name : string
226 ;
227
228 filename : STRINGVAL
229 | string
230 ;
231
232 param_val : STRINGVAL { $$ = $1; }
233 | NUMBER { std::stringstream ss; ss << $1; $$ = ss.str(); }
234 | DOTNUM { std::stringstream ss; ss << $1; $$ = ss.str(); }
235 ;
236
237 string : CHAR { std::string s; s = $1; $$ = s; }
238 | string CHAR { $$ = $1 + $2; }
239 ;
240
241 %%
242
243 /**
244 * Will be called when an error occured (usually syntax error).
245 */
246 void yyerror(const char* s) {
247 dmsg(2,("LSCPParser: %s\n", s));
248 }
249
250 /**
251 * Clears input buffer and restarts scanner.
252 */
253 void restart(yyparse_param_t* pparam, int& yychar) {
254 // restart scanner
255 yyrestart(stdin, pparam->pScanner);
256 // flush input buffer
257 static char buf[1024];
258 while(recv(hSession, buf, 1024, MSG_DONTWAIT) > 0);
259 // reset lookahead symbol
260 yyclearin;
261 }

  ViewVC Help
Powered by ViewVC