IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

 Delphi Discussion :

Création d'un métronome


Sujet :

Delphi

  1. #1
    Nouveau Candidat au Club
    Femme Profil pro
    Chef de projet NTIC
    Inscrit en
    Février 2018
    Messages
    1
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Chef de projet NTIC
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Février 2018
    Messages : 1
    Points : 1
    Points
    1
    Par défaut Création d'un métronome
    Bonjour,
    Je vous remercie si quelqu'un peut me montrer un code simple (je suis une débutante en programmation) pour créer un métronome simple. Par exemple, je souhaite régler les "bips" à 1 seconde, puis à 2 secondes, puis à 0,5 sec etc.
    Merci par avance

  2. #2
    Membre expérimenté
    Profil pro
    Inscrit en
    Janvier 2006
    Messages
    2 425
    Détails du profil
    Informations personnelles :
    Âge : 71
    Localisation : Belgique

    Informations forums :
    Inscription : Janvier 2006
    Messages : 2 425
    Points : 1 326
    Points
    1 326
    Par défaut
    @ Taniacle,

    A l'époque j'avais retenu ce site pour un exemple que tu pourras modifier en laissant le nom de l'auteur bien entendu !

    http://www.delphiforfun.org/Programs/metronome.htm

    @+,

    cincap

  3. #3
    Expert éminent sénior
    Avatar de ShaiLeTroll
    Homme Profil pro
    Développeur C++\Delphi
    Inscrit en
    Juillet 2006
    Messages
    13 459
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France, Seine Saint Denis (Île de France)

    Informations professionnelles :
    Activité : Développeur C++\Delphi
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juillet 2006
    Messages : 13 459
    Points : 24 873
    Points
    24 873
    Par défaut
    Je n'ai pas regardé l'exemple mais c'est un simple Timer avec Interval régler à 1000, 1000 x 2, 1000 / 2

    Et l'on exprime plutôt en BPM, comme par exemple Enter Sandman de Metallica, doit se jouer sur 120 Battement par Minute ... d'ailleurs, je dois bosser l'intro et le métronome personnellement ça me tape sur le nerfs.
    Aide via F1 - FAQ - Guide du développeur Delphi devant un problème - Pensez-y !
    Attention Troll Méchant !
    "Quand un homme a faim, mieux vaut lui apprendre à pêcher que de lui donner un poisson" Confucius
    Mieux vaut se taire et paraître idiot, Que l'ouvrir et de le confirmer !
    L'ignorance n'excuse pas la médiocrité !

    L'expérience, c'est le nom que chacun donne à ses erreurs. (Oscar Wilde)
    Il faut avoir le courage de se tromper et d'apprendre de ses erreurs

  4. #4
    Membre expérimenté
    Profil pro
    Inscrit en
    Janvier 2006
    Messages
    2 425
    Détails du profil
    Informations personnelles :
    Âge : 71
    Localisation : Belgique

    Informations forums :
    Inscription : Janvier 2006
    Messages : 2 425
    Points : 1 326
    Points
    1 326
    Par défaut
    Bonjour à toutes et à tous,

    Avec ce lien, il se compile avec D6 et fonctionne correctement.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
     
    { METRONOME PC
     
    Auteur : Jean-François MOREL
    Version : 1.0.0
    Date de création : 15.07.07
    Outil de développement : Borland Delphi 6 
     }
     
    unit Unit1_2;
     
    interface
     
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs,mmsystem, ExtCtrls, StdCtrls, RXSwitch, Mask,
      ToolEdit, RXSpin, VrControls, VrLcd, VrUpDown, VrSpinner, VrButtons,
      VrSwitch, VrNavigator, VrScope, VrDesign, VrAudio, VrDisplay,
      VrRotarySwitch, VrLabel, jpeg, VrLeds, VrScrollText, LMDControl,
      LMDBaseControl, LMDBaseGraphicControl, LMDGraphicControl,
      LMDLEDCustomLabel, LMDLEDLabel;
     
    type
      TForm1 = class(TForm)
        Timer1: TTimer;
        Fleches: TVrUpDown;
        Play: TVrPowerButton;
        Quitter: TVrMediaButton;
        VrDisplay1: TVrDisplay;
        ecran: TVrNum;
        Image1: TImage;
        Raz: TVrDemoButton;
        VrDemoButton1: TVrDemoButton;
        VrDemoButton2: TVrDemoButton;
        VrDemoButton3: TVrDemoButton;
        VrDemoButton4: TVrDemoButton;
        VrDemoButton5: TVrDemoButton;
        VrDemoButton6: TVrDemoButton;
        VrDemoButton7: TVrDemoButton;
        VrDemoButton8: TVrDemoButton;
        VrDemoButton9: TVrDemoButton;
        VrDemoButton10: TVrDemoButton;
        VrDemoButton11: TVrDemoButton;
        VrDemoButton12: TVrDemoButton;
        VrDemoButton13: TVrDemoButton;
        VrDemoButton14: TVrDemoButton;
        VrDemoButton15: TVrDemoButton;
        VrDemoButton16: TVrDemoButton;
        VrDemoButton17: TVrDemoButton;
        VrDemoButton18: TVrDemoButton;
        VrDemoButton19: TVrDemoButton;
        Label1: TLabel;
        Label2: TLabel;
        Label3: TLabel;
        Label4: TLabel;
        Label5: TLabel;
        Label6: TLabel;
        Led1: TVrUserLed;
        Led2: TVrUserLed;
        Timer2: TTimer;
        Timer3: TTimer;
        Defil: TVrScrollText;
        Info: TVrDemoButton;
        X: TVrDemoButton;
        digittemps: TLMDLEDLabel;
        procedure Timer1Timer(Sender: TObject);
        procedure FormCreate(Sender: TObject);
        procedure FlechesDownClick(Sender: TObject);
        procedure FlechesUpClick(Sender: TObject);
        procedure PlayClick(Sender: TObject);
        procedure QuitterClick(Sender: TObject);
        procedure RazClick(Sender: TObject);
        procedure VrDemoButton3Click(Sender: TObject);
        procedure VrDemoButton1Click(Sender: TObject);
        procedure VrDemoButton2Click(Sender: TObject);
        procedure VrDemoButton4Click(Sender: TObject);
        procedure VrDemoButton5Click(Sender: TObject);
        procedure VrDemoButton6Click(Sender: TObject);
        procedure VrDemoButton7Click(Sender: TObject);
        procedure VrDemoButton8Click(Sender: TObject);
        procedure VrDemoButton9Click(Sender: TObject);
        procedure VrDemoButton10Click(Sender: TObject);
        procedure VrDemoButton11Click(Sender: TObject);
        procedure VrDemoButton12Click(Sender: TObject);
        procedure VrDemoButton13Click(Sender: TObject);
        procedure VrDemoButton14Click(Sender: TObject);
        procedure VrDemoButton15Click(Sender: TObject);
        procedure VrDemoButton17Click(Sender: TObject);
        procedure VrDemoButton16Click(Sender: TObject);
        procedure VrDemoButton18Click(Sender: TObject);
        procedure VrDemoButton19Click(Sender: TObject);
        procedure Timer2Timer(Sender: TObject);
        procedure Timer3Timer(Sender: TObject);
        procedure InfoClick(Sender: TObject);
        procedure XClick(Sender: TObject);
      private
        { Déclarations privées }
      public
        { Déclarations publiques }
      end;
     
    var
      Form1: TForm1;
      compte, tempo, milli, bpm, i : integer;
     
    implementation
     
    {$R *.dfm}
    {$R sons.res} //Fichier ressource
     
    procedure CalcBpm(bpm : integer);
    begin
    milli := 60000 div bpm;              //conversion des millisecondes du timer
    form1.ecran.Value:=bpm;              //en battements par minute
    form1.timer1.Interval:= milli
    end;
     
     
    procedure TForm1.Timer1Timer(Sender: TObject);
    begin
    compte:=compte+1;              //joue Beat0 sur les 1er temps
    if compte = 1 then             //et Beat1 sur les autres temps
            begin
             led1.Active:=true;
             timer2.Enabled:=true;
             playsound('Beat0',HInstance,SND_RESOURCE);//Son extrait du fichier ressource
             end else
             begin
                led2.Active:=true;
                timer3.Enabled:=true;
                playsound('Beat1',HInstance,SND_RESOURCE);//Son extrait du fichier ressource
                end;
    if compte = tempo then compte:= 0;
    end;
     
    //initialisation des différentes variables et timer
     
    procedure TForm1.FormCreate(Sender: TObject);
    begin
    i:=0;
    compte:=0;
    tempo:= 4;
    bpm:=120;
    digittemps.caption:='4';
    timer1.Interval:= 500;
    timer2.Interval:=100;
    timer3.Interval:=100;
    ecran.Value:=bpm;
    end;
     
    //Gestion du composant UpDown
     
    procedure TForm1.FlechesDownClick(Sender: TObject);
    begin
    bpm := ecran.Value;
    bpm := bpm-1;
    if bpm<20 then bpm := 20;
    CalcBpm (bpm);
    end;
     
    procedure TForm1.FlechesUpClick(Sender: TObject);
    begin
    bpm := ecran.Value;
    bpm := bpm+1;
    if bpm > 300 then bpm := 300;
    CalcBpm (bpm);
    end;
     
    procedure TForm1.PlayClick(Sender: TObject);
    begin
    if play.Active = true then timer1.Enabled:=true
            else
                    begin
                    timer1.Enabled:=false;
                    compte:=0;
                    end;
    end;
     
    procedure TForm1.QuitterClick(Sender: TObject);
    begin
    Application.Terminate;
    end;
     
    procedure TForm1.RazClick(Sender: TObject);
    begin
    timer1.Interval:= 500;
    tempo := 4;
    bpm:=120;
    digittemps.caption:='4';
    ecran.Value:=bpm;
    end;
     
    //BOUTONS RYTHME ----------------------------------
     
    procedure TForm1.VrDemoButton3Click(Sender: TObject);
    begin
    CalcBpm (140);
    end;
     
    procedure TForm1.VrDemoButton1Click(Sender: TObject);
    begin
    CalcBpm (160);
    end;
     
    procedure TForm1.VrDemoButton2Click(Sender: TObject);
    begin
    CalcBpm (150);
    end;
     
    procedure TForm1.VrDemoButton4Click(Sender: TObject);
    begin
    CalcBpm (130);
    end;
     
    procedure TForm1.VrDemoButton5Click(Sender: TObject);
    begin
    CalcBpm (120);
    end;
     
    procedure TForm1.VrDemoButton6Click(Sender: TObject);
    begin
    CalcBpm (110);
    end;
     
    procedure TForm1.VrDemoButton7Click(Sender: TObject);
    begin
    CalcBpm (100);
    end;
     
    procedure TForm1.VrDemoButton8Click(Sender: TObject);
    begin
    CalcBpm (90);
    end;
     
    procedure TForm1.VrDemoButton9Click(Sender: TObject);
    begin
    CalcBpm (80);
    end;
     
    procedure TForm1.VrDemoButton10Click(Sender: TObject);
    begin
    CalcBpm (70);
    end;
     
    procedure TForm1.VrDemoButton11Click(Sender: TObject);
    begin
    CalcBpm (60);
    end;
     
    procedure TForm1.VrDemoButton12Click(Sender: TObject);
    begin
    CalcBpm (50);
    end;
     
    //BOUTONS TEMPO -------------------------------------
     
    procedure TForm1.VrDemoButton13Click(Sender: TObject);
    begin
    tempo := 2;
    digittemps.caption:='2';
    compte:= 0;
    end;
     
    procedure TForm1.VrDemoButton14Click(Sender: TObject);
    begin
    tempo := 3;
    digittemps.caption:='3';
    compte:= 0;
    end;
     
    procedure TForm1.VrDemoButton15Click(Sender: TObject);
    begin
    tempo := 4;
    digittemps.caption:='4';
    compte:= 0;
    end;
     
    procedure TForm1.VrDemoButton17Click(Sender: TObject);
    begin
    tempo := 5;
    digittemps.caption:='5';
    compte:= 0;
    end;
     
    procedure TForm1.VrDemoButton16Click(Sender: TObject);
    begin
    tempo := 6;
    digittemps.caption:='6';
    compte:= 0;
    end;
     
    procedure TForm1.VrDemoButton18Click(Sender: TObject);
    begin
    tempo := 7;
    digittemps.caption:='7';
    compte:= 0;
    end;
     
    procedure TForm1.VrDemoButton19Click(Sender: TObject);
    begin
    tempo := 8;
    digittemps.caption:='8';
    compte:= 0;
    end;
     
    //Gestion des timer de Led
     
    procedure TForm1.Timer2Timer(Sender: TObject);
    begin
    led1.Active:=false;
    timer2.Enabled:=false;
    end;
     
    procedure TForm1.Timer3Timer(Sender: TObject);
    begin
    led2.Active:=false;
    timer3.Enabled:=false;
    end;
     
    procedure TForm1.InfoClick(Sender: TObject);
    begin
    defil.Visible:=true;
    defil.Active:=true;
    X.Visible:=true;
    end;
     
    procedure TForm1.XClick(Sender: TObject);
    begin
    defil.Visible:=false;
    defil.Active:=false;
    x.Visible:=false;
    end;
     
    end.
    @+,

    cincap

Discussions similaires

  1. Classe pour la création d'un graphe xy
    Par Bob dans le forum MFC
    Réponses: 24
    Dernier message: 03/12/2009, 17h20
  2. Création dynamique de TImages
    Par Dric dans le forum C++Builder
    Réponses: 10
    Dernier message: 08/07/2002, 12h36
  3. [Kylix] Création d'un fichier lien
    Par DrQ dans le forum EDI
    Réponses: 2
    Dernier message: 14/05/2002, 21h30
  4. Création image BMP
    Par Anonymous dans le forum C
    Réponses: 2
    Dernier message: 25/04/2002, 16h04

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo