OSDN Git Service

#32713 初コミット。SVNrev567時点での、ファイルはbranch/140707(ReBuild XGVersion)から移行したもの。
[dtxmaniaxg-verk/dtxmaniaxg-verk-git.git] / DTXCreatorプロジェクト / コード / 02.WAV_BMP_AVI / CWAVリスト管理.cs
1 using System;
2 using System.Collections.Generic;
3 using System.Text;
4 using System.Windows.Forms;
5 using System.IO;
6 using System.Threading;
7 using System.Diagnostics;
8 using DTXCreator.UndoRedo;
9 using DTXCreator.譜面;
10 using FDK;
11
12 namespace DTXCreator.WAV_BMP_AVI
13 {
14         internal class CWAVリスト管理
15         {
16                 public int n現在選択中のItem番号0to1294 = -1;
17
18                 internal delegate void DGサウンドを再生する( int nWAV番号1to1295 );
19
20                 public CWAVリスト管理( Cメインフォーム pメインフォーム, ListView pListViewWAVリスト )
21                 {
22                         this._Form = pメインフォーム;
23                         this.listViewWAVリスト = pListViewWAVリスト;
24                         tDirectSoundの初期化();
25                 }
26                 private void tDirectSoundの初期化()
27                 {
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 );
30
31                         this.soundPreview = null;
32
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 );
36                         #endregion
37                 }
38
39                 public ListViewItem tCWAVとListViewItemを生成して返す( int n行番号1to1295 )
40                 {
41                         return this.tWAVをキャッシュから検索して返す_なければ新規生成する( n行番号1to1295 ).t現在の内容から新しいListViewItemを作成して返す();
42                 }
43                 public void tDirectSoundの解放()
44                 {
45                         if( this.soundPreview != null )
46                         {
47                                 this.soundPreview.Dispose();
48                         }
49                         if ( timer != null )
50                         {
51                                 timer.Change( Timeout.Infinite, Timeout.Infinite );
52                                 timer.Dispose();
53                                 timer = null;
54                         }
55                         if ( timerDelegate != null )
56                         {
57                                 timerDelegate = null;
58                         }
59                         if( this.sound管理 != null )
60                         {
61                                 this.sound管理.Dispose();
62                         }
63                 }
64                 public void tItemを交換する( int nItem番号1, int nItem番号2 )
65                 {
66                         if( !CUndoRedo管理.bUndoRedoした直後 )
67                         {
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の有効無効を設定する();
70                         }
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;
81                 }
82                 public void tItemを選択する( int nItem番号0to1294 )
83                 {
84                         this.n現在選択中のItem番号0to1294 = nItem番号0to1294;
85                         this.listViewWAVリスト.Items[ nItem番号0to1294 ].Selected = true;
86                         this.listViewWAVリスト.Items[ nItem番号0to1294 ].Focused = true;
87                 }
88                 public void tWAVリストにフォーカスを当てる()
89                 {
90                         this.listViewWAVリスト.Focus();
91                 }
92                 public CWAV tWAVをキャッシュから検索して返す( int nWAV番号1to1295 )
93                 {
94                         return this.WAVキャッシュ.tWAVをキャッシュから検索して返す( nWAV番号1to1295 );
95                 }
96                 public CWAV tWAVをキャッシュから検索して返す_なければ新規生成する( int nWAV番号1to1295 )
97                 {
98                         return this.WAVキャッシュ.tWAVをキャッシュから検索して返す_なければ新規生成する( nWAV番号1to1295 );
99                 }
100                 public ListViewItem tWAV番号に対応するListViewItemを返す( int nWAV番号1to1295 )
101                 {
102                         if( ( nWAV番号1to1295 < 1 ) || ( nWAV番号1to1295 > 36 * 36 - 1 ) )
103                         {
104                                 throw new Exception( "WAV番号が範囲外です。--->[" + nWAV番号1to1295 + "]" );
105                         }
106                         return this.listViewWAVリスト.Items[ nWAV番号1to1295 - 1 ];
107                 }
108                 public void tWAV編集のRedo( CWAV wc変更前, CWAV wc変更後 )
109                 {
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();
117                 }
118                 public void tWAV編集のUndo( CWAV wc変更前, CWAV wc変更後 )
119                 {
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();
127                 }
128                 public void tサウンドプロパティを開いて編集する( int nWAV番号1to1295, string str相対パスの基本フォルダ )
129                 {
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 )
135                         {
136                                 directoryName = Path.GetDirectoryName( this._Form.strファイルの存在するディレクトリを絶対パスで返す( item.SubItems[ 2 ].Text ) );
137                         }
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 )
151                         {
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 ) )
163                                 {
164                                         wav = new CWAV();
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 )
170                                         {
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;
181                                         }
182                                         this.listViewWAVリスト.Refresh();
183                                         this._Form.b未保存 = true;
184                                 }
185                         }
186                         this._Form.dlgチップパレット.t一時的な隠蔽を解除する();
187                 }
188                 public void tファイル名の相対パス化( string str基本フォルダ名 )
189                 {
190                         for( int i = 1; i <= 36 * 36 - 1; i++ )
191                         {
192                                 CWAV cwav = this.WAVキャッシュ.tWAVをキャッシュから検索して返す( i );
193                                 if( ( cwav != null ) && ( cwav.strファイル名.Length > 0 ) )
194                                 {
195                                         try
196                                         {
197                                                 Uri uri = new Uri( str基本フォルダ名 );
198                                                 cwav.strファイル名 = Uri.UnescapeDataString( uri.MakeRelativeUri( new Uri( cwav.strファイル名 ) ).ToString() ).Replace( '/', '\\' );
199                                         }
200                                         catch( UriFormatException )
201                                         {
202                                         }
203                                 }
204                         }
205                 }
206                 public string tファイル名を絶対パスで返す( int nWAV番号1to1295 )
207                 {
208                         CWAV wc = this.WAVキャッシュ.tWAVをキャッシュから検索して返す( nWAV番号1to1295 );
209                         return this._Form.strファイルの存在するディレクトリを絶対パスで返す( wc.strファイル名 );
210                 }
211                 public void tプレビュー音を再生する( CWAV wc )
212                 {
213                         if( ( wc != null ) && ( wc.strファイル名.Length != 0 ) )
214                         {
215                                 string strWavFilenameFullPath = this._Form.strファイルの存在するディレクトリを絶対パスで返す( wc.strファイル名 );
216                                 try
217                                 {
218                                         bool dtxmProcess = this._Form.DetectDTXManiaProcess();
219                                         if ( dtxmProcess != false )     // DTXManiaがViewerとして起動中なら
220                                         {
221 //Debug.WriteLine( "DTXManiaで再生" );
222                                                 // 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 );
227                                         }
228                                         else
229                                         {
230 //Debug.WriteLine( "DTXCで再生" );
231                                                 // さもなくば、DTXC内で再生する
232                                                 try
233                                                 {
234                                                         this.tプレビュー音を停止する();
235                                                 }
236                                                 catch ( SlimDX.DirectSound.DirectSoundException )       // DTXMania終了後はDirectSoundの再初期化が必要
237                                                 {
238                                                         tDirectSoundの解放();
239                                                         tDirectSoundの初期化();
240                                                 }
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再生を開始する();
245                                         }
246                                 }
247                                 catch
248                                 {
249                                 }
250                         }
251                 }
252                 public void tプレビュー音を再生する( int nWAV番号1to1295 )
253                 {
254                         CWAV wc = this.WAVキャッシュ.tWAVをキャッシュから検索して返す( nWAV番号1to1295 );
255                         this.tプレビュー音を再生する( wc );
256                 }
257                 public void tプレビュー音を停止する()
258                 {
259                         if( this.soundPreview != null )
260                         {
261                                 this.soundPreview.t再生を停止する();
262                         }
263                 }
264                 public void t行交換のRedo( int n変更前のItem番号0to1294, int n変更後のItem番号0to1294 )
265                 {
266                         CUndoRedo管理.bUndoRedoした直後 = true;
267                         this.tItemを交換する( n変更前のItem番号0to1294, n変更後のItem番号0to1294 );
268                 }
269                 public void t行交換のUndo( int n変更前のItem番号0to1294, int n変更後のItem番号0to1294 )
270                 {
271                         CUndoRedo管理.bUndoRedoした直後 = true;
272                         this.tItemを交換する( n変更前のItem番号0to1294, n変更後のItem番号0to1294 );
273                 }
274                 public void t新規生成のRedo( CWAV wc生成前はNull, CWAV wc生成されたWAVの複製 )
275                 {
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();
282                 }
283                 public void t新規生成のUndo( CWAV wc生成前はNull, CWAV wc生成されたWAVの複製 )
284                 {
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();
290                 }
291
292                 #region [ private ]
293                 //-----------------
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;
301
302                 private void tItemを交換する_ListViewItem( int nItem番号1, int nItem番号2 )
303                 {
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 ] );
314                 }
315                 private void tItemを交換する_WAVキャッシュ( int nItem番号1, int nItem番号2 )
316                 {
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;
327                 }
328                 private void tItemを交換する_カーソル移動( int nItem番号1, int nItem番号2 )
329                 {
330                         this.tItemを選択する( nItem番号2 );
331                 }
332                 private void tItemを交換する_チップパレット( int nItem番号1, int nItem番号2 )
333                 {
334                         this._Form.dlgチップパレット.tパレットセルの番号を置換する( 0, nItem番号1 + 1, nItem番号2 + 1 );
335                 }
336                 private void tItemを交換する_レーン割付チップ( int nItem番号1, int nItem番号2 )
337                 {
338                         for( int i = 0; i < this._Form.mgr譜面管理者.listレーン.Count; i++ )
339                         {
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 ) )
342                                 {
343                                         if( cレーン.nレーン割付チップ_表0or1to1295 == ( nItem番号1 + 1 ) )
344                                         {
345                                                 cレーン.nレーン割付チップ_表0or1to1295 = nItem番号2 + 1;
346                                         }
347                                         else if( cレーン.nレーン割付チップ_表0or1to1295 == ( nItem番号2 + 1 ) )
348                                         {
349                                                 cレーン.nレーン割付チップ_表0or1to1295 = nItem番号1 + 1;
350                                         }
351                                         if( cレーン.nレーン割付チップ_裏0or1to1295 == ( nItem番号1 + 1 ) )
352                                         {
353                                                 cレーン.nレーン割付チップ_裏0or1to1295 = nItem番号2 + 1;
354                                         }
355                                         else if( cレーン.nレーン割付チップ_裏0or1to1295 == ( nItem番号2 + 1 ) )
356                                         {
357                                                 cレーン.nレーン割付チップ_裏0or1to1295 = nItem番号1 + 1;
358                                         }
359                                 }
360                         }
361                 }
362                 private void tItemを交換する_譜面上のチップ( int nItem番号1, int nItem番号2 )
363                 {
364                         foreach( KeyValuePair<int, C小節> pair in this._Form.mgr譜面管理者.dic小節 )
365                         {
366                                 C小節 c小節 = pair.Value;
367                                 for( int i = 0; i < c小節.listチップ.Count; i++ )
368                                 {
369                                         Cチップ cチップ = c小節.listチップ[ i ];
370                                         switch( this._Form.mgr譜面管理者.listレーン[ cチップ.nレーン番号0to ].eレーン種別 )
371                                         {
372                                                 case Cレーン.E種別.WAV:
373                                                 case Cレーン.E種別.GtV:
374                                                 case Cレーン.E種別.BsV:
375                                                         if( cチップ.n値_整数1to1295 == ( nItem番号1 + 1 ) )
376                                                         {
377                                                                 cチップ.n値_整数1to1295 = nItem番号2 + 1;
378                                                         }
379                                                         else if( cチップ.n値_整数1to1295 == ( nItem番号2 + 1 ) )
380                                                         {
381                                                                 cチップ.n値_整数1to1295 = nItem番号1 + 1;
382                                                         }
383                                                         break;
384                                         }
385                                 }
386                         }
387                 }
388                 //-----------------
389                 #endregion
390         }
391 }