-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
play-1.js: add support for default instrument #21
Comments
Hi,
There are many topics in your message.
MIDI sound font.
I have no MIDI support (nor mp3) in the small set of web browsers that
is available for my ARM machine, but using the html5 MIDI API could be
a good alternative to the MIDI.JS fonts.
Anyway, in all cases, some sound fonts should be downloaded in the
user's computers.
Default instrument.
Your proposal does not solve the general problem.
Actually, the instruments are defined by '%%MIDI program'
parameters. These parameters are voice related: they must be inserted
in the tune body.
My idea is to predefine default instruments per voice outside the ABC
files. For this, only a small extension to the ABC notation is needed:
define the instrument inside the V:/K: definitions.
There were already some proposals to replace the %%MIDI parameter,
especially 'I:timbre' from Alexander Scheutzow
(http://abcnotation.com/wiki/abc:standard:v2.1:proposals:timbres_midi:alexmidicond:v1).
So, I will propose the syntax:
V:<voice name> timbre="timbre name"
to be added to the standard.
Then, you could set a default instrument by adding:
V:* timbre="instrument name"
before parsing the user's ABC files.
Sound font loading failure.
I did not carefully check this yet, but I don't see any easy workaround.
How could a program know if there is any available MIDI font in the
user's computer, and where?
|
Hi, [1] [2] [3] Thanks |
OK, I think I understood:
1- you want that the voices with no defined instrument are played as a
'default' instrument.
2- you want this default instrument to be used when there is no font
for some instrument.
For 1), you could insert a '%%MIDI program' before the ABC file when
parsing the tune.
In edit.js, the sequence would be:
var abc = new Abc(user);
abcplay.clear();
abc.tosvg("play", "%%play");
abc.tosvg("play", "%%MIDI program 40"); // default instrument = violin
abc.tosvg(abc_fname[0],...
...
For 2), if you know which instrument is available or not, you could
change the instruments in the voices.
In edit.js, this would be done in the get_abcmodel callback function:
user.get_abcmodel =
function(tsfirst, voice_tb, music_types, info) {
if (playing) {
// replace the unavailable instruments by the default
for (var i = 0; i < voice_tb.length; i++)
if (!avail_instr[voice_tb[i].instr])
voice_tb[i].instr = default_instr;
abcplay.add(tsfirst, voice_tb)
}
}
|
Looks good. We'll give these a try. In the meantime, if we manage to implement the "dynamic" detection of missing instruments, we will post them as PR. Thx! |
Hi,
We are trying to use the play-1.js script on an desktop app that can be used offline. One of the difficulties we are facing has to do with the dynamic download of audio files for MIDI playback.
For offline support, it means that we would have to increase the download size.
An alternative for this would be to define the concept of a user-defined default instrument.
Currently we are focused on violin, which means that most of the files (since they don't explicitly specify an instrument) end up playing as "acoustic_grand_piano".
Allowing setting the default instrument via something like "set_default_instr" could address this.
Another possible improvement would be to detect failure to load an instrument and, in that case, try to load the default instrument. From our analysis of the code, it seems that this could be easier with the 'mp3' mode, as it already has support for "onerror". This would also mean that we would have to pack fewer instruments while still being able to deal with user-defined files.
We can try to add some of this, but we fear our javascript skills are not yet on the required level to deal with play-1.js :)
Anyway, it would be great if you could give some input on this.
Thanks!
The text was updated successfully, but these errors were encountered: