forked from openframeworks/openFrameworks
/
testApp.cpp
131 lines (97 loc) · 3.93 KB
/
testApp.cpp
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#include "testApp.h"
//--------------------------------------------------------------
void testApp::setup(){
synth.loadSound(ofToDataPath("", true) + "/app/native/sounds/synth.wav");
beats.loadSound(ofToDataPath("", true) + "/app/native/sounds/1085.mp3");
vocals.loadSound(ofToDataPath("", true) + "/app/native/sounds/Violet.mp3");
synth.setVolume(0.75f);
beats.setVolume(0.75f);
vocals.setVolume(0.5f);
font.loadFont(ofToDataPath("", true) + "/app/native/Sudbury_Basin_3D.ttf", 32);
beats.setMultiPlay(false);
vocals.setMultiPlay(true);
}
//--------------------------------------------------------------
void testApp::update(){
ofBackground(255,255,255);
// update the sound playing system:
ofSoundUpdate();
}
//--------------------------------------------------------------
void testApp::draw(){
// draw the background colors:
float widthDiv = ofGetWidth() / 3.0f;
ofSetHexColor(0xeeeeee);
ofRect(0,0,widthDiv,ofGetHeight());
ofSetHexColor(0xffffff);
ofRect(widthDiv,0,widthDiv,ofGetHeight());
ofSetHexColor(0xdddddd);
ofRect(widthDiv*2,0,widthDiv,ofGetHeight());
//---------------------------------- synth:
if (synth.getIsPlaying()) ofSetHexColor(0xFF0000);
else ofSetHexColor(0x000000);
font.drawString("synth !!", 50,50);
ofSetHexColor(0x000000);
string tempStr = "click to play\npct done: "+ofToString(synth.getPosition())+"\nspeed: " + ofToString(synth.getSpeed()) + "\npan: " + ofToString(synth.getPan()) ;
ofDrawBitmapString(tempStr, 50,ofGetHeight()-50);
//---------------------------------- beats:
if (beats.getIsPlaying()) ofSetHexColor(0xFF0000);
else ofSetHexColor(0x000000);
font.drawString("beats !!", widthDiv+50,50);
ofSetHexColor(0x000000);
tempStr = "click and drag\npct done: "+ofToString(beats.getPosition())+"\nspeed: " +ofToString(beats.getSpeed());
ofDrawBitmapString(tempStr, widthDiv+50,ofGetHeight()-50);
//---------------------------------- vocals:
if (vocals.getIsPlaying()) ofSetHexColor(0xFF0000);
else ofSetHexColor(0x000000);
font.drawString("vocals !!", widthDiv*2+50,50);
ofSetHexColor(0x000000);
tempStr = "click to play (multiplay)\npct done: "+ofToString(vocals.getPosition())+"\nspeed: " + ofToString(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 - widthStep*2) / (float)widthStep);
}
}
//--------------------------------------------------------------
void testApp::mouseReleased(int x, int y, int button){
}
//--------------------------------------------------------------
void testApp::windowResized(int w, int h){
}
//--------------------------------------------------------------
void testApp::gotMessage(ofMessage msg){
}
//--------------------------------------------------------------
void testApp::dragEvent(ofDragInfo dragInfo){
}