import { Node , GainNode as GGainNode , LoopNode , FileNode , StretchNode } from 'nf-grapher' ; import { DirectedScore } from '../DirectedScore' ; import { SPNode , NodePlaybackDescription } from './SPNode' ; import { SPGainNode } from './SPGainNode' ; import { SPFileNode } from './SPFileNode' ; import { SPLoopNode } from './SPLoopNode' ; import { TimeInstant } from '../time' ; import { SPDestinationNode } from './SPDestinationNode' ; import { SPPassthroughNode } from './SPPassthroughNode' ; import { SPStretchNode } from './SPStretchNode' ; import { XAudioBuffer } from '../XAudioBuffer' ; import { RendererInfo } from '../renderers/RendererInfo' ; export class SPNodeFactory { static fromNode ( node , info , dscore ) { switch ( node . kind ) { case GGainNode . PLUGIN_KIND : { return new SPGainNode ( info , node , dscore ) ; } case FileNode . PLUGIN_KIND : { return new SPFileNode ( info , node , dscore ) ; } case LoopNode . PLUGIN_KIND : { return new SPLoopNode ( info , node , dscore ) ; } case StretchNode . PLUGIN_KIND : { return new SPStretchNode ( info , node , dscore ) ; } default : { console . warn ( 'Unimplemented node: ' + node . kind + '. Substituting with Passthrough.' ) ; return new SPPassthroughNode ( info , node , dscore ) ; } } } static createAncestors ( forNode , info , dscore ) { const ancestors = [ ] ; if ( forNode . kind === SPDestinationNode . KIND ) { const leaves = dscore . leaves ( ) ; leaves . forEach ( node => { const ancestor = SPNodeFactory . fromNode ( node , info , dscore ) ; if ( ! ancestor ) return ; ancestors . push ( ancestor ) ; } ) ; } else { const incoming = dscore . incomingEdges ( forNode ) ; incoming . forEach ( edge => { const ancestor = dscore . source ( edge ) ; if ( ! ancestor ) return ; let mixer = SPNodeFactory . fromNode ( ancestor , info , dscore ) ; if ( mixer !== undefined ) { ancestors . push ( mixer ) ; } } ) ; } return ancestors ; } static feed ( ancestors , renderTime , buffers , quantumSize ) { for ( let i = 0 ; i < ancestors . length ; i ++ ) { ancestors [ i ] . feed ( renderTime , buffers , quantumSize ) ; } } static getPlaybackDescription ( ancestors , renderTime , descriptions ) { for ( let i = 0 ; i < ancestors . length ; i ++ ) { ancestors [ i ] . getPlaybackDescription ( renderTime , descriptions ) ; } } } export { SPNode , SPFileNode , SPGainNode , SPLoopNode , SPStretchNode , SPDestinationNode , NodePlaybackDescription } ;