Json2midi

## json2midi.exe

Json2midi is a commandline program that can convert Piano Tiles 2 songs to MIDI Files.

It is a vice-versa of midi2json, made by the same developer.

MIDIs generated by this program have TPQN = 960 and BPMs = TPM/2.

Source code &download link is available here.

~~It ALSO be used by command for Discord bot - Volian1.~~

**As of August 2023, this is the only way you can mod something with Piano TItle 2.**

**Due to the removal of the Volian1 Discord bot, here is a very dedicated tutorial with errors and fixes on how to convert.**

## Requirements& Installaion

### Require:

**Windows System**, recommend 64 bit windows 10+ with a not potato PC.

Knowledge of CMD.exe's commands,usage of microsoft excel, usage of batch filesystem.

git command, g++ command support (require application)

json files you want to convert.

Patience

Have a good eyes.

### Install stages:

Install cygwin and its dependencies using this tutorial

Install git

Run **Cygwin terminal**,run these commands.

`git clone https://github.com/Volian0/json2midi`

`cd json2midi`

`g++ src/*.cpp -std=c++11 -o json2midi`

## Usages

There are 3 ways to use this program.

For these commands, they MUST be ran on windows's command prompt, or powershell,others will not execute.

> *Therefore, you have to change to the directory contain this file*
>
>

* You can find what commandline program will not work by typing `ls`. That will output instead of error
* Ms-DOS is too outdated to use.

### Automatic:

If the JSON file contains bpms and baseBeats, you can just simply pass the filename as parameter.

```
json2midi song.json

```

#### Specifing detailed location:

`json2midi "C:\new folder\folder 1\việt trì\song.json"`

`json2midi "my song.json"`

### Manual

In this mode, you need to specify all required bpms and baseBeats for each part.

E.g: the `song.json` consists of 3 parts.

```
json2midi song.json 120 0.25 122 0.25 124 0.5

```

### **~~Using music\_json.csv~~**

~~You can convert the entire CSV by passing it as parameter. You can't convert CSVs using Volian1 bot.~~

```
~~json2midi music\_json.csv~~

```

**The latest version of PT2's *music\_json.csv* had some issues,and thus the tool can't properly convert, see alternative insturction below.**

## Output:

If there is just a song's name(if you used "location\music.json" then it also outputting the full location as well), then it should be converted successfully. THe midi will be in the same location as the JSON file

If there appears to be an error, then it will not convert (sometime it actually will, rarely,depend on songs). These songs usually do not provide the bpm in the song parts (although it did provide but before the part's code actually start), especially challenges. There are about 100 songs (or song in the old version of PT2) does not have it in code.

Some songs can output even having too much errors, for example: Flight of the Bummble Bee, all 3 tracks having issues but still managed to output a midi fileneed someone compare to real game

## Error&Fixes

> ***If the song managed to output, it is better to hear it first and compare to the original one, rather than debugging and fixing.***
>
>

### G++ not found

Install cygwin correctly using this tutorial. At the end of the installion setup,click add cygwin terminal to desktop. Run that program.

### DLL not found

copy your missing dlls from C:\cygwin\bin (default installion location for cygwin/or you specify) into C:\windows\system32

### json2midi not recognized as command/command not found...

if you used cygwin terminal and then run git command, location for json2midi will be at C:\cygwin64\home\yourpcusername\json2midi. recommend putting it to your desktop. open that folder(the one must have json2midi.exe) on your desktop, at the file explorer taskbar, type in CMD then enter. once a window pop up, the first thing you see will look like this:

```
Microsoft Windows [Version 10.0.19044.2846]

(c) Microsoft Corporation. All rights reserved.

C:\cygwin64\home\yourpcusername\json2midi>
```
if you type `dir json2midi.exe` `and get this:`

```
C:\cygwin64\home\yourpcusername\json2midi>dir json2midi.exe

Volume in drive C has name of your disk.

Volume Serial Number is your disk serial number

Directory of C:\cygwin64\home\yourpcname\json2midi

created date created time     615.120 json2midi.exe

               1 File(s)        615.120 bytes

               0 Dir(s)  disk space left bytes free
```
then you should be able to run commands OK now.
Another way is to make a batch file (eg: file.bat) that has content like this:

```
@echo off

cd location of your json2midi.exe

json2midi "your song.json"

json2midi "your song 2.json"

...
```
doing so will help you edit easier&convert thousand files at once

### Part X missing basebeats/exeception

if any of your parts is missing either bpm,basebeats, you have to run through all the parts,by using this command json2midi song.json BASEBEAT***P1*** BPM***P1*** BASEBEAT***P2*** BPM***P2*** ...To know how many parts, consider open your JSON file using notepad/VSCODE, Ctrl F, search for id,and how many it finds=how many parts.

### Exception

Wrong file names

Location to your scores have space/weird characters/your song has space

assumed your command is `json2midi c:\Users\My Song\Việt Nam\Your song.json`

This can be fixed by adding quote into your location, so it will be `json2midi "c:\Users\My Song\Việt Nam\Your song.json"` but it is highly recommended having no special characters.

### Duplicate , OR ;

download visual studio codes (unless you want to destroy your eyes) then open the json. pay attention to part that has this duplication.

Pay attention to the red lines, and the error section. There should be an unexpected comma or something else. Look for a suspicious , or ; or even missing quotes (") . This turns out to be not an easy task, especially with large songs such as the Beginner Challenge.

Rarely be able to output

Notes: since you are editing notes, ít have a high chance that it won't be looking like the real game, making completely random misplaces notes,etc.

### Duplicate tracks

Probably you put the basebeat and BPM longer than the total parts. Reduce until success

### Track so long

It will shrink down,however rare songs will have this,usualy on modded ones. However it kinda the same.

### Long ticks/having issue with ticks

Unknown way to fix, but still output. It seems almost simillar to the real game.

### std:out\_of\_range:

Need someone to debug, it seems the error coming from dlls,current fix is you need another pc/fresh windows os or try to reinstall cygwin

## Converting music\_json.csv

Currently it is unable to convert the list because i do not know why, this method will let you do so,by using the batch file commands written in error&fixes section.

Prepare all the json files by extracting the apk (or renaming the apk extension to ZIP) into a folder

Ctrl A, hold ctrl, right click, copy as path.

Open Microsoft Excel then paste all into A column

click the G1 column and write this command to excel's cmdbar: `="json2midi "&CHAR(34)&A1&CHAR(34)`

click the bottom right of the G1 till you see the + symbol, hold ctrl, scroll all the way to the last song.

your sheet now should look like this(notice i use B column but just pay attention to G and because I put all the json file to the same location as the json2midi.exe, I do not need the file location, and this is recommended for highest success, to remove file location you just need to use ctrl H, ơn the search box type c:\yourfilelocation\ , yes it must have the \ at the end and do not contain json files, then replace all):

copy all the G column and paste into the batch file you just created

run the file, and hold enter while it runs, it can take about 1 minutes for 700 songs.

use windows explorer checkbox, search \*.MID then move to another destination

### Notes:

* Converting lots of json files sometimes you have to wait for a while for the search box to fully index, to instantly copy all the midi to the destination,use:
	+ `xcopy *.mid "C:\destination folder" /y` (assumed you opened cmd in where the midi files is extracted
* watch out for your holdings, when the converter go to the end, it is recommended to click enter manually to avoid accidentally open 100 cmd tabs after the converter end its works