MusicTheoryLib Documentation

Convenient music theory utilities for GameMaker.

MusicTheoryLib is a collection of music theory GML utilities. It can help you convert from scientific note notation to MIDI note number to frequency, and any other combination of directions between these. It can also find the nearest note to a given frequency, calculate note lengths for given BPMs and divisions, and determine pitch multipliers to get from one note to another.

A note on notation

In a few places, MusicTheoryLib accepts and returns notes in scientific notation (also known as scientific pitch notation). In short, this is just a way to describe a specific musical note or pitch. It is written as the note name (A, B, C, etc.), optionally followed by an accidental (♯ or ♭), and ending with the octave number. Some examples are A4, C#3, Db5. To make things simpler, MusicTheoryLib only supports sharps (#) as accidentals.


Frequency getters

mt_midi_note_frequency(note_number, [a])

Get the note frequency for a given MIDI note number

mt_midi_note_frequency

mt_note_frequency(note)

Get the frequency of a note given its scientific notation, which is a string containing the letter, an optional sharp (#), and the octave number.

mt_note_frequency

mt_note_frequency_ext(note_letter, octave, [sharp])

Get the frequency of a note given its letter, octave, and sharpness

mt_note_frequency_ext

mt_precalculate_all_frequencies()

This function will precalculate all MIDI frequencies into an array

mt_precalculate_all_frequencies

MIDI note number getters

mt_midi_note_number(note)

Get the MIDI note number for a given note in scientific notation

mt_midi_note_number

mt_midi_note_number_ext(note_letter, octave, [sharp])

Get the MIDI note number for a given note letter, octave, and sharpness

mt_midi_note_number_ext

Note getters

mt_note_from_number(note_number)

Get the note name for a given MIDI note number

mt_note_from_number

mt_note_from_frequency(frequency)

Get the closest note information for a given frequency

mt_note_from_frequency

Parsing

mt_note_scientific_parse(note)

Takes a note's scientific notation and returns its letter, octave, and sharpness

mt_note_scientific_parse

Note lengths

mt_get_note_length(bpm, division)

Returns the length of a note division in seconds, given a bpm (treating one quarter note as a beat)

mt_get_note_length

mt_get_note_total_length(bpm, note_divisions)

Returns the length of an array of note divisions in seconds, given a bpm

mt_get_note_total_length

Pitch

mt_frequency_pitch(root_note, target_note)

Returns the pitch multiplier you need to play a sound with a target note as the same frequency as a root note

mt_frequency_pitch

Index

Frequency getters

  • mt_midi_note_frequency(note_number, [a]) - Get the note frequency for a given MIDI note number
  • mt_note_frequency(note) - Get the frequency of a note given its scientific notation, which is a string containing the letter, an optional sharp (#), and the octave number.
  • mt_note_frequency_ext(note_letter, octave, [sharp]) - Get the frequency of a note given its letter, octave, and sharpness
  • mt_precalculate_all_frequencies() - This function will precalculate all MIDI frequencies into an array

MIDI note number getters

  • mt_midi_note_number(note) - Get the MIDI note number for a given note in scientific notation
  • mt_midi_note_number_ext(note_letter, octave, [sharp]) - Get the MIDI note number for a given note letter, octave, and sharpness

Note getters

  • mt_note_from_number(note_number) - Get the note name for a given MIDI note number
  • mt_note_from_frequency(frequency) - Get the closest note information for a given frequency

Parsing

  • mt_note_scientific_parse(note) - Takes a note's scientific notation and returns its letter, octave, and sharpness

Note lengths

  • mt_get_note_length(bpm, division) - Returns the length of a note division in seconds, given a bpm (treating one quarter note as a beat)
  • mt_get_note_total_length(bpm, note_divisions) - Returns the length of an array of note divisions in seconds, given a bpm

Pitch

  • mt_frequency_pitch(root_note, target_note) - Returns the pitch multiplier you need to play a sound with a target note as the same frequency as a root note

Enums

  • NoteDivision
    • WHOLE
    • WHOLE_DOTTED
    • WHOLE_TRIPLET
    • HALF
    • HALF_DOTTED
    • HALF_TRIPLET
    • QUARTER
    • QUARTER_DOTTED
    • QUARTER_TRIPLET
    • EIGHTH
    • EIGHTH_DOTTED
    • EIGHTH_TRIPLET
    • SIXTEENTH
    • SIXTEENTH_DOTTED
    • SIXTEENTH_TRIPLET
    • THIRTY_SECOND
    • THIRTY_SECOND_DOTTED
    • THIRTY_SECOND_TRIPLET
    • SIXTY_FOURTH
    • SIXTY_FOURTH_DOTTED
    • SIXTY_FOURTH_TRIPLET