2022-07-26 12:21:51 +00:00
|
|
|
#include "music_player_worker.h"
|
|
|
|
|
[FL-140] Core api dynamic records (#296)
* SYSTEM: tickless mode with deep sleep.
* Move FreeRTOS ticks to lptim2
* API: move all sumbodules init routines to one place. Timebase: working lptim2 at tick source.
* API Timebase: lp-timer routines, timer access safe zones prediction and synchronization. FreeRTOS: adjust configuration for tickless mode.
* NFC: support for tickless mode.
* API Timebase: improve tick error handling in IRQ. Apploader: use insomnia mode to run applications.
* BLE: prevent sleep while core2 starting
* HAL: nap while in insomnia mode
* init records work
* try to implement record delete
* tests and flapp
* flapp subsystem
* new core functions to get app stat, simplify core code
* fix thread termination
* add strdup to core
* fix tests
* Refactoring: remove all unusued parts, update API usage, aggreagate API sources and headers, new record storage
* Refactoring: update furi record api usage, cleanup code
* Fix broken merge for freertos apps
* Core, Target: fix compilation warnings
* Drop firmware target local
* HAL Timebase, Power, Clock: semaphore guarded access to clock and power modes, better sleep mode.
* SD-Filesystem: wait for all deps to arrive before adding widget. Core, BLE: disable debug dump to serial.
* delete old app example-ipc
* delete old app fatfs list
* fix strobe app, add input header
* delete old display driver
* comment old app qr-code
* fix sd-card test, add forced widget update
* remove unused new core test
* increase heap to 128k
* comment and assert old core tests
* fix syntax
Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
2021-01-20 16:09:26 +00:00
|
|
|
#include <furi.h>
|
2022-01-05 16:10:18 +00:00
|
|
|
#include <furi_hal.h>
|
2021-02-18 12:49:32 +00:00
|
|
|
|
2022-10-28 14:08:50 +00:00
|
|
|
#include <music_player_icons.h>
|
[FL-140] Core api dynamic records (#296)
* SYSTEM: tickless mode with deep sleep.
* Move FreeRTOS ticks to lptim2
* API: move all sumbodules init routines to one place. Timebase: working lptim2 at tick source.
* API Timebase: lp-timer routines, timer access safe zones prediction and synchronization. FreeRTOS: adjust configuration for tickless mode.
* NFC: support for tickless mode.
* API Timebase: improve tick error handling in IRQ. Apploader: use insomnia mode to run applications.
* BLE: prevent sleep while core2 starting
* HAL: nap while in insomnia mode
* init records work
* try to implement record delete
* tests and flapp
* flapp subsystem
* new core functions to get app stat, simplify core code
* fix thread termination
* add strdup to core
* fix tests
* Refactoring: remove all unusued parts, update API usage, aggreagate API sources and headers, new record storage
* Refactoring: update furi record api usage, cleanup code
* Fix broken merge for freertos apps
* Core, Target: fix compilation warnings
* Drop firmware target local
* HAL Timebase, Power, Clock: semaphore guarded access to clock and power modes, better sleep mode.
* SD-Filesystem: wait for all deps to arrive before adding widget. Core, BLE: disable debug dump to serial.
* delete old app example-ipc
* delete old app fatfs list
* fix strobe app, add input header
* delete old display driver
* comment old app qr-code
* fix sd-card test, add forced widget update
* remove unused new core test
* increase heap to 128k
* comment and assert old core tests
* fix syntax
Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
2021-01-20 16:09:26 +00:00
|
|
|
#include <gui/gui.h>
|
2022-05-05 09:49:59 +00:00
|
|
|
#include <dialogs/dialogs.h>
|
2022-07-26 12:21:51 +00:00
|
|
|
#include <storage/storage.h>
|
|
|
|
|
2022-05-05 09:49:59 +00:00
|
|
|
#define TAG "MusicPlayer"
|
2020-11-16 17:12:05 +00:00
|
|
|
|
2022-07-26 12:21:51 +00:00
|
|
|
#define MUSIC_PLAYER_APP_PATH_FOLDER ANY_PATH("music_player")
|
2022-05-05 09:49:59 +00:00
|
|
|
#define MUSIC_PLAYER_APP_EXTENSION "*"
|
2020-11-16 17:12:05 +00:00
|
|
|
|
2022-05-05 09:49:59 +00:00
|
|
|
#define MUSIC_PLAYER_SEMITONE_HISTORY_SIZE 4
|
2020-11-16 17:12:05 +00:00
|
|
|
|
|
|
|
typedef struct {
|
2022-05-05 09:49:59 +00:00
|
|
|
uint8_t semitone_history[MUSIC_PLAYER_SEMITONE_HISTORY_SIZE];
|
|
|
|
uint8_t duration_history[MUSIC_PLAYER_SEMITONE_HISTORY_SIZE];
|
2020-11-16 17:12:05 +00:00
|
|
|
|
2022-05-05 09:49:59 +00:00
|
|
|
uint8_t volume;
|
|
|
|
uint8_t semitone;
|
|
|
|
uint8_t dots;
|
|
|
|
uint8_t duration;
|
|
|
|
float position;
|
|
|
|
} MusicPlayerModel;
|
2020-11-16 17:12:05 +00:00
|
|
|
|
|
|
|
typedef struct {
|
2022-05-05 09:49:59 +00:00
|
|
|
MusicPlayerModel* model;
|
2022-07-20 10:56:33 +00:00
|
|
|
FuriMutex** model_mutex;
|
2022-05-05 09:49:59 +00:00
|
|
|
|
2022-07-20 10:56:33 +00:00
|
|
|
FuriMessageQueue* input_queue;
|
2022-05-05 09:49:59 +00:00
|
|
|
|
|
|
|
ViewPort* view_port;
|
|
|
|
Gui* gui;
|
|
|
|
|
|
|
|
MusicPlayerWorker* worker;
|
|
|
|
} MusicPlayer;
|
|
|
|
|
|
|
|
static const float MUSIC_PLAYER_VOLUMES[] = {0, .25, .5, .75, 1};
|
|
|
|
|
|
|
|
static const char* semitone_to_note(int8_t semitone) {
|
|
|
|
switch(semitone) {
|
|
|
|
case 0:
|
|
|
|
return "C";
|
|
|
|
case 1:
|
|
|
|
return "C#";
|
|
|
|
case 2:
|
|
|
|
return "D";
|
|
|
|
case 3:
|
|
|
|
return "D#";
|
|
|
|
case 4:
|
|
|
|
return "E";
|
|
|
|
case 5:
|
|
|
|
return "F";
|
|
|
|
case 6:
|
|
|
|
return "F#";
|
|
|
|
case 7:
|
|
|
|
return "G";
|
|
|
|
case 8:
|
|
|
|
return "G#";
|
|
|
|
case 9:
|
|
|
|
return "A";
|
|
|
|
case 10:
|
|
|
|
return "A#";
|
|
|
|
case 11:
|
|
|
|
return "B";
|
|
|
|
default:
|
|
|
|
return "--";
|
|
|
|
}
|
|
|
|
}
|
2020-11-16 17:12:05 +00:00
|
|
|
|
2022-05-05 09:49:59 +00:00
|
|
|
static bool is_white_note(uint8_t semitone, uint8_t id) {
|
|
|
|
switch(semitone) {
|
|
|
|
case 0:
|
2020-11-16 17:12:05 +00:00
|
|
|
if(id == 0) return true;
|
|
|
|
break;
|
2022-05-05 09:49:59 +00:00
|
|
|
case 2:
|
2020-11-16 17:12:05 +00:00
|
|
|
if(id == 1) return true;
|
|
|
|
break;
|
2022-05-05 09:49:59 +00:00
|
|
|
case 4:
|
2020-11-16 17:12:05 +00:00
|
|
|
if(id == 2) return true;
|
|
|
|
break;
|
2022-05-05 09:49:59 +00:00
|
|
|
case 5:
|
|
|
|
if(id == 3) return true;
|
|
|
|
break;
|
|
|
|
case 7:
|
2020-11-16 17:12:05 +00:00
|
|
|
if(id == 4) return true;
|
|
|
|
break;
|
2022-05-05 09:49:59 +00:00
|
|
|
case 9:
|
2020-11-16 17:12:05 +00:00
|
|
|
if(id == 5) return true;
|
|
|
|
break;
|
2022-05-05 09:49:59 +00:00
|
|
|
case 11:
|
2020-11-16 17:12:05 +00:00
|
|
|
if(id == 6) return true;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-05-05 09:49:59 +00:00
|
|
|
static bool is_black_note(uint8_t semitone, uint8_t id) {
|
|
|
|
switch(semitone) {
|
|
|
|
case 1:
|
|
|
|
if(id == 0) return true;
|
2020-11-16 17:12:05 +00:00
|
|
|
break;
|
2022-05-05 09:49:59 +00:00
|
|
|
case 3:
|
|
|
|
if(id == 1) return true;
|
2020-11-16 17:12:05 +00:00
|
|
|
break;
|
2022-05-05 09:49:59 +00:00
|
|
|
case 6:
|
|
|
|
if(id == 3) return true;
|
2020-11-16 17:12:05 +00:00
|
|
|
break;
|
2022-05-05 09:49:59 +00:00
|
|
|
case 8:
|
|
|
|
if(id == 4) return true;
|
2020-11-16 17:12:05 +00:00
|
|
|
break;
|
2022-05-05 09:49:59 +00:00
|
|
|
case 10:
|
|
|
|
if(id == 5) return true;
|
2020-11-16 17:12:05 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2022-05-05 09:49:59 +00:00
|
|
|
return false;
|
2020-11-16 17:12:05 +00:00
|
|
|
}
|
|
|
|
|
2020-12-14 10:50:32 +00:00
|
|
|
static void render_callback(Canvas* canvas, void* ctx) {
|
2022-05-05 09:49:59 +00:00
|
|
|
MusicPlayer* music_player = ctx;
|
2022-07-20 10:56:33 +00:00
|
|
|
furi_check(furi_mutex_acquire(music_player->model_mutex, FuriWaitForever) == FuriStatusOk);
|
2020-11-16 17:12:05 +00:00
|
|
|
|
2020-12-14 10:50:32 +00:00
|
|
|
canvas_clear(canvas);
|
|
|
|
canvas_set_color(canvas, ColorBlack);
|
|
|
|
canvas_set_font(canvas, FontPrimary);
|
|
|
|
canvas_draw_str(canvas, 0, 12, "MusicPlayer");
|
2020-11-16 17:12:05 +00:00
|
|
|
|
|
|
|
uint8_t x_pos = 0;
|
|
|
|
uint8_t y_pos = 24;
|
|
|
|
const uint8_t white_w = 10;
|
|
|
|
const uint8_t white_h = 40;
|
|
|
|
|
|
|
|
const int8_t black_x = 6;
|
|
|
|
const int8_t black_y = -5;
|
|
|
|
const uint8_t black_w = 8;
|
|
|
|
const uint8_t black_h = 32;
|
|
|
|
|
|
|
|
// white keys
|
|
|
|
for(size_t i = 0; i < 7; i++) {
|
2022-05-05 09:49:59 +00:00
|
|
|
if(is_white_note(music_player->model->semitone, i)) {
|
2020-12-14 10:50:32 +00:00
|
|
|
canvas_draw_box(canvas, x_pos + white_w * i, y_pos, white_w + 1, white_h);
|
2020-11-16 17:12:05 +00:00
|
|
|
} else {
|
2020-12-14 10:50:32 +00:00
|
|
|
canvas_draw_frame(canvas, x_pos + white_w * i, y_pos, white_w + 1, white_h);
|
2020-11-16 17:12:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// black keys
|
|
|
|
for(size_t i = 0; i < 7; i++) {
|
|
|
|
if(i != 2 && i != 6) {
|
2020-12-14 10:50:32 +00:00
|
|
|
canvas_set_color(canvas, ColorWhite);
|
|
|
|
canvas_draw_box(
|
2020-11-16 17:12:05 +00:00
|
|
|
canvas, x_pos + white_w * i + black_x, y_pos + black_y, black_w + 1, black_h);
|
2020-12-14 10:50:32 +00:00
|
|
|
canvas_set_color(canvas, ColorBlack);
|
2022-05-05 09:49:59 +00:00
|
|
|
if(is_black_note(music_player->model->semitone, i)) {
|
2020-12-14 10:50:32 +00:00
|
|
|
canvas_draw_box(
|
2020-11-16 17:12:05 +00:00
|
|
|
canvas, x_pos + white_w * i + black_x, y_pos + black_y, black_w + 1, black_h);
|
|
|
|
} else {
|
2020-12-14 10:50:32 +00:00
|
|
|
canvas_draw_frame(
|
2020-11-16 17:12:05 +00:00
|
|
|
canvas, x_pos + white_w * i + black_x, y_pos + black_y, black_w + 1, black_h);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-29 13:52:16 +00:00
|
|
|
// volume view_port
|
2020-11-16 17:12:05 +00:00
|
|
|
x_pos = 124;
|
|
|
|
y_pos = 0;
|
2022-05-05 09:49:59 +00:00
|
|
|
const uint8_t volume_h =
|
|
|
|
(64 / (COUNT_OF(MUSIC_PLAYER_VOLUMES) - 1)) * music_player->model->volume;
|
2020-12-14 10:50:32 +00:00
|
|
|
canvas_draw_frame(canvas, x_pos, y_pos, 4, 64);
|
|
|
|
canvas_draw_box(canvas, x_pos, y_pos + (64 - volume_h), 4, volume_h);
|
2020-11-16 17:12:05 +00:00
|
|
|
|
2021-01-29 13:52:16 +00:00
|
|
|
// note stack view_port
|
2020-11-16 17:12:05 +00:00
|
|
|
x_pos = 73;
|
|
|
|
y_pos = 0;
|
2020-12-14 10:50:32 +00:00
|
|
|
canvas_set_color(canvas, ColorBlack);
|
|
|
|
canvas_set_font(canvas, FontPrimary);
|
|
|
|
canvas_draw_frame(canvas, x_pos, y_pos, 49, 64);
|
|
|
|
canvas_draw_line(canvas, x_pos + 28, 0, x_pos + 28, 64);
|
2020-11-16 17:12:05 +00:00
|
|
|
|
2022-05-05 09:49:59 +00:00
|
|
|
char duration_text[16];
|
|
|
|
for(uint8_t i = 0; i < MUSIC_PLAYER_SEMITONE_HISTORY_SIZE; i++) {
|
|
|
|
if(music_player->model->duration_history[i] == 0xFF) {
|
|
|
|
snprintf(duration_text, 15, "--");
|
|
|
|
} else {
|
|
|
|
snprintf(duration_text, 15, "%d", music_player->model->duration_history[i]);
|
|
|
|
}
|
|
|
|
|
2020-11-16 17:12:05 +00:00
|
|
|
if(i == 0) {
|
2020-12-14 10:50:32 +00:00
|
|
|
canvas_draw_box(canvas, x_pos, y_pos + 48, 49, 16);
|
|
|
|
canvas_set_color(canvas, ColorWhite);
|
2020-11-16 17:12:05 +00:00
|
|
|
} else {
|
2020-12-14 10:50:32 +00:00
|
|
|
canvas_set_color(canvas, ColorBlack);
|
2020-11-16 17:12:05 +00:00
|
|
|
}
|
2020-12-14 10:50:32 +00:00
|
|
|
canvas_draw_str(
|
2022-05-05 09:49:59 +00:00
|
|
|
canvas,
|
|
|
|
x_pos + 4,
|
|
|
|
64 - 16 * i - 3,
|
|
|
|
semitone_to_note(music_player->model->semitone_history[i]));
|
|
|
|
canvas_draw_str(canvas, x_pos + 31, 64 - 16 * i - 3, duration_text);
|
2020-12-14 10:50:32 +00:00
|
|
|
canvas_draw_line(canvas, x_pos, 64 - 16 * i, x_pos + 48, 64 - 16 * i);
|
2020-11-16 17:12:05 +00:00
|
|
|
}
|
|
|
|
|
2022-07-20 10:56:33 +00:00
|
|
|
furi_mutex_release(music_player->model_mutex);
|
2020-11-16 17:12:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void input_callback(InputEvent* input_event, void* ctx) {
|
2022-05-05 09:49:59 +00:00
|
|
|
MusicPlayer* music_player = ctx;
|
|
|
|
if(input_event->type == InputTypeShort) {
|
2022-07-20 10:56:33 +00:00
|
|
|
furi_message_queue_put(music_player->input_queue, input_event, 0);
|
2022-05-05 09:49:59 +00:00
|
|
|
}
|
2020-11-16 17:12:05 +00:00
|
|
|
}
|
|
|
|
|
2022-05-05 09:49:59 +00:00
|
|
|
static void music_player_worker_callback(
|
|
|
|
uint8_t semitone,
|
|
|
|
uint8_t dots,
|
|
|
|
uint8_t duration,
|
|
|
|
float position,
|
|
|
|
void* context) {
|
|
|
|
MusicPlayer* music_player = context;
|
2022-07-20 10:56:33 +00:00
|
|
|
furi_check(furi_mutex_acquire(music_player->model_mutex, FuriWaitForever) == FuriStatusOk);
|
2022-05-05 09:49:59 +00:00
|
|
|
|
|
|
|
for(size_t i = 0; i < MUSIC_PLAYER_SEMITONE_HISTORY_SIZE - 1; i++) {
|
|
|
|
size_t r = MUSIC_PLAYER_SEMITONE_HISTORY_SIZE - 1 - i;
|
|
|
|
music_player->model->duration_history[r] = music_player->model->duration_history[r - 1];
|
|
|
|
music_player->model->semitone_history[r] = music_player->model->semitone_history[r - 1];
|
2020-11-16 17:12:05 +00:00
|
|
|
}
|
2022-05-05 09:49:59 +00:00
|
|
|
|
|
|
|
semitone = (semitone == 0xFF) ? 0xFF : semitone % 12;
|
|
|
|
|
|
|
|
music_player->model->semitone = semitone;
|
|
|
|
music_player->model->dots = dots;
|
|
|
|
music_player->model->duration = duration;
|
|
|
|
music_player->model->position = position;
|
|
|
|
|
|
|
|
music_player->model->semitone_history[0] = semitone;
|
|
|
|
music_player->model->duration_history[0] = duration;
|
|
|
|
|
2022-07-20 10:56:33 +00:00
|
|
|
furi_mutex_release(music_player->model_mutex);
|
2022-05-05 09:49:59 +00:00
|
|
|
view_port_update(music_player->view_port);
|
2020-11-16 17:12:05 +00:00
|
|
|
}
|
|
|
|
|
2022-10-08 10:13:26 +00:00
|
|
|
void music_player_clear(MusicPlayer* instance) {
|
|
|
|
memset(instance->model->duration_history, 0xff, MUSIC_PLAYER_SEMITONE_HISTORY_SIZE);
|
|
|
|
memset(instance->model->semitone_history, 0xff, MUSIC_PLAYER_SEMITONE_HISTORY_SIZE);
|
|
|
|
music_player_worker_clear(instance->worker);
|
|
|
|
}
|
|
|
|
|
2022-05-05 09:49:59 +00:00
|
|
|
MusicPlayer* music_player_alloc() {
|
|
|
|
MusicPlayer* instance = malloc(sizeof(MusicPlayer));
|
2020-11-16 17:12:05 +00:00
|
|
|
|
2022-05-05 09:49:59 +00:00
|
|
|
instance->model = malloc(sizeof(MusicPlayerModel));
|
|
|
|
instance->model->volume = 3;
|
2020-11-16 17:12:05 +00:00
|
|
|
|
2022-07-20 10:56:33 +00:00
|
|
|
instance->model_mutex = furi_mutex_alloc(FuriMutexTypeNormal);
|
2020-11-16 17:12:05 +00:00
|
|
|
|
2022-07-20 10:56:33 +00:00
|
|
|
instance->input_queue = furi_message_queue_alloc(8, sizeof(InputEvent));
|
2022-05-05 09:49:59 +00:00
|
|
|
|
|
|
|
instance->worker = music_player_worker_alloc();
|
|
|
|
music_player_worker_set_volume(
|
|
|
|
instance->worker, MUSIC_PLAYER_VOLUMES[instance->model->volume]);
|
|
|
|
music_player_worker_set_callback(instance->worker, music_player_worker_callback, instance);
|
|
|
|
|
2022-10-08 10:13:26 +00:00
|
|
|
music_player_clear(instance);
|
|
|
|
|
2022-05-05 09:49:59 +00:00
|
|
|
instance->view_port = view_port_alloc();
|
|
|
|
view_port_draw_callback_set(instance->view_port, render_callback, instance);
|
|
|
|
view_port_input_callback_set(instance->view_port, input_callback, instance);
|
|
|
|
|
|
|
|
// Open GUI and register view_port
|
2022-07-26 12:21:51 +00:00
|
|
|
instance->gui = furi_record_open(RECORD_GUI);
|
2022-05-05 09:49:59 +00:00
|
|
|
gui_add_view_port(instance->gui, instance->view_port, GuiLayerFullscreen);
|
|
|
|
|
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
void music_player_free(MusicPlayer* instance) {
|
|
|
|
gui_remove_view_port(instance->gui, instance->view_port);
|
2022-07-26 12:21:51 +00:00
|
|
|
furi_record_close(RECORD_GUI);
|
2022-05-05 09:49:59 +00:00
|
|
|
view_port_free(instance->view_port);
|
|
|
|
|
|
|
|
music_player_worker_free(instance->worker);
|
|
|
|
|
2022-07-20 10:56:33 +00:00
|
|
|
furi_message_queue_free(instance->input_queue);
|
2022-05-05 09:49:59 +00:00
|
|
|
|
2022-07-20 10:56:33 +00:00
|
|
|
furi_mutex_free(instance->model_mutex);
|
2022-05-05 09:49:59 +00:00
|
|
|
|
|
|
|
free(instance->model);
|
|
|
|
free(instance);
|
2020-11-16 17:12:05 +00:00
|
|
|
}
|
|
|
|
|
2021-08-07 16:54:42 +00:00
|
|
|
int32_t music_player_app(void* p) {
|
2022-05-05 09:49:59 +00:00
|
|
|
MusicPlayer* music_player = music_player_alloc();
|
2020-11-16 17:12:05 +00:00
|
|
|
|
2022-10-05 15:15:23 +00:00
|
|
|
FuriString* file_path;
|
|
|
|
file_path = furi_string_alloc();
|
2020-11-16 17:12:05 +00:00
|
|
|
|
2022-05-05 09:49:59 +00:00
|
|
|
do {
|
2022-08-03 15:47:10 +00:00
|
|
|
if(p && strlen(p)) {
|
2022-10-08 10:13:26 +00:00
|
|
|
furi_string_set(file_path, (const char*)p);
|
2022-05-05 09:49:59 +00:00
|
|
|
} else {
|
2022-10-05 15:15:23 +00:00
|
|
|
furi_string_set(file_path, MUSIC_PLAYER_APP_PATH_FOLDER);
|
2022-05-27 11:19:21 +00:00
|
|
|
|
2022-09-14 16:11:38 +00:00
|
|
|
DialogsFileBrowserOptions browser_options;
|
|
|
|
dialog_file_browser_set_basic_options(
|
|
|
|
&browser_options, MUSIC_PLAYER_APP_EXTENSION, &I_music_10px);
|
|
|
|
browser_options.hide_ext = false;
|
2022-12-07 14:17:41 +00:00
|
|
|
browser_options.base_path = MUSIC_PLAYER_APP_PATH_FOLDER;
|
2022-09-14 16:11:38 +00:00
|
|
|
|
2022-07-26 12:21:51 +00:00
|
|
|
DialogsApp* dialogs = furi_record_open(RECORD_DIALOGS);
|
2022-09-14 16:11:38 +00:00
|
|
|
bool res = dialog_file_browser_show(dialogs, file_path, file_path, &browser_options);
|
2022-05-27 11:19:21 +00:00
|
|
|
|
2022-07-26 12:21:51 +00:00
|
|
|
furi_record_close(RECORD_DIALOGS);
|
2022-05-05 09:49:59 +00:00
|
|
|
if(!res) {
|
|
|
|
FURI_LOG_E(TAG, "No file selected");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2020-11-16 17:12:05 +00:00
|
|
|
|
2022-10-05 15:15:23 +00:00
|
|
|
if(!music_player_worker_load(music_player->worker, furi_string_get_cstr(file_path))) {
|
2022-05-05 09:49:59 +00:00
|
|
|
FURI_LOG_E(TAG, "Unable to load file");
|
|
|
|
break;
|
|
|
|
}
|
2020-11-16 17:12:05 +00:00
|
|
|
|
2022-05-05 09:49:59 +00:00
|
|
|
music_player_worker_start(music_player->worker);
|
2020-11-16 21:39:48 +00:00
|
|
|
|
2022-05-05 09:49:59 +00:00
|
|
|
InputEvent input;
|
2022-07-20 10:56:33 +00:00
|
|
|
while(furi_message_queue_get(music_player->input_queue, &input, FuriWaitForever) ==
|
|
|
|
FuriStatusOk) {
|
|
|
|
furi_check(
|
|
|
|
furi_mutex_acquire(music_player->model_mutex, FuriWaitForever) == FuriStatusOk);
|
2022-05-05 09:49:59 +00:00
|
|
|
|
|
|
|
if(input.key == InputKeyBack) {
|
2022-07-20 10:56:33 +00:00
|
|
|
furi_mutex_release(music_player->model_mutex);
|
2022-05-05 09:49:59 +00:00
|
|
|
break;
|
|
|
|
} else if(input.key == InputKeyUp) {
|
|
|
|
if(music_player->model->volume < COUNT_OF(MUSIC_PLAYER_VOLUMES) - 1)
|
|
|
|
music_player->model->volume++;
|
|
|
|
music_player_worker_set_volume(
|
|
|
|
music_player->worker, MUSIC_PLAYER_VOLUMES[music_player->model->volume]);
|
|
|
|
} else if(input.key == InputKeyDown) {
|
|
|
|
if(music_player->model->volume > 0) music_player->model->volume--;
|
|
|
|
music_player_worker_set_volume(
|
|
|
|
music_player->worker, MUSIC_PLAYER_VOLUMES[music_player->model->volume]);
|
2020-11-16 17:12:05 +00:00
|
|
|
}
|
2022-05-05 09:49:59 +00:00
|
|
|
|
2022-07-20 10:56:33 +00:00
|
|
|
furi_mutex_release(music_player->model_mutex);
|
2022-05-05 09:49:59 +00:00
|
|
|
view_port_update(music_player->view_port);
|
2020-11-16 17:12:05 +00:00
|
|
|
}
|
|
|
|
|
2022-05-05 09:49:59 +00:00
|
|
|
music_player_worker_stop(music_player->worker);
|
2022-10-08 10:13:26 +00:00
|
|
|
if(p && strlen(p)) break; // Exit instead of going to browser if launched with arg
|
|
|
|
music_player_clear(music_player);
|
|
|
|
} while(1);
|
2021-02-12 17:24:34 +00:00
|
|
|
|
2022-10-05 15:15:23 +00:00
|
|
|
furi_string_free(file_path);
|
2022-05-05 09:49:59 +00:00
|
|
|
music_player_free(music_player);
|
2021-09-01 21:05:00 +00:00
|
|
|
|
2021-02-12 17:24:34 +00:00
|
|
|
return 0;
|
2020-11-16 17:12:05 +00:00
|
|
|
}
|