test publish

Dependencies:   mbed GroveEarbudSensor

Committer:
age2pierre
Date:
Mon Apr 11 11:18:46 2016 +0000
Revision:
7:d497a01156ef
Parent:
6:7cc8a333e03b
Child:
8:e1beb2a9454e
Update cello bach suite melody

Who changed what in which revision?

UserRevisionLine numberNew contents of line
age2pierre 6:7cc8a333e03b 1 #include "MelodyGenerator.h"
age2pierre 6:7cc8a333e03b 2
age2pierre 6:7cc8a333e03b 3 MelodyGenerator::MelodyGenerator()
age2pierre 6:7cc8a333e03b 4 {
age2pierre 7:d497a01156ef 5 //J.S Bach cello suite 1 prelude first 7 bars
age2pierre 7:d497a01156ef 6 this->melody = "1,5,u3,u2;u3,5,u3,5;1,5,u3,u2;u3,5,u3,5|1,6,u4,u3;u4,6,u4,6;1,6,u4,u3;u4,6,u4,6|1,7,u4,u3;u4,7,u4,7;1,7,u4,u3;u4,7,u4,7|1,u1,u3,u2;u3,u1,u3,u1;1,u1,u3,u2;u3,u1,u3,u1|1,6,u3,u2;u3,u1,7,u1;6,u1,7,u1;3,5,#4,3|#4,u1,u2,u1;u2,u1,u2,u1;5,u1,u2,u1;u2,u1,u2,u1|7,u2,u5,#u4;u5,u2,u1,u2;7,u2,u1,u2;5,7,6,5|";
age2pierre 6:7cc8a333e03b 7 this->cursor = 0;
age2pierre 6:7cc8a333e03b 8 }
age2pierre 6:7cc8a333e03b 9
age2pierre 6:7cc8a333e03b 10 MelodyGenerator::MelodyGenerator(string myMelody)
age2pierre 6:7cc8a333e03b 11 {
age2pierre 6:7cc8a333e03b 12 this->melody = myMelody;
age2pierre 6:7cc8a333e03b 13 }
age2pierre 6:7cc8a333e03b 14
age2pierre 6:7cc8a333e03b 15 vector<Notes> MelodyGenerator::getMeasure(Scale& mode)
age2pierre 6:7cc8a333e03b 16 {
age2pierre 6:7cc8a333e03b 17 int length = melody.length();
age2pierre 6:7cc8a333e03b 18 vector<Notes> result;
age2pierre 6:7cc8a333e03b 19 char currentChar = melody[cursor];
age2pierre 6:7cc8a333e03b 20
age2pierre 6:7cc8a333e03b 21 bool octaveUp = false;
age2pierre 6:7cc8a333e03b 22 bool octaveDown = false;
age2pierre 6:7cc8a333e03b 23 bool flat = false;
age2pierre 6:7cc8a333e03b 24 bool sharp = false;
age2pierre 6:7cc8a333e03b 25
age2pierre 6:7cc8a333e03b 26 while(currentChar != '|') {
age2pierre 6:7cc8a333e03b 27 if (currentChar == 'u')
age2pierre 6:7cc8a333e03b 28 octaveUp = true;
age2pierre 6:7cc8a333e03b 29 else if (currentChar == 'd')
age2pierre 6:7cc8a333e03b 30 octaveDown = true;
age2pierre 6:7cc8a333e03b 31 else if (currentChar == 'b')
age2pierre 6:7cc8a333e03b 32 flat = true;
age2pierre 6:7cc8a333e03b 33 else if (currentChar == '#')
age2pierre 6:7cc8a333e03b 34 sharp = true;
age2pierre 6:7cc8a333e03b 35 else if ((currentChar == ',')||(currentChar == ';')) {
age2pierre 6:7cc8a333e03b 36 octaveUp = false;
age2pierre 6:7cc8a333e03b 37 octaveDown = false;
age2pierre 6:7cc8a333e03b 38 flat = false;
age2pierre 6:7cc8a333e03b 39 sharp = false;
age2pierre 6:7cc8a333e03b 40 } else {
age2pierre 6:7cc8a333e03b 41 Notes currentNote;
age2pierre 6:7cc8a333e03b 42 switch(currentChar) {
age2pierre 6:7cc8a333e03b 43 case '1' :
age2pierre 6:7cc8a333e03b 44 currentNote = mode.getTonic();
age2pierre 6:7cc8a333e03b 45 break;
age2pierre 6:7cc8a333e03b 46 case '2' :
age2pierre 6:7cc8a333e03b 47 currentNote = mode.getSupertonic();
age2pierre 6:7cc8a333e03b 48 break;
age2pierre 6:7cc8a333e03b 49 case '3' :
age2pierre 6:7cc8a333e03b 50 currentNote = mode.getMediant();
age2pierre 6:7cc8a333e03b 51 break;
age2pierre 6:7cc8a333e03b 52 case '4' :
age2pierre 6:7cc8a333e03b 53 currentNote = mode.getSubdominant();
age2pierre 6:7cc8a333e03b 54 break;
age2pierre 6:7cc8a333e03b 55 case '5' :
age2pierre 6:7cc8a333e03b 56 currentNote = mode.getDominant();
age2pierre 6:7cc8a333e03b 57 break;
age2pierre 6:7cc8a333e03b 58 case '6' :
age2pierre 6:7cc8a333e03b 59 currentNote = mode.getSuperdominant();
age2pierre 6:7cc8a333e03b 60 break;
age2pierre 6:7cc8a333e03b 61 case '7' :
age2pierre 6:7cc8a333e03b 62 currentNote = mode.getSubtonic();
age2pierre 6:7cc8a333e03b 63 break;
age2pierre 6:7cc8a333e03b 64 }
age2pierre 6:7cc8a333e03b 65
age2pierre 6:7cc8a333e03b 66 if (sharp)
age2pierre 6:7cc8a333e03b 67 currentNote = mode.applySharp(currentNote);
age2pierre 6:7cc8a333e03b 68 else if (flat)
age2pierre 6:7cc8a333e03b 69 currentNote = mode.applyFlat(currentNote);
age2pierre 6:7cc8a333e03b 70 if (octaveUp)
age2pierre 6:7cc8a333e03b 71 currentNote = mode.applyOctaveUp(currentNote);
age2pierre 6:7cc8a333e03b 72 else if (octaveDown)
age2pierre 6:7cc8a333e03b 73 currentNote = mode.applyOctaveDown(currentNote);
age2pierre 6:7cc8a333e03b 74
age2pierre 6:7cc8a333e03b 75 result.push_back(currentNote);
age2pierre 6:7cc8a333e03b 76 }
age2pierre 6:7cc8a333e03b 77 }
age2pierre 6:7cc8a333e03b 78
age2pierre 6:7cc8a333e03b 79 if (cursor == length)
age2pierre 6:7cc8a333e03b 80 cursor = 0;
age2pierre 6:7cc8a333e03b 81 else
age2pierre 6:7cc8a333e03b 82 cursor++;
age2pierre 6:7cc8a333e03b 83
age2pierre 6:7cc8a333e03b 84 return result;
age2pierre 6:7cc8a333e03b 85 }
age2pierre 6:7cc8a333e03b 86
age2pierre 6:7cc8a333e03b 87 void MelodyGenerator::changeMelody(string myMelody)
age2pierre 6:7cc8a333e03b 88 {
age2pierre 6:7cc8a333e03b 89 this->melody = myMelody;
age2pierre 6:7cc8a333e03b 90 }
age2pierre 6:7cc8a333e03b 91