Skip to content

Commit a78b793

Browse files
committed
added string object category plus a basic bunch of objects
1 parent 1a6832f commit a78b793

File tree

12 files changed

+1712
-0
lines changed

12 files changed

+1712
-0
lines changed
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
/*==============================================================================
2+
3+
ofxVisualProgramming: A visual programming patching environment for OF
4+
5+
Copyright (c) 2018 Emanuele Mazza aka n3m3da <[email protected]>
6+
7+
ofxVisualProgramming is distributed under the MIT License.
8+
This gives everyone the freedoms to use ofxVisualProgramming in any context:
9+
commercial or non-commercial, public or private, open or closed source.
10+
11+
Permission is hereby granted, free of charge, to any person obtaining a
12+
copy of this software and associated documentation files (the "Software"),
13+
to deal in the Software without restriction, including without limitation
14+
the rights to use, copy, modify, merge, publish, distribute, sublicense,
15+
and/or sell copies of the Software, and to permit persons to whom the
16+
Software is furnished to do so, subject to the following conditions:
17+
18+
The above copyright notice and this permission notice shall be included
19+
in all copies or substantial portions of the Software.
20+
21+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
22+
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27+
DEALINGS IN THE SOFTWARE.
28+
29+
See https://github.com/d3cod3/ofxVisualProgramming for documentation
30+
31+
==============================================================================*/
32+
33+
#ifndef OFXVP_BUILD_WITH_MINIMAL_OBJECTS
34+
35+
#include "RandomString.h"
36+
37+
//--------------------------------------------------------------
38+
RandomString::RandomString() : PatchObject("random string")
39+
{
40+
41+
this->numInlets = 2;
42+
this->numOutlets = 1;
43+
44+
_inletParams[0] = new float(); // bang
45+
*(float *)&_inletParams[0] = 0.0f;
46+
47+
_inletParams[1] = new float(); // length
48+
*(float *)&_inletParams[1] = 1.0f;
49+
50+
_outletParams[0] = new string(); // random string
51+
*static_cast<string *>(_outletParams[0]) = "";
52+
53+
this->initInletsState();
54+
55+
bang = false;
56+
57+
length = 1;
58+
59+
loaded = false;
60+
61+
this->height /= 2.0f;
62+
63+
}
64+
65+
//--------------------------------------------------------------
66+
void RandomString::newObject(){
67+
PatchObject::setName( this->objectName );
68+
69+
this->addInlet(VP_LINK_NUMERIC,"bang");
70+
this->addInlet(VP_LINK_NUMERIC,"length");
71+
this->addOutlet(VP_LINK_STRING,"randomString");
72+
73+
this->setCustomVar(length,"LENGTH");
74+
75+
}
76+
77+
//--------------------------------------------------------------
78+
void RandomString::setupObjectContent(shared_ptr<ofAppGLFWWindow> &mainWindow){
79+
80+
}
81+
82+
//--------------------------------------------------------------
83+
void RandomString::updateObjectContent(map<int,shared_ptr<PatchObject>> &patchObjects){
84+
if(this->inletsConnected[0]){
85+
if(*(float *)&_inletParams[0] < 1.0){
86+
bang = false;
87+
}else{
88+
bang = true;
89+
}
90+
}
91+
if(bang){
92+
*static_cast<string *>(_outletParams[0]) = random_string(static_cast<size_t>(floor(length)));
93+
}
94+
95+
if(this->inletsConnected[1]){
96+
length = abs(static_cast<int>(floor(*(float *)&_inletParams[1])));
97+
}
98+
99+
if(!loaded){
100+
loaded = true;
101+
length = this->getCustomVar("LENGTH");
102+
}
103+
}
104+
105+
//--------------------------------------------------------------
106+
void RandomString::drawObjectContent(ofxFontStash *font, shared_ptr<ofBaseGLRenderer>& glRenderer){
107+
ofSetColor(255);
108+
}
109+
110+
//--------------------------------------------------------------
111+
void RandomString::drawObjectNodeGui( ImGuiEx::NodeCanvas& _nodeCanvas ){
112+
113+
// CONFIG GUI inside Menu
114+
if(_nodeCanvas.BeginNodeMenu()){
115+
116+
ImGui::Separator();
117+
ImGui::Separator();
118+
ImGui::Separator();
119+
120+
if (ImGui::BeginMenu("CONFIG"))
121+
{
122+
123+
drawObjectNodeConfig();
124+
125+
ImGui::EndMenu();
126+
}
127+
128+
_nodeCanvas.EndNodeMenu();
129+
}
130+
131+
// Visualize (Object main view)
132+
if( _nodeCanvas.BeginNodeContent(ImGuiExNodeView_Visualise) ){
133+
134+
135+
136+
_nodeCanvas.EndNodeContent();
137+
}
138+
}
139+
140+
//--------------------------------------------------------------
141+
void RandomString::drawObjectNodeConfig(){
142+
ImGui::Spacing();
143+
ImGui::PushItemWidth(130*scaleFactor);
144+
if(ImGui::DragInt("string length", &length)){
145+
if(length < 1){
146+
length = 1;
147+
}
148+
this->setCustomVar(length,"LENGTH");
149+
}
150+
151+
ImGuiEx::ObjectInfo(
152+
"Random string generator.",
153+
"https://mosaic.d3cod3.org/reference.php?r=random-string", scaleFactor);
154+
}
155+
156+
//--------------------------------------------------------------
157+
void RandomString::removeObjectContent(bool removeFileFromData){
158+
159+
}
160+
161+
162+
163+
OBJECT_REGISTER( RandomString, "random string", OFXVP_OBJECT_CAT_STRING)
164+
165+
#endif

