Playing and Following
showNotes gives back the page of music. The page can play its music, follow something else that plays, and tell your scene what is happening.
The programs on this page are parts of a scene: in JavaScript the names are ready with nothing to import, and in Python a scene begins with from pynotation import * (and from synths import * where it makes a synth or plays a song).
Play the page
const page = showNotes("C4 C4 G4 G4 A4 A4 G4:2", "quarter", { tempo: 100 })
function onMouseDown() {
if (page.playing) page.stop()
else page.play()
}page.play() plays the music and follows it: the notes that are sounding turn orange, a line moves through the bar, and the page turns when the music reaches the next line. page.stop() stops, and puts everything back to plain ink.
Two notes joined by a curved line are one note, held: that is a tie, and it is how a note is written when it lasts across a beat or a bar line. Both light together and you hear one sound.
| JavaScript | Python | What it does |
|---|---|---|
page.play({ from: 8 }) | page.play(start=8) | Starts eight beats in |
page.play({ tempo: 90 }) | page.play(tempo=90) | Plays at 90 beats a minute |
page.play({ repeat: true }) | page.play(repeat=True) | Plays it round and round |
Drag the music with a finger, or turn the mouse wheel, to look ahead; it goes back to following a moment later.
The sound it plays through
A page plays through the scene's own sound, and there is nothing to hand over: a scene that shows music has the sound as well, in JavaScript and in Python. page.play() is heard, and a tapped note sounds.
page.play() before the first click, tap or key press waits, and begins when the sound is on.
The option voice chooses the ready-made synth the page plays on, and synth gives it a synth of yours:
const lead = makeSynth("lead")
lead.echo = 0.3
showNotes("C4 E4 G4 C5:2", "quarter", { synth: lead })
showNotes("C3 G3 C3 G3", "quarter", { voice: "bell", at: "bottom" })Time is never kept by the page. Where the music has got to is read every frame from what is followed: a song's place, or the sound library's clock. So the notes that light are the notes you hear, however busy your scene is.
Follow something else that plays
const song = playSong("songs/night_drive.json")
const page = showNotes(await loadJSON("songs/night_drive.json"), { channels: [3] })
page.follow(song)page.follow takes a song from playSong, or a function that gives how many beats have gone by. The option follow does the same from the start: showNotes(written, { follow: song }).
When a note begins
const page = showNotes("C4 E4 G4 C5", "quarter")
let size = 20
page.onNote = (note) => { size = note.note }
page.onBar = (bar) => console.log("bar", bar)
page.onDone = () => console.log("the end")
function draw() {
background("midnightblue")
circle(width / 2, height * 0.75, size, "gold")
}| JavaScript | Python | When it is called |
|---|---|---|
page.onNote | page.on_note | A note has just begun. It is given the note: note.note (its number, where 60 is middle C), note.notes (a chord's), note.name, note.start, note.length, note.staff |
page.onBar | page.on_bar | A bar has just begun |
page.onTap | page.on_tap | A note was tapped (what.name), or a bar (what.bar) |
page.onDone | page.on_done | The music the page was playing has ended |
Everything a page has
| JavaScript | Python | What it is |
|---|---|---|
page.play(), page.stop() | the same | Play it and follow it; stop |
page.playing | the same | Is it playing? |
page.follow(song) | the same | Follow something else that plays |
page.beat, page.bar | the same | Where the music has got to. In JavaScript page.beat = 12 puts the line there |
page.sounding | the same | The notes sounding now, as numbers |
page.seek(5) | the same | Go to bar 5 |
page.show(music) | the same | Show other music in its place |
page.zoom = 1.5 | the same | Change its size |
page.place({ at: "bottom" }) | page.place("bottom") | Change its place |
page.x, page.y, page.width, page.height | JavaScript only | Where it is in the scene, for drawing around it |
page.remove() | the same | Take it away |
const page = showNotes("C4 D4 E4 F4 G4 A4 B4 C5", "quarter")
page.zoom = 1.5
page.place({ at: "bottom" })
page.seek(2)
page.show("G4 E4 C4:2", "quarter")Related
- What you can show
- Playing along
- Songs: playing a tracker song