WLJS LogoWLJS Notebook

SoundNote

SoundNote[note]
SoundNote[note, duration]
SoundNote[note, {start, end}]
SoundNote[note, duration, instrument]

represents one pitched sound event.

note can be a named pitch such as "C4", a semitone integer, or a list of pitches. A list of pitches is played simultaneously:

Sound[SoundNote[{"E4", "G#4", "B4"}]]

When duration is a number or a Tone duration such as "4n", notes in a surrounding list are scheduled sequentially. {start, end} places a note explicitly on the sound timeline.

Sound[{
  SoundNote["C4", {0., .5}],
  SoundNote["E4", {.5, 1.}],
  SoundNote["G4", {1., 1.5}]
}]

Instruments

The third argument selects the playback instrument:

Sound[{
  SoundNote["C4", {0., .5}, "Flute"],
  SoundNote["E4", {.5, 1.}, "Trumpet"],
  SoundNote["G4", {1., 1.5}, "Violin"]
}]

WLJS maps common Wolfram instrument names to cached Tone.js synths. Explicit Tone voice names are also accepted:

  • "Piano", "Guitar", "Violin" and "Flute"
  • "Trumpet", "Organ", "Marimba", "Vibraphone" and "Drums"
  • "Synth", "AMSynth", "FMSynth", "DuoSynth", "MembraneSynth" and "MetalSynth"

Unknown names fall back to Tone.Synth.

Piano-roll preview

All notes are evaluated before the player is drawn. The preview can therefore show symbolic or offloaded pitch values, chord members, note lengths and instruments without triggering playback.

Long sequences remain at their natural width and can be scrolled horizontally.

Methods

Wrap a SoundNote, or a list of notes, in Sound to display and play it:

Sound[{
  SoundNote[{"A4", "C4"}],
  SoundNote["E4"],
  SoundNote["G4"],
  SoundNote["C5"]
}]

On this page