Audio-Nama

 view release on metacpan or  search on metacpan

lib/Audio/Nama/Edit.pm  view on Meta::CPAN

	} grep{ $_->host_track eq $this_track->name} 
		values %Audio::Nama::Edit::by_name;
	Audio::Nama::throw("Aborting."), return if $overlap;
	my $name = $this_track->name;
	my $editre = qr($name-v\d+-edit\d+);
	Audio::Nama::throw("$name: editing of edits is not currently allowed."),
		return if $name =~ /-v\d+-edit\d+/;
	Audio::Nama::throw("$name: must be in PLAY mode.
Edits will be applied against current version"), 
		return unless $this_track->play 
			or $this_track->rec and
			grep{ /$editre/ } keys %Audio::Nama::Track::by_name;

	# create edit
	
	my $v = $this_track->playback_version;
	Audio::Nama::pager("$name: creating new edit against version $v");
	my $edit = Audio::Nama::Edit->new(
		host_track 		=> $this_track->name,
		host_version	=> $v,
	);
	$this_track->current_edit->{$v} = $edit->n;
	$this_edit = $edit;
	transfer_edit_points($edit);
	#select_edit($this_edit->n);
	edit_action('preview_edit_in');
}
{my %edit_actions = 
	(
		record_edit => sub { 
			$this_edit->edit_track->set(rw => REC);
			$this_edit->store_fades(std_host_fades(), edit_fades());
		},
		play_edit => sub {
			$this_edit->edit_track->set(rw => PLAY);
			$this_edit->store_fades(std_host_fades(), edit_fades());
		},
		preview_edit_in => sub {
			$this_edit->edit_track->set(rw => OFF);
			$this_edit->store_fades(std_host_fades());
		},
		preview_edit_out => sub {
			$this_edit->edit_track->set(rw => OFF);
			$this_edit->store_fades(reverse_host_fades());
		},
	);

sub edit_action {
	my $action = shift;
	defined $this_edit or Audio::Nama::throw("Please select an edit and try again."), return;
	set_edit_mode();
	$this_edit->host_alias_track->set(rw => PLAY); # all 
	$edit_actions{$action}->();
	request_setup();

#   TODO: looping
# 	my $is_setup = generate_setup(); 
# 	return unless $is_setup;
# 	if ($action !~ /record/){
# 		$mode->{loop_enable}++;
# 		@{$setup->{loop_endpoints}} = (0,$setup->{audio_length} - 0.05);
# 		#  and transport_start()
# 	}
# 	connect_transport(); 
}
}

sub end_edit_mode  	{ 

	# regenerate fades
	
	$mode->{offset_run} = 0; 
	$mode->{loop_enable} = 0;
	disable_offset_run_mode();	
	$this_track = $this_edit->host if defined $this_edit;
	undef $this_edit;
	request_setup();
}
sub destroy_edit {
	Audio::Nama::throw("no edit selected"), return unless $this_edit;
	my $reply;
   	#	= $text->{term}->readline('destroy edit "'.$this_edit->edit_name.
	# qq(" and all its WAV files?? [n] ));
	if ( $reply =~ /y/i ){
		Audio::Nama::pager("permanently removing edit");
		$this_edit->destroy;
	}
	#$text->{term}->remove_history($text->{term}->where_history);
	$this_track = $this_edit->host;
	end_edit_mode();
}
sub set_edit_mode 	{ $mode->{offset_run} = edit_mode_conditions() ?  1 : 0 }
sub edit_mode		{ $mode->{offset_run} and defined $this_edit}
sub edit_mode_conditions {        
	defined $this_edit or Audio::Nama::throw('No edit is defined'), return;
	defined $this_edit->play_start_time or Audio::Nama::throw('No edit points defined'), return;
	$this_edit->host_alias_track->play
		or Audio::Nama::throw('host alias track : ',$this_edit->host_alias,
				" status must be PLAY"), return;

	# the following conditions should never be triggered 
	
	$this_edit->host_alias_track->playback_version == $this_edit->host_version
		or die('host alias track: ',$this_edit->host_alias,
				" must be set to version ",$this_edit->host_version), return
	1;
}
sub reverse_host_fades { host_fades('in','out') }

sub std_host_fades { host_fades('out','in') }

sub host_fades {
	my ($first,$second) = @_;
	Audio::Nama::Fade->new(  type => $first,
					mark1 => $this_edit->rec_start_name,
					duration => $config->{edit_crossfade_time},
					relation => 'fade_from_mark',
					track => $this_edit->host_alias,
	), 
	Audio::Nama::Fade->new(  type => $second,
					mark1 => $this_edit->rec_end_name,



( run in 0.581 second using v1.01-cache-2.11-cpan-5735350b133 )