soundfont-player icon indicating copy to clipboard operation
soundfont-player copied to clipboard

note list in MIDI note numbers not working

Open hmoffatt opened this issue 8 years ago • 8 comments

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) {

hmoffatt avatar Jun 30 '16 02:06 hmoffatt

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.

cpansprout avatar Oct 12 '16 21:10 cpansprout

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

danigb avatar Oct 13 '16 13:10 danigb

If adding the feature would complicate things (adding bloat to avoid bloat :-), then I can live without it.

cpansprout avatar Oct 15 '16 20:10 cpansprout

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 onlyoption 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?

danigb avatar Oct 16 '16 09:10 danigb

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.

hmoffatt avatar Oct 16 '16 23:10 hmoffatt

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’).

cpansprout avatar Oct 17 '16 05:10 cpansprout

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:

  1. enharmonics (how do you know if it's Db or C#)
  2. 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.

danigb avatar Oct 17 '16 07:10 danigb

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.

hmoffatt avatar Oct 17 '16 22:10 hmoffatt