gkvoelkl / python-sonic

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

adding .reverse and .shuffle commands #6

Closed rbnpi closed 7 years ago

rbnpi commented 7 years ago

Would it be possible to add these? The first one at least would be very useful in being able to play descending scales. using scale(:c4,:major).reverse for the list of notes to use.

(Just taken a look at psonic and it works nicely. Trying it with a skywriter hat at present.)

gkvoelkl commented 7 years ago

Hi, looked for skywriter in the Internet. It is a great idea to make music with that. If you have an example on github I will make a link to it.

To your issue: The function scale returns a list with all notes of a scale. So you can use list methodes or functions. For example to play arpeggios descending or shuffeld.

import random ​ s = scale(C3, MAJOR) play_pattern_timed(s.reverse(), 0.125, release = 0.1) play_pattern_timed(random.shuffle(s), 0.125, release = 0.1)

Best regards

Gerhard

rbnpi commented 7 years ago

I tried your suggestions but they did not work. Typed python3 and from the >>> I typed

>>>from psonic import *
>>>s=scale(C3,MAJOR)
>>>play_pattern_timed(s.reverse(), 0.125, release = 0.1)

SP gave an error unitialised constant SonicPi::RunTimeMethods::None

>>>play_pattern_timed(s,0.125,release = 0.1)

worked fine

LIkewise the random.shuffle(s) example didn;t work either. (having done import random)

gkvoelkl commented 7 years ago

It's true. My example does produce an error.

The statement

s.reverse()

reverses the list but does not return a value.

You have to do

s.reverse()
play_pattern_timed(s, 0.125, release = 0.1)
random.shuffle(s)
play_pattern_timed(s, 0.125, release = 0.1)

The statements change the list s.

rbnpi commented 7 years ago

Thanks. that works fine now.

On 5 Dec 2016, at 18:52, Gerhard Völkl notifications@github.com wrote:

It's true. My example does produce an error.

The statement

s.reverse() reverses the list but does not return a value.

You have to do

s.reverse() play_pattern_timed(s, 0.125, release = 0.1) random.shuffle(s) play_pattern_timed(s, 0.125, release = 0.1) The statements change the list s.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/gkvoelkl/python-sonic/issues/6#issuecomment-264941575, or mute the thread https://github.com/notifications/unsubscribe-auth/AFVDiWDzXYKLwuRLsAgMTu2FTAeFh2tMks5rFF2FgaJpZM4K_QBc.