コード例 #1
0
        public static List <string> GetPresets(PlugInNode pin /*, int deep, List<string> plugInsList, StringBuilder plugInsSB*/)
        {
            //plugInsSB.AppendLine(pin.Presets.Count > 0 ? String.Join(Environment.NewLine, pin.Presets.Select(p => $"{new string('\t', deep)}Preset:[{p.Index}] '{p.Name}'").ToArray()) : $"{new string('\t', deep)}none presets");

            //return pin.Presets.Select(p => $"{new string('\t', deep)}[{p.Index}] '{p.Name}'").ToList();
            return(pin.Presets.Select(x => x.Name).ToList());
        }
コード例 #2
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";
    }
コード例 #3
0
ファイル: TextToClip.cs プロジェクト: thaivuN/TextToClip
        private Media createTextMedia(Vegas vegas, Preset preset)
        {
            PlugInNode plugin    = vegas.Generators.GetChildByName("Sony Titles & Text");
            Media      textMedia = new Media(plugin);

            switch (preset)
            {
            case Preset.Title:
                textMedia.Generator.Preset = showPreset;
                break;

            case Preset.Song:
                textMedia.Generator.Preset = songPreset;
                break;

            case Preset.Rank:
                textMedia.Generator.Preset = rankPreset;
                break;

            default:
                break;
            }

            return(textMedia);
        }
コード例 #4
0
        public void FromVegas(Vegas vegas)
        {
            try
            {
                _vegas = vegas;

                Track      track     = vegas.Project.AddVideoTrack();
                PlugInNode generator = vegas.Generators.GetChildByName("VEGAS Titles & Text");

                foreach (var region in vegas.Project.Regions)
                {
                    string text = region.Label;

                    VideoEvent e = new VideoEvent(vegas.Project, Timecode.FromMilliseconds(region.Position.ToMilliseconds()), region.Length, null);
                    track.Events.Add(e);

                    e.FadeIn.Curve  = CurveType.Linear;
                    e.FadeOut.Curve = CurveType.Linear;
                    text            = HandleAegisubTags(e, text);

                    CreateTextPreset("RegionsToTextbox", "Impress BT", 14, 0.5, 0.08, 10.0, text);
                    Media       media  = new Media(generator, "RegionsToTextbox");
                    MediaStream stream = media.Streams[0];
                    Take        take   = new Take(stream);
                    e.Takes.Add(take);
                }
            }
            catch (Exception e)
            {
                vegas.ShowError(e);
            }
        }
コード例 #5
0
    Effect CreateEffect(XmlElement elt, PlugInNode rootNode)
    {
        if (!elt.HasChildNodes)
        {
            return(null);
        }
        String plugInName = ChildString(elt, "PlugIn");

        switch (plugInName)
        {
        case "Track Noise Gate":
        case "Track EQ":
        case "Track Compressor":
            // ignore default audio track effects
            return(null);
        }
        PlugInNode plugIn = rootNode.GetChildByName(plugInName);

        if (null == plugIn)
        {
            return(null);
        }
        Effect effect = new Effect(plugIn);

        return(effect);
    }
コード例 #6
0
    //String presetName = "SMPTE Drop (29.97 fps)";

    public void FromVegas(Vegas vegas)
    {
        PlugInNode plugIn = vegas.VideoFX.GetChildByClassID(plugInClassID);

        if (null == plugIn)
        {
            throw new ApplicationException("Could not find video plug-in.");
        }

        foreach (Media media in vegas.Project.MediaPool)
        {
            // only add the effect if the media object has video
            if (!media.HasVideo())
            {
                continue;
            }
            // and if it does not already have the effect
            if (MediaHasEffect(media, plugIn))
            {
                continue;
            }
            Effect effect = new Effect(plugIn);
            media.Effects.Add(effect);
            if (null != presetName)
            {
                effect.Preset = presetName;
            }
        }
    }
コード例 #7
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;
    }
コード例 #8
0
    void ImportEffect(XmlElement parent, Effects effects, PlugInNode rootNode)
    {
        Effect effect = CreateEffect(parent, rootNode);

        if (null == effect)
        {
            return;
        }
        effects.Add(effect);
        ImportKeyframes(parent, effect.Keyframes);
    }
コード例 #9
0
 public bool MediaHasEffect(Media media, PlugInNode plugIn)
 {
     foreach (Effect effect in media.Effects)
     {
         if (effect.PlugIn == plugIn)
         {
             return(true);
         }
     }
     return(false);
 }
コード例 #10
0
    void ImportEffects(XmlElement parent, Effects effects, PlugInNode rootNode)
    {
        XmlElement elt = parent["Effects"];

        if (null == elt)
        {
            return;
        }
        foreach (XmlElement child in elt)
        {
            ImportEffect(child, effects, rootNode);
        }
    }
コード例 #11
0
ファイル: EffectRepository.cs プロジェクト: Burakovivan/VSG
        public static PlugInNode GetPlugIn(string plugInName)
        {
            PlugInNode pin = VegasHandler.Vegas.PlugIns.GetChildByName(plugInName);

            if (pin != null && pin.Any())
            {
                return(pin);
            }
            else
            {
                throw new ArgumentException($"There is no PlugInNode (Effect) with name '{plugInName}'", nameof(plugInName));
            }
        }
