/usr/share/perl5/Audio/Nama/Util.pm is in nama 1.078-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 | # ----------- Util.pm -----------
# this package is for small subroutines with
# well-defined interfaces
package Audio::Nama;
our ( %tn ); # rw_set()
package Audio::Nama::Util;
use Modern::Perl; use Carp;
no warnings 'uninitialized';
require Exporter;
our @ISA = qw(Exporter);
our %EXPORT_TAGS = ( 'all' => [ qw(
rw_set
freq
channels
input_node
output_node
signal_format
process_is_running
d1
d2
dn
round
colonize
time_tag
heuristic_time
dest_type
) ] );
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
our @EXPORT = ();
## rw_set() for managing bus-level REC/MON/OFF settings commands
{
my %bus_logic = (
mix_track =>
{
# setting mix track to REC
# set bus to MON (user should set bus to REC)
REC => sub
{
my ($bus, $track) = @_;
$track->set_rec;
$bus->set(rw => 'MON');
},
# setting mix track to MON
# set bus to OFF
MON => sub
{
my ($bus, $track) = @_;
$track->set_mon;
$bus->set(rw => 'OFF');
},
OFF => sub
{
# setting mix track to OFF
# set bus to OFF
my ($bus, $track) = @_;
$track->set_off;
$bus->set(rw => 'OFF');
}
},
member_track =>
{
# setting member track to REC
#
# - set REC siblings to MON if bus is MON
# - set all siblings to OFF if bus is OFF
# - set bus to REC
# - set mix track to REC/rec_defeat
REC => sub
{
my ($bus, $track) = @_;
if ($bus->rw eq 'MON'){
# set REC tracks to MON
map{$_->set(rw => 'MON') }
grep{$_->rw eq 'REC'}
map{$tn{$_}}
$bus->tracks;
}
if ($bus->rw eq 'OFF'){
# set all tracks to OFF
map{$_->set(rw => 'OFF') }
map{$tn{$_}}
$bus->tracks;
}
$track->set_rec;
$bus->set(rw => 'REC');
$tn{$bus->send_id}->busify;
},
# setting member track to MON
#
# - set all siblings to OFF if bus is OFF
# - set bus to MON
# - set mix track to REC/rec_defeat
MON => sub
{
my ($bus, $track) = @_;
if ($bus->rw eq 'OFF'){
# set all tracks to OFF
map{$_->set(rw => 'OFF') }
map{$Audio::Nama::tn{$_}}
$bus->tracks;
$bus->set(rw => 'MON');
}
$track->set_mon;
#$tn{$bus->send_id}->busify; why needed????
},
# setting member track to OFF
OFF => sub
{
my ($bus, $track) = @_;
$track->set_off;
},
},
);
sub rw_set {
my ($bus,$track,$rw) = @_;
my $type = $track->is_mix_track
? 'mix_track'
: 'member_track';
$bus_logic{$type}{uc $rw}->($bus,$track);
}
}
sub freq { [split ',', $_[0] ]->[2] } # e.g. s16_le,2,44100
sub channels { [split ',', $_[0] ]->[1] }
sub input_node { $_[0].'_in' }
sub output_node {$_[0].'_out'}
sub signal_format {
my ($template, $channel_count) = @_;
$template =~ s/N/$channel_count/;
my $format = $template;
}
sub process_is_running {
my $name = shift;
my @pids = split " ", qx(pgrep $name);
my @ps_ax = grep{ my $pid;
/$name/ and ! /defunct/
and ($pid) = /(\d+)/
and grep{ $pid == $_ } @pids
} split "\n", qx(ps ax) ;
}
sub d1 {
my $n = shift;
sprintf("%.1f", $n)
}
sub d2 {
my $n = shift;
sprintf("%.2f", $n)
}
sub dn {
my ($n, $places) = @_;
sprintf("%." . $places . "f", $n);
}
sub round {
my $n = shift;
return 0 if $n == 0;
$n = int $n if $n > 10;
$n = d2($n) if $n < 10;
$n;
}
sub colonize { # convert seconds to hours:minutes:seconds
my $sec = shift || 0;
my $hours = int ($sec / 3600);
$sec = $sec % 3600;
my $min = int ($sec / 60);
$sec = $sec % 60;
$sec = "0$sec" if $sec < 10;
$min = "0$min" if $min < 10 and $hours;
($hours ? "$hours:" : "") . qq($min:$sec);
}
sub time_tag {
my @time = localtime time;
$time[4]++;
$time[5]+=1900;
@time = @time[5,4,3,2,1,0];
sprintf "%4d.%02d.%02d-%02d:%02d:%02d", @time
}
sub heuristic_time {
my $sec = shift;
d1($sec) . ( $sec > 120 ? " (" . colonize( $sec ) . ") " : " " )
}
sub dest_type {
my $dest = shift;
my $type;
given( $dest ){
when( undef ) {} # do nothing
# non JACK related
when('bus') { $type = 'bus' }
when('null') { $type = 'null' }
when(/^loop,/) { $type = 'loop' }
when(! /\D/) { $type = 'soundcard' } # digits only
# JACK related
when(/^man/) { $type = 'jack_manual' }
when('jack') { $type = 'jack_manual' }
when(/(^\w+\.)?ports/) { $type = 'jack_ports_list' }
default { $type = 'jack_client' }
}
$type
}
1;
__END__
|