-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFileInterpreter.cpp
672 lines (579 loc) · 25 KB
/
FileInterpreter.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
/*
* FileInterpreter.cpp
*
* Created on: Jan 17, 2014
* Author: edwinrietmeijer
*/
#include "FileInterpreter.h"
void processFile( std::string filename, bool runAll ) {
bool isStartOfComment = false;
bool defaultStreamNameUsed= false;
int lineNo = 0;
std::vector<scriptcommand::ScriptCommand * > scriptLoop;
customtypes::InterpMode currInterpMode;
std::string lineToRead;
std::string funcName = "";
std::string newEntityName;
int nrOfNewEntities;
std::vector<double> centsToRels;
std::vector<std::string>::const_iterator gsnPos;
config::playScriptCommandStack.clear();
std::ifstream fileToRead ( filename.c_str() );
if ( fileToRead.is_open() )
{
while ( getline ( fileToRead, lineToRead ) )
{
lineNo++;
// LINE TOKENIZE
std::string::size_type start = 0;
std::string::size_type pos = lineToRead.find(" ");
std::string tok;
std::vector<std::string> tokens;
isStartOfComment = false;
// Uncomment this line to dump script during processing
// std::cout << lineNo << ": " << lineToRead << std::endl;
while ( pos != std::string::npos )
{
tok = lineToRead.substr( start, pos - start);
if ( tok[ 0 ] == '#' ) {
isStartOfComment = true;
}
start = pos + 1;
pos = lineToRead.find( " ", start );
if ( ! isStartOfComment && tok.size() > 0) {
tokens.push_back( tok );
}
}
tok = lineToRead.substr( start, pos - start );
if ( tok[ 0 ] == '#' ) {
isStartOfComment = true;
}
if ( ! isStartOfComment && tok.size() > 0) {
tokens.push_back( tok );
}
common::strVectorToLower( tokens );
if ( ! tokens.empty() ) {
funcName = tokens.at( 0 );
tokens.erase( tokens.begin() );
} else {
funcName = "";
}
if ( funcName != "" && funcName[0] != '#' ) {
ScriptCommandVars newScriptCommVars;
newScriptCommVars.noteBlock = nullptr;
newScriptCommVars.generator = nullptr;
newScriptCommVars.noteBlockFunction = customtypes::NO_NB_FUNC;
newScriptCommVars.generatorFunction = customtypes::NO_GEN_FUNC;
newScriptCommVars.streamName = &config::streamNames.front();
newScriptCommVars.pitchSet = config::defaultPitch;
newScriptCommVars.durationSet = config::defaultDuration;
newScriptCommVars.velocitySet = config::defaultVelocity;
newScriptCommVars.firstGenFuncInt = 0;
// LINE INTERPRETER
if ( funcName == "config" && runAll )
currInterpMode = customtypes::CONFIG_MODE;
if ( funcName == "init" && runAll )
currInterpMode = customtypes::INIT_MODE;
if ( funcName == "play" )
currInterpMode = customtypes::PLAY_MODE;
// CONFIG MODE
if ( currInterpMode == customtypes::CONFIG_MODE ) {
if( tokens.size() > 0 ) {
if ( funcName == "centernote" ) {
if ( common::isInt( tokens.front() ) ) {
config::centerNote = common::stringToInt( tokens.front() );
}
}
if ( funcName == "centerfreq" ) {
if ( common::isDouble( tokens.front() ) ) {
config::centerFreq = common::stringToDouble( tokens.front() );
}
}
if ( funcName == "notecents" ) {
std::vector<std::string>::iterator pos2;
std::vector<double> noteRelsToAdd;
for ( pos2 = tokens.begin(); pos2 != tokens.end(); ++pos2 ) {
std::string thisStr = *pos2;
if ( common::isDouble( thisStr ) ) {
noteRelsToAdd.push_back( musical::centToRel ( common::stringToDouble ( thisStr ) ) );
}
}
if ( ! noteRelsToAdd.empty() ) {
config::noteRelatives.clear();
config::noteRelatives = noteRelsToAdd;
} else {
std::cout << "Line " << lineNo << " : no notecents in correct format ( double/int ) found" << std::endl;
}
// notecents to noteRels
}
if ( funcName == "pitch" ) {
std::vector<std::string>::iterator pos2;
std::vector<int> pitchesToAdd;
for ( pos2 = tokens.begin(); pos2 != tokens.end(); ++pos2 ) {
std::string thisStr = *pos2;
if ( common::isInt( thisStr ) ) {
pitchesToAdd.push_back( common::stringToInt ( thisStr ) );
} else {
std::cout << "Line " << lineNo << " : pitch " << thisStr << " not in correct format ( int )" << std::endl;
}
}
if ( ! pitchesToAdd.empty() ) {
config::pitchStack.push_back( pitchesToAdd );
} else {
std::cout << "Line " << lineNo << " : no pitches in correct format ( int ) found" << std::endl;
}
// pitches to pitchStack
}
if ( funcName == "dur" ) {
std::vector<std::string>::iterator pos2;
std::vector<double> durationsToAdd;
for ( pos2 = tokens.begin(); pos2 != tokens.end(); ++pos2 ) {
std::string thisStr = *pos2;
if ( common::isDouble( thisStr ) ) {
durationsToAdd.push_back( common::stringToDouble ( thisStr ) );
} else {
std::cout << "Line " << lineNo << " : duration " << thisStr << " not in correct format ( double )" << std::endl;
}
}
if ( !durationsToAdd.empty() ) {
config::durationStack.push_back( durationsToAdd );
} else {
std::cout << "Line " << lineNo << " : no durations in correct format ( double ) found" << std::endl;
}
// durations to durationStack
}
if ( funcName == "vel" ) {
std::vector<std::string>::iterator pos2;
std::vector<double> velocitiesToAdd;
for ( pos2 = tokens.begin(); pos2 != tokens.end(); ++pos2 ) {
std::string thisStr = *pos2;
if ( common::isDouble( thisStr ) ) {
velocitiesToAdd.push_back( common::stringToDouble ( thisStr ) );
} else {
std::cout << "Line " << lineNo << " : velocity " << thisStr << " not in correct format ( double )" << std::endl;
}
}
if ( ! velocitiesToAdd.empty() ) {
config::velocityStack.push_back( velocitiesToAdd );
} else {
std::cout << "Line " << lineNo << " : no velocities in correct format ( double ) found" << std::endl;
}
// velocities to velocityStack
}
if ( funcName == "defaultpitch" ) {
if ( config::pitchStack.size() > 0 && common::isInt( tokens.front() ) ) {
if ( common::stringToInt( tokens.front() ) <= config::pitchStack.size() ) {
config::defaultPitch = & config::pitchStack.at( common::stringToInt( tokens.front() ) -1 );
} else {
std::cout << "Line " << lineNo << " : default pitch index " << common::stringToInt( tokens.front() ) << " not found, returning internal default" << std::endl;
}
} else {
std::cout << "Line " << lineNo << " : default pitch index value " << tokens.front() << " can not be processed" << std::endl;
}
}
if ( funcName == "defaultdur" ) {
if ( config::durationStack.size() > 0 && common::isInt( tokens.front() ) ) {
if ( common::stringToInt( tokens.front() ) <= config::durationStack.size() ) {
config::defaultDuration = & config::durationStack.at( common::stringToInt( tokens.front() ) -1 );
} else {
std::cout << "Line " << lineNo << " : default duration index " << common::stringToInt( tokens.front() ) << " not found, returning internal default" << std::endl;
}
} else {
std::cout << "Line " << lineNo << " : default duration index value " << tokens.front() << " can not be processed" << std::endl;
}
}
if ( funcName == "defaultvel" ) {
if ( config::velocityStack.size() > 0 && common::isInt( tokens.front() ) ) {
if ( common::stringToInt( tokens.front() ) <= config::velocityStack.size() ) {
config::defaultVelocity = & config::velocityStack.at( common::stringToInt( tokens.front() ) -1 );
} else {
std::cout << "Line " << lineNo << " : default velocity index " << common::stringToInt( tokens.front() ) << " not found, returning internal default" << std::endl;
}
} else {
std::cout << "Line " << lineNo << " : default velocity index value " << tokens.front() << " can not be processed" << std::endl;
}
}
// ADD NEW ENTITIES
if ( funcName == "new" ) {
bool entityFound = false;
if ( tokens.size() > 0 ) {
newEntityName = tokens.at( 0 );
tokens.erase( tokens.begin() );
nrOfNewEntities = 1;
// Number of new entities to add given?
if ( tokens.size() > 0 && common::isInt( tokens.front() ) ) {
nrOfNewEntities = common::stringToInt( tokens.front() );
}
// Check script name file for existing generators, add to the generator stack when found
for ( int i = 0; i < nrOfNewEntities; i++ ) {
// Cycle through accepted generator script names as supported in GenAdmin.h/.cpp
for ( gsnPos = generatorScriptNames.begin(); gsnPos != generatorScriptNames.end(); ++gsnPos ) {
if ( newEntityName == common::lower( *gsnPos ) ) {
// Add the generator to the generator stack and generator ID stack
addGen( findGenScriptName( newEntityName ), config::generatorStack, config::generatorIds );
// Initialize generator
config::generatorStack.back() -> setMediatorPointers( config::genMediatorVars, config::mutatorMediatorVars );
config::generatorStack.back() -> setScaleSize( config::noteRelatives.size() );
config::generatorStack.back() -> setDia( config::isDiatonic );
config::generatorStack.back() -> init();
entityFound = true;
}
}
if ( newEntityName == "stream" ) {
// config::streamStack.push_back( new noteblock::NoteBlock );
if ( tokens.front() != "" ) {
config::streamNames.push_back( tokens.front() );
entityFound = true;
} else {
if ( ! defaultStreamNameUsed ) {
// config::streamNames.push_back( "default" );
std::cout << "Line " << lineNo << " : stream name in use, using \'default\'" << std::endl;
entityFound = true;
}
}
}
if ( newEntityName == "noteblock" ) {
config::noteBlockStack.push_back( new noteblock::NoteBlock );
entityFound = true;
}
}
}
if ( ! entityFound ) {
std::cout << "Line " << lineNo << " : entity type not found" << std::endl;
}
}
}
}
// INIT MODE
if ( currInterpMode == customtypes::INIT_MODE ) {
// From here, the vector of tokens can be sent to a subfunction to be processed
// into a ScriptCommand var set.
bool isCompleteScriptCommand;
isCompleteScriptCommand = tokensToScriptVars( funcName, tokens, newScriptCommVars, lineNo );
if ( isCompleteScriptCommand ) {
config::initScriptCommandStack.push_back( new scriptcommand::ScriptCommand ( newScriptCommVars ) );
config::initScriptCommandStack.back() -> setMediatorPointers( config::genMediatorVars, config::mutatorMediatorVars );
config::initScriptCommandStack.back() -> setConfigPointers( config::centerNote, config::centerFreq, config::noteRelatives );
}
}
// gotFirstLoopOpenBracket
// PLAY MODE
if ( currInterpMode == customtypes::PLAY_MODE ) {
tokensToScriptVars( funcName, tokens, newScriptCommVars, lineNo );
if ( newScriptCommVars.noteBlock != nullptr && newScriptCommVars.noteBlockFunction != customtypes::NO_NB_FUNC ) {
scriptLoop.push_back( new scriptcommand::ScriptCommand ( newScriptCommVars ) );
scriptLoop.back() -> setMediatorPointers( config::genMediatorVars, config::mutatorMediatorVars );
scriptLoop.back() -> setConfigPointers( config::centerNote, config::centerFreq, config::noteRelatives );
}
if ( funcName =="}" && !scriptLoop.empty() ) {
config::playScriptCommandStack.push_back( scriptLoop );
config::loopWaitFor.push_back( 0.0 );
config::loopTimePassed.push_back( 0.0 );
config::loopCurrentIndex.push_back( 0 );
scriptLoop.clear();
}
}
} // end of emtpy function check
// next line or eof
}
if ( ! scriptLoop.empty() ) {
config::playScriptCommandStack.push_back( scriptLoop );
config::loopWaitFor.push_back( 0.0 );
config::loopTimePassed.push_back( 0.0 );
scriptLoop.clear();
}
// std::cout << scriptcommand::initScriptCommandStack.size() << std::endl;
//
// std::cout << (scriptcommand::playScriptCommandStack.front()).size() << std::endl;
// std::cout << (scriptcommand::playScriptCommandStack.back()).size() << std::endl;
fileToRead.close();
}
else std::cout << "Unable to open read file";
}
bool tokensToScriptVars( std::string & funcName, std::vector<std::string> & tokens, ScriptCommandVars & newScriptCommVars, int & lineNo ) {
bool completeScriptCommand = false;
if ( funcName != "noteblock" ) {
newScriptCommVars.noteBlock = nullptr;
bool isGen = false;
generator::Generator * aNewGen = findGenScriptName( funcName );
if( aNewGen -> getScriptName() != "" ) {
isGen = true;
// end of genType existance check
if ( ! isGen ) {
std::cout << "Line " << lineNo << " : generator type for generator script name '" << funcName << "' does not exist" << std::endl;
}
if( isGen && tokens.size() > 0 ) {
// Check if the given generator index of this type exists in the stack
// Note: a generator of index 2 could have a higher placement index
// in the generatorStack vector, depending on how many other generators
// of (a) different type(s) are in the stack
int genNr;
bool isGenInStack = false;
int genStackIndex = -1;
if ( common::isInt( tokens.at( 0 ) ) ) {
genNr = common::stringToInt( tokens.at( 0 ) );
tokens.erase( tokens.begin() );
genStackIndex = getGenStackIndex( aNewGen, genNr );
// If a generator of the type and and index specified exists on the
// generator stack, point to it in the new ScriptCommandVars struct.
if ( genStackIndex != -1 ) {
newScriptCommVars.generator = config::generatorStack.at( genStackIndex );
isGenInStack = true;
}
} // end of generator index check
if ( ! isGenInStack ) {
std::cout << "Line " << lineNo << " : generator stack index " << genNr << " for generator script name '" << funcName<< "' does not exist" << std::endl;
}
if ( isGenInStack && tokens.size() > 0 ) {
// Find and, if it exists, add non-noteBlock generator function to script
bool isGenFunc = false;
std::string genFuncCall = tokens.at( 0 );
tokens.erase( tokens.begin() );
for ( int i = 0; i < customtypes::nonNoteBlockGeneratorFuncs.size(); i++ ) {
if( genFuncCall == customtypes::nonNoteBlockGeneratorFuncsScriptNames.at( i ) ) {
isGenFunc = true;
completeScriptCommand = true;
newScriptCommVars.generatorFunction = customtypes::nonNoteBlockGeneratorFuncs.at( i );
}
} // end of generator function existance check
}
}
std::vector<std::string>::iterator pos2;
std::vector<double> variablesToAdd;
for ( pos2 = tokens.begin(); pos2 != tokens.end(); ++pos2 ) {
std::string thisStr = *pos2;
if ( common::isDouble( thisStr ) ) {
variablesToAdd.push_back( common::stringToDouble ( thisStr ) );
} else {
std::cout << "Line " << lineNo << " : variable '" << thisStr << "' not in correct format ( double )" << std::endl;
}
}
if ( ! variablesToAdd.empty() ) {
newScriptCommVars.variableSet = variablesToAdd;
completeScriptCommand = true;
}
// else {
// std::cout << "Line " << lineNo << " : no variables in correct format ( double ) found" << std::endl;
// }
// variables to script command struct
}
} else {
// Found noteblock based line of script
if( tokens.size() > 0 ) {
if( common::isInt( tokens.at( 0 ) ) ) {
// Get noteBlockStack index number
int noteBlockNo = common::stringToInt( tokens.at( 0 ) );
tokens.erase( tokens.begin() );
// Check to see if given noteBlockStack index number exists
if( noteBlockNo < config::noteBlockStack.size() && noteBlockNo > -1 ) {
// Set noteBlock index in new ScriptCommandVars
newScriptCommVars.noteBlock = config::noteBlockStack.at( noteBlockNo );
}
if ( tokens.size() > 0 ) {
// Find and, if it exists, add noteBlock Function to script
bool isNBFunc = false;
std::string nbFuncCall = tokens.at( 0 );
tokens.erase( tokens.begin() );
for ( int i = 0; i < customtypes::noteBlockFuncScriptNames.size(); i++ ) {
if( nbFuncCall == customtypes::noteBlockFuncScriptNames.at( i ) ) {
isNBFunc = true;
newScriptCommVars.noteBlockFunction = customtypes::allNoteBlockFuncs.at( i );
}
}
if ( ! isNBFunc ) {
std::cout << "Line " << lineNo << " : script noteblock function reference '" << nbFuncCall << "' does not exist" << std::endl;
}
//Add default pitch, duration, and velocity vector pointers now.
newScriptCommVars.pitchSet = config::defaultPitch;
newScriptCommVars.durationSet = config::defaultDuration;
newScriptCommVars.velocitySet = config::defaultVelocity;
if ( isNBFunc && tokens.size() > 0 ) {
// Check for existing of generator type
bool isGen = false;
std::string genScrName = tokens.at( 0 );
tokens.erase( tokens.begin() );
bool isGenNonNBFunc = false;
// Check to see if noteblock function is a non-generator noteblock function
std::vector<customtypes::NoteBlockFunc>::const_iterator ngfPos;
for( ngfPos = customtypes::nonGeneratorNoteBlockFuncs.begin(); ngfPos != customtypes::nonGeneratorNoteBlockFuncs.end(); ++ngfPos ) {
if( newScriptCommVars.noteBlockFunction == *ngfPos ) {
isGenNonNBFunc = true;
completeScriptCommand = true;
}
}
// If noteblock function is NOT a non-generator noteblock function,
// try to find a generator stack reference in script line
if( ! isGenNonNBFunc ) {
generator::Generator * aNewGen = findGenScriptName( genScrName );
if( aNewGen -> getScriptName() != "" ) {
isGen = true;
} // end of genType existance check
if ( ! isGen ) {
std::cout << "Line " << lineNo << " : generator type for generator script name '" << genScrName << "' does not exist" << std::endl;
}
if( isGen && tokens.size() > 0 ) {
// Check if the given generator index of this type exists in the stack
// Note: a generator of index 2 could have a higher placement index
// in the generatorStack vector, depending on how many other generators
// of (a) different type(s) are in the stack
int genNr;
bool isGenInStack = false;
int genStackIndex = -1;
if ( common::isInt( tokens.at( 0 ) ) ) {
genNr = common::stringToInt( tokens.at( 0 ) );
tokens.erase( tokens.begin() );
genStackIndex = getGenStackIndex( aNewGen, genNr );
// If a generator of the type and and index specified exists on the
// generator stack, point to it in the new ScriptCommandVars struct.
if ( genStackIndex != -1 ) {
newScriptCommVars.generator = config::generatorStack.at( genStackIndex );
isGenInStack = true;
}
} // end of generator index check
if ( ! isGenInStack ) {
std::cout << "Line " << lineNo << " : generator stack index " << genNr << " for generator script name '" << genScrName<< "' does not exist" << std::endl;
}
if ( isGenInStack && tokens.size() > 0 ) {
// Find and, if it exists, add generator Function to script
bool isGenFunc = false;
std::string genFuncCall = tokens.at( 0 );
tokens.erase( tokens.begin() );
for ( int i = 0; i < customtypes::generatorFuncScriptNames.size(); i++ ) {
if( genFuncCall == customtypes::generatorFuncScriptNames.at( i ) ) {
isGenFunc = true;
completeScriptCommand = true;
newScriptCommVars.generatorFunction = customtypes::allGeneratorFuncs.at( i );
}
} // end of generator function existance check
// Check to see if the generator function is a mutator function.
// If so, the next variable must be a noteblock
bool isGenFuncMutatorFunc = false;
for ( int i = 0; i < customtypes::mutatorGeneratorFuncs.size(); i++ ) {
if ( newScriptCommVars.generatorFunction == customtypes::mutatorGeneratorFuncs.at( i ) ) {
isGenFuncMutatorFunc = true;
}
}
std::string nextToken;
if( isGenFuncMutatorFunc ) {
completeScriptCommand = false;
if ( tokens.size() > 0 ) {
nextToken = tokens.at( 0 );
tokens.erase( tokens.begin() );
}
}
if ( nextToken == "noteblock" ) {
if ( tokens.size() > 0 ) {
std::string noteBlockNo = tokens.at( 0 );
tokens.erase( tokens.begin() );
if( common::isInt( noteBlockNo ) ) {
int noteBlockIndex = common::stringToInt( noteBlockNo );
if( noteBlockIndex < config::noteBlockStack.size() && noteBlockIndex > -1 ) {
// Set noteBlock index in new ScriptCommandVars
newScriptCommVars.anotherNoteBlock = config::noteBlockStack.at( noteBlockIndex );
completeScriptCommand = true;
}
}
}
}
// Check to see if the next variable is an int. This will be the value passed with the generator function
// MIGHT NOT BE INT!
if ( isGenInStack && tokens.size() > 0 ) {
bool isVarInt= false;
if( common::isInt( tokens.at( 0 ) ) ) {
// Get int value
newScriptCommVars.firstGenFuncInt = common::stringToInt( tokens.at( 0 ) );
tokens.erase( tokens.begin() );
isVarInt = true;
}
// If there is an int variable, increment the generator function:
// GET becomes GET_INT, NEXT becomes NEXT_INT, etcetera
if( isVarInt ) {
int genFuncNo = static_cast<int>( newScriptCommVars.generatorFunction );
++ genFuncNo;
newScriptCommVars.generatorFunction = static_cast<customtypes::GeneratorFunc>( genFuncNo );
}
}
}
// Process remaining tokens
while( ! tokens.empty() ) {
std::string nextString = tokens.at( 0 );
tokens.erase( tokens.begin() );
if ( nextString == "pitch" ) {
if( tokens.size() > 0 ) {
if( common::isInt( tokens.at( 0 ) ) ) {
int pitchIndex = common::stringToInt( tokens.at( 0 ) ) - 1;
tokens.erase( tokens.begin() );
if ( pitchIndex < config::pitchStack.size() && pitchIndex > -1 ) {
newScriptCommVars.pitchSet = & config::pitchStack.at( pitchIndex );
}
}
}
} // end of check for pitch index ref
if ( nextString == "dur" || nextString == "duration" ) {
if( tokens.size() > 0 ) {
if( common::isInt( tokens.at( 0 ) ) ) {
int durIndex = common::stringToInt( tokens.at( 0 ) ) - 1;
tokens.erase( tokens.begin() );
if ( durIndex < config::durationStack.size() && durIndex > -1 ) {
newScriptCommVars.durationSet = & config::durationStack.at( durIndex );
}
}
}
} // end of check for duration index ref
if ( nextString == "vel" || nextString == "velocity" ) {
if( tokens.size() > 0 ) {
if( common::isInt( tokens.at( 0 ) ) ) {
int velIndex = common::stringToInt( tokens.at( 0 ) ) - 1;
tokens.erase( tokens.begin() );
if ( velIndex < config::velocityStack.size() && velIndex > -1 ) {
newScriptCommVars.velocitySet = & config::velocityStack.at( velIndex );
}
}
}
} // end of check for duration index ref
} // end of remaining tokens processing
} // end of noteblock script line processing
}
if( newScriptCommVars.noteBlockFunction == customtypes::PLAY ) {
newScriptCommVars.generatorFunction = customtypes::NO_GEN_FUNC;
std::string thisStreamName = "default";
while( ! tokens.empty() ) {
std::string nextToken = tokens.at( 0 );
tokens.erase( tokens.begin() );
std::vector<std::string>::iterator strPos;
for( strPos = config::streamNames.begin(); strPos != config::streamNames.end(); ++strPos ) {
if ( nextToken == * strPos ) {
newScriptCommVars.streamName = &( *strPos );
}
}
}
}
}
}
}
}
} // end of noteblock script function
return completeScriptCommand;
}
void writeToFile( std::string filename, const std::string & lineToWrite ) {
std::ofstream fileToWrite( filename.c_str(), std::ios::app );
if (fileToWrite.is_open())
{
fileToWrite << lineToWrite;
fileToWrite.close();
}
else std::cout << "Unable to open write file";
}
void fileToScreen( std::string filename ) {
std::string lineToRead;
std::ifstream fileToRead ( filename.c_str() );
if (fileToRead.is_open())
{
while ( getline (fileToRead,lineToRead) )
{
std::cout << lineToRead << std::endl;
}
fileToRead.close();
}
else std::cout << "Unable to open read file";
}