import { TimeInstant } from './time' ; import { Score } from 'nf-grapher' ; import { Mutation } from './Mutations' ; import { NodePlaybackDescription } from './nodes/SPNodeFactory' ; import { BaseRenderer } from './renderers/BaseRenderer' ; import { ScriptProcessorRenderer } from './renderers/ScriptProcessorRenderer' ; export { NodePlaybackDescription } ; export class SmartPlayer { constructor ( private renderer = new ScriptProcessorRenderer ( ) ) { } async setJson ( json ) { await this . renderer . dequeueScores ( ) ; await this . enqueueScore ( json ) ; if ( this . renderTime . neq ( TimeInstant . ZERO ) ) { await this . renderer . timeChange ( TimeInstant . ZERO ) ; } } getJson ( graphId ? ) { if ( ! graphId ) { return JSON . stringify ( this . renderer . getScores ( ) ) ; } const score = this . renderer . getScore ( graphId ) ; return JSON . stringify ( score ) ; } get playing ( ) { return this . renderer . playing ; } set playing ( state ) { this . renderer . playing = ! ! state ; } get renderTime ( ) : TimeInstant { return this . renderer . renderedTime ( ) ; } deprecated set renderTime ( time ) { this . renderer . timeChange ( time ) ; } /**
     * Set renderTime to `time`. Seeking / setting renderTime is actually
     * an asynchronous process since the internal graph must be destroyed and
     * rebuilt, and potentially new content loaded. `seek` allows a user to
     * await the operation, unlike set/get `renderTime`.
     */ seek ( time ) { return this . renderer . timeChange ( time ) ; } public getPlaybackDescription ( renderTime ) { return this . renderer . getPlaybackDescription ( renderTime ) ; } public async enqueueMutation ( effect ) { return this . renderer . enqueueEffect ( effect ) ; } public enqueueScore ( score , fadeIn ? ) ; public enqueueScore ( score , fadeIn ? ) ; public enqueueScore ( scoreOrJSON , fadeIn = true ) { let score ; if ( typeof scoreOrJSON === 'string' ) { score = JSON . parse ( scoreOrJSON ) ; } else { score = JSON . parse ( JSON . stringify ( scoreOrJSON ) ) ; } return this . renderer . enqueueScore ( score , fadeIn ) ; } public dequeueScore ( graphId , fadeOut = true ) { return this . renderer . dequeueScore ( graphId , fadeOut ) ; } public dequeueScores ( ) { return this . renderer . dequeueScores ( ) ; } }