Console Commands

From Online Sequencer Wiki
Revision as of 20:06, 2 January 2023 by Liam (talk | contribs) (Fill in intermediate techniques.)
Jump to navigation Jump to search

Console Commands extend the functionality of the sequencer beyond what is possible with the UI. To access the console, press Ctrl + Shift + J for Chromium browsers, or Ctrl + Shift + K for Firefox.

To run a command using the console, just type it in and press enter. The console executes JS code, so if you want to go beyond copy/pasting the commands on this page, try learning some JS.

It's important to keep a few things in mind when using the console:

  • Not all of the commands below have undo/redo support. So if you make a change it might not be possible to undo it.
  • It's possible to corrupt your sequence using the console. So if you're new to this it's highly recommended that you save your sequence before messing with the console.
  • The fundamental time units used by the sequencer are quarter notes, starting at 0. So t=10 would mean the half beat after the second beat. If you set the grid to 1/4 (the default) the grid lines match this time unit. Markers can be placed at t=0, 1, 2, etc.
  • Instruments are identified using a number, also know as the id. The current instrument is stored in the global variable "instrument". So to figure out the number for an instrument, just choose that instrument in the UI, type "instrument", and press enter. You can also just pass "instrument" directly to use the current instrument, eg "setDetune(instrument, 1200)".

Basic techniques

You can change a lot of the sequencer options in the console. This can be useful to go beyond the values usually allowed in the UI.

Grid

setGrid(value)

Changes the size of the grid. The way the value works is a bit confusing: it's the number of grid lines per time unit (per quarter note). So a 1/4 grid has a value of 1, and a 1/8 grid has a value of 2. You can use this formula to work out the value: value = 0.25 / grid. No undo/redo support.

Time signature

setTimeSig(timeSig)

Sets the time signature of the sequence. Time signatures on OS are always N/4 (so 3/4, 4/4, 5/4 etc), and the timeSig parameter is just the N. So to set the time signature to 7/4, use "setTimeSig(7)". If you want something more exotic, you'll need to find the closest equivalent in N/4. So 6/8 could be represented as 3/4, and 7/16 could be represented as 7/4 with a faster tempo. No undo/redo support.

Detune

setDetune(instrument, detune)

Sets the detune of an instrument. Detune values are measured in cents, where each semi-tone is 100 cents. So to detune a full octave up, set the detune to 1200. The usual limit in the UI is -1200 to 1200, but you can use this function to set it to more extreme values. No undo/redo support.

WARNING: Firefox does not support detunes outside -1200 to 1200, so using extreme values will mean your sequence will only play correctly on Chromium browsers.

Reverb and distortion

setReverbVolume(instrument, volume)
setDistortVolume(instrument, volume)

Sets the reverb volume and distort volume of an instrument. The volume goes from 0 to 1 in the UI, but you can set it to whatever you like using these functions. No undo/redo support.

Equalizer

setEqHigh(instrument, value)
setEqMid(instrument, value)
setEqLow(instrument, value)

Sets the EQ of an instrument. The values only go from -48 to 48 in the UI, but you can set them to any value using these functions. No undo/redo support.

Panning

setPan(instrument, value)

Sets the panning of an instrument. The value can go from -1 to 1 in the UI, but this function can set it to anything. No undo/redo support.

Intermediate techniques

Most of these functions act on the currently selected notes. Select the notes you want to edit, then run the function in the console. I refer to the sequence of selected notes as the selected segment.

In JS, functions parameters can have default values. This means if you don't pass a value to that parameter, it will default to some value. A lot of the functions in this section have default parameters. They're written in the documentation like this: "fadeNotes(fadeIn = false)". This means the "fadeIn" parameter defaults to false, so instead of writing "fadeNotes(false)" you can just write "fadeNotes()".

Fade notes

fadeNotes(fadeIn = false)
fadeNotes()      // Fade out
fadeNotes(true)  // Fade in

Fades the selected notes in or out (that is, it sets the volumes of the notes based on their position in the segment). The function takes a single parameter, "fadeIn" which defaults to false. In other words it fades the notes from their original volume to 0 by default, or if you pass "true" it fades in the segment from 0 volume to original volume.

Includes undo/redo support.

Stretch notes

stretchNotes(factor)

Stretches or squishes the selected segment by the given factor. A factor more than 1 will make the selected segment longer, and less than 1 will make it shorter. A factor less than 0 will reverse the segment.

It also works on selected markers, but since marker times are quantized to whole number times, they might not be moved to exactly the right spot. Also, reversing markers is complicated, and not all marker sequences are reversible, so negative factors are not supported if you have markers selected.

Includes undo/redo support.

Truncate notes

truncateNotesAt(time)

Cuts off all the selected notes at the specified time. If a note extends past this time, its length will be truncated. If a note begins after this time it will be deleted.

Includes undo/redo support.

Convert to detune markers

convertToDetuneMarkers(startNote = 'C5')

Moves all the selected notes to the "startNote", then creates detune markers to detune each note back to its original pitch. For example, if you select a "D5" and then run this with the default startNote, it will move the note to "C5" and create a detune marker to detune it up 200 cents back to "D5". This is useful for making clear melodies on instruments that get muddy when there's a lot of notes.

Due to the limitations of detune markers, this will only work if the melody sticks to whole number time steps (ie lines up with the quarter note grid), and there's only ever one note at a particular time. This function ignores drum kit instruments.

Includes undo/redo support.

Humanize

humanize(volumeVariation = 0.2, timeVariation = 0.1)

Randomly alters the volume and start time of all the selected notes by a small amount. This is designed to simulate a human playing the sequence. You can choose your own variation amounts, or just run "humanize()" to use the defaults.

Each note volume is multiplied by a random value between 1 - volumeVariation and 1 + volumeVariation (so 0.8 to 1.2 by default). Each note start time is shifted by a random value between -timeVariation and timeVariation (ie timeVariation is measured in quarter notes).

Includes undo/redo support.

Remix notes

remixNotes(chunkSize = 4, avgChunksPerUnmixedSection = 2, avgChunksPerMixedSection = 2, avgMixedSectionsPerUnmixedSection = 1)

Divides the selected segment into chunks and mixes them around. This is mainly just for fun, but can be handy to generate a breakdown by remixing a drum loop, or to reshuffle a melody if you need a bit of inspiration. The chunkSize parameter controls how large the chunks are (in quarter notes), and the other parameters control how the chunks are mixed up.

Includes undo/redo support.

Reset all instrument settings

resetAllInstrumentSettings()

Resets the settings of all the instruments in the sequence.

WARNING: No undo/redo support.

removeAllMarkers()

Deletes all the markers in the sequence.

WARNING: No undo/redo support.

Advanced techniques

You will need to know a little JS to use these functions. In particular, we're going to be using a lot of lambda functions, so familiarize yourself with these first. This section also assumes you know basic programming concepts like variables, objects, loops, and if statements.

Selecting notes and markers

selectNotesIf(predicate, addToSelection = false)
selectMarkersIf(predicate, addToSelection = false)

Tweaking notes

tweakNotes(tweakFunction)

Tweaking markers

Creating and deleting notes

Creating and deleting markers

Other handy tools

selection