Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trying to parse the MusicXml file error in the project #192

Closed
yangyangnote opened this issue Oct 25, 2019 · 21 comments
Closed

Trying to parse the MusicXml file error in the project #192

yangyangnote opened this issue Oct 25, 2019 · 21 comments

Comments

@yangyangnote
Copy link

Now I have added the library to my project, but I always try to parse the MusicXml file I added to the project in viewdidload, and the string format, url format will be reported, I don't know the problem.

截屏2019-10-25下午5 48 20

@jsbean
Copy link
Member

jsbean commented Oct 25, 2019

The try here indicates that the Score.init(url:) throws.

This initializer could throw for any number of reasons: the file could be ill-formed, or perhaps we haven't implemented something properly yet, etc.

You can handle it in a few ways. This could be a good start:

do {
    let score = try Score(url: URL(string: "..."))
} catch {
    print(error) // TODO: handle error in UI
}

If the file does throw an error, please file an issue with the .xml file attached!

@jsbean
Copy link
Member

jsbean commented Oct 29, 2019

@yangyangnote, lemme know if this is workin' for you!

@jsbean
Copy link
Member

jsbean commented Nov 7, 2019

@yangyangnote, I am going to close this as it pertains to the Swift language itself. If you think the documentation can make this clearer, we can reopen this if you'd like.

@jsbean jsbean closed this as completed Nov 7, 2019
@yangyangnote
Copy link
Author

Sorry, I have been busy recently and have not tested in time.

I tried to rewrite it with the grammar you answered. He reported the following error saying that the optional value is nil, but my file path should be correct. What went wrong with me?

This is the path to the file
/Users/yangyang/Desktop/MusicXMLEM/MusicXMLEM/ViewController.swift

code

do {
        _ = try Score(url: URL(string: “file:///Users/yangyang/Desktop/MusicXMLEM/MusicXMLEM/03 
     爷爷的大钟.xml”)!)
     } catch {
         print(error) // TODO: handle error in UI
     }


  Wouldn't it be necessary to change the string
   var xmlPath : String! = String()
   xmlPath = Bundle.main.path(forResource: “03爷爷的大钟”, ofType: “xml”)!  as String

error:

*Fatal error: Unexpectedly found nil while unwrapping an Optional value: file /Users/yangyang/Desktop/MusicXMLEM/MusicXMLEM/ViewController.swift, line 33*
*2019-11-16 15:58:10.405723+0800 MusicXMLEM[1880:62875] Fatal error: Unexpectedly found nil while unwrapping an Optional value: file /Users/yangyang/Desktop/MusicXMLEM/MusicXMLEM/ViewController.swift, line 33*

@yangyangnote
Copy link
Author

I have modified the grammar now. If it seems better, I still have an error.

code

let file = “Users/yangyang/Desktop/MusicXMLEM/MusicXMLEM/03爷爷的大钟.xml”
 let path=URL(fileURLWithPath: file)

do {
            _ = try Score(url: path)
        } catch {
            print(error) // TODO: handle error in UI
        }

error

typeMismatch(MusicXML.Partwise, Swift.DecodingError.Context(codingPath: [], debugDescription: “Expected Timewise traversal but no measures found”, underlyingError: nil))

@yangyangnote
Copy link
Author

yangyangnote commented Nov 18, 2019 via email

@DJBen
Copy link
Collaborator

DJBen commented Nov 18, 2019

@yangyangnote After we merged my changes yesterday it should be easier to spot where in the codebase it failed to parse your musicXML. Could you provide a branch / url link with 03爷爷的大钟.xml so we can debug it?

@DJBen DJBen reopened this Nov 18, 2019
@yangyangnote
Copy link
Author

@DJBen,I have sent the file to your email to see if it is helpful for your test. If not, I am researching how to submit the branch.

DJBen added a commit to DJBen/MusicXML that referenced this issue Nov 19, 2019
@DJBen
Copy link
Collaborator