コード例 #12
0
ファイル: TextToClip.cs プロジェクト: thaivuN/TextToClip
        public void FromVegas(Vegas vegas)
        {
            string path = getFilePath();

            if (System.IO.File.Exists(path) == false)
            {
                MessageBox.Show("File does not exist");
                return;
            }
            string        directory = (new System.IO.FileInfo(path)).Directory.FullName;
            List <string> data      = readFromFile(path);
            //List<string> rawData = readFromFile();
            // printList(rawData);



            PlugInNode node = vegas.Generators;
            //Load the selected Track
            Track track = getSelectedTrack(vegas.Project);

            //Load selected events from Track
            TrackEvent[] events = getSelectedEventsInTrack(track);

            if (events.Length != data.Count)
            {
                MessageBox.Show("The number of input and clips does not match");
                return;
            }

            List <string> ranks = createRanks(data.Count);
            List <string> shows = getShows(data, " -|- ");
            List <string> songs = getSongs(data, " -|- ");

            //Get the Text media
            //Media txt_media = createTextMedia(vegas);

            //Create Ranking Track and Text events
            VideoTrack track1 = createTrackAbove(vegas.Project, track);

            VideoEvent[] rankTexts = createText(vegas, track1, events, Preset.Rank, ranks);
            //Create Title Track and Text events
            VideoTrack track2 = createTrackAbove(vegas.Project, track);

            VideoEvent[] titleTexts = createText(vegas, track2, events, Preset.Title, shows);
            //Create Songs Track and Text events
            VideoTrack track3 = createTrackAbove(vegas.Project, track);

            VideoEvent[] songTexts = createText(vegas, track3, events, Preset.Song, songs);
        }
コード例 #13
0
        static Effect GetEffect(Vegas vegas, String plugInName)
        {
            PlugInNode plugIn = vegas.PlugIns.GetChildByName(plugInName);

            if (plugIn == null)
            {
                return(null);
            }
            Effect linearBlur = new Effect(plugIn);

            if (null == plugIn)
            {
                throw new ApplicationException(String.Format("Failed to find plug-in: '{0}'", plugInName));
            }
            return(linearBlur);
        }
コード例 #14
0
    void ImportMedia(XmlElement elt, MediaPool pool)
    {
        String key   = ChildString(elt, "KeyString");
        Media  media = null;

        if (IsGeneratedMediaKey(key))
        {
            XmlElement effectElt = elt["Effect"];
            if (null == effectElt)
            {
                return;
            }
            String     plugInName = ChildString(effectElt, "PlugIn");
            PlugInNode plugIn     = myVegas.Generators.GetChildByName(plugInName);
            if (null == plugIn)
            {
                return;
            }
            media = new Media(plugIn);
            myGeneratedMediaKeys[key] = media.KeyString;
        }
        else
        {
            media = new Media(key);
        }
        try { media.UseCustomTimecode = ChildBoolean(elt, "UseCustomTimecode"); } catch { }
        if (media.IsOffline() || media.UseCustomTimecode)
        {
            media.TimecodeIn = ChildTimecode(elt, "TimecodeIn");
        }
        if (media.IsOffline())
        {
            Timecode tcOut = ChildTimecode(elt, "TimecodeOut");
            if (0 >= tcOut.Nanos)
            {
                tcOut = ChildTimecode(elt, "Length");
                if (0 >= tcOut.Nanos)
                {
                    throw new ApplicationException("offline media duration not specified.");
                }
                tcOut = media.TimecodeIn + tcOut;
            }
            media.TimecodeOut = tcOut;
        }
        ImportMediaInternal(elt, media);
    }
コード例 #15
0
        public void AddEffectsFirstGroupCuts(List <TrackEvent> cuts)
        {
            foreach (TrackEvent trackEvent in cuts)
            {
                if (trackEvent.MediaType == MediaType.Video)
                {
                    VideoEvent videoEvent = trackEvent as VideoEvent;
                    PlugInNode linearBlur = VegasPans.GetPlugin(myVegas, Config.pluginName);
                    using (UndoBlock undo = new UndoBlock("Add plugin to first clip"))
                    {
                        Effect effect = videoEvent.Effects.AddEffect(linearBlur);
                        effect.Preset = Config.pluginPreset;
                    }

                    var method = typeof(VegasPans).GetMethod(VegasPans.GetPanFunction(transitionMode, TransitionVideo.First));
                    var result = method.Invoke(null, new object[] { myVegas, videoEvent });
                }
            }
        }
コード例 #16
0
    Guid plugInClassID = new Guid("2869bb94-4971-4ccc-94ca-743666a85938"); // "Sony Timecode"

    public void FromVegas(Vegas vegas)
    {
        PlugInNode plugIn = vegas.VideoFX.GetChildByClassID(plugInClassID);

        if (null == plugIn)
        {
            throw new ApplicationException("Could not find video plug-in.");
        }

        foreach (Media media in vegas.Project.MediaPool)
        {
            foreach (Effect effect in media.Effects)
            {
                if (effect.PlugIn == plugIn)
                {
                    media.Effects.Remove(effect);
                    break;
                }
            }
        }
    }
コード例 #17
0
        public static void GetPlugInNodeList(PlugInNode pin, List <string> plugInsList, StringBuilder plugInsSB, int deep = 0)
        {
            var pinEnum = pin.GetEnumerator();

            if (pinEnum.MoveNext())
            {
                plugInsSB.Append($"{new string('\t', deep)}PlugInNode:'{pin.Name}'{Environment.NewLine}");
                //GetPresets(pin, deep + 1, plugInsList, plugInsSB);

                do
                {
                    GetPlugInNodeList(pinEnum.Current, plugInsList, plugInsSB, deep + 1);
                }while(pinEnum.MoveNext());
            }
            else
            {
                plugInsList.Add($"{pin.Name}");
                plugInsSB.Append($"{new string('\t', deep)}PlugIn:'{pin.Name}'{Environment.NewLine}");
                //GetPresets(pin, deep + 1, plugInsList, plugInsSB);
            }
        }
