summaryrefslogtreecommitdiff
path: root/gui/src/chaoslib.h
diff options
context:
space:
mode:
Diffstat (limited to 'gui/src/chaoslib.h')
-rw-r--r--gui/src/chaoslib.h203
1 files changed, 203 insertions, 0 deletions
diff --git a/gui/src/chaoslib.h b/gui/src/chaoslib.h
new file mode 100644
index 0000000..9196e88
--- /dev/null
+++ b/gui/src/chaoslib.h
@@ -0,0 +1,203 @@
+#pragma once
+
+#include "ofMain.h"
+#include "ofxGui.h"
+#include "ofxAChaoslib.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;
+ ofLog()<<"AChaosplugin creating "<<_name<<" with "<<_plugin->get_param_labels().size()<<" parameters";
+ //ofLog()<<"AChaosplugin copied "<<name<<" with "<<plugin->get_param_labels().size()<<" parameters";
+ plugin->setup();
+
+ load_defaults();
+ //ofLog()<<"AChaosplugin created "<<name<<" with "<<params.size()<<" parameters";
+ }
+
+ void load_defaults(){
+ params.clear();
+ for (int i=0;i<plugin->iv.size();i++){
+ if (plugin->get_param_labels()[i].size()){
+ params.push_back(ofParameter <float>().set(plugin->get_param_labels()[i],plugin->iv[i],0,plugin->iv[i]*5));
+ }
+ }
+ }
+
+};
+
+class Chaosplugin{
+ public:
+ Chaosplugin(){
+
+ }
+ vector <AChaosplugin*> plugins;
+ int whichplugin;
+ ofParameter <string> name;
+};
+
+
+class Chaoslib{
+ public:
+ vector <AChaosplugin*> plugins;
+ vector <vector <REAL>> params;
+ int whichplugin;
+ ofParameter <string> name;
+ Chaoslib(){
+ //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();
+ }
+
+
+
+ AChaosbase* get_plugin(){
+ return plugins[whichplugin]->plugin;
+ }
+ AChaosbase* get_params(){
+ return plugins[whichplugin]->params;
+ }
+ 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;
+ }
+};
+
+class chaosPanel : public ofxPanel {
+ public:
+ chaosPanel(){
+ ofRegisterKeyEvents(this, defaultEventsPriority);
+ }
+ bool isSelected;
+ ofParameter<bool> active;
+ ofParameter<float> amount;
+ ofParameter<float> scale; //?per plugin??
+ bool mouseMoved(ofMouseEventArgs & args){
+ if (args.x>getPosition().x&&
+ args.x-getPosition().x<getWidth()&&
+ args.y>getPosition().y&&
+ args.y-getPosition().y<getHeight()){
+ if (!isSelected){
+ isSelected=true;
+ setBorderColor(ofColor(255,128,0));
+ //ofLog()<<"IN> "<<args.x<<","<<args.y;
+ }
+ }
+ else {
+ if (isSelected){
+ isSelected=false;
+ setBorderColor(ofColor(0,0,0));
+ //ofLog()<<"OUT> "<<args.x<<","<<args.y;
+ }
+ }
+ }
+ bool keyPressed(ofKeyEventArgs & args){
+ if (isSelected){
+ //ofLog()<<"KEY> "<<args.key;
+ switch(args.key){
+ case 3812:{
+ chaosloader.previous();
+ update_sliders();
+ break;
+ }
+ case 3814:{
+ chaosloader.next();
+ update_sliders();
+ break;
+ }
+ }
+ }
+ }
+ bool keyReleased(ofKeyEventArgs & args){
+ //required in order to call ofRegisterKeyEvents
+ }
+ //this is a bit tangled
+ /*
+ audioplotter stores drawings that it extracts from audio
+ chaosloader manages a set of plugins that affect polylines
+ audio plotter calls chaosloader a set of lines and it affects them
+ chaosloader should own it's own params (use,scale,amount)
+ should expose compute(vector polyline)
+
+ so we could have
+
+ audio source
+ <>
+ transformer
+ <>
+ chaos
+ <>
+ drawing
+
+ */
+
+ int shown=0;
+
+ void update_sliders(){
+ clear();
+ add(plugin_label.setup(chaosloader.name));
+ add(active.set("use",false));
+ add(amount.set("amount", 0.0f, -0.1f, 0.1f));
+
+ for (int i=0;i<chaosloader.get_params().size();i++){
+ if (chaosloader.get_plugin()->get_param_labels()[i].size()){
+
+ add(chaosloader.get_params()[i]);
+
+ }
+ }
+ }
+ colourPolyline compute_chaos(colourPolyline& poly){
+ float chaosscale=1.0f;
+ colourPolyline tempPoly;
+ for (int i=0;i<poly.size();i++){
+ REAL iv[chaosloader.get_plugin()->iv.size()];
+ iv[0]=poly[i].x-(ofGetWidth()/2)/chaosscale;
+ iv[1]=poly[i].y-(ofGetHeight()/2)/chaosscale;
+ //chaos_a,chaos_b,chaos_k,chaos_p};
+ //ofLog() << i<<": calculating chaos with: "<<poly[i].x<<"->"<<((poly[i].x-(ofGetWidth()/2))/chaosscale)<<" "<<poly[i].y<<"->"<<((poly[i].y-(ofGetHeight()/2))/chaosscale)<<" "<<attractor.a<<" "<<attractor.b<<" "<<attractor.k<<" "<<attractor.p;
+ chaosloader.get_plugin()->set(iv);
+ chaosloader.get_plugin()->calc();
+ //ofLog() << i<<": got points: "<<attractor.nx<<" "<<attractor.ny;
+ tempPoly.addVertex(
+ ofPoint((chaosloader.get_plugin()->ov[0]*chaosscale)+(ofGetWidth()/2),
+ (chaosloader.get_plugin()->ov[1]*chaosscale)+(ofGetHeight()/2)),
+ poly.getColourAt(i));
+ }
+ return tempPoly;
+}
+private:
+ Chaoslib chaosloader;
+ ofxLabel plugin_label;
+ ofParameter<string> plugin_name;
+
+
+};
+