Example #1
0
def trackRun(track, line):
    pu._P().ARGUMENTS = []
    pu.addArgument("Seq", None, "Sequence tab.")
    pu.addArgument("Define", "", "For defining.")
    pu.addArgument("Bpm", "4", "Beats per bar.")
    pu.addArgument("Level", "9", "Max volume value.")
    pu.addArgument("Debug", "0", "For debugging.")
    args = pu.parseCommandLine(line)

    seq = args["Seq"]
    bpm = int(args["Bpm"])
    vol = int(args["Level"])
    debug = int(args["Debug"])
    define = args["Define"]

    if define == "":
        cmd = "Sequence " + process_sequence(seq, bpm, vol)
    else:
        cmd = process_sequence(seq, bpm, vol)
        cmd = "Define " + define + " " + cmd[2:-2]

    # Hackattack...
    # If we're called from a Begin Drum-Foo then we should not include
    # the track in the resultant command.
    beginData = parse.beginData
    if beginData and beginData[0].upper() == track:
        1
    else:
        cmd = track + " " + cmd

    if debug: print("Rhythm: " + cmd)
    pu.addCommand(cmd)
    # if debug: print(pu._P().COMMANDS)
    pu.sendCommands()
Example #2
0
def run(line):
    # Check for leading line number.
    if line[0].isdigit():
        res = [ line[0] ]
        line = line[1:]
    else:
        res = [ '' ]
        
    res.extend( dataRun(line) )

    # run() must use pu.sendCommands.
    pu.addCommand(" ".join(res))
    pu.sendCommands()
Example #3
0
def run(line):

    # We parse the arguments. Errors are thrown if something is wrong,
    # printing the correct usage on screen. Default are used if needed.
    # parseCommandLine also takes an optional boolean argument to allow
    # using of arguments not declared with pu.addArgument, default is False.
    args = pu.parseCommandLine(line)

    # This is how we access arguments.
    author = args["Author"]
    year = args["Year"]

    # MIDI specs say we should use (C).
    pu.addCommand("MidiCopyright (C) {} {}".format(year, author))
    pu.sendCommands()
Example #4
0
def dataRun(line):
    res = []
    cp = re.compile("([A-G][b#]?)(.*)$")

    for arg in line:
        m = cp.match(arg)
        if m is None:
            res.append(arg)
            continue
        root = m.group(1)
        type = m.group(2)
        if len(type) == 0:
            type = "M"

        # print(">> " + arg + " " + root + " " + type)
        
        # Using C as root, get the chord data.
        ch = ChordNotes("C" + type);
        c = ch.chordType

        # print("Chord: %s (%s %s)" % ( ch.name, ch.tonic, ch.chordType ) )
        # print("NoteList: %s" % ' '.join(map(str, ch.noteList)))
        # print("ScaleList: %s" % ' '.join(map(str, ch.scaleList)))

        chordlist = chordtable.chordlist
        notelist  = chordlist[c][0]
        scale     = chordlist[c][1]
        
        n = list(notelist)
        for j in random.choice(((0,1),(0,2),(1,2))):
            n.append(n[j]+12)

        rvcnt = nextval()
        type = "{}-{}".format(c, rvcnt)
        chordlist[type] = (n, scale, "Revoiced")
        pu.addCommand("PrintChord {}".format(type))

        res.append(root + type)

    # dataRun() must return a line array, not including line number.
    return res
