Delphi-PRAXiS
Seite 3 von 3     123   

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Multimedia (https://www.delphipraxis.net/16-multimedia/)
-   -   Delphi 'Visualissation' (https://www.delphipraxis.net/47947-visualissation.html)

turboPASCAL 20. Jun 2005 18:17

Re: 'Visualissation'
 
Ein Beispiel:

Delphi-Quellcode:
// Diese Methode flackert, weil erst der Hintergrund gelöscht wird
// und danach gezeichnet.
procedure TForm1.Timer1Timer(Sender: TObject);
var
  p: integer;
  aRect: TRect;
begin
  // Bar's zeichnen / aktualisieren
  if BassDLLPlayer1.Status = sndPlaying then
  begin
    aRect := PaintBox1.ClientRect;

    // Hintergrund der PaintBox Löschen
    PaintBox1.Canvas.Brush.Color := clBlack;
    PaintBox1.Canvas.Brush.Style := bsSolid;
    PaintBox1.Canvas.FillRect(aRect);

    //--- Obere Hälfte - LeftPeak ---------------------------------
    aRect.Bottom := (aRect.Bottom div 2) - 1; //Obere Hälfte der PaintBox

    // Ein bischen Prozentrechnung
    p := trunc((BassDLLPlayer1.LeftPeak / MaxPeak) * 100);
    aRect.Right := trunc((p * aRect.Right) / 100);

    PaintBox1.Canvas.Brush.Color := clRed;
    PaintBox1.Canvas.FillRect(aRect);

    //--- Untere Hälfte - RightPeak -------------------------------
    aRect.Right := TmpRight;  // <----<<< diese Zeile fehlte noch <----<<<
    aRect.Top := aRect.Bottom + 3; //Untere Hälfte der PaintBox 3 Px Abstand
    aRect.Bottom := aRect.Bottom * 2 + 3;

    // Ein bischen Prozentrechnung
    p := trunc((BassDLLPlayer1.RightPeak / MaxPeak) * 100);
    aRect.Right := trunc((p * aRect.Right) / 100);

    PaintBox1.Canvas.Brush.Color := clRed;
    PaintBox1.Canvas.FillRect(aRect);
  end;
end;

Khabarakh 20. Jun 2005 18:27

Re: 'Visualissation'
 
Zitat:

Zitat von Nils_13
Zitat:

Zitat von FAlter
Zitat:

Zitat von Nils_13
Delphi-Quellcode:
    for i := 0 to LKanal do
      p.Width := p.Width + 1;
     // DrawGradient
    for i := 0 to RKanal do
      p2.Width := p2.Width + 1;

Optimierungsvorschlag: Statt es in einer Schleife jedes mal um eins zu erhöhen...

Delphi-Quellcode:
inc(p.Width, LKanal + 1); //analog für rechts

//oder (falls Width ein Property ist)
p.Width := LKanal + 1 + p.Width; //analog für rechts
Ich weiß nicht, was p und p2 sein sollen??? Eventuell liegt da auch noch Optimierungsansatz.

//edit: schließenden quote-tag ergänzt :oops:

Geht nicht: der linken Seite kann nichs zugewiesen werden.

:roll:

Rate mal, wofür die zweite Möglichkeit von FAlter ist.

turboPASCAL 20. Jun 2005 19:00

Re: 'Visualissation'
 
Bessere Variante (Antiflacker):

Delphi-Quellcode:
procedure TForm1.Timer1Timer(Sender: TObject);
const
  MaxPeak = 32768; // sollte schon in BassDLLPlayer global def. sein
var
  p, TmpRight: integer;
  aRect, bRect: TRect;
begin
  // Bar's zeichnen / aktualisieren
  if BassDLLPlayer1.Status = sndPlaying then
  begin
    // Leinwandgrösse ermitteln
    aRect := PaintBox1.ClientRect;
    TmpRight := aRect.Right;
   
    // Hintergrund Style für Pinsel setzen
    PaintBox1.Canvas.Brush.Style := bsSolid;

    //--- Obere Hälfte - LeftPeak ---------------------------------
    aRect.Bottom := (aRect.Bottom div 2) - 1; //Obere Hälfte der PaintBox

    // Ein bischen Prozentrechnung (p {Prozent} = Peak ist wieviel % von MaxPeak)
    p := trunc((BassDLLPlayer1.LeftPeak / MaxPeak) * 100);
    aRect.Right := trunc((p * aRect.Right) / 100);
    // Zeichnen des Peak-Wertes
    PaintBox1.Canvas.Brush.Color := clRed; // <-
    PaintBox1.Canvas.FillRect(aRect);     // <-
    // oder DrawGradient(PaintBox1.Canvas, aRect, True, [clYellow, clRed]);

    // Rechten Rest von PaintBox berechnen
    bRect := aRect;
    bRect.Right := TmpRight;
    bRect.Left := aRect.Right;
    // Zeichnen des rechten Rests in Black
    PaintBox1.Canvas.Brush.Color := clBlack;
    PaintBox1.Canvas.FillRect(bRect);
    //--- Untere Hälfte - RightPeak -------------------------------
    aRect.Right := TmpRight;  // <----<<< diese Zeile fehlte noch <----<<<
    aRect.Top := aRect.Bottom + 3; // untere Hälfte der PaintBox 3 Px Abstand
    aRect.Bottom := (aRect.Bottom * 2) + 3; // es Fehlen ja noch 3 Px von oben

    // Ein bischen Prozentrechnung
    p := trunc((BassDLLPlayer1.RightPeak / MaxPeak) * 100);
    aRect.Right := trunc((p * aRect.Right) / 100);
    // Zeichnen des Peak Wertes
    PaintBox1.Canvas.Brush.Color := clRed; // <-
    PaintBox1.Canvas.FillRect(aRect);     // <-
    // oder DrawGradient(PaintBox1.Canvas, aRect, True, [clYellow, clRed]);
    // Rechten Rest von PaintBox berechnen
    bRect := aRect;
    bRect.Right := TmpRight;
    bRect.Left := aRect.Right;
    // Zeichnen des rechten Rests in Black
    PaintBox1.Canvas.Brush.Color := clBlack;
    PaintBox1.Canvas.FillRect(bRect);
  end;
end;
Das Würde ich noch in eine extra Procedure auslagern.(Übersichtlicher)

Bitte verwende aussagekräftigere Namen PaintBox1 oder MyPaintBox auch wenn es mehr Arbeit beim Tippen macht, sonst verliert man nach einer Weile die Übersicht.
(…und die Leute im Forum wissen nicht was Du damit meinst.)

Nils_13 20. Jun 2005 19:14

Re: 'Visualissation'
 
Beide Methoden sind sehr gut, thx.
Nur was kann ich dagegen machen, dass immer der Computer überfordert wird ?

turboPASCAL 20. Jun 2005 19:20

Re: 'Visualissation'
 
Was haste denn für einen ? Pentium 75 ? :mrgreen:

Ist der Timmer Interval zu klein, höher setzen > 50 oder so.

Nils_13 20. Jun 2005 19:22

Re: 'Visualissation'
 
Ich hab einen AMD AThlon mit einer guten Grafikkarte, außerdem muss das Programm auch auf anderen Computern laufen. Bei mir sind es 100%, mit 50 ist es auch nicht besser.
ICh geb mich geschlagen, ich hatte noch einen anderen Timer laufen.

THX !!!

Die Muhkuh 20. Jun 2005 19:24

Re: 'Visualissation'
 
Lager es vllt. in einen Thread aus?


Alle Zeitangaben in WEZ +1. Es ist jetzt 17:56 Uhr.
Seite 3 von 3     123   

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz