import mcgilldata, string, os, sys, collections, csv, music21

mcgillPath = 'mcgill-billboard'

#Gives spreadsheet of information by song:
    #Each song's tonic, mode, meter, instrumentation (including tonic/mode/meter change
#Mode includes ambiguous, major, and minor

theCorpus = mcgilldata.mcgillCorpus(mcgillPath, testMode = True)

#create spreadsheet with basic song information metadata
outputCsv = csv.writer(open('csv-results/corpusStatsBySong.csv', 'wb'))

#Create spreadsheet            
headerRow = list()
headerRow.append('SongID')
headerRow.append('Title')
headerRow.append('Artist')
headerRow.append('Beg. Tonic') 
headerRow.append('Beg. Mode')
headerRow.append('Beg. Meter')
headerRow.append('Meter Change?')
headerRow.append('Tonic Change?')
headerRow.append('Mode Change?')
outputCsv.writerow(headerRow)
####CODE INFORMATION

for theSongid, theSong in theCorpus.songs.iteritems():
    thisRow = list()
#Build metadata spreadsheet
    songID = theSongid
Beispiel #2
0
import mcgilldata, string, os, sys, collections, csv

mcgillPath = 'mcgill-billboard'

theCorpus = mcgilldata.mcgillCorpus(mcgillPath, testMode=True)

ChordTally = dict()  #Create dictionary of unigram distributions for all keys
outputColumns = collections.Counter()

for theSongid, theSong in theCorpus.songs.iteritems():

    for thePhrase in theSong.phrases:
        for theMeasure in thePhrase.measures:
            songTonic = theMeasure.tonic
            if songTonic not in ChordTally:
                ChordTally[songTonic] = collections.Counter()
            for theChord in theMeasure.chords:
                chordRoot = theChord.rootSD
                quality = theChord.quality
                outputColumns[chordRoot + quality] += 1
                ChordTally[songTonic][chordRoot + quality] += 1
outputCsv = csv.writer(open('chordUnigrams-quality.csv', 'wb'))
headerRow = list()
headerRow.append('Song Tonic')
headerRow.append('Chord Count')
for (chordType, count) in sorted(outputColumns.most_common(25)):
    headerRow.append(chordType)
outputCsv.writerow(headerRow)

for tonic in ChordTally:
    thisRow = list()
Beispiel #3
0
import mcgilldata, string

mcgillPath = 'mcgill-billboard'

theCorpus = mcgilldata.mcgillCorpus(mcgillPath)

for theSongid, theSong in theCorpus.songs.iteritems():
	for theMeasure in theSong.measuresFlat:
			print theMeasure
						
import mcgilldata, string, os, sys, collections, pprint, csv

#This code gives the most common chord for each root-type
#Chords are organized by chordRoot

mcgillPath = 'mcgill-billboard'

theCorpus = mcgilldata.mcgillCorpus(mcgillPath, testMode = False)

ChordTally = collections.Counter() #Create dictionary of unigram distributions for all roots
ChordTallyReduced = collections.Counter() #Create dictionary of unigram distributions for all reduced chords

for theSongid, theSong in theCorpus.songs.items():
    for thePhrase in theSong.phrases:
        for theMeasure in thePhrase.measures:
            for theChord in theMeasure.chords:
                chordRoot = theChord.rootPC
                chordQual = theChord.rootPC + theChord.quality
                chordRed = theChord.rootPC + theChord.qualityReduced
                #create chord tally for specific root
                ChordTally[chordRoot] += 1
                #create chord tally for specific reduced chord
                ChordTallyReduced[chordRed] += 1

for (chordRoot, count) in ChordTally.most_common():
	frequency = ((count * 1.0) / sum(ChordTally.values()))
	#determines frequency for a specific chordRoot
	print '{:>4}: {:.1%} ({})'.format(chordRoot,frequency,count)	
	#prints most common chords for specific root, based on given parameters
	 
	
