-
Notifications
You must be signed in to change notification settings - Fork 2
/
MyApp.cpp
85 lines (64 loc) · 2.22 KB
/
MyApp.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
#include "MyApp.h"
MyApp::MyApp(){
//long sound, stream
beat = new vaOpenal::SoundPlayer("savannadrum.ogg", true);
beat->setLoop(true);
beat->play();
//stereo sound
swosh = new vaOpenal::SoundPlayer("swosh_stereo.wav");
swosh->setVolume(0.8f);
//mono sound and multiplay
//can be triggered multiple times simultaneously
//works only with mono sounds
ping = new vaOpenal::SoundPlayer("sonar_mono.aiff");
ping->setMultiPlay(true);
// setup some widgets
//
float widthHalf = 0.5*scene->getWidth();
sliderFreq = new va::SliderWidget(300,40);
sliderFreq->setLabel("Speed");
sliderFreq->setPivot(150,20,0);
sliderFreq->setPosition(widthHalf,500);
sliderFreq->setValueMin(0.5);
sliderFreq->setValueMax(1.5);
sliderFreq->setValue(1.0);
sliderFreq->addEventHandler(this);
scene->addChild(sliderFreq);
sliderVol = new va::SliderWidget(300,40);
sliderVol->setLabel("Volume");
sliderVol->setPivot(150,20,0);
sliderVol->setPosition(widthHalf,440);
sliderVol->setValueMin(0.0);
sliderVol->setValueMax(1.0);
sliderVol->addEventHandler(this);
sliderVol->setValue(0.5);
scene->addChild(sliderVol);
va::ButtonWidget* buttonSwosh = new va::ButtonWidget(200,40);
buttonSwosh->setLabel("Swosh!");
buttonSwosh->setPivot(100,25,0);
buttonSwosh->setPosition(widthHalf,380);
buttonSwosh->addEventHandler(this);
scene->addChild(buttonSwosh);
va::ButtonWidget* buttonPing = new va::ButtonWidget(200,40);
buttonPing->setLabel("Ping!");
buttonPing->setPivot(100,25,0);
buttonPing->setPosition(widthHalf,320);
buttonPing->addEventHandler(this);
scene->addChild(buttonPing);
}
MyApp::~MyApp(){}
void MyApp::update() {}
void MyApp::widget( va::ButtonWidget& button ) {
if (button.getLabel() == "Swosh!") { //match by label
swosh->play();
} else if (button.getLabel() == "Ping!") {
ping->play();
}
}
void MyApp::widget( va::SliderWidget& slider ) {
if (&slider == sliderFreq) { //match by pointer
beat->setSpeed(slider.getValue());
} else if (&slider == sliderVol) {
beat->setVolume(slider.getValue());
}
}