Skip to content

Commit

Permalink
Merge pull request #183 from cuthbertLab/cautionary-accidental-in-chord
Browse files Browse the repository at this point in the history
Make cautionaryPitchClass=True work with chords
  • Loading branch information
vanderstel authored May 10, 2022
2 parents a578831 + 3b75e96 commit 7b59588
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
4 changes: 3 additions & 1 deletion src/pitch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -894,7 +894,9 @@ export class Pitch extends prebase.ProtoM21Object {
this.accidental = new Accidental('natural');
}
this.accidental.displayStatus = true;

// not exactly equivalent with https://github.com/cuthbertLab/music21/pull/1299
// because m21j does not track chordAttached
// Thus, some potential for subsequent same pitch class to lack a cautionary natural
// other cases: already natural in past usage, do not need
// natural again (and not in key sig)
} else {
Expand Down
8 changes: 4 additions & 4 deletions src/stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { Music21Exception } from './exceptions21';
import { debug } from './debug';

import * as base from './base';
import { Chord } from './chord';
import * as clef from './clef';
import * as common from './common';
import * as derivation from './derivation';
Expand All @@ -47,7 +48,6 @@ import * as iterator from './stream/iterator';
import * as makeNotation from './stream/makeNotation';

// for typing only
import type { Chord } from './chord';
import type { KeySignature } from './key';

export { filters };
Expand Down Expand Up @@ -1815,9 +1815,10 @@ export class Stream extends base.Music21Object {
if (tie !== undefined && tie.type !== 'stop') {
tiePitchSet.add(p.nameWithOctave);
}
} else if (e.classes.includes('Chord')) {
const chordNotes = (e as Chord).notes;
} else if (e instanceof Chord) {
const chordNotes = e.notes;
const seenPitchNames: Set<string> = new Set();
pitchPast.push(...e.pitches);
for (const n of chordNotes) {
const p = n.pitch;
const lastNoteWasTied: boolean = tiePitchSet.has(p.nameWithOctave);
Expand All @@ -1841,7 +1842,6 @@ export class Stream extends base.Music21Object {
for (const pName of seenPitchNames) {
tiePitchSet.add(pName);
}
pitchPast.push(...(e as Chord).pitches);
} else {
tiePitchSet.clear();
}
Expand Down
8 changes: 8 additions & 0 deletions tests/moduleTests/stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,14 @@ export default function tests() {
assert.ok(n2.pitch.accidental.displayStatus); // different note
});

test('music21.stream.Stream makeAccidentals augmented unison in chord', assert => {
const m = new music21.stream.Measure();
const c = new music21.chord.Chord('G# G');
m.append(c);
m.makeAccidentals({inPlace: true});
assert.ok(c.pitches[0].accidental.displayStatus); // G comes first
});

test('music21.stream.Stream makeBeams with stemDirection', assert => {
const n1 = new music21.note.Note('C5', 0.5);
n1.stemDirection = 'up';
Expand Down

0 comments on commit 7b59588

Please sign in to comment.