Commit cae92c6

Nick committed on
Adding double buffering to oscilloscopes, thanks handoko
commit cae92c6db3ec05e8f60b4aac27b665ad7fc18ee0 parent 9007586
2 changed files +32−24
Modifiedtracker.lfm +2−2
@@ -1,7 +1,7 @@
1 object frmTracker: TfrmTracker 1 object frmTracker: TfrmTracker
2 Left = 199 2 Left = 621
3 Height = 1250 3 Height = 1250
4 Top = 245 4 Top = 297
5 Width = 2067 5 Width = 2067
6 Caption = 'hUGETracker' 6 Caption = 'hUGETracker'
7 ClientHeight = 1216 7 ClientHeight = 1216
Modifiedtracker.pas +30−22
@@ -328,6 +328,7 @@ type
328 SymbolTable: TSymbolMap; 328 SymbolTable: TSymbolMap;
329 OptionsFile: TIniFile; 329 OptionsFile: TIniFile;
330 330
331 VisualizerBuffer: TBitmap;
331 PerformingOscilloscopeUpdate: Boolean; 332 PerformingOscilloscopeUpdate: Boolean;
332 333
333 procedure ChangeToSquare; 334 procedure ChangeToSquare;
@@ -440,7 +441,9 @@ procedure TfrmTracker.DrawVizualizer(PB: TPaintBox; Channel: Integer);
440 var 441 var
441 I, J, X: Integer; 442 I, J, X: Integer;
442 begin 443 begin
443 with PB.Canvas do begin 444 // Thanks to Handoko on the Lazarus forums for this repainting tip!
445 // https://forum.lazarus.freepascal.org/index.php/topic,48231.msg347235.html#msg347235
446 with VisualizerBuffer.Canvas do begin
444 MoveTo(0, PB.Height div 2); 447 MoveTo(0, PB.Height div 2);
445 448
446 Brush.Color := clBlack; 449 Brush.Color := clBlack;
@@ -449,22 +452,31 @@ begin
449 Pen.Color := clGray; 452 Pen.Color := clGray;
450 Rectangle(0, 0, PB.Width, PB.Height); 453 Rectangle(0, 0, PB.Width, PB.Height);
451 454
452 Pen.Color := clLime;
453 Pen.Width := 2; 455 Pen.Width := 2;
454 456
455 X := 0; 457 if not snd[Channel].ChannelOFF then begin
456 I := 0; 458 Pen.Color := clLime;
457 J := SampleBuffers[Channel].Cursor; 459
458 while I < SAMPLE_BUFFER_SIZE-1 do begin 460 X := 0;
459 LineTo(X, (PB.Height div 2) + 461 I := 0;
460 Trunc((SampleBuffers[Channel].BufferL[J]/512)*PB.Height) + 462 J := SampleBuffers[Channel].Cursor;
461 Trunc((SampleBuffers[Channel].BufferR[J]/512)*PB.Height)); 463 while I < SAMPLE_BUFFER_SIZE-1 do begin
462 J := (J+1) mod SAMPLE_BUFFER_SIZE; 464 LineTo(X, (PB.Height div 2) +
463 465 Trunc((SampleBuffers[Channel].BufferL[J]/512)*PB.Height) +
464 X := Trunc((I/SAMPLE_BUFFER_SIZE)*PB.Width); 466 Trunc((SampleBuffers[Channel].BufferR[J]/512)*PB.Height));
465 Inc(I, 2); 467 J := (J+1) mod SAMPLE_BUFFER_SIZE;
468
469 X := Trunc((I/SAMPLE_BUFFER_SIZE)*PB.Width);
470 Inc(I, 2);
471 end;
472 end
473 else begin
474 Pen.Color := TColor($0C0094);
475 Line(0, 0, PB.Width, PB.Height);
476 Line(0, PB.Height, PB.Width, 0);
466 end; 477 end;
467 end; 478 end;
479 PB.Canvas.Draw(0, 0, VisualizerBuffer);
468 end; 480 end;
469 481
470 procedure TfrmTracker.PreviewInstrument(Freq: Integer; Instr: Integer); 482 procedure TfrmTracker.PreviewInstrument(Freq: Integer; Instr: Integer);
@@ -927,6 +939,10 @@ begin
927 'font file, so please install PixeliteTTF.ttf and relaunch! Thanks.', 939 'font file, so please install PixeliteTTF.ttf and relaunch! Thanks.',
928 mtWarning, [mbOk], 0); 940 mtWarning, [mbOk], 0);
929 941
942 VisualizerBuffer := TBitmap.Create;
943 VisualizerBuffer.Height := Duty1Visualizer.Height;
944 VisualizerBuffer.Width := Duty1Visualizer.Width;
945
930 ReturnNilIfGrowHeapFails := False; 946 ReturnNilIfGrowHeapFails := False;
931 PreviewingInstrument := -1; 947 PreviewingInstrument := -1;
932 OptionsFile := TINIFile.Create('options.ini'); 948 OptionsFile := TINIFile.Create('options.ini');
@@ -1223,7 +1239,7 @@ begin
1223 else {if Sender = NoiseVisualizer then} Section := HeaderControl1.Sections.Items[3]; 1239 else {if Sender = NoiseVisualizer then} Section := HeaderControl1.Sections.Items[3];
1224 1240
1225 Section.ImageIndex := (Section.ImageIndex + 1) mod 2; 1241 Section.ImageIndex := (Section.ImageIndex + 1) mod 2;
1226 snd[HeaderControl1.Sections.Items[0].OriginalIndex+1].ChannelOFF := Section.ImageIndex = 0; 1242 snd[Section.OriginalIndex+1].ChannelOFF := Section.ImageIndex = 0;
1227 end; 1243 end;
1228 1244
1229 procedure TfrmTracker.PasteActionExecute(Sender: TObject); 1245 procedure TfrmTracker.PasteActionExecute(Sender: TObject);
@@ -1510,11 +1526,6 @@ var
1510 I: Integer; 1526 I: Integer;
1511 Samp: Integer; 1527 Samp: Integer;
1512 begin 1528 begin
1513 if PerformingOscilloscopeUpdate then Exit;
1514 PerformingOscilloscopeUpdate := True;
1515
1516 Application.ProcessMessages;
1517 // Hack to prevent the effect editor from choking when it's trying to close.
1518 if Playing then 1529 if Playing then
1519 OscilloscopeUpdateTimer.Interval := 25 1530 OscilloscopeUpdateTimer.Interval := 25
1520 else 1531 else
@@ -1541,9 +1552,6 @@ begin
1541 Max2 := Trunc((Max2/512)*100); 1552 Max2 := Trunc((Max2/512)*100);
1542 if Max1 > LEDMeter1.Position then LEDMeter1.Position := Max1; 1553 if Max1 > LEDMeter1.Position then LEDMeter1.Position := Max1;
1543 if Max2 > LEDMeter2.Position then LEDMeter2.Position := Max2; 1554 if Max2 > LEDMeter2.Position then LEDMeter2.Position := Max2;
1544
1545 Application.ProcessMessages;
1546 PerformingOscilloscopeUpdate := False;
1547 end; 1555 end;
1548 1556
1549 procedure TfrmTracker.ExportGBSButtonClick(Sender: TObject); 1557 procedure TfrmTracker.ExportGBSButtonClick(Sender: TObject);