Arduino STK 4.6.2
Instrmnt.h
1#ifndef STK_INSTRMNT_H
2#define STK_INSTRMNT_H
3
4#include "Stk.h"
5
6namespace stk {
7
8/***************************************************/
17/***************************************************/
18
19class Instrmnt : public Stk
20{
21 public:
23 Instrmnt( void ) { lastFrame_.resize( 1, 1, 0.0 ); };
24
26
29 virtual void clear( void ) {};
30
32 virtual void noteOn( StkFloat frequency, StkFloat amplitude ) = 0;
33
35 virtual void noteOff( StkFloat amplitude ) = 0;
36
38 virtual void setFrequency( StkFloat frequency );
39
41 virtual void controlChange(int number, StkFloat value);
42
44 unsigned int channelsOut( void ) const { return lastFrame_.channels(); };
45
47 const StkFrames& lastFrame( void ) const { return lastFrame_; };
48
50
58 StkFloat lastOut( unsigned int channel = 0 );
59
61
64 virtual StkFloat tick( unsigned int channel = 0 ) = 0;
65
67
75 virtual StkFrames& tick( StkFrames& frames, unsigned int channel = 0 ) {
76 unsigned int nChannels = lastFrame_.channels();
77#if defined(_STK_DEBUG_)
78 if ( channel > frames.channels() - nChannels ) {
79 oStream_ << "Mandolin::tick(): channel and StkFrames arguments are incompatible!";
80 handleError( StkError::FUNCTION_ARGUMENT );
81 }
82#endif
83
84 StkFloat *samples = &frames[channel];
85 unsigned int j, hop = frames.channels() - nChannels;
86 if ( nChannels == 1 ) {
87 for ( unsigned int i=0; i<frames.frames(); i++, samples += hop )
88 *samples++ = tick();
89 }
90 else {
91 for ( unsigned int i=0; i<frames.frames(); i++, samples += hop ) {
92 *samples++ = tick();
93 for ( j=1; j<nChannels; j++ )
94 *samples++ = lastFrame_[j];
95 }
96 }
97
98 return frames;
99}
100
101
102 protected:
103
104 StkFrames lastFrame_;
105
106};
107
108inline void Instrmnt :: setFrequency( StkFloat frequency )
109{
110 oStream_ << "Instrmnt::setFrequency: virtual setFrequency function call!";
111 handleError( StkError::WARNING );
112}
113
114inline StkFloat Instrmnt :: lastOut( unsigned int channel )
115{
116#if defined(_STK_DEBUG_)
117 if ( channel >= lastFrame_.channels() ) {
118 oStream_ << "Instrmnt::lastOut(): channel argument is invalid!";
119 handleError( StkError::FUNCTION_ARGUMENT );
120 }
121#endif
122
123 return lastFrame_[channel];
124}
125
126inline void Instrmnt :: controlChange( int number, StkFloat value )
127{
128 oStream_ << "Instrmnt::controlChange: virtual function call!";
129 handleError( StkError::WARNING );
130}
131
132} // stk namespace
133
134#endif
virtual void noteOn(StkFloat frequency, StkFloat amplitude)=0
Start a note with the given frequency and amplitude.
virtual StkFrames & tick(StkFrames &frames, unsigned int channel=0)
Fill the StkFrames object with computed sample frames, starting at the specified channel.
Definition Instrmnt.h:75
virtual void noteOff(StkFloat amplitude)=0
Stop a note with the given amplitude (speed of decay).
virtual void setFrequency(StkFloat frequency)
Set instrument parameters for a particular frequency.
Definition Instrmnt.h:108
virtual void controlChange(int number, StkFloat value)
Perform the control change specified by number and value (0.0 - 128.0).
Definition Instrmnt.h:126
virtual void clear(void)
Reset and clear all internal state (for subclasses).
Definition Instrmnt.h:29
unsigned int channelsOut(void) const
Return the number of output channels for the class.
Definition Instrmnt.h:44
Instrmnt(void)
Class constructor.
Definition Instrmnt.h:23
const StkFrames & lastFrame(void) const
Return an StkFrames reference to the last output sample frame.
Definition Instrmnt.h:47
StkFloat lastOut(unsigned int channel=0)
Return the specified channel value of the last computed frame.
Definition Instrmnt.h:114
virtual StkFloat tick(unsigned int channel=0)=0
Compute one sample frame and return the specified channel value.
An STK class to handle vectorized audio data.
Definition Stk.h:287
unsigned int channels(void) const
Return the number of channels represented by the data.
Definition Stk.h:415
unsigned int frames(void) const
Return the number of sample frames represented by the data.
Definition Stk.h:418
static void handleError(const char *message, StkError::Type type)
Static function for error reporting and handling using c-strings.
Stk(void)
Default constructor.
The STK namespace.
Definition ADSR.h:8