2 using System.Collections.Generic;
3 using System.ComponentModel;
8 using System.Threading.Tasks;
9 using System.Windows.Forms;
11 using System.Diagnostics;
12 using System.Runtime.InteropServices;
16 public partial class Main : Form
18 Form_Recording formRecording;
19 Process p_DTXMania = null;
20 bool bOpenedEncodingSettingTab = false;
24 InitializeComponent();
25 bindingSource_BGM.DataSource = new VolumeSlider();
26 bindingSource_SE.DataSource = new VolumeSlider();
27 bindingSource_Drums.DataSource = new VolumeSlider();
28 bindingSource_Guitar.DataSource = new VolumeSlider();
29 bindingSource_Bass.DataSource = new VolumeSlider();
30 bindingSource_Master.DataSource = new VolumeSlider();
31 bindingSource_Ogg_Q.DataSource = new VolumeSlider();
36 /// タイトルバーに、アプリ名とリリース番号を表示する
39 /// <param name="sender"></param>
40 /// <param name="e"></param>
41 private void Main_Shown(object sender, EventArgs e)
44 System.Reflection.Assembly asm = System.Reflection.Assembly.GetExecutingAssembly();
45 int ver_asm_major = asm.GetName().Version.Major;
46 this.Text = "DTX2WAV Rel" + ver_asm_major.ToString("D3");
50 // アプリのverup時は旧バージョンの設定を引き継ぐ。
51 // さもなくば、前回終了時の設定値を引き継ぐ。
52 if (Properties.Settings.Default.IsUpgrade == false)
55 Properties.Settings.Default.Upgrade();
57 // 「Upgradeを実行した」という情報を設定する
58 Properties.Settings.Default.IsUpgrade = true;
61 Properties.Settings.Default.Save();
66 Properties.Settings.Default.Reload();
70 #region [ 復元した設定値を、Formに反映する ]
71 numericUpDown_BGM.Value = Properties.Settings.Default.nVol_BGM;
72 numericUpDown_SE.Value = Properties.Settings.Default.nVol_SE;
73 numericUpDown_Drums.Value = Properties.Settings.Default.nVol_Drums;
74 numericUpDown_Guitar.Value = Properties.Settings.Default.nVol_Guitar;
75 numericUpDown_Bass.Value = Properties.Settings.Default.nVol_Bass;
76 numericUpDown_Master.Value = Properties.Settings.Default.nVol_Master;
77 checkBox_MonitorSound.Checked = Properties.Settings.Default.bMonitorSound;
78 comboBox_AudioFormat.SelectedIndex = Properties.Settings.Default.nAudioFormat;
79 checkBox_overwriteCheck.Checked = Properties.Settings.Default.bOverwriteCheck;
81 numericUpDown_Ogg_Q.Value = Properties.Settings.Default.nOgg_Q; // この設定は後でもう一度実施する。tabControl1_SelectedIndexChanged()へ。
82 comboBox_MP3_bps.SelectedIndex = Properties.Settings.Default.nMP3_bps;
86 private void button_browseDTX_Click(object sender, EventArgs e)
88 OpenFileDialog ofd = new OpenFileDialog();
90 ofd.Filter = Properties.Resources.ofdFilter;
92 ofd.Title = Properties.Resources.ofdTitle;
94 ofd.RestoreDirectory = false;
96 ofd.CheckFileExists = true;
97 ofd.CheckPathExists = true;
99 if (ofd.ShowDialog() == DialogResult.OK)
101 textBox_BrowseDTX.Text = ofd.FileName;
102 UpdateOutPath(ofd.FileName);
106 private void UpdateOutPath(string infile)
108 string outpath = Path.Combine(
109 Path.GetDirectoryName(infile),
110 Path.GetFileNameWithoutExtension(infile) + "." + comboBox_AudioFormat.Text.ToLower()
112 textBox_BrowseAudio.Text = outpath;
115 private void button_browseWAV_Click(object sender, EventArgs e)
117 SaveFileDialog sfd = new SaveFileDialog();
120 switch (comboBox_AudioFormat.Text)
123 filter = Properties.Resources.sfdFilterWAV;
126 filter = Properties.Resources.sfdFilterOGG;
129 filter = Properties.Resources.sfdFilterMP3;
132 filter = Properties.Resources.sfdFilterALL;
137 sfd.DefaultExt = "." + comboBox_AudioFormat.Text.ToLower();
138 sfd.Title = Properties.Resources.sfdTitle;
140 sfd.RestoreDirectory = false;
141 sfd.AddExtension = true;
143 sfd.OverwritePrompt = true;
144 sfd.CheckFileExists = false;
145 sfd.CheckPathExists = false;
147 if (sfd.ShowDialog() == DialogResult.OK)
149 textBox_BrowseAudio.Text = sfd.FileName;
155 /// 変換を実行。DTXManiaGRをDTX2WAVモードで呼び出す。
157 /// <param name="sender"></param>
158 /// <param name="e"></param>
159 private void button_Convert_Click(object sender, EventArgs e)
161 #region [ in/outファイル名など、必要な設定がなされているかをチェック ]
162 if (!File.Exists(textBox_BrowseDTX.Text))
164 MessageBox.Show(Properties.Resources.errNoDTXFileText, Properties.Resources.errNoDTXFileCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
167 if (textBox_BrowseAudio.Text == "")
169 MessageBox.Show(Properties.Resources.errNoOutFileText, Properties.Resources.errNoOutFileCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
173 string inext = Path.GetExtension(textBox_BrowseAudio.Text).ToLower();
174 if (inext == ".dtx" || inext == ".gda" || inext == ".g2d")
176 MessageBox.Show(Properties.Resources.errIllegalExtentionText, Properties.Resources.errIllegalExtentionCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
179 if (checkBox_overwriteCheck.Checked)
181 if (File.Exists(textBox_BrowseAudio.Text))
183 DialogResult result = MessageBox.Show(Properties.Resources.confirmOverwriteText, Properties.Resources.confirmOverwriteCaption, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
184 if (result == DialogResult.Cancel || result == DialogResult.No)
192 #region [ 録音用にDTXManiaプロセスを起動する ]
193 p_DTXMania = new System.Diagnostics.Process();
195 //イベントハンドラがフォームを作成したスレッドで実行されるようにする
196 p_DTXMania.SynchronizingObject = this;
198 p_DTXMania.Exited += new EventHandler(p_Exited);
199 p_DTXMania.EnableRaisingEvents = true;
202 p_DTXMania.StartInfo.FileName = "DTXManiaGR.exe";
203 p_DTXMania.StartInfo.Arguments = $"-E{comboBox_AudioFormat.Text.ToUpper()},";
204 p_DTXMania.StartInfo.WindowStyle = ProcessWindowStyle.Minimized;
206 switch (comboBox_AudioFormat.Text.ToUpper())
209 p_DTXMania.StartInfo.Arguments += "48000,192,"; // freqとbitrate、DTXMania側ではいずれも無視される
212 p_DTXMania.StartInfo.Arguments += $"48000,{numericUpDown_Ogg_Q.Value},";
215 p_DTXMania.StartInfo.Arguments += $"48000,{comboBox_MP3_bps.Text},";
218 p_DTXMania.StartInfo.Arguments += "48000,192,";
222 p_DTXMania.StartInfo.Arguments += $"{numericUpDown_BGM.Value},{numericUpDown_SE.Value},{numericUpDown_Drums.Value},{numericUpDown_Guitar.Value},{numericUpDown_Bass.Value},{numericUpDown_Master.Value},";
223 p_DTXMania.StartInfo.Arguments += $"\"{textBox_BrowseAudio.Text}\",\"{textBox_BrowseDTX.Text}\"";
232 MessageBox.Show(Properties.Resources.errFailedLaunchingDTXManiaText, Properties.Resources.errFailedLaunchingDTXManiaCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
234 p_DTXMania.Dispose();
240 //モーダルで変換中ダイアログを表示して、処理をいったん止める(キャンセル or 正常終了イベント待ち)
241 formRecording = new Form_Recording();
242 //formRecording.StartPosition = FormStartPosition.CenterParent;
243 formRecording.ShowDialog(this);
246 if (formRecording != null)
248 //フォームでCancelボタンが押されると、ここに来る
249 //変換終了時のイベントで正常終了する場合は、p_Exited()で終了して、fがnullになって、ここはスキップされる
250 formRecording.Dispose();
251 formRecording = null;
255 private void p_Exited(object sender, EventArgs e)
257 if (formRecording != null)
259 formRecording.Dispose();
260 formRecording = null;
263 // DTXManiaプロセスの返り値を確認し、それに応じたダイアログを表示する
264 if (p_DTXMania != null)
266 //MessageBox.Show(p_DTXMania.ExitCode.ToString());
268 switch (p_DTXMania.ExitCode)
271 using (var f = new Form_Finished_OK())
277 case 10010: // Cancel
278 using (var f = new Form_Finished_Fail())
284 default: // DTXMania本体を強制終了した、など
290 p_DTXMania.Dispose();
297 /// <param name="sender"></param>
298 /// <param name="e"></param>
299 private void button_Cancel_Click(object sender, EventArgs e)
306 /// 出力フォーマットを変更した場合は、出力パスの拡張子も更新する
308 /// <param name="sender"></param>
309 /// <param name="e"></param>
310 private void comboBox_AudioFormat_SelectedIndexChanged(object sender, EventArgs e)
312 string outpath = textBox_BrowseAudio.Text;
318 textBox_BrowseAudio.Text =
320 Path.GetDirectoryName(outpath),
321 Path.GetFileNameWithoutExtension(outpath) + "." + comboBox_AudioFormat.Text.ToLower()
329 /// NumericUpDown とTrackBar にバインドされるデータ
331 public class VolumeSlider : INotifyPropertyChanged
334 /// INotifyPropertyChanged から継承したイベントデリゲート
336 public event PropertyChangedEventHandler PropertyChanged;
340 /// <param name="info"></param>
341 private void NotifyPropertyChanged(String info)
343 if (PropertyChanged != null)
345 PropertyChanged(this, new PropertyChangedEventArgs(info));
351 get { return _value; }
357 // このプロパティ名を渡してイベント通知
358 NotifyPropertyChanged("Value");
368 /// <param name="sender"></param>
369 /// <param name="e"></param>
370 private void Main_FormClosing(object sender, FormClosingEventArgs e)
373 #region [ Formの設定値を、Propertiesに退避する ]
374 Properties.Settings.Default.nVol_BGM = (int)numericUpDown_BGM.Value;
375 Properties.Settings.Default.nVol_SE = (int)numericUpDown_SE.Value;
376 Properties.Settings.Default.nVol_Drums = (int)numericUpDown_Drums.Value;
377 Properties.Settings.Default.nVol_Guitar = (int)numericUpDown_Guitar.Value;
378 Properties.Settings.Default.nVol_Bass = (int)numericUpDown_Bass.Value;
379 Properties.Settings.Default.nVol_Master = (int)numericUpDown_Master.Value;
380 Properties.Settings.Default.bMonitorSound = checkBox_MonitorSound.Checked;
381 Properties.Settings.Default.nAudioFormat = comboBox_AudioFormat.SelectedIndex;
382 Properties.Settings.Default.nOgg_Q = (int)numericUpDown_Ogg_Q.Value;
383 Properties.Settings.Default.nMP3_bps = comboBox_MP3_bps.SelectedIndex;
384 Properties.Settings.Default.bOverwriteCheck = checkBox_overwriteCheck.Checked;
387 Properties.Settings.Default.Save();
391 #region #28821 2014.1.23 yyagi add: 外部からの文字列メッセージ送受信 定数定義
392 [StructLayout(LayoutKind.Sequential)]
393 public struct COPYDATASTRUCT
395 public IntPtr dwData;
396 public UInt32 cbData;
397 public IntPtr lpData;
403 /// <param name="m"></param>
404 protected override void WndProc(ref Message m)
406 if (m.Msg == 0x004A) //WM_COPYDATA
408 COPYDATASTRUCT cds = (COPYDATASTRUCT)Marshal.PtrToStructure(m.LParam, typeof(COPYDATASTRUCT));
409 string strMessage = Marshal.PtrToStringUni(cds.lpData);
410 formRecording.label_state.Text = strMessage; // Form_Recordingにメッセージの内容を伝える
417 private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
419 // Encoding Settingsタブにある、numericUpDownかTrackbarの値は、
420 // Form_Shown()で初期化した値が、
421 // タブの初回オープン時にゼロクリアされてしまう模様。
422 // そのため、この値だけは、タブの初回オープン時に初期化する。
423 if (tabControl1.SelectedIndex == 1 && bOpenedEncodingSettingTab == false)
425 bOpenedEncodingSettingTab = true;
426 numericUpDown_Ogg_Q.Value = Properties.Settings.Default.nOgg_Q;
431 /// 入力DTX欄にファイルをドラッグしたときの動作 (マウスカーソルを変更する)
433 /// <param name="sender"></param>
434 /// <param name="e"></param>
435 private void textBox_BrowseDTX_DragEnter(object sender, DragEventArgs e)
437 //コントロール内にドラッグされたとき実行される
438 if (e.Data.GetDataPresent(DataFormats.FileDrop))
440 //ドラッグされたデータ形式を調べ、ファイル1個のときはコピーとする
441 string[] fileName = (string[])e.Data.GetData(DataFormats.FileDrop, false);
442 if (fileName.Length == 1 &&
443 (Path.GetExtension(fileName[0]).ToLower() == ".dtx" ||
444 Path.GetExtension(fileName[0]).ToLower() == ".gda" ||
445 Path.GetExtension(fileName[0]).ToLower() == ".g2d"
448 e.Effect = DragDropEffects.Copy;
452 e.Effect = DragDropEffects.None; //ファイルが複数ある場合は受け付けない
457 e.Effect = DragDropEffects.None; //ファイル以外は受け付けない
461 private void textBox_BrowseDTX_DragDrop(object sender, DragEventArgs e)
463 //コントロール内にドロップされたとき実行される
464 //ドロップされたファイル名(1個)を取得する
465 string[] fileName = (string[])e.Data.GetData(DataFormats.FileDrop, false);
466 textBox_BrowseDTX.Text = fileName[0];
468 UpdateOutPath(fileName[0]);