import { Command } from 'nf-grapher' ; import { ScoreAudioParam } from './params/ScoreAudioParam' ; export type Mutation = PushCommandsMutation | ClearCommandsMutation ; export enum MutationNames { PushCommands = 'PUSH_COMMANDS' , ClearCommands = 'CLEAR_COMMANDS' } export type MutationBase = { name : MutationNames ; } ; export type PushCommandsMutation = { graphId ? : string ; nodeId : string ; paramName : string ; commands : Array < Command > ; } & MutationBase ; export type ClearCommandsMutation = { graphId ? : string ; nodeId : string ; paramName : string ; } & MutationBase ; export type CommandsMutation = PushCommandsMutation | ClearCommandsMutation ; export function applyMutationToParam ( effect , param , commands ) { switch ( effect . name ) { case MutationNames . ClearCommands : { commands . length = 0 ; param . cancelScheduledValues ( 0 ) ; return Promise . resolve ( ) ; } case MutationNames . PushCommands : { const mutation = < PushCommandsMutation > effect ; commands . push ( ... mutation . commands ) ; param . cancelScheduledValues ( 0 ) ; param . applyScoreCommands ( commands ) ; return Promise . resolve ( ) ; } default : { const exhaustive = effect . name ; return Promise . reject ( ) ; } } }