Skip to content

Commit

Permalink
fixes in meta edit
Browse files Browse the repository at this point in the history
  • Loading branch information
tillt committed Mar 15, 2024
1 parent 767a278 commit dfb2207
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 53 deletions.
2 changes: 1 addition & 1 deletion PlayEm/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
<key>CFBundleShortVersionString</key>
<string>1.2</string>
<key>CFBundleVersion</key>
<string>4759</string>
<string>4785</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.music</string>
<key>LSMinimumSystemVersion</key>
Expand Down
2 changes: 1 addition & 1 deletion PlayEm/Views/TextViewWithPlaceholder.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ NS_ASSUME_NONNULL_BEGIN

@interface TextViewWithPlaceholder : NSTextView

@property (strong, nonatomic) NSAttributedString* placeholderAttributedString;
@property (strong, nonatomic, nullable) NSAttributedString* placeholderAttributedString;

@end

Expand Down
128 changes: 77 additions & 51 deletions PlayEm/Window & ViewControllers/InfoPanel.m
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ - (void)loadArtworkWithView:(NSView*)view
imageWidth);
_largeCoverView.wantsLayer = YES;
_largeCoverView.layer.borderColor = [NSColor separatorColor].CGColor;
_largeCoverView.layer.borderWidth = 1.0f;
_largeCoverView.layer.borderWidth = 2.0f;
_largeCoverView.layer.cornerRadius = 7.0f;
_largeCoverView.layer.masksToBounds = YES;
[view addSubview:_largeCoverView];
Expand Down Expand Up @@ -562,9 +562,10 @@ - (void)viewWillAppear
_titleTextField.stringValue = @"loading...";
_artistTextField.stringValue = @"loading...";
_albumTextField.stringValue = @"loading...";
// Lets confirm the metadata from the file itself - iTunes doesnt give us all the
// Lets confirm the metadata from the files - iTunes doesnt give us all the
// beauty we need and it may also rely on outdated informations. iTunes does the
// same when showing the info from a library entry.
// same when showing the info from a library entry - it reads up the latest info
// from the song file metadata.
dispatch_async(_metaIOQueue, ^{
NSError* error = nil;
NSMutableArray* patchedMetas = [NSMutableArray array];
Expand Down Expand Up @@ -606,18 +607,37 @@ - (void)viewWillDisappear
[[NSApplication sharedApplication] stopModal];
}

- (void)setMetas:(NSMutableArray<MediaMetaData*>*)metas
- (void)updateViewHeader:(NSMutableDictionary<NSString *,NSNumber *> *)deltaKeys occurances:(NSMutableDictionary<NSString *,NSMutableDictionary *> *)occurances
{
_metas = metas;

if (self.view == nil) {
return;
if (![deltaKeys[@"artwork"] boolValue] && _commonMeta.artwork != nil) {
_largeCoverView.image = [_commonMeta imageFromArtwork];
_smallCoverView.image = [_commonMeta imageFromArtwork];
} else {
_largeCoverView.image = [NSImage imageNamed:@"UnknownSong"];
_smallCoverView.image = [NSImage imageNamed:@"UnknownSong"];
}

if ([_metas count] == 0) {
return;
if ([_metas count] > 1) {
_titleTextField.stringValue = [NSString stringWithFormat:@"%ld artists selected", [[occurances[@"artist"] allKeys] count] ];
} else {
_titleTextField.stringValue = _commonMeta.title;
}

if ([_metas count] > 1) {
_artistTextField.stringValue = [NSString stringWithFormat:@"%ld albums selected", [[occurances[@"album"] allKeys] count]];
} else {
_artistTextField.stringValue = _commonMeta.artist;
}

if ([_metas count] == 1) {
_albumTextField.stringValue = _commonMeta.album;
} else {
_albumTextField.stringValue = [NSString stringWithFormat:@"%ld songs selected", [_metas count]];
}
}

- (void)updateControls
{
// Identify any meta that is common / not common in the given list.
NSMutableDictionary<NSString*,NSNumber*>* deltaKeys = [NSMutableDictionary dictionary];
//NSMutableDictionary<NSString*,NSNumber*>* commonKeys = [NSMutableDictionary dictionary];
Expand All @@ -636,62 +656,37 @@ - (void)setMetas:(NSMutableArray<MediaMetaData*>*)metas
if (dictionary == nil) {
dictionary = [NSMutableDictionary dictionary];
}

NSString* stringValue = [meta stringForKey:key];
dictionary[stringValue] = @"1";
dictionary[stringValue] = @YES;
occurances[key] = dictionary;
}
}

if (![deltaKeys[@"artwork"] boolValue] && _commonMeta.artwork != nil) {
_largeCoverView.image = [_commonMeta imageFromArtwork];
_smallCoverView.image = [_commonMeta imageFromArtwork];
} else {
_largeCoverView.image = [NSImage imageNamed:@"UnknownSong"];
_smallCoverView.image = [NSImage imageNamed:@"UnknownSong"];
}

if ([_metas count] > 1) {
_titleTextField.stringValue = [NSString stringWithFormat:@"%ld artists selected", [[occurances[@"artist"] allKeys] count] ];
} else {
_titleTextField.stringValue = _commonMeta.title;
}

if ([_metas count] > 1) {
_artistTextField.stringValue = [NSString stringWithFormat:@"%ld albums selected", [[occurances[@"album"] allKeys] count]];
} else {
_artistTextField.stringValue = _commonMeta.artist;
}

if ([_metas count] == 1) {
_albumTextField.stringValue = _commonMeta.album;
} else {
_albumTextField.stringValue = [NSString stringWithFormat:@"%ld songs selected", [_metas count]];
}

[self updateViewHeader:deltaKeys occurances:occurances];

if (![deltaKeys[@"lyrics"] boolValue] && _commonMeta.lyrics != nil) {
[_lyricsTextView setString:_commonMeta.lyrics];
} else {
[_lyricsTextView setString:@""];
if ([deltaKeys[@"lyrics"] boolValue]) {
NSColor* color = [NSColor secondaryLabelColor];
NSDictionary* attrs = @{
NSForegroundColorAttributeName: color,
NSForegroundColorAttributeName: [NSColor tertiaryLabelColor],
NSFontAttributeName: [NSFont systemFontOfSize:[NSFont systemFontSize]],
};
_lyricsTextView.placeholderAttributedString = [[NSAttributedString alloc] initWithString:kInfoTextMultipleValues
attributes:attrs];
}
}

self.deltaKeys = deltaKeys;

NSArray<NSString*>* keys = [_viewControls allKeys];

for (NSString* key in keys) {
id control = _viewControls[key];
if (control == nil) {
continue;
}

if ([deltaKeys objectForKey:key] == nil) {
// The meta data in question is common.
NSString* value = @"";
Expand All @@ -714,9 +709,8 @@ - (void)setMetas:(NSMutableArray<MediaMetaData*>*)metas
}
NSString* placeHolder = [_viewConfiguration[kInfoPageKeyDetails][key] objectForKey:@"placeholder"];
if (placeHolder != nil && [control respondsToSelector:@selector(cell)]) {
NSColor* color = [NSColor tertiaryLabelColor];
NSDictionary* attrs = @{
NSForegroundColorAttributeName: color,
NSForegroundColorAttributeName: [NSColor tertiaryLabelColor],
NSFontAttributeName: [NSFont systemFontOfSize:[NSFont systemFontSize]],
};
NSTextFieldCell* cell = [control cell];
Expand All @@ -725,7 +719,22 @@ - (void)setMetas:(NSMutableArray<MediaMetaData*>*)metas
}
}
}
self.deltaKeys = deltaKeys;
}

