This repository was archived by the owner on Jul 21, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalue.go
More file actions
92 lines (78 loc) · 2.13 KB
/
Copy pathvalue.go
File metadata and controls
92 lines (78 loc) · 2.13 KB
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
package optional
import (
"github.com/gotracker/gomixing/panning"
"github.com/gotracker/gomixing/sampling"
"github.com/gotracker/gomixing/volume"
"github.com/gotracker/voice/period"
)
// Value is an optional value
type Value struct {
set bool
value interface{}
}
// Reset clears the memory on the value
func (o *Value) Reset() {
o.value = nil
o.set = false
}
// Set updates the value and sets the set flag
func (o *Value) Set(value interface{}) {
o.value = value
o.set = true
}
func (o *Value) IsSet() bool {
return o.set
}
// Get returns the value and its set flag
func (o *Value) Get() (interface{}, bool) {
return o.value, o.set
}
// GetBool returns the stored value as a boolean and if it has been set
func (o *Value) GetBool() (bool, bool) {
if v, ok := o.value.(bool); ok {
return v, o.set
}
return false, false
}
// GetInt returns the stored value as an integer and if it has been set
func (o *Value) GetInt() (int, bool) {
if v, ok := o.value.(int); ok {
return v, o.set
}
return 0, false
}
// GetVolume returns the stored value as a volume and if it has been set
func (o *Value) GetVolume() (volume.Volume, bool) {
if v, ok := o.value.(volume.Volume); ok {
return v, o.set
}
return volume.Volume(1), false
}
// GetPeriod returns the stored value as a period and if it has been set
func (o *Value) GetPeriod() (period.Period, bool) {
if v, ok := o.value.(period.Period); ok {
return v, o.set
}
return nil, false
}
// GetPeriodDelta returns the stored value as a period and if it has been set
func (o *Value) GetPeriodDelta() (period.Delta, bool) {
if v, ok := o.value.(period.Delta); ok {
return v, o.set
}
return period.Delta(0), false
}
// GetPanning returns the stored value as a panning position and if it has been set
func (o *Value) GetPanning() (panning.Position, bool) {
if v, ok := o.value.(panning.Position); ok {
return v, o.set
}
return panning.CenterAhead, false
}
// GetPosition returns the stored value as a sample position and if it has been set
func (o *Value) GetPosition() (sampling.Pos, bool) {
if v, ok := o.value.(sampling.Pos); ok {
return v, o.set
}
return sampling.Pos{}, false
}