From be28c1ee811485e5bbdb44b9c7eac189168d8494 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Tue, 17 Sep 2013 01:46:17 +0200 Subject: Adjust code for SDL > 5.4000 --- Build.PL | 3 +-- Changelog | 5 +++++ bin/ekgping | 35 ++++++++++++++++++++++++++--------- 3 files changed, 32 insertions(+), 11 deletions(-) diff --git a/Build.PL b/Build.PL index ef2e41b..e5cbe36 100755 --- a/Build.PL +++ b/Build.PL @@ -21,8 +21,7 @@ Module::Build->new( 'Getopt::Long' => 0, 'IO::Handle' => 0, 'IPC::Run' => 0, - 'SDL::Mixer' => 0, - 'SDL::Music' => 0, + 'SDL' => 2.400, 'Term::Size' => 0, 'Time::HiRes' => 0, }, diff --git a/Changelog b/Changelog index ae4d35f..1d4774e 100644 --- a/Changelog +++ b/Changelog @@ -1,3 +1,8 @@ +ekgping 1.31 - Tue Sep 17 2023 + + * Update code for SDL >= 5.4000 + * Switch to perl versioning scheme + ekgping 1.3 - Tue Jun 21 2011 * Fix Module::Build dependency (we need >= 0.36) diff --git a/bin/ekgping b/bin/ekgping index f3b26a3..dab8159 100755 --- a/bin/ekgping +++ b/bin/ekgping @@ -4,16 +4,19 @@ use strict; use warnings; use 5.010; +no if $] >= 5.018, warnings => "experimental::smartmatch"; + use File::ShareDir qw(dist_file); use Getopt::Long qw(:config bundling); use IO::Handle; use IPC::Run qw(harness); +use SDL qw(:init); use SDL::Mixer; -use SDL::Music; +use SDL::Mixer::Music; use Term::Size; use Time::HiRes qw(usleep); -our $VERSION = '1.3'; +our $VERSION = '1.31'; my $beep = 0; my $beep_when = 'both'; @@ -40,10 +43,18 @@ GetOptions( $beep_file //= dist_file( 'ekgping', 'beep.ogg' ); +if ( not $quiet ) { + if (SDL::init(SDL_INIT_AUDIO) != 0) { + warn("Failed to init SDL\n"); + } + if (SDL::Mixer::open_audio( 44100, AUDIO_S16SYS, 2, 4096 ) != 0) { + warn("Failed to open audio device AUDIO_S16SYS"); + } +} + my $host = shift or usage(); my @ping_opts = @ARGV; -my $mixer = SDL::Mixer->new(); -my $beep_sound = SDL::Music->new($beep_file); +my $beep_sound = SDL::Mixer::Music::load_MUS($beep_file); my $ping = harness( [ 'ping', '-n', @ping_opts, $host ], @@ -76,6 +87,12 @@ sub parse_ping_output { sub quit { $ping->kill_kill( grace => 1 ); + + if (not $quiet) { + SDL::Mixer::close_audio; + SDL::quit; + } + print "\e[?25h"; exit 0; } @@ -90,8 +107,8 @@ $ping->start(); $ping->pump(); if ( not $quiet ) { - $mixer->play_music( $beep_sound, 999_999 ); - $mixer->pause_music(); + SDL::Mixer::Music::play_music( $beep_sound, -1 ); + SDL::Mixer::Music::pause_music; } print "\e[?25l"; @@ -147,10 +164,10 @@ while ( usleep(100_000) ) { if ( not $quiet ) { if ($beep) { - $mixer->resume_music(); + SDL::Mixer::Music::resume_music; } else { - $mixer->pause_music(); + SDL::Mixer::Music::pause_music; } } } @@ -169,7 +186,7 @@ B [B<-q>] [B<-ba>|B<-bd>] [B<-t> I] [B<-f> I] I [B =head1 VERSION -version 1.3 +version 1.31 =head1 DESCRIPTION -- cgit v1.2.3