alterFor method

double alterFor(
  1. String step
)

The chromatic alteration this key applies to the diatonic step, as a Pitch.alter value: 1.0 for a sharp, -1.0 for a flat, 0.0 for a step the key leaves alone.

This exists because of a trap that caught this package's own flagship example. Pitch.alter is the SOUNDING alteration (ADR-003) and defaults to 0.0, so Pitch(step: 'F', octave: 5) is an F NATURAL — even under a two-sharp key signature. Writing a piece in D major therefore means spelling alter: 1.0 on every F and every C, and forgetting to is not a rendering bug: the engraver correctly prints a natural on each one to cancel the key, which is exactly what the model asked for.

complete_music_piece.dart did forget, and printed a natural in front of nearly every F in a D-major piece. Nothing was wrong with the resolver — measured, it hides the accidental on the first F when the pitch really is F sharp, and cancels correctly when it is not.

So write it this way instead:

const key = KeySignature(2); // D major
Pitch(step: 'F', octave: 5, alter: key.alterFor('F')); // F sharp

Implementation

double alterFor(String step) =>
    AccidentalResolver.keyAlterForStep(step, count).toDouble();