コード例 #18
0
        public static void SetEffectToElement(ElementStep elementStep)
        {
            if (!elementStep.Selector.IsValid() || elementStep.Selector.ElementType == ElementType.None)
            {
                return;
            }

            if (elementStep.Selector.ElementType == ElementType.Event)
            {
                TrackEvent trackEvent  = SelectorService.GetEvent(elementStep.Selector);
                PlugInNode pin         = SelectorService.GetPlugIn(elementStep.DataPropertyList[DataPropertyHolder.EFFECT_NAME].Value);
                string     effectPrest = string.IsNullOrEmpty(elementStep.DataPropertyList[DataPropertyHolder.EFFECT_PRESET_NAME].Value)
                    ? SelectorService.GetPresets(pin)[0]
                    : elementStep.DataPropertyList[DataPropertyHolder.EFFECT_PRESET_NAME].Value;
                Effect effect = new Effect(pin);
                if (elementStep.Selector.IsAudio())
                {
                    (trackEvent as AudioEvent).Effects.Add(effect);
                }
                if (elementStep.Selector.IsVideo())
                {
                    (trackEvent as VideoEvent).Effects.Add(effect);
                }
                effect.Preset = effectPrest;
            }
            if (elementStep.Selector.ElementType == ElementType.Track)
            {
                Track      track       = SelectorService.GetTrack(elementStep.Selector);
                PlugInNode pin         = SelectorService.GetPlugIn(elementStep.DataPropertyList[DataPropertyHolder.EFFECT_NAME].Value);
                string     effectPrest = string.IsNullOrEmpty(elementStep.DataPropertyList[DataPropertyHolder.EFFECT_PRESET_NAME].Value)
                    ? SelectorService.GetPresets(pin)[0]
                    : elementStep.DataPropertyList[DataPropertyHolder.EFFECT_PRESET_NAME].Value;
                Effect effect = new Effect(pin);
                track.Effects.Add(effect);
                effect.Preset = effectPrest;
            }
        }
コード例 #19
0
ファイル: EffectRepository.cs プロジェクト: Burakovivan/VSG
        public static void GetPlugInNodeTree(PlugInNode pin, EffectTreeModel plugInsTree, StringBuilder plugInsSB = null, int deep = 0)
        {
            if (plugInsSB == null)
            {
                plugInsSB = new StringBuilder();
            }

            IEnumerator <PlugInNode> pinEnum = pin.GetEnumerator();

            if (pin.IsContainer)
            {
                var current = new EffectTreeModel
                {
                    Name        = pin.Name,
                    IsContainer = false
                };
                plugInsSB.Append($"{new string('\t', deep)}{(pin.Any() ? "+" : "-")} PlugInNode:'{pin.Name}'{Environment.NewLine}");
                //GetPresets(pin, deep + 1, plugInsList, plugInsSB);
                while (pinEnum.MoveNext())
                {
                    GetPlugInNodeTree(pinEnum.Current, current, plugInsSB, deep + 1);
                }
                plugInsTree.Items.Add(current);
            }
            else
            {
                var current = new EffectTreeModel
                {
                    Name        = pin.Name,
                    IsContainer = true
                };
                plugInsSB.Append($"{new string('\t', deep)}PlugIn:'{pin.Name}'{Environment.NewLine}");
                GetPresets(pin, deep + 1, current, plugInsSB);
                plugInsTree.Items.Add(current);
            }
        }
