get_midi_length(3)

πŸ“¦ version 4.4.3.1, in fedora 43, fedora 44

πŸ’– get_midi_length β€” Allegro manual, bestie edition πŸ’–

okay so you're in the get_midi_length(3) page of the Allegro manual, and honestly? this one is a little bop. it's about finding out how long a MIDI is gonna play for. let's get into it πŸŽ€


✨ NAME ✨

get_midi_length β€” figures out the total playing time of a midi, in seconds. it's giving Allegro game programming library realness 🎡


✨ SYNOPSIS ✨

#include <allegro.h>

int get_midi_length(MIDI *midi);

✨ DESCRIPTION ✨

so basically this function simulates playing the given MIDI from start to finish just to work out how long it takes to play. no cap, it really does sit there and mentally run through the whole thing for you. 🧚

once you've called it, two things happen and they're lowkey important:

  • midi_pos will hold the negative number of beats 🫢
  • midi_time will hold the length of the midi, in seconds ⏱️
⚠️ heads up bestie: any midi that's currently playing gets stopped the moment you call this. so don't be out here calling it mid-vibe and then wondering why the music died 😭

the usual move is to call it before play_midi, so you already know the length of the thing you're about to play. like this:

length = get_midi_length(my_midi);
play_midi(my_midi);
do {
   pos = midi_time;
   textprintf_ex(screen, font, 0, 0, c, -1, "%d:%02d / %d:%02d\n",
      pos / 60, pos % 60, length / 60, length % 60);
   rest(100);
} while(pos <= length);

that's the whole "current time / total time" display situation. iconic honestly πŸ’…


✨ RETURN VALUE ✨

it returns the value of midi_time β€” aka the length of the midi. that's it, that's the tea πŸ“


✨ SEE ALSO ✨


and that's the page!! go forth and time your midis, queen πŸ‘‘ this was get_midi_length(3) from the Allegro manual, version 4.4.3 β€” mwah, catch you in the next one πŸ¦‹πŸ’œ

πŸ“¦ where this page comes from