get_midi_length(3alleg4)

✨ get_midi_length ✨

ok so this is from the Allegro manual bestie, it's get_midi_length(3alleg4) and it's literally about figuring out how long a midi is gonna play for. Allegro game programming library energy πŸŽ€


🌸 NAME 🌸

get_midi_length β€” Determines the total playing time of a midi, in seconds. Allegro game programming library. πŸ’–


πŸ¦‹ SYNOPSIS πŸ¦‹

#include <allegro.h>

int get_midi_length(MIDI *midi);

πŸ’… DESCRIPTION πŸ’…

okok so what this function does is it simulates playing the MIDI you hand it, start to finish, just to figure out how long it takes to play. like it's doing a full run-through in its head bestie, no cap 🧠✨

Once you've called it, two things get updated:

  • midi_pos will contain the negative number of beats
  • midi_time will contain the length of the midi, in seconds
🚨 heads up bestie: any currently playing midi is stopped when you call this function. it does not care. it will end it. periodt πŸ’€

So the move is usually to call it before play_midi, so you already know how long the thing you're about to play is gonna be. like this, fr fr:

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);

look at that progress bar-adjacent glow up 😭 it's giving main character energy fr 🫢


⭐ RETURN VALUE ⭐

Returns the value of midi_time, which is the length of the midi. so like, the answer. the whole point. slay πŸ‘‘


🌈 SEE ALSO 🌈


and that's the whole vibe bestie, go make some music timing magic πŸŽ€βœ¨πŸŒΈ

Allegro β€” version 4.4.3 β€” get_midi_length(3alleg4) πŸ’œ byeee πŸ¦‹