From b4b0cb12a89e9245f27c869e4d9bc24727b8edbe Mon Sep 17 00:00:00 2001 From: sdercolin Date: Sun, 11 Feb 2024 21:08:34 +0800 Subject: [PATCH] Fix raw SVP parsing --- src/jsMain/kotlin/io/Svp.kt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/jsMain/kotlin/io/Svp.kt b/src/jsMain/kotlin/io/Svp.kt index 5cb999f..d6fd3d9 100644 --- a/src/jsMain/kotlin/io/Svp.kt +++ b/src/jsMain/kotlin/io/Svp.kt @@ -36,11 +36,11 @@ import kotlin.math.roundToLong object Svp { suspend fun parse(file: File, params: ImportParams): model.Project { - val text = file.readText().let { - val index = it.lastIndexOf('}') - it.take(index + 1) - } - val project = jsonSerializer.decodeFromString(Project.serializer(), text) + val rawProjects = file.readText().split("\u0000") + .map { it.trim('\u0000') } + .filter { it.isNotBlank() } + val projects = rawProjects.map { jsonSerializer.decodeFromString(Project.serializer(), it) } + val project = projects.maxBy { it.version ?: 0 } val warnings = mutableListOf() val timeSignatures = project.time.meter?.map { TimeSignature(