clip

A clip is a container for a musical idea. It’s like a measure of music. It can be a single bar or two bars or how many ever bars you need. In DAWs such as Ableton Live and Propellerhead Reason, a clip is what you create in the session or arrangement view to capture a musical idea.

The clip method takes an object literal as an argument. This object lets you define the parameters of that clip. Here is an example of the clip method being called with an object that sets up the most basic properties of the clip:

import { clip, midi } from 'scribbletune';
 
// Create a clip that plays the middle C
const clip = clip({
notes: 'C4',
pattern: 'x'
});
 
// Render a MIDI file
midi(clip, 'c.mid');

Parameters

notes

String|Array

An array of notes or a string of notes separated by spaces. You can also use the scale method to generate notes from a scale.

import { clip, midi, scale } from 'scribbletune';
 
// Create a clip using a scale
const clip = clip({
notes: scale('C4 major'), // or 'C4 D4 E4 F4 G4 A4 B4'
pattern: 'xxxxxxx'
});
 
// Render a MIDI file
midi(clip, 'c.mid');

pattern

String

This is the most important parameter for the clip method’s object. It abstracts away the MIDI note on and note off events along with the individual note durations and few other MIDI instructions to form a simple notation language. It is made up only of the following characters:

xPlay a note
-Rest (dont play a note)
_Sustain a note denoted by x or R
RIf the randomNotes property is defined, use either a random selection from it or the next note in the notes sequence, OR randomly set the volume of the next note
[Start subdividing the note duration (based on the number of characters inserted)
]End subdividing (you can nest subdivisions as well)

This is native to Scribbletune and it’s used in multiple ways across the Scribbletune library. Here’s an example of what a very simply pattern looks like,

xxxx

These are 4 quarter notes. By default a single x is a quarter note. The default can be changed to eighth note or half note or any other standard note duration. It might look like this in a DAW (if exported as MIDI from Scribbletune):

Each x implies a MIDI "note on" event (hence shows a note in the piano roll when imported) and each hyphen implies a MIDI "note off" event which does not have any note in that location in the clip. Other than setting note on and off events, we can even set the duration of a note on event using the pattern language’s third character: the _ (underscore) character:

x_

This makes the quarter note double in size making it a half note

Notes can be divided further by placing them in square braces. Square braces also allow nesting more square braces leading to the creation of interesting or even complex patterns!

x[xx]x
x[x[xx]]x

Lastly, the letter R will let you randomly decide if a note is to be added or not at the specified position. For example, in this pattern xxRx, the quarter note at R will be randomly picked to be added or not (random midi note on/off). The volume of this note is governed by accentLow property of the clip.

If you set an additional property called randomNotes with a string or array of notes, R will then randomly select a note to play from these provided notes instead of randomly deciding note on or note off events.

R is a powerful feature to create interestingly intricate patterns.

shuffle

Boolean

Boolean (default: false). When true, the notes are shuffled.

sizzle

Boolean | sin | cos | rampUp | rampDown

Boolean (default: false). When true, adds a sizzle effect by randomizing the velocity of the notes.

subdiv

String

A string that specifies the subdivision of the pattern (e.g., 8n, 16n). Default is 4n.

accentMap

An array of velocities (0-127) that correspond to the pattern. Use this to add dynamic accents to your clip.

Using with Scales

import { clip, midi, scale } from 'scribbletune';
 
// Create a clip using a scale
const clip = clip({
notes: scale('C4 major'), // or 'C4 D4 E4 F4 G4 A4 B4'
pattern: 'xxxxxxx'
});
 
// Render a MIDI file
midi(clip, 'c.mid');

Custom Subdivisions

const scribble = require('scribbletune');
 
// Create a clip with a custom subdivision
const clip = scribble.clip({
notes: ['C4', 'E4', 'G4'],
pattern: 'x_x_x_x_',
subdiv: '8n'
});

The clip method is highly versatile and can be combined with other Scribbletune methods like scale, chord, and progression to create complex musical ideas.