Timing animation to soundtracks

Date:    Wed, 23 Aug 1995 17:57:59 +1000
From:    Dorian Dowse 
Subject: TIP - Timing animation to soundtracks
I recently was doing a presentation in Director with a long audio voiceover that required a series of events to occur cued to various parts of the speech.

I so was pleased with the solution I came up with, that I thought I'd post it on the list.


Timing animation to soundtracks

by Dorian Dowse <dorian@peg.apc.org>

This script is for getting Director to wait for audio cues. It comes in 2 parts.

PART ONE - RECORD

The first part is for generating a cueList You can use a seperate movie for this purpose Paste the following handlers into the movie script. Start the movie. The first keypress starts the timer and the sound. Following key presses are stored in the cuelist. Just tap a key to add a cue while the sound is playing.

on startMovie
  global cueList
  set cueList=[]
  set the keyDownScript to "do startSound()"
  pause
end

on startSound
  startimer
  sound playFile 1, "sound.aif"
  set the keyDownScript to "do addCue()"
end

on addCue
  global cueList
  if soundBusy(1) then
    add Cuelist, the timer
  else
    add Cuelist, the timer
    set the keyDownScript to ""
    put cueList
  end if
end

When the sound has finished, the cue list is put in the message window select it and copy it to the clipboard.

PART TWO - PLAYBACK

The second part is for playback. Go to the movie that requires the timed pauses and paste the cuelist into the following handler
on starMovie
  global cueList, cuePos
  set cueList = ["paste the cueList from the message window here"]
  set cuePos = 1
end

on playSound
  starTimer
  sound playFile 1, "sound.aif"
end
Put the exitFrame handler in the frame script of each frame where you want a cued paused. This handler will loop until the cue is reached, then continue on to the next frame. it could also launch scripts, objects, etc.
on exitFrame
  --waitForCue
  global cueList, cuePos
  if the timer > getAt(cueList,cuePos) then
    set cuePos = cuePos + 1
  else
    go to the frame
  end if
end