Skip to content

Commit 38ec528

Browse files
committed
added pins reset for loading patch on different audio device
1 parent e4279d1 commit 38ec528

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed

src/objects/sound/AudioDevice.cpp

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@ void AudioDevice::setupObjectContent(shared_ptr<ofAppGLFWWindow> &mainWindow){
7676

7777
//--------------------------------------------------------------
7878
void AudioDevice::setupAudioOutObjectContent(pdsp::Engine &engine){
79+
80+
if(this->numInlets != in_channels || this->numOutlets != out_channels){
81+
resetInletsOutlets();
82+
}
83+
7984
if(deviceLoaded && out_channels>0){
8085
for(size_t c=0;c<static_cast<size_t>(out_channels);c++){
8186
OUT_CH[c].out_signal() >> engine.audio_out(c);
@@ -231,7 +236,7 @@ void AudioDevice::resetSystemObject(){
231236
_inletParams[i] = new ofSoundBuffer(shortBuffer,static_cast<size_t>(bufferSize),1,static_cast<unsigned int>(sampleRateOUT));
232237
}
233238

234-
for( int i = 0; i < this->pdspOut.size(); i++){
239+
for( unsigned int i = 0; i < this->pdspOut.size(); i++){
235240
this->pdspOut[i].disconnectOut();
236241
}
237242
this->pdspOut.clear();
@@ -326,6 +331,50 @@ void AudioDevice::resetSystemObject(){
326331
}
327332
}
328333

334+
//--------------------------------------------------------------
335+
void AudioDevice::resetInletsOutlets(){
336+
337+
ofxXmlSettings XML;
338+
339+
if (XML.loadFile(patchFile)){
340+
int totalObjects = XML.getNumTags("object");
341+
342+
if (XML.pushTag("settings")){
343+
in_channels = XML.getValue("input_channels",0);
344+
out_channels = XML.getValue("output_channels",0);
345+
sampleRateIN = XML.getValue("sample_rate_in",0);
346+
sampleRateOUT= XML.getValue("sample_rate_out",0);
347+
bufferSize = XML.getValue("buffer_size",0);
348+
XML.popTag();
349+
}
350+
351+
// Save new object config
352+
for(int i=0;i<totalObjects;i++){
353+
if(XML.pushTag("object", i)){
354+
if(XML.getValue("id", -1) == this->nId){
355+
// Dynamic reloading outlets
356+
XML.removeTag("outlets");
357+
int newOutlets = XML.addTag("outlets");
358+
if(XML.pushTag("outlets",newOutlets)){
359+
for(int j=0;j<static_cast<int>(this->outletsType.size());j++){
360+
int newLink = XML.addTag("link");
361+
if(XML.pushTag("link",newLink)){
362+
XML.setValue("type",this->outletsType.at(j));
363+
XML.popTag();
364+
}
365+
}
366+
XML.popTag();
367+
}
368+
}
369+
}
370+
}
371+
372+
XML.saveFile();
373+
374+
}
375+
376+
}
377+
329378
//--------------------------------------------------------------
330379
void AudioDevice::loadDeviceInfo(){
331380
ofxXmlSettings XML;

src/objects/sound/AudioDevice.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ class AudioDevice : public PatchObject {
5959
void resetSystemObject() override;
6060

6161
void loadDeviceInfo();
62+
void resetInletsOutlets();
6263

6364
vector<ofSoundBuffer> IN_CH;
6465
vector<pdsp::ExternalInput> PN_IN_CH;

0 commit comments

Comments
 (0)