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
[TECHDAYS2012] OUI J'Y SERAI![TECHDAYS2012] OUI J'Y SERAI! par JeremyJeanson
Bonsoir, Certes, je l'annonce avec un peu de retard, mais je serai effectivement au Techdays demain. Comme l'an dernier, je participerai au programme ATE (Ask The Expert). Si vous avez des questions Workflow, WCF, AppFabric ou plus généralement .net, n'hé...
Cliquez pour lire la suite de l'article par JeremyJeanson TFS INTEGRATION TOOLS - SUIVI DES SYNCHRONISATIONS AVEC REPORTING SERVICESTFS INTEGRATION TOOLS - SUIVI DES SYNCHRONISATIONS AVEC REPORTING SERVICES par vfabing
Afin de s'assurer du bon fonctionnement des différentes synchronisations effectuées par les TFS Integration Tools, 2 rapports sont présents dès l'installation. Il suffit alors d'effectuer les manipulations suivantes pour pouvoir les visualiser : Loca...
Cliquez pour lire la suite de l'article par vfabing CSS CONTENT STATE SELECTORS (PERSONNAL DRAFT)CSS CONTENT STATE SELECTORS (PERSONNAL DRAFT) par FREMYCOMPANY
Bonjour à tous, Je viens de publier une proposition comprenant 5 pseudo-classes pour le CSS Working Group ayant trait à l'état de chargement d'un élément (ex: IMG,VIDEO,AUDIO,OBJECT pour l'HTML.). Si le c½ur vous en dit, vous pouvez retrouver cette p...
Cliquez pour lire la suite de l'article par FREMYCOMPANY MBA : POURQUOI FAIRE ET COMMENT LE CHOISIR ?MBA : POURQUOI FAIRE ET COMMENT LE CHOISIR ? par ROMELARD Fabrice
Formation initiale Durant la formation, le découpage classique est le suivant (je donnerai les équivalences Suisse lorsque je les connaîtrais) : Ecole primaire jusqu'au Collège : Formation générale permettant d'obtenir les méthodes...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice Y'A DES ERREURS QUI PEUVENT RENDRE LE DéVELOPPEUR VIOLENTY'A DES ERREURS QUI PEUVENT RENDRE LE DéVELOPPEUR VIOLENT par Aleks
Quand on a ce genre d'erreur sans log :
Et bas on a juste envie de choper le gas de Microsoft qu'a développé ça et lui foutre des baffes de Coboye ! ...
Cliquez pour lire la suite de l'article par Aleks
Logiciels
Academy System (17.2.1.0)ACADEMY SYSTEM (17.2.1.0)Logiciel de gestion des établissements.
- élèves/étudiants (inscription, dossier, absence...)
-... Cliquez pour télécharger Academy System Easy-Planning (1.0.0.1)EASY-PLANNING (1.0.0.1)Basé sur les mêmes principes que MyPlanning, Easy-Planning permet de créer des plannings sous la ... Cliquez pour télécharger Easy-Planning COLLECTOR PLUS (3.00B)COLLECTOR PLUS (3.00B)COLLECTOR PLUS version 3.00B est un logiciel utilisant une base de données alimentée par :
- L... Cliquez pour télécharger COLLECTOR PLUS PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V7.4)PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V7.4)PONAMEDIA TV DEVIENS HELLLOOO FLASH
LA TV SUR VOTRE ORDINATEUR.
Toute une plateforme Multi... Cliquez pour télécharger PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO LettresFaciles 2011 (8.0.0.1)LETTRESFACILES 2011 (8.0.0.1)LettresFaciles est un logiciel facilitant la création et la rédaction de lettres types.
Son inte... Cliquez pour télécharger LettresFaciles 2011
|