Added a songEnabledAtIndex: method to ITMTRemote.
authorKent Sutherland <ksuther@ithinksw.com>
Fri, 16 Sep 2005 16:50:58 +0000 (16:50 +0000)
committerKent Sutherland <ksuther@ithinksw.com>
Fri, 16 Sep 2005 16:50:58 +0000 (16:50 +0000)
The upcoming songs menu and status window now skip unchecked songs.
Fixed some problems with the live updating time status window.

ITMTRemote.h
ITMTRemote.m
MainController.h
MainController.m
MenuController.m
iTunesRemote.m
libValidate.a

index 6f10b7b..a99d52c 100755 (executable)
@@ -244,6 +244,11 @@ er's process managment.
  */
 - (NSString *)songTitleAtIndex:(int)index;
 
  */
 - (NSString *)songTitleAtIndex:(int)index;
 
+/*!
+ * @method songEnabledAtIndex:
+ */
+- (BOOL)songEnabledAtIndex:(int)index;
+
 /*!
  * @method currentAlbumTrackCount:
  */
 /*!
  * @method currentAlbumTrackCount:
  */
index 75ed74f..febdda1 100755 (executable)
     return nil;
 }
 
     return nil;
 }
 
+- (BOOL)songEnabledAtIndex:(int)index
+{
+       return nil;
+}
+
 - (int)currentAlbumTrackCount
 {
     return nil;
 - (int)currentAlbumTrackCount
 {
     return nil;
index 5fb00ec..7ca0e08 100755 (executable)
@@ -43,7 +43,7 @@
     NSUserDefaults *df;
     
     MTBlingController *bling;
     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
     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
index 201edef..cfc9518 100755 (executable)
@@ -64,6 +64,8 @@
 - (void)setLatestSongIdentifier:(NSString *)newIdentifier;
 - (void)applicationLaunched:(NSNotification *)note;
 - (void)applicationTerminated:(NSNotification *)note;
 - (void)setLatestSongIdentifier:(NSString *)newIdentifier;
 - (void)applicationLaunched:(NSNotification *)note;
 - (void)applicationTerminated:(NSNotification *)note;
+
+- (void)invalidateStatusWindowUpdateTimer;
 @end
 
 static MainController *sharedController;
 @end
 
 static MainController *sharedController;
@@ -85,6 +87,8 @@ static MainController *sharedController;
     if ( ( self = [super init] ) ) {
         sharedController = self;
         
     if ( ( self = [super init] ) ) {
         sharedController = self;
         
+               _statusWindowUpdateTimer = nil;
+               
         remoteArray = [[NSMutableArray alloc] initWithCapacity:1];
         [[PreferencesController sharedPrefs] setController:self];
         statusWindowController = [StatusWindowController sharedController];
         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;
                 [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"] ) {
         }
 
         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]) {
        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
                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 {
                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 networkError:localException];
     NS_ENDHANDLER
     
+       [self invalidateStatusWindowUpdateTimer];
+       
     ITDebugLog(@"Showing upcoming songs status window.");
     NS_DURING
         if (numSongs > 0) {
     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;
     
             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]];
                     [songList addObject:[[self currentRemote] songTitleAtIndex:i]];
-                }
+                } else {
+                                       numSongsInAdvance++;
+                               }
             }
             
             if ([songList count] == 0) {
             }
             
             if ([songList count] == 0) {
@@ -1223,6 +1243,7 @@ static MainController *sharedController;
         [[self currentRemote] setVolume:volume];
     
         // Show volume status window
         [[self currentRemote] setVolume:volume];
     
         // Show volume status window
+               [self invalidateStatusWindowUpdateTimer];
         [statusWindowController showVolumeWindowWithLevel:dispVol];
     NS_HANDLER
         [self networkError:localException];
         [statusWindowController showVolumeWindowWithLevel:dispVol];
     NS_HANDLER
         [self networkError:localException];
@@ -1247,6 +1268,7 @@ static MainController *sharedController;
         [[self currentRemote] setVolume:volume];
         
         //Show volume status window
         [[self currentRemote] setVolume:volume];
         
         //Show volume status window
+               [self invalidateStatusWindowUpdateTimer];
         [statusWindowController showVolumeWindowWithLevel:dispVol];
     NS_HANDLER
         [self networkError:localException];
         [statusWindowController showVolumeWindowWithLevel:dispVol];
     NS_HANDLER
         [self networkError:localException];
@@ -1272,6 +1294,7 @@ static MainController *sharedController;
         [[self currentRemote] setCurrentSongRating:rating];
         
         //Show rating status window
         [[self currentRemote] setCurrentSongRating:rating];
         
         //Show rating status window
+               [self invalidateStatusWindowUpdateTimer];
         [statusWindowController showRatingWindowWithRating:rating];
     NS_HANDLER
         [self networkError:localException];
         [statusWindowController showRatingWindowWithRating:rating];
     NS_HANDLER
         [self networkError:localException];
@@ -1297,6 +1320,7 @@ static MainController *sharedController;
         [[self currentRemote] setCurrentSongRating:rating];
         
         //Show rating status window
         [[self currentRemote] setCurrentSongRating:rating];
         
         //Show rating status window
+               [self invalidateStatusWindowUpdateTimer];
         [statusWindowController showRatingWindowWithRating:rating];
     NS_HANDLER
         [self networkError:localException];
         [statusWindowController showRatingWindowWithRating:rating];
     NS_HANDLER
         [self networkError:localException];
@@ -1330,6 +1354,7 @@ static MainController *sharedController;
         [[self currentRemote] setRepeatMode:repeatMode];
         
         //Show loop status window
         [[self currentRemote] setRepeatMode:repeatMode];
         
         //Show loop status window
+               [self invalidateStatusWindowUpdateTimer];
         [statusWindowController showRepeatWindowWithMode:repeatMode];
     NS_HANDLER
         [self networkError:localException];
         [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 currentRemote] setShuffleEnabled:newShuffleEnabled];
         //Show shuffle status window
         ITDebugLog(@"Setting shuffle mode to %i", newShuffleEnabled);
