Redefining Loop

Hi everyone, I’m really new into this world and it’s my first post…so I’m really sorry if my questions are a bit obvious…

I was just starting creating some loops using live_loop, as in the example:

in_thread do
  live_loop :choral_drone do
    sample :ambi_choir, rate: 0.6, amp: 0.4, beat_stretch: 10.0
    cue :sample
    sleep 1
  end
end

in_thread do
  live_loop :synth_dark do
    use_synth :dark_ambience
    play 50, amp: 0.5, attack: 0.3, decay: 0.4, release: 4.9, env_curve: 3, cutoff: 100,res: 0.9, noise: 3, room: 290, reverb_time: 100
    sync :sample
    sleep 3.7
  end
end

in_thread do
  live_loop :bleep do
    use_synth :hollow
    with_fx :reverb do
      play 90
      sync :sample
      sleep 0.7
    end
  end
end

in_thread do
  live_loop :drone do
    sample "/Users/matteoolivo/Desktop/SONIC PI/Cannella.WAV", rate: 0.2, room: 100, start: 0.90, finish: 0.8, cutoff: 130, amp: 0.5
    sync :sample
    sleep 0.4
  end
end

in_thread do
  live_loop :drone2 do
    load_synthdefs("/Users/matteoolivo/Desktop/my-synths/Bleepdel.scsyndef")
    synth :Bleepdel
    play 50
    sync :sample
    sleep 0.4
  end
end

First question: for the moment I’m using the comments to start and stop the loops. Normally I launch the first loop, and step by step I launch the others removing the #. If anyone knows a more efficient way to do it, any suggestion will be very appreciated! :slight_smile:

Second question: I have a problem if at a certain point I stop the music with the “stop” button at the top, after having modified some parameter of the loops (like the amp, or the rate, etc.). When I want to restart my liveset, the software doesn’t play and on the right side of the screen appears something like:
“Redefining fn :live_loop_drone
Thread :live_loop_drone
Redefining fn :live_loop_drone2…
etc etc…”

At this point, the only way to restart my liveset is to close the session and reopen it…
Does anyone have any suggestions?

Thanks a lot in advance :slight_smile:

1 Like

Hi @Matt,

just as a side note:

If you put three backticks in a separate line before and after your code example it’ll be nicely formated and colored and thus better readable.

2 Likes

To stop a live loop (or at first run prevent it from running in the first place) you can add stop:

live_loop :dont_stop_me_now do
  stop
  sample :loop_amen, beat_stretch: 2, amp: 1
  sleep 2
end

Note: Once you stopped a loop by putting a stop somewhere in the loop body (probably at the beginning) you will have to 1. remove/ or comment the stop and then 2. re-evaluate the code (hit run) to start this loop again. Alternatively you could just comment the sample ... line or set the amp to 0 (and let the loop running contineously).

There are also some discussions going on to dynamically create and control live_loops (e. g. here and here). But this is somehow more complicated.

One more thing: If you use live_loops you don’t need the in_thread construct anymore: a live_loop automatically creates its own thread. You will see, once you removed all in_tread statements your code will behave exactly the same.

2 Likes

Thanks a lot! I will do it the next time!

Thanks a lot Martin, your suggestion was very helpful! it works very well! :slight_smile:

…but I still have problems concerning the second question: when I stop the sound, and I change some parameters, the program seems to be blocked. If I try to press start, I still have the same message:

"Redefining fn :live_loop_drone

Redefining fn :live_loop_drone2…
etc etc…”

And nothing works anymore, until I close the session and I restart it…

Hi @Matt,

I am afraid, I can’t help you with that. I have seen this behaviour, I believe, in cases

  • where I had to much code in one buffer or
  • something else went wrong (when quite a lot of code was involved)

and the program became unresponsive. But it is quite unusual and does happen very rarely. I would recommend the usual suspects:

  • check your code, ran it partially and see if there is a point where the unwanted behaviour occurs
  • check if you can use another buffer with some other code you know always works

You also might want to post another example (the simplest code) with which you think this behaviour should be reproducable for others. And probably a good idea: Check the logs which you can find at “/.sonic-pi/logs”; possibly there’s some hint on what goes wrong. Finally post what version on which OS you are using.

I am sure that if not me, someone here will be able to help.

1 Like

bonsoir,

please post the code which causes your issue to help us to reproduce the issue.
see you soon

2 Likes

I’s bet money its related to your loading your own synthdefs…

Eli…

1 Like

by the way, speaking synthdefs, i have never used personal synthdefs. Is there some ressources to try with others synthdefs ? Is it hard to create ?

1 Like

Hi @nlb,

for a start have a look at:

1 Like

Thanks a lot Martin! you are very kind!

You are right Eli: synthdefs was the problem…

here’s my code:

#BLEEP supercollider
live_loop :drone2 do
  load_synthdefs("/Users/matteoolivo/Desktop/my-synths/Bleepdel.scsyndef")
  synth :Bleepdel
  play 50
  sync :sample
  sleep 0.4
  #stop
end
1 Like

and this is the Supercollider’s code:

(
SynthDef.new(\Bleepdel,{
var outArray;
outArray = [CombN.ar(SinOsc.ar(880, 0, 0.05)* Line.kr(0.7,0,1.5),0.3,0.25,22),
CombN.ar(SinOsc.ar(880, 0, 0.05)* Line.kr(0.7,0,1.5),0.3,0.25,22)];
Out.ar (0, outArray);
}).writeDefFile("/Users/matteoolivo/Desktop/my-synths");
)

Hi Matt,

Correct, the Synthdef is not quite right. There are a few constraints that they must meet in order to make them usable in Sonic Pi - see https://github.com/samaaron/sonic-pi/blob/master/SYNTH_DESIGN.md#synth-design-constraints.
Happy to answer any further questions about synth design if desired.

Also, once external Synthdefs are compiled correctly, there are a few things to note when wanting to use them in Sonic Pi. I have an outstanding PR on the GitHub page to add a few notes to the synth design document about this - see https://github.com/samaaron/sonic-pi/pull/1993/files for the details. ( /cc @samaaron)

2 Likes

Thanks a lot! :slight_smile:

I will try to follow your advices and I will try to correct my Synthdefs as soon as I can. I will write if I have further questions…:slight_smile:

1 Like

Hi, I’ve tried to follow the tutorials you sent me, but I still have problems with mys SynthDef.

  1. This is the code of my SynthDef, I’ve followed exactly the structure of the exemple in the tutorial but I have some errors. Have you got any suggestions?
(
SynthDef(\Bleepdel,
	    { |out_bus = 0|
	    Out.ar (out_bus,
		[CombN.ar(SinOsc.ar(880, 0, 0.05)* Line.kr(0.7,0,1.5),0.3,0.25,22),
		CombN.ar(SinOsc.ar(880, 0, 0.05)* Line.kr(0.7,0,1.5),0.3,0.25,22)])
}).writeDefFile(\"/Users/matteoolivo/Desktop/my-synths\");
)
  1. In the tutorial it’s written that we have to add some metadata to the path app/server/sonicpi/lib/sonicpi/synths/synthinfo.rb
    Sorry but I don’t understand what I have to add and where can I access to this path. Someone can help me?

Thanks a lot in advance!

Hey Matt,

  1. What errors are you getting? I am not on my Macbook at the moment so can’t test there easily, but at least on my Windows computer that synthdef works fine with one small alteration - the string for the synthdef write destination is slightly different for me. On my Windows computer, the same synthdef works if that string is:
    "C:\\Users\\Ethan\\Desktop\\" (for example).
    (Note sure if the escaped backslashes still apply on a non-windows machine).

Having said that, you also need to make the synth self-terminate - for example, in the Synth Design document I linked to above, the oscillators are multiplied by Line.kr(1, 0, 5, amp, doneAction: 2) - which is effectively the sound envelope - and crucially, when the envelope is finished, doneAction: 2 removes the synth from memory.
There are other ways of specifying a self-terminating synth envelope - see within the piano synth definition we have at https://github.com/samaaron/sonic-pi/blob/master/etc/synthdefs/designs/supercollider/piano.scd#L24-L27 for example. (Which allows for the user to set the envelope segment lengths).

  1. As far as metadata, it depends on whether you want Sonic Pi to do things like provide autocompletion for synth opts, or be able to recognise when you’re trying to trigger the synth with ‘out of range’/‘unsafe’ values that might cause uncomfortable noises - or whether you’re content to use the synth without any of that.

The difference then, is that if you are happy to use the synth without those things, you don’t need to add metadata to Sonic Pi’s source code. You just need to explicitly load the synthdef with a command before you start using it.
For example, with the SynthDef write path adjusted as above on my windows computer, it runs fine in Sonic Pi without opt validation as seen below:

Note that when not adding the metadata into Sonic Pi’s source code, the preferences checkbox ‘Enable external synths/FX’ must be turned on and the ‘Safe mode’ checkbox will not apply to anywhere you use the custom synth.

After all this, if you do in fact wish to integrate the synth into Sonic Pi to allow the built in validation etc, yes, you will need to add this metadata into the source code and re-compile the GUI. Happy to talk about that if you still wish to do so.

1 Like

Thanks a lot Ethan! Everything works fine now! :slight_smile:

I’ve removed the backslash and I made the synthdef self-terminate, using doneAction at the end of the envelope.

Concerning the metadata, I still didn’t try but for the moment I think I don’t need to write them!