Commit 50214728 authored by PoroCYon's avatar PoroCYon
Browse files

make converter code portable

parent a51a2497
#!/usr/bin/env python #!/usr/bin/env python2
import sys import sys
import zipfile import zipfile
import XML import oidosxml
import struct import struct
import ctypes import ctypes
import math import math
...@@ -483,8 +483,8 @@ class Music: ...@@ -483,8 +483,8 @@ class Music:
self.out += "\n%define USES_PANNING\n" self.out += "\n%define USES_PANNING\n"
# Instrument parameters # Instrument parameters
self.out += "\n\n\tsection iparam data align=4\n" self.out += "\n\n\tSECT_DATA(iparam) align=4\n"
self.out += "\n_InstrumentParams:\n" self.out += "\nInstrumentParams:\n"
for instr in self.instruments: for instr in self.instruments:
self.label(".i%02d" % instr.number) self.label(".i%02d" % instr.number)
self.comment(instr.title) self.comment(instr.title)
...@@ -502,8 +502,8 @@ class Music: ...@@ -502,8 +502,8 @@ class Music:
self.out += "\n" self.out += "\n"
# Instrument tones # Instrument tones
self.out += "\n\n\tsection itones data align=1\n" self.out += "\n\n\tSECT_DATA(itones) align=1\n"
self.out += "\n_InstrumentTones:\n" self.out += "\nInstrumentTones:\n"
for instr in self.instruments: for instr in self.instruments:
self.label(".i%02d" % instr.number) self.label(".i%02d" % instr.number)
self.comment(instr.title) self.comment(instr.title)
...@@ -516,8 +516,8 @@ class Music: ...@@ -516,8 +516,8 @@ class Music:
self.out += "%d\n" % (-129 + instr.columns) self.out += "%d\n" % (-129 + instr.columns)
# Track data # Track data
self.out += "\n\n\tsection trdata data align=1\n" self.out += "\n\n\tSECT_DATA(trdata) align=1\n"
self.out += "\n_TrackData:\n" self.out += "\nTrackData:\n"
for ti in self.track_order: for ti in self.track_order:
track = self.tracks[ti] track = self.tracks[ti]
instr = self.instrument_map[track.instr] instr = self.instrument_map[track.instr]
...@@ -537,13 +537,13 @@ class Music: ...@@ -537,13 +537,13 @@ class Music:
self.dataline(tavdata) self.dataline(tavdata)
# Lengths of notes # Lengths of notes
self.out += "\n\tsection notelen data align=1\n" self.out += "\n\tSECT_DATA(notelen) align=1\n"
self.out += "\n_NoteLengths:\n" self.out += "\nNoteLengths:\n"
self.notelist(self.lendata, [0], "L_") self.notelist(self.lendata, [0], "L_")
# Samples for notes # Samples for notes
self.out += "\n\tsection notesamp data align=1\n" self.out += "\n\tSECT_DATA(notesamp) align=1\n"
self.out += "\n_NoteSamples:\n" self.out += "\nNoteSamples:\n"
self.notelist(self.samdata, [], "S_") self.notelist(self.samdata, [], "S_")
return self.out return self.out
...@@ -912,7 +912,7 @@ if len(files) != 2: ...@@ -912,7 +912,7 @@ if len(files) != 2:
infile = files[0] infile = files[0]
outfile = files[1] outfile = files[1]
x = XML.makeXML(zipfile.ZipFile(infile).read("Song.xml")) x = oidosxml.makeXML(zipfile.ZipFile(infile).read("Song.xml"))
try: try:
music = makeMusic(x.RenoiseSong) music = makeMusic(x.RenoiseSong)
print print
......
#!/usr/bin/env python #!/usr/bin/env python2
import sys import sys
import zipfile import zipfile
import XML import oidosxml
import re import re
import math import math
import base64 import base64
import struct import struct
def upgradeInstrument(xi, xdevice, name): def upgradeInstrument(xi, xdevice, name):
def newname(s): def newname(s):
return re.sub("MetaSynth", "Oidos", s) return re.sub("MetaSynth", "Oidos", s)
xdevice.PluginIdentifier.replaceText(newname) xdevice.PluginIdentifier.replaceText(newname)
xdevice.PluginDisplayName.replaceText(newname) xdevice.PluginDisplayName.replaceText(newname)
xdevice.PluginShortDisplayName.replaceText(newname) xdevice.PluginShortDisplayName.replaceText(newname)
if name is not None: if name is not None:
xi.Name.setData(name) xi.Name.setData(name)
else: else:
xi.Name.replaceText(newname) xi.Name.replaceText(newname)
#pdata = base64.b64decode(xdevice.ParameterChunk.domlist[0].childNodes[0].data + "=") #pdata = base64.b64decode(xdevice.ParameterChunk.domlist[0].childNodes[0].data + "=")
#for i,c in enumerate(pdata): #for i,c in enumerate(pdata):
# print "%s%02X" % (" " if (i % 4) == 0 else "", ord(c)), # print "%s%02X" % (" " if (i % 4) == 0 else "", ord(c)),
#print #print
xparams = xdevice.Parameters.Parameter.Value xparams = xdevice.Parameters.Parameter.Value
params = [float(p) for p in xparams] params = [float(p) for p in xparams]
# Duplicate filter sweep parameter # Duplicate filter sweep parameter
params = params[:11] + [params[13]] + params[11:17] + [0.0] + params[20:27] + [params[29]] + params[27:33] params = params[:11] + [params[13]] + params[11:17] + [0.0] + params[20:27] + [params[29]] + params[27:33]
for i,p in enumerate(params): for i,p in enumerate(params):
xparams[i].setData(p) xparams[i].setData(p)
pstring = struct.pack("<4I", 1, 1, len(params), 0) + struct.pack("<%df" % len(params), *params) pstring = struct.pack("<4I", 1, 1, len(params), 0) + struct.pack("<%df" % len(params), *params)
xdevice.ParameterChunk.setData(base64.b64encode(pstring)) xdevice.ParameterChunk.setData(base64.b64encode(pstring))
def upgradeInstruments(xinstrs, name): def upgradeInstruments(xinstrs, name):
for xi in xinstrs: for xi in xinstrs:
for xdevice in xi.PluginProperties.PluginDevice: for xdevice in xi.PluginProperties.PluginDevice:
plugin_id = str(xdevice.PluginIdentifier) plugin_id = str(xdevice.PluginIdentifier)
if plugin_id == "MetaSynth": if plugin_id == "MetaSynth":
upgradeInstrument(xi, xdevice, name) upgradeInstrument(xi, xdevice, name)
break break
def upgradeReverb(xdevice): def upgradeReverb(xdevice):
def newname(s): def newname(s):
return re.sub("MetaEffect", "OidosReverb", s) return re.sub("MetaEffect", "OidosReverb", s)
xdevice.PluginIdentifier.replaceText(newname) xdevice.PluginIdentifier.replaceText(newname)
xdevice.PluginDisplayName.replaceText(newname) xdevice.PluginDisplayName.replaceText(newname)
xdevice.PluginShortDisplayName.replaceText(newname) xdevice.PluginShortDisplayName.replaceText(newname)
#pdata = base64.b64decode(xdevice.ParameterChunk.domlist[0].childNodes[0].data + "=") #pdata = base64.b64decode(xdevice.ParameterChunk.domlist[0].childNodes[0].data + "=")
#for i,c in enumerate(pdata): #for i,c in enumerate(pdata):
# print "%s%02X" % (" " if (i % 4) == 0 else "", ord(c)), # print "%s%02X" % (" " if (i % 4) == 0 else "", ord(c)),
#print #print
xparams = xdevice.Parameters.Parameter.Value xparams = xdevice.Parameters.Parameter.Value
params = [float(p) for p in xparams] params = [float(p) for p in xparams]
# Reduce parameters # Reduce parameters
params = params[:20] params = params[:20]
while len(xdevice.Parameters.Parameter) > 20: while len(xdevice.Parameters.Parameter) > 20:
xdevice.Parameters.removeChild(xdevice.Parameters.Parameter[20]) xdevice.Parameters.removeChild(xdevice.Parameters.Parameter[20])
pstring = struct.pack("<4I", 1, 1, len(params), 0) + struct.pack("<%df" % len(params), *params) pstring = struct.pack("<4I", 1, 1, len(params), 0) + struct.pack("<%df" % len(params), *params)
xdevice.ParameterChunk.setData(base64.b64encode(pstring)) xdevice.ParameterChunk.setData(base64.b64encode(pstring))
def upgradeReverbs(xtrack): def upgradeReverbs(xtrack):
for xdevice in xtrack.FilterDevices.Devices.AudioPluginDevice: for xdevice in xtrack.FilterDevices.Devices.AudioPluginDevice:
plugin_id = str(xdevice.PluginIdentifier) plugin_id = str(xdevice.PluginIdentifier)
if plugin_id == "MetaEffect": if plugin_id == "MetaEffect":
upgradeReverb(xdevice) upgradeReverb(xdevice)
infile = sys.argv[1] infile = sys.argv[1]
outfile = sys.argv[2] outfile = sys.argv[2]
zfile = zipfile.ZipFile(infile) zfile = zipfile.ZipFile(infile)
if infile.endswith(".xrns"): if infile.endswith(".xrns"):
info = zfile.getinfo("Song.xml") info = zfile.getinfo("Song.xml")
x = XML.makeXML(zfile.read(info)) x = oidosxml.makeXML(zfile.read(info))
upgradeInstruments(x.RenoiseSong.Instruments.Instrument, None) upgradeInstruments(x.RenoiseSong.Instruments.Instrument, None)
upgradeReverbs(x.RenoiseSong.Tracks.SequencerTrack) upgradeReverbs(x.RenoiseSong.Tracks.SequencerTrack)
upgradeReverbs(x.RenoiseSong.Tracks.SequencerSendTrack) upgradeReverbs(x.RenoiseSong.Tracks.SequencerSendTrack)
elif infile.endswith(".xrni"): elif infile.endswith(".xrni"):
info = zfile.getinfo("Instrument.xml") info = zfile.getinfo("Instrument.xml")
x = XML.makeXML(zfile.read(info)) x = oidosxml.makeXML(zfile.read(info))
upgradeInstruments(x.RenoiseInstrument, infile[infile.rfind('/')+1:-5]) upgradeInstruments(x.RenoiseInstrument, infile[infile.rfind('/')+1:-5])
else: else:
print "Unknown file extension: " + infile print "Unknown file extension: " + infile
sys.exit() sys.exit()
outzip = zipfile.ZipFile(outfile, 'w') outzip = zipfile.ZipFile(outfile, 'w')
outzip.writestr(info, x.export()) outzip.writestr(info, x.export())
outzip.close() outzip.close()
#!/usr/bin/env python
import xml.dom import xml.dom
import xml.dom.minidom import xml.dom.minidom
...@@ -89,3 +88,4 @@ def readXML(filename): ...@@ -89,3 +88,4 @@ def readXML(filename):
def makeXML(xstring): def makeXML(xstring):
return XML([xml.dom.minidom.parseString(xstring)]) return XML([xml.dom.minidom.parseString(xstring)])
#!/usr/bin/env python #!/usr/bin/env python2
from distutils.core import setup from distutils.core import setup
import py2exe, sys, os import py2exe, sys, os
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment