Trigger animations and actions by song position

  • #1, by LebosteinTuesday, 31. January 2017, 09:58 3 years ago
    For example a guitar player. He should move his arm fast at fast song parts and slow at slow song parts. Or he should speak the song text at specific song positions. How I can do that? How I can trigger animations or actions at specific song positions?

    Thanks!

    Key Killer

    601 Posts


  • #2, by afrlmeTuesday, 31. January 2017, 12:19 3 years ago
    For example a guitar player. He should move his arm fast at fast song parts and slow at slow song parts. Or he should speak the song text at specific song positions. How I can do that? How I can trigger animations or actions at specific song positions?

    Thanks!
    One of two ways I guess...

    1. by using the pause action parts to control when to play a specific kind of animation or force which frames of an animation should be looped with the AnimationFirstFrame & AnimationLastFrame data structure fields.
    -- force animation "example" to loop between frames 3 to 5
    ActiveAnimations["example"].AnimationFirstFrame = 3
    ActiveAnimations["example"].AnimationLastFrame = 5
    1
    2
    3


    2. Optionally you could play the song with Lua script via the openAL player & then use a mainLoop to query the current playback position (offset) to start an animation or call an action. It's probably closer to what you are asking, but a lot more complicated than the action part method & it's possible that the mainLoop could miss the range window if the queried values are too small.

    3. Actually, yes I know I said 1 of 2 ways but I just thought of another solution that might work as I don't think sounds fade in/out when you play them, so what you could do is chop up the song into parts, then you play one & then start the animation or action associated with it & then add a wait until sound "x" has finished playing then immediately play the next sound & so on.

    Whichever way you go about it will require a bit of hard work & some patience.

    Good luck. wink

    Imperator

    6842 Posts

  • #3, by LebosteinTuesday, 31. January 2017, 12:34 3 years ago
    Thanks for the hints. It is possible to examine the song position of the current music (in milliseconds for example) directly? Or other way: can I set the song position of the current music? I have programmed with FMOD long time ago an there was functions like SetPosition() and GetPosition() for music streams... Maybe there are similar things in the Visionaire music system.

    Key Killer

    601 Posts

  • #4, by sebastianTuesday, 31. January 2017, 12:38 3 years ago
    yes. via lua and the getSoundProperty function:

    Thread Captain

    2337 Posts

  • #5, by LebosteinTuesday, 31. January 2017, 12:44 3 years ago
    Ah! Now I have all the things I need. Thanks!

    Key Killer

    601 Posts

  • #6, by afrlmeTuesday, 31. January 2017, 13:24 3 years ago
    Quick note: I recommend querying a range rather than a single specific time value as the time between each loop with the mainLoop event handler varies on each loop so in theory it's entirely possible that you could miss such a narrow window.

    By range, I mean something like: >= 1000 & < 1500.
    local sndID = getSoundId("vispath:sounds/example.ogg")
    local sndOffset = getSoundProperty(sndID, "offset")

    if sndOffset >;= 1000 and sndOffset <; 1500 then
     startAction("Actions[action 1]")
    elseif sndOffset >;= 1500 and sndOffset <; 2000 then
     startAction(Scenes["x"].SceneActions["action 2"])
    end
    1
    2
    3
    4
    5
    6
    7
    8


    The safest approach would be the third option I mentioned, but using a Lua script approach would probably save a lot of time overall.

    * edit: code blocks seem to be automatically adding in ; for some reason.

    Imperator

    6842 Posts

Write post