Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove duplicate chords #1216

Merged
merged 5 commits into from
Aug 5, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
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
16 changes: 14 additions & 2 deletions src/model/Chord.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Staff } from '@src/model/Staff';

// TODO: rework model to specify for each finger
// on which frets they are placed.
// TODO: rework model to specify for each finger
// on which frets they are placed.

/**
* A chord definition.
Expand Down Expand Up @@ -51,4 +51,16 @@ export class Chord {
* Gets or sets whether the fingering is shown below the chord diagram.
*/
public showFingering: boolean = true;
/**
* Gets a unique id for this chord based on its properties.
*/
public get uniqueId(): string {
const properties = [
this.name,
this.firstFret,
JSON.stringify(this.strings),
JSON.stringify(this.barreFrets)
];
return properties.join('|');
}
}
10 changes: 5 additions & 5 deletions src/rendering/layout/ScoreLayout.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { StaveProfile } from '@src/StaveProfile';
import { Environment } from '@src/Environment';
import { Bar } from '@src/model/Bar';
import { Chord } from '@src/model/Chord';
import { Font, FontStyle, FontWeight } from '@src/model/Font';
import { Score } from '@src/model/Score';
import { Staff } from '@src/model/Staff';
Expand Down Expand Up @@ -209,15 +208,16 @@ export abstract class ScoreLayout {
if (notation.isNotationElementVisible(NotationElement.ChordDiagrams)) {
this.chordDiagrams = new ChordDiagramContainerGlyph(0, 0);
this.chordDiagrams.renderer = fakeBarRenderer;
let chords: Map<string, Chord> = new Map<string, Chord>();
let chordIds: Set<string> = new Set<string>();

for (let track of this.renderer.tracks!) {
for (let staff of track.staves) {
const sc = staff.chords;
if (sc) {
for (const [chordId, chord] of sc) {
if (!chords.has(chordId)) {
for (const [, chord] of sc) {
if (!chordIds.has(chord.uniqueId)) {
if (chord.showDiagram) {
chords.set(chordId, chord);
chordIds.add(chord.uniqueId);
this.chordDiagrams!.addChord(chord);
}
}
Expand Down