Closed jsbean closed 5 years ago
This could look something like:
extension Partwise {
func toTimewise() -> Timewise { ... }
}
extension Timewise {
func toPartwise() -> Partwise { ... }
}
extension Traversal {
func asPartwise() -> Partwise { // only do the conversion if necessary }
func asTimewise() -> Timewise { // only do the conversion if necessary }
}
@DJBen, @bwetherfield, any gripes with an API like that?
IMO these two APIs are sufficient.
extension Partwise {
func toTimewise() -> Timewise { ... }
}
extension Timewise {
func toPartwise() -> Partwise { ... }
}
We can create a new Traversal trivially by .timewise(partwise.toTimewise())
and vice versa. What do you think
The use case I was thinking of would be something like this:
partwise
or timewise
timewise
because you want to incrementally load the score measure by measure so your rendering is faster// Don't know what that traversal is
let musicXML = MusicXML(url: URL(string: "https://whatever.info")!)
// I want it timewise
for measure in musicXML.score.traversal.asTimewise().measures {
// render measure
}
Of course you could do it like this:
let traversal = musicXML.score.traversal
let timewise: Timewise
switch traversal {
case .timewise(value):
timewise = value
case .partwise(value):
timewise = value.toTimewise()
}
for measure in timewise.measures {
// render measure
}
But the one-liner is nice.
(Potentially off-topic: I think we are currently at least one level too-nested with the structure as it is. I think we should get rid of either MusicXML
or Score
or Traversal
and squash things down slightly.) See #166.
As far as the API, @DJBen, do you prefer:
extension Timewise {
func toPartwise() -> Partwise { ... }
}
Or something like this:
extension Partwise {
init(_ timewise: Timewise) { ... }
}
Traversing a
MusicXML
score either in a partwise or timewise fashion has its benefits.Let's enable conversion between
Partwise
andTimewise
elements.