Skip to content

Commit

Permalink
Set reasonable defaults if the noteStruct does not provide clef, octa…
Browse files Browse the repository at this point in the history
…ve_shift, or stem_direction.

Improve formatting. Clean up code.
  • Loading branch information
ronyeh committed Jul 25, 2021
1 parent a3f8ebd commit 1e5e449
Show file tree
Hide file tree
Showing 4 changed files with 143 additions and 147 deletions.
8 changes: 3 additions & 5 deletions src/element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ export abstract class Element {
protected style?: ElementStyle;
private attrs: ElementAttributes;
protected boundingBox?: BoundingBox;
protected fontStack: Font[];
protected musicFont: Font;
protected fontStack!: Font[];
protected musicFont!: Font;
protected registry?: Registry;

protected static newID(): string {
Expand All @@ -58,9 +58,7 @@ export abstract class Element {
};

this.rendered = false;

this.fontStack = Flow.DEFAULT_FONT_STACK;
this.musicFont = Flow.DEFAULT_FONT_STACK[0];
this.setFontStack(Flow.DEFAULT_FONT_STACK);

// If a default registry exist, then register with it right away.
Registry.getDefaultRegistry()?.register(this);
Expand Down
10 changes: 5 additions & 5 deletions src/stavenote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -368,10 +368,10 @@ export class StaveNote extends StemmableNote {
constructor(noteStruct: StaveNoteStruct) {
super(noteStruct);
this.setAttribute('type', 'StaveNote');
// Ledger Lines default width 2.0
this.ledgerLineStyle = { lineWidth: 2.0 };
this.clef = noteStruct.clef;
this.octave_shift = noteStruct.octave_shift;

this.ledgerLineStyle = { lineWidth: 2.0 }; // Set default width of ledger lines to 2.0.
this.clef = noteStruct.clef ?? 'treble';
this.octave_shift = noteStruct.octave_shift ?? 0;

// Pull note rendering properties
this.glyph = Flow.getGlyphProps(this.duration, this.noteType);
Expand Down Expand Up @@ -410,7 +410,7 @@ export class StaveNote extends StemmableNote {
if (noteStruct.auto_stem) {
this.autoStem();
} else {
this.setStemDirection(noteStruct.stem_direction);
this.setStemDirection(noteStruct.stem_direction ?? Stem.UP);
}
this.reset();
this.buildFlag();
Expand Down
12 changes: 5 additions & 7 deletions src/tables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -374,12 +374,9 @@ export const Tables = {
The last argument, params, is a struct the currently can contain one option,
octave_shift for clef ottavation (0 = default; 1 = 8va; -1 = 8vb, etc.).
*/
keyProperties(
key: string,
clef?: string,
// eslint-disable-next-line
params?: any): any {
*/
// eslint-disable-next-line
keyProperties(key: string, clef?: string, params?: any): any {
const noteValues: Record<
string,
{
Expand Down Expand Up @@ -1365,7 +1362,8 @@ export const Tables = {
m: { name: 'muted' },
s: { name: 'slash' },
} as Record<string, Record<string, string>>,
// Some defaults

// Default time signature.
TIME4_4: {
num_beats: 4,
beat_value: 4,
Expand Down
Loading

0 comments on commit 1e5e449

Please sign in to comment.