From bcc3f921af1b24df86594e50abf1a028d42b54c1 Mon Sep 17 00:00:00 2001 From: Ivan Mahonin Date: Jan 18 2019 13:53:08 +0000 Subject: lazarus: alarm-clock --- diff --git a/lazarus/alarm-clock/project1.ico b/lazarus/alarm-clock/project1.ico new file mode 100644 index 0000000..0341321 Binary files /dev/null and b/lazarus/alarm-clock/project1.ico differ diff --git a/lazarus/alarm-clock/project1.lpi b/lazarus/alarm-clock/project1.lpi new file mode 100644 index 0000000..c490021 --- /dev/null +++ b/lazarus/alarm-clock/project1.lpi @@ -0,0 +1,80 @@ + + + + + + + + + <ResourceType Value="res"/> + <UseXPManifest Value="True"/> + <Icon Value="0"/> + </General> + <i18n> + <EnableI18N LFM="False"/> + </i18n> + <VersionInfo> + <StringTable ProductVersion=""/> + </VersionInfo> + <BuildModes Count="1"> + <Item1 Name="Default" Default="True"/> + </BuildModes> + <PublishOptions> + <Version Value="2"/> + </PublishOptions> + <RunParams> + <local> + <FormatVersion Value="1"/> + </local> + </RunParams> + <RequiredPackages Count="1"> + <Item1> + <PackageName Value="LCL"/> + </Item1> + </RequiredPackages> + <Units Count="2"> + <Unit0> + <Filename Value="project1.lpr"/> + <IsPartOfProject Value="True"/> + </Unit0> + <Unit1> + <Filename Value="unit1.pas"/> + <IsPartOfProject Value="True"/> + <ComponentName Value="Form1"/> + <HasResources Value="True"/> + <ResourceBaseClass Value="Form"/> + <UnitName Value="Unit1"/> + </Unit1> + </Units> + </ProjectOptions> + <CompilerOptions> + <Version Value="11"/> + <Target> + <Filename Value="project1"/> + </Target> + <SearchPaths> + <IncludeFiles Value="$(ProjOutDir)"/> + <UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)"/> + </SearchPaths> + <Linking> + <Options> + <Win32> + <GraphicApplication Value="True"/> + </Win32> + </Options> + </Linking> + </CompilerOptions> + <Debugging> + <Exceptions Count="3"> + <Item1> + <Name Value="EAbort"/> + </Item1> + <Item2> + <Name Value="ECodetoolError"/> + </Item2> + <Item3> + <Name Value="EFOpenError"/> + </Item3> + </Exceptions> + </Debugging> +</CONFIG> diff --git a/lazarus/alarm-clock/project1.lpr b/lazarus/alarm-clock/project1.lpr new file mode 100644 index 0000000..58c35dc --- /dev/null +++ b/lazarus/alarm-clock/project1.lpr @@ -0,0 +1,21 @@ +program project1; + +{$mode objfpc}{$H+} + +uses + {$IFDEF UNIX}{$IFDEF UseCThreads} + cthreads, + {$ENDIF}{$ENDIF} + Interfaces, // this includes the LCL widgetset + Forms, Unit1 + { you can add units after this }; + +{$R *.res} + +begin + RequireDerivedFormResource:=True; + Application.Initialize; + Application.CreateForm(TForm1, Form1); + Application.Run; +end. + diff --git a/lazarus/alarm-clock/project1.res b/lazarus/alarm-clock/project1.res new file mode 100644 index 0000000..e994dfa Binary files /dev/null and b/lazarus/alarm-clock/project1.res differ diff --git a/lazarus/alarm-clock/unit1.lfm b/lazarus/alarm-clock/unit1.lfm new file mode 100644 index 0000000..ee9d584 --- /dev/null +++ b/lazarus/alarm-clock/unit1.lfm @@ -0,0 +1,62 @@ +object Form1: TForm1 + Left = 373 + Height = 235 + Top = 306 + Width = 265 + Caption = 'Form1' + ClientHeight = 235 + ClientWidth = 265 + OnCreate = FormCreate + LCLVersion = '1.6.2.0' + object TimeEdit1: TTimeEdit + Left = 8 + Height = 38 + Top = 80 + Width = 103 + ButtonWidth = 23 + NumGlyphs = 1 + MaxLength = 0 + TabOrder = 0 + end + object CheckBox1: TCheckBox + Left = 128 + Height = 25 + Top = 80 + Width = 110 + Caption = 'Enable Alarm' + TabOrder = 1 + end + object TimeEdit2: TTimeEdit + Left = 8 + Height = 38 + Top = 128 + Width = 103 + ButtonWidth = 23 + NumGlyphs = 1 + MaxLength = 0 + TabOrder = 2 + end + object TimeEdit3: TTimeEdit + Left = 8 + Height = 38 + Top = 176 + Width = 103 + ButtonWidth = 23 + NumGlyphs = 1 + MaxLength = 0 + TabOrder = 3 + end + object Label1: TLabel + Left = 8 + Height = 63 + Top = 7 + Width = 213 + Caption = 'Set following three alarm clocks,'#10'enable alarm'#10'and take a sleep.' + ParentColor = False + end + object Timer1: TTimer + OnTimer = Timer1Timer + left = 184 + top = 120 + end +end diff --git a/lazarus/alarm-clock/unit1.pas b/lazarus/alarm-clock/unit1.pas new file mode 100644 index 0000000..8a8c243 --- /dev/null +++ b/lazarus/alarm-clock/unit1.pas @@ -0,0 +1,106 @@ +unit Unit1; + +{$mode objfpc}{$H+} + +interface + +uses + Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, EditBtn, + StdCtrls, ExtCtrls, DateUtils, OpenAL; + +type + + { TForm1 } + + TForm1 = class(TForm) + CheckBox1: TCheckBox; + Label1: TLabel; + TimeEdit1: TTimeEdit; + TimeEdit2: TTimeEdit; + TimeEdit3: TTimeEdit; + Timer1: TTimer; + procedure FormCreate(Sender: TObject); + procedure Timer1Timer(Sender: TObject); + private + { private declarations } + public + { public declarations } + end; + +var + Form1: TForm1; + +implementation + +{$R *.lfm} + +// This procedure plays beep via OpenAL +// you don't need to understand how it works for now +// just use it if SysUtils.Beep does not works +procedure Beep; +const + frequency = 440; + rate = 10000; + count = 2000; +var + i: Integer; + samples: array[0..count-1] of Smallint; + device: PALCdevice; + context: PALCcontext; + buffer: ALuint; + source: ALuint; +begin + for i := 0 to count-1 do + samples[i] := Round(32760*sin(2*pi*i*frequency/rate)); + + device := alcOpenDevice(nil); + context := alcCreateContext(device, nil); + alcMakeContextCurrent(context); + + alGenBuffers(1, @buffer); + alBufferData(buffer, AL_FORMAT_MONO16, @samples, SizeOf(samples), rate); + alGenSources(1, @source); + alSourcei(source, AL_BUFFER, buffer); + alSourcePlay(source); + Sleep(Round(count/rate*1000 + 10)); + + alcMakeContextCurrent(nil); + alcDestroyContext(context); + alcCloseDevice(device); +end; + + +{ TForm1 } + +procedure TForm1.Timer1Timer(Sender: TObject); +begin + if CheckBox1.Checked then begin + if HourOf(TimeEdit1.Time) = HourOf(Time) then begin + if MinuteOf(TimeEdit1.Time) = MinuteOf(Time) then begin + Beep; + end; + end; + + if HourOf(TimeEdit2.Time) = HourOf(Time) then begin + if MinuteOf(TimeEdit2.Time) = MinuteOf(Time) then begin + Beep; + end; + end; + + if HourOf(TimeEdit3.Time) = HourOf(Time) then begin + if MinuteOf(TimeEdit3.Time) = MinuteOf(Time) then begin + Beep; + end; + end; + end; +end; + +procedure TForm1.FormCreate(Sender: TObject); +begin + TimeEdit1.Time := IncMinute(Time, 1); + TimeEdit2.Time := IncMinute(Time, 5); + TimeEdit3.Time := IncHour(Time, 1); +end; + +end. +