-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfloppy.spi
250 lines (227 loc) · 9.07 KB
/
floppy.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
comment do
# source: https://gist.github.com/xavriley/87ef7548039d1ee301bb
# modified for serial output by https://github.com/jweather
# transcribed from the MML notation here: http://www.mmlshare.com/tracks/view/403
#
# Sonic Pi currently has a size limit of about 9k which is a known issue (#102).
# I've kept the comments up here to get around that as comment blocks don't get
# sent to the interpreter. Some of the layout here is an exercise in reducing bytes.
# I'm using Ruby's stabby lambda syntax ( -> { ... } ) in case you want to google it :)
#
# THIS HAS ONLY BEEN TESTED ON A MAC - on an RaspberryPi you might want to change it to
# use_bpm 60
#
# Regarding the choice of an FM synth for drums:
# You could use a noise synth here, but I think the NES sound
# chip would have used something like this FM as the character
# of the noise would change with different notes which I'm making
# use of in drum_pattern_b
end
use_debug false # help RPi performance
use_bpm 100
use_synth :pulse
use_synth_defaults release: 0.2, mod_rate: 5, amp: 0.6
define :structure do |i,a,b,c,d|
1.times { i.call }
loop do
2.times { a.call }
2.times { b.call }
1.times { c.call }
2.times { a.call }
2.times { d.call }
1.times { c.call }
1.times { d.call }
end
end
require 'serialport'
defonce :sp do
SerialPort.new("COM1", 9600, 8, 1, SerialPort::NONE)
end
sp.sync = true
sleep 4 # wait for Arduino to boot after we open the serial port
def splay_pattern_timed(notes, times)
notes.each_with_index{|note, idx|
if note == nil
sp.putc(0)
else
sp.putc(note(note) - 24)
end
#play note
sleep(times[idx % times.size])
}
end
def splay2_pattern_timed(notes, times)
notes.each_with_index{|note, idx|
if note == nil
sp.putc(100)
else
sp.putc(100 + note(note) - 12)
end
#play note
sleep(times[idx % times.size])
}
end
in_thread do
intro = -> { splay_pattern_timed([:e5,:e5,nil,:e5,nil,:c5,:e5,nil,
:g5,nil,nil,nil,nil,nil,nil,nil], [0.25]) }
theme_a = -> {
splay_pattern_timed([:c5,nil,nil,:g4,nil,nil,:e4,nil,
nil,:a4,nil,:b4,nil,:Bb4,:a4,nil], [0.25])
splay_pattern_timed([:g4,:e5,:g5], [1/3.0]) # minim triplets
splay_pattern_timed([:a5,nil,:f5,:g5,
nil,:e5,nil,:c5,
:d5,:b4,nil,nil], [0.25]) }
theme_b = -> {
splay_pattern_timed([nil,nil,:g5,:fs5,:f5,:ds5,nil,:e5,
nil,:gs4,:a4,:c5,nil,:a4,:c5,:d5,
nil,nil,:g5,:fs5,:f5,:ds5,nil,:e5,
nil,:c6,nil,:c6,:c6,nil,nil,nil,
nil,nil,:g5,:fs5,:f5,:ds5,nil,:e5,
nil,:gs4,:a4,:c5,nil,:a4,:c5,:d5,
nil,nil,:ds5,nil,nil,:d5,nil,nil,
:c5,nil,nil,nil,nil,nil,nil,nil], [0.25]) }
theme_c = -> {
splay_pattern_timed([:c5,:c5,nil,:c5,nil,:c5,:d5,nil,
:e5,:c5,nil,:a4,:g4,nil,nil,nil,
:c5,:c5,nil,:c5,nil,:c5,:d5,:e5,
nil,nil,nil,nil,nil,nil,nil,nil,
:c5,:c5,nil,:c5,nil,:c5,:d5,nil,
:e5,:c5,nil,:a4,:g4,nil,nil,nil,
:e5,:e5,nil,:e5,nil,:c5,:e5,nil,
:g5,nil,nil,nil,nil,nil,nil,nil], [0.25]) }
theme_d = -> {
splay_pattern_timed([:e5,:c5,nil,:g4,nil,nil,:gs4,nil,
:a4,:f5,nil,:f5,:a4,nil,nil,nil], [0.25])
splay_pattern_timed([:b4,:a5,:a5,
:a5,:g5,:f5], [1/3.0])
splay_pattern_timed([:e5,:c5,nil,:a4,:g4,nil,nil,nil], [0.25])
splay_pattern_timed([:e5,:c5,nil,:g4,nil,nil,:gs4,nil,
:a4,:f5,nil,:f5,:a4,nil,nil,nil,
:b4,:f5,nil,:f5], [0.25])
splay_pattern_timed([:f5,:e5,:d5], [1/3.0])
splay_pattern_timed([:g5,:e5,nil,:e5,:c5,nil,nil,nil], [0.25]) }
structure(intro, theme_a, theme_b, theme_c, theme_d)
end
comment do
in_thread do
intro = -> { splay2_pattern_timed([:fs4,:fs4,nil,:fs4,nil,:fs4,:fs4,nil,
:b4,nil,nil,nil,:g4,nil,nil,nil], [0.25]) }
theme_a = -> {
splay2_pattern_timed([:e4,nil,nil,:c4,nil,nil,:g3,nil,
nil,:c4,nil,:d4,nil,:Db4,:c4,nil], [0.25])
splay2_pattern_timed([:c4,:g4,:b4], [1/3.0])
splay2_pattern_timed([:c5,nil,:a4,:b4,
nil,:a4,nil,:e4,
:f4,:d4,nil,nil], [0.25]) }
theme_b = -> {
splay2_pattern_timed([nil,nil,:e5,:ds5,:d5,:b4,nil,:c5,
nil,:e4,:f4,:g4,nil,:c4,:e4,:f4,
nil,nil,:e5,:ds5,:d5,:b4,nil,:c5,
nil,:f5,nil,:f5,:f5,nil,nil,nil,
nil,nil,:e5,:ds5,:d5,:b4,nil,:c5,
nil,:e4,:f4,:g4,nil,:c4,:e4,:f4,
nil,nil,:gs4,nil,nil,:f4,nil,nil,
:e4,nil,nil,nil,nil,nil,nil,nil], [0.25]) }
theme_c = -> {
splay2_pattern_timed([:gs4,:gs4,nil,:gs4,nil,:gs4,:as4,nil,
:g4,:e4,nil,:e4,:c4,nil,nil,nil,
:gs4,:gs4,nil,:gs4,nil,:gs4,:as4,:g4,
nil,nil,nil,nil,nil,nil,nil,nil,
:gs4,:gs4,nil,:gs4,nil,:gs4,:as4,nil,
:g4,:e4,nil,:e4,:c4,nil,nil,nil,
:fs4,:fs4,nil,:fs4,nil,:fs4,:fs4,nil,
:b4,nil,nil,nil,:g4,nil,nil,nil], [0.25]) }
theme_d = -> {
splay2_pattern_timed([:c5,:a4,nil,:e4,nil,nil,:e4,nil,
:f4,:c5,nil,:c5,:f4,nil,nil,nil], [0.25])
splay2_pattern_timed([:g4,:f5,:f5,
:f5,:e5,:d5], [1/3.0])
splay2_pattern_timed([:c5,:a4,nil,:f4,:e4,nil,nil,nil], [0.25])
splay2_pattern_timed([:c5,:a4,nil,:e4,nil,nil,:e4,nil,
:f4,:c5,nil,:c5,:f4,nil,nil,nil,
:g4,:d5,nil,:d5], [0.25])
splay2_pattern_timed([:d5,:c5,:b4], [1/3.0])
splay2_pattern_timed([:c5,nil,nil,nil,nil,nil,nil,nil], [0.25]) }
structure(intro, theme_a, theme_b, theme_c, theme_d)
end
end
in_thread do
use_synth :tri
use_synth_defaults attack: 0, sustain: 0.1, decay: 0.1, release: 0.1, amp: 0.4
intro = -> { splay2_pattern_timed([:D4,:D4,nil,:D4,nil,:D4,:D4,nil,
:G3,nil,nil,nil,:G4,nil,nil,nil], [0.25]) }
theme_a = -> {
splay2_pattern_timed([:G4,nil,nil,:E4,nil,nil,:C4,nil,
nil,:F4,nil,:G4,nil,:Gb4,:F4,nil], [0.25])
splay2_pattern_timed([:E4,:C4,:E4], [1/3.0])
splay2_pattern_timed([:F4,nil,:D4,:E4,
nil,:C4,nil,:A3,
:B3,:G3,nil,nil], [0.25]) }
theme_b = -> {
splay2_pattern_timed([:C3,nil,nil,:G3,nil,nil,:C3,nil,
:F3,nil,nil,:C3,:C3,nil,:F3,nil,
:C3,nil,nil,:E3,nil,nil,:G3,:C3,
nil,:G2,nil,:G2,:G2,nil,:G4,nil,
:C3,nil,nil,:G3,nil,nil,:C3,nil,
:F3,nil,nil,:C3,:C3,nil,:F3,nil,
:C3,nil,:Ab3,nil,nil,:Bb3,nil,nil,
:C3,nil,nil,:G2,:G2,nil,:C3,nil], [0.25]) }
theme_c = -> {
3.times {
splay2_pattern_timed([:gs4,nil,nil,:ds4,nil,nil,:gs4,nil,
:g4,nil,nil,:c4,nil,nil,:g4,nil], [0.25])
}
splay2_pattern_timed([:D4,:D4,nil,:D4,nil,:D4,:D4,nil,
:G3,nil,nil,nil,:G4,nil,nil,nil], [0.25]) }
theme_d = -> {
splay2_pattern_timed([:C3,nil,nil,:fs3,:g3,nil,:C3,nil,
:F3,nil,:F3,nil,:C3,:C3,:F3,nil,
:D3,nil,nil,:F3,:G3,nil,:B3,nil,
:G3,nil,:G3,nil,:C3,:C3,:G3,nil,
:C3,nil,nil,:fs3,:g3,nil,:C3,nil,
:F3,nil,:F3,nil,:C3,:C3,:F3,nil,
:G3,nil,nil,:G3], [0.25])
splay2_pattern_timed([:G3,:A3,:B3], [1/3.0])
splay2_pattern_timed([:C4,nil,:G3,nil,:C4,nil,nil,nil], [0.25]) }
structure(intro, theme_a, theme_b, theme_c, theme_d)
end
comment do
in_thread do
use_synth :fm
use_synth_defaults divisor: 1.6666, attack: 0.0, depth: 1500, sustain: 0.05, release: 0.0
ll = -> { play :a, sustain: 0.1; sleep 0.75 }
l = -> { play :a, sustain: 0.1; sleep 0.5 }
s = -> { play :a; sleep 0.25 }
define :drum_pattern_a do
[l,s,l,s,l,ll,l,s,s,s].map(&:call)
end
define :drum_pattern_b do
play :b
sleep 0.5
play :a6
sleep 0.3
play :a7
sleep 0.2
play :a, sustain: 0.1
sleep 0.5
play :a6
sleep 0.3
play :a7
sleep 0.2
end
define :drum_pattern_c do
[ll,s,l,l].map(&:call)
end
with_fx :level, amp: 0.5 do
1.times { drum_pattern_a }
loop do
24.times { drum_pattern_b }
4.times { drum_pattern_a }
8.times { drum_pattern_b }
16.times { drum_pattern_c }
4.times { drum_pattern_a }
8.times { drum_pattern_b }
end
end
end
end