Skip to content

Commit

Permalink
Create staves in new Part
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredjj3 committed Dec 21, 2023
1 parent 46b9b48 commit fb82aef
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 11 deletions.
6 changes: 4 additions & 2 deletions src/rendering/measurefragment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,10 @@ export class MeasureFragment {
config: this.config,
staveSignature: this.leadingStaveSignature,
number: staveNumber,
beginningBarStyle: this.beginningBarStyle,
endBarStyle: this.endBarStyle,
musicXml: {
beginningBarStyle: this.beginningBarStyle,
endBarStyle: this.endBarStyle,
},
measureEntries: this.measureEntries.filter((entry) => {
if (entry instanceof musicxml.Note) {
return entry.getStaveNumber() === staveNumber;
Expand Down
1 change: 1 addition & 0 deletions src/rendering/measurefragment2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ export class MeasureFragment {
}

return new Part({
config: this.config,
id: partId,
musicXml: {
staveLayouts: this.musicXml.staveLayouts,
Expand Down
34 changes: 33 additions & 1 deletion src/rendering/part2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as util from '@/util';
import * as musicxml from '@/musicxml';
import { Stave, StaveRendering } from './stave';
import { MeasureEntry, StaveSignature } from './stavesignature';
import { Config } from './config';

/** The result of rendering a part. */
export type PartRendering = {
Expand All @@ -12,6 +13,7 @@ export type PartRendering = {

/** A part in a musical score. */
export class Part {
private config: Config;
private id: string;
private musicXml: {
staveLayouts: musicxml.StaveLayout[];
Expand All @@ -22,6 +24,7 @@ export class Part {
private staveSignature: StaveSignature;

constructor(opts: {
config: Config;
id: string;
musicXml: {
staveLayouts: musicxml.StaveLayout[];
Expand All @@ -31,6 +34,7 @@ export class Part {
measureEntries: MeasureEntry[];
staveSignature: StaveSignature;
}) {
this.config = opts.config;
this.id = opts.id;
this.musicXml = opts.musicXml;
this.measureEntries = opts.measureEntries;
Expand All @@ -48,6 +52,34 @@ export class Part {

@util.memoize()
private getStaves(): Stave[] {
return [];
const result = new Array<Stave>();

const staveCount = this.staveSignature.getStaveCount();

for (let staveIndex = 0; staveIndex < staveCount; staveIndex++) {
const staveNumber = staveIndex + 1;

const measureEntries = this.measureEntries.filter((entry) => {
if (entry instanceof musicxml.Note) {
return entry.getStaveNumber() === staveNumber;
}
return true;
});

result.push(
new Stave({
config: this.config,
staveSignature: this.staveSignature,
number: staveNumber,
musicXml: {
beginningBarStyle: this.musicXml.beginningBarStyle,
endBarStyle: this.musicXml.endBarStyle,
},
measureEntries,
})
);
}

return result;
}
}
19 changes: 11 additions & 8 deletions src/rendering/stave.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,24 +49,27 @@ export type StaveModifier = 'clef' | 'keySignature' | 'timeSignature';
export class Stave {
private config: Config;
private number: number;
private musicXml: {
beginningBarStyle: musicxml.BarStyle;
endBarStyle: musicxml.BarStyle;
};
private staveSignature: StaveSignature;
private beginningBarStyle: musicxml.BarStyle;
private endBarStyle: musicxml.BarStyle;
private measureEntries: MeasureEntry[];

constructor(opts: {
config: Config;
number: number;
staveSignature: StaveSignature;
beginningBarStyle: musicxml.BarStyle;
endBarStyle: musicxml.BarStyle;
musicXml: {
beginningBarStyle: musicxml.BarStyle;
endBarStyle: musicxml.BarStyle;
};
measureEntries: MeasureEntry[];
}) {
this.config = opts.config;
this.number = opts.number;
this.staveSignature = opts.staveSignature;
this.beginningBarStyle = opts.beginningBarStyle;
this.endBarStyle = opts.endBarStyle;
this.musicXml = opts.musicXml;
this.measureEntries = opts.measureEntries;
}

Expand Down Expand Up @@ -166,10 +169,10 @@ export class Stave {
? new vexflow.TabStave(opts.x, opts.y, opts.width)
: new vexflow.Stave(opts.x, opts.y, opts.width);

const vfBeginningBarlineType = conversions.fromBarStyleToBarlineType(this.beginningBarStyle);
const vfBeginningBarlineType = conversions.fromBarStyleToBarlineType(this.musicXml.beginningBarStyle);
vfStave.setBegBarType(vfBeginningBarlineType);

const vfEndBarlineType = conversions.fromBarStyleToBarlineType(this.endBarStyle);
const vfEndBarlineType = conversions.fromBarStyleToBarlineType(this.musicXml.endBarStyle);
vfStave.setEndBarType(vfEndBarlineType);

if (opts.modifiers.includes('clef')) {
Expand Down

0 comments on commit fb82aef

Please sign in to comment.