danomatika / ofxPd

(maintained) a Pure Data addon for OpenFrameworks using libpd
Other
202 stars 45 forks source link

After closePatch() call the sound is still running #69

Closed d3cod3 closed 5 years ago

d3cod3 commented 5 years ago

Hi, i'm having trouble with closing patches, i'm testing it on macOS and when trying to close a patch and opening another, the first one is not closing (still sound) and both of them are running.

Basically i'm calling pd.init() in setup, then i'm testing the patch loading with an ofFileDialogResult, select the file, storing in a Patch variable, calling pd.openPatch() and everything is fine, then when i call pd.closePatch() the sound from the closed patch is still ON and when i open a new one they overlap (i'm trying with a simple sine on one patch and a noise on another).

In short:


ofxPd               pd;
Patch               currentPatch;
ofFile               currentPatchFile;

void ofApp::setup(){
    //..........
    pd.init(1,1,sampleRate,8,false);
    pd.addReceiver(*this);
    pd.addMidiReceiver(*this);
    //..........
}

//...........

void ofApp::keyPressed(int key){
    if(key == 'n'){
        ofFileDialogResult openFileResult= ofSystemLoadDialog("Select a PD patch");
        if (openFileResult.bSuccess){
            ofFile file (openFileResult.getPath());
            if (file.exists()){
                // if we have a previous patch opened, close it first
                if(currentPatchFile.exists()){
                    currentPatch.clear();
                    pd.closePatch(currentPatchFile.getAbsolutePath());
                    pd.clearSearchPath();
                    pd.stop();
                }
                currentPatchFile.open(file.getAbsolutePath());
                currentPatch = pd.openPatch(currentPatchFile.getAbsolutePath());

                pd.addToSearchPath(currentPatchFile.getEnclosingDirectory());
                pd.start();

                if(currentPatch.isValid()){
                     ofLog(OF_LOG_NOTICE,"PD patch: %s loaded & running!",currentPatchFile.getAbsolutePath().c_str());
                }
            }
        }
    }
}

Am i doing something wrong?

Thanks in advance

d3cod3 commented 5 years ago

SOLVED!

the problem was using

// calling closePatch passing the patch filepath
pd.closePatch(currentPatchFile.getAbsolutePath());

changing it with

// calling closePatch passing it the Patch variable
pd.closePatch(currentPatch)

solve the issue!