-
Notifications
You must be signed in to change notification settings - Fork 199
Expand file tree
/
Copy pathUScreenEditSub.pas
More file actions
6342 lines (5697 loc) · 258 KB
/
Copy pathUScreenEditSub.pas
File metadata and controls
6342 lines (5697 loc) · 258 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
{* UltraStar Deluxe - Karaoke Game
*
* UltraStar Deluxe is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*
* $URL: svn://basisbit@svn.code.sf.net/p/ultrastardx/svn/trunk/src/screens/UScreenEditSub.pas $
* $Id: UScreenEditSub.pas 3103 2014-11-22 23:21:19Z k-m_schindler $
*}
unit UScreenEditSub;
interface
{$IFDEF FPC}
{$MODE Delphi}
{$ENDIF}
{$I switches.inc}
uses
UCommon,
UEditorLyrics,
UFiles,
UFilesystem,
UGraphicClasses,
UIni,
UMain,
UMenu,
UMenuText,
UMusic,
UPath,
URecord,
USong,
USongs,
UTexture,
UThemes,
UTime,
dglOpenGL,
Math,
{$IFDEF UseMIDIPort}
MidiOut,
MidiCons,
{$IFDEF MSWINDOWS}
UMidiInput,
{$ENDIF}
{$ENDIF}
sdl2,
strutils,
SysUtils;
type
TMedleyNotes = record
start: TPos;
end_: TPos;
Preview: TPos;
isStart: boolean; //start beat is declared
isEnd: boolean; //end beat is declared
isCustom: boolean;
end;
TVisibleHeaders = record
Title: UTF8String;
Artist: UTF8String;
Language: UTF8String;
Edition: UTF8String;
Genre: UTF8String;
Year: Integer;
Creator: UTF8String;
Mp3: IPath;
Mp3Id: Integer;
Cover: IPath;
CoverId: Integer;
Background: IPath;
BackgroundId: Integer;
Video: IPath;
VideoId: Integer;
VideoGAP: Real;
BPM: Real;
GAP: Real;
StartTag: Real;
EndTag: longint;
MedleyNotes: TMedleyNotes;
PreviewStart: Real;
Relative: boolean;
end;
TScreenEditSub = class(TMenu)
private
CurrentBeat: Integer;
//Variable is True if no Song is loaded
Error: boolean;
TextNote: Integer;
TextSentence: Integer;
TextInfo: Integer;
CurrentNote: array[0..1] of Integer;
PlaySentence: boolean;
PlayOne: boolean;
PlayOneMidi: boolean;
PlaySentenceMidi: boolean;
midinotefound: boolean; // if one note was found
PlayVideo: boolean;
PlayStopTime: real;
LastClick: Integer;
Click: boolean;
CopySrc: TPos;
{$IFDEF UseMIDIPort}
MidiOut: TMidiOutput;
MidiStart: real;
MidiStop: real;
MidiTime: real;
MidiPos: real;
MidiLastNote: Integer;
MidiLastLine: Integer;
MidiLastTrack: Integer;
MidiLastPitch: Integer;
EditorMidiPitchOffset: Integer;
{$ENDIF}
//for mouse move
LastPressedMouseButton: boolean;
LastPressedMouseType: Integer;
PressedNoteId: Integer;
TextPosition: Integer;
TextEditMode: boolean;
TitleEditMode: boolean;
ArtistEditMode: boolean;
LanguageEditMode: boolean;
EditionEditMode: boolean;
GenreEditMode: boolean;
YearEditMode: boolean;
CreatorEditMode: boolean;
P1EditMode: boolean;
P2EditMode: boolean;
BPMEditMode: boolean;
PianoEditMode: boolean;
PianoKeysLow: TPianoKeyArray;
PianoKeysHigh: TPianoKeyArray;
// to interactive divide note
LastClickTime: Integer;
BackupEditText: UTF8String; //backup of current text in text-edit-mode
CurrentEditText: UTF8String; // current edit text
editLengthText: Integer;
CurrentSlideId: Integer;
//title header
TitleSlideId: Integer;
TitleData: Integer;
TitleVal: array of UTF8String;
SlideTitleIndex: Integer;
// artist header
ArtistSlideId: Integer;
ArtistData: Integer;
ArtistVal: array of UTF8String;
SlideArtistIndex: Integer;
// language header
LanguageSlideId: Integer;
LanguageData: Integer;
LanguageVal: array of UTF8String;
SlideLanguageIndex: Integer;
// edition header
EditionSlideId: Integer;
EditionData: Integer;
EditionVal: array of UTF8String;
SlideEditionIndex: Integer;
// genre header
GenreSlideId: Integer;
GenreData: Integer;
GenreVal: array of UTF8String;
SlideGenreIndex: Integer;
// year header
YearSlideId: Integer;
YearData: Integer;
YearVal: array of UTF8String;
SlideYearIndex: Integer;
// creator header
CreatorSlideId: Integer;
CreatorData: Integer;
CreatorVal: array of UTF8String;
SlideCreatorIndex: Integer;
// mp3 header
MP3SlideId: Integer;
MP3Data: Integer;
MP3Val: array of UTF8String;
SlideMP3Index: Integer;
// Cover header
CoverSlideId: Integer;
CoverData: Integer;
CoverVal: array of UTF8String;
SlideCoverIndex: Integer;
// Background header
BackgroundSlideId: Integer;
BackgroundData: Integer;
BackgroundVal: array of UTF8String;
SlideBackgroundIndex: Integer;
// Video header
VideoSlideId: Integer;
VideoData: Integer;
VideoVal: array of UTF8String;
SlideVideoIndex: Integer;
// VideoGap header
VideoGapSlideId: Integer;
VideoGapData: Integer;
VideoGapVal: array of UTF8String;
SlideVideoGapIndex: Integer;
// BPM header
BPMSlideId: Integer;
BPMData: Integer;
BPMVal: array of UTF8String;
SlideBPMIndex: Integer;
// GAP header
GAPSlideId: Integer;
GAPData: Integer;
GAPVal: array of UTF8String;
SlideGAPIndex: Integer;
// StartTag header
StartTagSlideId: Integer;
StartTagData: Integer;
StartTagVal: array of UTF8String;
SlideStartTagIndex: Integer;
// EndTag header
EndTagSlideId: Integer;
EndTagData: Integer;
EndTagVal: array of UTF8String;
SlideEndTagIndex: Integer;
// MedleyStart header
MedleyStartSlideId: Integer;
MedleyStartData: Integer;
MedleyStartVal: array of UTF8String;
SlideMedleyStartIndex: Integer;
// MedleyEnd header
MedleyEndSlideId: Integer;
MedleyEndData: Integer;
MedleyEndVal: array of UTF8String;
SlideMedleyEndIndex: Integer;
// PreviewStart header
PreviewStartSlideId: Integer;
PreviewStartData: Integer;
PreviewStartVal: array of UTF8String;
SlidePreviewStartIndex: Integer;
// Relative header
RelativeSlideId: Integer;
RelativeData: Integer;
RelativeVal: array of UTF8String;
SlideRelativeIndex: Integer;
// Start header
StartSlideId: Integer;
StartData: Integer;
StartVal: array of UTF8String;
SlideStartIndex: Integer;
// Duration header
DurationSlideId: Integer;
DurationData: Integer;
DurationVal: array of UTF8String;
SlideDurationIndex: Integer;
// Tone header
ToneSlideId: Integer;
ToneData: Integer;
ToneVal: array of UTF8String;
SlideToneIndex: Integer;
// Text header
LyricSlideId: Integer;
LyricData: Integer;
LyricVal: array of UTF8String;
SlideLyricIndex: Integer;
// Volume Slide
VolumeAudioSlideId: Integer;
VolumeMidiSlideId: Integer;
VolumeClickSlideId: Integer;
VolumeAudioIndex: Integer;
VolumeMidiIndex: Integer;
VolumeClickIndex: Integer; //for update slide
VolumeDragSlideId: Integer;
VolumeAudio: array of UTF8String;
VolumeMidi: array of UTF8String;
VolumeClick: array of UTF8String;
// control buttons
UndoButtonId: Integer;
PreviousSeqButtonID: Integer;
NextSeqButtonID: Integer;
FreestyleButtonID: Integer;
GoldButtonID: Integer;
PlayOnlyButtonID: Integer;
PlayWithNoteButtonID: Integer;
PlayNoteButtonID: Integer;
// background image & video preview
BackgroundImageId: Integer;
//NotesBackgroundId: Integer;
// player static picture
playerIconId: array[1..2] of Integer;
// currentX, CurrentY
CurrentX: Integer;
CurrentY: Integer;
LastX: Integer;
LastY: Integer;
Xmouse: Integer;
ResizeNoteLeft: boolean;
ResizeNoteRight: boolean;
MoveNote: boolean;
CurrentTrack: Integer; // 0 or 1 (for duets)
EditorLyrics: array[0..1] of TEditorLyrics;
//undo declaration
UndoLines: array of array of TLines;
UndoStateNote: array of array of Integer; //UNDO: note's position
CurrentUndoLines: Integer;
UndoHeader: array of TVisibleHeaders;
//video view
fCurrentVideo: IVideo;
//singtrack
CurrentSound: TCaptureBuffer;
// Interactive note
InteractiveNoteId: array of Integer;
TransparentNoteButtonId: array of Integer;
// Interactive Line bar
InteractiveLineId: array of Integer;
TransparentLineButtonId: array of Integer;
{$IFDEF UseMIDIPort}
PlayMidi: boolean;
{$ENDIF}// Midi
// medley
MedleyNotes: TMedleyNotes;
procedure ChangeBPM(newBPM: real);
procedure HandleSaveSong(SDL_ModState: word);
procedure SetPreviewStart(SDL_ModState: word);
procedure SetMedleyTags(SDL_ModState: word);
procedure Jump(SDL_ModState: word);
procedure ReloadSong(SDL_ModState: word);
procedure HandleDivideBPM(SDL_ModState: word);
procedure HandleMultiplyBPM(SDL_ModState: word);
procedure HandleVideo(SDL_ModState: word);
procedure HandlePaste(SDL_ModState: word);
procedure HandleFixTimings(SDL_ModState: word);
procedure HandleBPMIncrease(SDL_ModState: word);
procedure HandleBPMDecrease(SDL_ModState: word);
procedure HandleExtendedCopyPaste(SDL_ModState: word; PressedKey: Integer);
procedure HandleMoveTextRight(SDL_ModState: word);
procedure HandleMoveRight(SDL_ModState: word);
procedure HandleMoveLeft(SDL_ModState: word);
procedure HandleDownKey(SDL_ModState: word);
procedure HandleUpKey(SDL_ModState: word);
procedure EnterTextEditMode(SDL_ModState: word);
procedure EnterBPMEditMode(SDL_ModState: word);
procedure EnterPianoEditMode(SDL_ModState: word);
procedure ToggleTextEditMode(SDL_ModState: word);
procedure HandlePlaySentence(SDL_ModState: word);
procedure PlayNote(SDL_ModState: word);
procedure IncreaseNoteLength(SDL_ModState: word);
procedure CapitalizeLyrics(SDL_ModState: word);
procedure Undo(SDL_ModState: word);
procedure LeaveScope(SDL_ModState: word);
procedure IncreaseAllNoteTones(SDL_ModState: word);
procedure DecreaseAllNoteTones(SDL_ModState: word);
procedure DivideOrJoinNotes(SDL_ModState: word);
procedure DeleteNotes(SDL_ModState: word);
procedure IncreaseGAP(SDL_ModState: word);
procedure DecreaseGAP(SDL_ModState: word);
procedure DecreaseVideoGap(SDL_ModState: word);
procedure IncreaseVideoGap(SDL_ModState: word);
procedure SetFreestyleNote(SDL_ModState: word);
procedure SetGoldenNote(SDL_ModState: word);
procedure ShowPopupHelp(SDL_ModState: word);
procedure ToggleDuet(SDL_ModState: word);
procedure DivideBPM;
procedure MultiplyBPM;
procedure LyricsCapitalize;
procedure LyricsCorrectSpaces(TrackFilter: Integer = -1; LineFilter: Integer = -1);
procedure FixTimings;
procedure DivideSentence;
procedure JoinSentence;
procedure NextSentence;
procedure PreviousSentence;
procedure DivideNote(doubleclick: boolean);
procedure DeleteNote;
procedure OnMidiNote(Note: Byte);
procedure DeleteSentence;
procedure TransposeNote(Transpose: Integer);
procedure UpdateLineBaseNote(const TrackIndex, LineIndex: Integer);
procedure ChangeWholeTone(Tone: Integer);
procedure MoveAllToEnd(Move: Integer);
procedure MoveTextToRight;
procedure MarkCopySrc;
procedure CopySentence(SrcTrack, SrcLine, DstTrack, DstLine: Integer; CopyText: boolean = true; CopyNotes: boolean = true; EnforceSrcLength: boolean = false);
procedure CopySentences(SrcTrack, SrcLine, DstTrack, DstLine, Num: Integer);
procedure MakeSolo;
procedure MakeDuet;
function DuetCopyLine: boolean;
function DuetMoveLine: boolean;
procedure CopyLine(SrcTrack, SrcLine, DstTrack, DstLine: Integer);
function CheckTimingSyntaxErrors(out ErrorMessages: UTF8String): boolean;
function SaveSongToFile(const SaveRelative: boolean): boolean;
procedure Refresh;
procedure CopyToUndo; //copy current lines, mouse position and headers
procedure CopyFromUndo; //undo last lines, mouse position and headers
procedure DrawPlayerTrack(CurrentTone: Integer; Count: Integer; CurrentNote: Integer);
procedure DrawInfoBar(X, Y, W, H: Integer; ColR, ColG, ColB, Alpha: real; Track: Integer);
procedure DrawText(X, Y, W, H: real; Track: Integer; NumLines: Integer = 10);
//video view
procedure StartVideoPreview();
procedure StopVideoPreview();
procedure UpdateVideoPosition(NewPosition: real);
//Note Name Mod
function GetNoteName(Note: Integer): string;
// show transparent background note for interactions
procedure ShowInteractiveBackground;
function GetMedleyLength: real; //if available returns the length of the medley in seconds, otherwise 0
procedure SyncVolumeSlidersFromIni;
{$IFDEF UseMIDIPort}
procedure ResetMidiLastNote;
procedure ReleaseMidiLastNote;
procedure StopMidiPlayback;
procedure UpdateMidiPitchOffset;
function GetMidiPitch(NoteTone: Integer): Byte;
{$ENDIF}
public
Tex_PrevBackground: TTexture;
FadeOut: boolean;
constructor Create; override;
destructor Destroy; override;
procedure OnShow; override;
function ParseInput(PressedKey: cardinal; CharCode: UCS4Char; PressedDown: boolean): boolean; override;
function ParseInputEditText(PressedKey: cardinal; CharCode: UCS4Char; PressedDown: boolean): boolean;
function ParseInputEditBPM(PressedKey: cardinal; CharCode: UCS4Char; PressedDown: boolean): boolean;
function ParseInputEditPiano(PressedKey: cardinal; CharCode: UCS4Char; PressedDown: boolean): boolean;
procedure ApplyTone(NewTone: Integer);
function ParseMouse(MouseButton: Integer; BtnDown: boolean; X, Y: Integer): boolean; override;
function Draw: boolean; override;
procedure OnHide; override;
end;
const
ID='ID_064'; //for help system
implementation
uses
UDisplay,
UDraw,
UGraphic,
UHelp,
ULanguage,
ULog,
UMenuInteract,
UNote,
USkins,
UTextEncoding,
UUnicodeUtils,
TextGL;
const
DEFAULT_FADE_IN_TIME = 8; //TODO in INI
DEFAULT_FADE_OUT_TIME = 2;
NOT_SET = '-';
NotesSkipX: Integer = 20;
LineSpacing: Integer = 15;
EditorMidiToneOffset = 60;
EditorMidiMinPitch = 0;
EditorMidiMaxPitch = 127;
EditorMidiVocalLow = 36;
EditorMidiVocalHigh = 96;
procedure OnSaveEncodingError(Value: boolean; Data: Pointer);
var
SResult: TSaveSongResult;
FilePath: IPath;
Success: boolean;
begin
Success := false;
if (Value) then
begin
CurrentSong.Encoding := encUTF8;
FilePath := CurrentSong.Path.Append(CurrentSong.FileName);
// create backup file
FilePath.CopyFile(Path(FilePath.ToUTF8 + '.ansi.bak'), false);
// store in UTF-8 encoding
SResult := SaveSong(CurrentSong, CurrentSong.Tracks, FilePath, boolean(Data));
Success := (SResult = ssrOK);
end;
if (Success) then
ScreenPopupInfo.ShowPopup(Language.Translate('INFO_FILE_SAVED'))
else
ScreenPopupError.ShowPopup(Language.Translate('ERROR_SAVE_FILE_FAILED'));
end;
procedure OnExit(Value: boolean; Data: Pointer);
begin
Display.CheckOK := Value;
if (Value) then
begin
Display.CheckOK := false;
AudioPlayback.Stop;
Display.FadeTo(@ScreenSong);
end;
end;
// Method for input parsing. If false is returned, GetNextWindow
// should be checked to know the next window to load;
function TScreenEditSub.ParseInput(PressedKey: cardinal; CharCode: UCS4Char; PressedDown: boolean): boolean;
var
SDL_ModState: word;
begin
Result := true;
SDL_ModState := SDL_GetModState and (KMOD_LSHIFT + KMOD_RSHIFT
+ KMOD_LCTRL + KMOD_RCTRL + KMOD_LALT + KMOD_RALT {+ KMOD_CAPS});
{$IFDEF UseMIDIPort}
if PressedDown and
not ((((PressedKey = SDLK_LEFT) or (PressedKey = SDLK_RIGHT)) and (SDL_ModState = 0)) or
(PressedKey = SDLK_SPACE)) then
StopMidiPlayback;
{$ENDIF}
if PianoEditMode then
begin
Result := ParseInputEditPiano(PressedKey, CharCode, PressedDown);
if (Result = true) then
begin
Exit;
end;
if (PressedKey = SDLK_RETURN) then
begin
PressedKey := SDLK_P;
end;
Result := true;
end;
if TextEditMode or
TitleEditMode or
ArtistEditMode or
LanguageEditMode or
EditionEditMode or
GenreEditMode or
YearEditMode or
CreatorEditMode or
P1EditMode or
P2EditMode then
begin
Result := ParseInputEditText(PressedKey, CharCode, PressedDown);
end
else if BPMEditMode then
begin
Result := ParseInputEditBPM(PressedKey, CharCode, PressedDown)
end
else
begin
if (PressedDown) then // Key Down
begin
// check normal keys
case PressedKey of
SDLK_Q: Result := false;
SDLK_S: HandleSaveSong(SDL_ModState);
SDLK_I: SetPreviewStart(SDL_ModState);
SDLK_A: SetMedleyTags(SDL_ModState);
SDLK_J: Jump(SDL_ModState);
SDLK_R: ReloadSong(SDL_ModState);
SDLK_D:
begin
if (SDL_ModState = KMOD_LSHIFT) then HandleDivideBPM(SDL_ModState);
if (SDL_ModState = KMOD_LCTRL or KMOD_LSHIFT) then ToggleDuet(SDL_ModState);
end;
SDLK_M: HandleMultiplyBPM(SDL_ModState);
SDLK_C: CapitalizeLyrics(SDL_ModState);
SDLK_V:
if (SDL_ModState = 0) or (SDL_ModState = KMOD_LALT) then HandleVideo(SDL_ModState)
else HandlePaste(SDL_ModState);
SDLK_T: HandleFixTimings(SDL_ModState);
SDLK_P: HandlePlaySentence(SDL_ModState);
SDLK_G: SetGoldenNote(SDL_ModState);
SDLK_F: SetFreestyleNote(SDL_ModState);
SDLK_Z: Undo(SDL_ModState);
SDLK_ESCAPE: LeaveScope(SDL_ModState);
SDLK_TAB: ShowPopupHelp(SDL_ModState);
SDLK_BACKQUOTE: IncreaseNoteLength(SDL_ModState);
SDLK_EQUALS, // for keyboards which produce the EQUALS symbol without SHIFT modifier
SDLK_PLUS: HandleBPMIncrease(SDL_ModState); // for keyboards which produce the PLUS symbol without SHIFT modifier
SDLK_MINUS: HandleBPMDecrease(SDL_ModState);
SDLK_2, SDLK_3, SDLK_4, SDLK_5, SDLK_6: HandleExtendedCopyPaste(SDL_ModState, PressedKey);
SDLK_7: DecreaseVideoGap(SDL_ModState);
SDLK_8: IncreaseVideoGap(SDL_ModState);
SDLK_9: DecreaseGAP(SDL_ModState);
SDLK_0: IncreaseGAP(SDL_ModState);
SDLK_KP_PLUS: IncreaseAllNoteTones(SDL_ModState);
SDLK_KP_MINUS: DecreaseAllNoteTones(SDL_ModState);
SDLK_SLASH, SDLK_HASH, SDLK_KP_DIVIDE: DivideOrJoinNotes(SDL_ModState);
SDLK_F4: EnterTextEditMode(SDL_ModState);
SDLK_F5: EnterBPMEditMode(SDL_ModState);
SDLK_F6: EnterPianoEditMode(SDL_ModState);
SDLK_SPACE: PlayNote(SDL_ModState);
SDLK_RETURN: ToggleTextEditMode(SDL_ModState);
SDLK_DELETE: DeleteNotes(SDL_ModState);
SDLK_PERIOD: HandleMoveTextRight(SDL_ModState);
SDLK_RIGHT: HandleMoveRight(SDL_ModState);
SDLK_LEFT: HandleMoveLeft(SDL_ModState);
SDLK_DOWN: HandleDownKey(SDL_ModState);
SDLK_UP: HandleUpKey(SDL_ModState);
end; // case
end;
end; // if
end;
// SDLK_S: HandleSaveSong
procedure TScreenEditSub.HandleSaveSong(SDL_ModState: word);
var
TimingErrors: UTF8String;
begin
// run timing checks before saving and abort on serious problems
if CheckTimingSyntaxErrors(TimingErrors) then
begin
if TimingErrors <> '' then
ScreenPopupError.ShowPopup(TimingErrors);
Exit;
end;
SaveSongToFile(SDL_ModState = KMOD_LSHIFT);
end;
// SDLK_I: SetPreviewStart
procedure TScreenEditSub.SetPreviewStart(SDL_ModState: word);
// set PreviewStart tag
var
LineIndex: Integer;
begin
CopyToUndo;
if SDL_ModState and KMOD_SHIFT <> 0 then
begin
if (CurrentSong.HasPreview) and
(CurrentTrack = MedleyNotes.Preview.track) and
(CurrentSong.Tracks[CurrentTrack].CurrentLine = MedleyNotes.Preview.line) and
(CurrentNote[CurrentTrack] = MedleyNotes.Preview.note) and
(CurrentSong.Tracks[CurrentTrack].Lines[CurrentSong.Tracks[CurrentTrack].CurrentLine].Notes[CurrentNote[CurrentTrack]].IsStartPreview) then
begin
CurrentSong.Tracks[CurrentTrack].Lines[CurrentSong.Tracks[CurrentTrack].CurrentLine].Notes[CurrentNote[CurrentTrack]].IsStartPreview := false;
CurrentSong.PreviewStart := 0;
CurrentSong.HasPreview := false;
Text[TextInfo].Text := Language.Translate('EDIT_INFO_PREVIEW_CLEARED');
end
else
begin
// clear old IsStartPreview flag
CurrentSong.Tracks[MedleyNotes.Preview.track].Lines[MedleyNotes.Preview.line].Notes[MedleyNotes.Preview.note].IsStartPreview := false;
// set preview start
CurrentSong.PreviewStart := Round(GetTimeFromBeat(CurrentSong.Tracks[CurrentTrack].Lines[CurrentSong.Tracks[CurrentTrack].CurrentLine].Notes[CurrentNote[CurrentTrack]].StartBeat) * 100) / 100;
CurrentSong.HasPreview := CurrentSong.PreviewStart >= 0.0;
if (CurrentSong.HasPreview) then
begin
MedleyNotes.Preview.track := CurrentTrack;
MedleyNotes.Preview.line := CurrentSong.Tracks[CurrentTrack].CurrentLine;
MedleyNotes.Preview.note := CurrentNote[CurrentTrack];
CurrentSong.Tracks[MedleyNotes.Preview.track].Lines[MedleyNotes.Preview.line].Notes[MedleyNotes.Preview.note].IsStartPreview := true;
Text[TextInfo].Text := Format(Language.Translate('EDIT_INFO_PREVIEW_SET'), [CurrentSong.PreviewStart]);
end
else
begin
CurrentSong.Tracks[CurrentTrack].Lines[CurrentSong.Tracks[CurrentTrack].CurrentLine].Notes[CurrentNote[CurrentTrack]].IsStartPreview := false;
end;
end;
end
else if InRange(CurrentSong.PreviewStart, 0.0, AudioPlayback.Length) then
begin
if SDL_ModState = KMOD_LALT then
begin // jump and play
// simulate sentence switch to clear props
PreviousSentence;
CurrentSong.Tracks[CurrentTrack].CurrentLine := 0; // update lyric
Text[TextInfo].Text := Language.Translate('EDIT_INFO_JUMPTO_PREVIEW_AND_PLAY') + ' (' + FloatToStr(CurrentSong.PreviewStart) + ' s)';
PlayStopTime := AudioPlayback.Length;
PlaySentence := true;
Click := false;
AudioPlayback.Position := CurrentSong.PreviewStart;
AudioPlayback.Play;
// play video in sync if visible
if (fCurrentVideo <> nil) then UpdateVideoPosition(AudioPlayback.Position);
end
else if SDL_ModState = 0 then
begin // jump to preview start
// simulate sentence switch to clear props
PreviousSentence;
CurrentBeat := Floor(GetMidBeat(CurrentSong.PreviewStart - (CurrentSong.GAP) / 1000));
LineIndex := 0;
while (LineIndex <= CurrentSong.Tracks[CurrentTrack].High) and (CurrentBeat > CurrentSong.Tracks[CurrentTrack].Lines[LineIndex].EndBeat) do
Inc(LineIndex);
if LineIndex <= High(CurrentSong.Tracks[CurrentTrack].Lines) then
begin
CurrentSong.Tracks[CurrentTrack].Lines[CurrentSong.Tracks[CurrentTrack].CurrentLine].Notes[CurrentNote[CurrentTrack]].Color := 1;
CurrentSong.Tracks[CurrentTrack].CurrentLine := LineIndex;
// finding the right note
CurrentNote[CurrentTrack] := 0;
while (CurrentNote[CurrentTrack] <= CurrentSong.Tracks[CurrentTrack].Lines[LineIndex].HighNote) and (CurrentBeat > CurrentSong.Tracks[CurrentTrack].Lines[LineIndex].Notes[CurrentNote[CurrentTrack]].EndBeat) do
Inc(CurrentNote[CurrentTrack]);
CurrentSong.Tracks[CurrentTrack].Lines[CurrentSong.Tracks[CurrentTrack].CurrentLine].Notes[CurrentNote[CurrentTrack]].Color := P1_INVERTED;
EditorLyrics[CurrentTrack].AddLine(CurrentTrack, CurrentSong.Tracks[CurrentTrack].CurrentLine);
EditorLyrics[CurrentTrack].Selected := 0;
Text[TextInfo].Text := Language.Translate('EDIT_INFO_JUMPTO_PREVIEW') + ' (' + FloatToStr(CurrentSong.PreviewStart) + ' s)';
end;
end;
end
else Text[TextInfo].Text := Language.Translate('EDIT_INFO_NO_PREVIEW');
Exit;
end;
// SDLK_A: SetMedleyTags
procedure TScreenEditSub.SetMedleyTags(SDL_ModState: word);
// set Medley tags
begin
CopyToUndo;
if CurrentSong.Relative then
begin
Text[TextInfo].Text := Language.Translate('EDIT_INFO_MEDLEY_RELATIVE_UNSUPPORTED');
Exit;
end;
if CurrentSong.isDuet then
begin
Text[TextInfo].Text := Language.Translate('EDIT_INFO_MEDLEY_DUET_UNSUPPORTED');
Exit;
end;
MedleyNotes.isCustom := true;
CurrentSong.Medley.Source := msTag;
if SDL_ModState = KMOD_LSHIFT then // medley end note
begin
if MedleyNotes.isEnd then // if end is already set
begin
if (CurrentSong.Tracks[CurrentTrack].CurrentLine = MedleyNotes.end_.line) and (CurrentNote[CurrentTrack] = MedleyNotes.end_.note) then
begin // current note is medley end, so clear it
MedleyNotes.isEnd := false;
CurrentSong.Tracks[CurrentTrack].Lines[CurrentSong.Tracks[CurrentTrack].CurrentLine].Notes[CurrentNote[CurrentTrack]].IsMedley := false;
Text[TextInfo].Text := Language.Translate('EDIT_INFO_MEDLEY_END_CLEARED');
end else // otherwise, clear old medley end flag and set medley end flag to current note
begin
if (MedleyNotes.isStart) and
(MedleyNotes.start.line < CurrentSong.Tracks[CurrentTrack].CurrentLine) then // ensure that medley start is set and is earlier than medley end
begin
CurrentSong.Tracks[CurrentTrack].Lines[CurrentSong.Tracks[CurrentTrack].CurrentLine].Notes[CurrentNote[CurrentTrack]].IsMedley := true;
if (Length(CurrentSong.Tracks[CurrentTrack].Lines) > MedleyNotes.end_.line) and
(Length(CurrentSong.Tracks[CurrentTrack].Lines[MedleyNotes.end_.line].Notes) > MedleyNotes.end_.note) then
CurrentSong.Tracks[CurrentTrack].Lines[MedleyNotes.end_.line].Notes[MedleyNotes.end_.note].IsMedley := false;
MedleyNotes.end_.line := CurrentSong.Tracks[CurrentTrack].CurrentLine;
MedleyNotes.end_.note := CurrentNote[CurrentTrack];
Text[TextInfo].Text := Language.Translate('EDIT_INFO_MEDLEY_END_SET') + ' (' + FloatToStr(GetMedleyLength) + ' s)';
end
else
begin
if (MedleyNotes.isStart) then
Text[TextInfo].Text := Language.Translate('EDIT_INFO_MEDLEY_END_AFTER_MEDLEY_START')
else
Text[TextInfo].Text := Language.Translate('EDIT_INFO_SET_MEDLEY_START_FIRST');
end;
end;
end else // end is not set yet
begin
if (MedleyNotes.isStart) and
(MedleyNotes.start.line < CurrentSong.Tracks[CurrentTrack].CurrentLine) then // ensure that medley start is set and is earlier than medley end
begin
MedleyNotes.isEnd := true;
CurrentSong.Tracks[CurrentTrack].Lines[CurrentSong.Tracks[CurrentTrack].CurrentLine].Notes[CurrentNote[CurrentTrack]].IsMedley := true;
MedleyNotes.end_.line := CurrentSong.Tracks[CurrentTrack].CurrentLine;
MedleyNotes.end_.note := CurrentNote[CurrentTrack];
Text[TextInfo].Text := Language.Translate('EDIT_INFO_MEDLEY_END_SET') + ' (' + FloatToStr(GetMedleyLength) + ' s)';
end
else
begin
if (MedleyNotes.isStart) then
Text[TextInfo].Text := Language.Translate('EDIT_INFO_MEDLEY_END_AFTER_MEDLEY_START')
else
Text[TextInfo].Text := Language.Translate('EDIT_INFO_SET_MEDLEY_START_FIRST');
end;
end;
end else
begin // medley start note
if MedleyNotes.isStart then
begin
if (CurrentSong.Tracks[CurrentTrack].CurrentLine = MedleyNotes.start.line) and (CurrentNote[CurrentTrack] = MedleyNotes.start.note) then
begin
MedleyNotes.isStart := false;
CurrentSong.Tracks[CurrentTrack].Lines[CurrentSong.Tracks[CurrentTrack].CurrentLine].Notes[CurrentNote[CurrentTrack]].IsMedley := false;
Text[TextInfo].Text := Language.Translate('EDIT_INFO_MEDLEY_START_CLEARED');
end else
begin
CurrentSong.Tracks[CurrentTrack].Lines[CurrentSong.Tracks[CurrentTrack].CurrentLine].Notes[CurrentNote[CurrentTrack]].IsMedley := true;
if (Length(CurrentSong.Tracks[CurrentTrack].Lines) > MedleyNotes.start.line) and
(Length(CurrentSong.Tracks[CurrentTrack].Lines[MedleyNotes.start.line].Notes) > MedleyNotes.start.note) then
CurrentSong.Tracks[CurrentTrack].Lines[MedleyNotes.start.line].Notes[MedleyNotes.start.note].IsMedley := false;
MedleyNotes.start.line := CurrentSong.Tracks[CurrentTrack].CurrentLine;
MedleyNotes.start.note := CurrentNote[CurrentTrack];
Text[TextInfo].Text := Language.Translate('EDIT_INFO_MEDLEY_START_SET') + ifthen(MedleyNotes.isEnd, '(' + FloatToStr(GetMedleyLength) + ' s)', '');
end;
end else
begin
CurrentSong.Tracks[CurrentTrack].Lines[CurrentSong.Tracks[CurrentTrack].CurrentLine].Notes[CurrentNote[CurrentTrack]].IsMedley := true;
MedleyNotes.isStart := true;
MedleyNotes.start.line := CurrentSong.Tracks[CurrentTrack].CurrentLine;
MedleyNotes.start.note := CurrentNote[CurrentTrack];
Text[TextInfo].Text := Language.Translate('EDIT_INFO_MEDLEY_START_SET');
end;
end;
Exit;
end;
// SDLK_J: Jump
procedure TScreenEditSub.Jump(SDL_ModState: word);
// jump to Medley tags
var
R: real;
begin
if CurrentSong.Relative then
begin
Text[TextInfo].Text := Language.Translate('EDIT_INFO_MEDLEY_RELATIVE_UNSUPPORTED');
Exit;
end;
if CurrentSong.isDuet then
begin
Text[TextInfo].Text := Language.Translate('EDIT_INFO_MEDLEY_DUET_UNSUPPORTED');
Exit;
end;
//Medley End Note
if (SDL_ModState = KMOD_LSHIFT) then
begin
if (MedleyNotes.IsEnd) then
begin
// simulate sentence switch to clear props
PreviousSentence;
if (Length(CurrentSong.Tracks[CurrentTrack].Lines) > MedleyNotes.end_.line) and
(Length(CurrentSong.Tracks[CurrentTrack].Lines[MedleyNotes.end_.line].Notes) > MedleyNotes.end_.note) then
begin
CurrentSong.Tracks[CurrentTrack].CurrentLine := MedleyNotes.end_.line;
CurrentNote[CurrentTrack] := MedleyNotes.end_.note;
CurrentSong.Tracks[CurrentTrack].Lines[CurrentSong.Tracks[CurrentTrack].CurrentLine].Notes[CurrentNote[CurrentTrack]].Color := P1_INVERTED;
EditorLyrics[CurrentTrack].AddLine(CurrentTrack, CurrentSong.Tracks[CurrentTrack].CurrentLine);
EditorLyrics[CurrentTrack].Selected := 0;
Text[TextInfo].Text := Language.Translate('EDIT_INFO_JUMPTO_MEDLEY_END') + ' (' + Language.Translate('EDIT_DURATION') + ' ' + FloatToStr(GetMedleyLength) + ' s)';
end;
end
else
Text[TextInfo].Text := Language.Translate('EDIT_INFO_NO_MEDLEY_END');
end;
if (SDL_ModState = 0) then
begin
if (MedleyNotes.IsStart) then
begin
// simulate sentence switch to clear props
PreviousSentence;
if (Length(CurrentSong.Tracks[CurrentTrack].Lines)> MedleyNotes.start.line) and
(Length(CurrentSong.Tracks[CurrentTrack].Lines[MedleyNotes.start.line].Notes) > MedleyNotes.start.note) then
begin
CurrentSong.Tracks[CurrentTrack].CurrentLine := MedleyNotes.start.line;
CurrentNote[CurrentTrack] := MedleyNotes.start.note;
CurrentSong.Tracks[CurrentTrack].Lines[CurrentSong.Tracks[CurrentTrack].CurrentLine].Notes[CurrentNote[CurrentTrack]].Color := P1_INVERTED;
EditorLyrics[CurrentTrack].AddLine(CurrentTrack, CurrentSong.Tracks[CurrentTrack].CurrentLine);
EditorLyrics[CurrentTrack].Selected := 0;
Text[TextInfo].Text := Language.Translate('EDIT_INFO_JUMPTO_MEDLEY_START') + ' (' + Language.Translate('EDIT_DURATION') + ' ' + FloatToStr(GetMedleyLength) + ' s)';
end;
end
else
Text[TextInfo].Text := Language.Translate('EDIT_INFO_NO_MEDLEY_START');
end;
if (SDL_ModState = KMOD_LALT) then
begin
Writeln('ALT+J');
// simulate sentence switch to clear props
PreviousSentence;
if (MedleyNotes.isStart and MedleyNotes.isEnd) and
(MedleyNotes.start.line < MedleyNotes.end_.line) and
(Length(CurrentSong.Tracks[CurrentTrack].Lines) > MedleyNotes.end_.line) and
(Length(CurrentSong.Tracks[CurrentTrack].Lines[MedleyNotes.end_.line].Notes) > MedleyNotes.end_.note) and
(Length(CurrentSong.Tracks[CurrentTrack].Lines[MedleyNotes.start.line].Notes) > MedleyNotes.start.note) then
begin
R := GetTimeFromBeat(CurrentSong.Tracks[CurrentTrack].Lines[MedleyNotes.start.line].Notes[MedleyNotes.start.note].StartBeat);
if InRange(R, 0.0, AudioPlayback.Length) then
begin
AudioPlayback.Position:= R;
PlayStopTime := GetTimeFromBeat(
CurrentSong.Tracks[CurrentTrack].Lines[MedleyNotes.end_.line].Notes[MedleyNotes.end_.note].StartBeat +
CurrentSong.Tracks[CurrentTrack].Lines[MedleyNotes.end_.line].Notes[MedleyNotes.end_.note].Duration);
PlaySentence := true;
Click := false;
AudioPlayback.Play;
// play video in sync if visible
if (fCurrentVideo <> nil) then UpdateVideoPosition(AudioPlayback.Position);
Text[TextInfo].Text := Language.Translate('EDIT_INFO_JUMPTO_MEDLEY_AND_PLAY');
end;
end
else
Text[TextInfo].Text := Language.Translate('EDIT_INFO_NO_MEDLEY_SECTION');
end;
Exit;
end;
// SDLK_R: ReloadSong
{$IFDEF UseMIDIPort}
procedure TScreenEditSub.ResetMidiLastNote;
begin
MidiLastTrack := -1;
MidiLastLine := -1;
MidiLastNote := -1;
MidiLastPitch := -1;
end;
procedure TScreenEditSub.UpdateMidiPitchOffset;
var
TrackIndex: Integer;
LineIndex: Integer;
NoteIndex: Integer;
MinTone: Integer;
MaxTone: Integer;
FoundTone: Boolean;
begin
FoundTone := false;
MinTone := High(Integer);
MaxTone := Low(Integer);
for TrackIndex := 0 to High(CurrentSong.Tracks) do
for LineIndex := 0 to High(CurrentSong.Tracks[TrackIndex].Lines) do
for NoteIndex := 0 to CurrentSong.Tracks[TrackIndex].Lines[LineIndex].HighNote do
with CurrentSong.Tracks[TrackIndex].Lines[LineIndex].Notes[NoteIndex] do
begin
FoundTone := true;
if Tone < MinTone then
MinTone := Tone;
if Tone > MaxTone then
MaxTone := Tone;
end;
EditorMidiPitchOffset := EditorMidiToneOffset;
if FoundTone and (MinTone >= EditorMidiMinPitch) and (MaxTone <= EditorMidiMaxPitch) and
((MaxTone + EditorMidiToneOffset > EditorMidiMaxPitch) or
((MinTone >= EditorMidiVocalLow) and (MaxTone <= EditorMidiVocalHigh) and
(MaxTone + EditorMidiToneOffset > EditorMidiVocalHigh))) then
EditorMidiPitchOffset := 0;
end;
function TScreenEditSub.GetMidiPitch(NoteTone: Integer): Byte;
var
Pitch: Integer;
begin
Pitch := NoteTone + EditorMidiPitchOffset;
if Pitch < EditorMidiMinPitch then
Pitch := EditorMidiMinPitch
else if Pitch > EditorMidiMaxPitch then
Pitch := EditorMidiMaxPitch;
Result := Pitch;
end;