/*
 *  RocksAppController.mm
 *  fmod_rocks2010
 *
 *	Music and Code by Peter "pdx" Drescher.
 *  Copyright 2010 twittering machine. All rights reserved.
 *
 *	Controls for Next Mix and track checkboxes
 *
 */

#import "RocksController.h"
#import "LevelBGview.h"
#include "FMODaudio.h"

FMODaudio fmodAudio;

@implementation RocksController

- (id)init
{
	[super init];
	fmodAudio.init();
	levelNumber = 1;
    return self;
}

-(void)awakeFromNib
{
	[self setRadioButtons];	
}

- (IBAction)nextMixButton:(id)sender;
{
	levelNumber++;
	if (levelNumber > 15) {levelNumber = 1;}
	NSString *levelStr = [NSString stringWithFormat:@"Level %d", levelNumber];
	[levelLabel setStringValue:levelStr];
	[levelBGview setLevelBG:levelNumber];
	fmodAudio.setLevelMix(levelNumber);
	[self setRadioButtons];	
}

- (IBAction)bassCheck:(id)sender;
{
	if ([bassButton state] == NSOnState) {
		fmodAudio.unmuteChannel(BASS);
	} else {
		fmodAudio.muteChannel(BASS);
	}
}

- (IBAction)drumsCheck:(id)sender;
{
	if ([drumsButton state] == NSOnState) {
		fmodAudio.unmuteChannel(DRUMS);
	} else {
		fmodAudio.muteChannel(DRUMS);
	}	
}

- (IBAction)sweepCheck:(id)sender;
{
	if ([sweepButton state] == NSOnState) {
		fmodAudio.unmuteChannel(SWEEP);
	} else {
		fmodAudio.muteChannel(SWEEP);
	}
}

- (IBAction)ostinato1Check:(id)sender;
{
	if ([ostinato1Button state] == NSOnState) {
		fmodAudio.unmuteChannel(OST1);
	} else {
		fmodAudio.muteChannel(OST1);
	}
}

- (IBAction)ostinato2Check:(id)sender;
{
	if ([ostinato2Button state] == NSOnState) {
		fmodAudio.unmuteChannel(OST2);
	} else {
		fmodAudio.muteChannel(OST2);
	}
}

- (IBAction)ostinato3Check:(id)sender;
{
	if ([ostinato3Button state] == NSOnState) {
		fmodAudio.unmuteChannel(OST3);
	} else {
		fmodAudio.muteChannel(OST3);
	}
}

- (IBAction)gtrCheck:(id)sender;
{
	if ([gtrButton state] == NSOnState) {
		fmodAudio.unmuteChannel(GTR);
	} else {
		fmodAudio.muteChannel(GTR);
	}
}

- (IBAction)dingCheck:(id)sender;
{
	if ([dingButton state] == NSOnState) {
		fmodAudio.unmuteChannel(DING);
	} else {
		fmodAudio.muteChannel(DING);
	}
}

