Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added drum patterns #7

Merged
merged 1 commit into from Dec 18, 2020
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -34,3 +34,4 @@ auguries of innocence from william blake has really resonated with me this year.
- @Quixotic7 - replaced the polyperc engine with the bangs engine. This allows you to have different sounding note bangs. In the params menu you can change the synth parameters for 4 different synth sources. Sounds are banged by calling soundEngine:bang_note_hz(freq, synthId, midiId) and soundEngine:bang_note(noteNumber, synthId, midiId). Midi bangs only work if calling soundEngine:bang_note so the song currently only works with the internal synths since all the notes are frequencies.
- @ryanlaws - was being a real prima donna about hz and changed them to MIDI notes
- @evanmcook - aka evancook.audio added graphics that like to groove along to the measure number
- @Quixotic7 - added drum patterns
@@ -8,16 +8,54 @@ function parts.init(soundEngine)
parts.soundEngine = soundEngine
parts.quarter_beat = 0
parts.sixteenth_beat = 0

parts.drumPat = 1

parts.drums = {}

for i = 1, 16 do
parts.drums[i] = {}
parts.drums[i].kick = {}
parts.drums[i].snare = {}
parts.drums[i].hh = {}
end

parts.drums[2].kick = {1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0}

parts.drums[3].hh = {
0,0,1,0,
0,0,1,0,
0,0,1,0,
0,0,1,0}

parts.drums[4].kick = {
1,0,1,0,
0,0,0,0,
1,0,0,0,
0,0,1,0}
parts.drums[4].snare = {
0,0,0,0,
1,0,0,0,
0,0,0,0,
1,0,0,0}
parts.drums[4].hh = {
1,0,1,0,
1,0,1,0,
1,0,1,0,
1,0,1,0}

-- parts.whatever_we_need = 0
end

function parts:whole_notes(phase)
print("do a whole notes thing", phase)
-- engine.amp(1)
-- engine.hz(440)

self.soundEngine:bang_note(69, 2, 0)

if song.measure == 8 then self.drumPat = 2
elseif song.measure == 16 then self.drumPat = 3
elseif song.measure == 24 then self.drumPat = 4 end

if song.measure == 100 then
self.soundEngine:bang_note(62, 1, 0)
elseif song.measure % 4 == 1 then
@@ -31,27 +69,24 @@ function parts:quarter_notes(phase)
print("do a quarter_notes thing", phase)
if math.random(1, 2) == 1 then
self.soundEngine:bang_note(81, 2, 0)

-- engine.amp(.5)
-- engine.hz(880)
end
self.quarter_beat = self.quarter_beat+1
local beat = self.quarter_beat
if beat>32 then
-- rest
elseif beat%31==0 then self.soundEngine:bang_note(59, 1, 0)
elseif beat%29==0 then self.soundEngine:bang_note(60, 1, 0)
elseif beat%27==0 then self.soundEngine:bang_note(55, 1, 0)
elseif beat%25==0 then self.soundEngine:bang_note(52, 1, 0)
elseif beat%23==0 then self.soundEngine:bang_note(52, 1, 0)
elseif beat%21==0 then self.soundEngine:bang_note(52, 1, 0)
elseif beat%17==0 then self.soundEngine:bang_note(48, 1, 0)
elseif beat%15==0 then self.soundEngine:bang_note(52, 1, 0)
elseif beat%11==0 then self.soundEngine:bang_note(52, 1, 0)
elseif beat%9==0 then self.soundEngine:bang_note(47, 1, 0)
elseif beat%7==0 then self.soundEngine:bang_note(52, 1, 0)
elseif beat%5==0 then self.soundEngine:bang_note(52, 1, 0)
elseif beat%1==0 then self.soundEngine:bang_note(45, 1, 0)
elseif beat%31==0 then self.soundEngine:bang_note(59, 1, 0)
elseif beat%29==0 then self.soundEngine:bang_note(60, 1, 0)
elseif beat%27==0 then self.soundEngine:bang_note(55, 1, 0)
elseif beat%25==0 then self.soundEngine:bang_note(52, 1, 0)
elseif beat%23==0 then self.soundEngine:bang_note(52, 1, 0)
elseif beat%21==0 then self.soundEngine:bang_note(52, 1, 0)
elseif beat%17==0 then self.soundEngine:bang_note(48, 1, 0)
elseif beat%15==0 then self.soundEngine:bang_note(52, 1, 0)
elseif beat%11==0 then self.soundEngine:bang_note(52, 1, 0)
elseif beat%9==0 then self.soundEngine:bang_note(47, 1, 0)
elseif beat%7==0 then self.soundEngine:bang_note(52, 1, 0)
elseif beat%5==0 then self.soundEngine:bang_note(52, 1, 0)
elseif beat%1==0 then self.soundEngine:bang_note(45, 1, 0)
end
end

