Skip to content

Commit

Permalink
feat(Chords): Elongate measures for chords (merge PR #928)
Browse files Browse the repository at this point in the history
code mostly by @hartman42

* Add Test file for chord spacing

* update my chord test with a multirest

* fixed halfdim chords with the extra flat 5's

* Elongate measure for chords

* align chords to the bottom left

* Refactor width calculations for lyrics and chords.

* update demo files

* Add rule for chord overlap into next measure

* format changes based on existing code conventions

* pr #928 review: requested changes (chord spacing) - sschmidTU

Co-authored-by: sschmid <s.schmid@phonicscore.com>
  • Loading branch information
hartman42 and sschmid committed Jan 22, 2021
1 parent 87e3523 commit ba3ae42
Show file tree
Hide file tree
Showing 11 changed files with 2,508 additions and 135 deletions.
3 changes: 3 additions & 0 deletions demo/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ import * as svg2pdf from '../node_modules/svg2pdf.js/dist/svg2pdf.min';
"OSMD Function Test - Auto-/Custom-Coloring": "OSMD_function_test_auto-custom-coloring-entchen.musicxml",
"OSMD Function Test - Bar lines": "OSMD_function_test_bar_lines.musicxml",
"OSMD Function Test - Chord Symbols": "OSMD_function_test_chord_symbols.musicxml",
"OSMD Function Test - Chord Spacing Test": "ChordSpacingTest.musicxml",
"OSMD Function Test - Chord Symbols - sus4 test": "sus4_test.musicxml",
"OSMD Function Test - Chord Symbols - Cmmaj9 test": "Cmmaj9_test.xml",
"OSMD Function Test - Color (from XML)": "OSMD_function_test_color.musicxml",
"OSMD Function Test - Container height (compacttight mode)": "OSMD_Function_Test_Container_height.musicxml",
"OSMD Function Test - Drumset": "OSMD_function_test_drumset.musicxml",
Expand Down
2 changes: 2 additions & 0 deletions src/MusicalScore/Graphical/EngravingRules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ export class EngravingRules {
public OrnamentAccidentalScalingFactor: number;
public ChordSymbolTextHeight: number;
public ChordSymbolXSpacing: number;
public ChordOverlapAllowedIntoNextMeasure: number;
public ChordSymbolYOffset: number;
public ChordSymbolLabelTexts: Dictionary<ChordSymbolEnum, string>;
public RepetitionSymbolsYOffset: number;
Expand Down Expand Up @@ -389,6 +390,7 @@ export class EngravingRules {
this.OrnamentAccidentalScalingFactor = 0.65;
this.ChordSymbolTextHeight = 2.0;
this.ChordSymbolXSpacing = 1.0;
this.ChordOverlapAllowedIntoNextMeasure = 0;
this.ChordSymbolYOffset = 2.0;
this.ChordSymbolLabelTexts = new Dictionary<ChordSymbolEnum, string>();
this.resetChordSymbolLabelTexts(this.ChordSymbolLabelTexts);
Expand Down
6 changes: 3 additions & 3 deletions src/MusicalScore/Graphical/GraphicalChordSymbolContainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ export class GraphicalChordSymbolContainer extends GraphicalObject {
public get GetChordSymbolContainer(): ChordSymbolContainer {
return this.chordSymbolContainer;
}
public get GetGraphicalLabel(): GraphicalLabel {
public get GraphicalLabel(): GraphicalLabel {
return this.graphicalLabel;
}
private calculateLabel(textHeight: number, transposeHalftones: number, keyInstruction: KeyInstruction): void {
const text: string = ChordSymbolContainer.calculateChordText(this.chordSymbolContainer, transposeHalftones, keyInstruction);
this.graphicalLabel = new GraphicalLabel(new Label(text), textHeight, TextAlignmentEnum.CenterBottom, this.rules, this.boundingBox);
this.graphicalLabel.PositionAndShape.RelativePosition = new PointF2D(0.0, 0.0);
this.graphicalLabel = new GraphicalLabel(new Label(text), textHeight, TextAlignmentEnum.LeftBottom, this.rules, this.boundingBox);
this.graphicalLabel.PositionAndShape.RelativePosition = new PointF2D(-1.0, 0.0);
}
}
6 changes: 3 additions & 3 deletions src/MusicalScore/Graphical/MusicSheetCalculator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,21 +298,21 @@ export abstract class MusicSheetCalculator {
/** list of vertically ordered measures belonging to one bar */
let measures: GraphicalMeasure[] = this.graphicalMusicSheet.MeasureList[0];
let minimumStaffEntriesWidth: number = this.calculateMeasureXLayout(measures);
minimumStaffEntriesWidth = this.calculateMeasureWidthFromLyrics(measures, minimumStaffEntriesWidth);
minimumStaffEntriesWidth = this.calculateMeasureWidthFromStaffEntries(measures, minimumStaffEntriesWidth);
MusicSheetCalculator.setMeasuresMinStaffEntriesWidth(measures, minimumStaffEntriesWidth);
// minLength = minimumStaffEntriesWidth * 1.2 + maxInstrNameLabelLength + maxInstructionsLength;
for (let i: number = 1; i < this.graphicalMusicSheet.MeasureList.length; i++) {
measures = this.graphicalMusicSheet.MeasureList[i];
minimumStaffEntriesWidth = this.calculateMeasureXLayout(measures);
minimumStaffEntriesWidth = this.calculateMeasureWidthFromLyrics(measures, minimumStaffEntriesWidth);
minimumStaffEntriesWidth = this.calculateMeasureWidthFromStaffEntries(measures, minimumStaffEntriesWidth);
MusicSheetCalculator.setMeasuresMinStaffEntriesWidth(measures, minimumStaffEntriesWidth);
// minLength = Math.max(minLength, minimumStaffEntriesWidth * 1.2 + maxInstructionsLength);
}
}
// this.graphicalMusicSheet.MinAllowedSystemWidth = minLength; // currently unused
}

public calculateMeasureWidthFromLyrics(measuresVertical: GraphicalMeasure[], oldMinimumStaffEntriesWidth: number): number {
public calculateMeasureWidthFromStaffEntries(measuresVertical: GraphicalMeasure[], oldMinimumStaffEntriesWidth: number): number {
throw new Error("abstract, not implemented");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ export class VexFlowGraphicalSymbolFactory implements IGraphicalSymbolFactory {
transposeHalftones,
graphicalStaffEntry.parentMeasure.parentSourceMeasure.Rules // TODO undefined sometimes
);
const graphicalLabel: GraphicalLabel = graphicalChordSymbolContainer.GetGraphicalLabel;
const graphicalLabel: GraphicalLabel = graphicalChordSymbolContainer.GraphicalLabel;
graphicalLabel.PositionAndShape.RelativePosition.y -= rules.ChordSymbolYOffset;
graphicalLabel.PositionAndShape.RelativePosition.x += xShift;
// TODO check for available space until next staffEntry or chord symbol (x direction)
Expand Down
Loading

0 comments on commit ba3ae42

Please sign in to comment.