using System.Diagnostics;
using System.Drawing;
using System.IO;
+using System.IO.Pipes;
using System.Linq;
using System.Reflection;
using System.Text.RegularExpressions;
this.最後にプレイヤーに渡した一時ファイル名,
一時ファイルである: true ); // 一時ファイルなので、「最近使ったファイル一覧」には残さない。
- // プレイヤーを起動する。
- string 仮想ドラムオプション = ( 仮想ドラムを使う ) ? @" -d" : @"";
- //Process.Start( 普通に起動するバージョン。
- // this.Config.ViewerPath,
- // $"\"{this.最後にプレイヤーに渡した一時ファイル名}\" -p {小節番号.ToString()}{仮想ドラムオプション}" );
- var viewerProcess = new Process();
- viewerProcess.StartInfo.RedirectStandardOutput = true; // 標準出力をリダイレクトする。
- viewerProcess.StartInfo.UseShellExecute = false; // リダイレクトするなら false が必須。
- viewerProcess.StartInfo.FileName = this.Config.ViewerPath;
- viewerProcess.StartInfo.Arguments = $"\"{this.最後にプレイヤーに渡した一時ファイル名}\" -p {小節番号.ToString()}{仮想ドラムオプション}";
- viewerProcess.Start();
-
- // プレイヤーの標準出力から、デバイス情報を得る。
- var sor = viewerProcess.StandardOutput;
- string line = null;
- while( ( line = sor.ReadLine() ) != null )
- {
- var match = Regex.Match( line, @"^SoundDevice.Delay=(\d+(\.\d+)?)$" ); // 負数やべき乗は非対応。
- if( match.Success )
+ using( var stream = new NamedPipeServerStream( "SSTFEditor Viewer Device Information" ) )
+ {
+ // ビュアーを起動する。
+ string 仮想ドラムオプション = ( 仮想ドラムを使う ) ? @" -d" : @"";
+ try
{
- var strValue = match.Groups[ 1 ].Value;
- float value = 0f;
- if( float.TryParse( strValue, out value ) ) // 正しく float に変換できる文字列なら、
- this.textBoxサウンド遅延ms.Text = strValue; // GUI へセットする。
- break;
+ Process.Start(
+ this.Config.ViewerPath,
+ $"\"{this.最後にプレイヤーに渡した一時ファイル名}\" -p {小節番号.ToString()}{仮想ドラムオプション}" );
+ }
+ catch
+ {
+ return; // 起動に失敗。
+ }
+
+ // デバイス情報を得る。
+ stream.WaitForConnection();
+
+ using( var reader = new StreamReader( stream ) )
+ {
+ var msg = reader.ReadLine();
+
+ var match = Regex.Match( msg, @"^SoundDevice.Delay=(\d+(\.\d+)?)$" ); // 負数やべき乗には非対応。
+ if( match.Success )
+ {
+ var strValue = match.Groups[ 1 ].Value;
+ float value = 0f;
+ if( float.TryParse( strValue, out value ) ) // 正しく float に変換できる文字列なら、
+ this.textBoxサウンド遅延ms.Text = strValue; // GUI へセットする。
+ }
}
}
}
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
+using System.IO.Pipes;
using System.Linq;
using System.Windows.Forms;
using Microsoft.VisualBasic.ApplicationServices;
//----------------
StrokeStyleT.bs_Wasapiデバイス = new FDK.メディア.サウンド.WASAPI排他.ExclusiveDevice();
StrokeStyleT.bs_Wasapiデバイス.初期化する( 15.0f );
-
- if( StrokeStyleT.ビュアーモードである )
- {
- // デバイス情報を標準出力へ出力する。
- Console.WriteLine( $"SoundDevice.Delay={StrokeStyleT.bs_Wasapiデバイス.遅延ms}" );
- }
//----------------
#endregion
#region " キーボード入力 を初期化する。"
if( this.曲読込ステージ.現在のフェーズ == ステージ.曲読込.曲読込ステージ.フェーズ.終了 )
{
this.現在のステージ.非活性化する( this.デバイスリソース );
+
+ if( StrokeStyleT.ビュアーモードである )
+ this.デバイス情報を出力する();
+
this.現在のステージ = this.演奏ステージ;
this.現在のステージ.活性化する( this.デバイスリソース );
}
StrokeStyleT.ユーザ管理.ユーザを選択する( ユーザ名 );
FDK.Log.Info( $"ユーザが選択されました。[{StrokeStyleT.ユーザ管理.現在選択されているユーザ.名前}]" );
}
+ private void デバイス情報を出力する()
+ {
+ using( var stream = new NamedPipeClientStream( "SSTFEditor Viewer Device Information" ) )
+ {
+ try
+ {
+ stream.Connect( 1000 );
+
+ using( var writer = new StreamWriter( stream ) )
+ {
+ writer.WriteLine( $"SoundDevice.Delay={StrokeStyleT.Wasapiデバイス.遅延ms.ToString()}" );
+ FDK.Log.Info( "デバイス情報を出力しました。" );
+ }
+ }
+ catch( TimeoutException )
+ {
+ FDK.Log.WARNING( "SSTFEditor ビュアー用パイプへの接続がタイムアウトしました。SSTFEditor が起動していない可能性があります。" );
+ }
+ }
+ }
#region " Win32 API "
//-----------------