Home   Information   Classes   Download   Usage   Mail List   Requirements   Links   FAQ   Tutorial


Instrmnt.h

00001 #ifndef STK_INSTRMNT_H
00002 #define STK_INSTRMNT_H
00003 
00004 #include "Stk.h"
00005 
00006 namespace stk {
00007 
00008 /***************************************************/
00017 /***************************************************/
00018 
00019 class Instrmnt : public Stk
00020 {
00021  public:
00023   Instrmnt( void ) { lastFrame_.resize( 1, 1, 0.0 ); };
00024 
00026   virtual void noteOn( StkFloat frequency, StkFloat amplitude ) = 0;
00027 
00029   virtual void noteOff( StkFloat amplitude ) = 0;
00030 
00032   virtual void setFrequency( StkFloat frequency );
00033 
00035   virtual void controlChange(int number, StkFloat value);
00036 
00038   unsigned int channelsOut( void ) const { return lastFrame_.channels(); };
00039 
00041   const StkFrames& lastFrame( void ) const { return lastFrame_; };
00042 
00044 
00052   StkFloat lastOut( unsigned int channel = 0 );
00053 
00055 
00058   virtual StkFloat tick( unsigned int channel = 0 ) = 0;
00059 
00061 
00068   StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
00069 
00070  protected:
00071 
00072   StkFrames lastFrame_;
00073 
00074 };
00075 
00076 inline void Instrmnt :: setFrequency(StkFloat frequency)
00077 {
00078   errorString_ << "Instrmnt::setFrequency: virtual setFrequency function call!";
00079   handleError( StkError::WARNING );
00080 }
00081 
00082 inline StkFloat Instrmnt :: lastOut( unsigned int channel )
00083 {
00084 #if defined(_STK_DEBUG_)
00085   if ( channel >= lastFrame_.channels() ) {
00086     errorString_ << "Instrmnt::lastOut(): channel argument is invalid!";
00087     handleError( StkError::FUNCTION_ARGUMENT );
00088   }
00089 #endif
00090 
00091   return lastFrame_[channel];
00092 }
00093 
00094 inline StkFrames& Instrmnt :: tick( StkFrames& frames, unsigned int channel )
00095 {
00096   unsigned int nChannels = lastFrame_.channels();
00097 #if defined(_STK_DEBUG_)
00098   if ( channel > frames.channels() - nChannels ) {
00099     errorString_ << "Instrmnt::tick(): channel and StkFrames arguments are incompatible!";
00100     handleError( StkError::FUNCTION_ARGUMENT );
00101   }
00102 #endif
00103 
00104   StkFloat *samples = &frames[channel];
00105   unsigned int j, hop = frames.channels() - nChannels;
00106   if ( nChannels == 1 ) {
00107     for ( unsigned int i=0; i<frames.frames(); i++, samples += hop )
00108       *samples++ = tick();
00109   }
00110   else {
00111     for ( unsigned int i=0; i<frames.frames(); i++, samples += hop ) {
00112       *samples++ = tick();
00113       for ( j=1; j<nChannels; j++ )
00114         *samples++ = lastFrame_[j];
00115     }
00116   }
00117 
00118   return frames;
00119 }
00120 
00121 inline void Instrmnt :: controlChange( int number, StkFloat value )
00122 {
00123   errorString_ << "Instrmnt::controlChange: virtual function call!";
00124   handleError( StkError::WARNING );
00125 }
00126 
00127 } // stk namespace
00128 
00129 #endif

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