

#include "sonarResponder.h"
#include "notes.h"

sonarResponder::sonarResponder(){
	bAmInPlaybackMode	= false;
	endTime				= ofGetElapsedTimef();
	zTarget = 0;
	zVal = 0;
	
}


void sonarResponder::update(){
	
	zVal = 0.99f * zVal + 0.01f * zTarget;
	
	if (hitEnergy < hitEnergyTarget){
		hitEnergy = 0.95f * hitEnergy +  0.05f * hitEnergyTarget;
	} else {
		hitEnergy = 0.99f * hitEnergy +  0.01f * hitEnergyTarget;
	}
	
	// where are we?
	
	if (bAmInPlaybackMode == true){
		float diffTime = ofGetElapsedTimef() - startTime;
		if (diffTime < durationToPlay){
			float pct = diffTime / durationToPlay;
			int frameImOn = (int)(pct * nNotesToPlay);
			if (frameImOn != nPlayed){
				nPlayed = frameImOn;
			}
		} else {
			bAmInPlaybackMode = false;
		}
	}
}

void sonarResponder::startPlayback(){
	bAmInPlaybackMode	= true;  // shoudl be false at the start.
	nPlayed				= 0;
	nNotesToPlay		= 4;
	durationToPlay		= 1.0f;
	startTime			= ofGetElapsedTimef();
	
	zTarget = 200;
	zVal = 0;
	
}