Xrnitool.py

Here’s a small Python script I wrote to do some chores for me on large multisample xrni’s, you can easily change all the sample volume’s, the newnote actions and the panning of all samples in one instrument at once. Very easy to expand on as well.

Just drop this and 7zip in your path and run it from the command line, it’s pretty basic since it’s my first ever python script. I’m not sure if this will work on the new 3.0 version.

http://drop.io/xrnitool

I love this!! Is there any way to have this also turn the Volume envelopes off or on (really, just off)? I tried to figure it out looking at the code, but I’m not a programmer…

-Steven

I’ve made some changes to the code to turn off the volume envelopes (for those who want this).

Here’s my revision of xrnitool.py:

"""Utility for editing Renoise Instrument files (.xrni)"""  
#!/bin/perl  
  
import os, tempfile, zipfile  
from xml.dom import minidom  
from glob import glob  
from optparse import OptionParser  
  
def extractZip(zip, destination):  
 for files in zip.filelist:  
 if files.filename.endswith('/'):  
 os.mkdir(os.path.join(destination, files.filename))  
 else:  
 output = open(os.path.join(destination, files.filename), 'w')  
 output.write(zip.read(files.filename))  
 output.close()  
  
if __name__ == "__main__":  
 parser = OptionParser(version="%prog v0.22")  
 parser.add_option("-v", "--samples_volume", dest="volume",  
 help="change the amplification of all samples")  
 parser.add_option("-n", "--new_note_action", dest="newnoteaction",  
 help="change the new note action of all samples")  
 parser.add_option("-i", "--interpolation", dest="interpolation",  
 help="change the interpolation mode of all samples")  
 parser.add_option("-p", "--panning", dest="panning",  
 help="change the panning of all samples")  
 (options, args) = parser.parse_args()  
  
 for arguments in args:  
 for filename in glob(arguments):  
 xrni = zipfile.ZipFile(filename, 'r')   
 xrnixml = minidom.parseString(xrni.read('Instrument.xml'))  
 xrni.close()  
  
 if options.volume:  
 samplevolume = xrnixml.childNodes[0].childNodes[5].getElementsByTagName('Volume')  
 for n in samplevolume:  
 n.childNodes[0].nodeValue = options.volume  
  
 if options.newnoteaction:  
 newnoteaction = xrnixml.childNodes[0].childNodes[5].getElementsByTagName('NewNoteAction')  
 for n in newnoteaction:  
 n.childNodes[0].nodeValue = options.newnoteaction  
  
 if options.interpolation:  
 interpolation = xrnixml.childNodes[0].childNodes[5].getElementsByTagName('InterpolationMode')  
 for n in interpolation:  
 n.childNodes[0].nodeValue = options.interpolation  
  
 if options.panning:  
 panning = xrnixml.childNodes[0].childNodes[5].getElementsByTagName('Panning')  
 for n in panning:  
 n.childNodes[0].nodeValue = options.panning  
  
for node in xrnixml.getElementsByTagName('IsActive'):  
 for child in node.childNodes:  
 if str(child.data) == 'true':  
 child.replaceData(0,4,'False')  
 output = open('Instrument.xml', 'w')  
 output.write(xrnixml.toxml())  
 output.close()  
  
 print '\n\n*** working on ' + filename  
 os.system('7z u -tzip "' + filename + '" Instrument.xml')  
 os.remove('Instrument.xml')  
  

Enjoy!

nice one :)

*reclines in lazy chair