Added incremental seeking with remote, volumeUp/Down now take an amount argument, seekForward/Backward now take an amount argument, fixed incremental fadeout that will not register more than one timer, added status kCogStatusFading

CQTexperiment
areff 2008-02-13 18:03:06 +00:00
parent 3c712e2e45
commit f64ebf597f
6 changed files with 2135 additions and 2090 deletions

View File

@ -44,33 +44,47 @@
increase/decrease as long as the user holds the left/right, plus/minus button */
- (void) executeHoldActionForRemoteButton: (NSNumber*) buttonIdentifierNumber
{
static int incrementalSearch = 1;
if (remoteButtonHeld)
{
switch([buttonIdentifierNumber intValue])
{
case kRemoteButtonRight_Hold:
//Seek forward?
[playbackController seekForward:incrementalSearch];
break;
case kRemoteButtonLeft_Hold:
//Seek back
[playbackController seekBackward:incrementalSearch];
break;
case kRemoteButtonVolume_Plus_Hold:
//Volume Up
[playbackController volumeUp: self];
[playbackController volumeUp:DEFAULT_VOLUME_UP];
break;
case kRemoteButtonVolume_Minus_Hold:
//Volume Down
[playbackController volumeDown: self];
[playbackController volumeDown:DEFAULT_VOLUME_DOWN];
break;
}
if (remoteButtonHeld)
{
/* there should perhaps be a max amount that incrementalSearch can
be, so as to not start skipping ahead unreasonable amounts, even
in very long files. */
if ((incrementalSearch % 3) == 0)
incrementalSearch += incrementalSearch/3;
else
incrementalSearch++;
/* trigger event */
[self performSelector:@selector(executeHoldActionForRemoteButton:)
withObject:buttonIdentifierNumber
afterDelay:0.25];
}
}
else
// if we're not holding the search button, reset the incremental search
// variable, making it ready for another search
incrementalSearch = 1;
}
/* Apple Remote callback */
@ -85,10 +99,10 @@ increase/decrease as long as the user holds the left/right, plus/minus button */
break;
case kRemoteButtonVolume_Plus:
[playbackController volumeUp: self];
[playbackController volumeUp:DEFAULT_VOLUME_UP];
break;
case kRemoteButtonVolume_Minus:
[playbackController volumeDown: self];
[playbackController volumeDown:DEFAULT_VOLUME_DOWN];
break;
case kRemoteButtonRight:
[self clickNext];

View File

