In certain circumstances, a single
BMidiSynthFile
object can load and play more than one MIDI file at the same time, but you
shouldn't rely on this feature.
The BMidiSynthFile
class reads a standard MIDI file and plays it on the
General MIDI synthesizer. Each
BMidiSynthFile
object can read (and play) only one file at a time. To use a
BMidiSynthFile
,
you create the object, load a MIDI file, and tell the object to
Start()
:
/* Create and initialize a BMidiSynthFile. */BMidiSynthFile
midiSynthFile
; entry_ref midiRef;get_ref_for_path
("/boot/optional/midi/QuickBrownFox.mid", &midiRef
);midiSynthFile
.LoadFile
(&midiRef
); /* Play the file. */midiSynthFile
.Start
();
You should create a different
BMidiSynthFile
object for each MIDI file that you want to mix together into a single performance.
In certain circumstances, a single
BMidiSynthFile
object can load and play more than one MIDI file at the same time, but you
shouldn't rely on this feature.
When you call
LoadFile()
,
the BMidiSynthFile
object automatically calls…
EnableInput
(true
,false
)
It then loads the file's MIDI data into the synthesizer, which loads all the instruments that are needed by the file. If the file uses a lot of different instruments, loading the file can take some time.
When the file is finished playing (either because it's reached the end,
or because you called
Stop()
)
the instruments are not unloaded. This cuts the overhead if you play the file a second time.
BMidiSynthFile
is different from other
Start()
-able
BMidi
objects in that
it doesn't have a run loop. The MIDI data is parsed and realized in the
synthesizer's subscriber thread (the thread that dumps data into the DAC
stream). The lack of a run loop shouldn't affect the way you write your
code, but you should be aware that the thread isn't there so you won't go
looking for it while you're developing your app
Furthermore,
BMidiSynthFile
doesn't implement the
Run()
function.
Starting and stopping the object's performance (activities that are
normally handled in the Run() function) are handled by the synthesizer in
its subscriber thread. If you create a
BMidiSynthFile
subclass, don't try to resurrect the
Run()
function—leave it as a no-op.
As with the
BMidiSynth
class, the
BMidiSynthFile
MIDI hook implementations don't call the spray functions. This means that you
can't, for example, connect a
BMidiSynthFile
to a
BMidiPort
.
If you want to play a MIDI file out a MIDI port, use
BMidiStore
to represent and play the file.