Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #5 from revyver/metadata

Merged Metadata branch
  • Loading branch information...
commit 41d1c7e46e13ee5edb49bc2e772138a5b36470c9 2 parents b6904a7 + 71a2283
@kallepersson kallepersson authored
View
12 AppDelegate.h
@@ -7,6 +7,7 @@
//
#import <Cocoa/Cocoa.h>
+#import <QTKit/QTKit.h>
#import "INAppStoreWindow.h"
@interface AppDelegate : NSObject <NSApplicationDelegate>
@@ -17,13 +18,16 @@
@property (weak) IBOutlet NSSlider *endSlider;
@property (weak) IBOutlet NSLevelIndicator *currentTimeBar;
@property (weak) IBOutlet NSTextField *currentTimeLabel;
+@property (weak) IBOutlet NSTextField *currentTrackLabel;
+
@property (assign) BOOL paused;
-@property (assign) double startTime;
-@property (assign) double endTime;
-@property (assign) double currentTime;
+@property (assign) QTTime startTime;
+@property (assign) QTTime endTime;
+@property (assign) QTTime currentTime;
+@property (assign) long timeScale;
-@property (retain) NSSound *music;
+@property (retain) QTMovie *music;
- (void)checkTime:(NSTimer*)theTimer;
- (IBAction)playButtonClick:(id)sender;
- (IBAction)startSliderSet:(id)sender;
View
87 AppDelegate.m
@@ -8,6 +8,7 @@
#import "AppDelegate.h"
#import <CoreAudio/CoreAudio.h>
+#import <QTKit/QTKit.h>
@implementation AppDelegate
@@ -17,7 +18,9 @@ @implementation AppDelegate
@synthesize currentTimeLabel;
@synthesize currentTimeBar;
@synthesize playButton;
+@synthesize currentTrackLabel;
+@synthesize timeScale;
@synthesize startTime;
@synthesize endTime;
@synthesize currentTime;
@@ -33,75 +36,105 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
-(void) checkTime:(NSTimer*)theTimer{
currentTime = [music currentTime];
- if([music isPlaying]){
- if(currentTime >= endTime && startTime < endTime){
- [music setCurrentTime:startTime];
- }
+
+ if(currentTime.timeValue >= endTime.timeValue && startTime.timeValue < endTime.timeValue){
+ [music setCurrentTime:startTime];
}
+
NSCalendar *sysCalendar = [NSCalendar currentCalendar];
NSDate *date1 = [[NSDate alloc] init];
- NSDate *date2 = [[NSDate alloc] initWithTimeInterval:currentTime sinceDate:date1];
+ NSDate *date2 = [[NSDate alloc] initWithTimeInterval:currentTime.timeValue/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:currentTime];
+ [currentTimeBar setFloatValue:(float)currentTime.timeValue];
}
- (void)loadMusic:(NSURL *) fileURL {
- NSSound * m = [NSSound alloc];
- music = [m initWithContentsOfURL:fileURL byReference:YES];
- double maxValue = [music duration];
+ //Load the track from URL
+ //TODO: Error handling
+ music = [[QTMovie alloc] initWithURL:fileURL error:nil];
+
+ //Really needed anymore?
paused = YES;
- startTime = 0.0;
- endTime = maxValue;
- [currentTimeBar setMaxValue:endTime];
+
+ //Find and set slider max values
+ QTTime maxTime = [music duration];
+ timeScale = [music duration].timeScale;
+ float maxValue = (float)maxTime.timeValue;
+ startTime = QTMakeTime(0.0,timeScale);
+ endTime = maxTime;
+
+ [currentTimeBar setMaxValue:maxValue];
[startSlider setMaxValue:maxValue];
[startSlider setFloatValue:0.0];
[endSlider setMaxValue:maxValue];
[endSlider setFloatValue:maxValue];
- [startSlider setNumberOfTickMarks:(int) endTime];
- [endSlider setNumberOfTickMarks:(int) endTime];
+ [startSlider setNumberOfTickMarks:(int) maxValue/timeScale];
+ [endSlider setNumberOfTickMarks:(int) maxValue/timeScale];
+
+ //Set title and artist labels from
+ NSString * trackTitle = @"Unknown title";
+ NSString * trackArtist = @"Unknown artist";
+
+ NSArray * mdFormatsArray = [music availableMetadataFormats];
+ for(int i=0;i<[mdFormatsArray count];i++) {
+ NSArray * mdArray = [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) {
+ trackTitle = [[titleMetadataItems objectAtIndex:0] stringValue];
+ }
+ //Fixme: find out why we need to replace @ with ©
+ NSArray * artistMetadataItems = [QTMetadataItem metadataItemsFromArray:mdArray withKey:[QTMetadataiTunesMetadataKeyArtist stringByReplacingOccurrencesOfString:@"@" withString:@"©"] keySpace:nil];
+ if([artistMetadataItems count] > 0) {
+ trackArtist = [[artistMetadataItems objectAtIndex:0] stringValue];
+ }
+ }
+
+ [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];
- [music play];
- [music pause];
}
- (IBAction)startSliderSet:(id)sender {
- if([startSlider doubleValue] < endTime) {
- startTime = [startSlider doubleValue];
+ if([startSlider doubleValue] < (float)endTime.timeValue) {
+ startTime = QTMakeTime((long)[startSlider doubleValue],timeScale);
+
}
else{
- [startSlider setFloatValue:startTime];
+ [startSlider setFloatValue:(float)startTime.timeValue];
}
}
- (IBAction)endSliderSet:(id)sender {
- if([endSlider doubleValue] > startTime) {
- endTime = [endSlider doubleValue];
+ if([endSlider doubleValue] > (float)startTime.timeValue) {
+ endTime = QTMakeTime((long)[endSlider doubleValue],timeScale);
}
else{
- [endSlider setFloatValue:endTime];
+ [endSlider setFloatValue:(float)endTime.timeValue];
}
}
- (IBAction)currentTimeBarSet:(id)sender {
NSTimeInterval ct = [currentTimeBar doubleValue];
- [music setCurrentTime:ct];
+ [music setCurrentTime:QTMakeTime((long)ct,timeScale)];
}
- (IBAction)playButtonClick:(id)sender {
if(!paused) {
- [music pause];
+ [music stop];
paused = YES;
}
else {
- [music resume];
+ [music play];
paused = NO;
}
}
@@ -110,9 +143,7 @@ - (IBAction)openFile:(id)sender {
NSOpenPanel *openPanel = [NSOpenPanel openPanel];
NSInteger tvarNSInteger = [openPanel runModal];
if(tvarNSInteger == NSOKButton){
- if([music isPlaying]) {
- [music stop];
- }
+ [music stop];
NSURL * fileURL = [openPanel URL];
[self loadMusic:fileURL];
}
View
8 Perpetual.xcodeproj/project.pbxproj
@@ -11,12 +11,14 @@
9395B6AD14EB88A8002999D9 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9395B6AC14EB88A8002999D9 /* QuartzCore.framework */; };
9395B6B014EB8D91002999D9 /* Podfile in Resources */ = {isa = PBXBuildFile; fileRef = 9395B6AF14EB8D91002999D9 /* Podfile */; };
9A041EBD14EAEBA2009AC43F /* cover.jpg in Resources */ = {isa = PBXBuildFile; fileRef = 9A041EBC14EAEBA2009AC43F /* cover.jpg */; };
+ 9A31AA3414EBF3FD00382B2F /* AudioToolbox.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9A31AA3314EBF3FD00382B2F /* AudioToolbox.framework */; };
9AC739D314EAEAB6000A57AD /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9AC739D214EAEAB6000A57AD /* Cocoa.framework */; };
9AC739DD14EAEAB6000A57AD /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 9AC739DB14EAEAB6000A57AD /* InfoPlist.strings */; };
9AC739DF14EAEAB6000A57AD /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 9AC739DE14EAEAB6000A57AD /* main.m */; };
9AC739E314EAEAB6000A57AD /* Credits.rtf in Resources */ = {isa = PBXBuildFile; fileRef = 9AC739E114EAEAB6000A57AD /* Credits.rtf */; };
9AC739E614EAEAB6000A57AD /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 9AC739E514EAEAB6000A57AD /* AppDelegate.m */; };
9AC739E914EAEAB6000A57AD /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 9AC739E714EAEAB6000A57AD /* MainMenu.xib */; };
+ 9AE4EA5714EC59D6002EF094 /* QTKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9AE4EA5614EC59D6002EF094 /* QTKit.framework */; };
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
@@ -24,6 +26,7 @@
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>"; };
9A041EBC14EAEBA2009AC43F /* cover.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = cover.jpg; sourceTree = "<group>"; };
+ 9A31AA3314EBF3FD00382B2F /* AudioToolbox.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AudioToolbox.framework; path = System/Library/Frameworks/AudioToolbox.framework; sourceTree = SDKROOT; };
9AC739CE14EAEAB6000A57AD /* Perpetual.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Perpetual.app; sourceTree = BUILT_PRODUCTS_DIR; };
9AC739D214EAEAB6000A57AD /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = System/Library/Frameworks/Cocoa.framework; sourceTree = SDKROOT; };
9AC739D514EAEAB6000A57AD /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = System/Library/Frameworks/AppKit.framework; sourceTree = SDKROOT; };
@@ -37,6 +40,7 @@
9AC739E414EAEAB6000A57AD /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
9AC739E514EAEAB6000A57AD /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = "<group>"; };
9AC739E814EAEAB6000A57AD /* en */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = en; path = en.lproj/MainMenu.xib; sourceTree = "<group>"; };
+ 9AE4EA5614EC59D6002EF094 /* QTKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QTKit.framework; path = System/Library/Frameworks/QTKit.framework; sourceTree = SDKROOT; };
DDB3CDEF03204F9F8C7160C4 /* Pods.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Pods.xcconfig; path = Pods/Pods.xcconfig; sourceTree = SOURCE_ROOT; };
/* End PBXFileReference section */
@@ -45,6 +49,8 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
+ 9AE4EA5714EC59D6002EF094 /* QTKit.framework in Frameworks */,
+ 9A31AA3414EBF3FD00382B2F /* AudioToolbox.framework in Frameworks */,
9395B6AD14EB88A8002999D9 /* QuartzCore.framework in Frameworks */,
9AC739D314EAEAB6000A57AD /* Cocoa.framework in Frameworks */,
351CA58DF08E43309D0C1A7C /* libPods.a in Frameworks */,
@@ -57,6 +63,8 @@
9AC739C314EAEAB6000A57AD = {
isa = PBXGroup;
children = (
+ 9AE4EA5614EC59D6002EF094 /* QTKit.framework */,
+ 9A31AA3314EBF3FD00382B2F /* AudioToolbox.framework */,
9395B6AC14EB88A8002999D9 /* QuartzCore.framework */,
9AC739D814EAEAB6000A57AD /* Perpetual */,
9AC739D114EAEAB6000A57AD /* Frameworks */,
View
5 Perpetual.xcodeproj/xcuserdata/kallepersson.xcuserdatad/xcschemes/Perpetual.xcscheme
@@ -56,6 +56,11 @@
</BuildableReference>
</BuildableProductRunnable>
<AdditionalOptions>
+ <AdditionalOption
+ key = "NSZombieEnabled"
+ value = "YES"
+ isEnabled = "YES">
+ </AdditionalOption>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
View
109 en.lproj/MainMenu.xib
@@ -2,7 +2,7 @@
<archive type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="8.00">
<data>
<int key="IBDocument.SystemTarget">1070</int>
- <string key="IBDocument.SystemVersion">11D50b</string>
+ <string key="IBDocument.SystemVersion">11D50</string>
<string key="IBDocument.InterfaceBuilderVersion">1938</string>
<string key="IBDocument.AppKitVersion">1138.32</string>
<string key="IBDocument.HIToolboxVersion">568.00</string>
@@ -312,6 +312,7 @@
</set>
<string key="NSFrame">{{-3, 127}, {406, 256}}</string>
<reference key="NSSuperview" ref="439893737"/>
+ <reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="690740704"/>
<string key="NSReuseIdentifierKey">_NS:2141</string>
<bool key="NSEnabled">YES</bool>
@@ -335,6 +336,7 @@
<int key="NSvFlags">268</int>
<string key="NSFrame">{{8, 82}, {40, 40}}</string>
<reference key="NSSuperview" ref="439893737"/>
+ <reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="353695766"/>
<string key="NSReuseIdentifierKey">_NS:687</string>
<bool key="NSEnabled">YES</bool>
@@ -366,6 +368,7 @@
<int key="NSvFlags">268</int>
<string key="NSFrame">{{59, 86}, {245, 34}}</string>
<reference key="NSSuperview" ref="439893737"/>
+ <reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="753304525"/>
<string key="NSReuseIdentifierKey">_NS:360</string>
<string key="NSAntiCompressionPriority">{250, 750}</string>
@@ -406,6 +409,7 @@
<int key="NSvFlags">268</int>
<string key="NSFrame">{{319, 95}, {75, 17}}</string>
<reference key="NSSuperview" ref="439893737"/>
+ <reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="752942585"/>
<string key="NSReuseIdentifierKey">_NS:3944</string>
<bool key="NSEnabled">YES</bool>
@@ -425,6 +429,7 @@
<int key="NSvFlags">268</int>
<string key="NSFrame">{{18, 34}, {366, 16}}</string>
<reference key="NSSuperview" ref="439893737"/>
+ <reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="75188771"/>
<string key="NSReuseIdentifierKey">_NS:2200</string>
<bool key="NSEnabled">YES</bool>
@@ -442,6 +447,7 @@
<int key="NSvFlags">268</int>
<string key="NSFrame">{{9, 49}, {384, 26}}</string>
<reference key="NSSuperview" ref="439893737"/>
+ <reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="840108087"/>
<string key="NSReuseIdentifierKey">_NS:3905</string>
<bool key="NSEnabled">YES</bool>
@@ -466,6 +472,7 @@
<int key="NSvFlags">268</int>
<string key="NSFrame">{{9, 9}, {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>
@@ -488,6 +495,7 @@
</array>
<string key="NSFrameSize">{400, 380}</string>
<reference key="NSSuperview"/>
+ <reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="379503995"/>
</object>
<string key="NSScreenRect">{{0, 0}, {2560, 1440}}</string>
@@ -668,6 +676,14 @@
</object>
<int key="connectionID">612</int>
</object>
+ <object class="IBConnectionRecord">
+ <object class="IBOutletConnection" key="connection">
+ <string key="label">currentTrackLabel</string>
+ <reference key="source" ref="976324537"/>
+ <reference key="destination" ref="353695766"/>
+ </object>
+ <int key="connectionID">613</int>
+ </object>
</array>
<object class="IBMutableOrderedSet" key="objectRecords">
<array key="orderedObjects">
@@ -1053,9 +1069,96 @@
<nil key="activeLocalization"/>
<dictionary class="NSMutableDictionary" key="localizations"/>
<nil key="sourceID"/>
- <int key="maxID">612</int>
+ <int key="maxID">613</int>
+ </object>
+ <object class="IBClassDescriber" key="IBDocument.Classes">
+ <array class="NSMutableArray" key="referencedPartialClassDescriptions">
+ <object class="IBPartialClassDescription">
+ <string key="className">AppDelegate</string>
+ <string key="superclassName">NSObject</string>
+ <dictionary class="NSMutableDictionary" key="actions">
+ <string key="currentTimeBarSet:">id</string>
+ <string key="endSliderSet:">id</string>
+ <string key="openFile:">id</string>
+ <string key="playButtonClick:">id</string>
+ <string key="startSliderSet:">id</string>
+ </dictionary>
+ <dictionary class="NSMutableDictionary" key="actionInfosByName">
+ <object class="IBActionInfo" key="currentTimeBarSet:">
+ <string key="name">currentTimeBarSet:</string>
+ <string key="candidateClassName">id</string>
+ </object>
+ <object class="IBActionInfo" key="endSliderSet:">
+ <string key="name">endSliderSet:</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>
+ </object>
+ <object class="IBActionInfo" key="startSliderSet:">
+ <string key="name">startSliderSet:</string>
+ <string key="candidateClassName">id</string>
+ </object>
+ </dictionary>
+ <dictionary class="NSMutableDictionary" key="outlets">
+ <string key="currentTimeBar">NSLevelIndicator</string>
+ <string key="currentTimeLabel">NSTextField</string>
+ <string key="currentTrackLabel">NSTextField</string>
+ <string key="endSlider">NSSlider</string>
+ <string key="playButton">NSButton</string>
+ <string key="startSlider">NSSlider</string>
+ <string key="window">INAppStoreWindow</string>
+ </dictionary>
+ <dictionary class="NSMutableDictionary" key="toOneOutletInfosByName">
+ <object class="IBToOneOutletInfo" key="currentTimeBar">
+ <string key="name">currentTimeBar</string>
+ <string key="candidateClassName">NSLevelIndicator</string>
+ </object>
+ <object class="IBToOneOutletInfo" key="currentTimeLabel">
+ <string key="name">currentTimeLabel</string>
+ <string key="candidateClassName">NSTextField</string>
+ </object>
+ <object class="IBToOneOutletInfo" key="currentTrackLabel">
+ <string key="name">currentTrackLabel</string>
+ <string key="candidateClassName">NSTextField</string>
+ </object>
+ <object class="IBToOneOutletInfo" key="endSlider">
+ <string key="name">endSlider</string>
+ <string key="candidateClassName">NSSlider</string>
+ </object>
+ <object class="IBToOneOutletInfo" key="playButton">
+ <string key="name">playButton</string>
+ <string key="candidateClassName">NSButton</string>
+ </object>
+ <object class="IBToOneOutletInfo" key="startSlider">
+ <string key="name">startSlider</string>
+ <string key="candidateClassName">NSSlider</string>
+ </object>
+ <object class="IBToOneOutletInfo" key="window">
+ <string key="name">window</string>
+ <string key="candidateClassName">INAppStoreWindow</string>
+ </object>
+ </dictionary>
+ <object class="IBClassDescriptionSource" key="sourceIdentifier">
+ <string key="majorKey">IBProjectSource</string>
+ <string key="minorKey">./Classes/AppDelegate.h</string>
+ </object>
+ </object>
+ <object class="IBPartialClassDescription">
+ <string key="className">INAppStoreWindow</string>
+ <string key="superclassName">NSWindow</string>
+ <object class="IBClassDescriptionSource" key="sourceIdentifier">
+ <string key="majorKey">IBProjectSource</string>
+ <string key="minorKey">./Classes/INAppStoreWindow.h</string>
+ </object>
+ </object>
+ </array>
</object>
- <object class="IBClassDescriber" key="IBDocument.Classes"/>
<int key="IBDocument.localizationMode">0</int>
<string key="IBDocument.TargetRuntimeIdentifier">IBCocoaFramework</string>
<bool key="IBDocument.PluginDeclaredDependenciesTrackSystemTargetVersion">YES</bool>
Please sign in to comment.
Something went wrong with that request. Please try again.