www.pudn.com > d4psp31.zip > fmTakes.pas, change:1998-09-20,size:3141b


unit fmTakes; 
 
interface 
 
uses 
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, cmpMidiData, cmpMidiInput, cmpTrackOutputs, 
  ComCtrls, StdCtrls; 
 
type 
  TTakesForm = class(TForm) 
    GroupBox1: TGroupBox; 
    lvTakes: TListView; 
    btnSave: TButton; 
    btnDelete: TButton; 
    procedure FormShow(Sender: TObject); 
    procedure FormClose(Sender: TObject; var Action: TCloseAction); 
    procedure FormDestroy(Sender: TObject); 
    procedure lvTakesClick(Sender: TObject); 
    procedure btnDeleteClick(Sender: TObject); 
  private 
  public 
    MidiData : TMidiData; 
    TrackOutputs : TTrackOutputs; 
    MidiInput : TMidiInput; 
 
    procedure Refresh; 
    procedure SetButtons; 
  end; 
 
var 
  TakesForm: TTakesForm; 
 
implementation 
 
uses unitMidiTrackStream, fmMainForm; 
 
{$R *.DFM} 
 
procedure TTakesForm.FormShow(Sender: TObject); 
begin 
  Refresh 
end; 
 
procedure TTakesForm.Refresh; 
var 
  i : Integer; 
  take : TMidiTrackStream; 
begin 
  if Assigned (MidiInput) then 
  begin 
    lvTakes.Items.BeginUpdate; 
    with lvTakes.Items do 
    try 
      Clear; 
      for i := 0 to MidiInput.TakeCount - 1 do 
      begin 
        with Add do 
        begin 
          take := MidiInput.Take [i]; 
          Caption := take.TrackName; 
          SubItems.Add (IntToStr (take.Channel)); 
          SubItems.Add (IntToStr (take.Bank)); 
          SubItems.Add (IntToStr (take.Patch)); 
          Checked := TrackOutputs.IndexOf (take) <> -1 
        end 
      end 
    finally 
      EndUpdate 
    end 
  end; 
  SetButtons; 
end; 
 
procedure TTakesForm.FormClose(Sender: TObject; var Action: TCloseAction); 
begin 
  Action := caFree; 
end; 
 
procedure TTakesForm.FormDestroy(Sender: TObject); 
begin 
  MainForm.TakesFormRemoved 
end; 
 
procedure TTakesForm.lvTakesClick(Sender: TObject); 
var 
  i : Integer; 
  checked : boolean; 
  trackChecked : boolean; 
  take : TMidiTrackStream; 
begin 
  for i := 0 to lvTakes.Items.Count - 1 do 
  begin 
    checked := lvTakes.Items [i].checked; 
    take := MidiInput.Take [i]; 
    if Assigned (take) then 
    begin 
      trackChecked := TrackOutputs.IndexOf (take) <> -1; 
      if checked <> trackChecked then 
        if not trackChecked then 
          TrackOutputs.OpenTrack (take, take.TempPort) 
        else 
          TrackOutputs.TrackOutput [TrackOutputs.IndexOf (take)].Free 
    end 
  end; 
  SetButtons; 
end; 
 
procedure TTakesForm.SetButtons; 
begin 
  btnSave.Enabled := Assigned (lvTakes.Selected); 
  btnDelete.Enabled := Assigned (lvTakes.Selected); 
end; 
 
procedure TTakesForm.btnDeleteClick(Sender: TObject); 
var 
  takeNo : Integer; 
  take : TMidiTrackStream; 
  outputIdx : Integer; 
begin 
  if Assigned (lvTakes.Selected) then 
  begin 
    takeNo := lvTakes.Selected.Index; 
    take := MidiInput.Take [takeNo]; 
    if Assigned (take) then 
    begin 
      outputIdx := TrackOutputs.IndexOf (take); 
      if outputIdx <> -1 then 
        TrackOutputs.TrackOutput [outputIdx].Free; 
      MidiInput.DeleteTake (takeNo); 
      lvTakes.Selected.Delete 
    end 
  end 
end; 
 
end.