genish.js
Version:
33 lines (21 loc) • 690 B
JavaScript
let gen = require( './gen.js' )
let proto = {
basename:'switch',
gen() {
let inputs = gen.getInputs( this ), out
if( inputs[1] === inputs[2] ) return inputs[1] // if both potential outputs are the same just return one of them
out = ` var ${this.name}_out = ${inputs[0]} === 1 ? ${inputs[1]} : ${inputs[2]}\n`
gen.memo[ this.name ] = `${this.name}_out`
return [ `${this.name}_out`, out ]
},
}
module.exports = ( control, in1 = 1, in2 = 0 ) => {
let ugen = Object.create( proto )
Object.assign( ugen, {
uid: gen.getUID(),
inputs: [ control, in1, in2 ],
})
ugen.name = `${ugen.basename}${ugen.uid}`
return ugen
}