Skip to content

Commit

Permalink
Style tweaks.
Browse files Browse the repository at this point in the history
  • Loading branch information
bryanveloso committed Feb 18, 2012
1 parent e0ed1ce commit 3bd4993
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 42 deletions.
3 changes: 1 addition & 2 deletions AppDelegate.h
Expand Up @@ -22,15 +22,14 @@
@property (weak) IBOutlet NSTextField *loopCountLabel; @property (weak) IBOutlet NSTextField *loopCountLabel;
@property (weak) IBOutlet NSStepper *loopCountStepper; @property (weak) IBOutlet NSStepper *loopCountStepper;



@property (assign) BOOL paused; @property (assign) BOOL paused;
@property (assign) QTTime startTime; @property (assign) QTTime startTime;
@property (assign) QTTime endTime; @property (assign) QTTime endTime;
@property (assign) QTTime currentTime; @property (assign) QTTime currentTime;
@property (assign) long timeScale; @property (assign) long timeScale;
@property (assign) int loopCount; @property (assign) int loopCount;


//The value where we'll start looping infinitely // The value where we'll start looping infinitely.
@property (assign) int loopInfiniteCount; @property (assign) int loopInfiniteCount;




Expand Down
89 changes: 49 additions & 40 deletions AppDelegate.m
Expand Up @@ -31,16 +31,18 @@ @implementation AppDelegate
@synthesize music; @synthesize music;
@synthesize paused; @synthesize paused;


-(void) setTheLoopCount:(int)theLoopCount{
//Sets the property and updates the label -(void) setTheLoopCount:(int)theLoopCount
{
// Sets the property and updates the label.
[self setLoopCount:theLoopCount]; [self setLoopCount:theLoopCount];
if([self loopCount] < [self loopInfiniteCount]) { if ([self loopCount] < [self loopInfiniteCount]) {
[loopCountLabel setStringValue:[NSString stringWithFormat:@"x%d",self.loopCount]]; [loopCountLabel setStringValue:[NSString stringWithFormat:@"x%d",self.loopCount]];
} }
else { else {
[loopCountLabel setStringValue:@""]; [loopCountLabel setStringValue:@""];
} }
//Finally update the stepper so it's synchronized // Finally update the stepper so it's synchronized.
[loopCountStepper setIntValue:[self loopCount]]; [loopCountStepper setIntValue:[self loopCount]];
} }


Expand Down Expand Up @@ -72,12 +74,13 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
[[self loopCountStepper] setMaxValue:(double)[self loopInfiniteCount]]; [[self loopCountStepper] setMaxValue:(double)[self loopInfiniteCount]];
} }


