Esempio n. 1
0
        private void BuildMergeByFilename(ScriptPortal.Vegas.Vegas Vegas)
        {
            SetProgressBounds(Count);
            SetProgressStatus(RenderStrings.StatusBuildingOptimizing);

            // merge by filename
            for (int i = 0; i < Count; i++)
            {
                SetProgress(i);
                if (Cancel)
                {
                    return;
                }

                var killSheet = new List <RenderItem>();
                var ri        = this[i];
                var siblings  = this.Where(item => item != ri && item.FilePath == ri.FilePath);

                foreach (var sibling in siblings)
                {
                    ri.MergeWith(sibling);
                    killSheet.Add(sibling);
                }
                RemoveAll(killSheet.Contains);
            }
        }
Esempio n. 2
0
        private void BuildApplyTemplates(ScriptPortal.Vegas.Vegas Vegas)
        {
            // pass III: rendertemplates
            SetProgressBounds(Count);
            SetProgressStatus(RenderStrings.StatusBuildingApplyingTemplates);
            for (int i = 0; i < Count; i++)
            {
                SetProgress(i);
                if (Cancel)
                {
                    return;
                }

                var ri = this[i];
                if (ri.RenderParams.GetParam <bool>(RenderTags.DoVideo) && ri.Tracks.Any(trk => trk.IsVideo()))
                {
                    var renderer = ri.RenderParams.GetParam <string>(RenderTags.VideoFmt);
                    ri.RenderFormat = Vegas.Renderers.FindBestRendererByName(renderer);
                    ri.RenderFormat.Templates.Refresh();
                    var tpl = ri.RenderParams.GetParam <string>(RenderTags.VideoTpl);
                    ri.RenderTemplate = ri.RenderFormat.Templates.FindBestTemplateByName(tpl);
                }
                else
                {
                    var renderer = ri.RenderParams.GetParam <string>(RenderTags.AudioFmt);
                    ri.RenderFormat = Vegas.Renderers.FindBestRendererByName(renderer);
                    ri.RenderFormat.Templates.Refresh();
                    var tpl = ri.RenderParams.GetParam <string>(RenderTags.AudioTpl);
                    ri.RenderTemplate = ri.RenderFormat.Templates.FindBestTemplateByName(tpl);
                }
            }
        }
Esempio n. 3
0
        public static Region GetSelectedRegion(this ScriptPortal.Vegas.Vegas Vegas)
        {
            if (Vegas.Transport.SelectionLength == Timecode.FromSeconds(0))
            {
                return(null);
            }

            return(Vegas.Project.Regions.FirstOrDefault(r => r.Position == Vegas.Transport.SelectionStart && r.Length == Vegas.Transport.SelectionLength));
        }
Esempio n. 4
0
 public void Build(ScriptPortal.Vegas.Vegas Vegas)
 {
     Clear();
     if (Vegas.GetSelectedRegions() == null)
     {
         UseSelection = false;
     }
     BuildScanRegions(Vegas);
     BuildApplyCounters(Vegas);
     BuildApplyTemplates(Vegas);
     BuildMergeByFilename(Vegas);
 }
Esempio n. 5
0
        public static List <Region> GetSelectedRegions(this ScriptPortal.Vegas.Vegas Vegas)
        {
            if (Vegas.Transport.SelectionLength == Timecode.FromSeconds(0))
            {
                return(null);
            }

            Timecode start, end;

            Vegas.Transport.GetNormalizedTimeSelection(out start, out end);

            return(Vegas.Project.Regions.Where(r => r.Position >= start && r.End <= end).ToList());
        }
Esempio n. 6
0
    public void FromVegas(Vegas vegas)
    {
        myVegas = vegas;
        if (myVegas.Project.Length.ToMilliseconds() == 0)
        {
            MessageBox.Show("Project not loaded");
            throw new ApplicationException("Project not loaded");
        }

        GetRenderTemplate("MAGIX AVC/AAC MP4");
        CreateOutputFilename();
        RenderProject();
        myVegas.Exit();
    }
Esempio n. 7
0
        public static List <Marker> GetSelectedMarkers(this ScriptPortal.Vegas.Vegas Vegas)
        {
            if (Vegas.SelectionLength.Nanos == 0)
            {
                return(new List <Marker>());
            }

            Timecode start = Vegas.Transport.SelectionStart;
            Timecode end   = Vegas.Transport.SelectionStart + Vegas.Transport.SelectionLength;

            if (start > end)
            {
                Timecode temp = start;
                start = end;
                end   = temp;
            }

            return(Vegas.Project.Markers.Where(mk => mk.Position >= start && mk.Position <= end).ToList());
        }
    public void FromVegas(Vegas vegas)
    {
        myVegas = vegas;
        File.Create(logfile).Close();                   // Clear log file

        String projectPath = myVegas.Project.FilePath;

        if (String.IsNullOrEmpty(projectPath))
        {
            String dir = System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments);
            defaultBasePath = Path.Combine(dir, defaultBasePath);
        }
        else
        {
            String dir      = Path.GetDirectoryName(projectPath);
            String fileName = Path.GetFileNameWithoutExtension(projectPath);
            defaultBasePath = Path.Combine(dir, fileName + "_");
        }

        DialogResult result = ShowBatchRenderDialog();

        myVegas.UpdateUI();
        if (DialogResult.OK == result)
        {
            // inform the user of some special failure cases
            String     outputFilePath = FileNameBox.Text;
            RenderMode renderMode     = RenderMode.Project;
            if (RenderRegionsButton.Checked)
            {
                renderMode = RenderMode.Regions;
            }
            else if (RenderTrackEventsButton.Checked)
            {
                renderMode = RenderMode.TrackEvents;
            }
            else if (RenderSelectionButton.Checked)
            {
                renderMode = RenderMode.Selection;
            }
            DoBatchRender(SelectedTemplates, outputFilePath, renderMode);
        }
    }
