ASAP Framework has a follow-up: go to ASAP Library for our AS3 framework!
ASAP> ASAP Web>SoundSequencer (05 Nov 2005, ArthurClemens? )EditAttach

Sound Sequencer

Basically, I am trying to create a link between Sounds and Queues, where I can add Sounds to a queue (possibly an ActionQueue extension) and they are played in turn without any delay, to create a long loop.

This is a sequencer, you see! smile

The sequencer keeps an ordered list of sounds (as a single track) and the sequencer would create the ActionQueue which responds to the EventSound onSoundComplete callbacks to iterate through the queue.

Multiple tracks could be built up this way, and a main sequencer controller could start all the queues off together and keep things in sync...

Pseudo Code stub:

class SequencerTrack {
   
   private var _clipStack:Array; // this stack holds the sequence of sound clips in the correct order
   private var _clipPointer:Number; // a pointer to keep track of which clip we are playing
   private var _currentClip:SequencerClip;
   
   public function SequencerTrack:Void() {
      AsBroadcaster.initialize(this);
   }
   
   private function addClip(_clip:SequencerClip, _position:Number):Void {
      trace("addClip: " + _clip);
      this._clipStack.push(_clip);
      _clip.addListener(this);
   }
   
   private function removeClip( _position:Number)Void {
      trace("removeClip: " + _position);
      var _clip = this._clipStack[_position];
      _clip.removeListener(this);
      this._clipStack[_position] = null;      
   }
   
   private function startPlaying():Void {
      trace("startPlaying: ");
      this._currentClip = this._clipStack[0];
      this._currentClip.start();
   }
   
   private function onClipComplete(_clip:SequencerClip):Void {
      trace("onClipComplete: " + _clip);
      // called by the clip when it finishes playing
   }
   
   private function playNextClip():Void {
      trace("playNextClip: ");
      this._clipPointer ++;
      // get next clip from stack and tell it to play
      if(this.anyMoreClips()) {
         this._currentClip = this._clipStack[this._clipPointer];
         this._currentClip.start();
      } else {
         // if we have finished, loop
         this.resetPointer();
         this.startPlaying();
      }
   }
   
   private function anyMoreClips():Boolean {
      if(this._clipPointer => this._clipStack.length) { // we are on last clip
         return false;
      } else {
         return true;
      }
   }
   
   private function resetPointer():Void {
      this._clipPointer = 0;
   }
   
}

-- VishVishvanath - 04 Nov 2005

  • Having thunk about it a bit - Perhaps it might be better to simply extend the SoundManager to loop through an array of sounds and accept an onSoundComplete event. That would require the SoundClip to dispatch the onSoundComplete event and also require the extra event to be placed into SoundClipEvent. Not too hard. But would it work? -- VishVishvanath - 04 Nov 2005 - 07:50
  • The problem I think with this approach is that for multi-tracking we'd need several SoundManager instances (it is of course a Singleton). How to manage the several tracks? -- VishVishvanath - 04 Nov 2005 - 07:56

Perhaps of interest:

-- ArthurClemens? - 05 Nov 2005 - 00:39

In a previous project (not finished) I also played with the idea of a sequencer. See diagram:
SoundListController_diagram.png

Class hierarchy:

  • SoundListController = Sequencer
    • SoundListTrack = Track
      • TrackPart = sound clip controller, has an ActionQueue

-- ArthurClemens? - 05 Nov 2005

Category: Enhancements

Topic attachments
I Attachment Action Size Date Who Comment
pngpng SoundListController_diagram.png manage 17.3 K 05 Nov 2005 - 02:16 ArthurClemens?  
Topic revision: r5 - 05 Nov 2005 - 02:22:09 - ArthurClemens?

New site visitors: register here
Registered users may edit pages on this site.
Registration is free!
 
This site is powered by the TWiki collaboration platformCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding ASAP? Send feedback