Welcome to mirror list, hosted at ThFree Co, Russian Federation.

MUAdvancedAudioPreferencesViewController.m « Classes « Source - github.com/mumble-voip/mumble-iphoneos.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b53d8190417e737704fa8e8210b940c0e17ce780 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
// Copyright 2009-2011 The 'Mumble for iOS' Developers. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

#import "MUAdvancedAudioPreferencesViewController.h"
#import "MUTableViewHeaderLabel.h"
#import "MUApplicationDelegate.h"
#import "MUAudioQualityPreferencesViewController.h"
#import "MUAudioSidetonePreferencesViewController.h"
#import "MUColor.h"
#import "MUImage.h"

#import <MumbleKit/MKAudio.h>

@implementation MUAdvancedAudioPreferencesViewController

- (id) init {
    if ((self = [super initWithStyle:UITableViewStyleGrouped])) {
        self.contentSizeForViewInPopover = CGSizeMake(320, 480);
    }
    return self;
}

- (void) viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];

    self.title = NSLocalizedString(@"Advanced Audio", nil);
    self.tableView.backgroundView = [[[UIImageView alloc] initWithImage:[MUImage imageNamed:@"BackgroundTextureBlackGradient"]] autorelease];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.tableView.scrollEnabled = NO;

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(audioSubsystemRestarted:) name:MKAudioDidRestartNotification object:nil];
    
    [self.tableView reloadData];
}

- (void) viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
}

- (void) viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:YES];
    
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

#pragma mark - Table view data source

- (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
    return 3;
}

- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (section == 0) {
        return 1;
    } else if (section == 1) {
        return 2;
    } else if (section == 2) {
        return 2;
    }
    return 0;
}

- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"MUAdvancedAudioPreferencesCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease];
    }
    
    cell.detailTextLabel.text = nil;
    
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

    if ([indexPath section] == 0) {
        if ([indexPath row] == 0) {
            cell.textLabel.text = NSLocalizedString(@"Quality", nil);
            cell.detailTextLabel.textColor = [MUColor selectedTextColor];
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
            if ([[defaults stringForKey:@"AudioQualityKind"] isEqualToString:@"low"])
                cell.detailTextLabel.text = NSLocalizedString(@"Low", nil);
            else if ([[defaults stringForKey:@"AudioQualityKind"] isEqualToString:@"balanced"])
                cell.detailTextLabel.text = NSLocalizedString(@"Balanced", nil);
            else if ([[defaults stringForKey:@"AudioQualityKind"] isEqualToString:@"high"])
                cell.detailTextLabel.text = NSLocalizedString(@"High", nil);
            else
                cell.detailTextLabel.text = NSLocalizedString(@"Custom", nil);
            cell.selectionStyle = UITableViewCellSelectionStyleGray;
        }
    } else if ([indexPath section] == 1) {
        if ([indexPath row] == 0) {
            cell.textLabel.text = NSLocalizedString(@"Preprocessing", nil);
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            UISwitch *preprocSwitch = [[[UISwitch alloc] init] autorelease];
            preprocSwitch.onTintColor = [UIColor blackColor];
            preprocSwitch.on = [defaults boolForKey:@"AudioPreprocessor"];
            [preprocSwitch addTarget:self action:@selector(preprocessingChanged:) forControlEvents:UIControlEventValueChanged];
            cell.accessoryView = preprocSwitch;
        } else if ([indexPath row] == 1) {
            if ([defaults boolForKey:@"AudioPreprocessor"]) {
                cell.textLabel.text = NSLocalizedString(@"Echo Cancellation", nil);
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
                UISwitch *echoCancelSwitch = [[[UISwitch alloc] init] autorelease];
                echoCancelSwitch.onTintColor = [UIColor blackColor];
                echoCancelSwitch.on = [defaults boolForKey:@"AudioEchoCancel"];
                echoCancelSwitch.enabled = [[MKAudio sharedAudio] echoCancellationAvailable];
                if (!echoCancelSwitch.enabled) {
                    echoCancelSwitch.on = NO;
                }
                [echoCancelSwitch addTarget:self action:@selector(echoCancelChanged:) forControlEvents:UIControlEventValueChanged];
                cell.accessoryView = echoCancelSwitch;
            } else {
                cell.textLabel.text = NSLocalizedString(@"Mic Boost", nil);
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
                UISlider *slider = [[[UISlider alloc] init] autorelease];
                [slider setMaximumValue:2.0f];
                [slider setMinimumValue:0.0f];
                float boost = [defaults floatForKey:@"AudioMicBoost"];
                if (boost > 1.0f) {
                    [slider setMinimumTrackTintColor:[MUColor badPingColor]];
                } else {
                    [slider setMinimumTrackTintColor:[MUColor goodPingColor]];
                }
                [slider setValue:boost];
                [slider addTarget:self action:@selector(micBoostChanged:) forControlEvents:UIControlEventValueChanged];
                cell.accessoryView = slider;
            }
        }
    } else if ([indexPath section] == 2) {
        if ([indexPath row] == 0) {
            cell.textLabel.text = NSLocalizedString(@"Sidetone", nil);
            cell.detailTextLabel.textColor = [MUColor selectedTextColor];
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
            if ([defaults boolForKey:@"AudioSidetone"]) {
                cell.detailTextLabel.text = NSLocalizedString(@"On", nil);
            } else {
                cell.detailTextLabel.text = NSLocalizedString(@"Off", nil);
            }
            cell.selectionStyle = UITableViewCellSelectionStyleGray;
        } else if ([indexPath row] == 1) {
            cell.textLabel.text = NSLocalizedString(@"Speakerphone Mode", nil);
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            UISwitch *speakerPhoneSwitch = [[[UISwitch alloc] init] autorelease];
            speakerPhoneSwitch.onTintColor = [UIColor blackColor];
            speakerPhoneSwitch.on = [defaults boolForKey:@"AudioSpeakerPhoneMode"];
            speakerPhoneSwitch.enabled = YES;
            [speakerPhoneSwitch addTarget:self action:@selector(speakerPhoneModeChanged:) forControlEvents:UIControlEventValueChanged];
            cell.accessoryView = speakerPhoneSwitch;
        }
    }
    
    return cell;
}

- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    if (section == 0) { // Xmit
        return [MUTableViewHeaderLabel labelWithText:NSLocalizedString(@"Transmission Quality", nil)];
    } else if (section == 1) { // Audio Input
        return [MUTableViewHeaderLabel labelWithText:NSLocalizedString(@"Audio Input", nil)];
    } else if (section == 2) { // Audio Output
        return [MUTableViewHeaderLabel labelWithText:NSLocalizedString(@"Audio Output", nil)];
    } else {
        return nil;
    }
}

- (CGFloat) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    if (section == 0) {
        return [MUTableViewHeaderLabel defaultHeaderHeight];
    } else if (section == 1) {
        return [MUTableViewHeaderLabel defaultHeaderHeight];
    } else if (section == 2) {
        return [MUTableViewHeaderLabel defaultHeaderHeight];
    }
    return 0.0f;
}

- (UIView *) tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    if (section == 1) {
        if ([[NSUserDefaults standardUserDefaults] boolForKey:@"AudioPreprocessor"]) {
            if (![[MKAudio sharedAudio] echoCancellationAvailable]) {
                NSString *echoCancelNotAvail = NSLocalizedString(@"Echo Cancellation is not available when using the current audio peripheral.", nil);
                MUTableViewHeaderLabel *lbl = [MUTableViewHeaderLabel labelWithText:echoCancelNotAvail];
                lbl.font = [UIFont systemFontOfSize:16.0f];
                lbl.lineBreakMode = UILineBreakModeWordWrap;
                lbl.numberOfLines = 0;
                return lbl;
            }
        }
    }
    return nil;
}

- (CGFloat) tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    if (section == 1) {
        if ([[NSUserDefaults standardUserDefaults] boolForKey:@"AudioPreprocessor"]) {
            if (![[MKAudio sharedAudio] echoCancellationAvailable]) {
                return 44.0f;
            }
        }
    }
    return 0.0f;
}

#pragma mark - Table view delegate

- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if ([indexPath section] == 0 && [indexPath row] == 0) {
        MUAudioQualityPreferencesViewController *audioQual = [[MUAudioQualityPreferencesViewController alloc] init];
        [self.navigationController pushViewController:audioQual animated:YES];
        [audioQual release];
    } else if ([indexPath section] == 2 && [indexPath row] == 0) {
        MUAudioSidetonePreferencesViewController *sidetonePrefs = [[MUAudioSidetonePreferencesViewController alloc] init];
        [self.navigationController pushViewController:sidetonePrefs animated:YES];
        [sidetonePrefs release];
    }
}

#pragma mark - Actions

- (void) preprocessingChanged:(UISwitch *)sender {
    [[NSUserDefaults standardUserDefaults] setBool:sender.on forKey:@"AudioPreprocessor"];
    [self.tableView reloadSections:[NSIndexSet indexSetWithIndex:1] withRowAnimation:UITableViewRowAnimationNone];
}

- (void) echoCancelChanged:(UISwitch *)sender {
    [[NSUserDefaults standardUserDefaults] setBool:sender.on forKey:@"AudioEchoCancel"];
}

- (void) micBoostChanged:(UISlider *)sender {
    [[NSUserDefaults standardUserDefaults] setFloat:sender.value forKey:@"AudioMicBoost"];
    if (sender.value > 1.0f) {
        [sender setMinimumTrackTintColor:[MUColor badPingColor]];
    } else {
        [sender setMinimumTrackTintColor:[MUColor goodPingColor]];
    }
}

- (void) speakerPhoneModeChanged:(UISwitch *)sender {
    [[NSUserDefaults standardUserDefaults] setBool:sender.on forKey:@"AudioSpeakerPhoneMode"];
}

- (void) audioSubsystemRestarted:(NSNotification *)notification {
    if ([[NSUserDefaults standardUserDefaults] boolForKey:@"AudioPreprocessor"]) {
        [self.tableView reloadSections:[NSIndexSet indexSetWithIndex:1] withRowAnimation:UITableViewRowAnimationNone];
    }
}

@end