[MusicTools dev note] Half-Page Turns in Play Order: The Half You're Reading Never Moves
MusicTools 1.6.1 turns sheet music by half pages: whole lines in the order you play them, repeats and all, so you always have half a page to turn in.

A page turn asks for two things at once: the last bar of one page and the first bar of the next. Turning by half pages splits that moment in two. While you play the bottom of the screen, the top already shows what comes next, so the next music is there before you need it.
MusicTools has turned pages by halves since version 1.4. In 1.6.1 I rebuilt how it does it, after a lead sheet showed me that the old way could leave a player one line to turn in.
What went wrong: one line to turn in
The first version worked page by page. Each page was divided at a gap between two of its lines, and a turn brought in the top part of the next page above the part being played. With Follow Song Form on, MusicTools turns in the order the music is played, so a repeat brought the line it goes back to in at the top of the screen. (How that order is worked out from repeats, endings, D.S. and Fine is for another post.)
Each of those steps made sense on its own. But where a page was divided depended on the page, and a jump could land anywhere on it. Playing a lead sheet from my ensemble (I can’t show it here: the arrangement isn’t mine), I came to a screen where the part coming in was a single line, and the rest of that half was blank. That’s fine when the line ends in a repeat sign and the music goes on somewhere else. On that screen it didn’t. One line was all the time there was to turn. The division also followed the staff lines, so chord symbols printed above a staff could peek over it.
Showing just the one or two lines that matter can look clever. Halves that are always full are more useful. So the rule became simpler.
The new rule: a line that never moves, and whole lines in play order
- The screen is two halves that meet at one line, and that line never moves. It’s set once, when the sheet opens: the gap between two lines of the page it opens on that’s nearest the middle of the screen, if one is within 15% of the screen’s height from it, otherwise the middle. That way the first screen looks just like the printed page.
- The music is the lines in the order they’re played, one under another. A repeat back to line 3 just means that line 3 comes next.
- Each half takes as many of the next lines as fit, whole lines only. A line is its band of the page, from halfway across the gap above it to halfway across the gap below. The chord symbols, lyrics or brackets printed around it go with it.
- A turn swaps the half you’ve just played for the next lines. You read top, bottom, top, bottom. The half you’re reading never moves, and the next half arrives while you’re still reading the other one, so there’s always a whole half to turn in, never just a line.
A line you come to by a jump says so at its top, with a tag like “repeat → bar 18”. The bars of a line that aren’t played this time, like a first ending on the way through for the second time, are dimmed. If a single line is taller than half the screen, MusicTools turns whole pages instead. And if a page’s lines aren’t known, its halves are simply its top and its bottom.
The core of it is short. Here are the lines cut into halves, a little simplified from the app’s turnPlan.ts (in the app, the first half sits where it’s printed on the page rather than at the top):
// The lines in the order they're played, cut into halves: top, bottom, top…
for (const line of strip) {
const height = (line.to - line.from) * pageHeight;
if (halves.length === 0 || y + height > limit) {
const inTop = halves.length % 2 === 0;
y = inTop ? 0 : boundary;
limit = inTop ? boundary : screenHeight;
if (y + height > limit) return null; // taller than a half: turn whole pages
halves.push([]);
}
halves[halves.length - 1].push({ ...line, y });
y += height;
}
The turns are one line of arithmetic each. At turn i you’re playing half i, and the other half of the screen shows half i + 1:
const top = halves[2 * Math.floor((i + 1) / 2)]; // halves 0, 2, 2, 4, 4…
const bottom = halves[2 * Math.floor(i / 2) + 1]; // halves 1, 1, 3, 3, 5…
Here’s Bach’s chorale “Aus meines Herzens Grunde” (BWV 269) by half pages. Its first line is repeated, so it comes twice, the second time with a tag, and the whole chorale reads from top to bottom with no jump back up.

The plan is pure TypeScript, unit-tested on made-up pages whose lines are known. I checked the real screens on an Android tablet emulator with the lead sheet that started all this: four screens, each turn changing only the half that had been played, a tag wherever a jump lands and the skipped bar dimmed.
Also in 1.6.1: page turning set for each song
Follow Song Form, Turn by (Whole Page or Half Page) and Turn Pages by Face used to be one setting for the whole app. But a lead sheet full of repeats wants half pages in play order, while a sonata may be better turned a whole page at a time. Now each song keeps its own.
Open Settings over a song, and the Page Turning section names the song it’s changing. Open it with no song open, and you set the defaults for songs that haven’t set their own. The defaults start out as the old app-wide values, so nothing changes for anyone until they change a song. Turn Pages by Face has no default: it’s off until you set a song to it. The settings are kept with the song, so a backup or a shared setlist takes them along.

Face gestures took one more thought. MusicTools promises that the camera stays off until you turn it on, and goes off again every time the app starts. So a song set to turn by face can’t simply switch the camera on when it opens. The first time you open one after starting the app, it asks: “Turn pages by face?”, with Turn On and Not Now. (How a wink turns a page is in an earlier post.)
Also in 1.6.1: the metronome carries on through a setlist
In a setlist, moving on to the next song used to stop the metronome. Now, if it’s running, it carries on into the next song at that song’s tempo and meter. That works with the next-song button, the setlist menu, and turning past the last page.
The bug to avoid was in the cleanup. Each click sound has one engine, shared by every screen that uses it. When the next song opens, its screen starts the engine. Then the old screen goes away and runs its cleanup, which used to turn the engine off, under the new song’s clicks. So the engine now remembers which screen is driving it, and a screen that’s going away only turns it off if it still is:
const playing = new WeakMap<object, object>();
/** Whether the screen `who` may turn the shared engine off as it goes away. */
export function mayLetGo(engine: object, who: object): boolean {
const owner = playing.get(engine);
if (owner !== undefined && owner !== who) return false; // another screen has it now
playing.delete(engine);
return true;
}
All three are in MusicTools 1.6.1, on its way to the App Store.
MusicTools dev note
All episodes 8 so far
The metronome
Getting the score in
Turning pages hands-free
- Half-Page Turns in Play Order: The Half You're Reading Never Moves you're reading this
- Turning Pages with a Wink: ARKit on iPad, MediaPipe on Android
Sound: tuner, recording and analysis
Extras: notes from my dev setup


