Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 42 additions & 1 deletion src/pitch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,48 @@ export class Pitch extends prebase.ProtoM21Object {
getLowerEnharmonic(inPlace=false) {
return this._getEnharmonicHelper(inPlace, -1);
}
/* TODO: isEnharmonic, getEnharmonic, getAllCommonEnharmonics */

getEnharmonic(inPlace=false): Pitch|undefined {
let post = this;
if (!inPlace) {
post = this.clone();
}

if (post.accidental !== undefined) {
if (post.accidental.alter > 0) {
// we have a sharp, need to get the equivalent flat
post.getHigherEnharmonic(true);
}
else if (post.accidental.alter < 0) {
post.getLowerEnharmonic(true);
}
else {
// assume some direction, perhaps using a dictionary
if (this.step in ['C', 'D', 'G']) {
post.getLowerEnharmonic(true);
}
else {
post.getHigherEnharmonic(true);
}
}
}
else {
if (this.step in ['C', 'D', 'G']) {
post.getLowerEnharmonic(true);
}
else {
post.getHigherEnharmonic(true);
}
}

if (inPlace) {
return undefined;
}
else {
return post;
}
}
/* TODO: isEnharmonic, getAllCommonEnharmonics */

protected _nameInKeySignature(alteredPitches: Pitch[]) : boolean {
for (const p of alteredPitches) { // all are altered tones, must have acc
Expand Down