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
-
December 28, 2017 at 4:07 pm #73994
oh .. *so it is* π
don’t know if i needed ‘tonumber’ with tabl_count3[ k ].
don’t need it now.okay, so that is running through once.
i was thinking, what if i could get it to start again,
until i tell it to stop.. so i would want to AND it with
a run/stop button – but that’s where if/elseif might not
be ideal. i’m getting a bit scared of ‘while’ !i put it in a subfunction at the moment, in case it could
be an idea to just run/call that. looks like:function forRange() local tbl_count3 = {} local a = panel:getModulatorByName("start") :getValue() local b = panel:getModulatorByName("end") :getValue() for i=a,b,1 do table.insert(tbl_count3,i) -- returnConcat3 = table.concat(tbl_count3, " ") end --console(String(returnConcat3)) panel:getComponent("display1"):setPropertyString("uiLabelText",""..returnConcat3) function counter() for k,v in ipairs(tbl_count3) do console(String(v)) if v < b then console(String("add one")) --addOne() elseif v == b then --returnToStart() console(String("return to start")) end end end counter() end
December 29, 2017 at 1:00 am #74002Not sure what you are trying to do, but this code doesn’t make sense to me, because you are concatenating tbl_count3 within the loop. Surely it should be concatenated after the loop has completed?
for i=a,b,1 do table.insert(tbl_count3,i) -- returnConcat3 = table.concat(tbl_count3, " ") end
rather…
for i=a,b do table.insert(tbl_count3,i) end returnConcat3 = table.concat(tbl_count3, " ")
December 29, 2017 at 8:15 am #74007uh yes, sorry, silly mistake there; i was moving the
concatenate string-and-display bit around.it isn’t actually necessary to concatenate it, to go
to the next bit, where it increments through the table
to the end.after that, yesterday, i had a go at making it start
from the top again, but it crashed Ctrlr – went into
an infinite loop, i suppose. forgot that i’m just
printing out a series at the moment, not running a
counter, with a time interval etc.so it is in fact:
local tbl_count3 = {} local a = panel:getModulatorByName("start") :getValue() local b = panel:getModulatorByName("end") :getValue() for i=a,b,1 do table.insert(tbl_count3,i) end
followed by:
for k,v in ipairs(tbl_count3) do console(String(v)) if v < b then console(String("add one")) --addOne() elseif v == b then --returnToStart() console(String("return to start")) end end
getting there – this is about building the table and
‘counting’ from it. need to tie it in with a timer and
callback thing, and also make it run continuously.also wondering about what manipulations can happen at the
point where ‘v’ gets added to the table – ie: skip steps,
or only include active steps, etc. – but i have to rebuild
a fresh mini-panel for this.December 29, 2017 at 2:47 pm #74009back to the drawing board. this won’t work like this,
because when it hits v==b (generating count=a), it
goes back one step too early.anyway, was just a preliminary. don’t quite know what
i was going to do with it next.(was more about chucking
a varying range into a table, ..i think..)original clocking was good; possibly if it has ‘skip’
(or conversely, ‘on’) buttons or something, and a table
of valid step numbers, and compares buttons that are ‘on’
to table ‘v’ entries, for valid callbacks, that could work.December 29, 2017 at 6:24 pm #74011had a look at reverse-listing a table – as i couldn’t get it
to work – so i found these:for i = #tbl_count3, 1, -1 do value = tbl_count3 [ i ] console(String(i .. ": " .. value)) end
realise i don’t know how to list it normally with # – not doing
anything as:
for i = #tbl_count3, 1, 1 do
so not sure yet what’s wrong.and then there was this one, more complicated:
(first thing i found, don’t like it much, or know what math.floor is)for i=1, math.floor( #tbl_count3 / 2 ) do tbl_count3 [ i ], tbl_count3[#tbl_count3 - i + 1] = tbl_count3[#tbl_count3 - i + 1], tbl_count3 [ i ] end
lots of ideas for array functions here, but i don’t understand
how the table can be addressed by having the table referred to
as a variable (arr)eg:
function Reverse (arr)
this one looks interesting:function Reverse (arr) local i, j = 1, #arr while i < j do arr [ i ], arr [ j ] = arr [ j ], arr [ i ] i = i + 1 j = j - 1 end end
https://forums.coronalabs.com/topic/61784-function-for-reversing-table-order/
December 29, 2017 at 6:54 pm #74012okay…
to count up: (was putting 1st 1 in the wrong place, misunderstanding
what those entries were)for i =1, #tbl_count3,1 do value = tbl_count3 [ i ] console(String(i .. ": " .. value)) end
to count down:
for i = #tbl_count3, 1, -1 do value = tbl_count3 [ i ] console(String(i .. ": " .. value)) end
December 30, 2017 at 4:32 am #74019I noticed the forum code (wordpress) deletes [ n ] – is that the case here, because you would need that? π
console(String(i .. ": " .. value[ i ]))
December 30, 2017 at 8:30 am #74020ah yes, sorry, forgot to amend that.
see above. slightly different.also amended previous one.
December 30, 2017 at 9:36 am #74021for some reason, the elseif condition does not return
the reverse order here >panel>
they seem to work individually – ?!-
**note that i put the table build inside/after the
condition here, to see if it makes a difference.
i’m new to #table – just means last item in table,
doesn’t it?
(you may have to move start/end modulators to generate
the values)if a < b then for i=a,b,1 do table.insert(tbl_count3,i) end for i =1, #tbl_count3,1 do value = tbl_count3 [ i ] console(String(i .. ": " .. value)) end elseif a > b then for i=a,b,1 do table.insert(tbl_count3,i) end for i = #tbl_count3,1, -1 do value = tbl_count3 [ i ] console(String(i .. ": " .. value)) end end
Attachments:
You must be logged in to view attached files.December 30, 2017 at 10:20 am #74023finally got it. it’s this: (panel>)
‘for i=a,b,-1’ in the elseif. reverse with ‘-1’ there, instead
of 1. was getting it counting reverse with other ways, but
showing as if forwards order(if you see what i mean).if a < b then for i=a,b,1 do table.insert(tbl_count3,i) end for i =1, #tbl_count3,1 do value = tbl_count3 [ i ] console(String(i .. ": " .. value)) end elseif a > b then for i=a,b,-1 do table.insert(tbl_count3,i) end for i =1, #tbl_count3,1 do --not this--[ for i = #tbl_count3,1, -1 do ]-- value = tbl_count3 [ i ] console(String(i .. ": " .. value)) end end
Attachments:
You must be logged in to view attached files.December 30, 2017 at 10:30 am #74025alternatively π
if a < b then c =1 elseif a > b then c= -1 end for i=a,b,c do table.insert(tbl_count3,i) end for i =1, #tbl_count3,1 do value = tbl_count3 [ i ] console(String(i .. ": " .. value)) end
December 30, 2017 at 10:39 am #74026… in which case… c is a multiplier… of sorts.
if you multiply a number by -1, it’s an inverter.
i just tried c= -2 and it goes back 10,8,6,4,2mm..? don’t know yet what that could be good for.
wondering atm if a pattern could be substituted there,
ie: a series of numbers that it would follow.
ie: if these were pitches, obtained from _G [ “semi”..i ]
and could be forced to a pattern of intervals… π :-p
just a thought atm.December 31, 2017 at 1:17 pm #74034quick post/update on this – getting somewhere with it,
but i’ve got a(nother) mental block on how to get a
table with _G [ ] *if it is already defined/written*before, i was writing tables on the fly; now i’m declaring
lists/arrays on startup.i think i have correctly/semi-correctly given the intervals
for 29 chords and scales, in a function containing tables/arrays
-‘fields’ according to prior error messages, when it couldn’t
find any, but i’m now forcing it to find/call at least one field
filled with zeros, and it isn’t crashing.i now need to find tables called “tbl_chd”..i and their contents.
atm i’ve just called these arrays to display them on a label/display.
the rest is just a demo of where i’ve got to so far.*the idea of this, vaguely, is to return values within start/end
range that are also within the array. it’s a kind of Venn diagram
thing. (and now i’m off to crack on with it, see if i can figure
it out)best to see panel > list table v08
Attachments:
You must be logged in to view attached files.December 31, 2017 at 1:25 pm #74036quick post/update on this β getting somewhere with it,
but iβve got a(nother) mental block on how to get a
table with _G [ ] *if it is already defined/writtenIf a variable is pre-defined you don’t need _G[].
December 31, 2017 at 2:15 pm #74037ok, so, if i’m doing this, – and in every case, it has to return
0,0,0,0 – i want to replace that line (2) with the table in it, so
that it finds the actual table, for 0-29. (‘chords’ is a combo list,
each value represents one of the tables)function showChord() for x=0,29 do _G["tbl_chd"..x]={0,0,0,0} end x = panel:getModulatorByName("chords"):getValue() console(String("x : "..x)) for i =1, #(_G["tbl_chd"..x]),1 do value = _G["tbl_chd"..x] [ i ] console(String(i .. ": " .. value)) end chordConcat = table.concat((_G["tbl_chd"..x]), " ") console(String(chordConcat)) panel:getComponent("display2"):setPropertyString("uiLabelText",""..chordConcat) end
December 31, 2017 at 4:27 pm #74038function showChord() local x = panel:getModulatorByName("chords"):getValue()+1 local chordConcat = table.concat(_G["tbl_chd"..x], " ") panel:getComponent("display2"):setPropertyString("uiLabelText",chordConcat) end
Is this what you’re after HF? Also the table definitions are hidden in function tables()
--function tables() --major tbl_chd1 ={0,4,7} -- 12 --tbl_maj tbl_chd2 ={0,4,7,9} -- 12 --tbl_maj6 ...
…so they need to be outside that function unless you call the function somewhere.
Regards.
December 31, 2017 at 6:10 pm #74041oh, i see, of course – for some reason i was thinking that
the method/function would be run on panel start, and that
therefore they would exist – big ‘duh’…
so if i just have ‘panel loaded’ call that function with
the tables in it, (as i did before with the other panel,
of course…) then they will exist/won’t be nil.
i’ll have another go !Happy New Year to all out in Ctrlr land, btw.
December 31, 2017 at 7:04 pm #74044great: is working now. had to create a few more tables
so numbers matched. calling the tables function at the
top, with +1 offset on the value. tried to do it without
_G [ ], just as (tabl_chd..x), but it wouldn’t have it.so now it’s:
function showChord() tables() x = panel:getModulatorByName("chords"):getValue()+1 --console(String("x : "..x)) for i =1, #(_G["tbl_chd"..x]),1 do value = _G["tbl_chd"..x] [ i ] --console(String(i .. ": " .. value)) end local chordConcat = table.concat((_G["tbl_chd"..x]), " ") console(String(chordConcat)) panel:getComponent("display2"):setPropertyString("uiLabelText",""..chordConcat) end
December 31, 2017 at 7:30 pm #74045have to figure out what to do with it now π
good for learning scale and chord intervals..January 1, 2018 at 1:22 am #74046If a variable is predefined you donβt need _G[].
I was slightly wrong there, because if you want to reference that variable by concatenating ‘n’ i.e.
"table"..n
then you need_G[]
as you found out, but if you access a predefined global variable likemyValue
defined elsewhere (say at start-up), you don’t need_G[myValue]
– that’s what I meant.Yes interesting to see those intervals like that. Next challenge would be to map them to a graphic of a keyboard!
Happy New Year to you!
-
AuthorPosts
- The forum ‘Programming’ is closed to new topics and replies.