BEEP BOOP
Public beta

An instrument in SwiftUI

Beep Boop is a drum machine drawn on glass. The app holds one picture, its icon. Every key, lamp and dial is drawn by code, in SwiftUI, from a handful of numbers. This is how the panel is made, and the rules it is made by.

Fig. 1
One step key from the front, three times life size, with its measurements in points: a lamp 9 across, 8 above the key; a body 40 wide and 56 tall with a corner of 7; a moulded ridge 0.64 of the body's width; a foot 2 below the body; and a travel of 1.5 when pressed.LAMP, 9 ACROSS8 ABOVE THE KEYRIDGE, 0.64 OF THE WIDTHBODY, 40 BY 56CORNER, 7FOOT, 2 BELOWTRAVEL 1.5
One step key, three times life size, in the points the app draws it by. 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 and no key is orange. Orange appears only where something is lit: a lamp over a step that is on, 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. The SYNTH bench 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 three shapes

Fig. 1 is one step key. In code it is three shapes in a stack: a darker foot, 2 points below; the body, 40 points by 56 with a corner of 7; and a moulded ridge across it, 0.64 of its width. 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.

A lamp is a filament behind glass

The lamp above each key is 9 points across. The dark glass is always drawn. The lit state is a second layer laid over it and faded in, so a lamp warms in 90 milliseconds and cools in 150, as a small bulb behind smoked glass does. 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.

Labels are silkscreen

Every word on the panel is set as if printed on it: uppercase, in a monospaced face, a noun or two. TEMPO. SWING. PLAY. A label names the part and stops. Nothing on the panel is a sentence, and nothing asks a question.

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.

The key, pulled apart

The front page draws this same key in its five layers, foot, body, lip, glass and light, and presses it as the page scrolls.

Sources

More sheets

  1. A kick drum is twelve numbersHow a drum machine's kit is built.
  2. The audio thread never waitsNo allocation, no lock, one queue.
  3. Sample-accurate timing on an iPhoneSteps counted in samples, and how that was measured.
  4. A beat in 40 bytesTempo, swing, eight voices and a check byte.
  5. PatternsDrum patterns drawn on sixteen steps.
  6. Tempo by genreBPM for twelve genres, on one scale.