summaryrefslogtreecommitdiff
path: root/src/c/metronome.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/c/metronome.c')
-rw-r--r--src/c/metronome.c34
1 files changed, 21 insertions, 13 deletions
diff --git a/src/c/metronome.c b/src/c/metronome.c
index f7a5bd3..58fdf18 100644
--- a/src/c/metronome.c
+++ b/src/c/metronome.c
@@ -3,6 +3,7 @@
*/
#include <pebble.h>
+#include "config.h"
static Window *metronome_window;
static Layer *draw_layer;
@@ -11,7 +12,7 @@ static TextLayer *bpm_text;
static AppTimer *beat_timer;
#define BPM_TO_MS(bpm) (60000/(bpm))
-#define IS_FIRST_BEAT() (current_beat % beats == 0)
+#define IS_FIRST_BEAT() (current_beat % config_get_beats() == 0)
#define COLOR_BG GColorWhite
#define COLOR_BG_INV GColorBlack
@@ -20,23 +21,17 @@ static AppTimer *beat_timer;
#define NOTE_C4 60
#define NOTE_C5 72
-static int bpm = 90;
-static int beats = 4;
static int current_beat = -1;
static bool playing = true;
-static bool flash_enabled = true;
-static bool vibrate_enabled = true;
-static bool beep_enabled = true;
-
static void restore_background_color() {
window_set_background_color(metronome_window, COLOR_BG);
}
static void metronome_flash() {
static const int flash_duration = 50;
- if (!flash_enabled) {
+ if (!config_is_indicator_enabled(FLASHING)) {
return;
}
window_set_background_color(metronome_window, COLOR_BG_INV);
@@ -44,7 +39,7 @@ static void metronome_flash() {
}
static void metronome_vibrate() {
- if (!vibrate_enabled) {
+ if (!config_is_indicator_enabled(VIBRATION)) {
return;
}
if (IS_FIRST_BEAT()) {
@@ -57,7 +52,7 @@ static void metronome_vibrate() {
static void metronome_beep() {
#if defined(PBL_SPEAKER)
- if (!beep_enabled || speaker_is_muted()) {
+ if (!config_is_indicator_enabled(BEEP) || speaker_is_muted()) {
return;
}
const SpeakerNote note = {
@@ -67,12 +62,12 @@ static void metronome_beep() {
.velocity = 0,
};
- speaker_play_notes(&note, 1, 0);
+ speaker_play_notes(&note, 1, config_get_volume());
#endif
}
static void beat_timer_callback() {
- beat_timer = app_timer_register(BPM_TO_MS(bpm), beat_timer_callback, NULL);
+ beat_timer = app_timer_register(BPM_TO_MS(config_get_bpm()), beat_timer_callback, NULL);
current_beat++;
@@ -85,11 +80,12 @@ static void beat_timer_callback() {
static void update_bpm_text() {
static char bpm_buf[6];
- snprintf(bpm_buf, sizeof(bpm_buf), "%d", bpm);
+ snprintf(bpm_buf, sizeof(bpm_buf), "%d", config_get_bpm());
text_layer_set_text(bpm_text, bpm_buf);
}
static void beat_indicators_update_proc(Layer *layer, GContext *ctx) {
+ int beats = config_get_beats();
GRect bounds = layer_get_unobstructed_bounds(layer);
const int rect_radius = 10;
@@ -170,36 +166,48 @@ Window *create_metronome_window() {
return metronome_window;
}
+void update_display() {
+ update_bpm_text();
+}
+
void increase_bpm() {
+ uint16_t bpm = config_get_bpm();
bpm++;
if (bpm > 600) {
bpm = 600;
}
+ config_set_bpm(bpm);
APP_LOG(APP_LOG_LEVEL_DEBUG, "increasing bpm to: %d", bpm);
update_bpm_text();
}
void decrease_bpm() {
+ uint16_t bpm = config_get_bpm();
bpm--;
if (bpm <= 0) {
bpm = 0;
}
+ config_set_bpm(bpm);
APP_LOG(APP_LOG_LEVEL_DEBUG, "decreasing bpm to: %d", bpm);
update_bpm_text();
}
void increase_beats() {
+ uint8_t beats = config_get_beats();
beats++;
if (beats > 16) {
beats = 16;
}
+ config_set_beats(beats);
APP_LOG(APP_LOG_LEVEL_DEBUG, "increasing beats to: %d", beats);
}
void decrease_beats() {
+ uint8_t beats = config_get_beats();
beats--;
if (beats < 1) {
beats = 1;
}
+ config_set_beats(beats);
APP_LOG(APP_LOG_LEVEL_DEBUG, "decreasing beats to: %d", beats);
}