I want to add a channel to an array of channels if its level is above a threshold, this function is the delegate callback for providing the channel level.
This fucn is used constantly to provide level data, however On init i want to add the channels above the threshold to an array. However then i dont want it to add them again, just 1 instance of each channel that meets the criteria.
I wanted to use this code and check if the channel i receive data from is already in the channelArray, if it isnt, then add it and if it is then skip over it...However its not calling / working.
Can anyone help me with the approach to this? Issue is each channel calls this func every time its moved, so i need it to just run the code to add to array a single time.
- (void)cdcControlDidReceiveBusSend:(NSInteger)channel withValue:(float)value forBus:(NSInteger)bus onModule:(NSInteger)module {
NSNumber *recievingChannel = [NSNumber numberWithInteger:channel];
NSLog(@"RECIEVED SEND DATA FOR CHAN:%ld VALUE:%f FORBUS:%ld", (long)channel, value, (long)bus);
if (value != -80.000000) {
NSLog(@"CHANNEL:%ld FADER IS UP ATTEMPTING TO ADD TO FOCUS ARRAY", (long)channel);
for (NSNumber *arrayChannel in self.focusChannels) {
if (recievingChannel == arrayChannel) {
NSLog(@"ALREADY SAVED THIS CHANNEL...SKIPPING");
} else {
NSLog(@"ADDING CHANNEL %ld", (long)channel);
[self.focusChannels addObject:[NSNumber numberWithInteger:channel]]; // add the channel number to the array of channel numbers if the fader is up
NSLog(@"FOCUS ARRAY NOW CONTAINS %lu CHANNELS", (unsigned long)self.focusChannels.count);
}
}
} else {
NSLog(@"CHANNEL:%ld FADER IS DOWN NOT IN MIXFOCUS ARRAY", (long)channel);
}
}
You can not use ==
operator to compare values of NSNumber
. In order to do things right you ned to use comparator method, like isEqueal
if ([recievingChannel isEqual:arrayChannel]) {
//...
}
or compare values directly
if (recievingChannel.integerValue == arrayChannel.integerValue){
//...
}
Anyway, this task can be solved using -[NSArray containsObject:]
- (void)cdcControlDidReceiveBusSend:(NSInteger)channel withValue:(float)value forBus:(NSInteger)bus onModule:(NSInteger)module {
if (value != -80.000000) {
if ([self.focusChannels containsObject:@(channel)] == NO) {
[self.focusChannels addObject:@(channel)];
}
}
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments