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 19, 2018 at 11:40 pm #80812
I looked at the panel you uploaded. It’s working, right? But the last few posts are leaving me rather confused!
In that last function you are working with globals. I would tend to keep everything local, pass parameters into the function and return a value, otherwise your code will become spaghetti! ☺️
January 19, 2018 at 11:59 pm #80813yep it’s a bit like that, with external references at the moment.
sorry about that !
hmm, it’s getting there but i’m only spitting out all the steps
it read, *at each step*. so if it has read steps 1,3,5,6,7 for
example, it returns all of those with each callback. whereas i want
it to read the index one per callback, until it reaches the end of
the table, then starts again.
so that’s what i don’t know how to do.
there’s a few attempts in the ‘backup’ versions of what i’ve tried.
will have another go in the morning. seem to get a little bit of
progress each time i step back and come back fresh. it’s just the
iterating through table one step at a time.January 20, 2018 at 1:54 pm #80816Sorry when cluttering your thread… I would like to correct my statement that Ctrlr is not capable of doing sequencer tasks. Well, you could run a sequencer by midi clock. This way you won’t need timers. Each midi clock event would trigger a step. I think in theory that should with acceptable timing accuracy.
January 20, 2018 at 2:43 pm #80819nooooo… please chip in ! it’s just me and dnaldoog
having a dialog so far – and he’s taught me some nice
tricks, and an overall better conversance with some
basic principles. i’m really doing this mainly to give
me some references outside the core premise of Ctrlr
(being midi control & data), and a ‘sequencer’ is
something i’m always thinking about, and quite a good
basis for experimentation.i’m fairly happy with how it is running ‘virtually’ at
the moment, not yet thinking of producing any midi with
it. although that could be interesting at some point.
iterating tables seems to have many music-related applications,
as much with timing as with note intervals, chords, scales, etc.which is why there are a few digressions here 🙂
January 20, 2018 at 10:21 pm #80828good page here on iterating.
January 21, 2018 at 12:26 pm #80833morning 🙂
right, so this is where i’ve got to (de-spaghetti’ed) :
this will start the count from the initialised ‘=0’,
and then enter the loop i want. but i’m having trouble
correlating ‘count’ with the ‘first’ variable, which is
where i want it to start. if i go count=first, it just
retriggers the same value each time, eg: first+1
i feel it can’t be far off..count=0 --[ declare count ]--this is 'before' the method-- function runCallback() -- -------------------------------------------------------------------- function getFirst() first=tbl_mods[1]--[ create variable for first valid step ]-- --console(String("first="..first)) end -- function getLast() last=tbl_mods[#tbl_mods+1-1]--[ create variable for last valid step ]-- --console(String("last="..last)) end -- getFirst() getLast() -- -------------------------------------------------- --[ test ]-- --[ replace this with first/last ] -- function incCount (n) n = n or 1 count = count + n -- count = first + n -- if count > 16 then count = 0 if count > last then count = first end console(String("count=["..count.."]")) end incCount() end
Attachments:
You must be logged in to view attached files.January 21, 2018 at 12:40 pm #80835morning 🙂
right so i have de-spaghetti’ed and have this, which is nearly
working. it starts at the initialised ‘count=0’, and then enters
the first/last loop. but i have so far been unable to correlate
‘count’ as ‘first’ – if i do, it just returns the same count+1
each time. looks like this:(panel below)count=0 --[ declare count ]-- function runCallback() -- -------------------------------------------------------------------- function getFirst() first=tbl_mods[1] --[ create variable for first valid step ]-- --console(String("first="..first)) end -- function getLast() last=tbl_mods[#tbl_mods+1-1]--[ create variable for last valid step ]-- --console(String("last="..last)) end -- getFirst() getLast() -- --------------------------------------------------------------------- --[ test ]-- --[ replace this with first/last ] -- function incCount (n) n = n or 1 count = count + n if count > last then count = first end console(String("count=["..count.."]")) end incCount() end
Attachments:
You must be logged in to view attached files.January 21, 2018 at 1:03 pm #80838some extra thoughts on this:
– count is initialised before the method, but i have to get
‘first’ and ‘last’ during the callback, to keep it ‘realtime’,
eg: reflecting any changes while the sequencer is running.
i can create them before, ie: when clicking ‘enable’ buttons,
but this needs to happen at least once for ‘first’ and ‘last’ to
exist.(haven’t succeeded in creating them on startup yet)-anything i’m doing within the callback to make initial count
value = ‘first’ step just returns a fixed value, that being
‘first’+1. it keeps returning the same thing.-if i try something like count=first *before* the callback script,
it doesn’t work. maybe wrong place.-once it is running, and ‘in the loop’, it *does* return any
changes in button sequence.January 21, 2018 at 1:12 pm #80839Isn’t this
last=tbl_mods[#tbl_mods+1-1]
the same as
last=tbl_mods[#tbl_mods]
???
January 21, 2018 at 1:15 pm #80840okay 🙂 thanks for pointing that out. did look at bit
odd when i looked at it today. (just me learning concepts)January 21, 2018 at 1:28 pm #80867I don’t see these functions returning anything, so they are not necessary to me ie you are declaring a global variable within a function and calling the function to declare the variable. (Sometimes could be a good reason for doing this I suppose).
In that function
function incCount (n)
I notice you declare it with parametern
but later call it withoutn
? 🙂January 21, 2018 at 1:36 pm #80869I don’t see these functions
getFirst()
getLast()
returning anything, so they are not necessary to me – i.e you are declaring a global variable within a function and calling the function to declare the variable. (Sometimes could be a good reason for doing this I suppose).In that function
function incCount (n)
I notice you declare it with parametern
but later call it withoutn
? 🙂January 21, 2018 at 4:27 pm #80881if you re-enable the console statements, you will see
‘first’ and ‘last’ values returned with every step.
i can put these functions elsewhere, in the ‘multiselect’
method, but that means i have to activate that before ‘Run’.
i think i could also call those functions on panel start if
i put them in a ‘library’ method.yes, i kept them as global, to have something to work
with in the incCount.as for the ‘n’ … am thinking of having the parameter called
‘interval’ eg: ‘intv’? so it could increment in values other
than 1. but it’s a bit superfluous atm.i read
n=n or 1
on one of the tutorial pages.January 21, 2018 at 4:44 pm #80888ok, have now put getfirst/getlast in a library method,
to be called whenever needed.
declaring count as ‘0’ on panel start..can get correct value if i go count=count+first.
but cannot call that with the timer callback, because
it just refreshes each time.what if i did.. but it doesn’t make sense…
count=0 count = count+first
does it need a new variable? ie: ‘icount’ ..
count=0 icount = count+first
btw, i have NO idea what i’m doing, as usual 🙂
January 21, 2018 at 6:00 pm #80906the incCount thing – icount=icount+n – was temporary.
conned that into running – but it still runs sequentially
through normal integer increments, and not through the
actual values in the table – obviously. so, instead oficount = icount + n
it needs something??like???
icount = tonumber(tbl_mods,1,#tbl_mods + n)
which doesn’t work at all. but if you can see what i mean:
how to get the next [ k ] incremented, in order to get its [ v ],
(so to speak…)therein lies the whole problem … because n doesn’t mean anything
if it’s just 1 all the time. i don’t know how to refer to this in
the context of a table, ie: next value in table.January 29, 2018 at 5:37 pm #81077‘kaay.. i’ve been scratching my head over this for days:
objective: i want to step through a table, one key(index)
at a time. how is this done?i can *list and print* my table with:
for i= 1, #tbl_mods,1 do _G[step..i] = tbl_mods console(String("step"..i..": ".._G[step..i])) --or just: n=tbl_mods console(String("n: "..n)) end
but then i can’t do
i=i+1
because i is then nil outside
the previous loop.
so how do i do something like
tbl_mods[ i ] = tbl_mods[ i+1 ]
?
i just want to return the next key/value each time the function
is triggered. in terms of keys, it counts normally until last
existing key, but it uses the value output for results.going round in circles with this.
January 30, 2018 at 9:00 am #81078this is what i can’t seem to figure out:
how to step through the table index one at a time,
with each ‘callback’ call produced by the timer function.i can get all keys/values at each ‘callback’, with:
for i= 1, #tbl_mods,1 do _G[step..i] = tbl_mods console(String("step"..i..": ".._G[step..i])) --or: n=tbl_mods console(String("n: "..n)) end
but i only want the next value in the sequence.
i can’t usei=i+1
outside of that loop, and
i’ve tried creating variables to use, but it
repeatedly returns the last value’+1′.i can get
tbl_mods[ 1 ]
(first) and#tbl_mods
(last – or ‘length’),
so how can i get it to progress one at a time, from ‘first’,
until it reaches ‘last’ (and then goes back to first) ?(‘for’ just runs through all of them in one go, to the end of the table)
February 2, 2018 at 9:47 am #81198still trying to figure this out. might be getting
somewhere (having tried many permutations).
this ‘traverses’ the table one step at a time, but
misses the first index, and gives a nil error when
it reaches the end:function runCallback() for i,v in ipairs(tbl_mods) do tbl_mods=tbl_mods[ i+1 ] icount = tbl_mods[ 1 ] console(String("i="..i.."_v="..v)) end console(String("done="..icount)) end
this is the output of ‘icount’:
LUA>> count start LUA>> i=1_v=8 LUA>> i=2_v=9 LUA>> i=3_v=11 LUA>> i=4_v=13 LUA>> i=5_v=14 LUA>> i=6_v=15 LUA>> done=9 LUA>> i=1_v=9 LUA>> i=2_v=11 LUA>> i=3_v=13 LUA>> i=4_v=14 LUA>> i=5_v=15 LUA>> done=11 LUA>> i=1_v=11 LUA>> i=2_v=13 LUA>> i=3_v=14 LUA>> i=4_v=15 LUA>> done=13 LUA>> i=1_v=13 LUA>> i=2_v=14 LUA>> i=3_v=15 LUA>> done=14 LUA>> i=1_v=14 LUA>> i=2_v=15 LUA>> done=15 LUA>> i=1_v=15 LUA>> count stop
strange thing is that index1 seems to shift along as
it counts. and in fact the result (‘done’) is shifted
by 1 at each stage.(‘done’ will, basically, give the next seqstep to progress to)
February 2, 2018 at 9:54 am #81199trying this:
function runCallback() for i,v in ipairs(tbl_mods) do tbl_mods=tbl_mods[ i+1 ] icount = tbl_mods[ 1 ] console(String("i="..i.."_v="..v)) end console(String("done="..icount)) end
this outputs:
LUA>> count start LUA>> i=1_v=8 LUA>> i=2_v=9 LUA>> i=3_v=11 LUA>> i=4_v=13 LUA>> i=5_v=14 LUA>> i=6_v=15 LUA>> done=9 LUA>> i=1_v=9 LUA>> i=2_v=11 LUA>> i=3_v=13 LUA>> i=4_v=14 LUA>> i=5_v=15 LUA>> done=11 LUA>> i=1_v=11 LUA>> i=2_v=13 LUA>> i=3_v=14 LUA>> i=4_v=15 LUA>> done=13 LUA>> i=1_v=13 LUA>> i=2_v=14 LUA>> i=3_v=15 LUA>> done=14 LUA>> i=1_v=14 LUA>> i=2_v=15 LUA>> done=15 LUA>> i=1_v=15 LUA>> count stop
it is offsetting the ‘done’ count by +1,
and seems to shift the table for each
repetition (this function is fired by the
timer, producing a ‘done=etc’)it stops when it runs out of index and returns
a nil error.(should be fixable)February 2, 2018 at 9:57 am #81200soz, typo. should be:
tbl_mods { i ] = tbl_mods[ i+1 ]
-
AuthorPosts
- The forum ‘Programming’ is closed to new topics and replies.