### Create and start a browser clip with sample and pattern
Source: https://scribbletune.com/documentation/browser/clip
Creates a clip using a sample URL and pattern, then starts the Tone.js audio context and transport before starting the clip. Requires Tone.js to be loaded.
```javascript
import { clip } from "scribbletune";
const kickClip = clip({
pattern: "x",
sample: "https://scribbletune.com/sounds/kick.wav",
});
// Start the audio context followed by transport
// as browsers will not start the audio context
// unless the user has clicked a button
await Tone.start();
Tone.Transport.start();
kickClip.start(0);
```
--------------------------------
### Run Scribbletune CLI --help
Source: https://scribbletune.com/documentation/cli
Shows how to run the Scribbletune CLI after a global install, a local/project install, or directly from a local build. Use this to verify the CLI is available and to see the latest usage text.
```bash
# Global install
npm install -g scribbletune
scribbletune --help
# Local/project install
npm install scribbletune
npx scribbletune --help
# Local build (from the Scribbletune repo)
node dist/cli.cjs --help
```
--------------------------------
### Start Development Server
Source: https://scribbletune.com/documentation/installation
Run the Vite development server.
```bash
npx vite
```
--------------------------------
### Install Dependencies for Browser Development
Source: https://scribbletune.com/documentation/installation
Install Scribbletune and Vite as a development dependency.
```bash
npm i scribbletune
npm i vite --save-dev
```
--------------------------------
### --chord examples
Source: https://scribbletune.com/documentation/cli
Shows four --chord examples using different progression formats: degree digits, roman numerals, random, and explicit chord names. Use these as templates for generating chord-based MIDI files.
```bash
# Degree digits
scribbletune --chord C3 major xxxx 1m 1645 --outfile chord-1645.mid
# Roman numerals
scribbletune --chord C3 major xxxx 1m "I IV vi V" --outfile chord-roman.mid
# Random progression
scribbletune --chord C3 major xxxx 1m random --outfile chord-random.mid
# Explicit chord names
scribbletune --chord C3 major xxxx 1m CM-FM-Am-GM --outfile chord-explicit.mid
```
--------------------------------
### Install Scribbletune for Node.js
Source: https://scribbletune.com/documentation/installation
Use npm to install the Scribbletune package.
```bash
npm i scribbletune
```
--------------------------------
### --arp examples
Source: https://scribbletune.com/documentation/cli
Shows six --arp examples covering degree progression, single degree, explicit chords, custom order, auto-fit default, and disabling auto-fit. The --order option accepts one-based (recommended) or zero-based digits.
```bash
# Degree progression
scribbletune --arp C3 major xxxx 1m 1736 --sizzle cos 4 --outfile arp-1736.mid
# Single degree "1" means tonic chord in the selected key/mode
scribbletune --arp C3 major xxxx 4n 1 --outfile arp-degree-1.mid
# Explicit chords
scribbletune --arp C3 major xxxx 1m CM-FM-Am-GM --count 4 --order 1234 --outfile arp-explicit.mid
# Custom arp order (one-based)
scribbletune --arp C3 major xxxx 4n 1 --order 2143 --outfile arp-order.mid
# Auto-fit is default
scribbletune --arp C3 major x 4n 1736 --outfile arp-fit.mid
# Disable auto-fit
scribbletune --arp C3 major x 4n 1736 --no-fit-pattern --outfile arp-no-fit.mid
```
--------------------------------
### Create and start multiple independent clips
Source: https://scribbletune.com/documentation/browser/clip
Creates two independent clips (kick and bass) and starts them together after starting the audio context and transport.
```javascript
const kickClip = clip({
pattern: "x",
sample: "https://scribbletune.com/sounds/kick.wav",
});
const bassClip = clip({
pattern: "[-x]",
sample: "https://scribbletune.com/sounds/bass.wav",
});
// Do the following on the click of a button
await Tone.start();
Tone.Transport.start();
kickClip.start(0);
bassClip.start(0);
```
--------------------------------
### Create a clip with a sample URL
Source: https://scribbletune.com/documentation/browser/clip
Example for the `sample` input parameter, which is required for standalone use. Supports WAV format.
```javascript
const kick = clip({
pattern: "x-x-",
sample: "https://scribbletune.com/sounds/kick.wav",
});
```
--------------------------------
### --riff examples
Source: https://scribbletune.com/documentation/cli
Shows three --riff examples: a basic riff, a riff with a style, and a riff with subdivisions. The --style option creates sections by repeating the full pattern per letter; repeated letters reuse the same generated section.
```bash
# Basic riff
scribbletune --riff C3 phrygian x-xRx_RR 8n --outfile riff.mid
# Riff with style
scribbletune --riff C3 phrygian x-xRx_RR 8n --style AABC --outfile riff-style.mid
# Pattern with subdivisions
scribbletune --riff C3 phrygian 'x-x[xx]-x-[xx]' 8n --style AABC --outfile riff-subdiv.mid
```
--------------------------------
### Create MIDI files in Node.js
Source: https://scribbletune.com/documentation/installation
Example of generating a MIDI file using the Scribbletune module.
```javascript
const scribble = require('scribbletune');
const clip = scribble.clip({
notes: scribble.scale('C4 major'),
pattern: 'x'.repeat(8)
});
scribble.midi(clip); // creates a file called music.mid in the same location as this script was created and run.
```
--------------------------------
### Resume Tone Context and Start Transport
Source: https://scribbletune.com/documentation/browser/session
Resumes the Tone.js context and starts the Transport. Must be called after Tone.js is loaded in the browser.
```javascript
Tone.context.resume().then(() => Tone.Transport.start());
```
--------------------------------
### clip({ pattern, sample })
Source: https://scribbletune.com/documentation/browser/clip
Creates a browser clip that plays a sample according to a pattern. Returns a Tone.js Sequence object that can be started and stopped independently.
```APIDOC
## clip({ pattern, sample })
### Description
Creates a browser clip that plays a sample according to a pattern. Returns a Tone.js Sequence object that can be started and stopped independently.
### Method
clip
### Endpoint
clip({ pattern, sample })
### Parameters
#### Input Parameters
- **pattern** (String) - Required - The rhythmic pattern for the clip.
- **sample** (String) - Required for standalone use - The URL of an audio file (WAV format) to use as the sound source.
- **offlineRendering** (Boolean) - Optional - When set to true, the clip is pre-rendered offline into a buffer. Returns a Tone.Player instead of a Tone.Sequence.
- **offlineRenderingCallback** (Function) - Optional - A callback fired when offline rendering is complete. Only relevant when offlineRendering is true.
### Return Value
Returns a Tone.js Sequence (or a Tone.Player when offlineRendering is true). Both support .start(time) and .stop(time) methods.
### Usage Example
```javascript
import { clip } from "scribbletune";
const kickClip = clip({
pattern: "x",
sample: "https://scribbletune.com/sounds/kick.wav",
});
// Start the audio context followed by transport
await Tone.start();
Tone.Transport.start();
kickClip.start(0);
```
### Notes
- Tone.Transport must be running for clips to play. Call await Tone.start() and Tone.Transport.start() before calling .start() on a clip.
- sizzle and accent will not work in the context of a browser clip.
```
--------------------------------
### Get chord notes with chord function
Source: https://scribbletune.com/documentation/core/chord
Use the chord function to get an array of notes for a given chord. Major is denoted by M, minor by m. The octave is specified in the note name (e.g., C4). The examples show C Major, C Major on the 5th octave, and C minor.
```javascript
import { chord } from 'scribbletune';
// Get C Major (Major is denoted by M)
const cMajorChord = chord('C4 M'); // [ 'C4', 'E4', 'G4' ]
// Get the C Major chord on the 5th octave
const cMajorChord5 = scribble.chord('C5 M'); // [ 'C5', 'E5', 'G5' ]
// Get the C minor chord (denoted with a lowercase `m`)
const cMinorChord = chord('C4 m'); // [ 'C4', 'EB4', 'G4' ]
```
--------------------------------
### Start a Session Row
Source: https://scribbletune.com/documentation/browser/session
Plays the second row in the session, which corresponds to the second clip in all channels.
```javascript
session.startRow(1);
```
--------------------------------
### Add a Bass Channel to Session
Source: https://scribbletune.com/documentation/browser/session
Adds a second channel with a bass sample (using the same kick.wav URL in the example) and four clips with different patterns.
```javascript
session.createChannel({
sample: 'https://scribbletune.com/sounds/kick.wav',
clips: [
{ pattern: '[-x]' },
{ pattern: '[--xx]' },
{ pattern: '[-xxx]' },
{ pattern: 'xxx' }
]
});
```
--------------------------------
### Get Session Channels
Source: https://scribbletune.com/documentation/browser/session
Returns the list of all channels in the session.
```javascript
session.channels;
```
--------------------------------
### Set accent with custom amp and accentLow
Source: https://scribbletune.com/documentation/core/clip
Sets accent volumes: notes marked 'x' get amp (default 100) and notes marked '-' get accentLow (default 50). Here amp is 127 and accentLow is 30, producing the volume sequence 127, 30, 30, 127, 127, 30, 30, 127.
```javascript
import { clip } from 'scribbletune';
// Create a clip that plays the C major scale
const c = clip({
notes: 'C4',
pattern: 'x'.repeat(8),
accent: 'x--x',
amp: 127,
accentLow: 30,
});
```
--------------------------------
### Create a clip with offline rendering
Source: https://scribbletune.com/documentation/browser/clip
Example for the `offlineRendering` parameter. When set to true, the clip is pre-rendered offline into a buffer and returns a Tone.Player instead of a Tone.Sequence. The `offlineRenderingCallback` fires when rendering is complete.
```javascript
const rendered = clip({
pattern: "x-x-",
sample: "https://scribbletune.com/sounds/kick.wav",
offlineRendering: true,
offlineRenderingCallback: () => {
console.log("Rendering complete — ready to play!");
},
});
```
--------------------------------
### Start a clip on a channel
Source: https://scribbletune.com/documentation/browser/channel
Plays an individual clip on the channel. The index is zero-based; here it plays the second clip of bassChannel. Uses Tone.Transport.nextSubdivision for timing alignment.
```javascript
bassChannel.startClip(2);
```
--------------------------------
### Accent volume output
Source: https://scribbletune.com/documentation/core/clip
Output volume sequence for the accent example with amp 127 and accentLow 30.
```text
127, 30, 30, 127, 127, 30, 30, 127
```
--------------------------------
### Get the currently active clip index
Source: https://scribbletune.com/documentation/browser/channel
Returns the index of the currently playing clip on the channel.
```javascript
bassChannel.activeClipIdx; // returns the currently playing clip
```
--------------------------------
### List all available chords with chords function
Source: https://scribbletune.com/documentation/core/chord
Call the chords function to get an array of all available chords. This exposes Tonal's Chord.names() as chords in Scribbletune.
```javascript
import { chords } from 'scribbletune';
// Get a list of all the available chords
const allChords = chords(); // Returns an array of all the available chords
```
--------------------------------
### Stop a browser clip
Source: https://scribbletune.com/documentation/browser/clip
Stops the clip created in the previous example. Pass 0 to stop immediately.
```javascript
kickClip.stop(0);
```
--------------------------------
### Create HTML for Browser Testing
Source: https://scribbletune.com/documentation/installation
Create index.html to provide user interface for audio control.
```html
Testing Scribbletune
The Audio context needs to be started by a user gesture.
Once audio context is started by a user gesture, you can use the
start/stop methods on clip objects. The clips will align per bar, so if
you start a clip in the middle of a bar, it will wait until the next bar
to start playing.
```
--------------------------------
### Generate and Export a Scale as MIDI
Source: https://scribbletune.com/documentation/core/scale
Demonstrates how to retrieve a scale, create a musical clip using that scale, and export it as a MIDI file.
```javascript
const scribble = require('scribbletune');
// Get the C major scale
let cMajor = scribble.scale('C4 major'); // [ 'C4', 'D4', 'E4' ... ]
// That's the same as
cMajor = scribble.scale('C4 ionian'); // [ 'C4', 'D4', 'E4', 'F4' ...]
// Create a clip that plays this C major scale
const clip = scribble.clip({
notes: cMajor,
pattern: 'xxxxxxx',
});
// Export this clip as a MIDI file
scribble.midi(clip, 'c-major.mid');
```
--------------------------------
### Create channels with sample and clips
Source: https://scribbletune.com/documentation/browser/channel
Creates two channels (kickChannel and bassChannel) using a sample URL and an array of clip patterns. The sample property is used for all clips in the channel.
```javascript
const kickChannel = session.createChannel({
sample: 'https://scribbletune.com/sounds/kick.wav',
clips: [
{ pattern: 'x' },
{ pattern: 'xxx[xx]' },
{ pattern: 'x' },
{ pattern: 'xxx[-x]' }
]
});
const bassChannel = session.createChannel({
sample: 'https://scribbletune.com/sounds/kick.wav',
clips: [
{ pattern: '[-x]' },
{ pattern: '[--xx]' },
{ pattern: '[-xxx]' },
{ pattern: 'xxx' }
]
});
```
--------------------------------
### Implement Browser Logic with Scribbletune
Source: https://scribbletune.com/documentation/installation
Create script.js to handle audio context and clip playback.
```javascript
import { Session } from "scribbletune/browser";
const btnStart = document.getElementById("start");
const btnPlay1 = document.getElementById("play1");
const btnPlay2 = document.getElementById("play2");
const btnPlay3 = document.getElementById("play3");
const btnStop = document.getElementById("stop");
let channel;
let isReady = false;
btnStart.addEventListener("click", async () => {
// Resume audio context (required for browsers)
await Tone.start();
console.log("Audio context started");
// Create session and channel
const session = new Session();
channel = session.createChannel({
instrument: "PolySynth",
clips: [
{ pattern: "x-x-", notes: "C4 E4 G4" },
{ pattern: "x[xx]", notes: "C#4 D#4" },
{ pattern: "[xxxx]", notes: ["G4", "D5"] },
],
eventCb: (event, data) => {
console.log("Channel event:", event, data);
if (event === "loaded") {
isReady = true;
console.log("Channel is ready to play!");
}
if (event === "error") {
console.error("Channel error:", data.e);
}
},
});
// Start the transport
Tone.Transport.start();
console.log("Transport started");
});
btnPlay1.addEventListener("click", () => {
if (!isReady) {
console.log("Channel not ready yet. Click 'Start context' first.");
return;
}
console.log("Starting clip 0");
channel.startClip(0);
});
btnPlay2.addEventListener("click", () => {
if (!isReady) {
console.log("Channel not ready yet. Click 'Start context' first.");
return;
}
console.log("Starting clip 1");
channel.startClip(1);
});
btnPlay3.addEventListener("click", () => {
if (!isReady) {
console.log("Channel not ready yet. Click 'Start context' first.");
return;
}
console.log("Starting clip 2");
channel.startClip(2);
});
btnStop.addEventListener("click", () => {
if (channel) {
console.log(`Stopping clip ${channel.activeClipIdx}`);
channel.stopClip(channel.activeClipIdx);
}
});
```
--------------------------------
### Configure Vite
Source: https://scribbletune.com/documentation/installation
Create a minimal vite.config.js file.
```javascript
import { defineConfig } from "vite";
export default defineConfig({});
```
--------------------------------
### Scribbletune CLI common options
Source: https://scribbletune.com/documentation/cli
Lists the common CLI options for --riff, --chord, and --arp, including defaults and arp/riff-specific flags. Use this as a reference for available options and their meanings.
```bash
--outfile # default: music.mid
--bpm
--subdiv <4n|8n|1m...> # optional override to positional subdiv
--sizzle [sin|cos|rampUp|rampDown] [reps]
--sizzle-reps
--amp <0-127>
--accent
--accent-low <0-127>
--fit-pattern # explicit enable (enabled by default)
--no-fit-pattern # disable automatic pattern fitting
# arp only
--count <2-8>
--order
# riff only
--style # style/motif, e.g. AABC
```
--------------------------------
### Create a channel with a synth and notes
Source: https://scribbletune.com/documentation/browser/channel
Creates a channel using a Tone.js PolySynth. Requires the notes property along with pattern. Notes can be a string, chord names, an array, or the result of scribble.scale().
```javascript
const synthChannel = session.createChannel({
synth: 'PolySynth',
clips: [
{ pattern: '[-x]', notes: 'C4 D#4' }, // notes can be a string
{ pattern: '[--xx]', notes: 'C4 Cm-4' }, // it can contain chord names
{ pattern: '[-xxx]', notes: ['E4', 'D#4'] }, // or an array
{ pattern: 'xxx', notes: scribble.scale('C minor') } // or the scale method
]
});
```
--------------------------------
### Create a clip and render a MIDI file with Scribbletune
Source: https://scribbletune.com/documentation
Creates a clip using the Scribbletune API, specifying notes from the C4 major scale and a pattern, then renders it as a MIDI file named c.mid. This is the minimal workflow: create a clip, then export it as MIDI.
```javascript
const scribble = require('scribbletune');
// Create a clip that plays the middle C
const clip = scribble.clip({
notes: scribble.scale('C4 major'),
pattern: 'xxxxxxx'
});
// Render a MIDI file of this clip
scribble.midi(clip, 'c.mid');
```
--------------------------------
### Create a basic clip with middle C
Source: https://scribbletune.com/documentation/core/clip
Creates a clip with a single note (C4) and a pattern of one quarter note. Renders a MIDI file named 'c.mid'.
```javascript
import { clip } from 'scribbletune';
// Create a clip that plays the middle C
const c = clip({
notes: 'C4',
pattern: 'x'
});
// Render a MIDI file of this clip
scribble.midi(c, 'c.mid');
```
--------------------------------
### Scribbletune CLI command format
Source: https://scribbletune.com/documentation/cli
Shows the general command format for the three main CLI commands: --riff, --chord, and --arp. Use this as a reference for the required positional arguments and where options go.
```bash
scribbletune --riff [options]
scribbletune --chord [options]
scribbletune --arp [options]
```
--------------------------------
### Handle MIDI bytes manually in browser
Source: https://scribbletune.com/documentation/core/midi
Passing null as the second argument to midi() returns raw bytes, allowing for custom download implementation via Blob and URL.createObjectURL.
```javascript
// Sample Clip that renders the C Major scale
const c = scribble.clip({
notes: scribble.scale('C4 major'),
pattern: 'x'.repeat(7)
});
// Get hold of the bytes from the scribble.midi method
// (passing null as the second argument returns bytes)
const b = scribble.midi(c, null);
// Convert bytes to array buffer
// Ref: Accepted answer on https://stackoverflow.com/questions/35038884/download-file-from-bytes-in-javascript
var bytes = new Uint8Array(b.length);
for (var i = 0; i < b.length; i++) {
var ascii = b.charCodeAt(i);
bytes[i] = ascii;
}
// Create a Blob so that we can set it up with the type of file we want (for eg MIDI)
var blob = new Blob([bytes], {type: "audio/midi"});
// Create a link element to be used (you can use an existing link on the page as well)
var link = document.createElement('a');
link.href = window.URL.createObjectURL(blob);
// Give your downloadable file a name
link.download = 'music.mid';
link.innerText = 'Download MIDI file';
document.body.appendChild(link);
```
--------------------------------
### midi(clip, filename?)
Source: https://scribbletune.com/documentation/core/midi
Generates a MIDI file from a clip. The first parameter is the clip array created by the clip method. The optional second parameter is the filename; if omitted, the file is named music.mid. In the browser, passing a filename creates a download href, while passing null returns bytes.
```APIDOC
## midi(clip, filename?)
### Description
Generates a MIDI file from a clip. The first parameter is the clip array created by the clip method. The optional second parameter is the filename; if omitted, the file is named music.mid. In the browser, passing a filename creates a download href, while passing null returns bytes.
### Method
midi
### Parameters
#### Parameters
- **clip** (Array) - Required - The clip that you create using the clip method.
- **filename** (String) - Optional - The name of the MIDI file to create. If not provided, the file will be called music.mid. In the browser, passing null returns bytes instead of a download href.
### Request Example
```
import { clip, progression, midi } from 'scribbletune';
const c = clip({
notes: 'c4',
pattern: 'x_______'
});
midi(c); // Will create a file called music.mid
// OR
midi(c, 'c.mid'); // Will create a file called c.mid
```
### Response
#### Success Response
- **filename** (String) - The name of the created MIDI file.
- **href** (String) - In the browser, a download href is generated when a filename is provided.
- **bytes** (String) - When null is passed as the filename, the method returns bytes.
#### Response Example
```
// In the browser, with a filename:
http://yourDomainOrLocalhost/5f9aa791-3509-4584-81aa-656c74597e98
// With null as filename:
// bytes are returned
```
```
--------------------------------
### Generate MIDI files with midi()
Source: https://scribbletune.com/documentation/core/midi
The midi method takes a clip object and an optional filename. If no filename is provided, it defaults to music.mid.
```javascript
import { clip, progression, midi } from 'scribbletune';
const c = clip({
notes: 'c4',
pattern: 'x_______'
});
midi(c); // Will create a file called music.mid
// OR
midi(c, 'c.mid'); // Will create a file called c.mid
```
--------------------------------
### Create anchor element for MIDI download
Source: https://scribbletune.com/documentation/core/midi
Use the generated URL in an anchor element with the download attribute to trigger a file download.
```html
Download MIDI file
```
--------------------------------
### Create a Scribbletune session
Source: https://scribbletune.com/documentation/browser/channel
Required before creating a channel. Loads the browser build of Scribbletune and creates a new session instance.
```javascript
const scribble = require('scribbletune/browser');
const session = new scribble.Session();
```
--------------------------------
### Create a clip with C major scale notes
Source: https://scribbletune.com/documentation/core/clip
Creates a clip with the C major scale notes in the 4th octave and a pattern of 8 quarter notes. Shows both string and array notation for notes.
```javascript
import { clip } from 'scribbletune';
// Create a clip that plays the C major scale
const c = clip({
notes: 'C4 D4 E4 F4 G4 A4 B4 C5', // Or ['C4', 'D4', 'E4' ...]
pattern: 'x'.repeat(8)
});
```
--------------------------------
### Progression input formats for --chord and --arp
Source: https://scribbletune.com/documentation/cli
Lists the accepted progression formats for --chord and --arp. Hyphenated roman numerals like I-IV-vi-V are not supported, and for explicit chords like CM-FM-Am-GM the root/mode are currently ignored.
```bash
1645 # degree digits
"I IV vi V" # roman numerals (space separated)
I,IV,vi,V # roman numerals (comma separated)
random # generated progression
CM-FM-Am-GM # explicit chord names
```
--------------------------------
### Custom arpeggio with count and order using scribble.arp
Source: https://scribbletune.com/documentation/core/arp
Creates an arpeggiated MIDI file using a custom chord progression obtained via getChordsByProgression, with count set to 3 and order '102' (so notes are reordered as 1, 0, 2). The clip uses a pattern of 'x-x_' repeated and a subdiv of '16n'. The output file is 'arp.mid'.
```javascript
const scribble = require('scribbletune');
// we can use scribbletune's getChordsByProgression method to get the chord progression i iv i iv i v i II
// from a C major scale on the fourth octave
const theChords = scribble.getChordsByProgression('C4 major', 'i iv i iv i v i II');
// This will return 'Cm Fm Cm Fm Cm Gm Cm DM'. Here 'm' stands for a minor chord and 'M' stands for a major chord.
const notesArr = scribble.arp({
chords: theChords, // you can even provide a string like 'Cm Fm Cm Fm Cm Gm Cm DM'
count: 3, // you can set any number from 2 to 8
// The default value of order is 0123 as count is 4 by default
// but here we set count to 3 hence we are only using the first 3 indices to set a order
order: '102' // Any number up to the `count`
// Here the `count` is 3, hence any combination of 0, 1 and 2
});
const c = scribble.clip({
notes: notesArr,
pattern: 'x-x_'.repeat(notesArr.length/2),
subdiv: '16n'
});
scribble.midi(c, 'arp.mid');
```
--------------------------------
### Pattern repeat helpers in CLI
Source: https://scribbletune.com/documentation/cli
Shows repeat helpers that can be used directly in CLI pattern input. Use these to repeat pattern segments without writing them out manually.
```bash
x.repeat(4) # -> xxxx
'x-x[xx]'.repeat(2)
2(x-x[xx]) # prefix repeat shorthand
(x-x[xx])2 # suffix repeat shorthand
```
--------------------------------
### Create a chord progression with clip
Source: https://scribbletune.com/documentation/core/chord
Use chord names directly in the notes array of the clip function. M stands for Major, m for minor. The pattern 'x---'.repeat(4) creates a four-beat pattern. The resulting clip is saved as 'chords.mid'.
```javascript
import { clip } from 'scribbletune';
const chordsClip = clip({
// Use chord names directly in the notes array
// M stands for Major, m stands for minor
notes: 'CM FM GM CM',
pattern: 'x---'.repeat(4),
});
midi(chordsClip, 'chords.mid');
```
--------------------------------
### Add a Kick Drum Channel to Session
Source: https://scribbletune.com/documentation/browser/session
Adds a channel with a kick drum sample and four clips, each with a pattern. The channel will play the kick.wav sample according to the provided patterns.
```javascript
session.createChannel({
sample: 'https://scribbletune.com/sounds/kick.wav',
clips: [
{ pattern: 'x' },
{ pattern: 'xxx[xx]' },
{ pattern: 'x' },
{ pattern: 'xxx[-x]' }
]
});
```
--------------------------------
### Reference Scribbletune via CDN
Source: https://scribbletune.com/documentation/installation
Include Tone.js and the precompiled Scribbletune script in your HTML file.
```html
```
--------------------------------
### Generate arpeggiated MIDI clip with scribble.arp
Source: https://scribbletune.com/documentation/core/arp
Creates a MIDI clip with an arpeggiated chord progression (CM FM CM GM) using the default arpeggio settings: 4 notes per chord, order 0-3, and quarter-note duration. The resulting file is saved as 'arp.mid'.
```javascript
const scribble = require('scribbletune');
const c = scribble.clip({
notes: scribble.arp('CM FM CM GM'),
pattern: 'x'.repeat(32)
});
scribble.midi(c, 'arp.mid');
```
--------------------------------
### Simple pattern with four quarter notes
Source: https://scribbletune.com/documentation/core/clip
A pattern of four quarter notes, each 'x' representing a note on event.
```text
xxxx
```
--------------------------------
### Browser MIDI download URL
Source: https://scribbletune.com/documentation/core/midi
Using the midi method with a filename in the browser generates a download href.
```text
http://yourDomainOrLocalhost/5f9aa791-3509-4584-81aa-656c74597e98
```
--------------------------------
### List Available Scales
Source: https://scribbletune.com/documentation/core/scale
Retrieves an array of all available scales supported by the underlying tonal library.
```javascript
const allScales = scribble.scales(); // returns an array of all the available scales from tonal
```
--------------------------------
### Use Global Scribbletune Object
Source: https://scribbletune.com/documentation/installation
Verify the global scribble object is available after CDN inclusion.
```javascript
console.log(scribble.scale('C4 major')); // outputs ['C4', 'D4', 'E4', 'F4', 'G4', 'A4', 'B4']
```
--------------------------------
### Retrieve a Scale via Mode
Source: https://scribbletune.com/documentation/core/scale
Shows how to retrieve a specific scale using the mode method.
```javascript
let cMinor = scribble.mode('C4 aeolian'); // [ 'C4', 'D4', 'D#4', 'F4' ...]
```
--------------------------------
### Generate chord progressions with scribble.progression
Source: https://scribbletune.com/documentation/core/progression
Generates an array of chord degrees for major or minor scales. The second parameter specifies the number of chords to return, with a recommended range of 2 to 8.
```javascript
const scribble = require('scribbletune'); // using es5 syntax
const majorChordProgression = scribble.progression('M'); // you can substitute M with lowercase major
const minorChordProgression = scribble.progression('m', 8);
// the second param here ^ allows you to set the number of chords to return
// currently a count of 2 to 8 works best
console.log(majorChordProgression); // something like [ 'I', 'ii', 'ii', 'V' ]
console.log(minorChordProgression); // something like [ 'i', 'VI', 'ii', 'V', 'ii', 'iv', 'iv', 'V', 'V' ]
```
--------------------------------
### Quote pattern with brackets in CLI
Source: https://scribbletune.com/documentation/cli
Shows how to quote a pattern that uses [ and ] (subdivisions) in the shell. Use this when your pattern contains brackets to prevent shell interpretation.
```bash
scribbletune --arp C3 major 'x-x[xx]-x-[xx]' 16n 1736
```
--------------------------------
### Translate chord degrees with getChordsByProgression
Source: https://scribbletune.com/documentation/core/progression
Translates a string of chord degrees into actual chords for a specific scale and root note, suitable for use in clip creation.
```javascript
import {clip, getChordsByProgression, midi} from 'scribbletune'; // this will need transpilation
const c = clip({
notes: getChordsByProgression('C4 major', 'I IV V ii'), // Here 4 is the octave
pattern: 'x_'.repeat(4) + 'x_______'
});
midi(c, 'chords.mid');
```
--------------------------------
### Combine accent and sizzle in a clip
Source: https://scribbletune.com/documentation/core/clip
Combines accent and sizzle: volumes become the average of the accent/amp values and the sizzle-computed values. The resulting volumes are 64, 40, 60, 122, 127, 74, 60, 88.
```javascript
import { clip } from 'scribbletune';
// Create a clip that plays the C major scale
const c = clip({
notes: 'C4',
pattern: 'x'.repeat(8),
accent: 'x--x',
amp: 127,
accentLow: 30,
sizzle: 'sin',
});
```
--------------------------------
### Retrieve chord degrees with getChordDegrees
Source: https://scribbletune.com/documentation/core/progression
Returns the available chord degrees for a specified scale or mode.
```javascript
const scribble = require('scribbletune'); // using es5 syntax again
console.log(scribble.getChordDegrees('minor')); // outputs [ 'i', 'ii°', 'III', 'iv', 'v', 'VI', 'VII' ]
```
--------------------------------
### Pattern with sustains
Source: https://scribbletune.com/documentation/core/clip
A pattern using underscores to sustain notes, creating longer durations.
```text
x__-x__-x__-x__-
```
--------------------------------
### Set subdiv to '16n' for faster arpeggio
Source: https://scribbletune.com/documentation/core/arp
Sets the subdivision (note duration) to sixteenth notes, making the arpeggio play faster than the default quarter notes. This property is used inside the clip configuration object.
```javascript
subdiv: '16n'
```
--------------------------------
### Use sizzleReps to repeat a volume shape
Source: https://scribbletune.com/documentation/core/clip
Creates a repeating volume shape: with sizzleReps set to 4, the clip applies the sizzle pattern to groups of 4 notes, repeating it across the clip. The sizzle property accepts true, 'sin', 'cos', 'rampUp', or 'rampDown'.
```javascript
import { clip } from 'scribbletune';
// Create a clip that plays the C major scale
const c = clip({
notes: 'C4',
pattern: 'x'.repeat(8),
sizzle: 'rampUp',
sizzleReps: 4
});
```
--------------------------------
### Add a clip to an existing channel
Source: https://scribbletune.com/documentation/browser/channel
Adds a new clip to the channel at the specified index. If no index is provided, the clip is appended to the end of the clips array.
```javascript
const params = { pattern: 'xx[xx]'};
bassChannel.addClip(params, 4);
```
--------------------------------
### Set subdiv to 8n in a Scribbletune clip
Source: https://scribbletune.com/documentation/core/clip
Sets the duration of each pattern step to an eighth note. Valid subdiv values include 1m, 2m, 3m, 4m, 1n, 2n, 4n, 8n, and 16n; the default is 4n (quarter note).
```javascript
import { clip } from 'scribbletune';
// Create a clip that plays the C major scale
const c = clip({
notes: 'C4',
subdiv: '8n', // the default it a quarter note
pattern: 'xx_[xx]'
});
```