Creating a sound Track



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

    On 13/08/2011 at 09:40, xxxxxxxx wrote:

    User Information:
    Cinema 4D Version:   12 
    Platform:   Windows  ;   
    Language(s) :     C++  ;

    ---------
    Hi,
    I can't get a sound file to load into a sound track properly using Python. So I'm giving it a try with C++. But I'm running having problems creating a sound track.

    C4D is crashing on me. And I don't know what I'm doing wrong:

    Bool SimplePlugin::Execute(BaseDocument *doc)  
    {  
      BaseObject *sphere = BaseObject::Alloc(Osphere);  
      doc->InsertObject(sphere, NULL, NULL); // Add it to the OM  
      
      CTrack *soundtrack = CTrack::Alloc(sphere,DescLevel(CTsound,DTYPE_LONG,0));  //SDK says this: CTrack::Alloc(op,DescLevel(ID,ID,0))    
      sphere->InsertTrackSorted(soundtrack); //This crashes C4D!!!  
      
      //Then I need to load a sound file from my desktop into the sound field  
       
      EventAdd();  
        
      return true;  
    }
    

    I think I might be using the wrong code in the second Alloc ID parameter.
    Can anyone offer any help on creating a sound track and loading a sound file into it?

    -ScottA



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

    On 13/08/2011 at 12:42, xxxxxxxx wrote:

    I figured out where my the crashing mistake was.
    Now that I can successfully create a sound track. How do I load a file into it?
    If I use the base container method. It just loads the file's text information into the sound field. But it doesn't actually load the file into the track:

    Bool SimplePlugin::Execute(BaseDocument *doc)  
    {  
      BaseObject *sphere = BaseObject::Alloc(Osphere);  
      doc->InsertObject(sphere, NULL, NULL); // Add it to the OM   
      CTrack *soundtrack = CTrack::Alloc(sphere,DescLevel(CTsound,CTsound,0));  
      sphere->InsertTrackSorted(soundtrack);   
      
      Filename file = GeGetC4DPath(C4D_PATH_DESKTOP) + "moviemix.wav";  
      BaseContainer bc = soundtrack->GetData();  
      bc.SetFilename(CID_SOUND_NAME, file);  
      soundtrack->SetData(bc);  
       
      EventAdd();      
      return true;  
    }
    

    This is the same problem I was having with Python.

    -ScottA



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

    On 13/08/2011 at 15:38, xxxxxxxx wrote:

    Here's how I do it:

        // Add Sound track to Null object  
      CTrack*        track =        CTrack::Alloc(nullObj, DescID(DescLevel(ID_ANIM_SOUND,ID_ANIM_SOUND,0L)));  
      if (!track)                return ErrorException::OOMThrow(EE_NODIALOG, logging, GeLoadString(IPPERR_MEMORY_TEXT), "IPPLoader.AddSound.track");  
      nullObj->InsertTrackSorted(track);  
      if (storeUndoLoad)        baseDocument->AddUndo(UNDOTYPE_NEW, track);  
      // Set Start Time and Sound  
      // - Unofficial means to load audio file into SoundTrack  
      SoundTrack*    sdata =        (SoundTrack* )track->GetNodeData();  
      if (!sdata)                return ErrorException::Throw(EE_NODIALOG, logging, GeLoadString(IPPERR_MEMORY_TEXT), "IPPLoader.AddSound.sdata");  
      if (!sdata->sound)        return ErrorException::Throw(EE_NODIALOG, logging, GeLoadString(IPPERR_MEMORY_TEXT), "IPPLoader.AddSound.sdata->sound");  
      if (!sdata->sound->Load(sname))    return ErrorException::Throw(EE_NODIALOG, logging, GeLoadString(IPPERR_MEMORY_TEXT), "IPPLoader.AddSound.sdata->sound->Load(fn)");  
      // -  
      track->SetParameter(DescID(DescLevel(CID_SOUND_START, DTYPE_TIME,0L)), baseDocument->GetTime(), DESCFLAGS_SET_0);  
      //track->SetParameter(DescID(DescLevel(CID_SOUND_NAME, DTYPE_STRING,0L)), sname.GetFileString(), DESCFLAGS_SET_0);  
      track->SetParameter(DescLevel(CID_SOUND_NAME),sname.GetFileString(),DESCFLAGS_SET_0);  
      track->SetName(sname.GetFileString());  
      EventAdd();  
    


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

    On 13/08/2011 at 15:39, xxxxxxxx wrote:

    Note that ID_ANIM_SOUND is typdef'd from CTsound for backward compatibility; just use CTsound.



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

    On 13/08/2011 at 16:11, xxxxxxxx wrote:

    Thanks Robert.

    I'm getting all kinds of undefined errors with that code from things like: SoundTrack, ErrorException, logging,sname, EE_NODIALOG, etc..)

    Can you tell me what includes you're using?

    -ScottA



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

    On 13/08/2011 at 17:12, xxxxxxxx wrote:

    Never mind.
    I eventually managed to get it working.

    Using your example. I found out that SetParameter works:

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

    Now I just need to see if there's a way to make it work in Python.

    Thanks Robert.🍺
    -ScottA



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

    On 20/10/2011 at 15:09, xxxxxxxx wrote:

    Here's my method for Python:

    Download the script here:
    http://cl.ly/1J002V0y3o0q1c3v2B20

    I also explain it here:
    http://vimeo.com/30851937


Log in to reply