-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmidiselectcode.pas
More file actions
98 lines (71 loc) · 2.7 KB
/
midiselectcode.pas
File metadata and controls
98 lines (71 loc) · 2.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
(* Lazarus+FPC 2.2.6+3.2.2 on Linux Lazarus+FPC 2.2.6+3.2.2 on Linux Lazarus+FP *)
unit MidiSelectCode;
(* Select a MIDI synthesiser device. MarkMLl *)
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, ExtCtrls;
type
{ TMidiSelectForm }
TMidiSelectForm = class(TForm)
ButtonOK: TButton;
ButtonCancel: TButton;
PanelBottom: TPanel;
RadioGroup1: TRadioGroup;
private
public
(* The parameter contains a list of MIDI devices. Either delete the ones we don't
want to use (i.e. all but one) and their associated objects or leave them all
intact.
*)
procedure Select(dl: TStringList);
end;
var
MidiSelectForm: TMidiSelectForm;
implementation
{$R *.lfm}
(* The parameter contains a list of MIDI devices. Either delete the ones we don't
want to use (i.e. all but one) and their associated objects or leave them all
intact.
*)
procedure TMidiSelectForm.Select(dl: TStringList);
var
i: integer;
begin
(* A runtime error here might mean that the form has not been properly *)
(* created using a statement like *)
(* *)
(* Application.CreateForm(TMidiSelectForm, MidiSelectForm); *)
(* *)
(* in the main .lpr file. I have seen the Lazarus IDE remove this line when it *)
(* was governed by manually-inserted conditional compilation directives and the *)
(* controlling definition was changed in the project inspector. *)
Left := (Application.MainForm.Left + Width DIV 2 + Screen.Width DIV 2) DIV 2;
Top := (Application.MainForm.Top + Height DIV 2 + Screen.Height DIV 2) DIV 2;
RadioGroup1.Items.Clear;
for i := 0 to dl.Count - 1 do
RadioGroup1.Items.Add(dl[i]);
RadioGroup1.ItemIndex := 0;
(* Normally, if there is only a single item then there is no point in asking *)
(* the user which one he wants. However allow it to be enabled (by commenting *)
(* out the two lines below) for debugging, or if the operator has explicit *)
(* instructions to select a MIDI device and verify that it is working. *)
{ if RadioGroup1.Items.Count < 2 then
exit; }
case ShowModal of
mrOk: for i := dl.Count - 1 downto 0 do
if i <> RadioGroup1.itemIndex then begin
if dl.Objects[i] <> nil then
dl.Objects[i].free;
dl.Delete(i)
end
otherwise
(* Special case: the user has not hit OK but there is only a single device. *)
(* Delete it so that the caller doesn't think we mean "use this one". *)
if dl.Count = 1 then
if dl.Objects[0] <> nil then
dl.Objects[0].free;
dl.Delete(0)
end
end { TMidiSelectForm.Select } ;
end.