ABC Notation is a popular text-based notation for music. Many software applications already exist to e.g. convert to MIDI or typeset a musical score.
We can use ABC in scripts to create a Midi.Pattern or an entire Midi.Tune. In this example we'll create a Midi.Tune from a string that contains music written in ABC, in this case a short phrase by J.S.Bach.
We do this by putting the ABC in a multiline string and then using the Midi.ABCReader readTune method:
local abcTune = Midi.ABCReader().readTune(@" X:1 T:Minuet (Bach) C:J.S. Bach M:3/4 L:1/8 K:D A2DEFG|A2D2D2|B2GABc|d2D2D2|G2AGFE|F2GFED|E2DEFD|E2AGFE| A2DEFG|A2D2D2|B2GABc|d2D2D2|G2AGFE|F2GFED|E2FEDE|D6|| ")
Now the abcTune variable holds our new Midi.Tune, we can get information on the tune by calling various methods.
First we'll call for the title, and print it out:
local title = abcTune.title()
print("Now playing: " + title + "\n")
Now we call the timeSignature method to get the time signature which is 3/4 time as designated in the "M:" field of the original notation.
local timeSignature = abcTune.timeSignature()
Once we have this time signature we'll create a system TransportMaster and set it to that same time signature:
local master = Transport.Master(110) master.timeSignature(timeSignature)
To actually play the notes from the tune, we'll first create a plugin synthesizer and connect it to the system outputs:
local synth = Lv2.Plugin("http://calf.sourceforge.net/plugins/Monosynth", "Square Worm")
local output = Audio.StereoOutput("main", "system:playback_1", "system:playback_2")
output.connect(synth)
We can retrieve the notes from the tune as via the track method which returns the given track as a Midi.Pattern:
local pattern = abcTune.track(1)
Now we can schedule the pattern to play on the synthesizer starting from the first measure of the transport:
synth.schedule(pattern, 1)
local abcTune = Midi.ABCReader().readTune(@"
X:1
T:Minuet (Bach)
C:J.S. Bach
M:3/4
L:1/8
K:D
A2DEFG|A2D2D2|B2GABc|d2D2D2|G2AGFE|F2GFED|E2DEFD|E2AGFE|
A2DEFG|A2D2D2|B2GABc|d2D2D2|G2AGFE|F2GFED|E2FEDE|D6||
")
local title = abcTune.title()
print("Now playing: " + title + "\n")
local timeSignature = abcTune.timeSignature()
local master = Transport.Master(110)
master.timeSignature(timeSignature)
local synth = Lv2.Plugin("http://calf.sourceforge.net/plugins/Monosynth", "Square Worm")
local output = Audio.StereoOutput("main", "system:playback_1", "system:playback_2")
output.connect(synth)
local pattern = abcTune.track(1)
synth.schedule(pattern, 1)
This work is licensed under a
Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.