File: MyUserPrefsController.m

package info (click to toggle)
lynkeos.app 1.2-6
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 3,924 kB
  • sloc: objc: 7,122; ansic: 695; sh: 372; makefile: 59
file content (356 lines) | stat: -rw-r--r-- 12,012 bytes parent folder | download | duplicates (6)
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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
// 
//  Lynkeos
//  $Id: MyUserPrefsController.m,v 1.5 2005/02/01 22:55:52 j-etienne Exp $
//
//  Created by Jean-Etienne LAMIAUD on Sun Feb 8 2004.
//  Copyright (c) 2003-2005. Jean-Etienne LAMIAUD
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
//

#import "MyUserPrefsController.h"

static MyUserPrefsController *instancePointer = nil;

@interface MyUserPrefsController(Private)

- (void) getNumericPref :(double*)pref 
                  forKey:(NSString*)key
                minValue:(double)minv 
                maxValue:(double)maxv ;
- (void)initPrefsValue;
- (void) readPrefs ;
- (void) savePrefs ;
- (void) updatePanel ;
@end

@implementation MyUserPrefsController(Private)

- (void) getNumericPref :(double*)pref 
                  forKey:(NSString*)key
                minValue:(double)minv 
                maxValue:(double)maxv
{
#ifdef GNUSTEP
   double v = [_user floatForKey:key];

   if ( v < minv )
     v = minv;
   else if ( v > maxv )
     v = maxv;
   *pref = v;
#else
   NSString* stringValue = [_user stringForKey:key];
   double v;

   if ( stringValue != nil )
   {
      v = [stringValue doubleValue];
      if ( v < minv )
         v = minv;
      else if ( v > maxv )
         v = maxv;
      *pref = v;
   }
#endif
}

- (void)initPrefsValue
{
   // Set the factory defaults value
   _adjustFFTSizes = YES;
   _alignFrequencyCutoff = 0.41;
   _alignThreshold = 0.125;
   _alignImageUpdating = YES;
   _alignMultiProc = ListThreadsOptimizations;
   _analysisLowerCutoff = 0.125;
   _analysisUpperCutoff = 0.7;
   _analysisImageUpdating = NO;
   _analysisMultiProc = ListThreadsOptimizations;
   _stackImageUpdating = NO;
   _stackMultiProc = YES;
   _processMultiProc = YES;
}

- (void) readPrefs 
{
   u_short opt;

   // Set all values to their factory defaults
   [self initPrefsValue];

   // Update with database value, if any
   if ( [_user objectForKey:K_PREF_ADJUST_FFT_SIZES] != nil ){
      _adjustFFTSizes = [_user boolForKey:K_PREF_ADJUST_FFT_SIZES];
   }
   [self getNumericPref:&_alignFrequencyCutoff 
                 forKey:K_PREF_ALIGN_FREQUENCY_CUTOFF
               minValue:0.0 maxValue:0.71];
   [self getNumericPref:&_alignThreshold 
                 forKey:K_PREF_ALIGN_PRECISION_THRESHOLD
               minValue:0.0 maxValue:1.0];
   if ( [_user objectForKey:K_PREF_ALIGN_IMAGE_UPDATING] != nil ){
      _alignImageUpdating = [_user boolForKey:K_PREF_ALIGN_IMAGE_UPDATING];
   }
   if ( [_user objectForKey:K_PREF_ALIGN_MULTIPROC] != nil &&
        (opt = [_user integerForKey:K_PREF_ALIGN_MULTIPROC]) 
        <= ListThreadsOptimizations ){
     _alignMultiProc = opt;
   }
   [self getNumericPref:&_analysisLowerCutoff 
                 forKey:K_PREF_ANALYSIS_LOWER_CUTOFF
               minValue:0.0 maxValue:0.71];
   [self getNumericPref:&_analysisUpperCutoff 
                 forKey:K_PREF_ANALYSIS_UPPER_CUTOFF
               minValue:0.0 maxValue:0.71];
   if ( [_user objectForKey:K_PREF_ANALYSIS_IMAGE_UPDATING] != nil ){
      _analysisImageUpdating = [_user boolForKey:K_PREF_ANALYSIS_IMAGE_UPDATING];
   }
   if ( [_user objectForKey:K_PREF_ANALYSIS_MULTIPROC] != nil &&
        (opt = [_user integerForKey:K_PREF_ANALYSIS_MULTIPROC]) 
        <= ListThreadsOptimizations ){
      _analysisMultiProc = opt;
   }
   if ( [_user objectForKey:K_PREF_STACK_IMAGE_UPDATING] != nil ){
      _stackImageUpdating = [_user boolForKey:K_PREF_STACK_IMAGE_UPDATING];
   }
   if ( [_user objectForKey:K_PREF_STACK_MULTIPROC] != nil ){
     _stackMultiProc = [_user boolForKey:K_PREF_STACK_MULTIPROC];
   }
   if ( [_user objectForKey:K_PREF_PROCESS_MULTIPROC] != nil ){
     _processMultiProc = [_user boolForKey:K_PREF_PROCESS_MULTIPROC];
   }
}

