Define :e do <-- why does this not play?

Hello! I’m fairly new to Sonic Pi so please bear with me as this might be a stupid question…
I had an idea to create a composition where I would ‘define’ each letter of the alphabet as individual musical segments so that I could make a generative composition by combining the letters into words (putting them in_thread altogether).
I know that it is better to use the define function with specific keywords (e.g. foo), but I tested if it would work with single alphabets, and surprisingly it did work for all of them except ‘e’.
Does anyone know why the define function would not work on ‘e’ only, and is there any other way I can work around it for a similar result?

For example this code would not play:

define :e do
  use_synth :hoover
  loop do
    play choose(chord(:E3, :minor)), release: 0.3, cutoff: rrand(60, 120)
    sleep rrand(0.25, 0.5)
  end
end

e

While this code would:

define :d do
  use_synth :hoover
  loop do
    play choose(chord(:E3, :minor)), release: 0.3, cutoff: rrand(60, 120)
    sleep rrand(0.25, 0.5)
  end
end

d

Thank you!

1 Like

Intriguing. I can confirm that SP seems to ignore any definition of define :e whatever the contents, but other single letters seem OK. I’ve had a brief look at source code but haven’t spotted what might be the cause.
Incidentally it is a good idea perhaps to avoid loop do....end constructs as they are blocking in that once started they don’t exit until the overall p[rogram is halted.
If you need to use one you can isolate it to it’s own thread by putting it inside a in_thread do..end That is why live_loops are a better idea to use.

Thank you for your reply!
I guess the define :e do problem cannot be solved for now then. :joy:
I will also try avoiding using loop do ... end within the define codes. :slight_smile:

It looks like there is already a variable called e defined that is preventing this working. I’m not sure what it is supposed to be, or where it comes from - but it has a value of nil:

EDIT:
It looks like it must be escaping from an exception handling block somewhere - the variable name used in the rescue stays in use after the block, and e is a common name to use in this situation. I managed to make another one called f:

1 Like