Esempio n. 9
0
        public void FromVegas(VegasWrapper vegas)
        {
            var fileName  = "aud.csv";
            var trackName = "1CAM_AUD";

            string[] sourceOutsTiming = null;
            var      EffectNames      = new[] {
                "EffectName_1",
                "EffectName_2",
                "....",
                "EffectName_N",
            };

            try
            {
                sourceOutsTiming = File.ReadAllLines(Path.GetDirectoryName(vegas.Project.FilePath) + "\\" + fileName);
            }
            catch
            {
                MessageBox.Show("File " + fileName + " are used by another process.\nPlease close the file.", "File are unaccessible.");
                return;
            }
            var timings = ParseOutTiming(sourceOutsTiming);

            var track          = GetTrackByName(vegas.Project, trackName);
            var volumeEnvelope = track.Envelopes.FindByType(EnvelopeType.Volume);

            if (volumeEnvelope == null)
            {
                volumeEnvelope = new Envelope(EnvelopeType.Volume);
                track.Envelopes.Add(volumeEnvelope);
            }
            foreach (var timing in timings)
            {
                volumeEnvelope.Points.Add(new EnvelopePoint(timing.Item1, 1));
                volumeEnvelope.Points.Add(new EnvelopePoint(timing.Item1 + Timecode.FromFrames(5), 0.072));
                volumeEnvelope.Points.Add(new EnvelopePoint(timing.Item2 - Timecode.FromFrames(5), Math.Sqrt(((40 - 10) / 46))));
                volumeEnvelope.Points.Add(new EnvelopePoint(timing.Item2, 1));
            }
            removeFXFromTrackByName(track, EffectNames);
        }
Esempio n. 10
0
        public static List <RegionGroup> GetRegionGroups(this ScriptPortal.Vegas.Vegas Vegas)
        {
            Timecode selStart = Vegas.Transport.SelectionStart;
            Timecode selEnd   = Vegas.Transport.SelectionStart + Vegas.Transport.SelectionLength;

            if (selStart > selEnd)
            {
                Ext.SwapTimecode(ref selStart, ref selEnd);
            }

            bool selection = Vegas.SelectionLength != Timecode.FromNanos(0) && (Vegas.Transport.CursorPosition == selStart || Vegas.Transport.CursorPosition == selEnd);

            var rGrps = new List <RegionGroup>();

            foreach (var r in Vegas.Project.Regions)
            {
                if (selection && (r.Position < selStart || r.End > selEnd))
                {
                    continue;
                }

                var rgr = new RegionGroup(r);

                foreach (Track t in Vegas.Project.Tracks)
                {
                    foreach (TrackEvent ev in t.Events)
                    {
                        if (ev.Start < r.End && ev.End > r.Position)
                        {
                            rgr.AddEvent(ev);
                        }
                    }
                }
                rGrps.Add(rgr);
            }
            return(rGrps);
        }
Esempio n. 11
0
        private void BuildApplyCounters(ScriptPortal.Vegas.Vegas Vegas)
        {
            // pass II: counters
            var nameHitCount = new Dictionary <string, int>();
            var regions      = Vegas.Project.Regions.Count > 0 ? Vegas.Project.Regions.ToList() : new List <Region>();

            SetProgressBounds(regions.Count);
            SetProgressStatus(RenderStrings.StatusBuildingApplyingCounters);

            for (int i = 0; i < Vegas.Project.Regions.Count; i++)
            {
                SetProgress(i);
                if (Cancel)
                {
                    return;
                }

                var reg = Vegas.Project.Regions[i];
                if (string.IsNullOrEmpty(reg.Label))
                {
                    continue;
                }

                string regionLabel = reg.Label.StripRenderTags().ToLowerInvariant();
                if (!nameHitCount.ContainsKey(regionLabel))
                {
                    nameHitCount[regionLabel] = 1;
                }

                var items = this.Where(item => item.Region.EqualsRegion(reg));
                foreach (var item in items)
                {
                    item.CounterIndex = nameHitCount[regionLabel];
                }
                nameHitCount[regionLabel]++;
            }
        }
