Repository navigation
Expand file tree
/
Copy pathMainProject.vb
More file actions
4659 lines (3802 loc) · 215 KB
/
Copy pathMainProject.vb
File metadata and controls
4659 lines (3802 loc) · 215 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
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
Imports System.IO
Imports System.IO.Compression
Imports System.Net
Imports System.Threading
Imports System.Xml
Imports System.ComponentModel
Imports System.Text.RegularExpressions
Imports System.Drawing.Drawing2D
Imports System.Text
Imports System.Globalization
Imports NAudio.Wave
Imports NAudio.Midi
Imports ICSharpCode.SharpZipLib.GZip
Imports ICSharpCode.SharpZipLib.Core
Imports A2UP
Imports A2UP.A2U.keyLED_MIDEX
Imports A2UP.A2U.keySound
Imports System.Runtime.InteropServices
Imports System.Drawing.Text
Public Class MainProject
#Region "UniConverter-MainProject(s)"
#Region "MainProject-keySound(s)"
''' <summary>
''' keySound 저장 여부.
''' </summary>
Public Shared SoundIsSaved As Boolean
''' <summary>
''' keySound 변환 여부.
''' </summary>
Public ks_Converted As Boolean
#End Region
#Region "MainProject-keyLED(s)"
Private stopitnow As Boolean = False
''' <summary>
''' MainProject keyLED 저장 여부. (keyLED / keyLED (MIDEX))
''' </summary>
Public Shared keyLEDIsSaved As Boolean
''' <summary>
''' keyLED 버튼 저장
''' </summary>
Public Shared kl_ctrl As New Dictionary(Of String, Button)
''' <summary>
''' 현재 선택한 체인. (1~8)
''' </summary>
Public Shared klUniPack_SelectedChain As Integer = 1
''' <summary>
''' keyLED 변환 여부.
''' </summary>
Public kl_Converted As Boolean
#End Region
#Region "MainProject-Thread(s)"
Private trd_ListView As ListView
Private updateShow As Boolean = False
#End Region
''' <summary>
''' 라이센스 파일. (0: Developer Mode, 1: GreatEx Mode)
''' </summary>
Public Shared LicenseFile As String() = New String(1) {Application.StartupPath & "\MDSL\DeveloperMode.uni", Application.StartupPath & "\MDSL\GreatExMode.uni"}
''' <summary>
''' Developer Mode?
''' </summary>
Public Shared IsDeveloperMode As Boolean = False
''' <summary>
''' Great Exception Mode!
''' </summary>
Public Shared IsGreatExMode As Boolean = False
''' <summary>
''' MainProject 전체 저장 여부. (Save As Project)
''' </summary>
Public Shared IsSaved As Boolean
''' <summary>
''' UniPack info 저장 여부.
''' </summary>
Public Shared infoIsSaved As Boolean
''' <summary>
''' 업데이트 여부.
''' </summary>
Public Shared IsUpdated As Boolean
''' <summary>
''' 한 번에 Ableton Project를 열 것인가?
''' </summary>
Public OpenProjectOnce As ProjectOpenMethod
''' <summary>
''' 지금 매우 중요한 작업 여부.
''' </summary>
Public Shared IsWorking As Boolean
''' <summary>
''' 유니컨버터 언어. (English / Korean)
''' </summary>
Public Shared lang As Translator.tL
''' <summary>
''' 유니팩 이름
''' </summary>
Public Shared UniPack_Title As String
''' <summary>
''' 유니팩 제작자 이름
''' </summary>
Public Shared UniPack_ProducerName As String
''' <summary>
''' 유니팩 체인
''' </summary>
Public Shared UniPack_Chains As Integer
#Region "MIDI Settings"
Public midioutput As MidiOut
''' <summary>
''' 0: Mini/S, 1: MK2, 2: Pro
''' </summary>
Public midioutput_kind As Integer = 0
Public midioutput_avail As Boolean = False
Public WithEvents midiinput As MidiIn
''' <summary>
''' 0: Mini/S, 1: MK2, 2: Pro (0~127 단계 소리 세기 조절 기능)
''' </summary>
Public midiinput_kind As Integer = 0
Public midiinput_avail As Boolean = False
#End Region
#End Region
#Region "MainProject-Ableton(s)"
Public Shared abl_ver As String
Public Shared abl_FileName As String
Public Shared abl_Name As String
Public Shared abl_Chain As Integer
Public Shared abl_openedproj As Boolean
Public Shared abl_openedsnd As Boolean
Public Shared abl_openedled As Boolean
Private _midiExtensionMapping As New Dictionary(Of Integer, MidiExtensionSave)
Public Shared ReadOnly WORKSPACE_PATH As String = Application.StartupPath & "\Workspace"
Public Shared ReadOnly ABLETON_PROJECT_PATH As String = WORKSPACE_PATH & "\ableproj"
Public Shared ReadOnly ABLETON_PROJECT_XML_PATH As String = ABLETON_PROJECT_PATH & "\abl_proj.xml"
Public Shared ReadOnly ABLETON_SOUNDS_PATH As String = ABLETON_PROJECT_PATH & "\sounds"
Public Shared ReadOnly ABLETON_KEYLED_PATH As String = ABLETON_PROJECT_PATH & "\CoLED"
Public Shared ReadOnly UNIPACK_PROJECT_PATH As String = WORKSPACE_PATH & "\unipack"
Public Shared ReadOnly UNIPACK_INFO_PATH As String = UNIPACK_PROJECT_PATH & "\info"
Public Shared ReadOnly UNIPACK_SOUNDS_PATH As String = UNIPACK_PROJECT_PATH & "\sounds"
Public Shared ReadOnly UNIPACK_KEYSOUND_PATH As String = UNIPACK_PROJECT_PATH & "\keySound"
Public Shared ReadOnly UNIPACK_KEYLED_PATH As String = UNIPACK_PROJECT_PATH & "\keyLED"
#End Region
#Region "About XML (Settings / Version)"
''' <summary>
''' UniConverter 최신 버전.
''' </summary>
Public FileInfo As Version
''' <summary>
''' UniConverter 최신 버전 업데이트 로그.
''' </summary>
Public VerLog As String
''' <summary>
''' Version.XML 파일 분석.
''' </summary>
Public vxml As New XmlDocument
''' <summary>
''' Settings.XML 파일 분석.
''' </summary>
Public setxml As New XmlDocument
''' <summary>
''' settings.xml 중 Convert UniPack 설정.
''' </summary>
Private uni_confile As String
''' <summary>
''' Launchpad Setup Light. [When you connect the Launchpad]
''' </summary>
Private SetUpLight_ As Boolean
#End Region
#Region "UniPack(s)"
''' <summary>
''' LED 다중 매핑 순서. (a b c ...)
''' </summary>
Public Shared LEDMappings As Char() = New Char(25) {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"}
#End Region
#Region "DLL Import Functions"
Declare Function GetDC Lib "user32" Alias "GetDC" (ByVal hwnd As Integer) As Integer
'Declare Function RoundRect Lib "gdi32" Alias "RoundRect" (ByVal hdc As Integer, ByVal x1 As Integer, ByVal y1 As Integer, ByVal x2 As Integer, ByVal y2 As Integer, ByVal x3 As Integer, ByVal y3 As Integer) As Integer
#End Region
#Region "Sophiscated-UI"
Private Shared _pfc As New PrivateFontCollection()
Private Shared _pfcData As IntPtr
Public Shared ReadOnly Property NanumFont As FontFamily
Get
Return _pfc.Families(0)
End Get
End Property
#End Region
''' <summary>
''' 특별 기호 (")
''' </summary>
Public Shared ast As String = Chr(34)
''' <summary>
''' Temp 폴더.
''' </summary>
Public Shared TempDirectory As String = My.Computer.FileSystem.SpecialDirectories.Temp
Private Async Sub MainProject_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Try
ShowIntro()
Dim file_ex As String = Application.StartupPath + "\settings.xml"
If File.Exists(file_ex) = False Then
Throw New FileNotFoundException("Settings File doesn't exists.")
End If
'License File of Developer Mode.
If File.Exists(LicenseFile(0)) AndAlso File.ReadAllText(LicenseFile(0)).GetHashCode = My.Resources.License_DeveloperMode.GetHashCode Then
IsDeveloperMode = True
End If
'License File of Great Exception Mode.
If File.Exists(LicenseFile(1)) AndAlso File.ReadAllText(LicenseFile(1)).GetHashCode = My.Resources.License_GreatExMode.GetHashCode Then
IsGreatExMode = True
End If
If IsDeveloperMode Then
Me.Text &= " (Enabled Developer Mode)"
DeveloperModeToolStripMenuItem.Visible = True
End If
Me.KeyPreview = True
OpenProjectOnce = ProjectOpenMethod.Smart
Await Initialize()
'Text of Info TextBox
infoTB1.Text = "My Amazing UniPack!" 'Title
infoTB2.Text = "UniConverter, " & Environment.MachineName 'Producer Name
setxml.Load(file_ex)
Dim setNode As XmlNode
setNode = setxml.SelectSingleNode("/UniConverter-XML/UniConverter-Settings")
If setNode.ChildNodes(0).InnerText = "True" Then
BGW_CheckUpdate.RunWorkerAsync()
End If
If setNode.ChildNodes(2).InnerText = "True" Then
SetUpLight_ = True
End If
'Translate the Language from "Translator" Class.
Dim Ln As String = setNode.ChildNodes(3).InnerText
Dim tLn As Translator.tL = Translator.GetLnEnum(Ln)
lang = tLn
Select Case tLn
Case Translator.tL.English
Dim culture As CultureInfo = CultureInfo.GetCultureInfo("en-US")
Thread.CurrentThread.CurrentUICulture = culture
My.Resources.Contents.Culture = culture
Case Translator.tL.Korean
Dim culture As CultureInfo = CultureInfo.GetCultureInfo("ko-KR")
Thread.CurrentThread.CurrentUICulture = culture
My.Resources.Contents.Culture = culture
End Select
Dim trn As New Translator(tLn, IsDeveloperMode)
trn.TranslateMain()
'건드리면 IsSaved가 False로 진행되기 때문에 다시 기본값 설정을 해준다!
IsSaved = True
Catch ex As Exception
If IsGreatExMode Then
MessageBox.Show("Error - " & ex.Message & vbNewLine & "Error Message: " & ex.StackTrace, Me.Text & ": Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Else
MessageBox.Show("Error: " & ex.Message, Me.Text & ": Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Application.Exit()
End If
End Try
End Sub
Public Async Function Initialize() As Task
#Region "변수 기본값 설정"
abl_openedproj = False
abl_openedsnd = False
abl_openedled = False
IsSaved = True
SoundIsSaved = False
keyLEDIsSaved = False
infoIsSaved = False
IsUpdated = False
IsWorking = False
ks_Converted = False
kl_Converted = False
UniPack_Title = String.Empty
UniPack_ProducerName = String.Empty
UniPack_Chains = 1
keyLEDMIDEX_LEDViewMode.Checked = True
'keyLEDPad_Flush(False)
btnKeySound_AutoConvert.Enabled = False
keyLEDMIDEX_BetaButton.Enabled = False
btnConvertKeyLEDAutomatically.Enabled = False
#End Region
Await Task.Run(Sub() 'Workspace의 UniPack 폴더 정리.
DeleteWorkspaceDir()
End Sub)
InitializeNanumFont()
ApplyNanumFont(Me)
End Function
''' <summary>
''' MainScreen을 보여줄 인트로 구성 함수입니다.
''' </summary>
Public Sub ShowIntro()
Thread.Sleep(1000) '오류 대비
MainScreen.ShowFormSmoothly()
Thread.Sleep(5300)
MainScreen.CloseFormSmoothly()
End Sub
Private Sub InitializeNanumFont()
Dim fontLength = My.Resources.NanumBarunGothic.Length
Dim fontData = My.Resources.NanumBarunGothic
_pfcData = Marshal.AllocCoTaskMem(fontLength)
Marshal.Copy(fontData, 0, _pfcData, fontLength)
_pfc.AddMemoryFont(_pfcData, fontLength)
End Sub
Public Shared Function GetNanumFont(fontSize As Single) As Font
Return New Font(NanumFont, fontSize)
End Function
Public Shared Sub ApplyNanumFont(parent As Control)
Dim controls = GetAllChildControls(parent)
For Each child In controls
child.Font = GetNanumFont(child.Font.Size)
Next
End Sub
Public Shared Function GetAllChildControls(_control As Control, _type As Type) As IEnumerable(Of Control)
Dim controls = _control.Controls.Cast(Of Control)()
Return controls.SelectMany(Function(ctrl) GetAllChildControls(ctrl, _type)).Concat(controls).Where(Function(c) c.GetType() = _type)
End Function
Public Shared Function GetAllChildControls(_control As Control) As IEnumerable(Of Control)
Dim controls = _control.Controls.Cast(Of Control)()
Return controls.SelectMany(Function(ctrl) GetAllChildControls(ctrl)).Concat(controls)
End Function
Private Sub InfoToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles InfoToolStripMenuItem.Click
Info.Show()
End Sub
Public Sub DeleteWorkspaceDir()
If Directory.Exists(Application.StartupPath & "\Workspace") Then
Directory.Delete(Application.StartupPath & "\Workspace", True)
Directory.CreateDirectory(Application.StartupPath & "\Workspace")
Else
Directory.CreateDirectory(Application.StartupPath & "\Workspace")
End If
End Sub
Private Async Sub OpenSoundsToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles SoundsToolStripMenuItem.Click
Dim ofd As New OpenFileDialog()
ofd.Filter = My.Resources.Contents.Sound_ofd_Filter
ofd.Title = My.Resources.Contents.Sound_ofd_Title
ofd.Multiselect = True
If ofd.ShowDialog() = DialogResult.OK Then
Await Task.Run(Sub()
OpenSounds(ofd.FileNames, True)
End Sub)
End If
End Sub
#Region "Smart Invoke Function"
Public Sub UI(ByVal uiUpdate As Action)
If InvokeRequired Then
Try
Invoke(DirectCast(Sub() uiUpdate(), MethodInvoker))
Catch ex As Exception
' The try catch block here is here because the end user (you) may decide to close the form without closing the server first,
' and that may cause an ObjectDesposed access exception. I think we'd all rather not see that.
End Try
Else
Try
uiUpdate()
Catch ex As Exception
' The try catch block here is here because the end user (you) may decide to close the form without closing the server first,
' and that may cause an ObjectDesposed access exception. I think we'd all rather not see that.
End Try
End If
End Sub
#End Region
Private Sub TutorialsToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles TutorialsToolStripMenuItem.Click
Tutorials.Show()
End Sub
Private Sub SaveProjectToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles SaveProjectToolStripMenuItem.Click
Task.Run(Sub()
SaveProject(True)
End Sub)
End Sub
''' <summary>
''' URL 내용을 문자열로 나타냅니다. (Get Text from site.)
''' </summary>
''' <param name="URL">사이트 url.</param>
''' <returns></returns>
Public Function ReadURLString(URL As String) As String
Try
Dim client As WebClient = New WebClient()
Dim reader As StreamReader = New StreamReader(client.OpenRead(URL))
Dim returnstr As String = reader.ReadToEnd()
Return returnstr
Catch ex As Exception
If IsGreatExMode Then
MessageBox.Show("Error - " & ex.Message & vbNewLine & "Error Message: " & ex.StackTrace, Me.Text & ": Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Else
MessageBox.Show("Error: " & ex.Message, Me.Text & ": Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
Return String.Empty
End Try
End Function
Public Function roundRect(ByVal Rc As Rectangle, ByVal Rnd As Integer) As GraphicsPath
Dim path As New GraphicsPath
path.AddArc(Rc.X, Rc.Y, Rnd, Rnd, -180, 90)
path.AddLine(Rc.X + (Rnd \ 2), Rc.Y, Rc.X + Rc.Width - (Rnd \ 2), Rc.Y)
path.AddArc(Rc.X + Rc.Width - Rnd, Rc.Y, Rnd, Rnd, -90, 90)
path.AddLine(Rc.X + Rc.Width, Rc.Y + (Rnd \ 2), Rc.X + Rc.Width, Rc.Y + Rc.Height - (Rnd \ 2))
path.AddArc(Rc.X + Rc.Width - Rnd, Rc.Y + Rc.Height - Rnd, Rnd, Rnd, 0, 90)
path.AddLine(Rc.X + (Rnd \ 2), Rc.Y + Rc.Height, Rc.X + Rc.Width - (Rnd \ 2), Rc.Y + Rc.Height)
path.AddArc(Rc.X, Rc.Y + Rc.Height - Rnd, Rnd, Rnd, 90, 90)
path.AddLine(Rc.X, Rc.Y + (Rnd \ 2), Rc.X, Rc.Y + Rc.Height - (Rnd \ 2))
Return path
End Function
Public Function roundRect(ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer, ByVal Rnd As Integer) As GraphicsPath
Dim path As New GraphicsPath
path.AddArc(x, y, Rnd, Rnd, -180, 90)
path.AddLine(x + (Rnd \ 2), y, x + width - (Rnd \ 2), y)
path.AddArc(x + width - Rnd, y, Rnd, Rnd, -90, 90)
path.AddLine(x + width, y + (Rnd \ 2), x + width, y + height - (Rnd \ 2))
path.AddArc(x + width - Rnd, y + height - Rnd, Rnd, Rnd, 0, 90)
path.AddLine(x + (Rnd \ 2), y + height, x + width - (Rnd \ 2), y + height)
path.AddArc(x, y + height - Rnd, Rnd, Rnd, 90, 90)
path.AddLine(x, y + (Rnd \ 2), x, y + height - (Rnd \ 2))
Return path
End Function
Private Sub OpenKeyLED(fileNames As String(), showLoadingMessage As Boolean)
If fileNames.Length > 0 Then
If showLoadingMessage Then
Invoke(Sub()
Loading.Show()
Loading.DPr.Maximum = fileNames.Length
Loading.Text = My.Resources.Contents.LED_Open_Title
Loading.DLb.Text = String.Format(My.Resources.Contents.LED_Open, 0, fileNames.Length)
End Sub)
End If
If Directory.Exists(ABLETON_KEYLED_PATH) Then
Directory.Delete(ABLETON_KEYLED_PATH, True)
End If
Directory.CreateDirectory(ABLETON_KEYLED_PATH)
For i = 0 To fileNames.Length - 1
Dim fileName As String = fileNames(i)
File.Copy(fileName, Path.Combine(ABLETON_KEYLED_PATH, Path.GetFileName(fileName)), True)
If showLoadingMessage Then
Invoke(Sub()
Loading.DPr.Style = ProgressBarStyle.Continuous
Loading.DPr.Value += 1
Loading.DLb.Text = String.Format(My.Resources.Contents.LED_Open, Loading.DPr.Value, fileNames.Length)
End Sub)
End If
Next
If showLoadingMessage Then
Invoke(Sub()
Loading.DPr.Value = Loading.DPr.Maximum
Loading.DPr.Style = ProgressBarStyle.Marquee
Loading.DLb.Text = My.Resources.Contents.LED_Loaded
End Sub)
End If
abl_openedled = True
GetMidiExtensionSaveFile(fileNames)
If showLoadingMessage Then
Invoke(Sub()
Loading.Close()
End Sub)
MessageBox.Show(My.Resources.Contents.LED_Loaded, Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
End If
End Sub
Private Function GetMidiExtensionSaveFile(ledFilePath As String()) As Boolean
Try
_midiExtensionMapping.Clear()
Dim pathList As New List(Of String)
Dim saveFilePath As String = String.Empty
Dim saveFileFound As Boolean = False
For Each led In ledFilePath
Dim parentPath As String = Directory.GetParent(led).FullName
If Not pathList.Contains(parentPath) Then
For Each x In Directory.GetFiles(parentPath, "*.*", SearchOption.AllDirectories)
Dim fileName As String = Path.GetFileName(x)
If fileName.ToLower().Contains("save") AndAlso Not Path.HasExtension(x) Then
saveFilePath = x
saveFileFound = True
Exit For
End If
Next
If saveFileFound Then
Exit For
End If
pathList.Add(parentPath)
End If
Next
If saveFileFound AndAlso Not String.IsNullOrWhiteSpace(saveFilePath) Then
_midiExtensionMapping = GetMappingListForMidiExtension(saveFilePath)
End If
Catch ex As Exception
If IsGreatExMode Then
MessageBox.Show("Error - " & ex.Message & vbNewLine & "Error Message: " & ex.StackTrace, Me.Text & ": Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Else
MessageBox.Show("Error: " & ex.Message, Me.Text & ": Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
End Try
Return _midiExtensionMapping.Count > 0
End Function
Public Sub ExtractGZip(gzipFileName As String, targetDir As String)
'---Beta Code: Extract GZip to Original File---
' Use a 4K buffer. Any larger is a waste.
Dim dataBuffer As Byte() = New Byte(4095) {}
Using fs As Stream = New FileStream(gzipFileName, FileMode.Open, FileAccess.Read)
Using gzipStream As New GZipInputStream(fs)
' Change this to your needs
Dim fnOut As String = Path.Combine(targetDir, Path.GetFileNameWithoutExtension(gzipFileName))
Using fsOut As FileStream = File.Create(fnOut)
StreamUtils.Copy(gzipStream, fsOut, dataBuffer)
End Using
End Using
End Using
End Sub
''' <summary>
''' 체인 값을 가져옵니다.
''' </summary>
''' <param name="xmlPath">에이블톤 프로젝트 XML 경로</param>
''' <returns></returns>
Public Shared Function GetChainFromAbletonProject(xmlPath As String) As Integer
Dim doc As New XmlDocument
doc.Load(xmlPath)
Dim chain = 1
'LED
Dim ledNodes As XmlNodeList = doc.GetElementsByTagName("MidiEffectBranch")
Dim ledNodeList As List(Of XmlNode) = ledNodes.Cast(Of XmlNode).ToList()
Dim chainList As List(Of Integer) = ledNodeList.Select(Function(x) Integer.Parse(x.Item("BranchSelectorRange").Item("Max").GetAttribute("Value")) + 1).ToList()
Dim sortedChainList As List(Of Integer) = chainList.OrderByDescending(Function(x) x).ToList()
If sortedChainList.Count > 0 Then
Dim maxChain As Integer = sortedChainList.First()
ledNodeList.Clear()
chainList.Clear()
sortedChainList.Clear()
If maxChain >= 1 AndAlso maxChain <= 8 Then
chain = maxChain
ElseIf maxChain > 8 Then
chain = 8
End If '최대 체인이 1보다 작은 경우는 이미 chain이 1이므로 생략
End If
Return chain
End Function
''' <summary>
''' 에이블톤 프로젝트 파일을 불러옵니다.
''' </summary>
''' <param name="fileName">에이블톤 프로젝트 파일 경로</param>
''' <param name="showLoadingMessage">불러오는 중 메시지의 존재 여부</param>
Private Sub OpenAbletonProjectFile(fileName As String, showLoadingMessage As Boolean)
If String.IsNullOrWhiteSpace(fileName) OrElse Not File.Exists(fileName) Then
Return
End If
If Not Directory.Exists(ABLETON_PROJECT_PATH) Then
Directory.CreateDirectory(ABLETON_PROJECT_PATH)
End If
If showLoadingMessage Then
Invoke(Sub()
Loading.Show()
Loading.DPr.Style = ProgressBarStyle.Marquee
Loading.DPr.MarqueeAnimationSpeed = 10
Loading.Text = My.Resources.Contents.Project_Title
Loading.DLb.Text = My.Resources.Contents.Project_Loading
End Sub)
End If
If showLoadingMessage Then
Invoke(Sub()
Loading.DLb.Text = My.Resources.Contents.Project_DeletingTempoaryFiles
End Sub)
End If
If File.Exists(ABLETON_PROJECT_XML_PATH) Then
File.Delete(ABLETON_PROJECT_XML_PATH)
End If
abl_FileName = fileName
File.Copy(fileName, ABLETON_PROJECT_PATH & "\abl_proj.gz", True)
If showLoadingMessage Then
Invoke(Sub()
Loading.DLb.Text = My.Resources.Contents.Project_Extracting
End Sub)
End If
ExtractGZip(ABLETON_PROJECT_PATH & "\abl_proj.gz", ABLETON_PROJECT_PATH)
If showLoadingMessage Then
Invoke(Sub()
Loading.DLb.Text = My.Resources.Contents.Project_DeletingTempoaryFiles
End Sub)
End If
File.Delete("Workspace\ableproj\abl_proj.gz")
If showLoadingMessage Then
Invoke(Sub()
Loading.DLb.Text = My.Resources.Contents.Project_ChangeExtension
End Sub)
End If
File.Move(ABLETON_PROJECT_PATH & "\abl_proj", ABLETON_PROJECT_XML_PATH)
'Reading Informations of Ableton Project.
'Ableton Project's Name.
If showLoadingMessage Then
Invoke(Sub()
Loading.DLb.Text = My.Resources.Contents.Project_FileName
End Sub)
End If
Dim finalName As String = Path.GetFileNameWithoutExtension(fileName)
'Ableton Project's Chain.
If showLoadingMessage Then
Invoke(Sub()
Loading.DLb.Text = My.Resources.Contents.Project_Chain
End Sub)
End If
'정리.
abl_Name = finalName
abl_Chain = GetChainFromAbletonProject(ABLETON_PROJECT_XML_PATH)
'XML File Load.
If showLoadingMessage Then
Invoke(Sub()
Loading.DLb.Text = My.Resources.Contents.Project_Loading
infoTB1.Text = abl_Name
infoTB3.Text = abl_Chain
End Sub)
End If
abl_openedproj = True
UniPack_SaveInfo(False)
If showLoadingMessage Then
Invoke(Sub()
Loading.Close()
End Sub)
MessageBox.Show(My.Resources.Contents.Project_Loaded, Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
End Sub
''' <summary>
''' 자동 변환 (KeySound)/*
''' </summary>
Public Async Function ReadyForAutoConvertForKeySound() As Task
If abl_openedproj AndAlso abl_openedsnd Then
Dim errorMessage As String = Await ReadyForConvertKeySound(True)
If Not String.IsNullOrWhiteSpace(errorMessage) Then
MessageBox.Show(String.Format(My.Resources.Contents.Sound_Converting_Error, errorMessage), Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End If
MessageBox.Show(My.Resources.Contents.KeySound_Created, Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Information)
Else
MessageBox.Show(String.Concat(My.Resources.Contents.Project_Weird_Loaded, " [keySound]"), Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
End Function
Private Async Function ReadyForConvertKeySound(showLoadingMessage As Boolean) As Task(Of String)
Dim errorMessage As New StringBuilder(255)
Dim conversionErrorMessage As String = String.Empty
Dim soundConversion As Task(Of KeySoundStructure()) = Task.Run(Function() As KeySoundStructure()
Return ConvertKeySound_v2(ABLETON_PROJECT_XML_PATH, conversionErrorMessage, True)
End Function)
Dim sounds As KeySoundStructure() = Await soundConversion
If Not String.IsNullOrWhiteSpace(conversionErrorMessage) Then
errorMessage.Append(errorMessage)
End If
Await Task.Run(Sub()
Dim keySound As New StringBuilder(255)
Dim sortedSoundList As New List(Of KeySoundStructure)(sounds)
sortedSoundList = sortedSoundList.OrderBy(Function(x) x.Chain * 100 + x.X * 10 + x.Y).ToList()
Dim trimmedSoundList As List(Of KeySoundStructure) = sortedSoundList.Where(Function(x) x.StartTime <> TimeSpan.Zero OrElse x.EndTime <> TimeSpan.Zero).ToList()
trimmedSoundList = trimmedSoundList.OrderBy(Function(x) Long.Parse($"{Convert.ToInt32(Math.Truncate(x.StartTime.TotalMilliseconds))}{Convert.ToInt32(Math.Truncate(x.EndTime.TotalMilliseconds))}")).ToList()
Dim previousChain = 0
Dim padZeroFormat As String = New String("0"c, trimmedSoundList.Count.ToString().Length)
If showLoadingMessage Then
Invoke(Sub()
Loading.Show()
Loading.Text = My.Resources.Contents.KeySound_Creating_Title
Loading.DLb.Text = String.Format(My.Resources.Contents.Sound_Verifying, 0, trimmedSoundList.Count)
End Sub)
End If
For i = 0 To trimmedSoundList.Count - 1
Dim sound As KeySoundStructure = trimmedSoundList(i)
If Path.GetExtension(sound.FileName) <> ".wav" Then 'mp3 파일은 이미 변환 했으므로
sound.FileName = Path.ChangeExtension(sound.FileName, ".wav")
End If
Dim trimmedSoundFileName As String = $"ucv_ac_ts_{(i + 1).ToString(padZeroFormat)}.wav"
Dim abletonSoundFilePath As String = $"{ABLETON_SOUNDS_PATH}\{sound.FileName}"
Dim trimmedSoundFilePath As String = $"{ABLETON_SOUNDS_PATH}\{trimmedSoundFileName}"
Sound_Cutting.TrimWavFile(abletonSoundFilePath, trimmedSoundFilePath, sound.StartTime, sound.EndTime)
sound.FileName = trimmedSoundFileName
If showLoadingMessage Then
Invoke(Sub()
Loading.DLb.Text = String.Format(My.Resources.Contents.Sound_Verifying, i + 1, trimmedSoundList.Count)
End Sub)
End If
Next
If showLoadingMessage Then
Invoke(Sub()
Loading.DLb.Text = String.Format(My.Resources.Contents.Sound_Verifying, 0, sortedSoundList.Count)
End Sub)
End If
For i = 0 To sortedSoundList.Count - 1
Dim sound As KeySoundStructure = sortedSoundList(i)
If Path.GetExtension(sound.FileName) <> ".wav" Then 'mp3 파일은 이미 변환 했으므로
sound.FileName = Path.ChangeExtension(sound.FileName, ".wav")
End If
Dim abletonSoundFilePath As String = $"{ABLETON_SOUNDS_PATH}\{sound.FileName}"
Dim unipackSoundFilePath As String = $"{UNIPACK_SOUNDS_PATH}\{sound.FileName}"
If Not File.Exists(abletonSoundFilePath) Then
errorMessage.Append($"Error occured while converting to keySound: '{sound.FileName}' file doesn't exists.")
Continue For
End If
If Not Directory.Exists(UNIPACK_SOUNDS_PATH) Then
Directory.CreateDirectory(UNIPACK_SOUNDS_PATH)
End If
Dim key As String = sound.ToString()
Debug.WriteLine(key)
If previousChain <> 0 AndAlso previousChain <> sound.Chain Then
keySound.Append(Environment.NewLine)
End If
keySound.Append(key)
keySound.Append(Environment.NewLine)
File.Copy(abletonSoundFilePath, unipackSoundFilePath, True)
previousChain = sound.Chain
If showLoadingMessage Then
Invoke(Sub()
Loading.DLb.Text = String.Format(My.Resources.Contents.KeySound_Creating, i + 1, sortedSoundList.Count)
End Sub)
End If
Next
keySound.Length -= 1
Dim content As String = keySound.ToString()
File.WriteAllText(UNIPACK_KEYSOUND_PATH, content)
'Pad Layout 동기화 (keySound)
End Sub)
If showLoadingMessage Then
Invoke(Sub()
Loading.Close()
End Sub)
End If
Return errorMessage.ToString()
End Function
''' <summary>
''' 자동 변환 (KeyLED MIDEX)
''' </summary>
Public Async Function ReadyForAutoConvertForKeyLED() As Task
If abl_openedproj AndAlso abl_openedled Then
Dim errorMessage As String = Await ReadyForConvertKeyLEDForMIDEX(True)
If Not String.IsNullOrWhiteSpace(errorMessage) Then
MessageBox.Show(String.Format(My.Resources.Contents.LED_Converting_Error, errorMessage), Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End If
MessageBox.Show(My.Resources.Contents.KeyLED_Created, Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Information)
Else
MessageBox.Show(String.Concat(My.Resources.Contents.Project_Weird_Loaded, " [keyLED]"), Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
End Function
Private Async Function ReadyForConvertKeyLEDForMIDEX(showLoadingMessage As Boolean) As Task(Of String)
Dim errorMessage As String = String.Empty
Dim ledConversion As Task(Of KeyLEDStructure()) = Task.Run(Function() As KeyLEDStructure()
Return ConvertKeyLEDForMIDEX_v2(ABLETON_PROJECT_XML_PATH, errorMessage, True)
End Function)
Dim keyLEDs As KeyLEDStructure() = Await ledConversion
If showLoadingMessage Then
Invoke(Sub()
Loading.Show()
Loading.Text = My.Resources.Contents.KeyLED_Creating_Title
Loading.DLb.Text = String.Format(My.Resources.Contents.KeyLED_Creating, 0, keyLEDs.Length)
End Sub)
End If
Await Task.Run(Sub()
For i = 0 To keyLEDs.Length - 1
Dim led As KeyLEDStructure = keyLEDs(i)
SaveKeyLED(led)
If showLoadingMessage Then
Invoke(Sub()
Loading.DLb.Text = String.Format(My.Resources.Contents.KeyLED_Creating, i + 1, keyLEDs.Length)
End Sub)
End If
Next
If showLoadingMessage Then
Invoke(Sub()
Loading.Close()
End Sub)
End If
End Sub)
Return errorMessage
End Function
Private Async Sub OpenAbletonProjectToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles OpenAbletonProjectToolStripMenuItem.Click
Dim alsOpen1 As New OpenFileDialog With {
.Filter = My.Resources.Contents.Project_ofd_Filter,
.Title = My.Resources.Contents.Project_ofd_Title,
.AddExtension = False,
.Multiselect = False
}
If alsOpen1.ShowDialog() = DialogResult.OK Then
Await Task.Run(Sub()
OpenAbletonProjectFile(alsOpen1.FileName, True)
End Sub)
End If
End Sub
Private Async Sub CAOC(sender As Object, e As EventArgs) Handles tsmiCAOC.Click
Try
Await ReadyForAutoConvertForKeySound()
Await ReadyForAutoConvertForKeyLED()
If abl_openedproj AndAlso (abl_openedsnd OrElse abl_openedled) Then
Dim result As DialogResult = MessageBox.Show(My.Resources.Contents.UniPack_Not_Saved, My.Resources.Contents.UniPack_Not_Saved_Title, MessageBoxButtons.YesNo, MessageBoxIcon.Question)
If result = DialogResult.Yes Then
Await Task.Run(Sub()
SaveProject(False)
End Sub)
End If
End If
Catch ex As Exception
If IsGreatExMode Then
MessageBox.Show("Error - " & ex.Message & vbNewLine & "Error Message: " & ex.StackTrace, Me.Text & ": Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Else
MessageBox.Show("Failed to save UniPack." & vbNewLine & "Error: " & ex.Message, Me.Text & ": Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
End Try
End Sub
Private Sub Info_SaveButton_Click(sender As Object, e As EventArgs) Handles Info_SaveButton.Click
Try
UniPack_SaveInfo(True)
Catch ex As Exception
If IsGreatExMode Then
MessageBox.Show("Error - " & ex.Message & vbNewLine & "Error Message: " & ex.StackTrace, Me.Text & ": Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Else
MessageBox.Show("Error: " & ex.Message, Me.Text & ": Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
End Try
End Sub
''' <summary>
''' UniPack의 info 파일을 저장합니다.