X-Git-Url: http://git.ithinksw.org/MenuTunes.git/blobdiff_plain/865eb081d76064bc6ec16c44f6ac976a9b1a62b3..780eb8412d27bba1eaaf0a03ab74f90c62f28253:/MainController.m diff --git a/MainController.m b/MainController.m index b39d34d..4cfd11c 100755 --- a/MainController.m +++ b/MainController.m @@ -633,8 +633,8 @@ static MainController *sharedController; [timer invalidate]; if ([df boolForKey:@"audioscrobblerEnabled"]) { NS_DURING - int elapsed = [[self currentRemote] currentSongPlayed]; - if ((abs(elapsed - _audioscrobblerInterval) < 5) && ([[self currentRemote] playerPlayingState] == ITMTRemotePlayerPlaying)) { + int elapsed = [[self currentRemote] currentSongPlayed], length = [[self currentRemote] currentSongDuration], requiredInterval = ((length / 2 < 240) ? length / 2 : 240); + if ((abs(elapsed - requiredInterval) < 5) && ([[self currentRemote] playerPlayingState] == ITMTRemotePlayerPlaying)) { NSString *title = [[self currentRemote] currentSongTitle], *artist = [[self currentRemote] currentSongArtist]; if (title && artist) { ITDebugLog(@"Audioscrobbler: Submitting current track"); @@ -643,11 +643,11 @@ static MainController *sharedController; album:[[self currentRemote] currentSongAlbum] length:[[self currentRemote] currentSongDuration]]; } - } else if (_audioscrobblerInterval - elapsed > 0) { - ITDebugLog(@"Audioscrobbler: Creating a new timer that will run in %i seconds", _audioscrobblerInterval - elapsed); - _audioscrobblerInterval -= elapsed; + } else if (requiredInterval - elapsed > 0) { + _audioscrobblerInterval = requiredInterval - elapsed; [_audioscrobblerTimer release]; - _audioscrobblerTimer = [[NSTimer alloc] initWithFireDate:[NSDate dateWithTimeIntervalSinceNow:_audioscrobblerInterval] interval:nil target:self selector:@selector(submitAudioscrobblerTrack:) userInfo:nil repeats:NO]; + ITDebugLog(@"Audioscrobbler: Creating a new timer that will run in %i seconds", _audioscrobblerInterval); + _audioscrobblerTimer = [[NSTimer alloc] initWithFireDate:[NSDate dateWithTimeIntervalSinceNow:_audioscrobblerInterval] interval:1.0 target:self selector:@selector(submitAudioscrobblerTrack:) userInfo:nil repeats:NO]; [[NSRunLoop currentRunLoop] addTimer:_audioscrobblerTimer forMode:NSDefaultRunLoopMode]; } NS_HANDLER @@ -979,6 +979,16 @@ static MainController *sharedController; [[ITHotKeyCenter sharedCenter] registerHotKey:[hotKey autorelease]]; } + if ([df objectForKey:@"AlbumArt"] != nil) { + ITDebugLog(@"Setting up album art hot key."); + hotKey = [[ITHotKey alloc] init]; + [hotKey setName:@"AlbumArt"]; + [hotKey setKeyCombo:[ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"AlbumArt"]]]; + [hotKey setTarget:self]; + [hotKey setAction:@selector(showCurrentAlbumArtHotKey)]; + [[ITHotKeyCenter sharedCenter] registerHotKey:[hotKey autorelease]]; + } + if ([df objectForKey:@"UpcomingSongs"] != nil) { ITDebugLog(@"Setting up upcoming songs hot key."); hotKey = [[ITHotKey alloc] init]; @@ -1097,6 +1107,57 @@ static MainController *sharedController; [self showCurrentTrackInfo]; } +- (void)showCurrentAlbumArtHotKey +{ + //If we're already visible and the setting says so, vanish instead of displaying again. + if ([df boolForKey:@"ToggleTrackInfoWithHotKey"] && [statusWindowController currentStatusWindowType] == StatusWindowAlbumArtType && [[StatusWindow sharedWindow] visibilityState] == ITWindowVisibleState) { + ITDebugLog(@"Art window is already visible, hiding track window."); + [[StatusWindow sharedWindow] vanish:nil]; + return; + } + [self showCurrentAlbumArt]; +} + +- (void)showCurrentAlbumArt +{ + NSImage *art = nil; + NS_DURING + art = [[self currentRemote] currentSongAlbumArt]; + NS_HANDLER + [self networkError:localException]; + NS_ENDHANDLER + + if (art) { + NSSize oldSize = [art size], newSize; + if (oldSize.width > 300 && oldSize.height > 300) { + if (oldSize.width > oldSize.height) { + newSize = NSMakeSize(300, oldSize.height * (300.0f / oldSize.width)); + } else { + newSize = NSMakeSize(oldSize.width * (300.0f / oldSize.height), 300); + } + } else { + newSize = oldSize; + } + + art = [[[[NSImage alloc] initWithData:[art TIFFRepresentation]] autorelease] imageScaledSmoothlyToSize:newSize]; + + [statusWindowController showAlbumArtWindowWithImage:art]; + } else { + NSString *string = nil; + NS_DURING + if ([[self currentRemote] currentSongTitle]) { + string = NSLocalizedString(@"noAlbumArt", @"No art for current song."); + } else { + string = NSLocalizedString(@"noSongPlaying", @"No song is playing."); + } + NS_HANDLER + [self networkError:localException]; + NS_ENDHANDLER + //Show the no song playing window if there is no album art or no track is playing + [statusWindowController showAlbumArtWindowWithErrorText:string]; + } +} + - (void)showCurrentTrackInfo { ITMTRemotePlayerSource source = 0; @@ -1231,7 +1292,7 @@ static MainController *sharedController; { StatusWindow *sw = (StatusWindow *)[StatusWindow sharedWindow]; _timeUpdateCount++; - if ([sw visibilityState] != ITWindowHiddenState) { + if ([statusWindowController currentStatusWindowType] == StatusWindowTrackInfoType && [sw visibilityState] != ITWindowHiddenState) { NSString *time = nil, *length; NS_DURING length = [[self currentRemote] currentSongLength];