keyboard - Melodic sequencer for a given intrument node.
Inputs:
instrument [STRING] [REQUIRED]: the instrument node, a module available in the current scope (previously imported if necessary), exporting at least the following inputs: frequency, velocity, sustain.
bpm [FLOAT] [REQUIRED]: tempo in beats per minute.
divs [FLOAT] [OPTIONAL]: number of subdivisions in a beat.
file [STRING] [REQUIRED]: input melody file, see manual for format.
Outputs:
out [BUFFER]: output buffer, full sequence, sampled at 44100Hz.
This node takes a SNDC module which models an instrument, and uses an external score file to generate a melody.
Instrument
module
The given module name in instrument must be a module
available in the current scope, that you could otherwise
instantiate as a node. If it is not a built-in module, it
must be imported first in the same file.
To model an instrument, a SNDC module must export the following inputs:
frequency [FLOAT]: fundamental frequency of the note to be played.
velocity [FLOAT]: the strength of the note, how "hard" the key was pressed.
sustain [FLOAT]: the length of the note, how long the key is pressed.
It must also have the following outputs:
out [FLOAT]: the output buffer.
The instrument module is free to interpret those parameters as it sees fit.
Score
file
SNDC uses its own format for scores, SNDK. Unlike MIDI, this
format is designed to be easily editable with a text editor
or generated by an external program.
It contains one note per line, in the following format:
<beat>:<div> <pitch> <velocity> <sustain>
<beat> is the number of the beat counting from the beginning of the score, <div> is the number of the sub division of the beat, starting from 0. <pitch> is the pitch of the note, in the format [ABDCEFG][b#]?[0-8]. <velocity> is a positive float, 1. being considered "normal". <sustain> is a positive float and given in beat, so 1. = 1 full beat, 0.5 = half a beat, etc.
Note that the order at which the notes appear in the file doesn’t matter, you can of course append several notes at the same time code to make chords.
A simple
instrument module
The following SNDC code is the simplest instrument, using a
simple sinusoidal generator.
export input
base.duration as sustain;
export input base.freq as frequency;
export input base.amplitude as velocity;
export output base.out as out;
base: osc {
function: "sin";
duration: 1;
freq: 440;
}
A simple
score
The following SNDK file will play the famous Seven Nation
Army bass riff:
0:0 E5 0.8 1.5
1:2 E5 0.8 1
2:0 G5 0.8 0.6
2:3 E5 0.8 0.8
3:2 D5 0.8 0.8
4:0 C5 0.8 2
6:0 B4 0.8 2
A simple use
of the keyboard module
import "./simple.sndc" as simple;
k: keyboard {
instrument: "simple";
bpm: 120;
divs: 4;
file: "score.sndk";
}