topical media & game development
lib-of-vs-apps-examples-soundPlayerExample-src-testApp.cpp / cpp
include <testApp.h>
include <stdio.h>
//--------------------------------------------------------------
void testApp::setup(){
synth.loadSound("sounds/synth.wav");
beats.loadSound("sounds/1085.mp3");
vocals.loadSound("sounds/Violet.mp3");
synth.setVolume(0.75f);
beats.setVolume(0.75f);
vocals.setVolume(0.5f);
font.loadFont("Sudbury_Basin_3D.ttf", 32);
beats.setMultiPlay(false);
vocals.setMultiPlay(true);
}
//--------------------------------------------------------------
void testApp::update(){
ofBackground(255,255,255);
}
//--------------------------------------------------------------
void testApp::draw(){
char tempStr[255];
// draw the background colors:
float widthDiv = ofGetWidth() / 3.0f;
ofSetColor(0xeeeeee);
ofRect(0,0,widthDiv,ofGetHeight());
ofSetColor(0xffffff);
ofRect(widthDiv,0,widthDiv,ofGetHeight());
ofSetColor(0xdddddd);
ofRect(widthDiv*2,0,widthDiv,ofGetHeight());
//---------------------------------- synth:
if (synth.getIsPlaying()) ofSetColor(0xFF0000);
else ofSetColor(0x000000);
font.drawString("synth !!", 50,50);
ofSetColor(0x000000);
sprintf(tempStr, "click to play\npct done: \%f\nspeed: \%f\npan: \%f", synth.getPosition(), synth.getSpeed(), synth.getPan());
ofDrawBitmapString(tempStr, 50,ofGetHeight()-50);
//---------------------------------- beats:
if (beats.getIsPlaying()) ofSetColor(0xFF0000);
else ofSetColor(0x000000);
font.drawString("beats !!", widthDiv+50,50);
ofSetColor(0x000000);
sprintf(tempStr, "click and drag\npct done: \%f\nspeed: \%f", beats.getPosition(), beats.getSpeed());
ofDrawBitmapString(tempStr, widthDiv+50,ofGetHeight()-50);
//---------------------------------- vocals:
if (vocals.getIsPlaying()) ofSetColor(0xFF0000);
else ofSetColor(0x000000);
font.drawString("vocals !!", widthDiv*2+50,50);
ofSetColor(0x000000);
sprintf(tempStr, "click to play (multiplay)\npct done: \%f\nspeed: \%f", vocals.getPosition(), vocals.getSpeed());
ofDrawBitmapString(tempStr, widthDiv*2+50,ofGetHeight()-50);
}
//--------------------------------------------------------------
void testApp::keyPressed (int key){
}
//--------------------------------------------------------------
void testApp::keyReleased(int key){
}
//--------------------------------------------------------------
void testApp::mouseMoved(int x, int y ){
}
//--------------------------------------------------------------
void testApp::mouseDragged(int x, int y, int button){
// continuously control the speed of the beat sample via drag,
// when in the "beat" region:
float widthStep = ofGetWidth() / 3.0f;
if (x >= widthStep && x < widthStep*2){
beats.setSpeed( 0.5f + ((float)(ofGetHeight() - y) / (float)ofGetHeight())*1.0f);
}
}
//--------------------------------------------------------------
void testApp::mousePressed(int x, int y, int button){
float widthStep = ofGetWidth() / 3.0f;
if (x < widthStep){
float pct = x / widthStep;
synth.play();
synth.setSpeed( 0.1f + ((float)(ofGetHeight() - y) / (float)ofGetHeight())*10);
synth.setPan(pct);
} else if (x >= widthStep && x < widthStep*2){
beats.play();
} else {
vocals.play();
vocals.setSpeed( 0.1f + ((float)(ofGetHeight() - y) / (float)ofGetHeight())*3);
vocals.setPan((float)x / (float)ofGetWidth());
}
}
//--------------------------------------------------------------
void testApp::mouseReleased(int x, int y, int button){
}
//--------------------------------------------------------------
void testApp::resized(int w, int h){
}
(C) Æliens
04/09/2009
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.