/[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 123 - (hide annotations) (download)
Mon Jun 14 19:33:16 2004 UTC (19 years, 10 months ago) by schoenebeck
File size: 13305 byte(s)
* src/common: added template class 'optional<>' which can be used e.g. as
  return type whenever a value might be returned, but don't has to; this
  template class pretty much acts like a pointer of the given type, but is
  much more safer than a simple pointer
* src/audiodriver: added static class AudioDeviceFactory to create audio
  devices at runtime by using a string and to obtain driver informations
  of drivers at runtime, driver classes should simply use the macro
  REGISTER_AUDIO_OUTPUT_DRIVER(DriverName,DriverClass) in their cpp file
  to register the driver to LinuxSampler (no changes needed anymore in the
  LS code to add a new audio output driver)
* src/drivers: added classes to dynamically manage driver parameters; there
  are two different kinds of parameters: parameters which are need to
  create a new device (DeviceCreationParameterX) used to e.g. create an
  audio output device or a MIDI input device and parameters which are only
  available at runtime, means when a device is already created
  (DeviceRuntimeParameterX) which will be e.g. used as audio channel
  parameters and MIDI port parameters
* src/linuxsampler.cpp: all registered audio output drivers will be shown
  on the console on startup
* src/network: implemented configuration of audio output devices via LSCP

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

  ViewVC Help
Powered by ViewVC