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 9, 2017 at 11:21 am #73742
Now I don’t know where I read about
_G
, but take this example:hi,
i’ve run your example – seems to distinguish between alphanumericals and
‘all ascii’- tried to adapt it to _[G] without succes (as that doesn’t
like ‘local’) and got ‘global i’ nil error.am currently trying to make a selector button array, that spits out the
result from, a button group, using a loop, and _G[], and for some reason
cannot nail it. (see other topic reply – re: button array)December 13, 2017 at 8:55 pm #73827new version of this panel at bottom of this post.
stepsequencer runs, randomizes, collects the data.
now have working momentary ‘pattern’ selectors, not
yet linked to anything, but these will a/designate
an array to be written to, in conjunction with the
‘write’ button method, and retrieve data and assign
it to the stepsequencer when clicked.
that’s the plan for the next stage anyway 🙂my question now is: if i have created 16 tables on
startup (for 16 patterns), named:
ie: tabl_pattern1, 2, 3…16is there a way to get/designate a table name in the
same way you can with a generically named modulator/component,
ie: blablabla..i
?
i can get my data, and get it into any named pre-created table,
using table.insert, concatenate and print to console, so far.
see panel>> saveCurrent method, at the end (lots of previous
stuff in there early on, until clean-up)(hope nobody minds me posting this offtopic stuff … )
Attachments:
You must be logged in to view attached files.December 13, 2017 at 10:21 pm #73829looks like table names cannot be ‘handled’
relevant post here;http://www.computercraft.info/forums2/index.php?/topic/5187-lua-solved-table-name/
December 14, 2017 at 12:15 am #73830Not sure if I understand the question or reason for doing so, but you could return the table name of a certain integer, so if you entered ‘3’ for example you could do:
t={ [1]={"tabl_pattern1"}, [2]={"tabl_pattern2"}, [3]={"tabl_pattern3"}, [4]={"tabl_pattern4"}, [5]={"tabl_pattern5"}, [6]={"tabl_pattern6"}, [7]={"tabl_pattern7"}, [8]={"tabl_pattern8"}, [9]={"tabl_pattern9"}, [10]={"tabl_pattern10"}, [11]={"tabl_pattern11"}, [12]={"tabl_pattern12"}, [13]={"tabl_pattern13"}, [14]={"tabl_pattern14"}, [15]={"tabl_pattern15"}, [16]={"tabl_pattern16"}, } print(t[3][1]) -> returns tabl_pattern3 as a string
in the case above you could add extra fields to each array eg:
[3]={“table_pattern3″,4,”seq”,false},
or just:
t={"tabl_pattern1", "tabl_pattern2", "tabl_pattern3", "tabl_pattern4", "tabl_pattern5", "tabl_pattern6", "tabl_pattern7", "tabl_pattern8", "tabl_pattern9", "tabl_pattern10", "tabl_pattern11", "tabl_pattern12", "tabl_pattern13", "tabl_pattern14", "tabl_pattern15", "tabl_pattern16",} print(t[3]) -> returns tabl_pattern3 as a string
but then you wouldn’t need it to be so complex. You could just do:
function z(n) return "tabl_pattern"..n end print(z(3)) -> returns tabl_pattern3 as a string
or even this:
tabl_pattern3={"hello","world"} t={tabl_pattern1, tabl_pattern2, tabl_pattern3, tabl_pattern4, tabl_pattern5, tabl_pattern6, tabl_pattern7, tabl_pattern8, tabl_pattern9, tabl_pattern10, tabl_pattern11, tabl_pattern12, tabl_pattern13, tabl_pattern14, tabl_pattern15, tabl_pattern16,} print(t[3][1],t[3][2]) -> returns hello world as a string
December 14, 2017 at 8:39 am #73841so it seems i cannot invoke a table directly, by key,as with case below.
it needs to have an extra stage, treating the table name as a string
(which can then be inserted into an argument)?ie: you can’t have anything like
tabl_pattern..i={}
function patternArrays() tabl_pattbank={ tabl_pattern1={}, tabl_pattern2={}, tabl_pattern3={}, tabl_pattern4={}, tabl_pattern5={}, tabl_pattern6={}, tabl_pattern7={}, tabl_pattern8={}, tabl_pattern9={}, tabl_pattern10={}, tabl_pattern11={}, tabl_pattern12={}, tabl_pattern13={}, tabl_pattern14={}, tabl_pattern15={}, tabl_pattern16={}, } end
December 14, 2017 at 8:52 am #73842at this stage, i’m thinking about tables, because it seems
fairly easy to add data to a table. my 1st approach, because
the handling seemed straightforward.strings instead of tables?
i guess i can also build a string for each data group instead
– since the data has to end up back as a string at some point.so i can just as easily pre-initialize/declare some string variables,
to have strings assigned to? …December 14, 2017 at 4:47 pm #73843function patternArrays() tabl_pattbank={ tabl_pattern1={}, tabl_pattern2={"hello","world"}, tabl_pattern3={}, tabl_pattern4={}, tabl_pattern5={}, tabl_pattern6={}, tabl_pattern7={}, tabl_pattern8={}, tabl_pattern9={}, tabl_pattern10={}, tabl_pattern11={}, tabl_pattern12={}, tabl_pattern13={}, tabl_pattern14={}, tabl_pattern15={}, tabl_pattern16={}, } end patternArrays() print (tabl_pattbank.tabl_pattern2[1],tabl_pattbank.tabl_pattern2[2]) -- prints 'hello world' --print(tabl_pattbank[2][1],tabl_pattbank[2][2]) -- doesn't work
print (tabl_pattbank.tabl_pattern2[1],tabl_pattbank.tabl_pattern2[2]) — prints ‘hello world’
–print(tabl_pattbank[2][1],tabl_pattbank[2][2]) — doesn’t work
🙂December 15, 2017 at 1:58 pm #73855ok, got that.
a tabl_pattbank with tabl_pattern1…16 could be useful later,
but for now, i’ve just had a mini-success going the ‘long’ way:-initialize/declare the 16 pattern tables on start
-made new method called ‘writeDest’ with all 16 options
for saveDest = i , and i call that method in place of
the ‘for k,v in ipairs..’ loop used for table.insert.
(therefore ‘saveDest’ is no longer local)it’s still a bit wobbly, just made it, but it seems to return
a new batch of data each time i hit randomize all and a new
pattern destination button.having a quick look at something seems to work. it’s like micro-naps 🙂
December 16, 2017 at 3:26 pm #73865except it was accumulating pattern upon pattern each time,
so that 80 bytes becomes 160 becomes 240 etc.so i had to look for a workaround to clear the table each
time – this is still quite young, just figured it out, partly –to clear a table before rewriting it, i found i can do:
if saveDest ==1 then for k,v in pairs(tabl_pattern1) do tabl_pattern1[k]=nil end for k,v in ipairs(tabl_current) do table.insert(tabl_pattern1,tabl_current[k]) end
and so far, it seems to be working. i’m doing the same thing
for the table that collects data, and the table that converts
it to hex.(just chucked it in all over the place, bodge-style)December 17, 2017 at 12:01 am #73871I think to clear a table you just need
tabl_pattern1={}
December 17, 2017 at 9:08 am #73872i did wonder about that. so i supposed that was the problem
with pre-creating those tables on startup, rather than locally
each time the method is run.also the result of my ‘great’ idea to split functions out into
new methods .. if i’m calling a table name in another method,
then it contains what it had – which i need intially, but then
i need to clear it to repeat the operation, or the new data
just stack with existing data.i’m going to go through the whole thing again today and see
where i can condense and re-unify it – now that i’ve got
something working. it helped to look at things separately,
rather than scrolling down a single huge method.last thing i looked at yesterday was the possibility of having
strings instead – so i can get at the names with ..i – or
memory blocks since that’s the ‘currency’ i want, to getRange
on. and those have ‘regular’ variable names, so that should be
possible.however: at what point do i convert to hex – or not at all ?
that was about getting size and keeping bytes visibly separated
with a space; concatening decimal, with different value ranges,
ie: some just 0/1, others 0-11
means the string length varies(and size too?) – not with hex.duh… 🙂
December 17, 2017 at 10:13 am #73873The first question there would be “Why do you need to convert to hex?”
If you make a table ‘local’ within a function it is recreated every time there is a call to that function: It is only existent within that function call.
function myFunction(x) local t={} t[1]=x print (t[1]) end myFunction(5) print(t[1]) ------------------------------------- 5 input:8: attempt to index a nil value (global 't')
If you need the value returned initially, just assign that to a global variable
function myFunction(x) local t={} t[1]=x -- this could be more than one element of course return (t[1]) end myOneOff=myFunction(7) print(myOneOff)
or
globalx=10 myFunction=function(flag,val) if flag == true then globalx=val else local t={1,2,4,3,5,6,7,8,22,33,5,65} for i, v in ipairs(t) do -- do something print (i,v) end -- loop end -- if/else end --function print("globalx is "..globalx) myFunction(true,24) print("globalx is "..globalx) myFunction(false,35) print("globalx is "..globalx)
Regards,
December 17, 2017 at 4:32 pm #73874those functions:
yup, yup, and not sure about the last one, need to think about that,
or test run it.do you have another Lua compiler you use? would be good to
have something to run stuff without Ctrlr.why do i convert to hex? lol, because i figured out how to !
no: actually, at that point i wanted the string to come out
the same length each time, and it was the first thing i tried.
have not rearranged things yet. thinking about that now.December 17, 2017 at 5:21 pm #73875can give a better answer now: i knew i could getRange on a memory block,
and knew ‘toHexString’ – have now tried ‘tostring’, and found out it
would be ‘toString'(capital S) – don’t know if this page is still valid:
(it’s in ‘deprecated’)
https://github.com/RomanKubiak/ctrlr/blob/master/Source/Lua/Deprecated/CtrlrLuaMemoryBlock.cppanyway, that doesn’t seem to work.
had a Ctrlr crash when i tried to just send the getRange data to a
label.so basically, i don’t know how to getRange on a simple string, and
that’s why i’m going via a memory block. which means going into
Hex, otherwise it thinks the decimal characters should be in byte
pairs.December 17, 2017 at 7:42 pm #73876okay.. i’m printing out my large data table to console, k,v …
so what are my options for getting a ‘range’ of a
table – say, if i want k,v from 1 to 16, or from 17 to 32, etc?i read here that Lua tables ‘do not have a method for selecting
subranges’ (5.2 or less). with 5.3, there is table.move ie:function subrange(t, first, last) return table.move(t, first, last, 1, {}) end
which i think makes sense to me … assuming i could
create and name that table, and perhaps have ‘first, last’
as … numericals with square brackets? essentially creating
a new table with the items selected. isn’t that the same as
copying them out with table.insert, except they are being
removed from the original table?December 17, 2017 at 8:40 pm #73877(couldn’t get that to work …)
how about if i do this. not sure what i can do for string.format
instead of hex, so integer seems reasonable(?). this makes a new
table, just for semi tones (from the bulk pattern data, ie: gets
a range of keys):local tabl_semi={} for k,v in ipairs(tabl_current) do if k >=17 and k <=32 then tabl_current[k]=string.format("%.2i", v) table.insert (tabl_semi,tabl_current[k]) end end for k,v in ipairs(tabl_semi) do console(String("table_semi="..v)) end
(‘%.2i’ gives decimals with 2 characters, so it counts 01,02, etc.)
*edit* also as
tabl_current[k]=tonumber(v)
which fills the table with normal decimals. that’s the one 😉was looking at this page:
https://www.gammon.com.au/scripts/doc.php?lua=string.format*more edit* – can also do:
string.format("%d", v)
or
string.format("%i", v)
or for 2-character, also:
string.format("%.2d", v)
- This reply was modified 6 years, 4 months ago by human fly.
December 18, 2017 at 8:38 am #73882another version to look at > zip > v.68
i’m extracting from the bulk table into separate tables,
specifying a value range for [ k ] with >= and <= >it -seems to- work if i ‘clear all’ before i do ‘write’:
all displays update, and the console displays separate strings
correctly.but as soon as i randomize all, the 2nd string only returns
12 keys, and the other strings are empty.i wondered if this is because ‘tabl_current’ is referenced across
2 methods, but not sure. also: have reverted to creating the tables
at startup, this did not seem to make a difference. same with
initializing tables or filling keys with nil (seems the same result).so that’s as far as i’ve got to today.
>panelAttachments:
You must be logged in to view attached files.December 18, 2017 at 4:43 pm #73885my feeling is that it should work 🙁
every time, if i ‘clear sequence’ and reset everything to default,
it spits out separate table.concat strings. everything okay.and when it’s not reset, it spits out whatever it wants.
i’m seeing several ways of handing data here:
-as tables ( can specify keys )
-as strings ( need to know a lot more about handling strings;
would need to know how many characters – use %.2d decimal ?)
and:
-as memory blocks ( can getRange; but seems to like being spat
out ‘toHexString’, not sure if/how ‘toString’ works)keys don’t care how many characters there are in a decimal number …
it should work.
i’m going to try having only %.2d numbering in value lists.
don’t know how this can affect arithmetic – ie: if i want to
force to scale later. (hello theory of harmony)December 19, 2017 at 12:07 am #73888It’s looking good. I would flip the button title Run/Stop around so it says Run before you click on it, not Stop.
https://www.lua.org/cgi-bin/demo
tabl_hexcurrent={} tabl_current={8,9,10,11,12,13,14,15,16,17,18,19} --[[ for k,v in ipairs(tabl_current) do tabl_current[k]=string.format("%.2X", v) table.insert(tabl_hexcurrent,tabl_current[k]) end --]] -- should be for _,v in ipairs(tabl_current) do table.insert(tabl_hexcurrent,string.format("%.2X",v)) end for i,v in ipairs(tabl_hexcurrent) do print(i.." "..v) end
Here you are assigning the hex value of the value (v) to the index (i) or (k) as you call it. Then assigning that (k) to another table when it’s already (v ) anyway. k and v do not need to be referenced as tabl_current[k],tabl_current[v] within an ipairs loop – they are already k,v.
🙂
December 19, 2017 at 8:10 am #73889**https://www.lua.org/cgi-bin/demo**
duh, oh yeah, had forgotten already 🙂
a non-web version would be good – if it doesn’t cause
a conflict with the Ctrlr installation.thanks for reminding me that k,v are ‘arbitrary’,
eg: what you call them.
i’ll see if that fixes it..stop/run: yeah 🙂 had it like that originally.
thought it looked weird to have run=red. i’ll change the
colours or something, look at some other transports. -
AuthorPosts
- The forum ‘Programming’ is closed to new topics and replies.