def get_notes_by_rt_interval(self, interval): conversion = TimeConversion(self.tempo_sequence, self.time_signature_sequence, Position(self.duration.duration)) wnt_interval = Interval( conversion.actual_time_to_position(interval.lower), conversion.actual_time_to_position(interval.upper)) return self.get_notes_by_wnt_interval(wnt_interval)
def get_notes_starting_in_rt_interval(self, interval): """ Get all notes starting in the score by an interval based on real time: Return dict structure as follows: instrument_voice --> {voice_index --> [notes]} """ conversion = TimeConversion(self.tempo_sequence, self.time_signature_sequence, Position(self.duration.duration)) wnt_interval = Interval( conversion.actual_time_to_position(interval.lower), conversion.actual_time_to_position(interval.upper)) return self.get_notes_starting_in_wnt_interval(wnt_interval)
def test_time_conversion_simple(self): tempo_line = EventSequence([TempoEvent(Tempo(60), Position(0))]) ts_line = EventSequence([ TimeSignatureEvent(TimeSignature(3, Duration(1, 4)), Position(0)) ]) conversion = TimeConversion(tempo_line, ts_line, Position(1, 1)) actual_time = conversion.position_to_actual_time(Position(3, 4)) print(actual_time) self.assertTrue(actual_time == 3000, 'actual time = {0} should be 3000'.format(actual_time)) position = conversion.actual_time_to_position(3000) print(position) self.assertTrue(position, Position(3, 4))
def test_position_to_actual_time(self): tempo_line = EventSequence([ TempoEvent(Tempo(60), Position(0)), TempoEvent(Tempo(20), Position(4, 4)) ]) ts_line = EventSequence([ TimeSignatureEvent(TimeSignature(3, Duration(1, 4)), Position(0)), TimeSignatureEvent(TimeSignature(2, Duration(1, 8)), Position(5, 4)) ]) conversion = TimeConversion(tempo_line, ts_line, Position(2, 1)) actual_time = conversion.position_to_actual_time(Position(6, 4)) print(actual_time) # 4 quarter notes @ 60 with 1/4 beat = 4000 # 1 quarter note @ 20 with 1/4 beat = 3000 # 2 eighth notes @ 20 (effective 40) with 1/8 beat = 3000 self.assertTrue( actual_time == 10000, 'actual time = {0} should be 10000'.format(actual_time)) position = conversion.actual_time_to_position(10000) print(position) self.assertEquals(position, Position(6, 4))