objective c - Grand Central Dispatch Concurrency -
here's scenario....
i have core midi app detects note on , note off messages working nicely.
i have have midisend methods send messages controller illuminate leds - working fine.
what want on note off message have led blink on , off. code:
[midilistener performselectoronmainthread:@selector(starttimer:) withobject:midimsgparts waituntildone:yes]; -(void)starttimer:(nsdictionary *)dict { ledintervalcount = 0; ledintervaltimer = [nstimer scheduledtimerwithtimeinterval:0.3 target:self selector:@selector(ledintervalloop:) userinfo:dict repeats:yes]; } -(void)ledintervalloop:(nstimer *)inboundtimer{ nsdictionary *userinfo = [nsdictionary dictionarywithdictionary:[inboundtimer userinfo]]; nslog(@"%@", userinfo); uint32 oncommand = [[userinfo objectforkey:@"noteon"] intvalue]; //uint32 offcommand = [[userinfo objectforkey:@"noteoff"] intvalue]; uint32 thenote = [[userinfo objectforkey:@"note"] intvalue]; ledintervalcount++; if (ledintervalcount > 3) { [ledintervaltimer invalidate]; ledintervaltimer = nil; } else { if(ledintervalcount %2){ [self sendnoteonilluminate:oncommand midinote:thenote]; }else{ [self sendnoteoncommand:oncommand midinote:thenote]; } } }
so i'm using nstimer
alternate led on/off commands. works fine when press single button not when press multiple ones @ same time. seems picks on lastly phone call starttimer method.
this think need implement dispatch queue gcd. each nstimer
execute in total without beingness interrupted method calls follow.
am correct? gcd allow me have nstimer
run concurrently?
gcd new concept me guidance on how might implement help. i've read through of reference guides need see illustration code in context of scenario. guess i'm asking here is, part of code go in block?
ah invalidate timers anyway... after 3 tries. -- need x counters x timers, have 1 counter x timer
instead of 1 long ledintervalcount, have nsmutablearray ledintervalcounts! 1 per timer
then in userinfo timer, provide index counter used
objective-c nstimer grand-central-dispatch
No comments:
Post a Comment