gibberish-dsp
Version:
Gibberish is designed to be an optimized API for audio synthesis using per-sample techniques.
87 lines (76 loc) • 2.45 kB
JavaScript
// XXX TOO MANY GLOBAL GIBBERISH VALUES
const Gibberish = require( '../index.js' )
module.exports = {
note( freq ) {
// will be sent to processor node via proxy method...
if( Gibberish.mode !== 'worklet' ) {
let voice = this.__getVoice__()
//Object.assign( voice, this.properties )
//if( gain === undefined ) gain = this.gain
//voice.gain = gain
voice.__triggerLoudness = this.__triggerLoudness
voice.note( freq, this.__triggerLoudness )
this.__runVoice__( voice, this )
this.triggerNote = freq
}
},
// XXX this is not particularly satisfying...
// must check for both notes and chords
trigger( loudness ) {
if( this.triggerChord !== null ) {
this.triggerChord.forEach( v => {
let voice = this.__getVoice__()
Object.assign( voice, this.properties )
voice.note( v, loudness )
this.__runVoice__( voice, this )
})
}else if( this.triggerNote !== null ) {
let voice = this.__getVoice__()
Object.assign( voice, this.properties )
voice.note( this.triggerNote, loudness )
this.__runVoice__( voice, this )
}else{
let voice = this.__getVoice__()
Object.assign( voice, this.properties )
voice.trigger( loudness )
this.__runVoice__( voice, this )
}
},
__runVoice__( voice, _poly ) {
if( !voice.isConnected ) {
voice.connect( _poly )
voice.isConnected = true
}
//let envCheck
//if( _poly.envCheck === undefined ) {
// envCheck = function() {
// if( voice.env.isComplete() ) {
// _poly.disconnectUgen( voice )
// voice.isConnected = false
// }else{
// Gibberish.blockCallbacks.push( envCheck )
// }
// }
//}else{
// envCheck = _poly.envCheck( voice, _poly )
//}
// XXX uncomment this line to turn on dynamically connecting
// disconnecting individual voices from graph
//Gibberish.blockCallbacks.push( envCheck )
},
__getVoice__() {
return this.voices[ this.voiceCount++ % this.voices.length ]
},
chord( frequencies ) {
// will be sent to processor node via proxy method...
if( Gibberish !== undefined && Gibberish.mode !== 'worklet' ) {
frequencies.forEach( v => this.note( v ) )
this.triggerChord = frequencies
}
},
free() {
for( let child of this.voices ) child.free()
},
triggerChord:null,
triggerNote:null
}