Skip to content

Instantly share code, notes, and snippets.

@eodowd
Last active February 19, 2022 00:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eodowd/45b12e0ee89ca0f6735fd1470b97ff26 to your computer and use it in GitHub Desktop.
Save eodowd/45b12e0ee89ca0f6735fd1470b97ff26 to your computer and use it in GitHub Desktop.
dsconverter without GUI
import xml.etree.ElementTree as ET
import os
import sys
#first argument is the filename of the dspreset
#you can run this program with: python main.py example.dspreset
filename=sys.argv[1]
header = """
<control>
default_path= // relative path of your samples
<global>
// parameters that affect the whole instrument go here.
// *****************************************************************************
// Your mapping starts here
// *****************************************************************************
<group>
"""
tree = ET.parse(filename)
for gro in tree.iter('group'):
name = gro.get('name')
f = open('instrument {}'.format(name)+'.sfz','w')
f.write(header+'\n')
if gro.get('name') == name:
for neighbor in gro.iter('sample'):
getchi = neighbor.get('path')
root = neighbor.get('rootNote')
lokey = neighbor.get('loNote')
hikey = neighbor.get('hiNote')
hivel = neighbor.get('hiVel')
lovel = neighbor.get('loVel')
if(hivel == None and lovel == None):
hivel = 127
lovel = 0
f.write('<region>' + 'sample='+str(getchi)+' key= '+str(root)+' lokey= '+str(lokey)+' hikey= '+str(hikey)+' pitch_keycenter= '+str(root)+' hivel= '+str(hivel)+' lovel= '+str(lovel) +'\n')
else:
f.write('<region>' + 'sample=' + str(getchi) + ' key= ' + str(root) + ' lokey= ' + str(lokey) + ' hikey= ' + str(hikey) + ' pitch_keycenter= ' + str(root) + ' hivel= ' + str(hivel) + ' lovel= ' + str(lovel) + '\n')
f.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment