Sfoglia il codice sorgente

Added slider for sound input sensitivity

Thomas Buck 9 anni fa
parent
commit
2a0b6e3091

+ 28
- 1
CaseLights/AppDelegate.m Vedi File

@@ -19,6 +19,7 @@
19 19
 #define PREF_LED_MODE @"LEDMode"
20 20
 #define PREF_BRIGHTNESS @"Brightness"
21 21
 #define PREF_COLOR @"ManualColor"
22
+#define PREF_SENSITIVITY @"Sensitivity"
22 23
 
23 24
 #define TEXT_MANUAL @"Select..."
24 25
 #define TEXT_CPU_USAGE @"CPU Usage"
@@ -73,12 +74,15 @@
73 74
 @property (weak) IBOutlet NSMenuItem *menuItemAudio;
74 75
 @property (weak) IBOutlet NSMenu *menuAudio;
75 76
 @property (weak) IBOutlet NSMenu *menuPorts;
76
-
77 77
 @property (weak) IBOutlet NSMenuItem *buttonOff;
78 78
 @property (weak) IBOutlet NSMenuItem *brightnessItem;
79 79
 @property (weak) IBOutlet NSSlider *brightnessSlider;
80 80
 @property (weak) IBOutlet NSMenuItem *brightnessLabel;
81 81
 @property (weak) IBOutlet NSMenuItem *buttonLights;
82
+@property (weak) IBOutlet NSMenuItem *sensitivityItem;
83
+@property (weak) IBOutlet NSSlider *sensitivitySlider;
84
+@property (weak) IBOutlet NSMenuItem *sensitivityLabel;
85
+@property (weak) IBOutlet NSMenuItem *sensitivityMenu;
82 86
 
83 87
 @property (strong) NSMenuItem *menuItemColor;
84 88
 
@@ -99,6 +103,7 @@
99 103
 @synthesize menuItemAudio, menuAudio;
100 104
 @synthesize buttonOff, buttonLights;
101 105
 @synthesize brightnessItem, brightnessSlider, brightnessLabel;
106
+@synthesize sensitivityItem, sensitivitySlider, sensitivityLabel, sensitivityMenu;
102 107
 @synthesize statusItem, statusImage;
103 108
 @synthesize staticColors, animation;
104 109
 @synthesize serial, lastLEDMode, microphone;
@@ -126,6 +131,7 @@
126 131
     [appDefaults setObject:[NSNumber numberWithBool:NO] forKey:PREF_LIGHTS_STATE];
127 132
     [appDefaults setObject:@"" forKey:PREF_LED_MODE];
128 133
     [appDefaults setObject:[NSNumber numberWithFloat:50.0] forKey:PREF_BRIGHTNESS];
134
+    [appDefaults setObject:[NSNumber numberWithFloat:100.0] forKey:PREF_SENSITIVITY];
129 135
     [store registerDefaults:appDefaults];
130 136
     [store synchronize];
131 137
     NSString *savedPort = [store stringForKey:PREF_SERIAL_PORT];
@@ -133,6 +139,7 @@
133 139
     NSString *lastMode = [store stringForKey:PREF_LED_MODE];
134 140
     float brightness = [store floatForKey:PREF_BRIGHTNESS];
135 141
     NSData *lastColorData = [store dataForKey:PREF_COLOR];
142
+    float sensitivity = [store floatForKey:PREF_SENSITIVITY];
136 143
     NSColor *lastColor = nil;
137 144
     if (lastColorData != nil) {
138 145
         lastColor = (NSColor *)[NSUnarchiver unarchiveObjectWithData:lastColorData];
@@ -324,6 +331,13 @@
324 331
     }
325 332
     if ([inputDevices count] > 0) {
326 333
         [menuItemAudio setHidden:NO];
334
+        
335
+        // Prepare sensitivity menu
336
+        sensitivityItem.view = sensitivitySlider;
337
+        [sensitivitySlider setFloatValue:sensitivity];
338
+        [sensitivityLabel setTitle:[NSString stringWithFormat:@"Value: %.0f%%", sensitivity]];
339
+        [sensitivityMenu setHidden:NO];
340
+        [AudioVisualizer setSensitivity:sensitivity];
327 341
     }
