Copy Volume Envelope

ram17 wrote on 7/29/2019, 12:40 AM

This script by JETDV has been very helpful to me, its main function is to copy velocity envelopes. But now, I want to change its function to "copy volume envelopes" so I need your help in scripting knowledge here, or maybe someone has this type of script already. I have Vegasaur but I do not know if it have this functionality.

Edit: Sorry edited my post, I want to change it to be able to 'copy volume envelopes'

/**
 * Copy Velocity Envelope Nodes
 *
 * Written By: Edward Troxel
 * www.jetdv.com/tts
 * Modified: 03-31-2004
 * Copyright 2004 - JET Digital Video
 * www.jetdv.com/tts
 **/

import System;
import System.IO;
import System.Windows.Forms;
import ScriptPortal.Vegas;



try {
/*STUNNIX-OBFUS-ENCODED-BEGIN*/

  var evnt = FindSelectedEvent();
  if (null == evnt)
      throw "no selected event";

  var vevnt : VideoEvent = VideoEvent(evnt);

  // Find the velocity envelope
  var VelEnv : Envelope = FindVEEnvelope(vevnt, EnvelopeType.Velocity);
  if (null == VelEnv)
        throw "no velocity envelope";

  // Get the existing points in the selection area
  var EnvPts = VelEnv.Points;  
  var cPts = VelEnv.Points.Count;
  var ii, arcount;

  var arTC = new Array(cPts);
  var arY = new Array(cPts);
  var FirstInArea : Timecode = Vegas.SelectionStart + Vegas.SelectionLength;

  arcount = 0;
  for (ii=0; ii < cPts; ii++) {
          arTC[arcount] = EnvPts[ii].X;
          arY[arcount] = EnvPts[ii].Y * 100;
          if (EnvPts[ii].X < FirstInArea)
              FirstInArea = EnvPts[ii].X;
        arcount++;
  }

  // Now locate the next event
  evnt.Selected = false;
  evnt = FindSelectedEvent();
  if (null == evnt)
      throw "no selected 'TO' event";

  vevnt = VideoEvent(evnt);

  // Find the velocity envelope
  VelEnv = FindVEEnvelope(vevnt, EnvelopeType.Velocity);
  if (null == VelEnv) {
    VelEnv = new Envelope(EnvelopeType.Velocity);
    vevnt.Envelopes.Add(VelEnv);
  }




  // Set each point in the series
  for (ii=0; ii < arcount; ii++) {
    var BasePoint : Timecode = new Timecode(0);
    var NewPoint : Timecode = (BasePoint + (arTC[ii] - FirstInArea + evnt.Start) );
    SetVelocityPoint(NewPoint, arY[ii]);
  }

/*STUNNIX-OBFUS-ENCODED-END*/
} catch (e) {
    MessageBox.Show(e);
}

function FindSelectedEvent() : TrackEvent {
  var trackEnum = new Enumerator(Vegas.Project.Tracks);
  while (!trackEnum.atEnd()) {
    var track : Track = Track(trackEnum.item());
    var eventEnum = new Enumerator(track.Events);
    while (!eventEnum.atEnd()) {
      var evnt : TrackEvent = TrackEvent(eventEnum.item());
      if (evnt.Selected) {
          return evnt;
      }
      eventEnum.moveNext();
    }
    trackEnum.moveNext();
  }
  return null;
}

function FindVEEnvelope(mevnt : VideoEvent, etype : EnvelopeType) : Envelope {
  var envEnum : Enumerator = new Enumerator(mevnt.Envelopes);
  while (!envEnum.atEnd()) {
    var env : Envelope = envEnum.item();
    if (env.Type == etype) {
        return env;
    }
    envEnum.moveNext();
  }
  return null;
}