Example #5
0
def trackRun(tr, line):
    """ Entry point for track command. """

    # We check if track type is correct.
    pu.checkTrackType(tr)

    # initalize tracks 2 and 3
    setTuning(tr)

    out1 = ["%s Riff  " % tr]
    out2 = ["%s Riff  " % fTrack]
    out3 = ["%s Riff  " % sTrack]

    line = ''.join(line)[:-1]

    for a in line.split(';'):
        if not ']' in a:
            attr, note = ('', a)
        else:
            attr, note = a.split(']', 1)

        # we now have just the note info to worry about. The stuff in []
        # is tucked away in 'attr'.

        if '%' in note:
            flatNote = attr + note.replace('%', '')
            normNote = attr + note2rest(note)
            sharpNote = attr + note2rest(note)

        elif '*' in note:
            sharpNote = attr + note.replace('*', '')
            normNote = attr + note2rest(note)
            flatNote = attr + note2rest(note)

        else:
            sharpNote = attr + note2rest(note)
            flatNote = attr + note2rest(note)
            normNote = attr + note

        out1.extend([normNote, ';'])
        out2.extend([flatNote, ';'])
        out3.extend([sharpNote, ';'])

    pu.addCommand(''.join(out1))
    pu.addCommand(''.join(out2))
    pu.addCommand(''.join(out3))

    if MMA.debug.debug:
        print(''.join(out1))
        print(''.join(out2))
        print(''.join(out3))

    pu.sendCommands()
Example #6
0
def trackRun(trackname, line):
    # We check if track type is correct.
    pu.checkTrackType(trackname)
    # We parse the arguments. Errors are thrown if something is wrong,
    # printing the correct usage on screen. Default are used if needed.
    # parseCommandLine also takes an optional boolean argument to allow
    # using of arguments not declared with pu.addArgument, default is False.
    args = pu.parseCommandLine(line)
    
    # This is how we access arguments.
    pattern = args["Pattern"]
    strum   = args["Strum"]
    volumeN = args["Volume"]
    volumeM = args["VolumeMuted"]
    volumeE = args["VolumeEmph"]
    volumeP = args["VolumePick"]
    
    # This is the logic for the plugin.
    all_normal = ""
    all_muted = ""
    
    for bar_pattern in pattern.split(";"):
        if "." in bar_pattern:
            bar_pattern = bar_pattern.lower().split(".")
        else:
            # you can avoid commas when not using ue, ux, de, dx
            bar_pattern = bar_pattern.lower()

        strums_normal = []
        strums_muted = []
        
        step = float(pu.getSysVar("TIME"))/len(bar_pattern)
        for i, c in enumerate(bar_pattern):
            t = 1+step*i
        
            if c == "u":
                strums_normal.append("{:0.4} -{} {}".format(t, strum, volumeN))
            elif c == "ue":
                strums_normal.append("{:0.4} -{} {}".format(t, strum, volumeE))
            elif c == "um":
                strums_normal.append("{:0.4} 0 0".format(t))
                strums_muted.append("{:0.4} -{} {}".format(t, strum, volumeM))
                
            elif c == "d":
                strums_normal.append("{:0.4} +{} {}".format(t, strum, volumeN))
            elif c == "de":
                strums_normal.append("{:0.4} +{} {}".format(t, strum, volumeE))
            elif c == "dm":
                strums_normal.append("{:0.4} 0 0".format(t))
                strums_muted.append("{:0.4} +{} {}".format(t, strum, volumeM))
                
            elif c == "x":
                strums_normal.append("{:0.4} 0 0".format(t))
                strums_muted.append("{:0.4} 0 {}".format(t, volumeM))
                
            elif c == "0":
                strums_normal.append("{:0.4} 0 0".format(t))
                
            elif c.lstrip("0").isdigit():
                for s in c:
                    strums_normal.append("{:0.4} 0 {}:{}".format(t, s, volumeP))

            elif c == "-":
                pass
                
            else:
                #printUsage()
                pu.error("{}: unrecognized command in strum pattern: '{}'.".format(pu.getName(), c))    
     
        bar_normal = ("{" + "; ".join(strums_normal) + ";}") if len(strums_normal) > 0 else "z"
        bar_muted  = ("{" + "; ".join(strums_muted)  + ";}") if len(strums_muted)  > 0 else "z"
        
        all_normal += bar_normal + " "
        all_muted  += bar_muted + " "
        

    # If you don't send all the commands together the result is commands 
    # are reversed since each is pushed as the very next command to be executed.
    # So we save all the commands (with addCommand) and send them at the end
    # (with sendCommands).
    
    pu.addCommand("{} Sequence {}".format(trackname, all_normal))
    pu.addCommand("{}-Muted SeqClear".format(trackname))
    pu.addCommand("{}-Muted Copy {}".format(trackname, trackname))
    pu.addCommand("{}-Muted Voice MutedGuitar".format(trackname))
    pu.addCommand("{}-Muted Sequence {}".format(trackname, all_muted))
    pu.sendCommands()
