Skip to main content

Midi Insights: midi analyzer

Project description

MIDI Insights

This package inherits MidiFile of mido, adding note duration quantization functionality MidiFile.quantize and improving the MidiFile.print_tracks method.

import midii

mid = midii.MidiFile(
    midii.sample.dataset[0], # or 'song.mid'
    lyric_encoding="cp949"
)
mid.quantize(unit="32")
mid.print_tracks()

Installation

pip install midii

API

midii.sample

midii.sample: It contains some sample midi files.

  • dataset: List object that contains some midi dataset for deep learning model. The lyric encoding of these midi files is "cp949" or "utf-8"

  • simple: List object that contains some simple midi dataset. It is artificially created midi file for test purpose.

midii.quantize

midii.quantize(ticks, unit="32", ticks_per_beat=480, error_forwarding=True): quantization function

class midii.MidiFile

class midii.MidiFile(filename=None, file=None, type=1, ticks_per_beat=480, charset='latin1', debug=False, clip=False, tracks=None, convert_1_to_0=False, lyric_encoding='latin-1')

The parameters of this class are no different from those of the mido.MidiFile class it inherits, except for convert_1_to_0=False and lyric_encoding='latin-1'.

If you want to convert midi file type 1 to 0, pass convert_1_to_0=True.

lyric_encoding specify encoding of lyric data.

  • quantize(unit="32"): Quantize note duration. You can define least unit of quantization from "1"(whole note), "2"(half note), "4"(quarter note), "8"(eighth note), "16"(sixteenth note), "32"(thirty-second note), "64"(sixty-fourth note), "128"(hundred twenty-eighth note), "256"(two hundred fifty-sixth note)

    The smaller the minimum unit, the less sync error with the original, and the weaker the quantization effect. As the minimum unit becomes larger, the sync error with the original increases and the quantization effect increases.

  • print_tracks(track_limit=None, print_note=True, print_time=True, print_lyric=False, track_list=None, print_note_info=False): An overriding function that improves the existing mido.print_tracks.

    By default it will print all lines of track. By setting like track_limit=20, You can define upper bound of lines to be printed.

    By default it will prints all tracks. You can specify the tracks you want to output in the list track_list. For example, track_list=[], or track_list=["piano", "intro"].

midii.duration_secs_to_frames

midii.duration_secs_to_frames(note_duration_sec, sr=22050, hop_length=512): convert times to frames with handling rounding error

Example

print_tracks

  • print_tracks: mido.MidiFile.print_tracksmidii.MidiFile.print_tracks

quantize

  • quantize(unit="32"):

    The smaller the minimum unit, the less sync error with the original, and the weaker the quantization effect.

    As the minimum unit becomes larger, the sync error with the original increases and the quantization effect increases.

Figure

quantization effect(piano roll)

EF effect(time drift mitigating)

timing deviation for each quantization units

License

MIT

TODO

  • quantization 수행 공간이 discrete 한 경우 error 가 커지는 것을 확인하여, continuous 한 공간에서 진행되어야 에러가 없을듯.
  • quantize 함수 tick 단위가 아니라 일반적인 단위어도 되도록 일반화

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

midii-0.1.29.tar.gz (2.4 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

midii-0.1.29-py3-none-any.whl (28.7 kB view details)

Uploaded Python 3

File details

Details for the file midii-0.1.29.tar.gz.

File metadata

  • Download URL: midii-0.1.29.tar.gz
  • Upload date:
  • Size: 2.4 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.10

File hashes

Hashes for midii-0.1.29.tar.gz
Algorithm Hash digest
SHA256 9bc18a2163ecdb205161906a1e6d4e16a5da0e0b98b62a6459c93f496d74fe15
MD5 3df4d45310a281a9927c94ee20761996
BLAKE2b-256 b3e2904e9423d38633c40f9e3b7a209eef1721967f0684ee03ee92de86c33a3b

See more details on using hashes here.

File details

Details for the file midii-0.1.29-py3-none-any.whl.

File metadata

  • Download URL: midii-0.1.29-py3-none-any.whl
  • Upload date:
  • Size: 28.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.10

File hashes

Hashes for midii-0.1.29-py3-none-any.whl
Algorithm Hash digest
SHA256 a730ec32924c1fe991f1304926b4f2e910a5401283c6f8bb233e6bcc7c2b48dd
MD5 bfcf2c3156a263e31c2d513d78b426bd
BLAKE2b-256 4cba25f79012a1ab0774c4b62d7f5b0590cbd24ce699878c4262196517f8351c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page