Advertisement
Guest User

Untitled

a guest
Jul 29th, 2016
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. import processing.serial.*;
  2.  
  3. import themidibus.*; //Import the library
  4.  
  5. MidiBus myBus; // The MidiBus
  6.  
  7. Serial myPort; // The serial port
  8. int xPos = 1; // horizontal position of the graph
  9. float inByte = 0;
  10.  
  11. void setup () {
  12. MidiBus.list();
  13. // set the window size:
  14. size(900, 400);
  15.  
  16. // List all the available serial ports
  17. // if using Processing 2.1 or later, use Serial.printArray()
  18. println(Serial.list());
  19. myBus = new MidiBus(this, 1, 3); // Create a new MidiBus with no input device and the default Java Sound Synthesizer as the output device.
  20. // I know that the first port in the serial list on my mac
  21. // is always my Arduino, so I open Serial.list()[0].
  22. // Open whatever port is the one you're using.
  23. myPort = new Serial(this, Serial.list()[1], 115200);
  24.  
  25. // don't generate a serialEvent() unless you get a newline character:
  26. myPort.bufferUntil('\n');
  27.  
  28. // set inital background:
  29. background(0);
  30. }
  31. void draw () {
  32.  
  33.  
  34.  
  35.  
  36. // draw the line:
  37. stroke(127, 34, 255);
  38. line(xPos, height, xPos, height - inByte);
  39.  
  40. // at the edge of the screen, go back to the beginning:
  41. if (xPos >= width) {
  42. xPos = 0;
  43. background(255,255,255);
  44. } else {
  45. // increment the horizontal position:
  46. xPos++;
  47. }
  48. }
  49.  
  50.  
  51. void serialEvent (Serial myPort) {
  52. // get the ASCII string:
  53. String inString = myPort.readStringUntil('\n');
  54.  
  55.  
  56. if (inString != null) {
  57. // trim off any whitespace:
  58. inString = trim(inString);
  59. // convert to an int and map to the screen height:
  60. inByte = int(inString);
  61.  
  62. println(inByte);
  63. int a = 56;
  64. inByte = map(inByte, 0, 1023, 0, 127);
  65. int test = int(inByte);
  66. if(inByte > 2){
  67. myBus.sendNoteOn(1, 38, test); // Send a Midi noteOn
  68. delay(1);
  69. inByte--;
  70. myBus.sendNoteOff(1, 38, test); // Send a Midi nodeOff
  71.  
  72.  
  73. }
  74. }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement