Hi Everyone,
I running v 3.1.0 on a Windows 8.1 machine (64 bit) and I’m new to Sonic Pi - still working through the tutorial, but trying to take what I’ve learned and apply it to ideas I’ve had for performances, recordings, etc.
One such idea involves randomly looping a number of samples in a directory filled with .wav files. I’ve had a lot of success with both loops and live_loops, but now that I am working with a large number of samples of my own creation (all recorded with a H4n mic), I keep running into errors I can’t explain.
Here is the code I am working with:
load_samples "D:/Path/to/files/"
live_loop :attempt do
rec_idx = rrand_i(0, 37)
puts rec_idx
if rec_idx < 11
sample "D:/Path/to/files/", rec_idx, start: rrand(0, 0.8), sustain: 2, amp: 2
sleep 2
else
sample "D:/Path/to/files/", rec_idx, start: rrand(0, 0.8), sustain: 2, amp: 0.2
sleep 2
end
end
If I try to run this as a regular loop, it does what I expect it to do. But once I switch to the above code, I run into a thread death error, which I’ve pasted below. Any clue why this might happen? What’s particularly curious is that, once I receive this error, all live_loops fail for me, even live_loops as simple as “play 60, sleep 1.” To make that simple code work again, I have to clear the buffer, restart the program, and then re-enter the code.
Any idea what might cause this?
As a side note, I first ran into this problem working with a definition that set the duration of the sleep command to equal the value of the sustain opt (it also randomized things in one line, instead multiple lines). Once I started getting the error, I assumed I couldn’t use a definition with a live_loop and substituted a direct call to the path where my samples exist (this explains my use of the rec_idx definition hopefully). Only the error persists. Can anyone confirm for me whether or not I can execute definitions inside live_loops?
Many thanks for any help you can offer!
Runtime Error: [workspace_one] - TypeError
Thread death +--> :live_loop_attempt
class or module required
C:/Program Files (x86)/Sonic Pi/app/server/ruby/lib/sonicpi/runtime.rb:1300:in `is_a?'
C:/Program Files (x86)/Sonic Pi/app/server/ruby/lib/sonicpi/runtime.rb:1300:in `block in initialize'
C:/Program Files (x86)/Sonic Pi/app/server/ruby/lib/sonicpi/lang/core.rb:4079:in `__live_loop_cue'
C:/Program Files (x86)/Sonic Pi/app/server/ruby/lib/sonicpi/lang/core.rb:2134:in `block (2 levels) in live_loop'
C:/Program Files (x86)/Sonic Pi/app/server/ruby/lib/sonicpi/lang/core.rb:2055:in `block (2 levels) in loop'
C:/Program Files (x86)/Sonic Pi/app/server/ruby/lib/sonicpi/lang/core.rb:2276:in `block_duration'
C:/Program Files (x86)/Sonic Pi/app/server/ruby/lib/sonicpi/lang/core.rb:2313:in `block_slept?'
C:/Program Files (x86)/Sonic Pi/app/server/ruby/lib/sonicpi/lang/core.rb:2054:in `block in loop'
C:/Program Files (x86)/Sonic Pi/app/server/ruby/lib/sonicpi/lang/core.rb:2052:in `loop'
C:/Program Files (x86)/Sonic Pi/app/server/ruby/lib/sonicpi/lang/core.rb:2052:in `loop'
C:/Program Files (x86)/Sonic Pi/app/server/ruby/lib/sonicpi/lang/core.rb:2133:in `block in live_loop'
C:/Program Files (x86)/Sonic Pi/app/server/ruby/lib/sonicpi/runtime.rb:1043:in `block (2 levels) in __in_thread'