-
Notifications
You must be signed in to change notification settings - Fork 6
/
effect.go
116 lines (100 loc) · 3.62 KB
/
effect.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
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
package playback
import (
"fmt"
"reflect"
"github.com/gotracker/playback/index"
"github.com/gotracker/playback/period"
"github.com/gotracker/playback/player/machine"
"github.com/gotracker/playback/song"
)
// Effect is an interface to command/effect
type Effect interface {
//fmt.Stringer
TraceData() string
}
type Effecter[TMemory song.ChannelMemory] interface {
GetEffects(TMemory, period.Period) []Effect
}
func GetEffects[TPeriod period.Period, TMemory song.ChannelMemory, TChannelData song.ChannelData[TVolume], TGlobalVolume, TMixingVolume, TVolume song.Volume, TPanning song.Panning](mem TMemory, d TChannelData) []Effect {
var e []Effect
if eff, ok := any(d).(Effecter[TMemory]); ok {
var p TPeriod
e = eff.GetEffects(mem, p)
}
return e
}
type EffectNamer interface {
Names() []string
}
func GetEffectNames(e Effect) []string {
if namer, ok := e.(EffectNamer); ok {
return namer.Names()
} else {
typ := reflect.TypeOf(e)
return []string{typ.Name()}
}
}
// CombinedEffect specifies multiple simultaneous effects into one
type CombinedEffect[TPeriod period.Period, TGlobalVolume, TMixingVolume, TVolume song.Volume, TPanning song.Panning, TMemory song.ChannelMemory, TChannelData song.ChannelData[TVolume]] struct {
Effects []Effect
}
// String returns the string for the effect list
func (e CombinedEffect[TPeriod, TGlobalVolume, TMixingVolume, TVolume, TPanning, TMemory, TChannelData]) String() string {
for _, eff := range e.Effects {
s := fmt.Sprint(eff)
if s != "" {
return s
}
}
return ""
}
func (e CombinedEffect[TPeriod, TGlobalVolume, TMixingVolume, TVolume, TPanning, TMemory, TChannelData]) Names() []string {
var names []string
for _, eff := range e.Effects {
names = append(names, GetEffectNames(eff)...)
}
return names
}
func (e CombinedEffect[TPeriod, TGlobalVolume, TMixingVolume, TVolume, TPanning, TMemory, TChannelData]) OrderStart(ch index.Channel, m machine.Machine[TPeriod, TGlobalVolume, TMixingVolume, TVolume, TPanning]) error {
for _, effect := range e.Effects {
if err := m.DoInstructionOrderStart(ch, effect); err != nil {
return err
}
}
return nil
}
func (e CombinedEffect[TPeriod, TGlobalVolume, TMixingVolume, TVolume, TPanning, TMemory, TChannelData]) RowStart(ch index.Channel, m machine.Machine[TPeriod, TGlobalVolume, TMixingVolume, TVolume, TPanning]) error {
for _, effect := range e.Effects {
if err := m.DoInstructionRowStart(ch, effect); err != nil {
return err
}
}
return nil
}
func (e CombinedEffect[TPeriod, TGlobalVolume, TMixingVolume, TVolume, TPanning, TMemory, TChannelData]) Tick(ch index.Channel, m machine.Machine[TPeriod, TGlobalVolume, TMixingVolume, TVolume, TPanning], tick int) error {
for _, effect := range e.Effects {
if err := m.DoInstructionTick(ch, effect); err != nil {
return err
}
}
return nil
}
func (e CombinedEffect[TPeriod, TGlobalVolume, TMixingVolume, TVolume, TPanning, TMemory, TChannelData]) RowEnd(ch index.Channel, m machine.Machine[TPeriod, TGlobalVolume, TMixingVolume, TVolume, TPanning]) error {
for _, effect := range e.Effects {
if err := m.DoInstructionRowEnd(ch, effect); err != nil {
return err
}
}
return nil
}
func (e CombinedEffect[TPeriod, TGlobalVolume, TMixingVolume, TVolume, TPanning, TMemory, TChannelData]) OrderEnd(ch index.Channel, m machine.Machine[TPeriod, TGlobalVolume, TMixingVolume, TVolume, TPanning]) error {
for _, effect := range e.Effects {
if err := m.DoInstructionOrderEnd(ch, effect); err != nil {
return err
}
}
return nil
}
func (e CombinedEffect[TPeriod, TGlobalVolume, TMixingVolume, TVolume, TPanning, TMemory, TChannelData]) TraceData() string {
return e.String()
}