- (void) savePrefs 
{
   [_user setBool:_adjustFFTSizes forKey:K_PREF_ADJUST_FFT_SIZES];
   [_user setFloat:_alignFrequencyCutoff forKey:K_PREF_ALIGN_FREQUENCY_CUTOFF];
   [_user setFloat:_alignThreshold forKey:K_PREF_ALIGN_PRECISION_THRESHOLD];
   [_user setBool:_alignImageUpdating forKey:K_PREF_ALIGN_IMAGE_UPDATING];
   [_user setInteger:_alignMultiProc forKey:K_PREF_ALIGN_MULTIPROC];
   [_user setFloat:_analysisLowerCutoff forKey:K_PREF_ANALYSIS_LOWER_CUTOFF];
   [_user setFloat:_analysisUpperCutoff forKey:K_PREF_ANALYSIS_UPPER_CUTOFF];
   [_user setBool:_analysisImageUpdating forKey:K_PREF_ANALYSIS_IMAGE_UPDATING];
   [_user setInteger:_analysisMultiProc forKey:K_PREF_ANALYSIS_MULTIPROC];
   [_user setBool:_stackImageUpdating forKey:K_PREF_STACK_IMAGE_UPDATING];
   [_user setBool:_stackMultiProc forKey:K_PREF_STACK_MULTIPROC];
   [_user setBool:_processMultiProc forKey:K_PREF_PROCESS_MULTIPROC];
}

- (void) updatePanel
{
   [_adjustFFTSizesButton setState: (_adjustFFTSizes ? NSOnState : NSOffState)];
   [_alignFrequencyCutoffSlider setDoubleValue: _alignFrequencyCutoff*10.0];
   [_alignFrequencyCutoffText setDoubleValue: _alignFrequencyCutoff];
   [_alignThresholdSlider setDoubleValue: _alignThreshold*100.0];
   [_alignThresholdText setDoubleValue: _alignThreshold*100.0];
   [_alignImageUpdatingButton setState: 
      (_alignImageUpdating ? NSOnState : NSOffState)];
   [_alignMultiProcPopup selectItemAtIndex: _alignMultiProc];
   [_analysisLowerCutoffSlider setDoubleValue: _analysisLowerCutoff*10.0];
   [_analysisLowerCutoffText setDoubleValue: _analysisLowerCutoff];
   [_analysisUpperCutoffSlider setDoubleValue: _analysisUpperCutoff*10.0];
   [_analysisUpperCutoffText setDoubleValue: _analysisUpperCutoff];
   [_analysisImageUpdatingButton setState: 
      (_analysisImageUpdating ? NSOnState : NSOffState)];
   [_analysisMultiProcPopup selectItemAtIndex: _analysisMultiProc];
   [_stackImageUpdatingButton setState: 
      (_stackImageUpdating ? NSOnState : NSOffState)];
   [_stackMultiProcPopup selectItemAtIndex: (_stackMultiProc ? 1 : 0)];
   [_processMultiProcPopup selectItemAtIndex: (_processMultiProc ? 1 : 0)];
}

@end

@implementation MyUserPrefsController

- (id) init
{
   NSAssert( instancePointer == nil, 
             @"Creation of more than 1 MyUserPrefsController object" );

   self = [super init];

   _user = [NSUserDefaults standardUserDefaults];

   // Force preferences to have a consistent value
   [self readPrefs];
   [self savePrefs];
   instancePointer = self;

   return( self );
}

+ (MyUserPrefsController*) getUserPref { return instancePointer; }

// The accessors read the value in NSUserDefaults, because our attributes could
// be transient values while the user is interacting with the window
+ (bool) adjustFFTSizes { return [instancePointer->_user boolForKey:
                                                     K_PREF_ADJUST_FFT_SIZES]; }
+ (double) alignFrequencyCutoff { return [instancePointer->_user floatForKey:
                                               K_PREF_ALIGN_FREQUENCY_CUTOFF]; }
+ (double) alignThreshold { return [instancePointer->_user floatForKey:
                                            K_PREF_ALIGN_PRECISION_THRESHOLD]; }
+ (bool) alignImageUpdating { return [instancePointer->_user boolForKey:
                                                  K_PREF_ALIGN_IMAGE_UPDATING]; }
+ (ParalelOptimization_t) alignMultiProc { return [instancePointer->_user 
                                       integerForKey: K_PREF_ALIGN_MULTIPROC]; }
+ (double) analysisLowerCutoff { return [instancePointer->_user floatForKey:
                                                K_PREF_ANALYSIS_LOWER_CUTOFF]; }
