Giter Club home page Giter Club logo

swiftmxl's Issues

Time.Measured

Time fails to decode array of 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.

Unkeyed element of type [Signature] in Measured fails to be decoded

extension 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

The Workaround

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 & beatTypes 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.

The Investigation

Involves more debugging & more reading for me unless some one with more skills identifies the issue & makes my life easier.

Make MusicXML great again!

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!

Greetings from a stranger

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!

  • Could you estimate the effort needed to fully display MusicXML elements?
  • Are there plans to integrate score playback in the milestones?

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.