OSDN Git Service

#37271 ドラムとギター/ベースの最大同時発音数を独立して設定できるようにした。CONFIGURATION/System/Sound Option/Polyphoni...
[dtxmania/dtxmania.git] / DTXMania / コード / 全体 / CDTXMania.cs
index 8e8a664..556af49 100644 (file)
@@ -7,11 +7,13 @@ using System.Drawing;
 using System.Diagnostics;
 using System.IO;
 using System.Threading;
+using System.Management;
 using SharpDX;
 using SharpDX.Direct3D9;
 using FDK;
 using SampleFramework;
 using System.Runtime.Serialization;
+using System.Runtime;
 using System.Xml;
 
 using Point = System.Drawing.Point;
@@ -23,11 +25,11 @@ namespace DTXMania
        {
                // プロパティ
                #region [ properties ]
-               public static readonly string VERSION = "109(170723)";
-               public static readonly string SLIMDXDLL = "c_net20x86_Jun2010";
+               public static readonly string VERSION = "118(200510)";
+               //public static readonly string SLIMDXDLL = "c_net20x86_Jun2010";
                public static readonly string D3DXDLL = "d3dx9_43.dll";     // June 2010
-                                                                                                                                                                                                                                                               //public static readonly string D3DXDLL = "d3dx9_42.dll";       // February 2010
-                                                                                                                                                                                                                                                               //public static readonly string D3DXDLL = "d3dx9_41.dll";       // March 2009
+               //public static readonly string D3DXDLL = "d3dx9_42.dll";       // February 2010
+               //public static readonly string D3DXDLL = "d3dx9_41.dll";       // March 2009
                private static CDTXMania instance = new CDTXMania();
 
                public static CDTXMania Instance
@@ -146,6 +148,7 @@ namespace DTXMania
                public CStage終了 stage終了 { get; private set; }
                public CStage r現在のステージ = null;
                public CStage r直前のステージ = null;
+               public CStage r1フレーム前のステージ = null;
                public string strEXEのあるフォルダ { get; private set; }
                public string strコンパクトモードファイル { get; private set; }
                public CTimer Timer { get; private set; }
@@ -174,12 +177,14 @@ namespace DTXMania
                                return base.Window.Handle;
                        }
                }
-               public CDTXVmode DTXVmode { get; set; }// #28821 2014.1.23 yyagi
-               #endregion
+        public CDTXVmode DTXVmode;                       // #28821 2014.1.23 yyagi
+        public CDTX2WAVmode DTX2WAVmode;
+        public CCommandParse CommandParse;
+        #endregion
 
-               // コンストラクタ
+        // コンストラクタ
 
-               private CDTXMania()
+        private CDTXMania()
                {
                }
 
@@ -197,13 +202,13 @@ namespace DTXMania
                        #endregion
 
                        #region [ 言語リソースの初期化 ]
-                       Trace.TraceInformation( "言語リソースの初期化を行います。" );
+                       Trace.TraceInformation("言語リソースの初期化を行います。");
                        Trace.Indent();
                        try
                        {
                                Resources = new CResources();
-                               Resources.LoadResources( "" );
-                               Trace.TraceInformation( "言語リソースの初期化を完了しました。" );
+                               Resources.LoadResources("");
+                               Trace.TraceInformation("言語リソースの初期化を完了しました。");
                        }
                        finally
                        {
@@ -253,40 +258,44 @@ namespace DTXMania
                        }
                        Trace.WriteLine("");
                        Trace.WriteLine("DTXMania powered by YAMAHA Silent Session Drums");
-                       Trace.WriteLine(string.Format("Release: {0}", VERSION));
+                       Trace.WriteLine(string.Format("Release: {0} {1} mode.", VERSION, (Environment.Is64BitProcess)? "x64":"x86" ));
                        Trace.WriteLine("");
                        Trace.TraceInformation("----------------------");
                        Trace.TraceInformation("■ アプリケーションの初期化");
-                       Trace.TraceInformation("OS Version: " + Environment.OSVersion);
-                       Trace.TraceInformation("ProcessorCount: " + Environment.ProcessorCount.ToString());
-                       Trace.TraceInformation("CLR Version: " + Environment.Version.ToString());
+
+                       CPutSystemLog.PutSystemLog();
                        #endregion
 
                        #region [ 言語の設定 ]
-                       Trace.TraceInformation( "言語情報の読み込みを開始します。" );
+                       Trace.TraceInformation("言語情報の読み込みを開始します。");
                        //Debug.WriteLine( "language=" + Resources.Language );
                        //Debug.WriteLine( "settings=" + instance.ConfigIni.strLanguage );
                        Resources.Language = instance.ConfigIni.strLanguage;
-                       Trace.TraceInformation( "言語を{0}に設定しました。", Resources.Language );
+                       Trace.TraceInformation("言語を{0}に設定しました。", Resources.Language);
 
                        #endregion
 
