Music Production > Tracking

Reversing a .xm file?

(1/1)

ZedFox:
Is it possible? I'd like to know because instead of reversing my song manually I'd like a switch to reverse the whole song but keep the samples not reversed.

Saga Musix:
It sure is possible. I have written a tool years ago that reads the OpenMPT clipboard data and then reverses it. I can see if I can find it if you're interested. Back then OpenMPT could only copy one pattern at a time but these days it would be possible to process all patterns in one go.

ZedFox:

--- Quote from: Saga Musix on January 28, 2017, 12:54:11 ---It sure is possible. I have written a tool years ago that reads the OpenMPT clipboard data and then reverses it. I can see if I can find it if you're interested. Back then OpenMPT could only copy one pattern at a time but these days it would be possible to process all patterns in one go.

--- End quote ---
I'm definitely interested, I'd like to see what it is capable of!

Saga Musix:
Okay, I just rewrote this whole thing in Python and now it can handle more than one pattern. Here's the Python 3 script, reverse.py:


--- Code: ---#!/usr/bin/python3
# OpenMPT clipboard reverser by Saga Musix in 2017 (Public Domain / CC0)

import sys

if(len(sys.argv) != 3):
    print("Usage: " + sys.argv[0] + " infile outfile")
    sys.exit()

lines = list(open(sys.argv[1]))
f = open(sys.argv[2], 'w')

# ModPlug signature
f.write(lines.pop(0))

# Reverse order list if present
if(lines[0][:8] == "Orders: "):
    f.write("Orders: " + ",".join(reversed(lines[0][8:-1].split(","))) + "\n")
    lines.pop(0)

# Reverse patterns
pattern = list()
for line in lines:
    if(line[0] == "|"):
        pattern.append(line)
    else:
        f.write("".join(reversed(pattern)))
        pattern = list()
        f.write(line)
f.write("".join(reversed(pattern)))
--- End code ---
You will need Python 3 to run this, typically this comes pre-installed on Linux, on Windows you have to download the Python interpreter first.

To use it, copy some pattern data or multiple patterns in OpenMPT to the clipboard. Paste it into a text editor and save it, then run "python reverse.py infile.txt outfile.txt" on the command line (substitute the names of those text files of course). Then open the output file in a text editor, copy it and paste it back into OpenMPT.

Note: If you copy more than one pattern, current OpenMPT versions will get a bit confused. You need the latest test version (r7547 or later, soon available from https://buildbot.openmpt.org/) in that case so that the clipboard data is parsed correctly.

I hope this helps! It's not very luxurious but then again this is probably not a feature you need every day.

Navigation

[0] Message Index

Go to full version