mmpSearch/assets/js/audio/plugins/Kicker.js

45 lines
1.3 KiB
JavaScript

import * as Tone from "https://esm.sh/tone";
export class Kicker {
constructor(toneContext, data = {}) {
this.params = data.kicker || data || {};
// MembraneSynth é perfeito para Kicks e Toms
this.synth = new Tone.MembraneSynth({
pitchDecay: 0.05,
octaves: 6, // O Kicker desce muitas oitavas
oscillator: { type: "sine" },
envelope: {
attack: 0.001,
decay: 0.4,
sustain: 0.01,
release: 1.4
}
});
// Distorção opcional (O Kicker tem um drive)
this.dist = new Tone.Distortion(0.1).toDestination();
this.synth.disconnect();
this.synth.connect(this.dist);
this.output = this.dist;
}
triggerAttackRelease(note, duration, time) {
// O Kicker original geralmente ignora a nota MIDI e usa frequências fixas (Start/End freq)
// Mas para facilitar a composição, vamos permitir que ele toque a nota do Piano Roll
// Se quiser ser fiel ao LMMS, teríamos que ler this.params.start_freq
// Vamos usar a nota C1 ou C2 como base se a nota vier muito aguda
this.synth.triggerAttackRelease(note, duration, time);
}
connect(dest) {
this.output.connect(dest);
}
dispose() {
this.synth.dispose();
this.dist.dispose();
}
}