void programmer(void) /* Handles the front panel functions when at the top level The whole thing is basically a large loop going through the array of possible button presses and combinations. */ { static int8_t patchno = 0; // Display the selected patch number leds_7seg_two_digit_set(3, 4, patchno); int8_t last_patchno = patchno; // Handle UP and DOWN presses ui_updown(&patchno, PATCH_MIN, PATCH_MAX); if (state == STATE_SAVE) { patch_save(patchno); state = STATE_TOPLEVEL; } else if (patchno != last_patchno) patch_load(patchno); if (button_pressed(BTN_SAVE)) { ui_getvalue_session.button1 = BTN_SAVE; ui_getvalue_session.button2 = 0xFF; ui_getvalue_session.parameter.target = &patchno; ui_getvalue_session.parameter.type = RANGE; ui_getvalue_session.parameter.min = PATCH_MIN; ui_getvalue_session.parameter.max = PATCH_MAX; mode |= MODE_GETVALUE; state = STATE_SAVE; return; } sq1.enabled ? button_led_on(BTN_SQ1) : button_led_off(BTN_SQ1); sq2.enabled ? button_led_on(BTN_SQ2) : button_led_off(BTN_SQ2); tri.enabled ? button_led_on(BTN_TRI) : button_led_off(BTN_TRI); noise.enabled ? button_led_on(BTN_NOISE) : button_led_off(BTN_NOISE); dmc.enabled ? button_led_on(BTN_DMC) : button_led_off(BTN_DMC); toplevel_handler(); }
void synth_main() { gfx_wave_render_initialise(); gfx_envelope_render_initialise(); create_settings(); create_ui(); gfx_event_initialise(); gfx_initialise(); patch_initialise(); synth_initialise(); configure_audio(); configure_profiling(); config_setting_t* piglow_config = config_lookup(&app_config, CFG_DEVICES_PIGLOW); if (piglow_config != NULL) { piglow_initialise(piglow_config); } waveform_initialise(); gfx_register_event_global_handler(GFX_EVENT_BUFFERSWAP, process_buffer_swap); // Done after synth setup as this can load controller values into the synth configure_midi(); int profiling = 0; int32_t last_timestamp = get_elapsed_time_ms(); while (1) { int midi_controller_value; if (midi_controller_update_and_read(&exit_controller, &midi_controller_value)) { break; } if (midi_controller_update_and_read(&screenshot_controller, &midi_controller_value)) { static int screenshot_count = 0; char screenshot_name[64]; sprintf(screenshot_name, "pithesiser-img-%03d.png", screenshot_count++); gfx_screenshot(screenshot_name); } process_midi_events(); if (!profiling && midi_controller_update_and_read(&profile_controller, &midi_controller_value)) { if (profile_file != NULL) { ProfilerStart(profile_file); profiling = 1; } } alsa_sync_with_audio_output(); int32_t timestamp = get_elapsed_time_ms(); process_audio(timestamp - last_timestamp); last_timestamp = timestamp; } if (profiling) { ProfilerStop(); } synth_controllers_save(SETTINGS_FILE); patch_save(); patch_deinitialise(); piglow_deinitialise(); gfx_deinitialise(); destroy_ui(); gfx_envelope_render_deinitialise(); gfx_wave_render_deinitialise(); mod_matrix_controller_deinitialise(); alsa_deinitialise(); midi_deinitialise(); synth_deinitialise(); config_destroy(&app_config); LOG_INFO("Done: %d xruns", alsa_get_xruns_count()); }