/usr/share/perl5/Audio/Nama/Fade.pm is in nama 1.208-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 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 | # ----------- Fade ------------
package Audio::Nama::Fade;
use Modern::Perl;
use List::Util qw(min);
our $VERSION = 1.0;
use Carp;
use warnings;
no warnings qw(uninitialized);
our @ISA;
use vars qw($n %by_index);
use Audio::Nama::Globals qw(:singletons %tn @fade_data);
use Audio::Nama::Log qw(logsub logpkg);
use Audio::Nama::Effect qw(remove_effect add_effect update_effect);
# we don't import 'type' as it would clobber our $fade->type attribute
use Audio::Nama::Object qw(
n
type
mark1
mark2
duration
relation
track
class
);
initialize();
sub initialize {
%by_index = ();
@fade_data = (); # for save/restore
}
sub next_n {
my $n = 1;
while( $by_index{$n} ){ $n++}
$n
}
sub new {
my $class = shift;
my %vals = @_;
croak "undeclared field: @_" if grep{ ! $_is_field{$_} } keys %vals;
my $object = bless
{
# class => $class, # not needed yet
n => next_n(),
relation => 'fade_from_mark',
@_
}, $class;
$by_index{$object->n} = $object;
logpkg(__FILE__,__LINE__,'debug',"object class: $class, object type: ", ref $object);
my $id = add_fader($object->track);
my $track = $tn{$object->track};
Audio::Nama::request_setup(); # runs apply_fades and reconfigures engine
$object
}
# helper routines
sub refresh_fade_controller {
my $track = shift;
my @pairs = fader_envelope_pairs($track);
add_fader($track->name);
my $operator = Audio::Nama::fxn($track->fader)->type;
my $off_level = $config->{mute_level}->{$operator};
my $on_level = $config->{unity_level}->{$operator};
my @controllers = @{Audio::Nama::fxn($track->fader)->owns};
logpkg(__FILE__,__LINE__,'debug',$track->name, ": existing controllers: @controllers");
for my $controller (@controllers)
{
logpkg(__FILE__,__LINE__,'debug',"removing fade controller $controller");
remove_effect($controller);
}
# add controller
my $reuseid = pop @controllers; # we expect only one
logpkg(__FILE__,__LINE__,'debug',"applying fade controller");
add_effect({
track => $track,
id => $reuseid,
parent => $track->fader,
type => 'klg', # Ecasound controller
params => [ 1, # modify first parameter of fader op
$off_level,
$on_level,
@pairs,
]
});
# set fader to correct initial value
# first fade is type 'in' : 0
# first fade is type 'out' : 100%
update_effect($track->fader,0, initial_level($track->name) * 100)
}
sub all_fades {
my $track_name = shift;
sort {
$Audio::Nama::Mark::by_name{$a->mark1}->{time} <=> $Audio::Nama::Mark::by_name{$b->mark1}->{time}
} grep { $_->track eq $track_name } values %by_index
}
sub fades {
# get fades within playable region
my $track_name = shift;
my $track = $tn{$track_name};
my @fades = all_fades($track_name);
return @fades if ! $mode->{offset_run};
# handle offset run mode
my @in_bounds;
my $play_end = Audio::Nama::play_end_time();
my $play_start_time = Audio::Nama::play_start_time();
my $length = $track->wav_length;
for my $fade (@fades){
my $play_end_time = $play_end ? min($play_end, $length) : $length;
my $time = $Audio::Nama::Mark::by_name{$fade->mark1}->{time};
push @in_bounds, $fade if $time >= $play_start_time and $time <= $play_end_time;
}
@in_bounds
}
# our envelope must include a straight segment from the
# beginning of the track (or region) to the fade
# start. Similarly, we need a straight segment
# from the last fade to the track (or region) end
# - If the first fade is a fade-in, the straight
# segment will be at zero-percent level
# (otherwise 100%)
#
# - If the last fade is fade-out, the straight
# segment will be at zero-percent level
# (otherwise 100%)
# although we can get the precise start and endpoints,
# I'm using 0 and $track->shifted_playat_time + track length
sub initial_level {
# return 0, 1 or undef
# 0: track starts silent
# 1: track starts at full volume
my $track_name = shift;
my @fades = fades($track_name) or return undef;
# if we fade in we'll hold level zero from beginning
(scalar @fades and $fades[0]->type eq 'in') ? 0 : 1
}
sub exit_level {
my $track_name = shift;
my @fades = fades($track_name) or return undef;
# if we fade out we'll hold level zero from end
(scalar @fades and $fades[-1]->type eq 'out') ? 0 : 1
}
sub initial_pair { # duration: zero to...
my $track_name = shift;
my $init_level = initial_level($track_name);
defined $init_level or return ();
(0, $init_level )
}
sub final_pair { # duration: .... to length
my $track_name = shift;
my $exit_level = exit_level($track_name);
defined $exit_level or return ();
my $track = $tn{$track_name};
(
$track->shifted_playat_time + $track->wav_length,
$exit_level
);
}
sub fader_envelope_pairs {
# return number_of_pairs, pos1, val1, pos2, val2,...
my $track = shift;
my @fades = fades($track->name);
my @specs;
for my $fade ( @fades ){
# calculate fades
my $marktime1 = Audio::Nama::Mark::mark_time($fade->mark1);
my $marktime2 = Audio::Nama::Mark::mark_time($fade->mark2);
if ($marktime2) {} # nothing to do
elsif( $fade->relation eq 'fade_from_mark')
{ $marktime2 = $marktime1 + $fade->duration }
elsif( $fade->relation eq 'fade_to_mark')
{
$marktime2 = $marktime1;
$marktime1 -= $fade->duration
}
else { $fade->dumpp; die "fade processing failed" }
logpkg(__FILE__,__LINE__,'debug',"marktime1: $marktime1, marktime2: $marktime2");
push @specs,
[ $marktime1,
$marktime2,
$fade->type,
Audio::Nama::fxn($track->fader)->type,
];
}
# sort fades - may not need this
@specs = sort{ $a->[0] <=> $b->[0] } @specs;
logpkg(__FILE__,__LINE__,'debug',sub{Audio::Nama::json_out( \@specs)});
my @pairs = map{ spec_to_pairs($_) } @specs;
# WEIRD message - try to figure this out
# XXX results in bug via AUTOLOAD for Edit
# @pairs = (initial_pair($track->name), @pairs, final_pair($track->name));
# add flat segments
# - from start to first fade
# - from last fade to end
# prepend number of pairs;
unshift @pairs, (scalar @pairs / 2) if @pairs;
@pairs;
}
# each 'spec' is an array reference of the form [ $from, $to, $type, $op ]
#
# $from: time (in seconds)
# $to: time (in seconds)
# $type: 'in' or 'out'
# $op: 'ea' or 'eadb'
sub spec_to_pairs {
my ($from, $to, $type, $op) = @{$_[0]};
logpkg(__FILE__,__LINE__,'debug',"from: $from, to: $to, type: $type");
my $cutpos;
my @pairs;
# op 'eadb' uses two-stage fade
if ($op eq 'eadb'){
if ( $type eq 'out' ){
$cutpos = $from + $config->{fade_time1_fraction} * ($to - $from);
push @pairs, ($from, 1, $cutpos, $config->{fade_down_fraction}, $to, 0);
} elsif( $type eq 'in' ){
$cutpos = $from + $config->{fade_time2_fraction} * ($to - $from);
push @pairs, ($from, 0, $cutpos, $config->{fade_down_fraction}, $to, 1);
}
}
# op 'ea' uses one-stage fade
elsif ($op eq 'ea'){
if ( $type eq 'out' ){
push @pairs, ($from, 1, $to, 0);
} elsif( $type eq 'in' ){
push @pairs, ($from, 0, $to, 1);
}
}
else { die "missing or illegal fader op: $op" }
@pairs
}
# the following routine makes it possible to
# remove an edit fade by the name of the edit mark
# ???? does it even work?
sub remove_by_mark_name {
my $mark1 = shift;
my ($i) = map{ $_->n} grep{ $_->mark1 eq $mark1 } values %by_index;
remove($i) if $i;
}
sub remove_by_index {
my $i = shift;
my $fade = $by_index{$i};
$fade->remove;
}
sub remove {
my $fade = shift;
my $track = $tn{$fade->track};
my $i = $fade->n;
# remove object from index
delete $by_index{$i};
# remove fader entirely if this is the last fade on the track
my @track_fades = all_fades($fade->track);
if ( ! @track_fades ){
remove_effect($track->fader);
$tn{$fade->track}->set(fader => undef);
}
else { refresh_fade_controller($track) }
}
sub add_fader {
# if it is missing
my $name = shift;
my $track = $tn{$name};
my $id = $track->fader;
# create a fader if necessary, place before first effect
# if it exists
if (! $id or ! Audio::Nama::fxn($id)){
my $first_effect = $track->ops->[0];
$id = add_effect({
before => $first_effect,
track => $track,
type => $config->{fader_op},
params => [0], # XX hardcoded for -ea chain operator
});
$track->set(fader => $id);
}
$id
}
package Audio::Nama;
sub fade_uses_mark {
my $mark_name = shift;
grep{ $_->mark1 eq $mark_name or $_->mark2 eq $mark_name } values %Audio::Nama::Fade::by_index;
}
sub apply_fades {
# + data from Fade objects residing in %Audio::Nama::Fade::by_name
# + apply to tracks
# * that are part of current chain setup
# * that have a fade operator (i.e. most user tracks)
map{ Audio::Nama::Fade::refresh_fade_controller($_) }
grep{$_->{fader} }
Audio::Nama::ChainSetup::engine_tracks();
}
1;
|