Browse files

A bunch of things.

• WebView for cover art
• Clean up usage of properties rather than iVars
• Move to the in-build document opening.
  • Loading branch information...
1 parent 3818541 commit dfe8a09c3dd0f2bf3e0b2f37a0e3030be80aafd0 @dannygreg committed Feb 18, 2012
Showing with 118 additions and 87 deletions.
  1. +7 −4 AppDelegate.h
  2. +81 −64 AppDelegate.m
  3. +4 −0 Perpetual.xcodeproj/project.pbxproj
  4. 0 cover.html
  5. +26 −19 en.lproj/MainMenu.xib
View
11 AppDelegate.h
@@ -8,7 +8,9 @@
#import <Cocoa/Cocoa.h>
#import <QTKit/QTKit.h>
-#import "INAppStoreWindow.h"
+
+@class INAppStoreWindow;
+@class WebView;
@interface AppDelegate : NSObject <NSApplicationDelegate>
@@ -21,16 +23,17 @@
@property (weak) IBOutlet NSTextField *currentTrackLabel;
@property (weak) IBOutlet NSTextField *loopCountLabel;
@property (weak) IBOutlet NSStepper *loopCountStepper;
+@property (weak) IBOutlet WebView *coverWebView;
@property (assign) BOOL paused;
@property (assign) QTTime startTime;
@property (assign) QTTime endTime;
@property (assign) QTTime currentTime;
@property (assign) long timeScale;
-@property (assign) int loopCount;
+@property (assign) NSUInteger loopCount;
// The value where we'll start looping infinitely.
-@property (assign) int loopInfiniteCount;
+@property (assign) NSInteger loopInfiniteCount;
@property (retain) QTMovie *music;
@@ -40,5 +43,5 @@
- (IBAction)startSliderSet:(id)sender;
- (IBAction)endSliderSet:(id)sender;
- (IBAction)currentTimeBarSet:(id)sender;
-- (IBAction)openFile:(id)sender;
+//- (IBAction)openFile:(id)sender;
@end
View
145 AppDelegate.m
@@ -7,43 +7,48 @@
//
#import "AppDelegate.h"
+
+#import "INAppStoreWindow.h"
+
#import <CoreAudio/CoreAudio.h>
#import <QTKit/QTKit.h>
+#import <WebKit/WebKit.h>
@implementation AppDelegate
@synthesize window = _window;
-@synthesize startSlider;
-@synthesize endSlider;
-@synthesize currentTimeLabel;
-@synthesize currentTimeBar;
-@synthesize playButton;
-@synthesize currentTrackLabel;
-@synthesize loopCountLabel;
-@synthesize loopCountStepper;
-
-@synthesize loopCount;
-@synthesize loopInfiniteCount;
-@synthesize timeScale;
-@synthesize startTime;
-@synthesize endTime;
-@synthesize currentTime;
-@synthesize music;
-@synthesize paused;
+@synthesize startSlider = _startSlider;
+@synthesize endSlider = _endSlider;
+@synthesize currentTimeLabel = _currentTimeLabel;
+@synthesize currentTimeBar = _currentTimeBar;
+@synthesize playButton = _playButton;
+@synthesize currentTrackLabel = _currentTrackLabel;
+@synthesize loopCountLabel = _loopCountLabel;
+@synthesize loopCountStepper = _loopCountStepper;
+@synthesize coverWebView = _coverWebView;
+
+@synthesize loopCount = _loopCount;
+@synthesize loopInfiniteCount = _loopInfiniteCount;
+@synthesize timeScale = _timeScale;
+@synthesize startTime = _startTime;
+@synthesize endTime = _endTime;
+@synthesize currentTime = _currentTime;
+@synthesize music = _music;
+@synthesize paused = _paused;
-(void) setTheLoopCount:(int)theLoopCount
{
// Sets the property and updates the label.
[self setLoopCount:theLoopCount];
if ([self loopCount] < [self loopInfiniteCount]) {
- [loopCountLabel setStringValue:[NSString stringWithFormat:@"x%d",self.loopCount]];
+ [self.loopCountLabel setStringValue:[NSString stringWithFormat:@"x%d",self.loopCount]];
}
else {
- [loopCountLabel setStringValue:@""];
+ [self.loopCountLabel setStringValue:@""];
}
// Finally update the stepper so it's synchronized.
- [loopCountStepper setIntValue:[self loopCount]];
+ [self.loopCountStepper setIntValue:[self loopCount]];
}
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
@@ -76,62 +81,62 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
-(void) checkTime:(NSTimer*)theTimer
{
- currentTime = [music currentTime];
+ self.currentTime = [self.music currentTime];
- if (currentTime.timeValue >= endTime.timeValue && startTime.timeValue < endTime.timeValue && [self loopCount] > 0){
+ if (self.currentTime.timeValue >= self.endTime.timeValue && self.startTime.timeValue < self.endTime.timeValue && [self loopCount] > 0){
if ([self loopCount] < [self loopInfiniteCount]) {
// [self loopInfiniteCount] is the magic infinite number.
[self setTheLoopCount:[self loopCount]-1];
}
- [music setCurrentTime:startTime];
+ [self.music setCurrentTime:self.startTime];
}
NSCalendar *sysCalendar = [NSCalendar currentCalendar];
NSDate *date1 = [[NSDate alloc] init];
- NSDate *date2 = [[NSDate alloc] initWithTimeInterval:currentTime.timeValue/timeScale sinceDate:date1];
+ NSDate *date2 = [[NSDate alloc] initWithTimeInterval:self.currentTime.timeValue/self.timeScale sinceDate:date1];
unsigned int unitFlags = NSMinuteCalendarUnit | NSSecondCalendarUnit;
NSDateComponents *conversionInfo = [sysCalendar components:unitFlags fromDate:date1 toDate:date2 options:0];
- [currentTimeLabel setStringValue:[NSString stringWithFormat:@"%02d:%02d",[conversionInfo minute],[conversionInfo second]]];
- [currentTimeBar setFloatValue:(float)currentTime.timeValue];
+ [self.currentTimeLabel setStringValue:[NSString stringWithFormat:@"%02d:%02d",[conversionInfo minute],[conversionInfo second]]];
+ [self.currentTimeBar setFloatValue:(float)self.currentTime.timeValue];
}
- (void)loadMusic:(NSURL *) fileURL
{
// Load the track from URL.
// TODO: Error handling.
- music = [[QTMovie alloc] initWithURL:fileURL error:nil];
+ self.music = [[QTMovie alloc] initWithURL:fileURL error:nil];
//Really needed anymore?
- paused = YES;
+ self.paused = YES;
// Find and set slider max values.
- QTTime maxTime = [music duration];
- timeScale = [music duration].timeScale;
+ QTTime maxTime = [self.music duration];
+ self.timeScale = [self.music duration].timeScale;
float maxValue = (float)maxTime.timeValue;
- startTime = QTMakeTime(0.0, timeScale);
- endTime = maxTime;
+ self.startTime = QTMakeTime(0.0, self.timeScale);
+ self.endTime = maxTime;
- [currentTimeBar setMaxValue:maxValue];
- [startSlider setMaxValue:maxValue];
- [startSlider setFloatValue:0.0];
- [endSlider setMaxValue:maxValue];
- [endSlider setFloatValue:maxValue];
- [startSlider setNumberOfTickMarks:(int) maxValue/timeScale];
- [endSlider setNumberOfTickMarks:(int) maxValue/timeScale];
+ [self.currentTimeBar setMaxValue:maxValue];
+ [self.startSlider setMaxValue:maxValue];
+ [self.startSlider setFloatValue:0.0];
+ [self.endSlider setMaxValue:maxValue];
+ [self.endSlider setFloatValue:maxValue];
+ [self.startSlider setNumberOfTickMarks:(int) maxValue/self.timeScale];
+ [self.endSlider setNumberOfTickMarks:(int) maxValue/self.timeScale];
// Set title and artist labels from.
NSString * trackTitle = @"Unknown title";
NSString * trackArtist = @"Unknown artist";
- NSArray * mdFormatsArray = [music availableMetadataFormats];
+ NSArray * mdFormatsArray = [self.music availableMetadataFormats];
for (int i=0;i<[mdFormatsArray count];i++) {
- NSArray * mdArray = [music metadataForFormat:[mdFormatsArray objectAtIndex:i]];
+ NSArray * mdArray = [self.music metadataForFormat:[mdFormatsArray objectAtIndex:i]];
// Fixme: find out why we need to replace @ with ©.
NSArray * titleMetadataItems = [QTMetadataItem metadataItemsFromArray:mdArray withKey:[QTMetadataiTunesMetadataKeySongName stringByReplacingOccurrencesOfString:@"@" withString:@"©"] keySpace:nil];
if ([titleMetadataItems count] > 0) {
@@ -144,64 +149,76 @@ - (void)loadMusic:(NSURL *) fileURL
}
}
- [currentTrackLabel setStringValue:[NSString stringWithFormat:@"%@\n%@",trackTitle,trackArtist]];
+ [self.currentTrackLabel setStringValue:[NSString stringWithFormat:@"%@\n%@",trackTitle,trackArtist]];
// Start loop and play track.
[NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(checkTime:) userInfo:nil repeats:YES];
}
- (IBAction)startSliderSet:(id)sender
{
- if ([startSlider doubleValue] < (float)endTime.timeValue) {
- startTime = QTMakeTime((long)[startSlider doubleValue],timeScale);
+ if ([self.startSlider doubleValue] < (float)self.endTime.timeValue) {
+ self.startTime = QTMakeTime((long)[self.startSlider doubleValue], self.timeScale);
}
else {
- [startSlider setFloatValue:(float)startTime.timeValue];
+ [self.startSlider setFloatValue:(float)self.startTime.timeValue];
}
}
- (IBAction)endSliderSet:(id)sender
{
- if ([endSlider doubleValue] > (float)startTime.timeValue) {
- endTime = QTMakeTime((long)[endSlider doubleValue],timeScale);
+ if ([self.endSlider doubleValue] > (float)self.startTime.timeValue) {
+ self.endTime = QTMakeTime((long)[self.endSlider doubleValue], self.timeScale);
}
else {
- [endSlider setFloatValue:(float)endTime.timeValue];
+ [self.endSlider setFloatValue:(float)self.endTime.timeValue];
}
}
- (IBAction)currentTimeBarSet:(id)sender
{
- NSTimeInterval ct = [currentTimeBar doubleValue];
- [music setCurrentTime:QTMakeTime((long)ct,timeScale)];
+ NSTimeInterval ct = [self.currentTimeBar doubleValue];
+ [self.music setCurrentTime:QTMakeTime((long)ct, self.timeScale)];
}
- (IBAction)playButtonClick:(id)sender
{
- if (!paused) {
- [music stop];
- paused = YES;
+ if (!self.paused) {
+ [self.music stop];
+ self.paused = YES;
}
else {
- [music play];
- paused = NO;
+ [self.music play];
+ self.paused = NO;
}
}
- (IBAction)loopStepperStep:(id)sender
{
- [self setTheLoopCount:[loopCountStepper intValue]];
+ [self setTheLoopCount:[self.loopCountStepper intValue]];
}
-- (IBAction)openFile:(id)sender
+//- (IBAction)openFile:(id)sender
+//{
+// NSOpenPanel *panel = [NSOpenPanel openPanel];
+// NSInteger tvarNSInteger = [panel runModal];
+// if(tvarNSInteger == NSOKButton){
+// [self.music stop];
+// NSURL *fileURL = [panel URL];
+// [self loadMusic:fileURL];
+// }
+//}
+
+- (BOOL)application:(NSApplication *)sender openFile:(NSString *)filename
{
- NSOpenPanel *panel = [NSOpenPanel openPanel];
- NSInteger tvarNSInteger = [panel runModal];
- if(tvarNSInteger == NSOKButton){
- [music stop];
- NSURL *fileURL = [panel URL];
- [self loadMusic:fileURL];
- }
+ [self.music stop];
+ NSURL *fileURL = [NSURL fileURLWithPath:filename];
+ if (fileURL == nil)
+ return NO; //make me smarter
+
+ [self loadMusic:fileURL];
+ return YES;
}
+
@end
View
4 Perpetual.xcodeproj/project.pbxproj
@@ -8,6 +8,7 @@
/* Begin PBXBuildFile section */
307BADD914F04DEF0035E3AF /* WebKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 307BADD814F04DEF0035E3AF /* WebKit.framework */; };
+ 307BADDB14F04EA50035E3AF /* cover.html in Resources */ = {isa = PBXBuildFile; fileRef = 307BADDA14F04EA50035E3AF /* cover.html */; };
351CA58DF08E43309D0C1A7C /* libPods.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 4F63DF7AE63C4BFF97E85379 /* libPods.a */; };
9395B6AD14EB88A8002999D9 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9395B6AC14EB88A8002999D9 /* QuartzCore.framework */; };
9395B6B014EB8D91002999D9 /* Podfile in Resources */ = {isa = PBXBuildFile; fileRef = 9395B6AF14EB8D91002999D9 /* Podfile */; };
@@ -24,6 +25,7 @@
/* Begin PBXFileReference section */
307BADD814F04DEF0035E3AF /* WebKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = WebKit.framework; path = System/Library/Frameworks/WebKit.framework; sourceTree = SDKROOT; };
+ 307BADDA14F04EA50035E3AF /* cover.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = cover.html; sourceTree = "<group>"; };
4F63DF7AE63C4BFF97E85379 /* libPods.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libPods.a; sourceTree = BUILT_PRODUCTS_DIR; };
9395B6AC14EB88A8002999D9 /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; };
9395B6AF14EB8D91002999D9 /* Podfile */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Podfile; sourceTree = "<group>"; };
@@ -126,6 +128,7 @@
9AC739DA14EAEAB6000A57AD /* Info.plist */,
9AC739E114EAEAB6000A57AD /* Credits.rtf */,
9AC739DB14EAEAB6000A57AD /* InfoPlist.strings */,
+ 307BADDA14F04EA50035E3AF /* cover.html */,
);
name = "Supporting Files";
sourceTree = "<group>";
@@ -187,6 +190,7 @@
9AC739E914EAEAB6000A57AD /* MainMenu.xib in Resources */,
9A041EBD14EAEBA2009AC43F /* cover.jpg in Resources */,
9395B6B014EB8D91002999D9 /* Podfile in Resources */,
+ 307BADDB14F04EA50035E3AF /* cover.html in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
View
0 cover.html
No changes.
View
45 en.lproj/MainMenu.xib
@@ -444,7 +444,6 @@
<string key="NSFrame">{{9, 29}, {384, 25}}</string>
<reference key="NSSuperview" ref="439893737"/>
<reference key="NSWindow"/>
- <reference key="NSNextKeyView"/>
<string key="NSReuseIdentifierKey">_NS:3905</string>
<bool key="NSEnabled">YES</bool>
<object class="NSSliderCell" key="NSCell" id="622609772">
@@ -503,7 +502,7 @@
<reference key="NSTextColor" ref="41212231"/>
</object>
</object>
- <object class="WebView" id="1038146946">
+ <object class="WebView" id="598347787">
<reference key="NSNextResponder" ref="439893737"/>
<int key="NSvFlags">274</int>
<set class="NSMutableSet" key="NSDragTypes">
@@ -545,7 +544,7 @@
<string key="NSFrameSize">{400, 400}</string>
<reference key="NSSuperview"/>
<reference key="NSWindow"/>
- <reference key="NSNextKeyView"/>
+ <reference key="NSNextKeyView" ref="598347787"/>
</object>
<string key="NSScreenRect">{{0, 0}, {1680, 1050}}</string>
<string key="NSMinSize">{400, 422}</string>
@@ -639,6 +638,14 @@
<int key="connectionID">493</int>
</object>
<object class="IBConnectionRecord">
+ <object class="IBActionConnection" key="connection">
+ <string key="label">openDocument:</string>
+ <reference key="source" ref="1014"/>
+ <reference key="destination" ref="722745758"/>
+ </object>
+ <int key="connectionID">626</int>
+ </object>
+ <object class="IBConnectionRecord">
<object class="IBOutletConnection" key="connection">
<string key="label">currentTimeLabel</string>
<reference key="source" ref="976324537"/>
@@ -711,14 +718,6 @@
<int key="connectionID">553</int>
</object>
<object class="IBConnectionRecord">
- <object class="IBActionConnection" key="connection">
- <string key="label">openFile:</string>
- <reference key="source" ref="976324537"/>
- <reference key="destination" ref="722745758"/>
- </object>
- <int key="connectionID">611</int>
- </object>
- <object class="IBConnectionRecord">
<object class="IBOutletConnection" key="connection">
<string key="label">window</string>
<reference key="source" ref="976324537"/>
@@ -758,6 +757,14 @@
</object>
<int key="connectionID">622</int>
</object>
+ <object class="IBConnectionRecord">
+ <object class="IBOutletConnection" key="connection">
+ <string key="label">coverWebView</string>
+ <reference key="source" ref="976324537"/>
+ <reference key="destination" ref="598347787"/>
+ </object>
+ <int key="connectionID">624</int>
+ </object>
</array>
<object class="IBMutableOrderedSet" key="objectRecords">
<array key="orderedObjects">
@@ -965,7 +972,7 @@
<reference ref="753304525"/>
<reference ref="238452651"/>
<reference ref="153453889"/>
- <reference ref="1038146946"/>
+ <reference ref="598347787"/>
</array>
<reference key="parent" ref="972006081"/>
</object>
@@ -1101,7 +1108,7 @@
</object>
<object class="IBObjectRecord">
<int key="objectID">623</int>
- <reference key="object" ref="1038146946"/>
+ <reference key="object" ref="598347787"/>
<reference key="parent" ref="439893737"/>
</object>
</array>
@@ -1166,7 +1173,7 @@
<nil key="activeLocalization"/>
<dictionary class="NSMutableDictionary" key="localizations"/>
<nil key="sourceID"/>
- <int key="maxID">623</int>
+ <int key="maxID">626</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<array class="NSMutableArray" key="referencedPartialClassDescriptions">
@@ -1177,7 +1184,6 @@
<string key="currentTimeBarSet:">id</string>
<string key="endSliderSet:">id</string>
<string key="loopStepperStep:">id</string>
- <string key="openFile:">id</string>
<string key="playButtonClick:">id</string>
<string key="startSliderSet:">id</string>
</dictionary>
@@ -1194,10 +1200,6 @@
<string key="name">loopStepperStep:</string>
<string key="candidateClassName">id</string>
</object>
- <object class="IBActionInfo" key="openFile:">
- <string key="name">openFile:</string>
- <string key="candidateClassName">id</string>
- </object>
<object class="IBActionInfo" key="playButtonClick:">
<string key="name">playButtonClick:</string>
<string key="candidateClassName">id</string>
@@ -1208,6 +1210,7 @@
</object>
</dictionary>
<dictionary class="NSMutableDictionary" key="outlets">
+ <string key="coverWebView">WebView</string>
<string key="currentTimeBar">NSLevelIndicator</string>
<string key="currentTimeLabel">NSTextField</string>
<string key="currentTrackLabel">NSTextField</string>
@@ -1219,6 +1222,10 @@
<string key="window">INAppStoreWindow</string>
</dictionary>
<dictionary class="NSMutableDictionary" key="toOneOutletInfosByName">
+ <object class="IBToOneOutletInfo" key="coverWebView">
+ <string key="name">coverWebView</string>
+ <string key="candidateClassName">WebView</string>
+ </object>
<object class="IBToOneOutletInfo" key="currentTimeBar">
<string key="name">currentTimeBar</string>
<string key="candidateClassName">NSLevelIndicator</string>

0 comments on commit dfe8a09

Please sign in to comment.