@ -8,6 +8,9 @@
#import "TrackingSlider.h"
#import "AudioScrobbler.h"
#define DEFAULT_VOLUME_DOWN 5
#define DEFAULT_VOLUME_UP DEFAULT_VOLUME_DOWN
@class PlaylistController;
@class PlaylistView;
@ -38,9 +41,10 @@
- (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;
@ -54,8 +58,10 @@
- (IBAction)next:(id)sender;
- (IBAction)prev:(id)sender;
- (IBAction)seek:(id)sender;
- (IBAction)seekForward:(id)sender;
- (IBAction)seekBackward:(id)sender;
- (IBAction)eventSeekForward:(id)sender;
- (void)seekForward:(double)sender;
- (IBAction)eventSeekBackward:(id)sender;
- (void)seekBackward:(double)amount;
- (IBAction)fadeOut:(id)sender withTime:(double)time;
- (void)initDefaults;

View File

@ -216,9 +216,14 @@ double linearToLogarithmic(double linear)
[self updateTimeField:time];
}
- (IBAction)seekForward:(id)sender
- (IBAction)eventSeekForward:(id)sender
{
double seekTo = [audioPlayer amountPlayed] + DEFAULT_SEEK;
[self seekForward:DEFAULT_SEEK];
}
- (void)seekForward:(double)amount
{
double seekTo = [audioPlayer amountPlayed] + amount;
if (seekTo > (int)[positionSlider maxValue])
{
@ -232,9 +237,14 @@ double linearToLogarithmic(double linear)
}
}
- (IBAction)seekBackward:(id)sender
- (IBAction)eventSeekBackward:(id)sender
{
double seekTo = [audioPlayer amountPlayed] - DEFAULT_SEEK;
[self seekBackward:DEFAULT_SEEK];
}
- (void)seekBackward:(double)amount
{
double seekTo = [audioPlayer amountPlayed] - amount;
if (seekTo < 0)
{
@ -282,18 +292,22 @@ double linearToLogarithmic(double linear)
containing the current volume before we start fading. */
- (void)audioFader:(NSTimer *)audioTimer
{
static int incrementalFader = 10;
double volume = [audioPlayer volume];
double originalVolume = [[audioTimer userInfo] doubleValue];
NSLog(@"VOLUME IS %lf", volume);
if (volume > 0.0001) //YAY! Roundoff error!
{
[self volumeDown:self];
[self volumeDown:incrementalFader++];
}
else // volume is at 0 or below, we are ready to release the timer and move on
{
[audioPlayer pause];
[audioPlayer setVolume:originalVolume];
[volumeSlider setDoubleValue: logarithmicToLinear(originalVolume)];
incrementalFader = 10;
[audioTimer invalidate];
}
@ -301,11 +315,15 @@ double linearToLogarithmic(double linear)
- (IBAction)fadeOut:(id)sender withTime:(double)time
{
NSNumber *originalVolume = [NSNumber numberWithDouble: [audioPlayer volume]];
NSTimer *fadeTimer;
NSLog(@"currentVolume here%f", [volumeSlider doubleValue]);
// we can not allow multiple fade timers to be registered
if (playbackStatus != kCogStatusPlaying)
return;
NSNumber *originalVolume = [NSNumber numberWithDouble: [audioPlayer volume]];
NSTimer *fadeTimer;
playbackStatus = kCogStatusFading;
fadeTimer = [NSTimer scheduledTimerWithTimeInterval:time
target:self
selector:@selector(audioFader:)
@ -313,19 +331,30 @@ double linearToLogarithmic(double linear)
repeats:YES];
}
- (IBAction)volumeDown:(id)sender
- (IBAction)eventVolumeDown:(id)sender
{
double newVolume = linearToLogarithmic(logarithmicToLinear([audioPlayer volume]) - 5.0);
if (newVolume < 0)
[self volumeDown:DEFAULT_VOLUME_DOWN];
}
- (void)volumeDown:(double)amount
{
double newVolume;
if (amount > [audioPlayer volume])
newVolume = 0.0;
else
newVolume = linearToLogarithmic(logarithmicToLinear([audioPlayer volume]) - amount);
[volumeSlider setDoubleValue:logarithmicToLinear(newVolume)];
[audioPlayer setVolume:newVolume];
}
- (IBAction)volumeUp:(id)sender
- (IBAction)eventVolumeUp:(id)sender
{
double newVolume = linearToLogarithmic(logarithmicToLinear([audioPlayer volume]) + 5.0);
[self volumeUp:DEFAULT_VOLUME_UP];
}
- (void)volumeUp:(double)amount
{
double newVolume = linearToLogarithmic(logarithmicToLinear([audioPlayer volume]) + amount);
if (newVolume > MAX_VOLUME)
newVolume = MAX_VOLUME;

View File

@ -12,6 +12,7 @@ enum
kCogStatusPaused = 0,
kCogStatusStopped,
kCogStatusPlaying,
kCogStatusFading,
// kCogStatusEndOfFile,
// kCogStatusEndOfPlaylist,
// kCogStatusPlaybackEnded

File diff suppressed because it is too large Load Diff

View File

@ -1,8 +1,2 @@
Undo is broken badly when filtering.
Fade to pause is severely broken now that it uses volumeDown, since
this will not take into account the time used to fade.
volumeUp and volumeDown of playbackController aren't quite right, and
the slider sets the volume differently.