#include "testApp.h"

//--------------------------------------------------------------
void testApp::setup(){	
	// initialize the accelerometer
	ofxAccelerometer.setup();
	
	//If you want a landscape oreintation 
	iPhoneSetOrientation(OFXIPHONE_ORIENTATION_LANDSCAPE_RIGHT);
	
	ofBackground(255,127,0);
    mySound1.loadSound("sound/3647.caf");
    mySound2.loadSound("sound/27568.caf");
    mySound1.setMultiPlay(true);
    mySound2.setLoop(true);
    volume1=0.8;
    volume2=0.8;
    mySound1.setVolume(volume1);
    mySound2.setVolume(volume2);
    //sounds used:
    //http://www.freesound.org/people/suonho/sounds/3647/
    //http://www.freesound.org/people/suonho/sounds/27568/
}

//--------------------------------------------------------------
void testApp::update(){

}

//--------------------------------------------------------------
void testApp::draw(){
	ofDrawBitmapString("Volume1: "+ofToString(volume1), 5,12);
	ofDrawBitmapString("Speed1: "+ofToString(speed1), 5,24);
	ofDrawBitmapString("Volume2: "+ofToString(volume2), ofGetWidth()/2+5,12);
    ofDrawBitmapString("Speed2: "+ofToString(speed2), ofGetWidth()/2+5,24);
ofLine(ofGetWidth()/2, 0, ofGetWidth()/2, ofGetHeight());
}

//--------------------------------------------------------------
void testApp::exit(){
}
//--------------------------------------------------------------
void testApp::touchDown(ofTouchEventArgs & touch){
    if(touch.id==0){
        if(touch.x<ofGetWidth()/2){
            mySound1.play();
            volume1=1-touch.y/ofGetHeight();
            mySound1.setVolume(volume1);
            speed1 = (touch.x/(ofGetWidth()/2))*2;
            //with ofMap it would be
            //ofMap(touch.x, 0, ofGetWidth()/2, 0, 2);
            mySound1.setSpeed(speed1);
        }else{
            mySound2.play();
            volume2=1-touch.y/ofGetHeight();
            mySound2.setVolume(volume2);
            //with ofMap, you can map a range of values into another range
            //first you specify the changing value, then its min and max values
            //and finally the min and max output values
            //in this case, the changing value is touch.x;
            //the input min and max are the half and right of the screen
            //and the output values are the minimum speed and the max speed
            speed2 = ofMap(touch.x, ofGetWidth()/2, ofGetWidth(), 0, 2);
            //in alternative, you can use a mathmatical formula
            //speed2=((touch.x-ofGetWidth()/2)/(ofGetWidth()/2))*2
            mySound2.setSpeed(speed2);

        }
    }
    if(touch.id==1){
        if(touch.x<ofGetWidth()/2){
            mySound1.stop();
        }else{
            mySound2.stop();
        }
    }

}

//--------------------------------------------------------------
void testApp::touchMoved(ofTouchEventArgs & touch){

}

//--------------------------------------------------------------
void testApp::touchUp(ofTouchEventArgs & touch){

}

//--------------------------------------------------------------
void testApp::touchDoubleTap(ofTouchEventArgs & touch){

}

//--------------------------------------------------------------
void testApp::touchCancelled(ofTouchEventArgs & touch){
    
}

//--------------------------------------------------------------
void testApp::lostFocus(){

}

//--------------------------------------------------------------
void testApp::gotFocus(){

}

//--------------------------------------------------------------
void testApp::gotMemoryWarning(){

}

//--------------------------------------------------------------
void testApp::deviceOrientationChanged(int newOrientation){

}

