Closed yangyangnote closed 4 years ago
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!
@yangyangnote, lemme know if this is workin' for you!
@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.
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*
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))
Hi James
Is it possible to reopen this issue #192 https://github.com/dn-m/MusicXML/issues/192 , I am very sorry that I have been busy recently, I forgot to test it in time, and now I will test it back in time.
James Bean notifications@github.com 于2019年11月8日周五 上午2:00写道:
Closed #192 https://github.com/dn-m/MusicXML/issues/192.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/dn-m/MusicXML/issues/192?email_source=notifications&email_token=AETRKST52M46CSUU32UMOB3QSRJSRA5CNFSM4JFBDUMKYY3PNVWWK3TUL52HS4DFWZEXG43VMVCXMZLOORHG65DJMZUWGYLUNFXW5KTDN5WW2ZLOORPWSZGOUW4AMKI#event-2780300841, or unsubscribe https://github.com/notifications/unsubscribe-auth/AETRKSWJMK2MFZ57G245SX3QSRJSRANCNFSM4JFBDUMA .
@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,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.
I fixed it and added your xml to the test cases. You should be able to pull the latest hash after it is merged.
@DJBen Is this problem not updated to the new version, can not be operated with Xcode, must use Git? Is there any good advice?
The change is merged in now!
@yangyangnote you should be able to update the swift package dependency by setting it to 47ba7905de2b3ce7dc1b0e7e651b31468d976083
commit or latest
branch in Xcode.
Thanks @bwetherfield and @DJBen! Let me know if you can get this to work, @yangyangnote.
@jsbean @DJBen I update the swift package dependency by setting it to 47ba7905de2b3ce7dc1b0e7e651b31468d976083
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
}
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.
The information output is indeed a lot 😱
This is the mark markdown file
😄 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)
}
@jsbean When I try to reference your code in the code, two errors occur, as shown below
Whoops, a couple typos:
for part in partwise.parts
for part in measure.parts
@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
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.
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.