Skip to content

Commit

Permalink
Implement pitch.getEnharmonic().
Browse files Browse the repository at this point in the history
  • Loading branch information
gregchapman-dev committed Mar 10, 2024
1 parent 1fa6524 commit 3057b1c
Showing 1 changed file with 42 additions and 1 deletion.
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

0 comments on commit 3057b1c

Please sign in to comment.