Example #7
0
def trackRun( track, line ):
    args = pu.parseCommandLine(line)

    pat   = args["Pat"]
    tab   = args["Tab"] or pat
    bpb   = int(args["Bpb"])
    q     = int(args["Q"])
    debug = int(args["Debug"])

    # Init bpb and q from timesig if needed.
    if bpb == 0 or q == 0:
        ( n, d) = timeSig.get()
        if bpb == 0: bpb = n
        if q == 0: q = 2**d;

    # The sequence data is a series of Instrument Pattern pairs.
    # It may be passed in a macro name.
    t = tab.split()
    if len(t) == 1:
        # Macro name.
        t = pu.getVar(tab.upper())
        # MSet macro return list of list. Flatten.
        if len(t) > 0 and isinstance(t[0], list):
            #print(t)
            res = []
            for item in t:
                if len(item) > 1 and item[0].isalnum():
                    # Throw away string name.
                    item = item[1:]
                res.append("".join(item))
            t = res
            #print(t)
        else:
            # Single value macro. Split.
            t = t.split()

    string = len(t)
    tab = []

    #print(t)
    step = -1;
    for s in t:

        # Just in case we're quoted.
        if s[ 0] in "\"'": s = s[1:]
        if s[-1] in "\"'": s = s[:-1]

        # Drop leading string names.
        if s[0].isalnum(): s = s[1:]

        # Verify (and drop) leading and trailing bars.
        if s[0] == '|' and s[-1] == '|': s = s[1:-1]
        else:
            raise Exception( "Missing | | in tab element: {}".format(s) )

        # Verify equal width (step size).
        if step < 0:
            step = len(s)
        else:
            if step != len(s):
                raise Exception( "Incorrect length item in tab element: |{}| {} <> {}".format(s,len(s),step) )

        tab.append(s)

    # tab now contains N elements (N = strings) each M long (step size).
    if debug: print("FPP: {}".format(tab))

    # Verify and calculate step delta.
    if step % bpb != 0:
        raise Exception( "Step size {} must be multiple of bpb {}".format(bpb,step) )
    # Force floats for python2.
    delta = bpb / ( 1.0 * step )
    if delta <= 0:
        raise Exception( "DELTA ERROR: {} {} {} {}".format(delta,bpb,q,step) )

    # Nice formatting.
    df = len("{:g}".format(delta))
    if df == 1: df = 0
    else:
        if df == 3: df = 1
        else: df = 2

    # To collect strings per step.
    res = []
    for i in range(step): res.append('')

    tm = 1
    for i in range(step):
        for j in range(string):
            x = tab[j][i]
            if x == '-': continue
            if x.upper() == 'X': x = 0
            if res[i] == "":
                res[i] = "{:.{}f} 0 ".format(tm,df)
            res[i] += "{}:{} ".format( j+1, 10*int(x) )
        tm += delta

    cmd = "Define " + pat + " " + "; ".join([x for x in res if x])

    # Hackattack...
    # If we're called from a Begin Plectrum-Foo then we should not
    # include the track in the resultant command.
    beginData = parse.beginData
    if beginData and beginData[0].upper() == track:
        1
    else:
        cmd = track + " " + cmd

    if debug: print("FPP: " + cmd)
    pu.addCommand(cmd)

    pat = pat.upper()
    # Set picking pattern. Call after groove change.
    pu.addCommand("DefCall " + pat + " Chords=__OMITTED__")
    pu.addCommand(track + " Sequence " + pat)
    pu.addCommand(" If Ne $$Chords __OMITTED__")
    pu.addCommand("  $Chords")
    pu.addCommand(" EndIf")
    pu.addCommand("EndDefCall")
    pu.addCommand("Set " + pat + " Call " + pat)

    # if debug: print(pu._P().COMMANDS)

    # For convenience.
    if "PPSETUP" not in macro.macros.vars:
        pp = [ [ track, 'Voice', 'NylonGuitar' ],
               [ track, 'Volume', '100' ] ]
        if "RTIME" in macro.macros.vars:
            pp.append( [ track, 'RTime', macro.macros.vars["RTIME"] ] )
        if "RVOLUME" in macro.macros.vars:
            pp.append( [ track, 'RVolume', macro.macros.vars["RVOLUME"] ] )
        macro.macros.vars["PPSETUP"] = pp
        if debug: print("PPSETUP defined")

    pu.sendCommands()
