diff options
author | Paul Davis <paul@linuxaudiosystems.com> | 2007-04-26 20:54:31 +0000 |
---|---|---|
committer | Paul Davis <paul@linuxaudiosystems.com> | 2007-04-26 20:54:31 +0000 |
commit | 87726495c30f90554b5204b5385d17274a8fe93e (patch) | |
tree | d7ecaf0be9b5cbd2afa226cd02cb53a36875d6a2 /tools/ARDOUR | |
parent | 45d3ec1437cf661533bc7750c623865def4424df (diff) |
Merged changes from trunk 1699:1751 into 2.1-staging
git-svn-id: svn://localhost/ardour2/branches/2.1-staging@1752 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'tools/ARDOUR')
-rw-r--r-- | tools/ARDOUR/AutomationSRConverter.pm | 61 | ||||
-rw-r--r-- | tools/ARDOUR/SessionSRHandler.pm | 120 |
2 files changed, 181 insertions, 0 deletions
diff --git a/tools/ARDOUR/AutomationSRConverter.pm b/tools/ARDOUR/AutomationSRConverter.pm new file mode 100644 index 0000000000..afd8f6c702 --- /dev/null +++ b/tools/ARDOUR/AutomationSRConverter.pm @@ -0,0 +1,61 @@ +package ARDOUR::AutomationSRConverter; + +sub new { + my ($type, $input, $output, $inputSR, $outputSR) = @_; + + my $self = bless {}, $type; + + $self->{Input} = $input; + $self->{Output} = $output; + $self->{Ratio} = ($outputSR+0) / ($inputSR+0); + + return $self; +} + +sub readline { + my ($self) = @_; + + my $buf; + my $c=''; + + do { + $buf.=$c; + $c=$self->{Input}->getc; + } while ($c ne '' && $c ne "\n"); + + return $buf; +} + +sub writeline { + my ($self, $line) = @_; + + $self->{Output}->print($line."\n"); +} + +sub convert { + my ($self) = @_; + + my $version=$self->readline; + + if ($version ne "version 1") { + die ("Unsupported automation version $version"); + } + + $self->writeline($version); + + my $buf = $self->readline; + while ( $buf ne "" ) { + if ( $buf eq "begin" || + $buf eq "end") { + $self->writeline($buf); + } else { + my ($type, $position, $value) = split(' ', $buf); + + $self->writeline($type." ".sprintf("%.0f",$position*$self->{Ratio})." ".$value); + } + + $buf = $self->readline; + } +} + +1; diff --git a/tools/ARDOUR/SessionSRHandler.pm b/tools/ARDOUR/SessionSRHandler.pm new file mode 100644 index 0000000000..8bfe665aca --- /dev/null +++ b/tools/ARDOUR/SessionSRHandler.pm @@ -0,0 +1,120 @@ +package ARDOUR::SessionSRHandler; + + +use XML::Handler::XMLWriter; +use POSIX qw(floor); + +@ISA = qw( XML::Handler::XMLWriter ); + +$VERSION = 0.1; + +# This table maps the "names of XML elements" to lists of "names of attributes" which should +# be converted according to the SR change. +# TODO: The table is a bit dirty, i have to figure out how to do it cleanly +my $conversion_table = { + "Location" => { "end" => 0, "start" => 0 }, + "Region" => { "length" => 0, "start" => 0, "position" => 0, "sync-position" => 0 }, + "Crossfade" => { "left" => 0, "right" => 0 } + }; + + +sub new { + my ($type, $original_sr, $new_sr, $output) = @_; + + #my $self = XML::Handler::XMLWriter->new( { Output => $output } ); + + my $self = $type->SUPER::new( Output => $output ); + + $self->{Debug} = 0; + $self->{Ratio} = ($new_sr+0)/($original_sr+0); + $self->{OriginalSR} = $original_sr; + $self->{TargetSR} = $new_sr; + $self->{Output} = $output; + + $self->{InEvents} = 0; + + return $self; +} + +sub start_element { + my $self = shift; + my $element = shift; + + my $debug = $self->{Debug}; + + my $atts = $element->{Attributes}; + + my $convert_attributes = $conversion_table->{$element->{Name}}; + + foreach my $cAtt (keys %$convert_attributes) { + $atts->{$cAtt} = sprintf("%.0f", $atts->{$cAtt} * $self->{Ratio}); + $debug = 0; + } + + if ($debug eq 0) { + $self->SUPER::start_element($element, @_); + } + + if ($element->{Name} eq "events") { + $self->{InEvents} = 1; + } +} + +sub end_element { + my $self = shift; + my $element = shift; + + if ($self->{Debug} eq 0) { + $self->SUPER::end_element($element,@_); + } + + if ($element->{Name} eq "events") { + $self->{InEvents} = 0; + } +} + +sub start_document { + my $self = shift; + + $self->SUPER::start_document(@_); + + $self->{Output}->print("<!-- Sample rate converted from $self->{OriginalSR}hz to $self->{TargetSR}hz -->\n"); +} + +sub end_document { + my $self = shift; + + $self->SUPER::end_document(@_); +} + +sub characters { + my $self = shift; + my $c = shift; + + if ($self->{InEvents} > 0) { + my $converted = ""; + + foreach my $foo (split(' ',$c->{Data})) { + if ($self->{InEvents} eq 1) { + $converted .= floor($foo * $self->{Ratio})." "; + $self->{InEvents} = 2; + } else { + $converted .= $foo." "; + $self->{InEvents} = 1; + } + } + + $c->{Data} = $converted; + } + + + if ($self->{Debug} eq 0) { + $self->SUPER::characters($c, @_); + } + +} + +1; + + + |