Display Class for BaseMachine
ST7565_SequencerDisplay.h@12:e6b2b72db313, 2016-11-17 (annotated)
- Committer:
- ryood
- Date:
- Thu Nov 17 12:25:55 2016 +0000
- Revision:
- 12:e6b2b72db313
- Parent:
- 11:59d197b18cf5
- Child:
- 13:f95a117cddb8
Impl. Sequence pattern change
Who changed what in which revision?
User | Revision | Line number | New 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 | 8:2a06c35302e7 | 20 | gLCD(_gLCD), |
ryood | 8:2a06c35302e7 | 21 | runningStep(0) {}; |
ryood | 0:9a0f67fe026b | 22 | |
ryood | 9:a8adc9b9b3d8 | 23 | protected: |
ryood | 9:a8adc9b9b3d8 | 24 | void drawRunningStep(int step) { |
ryood | 9:a8adc9b9b3d8 | 25 | gLCD->fillrect(step * 7, 3, 8, 2, 1); |
ryood | 9:a8adc9b9b3d8 | 26 | } |
ryood | 9:a8adc9b9b3d8 | 27 | |
ryood | 9:a8adc9b9b3d8 | 28 | void drawSequenceGrid(int step) { |
ryood | 0:9a0f67fe026b | 29 | int x, y; |
ryood | 0:9a0f67fe026b | 30 | int i; |
ryood | 9:a8adc9b9b3d8 | 31 | |
ryood | 9:a8adc9b9b3d8 | 32 | // Step Indicator Grid |
ryood | 0:9a0f67fe026b | 33 | for (x = 0; x <= 16; x++) { |
ryood | 9:a8adc9b9b3d8 | 34 | gLCD->drawline(x * 7, 0, x * 7, 2, 1); |
ryood | 0:9a0f67fe026b | 35 | } |
ryood | 0:9a0f67fe026b | 36 | for (y = 0; y <= 1; y++) { |
ryood | 9:a8adc9b9b3d8 | 37 | gLCD->drawline(0, y * 2, 112, y * 2, 1); |
ryood | 0:9a0f67fe026b | 38 | } |
ryood | 0:9a0f67fe026b | 39 | |
ryood | 9:a8adc9b9b3d8 | 40 | gLCD->fillrect(step * 7, 1, 7, 1, 1); |
ryood | 0:9a0f67fe026b | 41 | |
ryood | 0:9a0f67fe026b | 42 | // Sequence Grid |
ryood | 0:9a0f67fe026b | 43 | for (x = 0; x <= 16; x++) { |
ryood | 0:9a0f67fe026b | 44 | gLCD->drawline(x * 7, 5, x * 7, 57, 1); |
ryood | 0:9a0f67fe026b | 45 | } |
ryood | 0:9a0f67fe026b | 46 | for (y = 0; y <= 13; y++) { |
ryood | 0:9a0f67fe026b | 47 | gLCD->drawline(0, y * 4 + 5, 112, y * 4 + 5, 1); |
ryood | 0:9a0f67fe026b | 48 | } |
ryood | 0:9a0f67fe026b | 49 | |
ryood | 0:9a0f67fe026b | 50 | for (i = 0; i < 16; i++) { |
ryood | 5:6264a3682865 | 51 | int noteOctave = (sequences[i].getPitch() / 12) - (Sequence::getBaseNoteNumber() / 12); |
ryood | 5:6264a3682865 | 52 | int pitchInOctave = sequences[i].getPitch() % 12; // 表示中のOctave内のPitch |
ryood | 5:6264a3682865 | 53 | // Octave内の12音階とOctave+1のPitch=0を表示 |
ryood | 5:6264a3682865 | 54 | if (this->getOctave() == noteOctave) { |
ryood | 5:6264a3682865 | 55 | int pitchRev = 12 - pitchInOctave; // Pitchの位置をGridの下から上に変換 |
ryood | 1:1f6d3e65d946 | 56 | gLCD->fillrect(i * 7, pitchRev * 4 + 5, 7, 4, 1); |
ryood | 0:9a0f67fe026b | 57 | } |
ryood | 5:6264a3682865 | 58 | if ((this->getOctave() + 1 == noteOctave) && (pitchInOctave == 0)) { |
ryood | 5:6264a3682865 | 59 | gLCD->fillrect(i * 7, 5, 7, 4, 1); |
ryood | 5:6264a3682865 | 60 | } |
ryood | 9:a8adc9b9b3d8 | 61 | } |
ryood | 9:a8adc9b9b3d8 | 62 | } |
ryood | 9:a8adc9b9b3d8 | 63 | |
ryood | 9:a8adc9b9b3d8 | 64 | void drawNoteGrid() { |
ryood | 9:a8adc9b9b3d8 | 65 | int x, i; |
ryood | 0:9a0f67fe026b | 66 | // NoteOn & Tie Grid |
ryood | 0:9a0f67fe026b | 67 | for (x = 0; x <= 16; x++) { |
ryood | 0:9a0f67fe026b | 68 | gLCD->drawline(x * 7, 57, x * 7, 63, 1); |
ryood | 0:9a0f67fe026b | 69 | } |
ryood | 0:9a0f67fe026b | 70 | gLCD->drawline(0, 63, 112, 63, 1); |
ryood | 0:9a0f67fe026b | 71 | |
ryood | 0:9a0f67fe026b | 72 | for (i = 0; i < 16; i++) { |
ryood | 3:5b11261a545a | 73 | if (sequences[i].isNoteOn()) { |
ryood | 3:5b11261a545a | 74 | if (sequences[i].isAccent() && sequences[i].isTie()) { |
ryood | 0:9a0f67fe026b | 75 | gLCD->fillrect(i * 7, 57, 7, 6, 1); |
ryood | 0:9a0f67fe026b | 76 | } else { |
ryood | 0:9a0f67fe026b | 77 | gLCD->fillrect(i * 7, 59, 5, 4, 1); |
ryood | 3:5b11261a545a | 78 | if (sequences[i].isAccent()) { |
ryood | 0:9a0f67fe026b | 79 | gLCD->fillrect(i * 7, 57, 5, 4, 1); |
ryood | 0:9a0f67fe026b | 80 | } |
ryood | 3:5b11261a545a | 81 | if (sequences[i].isTie()) { |
ryood | 0:9a0f67fe026b | 82 | gLCD->fillrect(i * 7 + 5, 59, 2, 4, 1); |
ryood | 0:9a0f67fe026b | 83 | } |
ryood | 0:9a0f67fe026b | 84 | } |
ryood | 0:9a0f67fe026b | 85 | } |
ryood | 4:e51a5f0891a0 | 86 | } |
ryood | 9:a8adc9b9b3d8 | 87 | } |
ryood | 9:a8adc9b9b3d8 | 88 | |
ryood | 9:a8adc9b9b3d8 | 89 | void drawOctave() { |
ryood | 4:e51a5f0891a0 | 90 | char buff[32]; |
ryood | 4:e51a5f0891a0 | 91 | sprintf(buff, "%2d", this->getOctave()); |
ryood | 4:e51a5f0891a0 | 92 | gLCD->drawstring(115, 0, "OC"); |
ryood | 4:e51a5f0891a0 | 93 | gLCD->drawstring(115, 1, buff); |
ryood | 9:a8adc9b9b3d8 | 94 | } |
ryood | 9:a8adc9b9b3d8 | 95 | |
ryood | 10:699beb99effe | 96 | void drawSequencePattern() { |
ryood | 10:699beb99effe | 97 | char buff[32]; |
ryood | 10:699beb99effe | 98 | sprintf(buff, "%02d", this->getSequencePattern()); |
ryood | 11:59d197b18cf5 | 99 | gLCD->drawstring(115, 2, "PT"); |
ryood | 10:699beb99effe | 100 | gLCD->drawstring(115, 3, buff); |
ryood | 10:699beb99effe | 101 | } |
ryood | 10:699beb99effe | 102 | |
ryood | 11:59d197b18cf5 | 103 | void drawWaveShape() { |
ryood | 11:59d197b18cf5 | 104 | char *str; |
ryood | 11:59d197b18cf5 | 105 | if (this->getWaveShape() == 0) { |
ryood | 11:59d197b18cf5 | 106 | str = "SQ"; |
ryood | 11:59d197b18cf5 | 107 | } else { |
ryood | 11:59d197b18cf5 | 108 | str = "SW"; |
ryood | 11:59d197b18cf5 | 109 | } |
ryood | 11:59d197b18cf5 | 110 | gLCD->drawstring(115, 5, str); |
ryood | 11:59d197b18cf5 | 111 | } |
ryood | 11:59d197b18cf5 | 112 | |
ryood | 9:a8adc9b9b3d8 | 113 | virtual void displayWhileStop(int editingStep, int runningStep) { |
ryood | 9:a8adc9b9b3d8 | 114 | gLCD->clear(); |
ryood | 4:e51a5f0891a0 | 115 | |
ryood | 9:a8adc9b9b3d8 | 116 | drawSequenceGrid(editingStep); |
ryood | 9:a8adc9b9b3d8 | 117 | drawNoteGrid(); |
ryood | 9:a8adc9b9b3d8 | 118 | drawRunningStep(runningStep); |
ryood | 10:699beb99effe | 119 | drawOctave(); |
ryood | 11:59d197b18cf5 | 120 | drawSequencePattern(); |
ryood | 11:59d197b18cf5 | 121 | drawWaveShape(); |
ryood | 0:9a0f67fe026b | 122 | |
ryood | 0:9a0f67fe026b | 123 | gLCD->display(); |
ryood | 0:9a0f67fe026b | 124 | }; |
ryood | 0:9a0f67fe026b | 125 | |
ryood | 9:a8adc9b9b3d8 | 126 | virtual void displayWhileRun(int editingStep, int runningStep) { |
ryood | 12:e6b2b72db313 | 127 | displayWhileStop(editingStep, runningStep); |
ryood | 12:e6b2b72db313 | 128 | /* |
ryood | 9:a8adc9b9b3d8 | 129 | gLCD->clear(); |
ryood | 7:13a13dd9a00b | 130 | |
ryood | 9:a8adc9b9b3d8 | 131 | drawSequenceGrid(editingStep); |
ryood | 9:a8adc9b9b3d8 | 132 | drawNoteGrid(); |
ryood | 9:a8adc9b9b3d8 | 133 | drawRunningStep(runningStep); |
ryood | 9:a8adc9b9b3d8 | 134 | drawOctave(); |
ryood | 10:699beb99effe | 135 | drawSequencePattern(); |
ryood | 11:59d197b18cf5 | 136 | drawWaveShape(); |
ryood | 9:a8adc9b9b3d8 | 137 | |
ryood | 6:ec1d00fa9835 | 138 | gLCD->display(); |
ryood | 12:e6b2b72db313 | 139 | */ |
ryood | 2:60f7d4c54b5f | 140 | } |
ryood | 12:e6b2b72db313 | 141 | /* |
ryood | 2:60f7d4c54b5f | 142 | void displayParams(int step) { |
ryood | 1:1f6d3e65d946 | 143 | char buff[64]; |
ryood | 1:1f6d3e65d946 | 144 | gLCD->clear(); |
ryood | 1:1f6d3e65d946 | 145 | sprintf(buff, "Step: %d", step); |
ryood | 1:1f6d3e65d946 | 146 | gLCD->drawstring(0, 0, buff); |
ryood | 1:1f6d3e65d946 | 147 | sprintf(buff, "Pitch: %d", sequences[step].getPitch()); |
ryood | 1:1f6d3e65d946 | 148 | gLCD->drawstring(0, 1, buff); |
ryood | 1:1f6d3e65d946 | 149 | sprintf(buff, "BPM: %d", this->getBpm()); |
ryood | 1:1f6d3e65d946 | 150 | gLCD->drawstring(0, 2, buff); |
ryood | 1:1f6d3e65d946 | 151 | gLCD->display(); |
ryood | 2:60f7d4c54b5f | 152 | }; |
ryood | 12:e6b2b72db313 | 153 | */ |
ryood | 1:1f6d3e65d946 | 154 | |
ryood | 0:9a0f67fe026b | 155 | private: |
ryood | 0:9a0f67fe026b | 156 | ST7565* gLCD; |
ryood | 8:2a06c35302e7 | 157 | int runningStep; |
ryood | 0:9a0f67fe026b | 158 | |
ryood | 0:9a0f67fe026b | 159 | }; |
ryood | 0:9a0f67fe026b | 160 | |
ryood | 0:9a0f67fe026b | 161 | #endif //ST7565_SEQUENCE_DISPLAY_H_ |