---
name: "get_midi_length"
section: "3alleg"
platform: "linux"
package: "liballegro-doc"
version: "2:4.2.2-2.2"
release: "Debian 6.0 (Squeeze)"
platforms: ["linux"]
url: "https://new.carta.tech/get_midi_length"
---

# get\_midi\_length(3alleg)

Determines the total playing time of a midi, in seconds. Allegro game programming library.

## 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

This function will simulate playing the given MIDI, from start to end, to determine how long it takes to play. After calling this function, midi\_pos will contain the negative number of beats, and midi\_time the length of the midi, in seconds.

Note that any currently playing midi is stopped when you call this function. Usually you would call it before play\_midi, to get the length of the midi to be played, like in this example:

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

## RETURN VALUE

Returns the value of midi\_time, the length of the midi.

## SEE ALSO

[**load\_midi**(3alleg)](/load_midi/3alleg.md), [**midi\_time**(3alleg)](/midi_time/3alleg.md), [**midi\_pos**(3alleg)](/midi_pos/3alleg.md), [**exmidi**(3alleg)](/exmidi/3alleg.md)
