LuaSession: allow multi-line commands and functions
[ardour.git] / tools / ARDOUR / AutomationSRConverter.pm
1 package ARDOUR::AutomationSRConverter;
2
3 sub new {
4         my ($type, $input, $output, $inputSR, $outputSR) = @_;
5
6         my $self = bless {}, $type;
7
8         $self->{Input}  = $input;
9         $self->{Output} = $output;
10         $self->{Ratio}  = ($outputSR+0) / ($inputSR+0);
11
12         return $self;
13 }
14
15 sub readline {
16         my ($self) = @_;
17
18         my $buf;
19         my $c='';
20         
21         do {
22                 $buf.=$c;
23                 $c=$self->{Input}->getc;
24         } while ($c ne '' && $c ne "\n");
25         
26         return $buf;
27 }
28
29 sub writeline {
30         my ($self, $line) = @_;
31
32         $self->{Output}->print($line."\n");
33 }
34
35 sub convert {
36         my ($self) = @_;
37
38         my $version=$self->readline;
39
40         if ($version ne "version 1") {
41                 die ("Unsupported automation version $version");
42         }
43
44         $self->writeline($version);
45
46         my $buf = $self->readline;
47         while ( $buf ne "" ) {
48                 if ( $buf eq "begin" ||
49                      $buf eq "end") {
50                         $self->writeline($buf);
51                 } else {
52                         my ($type, $position, $value) = split(' ', $buf);
53                 
54                         $self->writeline($type." ".sprintf("%.0f",$position*$self->{Ratio})." ".$value);
55                 }
56
57                 $buf = $self->readline;
58         }
59 }
60
61 1;