Java Reference
In-Depth Information
Listing 9-11. Wave.fx
public class Wave extends AudioVisualization{
var count = 0;
var anim = Timeline{
repeatCount: Timeline.INDEFINITE
keyFrames: KeyFrame{
time: 1/30*1s
action: function(){
count++;
for (node in content){
(node as WaveDot).update();
}
if (count mod 30 == 0){
emit();
}
}
}
}
init{
anim.play();
}
function emit():Void{
if (soundPlayer.isPlaying()){
insert WaveDot{
radius: 3
translateY: -soundPlayer.lowChannels*100;
fill: Color.CRIMSON
effect: ColorAdjust{
hue: -1 + soundPlayer.midChannels/3.5
}
} into content;
}
}
}
In Listing 9-11 we see that Wave creates a Timeline called anim that does two things; first it calls
update on each WaveDot , and second it calls emit every 30 th time. The function emit simply creates a new
WaveDot and inserts it into the Wave 's content . When creating the WaveDot , its height on the screen is
determined by sampling the soundPlayer 's lowChannel value. A ColorAdjust is also used in conjunction
with soundPlayer 's midChannel value.
By having the height be a function of the lowChannel and the color be a function of the midChannel ,
we create a kind history of the song as it plays, since only the most recently created WaveDot is a
reflection of the music you are hearing. Let's take a look at the source code for WaveDot to make sure we
understand how this works (Listing 9-12).
Search WWH ::




Custom Search