Arduino interface to sonic pi

thank you Robin, apologies for the belated reply - unusual times.
This seems to be in line with what I’m looking for.
How can I add some beat and rhythm to this using the similar techniques from the midi.
How would I be able to add choral angelic voices to this?

if you also get a chance can you please explain the logic of the code you posted ```
#demo on controlling level and cutoff for midi input

Hi,

from my own experience I can say it is a very productive thing to analyze code I don’t understand line by line and try to find out, what it does. This might take some time and be exhausting but it almost always leads to more knowledge and understanding in a deeper way. And if not that, I afterwards will surely be able to ask more specific questions than before.

My friends in this situation are the documentation and especially the command puts to find out, what a variable contains/is used for/works like at a certain point. You can e. g. use the following to log and study the incoming midi information:

live_loop :getmidi do
      use_real_time
      n,v = sync "/midi*/note_on"
      puts "Value of n: #{n} / value of v: #{v}"
      play n,release: 0.2,amp: v/127.0
      puts "Calculated value of v = #{v/127.0}"
    end

Of course this is just an example and if you want you might adapt this to your own ends. Some things you will probably have to try out and then also use Google. This might be the case e. g. to find out why the code says v/127.0 and not v/127.

Often things don’t make any sense at all at the first sight. But after some time, some testing and some meditation about it on my side they gradually do.

Thanks I do usually do that however the code has some concepts I didn’t quite follow.

I have another big question: for my application to work I need the code in cache 0 to run when sonic starts up, that is, there shouldn’t be any need for me to push the run command.
How do I get this to happen or configure sonic pi to auto run code in cache 0? right now using the above code it doesn’t autorun until I push run?

Hey @wro :slight_smile:

depending on what you are hoping for explanation over, it often helps to ask specific questions - the more focused they are, the more focused the answers can be :slight_smile:

1 Like

As far as I know there is no way to run code in a specific buffer automatically after program start.

But there is the ~/.sonic-pi/init.rb (this is the path on Linux), which might accomplish what you need. This file will be evaluated after program start, see one possible example here.

can someone tell me if thats true because then my whole project cant use sonic pi, i need it to autorun the code on startup.

the init.rb file allows you to run a piece of code at start up, without needing to have it in a specific buffer.

sounds promising - phew! please send me an example

@Martin mentioned one above :+1:

thanks - whats the equivalent in windows os

Usually the file is in C:\Users\[your name]\.sonic-pi by default.

:+1: much appreciated

No worries, you’re welcome :+1:

can someone assist me to understand this as as I understand this r is the cutoff value that should be used in the code below, but how or where is that value being used?

#r is a reference to the fx :nlpf
  with_fx :nlpf,cutoff: 50,mix: 0.7 do |r|
    #store r in the time state as :r
    set :r,r
    live_loop :getmidi do
      use_real_time
      n,v = sync "/midi*/note_on"
      play n,release: 0.2,amp: v/127.0
    end
``` but where is this value being used?

If I understand your thinking correctly, (might be wrong, so let me know if otherwise) you’re actually thinking about it back to front.

  with_fx :nlpf,cutoff: 50,mix: 0.7 do |r|
    #store r in the time state as :r
    set :r,r

This bit comes before live_loop :control. The idea is that we first use set to store some value in the global time-state memory store, and later on use get to retrieve this value for use. Ie, the above few lines create a new fx, store a reference to it called r to use within the fx’s own block, but we in turn then set this reference to the fx, r, in the global time-state system, so that we can refer to it somewhere outside the current loop without worrying about race conditions (for example).
Then, later down, when we want to use this fx reference, we use get to retrieve it.

 control get(:r), cutoff: 50+v*60

Does that make things any clearer? It may also help to read Chapters 10 and 10.1 of the tutorial about the time state system, set and get.

thanks appreciate the explanation makes a bit more sense now

Hi - if I want to add some rhythm to the above code ```
#demo on controlling level and cutoff for midi input

seems to have cutoff my text - … rhythm or beats to play during when notes are played and after notes are played, how would this be done?

can anyone assist please?