From f035fd1cc246478de05ce26a29e19535065825db Mon Sep 17 00:00:00 2001 From: vspader Date: Sun, 29 Jan 2006 14:57:48 +0000 Subject: [PATCH] Status now updates --- PlaybackController.h | 2 +- PlaybackController.m | 25 +++++++++++++++++++------ Playlist/PlaylistController.h | 4 ++-- Playlist/PlaylistController.m | 12 ++++++++---- Sound/OutputCoreAudio.m | 10 ++++++++++ Sound/OutputNode.m | 10 ++++++++++ Sound/SOUNDTODO | 2 +- Sound/SoundController.h | 1 + Sound/SoundController.m | 20 ++++++++++++++++++-- 9 files changed, 70 insertions(+), 16 deletions(-) diff --git a/PlaybackController.h b/PlaybackController.h index dcac5c3c0..2a0e233f5 100644 --- a/PlaybackController.h +++ b/PlaybackController.h @@ -51,7 +51,7 @@ //Methods since this is SoundController's delegate -- (void)delegateNotifyStatusUpdate:(int)status; +- (void)delegateNotifyStatusUpdate:(NSNumber *)status; - (void)delegateNotifyPositionUpdate:(double)pos; - (void)delegateNotifyBitrateUpdate:(float)bitrate; - (void)delegateNotifySongChanged:(double)length; diff --git a/PlaybackController.m b/PlaybackController.m index ccc71eaf2..cdf155bf3 100644 --- a/PlaybackController.m +++ b/PlaybackController.m @@ -84,24 +84,36 @@ - (void)playEntry:(PlaylistEntry *)pe; { // DBLog(@"PlayEntry: %@ Sent!", [pe filename]); - + if (playbackStatus != kCogStatusStopped) + [self stop:self]; [soundController play:[pe filename]]; } - (IBAction)next:(id)sender { - if ([playlistController next] == nil) + NSLog(@"CALLING: %i %i", playbackStatus, kCogStatusStopped); + if ([playlistController next] == NO) return; - - [self playEntry:[playlistController currentEntry]]; + + if (playbackStatus != kCogStatusStopped) + { + NSLog(@"STOPPING"); + [self stop:self]; + [self playEntry:[playlistController currentEntry]]; + } } - (IBAction)prev:(id)sender { + NSLog(@"CALLING"); if ([playlistController prev] == nil) return; - [self playEntry:[playlistController currentEntry]]; + if (playbackStatus != kCogStatusStopped) + { + [self stop:self]; + [self playEntry:[playlistController currentEntry]]; + } } - (IBAction)seek:(id)sender @@ -204,8 +216,9 @@ } -- (void)delegateNotifyStatusUpdate:(int)status +- (void)delegateNotifyStatusUpdate:(NSNumber *)s { + int status = [s intValue]; if (status == kCogStatusStopped || status == kCogStatusPaused) { //Show play image diff --git a/Playlist/PlaylistController.h b/Playlist/PlaylistController.h index 0bd31c1f9..2fcd19aa8 100644 --- a/Playlist/PlaylistController.h +++ b/Playlist/PlaylistController.h @@ -52,8 +52,8 @@ - (id)currentEntry; - (void)setCurrentEntry:(PlaylistEntry *)pe; -- (void)next; -- (void)prev; +- (BOOL)next; +- (BOOL)prev; - (PlaylistEntry *)entryAtOffset:(int)offset; - (void)addShuffledListToBack; diff --git a/Playlist/PlaylistController.m b/Playlist/PlaylistController.m index abe5121c3..c20626e5b 100644 --- a/Playlist/PlaylistController.m +++ b/Playlist/PlaylistController.m @@ -319,29 +319,33 @@ } } -- (void)next +- (BOOL)next { PlaylistEntry *pe; pe = [self entryAtOffset:1]; if (pe == nil) - return; + return NO; [self setCurrentEntry:pe]; + + return YES; } -- (void)prev +- (BOOL)prev { PlaylistEntry *pe; pe = [self entryAtOffset:-1]; if (pe == nil) - return; + return NO; if (shuffle == YES) shuffleIndex--; [self setCurrentEntry:pe]; + + return YES; } - (void)addShuffledListToBack diff --git a/Sound/OutputCoreAudio.m b/Sound/OutputCoreAudio.m index 5b0157852..da5d09bbe 100644 --- a/Sound/OutputCoreAudio.m +++ b/Sound/OutputCoreAudio.m @@ -154,4 +154,14 @@ static OSStatus Sound_Renderer(void *inRefCon, AudioUnitRenderActionFlags *ioAc } } +- (void)pause +{ + AudioOutputUnitStop(outputUnit); +} + +- (void)resume +{ + AudioOutputUnitStart(outputUnit); +} + @end diff --git a/Sound/OutputNode.m b/Sound/OutputNode.m index 43cc8f5a7..687153183 100644 --- a/Sound/OutputNode.m +++ b/Sound/OutputNode.m @@ -23,6 +23,16 @@ [output start]; } +- (void)pause +{ + [output pause]; +} + +- (void)resume +{ + [output resume]; +} + - (int)readData:(void *)ptr amount:(int)amount { int n; diff --git a/Sound/SOUNDTODO b/Sound/SOUNDTODO index b1ab8134b..722723cc3 100644 --- a/Sound/SOUNDTODO +++ b/Sound/SOUNDTODO @@ -2,7 +2,7 @@ Need to have soundcontroller or outputnode keep a count of how much was played. Need to integrate with UI (AppController). Limit the number of queued elements (2 would probably be good, maybe 3). -Need to finish implementation of setVolume, seekToTime, pause, play, resume, stop, etc. +Need to finish implementation of seekToTime, pause, play, resume, stop, etc. diff --git a/Sound/SoundController.h b/Sound/SoundController.h index 5160e6204..08a8b58b4 100644 --- a/Sound/SoundController.h +++ b/Sound/SoundController.h @@ -38,6 +38,7 @@ - (void)setVolume:(double)v; - (void)setNextSong:(NSString *)s; +- (void)setPlaybackStatus:(int)s; @end diff --git a/Sound/SoundController.m b/Sound/SoundController.m index fafeaf915..39a3b44ec 100644 --- a/Sound/SoundController.m +++ b/Sound/SoundController.m @@ -7,7 +7,7 @@ // #import "SoundController.h" - +#import "Status.h" @implementation SoundController @@ -41,22 +41,29 @@ [output launchThread]; [bufferChain launchThreads]; + + [self setPlaybackStatus:kCogStatusPlaying]; } - (void)stop { //Set shouldoContinue to NO on allll things [self setShouldContinue:NO]; + [self setPlaybackStatus:kCogStatusStopped]; } - (void)pause { [output pause]; + + [self setPlaybackStatus:kCogStatusPaused]; } - (void)resume { [output resume]; + + [self setPlaybackStatus:kCogStatusPlaying]; } - (void)seekToTime:(double)time @@ -108,8 +115,12 @@ - (void)endOfInputPlayed { if ([chainQueue count] <= 0) + { + //End of playlist + [self setPlaybackStatus:kCogStatusStopped]; + return; - + } // NSLog(@"SWAPPING BUFFERS"); [bufferChain release]; @@ -125,6 +136,11 @@ // NSLog(@"SWAPPED"); } +- (void)setPlaybackStatus:(int)s +{ + [delegate performSelectorOnMainThread:@selector(delegateNotifyStatusUpdate:) withObject:[NSNumber numberWithInt:s] waitUntilDone:NO]; +} + - (BufferChain *)bufferChain { return bufferChain;