Exemplo n.º 1
0
#---------------------------------------------------------------------
# from paper_3a

# use \\ because this runs on windoze

# initialize structure
thedata = []

# go over all files
for root, dirs, files in os.walk(".\\corpus"):
    for filename in files:
        thisfilepath = root + '\\' + filename
        # print(thisfilepath)
        thisdata = parse_kern_file(thisfilepath, 16)
        # ignore duration and turn key into pc number
        thisdata = (pitchclass(thisdata[0]), [i[1] for i in thisdata[1]])
        # add to main collection, ignoring key
        thedata += thisdata[1]

# sort all of our chords because we're not going to hear weird register changes
# also remove duplicated pitches to avoid weirdness
thedata = [sorted(list(set(i))) for i in thedata]

# look at only 4-note chords
tetrachords = list(filter(lambda i: len(i) == 4, thedata))

# note that thedata :: [[Int]], where Int stands for pitch


# MIDI-Hz conversion
def mtof(midinote):
    'red', 'orange', 'yellow', 'green', 'blue', 'magenta', 'brown', 'gray',
    'black'
]
plt.figure(2)

for degree in range(7):
    print("Scale Degree", degree + 1, '\n')

    # start structure
    thisdata = []

    # keep only those chords whose lowest pc is the right scaledegree, and is size 3/4.
    # I could do this more concisely...
    for i in keysdata:
        # i[0] is key as string, i[1] is list of chords
        tonic = pitchclass(i[0])
        for j in i[1]:
            if (len(j) in [3, 4]) and (((j[0] - tonic) % 12)
                                       in heightsizes[degree]):
                thisdata.append(j)
    thisresult = run_this_pair(thisdata)
    sized_scatter_sub(thisresult, degcolors[degree], str(degree + 1))

plt.xlabel('Lowest pitch of pset (Hz)')
plt.ylabel('Arithmetic span of pset (Hz)')
plt.legend()

# 4c: by key
print('Experiment 4c: global keys')

plt.figure(3)