def __call__( self, q_event_sequence, q_schema=None, grace_handler=None, heuristic=None, job_handler=None, attack_point_optimizer=None, attach_tempos=True, ): r'''Calls quantizer. Returns Abjad components. ''' from abjad.tools import quantizationtools q_event_sequence = quantizationtools.QEventSequence(q_event_sequence) if q_schema is None: q_schema = quantizationtools.MeasurewiseQSchema() assert isinstance(q_schema, quantizationtools.QSchema) q_target = q_schema(q_event_sequence.duration_in_ms) notation = q_target( q_event_sequence, grace_handler=grace_handler, heuristic=heuristic, job_handler=job_handler, attack_point_optimizer=attack_point_optimizer, attach_tempos=attach_tempos, ) return notation
def test_quantizationtools_QEventSequence_from_tempo_scaled_leaves_02(): staff = abjad.Staff([]) staff.append(abjad.Note(0, (1, 4))) staff.append(abjad.Rest((1, 4))) staff.append(abjad.Rest((1, 8))) staff.append(abjad.Note(1, (1, 8))) staff.append(abjad.Note(1, (1, 8))) staff.append(abjad.Note(2, (1, 8))) staff.append(abjad.Note(2, (1, 8))) staff.append(abjad.Note(3, (1, 8))) staff.append(abjad.Skip((1, 4))) staff.append(abjad.Rest((1, 4))) staff.append(abjad.Note(3, (1, 8))) staff.append(abjad.Chord([0, 1, 4], (1, 4))) tie = abjad.Tie() abjad.attach(tie, staff[3:5]) tie = abjad.Tie() abjad.attach(tie, staff[5:7]) tempo = abjad.MetronomeMark((1, 4), 58) abjad.attach(tempo, staff[0], context='Staff') tempo = abjad.MetronomeMark((1, 4), 77) abjad.attach(tempo, staff[9], context='Staff') leaves = abjad.select(staff).leaves() q_events = quantizationtools.QEventSequence.from_tempo_scaled_leaves( leaves) assert q_events == quantizationtools.QEventSequence( (quantizationtools.PitchedQEvent(abjad.Offset(0, 1), (abjad.NamedPitch("c'"), )), quantizationtools.SilentQEvent(abjad.Offset(30000, 29)), quantizationtools.PitchedQEvent(abjad.Offset(75000, 29), (abjad.NamedPitch("cs'"), )), quantizationtools.PitchedQEvent(abjad.Offset(105000, 29), (abjad.NamedPitch("d'"), )), quantizationtools.PitchedQEvent(abjad.Offset(135000, 29), (abjad.NamedPitch("ef'"), )), quantizationtools.SilentQEvent(abjad.Offset(150000, 29)), quantizationtools.PitchedQEvent(abjad.Offset(15600000, 2233), (abjad.NamedPitch("ef'"), )), quantizationtools.PitchedQEvent(abjad.Offset(16470000, 2233), ( abjad.NamedPitch("c'"), abjad.NamedPitch("cs'"), abjad.NamedPitch("e'"), )), quantizationtools.TerminalQEvent(abjad.Offset(18210000, 2233))))
def test_quantizationtools_QEventSequence_from_tempo_scaled_leaves_01(): staff = abjad.Staff([]) staff.append(abjad.Note(0, (1, 4))) staff.append(abjad.Rest((1, 4))) staff.append(abjad.Rest((1, 8))) staff.append(abjad.Note(1, (1, 8))) staff.append(abjad.Note(1, (1, 8))) staff.append(abjad.Note(2, (1, 8))) staff.append(abjad.Note(2, (1, 8))) staff.append(abjad.Note(3, (1, 8))) staff.append(abjad.Skip((1, 4))) staff.append(abjad.Rest((1, 4))) staff.append(abjad.Note(3, (1, 8))) staff.append(abjad.Chord([0, 1, 4], (1, 4))) tie = abjad.Tie() abjad.attach(tie, staff[3:5]) tie = abjad.Tie() abjad.attach(tie, staff[5:7]) tempo = abjad.MetronomeMark((1, 4), 55) leaves = abjad.select(staff).leaves() q_events = quantizationtools.QEventSequence.from_tempo_scaled_leaves( leaves, tempo) assert q_events == quantizationtools.QEventSequence( (quantizationtools.PitchedQEvent(abjad.Offset(0, 1), (abjad.NamedPitch("c'"), )), quantizationtools.SilentQEvent(abjad.Offset(12000, 11)), quantizationtools.PitchedQEvent(abjad.Offset(30000, 11), (abjad.NamedPitch("cs'"), )), quantizationtools.PitchedQEvent(abjad.Offset(42000, 11), (abjad.NamedPitch("d'"), )), quantizationtools.PitchedQEvent(abjad.Offset(54000, 11), (abjad.NamedPitch("ef'"), )), quantizationtools.SilentQEvent(abjad.Offset(60000, 11)), quantizationtools.PitchedQEvent(abjad.Offset(84000, 11), (abjad.NamedPitch("ef'"), )), quantizationtools.PitchedQEvent(abjad.Offset(90000, 11), ( abjad.NamedPitch("c'"), abjad.NamedPitch("cs'"), abjad.NamedPitch("e'"), )), quantizationtools.TerminalQEvent(abjad.Offset(102000, 11))))
def test_quantizationtools_QEventSequence_from_millisecond_durations_03(): r'''Silences are fused. ''' durations = [100, -100, 100, -100, -100, 100] q_events = quantizationtools.QEventSequence.from_millisecond_durations( durations, fuse_silences=True) assert q_events == quantizationtools.QEventSequence( (quantizationtools.PitchedQEvent(abjad.Offset(0), (abjad.NamedPitch("c'"), )), quantizationtools.SilentQEvent(abjad.Offset(100)), quantizationtools.PitchedQEvent(abjad.Offset(200), (abjad.NamedPitch("c'"), )), quantizationtools.SilentQEvent(abjad.Offset(300)), quantizationtools.PitchedQEvent(abjad.Offset(500), (abjad.NamedPitch("c'"), )), quantizationtools.TerminalQEvent(abjad.Offset(600))))
def test_quantizationtools_QEventSequence_from_millisecond_pitch_pairs_01(): durations = [100, 200, 100, 300, 350, 400, 600] pitches = [0, None, None, [1, 4], None, 5, 7] pairs = tuple(zip(durations, pitches)) q_events = quantizationtools.QEventSequence.from_millisecond_pitch_pairs( pairs) assert q_events == quantizationtools.QEventSequence(( quantizationtools.PitchedQEvent( abjad.Offset(0), (abjad.NamedPitch("c'"),) ), quantizationtools.SilentQEvent( abjad.Offset(100, 1) ), quantizationtools.PitchedQEvent( abjad.Offset(400, 1), ( abjad.NamedPitch("cs'"), abjad.NamedPitch("e'") ) ), quantizationtools.SilentQEvent( abjad.Offset(700, 1) ), quantizationtools.PitchedQEvent( abjad.Offset(1050, 1), (abjad.NamedPitch("f'"),) ), quantizationtools.PitchedQEvent( abjad.Offset(1450, 1), (abjad.NamedPitch("g'"),) ), quantizationtools.TerminalQEvent( abjad.Offset(2050, 1), ) ))
def test_quantizationtools_QEventSequence_from_tempo_scaled_durations_01(): r'''Test basic functionality. ''' durations = [ abjad.Duration(x) for x in [(1, 4), (1, 3), (1, 7), (2, 5), (3, 4)] ] tempo = abjad.MetronomeMark((1, 4), 55) q_events = quantizationtools.QEventSequence.from_tempo_scaled_durations( durations, tempo) assert q_events == quantizationtools.QEventSequence( (quantizationtools.PitchedQEvent(abjad.Offset(0, 1), (abjad.NamedPitch("c'"), )), quantizationtools.PitchedQEvent(abjad.Offset(12000, 11), (abjad.NamedPitch("c'"), )), quantizationtools.PitchedQEvent(abjad.Offset(28000, 11), (abjad.NamedPitch("c'"), )), quantizationtools.PitchedQEvent(abjad.Offset(244000, 77), (abjad.NamedPitch("c'"), )), quantizationtools.PitchedQEvent(abjad.Offset(34400, 7), (abjad.NamedPitch("c'"), )), quantizationtools.TerminalQEvent(abjad.Offset(630400, 77))))
def test_quantizationtools_QEventSequence_from_tempo_scaled_durations_02(): r'''Silences are fused. ''' durations = [ abjad.Duration(x) for x in [(1, 4), (-1, 4), (1, 4), (1, 4), (-1, 4), (-1, 4), (1, 4)] ] tempo = abjad.MetronomeMark((1, 4), 77) q_events = quantizationtools.QEventSequence.from_tempo_scaled_durations( durations, tempo) assert q_events == quantizationtools.QEventSequence( (quantizationtools.PitchedQEvent(abjad.Offset(0, 1), (abjad.NamedPitch("c'"), )), quantizationtools.SilentQEvent(abjad.Offset(60000, 77)), quantizationtools.PitchedQEvent(abjad.Offset(120000, 77), (abjad.NamedPitch("c'"), )), quantizationtools.PitchedQEvent(abjad.Offset(180000, 77), (abjad.NamedPitch("c'"), )), quantizationtools.SilentQEvent(abjad.Offset(240000, 77)), quantizationtools.PitchedQEvent(abjad.Offset(360000, 77), (abjad.NamedPitch("c'"), )), quantizationtools.TerminalQEvent(abjad.Offset(60000, 11))))
def test_quantizationtools_QEventSequence_from_millisecond_durations_01(): r'''Test basic functionality. ''' durations = abjad.mathtools.difference_series( [x[0] for x in test_time_segments]) q_events = quantizationtools.QEventSequence.from_millisecond_durations( durations) assert q_events == quantizationtools.QEventSequence( (quantizationtools.PitchedQEvent(abjad.Offset(0, 1), (abjad.NamedPitch("c'"), )), quantizationtools.PitchedQEvent(abjad.Offset(163, 1), (abjad.NamedPitch("c'"), )), quantizationtools.PitchedQEvent(abjad.Offset(511, 1), (abjad.NamedPitch("c'"), )), quantizationtools.PitchedQEvent(abjad.Offset(627, 1), (abjad.NamedPitch("c'"), )), quantizationtools.PitchedQEvent(abjad.Offset(1208, 1), (abjad.NamedPitch("c'"), )), quantizationtools.PitchedQEvent(abjad.Offset(1417, 1), (abjad.NamedPitch("c'"), )), quantizationtools.PitchedQEvent(abjad.Offset(1997, 1), (abjad.NamedPitch("c'"), )), quantizationtools.PitchedQEvent(abjad.Offset(3204, 1), (abjad.NamedPitch("c'"), )), quantizationtools.PitchedQEvent(abjad.Offset(3297, 1), (abjad.NamedPitch("c'"), )), quantizationtools.PitchedQEvent(abjad.Offset(4087, 1), (abjad.NamedPitch("c'"), )), quantizationtools.PitchedQEvent(abjad.Offset(4296, 1), (abjad.NamedPitch("c'"), )), quantizationtools.PitchedQEvent(abjad.Offset(4830, 1), (abjad.NamedPitch("c'"), )), quantizationtools.PitchedQEvent(abjad.Offset(6362, 1), (abjad.NamedPitch("c'"), )), quantizationtools.PitchedQEvent(abjad.Offset(6595, 1), (abjad.NamedPitch("c'"), )), quantizationtools.PitchedQEvent(abjad.Offset(6687, 1), (abjad.NamedPitch("c'"), )), quantizationtools.PitchedQEvent(abjad.Offset(7013, 1), (abjad.NamedPitch("c'"), )), quantizationtools.PitchedQEvent(abjad.Offset(7245, 1), (abjad.NamedPitch("c'"), )), quantizationtools.PitchedQEvent(abjad.Offset(7872, 1), (abjad.NamedPitch("c'"), )), quantizationtools.PitchedQEvent(abjad.Offset(8197, 1), (abjad.NamedPitch("c'"), )), quantizationtools.PitchedQEvent(abjad.Offset(8359, 1), (abjad.NamedPitch("c'"), )), quantizationtools.PitchedQEvent(abjad.Offset(8638, 1), (abjad.NamedPitch("c'"), )), quantizationtools.PitchedQEvent(abjad.Offset(8731, 1), (abjad.NamedPitch("c'"), )), quantizationtools.PitchedQEvent(abjad.Offset(8917, 1), (abjad.NamedPitch("c'"), )), quantizationtools.PitchedQEvent(abjad.Offset(9288, 1), (abjad.NamedPitch("c'"), )), quantizationtools.PitchedQEvent(abjad.Offset(9404, 1), (abjad.NamedPitch("c'"), )), quantizationtools.PitchedQEvent(abjad.Offset(10240, 1), (abjad.NamedPitch("c'"), )), quantizationtools.PitchedQEvent(abjad.Offset(10356, 1), (abjad.NamedPitch("c'"), )), quantizationtools.PitchedQEvent(abjad.Offset(10496, 1), (abjad.NamedPitch("c'"), )), quantizationtools.PitchedQEvent(abjad.Offset(10890, 1), (abjad.NamedPitch("c'"), )), quantizationtools.PitchedQEvent(abjad.Offset(11169, 1), (abjad.NamedPitch("c'"), )), quantizationtools.PitchedQEvent(abjad.Offset(11285, 1), (abjad.NamedPitch("c'"), )), quantizationtools.PitchedQEvent(abjad.Offset(11424, 1), (abjad.NamedPitch("c'"), )), quantizationtools.PitchedQEvent(abjad.Offset(12307, 1), (abjad.NamedPitch("c'"), )), quantizationtools.PitchedQEvent(abjad.Offset(12957, 1), (abjad.NamedPitch("c'"), )), quantizationtools.PitchedQEvent(abjad.Offset(13073, 1), (abjad.NamedPitch("c'"), )), quantizationtools.PitchedQEvent(abjad.Offset(13653, 1), (abjad.NamedPitch("c'"), )), quantizationtools.PitchedQEvent(abjad.Offset(13979, 1), (abjad.NamedPitch("c'"), )), quantizationtools.PitchedQEvent(abjad.Offset(14234, 1), (abjad.NamedPitch("c'"), )), quantizationtools.PitchedQEvent(abjad.Offset(15256, 1), (abjad.NamedPitch("c'"), )), quantizationtools.PitchedQEvent(abjad.Offset(15883, 1), (abjad.NamedPitch("c'"), )), quantizationtools.PitchedQEvent(abjad.Offset(16022, 1), (abjad.NamedPitch("c'"), )), quantizationtools.PitchedQEvent(abjad.Offset(16649, 1), (abjad.NamedPitch("c'"), )), quantizationtools.PitchedQEvent(abjad.Offset(16927, 1), (abjad.NamedPitch("c'"), )), quantizationtools.PitchedQEvent(abjad.Offset(17044, 1), (abjad.NamedPitch("c'"), )), quantizationtools.PitchedQEvent(abjad.Offset(17276, 1), (abjad.NamedPitch("c'"), )), quantizationtools.TerminalQEvent(abjad.Offset(18483, 1))))