gkvoelkl / python-sonic

Programming Music with Python, Sonic Pi and Supercollider
MIT License
313 stars 46 forks source link

Error caused python-sonic to stop producing sound #23

Closed Zylvian closed 5 years ago

Zylvian commented 5 years ago

So I did

`def live_5():

notes = scale(E3, MINOR_PENTATONIC, num_octaves=2)

for i in range(8):

    play(random.choice(notes),release=0.1,amp=1.5)
   `

And I did the rest of the example, where I put it in a thread and played it. But I forgot the sleep(0.125) in live_5(). The program made some weird noises, and now, after reloading the kernel, no sounds are produced.

https://i.gyazo.com/b1f6608f1a9920d2a33231acabab180c.png

Any clue?

filips123 commented 5 years ago

Yes, this happens when a lot of plays are sent to Sonic Pi in a small time. Note that this can also happen even with sleep.

I temporarily fixed this with restarting Sonic Pi, but after some time, this happened again.

filips123 commented 5 years ago

@gkvoelkl Do you know how to fix this? It is annoying and probably an important bug.

gkvoelkl commented 5 years ago

Python-Sonic is a very direct Interface for Sonic Pi. It sends a message to Sonic Pi and Sonic Pi makes the sound. All the timing is made by the Python application. Perhaps you can post your example.

filips123 commented 5 years ago

@gkvoelkl I will post example and more details later today.

filips123 commented 5 years ago

@gkvoelkl I tested this few more times and sometimes there is a bug and sometimes not.


Here is my example code:

while True:
    sample(AMBI_LUNAR_LAND, amp=0.5)

First, it will work. But then, the error will appear in Sonic Pi.

Here is the error:

Runtime Error: [eval] - ThreadError
 can't create Thread: Not enough space
D:/Users/filips/Downloads/SonicPiPortable/App/Sonic Pi/app/server/ruby/lib/sonicpi/runtime.rb:934:in `initialize'
D:/Users/filips/Downloads/SonicPiPortable/App/Sonic Pi/app/server/ruby/lib/sonicpi/runtime.rb:934:in `new'
D:/Users/filips/Downloads/SonicPiPortable/App/Sonic Pi/app/server/ruby/lib/sonicpi/runtime.rb:934:in `block in __in_thread'
D:/Users/filips/Downloads/SonicPiPortable/App/Sonic Pi/app/server/ruby/lib/sonicpi/util.rb:583:in `block in __no_kill_block'
D:/Users/filips/Downloads/SonicPiPortable/App/Sonic Pi/app/server/ruby/lib/sonicpi/util.rb:581:in `synchronize'
D:/Users/filips/Downloads/SonicPiPortable/App/Sonic Pi/app/server/ruby/lib/sonicpi/util.rb:581:in `__no_kill_block'
D:/Users/filips/Downloads/SonicPiPortable/App/Sonic Pi/app/server/ruby/lib/sonicpi/runtime.rb:931:in `__in_thread'
D:/Users/filips/Downloads/SonicPiPortable/App/Sonic Pi/app/server/ruby/lib/sonicpi/lang/core.rb:4240:in `in_thread'
eval:in `block in __spider_eval'
D:/Users/filips/Downloads/SonicPiPortable/App/Sonic Pi/app/server/ruby/lib/sonicpi/runtime.rb:780:in `eval'
D:/Users/filips/Downloads/SonicPiPortable/App/Sonic Pi/app/server/ruby/lib/sonicpi/runtime.rb:780:in `block in __spider_eval'```

And another error:

Runtime Error: [eval] - NoMemoryError
 failed to allocate memory
D:/Users/filips/Downloads/SonicPiPortable/App/Sonic Pi/app/server/ruby/lib/sonicpi/runtime.rb:934:in `new'
D:/Users/filips/Downloads/SonicPiPortable/App/Sonic Pi/app/server/ruby/lib/sonicpi/runtime.rb:934:in `block in __in_thread'
D:/Users/filips/Downloads/SonicPiPortable/App/Sonic Pi/app/server/ruby/lib/sonicpi/util.rb:583:in `block in __no_kill_block'
D:/Users/filips/Downloads/SonicPiPortable/App/Sonic Pi/app/server/ruby/lib/sonicpi/util.rb:581:in `synchronize'
D:/Users/filips/Downloads/SonicPiPortable/App/Sonic Pi/app/server/ruby/lib/sonicpi/util.rb:581:in `__no_kill_block'
D:/Users/filips/Downloads/SonicPiPortable/App/Sonic Pi/app/server/ruby/lib/sonicpi/runtime.rb:931:in `__in_thread'
D:/Users/filips/Downloads/SonicPiPortable/App/Sonic Pi/app/server/ruby/lib/sonicpi/lang/core.rb:4240:in `in_thread'
eval:in `block in __spider_eval'
D:/Users/filips/Downloads/SonicPiPortable/App/Sonic Pi/app/server/ruby/lib/sonicpi/runtime.rb:780:in `eval'
D:/Users/filips/Downloads/SonicPiPortable/App/Sonic Pi/app/server/ruby/lib/sonicpi/runtime.rb:780:in `block in __spider_eval'

After that, the sound will disappear and there will be this in the log:

=> Starting run 10687
=> Aborted Run 10687

So this is probably problem with Sonic Pi.

gkvoelkl commented 5 years ago

I started the sample program on my computer.

It called about 25.000 times Sonic Pi in one second. That's too much.

You have to use sleep for time management.

filips123 commented 5 years ago

I know this. But sometimes (I currently don't have this problem), this happened a lot earlier and also with (small) sleeps. But this is probably a problem with Sonic Pi.

gkvoelkl commented 5 years ago

It can happen, when python-Sonic sends too many messages to Sonic Pi. And that depends on the performance of the computer. Thanks.