// // MPT_MLRController.m // // Created by Andrew Salamon on 9/25/06. // Copyright 2006 __MyCompanyName__. All rights reserved. // #import "MPT_MLRController.h" #import @interface MPT_MLRController(PrivateMethods) - (inputAUVector)inputsFromArray:(NSArray *)array; @end // typedef std::vector< std::pair< std::string, unsigned int > > inputAUVector; @implementation MPT_MLRController - (id)init { if( self = [super init] ) { NSBundle *myBundle = [NSBundle bundleForClass:[self class]]; NSString *BHATpath = [myBundle objectForInfoDictionaryKey:@"BHATWeights"]; NSString *tablesDir = [[myBundle resourcePath] stringByAppendingPathComponent:BHATpath]; std::string dir( ([tablesDir length]?[tablesDir UTF8String]:"") ); NSArray *inputArray = [myBundle objectForInfoDictionaryKey:@"MLR_AUs"]; inputAUVector inputs = [self inputsFromArray:inputArray]; mlr = new mp_MLR( dir, inputs ); } return self; } - (void)dealloc { delete mlr; [super dealloc]; } - (NSString *)pluginID { NSString *ident = [super pluginID]; if( [ident length] > 0 ) return ident; return @"edu.ucsd.mplab.plugins.MLR.1+2+4"; } - (NSString *)localizedName { return NSLocalizedStringWithDefaultValue(@"MLR Plugin Name", nil, [NSBundle bundleForClass:[self class]], @"MLR: 1+2+4", @""); } - (NSString *)internalName { return @"1+2+4"; } - (NSString *)step { return MPT_PluginStep_Frequencies; } - (BOOL)loadLabels { labels = [[NSArray alloc] initWithObjects:[self localizedName], nil]; return YES; } - (void)setView:(MPT_AUView *)newView forLabel:(NSString *)label { [super setView:newView forLabel:label]; [newView resetDynamicRange]; [newView setDefaultMin:0.0]; [newView setDefaultMax:1.0]; } - (double)processFrequencyResults:(std::map< std::string, mp_AUResults > &)AUResults { double res = mlr->MLR( AUResults ); return res; } - (inputAUVector)inputsFromArray:(NSArray *)array { unsigned int max = [array count]; inputAUVector inputs; for( unsigned int index = 0; index < max; index += 2 ) { std::string cat( [[array objectAtIndex:index] UTF8String] ); unsigned int auIndex = [[array objectAtIndex:index+1] intValue]; inputs.push_back( std::pair< std::string, unsigned int >( cat, auIndex ) ); } return inputs; } @end