Skip to content

Commit

Permalink
add duration trait for midi devices
Browse files Browse the repository at this point in the history
  • Loading branch information
tyleretters committed Sep 7, 2020
1 parent d59ee84 commit 8dda078
Show file tree
Hide file tree
Showing 12 changed files with 58 additions and 25 deletions.
2 changes: 1 addition & 1 deletion arcologies.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
--
--
-- ........................................
-- v1.0.5
-- v1.0.6
-- <3 @tyleretters
-- nor.the-rn.info
-- GNU GPL v3.0
Expand Down
3 changes: 3 additions & 0 deletions lib/Cell.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ function Cell:new(x, y, g)
charge_trait.init(self)
crow_out_trait.init(self)
device_trait.init(self)
duration_trait.init(self)
er_trait.init(self)
level_trait.init(self)
metabolism_trait.init(self)
Expand All @@ -37,6 +38,7 @@ function Cell:new(x, y, g)
c.setup_charge(c)
c.setup_crow_out(c)
c.setup_device(c)
c.setup_duration(c)
c.setup_er(c)
c.setup_level(c)
c.setup_metabolism(c)
Expand All @@ -59,6 +61,7 @@ function Cell:get_menu_value_by_attribute(a)
elseif a == "CHARGE" then return self.charge
elseif a == "CROW OUT" then return self.crow_out
elseif a == "DEVICE" then return self.device
elseif a == "DURATION" then return self.duration
elseif a == "INDEX" then return self.state_index
elseif a == "LEVEL" then return self.level
elseif a == "METABOLISM" then return self.metabolism
Expand Down
5 changes: 4 additions & 1 deletion lib/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ config = {}
config["settings"] = {
["version_major"] = 1,
["version_minor"] = 0,
["version_patch"] = 5,
["version_patch"] = 6,
["playback"] = 0,
["length"] = 16,
["root"] = 0,
Expand Down Expand Up @@ -67,6 +67,7 @@ config["attributes"] = {
"CAPACITY",
"CHARGE",
"DOCS",
"DURATION",
"INDEX",
"METABOLISM",
"NETWORK",
Expand Down Expand Up @@ -145,13 +146,15 @@ config["structure_attribute_map"] = {
["UXB"] = {
"NOTES",
"VELOCITY",
"DURATION",
"DEVICE",
"DOCS",
"STRUCTURE"
},
["CASINO"] = {
"INDEX",
"NOTES",
"DURATION",
"VELOCITY",
"DEVICE",
"DOCS",
Expand Down
1 change: 1 addition & 0 deletions lib/counters.lua
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ function counters.conductor()
counters.music.time = parameters.bpm_to_seconds
if sound.playback == 0 then return end
counters.music.generation = counters.music.generation + 1
m:setup()
keeper:setup()
keeper:spawn_signals()
keeper:propagate_signals()
Expand Down
10 changes: 5 additions & 5 deletions lib/dev.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ function dev:scene(i)
elseif i == 2 then
sound:set_random_root()
sound:set_random_scale()
keeper:select_cell(4, 4)
-- kc():change("FOREST")
keeper:select_cell(4, 8)
kc():open_port("n")
-- keeper:select_cell(4, 1)
keeper:select_cell(4, 1)
kc():change("UXB")
kc():open_port("s")

kc():open_port("e")
-- kc():open_port("e")
-- kc():open_port("s")
kc():open_port("w")
-- kc():open_port("w")
-- kc():set_state_index(1)
page:select(2)
menu:select_item(1)
Expand Down
3 changes: 3 additions & 0 deletions lib/functions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,9 @@ function fn.random_cell()
if keeper.selected_cell:has("METABOLISM") then
keeper.selected_cell:set_metabolism(math.random(1, sound.length or 16))
end
if keeper.selected_cell:has("DURATION") then
keeper.selected_cell:set_duration(math.random(1, sound.length or 16))
end
if keeper.selected_cell:is("SHRINE") then
keeper.selected_cell:set_note(sound:get_random_note(.6, .7), 1)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/includes.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
-- ships with norns
crow = require("crow")
-- bc = require("beatclock")
er = require("er")
fs = require("fileselect")
mu = require("musicutil")
Expand Down Expand Up @@ -34,6 +33,7 @@ include("arcologies/lib/traits/capacity_trait")
include("arcologies/lib/traits/charge_trait")
include("arcologies/lib/traits/crow_out_trait")
include("arcologies/lib/traits/device_trait")
include("arcologies/lib/traits/duration_trait")
include("arcologies/lib/traits/er_trait")
include("arcologies/lib/traits/level_trait")
include("arcologies/lib/traits/network_trait")
Expand Down
4 changes: 2 additions & 2 deletions lib/keeper.lua
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function keeper:collision(signal, cell)

-- uxbs play single notes via midi
elseif cell:is("UXB") then
m:play(cell.notes[1], cell.velocity, cell.device)
m:play(cell.notes[1], cell.velocity, cell.duration, cell.device)

-- aviaries play single notes via crow
elseif cell:is("AVIARY") then
Expand All @@ -62,7 +62,7 @@ function keeper:collision(signal, cell)

-- topiaries cylce through notes
elseif cell:is("CASINO") then
m:play(cell.notes[cell.state_index], cell.velocity, cell.device)
m:play(cell.notes[cell.state_index], cell.velocity, cell.duration, cell.device)
cell:cycle_state_index(1)

-- forests cylce through notes
Expand Down
1 change: 1 addition & 0 deletions lib/menu.lua
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ function menu:scroll_value(d)
elseif s == "CHARGE" then keeper.selected_cell:set_charge(keeper.selected_cell.charge + d)
elseif s == "CROW OUT" then keeper.selected_cell:set_crow_out(keeper.selected_cell.crow_out + d)
elseif s == "DEVICE" then keeper.selected_cell:set_device(keeper.selected_cell.device + d)
elseif s == "DURATION" then keeper.selected_cell:set_duration(keeper.selected_cell.duration + d)
elseif s == "DOCS" then -- selecting docs automatically toggles them on
elseif s == "INDEX" then keeper.selected_cell:cycle_state_index(d)
elseif s == "LEVEL" then keeper.selected_cell:set_level(keeper.selected_cell.level + d)
Expand Down
24 changes: 23 additions & 1 deletion lib/midi.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,33 @@ function m.init()
m.devices[3] = midi.connect(3)
m.devices[4] = midi.connect(4)
end
m.notes = {}
end

function m:play(note, velocity, device)
function m:setup()
for k, note in pairs(self.notes) do
note.duration = note.duration - 1
if note.duration <= 0 then
self.devices[note.device]:note_off(note.note)
table.remove(self.notes, k)
end
end
end

function m:play(note, velocity, duration, device)
self:register_note(note, device, duration)
self.devices[device]:note_off(note)
self.devices[device]:note_on(note, velocity)
end

function m:register_note(note, device, duration)
local n = {
note = note,
device = device,
duration = duration,
generation = counters.music.generation
}
table.insert(self.notes, n)
end

return m
14 changes: 0 additions & 14 deletions lib/parameters.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,6 @@ function parameters.init()
}
params:hide("bpm")

-- params:add_option("clock", "CLOCK SOURCE", {"INTERNAL", "EXTERNAL"}, clk.external or 2 and 1)
-- params:set_action("clock", function(x) clk:clock_source_change(x) end)

-- params:add_number("bpm", "BPM", 20, 480, clk.bpm)
-- params:set_action("bpm", function(x) clk:bpm_change(x) parameters.bpm_to_seconds = 60 / x end)

-- params:add_option("clock_out", "CLOCK OUT", { "DISALBED", "ENABLED" }, clk.send or 2 and 1)
-- params:set_action("clock_out", function(x) if x == 1 then clk.send = false else clk.send = true end end)



params:add_option("crypts_directory", "CRYPT(S)", filesystem.crypts_names, 1)
params:set_action("crypts_directory", function(index) filesystem:set_crypt(index) end)

Expand Down Expand Up @@ -56,9 +45,6 @@ function parameters.init()
params:set_action(id, function(index) parameters.seed_structures[id] = index == 1 and true or false end)
end




params:default()
params:bang()
end
Expand Down
14 changes: 14 additions & 0 deletions lib/traits/duration_trait.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
duration_trait = {}

duration_trait.init = function(self)

self.setup_duration = function(self)
self.duration = 1
end

self.set_duration = function(self, i)
self.duration = util.clamp(i, 1, 16)
self.callback(self, 'set_duration')
end

end

0 comments on commit 8dda078

Please sign in to comment.