src/objects/string/RandomString.h

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*==============================================================================
2+
3+
ofxVisualProgramming: A visual programming patching environment for OF
4+
5+
Copyright (c) 2020 Emanuele Mazza aka n3m3da <[email protected]>
6+
7+
ofxVisualProgramming is distributed under the MIT License.
8+
This gives everyone the freedoms to use ofxVisualProgramming in any context:
9+
commercial or non-commercial, public or private, open or closed source.
10+
11+
Permission is hereby granted, free of charge, to any person obtaining a
12+
copy of this software and associated documentation files (the "Software"),
13+
to deal in the Software without restriction, including without limitation
14+
the rights to use, copy, modify, merge, publish, distribute, sublicense,
15+
and/or sell copies of the Software, and to permit persons to whom the
16+
Software is furnished to do so, subject to the following conditions:
17+
18+
The above copyright notice and this permission notice shall be included
19+
in all copies or substantial portions of the Software.
20+
21+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
22+
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27+
DEALINGS IN THE SOFTWARE.
28+
29+
See https://github.com/d3cod3/ofxVisualProgramming for documentation
30+
31+
==============================================================================*/
32+
33+
#ifndef OFXVP_BUILD_WITH_MINIMAL_OBJECTS
34+
35+
#pragma once
36+
37+
#include "PatchObject.h"
38+
39+
40+
class RandomString : public PatchObject {
41+
42+
public:
43+
44+
RandomString();
45+
46+
void newObject() override;
47+
void setupObjectContent(shared_ptr<ofAppGLFWWindow> &mainWindow) override;
48+
void updateObjectContent(map<int,shared_ptr<PatchObject>> &patchObjects) override;
49+
50+
void drawObjectContent(ofxFontStash *font, shared_ptr<ofBaseGLRenderer>& glRenderer) override;
51+
void drawObjectNodeGui( ImGuiEx::NodeCanvas& _nodeCanvas ) override;
52+
void drawObjectNodeConfig() override;
53+
54+
void removeObjectContent(bool removeFileFromData=false) override;
55+
56+
bool bang;
57+
int length;
58+
59+
bool loaded;
60+
61+
62+
private:
63+
64+
OBJECT_FACTORY_PROPS
65+
};
66+
67+
#endif

