It would really help if I attached the file...
@interface NSSound : NSObject <NSCoding, NSCopying>
{               
  NSString *_name;
  NSData   *_data;
  NSString *_playbackDeviceIdentifier; // Currently unused
  NSArray  *_channelMapping; // Currently unused
  BOOL     _onlyReference;
  id       _delegate;
  NSTimeInterval _duration;
  
  // Private info:
  //   0 - input bundle (id<GSSoundSource>)
  //   1 - output bundle (id<GSSoundSink>)
  //   2 - lock (NSConditionLock *)
  void *_private[4];
  BOOL _shouldStop;
}



- (void)_stream
{
  NSUInteger bytesRead;
  BOOL bytesWereWritten;
  BOOL success;
  void *bytes;
  
  bytes = NSZoneMalloc(NSDefaultMallocZone(), BUFFER_SIZE);
  bytesRead = [(id<GSSoundSource>)_private[0] readBytes: bytes length: 
BUFFER_SIZE];
  while ((!_shouldExit) || (bytesRead > 0) || (!success))
    {
      /* FIXME */
      if ([(NSConditionLock*)_private[2] condition] == SOUND_SHOULD_PAUSE)
        {
          [(NSConditionLock*)_private[2] lockWhenCondtion: SOUND_SHOULD_PLAY];
          [(NSConditionLock*)_private[2] unlock];
        }
      success = [(id<GSSoundSink>)_private[1] writeBytes: bytes length: 
bytesRead];
      bytesRead = [(id<GSSoundSource>)_private[0] readBytes: bytes length: 
BUFFER_SIZE];
    }
  
  [self performSelectorOnMainThread: @selector(_finished:)
                         withObject: [NSNumber numberforBool: success]
                      waitUntilDone: NO];
}

- (BOOL) pause 
{
  if ([(NSConditionLock*)_private[2] condition] == SOUND_SHOULD_PAUSE)
    {
      return NO;
    }
  if ([(NSConditionLock*)_private[2] tryLock] == NO)
    {
      return NO;
    }
  [(NSConditionLock*)_private[2] unlockWithCondition: SOUND_SHOULD_PAUSE];
  return YES;
}

- (BOOL) play
{
  // If the NSCondtionLock exists it's because NSSound is either playing or 
paused
  if ((NSConditionLock*)_private[2] != nil)
    {
      return NO;
    }
  
  _private[2] = (void *)[NSCondtionLock initWithCondition: SOUND_SHOULD_PAUSE];
  /* FIXME */
  if ([(NSConditionLock*)_private[2] tryLock] != YES)
    {
      return NO;
    }
  
  [[(NSConditionLock*)_private[2] unlockWithCondition: SHOUND_SHOULD_PLAY];
  return YES;
}

- (BOOL) resume
{
  if ([(NSConditionLock*)_private[2] condition] == SOUND_SHOULD_PLAY)
    {
      return NO;
    }
  if ([(NSConditionLock*)_private[2] tryLock] == NO)
    {
      return NO;
    }
  [(NSConditionLock*)_private[2] unlockWithCondition: SOUND_SHOULD_PLAY];
  return YES;
}

- (BOOL) stop
{
  if ((NSConditionLock*)_private[2] == nil)
    {
      return NO;
    }
  /* FIXME */
  _shouldStop = YES;
  
  RELEASE((NSConditionLock*)_private[2]);
  
  return YES;
}

- (BOOL) isPlaying
{
  if ([(NSConditionLock*)_private[2] condition] == SOUND_SHOULD_PLAY)
    {
      return YES;
    }
  return NO;
}
_______________________________________________
Gnustep-dev mailing list
Gnustep-dev@gnu.org
http://lists.gnu.org/mailman/listinfo/gnustep-dev

Reply via email to