-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheffect.go
More file actions
129 lines (109 loc) · 3.08 KB
/
effect.go
File metadata and controls
129 lines (109 loc) · 3.08 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
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
// SPDX-License-Identifier: Apache-2.0
// Copyright Contributors to the OpenTimelineIO project
package gotio
import (
"encoding/json"
)
// Effect is the interface for effects.
type Effect interface {
SerializableObjectWithMetadata
// EffectName returns the effect name.
EffectName() string
// SetEffectName sets the effect name.
SetEffectName(name string)
}
// EffectSchema is the schema for Effect.
var EffectSchema = Schema{Name: "Effect", Version: 1}
// EffectBase is the base implementation of Effect.
type EffectBase struct {
SerializableObjectWithMetadataBase
effectName string
}
// NewEffectBase creates a new EffectBase.
func NewEffectBase(name string, effectName string, metadata AnyDictionary) EffectBase {
return EffectBase{
SerializableObjectWithMetadataBase: NewSerializableObjectWithMetadataBase(name, metadata),
effectName: effectName,
}
}
// EffectName returns the effect name.
func (e *EffectBase) EffectName() string {
return e.effectName
}
// SetEffectName sets the effect name.
func (e *EffectBase) SetEffectName(name string) {
e.effectName = name
}
// EffectImpl is the standard Effect implementation.
type EffectImpl struct {
EffectBase
}
// NewEffect creates a new Effect.
func NewEffect(name string, effectName string, metadata AnyDictionary) *EffectImpl {
return &EffectImpl{
EffectBase: NewEffectBase(name, effectName, metadata),
}
}
// SchemaName returns the schema name.
func (e *EffectImpl) SchemaName() string {
return EffectSchema.Name
}
// SchemaVersion returns the schema version.
func (e *EffectImpl) SchemaVersion() int {
return EffectSchema.Version
}
// Clone creates a deep copy.
func (e *EffectImpl) Clone() SerializableObject {
return &EffectImpl{
EffectBase: EffectBase{
SerializableObjectWithMetadataBase: SerializableObjectWithMetadataBase{
name: e.name,
metadata: CloneAnyDictionary(e.metadata),
},
effectName: e.effectName,
},
}
}
// IsEquivalentTo returns true if equivalent.
func (e *EffectImpl) IsEquivalentTo(other SerializableObject) bool {
otherE, ok := other.(*EffectImpl)
if !ok {
return false
}
return e.name == otherE.name && e.effectName == otherE.effectName
}
// effectJSON is the JSON representation.
type effectJSON struct {
Schema string `json:"OTIO_SCHEMA"`
Name string `json:"name"`
Metadata AnyDictionary `json:"metadata"`
EffectName string `json:"effect_name"`
}
// MarshalJSON implements json.Marshaler.
func (e *EffectImpl) MarshalJSON() ([]byte, error) {
return json.Marshal(&effectJSON{
Schema: EffectSchema.String(),
Name: e.name,
Metadata: e.metadata,
EffectName: e.effectName,
})
}
// UnmarshalJSON implements json.Unmarshaler.
func (e *EffectImpl) UnmarshalJSON(data []byte) error {
var j effectJSON
if err := json.Unmarshal(data, &j); err != nil {
return err
}
e.name = j.Name
e.metadata = j.Metadata
if e.metadata == nil {
e.metadata = make(AnyDictionary)
}
e.effectName = j.EffectName
return nil
}
func init() {
RegisterSchema(EffectSchema, func() SerializableObject {
return NewEffect("", "", nil)
})
}