fixed metronom to be more accurate
This commit is contained in:
6
android/ConductorsPhone/.idea/vcs.xml
generated
Normal file
6
android/ConductorsPhone/.idea/vcs.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$/../.." vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
@@ -1,8 +1,6 @@
|
||||
package de.tonifetzer.conductorswatch;
|
||||
|
||||
import android.content.Context;
|
||||
import android.media.AudioManager;
|
||||
import android.media.MediaPlayer;
|
||||
import android.media.SoundPool;
|
||||
|
||||
import java.util.TimerTask;
|
||||
@@ -18,7 +16,7 @@ public class Metronome extends TimerTask {
|
||||
boolean loaded = false;
|
||||
private int soundID;
|
||||
|
||||
public Metronome(Context context){
|
||||
public Metronome(Context ){
|
||||
soundPool = new SoundPool.Builder().setMaxStreams(10).build();
|
||||
soundPool.setOnLoadCompleteListener(new SoundPool.OnLoadCompleteListener() {
|
||||
@Override
|
||||
|
||||
@@ -7,7 +7,7 @@ buildscript {
|
||||
jcenter()
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:3.1.2'
|
||||
classpath 'com.android.tools.build:gradle:3.3.0'
|
||||
|
||||
|
||||
// NOTE: Do not place your application dependencies here; they belong
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#Fri Apr 27 11:02:05 CEST 2018
|
||||
#Tue Jan 29 16:48:07 CET 2019
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip
|
||||
|
||||
@@ -1,48 +1,32 @@
|
||||
package de.tonifetzer.conductorswatch;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Vibrator;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.TimerTask;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
/**
|
||||
* Created by toni on 13/11/17.
|
||||
*/
|
||||
|
||||
//TODO: implement the metronome similar to phone. since thread sleeping is no accurate enough
|
||||
public class Metronome implements Runnable{
|
||||
public class Metronome extends TimerTask {
|
||||
|
||||
private volatile boolean mRunning = true;
|
||||
private int mBPM;
|
||||
private Vibrator mVibrator;
|
||||
|
||||
public Metronome(int bpm){
|
||||
mBPM = bpm;
|
||||
Metronome(Context context){
|
||||
mVibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
while(mRunning){
|
||||
|
||||
for (OnMetronomeListener listener:listeners) {
|
||||
listener.onNewClick();
|
||||
}
|
||||
mVibrator.vibrate(10);
|
||||
|
||||
try {
|
||||
if(mBPM > 0){
|
||||
Thread.sleep(60000 / mBPM);
|
||||
} else {
|
||||
Thread.sleep(60000);
|
||||
}
|
||||
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
for (OnMetronomeListener listener:listeners) {
|
||||
listener.onNewClick();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
mRunning = false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -9,6 +9,8 @@ import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.TextView;
|
||||
|
||||
import java.util.Timer;
|
||||
import java.util.Vector;
|
||||
|
||||
import de.tonifetzer.conductorswatch.ui.Croller;
|
||||
@@ -27,8 +29,7 @@ public class WorkerFragment extends Fragment implements Metronome.OnMetronomeLis
|
||||
private boolean mWorkerRunning = false;
|
||||
|
||||
private Estimator mEstimator;
|
||||
private Metronome mMetronome;
|
||||
private Thread mMetronomeThread;
|
||||
private Timer mTimer;
|
||||
|
||||
private TextView mTextView;
|
||||
private Croller mCroller;
|
||||
@@ -55,15 +56,12 @@ public class WorkerFragment extends Fragment implements Metronome.OnMetronomeLis
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
// init bpm estimator and listener
|
||||
//TODO: hier ein Thread draus machen?
|
||||
mEstimator = new Estimator(getContext());
|
||||
mEstimator.add(this);
|
||||
mBpmList = new Vector<Double>();
|
||||
|
||||
// init metronome and listener
|
||||
mMetronome = new Metronome(getArguments().getInt("bpm"));
|
||||
mMetronome.add(this);
|
||||
mMetronomeThread = new Thread(mMetronome, "metronomThread");
|
||||
mTimer = new Timer();
|
||||
|
||||
//keep screen always on
|
||||
this.getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||
@@ -94,8 +92,8 @@ public class WorkerFragment extends Fragment implements Metronome.OnMetronomeLis
|
||||
// start the worker thread for bpm estimator
|
||||
mEstimator.start();
|
||||
|
||||
// start the worker thread for metronom
|
||||
mMetronomeThread.start();
|
||||
// start the timer for metronom based on the predefined bpm
|
||||
mTimer.scheduleAtFixedRate(new Metronome(getContext()), 0, 60000 / getArguments().getInt("bpm"));
|
||||
|
||||
// everything is running
|
||||
mWorkerRunning = true;
|
||||
@@ -111,7 +109,7 @@ public class WorkerFragment extends Fragment implements Metronome.OnMetronomeLis
|
||||
mEstimator.stop();
|
||||
|
||||
// stop the worker thread for metronom
|
||||
mMetronome.stop();
|
||||
mTimer.cancel();
|
||||
|
||||
//private listener with list of all estimated bpm
|
||||
if (mListener != null) {
|
||||
|
||||
Reference in New Issue
Block a user