src/objects/string/StringAt.cpp

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
/*==============================================================================
2+
3+
ofxVisualProgramming: A visual programming patching environment for OF
4+
5+
Copyright (c) 2018 Emanuele Mazza aka n3m3da <[email protected]>
6+
7+
ofxVisualProgramming is distributed under the MIT License.
8+
This gives everyone the freedoms to use ofxVisualProgramming in any context:
9+
commercial or non-commercial, public or private, open or closed source.
10+
11+
Permission is hereby granted, free of charge, to any person obtaining a
12+
copy of this software and associated documentation files (the "Software"),
13+
to deal in the Software without restriction, including without limitation
14+
the rights to use, copy, modify, merge, publish, distribute, sublicense,
15+
and/or sell copies of the Software, and to permit persons to whom the
16+
Software is furnished to do so, subject to the following conditions:
17+
18+
The above copyright notice and this permission notice shall be included
19+
in all copies or substantial portions of the Software.
20+
21+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
22+
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27+
DEALINGS IN THE SOFTWARE.
28+
29+
See https://github.com/d3cod3/ofxVisualProgramming for documentation
30+
31+
==============================================================================*/
32+
33+
#ifndef OFXVP_BUILD_WITH_MINIMAL_OBJECTS
34+
35+
#include "StringAt.h"
36+
37+
//--------------------------------------------------------------
38+
StringAt::StringAt() : PatchObject("string at"){
39+
40+
this->numInlets = 2;
41+
this->numOutlets = 1;
42+
43+
_inletParams[0] = new string(); // input string
44+
*static_cast<string *>(_inletParams[0]) = "";
45+
_inletParams[1] = new float(); // at
46+
*(float *)&_inletParams[1] = 0.0f;
47+
48+
_outletParams[0] = new string(); // char
49+
*static_cast<string *>(_outletParams[0]) = "";
50+
51+
this->initInletsState();
52+
53+
stringAt = 0;
54+
loaded = false;
55+
56+
}
57+
58+
//--------------------------------------------------------------
59+
void StringAt::newObject(){
60+
PatchObject::setName( this->objectName );
61+
62+
this->addInlet(VP_LINK_STRING,"string");
63+
this->addInlet(VP_LINK_NUMERIC,"at");
64+
65+
this->addOutlet(VP_LINK_STRING,"char");
66+
67+
this->setCustomVar(static_cast<float>(stringAt),"AT");
68+
}
69+
70+
//--------------------------------------------------------------
71+
void StringAt::setupObjectContent(shared_ptr<ofAppGLFWWindow> &mainWindow){
72+
73+
}
74+
75+
//--------------------------------------------------------------
76+
void StringAt::updateObjectContent(map<int,shared_ptr<PatchObject>> &patchObjects){
77+
78+
79+
if(this->inletsConnected[1]){
80+
stringAt = static_cast<int>(floor(*(float *)&_inletParams[1]));
81+
}
82+
83+
if(this->inletsConnected[0]){
84+
if(stringAt >= 0 && stringAt < static_cast<string *>(_inletParams[0])->size()){
85+
string s(1,static_cast<string *>(_inletParams[0])->at(stringAt));
86+
*static_cast<string *>(_outletParams[0]) = s;
87+
}else{
88+
*static_cast<string *>(_outletParams[0]) = "";
89+
}
90+
}else{
91+
*static_cast<string *>(_outletParams[0]) = "";
92+
}
93+
94+
if(!loaded){
95+
loaded = true;
96+
stringAt = static_cast<int>(floor(this->getCustomVar("AT")));
97+
}
98+
99+
}
100+
101+
//--------------------------------------------------------------
102+
void StringAt::drawObjectContent(ofxFontStash *font, shared_ptr<ofBaseGLRenderer>& glRenderer){
103+
ofSetColor(255);
104+
105+
}
106+
107+
//--------------------------------------------------------------
108+
void StringAt::drawObjectNodeGui( ImGuiEx::NodeCanvas& _nodeCanvas ){
109+
110+
// CONFIG GUI inside Menu
111+
if(_nodeCanvas.BeginNodeMenu()){
112+
113+
ImGui::Separator();
114+
ImGui::Separator();
115+
ImGui::Separator();
116+
117+
if (ImGui::BeginMenu("CONFIG"))
118+
{
119+
120+
drawObjectNodeConfig();
121+
122+
ImGui::EndMenu();
123+
}
124+
125+
_nodeCanvas.EndNodeMenu();
126+
}
127+
128+
// Visualize (Object main view)
129+
if( _nodeCanvas.BeginNodeContent(ImGuiExNodeView_Visualise) ){
130+
131+
ImGui::Dummy(ImVec2(-1,ImGui::GetWindowSize().y/2 - (26*scaleFactor))); // Padding top
132+
ImGui::PushItemWidth(-1);
133+
if(ImGui::DragInt("", &stringAt)){
134+
if(stringAt < 0){
135+
stringAt = 0;
136+
}
137+
this->setCustomVar(static_cast<float>(stringAt),"AT");
138+
}
139+
ImGui::Spacing();
140+
ImGui::Text("string[%i] = %s", stringAt,static_cast<string *>(_outletParams[0])->c_str());
141+
ImGui::PopItemWidth();
142+
143+
_nodeCanvas.EndNodeContent();
144+
}
145+
146+
}
147+
148+
//--------------------------------------------------------------
149+
void StringAt::drawObjectNodeConfig(){
150+
ImGuiEx::ObjectInfo(
151+
"Extracts the char at a particular position from a string",
152+
"https://mosaic.d3cod3.org/reference.php?r=vector-at", scaleFactor);
153+
}
154+
155+
//--------------------------------------------------------------
156+
void StringAt::removeObjectContent(bool removeFileFromData){
157+
158+
}
159+
160+
161+
OBJECT_REGISTER( StringAt, "string at", OFXVP_OBJECT_CAT_STRING)
162+
163+
#endif

0 commit comments

Comments
 (0)