
#import "SoundManager.h"
#import "Imports.h"

@implementation SoundManager

- init
{
	CurrentSoundViewUsingDSP=NULL;
	CurrentSoundUsingDSP=NULL;
	Playing=NO;
	Recording=NO;
	return self;
}


- Stop:sender
{
	if (Playing)
		{
		[CurrentSoundViewUsingDSP stop:self];
		}
	else if (Recording)
		{
		[NewSound stop:self];
		}
	CurrentSoundViewUsingDSP=NULL;
	CurrentSoundUsingDSP=NULL;
	Playing=NO;
	Recording=NO;
	return self;
}


- Play:sender
{
	CurrentSoundViewUsingDSP=[TheFileController CurrentSoundView:self];
	if (CurrentSoundViewUsingDSP!=NULL) 
		{
		[CurrentSoundViewUsingDSP setDelegate:self];
		[CurrentSoundViewUsingDSP play:self];
		Playing=YES;
		}
	return self;
}

- Record: (int) SoundRate: (int) channels: (int) NumberOfSeconds: sender
{
		NewSound=[[Sound alloc] init];
		[NewSound setDelegate:self];
		[TheConsoleManager SetMeterTo: NewSound];
		[NewSound record:self];
		Recording=YES;
		return self;

}

- CurrentSoundUsingDSP:sender
{
	Recording=YES;
	return self;
}

- (BOOL) IsPlaying
{
	return Playing;
}

- (BOOL) IsRecording
{
	return Recording;
}

- didPlay:sender
{
	[TheConsoleManager TurnOffPlay];
	Playing=NO;
	return self;
}

- didRecord:sender
{
	[TheConsoleManager TurnOffRecord];
	[TheFileController NewRecordedSound: NewSound];
	Recording=NO;
	return self;
}

- selectionChanged:sender
{
	[TheEditController ChangeSelection:self];
	return self;
}

- willPlay:sender
{
	[TheConsoleManager SetMeterTo: [[ TheFileController CurrentSoundView:self ] 
				soundBeingProcessed]];
	return self;
}


@end
