simple sequencer

Home Forums General Programming simple sequencer

Tagged: 

Viewing 20 posts - 81 through 100 (of 163 total)
  • Author
    Posts
  • #73994
    human fly
    Participant
      • Topics: 124
      • Replies: 1070
      • Total: 1194
      • β˜…β˜…β˜…β˜…

      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
      #74002
      dnaldoog
      Participant
        • Topics: 4
        • Replies: 480
        • Total: 484
        • β˜…β˜…

        Not 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, " ")
        
        
        #74007
        human fly
        Participant
          • Topics: 124
          • Replies: 1070
          • Total: 1194
          • β˜…β˜…β˜…β˜…

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

          #74009
          human fly
          Participant
            • Topics: 124
            • Replies: 1070
            • Total: 1194
            • β˜…β˜…β˜…β˜…

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

            #74011
            human fly
            Participant
              • Topics: 124
              • Replies: 1070
              • Total: 1194
              • β˜…β˜…β˜…β˜…

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

              https://github.com/ggcrunchy/tektite_core/blob/def1371076b3f2bf5180a9aad4c9bd421796c3b1/array/funcs.lua#L172

              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/

              #74012
              human fly
              Participant
                • Topics: 124
                • Replies: 1070
                • Total: 1194
                • β˜…β˜…β˜…β˜…

                okay…
                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
                #74019
                dnaldoog
                Participant
                  • Topics: 4
                  • Replies: 480
                  • Total: 484
                  • β˜…β˜…

                  I noticed the forum code (wordpress) deletes [ n ] – is that the case here, because you would need that? πŸ™‚

                  console(String(i .. ": " .. value[ i ]))

                  #74020
                  human fly
                  Participant
                    • Topics: 124
                    • Replies: 1070
                    • Total: 1194
                    • β˜…β˜…β˜…β˜…

                    ah yes, sorry, forgot to amend that.
                    see above. slightly different.

                    also amended previous one.

                    #74021
                    human fly
                    Participant
                      • Topics: 124
                      • Replies: 1070
                      • Total: 1194
                      • β˜…β˜…β˜…β˜…

                      for 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.
                      #74023
                      human fly
                      Participant
                        • Topics: 124
                        • Replies: 1070
                        • Total: 1194
                        • β˜…β˜…β˜…β˜…

                        finally 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.
                        #74025
                        human fly
                        Participant
                          • Topics: 124
                          • Replies: 1070
                          • Total: 1194
                          • β˜…β˜…β˜…β˜…

                          alternatively πŸ™‚

                          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
                          
                          #74026
                          human fly
                          Participant
                            • Topics: 124
                            • Replies: 1070
                            • Total: 1194
                            • β˜…β˜…β˜…β˜…

                            … 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,2

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

                            #74034
                            human fly
                            Participant
                              • Topics: 124
                              • Replies: 1070
                              • Total: 1194
                              • β˜…β˜…β˜…β˜…

                              quick 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.
                              #74036
                              dnaldoog
                              Participant
                                • Topics: 4
                                • Replies: 480
                                • Total: 484
                                • β˜…β˜…

                                quick 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

                                If a variable is pre-defined you don’t need _G[].

                                #74037
                                human fly
                                Participant
                                  • Topics: 124
                                  • Replies: 1070
                                  • Total: 1194
                                  • β˜…β˜…β˜…β˜…

                                  ok, 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
                                  #74038
                                  dnaldoog
                                  Participant
                                    • Topics: 4
                                    • Replies: 480
                                    • Total: 484
                                    • β˜…β˜…
                                    
                                    function 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.

                                    #74041
                                    human fly
                                    Participant
                                      • Topics: 124
                                      • Replies: 1070
                                      • Total: 1194
                                      • β˜…β˜…β˜…β˜…

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

                                      #74044
                                      human fly
                                      Participant
                                        • Topics: 124
                                        • Replies: 1070
                                        • Total: 1194
                                        • β˜…β˜…β˜…β˜…

                                        great: 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
                                        #74045
                                        human fly
                                        Participant
                                          • Topics: 124
                                          • Replies: 1070
                                          • Total: 1194
                                          • β˜…β˜…β˜…β˜…

                                          have to figure out what to do with it now πŸ™‚
                                          good for learning scale and chord intervals..

                                          #74046
                                          dnaldoog
                                          Participant
                                            • Topics: 4
                                            • Replies: 480
                                            • Total: 484
                                            • β˜…β˜…

                                            If 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 like myValue 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!

                                          Viewing 20 posts - 81 through 100 (of 163 total)
                                          • The forum ‘Programming’ is closed to new topics and replies.
                                          There is currently 0 users and 104 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