
#import "OverAllController.h"
#import "PrefController.h"
#import "ResultInspector.h"
#import "SoundInspector.h"

@implementation OverAllController
- init;
{
	[super init];
	myNR = [NoteRepository instance];
	return self;
}
- awakeFromNib;
{
	[window makeKeyAndOrderFront:self];
	[nrFeld selectText:self];
	srandom(time(0));
    return self;
}
- nrFeldActed:sender;
{
// nur fuer Tests

	if(currentNote = [myNR noteByNr:[sender intValue]]){
		[self newNote:currentNote from:self];
	}
	[nrFeld selectText:self];
	return self;
}
- newNote:(Note *)value from:sender;
{
	id	*idp;
	
	if([(PrefController *)prefController mode]){	//Training
		[nameInspector displayNote:value];
		[soundInspector displayNote:value];
		if(value == currentNote){
			[resultController good:self];
		}else{
			[resultController noGood:self];
		}
	}else{	//info
		for(idp = &soundInspector;idp <= &tABInspector;idp++){
			if(*idp != sender){
				[*idp displayNote:value];
			}
		}
	}
	return self;
}
- clear:sender;
{
	id	*idp;
	
	for(idp = &keyInspector;idp <= &resultController;idp++){
		[*idp clear:self];
	}
	return self;
}
- (void)setEditable:(BOOL)yn;
{
	id	*idp;
	
	for(idp = &soundInspector;idp <= &tABInspector;idp++){
		[(NoteInspector *)*idp setEditable:yn];
	}
}
- next:sender;
{
#define offset 9
#define range 20
	[self clear:self];
	currentNote = [myNR noteByNr:1+offset+(range * (random() & 255)/255)];	
	if([prefController trainMode]){
		[nameInspector displayNote:currentNote];
	}else{
		[keyInspector displayNote:currentNote];
	}
	[resultController waiting:self];
	return self;
}
- (void)prefChanged;
{
	[self clear:self];
	[self setEditable:![(PrefController *)prefController mode]];
	if([(PrefController *)prefController mode]){
		if([prefController trainMode]==2){
			[(NoteInspector *)keyInspector setEditable:YES];
		}else{
			[(NoteInspector *)locationInspector setEditable:YES];
		}
	}
	[soundInspector setActive:[(PrefController *)prefController sound]];
}
@end
