Sonolus Wiki

07. Printing Measures

In this chapter, we will implementing printing measures.

Beats

To know how many measures to print, we first need to know how many beats are in a level.

Similar to how we obtain duration of a level, we can have a variable storing beats and notes continuously update it.

export const chart = previewData({
    beats: Number,
    // ...
})
export const chart = previewData({
    beats: Number,
    // ...
})
export class Note extends Archetype {
    // ...

    preprocess() {
        chart.beats = Math.max(chart.beats, this.import.beat)
        // ...
    }

    // ...
}
export class Note extends Archetype {
    // ...

    preprocess() {
        chart.beats = Math.max(chart.beats, this.import.beat)
        // ...
    }

    // ...
}

Measures

Now we can loop over the beats, and print every 4 beats:

export class Stage extends Archetype {
    // ...

    render() {
        // ...
        this.printMeasures()
    }

    // ...

    printMeasures() {
        for (let i = 4; i <= Math.floor(chart.beats); i += 4) {
            print(
                i / 4 + 1,
                bpmChanges.at(i).time,
                PrintFormat.MeasureCount,
                0,
                PrintColor.Neutral,
                'right',
            )
        }
    }
}
export class Stage extends Archetype {
    // ...

    render() {
        // ...
        this.printMeasures()
    }

    // ...

    printMeasures() {
        for (let i = 4; i <= Math.floor(chart.beats); i += 4) {
            print(
                i / 4 + 1,
                bpmChanges.at(i).time,
                PrintFormat.MeasureCount,
                0,
                PrintColor.Neutral,
                'right',
            )
        }
    }
}