SonicFrame v1.3.2

Zoom and scroll

Get close to a word, or across an hour. Every way of moving the view has its own switch; with zoom off, nothing changes.

Loading the sound…

Try it

Ways to move
Extras

Turning it on

Zoom is off by default. zoom: true gives the frame a view of the sound and its methods; each way of moving the view has its own switch, so a page turns on exactly what it wants. Without zoom nothing changes, not even the cost.

new SonicFrame({
    container,
    media,
    peaks: () => loadWaveform('/episode.dat'),
    zoom: { wheel: true, scroll: true, pinch: true, keys: true, follow: true, edgeScroll: true },
    a11y: { zoom: { announce: true } },
});

a11y.zoom.announce says the new view after a zoom by the keys, a button or two fingers ("Zoom 4×, 0:25 to 0:50"). a11y.zoom.words.view puts it in your own words: a phrase with {level}, {from} and {to}, or a function (level, from, to) => string.

a11y: {
    zoom: { announce: true, words: { view: 'Zoom {level}: {from} to {to}' } },
},

Options

Option Default What it does
view the whole sound The view at the start, { start, end } as ratios.
max one peak per bar The largest zoom, from 1 to 10,000 (100 without peaks).
step 2 How much one key or button zooms.
anchor 'position' Keys and buttons zoom around the playing position (when in view) or the 'center'.
wheel false The wheel zooms around the pointer; a touchpad pinch arrives as a wheel with Ctrl.
wheelModifier 'ctrl' The key held for the wheel to zoom: 'ctrl' (Ctrl or ⌘), 'alt' or 'none'.
wheelSpeed 1 How fast the wheel zooms, from 0.1 to 10.
scroll false The sideways wheel, a touchpad swipe and Shift + wheel scroll the view.
pinch false Two fingers zoom and drag the view.
keys false true gives +, - and 0; { in, out, reset } sets your own.
follow false While playing, the view follows the position.
followType 'page' 'page' turns a whole view; 'center' keeps the position in the middle.
followHold true A scroll or zoom by the person holds the following until the next seek or play.
edgeScroll false Dragging near an edge scrolls the view, so a selection can grow past the screen.
edgeSize, edgeSpeed 32, 1 The edge zone (CSS pixels) and views scrolled per second there.
revealKeys true A keyboard seek outside the view brings the view to it.

From code

frame.zoomTo(4); // 4× around the anchor
frame.zoomBy(2, 0.5); // twice as close, around the middle
frame.setView(0.25, 0.5); // show the second quarter
frame.scrollTo(0.6); // move the view, keeping its size
frame.on('viewchange', (view, source) => console.log(view.level, source));

view is { start, end, level, maxLevel }. The bars come from a pyramid of the peaks built the first time the frame zooms in, so the cost follows the screen, not the file, and each bar stays on the same piece of sound while the view scrolls. Give a long sound many peaks (a .dat file, or the player's decode.peaksPerSecond) for detail up close.

On the player, zoom: { buttons: true } adds zoom out, the whole sound and zoom in; see Parts and layouts. Plugins follow the view on their own: regions, markers, the timeline (down to tenths of a second), the silences' shade and the spectrogram.

Gestures and keys

  • Ctrl + wheel zooms around the pointer
  • Shift + wheel, or a sideways swipe, scrolls
  • + - 0 on the focused wave
  • Two fingers pinch and pan on a touch screen
  • Drag the box in the strip below to move the view
  • Shift + drag past the edge draws a region and the view follows

In code

import { createPlayer } from 'sonicframe/player';

createPlayer({
    container: document.querySelector('#zoom-buttons'),
    src: './sounds/little-elf.mp3',
    zoom: { wheel: true, keys: true, pinch: true, buttons: true },
    minimap: true,
    a11y: { zoom: { announce: true }, minimap: { keys: true } },
});