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 );
20 public CWAVリスト管理( Cメインフォーム pメインフォーム, ListView pListViewWAVリスト )
22 this._Form = pメインフォーム;
23 this.listViewWAVリスト = pListViewWAVリスト;
26 private void tDirectSoundの初期化()
28 this.sound管理 = new CSound管理( this._Form.Handle );
29 // this.sound管理 = new CSound管理( this._Form.Handle, this._Form.appアプリ設定.ViewerInfo.SoundType, 0, 0, this._Form.appアプリ設定.ViewerInfo.ASIODeviceNo );
31 this.soundPreview = null;
33 #region [ #26122 2011.8.31 yyagi; ストリーム再生のために、t再生中の処理をする()を定期的に呼び出す処理を追加 ]
34 timerDelegate = new TimerCallback( this.sound管理.t再生中の処理をする );
35 timer = new System.Threading.Timer( timerDelegate, null, 0, 300 );
39 public ListViewItem tCWAVとListViewItemを生成して返す( int n行番号1to1295 )
41 return this.tWAVをキャッシュから検索して返す_なければ新規生成する( n行番号1to1295 ).t現在の内容から新しいListViewItemを作成して返す();
43 public void tDirectSoundの解放()
45 if( this.soundPreview != null )
47 this.soundPreview.Dispose();
51 timer.Change( Timeout.Infinite, Timeout.Infinite );
55 if ( timerDelegate != null )
59 if( this.sound管理 != null )
61 this.sound管理.Dispose();
64 public void tItemを交換する( int nItem番号1, int nItem番号2 )
66 if( !CUndoRedo管理.bUndoRedoした直後 )
68 this._Form.mgrUndoRedo管理者.tノードを追加する( new CUndoRedoセル<int>( null, new DGUndoを実行する<int>( this.t行交換のUndo ), new DGRedoを実行する<int>( this.t行交換のRedo ), nItem番号1, nItem番号2 ) );
69 this._Form.tUndoRedo用GUIの有効無効を設定する();
71 CUndoRedo管理.bUndoRedoした直後 = false;
72 this.tItemを交換する_ListViewItem( nItem番号1, nItem番号2 );
73 this.tItemを交換する_WAVキャッシュ( nItem番号1, nItem番号2 );
74 this.tItemを交換する_チップパレット( 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._Form.listViewWAVリスト.Refresh();
79 this._Form.pictureBox譜面パネル.Refresh();
80 this._Form.b未保存 = true;
82 public void tItemを選択する( int nItem番号0to1294 )
84 this.n現在選択中のItem番号0to1294 = nItem番号0to1294;
85 this.listViewWAVリスト.Items[ nItem番号0to1294 ].Selected = true;
86 this.listViewWAVリスト.Items[ nItem番号0to1294 ].Focused = true;
88 public void tWAVリストにフォーカスを当てる()
90 this.listViewWAVリスト.Focus();
92 public CWAV tWAVをキャッシュから検索して返す( int nWAV番号1to1295 )
94 return this.WAVキャッシュ.tWAVをキャッシュから検索して返す( nWAV番号1to1295 );
96 public CWAV tWAVをキャッシュから検索して返す_なければ新規生成する( int nWAV番号1to1295 )
98 return this.WAVキャッシュ.tWAVをキャッシュから検索して返す_なければ新規生成する( nWAV番号1to1295 );
100 public ListViewItem tWAV番号に対応するListViewItemを返す( int nWAV番号1to1295 )
102 if( ( nWAV番号1to1295 < 1 ) || ( nWAV番号1to1295 > 36 * 36 - 1 ) )
104 throw new Exception( "WAV番号が範囲外です。--->[" + nWAV番号1to1295 + "]" );
106 return this.listViewWAVリスト.Items[ nWAV番号1to1295 - 1 ];
108 public void tWAV編集のRedo( CWAV wc変更前, CWAV wc変更後 )
110 int num = wc変更後.nWAV番号1to1295;
111 CWAV cwav = this.WAVキャッシュ.tWAVをキャッシュから検索して返す( num );
112 cwav.tコピーfrom( wc変更後 );
113 cwav.tコピーto( this.listViewWAVリスト.Items[ num - 1 ] );
114 this._Form.tWAV_BMP_AVIリストのカーソルを全部同じ行に合わせる( cwav.nWAV番号1to1295 - 1 );
115 this._Form.tタブを選択する( Cメインフォーム.Eタブ種別.WAV );
116 this.listViewWAVリスト.Refresh();
118 public void tWAV編集のUndo( CWAV wc変更前, CWAV wc変更後 )
120 int num = wc変更前.nWAV番号1to1295;
121 CWAV cwav = this.WAVキャッシュ.tWAVをキャッシュから検索して返す( num );
122 cwav.tコピーfrom( wc変更前 );
123 cwav.tコピーto( this.listViewWAVリスト.Items[ num - 1 ] );
124 this._Form.tWAV_BMP_AVIリストのカーソルを全部同じ行に合わせる( cwav.nWAV番号1to1295 - 1 );
125 this._Form.tタブを選択する( Cメインフォーム.Eタブ種別.WAV );
126 this.listViewWAVリスト.Refresh();
128 public void tサウンドプロパティを開いて編集する( int nWAV番号1to1295, string str相対パスの基本フォルダ )
130 this._Form.dlgチップパレット.t一時的に隠蔽する();
131 CWAV cwav = this.tWAVをキャッシュから検索して返す_なければ新規生成する( nWAV番号1to1295 );
132 ListViewItem item = cwav.t現在の内容から新しいListViewItemを作成して返す();
133 string directoryName = "";
134 if( item.SubItems[ 2 ].Text.Length > 0 )
136 directoryName = Path.GetDirectoryName( this._Form.strファイルの存在するディレクトリを絶対パスで返す( item.SubItems[ 2 ].Text ) );
138 Cサウンドプロパティダイアログ cサウンドプロパティダイアログ = new Cサウンドプロパティダイアログ( str相対パスの基本フォルダ, directoryName, new DGサウンドを再生する( this.tプレビュー音を再生する ) );
139 cサウンドプロパティダイアログ.wav = cwav;
140 cサウンドプロパティダイアログ.textBoxラベル.Text = item.SubItems[ 0 ].Text;
141 cサウンドプロパティダイアログ.textBoxWAV番号.Text = item.SubItems[ 1 ].Text;
142 cサウンドプロパティダイアログ.textBoxファイル.Text = item.SubItems[ 2 ].Text;
143 cサウンドプロパティダイアログ.textBox音量.Text = item.SubItems[ 3 ].Text;
144 cサウンドプロパティダイアログ.textBox位置.Text = item.SubItems[ 4 ].Text;
145 cサウンドプロパティダイアログ.hScrollBar音量.Value = cサウンドプロパティダイアログ.wav.n音量0to100;
146 cサウンドプロパティダイアログ.hScrollBar位置.Value = cサウンドプロパティダイアログ.wav.n位置_100to100 + 100;
147 cサウンドプロパティダイアログ.checkBoxBGM.CheckState = cサウンドプロパティダイアログ.wav.bBGMとして使用 ? CheckState.Checked : CheckState.Unchecked;
148 cサウンドプロパティダイアログ.textBoxWAV番号.ForeColor = item.ForeColor;
149 cサウンドプロパティダイアログ.textBoxWAV番号.BackColor = item.BackColor;
150 if( cサウンドプロパティダイアログ.ShowDialog() == DialogResult.OK )
152 CWAV wav = cサウンドプロパティダイアログ.wav;
153 CWAV cwav3 = new CWAV();
154 cwav3.nWAV番号1to1295 = cサウンドプロパティダイアログ.wav.nWAV番号1to1295;
155 cwav3.strラベル名 = cサウンドプロパティダイアログ.textBoxラベル.Text;
156 cwav3.strファイル名 = cサウンドプロパティダイアログ.textBoxファイル.Text;
157 cwav3.n音量0to100 = cサウンドプロパティダイアログ.hScrollBar音量.Value;
158 cwav3.n位置_100to100 = cサウンドプロパティダイアログ.hScrollBar位置.Value - 100;
159 cwav3.bBGMとして使用 = cサウンドプロパティダイアログ.checkBoxBGM.Checked;
160 cwav3.col文字色 = cサウンドプロパティダイアログ.textBoxWAV番号.ForeColor;
161 cwav3.col背景色 = cサウンドプロパティダイアログ.textBoxWAV番号.BackColor;
162 if( !cwav3.b内容が同じwith( wav ) )
165 wav.tコピーfrom( cサウンドプロパティダイアログ.wav );
166 this._Form.mgrUndoRedo管理者.tノードを追加する( new CUndoRedoセル<CWAV>( null, new DGUndoを実行する<CWAV>( this.tWAV編集のUndo ), new DGRedoを実行する<CWAV>( this.tWAV編集のRedo ), wav, cwav3 ) );
167 this._Form.tUndoRedo用GUIの有効無効を設定する();
168 cサウンドプロパティダイアログ.wav.tコピーfrom( cwav3 );
169 if( this.tWAV番号に対応するListViewItemを返す( nWAV番号1to1295 ) != null )
171 ListViewItem item2 = cサウンドプロパティダイアログ.wav.t現在の内容から新しいListViewItemを作成して返す();
172 item = this.tWAV番号に対応するListViewItemを返す( nWAV番号1to1295 );
173 item.SubItems[ 0 ].Text = item2.SubItems[ 0 ].Text;
174 item.SubItems[ 1 ].Text = item2.SubItems[ 1 ].Text;
175 item.SubItems[ 2 ].Text = item2.SubItems[ 2 ].Text;
176 item.SubItems[ 3 ].Text = item2.SubItems[ 3 ].Text;
177 item.SubItems[ 4 ].Text = item2.SubItems[ 4 ].Text;
178 item.SubItems[ 5 ].Text = item2.SubItems[ 5 ].Text;
179 item.ForeColor = item2.ForeColor;
180 item.BackColor = item2.BackColor;
182 this.listViewWAVリスト.Refresh();
183 this._Form.b未保存 = true;
186 this._Form.dlgチップパレット.t一時的な隠蔽を解除する();
188 public void tファイル名の相対パス化( string str基本フォルダ名 )
190 for( int i = 1; i <= 36 * 36 - 1; i++ )
192 CWAV cwav = this.WAVキャッシュ.tWAVをキャッシュから検索して返す( i );
193 if( ( cwav != null ) && ( cwav.strファイル名.Length > 0 ) )
197 Uri uri = new Uri( str基本フォルダ名 );
198 cwav.strファイル名 = Uri.UnescapeDataString( uri.MakeRelativeUri( new Uri( cwav.strファイル名 ) ).ToString() ).Replace( '/', '\\' );
200 catch( UriFormatException )
206 public string tファイル名を絶対パスで返す( int nWAV番号1to1295 )
208 CWAV wc = this.WAVキャッシュ.tWAVをキャッシュから検索して返す( nWAV番号1to1295 );
209 return this._Form.strファイルの存在するディレクトリを絶対パスで返す( wc.strファイル名 );
211 public void tプレビュー音を再生する( CWAV wc )
213 if( ( wc != null ) && ( wc.strファイル名.Length != 0 ) )
215 string strWavFilenameFullPath = this._Form.strファイルの存在するディレクトリを絶対パスで返す( wc.strファイル名 );
218 bool dtxmProcess = this._Form.DetectDTXManiaProcess();
219 if ( dtxmProcess != false ) // DTXManiaがViewerとして起動中なら
221 //Debug.WriteLine( "DTXManiaで再生" );
223 string strDTXViewerのパス = this._Form.strDTXCのあるフォルダ名 + this._Form.appアプリ設定.ViewerInfo.Path;
224 Process.Start( strDTXViewerのパス,
225 "-V" + wc.n音量0to100.ToString() + "," + wc.n位置_100to100 + "," +
226 "\"" + strWavFilenameFullPath + "\"" ).WaitForInputIdle( 20 * 1000 );
230 //Debug.WriteLine( "DTXCで再生" );
236 catch ( SlimDX.DirectSound.DirectSoundException ) // DTXMania終了後はDirectSoundの再初期化が必要
241 this.soundPreview = this.sound管理.tサウンドを生成する( strWavFilenameFullPath );
242 this.soundPreview.n音量 = wc.n音量0to100;
243 this.soundPreview.n位置 = wc.n位置_100to100;
244 this.soundPreview.t再生を開始する();
252 public void tプレビュー音を再生する( int nWAV番号1to1295 )
254 CWAV wc = this.WAVキャッシュ.tWAVをキャッシュから検索して返す( nWAV番号1to1295 );
255 this.tプレビュー音を再生する( wc );
257 public void tプレビュー音を停止する()
259 if( this.soundPreview != null )
261 this.soundPreview.t再生を停止する();
264 public void t行交換のRedo( int n変更前のItem番号0to1294, int n変更後のItem番号0to1294 )
266 CUndoRedo管理.bUndoRedoした直後 = true;
267 this.tItemを交換する( n変更前のItem番号0to1294, n変更後のItem番号0to1294 );
269 public void t行交換のUndo( int n変更前のItem番号0to1294, int n変更後のItem番号0to1294 )
271 CUndoRedo管理.bUndoRedoした直後 = true;
272 this.tItemを交換する( n変更前のItem番号0to1294, n変更後のItem番号0to1294 );
274 public void t新規生成のRedo( CWAV wc生成前はNull, CWAV wc生成されたWAVの複製 )
276 int num = wc生成されたWAVの複製.nWAV番号1to1295;
277 CWAV cwav = this.WAVキャッシュ.tWAVをキャッシュから検索して返す_なければ新規生成する( num );
278 cwav.tコピーfrom( wc生成されたWAVの複製 );
279 cwav.tコピーto( this.listViewWAVリスト.Items[ num - 1 ] );
280 this._Form.tタブを選択する( Cメインフォーム.Eタブ種別.WAV );
281 this.listViewWAVリスト.Refresh();
283 public void t新規生成のUndo( CWAV wc生成前はNull, CWAV wc生成されたWAVの複製 )
285 int num = wc生成されたWAVの複製.nWAV番号1to1295;
286 new CWAV().tコピーto( this.listViewWAVリスト.Items[ num - 1 ] );
287 this.WAVキャッシュ.tWAVをキャッシュから削除する( num );
288 this._Form.tタブを選択する( Cメインフォーム.Eタブ種別.WAV );
289 this.listViewWAVリスト.Refresh();
294 private Cメインフォーム _Form;
295 private ListView listViewWAVリスト;
296 private CSound soundPreview;
297 private CSound管理 sound管理 = null;
298 private CWAVキャッシュ WAVキャッシュ = new CWAVキャッシュ();
299 private TimerCallback timerDelegate;
300 private System.Threading.Timer timer;
302 private void tItemを交換する_ListViewItem( int nItem番号1, int nItem番号2 )
304 int num = nItem番号1 + 1;
305 int num2 = nItem番号2 + 1;
306 CWAV cwav = new CWAV();
307 cwav.tコピーfrom( this.listViewWAVリスト.Items[ nItem番号1 ] );
308 cwav.nWAV番号1to1295 = num2;
309 CWAV cwav2 = new CWAV();
310 cwav2.tコピーfrom( this.listViewWAVリスト.Items[ nItem番号2 ] );
311 cwav2.nWAV番号1to1295 = num;
312 cwav2.tコピーto( this.listViewWAVリスト.Items[ nItem番号1 ] );
313 cwav.tコピーto( this.listViewWAVリスト.Items[ nItem番号2 ] );
315 private void tItemを交換する_WAVキャッシュ( int nItem番号1, int nItem番号2 )
317 int num = nItem番号1 + 1;
318 int num2 = nItem番号2 + 1;
319 CWAV wc = this.WAVキャッシュ.tWAVをキャッシュから検索して返す( num );
320 CWAV cwav2 = this.WAVキャッシュ.tWAVをキャッシュから検索して返す( num2 );
321 CWAV cwav3 = new CWAV();
322 cwav3.tコピーfrom( wc );
323 wc.tコピーfrom( cwav2 );
324 wc.nWAV番号1to1295 = num;
325 cwav2.tコピーfrom( cwav3 );
326 cwav2.nWAV番号1to1295 = num2;
328 private void tItemを交換する_カーソル移動( int nItem番号1, int nItem番号2 )
330 this.tItemを選択する( nItem番号2 );
332 private void tItemを交換する_チップパレット( int nItem番号1, int nItem番号2 )
334 this._Form.dlgチップパレット.tパレットセルの番号を置換する( 0, nItem番号1 + 1, nItem番号2 + 1 );
336 private void tItemを交換する_レーン割付チップ( int nItem番号1, int nItem番号2 )
338 for( int i = 0; i < this._Form.mgr譜面管理者.listレーン.Count; i++ )
340 Cレーン cレーン = this._Form.mgr譜面管理者.listレーン[ i ];
341 if( ( ( cレーン.eレーン種別 == Cレーン.E種別.WAV ) || ( cレーン.eレーン種別 == Cレーン.E種別.GtV ) ) || ( cレーン.eレーン種別 == Cレーン.E種別.BsV ) )
343 if( cレーン.nレーン割付チップ_表0or1to1295 == ( nItem番号1 + 1 ) )
345 cレーン.nレーン割付チップ_表0or1to1295 = nItem番号2 + 1;
347 else if( cレーン.nレーン割付チップ_表0or1to1295 == ( nItem番号2 + 1 ) )
349 cレーン.nレーン割付チップ_表0or1to1295 = nItem番号1 + 1;
351 if( cレーン.nレーン割付チップ_裏0or1to1295 == ( nItem番号1 + 1 ) )
353 cレーン.nレーン割付チップ_裏0or1to1295 = nItem番号2 + 1;
355 else if( cレーン.nレーン割付チップ_裏0or1to1295 == ( nItem番号2 + 1 ) )
357 cレーン.nレーン割付チップ_裏0or1to1295 = nItem番号1 + 1;
362 private void tItemを交換する_譜面上のチップ( int nItem番号1, int nItem番号2 )
364 foreach( KeyValuePair<int, C小節> pair in this._Form.mgr譜面管理者.dic小節 )
366 C小節 c小節 = pair.Value;
367 for( int i = 0; i < c小節.listチップ.Count; i++ )
369 Cチップ cチップ = c小節.listチップ[ i ];
370 switch( this._Form.mgr譜面管理者.listレーン[ cチップ.nレーン番号0to ].eレーン種別 )
375 if( cチップ.n値_整数1to1295 == ( nItem番号1 + 1 ) )
377 cチップ.n値_整数1to1295 = nItem番号2 + 1;
379 else if( cチップ.n値_整数1to1295 == ( nItem番号2 + 1 ) )
381 cチップ.n値_整数1to1295 = nItem番号1 + 1;