Audio-Nama
view release on metacpan or search on metacpan
lib/Audio/Nama/Sequence.pm view on Meta::CPAN
my $items = delete $args{items};
my $counter = delete $args{clip_counter};
#logpkg(__FILE__,__LINE__,'debug', "items: ",map{json_out($_->as_hash)}map{$Audio::Nama::tn{$_}}@$items) if $items;
$items //= [];
@_ = ($class, %args);
my $self = super();
logpkg(__FILE__,__LINE__,'debug',"new object: ", json_out($self->as_hash));
logpkg(__FILE__,__LINE__,'debug', "items: ",json_out($items));
$self->{clip_counter} = $counter;
$self->{items} = $items;
$Audio::Nama::this_sequence = $self;
$self;
}
sub clip {
my ($self, $index) = @_;
return 0 if $index <= 0;
$Audio::Nama::tn{$self->{items}->[$index - 1]}
}
sub rw {
my $self = shift;
$Audio::Nama::mode->{offset_run} ? OFF : $self->{rw}
}
# perl indexes arrays at zero, for nama users we number items from one
sub insert_item {
my $self = shift;
my ($item, $index) = @_;
$self->append_item($item), return if $index == @{$self->{items}} + 1;
$self->verify_item($index) or die "$index: sequence index out of range";
splice @{$self->{items}}, $index - 1,0, $item->name
}
sub verify_item {
my ($self, $index) = @_;
$index >= 1 and $index <= scalar @{$self->items}
}
sub delete_item {
my $self = shift;
my $index = shift;
$self->verify_item($index) or die "$index: sequence index out of range";
my $trackname = splice(@{$self->{items}}, $index - 1, 1);
$Audio::Nama::tn{$trackname} and $Audio::Nama::tn{$trackname}->remove;
}
sub append_item {
my $self = shift;
my $item = shift;
push( @{$self->{items}}, $item->name );
}
sub item {
my $self = shift;
my $index = shift;
return 0 if $index <= 0;
$Audio::Nama::tn{$self->{items}->[$index - 1]};
}
sub list_output {
my $self = shift;
my $i;
join "\n","Sequence $self->{name} clips:",
map { join " ",
++$i,
$Audio::Nama::tn{$_}->n,
$_,
sprintf("%.3f %.3f", $Audio::Nama::tn{$_}->duration, $Audio::Nama::tn{$_}->endpoint),
} @{$self->items}
}
sub remove {
my $sequence = shift;
# delete all clips
map{$Audio::Nama::tn{$_}->remove } $by_name{$sequence->name}->tracks;
# delete clip array
delete $sequence->{items};
my $mix_track = $Audio::Nama::tn{$sequence->name};
if ( defined $mix_track ){
$mix_track->set(rw => OFF);
# remove mix track unless it has some WAV files
$mix_track->remove unless scalar @{ $mix_track->versions };
}
# remove sequence from index
delete $by_name{$sequence->name};
}
sub new_clip {
my ($self, $track, %args) = @_; # $track can be object or name
my $markpair = delete $args{region};
logpkg(__FILE__,__LINE__,'debug',json_out($self->as_hash), json_out($track->as_hash));
ref $track or $track = $Audio::Nama::tn{$track}
or die("$track: track not found.");
my %region_args = (
region_start => $markpair && $markpair->[0]->name || $track->region_start,
region_end => $markpair && $markpair->[1]->name || $track->region_end
);
my $clip = Audio::Nama::Clip->new(
target => $track->basename,
name => $self->unique_clip_name($track->name, $track->playback_version),
rw => PLAY,
group => $self->name,
version => $track->playback_version,
hide => 1,
%region_args,
%args
);
modify_effect( $clip->vol, 1, undef, fxn($track->vol)->params->[0]);
modify_effect( $clip->pan, 1, undef, fxn($track->pan)->params->[0]);
$clip
}
sub new_spacer {
my( $self, %args ) = @_;
my $position = delete $args{position};
my $spacer = Audio::Nama::Spacer->new(
duration => $args{duration},
name => $self->unique_spacer_name(),
rw => OFF,
group => $self->name,
);
$self->insert_item( $spacer, $position || ( scalar @{ $self->{items} } + 1 ))
( run in 0.973 second using v1.01-cache-2.11-cpan-5735350b133 )