-
Notifications
You must be signed in to change notification settings - Fork 0
/
mcgilldata-corpusStatsBySong.py
71 lines (64 loc) · 2.41 KB
/
mcgilldata-corpusStatsBySong.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
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
thisRow.append(songID)
songTitle = theSong.title
thisRow.append(songTitle)
songArtist = theSong.artist
thisRow.append(songArtist)
begTonicTrack = 0
modeChange = 0
meterChange = 0
tonicChange = 0
for thePhrase in theSong.phrases:
#FIND BEGINNING SONG VALUES ONLY (TONIC, METER, MODE)
for theMeasure in thePhrase.measures:
if begTonicTrack == 0:
if theMeasure.measureNumber == 1:
begTonic = theMeasure.tonic
thisRow.append(begTonic)
begMode = thePhrase.mode
thisRow.append(begMode)
begMeter = theMeasure.meter
thisRow.append(begMeter)
begTonicTrack += 1
if meterChange == 0:
thisRow.append(meterChange)
if theMeasure.changeMeter == True:
meterChange = 1
thisRow[-1] = meterChange
if tonicChange == 0:
thisRow.append(tonicChange)
if theMeasure.changeTonic == True:
tonicChange = 1
thisRow[-1] = tonicChange
# if phraseMode == currentMode:
# modeChange = 0
# thisRow.append(modeChange)
# currentMode = phraseMode
# else:
# modeChange = 1
# thisRow.append(modeChange)
outputCsv.writerow(thisRow)