@@ -60,19 +95,35 @@ function parts:sixteenth_notes(phase)
local beat = self.sixteenth_beat
if beat<64 then
-- nothing
elseif beat%31==0 then self.soundEngine:bang_note(71, 1, 0)
elseif beat%29==0 then self.soundEngine:bang_note(72, 1, 0)
elseif beat%27==0 then self.soundEngine:bang_note(67, 1, 0)
elseif beat%25==0 then self.soundEngine:bang_note(64, 1, 0)
elseif beat%23==0 then self.soundEngine:bang_note(64, 1, 0)
elseif beat%21==0 then self.soundEngine:bang_note(64, 1, 0)
elseif beat%17==0 then self.soundEngine:bang_note(60, 1, 0)
elseif beat%15==0 then self.soundEngine:bang_note(64, 1, 0)
elseif beat%11==0 then self.soundEngine:bang_note(64, 1, 0)
elseif beat%9==0 then self.soundEngine:bang_note(59, 1, 0)
elseif beat%7==0 then self.soundEngine:bang_note(64, 1, 0)
elseif beat%5==0 then self.soundEngine:bang_note(64, 1, 0)
elseif beat%1==0 then self.soundEngine:bang_note(57, 1, 0)
elseif beat%31==0 then self.soundEngine:bang_note(71, 1, 0)
elseif beat%29==0 then self.soundEngine:bang_note(72, 1, 0)
elseif beat%27==0 then self.soundEngine:bang_note(67, 1, 0)
elseif beat%25==0 then self.soundEngine:bang_note(64, 1, 0)
elseif beat%23==0 then self.soundEngine:bang_note(64, 1, 0)
elseif beat%21==0 then self.soundEngine:bang_note(64, 1, 0)
elseif beat%17==0 then self.soundEngine:bang_note(60, 1, 0)
elseif beat%15==0 then self.soundEngine:bang_note(64, 1, 0)
elseif beat%11==0 then self.soundEngine:bang_note(64, 1, 0)
elseif beat%9==0 then self.soundEngine:bang_note(59, 1, 0)
elseif beat%7==0 then self.soundEngine:bang_note(64, 1, 0)
elseif beat%5==0 then self.soundEngine:bang_note(64, 1, 0)
elseif beat%1==0 then self.soundEngine:bang_note(57, 1, 0)
end

local noteIndex = (self.sixteenth_beat % 16) + 1

local pat = self.drums[self.drumPat]

if pat.kick[noteIndex] == 1 then
self.soundEngine:bang_note(32, 4, 0)
end

if pat.snare[noteIndex] == 1 then
self.soundEngine:bang_note(38, 5, 0)
end

if pat.hh[noteIndex] == 1 then
self.soundEngine:bang_note(60, 6, 0)
end
end

@@ -8,7 +8,7 @@ local MidiBangs = include("lib/midibangs")
local SoundEngine = {}
SoundEngine.__index = SoundEngine

SoundEngine.SYNTH_COUNT = 4
SoundEngine.SYNTH_COUNT = 8
SoundEngine.MIDI_COUNT = 16


@@ -58,6 +58,19 @@ function SoundEngine:addSynthParams(id)
params:add{ type = "control", id = "release_"..id, name = "Release",controlspec = controlspec.new(0.0001, 10, 'exp', 0, 1.0, 's') }
end

function SoundEngine:setSynthParams(id, synthParams)
if synthParams == nil then return end

if synthParams.algo then params:set("algo_"..id, synthParams.algo) end
if synthParams.amp then params:set("amp_"..id, synthParams.amp) end
if synthParams.pan then params:set("pan_"..id, synthParams.pan) end
if synthParams.mod1 then params:set("mod1_"..id, synthParams.mod1) end
if synthParams.mod2 then params:set("mod2_"..id, synthParams.mod2) end
if synthParams.cutoff then params:set("cutoff_"..id, synthParams.cutoff) end
if synthParams.attack then params:set("attack_"..id, synthParams.attack) end
if synthParams.release then params:set("release_"..id, synthParams.release) end
end

function SoundEngine:addMidiParams(id)
local num_params = 6
params:add_group("Midi " .. id, num_params)
@@ -24,13 +24,19 @@ function init()

sound_engine:addParams()

sound_engine:setSynthParams(4, {algo=4, amp=1.0, pan=0, mod1 = 0.2, mod2 = 1.0, cutoff=800, attack=0, release=0.16})
sound_engine:setSynthParams(5, {algo=6, amp=0.8, pan=0, mod1 = 0.9, mod2 = 1.68, cutoff=2400, attack=0, release=0.35})
sound_engine:setSynthParams(6, {algo=7, amp=0.5, pan=0, mod1 = 0.8, mod2 = 2.64, cutoff=3300, attack=0.001, release=0.03})


parts.init(sound_engine)
graphics.init()
song.is_screen_dirty = true
song.is_playing = true
song.transport = 0
song.measure = 0
song.division = 8

super_metro = metro.init{
time = 1 / song.division,
event= super_tick
ProTip! Use n and p to navigate between commits in a pull request.