Advertisement
FHRL

metronomo0_0_0b4

Mar 16th, 2023
287
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.60 KB | Source Code | 0 0
  1. /*Created by Processing APDE app version 0.5.1
  2.  *       and OpenIA GPTchat Mar 14 version.
  3.  *compatibility: java, wallpaper, app.
  4.  *project: ".../storage/emulated/0/Sketchbook/metronomo/metronomo.../sketch.pde"
  5.  *User:fhrl007@gmail.com
  6.  *Date:16-03-2023
  7.  *Time: 00:04
  8.  *Verton:0.0.0b4
  9.  *Based an AI documentation generated.
  10.  */
  11.  
  12. import android.app.Activity;
  13. import android.os.Bundle;
  14. import android.os.Handler;
  15. import android.view.View;
  16. import android.widget.Button;
  17.  
  18. import java.util.Timer; // Importar la clase Timer
  19.  
  20. public class MetronomeActivity extends Activity {
  21.  
  22.     private Handler mHandler = new Handler();
  23.     private boolean mIsPlaying = false;
  24.     private int mTempo = 120;
  25.     private int mDuration = 60000 / mTempo;
  26.  
  27.     private Runnable mPlaySoundRunnable = new Runnable() {
  28.         @Override
  29.         public void run() {
  30.             // Reproduce el sonido del metrónomo
  31.             playSound();
  32.             // Programa la siguiente llamada a run() después del tiempo de duración del latido
  33.             mHandler.postDelayed(mPlaySoundRunnable, mDuration);
  34.         }
  35.     };
  36.  
  37.     @Override
  38.     protected void onCreate(Bundle savedInstanceState) {
  39.         super.onCreate(savedInstanceState);
  40.         setContentView(R.layout.activity_metronome);
  41.  
  42.         Button playButton = findViewById(R.id.play_button);
  43.         playButton.setOnClickListener(new View.OnClickListener() {
  44.             @Override
  45.             public void onClick(View view) {
  46.                 if (mIsPlaying) {
  47.                     stopMetronome();
  48.                 } else {
  49.                     startMetronome();
  50.                 }
  51.             }
  52.         });
  53.     }
  54.  
  55.     private void startMetronome() {
  56.         // Inicia el metrónomo
  57.         mIsPlaying = true;
  58.         timer = new Timer(); // inicializar el objeto timer
  59.         timer.scheduleAtFixedRate(new TimerTask() {
  60.             @Override
  61.             public void run() {
  62.                 playSound();
  63.             }
  64.         }, 0, mDuration);
  65.     }
  66.  
  67.     private void stopMetronome() {
  68.         // Detiene el metrónomo
  69.         mIsPlaying = false;
  70.         timer.cancel(); // cancelar la tarea del timer
  71.     }
  72.  
  73.     private void playSound() {
  74.         // Reproduce el sonido del metrónomo
  75.     }
  76. }
  77.  
  78.  
  79. PApplet parent;
  80. int tempo = 120; // latidos por minuto
  81. int duration = 1000 * 60 / tempo; // duración de cada latido en milisegundos
  82. Timer timer;
  83. boolean isPlaying = false;
  84.  
  85. void setup() {
  86.   size(200, 200);
  87.   frameRate(60); // velocidad de actualización de la ventana
  88.   parent = this;
  89. }
  90.  
  91. void draw(){// se muestra en pantalla por frame.
  92.  
  93. }
  94.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement