aboutsummaryrefslogtreecommitdiff
path: root/example
diff options
context:
space:
mode:
authorgretchen <gretchen@gnar.cool>2019-11-18 19:07:08 -0800
committergretchen <gretchen@gnar.cool>2019-11-18 19:07:08 -0800
commit91371d9c906e2864c6917b472627fc00c04cd880 (patch)
tree8c80705510c2c94d88176d08309e826244f81ded /example
parentf8dffe603a9573e80ff0efdc118b26d13fda5b3a (diff)
downloadnorns-etc-master.tar.gz
norns-etc-master.zip
Ok, last silly thing: random scaleHEADmaster
Diffstat (limited to 'example')
-rw-r--r--example/example.lua34
1 files changed, 26 insertions, 8 deletions
diff --git a/example/example.lua b/example/example.lua
index 73841c6..45056c3 100644
--- a/example/example.lua
+++ b/example/example.lua
@@ -3,26 +3,44 @@
local MusicUtil = require "musicutil"
engine.name = "PolyPerc"
+scale = nil
+
function redraw()
screen.clear()
screen.move(64, 32)
- screen.text_center("norns example #" .. math.floor(math.random() * 1000))
+ screen.text_center(scale.name)
screen.update()
end
function init()
+ -- random scale output, just to emphasize the point
+ local base = 60
+ scale = MusicUtil.SCALES[math.random(1, #MusicUtil.SCALES)]
redraw()
- -- random note output, just to emphasize the point
- local note = math.random(60, 90)
- engine.hz(MusicUtil.note_num_to_freq(note))
+
+ local notes = {}
+ for _, interval in pairs(scale.intervals) do
+ table.insert(notes, base + interval)
+ end
+
local m = midi.connect(2)
local c = metro.init()
- c.time = 0.5
+ c.time = 0.2
+ local on = false
c.event = function ()
- c:stop()
- metro.free(c.id)
- m:note_off(note, 10)
+ if #notes == 0 then
+ c:stop()
+ elseif not on then
+ on = true
+ local here = notes[1]
+ engine.hz(MusicUtil.note_num_to_freq(here))
+ m:note_on(here, 20)
+ else
+ on = false
+ local here = table.remove(notes, 1)
+ m:note_off(here, 20)
+ end
end
m:note_on(note, 20)
c:start()