-
Notifications
You must be signed in to change notification settings - Fork 0
/
synthesizer.rb
67 lines (56 loc) · 1.25 KB
/
synthesizer.rb
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
module RubyCoverBand
module Instruments
class Synthesizer
attr_reader :brand, :current_patch, :patch_memory
def initialize(brand:)
@brand = brand
@patch_memory = initialize_memory
@current_patch = nil
end
def save_patch(location:, patch:)
@patch_memory.write(location: location, patch: patch)
end
def program(note)
set_patch(note.synth_sound.patch)
play_key(key: note.synth_sound.key, duration: note.duration)
end
def find(patch)
@patch_memory.find(patch)
end
def set_patch(patch)
return unless patch
location = find(patch)
if location
@current_patch = @patch_memory.read(location)
end
end
def play_key(key:, duration:)
notes[(key - 1) % 12]
end
private
def initialize_memory
if @brand == :moog
MoogPatchMemory.new
elsif @brand == :nord
NordPatchMemory.new
end
end
def notes
[
:a,
:b_flat,
:b,
:c,
:d_flat,
:d,
:e_flat,
:e,
:f,
:g_flat,
:g,
:a_flat,
]
end
end
end
end