import { instrument } from "../synth"
import Gain from "../kit/gain"
import Osc from "../kit/osc"
import GainEnvelope from "../kit/gain-envelope"
import Filter from "../kit/filter"
/**
* Create a Cowbell
* @param {AudioContext} context
* @param {Object} config
* @return {AudioNode} the instrument
* @example
* const cowbell = Cowbell(ac)
* cowbell.trigger(ac.currentTime + 1)
*/
export default function Cowbell (ac, state) {
if (state) state = Object.assign({}, Cowbell.defaultState, state)
else state = Cowbell.defaultState
const cowbell = instrument(ac, {
osc1: [ Osc, "env1" ],
env1: [ GainEnvelope, "filter" ],
osc2: [ Osc, "env2" ],
env2: [ GainEnvelope, "filter" ],
filter: [ Filter, "amp" ],
amp: [ Gain, "output" ]
}).update(state)
cowbell.trigger = (time) => {
cowbell.env1.trigger(time)
cowbell.env2.trigger(time)
}
return cowbell
}