24
edits
(Missed a line of code) |
(Finish off advanced techniques.) |
||
Line 143: | Line 143: | ||
!Type | !Type | ||
!Description | !Description | ||
!Can modify? | |||
|- | |- | ||
|instrument | |instrument | ||
|Integer | |Integer | ||
|The instrument id, eg 22 for sitar | |The instrument id, eg 22 for sitar | ||
|Only with tweakNotes | |||
|- | |- | ||
|type | |type | ||
|String | |String | ||
|The pitch or keyboard note, eg 'C5' or 'F#7' | |The pitch or keyboard note, eg 'C5' or 'F#7' | ||
|Only with tweakNotes | |||
|- | |- | ||
|time | |time | ||
|Number | |Number | ||
|The time when the note starts in standard time units (quarter notes) | |The time when the note starts in standard time units (quarter notes) | ||
|Only with tweakNotes | |||
|- | |- | ||
|length | |length | ||
|Number | |Number | ||
|The length of the note in standard time units | |The length of the note in standard time units | ||
|Only with tweakNotes | |||
|- | |- | ||
|volume | |volume | ||
|Number | |Number | ||
|The volume of the note, usually from 0 to 1. | |The volume of the note, usually from 0 to 1. | ||
|Always | |||
|} | |} | ||
If you console.log the note you'll see other internal fields, but '''DO NOT MODIFY THESE'''. | If you console.log the note you'll see other internal fields, but '''DO NOT MODIFY THESE'''. | ||
Line 202: | Line 208: | ||
|Integer | |Integer | ||
|The instrument id, eg 19 for xylophone | |The instrument id, eg 19 for xylophone | ||
| | |Never | ||
|- | |- | ||
|time | |time | ||
|Integer | |Integer | ||
|The marker's time (quarter notes, must be a whole number) | |The marker's time (quarter notes, must be a whole number) | ||
| | |Never | ||
|- | |- | ||
|setting | |setting | ||
|Integer | |Integer | ||
|The setting (one of the kMarkerSetting... constants, eg kMarkerSettingBpm) | |The setting (one of the kMarkerSetting... constants, eg kMarkerSettingBpm) | ||
| | |Never | ||
|- | |- | ||
|value | |value | ||
|Dynamic | |Dynamic | ||
|The marker value. Its type depends on the marker setting. | |The marker value. Its type depends on the marker setting. | ||
| | |Always | ||
|- | |- | ||
|blend | |blend | ||
|Boolean | |Boolean | ||
|Whether or not the marker is blended. | |Whether or not the marker is blended. | ||
| | |Always | ||
|} | |} | ||
With these limitations, the most useful thing you can do is set the marker value to a value outside the normal range (like we did for the instrument settings above). This snippet sets all the selected detune markers to detune up by 2 octaves: | With these limitations, the most useful thing you can do is set the marker value to a value outside the normal range (like we did for the instrument settings above). This snippet sets all the selected detune markers to detune up by 2 octaves: | ||
Line 230: | Line 236: | ||
} | } | ||
} | } | ||
If you really need to change the instrument, time, or setting, delete the marker and create a new one (see below for details). | |||
You can also use "song.getAllMarkersAtTime(t)" to get a list of all the markers at a specific time, but selecting them in the UI and then iterating over "selection.markers" is easier. | You can also use "song.getAllMarkersAtTime(t)" to get a list of all the markers at a specific time, but selecting them in the UI and then iterating over "selection.markers" is easier. | ||
=== Creating and deleting notes == | === Creating notes === | ||
You can create Note objects using "new Note", but you also have to manually add them to the song, like so: | |||
song.addNote(new Note(song, type, time, length, instrument, volume)) | |||
For example, let's generate a random melody: | |||
for (let i = 0; i < 16; ++i) { | |||
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. | |||
Adding notes like this doesn't have undo/redo support. | |||
=== Deleting notes === | |||
If you have a Note object, you can remove it from the sequence like this: | |||
song.removeNote(note) | |||
This doesn't actually delete the Note object, just removes it from the sequence. In fact you can add it again if you want, using "song.addNote(note)". | |||
Let's take another look at our earlier example, where we wanted to delete the thumbnail notes. Instead of using selectNotesIf and then manually deleting them, we could automatically delete them. | |||
for (const note of song.notes) { | |||
if (note.volume == 0) { | |||
song.removeNote(note); | |||
} | |||
} | |||
Removing notes like this doesn't have undo/redo support. | |||
=== Creating | === Creating markers === | ||
addMarker(time, setting, instrument, value, blend) | |||
This function adds a marker to the song. The parameters are the same as in the marker field table above. Returns the newly created Marker object. Includes undo/redo support. | |||
=== | === Deleting markers === | ||
removeMarker(marker) | |||
Removes the marker from the sequence. Includes undo/redo support. |