| 1 |
unit mainf; |
| 2 |
|
| 3 |
{$mode objfpc}{$H+} |
| 4 |
|
| 5 |
interface |
| 6 |
|
| 7 |
uses |
| 8 |
Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, Spin, |
| 9 |
StdCtrls, Buttons, CastleSoundEngine, ExtCtrls, Grids, EditBtn; |
| 10 |
|
| 11 |
type |
| 12 |
{ TMain } |
| 13 |
|
| 14 |
TMain = class(TForm) |
| 15 |
ApplicationProperties1: TApplicationProperties; |
| 16 |
ButtonAllocateAndPlay: TButton; |
| 17 |
ButtonApplyAllocatorLimits: TButton; |
| 18 |
ButtonApplyAllocatorLimitsDefault: TButton; |
| 19 |
CheckKeepRefreshingUsed: TCheckBox; |
| 20 |
CheckBoxPlayLooping: TCheckBox; |
| 21 |
FileNameEditSound: TFileNameEdit; |
| 22 |
LabelDescription: TLabel; |
| 23 |
Label2: TLabel; |
| 24 |
Label3: TLabel; |
| 25 |
LabelTitle: TLabel; |
| 26 |
LabelMaxAllocatedSources: TLabel; |
| 27 |
LabelMinAllocatedSources: TLabel; |
| 28 |
LabelSourceImportance: TLabel; |
| 29 |
ListAllocatedSources: TListBox; |
| 30 |
ListUsedSources1: TListBox; |
| 31 |
PanelSourcePlaying: TPanel; |
| 32 |
PanelAllocatorLimits: TPanel; |
| 33 |
PanelLists: TPanel; |
| 34 |
SpinEditSourceImportance: TSpinEdit; |
| 35 |
SpinEditMaxAllocatedSources: TSpinEdit; |
| 36 |
SpinEditMinAllocatedSources: TSpinEdit; |
| 37 |
TimerToRefreshUsedSounds: TTimer; |
| 38 |
TimerToDisplaySounds: TTimer; |
| 39 |
procedure ButtonAllocateAndPlayClick(Sender: TObject); |
| 40 |
procedure ButtonApplyAllocatorLimitsClick(Sender: TObject); |
| 41 |
procedure ButtonApplyAllocatorLimitsDefaultClick(Sender: TObject); |
| 42 |
procedure FormCreate(Sender: TObject); |
| 43 |
procedure TimerToDisplaySoundsTimer(Sender: TObject); |
| 44 |
procedure TimerToRefreshUsedSoundsTimer(Sender: TObject); |
| 45 |
public |
| 46 |
{ public declarations } |
| 47 |
end; |
| 48 |
|
| 49 |
var |
| 50 |
Main: TMain; |
| 51 |
|
| 52 |
implementation |
| 53 |
|
| 54 |
uses CastleVectors, CastleUtils, CastleStringUtils, CastleApplicationProperties, |
| 55 |
CastleLCLUtils; |
| 56 |
|
| 57 |
procedure TMain.FormCreate(Sender: TObject); |
| 58 |
begin |
| 59 |
ButtonApplyAllocatorLimitsDefault.Caption:= Format('Set Min / Max allocated sources to Defaults (%d / %d)', [ |
| 60 |
TSoundAllocator.DefaultMinAllocatedSources, |
| 61 |
TSoundAllocator.DefaultMaxAllocatedSources |
| 62 |
]); |
| 63 |
SoundEngine.MinAllocatedSources := SpinEditMinAllocatedSources.Value; |
| 64 |
SoundEngine.MaxAllocatedSources := SpinEditMaxAllocatedSources.Value; |
| 65 |
SoundEngine.ContextOpen; |
| 66 |
TimerToDisplaySounds.Enabled := true; |
| 67 |
FileFiltersToDialog(LoadSound_FileFilters, FileNameEditSound); |
| 68 |
end; |
| 69 |
|
| 70 |
procedure TMain.ButtonApplyAllocatorLimitsClick(Sender: TObject); |
| 71 |
begin |
| 72 |
SoundEngine.MinAllocatedSources := SpinEditMinAllocatedSources.Value; |
| 73 |
SoundEngine.MaxAllocatedSources := SpinEditMaxAllocatedSources.Value; |
| 74 |
end; |
| 75 |
|
| 76 |
procedure TMain.ButtonApplyAllocatorLimitsDefaultClick(Sender: TObject); |
| 77 |
begin |
| 78 |
SpinEditMinAllocatedSources.Value := TSoundAllocator.DefaultMinAllocatedSources; |
| 79 |
SpinEditMaxAllocatedSources.Value := TSoundAllocator.DefaultMaxAllocatedSources; |
| 80 |
ButtonApplyAllocatorLimitsClick(nil); |
| 81 |
end; |
| 82 |
|
| 83 |
procedure TMain.ButtonAllocateAndPlayClick(Sender: TObject); |
| 84 |
var |
| 85 |
Sound: TCastleSound; |
| 86 |
PlayingSound: TCastlePlayingSound; |
| 87 |
begin |
| 88 |
Sound := TCastleSound.Create(Self); |
| 89 |
Sound.Url := FileNameEditSound.FileName; |
| 90 |
Sound.Priority := SpinEditSourceImportance.Value; // TODO: should be in 0..1 range |
| 91 |
|
| 92 |
PlayingSound := TCastlePlayingSound.Create(Self); |
| 93 |
PlayingSound.Sound := Sound; |
| 94 |
PlayingSound.Loop := CheckBoxPlayLooping.Checked; |
| 95 |
PlayingSound.FreeOnStop := true; |
| 96 |
|
| 97 |
SoundEngine.Play(PlayingSound); |
| 98 |
end; |
| 99 |
|
| 100 |
procedure TMain.TimerToDisplaySoundsTimer(Sender: TObject); |
| 101 |
var |
| 102 |
I: Integer; |
| 103 |
S: string; |
| 104 |
begin |
| 105 |
ListAllocatedSources.Clear; |
| 106 |
// SoundEngine.AllocatedSources will be nil if sound backend initialization failed |
| 107 |
if SoundEngine.InternalAllocatedSources <> nil then |
| 108 |
for I := 0 to SoundEngine.InternalAllocatedSources.Count - 1 do |
| 109 |
begin |
| 110 |
S := Format('%d: Sound source used: %5s', [ |
| 111 |
I, |
| 112 |
BoolToStr(SoundEngine.InternalAllocatedSources[I].Used, true) |
| 113 |
]); |
| 114 |
ListAllocatedSources.Items.Append(S); |
| 115 |
end; |
| 116 |
end; |
| 117 |
|
| 118 |
procedure TMain.TimerToRefreshUsedSoundsTimer(Sender: TObject); |
| 119 |
begin |
| 120 |
if CheckKeepRefreshingUsed.Checked then |
| 121 |
{ calling TCastleApplicationProperties._Update will cause |
| 122 |
updating used sound sources in SoundEngine. } |
| 123 |
ApplicationProperties._Update; |
| 124 |
end; |
| 125 |
|
| 126 |
initialization |
| 127 |
{$I mainf.lrs} |
| 128 |
end. |
| 129 |
|