def __init__(self, *args): from abjad.tools import indicatortools if len(args) == 1 and isinstance(args[0], type(self)): self._tempo_indication = args[0].tempo_indication self._proportional_notation_duration = \ args[0].proportional_notation_duration elif len(args) == 2: tempo = args[0] if isinstance(tempo, tuple): tempo = indicatortools.Tempo(*tempo) tempo_indication = tempo proportional_notation_duration = durationtools.Duration(args[1]) self._tempo_indication = tempo_indication self._proportional_notation_duration = \ proportional_notation_duration elif len(args) == 0: tempo = indicatortools.Tempo() proportional_notation_duration = durationtools.Duration(1, 68) self._tempo_indication = tempo self._proportional_notation_duration = \ proportional_notation_duration else: message = 'can not initialize spacing indication from {!r}' message = message.format(args) raise ValueError(message)
def __init__( self, beatspan=None, offset_in_ms=None, search_tree=None, tempo=None, ): from abjad.tools import quantizationtools beatspan = beatspan or durationtools.Duration(0) beatspan = durationtools.Duration(beatspan) offset_in_ms = offset_in_ms or durationtools.Duration(0) offset_in_ms = durationtools.Offset(offset_in_ms) if search_tree is None: search_tree = quantizationtools.UnweightedSearchTree() assert isinstance(search_tree, quantizationtools.SearchTree) tempo = tempo or indicatortools.Tempo(durationtools.Duration(1, 4), 60) #tempo = indicatortools.Tempo(tempo) if isinstance(tempo, tuple): tempo = indicatortools.Tempo(*tempo) assert not tempo.is_imprecise q_events = [] q_grids = [] self._beatspan = beatspan self._distances = {} self._offset_in_ms = offset_in_ms self._q_events = q_events self._q_grid = None self._q_grids = q_grids self._search_tree = search_tree self._tempo = tempo
def __init__( self, offset_in_ms=None, search_tree=None, time_signature=None, tempo=None, use_full_measure=False, ): from abjad.tools import quantizationtools offset_in_ms = offset_in_ms or 0 offset_in_ms = durationtools.Offset(offset_in_ms) if search_tree is None: search_tree = quantizationtools.UnweightedSearchTree() assert isinstance(search_tree, quantizationtools.SearchTree) tempo = tempo or indicatortools.Tempo((1, 4), 60) #tempo = indicatortools.Tempo(tempo) if isinstance(tempo, tuple): tempo = indicatortools.Tempo(*tempo) assert not tempo.is_imprecise time_signature = time_signature or (4, 4) time_signature = indicatortools.TimeSignature(time_signature) use_full_measure = bool(use_full_measure) beats = [] if use_full_measure: beatspan = time_signature.duration beat = quantizationtools.QTargetBeat( beatspan=beatspan, offset_in_ms=offset_in_ms, search_tree=search_tree, tempo=tempo ) beats.append(beat) else: beatspan = durationtools.Duration(1, time_signature.denominator) current_offset_in_ms = offset_in_ms beatspan_duration_in_ms = \ tempo.duration_to_milliseconds(beatspan) for i in range(time_signature.numerator): beat = quantizationtools.QTargetBeat( beatspan=beatspan, offset_in_ms=current_offset_in_ms, search_tree=search_tree, tempo=tempo ) beats.append(beat) current_offset_in_ms += beatspan_duration_in_ms self._beats = tuple(beats) self._offset_in_ms = offset_in_ms self._search_tree = search_tree self._tempo = tempo self._time_signature = time_signature self._use_full_measure = use_full_measure
def coerce_(expr): if expr is None: tempo = indicatortools.Tempo() elif isinstance(expr, tuple): tempo = indicatortools.Tempo(*expr) elif isinstance(expr, indicatortools.Tempo): tempo = copy.copy(expr) else: raise TypeError(repr(expr)) return tempo
def __init__(self, *args, **kwargs): from abjad.tools import quantizationtools self._beatspan = durationtools.Duration(kwargs.get('beatspan', (1, 4))) search_tree = kwargs.get('search_tree', quantizationtools.UnweightedSearchTree()) assert isinstance(search_tree, quantizationtools.SearchTree) self._search_tree = search_tree tempo = kwargs.get('tempo', ((1, 4), 60)) if isinstance(tempo, tuple): tempo = indicatortools.Tempo(*tempo) self._tempo = tempo QSchema.__init__(self, *args, **kwargs)
def __init__(self, *args, **kwargs): from abjad.tools import quantizationtools search_tree = kwargs.get('search_tree', quantizationtools.UnweightedSearchTree()) assert isinstance(search_tree, quantizationtools.SearchTree) self._search_tree = search_tree tempo = kwargs.get('tempo', ((1, 4), 60)) if isinstance(tempo, tuple): tempo = indicatortools.Tempo(*tempo) self._tempo = tempo self._time_signature = indicatortools.TimeSignature( kwargs.get('time_signature', (4, 4))) self._use_full_measure = bool(kwargs.get('use_full_measure')) QSchema.__init__(self, *args, **kwargs)
def set_tempo(self, source_expression): r'''Set tempo to `source_expresion`. Returns tempo set expression. ''' from experimental.tools import musicexpressiontools if isinstance(source_expression, indicatortools.Tempo): source_expression = copy.copy(source_expression) elif isinstance(source_expression, tuple): source_expression = indicatortools.Tempo(*source_expression) else: raise TypeError(source_expression) source_expression = \ musicexpressiontools.PayloadExpression(payload=source_expression) attribute = 'tempo' return self._store_leaf_set_expression(attribute, source_expression)
def __init__( self, search_tree=None, tempo=None, ): from abjad.tools import quantizationtools if search_tree is not None: assert isinstance(search_tree, quantizationtools.SearchTree) self._search_tree = search_tree #if tempo is not None: # tempo = indicatortools.Tempo(tempo) # assert not tempo.is_imprecise if tempo is not None: if isinstance(tempo, tuple): tempo = indicatortools.Tempo(*tempo) assert not tempo.is_imprecise self._tempo = tempo
def from_tempo_scaled_leaves(cls, leaves, tempo=None): r'''Convert ``leaves``, optionally with ``tempo`` into a ``QEventSequence``: :: >>> staff = Staff("c'4 <d' fs'>8. r16 gqs'2") >>> tempo = Tempo((1, 4), 72) :: >>> sequence = \ ... quantizationtools.QEventSequence.from_tempo_scaled_leaves( ... staff[:], tempo=tempo) :: >>> for q_event in sequence: ... print(format(q_event, 'storage')) ... quantizationtools.PitchedQEvent( offset=durationtools.Offset(0, 1), pitches=( pitchtools.NamedPitch("c'"), ), ) quantizationtools.PitchedQEvent( offset=durationtools.Offset(2500, 3), pitches=( pitchtools.NamedPitch("d'"), pitchtools.NamedPitch("fs'"), ), ) quantizationtools.SilentQEvent( offset=durationtools.Offset(4375, 3), ) quantizationtools.PitchedQEvent( offset=durationtools.Offset(5000, 3), pitches=( pitchtools.NamedPitch("gqs'"), ), ) quantizationtools.TerminalQEvent( offset=durationtools.Offset(10000, 3), ) If ``tempo`` is ``None``, all leaves in ``leaves`` must have an effective, non-imprecise tempo. The millisecond-duration of each leaf will be determined by its effective tempo. Return ``QEventSequence`` instance. ''' from abjad.tools import quantizationtools from abjad.tools import selectiontools Selection = selectiontools.Selection assert Selection._all_are_contiguous_components_in_same_logical_voice( leaves) assert len(leaves) if tempo is None: assert leaves[0]._get_effective(indicatortools.Tempo) is not None #else: # #tempo = indicatortools.Tempo(tempo) elif isinstance(tempo, indicatortools.Tempo): tempo = copy.copy(tempo) elif isinstance(tempo, tuple): tempo = indicatortools.Tempo(*tempo) else: raise TypeError(tempo) # sort by silence and tied leaves groups = [] for rvalue, rgroup in itertools.groupby( leaves, lambda x: isinstance(x, (scoretools.Rest, scoretools.Skip))): if rvalue: groups.append(list(rgroup)) else: for tvalue, tgroup in itertools.groupby( rgroup, lambda x: x._get_logical_tie()): groups.append(list(tgroup)) # calculate lists of pitches and durations durations = [] pitches = [] for group in groups: # get millisecond cumulative duration if tempo is not None: duration = sum( tempo.duration_to_milliseconds(x._get_duration()) for x in group) else: duration = sum( x._get_effective(indicatortools.Tempo). duration_to_milliseconds(x._get_duration()) for x in group) durations.append(duration) # get pitch of first leaf in group if isinstance(group[0], (scoretools.Rest, scoretools.Skip)): pitch = None elif isinstance(group[0], scoretools.Note): pitch = group[0].written_pitch.pitch_number else: # chord pitch = [ x.written_pitch.pitch_number for x in group[0].note_heads ] pitches.append(pitch) # convert durations and pitches to QEvents and return return cls.from_millisecond_pitch_pairs(tuple(zip(durations, pitches)))
# -*- encoding: utf-8 -*- import armilla import consort from abjad import new from abjad.tools import indicatortools from abjad.tools import spannertools from abjad.tools import selectortools ### SEGMENT MAKER ### segment_maker = armilla.ArmillaSegmentMaker( desired_duration_in_seconds=60 / 2, discard_final_silence=True, name='Selidor (iii)', repeat=True, tempo=indicatortools.Tempo((1, 4), 72), ) ### ATTACHMENTS ### intermittent_trills = armilla.materials.intermittent_trills ### MUSIC SPECIFIERS ### rh_circular = new( armilla.materials.right_hand_circular_music_specifier, attachment_handler__stem_tremolo_spanner=consort.AttachmentExpression( attachments=( None, spannertools.StemTremoloSpanner(), ),
def __call__(self): '''Calls score template. Returns LilyPond file. ''' # make bell voice and staff bell_voice = scoretools.Voice(name='Bell Voice') bell_staff = scoretools.Staff([bell_voice], name='Bell Staff') clef = indicatortools.Clef('treble') attach(clef, bell_staff) bells = instrumenttools.Instrument( instrument_name='Campana in La', short_instrument_name='Camp.', pitch_range='[C4, C6]', ) attach(bells, bell_staff) tempo = indicatortools.Tempo((1, 4), (112, 120)) attach(tempo, bell_staff) time_signature = indicatortools.TimeSignature((6, 4)) attach(time_signature, bell_staff) # make first violin voice and staff first_violin_voice = scoretools.Voice(name='First Violin Voice') first_violin_staff = scoretools.Staff( [first_violin_voice], name='First Violin Staff', ) clef = indicatortools.Clef('treble') attach(clef, first_violin_staff) violin = instrumenttools.Violin( instrument_name_markup=markuptools.Markup('Violin I'), short_instrument_name_markup=markuptools.Markup('Vl. I'), ) attach(violin, first_violin_staff) # make second violin voice and staff second_violin_voice = scoretools.Voice(name='Second Violin Voice') second_violin_staff = scoretools.Staff( [second_violin_voice], name='Second Violin Staff', ) clef = indicatortools.Clef('treble') attach(clef, second_violin_staff) violin = instrumenttools.Violin( instrument_name_markup=markuptools.Markup('Violin II'), short_instrument_name_markup=markuptools.Markup('Vl. II'), ) attach(violin, second_violin_staff) # make viola voice and staff viola_voice = scoretools.Voice(name='Viola Voice') viola_staff = scoretools.Staff([viola_voice], name='Viola Staff') clef = indicatortools.Clef('alto') attach(clef, viola_staff) viola = instrumenttools.Viola() attach(viola, viola_staff) # make cello voice and staff cello_voice = scoretools.Voice(name='Cello Voice') cello_staff = scoretools.Staff([cello_voice], name='Cello Staff') clef = indicatortools.Clef('bass') attach(clef, cello_staff) cello = instrumenttools.Cello() attach(cello, cello_staff) # make bass voice and staff bass_voice = scoretools.Voice(name='Bass Voice') bass_staff = scoretools.Staff([bass_voice], name='Bass Staff') clef = indicatortools.Clef('bass') attach(clef, bass_staff) contrabass = instrumenttools.Contrabass( short_instrument_name_markup=markuptools.Markup('Cb.'), ) attach(contrabass, bass_staff) # make strings staff group strings_staff_group = scoretools.StaffGroup( [ first_violin_staff, second_violin_staff, viola_staff, cello_staff, bass_staff, ], name='Strings Staff Group', ) # make score score = scoretools.Score([ bell_staff, strings_staff_group, ], name='Pärt Cantus Score') # return Pärt Cantus score return score
import armilla import consort from abjad import new from abjad.tools import durationtools from abjad.tools import indicatortools from abjad.tools import scoretools from abjad.tools import selectortools ### SEGMENT MAKER ### segment_maker = armilla.ArmillaSegmentMaker( desired_duration_in_seconds=30, discard_final_silence=True, name='Far Sorr', repeat=False, tempo=indicatortools.Tempo((1, 4), 36), ) ### ATTACHMENTS ### dietro_ponticello = consort.AttachmentExpression( attachments=indicatortools.StringContactPoint('dietro ponticello'), scope=scoretools.Voice, selector=selectortools.Selector().by_leaf(), ) intermittent_accents = armilla.materials.intermittent_accents intermittent_circular = armilla.materials.intermittent_circular intermittent_glissandi = armilla.materials.intermittent_glissandi intermittent_tremoli = armilla.materials.intermittent_tremoli ### MUSIC SPECIFIERS ###
from abjad import new from abjad.tools import indicatortools from abjad.tools import rhythmmakertools from abjad.tools import selectortools import armilla import consort ### SEGMENT MAKER ### segment_maker = armilla.ArmillaSegmentMaker( desired_duration_in_seconds=30 / 2, discard_final_silence=True, name='Wellogy', repeat=True, tempo=indicatortools.Tempo((1, 4), 108), ) ### MUSIC SPECIFIERS ### lh_glissandi = new( armilla.materials.left_hand_glissandi_music_specifier, attachment_handler__bend_after=consort.AttachmentExpression( attachments=indicatortools.BendAfter(4), selector=selectortools.Selector().by_leaf()[-1], ), pitch_handler__pitch_specifier="fs' gs' as'", rhythm_maker=rhythmmakertools.NoteRhythmMaker( duration_spelling_specifier=rhythmmakertools.DurationSpellingSpecifier( forbid_meter_rewriting=True, ),