beats per bar, settable, not implemented

master
Felix Pankratz 2 years ago
parent 7540797c2e
commit 7460e50be0

@ -25,6 +25,8 @@ typedef struct {
typedef struct { typedef struct {
double bpm; double bpm;
bool playing; bool playing;
int beats_per_bar;
int note_length;
FuriTimer* timer; FuriTimer* timer;
} MetronomeState; } MetronomeState;
@ -33,7 +35,6 @@ static void render_callback(Canvas* const canvas, void* ctx) {
if(metronome_state == NULL) { if(metronome_state == NULL) {
return; return;
} }
// char* play_state;
string_t tempStr; string_t tempStr;
string_init(tempStr); string_init(tempStr);
@ -41,14 +42,10 @@ static void render_callback(Canvas* const canvas, void* ctx) {
canvas_draw_frame(canvas, 0, 0, 128, 64); canvas_draw_frame(canvas, 0, 0, 128, 64);
canvas_set_font(canvas, FontPrimary); canvas_set_font(canvas, FontPrimary);
// // draw playing state // draw bars/beat
// if (metronome_state->playing) { string_printf(tempStr, "%d/%d", metronome_state->beats_per_bar, metronome_state->note_length);
// play_state = "Playing"; canvas_draw_str_aligned(canvas, 64, 16, AlignCenter, AlignCenter, string_get_cstr(tempStr));
// } else { string_reset(tempStr);
// play_state = "Paused";
// }
// canvas_draw_str_aligned(canvas, 5, 10, AlignLeft, AlignBottom, play_state);
// draw BPM value // draw BPM value
string_printf(tempStr, "%.2f", metronome_state->bpm); string_printf(tempStr, "%.2f", metronome_state->bpm);
canvas_set_font(canvas, FontBigNumbers); canvas_set_font(canvas, FontBigNumbers);
@ -86,6 +83,8 @@ static void timer_callback() {
static void metronome_state_init(MetronomeState* const metronome_state) { static void metronome_state_init(MetronomeState* const metronome_state) {
metronome_state->bpm = 120.0; metronome_state->bpm = 120.0;
metronome_state->playing = false; metronome_state->playing = false;
metronome_state->beats_per_bar = 4;
metronome_state->note_length = 4;
metronome_state->timer = furi_timer_alloc(timer_callback, FuriTimerTypePeriodic, metronome_state); metronome_state->timer = furi_timer_alloc(timer_callback, FuriTimerTypePeriodic, metronome_state);
} }
@ -122,6 +121,13 @@ static void decrease_bpm(MetronomeState* metronome_state, double amount) {
update_timer(metronome_state); update_timer(metronome_state);
} }
static void cycle_beats_per_bar(MetronomeState* metronome_state) {
metronome_state->beats_per_bar++;
if (metronome_state->beats_per_bar > metronome_state->note_length) {
metronome_state->beats_per_bar = 1;
}
}
int32_t metronome_app() { int32_t metronome_app() {
FuriMessageQueue* event_queue = furi_message_queue_alloc(8, sizeof(PluginEvent)); FuriMessageQueue* event_queue = furi_message_queue_alloc(8, sizeof(PluginEvent));
@ -156,6 +162,7 @@ int32_t metronome_app() {
if(event.input.type == InputTypeShort) { if(event.input.type == InputTypeShort) {
switch(event.input.key) { switch(event.input.key) {
case InputKeyUp: case InputKeyUp:
cycle_beats_per_bar(metronome_state);
break; break;
case InputKeyDown: case InputKeyDown:
break; break;

Loading…
Cancel
Save