Blame lazarus/alarm-clock/unit1.pas

bcc3f9
unit Unit1;
bcc3f9
bcc3f9
{$mode objfpc}{$H+}
bcc3f9
bcc3f9
interface
bcc3f9
bcc3f9
uses
bcc3f9
  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, EditBtn,
bcc3f9
  StdCtrls, ExtCtrls, DateUtils, OpenAL;
bcc3f9
bcc3f9
type
bcc3f9
bcc3f9
  { TForm1 }
bcc3f9
bcc3f9
  TForm1 = class(TForm)
bcc3f9
    CheckBox1: TCheckBox;
bcc3f9
    Label1: TLabel;
bcc3f9
    TimeEdit1: TTimeEdit;
bcc3f9
    TimeEdit2: TTimeEdit;
bcc3f9
    TimeEdit3: TTimeEdit;
bcc3f9
    Timer1: TTimer;
bcc3f9
    procedure FormCreate(Sender: TObject);
bcc3f9
    procedure Timer1Timer(Sender: TObject);
bcc3f9
  private
bcc3f9
    { private declarations }
bcc3f9
  public
bcc3f9
    { public declarations }
bcc3f9
  end;
bcc3f9
bcc3f9
var
bcc3f9
  Form1: TForm1;
bcc3f9
bcc3f9
implementation
bcc3f9
bcc3f9
{$R *.lfm}
bcc3f9
bcc3f9
// This procedure plays beep via OpenAL
bcc3f9
// you don't need to understand how it works for now
bcc3f9
// just use it if SysUtils.Beep does not works
bcc3f9
procedure Beep;
bcc3f9
const
bcc3f9
  frequency = 440;
bcc3f9
  rate = 10000;
bcc3f9
  count = 2000;
bcc3f9
var
bcc3f9
  i: Integer;
bcc3f9
  samples: array[0..count-1] of Smallint;
bcc3f9
  device: PALCdevice;
bcc3f9
  context: PALCcontext;
bcc3f9
  buffer: ALuint;
bcc3f9
  source: ALuint;
bcc3f9
begin
bcc3f9
  for i := 0 to count-1 do
bcc3f9
    samples[i] := Round(32760*sin(2*pi*i*frequency/rate));
bcc3f9
bcc3f9
  device := alcOpenDevice(nil);
bcc3f9
  context := alcCreateContext(device, nil);
bcc3f9
  alcMakeContextCurrent(context);
bcc3f9
bcc3f9
  alGenBuffers(1, @buffer);
bcc3f9
  alBufferData(buffer, AL_FORMAT_MONO16, @samples, SizeOf(samples), rate);
bcc3f9
  alGenSources(1, @source);
bcc3f9
  alSourcei(source, AL_BUFFER, buffer);
bcc3f9
  alSourcePlay(source);
bcc3f9
  Sleep(Round(count/rate*1000 + 10));
bcc3f9
bcc3f9
  alcMakeContextCurrent(nil);
bcc3f9
  alcDestroyContext(context);
bcc3f9
  alcCloseDevice(device);
bcc3f9
end;
bcc3f9
bcc3f9
bcc3f9
{ TForm1 }
bcc3f9
bcc3f9
procedure TForm1.Timer1Timer(Sender: TObject);
bcc3f9
begin
bcc3f9
  if CheckBox1.Checked then begin
bcc3f9
    if HourOf(TimeEdit1.Time) = HourOf(Time) then begin
bcc3f9
      if MinuteOf(TimeEdit1.Time) = MinuteOf(Time) then begin
bcc3f9
        Beep;
bcc3f9
      end;
bcc3f9
    end;
bcc3f9
bcc3f9
    if HourOf(TimeEdit2.Time) = HourOf(Time) then begin
bcc3f9
      if MinuteOf(TimeEdit2.Time) = MinuteOf(Time) then begin
bcc3f9
        Beep;
bcc3f9
      end;
bcc3f9
    end;
bcc3f9
bcc3f9
    if HourOf(TimeEdit3.Time) = HourOf(Time) then begin
bcc3f9
      if MinuteOf(TimeEdit3.Time) = MinuteOf(Time) then begin
bcc3f9
        Beep;
bcc3f9
      end;
bcc3f9
    end;
bcc3f9
  end;
bcc3f9
end;
bcc3f9
bcc3f9
procedure TForm1.FormCreate(Sender: TObject);
bcc3f9
begin
bcc3f9
  TimeEdit1.Time := IncMinute(Time, 1);
bcc3f9
  TimeEdit2.Time := IncMinute(Time, 5);
bcc3f9
  TimeEdit3.Time := IncHour(Time, 1);
bcc3f9
end;
bcc3f9
bcc3f9
end.
bcc3f9