Home Information Classes Download Usage Mail List Requirements Links FAQ Tutorial

Public Member Functions | List of all members
stk::Voicer Class Reference

STK voice manager class. More...

`#include <Voicer.h>`

Inheritance diagram for stk::Voicer:

## 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.
Public Member Functions inherited from stk::Stk
void | ignoreSampleRateChange (bool ignore=true)
| A function to enable/disable the automatic updating of class data when the STK sample rate changes.

## Additional Inherited Members
Static Public Member Functions inherited from stk::Stk
static StkFloat | sampleRate (void)
| Static method that returns the current STK sample rate.
static void | setSampleRate (StkFloat rate)
| Static method that sets the STK sample rate.
static void | clear_alertList ()
| Static method that frees memory from alertList_.
static std::string | rawwavePath (void)
| Static method that returns the current rawwave path.
static void | setRawwavePath (std::string path)
| Static method that sets the STK rawwave path.
static void | swap16 (unsigned char *ptr)
| Static method that byte-swaps a 16-bit data type.
static void | swap32 (unsigned char *ptr)
| Static method that byte-swaps a 32-bit data type.
static void | swap64 (unsigned char *ptr)
| Static method that byte-swaps a 64-bit data type.
static void | sleep (unsigned long milliseconds)
| Static cross-platform method to sleep for a number of milliseconds.
static bool | inRange (StkFloat value, StkFloat min, StkFloat max)
| Static method to check whether a value is within a specified range.
static void | handleError (const char *message, StkError::Type type)
| Static function for error reporting and handling using c-strings.
static void | handleError (std::string message, StkError::Type type)
| Static function for error reporting and handling using c++ strings.
static void | showWarnings (bool status)
| Toggle display of WARNING and STATUS messages.
static void | printErrors (bool status)
| Toggle display of error messages before throwing exceptions.
Static Public Attributes inherited from stk::Stk
static const StkFormat | STK_SINT8
static const StkFormat | STK_SINT16
static const StkFormat | STK_SINT24
static const StkFormat | STK_SINT32
static const StkFormat | STK_FLOAT32
static const StkFormat | STK_FLOAT64
Protected Member Functions inherited from stk::Stk
| Stk (void)
| Default constructor.
virtual | ~Stk (void)
| Class destructor.
virtual void | sampleRateChanged (StkFloat newRate, StkFloat oldRate)
| This function should be implemented in subclasses that depend on the sample rate.
void | addSampleRateAlert (Stk *ptr)
| Add class pointer to list for sample rate change notification.
void | removeSampleRateAlert (Stk *ptr)
| Remove class pointer from list for sample rate change notification.
void | handleError (StkError::Type type) const
| Internal function for error reporting that assumes message in `oStream_` variable.

## 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–2023.

## Member Function Documentation

## ◆ addInstrument()

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.

## ◆ removeInstrument()

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!!

## ◆ noteOn()

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.

## ◆ noteOff() [1/2]

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.

## ◆ noteOff() [2/2]

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.

## ◆ setFrequency() [1/2]

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.

## ◆ setFrequency() [2/2]

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.

## ◆ lastOut()

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()

166{
167#if defined(_STK_DEBUG_)
168 if ( channel >= lastFrame_.channels() ) {
169 oStream_ << "Voicer::lastOut(): channel argument is invalid!";
170 handleError( StkError::FUNCTION_ARGUMENT );
171 }
172#endif
173
174 return lastFrame_[channel];
175}
stk::StkFrames::channels
unsigned int channels(void) const
Return the number of channels represented by the data.
Definition Stk.h:416
stk::Stk::handleError
static void handleError(const char *message, StkError::Type type)
Static function for error reporting and handling using c-strings.

## ◆ tick() [1/2]

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.

179{
180 unsigned int j;
181 for ( j=0; j<lastFrame_.channels(); j++ ) lastFrame_[j] = 0.0;
182 for ( unsigned int i=0; i<voices_.size(); i++ ) {
183 if ( voices_[i].sounding != 0 ) {
184 voices_[i].instrument->tick();
185 for ( j=0; j<voices_[i].instrument->channelsOut(); j++ ) lastFrame_[j] += voices_[i].instrument->lastOut( j );
186 }
187 if ( voices_[i].sounding < 0 )
188 voices_[i].sounding++;
189 if ( voices_[i].sounding == 0 )
190 voices_[i].noteNumber = -1;
191 }
192
193 return lastFrame_[channel];
194}

## ◆ tick() [2/2]

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).

197{
198 unsigned int nChannels = lastFrame_.channels();
199#if defined(_STK_DEBUG_)
200 if ( channel > frames.channels() - nChannels ) {
201 oStream_ << "Voicer::tick(): channel and StkFrames arguments are incompatible!";
202 handleError( StkError::FUNCTION_ARGUMENT );
203 }
204#endif
205
206 StkFloat *samples = &frames[channel];
207 unsigned int j, hop = frames.channels() - nChannels;
208 for ( unsigned int i=0; i<frames.frames(); i++, samples += hop ) {
209 tick();
210 for ( j=0; j<nChannels; j++ )
211 *samples++ = lastFrame_[j];
212 }
213
214 return frames;
215}
stk::Voicer::tick
StkFloat tick(unsigned int channel=0)
Mix one sample frame of all sounding voices and return the specified channel value.
Definition Voicer.h:178

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

- Voicer.h

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