예제 #1
0
def test_QEventSequence_from_tempo_scaled_durations_01():
    """
    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 = abjadext.nauert.QEventSequence.from_tempo_scaled_durations(
        durations, tempo
    )
    assert q_events == abjadext.nauert.QEventSequence(
        (
            abjadext.nauert.PitchedQEvent(
                abjad.Offset(0, 1), (abjad.NamedPitch("c'"),)
            ),
            abjadext.nauert.PitchedQEvent(
                abjad.Offset(12000, 11), (abjad.NamedPitch("c'"),)
            ),
            abjadext.nauert.PitchedQEvent(
                abjad.Offset(28000, 11), (abjad.NamedPitch("c'"),)
            ),
            abjadext.nauert.PitchedQEvent(
                abjad.Offset(244000, 77), (abjad.NamedPitch("c'"),)
            ),
            abjadext.nauert.PitchedQEvent(
                abjad.Offset(34400, 7), (abjad.NamedPitch("c'"),)
            ),
            abjadext.nauert.TerminalQEvent(abjad.Offset(630400, 77)),
        )
    )
def test_QEventSequence_from_millisecond_pitch_attachment_tuples_01():
    durations = [100, 200, 100, 300, 350, 400, 600]
    pitches = [0, None, None, [1, 4], None, 5, 7]
    attachments = [("foo",), None, None, (6,), None, ("foobar",), ("foo", "bar")]
    tuples = tuple(zip(durations, pitches, attachments))
    q_events = nauert.QEventSequence.from_millisecond_pitch_attachment_tuples(tuples)
    assert q_events == nauert.QEventSequence(
        (
            nauert.PitchedQEvent(abjad.Offset(0), (abjad.NamedPitch("c'"),), ("foo",)),
            nauert.SilentQEvent(abjad.Offset(100, 1)),
            nauert.PitchedQEvent(
                abjad.Offset(400, 1),
                (abjad.NamedPitch("cs'"), abjad.NamedPitch("e'")),
                (6,),
            ),
            nauert.SilentQEvent(abjad.Offset(700, 1)),
            nauert.PitchedQEvent(
                abjad.Offset(1050, 1), (abjad.NamedPitch("f'"),), ("foobar",)
            ),
            nauert.PitchedQEvent(
                abjad.Offset(1450, 1), (abjad.NamedPitch("g'"),), ("foo", "bar")
            ),
            nauert.TerminalQEvent(abjad.Offset(2050, 1)),
        )
    ), repr(q_events)
예제 #3
0
    def __sub__(self, argument):
        """
        Subtracts `argument` from named pitch-class.

        ..  container:: example

            >>> abjad.NamedPitchClass('cs') - abjad.NamedPitchClass('g')
            NamedInversionEquivalentIntervalClass('+A4')

            >>> abjad.NamedPitchClass('c') - abjad.NamedPitchClass('cf')
            NamedInversionEquivalentIntervalClass('+A1')

            >>> abjad.NamedPitchClass('cf') - abjad.NamedPitchClass('c')
            NamedInversionEquivalentIntervalClass('+A1')

        Returns named inversion-equivalent interval-class.
        """
        import abjad
        if not isinstance(argument, type(self)):
            message = 'must be named pitch-class: {!r}.'
            message = message.format(argument)
            raise TypeError(message)
        pitch_1 = abjad.NamedPitch((self.name, 4))
        pitch_2 = abjad.NamedPitch((argument.name, 4))
        mdi = abjad.NamedInterval.from_pitch_carriers(pitch_1, pitch_2)
        pair = (mdi.quality, mdi.number)
        dic = abjad.NamedInversionEquivalentIntervalClass(pair)
        return dic
예제 #4
0
def test_QEventSequence_from_tempo_scaled_durations_02():
    """
    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 = abjadext.nauert.QEventSequence.from_tempo_scaled_durations(
        durations, tempo
    )
    assert q_events == abjadext.nauert.QEventSequence(
        (
            abjadext.nauert.PitchedQEvent(
                abjad.Offset(0, 1), (abjad.NamedPitch("c'"),)
            ),
            abjadext.nauert.SilentQEvent(abjad.Offset(60000, 77)),
            abjadext.nauert.PitchedQEvent(
                abjad.Offset(120000, 77), (abjad.NamedPitch("c'"),)
            ),
            abjadext.nauert.PitchedQEvent(
                abjad.Offset(180000, 77), (abjad.NamedPitch("c'"),)
            ),
            abjadext.nauert.SilentQEvent(abjad.Offset(240000, 77)),
            abjadext.nauert.PitchedQEvent(
                abjad.Offset(360000, 77), (abjad.NamedPitch("c'"),)
            ),
            abjadext.nauert.TerminalQEvent(abjad.Offset(60000, 11)),
        )
    )
