//
//  SliderViewController.m
//  sonicZoom
//
//  Created by Robert Tubb on 01/02/2013.
//
//

#import "SliderViewController.h"
#import "testApp.h"

@interface SliderViewController ()

@end

@implementation SliderViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        [self populateParamNames];
        self.sliderArray = [[NSMutableArray alloc] init];
        
    }
    return self;
}

- (void)viewDidLoad
{
    int left = 22;
    int top = 3;
    const int height = 62;
    const int width = 337;
    
    [super viewDidLoad];
    
    for(int i=0;i<10;i++){
        
        if(i==5){
            top = 0;
            left = left*3 + width;
        }
        SliderController * sliderV	= [[SliderController alloc] initWithNibName:@"SliderController" bundle:nil delegate:self pID:i];
        
        [self.view addSubview:sliderV.view];
        
        sliderV.view.frame = CGRectMake(left,top,width,height);
        [sliderV setPID:i];
        NSLog(@"setting name to %@", self.paramNames[i]);
        [sliderV changeLabel:self.paramNames[i] ];
        [sliderV setParamValue:44];
        top += height;
        
        [self.sliderArray addObject:sliderV]; // not working
        
    }
    int i = [self.sliderArray count];
    NSLog(@"count: %d", i);
    
    [(SliderController *)[self.sliderArray objectAtIndex:5] setParamValue:13];
    
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)setAppRef:(id)theOFApp{
    self.theOFAppRef = theOFApp;
    
}

- (IBAction)show:(id)sender
{
    self.theOFAppRef = sender;
    self.view.hidden = NO;
}
- (IBAction)hide:(id)sender
{
    self.theOFAppRef = sender;
    self.view.hidden = YES;
}
- (void)dealloc {
    
    [super dealloc];
}
- (void)viewDidUnload {
    [super viewDidUnload];
}
- (void)slider:(int)which changedTo:(float)value{
    // call testApp
    ((testApp *)self.theOFAppRef)->sliderMoved(which,value);
}
- (void)setSlider:(int)which to:(float)value{
    NSLog(@"set slider to");
    [[self.sliderArray objectAtIndex:which] setParamValue:value];
}
- (void)populateParamNames{
    
    
    self.paramNames = [NSArray arrayWithObjects:
                       @"Transpose",@"1/4 note",@"1/6 note",@"1/7 note",@"1/8 note",
                       @"Waveform",@"Filter Type",@"Filter Cutoff",@"Envelope",@"FM amount",
                       nil];
    
}
@end
