MIDI Interface in progress
Dependencies: SPI_TFT_ILI9341 TFT_fonts Touch_tft PowerControl mbed USBMIDI
Diff: touch_interface.h
- Revision:
- 15:c297064a829b
- Child:
- 16:f4d090f1e6ed
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/touch_interface.h Mon Feb 24 09:54:44 2014 +0000 @@ -0,0 +1,136 @@ +#include "touch_tft.h" +#include "SPI_TFT_ILI9341.h" +#include "USBMIDI.h" + +// short slider = 8192; +extern unsigned short Oct = 36; //default octave C1 + +// the TFT is connected to SPI pin 5-7 +// the touch is connected to 19,20,17,18 +touch_tft tft(p20,p19,p18,p17,p5, p6, p7, p14, p15, p21, "TFT"); // x+,x-,y+,y-,mosi, miso, sclk, cs, reset, dc +DigitalIn key[9] = {p22, p23, p24, p25, p26, p27, p28, p29, p30}; //inputit + +unsigned char i; +bool pressed_keys[9] = {0}; + +USBMIDI midi; + +void Nine_keys(void) +{ + for (i = 0; i < 9; i++) { + if (!key[i].read() & !pressed_keys[i]) { + midi.write(MIDIMessage::NoteOn(Oct + i)); + pressed_keys[i] = true; + } + if (key[i].read() & pressed_keys[i]) { + midi.write(MIDIMessage::NoteOff(Oct + i)); + pressed_keys[i] = false; + } + } +} + +void Buttons(unsigned char b, unsigned short color) //Button Field +{ + if (b == 1) { //Slider + tft.fillrect(3,96,78,318,color); + } + if (b == 2) { //Octave Reset + tft.fillrect(163,163,238,238,color); + } + if (b == 3) { //Octave DOWN + tft.fillrect(83,243,158,318,color); + } + if (b == 4) { //Octave UP + tft.fillrect(163,243,238,318,color); + } +} + +void Draw_buttons(unsigned short color) //Draws Button Field +{ + unsigned char i = 0; + + for (i = 0; i<5; i++) { + //tft.locate(10,50); + Buttons(i, color); + } +} + +void Slider_action(point p) +{ + if (p.x > 3 && p.x < 78) { //Slider + if (p.y > 88 && p.y < 111) { + //tft.fillrect(3,88,78,111,Red); + midi.write(MIDIMessage::PitchWheel(8192)); + } + if (p.y > 111 && p.y < 134) { + //tft.fillrect(3,111,78,134,Red); + midi.write(MIDIMessage::PitchWheel(6400)); + } + if (p.y > 134 && p.y < 157) { + //tft.fillrect(3,111,78,157,Red); + midi.write(MIDIMessage::PitchWheel(4915)); + } + if (p.y > 157 && p.y < 180) { + //tft.fillrect(3,111,78,180,Red); + midi.write(MIDIMessage::PitchWheel(3277)); + } + if (p.y > 180 && p.y < 203) { + //tft.fillrect(3,111,78,203,Red); + midi.write(MIDIMessage::PitchWheel(1638)); + } + if (p.y > 203 && p.y < 226) { + //tft.fillrect(3,111,78,226,Red); + midi.write(MIDIMessage::PitchWheel(0)); + } + if (p.y > 226 && p.y < 249) { + //tft.fillrect(3,111,78,249,Red); + midi.write(MIDIMessage::PitchWheel(-1638)); + } + if (p.y > 249 && p.y < 272) { + //tft.fillrect(3,111,78,272,Red); + midi.write(MIDIMessage::PitchWheel(-3277)); + } + if (p.y > 272 && p.y < 295) { + //tft.fillrect(3,111,78,295,Red); + midi.write(MIDIMessage::PitchWheel(-4915)); + } + if (p.y > 295 && p.y < 318) { + //tft.fillrect(3,111,78,318,Red); + midi.write(MIDIMessage::PitchWheel(-8192)); + } + } +} + + +void Octave_buttons(unsigned short color, point p) +{ + if (p.y > 243 && p.y < 318) { //ROW C + if (p.x > 83 && p.x < 158) { //Octave down + Buttons(3, color); + Oct -= 12; + wait(0.2); + Buttons(3, White); + } + if (p.x > 163 && p.x < 238) { //Octave up + Buttons(4, color); + Oct += 12; + wait(0.2); + Buttons(4, White); + } + } + + if (p.y > 163 && p.y < 238) { //ROW B + if (p.x > 163 && p.x < 238) { //Octave reset + Oct = 36; + Buttons(2, Cyan); + wait(0.2); + Buttons(2, White); + } + } + + if (Oct > 120) Oct -=12; //Octave range 12-120. + if (Oct < 12) Oct +=12; +} + + +