Plugin Cafe Homepage
Forum Home Forum Home > Plugin Cafe > PYTHON Development
  New Posts New Posts
  FAQ FAQ  Forum Search

Adjusting "Sound" Parameter of Sound Track

Author
Message
  Topic Search Topic Search
Donovan Keith View Drop Down
Member
Member


Joined: 2002 Oct 30
Location: United States
Online Status: Offline
Posts: 199
Direct Link To This Post Topic: Adjusting "Sound" Parameter of Sound Track
    Posted: 2011 Aug 03 at 3:37pm
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
Back to Top
s_rath View Drop Down
Member
Member


Joined: 2010 May 04
Location: Ne / Düsseldorf
Online Status: Offline
Posts: 319
Direct Link To This Post Posted: 2011 Aug 11 at 10:25am
Hi, please set the filename via the BaseContainer from GetDataInstance().

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

Cheers, Sebastian
Back to Top
ScottA View Drop Down
Member
Member


Joined: 2011 Jan 07
Online Status: Offline
Posts: 2288
Direct Link To This Post Posted: 2011 Aug 11 at 11:46am
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
Back to Top
ScottA View Drop Down
Member
Member


Joined: 2011 Jan 07
Online Status: Offline
Posts: 2288
Direct Link To This Post Posted: 2011 Aug 14 at 10:34am
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
Back to Top
maxx_981 View Drop Down
Member
Member


Joined: 2011 Apr 12
Location: CH
Online Status: Offline
Posts: 172
Direct Link To This Post Posted: 2011 Aug 19 at 10:20am
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
Back to Top
80prozent View Drop Down
Member
Member


Joined: 2011 Apr 17
Online Status: Offline
Posts: 7
Direct Link To This Post Posted: 2013 Jun 26 at 9:08am
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

Back to Top
80prozent View Drop Down
Member
Member


Joined: 2011 Apr 17
Online Status: Offline
Posts: 7
Direct Link To This Post Posted: 2013 Jun 26 at 9:15am
argh - sorry
no still doesnt work

just the filename is shown in the linkBox, but the sound is still not loaded in correctly....
Back to Top
MarcPearson View Drop Down
Member
Member
Avatar

Joined: 2012 Jan 19
Online Status: Offline
Posts: 36
Direct Link To This Post Posted: 2013 Nov 19 at 2:33pm
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.


Edited by MarcPearson - 2013 Nov 19 at 2:40pm
-Marc
Back to Top

Forum Jump Forum Permissions View Drop Down

Bulletin Board Software by Web Wiz Forums® version 9.61 [Free Express Edition]
Copyright ©2001-2009 Web Wiz

This page was generated in 0.141 seconds.