Skip to content

Commit

Permalink
add a getKeyframes method to Sequence and TheatreSequence
Browse files Browse the repository at this point in the history
  • Loading branch information
akre54 authored and AriaMinaei committed Jul 17, 2023
1 parent 8b8d2bf commit d89cc45
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
38 changes: 38 additions & 0 deletions theatre/core/src/sequences/Sequence.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type Project from '@theatre/core/projects/Project'
import type Sheet from '@theatre/core/sheets/Sheet'
import {encodePathToProp} from '@theatre/shared/utils/addresses'
import type {SequenceAddress} from '@theatre/shared/utils/addresses'
import didYouMean from '@theatre/shared/utils/didYouMean'
import {InvalidArgumentError} from '@theatre/shared/utils/errors'
Expand All @@ -20,10 +21,12 @@ import type {
} from './playbackControllers/DefaultPlaybackController'
import DefaultPlaybackController from './playbackControllers/DefaultPlaybackController'
import TheatreSequence from './TheatreSequence'
import type {Keyframe} from '@theatre/core/projects/store/types/SheetState_Historic'
import type {ILogger} from '@theatre/shared/logger'
import type {ISequence} from '..'
import {notify} from '@theatre/shared/notify'
import type {$IntentionalAny} from '@theatre/dataverse/src/types'
import {isSheetObject} from '@theatre/shared/instanceTypes'

export type IPlaybackRange = [from: number, to: number]

Expand Down Expand Up @@ -114,6 +117,41 @@ export default class Sequence implements PointerToPrismProvider {
}
}

getKeyframes<V>(prop: Pointer<any>): Keyframe[] {
const {path, root} = getPointerParts(prop)

if (!isSheetObject(root)) {
throw new InvalidArgumentError(
'Argument prop must be a pointer to a SheetObject property',
)
}

const trackP = val(
this._project.pointers.historic.sheetsById[this._sheet.address.sheetId]
.sequence.tracksByObject[root.address.objectKey],
)

if (!trackP) {
return []
}

const {trackData, trackIdByPropPath} = trackP
const objectAddress = encodePathToProp(path)
const id = trackIdByPropPath[objectAddress]

if (!id) {
return []
}

const track = trackData[id]

if (!track) {
return []
}

return track.keyframes
}

get positionFormatter(): ISequencePositionFormatter {
return this._positionFormatterD.getValue()
}
Expand Down
12 changes: 12 additions & 0 deletions theatre/core/src/sequences/TheatreSequence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {privateAPI, setPrivateAPI} from '@theatre/core/privateAPIs'
import {defer} from '@theatre/shared/utils/defer'
import type Sequence from './Sequence'
import type {IPlaybackDirection, IPlaybackRange} from './Sequence'
import type {Keyframe} from '@theatre/core/projects/store/types/SheetState_Historic'
import AudioPlaybackController from './playbackControllers/AudioPlaybackController'
import {getCoreTicker} from '@theatre/core/coreTicker'
import type {Pointer} from '@theatre/dataverse'
Expand Down Expand Up @@ -133,6 +134,13 @@ export interface ISequence {
position: number
}>

/**
* Given a property, returns a list of keyframes that affect that property.
*
* @returns A list of keyframe objects
*/
getKeyframes(prop: Pointer<{}>): Keyframe[]

/**
* Attaches an audio source to the sequence. Playing the sequence automatically
* plays the audio source and their times are kept in sync.
Expand Down Expand Up @@ -291,6 +299,10 @@ export default class TheatreSequence implements ISequence {
privateAPI(this).position = position
}

getKeyframes(prop: Pointer<any>): Keyframe[] {
return privateAPI(this).getKeyframes(prop)
}

async attachAudio(args: IAttachAudioArgs): Promise<{
decodedBuffer: AudioBuffer
audioContext: AudioContext
Expand Down

0 comments on commit d89cc45

Please sign in to comment.