[solved] Can I use the value sent from Pd as float or bool using ofxPd

Can I use the value sent from Pd as float or bool using ofxPd?
Even looking at PdExample, it looks just like displaying it on the console.

I’m sorry if I misunderstand

Do I have to use osc?

Hi, can you show some code? How are you sending and receiving the data?

In this example https://github.com/danomatika/ofxPd/blob/master/pdExample/src/ofApp.cpp there’s a receiveFloat() method in which the value is actually a float… is that what you’re using?

Hi, thanks for your replying.

Here is the code. And Pd’ SS.
I’m attempting to implement simple step sequencer. oF has gui and control Pd’s logic.
First of all, I’m trying to display a number from Pd with ofDrawBitmapString etc…

class ofApp : public ofBaseApp, public PdReceiver {
    
    ofxPd pd;
    float value = 0;
    
    //--------------------------------------------------------------
    void setup()
    {
        
        if(!pd.init(2, 1, 44100))
        {
            OF_EXIT_APP(1);
        }
        
        pd.subscribe("FromPD");
        pd.addReceiver(*this);
        
        Patch patch = pd.openPatch("puredata/simple_stepsequencer.pd");
        pd.start();
    }
    
    //--------------------------------------------------------------
    void update()
    {
        
        if(pd.isQueued()) {
            // process any received messages, if you're using the queue and *do not*
            // call these, you won't receieve any messages or midi!
            pd.receiveMessages();
        }
    }
    
    //--------------------------------------------------------------
    void draw()
    {
        ofBackground(0);
        
        ofSetColor(255);
        ofDrawBitmapString("FromPD"+ofToString(value), 20, 20);
    }
    
    //--------------------------------------------------------------
    void audioReceived(float * input, int bufferSize, int nChannels) {
        pd.audioIn(input, bufferSize, nChannels);
    }
    
    //--------------------------------------------------------------
    void audioRequested(float * output, int bufferSize, int nChannels) {
        pd.audioOut(output, bufferSize, nChannels);
    }
    
    //--------------------------------------------------------------
    void print(const std::string& message) {
        cout << message << endl;
    }
    
    //--------------------------------------------------------------
    void receiveBang(const std::string& dest) {
        cout << "OF: bang " << dest << endl;
    }
    
    void receiveFloat(const std::string& dest, float value) {
        cout << "OF: float " << dest << ": " << value << endl;
    }
    
    void receiveSymbol(const std::string& dest, const std::string& symbol) {
        cout << "OF: symbol " << dest << ": " << symbol << endl;
    }
    
    void receiveList(const std::string& dest, const List& list) {
        cout << "OF: list " << dest << ": ";
        
        // step through the list
        for(int i = 0; i < list.len(); ++i) {
            if(list.isFloat(i))
                cout << list.getFloat(i) << " ";
            else if(list.isSymbol(i))
                cout << list.getSymbol(i) << " ";
        }
        
        // you can also use the built in toString function or simply stream it out
        // cout << list.toString();
        // cout << list;
        
        // print an OSC-style type string
        cout << list.types() << endl;
    }
    
    void receiveMessage(const std::string& dest, const std::string& msg, const List& list) {
        cout << "OF: message " << dest << ": " << msg << " " << list.toString() << list.types() << endl;
    }
};

Do you receive float values from pd?

If you do, you will see something like “OF: float FromPD: 3” in the console.

Then you can use the received float value in void receiveFloat() method.

I just realized it was very very easy…
Thank you! :slight_smile:

float count = 0;
void draw()
{
    ofBackground(0);
    
    ofSetColor(255);
    ofDrawBitmapString("FromPD : "+ofToString(count), 20, 20);
}

void receiveFloat(const std::string& dest, float value) {
    cout << "OF: float " << dest << ": " << value << endl;
    
    if(dest == "FromPD") count = value;
}