abcjs
abcjs copied to clipboard
Dinamicaly change soundFontUrl
Hello @paulrosen , hope you're doing well
I come back with a small issues. I try to allow the users to select one from different soundFontUrl I provide. The idea is that he selects the desired sound font in a select, then I completely recreate the synthcontroller with the new soundfont
if (this.synthController) {
this.synthController.destroy()
delete this.synthController
}
// .... recreating the synthController
var soundfont = ['Reggae', 'Pop-Rock', 'Hard-Rock'][Math.floor(Math.random()*3)]
this.synthController.setTune(this.visualObj, false, {
drum: this.isMetronomeActive() ? metronome_struct.trim() : "",
soundFontUrl: '/sounds/' + soundfont + '/',
sequenceCallback: (tracks) => {
this.sequenceCallback(tracks)
},
}).then(() => {
this.synthController.toggleLoop()
console.log("Audio successfully loaded.")
}).catch(function (error) {
console.warn("Audio problem:", error);
});
The first time the synthController is created, it's working fine, but once I change the value or the variable soundFont, it stays on the first loaded soundFont.
Any idea of what's goin on ? Thank you!
Are you doing this.synthController = new ABCJS.synth.SynthController() as part of recreating? Other than that, I'd have to see your site to debug.
Hi, yes of course, here my code called when I update the sound font variable. (When console.log, it shows me the right selected sound fond)
My guess is: once played, the sound readed in mp3 is cached or something.
Because, if I put just one note, playing, then changing the sound_font, then adding an other note (so another sound), it's loading the other note when the correct sound. But the first added note keeps the old sound font. So maybe it's related to that?
Btw I'm using v6.1.2, so idk if there is another version patching that,
Thanks!
renderMidi() {
if (this.synthController) {
this.synthController.destroy()
}
this.synthController = new abcjs.synth.SynthController();
this.synthController.load(this.$refs.midi_render,
new CursorControl(),
this.player_options
);
this.adjustPitch();
console.log(this.sound_font)
this.synthController.setTune(this.abc_core.visualObj, false, {
drum: this.generateMetronomeForSynthController(),
soundFontUrl: '/sounds/' + this.sound_font + '/',
sequenceCallback: (tracks) => {
this.sequenceCallback(tracks)
},
}).then(() => {
// By default, we activate the loop of the player
this.synthController.toggleLoop()
}).catch(function (error) {
console.warn("Audio problem:", error);
});
},
I see the problem - yes, it is related to caching. Once the note is loaded I don't bother getting it again. This will be fixed in the next version. Sorry.