summaryrefslogtreecommitdiff
path: root/tools/ARDOUR/SourceInfoLoader.pm
blob: ec327d91f6b4e5b8fb107e3cd5123358620747ad (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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package ARDOUR::SourceInfoLoader;


use XML::Handler::Subs;

@ISA = qw( XML::Handler::Subs );

$VERSION = 1.0;


sub new {
	my ($type, $sessionName) = @_;

	my $self = $type->SUPER::new();
	
	$self->{SessionName} = $sessionName;
	$self->{InRegions} = 0;
	%self->{Sources} = {};

	
	return $self;
}

sub start_element {
	my $self = shift;
	my $element = shift;

	my $atts = $element->{Attributes};

	if ( $element->{Name} eq "Source") {
		if ( ! -f "interchange/".$sessionName."/audiofiles/".$atts->{name}) {
			$atts->{calculated_length} = 1;
			$self->{Sources}->{$atts->{id}} = $atts;
		}
	}

	
	if ( $self->{InRegions} eq 1 && $element->{Name} eq "Region") {
		#print "Looking at region ".$atts->{id}."\n";
		my $num = 0;

		my $region_length = $atts->{length};
		while ( $atts->{"source-".$num} ne "" ) {

			if ($region_length > $self->{Sources}->{$atts->{"source-".$num}}->{calculated_length} ) {
				$self->{Sources}->{$atts->{"source-".$num}}->{calculated_length} = $region_length;
			}

			$num++;
		}
	}

	if ( $element->{Name} eq "Regions") {
		$self->{InRegions} = 1;
		#print "In regions\n";
	}


}

sub end_element {
	my $self = shift;
	my $element = shift;

	if ( $element->{Name} eq "Regions") {
		$self->{InRegions} = 0;
		#print "Out of regions\n";
	}

}

1;