-
Notifications
You must be signed in to change notification settings - Fork 0
/
LargeDataset.py
49 lines (49 loc) · 1.26 KB
/
LargeDataset.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
#from __future__ import division
try:
import cPickle as pickle
except:
import pickle
import midi
import os.path
import os
from operator import itemgetter
from collections import OrderedDict
import numpy as np
from SongData import SongData
def Main():
#these values should match what is in SongData
#and are here just for reference
#REST = 128
#HOLD = 129
#NULL = 130
#END = 131
#BEATS_PER_BAR = 32
#extract features
absolute_pos = 0
folder = os.path.join('downloads','midiworld')
pitches = set()
songs = []
observedstates = set()
featurevectors = []
import csv
with open('features.csv','wb') as out:
try:
print('finding valid songs')
csv_out=csv.writer(out)
valid_filenames = []
for filename in os.listdir(folder):
out_of_range = False
song_path = os.path.join(folder, filename)
pattern = midi.read_midifile(song_path)
song = SongData(pattern, filename)
for action in song.eventset:
if (action > 84 and action < 128) or action < 48:
out_of_range = True
if song.startstate.pitch == 131:
out_of_range = True
if not out_of_range:
valid_filenames.append(song.filename)
print(len(valid_filenames))
pdump(valid_filenames, 'valid_filenames.pkl',noPrefix=True)
if __name__ == "__main__":
Main()