Using music21, how can I transpose a pitch down an octave?
If I use p.transpose(-12)
, flats get changed to sharps:
import music21
p = music21.pitch.Pitch('D-4')
print(p.transpose(-12))
output
C#3
Using music21, how can I transpose a pitch down an octave?
If I use p.transpose(-12)
, flats get changed to sharps:
import music21
p = music21.pitch.Pitch('D-4')
print(p.transpose(-12))
output
C#3
Share
Improve this question
asked Feb 17 at 23:21
Jeff LearmanJeff Learman
3,3191 gold badge24 silver badges33 bronze badges
6
- For most practical purposes, C sharp and D flat are the same note. Probably the printed representation of the note is affected by the key signature. – kindall Commented Feb 17 at 23:29
- Try -8 instead of -12 – Starship Commented Feb 18 at 0:37
- @kindall -- a pitch doesn't have a key or key signature, and I couldn't find a way to transpose using a key or key signature (other than perhaps adding the note to a stream and transposing that, and then removing it from the stream and discarding it.) – Jeff Learman Commented 2 days ago
- @Starship -- when a number is used, it's interpreted as semitones. – Jeff Learman Commented 2 days ago
- 1 @JeffLearman I meant -P8 (which you also say is what worked for you) – Starship Commented 2 days ago
1 Answer
Reset to default 0Instead of -P12
, use -P8
, like this:
import music21
p = music21.pitch.Pitch('D-4')
print(p.transpose('-P8'))