1// 2// PRCDFTLowPass.m 3// PRICE 4// DFT based LowPass filter controller 5// 6// Created by Riccardo Mottola on Sat Sep 13 2003. 7// Copyright (c) 2003-2010 Carduus. All rights reserved. 8// 9// 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. 10// 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. 11 12#import "PRCDFTLowPass.h" 13#import "MyDocument.h" 14#include "math.h" 15#import "PRDFTLowPass.h" 16 17 18@implementation PRCDFTLowPass 19 20- (id)init 21{ 22 if ((self = [super init])) 23 { 24 filter = [[PRDFTLowPass 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:@"DFTLowPass" 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- (void)closeFilterPanel 67{ 68 [filterWindow performClose:nil]; 69} 70 71- (IBAction)dftLPAutoRange:(id)sender 72{ 73 if ([autoRangeCheck state] == NSOnState) 74 autoRange = YES; 75 else 76 autoRange = NO; 77 [self parametersChanged:sender]; 78} 79 80- (IBAction)changeStopBand:(id)sender 81{ 82 if (sender == stopBandValPi) 83 { 84 stopBandFreq = [sender floatValue] / M_PI; 85 if (stopBandFreq > 1) 86 { 87 stopBandFreq = 1; 88 [stopBandValPi setFloatValue:(stopBandFreq*M_PI)]; 89 } else if (stopBandFreq < 0) 90 { 91 stopBandFreq = 0; 92 [stopBandValPi setFloatValue:(stopBandFreq*M_PI)]; 93 } 94 [stopBandVal setFloatValue:stopBandFreq]; 95 [stopBandSlider setFloatValue:stopBandFreq]; 96 } else if (sender == stopBandVal) 97 { 98 stopBandFreq = [sender floatValue]; 99 if (stopBandFreq > 1) 100 { 101 stopBandFreq = 1; 102 [stopBandVal setFloatValue:stopBandFreq]; 103 } else if (passBandFreq < 0) 104 { 105 stopBandFreq = 0; 106 [stopBandVal setFloatValue:stopBandFreq]; 107 } 108 [stopBandValPi setFloatValue:(stopBandFreq*M_PI)]; 109 [stopBandSlider setFloatValue:stopBandFreq]; 110 } else 111 { 112 stopBandFreq = [sender floatValue]; 113 [stopBandVal setFloatValue:stopBandFreq]; 114 [stopBandValPi setFloatValue:(stopBandFreq*M_PI)]; 115 } 116 if (passBandFreq > stopBandFreq) 117 { 118 passBandFreq = stopBandFreq; 119 [passBandVal setFloatValue:passBandFreq]; 120 [passBandValPi setFloatValue:(passBandFreq*M_PI)]; 121 [passBandSlider setFloatValue:passBandFreq]; 122 } 123 [self parametersChanged:sender]; 124} 125 126- (IBAction)changePassBand:(id)sender 127{ 128 if (sender == passBandValPi) 129 { 130 passBandFreq = [sender floatValue] / M_PI; 131 if (passBandFreq > 1) 132 { 133 passBandFreq = 1; 134 [passBandValPi setFloatValue:(passBandFreq*M_PI)]; 135 } else if (passBandFreq < 0) 136 { 137 passBandFreq = 0; 138 [passBandValPi setFloatValue:(passBandFreq*M_PI)]; 139 } 140 [passBandVal setFloatValue:passBandFreq]; 141 [passBandSlider setFloatValue:passBandFreq]; 142 } else if (sender == passBandVal) 143 { 144 passBandFreq = [sender floatValue]; 145 if (passBandFreq > 1) 146 { 147 passBandFreq = 1; 148 [passBandVal setFloatValue:passBandFreq]; 149 } else if (passBandFreq < 0) 150 { 151 passBandFreq = 0; 152 [passBandVal setFloatValue:passBandFreq]; 153 } 154 [passBandValPi setFloatValue:(passBandFreq*M_PI)]; 155 [passBandSlider setFloatValue:passBandFreq]; 156 } else 157 { 158 passBandFreq = [sender floatValue]; 159 [passBandVal setFloatValue:passBandFreq]; 160 [passBandValPi setFloatValue:(passBandFreq*M_PI)]; 161 } 162 if (stopBandFreq < passBandFreq) 163 { 164 stopBandFreq = passBandFreq; 165 [stopBandVal setFloatValue:stopBandFreq]; 166 [stopBandValPi setFloatValue:(stopBandFreq*M_PI)]; 167 [stopBandSlider setFloatValue:stopBandFreq]; 168 } 169 [self parametersChanged:sender]; 170} 171 172@end 173