Blogs-Midi2Tiles

Midi2Tiles

GitHub last commit (branch) GitHub closed issues GitHub pull requests

Github: link

Synthesia is a program for piano notes visualization. Notes are represented as tiles and appers in the chronlogoical order. On top of that, it also helps piano novice to learn to play music by pressing the corresponding keys within the sheet music visualization. For composers, it serves as a tool to convert MIDI files into elegant piano tiles videos. The videos can futher be employed in video compositing programs, such as After Effects, Premiere Pro... to create an overlay on the original film. Here is an example:

Nonetheless, to output mp4 files from midi, we are required to purchase Synthesia, which is totally not worth it, since only the video output function is used.

To solve this problem, I implemented a simple version of piano tiles video maker. All you need is to prepare your midi file and run the python code to generate your own synthesia-like video.

Installation

pip install midi2Tiles

Usage

# some video settings VIDEO_DPI = 1000 VIDEO_FPS = 60 VIDEO_WIDTH = 1080 VIDEO_HEIGHT = 720 # the proportion of keyboard display KB_RATIO = 0.1 # speed of the falling tiles (pixels per sec) # notice that this value also affect the height of each tile TILE_VELOCITY = 500 from midi2Tiles import pianoTileCreator ptc = pianoTileCreator.PianoTileCreator(video_width=VIDEO_WIDTH, video_height=VIDEO_HEIGHT, video_dpi=VIDEO_DPI, video_fps=VIDEO_FPS, KB_ratio=KB_RATIO, tile_velocity=TILE_VELOCITY, key_color="green", showKeyVelocity=True) ptc.loadMidiFile("<input midi file>",verbose=True) ptc.render("<output video file>",verbose=True)

Parameters for output video

  • video_width (int): the width of the output video (px)
  • video_height (int): the height of the output video (px)
  • video_dpi (int): the dpi of the output video (px)
  • video_fps (int): the fps of the output video (px)
  • KB_ratio (float): the proportion of the piano keyboard display. This value should be in [0,1)
  • tile_velocity (int): the velocity of the falling tiles
  • key_color (string): the color of the tiles
  • showKeyVelocity (bool): if True, the velocity of midi notes will affect the opacity of the tiles

Acknowledgement

The ratio of the piano design is referenced from https://github.com/gin66/piano_keyboard

© 2023,By Ian Shih