-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerator_reference.go
More file actions
147 lines (129 loc) · 4.23 KB
/
generator_reference.go
File metadata and controls
147 lines (129 loc) · 4.23 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
// SPDX-License-Identifier: Apache-2.0
// Copyright Contributors to the OpenTimelineIO project
package gotio
import (
"encoding/json"
"github.com/Avalanche-io/gotio/opentime"
)
// GeneratorReferenceSchema is the schema for GeneratorReference.
var GeneratorReferenceSchema = Schema{Name: "GeneratorReference", Version: 1}
// GeneratorReference represents a media reference generated algorithmically.
type GeneratorReference struct {
MediaReferenceBase
generatorKind string
parameters AnyDictionary
}
// NewGeneratorReference creates a new GeneratorReference.
func NewGeneratorReference(
name string,
generatorKind string,
parameters AnyDictionary,
availableRange *opentime.TimeRange,
metadata AnyDictionary,
) *GeneratorReference {
if parameters == nil {
parameters = make(AnyDictionary)
}
return &GeneratorReference{
MediaReferenceBase: NewMediaReferenceBase(name, availableRange, metadata, nil),
generatorKind: generatorKind,
parameters: parameters,
}
}
// GeneratorKind returns the generator kind.
func (g *GeneratorReference) GeneratorKind() string {
return g.generatorKind
}
// SetGeneratorKind sets the generator kind.
func (g *GeneratorReference) SetGeneratorKind(kind string) {
g.generatorKind = kind
}
// Parameters returns the generator parameters.
func (g *GeneratorReference) Parameters() AnyDictionary {
return g.parameters
}
// SetParameters sets the generator parameters.
func (g *GeneratorReference) SetParameters(params AnyDictionary) {
if params == nil {
params = make(AnyDictionary)
}
g.parameters = params
}
// SchemaName returns the schema name.
func (g *GeneratorReference) SchemaName() string {
return GeneratorReferenceSchema.Name
}
// SchemaVersion returns the schema version.
func (g *GeneratorReference) SchemaVersion() int {
return GeneratorReferenceSchema.Version
}
// Clone creates a deep copy.
func (g *GeneratorReference) Clone() SerializableObject {
return &GeneratorReference{
MediaReferenceBase: MediaReferenceBase{
SerializableObjectWithMetadataBase: SerializableObjectWithMetadataBase{
name: g.name,
metadata: CloneAnyDictionary(g.metadata),
},
availableRange: cloneAvailableRange(g.availableRange),
availableImageBounds: cloneBox2d(g.availableImageBounds),
},
generatorKind: g.generatorKind,
parameters: CloneAnyDictionary(g.parameters),
}
}
// IsEquivalentTo returns true if equivalent.
func (g *GeneratorReference) IsEquivalentTo(other SerializableObject) bool {
otherG, ok := other.(*GeneratorReference)
if !ok {
return false
}
return g.name == otherG.name && g.generatorKind == otherG.generatorKind
}
// generatorReferenceJSON is the JSON representation.
type generatorReferenceJSON struct {
Schema string `json:"OTIO_SCHEMA"`
Name string `json:"name"`
Metadata AnyDictionary `json:"metadata"`
AvailableRange *opentime.TimeRange `json:"available_range"`
AvailableImageBounds *Box2d `json:"available_image_bounds"`
GeneratorKind string `json:"generator_kind"`
Parameters AnyDictionary `json:"parameters"`
}
// MarshalJSON implements json.Marshaler.
func (g *GeneratorReference) MarshalJSON() ([]byte, error) {
return json.Marshal(&generatorReferenceJSON{
Schema: GeneratorReferenceSchema.String(),
Name: g.name,
Metadata: g.metadata,
AvailableRange: g.availableRange,
AvailableImageBounds: g.availableImageBounds,
GeneratorKind: g.generatorKind,
Parameters: g.parameters,
})
}
// UnmarshalJSON implements json.Unmarshaler.
func (g *GeneratorReference) UnmarshalJSON(data []byte) error {
var j generatorReferenceJSON
if err := json.Unmarshal(data, &j); err != nil {
return err
}
g.name = j.Name
g.metadata = j.Metadata
if g.metadata == nil {
g.metadata = make(AnyDictionary)
}
g.availableRange = j.AvailableRange
g.availableImageBounds = j.AvailableImageBounds
g.generatorKind = j.GeneratorKind
g.parameters = j.Parameters
if g.parameters == nil {
g.parameters = make(AnyDictionary)
}
return nil
}
func init() {
RegisterSchema(GeneratorReferenceSchema, func() SerializableObject {
return NewGeneratorReference("", "", nil, nil, nil)
})
}