def fill_skips(self, voice): """ Add Skips at the end of the bar, so that it is filled. We assume that any elements already added are placed at the correct timepos. """ # nt = short for "next timepos", the timepos to start fill skips to if voice.get_timeposes_of(self): nt = voice.get_timeposes_of(self)[-1] nt = nt + voice.m_tdict[nt]['elem'][0].m_duration.get_rat_value() else: # we get here if the bar is empty nt = self.m_timepos default_skip = Rat(1, 4) # pos within default skip pp = nt - int(nt / default_skip) * default_skip if pp != Rat(0, 1): # Here we add a skip so that the next column will be X times # default_skip voice.set_elem([Skip(Duration.new_from_rat(default_skip - pp))], nt) nt += (default_skip - pp) # And the we fill the bar with Skips as long as default_skip. while nt < self.end(): voice.set_elem([Skip(Duration.new_from_rat(default_skip))], nt) nt += default_skip
def fill_skips(self, voice): """ Add Skips at the end of the bar, so that it is filled. We assume that any elements already added are placed at the correct timepos. """ # nt = short for "next timepos", the timepos to start fill skips to if voice.get_timeposes_of(self): nt = voice.get_timeposes_of(self)[-1] nt = nt + voice.m_tdict[nt]['elem'][0].m_duration.get_rat_value() else: # we get here if the bar is empty nt = self.m_timepos default_skip = Rat(1, 4) # pos within default skip pp = nt - int (nt / default_skip) * default_skip if pp != Rat(0, 1): # Here we add a skip so that the next column will be X times # default_skip voice.set_elem([Skip(Duration.new_from_rat(default_skip - pp))], nt) nt += (default_skip - pp) # And the we fill the bar with Skips as long as default_skip. while nt < self.end(): voice.set_elem([Skip(Duration.new_from_rat(default_skip))], nt) nt += default_skip
def test_set_from_rat(self): for i in (1, 2, 4, 8, 16, 32, 64): d = Duration.new_from_rat(Rat(1, i)) self.assertEquals(d, Duration(i, 0)) d = Duration.new_from_rat(Rat(3, 8)) self.assertEquals(d.get_rat_value(), Rat(3, 8))