-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetters.go
314 lines (304 loc) · 8.63 KB
/
setters.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
package eternal
import "github.com/CharlesHolbrow/synk"
// cellDiff diff type for synk.Object
type cellDiff struct {
Hue *float32 `json:"hue,omitempty"`
X *int `json:"x,omitempty"`
Y *int `json:"y,omitempty"`
AudioPath *string `json:"audioPath,omitempty"`
MapName *string `json:"mapName,omitempty"`
Class *string `json:"class,omitempty"`
MidiNote *int `json:"midiNote,omitempty"`
}
// State returns a fully populated diff of the unresolved state
func (o *Cell) State() interface{} {
d := cellDiff{
Hue: &o.Hue,
X: &o.X,
Y: &o.Y,
AudioPath: &o.AudioPath,
MapName: &o.MapName,
Class: &o.Class,
MidiNote: &o.MidiNote,
}
return d
}
// Resolve applies the current diff, then returns it
func (o *Cell) Resolve() interface{} {
if o.diff.Hue != nil {o.Hue = *o.diff.Hue}
if o.diff.X != nil {o.X = *o.diff.X}
if o.diff.Y != nil {o.Y = *o.diff.Y}
if o.diff.AudioPath != nil {o.AudioPath = *o.diff.AudioPath}
if o.diff.MapName != nil {o.MapName = *o.diff.MapName}
if o.diff.Class != nil {o.Class = *o.diff.Class}
if o.diff.MidiNote != nil {o.MidiNote = *o.diff.MidiNote}
o.V++
diff := o.diff
o.diff = cellDiff{}
return diff
}
// Changed checks if struct has been changed since the last .Resolve()
func (o *Cell) Changed() bool {
return o.diff.Hue != nil ||
o.diff.X != nil ||
o.diff.Y != nil ||
o.diff.AudioPath != nil ||
o.diff.MapName != nil ||
o.diff.Class != nil ||
o.diff.MidiNote != nil
}
// Diff getter
func (o *Cell) Diff() interface{} { return o.diff }
// Copy duplicates this object and returns an interface to it.
// The object's diff will be copied too, with the exception of the diffMap for
// array members. A diffMap is created automatically when we use array Element
// setters (ex SetDataElement). Copy() will create shallow copies of unresolved
// diffMaps. Usually we Resolve() after Copy() which means that our shallow copy
// will be safe to send over a channel.
func (o *Cell) Copy() synk.Object {
n := *o
return &n
}
// Init (ialize) all diff fields to the current values. The next call to
// Resolve() will return a diff with all the fields initialized.
func (o *Cell) Init() {
o.diff = o.State().(cellDiff)
}
// SetHue on diff
func (o *Cell) SetHue(v float32) {
if v != o.Hue {
o.diff.Hue = &v
} else {
o.diff.Hue = nil
}
}
// GetPrevHue Gets the previous value. Ignores diff.
func (o *Cell) GetPrevHue() float32 { return o.Hue }
// GetHue from diff. Fall back to current value if no diff
func (o *Cell) GetHue() float32 {
if o.diff.Hue != nil {
return *o.diff.Hue
}
return o.Hue
}
// GetHue. Diff method
func (o cellDiff) GetHue() *float32 { return o.Hue }
// SetX on diff
func (o *Cell) SetX(v int) {
if v != o.X {
o.diff.X = &v
} else {
o.diff.X = nil
}
}
// GetPrevX Gets the previous value. Ignores diff.
func (o *Cell) GetPrevX() int { return o.X }
// GetX from diff. Fall back to current value if no diff
func (o *Cell) GetX() int {
if o.diff.X != nil {
return *o.diff.X
}
return o.X
}
// GetX. Diff method
func (o cellDiff) GetX() *int { return o.X }
// SetY on diff
func (o *Cell) SetY(v int) {
if v != o.Y {
o.diff.Y = &v
} else {
o.diff.Y = nil
}
}
// GetPrevY Gets the previous value. Ignores diff.
func (o *Cell) GetPrevY() int { return o.Y }
// GetY from diff. Fall back to current value if no diff
func (o *Cell) GetY() int {
if o.diff.Y != nil {
return *o.diff.Y
}
return o.Y
}
// GetY. Diff method
func (o cellDiff) GetY() *int { return o.Y }
// SetAudioPath on diff
func (o *Cell) SetAudioPath(v string) {
if v != o.AudioPath {
o.diff.AudioPath = &v
} else {
o.diff.AudioPath = nil
}
}
// GetPrevAudioPath Gets the previous value. Ignores diff.
func (o *Cell) GetPrevAudioPath() string { return o.AudioPath }
// GetAudioPath from diff. Fall back to current value if no diff
func (o *Cell) GetAudioPath() string {
if o.diff.AudioPath != nil {
return *o.diff.AudioPath
}
return o.AudioPath
}
// GetAudioPath. Diff method
func (o cellDiff) GetAudioPath() *string { return o.AudioPath }
// SetMapName on diff
func (o *Cell) SetMapName(v string) {
if v != o.MapName {
o.diff.MapName = &v
} else {
o.diff.MapName = nil
}
}
// GetPrevMapName Gets the previous value. Ignores diff.
func (o *Cell) GetPrevMapName() string { return o.MapName }
// GetMapName from diff. Fall back to current value if no diff
func (o *Cell) GetMapName() string {
if o.diff.MapName != nil {
return *o.diff.MapName
}
return o.MapName
}
// GetMapName. Diff method
func (o cellDiff) GetMapName() *string { return o.MapName }
// SetClass on diff
func (o *Cell) SetClass(v string) {
if v != o.Class {
o.diff.Class = &v
} else {
o.diff.Class = nil
}
}
// GetPrevClass Gets the previous value. Ignores diff.
func (o *Cell) GetPrevClass() string { return o.Class }
// GetClass from diff. Fall back to current value if no diff
func (o *Cell) GetClass() string {
if o.diff.Class != nil {
return *o.diff.Class
}
return o.Class
}
// GetClass. Diff method
func (o cellDiff) GetClass() *string { return o.Class }
// SetMidiNote on diff
func (o *Cell) SetMidiNote(v int) {
if v != o.MidiNote {
o.diff.MidiNote = &v
} else {
o.diff.MidiNote = nil
}
}
// GetPrevMidiNote Gets the previous value. Ignores diff.
func (o *Cell) GetPrevMidiNote() int { return o.MidiNote }
// GetMidiNote from diff. Fall back to current value if no diff
func (o *Cell) GetMidiNote() int {
if o.diff.MidiNote != nil {
return *o.diff.MidiNote
}
return o.MidiNote
}
// GetMidiNote. Diff method
func (o cellDiff) GetMidiNote() *int { return o.MidiNote }
// noteDiff diff type for synk.Object
type noteDiff struct {
SubKey *string `json:"subKey,omitempty"`
Number *int `json:"number,omitempty"`
Velocity *int `json:"velocity,omitempty"`
}
// State returns a fully populated diff of the unresolved state
func (o *Note) State() interface{} {
d := noteDiff{
SubKey: &o.SubKey,
Number: &o.Number,
Velocity: &o.Velocity,
}
return d
}
// Resolve applies the current diff, then returns it
func (o *Note) Resolve() interface{} {
if o.diff.SubKey != nil {o.SubKey = *o.diff.SubKey}
if o.diff.Number != nil {o.Number = *o.diff.Number}
if o.diff.Velocity != nil {o.Velocity = *o.diff.Velocity}
o.V++
diff := o.diff
o.diff = noteDiff{}
return diff
}
// Changed checks if struct has been changed since the last .Resolve()
func (o *Note) Changed() bool {
return o.diff.SubKey != nil ||
o.diff.Number != nil ||
o.diff.Velocity != nil
}
// Diff getter
func (o *Note) Diff() interface{} { return o.diff }
// Copy duplicates this object and returns an interface to it.
// The object's diff will be copied too, with the exception of the diffMap for
// array members. A diffMap is created automatically when we use array Element
// setters (ex SetDataElement). Copy() will create shallow copies of unresolved
// diffMaps. Usually we Resolve() after Copy() which means that our shallow copy
// will be safe to send over a channel.
func (o *Note) Copy() synk.Object {
n := *o
return &n
}
// Init (ialize) all diff fields to the current values. The next call to
// Resolve() will return a diff with all the fields initialized.
func (o *Note) Init() {
o.diff = o.State().(noteDiff)
}
// SetSubKey on diff
func (o *Note) SetSubKey(v string) {
if v != o.SubKey {
o.diff.SubKey = &v
} else {
o.diff.SubKey = nil
}
}
// GetPrevSubKey Gets the previous value. Ignores diff.
func (o *Note) GetPrevSubKey() string { return o.SubKey }
// GetSubKey from diff. Fall back to current value if no diff
func (o *Note) GetSubKey() string {
if o.diff.SubKey != nil {
return *o.diff.SubKey
}
return o.SubKey
}
// GetSubKey. Diff method
func (o noteDiff) GetSubKey() *string { return o.SubKey }
// SetNumber on diff
func (o *Note) SetNumber(v int) {
if v != o.Number {
o.diff.Number = &v
} else {
o.diff.Number = nil
}
}
// GetPrevNumber Gets the previous value. Ignores diff.
func (o *Note) GetPrevNumber() int { return o.Number }
// GetNumber from diff. Fall back to current value if no diff
func (o *Note) GetNumber() int {
if o.diff.Number != nil {
return *o.diff.Number
}
return o.Number
}
// GetNumber. Diff method
func (o noteDiff) GetNumber() *int { return o.Number }
// SetVelocity on diff
func (o *Note) SetVelocity(v int) {
if v != o.Velocity {
o.diff.Velocity = &v
} else {
o.diff.Velocity = nil
}
}
// GetPrevVelocity Gets the previous value. Ignores diff.
func (o *Note) GetPrevVelocity() int { return o.Velocity }
// GetVelocity from diff. Fall back to current value if no diff
func (o *Note) GetVelocity() int {
if o.diff.Velocity != nil {
return *o.diff.Velocity
}
return o.Velocity
}
// GetVelocity. Diff method
func (o noteDiff) GetVelocity() *int { return o.Velocity }