Re: shorten midi file
[email protected] ("Noel Lairson") Fri, 31 Jan 2003 17:31:57 -0800
| Newsgroups | perl.midi |
|---|---|
| Message-ID | <001c01c2c991$b6035db0$afe9fea9@fido> |
I've actually done a similar script based on Sean's midiparse script.
You have to do delta-time math.
It's not fun.
If there are tempo changes involved, it will be much less fun.
midiparse outputs in MIDI::Opus format, so you generally get a list of:
[event, delta time, parameters]
so dump these references into an array while adding up delta times.
something like:
while($input = <IN>) {
chomp $input;
while ($time < '60') {
push(@out, $input);
$tics += $input[$delta_time_address_in_array]; #I don't remember; this
might be an array reference
$beats = $tics/$tics_per_quarter_note #(you'll need to strip this out of the
['tics' 0, $value] field, and adjust for time signature if you're not in 4/4
of 3/4 or whatever));
$time = int($beats/$bpm);
}
}
If there are tempo or time changes, you need something in the loop that
looks for them and fixes other variables accordingly. There will also need
to be a way to capture the remaining 'note off' events.
Then parse it back into MIDI::Simple format (be sure to do "Tempo(whatever
the 'tics' setting was on the dump)" or all the time will be off) and output
it into its own file name.
That's how I'd do it if I HAD to use Perl; I'm sure there's WAY BETTER ways
to do it.
Good luck though; have you looked for a free or shareware midi editor?
Noel
----- Original Message -----
From: "Sean M. Burke" <[email protected]>
To: "Nandita Shenvi" <[email protected]>; <[email protected]>
Sent: Friday, January 31, 2003 3:22 AM
Subject: Re: shorten midi file
> At 10:09 AM 2003-01-31 +0100, Nandita Shenvi asked:
> >[...]I have midi files and I need to shorten them i.e I recquire only the
> >initial 1 min of the song.[...]
>
> I am curious about this question too -- or actually in the more general
> question of "how do you turn MIDI tick-times into seconds?".
>
> As I was writing MIDI-Perl, I thought I understood how this all worked,
but
> then I learned that there were tempo-change events, and that seemed really
> hard to think about. Since I writing a parse and not a sequencer, I
> decided that I could just ignore the whole issue. But I'm still curious
> about it.
> Anyone know how this works?
>
> --
> Sean M. Burke http://search.cpan.org/~sburke/
>