Skip to content

Capella import fails for any file containing a rest (isFullBarRest reads voice before beat is added) #2887

Description

@jhoevelmanns-lab

Bug description

Loading any Capella file (.capx / CapXML) that contains a rest fails with No compatible importer found for file.

With debug logging the Capella importer gets as far as Start Parsing score.xml, then gives up. The underlying exception is:

TypeError: Cannot read properties of undefined (reading 'beats')
    at get isFullBarRest
    at Beat._calculateDuration
    at Beat.updateDurations
    at CapellaParser._parseVoice
    at CapellaParser._parseVoices

Cause

In CapellaParser._parseVoice, the rest case calls restBeat.updateDurations() before this._currentVoice.addBeat(restBeat). updateDurations() → _calculateDuration() reads isFullBarRest, which accesses this.voice.beats — but voice is not set yet, because the beat has not been added to a voice. (The chord case does the same, but there isRest is false, so the getter short-circuits before touching voice.)

case "rest":
    const restBeat = this._parseRestDurations(c.findChildElement("duration"));
    if (restBeat) {
        this._initFromPreviousBeat(restBeat, this._currentVoice);
        restBeat.updateDurations();          // <- voice is still undefined here
        this._currentVoiceState.currentPosition += restBeat.playbackDuration;
        this._currentVoice.addBeat(restBeat);

Possible fix

Either call addBeat before updateDurations for rests, or make the getter tolerant:

get isFullBarRest() {
    return this.isRest && !!this.voice && this.voice.beats.length === 1 && this.duration === Duration.Whole;
}

With the guarded getter (applied as a runtime patch on our side) the affected file loads and renders completely (26 bars).

Environment

  • alphaTab 1.8.4 (npm @coderline/alphatab), browser (Chrome), useWorkers: false
  • File: saved with capella 10 (<score xmlns="http://www.capella.de/CapXML/5.4">), a simple single-staff melody with eighth/quarter rests. I can't attach the original (copyrighted melody), but any CapXML file with a <rest> inside <noteObjects> should reproduce it.

Thanks for alphaTab — it's great to work with!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    Priority

    None yet

    Area

    None yet

    Platform

    None yet

    Work State

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions