Example #1
0
 def test_basic_4_4_signature(self):
     ticks_per_qn = 4
     s = TimeSignature(4, 4, ticks_per_qn)
     self.assertFalse(s.is_tick_start_of_bar(15))
     self.assertTrue(s.is_tick_start_of_bar(16),
                     'tick 16 is start of new bar (ticks start at 0)')
     self.assertTrue(s.is_tick_start_of_bar(0))
Example #2
0
 def test_5_4_signature(self):
     ticks_per_qn = 8
     s = TimeSignature(5, 4, ticks_per_qn)
     self.assertTrue(s.is_tick_start_of_bar(0))
     self.assertFalse(
         s.is_tick_start_of_bar(39),
         'first bar range == 0 ..< 5*8, which means 40 start of new')
     self.assertTrue(s.is_tick_start_of_bar(40))
Example #3
0
 def test_find_looping_point_for_0_time_stamp(self):
     time_signature = TimeSignature(numerator=4,
                                    denumerator=4,
                                    ticks_per_quarter_note=4)
     event_time_stamps = [0]
     event_list: EventList = MockEventGenerator().generate_events(
         event_time_stamps)
     looping_point = event_list.find_looping_point_for_time_signature(
         time_signature)
     self.assertEqual(time_signature.get_num_ticks_per_bar(), looping_point)
Example #4
0
    def find_looping_point_for_time_signature(
            self, time_signature: TimeSignature) -> int:
        loop_end = self.find_highest_time_stamp()

        # if the event is at 1st tick of a new bar, you want to loop for an extra bar
        if loop_end % time_signature.get_num_ticks_per_bar() == 0:
            return loop_end + time_signature.get_num_ticks_per_bar()

        while not time_signature.is_tick_start_of_bar(loop_end):
            loop_end += 1
        return loop_end
Example #5
0
 def __init__(self):
     self.event_list = None
     self.play_state = PlayStates.stopped
     self.time_signature = TimeSignature(numerator=4,
                                         denumerator=4,
                                         ticks_per_quarter_note=4)
     self.play_head = PlayHead()
Example #6
0
    def sample_events_to_string_with_time_signature(
            self, sample_name: str, time_signature: TimeSignature) -> str:
        num_ticks = int(
            self.find_looping_point_for_time_signature(time_signature))
        ticks_per_denum = int(time_signature.ticks_per_denumerator)
        ticks_per_bar = int(time_signature.get_num_ticks_per_bar())
        num_bars = int(num_ticks / ticks_per_bar)

        seq = [False] * num_ticks

        for i in self.get_time_stamps_for_sample(sample_name):
            seq[i] = True

        string = '|'

        for bar in range(num_bars):
            for beat in range(time_signature.numerator):
                for tick in range(ticks_per_denum):
                    if seq[bar * ticks_per_bar + ticks_per_denum * beat +
                           tick]:
                        string += 'x'
                    else:
                        string += '.'
                string += ' '
            string = string[:-1] + '|'

        return string
Example #7
0
 def test_to_string_multi_bar(self):
     time_signature = TimeSignature(numerator=5,
                                    denumerator=4,
                                    ticks_per_quarter_note=2)
     event_time_stamps = [0, 2, 4, 6, 8, 10, 13]
     event_list = MockEventGenerator().generate_events(event_time_stamps)
     expected_string = '|x. x. x. x. x.|x. .x .. .. ..|'
     actual_string = event_list.to_string_with_time_signature(
         time_signature)
     self.assertEqual(expected_string, actual_string)
Example #8
0
 def test_to_string(self):
     time_signature = TimeSignature(numerator=5,
                                    denumerator=4,
                                    ticks_per_quarter_note=8)
     event_time_stamps = [0, 8, 16, 24, 32]
     event_list: EventList = MockEventGenerator().generate_events(
         event_time_stamps)
     expected_string = '|x....... x....... x....... x....... x.......|'
     actual_string = event_list.to_string_with_time_signature(
         time_signature)
     self.assertEqual(expected_string, actual_string)
Example #9
0
 def load_state(self, state: dict) -> None:
     self.state = state
     self.play_state = PlayStates.stopped
     self.tempo_bpm = state['tempo']
     self.time_signature = TimeSignature(settings=state['time_signature'])
     self.sample_list = SampleList(state['samples'])
     self.event_handler = SimpleAudio_EventHandler(self.sample_list)
     self.event_list = EventList(sample_list=self.sample_list, state=state['events'])
     self.clock = Clock(tick_time_ms=self.calculate_tick_time())
     self.keep_thread_active = True
     self.update_looping_position()
     self.rewind()
Example #10
0
 def __init__(self):
     super(AudioTransport, self).__init__()
     self.play_state = PlayStates.stopped
     self.tempo_bpm = 100
     self.ms_between_ticks = 0
     self.time_signature = TimeSignature(numerator=4,
                                         denumerator=4,
                                         ticks_per_quarter_note=4)
     self.playhead = PlayHead()
     self.event_list = EventList([])
     self.event_handler = EventHandler()
     self.recalculate_tick_time()
     self.keep_thread_active = True
     self.start()
Example #11
0
 def test_7_8_signature(self):
     ticks_per_qn = 8
     s = TimeSignature(7, 8, ticks_per_qn)
     self.assertTrue(s.is_tick_start_of_bar(0))
     self.assertFalse(s.is_tick_start_of_bar(1))
     # each 8th note has 4/8 quarter notes, so each 8th note has 4/8 * 8 ticks
     # each bar has 7 8th notes, which would mean 7 * 4/8 * 8 ticks
     expected_num_ticks_per_bar = 7 * (4 / 8) * 8
     self.assertEqual(s.get_num_ticks_per_bar(), expected_num_ticks_per_bar)
     self.assertTrue(s.is_tick_start_of_bar(expected_num_ticks_per_bar * 2))
Example #12
0
 def test_musical_time_to_ticks(self):
     s = TimeSignature(numerator=5, denumerator=4, ticks_per_quarter_note=8)
     bar, beat, tick = 2, 3, 4
     expected = bar * (5 * 8) + beat * 8 + tick
     self.assertEqual(expected, s.musical_time_to_ticks(bar, beat, tick))
Example #13
0
 def time_signature(self):
     beats, beat_type = self.beats, self.beat_type
     if beats and beat_type:
         return TimeSignature(beats, beat_type)