1 modulestk.instrument;
2 3 importstk.stk;
4 5 /**
6 7 STK instrument abstract base class.
8 9 This class provides a common interface for
10 all STK instruments.
11 12 Porting portions of STK library to D.
13 https://github.com/thestk/stk by Perry R. Cook and Gary P. Scavone, 1995--2016.
14 15 */16 17 abstractclassInstrmnt : Stk18 {
19 public:
20 //! Class constructor.21 this() {
22 lastFrame_.resize( 1, 1, 0.0 );
23 };
24 25 //! Reset and clear all internal state (for subclasses).26 /*!
27 Not all subclasses implement a clear() function.
28 */29 voidclear() {};
30 31 //! Start a note with the given frequency and amplitude.32 voidnoteOn( StkFloatfrequency, StkFloatamplitude ) = 0;
33 34 //! Stop a note with the given amplitude (speed of decay).35 voidnoteOff( StkFloatamplitude ) = 0;
36 37 //! Set instrument parameters for a particular frequency.38 voidsetFrequency( StkFloatfrequency );
39 40 //! Perform the control change specified by \e number and \e value (0.0 - 128.0).41 voidcontrolChange(intnumber, StkFloatvalue);
42 43 //! Return the number of output channels for the class.44 uintchannelsOut() const { returnlastFrame_.channels(); };
45 46 //! Return an StkFrames reference to the last output sample frame.47 refStkFrameslastFrame() { returnlastFrame_; };
48 49 //! Return the specified channel value of the last computed frame.50 /*!
51 The \c channel argument must be less than the number of output
52 channels, which can be determined with the channelsOut() function
53 (the first channel is specified by 0). However, range checking is
54 only performed if _STK_DEBUG_ is defined during compilation, in
55 which case an out-of-range value will trigger an StkError
56 exception. \sa lastFrame()
57 */58 StkFloatlastOut( uintchannel = 0 );
59 60 //! Compute one sample frame and return the specified \c channel value.61 /*!
62 For monophonic instruments, the \c channel argument is ignored.
63 */64 StkFloattick( uintchannel = 0 ) = 0;
65 66 //! Fill the StkFrames object with computed sample frames, starting at the specified channel.67 /*!
68 The \c channel argument plus the number of output channels must
69 be less than the number of channels in the StkFrames argument (the
70 first channel is specified by 0). However, range checking is only
71 performed if _STK_DEBUG_ is defined during compilation, in which
72 case an out-of-range value will trigger an StkError exception.
73 */74 StkFramestick( StkFramesframes, uintchannel = 0) = 0;
75 76 protected:
77 78 StkFrameslastFrame_;
79 80 }