/** * This script will reduce the volume on a music track whenever there are clips * on a narrative track. * Written By: Edward Troxel - Vegas Tips, Tricks, & Scripts * Modified By: David Arendt - multiple successive tracks now working **/ import System; import System.IO; import System.Object; import System.Windows.Forms; import SonicFoundry.Vegas; try { // Set the defaults var FadeWhen = 2; // 1 = all before/after, 2 = Centered on start/end var FadeMS : Double = 2000; //500 = 1/2 second - Time is MilliSeconds var LoudVol = 1; //1 = 0db, 2 = 6db, 1.5 = 3.5db, 1.75 = 4.8db var SoftVol = 0.25; //0 = -inf, .5 = -6db, .25 = -12db if (FadeWhen == 2) { FadeMS = FadeMS / 2; } var FadeTime = new Timecode(FadeMS); // Find the two audio tracks by name var VoiceTrack = FindTrack("Narrative"); if (null == VoiceTrack) throw "no selected track"; var MusicTrack = FindTrack("Music"); if (null == MusicTrack) throw "no selected track"; // Find the volume envelope on the music track - add if needed var VolEnv = FindEnvelope(MusicTrack, EnvelopeType.Volume); if (null == VolEnv) { VolEnv = new Envelope(EnvelopeType.Volume); MusicTrack.Envelopes.Add(VolEnv); } // Go thru the events on the narrative track finding in/out points var eventEnum = new Enumerator(VoiceTrack.Events); while (!eventEnum.atEnd()) { var evnt : TrackEvent = TrackEvent(eventEnum.item()); var evntStart : Timecode = evnt.Start; var evntLen : Timecode = evnt.Length; // begin modification by David Arendt eventEnum.moveNext(); var nextEvnt : TrackEvent; var nextEvntStart : Timecode; var nextEvntLen : Timecode; while (!eventEnum.atEnd()) { nextEvnt = TrackEvent(eventEnum.item()); nextEvntStart = nextEvnt.Start; nextEvntLen = nextEvnt.Length; if (nextEvntStart > evntStart + evntLen + FadeTime + FadeTime) break; evntLen = nextEvntStart - evntStart + nextEvntLen; eventEnum.moveNext(); } // end modification by David Arendt VolEnv.Points.Add(new EnvelopePoint(evntStart - FadeTime, LoudVol)); if (FadeWhen == 2) { VolEnv.Points.Add(new EnvelopePoint(evntStart + FadeTime, SoftVol)); } else { VolEnv.Points.Add(new EnvelopePoint(evntStart, SoftVol)); } if (FadeWhen == 2) { VolEnv.Points.Add(new EnvelopePoint(evntStart + evntLen - FadeTime, SoftVol)); } else { VolEnv.Points.Add(new EnvelopePoint(evntStart + evntLen, SoftVol)); } VolEnv.Points.Add(new EnvelopePoint(evntStart + evntLen + FadeTime, LoudVol)); } } catch (e) { MessageBox.Show(e); } function FindTrack(WhichTrack) : Track { var trackEnum = new Enumerator(Vegas.Project.Tracks); var PrevTrack : Track = Track(trackEnum.item()); while (!trackEnum.atEnd()) { var track : Track = Track(trackEnum.item()); if (WhichTrack == "Current") { if (track.Selected) { return track; } } if (WhichTrack == "Previous") { if (track.Selected) { return PrevTrack; } } if (track.Name == WhichTrack) { return track; } trackEnum.moveNext(); } return null; } function FindEnvelope(track : Track, etype : EnvelopeType) : Envelope { var envEnum : Enumerator = new Enumerator(track.Envelopes); while (!envEnum.atEnd()) { var env : Envelope = envEnum.item(); if (env.Type == etype) { return env; } envEnum.moveNext(); } return null; }