//
//  ChannelConfigViewController.m
//  iPhly
//
//  Created by Ari Krupnik on 5/10/10.
//  Copyright 2010 lib.aero. All rights reserved.
//

#import "ChannelConfigViewController.h"
#import "NSMutableDictionary+ModelConfig.h"
#import "ModelProcessor.h"


@implementation ChannelConfigViewController


@synthesize reverser;
@synthesize trimmer;
@synthesize trimValueLabel;
@synthesize atvSlider;
@synthesize atvValueLabel;

@synthesize processor;
@synthesize channel;


- (id) initWithProcessor: (ModelProcessor *) pr andChannel: (ModelProcessorChannel *) ch {
	if (self = [super initWithNibName:nil bundle:nil]) {
		[self setProcessor: pr];
		[self setChannel: ch];
		[self setTitle: [channel name]];
	}
	return self;
}

/*
- (id) initWithProcessor: (ModelProcessor *) pr andChannel: (SEL) sel {
	if (self = [super initWithNibName:nil bundle:nil]) {
		[self setProcessor: pr];
		[self setChannel: [pr performSelector:sel]];
		[self setTitle: [channel name]];
	}
	return self;
}
 */

/*
 // The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
        // Custom initialization
    }
    return self;
}
*/


// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
	[[self reverser] setSelectedSegmentIndex: [[self channel] reversing]];
	[[self trimmer] setValue: [[self channel] trim]];
	[[self trimValueLabel] setText: [NSString stringWithFormat:@"%3.2f", [[self channel] trim]]];
	[[self atvSlider] setValue: [[self channel] rate]];
	[[self atvValueLabel] setText: [NSString stringWithFormat:@"%3.2f", [[self channel] rate]]];
}

- (void) setTrim: (UISlider *) target {
	[[self trimValueLabel] setText: [NSString stringWithFormat:@"%3.2f", [target value]]];
	[[self channel] setTrim: [target value]];
}

- (void) setAtv: (UISlider *) target {
	[[self atvValueLabel] setText: [NSString stringWithFormat:@"%3.2f", [target value]]];
	[[self channel] setRate: [target value]];
}

- (void) reverserClick: (UISegmentedControl *) target {
	[[self channel] setReversing: [target selectedSegmentIndex]];}

/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/

- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}


- (void)dealloc {
	[processor release];
	[channel release];
	
	[reverser release];
	[trimmer release];
	[trimValueLabel release];
	[atvSlider release];
	[atvValueLabel release];
	
    [super dealloc];
}


@end
