summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--passadesgui/src/lineSegmenter.cpp2
-rw-r--r--passadesgui/src/lineSegmenter.h8
-rw-r--r--passadesgui/src/ofApp.cpp139
-rw-r--r--passadesgui/src/ofApp.h6
4 files changed, 139 insertions, 16 deletions
diff --git a/passadesgui/src/lineSegmenter.cpp b/passadesgui/src/lineSegmenter.cpp
index 3f434b1..495190d 100644
--- a/passadesgui/src/lineSegmenter.cpp
+++ b/passadesgui/src/lineSegmenter.cpp
@@ -84,7 +84,7 @@ const vector <colourPolyline> & colourLineSegmenter::getSegments(int num,float c
segment.addVertex(line.getPointAtIndexInterpolated(endIndex),line.getColourAtIndexInterpolated(endIndex));
}
else {
- segment.addVertex(line.getPointAtIndexInterpolated(endIndex),line.getColourAtIndexInterpolated(endIndex) );
+ segment.addVertex(line.getPointAtIndexInterpolated(endIndex),line.getColourAtIndexInterpolated(endIndex));
}
segments.push_back(segment);
}
diff --git a/passadesgui/src/lineSegmenter.h b/passadesgui/src/lineSegmenter.h
index 2467c6a..6aa7bc7 100644
--- a/passadesgui/src/lineSegmenter.h
+++ b/passadesgui/src/lineSegmenter.h
@@ -26,15 +26,17 @@ class colourLineSegmenter{
public:
colourLineSegmenter(colourPolyline &_line){
line=_line;
+ //this was commented out
//if (line.isClosed()){
// line.addVertex(line[0]);
//}
}
colourLineSegmenter(ofPolyline &_line,const ofColor color=ofColor(255,255,255)){
line=colourPolyline(_line,color);
- if (_line.isClosed()){
- line.addVertex(line[0],line.getColourAt(0));
- }
+ //if (_line.isClosed()){
+ // line.addVertex(line[0],line.getColourAt(0));
+ //}
+ //commenting this out does not help weird issie when segmenting
}
const vector <colourPolyline> &getSegments(int num,float coverage, float phase);
colourPolyline getPoly(){
diff --git a/passadesgui/src/ofApp.cpp b/passadesgui/src/ofApp.cpp
index 36e0785..e8b8a91 100644
--- a/passadesgui/src/ofApp.cpp
+++ b/passadesgui/src/ofApp.cpp
@@ -91,7 +91,7 @@ void ofApp::setup(){
drawgui.add(video_speed.setup("playback speed", 1.0, 0.0, 3.0));
drawgui.add(shapes_randomise.setup("randomise shapes", true));
drawgui.add(shapes_amount.setup("shapes amount", 0.2, 0.0, 0.8));
- drawgui.add(shapes_duration.setup("shape duration", 5, 0, 25));
+ drawgui.add(shapes_duration.setup("shape duration", 5, 0, 250));
drawgui.add(use_mask.setup("use mask", true));
drawgui.add(invert_mask.setup("invert mask", false));
drawgui.add(use_segmenter.setup("use segmenter", false));
@@ -115,7 +115,7 @@ void ofApp::setup(){
audiogui.add(plotter.bars.set("bars",true));
audiogui.add(plotter.mirror.set("mirror",false));
audiogui.add(plotter.width.set("point width", 2, 1, 256));
- audiogui.add(plotter.num_points.set("num points", 50, 1, 64));
+ audiogui.add(plotter.num_points.set("num points", 50, 1, 512));
audiogui.add(plotter.history_size.set("num plots", 5, 1, 64));
audiogui.add(plotter.translate.set("translate",ofVec2f(0,0),ofVec2f(-50,-50),ofVec2f(50,50)));
audiogui.add(plotter.rotate.set("rotate",0.0f,-10.0f,10.0f));
@@ -128,7 +128,7 @@ void ofApp::setup(){
//============================ MIDI
midiIn.listInPorts();
- midiIn.openPort(0);
+ midiIn.openPort(1);
midiIn.addListener(this);
//======================================= //positioning interface
@@ -755,6 +755,54 @@ void ofApp::drawOutput(ofEventArgs & args){
break;
}
case SVG_outlines:{
+ if (!use_onset||onset_frame<onset_duration||shapes_randomise){
+ if (shapes_randomise){
+ //if (framecounter==0){
+ // select_random_shapes();
+ // framecounter=shapes_duration;
+ //}
+ select_random_shapes(shapes_duration,!use_onset||onset_frame<onset_duration);
+ for (auto s:shape_selection){
+ if (use_segmenter){
+ auto segments=segmenters[s].getSegments(segmenter_number,segmenter_length,phase);
+ for (auto segment=segments.begin();segment!=segments.end();segment++){
+ //polyOutput.push_back(colourPolyline(*segment,ofColor(laser_R,laser_G,laser_B)));
+ polyOutput.push_back(*segment);
+ }
+ }
+ else {
+ //polyOutput.push_back(colourPolyline(segmenters[s].getPoly(),ofColor(laser_R,laser_G,laser_B)));
+ polyOutput.push_back(segmenters[s].getPoly());
+ }
+ }
+ framecounter--;
+ }
+ else {
+ for (auto shape=segmenters.begin();shape!=segmenters.end();shape++){
+ if (use_segmenter){
+ auto segments=shape->getSegments(segmenter_number,segmenter_length,phase);
+ for (auto segment=segments.begin();segment!=segments.end();segment++){
+ //polyOutput.push_back(colourPolyline(*segment,ofColor(laser_R,laser_G,laser_B)));
+ polyOutput.push_back(*segment);
+ }
+ }
+ else {
+ //polyOutput.push_back(colourPolyline(shape->getPoly(),ofColor(laser_R,laser_G,laser_B)));
+ polyOutput.push_back(shape->getPoly());
+ }
+ }
+ }
+ if (contour_useColour){
+ vector<colourPolyline> newPolys;
+ for (auto p: polyOutput){
+ newPolys.push_back(colourPolyline((ofPolyline)p,ofColor(laser_R,laser_G,laser_B))) ;
+ }
+ polyOutput=newPolys;
+ }
+ }
+ break;
+ }
+ /*{
if (shapes_randomise){
if (framecounter==0){
select_random_shapes();
@@ -764,11 +812,15 @@ void ofApp::drawOutput(ofEventArgs & args){
if (use_segmenter){
auto segments=segmenters[s].getSegments(segmenter_number,segmenter_length,phase);
for (auto segment=segments.begin();segment!=segments.end();segment++){
- polyOutput.push_back(colourPolyline(*segment,ofColor(laser_R,laser_G,laser_B)));
+ polyOutput.push_back(contour_useColour?
+ colourPolyline(*segment):
+ colourPolyline(*segment,ofColor(laser_R,laser_G,laser_B)));
}
}
else {
- polyOutput.push_back(colourPolyline(segmenters[s].getPoly(),ofColor(laser_R,laser_G,laser_B)));
+ polyOutput.push_back(contour_useColour?
+ colourPolyline(segmenters[s].getPoly()):
+ colourPolyline(segmenters[s].getPoly(),ofColor(laser_R,laser_G,laser_B)));
}
}
framecounter--;
@@ -778,17 +830,21 @@ void ofApp::drawOutput(ofEventArgs & args){
if (use_segmenter){
auto segments=shape->getSegments(segmenter_number,segmenter_length,phase);
for (auto segment=segments.begin();segment!=segments.end();segment++){
- polyOutput.push_back(colourPolyline(*segment,ofColor(laser_R,laser_G,laser_B)));
+ polyOutput.push_back(contour_useColour?
+ colourPolyline(*segment):
+ colourPolyline(*segment,ofColor(laser_R,laser_G,laser_B)));
}
}
else {
- polyOutput.push_back(colourPolyline(shape->getPoly(),ofColor(laser_R,laser_G,laser_B)));
+ polyOutput.push_back(contour_useColour?
+ colourPolyline(shape->getPoly()):
+ colourPolyline(shape->getPoly(),ofColor(laser_R,laser_G,laser_B)));
}
}
}
break;
- }
+ }*/
case Audio:{
ofMatrix4x4 x=ofMatrix4x4(1.0f,0.0f,0.0f,0.0f,
0.0f,1.0f,0.0f,0.0f,
@@ -1068,7 +1124,49 @@ void ofApp::windowResized(int w, int h){
}
-void ofApp::select_random_shapes(){
+float last_frame_time=0.0f;
+
+void ofApp::select_random_shapes(float duration,bool generate=true){
+ float timedelta=ofGetElapsedTimef()-last_frame_time;
+ last_frame_time=ofGetElapsedTimef();
+ //track how long each shape has been selected
+ for (int i=0;i<shape_selection_durations.size();i++){
+ if (shape_selection_durations[i]>0.0f){
+ shape_selection_durations[i]=shape_selection_durations[i]-timedelta;
+ }
+ }
+
+ shape_selection.clear();
+
+ for (int i=0;i<shape_selection_durations.size();i++){
+ if (shape_selection_durations[i]>0.0f){
+ shape_selection.insert(i);
+ }
+ }
+ std::stringstream strom;
+ for (auto& s:shape_selection){
+ strom << s <<":"<<shape_selection_durations[s]<<" ";
+ }
+
+ //cout << timedelta <<": decay selection: "<<shape_selection.size()<<" shapes (" << strom.str() <<") \n";
+ if (generate){
+
+ while (shape_selection.size()<(segmenters.size()*shapes_amount)){
+ int selection=rand()%segmenters.size();
+ if (shape_selection.find(selection)==shape_selection.end()){
+ shape_selection_durations[selection]=duration+ofRandom(1.0f);
+ shape_selection.insert(selection);
+ }
+ }
+ std::stringstream strm;
+ for (auto& s:shape_selection){
+ strm << s <<":"<<shape_selection_durations[s]<<" ";
+ }
+ }
+ //cout << "random selection: "<<shape_selection.size()<<" shapes (" << strm.str() <<") \n";
+}
+/*
+void ofApp::old_select_random_shapes(){
shape_selection.clear();
while (shape_selection.size()<(segmenters.size()*shapes_amount)){
int selection=rand()%segmenters.size();
@@ -1082,6 +1180,7 @@ void ofApp::select_random_shapes(){
}
//cout << "randomly selected (" << strm.str() <<") \n";
}
+*/
//--------------------------------------------------------------
void ofApp::dragEvent(ofDragInfo dragInfo){
@@ -1108,6 +1207,7 @@ void ofApp::dragEvent(ofDragInfo dragInfo){
if (imagepaths.size()){
segmenters.clear();
+ shape_selection_durations.clear();
for (auto& path:imagepaths){
path.setPolyWindingMode(OF_POLY_WINDING_ODD);
@@ -1117,12 +1217,31 @@ void ofApp::dragEvent(ofDragInfo dragInfo){
outline.simplify(contour_simplify);
strm << outline.size() << " ";
segmenters.push_back(lineSegmenter(outline));
+ //segmenters.push_back(colourLineSegmenter(outline,path.getStrokeColor()));
+ shape_selection_durations.push_back(0.0f);
}
strm << " , ";
}
+ std::stringstream strom;
+
+ shape_selection.clear();
+ while (shape_selection.size()<(segmenters.size()*shapes_amount)){
+ int selection=(int)ofRandom(0,segmenters.size());
+ shape_selection.insert(selection);
+ }
+ for (auto s:shape_selection){
+ float spawn=(ofRandom(0,(float)shapes_duration));
+ shape_selection_durations[s]=spawn;
+ strom << s << ":"<<spawn<<" ";
+ }
+ last_frame_time=ofGetElapsedTimef();
+ //cout << "SVG: selected paths [ "<<strom.str() << " ]" <<std::endl;
+ //cout << "SVG: found " << imagepaths.size() << " paths with " << segmenters.size() << " shapes [ " << strm.str() << " ]" <<std::endl;
+ //select_random_shapes(shapes_duration);
+
cout << "SVG: found " << imagepaths.size() << " paths with " << segmenters.size() << " shapes [ " << strm.str() << " ]" <<std::endl;
- select_random_shapes();
+ select_random_shapes(shapes_duration);
}
}
diff --git a/passadesgui/src/ofApp.h b/passadesgui/src/ofApp.h
index 24ab46e..92eabbd 100644
--- a/passadesgui/src/ofApp.h
+++ b/passadesgui/src/ofApp.h
@@ -67,7 +67,7 @@ class ofApp: public ofBaseApp, public ofxMidiListener {
void outputMouseReleased(ofMouseEventArgs & args);
void outputWindowResized(ofResizeEventArgs &resizeargs);
- void select_random_shapes();
+ void select_random_shapes(float duration,bool generate);
void default_settings();
void save_settings();
@@ -210,7 +210,9 @@ class ofApp: public ofBaseApp, public ofxMidiListener {
//======================================= //SVG player
ofxSVG svg;
- vector <lineSegmenter> segmenters;
+ vector <lineSegmenter> segmenters; //<colourLineSegmenter> segmenters; //
+ vector <float> shape_selection_durations;
+
set <int> shape_selection;
int framecounter;
float phase,prev_time; //to calculate phase