Re: midi re-tempoizer

[email protected] (Jean-Pierre Vidal) Thu, 9 Dec 2004 22:00:41 +0000
Newsgroups perl.midi
Message-ID <[email protected]>
Le jeudi 9 D=E9cembre 2004 11:08, zentara a =E9crit=A0:
> On Wed, 8 Dec 2004 21:02:54 +0000, [email protected] (Jean-Pierre
> Vidal) wrote:
>=20
> >Le vendredi 3 D=E9cembre 2004 10:18, zentara a =E9crit=A0:
> >> Cool. This is a much asked for utility.
> >>=20
> >> I've been wracking my brain trying to figure out how to
> >> get the total playlength of a midi using Perl.
> >>=20
> >> Would anyone know how to do this?
> >
> >Here is a new one, which use MIDI::Score
> >
> >#!perl -w
> >use strict;
> >use diagnostics;
> >use MIDI;
> ......
>=20
> >It works for almost of my midifiles.=20
> >Unfortunately, it doesnt work for some midifiles, failing with a diagnos=
tic=20
> >like this:
> >
> >
> >I'll search what is wrong with these files and MIDI::Opus
> >
> >Jean-Pierre
>=20
> Your script runs without error for me, and on some midi
> files gives the correct time.=20
>=20
> But I often get
> 0 mn 0.0 s
> as output.
>=20
> From a quick check of differences between files that work, and
> those that give  0 0, it seems the problem is with midi files that
> have NO 'set_tempo' in them.
> I put a print in to test various files
>      for my $note (@$score_r) {
>               if($$note[0] eq 'set_tempo'){print $$note[0],"\n"}
>=20
> and if it had no set_tempo, I get  0 0 output.
>=20
> So maybe set a default tempo?

You are the winner!
Obviously :-(, according to MIDI specs, "If there are no tempo events in a=
=20
MIDI file, then the tempo is assumed to be 120 BPM".
This is 120 quarter note per mn, or 0.5 s per quarter note.
So we need to initialize $tempo =3D .5; instead of $tempo =3D 0; (line 30) =
and all=20
will work right.

RTFM: read the specs, read the specs,  read the specs, :-)
Jean-Pierre

>=20
> I think you are on the right track, in detecting 'set_tempo' events
> to adjust the note playlength.
>=20
> It seems like you are sooooo close. :-)
>=20
>=20
>=20
>=20
> --=20
> I'm not really a human, but I play one on earth.
> http://zentara.net/japh.html
>=20
>=20