Adjusting "Sound" Parameter of Sound Track



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 03/08/2011 at 15:37, xxxxxxxx wrote:

    Hi,

    Is it possible to adjust the properties of special tracks? Specifically: the filename parameter of the Sound track?

    Here's what I'm doing now:

      
         #Add a Sound track   
         sound_track = c4d.CTrack(sound_obj, c4d.DescID(c4d.DescLevel(c4d.CTsound, c4d.CTsound, 0)))   
         sound_obj.InsertTrackSorted(sound_track)   
      
         #Set the Sound property to the wav file NOT WORKING   
         sound_track[c4d.CID_SOUND_NAME] = "Test.wav"   
      
         if debug:   
              print "sound_track[c4d.CID_SOUND_NAME] = ", sound_track[c4d.CID_SOUND_NAME]   
            
         #Tell C4D something has changed   
         c4d.EventAdd()   
    

    Unfortunately, it's not working. I get this error:

    "IndexError: Invalid key type."

    Any ideas would be greatly appreciated.
    Thanks,

    Donovan



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 11/08/2011 at 10:25, xxxxxxxx wrote:

    Hi, please set the filename via the BaseContainer from GetDataInstance().

    bc=sound_obj.GetDataInstance()
    bc.SetFilename(c4d.CID_SOUND_NAME, "Test.wav")

    Cheers, Sebastian



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 11/08/2011 at 11:46, xxxxxxxx wrote:

    That will add the text location of where the sound file is located to the field.
    But C4D doesn't seem to actually load the file this way. There seems to be a missing step needed that tells C4D to load it.

    Here's a full example:

    import c4d  
    from c4d import gui  
      
    def main() :   
      obj = doc.GetActiveObject()   
      sound_track = c4d.CTrack(obj, c4d.DescID(c4d.DescLevel(c4d.CTsound, c4d.CTsound, 0)))  
      obj.InsertTrackSorted(sound_track)  
      bc = sound_track.GetDataInstance()  
      
      path = "\\Users\\user\\Desktop\\moviemix.wav"  #The path to the .wav file    
      bc.SetFilename(c4d.CID_SOUND_NAME, path)       #Set the Sound property to the wav file  
      sound_track.Message(c4d.MSG_UPDATE)  
      c4d.EventAdd()  
        
    if __name__=='__main__':  
      main()
    

    Any idea how to get C4D to update and load the sound file. Based on the text in the field?

    -ScottA



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 14/08/2011 at 10:34, xxxxxxxx wrote:

    Hello?

    I've tried this a bunch of ways. And even though the file is there in the container. It's not being loaded:

    import c4d  
    from c4d import gui  
      
    def main() :   
      obj = doc.GetActiveObject()   
      sound_track = c4d.CTrack(obj, c4d.DescID(c4d.DescLevel(c4d.CTsound, c4d.CTsound, 0)))  
      obj.InsertTrackSorted(sound_track)  
      bc = obj.GetDataInstance()  
      bc.SetFilename(c4d.CID_SOUND_NAME, "C:\\Users\\user\\Desktop\\moviemix.wav")  
      
      #The file **is** there in the container. But it's not being loaded into C4D!  
      print bc.FindIndex(c4d.CID_SOUND_NAME)   
      
      
      #Even trying to **force** an update does nothing!  
      sound_track.Message(c4d.MSG_UPDATE)  
      sound_track.SetData(bc)  
      obj.SetData(bc)  
      
      c4d.EventAdd()  
        
    if __name__=='__main__':  
      main()
    

    It works properly in C++ using SetParameter:

        BaseObject *sphere = BaseObject::Alloc(Osphere);  
      doc->InsertObject(sphere, NULL, NULL);   
      CTrack *soundtrack = CTrack::Alloc(sphere, DescID(DescLevel(CTsound,CTsound,0L)));   
      sphere->InsertTrackSorted(soundtrack);     
      
      soundtrack->SetParameter(DescID(DescLevel(CID_SOUND_START, DTYPE_TIME,0L)), doc->GetTime(), DESCFLAGS_SET_0);      
      Filename file = GeGetC4DPath(C4D_PATH_DESKTOP) + "moviemix.wav";  
      soundtrack->SetParameter(DescLevel(CID_SOUND_NAME),file,DESCFLAGS_SET_0);  
      
      EventAdd();  
      return true;
    

    Is this a bug?
    Am I doing something wrong?

    -ScottA



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 19/08/2011 at 10:20, xxxxxxxx wrote:

    Hy Scott,

    I tested your code with the same results that you get. What I find strange, once you attempt to load a wav in this manner, you also can't load the wav "manually" afterwards. Does not work anymore, on the "self" constructed Track ...

    Cheers,
    maxx



  • On 26/06/2013 at 09:08, xxxxxxxx wrote:

    Hi
    I just figured this out:
    instead of:

      bc = obj.GetDataInstance()  
      bc.SetFilename(c4d.CID_SOUND_NAME, "C:\\Users\\user\\Desktop\\moviemix.wav")
    

    try:

      bc = sound_track.GetDataInstance()  
      bc.SetFilename(c4d.CID_SOUND_NAME, "C:\\Users\\user\\Desktop\\moviemix.wav")
    

    for me, this did the trick



  • On 26/06/2013 at 09:15, xxxxxxxx wrote:

    argh - sorry
    no still doesnt work

    just the filename is shown in the linkBox, but the sound is still not loaded in correctly....



  • On 19/11/2013 at 14:33, xxxxxxxx wrote:

    I know this is an old thread, but I just happen to be attempting this on a project of mine. I am using this code in a Python node in Xpresso. The creation and removal of the CTrack is working perfectly, but the setting of the file path does not. Anything obviously wrong with this code?

    def main() :
        global Output1
        Output1 = 1
        
        bc = myObj.GetDataInstance() #myObj is a Null in the scene and used as an input port
        myTrack = c4d.CTrack(myObj,c4d.DescID(c4d.DescLevel(c4d.CTsound,c4d.CTsound, 0)))
        
        if myTime == 1: #myTime is another input, taking in the current frame so only creates on frame 1
            myObj.InsertTrackSorted(myTrack)
            bc.SetFilename(c4d.CID_SOUND_NAME, mySoundFile) #mySoundFile is a filename input port
            Output1 = 1
            c4d.EventAdd()
        elif myTime == 0:
            for track in myObj.GetCTracks() :
                track.Remove()
                c4d.EventAdd()
                Output1 = 1
            return()

    I am trying to make this a portable rig so that I can link to a file in the user data of the master Null and have that file trickle down into a sound track and a Sound Effector.


Log in to reply