Esempio n. 12
0
        private void BuildScanRegions(ScriptPortal.Vegas.Vegas Vegas)
        {
            var regions = UseSelection ? Vegas.GetSelectedRegions().Where(r => !r.Label.ContainsRenderTag(RenderTags.NoRender)).ToList() : Vegas.Project.Regions.Where(region => !region.Label.ContainsRenderTag(RenderTags.NoRender)).ToList();

            SetProgressBounds(regions.Count);
            SetProgressStatus(RenderStrings.StatusBuildingScanningRegions);

            for (int scanCounter = 0; scanCounter < regions.Count; scanCounter++)
            {
                SetProgress(scanCounter);
                if (Cancel)
                {
                    return;
                }

                var reg = regions[scanCounter];

                var regionParams = Vegas.Project.GetParamsAt(reg.End);
                regionParams.ParseString(reg.Label);

                var tracks = Vegas.Project.Tracks.Where(trk => string.IsNullOrEmpty(trk.Name) || !trk.Name.ContainsRenderTag(RenderTags.NoRender)).ToList();
                if (regionParams.GetParam <bool>(RenderTags.NoEmpty))
                {
                    tracks = tracks.Where(item => item.Events.Any(ev => ev.Start <= reg.End && ev.End >= reg.Position)).ToList();
                }
                if (!regionParams.GetParam <bool>(RenderTags.DoVideo))
                {
                    tracks = tracks.Where(trk => !trk.IsVideo()).ToList();
                }

                // straight mode
                if (!regionParams.GetParam <bool>(RenderTags.DoStems))
                {
                    var localParams = new RenderParamSet(regionParams);
                    foreach (var trk in tracks)
                    {
                        localParams.ParseString(trk.Name);
                        localParams.ParseString(trk.BusTrack.Name);
                    }
                    var ri = new RenderItem(reg, localParams);
                    ri.Tracks.AddRange(tracks);

                    Add(ri);
                }

                else                 // stem mode
                {
                    foreach (var trk in tracks)
                    {
                        var localParams = new RenderParamSet(regionParams);

                        localParams.ParseString(trk.Name);
                        localParams.ParseString(trk.BusTrack.Name);
                        var ri = new RenderItem(reg, localParams);
                        ri.Tracks.Add(trk);

                        Add(ri);
                    }
                }
            }
        }
Esempio n. 13
0
        public void Render(ScriptPortal.Vegas.Vegas myVegas)
        {
            SetProgressBounds(Count);
            using (UndoBlock undo = new UndoBlock("Render tracks"))
            {
                for (int i = 0; i < Count; i++)
                {
                    var ri = this[i];

                    foreach (var trk in myVegas.Project.Tracks)
                    {
                        trk.Mute = !ri.Tracks.Contains(trk);
                    }

                    // padding
                    if (ri.RenderParams.GetParam <bool>(RenderTags.DoPadding))
                    {
                        if (ri.RenderTemplate.RendererID != myVegas.Renderers.FindByName("Wave (Microsoft)").ID)
                        {
                            ErrorLog(
                                String.Format(
                                    "The region {0} could not be padded. Padded rendering can only be performed on .WAV (PCM) files.",
                                    ri.Region.Label));
                        }
                        else
                        {
                            var paddingTime = Timecode.FromSeconds(ri.PaddingSeconds);
                            if (ri.Start - paddingTime < myVegas.Project.Ruler.StartTime)
                            {
                                ErrorLog(String.Format(
                                             "The region {0} could not be padded. Move your region further into the project.", ri.Region.Label));
                            }
                            else
                            {
                                ri.Start  -= paddingTime;
                                ri.Length += paddingTime;
                                ri.Length += paddingTime;
                            }
                        }
                    }

                    if (File.Exists(ri.FilePath) && ri.RenderParams.GetParam <bool>(RenderTags.DoReadonly))
                    {
                        // check readonly
                        var attr = File.GetAttributes(ri.FilePath);
                        if (attr.IsSet(FileAttributes.ReadOnly))
                        {
                            File.SetAttributes(ri.FilePath, attr & ~FileAttributes.ReadOnly);
                        }
                    }
                    SetProgress(i);
                    SetProgressStatus("Rendering " + ri.FilePath);
                    RenderStatus status = myVegas.Render(ri.FilePath, ri.RenderTemplate, ri.Start, ri.Length);
                    if (status != RenderStatus.Complete)
                    {
                        ErrorLog(String.Format("{0} raised error {1}", ri.FilePath, status.ToString()));
                    }
                    else
                    {
                        // file successfully rendered

                        // strip padding
                        if (ri.RenderParams.GetParam <bool>(RenderTags.DoPadding))
                        {
                            WaveFile.StripPadding(ri.FilePath, ri.PaddingSeconds);
                        }
                    }
                }
                foreach (ScriptPortal.Vegas.Track trk in myVegas.Project.Tracks)
                {
                    trk.Mute = false;
                }
                undo.Cancel = true;                 // we didn't really do anything useful.
            }
        }
Esempio n. 14
0
 public static void Initialize(VegasWrapper vegas)
 {
     Vegas = vegas;
 }