function SetVelocityPoint(markLoc, markLabel) {
/*STUNNIX-OBFUS-ENCODED-BEGIN*/
  var PointSpeed = parseFloat(markLabel) / 100;

  var trackEnum = new Enumerator(Vegas.Project.Tracks);
  while (!trackEnum.atEnd()) {
    var track : Track = Track(trackEnum.item());

    if (track.IsVideo()) {
      var eventEnum = new Enumerator(track.Events);
      while (!eventEnum.atEnd()) {
        var evnt : TrackEvent = TrackEvent(eventEnum.item());

        if (evnt.Selected) {
          if ((evnt.Start.ToMilliseconds() < markLoc.ToMilliseconds()) & ((evnt.Start.ToMilliseconds() + evnt.Length.ToMilliseconds()) > (markLoc.ToMilliseconds()))) {
            var vevnt : VideoEvent = VideoEvent(evnt);

            // Find the velocity envelope - add if needed
            var VelEnv : Envelope = FindVEEnvelope(vevnt, EnvelopeType.Velocity);
            if (null == VelEnv) {
                VelEnv = new Envelope(EnvelopeType.Velocity);
                vevnt.Envelopes.Add(VelEnv);
            }

            var PointLoc : Timecode = markLoc - evnt.Start;
            var a : EnvelopePoint = VelEnv.Points.GetPointAtX(PointLoc);

            if (a == null) {
              a = new EnvelopePoint(PointLoc, PointSpeed);
              VelEnv.Points.Add(a);
            } else {
              a.Y = PointSpeed;
            }

          }
        }
      eventEnum.moveNext();
      }
    }
    trackEnum.moveNext();
  }
/*STUNNIX-OBFUS-ENCODED-END*/
}

 

Comments

Rednroll wrote on 7/29/2019, 7:53 AM

I haven't tried this script and by no means do I understand most of it but what you have shown seems like it is copying Velocity envelopes.

I base that on looking over the API definitions which can be found here.

http://www.vegascreativesoftware.com/us/downloads/#c24726

My thought was that you may need to just replace the command defined for volume envelopes with the velocity envelope.

However, the API shows

EnvelopeType.Volume = audio track volume

and

EnvelopeType.Velocity = video event velocity

So what I am able to understand is that the script you posted already shows "EnvelopeType.Velocity" syntax within it but doesn't show "EnvelopeType.Volume" which makes me think it's written for velocity envelopes.

 

klt wrote on 7/29/2019, 9:08 AM

I just paste event attributes. Maybe selectively.... :)

ram17 wrote on 7/29/2019, 7:59 PM

My bad, it's the reverse of the function of the script I need. I edited my post. Thanks.

ram17 wrote on 7/29/2019, 8:06 PM

@Rednroll Trying to modify it using the Script API as a guide.

wwaag wrote on 7/29/2019, 9:38 PM

@ram17

I assume that you want to "copy" a volume envelope from a "source" track and "paste" it on to another "target" track. Since volume envelopes are a track function, I would suggest doing this. First, duplicate the source track containing the volume envelope. Then delete the events, making sure that the "Lock Envelolpes to Events" button on the bottom Taskbar is not depressed. Next, copy the events from the "target" track into the duplicate track. While not as elegant as a dedicated script, it's pretty simple.

If you're still interested in writing a script, let me know and I can provide you snippets of C# code I just wrote for "bypassing" and then "restoring" volume and pan envelopes as part of HOS, which is essentially cutting and pasting.

ram17 wrote on 7/29/2019, 10:39 PM

@wwaag

Yes, that's the thing I needed, just like the function of the script above which is select the source event then paste to other selected/target video events. So, I want to change it to same function of the script but for copying audio events envelopes only. Tried to modify it but there's an error.

I wish Vegas adds this function to the 'selective paste attributes' of audio events.

wwaag wrote on 7/29/2019, 10:50 PM

@ram17

"copying audio events envelopes only".

Again, volume envelopes are associated with tracks, not events. AFAIK, you cannot paste a volume envelope for just an event, although the points might only pertain to a single event. For that reason, "I wish Vegas adds this function to the 'selective paste attributes of audio events." seems unlikely.

I'll try to post some code snippets tomorrow.

 

altarvic wrote on 7/30/2019, 1:20 AM

You can use Vegas' Envelope Edit Tool to copy envelopes between tracks

wwaag wrote on 7/31/2019, 1:34 PM

@ram17

Try this.

You can download it here. https://tools4vegas.com/copy-volume-envelope/

Former users wrote on 7/31/2019, 3:31 PM

Try this

ram17 wrote on 8/3/2019, 6:59 PM

Thanks to altarvic & Veg, I learned something important again. Also for wwaag for his script & getting back at me.