Bug? Indentation is wrong

Hi, I’m working on a song inspired by hammy death scenes that go on too long. Here is the code:

a = (ring :C3, :D3, :Es3, :F3, :E4, :D4, :Bs4)
b = (ring :Ds3, :G3, :E4, :Fs4)
c = (ring :E3, :F3, :A4)

deathBlow = 1
dramaticPause = 0.5
loop do
  use_synth :piano
  play a[deathBlow]
  play b[deathBlow]
  play c[deathBlow]
  deathTime = (Math.sqrt(deathBlow*100)/50)
if deathTime > dramaticPause
dramaticPause = rrand(0.5,1.5)
sleep deathTime * 2
deathBlow = 1
else
  sleep deathTime
  deathBlow += 1
end
end

I’ve heard reports that the indentation for this sample is wrong until you fidget with it. How do I go about submitting a bug report?

1 Like

Actually according to another report, the way to get the indentation correct in this code is to remove the lines from use_synth up to deathTime, hit enter to auto indent, and then add those lines back in, but this shouldn’t be!

Looks like the auto-indenter is choking on the deathTime line.

If you add spaces around the / then it works as expected:

  deathTime = (Math.sqrt(deathBlow*100) / 50)
1 Like

Thanks! Its such a small thing to choke on, does this count as a bug or a feature? I gotsta know: fanfic or cannon?

1 Like

So, I modified the code:

a = (ring :C3, :D3, :Es3, :F3, :E4, :D4, :Bs4)
b = (ring :Ds3, :G3, :E4, :Fs4)
c = (ring :E3, :F3, :A4)

iteration = 1
deathBlow = 1
dramaticPause = 0.5
loop do
  use_synth :piano
  play a[deathBlow]
  play b[deathBlow]
  if iteration == 1 || deathBlow % 2 == 0
    play c[deathBlow]
  end
  
  deathTime = (Math.sqrt(deathBlow*100) / 50)
  if deathTime > dramaticPause
    dramaticPause = rrand(0.5,1.5)
    sleep deathTime * 2
    deathBlow = 1
    iteration++
    else
      sleep deathTime
      deathBlow += 1
    end
  end

It seems we have another dramatic turn, I get this error:

Runtime Error: [buffer 1, line 781] - SyntaxError
Thread death!
workspace_one:2

And that’s all that will copy from the buffer. WHAT A TWIST! The line says: syntax error, unexpected `else’

E D I T:

Ok so getting rid of the ++ operation fixes it but is ++ not supported?

a = (ring :C3, :D3, :Es3, :F3, :E4, :D4, :Bs4)
b = (ring :Ds3, :G3, :E4, :Fs4)
c = (ring :E3, :F3, :A4)

iteration = 1
deathBlow = 1
dramaticPause = 0.5
loop do
  use_synth :piano
  play a[deathBlow]
  play b[deathBlow]
  if deathBlow % 2 == 1
    play c[deathBlow]
  end
  
  deathTime = (Math.sqrt(deathBlow*100) / 50)
  if deathTime > dramaticPause
    dramaticPause = rrand(0.5,1.5)
    sleep deathTime * 2
    deathBlow = 1
    iteration += 1
  else
    sleep deathTime
    deathBlow += 1
  end
end

Hey @michaelplzno,
Nope, ++ will fail to parse correctly. Ruby (and therefore, currently, Sonic Pi by extension) does not have pre/post increment operators.
The correct way to achieve this in this context is indeed to write += 1, as you have done.

1 Like

Ah thanks! My CPU is a neural net processor, a learning computer.

hi @michaelplzno,

Is there a reason to use there square root to obtain a special value ? Just to know :slight_smile:

@nlb the square root creates a pausing effect that simulates the struggle of death extending over time. Each death blow is supposed to be dramatic, followed by a cooling off. Square root has that progression.

Here is a link to the final version, which is a remix, on my soundcloud: The Abstruse Death of Nick Bottom REMIX

And here is the final code, with added machine gun.

a = (ring :C3, :D3, :Es3, :F3, :E4, :D4, :Bs4)
b = (ring :Ds3, :G3, :E4, :Fs4)
c = (ring :E3, :F3, :A4)

pauses = (ring 0.3, 0.5, 0.55, 0.3, 0.1, 0.1, 0.2, 0.25, 0.5, 0.7)

shots = 1
iteration = 1
deathBlow = 1
dramaticPause = pauses[0]
live_loop :deathCycle do
  use_synth :piano
  
  ampFade = 0.25 + 4 / deathBlow
  if ampFade > 1.0
    ampFade = 1
  end
  
  play a[deathBlow], amp: ampFade
  play b[deathBlow], amp: ampFade
  
  if iteration <= 2 || deathBlow % 2 == 0
    play c[deathBlow], amp: ampFade
  else
    use_synth :saw
    sleep 0.05
    play c[deathBlow], amp: ampFade
  end
  
  deathTime = Math.sqrt(deathBlow * 100)  / (50 + 5 * iteration)
  if deathTime > dramaticPause
    dramaticPause = pauses[iteration]
    sleepTime = deathTime * 2
    if sleepTime < 2.0
      sleepTime = 2.0
    end
    deathBlow = 1
    iteration += 1
    shots = 1
    sleep sleepTime
  else
    deathBlow += 1
    sleep deathTime
  end
  
  if iteration > 10
    break
  end
end


live_loop :machineGun do
  gunAmp = 0.2 + 5 / shots
  if gunAmp > 1
    gunAmp = 1
  end
  
  if deathBlow >= 3
    shots += 1
    sample :drum_snare_soft, amp: gunAmp
  end
  
  if deathBlow >= 6
    sample :drum_cymbal_open, amp: 0.5 * gunAmp
  end
  
  if deathBlow >= 9
    sample :drum_cowbell, amp: 0.3 * gunAmp
  end

  sleep 0.25 - iteration * 0.01
end

Some day I hope to make the original because the original version is always better!

1 Like

ok it’s an explanation :slight_smile:

ps : by the way, i know now who is Nick Bottom :wink:

Oh I know the problem of making a remix without the original available. Though my non existing original sounded by far not as musically exotic as yours…

I think you argument for the square root is very convincing.

Thank you for indulging my bizarre music, I’m a creep, I’m a weirdo after all.

But it did one that is a bit more traditional today. The melody is a little sloppy but I’m proud of it for not being a “terrible” song: Doodlin With the Donky

I actually lifted and modified the NES Donkey Kong BGM!

Here’s the code:

iteration = 0

live_loop :donky do
  use_synth :saw
  if(iteration%4 < 2)
    play :C3
    sleep 0.5
    play :E3
  else
    play :D3
    sleep 0.5
    play :F3
  end
  sleep 0.33
  play :G3
  sleep 0.166
  play :A3
  sleep 0.166
  play :G3
  sleep 0.166
  
  iteration += 1
end