test publish
Dependencies: mbed GroveEarbudSensor
Diff: MelodyGenerator.cpp
- Revision:
- 8:e1beb2a9454e
- Parent:
- 7:d497a01156ef
--- a/MelodyGenerator.cpp Mon Apr 11 11:18:46 2016 +0000 +++ b/MelodyGenerator.cpp Mon Apr 11 13:30:35 2016 +0000 @@ -12,18 +12,19 @@ this->melody = myMelody; } -vector<Notes> MelodyGenerator::getMeasure(Scale& mode) +vector<Notes>* MelodyGenerator::getMeasure(Scale& mode) { int length = melody.length(); - vector<Notes> result; + vector<Notes>* result = new vector<Notes>(); char currentChar = melody[cursor]; - bool octaveUp = false; - bool octaveDown = false; - bool flat = false; - bool sharp = false; + while(currentChar != '|') { - while(currentChar != '|') { + bool octaveUp = false; + bool octaveDown = false; + bool flat = false; + bool sharp = false; + if (currentChar == 'u') octaveUp = true; else if (currentChar == 'd') @@ -72,14 +73,20 @@ else if (octaveDown) currentNote = mode.applyOctaveDown(currentNote); - result.push_back(currentNote); + result->push_back(currentNote); } - } + + cursor++; + if (cursor == length) + cursor = 0; - if (cursor == length) - cursor = 0; - else + currentChar = melody[cursor]; + } + + cursor++; + if (cursor == length) + cursor = 0; return result; } @@ -88,4 +95,3 @@ { this->melody = myMelody; } -