DJBen commented Nov 19, 2019

I fixed it and added your xml to the test cases. You should be able to pull the latest hash after it is merged.

@yangyangnote
Copy link
Author

@DJBen Is this problem not updated to the new version, can not be operated with Xcode, must use Git? Is there any good advice?

@bwetherfield
Copy link
Member

The change is merged in now!

@DJBen
Copy link
Collaborator

DJBen commented Nov 19, 2019

@yangyangnote you should be able to update the swift package dependency by setting it to 47ba7905de2b3ce7dc1b0e7e651b31468d976083 commit or latest branch in Xcode.

@jsbean
Copy link
Member

jsbean commented Nov 19, 2019

Thanks @bwetherfield and @DJBen! Let me know if you can get this to work, @yangyangnote.

@yangyangnote
Copy link
Author

yangyangnote commented Nov 20, 2019

@jsbean @DJBen I update the swift package dependency by setting it to 47ba790

The code didn't report an error, but nothing was displayed on the screen. This is my code. Any questions?

code

let file = “Users/yangyang/Desktop/MusicXMLEM/MusicXMLEM/03爷爷的大钟.xml”
 let path=URL(fileURLWithPath: file)

do {
            _ = try Score(url: path)
        } catch {
            print(error) // TODO: handle error in UI
        }

@jsbean
Copy link
Member

jsbean commented Nov 20, 2019

This is a good thing :).

Now you can try:

do {
    let score = Score(url: ...)
    dump(score)
} catch {
    print(error)
}

This should print a few tons worth of stuff to the console. It should give you a sense of the structure of a Score value.

@yangyangnote
Copy link
Author

The information output is indeed a lot 😱

This is the mark markdown file

Music XML parse Error.md.zip

@jsbean
Copy link
Member

jsbean commented Nov 22, 2019

😄 To be clear, this isn't an error. You have successfully parsed your music xml file into Swift!

Now you can play around with it:

do {
    let score = Score(url: ...)
    switch score {
        case let .partwise(partwise):
            print("We've got a Partwise traversal!")
            for part in partwise {
                print(part.id)
                for measure in part.measures {
                    print(measure.number)
                    for musicDatum in measure.musicData {
                        print(musicDatum)
                        // TODO: Do something with the data!
                    }
                }
            }
        case let .timewise(timewise):
            print("We've got a Timewise traversal!")
            for measure in timewise.measures {
                    print(measure.number)
                for part in measure.part {
                    print(part.id)
                    for musicDatum in part.musicData {
                        print(musicDatum)
                        // TODO: Do something with the data!
                    }
                }
            }
    }
} catch {
    print(error)
}

@yangyangnote
Copy link
Author

@jsbean When I try to reference your code in the code, two errors occur, as shown below
截屏2019-11-25下午5 00 48

@jsbean
Copy link
Member

jsbean commented Nov 26, 2019

Whoops, a couple typos:

  • for part in partwise.parts
  • for part in measure.parts

@yangyangnote
Copy link
Author

yangyangnote commented Nov 26, 2019

@jsbean Now the console outputs a bunch of things, I don't quite understand. Can't you generate a staff directly on the screen after parsing? Or is there something wrong with my understanding?
Parseoutput.md.zip

@jsbean
Copy link
Member

jsbean commented Nov 28, 2019

Perhaps it is not made it clear in the README, but graphical representation of musical information is out of scope for this repository. This package merely provides a Swift representation of the MusicXML types. This allows different musical renderers to do as they please, in their own way.

Check out music-notation-core, Guido, Verovio, or dn-m/NotationView for rendering your MusicXML files onto the screen.

All of these projects are either works-in-progress, or require a bit of handling between C++ and Swift.

I am going to close this as the package is working as intended. I will work toward making the documentation clear about the scope of its responsibilities.

@jsbean jsbean closed this as completed Nov 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants