-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
109 lines (87 loc) · 1.99 KB
/
Copy pathtest.py
File metadata and controls
109 lines (87 loc) · 1.99 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
from music21 import *
import hhmm
"""
s=stream.Stream()
n=note.Note('a4', type='32nd')
s.append(meter.TimeSignature('4/4'))
s.append(n)
s.show()
paths=corpus.getComposer('bach')
c = converter.parse('tinynotation: 4/4 c4 d e f')
c.show('text')
fp = converter.freeze(c, fmt='pickle')
print fp
data1 = [('g4', 'quarter'), ('a4', 'quarter'), ('b4', 'quarter'), ('c#5', 'quarter')]
data2 = [('d5', 'whole')]
data = [data1, data2]
partUpper = stream.Part()
for mData in data:
m = stream.Measure()
for pitchName, durType in mData:
n = note.Note(pitchName)
n.duration.type = durType
m.append(n)
partUpper.append(m)
A = key.KeySignature(3)
for m in partUpper:
for n in m:
print "\t",type(n)
# x=n.transpose('g4')
# print "\t\t===========",x
# n.transpose('g4',inPlace=True)
print type(partUpper)
partUpper.flat.transpose('a4').show()
partUpper.show()
"""
import pdb
seqs=[]
f = open('matlab25_chorales.data','r')
for line in f:
temp=[]
line=line.split()
for n in line:
temp.append(int(n))
seqs.append(temp)
f.close()
smax=0
for s in seqs:
if len(s)>smax:
smax=len(s)
for s in seqs:
if len(s)<smax:
while len(s)!=smax:
s.append(1)
print "making seq variable for matlab"
print "making note dictionary (used as states)"
ndict={}
for s in seqs:
for i in s:
ndict[i]=0
matlab_dict={}
matlab_reverse={}
counter=1
for n in ndict:
matlab_dict[n]=counter
matlab_reverse[counter]=n
counter+=1
def back_to_midi(note_seq):
new_seq=[]
for n in note_seq:
if matlab_reverse[n]==1:
hhmm.write_midi(new_seq)
return
elif matlab_reverse[n]==0:
continue
new_seq.append(matlab_reverse[n])
hhmm.write_midi(new_seq)
"""
for s in seqs:
for x in s:
print matlab_dict[x], ' ',
print ';',''
print '\n\n\n\n'
for n in ndict:
for n2 in ndict:
print float(1)/len(ndict), ' ',
print ';',''
"""