ok i'll use NSTimer instead of performSelector:withObject:afterDelay,
it should be easier to track this way.  however, i'm still having an
issue with executing logic for the callback method:

so i set the timer to fire ever 0.15 seconds with this:

currentVolume =+ targetVolume / (fadeDuration / 0.15);

this makes sense to me but it doesn't work.

i see in your example you have callback which you said is used for
both fading in and fading out

float vol = [fi level1] + ([fi delta] * ( t / [fi time]));

in comparing the two, i believe i'm missing the entire end of the
logic: * ( t / [fi time])), but i can't really figure out what [fi
time] is...

ughhh...




On Wed, Jan 6, 2010 at 10:38 PM, Graham Cox <[email protected]> wrote:
>
> On 07/01/2010, at 2:23 PM, Chunk 1978 wrote:
>
>> unfortunately i'm developing for iPhone OS (which i should have stated
>> earlier) so NSAnimation doesn't seem to be an option :-/
>
>
> So just use NSTimer, within or without a wrapper object of your own devise.
>
> Here's the basics of the code I used, which implements a generic fade method. 
> This is called for a number of different tasks, such as fading in, fading out 
> and ducking the track. Warning: this is an old project, and I think I would 
> do things slightly differently now, but the basic principle of using a 
> repeating timer remains the way to go, IMO.
>
>
> - (void)                fadeFromLevel:(float) l1 toLevel:(float) l2 
> inTime:(NSTimeInterval) time
> {
>        // performs a linear fade from l1 to l2 over the time interval <time>.
>
>        if ( _fader == nil )
>        {
>                DJFadeInfo* fi = [[DJFadeInfo alloc] initWithLevel1:l1 
> level2:l2 time:time];
>
>                _fader = [NSTimer scheduledTimerWithTimeInterval:1.0/30.0
>                                                                        
> target:self
>                                                                        
> selector:@selector(fadeCallback:)
>                                                                        
> userInfo:fi
>                                                                        
> repeats:YES];
>                _fadeStartTime = [[NSDate date] retain];
>        }
> }
>
>
> - (void)                fadeCallback:(NSTimer*) timer
> {
>        //NSLog(@"fade target = %@", [self name]);
>
>        DJFadeInfo*     fi = [timer userInfo];
>        NSTimeInterval  t = [[NSDate date] 
> timeIntervalSinceDate:_fadeStartTime];
>
>        float vol = [fi level1] + ([fi delta] * ( t / [fi time]));
>
>        if ( t > [fi time])
>        {
>                [_fader invalidate];
>                _fader = nil;
>                [_fadeStartTime release];
>                _fadeStartTime = nil;
>
>                [self setMainLevel:[fi level2]];
>                [fi release];
>        }
>        else
>        {
>                [self setMainLevel:vol];
>        }
> }
>
>
> --Graham
>
>
>
_______________________________________________

Cocoa-dev mailing list ([email protected])

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to