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;
|
||||
case kRemoteButtonVolume_Plus_Hold:
|
||||
//Volume Up
|
||||
[playbackController volumeUp:DEFAULT_VOLUME_UP];
|
||||
[playbackController volumeUp:self];
|
||||
break;
|
||||
case kRemoteButtonVolume_Minus_Hold:
|
||||
//Volume Down
|
||||
[playbackController volumeDown:DEFAULT_VOLUME_DOWN];
|
||||
[playbackController volumeDown:self];
|
||||
break;
|
||||
}
|
||||
if (remoteButtonHeld)
|
||||
|
@ -99,10 +99,10 @@ increase/decrease as long as the user holds the left/right, plus/minus button */
|
|||
|
||||
break;
|
||||
case kRemoteButtonVolume_Plus:
|
||||
[playbackController volumeUp:DEFAULT_VOLUME_UP];
|
||||
[playbackController volumeUp:self];
|
||||
break;
|
||||
case kRemoteButtonVolume_Minus:
|
||||
[playbackController volumeDown:DEFAULT_VOLUME_DOWN];
|
||||
[playbackController volumeDown:self];
|
||||
break;
|
||||
case kRemoteButtonRight:
|
||||
[self clickNext];
|
||||
|
|
|
@ -40,11 +40,9 @@
|
|||
|
||||
- (IBAction)toggleShowTimeRemaining:(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)pauseResume:(id)sender;
|
||||
- (IBAction)skipToNextAlbum:(id)sender;
|
||||
|
@ -63,7 +61,7 @@
|
|||
- (void)seekForward:(double)sender;
|
||||
- (IBAction)eventSeekBackward:(id)sender;
|
||||
- (void)seekBackward:(double)amount;
|
||||
- (IBAction)fadeOut:(id)sender withTime:(double)time;
|
||||
- (IBAction)fade:(id)sender withTime:(double)time;
|
||||
|
||||
- (void)initDefaults;
|
||||
- (void)audioFadeDown:(NSTimer *)audioTimer;
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#import "PlaylistView.h"
|
||||
#import <Foundation/NSTimer.h>
|
||||
#import "CogAudio/Status.h"
|
||||
#import "CogAudio/Helper.h"
|
||||
|
||||
#import "PlaylistController.h"
|
||||
#import "PlaylistEntry.h"
|
||||
|
@ -10,23 +11,6 @@
|
|||
|
||||
#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
|
||||
{
|
||||
|
@ -248,17 +232,11 @@ double linearToLogarithmic(double linear)
|
|||
double seekTo = [audioPlayer amountPlayed] - amount;
|
||||
|
||||
if (seekTo < 0)
|
||||
{
|
||||
[audioPlayer seekToTime:0];
|
||||
[self updateTimeField:0];
|
||||
[positionSlider setDoubleValue:0.0];
|
||||
}
|
||||
else
|
||||
{
|
||||
[audioPlayer seekToTime:seekTo];
|
||||
[self updateTimeField:seekTo];
|
||||
[positionSlider setDoubleValue:seekTo];
|
||||
}
|
||||
seekTo = 0;
|
||||
|
||||
[audioPlayer seekToTime:seekTo];
|
||||
[self updateTimeField:seekTo];
|
||||
[positionSlider setDoubleValue:seekTo];
|
||||
}
|
||||
|
||||
- (void)changePlayButtonImage:(NSString *)name
|
||||
|
@ -295,12 +273,13 @@ double linearToLogarithmic(double linear)
|
|||
{
|
||||
double volume = [audioPlayer volume];
|
||||
double originalVolume = [[audioTimer userInfo] doubleValue];
|
||||
|
||||
double down = originalVolume/10;
|
||||
|
||||
NSLog(@"VOLUME IS %lf", volume);
|
||||
|
||||
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
|
||||
{
|
||||
|
@ -316,15 +295,16 @@ double linearToLogarithmic(double linear)
|
|||
{
|
||||
double volume = [audioPlayer volume];
|
||||
double originalVolume = [[audioTimer userInfo] doubleValue];
|
||||
|
||||
double up = originalVolume/10;
|
||||
|
||||
NSLog(@"VOLUME IS %lf", volume);
|
||||
|
||||
if (volume < originalVolume)
|
||||
{
|
||||
if ((volume + 5) > originalVolume)
|
||||
[self volumeUp:(originalVolume - volume)];
|
||||
if ((volume + up) > originalVolume)
|
||||
[audioPlayer volumeUp:(originalVolume - volume)];
|
||||
else
|
||||
[self volumeUp:5];
|
||||
[audioPlayer volumeUp:up];
|
||||
}
|
||||
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
|
||||
if (playbackStatus == kCogStatusFading)
|
||||
|
@ -460,35 +440,20 @@ double linearToLogarithmic(double linear)
|
|||
}
|
||||
|
||||
|
||||
- (IBAction)eventVolumeDown:(id)sender
|
||||
{
|
||||
[self volumeDown:DEFAULT_VOLUME_DOWN];
|
||||
}
|
||||
|
||||
- (void)volumeDown:(double)amount
|
||||
- (IBAction)volumeDown:(id)sender
|
||||
{
|
||||
double newVolume;
|
||||
if (amount > [audioPlayer volume])
|
||||
newVolume = 0.0;
|
||||
else
|
||||
newVolume = linearToLogarithmic(logarithmicToLinear([audioPlayer volume]) - amount);
|
||||
|
||||
newVolume = [audioPlayer volumeDown:DEFAULT_VOLUME_DOWN];
|
||||
[volumeSlider setDoubleValue:logarithmicToLinear(newVolume)];
|
||||
[audioPlayer setVolume:newVolume];
|
||||
|
||||
}
|
||||
|
||||
- (IBAction)eventVolumeUp:(id)sender
|
||||
- (IBAction)volumeUp:(id)sender
|
||||
{
|
||||
[self volumeUp:DEFAULT_VOLUME_UP];
|
||||
}
|
||||
- (void)volumeUp:(double)amount
|
||||
{
|
||||
double newVolume = linearToLogarithmic(logarithmicToLinear([audioPlayer volume]) + amount);
|
||||
if (newVolume > MAX_VOLUME)
|
||||
newVolume = MAX_VOLUME;
|
||||
|
||||
double newVolume;
|
||||
newVolume = [audioPlayer volumeUp:DEFAULT_VOLUME_UP];
|
||||
[volumeSlider setDoubleValue:logarithmicToLinear(newVolume)];
|
||||
[audioPlayer setVolume:newVolume];
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -43,6 +43,8 @@
|
|||
- (void)seekToTime:(double)time;
|
||||
- (void)setVolume:(double)v;
|
||||
- (double)volume;
|
||||
- (double)volumeUp:(double)amount;
|
||||
- (double)volumeDown:(double)amount;
|
||||
|
||||
- (double)amountPlayed;
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#import "BufferChain.h"
|
||||
#import "OutputNode.h"
|
||||
#import "Status.h"
|
||||
#import "Helper.h"
|
||||
#import "PluginController.h"
|
||||
|
||||
|
||||
|
@ -352,4 +353,30 @@
|
|||
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
|
||||
|
|
|
@ -46,6 +46,8 @@
|
|||
8E8D3D300CBAEE6E00135C1B /* AudioContainer.m in Sources */ = {isa = PBXBuildFile; fileRef = 8E8D3D2E0CBAEE6E00135C1B /* AudioContainer.m */; };
|
||||
8EC1225F0B993BD500C5B3AD /* ConverterNode.h in Headers */ = {isa = PBXBuildFile; fileRef = 8EC1225D0B993BD500C5B3AD /* ConverterNode.h */; };
|
||||
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 */
|
||||
|
||||
/* Begin PBXCopyFilesBuildPhase section */
|
||||
|
@ -105,6 +107,8 @@
|
|||
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>"; };
|
||||
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>"; };
|
||||
/* End PBXFileReference section */
|
||||
|
||||
|
@ -182,6 +186,8 @@
|
|||
17D21C750B8BE4BA00D1EBDE /* Chain */,
|
||||
17D21C9B0B8BE4BA00D1EBDE /* Output */,
|
||||
17D21C9E0B8BE4BA00D1EBDE /* Status.h */,
|
||||
B0575F2C0D687A0800411D77 /* Helper.h */,
|
||||
B0575F2F0D687A4000411D77 /* Helper.m */,
|
||||
17D21CD80B8BE5B400D1EBDE /* ThirdParty */,
|
||||
17D21CDC0B8BE5B400D1EBDE /* Utils */,
|
||||
);
|
||||
|
@ -305,6 +311,7 @@
|
|||
17ADB13C0B97926D00257CA2 /* AudioSource.h in Headers */,
|
||||
8EC1225F0B993BD500C5B3AD /* ConverterNode.h in Headers */,
|
||||
8E8D3D2F0CBAEE6E00135C1B /* AudioContainer.h in Headers */,
|
||||
B0575F2D0D687A0800411D77 /* Helper.h in Headers */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
@ -380,6 +387,7 @@
|
|||
17ADB13D0B97926D00257CA2 /* AudioSource.m in Sources */,
|
||||
8EC122600B993BD500C5B3AD /* ConverterNode.m in Sources */,
|
||||
8E8D3D300CBAEE6E00135C1B /* AudioContainer.m in Sources */,
|
||||
B0575F300D687A4000411D77 /* Helper.m in Sources */,
|
||||
);
|
||||
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
|
||||
else if (modifiers == (NSCommandKeyMask | NSShiftKeyMask) && c == 0x70)
|
||||
{
|
||||
[playbackController fadeOut:self withTime:0.1];
|
||||
[playbackController fade:self withTime:0.1];
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue