|
On 12/9, at the end of 'The Machinery of Taste', I wrote that things would be slower here for a month or so. A new client placement was taking a great deal of attention, one of my AWS Professional certifications was due for renewal, and Ooloi would have to wait its turn.
It was, for about a fortnight. Then came the heaviest run of posts this blog has had: three long ones in less than a week. So much for the quiet month. What was left to do on the engine was mechanical: refining the file chooser, and building the permission and invitation machinery for collaboration. Neither needs much thought once it's specified, and both were specified. That left the part of my mind that doesn't type with nothing to do, and it went where it always goes, to the next hard problem. Given the six-stage pipeline, how should a score be cast off, and how should the notes in each system share out its width? I read and mulled, argued with myself and with language models, left it alone and came back to it. I didn't recognise what I was doing until it was over. Rich Hickey gave a talk in 2010, 'Hammock Driven Development', about exactly this. You load a problem into your waking mind as thoroughly as you can, then step away and let the background get on with it. That background is where most real design happens, he argues, and it only works on what you've given it. Mine had been given two years of pipeline and had nothing urgent to do with its hands. Then the paper arrived, and the timing is what I keep turning over. Hegazy and Gourlay's 'Optimal Line Breaking in Music' reached me after I'd converted completely to Knuth–Plass. ADR-0037 had been aligned with the original down to TeX's constants, and 'Boxes & Glue' had ended on an unfinished thought about notes that want to stretch and give by different amounts. A month earlier it would have been an interesting old paper. When it came, I already had the question it answered. It's the second time this has happened. In April I wrote that I needed Ross's The Art of Music Engraving and Processing and couldn't buy it. Kim Bastin in Melbourne read it and put his own copy in the post. In September I asked in a comment whether anyone had the Hegazy and Gourlay report, and within a week Ulrik Bodén had found one. I hadn't asked either of them personally. The paper changed the project's direction, which is a different thing from being grateful, though I'm that too. Until Ulrik's copy arrived, Ooloi's design used one scale factor per system, both to choose the breaks and to place the notes. It was one model, but a crude one. It had no way of letting an accidental hold a gap open while its neighbours carried on, so every way of fitting chromatic music into it was wrong somewhere. Letting an accidental hold its gap while the others carry on is exactly what Gourlay's springs were made for. The force that decides where a system ends now decides, gap by gap, where each note in it sits, and it treats an accidental the way an engraver would. 'Vestigia' has the details. The short version is that casting off and note positioning are now governed by one single piece of mathematics that's right where it matters. That's huge, actually. Huge because of what it protects. Information in Ooloi's pipeline flows one way: no stage asks an earlier one to think again. A model that's wrong in some cases will sooner or later tempt somebody to fix those cases afterwards, just this once, and that's the frost troll from yesterday's post. A model that's right about the hard cases gives the troll nothing to work with. Every rule about horizontal space reaches the springs as data, and once it does, it combines with all the others without anybody writing special cases. Engraving becomes far easier to reason about, for me and for the AI, which is at its best with mathematics somebody has written down. It's encouraging, too, how little resistance the change met. The dynamic program didn't move at all. Stages 1 and 2 were already producing the widths the springs need, and each bar now keeps a couple of extra sums and a short list of the gaps its accidentals hold open. ADR-0037 was revised and ADR-0055 written within days of the paper arriving, and nothing around them had to change. None of it is built yet, so what passed the test was the specification, not the code. But building something that a better idea could walk into without a fight was the point of the last two years, and this was a big idea. In 'High Hrothgar' I wrote that 'Nun denn, allein!' could have been carved over the monastery door. That was the honest picture of the first two years, and I won't revise it now. In April, when Kim offered me his copy of Ross, I wrote that something like an informal fellowship seemed to be forming around the work. That was a feeling. This is a fact about the engine: the model at the centre of its layout came from a paper I couldn't find and Ulrik could. 'Alone' describes how Ooloi was started. It no longer describes how it's being built. That changes how the work feels. The conversation here will change too. When the permission and invitation machinery is finished, I'll show it in a video, and that will be the last of the plumbing. In August I raked the ring and left it empty. What comes next is what it was raked for: spacing, beams, slurs, page turns, the page itself. Those are questions musicians can argue about without reading a line of Clojure, and the people already gathered in the comments are the ones who'll know when I've got an answer wrong. I should take more quiet months.
0 Comments
The paper is here. 'Optimal Line Breaking in Music', by Wael A. Hegazy and John S. Gourlay of the Ohio State University, 1987: fifteen typed pages, scanned from somebody's reading copy, complete with underlinings and a few pencilled notes in the margins. It's out of print and it isn't online, and I'd been looking for it far and wide. In the end Ulrik Bodén, owner of Musikboden and one of Ooloi's sponsors, tracked down a copy and sent it to me. Once again the small circle of friends around this project has done what searching couldn't, and I'm very grateful. Under the last post, Magnus Johansson asked whether I'd had the chance to study it yet. I have, and this is what I found. First, a word about how I look at other programs, since several of them appear below. I don't run Dorico, MuseScore or LilyPond, and I don't intend to. That isn't disdain. I read what can be read: source code where it's open, development diaries where their authors have published them, forum posts where a decision has been explained. I read them as I read the source of gRPC or the JVM, to understand how something was built and, above all, why. What I don't do is examine the latest release to see what I'm up against, because I'm not up against anything. Ooloi isn't a feature race. I'm trying to build an engine for music notation in which the difficult parts are dealt with underneath, once and properly, so that whoever builds on it doesn't have to. If it works, it'll be because of what Ooloi is rather than what it does. Casting off and horizontal spacing are where reading other programs is most illuminating. Casting off is the engraver's term for deciding where each system ends; horizontal spacing is how the notes within a system share out its width. Between them they decide whether a page reads evenly or lurches, and whether the last system of a movement is full or holds two forlorn bars. A player takes all of that in before reading a single note. Every notation program has to answer the question, the answers differ, and the reasons for the differences say a great deal about the architectures behind them. The Other Ninety Per CentIn September 1985 Jon Bentley's Programming Pearls column in Communications of the ACM collected a page of programmers' aphorisms. One of them, credited to Tom Cargill of Bell Labs, has outlived most of the others: 'The first 90 percent of the code accounts for the first 90 percent of the development time. The remaining 10 percent of the code accounts for the other 90 percent of the development time.' Engravers have their own version. Notation software handles about 95% of engraving well, and engravers spend about 95% of their time on the remaining 5%. Those figures are practitioners' experience rather than measurements, but anyone who has prepared parts for a performance will recognise the shape. The afternoon goes on forcing system breaks, prising collisions apart, and recasting a part so that the page turns fall in rests. The two rules describe the same remainder from opposite ends. The cases a developer leaves unfinished, because they belong to the last 10% that would take the other 90% of the time, are precisely the cases the engraver then finishes by hand. Shipping at the 90% mark doesn't make the remaining work go away. It passes it on to the users, multiplied by every user and every score. That's a tax, and like most taxes it's paid continuously by people who never voted for it. Ooloi is in large part an attempt to abolish taxes of this kind wherever the architecture allows, from undo to collaboration. The engraver's 5% is the largest of them. I should be fair here, because it matters. Doing 95% well might genuinely be good enough for most people's music. In December 2016 Daniel Spreadbury wrote that Dorico's casting off, tested against the Gourlay method, 'produced very similar results a lot of the time'. That's the 95% working exactly as designed. The 5% is where it doesn't, and that's where the engraver's afternoons go. Knuth & Plass, BrieflyI wrote about the algorithm in 'Boxes & Glue', so a reminder will do. In 1981 Donald Knuth and Michael Plass published the line breaker that TeX still uses. A paragraph is a row of boxes (the words, which are rigid) with glue between them (the spaces, each with a natural width and a given capacity to stretch and shrink). Any choice of breaks gives each line an adjustment ratio r: the stretch or shrink the line needs, divided by the stretch or shrink its glue can supply. So r = 0 is a line at its natural width, r = 1 is a line stretched as far as its glue is meant to go, and r = −1 is the tightest line TeX will set. Knuth turns r into badness, roughly 100 × |r|³, and badness into demerits, (l + b)² + p², where l is a small charge for every line and p the penalty attached to the break. Then he finds the set of breaks with the smallest total for the whole paragraph. The cubes and squares mean that one very bad line is punished far more than several slightly imperfect ones, which is exactly the judgement a good compositor makes. What makes it fast is dynamic programming. The program walks through the paragraph once and, at each possible break, remembers only the best way of getting there. If the cost of a line depends on that line alone, nothing more is needed: when the walk reaches the end, the best layout of the whole paragraph is recovered by following the remembered steps backwards. The result is exact, meaning provably the minimum of its cost rather than a good guess, and the work grows with the number of possible breaks times the number of words that can share a line. The alternative, and still the usual one, is greedy filling: put bars on a system until the next one won't fit, move on, and never look back. It's quick and it's local, and the bill arrives at the end of the piece. What Hegazy and Gourlay Actually WroteAs far as I can tell, nobody has described this paper in public. LilyPond's source names it as the origin of its first line breaker, and Daniel Spreadbury has said it informed Dorico's casting off, but I've found no account of what it actually contains. ADR-0037, which specifies Ooloi's breaker, cited it while admitting that it described none of its contents. That ADR has now been updated with a description along these lines. The paper opens by explaining why music isn't text. The last system of a piece is always full, so a copyist has to be prepared to revise early breaks that don't lead to a full last line, and a program must be able to do the same or it'll stretch the last system grotesquely. Long works should also fill their last page, which sometimes means forcing a particular number of systems. Clefs and key signatures repeat at the start of every system, and they change, in content and in width. Most important of all, notes don't move linearly when a system is stretched or squeezed. The state of the art, they note, offered little help. Byrd's 1984 thesis program did first-fit breaking, which is greedy filling by another name, and expected users to choose their own breaks. Ross's engraving manual advised avoiding bad breaks and keeping the spacing uniform. 'There appears to be no published algorithm', they write, that attempts to deal with these problems at all. Their claim is that Knuth's model already handles the first three. A paragraph with no fill glue at its end gets a full last line automatically. Penalties encourage or discourage particular breaks, which is how a performer's awkward page turn can be avoided. TeX can be told to use a set number of lines. And TeX's discretionary breaks, the mechanism behind hyphenation, can change what's printed at the end of one line and the start of the next. Only the fourth problem needs new theory. That theory is the paper's real contribution, and it's lovely. Think of the space between two notes as a spring. In text the springs join the outsides of rigid boxes. Hegazy and Gourlay pass the springs through the boxes and attach them to the left edges of the noteheads, because what the eye measures is the distance from one note to the next, not the white space between their shapes. The boxes still can't pass through each other, though. A note and the accidentals of the note after it take up room, and when those shapes touch, the spring between them can shrink no further. So each gap carries four numbers: an ideal width w, a stretchability y, a shrinkability z, and a blocking width b, the width at which the shapes on either side collide. Under a force f, which is Knuth's adjustment ratio under another name, positive to stretch and negative to compress, the gap's width is the larger of two quantities: width = max(b, w + f·k), where k is y when stretching and z when compressing. Read as a musician: the spring tries to be its ideal width plus whatever the force asks of it, but never narrower than the collision allows. Read as a mathematician: each gap is a piecewise-linear function of the force, and therefore so is the whole system. The interesting case is the one where b exceeds w, which they call 'prestretched'. Their Figure 1 shows it: a note preceded by two flats so wide that the gap before it is already larger than its duration warrants. That gap doesn't move at any line length until the force on the rest of the system has caught up with it; only then does it begin to grow with the others. The accidental takes the room it needs and not a hair more, and once the system is loose enough it costs nothing at all. That's exactly how an engraver treats an accidental. The consequence for breaking is that the force needed to fit a system is no longer a single division, as it is in TeX. It's the solution of a piecewise-linear equation whose kinks lie wherever an individual gap collides or begins to stretch. The search around it is Knuth's, which they say 'does not differ in any significant way' from TeX's: remember the best predecessor for each barline, discard lines whose force falls outside a permitted window, and trace the optimum backwards from the end. Their efficiency section is the most telling part of the paper, because they never treat the dynamic programming as the expensive part. The expense lies in working out the force for each candidate system, and they attack it twice. First comes a cheap lower bound on the force, built from running totals: 'the sums are computed from the beginning of the piece to the current place, and two such sums are subtracted to obtain the sum for what lies between them'. Programmers call these prefix sums. The bound is designed so that it can never wrongly reject a system that would fit. Second comes a fast path for the common case, in which the force stays on the first straight segment of the curve, before any gap has collided. They test for that with minima precomputed for each bar. Their evidence is modest and well chosen. They broke a 48-bar piece on a single stave, Dean K. Roush's 'Lacrimosa', into systems. The breaks matched those chosen by a professional musician, who had spent a few hours on it. The program took a few seconds on a personal computer of 1987. So is it Knuth–Plass? Not purely. The search is Knuth's without his fitness classes, which TeX uses to stop a tight line from sitting next to a loose one, at the price of extra bookkeeping. The cost is shaped like TeX's but never written down as a formula. And the model of a line is a strict generalisation of boxes and glue: TeX's glue is the special case in which nothing ever collides. But it isn't approximate either. The cost of each system depends only on that system, the pruning is sound, and the cheap bound never discards a line that would fit, so the result is the exact optimum of its own cost. Nor do the modifications reduce the efficiency of the algorithm. The dynamic programming is untouched; what grows is the arithmetic inside the evaluation of a single system. What Hegazy and Gourlay did to Knuth and Plass was extend them. The DescendantsThree documented lines of descent made three different choices, and in each case the authors have said why. LilyPond's first line breaker, gourlay-breaking.cc, says in its source that it was 'adapted from the OSU Tech report on breaking lines'. It was a straightforward dynamic program until October 1999 (release 1.2.14), when a term comparing each system with its predecessor was added for the sake of evenness. With only one predecessor stored per breakpoint, that made the result an approximation of its own cost, and the term survives in LilyPond's current breaker. LilyPond's spacing, which I'll come back to, is solved afresh for every candidate line. Han-Wen Nienhuys, who wrote the original breaker, commented in 2015 that he'd first run it on a 386 at about 40 MHz, where 'it was somewhat expensive'; that computers had since become a hundred times faster; and that you have to solve 'O(#bars * #bars-per-system) spacing problems'. He thought it could be used for interactive scores too. Dorico's team evaluated the Gourlay method early on. In 2015 Spreadbury set out the reasoning in his development diary. A program that compiles its output from text input needn't respond in real time, but for an interactive one 'a compromise is needed in order to balance the quality of the result against the time taken to compute it', and Dorico's principle was to 'always do only the minimal amount of recalculation to respond to an edit'. In December 2016 he wrote that the method's performance characteristics weren't suitable for Dorico's real-time use, and that Dorico's own algorithm 'basically runs only one way, from the start of the layout to the end'. In April this year he confirmed that the paper had informed Dorico's casting off, which is greedy, with a separate remainder-distribution step at the end of each flow. That remainder step deals with the full last system, the first of the four problems Hegazy and Gourlay listed in 1987. Others claim the full prize. Christof Schardt, the author of PriMus, wrote in 2015 that PriMus had used TeX's total-fit algorithm, 'modified for scores instead of text', interactively for over ten years, taking collisions into account 'by an equivalent linear operation'. Basil Crow's open-source Neanes editor does optimal line breaking for Byzantine neume notation. I haven't checked either at source. None of this is a league table. Each choice was rational under the constraints its makers had, and Spreadbury's 2013 statement of Dorico's ethos, that the application should do 'automatically what an experienced engraver or copyist would do anyway', is one I'd sign without changing a word. The goal is shared. The constraints aren't. Speed was Never the ObstaclePut the dates side by side. In 1987 an exact optimum over a nonlinear spring model ran in seconds on a personal computer. In 2015 the author of LilyPond's first breaker, who had run it on a 386, reckoned that machines a hundred times faster could manage it interactively. Processor speed hasn't been the obstacle for a very long time. What costs something is evaluating each candidate system, and everyone who has looked closely puts the cost there: Hegazy and Gourlay in 1987, Han-Wen in 2015. Hegazy and Gourlay's remedies, the running totals and the per-bar minima, rest on an assumption so basic they never needed to state it, which is that each bar's numbers are fixed before breaking begins. They could assume it because their input was a single stave, handed to the program as a ready-made sequence of springs. A notation program has to manufacture that input from a full score, and this is where architecture comes in. Suppose a candidate system's width depends on which bars share it, or on something settled only after the breaks are chosen: the courtesy accidentals at a system start, an accidental decision that changes when a tie crosses a break, spacing that's adjusted and then fed back. Then every candidate needs its own spacing calculation. In a mutable, incremental program, every moved break also invalidates whatever was computed downstream of it. A global optimum, where one edit can move breaks anywhere in the score, then becomes the most expensive thing you could possibly ask for, and greedy filling is the sensible choice. I can't see inside anyone else's program, so take this as my reading of the problem rather than a finding about any product. But it's consistent with everything their authors have said, and it puts the obstacle where the 1987 paper already implied it was: in the data, not in the processor. Vestigia Nulla RetrorsumOoloi lays out a score in six stages, and information moves through them in one direction only. Stage 1 works on every bar in parallel. It forms the atoms (a note or chord with its accidentals, dots and articulations, handled as one unit) and traces their outlines from the font, the shape each presents to its neighbours. Stage 2 lines the staves up vertically and works out, for every gap, both its ideal width, which comes from the durations, and its minimum, where neighbouring outlines would touch, so that each measure stack (one bar across all the staves) leaves it as a handful of numbers. Stage 3 breaks the systems. Stage 4 positions the atoms. Stage 5 draws what connects them, the ties, slurs, hairpins and beams, and works out how tall each system is. Stage 6 breaks the pages. Nothing flows back. Stage 5 can't ask Stage 3 for more room, and Stage 3 can't reopen a decision made in Stage 1. The musical questions, such as which accidentals a note needs, are closed before layout begins, so layout can't change them. Everything Stage 3 needs is known before it starts, including what each bar would require at the start of a system and at the end of one. The pipeline has a motto, borrowed from Horace. In the first of his Epistles (I.1.73–75) a fox declines the sick lion's invitation into its den and explains why: 'quia me vestigia terrent, omnia te adversum spectantia, nulla retrorsum'. The footprints frighten me: they all lead towards you, and none lead back. In the fable that's a warning; in a layout pipeline it's the design. Every footprint points forward, and that single property is what turns casting off from a negotiation into arithmetic. Arriving at the Same PlaceOoloi’s breaker, specified in ADR-0037, was written from Knuth and Plass directly, before I’d read a line of Hegazy and Gourlay. Reading them now is a curious experience, because the search is the same. Both remember one best predecessor per barline, with no fitness classes. Both subtract running totals between barlines, and both stop extending a candidate system as soon as more bars can’t possibly fit. Their per-bar minima, used to test whether a line has reached its first collision, correspond to a number every Ooloi measure stack carried until now: its tightest gap’s ratio of minimum to ideal width, tracked as a running maximum while the candidate system grew. The correspondence goes deeper than I expected. Until now, Ooloi’s baseline let every gap stretch and shrink in proportion to its ideal width, so each system had a single scale factor. It also calibrated the adjustment ratio so that r = −1 fell exactly where the tightest gap in the system reached its minimum, and allowed nothing beyond that point. In Hegazy and Gourlay’s terms, that was their model restricted to the first straight segment, before any gap has collided, with the force rescaled so that the first collision sits at −1. I got there independently, but I don't think the convergence is remarkable. Both designs start from TeX, and both discover that the cost lies in evaluating a line; from there the problem pushes you towards the same answers. I find that reassuring rather than surprising. Where Ooloi goes further, most of the reasons lead back to the direction of flow. The first concerns system starts and ends. Hegazy and Gourlay pointed at TeX's discretionary breaks for the clefs and keys at each system start, and left it there. A discretionary has three parts: what's printed before the break, what's printed after it, and what's printed if no break happens. Ooloi's breaker has all three. A postamble holds what a system's end needs, which is the cautionary key and time signatures; a preamble and a gutter hold what the next system's start needs: clef and key, courtesy accidentals for tied notes, a start repeat. Everything else at a barline belongs to a bar, wherever that bar falls: the barline itself, as it looks at the end of a system, and a clef change drawn in front of it belong to the bar they close, and a new key or time signature to the bar it begins. The third part holds what exists only mid-system: the start half of a repeat barline, which at a break moves to the start of the next system, and the cancellation naturals of a key change, if the house style drops them at a system start because the previous system's cautionary has already shown them. Each is a fixed width at its barline, and the breaker subtracts those inside a candidate system with a single subtraction of running totals, so the result stays exact. All of it is known before breaking, because nothing downstream can change it. This also matters for exactness. Hegazy and Gourlay's pruning is only safe because their systems carry no such material. Give each system start a width that varies from bar to bar and their pruning can wrongly discard systems that would have fitted. ADR-0037 prunes against the full system width instead, which stays exact. The second concerns editing. A global optimum means that one edit can move breaks anywhere, which is why interactive programs avoid it. In Ooloi every stack's numbers are immutable and cached, so after an edit nothing upstream is recomputed except what the edit actually touched, which is usually the bar that changed. The new optimum is then found exactly from two stored tables, holding the best layouts of everything before the edit and of everything after it, in roughly K² evaluations, where K is the number of bars that fit on a system. That's a couple of hundred cheap evaluations, not a re-layout. Keeping breaks where they were while you work is a separate problem, and the ADR specifies mechanisms for it that are anchored to the identity of bars rather than to luck. The third is determinism. Layout is computed once, by the authoritative backend, not separately by each client; but it still matters that the same music always produces the same layout. Everything is computed in exact rational arithmetic, and when two layouts cost exactly the same, which under exact arithmetic happens whenever bars are identical, the tie is broken by a rule that depends only on the layout itself, never on the order in which the program happened to meet the candidates. Re-optimising after an edit therefore gives the same answer as starting from scratch, undo brings back the identical layout, and a score opened on another machine looks the same there. Nothing on the page moves unless the music has given it a reason to, which removes a whole class of jitter at its source. One further difference has nothing to do with immutability: Ooloi's cost is written down. It uses Knuth's badness and demerits with TeX's own constants as the starting point. That only works because the adjustment ratio is calibrated so that −1 means collision and +1 means a stated amount of stretch; without the calibration, TeX's numbers would mean something quite different for music. That one is simply care. What Gourlay has that Ooloi Doesn'tThe other direction is the more interesting one. Until now, ADR-0037 allowed four fitting rules, which are ways of deciding how each gap gives way when a system is looser or tighter than ideal. All four were linear glue: each gap stretches and shrinks in fixed proportion, and a system’s force is a single division. None of them could represent a gap that blocks while its neighbours carry on, and none could represent a prestretched gap at all. The ADR’s contract with Stages 1 and 2 actually forbade it, since every gap’s minimum had to be at or below its ideal. And the case isn’t rare. The engraver’s principle is that everything belonging to a note, accidentals included, should fit within its proportional allocation: accidentals don’t add space. But a sixteenth’s allocation is around one and a half stave spaces, and a notehead plus a sharp plus clearance needs more than two. In any chromatic passage in sixteenths, a good share of the gaps have a minimum larger than their ideal. That’s Gourlay’s prestretched spring, and it’s what the decision below turns on. All of this is easiest to picture on a single stave, but Ooloi doesn't space just single staves. Stage 2 aligns every stave in a measure stack on a shared vertical raster: one column for each rhythmic position that occurs in any stave, so that notes sounding together line up from the top of the system to the bottom. A gap in Gourlay's sense is the distance between two columns, and its blocking width is set by whichever stave needs the most room there. A sharp in the violas widens that column for the flutes as well. What I Have to DecideThere are three ways to go, and each of them shows on the page. Take a bar of chromatic sixteenths, half of them carrying accidentals, as the running example.
I have decided that Ooloi will adopt Gourlay’s springs, and ADR-0037 has been revised to specify them. Will it make Ooloi slower? As with Hegazy and Gourlay, the dynamic programming itself doesn’t change at all: the same states, the same number of candidate systems, the same tables for re-optimising after an edit. What changes is the arithmetic inside the evaluation of a single candidate system, and only for the systems that need it. Compression is always a single division, exactly as before. So is stretching, until a gap held open by an accidental starts to stretch. Only then does the candidate take the slower path, in which those gaps’ kinks are kept in sorted order as the candidate grows and the force is found by walking them. That costs a handful of extra operations per kink passed, not a spacing calculation. Those are precisely the systems the linear baseline spaced wrongly. The ones it rejected outright, frozen by a single gap that couldn’t shrink, now cost nothing extra at all. Stages 1 and 2 already compute every gap’s ideal and minimum, so nothing new is asked of them; each stack simply keeps a few sums and a short list of its accidental-held gaps. The result stays exact and identical on every machine, and nothing flows backwards. I’ll know the real cost when there’s a benchmark on chromatic material. Until then, that’s reasoning rather than measurement. As I've decided to go with the springs, more questions follow. The first is what r = −1 should mean. If each gap’s shrinkability is set to its room above collision, every gap reaches collision at the same moment, at −1, and TeX’s constants keep their meaning. But wherever long notes have more room than short ones, they give up more of it, and the rhythmic hierarchy flattens under pressure. If shrinkability is weighted by duration instead, short values compress and collide first while longer ones keep giving. That’s nearer to the way engravers describe their own practice, but −1 then needs another definition. The choice decides whether a tight system still reads as rhythm. I’m starting with the first, which is also LilyPond’s default and keeps compression a single division; duration weighting stays a candidate for the plates to decide. The second is minimum distances that span more than one gap: a long syllable sung across a melisma, or material that crosses between staves. Gourlay’s blocking works between neighbours, so such constraints have to be reduced to minimums on adjacent gaps before breaking. LilyPond’s spacer shows how: a minimum distance spanning several notes becomes a blocking force on every spring beneath it, at a small cost in density that a comment in its source considers acceptable. Since that force depends only on the springs inside the span, it can be worked out before any break is chosen, and that’s the reduction ADR-0037 now specifies, in Stage 2. So Ooloi doesn’t need the per-candidate spacing calculation that LilyPond chose to pay for. The third is what the raster should do with the room. Take two staves of sixteenths in the same stack, some notes carrying accidentals and some not, in different places in each stave. One answer is that every sixteenth in the bar sits at the same distance from the next, so the rhythm reads as a regular grid and every column gets as much room as the most demanding one. Another is that each column takes only what it needs, so a column with an accidental in any stave is a little wider and the rest a little narrower: more economical, less regular. Gourlay's springs give a third answer that moves between the two. Under pressure the columns differ; as the system loosens, the columns held open by accidentals stop growing while the others catch up, until at some point the grid is even again. Which of these an engraver would choose, and at what degree of tightness, is a question for the plate. A related case shows what's at stake. Take a bar that opens with a half note, continues with eight thirty-second notes and ends on a quarter. Logarithmic spacing already gives the thirty-seconds far more room than strict proportion would, and with their beams, stems and perhaps an accidental or two they may need more still. The half note and the quarter, on the other hand, are mostly air. An engraver lets them pay: the run of thirty-seconds gets the room it needs, and the long notes give some of theirs back. Proportional scaling can’t do that. Every gap shrinks by the same factor, so the thirty-seconds reach their minimum first and the whole system stops compressing while the half note still has room to spare. Shrinkability bounded by each gap’s own room, the second option above, does let the long notes give way, and Gourlay’s springs do it as a matter of course: the thirty-seconds, with little or no room above their minimum, give up little or nothing, and the half note and the quarter absorb the rest. This is also where the weighting question gets interesting. ‘Shorter values compress first’ sounds right until the shorter values have nowhere left to go; beyond that point the blocking decides, not the weighting. What none of this decides is who pays. Gourlay's force is one number for the whole system, so the cost of the thirty-seconds is spread over every gap in it, including a half note three bars away. An engraver might prefer the half note in the same bar to pay, and leave the rest of the system alone. That's a choice between consistency, where the same duration gets the same space across the system, and locality, where each bar settles its own debts. It belongs to the setting of ideal widths within a bar, before any fitting begins. In a full score it's subtler still: if the half note sounds against thirty-seconds in another stave, the raster has no half-note gap to shrink at all. All of this sits beside two questions ADR-0037 already left open. One was whether to add a term for evenness between neighbouring systems, as TeX does with its fitness classes. I’ve decided against it. The cubic badness already punishes an extreme system out of all proportion, so under an exact optimum a cramped system survives next to a loose one only when every alternative costs more. And a comment in LilyPond’s source warns that such a term can make cramped lines more cramped where the music grows gradually denser. Music changes density for reasons of its own, and the layout shouldn’t pretend otherwise. The other question, how page breaking and with it the page turns in parts should be costed, remains open. How the Others AnswerEach of the programs I've read has answered these questions definitely, and since I read rather than run them, what follows comes from their source and their documentation. It describes how they work, not how their pages look. LilyPond's answer is the closest to Gourlay's, more literally than I'd realised. A spring in its spring.cc has an ideal length, a stretch, a compression and a minimum, and its length under a force is the larger of the minimum and the ideal plus the force times the flexibility: Hegazy and Gourlay's formula, prestretched springs included. By default a spring compresses by exactly its room above its minimum, which is the second option above, and a note's stretch is proportional to the space between bare noteheads, so the air stretches and the ink doesn't. In the bar with the half note and the thirty-seconds, the half note therefore takes most of any stretching and most of any compression, because it has most of the air. Durations are spaced from the most common shortest duration, each doubling adding a fixed increment of about a notehead's width, and each column takes the shortest duration sounding in it. MuseScore, in its current source, derives each note's natural width from its duration on a logarithmic curve: every doubling multiplies the space by a factor, 1.5 by default, starting from 3.5 stave spaces for a quarter. Where a collision demands more room, the extra is spread over the preceding notes rather than piled into one gap. When a system is justified, its notes act as springs whose stiffness comes from their durations, and a note already widened by a collision doesn't stretch until the force reaches it, which is the stretching half of Gourlay's model. Compression works differently: a system that is too wide is re-spaced with paddings and duration spacing reduced in steps, and as a last resort collisions are accepted. Bars are added to a system until the next one no longer fits at its natural width, and the system is then stretched to the margin, as its handbook also describes. Dorico's documentation says less about mechanism, but two things are on record. In 2015 Spreadbury described forming a column for every onset across all staves and giving it the value of the shortest note sounding there, the same raster as Ooloi's, and spreading surplus space as 'a tiny fraction of a space to each column', in contrast to the hand engraver's habit of giving it to the longest notes first. Its current layout options include a minimum space for short notes, which is the thirty-seconds' case, and a choice, when justifying, between 'actual widths', which count accidentals and dots, and 'ideal widths only', which count the notes. That last option is, in effect, the question of whether accidentals add space, offered to the user as a setting. None of it will be settled by argument. Ooloi's Vorbilder, the models it measures itself against, are printed pages from the great engraving houses, made by people who did this by hand for a living, and that's where the questions will be settled: on material chosen for where the 5% lives, such as chromatic passages, vocal scores heavy with lyrics, tight orchestral pages and parts with page turns. The measure is how many interventions it takes to reach the layout an engraver produced by hand. That number is the tax. And when I start showing pages from Ooloi, I'll set them beside printed music, never beside another program's output, however anonymised. Coda'Boxes & Glue' ended on a thought I hadn't finished: that the space after a whole note and the space after a sixteenth want different things, that each might have its own idea of how far it will stretch and how far it will give, and that this seemed very close to how a human engraver reasons about whitespace.
The thought is thirty-nine years old. Hegazy and Gourlay had it in 1987. They passed the springs through the boxes, gave each one a point beyond which it won't give, and solved the result exactly on a machine any modern thermostat would outrun. What they didn't have was a full score reduced to numbers that couldn't change underneath them. But that's exactly what I've spent the last two years building, mostly without realising that this was one of the things it was for. Something's been nagging at the edge of my mind. Knuth–Plass, the algorithm that breaks TeX's paragraphs into lines, has been adapted for music at least once, by Hegazy and Gourlay, and I ought to look at what they did. If there's prior art, so much the better: that's a strength, and something to build on.
For musicians, the underlying question is an old one: where should each system end? A score has to be cut into lines, and where the cuts fall decides whether the spacing is even, whether a crammed system sits next to a loose one, and where a page can be turned. The simplest method, and a common one, fills a system bar by bar, moves on when the next bar won't fit, and stretches whatever is there to the width of the page. It's quick, it never looks ahead, and it leaves the engraver forcing breaks by hand. Programmers call this greedy filling, and it doesn't produce optimal breaks. Knuth's algorithm, written for paragraphs of text, does the opposite: it weighs every possible set of breaks and picks the best. This matters because a player judges a page at a glance, before reading a note of it. And it's technical because that glance is decided here, in the model, long before anything is drawn. The questions were harder to settle than I'd expected. Was Hegazy and Gourlay's algorithm, and whatever descended from it, really Knuth–Plass, or something merely inspired by it or adapted from it? If adapted, was it still provably optimal, as the original is? And had the real algorithm ever been used to engrave music at all? The last question has the clearest answer: yes, in 1987. MuTeX, a master's thesis at Bonn by Andrea Steinbach and Angelika Schofer, set music with TeX's own glue and line breaking. The MusiXTeX manual later explained why that struggles: a line of text holds dozens of words and a system only a handful of bars, so the stretch piles up as gaps before the barlines. Hegazy and Gourlay's paper, from the same year, isn't online, so exactly what they did I can't say. What can be read is its descendant, described in ADR-0037. LilyPond's first line breaker, written ten years later, names their report in its source as its origin, and it's a dynamic program in Knuth–Plass's family. Later versions added a term for the evenness of consecutive systems, judged against a single stored predecessor, which makes the result an approximation of their own cost rather than its exact minimum. The other half of Ooloi's model, fixed space for clefs and signatures with one scale factor for everything else, is what Daniel Taupin, Ross Mitchell and Andreas Egler built into MusiXTeX in the mid-nineties. ADR-0037 now sets all of this out. Ooloi's own algorithm had been specified as Knuth–Plass from the start. What I hadn't expected was that it could be aligned with the original exactly. The atoms are the boxes, the spacing between them is the glue, and Ooloi's baseline is simply the case in which every piece of glue stretches in proportion to its natural width. So I aligned it fully, down to TeX's badness and demerits, with TeX's constants as starting points, and it's optimal in precisely Knuth's sense: the dynamic program finds the exact minimum of its own cost. That turned out to have real advantages. One of them I hadn't foreseen at all. Claude reasons far better about a forty-five-year-old algorithm, documented down to its last constant, than about anything bespoke. Once the cost had Knuth's shape, whole classes of question could be settled by reference instead of argument. None of this makes the algorithm Ooloi's; it's textbook, and the ADR says so. What Ooloi supplies is the conditions it needs. Knuth's algorithm wants stable inputs, and by the time Ooloi's pipeline reaches the breaking stage it has them, because information only flows forward. It's fast for a related reason: the earlier stages have already reduced the music to a very small set of numbers, a handful per bar, which are trivial to process even when the score runs to 800 pages and is set in Valhalla. The best layout can be recomputed while you type. For the person reading the part, the result should simply look right: systems evenly spaced from first to last, no cramped system beside a loose one, fewer breaks to force by hand. Stopping that layout from jumping about while you edit is a different problem, and the ADR deals with it in its own right. The glue has a further implication, one I haven't finished thinking through. The space after a whole note and the space after a sixteenth want different things. One is mostly air and can give a good deal in either direction. The other sits close to its neighbour: squeeze it and rhythm becomes collision, stretch it and a beamed group falls apart. Under the glue model the space after each note can have its own idea of how far it will stretch and how far it will give, and the two needn't match. The system then stops giving way in simple proportion, and if Knuth–Plass does what it should, the breaks are still optimal. That seems to me very close to how a human engraver reasons about whitespace. Creating a wind quintet with score and parts in Ooloi. Then adding doublings. No dialogs. Two years ago today, on 9 July 2024, the first commit to Ooloi went in. Time to take stock.
There's no music on screen. Two years in, and still not one printed note. No noteheads. No beams. No slurs. No page of music. All true, all planned, and all completely beside the point. Why? A notehead drawn in the first year would've been a comfort object, not evidence. So the visible surface stayed sparse on purpose while the real work went on underneath it. The absence of staves was never the interesting fact about this project. It was the cost of getting the interesting facts right, and this anniversary is the point at which they start becoming visible. This isn't an eccentric way to build notation software. It's how the serious ones are built, and the record is consistent. Sibelius took its two founders about seven years before the first release in 1993. MuseScore was carved out of a sequencer in 2002 and did not reach a stable 1.0 until 2011. Dorico, built by most of the old Sibelius team after they were let go, took close to four years and shipped its first version deliberately slow and incomplete, engine and engraving model first; the field judged the decision sound. Three programs, three decades, open source and commercial alike, and in every case the foundational years came before anything a user would recognise as finished. The counter-example proves the same point from the other side. Finale shipped fast in 1988, did more than anything before it, and became the industry standard for a generation. It was also, by wide agreement, punishing to use, and when its owners finally discontinued it in 2024 they said plainly that decades of accumulated code had made each new version harder to deliver and worth less. Feature piled on feature until the architecture could no longer move. That's the ceiling a notation program hits when the surface is built before the foundations are right. Two years isn't a long time to spend getting the foundations of a fifty-year program right, and I've never regarded it as a delay. Now, the bet on which Ooloi is built is functional programming. Music notation is a genuinely hard computer science problem wearing a friendly costume, and Clojure's properties looked to me like the right machinery for the parts of it that commercial programs have learned to manage rather than solve. Ooloi is my first Clojure project, though not my first Lisp by a long way, so the syntax was familiar ground; an old hand picks up a new dialect quickly. The deeper reorientation was immutability. Fully embracing immutable data structures, rather than merely tolerating them, changed how I thought about the whole domain, and almost everything architecturally distinctive about Ooloi fell out of that one shift. Undo, collaboration across machines, full use of multi-core parallelism, pervasive structural sharing: none of these is a feature bolted onto mutable objects. Each is a consequence of representing musical facts as immutable values. Learning to think that way was the real work of the first stretch. The harder part was psychological. A screenshot of notation would've been reassuring, and I could've produced something theatrical early on if theatre had been the goal. I grew up around theatre. I know a backdrop when I see one. I also know there's never a wall behind it. So the project spent a long time with most of its real work below the surface. The documentation was public, the ADRs were public, the blog was public, but the evidence still required reading. And the focus on the yet invisible might have given the impression that progress had been slow. So I drew up a list of what's been completed over the past two years. I expected it to be useful. I did not expect it to be quite so long. That surprised me, which is perhaps the point of doing the accounting at all. Daily work doesn't feel like accumulation. It feels like the next ticket, the next invariant, the next small refusal to leave a problem in a shape that'll charge interest later. Only when the pieces sit next to each other does the scale become visible:
During daily work, a subsystem closes and vanishes from attention. That's partly the method: finish something completely enough that it stops sharing the desk. The Instrument Library no longer asks to be designed. Localisation no longer asks to be invented, and the interface already speaks twenty-two locales. Undo no longer waits behind every future feature (with a small knife). Transport no longer converts itself through protobuf in-process for no reason. Window lifecycle no longer belongs to individual windows. Each closed subsystem removes one more thing from the cognitive field. The list makes visible what the surface hid. Ooloi hasn't spent two years waiting to become a notation program. It's spent two years removing the taxes a notation program would otherwise pay forever. This is also where the unusual working conditions matter. I've been ... unburdened by people. That sounds harsher than I mean it, though perhaps not by much. Not unburdened by readers, musicians, criticism or conversation, which have all mattered, but by the organisational forms that force software to explain itself before it has finished thinking. No investors, no release calendar, no committee, no inherited user base demanding that a workaround stay sacred because muscle memory has mistaken it for design. A team would have made some things faster and some things impossible, or at least premature. There's a stage in a project like this where the architecture has to be held whole in one mind, not because one mind is superior to several, but because dividing the thing too early changes the thing. Ooloi needed a period before that could happen. That period has had its own cost. Solitude removes obstruction, but it also removes alibis. Every accepted decision is mine. Every inconsistency in the documents is mine to catch. Every time Claude Code proposes a convenient shortcut, I have to know whether it's harmless, local, or the kind of thing that looks harmless now and grows teeth later. There's no one else to blame, which is excellent architecture and poor comfort. The AI has made the solitude more productive, though only because the architecture constrains it. Claude works best as an implementor inside settled boundaries. Give it one subsystem, clear invariants, failing tests, and a narrow target, and it moves with astonishing speed. Ask it to hold the whole system in its head at once, and it becomes what all of us become under those conditions: less intelligent than advertised. Every subsystem sealed below the musical floor is one fewer thing it has to juggle when the visible engraving work begins. That's another reason the long groundwork was worth doing. The cleared desk isn't a metaphor I use lightly. It's how the next phase becomes possible. The 3 June proof mattered because it compressed much of this into one modest action. Two laptops. One Ooloi hosting, one connected. A flute name changed on the guest, visible on the host. Undo on the host, reverting the guest's edit. The revert appearing on the guest. As cinema, it will not trouble Bergman. As architecture, it was the exact kind of evidence I had been waiting for. That little proof did not show engraving, and it did not pretend to. It showed authority, transport, shared state, invalidation, fetch, undo routing, and cross-machine propagation acting together without ceremony. Nearly two years of decisions appeared as a small correction to the name of a flute. Software milestones are sometimes like that: not fireworks, just a door opening without sticking because someone spent a very long time caring about the hinge. Now the work is moving towards the page. The custom picker is already visible and operable. It's not a native file chooser with new paint. It asks the backend what exists, receives opaque tokens, and never sees paths. Local storage and remote storage go through the same contract. The boring dialog is already the front edge of the piece model. Behind it, the piece window is now a live view of authoritative backend state, and this anniversary comes with a second small proof to show it. The video accompanying this post was recorded on two machines. On one, a wind quintet is assembled in a handful of gestures: flute, oboe, clarinet, horn, and bassoon dragged out of the Instrument Library into the Musicians panel of a shared piece window, each becoming a musician with its staves beneath it, and then dragged across into the Layouts panel to define the full score and the five individual parts. On the other machine, the same piece window answers. No delta is sent between them: a structural change names what is now stale, and the other screen refetches the canonical structure and redraws. It's the 3 June proof one storey higher. In June a flute changed its name and the plumbing held; here the same architecture carries piece structure rather than a library entry, edited collaboratively, with the invalidate–fetch–replace model the Instrument Library established generalising to the piece itself unchanged. And it's still, deliberately, not engraving. What crosses the wire and appears on the second screen is musical structure, not a rendered stave. There's no notehead in the video. The machinery that'll carry the music is running, and running across two machines, before the music arrives. Next come piece preferences and window persistence, the rest of the Piece Window arc. After that, MusicXML, because real scores must drive real notation work. Then Skija and the rendering pipeline. Then the noteheads: spacing, stems, flags, dots, accidentals, voices, collisions, beams, ties, slurs, hairpins, lyrics, pedalling, ottavas, tuplets, and the geometry of the page. The evidence will change again at that point. The collaboration you can already see in the video will still be there, but it'll be moving notation rather than structure. A slur will find space. A beam will sit, straddle, or hang. A note in a chord will change geometry around it. One screen will alter shared musical notation and another will answer with the same page. The program will make the argument in engraving, not only in structure. I'm looking forward to that more than I can sensibly say. Two years in, the thing that surprises me isn't that there's still no music on screen. I expected that. The noteheads were never beside the point as a goal, only as evidence; a program isn't proved by what it can draw first. The surprise is how much of the project is already behind the moment when music appears. The empty stave, seen from the surface, suggests absence. The inventory tells a different story: a great deal has already been decided, tested, closed, and made boring. Boring is underrated. Boring is what a foundation becomes when it's doing its job. So, coming out from the darkness that never really was, the next part will be visibly brighter, and with any luck it will involve fewer ... certificate files. |
AuthorPeter Bengtson – SearchArchives
November 2026
Categories
All
|
|
|
Ooloi is an open-source desktop music notation system for musicians who need stable, precise engraving and the freedom to notate complex music without workarounds. Scores and parts are handled consistently, remain responsive at scale, and support collaborative work without semantic compromise. They are not tied to proprietary formats or licensing.
Ooloi is currently under development. No release date has been announced.
|
RSS Feed