Skip to main content

Python General MIDI representation for symbolic music data analysis

Project description

pygmidi logo

pygmidi

A general representation for MIDI files for symbolic music data-driven approaches

MIDI files are a common way to represent symbolic music. pygmidi (Python General Midi) is a facade for the most used python packages focused on midi files manipulation, so it can used transparently. For now, it includes:

  • midi Pattern
  • PrettyMidi
  • pianoroll Multitrack
  • MidiFile
  • MidiArray: a new minimalistic representation that uses only an array and a list of instruments, allowing to easily have a tensor representation of the midi file aimming machine learning purposes

New Features:

  • Methods to automatically orchestrate and slice midi files to help pre-processing midi data
  • sparray is a sparse array representation for efficient disk saving purposes with which you may save and load tensor representated midi files for both time and space efficiency
  • Set of evaluation tools for variable sized sequences of pianoroll blocks and metrics for music evaluation
  • A lot of different ways to export to jpg, gif and wav formats (comming exporting to PDF)

Instalation


$ git clone https://github.com/LESSSE/pygmidi
$ cd pygmidi
$ pip install . --user

Typical Use


    #!/usr/bin/env python

    from pygmidi import pygmidi
    g = pygmidi("path_to_midifile.mid")

    g.transpose(-1)
    g.to_npz("new_npz_path")
    g.to_gif("new_gif_path")

For processing midi files in a directory


    #!/usr/bin/env python

    from pygmidi import pygmidi,utils,midiarray
    from glob import glob
    from os import path

    programs_map = {('woods',False): 0,
                ('brass',False): 1,
                ('percussion',True): 2,
                ('timpani',False): 3,
                ('chromatic_percussion',False): 4,
                ('voices', False): 5,
                ('guitars',False): 6,
                ('basses',False): 6,
                ('strings',False): 6,
                ('keyboards',False): 7}

    #Tracks_map is the configuration for the new orchestrated tracks
    tracks_map = [{'program':71,'is_drum':False,"name":"woods"}, #woods
                {'program':60,'is_drum':False,"name":"brass"}, #brass
                {'program':0,'is_drum':True,"name":"percussion"},  #percussion
                {'program':47,'is_drum':False,"name":"timpani"}, #timpani
                {'program':14,'is_drum':False,"name":"tubular bells"}, #tubular bells
                {'program':52,'is_drum':False,"name":"voices"}, #voices
                {'program':48,'is_drum':False,"name":"strings"}, #strings
                {'program':1,'is_drum':False,"name":"piano"}] #piano

    for i in glob('{}/*.mid'.format("midi")):
         a = pygmidi.process(songs[0],
                  i_to_t=programs_map,
                  t_to_i=tracks_map,
                  ticks=4*24*4,
                  transpose=(0,1))
         utils.sparray.save("{}/{}.npz".format("npz",path.splitext(path.basename(i))[0]),a)

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

pygmidi-4.0.1.tar.gz (24.3 kB view details)

Uploaded Source

Built Distribution

pygmidi-4.0.1-py3-none-any.whl (24.3 kB view details)

Uploaded Python 3

File details

Details for the file pygmidi-4.0.1.tar.gz.

File metadata

  • Download URL: pygmidi-4.0.1.tar.gz
  • Upload date:
  • Size: 24.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.4

File hashes

Hashes for pygmidi-4.0.1.tar.gz
Algorithm Hash digest
SHA256 5eda8db0e51f27bb61510246564bbe677e91e36ebdf36a90bb7823ce39005f2f
MD5 5493a574c88a57259313a978a9d506bc
BLAKE2b-256 b9592ca42bd01fa417b2305b04b5dfcf3b53eb71884dd1b1283aa5c5c27637bf

See more details on using hashes here.

File details

Details for the file pygmidi-4.0.1-py3-none-any.whl.

File metadata

  • Download URL: pygmidi-4.0.1-py3-none-any.whl
  • Upload date:
  • Size: 24.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.4

File hashes

Hashes for pygmidi-4.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6bfab99104b6384cd8c5c6a82e660fcf3cf3e70390eedcf75c794599d838b761
MD5 d8eb1168bc8c1764a09fc140cec5609c
BLAKE2b-256 dc3e060f5ebf9f5ee52e9581f3c7f1a7de80d35906a95ec2bcbbc7a38a931788

See more details on using hashes here.

Supported by

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