Home › Forums › General › Programming › simple sequencer
Tagged: sequencer
- This topic has 162 replies, 3 voices, and was last updated 6 years, 2 months ago by human fly.
-
AuthorPosts
-
January 12, 2018 at 1:40 am #74259
How about this?
-- -- Called when a modulator value changes -- @mod http://ctrlr.org/api/class_ctrlr_modulator.html -- @value new numeric value of the modulator -- function multiRun(mod,value) local c="" local t = { {"mod1","enable1"}, {"mod2","enable2"}, {"mod3","enable3"}, {"mod4","enable4"}, } for i,v in ipairs (t) do local mo=panel:getModulatorByName(tostring(v[1])):getValue() local en=panel:getModulatorByName(tostring(v[2])):getValue() console(String(i.." ["..v[1].."] mo "..mo.." "..en)) if en ~= 0 then c=c..mo.." " end end -- loop panel:getComponent("display3"):setPropertyString("uiLabelText",c) console("_____________________________") end
January 12, 2018 at 2:29 am #74261interesting to see nested tables used.
have to think about that one..
what is the benefit of doing it like that?since it can now add to a table depending on enable
button state, i thought of replacing the sequencer
‘count=count+1’ stuff with something that counts through
a table/array, whose default would be 1-16, but where
steps could be switched on/off – so it would rebuild the
count table – either with each runcallback or when it hits
the last(?) step.…how to drive the count from an array … ??
January 12, 2018 at 2:31 am #74263another way i saw for the count was this. seems like
it lets you count in increments of more than 1:function incCount (n) n = n or 1 count = count + n end
January 12, 2018 at 3:29 am #74268I don’t know – for me keeping it all in one loop is good, but I think it’s all about readability. I think if you ran two loops instead of one on only 4 iterations, it wouldn’t make much difference speed wise. It’s one of many ways to do it!
that counts through
a table/array, whose default would be 1-16, but where
steps could be switched on/off – so it would rebuild the
count table – either with each runcallback or when it hits
the last(?) step.…how to drive the count from an array … ??
????? and what is runcallback?
January 12, 2018 at 8:43 am #74283sorry, was late, trying to post some sort of reply 🙂
ok so say my ‘default’ count follows
1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16
and somehow this is a table.but i want to be able to turn off any step, so that it skips it.
it would have a row of enable buttons under each step (like active
step on a korg volca – and would change the pattern length, of course)as the little method above can ‘switch on/off’ items entered into a
table/array, it looks like it could be a way to determine how a
sequence runs – what steps, what length, what order, etc.currently, the sequencer depends on just ‘count=count+1’ and
start/end points, and will always do all steps within those bounds.
(it can run backwards if the ‘start’ value is higher than the ‘end’ value)(‘runcallback’ is my method that depends on the ‘clock’/rate timer)
January 12, 2018 at 11:16 am #74284Another interesting puzzle you pose!
Well I came up with this. I feel like I am missing something easier though!
t={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16} -- the base table seq={1,2,4,5,7,8,9,11,12,13,15,16} -- these are all switched on n={} -- initialise new table for i,v in ipairs (t) do n[v] = false end for i,v in ipairs (seq) do n[v] = true end for i,v in ipairs (n) do if v then console(String("["..i.."] run sequence")) end end
January 13, 2018 at 9:16 am #74385edit>>
January 14, 2018 at 9:38 pm #74485here’s that working on a row of 16 controls with buttons.
it only picks up the values enabled:
(serious amount of spam on this forum)
>panelAttachments:
You must be logged in to view attached files.January 14, 2018 at 11:39 pm #74491So all you really need is:
function multiselect() local tbl_enab={} for i=1,16 do if _G["enable"..i]:getValue() == 1 then table.insert(tbl_enab,_G["mod"..i]:getValue()) end end ----------------------------------------------- local enabConcat = table.concat(tbl_enab," ") panel:getComponent("display3"):setPropertyString("uiLabelText",tostring(enabConcat)) end
panel:getModulatorByName() etc is initialised on panel start 🙂
Attachments:
You must be logged in to view attached files.January 15, 2018 at 8:15 am #74514oh i see: it autoupdates the readout 🙂
because you set each button to run the method, which
i didn’t have.ok, so (have to go out now but will look later) HOW
does ‘count=count+n’ follow the readout steps instead
of simple 1,2,3 etc. counting?if it can do
count+n
, can it somehow docount+(tbl_enab[ i ] +1 )
or something like that?January 16, 2018 at 12:06 pm #74847I don’t see exactly what you are doing here so maybe you can ignore my post… the thing is, when I read the thread’s title “simple sequencer” I think you should know that Ctrlr is not really capable of doing sequencer tasks. That is because most parts of Ctrlr are single threaded. When you run a Lua script it will freeze Ctrlr for the time it is running. Therefore there would be no way to stop a running sequence. It would run forever. As a workaround you can use timers but they can’t provide you a tight timing so usefulness is limited. Also, when you set the timer too short (for a fast running sequence) it will freeze Ctrlr too.
January 16, 2018 at 12:52 pm #74856hi Possemo,
i take your point about Ctrlr’s capabilities, and read about
this previously – before embarking on checking this out with
this topic.i have in fact, noticed that clocking can ‘bug’ at times.
it is completely untested as far as trying to generate MIDI,
but i’m not really trying to build a working sequencer, this
is just for experimentation and to find out how to do things
with Lua.January 16, 2018 at 8:56 pm #75509next question 😀
if increment is
count=count+1
can this also be done as
myTable [ k ]+1
somehow?but the index will always be 1,2,3,4,etc (or? 0,1,2,3.. ?)
ie: consecutive sequence.
what if i want only the ‘enabled’ steps?so far, this has been collecting the values on the modulators.
if i collect the values on the buttons instead, and take only
those with value ==1,and use button
[ i ]
as table[ v ]
…
then the ‘v’ series will be the count order…
that’s what i want, anyway.
this is why i want to count from a table.
it creates the table each time it starts the sequence
ie: so it skips steps that are not switched on.January 17, 2018 at 9:09 am #76392ok, this collects the values in one table,
and the active steps in another:so now ‘active’ (i) is to be the count order/sequence.
?count = (tbl_mods[ v ])
? (etc)local tbl_enab={} local tbl_mods={} for i=1,16 do --[ list values ]-- if _G["enable"..i]:getValue() == 1 then table.insert(tbl_enab,_G["mod"..i]:getValue()) --[ list active steps ]-- local active = i table.insert(tbl_mods,active) end end
Attachments:
You must be logged in to view attached files.January 18, 2018 at 12:46 am #77976local active = i
table.insert(tbl_mods,active)except you don’t need the variable
active
:table.insert(tbl_mods,i)
🙂
January 18, 2018 at 9:44 am #78613ah yes, of course 🙂
so now, with a ‘runCallback()’ method, and keeping
‘tbl_mods’ global, i can get the ‘active’/’i’ when
i run the timer, with:function runCallback() for k,v in ipairs(tbl_mods) do console(String(k..": "..v)) end end
having some difficulty conceiving of how to get the
count to follow the arbitrary new values at steps,
eg: tbl_mods [ k ] = tbl_mods [ k ] +1 or whatever…January 18, 2018 at 10:22 am #78654look>> here i put back your table comparison thing,
but i think it is doing the same thing (?)
(i left the current version commented out, to try)
panel example >>still not quite there: it’s chucking out the entire
steps list at each step. not yet doing count=count+1 stuff.Attachments:
You must be logged in to view attached files.January 18, 2018 at 5:10 pm #79047mm, i can also do:
for i= 1, #tbl_mods,1 do console(String(tbl_mods)) end
but this just gives me the entire array every time
the callback is performed. if i include this,--tbl_mods = tbl_mods+1
it goes a bit crazy and starts incrementing everything
in the table 🙂 and won’t restart at the beginning again
until i re-open the project.saw this here, but not familiar with the %. tried to
put%#tbl_mods
to allow for any length table(array…)
but it just returned 2’s continuously. – ? –https://forums.coronalabs.com/topic/43289-incrementing-table-index/
so what i need is something that will call each
increment of the table/array once per callback.January 18, 2018 at 5:31 pm #79065a-haa, found out how to get my *last* step(key) in the array:
function getLast() last=tbl_mods[#tbl_mods+1-1] console(String(last)) end
January 19, 2018 at 4:03 pm #80657ok, so if my timer callback was to run a function each time,
i was thinking of trying to increment through my table with
something like this (which doesn’t work):function leftRight() count=tbl_mods[1]+1 if count > last then count = first end console(String("count="..count)) end
(‘last’ and ‘first’ are known, because they are created with
another method at the moment) -
AuthorPosts
- The forum ‘Programming’ is closed to new topics and replies.