flext  0.6.2
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
virtual bool Init()
Set up inlets and outlets, method and attribute lists.
Definition: flext.cpp:62
Flext dsp enabled base object.
Definition: fldsp.h:33
virtual void Exit()
Deallocate all kinds of stuff.
Definition: fldsp.cpp:44
STK object for reading from inlet buffer.
Definition: flstk.h:47
Input(const t_sample *b, int v)
Definition: flstk.h:49
StkFloat tick()
Definition: flstk.h:56
StkFloat lastOut() const
Definition: flstk.h:54
void SetBuf(const t_sample *b)
Definition: flstk.h:71
const t_sample * buf
Definition: flstk.h:74
StkFrames & tick(StkFrames &vector)
Definition: flstk.h:64
int index
Definition: flstk.h:75
STK object for writing to outlet buffer.
Definition: flstk.h:81
void tick(const StkFrames &vector)
Definition: flstk.h:96
void SetBuf(t_sample *b)
Definition: flstk.h:103
Output(t_sample *b, int v)
Definition: flstk.h:83
t_sample * buf
Definition: flstk.h:106
void tick(StkFloat s)
Definition: flstk.h:88
int index
Definition: flstk.h:107
Definition: flstk.h:29
virtual void ProcessObjs(int blocksize)
Definition: flstk.h:38
Input ** inobj
Definition: flstk.h:120
Output ** outobj
Definition: flstk.h:121
virtual bool NewObjs()
Definition: flstk.h:36
int inobjs
Definition: flstk.h:119
Input & Inlet(int ix)
Definition: flstk.h:110
Output & Outlet(int ix)
Definition: flstk.h:111
float smprt
Definition: flstk.h:123
int blsz
Definition: flstk.h:124
virtual void FreeObjs()
Definition: flstk.h:37
This is the main flext include file.
#define FLEXT_SHARE
Definition: flprefix.h:425
#define FLEXT_ASSERT(b)
Definition: flstdc.h:316
virtual bool CbDsp()
Called on every dsp init.
Definition: fldsp.cpp:139
virtual void CbSignal()
Called with every signal vector - here you do the dsp calculation flext_dsp::CbSignal fills all outpu...
Definition: fldsp.cpp:153
#define FLEXT_HEADER(NEW_CLASS, PARENT_CLASS)
Plain flext class header.
Definition: fldefs_hdr.h:29