The Synthesis ToolKit in C++ (STK)

Home Information Classes Download Usage Mail List Requirements Links FAQ Tutorial

# stk::Voicer Class Reference

STK voice manager class. More...

`#include <Voicer.h>`

Inheritance diagram for stk::Voicer:

List of all members.

## Public Member Functions
| Voicer (StkFloat decayTime=0.2)
| Class constructor taking an optional note decay time (in seconds).
void | addInstrument (Instrmnt *instrument, int group=0)
| Add an instrument with an optional group number to the voice manager.
void | removeInstrument (Instrmnt *instrument)
| Remove the given instrument pointer from the voice manager's control.
long | noteOn (StkFloat noteNumber, StkFloat amplitude, int group=0)
| Initiate a noteOn event with the given note number and amplitude and return a unique note tag.
void | noteOff (StkFloat noteNumber, StkFloat amplitude, int group=0)
| Send a noteOff to all voices having the given noteNumber and optional group (default group = 0).
void | noteOff (long tag, StkFloat amplitude)
| Send a noteOff to the voice with the given note tag.
void | setFrequency (StkFloat noteNumber, int group=0)
| Send a frequency update message to all voices assigned to the optional group argument (default group = 0).
void | setFrequency (long tag, StkFloat noteNumber)
| Send a frequency update message to the voice with the given note tag.
void | pitchBend (StkFloat value, int group=0)
| Send a pitchBend message to all voices assigned to the optional group argument (default group = 0).
void | pitchBend (long tag, StkFloat value)
| Send a pitchBend message to the voice with the given note tag.
void | controlChange (int number, StkFloat value, int group=0)
| Send a controlChange to all instruments assigned to the optional group argument (default group = 0).
void | controlChange (long tag, int number, StkFloat value)
| Send a controlChange to the voice with the given note tag.
void | silence (void)
| Send a noteOff message to all existing voices.
unsigned int | channelsOut (void) const
| Return the current number of output channels.
const StkFrames & | lastFrame (void) const
| Return an StkFrames reference to the last output sample frame.
StkFloat | lastOut (unsigned int channel=0)
| Return the specified channel value of the last computed frame.
StkFloat | tick (unsigned int channel=0)
| Mix one sample frame of all sounding voices and return the specified `channel` value.
StkFrames & | tick (StkFrames &frames, unsigned int channel=0)
| Fill the StkFrames argument with computed frames and return the same reference.

## Detailed Description

STK voice manager class.

This class can be used to manage a group of STK instrument classes. Individual voices can be controlled via unique note tags. Instrument groups can be controlled by group number.

A previously constructed STK instrument class is linked with a voice manager using the addInstrument() function. An optional group number argument can be specified to the addInstrument() function as well (default group = 0). The voice manager does not delete any instrument instances ... it is the responsibility of the user to allocate and deallocate all instruments.

The tick() function returns the mix of all sounding voices. Each noteOn returns a unique tag (credits to the NeXT MusicKit), so you can send control changes to specific voices within an ensemble. Alternately, control changes can be sent to all voices in a given group.

by Perry R. Cook and Gary P. Scavone, 1995-2012.

## Member Function Documentation

void stk::Voicer::addInstrument | ( | Instrmnt * | instrument,
|  | int | group = `0` |
| ) |  |  |

Add an instrument with an optional group number to the voice manager.

A set of instruments can be grouped by group number and controlled via the functions that take a group number argument.

void stk::Voicer::removeInstrument | ( | Instrmnt * | instrument | ) |

Remove the given instrument pointer from the voice manager's control.

It is important that any instruments which are to be deleted by the user while the voice manager is running be first removed from the manager's control via this function!!

long stk::Voicer::noteOn | ( | StkFloat | noteNumber,
|  | StkFloat | amplitude,
|  | int | group = `0` |
| ) |  |  |

Initiate a noteOn event with the given note number and amplitude and return a unique note tag.

Send the noteOn message to the first available unused voice. If all voices are sounding, the oldest voice is interrupted and sent the noteOn message. If the optional group argument is non-zero, only voices in that group are used. If no voices are found for a specified non-zero group value, the function returns -1. The amplitude value should be in the range 0.0 - 128.0.

void stk::Voicer::noteOff | ( | StkFloat | noteNumber,
|  | StkFloat | amplitude,
|  | int | group = `0` |
| ) |  |  |

Send a noteOff to all voices having the given noteNumber and optional group (default group = 0).

