INSTRUMENT is a library for livecoding music (beats, basslines, harmony, looping, FX, signal routing, synthesis, etc.) and interfacing with musical instruments and controllers from inside the SuperCollider environment.
Timing is event-scheduled with sub-millisecond OSC bundling — no polling loops, no beat-detection jitter. Each pattern track runs its own Routine on a shared TempoClock with server.makeBundle timestamping for sub-millisecond precision (~0.2-1ms, below the human perception threshold).
// Create a beat
// First, boot server:
s.options.memSize=2048*1024;
s.options.maxNodes=128*1024;
s.boot;
// Then, evaluate following block
(
i = INSTRUMENT.new(s);
d = i.synths.drums.electro;
i.drums=(
k: d.kick,
h: d.hihat,
s: d.snare,
);
i.drums.k.seq("1 1 1 1 ").speed(2);
i.drums.h.seq("1");
i.drums.s[0].seq(" 1 1 1 1 1").speed(2).do(3);
i.drums.s[1].seq(" 1x4 1 1x2 1").speed(2).do(1);
i.drums.clock=4;
i.tempo = 150;
)
// Wait a while and then run this block:
(
i.drums.clock=1.5;
i.drums.fx='reverb.large';
)
// Return to first beat, with new FX
(
i.drums.clock=4;
i.drums.fx="gateDistortion.hardcore";
)
// change group
i.drums=(
// k: d.kick,
h: 'snareNeuro',
s: d.snare,
);
// run this
(
i.drums.fx='reverb.infinite';
i.drums.fx.reverb.wet=1/2;
)
// now this
(
i.drums.fx.reverb.wet=1;
i.drums.stop;
)
(
i = INSTRUMENT();
i.drums = (
kick: 'kick',
hihat: 'hihat',
clap: 'clap'
);
i.drums.kick.seq("1");
i.drums.hihat.seq(" 1").speed(2);
i.drums.clap.seq(" 1");
i.drums.clock = 2;
)
INSTRUMENT is now publicly available as an pre-alpha release.
Please try this tool and get in touch.
Expect turbulence in this repository while this test phase evolves.
This tool is aimed at the creation of musical compositions from scratch, 'on the fly'. INSTRUMENT focuses on musical language: rhythm, harmony, melody, audio processing.
INSTRUMENT also enables the connection of MIDI controllers with an easy interface that facilitates its mapping to different sound parameters.
The name is inspired by Fugazi.
INSTRUMENT is a voluntary independent open source initiative operating from the Mexican live coding underground
For questions, inquiries, help, or fun conversations, please contact me at [email protected].
- Full Documentation + Tutorial coming soon.
- INSTRUMENT is in pre-alpha phase. The API is subject to change in the near future.
- Figure out your Supercollider Extensions folder path. You can find this inside SuperCollider environment, by running the following command:
Platform.userExtensionDir;
-
To install INSTRUMENT, theres two possible ways:
- Using git, clone the repo inside your 'Extensions/' folder
- or download the .zip file and place it inside the 'Extensions/' folder. Make sure the folder's name is INSTRUMENT. (Downloading from this repo creates a folder named INSTRUMENT-main. Please rename it to INSTRUMENT)
-
Restart or Recompile SuperCollider.
-
Verify installation. Type:
i=INSTRUMENT();
to see if the Library was successfully added.
(
// useful snippet for increasing default memory
s.options.memSize=2048*1024;
s.options.maxNodes=128*1024;
s.boot;
)
Most things related with INSTRUMENT are accessed through a single intance.
You will normally begin by typing and evaluating the following line:
i = INSTRUMENT();
This line will be repeated throughout this document, so any individual fragment can be tried in isolation.
INSTRUMENT comes with some predefined SynthDefs that you can use.
See Synthesizers, at the end of this document, for more info about working with Synths, Effects, and the automatic synth loader.
If you want to add your own, see Loading more Synths
i=INSTRUMENT();
// list all preloaded synths:
i.synths.list;
i.synths.kick.simple;
i.kick=i.synths.kick.choose;
i.kick.seq("1 1").speed(4);
i=INSTRUMENT();
// creates a dictionary inside **i.synths**
// access by name
i.kick= "kick";
i.kick.seq("1").speed(2);
// use the dictionary
i.kick='kick';
// replace sounds
i.kick='hihat';
// access by index
i.kick=i.synths.drums.kick[0];
i.kick=i.synths.drums.kick[1];
i.kick=i.synths.drums.kick[2];
i.kick=i.synths.drums.kick[3];
// index wraps around total synths number inside folder
i.kick=i.synths.drums.kick[99999];
// access randomly
i.kick=i.synths.drums.kick.choose;
i.kick=i.synths.drums.kick.choose;
i.kick=i.synths.drums.snare.choose;
i.kick=i.synths.drums.snare.choose;
// long vs short synth routes are equivalent:
i.synths.percussion.drums.kick[3] == i.synths.kick[3]
// each synth gets added to root folder
i.synths.bass.simpleBass == i.synths.simpleBass;
i=INSTRUMENT();
i.kick= i.synths.kick.deep;
i.kick.seq("1");
// equivalent syntax:
i.kick.seq = "1";
// trigger synths with different amp values:
i.kick.seq("1 0.3 0.75 2");
i.kick.seq([1, 0.3, 0.75, 2]);
i.kick.stop;
// Press Ctrl/Cmd + . to stop the server
.seq method allows to sequence any parameter. In previous example, the default parameter 'trigger' is being automatically passed.
There are shorthands 'seq' methods for some common parameters, some of them:
- trigger
- note
- chord
- vol
- pan
- fx
- fxSet
Lets pass a different parameter, note.
i=INSTRUMENT();
i.bass=i.synths.trance.choose;
i.bass.seq(\note, "0 2 3 5");
// shorthand:
i.bass.note("0 2 3 5");
i.bass.note = "0 2 3 5";
i=INSTRUMENT();
i.bass=i.synths.trance.choose;
i.bass.note("0 2 3 5");
// microtonality
i.bass.note("0 2.25 3.75 5");
// you can also use note names:
i.bass.note("C D Eb F D# D").speed(4);
// you can choose octaves
i.bass.note("C3 D4 Eb5 F6");
// a more complex bassline
i.bass.note = "C3 Db3 C4 C3 :1.5 Db3x2 :1/2 Bb2x2 ";
i.bass.clock=4;
i.bass.amp=2;
When sequencing notes, you can use amplitude and release time modifiers
i=INSTRUMENT();
i.bass=i.synths.trance[0];
i.bass.note = "0 2< 3> 5<< 7>> 8<<< 10>>> 12<<<<";
// equivalent:
i.bass.note = "0 2< 3> 5<2 7>2 8<3 10>3 12<4";
i.bass.note = "0 (3 5)>>>> (7 8)<<<<";
// equivalent:
i.bass.note = "0 (3 5)>4. (7 8)<4";
i=INSTRUMENT();
i.piano=i.synths.piano[0];
i.piano.note = "0 2p 3f 5pp 7ff 8ppp 10fff 12ffff";
i.bass.note = "0 (3 5)ppp (7 8)fff";
// equivalent:
i.bass.note = "0 (3 5)p3 (7 8)f3";
(
i=INSTRUMENT();
i.bass=i.synths.trance.choose;
i.bass.note("0 2 3 7");
i.bass.note("C D Eb G");
i.bass.octave=4;
i.bass.octave=3;
i.bass.octave=5;
i.bass.octave=6;
)
i = INSTRUMENT();
i.bass=i.synths.trance.choose;
i.chords = i.synths.note.dist;
i.chords.octave=5;
// use comma to join notes in a chord (no spaces!):
i.chords.note("C,Eb,G,Bb F,A,C5,Eb D,F,A,C Bb,D5,F5,A ");
// alternate chords and single notes
i.chords.note("5 3 C,Eb,G,Bb 5 7 F,A,C5,Eb 2 5 D,F,A,C 7 10 Bb,D5,F5,A ").speed(4);
Class 'C' is an alias for 'I8TChord': C( interval, chordtype/chordarray, inversion, additional );
i = INSTRUMENT();
i.chords = i.synths.note.dist;
i.chords.note([
C(0,\m),
C(7,\M,1),
C(3,\Mmaj7),
C(1,\m,0,[16])
]).speed(1/2);
(
i = INSTRUMENT();
i.chords = i.synths.note.dist;
i.chords[0].note([
C(0,\m),
C(1,\M,0,[16]),
]).speed(1/2).do(2);
i.chords[1].note([
C(0,\m),
C(3,\sus2),
C(2,\dim),
C(7,\M)
]).speed(1/2).do(3);
)
(
i = INSTRUMENT();
i.chords = i.synths.pad.dist;
i.chords.note([
C(0,\M),
C(0,\m),
C(0,\M7),
C(0,\m7),
C(0,\dim),
C(0,\aug),
C(0,\Mmaj7),
C(0,\mmaj7),
C(0,\M9),
C(0,\M9m),
C(0,\m9),
C(0,\m9m),
C(0,\sus2),
C(0,\sus4),
// custom chord type
C(0,[6,10,15]),
]).speed(1/2);
)
INSTRUMENT has a global key and scale, which instruments and groups can override. Nothing changes until you set one: the default key is C, so existing patches sound exactly the same.
i.key = 'Dm'; // D minor (aeolian): root and mode
i.key = 'D'; // a bare root means major
i.scale = \dorian; // change only the mode, keep the root -> D dorian
i.key = 'D dorian'; // root + mode in one go; also 'D_dorian' or \d_dorian
i.scale = Scale.hijazKar; // any SC Scale object or Scale name
i.scale = [0, 2, 3, 7, 8]; // a custom scale (semitones above the root)
i.key = nil; // back to C major (unset)
i.key; // -> I8TScale(D dorian)Accepted keys: 'C', 'Dm', 'F#m', 'Bb', 'Ebmaj', 'A minor', 'D dorian', 'D_dorian', \d_dorian, and any name in Scale.names. scale and key are reserved: you can't name an instrument i.scale or i.key.
The key root moves numeric notes. Note names stay absolute:
i.key = 'D';
i.bass.note("0 4 7"); // D F# A (numbers + 2)
i.bass.note("C Eb G"); // C Eb G (names don't move).degree plays scale degrees through the current scale. Degrees are 0-based: 0 is the root.
i.key = 'Dm';
i.bass.degree("0 2 4 7"); // D F A D5
i.bass.degree("-1 0 7 14"); // below the root, root, one octave up, two octaves up
i.bass.degree("2b 3# 6bb"); // accidentals are suffixes: b lowers, # raises
i.bass.degree("0,2,4 3,5,7"); // degree chords (comma, no spaces)
i.bass.degree([0, 2, 4]); // arrays work too
i.bass.degree("0 2.5 4"); // decimals move between neighbouring steps (microtonal)
i.bass.degree("0 2 4").transport(1); // diatonic transposition; accidentals are keptPast the end of the scale, degrees wrap up an octave (7 in a 7-note scale, 5 in a pentatonic). Negative degrees go down. Note names inside a degree pattern stay absolute.
i.key = 'Dm';
i.bass.scale = \phrygian; // own mode, global root: D phrygian. Follows i.key changes
i.lead.key = 'F'; // own root + mode: F major. Ignores i.key
i.lead.key = nil; // inherit the global key again
i.voices.key = 'G'; // a group pushes its key to every member (like .octave)A mode name on a scale converts degrees into frozen semitones above the current root. Use the result with .note, which adds the key:
i.scale.dorian([0, 1, 3]); // -> [0, 2, 5]
i.bass.note(i.scale.dorian([0, 1, 3, 4]));
i.scale.dorian; // no argument: the current root with that mode, as a scalei.key = 'C';
// roman numerals, in .chord, .note or .degree strings ...
i.pad.chord("ii7 V7 I:2");
i.pad.chord("I vi IV V7 bVII IV I");
i.pad.chord("V7/V V7 I"); // applied chord
i.pad.chord("I^1 IV^2 V7^3 I"); // ^n = inversion
// ... or as C(...)
i.pad.note([C(\ii), C(\V7, 1), C(\I)]);
// diatonic chords by degree: stacked thirds in the current scale
i.pad.note([i.scale.chord(1), i.scale.chord(4, 4), i.scale.chord(0, 3, 1)]);
// chord(degree, size = 3 (triad), 4 (7th), 5 (9th); inversion; add: extra scale steps above the root)
i.scale.chord(0, 3, 0, [8]); // triad + 9thRoman numerals and i.scale.chord(...) are resolved when they play, so they follow key changes. C(0,\m) and the other plain chords are note numbers, and they move with the key like any .note number.
Supported roman numerals:
| part | meaning |
|---|---|
I II III IV V VI VII / i ii ... |
the scale degree. UPPER case = major third, lower case = minor third |
b, # before the numeral |
lower or raise the root by a semitone (bVII, bVI, #ivo) |
| (nothing) | triad |
7 |
minor 7th on top: V7 = dominant, ii7 = minor 7th |
maj7, M7 |
major 7th (Imaj7, IVM7) |
m, m7, M |
force a minor or major triad / minor 7th |
o, dim / o7, dim7 |
diminished triad / diminished 7th (viio, viio7) |
ø, ø7, m7b5 |
half-diminished (viiø7, viim7b5) |
+, aug, +7 |
augmented / augmented 7th |
9, maj9 |
9th chords |
sus2, sus4, sus, 7sus4 |
suspended |
^1, ^2, ... |
inversion |
X/Y |
applied chord: X of the major key on Y (V7/V, viio7/ii). IV/V therefore means IV of V (= I), not F over G |
The root is the scale's degree, so in A minor III is C and VII is G. The quality comes from the case and the suffix: V7 in A minor is E7. Chords are voiced in close position from the root, without doubling. Roman numerals are meant for 7-note scales.
Key changes apply immediately, from the next note. Keys can also be sequenced:
// per instrument (like \octave)
i.bass.seq(\key, "Dm:2 G C F");
i.bass.seq(\scale, ['D dorian', 'D phrygian']);
// global key progression: every instrument without its own key follows it
i.seq(\key, "Dm:2 Gm:2 C F").speed(1/4);
i.conductor.rm(\key); // remove it (i.conductor.stop / .play too)Inside pattern strings, p, f and x are pattern operators. Write mode names that contain them (phrygian, mixolydian, minorPentatonic), and lower-case f roots, as an array: ['F#m', 'E phrygian'].
counterpoint, harmonize and cantus use, in order: their own scale:/key: arguments, then the instrument's or group's scale, then the global key, and only then infer the mode from the melody. When a track is used as the melody, it is read as it sounds (key and degrees included). Results sent to an instrument compensate for its key.
You can add some probability for a certain event using the '?' operator:
i = INSTRUMENT();
i.bass = i.synths.bass.dist;
// 50% probability is the default value
i.bass[0].note = "0 3? 5";
// 10% probability
i.bass[1].note = "12 15?0.1 17";
// 90% probability
i.bass[2].note = "14 18?0.9 20";
// 40% probability applied to each event in a group of events
i.bass.note = "14 (18 20)?0.4 8";
You can have a value be chosen between two options with the '|' operator:
// 50% probability of choosing D or F
i.bass.note = "C D|F";
The '%' operator distributes hits evenly across a number of slots using the Euclidean/Bjorklund algorithm.
Syntax: value%hits/steps
i = INSTRUMENT();
i.kick = 'kick';
// 3 kicks spread across 8 slots: [x . . x . . x .]
i.kick.seq("1%3/8");
// a regular kick followed by a euclidean pattern with lower amplitude
i.kick.seq("1 0.5%3/8");
// 5 hits in 8 slots: [x . x x . x x .]
i.kick.seq("1%5/8");
You can also apply it to subsequences. The values inside cycle across the hit positions:
// 3 hits in 8 slots, cycling through amplitudes [1, 0.3, 2]
i.kick.seq("(1 0.3 2)%3/8");
// if count doesn't match, values wrap: 2 values across 3 hits
// hits get: 0.8, 0.4, 0.8
i.kick.seq("(0.8 0.4)%3/8");
// combine with other operators
i.kick.seq("(1 0.5 0.8)%3/8:0.5");
Add swing/groove feel by shifting off-beat events later in time. The stored pattern data stays clean -- shuffle is applied at runtime so it can be tweaked live.
i = INSTRUMENT();
i.kick = 'kick';
i.kick.seq("1").speed(2);
// add shuffle (0 = straight, higher = more swing)
i.kick.shuffle(0.3);
// triplet feel
i.kick.shuffle(0.5);
// 16th-note shuffle (custom grid resolution)
i.kick.shuffle(0.5, 0.25);
// reset to straight
i.kick.shuffle(0);
Shuffle works on any instrument or group:
i.drums = (
kick: 'kick',
hihat: 'hihat',
snare: 'snare',
);
i.drums.kick.seq("1").speed(2);
i.drums.hihat.seq(" 1").speed(4);
// shuffle the whole group
i.drums.shuffle(0.3);
i=INSTRUMENT();
i.kick="kick";
i.kick.seq = "1 1";
i.kick.speed(8)
i.tempo=180;
i.tempo=140;
i.tempo=120;
i.tempo=220;
i.tempo=400;
i.tempo is in quarter-note BPM: one clock beat is one quarter note, and a step of duration 1 is one beat. A fresh session starts at 120 BPM (i.clock.tempo is 2 beats per second).
Migrating (tempo): earlier versions counted i.tempo in half notes (clock.tempo = bpm / 120), so a set written before this change plays twice as fast at the same number. Halve its tempo values to keep its sound (i.tempo = 140 becomes i.tempo = 70); everything counted in beats (bars, patterns, go, every) is unchanged.
i=INSTRUMENT();
i.kick="kick";
i.kick.seq("1 0.5").speed(4);
i=INSTRUMENT();
i.kick="kick";
i.kick.seq("1 0.5").speed(4);
i.kick.amp=1/2;
i.kick.amp=3/4;
i.kick.amp=1;
i.kick.amp=2;
i.kick.amp=2;
i.kick.clock=2;
i.kick.clock=8;
The 'x' operator inside string Patterns allow for repetition of last value
(
i=INSTRUMENT();
i.piano=i.synths.piano;
i.piano.amp=4;
i.piano.clock=2;
i.piano.note("0xx 2xxx 3xxxxx");
i.piano.note("0x2 2x3 3x5");
// get last pattern duration:
i.piano.duration;
i.kick='kick';
// repeat three times
i.kick.seq("1 0.5x3");
i.kick.duration;
// lazy equivalent
i.kick.seq("1 0.5xxx");
// clear patterns
i.kick.rm(\trigger);
)
(
i=INSTRUMENT();
i.kick='kick';
i.kick[0].seq("1");
i.kick[1].seq("1 1");
i.kick[2].seq("1x14 ").speed(16).x(1);
i.kick.seq("1x4 :0.5 1x8 :0.25 1x16 :0.125 1x32");
// add some silences
i.kick.seq("1x5 :0.25 1 1x3 1 1x3");
// check duration
i.kick.duration;
i.bass=i.synths.bass.trance[2];
i.bass.octave=3;
i.bass.clock=3;
i.bass.amp=2;
i.bass.note("C Dx2 Ebx3 Bbx2 Ax3 F ");
i.bass.duration;
)
The ':' operator inside string Patterns allows for setting of duration any values following it.
It requires a duration parameter, which must be a number (integer or fractionary).
// all subsequent events are affected
i=INSTRUMENT();
i.kick='kick';
// decimal representation
i.kick.seq("1 :0.25 1x3 ");
// fraction representation
i.kick.seq("1 :1/4 1x3 ");
i.kick.seq("1x2 :1/4 1x4 :1/8 1x8 :2 1");
Using fractions allow some interesting rhythms:
i=INSTRUMENT();
i.kick='kick';
i.hihat=i.synths.hihat.choose.postln;
i.kick.seq("1xx :3/8 1x3 1x2 :1/4 1x3 1x2 :1/2 1xx");
i.hihat.seq("1xx :1/3 1x3");
You can group patterns inside patterns using parenthesis, including nested groups. This is useful for playing parts of patterns with different durations and repetitions.
i=INSTRUMENT();
i.bass = i.synths.bass.trance[2];
i.bass.clock=4;
// repeat subsequence times
i.bass.note("Cx3 (Dx2 Gx2)x2 A");
i.bass.note("(Dx2 Gx2)x3 F A ");
// change subsequence duration
i.bass.note("(Dx2 Gx2):0.5 F A ");
// same result:
i.bass.note("(:0.5 Dx2 Gx2) F A ");
// same:
i.bass.note("(Dx2 Gx2):1/2 F A ");
i.bass.note("(Dx3 Gx2 B Cx7):1/3 F A");
// change both duration and repetition
i.bass.note("(Dx2 Gx2):1/2x4 F A ");
// multiple subselections
i.bass.note("(Dx2 Gx2):1/2x4 (F A)x3 ");
// between patterns
i.bass.note("C D E (Dx2 Ex2):1/2x3 F G C5 (B A)x2 C5 B D ");
// nested subsequences
i.bass.note("(C (D E)x2 G)x3 F A");
i.bass.note("(C (D (E F)x2)x3 G)x2");
// Ctrl/Cmd + Period
i=INSTRUMENT();
i.kick=i.synths.kick[3];
i.kick.clock=2;
i.kick[0].seq("1 1");
i.kick[1].seq("1xx 1xxx ").speed(2);
i.kick[2].seq("1 1xx 1x2 1x4 ").speed(4);
i.kick[3].seq("1 1xx ").speed(8);
// You can also use '=' syntax (setter)
i.kick[0].seq = "1";
i.kick[1].seq = ":1/2 1xx 1xxx ";
i.kick[1].speed(2);
// or just pass speed as a speed modifier:
i.kick[2].seq = ":1/4 1 1x2 1x3 1x4 ";
i=INSTRUMENT();
i.kick=i.synths.kick[3];
i.kick.clock=2;
// first add some patterns:
i.kick[1].seq("1xx 1xxx ").speed(2);
i.kick[2].seq("1 1xx 1x2 1x4 ").speed(4);
// now remove them:
i.kick.rm(\trigger,2);
i.kick.rm(\trigger,1);
i.kick.rm(\trigger,0);
i=INSTRUMENT();
i.kick=i.synths.kick[3];
// first add some patterns:
i.kick[0].seq("1").speed(1);
i.kick[1].seq("1").speed(2);
i.kick[2].seq("1").speed(4);
i=INSTRUMENT();
i.kick=i.synths.kick[3];
i.kick[0].seq("1").speed(1).repeat(4);
// different names for the same function:
i.kick[1].seq("1").speed(2).do(8);
i.kick[2].seq("1").speed(4).x(16);
i = INSTRUMENT();
(
i.hihat="hihatElectro";
i.hihat.seq("1xx :0.25 1xxx :0.5 1xxx :2 1").speed(2);
i.kick="kickElectro";
i.kick.seq("1xx :0.25 1xxx :0.5 1xxx :2 1").speed(1/3);
)
i.hihat.clock=2;
i.kick.clock=2;
// repeteadly evaluate this group:
(
i.hihat.go(0);
i.kick.go(0);
)
// again:
(
i.hihat.go(13);
i.kick.go(13);
)
(
i = INSTRUMENT();
i.bass=i.synths.trance[0];
i.bass.note("0 2 3");
)
i.bass.rel=2;
i.bass.rel=0.2;
i.bass.rel=1/2;
i.bass.dist=2;
i.bass.dist=1;
i.bass.dist=4;
i.bass.dist=14;
i.bass.dist=1;
i = INSTRUMENT();
i.bass=i.synths.trance[0];
i.bass.note("0 2 3");
i.bass.seq(\rel,[2,0.2,1]);
// rests in params:
i.bass.seq(\rel,[2,0.2,\r,\r,1]);
Parameter proxy syntax is also supported:
i.bass.rel.seq([2,0.2,1]);
i.bass.rel.seq("2 0.2 1");
// equivalent to:
i.bass.seq(\rel,[2,0.2,1]);
You can clear or reset a specific parameter sequence directly from the parameter proxy:
i.bass.rel.clear(); // remove rel patterns on this instrument
i.bass.rel.reset(); // clear + restore parameter default when available
Stop or remove parameter sequences with optional clear flag (true/false or 1/0):
i.bass.rel.stop(clear: true); // stop + clear rel patterns
i.bass.rel.stop(clear: false); // stop only, keep patterns
i.bass.rel.rm(clear: true); // remove patterns and stop
i.bass.rel.rm(clear: false); // remove patterns only
i=INSTRUMENT();
(
i.kick="kickDeep";
i.kick.seq("1");
i.kick.synthdef([\kickSyn1,\kickSyn2,\kickSyn3]);
i.bass=i.synths.trance.choose;
i.bass.note("0 2 3");
i.bass.synthdef([\bassTrance1,\bassTrance2,\bassTrance3]);
)
(
i=INSTRUMENT();
i.piano=i.synths.dist.note;
i.piano.note("0 2 3 5").random().mirror.speed(2);
i.piano.octave=4;
)
// using fx name
i.piano.fx="reverb";
// using synth dictionary
i.piano.fx=i.synths.fx.reverb;
// using synth variants
// by name
i.piano.fx=i.synths.fx.reverb.infinite;
// by index
i.piano.fx=i.synths.fx.reverb[2];
// variants
i.piano.fx.reverb="large";
// equivalent to:
i.piano.fx="reverb.large";
i.piano.fx.reverb="small";
i.piano.fx.reverb="infinite";
// modify parameters
i.piano.fx.reverb.wet=0;
i.piano.fx.reverb.wet=1;
i.piano.fx.reverb.wet=1/4;
i.piano.fx.reverb.wet=3/4;
i.piano.fx.reverb.room=7/8;
i.piano.fx.reverb.damp=7/8;
i.piano.fx.reverb.room=1/8;
i.piano.fx.reverb.damp=1/8;
i.piano.fx.reverb.room=1;
i.piano.fx.reverb.damp=1;
i.piano.fx=nil;
### FX Chains:
i.piano.fx = [ "reverb", "lpf" ];
i.piano.fx = [ "delay2", "distortion" ];
i.piano.fx.distortion.gain=30;
i.piano.fx.distortion.gain=3;
i.piano.fx.delay2.time=0.1;
i.piano.fx.delay2.time=0.5;
(
i = INSTRUMENT();
i.clap="clapElectro";
i.clap.seq(" 1 :0.25 1xx 1").speed(2);
i.clap.seq(\fx, [\reverb,\reverbLPF,\gateDistort]).speed(2);
)
i.piano=i.synths.piano[0];
i.piano.note("0 2 3 5").random().mirror.speed(2);
i.piano.seq(\fx,[
"reverb",
"gateDistortion",
"lpf"
]).speed(2);
// clear all FX:
i.piano.fx=nil;
You can group Instruments for easier manipulation, while retaining access to individual instruments
i = INSTRUMENT();
i.drums=(
kick: 'kick',
hihat: i.synths.hihat.choose,
snare: i.synths.snare.choose,
);
i.drums.kick.seq("1");
i.drums.hihat.seq(" 1").speed(2);
i.drums.snare.seq(" 1").speed(1/2);
i.drums.clock=1/2;
i.drums.clock=2;
i.drums.clock=1;
i.drums.amp=1/2;
i.drums.amp=1;
i.drums.amp=2;
i.drums.stop;
i.drums.play;
// add fx to group
i.drums.fx = "reverb";
i.drums.fx = nil;
// redeclare group with less instruments
i.drums=(
hihat: i.synths.hihat.choose,
)
// restore
i.drums=(
kick: 'kick',
hihat: i.synths.hihat.choose,
snare: i.synths.snare.choose,
)
// melodic synths:
i.melodies=(
note1: i.synths.note.dist[0],
note2: i.synths.note.dist[1]
);
i.melodies.note1.note("0 7 8");
i.melodies.note2.note("12 15 13");
i.melodies.amp=3;
i.melodies.octave=5;
i.melodies.octave=6;
i.melodies.octave=3;
i.melodies.octave=4;
i.melodies.fx = "reverb.large";
(
i=INSTRUMENT();
i.drums=(
k:i.synths.kick[3],
h:i.synths.hihat[2],
s:i.synths.snare[2],
);
i.drums.k.seq("1x3 1x3 1x3 :2 1").speed(4);
i.drums.h.seq("1x2 1 ").speed(8);
i.drums.s.seq(" 1x3 1x2 :2 1 :1/2 1x3 1x2 ").speed(2);
)
i.drums=(
k:i.synths.kick[4],
h:"kickDeep",
s:i.synths.snare[2],
);
i.drums=(
// k:'kick',
h:"hihatClosed",
s:i.synths.snare[5],
);
(
i.drums=(
k:'kick',
h:"kickDamp",
hh:i.synths.hihat[0],
s:i.synths.snare[2],
);
i.drums.k.seq("1").speed(2);
i.drums.hh.clock=2;
i.drums.hh.seq("1x7 1x6 ").speed(4);
)
i.drums.hh=i.synths.hihat[2];
i.drums.k=i.synths.hihat[0];
// wait a bit:
i.drums.k='kick';
(
i.drums.clock=1/8;
i.drums.fx="reverb.infinite";
)
(
i.drums.clock=2;
// i.drums.fx=i.synths.reverb;
i.drums.fx="reverb.small";
)
(
i.drums.k.seq("1").speed(2);
i.drums.fx=nil;
i.drums.clock=1;
i.drums.go(0);
)
i.drums.stop;
There is a Mixer channel automatically created for each group, and one for each of its children.
(
s.boot;
s.doWhenBooted({
Task.new({
i = INSTRUMENT();
i.drums=(
k: 'kickElectro',
h: 'hihat',
s: 'snareNeuro',
);
i.drums.k[0].seq = "1 ";
i.drums.k[1].seq = "1 1 ";
i.drums.h.seq = " 1";
i.drums.s.seq = " 1 ";
i.drums.play;
i.drums.fx=["reverb","lpf"];
i.drums.clock=4;
i.drums.fx.lpf.freq=15000;
4.wait;
i.drums.fx.lpf.lag=8;
i.drums.fx.lpf.freq=80;
12.wait;
i.drums.fx="hpf";
i.drums.fx.hpf.freq=40;
4.wait;
i.drums.fx.hpf.lag=8;
i.drums.fx.hpf.freq=15000;
8.wait;
i.drums.fx=["reverb.infinite"];
(3/8).wait;
i.stop;
}).play;
s.volume = (-12);
});
)
(
i = INSTRUMENT();
i.drums=( k: 'kickElectro', h: 'hihat', s: 'snareNeuro', );
i.drums.k[0].seq = "1 "; i.drums.k[1].seq = "1 1 ";
i.drums.h.seq = " 1"; i.drums.s.seq = " 1 ";
i.drums.clock=4;
)
i.clear;
i.restore;
Use i.clear to stop running instruments,, so you can easily create quick changes without pausing main thread. You can use i.restore to bring back cleared instruments and sequencer functions.
i=INSTRUMENT();
(
i.drums=(
k:i.synths.kick[3],
h:i.synths.hihat[2],
s:i.synths.snare[2],
);
i.drums.k.seq("1x3 1x3 1x3 :2 1").speed(4);
i.drums.h.seq("1x2 1 ").speed(8);
i.drums.s.seq(" 1x3 1x2 :2 1 :1/2 1x3 1x2 ").speed(2);
i.bass = i.synths.bass.trance[2];
i.bass.note("0 2 3");
i.bass.fx="reverb";
i.bass.octave=3;
i.bass.amp=1.5;
i.every(2,{ c=[2,4,8].choose; i.bass.clock=c; ["chose",c].postln; })
)
(
// Clear previous sounds
i.clear;
i.drums2=(
k:i.synths.kick[0],
s:i.synths.snare[4],
);
i.drums2.k.seq("1x2 1x4 1x3").speed(8);
i.drums2.s.seq(" 1x2 :2 1 :1/2 1x3 1x2 ").speed(4);
)
// restore first group
i.restore;
i.drums2.stop;
You can store nodes and groups inside named spaces, and then restore them:
i=INSTRUMENT();
i.k=i.synths.kick.syn[2];
i.h=i.synths.hihat.dist;
i.k.seq("1").speed(2);
i.h.seq(" 1").speed(4);
i.clear("test1");
i.b=i.synths.bass.sintri;
i.b.note("0");
i.clear()
i.restore()
i.restore("test1")
i.kk=i.synths.kick.syn[2];
i.hh=i.synths.hihat.dist;
i.kk.seq("1 1 ").speed(4);
i.hh.seq(" 1 1").speed(8);
i.clear("test2")
i.restore("test1")
i.clear("test1")
i.restore("test2")
i.clear("test2")
i.restore()
i.clear()
i = INSTRUMENT();
(
i.bass=i.synths.bass.trance;
i.hihat=i.synths.hihat.electro;
i.bass.clock=4;
i.bass.note("0 2 3");
)
i.bass.note("0 2 3").pyramid.mirror.speed(2);
// randomness
i.bass.note("0 2 3 5 7 10 12").random;
i.bass.note("0 2 3 5 7 10 12").random;
i.hihat.seq("1xxxxxxxxx").speed(8).maybe(0.5); // default value
i.hihat.seq("1xxxxxxxxx").speed(8).maybe(0.25);
i.hihat.seq("1xxxxxxxxx").speed(8).maybe(0.75);
i.hihat.seq("1xxxxxxxxx").speed(8).maybe(0); // never play
i.hihat.seq("1xxxxxxxxx").speed(8).maybe(1); // always play
i.hihat.seq("1xxxxxxxxx").speed(8).maybe(0.35);
A small composition:
// Ctrl/Cmd + .
i = INSTRUMENT();
(
i.voices = (
a: i.synths.pad.dist[0],
b: i.synths.pad.dist[1],
c: i.synths.note.dist[0],
d: i.synths.note.dist[1],
);
i.voices.a.note("0 2 0 2 3 0 2 3 7 0 2 3 7 14").speed(1/4);
i.voices.a.amp=1.5;
i.voices.a.set(\rel,8);
i.voices.b.note("0 2 0 2 3 0 2 3 7 0 2 3 7 14").speed(1/2).random;
i.voices.b.octave=6;
i.voices.b.amp=1/4;
i.voices.c.note("0 2 0 2 3 0 2 3 7 0 2 3 7 14").speed(2).random;
i.voices.c.octave=8;
i.voices.c.amp=1/4;
i.voices.d.note("0 2 0 2 3 0 2 3 7 0 2 3 7 14").speed(3).random;
i.voices.d.octave=7;
i.voices.d.amp=1/3;
)
i = INSTRUMENT();
i.hihat = i.synths.hihat.choose;
i.hihat.seq("1xxxxxxxxx");
i.drums=(
kick: i.synths.kick.choose,
hihat: i.synths.hihat.choose,
snare: i.synths.snare.choose,
);
i.drums.kick.seq("1");
i.drums.hihat.seq(" 1").speed(2);
i.drums.snare.seq(" 1").speed(1/2);
i.drums.clock=2;
i.every(4,{
i.drums=(
kick: i.synths.kick.choose,
hihat: i.synths.hihat.choose,
snare: i.synths.snare.choose,
);
});
// remove repeating function:
i.every(4, nil);
i.hihat.seq("1xxxxxxxxx").speed(2);
i = INSTRUMENT();
i.hihat = i.synths.hihat.choose;
i.hihat.seq("1xxxxxxxxx").speed([4,8,16].choose).maybe(0.75);
i.when(8,{
i.hihat.fx="distortion";
});
i.when(16,{
i.hihat.fx="reverb.large";
i.hihat.clock=1/4;
});
One of its main motivations is to easily integrate with the awesome JITLib, that allows musicians to incorporate mutating synthesis onto their live acts.
To sync tempo in ProxySpace with INSTRUMENT, run following code:
(
i = INSTRUMENT();
p = ProxySpace.push(s);
i.proxyspace = p;
)
After that, you can easily use tempo in the following way:
i.drums=(
kick: i.synths.kick.choose,
hihat: i.synths.hihat.choose,
snare: i.synths.snare.choose,
);
i.drums.kick.seq("1");
i.drums.hihat.seq(" 1").speed(2);
i.drums.snare.seq(" 1").speed(1/2);
~z.play;
// ~tempo is the clock's beats (quarter notes) per second: ~tempo.kr * 2 pulses on eighth notes
~z = { Decay2.kr(Impulse.kr( ~tempo.kr * 2 )) * Mix.new(RLPF.ar(WhiteNoise.ar,SinOsc.kr(~tempo.kr*4,0,1000,4000),0.1)) / 2}
Tempo changes in INSTRUMENT now affect ProxySpace's tempo:
i.tempo = 120;
i.tempo = 200;
i.tempo = 90;
i = INSTRUMENT();
p=ProxySpace.push(s);
i.proxyspace = p;
~z.play;
~z.fadeTime=10;
~z={|freq=200| RLPF.ar(WhiteNoise.ar,freq,0.2) };
i.z=Proxy(~z);
i.z.seq(\freq,"(1000 600):1/4x3 700");
i.z.freq.seq("(1000 600):1/4x3 700"); // equivalent parameter-proxy syntax
~z.fadeTime=3;
i.z.clock=1;
~z={|freq=200| (Resonz.ar(WhiteNoise.ar,Lag2.kr(freq,1/4),0.01)*30).tanh/2 };
i = INSTRUMENT();
p=ProxySpace.push(s);
i.proxyspace = p;
~z.play;
~z.fadeTime=1;
~z={|freq=200, t_trig=1| (LFPulse.ar(freq,SinOsc.kr(1/2).linlin(-1,1,0,1),SinOsc.kr(105).linlin(-1,1,0,1))*30).tanh/2*Decay2.kr(t_trig,2,0) };
i=INSTRUMENT();
i.z=Proxy(~z);
// automatic mapping of note to 'freq and t_trig':
i.z.note("0 2 3");
i.z.clock=4;
i.z.octave=5;
i.z.freq.seq("200 400 1200 300");
i.z.freq.clear();
i.z.freq.reset(); // restores NodeProxy function default arg when available (e.g. freq=200)
i = INSTRUMENT();
p=ProxySpace.push(s);
p.fadeTime = 10;
~sound.play;
~sound = {|notes=#[60,65,67,72],gain=1| (SinOsc.ar(notes.midicps)*gain).tanh / 6 ! 2 };
~sound = {|notes=#[60,65,67,72],gain=1| (Saw.ar(notes.midicps*[1/2, 2])*gain).tanh / 6 ! 2 };
i.sound=Proxy(~sound);
(
i.sound.chord([
C(0,\m),
C(7,\M,1),
C(3,\Mmaj7),
C(1,\m,0,[16])
]).speed(1/2);
)
(
i.sound.chord([
C(0,\m),
C(0,\m,1),
C(0,\m,2),
C(0,\m,2,[14]),
C(7,[6,10,16])
]).speed(1/4);
)
See Chord types
You can create shared channels for routing and sharing effects.
(
Task.new({
i=INSTRUMENT();
i.fx.ch1="reverb.infinite";
i.kick = 'kick';
i.hihat = 'hihat';
i.snare = 'snareNeuro';
i.kick.seq = ":1/4 1 2 4 ";
i.hihat.seq( ":1/4 5 2x3 1xx 3x3 :1/8 1x4 ").random;
i.snare.seq( " 5 2x3 1xx 3x3 :1/4 1x4 1X3 ").random;
4.wait;
i.hihat.send(i.fx.ch1);
4.wait;
i.fx.ch2=["reverb.infinite","delay2","lpf"];
i.snare.send(i.fx.ch2);
4.wait;
i.fx.ch1=nil;
i.fx.ch2=["reverb.small"];
4.wait;
i.fx.ch2=["reverb.infinite","gateDistort.hardcore"];
i.kick.send(i.fx.ch2);
6.wait;
i.fx.ch3=["shineDestroy","delay2"];
i.snare.send(i.fx.ch3);
i.hihat.stop;
4.wait;
i.fx.ch2=nil;
i.fx.ch1=["reverb.infinite"];
i.kick.send(i.fx.ch1);
4.wait;
i.snare.send(i.fx.ch1, false);
4.wait;
i.snare.stop;
8.wait;
i.kick.send(i.fx.ch1, false);
6.wait;
i.kick.stop;
}).play;
)
A multi-layer looper
- Time-synced to main sequencer.
- Allows recording of multiple layers.
- Sequenceable amp and rate manipulation.
- Works in the same way as any other INSTRUMENT
- Sequence any parameter
- Add FX
- etc...
i=INSTRUMENT();
// create looper connected to audio interface's first audio input:
i.loop1=Looper(0);
// record looper for the 1st channel:
i.loop1.rec;
i.loop1.start;
// replace
i.loop1.rec;
i.loop1.start;
i.loop1.rec(1);
i.loop1.start(1);
i.loop1.rec(2);
i.loop1.start(2);
i.loop1.rec(3);
i.loop1.start(3);
i.loop1.amp=0.5;
i.loop1.amp=1;
i.loop1.amp=0;
i.loop1.amp=0.3;
i.loop1.amp=1;
i.loop1.amp_(1);
// sequence amp
i.loop1.seq(\amp,"1 0.2 1 0.5 0.75").speed(2)
i.loop1.rate = 1/2;
i.loop1.rate = -2;
i.loop1.rate([1, 2, -1, \r, 3, \r , 1/2]).speed(1);
// remove rate sequencer:
i.loop1.rm(\rate,0);
i.loop1.rate(1/8);
i.loop1.rate(2.5);
// change rate separately for each of the layers:
i.loop1.rate(1,0);
i.loop1.rate(1.5,1);
i.loop1.rate(3,0);
i.loop1.rate(1/4,1);
i.loop1.rate(4,0);
i.loop1.rate(1/2,0);
i.loop1.rate(1/2,1);
i.loop1.rate(1/4,1);
i.loop1.rm(\amp)
i.loop1.fx="distortion"
i.loop1.fx=nil
i.loop1.amp=1;
i.loop1.rate(1);
// create another separate looper:
i.loop2=Looper(0);
i.loop2.rec;
i.loop2.start;
i.loop2.amp=0.5;
i.loop2.rate([1, 2, -1, \r, 3, \r , 1/2]).speed(2);
i.loop2.amp("1 0.3 1 0.5 0 0.1").speed(4)
i.loop2.amp(0.5);
i.loop2.rate(-1);
// stop loopers:
i.loop1.stop;
i.loop2.stop;
i.loop1.play;
i.loop1.stop;
//Docs coming soon...
INSTRUMENT can write counterpoint against a melody, voice-lead chord progressions, harmonize melodies and invent a cantus firmus. It follows the classic rules of first-species (note against note) counterpoint:
- only consonances against the bass;
- no parallel or hidden fifths and octaves;
- no awkward leaps;
- voices stay in range and never cross;
- a proper cadence (with musica ficta in the modes).
It uses the same values as .note: semitones relative to C at the instrument's octave, and note names work too. The new voices follow the melody's rhythm note for note, and rests pass through to every voice.
Every call computes a whole phrase, which loops. Run it again (or call .next) to get a new one. As with any pattern change, the new phrase comes in on the next bar line.
i = INSTRUMENT();
i.cantus = i.synths.note.dist[1];
i.alto = i.synths.note.dist[2];
i.cantus.note("D F E D G F A G F E D");
// write a counterpoint to whatever i.cantus is playing
i.alto.counterpoint(i.cantus);
// ...or to a melody given directly: note names, semitones or scale degrees
i.alto.counterpoint("D F E D G F A G F E D");
i.alto.counterpoint([2, 5, 4, 2, 7, 5, 9, 7, 5, 4, 2]);
i.alto.counterpoint([0, 2, 1, 0, 3, 2, 4, 3, 2, 1, 0], scale: "D dorian", degrees: true);
// put the counterpoint below the melody
i.alto.counterpoint(i.cantus, cantus: \above);
// several voices on one instrument are played as chords
i.alto.counterpoint(i.cantus, voices: 4);
If the instruments have different octaves, the new voice is shifted to match the melody's track.
Group members are taken in key (alphabetical) order. The first one plays the melody, and the rest get the other voices from low to high:
i.voices = (
v1: i.synths.note.dist[1],
v2: i.synths.note.dist[2],
v3: i.synths.note.dist[3]
);
i.voices.counterpoint("D F E D G F A G F E D");
// melody in the middle, or on top
i.voices.counterpoint("D F E D G F A G F E D", cantus: \middle);
i.voices.counterpoint("D F E D G F A G F E D", cantus: \above);
// the melody comes from another track: every member gets a counterpoint voice
i.voices.counterpoint(i.cantus);
// no melody: invent a Fux-style cantus firmus, then a counterpoint to it
i.voices.counterpoint(length: 10);
i.voices.counterpoint(length: 8, scale: \phrygian);
i.voices.octave = 5;
// members are taken in key (alphabetical) order: v1 gets the bass ... v4 the top voice
i.choir = (
v1: i.synths.note.dist[1],
v2: i.synths.note.dist[2],
v3: i.synths.note.dist[3],
v4: i.synths.note.dist[4]
);
i.choir.voicelead([C(0,\m), C(5,\m), C(7,\M7), C(0,\m)]);
// one instrument: smoothly voiced chords
i.chords = i.synths.note.dist;
i.chords.voicelead([C(0,\M), C(9,\m), C(5,\M), C(7,\M)]).speed(1/2);
// C() with an explicit inversion keeps that bass; without one the inversion is chosen freely
i.chords.voicelead([C(0,\M), C(5,\M,2), C(7,\M,1), C(0,\M,0)]);
// durations
i.chords.voicelead([(val: C(0,\m), duration: 2), C(5,\m), C(7,\M)]);
Chords are chosen from the scale (V gets its leading tone in minor modes) and the voices are led under the melody:
// first member: the melody on top; the others: the lower voices from low to high
i.choir.harmonize("E D C D E E E D D E G G");
// chords under another track's melody
i.chords.harmonize(i.cantus);
i.choir.harmonize("A B C B A G# A", key: "Am");
scale:takes an SC Scale (Scale.dorian), a symbol (\dorian) or a string ("D dorian","Dm","F#").key:takes"D","Dm",'Bb'or a pitch-class number.- Without them, the instrument's or group's scale is used, or else the global
i.key/i.scale(see Scales and keys). - If no key is set anywhere, the mode is inferred from the melody: its last note is taken as the final, and the reading with the fewest accidentals wins.
- In modes without a leading tone (dorian, mixolydian, aeolian), the note before the final is raised at the cadence (musica ficta). Turn this off with
ficta: false.
I8THarmony.rules; // the counterpoint rules and their defaults
I8THarmony.rules(\voicelead); // the voice-leading rules
| rule | default | what it means |
|---|---|---|
dissonance |
hard | only unison, 3rds, 5th, 6ths and octave against the bass |
parallelFifths, parallelOctaves |
hard | no parallel (or contrary) 5ths, 8ves or unisons |
hiddenPerfects |
hard | no similar motion into a 5th or 8ve (outer voices, upper voice leaping) |
badLeaps |
hard | no tritone, 7th, major 6th or leap beyond an octave |
crossing, voiceOverlap, range |
hard | voices keep their order and their range |
diatonic |
hard | notes from the scale (plus the raised leading tone at the cadence) |
startPerfect, finalPerfect, cadence, ficta |
hard | perfect beginning and end, stepwise cadence into the final |
chordTones, completeChord, doubling, inversion |
hard | voice-leading/harmonizing: chord tones, complete chords, no doubled 7ths/leading tones, explicit inversions kept |
stepwise, contraryMotion, leapRecovery, repeatedNotes, oscillation, climax, parallelThirds, unison, perfectInterior, spacing ... |
soft | preferences (weights) |
You can override any rule on any call:
i.alto.counterpoint(i.cantus, rules: (parallelFifths: false)); // allow parallel fifths
i.alto.counterpoint(i.cantus, rules: (hiddenPerfects: \soft)); // a hard rule becomes a penalty
i.alto.counterpoint(i.cantus, rules: (stepwise: 4, unison: \hard)); // change a weight / make a rule hard
i.alto.counterpoint(i.cantus, rules: (parallelFifths: -10)); // negative weight: ask for them
i.alto.counterpoint(i.cantus, strictness: 0.5); // looser: secondary rules become penalties
Rule values are:
false: off.true: the default.\hard: must be obeyed.\soft: a penalty.- A number: a soft weight.
strictness ranges from 1 (all hard rules hard) down to 0 (everything is only a preference).
If no strictly correct answer exists (an odd melody, or a range that is too narrow), the hard rules are relaxed step by step. You get a warning and the best attempt, and .report lists the rules that were broken.
Each call returns a result and posts a line such as counterpoint #3 · D dorian · 3 voices · 11 steps · seed 482113 · ok.
r = i.voices.counterpoint("D F E D G F A G F E D");
r.next; // same melody, new seed
r.report; // the voices and any rule problems
r.voices; // arrays of semitones, low to high (\r = rest)
r.melody;
r.chords; // one chord per step, e.g. for a Proxy with a `notes` control
r.seed;
// reproduce a result you liked
i.voices.counterpoint("D F E D G F A G F E D", seed: 482113);
// the last 20 results per instrument/group
i.voices.harmony.history;
i.voices.harmony.recall(3); // send result #3 again
i.voices.harmony.recall(-1); // the one before the latest
i.voices.harmony.next; // regenerate the latest call
// a new counterpoint every 16 beats
i.every(16, { i.voices.harmony.next });
In live mode the voices do not compute a phrase in advance. Each voice chooses its note at the moment it plays, from probabilities weighted by the rules, reacting to what was just played. It changes on every pass and can't look ahead, so it mostly follows the rules and cadences are best-effort:
i.voices.counterpoint("D F E D G F A G F E D", mode: \live);
i.voices.harmonize("E D C D E E E", mode: \live);
i.voices.harmony.last.report; // how often the rules were kept so far
r = I8THarmony.counterpoint("D F E D G F A G F E D", 3);
r.voices;
I8THarmony.voicelead([C(0,\M), C(5,\M), C(7,\M), C(0,\M)]).voices;
I8THarmony.harmonize("E D C D E E E").chords;
I8THarmony.cantus(10, \dorian).melody;
// check any voices against the rules
I8THarmony.check([[2, 5, 4, 2], [9, 12, 11, 9]]); // -> parallel fifths
(The old I8THarmony().generateVoicings was removed: its output was effectively random.)
INSTRUMENT comes with a group of SynthDefs that are automatically loaded when a new instance of INSTRUMENT is created.
You can access them via i.synths
i=INSTRUMENT();
i.synths.list;
i.synths.percussion.list;
i.synths.percussion.drums.list;
// all synths accesible using their names:
// (Currently, synthnames are converted to lowercase).
i.synths.simple == i.synths.simple;
// references are created without redundant names:
i.synths.simple==i.synths.percussion.drums.kick.simple;
// Multiple hierarchies support.
i.synths.drums == i.synths.percussion.drums;
i.synths.electro == i.synths.percussion.drums.kits.electro;
// smart organization
i.synths.electro.kick===i.synths.kick.electro;
// numeric indexes are fixed by prefixing an 's'
i.synths.kick.syn.s1===i.synths.kicksyn1;
i.synths.kick.s808===i.synths.kick808;
// numerical indexing based on alphabetical order.
i.synths.kick[0].name
i.synths.kick[1].name
i.synths.kick[2].name
i.synths.kick[3].name
// (number wraps around item size)
(
Task.new({
30.do{|h|
[h,i.synths.kick[h].name].postln;
0.01.wait;
}
}).play;
)
// choose one Synthdef at random
'kick'.postln;
i.synths.bass.choose.postln;
// a specific SynthDef
i.synths.kick.simple
You can load your own SynthDef paths:
i.loadSynths("path/to/synths");You can use your own Synthdefs. You need to have an out parameter for signal routing.
Optionally, you can make them add themselves to the server by putting them inside INSTRUMENT's Sounds/Synthdef folder.
They are automatically added on startup, but you can manually re-load them, or load any path that contains SynthDefs or folders containing them.
i=INSTRUMENT();
// load your own path with SynthDefs
i.loadSynths("path/to/your/synthdefs/*");
Synthdef(\yourSynthdef, {|out=0,amp=1,freq,gate=1|
//... your synthesis code
Out.ar( out, /*...*/ ));
}).store;
-
amp - for setting amplitude manually or via a sequence
-
gate useful for retriggering and monophonic synths
-
note
-
freq
NOTE: you can use note or freq interchangeably. When you sequence notes, both parameters are addressed. note must be converted to freq using the .midicps method.
You can check currently existing Synthdefs here
Only requirements are using inBus, outBus, wet, and amp params.
See following example:
SynthDef(\reverb, {
arg
inBus=0,
outBus=0,
wet=0.5,
room=0.3,
damp=0.3
amp=1;
var sig;
var targetRoom, targetDamp, lag=0.3;
var dsp, mix;
sig = In.ar(inBus) * 1.25;
dsp = FreeVerb.ar( sig, 1, room, damp );
mix = (sig * (1-wet)) + (dsp * wet);
ReplaceOut.ar( outBus, Pan2.ar( mix * amp.linlin(0,1,0,1.5), 0 ) );
}).store;
The * operator inside string patterns sets an amplitude multiplier for individual events:
i = INSTRUMENT();
i.kick = 'kick';
// set amplitude directly in the pattern string
i.kick.seq("1*2 1*0.5 1*1.5 1*0.3");
In addition to pyramid, mirror, random, and maybe, the following transformations are available:
i = INSTRUMENT();
i.bass = i.synths.bass.trance[2];
// reverse the pattern
i.bass.note("0 2 3 5 7").reverse();
// mirror variants
i.bass.note("0 2 3 5 7").mirror();
i.bass.note("0 2 3 5 7").mirror1();
i.bass.note("0 2 3 5 7").mirror2();
// rotate pattern by n positions
i.bass.note("0 2 3 5 7").rotate(2);
// shift pattern values
i.bass.note("0 2 3 5 7").shift(1);
// lace pattern to a specified length
i.bass.note("0 2 3 5 7").lace(8);
// permute pattern
i.bass.note("0 2 3 5 7").permute(2);
// transpose all note values by n semitones
i.bass.note("0 2 3 5 7").transport(3);
Transformations can be chained:
i.bass.note("0 2 3 5 7").reverse().mirror.speed(2);
Instruments support both polyphonic and monophonic modes. In mono mode, notes use gate control for legato behavior:
i = INSTRUMENT();
i.bass = i.synths.bass.trance[2];
// monophonic mode (legato, single voice, gate-controlled)
i.bass.mode = \mono;
i.bass.note("0 2 3 5").speed(4);
// polyphonic mode (default, new synth per note)
i.bass.mode = \poly;
These methods are available on any instrument or sequenceable object:
Pauses playback, distinct from stop (which resets position):
i.bass.pause;
i.bass.play;
Shorthand for .repeat(1) / .do(1):
i.kick.seq("1 1 1").one();
Adds a delay (in beats) before the pattern starts playing:
i.kick.seq("1").waitBefore(4);
Retrieve a pattern by parameter and key:
i.kick.get(\trigger, 0);
Removes the instrument from the sequencer entirely:
i.kick.kill;
Returns the current pattern object:
i.kick.pattern;
Access all patterns for a parameter, or the full sequence:
i.kick.patterns(\trigger);
i.kick.sequence(\trigger);
These are shorthands for seq(\parameter, pattern):
i = INSTRUMENT();
i.bass = i.synths.bass.trance[2];
// volume sequencing
i.bass.vol("1 0.5 0.75 1");
i.bass.vol = "1 0.5 0.75 1";
// pan sequencing
i.bass.pan("-1 0 1 0");
i.bass.pan = "-1 0 1 0";
// FX set sequencing (change FX parameters in sequence)
i.bass.fxSet("paramName", [val1, val2, val3]);
// trigger shorthand
i.bass.trigger("1 0.5 1");
i.bass.trigger = "1 0.5 1";
INSTRUMENT includes a built-in mixer with per-channel processing.
i = INSTRUMENT();
i.kick = 'kick';
i.kick.seq("1");
// toggle EQ on a channel
i.kick.channel.toggle(\eq, true);
// set EQ bands
i.kick.channel.set(\low, 0.5);
i.kick.channel.set(\middle, 1);
i.kick.channel.set(\high, 0.8);
// toggle compressor
i.kick.channel.toggle(\compressor, true);
// toggle lo-cut filter
i.kick.channel.toggle(\locut, true);
// free (disable) a specific module
i.kick.channel.free(\eq);
i.kick.channel.free(\compressor);
// send audio to another channel
i.kick.channel.send(targetChannel, true);
// connect directly
i.kick.channel.connect(targetChannel);
// disconnect
i.kick.channel.disconnect;
// add/remove sources
i.kick.channel.addSource(source);
i.kick.channel.removeSource(source);
// access mixer channels
i.mixer.at(\drums);
// remove mixer channel
i.mixer.rm(\drums);
// get all channels
i.mixer.getChannels;
// get master channels
i.mixer.getMasterChannels;
Additional methods available on instrument groups:
i = INSTRUMENT();
i.drums = (
kick: 'kick',
hihat: 'hihat',
snare: 'snare',
);
// pause all instruments in group
i.drums.pause;
// pause specific instrument
i.drums.pause(\kick);
// stop specific instrument
i.drums.stop(\kick);
// check if group includes a value
i.drums.includes('kick');
// iterate with keys and values
i.drums.keysValuesDo({|key, instrument|
[key, instrument].postln;
});
// get all keys
i.drums.keys;
i = INSTRUMENT();
i.volume = 0.5;
i.volume = 1;
bpm and bpm_ are aliases for tempo:
i.bpm = 140;
i.bpm; // returns 140
Completely destroys the INSTRUMENT instance:
i.kill;
// free a specific node
i.free(i.kick);
// remove node by key
i.removeNode(\kick);
// add node manually
i.addNode(node, \myNode);
// change server
i.setServer(s);
// add additional server
i.addServer(s);
Automatically assign MIDI controllers to instruments:
i.autoMIDI(true);
i.autoMIDI(false);
// start MIDI
i.startMidi;
// map a controller
i.map(controller, target, parameter, range);
// unmap a controller
i.unmap(controller, target, parameter);
// rewind to beginning
i.sequencer.rewind;
// clear all repeat functions
i.clearSequencerFunctions;
The Looper supports per-layer operations beyond what's shown in the basic examples:
i = INSTRUMENT();
i.loop1 = Looper(0);
// record multiple layers
i.loop1.rec(0);
i.loop1.start(0);
i.loop1.rec(1);
i.loop1.start(1);
// stop a specific layer
i.loop1.stop(0);
// play a specific layer
i.loop1.play(1);
// set volume per layer
i.loop1.amp_(0.5, 0);
i.loop1.amp_(1, 1);
// sequence volume (vol is alias)
i.loop1.vol("1 0.5 0.75", 0);
i = INSTRUMENT();
// pause everything
i.pause;
// resume
i.play;