16. Interface and application programming#
group assignment: compare as many tool options as possible
Sonic Pi#
Sonic Pi is a code-based music creation and performance tool. The reason why it is called ‘Live coding’ is, you can change the code while playing the music without stop music. If you press [Run] again during playback, the changed chord will be applied without stopping the music playback.
After installing the mac version, we tried it in reference to the Tips.
MIDI notes and music notes
C4 | D4 | E4 | F4 | G4 | A4 | B4 |
---|---|---|---|---|---|---|
60 | 62 | 64 | 65 | 67 | 69 | 71 |
Chord example
1 2 3 4 5 6 | live_loop :flibble do play 60 play 64 play 67 sleep 0.5 end |
The chord is same as below
1 2 3 4 5 6 | live_loop :flibble do play :C4 play :E4 play :G4 sleep 0.5 end |
To create music with pre-recorded samples, add the name of sample as follows.
1 2 3 4 | live_loop :flibble do sample :bd_haus, rate: 1 sleep 0.5 end |
We explored how to communicate with application such as Processing With reference to the site. Sonic Pi can communicate with other application with simple protocol called OSC - Open Sound Control. Processing application sends note and decay via IP:127.0.0.1/Port:4559 according to the mouse click position, and Sonic Pi plays piano with the node and the decay. ‘/trigger/synth’ is the data label and note (=’a’ in SonicPi) and decay (=’b’ in Sonic Pi )are arguments.
Sonic Pi code
1 2 3 4 5 | live_loop :trigger do use_real_time a, b, c = sync "/osc/trigger/synth" synth :piano, note: a, pan: b, sustain: c end |
Processing code It is necessary to import oscP5 library in davance.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | import oscP5.*; import netP5.*; OscP5 oscP5; NetAddress nAdd; void setup() { size(480, 320); frameRate(60); oscP5 = new OscP5(this, 12000); nAdd = new NetAddress("127.0.0.1", 4559); } void draw() { background(0); if (mousePressed) { ellipse(mouseX, mouseY, 40, 40); } } void mouseReleased() { float note = map(mouseX, 0, width, 20, 120); float decay = map(mouseY, 0, height, 0, 5); OscMessage msg = new OscMessage("/trigger/synth"); msg.add(note); msg.add(decay); oscP5.send(msg, nAdd); println(msg); } |