Ejemplo n.º 1
0
        public string OutputVMD(List <Point> points, int frameLength, string morphName, double startRatio, double endRatio)
        {
            string FileName = $"Complemented_{new string(morphName.Where(c => !Path.GetInvalidFileNameChars().Contains(c)).ToArray())}.vmd";

            VocaloidMotionData vmd = new VocaloidMotionData();

            vmd.ModelName = "Complemented Morphs";
            vmd.MorphFrames.AddRange(points.Select(p => new VmdMorphFrameData(morphName, (uint)Math.Round(p.X * frameLength), (float)(p.Y * (endRatio - startRatio) + startRatio))));

            using (BinaryWriter writer = new BinaryWriter(new FileStream(FileName, FileMode.OpenOrCreate)))
            {
                Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
                vmd.Write(writer);
            }

            return(FileName);
        }
Ejemplo n.º 2
0
        private void ButtonExcute_Click(object sender, EventArgs e)
        {
            try
            {
                if (filePath == null)
                {
                    throw new InvalidOperationException();
                }
            }
            catch (InvalidOperationException)
            {
                MessageBox.Show("vmdファイルを読み込んでください。");
                return;
            }

            if (checkBoxReload.Checked)
            {
                OpenFile(filePath);
            }

            var vmdMotionBuffer = vmd.MotionFrames;

            try
            {
                vmd.MotionFrames = GetLoopFrame(vmd.MotionFrames);
            }
            catch (DivideByZeroException)
            {
                MessageBox.Show("BPMが0です。");
                return;
            }

            var vmdMorphBuffer = vmd.MorphFrames;

            try
            {
                vmd.MorphFrames = GetLoopFrame(vmd.MorphFrames);
            }
            catch (DivideByZeroException)
            {
                MessageBox.Show("BPMが0です。");
                return;
            }


            string writePath;

            writePath = Path.GetDirectoryName(filePath) + @"\" + Path.GetFileNameWithoutExtension(filePath) + "_loop.vmd";
            try
            {
                var writer = new BinaryWriter(File.OpenWrite(writePath));
                vmd.Write(writer);
                writer.Close();
            }
            catch (Exception)
            {
                MessageBox.Show("データ出力に失敗しました。");
            }

            textBoxDisplay.AppendText("出力キーフレーム数:" + (vmd.MotionFrames.Count + vmd.MorphFrames.Count).ToString() + Environment.NewLine);
            textBoxDisplay.AppendText("出力データパス:" + writePath + Environment.NewLine + Environment.NewLine);
            vmd.MotionFrames = vmdMotionBuffer;
            vmd.MorphFrames  = vmdMorphBuffer;
        }