In this post:
- I come up with a plan to replace my current ad-hoc time signature data type.
- I execute all of it...
- Except the "replace the time signature type" bit.
Looking over the details of various kinds of time signatures, I see that I want the time signature objects to be somewhat sophisticated, and to carry much of the weight in placing the beats within a measure. In short, the current beat determination code only produces sensible results for simple time signatures. There's a single well-defined beat structure for compound time signatures, but a single asymmetric time signature can have different beat structures as close as consecutive measures.
Since I'm storing beat structure data (in the form of time signature) on every measure anyway, I'll keep on doing that, but instead have an explicit "beat structure" object, with various constructor methods.
Here's what I need to make this happen:
I'm going to rename the "NoteDuration" class to "Note".
Then, I'm going to add a "NoteDuration" class that wraps the Fraction type, and thread that through the codebase where I'm currently using Fractions.
The BeatStructure object is a base NoteDuration, and a sequence of integer beat durations.
Several helper methods to create common BeatStructures:
- Symmetrical beat structures may have length one or three. A single function creates both.
- There are two functions that explicitly create simple or compound time signatures, which do basic validation and forward to the previous function. Or maybe it's a little the other way around.
So, it's almost eleven pm now, and here's where I stand:
- I did (almost) everything in that list up there.
- But that's not enough.
- The remaining work is to replace the "time_signature" tuple with a BeatStructure, and rewrite the code that consumes it.
- This is non-trivial, at least compared to what I've done so far.
- I'm currently cursing my past self for not reading ahead, and playing Minecraft instead of working on this earlier today.
- My head hurts, and I have to know my limits.
Next week, I'll replace the time signature with a beat structure. I may have a chance to make the analysis code more sophisticated; I read ahead just now, and that's pretty much the last thing to do before I start getting actual pitches involved.