Python 2.7.6 (default, Jan 10 2014, 13:35:22)
Type "copyright", "credits" or "license" for more information.
IPython 1.1.0 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
%guiref -> A brief reference about the graphical user interface.
In [1]: # My goal was to analyze the set of Bach chorales in the music21 corpus to answer the following question: Of the chorales that are in a minor key, what proportion end with the Picardy third (i.e., the final chord is major)? From my experience with Bach's style, I hypothesized that the answer would be quite high, maybe around 90%.
In [2]: from music21 import *
In [3]: works = []
...: for workName in corpus.getBachChorales():
...: work = converter.parse(workName)
...: fe = features.native.QualityFeature(work)
...: f = fe.extract()
...: if f.vector == [1]: # f.vector is [0] for major and [1] for minor
...: works.append(work)
...:
...:
...:
In [4]: # This was super slow!!
In [5]: total = len(works)
In [6]: print(total)
182
In [7]: # So there are 182 minor key chorales. Now we need to go through each one and check the quality of the final chord.
In [8]: count = 0
...: for work in works:
...: chordsOnly = work.flat
...: chordsOnly = chordsOnly.chordify()
...: chordsOnly = chordsOnly.notes # this eliminates extraneous rests and barlines which might occur at the end
...: lastChord = chordsOnly[-1]
...: if lastChord.quality == 'major':
...: count += 1
In [9]: # This was also super slow!
In [10]: print(count)
169
In [11]: percent = 100 * count / float(total)
In [12]: print(percent)
92.8571428571
In [13]: # So in fact, in the music21 corpus of Bach chorales, about 93% of the minor chorales end with the Picardy third, slightly higher even than I predicted. It would be interesting to examine the 7% that do not to see whether they share any common characteristics! Perhaps in a future project.