예제 #5
0
파일: Scale.py 프로젝트: tchiwinpiti/abjad
    def voice_scale_degrees_in_open_position(self, scale_degrees):
        r'''Voices `scale_degrees` in open position.

        ..  container:: example

            >>> scale = abjad.tonalanalysistools.Scale(('c', 'major'))
            >>> scale_degrees = [1, 3, 'b5', 7, '#9']
            >>> segment = scale.voice_scale_degrees_in_open_position(
            ...     scale_degrees)
            >>> segment
            PitchSegment("c' e' gf' b' ds''")

        Return pitch segment.
        '''
        import abjad
        from abjad.tools import tonalanalysistools
        scale_degrees = [
            tonalanalysistools.ScaleDegree(x) for x in scale_degrees
        ]
        pitch_classes = [
            self.scale_degree_to_named_pitch_class(x) for x in scale_degrees
        ]
        pitches = [abjad.NamedPitch(pitch_classes[0])]
        for pitch_class in pitch_classes[1:]:
            pitch = abjad.NamedPitch(pitch_class)
            while pitch < pitches[-1]:
                pitch += 12
            pitches.append(pitch)
        pitches = abjad.PitchSegment(pitches)
        return pitches
예제 #6
0
 def _contains_pitch(self, pitch):
     import abjad
     if isinstance(pitch, numbers.Number):
         pitch = abjad.NamedPitch(pitch)
     elif isinstance(pitch, str):
         pitch = abjad.NamedPitch(pitch)
     if self.start_pitch is None and self.stop_pitch is None:
         return True
     elif self.start_pitch is None:
         if self.stop_pitch_is_included_in_range:
             return pitch <= self.stop_pitch
         else:
             return pitch < self.stop_pitch
     elif self.stop_pitch is None:
         if self.start_pitch_is_included_in_range:
             return self.start_pitch <= pitch
         else:
             return self.start_pitch < pitch
     else:
         if self.start_pitch_is_included_in_range:
             if self.stop_pitch_is_included_in_range:
                 return self.start_pitch <= pitch <= self.stop_pitch
             else:
                 return self.start_pitch <= pitch < self.stop_pitch
         else:
             if self.stop_pitch_is_included_in_range:
                 return self.start_pitch < pitch <= self.stop_pitch
             else:
                 return self.start_pitch < pitch < self.stop_pitch
예제 #7
0
    def transpose(self, expr):
        r"""
        Transposes music specifier.

        ..  container:: example

            >>> music_specifier = tsmakers.MusicSpecifier()
            >>> transposed_music_specifier = music_specifier.transpose('-M2')
            >>> print(abjad.storage(transposed_music_specifier))
            tsmakers.MusicSpecifier()

        Returns new music specifier.
        """
        if isinstance(expr, str):
            try:
                pitch = abjad.NamedPitch(expr)
                expr = abjad.NamedPitch("C4") - pitch
            except Exception:
                expr = abjad.NamedInterval(expr)
        pitch_handler = self.pitch_handler
        if pitch_handler is not None:
            pitch_handler = pitch_handler.transpose(expr)
        return abjad.new(
            self,
            pitch_handler=pitch_handler,
        )