-(void) checkTime:(NSTimer*)theTimer{ -(void) checkTime:(NSTimer*)theTimer
{
currentTime = [music currentTime]; currentTime = [music currentTime];


if(currentTime.timeValue >= endTime.timeValue && startTime.timeValue < endTime.timeValue && [self loopCount] > 0){ if (currentTime.timeValue >= endTime.timeValue && startTime.timeValue < endTime.timeValue && [self loopCount] > 0){
if([self loopCount] < [self loopInfiniteCount]) { if ([self loopCount] < [self loopInfiniteCount]) {
//[self loopInfiniteCount] is the magic infinite number // [self loopInfiniteCount] is the magic infinite number.
[self setTheLoopCount:[self loopCount]-1]; [self setTheLoopCount:[self loopCount]-1];
} }
[music setCurrentTime:startTime]; [music setCurrentTime:startTime];
Expand All @@ -98,80 +101,84 @@ -(void) checkTime:(NSTimer*)theTimer{


} }


- (void)loadMusic:(NSURL *) fileURL { - (void)loadMusic:(NSURL *) fileURL
//Load the track from URL {
//TODO: Error handling // Load the track from URL.
// TODO: Error handling.
music = [[QTMovie alloc] initWithURL:fileURL error:nil]; music = [[QTMovie alloc] initWithURL:fileURL error:nil];


//Really needed anymore? //Really needed anymore?
paused = YES; paused = YES;


//Find and set slider max values // Find and set slider max values.
QTTime maxTime = [music duration]; QTTime maxTime = [music duration];
timeScale = [music duration].timeScale; timeScale = [music duration].timeScale;
float maxValue = (float)maxTime.timeValue; float maxValue = (float)maxTime.timeValue;
startTime = QTMakeTime(0.0,timeScale); startTime = QTMakeTime(0.0, timeScale);
endTime = maxTime; endTime = maxTime;

[currentTimeBar setMaxValue:maxValue]; [currentTimeBar setMaxValue:maxValue];
[startSlider setMaxValue:maxValue]; [startSlider setMaxValue:maxValue];
[startSlider setFloatValue:0.0]; [startSlider setFloatValue:0.0];
[endSlider setMaxValue:maxValue]; [endSlider setMaxValue:maxValue];
[endSlider setFloatValue:maxValue]; [endSlider setFloatValue:maxValue];
[startSlider setNumberOfTickMarks:(int) maxValue/timeScale]; [startSlider setNumberOfTickMarks:(int) maxValue/timeScale];
[endSlider setNumberOfTickMarks:(int) maxValue/timeScale]; [endSlider setNumberOfTickMarks:(int) maxValue/timeScale];

//Set title and artist labels from // Set title and artist labels from.
NSString * trackTitle = @"Unknown title"; NSString * trackTitle = @"Unknown title";
NSString * trackArtist = @"Unknown artist"; NSString * trackArtist = @"Unknown artist";

NSArray * mdFormatsArray = [music availableMetadataFormats]; NSArray * mdFormatsArray = [music availableMetadataFormats];
for(int i=0;i<[mdFormatsArray count];i++) { for (int i=0;i<[mdFormatsArray count];i++) {
NSArray * mdArray = [music metadataForFormat:[mdFormatsArray objectAtIndex:i]]; NSArray * mdArray = [music metadataForFormat:[mdFormatsArray objectAtIndex:i]];
//Fixme: find out why we need to replace @ with © // Fixme: find out why we need to replace @ with ©.
NSArray * titleMetadataItems = [QTMetadataItem metadataItemsFromArray:mdArray withKey:[QTMetadataiTunesMetadataKeySongName stringByReplacingOccurrencesOfString:@"@" withString:@"©"] keySpace:nil]; NSArray * titleMetadataItems = [QTMetadataItem metadataItemsFromArray:mdArray withKey:[QTMetadataiTunesMetadataKeySongName stringByReplacingOccurrencesOfString:@"@" withString:@"©"] keySpace:nil];
if([titleMetadataItems count] > 0) { if ([titleMetadataItems count] > 0) {
trackTitle = [[titleMetadataItems objectAtIndex:0] stringValue]; trackTitle = [[titleMetadataItems objectAtIndex:0] stringValue];
} }
//Fixme: find out why we need to replace @ with © // Fixme: find out why we need to replace @ with ©.
NSArray * artistMetadataItems = [QTMetadataItem metadataItemsFromArray:mdArray withKey:[QTMetadataiTunesMetadataKeyArtist stringByReplacingOccurrencesOfString:@"@" withString:@"©"] keySpace:nil]; NSArray * artistMetadataItems = [QTMetadataItem metadataItemsFromArray:mdArray withKey:[QTMetadataiTunesMetadataKeyArtist stringByReplacingOccurrencesOfString:@"@" withString:@"©"] keySpace:nil];
if([artistMetadataItems count] > 0) { if ([artistMetadataItems count] > 0) {
trackArtist = [[artistMetadataItems objectAtIndex:0] stringValue]; trackArtist = [[artistMetadataItems objectAtIndex:0] stringValue];
} }
} }


[currentTrackLabel setStringValue:[NSString stringWithFormat:@"%@\n%@",trackTitle,trackArtist]]; [currentTrackLabel setStringValue:[NSString stringWithFormat:@"%@\n%@",trackTitle,trackArtist]];

//Start loop and play track // Start loop and play track.
[NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(checkTime:) userInfo:nil repeats:YES]; [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(checkTime:) userInfo:nil repeats:YES];
} }


- (IBAction)startSliderSet:(id)sender { - (IBAction)startSliderSet:(id)sender
if([startSlider doubleValue] < (float)endTime.timeValue) { {
if ([startSlider doubleValue] < (float)endTime.timeValue) {
startTime = QTMakeTime((long)[startSlider doubleValue],timeScale); startTime = QTMakeTime((long)[startSlider doubleValue],timeScale);

} }
else{ else {
[startSlider setFloatValue:(float)startTime.timeValue]; [startSlider setFloatValue:(float)startTime.timeValue];
} }
} }


- (IBAction)endSliderSet:(id)sender { - (IBAction)endSliderSet:(id)sender
if([endSlider doubleValue] > (float)startTime.timeValue) { {
if ([endSlider doubleValue] > (float)startTime.timeValue) {
endTime = QTMakeTime((long)[endSlider doubleValue],timeScale); endTime = QTMakeTime((long)[endSlider doubleValue],timeScale);
} }
else{ else {
[endSlider setFloatValue:(float)endTime.timeValue]; [endSlider setFloatValue:(float)endTime.timeValue];
} }
} }


- (IBAction)currentTimeBarSet:(id)sender { - (IBAction)currentTimeBarSet:(id)sender
{
NSTimeInterval ct = [currentTimeBar doubleValue]; NSTimeInterval ct = [currentTimeBar doubleValue];
[music setCurrentTime:QTMakeTime((long)ct,timeScale)]; [music setCurrentTime:QTMakeTime((long)ct,timeScale)];
} }


- (IBAction)playButtonClick:(id)sender { - (IBAction)playButtonClick:(id)sender
if(!paused) { {
if (!paused) {
[music stop]; [music stop];
paused = YES; paused = YES;
} }
Expand All @@ -181,16 +188,18 @@ - (IBAction)playButtonClick:(id)sender {
} }
} }


- (IBAction)loopStepperStep:(id)sender { - (IBAction)loopStepperStep:(id)sender
{
[self setTheLoopCount:[loopCountStepper intValue]]; [self setTheLoopCount:[loopCountStepper intValue]];
} }


- (IBAction)openFile:(id)sender { - (IBAction)openFile:(id)sender
NSOpenPanel *openPanel = [NSOpenPanel openPanel]; {
NSInteger tvarNSInteger = [openPanel runModal]; NSOpenPanel *panel = [NSOpenPanel openPanel];
NSInteger tvarNSInteger = [panel runModal];
if(tvarNSInteger == NSOKButton){ if(tvarNSInteger == NSOKButton){
[music stop]; [music stop];
NSURL * fileURL = [openPanel URL]; NSURL *fileURL = [panel URL];
[self loadMusic:fileURL]; [self loadMusic:fileURL];
} }
} }
Expand Down

0 comments on commit 3bd4993

Please sign in to comment.