Skip to content

Commit

Permalink
Serialize logics unit, new AB Switch unit
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperNiCd committed Sep 15, 2019
1 parent 09c149c commit a7f501a
Show file tree
Hide file tree
Showing 3 changed files with 183 additions and 39 deletions.
111 changes: 111 additions & 0 deletions ABSwitch.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
-- GLOBALS: app, os, verboseLevel, connect, tie
local app = app
local Class = require "Base.Class"
local Unit = require "Unit"
local ModeSelect = require "Unit.ViewControl.OptionControl"
local GainBias = require "Unit.ViewControl.GainBias"
local BranchMeter = require "Unit.ViewControl.BranchMeter"
local MenuHeader = require "Unit.MenuControl.Header"
local Gate = require "Unit.ViewControl.Gate"
local Encoder = require "Encoder"
local ply = app.SECTION_PLY

local ABSwitch = Class{}
ABSwitch:include(Unit)

function ABSwitch:init(args)
args.title = "AB Switch"
args.mnemonic = "AB"
Unit.init(self,args)
end

function ABSwitch:onLoadGraph(channelCount)
local a = self:createObject("ConstantGain","a")
local b = self:createObject("ConstantGain","b")
local sum = self:createObject("Sum","sum")
a:hardSet("Gain",1.0)
b:hardSet("Gain",1.0)
a:setClampInDecibels(-59.9)
b:setClampInDecibels(-59.9)
self:createMonoBranch("inA", a, "In", a,"Out")
self:createMonoBranch("inB", b, "In", b,"Out")


local one = self:createObject("Constant","one")
one:hardSet("Value",1.0)
local negOne = self:createObject("Constant","negOne")
negOne:hardSet("Value",-1.0)
local invert = self:createObject("Multiply","invert")
local sub = self:createObject("Sum","sub")
local vcaA = self:createObject("Multiply","vcaA")
local vcaB = self:createObject("Multiply","vcaB")

local ab = self:createObject("Comparator","ab")
ab:setToggleMode()


self:createMonoBranch("ab",ab,"In",ab,"Out")

connect(b,"Out",vcaA,"Left")
connect(ab,"Out",vcaA,"Right")
connect(vcaA,"Out",sum,"Left")
connect(a,"Out",vcaB,"Left")
connect(ab,"Out",invert,"Left")
connect(negOne,"Out",invert,"Right")
connect(invert,"Out",sub,"Left")
connect(one,"Out",sub,"Right")
connect(sub,"Out",vcaB,"Right")
connect(vcaB,"Out",sum,"Right")
connect(sum,"Out",self,"Out1")

if channelCount > 1 then
connect(sum,"Out",self,"Out2")
end


end

local views = {
expanded = {"ab","a","b"},
collapsed = {},
input = {}
}

function ABSwitch:onLoadViews(objects,branches)
local controls = {}

controls.a = BranchMeter {
button = "a",
branch = branches.inA,
faderParam = objects.a:getParameter("Gain")
}

controls.b = BranchMeter {
button = "b",
branch = branches.inB,
faderParam = objects.b:getParameter("Gain")
}

controls.ab = Gate {
button = "ab",
description = "Output A/B",
branch = branches.ab,
comparator = objects.ab,
}

self:addToMuteGroup(controls.a)
self:addToMuteGroup(controls.b)

return controls, views
end

local menu = {
"infoHeader",
"rename",
"load",
"save",
"edit"
}


return ABSwitch
102 changes: 64 additions & 38 deletions Logics.lua
Original file line number Diff line number Diff line change
Expand Up @@ -270,87 +270,113 @@ local menu = {

local op = "AND"

function Logics:setOp(op)
local objects = self.objects
self.op = op
if op=="AND" then
objects.ANDSelectorConst:hardSet("Value",1.0)
objects.ORSelectorConst:hardSet("Value",0.0)
objects.XORSelectorConst:hardSet("Value",0.0)
objects.NOTInverterConst:hardSet("Value",1.0)
objects.NOTOffsetConst:hardSet("Value",0.0)
elseif op=="OR" then
objects.ANDSelectorConst:hardSet("Value",0.0)
objects.ORSelectorConst:hardSet("Value",1.0)
objects.XORSelectorConst:hardSet("Value",0.0)
objects.NOTInverterConst:hardSet("Value",1.0)
objects.NOTOffsetConst:hardSet("Value",0.0)
elseif op=="XOR" then
objects.ANDSelectorConst:hardSet("Value",0.0)
objects.ORSelectorConst:hardSet("Value",0.0)
objects.XORSelectorConst:hardSet("Value",1.0)
objects.NOTInverterConst:hardSet("Value",1.0)
objects.NOTOffsetConst:hardSet("Value",0.0)
elseif op=="NAND" then
objects.ANDSelectorConst:hardSet("Value",1.0)
objects.ORSelectorConst:hardSet("Value",0.0)
objects.XORSelectorConst:hardSet("Value",0.0)
objects.NOTInverterConst:hardSet("Value",-1.0)
objects.NOTOffsetConst:hardSet("Value",1.0)
elseif op=="NOR" then
objects.ANDSelectorConst:hardSet("Value",0.0)
objects.ORSelectorConst:hardSet("Value",1.0)
objects.XORSelectorConst:hardSet("Value",0.0)
objects.NOTInverterConst:hardSet("Value",-1.0)
objects.NOTOffsetConst:hardSet("Value",1.0)
elseif op=="XNOR" then
objects.ANDSelectorConst:hardSet("Value",0.0)
objects.ORSelectorConst:hardSet("Value",0.0)
objects.XORSelectorConst:hardSet("Value",1.0)
objects.NOTInverterConst:hardSet("Value",-1.0)
objects.NOTOffsetConst:hardSet("Value",1.0)
end
end

function Logics:onLoadMenu(objects,branches)
local controls = {}

controls.setHeader = MenuHeader {
description = string.format("Current op is: %s.",op)
description = string.format("Current op is: %s.",self.op)
}

controls.opAND = Task {
description = "AND",
task = function()
objects.ANDSelectorConst:hardSet("Value",1.0)
objects.ORSelectorConst:hardSet("Value",0.0)
objects.XORSelectorConst:hardSet("Value",0.0)
objects.NOTInverterConst:hardSet("Value",1.0)
objects.NOTOffsetConst:hardSet("Value",0.0)
op = "AND"
self:setOp("AND")
end
}

controls.opOR = Task {
description = "OR",
task = function()
objects.ANDSelectorConst:hardSet("Value",0.0)
objects.ORSelectorConst:hardSet("Value",1.0)
objects.XORSelectorConst:hardSet("Value",0.0)
objects.NOTInverterConst:hardSet("Value",1.0)
objects.NOTOffsetConst:hardSet("Value",0.0)
op = "OR"
self:setOp("OR")
end
}

controls.opXOR = Task {
description = "XOR",
task = function()
objects.ANDSelectorConst:hardSet("Value",0.0)
objects.ORSelectorConst:hardSet("Value",0.0)
objects.XORSelectorConst:hardSet("Value",1.0)
objects.NOTInverterConst:hardSet("Value",1.0)
objects.NOTOffsetConst:hardSet("Value",0.0)
op = "XOR"
self:setOp("XOR")
end
}

controls.opNAND = Task {
description = "NAND",
task = function()
objects.ANDSelectorConst:hardSet("Value",1.0)
objects.ORSelectorConst:hardSet("Value",0.0)
objects.XORSelectorConst:hardSet("Value",0.0)
objects.NOTInverterConst:hardSet("Value",-1.0)
objects.NOTOffsetConst:hardSet("Value",1.0)
op = "NAND"
self:setOp("NAND")
end
}

controls.opNOR = Task {
description = "NOR",
task = function()
objects.ANDSelectorConst:hardSet("Value",0.0)
objects.ORSelectorConst:hardSet("Value",1.0)
objects.XORSelectorConst:hardSet("Value",0.0)
objects.NOTInverterConst:hardSet("Value",-1.0)
objects.NOTOffsetConst:hardSet("Value",1.0)
op = "NOR"
self:setOp("NOR")
end
}

controls.opXNOR = Task {
description = "XNOR",
task = function()
objects.ANDSelectorConst:hardSet("Value",0.0)
objects.ORSelectorConst:hardSet("Value",0.0)
objects.XORSelectorConst:hardSet("Value",1.0)
objects.NOTInverterConst:hardSet("Value",-1.0)
objects.NOTOffsetConst:hardSet("Value",1.0)
op = "XNOR"
self:setOp("XNOR")
end
}
return controls, menu
end

function Logics:onLoadFinished()
self:setOp("AND")
end

function Logics:serialize()
local t = Unit.serialize(self)
t.logicOp = self.op
return t
end

return controls, menu
function Logics:deserialize(t)
Unit.deserialize(self,t)
if t.logicOp then
self:setOp(t.logicOp)
end
end
return Logics
9 changes: 8 additions & 1 deletion init.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
local units = {

{category="Essentials"},
{title="Linear Sampling VCA", moduleName="LinearSamplingVCA",keywords="modulate, utility"},

{category = "Delays and Reverb"},
{title="Ensemble",moduleName="StereoEnsemble",keywords="modulate, pitch"},
{title="Flanger",moduleName="Flanger",keywords="modulate, pitch"},
Expand All @@ -12,6 +16,7 @@ local units = {

{category="Oscillators"},
{title="Aliasing Pulse",moduleName="BespokeAliasingPulse",keywords="oscillator"},
-- {title="Hexonic", moduleName="Hexonic", keywords="oscillator"},

{category="Mapping and Control"},
{title="Compare",moduleName="Compare",keywords="mapping,control"},
Expand All @@ -29,7 +34,9 @@ local units = {
{title="Timed Gate", moduleName="TimedGate",keywords="timing"},

{category="Experimental"},
{title="Linear Sampling VCA", moduleName="LinearSamplingVCA",keywords="modulate, utility"},
{title="AB Switch", moduleName="ABSwitch",keywords="control"}
-- {title="Equals",moduleName="Equals",keywords=""},
-- {title="Inverse",moduleName="Inverse",keywords=""}
}

return {
Expand Down

0 comments on commit a7f501a

Please sign in to comment.