# Bug? Indentation is wrong

**URL:** <https://in-thread.sonic-pi.net/t/bug-indentation-is-wrong/3722>\
**Category:** Support, Help & Resources\
**Created:** [April 26, 2020, 10:45pm UTC](https://in-thread.sonic-pi.net/t/bug-indentation-is-wrong/3722 "2020-04-26T22:45:42Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![michaelplzno](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/michaelplzno/32/1359_2.png) [@michaelplzno](https://in-thread.sonic-pi.net/u/michaelplzno)\
**Post date:** [April 26, 2020, 10:45pm UTC](https://in-thread.sonic-pi.net/t/bug-indentation-is-wrong/3722/1 "2020-04-26T22:45:42Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![michaelplzno](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/michaelplzno/32/1359_2.png) [@michaelplzno](https://in-thread.sonic-pi.net/u/michaelplzno)\
**Post date:** [April 26, 2020, 10:48pm UTC](https://in-thread.sonic-pi.net/t/bug-indentation-is-wrong/3722/2 "2020-04-26T22:48:16Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![samaaron](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/samaaron/32/7_2.png) [@samaaron](https://in-thread.sonic-pi.net/u/samaaron)\
**Post date:** [April 26, 2020, 11:10pm UTC](https://in-thread.sonic-pi.net/t/bug-indentation-is-wrong/3722/3 "2020-04-26T23:10:13Z")

</div>

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

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

```ruby
  deathTime = (Math.sqrt(deathBlow*100) / 50)

```

---

<div class="post-metadata">

**Author:** ![michaelplzno](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/michaelplzno/32/1359_2.png) [@michaelplzno](https://in-thread.sonic-pi.net/u/michaelplzno)\
**Post date:** [April 26, 2020, 11:15pm UTC](https://in-thread.sonic-pi.net/t/bug-indentation-is-wrong/3722/4 "2020-04-26T23:15:09Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![michaelplzno](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/michaelplzno/32/1359_2.png) [@michaelplzno](https://in-thread.sonic-pi.net/u/michaelplzno)\
**Post date:** [April 26, 2020, 11:29pm UTC](https://in-thread.sonic-pi.net/t/bug-indentation-is-wrong/3722/5 "2020-04-26T23:29:10Z")

</div>

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
```

---

<div class="post-metadata">

**Author:** ![ethancrawford](https://avatars.discourse-cdn.com/v4/letter/e/a88e4f/32.png) [@ethancrawford](https://in-thread.sonic-pi.net/u/ethancrawford)\
**Post date:** [April 27, 2020, 12:45am UTC](https://in-thread.sonic-pi.net/t/bug-indentation-is-wrong/3722/6 "2020-04-27T00:45:09Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![michaelplzno](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/michaelplzno/32/1359_2.png) [@michaelplzno](https://in-thread.sonic-pi.net/u/michaelplzno)\
**Post date:** [April 27, 2020, 12:57am UTC](https://in-thread.sonic-pi.net/t/bug-indentation-is-wrong/3722/7 "2020-04-27T00:57:36Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![nlb](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/nlb/32/997_2.png) [@nlb](https://in-thread.sonic-pi.net/u/nlb)\
**Post date:** [April 27, 2020, 8:16am UTC](https://in-thread.sonic-pi.net/t/bug-indentation-is-wrong/3722/8 "2020-04-27T08:16:19Z")

</div>

> [@michaelplzno](#):
>
> deathTime = (Math.sqrt(deathBlow\*100)/50)

hi @michaelplzno,

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

---

<div class="post-metadata">

**Author:** ![michaelplzno](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/michaelplzno/32/1359_2.png) [@michaelplzno](https://in-thread.sonic-pi.net/u/michaelplzno)\
**Post date:** [April 27, 2020, 2:22pm UTC](https://in-thread.sonic-pi.net/t/bug-indentation-is-wrong/3722/10 "2020-04-27T14:22:20Z")

</div>

@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](https://soundcloud.com/michaelplzno/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!

---

<div class="post-metadata">

**Author:** ![nlb](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/nlb/32/997_2.png) [@nlb](https://in-thread.sonic-pi.net/u/nlb)\
**Post date:** [April 27, 2020, 4:19pm UTC](https://in-thread.sonic-pi.net/t/bug-indentation-is-wrong/3722/11 "2020-04-27T16:19:34Z")

</div>

ok it’s an explanation 🙂

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

---

<div class="post-metadata">

**Author:** ![Martin](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/martin/32/157_2.png) [@Martin](https://in-thread.sonic-pi.net/u/Martin)\
**Post date:** [April 27, 2020, 6:32pm UTC](https://in-thread.sonic-pi.net/t/bug-indentation-is-wrong/3722/12 "2020-04-27T18:32:34Z")

</div>

> [@michaelplzno](#):
>
> Some day I hope to make the original because the original version is always better!

Oh I know the problem of [making a remix without the original available](https://soundcloud.com/mbutz/jam). 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.

---

<div class="post-metadata">

**Author:** ![michaelplzno](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/michaelplzno/32/1359_2.png) [@michaelplzno](https://in-thread.sonic-pi.net/u/michaelplzno)\
**Post date:** [April 27, 2020, 10:00pm UTC](https://in-thread.sonic-pi.net/t/bug-indentation-is-wrong/3722/13 "2020-04-27T22:00:28Z")

</div>

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](https://soundcloud.com/michaelplzno/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
```
