handle multiple imports of the same file better (via better source naming); make...
[ardour2.git] / tools / ARDOUR / SourceInfoLoader.pm
blobec327d91f6b4e5b8fb107e3cd5123358620747ad
1 package ARDOUR::SourceInfoLoader;
4 use XML::Handler::Subs;
6 @ISA = qw( XML::Handler::Subs );
8 $VERSION = 1.0;
11 sub new {
12 my ($type, $sessionName) = @_;
14 my $self = $type->SUPER::new();
16 $self->{SessionName} = $sessionName;
17 $self->{InRegions} = 0;
18 %self->{Sources} = {};
21 return $self;
24 sub start_element {
25 my $self = shift;
26 my $element = shift;
28 my $atts = $element->{Attributes};
30 if ( $element->{Name} eq "Source") {
31 if ( ! -f "interchange/".$sessionName."/audiofiles/".$atts->{name}) {
32 $atts->{calculated_length} = 1;
33 $self->{Sources}->{$atts->{id}} = $atts;
38 if ( $self->{InRegions} eq 1 && $element->{Name} eq "Region") {
39 #print "Looking at region ".$atts->{id}."\n";
40 my $num = 0;
42 my $region_length = $atts->{length};
43 while ( $atts->{"source-".$num} ne "" ) {
45 if ($region_length > $self->{Sources}->{$atts->{"source-".$num}}->{calculated_length} ) {
46 $self->{Sources}->{$atts->{"source-".$num}}->{calculated_length} = $region_length;
49 $num++;
53 if ( $element->{Name} eq "Regions") {
54 $self->{InRegions} = 1;
55 #print "In regions\n";
61 sub end_element {
62 my $self = shift;
63 my $element = shift;
65 if ( $element->{Name} eq "Regions") {
66 $self->{InRegions} = 0;
67 #print "Out of regions\n";