BEEP BOOP

An instrument in SwiftUI

Beep Boop is a drum machine drawn on glass. The app holds one picture, its icon. Every key, light and dial is drawn by code, in SwiftUI, from a handful of numbers.

Fig. 1
One step key from the front, three times life size, lit, with its measurements in points: a body 40 wide and 56 tall with a corner of 7, its light inside the cap; a moulded ridge 0.64 of the body's width, which lights orange on a key held to accent; and a foot 2 below the body.RIDGE, 0.64 OF THE WIDTHLIGHT, IN THE CAPBODY, 40 BY 56CORNER, 7FOOT, 2 BELOW
One step key, three times life size, lit, in the points the app draws it by. The light is inside the cap. Pressed, the body travels 1.5 points onto its foot.

The rule

The test for every screen is Dieter Rams's: as little design as possible, and what there is must be useful, understandable and honest. On a panel that becomes three working rules.

One orange, and only as light

The panel is paper white, with black ink and grey labels. The drums have one colour, an orange, and it is never paint. No word is orange. Orange appears only where something is lit: a step key glowing from inside its cap, the ridge of a key held to accent, the figures in the window. So orange always means the same thing, which is that this is live.

The rule has been bent twice, both times by the same test. SYNTH has its own light, a yellow, so a tune is never mistaken for a beat, and a pad struck live glows green. Each is a light and never a paint, and each means one thing.

The grey of the labels was chosen by measurement. It passes 4.5 to 1 against the body for small text. The first grey did not, and was changed.

A key is a few shapes and a light

Fig. 1 is one step key. In code it is a few shapes in a stack: a darker foot, 2 points below; the body, 40 points by 56 with a corner of 7; a moulded ridge across it, 0.64 of its width; and a light inside the cap, cut to the body's own outline. There is no image and no texture.

It has height because it travels. Pressed, the body moves down 1.5 points onto its foot in 40 milliseconds, and its shadow shortens. That is the whole press. A key that did more would be showing off, and a key that did less would not feel pressed.

The light is in the cap

A step that is on lights its own key, from inside, as a lamp under a silicone cap does. The light warms in 90 milliseconds and cools in 150. When the playhead passes a lit step, the flash lands at once, at the moment the step is heard, and cools over 100 milliseconds.

The numbers are different on purpose. Light that arrives late looks wrong against sound, so the flash does not fade in. Light that leaves slowly looks warm.

Hold a key for half a second and the step is accented: struck harder, with its ridge lit orange. The accent is a held key and not a second control, so the panel gains nothing to look at.

Labels are silkscreen

Most parts carry a mark, not a word. TEMPO, KEEP, PLAY, PRINT and SWING each have a small engraved glyph, so the row under the keys reads at a glance. Where a word is needed it is set as if printed on: uppercase, in a monospaced face, a noun or two. SOUND. KICK. 1 OF 8. A label names the part and stops.

The same key on every screen

The panel is drawn once, on a canvas of 402 points by 874, the size of the phone it was designed on. On another iPhone the whole canvas is fitted by one factor. On an iPad the parts move, whole, to new places, and are fitted by one factor again. A key is never stretched, so it is the same key everywhere.

Where SwiftUI stops

SwiftUI draws the panel. It does not take the touches. A SwiftUI button answers when the finger lifts, and a gesture waits a moment to see what kind of gesture it is. An instrument must sound when the finger lands. So a clear layer from UIKit sits over each drawn part and reports touch-down with the touch's own timestamp.

The sound is kept apart in the same way. The panel never touches the audio system, and the engine never imports the code that draws. They speak through one queue. The audio thread never waits has that side of it.

Sources

More sheets

  1. A kick drum is twelve numbersHow a drum machine's kit is built.
  2. How Beep Boop makes a soundTwo voices, TEAR, and one path out.
  3. The audio thread never waitsNo allocation, no lock, one queue.
  4. Every note in keyEight rows, one scale, no wrong notes.
  5. PatternsDrum patterns drawn on sixteen steps.
  6. Tempo by genreBPM for twelve genres, on one scale.