Skip to content

Commit 2aca83c

Browse files
committed
added code structure for subpatching capabilities
1 parent 6ff3fb7 commit 2aca83c

File tree

4 files changed

+75
-57
lines changed

4 files changed

+75
-57
lines changed

src/PatchObject.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,16 @@
3434

3535
//--------------------------------------------------------------
3636
PatchObject::PatchObject(const std::string& _customUID ) : ofxVPHasUID(_customUID) {
37-
nId = -1;
38-
name = "none";
39-
filepath = "none";
40-
patchFile = "";
41-
patchFolderPath = "";
37+
nId = -1;
38+
name = "none";
39+
filepath = "none";
40+
patchFile = "";
41+
patchFolderPath = "";
4242

4343
specialLinkTypeName = "";
4444

45+
subpatchName = "root";
46+
4547
numInlets = 0;
4648
numOutlets = 0;
4749

@@ -511,6 +513,7 @@ bool PatchObject::loadConfig(shared_ptr<ofAppGLFWWindow> &mainWindow, pdsp::Engi
511513
nId = XML.getValue("id", 0);
512514
name = XML.getValue("name","none");
513515
filepath = XML.getValue("filepath","none");
516+
subpatchName = XML.getValue("subpatch","root");
514517

515518
move(XML.getValue("position:x", 0),XML.getValue("position:y", 0));
516519

@@ -601,6 +604,8 @@ bool PatchObject::saveConfig(bool newConnection){
601604
XML.setValue("name",name);
602605
XML.addTag("filepath");
603606
XML.setValue("filepath",filepath);
607+
XML.addTag("subpatch");
608+
XML.setValue("subpatch",subpatchName);
604609
XML.addTag("position");
605610
XML.setValue("position:x",static_cast<double>(x));
606611
XML.setValue("position:y",static_cast<double>(y));
@@ -656,6 +661,7 @@ bool PatchObject::saveConfig(bool newConnection){
656661
if(XML.pushTag("object", i)){
657662
if(XML.getValue("id", -1) == nId){
658663
XML.setValue("filepath",filepath);
664+
XML.setValue("subpatch",subpatchName);
659665
XML.setValue("position:x",static_cast<double>(x));
660666
XML.setValue("position:y",static_cast<double>(y));
661667

src/PatchObject.h

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ class PatchObject : public ofxVPHasUID {
185185
void setWillErase(bool e) { willErase = e; }
186186
void setIsObjectSelected(bool s) { isObjectSelected = s; }
187187
void setConfigmenuWidth(float cmw) { configMenuWidth = cmw; }
188+
void setSubpatch(string sp) { subpatchName = sp; }
188189

189190
// PUGG Plugin System
190191
static const int version = 1;
@@ -196,18 +197,24 @@ class PatchObject : public ofxVPHasUID {
196197
vector<int> objectsSelected;
197198
vector<bool> inletsConnected;
198199

200+
// subpatch vars
201+
string subpatchName;
202+
203+
// inlets/outlets
199204
void *_inletParams[MAX_INLETS];
200205
void *_outletParams[MAX_OUTLETS];
201206

207+
// PDSP nodes
202208
map<int,pdsp::PatchNode> pdspIn;
203209
map<int,pdsp::PatchNode> pdspOut;
204210

205-
ofEvent<int> resetEvent;
206-
ofEvent<int> removeEvent;
207-
ofEvent<int> reconnectOutletsEvent;
208-
ofEvent<int> duplicateEvent;
211+
// events
212+
ofEvent<int> resetEvent;
213+
ofEvent<int> removeEvent;
214+
ofEvent<int> reconnectOutletsEvent;
215+
ofEvent<int> duplicateEvent;
209216

210-
string specialLinkTypeName;
217+
string specialLinkTypeName;
211218

212219
protected:
213220

src/ofxVisualProgramming.cpp

Lines changed: 38 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ ofxVisualProgramming::ofxVisualProgramming(){
6868
currentPatchFile = "empty_patch.xml";
6969
currentPatchFolderPath = ofToDataPath("temp/");
7070

71+
currentSubpatch = "root";
72+
73+
vector<string> rootBranch;
74+
subpatchesTree[currentSubpatch] = rootBranch;
75+
7176
resetTime = ofGetElapsedTimeMillis();
7277
wait = 2000;
7378

@@ -175,12 +180,6 @@ void ofxVisualProgramming::update(){
175180
}
176181
}
177182

178-
// Sound Context
179-
/*unique_lock<std::mutex> lock(inputAudioMutex);
180-
{
181-
182-
}*/
183-
184183
// Clear map from deleted objects
185184
clearObjectsMap();
186185

@@ -198,20 +197,22 @@ void ofxVisualProgramming::update(){
198197
ImGuiEx::ProfilerTask *pt = new ImGuiEx::ProfilerTask[leftToRightIndexOrder.size()];
199198

200199
for(unsigned int i=0;i<leftToRightIndexOrder.size();i++){
201-
pt[i].color = profiler.cpuGraph.colors[static_cast<unsigned int>(i%16)];
202-
pt[i].startTime = ofGetElapsedTimef();
203-
pt[i].name = patchObjects[leftToRightIndexOrder[i].second]->getName()+ofToString(patchObjects[leftToRightIndexOrder[i].second]->getId())+"_update";
204-
patchObjects[leftToRightIndexOrder[i].second]->update(patchObjects,*engine);
205-
pt[i].endTime = ofGetElapsedTimef();
206-
207-
// update scripts objects files map
208-
ofFile tempsofp(patchObjects[leftToRightIndexOrder[i].second]->getFilepath());
209-
string fileExt = ofToUpper(tempsofp.getExtension());
210-
if(fileExt == "LUA" || fileExt == "PY" || fileExt == "SH" || fileExt == "FRAG"){
211-
map<string,string>::iterator sofpIT = scriptsObjectsFilesPaths.find(tempsofp.getFileName());
212-
if (sofpIT == scriptsObjectsFilesPaths.end()){
213-
// not found, insert it
214-
scriptsObjectsFilesPaths.insert( pair<string,string>(tempsofp.getFileName(),tempsofp.getAbsolutePath()) );
200+
if(patchObjects[leftToRightIndexOrder[i].second]->subpatchName == currentSubpatch){
201+
pt[i].color = profiler.cpuGraph.colors[static_cast<unsigned int>(i%16)];
202+
pt[i].startTime = ofGetElapsedTimef();
203+
pt[i].name = patchObjects[leftToRightIndexOrder[i].second]->getName()+ofToString(patchObjects[leftToRightIndexOrder[i].second]->getId())+"_update";
204+
patchObjects[leftToRightIndexOrder[i].second]->update(patchObjects,*engine);
205+
pt[i].endTime = ofGetElapsedTimef();
206+
207+
// update scripts objects files map
208+
ofFile tempsofp(patchObjects[leftToRightIndexOrder[i].second]->getFilepath());
209+
string fileExt = ofToUpper(tempsofp.getExtension());
210+
if(fileExt == "LUA" || fileExt == "PY" || fileExt == "SH" || fileExt == "FRAG"){
211+
map<string,string>::iterator sofpIT = scriptsObjectsFilesPaths.find(tempsofp.getFileName());
212+
if (sofpIT == scriptsObjectsFilesPaths.end()){
213+
// not found, insert it
214+
scriptsObjectsFilesPaths.insert( pair<string,string>(tempsofp.getFileName(),tempsofp.getAbsolutePath()) );
215+
}
215216
}
216217
}
217218
}
@@ -294,22 +295,24 @@ void ofxVisualProgramming::draw(){
294295
ImGuiEx::ProfilerTask *pt = new ImGuiEx::ProfilerTask[leftToRightIndexOrder.size()];
295296
for(unsigned int i=0;i<leftToRightIndexOrder.size();i++){
296297

297-
pt[i].color = profiler.gpuGraph.colors[static_cast<unsigned int>(i%16)];
298-
pt[i].startTime = ofGetElapsedTimef();
299-
pt[i].name = patchObjects[leftToRightIndexOrder[i].second]->getName()+ofToString(patchObjects[leftToRightIndexOrder[i].second]->getId())+"_draw";
298+
if(patchObjects[leftToRightIndexOrder[i].second]->subpatchName == currentSubpatch){
299+
pt[i].color = profiler.gpuGraph.colors[static_cast<unsigned int>(i%16)];
300+
pt[i].startTime = ofGetElapsedTimef();
301+
pt[i].name = patchObjects[leftToRightIndexOrder[i].second]->getName()+ofToString(patchObjects[leftToRightIndexOrder[i].second]->getId())+"_draw";
300302

301-
// LivePatchingObject hack, should not be handled by mosaic.
302-
if(patchObjects[leftToRightIndexOrder[i].second]->getName() == "live patching"){
303-
livePatchingObiID = patchObjects[leftToRightIndexOrder[i].second]->getId();
304-
}
303+
// LivePatchingObject hack, should not be handled by mosaic.
304+
if(patchObjects[leftToRightIndexOrder[i].second]->getName() == "live patching"){
305+
livePatchingObiID = patchObjects[leftToRightIndexOrder[i].second]->getId();
306+
}
305307

306-
// Draw
307-
patchObjects[leftToRightIndexOrder[i].second]->draw(font);
308-
if(isCanvasVisible){
309-
patchObjects[leftToRightIndexOrder[i].second]->drawImGuiNode(nodeCanvas,patchObjects);
310-
}
308+
// Draw
309+
patchObjects[leftToRightIndexOrder[i].second]->draw(font);
310+
if(isCanvasVisible){
311+
patchObjects[leftToRightIndexOrder[i].second]->drawImGuiNode(nodeCanvas,patchObjects);
312+
}
311313

312-
pt[i].endTime = ofGetElapsedTimef();
314+
pt[i].endTime = ofGetElapsedTimef();
315+
}
313316

314317
}
315318

@@ -374,7 +377,7 @@ void ofxVisualProgramming::drawInspector(){
374377

375378
//--------------------------------------------------------------
376379
void ofxVisualProgramming::drawLivePatchingSession(){
377-
if(weAlreadyHaveObject("live patching") && livePatchingObiID != -1){
380+
if(weAlreadyHaveObject("live patching") && livePatchingObiID != -1 && currentSubpatch == "root"){
378381
if(patchObjects[livePatchingObiID]->inletsConnected[0] && static_cast<ofTexture *>(patchObjects[livePatchingObiID]->_inletParams[0])->isAllocated()){
379382
float lpDrawW, lpDrawH, lpPosX, lpPosY;
380383
if(static_cast<ofTexture *>(patchObjects[livePatchingObiID]->_inletParams[0])->getWidth() >= static_cast<ofTexture *>(patchObjects[livePatchingObiID]->_inletParams[0])->getHeight()){ // horizontal texture
@@ -596,6 +599,7 @@ void ofxVisualProgramming::addObject(string name,ofVec2f pos){
596599
tempObj->setupDSP(*engine);
597600
tempObj->move(static_cast<int>(pos.x-(OBJECT_STANDARD_WIDTH/2*scaleFactor)),static_cast<int>(pos.y-(OBJECT_STANDARD_HEIGHT/2*scaleFactor)));
598601
tempObj->setIsRetina(isRetina);
602+
tempObj->setSubpatch(currentSubpatch);
599603
ofAddListener(tempObj->removeEvent ,this,&ofxVisualProgramming::removeObject);
600604
ofAddListener(tempObj->resetEvent ,this,&ofxVisualProgramming::resetObject);
601605
ofAddListener(tempObj->reconnectOutletsEvent ,this,&ofxVisualProgramming::reconnectObjectOutlets);
@@ -1283,9 +1287,7 @@ void ofxVisualProgramming::loadPatch(string patchFile){
12831287

12841288
shared_ptr<PatchObject> tempObj = selectObject(objname);
12851289
if(tempObj != nullptr){
1286-
ofLog(OF_LOG_NOTICE,"BEFORE LOADING OBJECT CONFIG....");
12871290
loaded = tempObj->loadConfig(mainWindow,*engine,i,patchFile);
1288-
ofLog(OF_LOG_NOTICE,"AFTER LOADING OBJECT CONFIG....");
12891291
if(loaded){
12901292
tempObj->setPatchfile(currentPatchFile);
12911293
tempObj->setIsRetina(isRetina);

src/ofxVisualProgramming.h

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -134,17 +134,20 @@ class ofxVisualProgramming : public pdsp::Wrapper {
134134
pugg::Kernel plugins_kernel;
135135

136136
// PATCH OBJECTS
137-
map<int,shared_ptr<PatchObject>> patchObjects;
138-
map<string,string> scriptsObjectsFilesPaths;
139-
vector<pair<int,int>> leftToRightIndexOrder;
140-
vector<int> eraseIndexes;
141-
142-
int selectedObjectID;
143-
int actualObjectID;
144-
int lastAddedObjectID;
145-
bool bLoadingNewObject;
146-
bool bLoadingNewPatch;
147-
bool clearingObjectsMap;
137+
map<int,shared_ptr<PatchObject>> patchObjects;
138+
map<string,string> scriptsObjectsFilesPaths;
139+
vector<pair<int,int>> leftToRightIndexOrder;
140+
vector<int> eraseIndexes;
141+
142+
map<string,vector<string>> subpatchesTree;
143+
string currentSubpatch;
144+
145+
int selectedObjectID;
146+
int actualObjectID;
147+
int lastAddedObjectID;
148+
bool bLoadingNewObject;
149+
bool bLoadingNewPatch;
150+
bool clearingObjectsMap;
148151

149152
// LOAD/SAVE
150153
string currentPatchFile;

0 commit comments

Comments
 (0)