def test_Quantizer___call___11(): quantizer = nauert.Quantizer() durations = [250, 1250, 750, 1000, 250] pitches = range(5) all_attachments = [(x,) for x in pitches] pitches = [(x, x + 7) for x in pitches] q_event_sequence = nauert.QEventSequence.from_millisecond_pitch_attachment_tuples( tuple(zip(durations, pitches, all_attachments)) ) time_signature = abjad.TimeSignature((7, 8)) search_tree = nauert.UnweightedSearchTree( definition={ 2: {2: None, 3: None}, 3: {2: None, 3: None}, 5: {2: None}, 7: {2: None}, 13: None, } ) q_schema = nauert.MeasurewiseQSchema( time_signature=time_signature, search_tree=search_tree, use_full_measure=True, ) grace_handler = nauert.ConcatenatingGraceHandler( replace_rest_with_final_grace_note=True ) attack_point_optimizer = nauert.MeasurewiseAttackPointOptimizer() result = quantizer( q_event_sequence, q_schema=q_schema, grace_handler=grace_handler, attack_point_optimizer=attack_point_optimizer, ) staff = abjad.Staff([result]) string = abjad.lilypond(staff) assert string == abjad.string.normalize( r""" \new Staff { \new Voice { { \tempo 4=60 \time 7/8 <c' g'>16 <cs' af'>16 ~ <cs' af'>4 <d' a'>8. <ef' bf'>16 ~ <ef' bf'>8. <e' b'>16 } } } """ ), print(string) assert_q_event_attachments(result, all_attachments)
def test_Quantizer___call___02(): milliseconds = [750, 750] q_events = nauert.QEventSequence.from_millisecond_durations(milliseconds) quantizer = nauert.Quantizer() optimizer = nauert.MeasurewiseAttackPointOptimizer() result = quantizer(q_events, attack_point_optimizer=optimizer) staff = abjad.Staff([result], lilypond_type="RhythmicStaff") score = abjad.Score([staff]) assert abjad.lilypond(score) == abjad.string.normalize( r""" \new Score << \new RhythmicStaff { \new Voice { { \tempo 4=60 \time 4/4 c'8. c'16 ~ c'8 r8 r2 } } } >> """ ), print(abjad.lilypond(score))
def test_Quantizer___call___15(): durations = [1000, 1000, 1000, 400, 50, 50] pitches = range(len(durations)) quantizer = nauert.Quantizer() q_event_sequence = nauert.QEventSequence.from_millisecond_pitch_pairs( tuple(zip(durations, pitches)) ) search_tree = nauert.UnweightedSearchTree() attack_point_optimizer = nauert.MeasurewiseAttackPointOptimizer() q_schema = nauert.MeasurewiseQSchema( search_tree=search_tree, time_signature=(7, 8), use_full_measure=True ) result = quantizer( q_event_sequence, q_schema=q_schema, attach_tempos=True, attack_point_optimizer=attack_point_optimizer, ) staff = abjad.Staff([result]) string = abjad.lilypond(staff) assert string == abjad.string.normalize( r""" \new Staff { \new Voice { { \tempo 4=60 \time 7/8 c'4 cs'8 ~ cs'8 d'8 ~ d'8 \afterGrace ef'8 { e'16 f'16 } } } } """ ), print(string)
def test_Quantizer___call___14(): definition = {"divisors": (2, 3, 5, 7), "max_depth": 2, "max_divisions": 2} search_tree = nauert.WeightedSearchTree(definition=definition) quantizer = nauert.Quantizer() durations = [1000, 1000, 1000, 400, 50, 50, 3500] pitches = range(len(durations)) q_event_sequence = nauert.QEventSequence.from_millisecond_pitch_pairs( tuple(zip(durations, pitches)) ) q_schema = nauert.MeasurewiseQSchema( search_tree=search_tree, time_signature=(7, 8), use_full_measure=True ) attack_point_optimizer = nauert.MeasurewiseAttackPointOptimizer() result = quantizer( q_event_sequence, q_schema=q_schema, attack_point_optimizer=attack_point_optimizer, attach_tempos=True, ) staff = abjad.Staff([result]) string = abjad.lilypond(staff) assert string == abjad.string.normalize( r""" \new Staff { \new Voice { { \tempo 4=60 \time 7/8 c'4 cs'8 ~ cs'8 d'8 ~ d'8 ef'8 } { \grace { e'16 f'16 } fs'2.. } } } """ ), print(string)
def test_MeasurewiseAttackPointOptimizer___call___01(): string = r""" \times 8/11 { a''8 ~ a''8 ~ a''8 ~ a''8 ~ a''8 ~ a''8 ~ a''8 \grace { e''16 e''16 } d''8 ~ d''8 r8 r8 } """ string = abjad.string.normalize(string) container = abjad.Container(string) time_signature = abjad.TimeSignature((4, 4)) attack_point_optimizer = nauert.MeasurewiseAttackPointOptimizer() attack_point_optimizer(container, time_signature) string = abjad.lilypond(container) assert string == abjad.string.normalize(r""" { \times 8/11 { a''2.. \grace { e''16 e''16 } d''4 r4 } } """), print(string)
def __init__( self, sequence, q_schema=None, grace_handler=None, heuristic=None, attack_point_optimizer=None, attach_tempos=True, ): self._sequence = sequence self._q_schema = q_schema or nauert.MeasurewiseQSchema() self._grace_handler = grace_handler or nauert.ConcatenatingGraceHandler( replace_rest_with_final_grace_note=True) self._heuristic = heuristic or nauert.DistanceHeuristic() self._attack_point_optimizer = ( attack_point_optimizer or nauert.MeasurewiseAttackPointOptimizer()) self._attach_tempos = attach_tempos self._quantizer = nauert.Quantizer()
def make_cloud(self, *arguments, **keywords): self._simulate_queue() results = [] measurewise_q_schema = nauert.MeasurewiseQSchema( *arguments, **keywords) grace_handler = nauert.ConcatenatingGraceHandler( replace_rest_with_final_grace_note=True) optimizer = nauert.MeasurewiseAttackPointOptimizer() quantizer = nauert.Quantizer() for durations_ms, pitches in zip(self.durations_msps, self.pitches_per_server): q_event_sequence = nauert.QEventSequence.from_millisecond_pitch_pairs( tuple(zip(durations_ms, pitches))) result = quantizer( q_event_sequence, q_schema=measurewise_q_schema, grace_handler=grace_handler, attack_point_optimizer=optimizer, attach_tempos=False, ) results.append(result) return results
def test_Quantizer___call___09(): q_schema = nauert.BeatwiseQSchema( {"search_tree": nauert.UnweightedSearchTree({2: None})}, {"search_tree": nauert.UnweightedSearchTree({3: None})}, {"search_tree": nauert.UnweightedSearchTree({5: None})}, {"search_tree": nauert.UnweightedSearchTree({7: None})}, ) milliseconds = [250, 250, 250, 250] * 4 q_events = nauert.QEventSequence.from_millisecond_durations(milliseconds) attack_point_optimizer = nauert.MeasurewiseAttackPointOptimizer() quantizer = nauert.Quantizer() try: quantizer( q_events, q_schema=q_schema, attack_point_optimizer=attack_point_optimizer, ) assert False except TypeError as error: assert ( str(error) == "BeatwiseQTarget is not supposed to be used together with MeasurewiseAttackPointOptimizer." )
def test_Quantizer___call___16(): durations = [1546, 578, 375, 589, 144, 918, 137] pitches = list(range(len(durations))) pitches[0] = None all_attachments = [(x,) for x in pitches] all_attachments[0] = None quantizer = nauert.Quantizer() q_event_sequence = nauert.QEventSequence.from_millisecond_pitch_attachment_tuples( tuple(zip(durations, pitches, all_attachments)) ) definition = {"divisors": (2, 3, 5, 7), "max_depth": 2, "max_divisions": 2} search_tree = nauert.WeightedSearchTree(definition=definition) attack_point_optimizer = nauert.MeasurewiseAttackPointOptimizer() q_schema = nauert.MeasurewiseQSchema( search_tree=search_tree, tempo=abjad.MetronomeMark((1, 4), 72), time_signature=(7, 8), use_full_measure=True, ) result = quantizer( q_event_sequence, q_schema=q_schema, attach_tempos=True, attack_point_optimizer=attack_point_optimizer, ) staff = abjad.Staff([result]) string = abjad.lilypond(staff) assert string == abjad.string.normalize( r""" \new Staff { \new Voice { { \tweak text #tuplet-number::calc-fraction-text \times 5/7 { \tempo 4=72 \time 7/8 r4. r4 cs'4 } d'8 ef'8 ~ } { \times 4/5 { ef'16 e'32 ~ e'16 } f'4 fs'2 } } } """ ), print(string) assert_q_event_attachments(result, all_attachments[1:])