Home Forums General Programming simple sequencer

This topic contains 152 replies, has 3 voices, and was last updated by  human fly 7 hours, 14 minutes ago.

Viewing 20 posts - 121 through 140 (of 153 total)
  • Author
    Posts
  • #74259
    dnaldoog
    dnaldoog
    Participant

    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
    
    #74261

    human fly
    Participant

    interesting 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 … ??

    #74263

    human fly
    Participant

    another 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
    #74268
    dnaldoog
    dnaldoog
    Participant

    I 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?

    #74283

    human fly
    Participant

    sorry, 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)

    #74284
    dnaldoog
    dnaldoog
    Participant

    Another 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
    
    #74385

    human fly
    Participant

    edit>>

    #74485

    human fly
    Participant

    here’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)
    >panel

    Attachments:
    You must be logged in to view attached files.
    #74491
    dnaldoog
    dnaldoog
    Participant

    So 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.
    #74514

    human fly
    Participant

    oh 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 do count+(tbl_enab[ i ] +1 )
    or something like that?

    #74847
    Possemo
    Possemo
    Participant

    I 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.

    #74856

    human fly
    Participant

    hi 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.

    #75509

    human fly
    Participant

    next question 😀

    if increment is count=count+1

    can this also be done asmyTable [ 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.

    #76392

    human fly
    Participant

    ok, 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.
    #77976
    dnaldoog
    dnaldoog
    Participant

    local active = i
    table.insert(tbl_mods,active)

    except you don’t need the variable active:

    
    table.insert(tbl_mods,i)
    

    🙂

    #78613

    human fly
    Participant

    ah 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…

    #78654

    human fly
    Participant

    look>> 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.
    #79047

    human fly
    Participant

    mm, 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.

    #79065

    human fly
    Participant

    a-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
    #80657

    human fly
    Participant

    ok, 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)

Viewing 20 posts - 121 through 140 (of 153 total)

You must be logged in to reply to this topic.

Comments are closed.