2 using System.Collections.Generic;
4 using System.Windows.Forms;
6 using System.Threading;
7 using System.Diagnostics;
8 using DTXCreator.UndoRedo;
12 namespace DTXCreator.WAV_BMP_AVI
14 internal class CWAVリスト管理
16 public int n現在選択中のItem番号0to1294 = -1;
18 internal delegate void DGサウンドを再生する( int nWAV番号1to1295 );
19 internal delegate void DGサウンドファイルを再生する( string filename);
21 public CWAVリスト管理( Cメインフォーム pメインフォーム, ListView pListViewWAVリスト )
23 this._Form = pメインフォーム;
24 this.listViewWAVリスト = pListViewWAVリスト;
27 private void tDirectSoundの初期化()
29 this.sound管理 = new CSound管理( this._Form.Handle );
30 // this.sound管理 = new CSound管理( this._Form.Handle, this._Form.appアプリ設定.ViewerInfo.SoundType, 0, 0, this._Form.appアプリ設定.ViewerInfo.ASIODeviceNo );
32 this.soundPreview = null;
34 #region [ #26122 2011.8.31 yyagi; ストリーム再生のために、t再生中の処理をする()を定期的に呼び出す処理を追加 ]
35 timerDelegate = new TimerCallback( this.sound管理.t再生中の処理をする );
36 timer = new System.Threading.Timer( timerDelegate, null, 0, 300 );
40 public ListViewItem tCWAVとListViewItemを生成して返す( int n行番号1to1295 )
42 return this.tWAVをキャッシュから検索して返す_なければ新規生成する( n行番号1to1295 ).t現在の内容から新しいListViewItemを作成して返す();
44 public void tDirectSoundの解放()
46 if( this.soundPreview != null )
48 this.soundPreview.Dispose();
52 timer.Change( Timeout.Infinite, Timeout.Infinite );
56 if ( timerDelegate != null )
60 if( this.sound管理 != null )
62 this.sound管理.Dispose();
65 public void tItemを交換する( int nItem番号1, int nItem番号2 )
67 if( !CUndoRedo管理.bUndoRedoした直後 )
69 this._Form.mgrUndoRedo管理者.tノードを追加する( new CUndoRedoセル<int>( null, new DGUndoを実行する<int>( this.t行交換のUndo ), new DGRedoを実行する<int>( this.t行交換のRedo ), nItem番号1, nItem番号2 ) );
70 this._Form.tUndoRedo用GUIの有効無効を設定する();
72 CUndoRedo管理.bUndoRedoした直後 = false;
73 this.tItemを交換する_ListViewItem( nItem番号1, nItem番号2 );
74 this.tItemを交換する_WAVキャッシュ( nItem番号1, nItem番号2 );
75 this.tItemを交換する_チップパレット( nItem番号1, nItem番号2 );
76 this.tItemを交換する_譜面上のチップ( nItem番号1, nItem番号2 );
77 this.tItemを交換する_レーン割付チップ( nItem番号1, nItem番号2 );
78 this.tItemを交換する_カーソル移動( nItem番号1, nItem番号2 );
79 this._Form.listViewWAVリスト.Refresh();
80 this._Form.pictureBox譜面パネル.Refresh();
81 this._Form.b未保存 = true;
83 public void tItemを選択する( int nItem番号0to1294 )
85 this.n現在選択中のItem番号0to1294 = nItem番号0to1294;
86 this.listViewWAVリスト.Items[ nItem番号0to1294 ].Selected = true;
87 this.listViewWAVリスト.Items[ nItem番号0to1294 ].Focused = true;
89 public void tWAVリストにフォーカスを当てる()
91 this.listViewWAVリスト.Focus();
93 public CWAV tWAVをキャッシュから検索して返す( int nWAV番号1to1295 )
95 return this.WAVキャッシュ.tWAVをキャッシュから検索して返す( nWAV番号1to1295 );
97 public CWAV tWAVをキャッシュから検索して返す_なければ新規生成する( int nWAV番号1to1295 )
99 return this.WAVキャッシュ.tWAVをキャッシュから検索して返す_なければ新規生成する( nWAV番号1to1295 );
101 public ListViewItem tWAV番号に対応するListViewItemを返す( int nWAV番号1to1295 )
103 if( ( nWAV番号1to1295 < 1 ) || ( nWAV番号1to1295 > 36 * 36 - 1 ) )
105 throw new Exception( "WAV番号が範囲外です。--->[" + nWAV番号1to1295 + "]" );
107 return this.listViewWAVリスト.Items[ nWAV番号1to1295 - 1 ];
109 public void tWAV編集のRedo( CWAV wc変更前, CWAV wc変更後 )
111 int num = wc変更後.nWAV番号1to1295;
112 CWAV cwav = this.WAVキャッシュ.tWAVをキャッシュから検索して返す( num );
113 cwav.tコピーfrom( wc変更後 );
114 cwav.tコピーto( this.listViewWAVリスト.Items[ num - 1 ] );
115 this._Form.tWAV_BMP_AVIリストのカーソルを全部同じ行に合わせる( cwav.nWAV番号1to1295 - 1 );
116 this._Form.tタブを選択する( Cメインフォーム.Eタブ種別.WAV );
117 this.listViewWAVリスト.Refresh();
119 public void tWAV編集のUndo( CWAV wc変更前, CWAV wc変更後 )
121 int num = wc変更前.nWAV番号1to1295;
122 CWAV cwav = this.WAVキャッシュ.tWAVをキャッシュから検索して返す( num );
123 cwav.tコピーfrom( wc変更前 );
124 cwav.tコピーto( this.listViewWAVリスト.Items[ num - 1 ] );
125 this._Form.tWAV_BMP_AVIリストのカーソルを全部同じ行に合わせる( cwav.nWAV番号1to1295 - 1 );
126 this._Form.tタブを選択する( Cメインフォーム.Eタブ種別.WAV );
127 this.listViewWAVリスト.Refresh();
129 public void tサウンドプロパティを開いて編集する( int nWAV番号1to1295, string str相対パスの基本フォルダ )
131 this._Form.dlgチップパレット.t一時的に隠蔽する();
132 CWAV cwav = this.tWAVをキャッシュから検索して返す_なければ新規生成する( nWAV番号1to1295 );
133 ListViewItem item = cwav.t現在の内容から新しいListViewItemを作成して返す();
134 string directoryName = "";
135 if( item.SubItems[ 2 ].Text.Length > 0 )
137 directoryName = Path.GetDirectoryName( this._Form.strファイルの存在するディレクトリを絶対パスで返す( item.SubItems[ 2 ].Text ) );
139 Cサウンドプロパティダイアログ cサウンドプロパティダイアログ = new Cサウンドプロパティダイアログ( str相対パスの基本フォルダ, directoryName, new DGサウンドファイルを再生する( this.tプレビュー音を再生する ) );
140 cサウンドプロパティダイアログ.wav = cwav;
141 cサウンドプロパティダイアログ.textBoxラベル.Text = item.SubItems[ 0 ].Text;
142 cサウンドプロパティダイアログ.textBoxWAV番号.Text = item.SubItems[ 1 ].Text;
143 cサウンドプロパティダイアログ.textBoxファイル.Text = item.SubItems[ 2 ].Text;
144 cサウンドプロパティダイアログ.button試聴.Enabled = (cサウンドプロパティダイアログ.textBoxファイル.Text.Length > 0);
145 cサウンドプロパティダイアログ.textBox音量.Text = item.SubItems[ 3 ].Text;
146 cサウンドプロパティダイアログ.textBox位置.Text = item.SubItems[ 4 ].Text;
147 cサウンドプロパティダイアログ.hScrollBar音量.Value = cサウンドプロパティダイアログ.wav.n音量0to100;
148 cサウンドプロパティダイアログ.hScrollBar位置.Value = cサウンドプロパティダイアログ.wav.n位置_100to100 + 100;
149 cサウンドプロパティダイアログ.checkBoxBGM.CheckState = cサウンドプロパティダイアログ.wav.bBGMとして使用 ? CheckState.Checked : CheckState.Unchecked;
150 cサウンドプロパティダイアログ.textBoxWAV番号.ForeColor = item.ForeColor;
151 cサウンドプロパティダイアログ.textBoxWAV番号.BackColor = item.BackColor;
152 if( cサウンドプロパティダイアログ.ShowDialog() == DialogResult.OK )
154 CWAV wav = cサウンドプロパティダイアログ.wav;
155 CWAV cwav3 = new CWAV();
156 cwav3.nWAV番号1to1295 = cサウンドプロパティダイアログ.wav.nWAV番号1to1295;
157 cwav3.strラベル名 = cサウンドプロパティダイアログ.textBoxラベル.Text;
158 cwav3.strファイル名 = cサウンドプロパティダイアログ.textBoxファイル.Text;
159 cwav3.n音量0to100 = cサウンドプロパティダイアログ.hScrollBar音量.Value;
160 cwav3.n位置_100to100 = cサウンドプロパティダイアログ.hScrollBar位置.Value - 100;
161 cwav3.bBGMとして使用 = cサウンドプロパティダイアログ.checkBoxBGM.Checked;
162 cwav3.col文字色 = cサウンドプロパティダイアログ.textBoxWAV番号.ForeColor;
163 cwav3.col背景色 = cサウンドプロパティダイアログ.textBoxWAV番号.BackColor;
164 if( !cwav3.b内容が同じwith( wav ) )
167 wav.tコピーfrom( cサウンドプロパティダイアログ.wav );
168 this._Form.mgrUndoRedo管理者.tノードを追加する( new CUndoRedoセル<CWAV>( null, new DGUndoを実行する<CWAV>( this.tWAV編集のUndo ), new DGRedoを実行する<CWAV>( this.tWAV編集のRedo ), wav, cwav3 ) );
169 this._Form.tUndoRedo用GUIの有効無効を設定する();
170 cサウンドプロパティダイアログ.wav.tコピーfrom( cwav3 );
171 if( this.tWAV番号に対応するListViewItemを返す( nWAV番号1to1295 ) != null )
173 ListViewItem item2 = cサウンドプロパティダイアログ.wav.t現在の内容から新しいListViewItemを作成して返す();
174 item = this.tWAV番号に対応するListViewItemを返す( nWAV番号1to1295 );
175 item.SubItems[ 0 ].Text = item2.SubItems[ 0 ].Text;
176 item.SubItems[ 1 ].Text = item2.SubItems[ 1 ].Text;
177 item.SubItems[ 2 ].Text = item2.SubItems[ 2 ].Text;
178 item.SubItems[ 3 ].Text = item2.SubItems[ 3 ].Text;
179 item.SubItems[ 4 ].Text = item2.SubItems[ 4 ].Text;
180 item.SubItems[ 5 ].Text = item2.SubItems[ 5 ].Text;
181 item.ForeColor = item2.ForeColor;
182 item.BackColor = item2.BackColor;
184 this.listViewWAVリスト.Refresh();
185 this._Form.b未保存 = true;
188 this._Form.dlgチップパレット.t一時的な隠蔽を解除する();
190 public void tファイル名の相対パス化( string str基本フォルダ名 )
192 for( int i = 1; i <= 36 * 36 - 1; i++ )
194 CWAV cwav = this.WAVキャッシュ.tWAVをキャッシュから検索して返す( i );
195 if( ( cwav != null ) && ( cwav.strファイル名.Length > 0 ) )
199 // #39610 パス末尾を必ずパス区切り文字にすることで、次のUriでパス名をファイル名と誤認識させないようにする
200 // 例えば、c:\dtxdata というフォルダ名を、dtxdataというファイルであると誤解しないように、末尾に\をつけて c:\dtxdata\にする
201 str基本フォルダ名 = str基本フォルダ名.TrimEnd(Path.DirectorySeparatorChar) + Path.DirectorySeparatorChar;
202 Uri uri = new Uri( str基本フォルダ名 );
203 cwav.strファイル名 = Uri.UnescapeDataString( uri.MakeRelativeUri( new Uri( cwav.strファイル名 ) ).ToString() ).Replace( '/', Path.DirectorySeparatorChar);
205 catch( UriFormatException )
211 public string tファイル名を絶対パスで返す( int nWAV番号1to1295 )
213 CWAV wc = this.WAVキャッシュ.tWAVをキャッシュから検索して返す( nWAV番号1to1295 );
214 return this._Form.strファイルの存在するディレクトリを絶対パスで返す( wc.strファイル名 );
216 public void tプレビュー音を再生する( CWAV wc )
218 if( ( wc != null ) && ( wc.strファイル名.Length != 0 ) )
220 string strWavFilenameFullPath = this._Form.strファイルの存在するディレクトリを絶対パスで返す( wc.strファイル名 );
223 // WASAPI排他モードのDTXManiaをViewerとして起動中なら
224 if (this._Form.appアプリ設定.ViewerInfo.SoundType == ESoundDeviceType.ExclusiveWASAPI && this._Form.DetectDTXManiaProcess())
226 //Debug.WriteLine( "DTXManiaで再生" );
228 string strDTXViewerのパス = this._Form.strDTXCのあるフォルダ名 + this._Form.appアプリ設定.ViewerInfo.Path;
229 Process.Start( strDTXViewerのパス,
230 "-V" + wc.n音量0to100.ToString() + "," + wc.n位置_100to100 + "," +
231 "\"" + strWavFilenameFullPath + "\"" ).WaitForInputIdle( 20 * 1000 );
235 //Debug.WriteLine( "DTXCで再生" );
241 catch // DTXMania終了後はDirectSoundの再初期化が必要
246 this.soundPreview = this.sound管理.tサウンドを生成する( strWavFilenameFullPath );
247 this.soundPreview.n音量 = wc.n音量0to100;
248 this.soundPreview.n位置 = wc.n位置_100to100;
249 this.soundPreview.t再生を開始する();
257 public void tプレビュー音を再生する( int nWAV番号1to1295 )
259 CWAV wc = this.WAVキャッシュ.tWAVをキャッシュから検索して返す( nWAV番号1to1295 );
260 this.tプレビュー音を再生する( wc );
262 public void tプレビュー音を再生する(string filename)
264 CWAV wc = new CWAV();
265 wc.strファイル名 = filename;
266 this.tプレビュー音を再生する(wc);
268 public void tプレビュー音を停止する()
270 if( this.soundPreview != null )
272 this.soundPreview.t再生を停止する();
275 public void t行交換のRedo( int n変更前のItem番号0to1294, int n変更後のItem番号0to1294 )
277 CUndoRedo管理.bUndoRedoした直後 = true;
278 this.tItemを交換する( n変更前のItem番号0to1294, n変更後のItem番号0to1294 );
280 public void t行交換のUndo( int n変更前のItem番号0to1294, int n変更後のItem番号0to1294 )
282 CUndoRedo管理.bUndoRedoした直後 = true;
283 this.tItemを交換する( n変更前のItem番号0to1294, n変更後のItem番号0to1294 );
285 public void t新規生成のRedo( CWAV wc生成前はNull, CWAV wc生成されたWAVの複製 )
287 int num = wc生成されたWAVの複製.nWAV番号1to1295;
288 CWAV cwav = this.WAVキャッシュ.tWAVをキャッシュから検索して返す_なければ新規生成する( num );
289 cwav.tコピーfrom( wc生成されたWAVの複製 );
290 cwav.tコピーto( this.listViewWAVリスト.Items[ num - 1 ] );
291 this._Form.tタブを選択する( Cメインフォーム.Eタブ種別.WAV );
292 this.listViewWAVリスト.Refresh();
294 public void t新規生成のUndo( CWAV wc生成前はNull, CWAV wc生成されたWAVの複製 )
296 int num = wc生成されたWAVの複製.nWAV番号1to1295;
297 new CWAV().tコピーto( this.listViewWAVリスト.Items[ num - 1 ] );
298 this.WAVキャッシュ.tWAVをキャッシュから削除する( num );
299 this._Form.tタブを選択する( Cメインフォーム.Eタブ種別.WAV );
300 this.listViewWAVリスト.Refresh();
305 private Cメインフォーム _Form;
306 private ListView listViewWAVリスト;
307 private CSound soundPreview;
308 private CSound管理 sound管理 = null;
309 private CWAVキャッシュ WAVキャッシュ = new CWAVキャッシュ();
310 private TimerCallback timerDelegate;
311 private System.Threading.Timer timer;
313 private void tItemを交換する_ListViewItem( int nItem番号1, int nItem番号2 )
315 int num = nItem番号1 + 1;
316 int num2 = nItem番号2 + 1;
317 CWAV cwav = new CWAV();
318 cwav.tコピーfrom( this.listViewWAVリスト.Items[ nItem番号1 ] );
319 cwav.nWAV番号1to1295 = num2;
320 CWAV cwav2 = new CWAV();
321 cwav2.tコピーfrom( this.listViewWAVリスト.Items[ nItem番号2 ] );
322 cwav2.nWAV番号1to1295 = num;
323 cwav2.tコピーto( this.listViewWAVリスト.Items[ nItem番号1 ] );
324 cwav.tコピーto( this.listViewWAVリスト.Items[ nItem番号2 ] );
326 private void tItemを交換する_WAVキャッシュ( int nItem番号1, int nItem番号2 )
328 int num = nItem番号1 + 1;
329 int num2 = nItem番号2 + 1;
330 CWAV wc = this.WAVキャッシュ.tWAVをキャッシュから検索して返す( num );
331 CWAV cwav2 = this.WAVキャッシュ.tWAVをキャッシュから検索して返す( num2 );
332 CWAV cwav3 = new CWAV();
333 cwav3.tコピーfrom( wc );
334 wc.tコピーfrom( cwav2 );
335 wc.nWAV番号1to1295 = num;
336 cwav2.tコピーfrom( cwav3 );
337 cwav2.nWAV番号1to1295 = num2;
339 private void tItemを交換する_カーソル移動( int nItem番号1, int nItem番号2 )
341 this.tItemを選択する( nItem番号2 );
343 private void tItemを交換する_チップパレット( int nItem番号1, int nItem番号2 )
345 this._Form.dlgチップパレット.tパレットセルの番号を置換する( 0, nItem番号1 + 1, nItem番号2 + 1 );
347 private void tItemを交換する_レーン割付チップ( int nItem番号1, int nItem番号2 )
349 for( int i = 0; i < this._Form.mgr譜面管理者.listレーン.Count; i++ )
351 Cレーン cレーン = this._Form.mgr譜面管理者.listレーン[ i ];
352 if( ( ( cレーン.eレーン種別 == Cレーン.E種別.WAV ) || ( cレーン.eレーン種別 == Cレーン.E種別.GtV ) ) || ( cレーン.eレーン種別 == Cレーン.E種別.BsV ) )
354 if( cレーン.nレーン割付チップ_表0or1to1295 == ( nItem番号1 + 1 ) )
356 cレーン.nレーン割付チップ_表0or1to1295 = nItem番号2 + 1;
358 else if( cレーン.nレーン割付チップ_表0or1to1295 == ( nItem番号2 + 1 ) )
360 cレーン.nレーン割付チップ_表0or1to1295 = nItem番号1 + 1;
362 if( cレーン.nレーン割付チップ_裏0or1to1295 == ( nItem番号1 + 1 ) )
364 cレーン.nレーン割付チップ_裏0or1to1295 = nItem番号2 + 1;
366 else if( cレーン.nレーン割付チップ_裏0or1to1295 == ( nItem番号2 + 1 ) )
368 cレーン.nレーン割付チップ_裏0or1to1295 = nItem番号1 + 1;
373 private void tItemを交換する_譜面上のチップ( int nItem番号1, int nItem番号2 )
375 foreach( KeyValuePair<int, C小節> pair in this._Form.mgr譜面管理者.dic小節 )
377 C小節 c小節 = pair.Value;
378 for( int i = 0; i < c小節.listチップ.Count; i++ )
380 Cチップ cチップ = c小節.listチップ[ i ];
381 switch( this._Form.mgr譜面管理者.listレーン[ cチップ.nレーン番号0to ].eレーン種別 )
386 if( cチップ.n値_整数1to1295 == ( nItem番号1 + 1 ) )
388 cチップ.n値_整数1to1295 = nItem番号2 + 1;
390 else if( cチップ.n値_整数1to1295 == ( nItem番号2 + 1 ) )
392 cチップ.n値_整数1to1295 = nItem番号1 + 1;