aboutsummaryrefslogtreecommitdiff
path: root/externals/grill/flext/source/flstk.h
blob: c3376cb5ebf66abad4baf64facedb15ef2256370 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/* 

flext - C++ layer for Max/MSP and pd (pure data) externals

Copyright (c) 2001-2007 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 __FLSTK_H
#define __FLSTK_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>

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();

    //! STK object for reading from inlet buffer
    class Input:
        public Stk
    {
    public:
        Input(const t_sample *b,int vecsz);

        inline MY_FLOAT lastOut() const { return (MY_FLOAT)buf[index]; }

        inline MY_FLOAT tick() 
        { 
            if(++index >= vecsz) index = 0; 
            return lastOut(); 
        }

        MY_FLOAT *tick(MY_FLOAT *vector,unsigned int vectorSize);

        inline void SetBuf(const t_sample *b) { buf = b; }

    private:
        const t_sample *buf;
        int vecsz,index;
    };

    //! STK object for writing to outlet buffer
    class Output:
        public Stk
    {
    public:
        Output(t_sample *b,int vecsz);

        inline void tick(MY_FLOAT s) 
        { 
            buf[index] = (t_sample)s; 
            if(++index >= vecsz) index = 0; 
        }

        void tick(const MY_FLOAT *vector,unsigned int vectorSize);

        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;
};

#endif