music_player: Return to browser instead of exiting on back button (#1846)

* music_player: Return to browser instead of exiting on back button
* music_player: Fix number and dots extraction
This commit is contained in:
Yukai Li 2022-10-08 04:13:26 -06:00 committed by GitHub
parent d10e16ca3c
commit 88ca267466
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 4 deletions

View File

@ -248,12 +248,16 @@ static void music_player_worker_callback(
view_port_update(music_player->view_port);
}
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);
}
MusicPlayer* music_player_alloc() {
MusicPlayer* instance = malloc(sizeof(MusicPlayer));
instance->model = malloc(sizeof(MusicPlayerModel));
memset(instance->model->duration_history, 0xff, MUSIC_PLAYER_SEMITONE_HISTORY_SIZE);
memset(instance->model->semitone_history, 0xff, MUSIC_PLAYER_SEMITONE_HISTORY_SIZE);
instance->model->volume = 3;
instance->model_mutex = furi_mutex_alloc(FuriMutexTypeNormal);
@ -265,6 +269,8 @@ MusicPlayer* music_player_alloc() {
instance->worker, MUSIC_PLAYER_VOLUMES[instance->model->volume]);
music_player_worker_set_callback(instance->worker, music_player_worker_callback, instance);
music_player_clear(instance);
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);
@ -299,7 +305,7 @@ int32_t music_player_app(void* p) {
do {
if(p && strlen(p)) {
furi_string_cat(file_path, (const char*)p);
furi_string_set(file_path, (const char*)p);
} else {
furi_string_set(file_path, MUSIC_PLAYER_APP_PATH_FOLDER);
@ -350,7 +356,9 @@ int32_t music_player_app(void* p) {
}
music_player_worker_stop(music_player->worker);
} while(0);
if(p && strlen(p)) break; // Exit instead of going to browser if launched with arg
music_player_clear(music_player);
} while(1);
furi_string_free(file_path);
music_player_free(music_player);

View File

@ -108,6 +108,10 @@ MusicPlayerWorker* music_player_worker_alloc() {
return instance;
}
void music_player_worker_clear(MusicPlayerWorker* instance) {
NoteBlockArray_reset(instance->notes);
}
void music_player_worker_free(MusicPlayerWorker* instance) {
furi_assert(instance);
furi_thread_free(instance->thread);
@ -129,6 +133,7 @@ static bool is_space(const char c) {
static size_t extract_number(const char* string, uint32_t* number) {
size_t ret = 0;
*number = 0;
while(is_digit(*string)) {
*number *= 10;
*number += (*string - '0');
@ -140,6 +145,7 @@ static size_t extract_number(const char* string, uint32_t* number) {
static size_t extract_dots(const char* string, uint32_t* number) {
size_t ret = 0;
*number = 0;
while(*string == '.') {
*number += 1;
string++;

View File

@ -14,6 +14,8 @@ typedef struct MusicPlayerWorker MusicPlayerWorker;
MusicPlayerWorker* music_player_worker_alloc();
void music_player_worker_clear(MusicPlayerWorker* instance);
void music_player_worker_free(MusicPlayerWorker* instance);
bool music_player_worker_load(MusicPlayerWorker* instance, const char* file_path);