Skip to content

Commit

Permalink
Add negative value support for PPTimeFormatter.
Browse files Browse the repository at this point in the history
Remove PPEscapeValue.
Better description getters for CurrentlyPlayingIndex.
  • Loading branch information
MaddTheSane committed Nov 13, 2016
1 parent f0f59fc commit 7dd0c10
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 12 deletions.
11 changes: 9 additions & 2 deletions PlayerPRO Player/CurrentlyPlayingIndex.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,17 @@ struct CurrentlyPlayingIndex: CustomDebugStringConvertible, CustomStringConverti
var playbackURL: URL? = nil

var description: String {
return "Index: \(index) URL: \(playbackURL!.relativePath)"
return "Index: \(index) URL: \(playbackURL?.relativePath ?? "none")"
}

var debugDescription: String {
return "Index: \(index) URL: '\(playbackURL)' URL Path: \(playbackURL!.path)"
let urlDes: String
if let playURL = playbackURL {
urlDes = String(describing: playURL)
} else {
urlDes = "none"
}

return "Index: \(index) URL: '\(urlDes)' URL Path: \(playbackURL?.path ?? "none")"
}
}
7 changes: 5 additions & 2 deletions PlayerPRO Player/PlayerAppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ class PlayerAppDelegate: NSObject, NSApplicationDelegate, NSTableViewDelegate, N
}

func addMusicToMusicList(_ theURL: URL, loadIfPreferencesAllow load: Bool = true) {
// clear sort descriptors, so added files don't get sorted incorrectly.
tableView.sortDescriptors = []
willChangeValue(forKey: kMusicListKVO)
let okayMusic = musicList.addMusicURL(theURL, force: false)
Expand All @@ -261,8 +262,10 @@ class PlayerAppDelegate: NSObject, NSApplicationDelegate, NSTableViewDelegate, N
similarAlert.informativeText = "There is already a tracker file that points to the added file. Do you still wish to add it?";
similarAlert.addButton(withTitle: "Add")

let cancelButton = similarAlert.addButton(withTitle: "Cancel")
cancelButton.keyEquivalent = PPEscapeValue;
do {
let cancelButton = similarAlert.addButton(withTitle: "Cancel")
cancelButton.keyEquivalent = "\u{1b}" //escape
}

similarAlert.addButton(withTitle: "Load Existing")

Expand Down
16 changes: 9 additions & 7 deletions Shared/PPTimeFormatter.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,25 @@
//
//

#include <stdio.h>
#import "PPTimeFormatter.h"
#import <Foundation/Foundation.h>
#import <stdio.h>

@implementation PPTimeFormatter

- (NSString *)stringForObjectValue:(id)obj
{
if ([obj isKindOfClass:[NSNumber class]] ) {
NSInteger theVal = [obj integerValue];
int seconds = (theVal/60) % 60;
int minutes = (theVal/(60 * 60)) % 60;
if (theVal / (60*60*60) > 0) {
int hours = (int)(theVal/(60 * 60 * 60));
return [NSString stringWithFormat:@"%d:%02d:%02d", hours, minutes, seconds];
NSInteger fullVal = labs(theVal);
BOOL isNeg = theVal < 0;
int seconds = (fullVal/60) % 60;
int minutes = (fullVal/(60 * 60)) % 60;
if (fullVal / (60*60*60) > 0) {
int hours = (int)(fullVal/(60 * 60 * 60));
return [NSString stringWithFormat:@"%s%d:%02d:%02d", isNeg ? "-": "", hours, minutes, seconds];
} else {
return [NSString stringWithFormat:@"%d:%02d", minutes, seconds];
return [NSString stringWithFormat:@"%s%d:%02d", isNeg ? "-": "", minutes, seconds];
}
} else return nil;
}
Expand Down
1 change: 0 additions & 1 deletion Shared/UserDefaultKeys.h
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,6 @@ extern NSString * const PPCETrackHeight;
#pragma mark Misc./other
extern NSString * const PPDoubleDash;
extern NSString * const kMusicListKVO;
#define PPEscapeValue @"\e"

NS_ASSUME_NONNULL_END

Expand Down

0 comments on commit 7dd0c10

Please sign in to comment.