treata11 / swiftmxl Goto Github PK
View Code? Open in Web Editor NEWImplementation of the MusicXML specification in Swift
License: MIT License
Implementation of the MusicXML specification in Swift
License: MIT License
Time.Signature
Based on Time.Measured
implementations
public struct Measured {
// FIXME:
var values: [Time.Signature]
var interchangeable: Interchangeable?
public init(_ values: [Time.Signature], interchangeable: Interchangeable? = nil) {
self.values = values
self.interchangeable = interchangeable
}
}
& based on Time's elements in a common MusicXML
<time symbol="single-number">
<beats>1</beats>
<beat-type>8</beat-type>
<beats>2</beats>
<beat-type>4</beat-type>
</time>
The array of Time.Signature is certainly an unkeyed element since no keys for this variable exist in a MusicXML file.
[Signature]
in Measured fails to be decodedextension Time.Measured: Codable {
enum CodingKeys: String, CodingKey {
// case signature
case interchangeable
}
public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: Time.Measured.CodingKeys.self)
self.values = try decoder.collectArray()
self.interchangeable = try container.decodeIfPresent(Interchangeable.self, forKey: .interchangeable)
}
}
The line self.values = try decoder.collectArray()
should be able to decode the array of `[Time.Signature] but throws an error in the debugger:
error: -[SwiftMXLTests.TimeTests testDecodingMeasured] : failed: caught error:
"typeMismatch(Swift.Dictionary<Swift.String, Any>,
Swift.DecodingError.Context(codingPath:
[XMLKey(stringValue: "0", intValue: 0),
XMLKey(stringValue: "0", intValue: 0)],
debugDescription: "Expected to decode Dictionary<String, Any> but found ChoiceBox instead.",
underlyingError: nil)
)"
I currently don't know what is wrong, but I have two options right now:
1. A Workaround
2. Investigate the thrown error
Currently, instead of decoding an array of Signature, I decoded an array of beats
an another array for beatType
.
This would decode the data in the following way:
decoded:
Measured(signature: [SwiftMXL.Time.Signature(beats: ["3", "1"], beatType: ["4", "8"])], interchangeable: nil)
The workaround would be to write some logic for the decoded beats
& beatType
s that would initialize an array of Time.Signature
with the number of elements based on the count of beats & then return the decoded data using the created array.
Though it isn't a very convenient approach, it'll work at least for the decode process.
Involves more debugging & more reading for me unless some one with more skills identifies the issue & makes my life easier.
The original MusicXML package was failing due to 6 errors still exists to this date.
First things first, those issues must be fixed before any new additions to package!
Hello, @Treata11,
I'm glad to find an active Swift repository focused on MusicXML processing. My intention is to create a native Apple app capable of displaying scores and playing music.
Would you like to address a few concerns I have? Thanks a lot!
I’m still getting familiar with the Apple ecosystem, so I can’t join your project just yet. However, I’m learning and practicing, and I hope to contribute one day.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.