static int eq_do_simple_menu(void * param) { (void)param; struct simplelist_info info; struct settings_list setting; char title[MAX_PATH]; simplelist_info_init(&info, str(LANG_EQUALIZER_GAIN), EQ_NUM_BANDS, NULL); info.get_name = (list_get_name*)gainitem_get_name; info.get_talk = gainitem_speak_item; info.get_icon = gainitem_get_icon; info.action_callback = simplelist_action_callback; info.selection = -1; info.title_icon = Icon_Submenu; setting.flags = F_BANFROMQS|F_INT_SETTING|F_T_INT|F_NO_WRAP; setting.lang_id = LANG_GAIN; setting.default_val.int_ = 0; setting.int_setting = &gain_int_setting; while (true) { simplelist_show_list(&info); if (info.selection < 0) break; pcmbuf_set_low_latency(true); setting.setting = &global_settings.eq_band_settings[info.selection].gain; option_screen(&setting, NULL, false, gainitem_get_name(info.selection, NULL, title, MAX_PATH)); eq_apply(); pcmbuf_set_low_latency(false); } return 0; }
/* Use this callback if your menu adjusts DSP settings. */ int lowlatency_callback(int action, const struct menu_item_ex *this_item) { (void)this_item; switch (action) { case ACTION_ENTER_MENUITEM: /* on entering an item */ pcmbuf_set_low_latency(true); break; case ACTION_EXIT_MENUITEM: /* on exit */ pcmbuf_set_low_latency(false); break; } return action; }
int gui_syncpitchscreen_run(void) { int button, i; int32_t pitch = sound_get_pitch(); int32_t semitone; int32_t new_pitch; int32_t pitch_delta; bool nudged = false; bool exit = false; /* should maybe be passed per parameter later, not needed for now */ struct viewport parent[NB_SCREENS]; struct viewport pitch_viewports[NB_SCREENS][PITCH_ITEM_COUNT]; int max_lines[NB_SCREENS]; #if CONFIG_CODEC == SWCODEC int32_t new_speed = 0, new_stretch; /* the speed variable holds the apparent speed of the playback */ int32_t speed; if (dsp_timestretch_available()) { speed = GET_SPEED(pitch, dsp_get_timestretch()); } else { speed = pitch; } /* Figure out whether to be in timestretch mode */ if (global_settings.pitch_mode_timestretch && !dsp_timestretch_available()) { global_settings.pitch_mode_timestretch = false; settings_save(); } #endif /* set the semitone index based on the current pitch */ semitone = get_semitone_from_pitch(pitch); /* initialize pitchscreen vps */ FOR_NB_SCREENS(i) { viewport_set_defaults(&parent[i], i); max_lines[i] = viewport_get_nb_lines(&parent[i]); pitchscreen_fix_viewports(&parent[i], pitch_viewports[i]); screens[i].set_viewport(&parent[i]); screens[i].clear_viewport(); /* also, draw the icons now, it's only needed once */ pitchscreen_draw_icons(&screens[i], &parent[i]); } #if CONFIG_CODEC == SWCODEC pcmbuf_set_low_latency(true); #endif while (!exit) { FOR_NB_SCREENS(i) pitchscreen_draw(&screens[i], max_lines[i], pitch_viewports[i], pitch, semitone #if CONFIG_CODEC == SWCODEC , speed #endif ); pitch_delta = 0; #if CONFIG_CODEC == SWCODEC new_speed = 0; #endif button = get_action(CONTEXT_PITCHSCREEN, HZ); #ifdef HAVE_TOUCHSCREEN if (button == ACTION_TOUCHSCREEN) { FOR_NB_SCREENS(i) button = pitchscreen_do_touchscreen(pitch_viewports[i]); } #endif switch (button) { case ACTION_PS_INC_SMALL: if(global_settings.pitch_mode_semitone) pitch_delta = SEMITONE_SMALL_DELTA; else pitch_delta = PITCH_SMALL_DELTA; break; case ACTION_PS_INC_BIG: if(global_settings.pitch_mode_semitone) pitch_delta = SEMITONE_BIG_DELTA; else pitch_delta = PITCH_BIG_DELTA; break; case ACTION_PS_DEC_SMALL: if(global_settings.pitch_mode_semitone) pitch_delta = -SEMITONE_SMALL_DELTA; else pitch_delta = -PITCH_SMALL_DELTA; break; case ACTION_PS_DEC_BIG: if(global_settings.pitch_mode_semitone) pitch_delta = -SEMITONE_BIG_DELTA; else pitch_delta = -PITCH_BIG_DELTA; break; case ACTION_PS_NUDGE_RIGHT: #if CONFIG_CODEC == SWCODEC if (!global_settings.pitch_mode_timestretch) { #endif new_pitch = pitch_increase(pitch, PITCH_NUDGE_DELTA, false #if CONFIG_CODEC == SWCODEC , speed #endif ); nudged = (new_pitch != pitch); pitch = new_pitch; semitone = get_semitone_from_pitch(pitch); #if CONFIG_CODEC == SWCODEC speed = pitch; #endif break; #if CONFIG_CODEC == SWCODEC } else { new_speed = speed + SPEED_SMALL_DELTA; at_limit = false; } break; case ACTION_PS_FASTER: if (global_settings.pitch_mode_timestretch) { new_speed = speed + SPEED_BIG_DELTA; /* snap to whole numbers */ if(new_speed % PITCH_SPEED_PRECISION != 0) new_speed -= new_speed % PITCH_SPEED_PRECISION; at_limit = false; } break; #endif case ACTION_PS_NUDGE_RIGHTOFF: if (nudged) { pitch = pitch_increase(pitch, -PITCH_NUDGE_DELTA, false #if CONFIG_CODEC == SWCODEC , speed #endif ); #if CONFIG_CODEC == SWCODEC speed = pitch; #endif semitone = get_semitone_from_pitch(pitch); nudged = false; } break; case ACTION_PS_NUDGE_LEFT: #if CONFIG_CODEC == SWCODEC if (!global_settings.pitch_mode_timestretch) { #endif new_pitch = pitch_increase(pitch, -PITCH_NUDGE_DELTA, false #if CONFIG_CODEC == SWCODEC , speed #endif ); nudged = (new_pitch != pitch); pitch = new_pitch; semitone = get_semitone_from_pitch(pitch); #if CONFIG_CODEC == SWCODEC speed = pitch; #endif break; #if CONFIG_CODEC == SWCODEC } else { new_speed = speed - SPEED_SMALL_DELTA; at_limit = false; } break; case ACTION_PS_SLOWER: if (global_settings.pitch_mode_timestretch) { new_speed = speed - SPEED_BIG_DELTA; /* snap to whole numbers */ if(new_speed % PITCH_SPEED_PRECISION != 0) new_speed += PITCH_SPEED_PRECISION - speed % PITCH_SPEED_PRECISION; at_limit = false; } break; #endif case ACTION_PS_NUDGE_LEFTOFF: if (nudged) { pitch = pitch_increase(pitch, PITCH_NUDGE_DELTA, false #if CONFIG_CODEC == SWCODEC , speed #endif ); #if CONFIG_CODEC == SWCODEC speed = pitch; #endif semitone = get_semitone_from_pitch(pitch); nudged = false; } break; case ACTION_PS_RESET: pitch = PITCH_SPEED_100; sound_set_pitch(pitch); #if CONFIG_CODEC == SWCODEC speed = PITCH_SPEED_100; if (dsp_timestretch_available()) { dsp_set_timestretch(PITCH_SPEED_100); at_limit = false; } #endif semitone = get_semitone_from_pitch(pitch); break; case ACTION_PS_TOGGLE_MODE: global_settings.pitch_mode_semitone = !global_settings.pitch_mode_semitone; #if CONFIG_CODEC == SWCODEC if (dsp_timestretch_available() && !global_settings.pitch_mode_semitone) { global_settings.pitch_mode_timestretch = !global_settings.pitch_mode_timestretch; if(!global_settings.pitch_mode_timestretch) { /* no longer in timestretch mode. Reset speed */ speed = pitch; dsp_set_timestretch(PITCH_SPEED_100); } } settings_save(); #endif break; case ACTION_PS_EXIT: exit = true; break; default: if (default_event_handler(button) == SYS_USB_CONNECTED) return 1; break; } if (pitch_delta) { if (global_settings.pitch_mode_semitone) { semitone = pitch_increase_semitone(pitch, semitone, pitch_delta #if CONFIG_CODEC == SWCODEC , speed #endif ); pitch = get_pitch_from_semitone(semitone); } else { pitch = pitch_increase(pitch, pitch_delta, true #if CONFIG_CODEC == SWCODEC , speed #endif ); semitone = get_semitone_from_pitch(pitch); } #if CONFIG_CODEC == SWCODEC if (global_settings.pitch_mode_timestretch) { /* do this to make sure we properly obey the stretch limits */ new_speed = speed; } else { speed = pitch; } #endif } #if CONFIG_CODEC == SWCODEC if(new_speed) { new_stretch = GET_STRETCH(pitch, new_speed); /* limit the amount of stretch */ if(new_stretch > STRETCH_MAX) { new_stretch = STRETCH_MAX; new_speed = GET_SPEED(pitch, new_stretch); } else if(new_stretch < STRETCH_MIN) { new_stretch = STRETCH_MIN; new_speed = GET_SPEED(pitch, new_stretch); } new_stretch = GET_STRETCH(pitch, new_speed); if(new_stretch >= STRETCH_MAX || new_stretch <= STRETCH_MIN) { at_limit = true; } /* set the amount of stretch */ dsp_set_timestretch(new_stretch); /* update the speed variable with the new speed */ speed = new_speed; /* Reset new_speed so we only call dsp_set_timestretch */ /* when needed */ new_speed = 0; } #endif } #if CONFIG_CODEC == SWCODEC pcmbuf_set_low_latency(false); #endif return 0; }
static int eq_do_advanced_menu(void * param) { (void)param; struct simplelist_info info; struct settings_list setting; char title[MAX_PATH]; int band, item; intptr_t selected_band = -1; simplelist_info_init(&info, str(LANG_EQUALIZER_ADVANCED), EQ_NUM_BANDS, &selected_band); info.get_name = (list_get_name*)advancedmenu_item_get_name; info.get_talk = advancedmenu_speak_item; info.get_icon = advancedmenu_get_icon; info.action_callback = simplelist_action_callback; info.selection = -1; info.title_icon = Icon_EQ; setting.flags = F_BANFROMQS|F_INT_SETTING|F_T_INT|F_NO_WRAP; while (true) { simplelist_show_list(&info); if (info.selection < 0) break; selection_to_banditem(info.selection, selected_band, &band, &item); switch (item) { case 0: /* title, do nothing */ { int extra; if (selected_band == band) { extra = 0; selected_band = -1; } else { extra = 3; selected_band = band; } info.selection = band; info.count = EQ_NUM_BANDS + extra; continue; } case 1: /* cutoff */ if (band == 0 || band == EQ_NUM_BANDS - 1) setting.lang_id = LANG_EQUALIZER_BAND_CUTOFF; else setting.lang_id = LANG_EQUALIZER_BAND_CENTER; setting.default_val.int_ = eq_defaults[band].cutoff; setting.int_setting = &cutoff_int_setting; setting.setting = &global_settings.eq_band_settings[band].cutoff; break; case 2: /* Q */ setting.lang_id = LANG_EQUALIZER_BAND_Q; setting.default_val.int_ = eq_defaults[band].q; setting.int_setting = &q_int_setting; setting.setting = &global_settings.eq_band_settings[band].q; break; case 3: /* Gain */ setting.lang_id = LANG_GAIN; setting.default_val.int_ = eq_defaults[band].gain; setting.int_setting = &gain_int_setting; setting.setting = &global_settings.eq_band_settings[band].gain; break; } pcmbuf_set_low_latency(true); advancedmenu_item_get_name(info.selection, &selected_band, title, MAX_PATH); option_screen(&setting, NULL, false, title[0] == '\t' ? &title[1] : title); eq_apply(); pcmbuf_set_low_latency(false); } return 0; }