summaryrefslogtreecommitdiff
path: root/tools/ARDOUR/AutomationSRConverter.pm
blob: afd8f6c7022609c907dd467200773fa2728c3ad6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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;