Blob Blame Raw
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.