Error value must be immutable with use_synth - SP 3.2dev

Hi !

This code returns an error under Sonic PI 3.2

instruments = ['piano', 'pretty_bell']

define :albert do | num: 1, a: 0, d: 0.5, s:0.5, r:0.5, amp: 1, c:80 |
  
  puts instruments[num-1]
  use_synth instruments[num-1]
  use_synth_defaults attack: a, decay: d, sustain: s, release: r, amp: amp, cutoff: c
end

albert 
play :c4
 Error setting Thread Local - value must be immutable. Got: "piano" for :sonic_pi_mod_sound_current_synth_name

could somebody explain what is it immutable ?
i guess that once a variable is set to a value, this value can’t be changed. Right ?
So why this error ?
Thanks

Hmm. The code worked OK for me. (on 3.2dev)

I tried

instruments = ['piano', 'pretty_bell']

define :albert do | num: 1, a: 0, d: 0.5, s:0.5, r:0.5, amp: 1, c:80 |
  
  puts instruments[num-1]
  use_synth instruments[num-1]
  use_synth_defaults attack: a, decay: d, sustain: s, release: r, amp: amp, cutoff: c
end

albert num: 2
play :c4
sleep 1
albert num: 1
play :c5

which was fine.

Are you starting Sonic Pi in a non-standard way? I think Sonic Pi starts Ruby with the --enable-frozen-string-literal option enabled, so if you start it yourself without that option it could lead to this error.
If you use symbols instead, I think it should work (i.e. instruments = [:piano, :pretty_bell])

1 Like

thank you @emlyn if i use symbols it works.
For information, i start sonicpi the standard way under ubuntu 18.04.3. I do not use the latest version of 3.2 dev.

Under spi 3.1 under windows 10, the list way works. By the way, the spi 3.2dev version for windows is available for patreons or not yet ?

Hi,

For info, with Sonic PI v3.2.0-dev-6614a built under raspbian buster , we have to use symbols. I start Sonic Pi the standard way without any option.

Cheers

It looks like that option is only enabled on Mac and Windows (link). I guess you’ll just have to use symbols (or try building it yourself with the option enabled, but there may well be a reason it’s not already enabled).

@nlb thanks for bringing this to my attention :slight_smile:

I’ve now enabled the frozen literal flag for all platforms on Master over on Github.

This has the side effect of requiring at least v2.3 of Ruby to work going forward.

1 Like