Drum machine

A six-sound drum machine: examples/audio/drum_machine.py.
python examples/audio/drum_machine.pyClick or drag on the step grid to write the beat, play each sound with its pad, and change the tempo and the swing with the knobs.
Why the timing is exact
Section titled “Why the timing is exact”The rhythm runs inside the engine, not in Python. A clock module ticks every sixteenth note
and drives one sequencer per row; each sequencer’s trigger strikes its drum:
clock = engine.add("clock", bpm=124, division="1/16")for sound in ("kick", "snare", "clap", "hihat", "hihat", "tom"): drum = engine.add("drum", sound=sound) seq = engine.add("sequencer", steps=16) engine.connect(clock, "clock", seq, "clock") engine.connect(seq, "trigger", drum, "trigger")So the beat stays on time however busy the window is. The grid only switches the sequencers’
gates (engine.set(seq, "gate_5", 1)), and the playhead reads the step they are on
(seq.state["step"]).