예제 #8
0
 def calc_anchor(self):
     durs = [self.leaf.written_duration, self.anchor_dur]
     container = abjad.Container()
     pre_mult = self.leaf.written_duration - self.anchor_dur
     mult = pre_mult / self.leaf.written_duration
     if isinstance(self.leaf, abjad.Chord):
         pitches = [
             abjad.NamedPitch(_) for _ in abjad.get.pitches(self.leaf)
         ]
     elif isinstance(self.leaf, abjad.Note):
         pitches = [
             abjad.NamedPitch(_) for _ in abjad.get.pitches(self.leaf)
         ]
         pitches = pitches[0]
     else:
         pass
     maker = abjad.LeafMaker()
     new_leaves = [list_ for list_ in maker([pitches], durs)]
     indicators = abjad.get.indicators(self.leaf)
     for indicator in indicators:
         abjad.attach(indicator, new_leaves[0][0])
     self.leaf.multiplier = mult
     abjad.attach(
         abjad.LilyPondLiteral(r"""\abjad-invisible-music""",
                               format_slot="before"),
         new_leaves[1],
     )
     abjad.annotate(new_leaves[1], "type", "spanner anchor")
     container.extend(new_leaves)
     return container
예제 #9
0
def test_NamedInterval_01(pitch_a, pitch_b, name):
    pitch_a = abjad.NamedPitch(pitch_a)
    pitch_b = abjad.NamedPitch(pitch_b)
    interval = abjad.NamedInterval.from_pitch_carriers(pitch_a, pitch_b)
    assert str(interval) == name
    assert pitch_a.transpose(interval) == pitch_b
    assert pitch_b.transpose(-interval) == pitch_a
예제 #10
0
    def __mul__(self, argument):
        """
        Multiplies named interval by `argument`.

        ..  container:: example

            >>> 3 * abjad.NamedInterval('+M9')
            NamedInterval('+A25')

        Returns new named interval.
        """
        import abjad

        if not isinstance(argument, int):
            message = "must be integer: {!r}."
            message = message.format(argument)
            raise TypeError(message)
        dummy_pitch = abjad.NamedPitch(0)
        for i in range(abs(argument)):
            dummy_pitch += self
        result = NamedInterval.from_pitch_carriers(abjad.NamedPitch(0),
                                                   dummy_pitch)
        if argument < 0:
            return -result
        return result
예제 #11
0
파일: Scale.py 프로젝트: tchiwinpiti/abjad
    def create_named_pitch_set_in_pitch_range(self, pitch_range):
        r'''Creates named pitch-set in `pitch_range`.

        Returns pitch-set.
        '''
        import abjad
        if not isinstance(pitch_range, abjad.PitchRange):
            pitch_range = abjad.PitchRange(
                float(abjad.NamedPitch(pitch_range[0])),
                float(abjad.NamedPitch(pitch_range[1])))
        low = pitch_range.start_pitch.octave.number
        high = pitch_range.stop_pitch.octave.number
        pitches = []
        octave = low
        while octave <= high:
            for x in self:
                pitch = abjad.NamedPitch((x.name, octave))
                if (pitch_range.start_pitch <= pitch
                        and pitch <= pitch_range.stop_pitch):
                    pitches.append(pitch)
            octave += 1
        return abjad.PitchSet(
            items=pitches,
            item_class=abjad.NamedPitch,
        )
예제 #12
0
def test_virtual_fundamental_08():
    pitches = abjad.PitchSegment(r"c'' cs'' d'' ef'' e'' fs''")
    fundamental = auxjad.get.virtual_fundamental(
        pitches,
        min_fundamental=abjad.NamedPitch(r"c,,,"),
    )
    assert fundamental == abjad.NamedPitch(r"d,,")
예제 #13
0
 def __init__(self, *args, **kwargs):
     super().__init__(*args, **kwargs)
     if self.displace_fifths:
         self.pitch = abjad.NamedPitch(self.pitch).transpose(
             self.displace_fifths * 7)
     if self.displace_octaves:
         self.pitch = abjad.NamedPitch(self.pitch).transpose(
             self.displace_octaves * 12)
예제 #14
0
def test_init(input_, expected_semitones):
    if isinstance(expected_semitones, type) and issubclass(
            expected_semitones, Exception):
        with pytest.raises(expected_semitones):
            abjad.NamedPitch(input_)
        return
    instance = abjad.NamedPitch(input_)
    assert float(instance) == expected_semitones