コード例 #20
0
        Take GenerateTakeText(Vegas vegas, string text)
        {
            if (text.Length == 0)
            {
                return(null);
            }

            // テキストを順次追加
            PlugInNode plugin = vegas.Generators.GetChildByName("VEGAS タイトルおよびテキスト"); // 日本語版だとプラグイン名はこれです。英語版は不明
            Media      media  = new Media(plugin);                                    // これちょっと遅いです

            if (media.Generator == null)
            {
                return(null);
            }
            if (!media.Generator.IsOFX)
            {
                return(null);
            }
            // Text属性を得る。
            // 全属性を見たい場合はウォッチのOfxEffect.Parameters.Results Viewを見るとある。(多分21個)
            OFXEffect          ofxEffect = media.Generator.OFXEffect;
            OFXStringParameter textParam = (OFXStringParameter)ofxEffect.FindParameterByName("Text");

            if (textParam == null)
            {
                return(null);
            }

            // テキストをセット
            RichTextBox richtextBox1 = new RichTextBox();

            richtextBox1.Text = text;
            richtextBox1.SelectAll();                                                     // 全テキストが対象
            richtextBox1.SelectionFont = new System.Drawing.Font(_fontFamily, _fontSize); // フォント変更
            //richtextBox.SaveFile(file); // debug. フォントが変わったか確認してみよう

            // OFXEffectの"Text" Parameterに対して再登録する
            System.Xml.XmlDocument textValDoc = new System.Xml.XmlDocument();
            textValDoc.LoadXml("<OfxParamValue>" + textParam.Value + "</OfxParamValue>");
            System.Xml.XmlNode textPValue = textValDoc.FirstChild;
            textPValue.InnerText = richtextBox1.Rtf; // your new rtf words.
            textParam.Value      = textPValue.InnerText;
            textParam.ParameterChanged();            // Apply changed.

            // これらはTextが見つかれば絶対全部見つかるからnullチェックしない
            OFXRGBAParameter     textColorParam    = (OFXRGBAParameter)ofxEffect.FindParameterByName("TextColor");
            OFXDouble2DParameter locationParam     = (OFXDouble2DParameter)ofxEffect.FindParameterByName("Location");
            OFXChoiceParameter   alignmentParam    = (OFXChoiceParameter)ofxEffect.FindParameterByName("Alignment");
            OFXDoubleParameter   outlineWidthParam = (OFXDoubleParameter)ofxEffect.FindParameterByName("OutlineWidth");
            OFXRGBAParameter     outlineColorParam = (OFXRGBAParameter)ofxEffect.FindParameterByName("OutlineColor");
            OFXBooleanParameter  shadowEnableParam = (OFXBooleanParameter)ofxEffect.FindParameterByName("ShadowEnable");

            //OFXStringParameter shadowColorParam = (OFXStringParameter)ofxEffect.FindParameterByName("ShadowColor");

            // パラメータセット //
            // TextColor
            textColorParam.Value = _fontColor;// new OFXColor(50.0f / 255.0, 100.0f / 255.0f, 150.0f / 255.0f);

            // Alignment
            // alignmentParam.Choiesを確認すること
            // OFXChoiceはReadOnly型なのでなにもできません
            alignmentParam.Value = alignmentParam.Choices[_Align]; //alignmentParam.Choices[7];

            //Location
            OFXDouble2D loc;

            loc.X = _locationX;
            loc.Y = _locationY;
            locationParam.Value = loc;

            // Outline
            outlineWidthParam.Value = _outlineWidth;
            outlineColorParam.Value = _outlineColor;// new OFXColor(10 / 255.0, 10 / 255.0f, 10 / 255.0f);

            MediaStream stream = media.Streams[0];
            //VideoEvent videoEvent = new VideoEvent(Timecode.FromSeconds(_currentTime), Timecode.FromSeconds(_timeLength));
            //track.Events.Add(videoEvent);
            Take take = new Take(stream);

            //videoEvent.Takes.Add(take);

            //_currentTime += _timeLength;

            return(take);
        }
コード例 #21
0
ファイル: EffectRepository.cs プロジェクト: Burakovivan/VSG
        public static List <string> GetPresets(PlugInNode pin, int deep, EffectTreeModel plugInsTree, StringBuilder plugInsSB)
        {
            plugInsSB.AppendLine(pin.Presets.Count > 0 ? String.Join(Environment.NewLine, pin.Presets.Select(p => $"{new string('\t', deep)}Preset:[{p.Index}] '{p.Name}'").ToArray()) : $"{new string('\t', deep)}none presets");

            return(pin.Presets.Select(p => $"{new string('\t', deep)}[{p.Index}] '{p.Name}'").ToList());
        }
コード例 #22
0
ファイル: ImportFlp.cs プロジェクト: THEN00P/vegasYtpmvTools
        private void importCallback(object sender, EventArgs e)
        {
            LogWriter.LogWrite("Callback");

            var importOptions = e as ImportEventArgs;

            using (var undo = new UndoBlock(moduleName))
            {
                try
                {
                    var frameOffsetInMs = (1000 / vegas.Project.Video.FrameRate) * importOptions.FrameOffset;

                    var beatLengthInS = 60 / selectedFlp.Tempo;
                    var ppqLengthInS  = beatLengthInS / selectedFlp.Ppq;


                    PlugInNode solidColor = vegas.Generators.GetChildByUniqueID("{Svfx:com.sonycreativesoftware:solidcolor}");

                    vegas.Project.Markers.Clear();

                    List <List <FullTrackTimes> > fullTrackTimesList = new List <List <FullTrackTimes> >();

                    foreach (int i in importOptions.SelectedIndices)
                    {
                        List <FullTrackTimes> fullTrackTimes = new List <FullTrackTimes>();

                        foreach (var j in selectedFlp.Tracks[i].Items)
                        {
                            if (j is PatternPlaylistItem)
                            {
                                var patternItem = j as PatternPlaylistItem;

                                foreach (Channel channel in patternItem.Pattern.Notes.Keys)
                                {
                                    foreach (Note note in patternItem.Pattern.Notes[channel])
                                    {
                                        if (note.Position < patternItem.StartOffset)
                                        {
                                            continue;
                                        }
                                        if (note.Position > patternItem.Length)
                                        {
                                            continue;
                                        }

                                        var noteStartPpq = patternItem.Position + (note.Position - patternItem.StartOffset);
                                        var startInMs    = noteStartPpq * ppqLengthInS * 1000;

                                        var noteEndInMs = note.Length * ppqLengthInS * 1000;

                                        startInMs =
                                            (frameOffsetInMs + startInMs < 0) ?
                                            (int)(frameOffsetInMs + startInMs) :
                                            (int)startInMs;

                                        noteEndInMs =
                                            (frameOffsetInMs + noteEndInMs < 0) ?
                                            (int)(frameOffsetInMs + noteEndInMs) :
                                            (int)noteEndInMs;

                                        fullTrackTimes.Add(new FullTrackTimes(startInMs, noteEndInMs));
                                    }
                                }
                            }
                            //if(j is ChannelPlaylistItem)
                            //{
                            //    var channelItem = j as ChannelPlaylistItem;

                            //    if(channelItem.Channel.Data is GeneratorData)
                            //    {
                            //        var audioStartPpq = channelItem.Position;
                            //        var startInMs = audioStartPpq * ppqLengthInS * 1000;

                            //        var audioEndPpq = audioStartPpq + channelItem.Length;
                            //        var noteEndInMs = audioEndPpq * ppqLengthInS * 1000;

                            //        fullTrackTimes.Add();
                            //    }
                            //}
                        }

                        fullTrackTimesList.Add(fullTrackTimes);
                    }
                    foreach (var trackTimes in fullTrackTimesList)
                    {
                        if (importOptions.ImportType == "Solid color")
                        {
                            Media      solidColorMedia = Media.CreateInstance(vegas.Project, solidColor);
                            VideoTrack v = vegas.Project.AddVideoTrack();

                            foreach (var fullTrackTimes in trackTimes)
                            {
                                if (importOptions.ImportType == "Solid color")
                                {
                                    VideoEvent ve = v.AddVideoEvent(new Timecode(fullTrackTimes.start), new Timecode(fullTrackTimes.end));
                                    //ve.
                                    ve.AddTake(solidColorMedia.Streams[0]);
                                }
                            }
                        }
                        else if (importOptions.ImportType == "Marker")
                        {
                            foreach (var fullTrackTimes in trackTimes)
                            {
                                if (importOptions.ImportType == "Marker")
                                {
                                    vegas.Project.Markers.Add(new Marker(new Timecode(fullTrackTimes.start)));
                                }
                            }
                        }
                    }
                }
                catch (Exception err)
                {
                    LogWriter.LogWrite(err.ToString());
                    throw err;
                }
            }
        }
