Mercurial > hg > syncopation-dataset
comparison Syncopation models/music_objects.py @ 13:bc3b9022ebc4
Merged.
author | csong <csong@eecs.qmul.ac.uk> |
---|---|
date | Fri, 03 Apr 2015 17:05:31 +0100 |
parents | c2843ef4de2c |
children | 4fb9c00e4ef0 |
comparison
equal
deleted
inserted
replaced
12:4acddc008048 | 13:bc3b9022ebc4 |
---|---|
1 | 1 |
2 from BasicFuncs import ceiling | 2 from basic_functions import ceiling, string_to_sequence |
3 | 3 |
4 import ParameterSetter | 4 import parameter_setter |
5 import RhythmParser | 5 import rhythm_parser |
6 | 6 |
7 class Note(): | 7 class Note(): |
8 def __init__(self, argstring): | 8 def __init__(self, argstring): |
9 intlist = map(int,argstring.split(',')) | 9 intlist = string_to_sequence(argstring) |
10 self.startTime = intlist[0] | 10 self.startTime = intlist[0] |
11 self.duration = intlist[1] | 11 self.duration = intlist[1] |
12 self.velocity = intlist[2] | 12 self.velocity = intlist[2] |
13 | 13 |
14 # toString() | 14 # toString() |
18 def __init__(self, noteSequenceString=None): | 18 def __init__(self, noteSequenceString=None): |
19 if noteSequenceString!=None: | 19 if noteSequenceString!=None: |
20 self.string_to_note_sequence(noteSequenceString) | 20 self.string_to_note_sequence(noteSequenceString) |
21 | 21 |
22 def string_to_note_sequence(self, noteSequenceString): | 22 def string_to_note_sequence(self, noteSequenceString): |
23 noteSequenceString = RhythmParser.discardSpaces(noteSequenceString) | 23 noteSequenceString = rhythm_parser.discardSpaces(noteSequenceString) |
24 # try: | 24 # try: |
25 # Turning "(1,2,3),(4,5,6),(7,8,9)" into ["1,2,3","4,5,6,","7,8,9"] | 25 # Turning "(1,2,3),(4,5,6),(7,8,9)" into ["1,2,3","4,5,6,","7,8,9"] |
26 listStrings = noteSequenceString[1:-1].split("),(") | 26 listStrings = noteSequenceString[1:-1].split("),(") |
27 for localString in listStrings: | 27 for localString in listStrings: |
28 self.append(Note(localString)) | 28 self.append(Note(localString)) |
29 | 29 |
30 # toString() | 30 # toString() |
31 | 31 |
32 | 32 |
33 print NoteSequence("(1,2,3),(4,5,6),(7,8,9)") | 33 #print NoteSequence("(1,2,3),(4,5,6),(7,8,9)") |
34 # class VelocitySequence(list): | 34 class VelocitySequence(list): |
35 # def __init__(self, noteSequenceString=None): | 35 def __init__(self, noteSequenceString=None): |
36 # if noteSequenceString!=None: | 36 if noteSequenceString!=None: |
37 # self.string_to_note_sequence(noteSequenceString) | 37 self.string_to_note_sequence(noteSequenceString) |
38 | 38 |
39 # def string_to_note_sequence(string): | 39 def string_to_note_sequence(self,inputString): |
40 self.extend(string_to_sequence(inputString)) | |
40 | 41 |
41 | 42 |
42 class BarList(list): | 43 class BarList(list): |
43 def append(self,bar): | 44 def append(self,bar): |
44 if(len(self)>0): | 45 if(len(self)>0): |
45 bar.set_previous_bar(self[-1]) | 46 bar.set_previous_bar(self[-1]) |
46 self[-1].set_next_bar(bar) | 47 self[-1].set_next_bar(bar) |
47 super(BarList, self).append(bar) | 48 super(BarList, self).append(bar) |
49 | |
50 | |
48 | 51 |
49 | 52 |
50 | 53 |
51 class Bar: | 54 class Bar: |
52 | 55 |
64 self.nextBar = nextBar | 67 self.nextBar = nextBar |
65 self.prevBar = prevBar | 68 self.prevBar = prevBar |
66 | 69 |
67 def get_note_sequence(self): | 70 def get_note_sequence(self): |
68 #if self.noteSequence==None: | 71 #if self.noteSequence==None: |
69 # self.noteSequence = velocitySequenceToNotes(self.velocitySequence) | 72 # self.noteSequence = velocity_sequence_to_notes(self.velocitySequence) |
70 return self.noteSequence | 73 return self.noteSequence |
71 | 74 |
72 def get_velocity_sequence(self): | 75 def get_velocity_sequence(self): |
73 if self.velocitySequence==None: | 76 if self.velocitySequence==None: |
74 self.velocitySequence = noteSequenceToVelocities(self.velocitySequence) | 77 self.velocitySequence = note_sequence_to_velocities(self.velocitySequence) |
75 return self.velocitySequence | 78 return self.velocitySequence |
76 | 79 |
77 def get_binary_sequence(self): | 80 def get_binary_sequence(self): |
78 return ceiling(self.get_velocity_sequence()) | 81 return ceiling(self.get_velocity_sequence()) |
79 | 82 |