Display Class for BaseMachine

Committer:
ryood
Date:
Sun Aug 28 07:40:02 2016 +0000
Revision:
6:ec1d00fa9835
Parent:
5:6264a3682865
Child:
7:13a13dd9a00b
exchange displayWhileRun() and displayWhileStop()

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ryood 0:9a0f67fe026b 1 /*
ryood 0:9a0f67fe026b 2 * ST7565_SequencerDisplay.h
ryood 0:9a0f67fe026b 3 *
ryood 0:9a0f67fe026b 4 * 2016.08.13
ryood 0:9a0f67fe026b 5 *
ryood 0:9a0f67fe026b 6 */
ryood 0:9a0f67fe026b 7 #ifndef _ST7565_SEQUENCE_DISPLAY_H_
ryood 0:9a0f67fe026b 8 #define _ST7565_SEQUENCE_DISPLAY_H_
ryood 0:9a0f67fe026b 9
ryood 4:e51a5f0891a0 10 #define DISPLAY_PARAMS_ON_LCD (0)
ryood 4:e51a5f0891a0 11
ryood 0:9a0f67fe026b 12 #include "mbed.h"
ryood 0:9a0f67fe026b 13 #include "SequencerDisplay.h"
ryood 0:9a0f67fe026b 14 #include "st7565LCD.h"
ryood 0:9a0f67fe026b 15
ryood 0:9a0f67fe026b 16 class ST7565_SequencerDisplay : public SequencerDisplay {
ryood 0:9a0f67fe026b 17 public:
ryood 0:9a0f67fe026b 18 ST7565_SequencerDisplay(ST7565* _gLCD, Sequence* _sequences, int _sequenceNum) :
ryood 0:9a0f67fe026b 19 SequencerDisplay(_sequences, _sequenceNum),
ryood 0:9a0f67fe026b 20 gLCD(_gLCD) {};
ryood 0:9a0f67fe026b 21
ryood 0:9a0f67fe026b 22 protected:
ryood 6:ec1d00fa9835 23 virtual void displayWhileStop(int step) {
ryood 0:9a0f67fe026b 24 int x, y;
ryood 0:9a0f67fe026b 25 int i;
ryood 0:9a0f67fe026b 26
ryood 0:9a0f67fe026b 27 gLCD->clear();
ryood 0:9a0f67fe026b 28
ryood 0:9a0f67fe026b 29 // Pos Indicator Grid
ryood 0:9a0f67fe026b 30 for (x = 0; x <= 16; x++) {
ryood 0:9a0f67fe026b 31 gLCD->drawline(x * 7, 0, x * 7, 3, 1);
ryood 0:9a0f67fe026b 32 }
ryood 0:9a0f67fe026b 33 for (y = 0; y <= 1; y++) {
ryood 0:9a0f67fe026b 34 gLCD->drawline(0, y * 3, 112, y * 3, 1);
ryood 0:9a0f67fe026b 35 }
ryood 0:9a0f67fe026b 36
ryood 6:ec1d00fa9835 37 gLCD->fillrect(step * 7, 1, 7, 2, 1);
ryood 0:9a0f67fe026b 38
ryood 0:9a0f67fe026b 39 // Sequence Grid
ryood 0:9a0f67fe026b 40 for (x = 0; x <= 16; x++) {
ryood 0:9a0f67fe026b 41 gLCD->drawline(x * 7, 5, x * 7, 57, 1);
ryood 0:9a0f67fe026b 42 }
ryood 0:9a0f67fe026b 43 for (y = 0; y <= 13; y++) {
ryood 0:9a0f67fe026b 44 gLCD->drawline(0, y * 4 + 5, 112, y * 4 + 5, 1);
ryood 0:9a0f67fe026b 45 }
ryood 0:9a0f67fe026b 46
ryood 0:9a0f67fe026b 47 for (i = 0; i < 16; i++) {
ryood 5:6264a3682865 48 int noteOctave = (sequences[i].getPitch() / 12) - (Sequence::getBaseNoteNumber() / 12);
ryood 5:6264a3682865 49 int pitchInOctave = sequences[i].getPitch() % 12; // 表示中のOctave内のPitch
ryood 5:6264a3682865 50 // Octave内の12音階とOctave+1のPitch=0を表示
ryood 5:6264a3682865 51 if (this->getOctave() == noteOctave) {
ryood 5:6264a3682865 52 int pitchRev = 12 - pitchInOctave; // Pitchの位置をGridの下から上に変換
ryood 1:1f6d3e65d946 53 gLCD->fillrect(i * 7, pitchRev * 4 + 5, 7, 4, 1);
ryood 0:9a0f67fe026b 54 }
ryood 5:6264a3682865 55 if ((this->getOctave() + 1 == noteOctave) && (pitchInOctave == 0)) {
ryood 5:6264a3682865 56 gLCD->fillrect(i * 7, 5, 7, 4, 1);
ryood 5:6264a3682865 57 }
ryood 0:9a0f67fe026b 58 }
ryood 0:9a0f67fe026b 59
ryood 0:9a0f67fe026b 60 // NoteOn & Tie Grid
ryood 0:9a0f67fe026b 61 for (x = 0; x <= 16; x++) {
ryood 0:9a0f67fe026b 62 gLCD->drawline(x * 7, 57, x * 7, 63, 1);
ryood 0:9a0f67fe026b 63 }
ryood 0:9a0f67fe026b 64 gLCD->drawline(0, 63, 112, 63, 1);
ryood 0:9a0f67fe026b 65
ryood 0:9a0f67fe026b 66 for (i = 0; i < 16; i++) {
ryood 3:5b11261a545a 67 if (sequences[i].isNoteOn()) {
ryood 3:5b11261a545a 68 if (sequences[i].isAccent() && sequences[i].isTie()) {
ryood 0:9a0f67fe026b 69 gLCD->fillrect(i * 7, 57, 7, 6, 1);
ryood 0:9a0f67fe026b 70 } else {
ryood 0:9a0f67fe026b 71 gLCD->fillrect(i * 7, 59, 5, 4, 1);
ryood 3:5b11261a545a 72 if (sequences[i].isAccent()) {
ryood 0:9a0f67fe026b 73 gLCD->fillrect(i * 7, 57, 5, 4, 1);
ryood 0:9a0f67fe026b 74 }
ryood 3:5b11261a545a 75 if (sequences[i].isTie()) {
ryood 0:9a0f67fe026b 76 gLCD->fillrect(i * 7 + 5, 59, 2, 4, 1);
ryood 0:9a0f67fe026b 77 }
ryood 0:9a0f67fe026b 78 }
ryood 0:9a0f67fe026b 79 }
ryood 4:e51a5f0891a0 80 }
ryood 4:e51a5f0891a0 81
ryood 4:e51a5f0891a0 82 char buff[32];
ryood 4:e51a5f0891a0 83 sprintf(buff, "%2d", this->getOctave());
ryood 4:e51a5f0891a0 84 gLCD->drawstring(115, 0, "OC");
ryood 4:e51a5f0891a0 85 gLCD->drawstring(115, 1, buff);
ryood 4:e51a5f0891a0 86
ryood 4:e51a5f0891a0 87 #if (DISPLAY_PARAMS_ON_LCD)
ryood 4:e51a5f0891a0 88 char* s;
ryood 4:e51a5f0891a0 89 switch (waveShape) {
ryood 4:e51a5f0891a0 90 case 0:
ryood 4:e51a5f0891a0 91 s = "SQ";
ryood 4:e51a5f0891a0 92 break;
ryood 4:e51a5f0891a0 93 case 1:
ryood 4:e51a5f0891a0 94 s = "SW";
ryood 4:e51a5f0891a0 95 break;
ryood 4:e51a5f0891a0 96 }
ryood 4:e51a5f0891a0 97 gLCD->drawstring(115, 2, s);
ryood 4:e51a5f0891a0 98
ryood 4:e51a5f0891a0 99 gLCD->drawstring(115, 3, "MN");
ryood 4:e51a5f0891a0 100 sprintf(buff, "%2d", this->getModNumber());
ryood 4:e51a5f0891a0 101 gLCD->drawstring(115, 4, buff);
ryood 4:e51a5f0891a0 102
ryood 4:e51a5f0891a0 103 sprintf(buff, "%3d", this->getBpm());
ryood 4:e51a5f0891a0 104 gLCD->drawstring(109, 5, "BPM");
ryood 4:e51a5f0891a0 105 gLCD->drawstring(109, 6, buff);
ryood 4:e51a5f0891a0 106 #endif // DISPLAY_PARAMS_ON_LCD
ryood 0:9a0f67fe026b 107
ryood 0:9a0f67fe026b 108 gLCD->display();
ryood 0:9a0f67fe026b 109 };
ryood 0:9a0f67fe026b 110
ryood 6:ec1d00fa9835 111 virtual void displayWhileRun(int step) {
ryood 6:ec1d00fa9835 112 gLCD->fillrect((step-1) * 7, 1, 7, 1, 0);
ryood 6:ec1d00fa9835 113 gLCD->fillrect(step * 7, 1, 7, 1, 1);
ryood 6:ec1d00fa9835 114 //gLCD->display();
ryood 6:ec1d00fa9835 115 /*
ryood 6:ec1d00fa9835 116 char buff[32];
ryood 6:ec1d00fa9835 117 sprintf(buff, "%d ", step);
ryood 6:ec1d00fa9835 118 gLCD->clear();
ryood 6:ec1d00fa9835 119 gLCD->drawstring(0, 0, buff);
ryood 6:ec1d00fa9835 120 gLCD->display();
ryood 6:ec1d00fa9835 121 */
ryood 2:60f7d4c54b5f 122 }
ryood 2:60f7d4c54b5f 123
ryood 2:60f7d4c54b5f 124 void displayParams(int step) {
ryood 1:1f6d3e65d946 125 char buff[64];
ryood 1:1f6d3e65d946 126 gLCD->clear();
ryood 1:1f6d3e65d946 127 sprintf(buff, "Step: %d", step);
ryood 1:1f6d3e65d946 128 gLCD->drawstring(0, 0, buff);
ryood 1:1f6d3e65d946 129 sprintf(buff, "Pitch: %d", sequences[step].getPitch());
ryood 1:1f6d3e65d946 130 gLCD->drawstring(0, 1, buff);
ryood 1:1f6d3e65d946 131 sprintf(buff, "BPM: %d", this->getBpm());
ryood 1:1f6d3e65d946 132 gLCD->drawstring(0, 2, buff);
ryood 1:1f6d3e65d946 133 gLCD->display();
ryood 2:60f7d4c54b5f 134 };
ryood 1:1f6d3e65d946 135
ryood 0:9a0f67fe026b 136 private:
ryood 0:9a0f67fe026b 137 ST7565* gLCD;
ryood 0:9a0f67fe026b 138
ryood 0:9a0f67fe026b 139 };
ryood 0:9a0f67fe026b 140
ryood 0:9a0f67fe026b 141 #endif //ST7565_SEQUENCE_DISPLAY_H_