328 342
 }
329 343
 
@@ -512,6 +526,16 @@
512 526
     [self setLightsColor:[sender color]];
513 527
 }
514 528
 
529
+- (IBAction)sensitivityMoved:(NSSlider *)sender {
530
+    [sensitivityLabel setTitle:[NSString stringWithFormat:@"Value: %.0f%%", [sender floatValue]]];
531
+    [AudioVisualizer setSensitivity:[sender floatValue]];
532
+    
533
+    // Store changed value in preferences
534
+    NSUserDefaults *store = [NSUserDefaults standardUserDefaults];
535
+    [store setObject:[NSNumber numberWithFloat:[sender floatValue]] forKey:PREF_SENSITIVITY];
536
+    [store synchronize];
537
+}
538
+
515 539
 - (IBAction)brightnessMoved:(NSSlider *)sender {
516 540
     [brightnessLabel setTitle:[NSString stringWithFormat:@"Value: %.0f%%", [sender floatValue]]];
517 541
     
@@ -728,6 +752,9 @@
728 752
         for (int  i = 0; i < [audioDevices count]; i++) {
729 753
             EZAudioDevice *dev = [audioDevices objectAtIndex:i];
730 754
             if ([[dev name] isEqualToString:[sender title]]) {
755
+                // Send command to turn off LEDs
756
+                [self setLightsR:0 G:0 B:0];
757
+                
731 758
                 // Found device
732 759
                 foundDev = YES;
733 760
                 if (microphone != nil) {

+ 1
- 0
CaseLights/AudioVisualizer.h Vedi File

@@ -13,6 +13,7 @@
13 13
 @interface AudioVisualizer : NSObject
14 14
 
15 15
 + (void)setDelegate:(AppDelegate *)delegate;
16
++ (void)setSensitivity:(float)sens;
16 17
 + (void)updateBuffer:(float *)buffer withBufferSize:(UInt32)bufferSize;
17 18
 
18 19
 @end

+ 13
- 0
CaseLights/AudioVisualizer.m Vedi File

@@ -54,6 +54,7 @@
54 54
 static AppDelegate *appDelegate = nil;
55 55
 static EZAudioFFT *fft = nil;
56 56
 static int maxBufferSize = 0;
57
+static float sensitivity = 1.0f;
57 58
 
58 59
 @implementation AudioVisualizer
59 60
 
@@ -61,6 +62,10 @@ static int maxBufferSize = 0;
61 62
     appDelegate = delegate;
62 63
 }
63 64
 
65
++ (void)setSensitivity:(float)sens {
66
+    sensitivity = sens / 100.0;
67
+}
68
+
64 69
 + (void)updateBuffer:(float *)buffer withBufferSize:(UInt32)bufferSize {
65 70
     // Create Fast Fourier Transformation object
66 71
     if (fft == nil) {
@@ -79,6 +84,14 @@ static int maxBufferSize = 0;
79 84
         fft = [EZAudioFFT fftWithMaximumBufferSize:maxBufferSize sampleRate:appDelegate.microphone.audioStreamBasicDescription.mSampleRate];
80 85
     }
81 86
     
87
+    // Scale input if required
88
+    if (sensitivity != 1.0f) {
89
+        for (int i = 0; i < bufferSize; i++) {
90
+            buffer[i] *= sensitivity;
91
+        }
92
+    }
93
+    
94
+    // Perform fast fourier transformation
82 95
     [fft computeFFTWithBuffer:buffer withBufferSize:bufferSize];
83 96
     
84 97
     static float history[FFT_BUCKET_COUNT][FFT_BUCKET_HISTORY];

+ 27
- 1
CaseLights/Base.lproj/MainMenu.xib Vedi File

@@ -28,6 +28,10 @@
28 28
                 <outlet property="menuItemDisplays" destination="1Cz-Xz-d16" id="rRz-n5-n2P"/>
29 29
                 <outlet property="menuPorts" destination="lFU-D0-M5p" id="pHd-AA-S3J"/>
30 30
                 <outlet property="menuVisualizations" destination="yZl-ae-7SI" id="b2b-dW-mvy"/>
31
+                <outlet property="sensitivityItem" destination="ioy-5y-tbs" id="huT-vf-Q9H"/>
32
+                <outlet property="sensitivityLabel" destination="luW-fv-Xlk" id="qbr-n1-q7M"/>
33
+                <outlet property="sensitivityMenu" destination="1Mp-yz-ggj" id="Xif-Mk-ff8"/>
34
+                <outlet property="sensitivitySlider" destination="0Vh-pa-Rae" id="4vd-WY-Jwv"/>
31 35
                 <outlet property="statusMenu" destination="g7M-LS-DgA" id="txO-T1-8yD"/>
32 36
             </connections>
33 37
         </customObject>
@@ -703,6 +707,19 @@
703 707
                     <modifierMask key="keyEquivalentModifierMask"/>
704 708
                     <menu key="submenu" title="Audio Inputs" id="KUj-jy-iwd"/>
705 709
                 </menuItem>
710
+                <menuItem title="Sensitivity" hidden="YES" id="1Mp-yz-ggj">
711
+                    <modifierMask key="keyEquivalentModifierMask"/>
712
+                    <menu key="submenu" title="Sensitivity" id="yt8-Dk-EIy">
713
+                        <items>
714
+                            <menuItem title="Item" id="ioy-5y-tbs">
715
+                                <modifierMask key="keyEquivalentModifierMask"/>
716
+                            </menuItem>
717
+                            <menuItem title="Value: 50%" enabled="NO" id="luW-fv-Xlk">
718
+                                <modifierMask key="keyEquivalentModifierMask"/>
719
+                            </menuItem>
720
+                        </items>
721
+                    </menu>
722
+                </menuItem>
706 723
                 <menuItem title="Brightness" id="Oh0-1U-yDg">
707 724
                     <modifierMask key="keyEquivalentModifierMask"/>
708 725
                     <menu key="submenu" title="Brightness" id="jRu-sM-3xB">
@@ -765,7 +782,16 @@
765 782
             <connections>
766 783
                 <action selector="brightnessMoved:" target="Voe-Tx-rLC" id="Wxj-Xc-ZtT"/>
767 784
             </connections>
768
-            <point key="canvasLocation" x="370.5" y="496.5"/>
785
+            <point key="canvasLocation" x="122.5" y="326.5"/>
786
+        </slider>
787
+        <slider verticalHuggingPriority="750" id="0Vh-pa-Rae">
788
+            <rect key="frame" x="0.0" y="0.0" width="129" height="30"/>
789
+            <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
790
+            <sliderCell key="cell" alignment="left" maxValue="200" doubleValue="100" tickMarkPosition="below" numberOfTickMarks="11" sliderType="linear" id="39W-Os-oE7"/>
791
+            <connections>
792
+                <action selector="sensitivityMoved:" target="Voe-Tx-rLC" id="4Vd-6i-qvd"/>
793
+            </connections>
794
+            <point key="canvasLocation" x="122.5" y="394.5"/>
769 795
         </slider>
770 796
     </objects>
771 797
 </document>

+ 1
- 1
CaseLights/Info.plist Vedi File

@@ -21,7 +21,7 @@
21 21
 	<key>CFBundleSignature</key>
22 22
 	<string>????</string>
23 23
 	<key>CFBundleVersion</key>
24
-	<string>391</string>
24
+	<string>397</string>
25 25
 	<key>LSApplicationCategoryType</key>
26 26
 	<string>public.app-category.utilities</string>
27 27
 	<key>LSMinimumSystemVersion</key>

Loading…
Annulla
Salva