flstk.h
Go to the documentation of this file.
/*
flext - C++ layer for Max and Pure Data externals
Copyright (c) 2001-2015 Thomas Grill (gr@grrrr.org)
For information on usage and redistribution, and for a DISCLAIMER OF ALL
WARRANTIES, see the file, "license.txt," in this distribution.
*/
#ifndef __FLEXT_STK_H
#define __FLEXT_STK_H
#include "flext.h"
// PI is defined in the Max/MSP SDK, but clashes with Stk.h
#ifdef PI
#undef PI
#endif
#include <Stk.h>
#include "flpushns.h"
using stk::Stk;
using stk::StkFloat;
using stk::StkFrames;
class FLEXT_SHARE flext_stk:
public flext_dsp
{
FLEXT_HEADER(flext_stk,flext_dsp)
public:
flext_stk();
// these have to be overridden in child classes
virtual bool NewObjs() { return true; }
virtual void FreeObjs() {}
virtual void ProcessObjs(int blocksize) {}
protected:
virtual bool Init();
virtual void Exit();
class Input:
public Stk
{
public:
Input(const t_sample *b,int v):
buf(b),vecsz(v),
index(v-1)
{}
inline StkFloat lastOut() const { return (StkFloat)buf[index]; }
inline StkFloat tick()
{
if(++index >= vecsz) index = 0;
return lastOut();
}
StkFloat *tick(StkFloat *vector,unsigned int vectorSize);
inline StkFrames &tick(StkFrames &vector)
{
FLEXT_ASSERT(vector.channels() == 1);
tick(&vector[0],vector.frames());
return vector;
}
inline void SetBuf(const t_sample *b) { buf = b; }
private:
const t_sample *buf;
int vecsz,index;
};
class Output:
public Stk
{
public:
Output(t_sample *b,int v):
buf(b),vecsz(v),
index(0)
{}
inline void tick(StkFloat s)
{
buf[index] = (t_sample)s;
if(++index >= vecsz) index = 0;
}
void tick(const StkFloat *vector,unsigned int vectorSize);
inline void tick(const StkFrames &vector)
{
FLEXT_ASSERT(vector.channels() == 1);
// dirty casting due to bug in STK api... operator[] _should_ return const StkFloat &
tick(&const_cast<StkFrames &>(vector)[0],vector.frames());
}
inline void SetBuf(t_sample *b) { buf = b; }
private:
t_sample *buf;
int vecsz,index;
};
Input &Inlet(int ix) { return *inobj[ix]; }
Output &Outlet(int ix) { return *outobj[ix]; }
private:
virtual bool CbDsp();
virtual void CbSignal();
void ClearObjs();
int inobjs,outobjs;
Input **inobj;
Output **outobj;
float smprt;
int blsz;
};
#include "flpopns.h"
#ifdef FLEXT_INLINE
# include "flstk.cpp"
#endif
#endif
flext_base::Init
virtual bool Init()
Set up inlets and outlets, method and attribute lists.
Definition: flext.cpp:62
flext_stk::Input::lastOut
StkFloat lastOut() const
Definition: flstk.h:54
flext_stk::Output::Output
Output(t_sample *b, int v)
Definition: flstk.h:83
flext_stk::Output::buf
t_sample * buf
Definition: flstk.h:106
flext_stk::Input::buf
const t_sample * buf
Definition: flstk.h:74
FLEXT_HEADER
#define FLEXT_HEADER(NEW_CLASS, PARENT_CLASS)
Plain flext class header.
Definition: fldefs_hdr.h:29
flext_stk::Input::SetBuf
void SetBuf(const t_sample *b)
Definition: flstk.h:71
flext.h
This is the main flext include file.
flext_stk
Definition: flstk.h:27
flext_stk::Output::tick
void tick(const StkFrames &vector)
Definition: flstk.h:96
flext_stk::Output
STK object for writing to outlet buffer.
Definition: flstk.h:79
flext_stk::Input::tick
StkFloat tick()
Definition: flstk.h:56
flext_dsp::Exit
virtual void Exit()
Deallocate all kinds of stuff.
Definition: fldsp.cpp:40
FLEXT_ASSERT
#define FLEXT_ASSERT(b)
Definition: flstdc.h:284
flext_stk::outobjs
int outobjs
Definition: flstk.h:119
flext_stk::ProcessObjs
virtual void ProcessObjs(int blocksize)
Definition: flstk.h:38
flext_stk::Output::vecsz
int vecsz
Definition: flstk.h:107
flext_stk::blsz
int blsz
Definition: flstk.h:124
flext_stk::Output::SetBuf
void SetBuf(t_sample *b)
Definition: flstk.h:103
flext_dsp
Flext dsp enabled base object.
Definition: fldsp.h:31
flpushns.h
flext_stk::NewObjs
virtual bool NewObjs()
Definition: flstk.h:36
flpopns.h
flext_stk::Inlet
Input & Inlet(int ix)
Definition: flstk.h:110
FLEXT_SHARE
#define FLEXT_SHARE
Definition: flprefix.h:418
flext_stk::Input
STK object for reading from inlet buffer.
Definition: flstk.h:45
flext_stk::Outlet
Output & Outlet(int ix)
Definition: flstk.h:111
flext_stk::inobj
Input ** inobj
Definition: flstk.h:120
flext_stk::smprt
float smprt
Definition: flstk.h:123
flext_stk::Input::vecsz
int vecsz
Definition: flstk.h:75
flstk.cpp
flext_stk::FreeObjs
virtual void FreeObjs()
Definition: flstk.h:37
flext_stk::Input::Input
Input(const t_sample *b, int v)
Definition: flstk.h:49
flext_stk::outobj
Output ** outobj
Definition: flstk.h:121
flext_stk::Output::tick
void tick(StkFloat s)
Definition: flstk.h:88
flext_stk::Input::tick
StkFrames & tick(StkFrames &vector)
Definition: flstk.h:64