-
-
Save severak/f82b1fad78f62f4f6515e39f455bcd01 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- EBM generator | |
-- (c) Severak 2021 | |
-- generates random EBM riff, drums not implmeneted yet | |
require "include/protoplug" | |
--Welcome to Lua Protoplug generator (version 1.0.0) | |
-- default song: | |
-- DAF: Der Mussolini | |
-- B2 E3 B2 D4 B2 B3 B2 B2 B3 B2 B3 B2 B3 A3 B2 B3 | |
local song = {46, 52, 46, 62, 46, 59, 46, 46, 59, 46, 59, 46, 59, 57, 46, 59} | |
local is_playing = false | |
x=0 | |
prevNote = false | |
local transpose = 0 | |
function ebmgen() | |
local i | |
local base = math.random(36,71) | |
for i=1,16 do | |
song[i] = base | |
end | |
for i=1,16 do | |
local offset = math.random(-12, 12) | |
if math.random(0,2)==1 then | |
song[i] = song[i] + offset | |
end | |
end | |
end | |
function plugin.processBlock(samples, smax, midiBuf) | |
newEvents = {} | |
if not interval then updateInterval() end | |
if not i then i = interval + 1 end | |
for s=0,smax do | |
if i>=interval then | |
if is_playing then | |
local at = (x % 16) + 1; | |
print(prevNote) | |
if prevNote then | |
noteOff(prevNote) | |
end | |
noteOn(song[at] + transpose, 127) | |
prevNote = song[at] + transpose | |
elseif prevNote then | |
noteOff(prevNote) | |
prevNote = false | |
end | |
i = 0 | |
x = x + 1 | |
end | |
i = i + 1 | |
end | |
midiBuf:clear() | |
if #newEvents>0 then | |
for _,e in ipairs(newEvents) do | |
midiBuf:addEvent(e) | |
end | |
end | |
end | |
function noteOn(n,v) | |
table.insert(newEvents, midi.Event.noteOn(1, n, v)) | |
end | |
function noteOff(n) | |
table.insert(newEvents, midi.Event.noteOff(1, n, 0)) | |
end | |
function updateInterval() | |
local int = params[2].getValue() | |
bpm = plugin.getCurrentPosition().bpm | |
interval = math.floor((plugin.getSampleRate()*int)/(bpm)) | |
end | |
params = plugin.manageParams { | |
{ | |
name = "Is playing?"; | |
type = "list"; | |
values = {"yes", "no"}; | |
default = "no"; | |
changed = function(is) | |
is_playing = (is == "yes") | |
end; | |
}; | |
{ | |
name = "Interval"; | |
type = "int"; | |
min = 3; | |
max = 30; | |
default = 60; | |
changed = function(val) interval = nil end; | |
}; | |
{ | |
name = "Transpose"; | |
type = "int"; | |
min = -2; | |
max = 2; | |
default = 0; | |
changed = function(val) | |
transpose = val * 12 | |
end; | |
}; | |
{ | |
name = "Song seed"; | |
type = "int"; | |
min = 1; | |
max = 256; | |
default = 128; | |
changed = function(val) | |
math.randomseed(val) | |
ebmgen() | |
end; | |
}; | |
} | |
params.resetToDefaults() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment