handleEndBrace method

void handleEndBrace(
  1. ChantContext ctxt,
  2. ChantLayoutElement note,
  3. int i
)

Implementation

void handleEndBrace(ChantContext ctxt, ChantLayoutElement note, int i) {
  final startBrace = ctxt.lastStartBrace;
  if (startBrace == null) return;

  double y;
  final k = startBrace.notationIndex;
  final notations = score.notations;
  final dy = ctxt.intraNeumeSpacing / 2;
  final startNote = startBrace.note!;

  if (startBrace.isAbove) {
    y = math.min(
      ctxt.calculateHeightFromStaffPosition(score.staffLineCount * 2),
      [
        startNote,
        note,
        ...notations.sublist(k, i + 1),
      ].map((n) => n.bounds.y - dy).reduce(math.min),
    );
  } else {
    y = math.min(
      ctxt.calculateHeightFromStaffPosition(0),
      [
        startNote,
        note,
        ...notations.sublist(k, i + 1),
      ].map((n) => n.bounds.bottom + dy).reduce(math.min),
    );
  }

  bool addAcuteAccent = false;

  if (startBrace.shape == BraceShape.roundBrace) {
    braces.add(
      RoundBraceVisualizer(
        ctxt,
        startBrace.getAttachmentX(startNote),
        (note as BraceEnd).braceEnd!.getAttachmentX(note),
        y,
        startBrace.isAbove,
      ),
    );
  } else {
    if (startBrace.shape == BraceShape.accentedCurlyBrace) {
      addAcuteAccent = true;
    }

    braces.add(
      CurlyBraceVisualizer(
        ctxt,
        startBrace.getAttachmentX(startNote),
        (note as BraceEnd).braceEnd!.getAttachmentX(note),
        y,
        startBrace.isAbove,
        addAcuteAccent,
      ),
    );
  }

  ctxt.lastStartBrace = null;
}