-       
-                       #region [ DTXVmodeクラス の初期化 ]
+                       #region [ DTXVmodeクラス, DTX2WAVmodeクラス, CommandParseクラス の初期化 ]
                        //Trace.TraceInformation( "DTXVモードの初期化を行います。" );
                        //Trace.Indent();
                        try
                        {
                                DTXVmode = new CDTXVmode();
                                DTXVmode.Enabled = false;
-                               //Trace.TraceInformation( "DTXVモードの初期化を完了しました。" );
-                       }
-                       finally
+                //Trace.TraceInformation( "DTXVモードの初期化を完了しました。" );
+
+                DTX2WAVmode = new CDTX2WAVmode();
+                //Trace.TraceInformation( "DTX2WAVモードの初期化を完了しました。" );
+
+                CommandParse = new CCommandParse();
+                //Trace.TraceInformation( "CommandParseの初期化を完了しました。" );
+            }
+            finally
                        {
                                //Trace.Unindent();
                        }
                        #endregion
-                       #region [ コンパクトモードスイッチの有無、もしくは、DTXViewerとしての起動 ]
+                       #region [ コンパクトモードスイッチの有無、もしくは、DTXViewer/DTX2WAVとしての起動 ]
                        bコンパクトモード = false;
                        strコンパクトモードファイル = "";
                        string[] commandLineArgs = Environment.GetCommandLineArgs();
@@ -306,7 +315,7 @@ namespace DTXMania
                                                arg += commandLineArgs[i];
                                        }
                                }
-                               DTXVmode.ParseArguments(arg);
+                               CommandParse.ParseArguments(arg, ref DTXVmode, ref DTX2WAVmode);
                                if (DTXVmode.Enabled)
                                {
                                        DTXVmode.Refreshed = false;                             // 初回起動時は再読み込みに走らせない
@@ -340,12 +349,146 @@ namespace DTXMania
                                        }
 
                                        CDTXMania.Instance.ConfigIni.bFullScreen.Value = false;
-                                       CDTXMania.Instance.ConfigIni.rcWindow_backup = CDTXMania.Instance.ConfigIni.rcWindow;           // #36612 2016.9.12 yyagi
+                                       CDTXMania.Instance.ConfigIni.rcWindow_backup = CDTXMania.Instance.ConfigIni.rcWindow;       // #36612 2016.9.12 yyagi
                                        CDTXMania.Instance.ConfigIni.rcWindow.W = CDTXMania.Instance.ConfigIni.rcViewerWindow.W;
                                        CDTXMania.Instance.ConfigIni.rcWindow.H = CDTXMania.Instance.ConfigIni.rcViewerWindow.H;
                                        CDTXMania.Instance.ConfigIni.rcWindow.X = CDTXMania.Instance.ConfigIni.rcViewerWindow.X;
                                        CDTXMania.Instance.ConfigIni.rcWindow.Y = CDTXMania.Instance.ConfigIni.rcViewerWindow.Y;
                                }
