2019-08-27 18:18:38 +01:00
|
|
|
import('./pkg')
|
2018-09-28 13:54:29 -07:00
|
|
|
.then(rust_module => {
|
|
|
|
let fm = null;
|
2018-09-10 17:50:34 -07:00
|
|
|
|
2018-09-28 13:54:29 -07:00
|
|
|
const play_button = document.getElementById("play");
|
|
|
|
play_button.addEventListener("click", event => {
|
|
|
|
if (fm === null) {
|
|
|
|
fm = new rust_module.FmOsc();
|
|
|
|
fm.set_note(50);
|
|
|
|
fm.set_fm_frequency(0);
|
|
|
|
fm.set_fm_amount(0);
|
|
|
|
fm.set_gain(0.8);
|
|
|
|
} else {
|
|
|
|
fm.free();
|
|
|
|
fm = null;
|
|
|
|
}
|
|
|
|
});
|
2018-09-10 17:50:34 -07:00
|
|
|
|
2018-09-28 13:54:29 -07:00
|
|
|
const primary_slider = document.getElementById("primary_input");
|
|
|
|
primary_slider.addEventListener("input", event => {
|
|
|
|
if (fm) {
|
2019-01-28 23:54:40 -05:00
|
|
|
fm.set_note(parseInt(event.target.value));
|
2018-09-28 13:54:29 -07:00
|
|
|
}
|
|
|
|
});
|
2018-09-10 17:50:34 -07:00
|
|
|
|
2018-09-28 13:54:29 -07:00
|
|
|
const fm_freq = document.getElementById("fm_freq");
|
|
|
|
fm_freq.addEventListener("input", event => {
|
|
|
|
if (fm) {
|
2019-01-28 23:54:40 -05:00
|
|
|
fm.set_fm_frequency(parseFloat(event.target.value));
|
2018-09-28 13:54:29 -07:00
|
|
|
}
|
|
|
|
});
|
2018-09-10 17:50:34 -07:00
|
|
|
|
2018-09-28 13:54:29 -07:00
|
|
|
const fm_amount = document.getElementById("fm_amount");
|
|
|
|
fm_amount.addEventListener("input", event => {
|
|
|
|
if (fm) {
|
2019-01-28 23:54:40 -05:00
|
|
|
fm.set_fm_amount(parseFloat(event.target.value));
|
2018-09-28 13:54:29 -07:00
|
|
|
}
|
|
|
|
});
|
|
|
|
})
|
|
|
|
.catch(console.error);
|