Archive for June, 2012

hydrogen drumkits for composite sampler

Composite is will be a software application/system for real-time, in-performance sequencing, sampling, and looping. …” [Composite web site]. It comes with a LV2 plugin (called composite sampler) that allows to use its drumkits in zynjacku (“zynjacku is a nunchaku weapon for JACK audio synthesis. …” [zynjacku web site]), which means that you can use the sounds alone without running the whole sequencer. The drumkits are compatible to the ones used by hydrogen (“Hydrogen is an advanced drum machine for GNU/Linux. …” [hydrogen web site]).

The composite sampler documentation says that one needs to put the drumkits (or symlinks) into the according path and adjust the default.xml file in the composite presets (see manual). Then it is possible to change through the drumkits with MIDI program change messages. I thought an automated way of preparing this setup would be useful, so I wrote the following python script. Feel free to use/alter it, no guarantee is given for anything. Comments are welcome.

importHydrogenDrumkitsToComposite.py

"""
Generates symlinks in the composite drumkit path that point 
to the hydrogen drumkits. Creates an according xml-file with 
all drumkits with GMkit as the first entry.
"""
__author__ = "https://linuxaudiolive.wordpress.com"

from glob import glob
from os import system, path

xmlstart = "<?xml version=\"1.0\"?>\n\
<T:tritium xmlns:T=\"http://gabe.is-a-geek.org/tritium/xml/1/\">\n\
\t<T:presets>\n\\t\t<T:bank coarse=\"0\" fine=\"0\">"
xmlend = "\t\t</T:bank>\n\\t</T:presets>\n\</T:tritium>"

hydrogenDrumkitPath = "/usr/share/hydrogen/data/drumkits/"
compositeDrumkitPath = path.expanduser("~/.composite/data/drumkits/")
newDefaultFilename = "newDefault.xml"

def makeDrumkitSymlinks(hydrogenPath, compositePath):
    """Puts symlinks for all entries in hydrogenPath into compositePath"""
    print "Creating symlinks..."
    names = glob(hydrogenPath+"*")
    for n in names:
        system("ln -s '"+n+"' '"+compositePath+n.split("/")[-1]+"'")

def drumKitField(name, MIDIdevice):
    """Returns the complete xml-entry for one drumkit"""
    drumKitString = "\t\t\t<T:program>\n"
    drumKitString += "\t\t\t\t<T:midi_number>" 
    drumKitString += str(MIDIdevice) 
    drumKitString += "</T:midi_number>\n"
    drumKitString += "\t\t\t\t<T:resource>tritium:drumkits/"
    drumKitString += name
    drumKitString += "</T:resource>\n\t\t\t</T:program>"
    return drumKitString

if __name__ == '__main__':
    if path.exists(newDefaultFilename):
        print "The file '",newDefaultFilename,"' already exists."
        print "Not deleting anything."
        print "Aborting!"
    else:
        #uncomment the following to create the symlinks
        #makeDrumkitSymlinks(hydrogenDrumkitPath, compositeDrumkitPath)
        print "Creating new default file."
        drumkitnames = glob(compositeDrumkitPath+"*")
        drumkitnames.sort()
        f = open(newDefaultFilename,'w')
        f.write(xmlstart)
        f.write(drumKitField("GMkit",0)) #the default entry
        counter = 1
        for kit in drumkitnames:
            name = kit.split("/")[-1]
            if name!="GMkit": #default entry is already the first
                f.write(drumKitField(name, counter))
                counter+=1
        f.write(xmlend)
        f.close()
        print "Done. Now copy",newDefaultFilename,
        print "to your .composite/data/presets/default.xml"
Advertisements