📄 fmmainform.pas
字号:
//-----------------------------------------------------
// Step mode public functions
procedure SetStepModeState (value : boolean);
procedure TakesFormRemoved;
//-----------------------------------------------------
// Port & Patch public functions
function GetOutputPortInstrument (index : Integer) : TInstrument;
function GetOutputPortInstrumentName (index : Integer) : string;
procedure SetOutputPortInstrument (index : Integer; fileName : string);
function GetPatchForInstrument (portNo, patch, bank : Integer) : TPatch;
//-----------------------------------------------------
// Form properties
property CurrentTrackNo : Integer read fCurrentTrackNo write SetCurrentTrackNo;
property CurrentPosition : Integer read GetCurrentPosition;
property CurrentTime : Integer read GetCurrentTime;
end;
var
MainForm: TMainForm;
implementation
{$R *.DFM}
uses Reg, Globals, unitMidiTrackStream, fmAboutBox,fmTracksheet, fmNoteEditor, fmEventList, fmTempoMap, fmSelectTrack, fmTrackProperties, fmProgramProperties, fmSongProperties, fmInstruments, cmpMidiOutput, fmGotoPosition, cmpMidiIterator, Clipbrd, fmController;
(*-------------------------------------------------------------------------*
| constructor TMainForm.Create |
| |
| Constructor for main form |
| |
| Parameters: |
| AOwner : TComponent // The form's owner |
*-------------------------------------------------------------------------*)
constructor TMainForm.Create (AOwner : TComponent);
var
i : Integer;
numDevs : Integer;
inCaps : TMidiInCaps;
begin
ShowInitialTracksheet := True;
ActiveForms := TList.Create; // Create the active forms list
fCurrentTrackNo := 1;
DragNoteVolume := 64;
// Create the input port list
midiInputPorts := TStringList.Create;
numDevs := MidiInGetNumDevs;
for i := 0 to numDevs - 1 do
begin
midiInGetDevCaps (i, @inCaps, sizeof (inCaps));
midiInputPorts.AddObject (inCaps.szPName, TBoolVal.Create);
end;
// Create the output port list
midiOutputPorts := TList.Create;
// Read properties
inherited Create (AOwner);
end;
(*-------------------------------------------------------------------------*
| destructor TMainForm.Destroy |
| |
| Free the input ports list, output ports list and associated instruments |
| and the active form list. |
*-------------------------------------------------------------------------*)
destructor TMainForm.Destroy;
var
i : Integer;
port : TMidiOutputPortDetails;
begin
for i := 0 to MidiInputPorts.Count-1 do
TBoolVal (MidiInputPorts.objects [i]).Free;
MidiInputPorts.Free; // Free the input ports list
// Free the output ports details list
// and associated instruments
for i := 0 to MidiOutputPorts.Count - 1 do
begin
port := TMidiOutputPortDetails (MidiOutputPorts.Items [i]);
if Assigned (port.Instrument) then
port.Instrument.Free;
port.Free
end;
MidiOutputPorts.Free;
ActiveForms.Free; // Free the active forms list
inherited
end;
//==========================================================================
// Form event handlers
(*-------------------------------------------------------------------------*
| procedure TMainForm.FormShow () |
| |
| |
| |
| Parameters: |
| Sender : TObject // The event sender |
| |
| The function returns |
*-------------------------------------------------------------------------*)
procedure TMainForm.FormShow(Sender: TObject);
var i : Integer;
begin
ReadProperties;
for i := 0 to MidiInputPorts.Count - 1 do
if TBoolVal (MidiInputPorts.Objects [i]).val then
MidiInput.OpenPorts [i] := True;
// Open the MIDI input ports.
if ParamCount > 0 then // Open the 'command line' file
try
OpenSong (ParamStr (1)) // ... supports drag 'n' drop
except
MessageDlg ('Unable to open ' + ParamStr (1), mtWarning, [mbOk], 0);
NewSong;
end
else NewSong; // nb. Both Open Song & New Song display
// the initial track sheet if required,
// and initialise the whole dang thing.
end;
(*-------------------------------------------------------------------------*
| procedure TMainForm.FormCloseQuery |
| |
| Try to close the song. If there've been changes, but the save is |
| cancelled, don't terminate. |
| |
| Parameters: |
| Sender : TObject // The event sender |
*-------------------------------------------------------------------------*)
procedure TMainForm.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
CanClose := CloseSong
end;
//==========================================================================
// File menu event handlers
(*-------------------------------------------------------------------------*
| procedure TMainForm.FileNewClick |
| |
| Respond to a 'new song' menu event. |
| |
| Parameters: |
| Sender : TObject // The event sender |
*-------------------------------------------------------------------------*)
procedure TMainForm.FileNewSongClick(Sender: TObject);
begin
if CloseSong then // First, try to close the old song.
NewSong
end;
(*-------------------------------------------------------------------------*
| procedure TMainForm.FileOpenSongClick |
| |
| Respond to a 'FileOpen' event. |
| |
| Parameters: |
| Sender : TObject // The event sender |
*-------------------------------------------------------------------------*)
procedure TMainForm.FileOpenSongClick(Sender: TObject);
begin
OpenSongDialog.FileName := MidiData.FileName;
OpenSongDialog.InitialDir := MidiDir;
if OpenSongDialog.Execute then // Do the 'open file' dialog
if CloseSong then // Try to close the old song
OpenSong (OpenSongDialog.FileName);
end;
(*-------------------------------------------------------------------------*
| procedure TMainForm.FileSaveSongClick |
| |
| Respond to 'save song' messages. |
| |
| Parameters: |
| Sender : TObject // The event sender |
*-------------------------------------------------------------------------*)
procedure TMainForm.FileSaveSongClick(Sender: TObject);
begin
SaveSong
end;
(*-------------------------------------------------------------------------*
| procedure TMainForm.FileSaveSongAsClick |
| |
| Respond to 'save song as' messages |
| |
| Parameters: |
| Sender : TObject // The event sender |
*-------------------------------------------------------------------------*)
procedure TMainForm.FileSaveSongAsClick(Sender: TObject);
begin
SaveSongAs
end;
(*-------------------------------------------------------------------------*
| procedure TMainForm.FilePrintClick |
| |
| Respond to 'File print' events |
| |
| Parameters: |
| Sender : TObject // The event sender |
*-------------------------------------------------------------------------*)
procedure TMainForm.FilePrintClick(Sender: TObject);
begin
if PrintDialog.Execute then
end;
procedure TMainForm.ResetPatchNames;
var
i : Integer;
PatchRec : TPatch;
begin
for i := 0 to MidiData.NoTracks - 1 do
with MidiData.Tracks [i] do
begin
PatchRec := GetPatchForInstrument (trackOutputs.GetTrackPortID (i), Patch, Bank);
if Assigned (patchRec) then
InstrumentName := PatchRec.PatchName
else
InstrumentName := ''
end
end;
(*-------------------------------------------------------------------------*
| procedure TMainForm.FilePropertiesClick |
| |
| Respond to 'FileProperties' events. |
| |
| Parameters: |
| Sender : TObject // The event sender |
*-------------------------------------------------------------------------*)
procedure TMainForm.FilePropertiesClick(Sender: TObject);
var
dialog : TProgramProperties;
registry : TReg;
i, idx : Integer;
Item : TListItem;
extItem : TListItem;
OutputPort : TMidiOutputPortDetails;
begin // Create and fill in the dialog...
dialog := TProgramProperties.Create (Self);
try
dialog.cbShowHints.Checked := ShowHint;
dialog.cbInitialTracksheet.Checked := ShowInitialTracksheet;
dialog.cbAutoSynchronize.Checked := AutoSynchronize;
dialog.udDragNoteVolume.Position := DragNoteVolume;
dialog.cbBoostPlaybackPriority.Checked := MidiPlayer.BoostPriority;
// Fill in 'output ports' list view
for i := 0 to MidiOutputPorts.Count - 1 do
begin
extItem := dialog.elvOutputPorts.Items.Add;
extItem.caption := IntToStr (i);
extItem.SubItems.Add (TMidiOutputPortDetails (MidiOutputPorts.Items [i]).Name);
extItem.SubItems.Add (ExtractInstrumentName (TMidiOutputPortDetails (MidiOutputPorts.Items [i]).InstrumentName));
end;
// Fill in 'input ports' list views
for i := 0 to MidiInputPorts.Count - 1 do
begin
if TBoolVal (MidiInputPorts.Objects [i]).val then
item := dialog.lvSelectedPorts.items.Add
else
item := dialog.lvUnSelectedPorts.items.Add;
item.caption := MidiInputPorts.Strings [i]
end;
Dialog.DefaultPortNo := TrackOutputs.DefaultOutputPort;
// Do the dialog...
if dialog.ShowModal = mrOk then
begin
registry := TReg.Create (HKEY_CURRENT_USER, ProgramKey + '\' + PropertiesKey, True);
try // Save the new 'ShowHints' value
if dialog.cbShowHints.Checked <> ShowHint then
begin
// Set 'ShowHint' form property here...
ShowHint := dialog.cbShowHints.Checked;
Registry.WriteBoolean (ShowHintsValue, ShowHint);
end;
// Save the new 'InitialTracksheet' value
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -