Пример #1
0
    public void FromVegas(Vegas vegas)
    {
        try
        {
            Track track = vegas.Project.Tracks[0];

            float  rescale = 0.9f;
            double new_duration;

            foreach (TrackEvent curr_event in track.Events)
            {
                new_duration = curr_event.Length.ToMilliseconds() * rescale;
                curr_event.AdjustStartLength(curr_event.Start, Timecode.FromMilliseconds(new_duration), false);
            }



            Timecode curr_event_length;
            Timecode curr_event_start;
            Timecode next_event_start = Timecode.FromSeconds(0);

            foreach (TrackEvent curr_event in track.Events)
            {
                curr_event_length = curr_event.End;
                curr_event_start  = curr_event.Start;

                curr_event.AdjustStartLength(next_event_start, curr_event.Length, false);
                next_event_start = curr_event.End;
            }
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }
    }
Пример #2
0
        // 画像トラックの作り方
        // https://www.youtube.com/watch?v=GdrXo_HiNZM
        TrackEvent AddMedia(Project project, string mediaPath, int trackIndex, Timecode start, Timecode length)
        {
#if false
            Media media = Media.CreateInstance(project, mediaPath);
            Track track = project.Tracks[trackIndex];
            if (track.MediaType == MediaType.Video)
            {
                VideoTrack videoTrack = (VideoTrack)track;
                VideoEvent videoEvent = videoTrack.AddVideoEvent(start, length);
                Take       take       = videoEvent.AddTake(media.GetVideoStreamByIndex(0));
                return(videoEvent);
            }

            // サンプル:画像はこれで追加できる
            //AddMediaImage(vegas.Project, @"C:\Users\Administrator\Desktop\mouse.png", 0, );
            {
                Media media = Media.CreateInstance(vegas.Project, @"C:\Users\Administrator\Desktop\mouse.png");
                Track track = vegas.Project.Tracks[0];
                if (track.MediaType == MediaType.Video)
                {
                    VideoTrack videoTrack = (VideoTrack)track;
                    VideoEvent videoEvent = videoTrack.AddVideoEvent(Timecode.FromSeconds(1), Timecode.FromSeconds(5));
                    Take       take       = videoEvent.AddTake(media.GetVideoStreamByIndex(0));
                    return(videoEvent);
                }
            }
#endif
            return(null);
        }
Пример #3
0
        private void SelectionFindRegion()
        {
            try
            {
                //Options.ScriptOptionCollection options = Options.GetOptions("Find Region");
                var myPrompt = new FormSimplePrompt
                {
                    tbUserData     = { Text = ScriptOptions.GetValue(SelectionStrings.FindRegionKeyName, SelectionStrings.FindRegionLastString, "") },
                    Text           = "Find Region",
                    lblPrompt      = { Text = "Search for:" },
                    lblDescription = { Text = "Partial name of region to find" }
                };

                if (myPrompt.ShowDialog() == DialogResult.OK)
                {
                    Region   selRegion  = myVegas.GetSelectedRegion();
                    Timecode startTime  = (selRegion != null) ? selRegion.Position : Timecode.FromSeconds(0);
                    Region   bestRegion = myVegas.Project.FindRegion(myPrompt.tbUserData.Text, startTime);

                    if (bestRegion == null)
                    {
                        return;
                    }

                    myVegas.Transport.SelectionStart  = bestRegion.Position;
                    myVegas.Transport.SelectionLength = bestRegion.Length;

                    ScriptOptions.SetValue(SelectionStrings.FindRegionKeyName, SelectionStrings.FindRegionLastString, myPrompt.tbUserData.Text);
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
            }
        }
Пример #4
0
//
// Adds a given media fileName to the current track at the specified cursorPosition
//
    void InsertFileAt(Vegas vegas, string fileName, Timecode cursorPosition)
    {
        PlugInNode plugIn = vegas.Transitions.FindChildByName("VEGAS Linear Wipe");

        VideoEvent videoEvent = null;

        Media      media      = new Media(fileName);
        VideoTrack videoTrack = FindSelectedVideoTrack(vegas.Project);

        videoEvent = videoTrack.AddVideoEvent(cursorPosition, Timecode.FromSeconds(stillLength));
        Take take = videoEvent.AddTake(media.GetVideoStreamByIndex(0));

        videoEvent.MaintainAspectRatio = false;

        VideoMotionKeyframe key1 = new VideoMotionKeyframe(Timecode.FromSeconds(stillLength));

        videoEvent.VideoMotion.Keyframes.Add(key1);
        VideoMotionKeyframe key0 = videoEvent.VideoMotion.Keyframes[0];

        key0.ScaleBy(new VideoMotionVertex(initialScale, initialScale));
        key0.RotateBy(initialRotationRadians);


        Effect fx = new Effect(plugIn);

        videoEvent.FadeIn.Transition = fx;
        fx.Preset = "Top-Down, Soft Edge";
    }
Пример #5
0
    private void Import(Config config, Vegas vegas)
    {
        Project project = vegas.Project;

        // Clear markers and regions
        if (config.ClearMarkers)
        {
            project.Markers.Clear();
        }
        if (config.ClearRegions)
        {
            project.Regions.Clear();
        }

        // Load log file
        if (!File.Exists(config.LogFile))
        {
            throw new Exception("Log file does not exist.");
        }
        Dictionary <EventType, List <TimedEvent> > timedEvents = ParseLogFile(config);

        // Add markers/regions
        foreach (EventType eventType in timedEvents.Keys)
        {
            foreach (Visualization visualization in config.Visualizations)
            {
                if (visualization.EventType != eventType)
                {
                    continue;
                }

                List <TimedEvent> filteredEvents = FilterEvents(timedEvents[eventType], visualization.Regex);
                foreach (TimedEvent timedEvent in filteredEvents)
                {
                    Timecode start  = Timecode.FromSeconds(timedEvent.Start);
                    Timecode end    = Timecode.FromSeconds(timedEvent.End);
                    Timecode length = end - start;
                    if (config.LoopRegionOnly)
                    {
                        Timecode loopRegionStart = vegas.Transport.LoopRegionStart;
                        Timecode loopRegionEnd   = loopRegionStart + vegas.Transport.LoopRegionLength;
                        if (start < loopRegionStart || start > loopRegionEnd || end < loopRegionStart || end > loopRegionEnd)
                        {
                            continue;
                        }
                    }
                    switch (visualization.VisualizationType)
                    {
                    case VisualizationType.Marker:
                        project.Markers.Add(new Marker(start, timedEvent.Value));
                        break;

                    case VisualizationType.Region:
                        project.Regions.Add(new Region(start, length, timedEvent.Value));
                        break;
                    }
                }
            }
        }
    }
Пример #6
0
//
// Adds a given media fileName to the current track at the specified cursorPosition
//
    void InsertFileAt(Vegas vegas, string fileName, Timecode cursorPosition)
    {
        VideoEvent videoEvent = null;

        Media      media      = new Media(fileName);
        VideoTrack videoTrack = FindSelectedVideoTrack(vegas.Project);

        videoEvent = videoTrack.AddVideoEvent(cursorPosition, Timecode.FromSeconds(stillLength));
        Take take = videoEvent.AddTake(media.GetVideoStreamByIndex(0));

        videoEvent.MaintainAspectRatio = false;

        VideoMotionKeyframe key1 = new VideoMotionKeyframe(Timecode.FromSeconds(stillLength));

        videoEvent.VideoMotion.Keyframes.Add(key1);
        VideoMotionKeyframe key0 = videoEvent.VideoMotion.Keyframes[0];

        key0.ScaleBy(new VideoMotionVertex(initialScale, initialScale));
        key0.RotateBy(initialRotationRadians * (double)rnd.Next(-1, 1));
        key0.MoveBy(new VideoMotionVertex((float)rnd.Next(-15, 15), (float)rnd.Next(-20, 20)));

        PlugInNode plugIn = vegas.Transitions.FindChildByName(desiredTransitions[rnd.Next(0, desiredTransitions.Length - 1)]);

        Effect fx = new Effect(plugIn);

        videoEvent.FadeIn.Transition = fx;
    }
Пример #7
0
        void AddMedias(Vegas vegas, string file)
        {
            // トラックを追加
            Track track = new VideoTrack(0, _trackName);

            vegas.Project.Tracks.Add(track);
            track.Selected = true;
            // テキストファイルを開く
            // 1行につき1イベントを作ります
            System.IO.StreamReader sr = new System.IO.StreamReader(file, System.Text.Encoding.GetEncoding("shift_jis"));
            string line = "";

            while ((line = sr.ReadLine()) != null)
            {
                // ビデオイベント作成
                VideoEvent videoEvent = new VideoEvent(Timecode.FromSeconds(_currentTime), Timecode.FromSeconds(_timeLength));
                track.Events.Add(videoEvent);
                // Takeを作成。ここにMediaのText情報が入っている
                Take take = GenerateTakeText(vegas, line);
                if (take != null)
                {
                    videoEvent.Takes.Add(take); // イベントにテキストTakeを登録
                }
                // 次の開始位置を決める
                _currentTime += _timeLength + _timeInterval;
            }
            sr.Close();
        }
Пример #8
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));
        }
Пример #9
0
    public void FromVegas(Vegas vegas)
    {
        int       trackCount  = 10;
        int       eventCount  = 10;
        Timecode  eventLength = Timecode.FromSeconds(10);
        MediaType mediaType   = MediaType.Audio;

        for (int i = 0; i < trackCount; i++)
        {
            // create a track
            Track track;
            if (mediaType == MediaType.Audio)
            {
                track = new AudioTrack(i, "Audio " + ((i / 2) + 1));
            }
            else
            {
                track = new VideoTrack(i, "Video " + ((i / 2) + 1));
            }

            // add the track
            vegas.Project.Tracks.Add(track);

            Timecode startTime = Timecode.FromSeconds(0);

            for (int j = 0; j < eventCount; j++)
            {
                // create an event
                TrackEvent trackEvent;
                if (mediaType == MediaType.Audio)
                {
                    trackEvent = new AudioEvent(startTime, eventLength, "Audio Event " + (j + 1));
                }
                else
                {
                    trackEvent = new VideoEvent(startTime, eventLength, "Video Event " + (j + 1));
                }

                // add the event to the track
                track.Events.Add(trackEvent);

                // increment the start time
                startTime += eventLength;
            }

            // toggle the media type
            if (mediaType == MediaType.Audio)
            {
                mediaType = MediaType.Video;
            }
            else
            {
                mediaType = MediaType.Audio;
            }
        }
    }
Пример #10
0
        private void RegionAdjustResizeIn_Invoked(object sender, EventArgs e)
        {
            var time = FormTimeEntry.GetUserTime("Region adjust", "Shorten by");

            if (time == null)
            {
                return;
            }
            time = Timecode.FromSeconds(0) - time;
            RegionsResize(time);
        }
Пример #11
0
        private void RegionAdjustNudgeLeft_Invoked(object sender, EventArgs e)
        {
            var time = FormTimeEntry.GetUserTime("Region adjust", "Nudge left by");

            if (time == null)
            {
                return;
            }
            time = Timecode.FromSeconds(0) - time;
            RegionsNudge(time, false);
        }
Пример #12
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());
        }
Пример #13
0
    //
    // FromVegas is always the initial entry point that Vegas makes when
    // calling a script
    //
    public void FromVegas(Vegas vegas)
    {
        double s = 0.0;

        //  Gran the media and insert it

        string[] files = Directory.GetFiles(StillsPath);
        for (int i = 0; i < files.Length; i++)
        {
            InsertFileAt(vegas, files[i], Timecode.FromSeconds(s));
            s = s + (stillLength - overlap);
        }
    }
Пример #14
0
 public void FromVegas(Vegas vegas)
 {
     foreach (Track t in vegas.Project.Tracks)
     {
         foreach (TrackEvent evt in t.Events)
         {
             if (evt.Start > Timecode.FromSeconds(0))
             {
                 evt.FadeIn.Length = Timecode.FromSeconds(1);
             }
             evt.FadeOut.Length = Timecode.FromSeconds(1);
         }
     }
 }
