How to use musictheory - 10 common examples

To help you get started, we’ve selected a few musictheory examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github joaoperfig / mikezart / source / mikezario.py View on Github external
def scaleMenu():
    while True:
        print("Please input the list of 7 notes in the Scale (ex: 'C Ds E ...'), a smaller list to autocomplete, or write G or g for random:")
        scalet = usrinp()
        if scalet in "Gg":
            scale = musictheory.scale7()
        else:
            notenames = str.split(scalet, " ")
            notes = ()
            for i in range(len(notenames)):
                if len(notenames[i]) != 0:
                    notes = notes + (musictheory.mnote.fromName(notenames[i] + "0"),)
            scale = musictheory.scale7(notes)
        while True:
            scaleInfo(scale)
            print()
            print ("Accept? (Yy, Nn, Pp(preview)):")
            inp = usrinp()
            if inp in "Yy":
                return scale
            elif inp in "Nn":
                break
            elif inp in "Pp":
                previewscale(scale)
github joaoperfig / mikezart / source / mikezario.py View on Github external
def scaleMenu():
    while True:
        print("Please input the list of 7 notes in the Scale (ex: 'C Ds E ...'), a smaller list to autocomplete, or write G or g for random:")
        scalet = usrinp()
        if scalet in "Gg":
            scale = musictheory.scale7()
        else:
            notenames = str.split(scalet, " ")
            notes = ()
            for i in range(len(notenames)):
                if len(notenames[i]) != 0:
                    notes = notes + (musictheory.mnote.fromName(notenames[i] + "0"),)
            scale = musictheory.scale7(notes)
        while True:
            scaleInfo(scale)
            print()
            print ("Accept? (Yy, Nn, Pp(preview)):")
            inp = usrinp()
            if inp in "Yy":
                return scale
            elif inp in "Nn":
                break
github joaoperfig / mikezart / source / mikezart2.py View on Github external
def mtest():
    inst = rselect(ipack("churchpiano"))
    scale = musictheory.scale7()
    progsize = rselect((2,3,4,5,6))
    progcount = rselect((1,2,3,4,5))
    csize = wselect({2:5, 3:10, 4:20, 5:10, 6:5})
    bpm = wselect({80:5, 100:10, 120:20, 140:10, 160:5, 180:5})   
    palett = musictheory.palette(scale, progsize, progcount, csize)
    palett._bpm = bpm
    palett.autoProgs()    
    centre = rselect(musictheory.listNotes(inst))
    ncount = wselect(musictheory.chordicCWeights())
    palett._n1.addVoice(inst, centre, "chordic", ncount)  
    
    inst = rselect(ipack("guitars"))
    centre = rselect(musictheory.listNotes(inst))
    ncount = wselect(musictheory.chordicCWeights())
    voic = musictheory.voice(inst, centre, scale, "chordic", 0, 0)
    voic.mimic(palett._n1._voices["chordic"][0])
    palett._n1.addVoiceAsIs(voic)      
    
    inst = rselect(ipack("cellopack"))
    centre = rselect(musictheory.listNotes(inst))
    ncount = wselect(musictheory.chordicCWeights())
github joaoperfig / mikezart / source / mikezario.py View on Github external
def paletteMenu():
    while True:
        print("Starting Palette creation:")
        bpm = bpmMenu()
        csize = csizeMenu()
        progsize = psizeMenu()
        progcount = progcMenu()
        scale = scaleMenu()
        pal = musictheory.palette(scale, progsize, progcount, csize)
        pal._bpm = bpm
        while True:
            print("Palette created, Accept? Yy Nn(redo) Qq(quit):")
            inp = usrinp()
            if inp in "Yy":
                name = nameMenu()
                paletteEdit(pal, name)
                return
            elif inp in "Nn":
                print("Retrying:")
                break
            elif inp in "Qq":
                return
github joaoperfig / mikezart / source / mikezario.py View on Github external
def scaleMenu():
    while True:
        print("Please input the list of 7 notes in the Scale (ex: 'C Ds E ...'), a smaller list to autocomplete, or write G or g for random:")
        scalet = usrinp()
        if scalet in "Gg":
            scale = musictheory.scale7()
        else:
            notenames = str.split(scalet, " ")
            notes = ()
            for i in range(len(notenames)):
                if len(notenames[i]) != 0:
                    notes = notes + (musictheory.mnote.fromName(notenames[i] + "0"),)
            scale = musictheory.scale7(notes)
        while True:
            scaleInfo(scale)
            print()
            print ("Accept? (Yy, Nn, Pp(preview)):")
            inp = usrinp()
            if inp in "Yy":
                return scale
            elif inp in "Nn":
                break
            elif inp in "Pp":
                previewscale(scale)
