#NEWLINE# def segmentIntoBeats( self ) : #NEWLINE# #INDENT# self . beats = [ ] #NEWLINE# messages = self . mainMessages #NEWLINE# on = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# index = 0 #NEWLINE# tickLimit = 0 #NEWLINE# result = [ ] #NEWLINE# for i in xrange ( self . getTotalBeats ( ) ) : #NEWLINE# #INDENT# tickLimit += self . ticks_per_beat #NEWLINE# while ( ( index < len ( self . mainMessages ) ) and ( ( toRemove - self . mainMessages [ index ] . time ) >= 0 ) ) : #NEWLINE# #INDENT# message = self . mainMessages [ index ] #NEWLINE# for note in on : #NEWLINE# #INDENT# if on [ note ] [ 0 ] : #NEWLINE# #INDENT# on [ note ] = ( True , ( on [ note ] [ 1 ] + min ( self . ticks_per_beat , message . time ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# if ( message . velocity == 0 ) : #NEWLINE# #INDENT# if ( message . note in on ) : #NEWLINE# #INDENT# on [ message . note ] = ( False , on [ message . note ] [ 1 ] ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( message . note in on ) : #NEWLINE# #INDENT# on [ message . note ] = ( True , on [ message . note ] [ 1 ] ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# on [ message . note ] = ( True , 0 ) #NEWLINE# #UNINDENT# #UNINDENT# tickLimit -= message . time #NEWLINE# index += 1 #NEWLINE# #UNINDENT# for note in on : #NEWLINE# #INDENT# if on [ note ] [ 0 ] : #NEWLINE# #INDENT# on [ note ] = ( True , ( on [ note ] [ 1 ] + tickLimit ) ) #NEWLINE# #UNINDENT# #UNINDENT# result . append ( [ ( note , ( length / float ( self . ticks_per_beat ) ) ) for ( note , ( isOn , length ) ) in on . items ( ) if ( length > 0 ) ] ) #NEWLINE# toRemove = [ ] #NEWLINE# for note in on : #NEWLINE# #INDENT# if on [ note ] [ 0 ] : #NEWLINE# #INDENT# on [ note ] = ( True , 0 ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# toRemove . append ( note ) #NEWLINE# #UNINDENT# #UNINDENT# for note in toRemove : #NEWLINE# #INDENT# del on [ note ] #NEWLINE# #UNINDENT# #UNINDENT# self . beats = result