Python ‘Machine Info’ script

By | January 23, 2010

Found this on my harddrive recently from an old project, example provided to me by Ed some time ago… Better posted here than lost or squandered. To explain, it’s a relatively simple python script that you can run against your Buzz gear directories and a list of all machines in the directory is given and the type of machine, what flags it uses, the author, etc. is returned. It is more or less a starting example, but you may find it useful for sorting modules as-is:

import ctypes
from ctypes import c_int, c_char_p, c_void_p

class MachineInfo:
        def __init__(self, dllname):
                # Info struct from machineinterface.h
                class CMachineInfo(ctypes.Structure):
                        _fields_ = [
                                ("Type", c_int),
                                ("Version", c_int),
                                ("Flags", c_int),
                                ("minTracks", c_int),
                                ("maxTracks", c_int),
                                ("numGlobalParameters", c_int),
                                ("numTrackParameters", c_int),
                                ("Parameters", c_void_p),
                                ("numAttributes", c_int),
                                ("Attributes", c_void_p),
                                ("Name", c_char_p),
                                ("ShortName", c_char_p),
                                ("Author", c_char_p),
                                ("Commands", c_char_p),
                                ("pLI", c_void_p)
                # Load library and call GetInfo
                dll = ctypes.cdll.LoadLibrary(dllname)
                dll.GetInfo.restype = ctypes.POINTER(CMachineInfo)
                info = dll.GetInfo().contents
                # Copy all attributes from the info struct into self
                # Skip attributes starting with _
                for attr in dir(info):
                        if attr[0] != '_':
                                setattr(self, attr, getattr(info, attr))
                # Set types to a human-readable string
                types = { 0: "MT_MASTER", 1: "MT_GENERATOR", 2: "MT_EFFECT" }
                if self.Type in types:
                        self.Type = types[self.Type]
                # Flag values from machineinterface.h
                flags = {
                        (1<<0)        : "MIF_MONO_TO_STEREO",
                        (1<<1)        : "MIF_PLAYS_WAVES",
                        (1<<2)        : "MIF_USES_LIB_INTERFACE",
                        (1<<3)        : "MIF_USES_INSTRUMENTS",
                        (1<<4)        : "MIF_DOES_INPUT_MIXING",
                        (1<<5)        : "MIF_NO_OUTPUT",
                        (1<<6)        : "MIF_CONTROL_MACHINE",
                        (1<<7)        : "MIF_INTERNAL_AUX",
                        (1<<8)        : "MIF_EXTENDED_MENUS",
                        (1<<9)        : "MIF_PATTERN_EDITOR",
                        (1<<10)        : "MIF_PE_NO_CLIENT_EDGE",
                        (1<<11)        : "MIF_GROOVE_CONTROL",
                        (1<<12)        : "MIF_DRAW_PATTERN_BOX",
                # Set flags to a list of strings
                # If unknown flags are included, append them to the list as an int
                newflags = []
                for k,v in flags.iteritems():
                        if self.Flags & k:
                                self.Flags &= ~k
                if self.Flags != 0:
                self.Flags = newflags

# The main program
def main():
        from sys import argv
        if len(argv) != 2:
                print "Usage: path\\to\\buzz\\gear\\generators_or_effects"
                raise SystemExit
        # Find all dlls in the given directory
        from glob import glob
        from os.path import join
        for dllname in glob(join(argv[1], '*.dll')):
                print dllname
                        info = MachineInfo(dllname)
                        print "Error"
                print "Name:", info.Name
                print "Author:", info.Author
                print "Type:", info.Type
                print "Flags:", info.Flags

if __name__ == '__main__':

Leave a Reply

Your email address will not be published. Required fields are marked *