Console Commands: Difference between revisions

Jump to navigation Jump to search
m
grammar formalised
(Finish off advanced techniques.)
m (grammar formalised)
Line 1: Line 1:
'''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.
'''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 [https://developer.mozilla.org/en-US/docs/Learn/JavaScript/First_steps learning some JS].
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 copying/pasting the commands on this page, try [https://developer.mozilla.org/en-US/docs/Learn/JavaScript/First_steps learning some JS].


It's important to keep a few things in mind when using the console:
It's important to keep a few things in mind when using the console:
Line 8: Line 8:
* 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.
* 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.
* 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)".
* Instruments are identified using a number, also known 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 ==
== Basic techniques ==
Line 46: Line 46:
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.
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 [https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Default_parameters 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()".
In JS, function parameters can have [https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Default_parameters 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()".


The functions in this section are defined [https://onlinesequencer.net/app/consoleCommands.js here]. If you know some JS, you can read this file to learn how they work and create your own.
The functions in this section are defined [https://onlinesequencer.net/app/consoleCommands.js here]. If you know some JS, you can read this file to learn how they work and create your own.
Line 54: Line 54:
  fadeNotes()      // Fade out
  fadeNotes()      // Fade out
  fadeNotes(true)  // Fade in
  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.
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 the original volume.


Includes undo/redo support.
Includes undo/redo support.
Line 60: Line 60:
=== Stretch notes ===
=== Stretch notes ===
  stretchNotes(factor)
  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.
Stretches or squishes the selected segment by the given factor. A factor of 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.
It also works on selected markers, but since marker times are quantized to whole number of 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.
Includes undo/redo support.
Line 74: Line 74:
=== Convert to detune markers ===
=== Convert to detune markers ===
  convertToDetuneMarkers(startNote = 'C5')
  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.
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 are 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.
Due to the limitations of detune markers, this will only work if the melody sticks to whole number of 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.
Includes undo/redo support.
Line 90: Line 90:
=== Remix notes ===
=== Remix notes ===
  remixNotes(chunkSize = 4, avgChunksPerUnmixedSection = 2, avgChunksPerMixedSection = 2, avgMixedSectionsPerUnmixedSection = 1)
  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.
Divides the selected segment into chunks and mix 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.
Includes undo/redo support.
Line 123: Line 123:
  selectNotesIf(predicate, addToSelection = false)
  selectNotesIf(predicate, addToSelection = false)
  selectMarkersIf(predicate, addToSelection = false)
  selectMarkersIf(predicate, addToSelection = false)
These functions take a predicate (a function that returns true or false) and select all the notes or markers for which the predicate returns true. If addToSelection is true, these notes or markers are added to the existing selection, otherwise they replace the current selection. Both these functions include undo/redo support.
These functions take a predicate (a function that returns true or false) and select all the notes or markers for which the predicate returns true. If addToSelection is true, these notes or markers are added to the existing selection, otherwise, they replace the current selection. Both these functions include undo/redo support.


For example, say you wanted to delete the [https://tiusic.com/thumb.html thumbnail] notes from a sequence, so you can change the thumbnail. Thumbnail notes all have 0 volume, so you can just select all the notes with 0 volume:
For example, say you wanted to delete the [https://tiusic.com/thumb.html thumbnail] notes from a sequence, so you can change the thumbnail. Thumbnail notes all have 0 volume, so you can just select all the notes with 0 volume:
Line 131: Line 131:
=== Tweaking notes ===
=== Tweaking notes ===
  tweakNotes(tweakFunction)
  tweakNotes(tweakFunction)
This is probably the single most useful console function. It basically runs tweakFunction on every selected note, and has undo/redo support for any changes that tweakFunction makes to the note. It's roughly equivalent to:
This is probably the single most useful console function. It basically runs tweakFunction on every selected note and has undo/redo support for any changes that tweakFunction makes to the note. It's roughly equivalent to:
  for (const note of selection.notes) {
  for (const note of selection.notes) {
   tweakFunction(note);
   tweakFunction(note);
  }
  }
There are a few problems with doing a for loop like this and manually tweaking the notes. For starters you won't get undo/redo support, but the bigger problem is that there are a few optimizations that OS does based on the note time, instrument, length, or pitch that require extra work if you modify those parameters (namely "song.moveNote()" and "song.updateLoopTime()"). Failure to do so could corrupt your sequence. tweakNotes takes care of this work for you so you don't have to worry about it.
There are a few problems with doing a for loop like this and manually tweaking the notes. For starters, you won't get undo/redo support, but the bigger problem is that there are a few optimizations that OS does base on the note time, instrument, length, or pitch that require extra work if you modify those parameters (namely "song.moveNote()" and "song.updateLoopTime()"). Failure to do so could corrupt your sequence. tweakNotes takes care of this work for you so you don't have to worry about it.


The fields of the note object that you can modify are:
The fields of the note object that you can modify are:
Line 247: Line 247:
   song.addNote(new Note(song, 'CDEFGAB'[Math.floor(Math.random() * 7)] + '4', i, 1, instrument, 1));
   song.addNote(new Note(song, 'CDEFGAB'[Math.floor(Math.random() * 7)] + '4', i, 1, instrument, 1));
  }
  }
Whenever you make changes to the notes of a sequence (adding, removing, moving, etc), the changes won't be visible until the sequencer view is updated. You can either run "SequencerView.repaint()", or just move the view a bit (eg scroll). tweakNotes handles this for you, but in this example you need to do it manually.
Whenever you make changes to the notes of a sequence (adding, removing, moving, etc), the changes won't be visible until the sequencer view is updated. You can either run "SequencerView.repaint()", or just move the view a bit (eg scroll). tweakNotes handles this for you, but in this example, you need to do it manually.


Adding notes like this doesn't have undo/redo support.
Adding notes like this doesn't have undo/redo support.
36

edits

Navigation menu