A modern Music Player Daemon based on Rockbox open source high quality audio player
libadwaita audio rust zig deno mpris rockbox mpd

radio.c presets.c small clean-up

remove some extern vars in favor of get/set functions

Change-Id: Ic4effae2acdd480beeab76c9f0319b1783a3bab3

+65 -42
+1 -1
apps/gui/skin_engine/skin_display.c
··· 237 237 #endif 238 238 { 239 239 int min = fm_region_data[global_settings.fm_region].freq_min; 240 - end = radio_current_frequency() - min; 240 + end = radio_get_current_frequency() - min; 241 241 length = fm_region_data[global_settings.fm_region].freq_max - min; 242 242 } 243 243 }
+4 -4
apps/gui/skin_engine/skin_tokens.c
··· 455 455 return "t"; 456 456 return NULL; 457 457 case SKIN_TOKEN_TUNER_SCANMODE: 458 - if (radio_scan_mode()) 458 + if (radio_get_mode() == RADIO_SCAN_MODE) 459 459 return "s"; 460 460 return NULL; 461 461 case SKIN_TOKEN_TUNER_STEREO: ··· 469 469 return format_freq_MHz(region_data->freq_max, 470 470 region_data->freq_step, buf, buf_size); 471 471 case SKIN_TOKEN_TUNER_CURFREQ: 472 - return format_freq_MHz(radio_current_frequency(), 472 + return format_freq_MHz(radio_get_current_frequency(), 473 473 region_data->freq_step, buf, buf_size); 474 474 #ifdef HAVE_RADIO_RSSI 475 475 case SKIN_TOKEN_TUNER_RSSI: ··· 510 510 if (preset < 0) 511 511 preset += preset_count; 512 512 if (token->type == SKIN_TOKEN_PRESET_NAME) 513 - snprintf(buf, buf_size, "%s", radio_get_preset(preset)->name); 513 + snprintf(buf, buf_size, "%s", radio_get_preset_name(preset)); 514 514 else if (token->type == SKIN_TOKEN_PRESET_FREQ) 515 - format_freq_MHz(radio_get_preset(preset)->frequency, 515 + format_freq_MHz(radio_get_preset_freq(preset), 516 516 region_data->freq_step, buf, buf_size); 517 517 else 518 518 snprintf(buf, buf_size, "%d", preset + 1);
+7 -4
apps/menus/radio_menu.c
··· 92 92 #endif 93 93 94 94 #ifndef FM_MODE 95 - extern int radio_mode; 95 + 96 96 static char* get_mode_text(int selected_item, void * data, 97 97 char *buffer, size_t buffer_len) 98 98 { 99 + int radio_mode = radio_get_mode(); 99 100 (void)selected_item; 100 101 (void)data; 101 102 snprintf(buffer, buffer_len, "%s %s", str(LANG_MODE), ··· 105 106 } 106 107 static int mode_speak_item(int selected_item, void * data) 107 108 { 109 + int radio_mode = radio_get_mode(); 108 110 (void)selected_item; 109 111 (void)data; 110 112 long talk_ids[4]; 111 113 talk_ids[0] = LANG_MODE; 112 - talk_ids[1] = radio_mode ? LANG_PRESET : LANG_RADIO_SCAN_MODE; 114 + talk_ids[1] = radio_mode != RADIO_SCAN_MODE? LANG_PRESET : LANG_RADIO_SCAN_MODE; 113 115 talk_ids[2] = TALK_FINAL_ID; 114 116 talk_idarray(talk_ids, true); 115 117 return 0; 116 118 } 117 119 static int toggle_radio_mode(void) 118 120 { 119 - radio_mode = (radio_mode == RADIO_SCAN_MODE) ? 120 - RADIO_PRESET_MODE : RADIO_SCAN_MODE; 121 + int radio_mode = radio_get_mode(); 122 + radio_set_mode((radio_mode == RADIO_SCAN_MODE) ? 123 + RADIO_PRESET_MODE : RADIO_SCAN_MODE); 121 124 return 0; 122 125 } 123 126 MENUITEM_FUNCTION_DYNTEXT(radio_mode_item, 0, toggle_radio_mode,
+27 -16
apps/radio/presets.c
··· 46 46 47 47 static int curr_preset = -1; 48 48 49 - extern int curr_freq; /* from radio.c.. naughty but meh */ 50 - extern int radio_mode; 51 49 int snap_freq_to_grid(int freq); 52 50 void remember_frequency(void); 53 51 52 + #define FREQ_DISP_DIVISOR (10000) 54 53 #define MAX_PRESETS 64 55 54 static bool presets_loaded = false; 56 55 static bool presets_changed = false; 57 - static struct fmstation presets[MAX_PRESETS]; 56 + 57 + static struct fmstation 58 + { 59 + int frequency; /* In Hz */ 60 + char name[MAX_FMPRESET_LEN+1]; 61 + } presets[MAX_PRESETS]; 58 62 59 63 static char filepreset[MAX_PATH]; /* preset filename variable */ 60 64 ··· 68 72 { 69 73 return num_presets; 70 74 } 71 - const struct fmstation *radio_get_preset(int preset) 72 - { 73 - return &presets[preset]; 74 - } 75 75 76 76 bool presets_have_changed(void) 77 77 { ··· 149 149 if (num_presets < 1) 150 150 return; 151 151 152 + int curr_freq = radio_get_current_frequency(); 153 + 152 154 if (curr_preset == -1) 153 155 curr_preset = find_closest_preset(curr_freq, direction); 154 156 else ··· 156 158 157 159 /* Must stay on the current grid for the region */ 158 160 curr_freq = snap_freq_to_grid(presets[curr_preset].frequency); 159 - 161 + radio_set_current_frequency(curr_freq); 160 162 tuner_set(RADIO_FREQUENCY, curr_freq); 161 163 remember_frequency(); 162 164 } ··· 263 265 presets_changed = false; 264 266 } 265 267 268 + int radio_get_preset_freq(int preset) 269 + { 270 + if (preset < num_presets) 271 + return presets[preset].frequency; 272 + return -1; 273 + } 274 + 266 275 const char* radio_get_preset_name(int preset) 267 276 { 268 277 if (preset < num_presets) ··· 282 291 { 283 292 struct fmstation * const fms = &presets[num_presets]; 284 293 strcpy(fms->name, buf); 285 - fms->frequency = curr_freq; 294 + fms->frequency = radio_get_current_frequency(); 286 295 num_presets++; 287 296 presets_changed = true; 288 297 presets_loaded = num_presets > 0; ··· 340 349 if (!presets_changed) 341 350 { 342 351 /* The preset list will be cleared, switch to Scan Mode. */ 343 - radio_mode = RADIO_SCAN_MODE; 352 + radio_set_mode(RADIO_SCAN_MODE); 344 353 curr_preset = -1; 345 354 presets_loaded = false; 346 355 } ··· 425 434 num_presets = 0; 426 435 presets_loaded = false; 427 436 /* The preset list will be cleared switch to Scan Mode. */ 428 - radio_mode = RADIO_SCAN_MODE; 437 + radio_set_mode(RADIO_SCAN_MODE); 429 438 curr_preset = -1; 430 439 presets_changed = false; /* Don't ask to save when clearing the list. */ 431 440 ··· 459 468 struct fmstation *p = &presets[selected_item]; 460 469 if(p->name[0]) 461 470 return p->name; 462 - int freq = p->frequency / 10000; 471 + int freq = p->frequency / FREQ_DISP_DIVISOR; 463 472 int frac = freq % 100; 464 473 freq /= 100; 465 474 snprintf(buffer, buffer_len, ··· 509 518 break; 510 519 case ACTION_STD_OK: 511 520 curr_preset = gui_synclist_get_sel_pos(&lists); 512 - curr_freq = presets[curr_preset].frequency; 521 + radio_set_current_frequency(presets[curr_preset].frequency); 513 522 next_station(0); 514 523 result = 1; 515 524 break; ··· 532 541 int presets_scan(void *viewports) 533 542 { 534 543 bool do_scan = true; 544 + int curr_freq = radio_get_current_frequency(); 535 545 struct viewport *vp = (struct viewport *)viewports; 536 546 537 547 FOR_NB_SCREENS(i) ··· 556 566 if(num_presets >= MAX_PRESETS || action_userabort(TIMEOUT_NOBLOCK)) 557 567 break; 558 568 559 - freq = curr_freq / 10000; 569 + freq = curr_freq / FREQ_DISP_DIVISOR; 560 570 frac = freq % 100; 561 571 freq /= 100; 562 572 ··· 572 582 573 583 curr_freq += fmr->freq_step; 574 584 } 585 + radio_set_current_frequency(curr_freq); 575 586 576 587 if (get_radio_status() == FMRADIO_PLAYING) 577 588 tuner_set(RADIO_MUTE, 0); ··· 586 597 587 598 if(num_presets > 0) 588 599 { 589 - curr_freq = presets[0].frequency; 590 - radio_mode = RADIO_PRESET_MODE; 600 + radio_set_current_frequency(presets[0].frequency); 601 + radio_set_mode(RADIO_PRESET_MODE); 591 602 presets_loaded = true; 592 603 next_station(0); 593 604 }
+16 -6
apps/radio/radio.c
··· 123 123 124 124 #endif 125 125 126 - /* presets.c needs these so keep unstatic or redo the whole thing! */ 127 - int curr_freq; /* current frequency in Hz */ 128 - int radio_mode = RADIO_SCAN_MODE; 126 + static int curr_freq; /* current frequency in Hz */ 127 + static int radio_mode = RADIO_SCAN_MODE; 129 128 130 129 static int search_dir = 0; 131 130 static int radio_status = FMRADIO_OFF; ··· 134 133 135 134 static void radio_off(void); 136 135 137 - bool radio_scan_mode(void) 136 + enum radio_scan_mode radio_get_mode(void) 138 137 { 139 - return radio_mode == RADIO_SCAN_MODE; 138 + return radio_mode; 139 + } 140 + 141 + void radio_set_mode(enum radio_scan_mode mode) 142 + { 143 + radio_mode = mode; 140 144 } 141 145 142 146 bool radio_is_stereo(void) 143 147 { 144 148 return tuner_get(RADIO_STEREO) && !global_settings.fm_force_mono; 145 149 } 146 - int radio_current_frequency(void) 150 + 151 + int radio_get_current_frequency(void) 147 152 { 148 153 return curr_freq; 154 + } 155 + 156 + void radio_set_current_frequency(int freq) 157 + { 158 + curr_freq = freq; 149 159 } 150 160 151 161 void radio_init(void)
+9 -10
apps/radio/radio.h
··· 28 28 #include "screen_access.h" 29 29 #include "bmp.h" 30 30 31 - enum { 31 + enum radio_scan_mode { 32 32 RADIO_SCAN_MODE = 0, 33 33 RADIO_PRESET_MODE, 34 34 }; ··· 43 43 void radio_stop(void); 44 44 bool radio_hardware_present(void); 45 45 bool in_radio_screen(void); 46 + bool radio_is_stereo(void); 46 47 47 - bool radio_scan_mode(void); /* true for scan mode, false for preset mode */ 48 - bool radio_is_stereo(void); 49 - int radio_current_frequency(void); 48 + enum radio_scan_mode radio_get_mode(void); /* RADIO_SCAN_MODE, RADIO_PRESET_MODE */ 49 + void radio_set_mode(enum radio_scan_mode); 50 + 51 + int radio_get_current_frequency(void); 52 + void radio_set_current_frequency(int freq); 53 + 50 54 int radio_current_preset(void); 51 55 int radio_preset_count(void); 52 - const struct fmstation *radio_get_preset(int preset); 53 56 54 57 /* callbacks for the radio settings */ 55 58 void set_radio_region(int region); ··· 57 60 58 61 #define MAX_FMPRESET_LEN 27 59 62 60 - struct fmstation 61 - { 62 - int frequency; /* In Hz */ 63 - char name[MAX_FMPRESET_LEN+1]; 64 - }; 63 + int radio_get_preset_freq(int preset); 65 64 const char* radio_get_preset_name(int preset); 66 65 #if 0 /* disabled in draw_progressbar() */ 67 66 void presets_draw_markers(struct screen *screen, int x, int y, int w, int h);
+1 -1
apps/radio/radioart.c
··· 109 109 int free_idx = -1; 110 110 const char* preset_name; 111 111 112 - if (!buf || radio_scan_mode() || preset < 0) 112 + if (!buf || (radio_get_mode() == RADIO_SCAN_MODE) || preset < 0) 113 113 return -1; 114 114 115 115 preset_name = radio_get_preset_name(preset);