Ben Centra
@TheBenCentra
blcentra@gmail.com
bencentra.com
BarCamp Rochester - Spring 2014
import themidibus.*
MidiBus mb;
void setup() {
// See available MIDI ins/outs
MidiBus.list();
// MidiBus(PApplet sketch, int input, int output)
mb = new MidiBus(this, -1, 1);
}
void draw() {
// Play a note on channel 0 of pitch 60 (C) and velocity 80
mb.sendNoteOn(0, 60, 127);
delay(500);
// Stop the note
mb.sendNoteOff(0, 60, 127);
delay(500);
}
public void run() { while (running && counter < repeats) { // Send a noteOn message noteOn(); // Sleep for the note's duration try { sleep((long) duration); } catch (Exception e) { println("Problem sleeping thread..."); println(e.getMessage()); } // Send a note off event and quit executing noteOff(); if (!infinite) { counter++; } } running = false; counter = 0;
}
public void run() {
while (running && counter < repeats) {
// Play the notes in the chord
for (int i = 0; i < notes.size(); i++) {
notes.get(i).start();
}
// Sleep for the chord's duration
try {
sleep((long) duration);
} catch (Exception e) {
println("Problem sleeping thread...");
println(e.getMessage());
}
// Stop the notes in the chord
counter++;
}
running = false;
counter = 0;
}
public void run() {
// Loop through each note in the sequence
while(running && counter < repeats) {
int c = 0;
while (c < notes.size()) {
// Grab and play the current note in the sequence
RiriObject currentNote = notes.get(c).clone();
int wait = currentNote.duration() * currentNote.repeats();
currentNote.start();
// Sleep for the duration of the note
try {
//sleep((long) currentNote.duration());
sleep((long) wait);
} catch (Exception e) {
println("Problem sleeping thread...");
println(e.getMessage());
}
c++;
}
if (!infinite) {
counter++;
}
}
// If we're out of notes, stop executing
running = false;
counter = 0;
println("Done");
}
Ben Centra
@TheBenCentra
blcentra@gmail.com
bencentra.com