2018-07-27 13:07:33 +00:00
|
|
|
package code.name.monkey.retromusic.util;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @author Hemanth S (h4h13).
|
|
|
|
*/
|
|
|
|
public class TempUtils {
|
|
|
|
|
2018-08-22 17:54:07 +00:00
|
|
|
// Enums
|
|
|
|
public static final int TEMPO_STROLL = 0;
|
|
|
|
public static final int TEMPO_WALK = 1;
|
|
|
|
public static final int TEMPO_LIGHT_JOG = 2;
|
|
|
|
public static final int TEMPO_JOG = 3;
|
|
|
|
public static final int TEMPO_RUN = 4;
|
|
|
|
public static final int TEMPO_SPRINT = 5;
|
|
|
|
public static final int TEMPO_UNKNOWN = 6;
|
2018-07-27 13:07:33 +00:00
|
|
|
|
2018-08-22 17:54:07 +00:00
|
|
|
// take BPM as an int
|
|
|
|
public static int getTempoFromBPM(int bpm) {
|
2018-07-27 13:07:33 +00:00
|
|
|
|
2018-08-22 17:54:07 +00:00
|
|
|
// STROLL less than 60
|
|
|
|
if (bpm < 60) {
|
|
|
|
return TEMPO_STROLL;
|
|
|
|
}
|
2018-07-27 13:07:33 +00:00
|
|
|
|
2018-08-22 17:54:07 +00:00
|
|
|
// WALK between 60 and 70, or between 120 and 140
|
|
|
|
else if (bpm < 70 || bpm >= 120 && bpm < 140) {
|
|
|
|
return TEMPO_WALK;
|
|
|
|
}
|
2018-07-27 13:07:33 +00:00
|
|
|
|
2018-08-22 17:54:07 +00:00
|
|
|
// LIGHT_JOG between 70 and 80, or between 140 and 160
|
|
|
|
else if (bpm < 80 || bpm >= 140 && bpm < 160) {
|
|
|
|
return TEMPO_LIGHT_JOG;
|
|
|
|
}
|
2018-07-27 13:07:33 +00:00
|
|
|
|
2018-08-22 17:54:07 +00:00
|
|
|
// JOG between 80 and 90, or between 160 and 180
|
|
|
|
else if (bpm < 90 || bpm >= 160 && bpm < 180) {
|
|
|
|
return TEMPO_JOG;
|
|
|
|
}
|
2018-07-27 13:07:33 +00:00
|
|
|
|
2018-08-22 17:54:07 +00:00
|
|
|
// RUN between 90 and 100, or between 180 and 200
|
|
|
|
else if (bpm < 100 || bpm >= 180 && bpm < 200) {
|
|
|
|
return TEMPO_RUN;
|
|
|
|
}
|
2018-07-27 13:07:33 +00:00
|
|
|
|
2018-08-22 17:54:07 +00:00
|
|
|
// SPRINT between 100 and 120
|
|
|
|
else if (bpm < 120) {
|
|
|
|
return TEMPO_SPRINT;
|
|
|
|
}
|
2018-07-27 13:07:33 +00:00
|
|
|
|
2018-08-22 17:54:07 +00:00
|
|
|
// UNKNOWN
|
|
|
|
else {
|
|
|
|
return TEMPO_UNKNOWN;
|
|
|
|
}
|
2018-07-27 13:07:33 +00:00
|
|
|
}
|
|
|
|
|
2018-08-22 17:54:07 +00:00
|
|
|
// take BPM as a string
|
|
|
|
public static int getTempoFromBPM(String bpm) {
|
|
|
|
// cast to an int from string
|
|
|
|
try {
|
|
|
|
// convert the string to an int
|
|
|
|
return getTempoFromBPM(Integer.parseInt(bpm.trim()));
|
|
|
|
} catch (NumberFormatException nfe) {
|
2018-07-27 13:07:33 +00:00
|
|
|
|
2018-08-22 17:54:07 +00:00
|
|
|
//
|
|
|
|
return TEMPO_UNKNOWN;
|
|
|
|
}
|
2018-07-27 13:07:33 +00:00
|
|
|
}
|
|
|
|
}
|