You are not dreaming: the PHP interface is producing sounds!
Yet not via the console, indeed. I was wondering how to hear a "preview"
of MIDI streams handled by sound-object prototypes. I discovered a
Javascript function "MIDIjs.play" that plays MIDI files:
https://www.midijs.net/
However we did not have MIDI files except when they were imported (using
MIDI Library). We only have time-stamped MIDI codes that Bol Processor
will send to a MIDI player. The MIDI Library does create MIDI files but
not from a sequence of MIDI instructions. It requires a text description
of the MIDI file in a poorly-documented format called "MF2T/T2MF". This
is the output format of its MIDI file to text converter. I could keep it
for imported MIDI files but for all other objects I implemented the
creation of a MF2T/T2MF file from time-stamped MIDI codes.
This was not easy because time-stamped MIDI codes do not contain all the
information required in a well-formed type-1 MIDI file, which is the
format required by the text to MIDIfile converter. A type-1 MIDI file
may contain several tracks, so we guess track changes in time-stamped
MIDI codes when time goes back (generally to 0), and a "NewTrk"
instruction is inserted.
Another problem on which I spent part of the night is to figure out the
tempo. MIDI files have a header that tells the format, number of tracks,
and an obscure parameter called "division" giving "the time resolution
in clicks per quarter note". This looks simple but I needed to figure
out how this parameter will be taken care of so that an imported MIDI
file will be played at exactly the same speed. I got confused with a
variable called "Tref" in Bol Processor, which is the period of the
metronom used to count the number of beats of an object. The problem is
that Tref is actually a number of "ticks" and not a number of
milliseconds. To sort it out we need to know the time-resolution. Since
it was 1 millisecond by default on most sound-objects, I wrongly
asssumed that Tref was in milliseconds.
Finally I found the magic equation:
resolution = division / (0.48 * Tref)
Don't ask me why "0.48"… It works!
If you use the new PHP interface (now on https://leti.lt/bolprocessor/)
you will see a "Play MIDI file" link just below the Csound score of any
object in "-mi.abc1". It works with the "default player" on your system,
so we need to check it on Windows and other platforms.
Then you can try to upload a MIDI file and select a long one to check
that durations remain correct. In the "ctests.zip" folder I added
"Christmas_Carols_-_12_Days_Of_Christmas.mid" that will give you a
14-second delight! One you have heard the song try to modify its duration
Tring to import this multitrack file in BP2.9.8 does not yield a
satisfactory result: most data is ignored or modified. Therefore we
can't rely on BP current methods for importing/exporting MIDI files —
written by Kumar in 1997. The MIDI file format has been upgraded since then.
Normally we won't need to read/write multitrack MIDI files but some
users may not be aware of it and they may try to create a multitrack
sound-object. It will work since the conversion to time-stamped MIDI
bytes is correct. This will add a new "density" to sound-objects! ;-)
This does not really require an update of the checklist because it is a
tentative implementation that forced me to study again MIDI encoding and
the representation of physical time in Bol Processor. Understanding time
resolution, durations, preroll and postroll etc.
Bernard
|