Skip to content

Commit

Permalink
initial github commit
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperNiCd committed Aug 6, 2018
1 parent 07a0edd commit e568fd2
Show file tree
Hide file tree
Showing 6 changed files with 402 additions and 27 deletions.
30 changes: 17 additions & 13 deletions ClockedRandomGate.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ local Unit = require "Unit"
local GainBias = require "Unit.ViewControl.GainBias"
local Comparator = require "Unit.ViewControl.Comparator"
local InputComparator = require "Unit.ViewControl.InputComparator"
local ModeSelect = require "Unit.ViewControl.OptionControl"
local ModeSelect = require "Unit.MenuControl.OptionControl"
local Task = require "Unit.MenuControl.Task"
local MenuHeader = require "Unit.MenuControl.Header"
local Encoder = require "Encoder"
local ply = app.SECTION_PLY

Expand Down Expand Up @@ -144,6 +146,19 @@ function ClockedRandomGate:deserialize(t)
end
end

local function linMap(min,max,n)
local map = app.DialMap()
map:clear(n+1)
local scale = (max - min)/n
for i=0,n do
map:add(i*scale+min)
end
map:setZero(-min/scale,false)
return map
end

local probMap = linMap(0,1.0,100)

local views = {
expanded = {"tap","prob","mult","div","sync","width"},
collapsed = {},
Expand Down Expand Up @@ -203,23 +218,12 @@ function ClockedRandomGate:onLoadViews(objects,controls)
branch = self:getBranch("Prob"),
gainbias = objects.probOffset,
range = objects.probOffset,
biasMap = self:linMap(0,1,100),
biasMap = probMap,
biasUnits = app.unitNone,
initialBias = 1.0
}

return views
end

function ClockedRandomGate:linMap(min,max,n)
local map = app.DialMap()
map:clear(n+1)
local scale = (max - min)/n
for i=0,n do
map:add(i*scale+min)
end
map:setZero(-min/scale,false)
return map
end

return ClockedRandomGate
33 changes: 20 additions & 13 deletions MotionSensor.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ function MotionSensor:onLoadGraph(pUnit)
local env = self:createObject("EnvelopeFollower","env")
local release = self:createObject("ParameterAdapter","release")
local attack = self:createObject("ParameterAdapter","attack")
local pregain = self:createObject("Multiply","pregain")
local preGainAmt = self:createObject("Constant","preGainAmt")
local gain = self:createObject("Multiply","gain")
local level = self:createObject("GainBias","level")
local levelRange = self:createObject("MinMax","levelRange")
Expand All @@ -45,6 +47,7 @@ function MotionSensor:onLoadGraph(pUnit)
rectify:optionSet("Type",3) --full rectification
self:setMaxDelayTime(0.1)
delay:hardSet("Left Delay",0.001)
preGainAmt:hardSet("Value",4.0)



Expand All @@ -58,7 +61,9 @@ function MotionSensor:onLoadGraph(pUnit)
connect(rectify,"Out",env,"In")
connect(level,"Out",levelRange,"In")
connect(level,"Out",gain,"Left")
connect(env,"Out",gain,"Right")
connect(env,"Out", pregain,"Left")
connect(preGainAmt,"Out",pregain,"Right")
connect(pregain,"Out",gain,"Right")
connect(gain,"Out",compare,"In")
connect(compare,"Out",pUnit,"Out1")

Expand All @@ -80,6 +85,19 @@ local views = {
input = {"scope","input"}
}

local function linMap(min,max,n)
local map = app.DialMap()
map:clear(n+1)
local scale = (max - min)/n
for i=0,n do
map:add(i*scale+min)
end
map:setZero(-min/scale,false)
return map
end

local sensMap = linMap(0,100,100)

function MotionSensor:onLoadViews(objects,controls)

