Mercurial > hg > syncopation-dataset
comparison Syncopation models/basic_functions.py @ 23:df1e7c378ee0
fixed KTH, and WNBD
author | csong <csong@eecs.qmul.ac.uk> |
---|---|
date | Sun, 12 Apr 2015 13:06:17 +0100 |
parents | 2dbc09ca8013 |
children | d9d22e6f396d |
comparison
equal
deleted
inserted
replaced
22:2dbc09ca8013 | 23:df1e7c378ee0 |
---|---|
78 if number % odd == 0: | 78 if number % odd == 0: |
79 isPrime = False | 79 isPrime = False |
80 return isPrime | 80 return isPrime |
81 | 81 |
82 # convert a velocity sequence to its minimum time-span representation | 82 # convert a velocity sequence to its minimum time-span representation |
83 def velocity_sequence_to_min_timetpan(velocitySequence): | 83 def velocity_sequence_to_min_timespan(velocitySequence): |
84 minTimeSpanVelocitySeq = [1] | 84 minTimeSpanVelocitySeq = [1] |
85 for divisors in find_divisor(len(velocitySequence)): | 85 for divisors in find_divisor(len(velocitySequence)): |
86 segments = subdivide(velocitySequence,divisors) | 86 segments = subdivide(velocitySequence,divisors) |
87 if len(segments)!=0: | 87 if len(segments)!=0: |
88 del minTimeSpanSequence[:] | 88 del minTimeSpanVelocitySeq[:] |
89 for s in segments: | 89 for s in segments: |
90 minTimeSpanVelocitySeq.append(s[0]) | 90 minTimeSpanVelocitySeq.append(s[0]) |
91 if sum(minTimeSpanVelocitySeq) == sum(velocitySequence): | 91 if sum(minTimeSpanVelocitySeq) == sum(velocitySequence): |
92 break | 92 break |
93 return minTimeSpanVelocitySeq | 93 return minTimeSpanVelocitySeq |
94 | 94 |
95 # convert a note sequence to its minimum time-span representation | 95 # convert a note sequence to its minimum time-span representation |
96 def note_sequence_to_min_timespan(noteSequence, barTicks): | 96 def note_sequence_to_min_timespan(noteSequence): |
97 barBinaryArray = [0]*barTicks | 97 from music_objects import note_sequence_to_velocity_sequence |
98 timeSpanTicks = len(note_sequence_to_velocity_sequence(noteSequence)) | |
99 # print timeSpanTicks | |
100 | |
101 barBinaryArray = [0]*(timeSpanTicks+1) | |
98 for note in noteSequence: | 102 for note in noteSequence: |
99 # mark note_on event (i.e. startTime) and note_off event (i.e. endTime = startTime + duration) as 1 in the barBinaryArray | 103 # mark note_on event (i.e. startTime) and note_off event (i.e. endTime = startTime + duration) as 1 in the barBinaryArray |
100 barBinaryArray[note[0]] = 1 | 104 barBinaryArray[note.startTime] = 1 |
101 barBinaryArray[note[0]+note[1]] = 1 | 105 barBinaryArray[note.startTime + note.duration] = 1 |
102 | 106 |
103 # convert the barBinaryArray to its minimum time-span representation | 107 # convert the barBinaryArray to its minimum time-span representation |
104 minBarBinaryArray = velocitySequence_to_min_timeSpan(barBinaryArray) | 108 minBarBinaryArray = velocity_sequence_to_min_timetpan(barBinaryArray[:-1]) |
109 print barBinaryArray | |
110 print minBarBinaryArray | |
105 delta_t = len(barBinaryArray)/len(minBarBinaryArray) | 111 delta_t = len(barBinaryArray)/len(minBarBinaryArray) |
106 | 112 |
107 # scale the startTime and duration of each note by delta_t | 113 # scale the startTime and duration of each note by delta_t |
108 for note in noteSequence: | 114 for note in noteSequence: |
109 note[0] = note[0]/delta_t | 115 note.startTime = note.startTime/delta_t |
110 note[1] = note[1]/delta_t | 116 note.duration = note.duration/delta_t |
111 | 117 |
112 return noteSequence | 118 return noteSequence |
113 | 119 |
114 | 120 |
115 | 121 |