aboutsummaryrefslogtreecommitdiffstats
path: root/ofxMaxim/ofxMaximExample_0.8.4_OSX_Granular/ofxOsc/src/ofxOscParameterSync.cpp
blob: 2cf7a1125e5ae44ab565fdeb6ffe72be7380f957 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/*
 * ofxOscParameterSync.cpp
 *
 *  Created on: 13/07/2012
 *      Author: arturo
 */

#include "ofxOscParameterSync.h"

ofxOscParameterSync::ofxOscParameterSync() {
	syncGroup = NULL;
	updatingParameter = false;
}

ofxOscParameterSync::~ofxOscParameterSync(){
	if(syncGroup)
		ofRemoveListener(syncGroup->parameterChangedE,this,&ofxOscParameterSync::parameterChanged);
}


void ofxOscParameterSync::setup(ofParameterGroup & group, int localPort, string host, int remotePort){
	syncGroup = &group;
	ofAddListener(group.parameterChangedE,this,&ofxOscParameterSync::parameterChanged);
	sender.setup(host,remotePort);
	receiver.setup(localPort);
}

void ofxOscParameterSync::update(){
	if(receiver.hasWaitingMessages()){
		updatingParameter = true;
		receiver.getParameter(*syncGroup);
		updatingParameter = false;
	}
}

void ofxOscParameterSync::parameterChanged( ofAbstractParameter & parameter ){
	if(updatingParameter) return;
	sender.sendParameter(parameter);
}