Пример #15
0
        /// Implementation
        ///
        ///
        private void RegionsNudge(Timecode Time, bool Cumulative)
        {
            Timecode ZeroTime   = myVegas.Project.Ruler.StartTime;
            Timecode Adjustment = Time;

            if (Cumulative)
            {
                Adjustment = Timecode.FromSeconds(0);
            }

            var Groups = myVegas.GetRegionGroups();

            using (var undo = new UndoBlock("Nudge regions by " + Time))
            {
                foreach (var group in Groups)
                {
                    Timecode newTime         = group.Region.Position + Adjustment;
                    Timecode localAdjustment = Timecode.FromSeconds(0);

                    // zero time detection
                    if (newTime < ZeroTime)
                    {
                        if (ScriptOptions.GetValue(Strings.ScriptName, "ShowZeroTimeWarning", true))
                        {
                            myVegas.ShowError("Cannot move beyond start of timeline",
                                              "Your operation was aborted to avoid moving events outside the timeline");
                        }
                        return;
                    }

                    // collision detection
                    foreach (var grp in Groups)
                    {
                        if (!grp.Equals(@group))
                        {
                            if (newTime <= grp.Region.End && newTime >= grp.Region.Position)
                            {
                                localAdjustment = newTime - grp.Region.End;
                                break;
                            }
                        }
                    }
                    group.MoveTo(newTime - localAdjustment);
                    if (Cumulative)
                    {
                        Adjustment += Time;
                    }
                }
            }
        }
Пример #16
0
    //
    // FromVegas is always the initial entry point that Vegas makes when
    // calling a script
    //
    public void FromVegas(Vegas vegas)
    {
        Timecode s = vegas.Transport.CursorPosition;

        FolderBrowserDialog folderBrowserDialog1 = new FolderBrowserDialog();

        folderBrowserDialog1.SelectedPath = initialFolderRoot;
        DialogResult result = folderBrowserDialog1.ShowDialog();

        if (result == DialogResult.OK)
        {
            string[] files = Directory.GetFiles(folderBrowserDialog1.SelectedPath);
            for (int i = 0; i < files.Length; i++)
            {
                InsertFileAt(vegas, files[i], s);
                s = s + Timecode.FromSeconds(stillLength - overlap);
            }
        }
    }
Пример #17
0
        void AddMedias(Vegas vegas)
        {
            // トラックを追加
            Track track = new VideoTrack(0, _trackName);

            vegas.Project.Tracks.Add(track);
            track.Selected = true;
            for (int i = 0; i < _rtb.Lines.Length; i++)
            {
                string line = _rtb.Lines[i];
                // ビデオイベント作成
                VideoEvent videoEvent = new VideoEvent(Timecode.FromSeconds(_currentTime), Timecode.FromSeconds(_timeLength));
                track.Events.Add(videoEvent);
                // Takeを作成。ここにMediaのText情報が入っている
                Take take = GenerateTakeText(vegas, line);
                if (take != null)
                {
                    videoEvent.Takes.Add(take); // イベントにテキストTakeを登録
                }
                // 次の開始位置を決める
                _currentTime += _timeLength + _timeInterval;
            }
        }
Пример #18
0
 public static Region FindRegion(this ScriptPortal.Vegas.Project Project, string RegionName)
 {
     return(FindRegion(Project, RegionName, Timecode.FromSeconds(0)));
 }
Пример #19
0
    private static Timecode GetTimecode(XmlAttribute valueAttribute)
    {
        double seconds = Double.Parse(valueAttribute.Value, CultureInfo.InvariantCulture);

        return(Timecode.FromSeconds(seconds));
    }
Пример #20
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.
            }
        }
Пример #21
0
        private void SelectionFindAgain()
        {
            string searchString = ScriptOptions.GetValue(SelectionStrings.FindRegionKeyName, SelectionStrings.FindRegionLastString, "");

            if (!string.IsNullOrEmpty(searchString))
            {
                Region selectedRegion = myVegas.GetSelectedRegion();
                var    bestRegion     = myVegas.Project.FindRegion(searchString, (selectedRegion != null) ? selectedRegion.Position : Timecode.FromSeconds(0));

                if (bestRegion == null)
                {
                    return;
                }

                myVegas.Transport.SelectionStart  = bestRegion.Position;
                myVegas.Transport.SelectionLength = bestRegion.Length;
            }
        }