views:

56

answers:

1

Here is the code:

- (IBAction) startRecognition:(id)sender {
    backgroundSoundLevel = [backgroundSoundChange stringValue];
    timer = [NSTimer scheduledTimerWithTimeInterval:0.25 target:self selector:@selector(timerFired:) userInfo:nil repeats:YES];
}

- (void)timerFired:(NSTimer*)theTimer
{   
    NSString *charlieSoundVolume = [charlieSoundLevel stringValue];
    if ([charlieSoundVolume isLessThan: backgroundSoundLevel]) {
        NSRunAlertPanel(@"", charlieSoundVolume, @"", @"", @"");
    }
}

So when you press the button "startRecognition" then it starts this timer loop "timer fired". BUT when the value charlieSoundVolume is less than backgroundSoundLevel, it freezes the app. When it's greater, it works fine. So there's something wrong with that part of the code. I'm not really sure what...

Background info: charlieSoundVolume is the current volume expressed in an NSString. backgroundSoundVolume is also expressed in an NSString. The charlieSoundVolume is the current volume and the backgroundSoundVolume is the preset volume set by the NSSlider backGroundSoundChange.

Any ideas??

Elijah

A: 

Here is the working code:

- (IBAction) startRecognition:(id)sender {
    timer = [NSTimer scheduledTimerWithTimeInterval:0.25 target:self selector:@selector(timerFired:) userInfo:nil repeats:YES];
}

- (void)timerFired:(NSTimer*)theTimer
{   
    backgroundSoundLevel = [backgroundSoundChange stringValue];
    NSString *charlieSoundVolume = [charlieSoundLevel stringValue];
    if ([charlieSoundVolume  isLessThan: backgroundSoundLevel]) {
        NSRunAlertPanel(@"", charlieSoundVolume, @"", @"", @"");
    }
}
Elijah W.
So `backgroundSoundLevel` is a string, but `charlieSoundLevel` is a control? You need to name your variables more clearly. (And stop storing data in controls! Your controller object should own one or both of these value objects directly.)
Peter Hosey
Yes. backgroundSoundLevel is the value that the NSSlider produces. charlieSoundLevel is the value of an NSTextField (which a quartz composer view changes with a patch, this quartz composer view file is a visualizer template that just gets the sound level). A little confusing, but the WHOLE app works now PERFECTLY! So, I'll look through it and make it more efficient. :D
Elijah W.
According to the code in your answer, `charlieSoundLevel` is not the value of an NSTextField, but a control (possibly a text field) itself.
Peter Hosey
ok yes that is correct
Elijah W.