summaryrefslogtreecommitdiff
path: root/gui/src/AudioPlotter.h
blob: 7ea4bf866fdfd3dcef1ae0457b8d3dabd1e1d58a (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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#include "ofMain.h"
#include "ofxAChaoslib.h"

#include "lineTransformer.h"

class AChaosplugin{
    public:
        AChaosBase* plugin;
        vector <ofParameter <float>> params;
        string name;
        AChaosplugin(AChaosBase* _plugin,string _name,vector <REAL> _params={0,0,0,0,0,0}){
            plugin=_plugin;
            name=_name;
            plugin->setup();
            load_defaults();
            ofLog()<<"constructor "<<name;
        }
        void load_defaults(){
            params.clear();
            for (auto i:plugin->iv){
                ofLog()<<"iv: "<<i;
                params.push_back(ofParameter <float>().set(ofToString(i),i,0,i*5));
            }
        }
};

class Chaos{
    public:
        vector <AChaosplugin*> plugins;
        vector <vector <REAL>> params;
        int whichplugin;
        ofParameter <string> name;
        Chaos(){
            //can only use those that have 2 output params?
            //or just make it 1 dimensional? only affect the x axis?
            plugins.push_back(new AChaosplugin(new AChaosBaker(),"Baker"));
            plugins.push_back(new AChaosplugin(new AChaosClifford(),"Clifford"));
            plugins.push_back(new AChaosplugin(new AChaosCollatz(),"Collatz"));
            plugins.push_back(new AChaosplugin(new AChaosDuffing(),"Duffing"));
            plugins.push_back(new AChaosplugin(new AChaosGinger(),"Ginger"));
            plugins.push_back(new AChaosplugin(new AChaosHenon(),"Henon"));
            whichplugin=0;
            update_name();
        }
        AChaosplugin &get(){
            return *plugins[whichplugin];
        }
        void next(){
            whichplugin=(whichplugin+1)%plugins.size();
            update_name();
        }
        void previous(){
            whichplugin=whichplugin-1;
            if (whichplugin<0){
                whichplugin=plugins.size()-1;
            }
            update_name();
        }
        void update_name(){
            name=plugins[whichplugin]->name;
            //save old params & load new
        }
        std::string &get_name(){
            return plugins[whichplugin]->name;
        }
};

/*
    vector <string> names = { 
        "Baker",
        "Clifford",
        "Collatz",
        "Duffing",
        "Ginger",
        "Henon",
        "HenonF",
        "HenonHeilles",
        "HenonPhase",
        "Ikeda",
        "Jong",
        "Logistic",
        "Logistic1",
        "Lorenz",
        "LorenzEuler",
        "Lyapunov",
        "NavierStokes",
        "NavierStokesEuler",
        "Rossler",
        "Stein",
        "Stein1",
        "Torus",
        "Verhulst" 
    };
}
*/

class Audioplotter{
    //store and draw a numbr of audio samples
    //how best to handle transforms - maybe pass in a transform to be added to 2nd and subsequent
    //how best to handle length of history data - fixed number that can be set, or line budget?
public:
    Audioplotter(int _size=1,bool _joined=true,bool _bars=false,int _width=2){
        setup(_size,_joined,_bars,_width);
    }
    void setup(int _size=1,bool _joined=true,bool _bars=false,int _width=2){
        history_size=_size;
        joined=_joined;
        bars=_bars;
        width=_width;
        startColour=ofColor(255,255,255);
        endColour=ofColor(0,0,0);
        attractor.setup();
    }
    colourPolyline compute_chaos(colourPolyline& poly,float colourFade=1.0f);
    vector <colourPolyline> output(float scale=1.0f,float decay=-1.0f);
    void addpoints(vector <float> &audio);
    void blankframe();
    int numpoints();

    ofParameter<bool> random;
    ofParameter<bool> joined;
    ofParameter<bool> bars;
    ofParameter<bool> mirror;
    ofParameter<int> width;
    ofParameter<int> history_size;
    ofParameter<int> num_points;

//feedback transformation
    ofParameter<ofVec2f> translate;
    ofParameter<float> rotate;
    ofParameter<ofVec2f> scale;

    ofParameter<ofColor> startColour;
    ofParameter<ofColor> endColour;

    ofParameter<bool> usechaos;
    ofParameter<float> chaosamount;
    ofParameter<float> chaosscale;
    ofParameter<float> chaos_a;
    ofParameter<float> chaos_b;
    ofParameter<float> chaos_k;
    ofParameter<float> chaos_p;

    Chaos chaosloader;

private:
    vector < vector<colourPolyline>> data;
    AChaosIkeda attractor;
    

};