-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
note_ops.go
45 lines (42 loc) · 1.11 KB
/
note_ops.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
package core
// Pitched creates a new Note with a pitch by a (positive or negative) number of semi tones
func (n Note) Pitched(howManySemitones int) Note {
if howManySemitones == 0 {
return n
}
if n.IsRest() || n.IsPedalUp() || n.IsPedalDown() || n.IsPedalUpDown() {
return n
}
simple, err := MIDItoNote(1.0, n.MIDI()+howManySemitones, 1.0)
if err != nil {
panic(err)
}
p := MakeNote(simple.Name, simple.Octave, n.fraction, simple.Accidental, n.Dotted, n.Velocity)
// handle tied notes
for _, each := range n.tied {
p = p.WithTiedNote(each.Pitched(howManySemitones))
}
return p
}
func (n Note) Octaved(howmuch int) Note {
if howmuch == 0 {
return n
}
p := MakeNote(n.Name, n.Octave+howmuch, n.fraction, n.Accidental, n.Dotted, n.Velocity)
// handle tied notes
for _, each := range n.tied {
p = p.WithTiedNote(each.Octaved(howmuch))
}
return p
}
func (n Note) Stretched(f float32) Note {
if f == 1.0 {
return n
}
p := MakeNote(n.Name, n.Octave, n.fraction*f, n.Accidental, n.Dotted, n.Velocity)
// handle tied notes
for _, each := range n.tied {
p = p.WithTiedNote(each.Stretched(f))
}
return p
}