-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlinear_time_warp.go
More file actions
116 lines (101 loc) · 2.97 KB
/
linear_time_warp.go
File metadata and controls
116 lines (101 loc) · 2.97 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
// SPDX-License-Identifier: Apache-2.0
// Copyright Contributors to the OpenTimelineIO project
package gotio
import (
"encoding/json"
)
// LinearTimeWarpSchema is the schema for LinearTimeWarp.
var LinearTimeWarpSchema = Schema{Name: "LinearTimeWarp", Version: 1}
// LinearTimeWarp is a time effect that applies a linear speed change.
type LinearTimeWarp struct {
EffectBase
timeScalar float64
}
// NewLinearTimeWarp creates a new LinearTimeWarp.
func NewLinearTimeWarp(name string, effectName string, timeScalar float64, metadata AnyDictionary) *LinearTimeWarp {
if timeScalar == 0 {
timeScalar = 1.0
}
return &LinearTimeWarp{
EffectBase: NewEffectBase(name, effectName, metadata),
timeScalar: timeScalar,
}
}
// TimeScalar returns the time scalar (speed multiplier).
func (l *LinearTimeWarp) TimeScalar() float64 {
return l.timeScalar
}
// SetTimeScalar sets the time scalar.
func (l *LinearTimeWarp) SetTimeScalar(scalar float64) {
l.timeScalar = scalar
}
// SchemaName returns the schema name.
func (l *LinearTimeWarp) SchemaName() string {
return LinearTimeWarpSchema.Name
}
// SchemaVersion returns the schema version.
func (l *LinearTimeWarp) SchemaVersion() int {
return LinearTimeWarpSchema.Version
}
// Clone creates a deep copy.
func (l *LinearTimeWarp) Clone() SerializableObject {
return &LinearTimeWarp{
EffectBase: EffectBase{
SerializableObjectWithMetadataBase: SerializableObjectWithMetadataBase{
name: l.name,
metadata: CloneAnyDictionary(l.metadata),
},
effectName: l.effectName,
},
timeScalar: l.timeScalar,
}
}
// IsEquivalentTo returns true if equivalent.
func (l *LinearTimeWarp) IsEquivalentTo(other SerializableObject) bool {
otherL, ok := other.(*LinearTimeWarp)
if !ok {
return false
}
return l.name == otherL.name && l.effectName == otherL.effectName && l.timeScalar == otherL.timeScalar
}
// linearTimeWarpJSON is the JSON representation.
type linearTimeWarpJSON struct {
Schema string `json:"OTIO_SCHEMA"`
Name string `json:"name"`
Metadata AnyDictionary `json:"metadata"`
EffectName string `json:"effect_name"`
TimeScalar float64 `json:"time_scalar"`
}
// MarshalJSON implements json.Marshaler.
func (l *LinearTimeWarp) MarshalJSON() ([]byte, error) {
return json.Marshal(&linearTimeWarpJSON{
Schema: LinearTimeWarpSchema.String(),
Name: l.name,
Metadata: l.metadata,
EffectName: l.effectName,
TimeScalar: l.timeScalar,
})
}
// UnmarshalJSON implements json.Unmarshaler.
func (l *LinearTimeWarp) UnmarshalJSON(data []byte) error {
var j linearTimeWarpJSON
if err := json.Unmarshal(data, &j); err != nil {
return err
}
l.name = j.Name
l.metadata = j.Metadata
if l.metadata == nil {
l.metadata = make(AnyDictionary)
}
l.effectName = j.EffectName
l.timeScalar = j.TimeScalar
if l.timeScalar == 0 {
l.timeScalar = 1.0
}
return nil
}
func init() {
RegisterSchema(LinearTimeWarpSchema, func() SerializableObject {
return NewLinearTimeWarp("", "", 1.0, nil)
})
}