transpose_pitch_number_by_octave_transposition_mapping¶

pitchtools.
transpose_pitch_number_by_octave_transposition_mapping
(pitch_number, mapping)¶ Transposes pitch_number by the some number of octaves up or down. Derive correct number of octaves from mapping where mapping is a list of
(range_spec, octave)
pairs andrange_spec
is, in turn, a(start, stop)
pair suitable to pass to the builtin Pythonrange()
function:>>> mapping = [((39, 13), 0), ((12, 23), 12), ((24, 48), 24)]
The mapping given here comprises three
(range_spec, octave)
pairs. The first such pair is((39, 13), 0)
and can be read as follows: “any pitches between39
and13
should be transposed into the octave rooted at pitch0
.” The octave rooted at pitch0
equals the twelve pitchesrange(0, 0 + 12)
or[0, 1, ..., 10, 11]
.The second
(range_spec, octave)
pair is((12, 23), 12)
and can be read as “any pitches between12
and23
should be transposed into the octave rooted at pitch12
,” with the octave rooted at pitch12
equal to the twelve pitchesrange(12, 12 + 12)
or[12, 13, ..., 22, 23]
.The third and last
(range_spec, octave)
pair is((24, 48), 24)
and can be read as “any pitches between24
and48
should be transposed to the octave rooted at24
,” with the octave rooted at24
equal to the twelve pitchesrange(24, 24, + 12)
or[24, 25, ..., 34, 35]
.The mapping given here divides the compass of the piano, from
39
to48
, into three disjunct subranges and then explains how to transpose pitches found in any of those three disjunct subranges. This means that, for example, all the fsharps within the range of the piano now undergo a known transposition under mapping as defined here:>>> pitchtools.transpose_pitch_number_by_octave_transposition_mapping( ... 30, mapping) 6
We verify that pitch
30
should map to pitch6
by noticing that pitch30
falls in the first of the three subranges defined by mapping from39
to13
and then noting that mapping sends pitches with that subrange to the octave rooted at pitch0
. The octave transposition of30
that falls within the octave rooted at0
is6
:>>> pitchtools.transpose_pitch_number_by_octave_transposition_mapping( ... 18, mapping) 6
Likewise, mapping sends pitch
18
to pitch6
because pitch18
falls in the same subrange from39
to13
as did pitch39
and so undergoes the same transposition to the octave rooted at0
.In this way we can map all fsharps from
39
to48
according to mapping:>>> pitch_numbers = [30, 18, 6, 6, 18, 30, 42] >>> for n in pitch_numbers: ... n, pitchtools.transpose_pitch_number_by_octave_transposition_mapping( ... n, mapping) ... (30, 6) (18, 6) (6, 18) (6, 18) (18, 18) (30, 30) (42, 30)
And so on.
Returns pitch number.