-
Notifications
You must be signed in to change notification settings - Fork 0
/
workspace_seven.spi
61 lines (52 loc) · 1.84 KB
/
workspace_seven.spi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# Welcome to Sonic Pi
use_bpm 120
# Define the keys and their transition probabilities using a Markov chain
key_transitions = {
"C" => { "C" => 0.2, "D" => 0.3, "E" => 0.2, "F" => 0.1, "G" => 0.1, "A" => 0.1 },
"D" => { "C" => 0.1, "D" => 0.2, "E" => 0.3, "F" => 0.1, "G" => 0.2, "A" => 0.1 },
"E" => { "C" => 0.1, "D" => 0.1, "E" => 0.2, "F" => 0.3, "G" => 0.2, "A" => 0.1 },
"F" => { "C" => 0.2, "D" => 0.1, "E" => 0.1, "F" => 0.2, "G" => 0.3, "A" => 0.1 },
"G" => { "C" => 0.1, "D" => 0.2, "E" => 0.1, "F" => 0.2, "G" => 0.2, "A" => 0.2 },
"A" => { "C" => 0.1, "D" => 0.1, "E" => 0.1, "F" => 0.2, "G" => 0.2, "A" => 0.3 }
}
# Define the keys and their corresponding MIDI note values
key_to_note = {
"C" => 60,
"D" => 62,
"E" => 64,
"F" => 65,
"G" => 67,
"A" => 69
}
# Method to switch key based on Markov chain
define :switch_key do |current_key|
transitions = key_transitions[current_key]
new_key = transitions.max_by { |_, probability| rand ** (1.0 / probability) }.first
return new_key
end
# Method to play a chord based on the current key
define :play_thing do |key|
notes = [key_to_note[key], key_to_note[key] + 4, key_to_note[key] + 7]
notes.each do |note|
play note, release: 0.3
sleep 0.25
end
end
# Method to play a syncopated chord based on the current key
define :play_syncopated_chord do |key|
# Play the root note in a lower octave
play key_to_note[key] - 12, release: 0.2
# Sleep for a short duration before playing the chord in the original octave
sleep 0.2
# Play the chord in the original octave
play_thing key
end
# Example usage: play a chord progression with key changes
live_loop :chord_progression do
current_key = "G" # Start with the key of C
8.times do
play_syncopated_chord current_key
sleep 0.5
current_key = switch_key(current_key) # Switch to a new key
end
end