Convert CogStatus enum to NS_ENUM

CQTexperiment
Dzmitry Neviadomski 2021-02-07 00:20:03 +03:00
parent 2b916704a0
commit 9840d87127
10 changed files with 73 additions and 61 deletions

View File

@ -165,9 +165,9 @@
int lastStatus = (int) [[NSUserDefaults standardUserDefaults] integerForKey:@"lastPlaybackStatus"];
int lastIndex = (int) [[NSUserDefaults standardUserDefaults] integerForKey:@"lastTrackPlaying"];
if (lastStatus != kCogStatusStopped && lastIndex >= 0)
if (lastStatus != CogStatusStopped && lastIndex >= 0)
{
[playbackController playEntryAtIndex:lastIndex startPaused:(lastStatus == kCogStatusPaused)];
[playbackController playEntryAtIndex:lastIndex startPaused:(lastStatus == CogStatusPaused)];
[playbackController seek:[NSNumber numberWithDouble:[[NSUserDefaults standardUserDefaults] floatForKey:@"lastTrackPosition"]]];
}
}
@ -239,16 +239,16 @@
- (void)applicationWillTerminate:(NSNotification *)aNotification
{
int currentStatus = [playbackController playbackStatus];
CogStatus currentStatus = [playbackController playbackStatus];
int lastTrackPlaying = -1;
double lastTrackPosition = 0;
if (currentStatus == kCogStatusStopping)
currentStatus = kCogStatusStopped;
if (currentStatus == CogStatusStopping)
currentStatus = CogStatusStopped;
[[NSUserDefaults standardUserDefaults] setInteger:currentStatus forKey:@"lastPlaybackStatus"];
if (currentStatus != kCogStatusStopped)
if (currentStatus != CogStatusStopped)
{
PlaylistEntry * pe = [playlistController currentEntry];
lastTrackPlaying = [pe index];
@ -372,7 +372,7 @@
[userDefaultsValuesDict setObject:@"cubic" forKey:@"resampling"];
[userDefaultsValuesDict setObject:[NSNumber numberWithInteger:kCogStatusStopped] forKey:@"lastPlaybackStatus"];
[userDefaultsValuesDict setObject:[NSNumber numberWithInteger:CogStatusStopped] forKey:@"lastPlaybackStatus"];
[userDefaultsValuesDict setObject:[NSNumber numberWithInteger:-1] forKey:@"lastTrackPlaying"];
[userDefaultsValuesDict setObject:[NSNumber numberWithDouble:0] forKey:@"lastTrackPosition"];

View File

@ -49,14 +49,17 @@ static NSString *getBadgeName(NSString *baseName, BOOL colorfulIcons)
BOOL colorfulIcons = [[NSUserDefaults standardUserDefaults] boolForKey:@"colorfulDockIcons"];
if (playbackStatus == kCogStatusPlaying) {
badgeImage = [NSImage imageNamed:getBadgeName(@"playDockBadge", colorfulIcons)];
}
else if (playbackStatus == kCogStatusPaused) {
badgeImage = [NSImage imageNamed:getBadgeName(@"pauseDockBadge", colorfulIcons)];
}
else {
badgeImage = [NSImage imageNamed:getBadgeName(@"stopDockBadge", colorfulIcons)];
switch (playbackStatus) {
case CogStatusPlaying:
badgeImage = [NSImage imageNamed:getBadgeName(@"playDockBadge", colorfulIcons)];
break;
case CogStatusPaused:
badgeImage = [NSImage imageNamed:getBadgeName(@"pauseDockBadge", colorfulIcons)];
break;
default:
badgeImage = [NSImage imageNamed:getBadgeName(@"stopDockBadge", colorfulIcons)];
break;
}
NSSize badgeSize = [badgeImage size];

View File

@ -3,6 +3,7 @@
#import <Cocoa/Cocoa.h>
#import "CogAudio/AudioPlayer.h"
#import "CogAudio/Status.h"
#import "TrackingSlider.h"
#import "AudioScrobbler.h"
@ -34,13 +35,13 @@ extern NSDictionary * makeRGInfo(PlaylistEntry *pe);
AudioPlayer *audioPlayer;
int playbackStatus;
CogStatus playbackStatus;
double position;
BOOL seekable;
BOOL fading;
}
@property int playbackStatus;
@property CogStatus playbackStatus;
- (IBAction)changeVolume:(id)sender;
- (IBAction)volumeDown:(id)sender;

View File

@ -44,7 +44,7 @@ NSString *CogPlaybackDidStopNotficiation = @"CogPlaybackDidStopNotficiation";
audioPlayer = [[AudioPlayer alloc] init];
[audioPlayer setDelegate:self];
[self setPlaybackStatus: kCogStatusStopped];
[self setPlaybackStatus: CogStatusStopped];
}
return self;
@ -73,7 +73,7 @@ NSString *CogPlaybackDidStopNotficiation = @"CogPlaybackDidStopNotficiation";
- (IBAction)playPauseResume:(id)sender
{
if (playbackStatus == kCogStatusStopped || playbackStatus == kCogStatusStopping)
if (playbackStatus == CogStatusStopped || playbackStatus == CogStatusStopping)
{
[self play:self];
}
@ -87,7 +87,7 @@ NSString *CogPlaybackDidStopNotficiation = @"CogPlaybackDidStopNotficiation";
- (IBAction)pauseResume:(id)sender
{
if (playbackStatus == kCogStatusPaused)
if (playbackStatus == CogStatusPaused)
[self resume:self];
else
[self pause:self];
@ -96,7 +96,7 @@ NSString *CogPlaybackDidStopNotficiation = @"CogPlaybackDidStopNotficiation";
- (IBAction)pause:(id)sender
{
[audioPlayer pause];
[self setPlaybackStatus: kCogStatusPaused];
[self setPlaybackStatus: CogStatusPaused];
[self sendMetaData];
}
@ -160,7 +160,7 @@ NSDictionary * makeRGInfo(PlaylistEntry *pe)
- (void)playEntry:(PlaylistEntry *)pe startPaused:(BOOL)paused
{
if (playbackStatus != kCogStatusStopped && playbackStatus != kCogStatusStopping)
if (playbackStatus != CogStatusStopped && playbackStatus != CogStatusStopping)
[self stop:self];
DLog(@"PLAYLIST CONTROLLER: %@", [playlistController class]);
@ -382,7 +382,7 @@ NSDictionary * makeRGInfo(PlaylistEntry *pe)
NSNumber *originalVolume = [NSNumber numberWithDouble: [audioPlayer volume]];
NSTimer *fadeTimer;
if (playbackStatus == kCogStatusPlaying) {
if (playbackStatus == CogStatusPlaying) {
fadeTimer = [NSTimer timerWithTimeInterval:time
target:self
selector:@selector(audioFadeDown:)
@ -551,7 +551,7 @@ NSDictionary * makeRGInfo(PlaylistEntry *pe)
- (void)audioPlayer:(AudioPlayer *)player didChangeStatus:(NSNumber *)s userInfo:(id)userInfo
{
int status = [s intValue];
if (status == kCogStatusStopped || status == kCogStatusPaused)
if (status == CogStatusStopped || status == CogStatusPaused)
{
if (positionTimer)
{
@ -559,7 +559,7 @@ NSDictionary * makeRGInfo(PlaylistEntry *pe)
positionTimer = NULL;
}
if (status == kCogStatusStopped)
if (status == CogStatusStopped)
{
[self setPosition:0];
[self setSeekable:NO]; // the player stopped, disable the slider
@ -571,7 +571,7 @@ NSDictionary * makeRGInfo(PlaylistEntry *pe)
[[NSNotificationCenter defaultCenter] postNotificationName:CogPlaybackDidPauseNotficiation object:nil];
}
}
else if (status == kCogStatusPlaying)
else if (status == CogStatusPlaying)
{
if (!positionTimer) {
positionTimer = [NSTimer timerWithTimeInterval:1.00 target:self selector:@selector(updatePosition:) userInfo:nil repeats:YES];
@ -581,7 +581,7 @@ NSDictionary * makeRGInfo(PlaylistEntry *pe)
[[NSNotificationCenter defaultCenter] postNotificationName:CogPlaybackDidResumeNotficiation object:nil];
}
if (status == kCogStatusStopped) {
if (status == CogStatusStopped) {
DLog(@"DONE!");
[playlistController setCurrentEntry:nil];
[self setSeekable:NO]; // the player stopped, disable the slider
@ -591,11 +591,11 @@ NSDictionary * makeRGInfo(PlaylistEntry *pe)
[self setSeekable:YES];
}
if (status == kCogStatusStopped) {
status = kCogStatusStopping;
if (status == CogStatusStopped) {
status = CogStatusStopping;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 3 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
if ([self playbackStatus] == kCogStatusStopping)
[self setPlaybackStatus:kCogStatusStopped];
if ([self playbackStatus] == CogStatusStopping)
[self setPlaybackStatus:CogStatusStopped];
});
}
@ -648,12 +648,17 @@ NSDictionary * makeRGInfo(PlaylistEntry *pe)
[songInfo setObject:[NSNumber numberWithFloat:[entry index]] forKey:MPMediaItemPropertyPersistentID];
}
if (playbackStatus == kCogStatusPlaying) {
defaultCenter.playbackState = MPNowPlayingPlaybackStatePlaying;
} else if (playbackStatus == kCogStatusPaused) {
defaultCenter.playbackState = MPNowPlayingPlaybackStatePaused;
} else {
defaultCenter.playbackState = MPNowPlayingPlaybackStateStopped;
switch (playbackStatus) {
case CogStatusPlaying:
defaultCenter.playbackState = MPNowPlayingPlaybackStatePlaying;
break;
case CogStatusPaused:
defaultCenter.playbackState = MPNowPlayingPlaybackStatePaused;
break;
default:
defaultCenter.playbackState = MPNowPlayingPlaybackStateStopped;
break;
}
[defaultCenter setNowPlayingInfo:songInfo];

View File

@ -107,21 +107,21 @@
[bufferChain launchThreads];
if (paused)
[self setPlaybackStatus:kCogStatusPaused waitUntilDone:YES];
[self setPlaybackStatus:CogStatusPaused waitUntilDone:YES];
}
- (void)stop
{
//Set shouldoContinue to NO on allll things
[self setShouldContinue:NO];
[self setPlaybackStatus:kCogStatusStopped waitUntilDone:YES];
[self setPlaybackStatus:CogStatusStopped waitUntilDone:YES];
}
- (void)pause
{
[output pause];
[self setPlaybackStatus:kCogStatusPaused waitUntilDone:YES];
[self setPlaybackStatus:CogStatusPaused waitUntilDone:YES];
}
- (void)resume
@ -135,7 +135,7 @@
[output resume];
[self setPlaybackStatus:kCogStatusPlaying waitUntilDone:YES];
[self setPlaybackStatus:CogStatusPlaying waitUntilDone:YES];
}
- (void)seekToTime:(double)time
@ -208,7 +208,7 @@
{
initialBufferFilled = YES;
if (outputLaunched == NO && startedPaused == NO) {
[self setPlaybackStatus:kCogStatusPlaying];
[self setPlaybackStatus:CogStatusPlaying];
[output launchThread];
outputLaunched = YES;
}

View File

@ -7,10 +7,11 @@
*
*/
enum
{
kCogStatusStopped = 0,
kCogStatusPaused,
kCogStatusPlaying,
kCogStatusStopping,
#import <Foundation/Foundation.h>
typedef NS_ENUM(NSInteger, CogStatus) {
CogStatusStopped = 0,
CogStatusPaused,
CogStatusPlaying,
CogStatusStopping,
};

View File

@ -64,7 +64,7 @@
8E6096C009F314CF006D8BD7 /* mpc_reader.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = mpc_reader.c; path = Files/src/mpc_reader.c; sourceTree = "<group>"; };
8E6096C109F314CF006D8BD7 /* requant.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = requant.c; path = Files/src/requant.c; sourceTree = "<group>"; };
8E6096C309F314CF006D8BD7 /* streaminfo.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = streaminfo.c; path = Files/src/streaminfo.c; sourceTree = "<group>"; };
8E6096C409F314CF006D8BD7 /* synth_filter.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = synth_filter.c; path = Files/src/synth_filter.c; sourceTree = "<group>"; };
8E6096C409F314CF006D8BD7 /* synth_filter.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = synth_filter.c; path = Files/src/synth_filter.c; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */

View File

@ -362,8 +362,8 @@
}
if (action == @selector(scrollToCurrentEntry:) &&
(([playbackController playbackStatus] == kCogStatusStopped) ||
([playbackController playbackStatus] == kCogStatusStopping)))
(([playbackController playbackStatus] == CogStatusStopped) ||
([playbackController playbackStatus] == CogStatusStopping)))
return NO;
return [super validateUserInterfaceItem:anItem];

View File

@ -17,17 +17,19 @@ class PlaybackStatusToHiddenTransformer : ValueTransformer {
}
override func transformedValue(_ value: Any?) -> Any? {
switch value {
case kCogStatusStopped as Int:
guard let intValue = value as? Int,
let status = CogStatus(rawValue: intValue) else {
return true;
}
switch status {
case .stopped:
return true
case kCogStatusPaused as Int,
kCogStatusPlaying as Int,
kCogStatusStopping as Int:
case .paused,
.playing,
.stopping:
return false
case .none:
return true
case .some(_):
return true
@unknown default:
return false;
}
}
}

View File

@ -45,7 +45,7 @@ static NSString *PlaybackButtonsPlaybackStatusObservationContext = @"PlaybackBut
NSImage *image = nil;
if (playbackStatus == kCogStatusPlaying) {
if (playbackStatus == CogStatusPlaying) {
image = [NSImage imageNamed:@"pauseTemplate"];
}
else {