controls.input = InputComparator {
Expand All @@ -95,7 +113,7 @@ function MotionSensor:onLoadViews(objects,controls)
description = "Level",
gainbias = objects.level,
range = objects.levelRange,
biasMap = self:linMap(0,100,100),
biasMap = sensMap,
biasUnits = app.unitNone,
initialBias = 50.0,
gainMap = Encoder.getMap("gain"),
Expand Down Expand Up @@ -135,17 +153,6 @@ function MotionSensor:onLoadViews(objects,controls)
return views
end

function MotionSensor:linMap(min,max,n)
local map = app.DialMap()
map:clear(n+1)
local scale = (max - min)/n
for i=0,n do
map:add(i*scale+min)
end
map:setZero(-min/scale,false)
return map
end

function MotionSensor:setMaxDelayTime(secs)
local requested = Utils.round(secs,1)
local allocated = self.objects.delay:allocateTimeUpTo(requested)
Expand Down
181 changes: 181 additions & 0 deletions PingableScaledRandom.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
-- GLOBALS: app, os, verboseLevel, connect
local app = app
local Class = require "Base.Class"
local Unit = require "Unit"
local Comparator = require "Unit.ViewControl.Comparator"
local GainBias = require "Unit.ViewControl.GainBias"
local Fader = require "Unit.ViewControl.Fader"
local Task = require "Unit.MenuControl.Task"
local ModeSelect = require "Unit.ViewControl.OptionControl"
local MenuHeader = require "Unit.MenuControl.Header"
local Encoder = require "Encoder"
local ply = app.SECTION_PLY

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

function PingableScaledRandom:init(args)
args.title = "Pingable Scaled Random"
args.mnemonic = "SR"
Unit.init(self,args)
end

function PingableScaledRandom:onLoadGraph(pUnit,channelCount)

--random block
local random=self:createObject("WhiteNoise","random")
local hold = self:createObject("TrackAndHold","hold")
local edge = self:createObject("Comparator","edge")
local scale = self:createObject("Multiply","scale")
local scaleAmt = self:createObject("ConstantOffset","scaleAmt")
local scaleLevel = self:createObject("ParameterAdapter","scaleLevel")
local offset = self:createObject("ConstantOffset","offset")
local offsetLevel = self:createObject("ParameterAdapter","offsetLevel")
local quantize = self:createObject("GridQuantizer", "quantize")
local quantVCA = self:createObject("Multiply", "quantVCA")
local noQuantVCA = self:createObject("Multiply","noQuantVCA")
local mix = self:createObject("Sum","mix")
local quantVCASelector = self:createObject("Constant","quantVCASelector")
local noQuantVCASelector = self:createObject("Constant","noQuantVCASelector")

edge:setTriggerMode()
quantVCASelector:hardSet("Value",0.0)
noQuantVCASelector:hardSet("Value",1.0)

tie(scaleAmt,"Offset",scaleLevel,"Out")
tie(offset,"Offset",offsetLevel,"Out")


-- connect objects
connect(edge,"Out",hold,"Track")
connect(random,"Out",hold,"In")
connect(hold,"Out",quantize,"In")
--quantized branch
connect(quantize,"Out",quantVCA,"Left")
connect(quantVCASelector,"Out",quantVCA,"Right")
connect(quantVCA,"Out",mix,"Left")
--unquantized branch
connect(hold,"Out",noQuantVCA,"Left")
connect(noQuantVCASelector,"Out",noQuantVCA,"Right")
connect(noQuantVCA,"Out",mix,"Right")
--merge branches
connect(mix,"Out",scale,"Left")
connect(scaleAmt,"Out",scale,"Right")
connect(scale,"Out",offset,"In")
connect(offset,"Out",pUnit,"Out1")

if channelCount>1 then
connect(offset,"Out",pUnit,"Out2")
end

-- register exported ports
self:addBranch("trig","Trigger",edge,"In")
self:addBranch("scalelvl","Scalelvl",scaleLevel,"In")
self:addBranch("offset","Offset",offsetLevel,"In")

end

local views = {
expanded = {"trigger","levels","scale","offset"},
collapsed = {},
}

local function linMap(min,max,n)
local map = app.DialMap()
map:clear(n+1)
local scale = (max - min)/n
for i=0,n do
map:add(i*scale+min)
end
map:setZero(-min/scale,false)
return map
end

local scaleMap = linMap(0,1,100)
local offsetMap = linMap(-1,1,100)

function PingableScaledRandom:onLoadViews(objects,controls)
controls.trigger = Comparator {
button = "trig",
branch = self:getBranch("Trigger"),
description = "Trigger",
edge = objects.edge,
}
controls.scale = GainBias {
button = "scale",
description = "Attenuation",
branch = self:getBranch("Scalelvl"),
gainbias = objects.scaleLevel,
range = objects.scaleLevel,
biasMap = scaleMap,
biasUnits = app.unitNone,
initialBias = 1.0
}
controls.offset = GainBias {
button = "offset",
description = "Offset",
branch = self:getBranch("Offset"),
gainbias = objects.offsetLevel,
range = objects.offsetLevel,
biasMap = offsetMap,
biasUnits = app.unitNone,
initialBias = 0.0
}
controls.levels = Fader {
button = "levels",
description = "Quant Levels",
param = objects.quantize:getParameter("Levels"),
monitor = self,
map = Encoder.getMap("int[1,256]"),
units = app.unitInteger
}


return views
end

local controlMode = "no"

local menu = {
"setHeader",
"setControlsNo",
"setControlsYes",
"infoHeader",
"rename",
"load",
"save"
}

function PingableScaledRandom:onLoadMenu(objects,controls)

controls.setHeader = MenuHeader {
description = string.format("Quantize Output: %s.",controlMode)
}

controls.setControlsNo = Task {
description = "no",
task = function() self:changeControlMode("no", objects) end
}

controls.setControlsYes = Task {
description = "yes",
task = function() self:changeControlMode("yes", objects) end
}

return menu
end



function PingableScaledRandom:changeControlMode(mode, objects)
controlMode = mode
if controlMode=="no" then
objects.quantVCASelector:hardSet("Value",0.0)
objects.noQuantVCASelector:hardSet("Value",1.0)
else
objects.quantVCASelector:hardSet("Value",1.0)
objects.noQuantVCASelector:hardSet("Value",0.0)
end
end

return PingableScaledRandom
Loading

0 comments on commit e568fd2

Please sign in to comment.