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

Voice cross stave support in System #1434

Merged
merged 3 commits into from
Oct 16, 2022
Merged
Changes from 1 commit
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
Prev Previous commit
minimal crossbeam support
  • Loading branch information
rvilarl committed Sep 27, 2022
commit 95370b3dc8106008ffa0fa11582b62576c8d3662
30 changes: 18 additions & 12 deletions src/beam.ts
Original file line number Diff line number Diff line change
Expand Up @@ -469,15 +469,7 @@ export class Beam extends Element {
let i; // shared iterator
let note;

this.stem_direction = Stem.UP;

for (i = 0; i < notes.length; ++i) {
note = notes[i];
if (note.hasStem()) {
this.stem_direction = note.getStemDirection();
break;
}
}
this.stem_direction = notes[0].getStemDirection();

let stem_direction = this.stem_direction;
// Figure out optimal stem direction based on given notes
Expand Down Expand Up @@ -718,7 +710,6 @@ export class Beam extends Element {
notes,
slope,
y_shift,
stem_direction,
beam_count,
render_options: { show_stemlets, stemlet_extension, beam_width },
} = this;
Expand All @@ -735,9 +726,24 @@ export class Beam extends Element {
const { topY: stemTipY } = note.getStemExtents();
const beamedStemTipY = this.getSlopeY(stemX, firstStemX, firstStemTipY, slope) + y_shift;
const preBeamExtension = stem.getExtension();
const beamExtension = stem_direction === Stem.UP ? stemTipY - beamedStemTipY : beamedStemTipY - stemTipY;
const beamExtension =
note.getStemDirection() === Stem.UP ? stemTipY - beamedStemTipY : beamedStemTipY - stemTipY;
// Determine necessary extension for cross-stave notes in the beam group
let crossStemExtension = 0;
if (note.getStemDirection() !== this.stem_direction) {
const beamCount = note.getGlyph().beam_count;
crossStemExtension = (1 + (beamCount - 1) * 1.5) * this.render_options.beam_width;

/* This will be required if the partial beams are moved to the note side.
if (i > 0 && note.getGlyph().beam_count > 1) {
const prevBeamCount = this.notes[i - 1].getGlyph().beam_count;
const beamDiff = Math.abs(prevBeamCount - beamCount);
if (beamDiff > 0) crossStemExtension -= beamDiff * (this.render_options.beam_width * 1.5);
}
*/
}

stem.setExtension(preBeamExtension + beamExtension);
stem.setExtension(preBeamExtension + beamExtension + crossStemExtension);
stem.adjustHeightForBeam();

if (note.isRest() && show_stemlets) {
Expand Down