1// 2// PRCDFTHighPass.m 3// PRICE 4// 5// Created by Riccardo Mottola on Mon Oct 13 2003. 6// Copyright (c) 2003-2010 Carduus. All rights reserved. 7// 8// This application 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. 9// 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. 10 11 12#import "PRCDFTHighPass.h" 13#import "MyDocument.h" 14#import "PRDFTHighPass.h" 15 16#include <math.h> 17 18@implementation PRCDFTHighPass 19 20- (id)init 21{ 22 if ((self = [super init])) 23 { 24 filter = [[PRDFTHighPass alloc] init]; 25 } 26 return self; 27} 28 29- (IBAction)showFilter:(id)sender 30{ 31 [super showFilter:sender]; 32 33 if (!filterWindow) 34 [NSBundle loadNibNamed:@"DFTHighPass" owner:self]; 35 [filterWindow makeKeyAndOrderFront:nil]; 36 37 /* now we read the default values and initialize all fields */ 38 if ([autoRangeCheck state] == NSOnState) 39 autoRange = YES; 40 else 41 autoRange = NO; 42 passBandFreq = [passBandSlider floatValue]; 43 [passBandVal setFloatValue:passBandFreq]; 44 [passBandValPi setFloatValue:(passBandFreq*M_PI)]; 45 stopBandFreq = [stopBandSlider floatValue]; 46 [stopBandVal setFloatValue:stopBandFreq]; 47 [stopBandValPi setFloatValue:(stopBandFreq*M_PI)]; 48 49 [self parametersChanged:self]; 50} 51 52- (NSArray *)encodeParameters 53{ 54 NSArray *parameters; 55 56 /* encode parameters */ 57 parameters = [NSArray arrayWithObjects: 58 [NSNumber numberWithBool:autoRange], 59 [NSNumber numberWithFloat:passBandFreq], 60 [NSNumber numberWithFloat:stopBandFreq], 61 nil]; 62 63 return parameters; 64} 65 66 67- (void)closeFilterPanel 68{ 69 [filterWindow performClose:nil]; 70} 71 72- (IBAction)dftHPAutoRange:(id)sender 73{ 74 if ([autoRangeCheck state] == NSOnState) 75 autoRange = YES; 76 else 77 autoRange = NO; 78 [self parametersChanged:sender]; 79} 80 81- (IBAction)changeStopBand:(id)sender 82{ 83 if (sender == stopBandValPi) 84 { 85 stopBandFreq = [sender floatValue] / M_PI; 86 if (stopBandFreq > 1) 87 { 88 stopBandFreq = 1; 89 [stopBandValPi setFloatValue:(stopBandFreq*M_PI)]; 90 } else if (stopBandFreq < 0) 91 { 92 stopBandFreq = 0; 93 [stopBandValPi setFloatValue:(stopBandFreq*M_PI)]; 94 } 95 [stopBandVal setFloatValue:stopBandFreq]; 96 [stopBandSlider setFloatValue:stopBandFreq]; 97 } else if (sender == stopBandVal) 98 { 99 stopBandFreq = [sender floatValue]; 100 if (stopBandFreq > 1) 101 { 102 stopBandFreq = 1; 103 [stopBandVal setFloatValue:stopBandFreq]; 104 } else if (passBandFreq < 0) 105 { 106 stopBandFreq = 0; 107 [stopBandVal setFloatValue:stopBandFreq]; 108 } 109 [stopBandValPi setFloatValue:(stopBandFreq*M_PI)]; 110 [stopBandSlider setFloatValue:stopBandFreq]; 111 } else 112 { 113 stopBandFreq = [sender floatValue]; 114 [stopBandVal setFloatValue:stopBandFreq]; 115 [stopBandValPi setFloatValue:(stopBandFreq*M_PI)]; 116 } 117 if (stopBandFreq > passBandFreq) 118 { 119 passBandFreq = stopBandFreq; 120 [passBandVal setFloatValue:passBandFreq]; 121 [passBandValPi setFloatValue:(passBandFreq*M_PI)]; 122 [passBandSlider setFloatValue:passBandFreq]; 123 } 124 [self parametersChanged:sender]; 125} 126 127- (IBAction)changePassBand:(id)sender 128{ 129 if (sender == passBandValPi) 130 { 131 passBandFreq = [sender floatValue] / M_PI; 132 if (passBandFreq > 1) 133 { 134 passBandFreq = 1; 135 [passBandValPi setFloatValue:(passBandFreq*M_PI)]; 136 } else if (passBandFreq < 0) 137 { 138 passBandFreq = 0; 139 [passBandValPi setFloatValue:(passBandFreq*M_PI)]; 140 } 141 [passBandVal setFloatValue:passBandFreq]; 142 [passBandSlider setFloatValue:passBandFreq]; 143 } else if (sender == passBandVal) 144 { 145 passBandFreq = [sender floatValue]; 146 if (passBandFreq > 1) 147 { 148 passBandFreq = 1; 149 [passBandVal setFloatValue:passBandFreq]; 150 } else if (passBandFreq < 0) 151 { 152 passBandFreq = 0; 153 [passBandVal setFloatValue:passBandFreq]; 154 } 155 [passBandValPi setFloatValue:(passBandFreq*M_PI)]; 156 [passBandSlider setFloatValue:passBandFreq]; 157 } else 158 { 159 passBandFreq = [sender floatValue]; 160 [passBandVal setFloatValue:passBandFreq]; 161 [passBandValPi setFloatValue:(passBandFreq*M_PI)]; 162 } 163 if (passBandFreq < stopBandFreq) 164 { 165 stopBandFreq = passBandFreq; 166 [stopBandVal setFloatValue:stopBandFreq]; 167 [stopBandValPi setFloatValue:(stopBandFreq*M_PI)]; 168 [stopBandSlider setFloatValue:stopBandFreq]; 169 } 170 [self parametersChanged:sender]; 171} 172 173 174@end 175