Writing

I haven’t done a lot of writing here, mostly because I forgot about it, but here I am trying to decide which parts of my website are worth saving and which parts are going to be purged. Personally, I feel like I could benefit from quite a lot more writing, even if I never read the things again. But this place was mostly going to be for things that I learned while coding. I haven’t done a lot of very useful coding recently. I thought I would do more, especially during the pandemic, but that seems to have not been the case. It was really weird how, suddenly with so much free time, I just didn’t want to do any of the things I always felt I would do if I only had the time. This seems to have been a common feeling among people.

Currently, I’m working on a number of projects that I don’t know will end up finished. First of all is a music staff view library that compliments the Music library that I wrote a number of years ago. The staff view could be helpful in many projects, but first I need to give it basic functionality (which gives me a good idea about how to proceed with a version 1.0).

The second of these comes out of trying to create a DSL, or Domain Specific Language, in Swift, which turned out to be a really cool idea. The eventual goal of the staff view library is going to be to represent code in Swift/SwiftUI in the following manner:

That looks very clean and concise to me. Now to figure out how the heck to make it draw. I wrote the original version so that anything could adopt a specific protocol called MusicStaffViewElement, which describes the necessary methods required for the element to be rendered by the view. This tends to make things easy for simple setups like the one above. But how do you draw more complicated groups like notes with accidentals or notes grouped by a beam? That kind of complicated rendering makes me want to create more complex data structures like beam groups and the like, but it feels like that’s too complicated for the SwiftUI rendering system (it probably isn’t, but it was too complicated for my UIView rendering system, so it might yet be).

I thought about drawing note heads separately, and then computing how the rest of the parts of the notes—such as stems and flags and dots—should draw. But that’s also complicated. So then, maybe it becomes a question of creating new elements, like NoteWithAccidental or NoteBeamGroup. But does that defeat the purpose of making the MusicStaffViewElement protocol so easy to draw? It’s a bit of a feedback loop still.