Accueil > > > CHRONOMÈTRE POUR LE THÉ
CHRONOMÈTRE POUR LE THÉ
Information sur la source
Description
Dans la lignée des sources pas très innovantes voici un chronomètre avec une sonnerie. Bon je sais il en existe d'autres sur le site, mais celui-ci crée lui-même le son qu'il produit lorsqu'il sonne (en générant une oscillation périodique en créneaux dans le buffer de la carte son). La bonne nouvelle c'est que le composant TWaveOut (voir http://www.delphifr.com/codes/PROGRAMME-MIX-AUDIO- APPRENTI-DJ_33254.aspx) est créé au runtime donc pas besoin d'installer le package. Je l'utilise pour faire infuser le thé, et éviter de me retrouver avec un liquide tout noir imbuvable parce que je l'ai oublié :-) Les paramètres (durée du compte à rebours, position de la fenêtre) sont enregistrés dans un fichier ini.
Source
- unit Unit1;
-
- interface
-
- uses
- Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
- Dialogs, StdCtrls, ExtCtrls, Buttons, WaveBase, WaveOut, IniFiles;
-
- type
- TForm1 = class(TForm)
- Timer1: TTimer;
- Label1: TLabel;
- Label2: TLabel;
- SpeedButton1: TSpeedButton;
- procedure FormCreate(Sender: TObject);
- procedure Timer1Timer(Sender: TObject);
- procedure SpeedButton1Click(Sender: TObject);
- procedure FormKeyDown(Sender: TObject; var Key: Word;
- Shift: TShiftState);
- procedure WaveOut1Buffer(Buffer: Pointer; Length: Cardinal;
- BufferQueueLength: Integer);
- procedure FormClose(Sender: TObject; var Action: TCloseAction);
- procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
- Shift: TShiftState; X, Y: Integer);
- private
- public
- FFirstTick,FDeltaSound,FSoundIntensity:Integer;
- FFlash:Boolean;
- WaveOut1: TWaveOut;
- end;
-
- var
- Form1: TForm1;
- GTotalTime:Integer;
-
- const
- GMillisecondsPerDay=3600*1000*24;
-
- implementation
-
- {$R *.dfm}
-
- procedure TForm1.FormCreate(Sender: TObject);
- var
- f:TIniFile;
- h1,h2:HRGN;
- const
- Rounding=15;
- begin
- WaveOut1:=TWaveOut.Create(Self);
- WaveOut1.Bits16:=True;
- WaveOut1.BufferSize:=2048;
- WaveOut1.DeviceID:=-1;
- WaveOut1.OnBuffer:=WaveOut1Buffer;
- h1:=CreateRoundRectRgn(0,0,ClientWidth+1,ClientHeight+1,Rounding,Rounding);
- with SpeedButton1.BoundsRect do
- h2:=CreateRectRgn(Left,Top,Right,Bottom);
- CombineRgn(h1,h1,h2,RGN_OR);
- DeleteObject(h2);
- SetWindowRgn(Handle,h1,False);
- DeleteObject(h1);
- f:=TIniFile.Create(ChangeFileExt(Application.ExeName,'.ini'));
- try
- Left:=f.ReadInteger('Position','X',0);
- Top:=f.ReadInteger('Position','Y',0);
- finally
- f.Destroy;
- end;
- end;
-
- procedure TForm1.Timer1Timer(Sender: TObject);
- var
- t,u:Integer;
- begin
- t:=Integer(GetTickCount)-FFirstTick;
- u:=GTotalTime-t;
- if u<6000 then
- WaveOut1.Start;
- if u<0 then begin
- FFlash:=not FFlash;
- if FFlash then
- Label1.Color:=clRed
- else
- Label1.Color:=0;
- u:=0;
- end;
- Label1.Caption:=TimeToStr(u/GMillisecondsPerDay);
- Label2.Caption:='Total time: '+TimeToStr(t/GMillisecondsPerDay);
- end;
-
- procedure TForm1.SpeedButton1Click(Sender: TObject);
- begin
- Close;
- end;
-
- procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
- Shift: TShiftState);
- begin
- if Key=27 then
- Close;
- end;
-
- procedure TForm1.WaveOut1Buffer(Buffer: Pointer; Length: Cardinal;
- BufferQueueLength: Integer);
- type
- TSmallintArray=array[0..$FFFFFF] of Smallint;
- PSmallintArray=^TSmallintArray;
- var
- p:PSmallintArray;
- i:Integer;
-
- function Signal(x:Single):Smallint;
- begin
- if Frac(x/3000)<0.8 then
- Result:=0
- else begin
- if Cos(x)>0 then
- Result:=FSoundIntensity
- else
- Result:=-FSoundIntensity;
- end;
- end;
-
- begin
- p:=Buffer;
- Length:=Length div 2;
- for i:=0 to Length-1 do
- p[i]:=Signal(0.3*(i+FDeltaSound));
- FDeltaSound:=FDeltaSound+Integer(Length);
- Inc(FSoundIntensity,5+FSoundIntensity div 20);
- if FSoundIntensity>32000 then
- FSoundIntensity:=32000;
- end;
-
- procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
- var
- f:TIniFile;
- begin
- f:=TIniFile.Create(ChangeFileExt(Application.ExeName,'.ini'));
- try
- f.WriteInteger('Position','X',Left);
- f.WriteInteger('Position','Y',Top);
- finally
- f.Destroy;
- end;
- end;
-
- procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
- Shift: TShiftState; X, Y: Integer);
- begin
- ReleaseCapture;
- Perform(WM_SYSCOMMAND,$f012,0);
- end;
-
- end.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, Buttons, WaveBase, WaveOut, IniFiles;
type
TForm1 = class(TForm)
Timer1: TTimer;
Label1: TLabel;
Label2: TLabel;
SpeedButton1: TSpeedButton;
procedure FormCreate(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure SpeedButton1Click(Sender: TObject);
procedure FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure WaveOut1Buffer(Buffer: Pointer; Length: Cardinal;
BufferQueueLength: Integer);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
private
public
FFirstTick,FDeltaSound,FSoundIntensity:Integer;
FFlash:Boolean;
WaveOut1: TWaveOut;
end;
var
Form1: TForm1;
GTotalTime:Integer;
const
GMillisecondsPerDay=3600*1000*24;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
var
f:TIniFile;
h1,h2:HRGN;
const
Rounding=15;
begin
WaveOut1:=TWaveOut.Create(Self);
WaveOut1.Bits16:=True;
WaveOut1.BufferSize:=2048;
WaveOut1.DeviceID:=-1;
WaveOut1.OnBuffer:=WaveOut1Buffer;
h1:=CreateRoundRectRgn(0,0,ClientWidth+1,ClientHeight+1,Rounding,Rounding);
with SpeedButton1.BoundsRect do
h2:=CreateRectRgn(Left,Top,Right,Bottom);
CombineRgn(h1,h1,h2,RGN_OR);
DeleteObject(h2);
SetWindowRgn(Handle,h1,False);
DeleteObject(h1);
f:=TIniFile.Create(ChangeFileExt(Application.ExeName,'.ini'));
try
Left:=f.ReadInteger('Position','X',0);
Top:=f.ReadInteger('Position','Y',0);
finally
f.Destroy;
end;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
var
t,u:Integer;
begin
t:=Integer(GetTickCount)-FFirstTick;
u:=GTotalTime-t;
if u<6000 then
WaveOut1.Start;
if u<0 then begin
FFlash:=not FFlash;
if FFlash then
Label1.Color:=clRed
else
Label1.Color:=0;
u:=0;
end;
Label1.Caption:=TimeToStr(u/GMillisecondsPerDay);
Label2.Caption:='Total time: '+TimeToStr(t/GMillisecondsPerDay);
end;
procedure TForm1.SpeedButton1Click(Sender: TObject);
begin
Close;
end;
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if Key=27 then
Close;
end;
procedure TForm1.WaveOut1Buffer(Buffer: Pointer; Length: Cardinal;
BufferQueueLength: Integer);
type
TSmallintArray=array[0..$FFFFFF] of Smallint;
PSmallintArray=^TSmallintArray;
var
p:PSmallintArray;
i:Integer;
function Signal(x:Single):Smallint;
begin
if Frac(x/3000)<0.8 then
Result:=0
else begin
if Cos(x)>0 then
Result:=FSoundIntensity
else
Result:=-FSoundIntensity;
end;
end;
begin
p:=Buffer;
Length:=Length div 2;
for i:=0 to Length-1 do
p[i]:=Signal(0.3*(i+FDeltaSound));
FDeltaSound:=FDeltaSound+Integer(Length);
Inc(FSoundIntensity,5+FSoundIntensity div 20);
if FSoundIntensity>32000 then
FSoundIntensity:=32000;
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
var
f:TIniFile;
begin
f:=TIniFile.Create(ChangeFileExt(Application.ExeName,'.ini'));
try
f.WriteInteger('Position','X',Left);
f.WriteInteger('Position','Y',Top);
finally
f.Destroy;
end;
end;
procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
ReleaseCapture;
Perform(WM_SYSCOMMAND,$f012,0);
end;
end.
Conclusion
Un peu d'indulgence svp, parce que là, j'ai presque l'impression d'avoir posté mon premier programme de calculette :-)
Sources du même auteur
Sources de la même categorie
Commentaires et avis
Discussions en rapport avec ce code source dans le forum
Comment créer un chronomètre [ par Alysum ]
Un chrono en min + secondes qui sera remise a zero a chaque pressions sur un bouton.HS: ya un bug sur le forum, je fais une recherche, ke clique sur u
chronomètre [ par oudoudou ]
Comment faire un chronomètre qui un fois déclenché s'arrète lorsqu'un son est détecté par mo microphonne?
Conversion mp3 > Wave [ par CorO ]
Bonjour tout le monde :) ,Je voudrais savoir si vous connaissiez un composant ou un quelquonque moyen de transormer des MP3 en Wave sous Delphi 6.Mici
Lire un fichier wave [ par olator ]
J'ai programmer un puissance4 et je désire que mon prog joue un son wave (enregistrer sur le disque dur) lorsque le joueur gagne. Comment fait on pour
wave paradox [ par bilou2000 ]
BonjourJ?ai deux soucis : 1er je possede une bdd paradox avec des champs binaires devant contenir du son (wave, mp3)je n?arrive pas à y enregistrer le
son wave et octave [ par bilou2000 ]
bonjour.j'ai des sons waves et je voudrai soit augmenter d'un octave (plus aigu) soit diminuer d'un octave (plus grave) comment peut t'on faire.Merci.
Pb périphérique Wave [ par LeFrettchen ]
Bonjour.Je viens de programmer un petit logiciel tout bête pour lire les fichiers de type wav.Je l'ai testé sous win98, il fonctionne impecc
faire un double chronomètre [ par tequilasurlaterre ]
bonjours a tous Voila ! je cherche a faire un crono utiliser par les boxeurs.je m'explique.. il faut deux chauses 1) il faut que s
Wave en MP3 [ par f6dqm1 ]
Bonjour à tousLe sujet n'est pas nouveau. On y trouve des tas de références mais ce n'est pour ça qu'on y arrive !!Je suis l'auteur du programme d'app
Wave vizualization and recordind [ par Chaser_DS ]
Hi. I am from Russia, and I small speak English. I have a question. Sample - It is a test audio visualization and audio recording test (link on sour
|
Derniers Blogs
UNE JOLIE-HORLOGE ET PAS QU'UN PEU !UNE JOLIE-HORLOGE ET PAS QU'UN PEU ! par neodante
Pour les possesseurs d'iPhone, ça y est Bijin Tokei - qui se traduit littéralement en Français par " Jolie Horloge " - est arrivé et GRATUITEMENT s'il vous plaît ! Après la version Tokyo, Hokkaido, night club, racing, Gal, "pour les mademoiselles'", . voi...
Cliquez pour lire la suite de l'article par neodante TECHDAYS PARIS 2010 : CONNECTEZ VOS DONNéES à SHAREPOINT 2010 AVEC LES BUSINESS CONNECTIVITY SERVICESTECHDAYS PARIS 2010 : CONNECTEZ VOS DONNéES à SHAREPOINT 2010 AVEC LES BUSINESS CONNECTIVITY SERVICES par ROMELARD Fabrice
Animé par: Gaetan Bouveret et Julien Chomarat Business Connectivity Services (BCS) est dans SharePoint 2010 la version 2 de Business Data Catalog (BDC dans SharePoint 2007). Il s'agit de la solution permettant de visualiser des données provenan...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice [DIVERS] SUIVRE VOS SéRIES PRéFéRéS SUR LA TOILE[DIVERS] SUIVRE VOS SéRIES PRéFéRéS SUR LA TOILE par orion
Comme de nombreux geek, je suis un grand amateur de série TV et je rate régulièrement des épisodes de mes séries préférés. Une solution s'offre à vous avec ce merveilleux site : Tv Gorge - www.tvgorge.com Moteur de recherche à l'appui, vous pouvez ...
Cliquez pour lire la suite de l'article par orion TECHDAYS PARIS 2010 : LA BI DANS SHAREPOINT 2010TECHDAYS PARIS 2010 : LA BI DANS SHAREPOINT 2010 par ROMELARD Fabrice
Animé par: Vincent Bellet et Baptiste Giraudier La BI dans SharePoint 2010, Les nouveaux services d'application dans SP2010 et SQL Server Reporting services 2008 R2. La BI dans SharePoint est généralisée pour tous afin de permettre à tous les coll...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice
Logiciels
DB-MAIN (9.1.0)DB-MAIN (9.1.0)DB-MAIN is a data-modeling and data-architecture tool. It is designed to help developers and anal... Cliquez pour télécharger DB-MAIN Xilisoft DPG Convertisseur (5.1.37.0120)XILISOFT DPG CONVERTISSEUR (5.1.37.0120)Xilisoft DPG Convertisseur offre aux fans de Nintendo DS une bonne solution leur permettant de dé... Cliquez pour télécharger Xilisoft DPG Convertisseur GraphicsGale (2.01.01)GRAPHICSGALE (2.01.01)GraphicsGale est un logiciel de PixelArt avec de nombreuse fonctionnalités permettant de réalisé ... Cliquez pour télécharger GraphicsGale Architecte 3D (Platinum 2010)ARCHITECTE 3D (PLATINUM 2010)Architecte 3D Platinium vous permet de concevoir facilement les plans votre future maison, de l'é... Cliquez pour télécharger Architecte 3D TeamViewer 5 (TeamViewer 5)TEAMVIEWER 5 (TEAMVIEWER 5)Dépanner un ami,expliquer une manipulation devient un jeu d'enfant.
Prise en main d'un autre ord... Cliquez pour télécharger TeamViewer 5
|