sightPlan function

SightPlan sightPlan(
  1. SightRecipe recipe,
  2. Random rng, {
  3. bool? minor,
  4. SightForm? form,
})

A forma e os tons do exercício, pela receita. Com mod no vocabulário, as formas modulam; senão ficam no tom. minor e form forçam o modo e a forma (nos testes e quando o tom já foi sorteado).

Implementation

SightPlan sightPlan(
  SightRecipe recipe,
  Random rng, {
  bool? minor,
  SightForm? form,
}) {
  final isMinor =
      minor ?? (recipe.minorShare > 0 && rng.nextDouble() < recipe.minorShare);
  final home = SightLocalKey.home(minor: isMinor);
  final meter = recipe.meters[rng.nextInt(recipe.meters.length)];
  final modulates = recipe.harmony.contains('mod');
  final toRelative =
      modulates &&
      !home.minor &&
      recipe.harmony.contains('modRel') &&
      rng.nextBool();
  // A modulação enarmônica: o tom novo é remoto (a mediante cromática ou o
  // ♭II), ligado pela diminuta ou pela sexta alemã (`_phraseSlots`).
  final remote = modulates && recipe.harmony.contains('enharmonic')
      ? sightRemoteKeys(home)[rng.nextInt(3)]
      : null;
  final target = remote?.key ?? _modulationKey(home, toRelative);
  final other = modulates ? target : home;

  final chosen =
      form ??
      _formOf(recipe, rng, modulates: modulates, remote: remote != null);

  final phrases = switch (chosen) {
    SightForm.phrase => [_whole(SightPhraseKind.phrase, 4, home)],
    SightForm.period => [_antecedent(home), _consequent(home, home, 0)],
    SightForm.sentence => [_whole(SightPhraseKind.sentence, 8, home)],
    SightForm.modulatingPeriod => [
      _antecedent(home),
      _consequent(home, target, 0),
    ],
    SightForm.binary => _binaryPhrases(recipe, rng, home, other),
    SightForm.ternary => _ternaryPhrases(
      recipe,
      rng,
      home,
      modulates: modulates,
    ),
  };
  return SightPlan(form: chosen, phrases: phrases, home: home, meter: meter);
}