#import "Finch-RevolverSound.h"
#import "Finch-Sound.h"

@implementation FinchRevolverSound

- (id) initWithFile: (NSString*) file rounds: (int) max
{
    self = [super init];
    sounds = [[NSMutableArray alloc] init];
    for (int i=0; i<max; i++)
    {
        FinchSound *const sample = [[FinchSound alloc] initWithFile:file];
        if (!sample)
            return nil;
        [sounds addObject:sample];
        //[sample release]; ARC dumb
    }
    return self;
}

- (void) dealloc
{
    //[sounds release]; ARC dumb
    //[super dealloc]; ARC dumb
}

- (void) play
{
    ((__bridge FinchSound *)[sounds objectAtIndex:current])->play();
    current = (current + 1) % [sounds count];
}

- (void) stop
{
    [sounds objectAtIndex:current]->stop();
}

- (void) setGain: (float) val
{
    for (FinchSound *sound in sounds)
        [sound setGain:val];
}

- (float) gain
{
    return [[sounds lastObject] gain];
}

@end
