Err StartInstrument( Item Instrument, TagArg *TagList )
*TagList
to NULL. (You do not, for example, need to supply frequency and amplitude settings for mixers, submixers, and other instruments that do no play notes).
When StartInstrument()
executes, it starts the specified instrument, a process that, for DSP instruments, makes it an active instrument. In other words, StartInstrument()
runs the instrument on the DSP. Before an instrument is started, it does not run on the DSP and does not take up DSP cycles.
StartInstrument()
returns 0 if successful, or a negative value (an error code) if unsuccessful.
The effect of starting an instrument is different from instrument to instrument. It depends on what the instrument does once it is running. For instruments that do no play notes, such as mixers and effects instruments, starting the instrument simply runs it on the DSP so you can use it to act on other instruments (think of it as switching the instrument on). For note playing instruments such as sampled sound instruments and sound synthesis instruments, starting the instrument turns it on and starts whatever note the instrument is set up to play.
If an instrument stops, all of its attachments also stop playing. The instrument then uses no more DSP cycles. When an attachment to an instrument stops playback, the instrument itself keeps going (unless, of course, the attachment was defined as a stop-linked attachment). While the instrument runs, it uses DSP cycles.
If an instrument is restarted before it has stopped, its playback starts from the beginning once again. When an instrument restarts, the Audio folio stops it very quickly and then starts it again.
StartInstrument()
without tag arguments, the instrument plays using whatever frequency and amplitude are initially set for the instrument. That frequency and amplitude may have been set by a tweaked knob, or, if the knobs have not been touched, the default frequency and amplitude for the instrument. Or the instrument may not have variable amplitude or variable frequency (directout.dsp
, for example).
To start an instrument and specify that it play at a given frequency or
amplitude, you can tweak the instrument's frequency or amplitude knob to
the frequency or amplitude you want. An easier method is to use the tag
arguments supported by StartInstrument()
, which tweak the
frequency or amplitude knob for you without a TweakKnob()
call.
The three tag arguments listed in Table 1 set frequency.
Table 1: tag arguments that set frequency. --------------------------------------------------------- Tag Name |Descrption --------------------------------------------------------- AF_TAG_PITCH |A MIDI pitch value from 0 to 127 that |specifies the appropriate frequency |set by the instrument's tuning. |Default tuning is 12-tone |equal-tempered tuning with 60 set to |middle C. --------------------------------------------------------- AF_TAG_FREQUENCY |A direct frequency value, measured in |Hertz andexpressed in 16.16 format. Do |not use with sampled sounds in Opera |Portfolio. Use AF_TAG_RATE instead. --------------------------------------------------------- AF_TAG_RATE |A rate value, in raw units, that |determines frequency. Raw values are |instrument dependent, and are |described in Preparing Instruments. in |the description of TweakRawKnob(). ---------------------------------------------------------
For a detailed description of how to use AF_TAG_RATE to play samples recorded at various sample rates, see Playback Rate.
The tag arguments shown in Table 2 set amplitude. shows the other tag argument that can be used with StartInstrument()
.
Table 2: Tag arguments that set amplitude. ------------------------------------------------------- Tag Name |Description ------------------------------------------------------- AF_TAG_VELOCITY |A MIDI velocity value from 0 to 127 |that specifies relative amplitude. 0 |is no amplitude, 127 is maximum |amplitude, and 64 is "normal" |amplitudeor at least "median" |amplitude. ------------------------------------------------------- AF_TAG_AMPLITUDE|An amplitude value ranging from 0x0 |(no amplitude) to 0x7FFF (full |amplitude). -------------------------------------------------------
Table 3: Other Instrument tag arguments. ----------------------------------------------------- Tag Name |Description ----------------------------------------------------- AF_TAG_TIME_SCALE |Scale times for all Envelopes |attached to this Instrument. |Original value is derived from |the AF_TAG_TIME_SCALE provided |when the Envelope Attachment |was made. This value remains in |effect until another |AF_TAG_TIME_SCALE is passed to |StartInstrument() or |ReleaseInstrument(). -----------------------------------------------------
Whenever you use these tag arguments in StartInstrument()
, they have the same effect as tweaking either the frequency or amplitude knob of the specified instrument. If an instrument does not have a frequency knob, then frequency tag arguments have no effect. If an instrument does not have an amplitude knob, then amplitude tag arguments have no effect. And if an instrument has a frequency or amplitude knob but has another instrument (such as envelope.dsp
) connected to it, the knob is not available, so the tag arguments do not affect it.
Err ReleaseInstrument( Item Instrument, TagArg *TagList )
When ReleaseInstrument()
executes, it releases the specified instrument. It returns 0 if successful, or a negative value (an error code) if unsuccessful.
Releasing an instrument that is not playing a sustain loop (either on its own or through an attachment) has no effect at all on the item. Nor, for that matter, does it have any effect on instruments that do not play notes, such as mixers.
Err StopInstrument( Item Instrument, TagArg *TagList )
StopInstrument()
stops the specified instrument. It returns 0 if successful, or a negative value (an error code) if unsuccessful.Stopping an instrument stops playback of all attachments to that instrument. Stopping a note playing instrument in full voice can result in a click. It is wise to apply an amplitude envelope that tapers to nothing or to turn down the amplitude completely before stopping a note playing instrument.
Err DeleteInstrument( Item Instrument )
Note: If you created an instrument with the LoadInstrument()
call, do not use FreeInstrument()
to delete it. If you do, the instrument is deleted and its template is still there with no way to get rid of it. Use UnloadInstrument()
instead.
Err UnloadInsTemplate( Item InsTemplateItem )
When you delete an instrument template, any instruments created with that palette are also deleted. Be certain that you do not delete an instrument template when you have associated instruments still in use.
Deleting an Instrument and Its Template
If you created an instrument and loaded an instrument template using the
LoadInsTemplate()
call, you should delete that instrument and its template (when finished with them) with the following call:
Err UnloadInstrument( Item InstrumentItem )
Note: Do not use this call to delete an instrument that is one of many instruments created with one instrument template. The call deletes the template when it deletes the instrument and all the other instruments associated with that template are deleted at the same time, whether you intended to delete them or not.
Err CloseAudioFolio( void )
CloseAudioFolio()
executes, it disconnects the task from the Audio folio.