Skip to content

Commit

Permalink
horrible fix for new firmware + fam version bump
Browse files Browse the repository at this point in the history
  • Loading branch information
LTVA1 committed Aug 19, 2024
1 parent b702c44 commit 8377410
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 139 deletions.
2 changes: 1 addition & 1 deletion application.fam
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ App(
cdefines=["APP_FLIZZER_TRACKER"],
stack_size=2 * 1024,
order=90,
fap_version=(0, 9),
fap_version=(0, 10),
fap_description="An advanced Flipper Zero chiptune tracker with 4 channels",
fap_author="LTVA",
fap_weburl="https://github.com/LTVA1/flizzer_tracker",
Expand Down
104 changes: 5 additions & 99 deletions flizzer_tracker.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ bool input_callback(InputEvent* input_event, void* ctx) {
.type = EventTypeInput, .input = *input_event, .period = final_period};

if(!(tracker->is_loading) && !(tracker->is_saving)) {
furi_message_queue_put(tracker->event_queue, &event, FuriWaitForever);
if(event.type == EventTypeInput) {
process_input_event(tracker, &event);
}
}

consumed = true;
Expand All @@ -107,106 +109,10 @@ int32_t flizzer_tracker_app(void* p) {

FlizzerTrackerApp* tracker = init_tracker(44100, 50, true, 1024);

// Текущее событие типа кастомного типа FlizzerTrackerEvent
FlizzerTrackerEvent event;

view_dispatcher_switch_to_view(tracker->view_dispatcher, VIEW_TRACKER);
view_dispatcher_run(tracker->view_dispatcher);

// Бесконечный цикл обработки очереди событий
while(!(tracker->quit)) {
// Выбираем событие из очереди в переменную event (ждём бесконечно долго, если очередь пуста)
// и проверяем, что у нас получилось это сделать
furi_check(
furi_message_queue_get(tracker->event_queue, &event, FuriWaitForever) == FuriStatusOk);

// Наше событие — это нажатие кнопки
if(event.type == EventTypeInput) {
process_input_event(tracker, &event);
}

if(event.type == EventTypeSaveSong) {
save_song(tracker, tracker->filepath);
}

if(event.type == EventTypeSaveInstrument) {
save_instrument(tracker, tracker->filepath);
}

if(event.type == EventTypeLoadSong) {
stop_song(tracker);

tracker->tracker_engine.sequence_position = tracker->tracker_engine.pattern_position =
tracker->current_instrument = 0;

tracker->dialogs = furi_record_open(RECORD_DIALOGS);
tracker->is_loading = true;

FuriString* path;
path = furi_string_alloc();
furi_string_set(path, FLIZZER_TRACKER_FOLDER);

DialogsFileBrowserOptions browser_options;
dialog_file_browser_set_basic_options(
&browser_options, SONG_FILE_EXT, &I_flizzer_tracker_module);
browser_options.base_path = FLIZZER_TRACKER_FOLDER;
browser_options.hide_ext = false;

bool ret = dialog_file_browser_show(tracker->dialogs, path, path, &browser_options);

furi_record_close(RECORD_DIALOGS);

const char* cpath = furi_string_get_cstr(path);

if(ret && strcmp(&cpath[strlen(cpath) - 4], SONG_FILE_EXT) == 0) {
bool result = load_song_util(tracker, path);
UNUSED(result);
}

else {
furi_string_free(path);
tracker->is_loading = false;
}
}

if(event.type == EventTypeLoadInstrument) {
stop_song(tracker);

tracker->dialogs = furi_record_open(RECORD_DIALOGS);
tracker->is_loading_instrument = true;

FuriString* path;
path = furi_string_alloc();
furi_string_set(path, FLIZZER_TRACKER_INSTRUMENTS_FOLDER);

DialogsFileBrowserOptions browser_options;
dialog_file_browser_set_basic_options(
&browser_options, INST_FILE_EXT, &I_flizzer_tracker_instrument);
browser_options.base_path = FLIZZER_TRACKER_FOLDER;
browser_options.hide_ext = false;

bool ret = dialog_file_browser_show(tracker->dialogs, path, path, &browser_options);

furi_record_close(RECORD_DIALOGS);

const char* cpath = furi_string_get_cstr(path);

if(ret && strcmp(&cpath[strlen(cpath) - 4], INST_FILE_EXT) == 0) {
bool result = load_instrument_util(tracker, path);
UNUSED(result);
}

else {
furi_string_free(path);
tracker->is_loading = false;
}
}

if(event.type == EventTypeSetAudioMode) {
sound_engine_PWM_timer_init(tracker->external_audio);

tracker->sound_engine.external_audio_output = tracker->external_audio;
}
}
//here program hangs until view_dispatcher_stop() is called!

stop();

Expand Down
18 changes: 14 additions & 4 deletions init_deinit.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,25 @@

#define AUDIO_MODES_COUNT 2

static void tracker_redraw_update_model(void* context) {
FlizzerTrackerApp* tracker = context;

view_commit_model(tracker->tracker_view->view, true);
}

TrackerView* tracker_view_alloc(FlizzerTrackerApp* tracker) {
TrackerView* tracker_view = malloc(sizeof(TrackerView));
tracker_view->view = view_alloc();
tracker_view->context = tracker;
view_set_context(tracker_view->view, tracker_view);
view_allocate_model(tracker_view->view, ViewModelTypeLocking, sizeof(TrackerViewModel));
view_allocate_model(tracker_view->view, ViewModelTypeLockFree, sizeof(TrackerViewModel));
view_set_draw_callback(tracker_view->view, draw_callback);
view_set_input_callback(tracker_view->view, input_callback);

view_dispatcher_set_event_callback_context(tracker->view_dispatcher, tracker);
view_dispatcher_set_tick_event_callback(
tracker->view_dispatcher, tracker_redraw_update_model, 250);

return tracker_view;
}

Expand Down Expand Up @@ -67,13 +77,13 @@ FlizzerTrackerApp* init_tracker(

tracker->tracker_view = tracker_view_alloc(tracker);

with_view_model(
tracker->tracker_view->view, TrackerViewModel * model, { model->tracker = tracker; }, true);

view_dispatcher_add_view(tracker->view_dispatcher, VIEW_TRACKER, tracker->tracker_view->view);
view_dispatcher_attach_to_gui(
tracker->view_dispatcher, tracker->gui, ViewDispatcherTypeFullscreen);

with_view_model(
tracker->tracker_view->view, TrackerViewModel * model, { model->tracker = tracker; }, true);

tracker->storage = furi_record_open(RECORD_STORAGE);
tracker->stream = file_stream_alloc(tracker->storage);

Expand Down
110 changes: 75 additions & 35 deletions input_event.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#include "diskop.h"

#include <flizzer_tracker_icons.h>

#define AUDIO_MODES_COUNT 2

void return_from_keyboard_callback(void* ctx) {
Expand Down Expand Up @@ -62,8 +64,7 @@ void return_from_keyboard_callback(void* ctx) {
}

else {
FlizzerTrackerEvent event = {.type = EventTypeSaveSong, .input = {{0}}, .period = 0};
furi_message_queue_put(tracker->event_queue, &event, FuriWaitForever);
save_song(tracker, tracker->filepath);
}
}

Expand All @@ -85,9 +86,7 @@ void return_from_keyboard_callback(void* ctx) {
}

else {
FlizzerTrackerEvent event = {
.type = EventTypeSaveInstrument, .input = {{0}}, .period = 0};
furi_message_queue_put(tracker->event_queue, &event, FuriWaitForever);
save_instrument(tracker, tracker->filepath);
}
}
}
Expand All @@ -100,10 +99,8 @@ void overwrite_file_widget_yes_input_callback(GuiButtonType result, InputType ty
if(type == InputTypeShort) {
tracker->is_saving = true;
view_dispatcher_switch_to_view(tracker->view_dispatcher, VIEW_TRACKER);
// save_song(tracker, tracker->filepath);
static FlizzerTrackerEvent event = {
.type = EventTypeSaveSong, .input = {{0}}, .period = 0};
furi_message_queue_put(tracker->event_queue, &event, FuriWaitForever);

save_song(tracker, tracker->filepath);
}
}

Expand Down Expand Up @@ -170,15 +167,8 @@ void submenu_callback(void* context, uint32_t index) {
switch(index) {
case SUBMENU_PATTERN_EXIT: {
tracker->quit = true;

static InputEvent inevent = {.sequence = 0, .key = InputKeyLeft, .type = InputTypeMAX};
FlizzerTrackerEvent event = {
.type = EventTypeInput,
.input = inevent,
.period =
0}; // making an event so tracker does not wait for next keypress and exits immediately
furi_message_queue_put(tracker->event_queue, &event, FuriWaitForever);
view_dispatcher_switch_to_view(tracker->view_dispatcher, VIEW_TRACKER);
view_dispatcher_stop(tracker->view_dispatcher);
break;
}

Expand Down Expand Up @@ -206,9 +196,41 @@ void submenu_callback(void* context, uint32_t index) {
}

case SUBMENU_PATTERN_LOAD_SONG: {
FlizzerTrackerEvent event = {.type = EventTypeLoadSong, .input = {{0}}, .period = 0};
furi_message_queue_put(tracker->event_queue, &event, FuriWaitForever);
view_dispatcher_switch_to_view(tracker->view_dispatcher, VIEW_TRACKER);

stop_song(tracker);

tracker->tracker_engine.sequence_position = tracker->tracker_engine.pattern_position =
tracker->current_instrument = 0;

tracker->dialogs = furi_record_open(RECORD_DIALOGS);
tracker->is_loading = true;

FuriString* path;
path = furi_string_alloc();
furi_string_set(path, FLIZZER_TRACKER_FOLDER);

DialogsFileBrowserOptions browser_options;
dialog_file_browser_set_basic_options(
&browser_options, SONG_FILE_EXT, &I_flizzer_tracker_module);
browser_options.base_path = FLIZZER_TRACKER_FOLDER;
browser_options.hide_ext = false;

bool ret = dialog_file_browser_show(tracker->dialogs, path, path, &browser_options);

furi_record_close(RECORD_DIALOGS);

const char* cpath = furi_string_get_cstr(path);

if(ret && strcmp(&cpath[strlen(cpath) - 4], SONG_FILE_EXT) == 0) {
bool result = load_song_util(tracker, path);
UNUSED(result);
}

else {
furi_string_free(path);
tracker->is_loading = false;
}
break;
}

Expand All @@ -229,14 +251,8 @@ void submenu_callback(void* context, uint32_t index) {
case SUBMENU_INSTRUMENT_EXIT: {
tracker->quit = true;

static InputEvent inevent = {.sequence = 0, .key = InputKeyLeft, .type = InputTypeMAX};
FlizzerTrackerEvent event = {
.type = EventTypeInput,
.input = inevent,
.period =
0}; // making an event so tracker does not wait for next keypress and exits immediately
furi_message_queue_put(tracker->event_queue, &event, FuriWaitForever);
view_dispatcher_switch_to_view(tracker->view_dispatcher, VIEW_TRACKER);
view_dispatcher_stop(tracker->view_dispatcher);
break;
}

Expand All @@ -258,10 +274,38 @@ void submenu_callback(void* context, uint32_t index) {
}

case SUBMENU_INSTRUMENT_LOAD: {
FlizzerTrackerEvent event = {
.type = EventTypeLoadInstrument, .input = {{0}}, .period = 0};
furi_message_queue_put(tracker->event_queue, &event, FuriWaitForever);
view_dispatcher_switch_to_view(tracker->view_dispatcher, VIEW_TRACKER);

stop_song(tracker);

tracker->dialogs = furi_record_open(RECORD_DIALOGS);
tracker->is_loading_instrument = true;

FuriString* path;
path = furi_string_alloc();
furi_string_set(path, FLIZZER_TRACKER_INSTRUMENTS_FOLDER);

DialogsFileBrowserOptions browser_options;
dialog_file_browser_set_basic_options(
&browser_options, INST_FILE_EXT, &I_flizzer_tracker_instrument);
browser_options.base_path = FLIZZER_TRACKER_FOLDER;
browser_options.hide_ext = false;

bool ret = dialog_file_browser_show(tracker->dialogs, path, path, &browser_options);

furi_record_close(RECORD_DIALOGS);

const char* cpath = furi_string_get_cstr(path);

if(ret && strcmp(&cpath[strlen(cpath) - 4], INST_FILE_EXT) == 0) {
bool result = load_instrument_util(tracker, path);
UNUSED(result);
}

else {
furi_string_free(path);
tracker->is_loading = false;
}
break;
}

Expand Down Expand Up @@ -345,13 +389,9 @@ void audio_output_changed_callback(VariableItem* item) {

tracker->external_audio = audio_modes_values[(index > 1 ? 1 : index)];

// sound_engine_init(&tracker->sound_engine, tracker->sound_engine.sample_rate, tracker->external_audio, tracker->sound_engine.audio_buffer_size);
// sound_engine_init_hardware(tracker->sound_engine.sample_rate, tracker->external_audio, tracker->sound_engine.audio_buffer, tracker->sound_engine.audio_buffer_size);

FlizzerTrackerEvent event = {.type = EventTypeSetAudioMode, .input = {{0}}, .period = 0};
furi_message_queue_put(tracker->event_queue, &event, FuriWaitForever);
sound_engine_PWM_timer_init(tracker->external_audio);

UNUSED(event);
tracker->sound_engine.external_audio_output = tracker->external_audio;
}
}

Expand Down

0 comments on commit 8377410

Please sign in to comment.