From fcd1e802a9674b44c6fb50e03f4902d841c41734 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Wed, 5 Apr 2017 19:17:05 +0200 Subject: Add -l / --volume option and bump version --- Changelog | 4 ++++ bin/ekgping | 23 ++++++++++++++++++----- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/Changelog b/Changelog index 5b7d62a..24d135a 100644 --- a/Changelog +++ b/Changelog @@ -1,3 +1,7 @@ +ekgping 1.32 - Wed Apr 5 2017 + + * Add -l / --volume option + ekgping 1.31 - Tue Sep 17 2013 * Update code for SDL >= 5.4000 diff --git a/bin/ekgping b/bin/ekgping index 2014f65..448c435 100755 --- a/bin/ekgping +++ b/bin/ekgping @@ -26,6 +26,7 @@ my $last_id = 0; my $dead_count = 0; my $column = 0; my $column_max = Term::Size::chars; +my $volume = 100; my $beep_file; my $quiet = 0; @@ -35,6 +36,7 @@ GetOptions( 'b|beep-when=s' => \$beep_when, 'f|beep-file=s' => \$beep_file, + 'l|volume=f' => \$volume, 'q|quiet' => \$quiet, 't|timeout=f' => \$timeout, 'V|version' => sub { say "ekgping version ${VERSION}"; exit 0 }, @@ -43,11 +45,16 @@ GetOptions( $beep_file //= dist_file( 'ekgping', 'beep.ogg' ); +if ( $volume < 0 or $volume > 100 ) { + warn("-l / --volume: Argument must be between 0 and 100. Setting to 50.\n"); + $volume = 50; +} + if ( not $quiet ) { - if (SDL::init(SDL_INIT_AUDIO) != 0) { + if ( SDL::init(SDL_INIT_AUDIO) != 0 ) { warn("Failed to init SDL\n"); } - if (SDL::Mixer::open_audio( 44100, AUDIO_S16SYS, 2, 4096 ) != 0) { + if ( SDL::Mixer::open_audio( 44100, AUDIO_S16SYS, 2, 4096 ) != 0 ) { warn("Failed to open audio device AUDIO_S16SYS"); } } @@ -88,7 +95,7 @@ sub parse_ping_output { sub quit { $ping->kill_kill( grace => 1 ); - if (not $quiet) { + if ( not $quiet ) { SDL::Mixer::close_audio; SDL::quit; } @@ -107,6 +114,7 @@ $ping->start(); $ping->pump(); if ( not $quiet ) { + SDL::Mixer::Music::volume_music( $volume * 1.28 ); SDL::Mixer::Music::play_music( $beep_sound, -1 ); SDL::Mixer::Music::pause_music; } @@ -182,7 +190,8 @@ B - Electrocardiograph-like graphical and audible ping =head1 SYNOPSIS -B [B<-q>] [B<-ba>|B<-bd>] [B<-t> I] [B<-f> I] I [B<--> I] +B [B<-q>] [B<-ba>|B<-bd>] [B<-t> I] [B<-f> I] +[B<-l> I] I [B<--> I] =head1 VERSION @@ -222,6 +231,10 @@ C<< --beep-when alive >>. Play I instead of the default beeps. May be any sound / music file +=item B<-l>, B<--volume> I + +Set volume to I per cent (minimum 0, maximum 100). Default: B<100>. + =item B<-q>, B<--quiet> Do not play beeps, graphical output only @@ -275,7 +288,7 @@ an SDL problem, use C<< ekgping -t 0.8 >> as workaround. =head1 AUTHOR -Copyright (C) 2011 by Daniel Friesel Ederf@finalrewind.orgE +Copyright (C) 2011-2017 by Daniel Friesel Ederf@finalrewind.orgE =head1 LICENSE -- cgit v1.2.3