1 /*
2 * command.h
3 * DIN Is Noise is copyright (c) 2006-2021 Jagannathan Sampath
4 * DIN Is Noise is released under GNU Public License 2.0
5 * For more information, please visit https://dinisnoise.org/
6 */
7 
8 
9 #ifndef __command
10 #define __command
11 
12 #include "help.h"
13 
14 struct tokenizer;
15 
16 struct command {
17 
18   std::string longname;
19   std::string shortname;
20 
commandcommand21   command (const std::string& ln, const std::string& sn) : longname (ln), shortname (sn) {}
operatorcommand22   virtual int operator() (tokenizer& tz) { return 1; }
~commandcommand23   virtual ~command () {}
24 
25 };
26 
27 struct cmdlist {
28 
29   std::vector<command*> cmds;
30   int ncmds;
31 
32   std::string result; // holds last run command output
33 
34   void add (command* cmd);
35   ~cmdlist ();
36 
37 };
38 
39 extern cmdlist cmdlst;
40 
41 struct din;
42 struct i_binaural_drones;
43 
44 struct set_var : command { // set var
45   din* d;
set_varset_var46 	set_var (din* dd, const std::string& ln, const std::string& sn) : command (ln, sn), d(dd) {}
47 	int operator() (tokenizer& tz);
48 	int set_scroll (std::string& varn, tokenizer& tz);
49 	int set_zoom_pan (int& rate, float& amount, std::string& varn, tokenizer& tz);
~set_varset_var50 	~set_var () {}
51 };
52 
53 struct get_var : command { // get var
54   din* d;
get_varget_var55 	get_var (din* dd, const std::string& ln, const std::string& sn) : command (ln, sn), d(dd) {}
56 	int operator() (tokenizer& tz);
~get_varget_var57 	~get_var () {}
58 };
59 
60 struct delay;
61 struct set_delay: command { // set delay time
62   delay* left;
63   delay* right;
set_delayset_delay64 	set_delay (delay* l, delay* r, const std::string& ln, const std::string& sn) : command (ln, sn), left(l), right(r) {}
65 	int operator() (tokenizer& tz);
~set_delayset_delay66 	~set_delay () {}
67 };
68 
69 struct get_delay: command { // get delay time
70   delay* left;
71   delay* right;
get_delayget_delay72 	get_delay (delay* l, delay* r, const std::string& ln, const std::string& sn) : command (ln, sn), left(l), right(r) {}
73 	int operator() (tokenizer& tz);
~get_delayget_delay74 	~get_delay () {}
75 };
76 
77 struct beat2value;
78 
79 // bpm
80 //
81 struct bpm_com {
82   static const int NUM = 4;
83   static const char* str [NUM];
84   static beat2value* bv [NUM];
85   int get_bpm_id_from_name (const std::string& name);
86 };
87 
88 struct ls_bpm: command, bpm_com { // list bpmable components
ls_bpmls_bpm89   ls_bpm (const std::string& ln, const std::string& sn) : command (ln, sn) {}
90   int operator() (tokenizer& tz);
~ls_bpmls_bpm91   ~ls_bpm () {}
92 };
93 
94 struct set_bpm: command, bpm_com {
set_bpmset_bpm95   set_bpm (const std::string& ln, const std::string& sn) : command (ln, sn) {}
96   int operator() (tokenizer& tz);
~set_bpmset_bpm97   ~set_bpm () {}
98 };
99 
100 struct get_bpm: command, bpm_com {
get_bpmget_bpm101   get_bpm (const std::string& ln, const std::string& sn) : command (ln, sn) {}
102   int operator() (tokenizer& tz);
~get_bpmget_bpm103   ~get_bpm () {}
104 };
105 
106 struct set_style : command, bpm_com {
set_styleset_style107   set_style (const std::string& ln, const std::string& sn) : command (ln, sn) {}
108   int operator() (tokenizer& tz);
~set_styleset_style109   ~set_style () {}
110 };
111 
112 struct get_style : command, bpm_com {
get_styleget_style113   get_style (const std::string& ln, const std::string& sn) : command (ln, sn) {}
114   int operator() (tokenizer& tz);
~get_styleget_style115   ~get_style () {}
116 };
117 
118 struct set_beat : command, bpm_com {
set_beatset_beat119   set_beat (const std::string& ln, const std::string& sn) : command (ln, sn) {}
120   int operator() (tokenizer& tz);
~set_beatset_beat121   ~set_beat () {}
122 };
123 
124 struct get_beat : command, bpm_com {
get_beatget_beat125   get_beat (const std::string& ln, const std::string& sn) : command (ln, sn) {}
126   int operator() (tokenizer& tz);
~get_beatget_beat127   ~get_beat () {}
128 };
129 
130 struct add_scale: command {
add_scaleadd_scale131 	add_scale (const std::string& ln, const std::string& sn) : command (ln, sn) {}
132 	int operator () (tokenizer& tz);
~add_scaleadd_scale133 	~add_scale () {}
134 };
135 
136 struct remove_scale : command {
remove_scaleremove_scale137 	remove_scale (const std::string& ln, const std::string& sn) : command (ln, sn) {}
138 	int operator () (tokenizer& tz);
~remove_scaleremove_scale139 	~remove_scale () {}
140 };
141 
142 struct ls_scales: command {
ls_scalesls_scales143 	ls_scales (const std::string& ln, const std::string& sn) : command (ln, sn) {}
144 	int operator () (tokenizer& tz);
~ls_scalesls_scales145 	~ls_scales () {}
146 };
147 
148 struct ls_notes: command {
ls_notesls_notes149 	ls_notes (const std::string& ln, const std::string& sn) : command (ln, sn) {}
150 	int operator () (tokenizer& tz);
~ls_notesls_notes151 	~ls_notes () {}
152 };
153 
154 struct load_scale : command {
155   din* d;
156   int reentry;
load_scaleload_scale157 	load_scale (din* dd, const std::string& ln, const std::string& sn) : command (ln, sn), d(dd) {}
158 	int operator () (tokenizer& tz);
~load_scaleload_scale159 	~load_scale () {}
160 };
161 
162 struct key : command {
163   din* d;
keykey164 	key (din* dd, const std::string& ln, const std::string& sn) : command (ln, sn), d(dd) {}
165 	int operator() (tokenizer& tz);
~keykey166 	~key () {}
167 };
168 
169 struct notation : command {
170   din* d;
notationnotation171   notation (din* dd, const std::string& ln, const std::string& sn) : command (ln, sn), d(dd) {}
172   int operator() (tokenizer& tz);
~notationnotation173   ~notation () {}
174 };
175 
176 struct note_distance: command {
note_distancenote_distance177 	note_distance (const std::string& ln, const std::string& sn) : command (ln, sn) {}
178 	int operator() (tokenizer& tz);
~note_distancenote_distance179 	~note_distance () {}
180 };
181 
182 struct chord: command {
chordchord183 	chord (const std::string& ln, const std::string& sn) : command (ln, sn) {}
184 	int operator() (tokenizer& tz);
~chordchord185 	~chord () {}
186 };
187 
188 struct set_font_size: command {
set_font_sizeset_font_size189 	set_font_size (const std::string& ln, const std::string& sn) : command (ln, sn) {}
190 	int operator() (tokenizer& tz);
~set_font_sizeset_font_size191 	~set_font_size () {}
192 };
193 
194 struct get_font_size: command {
get_font_sizeget_font_size195 	get_font_size (const std::string& ln, const std::string& sn) : command (ln, sn) {}
196 	int operator() (tokenizer& tz);
~get_font_sizeget_font_size197 	~get_font_size () {}
198 };
199 
200 struct set_kern: command {
set_kernset_kern201 	set_kern (const std::string& ln, const std::string& sn) : command (ln, sn) {}
202 	int operator() (tokenizer& tz);
~set_kernset_kern203 	~set_kern () {}
204 };
205 
206 struct get_kern: command {
get_kernget_kern207 	get_kern (const std::string& ln, const std::string& sn) : command (ln, sn) {}
208 	int operator() (tokenizer& tz);
~get_kernget_kern209 	~get_kern () {}
210 };
211 
212 struct curve_name : command { // change picked curve name
curve_namecurve_name213   curve_name (const std::string& ln, const std::string& sn) : command (ln, sn) {}
214   int operator() (tokenizer& tz);
~curve_namecurve_name215   ~curve_name () {}
216 };
217 
218 struct scale_curve : command {
scale_curvescale_curve219   scale_curve (const std::string& ln, const std::string& sn) : command (ln, sn) {}
220   int operator() (tokenizer& tz);
~scale_curvescale_curve221   ~scale_curve () {}
222 };
223 
224 
225 struct multi_curve;
226 
227 struct paste_gater: command {
paste_gaterpaste_gater228   paste_gater (const std::string& ln, const std::string& sn) : command (ln, sn) {}
229   int operator() (tokenizer& tz);
~paste_gaterpaste_gater230   ~paste_gater () {}
231 };
232 
233 struct curve_value : command { // change curve value (vertex, tangent)
curve_valuecurve_value234   curve_value (const std::string& ln, const std::string& sn) : command (ln, sn) {}
~curve_valuecurve_value235   ~curve_value () {}
236   int operator() (tokenizer& tz);
237 };
238 
239 struct curve__library : command { // edit curve library attached to current curve editor
curve__librarycurve__library240   curve__library (const std::string& ln, const std::string& sn) : command (ln, sn) {}
241   int operator() (tokenizer& tz);
~curve__librarycurve__library242   ~curve__library () {}
243 };
244 
245 struct set_curve_editor : command {
set_curve_editorset_curve_editor246   set_curve_editor (const std::string& ln, const std::string& sn) : command (ln, sn) {}
247   int operator() (tokenizer& tz);
~set_curve_editorset_curve_editor248   ~set_curve_editor () {}
249 };
250 
251 struct set_scope : command {
252   din* d;
253 	i_binaural_drones* sb;
set_scopeset_scope254   set_scope (const std::string& ln, const std::string& sn, din* _d, i_binaural_drones* _sb) : command (ln, sn), d(_d), sb(_sb) {}
255   int operator() (tokenizer& tz);
~set_scopeset_scope256   ~set_scope () {}
257 };
258 
259 struct get_scope : command {
260   din* d;
get_scopeget_scope261   get_scope (const std::string& ln, const std::string& sn, din* dd) : command (ln, sn), d(dd) {}
262   int operator() (tokenizer& tz);
~get_scopeget_scope263   ~get_scope () {}
264 };
265 
266 struct echo : command {
echoecho267   echo (const std::string& ln, const std::string& sn) : command (ln, sn) {}
268   int operator() (tokenizer& tz);
~echoecho269   ~echo () {}
270 };
271 
272 struct set_text_color: command {
set_text_colorset_text_color273   set_text_color (const std::string& ln, const std::string& sn) : command (ln, sn) {}
274   int operator() (tokenizer& tz);
~set_text_colorset_text_color275   ~set_text_color () {}
276 };
277 
278 struct get_selection : command {
get_selectionget_selection279   get_selection (const std::string& ln, const std::string& sn) : command (ln, sn) {}
280   int operator() (tokenizer& tz);
~get_selectionget_selection281   ~get_selection () {}
282 };
283 
284 struct set_drone : command {
285   din& d;
set_droneset_drone286   set_drone (const std::string& ln, const std::string& sn, din& dd) : command (ln, sn), d(dd) {}
287   int operator() (tokenizer& tz);
~set_droneset_drone288   ~set_drone () {}
289 };
290 
291 struct get_drone : command {
292   din& d;
get_droneget_drone293   get_drone (const std::string& ln, const std::string& sn, din& dd) : command (ln, sn), d(dd) {}
294   int operator() (tokenizer& tz);
~get_droneget_drone295   ~get_drone () {}
296 };
297 
298 struct get_intervals : command {
get_intervalsget_intervals299   get_intervals (const std::string& ln, const std::string& sn) : command (ln, sn) {}
300   int operator() (tokenizer& tz);
~get_intervalsget_intervals301   ~get_intervals () {}
302 };
303 
304 struct num_octaves : command {
305   din& d;
num_octavesnum_octaves306   num_octaves (const std::string& ln, const std::string& sn, din& dd) : command (ln, sn), d(dd) {}
307   int operator() (tokenizer& tz);
~num_octavesnum_octaves308   ~num_octaves () {}
309 };
310 
311 struct set_kb_layout : command {
312   std::string layout;
set_kb_layoutset_kb_layout313   set_kb_layout (const std::string& ln, const std::string& sn) : command (ln, sn), layout ("us") {}
314   int operator() (tokenizer& tz);
~set_kb_layoutset_kb_layout315   ~set_kb_layout () {}
316 };
317 
318 struct list_midi : command {
list_midilist_midi319   list_midi (const std::string& ln, const std::string& sn) : command (ln, sn) {}
320   int operator() (tokenizer& tz);
~list_midilist_midi321   ~list_midi () {}
322 };
323 
324 struct set_midi : command {
set_midiset_midi325   set_midi (const std::string& ln, const std::string& sn) : command (ln, sn) {}
326   int operator() (tokenizer& tz);
~set_midiset_midi327   ~set_midi () {}
328 };
329 
330 struct set_audio : command {
set_audioset_audio331   set_audio (const std::string& ln, const std::string& sn) : command (ln, sn) {}
332   int operator() (tokenizer& tz);
~set_audioset_audio333   ~set_audio () {}
334 };
335 
336 struct gravity : command {
gravitygravity337   gravity (const std::string& ln, const std::string& sn) : command (ln, sn) {}
338 	int operator() (tokenizer& tz);
~gravitygravity339 	~gravity () {}
340 };
341 
342 #ifdef __SVG__
343 
344 struct write_svg : command {
write_svgwrite_svg345   write_svg (const std::string& ln, const std::string& sn) : command (ln, sn) {}
346   int operator() (tokenizer& tz);
~write_svgwrite_svg347   ~write_svg () {}
348 };
349 
350 struct write_trail : command {
write_trailwrite_trail351   write_trail (const std::string& ln, const std::string& sn) : command (ln, sn) {}
352   int operator() (tokenizer& tz);
~write_trailwrite_trail353   ~write_trail () {}
354 };
355 
356 #endif
357 
358 #ifdef __HPGL__
359 struct write_hpgl : command {
write_hpglwrite_hpgl360 	write_hpgl (const std::string& ln, const std::string& sn) : command (ln, sn) {}
361 	int operator() (tokenizer& tz);
~write_hpglwrite_hpgl362 	~write_hpgl () {}
363 };
364 #endif
365 
366 struct cmd_binaural_drone : command {
cmd_binaural_dronecmd_binaural_drone367   cmd_binaural_drone (const std::string& ln, const std::string& sn) : command (ln, sn) {}
368   int operator() (tokenizer& tz);
~cmd_binaural_dronecmd_binaural_drone369   ~cmd_binaural_drone () {}
370 };
371 
372 struct set_sine_mixer : command {
set_sine_mixerset_sine_mixer373   set_sine_mixer (const std::string& ln, const std::string& sn) : command (ln, sn) {}
374   int operator() (tokenizer& tz);
~set_sine_mixerset_sine_mixer375   ~set_sine_mixer () {}
376 };
377 
378 struct change_sine_mixer : command {
change_sine_mixerchange_sine_mixer379   change_sine_mixer (const std::string& ln, const std::string& sn) : command (ln, sn) {}
380   int operator() (tokenizer& tz);
~change_sine_mixerchange_sine_mixer381   ~change_sine_mixer () {}
382 };
383 
384 struct update_sine_mixer : command {
update_sine_mixerupdate_sine_mixer385 	update_sine_mixer (const std::string& ln, const std::string& sn) : command (ln, sn) {}
386 	int operator() (tokenizer& tz);
~update_sine_mixerupdate_sine_mixer387 	~update_sine_mixer () {}
388 };
389 
390 
391 #endif
392