The amplitude value should be in the range 0.0 - 128.0.

void stk::Voicer::noteOff | ( | long | tag,
|  | StkFloat | amplitude |
| ) |  |  |

Send a noteOff to the voice with the given note tag.

The amplitude value should be in the range 0.0 - 128.0.

void stk::Voicer::setFrequency | ( | StkFloat | noteNumber,
|  | int | group = `0` |
| ) |  |  |

Send a frequency update message to all voices assigned to the optional group argument (default group = 0).

The noteNumber argument corresponds to a MIDI note number, though it is a floating-point value and can range beyond the normal 0-127 range.

void stk::Voicer::setFrequency | ( | long | tag,
|  | StkFloat | noteNumber |
| ) |  |  |

Send a frequency update message to the voice with the given note tag.

The noteNumber argument corresponds to a MIDI note number, though it is a floating-point value and can range beyond the normal 0-127 range.

StkFloat stk::Voicer::lastOut | ( | unsigned int | channel = `0` | ) | `[inline]`

Return the specified channel value of the last computed frame.

The `channel` argument must be less than the number of output channels, which can be determined with the channelsOut() function (the first channel is specified by 0). However, range checking is only performed if _STK_DEBUG_ is defined during compilation, in which case an out-of-range value will trigger an StkError exception.

See also:
  lastFrame()

    00166 {
    00167 #if defined(_STK_DEBUG_)
    00168   if ( channel >= lastFrame_.channels() ) {
    00169     oStream_ << "Voicer::lastOut(): channel argument is invalid!";
    00170     handleError( StkError::FUNCTION_ARGUMENT );
    00171   }
    00172 #endif
    00173
    00174   return lastFrame_[channel];
    00175 }

StkFloat stk::Voicer::tick | ( | unsigned int | channel = `0` | ) | `[inline]`

Mix one sample frame of all sounding voices and return the specified `channel` value.

The `channel` argument must be less than the number of output channels, which can be determined with the channelsOut() function (the first channel is specified by 0). However, range checking is only performed if _STK_DEBUG_ is defined during compilation, in which case an out-of-range value will trigger an StkError exception.

    00179 {
    00180   unsigned int j;
    00181   for ( j=0; j<lastFrame_.channels(); j++ ) lastFrame_[j] = 0.0;
    00182   for ( unsigned int i=0; i<voices_.size(); i++ ) {
    00183     if ( voices_[i].sounding != 0 ) {
    00184       voices_[i].instrument->tick();
    00185       for ( j=0; j<voices_[i].instrument->channelsOut(); j++ ) lastFrame_[j] += voices_[i].instrument->lastOut( j );
    00186     }
    00187     if ( voices_[i].sounding < 0 )
    00188       voices_[i].sounding++;
    00189     if ( voices_[i].sounding == 0 )
    00190       voices_[i].noteNumber = -1;
    00191   }
    00192
    00193   return lastFrame_[channel];
    00194 }

StkFrames & stk::Voicer::tick | ( | StkFrames & | frames,
|  | unsigned int | channel = `0` |
| ) |  |  | `[inline]`

Fill the StkFrames argument with computed frames and return the same reference.

The number of channels in the StkFrames argument must equal the number of channels in the file data. However, this is only checked if _STK_DEBUG_ is defined during compilation, in which case an incompatibility will trigger an StkError exception. If no file data is loaded, the function does nothing (a warning will be issued if _STK_DEBUG_ is defined during compilation).

    00197 {
    00198   unsigned int nChannels = lastFrame_.channels();
    00199 #if defined(_STK_DEBUG_)
    00200   if ( channel > frames.channels() - nChannels ) {
    00201     oStream_ << "Voicer::tick(): channel and StkFrames arguments are incompatible!";
    00202     handleError( StkError::FUNCTION_ARGUMENT );
    00203   }
    00204 #endif
    00205
    00206   StkFloat *samples = &frames[channel];
    00207   unsigned int j, hop = frames.channels() - nChannels;
    00208   for ( unsigned int i=0; i<frames.frames(); i++, samples += hop ) {
    00209     tick();
    00210     for ( j=0; j<nChannels; j++ )
    00211       *samples++ = lastFrame_[j];
    00212   }
    00213
    00214   return frames;
    00215 }

The documentation for this class was generated from the following file:

- Voicer.h

The Synthesis ToolKit in C++ (STK)
©1995-2012 Perry R. Cook and Gary P. Scavone. All Rights Reserved.