📄 fmeventlist.pas
字号:
unit fmEventList;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
fmPower, Grids, cmpMidiGrid, cmpMidiData, ComCtrls, Menus, Buttons,
ExtCtrls, unitMidiTrackStream;
type
TEventListForm = class(TPowerForm)
PopupMenu1: TPopupMenu;
poSelectTrack: TMenuItem;
N1: TMenuItem;
poEdit: TMenuItem;
poInsert: TMenuItem;
poDelete: TMenuItem;
MidiGrid1: TMidiGrid;
HeaderControl1: THeaderControl;
procedure FormShow(Sender: TObject);
procedure poSelectTrackClick(Sender: TObject);
procedure FormResize(Sender: TObject);
procedure HeaderControl1SectionResize(HeaderControl: THeaderControl;
Section: THeaderSection);
procedure poEditClick(Sender: TObject);
procedure MidiGrid1DblClick(Sender: TObject);
private
fCurrentTrack : TMidiTrackStream;
procedure SetRowForPosition (position : Integer);
procedure EditSelectedEvent;
protected
procedure AdjustHeader;
procedure AdjustGrid;
public
procedure Notify (tp : TActiveFormNotify); override;
end;
var
EventListForm: TEventListForm;
implementation
{$R *.DFM}
uses fmMainForm, commctrl, fmEventProperties;
procedure TEventListForm.FormShow(Sender: TObject);
begin
inherited;
with HeaderControl1 do
SetWindowLong (Handle, GWL_STYLE, GetWindowLong (HeaderControl1.Handle, GWL_STYLE) and not HDS_BUTTONS);
AdjustHeader;
MidiGrid1.MidiData := MainForm.MidiData;
MidiGrid1.Track := MainForm.CurrentTrackNo;
fCurrentTrack := MainForm.MidiData.Tracks [MainForm.CurrentTrackNo];
SetCaption ('Event List', MidiGrid1.Track);
end;
const
Sections = 6;
SectionLoadings : array [0..Sections - 1] of Integer = (12, 13, 10, 30, 20, 10);
MaxLoadings = 95;
procedure TEventListForm.AdjustHeader;
var i, width : Integer;
begin
width := MidiGrid1.ClientWidth;
for i := 0 to Sections - 2 do
HeaderControl1.Sections [i].Width := width * SectionLoadings [i] div MaxLoadings;
AdjustGrid;
end;
procedure TEventListForm.AdjustGrid;
var i, totWidth : Integer;
begin
totWidth := 0;
for i := 0 to Sections - 2 do
Inc (totWidth, HeaderControl1.Sections [i].width);
HeaderControl1.Sections [Sections - 1].width := MidiGrid1.ClientWidth - totWidth;
MidiGrid1.ColWidths [0] := HeaderControl1.Sections [0].Width - 3;
for i := 1 to Sections - 1 do
MidiGrid1.ColWidths [i] := HeaderControl1.Sections [i].Width - 1
end;
procedure TEventListForm.poSelectTrackClick(Sender: TObject);
var
trackNo : Integer;
begin
inherited;
trackNo := MidiGrid1.Track;
if MainForm.SelectTrackDialog (trackNo, True, False) then
begin
MidiGrid1.Track := trackNo;
fCurrentTrack := MainForm.MidiData.Tracks [trackNo];
SetCaption ('Event List', MidiGrid1.Track);
end
end;
procedure TEventListForm.SetRowForPosition (position : Integer);
var
idx : Integer;
begin
if Assigned (fCurrentTrack) then
begin
idx := fCurrentTrack.FindEventNo (position , feFirst);
if (idx = -1) or (idx >= fCurrentTrack.EventCount) then
idx := fCurrentTrack.EventCount - 1
else
if fCurrentTrack.Event [idx]^.pos <> position then
Dec (idx);
MidiGrid1.row := idx;
end
end;
procedure TEventListForm.Notify (tp : TActiveFormNotify);
begin
case tp of
ntFullUpdate :
begin
SetCaption ('Event List', MidiGrid1.Track);
with MidiGrid1 do if RowCount <> MidiData.Tracks [Track].EventCount then
MidiGrid1.RowCount := MidiData.Tracks [Track].EventCount
else
MidiGrid1.Refresh
end;
ntPositionUpdate :
begin
SetRowForPosition (MainForm.CurrentPosition);
end
end
end;
procedure TEventListForm.FormResize(Sender: TObject);
begin
inherited;
AdjustHeader;
end;
procedure TEventListForm.HeaderControl1SectionResize(
HeaderControl: THeaderControl; Section: THeaderSection);
var
i, idx, widthLeft, sectionsLeft : Integer;
begin
for idx := 0 to Sections - 1 do
if Section = HeaderControl.Sections [idx] then
break;
widthLeft := MidiGrid1.ClientWidth;
for i := 0 to idx do
Dec (widthLeft, HeaderControl1.Sections [i].Width);
sectionsLeft := 0;
for i := idx + 1 to Sections - 1 do
Inc (sectionsLeft, sectionLoadings [i]);
for i := idx + 1 to Sections - 2 do
HeaderControl1.Sections [i].Width := widthLeft * SectionLoadings [i] div sectionsLeft;
AdjustGrid;
end;
procedure TEventListForm.poEditClick(Sender: TObject);
begin
inherited;
EditSelectedEvent
end;
procedure TEventListForm.MidiGrid1DblClick(Sender: TObject);
begin
inherited;
EditSelectedEvent
end;
procedure TEventListForm.EditSelectedEvent;
begin
with TfmEditEvent.Create (self) do
try
ShowModal
finally
Free
end
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -