simple sequencer

Home Forums General Programming simple sequencer

Tagged: 

Viewing 20 posts - 141 through 160 (of 163 total)
  • Author
    Posts
  • #80812
    dnaldoog
    Participant
      • Topics: 4
      • Replies: 480
      • Total: 484
      • ★★

      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! ☺️

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

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

        #80816
        Possemo
        Participant
          • Topics: 14
          • Replies: 638
          • Total: 652
          • ★★★

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

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

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

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

                morning 🙂

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

                  morning 🙂

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

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

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

                      Isn’t this

                      last=tbl_mods[#tbl_mods+1-1]

                      the same as

                      last=tbl_mods[#tbl_mods]

                      ???

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

                        okay 🙂 thanks for pointing that out. did look at bit
                        odd when i looked at it today. (just me learning concepts)

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

                          I 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 parameter n but later call it without n? 🙂

                          • This reply was modified 6 years, 3 months ago by dnaldoog.
                          • This reply was modified 6 years, 1 month ago by dasfaker.
                          #80869
                          dnaldoog
                          Participant
                            • Topics: 4
                            • Replies: 480
                            • Total: 484
                            • ★★

                            I 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 parameter n but later call it without n? 🙂

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

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

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

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

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

                                  the 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 of

                                  icount = 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.

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

                                    ‘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 doi=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.

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

                                      this 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 use i=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)

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

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

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

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

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

                                            soz, typo. should be:

                                            tbl_mods { i ] = tbl_mods[ i+1 ]

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