Here's the simplest example of combining Lua with our musicAPI. Since our docs are generally focused on JavaScript, these working examples are the best way to understand the mapping between the docs and the conditions on the moon (Lua is Moon in Portuguese).
local Ascene = require("ascene")
Ascene:init(function(scene) -- initialize the audio engine, callback when ready.
-- instantiate and connect some Anodes
local inst = scene:newAnode("Hz.Syntho")
local dac = scene:newAnode("dac")
scene:connect(inst, dac)
scene:begin() -- asynchronously wait for scene to be ready
local baseNote = 30 -- a midi note number
local waittime = scene:seconds(.25)
for i=0,23 do -- generate some notes
local note = baseNote + i
inst:noteOn(note, .9) -- initiate the note with velocity .9
scene:wait(waittime) -- synchronously wait while note plays.
inst:noteOff(note, 1)
end
Log.notice("done")
end)
We've included a number of additional small examples in the firstlua
subdirectory for your perusal. Some of them assume the presence of
a MIDI input device and some assume the present of one or more
third-party CLAP plugins.
fluidVoices.lua
- requires FluidSynth.clap and generates notes in
each of its 128 voices.fluidMidi.lua
- shows how to read MIDI input and play notes.threeSynths.lua
- shows how to control independent coroutines
associated with 3 different synths. tonal.lua
- shows a trivial use of the Tonal(.lua) module.voices.lua
- a simple example of Voices API.