예제 #15
0
def test_quantizationtools_PitchedQEvent___init___01():

    q_event = quantizationtools.PitchedQEvent(130, [0, 1, 4])

    assert q_event.offset == abjad.Offset(130)
    assert q_event.pitches == (abjad.NamedPitch(0), abjad.NamedPitch(1),
                               abjad.NamedPitch(4))
    assert q_event.attachments == ()
예제 #16
0
def test_PitchedQEvent___init___01():
    q_event = abjadext.nauert.PitchedQEvent(130, [0, 1, 4])
    assert q_event.offset == abjad.Offset(130)
    assert q_event.pitches == (
        abjad.NamedPitch(0),
        abjad.NamedPitch(1),
        abjad.NamedPitch(4),
    )
    assert q_event.attachments == ()
def test_scoretools_Chord___init___04():
    r'''Initialize chord with pitches.
    '''

    pitches = []
    pitches.append(abjad.NamedPitch('D#4'))
    pitches.append(abjad.NamedPitch('Eb4'))
    chord = abjad.Chord(pitches, (1, 4))
    assert format(chord) == "<ds' ef'>4"
def test_Chord_written_pitches_05():
    """
    Set written pitches with both pitches and pitch numbers.
    """

    chord = abjad.Chord([], (1, 4))
    chord.written_pitches = [4, abjad.NamedPitch(3), abjad.NamedPitch(2)]

    assert format(chord) == "<d' ef' e'>4"
예제 #19
0
def test_quantizationtools_PitchedQEvent___init___02():

    q_event = quantizationtools.PitchedQEvent(
        abjad.Offset(133, 5), [abjad.NamedPitch('fss')],
        attachments=['foo', 'bar', 'baz'])

    assert q_event.offset == abjad.Offset(133, 5)
    assert q_event.pitches == (abjad.NamedPitch('fss'), )
    assert q_event.attachments == ('foo', 'bar', 'baz')
예제 #20
0
def test_PitchedQEvent___init___02():
    q_event = abjadext.nauert.PitchedQEvent(
        abjad.Offset(133, 5),
        [abjad.NamedPitch("fss")],
        attachments=["foo", "bar", "baz"],
    )
    assert q_event.offset == abjad.Offset(133, 5)
    assert q_event.pitches == (abjad.NamedPitch("fss"), )
    assert q_event.attachments == ("foo", "bar", "baz")
def test_scoretools_NoteHeadList___contains___02():

    chord = abjad.Chord("<ef' cs'' f''>4")

    assert not 18 in chord.note_heads
    assert not 18.0 in chord.note_heads
    assert not abjad.NamedPitch(18) in chord.note_heads
    assert not abjad.NamedPitch("fs''") in chord.note_heads
    assert not abjad.NoteHead(18) in chord.note_heads
    assert not abjad.NoteHead("fs''") in chord.note_heads
예제 #22
0
    def find_pitches(self, abjad_pitch: abjad.NamedPitch) -> None:
        from mutools import lily

        basic_pitch = abjad.NamedPitch(
            lily.round_scale_index_to_12th_tone(
                float(abjad_pitch) - self.ground_interval))
        harmonic_pitch = abjad.NamedPitch(
            lily.round_scale_index_to_12th_tone(
                float(basic_pitch) + self.harmonic_interval))
        return abjad.PitchSegment([basic_pitch, harmonic_pitch])
def test_scoretools_NoteHeadList___contains___01():

    chord = abjad.Chord("<ef' cs'' f''>4")

    assert 17 in chord.note_heads
    assert 17.0 in chord.note_heads
    assert abjad.NamedPitch(17) in chord.note_heads
    assert abjad.NamedPitch("f''") in chord.note_heads
    assert chord.note_heads[1] in chord.note_heads
    assert abjad.NoteHead("f''") in chord.note_heads
예제 #24
0
def test_Chord___init___04():
    """
    Initialize chord with pitches.
    """

    pitches = []
    pitches.append(abjad.NamedPitch("D#4"))
    pitches.append(abjad.NamedPitch("Eb4"))
    chord = abjad.Chord(pitches, (1, 4))
    assert format(chord) == "<ds' ef'>4"
