From 24f309fb8bda44b28f54220eb03cf759e3b07653 Mon Sep 17 00:00:00 2001 From: emanuels Date: Wed, 7 Aug 2024 16:38:40 -0300 Subject: [PATCH] add code --- midi_gh.pde | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 midi_gh.pde diff --git a/midi_gh.pde b/midi_gh.pde new file mode 100644 index 0000000..6d5f581 --- /dev/null +++ b/midi_gh.pde @@ -0,0 +1,75 @@ +import themidibus.*; + +MidiBus myBus; +ArrayList squares; +ArrayList velocities; +color[] pitchColors; + +void setup() { + size(400, 400); + squares = new ArrayList(); + velocities = new ArrayList(); + MidiBus.list(); + myBus = new MidiBus(this, 2, 3); + + pitchColors = new color[128]; + for (int pitch = 0; pitch < 128; pitch++) { + if (pitch == 36){ + pitchColors[pitch] = color(255, 255, 255); + } + if (pitch == 38){ + pitchColors[pitch] = color(255, 0, 0); + } + if (pitch == 48){ + pitchColors[pitch] = color(0, 0, 255); + } + if (pitch == 45){ + pitchColors[pitch] = color(0, 255, 0); + } + if (pitch == 46){ + pitchColors[pitch] = color(205, 85, 0); + } + if (pitch == 49){ + pitchColors[pitch] = color(255, 255, 0); + } + } +} + +void draw() { + background(0); + + for (int i = 0; i < squares.size(); i++) { + PVector square = squares.get(i); + int pitch = (int) square.z; + int velocity = velocities.get(i); + fill(pitchColors[pitch]); + rect(square.x, square.y, velocity, velocity); + } +} + +void noteOn(int channel, int pitch, int velocity) { + println("--------"); + println("Channel: "+channel, "Pitch: "+pitch, "Velocity: "+velocity); + if (pitch == 36 || pitch == 38 || pitch == 48 || pitch == 45 || pitch == 46 || pitch == 49) { + squares.add(new PVector(random(width), random(height), pitch)); + velocities.add(velocity); + } +} + +void noteOff(int channel, int pitch, int velocity) { + println("--------"); + println("Channel: "+channel, "Pitch: "+pitch, "Velocity: "+velocity); + if (pitch == 36 || pitch == 38 || pitch == 48 || pitch == 45 || pitch == 46 || pitch == 49) { + for (int i = squares.size() - 1; i >= 0; i--) { + if (squares.get(i).z == pitch) { + squares.remove(i); + velocities.remove(i); + } + } + } +} + +void controllerChange(int channel, int number, int value) { + println("--------"); + println("Channel: "+channel, "Number: "+number, "Value: "+value); +}