github joaoperfig / mikezart / source / mikezario.py View on Github external
if inp2 in "Yy":
                    return chord
                elif inp2 in "Nn":
                    break
                elif inp2 in "Pp":
                    previewChord(chord)
        elif inp in "Ii":
            scaleInfo(scale)
        elif inp in "Qq":
            return None
        else:
            notenames = str.split(inp, " ")
            notes = ()
            for i in range(len(notenames)):
                if len(notenames[i]) != 0:
                    notes = notes + (musictheory.mnote.fromName(notenames[i] + "0"),)
            if len(notes) == 1:
                for i in scale.getChords():
                    if i._types[0]._type == notes[0]._type:
                        chord = i
                        break
                pianoprinter.octoPrint(chord._types)
                while True:
                    print(str(chord)+", accept? Yy Nn")
                    inp2 = usrinp()
                    if inp2 in "Yy":
                        return chord
                    elif inp2 in "Nn":
                        break
                
            elif len(notes) == 3:
                chord = musictheory.chord3(notes[0], notes[1], notes[2])
github joaoperfig / mikezart / source / mikezario.py View on Github external
def printInsts(insts):
    print("Selected instruments:")
    for inst in insts:
        notes = musictheory.listNotes(inst)
        bot = min(notes)
        top = max(notes)
        print(inst._name)
        print(inst._type)
        print(bot, "-", top)
        print()
    return
github joaoperfig / mikezart / source / mikezart2.py View on Github external
def testInst(name):
    inst = filezart.getInstrument(name)
    scale = musictheory.scale7()
    progsize = rselect((2,3,4,5,6))
    progcount = rselect((1,2,3,4,5))
    csize = wselect({2:5, 3:10, 4:20, 5:10, 6:5})
    bpm = wselect({80:5, 100:10, 120:20, 140:10, 160:5, 180:5})   
    palett = musictheory.palette(scale, progsize, progcount, csize)
    palett._bpm = bpm
    palett.autoProgs()    
    for i in range(2):
        centre = rselect(musictheory.listNotes(inst))
        ncount = wselect(musictheory.chordicCWeights())
        palett._n1.addVoice(inst, centre, "chordic", ncount)    
    play(palett._n1.previewAudio(bpm))
github joaoperfig / mikezart / source / mikezart2.py View on Github external
centre = rselect(musictheory.listNotes(inst))
            ncount = wselect(musictheory.smelodicCWeights())
            them.addVoice(inst, centre, "smelodic", ncount)
    for inst in lminsts:
        for them in themes:
            centre = rselect(musictheory.listNotes(inst))
            ncount = wselect(musictheory.lmelodicCWeights())
            them.addVoice(inst, centre, "lmelodic", ncount)
    for inst in pinsts:
        for them in themes:
            centre = rselect(musictheory.listNotes(inst))
            ncount = wselect(musictheory.percussionCWeights())
            them.addVoice(inst, centre, "percussion", ncount)
    for inst in ginsts:
        for them in themes:
            centre = rselect(musictheory.listNotes(inst))
            ncount = wselect(musictheory.genericCWeights())
            them.addVoice(inst, centre, "generic", ncount)    
    for inst in miminsts:
        for them in themes:
            toCopy = rselect(them._voices["chordic"] + them._voices["smelodic"])
            centre = rselect(musictheory.listNotes(inst))
            ncount = wselect(musictheory.chordicCWeights())
            voic = musictheory.voice(inst, centre, scale, "chordic", 0, 0)
            try:
                voic.mimic(toCopy)
                them.addVoiceAsIs(voic)                  
            except:
                print("could not mimic!")
    for t in themes:
        t.shuffleSort()
github joaoperfig / mikezart / source / mikezart2.py View on Github external
def adjustTest(pack = None, splay=True):
    if pack == None:
        pack = filezart.getInfo()
    else:
        pack = filezart.getPack(pack)
    for i in pack:
        clip = musictheory.getNote(i, musictheory.listNotes(i)[len(musictheory.listNotes(i))//2])
        dest = -30
        if splay:
            play(clip)
        print("audio:",clip.max_dBFS)
        print("delta:",dest-clip.max_dBFS)