Beispiel #5
0
##Set default variables
##If change key, triad, beat, or form mode will affect NGRAM pickle
global keyMode
keyMode = False
global triadMode  #Change of triad mode will affect DATA and NGRAM PICKLE
triadMode = 0
global beatMode
beatMode = False
global formMode
formMode = False
#####DO NOT CHANGE UNLESS NECESSARY
countThreshold = 10
testMode = True

mcgillPath = 'mcgill-billboard'
theCorpus = mcgilldata.mcgillCorpus(mcgillPath, triadMode, keyMode, testMode)

##RUN ngram algorithm
if keyMode == False:
    theCorpus.findNgramsNoKey(keyMode, beatMode, formMode, triadMode,
                              countThreshold, testMode)
    filename = 'csv-results/nGramResults/ngrams' + '_' + str(
        countThreshold) + '_noKey' + '_TriadMode' + str(
            triadMode) + '_BeatMode' + str(beatMode) + '_formMode' + str(
                formMode)
else:
    theCorpus.findNgrams(
        keyMode,
        beatMode,
        formMode,
        triadMode,
global triadMode #Change of triad mode will affect DATA and SUFFIXTREE PICKLE
triadMode = 0
global beatMode
beatMode = False  
global formMode
formMode = False
#####DO NOT CHANGE UNLESS NECESSARY
treeDepth = 20
countThreshold = 20
entropyThreshold = 0
probThreshold = 0.25
testMode = False
singleMode = True#Determines whether only run once or run as automatic mode

mcgillPath = 'mcgill-billboard'
theCorpus = mcgilldata.mcgillCorpus(mcgillPath, triadMode, keyMode, testMode)

###Run in Single Mode (Will only run one value per variable type)
if singleMode:
    ##RUN entropy algorithm
    if keyMode == False:
        theCorpus.findLicksNoKey(keyMode, beatMode, formMode, triadMode, treeDepth, countThreshold, entropyThreshold, probThreshold)
        filename = 'csv-results/entropyResults/ngrams-entropy' + '_noKey' + '_TriadMode' + str(triadMode) + '_BeatMode' + str(beatMode) + '_formMode' + str(formMode) + '_' + str(entropyThreshold) + '_' + str(probThreshold)
    else: 
        theCorpus.findLicks(keyMode, beatMode, formMode, triadMode, treeDepth, countThreshold, entropyThreshold, probThreshold)
        filename = 'csv-results/entropyResults/ngrams-entropy' + '_Key' + '_TriadMode' + str(triadMode) + '_BeatMode' + str(beatMode) + '_formMode' + str(formMode) + '_' + str(entropyThreshold) + '_' + str(probThreshold)
    
    #Output progressions
    outputList = theCorpus.listLicks(keyMode, beatMode, formMode, triadMode, entropyThreshold, probThreshold)

    #Write progressions
Beispiel #7
0
import mcgilldata, string, os, sys, collections, csv, music21
from mcgilldata import *

#Gives spreadsheet of information by song:
#Each song's tonic, mode, meter, instrumentation (including tonic/mode/meter change
#Mode includes ambiguous, major, and minor

mcgillPath = 'mcgill-billboard'
theCorpus = mcgilldata.mcgillCorpus(mcgillPath, testMode=False)

#create spreadsheet with basic song information metadata
outputCsv = csv.writer(open('csv-results/corpusStatsBySong.csv', 'wb'))

#Create spreadsheet
headerRow = list()
headerRow.append('SongID')
headerRow.append('Title')
headerRow.append('Artist')
headerRow.append('Beg. Tonic')
headerRow.append('Beg. Mode')
headerRow.append('Beg. Meter')
headerRow.append('Meter Change?')
headerRow.append('Tonic Change?')
headerRow.append('Mode Change?')
outputCsv.writerow(headerRow)

####CODE INFORMATION

for theSongid, theSong in theCorpus.songs.iteritems():
    thisRow = list()
    #Build metadata spreadsheet