/[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 53 - (hide annotations) (download)
Mon Apr 26 17:15:51 2004 UTC (19 years, 11 months ago) by schoenebeck
File size: 9387 byte(s)
* completely restructured source tree
* implemented multi channel support
* implemented instrument manager, which controls sharing of instruments
  between multiple sampler engines / sampler channels
* created abstract classes 'AudioOutputDevice' and 'MidiInputDevice' for
  convenient implementation of further audio output driver and MIDI input
  driver for LinuxSampler
* implemented following LSCP commands: 'SET CHANNEL MIDI INPUT TYPE',
  'LOAD ENGINE', 'GET CHANNELS', 'ADD CHANNEL', 'REMOVE CHANNEL',
  'SET CHANNEL AUDIO OUTPUT TYPE'
* temporarily removed all command line options
* LSCP server is now launched by default

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

  ViewVC Help
Powered by ViewVC