Derived from: (none)
Declared in: be/midi/Synth.h
Library: libmidi.so
The BeOS includes a General MIDI software synthsizer designed by HeadSpace <etc.> The BSynth class is the interface to the synthesizer itself. Any application that wants to use the synthesizer must include a BSynth object; however, most applications won't need to create the object directly:
For "lightweight" use of the synthesizer--if you just want to play a MIDI file (for example) but don't need to fiddle with the synthesizer's virtual knobs and buttons--you can ignore BSynth and move on to the BMidiSynth, BMidiSynthFile, and BSamples classes. These classes create a BSynth for you. |
BSynth(void) BSynth(synth_mode mode)
Creates a new BSynth object and sets be_synth (the application-wide BSynth pointer) to point to it. The BSynth that be_synth previously pointed to (if any) is deleted. You should follow the constructor with a call to LoadSynthData() to initialize the synthesizer.
The default constructor tries to locate and load the "big" synthesizer. Failing that, it looks for the "little" synthesizer; if it can find neither, the default constructor fails (it doesn't initialize for "samples only").
The synth_mode constructor let's you specify the synthesizer's initialization. Of the six synth_mode constants, four are useful as mode arguments:
You can only construct one BSynth object per application. Every application that wants to use the synthesizer must have its own BSynth--you can't "share" another application's be_synth object.
~BSynth()
The destructor stops the synthesizer if it's currently playing anything, frees all synthesis-related storage that the BSynth object allocated, and sets be_synth to point to NULL.
status_t LoadSynthData(synth_mode mode = B_DEFAULT_SYNTH) status_t LoadSynthData(entry_ref *instrument_file) status_t Uninit(void) synth_mode SynthMode(void)
After you've constructed a BSynth object, you have to initialize the synthesizer by telling it which "instrument" file to load. The instrument file contains descriptions of individual General MIDI instruments. The BSynth object loads the file by copying the entire contents into virtual memory. As individual instruments are needed during a performance, they're locked into RAM. (You can force an instrument to be locked into RAM through BMidiSynth::LoadInstrument().)
Be supplies two instrument files:
There are two ways to load an instrument file:
Here we describe the do-it-yourself method; see the other classes for details of automatic loading.
LoadSynthData() can be called with a synth_mode constant, or an entry_ref:
The synth_mode constants are:
If the synthesizer is initialized with an instrument file, it will automatically know how to play BSample data. |
The big instruments sound better than the small instruments, but they occupy four times more memory.
Any changes to the instrument file that are made after the file is loaded won't be seen by the synthesizer unless you re-load.
The constructors of the other MIDI synthesis classes will call LoadSynthData() automatically if the synthesizer hasn't already been initialized:
These constructor initializations are skipped if the synthesizer is already adequately initialized--they never "downgrade" the synthesizer. See the individual classes for details.
Unload() stops the synthesizer (if it's currently playing), clears the instruments that were loaded into RAM (through the LoadInstruments() function), forgets the instrument file that was used to initialize the synthesizer, and steps out of the audio output mechanism. After you call Unload(), the be_synth object is good for nothing until you re-initialize.
You can re-initialize the synthesizer on the fly without calling Unload() first. In other words, successive LoadSynthData() calls don't require interleaved Unload()s. However, re-initializing while the synthesizer is playing will abort the current MIDI synthesis. BSample output shouldn't be affected (depending on the load on your computer).
SynthMode() returns a synth_mode constant that descibes the synthesizer's current initialization state:
status_t LockInstrument(uint16 number) status_t LockInstrument(midi_axe instrument) status_t UnlockInstrument(uint16 number) status_t UnlockInstrument(midi_axe instrument) status_t FlushInstruments(void)
Normally, instrument data is paged in and out of RAM as needed. If you know which instruments you'll be using, you can tell the synthesizer to lock the instruments into RAM (and do it now!). Locked instruments won't be paged out; when the instrument is unlocked, its data is paged out through the normal course of events.
The LockInstrument() and UnlockInstrument() functions let you designate the target instrument either as a General MIDI instrument number (1 through 128) or as one of the midi_axe constants. See <x> for the complete list of instruments.
Keep in mind that the General MIDI numbers used here correspond to the numbers given in the General MIDI specification. In other words, these numbers start with instrument number 1 (not 0).
The LockInstrument() and UnlockInstrument() return codes are:
FlushInstruments() removes all instruments, locked or not, that are currently in RAM. The instruments aren't thrown away--they'll still reside in virtual memory. Flushing doesn't affect BSample playback (which doesn't rely on instruments).
FlushInstruments() returns:
The Be Book, in lovely HTML, for BeOS Release 4.
Copyright © 1998 Be, Inc. All rights reserved.
Last modified December 23, 1998.