forked from LingFeng-bbben/MajdataEdit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainWindow.xaml.cs
More file actions
561 lines (526 loc) · 20 KB
/
Copy pathMainWindow.xaml.cs
File metadata and controls
561 lines (526 loc) · 20 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Timers;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Interop;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Diagnostics;
using System.IO;
using Un4seen.Bass;
using Un4seen.Bass.Misc;
using System.Drawing;
using System.Media;
using System.ComponentModel;
namespace MajdataEdit
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
if (Environment.GetCommandLineArgs().Contains("--ForceSoftwareRender"))
{
MessageBox.Show("正在以软件渲染模式运行\nソフトウェア・レンダリング・モードで動作\nBooting as software rendering mode.");
RenderOptions.ProcessRenderMode = RenderMode.SoftwareOnly;
}
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
CheckAndStartView();
TheWindow.Title = GetWindowsTitleString();
SetWindowGoldenPosition();
var handle = (new WindowInteropHelper(this)).Handle;
Bass.BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_CPSPEAKERS, handle);
ReadSoundEffect();
ReadEditorSetting();
ReadMuriCheckSlideTime();
chartChangeTimer.Elapsed += ChartChangeTimer_Elapsed;
chartChangeTimer.AutoReset = false;
currentTimeRefreshTimer.Elapsed += CurrentTimeRefreshTimer_Elapsed;
currentTimeRefreshTimer.Start();
clickSoundTimer.Elapsed += ClickSoundTimer_Elapsed;
VisualEffectRefreshTimer.Elapsed += VisualEffectRefreshTimer_Elapsed;
VisualEffectRefreshTimer.Start();
waveStopMonitorTimer.Elapsed += WaveStopMonitorTimer_Elapsed;
PlbHideTimer.Elapsed += PlbHideTimer_Elapsed;
if (editorSetting.AutoCheckUpdate)
{
CheckUpdate(onStart: true);
}
}
//start the view and wait for boot, then set window pos
private void SetWindowPosTimer_Elapsed(object sender, ElapsedEventArgs e)
{
Timer setWindowPosTimer = (Timer)sender;
Dispatcher.Invoke(() =>
{
InternalSwitchWindow();
});
setWindowPosTimer.Stop();
setWindowPosTimer.Dispose();
}
// This update very freqently to Draw FFT wave.
private void VisualEffectRefreshTimer_Elapsed(object sender, ElapsedEventArgs e)
{
DrawFFT();
}
// This update very freqently to play sound effect.
private void ClickSoundTimer_Elapsed(object sender, ElapsedEventArgs e)
{
SoundEffectUpdate();
}
// This update less frequently. set the time text.
private void CurrentTimeRefreshTimer_Elapsed(object sender, ElapsedEventArgs e)
{
UpdateTimeDisplay();
}
// This update "middle" frequently to monitor if the wave has to be stopped
private void WaveStopMonitorTimer_Elapsed(object sender, ElapsedEventArgs e)
{
WaveStopMonitorUpdate();
}
/// <summary>
/// 谱面变更延迟解析
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ChartChangeTimer_Elapsed(object sender, ElapsedEventArgs e)
{
Console.WriteLine("TextChanged");
Dispatcher.Invoke(
new Action(
delegate
{
SimaiProcess.Serialize(GetRawFumenText(), GetRawFumenPosition());
DrawWave();
}
)
);
}
//Window events
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
if (!isSaved)
{
if (!AskSave())
{
e.Cancel = true;
return;
}
}
var process = Process.GetProcessesByName("MajdataView");
if (process.Length > 0)
{
var result = MessageBox.Show(GetLocalizedString("AskCloseView"), GetLocalizedString("Attention"), MessageBoxButton.YesNo);
if (result == MessageBoxResult.Yes)
process[0].Kill();
}
currentTimeRefreshTimer.Stop();
VisualEffectRefreshTimer.Stop();
soundSetting.Close();
//if (bpmtap != null) { bpmtap.Close(); }
//if (muriCheck != null) { muriCheck.Close(); }
SaveSetting();
Bass.BASS_ChannelStop(bgmStream);
Bass.BASS_StreamFree(bgmStream);
Bass.BASS_ChannelStop(answerStream);
Bass.BASS_StreamFree(answerStream);
Bass.BASS_ChannelStop(breakStream);
Bass.BASS_StreamFree(breakStream);
Bass.BASS_ChannelStop(judgeExStream);
Bass.BASS_StreamFree(judgeExStream);
Bass.BASS_ChannelStop(hanabiStream);
Bass.BASS_StreamFree(hanabiStream);
Bass.BASS_Stop();
Bass.BASS_Free();
}
//Window grid events
private void Grid_DragEnter(object sender, DragEventArgs e)
{
e.Effects = DragDropEffects.Move;
}
private void Grid_Drop(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
{
//Console.WriteLine(e.Data.GetData(DataFormats.FileDrop).ToString());
if (e.Data.GetData(DataFormats.FileDrop).ToString() == "System.String[]")
{
var path = ((string[])e.Data.GetData(DataFormats.FileDrop))[0];
if (path.ToLower().Contains("maidata.txt"))
{
if (!isSaved)
{
if (!AskSave()) return;
}
FileInfo fileInfo = new FileInfo(path);
initFromFile(fileInfo.DirectoryName);
}
return;
}
}
}
#region MENU BARS
private void Menu_New_Click(object sender, RoutedEventArgs e)
{
if (!isSaved)
{
if (!AskSave()) return;
}
var openFileDialog = new Microsoft.Win32.OpenFileDialog();
openFileDialog.Filter = "track.mp3|track.mp3";
if ((bool)openFileDialog.ShowDialog())
{
FileInfo fileInfo = new FileInfo(openFileDialog.FileName);
CreateNewFumen(fileInfo.DirectoryName);
initFromFile(fileInfo.DirectoryName);
}
}
private void Menu_Open_Click(object sender, RoutedEventArgs e)
{
if (!isSaved)
{
if (!AskSave()) return;
}
var openFileDialog = new Microsoft.Win32.OpenFileDialog();
openFileDialog.Filter = "maidata.txt|maidata.txt";
if ((bool)openFileDialog.ShowDialog())
{
FileInfo fileInfo = new FileInfo(openFileDialog.FileName);
initFromFile(fileInfo.DirectoryName);
}
}
private void Menu_Save_Click(object sender, RoutedEventArgs e)
{
SaveFumen(true);
SystemSounds.Beep.Play();
}
private void Menu_SaveAs_Click(object sender, RoutedEventArgs e)
{
}
private void MirrorLeftRight_MenuItem_Click(object sender, RoutedEventArgs e)
{
var result = Mirror.NoteMirrorLeftRight(FumenContent.Selection.Text);
FumenContent.Selection.Text = result;
}
private void MirrorUpDown_MenuItem_Click(object sender, RoutedEventArgs e)
{
var result = Mirror.NoteMirrorUpDown(FumenContent.Selection.Text);
FumenContent.Selection.Text = result;
}
private void Mirror180_MenuItem_Click(object sender, RoutedEventArgs e)
{
var result = Mirror.NoteMirror180(FumenContent.Selection.Text);
FumenContent.Selection.Text = result;
}
private void Mirror45_MenuItem_Click(object sender, RoutedEventArgs e)
{
var result = Mirror.NoteMirrorSpin45(FumenContent.Selection.Text);
FumenContent.Selection.Text = result;
}
private void MirrorCcw45_MenuItem_Click(object sender, RoutedEventArgs e)
{
var result = Mirror.NoteMirrorSpinCcw45(FumenContent.Selection.Text);
FumenContent.Selection.Text = result;
}
private void BPMtap_MenuItem_Click(object sender, RoutedEventArgs e)
{
BPMtap tap = new BPMtap();
tap.Owner = this;
tap.Show();
}
private void MenuItem_InfomationEdit_Click(object sender, RoutedEventArgs e)
{
var infoWindow = new Infomation();
infoWindow.ShowDialog();
TheWindow.Title = GetWindowsTitleString(SimaiProcess.title);
}
private void MenuItem_SimaiWiki_Click(object sender, RoutedEventArgs e)
{
System.Diagnostics.Process.Start("https://w.atwiki.jp/simai/pages/25.html");
//maidata.txtの譜面書式
}
private void MenuItem_GitHub_Click(object sender, RoutedEventArgs e)
{
System.Diagnostics.Process.Start("https://github.com/LingFeng-bbben/MajdataView");
}
private void MenuItem_SoundSetting_Click(object sender, RoutedEventArgs e)
{
soundSetting = new SoundSetting();
soundSetting.Owner = this;
soundSetting.ShowDialog();
}
private void MuriCheck_Click_1(object sender, RoutedEventArgs e)
{
MuriCheck muriCheck = new MuriCheck();
muriCheck.Owner = this;
muriCheck.Show();
}
private void MenuItem_EditorSetting_Click(object sender, RoutedEventArgs e)
{
EditorSettingPanel esp = new EditorSettingPanel();
esp.Owner = this;
esp.ShowDialog();
}
private void Menu_ResetViewWindow(object sender, RoutedEventArgs e)
{
if (CheckAndStartView()) return;
InternalSwitchWindow();
}
private void MenuFind_Click(object sender, RoutedEventArgs e)
{
if (FindGrid.Visibility == Visibility.Collapsed)
{
FindGrid.Visibility = Visibility.Visible;
InputText.Focus();
}
else
FindGrid.Visibility = Visibility.Collapsed;
}
private void CheckUpdate_Click(object sender, RoutedEventArgs e)
{
CheckUpdate();
}
#endregion
#region 快捷键
private void PlayAndPause_CanExecute(object sender, CanExecuteRoutedEventArgs e) //快捷键
{
TogglePlayAndStop();
}
private void StopPlaying_CanExecute(object sender, CanExecuteRoutedEventArgs e) //快捷键
{
TogglePlayAndPause();
}
private void SaveFile_Command_CanExecute(object sender, CanExecuteRoutedEventArgs e)
{
SaveFumen(true);
SystemSounds.Beep.Play();
}
private void SendToView_CanExecute(object sender, CanExecuteRoutedEventArgs e)
{
TogglePlayAndStop(true);
}
private void IncreasePlaybackSpeed_CanExecute(object sender, CanExecuteRoutedEventArgs e)
{
if (Bass.BASS_ChannelIsActive(bgmStream) == BASSActive.BASS_ACTIVE_PLAYING) return;
float speed = GetPlaybackSpeed();
Console.WriteLine(speed);
speed += 0.25f;
PlbSpdLabel.Content = speed * 100 + "%";
SetPlaybackSpeed(speed);
PlbSpdAdjGrid.Visibility = Visibility.Visible;
PlbHideTimer.Stop();
PlbHideTimer.Start();
}
private void DecreasePlaybackSpeed_CanExecute(object sender, CanExecuteRoutedEventArgs e)
{
if (Bass.BASS_ChannelIsActive(bgmStream)==BASSActive.BASS_ACTIVE_PLAYING) return;
float speed = GetPlaybackSpeed();
Console.WriteLine(speed);
speed -= 0.25f;
PlbSpdLabel.Content = speed * 100 + "%";
SetPlaybackSpeed(speed);
PlbSpdAdjGrid.Visibility = Visibility.Visible;
PlbHideTimer.Stop();
PlbHideTimer.Start();
}
Timer PlbHideTimer = new Timer(1000);
private void PlbHideTimer_Elapsed(object sender, ElapsedEventArgs e)
{
Dispatcher.Invoke(() => { PlbSpdAdjGrid.Visibility = Visibility.Collapsed; });
((Timer)sender).Stop();
}
private void FindCommand_CanExecute(object sender, CanExecuteRoutedEventArgs e)
{
if (FindGrid.Visibility == Visibility.Collapsed)
{
FindGrid.Visibility = Visibility.Visible;
InputText.Focus();
}
else
FindGrid.Visibility = Visibility.Collapsed;
}
private void MirrorLRCommand_CanExecute(object sender, CanExecuteRoutedEventArgs e)
{
MirrorLeftRight_MenuItem_Click(sender, null);
}
private void MirrorUDCommand_CanExecute(object sender, CanExecuteRoutedEventArgs e)
{
MirrorUpDown_MenuItem_Click(sender, null);
}
private void Mirror180Command_CanExecute(object sender, CanExecuteRoutedEventArgs e)
{
Mirror180_MenuItem_Click(sender, null);
}
private void Mirror45Command_CanExecute(object sender, CanExecuteRoutedEventArgs e)
{
Mirror45_MenuItem_Click(sender, null);
}
private void MirrorCcw45Command_CanExecute(object sender, CanExecuteRoutedEventArgs e)
{
MirrorCcw45_MenuItem_Click(sender, null);
}
#endregion
#region Left componients
private void PlayAndPauseButton_Click(object sender, RoutedEventArgs e)
{
TogglePlayAndPause();
}
private void StopButton_Click(object sender, RoutedEventArgs e)
{
ToggleStop();
}
private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
int i = LevelSelector.SelectedIndex;
SetRawFumenText(SimaiProcess.fumens[i]);
selectedDifficulty = i;
LevelTextBox.Text = SimaiProcess.levels[selectedDifficulty];
SetSavedState(true);
SimaiProcess.Serialize(GetRawFumenText());
DrawWave();
}
private void LevelTextBox_TextChanged(object sender, TextChangedEventArgs e)
{
SetSavedState(false);
if (selectedDifficulty == -1) return;
SimaiProcess.levels[selectedDifficulty] = LevelTextBox.Text;
}
private void OffsetTextBox_TextChanged(object sender, TextChangedEventArgs e)
{
SetSavedState(false);
try
{
SimaiProcess.first = float.Parse(OffsetTextBox.Text);
SimaiProcess.Serialize(GetRawFumenText());
DrawWave();
}
catch { SimaiProcess.first = 0f; }
}
private void OffsetTextBox_MouseWheel(object sender, MouseWheelEventArgs e)
{
var offset = float.Parse(OffsetTextBox.Text);
offset += e.Delta > 0 ? 0.01f : -0.01f;
OffsetTextBox.Text = offset.ToString();
}
private void FollowPlayCheck_Click(object sender, RoutedEventArgs e)
{
FumenContent.Focus();
}
private void Export_Button_Click(object sender, RoutedEventArgs e)
{
TogglePlayAndStop(true);
}
private void SettingLabel_MouseUp(object sender, MouseButtonEventArgs e)
{
// 单击设置的时候也可以进入设置界面
EditorSettingPanel esp = new EditorSettingPanel();
esp.Owner = this;
esp.ShowDialog();
}
#endregion
#region RichTextbox events
private void FumenContent_SelectionChanged(object sender, RoutedEventArgs e)
{
NoteNowText.Content = "" + (
new TextRange(FumenContent.Document.ContentStart, FumenContent.CaretPosition).Text.
Replace("\r", "").Count(o => o == '\n') + 1) + " 行";
if (Bass.BASS_ChannelIsActive(bgmStream) == BASSActive.BASS_ACTIVE_PLAYING && (bool)FollowPlayCheck.IsChecked)
return;
var time = SimaiProcess.Serialize(GetRawFumenText(), GetRawFumenPosition());
//按住Ctrl,同时按下鼠标左键/上下左右方向键时,才改变进度,其他包含Ctrl的组合键不影响进度。
if (Keyboard.Modifiers == ModifierKeys.Control && (
Mouse.LeftButton == MouseButtonState.Pressed ||
Keyboard.IsKeyDown(Key.Left) ||
Keyboard.IsKeyDown(Key.Right) ||
Keyboard.IsKeyDown(Key.Up) ||
Keyboard.IsKeyDown(Key.Down)
))
{
if(Bass.BASS_ChannelIsActive(bgmStream) == BASSActive.BASS_ACTIVE_PLAYING)
TogglePause();
SetBgmPosition(time);
}
//Console.WriteLine("SelectionChanged");
SimaiProcess.ClearNoteListPlayedState();
DrawCusor(time);
}
private void FumenContent_TextChanged(object sender, TextChangedEventArgs e)
{
if (GetRawFumenText() == ""||isLoading) return;
SetSavedState(false);
if (chartChangeTimer.Interval < 33)
{
SimaiProcess.Serialize(GetRawFumenText(), GetRawFumenPosition());
DrawWave();
}
else
{
chartChangeTimer.Stop();
chartChangeTimer.Start();
}
}
private void FumenContent_OnPreviewKeyDown(object sender, KeyEventArgs e)
{
// 按下Insert键,同时未按下任何组合键,切换覆盖模式
if (e.Key == Key.Insert && Keyboard.Modifiers == ModifierKeys.None)
{
SwitchFumenOverwriteMode();
e.Handled = true;
}
}
#endregion
#region Wave displayer
private void WaveViewZoomIn_Click(object sender, RoutedEventArgs e)
{
if (zoominPower <6)
zoominPower += 1;
DrawWave();
FumenContent.Focus();
}
private void WaveViewZoomOut_Click(object sender, RoutedEventArgs e)
{
if(zoominPower>1)
zoominPower -= 1;
DrawWave();
FumenContent.Focus();
}
private void MusicWave_MouseWheel(object sender, MouseWheelEventArgs e)
{
ScrollWave(e.Delta);
}
private void MusicWave_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
//lastMousePointX = e.GetPosition(this).X;
}
private void MusicWave_MouseMove(object sender, MouseEventArgs e)
{
if (e.LeftButton == MouseButtonState.Pressed)
{
double delta = e.GetPosition(this).X - lastMousePointX;
lastMousePointX = e.GetPosition(this).X;
ScrollWave(delta*zoominPower*4d);
}
lastMousePointX = e.GetPosition(this).X;
}
#endregion
private void FindClose_MouseDown(object sender, MouseButtonEventArgs e)
{
FindGrid.Visibility = Visibility.Collapsed;
FumenContent.Focus();
}
}
}