+               [self invalidateStatusWindowUpdateTimer];
         [statusWindowController showShuffleWindow:newShuffleEnabled];
     NS_HANDLER
         [self networkError:localException];
         [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
                        ITDebugLog(@"Toggling shufflability.");
                        [[self currentRemote] setCurrentSongShufflable:flag];
                        //Show song shufflability status window
+                       [self invalidateStatusWindowUpdateTimer];
                        [statusWindowController showSongShufflabilityWindow:flag];
                NS_HANDLER
                        [self networkError:localException];
                        [statusWindowController showSongShufflabilityWindow:flag];
                NS_HANDLER
                        [self networkError:localException];
@@ -1499,6 +1526,7 @@ static MainController *sharedController;
 - (void)remoteServerFound:(id)sender
 {
     if (![networkController isServerOn] && ![networkController isConnectedToServer]) {
 - (void)remoteServerFound:(id)sender
 {
     if (![networkController isServerOn] && ![networkController isConnectedToServer]) {
+               [self invalidateStatusWindowUpdateTimer];
         [[StatusWindowController sharedController] showReconnectQueryWindow];
     }
 }
         [[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);
     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];
         [[StatusWindowController sharedController] showNetworkErrorQueryWindow];
         if ([self disconnectFromServer]) {
             [[PreferencesController sharedPrefs] resetRemotePlayerTextFields];
index 7c418be..36b112b 100755 (executable)
@@ -63,7 +63,7 @@
     NS_HANDLER
         [[MainController sharedController] networkError:localException];
     NS_ENDHANDLER
     NS_HANDLER
         [[MainController sharedController] networkError:localException];
     NS_ENDHANDLER
-    
+       
     ITDebugLog(@"Reset menu if required.");
     
     //Kill the old submenu items
     ITDebugLog(@"Reset menu if required.");
     
     //Kill the old submenu items
                     keyEquivalent:@""];
             [tempItem setSubmenu:_upcomingSongsMenu];
             [tempItem setTag:2];
                     keyEquivalent:@""];
             [tempItem setSubmenu:_upcomingSongsMenu];
             [tempItem setTag:2];
-            if (_playingRadio || !_currentPlaylist) {
+            if (_playingRadio || _currentPlaylist < 1) {
                 [tempItem setEnabled:NO];
             }
         } else if ([nextObject isEqualToString:@"artists"]) {
                 [tempItem setEnabled:NO];
             }
         } else if ([nextObject isEqualToString:@"artists"]) {
     if (_currentPlaylist && !_playingRadio) {
         if (numSongs > 0) {
             int i;
     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];
                     NSString *curSong = nil;
                     NS_DURING
                         curSong = [[[MainController sharedController] currentRemote] songTitleAtIndex:i];
                     [songItem setTag:i];
                     [songItem setTarget:self];
                 } else {
                     [songItem setTag:i];
                     [songItem setTarget:self];
                 } else {
-                    break;
-                }
+                                       numSongsInAdvance++;
+                               }
             }
         }
         
             }
         }
         
index c537975..b5365b2 100755 (executable)
     return ( ([temp1 length]) ? temp1 : nil ) ;
 }
 
     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;
 - (int)currentAlbumTrackCount
 {
     int temp1;
index 8f2ca1a..aa76b86 100755 (executable)
Binary files a/libValidate.a and b/libValidate.a differ