Using notation with Python
pynotation is notation for Pyctures scenes. It has the same names as notation.js, spelled Python's way, and it draws the same music: the page in the browser is drawn by notation.js itself, which pynotation carries inside it.
from pyctures import *
from synths import *
from pynotation import *
page = show_notes("C4 C4 G4 G4 A4 A4 G4:2", "quarter", tempo=100, title="Twinkle")
def on_mouse_down(x, y):
page.play()
def draw():
background("midnightblue")
What is different
The names have underscores. showNotes is show_notes, makeSheet is make_sheet, page.playAlong is page.play_along, page.onNote is page.on_note, and the options barNumbers, rowsPerBeat, anyOctave and countIn are bar_numbers, rows_per_beat, any_octave and count_in.
Options are given by name, where JavaScript has a last { ... }:
show_notes("C4 E4 G4", "quarter", key="G", at="bottom", paper="dark", bar_numbers=False)
from pynotation import * is all a scene needs. It brings the sound with it, so the page is heard with nothing else imported. from synths import * is still wanted for play_song, make_synth and the rest of the sound names.
A song is shown by its name. show_notes("songs/night_drive.json", channels=[3, 1]) reads the file from beside the scene. A song as a dictionary works too.
page.play starts with start, where JavaScript has from (a word Python keeps for itself): page.play(start=8).
page.play_along takes the mode first: page.play_along("wait", synth=lead), page.play_along("time", tempo=60).
page.place takes the place first: page.place("bottom"), or page.place(x=20, y=20, width=400, height=200).
What the page says comes back a frame later. The music is written and drawn in the browser, and Python keeps a small object that stands for it. page.beat, page.bar, page.sounding and page.result are what the page last said, so they are read and not set. A keyboard from pydials tied to the page (keyboard(page)) plays it in the page itself, so a key is marked the moment it is touched.
A mistake in the music is said by the page. A note that is not a note, or a clef that is not a clef, is found when the page writes the music out, a moment after Python has gone on. A mistake in an option's name is Python's own error, at once.
A sheet
sheet = make_sheet(key="G", time="3/4", tempo=132, title="Waltz")
sheet.add("D4", "quarter").add(["B4", "D5"], "half").rest("quarter")
for name in ["G4", "A4", "B4"]:
sheet.add(name, "eighth")
show_notes(sheet)
What a note is given as
page = show_notes("C4 E4 G4 C5", "quarter")
def began(note):
print(note.name, note.note, note.start, note.length)
page.on_note = began