experimenting with the idea of a declarative style midi processing chain
| engine.name = 'PolySub' | |
| local midi = require 'ngwese/midi_process' | |
| chain = midi.Chain{ | |
| midi.Logger(), | |
| midi.Held(), | |
| midi.Pattern{ | |
| pattern = 'as-played' | |
| }, | |
| midi.Arp{ | |
| octaves = 1 | |
| }, | |
| midi.Logger(), | |
| midi.Behavior{ | |
| note_on = function(ch, num, vel) | |
| local pitch = midi.to_hz(num) | |
| engine.start(midi.to_id(ch, num), pitch) | |
| end, | |
| note_off = function(ch, num, vel) | |
| engine.stop(midi.to_id(ch, num)) | |
| end, | |
| pitch_bend = function(ch, value) | |
| local v = midi.to_bend_range(value) | |
| engine.shape(math.abs(v) * 0.7) | |
| end, | |
| channel_pressure = function(ch, value) | |
| local f = value / 127 | |
| engine.noise(f * 0.2) | |
| engine.fgain((f * 0.7) + 0.2) | |
| engine.timbre(f * 0.7) | |
| end, | |
| }, | |
| } | |
| clock = midi.Clock{ | |
| interval = midi.bpm_to_sec(120, 16), | |
| chain = chain, | |
| } | |
| input1 = midi.Input{ | |
| device = "AXIS-64 USB Keyboard", | |
| chain = chain, | |
| } | |
| input2 = midi.Input{ | |
| device = "TOUCHE", | |
| chain = chain, | |
| } | |
| init = function() | |
| midi.init() | |
| -- configure engine | |
| engine.level(0.2) | |
| engine.stopAll() | |
| -- register parameters | |
| params:add_control("shape", controlspec.new(0,1,"lin",0,0,"")) | |
| params:set_action("shape", function(x) engine.shape(x) end) | |
| params:add_control("timbre", controlspec.new(0,1,"lin",0,0.5,"")) | |
| params:set_action("timbre", function(x) engine.timbre(x) end) | |
| params:add_control("noise", controlspec.new(0,1,"lin",0,0,"")) | |
| params:set_action("noise", function(x) engine.noise(x) end) | |
| params:add_control("cut", controlspec.new(0,32,"lin",0,8,"")) | |
| params:set_action("cut", function(x) engine.cut(x) end) | |
| params:add_control("fgain", controlspec.new(0,6,"lin",0,0,"")) | |
| params:set_action("fgain", function(x) engine.fgain(x) end) | |
| params:add_control("cutEnvAmt", controlspec.new(0,1,"lin",0,0,"")) | |
| params:set_action("cutEnvAmt", function(x) engine.cutEnvAmt(x) end) | |
| params:add_control("detune", controlspec.new(0,1,"lin",0,0,"")) | |
| params:set_action("detune", function(x) engine.detune(x) end) | |
| params:add_control("ampAtk", controlspec.new(0.01,10,"lin",0,0.05,"")) | |
| params:set_action("ampAtk", function(x) engine.ampAtk(x) end) | |
| params:add_control("ampDec", controlspec.new(0,2,"lin",0,0.1,"")) | |
| params:set_action("ampDec", function(x) engine.ampDec(x) end) | |
| params:add_control("ampSus", controlspec.new(0,1,"lin",0,1,"")) | |
| params:set_action("ampSus", function(x) engine.ampSus(x) end) | |
| params:add_control("ampRel", controlspec.new(0.01,10,"lin",0,1,"")) | |
| params:set_action("ampRel", function(x) engine.ampRel(x) end) | |
| params:add_control("cutAtk", controlspec.new(0.01,10,"lin",0,0.05,"")) | |
| params:set_action("cutAtk", function(x) engine.cutAtk(x) end) | |
| params:add_control("cutDec", controlspec.new(0,2,"lin",0,0.1,"")) | |
| params:set_action("cutDec", function(x) engine.cutDec(x) end) | |
| params:add_control("cutSus", controlspec.new(0,1,"lin",0,1,"")) | |
| params:set_action("cutSus", function(x) engine.cutSus(x) end) | |
| params:add_control("cutRel", controlspec.new(0.01,10,"lin",0,1,"")) | |
| params:set_action("cutRel", function(x) engine.cutRel(x) end) | |
| end | |
| cleanup = function() | |
| midi.cleanup() | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment