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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 111 - (hide annotations) (download)
Sat Jun 5 20:55:50 2004 UTC (19 years, 10 months ago) by schoenebeck
File size: 9652 byte(s)
* LSCP allows now comment lines, that is lines starting with a hash ('#')
  character
* src/engines/gig/Voice.cpp: fixed "SET CHANNEL VOLUME" bug

1 schoenebeck 35 /***************************************************************************
2     * *
3     * LinuxSampler - modular, streaming capable sampler *
4     * *
5 schoenebeck 56 * Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck *
6 schoenebeck 35 * *
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 schoenebeck 111 %token SP LF CR HASH
56 schoenebeck 35 %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 schoenebeck 53 %type <Number> sampler_channel instrument_index udp_port audio_output_channel midi_input_channel
66 schoenebeck 35 %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 schoenebeck 53 %type <MidiInput> midi_input_type
70 schoenebeck 35
71     %start input
72    
73     %%
74    
75     //TODO: return more meaningful error messages
76    
77     input : line
78     | input LF line
79     | input CR LF line
80     ;
81    
82     line : /* epsilon (empty line ignored) */
83 schoenebeck 111 | comment
84 schoenebeck 35 | command { LSCPSERVER->AnswerClient($1); }
85     | error { LSCPSERVER->AnswerClient("Err:0:Unknown command.\r\n"); RESTART; return LSCP_SYNTAX_ERROR; }
86     ;
87    
88 schoenebeck 111 comment : HASH
89     | comment HASH
90     | comment SP
91     | comment NUMBER
92     | comment string
93     ;
94    
95 schoenebeck 35 command : ADD SP CHANNEL { $$ = LSCPSERVER->AddChannel(); }
96     | GET SP get_instruction { $$ = $3; }
97     | LOAD SP load_instruction { $$ = $3; }
98     | REMOVE SP CHANNEL SP sampler_channel { $$ = LSCPSERVER->RemoveChannel($5); }
99     | SET SP CHANNEL SP set_chan_instruction { $$ = $5; }
100     | SUBSCRIBE SP NOTIFICATION SP udp_port { $$ = LSCPSERVER->SubscribeNotification($5); }
101     | UNSUBSCRIBE SP NOTIFICATION SP session_id { $$ = LSCPSERVER->UnsubscribeNotification($5); }
102     | RESET SP CHANNEL SP sampler_channel { $$ = LSCPSERVER->ResetChannel($5); }
103     | QUIT { LSCPSERVER->AnswerClient("Bye!\r\n"); return 0; }
104     ;
105    
106     get_instruction : AVAILABLE_ENGINES { $$ = LSCPSERVER->GetAvailableEngines(); }
107     | CHANNELS { $$ = LSCPSERVER->GetChannels(); }
108     | CHANNEL SP INFO SP sampler_channel { $$ = LSCPSERVER->GetChannelInfo($5); }
109     | CHANNEL SP BUFFER_FILL SP buffer_size_type SP sampler_channel { $$ = LSCPSERVER->GetBufferFill($5, $7); }
110     | CHANNEL SP STREAM_COUNT SP sampler_channel { $$ = LSCPSERVER->GetStreamCount($5); }
111     | CHANNEL SP VOICE_COUNT SP sampler_channel { $$ = LSCPSERVER->GetVoiceCount($5); }
112     | ENGINE SP INFO SP engine_name { $$ = LSCPSERVER->GetEngineInfo($5); }
113     ;
114    
115     load_instruction : INSTRUMENT SP load_instr_args { $$ = $3; }
116     | ENGINE SP load_engine_args { $$ = $3; }
117     ;
118    
119     set_chan_instruction : AUDIO_OUTPUT_CHANNEL SP sampler_channel SP audio_output_channel { $$ = LSCPSERVER->SetAudioOutputChannel($5, $3); }
120     | AUDIO_OUTPUT_TYPE SP sampler_channel SP audio_output_type { $$ = LSCPSERVER->SetAudioOutputType($5, $3); }
121     | MIDI_INPUT_PORT SP sampler_channel SP midi_input_port { $$ = LSCPSERVER->SetMIDIInputPort($5, $3); }
122     | MIDI_INPUT_CHANNEL SP sampler_channel SP midi_input_channel { $$ = LSCPSERVER->SetMIDIInputChannel($5, $3); }
123 schoenebeck 53 | MIDI_INPUT_TYPE SP sampler_channel SP midi_input_type { $$ = LSCPSERVER->SetMIDIInputType($5, $3); }
124 schoenebeck 35 | VOLUME SP sampler_channel SP volume { $$ = LSCPSERVER->SetVolume($5, $3); }
125     ;
126    
127     buffer_size_type : BYTES { $$ = fill_response_bytes; }
128     | PERCENTAGE { $$ = fill_response_percentage; }
129     ;
130    
131     load_instr_args : filename SP instrument_index SP sampler_channel { $$ = LSCPSERVER->LoadInstrument($1, $3, $5); }
132     ;
133    
134     load_engine_args : engine_name SP sampler_channel { $$ = LSCPSERVER->LoadEngine($1, $3); }
135     ;
136    
137 schoenebeck 64 audio_output_type : ALSA { $$ = AudioOutputDevice::type_alsa; }
138     | JACK { $$ = AudioOutputDevice::type_jack; }
139 schoenebeck 35 ;
140    
141 schoenebeck 64 midi_input_type : ALSA { $$ = MidiInputDevice::type_alsa; }
142 schoenebeck 35 ;
143    
144     volume : DOTNUM
145     | NUMBER { $$ = $1; }
146     ;
147    
148     sampler_channel : NUMBER
149     ;
150    
151     instrument_index : NUMBER
152     ;
153    
154     udp_port : NUMBER
155     ;
156    
157     audio_output_channel : NUMBER
158     ;
159    
160     midi_input_channel : NUMBER
161     ;
162    
163     session_id : alpha_num_string
164     ;
165    
166     engine_name : string
167     ;
168    
169     midi_input_port : alpha_num_string
170     ;
171    
172     filename : alpha_num_string
173     | filename SP alpha_num_string { $$ = $1 + ' ' + $3; }
174     ;
175    
176     alpha_num_string : string { $$ = $1; }
177     | NUMBER { std::stringstream ss; ss << $1; $$ = ss.str(); }
178     | alpha_num_string string { $$ = $1 + $2; }
179     | alpha_num_string NUMBER { std::stringstream ss; ss << $1 << $2; $$ = ss.str(); }
180     ;
181    
182     string : CHAR { std::string s; s = $1; $$ = s; }
183     | string CHAR { $$ = $1 + $2; }
184     ;
185    
186     %%
187    
188     /**
189     * Will be called when an error occured (usually syntax error).
190     */
191     void yyerror(const char* s) {
192     dmsg(2,("LSCPParser: %s\n", s));
193     }
194    
195     /**
196     * Clears input buffer and restarts scanner.
197     */
198     void restart(yyparse_param_t* pparam, int& yychar) {
199     // restart scanner
200     yyrestart(stdin, pparam->pScanner);
201     // flush input buffer
202     static char buf[1024];
203     while(recv(hSession, buf, 1024, MSG_DONTWAIT) > 0);
204     // reset lookahead symbol
205     yyclearin;
206     }

  ViewVC Help
Powered by ViewVC