@@ -58,80 +58,80 @@ void OscSender::newObject(){
5858 PatchObject::setName ( this ->objectName );
5959
6060 this ->setCustomVar (static_cast <float >(osc_port)," PORT" );
61+ this ->setCustomVar (0 .0f ," @" +osc_host);
6162}
6263
6364// --------------------------------------------------------------
6465void OscSender::setupObjectContent (shared_ptr<ofAppGLFWWindow> &mainWindow){
6566
66- if (filepath == " none" ){
67- filepath = osc_host;
68- }
67+ initInlets ();
6968
7069}
7170
7271// --------------------------------------------------------------
7372void OscSender::updateObjectContent (map<int ,shared_ptr<PatchObject>> &patchObjects){
7473
75- for (int i=0 ;i<this ->getNumInlets ();i++){
76- if (this ->inletsConnected [i]){
77- ofxOscMessage m;
78- bool messageOK = false ;
79- m.setAddress (osc_labels.at (i));
80- if (this ->getInletType (i) == VP_LINK_NUMERIC){
81- m.addFloatArg (*(float *)&_inletParams[i]);
82- messageOK = true ;
83- }else if (this ->getInletType (i) == VP_LINK_STRING){
84- m.addStringArg (*static_cast <string *>(_inletParams[i]));
85- messageOK = true ;
86- }else if (this ->getInletType (i) == VP_LINK_ARRAY){
87- for (size_t s=0 ;s<static_cast <size_t >(static_cast <vector<float > *>(_inletParams[i])->size ());s++){
88- m.addFloatArg (static_cast <vector<float > *>(_inletParams[i])->at (s));
89- }
90- messageOK = true ;
91- }else if (this ->getInletType (i) == VP_LINK_TEXTURE && static_cast <ofTexture *>(_inletParams[i])->isAllocated ()){
92- // note: the size of the image depends greatly on your network buffer sizes,
93- // if an image is too big the message won't come through
94- int depth = 1 ;
95- if (static_cast <ofTexture *>(_inletParams[i])->getTextureData ().glInternalFormat == GL_LUMINANCE || static_cast <ofTexture *>(_inletParams[i])->getTextureData ().glInternalFormat == GL_LUMINANCE8 || static_cast <ofTexture *>(_inletParams[i])->getTextureData ().glInternalFormat == GL_LUMINANCE16 || static_cast <ofTexture *>(_inletParams[i])->getTextureData ().glInternalFormat == GL_LUMINANCE32F_ARB){
96- depth = 1 ;
97- }else if (static_cast <ofTexture *>(_inletParams[i])->getTextureData ().glInternalFormat == GL_RGB || static_cast <ofTexture *>(_inletParams[i])->getTextureData ().glInternalFormat == GL_RGB8 || static_cast <ofTexture *>(_inletParams[i])->getTextureData ().glInternalFormat == GL_RGB16 || static_cast <ofTexture *>(_inletParams[i])->getTextureData ().glInternalFormat == GL_RGB32F || static_cast <ofTexture *>(_inletParams[i])->getTextureData ().glInternalFormat == GL_RGB32F_ARB){
98- depth = 3 ;
99- }else if (static_cast <ofTexture *>(_inletParams[i])->getTextureData ().glInternalFormat == GL_RGBA ||static_cast <ofTexture *>(_inletParams[i])->getTextureData ().glInternalFormat == GL_RGBA16 || static_cast <ofTexture *>(_inletParams[i])->getTextureData ().glInternalFormat == GL_RGBA32F_ARB){
100- depth = 4 ;
101- }
102- if (static_cast <ofTexture *>(_inletParams[i])->getWidth ()*static_cast <ofTexture *>(_inletParams[i])->getHeight ()*depth < 922000 ){ // 327680
103- static_cast <ofTexture *>(_inletParams[i])->readToPixels (*_tempPixels);
104- m.addFloatArg (static_cast <ofTexture *>(_inletParams[i])->getWidth ());
105- m.addFloatArg (static_cast <ofTexture *>(_inletParams[i])->getHeight ());
74+ if (loaded){
75+ for (int i=0 ;i<this ->getNumInlets ();i++){
76+ if (this ->inletsConnected [i]){
77+ ofxOscMessage m;
78+ bool messageOK = false ;
79+ m.setAddress (osc_labels.at (i));
80+ if (this ->getInletType (i) == VP_LINK_NUMERIC){
81+ m.addFloatArg (*(float *)&_inletParams[i]);
82+ messageOK = true ;
83+ }else if (this ->getInletType (i) == VP_LINK_STRING){
84+ m.addStringArg (*static_cast <string *>(_inletParams[i]));
85+ messageOK = true ;
86+ }else if (this ->getInletType (i) == VP_LINK_ARRAY){
87+ for (size_t s=0 ;s<static_cast <size_t >(static_cast <vector<float > *>(_inletParams[i])->size ());s++){
88+ m.addFloatArg (static_cast <vector<float > *>(_inletParams[i])->at (s));
89+ }
90+ messageOK = true ;
91+ }else if (this ->getInletType (i) == VP_LINK_TEXTURE && static_cast <ofTexture *>(_inletParams[i])->isAllocated ()){
92+ // note: the size of the image depends greatly on your network buffer sizes,
93+ // if an image is too big the message won't come through
94+ int depth = 1 ;
10695 if (static_cast <ofTexture *>(_inletParams[i])->getTextureData ().glInternalFormat == GL_LUMINANCE || static_cast <ofTexture *>(_inletParams[i])->getTextureData ().glInternalFormat == GL_LUMINANCE8 || static_cast <ofTexture *>(_inletParams[i])->getTextureData ().glInternalFormat == GL_LUMINANCE16 || static_cast <ofTexture *>(_inletParams[i])->getTextureData ().glInternalFormat == GL_LUMINANCE32F_ARB){
107- _tempImage->setFromPixels (_tempPixels->getData (),static_cast <ofTexture *>(_inletParams[i])->getWidth (),static_cast <ofTexture *>(_inletParams[i])->getHeight (),OF_IMAGE_GRAYSCALE);
108- m.addInt32Arg (OF_IMAGE_GRAYSCALE);
96+ depth = 1 ;
10997 }else if (static_cast <ofTexture *>(_inletParams[i])->getTextureData ().glInternalFormat == GL_RGB || static_cast <ofTexture *>(_inletParams[i])->getTextureData ().glInternalFormat == GL_RGB8 || static_cast <ofTexture *>(_inletParams[i])->getTextureData ().glInternalFormat == GL_RGB16 || static_cast <ofTexture *>(_inletParams[i])->getTextureData ().glInternalFormat == GL_RGB32F || static_cast <ofTexture *>(_inletParams[i])->getTextureData ().glInternalFormat == GL_RGB32F_ARB){
110- _tempImage->setFromPixels (_tempPixels->getData (),static_cast <ofTexture *>(_inletParams[i])->getWidth (),static_cast <ofTexture *>(_inletParams[i])->getHeight (),OF_IMAGE_COLOR);
111- m.addInt32Arg (OF_IMAGE_COLOR);
98+ depth = 3 ;
11299 }else if (static_cast <ofTexture *>(_inletParams[i])->getTextureData ().glInternalFormat == GL_RGBA ||static_cast <ofTexture *>(_inletParams[i])->getTextureData ().glInternalFormat == GL_RGBA16 || static_cast <ofTexture *>(_inletParams[i])->getTextureData ().glInternalFormat == GL_RGBA32F_ARB){
113- _tempImage->setFromPixels (_tempPixels->getData (),static_cast <ofTexture *>(_inletParams[i])->getWidth (),static_cast <ofTexture *>(_inletParams[i])->getHeight (),OF_IMAGE_COLOR_ALPHA);
114- m.addInt32Arg (OF_IMAGE_COLOR_ALPHA);
100+ depth = 4 ;
101+ }
102+ if (static_cast <ofTexture *>(_inletParams[i])->getWidth ()*static_cast <ofTexture *>(_inletParams[i])->getHeight ()*depth < 922000 ){ // 327680
103+ static_cast <ofTexture *>(_inletParams[i])->readToPixels (*_tempPixels);
104+ m.addFloatArg (static_cast <ofTexture *>(_inletParams[i])->getWidth ());
105+ m.addFloatArg (static_cast <ofTexture *>(_inletParams[i])->getHeight ());
106+ if (static_cast <ofTexture *>(_inletParams[i])->getTextureData ().glInternalFormat == GL_LUMINANCE || static_cast <ofTexture *>(_inletParams[i])->getTextureData ().glInternalFormat == GL_LUMINANCE8 || static_cast <ofTexture *>(_inletParams[i])->getTextureData ().glInternalFormat == GL_LUMINANCE16 || static_cast <ofTexture *>(_inletParams[i])->getTextureData ().glInternalFormat == GL_LUMINANCE32F_ARB){
107+ _tempImage->setFromPixels (_tempPixels->getData (),static_cast <ofTexture *>(_inletParams[i])->getWidth (),static_cast <ofTexture *>(_inletParams[i])->getHeight (),OF_IMAGE_GRAYSCALE);
108+ m.addInt32Arg (OF_IMAGE_GRAYSCALE);
109+ }else if (static_cast <ofTexture *>(_inletParams[i])->getTextureData ().glInternalFormat == GL_RGB || static_cast <ofTexture *>(_inletParams[i])->getTextureData ().glInternalFormat == GL_RGB8 || static_cast <ofTexture *>(_inletParams[i])->getTextureData ().glInternalFormat == GL_RGB16 || static_cast <ofTexture *>(_inletParams[i])->getTextureData ().glInternalFormat == GL_RGB32F || static_cast <ofTexture *>(_inletParams[i])->getTextureData ().glInternalFormat == GL_RGB32F_ARB){
110+ _tempImage->setFromPixels (_tempPixels->getData (),static_cast <ofTexture *>(_inletParams[i])->getWidth (),static_cast <ofTexture *>(_inletParams[i])->getHeight (),OF_IMAGE_COLOR);
111+ m.addInt32Arg (OF_IMAGE_COLOR);
112+ }else if (static_cast <ofTexture *>(_inletParams[i])->getTextureData ().glInternalFormat == GL_RGBA ||static_cast <ofTexture *>(_inletParams[i])->getTextureData ().glInternalFormat == GL_RGBA16 || static_cast <ofTexture *>(_inletParams[i])->getTextureData ().glInternalFormat == GL_RGBA32F_ARB){
113+ _tempImage->setFromPixels (_tempPixels->getData (),static_cast <ofTexture *>(_inletParams[i])->getWidth (),static_cast <ofTexture *>(_inletParams[i])->getHeight (),OF_IMAGE_COLOR_ALPHA);
114+ m.addInt32Arg (OF_IMAGE_COLOR_ALPHA);
115+ }
116+ _tempImage->save (*_tempBuffer);
117+ m.addBlobArg (*_tempBuffer);
118+ _tempBuffer->clear ();
119+ messageOK = true ;
120+ }else {
121+ ofLog (OF_LOG_ERROR," The image you're trying to send via OSC is too big! Please choose an image below 1280x720 GRAYSCALE, or 640x480 RGB, or 640x360 RGBA" );
115122 }
116- _tempImage->save (*_tempBuffer);
117- m.addBlobArg (*_tempBuffer);
118- _tempBuffer->clear ();
119- messageOK = true ;
120- }else {
121- ofLog (OF_LOG_ERROR," The image you're trying to send via OSC is too big! Please choose an image below 1280x720 GRAYSCALE, or 640x480 RGB, or 640x360 RGBA" );
122123 }
123- }
124- if (messageOK){
125- osc_sender. sendMessage (m, false );
124+ if (messageOK){
125+ osc_sender. sendMessage (m, false );
126+ }
126127 }
127128 }
128129 }
129130
130131 if (!loaded){
131132 loaded = true ;
132- initInlets ();
133133
134- osc_host = filepath ;
134+ osc_host = getHostFromConfig () ;
135135 osc_port = static_cast <int >(floor (this ->getCustomVar (" PORT" )));
136136 osc_port_string = ofToString (osc_port);
137137 osc_sender.setup (osc_host.c_str (),osc_port);
@@ -157,7 +157,9 @@ void OscSender::drawObjectNodeGui( ImGuiEx::NodeCanvas& _nodeCanvas ){
157157 if (ImGui::BeginMenu (" CONFIG" ))
158158 {
159159
160- drawObjectNodeConfig ();
160+ if (loaded){
161+ drawObjectNodeConfig ();
162+ }
161163
162164
163165 ImGui::EndMenu ();
@@ -173,6 +175,7 @@ void OscSender::drawObjectNodeGui( ImGuiEx::NodeCanvas& _nodeCanvas ){
173175 ImGui::PushItemWidth (80 *scaleFactor);
174176 if (ImGui::InputText (" HOST" ,&osc_host)){
175177 filepath = osc_host;
178+ this ->saveConfig (false );
176179 }
177180 ImGui::Spacing ();
178181 if (ImGui::InputText (" PORT" ,&osc_port_string)){
@@ -370,6 +373,34 @@ void OscSender::initInlets(){
370373 this ->initInletsState ();
371374}
372375
376+ // --------------------------------------------------------------
377+ string OscSender::getHostFromConfig (){
378+
379+ ofxXmlSettings XML;
380+ if (XML.loadFile (this ->patchFile )){
381+ int totalObjects = XML.getNumTags (" object" );
382+
383+ // Get object inlets config
384+ for (int i=0 ;i<totalObjects;i++){
385+ if (XML.pushTag (" object" , i)){
386+ if (XML.getValue (" id" , -1 ) == this ->nId ){
387+ string temp = XML.getValue (" filepath" ," none" );
388+
389+ size_t found = temp.find_last_of (" /" );
390+ if (found != string::npos){
391+ return temp.substr (found+1 );
392+ }else {
393+ return temp;
394+ }
395+ }
396+ XML.popTag ();
397+ }
398+ }
399+ }
400+
401+ return " localhost" ;
402+ }
403+
373404
374405OBJECT_REGISTER ( OscSender, " osc sender" , OFXVP_OBJECT_CAT_COMMUNICATIONS)
375406
0 commit comments