-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfrmSTMainWnd.pas
4163 lines (3795 loc) · 143 KB
/
frmSTMainWnd.pas
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
unit frmSTMainWnd;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Menus, Grids, StdCtrls, ComCtrls, ExtCtrls, MMSystem, STSong,
SpecEmu, STPatterns, Buttons, ImgList, PlayerThread, MRUList, RegSettings;
type
TPlaying = (PLAY_SONG, PLAY_PATTERN);
type
TSTMainWnd = class(TForm)
MainMenu1: TMainMenu;
mnuFile: TMenuItem;
mnuFileNew: TMenuItem;
mnuFileOpen: TMenuItem;
mnuFileSave: TMenuItem;
mnuFileSaveAs: TMenuItem;
N1: TMenuItem;
mnuExit: TMenuItem;
mnuPlay: TMenuItem;
mnuPlaySong: TMenuItem;
mnuPlayPattern: TMenuItem;
mnuTools: TMenuItem;
mnuCompile: TMenuItem;
mnuHelp: TMenuItem;
mnuHelpKeys: TMenuItem;
N2: TMenuItem;
mnuAbout: TMenuItem;
dlgSave: TSaveDialog;
dlgOpen: TOpenDialog;
mnuPattern: TMenuItem;
mnuPatternCopy: TMenuItem;
mnuPatternTranspose: TMenuItem;
mnuPlayStop: TMenuItem;
N4: TMenuItem;
mnuPlayToneGen: TMenuItem;
mnuTGSpecialFX: TMenuItem;
mnuTGTheMusicBox: TMenuItem;
pnlPattern: TPanel;
lblPatternNum: TLabel;
lblPatternLen: TLabel;
lblTempo: TLabel;
lblPatternName: TLabel;
lblAutoInc: TLabel;
txtPatternLen: TEdit;
udnPatternLen: TUpDown;
txtPatternNum: TEdit;
udnPatternNum: TUpDown;
txtTempo: TEdit;
udnTempo: TUpDown;
grdPattern: TStringGrid;
txtPatternName: TEdit;
cboAutoInc: TComboBox;
pnlKeys: TPanel;
imgPianoKeys: TImage;
udnOctave: TUpDown;
txtOctave: TEdit;
lblOctave: TLabel;
imgCh1Note: TImage;
imgCh2Note: TImage;
pnlSongInfo: TPanel;
grdSong: TStringGrid;
pbxLoopStart: TPaintBox;
lblSongTitle: TLabel;
txtSongTitle: TEdit;
lblSongAuthor: TLabel;
txtSongAuthor: TEdit;
mnuEdit: TMenuItem;
mnuEditCopy: TMenuItem;
mnuEditPaste: TMenuItem;
N3: TMenuItem;
mnuEditUndo: TMenuItem;
mnuHelpOnline: TMenuItem;
mnuTGMusicStudio: TMenuItem;
N5: TMenuItem;
mnuSongInfo: TMenuItem;
mnuSongTranspose: TMenuItem;
mnuExportWAVFile: TMenuItem;
N7: TMenuItem;
mnuPlayFromCurrent: TMenuItem;
mnuTGPhaser1Digital: TMenuItem;
mnuTGPhaser1Synth: TMenuItem;
pnlPhaser1Ed: TPanel;
lblP1InstrEd: TLabel;
lblP1Instrument: TLabel;
lblP1Mult: TLabel;
Label2: TLabel;
Label3: TLabel;
txtP1Instrument: TEdit;
udnP1Instrument: TUpDown;
txtP1Mult: TEdit;
udnP1Mult: TUpDown;
txtP1Detune: TEdit;
udnP1Detune: TUpDown;
txtP1Phase: TEdit;
udnP1Phase: TUpDown;
N8: TMenuItem;
mnuSong: TMenuItem;
chkP1InstInUse: TCheckBox;
Label1: TLabel;
btnP1Test: TSpeedButton;
pnlToolbar: TPanel;
sbnOpen: TSpeedButton;
sbnSave: TSpeedButton;
sbnNew: TSpeedButton;
sbnCompileSong: TSpeedButton;
sbnPlay: TSpeedButton;
sbnPlayFromCurrent: TSpeedButton;
sbnPlayPattern: TSpeedButton;
sbnStop: TSpeedButton;
cboBeeperEngine: TComboBox;
imlMenus: TImageList;
sbnSongInfo: TSpeedButton;
imgSep1: TImage;
Image1: TImage;
Image2: TImage;
pnlSavageOrnEditor: TPanel;
lblSavageArpEditor: TLabel;
mnuPatternSwapChans: TMenuItem;
mnuPatternAppend: TMenuItem;
N6: TMenuItem;
mnuFileImport: TMenuItem;
mnuImportVTIIText: TMenuItem;
dlgImport: TOpenDialog;
mnuSongAdjustTempo: TMenuItem;
mnuTGSavage: TMenuItem;
lblSavageOrnament: TLabel;
txtSvgOrnament: TEdit;
udnSvgOrnament: TUpDown;
chkSavageOrnInUse: TCheckBox;
lblSavageOrnInUse: TLabel;
btnSavageTest: TSpeedButton;
grdSVGOrnEdit: TStringGrid;
N9: TMenuItem;
mnuToolsOptions: TMenuItem;
mnuPatternExpand: TMenuItem;
mnuPatternShrink: TMenuItem;
mnuImportRipper: TMenuItem;
mnuPatternExpandX3: TMenuItem;
mnuPatternShrinkX3: TMenuItem;
mnuPatternExpandX2: TMenuItem;
mnuPatternShrinkX2: TMenuItem;
chkOrnLooped: TCheckBox;
lblOrnLooped: TLabel;
mnuTGROMBeep: TMenuItem;
mnuTGPlipPlop: TMenuItem;
mnuTGStocker: TMenuItem;
procedure mnuCompileClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure grdPatternKeyPress(Sender: TObject; var Key: Char);
procedure txtPatternNumChange(Sender: TObject);
procedure udnPatternLenClick(Sender: TObject; Button: TUDBtnType);
procedure grdPatternKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure mnuFileSaveAsClick(Sender: TObject);
procedure mnuFileNewClick(Sender: TObject);
procedure mnuFileSaveClick(Sender: TObject);
procedure mnuExitClick(Sender: TObject);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
procedure mnuFileOpenClick(Sender: TObject);
procedure txtPatternNameChange(Sender: TObject);
procedure grdSongKeyPress(Sender: TObject; var Key: Char);
procedure grdSongSelectCell(Sender: TObject; ACol, ARow: Integer;
var CanSelect: Boolean);
procedure grdSongKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure udnTempoClick(Sender: TObject; Button: TUDBtnType);
procedure mnuPlaySongClick(Sender: TObject);
procedure mnuPlayPatternClick(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure FormResize(Sender: TObject);
procedure mnuPatternCopyClick(Sender: TObject);
procedure mnuPlayStopClick(Sender: TObject);
procedure mnuTGSpecialFXClick(Sender: TObject);
procedure mnuTGTheMusicBoxClick(Sender: TObject);
procedure grdPatternMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure grdSongTopLeftChanged(Sender: TObject);
procedure pbxLoopStartMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure pbxLoopStartPaint(Sender: TObject);
procedure FormPaint(Sender: TObject);
procedure pbxLoopStartMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure pbxLoopStartMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure grdPatternDrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
procedure txtSongTitleChange(Sender: TObject);
procedure txtSongAuthorChange(Sender: TObject);
procedure mnuPatternTransposeClick(Sender: TObject);
procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure FormKeyPress(Sender: TObject; var Key: Char);
procedure grdPatternSelectCell(Sender: TObject; ACol, ARow: Integer;
var CanSelect: Boolean);
procedure mnuAboutClick(Sender: TObject);
procedure mnuHelpKeysClick(Sender: TObject);
procedure mnuEditUndoClick(Sender: TObject);
procedure mnuEditCopyClick(Sender: TObject);
procedure mnuEditPasteClick(Sender: TObject);
procedure mnuHelpOnlineClick(Sender: TObject);
procedure mnuTGMusicStudioClick(Sender: TObject);
procedure mnuSongInfoClick(Sender: TObject);
procedure mnuSongTransposeClick(Sender: TObject);
procedure imgPianoKeysMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure imgCh1NoteMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure mnuExportWAVFileClick(Sender: TObject);
procedure mnuPlayFromCurrentClick(Sender: TObject);
procedure mnuTGPhaser1DigitalClick(Sender: TObject);
procedure mnuTGPhaser1SynthClick(Sender: TObject);
procedure txtP1InstrumentChange(Sender: TObject);
procedure txtP1MultChange(Sender: TObject);
procedure txtP1DetuneChange(Sender: TObject);
procedure txtP1PhaseChange(Sender: TObject);
procedure btnP1TestClick(Sender: TObject);
procedure sbnNewClick(Sender: TObject);
procedure sbnOpenClick(Sender: TObject);
procedure sbnSaveClick(Sender: TObject);
procedure sbnPlayClick(Sender: TObject);
procedure cboBeeperEngineClick(Sender: TObject);
procedure chkP1InstInUseClick(Sender: TObject);
procedure mnuPatternSwapChansClick(Sender: TObject);
procedure mnuPatternAppendClick(Sender: TObject);
procedure mnuImportVTIITextClick(Sender: TObject);
procedure mnuSongAdjustTempoClick(Sender: TObject);
procedure mnuTGSavageClick(Sender: TObject);
procedure chkSavageOrnInUseClick(Sender: TObject);
procedure txtSvgOrnamentChange(Sender: TObject);
procedure grdSVGOrnEditKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure grdSVGOrnEditKeyPress(Sender: TObject; var Key: Char);
procedure grdSVGOrnEditSelectCell(Sender: TObject; ACol, ARow: Integer;
var CanSelect: Boolean);
procedure cboAutoIncChange(Sender: TObject);
procedure btnSavageTestClick(Sender: TObject);
procedure mnuToolsOptionsClick(Sender: TObject);
procedure grdSongDrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect;
State: TGridDrawState);
procedure mnuPatternExpandClick(Sender: TObject);
procedure mnuPatternShrinkClick(Sender: TObject);
procedure txtPatternLenExit(Sender: TObject);
procedure txtTempoExit(Sender: TObject);
procedure mnuImportRipperClick(Sender: TObject);
procedure mnuPatternExpandX3Click(Sender: TObject);
procedure mnuPatternShrinkX3Click(Sender: TObject);
procedure pbxOrnLoopMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure lblOrnLoopedClick(Sender: TObject);
procedure chkOrnLoopedClick(Sender: TObject);
procedure mnuTGROMBeepClick(Sender: TObject);
procedure mnuTGPlipPlopClick(Sender: TObject);
procedure mnuTGStockerClick(Sender: TObject);
private
{ Private declarations }
bMovingLoop: boolean;
bNewSongItemEntry: boolean;
bNewOrnamentItemEntry: boolean;
bNewPatternCellEntry: boolean;
SpecEmu: TSpecEmu;
bStopPlayer: boolean;
iPatternPlayer: integer;
iPatternTickCount: integer;
iPlayerRow: integer;
ZXPlay: TPlayerThread;
iOldPatternRow, iOldPatternCol: integer;
FPlaying: TPlaying;
MRUList: TMRUList;
procedure InitDisplay;
procedure InitPatternGrid;
procedure NumberGridRows;
function KeyToNoteVal(Key: Char; Octave: integer): byte;
procedure UpdatePatternGrid;
function IsValidNoteKey(Key: Char): boolean;
procedure InitSongGrid;
procedure UpdateSongGrid;
procedure PatternPlayerNewPattern;
procedure PatternTick;
procedure SongPlayerNewPattern;
procedure TMBPatternTick;
procedure UpdatePianoKeys(iCh1, iCh2: integer);
procedure DrawSongLoopStart;
procedure NotePlayerNewPattern;
function MousePosToNoteVal(X, Y: integer): integer;
function GetPhaser1Instr(iRow: integer): byte;
procedure Phaser1PatternTick;
procedure P1InstrumentTestNewPattern;
procedure WM_NewPattern(var Msg: TMessage); message WM_USER_NEWPATTERN;
procedure WM_PatternTick(var Msg: TMessage); message WM_USER_PATTERNTICK;
procedure WM_SongEnd(var Msg: TMessage); message WM_USER_SONGEND;
procedure StopPlayer;
procedure UpdateMRUMenu;
procedure mnuMRUItemClick(Sender: TObject);
procedure SetPatternEdStandard;
procedure SetPatternEdSavage;
procedure RenderStandardPatternInfo;
procedure RenderSVGPatternInfo;
procedure SavagePatternKeyDown(var Key: Word; Shift: TShiftState);
procedure StdPatternKeyPress(var Key: Char);
procedure SavagePatternKeyPress(var Key: Char);
procedure InitSVGOrnEditGrid;
procedure SetSvgOrnamentGrid(i: integer);
function SVGGetGlissando(iPat, iChan, iRow: integer): integer;
function SVGGetSkew(iPat, iChan, iRow: integer): integer;
function SVGGetSkewXOR(iPat, iChan, iRow: integer): integer;
function SVGGetArpeggio(iPat, iChan, iRow: integer): integer;
function EvenRowNotes(iPat: integer): boolean;
function TripleShrinkRowNotes(iPat: integer): boolean;
public
{ Public declarations }
hWaveOut: System.Cardinal;
bSongDirty: boolean;
sFileName: string;
Song: TSTSong;
UndoPattern: STPatterns.TPattern;
UndoSvgPattern: STPatterns.TPatternSvg;
RegSettings: TRegSettings;
end;
var
STMainWnd: TSTMainWnd;
implementation
uses frmCompileDlg, frmCopyPattern, frmTransposePatternDlg,
frmAboutDlg, frmKeyLayoutWnd, ShellApi, frmSongInfoDlg, frmTransposeSongDlg,
frmExportWavDlg, Math, frmSwapChannelsDlg, frmPatternAppendDlg, IniFiles,
frmImportVTIIFileDlg, frmAdjustSongTempoDlg, frmOptionsDlg,
frmSongRipper;
{$R *.dfm}
{$R BeepolaData.res}
var
CopyPattern: STPatterns.TPattern;
CopySVGPattern: STPatterns.TPatternSVG;
iTimerPeriod: Cardinal;
function ExtractBBSongFileName(sFile: string): string;
begin
Result := ExtractFileName(sFile);
if LowerCase(Copy(Result,Length(Result) - 6,7)) = '.bbsong' then
Result := Copy(Result,1,Length(Result)-7);
end;
procedure TSTMainWnd.P1InstrumentTestNewPattern();
begin
iPatternTickCount := 0;
inc(iPatternPlayer);
if iPatternPlayer > 1 then
StopPlayer();
end;
procedure TSTMainWnd.btnP1TestClick(Sender: TObject);
var
Spec: TSpecEmu;
begin
if bStopPlayer = false then exit;
Spec := TSpecEmu.Create(Self.hWaveOut);
Spec.Engine := P1D;
Spec.Register_SP := $7FF0; // stack pointer - 32752
Spec.Register_PC := $8000; //$8000; // program counter - 32768
Spec.LoadPlayerNote(255,24,1,udnP1Instrument.Position and $FF,0,2,Song);
Spec.OnNewPattern := P1InstrumentTestNewPattern;
Spec.OnPatternTick := nil;
iPatternPlayer := 0; // inc'd to 0 on first OnNewPattern event
bStopPlayer := false;
while bStopPlayer = false do
Spec.Exec(false);
// for i := 0 to 2 do
// Spec.Exec(true);
Spec.ResetWaveBuffers;
Sleep(210);
FreeAndNil(Spec);
end;
procedure TSTMainWnd.btnSavageTestClick(Sender: TObject);
var
Spec: TSpecEmu;
i: integer;
begin
if bStopPlayer = false then exit;
Spec := TSpecEmu.Create(Self.hWaveOut);
Spec.Engine := SVG;
Spec.Register_SP := $7FF0; // stack pointer - 32752
Spec.Register_PC := $8000; //$8000; // program counter - 32768
Spec.SavageLoadPlayerNote(255,24,0,0,0,0,0,0,0,udnSVGOrnament.Position and $FF,0,0,0,4,Song);
Spec.OnNewPattern := P1InstrumentTestNewPattern;
Spec.OnPatternTick := nil;
iPatternPlayer := 0; // inc'd to 0 on first OnNewPattern event
bStopPlayer := false;
while bStopPlayer = false do
Spec.Exec(false);
for i := 0 to 2 do
Spec.Exec(true);
Sleep(210);
Spec.ResetWaveBuffers;
FreeAndNil(Spec);
end;
procedure TSTMainWnd.Button1Click(Sender: TObject);
begin
//SpecEmu.WavOutputFile := 'c:\users\chris\bb-debug.wav';
end;
procedure TSTMainWnd.cboAutoIncChange(Sender: TObject);
begin
grdPattern.SetFocus();
UpdatePatternGrid();
end;
procedure TSTMainWnd.cboBeeperEngineClick(Sender: TObject);
begin
case (Sender as TComboBox).ItemIndex of
0: mnuTGSpecialFXClick(nil);
1: mnuTGTheMusicBoxClick(nil);
2: mnuTGMusicStudioClick(nil);
3: mnuTGPhaser1DigitalClick(nil);
4: mnuTGPhaser1SynthClick(nil);
5: mnuTGSavageClick(nil);
6: mnuTGROMBeepClick(nil);
7: mnuTGPlipPlopClick(nil);
8: mnuTGStockerClick(nil);
end;
end;
procedure TSTMainWnd.chkOrnLoopedClick(Sender: TObject);
begin
bSongDirty := true;
if Song.SVGArpeggio[udnSvgOrnament.Position].Length = 0 then exit;
if chkOrnLooped.Checked then
Song.SvgArpeggio[udnSvgOrnament.Position].Value[Song.SvgArpeggio[udnSvgOrnament.Position].Length] :=
Song.SvgArpeggio[udnSvgOrnament.Position].Value[Song.SvgArpeggio[udnSvgOrnament.Position].Length] or $80
else
Song.SvgArpeggio[udnSvgOrnament.Position].Value[Song.SvgArpeggio[udnSvgOrnament.Position].Length] :=
Song.SvgArpeggio[udnSvgOrnament.Position].Value[Song.SvgArpeggio[udnSvgOrnament.Position].Length] and $7F;
end;
procedure TSTMainWnd.chkP1InstInUseClick(Sender: TObject);
begin
txtP1InstrumentChange(nil);
end;
procedure TSTMainWnd.chkSavageOrnInUseClick(Sender: TObject);
begin
txtSvgOrnamentChange(nil);
end;
procedure TSTMainWnd.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
var
iRet: integer;
begin
StopPlayer();
if bSongDirty then
begin
iRet := Application.MessageBox('Do you want to save changes to the current song?',
PAnsiChar(Application.Title),
MB_YESNOCANCEL or MB_DEFBUTTON3 or MB_ICONQUESTION);
if iRet = ID_YES then
begin
if sFileName <> '' then
mnuFileSaveClick(nil)
else
mnuFileSaveAsClick(nil);
if not bSongDirty then
begin
CanClose := true;
end;
end
else if iRet = ID_NO then
begin
CanClose := true;
end
else if iRet = ID_CANCEL then CanClose := false;
end
else
CanClose := true;
end;
procedure TSTMainWnd.FormCreate(Sender: TObject);
var
TimeCaps: TTimeCaps;
iRet: integer;
sErrMsg: string;
WavFormat: TWaveFormatEx;
begin
MRUList := TMRUList.Create();
MRUList.Size := 5;
MRUList.Load();
RegSettings := TRegSettings.Create();
Song := TSTSong.Create();
bSongDirty := false;
sFileName := '';
hWaveOut := INVALID_HANDLE_VALUE;
with WavFormat do
begin
wFormatTag := WAVE_FORMAT_PCM;
nChannels := 1;
nSamplesPerSec := 44100;
nAvgBytesPerSec := 44100;
nBlockAlign := 1;
wBitsPerSample := 8;
cbSize := 0;
end;
iRet := waveOutOpen(@hWaveOut, WAVE_MAPPER, @WavFormat, 0, 0, CALLBACK_NULL);
if iRet <> MMSYSERR_NOERROR then
begin
sErrMsg := StringOfChar(#0,255);
waveOutGetErrorText(iRet, PAnsiChar(sErrMsg), Length(sErrMsg));
sErrMsg := Copy(sErrMsg, 1, Pos(#0,sErrMsg)- 1);
ShowMessage('Error initialising WaveOut device.'#13#10#13#10 + sErrMsg);
exit;
end;
SpecEmu := TSpecEmu.Create(Self.hWaveOut);
SpecEmu.Engine := sfx;
Self.DoubleBuffered := true;
pnlPattern.DoubleBuffered := true;
pnlKeys.DoubleBuffered := true;
pnlSongInfo.DoubleBuffered := true;
pnlToolbar.DoubleBuffered := true;
InitSongGrid();
grdSVGOrnEdit.Height := grdSVGOrnEdit.RowHeights[0] + GetSystemMetrics(SM_CXHSCROLL) + 5;
StopPlayer();
UpdateMRUMenu();
timeGetDevCaps(@TimeCaps,SizeOf(TimeCaps));
iTimerPeriod := TimeCaps.wPeriodMin;
timeBeginPeriod(iTimerPeriod);
end;
procedure TSTMainWnd.UpdateMRUMenu();
var
Item: TMenuItem;
i: Integer;
begin
for i := mnuFile.Count - 1 downto 0 do
begin
if Copy(mnuFile.Items[i].Name,1,6) = 'mnuMRU' then
mnuFile.Items[i].Free;
end;
if MRUList.ItemCount < 1 then exit;
Item := TMenuItem.Create(mnuFile);
Item.Caption := '-';
Item.Name := 'mnuMRUSep';
mnuFile.Add(Item);
for i := 0 to MRUList.ItemCount - 1 do
begin
Item := TMenuItem.Create(mnuFile);
Item.Caption := '&' + IntToStr(i+1) + ' ' + MRUList.Item[i];
Item.Name := 'mnuMRU' + IntToStr(i);
Item.OnClick := mnuMRUItemClick;
mnuFile.Add(Item);
end;
end;
procedure TSTMainWnd.mnuMRUItemClick(Sender: TObject);
var
iRet: integer;
sFile: string;
begin
StopPlayer();
if bSongDirty then
begin
iRet := Application.MessageBox('Do you want to save changes to the current song?',
PAnsiChar(Application.Title),
MB_YESNOCANCEL or MB_DEFBUTTON3 or MB_ICONQUESTION);
if iRet = ID_YES then
begin
if sFileName <> '' then
mnuFileSaveClick(nil)
else
mnuFileSaveAsClick(nil);
if bSongDirty then exit; // Failed to save file or Save Cancelled
end
else if iRet = ID_CANCEL then exit;
end;
sFile := Trim(Copy((Sender as TMenuItem).Caption,4,2048));
if FileExists(sFile) then
begin
if Song.LoadFile(sFile) then
begin
sFileName := sFile;
Self.Caption := ExtractBBSongFileName(sFileName) + ' - ' + Application.Title;
udnPatternNum.Position := 0;
UpdateSongGrid();
UpdatePatternGrid();
DrawSongLoopStart();
UndoPattern := Song.Pattern[0];
UndoSvgPattern := Song.SvgPatternData[0];
if Song.PreferredEngine = 'TMB' then
begin
mnuTGTheMusicBoxClick(nil);
end
else if Song.PreferredEngine = 'MSD' then
begin
mnuTGMusicStudioClick(nil);
end
else if Song.PreferredEngine = 'P1D' then
begin
mnuTGPhaser1DigitalClick(nil);
end
else if Song.PreferredEngine = 'P1S' then
begin
mnuTGPhaser1SynthClick(nil);
end
else if Song.PreferredEngine = 'SVG' then
begin
mnuTGSavageClick(nil);
end
else
begin
mnuTGSpecialFXClick(nil);
end;
grdPattern.SetFocus();
bSongDirty := false;
MRUList.AddFile(sFileName);
UpdateMRUMenu();
end;
end;
end;
procedure TSTMainWnd.FormDestroy(Sender: TObject);
begin
timeEndPeriod(iTimerPeriod);
FreeAndNil(MRUList);
FreeAndNil(SpecEmu);
FreeAndNil(Song);
WaveOutClose(hWaveOut);
end;
procedure TSTMainWnd.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
case KEY of
VK_NUMPAD1:
begin
udnOctave.SetFocus;
udnOctave.Position := 1;
end;
VK_NUMPAD2:
begin
udnOctave.SetFocus;
udnOctave.Position := 2;
end;
VK_NUMPAD3:
begin
udnOctave.SetFocus;
udnOctave.Position := 3;
end;
VK_NUMPAD4:
begin
udnOctave.SetFocus;
udnOctave.Position := 4;
end;
VK_NUMPAD5:
begin
udnOctave.SetFocus;
udnOctave.Position := 5;
end;
end;
end;
procedure TSTMainWnd.FormKeyPress(Sender: TObject; var Key: Char);
begin
if udnOctave.Focused then
begin
Key := #0;
grdPattern.SetFocus;
end;
if Key = ' ' then
begin
StopPlayer();
end;
end;
procedure TSTMainWnd.FormPaint(Sender: TObject);
var
Ht,Row: integer;
begin
Ht := (ClientHeight + 255) div 192 ;
for Row := 0 to 255 do
with Canvas do begin
Brush.Color := RGB(0, 0, Row) ;
FillRect(Rect(0, Row * Ht,
ClientWidth, (Row + 1) * Ht)) ;
end;
end;
procedure TSTMainWnd.FormResize(Sender: TObject);
begin
if Assigned(Song) then
begin
UpdatePianoKeys(Song.Pattern[udnPatternNum.Position].Chan[1][grdPattern.Row],
Song.Pattern[udnPatternNum.Position].Chan[2][grdPattern.Row]);
end;
FormPaint(Sender);
end;
procedure TSTMainWnd.FormShow(Sender: TObject);
var
sFileName: string;
begin
InitDisplay();
// If a file name is specified on the cmd line, then attempt to load it
if (ParamStr(1) <> '') and (Copy(ParamStr(1),1,1) <> '-') then
begin
if Song.LoadFile(ParamStr(1)) then
begin
sFileName := ParamStr(1);
Self.Caption := ExtractBBSongFileName(sFileName) + ' - ' + Application.Title;
udnPatternNum.Position := 0;
if Song.PreferredEngine = 'TMB' then
begin
mnuTGTheMusicBoxClick(nil);
end
else if Song.PreferredEngine = 'MSD' then
begin
mnuTGMusicStudioClick(nil);
end
else if Song.PreferredEngine = 'P1D' then
begin
mnuTGPhaser1DigitalClick(nil);
end
else if Song.PreferredEngine = 'P1S' then
begin
mnuTGPhaser1SynthClick(nil);
end
else if Song.PreferredEngine = 'SVG' then
begin
mnuTGSavageClick(nil);
end
else if Song.PreferredEngine = 'RMB' then
begin
mnuTGROMBeepClick(nil);
end
else if Song.PreferredEngine = 'PLP' then
begin
mnuTGPlipPlopClick(nil);
end
else if Song.PreferredEngine = 'STK' then
begin
mnuTGStockerClick(nil);
end
else
begin
mnuTGSpecialFXClick(nil);
end;
end;
end;
UpdateSongGrid();
UpdatePatternGrid();
DrawSongLoopStart();
grdPattern.SetFocus();
CopyPattern := Song.Pattern[0];
UndoPattern := Song.Pattern[0];
UndoSvgPattern := Song.SvgPatternData[0];
bSongDirty := false;
end;
function TSTMainWnd.GetPhaser1Instr(iRow: integer): byte;
var
i: Integer;
begin
Result := 0;
for i := 1 to iRow do
begin
if Song.Pattern[udnPatternNum.Position].Sustain[2][i] < 255 then
Result := Song.Pattern[udnPatternNum.Position].Sustain[2][i];
end;
end;
procedure TSTMainWnd.grdPatternKeyPress(Sender: TObject; var Key: Char);
begin
if not bStopPlayer then exit;
if Key = #9 then exit;
if Song.PreferredEngine = 'SVG' then
SavagePatternKeyPress(Key)
else
StdPatternKeyPress(Key);
end;
function TSTMainWnd.SVGGetGlissando(iPat,iChan,iRow: integer): integer;
var
i: Integer;
begin
Result := 0; // Default to glis 0
for i := 1 to iRow do
begin
if Song.SvgPatternData[iPat].Glissando[iChan][i] <> 256 then
Result := Song.SvgPatternData[iPat].Glissando[iChan][i];
end;
end;
function TSTMainWnd.SVGGetSkew(iPat,iChan,iRow: integer): integer;
var
i: Integer;
begin
Result := 0; // Default to glis 0
for i := 1 to iRow do
begin
if Song.SvgPatternData[iPat].Skew[iChan][i] <> 256 then
Result := Song.SvgPatternData[iPat].Skew[iChan][i];
end;
end;
function TSTMainWnd.SVGGetSkewXOR(iPat,iChan,iRow: integer): integer;
var
i: Integer;
begin
Result := 0; // Default to glis 0
for i := 1 to iRow do
begin
if Song.SvgPatternData[iPat].SkewXOR[iChan][i] <> 256 then
Result := Song.SvgPatternData[iPat].SkewXOR[iChan][i];
end;
end;
function TSTMainWnd.SVGGetArpeggio(iPat,iChan,iRow: integer): integer;
var
i: Integer;
begin
Result := 0; // Default to glis 0
for i := 1 to iRow do
begin
if Song.SvgPatternData[iPat].Arpeggio[iChan][i] <> 256 then
Result := Song.SvgPatternData[iPat].Arpeggio[iChan][i];
end;
end;
procedure TSTMainWnd.SavagePatternKeyPress(var Key: Char);
var
iChan: integer;
wEditVal: word;
KeyVal: byte;
begin
if (grdPattern.Col = 1) or (grdPattern.Col = 7) then
begin
if (grdPattern.Col = 1) then iChan := 1 else iChan := 2;
if IsValidNoteKey(Key) then
begin
UndoPattern := Song.Pattern[udnPatternNum.Position];
UndoSvgPattern := Song.SvgPatternData[udnPatternNum.Position];
Song.Pattern[udnPatternNum.Position].Chan[iChan][grdPattern.Row] := KeyToNoteVal(Key,udnOctave.Position);
UpdatePatternGrid();
SpecEmu.Register_SP := $7FF0; // stack pointer - 32752
SpecEmu.Register_PC := $8000; //$8000; // program counter - 32768
SpecEmu.SavageLoadPlayerNote(Song.Pattern[udnPatternNum.Position].Chan[1][grdPattern.Row],
Song.Pattern[udnPatternNum.Position].Chan[2][grdPattern.Row],
Song.SvgPatternData[udnPatternNum.Position].Glissando[1][grdPattern.Row],
Song.SvgPatternData[udnPatternNum.Position].Glissando[2][grdPattern.Row],
SVGGetSkew(udnPatternNum.Position,1,grdPattern.Row),
SVGGetSkew(udnPatternNum.Position,2,grdPattern.Row),
SVGGetSkewXOR(udnPatternNum.Position,1,grdPattern.Row),
SVGGetSkewXOR(udnPatternNum.Position,2,grdPattern.Row),
SVGGetArpeggio(udnPatternNum.Position,1,grdPattern.Row),
SVGGetArpeggio(udnPatternNum.Position,2,grdPattern.Row),
Song.SvgPatternData[udnPatternNum.Position].Warp[1][grdPattern.Row],
Song.SvgPatternData[udnPatternNum.Position].Warp[2][grdPattern.Row],
Song.Pattern[udnPatternNum.Position].Drum[grdPattern.Row],
Song.Pattern[udnPatternNum.Position].Tempo,
Song);
SpecEmu.OnNewPattern := NotePlayerNewPattern;
SpecEmu.OnPatternTick := nil;
iPatternPlayer := 0; // inc'd to 0 on first OnNewPattern event
bStopPlayer := false;
while bStopPlayer = false do
SpecEmu.Exec(false);
for iChan := 0 to 5 do
SpecEmu.Exec(false);
SpecEmu.ResetWaveBuffers;
bSongDirty := true;
end
else
exit;
end
else if grdPattern.Col = 13 then
begin
// Drum Channel
if (Key >= '0') and (Key <= '9') then
begin
UndoPattern := Song.Pattern[udnPatternNum.Position];
UndoSvgPattern := Song.SvgPatternData[udnPatternNum.Position];
if bNewPatternCellEntry or ((Song.Pattern[udnPatternNum.Position].Drum[grdPattern.Row]-$80) * 10 >= 254) then
Song.Pattern[udnPatternNum.Position].Drum[grdPattern.Row] := $80 + StrToIntDef(Key,0)
else
Song.Pattern[udnPatternNum.Position].Drum[grdPattern.Row] := $80 + (Song.Pattern[udnPatternNum.Position].Drum[grdPattern.Row]-$80) * 10 + StrToIntDef(Key,0);
if Song.Pattern[udnPatternNum.Position].Drum[grdPattern.Row] > $85 then
Song.Pattern[udnPatternNum.Position].Drum[grdPattern.Row] := 0;
if Song.Pattern[udnPatternNum.Position].Drum[grdPattern.Row] < $81 then
Song.Pattern[udnPatternNum.Position].Drum[grdPattern.Row] := 0;
UpdatePatternGrid();
SpecEmu.Register_SP := $7FF0; // stack pointer - 32752
SpecEmu.Register_PC := $8000; //$8000; // program counter - 32768
SpecEmu.SavageLoadPlayerNote(Song.Pattern[udnPatternNum.Position].Chan[1][grdPattern.Row],
Song.Pattern[udnPatternNum.Position].Chan[2][grdPattern.Row],
Song.SvgPatternData[udnPatternNum.Position].Glissando[1][grdPattern.Row],
Song.SvgPatternData[udnPatternNum.Position].Glissando[2][grdPattern.Row],
Song.SvgPatternData[udnPatternNum.Position].Skew[1][grdPattern.Row],
Song.SvgPatternData[udnPatternNum.Position].Skew[2][grdPattern.Row],
Song.SvgPatternData[udnPatternNum.Position].SkewXOR[1][grdPattern.Row],
Song.SvgPatternData[udnPatternNum.Position].SkewXOR[2][grdPattern.Row],
Song.SvgPatternData[udnPatternNum.Position].Arpeggio[1][grdPattern.Row],
Song.SvgPatternData[udnPatternNum.Position].Arpeggio[2][grdPattern.Row],
Song.SvgPatternData[udnPatternNum.Position].Warp[1][grdPattern.Row],
Song.SvgPatternData[udnPatternNum.Position].Warp[2][grdPattern.Row],
Song.Pattern[udnPatternNum.Position].Drum[grdPattern.Row],
Song.Pattern[udnPatternNum.Position].Tempo,
Song);
SpecEmu.OnNewPattern := NotePlayerNewPattern;
SpecEmu.OnPatternTick := nil;
iPatternPlayer := 0; // inc'd to 0 on first OnNewPattern event
bStopPlayer := false;
bNewPatternCellEntry := true; // always true as Savage drums < 10
while bStopPlayer = false do
SpecEmu.Exec(false);
for iChan := 0 to 5 do
SpecEmu.Exec(false);
SpecEmu.ResetWaveBuffers;
bSongDirty := true;
end;
end
else if ((grdPattern.Col >= 2) and (grdPattern.Col <= 6)) or
((grdPattern.Col >= 8) and (grdPattern.Col <= 12)) then
begin
if (grdPattern.Col < 7) then iChan := 1 else iChan := 2;
// Glis/Skew/Xor/Arp value for iChan
wEditVal := 0;
UndoPattern := Song.Pattern[udnPatternNum.Position];
UndoSvgPattern := Song.SvgPatternData[udnPatternNum.Position];
case grdPattern.Col of
2,8: wEditVal := Song.SvgPatternData[udnPatternNum.Position].Glissando[iChan][grdPattern.Row];
3,9: wEditVal := Song.SvgPatternData[udnPatternNum.Position].Skew[iChan][grdPattern.Row];
4,10: wEditVal := Song.SvgPatternData[udnPatternNum.Position].SkewXOR[iChan][grdPattern.Row];
5,11: wEditVal := Song.SvgPatternData[udnPatternNum.Position].Arpeggio[iChan][grdPattern.Row];
6,12: wEditVal := Song.SvgPatternData[udnPatternNum.Position].Warp[iChan][grdPattern.Row];
end;
if Key >= 'a' then Key := Chr(byte(Key) and $DF); // Make Uppercase
if ((Key >= '0') and (Key <= '9')) or ((Key >= 'A') and (Key <= 'F')) then
begin
if (Key <= '9') then KeyVal := byte(Key)-48 else KeyVal := byte(Key)-55;