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

Honor measure width specifications #213

Open
jaredjj3 opened this issue Mar 5, 2024 · 3 comments
Open

Honor measure width specifications #213

jaredjj3 opened this issue Mar 5, 2024 · 3 comments

Comments

@jaredjj3
Copy link
Collaborator

jaredjj3 commented Mar 5, 2024

In #211 (comment), I realized that vexml is not honoring measure width specifications correctly.

  • Update the system generating procedure to use the measure specified width as a target width instead of a required width.
  • Account for <scaling> when calculating how many pixels a <measure> element's width is.

The data that can be used for testing is: Prelude_No._1_BWV_846_in_C_Major.zip

@jaredjj3
Copy link
Collaborator Author

jaredjj3 commented Mar 9, 2024

It sounds like this might be an issue in vexflow as described in vexflow/vexflow#13 (comment). I'm going to use this issue to refactor the rendering.Seed stave width calculations and honor the <scaling> specification.

@jaredjj3
Copy link
Collaborator Author

I'm putting this on ice for now. I tried applying <scaling>, but I realized that I need to scale all the symbols as well — not just the widths. I'll reassign myself when I revisit.

@jaredjj3
Copy link
Collaborator Author

musicxml/scaling.ts

import { NamedElement } from '@/util';

const DEFAULT_MILLIMETERS = 7;
const DEFAULT_TENTHS = 40;
const DEFAULT_MILLIMETERS_PER_TENTH = DEFAULT_MILLIMETERS / DEFAULT_TENTHS;

/**
 * Describes the scaling throughout the MusicXML document.
 *
 * See https://www.w3.org/2021/06/musicxml40/musicxml-reference/elements/scaling/
 */
export class Scaling {
  constructor(private element: NamedElement<'scaling'>) {}

  /** Returns the factor to adjust specified measurements by. */
  getScalingFactor(): number {
    const millimeters = this.getMillimeters();
    const tenths = this.getTenths();
    const millimetersPerTenth = millimeters / tenths;
    return millimetersPerTenth / DEFAULT_MILLIMETERS_PER_TENTH;
  }

  /** Returns the millimeters. */
  getMillimeters(): number {
    return this.element.first('millimeters')?.content().withDefault(DEFAULT_MILLIMETERS).float() ?? DEFAULT_MILLIMETERS;
  }

  /** Returns the tenths. */
  getTenths(): number {
    return this.element.first('tenths')?.content().withDefault(DEFAULT_TENTHS).float() ?? DEFAULT_TENTHS;
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant