Mod Archive Forums Mod Archive Forums
Advanced search  

News:

Please note: Your main modarchive.org account will not work here, you must create a forum account to post on the forums.

Pages: [1]   Go Down

Author Topic: Reversing a .xm file?  (Read 772 times)

0 Members and 1 Guest are viewing this topic.

ZedFox

  • Liking the Pie
  • Offline Offline
  • Posts: 4
    • View Profile
Reversing a .xm file?
« on: January 28, 2017, 11:03:39 »

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.
Logged

Saga Musix

  • TMA Moderator
  • Lerd of the Pies
  • ****
  • Online Online
  • Posts: 1953
  • I love OpenMPT! And Modules! And TMA! And Pie! :>
    • View Profile
    • Saga Musix - free mod music and more!
Re: Reversing a .xm file?
« Reply #1 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.
Logged
» My TMA artist profile
» Visit my music site: https://sagamusix.de/ [de, en]
» Visit my programming website: https://sagagames.de/ [de]
» Open ModPlug tracker

ZedFox

  • Liking the Pie
  • Offline Offline
  • Posts: 4
    • View Profile
Re: Reversing a .xm file?
« Reply #2 on: January 29, 2017, 06:25:59 »

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.
I'm definitely interested, I'd like to see what it is capable of!
Logged

Saga Musix

  • TMA Moderator
  • Lerd of the Pies
  • ****
  • Online Online
  • Posts: 1953
  • I love OpenMPT! And Modules! And TMA! And Pie! :>
    • View Profile
    • Saga Musix - free mod music and more!
Re: Reversing a .xm file?
« Reply #3 on: January 30, 2017, 00:30:53 »

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: [Select]
#!/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)))
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.
« Last Edit: January 30, 2017, 00:34:38 by Saga Musix »
Logged
» My TMA artist profile
» Visit my music site: https://sagamusix.de/ [de, en]
» Visit my programming website: https://sagagames.de/ [de]
» Open ModPlug tracker
Pages: [1]   Go Up