Hi, im developing an instrument with makey makey, processing and sonic-pi, it is simple, just send OSC messages from Processing towards Sonic Pi when i press a keyboard. The question is that i may send simultaneous and fast messages and when i’m playing sometimes it crashes and stop receiving messages (or sending from processing, i’m not really shure) so, i wonder if it is a problem of hardware, software or if someone know how to improve this in a not so hard way, my system specs are the following:
| Model Name:|MacBook Pro|
| Model Identifier:|MacBookPro5,3|
| Processor Name:|Intel Core 2 Duo|
| Processor Speed:|2.8 GHz|
| Number of Processors:|1|
| Total Number of Cores:|2|
| L2 Cache:|6 MB|
| Memory:|4 GB|
| Bus Speed:|1.07 GHz|
im using processing 3.3.6 and sonic-pi 3.0.1
Hi there,
how many messages are you sending per second from Processing? Do you have a simple way of reproducing the issue?
I’m new here, i dont know exactly how to adjunt the code in the best way, but here you have the sonic-pi and processing code i’m using
Sonic-Pi Code
Processing code
And about the velocity the faster i play should be like 400BPM (around 7 messages per second)
Hi there
I’ve downloaded your code and it runs fine on my Mac which is a bit more powerful than yours I think MPB with 2.8GHz Intel core i7
I can play all the internal samples at speed using your processing input. I haven;t got your external samples, and I think they might slow things down a bit.
Incidentally, I notice you have Sonic Pi 3.0.1 version 3.1 is available for the Mac so you might get a better response from this. You can also use the use_real_time
command instead of setting the sched ahead time to 0.0001
It may also be worth trying putting each sample into its own live loop. You have some overhead as all teh conditions are checked, whereas using separate loops may give a quicker response.
I altered your code to this:
use_real_time
use_debug false
tarola = "/Users/Mayorga/Google Drive/Sonic-Pi/samples/drum_hydrogen/tarola.flac"
stick = "/Users/Mayorga/Google Drive/Sonic-Pi/samples/drum_hydrogen/stick.flac"
#----------------------------------------------------------------------------------------------------banco 1
live_loop :os do
nv=sync "/osc/edrum0"
sample :drum_splash_hard, amp: 0.3, pan: -1 if (nv[0] == 1)
end
live_loop :os2 do
nv=sync "/osc/edrum0"
sample :drum_cymbal_closed, amp: 2, pan: -1 if (nv[0] == 2)
end
live_loop :os3 do
nv=sync "/osc/edrum0"
sample :bd_haus, pan: 0 if (nv[0] == 3)
end
live_loop :os4 do
nv=sync "/osc/edrum0"
sample :bd_haus, pan: 0 if (nv[0] == 4)
end
live_loop :os5 do
nv=sync "/osc/edrum0"
sample :drum_cymbal_open, amp: 0.3, pan: 0.7, pan: -1 if (nv[0] == 5)
end
live_loop :os6 do
nv=sync "/osc/edrum0"
sample :elec_cymbal, amp: 0.3, pan: -0.7, pan: -1 if (nv[0] == 6)
end
live_loop :os7 do
nv=sync "/osc/edrum0"
sample stick, amp: 1, pan: -1 if (nv[0] == 7)
end
live_loop :os8 do
nv=sync "/osc/edrum0"
sample :sn_zome, amp: 1, pan: -1 if (nv[0] == 8)
end
live_loop :os9 do
nv=sync "/osc/edrum0"
sample tarola, amp: 2, pan: -1 if (nv[0] == 9)
end
live_loop :os10 do
nv=sync "/osc/edrum0"
sample :sn_dolf, amp: 1, pan: -1 if (nv[0] == 10)
end
live_loop :os11 do
nv=sync "/osc/edrum0"
sample :drum_snare_hard, amp: 0.5, pan: -1 if (nv[0] == 11)
end
#----------------------------------------------------------------------------------------------------banco 2
live_loop :os12 do
nv=sync "/osc/edrum0"
sample :tabla_dhec if (nv[0] == 12)
end
live_loop :os13 do
nv=sync "/osc/edrum0"
sample :tabla_ghe1 if (nv[0] == 13)
end
live_loop :os14 do
nv=sync "/osc/edrum0"
sample :tabla_ke1 if (nv[0] == 14)
end
live_loop :os15 do
nv=sync "/osc/edrum0"
sample :tabla_na if (nv[0] == 15)
end
live_loop :os16 do
nv=sync "/osc/edrum0"
sample :tabla_tas1 if (nv[0] == 16)
end
live_loop :os17 do
nv=sync "/osc/edrum0"
sample :tabla_tun1 if (nv[0] == 17)
end
live_loop :os18 do
nv=sync "/osc/edrum0"
sample :tabla_te_m if (nv[0] == 18)
end
live_loop :os19 do
nv=sync "/osc/edrum0"
sample :tabla_tas3 if (nv[0] == 19)
end
live_loop :os20 do
nv=sync "/osc/edrum0"
sample :tabla_ghe6 if (nv[0] == 20)
end
live_loop :os21 do
nv=sync "/osc/edrum0"
sample :tabla_ke2 if (nv[0] == 21)
end
live_loop :os22 do
nv=sync "/osc/edrum0"
sample :tabla_ghe8 if (nv[0] == 22)
end
Just for documenting better, sometimes the program just stop responding for a while, but sometimes i get something like this and i have to replay:
then i tried your code and improves the behaviour but still stop for a while, now i installed the last version of sonic pi, have some troubles booting but finally it opens and your code works great, now it rocks, this is how the “Percutarra” (Drumitar)look and sound. Thank you so much RN and SA.
click here for listen: test_percutarra
2 Likes
Glad you got it going. The audio file sounds great. It is a very interesting project.
Sonic Pi handles concurrent processes well. Rearranging a single command to process in each live_loop rather than processing all of the samples in one loop means that it can keep up more easily, and I think that is why the alternative code works better. Otherwise, Sonic Pi gets too far behind when processing the live_loop and the error occurs.
You can paste both the Sonic Pi code (which effectively I have done above) and the processing code (which is a text file also) directly into a post here. Just put three ```
before and after the code and it will format it.
It would be good if you could write up the whole project, including the makey makey connection. I’m sure others here would be very interested.
I found the processing file a little difficult to download on my Mac. It seemed to want to open in windows notebook. So to document your code more fully here I have taken the liberty of adding the processing source code below, taken from your link in a previous post.
import oscP5.*; //libraries required
import netP5.*;
import controlP5.*;
OscP5 oscP5;
NetAddress sonicPi;
int sound = 0;
int b = 0;
int n = 2;
void setup() {
size(200, 200);
oscP5 = new OscP5(this, 8000);
sonicPi = new NetAddress("127.0.0.1",4559);
}
void sendOscNote(int ins ) {
OscMessage toSend = new OscMessage("/edrum0");
toSend.add(ins); //add mx and my values asss floating numbers
oscP5.send(toSend, sonicPi);
println(toSend);
}
void draw() {
background(51);
text(b,30,30);
}
void keyPressed() {
if (key == ' ') {
sound = 5 +b*11;
sendOscNote(sound);
}
else if (key == 'w') {
sound = 6+b*11;
sendOscNote(sound);
}
else if (key == 'a') {
sound = 7+b*11;
sendOscNote(sound);
}
else if (key == 's') {
sound = 8+b*11;
sendOscNote(sound);
}
else if (key == 'd') {
sound = 9+b*11;
sendOscNote(sound);
}
else if (key == 'f') {
sound = 10+b*11;
sendOscNote(sound);
}
else if (key == 'g') {
sound = 11+b*11;
sendOscNote(sound);
}
else if (key == CODED) {
if (keyCode == UP) {
sound = 4+b*11;
sendOscNote(sound);
}
else if (keyCode == DOWN) {
sound = 2+b*11;
sendOscNote(sound);
}
if (keyCode == RIGHT) {
sound = 1+b*11;
sendOscNote(sound);
}
else if (keyCode == LEFT) {
sound = 3+b*11;
sendOscNote(sound);
}
}
}
void mouseClicked() {
b++;
if (b == (n+1)){
b = 0;
}
}