Monostep Sequencer
Created on 2020-08-25T06:17:49.660609
- A list of hit or no-hits
- On a step check if there is a hit; if yes then trigger the sound.
This is the most basic kind of sequencer you can make.
type Monostep* = object steps: seq[bool] at: int note: MidiNote channel: MidiChannel proc step*(self: var Monostep; feed: var seq[MidiMessage]) = # we always turn the note off feed.add(MidiMessage(kind: Note, note: self.note, channel: self.channel, velocity: 0)) # advance the play head self.at = (self.at + 1) mod self.steps.len.int # we might trigger the note if self.steps[self.at]: feed.add(MidiMessage(kind: Note, note: self.note, channel: self.channel, velocity: 127))
To behave more like a traditional tracker, add a hot bit to Monostep:
hot: bool
Now we only emit a note ON on a beat, an OFF on a rest, and nothing otherwise:
proc step*(self: var Monostep; feed: var seq[MidiMessage]) = # advance the play head self.at = (self.at + 1) mod self.steps.len.int # we might trigger the note if self.steps[self.at]: feed.add(MidiMessage(kind: Note, note: self.note, channel: self.channel, velocity: 127)) self.hot = true else: if self.hot: feed.add(MidiMessage(kind: Note, note: self.note, channel: self.channel, velocity: 0)) self.hot = false