View on GitHub

arc2midi

convert microsoft makecode arcade song assets into type 1 midi files

Open this page at https://musiciancoder2762.github.io/arc2midi/

Use as Extension

This repository can be added as an extension in MakeCode.

Edit this project

To edit this repository in MakeCode.

Metadata (used for search, rendering)

arc2midi documentation

contents:

warning: this is an extremely early release and it is not fully released yet. arc2midi as of right now is unable to convert any song that contains percussion.

installation

copy the arc2midi link (https://github.com/musiciancoder2762/arc2midi) and then go to the extensions button at the left side of your code (where the music, sprite, math, logic, etc. sections are located). there will be a search input above the extensions and paste said link in there.

usage

to create a midi file, call the function createMIDI inside of namespace arc2MIDI. for example: to convert the song asset “song 1” into midi, write the following line of code

``arc2MIDI.createMIDI(assets.song`song 1`);``

note: the traditional way of playing a song saved in the game assets involves the conversion of the song asset to a music.Playable song (when using music.play()). arc2midi doesn’t need this conversion.

the following function above will print a message in the console. said message is the midi file’s contents encoded in base64*
*the base64 encoding can be disabled by setting the arc2MIDI.b64output variable to false. this will set the encoding to hexadecimal characters (e.g. 0123456789abcdef). see “advanced extra info.”

after printing the message into the console, copy said message and paste the message into HexEd.it. When pasting said base64 message, HexEd.it will prompt you with this interface.
select the “Create a new file” option and click the “Binary Data / Text” option to display a series of different interpretations.

select the “Base64 encoded” option.
after pasting the base64 data, press “Save as” and save your file. make sure the file ends with .mid for it to be recognised by midi-interpreting software.

potential errors & solutions {#potential-errors-&-solutions}

one potential error that is possible to encounter upon usage of this extension is
Cannot read properties of null (reading ‘data’)
(ignore at <main> line 1)
this error is reproduced when you try to convert a non-existent file (which returns null or undefined by default). potential solutions include

*due to the way microsoft makecode arcade interprets code, it makes sure that main.ts is always last to execute, after everything is loaded. The pxt.json file is responsible for the order of files to be executed. edit the file as text and rearrange the file where the createMIDI function is being called so that it is the last to execute.

advanced extra info

when using the arc2MIDI namespace, you will find 2 variables, tick480 and b64output.
![][image4]
the tick480 variable is a boolean value that allows the user to change the tick rate of the midi file*.
The b64output variable is also a boolean value that allows the user to encode the midi file into base64**.

*most midi files have their tick rate set to 480 ticks per quarter note, which makes this variable enabled by default. if this variable is disabled (by setting it to false), it sets the tick rate to the song asset’s tick rate (usually 8-16 ticks per whole note or 2-4 ticks per quarter note).
**base64 uses 6 bits per character to store encoded data, which makes it more compact and efficient than hexadecimal encoding, which uses 4 bits. this variable is also enabled by default as a result of this.