-(void)setRadioButtons;
{
	//set the buttons on/off state to match the tracks playing for that level
	switch (levelNumber)
	{
		case 1: //bass
		{
			[bassButton		 setState:NSOnState];
			[drumsButton	 setState:NSOffState];
			[sweepButton	 setState:NSOffState];
			[ostinato1Button setState:NSOffState];
			[ostinato2Button setState:NSOffState];
			[ostinato3Button setState:NSOffState];
			[gtrButton		 setState:NSOffState];
			[dingButton		 setState:NSOffState];
			break;
		}
		case 2: //bass, drums
		{
			[bassButton		 setState:NSOnState];
			[drumsButton	 setState:NSOnState];
			[sweepButton	 setState:NSOffState];
			[ostinato1Button setState:NSOffState];
			[ostinato2Button setState:NSOffState];
			[ostinato3Button setState:NSOffState];
			[gtrButton		 setState:NSOffState];
			[dingButton		 setState:NSOffState];
			break;
		}
		case 3: //bass, drums, sweep, gtr
		{
			[bassButton		 setState:NSOnState];
			[drumsButton	 setState:NSOnState];
			[sweepButton	 setState:NSOnState];
			[ostinato1Button setState:NSOffState];
			[ostinato2Button setState:NSOffState];
			[ostinato3Button setState:NSOffState];
			[gtrButton		 setState:NSOnState];
			[dingButton		 setState:NSOffState];
			break;
		}
		case 4: //bass, drums, sweep, ost2
		{
			[bassButton		 setState:NSOnState];
			[drumsButton	 setState:NSOnState];
			[sweepButton	 setState:NSOnState];
			[ostinato1Button setState:NSOffState];
			[ostinato2Button setState:NSOnState];
			[ostinato3Button setState:NSOffState];
			[gtrButton		 setState:NSOffState];
			[dingButton		 setState:NSOffState];
			break;
		}
		case 5: //bass, sweep, ost1, ost2, ding
		{
			[bassButton		 setState:NSOnState];
			[drumsButton	 setState:NSOffState];
			[sweepButton	 setState:NSOnState];
			[ostinato1Button setState:NSOnState];
			[ostinato2Button setState:NSOnState];
			[ostinato3Button setState:NSOffState];
			[gtrButton		 setState:NSOffState];
			[dingButton		 setState:NSOnState];
			break;
		}
		case 6: //bass, sweep, ost1, ost2, ost3, ding
		{
			[bassButton		 setState:NSOnState];
			[drumsButton	 setState:NSOffState];
			[sweepButton	 setState:NSOnState];
			[ostinato1Button setState:NSOnState];
			[ostinato2Button setState:NSOnState];
			[ostinato3Button setState:NSOnState];
			[gtrButton		 setState:NSOffState];
			[dingButton		 setState:NSOnState];
			break;
		}
		case 7: //drums, ost1, ost2, ost3, ding
		{
			[bassButton		 setState:NSOffState];
			[drumsButton	 setState:NSOnState];
			[sweepButton	 setState:NSOffState];
			[ostinato1Button setState:NSOnState];
			[ostinato2Button setState:NSOnState];
			[ostinato3Button setState:NSOnState];
			[gtrButton		 setState:NSOffState];
			[dingButton		 setState:NSOnState];
			break;
		}
		case 8: //drums, ost1, ost2, ost3
		{
			[bassButton		 setState:NSOffState];
			[drumsButton	 setState:NSOnState];
			[sweepButton	 setState:NSOffState];
			[ostinato1Button setState:NSOnState];
			[ostinato2Button setState:NSOnState];
			[ostinato3Button setState:NSOnState];
			[gtrButton		 setState:NSOffState];
			[dingButton		 setState:NSOffState];
			break;
		}
		case 9: //drums, sweep, ost3, ding
		{
			[bassButton		 setState:NSOffState];
			[drumsButton	 setState:NSOnState];
			[sweepButton	 setState:NSOnState];
			[ostinato1Button setState:NSOffState];
			[ostinato2Button setState:NSOffState];
			[ostinato3Button setState:NSOnState];
			[gtrButton		 setState:NSOffState];
			[dingButton		 setState:NSOnState];
			break;
		}
		case 10: //bass, drums, ost3, ding
		{
			[bassButton		 setState:NSOnState];
			[drumsButton	 setState:NSOnState];
			[sweepButton	 setState:NSOffState];
			[ostinato1Button setState:NSOffState];
			[ostinato2Button setState:NSOffState];
			[ostinato3Button setState:NSOnState];
			[gtrButton		 setState:NSOffState];
			[dingButton		 setState:NSOnState];
			break;
		}
		case 11: //bass, drums, ost1, ost3, 
		{
			[bassButton		 setState:NSOnState];
			[drumsButton	 setState:NSOnState];
			[sweepButton	 setState:NSOffState];
			[ostinato1Button setState:NSOnState];
			[ostinato2Button setState:NSOffState];
			[ostinato3Button setState:NSOnState];
			[gtrButton		 setState:NSOffState];
			[dingButton		 setState:NSOffState];
			break;
		}
		case 12: //bass, drums, gtr, ding
		{
			[bassButton		 setState:NSOnState];
			[drumsButton	 setState:NSOnState];
			[sweepButton	 setState:NSOffState];
			[ostinato1Button setState:NSOffState];
			[ostinato2Button setState:NSOffState];
			[ostinato3Button setState:NSOffState];
			[gtrButton		 setState:NSOnState];
			[dingButton		 setState:NSOnState];
			break;
		}
		case 13: //bass, drums, sweep, gtr, ding
		{
			[bassButton		 setState:NSOnState];
			[drumsButton	 setState:NSOnState];
			[sweepButton	 setState:NSOnState];
			[ostinato1Button setState:NSOffState];
			[ostinato2Button setState:NSOffState];
			[ostinato3Button setState:NSOffState];
			[gtrButton		 setState:NSOnState];
			[dingButton		 setState:NSOnState];
			break;
		}
		case 14: //bass, sweep, gtr
		{
			[bassButton		 setState:NSOnState];
			[drumsButton	 setState:NSOffState];
			[sweepButton	 setState:NSOnState];
			[ostinato1Button setState:NSOffState];
			[ostinato2Button setState:NSOffState];
			[ostinato3Button setState:NSOffState];
			[gtrButton		 setState:NSOnState];
			[dingButton		 setState:NSOffState];
			break;
		}
		case 15: //bass, sweep
		{
			[bassButton		 setState:NSOnState];
			[drumsButton	 setState:NSOffState];
			[sweepButton	 setState:NSOnState];
			[ostinato1Button setState:NSOffState];
			[ostinato2Button setState:NSOffState];
			[ostinato3Button setState:NSOffState];
			[gtrButton		 setState:NSOffState];
			[dingButton		 setState:NSOffState];
			break;
		}
		default:	//all off (should never happen)
		{
			[bassButton		 setState:NSOffState];
			[drumsButton	 setState:NSOffState];
			[sweepButton	 setState:NSOffState];
			[ostinato1Button setState:NSOffState];
			[ostinato2Button setState:NSOffState];
			[ostinato3Button setState:NSOffState];
			[gtrButton		 setState:NSOffState];
			[dingButton		 setState:NSOffState];
			break;
		}
	}	
}

@end
