simple sequencer

Home Forums General Programming simple sequencer

Tagged: 

Viewing 20 posts - 41 through 60 (of 163 total)
  • Author
    Posts
  • #73742
    human fly
    Participant
      • Topics: 124
      • Replies: 1070
      • Total: 1194
      • ★★★★

      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)

      #73827
      human fly
      Participant
        • Topics: 124
        • Replies: 1070
        • Total: 1194
        • ★★★★

        new 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…16

        is 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.
        #73829
        human fly
        Participant
          • Topics: 124
          • Replies: 1070
          • Total: 1194
          • ★★★★

          looks like table names cannot be ‘handled’
          relevant post here;

          http://www.computercraft.info/forums2/index.php?/topic/5187-lua-solved-table-name/

          #73830
          dnaldoog
          Participant
            • Topics: 4
            • Replies: 480
            • Total: 484
            • ★★

            Not 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
            
            #73841
            human fly
            Participant
              • Topics: 124
              • Replies: 1070
              • Total: 1194
              • ★★★★

              so 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
              #73842
              human fly
              Participant
                • Topics: 124
                • Replies: 1070
                • Total: 1194
                • ★★★★

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

                #73843
                dnaldoog
                Participant
                  • Topics: 4
                  • Replies: 480
                  • Total: 484
                  • ★★
                  
                  function 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
                  🙂

                  #73855
                  human fly
                  Participant
                    • Topics: 124
                    • Replies: 1070
                    • Total: 1194
                    • ★★★★

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

                    #73865
                    human fly
                    Participant
                      • Topics: 124
                      • Replies: 1070
                      • Total: 1194
                      • ★★★★

                      except 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)

                      #73871
                      dnaldoog
                      Participant
                        • Topics: 4
                        • Replies: 480
                        • Total: 484
                        • ★★

                        I think to clear a table you just need

                        
                        tabl_pattern1={}
                        
                        #73872
                        human fly
                        Participant
                          • Topics: 124
                          • Replies: 1070
                          • Total: 1194
                          • ★★★★

                          i 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… 🙂

                          #73873
                          dnaldoog
                          Participant
                            • Topics: 4
                            • Replies: 480
                            • Total: 484
                            • ★★

                            The 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,

                            #73874
                            human fly
                            Participant
                              • Topics: 124
                              • Replies: 1070
                              • Total: 1194
                              • ★★★★

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

                              #73875
                              human fly
                              Participant
                                • Topics: 124
                                • Replies: 1070
                                • Total: 1194
                                • ★★★★

                                can 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.cpp

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

                                #73876
                                human fly
                                Participant
                                  • Topics: 124
                                  • Replies: 1070
                                  • Total: 1194
                                  • ★★★★

                                  okay.. 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?

                                  #73877
                                  human fly
                                  Participant
                                    • Topics: 124
                                    • Replies: 1070
                                    • Total: 1194
                                    • ★★★★

                                    (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.
                                    #73882
                                    human fly
                                    Participant
                                      • Topics: 124
                                      • Replies: 1070
                                      • Total: 1194
                                      • ★★★★

                                      another 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.
                                      >panel

                                      Attachments:
                                      You must be logged in to view attached files.
                                      #73885
                                      human fly
                                      Participant
                                        • Topics: 124
                                        • Replies: 1070
                                        • Total: 1194
                                        • ★★★★

                                        my 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)

                                        #73888
                                        dnaldoog
                                        Participant
                                          • Topics: 4
                                          • Replies: 480
                                          • Total: 484
                                          • ★★

                                          It’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.

                                          🙂

                                          #73889
                                          human fly
                                          Participant
                                            • Topics: 124
                                            • Replies: 1070
                                            • Total: 1194
                                            • ★★★★

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

                                          Viewing 20 posts - 41 through 60 (of 163 total)
                                          • The forum ‘Programming’ is closed to new topics and replies.
                                          There is currently 0 users and 83 guests online
                                          No users are currently active
                                          Forum Statistics
                                          Threads: 2,495, Posts: 17,374, Members: 77,605
                                          Most users ever online was 12 on January 22, 2019 3:47 pm
                                          Ctrlr