Audio-Nama
view release on metacpan or search on metacpan
lib/Audio/Nama/Waveform.pm view on Meta::CPAN
package Audio::Nama::Waveform;
use Audio::Nama::Globals qw($project $config $gui %ti);
use Audio::Nama::Util qw(join_path);
use v5.36;
our $VERSION = 1.0;
use Try::Tiny;
use vars qw(%by_name);
use Audio::Nama::Object qw(wav track project start end);
# * objects of this class represent a waveform display
# * each object is associated with an audio file
# * object will find or generate PNG for the audio
# * will display waveform
# + if shift, correctly position PNG
# + if region, trim the PNG existing for the track
# the $track->waveform method will create a new object of this class
# we will memoize since it remains constant between reconfigures
# keyed to the
# + name of the WAV file
# + name of project
# + start and end times
# the get_png() method will find or generate the appropriate PNG
# files are of the form # sax_1.wav.1200x200-10.png
# where the numbers correspond to width and height in pixels of the audio
# waveform image, and the x-scaling in pixels per second (default 10)
sub new {
my $class = shift;
my %args = @_;
bless \%args, $class
}
sub generate_waveform {
my $self = shift;
my ($width, $height, $pixels_per_second) = @_;
$pixels_per_second //= $config->{waveform_pixels_per_second};
$height //= $config->{waveform_height};
$width //= int( $self->track->wav_length * $pixels_per_second);
my $name = waveform_name($self->track->full_path, $width, $height, $pixels_per_second);
my $cmd = join ' ', 'waveform', "-b #c2d6d6 -c #0080ff -W $width -H $height", $self->track->full_path, $name;
say $cmd;
system($cmd);
$name;
}
# utility subroutine
sub waveform_name {
my($path, $width, $height, $pixels, $start, $end) = @_;
"$path." . $width . 'x' . "$height-$pixels" . region_def($start,$end) . ".png"
}
sub region_def {}
sub find_waveform {
my $self = shift;
my $match = shift() // '*';
my @files = File::Find::Rule->file()
->name( $self->wav . ".$match.png" )
->in( Audio::Nama::this_wav_dir() );
@files;
}
sub get_waveform {
( run in 1.119 second using v1.01-cache-2.11-cpan-5511b514fd6 )