예제 #25
0
파일: mathx.py 프로젝트: jgarte/baca
def _get_intervals_in_subrun(subrun_source):
    subrun_source = list(subrun_source)
    result = [0]
    for first, second in abjad.Sequence(subrun_source).nwise():
        first_pitch = abjad.NamedPitch(first)
        second_pitch = abjad.NamedPitch(second)
        interval = (abjad.NumberedPitch(second_pitch).number -
                    abjad.NumberedPitch(first_pitch).number)
        result.append(interval + result[-1])
    result.pop(0)
    return result
예제 #26
0
 def _is_equivalent_under_transposition(self, argument):
     import abjad
     if not isinstance(argument, type(self)):
         return False
     if not len(self) == len(argument):
         return False
     difference = -(abjad.NamedPitch(argument[0], 4) -
                    abjad.NamedPitch(self[0], 4))
     new_pitches = (x + difference for x in self)
     new_pitches = abjad.new(self, items=new_pitches)
     return argument == new_pitches
예제 #27
0
    def assign_to_instruments(self, inst_names, inst_noten, round_=False):
        """Distribute analyzed pitches to different instruments.

        inst_noten: number of pitches assigned for each specified instrument
        (inst_names), for each chord analyzed.

        Save the result in a .json file.

        """
        # inst_names = ["Bass Clarinet", "Piano"]
        # inst_noten = [4, 1]
        result = {}
        save_dict = {}
        for name in inst_names:
            result[name] = []
            save_dict[name] = []

        for chord in self.container:
            chord_ = []
            str_chord = []
            chord_notes = iter(chord.written_pitches)
            if round_ is True:
                num_pitches = [abjad.NamedPitch(_).number for _ in chord_notes]
                # NO MICROTONAL
                for item, i in zip(num_pitches, range(len(num_pitches))):
                    if isinstance(item, float):
                        item = item - 0.5
                        num_pitches[i] = item
                num_pitches = iter(num_pitches)
                for name, number in zip(inst_names, inst_noten):
                    for n in range(number):
                        note = next(num_pitches)
                        chord_.append(note)
                        str_chord.append(abjad.NamedPitch(note).name)
                    result[name].append(chord_)
                    save_dict[name].append(str_chord)

            else:
                for name, number in zip(inst_names, inst_noten):
                    for n in range(number):
                        note = next(chord_notes)
                        chord_.append(note)
                        str_chord.append(note.name)
                    result[name].append(chord_)
                    save_dict[name].append(str_chord)

        file_str = ""
        for item in result:
            file_str = file_str + item + "_"
        file_str = file_str + "pitches.json"
        a_file = open(file_str, "w")
        json.dump(save_dict, a_file)
        print("Saved in", file_str)
        a_file.close()
예제 #28
0
def test_scoretools_NoteHead_written_pitch_04():
    r'''Set note-head pitch from another note or note-head.
    Make sure this does not cause reference problems.
    '''

    n1 = abjad.Note(12, (1, 4))
    n2 = abjad.Note(14, (1, 4))
    n1.written_pitch = n2.written_pitch

    assert n1.written_pitch == abjad.NamedPitch(14)
    assert n2.written_pitch == abjad.NamedPitch(14)
    assert n1.written_pitch is not n2.written_pitch
예제 #29
0
def test_scoretools_Chord_written_pitches_06():
    r'''Set written pitches with both pitches and pitch numbers.
    '''

    chord = abjad.Chord([], (1, 4))
    chord.written_pitches = [
        4,
        abjad.NamedPitch(3),
        abjad.NamedPitch(2),
    ]

    assert format(chord) == "<d' ef' e'>4"
def test_Chord_written_pitches_04():
    """
    Set written pitches with pitches.
    """

    chord = abjad.Chord([], (1, 4))
    chord.written_pitches = [
        abjad.NamedPitch(4),
        abjad.NamedPitch(3),
        abjad.NamedPitch(2),
    ]

    assert format(chord) == "<d' ef' e'>4"