import { TimeInstant } from '../time' ; import { Node } from 'nf-grapher' ; import { DirectedScore } from '../DirectedScore' ; import { SPNodeFactory } from './SPNodeFactory' ; import { ContentCache } from '../ContentCache' ; import { CommandsMutation } from '../Mutations' ; import { XAudioBuffer } from '../XAudioBuffer' ; import { RendererInfo } from '../renderers/RendererInfo' ; export type NodePlaybackDescription = { id : string ; kind : string ; time : TimeInstant ; file ? : { maxDuration : TimeInstant ; } ; loop ? : { loopsSinceStart : number ; currentLoopStartTime : TimeInstant ; currentLoopEndTime : TimeInstant ; loopElapsedTime : TimeInstant ; infinite : boolean ; } ; } ; export abstract class SPNode { public ancestors : SPNode [ ] = [ ] ; constructor ( protected info , public readonly node , protected dscore ) { } feed ( renderTime , buffers , quantumSize ) { for ( let i = 0 ; i < this . ancestors . length ; i ++ ) { this . ancestors [ i ] . feed ( renderTime , buffers , quantumSize ) ; } } ancestorsWithId ( nodeId ) { let result = [ ] ; this . ancestors . forEach ( ancestor => { if ( ancestor . node . id === nodeId ) { result . push ( ancestor ) ; return ; } const ancestorResult = ancestor . ancestorsWithId ( nodeId ) ; if ( ancestorResult ) { result . push ( ... ancestorResult ) ; } } ) ; return result ; } async unmountAncestors ( ) { return Promise . all ( this . ancestors . map ( node => node . nodeWillUnmount ( ) ) ) ; } async timeChange ( renderTime , cache , quantumSize ) { await this . unmountAncestors ( ) ; this . ancestors = SPNodeFactory . createAncestors ( this . node , this . info , this . dscore ) ; await Promise . all ( this . ancestors . map ( node => node . timeChange ( renderTime , cache , quantumSize ) ) ) ; await this . nodeDidMount ( ) ; } getPlaybackDescription ( renderTime , descriptions ) { descriptions . push ( { id : this . node . id , kind : this . node . kind , time : renderTime } ) ; SPNodeFactory . getPlaybackDescription ( this . ancestors , renderTime , descriptions ) ; } async nodeDidMount ( ) { } async nodeWillUnmount ( ) { } acceptCommandsEffect ( effect ) { throw new Error ( `${ this . node . kind } has no params to accept commands.` ) ; } }