Salut la compagnie
J'ai réalisé un petit composant : Celui fonctionne très bien sauf qu'il est terriblement lent ce qui fait que le refresh de la fiche que j'utilise mais du temps à se faire. Je pense que c'est une question d'optimisation mais je ne vois pas trop ce que je pourrais améliorer. Donc je m'en remet à vos lumières
unit Browser;
interface
uses
Windows, Messages, SysUtils, Classes, Controls, ExtCtrls, Graphics, Menus, dialogs;
Type
TInstrument = record
Channel:Cardinal;
Instrument:Cardinal;
Panel:TPanel;
Selected:Boolean;
End;
Type
TSoundFont = record
FileName:String;
Bank:Cardinal;
Panel:TPanel;
Selected:Boolean;
End;
Type
TASio = record
FileName:String;
Panel:TPanel;
Selected:Boolean;
End;
Type
TVSTInstr = record
FileName:String;
Panel:TPanel;
Selected:Boolean;
End;
type
TInstrument_Event = procedure(Sender : TObject) of object;
TSoundFont_Event = procedure(Sender : TObject) of object;
TAsio_Event = procedure(Sender : TObject) of object;
TVSTInstr_Event = procedure(Sender : TObject) of object;
TBrowser = class(TCustomControl)
private
fInstrumentPanel:TPanel;
fSoundFontPanel:TPanel;
fASioPanel:TPanel;
fVSTInstrPanel:TPanel;
fColorPanel:TColor;
fColorBackGround:TColor;
fColorGrad:TColor;
fSelectColor:TColor;
fInstrumentsVisible:Boolean;
fSoundFontsVisible:Boolean;
fASiosVisible:Boolean;
fVSTInstrsVisible:Boolean;
fOnInstrument_Event:TInstrument_Event;
fOnSoundFont_Event:TSoundFont_Event;
fOnAsio_Event:TAsio_Event;
fOnVSTInstr_Event:TVSTInstr_Event;
fPopupMenu:TPopupMenu;
Procedure SetColorPanel(Value:TColor);
Procedure SetColorBackGround(Value:TColor);
Procedure SetColorGrad(Value:TColor);
Procedure SetSelectColor(Value:TColor);
Procedure Create_InstrumentsPanel;
Procedure InstrumentsOnClick(Sender:TObject);
Procedure InstrumentPanelOnClick(Sender:TObject);
Procedure SoundFontsOnClick(Sender:TObject);
Procedure SoundFontPanelOnClick(Sender:TObject);
Procedure AsiosOnClick(Sender:TObject);
Procedure AsioPanelOnClick(Sender:TObject);
Procedure VSTInstrsOnClick(Sender:TObject);
Procedure VSTInstrPanelOnClick(Sender:TObject);
Procedure Gen_Grad_Panel;
Procedure SetPopupMenu(Value:TPopupMenu);
protected
procedure MouseDown(Button: TMouseButton;Shift: TShiftState; X, Y: Integer); override;
public
InstrumentList:Array[1..128] of TInstrument;
SoundFontList:Array of TSoundFont;
AsioList:Array of TAsio;
VSTInstrList:Array of TVSTInstr;
SoundFontSelected : Cardinal;
InstrumentSelected : Cardinal;
AsioSelected : Cardinal;
VSTISelected : Cardinal;
Procedure Add_SoundFont(Value:String);
Procedure Add_Asio(Value:String);
Procedure Add_VSTInstr(Value:String);
Procedure Paint; override;
constructor Create(AOwner:TComponent); override;
destructor Destroy; override;
published
Property ColorPanel:TColor Read fColorPanel Write SetColorPanel;
Property ColorBackGround:TColor Read fColorBackGround Write SetColorBackGround;
Property ColorGrad:TColor Read fColorGrad Write SetColorGrad;
Property SelectColor:TColor Read fSelectColor Write SetSelectColor;
Property Instrument_Event : TInstrument_Event read fOnInstrument_Event write fOnInstrument_Event;
Property SoundFont_Event : TSoundFont_Event read fOnSoundFont_Event write fOnSoundFont_Event;
Property Asio_Event : TAsio_Event read fOnAsio_Event write fOnAsio_Event;
Property VSTInstr_Event : TVSTInstr_Event read fOnVSTInstr_Event write fOnVSTInstr_Event;
Property PopupMenu:TPopupMenu Read fPopupMenu Write SetPopupMenu;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('MUSIC_PRO', [TBrowser]);
end;
constructor TBrowser.Create(AOwner:TComponent);
begin
inherited Create(AOwner);
fInstrumentPanel:=TPanel.Create(Self);
fInstrumentPanel.Parent:=Self;
Self.fInstrumentsVisible:=True;
fInstrumentPanel.OnClick:=InstrumentPanelOnClick;
Create_InstrumentsPanel;
fSoundFontPanel:=TPanel.Create(Self);
fSoundFontPanel.Parent:=Self;
Self.fSoundFontsVisible:=True;
fSoundFontPanel.OnClick:=SoundFontPanelOnClick;
fAsioPanel:=TPanel.Create(Self);
fAsioPanel.Parent:=Self;
Self.fAsiosVisible:=True;
fAsioPanel.OnClick:=AsioPanelOnClick;
fVSTInstrPanel:=TPanel.Create(Self);
fVSTInstrPanel.Parent:=Self;
Self.fVSTInstrsVisible:=True;
fVSTInstrPanel.OnClick:=VSTInstrPanelOnClick;
Initialize(SoundFontList);
Initialize(AsioList);
Initialize(VSTInstrList);
SoundFontSelected:=0;
InstrumentSelected :=0;
VSTISelected :=0;
end;
Procedure TBrowser.InstrumentPanelOnClick(Sender:TObject);
Begin
Self.fInstrumentsVisible:=Not Self.fInstrumentsVisible;
Self.Invalidate;
End;
Procedure TBrowser.SoundFontPanelOnClick(Sender:TObject);
Begin
Self.fSoundFontsVisible:=Not Self.fSoundFontsVisible;
Self.Invalidate;
End;
Procedure TBrowser.AsioPanelOnClick(Sender:TObject);
Begin
Self.fAsiosVisible:=Not Self.fAsiosVisible;
Self.Invalidate;
End;
Procedure TBrowser.VSTInstrPanelOnClick(Sender:TObject);
Begin
Self.fVSTInstrsVisible:=Not Self.fVSTInstrsVisible;
Self.Invalidate;
End;
Procedure TBrowser.SetColorPanel(Value:TColor);
Begin
If Assigned(Self) Then
Begin
fColorPanel:=Value;
Self.Invalidate;
End;
End;
Procedure TBrowser.SetColorBackGround(Value:TColor);
Begin
If Assigned(Self) Then
Begin
fColorBackGround:=Value;
Self.Invalidate;
End;
End;
Procedure TBrowser.SetColorGrad(Value:TColor);
Begin
If Assigned(Self) Then
Begin
fColorGrad:=Value;
Self.Invalidate;
End;
End;
Procedure TBrowser.SetSelectColor(Value:TColor);
Begin
If Assigned(Self) Then
Begin
fSelectColor:=Value;
Self.Invalidate;
End;
End;
Procedure TBrowser.SetPopupMenu(Value:TPopupMenu);
Begin
If Assigned(Self) Then
fPopupMenu:=Value;
End;
Procedure TBrowser.Create_InstrumentsPanel;
Const
NameInstruments:Array [1..128] of String=
( 'Piano acoustique 1'
,'Piano acoustique 2'
,'Piano électrique'
,'Piano HonkyTonk'
,'Piano électrique 1'
,'Piano électrique 2'
,'Clavecin'
,'Clavicorde'
,'Célesta'
,'Carillon'
,'Boîte à musique'
,'Vibraphone'
,'Marimba'
,'Xylophone'
,'Cloches tubulaires'
,'Tympanon'
,'Orgue à tubes'
,'Orgue percussif'
,'Orgue rock'
,'Orgue église'
,'Orgue vibrato'
,'Accordéon'
,'Harmonica'
,'Accordéon tango'
,'Guitare classique'
,'Guitare folk'
,'Guitare electrique Jazz'
,'Guitare electrique claire'
,'Guitare electrique muted'
,'Guitare saturée'
,'Guitare à distorsion'
,'Harmoniques'
,'Basse acoustique'
,'Basse electrique(doigt)'
,'Basse electrique (medium)'
,'Basse fretless'
,'Basse Slap 1'
,'Basse Slap 2'
,'Basse Synthé 1'
,'Basse Synthé 2'
,'Violon'
,'Viole'
,'Violoncelle'
,'Contrebasse'
,'Cordes tremolo'
,'Cordes pizzicato'
,'Harpe'
,'Timbales'
,'Quartet cordes 1'
,'Quartet cordes 2'
,'Cordes synthé 1'
,'Cordes synthé 2'
,'Chours Aahs'
,'Voix Oohs'
,'Voix synthé'
,'Coup orchestre'
,'Trompette'
,'Trombone'
,'Tuba'
,'Trompette bouchée'
,'Cors'
,'Ensemble de cuivres'
,'Cuivres synthé 1'
,'Cuivres synthé 2'
,'Saxo soprano'
,'Saxo alto'
,'Saxo ténor'
,'Saxo Baryton'
,'Hautbois'
,'Cors anglais'
,'Basson'
,'Clarinette'
,'Piccolo'
,'Flûte'
,'Flûte à bec'
,'Flûte de Pan'
,'Bouteille'
,'Shakuhachi'
,'Sifflet'
,'Ocarina'
,'Signal carré'
,'Signal dents de scie'
,'Orgue à vapeur'
,'Chiff'
,'Charang'
,'Voix solo'
,'Quinte'
,'Basse'
,'New Age'
,'Warm'
,'Polysynth'
,'Chour'
,'Archet'
,'Métallique'
,'Halo'
,'Sweep'
,'Pluie'
,'Bande son'
,'Cristal'
,'Atmosphère'
,'Brightness'
,'Goblins'
,'Echos'
,'Scie '
,'Sitar'
,'Banjo'
,'Shamisen'
,'Koto'
,'Kalimba'
,'Cornemuse'
,'Violon folklorique'
,'Shanai'
,'Sonnerie'
,'Agogo'
,'Percussion acier'
,'Woodblock'
,'Taiko'
,'Tom mélodique'
,'Percussion synthé'
,'Cymbale inversée'
,'Cordes guitares'
,'Respiration'
,'Rivage'
,'Chant oiseaux'
,'Sonnerie téléphone'
,'Hélicoptère'
,'Applaudissements'
,'Coup de feu');
Var
Index:Cardinal;
Begin
For Index:=1 To 128 Do
With InstrumentList[Index] Do
Begin
Channel:=1;
Instrument:=Index;
Panel:=TPanel.Create(Self);
Panel.Parent:=Self;
Panel.OnClick:=InstrumentsOnClick;
Panel.Tag:=Index;
Selected:=False;
Font.Color:=ClBlack;
Font.Color:=ClWhite;
Panel.Caption:=NameInstruments[Index];
End;
End;
Procedure TBrowser.Add_SoundFont(Value:String);
Begin
SetLength(SoundFontList,High(SoundFontList)+2);
With SoundFontList[High(SoundFontList)] Do
Begin
FileName:=Value;
Bank:=0;
Panel:=TPanel.Create(Self);
Panel.Parent:=Self;
Panel.OnClick:=SoundFontsOnClick;
Panel.Tag:=High(SoundFontList)+1;
Selected:=False;
Font.Color:=Clwhite;
Panel.Caption:=ExtractFileName(FileName);
End;
Self.Invalidate;
End;
Procedure TBrowser.Add_Asio(Value:String);
Begin
SetLength(AsioList,High(AsioList)+2);
With AsioList[High(AsioList)] Do
Begin
FileName:=Value;
Panel:=TPanel.Create(Self);
Panel.Parent:=Self;
Panel.OnClick:=AsiosOnClick;
Panel.Tag:=High(AsioList)+1;
Selected:=False;
Font.Color:=Clwhite;
Panel.Caption:=ExtractFileName(FileName);
End;
Self.Invalidate;
End;
Procedure TBrowser.Add_VSTInstr(Value:String);
Begin
SetLength(VSTInstrList,High(VSTInstrList)+2);
With VSTInstrList[High(VSTInstrList)] Do
Begin
FileName:=Value;
Panel:=TPanel.Create(Self);
Panel.Parent:=Self;
Panel.OnClick:=VSTInstrsOnClick;
Panel.Tag:=High(VSTInstrList)+1;
Selected:=False;
Font.Color:=Clwhite;
Panel.Caption:=ExtractFileName(FileName);
End;
Self.Invalidate;
End;
Procedure TBrowser.InstrumentsOnClick(Sender:TObject);
Var
Number,Index:Cardinal;
Begin
InstrumentSelected:=0;
Number:=1;
If (Sender is TPanel) Then
Number:=(Sender As TPanel).Tag;
For Index:=1 To 128 Do
InstrumentList[Index].Selected:=False;
InstrumentList[Number].Selected:=True;
InstrumentSelected:=Number;
Self.Invalidate;
If Assigned(fOnInstrument_Event) Then Self.fOnInstrument_Event(Sender);
End;
Procedure TBrowser.SoundFontsOnClick(Sender:TObject);
Var
Number,Index:Cardinal;
Begin
SoundFontSelected:=0;
Number:=1;
If (Sender is TPanel) Then
Number:=(Sender As TPanel).Tag;
For Index:=Low(SoundFontList) To High(SoundFontList) Do
SoundFontList[Index].Selected:=False;
SoundFontList[Number-1].Selected:=Not SoundFontList[Number-1].Selected;
If SoundFontList[Number-1].Selected Then SoundFontSelected:=Number;
Self.Invalidate;
If Assigned(fOnSoundFont_Event) Then Self.fOnSoundFont_Event(Sender);
End;
Procedure TBrowser.AsiosOnClick(Sender:TObject);
Var
Number,Index:Cardinal;
Begin
Number:=1;
If (Sender is TPanel) Then
Number:=(Sender As TPanel).Tag;
For Index:=Low(AsioList) To High(AsioList) Do
If Number-1<>Index Then AsioList[Index].Selected:=False;
AsioList[Number-1].Selected:=Not AsioList[Number-1].Selected;
If AsioList[Number-1].Selected Then AsioSelected:=Number;
Self.Invalidate;
If Assigned(fOnAsio_Event) Then Self.fOnAsio_Event(Sender);
End;
Procedure TBrowser.VSTInstrsOnClick(Sender:TObject);
Var
Number,Index:Cardinal;
Begin
Number:=1;
VSTISelected:=0;
If (Sender is TPanel) Then
Number:=(Sender As TPanel).Tag;
For Index:=Low(VSTInstrList) To High(VSTInstrList) Do
If Number-1<>Index Then VSTInstrList[Index].Selected:=False;
VSTInstrList[Number-1].Selected:=Not VSTInstrList[Number-1].Selected;
If VSTInstrList[Number-1].Selected Then VSTISelected:=Number;
Self.Invalidate;
If Assigned(fOnVSTInstr_Event) Then Self.fOnVSTInstr_Event(Sender);
End;
Procedure TBrowser.Gen_Grad_Panel;
Var
Index, R1, G1, B1, R2, G2, B2, R3, G3, B3, Border: integer;
begin
Self.Color:=Self.fColorGrad;
R1 := GetRValue(Self.fColorBackGround);
G1 := GetGValue(Self.fColorBackGround);
B1 := GetBValue(Self.fColorBackGround);
R2 := GetRValue(Self.fColorGrad);
G2 := GetGValue(Self.fColorGrad);
B2 := GetBValue(Self.fColorGrad);
Border:=Round(Self.Width*0.1);
For Index := 0 to Border do
begin
R3 := Trunc(((Border - Index) * R1)/Border + (Index * R2)/Border);
G3 := Trunc(((Border - Index) * G1)/Border + (Index * G2)/Border);
B3 := Trunc(((Border - Index) * B1)/Border + (Index * B2)/Border);
Self.Canvas.Pen.Color :=RGB(R3, G3, B3);
Self.Canvas.MoveTo(Index,0);
Self.Canvas.LineTo(Index,Self.Height);
End;
end;
Procedure TBrowser.Paint;
Var
Index, IndexTop:Cardinal;
Begin
Gen_Grad_Panel;
IndexTop:=0;
With fInstrumentPanel Do
Begin
Width:=Self.Width-4;
Height:=30;
Top:=IndexTop*32;
Left:=2;
Color:=Self.fColorPanel;
Caption:='INSTRUMENT';
End;
For Index:=1 To 128 Do
With InstrumentList[Index] Do
Begin
Panel.Width:=Round(Self.Width*0.90)-2;
Panel.Height:=30;
Panel.Top:=32*IndexTop+32;
Panel.Left:=Round(Self.Width*0.1);
If Not Selected Then Panel.Color:=Self.fColorPanel Else
Panel.Color:=Self.fSelectColor;
Panel.Visible:=Self.fInstrumentsVisible;
If Panel.Visible Then Inc(IndexTop);
End;
With fSoundFontPanel Do
Begin
Width:=Self.Width-4;
Height:=30;
Top:=32*IndexTop+32;
Left:=2;
Color:=Self.fColorPanel;
Caption:='SOUNDFONT';
Inc(IndexTop);
End;
If High(SoundFontList)>-1 Then
For Index:=Low(SoundFontList) To High(SoundFontList) Do
With SoundFontList[Index] Do
Begin
Panel.Width:=Round(Self.Width*0.90)-2;
Panel.Height:=30;
Panel.Top:=32*IndexTop+32;
Panel.Left:=Round(Self.Width*0.1);
If Not Selected Then Panel.Color:=Self.fColorPanel Else
Panel.Color:=Self.fSelectColor;
Panel.Visible:=Self.fSoundFontsVisible;
If Panel.Visible Then Inc(IndexTop);
End;
With fAsioPanel Do
Begin
Inc(IndexTop);
Width:=Self.Width-4;
Height:=30;
Top:=IndexTop*32;
Left:=2;
Color:=Self.fColorPanel;
Caption:='ASIO';
End;
If High(AsioList)>-1 Then
For Index:=Low(AsioList) To High(AsioList) Do
With AsioList[Index] Do
Begin
Panel.Width:=Round(Self.Width*0.90)-2;
Panel.Height:=30;
Panel.Top:=32*IndexTop+32;
Panel.Left:=Round(Self.Width*0.1);
If Not Selected Then Panel.Color:=Self.fColorPanel Else
Panel.Color:=Self.fSelectColor;
Panel.Visible:=Self.fAsiosVisible;
If Panel.Visible Then Inc(IndexTop);
End;
With fVSTInstrPanel Do
Begin
Inc(IndexTop);
Width:=Self.Width-4;
Height:=30;
Top:=IndexTop*32;
Left:=2;
Color:=Self.fColorPanel;
Caption:='VST INSTRUMENT';
End;
If High(VSTInstrList)>-1 Then
For Index:=Low(VSTInstrList) To High(VSTInstrList) Do
With VSTInstrList[Index] Do
Begin
Panel.Width:=Round(Self.Width*0.90)-2;
Panel.Height:=30;
Panel.Top:=32*IndexTop+32;
Panel.Left:=Round(Self.Width*0.1);
If Not Selected Then Panel.Color:=Self.fColorPanel Else
Panel.Color:=Self.fSelectColor;
Panel.Visible:=Self.fVSTInstrsVisible;
If Panel.Visible Then Inc(IndexTop);
End;
Self.Height:=(IndexTop+1)*32;
End;
destructor TBrowser.Destroy;
Var
Index:Cardinal;
begin
fInstrumentPanel.Free;
fSoundFontPanel.Free;
fASioPanel.Free;
If High(SoundFontList)>-1 Then
For Index:=0 To High(SoundFontList) Do Self.SoundFontList[Index].Panel.Free;
If High(AsioList)>-1 Then
For Index:=0 To High(AsioList) Do Self.AsioList[Index].Panel.Free;
If High(VSTInstrList)>-1 Then
For Index:=0 To High(VSTInstrList) Do Self.VSTInstrList[Index].Panel.Free;
Finalize(SoundFontList);
Finalize(AsioList);
Finalize(VSTInstrList);
inherited;
end;
procedure TBrowser.MouseDown(Button: TMouseButton;Shift: TShiftState; X, Y: Integer);
Begin
Inherited;
If (Assigned(fPopupMenu)) And (Shift=[ssRight]) Then
fPopupMenu.Popup(ClientOrigin.X+x,ClientOrigin.Y+y);
End;
end.
Désolé pour le pavé

.
Merci à tous
