Skip to content

Commit 395d613

Browse files
committed
Processing example synced with MIDI clock
0 parents  commit 395d613

File tree

2 files changed

+78
-0
lines changed

2 files changed

+78
-0
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
3+
Basic tutorial to create animations in sync with a MIDI clock
4+
by: luiscript
5+
6+
7+
Important info about MIDI clock standard:
8+
9+
clock 0xF8 (248)
10+
start 0xFA (250)
11+
continue 0xFB (251)
12+
stop 0xFC (252)
13+
14+
15+
*/
16+
17+
import themidibus.*; // download this library or you would get an error
18+
19+
MidiBus myBus; // this is or MIDI bus object
20+
21+
int timing = 0; // counts the total of quarter notes
22+
float lfo = 0.0; // this will be our LFO
23+
24+
void setup() {
25+
size(400, 400);
26+
background(0);
27+
28+
//this prints all the available MIDI ports
29+
MidiBus.list();
30+
31+
//select the MIDI port of your preference
32+
//in my case port 0 named "Bus 1"
33+
myBus = new MidiBus(this, 0, "Bus 1");
34+
}
35+
36+
37+
//this function will be called when raw MIDI data arrives
38+
void rawMidi(byte[] data) {
39+
40+
if(data[0] == (byte)0xFC) { // TRUE when MIDI clock stops.
41+
42+
// reset timing when clock stops to stay in sync for the next start
43+
timing = 0;
44+
45+
} else if(data[0] == (byte)0xF8) { // TRUE every MIDI clock pulse
46+
47+
//we need to increase timing every pulse to get the total count
48+
timing++;
49+
50+
// MIDI clock sends 24 ppqn (pulses per quarter note)
51+
// with this formula, lfo will oscillate between 0 and 1 every quarter note
52+
lfo = ( timing % 24 ) / 24.0;
53+
54+
// now you can use lfo to easily animate whatever you want in sync with BPM
55+
}
56+
}
57+
58+
void draw() {
59+
background(0);
60+
61+
//since we have lfo oscillating between 0 and 1, we can use it to animate the size of this ellipse in sync
62+
ellipse(width/2, height/2, 100 * lfo, 100 * lfo);
63+
}
64+
65+
66+
// Enjoy
67+
// @luiscript

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
### NSYNC
2+
3+
If you think this is related with a Boy Band, ~~fuck off~~ ¡Bye! ¡Bye! ¡Bye!
4+
5+
This is a repository containing basic examples that will teach you how to sync animations created with tools like processing.
6+
7+
Processing example is synced with MIDI clock.
8+
9+
### Autor
10+
Luis Fernando García
11+
[@luiscript](https://twitter.com/luiscript)

0 commit comments

Comments
 (0)