Moved volume controls into AudioPlayer, logarithmic helper functions now have their own file, fixed broken seekbar resize
parent
9d8be7851a
commit
1b83061c49
|
@ -58,11 +58,11 @@ increase/decrease as long as the user holds the left/right, plus/minus button */
|
||||||
break;
|
break;
|
||||||
case kRemoteButtonVolume_Plus_Hold:
|
case kRemoteButtonVolume_Plus_Hold:
|
||||||
//Volume Up
|
//Volume Up
|
||||||
[playbackController volumeUp:DEFAULT_VOLUME_UP];
|
[playbackController volumeUp:self];
|
||||||
break;
|
break;
|
||||||
case kRemoteButtonVolume_Minus_Hold:
|
case kRemoteButtonVolume_Minus_Hold:
|
||||||
//Volume Down
|
//Volume Down
|
||||||
[playbackController volumeDown:DEFAULT_VOLUME_DOWN];
|
[playbackController volumeDown:self];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (remoteButtonHeld)
|
if (remoteButtonHeld)
|
||||||
|
@ -99,10 +99,10 @@ increase/decrease as long as the user holds the left/right, plus/minus button */
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case kRemoteButtonVolume_Plus:
|
case kRemoteButtonVolume_Plus:
|
||||||
[playbackController volumeUp:DEFAULT_VOLUME_UP];
|
[playbackController volumeUp:self];
|
||||||
break;
|
break;
|
||||||
case kRemoteButtonVolume_Minus:
|
case kRemoteButtonVolume_Minus:
|
||||||
[playbackController volumeDown:DEFAULT_VOLUME_DOWN];
|
[playbackController volumeDown:self];
|
||||||
break;
|
break;
|
||||||
case kRemoteButtonRight:
|
case kRemoteButtonRight:
|
||||||
[self clickNext];
|
[self clickNext];
|
||||||
|
|
|
@ -40,11 +40,9 @@
|
||||||
|
|
||||||
- (IBAction)toggleShowTimeRemaining:(id)sender;
|
- (IBAction)toggleShowTimeRemaining:(id)sender;
|
||||||
- (IBAction)changeVolume:(id)sender;
|
- (IBAction)changeVolume:(id)sender;
|
||||||
|
- (IBAction)volumeDown:(id)sender;
|
||||||
|
- (IBAction)volumeUp:(id)sender;
|
||||||
|
|
||||||
- (void)volumeDown:(double)amount;
|
|
||||||
- (IBAction)eventVolumeDown:(id)sender;
|
|
||||||
- (void)volumeUp:(double)amount;
|
|
||||||
- (IBAction)eventVolumeUp:(id)sender;
|
|
||||||
- (IBAction)playPauseResume:(id)sender;
|
- (IBAction)playPauseResume:(id)sender;
|
||||||
- (IBAction)pauseResume:(id)sender;
|
- (IBAction)pauseResume:(id)sender;
|
||||||
- (IBAction)skipToNextAlbum:(id)sender;
|
- (IBAction)skipToNextAlbum:(id)sender;
|
||||||
|
@ -63,7 +61,7 @@
|
||||||
- (void)seekForward:(double)sender;
|
- (void)seekForward:(double)sender;
|
||||||
- (IBAction)eventSeekBackward:(id)sender;
|
- (IBAction)eventSeekBackward:(id)sender;
|
||||||
- (void)seekBackward:(double)amount;
|
- (void)seekBackward:(double)amount;
|
||||||
- (IBAction)fadeOut:(id)sender withTime:(double)time;
|
- (IBAction)fade:(id)sender withTime:(double)time;
|
||||||
|
|
||||||
- (void)initDefaults;
|
- (void)initDefaults;
|
||||||
- (void)audioFadeDown:(NSTimer *)audioTimer;
|
- (void)audioFadeDown:(NSTimer *)audioTimer;
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#import "PlaylistView.h"
|
#import "PlaylistView.h"
|
||||||
#import <Foundation/NSTimer.h>
|
#import <Foundation/NSTimer.h>
|
||||||
#import "CogAudio/Status.h"
|
#import "CogAudio/Status.h"
|
||||||
|
#import "CogAudio/Helper.h"
|
||||||
|
|
||||||
#import "PlaylistController.h"
|
#import "PlaylistController.h"
|
||||||
#import "PlaylistEntry.h"
|
#import "PlaylistEntry.h"
|
||||||
|
@ -10,23 +11,6 @@
|
||||||
|
|
||||||
#define DEFAULT_SEEK 10
|
#define DEFAULT_SEEK 10
|
||||||
|
|
||||||
//MAX_VOLUME is in percent
|
|
||||||
#define MAX_VOLUME 400
|
|
||||||
|
|
||||||
//These functions are helpers for the process of converting volume from a linear to logarithmic scale.
|
|
||||||
//Numbers that goes in to audioPlayer should be logarithmic. Numbers that are displayed to the user should be linear.
|
|
||||||
//Here's why: http://www.dr-lex.34sp.com/info-stuff/volumecontrols.html
|
|
||||||
//We are using the approximation of X^4.
|
|
||||||
//Input/Output values are in percents.
|
|
||||||
double logarithmicToLinear(double logarithmic)
|
|
||||||
{
|
|
||||||
return pow((logarithmic/MAX_VOLUME), 0.25) * 100.0;
|
|
||||||
}
|
|
||||||
double linearToLogarithmic(double linear)
|
|
||||||
{
|
|
||||||
return (linear/100) * (linear/100) * (linear/100) * (linear/100) * MAX_VOLUME;
|
|
||||||
}
|
|
||||||
//End helper volume function thingies. ONWARDS TO GLORY!
|
|
||||||
|
|
||||||
- (id)init
|
- (id)init
|
||||||
{
|
{
|
||||||
|
@ -248,17 +232,11 @@ double linearToLogarithmic(double linear)
|
||||||
double seekTo = [audioPlayer amountPlayed] - amount;
|
double seekTo = [audioPlayer amountPlayed] - amount;
|
||||||
|
|
||||||
if (seekTo < 0)
|
if (seekTo < 0)
|
||||||
{
|
seekTo = 0;
|
||||||
[audioPlayer seekToTime:0];
|
|
||||||
[self updateTimeField:0];
|
[audioPlayer seekToTime:seekTo];
|
||||||
[positionSlider setDoubleValue:0.0];
|
[self updateTimeField:seekTo];
|
||||||
}
|
[positionSlider setDoubleValue:seekTo];
|
||||||
else
|
|
||||||
{
|
|
||||||
[audioPlayer seekToTime:seekTo];
|
|
||||||
[self updateTimeField:seekTo];
|
|
||||||
[positionSlider setDoubleValue:seekTo];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)changePlayButtonImage:(NSString *)name
|
- (void)changePlayButtonImage:(NSString *)name
|
||||||
|
@ -295,12 +273,13 @@ double linearToLogarithmic(double linear)
|
||||||
{
|
{
|
||||||
double volume = [audioPlayer volume];
|
double volume = [audioPlayer volume];
|
||||||
double originalVolume = [[audioTimer userInfo] doubleValue];
|
double originalVolume = [[audioTimer userInfo] doubleValue];
|
||||||
|
double down = originalVolume/10;
|
||||||
|
|
||||||
NSLog(@"VOLUME IS %lf", volume);
|
NSLog(@"VOLUME IS %lf", volume);
|
||||||
|
|
||||||
if (volume > 0.0001) //YAY! Roundoff error!
|
if (volume > 0.0001) //YAY! Roundoff error!
|
||||||
{
|
{
|
||||||
[self volumeDown:5];
|
[audioPlayer volumeDown:down];
|
||||||
}
|
}
|
||||||
else // volume is at 0 or below, we are ready to release the timer and move on
|
else // volume is at 0 or below, we are ready to release the timer and move on
|
||||||
{
|
{
|
||||||
|
@ -316,15 +295,16 @@ double linearToLogarithmic(double linear)
|
||||||
{
|
{
|
||||||
double volume = [audioPlayer volume];
|
double volume = [audioPlayer volume];
|
||||||
double originalVolume = [[audioTimer userInfo] doubleValue];
|
double originalVolume = [[audioTimer userInfo] doubleValue];
|
||||||
|
double up = originalVolume/10;
|
||||||
|
|
||||||
NSLog(@"VOLUME IS %lf", volume);
|
NSLog(@"VOLUME IS %lf", volume);
|
||||||
|
|
||||||
if (volume < originalVolume)
|
if (volume < originalVolume)
|
||||||
{
|
{
|
||||||
if ((volume + 5) > originalVolume)
|
if ((volume + up) > originalVolume)
|
||||||
[self volumeUp:(originalVolume - volume)];
|
[audioPlayer volumeUp:(originalVolume - volume)];
|
||||||
else
|
else
|
||||||
[self volumeUp:5];
|
[audioPlayer volumeUp:up];
|
||||||
}
|
}
|
||||||
else // volume is at 0 or below, we are ready to release the timer and move on
|
else // volume is at 0 or below, we are ready to release the timer and move on
|
||||||
{
|
{
|
||||||
|
@ -334,7 +314,7 @@ double linearToLogarithmic(double linear)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (IBAction)fadeOut:(id)sender withTime:(double)time
|
- (IBAction)fade:(id)sender withTime:(double)time
|
||||||
{
|
{
|
||||||
// we can not allow multiple fade timers to be registered
|
// we can not allow multiple fade timers to be registered
|
||||||
if (playbackStatus == kCogStatusFading)
|
if (playbackStatus == kCogStatusFading)
|
||||||
|
@ -460,35 +440,20 @@ double linearToLogarithmic(double linear)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
- (IBAction)eventVolumeDown:(id)sender
|
- (IBAction)volumeDown:(id)sender
|
||||||
{
|
|
||||||
[self volumeDown:DEFAULT_VOLUME_DOWN];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)volumeDown:(double)amount
|
|
||||||
{
|
{
|
||||||
double newVolume;
|
double newVolume;
|
||||||
if (amount > [audioPlayer volume])
|
newVolume = [audioPlayer volumeDown:DEFAULT_VOLUME_DOWN];
|
||||||
newVolume = 0.0;
|
|
||||||
else
|
|
||||||
newVolume = linearToLogarithmic(logarithmicToLinear([audioPlayer volume]) - amount);
|
|
||||||
|
|
||||||
[volumeSlider setDoubleValue:logarithmicToLinear(newVolume)];
|
[volumeSlider setDoubleValue:logarithmicToLinear(newVolume)];
|
||||||
[audioPlayer setVolume:newVolume];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (IBAction)eventVolumeUp:(id)sender
|
- (IBAction)volumeUp:(id)sender
|
||||||
{
|
{
|
||||||
[self volumeUp:DEFAULT_VOLUME_UP];
|
double newVolume;
|
||||||
}
|
newVolume = [audioPlayer volumeUp:DEFAULT_VOLUME_UP];
|
||||||
- (void)volumeUp:(double)amount
|
|
||||||
{
|
|
||||||
double newVolume = linearToLogarithmic(logarithmicToLinear([audioPlayer volume]) + amount);
|
|
||||||
if (newVolume > MAX_VOLUME)
|
|
||||||
newVolume = MAX_VOLUME;
|
|
||||||
|
|
||||||
[volumeSlider setDoubleValue:logarithmicToLinear(newVolume)];
|
[volumeSlider setDoubleValue:logarithmicToLinear(newVolume)];
|
||||||
[audioPlayer setVolume:newVolume];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -43,6 +43,8 @@
|
||||||
- (void)seekToTime:(double)time;
|
- (void)seekToTime:(double)time;
|
||||||
- (void)setVolume:(double)v;
|
- (void)setVolume:(double)v;
|
||||||
- (double)volume;
|
- (double)volume;
|
||||||
|
- (double)volumeUp:(double)amount;
|
||||||
|
- (double)volumeDown:(double)amount;
|
||||||
|
|
||||||
- (double)amountPlayed;
|
- (double)amountPlayed;
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
#import "BufferChain.h"
|
#import "BufferChain.h"
|
||||||
#import "OutputNode.h"
|
#import "OutputNode.h"
|
||||||
#import "Status.h"
|
#import "Status.h"
|
||||||
|
#import "Helper.h"
|
||||||
#import "PluginController.h"
|
#import "PluginController.h"
|
||||||
|
|
||||||
|
|
||||||
|
@ -352,4 +353,30 @@
|
||||||
return [[pluginController sources] allKeys];
|
return [[pluginController sources] allKeys];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (double)volumeUp:(double)amount
|
||||||
|
{
|
||||||
|
double newVolume = linearToLogarithmic(logarithmicToLinear(volume + amount));
|
||||||
|
if (newVolume > MAX_VOLUME)
|
||||||
|
newVolume = MAX_VOLUME;
|
||||||
|
|
||||||
|
[self setVolume:newVolume];
|
||||||
|
|
||||||
|
// the playbackController needs to know the new volume, so it can update the
|
||||||
|
// volumeSlider accordingly.
|
||||||
|
return newVolume;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (double)volumeDown:(double)amount
|
||||||
|
{
|
||||||
|
double newVolume;
|
||||||
|
if (amount > volume)
|
||||||
|
newVolume = 0.0;
|
||||||
|
else
|
||||||
|
newVolume = linearToLogarithmic(logarithmicToLinear(volume - amount));
|
||||||
|
|
||||||
|
[self setVolume:newVolume];
|
||||||
|
return newVolume;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -46,6 +46,8 @@
|
||||||
8E8D3D300CBAEE6E00135C1B /* AudioContainer.m in Sources */ = {isa = PBXBuildFile; fileRef = 8E8D3D2E0CBAEE6E00135C1B /* AudioContainer.m */; };
|
8E8D3D300CBAEE6E00135C1B /* AudioContainer.m in Sources */ = {isa = PBXBuildFile; fileRef = 8E8D3D2E0CBAEE6E00135C1B /* AudioContainer.m */; };
|
||||||
8EC1225F0B993BD500C5B3AD /* ConverterNode.h in Headers */ = {isa = PBXBuildFile; fileRef = 8EC1225D0B993BD500C5B3AD /* ConverterNode.h */; };
|
8EC1225F0B993BD500C5B3AD /* ConverterNode.h in Headers */ = {isa = PBXBuildFile; fileRef = 8EC1225D0B993BD500C5B3AD /* ConverterNode.h */; };
|
||||||
8EC122600B993BD500C5B3AD /* ConverterNode.m in Sources */ = {isa = PBXBuildFile; fileRef = 8EC1225E0B993BD500C5B3AD /* ConverterNode.m */; };
|
8EC122600B993BD500C5B3AD /* ConverterNode.m in Sources */ = {isa = PBXBuildFile; fileRef = 8EC1225E0B993BD500C5B3AD /* ConverterNode.m */; };
|
||||||
|
B0575F2D0D687A0800411D77 /* Helper.h in Headers */ = {isa = PBXBuildFile; fileRef = B0575F2C0D687A0800411D77 /* Helper.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||||
|
B0575F300D687A4000411D77 /* Helper.m in Sources */ = {isa = PBXBuildFile; fileRef = B0575F2F0D687A4000411D77 /* Helper.m */; };
|
||||||
/* End PBXBuildFile section */
|
/* End PBXBuildFile section */
|
||||||
|
|
||||||
/* Begin PBXCopyFilesBuildPhase section */
|
/* Begin PBXCopyFilesBuildPhase section */
|
||||||
|
@ -105,6 +107,8 @@
|
||||||
8E8D3D2E0CBAEE6E00135C1B /* AudioContainer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AudioContainer.m; sourceTree = "<group>"; };
|
8E8D3D2E0CBAEE6E00135C1B /* AudioContainer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AudioContainer.m; sourceTree = "<group>"; };
|
||||||
8EC1225D0B993BD500C5B3AD /* ConverterNode.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = ConverterNode.h; sourceTree = "<group>"; };
|
8EC1225D0B993BD500C5B3AD /* ConverterNode.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = ConverterNode.h; sourceTree = "<group>"; };
|
||||||
8EC1225E0B993BD500C5B3AD /* ConverterNode.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; path = ConverterNode.m; sourceTree = "<group>"; };
|
8EC1225E0B993BD500C5B3AD /* ConverterNode.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; path = ConverterNode.m; sourceTree = "<group>"; };
|
||||||
|
B0575F2C0D687A0800411D77 /* Helper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Helper.h; sourceTree = "<group>"; };
|
||||||
|
B0575F2F0D687A4000411D77 /* Helper.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Helper.m; sourceTree = "<group>"; };
|
||||||
D2F7E79907B2D74100F64583 /* CoreData.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreData.framework; path = /System/Library/Frameworks/CoreData.framework; sourceTree = "<absolute>"; };
|
D2F7E79907B2D74100F64583 /* CoreData.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreData.framework; path = /System/Library/Frameworks/CoreData.framework; sourceTree = "<absolute>"; };
|
||||||
/* End PBXFileReference section */
|
/* End PBXFileReference section */
|
||||||
|
|
||||||
|
@ -182,6 +186,8 @@
|
||||||
17D21C750B8BE4BA00D1EBDE /* Chain */,
|
17D21C750B8BE4BA00D1EBDE /* Chain */,
|
||||||
17D21C9B0B8BE4BA00D1EBDE /* Output */,
|
17D21C9B0B8BE4BA00D1EBDE /* Output */,
|
||||||
17D21C9E0B8BE4BA00D1EBDE /* Status.h */,
|
17D21C9E0B8BE4BA00D1EBDE /* Status.h */,
|
||||||
|
B0575F2C0D687A0800411D77 /* Helper.h */,
|
||||||
|
B0575F2F0D687A4000411D77 /* Helper.m */,
|
||||||
17D21CD80B8BE5B400D1EBDE /* ThirdParty */,
|
17D21CD80B8BE5B400D1EBDE /* ThirdParty */,
|
||||||
17D21CDC0B8BE5B400D1EBDE /* Utils */,
|
17D21CDC0B8BE5B400D1EBDE /* Utils */,
|
||||||
);
|
);
|
||||||
|
@ -305,6 +311,7 @@
|
||||||
17ADB13C0B97926D00257CA2 /* AudioSource.h in Headers */,
|
17ADB13C0B97926D00257CA2 /* AudioSource.h in Headers */,
|
||||||
8EC1225F0B993BD500C5B3AD /* ConverterNode.h in Headers */,
|
8EC1225F0B993BD500C5B3AD /* ConverterNode.h in Headers */,
|
||||||
8E8D3D2F0CBAEE6E00135C1B /* AudioContainer.h in Headers */,
|
8E8D3D2F0CBAEE6E00135C1B /* AudioContainer.h in Headers */,
|
||||||
|
B0575F2D0D687A0800411D77 /* Helper.h in Headers */,
|
||||||
);
|
);
|
||||||
runOnlyForDeploymentPostprocessing = 0;
|
runOnlyForDeploymentPostprocessing = 0;
|
||||||
};
|
};
|
||||||
|
@ -380,6 +387,7 @@
|
||||||
17ADB13D0B97926D00257CA2 /* AudioSource.m in Sources */,
|
17ADB13D0B97926D00257CA2 /* AudioSource.m in Sources */,
|
||||||
8EC122600B993BD500C5B3AD /* ConverterNode.m in Sources */,
|
8EC122600B993BD500C5B3AD /* ConverterNode.m in Sources */,
|
||||||
8E8D3D300CBAEE6E00135C1B /* AudioContainer.m in Sources */,
|
8E8D3D300CBAEE6E00135C1B /* AudioContainer.m in Sources */,
|
||||||
|
B0575F300D687A4000411D77 /* Helper.m in Sources */,
|
||||||
);
|
);
|
||||||
runOnlyForDeploymentPostprocessing = 0;
|
runOnlyForDeploymentPostprocessing = 0;
|
||||||
};
|
};
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
/*
|
||||||
|
* Helper.h
|
||||||
|
* CogAudio
|
||||||
|
*
|
||||||
|
* Created by Andre Reffhaug on 2/17/08.
|
||||||
|
* Copyright 2008 __MyCompanyName__. All rights reserved.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define MAX_VOLUME 400
|
||||||
|
|
||||||
|
double logarithmicToLinear(double logarithmic);
|
||||||
|
double linearToLogarithmic(double linear);
|
|
@ -0,0 +1,27 @@
|
||||||
|
/*
|
||||||
|
* Helper.c
|
||||||
|
* CogAudio
|
||||||
|
*
|
||||||
|
* Created by Andre Reffhaug on 2/17/08.
|
||||||
|
* Copyright 2008 __MyCompanyName__. All rights reserved.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <math.h>
|
||||||
|
#include "Helper.h"
|
||||||
|
|
||||||
|
//These functions are helpers for the process of converting volume from a linear to logarithmic scale.
|
||||||
|
//Numbers that goes in to audioPlayer should be logarithmic. Numbers that are displayed to the user should be linear.
|
||||||
|
//Here's why: http://www.dr-lex.34sp.com/info-stuff/volumecontrols.html
|
||||||
|
//We are using the approximation of X^4.
|
||||||
|
//Input/Output values are in percents.
|
||||||
|
double logarithmicToLinear(double logarithmic)
|
||||||
|
{
|
||||||
|
return pow((logarithmic/MAX_VOLUME), 0.25) * 100.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
double linearToLogarithmic(double linear)
|
||||||
|
{
|
||||||
|
return (linear/100) * (linear/100) * (linear/100) * (linear/100) * MAX_VOLUME;
|
||||||
|
}
|
||||||
|
//End helper volume function thingies. ONWARDS TO GLORY!
|
File diff suppressed because it is too large
Load Diff
|
@ -248,7 +248,7 @@
|
||||||
// shift+command+p - fade to pause
|
// shift+command+p - fade to pause
|
||||||
else if (modifiers == (NSCommandKeyMask | NSShiftKeyMask) && c == 0x70)
|
else if (modifiers == (NSCommandKeyMask | NSShiftKeyMask) && c == 0x70)
|
||||||
{
|
{
|
||||||
[playbackController fadeOut:self withTime:0.1];
|
[playbackController fade:self withTime:0.1];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue