From d55ec084e1e3ad61992ec2144bafda7cef5f3265 Mon Sep 17 00:00:00 2001
From: kthakore Start the application with audio and video support.Music Visualizer
+The Code and Comments
+
- my $lines = 100;
+ use strict;
use warnings;
@@ -3291,11 +3293,11 @@
Music Visualizer
use SDL::Mixer::Music;
use SDL::Mixer::Effects;
- use SDLx::App;
+ use SDLx::App; my $app = SDLx::App->new(
init => SDL_INIT_AUDIO | SDL_INIT_VIDEO,
width => 800,
height => 600,
@@ -3352,7 +3354,12 @@
Music Visualizer
playing. We read the stream data and show it on the screen as a wave
form.
# Music Playing Callbacks
+The number of lines to show in our visualizer.
+
+ my $lines = $ARGV[0];
+ $lines = 50 unless $lines;
+
+ # Music Playing Callbacks
my $current_song = 0;
my $current_music_callback = sub {
@@ -3362,6 +3369,7 @@ Music Visualizer
if( $stream_lock == 0 ){
$app->draw_rect([ 0, 0, $app->w(), $app->h()], 0x000000FF );
+ $app->draw_gfx_text([5,$app->h()-10], [255,0,0,255], "Playing Song: ".$songs[$current_song-1]);
my @stream = split( ',', $stream_data );
$stream_data = '';
@@ -3383,8 +3391,13 @@ Music Visualizer
my $point_x = ( $i / $#stream ) * $app->w;
- SDL::GFX::Primitives::box_RGBA( $app, $point_x-$l_wdt, 300, $point_x+$l_wdt, $point_y, 40, 0, 255, 128 );
- SDL::GFX::Primitives::box_RGBA( $app, $point_x-$l_wdt, 300, $point_x+$l_wdt, $point_y_r , 255, 0, 40, 128 );
+ SDL::GFX::Primitives::box_RGBA( $app, $point_x-$l_wdt, 300,
+ $point_x+$l_wdt, $point_y,
+ 40, 0, 255, 128 );
+
+ SDL::GFX::Primitives::box_RGBA( $app, $point_x-$l_wdt, 300,
+ $point_x+$l_wdt, $point_y_r ,
+ 255, 0, 40, 128 );
}
@@ -3393,18 +3406,17 @@ Music Visualizer
}
$app->flip();
};
+When a song is finished playing we remove the show handler and hook on another callback to switch to the
+next song gracefully.
- my $cms_move_callback;
- my $pns_move_callback;
-
-When a song is finished playing we remove the show handler and hook on
-another callback to switch to the next song gracefully.
+ my $cms_move_callback_id;
+ my $pns_move_callback_id;
- sub music_finished_playing {
+ sub music_finished_playing {
SDL::Mixer::Music::halt_music();
- $pns_move_callback = $app->add_move_handler( $play_next_song_callback );
- $app->remove_show_handler($cms_move_callback);
+ $pns_move_callback_id = $app->add_move_handler( $play_next_song_callback );
+ $app->remove_show_handler($cms_move_callback_id);
}
@@ -3416,11 +3428,14 @@ Music Visualizer
SDL::Mixer::Music::hook_music_finished('main::music_finished_playing');
SDL::Mixer::Music::play_music($song, 0 );
- $app->remove_move_handler( $pns_move_callback ) if defined $pns_move_callback;
- $cms_move_callback = $app->add_show_handler( $current_music_callback );
- };
+ $app->remove_move_handler( $pns_move_callback_id ) if defined $pns_move_callback_id;
+ $cms_move_callback_id = $app->add_show_handler( $current_music_callback );
+ };
+Add the first callback to get our first song.
+
+ $pns_move_callback_id= $app->add_move_handler( $play_next_song_callback);
-The event handler allows you to move through the songs.
+Add a event handler allows you to move through the songs.
$app->add_event_handler(
sub {
@@ -3433,12 +3448,7 @@ Music Visualizer
}
}
- );
-
-Add the first callback to get our first song, and start runing the
-$app
.
$pns_move_callback= $app->add_move_handler( $play_next_song_callback);
+ );
$app->run();
diff --git a/dist/SDL_Manual.pdf b/dist/SDL_Manual.pdf
index a56d89cc5981b0484b2be82dfd90ab72f4bc279b..c41331f61d474be9db990617280510fbe4553918 100644
GIT binary patch
delta 70770
zcmZ@>d0Y(t|F^sCc5k&?x@$=)DSIC}bdVAuIZ7xbp*u;`s@#+qyeUUW?lamPMQ)Ko
z6mpe2-^h4vad5%hUq@Oi-COD%*$wlqwQ-|Mk?)nnrhESHGoOal$9~Ipvwg8Q
zJf`nh?MGU39hd3;bnplcec>?Mg}?ZC=G~`OGW8S1L7PwJWn1`|nhY5c${B2TV$6k`
z%S&gD*y6wG*3u>095R-h=Xc}w&d~R)aLD$06ZzY+oN~BHC^u=zDwu2*$2q%j=F|Gs
zgDERt%T}ZdxlUK6c&}S@VZeR6#i;>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