- (void)setMetas:(NSMutableArray<MediaMetaData*>*)metas
{
_metas = metas;

if (self.view == nil) {
return;
}

if ([_metas count] == 0) {
return;
}

[self updateControls];

self.mutatedKeys = [NSMutableDictionary dictionary];
}

Expand All @@ -744,21 +753,20 @@ - (void)okPressed:(id)sender
dataValue = self.deltaMeta.artwork;
NSLog(@"applying the meta image change");
} else {
NSString* stringValue = [self.deltaMeta stringForKey:key];
stringValue = [self.deltaMeta stringForKey:key];
NSLog(@"applying the meta change for %@ towards \"%@\"", key, stringValue);
}
for (MediaMetaData* meta in self.metas) {
MediaMetaData* patchedMeta = [patchedMetas objectForKey:meta.location];
if (patchedMeta == nil) {
patchedMeta = [meta copy];
}
if (stringValue != nil) {
[patchedMeta updateWithKey:key string:stringValue];
patchedMetas[meta.location] = patchedMeta;
}
if (dataValue != nil) {
patchedMeta.artwork = dataValue;
patchedMetas[meta.location] = patchedMeta;
} else {
[patchedMeta updateWithKey:key string:stringValue];
patchedMetas[meta.location] = patchedMeta;
}
}
}
Expand Down Expand Up @@ -823,17 +831,34 @@ - (void)controlTextDidEndEditing:(NSNotification *)notification
NSString* stringValue = [textField stringValue];

[self patchMetasAtKey:key string:stringValue];
textField.placeholderAttributedString = nil;
}

- (void)controlTextDidChange:(NSNotification *)notification
{
NSTextField* textField = [notification object];
// NSString *key = nil;
// for (NSString* k in [_viewControls allKeys]) {
// if ([_viewControls valueForKey:k] == textField) {
// key = k;
// break;
// }
// }
// NSAssert(key != nil, @"couldnt find the key for the control that triggered the notification");

textField.placeholderAttributedString = nil;
}

#pragma mark - NSTextView delegate

- (void)textDidEndEditing:(NSNotification *)notification
{
NSTextView* textView = [notification object];
TextViewWithPlaceholder* textView = [notification object];

NSString* stringValue = textView.string;

[self patchMetasAtKey:@"lyrics" string:stringValue];
//textView.placeholderAttributedString = nil;
}

#pragma mark - NSComboBox delegate
Expand Down Expand Up @@ -881,6 +906,7 @@ - (BOOL)performDragOperationWithURL:(NSURL*)url
if (data == nil) {
return NO;
}
// Handrolled `patchMetaAsKey:string:` for `artwork` data.
_deltaMeta.artwork = data;
_mutatedKeys[@"artwork"] = @YES;

Expand Down

0 comments on commit dfb2207

Please sign in to comment.