Permalink
Browse files

New Growl notifications, and hooked them up

iTunes scripting bridge to get album art and playerPosition
  • Loading branch information...
mxcl committed May 4, 2009
1 parent 3bd1510 commit 39e4d2bffd0a7e96959b7b912462f1f6131d6bbe
@@ -9,6 +9,9 @@
/* Begin PBXBuildFile section */
1DDD58160DA1D0A300B32029 /* main.xib in Resources */ = {isa = PBXBuildFile; fileRef = 1DDD58140DA1D0A300B32029 /* main.xib */; };
63024AEC0F9640A8001B8E9B /* Mediator.m in Sources */ = {isa = PBXBuildFile; fileRef = 63024AEB0F9640A8001B8E9B /* Mediator.m */; };
+ 637F066B0FADD0F7006EE129 /* Preferences.xib in Resources */ = {isa = PBXBuildFile; fileRef = 637F066A0FADD0F7006EE129 /* Preferences.xib */; };
+ 637F066E0FADD118006EE129 /* PreferencesWindowController.m in Sources */ = {isa = PBXBuildFile; fileRef = 637F066D0FADD118006EE129 /* PreferencesWindowController.m */; };
+ 637F074E0FAF20AD006EE129 /* ScriptingBridge.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 637F074D0FAF20AD006EE129 /* ScriptingBridge.framework */; };
63906F0C0F9DE71E00797A14 /* ShareWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = 63906F0B0F9DE71E00797A14 /* ShareWindow.xib */; };
63B5AA390F93565500DC9D8C /* md5.c in Sources */ = {isa = PBXBuildFile; fileRef = 63B5AA380F93565500DC9D8C /* md5.c */; };
63B5AA5E0F9356DD00DC9D8C /* Audioscrobbler.sdef in Resources */ = {isa = PBXBuildFile; fileRef = 63B5AA5D0F9356DD00DC9D8C /* Audioscrobbler.sdef */; };
@@ -68,6 +71,11 @@
32CA4F630368D1EE00C91783 /* pc.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = pc.h; sourceTree = "<group>"; };
63024AE90F964063001B8E9B /* Mediator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Mediator.h; sourceTree = "<group>"; };
63024AEB0F9640A8001B8E9B /* Mediator.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Mediator.m; sourceTree = "<group>"; };
+ 637F066A0FADD0F7006EE129 /* Preferences.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = Preferences.xib; sourceTree = "<group>"; };
+ 637F066C0FADD118006EE129 /* PreferencesWindowController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PreferencesWindowController.h; sourceTree = "<group>"; };
+ 637F066D0FADD118006EE129 /* PreferencesWindowController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PreferencesWindowController.m; sourceTree = "<group>"; };
+ 637F07050FAF180F006EE129 /* iTunes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = iTunes.h; sourceTree = "<group>"; };
+ 637F074D0FAF20AD006EE129 /* ScriptingBridge.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = ScriptingBridge.framework; path = /System/Library/Frameworks/ScriptingBridge.framework; sourceTree = "<absolute>"; };
63906F0B0F9DE71E00797A14 /* ShareWindow.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = ShareWindow.xib; sourceTree = "<group>"; };
6393C3C70F93870400286602 /* iTunes Plug-in.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = "iTunes Plug-in.xcodeproj"; path = "../iTunes/iTunes Plug-in.xcodeproj"; sourceTree = SOURCE_ROOT; };
63B5AA380F93565500DC9D8C /* md5.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = md5.c; path = ../portable/md5.c; sourceTree = SOURCE_ROOT; };
@@ -106,6 +114,7 @@
63C9B9630F867C460065ED7F /* Security.framework in Frameworks */,
63D1D09F0F97FDB3004FBC05 /* Growl.framework in Frameworks */,
63D1D2990F9A0CB1004FBC05 /* Carbon.framework in Frameworks */,
+ 637F074E0FAF20AD006EE129 /* ScriptingBridge.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -117,6 +126,8 @@
children = (
63D1D2520F99FC2F004FBC05 /* MetadataWindowController.h */,
63D1D2530F99FC2F004FBC05 /* MetadataWindowController.m */,
+ 637F066C0FADD118006EE129 /* PreferencesWindowController.h */,
+ 637F066D0FADD118006EE129 /* PreferencesWindowController.m */,
63024AEB0F9640A8001B8E9B /* Mediator.m */,
63024AE90F964063001B8E9B /* Mediator.h */,
63D6DAEF0F8396E000F4DCAA /* StatusItemController.h */,
@@ -125,14 +136,14 @@
63D1D1030F980532004FBC05 /* lastfm.m */,
63D1D1A00F989847004FBC05 /* HistoryMenuController.h */,
63D1D1A10F989847004FBC05 /* HistoryMenuController.m */,
- 29B97315FDCFA39411CA2CEA /* Other Sources */,
);
name = Classes;
sourceTree = "<group>";
};
1058C7A0FEA54F0111CA2CBB /* Linked Frameworks */ = {
isa = PBXGroup;
children = (
+ 637F074D0FAF20AD006EE129 /* ScriptingBridge.framework */,
63D1D2980F9A0CB1004FBC05 /* Carbon.framework */,
63D1D09E0F97FDB3004FBC05 /* Growl.framework */,
63C9B9620F867C460065ED7F /* Security.framework */,
@@ -164,6 +175,7 @@
children = (
6393C3C70F93870400286602 /* iTunes Plug-in.xcodeproj */,
080E96DDFE201D6D7F000001 /* Classes */,
+ 29B97315FDCFA39411CA2CEA /* Other Sources */,
29B97317FDCFA39411CA2CEA /* Resources */,
29B97323FDCFA39411CA2CEA /* Frameworks */,
19C28FACFE9D520D11CA2CBB /* Products */,
@@ -174,6 +186,7 @@
29B97315FDCFA39411CA2CEA /* Other Sources */ = {
isa = PBXGroup;
children = (
+ 637F07050FAF180F006EE129 /* iTunes.h */,
63D6DB8F0F83B6FE00F4DCAA /* scrobsub.h */,
63D6DB8D0F83B6F800F4DCAA /* scrobsub.c */,
63D6DBDE0F83CE6700F4DCAA /* scrobsub.m */,
@@ -197,6 +210,7 @@
63D1D2350F99E3B8004FBC05 /* MetadataWindow.xib */,
63D1D39E0F9A3EB1004FBC05 /* TagWindow.xib */,
63906F0B0F9DE71E00797A14 /* ShareWindow.xib */,
+ 637F066A0FADD0F7006EE129 /* Preferences.xib */,
63D1D0DA0F980171004FBC05 /* Growl Registration Ticket.growlRegDict */,
);
name = Resources;
@@ -290,6 +304,7 @@
63D1D2360F99E3B8004FBC05 /* MetadataWindow.xib in Resources */,
63D1D39F0F9A3EB1004FBC05 /* TagWindow.xib in Resources */,
63906F0C0F9DE71E00797A14 /* ShareWindow.xib in Resources */,
+ 637F066B0FADD0F7006EE129 /* Preferences.xib in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -328,6 +343,7 @@
63D1D1040F980532004FBC05 /* lastfm.m in Sources */,
63D1D1A20F989847004FBC05 /* HistoryMenuController.m in Sources */,
63D1D2540F99FC2F004FBC05 /* MetadataWindowController.m in Sources */,
+ 637F066E0FADD118006EE129 /* PreferencesWindowController.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
View
@@ -8,7 +8,7 @@
<string key="IBDocument.HIToolboxVersion">353.00</string>
<object class="NSMutableArray" key="IBDocument.EditedObjectIDs">
<bool key="EncodedWithXMLCoder">YES</bool>
- <integer value="457"/>
+ <integer value="481"/>
</object>
<object class="NSArray" key="IBDocument.PluginDependencies">
<bool key="EncodedWithXMLCoder">YES</bool>
@@ -150,10 +150,9 @@
</object>
<object class="NSMenuItem" id="251036408">
<reference key="NSMenu" ref="139733844"/>
- <string key="NSTitle">Automatically Hide Metadata Window</string>
+ <string type="base64-UTF8" key="NSTitle">UHJlZmVyZW5jZXPigKY</string>
<string key="NSKeyEquiv"/>
<int key="NSMnemonicLoc">2147483647</int>
- <int key="NSState">1</int>
<reference key="NSOnImage" ref="794915978"/>
<reference key="NSMixedImage" ref="273203663"/>
</object>
@@ -187,6 +186,9 @@
<object class="NSCustomObject" id="52689697">
<string key="NSClassName">Mediator</string>
</object>
+ <object class="NSCustomObject" id="284755017">
+ <string key="NSClassName">PreferencesWindowController</string>
+ </object>
</object>
<object class="IBObjectContainer" key="IBDocument.Objects">
<object class="NSMutableArray" key="connectionRecords">
@@ -263,21 +265,13 @@
</object>
<int key="connectionID">480</int>
</object>
- <object class="IBConnectionRecord">
- <object class="IBOutletConnection" key="connection">
- <string key="label">autohide</string>
- <reference key="source" ref="1050762845"/>
- <reference key="destination" ref="251036408"/>
- </object>
- <int key="connectionID">482</int>
- </object>
<object class="IBConnectionRecord">
<object class="IBActionConnection" key="connection">
- <string key="label">toggle:</string>
- <reference key="source" ref="1050762845"/>
+ <string key="label">showWindow:</string>
+ <reference key="source" ref="284755017"/>
<reference key="destination" ref="251036408"/>
</object>
- <int key="connectionID">483</int>
+ <int key="connectionID">485</int>
</object>
</object>
<object class="IBMutableOrderedSet" key="objectRecords">
@@ -433,6 +427,11 @@
<reference key="object" ref="251036408"/>
<reference key="parent" ref="139733844"/>
</object>
+ <object class="IBObjectRecord">
+ <int key="objectID">484</int>
+ <reference key="object" ref="284755017"/>
+ <reference key="parent" ref="1049"/>
+ </object>
</object>
</object>
<object class="NSMutableDictionary" key="flattenedProperties">
@@ -463,13 +462,15 @@
<string>477.IBPluginDependency</string>
<string>479.IBPluginDependency</string>
<string>481.IBPluginDependency</string>
+ <string>484.IBPluginDependency</string>
</object>
<object class="NSMutableArray" key="dict.values">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilderKit</string>
<string>com.apple.InterfaceBuilderKit</string>
- <string>{{391, 963}, {357, 193}}</string>
+ <string>{{391, 963}, {242, 193}}</string>
+ <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
@@ -481,8 +482,8 @@
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
+ <string>{{633, 1013}, {206, 53}}</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
- <string>{{583, 1013}, {206, 53}}</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
@@ -512,7 +513,7 @@
</object>
</object>
<nil key="sourceID"/>
- <int key="maxID">483</int>
+ <int key="maxID">485</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<object class="NSMutableArray" key="referencedPartialClassDescriptions">
@@ -545,6 +546,14 @@
<string key="minorKey">Mediator.h</string>
</object>
</object>
+ <object class="IBPartialClassDescription">
+ <string key="className">PreferencesWindowController</string>
+ <string key="superclassName">NSWindowController</string>
+ <object class="IBClassDescriptionSource" key="sourceIdentifier">
+ <string key="majorKey">IBProjectSource</string>
+ <string key="minorKey">PreferencesWindowController.h</string>
+ </object>
+ </object>
<object class="IBPartialClassDescription">
<string key="className">StatusItemController</string>
<string key="superclassName">NSObject</string>
@@ -566,17 +575,8 @@
</object>
</object>
<object class="NSMutableDictionary" key="outlets">
- <bool key="EncodedWithXMLCoder">YES</bool>
- <object class="NSMutableArray" key="dict.sortedKeys">
- <bool key="EncodedWithXMLCoder">YES</bool>
- <string>autohide</string>
- <string>menu</string>
- </object>
- <object class="NSMutableArray" key="dict.values">
- <bool key="EncodedWithXMLCoder">YES</bool>
- <string>NSMenuItem</string>
- <string>NSMenu</string>
- </object>
+ <string key="NS.key.0">menu</string>
+ <string key="NS.object.0">NSMenu</string>
</object>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
<string key="majorKey">IBProjectSource</string>
@@ -10,11 +10,8 @@
<string>Track Paused</string>
<string>Track Resumed</string>
<string>Playlist Ended</string>
-
- <string>Scrobble Submission Successful</string>
- <string>Scrobble Submission Failed</string>
-
- <string>iPod Detected</string>
+ <string>Scrobble Submission Status</string>
+ <string>iPod Scrobbling Status</string>
</array>
<key>DefaultNotifications</key>
<array>
View
@@ -53,12 +53,14 @@ -(void)insert:(NSDictionary*)track
-(void)onPlayerInfo:(NSNotification*)not
{
NSDictionary* track = [not userInfo];
- NSString* state = [track objectForKey:@"Player State"];
+ uint transition = [[track objectForKey:@"Transition"] unsignedIntValue];
- if([state isEqualToString:@"Playing"]){
- if(currentTrack)
- [self insert:currentTrack];
- currentTrack = track;
+ switch(transition){
+ case TrackStarted:
+ case PlaybackStopped:
+ if(currentTrack)
+ [self insert:currentTrack];
+ currentTrack = track;
}
}
View
@@ -36,15 +36,24 @@
-(void)resume:(NSString*)clientId;
-(void)stop:(NSString*)clientId;
+-(void)changeMetadata:(NSString*)clientId
+ forTrack:(NSString*)track
+ artist:(NSString*)artist
+ album:(NSString*)album;
+
-(IBAction)onScrobblingEnabledChanged:(id)sender;
-(NSDictionary*)currentTrack;
@end
+
+@class ITunesApplication;
+
@interface ITunesListener:NSObject{
int64_t pid;
bool waspaused;
+ ITunesApplication* itunes;
}
-(id)init;
@end
View
@@ -211,6 +211,8 @@ -(void)changeMetadata:(NSString*)id
nonullthx(Album);
nonullthx(Name);
scrobsub_change_metadata(Artist, Name, Album);
+
+ [self announce:dict withTransition:TrackMetadataChanged];
}
}
}
@@ -245,6 +247,7 @@ -(id)performDefaultImplementation
@end
+#import "iTunes.h"
@implementation ITunesListener
@@ -255,6 +258,7 @@ -(id)init
selector:@selector(onPlayerInfo:)
name:@"com.apple.iTunes.playerInfo"
object:nil];
+ itunes = [SBApplication applicationWithBundleIdentifier:@"com.apple.iTunes"];
return self;
}
@@ -270,15 +274,22 @@ -(void)onPlayerInfo:(NSNotification*)userData
int64_t const oldpid = pid;
NSMutableDictionary* dict = [[userData userInfo] mutableCopy];
pid = [[dict objectForKey:@"PersistentID"] longLongValue];
- if(oldpid == pid){
- if(waspaused)
- [[Mediator sharedMediator] resume:@"osx"];
- else
- [[Mediator sharedMediator] changeMetadata:@"osx"
- forTrack:[dict objectForKey:@"Name"]
- artist:[dict objectForKey:@"Artist"]
- album:[dict objectForKey:@"Album"]];
- }else{
+ bool const sametrack = oldpid == pid;
+ if(sametrack && waspaused)
+ [[Mediator sharedMediator] resume:@"osx"];
+ else if(sametrack && itunes.playerPosition > 0)
+ // iTunes sends this message if:
+ // 1) track started
+ // 2) track restarted
+ // 3) track metadata altered
+ // so this branch is a guess for (3)
+ [[Mediator sharedMediator] changeMetadata:@"osx"
+ forTrack:[dict objectForKey:@"Name"]
+ artist:[dict objectForKey:@"Artist"]
+ album:[dict objectForKey:@"Album"]];
+ else{
+ NSImage* img = [(ITunesArtwork*)[itunes.currentTrack.artworks objectAtIndex:0] data];
+ [dict setObject:img forKey:@"Album Art"];
uint const duration = [(NSNumber*)[dict objectForKey:@"Total Time"] longLongValue] / 1000;
[dict setObject:[NSNumber numberWithUnsignedInt:duration] forKey:@"Total Time"];
[dict setObject:@"iTunes" forKey:@"Player Name"];
View
@@ -98,7 +98,7 @@
<object class="NSTextView" id="371518471">
<reference key="NSNextResponder" ref="90067385"/>
<int key="NSvFlags">2322</int>
- <string key="NSFrameSize">{252, 25}</string>
+ <string key="NSFrameSize">{252, 14}</string>
<reference key="NSSuperview" ref="90067385"/>
<object class="NSTextContainer" key="NSTextContainer" id="890250299">
<object class="NSLayoutManager" key="NSLayoutManager">
@@ -127,7 +127,7 @@
</object>
<object class="NSColor" key="NSInsertionColor">
<int key="NSColorSpace">1</int>
- <bytes key="NSRGB">MSAxIDEAA</bytes>
+ <bytes key="NSRGB">MSAxIDEgMAA</bytes>
</object>
<object class="NSDictionary" key="NSSelectedAttributes">
<bool key="EncodedWithXMLCoder">YES</bool>
View
@@ -27,7 +27,6 @@
{
NSStatusItem* status_item;
IBOutlet NSMenu* menu;
- IBOutlet NSMenuItem* autohide;
NSWindowController* metadataWindow;
}
Oops, something went wrong.

0 comments on commit 39e4d2b

Please sign in to comment.