-
Notifications
You must be signed in to change notification settings - Fork 0
/
keyboard.go
56 lines (44 loc) · 1.09 KB
/
keyboard.go
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
package keyboard
import (
"github.com/heucuva/go-qwertysynth/internal/machine"
"github.com/heucuva/go-qwertysynth/internal/standards/note"
"github.com/heucuva/go-qwertysynth/internal/standards/scale"
"github.com/heucuva/go-qwertysynth/internal/synth/keymap"
"github.com/heucuva/go-qwertysynth/internal/synth/voice"
"github.com/heucuva/go-qwertysynth/internal/synth/wavetable"
)
type keyboard struct {
mach machine.Machine
voices []*wavetable.Item
km keymap.KeyMap
}
func NewKeyboard(mach machine.Machine, km keymap.KeyMap, voices []*wavetable.Item) wavetable.WaveTable {
return &keyboard{
mach: mach,
voices: voices,
km: km,
}
}
func (t keyboard) Get(n note.Note) voice.Voice {
if t.voices == nil {
return nil
}
ko := n.KeyOctave()
idx := t.km[ko]
if len(t.voices) <= int(idx) {
return nil
}
w := t.voices[idx]
if w == nil {
return nil
}
v := w.Voice()
v.SetNote(n)
return v
}
func (t keyboard) Machine() machine.Machine {
return t.mach
}
func (t keyboard) Note(o scale.Octave, k scale.Key, s scale.Microtone) note.Note {
return t.mach.Note(o, k, s)
}