whitlockjc / m8-js

JavaScript library for parsing Dirtywave M8 files, complete with a CLI for interacting with M8 files.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Import/output songs/instruments to JSON via CLI

dimatura opened this issue · comments

Hello, thanks for the great work! One feature that would be useful for people who are not good JS programmers like me is to export songs (.m8s) and instruments (.m8i) to JSON from the command line. That way it would be possible to say, export a song to JSON, manipulate the JSON data in some other language, and then convert that back into .m8s.

I'm imagining something like m8 song export foo.m8s foo.json and m8 song import foo.json foo.m8s, and analogous commands for .m8i.

I'm going to give this a shot and get your opinion before releasing it. Long story short, I have some thoughts around using M8 byte values in all places (like I could see a kind or type property in the generated Object to keep track of its type instead of a byte value).For example, would you rather see kind: WAVSYNTH or kind: 0x00 when an Instrument is turned into JSON? I'll start with the M8 approach and as I encounter places where we could make the JSON more human readable, I'll take note and share in the follow-up.

I'm leaning toward the following: Any place where the M8 UI shows a string value for its raw numerical value, we will have a read-only property (read-only in that its value is ignored when importing JSON) ending in {propName}Str that has the string representation of the numerical value. We need to make sure the exported JSON includes the raw value (to allow for import support) but the string representation would be useful as well.

I think having a string in addition to ints would be super useful! (Wouldn't be opposed to just having strings, and some kind of enum to map ints to strings and vice-versa, but having both also makes sense).

This was released today in m8-js@0.2.0. m8 export, m8 import and the API of every m8-js all support exporting to and importing from JSON.

nice, it works!