示例#1
0
        /// <summary>
        /// VOICEROIDの保存パスとして正常か否かを取得する。
        /// </summary>
        /// <param name="path">調べるパス。</param>
        /// <param name="invalidLetter">
        /// 不正原因文字の設定先。正常な場合や文字不明の場合は null が設定される。
        /// </param>
        /// <returns>正常ならば true 。そうでなければ false 。</returns>
        public static bool IsValidPath(string path, out string invalidLetter)
        {
            invalidLetter = null;

            if (string.IsNullOrWhiteSpace(path))
            {
                return(false);
            }

            var cp932Path = ToCodePage932String(path);

            if (cp932Path != path)
            {
                var fileElems  = new TextElementEnumerable(path);
                var cp932Elems = new TextElementEnumerable(cp932Path);
                invalidLetter =
                    fileElems
                    .Zip(cp932Elems, (e1, e2) => (e1 == e2) ? null : e1)
                    .FirstOrDefault(e => e != null);
                return(false);
            }

            return(true);
        }
示例#2
0
        /// <summary>
        /// フォームが閉じる際の字幕処理を行う。
        /// </summary>
        /// <param name="lipFrameLength">
        /// 口パクのフレーム長。口パクしないならば 0 。
        /// </param>
        /// <returns>確認メッセージ。確認不要ならば null 。</returns>
        private string ProcessCaptionOnFormClosing(long lipFrameLength)
        {
            string confirm = null;

            // 初期化
            this.CaptionInfo = null;
            this.CaptionFrameLength = 0;
            this.CaptionFadeInLength = 0;
            this.CaptionFadeOutLength = 0;

            if (this.CaptionEnabled)
            {
                // 字幕情報設定
                var preset = FindCaptionPreset(this.CaptionPresetName);
                this.CaptionInfo = preset.Value.Clone();

                // XY位置上書き
                if (this.CaptionXYEnabled)
                {
                    this.CaptionInfo.X = this.CaptionX;
                    this.CaptionInfo.Y = this.CaptionY;
                }

                if (string.IsNullOrEmpty(this.CaptionText))
                {
                    // 確認文作成
                    confirm = @"入力文が空のため、字幕は表示されません。";
                }
                else
                {
                    // 字幕フレーム長決定
                    this.CaptionFrameLength = this.CaptionFixedSpanFrame;
                    if (this.CaptionLetterSpanFrame > 0)
                    {
                        // 改行を除く文字数分を加算
                        var letters =
                            new TextElementEnumerable(
                                RemoveCrLf(this.CaptionText));
                        this.CaptionFrameLength +=
                            this.CaptionLetterSpanFrame * letters.Count();
                    }

                    // 口パクのフレーム長より短くはならない
                    this.CaptionFrameLength =
                        Math.Max(
                            this.CaptionFrameLength,
                            Math.Max(lipFrameLength, 1L));

                    // フェードイン/アウトフレーム長決定
                    double fadeRate = 1;
                    var fadeTotal =
                        this.CaptionFadeInFrame + this.CaptionFadeOutFrame;
                    if (fadeTotal > this.CaptionFrameLength)
                    {
                        // フェード長合計がフレーム長を超える場合は
                        // 割合をそのままに短くする
                        fadeRate = (double)this.CaptionFrameLength / fadeTotal;
                    }
                    this.CaptionFadeInLength = this.CaptionFadeInFrame * fadeRate;
                    this.CaptionFadeOutLength = this.CaptionFadeOutFrame * fadeRate;

                    // 確認文作成
                    confirm =
                        @"字幕の総フレーム長は " + this.CaptionFrameLength +
                        @" フレームになります。";
                    if (fadeRate < 1)
                    {
                        if (this.CaptionFadeInLength > 0)
                        {
                            confirm +=
                                Environment.NewLine +
                                @"フェードインフレーム長は約 " +
                                this.CaptionFadeInLength.ToString("F1") +
                                @" フレームに縮められます。";
                        }
                        if (this.CaptionFadeOutLength > 0)
                        {
                            confirm +=
                                Environment.NewLine +
                                @"フェードアウトフレーム長は約 " +
                                this.CaptionFadeOutLength.ToString("F1") +
                                @" フレームに縮められます。";
                        }
                    }
                }
            }

            return confirm;
        }