Skip to content

KeyChannel

Tempestissiman edited this page Jul 26, 2022 · 2 revisions

Descriptions

Returns a value from timing input, based on keys.

Remarks

Inherited from ValueChannel.

Properties


Name Type Description
name string The name of the channel
keyCount number The number of keys added to this channel
introExtrapolation bool Whether to extrapolate before the first key
outtroExtrapolation bool Whether to extrapolate after the final key

Methods


setDefaultEasing(easing)

Descriptions

Set the easing for all subsequently created keys that do not have its easing explicitly defined.

Parameters

Name Type Description
easing string The easing type

Return types

KeyChannel

Remarks

This method returns the channel itself, which allows for chaining multiple methods.

Example

local channel = Channel.keyframe().setDefaultEasing('b')
channel.addKey(0, 10) -- easing 'b'
channel.addKey(1000, 5, 'so') -- easing 'so'
channel.addKey(2000, 5) -- easing 'b'

setIntroExtrapolation(toggle)

Descriptions

Set the value of the property introExtrapolation.

Parameters

Name Type Description
toggle boolean Same as introExtrapolation

Return types

KeyChannel

Remarks

This method returns the channel itself, which allows for chaining multiple methods.

Example

local channel = Channel.keyframe().setIntroExtrapolation(true)
channel.addKey(1000, 10)
channel.addKey(2000, 5)
log(channel.valueAt(0)) -- should be larger than 10

setOuttroExtrapolation(toggle)

Descriptions

Set the value of the property outtroExtrapolation.

Parameters

Name Type Description
toggle boolean Same as outtroExtrapolation

Return types

KeyChannel

Remarks

This method returns the channel itself, which allows for chaining multiple methods.

Example

local channel = Channel.keyframe().setOuttroExtrapolation(true)
channel.addKey(1000, 10)
channel.addKey(2000, 5)
log(channel.valueAt(3000)) -- should be smaller than 5

addKey(timing, value, easing = nil)

Descriptions

Add a key to the channel.

Parameters

Name Type Description
timing number Timing of the key
value number Value of the key
easing string Easing of the key

Return types

KeyChannel

Remarks

This method returns the channel itself, which allows for chaining multiple methods.

In case easing is not specified, or set to nil, the default easing of this channel is used

Example

local channel = Channel.keyframe()
channel.addKey(1000, 10)
channel.addKey(2000, 5, 'so')

removeKeyAtTiming(timing)

Descriptions

Remove a key with the exact timing.

Parameters

Name Type Description
timing number Timing of the key to remove

Return types

KeyChannel

Remarks

Currently if there are multiple keys with the same timing, this only removes the first one.

Example

local channel = Channel.keyframe().addKey(1000, 10).addKey(2000, 5, 'so')
channel.removeKeyAtTiming(1000)
log(channel.keyCount)

removeKeyAtIndex(index)

Descriptions

Removess the index-th key.

Parameters

Name Type Description
index number Index of the key to remove

Return types

KeyChannel

Remarks

_

Example

local channel = Channel.keyframe().addKey(1000, 10).addKey(2000, 5, 'so')
channel.removeKeyAtIndex(2) -- Remove the 2nd key with timing 2000ms
log(channel.keyCount)

find(name)

Descriptions

Find the channel within the sub-channels that composed this.

Parameters

Name Type Description
name string Name of the channel to find

Return types

ValueChannel

Remarks

Returns nil if no channel was found. Because this channel is not a composition channel, this means it'll only return itself if the provided name matches its own, and will always return nil otherwise

This method is useful to detect if you have previously created a channel for a property of a controller, which is a common need when working with note groups.

Example

local toFind = Channel.named("myChannel").keyframe()
track.colorA = toFind

local foundChannel = track.colorA.find("myChannel")
foundChannel.addKey(0, 255)

valueAt(timing)

Descriptions

Calculate the value at a timing point.

Parameters

Name Type Description
timing number Timing point to calculate at

Return types

number

Remarks

_

Example

local saw = Channel.saw('so', 1000, 1, 0)
log(saw.valueAt(500))
local keyChannel = Channel.keyframe()

track.colorA.addKey(1000, keyChannel.valueAt(1000))
track.colorA.addKey(2000, 0)

Operators


Operator Return type Description
+ ValueChannel Add two value channels, or a value channel with a number, or a number with a value channel together
- ValueChannel Subtract two value channels, or a value channel with a number, or a number with a value channel together
* ValueChannel Multiply two value channels, or a value channel with a number, or a number with a value channel together
/ ValueChannel Divide one value channel with another, or a value channel with a number, or a number with a value channel

Clone this wiki locally