From c034241087fdb2a87a7e2c43209d20789c276429 Mon Sep 17 00:00:00 2001 From: Jacob Walls Date: Mon, 9 May 2022 13:30:01 -0400 Subject: [PATCH 1/2] Make cautionaryPitchClass=True work with chords Partial port of https://github.com/cuthbertLab/music21/pull/1299 --- src/pitch.ts | 4 +++- src/stream.ts | 8 ++++---- tests/moduleTests/stream.ts | 9 +++++++++ 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/pitch.ts b/src/pitch.ts index 7fde8df5..8282049e 100644 --- a/src/pitch.ts +++ b/src/pitch.ts @@ -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 { diff --git a/src/stream.ts b/src/stream.ts index d994da65..c2f0bc0b 100644 --- a/src/stream.ts +++ b/src/stream.ts @@ -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'; @@ -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 }; @@ -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 = new Set(); + pitchPast.push(...e.pitches); for (const n of chordNotes) { const p = n.pitch; const lastNoteWasTied: boolean = tiePitchSet.has(p.nameWithOctave); @@ -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(); } diff --git a/tests/moduleTests/stream.ts b/tests/moduleTests/stream.ts index 05652d0b..5ffe87cb 100644 --- a/tests/moduleTests/stream.ts +++ b/tests/moduleTests/stream.ts @@ -554,6 +554,15 @@ 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); + assert.ok(c.pitches[1].accidental.displayStatus); + }); + test('music21.stream.Stream makeBeams with stemDirection', assert => { const n1 = new music21.note.Note('C5', 0.5); n1.stemDirection = 'up'; From 3b75e96c2d0b25e677f30ba9a0c195cb61aa9fb9 Mon Sep 17 00:00:00 2001 From: Jacob Walls Date: Mon, 9 May 2022 13:43:42 -0400 Subject: [PATCH 2/2] Avoid needless assertion on G# --- tests/moduleTests/stream.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/moduleTests/stream.ts b/tests/moduleTests/stream.ts index 5ffe87cb..ed455a4f 100644 --- a/tests/moduleTests/stream.ts +++ b/tests/moduleTests/stream.ts @@ -559,8 +559,7 @@ export default function tests() { const c = new music21.chord.Chord('G# G'); m.append(c); m.makeAccidentals({inPlace: true}); - assert.ok(c.pitches[0].accidental.displayStatus); - assert.ok(c.pitches[1].accidental.displayStatus); + assert.ok(c.pitches[0].accidental.displayStatus); // G comes first }); test('music21.stream.Stream makeBeams with stemDirection', assert => {