Esempio n. 1
0
def list_grooves():
    # Clear global variables
    gbl.__init__()
    # Set paths for the libs
    paths.init()

    # Needed import for global variable libDirs after paths.init() method ran
    from mma.MMA.paths import libDirs

    grooves = {}
    for lib in libDirs:
        g = loadDB(lib)
        if g:
            for g_path in g:
                name = g_path.split("/")[-1].split(".")[0]
                gs = g[g_path]

                if name in grooves:
                    og = grooves[name]
                    gs = og + gs

                grooves.update({
                        name: gs
                    })
    return jsonify(grooves)
Esempio n. 2
0
def generate_midi(filename):
    # Clear global variables
    gbl.__init__()
    # Set paths for the libs
    paths.init()
    # Get the filename of the uploaded file
    gbl.infile = filename
    # Create first elements for midi file
    m = gbl.mtrks[0] = midi.Mtrk(0)
    m.addTrkName(0, "%s" % filename.rstrip(".mma"))
    m.addText(0, "Created by mma.MMA. Input filename: %s" % filename)
    m.addTempo(0, gbl.tempo)
    tempo.setTime(['4/4'])
    # Parse MMA file
    paths.dommaStart()
    try:
        parse.parseFile(filename)
    except SystemExit:
        print("Error on parse", flush=True)
        return None
    paths.dommaEnd()
    # Create the midi file
    paths.createOutfileName(".mid")
    out_filename = paths.outfile

    for n in gbl.tnames.values():
        if n.channel:
            n.clearPending()
            n.doMidiClear()
            n.doChannelReset()
            if n.riff:
                warning("%s has pending Riff(s)" % n.name)

    trackCount = 1  # account for meta track

    for n in sorted(gbl.mtrks.keys())[1:]:  # check all but 0 (meta)
        if len(gbl.mtrks[n].miditrk) > 1:
            trackCount += 1

    gbl.mtrks[0].addText(0, "DURATION: %d" % (gbl.totTime * 60))

    try:
        out = open(out_filename, 'wb')
        midi.writeTracks(out)
        out.close()
    except IOError:
        print("ERROR")

    grooves.grooveClear([])

    return out_filename
Esempio n. 3
0
def add_groove(f, filename):
    # Clear global variables
    gbl.__init__()
    # Set paths for the libs
    paths.init()

    # Copy file to lib folder
    shutil.copy(f.name, MMAdir + "/lib/" + filename)
    gbl.makeGrvDefs = 1

    try:
        auto.libUpdate()
    except SystemExit:
        print("ignoring SystemExit", flush=True)

    grooves.grooveClear([])

    return {"name": filename, "status": "available"}