Advertisement
FHRL

metronomo0_0_0b4

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