Greg Kurka
Composer
gregkurka@gmail.com
Greg utilizes Cubase functions and Python scripting to convert MIDI files into the JSON format required for Piano Tiles 2. The following section provides a detailed overview of these processes and achievements.
I created a python script for converting midi files into the JSON format required for Piano Tiles 2 early this year, and I've made several small improvements on it over time. When I first started working with Piano Tiles, I worked with an editor, inputting each note, and slowly realized I could do things faster if I was able to work in my preferred Digital Audio Workstation (Cubase) and then bring it over to the editor after I was done there. That way, I could play notes using my keyboard, quantize parts, run Cubase functions, and bring in public domain midi files when tackling classical pieces.
This is the Kooapps editor for piano tiles that exports JSON files for working with the game.
There are several ways a piece in Piano Tiles differs from a midi file. Midi files are a series of numerous messages over a given delta time. The most essential messages for what we are doing in Piano Tiles are the Note On and Note Off messages. These contain which note is turning on and which note is turning off at given times.
The Piano Tiles' JSON files are lists of Notes and their lengths, as well as information about what kind of tiles are given, and some other information such as tempo data, and game driven data.
The trickiest parts are dealing with polyphony (multiple notes at the same time) and complicated rhythms (such as triplets). In the JSON files, any notes that start at the same time, must end at the same time, unless they are in different tracks. Also, regular tiles cannot be smaller than the "Base Beat", so if the base beats are set to "0.25", or sixteenth notes, then anything smaller than a sixteenth note must involve special tiles. Special tiles require other circumstances. Double tiles need two tiles that are half of the base beat next to each other. Sliders require several tiles that are smaller than base beats. Other special tiles, like accompaniment tiles, require other specifics: a long note in track one, and notes that are equal to or larger than the base beat in track two.
In midi files, notes can fall at any point for any length in any track. Therefore, using cubase, I quantize notes to create "perfect" rhythms, and run functions to ensure notes start and end at the same time in the same track, and move notes to other tracks as necessary.
It is also important to note that when writing pieces, or choosing classical pieces to convert, I must take into account that most tiles should be "regular" tiles, or tiles equal to the base beats, with some tiles longer, and some tiles shorter that involve special tiles. Certain tempos paired with base beats make the tiles move too fast on the screen, so, for instance, if a piece has a tempo between 60 and 90, then there should not be too many notes smaller than "0.25" or a sixteenth note in 4/4 time.
Any notes that are not exactly divisible by 0.125 (equal to a 32nd note in 4/4 time), must be processed as a tuplet, and will appear as a single tile with multiple notes. Therefore, pieces with an excess of triplets are not applicable as they will create an excess of long tiles with numerous notes in them.
There are two different sound samples that play in piano tiles.A short piano sound and a longer piano sound. These sounds are always the same amount of loudness.This must be taken into account when composing and choosing songs, as light playing is not an option. The short sounds are always of the same length, so sometimes they can mush together, and sometimes the long sound will not be held long enough on very long tiles.
Therefore, my workflow for writing an original piece is playing and composing using my keyboard in Cubase, then quantizing notes to perfect lengths, ensuring that anything note with a smaller rhythm than the base beats meet special note criteria. I also seperate the initial file into three parts, as there are three sections in each Piano Tile level.
Then after exporting, I run my script, and it is ready to be imported into the Piano Tiles Editor. From there, I can add special tiles to the spots that are ready for them and I can export the finished JSON file.
Essentially, the script that I wrote converts delta time between note on and note off messages to exact lengths, such as "0.25" or a sixteenth note in 4/4 time. It is able to deal with tuplets manually by allowing me to choose how many notes belong in certain tuplets. It also detects rests, which are not messages in midi files, and must be derived from the data. The script also creates the BPM, sets the base beats, parses through different tracks of the midi file, and ignores unneeded messages. I use the library Mido for opening the midi tracks, and generating midi messages from midi files, then calculate delta times, and detect rests, and output in the required JSON format.
Midi Messages given through the Mido Python Library
A short example of the JSON format for Piano Tiles
The midi parser in action, creating a load javascript file for the editor.