Graphics

 View Only
Expand all | Collapse all

Scripting to update audiofile

  • 1.  Scripting to update audiofile

    Posted 03-19-2015 13:34

    Hello,

    I am new to Xpressions scripting and have a questions about updating an audio file. I have the file's path/name in a hidden text object and I am stuck on something, just not sure what. Here is what I have so far. It is in the OnOnline scripting event.


    dim AudioFilePath as xpBaseObject

    dim AudioFile as xpAudioFile

    Self.GetObjectByName("AudioFilePath", AudioFilePath)

    Self.GetAudioFileByName("AudioFile",AudioFile)

    AudioFile.SetFileName(AudioFilePath.text)



    After I compile this, I get no errors, but it still keeps playing the original file, not the one using the file name/path provided.

    Thank you in advance for the assistance. I am quite excited to get a better understanding.

    Regards,

    Mike



  • 2.  RE: Scripting to update audiofile

    Posted 03-19-2015 13:44
    It should be `engine.GetAudioFileByName` not `Self.GetAudioFileByName`. The audio file is part of the xpEngine object, not the xpScene object.

    #XPression


  • 3.  RE: Scripting to update audiofile

    Posted 03-19-2015 15:13
    That's excellent. Can't believe I missed that.

    How do I now take the clip offline after a certain number of frames? I have the length of the song in seconds. I can multiply that by 30 to get the number of frames. But I don't see a method to setoffline after a certain number of frames. Maybe I am not seeing it.

    Thanks again for your help.

    Mike

    #XPression


  • 4.  RE: Scripting to update audiofile

    Posted 03-19-2015 18:42
    There is an offline event you can add to the Scene Director that will take the scene offline.

    #XPression


  • 5.  RE: Scripting to update audiofile

    Posted 03-20-2015 15:05
    Thanks Dan. Are you referring to when I right click then Add Clip, Event, Take Offline?

    That is the action I am trying to do. My issue is since the duration of my audio clips varies how can I make the location of that Take Offline event dependent on the duration of the file?

    I could also use this to clear the frame buffer for this layer.

    engine.ClearFrameBuffer(1,1)

    How do I delay this command from happening until after X number of seconds or frames?

    Thanks again for your suggestions

    #XPression


  • 6.  RE: Scripting to update audiofile

    Posted 03-20-2015 15:16
    That is the event I was talking about. I feel like there was a discussion not that long ago that went over variable Take Offline through scripting. If I remember correctly, he ended up building multiple animation controllers, then used keyboard mapping and script input to change the play range of the scene director depending on what he needed. It was for a game show.

    You might want to try searching back a bit for similar topics. Your answer may already be here.

    #XPression


  • 7.  RE: Scripting to update audiofile

    Posted 03-20-2015 15:22
    You could add the take offline event to a scene director track that is disabled.. Then through scripting you could enable the track and move the event to the correct frame number based in the audio clip duration. Look in the SDK for the xpscendirectortrack and xpscendirectorclip objects.

    #XPression


  • 8.  RE: Scripting to update audiofile

    Posted 03-20-2015 18:55
    That sounds like a good method, move the position of the Event clip on the director track.

    I have gotten this far and I think I am close but am not getting any result:

    dim eventTrack as xpSceneDirectorTrack

    dim offlineEventClip as xpSceneDirectorClip

    dim sceneDir as xpSceneDirector

    ' This might be the issue. How do I find the index of the scene director?

    Self.GetSceneDirector(1,sceneDir)

    sceneDir.GetTrackByName("Track1",eventTrack)

    eventTrack.GetClipByName("OfflineEvent",offlineEventClip)

    offlineEventClip.Position = 90

    I set position 90 just to confirm if it works. I will replace with the number of frames after.

    #XPression


  • 9.  RE: Scripting to update audiofile

    Posted 03-20-2015 19:11
    Scenedirectors are numbered starting from 0, so the first scene director would be `Self.GetSceneDirector(0, sceneDir)`

    or you can just do `Self.SceneDirector.GetTrackByName`

    To debug scripting easier, turn on the Preference in the Advanced Preferences menu to enable debug monitor output for scripts. (Restart XPression after enabling it). Then you can output debug messages and do something like this..

    `if sceneDir.GetTrackByName("Track1", track) = false then

    engine.DebugMessage("Could not get Track named Track1.", 1)

    end if`

    Most XPression SDK calls return true or false based on if the call succeeded or not.

    If the script has something wrong in it, like you try calling a function that doesn't exist etc, the script will still compile but will usually immediately exit when it hits the error in the script.

    Even just adding an `engine.DebugMessage` at various points in the script can help you confirm that it is reaching a particular line in the script and didn't exit due to a failure.

    #XPression


  • 10.  RE: Scripting to update audiofile

    Posted 03-20-2015 19:17
    Scene directors are also named, so you can get them by name, `self.GetSceneDirectorByName("MySceneDir", scenedir)`

    `Self.SceneDirector` always returns the "default" scenedirector which can be set in the XPression layout mode.

    #XPression


  • 11.  RE: Scripting to update audiofile

    Posted 03-02-2020 23:00

    I know this is a very old thread but I have come across a use for just this sort of thing. @Mike Krebs, do you still have a working model that you would be willing to share? My application is just a little different but this could do the job.


    #XPression


  • 12.  RE: Scripting to update audiofile

    Posted 03-10-2020 17:52

    <x-zendesk-user data-user-name="Malcolm Thorpe">369642859871</x-zendesk-user>   Here is the scripting I ended up using.  In my scene I also had a text object for the volume amount and the name of the track.  We have all the files living on a shared NAS that all of our machines connect to.  

    I also created a GPI that you can trigger while the file is playing.  The GPI will add keyframes for the volume to fade out after 5 seconds.  Let me know if I can help any way.  

     

    dim AudioFile as xpAudioFile
    dim AudioFileName as xpBaseObject

    Self.GetObjectByName("AudioFileName",AudioFileName)
    if AudioFile.SetFileName("D:\Audio\" & AudioFileName.text) = true then

    end if

    dim eventTrack as xpSceneDirectorTrack
    dim offlineEventClip as xpSceneDirectorClip
    dim sceneDir as xpSceneDirector

    Self.GetSceneDirectorByName("SceneDirector1",sceneDir)
    sceneDir.GetTrackByName("Track1",eventTrack)
    eventTrack.GetClipByName("OfflineEvent",offlineEventClip)

    dim KeyFrameVol as xpBaseObject
    dim AudioFileClip as xpSceneDirectorClip
    dim AudioTrack as xpSceneDirectorTrack
    dim posit as Long
    dim value as Double

    Self.GetObjectByName("Volume",KeyFrameVol)

    posit = Clng(1)
    value = Cdbl(KeyFrameVol.text)

    sceneDir.GetTrackByName("Audio1",AudioTrack)
    AudioTrack.GetClipByName("AudioFile1",AudioFileClip)
    AudioFileClip.SetKeyFrame(posit,value)

    '  Set the offline clip at the end of the track
    offlineEventClip.Position = AudioFileClip.Duration + 30


    #XPression