+ (double) analysisUpperCutoff { return [instancePointer->_user floatForKey:
                                                K_PREF_ANALYSIS_UPPER_CUTOFF]; }
+ (bool) analysisImageUpdating { return [instancePointer->_user boolForKey:
                                              K_PREF_ANALYSIS_IMAGE_UPDATING]; }
+ (ParalelOptimization_t) analysisMultiProc {  return [instancePointer->_user 
                                     integerForKey:K_PREF_ANALYSIS_MULTIPROC]; }
+ (bool) stackImageUpdating { return [instancePointer->_user boolForKey:
                                                 K_PREF_STACK_IMAGE_UPDATING]; }
+ (bool) stackMultiProc { return [instancePointer->_user boolForKey:
                                                      K_PREF_STACK_MULTIPROC]; }
+ (bool) processMultiProc { return [instancePointer->_user boolForKey:
                                                    K_PREF_PROCESS_MULTIPROC]; }

- (IBAction)changeAdjustFFTSizes:(id)sender
{
   _adjustFFTSizes = ([sender state] == NSOnState);
}

- (IBAction)changeEndProcessingSound:(id)sender
{
}

- (IBAction)changeAlignFrequencyCutoff:(id)sender
{
   _alignFrequencyCutoff = [sender doubleValue];
   
   if ( sender == _alignFrequencyCutoffSlider )
   {
      _alignFrequencyCutoff /= 10.0;
      [_alignFrequencyCutoffText setDoubleValue: _alignFrequencyCutoff];
   }
   
   else
      [_alignFrequencyCutoffSlider setDoubleValue: _alignFrequencyCutoff*10.0];
}

- (IBAction)changeAlignThreshold:(id)sender
{
   _alignThreshold = [sender doubleValue]/100.0;
   
   if ( sender != _alignThresholdSlider )
      [_alignThresholdSlider setDoubleValue: _alignThreshold*100.0];
   
   if ( sender != _alignThresholdText )
      [_alignThresholdText setDoubleValue: _alignThreshold*100.0];
}

- (IBAction)changeAlignImageUpdating:(id)sender
{
   _alignImageUpdating = ([sender state] == NSOnState);
}

- (IBAction)changeAlignMultiProc:(id)sender
{
   _alignMultiProc = [sender indexOfSelectedItem];
}

- (IBAction)changeAnalysisLowerCutoff:(id)sender
{
   _analysisLowerCutoff = [sender doubleValue];
   
   if ( sender == _analysisLowerCutoffSlider )
      _analysisLowerCutoff /= 10.0;
   
   // Enforce consistency
   if ( _analysisLowerCutoff > _analysisUpperCutoff )
      _analysisLowerCutoff = _analysisUpperCutoff;
   
   [_analysisLowerCutoffSlider setDoubleValue: _analysisLowerCutoff*10.0];
   [_analysisLowerCutoffText setDoubleValue: _analysisLowerCutoff];
}

- (IBAction)changeAnalysisUpperCutoff:(id)sender
{
   _analysisUpperCutoff = [sender doubleValue];
   
   if ( sender == _analysisUpperCutoffSlider )
      _analysisUpperCutoff /= 10.0;
   
   // Enforce consistency
   if ( _analysisUpperCutoff < _analysisLowerCutoff )
      _analysisUpperCutoff = _analysisLowerCutoff;
   
   [_analysisUpperCutoffSlider setDoubleValue: _analysisUpperCutoff*10.0];
   [_analysisUpperCutoffText setDoubleValue: _analysisUpperCutoff];
}

- (IBAction)changeAnalysisImageUpdating:(id)sender
{
   _analysisImageUpdating = ([sender state] == NSOnState);
}

- (IBAction)changeAnalysisMultiProc:(id)sender
{
   _analysisMultiProc = [sender indexOfSelectedItem];
}

- (IBAction)changeStackImageUpdating:(id)sender
{
   _stackImageUpdating = ([sender state] == NSOnState);
}

- (IBAction)changeStackMultiProc:(id)sender
{
   _stackMultiProc = ([sender indexOfSelectedItem] == 1);
}

- (IBAction)changeProcessMultiProc:(id)sender
{
   _processMultiProc = ([sender indexOfSelectedItem] == 1);
}

- (IBAction)resetPrefs:(id)sender
{
   [self initPrefsValue];
   [self savePrefs];
   [self updatePanel];
}

- (IBAction)applyChanges:(id)sender
{
   [self savePrefs];
}

- (IBAction)cancelChanges:(id)sender
{
   [_panel orderOut:sender];
}

- (IBAction)confirmChanges:(id)sender
{
   [self savePrefs];
   [_panel orderOut:sender];
}

- (IBAction) showPrefs :(id)sender
{
   [self readPrefs];
   [self updatePanel];
   
   [_panel makeKeyAndOrderFront:self];
}

@end