From 6f3e95b38759c72706e83ff140ae17667cdfad22 Mon Sep 17 00:00:00 2001 From: Kent Sutherland Date: Fri, 16 Sep 2005 16:50:58 +0000 Subject: [PATCH] Added a songEnabledAtIndex: method to ITMTRemote. The upcoming songs menu and status window now skip unchecked songs. Fixed some problems with the live updating time status window. --- ITMTRemote.h | 5 +++++ ITMTRemote.m | 5 +++++ MainController.h | 2 +- MainController.m | 51 +++++++++++++++++++++++++++++++++++++---------- MenuController.m | 21 +++++++++++++------ iTunesRemote.m | 9 +++++++++ libValidate.a | Bin 8032 -> 8056 bytes 7 files changed, 75 insertions(+), 18 deletions(-) diff --git a/ITMTRemote.h b/ITMTRemote.h index 6f10b7b..a99d52c 100755 --- a/ITMTRemote.h +++ b/ITMTRemote.h @@ -244,6 +244,11 @@ er's process managment. */ - (NSString *)songTitleAtIndex:(int)index; +/*! + * @method songEnabledAtIndex: + */ +- (BOOL)songEnabledAtIndex:(int)index; + /*! * @method currentAlbumTrackCount: */ diff --git a/ITMTRemote.m b/ITMTRemote.m index 75ed74f..febdda1 100755 --- a/ITMTRemote.m +++ b/ITMTRemote.m @@ -124,6 +124,11 @@ return nil; } +- (BOOL)songEnabledAtIndex:(int)index +{ + return nil; +} + - (int)currentAlbumTrackCount { return nil; diff --git a/MainController.h b/MainController.h index 5fb00ec..7ca0e08 100755 --- a/MainController.h +++ b/MainController.h @@ -43,7 +43,7 @@ NSUserDefaults *df; MTBlingController *bling; - NSTimer *registerTimer; + NSTimer *registerTimer, *_statusWindowUpdateTimer; BOOL timerUpdating, _checkingForServer, _popped, _open, _needsPolling; BOOL blinged; int _timeUpdateCount; //Keeps track of how many times the time has been updated in the info status window diff --git a/MainController.m b/MainController.m index 201edef..cfc9518 100755 --- a/MainController.m +++ b/MainController.m @@ -64,6 +64,8 @@ - (void)setLatestSongIdentifier:(NSString *)newIdentifier; - (void)applicationLaunched:(NSNotification *)note; - (void)applicationTerminated:(NSNotification *)note; + +- (void)invalidateStatusWindowUpdateTimer; @end static MainController *sharedController; @@ -85,6 +87,8 @@ static MainController *sharedController; if ( ( self = [super init] ) ) { sharedController = self; + _statusWindowUpdateTimer = nil; + remoteArray = [[NSMutableArray alloc] initWithCapacity:1]; [[PreferencesController sharedPrefs] setController:self]; statusWindowController = [StatusWindowController sharedController]; @@ -1081,7 +1085,8 @@ static MainController *sharedController; [self networkError:localException]; NS_ENDHANDLER _timeUpdateCount = 0; - [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(updateTime:) userInfo:nil repeats:YES]; + [self invalidateStatusWindowUpdateTimer]; + _statusWindowUpdateTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(updateTime:) userInfo:nil repeats:YES]; } if ( [df boolForKey:@"showTrackNumber"] ) { @@ -1143,18 +1148,29 @@ static MainController *sharedController; StatusWindow *sw = [StatusWindow sharedWindow]; _timeUpdateCount++; if (_timeUpdateCount < (int)[sw exitDelay] + (int)[[sw exitEffect] effectTime] + (int)[[sw entryEffect] effectTime]) { - NSString *time = nil; + NSString *time = nil, *length; NS_DURING - time = [NSString stringWithFormat:@"%@: %@ / %@", - NSLocalizedString(@"time", @"Time"), - [[self currentRemote] currentSongElapsed], - [[self currentRemote] currentSongLength]]; - [[StatusWindowController sharedController] updateTime:time]; + length = [[self currentRemote] currentSongLength]; + if (length) { + time = [NSString stringWithFormat:@"%@: %@ / %@", + NSLocalizedString(@"time", @"Time"), + [[self currentRemote] currentSongElapsed], + length]; + [[StatusWindowController sharedController] updateTime:time]; + } NS_HANDLER [self networkError:localException]; NS_ENDHANDLER } else { - [timer invalidate]; + [self invalidateStatusWindowUpdateTimer]; + } +} + +- (void)invalidateStatusWindowUpdateTimer +{ + if (_statusWindowUpdateTimer) { + [_statusWindowUpdateTimer invalidate]; + _statusWindowUpdateTimer = nil; } } @@ -1167,6 +1183,8 @@ static MainController *sharedController; [self networkError:localException]; NS_ENDHANDLER + [self invalidateStatusWindowUpdateTimer]; + ITDebugLog(@"Showing upcoming songs status window."); NS_DURING if (numSongs > 0) { @@ -1175,10 +1193,12 @@ static MainController *sharedController; int curTrack = [[self currentRemote] currentSongIndex]; int i; - for (i = curTrack + 1; i <= curTrack + numSongsInAdvance; i++) { - if (i <= numSongs) { + for (i = curTrack + 1; i <= curTrack + numSongsInAdvance && i <= numSongs; i++) { + if ([[self currentRemote] songEnabledAtIndex:i]) { [songList addObject:[[self currentRemote] songTitleAtIndex:i]]; - } + } else { + numSongsInAdvance++; + } } if ([songList count] == 0) { @@ -1223,6 +1243,7 @@ static MainController *sharedController; [[self currentRemote] setVolume:volume]; // Show volume status window + [self invalidateStatusWindowUpdateTimer]; [statusWindowController showVolumeWindowWithLevel:dispVol]; NS_HANDLER [self networkError:localException]; @@ -1247,6 +1268,7 @@ static MainController *sharedController; [[self currentRemote] setVolume:volume]; //Show volume status window + [self invalidateStatusWindowUpdateTimer]; [statusWindowController showVolumeWindowWithLevel:dispVol]; NS_HANDLER [self networkError:localException]; @@ -1272,6 +1294,7 @@ static MainController *sharedController; [[self currentRemote] setCurrentSongRating:rating]; //Show rating status window + [self invalidateStatusWindowUpdateTimer]; [statusWindowController showRatingWindowWithRating:rating]; NS_HANDLER [self networkError:localException]; @@ -1297,6 +1320,7 @@ static MainController *sharedController; [[self currentRemote] setCurrentSongRating:rating]; //Show rating status window + [self invalidateStatusWindowUpdateTimer]; [statusWindowController showRatingWindowWithRating:rating]; NS_HANDLER [self networkError:localException]; @@ -1330,6 +1354,7 @@ static MainController *sharedController; [[self currentRemote] setRepeatMode:repeatMode]; //Show loop status window + [self invalidateStatusWindowUpdateTimer]; [statusWindowController showRepeatWindowWithMode:repeatMode]; NS_HANDLER [self networkError:localException]; @@ -1344,6 +1369,7 @@ static MainController *sharedController; [[self currentRemote] setShuffleEnabled:newShuffleEnabled]; //Show shuffle status window ITDebugLog(@"Setting shuffle mode to %i", newShuffleEnabled); + [self invalidateStatusWindowUpdateTimer]; [statusWindowController showShuffleWindow:newShuffleEnabled]; NS_HANDLER [self networkError:localException]; @@ -1358,6 +1384,7 @@ static MainController *sharedController; ITDebugLog(@"Toggling shufflability."); [[self currentRemote] setCurrentSongShufflable:flag]; //Show song shufflability status window + [self invalidateStatusWindowUpdateTimer]; [statusWindowController showSongShufflabilityWindow:flag]; NS_HANDLER [self networkError:localException]; @@ -1499,6 +1526,7 @@ static MainController *sharedController; - (void)remoteServerFound:(id)sender { if (![networkController isServerOn] && ![networkController isConnectedToServer]) { + [self invalidateStatusWindowUpdateTimer]; [[StatusWindowController sharedController] showReconnectQueryWindow]; } } @@ -1515,6 +1543,7 @@ static MainController *sharedController; ITDebugLog(@"Remote exception thrown: %@: %@", [exception name], [exception reason]); if ( ((exception == nil) || [[exception name] isEqualToString:NSPortTimeoutException]) && [networkController isConnectedToServer]) { //NSRunCriticalAlertPanel(@"Remote MenuTunes Disconnected", @"The MenuTunes server you were connected to stopped responding or quit. MenuTunes will revert back to the local player.", @"OK", nil, nil); + [self invalidateStatusWindowUpdateTimer]; [[StatusWindowController sharedController] showNetworkErrorQueryWindow]; if ([self disconnectFromServer]) { [[PreferencesController sharedPrefs] resetRemotePlayerTextFields]; diff --git a/MenuController.m b/MenuController.m index 7c418be..36b112b 100755 --- a/MenuController.m +++ b/MenuController.m @@ -63,7 +63,7 @@ NS_HANDLER [[MainController sharedController] networkError:localException]; NS_ENDHANDLER - + ITDebugLog(@"Reset menu if required."); //Kill the old submenu items @@ -444,7 +444,7 @@ keyEquivalent:@""]; [tempItem setSubmenu:_upcomingSongsMenu]; [tempItem setTag:2]; - if (_playingRadio || !_currentPlaylist) { + if (_playingRadio || _currentPlaylist < 1) { [tempItem setEnabled:NO]; } } else if ([nextObject isEqualToString:@"artists"]) { @@ -609,8 +609,17 @@ if (_currentPlaylist && !_playingRadio) { if (numSongs > 0) { int i; - for (i = _currentTrack + 1; i <= _currentTrack + numSongsInAdvance; i++) { - if (i <= numSongs) { + for (i = _currentTrack + 1; i <= _currentTrack + numSongsInAdvance && i <= numSongs; i++) { + BOOL enabled; + + //Check if the song at this index is enabled for playback. If it isn't, skip over it + NS_DURING + enabled = [[[MainController sharedController] currentRemote] songEnabledAtIndex:i]; + NS_HANDLER + [[MainController sharedController] networkError:localException]; + NS_ENDHANDLER + + if (enabled) { NSString *curSong = nil; NS_DURING curSong = [[[MainController sharedController] currentRemote] songTitleAtIndex:i]; @@ -623,8 +632,8 @@ [songItem setTag:i]; [songItem setTarget:self]; } else { - break; - } + numSongsInAdvance++; + } } } diff --git a/iTunesRemote.m b/iTunesRemote.m index c537975..b5365b2 100755 --- a/iTunesRemote.m +++ b/iTunesRemote.m @@ -525,6 +525,15 @@ return ( ([temp1 length]) ? temp1 : nil ) ; } +- (BOOL)songEnabledAtIndex:(int)index +{ + BOOL temp1; + ITDebugLog(@"Getting song enabled at index %i.", index); + temp1 = [ITSendAEWithString([NSString stringWithFormat:@"'----':obj { form:'prop', want:type('prop'), seld:type('enbl'), from:obj { form:'indx', want:type('cTrk'), seld:long(%lu), from:obj { form:'prop', want:type('prop'), seld:type('pPla'), from:'null'() } } }", index], 'core', 'getd', &savedPSN) booleanValue]; + ITDebugLog(@"Getting song enabled at index %i done.", index); + return temp1; +} + - (int)currentAlbumTrackCount { int temp1; diff --git a/libValidate.a b/libValidate.a index 8f2ca1a7273eccbd0cda504592c82b35f2020870..aa76b861879a654d8ccbbda9189a59c9a37c6532 100755 GIT binary patch delta 308 zcmaE0_ruOw(I&AdIm3=i*-+oeKmh>^4UNn!EG&)9O%xPN4Ge)25Yo`Vz{~_BW^Odm zTBe=>2sQxm4F(3L1_lO3Z73}ap&6{8bP1GBgwh&N+6_u`L1{@SeI82xgwjW$^am)t z3qqTL><3%y1eJ(@@|mEtKU91Llx_#nn>iRu74Ge)25E3YCW?};5nORJ< zmZ{&sz`$^Wfq|)pfq_vQN()111}i9C0;Ln7v<8%RgVJ13S`td1htfZx^ie4N0ZQ+J z(m<