Just made an arpeggiator method, which generates configurable arpeggios. It is also a nice example of a method with named parameters:
# p_tonic tonic of the chord
# p_name name of the chord
# p_length number of different pitches in the arpeggio
# p_invert inversion of the chord: 0, 1 or 2
# p_sleep number of beats for the arpeggio
# p_type: 0 ascending, 1 descending, 2 hill 3 valley
# p_random number of additional notes from 0 to 3 -> .shuffle gives a random selection
# p_has_basenote shall the base note be played (true or false)
def m_play_arpeggio(p_tonic: 60, p_name: :maj, p_length: 3, p_invert: 0, p_sleep: 2,
p_type: 0, p_random: 0, p_has_basenote: false, p_has_droplastnote: true)
# damit sich die Zufallswerte nicht wiederholen
use_random_seed Time.new.to_i
# Chord definieren
l_chord = (chord p_tonic, p_name, num_octaves: 4)
# Inversion
l_chord = l_chord.drop(p_invert)
l_basenote = l_chord.take(1) - 12
print l_basenote
# Wir holen aus jedem beliebigen Chord diese Anzahl Noten + p_random
l_chord = l_chord.take(p_length + p_random)
print l_chord.notes
# Jetzt mischeln wir diese, nehmen die ersten gemäss Anzahl und Sortieren
l_chord = l_chord.shuffle.take(p_length).sort
print l_chord.notes
if p_type == 1 # absteigend
l_chord = l_chord.reverse
else
if p_type == 2 # auf- dann absteigend
# Mit .reflect hängen wir die Noten absteigend an
l_chord = l_chord.reflect
else
if p_type == 3 # ab- dann aufsteigend
l_chord = l_chord.reverse.reflect
end
end
end
# jetzt eventuell noch die letzte Note entfernen
if p_has_droplastnote == true && p_type > 1
l_chord = l_chord.drop_last(1)
end
print l_chord.notes
p_length_arp = l_chord.length
# spiele einen Grundton
if p_has_basenote
play l_basenote, sustain: p_sleep
end
l_chord.each do |p_note|
play p_note
sleep p_sleep * 1.0 / p_length_arp
end
end
use_synth :tri
m_play_arpeggio(p_name: :min, p_length: 4, p_type: 3, p_has_basenote: false)
sleep 0.25
m_play_arpeggio(p_name: :min, p_length: 5, p_invert: 1, p_sleep: 1)
sleep 0.25
m_play_arpeggio(p_name: :min, p_length: 6, p_invert: 2, p_type: 1)
sleep 0.25
m_play_arpeggio(p_name: :min, p_length: 6, p_type: 2)