コード例 #23
0
    public class EntryPoint {   //The usual stuff for a Vegas script, I'll explain it later (no)
        public void FromVegas(Vegas myVegas)
        {
            PlugInNode pipeffect = myVegas.VideoFX.GetChildByName("VEGAS Picture In Picture"); //Getting the PiP effetc

            if (pipeffect == null)                                                             //if the effect doesn't exists we exit the script with an error message
            {
                MessageBox.Show("You don't have the VEGAS Picture In Picture effect. \n Please install it and try again!");
                return;
            }
            List <VideoEvent> videvents = new List <VideoEvent>();         //A list for the selected events

            foreach (Track myTrack in myVegas.Project.Tracks)              //going through every track and every event, adding the selected video events to the list
            {
                foreach (TrackEvent myEvent in myTrack.Events)
                {
                    if ((myEvent.MediaType == MediaType.Video) && (myEvent.Selected == true))
                    {
                        videvents.Add((VideoEvent)myEvent);
                    }
                }
            }
            double            proWidth  = myVegas.Project.Video.Width;                           //the project's width
            double            proHeight = myVegas.Project.Video.Height;                          //the project's height
            VideoMotionBounds newBound;                                                          //variable for the crop's size
            VideoMotionBounds newerBound;                                                        //variable for crop size if the first one doesn't fit the whole picture

            foreach (VideoEvent pipevent in videvents)                                           // for each video event in the list
            {
                Take                piptake   = pipevent.ActiveTake;                             //getting the width and height of the event's source
                VideoStream         pipstream = piptake.MediaStream as VideoStream;
                int                 myWidth   = pipstream.Width;                                 //the event's width
                int                 myHeight  = pipstream.Height;                                //the event"s height
                double              proAspect = myWidth / (myHeight * (proWidth / proHeight));   //calculating the correct number to multiply later the width/height later
                VideoMotionKeyframe reframe   = new VideoMotionKeyframe(Timecode.FromFrames(0)); //creating a new Pan/Crop keyframe at the beginning of the event
                pipevent.VideoMotion.Keyframes.Add(reframe);
                if (myWidth > myHeight)                                                          //calculating the size of the pan/crop keyframe with the help of the previously calculated value (proAspect) (EXTREMLY COMPLEX AND DANGEROUS, handle with care)
                {
                    newBound = new VideoMotionBounds(new VideoMotionVertex((float)(reframe.Center.X - (double)(myWidth / 2)), (float)(reframe.Center.Y - (double)(myHeight / 2) * proAspect)), new VideoMotionVertex((float)(reframe.Center.X + (double)(myWidth / 2)), (float)(reframe.Center.Y - (double)(myHeight / 2) * proAspect)), new VideoMotionVertex((float)(reframe.Center.X + (double)(myWidth / 2)), (float)(reframe.Center.Y + (double)(myHeight / 2) * proAspect)), new VideoMotionVertex((float)(reframe.Center.X - (double)(myWidth / 2)), (float)(reframe.Center.Y + (double)(myHeight / 2) * proAspect)));
                    if (Math.Abs(newBound.TopLeft.Y - newBound.BottomLeft.Y) < myHeight)                   //if the crop is the correct aspect ration, but it still cuts out part of the image, this code will run and make a cropize, which covers the whole picture with the correct ratio (MORE MATH)
                    {
                        float multiply = myHeight / Math.Abs(newBound.TopLeft.Y - newBound.BottomLeft.Y);
                        float actWidth = Math.Abs(newBound.TopRight.X - newBound.TopLeft.X) / 2;
                        float toHeight = myHeight / 2;
                        newerBound = new VideoMotionBounds(new VideoMotionVertex(reframe.Center.X - actWidth * multiply, reframe.Center.Y - toHeight), new VideoMotionVertex(reframe.Center.X + actWidth * multiply, reframe.Center.Y - toHeight), new VideoMotionVertex(reframe.Center.X + actWidth * multiply, reframe.Center.Y + toHeight), new VideoMotionVertex(reframe.Center.X - actWidth * multiply, reframe.Center.Y + toHeight));
                        newBound   = newerBound;
                    }
                }
                else                 //almost same as above, casual math
                {
                    newBound = new VideoMotionBounds(new VideoMotionVertex((float)(reframe.Center.X - (double)(myWidth / 2) / proAspect), (float)(reframe.Center.Y - (double)(myHeight / 2))), new VideoMotionVertex((float)(reframe.Center.X + (double)(myWidth / 2) / proAspect), (float)(reframe.Center.Y - (double)(myHeight / 2))), new VideoMotionVertex((float)(reframe.Center.X + (double)(myWidth / 2) / proAspect), (float)(reframe.Center.Y + (double)(myHeight / 2))), new VideoMotionVertex((float)(reframe.Center.X - (double)(myWidth / 2) / proAspect), (float)(reframe.Center.Y + (double)(myHeight / 2))));
                    if (Math.Abs(newBound.TopRight.X - newBound.TopLeft.X) < myWidth)
                    {
                        float multiply  = myHeight / Math.Abs(newBound.TopRight.X - newBound.TopLeft.X);
                        float toWidth   = myWidth / 2;
                        float actHeight = Math.Abs(newBound.TopLeft.Y - newBound.BottomLeft.Y / 2);
                        newerBound = new VideoMotionBounds(new VideoMotionVertex(reframe.Center.X - toWidth, reframe.Center.Y - actHeight * multiply), new VideoMotionVertex(reframe.Center.X + toWidth, reframe.Center.Y - actHeight * multiply), new VideoMotionVertex(reframe.Center.X + toWidth, reframe.Center.Y + actHeight * multiply), new VideoMotionVertex(reframe.Center.X - toWidth, reframe.Center.Y + actHeight * multiply));
                        newBound   = newerBound;
                    }
                }
                reframe.Bounds = newBound;                //setting the keyframe's size
                pipevent.Effects.AddEffect(pipeffect);    //adding the PiP effect to the event
            }
        }
コード例 #24
0
    public void FromVegas(Vegas vegas)
    {
        myVegas = vegas;

        System.Collections.Generic.List <OFXDouble2DKeyframe> locations = new System.Collections.Generic.List <OFXDouble2DKeyframe>();
        Tuple <Timecode, Timecode> durationTrackEvent;

        VideoEvent trackEvent = (VideoEvent)FindFirstSelectedEventUnderCursor();

        if (trackEvent == null)
        {
            MessageBox.Show("Please select the video event on which VEGAS Bezier Masking has been applied.", "No selected event", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            return;
        }
        else
        {
            durationTrackEvent = new Tuple <Timecode, Timecode>(trackEvent.Start, trackEvent.End);
            Effects fxs            = trackEvent.Effects;
            bool    bezierWasFound = false;
            foreach (Effect fx in fxs)
            {
                bezierWasFound = fx.PlugIn.UniqueID == "{Svfx:com.sonycreativesoftware:bzmasking}";
                if (bezierWasFound)
                {
                    OFXParameters parameter = fx.OFXEffect.Parameters;
                    foreach (OFXParameter param in parameter)
                    {
                        if (param.Name == "Location_0")
                        {
                            OFXDouble2DParameter locationTracking = (OFXDouble2DParameter)param;
                            locations = new List <OFXDouble2DKeyframe>(locationTracking.Keyframes);
                            break;
                        }
                    }

                    break;
                }
            }
            if (!bezierWasFound)
            {
                MessageBox.Show("Please apply VEGAS Bezier Masking to the video event", "VEGAS Bezier Masking not applied", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
        }

        if (locations.Count == 0)
        {
            MessageBox.Show("Please add Motion Tracking to the VEGAS Bezier Masking FX", "No tracking data", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            return;
        }
        else
        {
            using (OffsetDialog offsetPrompt = new OffsetDialog())
            {
                DialogResult result = offsetPrompt.ShowDialog();
                if (result == DialogResult.OK)
                {
                    VideoTrack titleTrack    = myVegas.Project.AddVideoTrack();
                    PlugInNode textAndTitles = myVegas.Generators.GetChildByUniqueID("{Svfx:com.sonycreativesoftware:titlesandtext}"); // GetChildByName("VEGAS Titles & Text");//
                    Timecode   lengthEvent   = durationTrackEvent.Item2 - durationTrackEvent.Item1;
                    Media      media         = new Media(textAndTitles, "Placeholder");
                    media.Length = lengthEvent;
                    VideoEvent vEvent = titleTrack.AddVideoEvent(durationTrackEvent.Item1, lengthEvent);
                    Take       take   = new Take(media.Streams[0]);
                    vEvent.Takes.Add(take);

                    Effect        fxText    = media.Generator;
                    OFXParameters parameter = fxText.OFXEffect.Parameters;
                    foreach (OFXParameter param in parameter)
                    {
                        if (param.Name == "Location")
                        {
                            OFXDouble2DParameter locationText = (OFXDouble2DParameter)param;
                            locationText.Keyframes.Clear();
                            foreach (OFXDouble2DKeyframe location in locations)
                            {
                                OFXDouble2D tmpValue = location.Value;
                                tmpValue.X += offsetPrompt.X;
                                tmpValue.Y += offsetPrompt.Y;
                                locationText.SetValueAtTime(location.Time, tmpValue);
                            }

                            break;
                        }
                    }
                }
            }
        }
    }
コード例 #25
0
        public static PlugInNode GetPlugin(Vegas vegas, String plugInName)
        {
            PlugInNode plugIn = vegas.PlugIns.GetChildByName(plugInName);

            return((plugIn != null) ? plugIn : null);
        }
コード例 #26
0
    public void FromVegas(Vegas vegas)
    {
        try
        {
            int      num = 1;          //number of the current song track
            Timecode curr_song_lenght; //the lenght of the current song
            Timecode start_song_start; //the start of the current song

            //The track with songs must be the first one
            AudioTrack track_with_songs = (AudioTrack)vegas.Project.Tracks[0];

            //create a new track for the numbers
            VideoTrack new_track = new VideoTrack(0, "Numerotation");
            vegas.Project.Tracks.Add(new_track);

            foreach (TrackEvent song_event in track_with_songs.Events)
            {
                curr_song_lenght = song_event.Length;
                start_song_start = song_event.Start;

                //create the video event with the corresponding number of the song
                VideoEvent new_event = new VideoEvent(start_song_start, curr_song_lenght);

                PlugInNode plugIn = vegas.Generators.FindChildByUniqueID("{Svfx:com.sonycreativesoftware:titlesandtext}");
                Media      media  = new Media(plugIn);
                new_track.Events.Add(new_event);
                MediaStream stream = media.Streams[0];
                Take        take   = new Take(stream);
                new_event.Takes.Add(take);



                //Set the text
                Effect             effect  = new_event.ActiveTake.Media.Generator;
                OFXEffect          fxo     = effect.OFXEffect;
                OFXStringParameter tparm   = (OFXStringParameter)fxo.FindParameterByName("Text");
                RichTextBox        rtfText = new RichTextBox();



                rtfText.Text = num.ToString();  //the text


                rtfText.SelectAll();
                Font font = new Font(Constants.FONT_FAMILY, Constants.TEXT_SIZE, FontStyle.Bold);  //font and size

                rtfText.SelectAll();
                rtfText.SelectionColor = Color.Cyan;//Constants.TEXT_COLOR;
                rtfText.SelectionFont  = font;

                tparm.Value = rtfText.Rtf;
                fxo.AllParametersChanged();


                num++;
            }
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }
    }
コード例 #27
0
    public void FromVegas(Vegas vegas)
    {
        // select a midi file
        MessageBox.Show("请选择一个MIDI文件。");
        OpenFileDialog openFileDialog = new OpenFileDialog();

        openFileDialog.Filter           = "*.mid|*.mid|所有文件|*.*";
        openFileDialog.RestoreDirectory = true;
        openFileDialog.FilterIndex      = 1;
        if (openFileDialog.ShowDialog() == DialogResult.OK)
        {
            midiName = openFileDialog.FileName;
        }
        else
        {
            return;
        }

        MidiFile midi = new MidiFile(midiName);

        // generate statistics of each midi track
        String[] trackInfo       = new String[midi.Events.Tracks];
        int      ticksPerQuarter = midi.DeltaTicksPerQuarterNote;
        double   msPerQuarter    = 0;

        for (int i = 0; i < midi.Events.Tracks; i++)
        {
            String info1      = "轨道 " + i.ToString() + ": ";
            String info2      = "";
            int    notesCount = 0;
            String info3      = "起音 ";

            foreach (MidiEvent midiEvent in midi.Events[i])
            {
                if ((midiEvent is NoteEvent) && !(midiEvent is NoteOnEvent))
                {
                    NoteEvent noteEvent = midiEvent as NoteEvent;
                    if (notesCount == 0)
                    {
                        info3 = info3 + noteEvent.NoteName;
                    }
                    notesCount++;
                }
                if ((midiEvent is PatchChangeEvent) && info2.Length == 0)
                {
                    PatchChangeEvent patchEvent = midiEvent as PatchChangeEvent;
                    for (int j = 4; j < patchEvent.ToString().Split(' ').Length; j++)
                    {
                        info2 += patchEvent.ToString().Split(' ')[j];
                    }
                }
                if ((midiEvent is TempoEvent) && msPerQuarter == 0)
                {
                    TempoEvent tempoEvent = midiEvent as TempoEvent;
                    msPerQuarter = Convert.ToDouble(tempoEvent.MicrosecondsPerQuarterNote) / 1000;
                }
            }

            trackInfo[i] = info1 + info2 + "; 音符数: " + notesCount.ToString() + "; " + info3;
        }

        // select a video clip
        MessageBox.Show("请选择一个视频或音频素材片段。");
        openFileDialog.Filter           = "所有文件|*.*";
        openFileDialog.RestoreDirectory = true;
        openFileDialog.FilterIndex      = 1;
        if (openFileDialog.ShowDialog() == DialogResult.OK)
        {
            clipName = openFileDialog.FileName;
        }
        else
        {
            return;
        }
        Media  media       = new Media(clipName);
        double mediaLength = media.Length.ToMilliseconds();

        // start configuration
        ConfigForm configForm = new ConfigForm();

        for (int i = 0; i < midi.Events.Tracks; i++)
        {
            configForm.comboBoxTrack.Items.Add(trackInfo[i]);
        }
        configForm.comboBoxTrack.SelectedIndex = 0;
        Application.Run(configForm);

        // apply configuration
        aconfig          = configForm.checkBoxA.Checked;
        aconfigNoTune    = configForm.checkBoxNoTune.Checked;
        vconfig          = configForm.checkBoxV.Checked;
        vconfigAutoFlip  = configForm.checkBoxFlip.Checked;
        vconfigStartSize = configForm.hScrollBar1.Value;
        vconfigEndSize   = configForm.hScrollBar2.Value;
        vconfigFadein    = configForm.hScrollBar4.Value;
        vconfigFadeout   = configForm.hScrollBar3.Value;
        aconfigBasePitch = pitchMap[configForm.comboBoxA1.SelectedItem.ToString() + configForm.comboBoxA2.SelectedItem.ToString()];
        for (int i = 0; i < midi.Events.Tracks; i++)
        {
            if (trackInfo[i] == configForm.comboBoxTrack.SelectedItem.ToString())
            {
                aconfigTrack = i;
            }
        }
        configStartTime = Convert.ToDouble(configForm.startT) * 1000;
        configEndTime   = Convert.ToDouble(configForm.endT) * 1000;

        // start processing MIDI
        VideoTrack vTrack = vegas.Project.AddVideoTrack();

        AudioTrack[] aTracks         = new AudioTrack[20];
        double       vTrackPosition  = 0;
        int          vTrackDirection = 1;

        double[] aTrackPositions = new double[20];
        aTracks[0]         = vegas.Project.AddAudioTrack();
        aTrackPositions[0] = 0;
        int aTrackCount = 1;

        foreach (MidiEvent midiEvent in midi.Events[aconfigTrack])
        {
            if (midiEvent is NoteOnEvent)
            {
                NoteEvent   noteEvent   = midiEvent as NoteEvent;
                NoteOnEvent noteOnEvent = midiEvent as NoteOnEvent;
                double      startTime   = midiEvent.AbsoluteTime * msPerQuarter / ticksPerQuarter;
                double      duration    = noteOnEvent.NoteLength * msPerQuarter / ticksPerQuarter;
                int         pitch       = noteEvent.NoteNumber;
                int         trackIndex  = 0;

                if (startTime < configStartTime)
                {
                    continue;
                }
                if (startTime > configEndTime)
                {
                    break;
                }

                // generate audio events
                if (aconfig == true)
                {
                    while (startTime < aTrackPositions[trackIndex])
                    {
                        trackIndex++;
                        if (trackIndex == aTrackCount)
                        {
                            aTrackCount++;
                            aTracks[trackIndex] = vegas.Project.AddAudioTrack();
                        }
                    }
                    AudioEvent audioEvent = aTracks[trackIndex].AddAudioEvent(Timecode.FromMilliseconds(startTime), Timecode.FromMilliseconds(duration));
                    Take       take       = audioEvent.AddTake(media.GetAudioStreamByIndex(0));
                    aTrackPositions[trackIndex] = startTime + duration;
                    TrackEvent trackEvent = audioEvent as TrackEvent;
                    trackEvent.PlaybackRate = mediaLength / duration;
                    trackEvent.Loop         = false;

                    // apply pitch shifting

                    if (aconfigNoTune == false)
                    {
                        int pitchDelta = pitch - aconfigBasePitch;
                        if (pitchDelta > 0)
                        {
                            while (pitchDelta > 12)
                            {
                                PlugInNode plugIn0 = vegas.AudioFX.FindChildByName("Pitch Shift");
                                Effect     effect0 = new Effect(plugIn0);
                                audioEvent.Effects.Add(effect0);
                                effect0.Preset = "12";
                                pitchDelta    -= 12;
                            }
                            PlugInNode plugIn = vegas.AudioFX.FindChildByName("Pitch Shift");
                            Effect     effect = new Effect(plugIn);
                            audioEvent.Effects.Add(effect);
                            effect.Preset = pitchDelta.ToString();
                        }
                        else
                        {
                            while (pitchDelta < -12)
                            {
                                PlugInNode plugIn0 = vegas.AudioFX.FindChildByName("Pitch Shift");
                                Effect     effect0 = new Effect(plugIn0);
                                audioEvent.Effects.Add(effect0);
                                effect0.Preset = "-12";
                                pitchDelta    += 12;
                            }
                            PlugInNode plugIn = vegas.AudioFX.FindChildByName("Pitch Shift");
                            Effect     effect = new Effect(plugIn);
                            audioEvent.Effects.Add(effect);
                            effect.Preset = pitchDelta.ToString();
                        }
                    }
                }

                // generate video events
                if (vconfig == true)
                {
                    vTrackPosition = startTime + duration;
                    VideoEvent videoEvent = vTrack.AddVideoEvent(Timecode.FromMilliseconds(startTime), Timecode.FromMilliseconds(duration));
                    Take       take       = videoEvent.AddTake(media.GetVideoStreamByIndex(0));
                    TrackEvent trackEvent = videoEvent as TrackEvent;
                    trackEvent.PlaybackRate = mediaLength / duration;
                    trackEvent.Loop         = false;

                    videoEvent.FadeIn.Length  = Timecode.FromMilliseconds(duration * vconfigFadein / 100);
                    videoEvent.FadeOut.Length = Timecode.FromMilliseconds(duration * vconfigFadeout / 100);

                    VideoMotionKeyframe key0 = videoEvent.VideoMotion.Keyframes[0];
                    VideoMotionKeyframe key1 = new VideoMotionKeyframe(Timecode.FromMilliseconds(duration));
                    videoEvent.VideoMotion.Keyframes.Add(key1);
                    key0.ScaleBy(new VideoMotionVertex((vconfigStartSize / 100) * vTrackDirection, (vconfigStartSize / 100)));
                    key1.ScaleBy(new VideoMotionVertex((vconfigEndSize / 100) * vTrackDirection, (vconfigEndSize / 100)));

                    if (vconfigAutoFlip == true)
                    {
                        vTrackDirection *= -1;
                    }
                }
            }
        }
    }