-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPattern.py
More file actions
90 lines (80 loc) · 3.45 KB
/
Pattern.py
File metadata and controls
90 lines (80 loc) · 3.45 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
import pretty_midi
from Note import Note
class Pattern:
def __init__(self, lengthOfSixteenthNote):
self.lengthOfSixteenthNote = lengthOfSixteenthNote
self.pattern = []
self.length = 0
self.place = 0
self.dynamic = 63
self.id = 0
return
def AddNote(self, letter, octave, rhythmicValue):
if rhythmicValue == 'graceNote':
lengthOfGraceNote = self.place - (self.lengthOfSixteenthNote * .5)
self.pattern.append(Note(letter, octave, lengthOfGraceNote, self.place))
# so self.place = self.place
return
elif rhythmicValue == 'sixteenth':
end = self.place + self.lengthOfSixteenthNote
elif rhythmicValue == 'eighth':
end = self.place + (self.lengthOfSixteenthNote * 2)
elif rhythmicValue == 'dottedEighth':
end = self.place + (self.lengthOfSixteenthNote * 3)
elif rhythmicValue == 'quarter':
end = self.place + (self.lengthOfSixteenthNote * 4)
elif rhythmicValue == 'dottedQuarter':
end = self.place + (self.lengthOfSixteenthNote * 6)
elif rhythmicValue == 'half':
end = self.place + (self.lengthOfSixteenthNote * 8)
elif rhythmicValue == 'halfTiedToEighth':
end = self.place + (self.lengthOfSixteenthNote * 10)
elif rhythmicValue == 'dottedHalf':
end = self.place + (self.lengthOfSixteenthNote * 12)
elif rhythmicValue == 'dottedHalfTiedToSixteenth':
end = self.place + (self.lengthOfSixteenthNote * 13)
elif rhythmicValue == 'dottedHalfTiedToEighth':
end = self.place + (self.lengthOfSixteenthNote * 14)
elif rhythmicValue == 'whole':
end = self.place + (self.lengthOfSixteenthNote * 16)
elif rhythmicValue == 'wholeTiedToQuarter':
end = self.place + (self.lengthOfSixteenthNote * 20)
elif rhythmicValue == 'dottedWhole':
end = self.place + (self.lengthOfSixteenthNote * 24)
elif rhythmicValue == 'tiedWhole':
end = self.place + (self.lengthOfSixteenthNote * 32)
self.pattern.append(Note(letter, octave, self.place, end))
self.place = end
self.length = self.place
return
def AddRest(self, rhythmicValue):
if rhythmicValue == 'emptyMeasure':
self.place = self.place + (self.lengthOfSixteenthNote * 4)
self.length = self.place
#self.pattern.append(Note('C', 4, 0, 0))
elif rhythmicValue == 'sixteenth':
self.place = self.place + self.lengthOfSixteenthNote
elif rhythmicValue == 'eighth':
self.place = self.place + (self.lengthOfSixteenthNote * 2)
elif rhythmicValue == 'dottedEighth':
self.place = self.place + (self.lengthOfSixteenthNote * 3)
elif rhythmicValue == 'quarter':
self.place = self.place + (self.lengthOfSixteenthNote * 4)
self.length = self.place
return
def GetPattern(self):
return self.pattern
def GetLength(self):
return self.length
def SetDynamic(self, dynamic):
self.dynamic = dynamic
return
def SetID(self, id):
self.id = id
return
def GetID(self):
return self.id
def GetMIDIData(self, instrument, place):
for i in range(0, len(self.pattern)):
instrument.notes.append(self.pattern[i].GetMIDIData(place, self.dynamic))
return