Coder Social home page Coder Social logo

mathigatti / midi2img Goto Github PK

View Code? Open in Web Editor NEW
60.0 3.0 14.0 30 KB

MIDI to image and image to MIDI conversion scripts

Home Page: https://mathigatti.com/2019/06/02/midi2text-midi2image/

License: MIT License

Python 100.00%
midi python song midis

midi2img's Introduction

MIDI to Image conversion

Convert MIDI files into piano roll images and back with this Python script.

Demo

Here is a video demonstration using the program to generate midis and images, then we use it for an artistic performance.

IMAGE ALT TEXT HERE

Implementation Details

This script relies on the music21 library to parse and create MIDI files. The expected images are black and white and have a fixed size of 106 rows and 100 columns. 106 is the number of different notes (From 21 (A0) to 127 (G9)) and 100 is the length of the song, if a song is longer than that the script splits the song and generates several images. Each image represents one instrument, if a song has several instruments different images are generated for each. Each pixel represents a note played for 1/4 beats, this can be changed with the resolution variable.

Requirements

  • python 3
  • python packages (Try something like: pip install -r requirements.txt)
    • music21
    • imageio
    • numpy
    • Pillow

Usage

There are two scripts, one for converting a MIDI into images and the other one to convert an image into a MIDI.

MIDI to Image

REPETITIONS is an optional parameter which indicates, in case the song is too long, how many parts of the song to convert into an image. If it is 1 it only extracts the first part of the song. If you don't specify it then it generates as many images as needed to cover all the song.

python midi2img.py MIDI_FILE_PATH REPETITIONS
python midi2img.py samples/zelda.mid 1

Using the sample zelda midi the generated image for the first part of the song looks like this

Image to MIDI

Converts image of size (106,100) into a midi file.

python img2midi.py IMAGE_PATH
python img2midi.py samples/image.png

Using the image from the sample folder it generates as expected a midi file with decreasing and increasing notes.

midi2img's People

Contributors

mathigatti avatar savin000 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.