+                               else if (DTX2WAVmode.Enabled)
+                               {
+                                       strコンパクトモードファイル = DTX2WAVmode.dtxfilename;
+                                       #region [ FDKへの録音設定 ]
+                                       FDK.CSound管理.strRecordInputDTXfilename = DTX2WAVmode.dtxfilename;
+                                       FDK.CSound管理.strRecordOutFilename = DTX2WAVmode.outfilename;
+                                       FDK.CSound管理.strRecordFileType = DTX2WAVmode.Format.ToString();
+                                       FDK.CSound管理.nBitrate = DTX2WAVmode.bitrate;
+                                       for (int i = 0; i < (int)FDK.CSound.EInstType.Unknown; i++)
+                                       {
+                                               FDK.CSound管理.nMixerVolume[ i ] = DTX2WAVmode.nMixerVolume[ i ];
+                                       }
+                                       ConfigIni.nMasterVolume.Value = DTX2WAVmode.nMixerVolume[(int)FDK.CSound.EInstType.Unknown];    // [5](Unknown)のところにMasterVolumeが入ってくるので注意
+                                                                                                                                                                                                                                       // CSound管理.nMixerVolume[5]は、結局ここからは変更しないため、
+                                                                                                                                                                                                                                       // 事実上初期値=100で固定。
+                                       #endregion
+                                       #region [ 録音用の本体設定 ]
+
+                                       // 本体プロセスの優先度を少し上げる (最小化状態で動作させると、処理性能が落ちるようなので
+                                       // → ほとんど効果がなかったので止めます
+                                       //Process thisProcess = System.Diagnostics.Process.GetCurrentProcess();
+                                       //thisProcess.PriorityClass = ProcessPriorityClass.AboveNormal;
+
+                                       // エンコーダーのパス設定 (=DLLフォルダ)
+                                       FDK.CSound管理.strEncoderPath = Path.Combine(strEXEのあるフォルダ, "DLL");
+
+                                       CDTXMania.instance.ConfigIni.nSoundDeviceType.Value = ESoundDeviceTypeForConfig.WASAPI_Exclusive;
+                                       CDTXMania.instance.ConfigIni.bEventDrivenWASAPI.Value = false;
+
+                                       CDTXMania.instance.ConfigIni.bVSyncWait.Value = false;
+                                       CDTXMania.instance.ConfigIni.bTimeStretch.Value = false;
+                                       CDTXMania.instance.ConfigIni.eActiveInst.Value = EActiveInstrument.Both;
+
+                                       CDTXMania.instance.ConfigIni.bFullScreen.Value = false;
+                                       CDTXMania.instance.ConfigIni.rcWindow_backup = CDTXMania.Instance.ConfigIni.rcWindow;
+                                       CDTXMania.instance.ConfigIni.rcWindow.W = CDTXMania.Instance.ConfigIni.rcViewerWindow.W;
+                                       CDTXMania.instance.ConfigIni.rcWindow.H = CDTXMania.Instance.ConfigIni.rcViewerWindow.H;
+                                       CDTXMania.instance.ConfigIni.rcWindow.X = CDTXMania.Instance.ConfigIni.rcViewerWindow.X;
+                                       CDTXMania.instance.ConfigIni.rcWindow.Y = CDTXMania.Instance.ConfigIni.rcViewerWindow.Y;
+
+                                       //全オート
+                                       CDTXMania.instance.ConfigIni.bAutoPlay.LC.Value = true;
+                                       CDTXMania.instance.ConfigIni.bAutoPlay.HH.Value = true;
+                                       CDTXMania.instance.ConfigIni.bAutoPlay.HHO.Value = true;
+                                       CDTXMania.instance.ConfigIni.bAutoPlay.SD.Value = true;
+                                       CDTXMania.instance.ConfigIni.bAutoPlay.BD.Value = true;
+                                       CDTXMania.instance.ConfigIni.bAutoPlay.HT.Value = true;
+                                       CDTXMania.instance.ConfigIni.bAutoPlay.LT.Value = true;
+                                       CDTXMania.instance.ConfigIni.bAutoPlay.FT.Value = true;
+                                       CDTXMania.instance.ConfigIni.bAutoPlay.CY.Value = true;
+                                       CDTXMania.instance.ConfigIni.bAutoPlay.RD.Value = true;
+
+                                       CDTXMania.instance.ConfigIni.bAutoPlay.GtR.Value = true;
+                                       CDTXMania.instance.ConfigIni.bAutoPlay.GtG.Value = true;
+                                       CDTXMania.instance.ConfigIni.bAutoPlay.GtB.Value = true;
+                                       CDTXMania.instance.ConfigIni.bAutoPlay.GtPick.Value = true;
+                                       //CDTXMania.instance.ConfigIni.bAutoPlay.GtWail.Value = true;  // 無くてもよい 処理不可削減のため、敢えてWailはAutoにしない
+                                       CDTXMania.instance.ConfigIni.bAutoPlay.BsR.Value = true;
+                                       CDTXMania.instance.ConfigIni.bAutoPlay.BsG.Value = true;
+                                       CDTXMania.instance.ConfigIni.bAutoPlay.BsB.Value = true;
+                                       CDTXMania.instance.ConfigIni.bAutoPlay.BsPick.Value = true;
+                                       //CDTXMania.instance.ConfigIni.bAutoPlay.BsWail.Value = true;
+
+                                       //FillInオフ, 歓声オフ
+                                       CDTXMania.instance.ConfigIni.bFillin.Value = false;
+                                       CDTXMania.instance.ConfigIni.bAudience.Value = false;
+                                       //ストイックモード
+                                       CDTXMania.instance.ConfigIni.bStoicMode.Value = false;
+                                       //チップ非表示
+                                       CDTXMania.instance.ConfigIni.eSudHidInv.Drums.Value = ESudHidInv.FullInv;
+                                       CDTXMania.instance.ConfigIni.eSudHidInv.Guitar.Value = ESudHidInv.FullInv;
+                                       CDTXMania.instance.ConfigIni.eSudHidInv.Bass.Value = ESudHidInv.FullInv;
+
+                                       // Dark=Full
+                                       CDTXMania.instance.ConfigIni.eDark.Value = EDark.Full;
+
+                                       //多重再生数=4
+                                       CDTXMania.instance.ConfigIni.nPolyphonicSounds.Value = 4;
+                                       CDTXMania.instance.ConfigIni.nPolyphonicSoundsGB.Value = 2;
+
+                                       //再生速度x1
+                                       CDTXMania.instance.ConfigIni.nPlaySpeed.Value = 20;
+
+                                       //メトロノーム音量0
+                                       CDTXMania.instance.ConfigIni.eClickType.Value = EClickType.Off;
+                                       CDTXMania.instance.ConfigIni.nClickHighVolume.Value = 0;
+                                       CDTXMania.instance.ConfigIni.nClickLowVolume.Value = 0;
+
+                                       //自動再生音量=100
+                                       CDTXMania.instance.ConfigIni.nAutoVolume.Value = 100;
+                                       CDTXMania.instance.ConfigIni.nChipVolume.Value = 100;
+
+                                       //マスターボリューム100
+                                       //CDTXMania.instance.ConfigIni.nMasterVolume.Value = 100;       // DTX2WAV側から設定するので、ここでは触らない
+
+                                       //StageFailedオフ
+                                       CDTXMania.instance.ConfigIni.bStageFailed.Value = false;
+
+                                       //グラフ無効
+                                       CDTXMania.instance.ConfigIni.bGraph.Drums.Value = false;
+                                       CDTXMania.instance.ConfigIni.bGraph.Guitar.Value = false;
+                                       CDTXMania.instance.ConfigIni.bGraph.Bass.Value = false;
+
+                                       //コンボ非表示,判定非表示
+                                       CDTXMania.instance.ConfigIni.bDisplayCombo.Drums.Value = false;
+                                       CDTXMania.instance.ConfigIni.bDisplayCombo.Guitar.Value = false;
+                                       CDTXMania.instance.ConfigIni.bDisplayCombo.Bass.Value = false;
+                                       CDTXMania.instance.ConfigIni.bDisplayJudge.Drums.Value = false;
+                                       CDTXMania.instance.ConfigIni.bDisplayJudge.Guitar.Value = false;
+                                       CDTXMania.instance.ConfigIni.bDisplayJudge.Bass.Value = false;
+
+
+                                       //デバッグ表示オフ
+                                       //CDTXMania.instance.ConfigIni.b演奏情報を表示する = false;
+                                       CDTXMania.instance.ConfigIni.bDebugInfo.Value = false;
+
+                                       //BGAオフ, AVIオフ
+                                       CDTXMania.instance.ConfigIni.bBGA.Value = false;
+                                       CDTXMania.instance.ConfigIni.bAVI.Value = false;
+
+                                       //BGMオン、チップ音オン
+                                       CDTXMania.instance.ConfigIni.bBGMPlay.Value = true;
+                                       CDTXMania.instance.ConfigIni.bDrumsHitSound.Value = true;
+
+                                       //パート強調オフ
+                                       CDTXMania.instance.ConfigIni.bEmphasizePlaySound.Drums.Value = false;
+                                       CDTXMania.instance.ConfigIni.bEmphasizePlaySound.Guitar.Value = false;
+                                       CDTXMania.instance.ConfigIni.bEmphasizePlaySound.Bass.Value = false;
+
+                                       // パッド入力等、基本操作の無効化 (ESCを除く)
+                                       //CDTXMania.Instance.ConfigIni.KeyAssign[][];
+                                       
+                                       #endregion
+                               }
                                else                                                        // 通常のコンパクトモード
                                {
                                        strコンパクトモードファイル = commandLineArgs[1];
@@ -371,6 +514,11 @@ namespace DTXMania
                                {
                                        Trace.TraceInformation("DTXVモードで起動します。[{0}]", strコンパクトモードファイル);
                                }
+                               else if (DTX2WAVmode.Enabled)
+                               {
+                                       Trace.TraceInformation("DTX2WAVモードで起動します。[{0}]", strコンパクトモードファイル);
+                                       DTX2WAVmode.SendMessage2DTX2WAV("BOOT");
+                               }
                                else
                                {
                                        Trace.TraceInformation("コンパクトモードで起動します。[{0}]", strコンパクトモードファイル);
@@ -378,7 +526,15 @@ namespace DTXMania
                        }
                        else
                        {
-                               Trace.TraceInformation( "通常モードで起動します。" );
+                               Trace.TraceInformation("通常モードで起動します。");
+                       }
+                       #endregion
+
+                       #region [ 現在の電源プランをバックアップし、CONFIGのHighPower=ONの場合は HighPerformanceに変更 ]
+                       if (CDTXMania.Instance.ConfigIni.bForceHighPowerPlan)
+                       {
+                               CPowerPlan.BackupCurrentPowerPlan();
+                               CPowerPlan.ChangeHighPerformance();
                        }
                        #endregion
 
@@ -389,6 +545,26 @@ namespace DTXMania
                        {
                                bool bUseMIDIIn = !DTXVmode.Enabled;
                                Input管理 = new CInput管理(base.Window.Handle, bUseMIDIIn);
+
+                               // If the users uses MIDI2.0-USB cable, then warn it
+                               if (bUseMIDIIn && CDTXMania.Instance.ConfigIni.bWarnMIDI20USB.Value)
+                               {
+                                       foreach (IInputDevice device in Input管理.list入力デバイス)
+                                       {
+                                               if ((device.e入力デバイス種別 == E入力デバイス種別.MidiIn) && (device.strDeviceName == "USB2.0-MIDI"))
+                                               {
+                                                       string strWarnMes = CDTXMania.Instance.Resources.Explanation("strWarnMIDI20USB");
+                                                       var ret = MessageBox.Show(strWarnMes, "DTXMania Warning", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2);
+                                                       if (ret == DialogResult.OK)
+                                                       {
+                                                               CDTXMania.Instance.ConfigIni.bWarnMIDI20USB.Value = false;
+                                                       }
+                                               }
+                                       }
+                               }
+
+
+
                                foreach (IInputDevice device in Input管理.list入力デバイス)
                                {
                                        if ((device.e入力デバイス種別 == E入力デバイス種別.Joystick) && !ConfigIni.dicJoystick.Value.ContainsValue(device.GUID))
@@ -461,6 +637,7 @@ namespace DTXMania
                        base.Window.Icon = Properties.Resources.dtx;
                        base.Window.KeyDown += new KeyEventHandler(this.Window_KeyDown);
                        base.Window.MouseUp += new MouseEventHandler(this.Window_MouseUp);
+                       base.Window.MouseDown += new MouseEventHandler(this.Window_MouseDown);
                        // #23510 2010.11.13 yyagi: to go fullscreen mode
                        base.Window.MouseDoubleClick += new MouseEventHandler(this.Window_MouseDoubleClick);
                        // #23510 2010.11.20 yyagi: to set resized window size in Config.ini
@@ -485,9 +662,9 @@ namespace DTXMania
                        settings.BackBufferHeight = SampleFramework.GameWindowSize.Height;
                        settings.EnableVSync = ConfigIni.bVSyncWait;
                        //settings.MultisampleType = MultisampleType.FourSamples;
-                       settings.MultisampleQuality = 3;
-                       settings.MultisampleType = MultisampleType.NonMaskable;
                        //settings.MultisampleQuality = 3;
+                       //settings.MultisampleType = MultisampleType.NonMaskable;
+                       //settings.Multithreaded = true;
 
 
                        try
@@ -522,6 +699,11 @@ namespace DTXMania
                        actFlushGPU = new CActFlushGPU();
                        #endregion
 
+                       if (DTX2WAVmode.Enabled)
+                       {
+                               this.Window.WindowState = FormWindowState.Minimized;            //DTX2WAVモード時は自動的に最小化
+                       }
+
                        DTX = null;
 
                        #region [ Skin の初期化 ]
@@ -553,6 +735,7 @@ namespace DTXMania
                        {
                                Resources.csvCurrentPath = CDTXMania.Instance.ConfigIni.strSystemSkinSubfolderPath.Value;
                                Trace.TraceInformation("Skin Path:" + Resources.csvCurrentPath);
+
                                bool ret = Resources.LoadResources(instance.ConfigIni.strLanguage);
                                if (ret)
                                {
@@ -684,8 +867,33 @@ namespace DTXMania
                                FDK.CSound管理.bIsTimeStretch = CDTXMania.Instance.ConfigIni.bTimeStretch;
                                Sound管理.nMasterVolume = CDTXMania.Instance.ConfigIni.nMasterVolume;
                                //FDK.CSound管理.bIsMP3DecodeByWindowsCodec = CDTXMania.Instance.ConfigIni.bNoMP3Streaming;
+
+
+                               string strDefaultSoundDeviceBusType = CSound管理.strDefaultDeviceBusType;
+                               Trace.TraceInformation($"Bus type of the default sound device = {strDefaultSoundDeviceBusType}");
+
+                               if (strDefaultSoundDeviceBusType.ToUpper().Equals("USB"))
+                               {
+                                       if (CDTXMania.Instance.ConfigIni.bWarnSoundDeviceOnUSB.Value)
+                                       {
+                                               string strWarnMes = CDTXMania.Instance.Resources.Explanation("strWarnSoundDeviceOnUSB");
+                                               var ret = MessageBox.Show(strWarnMes, "DTXMania Warning", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2);
+                                               if (ret == DialogResult.OK)
+                                               {
+                                                       CDTXMania.Instance.ConfigIni.bWarnSoundDeviceOnUSB.Value = false;
+                                               }
+                                       }
+                               }
+
                                Trace.TraceInformation("サウンドデバイスの初期化を完了しました。");
                        }
+                       catch (NullReferenceException)  // No audio output found
+                       {
+                               Trace.TraceError("Error: No sound output devices are ready.");
+                               string strWarnMes = CDTXMania.Instance.Resources.Explanation("strErrorNoActiveSoundDevice");
+                               MessageBox.Show(strWarnMes, "DTXMania Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
+                               Environment.Exit(-1);
+                       }
                        catch (Exception e)
                        {
                                Trace.TraceError(e.Message);
@@ -818,9 +1026,11 @@ namespace DTXMania
                                r現在のステージ = stage起動;
                        }
                        r現在のステージ.On活性化();
+                       this.Window.Activate();     // #41300 workaround to avoid SharpDX exception
                        #endregion
                }
 
+
                public void t全画面_ウィンドウモード切り替え()
                {
 #if WindowedFullscreen
@@ -848,7 +1058,7 @@ namespace DTXMania
 #if WindowedFullscreen
                                        // #30666 2013.2.2 yyagi Don't use Fullscreen mode becasue NVIDIA GeForce is
                                        // tend to delay drawing on Fullscreen mode. So DTXMania uses Maximized window
-                                       // in spite of using fullscreen mode.
+                                       // instead of using fullscreen mode.
                                        Instance.Window.WindowState = FormWindowState.Normal;
                                        Instance.Window.FormBorderStyle = FormBorderStyle.Sizable;
                                        Instance.Window.WindowState = FormWindowState.Normal;
@@ -931,16 +1141,6 @@ namespace DTXMania
                                st.plugin.OnManagedリソースの作成();
                                Directory.SetCurrentDirectory(CDTXMania.Instance.strEXEのあるフォルダ);
                        }
-
-                       #region [ 現在の電源プランをバックアップし、HighPerformanceに変更 ]
-                       CPowerPlan.BackupCurrentPowerPlan();
-                       if ( CDTXMania.Instance.ConfigIni.bForceHighPowerPlan )
-                       {
-                               CPowerPlan.ChangeHighPerformance();
-                       }
-                       #endregion
-
-
 #if GPUFlushAfterPresent
                        FrameEnd += dtxmania_FrameEnd;
 #endif
@@ -968,8 +1168,8 @@ namespace DTXMania
                        this.Device.SetTransform(TransformState.View, Matrix.LookAtLH(new Vector3(0f, 0f, (float)(-SampleFramework.GameWindowSize.Height / 2 * Math.Sqrt(3.0))), new Vector3(0f, 0f, 0f), new Vector3(0f, 1f, 0f)));
                        this.Device.SetTransform(TransformState.Projection, Matrix.PerspectiveFovLH(C変換.DegreeToRadian((float)60f), ((float)this.Device.Viewport.Width) / ((float)this.Device.Viewport.Height), -100f, 100f));
                        this.Device.SetRenderState(RenderState.Lighting, false);
-                       this.Device.SetRenderState(RenderState.ZEnable, true);
-                       this.Device.SetRenderState(RenderState.AntialiasedLineEnable, true);
+                       this.Device.SetRenderState(RenderState.ZEnable, false);                                         // trueにすると、一部システムで画面表示できなくなる
+                       this.Device.SetRenderState(RenderState.AntialiasedLineEnable, false);       // trueにすると、一部システムで画面表示できなくなる 
                        this.Device.SetRenderState(RenderState.AlphaTestEnable, true);
                        this.Device.SetRenderState(RenderState.AlphaRef, 10);
 
@@ -1015,7 +1215,6 @@ namespace DTXMania
                }
                protected override void OnExiting(EventArgs e)
                {
-                       CPowerPlan.RestoreCurrentPowerPlan();           // 電源プランを元のものに戻す
                        CPowerManagement.tEnableMonitorSuspend();       // スリープ抑止状態を解除
                        this.t終了処理();
                        base.OnExiting(e);
@@ -1025,7 +1224,11 @@ namespace DTXMania
                }
                protected override void Draw(GameTime gameTime)
                {
-                       Sound管理.t再生中の処理をする();
+                       if (Sound管理 == null)
+                       {
+                               return;
+                       }
+                       //Sound管理.t再生中の処理をする();
 
                        if (Timer != null)
                                Timer.t更新();
@@ -1055,15 +1258,14 @@ namespace DTXMania
                        }
                        #endregion
 
-                       #region [ DTXCreatorからの指示 ]
+                       #region [ DTXCreator/DTX2WAVからの指示 ]
                        if (this.Window.IsReceivedMessage)  // ウインドウメッセージで、
                        {
                                string strMes = this.Window.strMessage;
                                this.Window.IsReceivedMessage = false;
-
                                if (strMes != null)
                                {
-                                       DTXVmode.ParseArguments(strMes);
+                                       CommandParse.ParseArguments(strMes, ref DTXVmode, ref DTX2WAVmode);
 
                                        if (DTXVmode.Enabled)
                                        {
@@ -1099,6 +1301,27 @@ namespace DTXMania
                                                        }
                                                }
                                        }
+                                       if (DTX2WAVmode.Enabled)
+                                       {
+                                               if (DTX2WAVmode.Command == CDTX2WAVmode.ECommand.Cancel)
+                                               {
+                                                       Trace.TraceInformation("録音のCancelコマンドをDTXMania本体が受信しました。");
+                                                       //Microsoft.VisualBasic.Interaction.AppActivate("メモ帳");
+                                                       //SendKeys.Send("{ESC}");
+                                                       //SendKeys.SendWait("%{F4}");
+                                                       //Application.Exit();
+                                                       if (DTX != null)        // 曲読み込みの前に録音Cancelされると、DTXがnullのままここにきてでGPFとなる→nullチェック追加
+                                                       {
+                                                               DTX.t全チップの再生停止();
+                                                               DTX.On非活性化();
+                                                       }
+                                                       r現在のステージ.On非活性化();
+
+                                                       //Environment.ExitCode = 10010;         // この組み合わせではダメ、返り値が反映されない
+                                                       //base.Window.Close();
+                                                       Environment.Exit(10010);                        // このやり方ならばOK
+                                               }
+                                       }
                                }
                        }
                        #endregion
@@ -1126,10 +1349,29 @@ namespace DTXMania
                                //---------------------
                                #endregion
 
+                               #region [ DTX2WAVモード時、ステージが変わるたびに、そのことをDTX2WAVアプリ側に通知する ]
+                               if (DTX2WAVmode.Enabled && r現在のステージ != r1フレーム前のステージ)
+                               {
+                                       r1フレーム前のステージ = r現在のステージ;
+                                       //Trace.TraceInformation("Stage変更 to : " + r現在のステージ.eステージID.ToString());
+                                       switch (r現在のステージ.eステージID)
+                                       {
+                                               case CStage.Eステージ.曲読み込み:
+                                                       DTX2WAVmode.SendMessage2DTX2WAV("LOAD");
+                                                       break;
+                                               case CStage.Eステージ.演奏:
+                                                       DTX2WAVmode.SendMessage2DTX2WAV("PLAY");
+                                                       break;
+                                               default:
+                                                       break;
+                                       }
+                               }
+                               #endregion
 
                                CScoreIni scoreIni = null;
 
-                               if (Control.IsKeyLocked(Keys.CapsLock))             // #30925 2013.3.11 yyagi; capslock=ON時は、EnumSongsしないようにして、起動負荷とASIOの音切れの関係を確認する
+                               //if (Control.IsKeyLocked(Keys.CapsLock))             // #30925 2013.3.11 yyagi; capslock=ON時は、EnumSongsしないようにして、起動負荷とASIOの音切れの関係を確認する
+                               if (!CDTXMania.instance.ConfigIni.bEnumerateSongsInBoot)        // #40772 2020.10.12 yyagi
                                {
                                        // → songs.db等の書き込み時だと音切れするっぽい
                                        actEnumSongs.On非活性化();
@@ -1149,7 +1391,7 @@ namespace DTXMania
                                        case CStage.Eステージ.曲読み込み:
                                                if (EnumSongs != null)
                                                {
-                                                       #region [ (特定条件時) 曲検索スレッドの起動・開始 ]
+                            #region [ (特定条件時) 曲検索スレッドの起動・開始 ]
                                                        if (r現在のステージ.eステージID == CStage.Eステージ.タイトル &&
                                                                         r直前のステージ.eステージID == CStage.Eステージ.起動 &&
                                                                         this.n進行描画の戻り値 == (int)CStageタイトル.E戻り値.継続 &&
@@ -1262,9 +1504,9 @@ namespace DTXMania
                                                break;
 
                                        case CStage.Eステージ.タイトル:
-                                               #region [ *** ]
-                                               //-----------------------------
-                                               switch (this.n進行描画の戻り値)
+                        #region [ *** ]
+                        //-----------------------------
+                        switch (this.n進行描画の戻り値)
                                                {
                                                        case (int)CStageタイトル.E戻り値.GAMESTART:
                                                                #region [ 選曲処理へ ]
@@ -1689,6 +1931,10 @@ namespace DTXMania
                                                                DTX.t全チップの再生停止();
                                                                DTX.On非活性化();
                                                                r現在のステージ.On非活性化();
+                                                               if (DTX2WAVmode.Enabled)
+                                                               {
+                                                                       Environment.Exit(0);
+                                                               }
                                                                if (bコンパクトモード)
                                                                {
                                                                        base.Window.Close();
@@ -1941,7 +2187,7 @@ namespace DTXMania
                        }
 
                        #region [ マウスカーソル消去制御 ]
-                       cMouseHideControl.tHideCursorIfNeed();
+                       if (cMouseHideControl != null) cMouseHideControl.tHideCursorIfNeed();
                        #endregion
                        #region [ 全画面・ウインドウ切り替え ]
                        if (this.b次のタイミングで全画面_ウィンドウ切り替えを行う)
@@ -1968,7 +2214,7 @@ namespace DTXMania
                        }
                        #endregion
 
-                       //GC.Collect( 0, GCCollectionMode.Optimized, false );           // Rel105で処理が重くなっていることに対する、暫定処置。
+                       GC.Collect( 0, GCCollectionMode.Optimized, false );             // Rel105で処理が重くなっていることに対する、暫定処置。
                                                                                                                                        // 重くなっている原因に対する適切な処置をして、処理が104程度に軽くなったら、
                                                                                                                                        // この暫定処置は削除します。
                }
@@ -1985,7 +2231,8 @@ namespace DTXMania
                        {
                                if (File.Exists(xmlpath))
                                {
-                                       using (XmlReader xr = XmlReader.Create(xmlpath))
+                                       using (StreamReader reader = new StreamReader(xmlpath, Encoding.GetEncoding("shift_jis")))
+                                       using (XmlReader xr = XmlReader.Create(reader))
                                        {
                                                DataContractSerializer serializer = new DataContractSerializer(t);
                                                ret = serializer.ReadObject(xr);
@@ -2012,11 +2259,14 @@ namespace DTXMania
                        settings.Indent = true;
                        settings.NewLineChars = Environment.NewLine;
                        settings.Encoding = new System.Text.UTF8Encoding(false);
-                       using ( XmlWriter xw = XmlWriter.Create( new FileStreamSSD( xmlpath ), settings ) )
-                       {
-                               DataContractSerializer serializer = new DataContractSerializer(obj.GetType());
-                               serializer.WriteObject(xw, obj);
-                       }
+            using (FileStreamSSD fsssd = new FileStreamSSD(xmlpath))
+            {
+                using (XmlWriter xw = XmlWriter.Create(fsssd, settings))
+                {
+                    DataContractSerializer serializer = new DataContractSerializer(obj.GetType());
+                    serializer.WriteObject(xw, obj);
+                }
+            }
                }
 
                public void SaveConfig()
@@ -2076,6 +2326,8 @@ namespace DTXMania
                                                Path.Combine( Path.Combine( this.strEXEのあるフォルダ, "System" ), ConfigIni.strSystemSkinSubfolderPath );
                                }
                        }
+
+                       ConfigIni.UpgradeConfig();      // 本体version upに伴ってConfig.xmlの定義が更新される場合の、最低限のフォローアップ
                }
                /// <summary>
                /// 座標値を読み込む。Coordinates メンバ初期化後いつ呼び出しても構わない。
@@ -2200,7 +2452,11 @@ namespace DTXMania
                        {
                                delay = "(" + Sound管理.GetSoundDelay() + "ms)";
                        }
-                       base.Window.Text = strWindowTitle + " (" + Sound管理.GetCurrentSoundDeviceType() + delay + ")";
+                       base.Window.Text = strWindowTitle;
+                       if (!this.DTX2WAVmode.Enabled)
+                       {
+                               base.Window.Text += " (" + Sound管理.GetCurrentSoundDeviceType() + delay + ")";
+                       }
                }
 
                #region [ private ]
@@ -2214,13 +2470,19 @@ namespace DTXMania
                {
                        get
                        {
-                               if (DTXVmode.Enabled)
+                               string strCPUmode = (Environment.Is64BitProcess) ? " [x64]" : " [x86]";
+
+                                       if (DTXVmode.Enabled)
+                               {
+                                       return "DTXMViewer release " + VERSION + strCPUmode;
+                               }
+                               else if (DTX2WAVmode.Enabled)
                                {
-                                       return "DTXMViewer release " + VERSION;
+                                       return "DTX2WAV (" + VERSION + "): " + Path.GetFileName(this.DTX2WAVmode.dtxfilename) + strCPUmode;
                                }
                                else
                                {
-                                       return "DTXMania .NET style release " + VERSION;
+                                       return "DTXMania .NET style release " + VERSION + strCPUmode;
                                }
                        }
                }
@@ -2233,6 +2495,9 @@ namespace DTXMania
                        {
                                Trace.TraceInformation("----------------------");
                                Trace.TraceInformation("■ アプリケーションの終了");
+                               #region[ 電源プランの復元 ]
+                               CPowerPlan.RestoreCurrentPowerPlan();           // 電源プランを元のものに戻す
+                               #endregion
                                #region [ 曲検索の終了処理 ]
                                //---------------------
                                if (actEnumSongs != null)
@@ -2513,6 +2778,12 @@ namespace DTXMania
                                                DTXVmode.tUpdateConfigIni();
                                                Trace.TraceInformation("DTXVモードの設定情報を、Config.xmlに保存しました。");
                                        }
+                                       else if (DTX2WAVmode.Enabled)
+                                       {
+                                               DTX2WAVmode.tUpdateConfigIni();
+                                               Trace.TraceInformation("DTX2WAVモードの設定情報を、Config.xmlに保存しました。");
+                                               DTX2WAVmode.SendMessage2DTX2WAV("TERM");
+                                       }
                                        else
                                        {
                                                CDTXMania.Instance.SaveConfig();
@@ -2628,10 +2899,16 @@ namespace DTXMania
                }
                private void tガベージコレクションを実行する()
                {
+                       // LOHに対するコンパクションを要求
+                       GCSettings.LargeObjectHeapCompactionMode = GCLargeObjectHeapCompactionMode.CompactOnce;
+
                        GC.Collect(0, GCCollectionMode.Optimized, true );
                        GC.WaitForPendingFinalizers();
                        GC.Collect(0, GCCollectionMode.Forced, true );
                        GC.WaitForPendingFinalizers();
+
+                       // 通常通り、LOHへのGCを抑制
+                       GCSettings.LargeObjectHeapCompactionMode = GCLargeObjectHeapCompactionMode.Default;
                }
                private void tプラグイン検索と生成()
                {
@@ -2751,7 +3028,7 @@ namespace DTXMania
                private void Window_ApplicationDeactivated(object sender, EventArgs e)
                {
                        this.bApplicationActive = false;
-                       cMouseHideControl.Show();
+                       if (cMouseHideControl != null) cMouseHideControl.Show();
                }
                private void Window_KeyDown(object sender, KeyEventArgs e)
                {
@@ -2792,20 +3069,37 @@ namespace DTXMania
                {
                        mb = e.Button;
                }
+               private void Window_MouseDown(object sender, MouseEventArgs e)
+               {
+                       currentMousePosition.X = Control.MousePosition.X;
+                       currentMousePosition.Y = Control.MousePosition.Y;
+               }
 
                private void Window_MouseDoubleClick(object sender, MouseEventArgs e)   // #23510 2010.11.13 yyagi: to go full screen mode
                {
                        if (mb.Equals(MouseButtons.Left) && ConfigIni.bIsAllowedDoubleClickFullscreen)  // #26752 2011.11.27 yyagi
                        {
-                               ConfigIni.bウィンドウモード = false;
+                               ConfigIni.bウィンドウモード = !ConfigIni.bウィンドウモード;
                                this.t全画面_ウィンドウモード切り替え();
                        }
                }
+               private Point currentMousePosition = new Point(-1,-1);
                private void Window_MouseMove(object sender, MouseEventArgs e)
                {
-                       cMouseHideControl.tResetCursorState(ConfigIni.bウィンドウモード, this.bApplicationActive);
-               }
+                       if (cMouseHideControl != null) cMouseHideControl.tResetCursorState(ConfigIni.bウィンドウモード, this.bApplicationActive);
+                       if (Control.MouseButtons.HasFlag(MouseButtons.Left))
+                       {
+                               int X = base.Window.Location.X;
+                               X += (Control.MousePosition.X - currentMousePosition.X);
+                               int Y = base.Window.Location.Y;
+                               Y += (Control.MousePosition.Y - currentMousePosition.Y);
 
+                               base.Window.Location = new Point(X, Y);
+
+                               currentMousePosition.X = Control.MousePosition.X;
+                               currentMousePosition.Y = Control.MousePosition.Y;
+                       }
+               }
                private void Window_ResizeEnd(object sender, EventArgs e)               // #23510 2010.11.20 yyagi: to get resized window size
                {
                        if (ConfigIni.bウィンドウモード)