soundfont-player
soundfont-player copied to clipboard
note list in MIDI note numbers not working
The comments for Soundfont.instrument() imply that you can supply a notes list to load in the options, using MIDI note numbers. However if you do that nothing is loaded.
I don't see any code which would map the note numbers to names before handing them to the audio-loader.
My test case is:
Soundfont.instrument(ac, 'marimba', { destination: vca, notes: [70, 72] }).then(function (marimba) {
It does not just imply that you can supply MIDI note numbers, it says so explicitly. I have run into the same problem myself. It would be very convenient if I could just list the numbers instead of converting them in my code to note names.
Hi,
first of all, sorry @hmoffatt for not addressing this before. Obviously, the documentation is wrong, and it's the first thing to be fixed.
Second, the parameter to load only a selected number of notes is called only
:
Soundfont.instrument(ac, 'marimba', { only: ['C4', 'C#4', ... ]})
And third: this is a performance option only, just to avoid some costing computation of decoding the audio, mostly on mobile devices (an edge case).
With the feature you are asking for, the library that loads the audio (https://github.com/danigb/audio-loader) would require to convert the loaded audio names to midi before decoding, then comparing with the numbers supplied and the discard the not required audio. That means add a dependency to the library (to convert note names to midi) and complexity for a small use case that is seeking for performance (and more code will mean less performance...)
So, If I understood the issue correctly, with this considerations I would prefer not to implement that feature. But I'm open to other views. Any thoughts?
Saludos
If adding the feature would complicate things (adding bloat to avoid bloat :-), then I can live without it.
Hi @cpansprout
Looking at this issue and the other one you've created (#38) I'm wondering how are you using Soundfont
interface. For example, the only
option we are discussing in this issue is only required if you work in mobile environments and performance is a problem. If it's not your case, you don't need to specify the notes to be loaded. I'm starting to suspect you are using it even if it's not needed. Can you describe your process, please?
I agree it's an optimisation for performance on mobile. I think it's still useful if you know you just need a few notes from the sound font (probably from a drum kit sound font mostly). Converting MIDI note numbers to note names appears to be pretty trivial and could be done without another dependency, but could just as easily be done by the caller.
So I think it's reasonable just to fix the documentation and close this issue.
I was wondering whether #38 was related to memory usage, which was why I tried the ‘notes’ option (your code appears to work with both ‘notes’ and ‘only’).
Hi @hmoffatt, thanks for joining the conversation after so much time. At first, I thought that converting from midi to names were not a trivial task because:
- enharmonics (how do you know if it's Db or C#)
- Correct spelling: because strings are compared, it's not the same "c#2" than "C#2"
But since I know (at least for the gleitz soundfonts) how the note names are provided, maybe I can add this feature.
I agree @danigb it's not trivial in general but is easier for the gleitz soundfonts (or anything generated with his soundfont_builder.rb) because of the known pattern of the note names. I suspect most js-formatted fonts have been generated for MIDI.js which would expect the fonts to be in this format.