Akkorde

Sonic Pi bietet dir auch Unterstützung dabei, dir den Namen eines Akkords in eine Liste seiner Töne zu übersetzen. Probiere es selbst aus:

play chord(:E3, :minor)

Damit kommen wir nun wirklich weiter. Das sieht schon viel besser aus als einfache Listen (und es ist für andere viel leichter zu lesen). Welche Akkordauflösungen unterstützt Sonic Pi noch? Naja, viele. Probiere ein paar hiervon aus:

Arpeggios

Wir können Akkorde leicht in Arpeggios umwandeln, indem wir die Funktion play_pattern verwenden:

play_pattern chord(:E3, :m7)

Ok, that’s not so fun - it played it really slowly. play_pattern will play each note in the list with a call to sleep 1 after each call to play. We can use another function play_pattern_timed to specify our own timings and speed things up:

play_pattern_timed chord(:E3, :m7), 0.25

Wir können sogar eine Liste von Zeiten übergeben, die nacheinander verwendet und wiederholt werden:

play_pattern_timed chord(:E3, :m13), [0.25, 0.5]

Das bedeutet das gleiche wie:

play 52, sustain: 0.25
sleep 0.25
play 55, sustain: 0.5
sleep 0.5
play 59, sustain: 0.25
sleep 0.25
play 62, sustain: 0.5
sleep 0.5
play 66, sustain: 0.25
sleep 0.25
play 69, sustain: 0.5
sleep 0.5
play 73, sustain: 0.25
sleep 0.25

Was würdest du lieber schreiben?

Note that play_pattern and play_pattern_timed alter the sustain of the notes to fill the times. You can remove this behavior by setting the sustain: opt to 0:

play_pattern_timed chord(:E3, :m13), [0.25, 0.5], sustain: 0