flext  0.6.0
flstk.h
Go to the documentation of this file.
1 /*
2 flext - C++ layer for Max and Pure Data externals
3 
4 Copyright (c) 2001-2015 Thomas Grill (gr@grrrr.org)
5 For information on usage and redistribution, and for a DISCLAIMER OF ALL
6 WARRANTIES, see the file, "license.txt," in this distribution.
7 */
8 
9 #ifndef __FLEXT_STK_H
10 #define __FLEXT_STK_H
11 
12 #include "flext.h"
13 
14 // PI is defined in the Max/MSP SDK, but clashes with Stk.h
15 #ifdef PI
16 #undef PI
17 #endif
18 
19 #include <Stk.h>
20 
21 #include "flpushns.h"
22 
23 using stk::Stk;
24 using stk::StkFloat;
25 using stk::StkFrames;
26 
28  public flext_dsp
29 {
31 
32 public:
33  flext_stk();
34 
35  // these have to be overridden in child classes
36  virtual bool NewObjs() { return true; }
37  virtual void FreeObjs() {}
38  virtual void ProcessObjs(int blocksize) {}
39 
40 protected:
41  virtual bool Init();
42  virtual void Exit();
43 
45  class Input:
46  public Stk
47  {
48  public:
49  Input(const t_sample *b,int v):
50  buf(b),vecsz(v),
51  index(v-1)
52  {}
53 
54  inline StkFloat lastOut() const { return (StkFloat)buf[index]; }
55 
56  inline StkFloat tick()
57  {
58  if(++index >= vecsz) index = 0;
59  return lastOut();
60  }
61 
62  StkFloat *tick(StkFloat *vector,unsigned int vectorSize);
63 
64  inline StkFrames &tick(StkFrames &vector)
65  {
66  FLEXT_ASSERT(vector.channels() == 1);
67  tick(&vector[0],vector.frames());
68  return vector;
69  }
70 
71  inline void SetBuf(const t_sample *b) { buf = b; }
72 
73  private:
74  const t_sample *buf;
75  int vecsz,index;
76  };
77 
79  class Output:
80  public Stk
81  {
82  public:
83  Output(t_sample *b,int v):
84  buf(b),vecsz(v),
85  index(0)
86  {}
87 
88  inline void tick(StkFloat s)
89  {
90  buf[index] = (t_sample)s;
91  if(++index >= vecsz) index = 0;
92  }
93 
94  void tick(const StkFloat *vector,unsigned int vectorSize);
95 
96  inline void tick(const StkFrames &vector)
97  {
98  FLEXT_ASSERT(vector.channels() == 1);
99  // dirty casting due to bug in STK api... operator[] _should_ return const StkFloat &
100  tick(&const_cast<StkFrames &>(vector)[0],vector.frames());
101  }
102 
103  inline void SetBuf(t_sample *b) { buf = b; }
104 
105  private:
106  t_sample *buf;
107  int vecsz,index;
108  };
109 
110  Input &Inlet(int ix) { return *inobj[ix]; }
111  Output &Outlet(int ix) { return *outobj[ix]; }
112 
113 private:
114  virtual bool CbDsp();
115  virtual void CbSignal();
116 
117  void ClearObjs();
118 
119  int inobjs,outobjs;
122 
123  float smprt;
124  int blsz;
125 };
126 
127 #include "flpopns.h"
128 
129 #ifdef FLEXT_INLINE
130 # include "flstk.cpp"
131 #endif
132 
133 #endif
flext.h
This is the main flext include file.
flext_base::Init
virtual bool Init()
Set up inlets and outlets, method and attribute lists.
Definition: flext.cpp:62
FLEXT_ASSERT
#define FLEXT_ASSERT(b)
Definition: flstdc.h:284
flext_stk::Output::tick
void tick(const StkFrames &vector)
Definition: flstk.h:96
flext_stk::Input::SetBuf
void SetBuf(const t_sample *b)
Definition: flstk.h:71
flext_stk::Input::tick
StkFloat tick()
Definition: flstk.h:56
flext_dsp::CbDsp
virtual bool CbDsp()
Called on every dsp init.
Definition: fldsp.cpp:139
flext_stk::Output::Output
Output(t_sample *b, int v)
Definition: flstk.h:83
flext_stk::Input::tick
StkFrames & tick(StkFrames &vector)
Definition: flstk.h:64
flpopns.h
flext_stk::Output::buf
t_sample * buf
Definition: flstk.h:106
flext_stk::Input
STK object for reading from inlet buffer.
Definition: flstk.h:47
flext_stk::Input::lastOut
StkFloat lastOut() const
Definition: flstk.h:54
flstk.cpp
flext_stk::blsz
int blsz
Definition: flstk.h:124
flext_stk::Output
STK object for writing to outlet buffer.
Definition: flstk.h:81
flext_stk::ProcessObjs
virtual void ProcessObjs(int blocksize)
Definition: flstk.h:38
flext_dsp
Flext dsp enabled base object.
Definition: fldsp.h:33
flext_stk::Input::vecsz
int vecsz
Definition: flstk.h:75
flext_stk::Input::buf
const t_sample * buf
Definition: flstk.h:74
flext_stk::NewObjs
virtual bool NewObjs()
Definition: flstk.h:36
flext_stk::outobjs
int outobjs
Definition: flstk.h:119
flext_stk::Input::Input
Input(const t_sample *b, int v)
Definition: flstk.h:49
flext_stk::Outlet
Output & Outlet(int ix)
Definition: flstk.h:111
flext_dsp::CbSignal
virtual void CbSignal()
Called with every signal vector - here you do the dsp calculation flext_dsp::CbSignal fills all outpu...
Definition: fldsp.cpp:153
flext_stk::Output::vecsz
int vecsz
Definition: flstk.h:107
flext_stk::Output::SetBuf
void SetBuf(t_sample *b)
Definition: flstk.h:103
FLEXT_SHARE
#define FLEXT_SHARE
Definition: flprefix.h:425
flpushns.h
flext_stk::Inlet
Input & Inlet(int ix)
Definition: flstk.h:110
flext_stk::FreeObjs
virtual void FreeObjs()
Definition: flstk.h:37
flext_stk
Definition: flstk.h:29
flext_stk::Output::tick
void tick(StkFloat s)
Definition: flstk.h:88
flext_stk::inobj
Input ** inobj
Definition: flstk.h:120
flext_dsp::Exit
virtual void Exit()
Deallocate all kinds of stuff.
Definition: fldsp.cpp:44
FLEXT_HEADER
#define FLEXT_HEADER(NEW_CLASS, PARENT_CLASS)
Plain flext class header.
Definition: fldefs_hdr.h:29
flext_stk::outobj
Output ** outobj
Definition: flstk.h:121
flext_stk::smprt
float smprt
Definition: flstk.h:123