Example #8
0
def setTuning(trk):
    global tuningSet, sTrack, fTrack

    fTrack = '%s-qFlat' % trk
    sTrack = '%s-qSharp' % trk

    if not tuningSet:

        if not fTrack.upper() in MMA.gbl.tnames:
            MMA.alloc.trackAlloc('%s' % fTrack, 0)
            pu.addCommand("%s Copy %s" % (fTrack, trk))

        if not sTrack.upper() in MMA.gbl.tnames:
            MMA.alloc.trackAlloc('%s' % sTrack, 0)
            pu.addCommand("%s Copy %s" % (sTrack, trk))

        pu.addCommand('%s MidiNote PB 0 -2048' % fTrack)
        pu.addCommand('%s MidiNote PB 0 2048' % sTrack)
        pu.addCommand('After Bar=EOF %s MidiNote PB 0 0' % fTrack)
        pu.addCommand('After Bar=EOF %s MidiNote PB 0 0' % sTrack)
        pu.sendCommands()

        tuningSet = True
Example #9
0
def run(line):

    args = pu.parseCommandLine(line)

    # Mandatory.
    groove = args["Groove"]
    seq = args["Seq"]

    # Optional.
    bpm = int(args["Bpm"])
    level = int(args["Level"])
    rvol = int(args["RVolume"])
    rtime = int(args["RTime"])
    seqsz = int(args["SeqSize"])
    clear = int(args["Clear"])
    debug = int(args["Debug"])

    # Some checks.
    if level < 1 or level > 9:
        raise Exception("Rhtythm: Level must be 1 .. 9, not {}".format(level))

    if clear: pu.addCommand("SeqClear")
    if seqsz: pu.addCommand("SeqSize {}".format(seqsz))

    # The sequence data is a series of Instrument Pattern pairs.
    # It may be passed in a macro name.
    line = seq.split()
    if len(line) == 1:
        # Macro name.
        line = pu.getVar(seq.upper())
        # MSet macro return list of list. Flatten.
        if len(line) > 0 and isinstance(line[0], list):
            line = [item for sublist in line for item in sublist]
        else:
            # Single value macro. Split.
            line = line.split()

    if len(line) % 2:
        raise Exception(
            "Rhythm: Seq must have an even number of whitespace separated items"
        )

    # Process two at a time.
    while len(line) > 1:

        # Pop off instrument name.
        instr = line.pop(0)
        if re.match(r'^[0-9]+$', instr):
            # If it is a number, use the Zoom predefined names.
            tone = zoomTones[int(instr) - 1]
            instr = zoomNames[int(instr) - 1]
        elif instr in zoomNames:
            i = zoomNames.index(instr)
            tone = zoomTones[i]
        else:
            tone = instr

        # Pop off the sequence data.
        seq = line.pop(0)

        pu.addCommand("Begin Drum-" + instr)
        pu.addCommand("  Tone     " + tone)
        if rtime: pu.addCommand("  RTime    {:d}".format(rtime))
        if rvol: pu.addCommand("  RVolume  {:d}".format(rvol))
        pu.addCommand("  Sequence " + process_sequence(seq, bpm, level))
        pu.addCommand("End")

    pu.addCommand("DefGroove " + groove)
    # if debug: print(pu._P().COMMANDS)
    pu.sendCommands()