summaryrefslogtreecommitdiff
path: root/gui/src
diff options
context:
space:
mode:
authorTim Redfern <tim@getdrop.com>2018-08-18 12:09:34 +0100
committerTim Redfern <tim@getdrop.com>2018-08-18 12:09:34 +0100
commitd503992380630c1ee6d2edce8861d5f6e31cf8a1 (patch)
tree5f813f80ac7bc566534cf3fbfb7411244ec33d3b /gui/src
parentfb68eed64f548d090eb550047fd0d898e4e033fc (diff)
start vector plugin arch
Diffstat (limited to 'gui/src')
-rw-r--r--gui/src/AudioPlotter.h67
-rw-r--r--gui/src/chaoslib.h203
-rw-r--r--gui/src/lineSegmenter.cpp71
-rw-r--r--gui/src/lineSegmenter.h22
-rw-r--r--gui/src/lineTransformer.cpp126
-rw-r--r--gui/src/lineTransformer.h21
-rw-r--r--gui/src/ofApp.h107
-rw-r--r--gui/src/vectorplugin.h8
-rw-r--r--gui/src/warper.cpp0
-rw-r--r--gui/src/warper.h0
10 files changed, 474 insertions, 151 deletions
diff --git a/gui/src/AudioPlotter.h b/gui/src/AudioPlotter.h
index 42fe190..d001d22 100644
--- a/gui/src/AudioPlotter.h
+++ b/gui/src/AudioPlotter.h
@@ -3,70 +3,9 @@
#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;
- ofLog()<<"AChaosplugin creating "<<_name<<" with "<<_plugin->param_labels.size()<<" parameters";
- ofLog()<<"AChaosplugin copied "<<name<<" with "<<plugin->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->param_labels[i].size()){
- params.push_back(ofParameter <float>().set(plugin->param_labels[i],plugin->iv[i],0,plugin->iv[i]*5));
- }
- }
- }
-};
+#include "chaoslib.h"
+
-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 = {
@@ -144,7 +83,7 @@ public:
ofParameter<float> chaos_k;
ofParameter<float> chaos_p;
- Chaos chaosloader;
+ Chaoslib chaosloader;
private:
vector < vector<colourPolyline>> data;
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;
+
+
+};
+
diff --git a/gui/src/lineSegmenter.cpp b/gui/src/lineSegmenter.cpp
new file mode 100644
index 0000000..14f6e24
--- /dev/null
+++ b/gui/src/lineSegmenter.cpp
@@ -0,0 +1,71 @@
+ #include "lineSegmenter.h"
+
+const vector <ofPolyline> & lineSegmenter::getSegments(int num,float coverage, float phase){
+ //num - number of segments
+ //coverage - amount that each segment fills it's slot from 0-1
+ //phase - from 0-1
+
+ //if the path is closed, we can make a segment that crosses the end/beginning
+ //however we want to be able to deal with open paths
+
+/*
+
+segments 0...n - 1
+phase 0...1
+
+phase 0
+
+segment 0 is (0 -> coverage) / n
+segment n - 1 is ((0 -> coverage) + (n-1)) /n
+
+phase 1: has to be the loop target, it has to look identical
+
+segment 0 is (1 -> coverage) / n
+segment n - 1 is (1 - > coverage) + (n-1)
+
+*/
+
+
+ segments.clear();
+
+ for (int i=0;i<num;i++){
+ float startIndex=line.getIndexAtPercent((phase+i)/num); //always <1
+ float endPoint=(phase+i+coverage)/num; //can be >1
+ float endIndex=line.getIndexAtPercent(endPoint>1.0f?endPoint-1.0f:endPoint);
+ ofPolyline segment;
+ segment.addVertex(line.getPointAtIndexInterpolated(startIndex));
+ for (int j=(int)ceil(startIndex);j<(endPoint>1?line.size():(int)ceil(endIndex));j++){
+ segment.addVertex(line[j]);
+ }
+ if (endPoint>1){
+ segments.push_back(segment);
+ segment.clear();
+ for (int j=0;j<(int)ceil(endIndex);j++){
+ segment.addVertex(line[j]);
+ }
+ segment.addVertex(line.getPointAtIndexInterpolated(endIndex));
+ }
+ else {
+ segment.addVertex(line.getPointAtIndexInterpolated(endIndex));
+ }
+ segments.push_back(segment);
+ }
+
+ return segments;
+}
+
+void lineSegmenter::draw(){
+ line.draw();
+ return;
+}
+int lineSegmenter::size(){
+ return line.size();
+}
+
+
+/*
+
+
+
+
+*/ \ No newline at end of file
diff --git a/gui/src/lineSegmenter.h b/gui/src/lineSegmenter.h
new file mode 100644
index 0000000..d858ba2
--- /dev/null
+++ b/gui/src/lineSegmenter.h
@@ -0,0 +1,22 @@
+#pragma once
+
+#include "ofMain.h"
+
+class lineSegmenter{
+ public:
+ lineSegmenter(ofPolyline &_line){
+ line=_line;
+ if (line.isClosed()){
+ line.addVertex(line[0]);
+ }
+ }
+ const vector <ofPolyline> &getSegments(int num,float coverage, float phase);
+ ofPolyline getPoly(){
+ return line;
+ }
+ void draw();
+ int size();
+ private:
+ ofPolyline line;
+ vector <ofPolyline> segments;
+}; \ No newline at end of file
diff --git a/gui/src/lineTransformer.cpp b/gui/src/lineTransformer.cpp
new file mode 100644
index 0000000..8e2bd80
--- /dev/null
+++ b/gui/src/lineTransformer.cpp
@@ -0,0 +1,126 @@
+#include "lineTransformer.h"
+
+
+void lineTransformer::drawWarpFrame(glm::vec2 warpframe[4]){
+ ofSetColor(255,255,255);
+ ofNoFill();
+ for (int i=0;i<4;i++){
+ ofDrawCircle(warpframe[i],25);
+ ofDrawLine(warpframe[i],warpframe[(i+1)%4]);
+ }
+}
+
+void lineTransformer::gaussianElimination(float * input, int n)
+{
+ auto i = 0;
+ auto j = 0;
+ auto m = n - 1;
+
+ while (i < m && j < n)
+ {
+ auto iMax = i;
+ for (auto k = i + 1; k < m; ++k)
+ {
+ if (fabs(input[k * n + j]) > fabs(input[iMax * n + j]))
+ {
+ iMax = k;
+ }
+ }
+
+ if (input[iMax * n + j] != 0)
+ {
+ if (i != iMax)
+ {
+ for (auto k = 0; k < n; ++k)
+ {
+ auto ikIn = input[i * n + k];
+ input[i * n + k] = input[iMax * n + k];
+ input[iMax * n + k] = ikIn;
+ }
+ }
+
+ float ijIn = input[i * n + j];
+ for (auto k = 0; k < n; ++k)
+ {
+ input[i * n + k] /= ijIn;
+ }
+
+ for (auto u = i + 1; u < m; ++u)
+ {
+ auto ujIn = input[u * n + j];
+ for (auto k = 0; k < n; ++k)
+ {
+ input[u * n + k] -= ujIn * input[i * n + k];
+ }
+ }
+
+ ++i;
+ }
+ ++j;
+ }
+
+ for (auto i = m - 2; i >= 0; --i)
+ {
+ for (auto j = i + 1; j < n - 1; ++j)
+ {
+ input[i * n + m] -= input[i * n + j] * input[j * n + m];
+ }
+ }
+}
+
+glm::mat4 lineTransformer::getPerspectiveTransformMatrix(const glm::vec2 src[4], const glm::vec2 dst[4])
+{
+ float p[8][9] =
+ {
+ { -src[0][0], -src[0][1], -1, 0, 0, 0, src[0][0] * dst[0][0], src[0][1] * dst[0][0], -dst[0][0] }, // h11
+ { 0, 0, 0, -src[0][0], -src[0][1], -1, src[0][0] * dst[0][1], src[0][1] * dst[0][1], -dst[0][1] }, // h12
+ { -src[1][0], -src[1][1], -1, 0, 0, 0, src[1][0] * dst[1][0], src[1][1] * dst[1][0], -dst[1][0] }, // h13
+ { 0, 0, 0, -src[1][0], -src[1][1], -1, src[1][0] * dst[1][1], src[1][1] * dst[1][1], -dst[1][1] }, // h21
+ { -src[2][0], -src[2][1], -1, 0, 0, 0, src[2][0] * dst[2][0], src[2][1] * dst[2][0], -dst[2][0] }, // h22
+ { 0, 0, 0, -src[2][0], -src[2][1], -1, src[2][0] * dst[2][1], src[2][1] * dst[2][1], -dst[2][1] }, // h23
+ { -src[3][0], -src[3][1], -1, 0, 0, 0, src[3][0] * dst[3][0], src[3][1] * dst[3][0], -dst[3][0] }, // h31
+ { 0, 0, 0, -src[3][0], -src[3][1], -1, src[3][0] * dst[3][1], src[3][1] * dst[3][1], -dst[3][1] }, // h32
+ };
+
+ gaussianElimination(&p[0][0], 9);
+
+ return glm::mat4(p[0][8], p[3][8], 0, p[6][8],
+ p[1][8], p[4][8], 0, p[7][8],
+ 0, 0, 1, 0,
+ p[2][8], p[5][8], 0, 1);
+}
+
+ofPolyline lineTransformer::polyLineTransform(const ofMatrix4x4 xform, const ofPolyline& poly){
+ ofPolyline tempPoly;
+ for (auto& p:poly){
+ tempPoly.addVertex(ofVec3f(p)*xform);
+ }
+ return tempPoly;
+}
+
+colourPolyline lineTransformer::polyLineTransform(const ofMatrix4x4 xform,colourPolyline& poly,float colourFade){
+ colourPolyline tempPoly;
+ for (int i=0;i<poly.size();i++){
+ tempPoly.addVertex(ofVec3f(poly[i])*xform,poly.getColourAt(i)*colourFade);
+ }
+ return tempPoly;
+}
+
+ofPolyline lineTransformer::makePolygon(int num,float diam){
+ ofPolyline poly;
+ float step=PI*2/num;
+ for (int i=0;i<=num;i++){
+ poly.addVertex(cos(step*i)*diam,sin(step*i)*diam);
+ }
+ return poly;
+}
+
+void lineTransformer::drawPoly(ofPolyline poly,float x,float y){
+ glPushMatrix();
+ ofTranslate(x,y);
+ poly.draw();
+ for (int i=0;i<poly.size();i++){
+ ofDrawBitmapString(poly.getDegreesAtIndex(i),poly[i].x+10,poly[i].y+10,0);
+ }
+ glPopMatrix();
+}
diff --git a/gui/src/lineTransformer.h b/gui/src/lineTransformer.h
new file mode 100644
index 0000000..f5ec22f
--- /dev/null
+++ b/gui/src/lineTransformer.h
@@ -0,0 +1,21 @@
+#pragma once
+
+#include "ofMain.h"
+#include "colourPolyline.h"
+
+class lineTransformer {
+
+ public:
+ lineTransformer(){
+ }
+ void static drawWarpFrame(glm::vec2 warpframe[4]);
+ void static gaussianElimination(float * input, int n);
+ glm::mat4 static getPerspectiveTransformMatrix(const glm::vec2 src[4], const glm::vec2 dst[4]);
+ ofPolyline static polyLineTransform(const ofMatrix4x4 xform,const ofPolyline& poly);
+ ofPolyline static polyLineTransform(ofPoint (*transferFunction)(const ofPoint),const ofPolyline& poly);
+ colourPolyline static polyLineTransform(const ofMatrix4x4 xform,colourPolyline& poly,float colourFade=1.0f);
+ colourPolyline static polyLineTransform(ofPoint (*transferFunction)(const ofPoint),colourPolyline& poly,float colourFade=1.0f);
+ ofPolyline static makePolygon(int num,float diam);
+ void static drawPoly(ofPolyline poly,float x,float y);
+
+}; \ No newline at end of file
diff --git a/gui/src/ofApp.h b/gui/src/ofApp.h
index 128dd05..3d9a646 100644
--- a/gui/src/ofApp.h
+++ b/gui/src/ofApp.h
@@ -1,4 +1,4 @@
- #pragma once
+#pragma once
#include "ofMain.h"
@@ -26,6 +26,25 @@
#include "ofxHistoryPlot.h"
#include "Audioplotter.h"
+/*
+doing the show
+
+projection mapping * drawing
+draw shapes into the space and save them in sets
+use them to draw lines, expand and contract outline
+use them to mask geometric and random drawn styles
+have some kind of audioreactivity
+an interface flexible enough to enable making a show on the fly
+
+plugin architecture for vector generators and effects
+
+polylines in
+polylines out
+masking
+audio
+
+*/
+
enum Source{
TEST,
// NDI,
@@ -37,93 +56,7 @@ enum Source{
};
-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 (auto p:chaosloader.get().params){
- add(p);
- }
- ofLog()<<"loaded "<<chaosloader.get().params.size()<<" params";
- }
-private:
- Chaos chaosloader;
- ofxLabel plugin_label;
- ofParameter<string> plugin_name;
-};
class ofApp: public ofBaseApp, public ofxMidiListener {
diff --git a/gui/src/vectorplugin.h b/gui/src/vectorplugin.h
new file mode 100644
index 0000000..cccc6ee
--- /dev/null
+++ b/gui/src/vectorplugin.h
@@ -0,0 +1,8 @@
+
+#include "ofMain.h"
+
+class vectorBase {
+ public:
+ vectorBase(){};
+ vectorBase(){};
+} \ No newline at end of file
diff --git a/gui/src/warper.cpp b/gui/src/warper.cpp
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/gui/src/warper.cpp
diff --git a/gui/src/warper.h b/gui/src/warper.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/gui/src/warper.h