Skip to content

Commit

Permalink
Migrated respell_with_flats(), sharps() from MutationAgent to NamedPi…
Browse files Browse the repository at this point in the history
…tch.
  • Loading branch information
trevorbaca committed Jul 31, 2017
1 parent 8b45e40 commit 599f47b
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 238 deletions.
108 changes: 0 additions & 108 deletions abjad/tools/agenttools/MutationAgent.py
Original file line number Diff line number Diff line change
Expand Up @@ -598,114 +598,6 @@ def replace_measure_contents(self, new_contents):
# return iterated measures
return result

def respell_with_flats(self):
r'''Respells named pitches in mutation client with flats.
.. todo:: Move to pitchtools package.
.. container:: example
Respells notes in staff:
::
>>> staff = Staff("c'8 cs'8 d'8 ef'8 e'8 f'8")
>>> show(staff) # doctest: +SKIP
.. docs::
>>> f(staff)
\new Staff {
c'8
cs'8
d'8
ef'8
e'8
f'8
}
::
>>> mutate(staff).respell_with_flats()
>>> show(staff) # doctest: +SKIP
.. docs::
>>> f(staff)
\new Staff {
c'8
df'8
d'8
ef'8
e'8
f'8
}
Returns none.
'''
from abjad.tools import scoretools
for leaf in iterate(self._client).by_leaf():
if isinstance(leaf, scoretools.Note):
leaf.written_pitch = leaf.written_pitch.respell_with_flats()
elif isinstance(leaf, scoretools.Chord):
for note_head in leaf.note_heads:
pitch = note_head.written_pitch.respell_with_flats()
note_head.written_pitch = pitch

def respell_with_sharps(self):
r'''Respells named pitches in mutation client with sharps.
.. todo:: Move to pitchtools package.
.. container:: example
Respells notes in staff:
::
>>> staff = Staff("c'8 cs'8 d'8 ef'8 e'8 f'8")
>>> show(staff) # doctest: +SKIP
.. docs::
>>> f(staff)
\new Staff {
c'8
cs'8
d'8
ef'8
e'8
f'8
}
::
>>> mutate(staff).respell_with_sharps()
>>> show(staff) # doctest: +SKIP
.. docs::
>>> f(staff)
\new Staff {
c'8
cs'8
d'8
ds'8
e'8
f'8
}
Returns none.
'''
from abjad.tools import scoretools
for leaf in iterate(self._client).by_leaf():
if isinstance(leaf, scoretools.Note):
leaf.written_pitch = leaf.written_pitch.respell_with_sharps()
elif isinstance(leaf, scoretools.Chord):
for note_head in leaf.note_heads:
pitch = note_head.written_pitch.respell_with_sharps()
note_head.written_pitch = pitch

def rewrite_meter(
self,
meter,
Expand Down

This file was deleted.

This file was deleted.

134 changes: 98 additions & 36 deletions abjad/tools/pitchtools/NamedPitch.py
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,26 @@ def _list_format_contributions(self):
contributions.append(override_string)
return contributions

def _respell_with_flats(self):
from abjad.tools import pitchtools
class_ = pitchtools.PitchClass
octave = pitchtools.Octave.from_pitch_number(
self.numbered_pitch.pitch_number)
name = class_._pitch_class_number_to_pitch_class_name_with_flats[
self.pitch_class_number]
pitch = type(self)(name, octave.number)
return pitch

def _respell_with_sharps(self):
from abjad.tools import pitchtools
class_ = pitchtools.PitchClass
octave = pitchtools.Octave.from_pitch_number(
self.numbered_pitch.pitch_number)
name = class_._pitch_class_number_to_pitch_class_name_with_sharps[
self.pitch_class_number]
pitch = type(self)(name, octave.number)
return pitch

@staticmethod
def _spell_pitch_number(pitch_number, diatonic_pitch_class_name):
from abjad.tools import pitchtools
Expand Down Expand Up @@ -1718,69 +1738,111 @@ def multiply(self, n=1):
octave_floor = (self.octave.number - 4) * 12
return type(self)(pitch_class_number + octave_floor)

def respell_with_flats(self):
r'''Respells named pitch with flats.
@staticmethod
def respell_with_flats(selection):
r'''Respells named pitches in `selection` with flats.
.. container:: example
Respells C#5 with flats:
Respells notes in staff:
::
>>> NamedPitch("cs''").respell_with_flats()
NamedPitch("df''")
>>> staff = Staff("c'8 cs'8 d'8 ef'8 e'8 f'8")
>>> show(staff) # doctest: +SKIP
.. container:: example
.. docs::
Respells Db5 with flats:
>>> f(staff)
\new Staff {
c'8
cs'8
d'8
ef'8
e'8
f'8
}
::
>>> NamedPitch("df''").respell_with_flats()
NamedPitch("df''")
>>> NamedPitch.respell_with_flats(staff)
>>> show(staff) # doctest: +SKIP
Returns new named pitch.
.. docs::
>>> f(staff)
\new Staff {
c'8
df'8
d'8
ef'8
e'8
f'8
}
Returns none.
'''
from abjad.tools import pitchtools
class_ = pitchtools.PitchClass
octave = pitchtools.Octave.from_pitch_number(
self.numbered_pitch.pitch_number)
name = class_._pitch_class_number_to_pitch_class_name_with_flats[
self.pitch_class_number]
pitch = type(self)(name, octave.number)
return pitch
import abjad
for leaf in abjad.iterate(selection).by_leaf():
if isinstance(leaf, abjad.Note):
leaf.written_pitch = leaf.written_pitch._respell_with_flats()
elif isinstance(leaf, abjad.Chord):
for note_head in leaf.note_heads:
pitch = note_head.written_pitch._respell_with_flats()
note_head.written_pitch = pitch

def respell_with_sharps(self):
r'''Respells named pitch with sharps.
@staticmethod
def respell_with_sharps(selection):
r'''Respells named pitches in selection with sharps.
.. container:: example
Respells Db5 with sharps:
Respells notes in staff:
::
>>> NamedPitch("df''").respell_with_sharps()
NamedPitch("cs''")
>>> staff = Staff("c'8 cs'8 d'8 ef'8 e'8 f'8")
>>> show(staff) # doctest: +SKIP
.. container:: example
.. docs::
Respells C#5 with sharps:
>>> f(staff)
\new Staff {
c'8
cs'8
d'8
ef'8
e'8
f'8
}
::
>>> NamedPitch("cs''").respell_with_sharps()
NamedPitch("cs''")
>>> NamedPitch.respell_with_sharps(staff)
>>> show(staff) # doctest: +SKIP
Returns new named pitch.
.. docs::
>>> f(staff)
\new Staff {
c'8
cs'8
d'8
ds'8
e'8
f'8
}
Returns none.
'''
from abjad.tools import pitchtools
class_ = pitchtools.PitchClass
octave = pitchtools.Octave.from_pitch_number(
self.numbered_pitch.pitch_number)
name = class_._pitch_class_number_to_pitch_class_name_with_sharps[
self.pitch_class_number]
pitch = type(self)(name, octave.number)
return pitch
import abjad
for leaf in abjad.iterate(selection).by_leaf():
if isinstance(leaf, abjad.Note):
leaf.written_pitch = leaf.written_pitch._respell_with_sharps()
elif isinstance(leaf, abjad.Chord):
for note_head in leaf.note_heads:
pitch = note_head.written_pitch._respell_with_sharps()
note_head.written_pitch = pitch

def to_staff_position(self, clef=None):
r'''Changes named pitch to staff position with optional `clef`.
Expand Down

0 comments on commit 599f47b

Please sign in to comment.