source: gs2-extensions/music-ir/trunk/perllib/plugins/MusicIRPlugin.pm@ 22430

Last change on this file since 22430 was 22430, checked in by davidb, 14 years ago

Further development of MusicIR support to point where simple test collection could be built

File size: 3.8 KB
Line 
1###########################################################################
2#
3# MusicIRPlugin.pm -- for augmenting audio/midi files with Music IR
4# features and tags
5# A component of the Greenstone digital library software
6# from the New Zealand Digital Library Project at the
7# University of Waikato, New Zealand.
8#
9# Copyright (C) 1999 New Zealand Digital Library Project
10#
11# This program is free software; you can redistribute it and/or modify
12# it under the terms of the GNU General Public License as published by
13# the Free Software Foundation; either version 2 of the License, or
14# (at your option) any later version.
15#
16# This program is distributed in the hope that it will be useful,
17# but WITHOUT ANY WARRANTY; without even the implied warranty of
18# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19# GNU General Public License for more details.
20#
21# You should have received a copy of the GNU General Public License
22# along with this program; if not, write to the Free Software
23# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24#
25###########################################################################
26
27package MusicIRPlugin;
28
29use BasePlugin;
30use jAudioExtractor;
31
32use strict;
33no strict 'refs'; # allow filehandles to be variables and viceversa
34no strict 'subs';
35
36use gsprintf 'gsprintf';
37
38sub BEGIN {
39 @MusicIRPlugin::ISA = ('BasePlugin', 'jAudioExtractor');
40}
41
42my $arguments =
43 [
44 { 'name' => "compute_mir_features",
45 'desc' => "{BasePlugin.compute_mir_features}",
46 'type' => "enum",
47 'list' => [{'name' => "true", 'desc' => "{common.true}"},
48 {'name' => "false", 'desc' => "{common.false}"}],
49 'deft' => "false",
50 'reqd' => "no" },
51 { 'name' => "process_exp",
52 'desc' => "{BasePlugin.process_exp}",
53 'type' => "regexp",
54 'deft' => &get_default_process_exp(),
55 'reqd' => "no" }
56 ];
57
58my $options = { 'name' => "MusicIRPlugin",
59 'desc' => "{MusicIRPlugin.desc}",
60 'abstract' => "no",
61 'inherits' => "yes",
62 'args' => $arguments };
63
64
65
66sub new {
67 my ($class) = shift (@_);
68 my ($pluginlist,$inputargs,$hashArgOptLists) = @_;
69 push(@$pluginlist, $class);
70
71 push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});
72 push(@{$hashArgOptLists->{"OptList"}},$options);
73
74
75 my $jac_self = new jAudioExtractor($pluginlist, $inputargs, $hashArgOptLists);
76 my $base_self = new BasePlugin($pluginlist, $inputargs, $hashArgOptLists);
77
78 my $self = BasePlugin::merge_inheritance($jac_self,$base_self);
79
80 return bless $self, $class;
81}
82
83sub get_default_process_exp {
84 my $self = shift (@_);
85
86 return q^(?i)(\.mp3|\.wave?|\.aif[fc]?|\.au|\.snd|\.og[ga])$^;
87}
88
89sub begin {
90 my $self = shift (@_);
91 my ($pluginfo, $base_dir, $processor, $maxdocs) = @_;
92
93 $self->SUPER::begin(@_);
94 $self->jAudioExtractor::begin(@_);
95}
96
97
98
99# do plugin specific processing of doc_obj
100sub process {
101 my $self = shift (@_);
102 my ($pluginfo, $base_dir, $file, $metadata, $doc_obj, $gli) = @_;
103
104
105 my $outhandle = $self->{'outhandle'};
106 my ($filename_full_path, $filename_no_path) = &util::get_full_filenames($base_dir, $file);
107
108 if ($self->{'compute_mir_features'} eq "true")
109 {
110 my $utf8_filename_no_path = $self->filepath_to_utf8($filename_no_path);
111 my $url_encoded_filename = &util::rename_file($utf8_filename_no_path, $self->{'file_rename_method'});
112
113 my $features_filename = $self->compute_features($filename_full_path);
114 my ($features_ext) = ($features_filename =~ m/\.([^.]+)$/);
115
116 my $top_section = $doc_obj->get_top_section();
117
118 my $mime_type = ($features_ext eq "arff") ? "text/plain" : "text/xml";
119 $doc_obj->associate_file($features_filename, "jaudio.$features_ext",
120 $mime_type, $top_section);
121
122 }
123
124 #we have no text - adds dummy text and NoText metadata
125 $self->add_dummy_text($doc_obj, $doc_obj->get_top_section());
126
127 return 1;
128
129}
130
131
1321;
133
134
135
Note: See TracBrowser for help on using the repository browser.