public void loadSong(int s) {
   TextView songName = (TextView) findViewById(R.id.textViewSong);
   if (s == 1) {
     songName.setText(songName1);
     bpm = bpm1;
     metronome.setTempo(bpm);
   }
   if (s == 2) {
     songName.setText(songName2);
     bpm = bpm2;
     metronome.setTempo(bpm);
   }
   if (s == 3) {
     songName.setText(songName3);
     bpm = bpm3;
     metronome.setTempo(bpm);
   }
   if (s == 4) {
     songName.setText(songName4);
     bpm = bpm4;
     metronome.setTempo(bpm);
   }
   if (s == 5) {
     songName.setText(songName5);
     bpm = bpm5;
     metronome.setTempo(bpm);
   }
   bpmTextView.setText(String.valueOf(bpm));
 }
  /**
   * Calculates average tempo of touches, sets it and starts metronome. Calculates tempo from 57 to
   * 200 bpm. Re-calculate after 1100 ms pause*
   */
  private void tapTempo() {
    int hp = metronome.headPosition();
    bpmf = bpm;
    playStatePrevious = metronome.getPlayState();
    // If tapped while playing, just after the previous click, it doesn't click again, just delays
    // next click.
    if (playStatePrevious == 3) {
      if (hp < 8820) {
        metronome.setDelay(hp / 44100 * 1000);
      }
    } else {
      flasher();
      metronome.play();
      startDelayHandler.postDelayed(startDelay, 20000 / bpm); //
    }

    if (tapCount == 0) { // On the first tap it only records time
      timeFirstTap = System.currentTimeMillis();
      timeLastTap = timeFirstTap;
      tapCount++;
    } else if ((System.currentTimeMillis() - timeLastTap)
        < 1050) { // Maximum time between taps is set to 1050 ms (57 bpm)
      if (hp
          > 8820) { // If tapped while playing, after less than 8820 samples from the previous
                    // click, it doesn't stop, just delays next click.
        metronome.stop();
      }
      timeLastTap = System.currentTimeMillis();
      exactBpmMs = (double) (timeLastTap - timeFirstTap) / tapCount;
      exactBpm = 60000 / exactBpmMs;
      tapBpm = (int) Math.round(exactBpm);
      Log.i("exactBpm", "" + exactBpm);
      Log.i("tapBpm", "" + tapBpm);
      if (tapBpm > 200) tapBpm = 200;
      metronome.setTempo(tapBpm);
      bpm = tapBpm;
      bpmTextView.setText(String.valueOf(tapBpm));
      tapCount++;
      if (hp > 7340) {
        metronome.play();
        startDelayHandler.postDelayed(startDelay, (20000 / bpm));
      }
    } else {
      tapCount = 1;
      timeFirstTap = System.currentTimeMillis();
      timeLastTap = timeFirstTap;
    }
  }
 @Override
 public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
   Log.i("msg", "onScroll X=" + distanceX + " Y=" + distanceY);
   if (Math.abs(distanceY) > Math.abs(distanceX) * 1.5) {
     if (playStatePrevious != 3) // prevents starting metronome when changing tempo
     stop = true;
     flasherState = 0;
     bpmf = bpmf + distanceY / 10;
     if (bpmf > 49 || bpmf < 201) {
       bpm = ((int) bpmf);
       bpmTextView.setText(String.valueOf(bpm));
       metronome.setTempo(bpm);
     }
   }
   return false;
 }