Fixed the shuffle and loop methods.
[MenuTunes.git] / iTunesRemote.m
index a741164..2595861 100755 (executable)
 {
     ITDebugLog(@"iTunesRemote begun");
     savedPSN = [self iTunesPSN];
+       [[NSDistributedNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationHandler:) name:@"com.apple.iTunes.playerInfo" object:@"com.apple.iTunes.player"];
     return YES;
 }
 
 - (BOOL)halt
 {
     ITDebugLog(@"iTunesRemote halted");
+       [[NSDistributedNotificationCenter defaultCenter] removeObserver:self];
     return YES;
 }
 
 - (BOOL)shuffleEnabled
 {
     ITDebugLog(@"Getting shuffle enabled status.");
-    BOOL final;
-    int result = (int)[ITSendAEWithString(@"'----':obj { form:'prop', want:type('prop'), seld:type('pShf'), from:obj { form:'prop', want:type('pPla'), seld:type('pEQP'), from:'null'() } }", 'core', 'getd', &savedPSN) int32Value];
-    if (result != 0) {
-        final = YES;
-    } else {
-        final = NO;
-    }
+       int result = (int)[ITSendAEWithString(@"'----':obj { form:'prop', want:type('prop'), seld:type('pShf'), from:obj { form:'prop', want:type('prop'), seld:type('pPla'), from:'null'() } }", 'core', 'getd', &savedPSN) int32Value];
     ITDebugLog(@"Getting shuffle enabled status done.");
-    return final;
+    return (result != 0);
 }
 
 - (BOOL)setShuffleEnabled:(BOOL)enabled
 {
     FourCharCode m00f = 0;
     int result = 0;
-    m00f = (FourCharCode)[ITSendAEWithString(@"'----':obj { form:'prop', want:type('prop'), seld:type('pRpt'), from:obj { form:'prop', want:type('pPla'), seld:type('pEQP'), from:'null'() } }", 'core', 'getd', &savedPSN) int32Value];
+    m00f = (FourCharCode)[ITSendAEWithString(@"'----':obj { form:'prop', want:type('prop'), seld:type('pRpt'), from:obj { form:'prop', want:type('prop'), seld:type('pPla'), from:'null'() } }", 'core', 'getd', &savedPSN) int32Value];
     ITDebugLog(@"Getting repeat mode.");
     switch (m00f)
     {
        return ([ITSendAEWithString(@"'----':obj { form:'prop', want:type('prop'), seld:type('pcls'), from:obj { form:'prop', want:type('prop'), seld:type('pTrk'), from:'null'() } }", 'core', 'getd', &savedPSN) int32Value] != 'prop');
 }
 
+- (void)notificationHandler:(NSNotification *)note
+{
+       ITDebugLog(@"Received notification: %@", note);
+       [[NSNotificationCenter defaultCenter] postNotificationName:@"ITMTTrackChanged" object:self userInfo:[note userInfo]];
+       ITDebugLog(@"Handled notification.");
+}
+
 - (ProcessSerialNumber)iTunesPSN
 {
     /*NSArray *apps = [[NSWorkspace sharedWorkspace] launchedApplications];