Array of samples osc

I’m back with osc isssues. Actually now it’s something I think more revolved about my insufficient knowledge of Sonic Pi programming… (at least I think, maybe it is something osc can’t achieve)

I want an array of 8 sounds (*.wav files)

And I want to trigger them when the corresponding number comes in.

Should I make 8 live loops? Or 1 live loop with 8 files in??

I just started to make the array and thought about how I would approach it. But I got stuck in my head with how to make it work…?

Can’t wrap my head around it.

1 Like

good evening,

For me one live_loop.

with an osc path /play/sample and argument 1 or 2 or 3

then you check with if 1 then play sample1. you can use case

case a
when 1
  puts "It's 1"
when 3
  puts "It's 3"
when 4
  puts "It's 4"
else
  puts "It's something else"
end

# different type of case
case
when a > 100
  puts "It's greater than 100"
when a == 50
  puts "It's 50"
else
  puts "It's something else"
end
1 Like

Following @nlb’s comment, that is the way I would go too. Funnily enough by coincidence I just used that in my recent project Sonic Pi 3.2.2 and Scratch 3 project
I you have a look at the project I used this to select from a whole range of samples using a keyboard in scratch3

1 Like

@samaaron Kobetran seems to be a robot no ?

I was beginning to wonder :thinking:

it (the robot :slight_smile: ) sends me three hearts and the website is a gaming website. so perhaps

1 Like

His bio translates as:

Kobe Tran is a young businessman from Vietnamese New Zealand. Wishing to build a reputable and top quality information website in Vietnam, undergo a …
gamebaidoithuong.vn/
45 Le Quat, Hoa Quy, Ngu Hanh Son, Da Nang

I’ve marked them as spam :slight_smile: Thanks for the heads up.

I’ll have to reopen this question. I’ve just found somebody who can help me with the nodejs coding part of my project that’s with a serious deadline. (Even had to pay somebody to get a project running, not one of my pridest moments :confused:)

But to be absolutely sure. If I send a trigger (message, int, value) into sonic pi. Can I use this to create a trigger to play one (or ideally more samples). (I’m thinking like a bang in max msp that triggers a different sound sample, and no I unfortunately can’t use max/msp.)

I can pounder on how to do this for a couple of days, I just need to be sure It’s possible before I hire the developer…

Sure, you can use incoming OSC to trigger anything you want.

Take a look at section 12 of the tutorial for more detail and some examples. If it doesn’t help you, please let me know so I can improve it :slight_smile:

https://sonic-pi.net/tutorial.html#section-12

@samaaron I’m taking free time that I have to try things out, still doing so. But small question.

Is it possible to send a number via osc ( this is possible ofcourse) and let it act as a frequency handler or timer.

Let’s say the number is 1.6 for example. This would mean in my case make sample run every 1.6 seconds. Or is this something that is not possible?

Hi @dewildequinten,

yes, if I understand you correctly it’s absolutely possible. All you’d need to do is to grab the number from an incoming OSC message and then use it as a value to a call to sleep or use_bpm :slight_smile:

1 Like

Any tutorials on this subject?

hi @dewildequinten

Any already made solution to special project :slight_smile: . We can help you but not do the job for you.
It’s not pleasant but it’s often the case in life…
So if you want to get some help from your code, publish the state of your searches and then i am pretty sure people would help you if they want or can.
Cheers

@nlb Exactly the reason why I asked for tutorials or examples of the subject. I already learned that I can’t expect completely build solutions for my specific project. Which I ofcourse completely logical. I’ve already had lot’s of insights and help from the people from this forum, for this project and former projects. And I’m very grateful to those people! It’s the reason why I keep coming back for SonicPi to add to my projects. Because of the user based help I’m getting!

Maybe I asked the question in a wrong matter. Because the thing is I don’t know what to look for (terminology wise) to go through the help files to learn about the code for my specific reasons.

if i understand what you’re trying to achieve, i propose this code

use_bpm 40


live_loop :setTempo do
  use_real_time
  
  tempo = sync "/osc:127.0.0.1:7777/tempo"
  set :pulse, tempo[0].to_int
end


live_loop :test do
  
  use_real_time
  use_bpm get[:pulse]
  
  play :c4
  sleep 1
  play :e4
  sleep 1
  play :g4
  sleep 1
  play :c5
  sleep 1
  
  
end

Sonic Pi receives osc message from an external program on the path /tempo with a changing value to vary the tempo of the live_loop test.

HI @nlb, I’m picking back up on this part of the thread because I started back from the start.
(FYI thank you for you last response, but I’ve found out how to do the frequency with javascript!)

So I’m using the case way. With this code I should get console logs from the osc input. But that’s not happening.

incoming osc messages are 1.0,2.0,3.0,4.0,5.0,6.0,7.0

    use_osc "localhost",4560 #address where osc messages will be sent

use_debug false
use_osc_logging false


live_loop :playsample do
  a = sync "/osc/trigger/prophet"
  
  case a
  when 1.0
    puts "hello"    
  when 2
    puts "two"
  when 3
    puts "three"
  when 4.0
    puts "hello"
  when 5.0
    puts "two"
  when 6.0
    puts "three"
  when 7.0
    puts "three"
  else
    puts "error"
  end
end

I’ve used print as well but I get no changes. And I don’t find any more info on the case lang.

a is a list so you need to test the first (0th) element in this list
Below I’ve amended your program and added a test live loop to send specimen data

use_osc "localhost",4560 #address where osc messages will be sent

#test live_loop to send osc messages
live_loop :test do
  osc "/trigger/prophet",(ring 1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0).tick
  sleep 1
end

use_debug false
use_osc_logging false


live_loop :playsample do
  use_real_time #gives faster realtime response
  a = sync "/osc*/trigger/prophet"
  
  case a[0]
  when 1.0
    puts "hello"
  when 2
    puts "two"
  when 3
    puts "three"
  when 4.0
    puts "hello"
  when 5.0
    puts "two"
  when 6.0
    puts "three"
  when 7.0
    puts "three"
  else
    puts "error"
  end
end
1 Like

Case is part of ruby language. https://www.techotopia.com/index.php/The_Ruby_case_Statement

1 Like

So if I am correct case & puts are Ruby native lang and should be able to run in Sonic PI without any issues?

So in the following code where I get to correct incoming osc messages.
I should get at least one of the responses right??

use_osc "localhost",4560 #address where osc messages will be sent

use_debug false
use_osc_logging false


live_loop :playsample do
  use_real_time #gives faster realtime response
  a = sync "/osc*/trigger/prophet"
  
  case a[0]
  when 1.0
    puts "hello"
    print "hello"
  when 2.0
    puts "two"
  when 3.0
    puts "three"
    
    play sample :ambi_choir
    
  when 4.0
    puts a
  when 5.0
    puts "two"
  when 6.0
    puts "three"
  when 7.0
    puts "three"
  else
    puts "error"
  end
end