![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Game codes for Pokemon Academy Yiu Fai Kwok - 201198802 I have read the University Regulations on Plagiarism and state that the work covered by this declaration is my own and does not contain any unacknowledged work from other sources.
Dependencies: mbed FXOS8700CQ mbed-rtos
Score/Notes.cpp@2:464c7e62d97d, 2019-04-03 (annotated)
- Committer:
- yfkwok
- Date:
- Wed Apr 03 03:06:00 2019 +0000
- Revision:
- 2:464c7e62d97d
Date 3/4/2019 - Mini game one beta complete
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
yfkwok | 2:464c7e62d97d | 1 | /* * * * * * * * * * * * * * * * * * * * * * * * * * * |
yfkwok | 2:464c7e62d97d | 2 | * This is a definitions class for music notes and * |
yfkwok | 2:464c7e62d97d | 3 | * their frequencies. * |
yfkwok | 2:464c7e62d97d | 4 | * * |
yfkwok | 2:464c7e62d97d | 5 | * Created by: Michael Dushkoff (mad1841@rit.edu) * |
yfkwok | 2:464c7e62d97d | 6 | * * * * * * * * * * * * * * * * * * * * * * * * * * */ |
yfkwok | 2:464c7e62d97d | 7 | |
yfkwok | 2:464c7e62d97d | 8 | #include "mbed.h" |
yfkwok | 2:464c7e62d97d | 9 | #include "Notes.h" |
yfkwok | 2:464c7e62d97d | 10 | |
yfkwok | 2:464c7e62d97d | 11 | // Initialize local note arrays for indexing |
yfkwok | 2:464c7e62d97d | 12 | double _A[] = {NOTE_A0, NOTE_A1, NOTE_A2, NOTE_A3, NOTE_A4, |
yfkwok | 2:464c7e62d97d | 13 | NOTE_A5, NOTE_A6, NOTE_A7}; |
yfkwok | 2:464c7e62d97d | 14 | double _AS[] = {NOTE_AS0, NOTE_AS1, NOTE_AS2, NOTE_AS3, NOTE_AS4, |
yfkwok | 2:464c7e62d97d | 15 | NOTE_AS5, NOTE_AS6, NOTE_AS7}; |
yfkwok | 2:464c7e62d97d | 16 | double _B[] = {NOTE_B0, NOTE_B1, NOTE_B2, NOTE_B3, NOTE_B4, |
yfkwok | 2:464c7e62d97d | 17 | NOTE_B5, NOTE_B6, NOTE_B7}; |
yfkwok | 2:464c7e62d97d | 18 | double _BS[] = {NOTE_C0, NOTE_C1, NOTE_C2, NOTE_C3, NOTE_C4, |
yfkwok | 2:464c7e62d97d | 19 | NOTE_C5, NOTE_C6, NOTE_C7, NOTE_C8}; |
yfkwok | 2:464c7e62d97d | 20 | double _C[] = {NOTE_C0, NOTE_C1, NOTE_C2, NOTE_C3, NOTE_C4, |
yfkwok | 2:464c7e62d97d | 21 | NOTE_C5, NOTE_C6, NOTE_C7, NOTE_C8}; |
yfkwok | 2:464c7e62d97d | 22 | double _CS[] = {NOTE_CS0, NOTE_CS1, NOTE_CS2, NOTE_CS3, NOTE_CS4, |
yfkwok | 2:464c7e62d97d | 23 | NOTE_CS5, NOTE_CS6, NOTE_CS7, NOTE_CS8}; |
yfkwok | 2:464c7e62d97d | 24 | double _D[] = {NOTE_D0, NOTE_D1, NOTE_D2, NOTE_D3, NOTE_D4, |
yfkwok | 2:464c7e62d97d | 25 | NOTE_D5, NOTE_D6, NOTE_D7, NOTE_D8}; |
yfkwok | 2:464c7e62d97d | 26 | double _DS[] = {NOTE_DS0, NOTE_DS1, NOTE_DS2, NOTE_DS3, NOTE_DS4, |
yfkwok | 2:464c7e62d97d | 27 | NOTE_DS5, NOTE_DS6, NOTE_DS7, NOTE_DS8}; |
yfkwok | 2:464c7e62d97d | 28 | double _E[] = {NOTE_E0, NOTE_E1, NOTE_E2, NOTE_E3, NOTE_E4, |
yfkwok | 2:464c7e62d97d | 29 | NOTE_E5, NOTE_E6, NOTE_E7}; |
yfkwok | 2:464c7e62d97d | 30 | double _ES[] = {NOTE_F0, NOTE_F1, NOTE_F2, NOTE_F3, NOTE_F4, |
yfkwok | 2:464c7e62d97d | 31 | NOTE_F5, NOTE_F6, NOTE_F7}; |
yfkwok | 2:464c7e62d97d | 32 | double _F[] = {NOTE_F0, NOTE_F1, NOTE_F2, NOTE_F3, NOTE_F4, |
yfkwok | 2:464c7e62d97d | 33 | NOTE_F5, NOTE_F6, NOTE_F7}; |
yfkwok | 2:464c7e62d97d | 34 | double _FS[] = {NOTE_FS0, NOTE_FS1, NOTE_FS2, NOTE_FS3, NOTE_FS4, |
yfkwok | 2:464c7e62d97d | 35 | NOTE_FS5, NOTE_FS6, NOTE_FS7}; |
yfkwok | 2:464c7e62d97d | 36 | double _G[] = {NOTE_G0, NOTE_G1, NOTE_G2, NOTE_G3, NOTE_G4, |
yfkwok | 2:464c7e62d97d | 37 | NOTE_G5, NOTE_G6, NOTE_G7}; |
yfkwok | 2:464c7e62d97d | 38 | double _GS[] = {NOTE_GS0, NOTE_GS1, NOTE_GS2, NOTE_GS3, NOTE_GS4, |
yfkwok | 2:464c7e62d97d | 39 | NOTE_GS5, NOTE_GS6, NOTE_GS7}; |
yfkwok | 2:464c7e62d97d | 40 | |
yfkwok | 2:464c7e62d97d | 41 | /* |
yfkwok | 2:464c7e62d97d | 42 | * This is a lookup function to provide the correct |
yfkwok | 2:464c7e62d97d | 43 | * frequency given a note and an octave |
yfkwok | 2:464c7e62d97d | 44 | * |
yfkwok | 2:464c7e62d97d | 45 | * note - The given note character [A - G] |
yfkwok | 2:464c7e62d97d | 46 | * sharp - Whether the note is sharp (1) or not (0) |
yfkwok | 2:464c7e62d97d | 47 | * octave - The given octave [0 - 8] |
yfkwok | 2:464c7e62d97d | 48 | */ |
yfkwok | 2:464c7e62d97d | 49 | double notes::get_freq(char note, int sharp, int octave) { |
yfkwok | 2:464c7e62d97d | 50 | switch(note){ |
yfkwok | 2:464c7e62d97d | 51 | case 'A': |
yfkwok | 2:464c7e62d97d | 52 | //A Note |
yfkwok | 2:464c7e62d97d | 53 | if (octave>=0 && octave <=7){ |
yfkwok | 2:464c7e62d97d | 54 | if (sharp == 0){ |
yfkwok | 2:464c7e62d97d | 55 | return _A[octave]; |
yfkwok | 2:464c7e62d97d | 56 | } |
yfkwok | 2:464c7e62d97d | 57 | else{ |
yfkwok | 2:464c7e62d97d | 58 | return _AS[octave]; |
yfkwok | 2:464c7e62d97d | 59 | } |
yfkwok | 2:464c7e62d97d | 60 | } |
yfkwok | 2:464c7e62d97d | 61 | break; |
yfkwok | 2:464c7e62d97d | 62 | case 'B': |
yfkwok | 2:464c7e62d97d | 63 | //B Note |
yfkwok | 2:464c7e62d97d | 64 | if (octave>=0 && octave <=7){ |
yfkwok | 2:464c7e62d97d | 65 | if (sharp == 0){ |
yfkwok | 2:464c7e62d97d | 66 | return _B[octave]; |
yfkwok | 2:464c7e62d97d | 67 | } |
yfkwok | 2:464c7e62d97d | 68 | else{ |
yfkwok | 2:464c7e62d97d | 69 | return _BS[octave]; |
yfkwok | 2:464c7e62d97d | 70 | } |
yfkwok | 2:464c7e62d97d | 71 | } |
yfkwok | 2:464c7e62d97d | 72 | break; |
yfkwok | 2:464c7e62d97d | 73 | case 'C': |
yfkwok | 2:464c7e62d97d | 74 | //C Note |
yfkwok | 2:464c7e62d97d | 75 | if (octave>=0 && octave <=8){ |
yfkwok | 2:464c7e62d97d | 76 | if (sharp == 0){ |
yfkwok | 2:464c7e62d97d | 77 | return _C[octave]; |
yfkwok | 2:464c7e62d97d | 78 | } |
yfkwok | 2:464c7e62d97d | 79 | else{ |
yfkwok | 2:464c7e62d97d | 80 | return _CS[octave]; |
yfkwok | 2:464c7e62d97d | 81 | } |
yfkwok | 2:464c7e62d97d | 82 | } |
yfkwok | 2:464c7e62d97d | 83 | break; |
yfkwok | 2:464c7e62d97d | 84 | case 'D': |
yfkwok | 2:464c7e62d97d | 85 | //D Note |
yfkwok | 2:464c7e62d97d | 86 | if (octave>=0 && octave <=8){ |
yfkwok | 2:464c7e62d97d | 87 | if (sharp == 0){ |
yfkwok | 2:464c7e62d97d | 88 | return _D[octave]; |
yfkwok | 2:464c7e62d97d | 89 | } |
yfkwok | 2:464c7e62d97d | 90 | else{ |
yfkwok | 2:464c7e62d97d | 91 | return _DS[octave]; |
yfkwok | 2:464c7e62d97d | 92 | } |
yfkwok | 2:464c7e62d97d | 93 | } |
yfkwok | 2:464c7e62d97d | 94 | break; |
yfkwok | 2:464c7e62d97d | 95 | case 'E': |
yfkwok | 2:464c7e62d97d | 96 | //E Note |
yfkwok | 2:464c7e62d97d | 97 | if (octave>=0 && octave <=7){ |
yfkwok | 2:464c7e62d97d | 98 | if (sharp == 0){ |
yfkwok | 2:464c7e62d97d | 99 | return _E[octave]; |
yfkwok | 2:464c7e62d97d | 100 | } |
yfkwok | 2:464c7e62d97d | 101 | else{ |
yfkwok | 2:464c7e62d97d | 102 | return _ES[octave]; |
yfkwok | 2:464c7e62d97d | 103 | } |
yfkwok | 2:464c7e62d97d | 104 | } |
yfkwok | 2:464c7e62d97d | 105 | break; |
yfkwok | 2:464c7e62d97d | 106 | case 'F': |
yfkwok | 2:464c7e62d97d | 107 | //F Note |
yfkwok | 2:464c7e62d97d | 108 | if (octave>=0 && octave <=7){ |
yfkwok | 2:464c7e62d97d | 109 | if (sharp == 0){ |
yfkwok | 2:464c7e62d97d | 110 | return _F[octave]; |
yfkwok | 2:464c7e62d97d | 111 | } |
yfkwok | 2:464c7e62d97d | 112 | else{ |
yfkwok | 2:464c7e62d97d | 113 | return _FS[octave]; |
yfkwok | 2:464c7e62d97d | 114 | } |
yfkwok | 2:464c7e62d97d | 115 | } |
yfkwok | 2:464c7e62d97d | 116 | break; |
yfkwok | 2:464c7e62d97d | 117 | case 'G': |
yfkwok | 2:464c7e62d97d | 118 | //G Note |
yfkwok | 2:464c7e62d97d | 119 | if (octave>=0 && octave <=7){ |
yfkwok | 2:464c7e62d97d | 120 | if (sharp == 0){ |
yfkwok | 2:464c7e62d97d | 121 | return _G[octave]; |
yfkwok | 2:464c7e62d97d | 122 | } |
yfkwok | 2:464c7e62d97d | 123 | else{ |
yfkwok | 2:464c7e62d97d | 124 | return _GS[octave]; |
yfkwok | 2:464c7e62d97d | 125 | } |
yfkwok | 2:464c7e62d97d | 126 | } |
yfkwok | 2:464c7e62d97d | 127 | break; |
yfkwok | 2:464c7e62d97d | 128 | } |
yfkwok | 2:464c7e62d97d | 129 | return 0; |
yfkwok | 2:464c7e62d97d | 130 | } |