Skip to content

Commit 727a0f3

Browse files
committed
ofMultiSoundPlayer: added volume parameter listener
1 parent 71d8239 commit 727a0f3

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

src/SoundObjects/VUMeter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ ofColor& VUMeter::getPeakHoldColor(){
260260
}
261261
//--------------------------------------------------------------
262262
ofColor& VUMeter::getBorderColor(){
263-
static std::unique_ptr<ofColor> i = std:: make_unique<ofColor>(70);
263+
static std::unique_ptr<ofColor> i = std::make_unique<ofColor>(70);
264264
return *i;
265265
}
266266
//--------------------------------------------------------------

src/ofxMultiSoundPlayer.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ ofxMultiSoundPlayer::ofxMultiSoundPlayer() {
2121
setNumInstances(0);
2222

2323
volume.set("Volume", 1, 0, 1);
24+
volListener = volume.newListener(this, &ofxMultiSoundPlayer::volumeChanged);
2425
}
2526
//--------------------------------------------------------------
2627
bool ofxMultiSoundPlayer::canPlayInstance(){
@@ -143,13 +144,13 @@ void ofxMultiSoundPlayer::audioOut(ofSoundBuffer& outputBuffer){
143144
//========================END RUNNING ON AUDIO THREAD===============================
144145
//========================SETTERS===============================
145146
void ofxMultiSoundPlayer::setVolume(float vol, int index){
146-
if(index <= -1){
147+
// if(index <= -1){
147148
volume = vol;
148-
}else{
149+
// }else{
149150
updateInstance([&](ofxSingleSoundPlayer* inst){
150151
inst->volume = vol;
151152
},index, "ofxMultiSoundPlayer::setVolume");
152-
}
153+
// }
153154
}
154155
//--------------------------------------------------------------
155156
void ofxMultiSoundPlayer::setPan(float _pan, int index){
@@ -426,3 +427,13 @@ size_t ofxMultiSoundPlayer::getNumFrames() const {
426427
}
427428
return 0;
428429
}
430+
431+
432+
void ofxMultiSoundPlayer::volumeChanged(float&){
433+
if(bVolumeChangedByParameter)return;
434+
bVolumeChangedByParameter = true;
435+
setVolume(volume.get());
436+
437+
bVolumeChangedByParameter = false;
438+
}
439+

src/ofxMultiSoundPlayer.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,9 @@ class ofxMultiSoundPlayer: public ofxBaseSoundPlayer {
122122
ofxSoundMixer _mixer;
123123

124124
ofEventListeners endEventListeners;
125+
ofEventListener volListener;
126+
void volumeChanged(float&);
127+
bool bVolumeChangedByParameter = false;
125128

126129
void onInstanceEnd(size_t&);
127130
};

0 commit comments

Comments
 (0)