Scripting in OpenMPT

Started by Saga Musix, August 25, 2010, 18:02:18

Previous topic - Next topic

Saga Musix

Quote from: LPChip on July 09, 2017, 10:32:24
Can it open a textfile, read its content, parse it, and perform actions based on that?
Lua has a file I/O package, yes, and I will enable all the default Lua packages.

Quote from: LPChip on July 09, 2017, 10:32:24Can it also get information FROM the tracker?
Yes, that is the entire point of the API. ;)

Quote from: LPChip on July 09, 2017, 10:32:24Oh, and if possible, can the script generate a dialog with buttons and perform actions based on custom button presses?
Oh come on, it's even being discussed in the first post on this page...
» No support, bug reports, feature requests via private messages - they will not be answered. Use the forums and the issue tracker so that everyone can benefit from your post.

LPChip

Okay, I admit, that last one I got carried away in enthusiasm and it was a bit of teasing on my end. :P
"Heh, maybe I should've joined the compo only because it would've meant I wouldn't have had to worry about a damn EQ or compressor for a change. " - Atlantis
"yes.. I think in this case it was wishful thinking: MPT is makng my life hard so it must be wrong" - Rewbs

Saga Musix

I like how my post is now referring to itself recursively due to the page break.
» No support, bug reports, feature requests via private messages - they will not be answered. Use the forums and the issue tracker so that everyone can benefit from your post.

LPChip

Quote from: Saga Musix on July 09, 2017, 10:43:58
I like how my post is now referring to itself recursively due to the page break.

Hahahaha I hadn't noticed. I read first post of this topic, not page...
"Heh, maybe I should've joined the compo only because it would've meant I wouldn't have had to worry about a damn EQ or compressor for a change. " - Atlantis
"yes.. I think in this case it was wishful thinking: MPT is makng my life hard so it must be wrong" - Rewbs

JanKXSKI

I am very sorry to revive an old thread, but any update on this? I cannot find references to scripting in the doc/version history. I would like to export pattern data from OpenMPT to json.

Saga Musix

I work on this every now and then, but there's not so much progress. It's a huge and difficult task. The current state can be tried at https://github.com/sagamusix/openmpt but I don't remember if accessing pattern data currently works. libopenmpt might currently be an easier / more stable way to get pattern data out of module files, or maybe copying all patterns to the clipboard and then transforming the text data to json with an external tool.
» No support, bug reports, feature requests via private messages - they will not be answered. Use the forums and the issue tracker so that everyone can benefit from your post.

JanKXSKI

Thank you for the reply and the effort! I'll look into the alternatives you suggested.

chr15m

#52
For me the ideal simple scripting interface for modplug would work like Inkscape plugins.

Inkscape is an SVG editor and when you run a plugin what happens is the entire SVG data is simply passed to the plugin via stdin, which makes its changes, and then returns the SVG data back again. Inkscape replaces its own buffer with whatever the script passed back via stdout (and you can undo of course).

For modplug it could be just this simple. You click a button called "run pattern script" and then choose an executable, or scripting file which is associated with an interpreter by the OS already. The entire pattern data is passed to the script you choose via stdin, which could even be in the same format as modplug copy-paste data (JSON could be nice but it's probably more work). The stdout from the executable/script is then parsed as paste data and pasted over existing pattern data.

In this way the user can use whatever language they like. If .py files are associated with the Python interpreter they can select a Python script. Same for Lua, Nodejs, native exe, etc. All they need to do is parse the pattern data in their language and return the modified data by printing to stdout.

Openmpt could remember previous scripts in a pull-down menu for convenient access.

Stderr could be logged and simply displayed to the user for errors and debugging.

For me an important difference from just manual copy-paste is being able to get the entire song of data not just one pattern.

Perhaps it would be nice to be able to only pass some channels and somehow tell the executable this, but that's not essential.

It could be done in an async way so the script can e.g. launch a UI with options/config for the user if needed.