Commit d973544

Nick Faro committed on
Update wave render UI, wip vgm
commit d973544e98ecb4a0e001de2fe2ad7cfa1529ba9f parent 9814cad
3 changed files +103−86
Modifiedrendertowave.lfm +71−72
@@ -1,21 +1,20 @@
1 object frmRenderToWave: TfrmRenderToWave 1 object frmRenderToWave: TfrmRenderToWave
2 Left = 2188 2 Left = 2188
3 Height = 365 3 Height = 209
4 Top = 290 4 Top = 290
5 Width = 789 5 Width = 451
6 BorderStyle = bsSingle 6 BorderStyle = bsSingle
7 Caption = 'Render song' 7 Caption = 'Render song'
8 ClientHeight = 365 8 ClientHeight = 209
9 ClientWidth = 789 9 ClientWidth = 451
10 DesignTimePPI = 168
11 OnShow = FormShow 10 OnShow = FormShow
12 Position = poDefault 11 Position = poDefault
13 LCLVersion = '2.0.12.0' 12 LCLVersion = '2.2.3.0'
14 object RenderButton: TButton 13 object RenderButton: TButton
15 Left = 24 14 Left = 14
16 Height = 44 15 Height = 25
17 Top = 289 16 Top = 165
18 Width = 462 17 Width = 264
19 Caption = 'Render' 18 Caption = 'Render'
20 Enabled = False 19 Enabled = False
21 OnClick = RenderButtonClick 20 OnClick = RenderButtonClick
@@ -23,14 +22,14 @@ object frmRenderToWave: TfrmRenderToWave
23 TabOrder = 0 22 TabOrder = 0
24 end 23 end
25 object FileNameEdit1: TFileNameEdit 24 object FileNameEdit1: TFileNameEdit
26 Left = 140 25 Left = 80
27 Height = 38 26 Height = 23
28 Top = 14 27 Top = 8
29 Width = 402 28 Width = 230
30 Filter = 'Wave|*.wav|MP3|*.mp3|FLAC|*.flac' 29 Filter = 'Wave|*.wav|MP3|*.mp3|FLAC|*.flac'
31 FilterIndex = 0 30 FilterIndex = 0
32 HideDirectories = False 31 HideDirectories = False
33 ButtonWidth = 40 32 ButtonWidth = 23
34 NumGlyphs = 1 33 NumGlyphs = 1
35 MaxLength = 0 34 MaxLength = 0
36 ParentFont = False 35 ParentFont = False
@@ -38,106 +37,98 @@ object frmRenderToWave: TfrmRenderToWave
38 OnChange = FileNameEdit1Change 37 OnChange = FileNameEdit1Change
39 end 38 end
40 object Label1: TLabel 39 object Label1: TLabel
41 Left = 24 40 Left = 14
42 Height = 30 41 Height = 15
43 Top = 22 42 Top = 13
44 Width = 83 43 Width = 48
45 Caption = 'Filename' 44 Caption = 'Filename'
46 ParentColor = False 45 ParentColor = False
47 ParentFont = False 46 ParentFont = False
48 end 47 end
49 object ProgressBar1: TProgressBar
50 Left = 24
51 Height = 49
52 Top = 219
53 Width = 730
54 ParentFont = False
55 Smooth = True
56 TabOrder = 2
57 end
58 object CancelButton: TButton 48 object CancelButton: TButton
59 Left = 498 49 Left = 285
60 Height = 44 50 Height = 25
61 Top = 289 51 Top = 165
62 Width = 256 52 Width = 146
63 Caption = 'Cancel' 53 Caption = 'Cancel'
64 Enabled = False 54 Enabled = False
65 OnClick = CancelButtonClick 55 OnClick = CancelButtonClick
66 ParentFont = False 56 ParentFont = False
67 TabOrder = 3 57 TabOrder = 2
68 end 58 end
69 object PlayEntireSongRadioButton: TRadioButton 59 object PlayEntireSongRadioButton: TRadioButton
70 Left = 24 60 Left = 14
71 Height = 34 61 Height = 19
72 Top = 79 62 Top = 45
73 Width = 182 63 Width = 104
74 Caption = 'Play entire song' 64 Caption = 'Play entire song'
75 Checked = True 65 Checked = True
76 ParentFont = False 66 ParentFont = False
77 TabOrder = 8 67 TabOrder = 7
78 TabStop = True 68 TabStop = True
79 end 69 end
80 object FromPositionRadioButton: TRadioButton 70 object FromPositionRadioButton: TRadioButton
81 Left = 24 71 Left = 14
82 Height = 34 72 Height = 19
83 Top = 149 73 Top = 85
84 Width = 161 74 Width = 94
85 Caption = 'From position' 75 Caption = 'From position'
86 ParentFont = False 76 ParentFont = False
87 TabOrder = 7 77 TabOrder = 6
88 end 78 end
89 object PlayEntireSongSpinEdit: TSpinEdit 79 object PlayEntireSongSpinEdit: TSpinEdit
90 Left = 234 80 Left = 134
91 Height = 38 81 Height = 23
92 Top = 72 82 Top = 41
93 Width = 172 83 Width = 98
84 MaxValue = 999
94 MinValue = 1 85 MinValue = 1
95 ParentFont = False 86 ParentFont = False
96 TabOrder = 4 87 TabOrder = 3
97 Value = 1 88 Value = 1
98 end 89 end
99 object Label2: TLabel 90 object Label2: TLabel
100 Left = 430 91 Left = 246
101 Height = 30 92 Height = 15
102 Top = 83 93 Top = 47
103 Width = 50 94 Width = 29
104 Caption = 'times' 95 Caption = 'times'
105 ParentColor = False 96 ParentColor = False
106 ParentFont = False 97 ParentFont = False
107 end 98 end
108 object FromPositionLowerSpinEdit: TSpinEdit 99 object FromPositionLowerSpinEdit: TSpinEdit
109 Left = 234 100 Left = 134
110 Height = 38 101 Height = 23
111 Top = 142 102 Top = 81
112 Width = 126 103 Width = 72
113 MaxValue = 9999999 104 MaxValue = 9999999
114 ParentFont = False 105 ParentFont = False
115 TabOrder = 5 106 TabOrder = 4
116 end 107 end
117 object FromPositionUpperSpinEdit: TSpinEdit 108 object FromPositionUpperSpinEdit: TSpinEdit
118 Left = 444 109 Left = 254
119 Height = 38 110 Height = 23
120 Top = 142 111 Top = 81
121 Width = 126 112 Width = 72
122 MaxValue = 99999999 113 MaxValue = 99999999
123 ParentFont = False 114 ParentFont = False
124 TabOrder = 6 115 TabOrder = 5
125 end 116 end
126 object Label3: TLabel 117 object Label3: TLabel
127 Left = 392 118 Left = 224
128 Height = 30 119 Height = 15
129 Top = 153 120 Top = 87
130 Width = 19 121 Width = 11
131 Caption = 'to' 122 Caption = 'to'
132 ParentColor = False 123 ParentColor = False
133 ParentFont = False 124 ParentFont = False
134 end 125 end
135 object ComboBox1: TComboBox 126 object ComboBox1: TComboBox
136 Left = 560 127 Left = 320
137 Height = 38 128 Height = 23
138 Top = 14 129 Top = 8
139 Width = 207 130 Width = 118
140 ItemHeight = 30 131 ItemHeight = 15
141 ItemIndex = 0 132 ItemIndex = 0
142 Items.Strings = ( 133 Items.Strings = (
143 'Wave' 134 'Wave'
@@ -145,7 +136,15 @@ object frmRenderToWave: TfrmRenderToWave
145 'FLAC' 136 'FLAC'
146 ) 137 )
147 Style = csDropDownList 138 Style = csDropDownList
148 TabOrder = 9 139 TabOrder = 8
149 Text = 'Wave' 140 Text = 'Wave'
150 end 141 end
142 object Panel1: TPanel
143 Left = 16
144 Height = 34
145 Top = 120
146 Width = 417
147 Caption = 'Ready'
148 TabOrder = 9
149 end
151 end 150 end
Modifiedrendertowave.pas +11−13
@@ -19,13 +19,13 @@ type
19 ComboBox1: TComboBox; 19 ComboBox1: TComboBox;
20 Label2: TLabel; 20 Label2: TLabel;
21 Label3: TLabel; 21 Label3: TLabel;
22 Panel1: TPanel;
22 PlayEntireSongRadioButton: TRadioButton; 23 PlayEntireSongRadioButton: TRadioButton;
23 FromPositionRadioButton: TRadioButton; 24 FromPositionRadioButton: TRadioButton;
24 RenderButton: TButton; 25 RenderButton: TButton;
25 CancelButton: TButton; 26 CancelButton: TButton;
26 FileNameEdit1: TFileNameEdit; 27 FileNameEdit1: TFileNameEdit;
27 Label1: TLabel; 28 Label1: TLabel;
28 ProgressBar1: TProgressBar;
29 PlayEntireSongSpinEdit: TSpinEdit; 29 PlayEntireSongSpinEdit: TSpinEdit;
30 FromPositionLowerSpinEdit: TSpinEdit; 30 FromPositionLowerSpinEdit: TSpinEdit;
31 FromPositionUpperSpinEdit: TSpinEdit; 31 FromPositionUpperSpinEdit: TSpinEdit;
@@ -42,7 +42,7 @@ type
42 42
43 function FilenameToFormatIndex: Integer; 43 function FilenameToFormatIndex: Integer;
44 function GetFFMPEGFormat: String; 44 function GetFFMPEGFormat: String;
45 procedure UpdateButtonEnabledStates; 45 procedure UpdateUI;
46 46
47 procedure ExportWaveToFile(Filename: String); 47 procedure ExportWaveToFile(Filename: String);
48 48
@@ -65,10 +65,9 @@ uses sound, machine, mainloop, vars, symparser;
65 65
66 procedure TfrmRenderToWave.RenderButtonClick(Sender: TObject); 66 procedure TfrmRenderToWave.RenderButtonClick(Sender: TObject);
67 begin 67 begin
68 ProgressBar1.Position := 0;
69 Rendering := True; 68 Rendering := True;
70 CancelRequested := False; 69 CancelRequested := False;
71 UpdateButtonEnabledStates; 70 UpdateUI;
72 71
73 try 72 try
74 ExportWaveToFile(FileNameEdit1.FileName); 73 ExportWaveToFile(FileNameEdit1.FileName);
@@ -79,30 +78,28 @@ begin
79 end; 78 end;
80 end; 79 end;
81 80
82 ProgressBar1.Position := 0;
83 Rendering := False; 81 Rendering := False;
84 CancelRequested := False; 82 CancelRequested := False;
85 UpdateButtonEnabledStates; 83 UpdateUI;
86 end; 84 end;
87 85
88 procedure TfrmRenderToWave.CancelButtonClick(Sender: TObject); 86 procedure TfrmRenderToWave.CancelButtonClick(Sender: TObject);
89 begin 87 begin
90 CancelRequested := True; 88 CancelRequested := True;
91 UpdateButtonEnabledStates; 89 UpdateUI;
92 end; 90 end;
93 91
94 procedure TfrmRenderToWave.FileNameEdit1Change(Sender: TObject); 92 procedure TfrmRenderToWave.FileNameEdit1Change(Sender: TObject);
95 begin 93 begin
96 ComboBox1.ItemIndex := FilenameToFormatIndex; 94 ComboBox1.ItemIndex := FilenameToFormatIndex;
97 UpdateButtonEnabledStates; 95 UpdateUI;
98 end; 96 end;
99 97
100 procedure TfrmRenderToWave.FormShow(Sender: TObject); 98 procedure TfrmRenderToWave.FormShow(Sender: TObject);
101 begin 99 begin
102 ProgressBar1.Position:=0;
103 FileNameEdit1.FileName:=''; 100 FileNameEdit1.FileName:='';
104 PlayEntireSongRadioButton.Checked:=True; 101 PlayEntireSongRadioButton.Checked:=True;
105 PlayEntireSongSpinEdit.Value:=0; 102 PlayEntireSongSpinEdit.Value:=1;
106 FromPositionLowerSpinEdit.Value:=0; 103 FromPositionLowerSpinEdit.Value:=0;
107 FromPositionUpperSpinEdit.Value:=0; 104 FromPositionUpperSpinEdit.Value:=0;
108 end; 105 end;
@@ -127,7 +124,7 @@ begin
127 end; 124 end;
128 end; 125 end;
129 126
130 procedure TfrmRenderToWave.UpdateButtonEnabledStates; 127 procedure TfrmRenderToWave.UpdateUI;
131 begin 128 begin
132 RenderButton.Enabled := (FileNameEdit1.FileName <> '') and not Rendering; 129 RenderButton.Enabled := (FileNameEdit1.FileName <> '') and not Rendering;
133 CancelButton.Enabled := Rendering and not CancelRequested; 130 CancelButton.Enabled := Rendering and not CancelRequested;
@@ -137,8 +134,6 @@ procedure TfrmRenderToWave.ExportWaveToFile(Filename: String);
137 var 134 var
138 Proc: TProcess; 135 Proc: TProcess;
139 begin 136 begin
140 ProgressBar1.Position := 0;
141
142 z80_reset; 137 z80_reset;
143 ResetSound; 138 ResetSound;
144 enablesound; 139 enablesound;
@@ -186,6 +181,8 @@ begin
186 Proc.CloseInput; 181 Proc.CloseInput;
187 Proc.WaitOnExit; 182 Proc.WaitOnExit;
188 Proc.Free; 183 Proc.Free;
184
185 Panel1.Caption := 'Ready';
189 end; 186 end;
190 end; 187 end;
191 188
@@ -263,6 +260,7 @@ begin
263 260
264 Inc(SeenPatterns[Pat]); 261 Inc(SeenPatterns[Pat]);
265 CurrentPattern := Pat; 262 CurrentPattern := Pat;
263 Panel1.Caption := 'Rendering order '+IntToStr(CurrentPattern+1);
266 end; 264 end;
267 265
268 end. 266 end.
Modifiedvgm.pas +21−1
@@ -94,6 +94,7 @@ implementation
94 var 94 var
95 VGMFile: TFileStream; 95 VGMFile: TFileStream;
96 CommandBuffer: TCommandVector; 96 CommandBuffer: TCommandVector;
97 TotalWaitTicks: Integer;
97 98
98 procedure BeginRecordingVGM(F: String); 99 procedure BeginRecordingVGM(F: String);
99 begin 100 begin
@@ -109,6 +110,7 @@ end;
109 procedure EndRecordingVGM; 110 procedure EndRecordingVGM;
110 var 111 var
111 Header: TVGMHeader; 112 Header: TVGMHeader;
113 Cmd: TVGMCommand;
112 begin 114 begin
113 Header := Default(TVGMHeader); // Zero the header 115 Header := Default(TVGMHeader); // Zero the header
114 Header.Vgmident := $56676d20; // "Vgm " 116 Header.Vgmident := $56676d20; // "Vgm "
@@ -116,7 +118,25 @@ begin
116 Header.Rate := 60; // 60hz 118 Header.Rate := 60; // 60hz
117 Header.GBDMGclock := 4194304; // 4194304 hz (from docs) 119 Header.GBDMGclock := 4194304; // 4194304 hz (from docs)
118 120
121 // TODO: Fill total wait ticks, loop point offset, loop length
122
119 VGMFile.WriteBuffer(Header, SizeOf(Header)); 123 VGMFile.WriteBuffer(Header, SizeOf(Header));
124 for Cmd in CommandBuffer do begin
125 case Cmd.type_ of
126 ctRegWrite: begin
127 VGMFile.WriteByte($B3); // Write DMG Reg
128 VGMFile.WriteByte(Byte(Cmd.Reg - $FF10));
129 VGMFile.WriteByte(Byte(Cmd.Param));
130 end;
131 ctWait: begin
132 VGMFile.WriteByte($61); // TODO: Use the smaller commands if it matches
133 VGMFile.WriteWord(Word(Cmd.Param));
134 end;
135 end;
136 end;
137
138 VGMFile.Free;
139 CommandBuffer.Clear;
120 end; 140 end;
121 141
122 procedure VGMWriteReg(Reg: Integer; Value: Integer); 142 procedure VGMWriteReg(Reg: Integer; Value: Integer);
@@ -124,7 +144,7 @@ var
124 Cmd: TVGMCommand; 144 Cmd: TVGMCommand;
125 begin 145 begin
126 Cmd.type_ := ctRegWrite; 146 Cmd.type_ := ctRegWrite;
127 Cmd.Reg := Reg - $FF10; 147 Cmd.Reg := Reg;
128 Cmd.Param := Value; 148 Cmd.Param := Value;
129 149
130 CommandBuffer.PushBack(Cmd); 150 CommandBuffer.PushBack(Cmd);