why is this method looping through several times?

Home Forums General Programming why is this method looping through several times?

This topic contains 21 replies, has 3 voices, and was last updated by  human fly 3 months, 2 weeks ago.

Viewing 20 posts - 1 through 20 (of 22 total)
  • Author
    Posts
  • #83626

    human fly
    Participant
    • Topics: 123
    • Replies: 1051
    • Total: 1174
    • ★★★★

    this runs the console command about 70 times:

    function testMethod()
    
    	padselct=nil
    	for i=1,24 do 
    	local padcolour=panel:getComponent("pad"..i):getProperty("uiButtonTextColourOff")
    		if padcolour~="FF1291DF" then 
    		padselct = i 
    		end
    	end
    --
    	kitselct=nil
    	for i=1,5 do 
    	local kitcolour=panel:getComponent("keydata"..i-1):getProperty("uiButtonTextColourOff")	
    		if kitcolour~="FF1291DF" then 
    		kitselct = i 
    		end
    	end
    --
    	keyselct=nil 
    	keyselct = (tbl_bankoffset[ kitselct ]+padselct) 	
    	--console(String("pad"..padselct.. ":kit"..kitselct..":keyselct"..keyselct))
    	console(String("found:pad/kit/key"))
    
    	for i=1,12 do 
    	local param = tbl_keyParam
    	param:setModulatorValue((_G[ "tbl_keyassgn"..keyselct ])[ i ],false,false,false)
    	end
    --	---------------------
    	local tblconcat =nil
    	tblconcat = table.concat(_G["tbl_keyassgn"..keyselct]," ")
    	panel:getComponent("lcd_top2"):setPropertyString("uiLabelText",tblconcat)
    	--console(String(""..tblconcat))	--[ check collected values]--
    --
    	local voice=(_G["tbl_keyassgn"..keyselct]) [ 1 ]	--[ get voice number ]--
    	vnmbr=nil --[ global ]--
    	vname=nil --[ global ]--
    	vnmbr= (_G["tbl_keyassgn"..keyselct]) [ 1 ]+1	--[ vnmbr:1st param ]--[ offset for index 0-99]--
    	vname= tbl_voiceName[ vnmbr ]	--[ get text voice name ]--
    --[ update display ]--
    	panel:getComponent("labl_VoiceNmbr"):setPropertyString("uiLabelText","voice "..voice..":"..vname)
    	panel:getComponent("lcd_paramval"):setPropertyString("uiLabelText","voice "..voice..":"..vname)
    	--console(String("show: voice "..voice..":"..vname))
    end
    • This topic was modified 3 months, 3 weeks ago by  human fly.
    • This topic was modified 3 months, 3 weeks ago by  human fly.
    • This topic was modified 3 months, 3 weeks ago by  human fly.
    #83648

    human fly
    Participant
    • Topics: 123
    • Replies: 1051
    • Total: 1174
    • ★★★★

    to clarify: i was curious to check whether what i was
    doing was efficient: having lots of little subfunctions,
    and having main functions calling them. seems to be
    working ok, but what’s happening that i can’t see?

    so i put in a console command, as a marker, that tells me
    each time that function has run, and where it should only
    appear once, it is appearing, depending on what i click,
    24 times, or 25, or 70 or more. in fact, the console thing
    runs multiple times whatever i click on my UI.

    leading me to conclude that i might have overdone the minifunctions
    thing, and might need to reconstruct some individual methods again.
    this function get called whatever operation is performed.

    #83649

    human fly
    Participant
    • Topics: 123
    • Replies: 1051
    • Total: 1174
    • ★★★★

    however, just what’s above, run on its own,
    produces the console command multiple times.

    would clicking one button on a UI somehow trigger
    other buttons with ‘onclick’ methods assigned to them?
    i’m assuming they don’t, so what’s posted above should
    be all that is run by the button.

    #83650

    daimondamps
    Participant
    • Topics: 7
    • Replies: 64
    • Total: 71

    Do you using some labelChanged callbak? So when you change something , callback is trigerred which is changing uiLabel wchich again triggers the callback.

    • This reply was modified 3 months, 3 weeks ago by  daimondamps.
    #83652

    human fly
    Participant
    • Topics: 123
    • Replies: 1051
    • Total: 1174
    • ★★★★

    i had one label as ‘editing begins with click’, so i changed
    that, – so no labels now have any method associated – and it
    made no difference.

    however, labels are used to write to, as displays.
    they themselves don’t have any ‘action’ by themselves.

    so that, above, should be the only script being run.
    will have to look at this again later.

    #83653

    daimondamps
    Participant
    • Topics: 7
    • Replies: 64
    • Total: 71

    It’s hard to tell because we don’t have whole panel. Something is triggering your script(and this is something what this script is changing)
    Maybe try to mute modulator
    param:setModulatorValue((_G[ “tbl_keyassgn”..keyselct ])[ i ],false,false,false)
    change to
    param:setValue((_G[ “tbl_keyassgn”..keyselct ])[ i ],true, true)

    • This reply was modified 3 months, 3 weeks ago by  daimondamps.
    • This reply was modified 3 months, 3 weeks ago by  daimondamps.
    • This reply was modified 3 months, 3 weeks ago by  daimondamps.
    #83657

    human fly
    Participant
    • Topics: 123
    • Replies: 1051
    • Total: 1174
    • ★★★★

    i wonder if it’s worth worrying about? as long as the panel runs?

    of course that doesn’t sit very well with one’s quest for
    efficiency.

    previously, i have stopped something from running twice,
    just by moving some of the script around. but i think
    this is different.

    wonder if the latter part is forcing it to find the variable
    multiple times. have to check if other sections are doing
    the same thing (more console commands).

    #83658

    human fly
    Participant
    • Topics: 123
    • Replies: 1051
    • Total: 1174
    • ★★★★

    ok i tried it just as ‘setValue’ and it did the same thing
    (why is it ‘true,true’ in that format? will check)

    so if i disable this bit/from here, it runs ok:

    for i=1,12 do 
    local param = tbl_keyParam
    --param:setModulatorValue((_G[ "tbl_keyassgn"..keyselct ])[ i ],false,false,false)
    param:setValue((_G[ "tbl_keyassgn"..keyselct ])[ i ],true,true)
    end

    so that’s making it run through the whole thing again
    -25 times, to be precise. that’s the one time it is supposed to,
    and 24 more times. mmm. i have 24 pads, or for each of the 12 parameters,
    it’s doing it twice… mystery continues…

    #83660

    daimondamps
    Participant
    • Topics: 7
    • Replies: 64
    • Total: 71

    There is true twice because it has input like (value, force, mute).
    I have similiar problem once. Try to change midi controller device to none and then once again to your device.

    Sysex problem – doubled sysex recived.

    • This reply was modified 3 months, 3 weeks ago by  daimondamps.
    • This reply was modified 3 months, 3 weeks ago by  daimondamps.
    #83663

    human fly
    Participant
    • Topics: 123
    • Replies: 1051
    • Total: 1174
    • ★★★★

    Hi,
    not a problem with midi yet because that bit still
    isn’t done – this is just debugging the panel generally.

    #83667

    daimondamps
    Participant
    • Topics: 7
    • Replies: 64
    • Total: 71

    You cannot debug function which affect a panel modulators without MIDI. Thay are affected. They sometimes some feedback loop’s problem.

    #83672

    human fly
    Participant
    • Topics: 123
    • Replies: 1051
    • Total: 1174
    • ★★★★

    note that i use the term debugging very loosely, don’t
    know exactly what that means technically. i’m ‘fault-finding’.

    it seems that as ‘keyselct’ is global, ie: not local
    and i’m looking for an index in a ‘global’ table, with:
    (_G[ "tbl_keyassgn"..keyselct ])[ i ]
    there is an issue there. as these are created on start-up,
    they already exist, and not nil.

    i will try it with fewer iterations to see what happens.
    nb: this does not seem to affect the operation of the UI;
    but sometimes there does seem to be a refresh delay, as if
    ‘something’ as going on. generally, it seems fast enough.
    but if this is going to cause problems further down the line,
    with sysex messages triggered 20x, obviously that is no good.

    i will think about the structure of my code again. it’s definitely
    that bit that’s doing it. i’ll look to see if it happens elsewhere.
    all the other console commands i’ve re-activated only trigger once.

    #83673

    human fly
    Participant
    • Topics: 123
    • Replies: 1051
    • Total: 1174
    • ★★★★

    if you want to look at the panel it is here:
    v.0.91
    https://app.box.com/s/jmy8wa2ij0bqmpwsiu8l34ioy4ehzzss

    at the moment, it is a UI for a drum machine, with pads
    recalling parameter values and displaying voice names etc.
    it’s experimental for me – so advance apologies if my
    attempt to structure it via a Function Library seems strange.
    overall this seems to be working ok, except this retriggering
    of one console command with pretty much every panel operation.

    #83677
    proton
    proton
    Participant
    • Topics: 16
    • Replies: 78
    • Total: 94

    Hi human fly,

    take a closer look at your findvoice(), fetchVoiceTable() and fetchKeyTable() methods. Those get triggered multiple times whenever you use the Kit button or the Pad button (in kitSelect() and padSelect() methods).
    Also in the Library() where you placed all those functions there are weird dependencies and triggering one of them triggers the other. I just glanced over quickly and did not test any further since I got a project to finish but I think you should start there. Also the way you create tables using the _G metamethods might have something to do with it. Dunno. Just few ideas to think about.
    Cheers!

    #83688

    human fly
    Participant
    • Topics: 123
    • Replies: 1051
    • Total: 1174
    • ★★★★

    thanks for looking through it.
    yes, of course – s’pose i knew some problems could
    arise by doing that. and some of it was thrown together
    with those series of functions, just getting things
    to work.

    sort of experimenting with the library thing. don’t know
    if it has downsides compared to just having separate
    methods – does it have to run through the whole thing
    each time it wants that function?

    discovered that the_G [ .. ] tables have to be created at
    startup, or it doesn’t work – tried without, to see if it was
    creating doubles of those tables.

    they are created on startup, filled with default values,
    and then each time something is changed, the table for that voice,
    or key, is initialised and rebuilt ie: filled with current display
    values. when a pad with that Voice is clicked, values from the
    corresponding _G table are sent to their modulators – so the dispay
    jumps to that pad’s settings.

    which sort of seems to work – as a way of avoiding having hundreds
    of tabs each with 20 or more modulators.

    #83707

    human fly
    Participant
    • Topics: 123
    • Replies: 1051
    • Total: 1174
    • ★★★★

    it is definitely this that is doing it.
    can anyone suggest an alternative way?
    ‘keyselect’ is the id number of each key assignment,
    and the _G table contain all the values that need to
    be retrieved.
    is it maybe the way that ‘keyselect’ is obtained, by
    finding which pad (1-24) and which kit (0-5), performing
    separate iterations? is there an art to this? or do i just
    have to run through it as many times as needed? ( i put the
    console command in as a marker, to check for loops like this )

    for i=1,12 do 
    local param = tbl_keyParam
    --param:setModulatorValue((_G[ "tbl_keyassgn"..keyselct ])[ i ],false,false,false)
    param:setValue((_G[ "tbl_keyassgn"..keyselct ])[ i ],true,true)
    end
    #83708

    human fly
    Participant
    • Topics: 123
    • Replies: 1051
    • Total: 1174
    • ★★★★

    does the same thing with:

    for i,v in ipairs ((_G[ "tbl_keyassgn"..keyselct ]),1) do 
    local param = tbl_keyParam
    param:setModulatorValue(v,false,false,false)
    end

    so it seems to be forcing the previous functions to run for each
    time it needs the ‘keyselct’ variable. something like that.
    i’m ok with skipping the function calls and putting the code back
    in there instead. but i don’t know if it will fix it as it is.

    #83767

    human fly
    Participant
    • Topics: 123
    • Replies: 1051
    • Total: 1174
    • ★★★★

    aaagh – tried to unpack functions back into the method,
    now i’ve broken it…start again.

    reinstated console messages to check where it got up
    to, and it’s always the same thing that makes it loop
    through. maybe it needs to.

    changed some things round, and got different patterns
    of repeats.

    got lost now, so back to last good version.
    trying to make a readable version.
    (so much for putting it all in separate functions)

    #83768

    human fly
    Participant
    • Topics: 123
    • Replies: 1051
    • Total: 1174
    • ★★★★

    ok, here’s a working unpack of the little subfunctions.
    it reaches the end and then spews out a load of console
    stuff that isn’t even in it. very weird. so it’s something
    in the panel. see below for version.
    (“kbmidi()” is nothing to worry about – deals with another
    part of the panel)

    function padSelect(mod,value)
    	-- This variable stops index issues during panel bootup
    	if panel:getRestoreState() == true or panel:getProgramState() == true then return end
    --	------------------------------------------------------
    	psub=nil							--[ pad number ]--
    	local padName= L(mod:getName())
    	psub=tonumber(string.sub(padName,4))
    --	------------------------------------------------------
    	kitnmbr	=nil						--[ kgetcolour ]--
    	local tbl_kitcolour={}
    	for i=1,5 do 
    	local kitcolour=panel:getComponent("keydata"..i-1):getProperty("uiButtonTextColourOff")
    	table.insert(tbl_kitcolour,kitcolour)
    --
    		if tbl_kitcolour~="FF1291DF" then 
    		kcolourB = tbl_kitcolour		--[ for psetcolour ]--
    		kcolourA ="FF1291DF"			--[ for psetcolour ]--
    		end
    --
    		if kcolourB == tbl_kcolourB then 			--[ see utilTables ]--
    		kitnmbr = i-1	--[ get current kit number ]--	--[ offset to 0-4 ]--
    		end
    	end
    --	------------------------------------------------------
    	local tbl_pads={}	--[ psetcolour ]--
    	for i=1,24 do
    	local pad=panel:getModulatorByName("pad"..i)
    	table.insert(tbl_pads,pad)
           	if i ~= psub then
    		tbl_pads[ i ]	:getComponent():setProperty("uiButtonTextColourOff",kcolourA, false)	
    		else
    		tbl_pads[ psub ]:getComponent():setProperty("uiButtonTextColourOff",kcolourB, false)
    			--[ change tab etc ]--
    			--panel:getComponent ("tabs_voiceEdit"):setPropertyInt("uiTabsCurrentTab", psub-1) -- or i-1
           	end
    	end
    	console(String("setpcolour"))	--..padselct..":"..psub))
    --	------------------------------------------------------
    	kitselct=nil		--[ findkit ]--
    	for i=1,5 do 
    	local kitcolour=panel:getComponent("keydata"..i-1):getProperty("uiButtonTextColourOff")	
    		if kitcolour~="FF1291DF" then 
    		kitselct = i 
    		end
    	end
    	console(String( "kit:"..kitselct))
    --	------------------------------------------------------
    	padselct=nil		--[ findpad ]--
    	for i=1,24 do 
    	local padcolour=panel:getComponent("pad"..i):getProperty("uiButtonTextColourOff")
    		if padcolour~="FF1291DF" then 
    		padselct = i 
    		end
    	end
    	console(String( "pad:"..padselct))
    --	------------------------------------------------------
    	keyselct=nil	--[ KeyAssign number, global ]--	--[ keynumber ]--
    	keyselct = (tbl_bankoffset[ kitselct ]+padselct) 	
    	console(String("keyselct:"..keyselct))
    --	------------------------------------------------------
    	local voice=(_G["tbl_keyassgn"..keyselct]) [ 1 ]	--[ get voice number ]--
    	vnmbr=nil --[ global? ]--
    	vname=nil --[ global? ]--
    	vnmbr= (_G["tbl_keyassgn"..keyselct]) [ 1 ]+1	--[ vnmbr:1st param ]--[ offset for index 0-99]--
    	vname= tbl_voiceName[ vnmbr ]	--[ get text voice name ]--
    --[ update display ]--
    	panel:getComponent("labl_VoiceNmbr"):setPropertyString("uiLabelText","voice "..voice..":"..vname)
    	panel:getComponent("lcd_paramval"):setPropertyString("uiLabelText","voice "..voice..":"..vname)
    	console(String("updateVoiceName: "..voice..":"..vname))
    --	------------------------------------------------------
    	for i,v in ipairs ((_G[ "tbl_keyassgn"..keyselct ]),1) do 	--[ fetchKeyTable ]--
    	local param = tbl_keyParam
    	param:setModulatorValue(v,false,false,false)
    	end
    	--
    	local ktblconcat =nil
    	ktblconcat = table.concat(_G["tbl_keyassgn"..keyselct]," ")
    	panel:getComponent("lcd_top2"):setPropertyString("uiLabelText",ktblconcat)
    	console(String("fetchKeyTable:"..ktblconcat))
    --	------------------------------------------------------
    	for i=1,21 do 												--[ fetchVoiceTable ]--
    	local param = tbl_voiceParam[ i ]
    	param:setModulatorValue((_G[ "tbl_voice"..vnmbr ])[ i ],false,false,false)
    	--
    	local vparam =_G["tbl_voice"..vnmbr][ i ]
    	table.insert(_G["tbl_voice"..vnmbr],vparam)
    	end
    	---
    	local vtblconcat =nil
    	vtblconcat = table.concat(_G["tbl_voice"..vnmbr]," ")
    	panel:getComponent("lcd_top3"):setPropertyString("uiLabelText",vtblconcat)
    	console(String("fetchVoiceTable:"..vtblconcat))
    --	------------------------------------------------------
    	panel:getComponent("lcd_top1"):setProperty("uiLabelText",	--[ displaypad ]--
    	"pad "..(tbl_padalpha[psub])..":".." kit:"..kitnmbr.." key:"..keyselct.." voice "..
    	(vnmbr-1)..":"..vname.." midi:"..tbl_initNoteNo[ vnmbr ],false)
    --	------------------------------------------------------
    	kbdmidi()
    -- -------------------------------------
    end
    Attachments:
    You must be logged in to view attached files.
    #83770

    human fly
    Participant
    • Topics: 123
    • Replies: 1051
    • Total: 1174
    • ★★★★

    Do you using some labelChanged callbak? So when you change something , callback is trigerred which is changing uiLabel wchich again triggers the callback.

    a-ha: this was good. not labelChanged, but valueChanged: all the modulators
    jump to position and change value when a button is clicked, and the method
    they trigger – which i completely forgot about , because it’s in another
    Folder – is triggering the rogue console prints.

    so i suppose i’m changing the wrong thing when i’m recalling values from
    the table. it should be a component property, so value change doesn’t
    fire the method.

    was able to re-order and reduce the script before ‘unpacking’ it.
    some things were happening twice. still full of things happening
    twice. but runs snappier now.

Viewing 20 posts - 1 through 20 (of 22 total)

You must be logged in to reply to this topic.

There is currently 0 users and 19 guests online
No users are currently active
Forum Statistics
Threads: 2,143, Posts: 15,125, Members: 11,885
Most users ever online was 5 on March 28, 2018 6:11 pm
Do NOT follow this link or you will be banned from the site!