summaryrefslogtreecommitdiff
path: root/apps/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins')
-rw-r--r--apps/plugins/pitch_detector.c48
1 files changed, 44 insertions, 4 deletions
diff --git a/apps/plugins/pitch_detector.c b/apps/plugins/pitch_detector.c
index 0fdbc25a27..fe31b3c768 100644
--- a/apps/plugins/pitch_detector.c
+++ b/apps/plugins/pitch_detector.c
@@ -294,8 +294,19 @@ static struct tuner_settings
294 int freq_A; /* Index of the frequency of A */ 294 int freq_A; /* Index of the frequency of A */
295 bool use_sharps; 295 bool use_sharps;
296 bool display_hz; 296 bool display_hz;
297 int key_transposition; /* Which note to display as 'C'. */
298 /* 0=C, 1=D-flat, 2=D, ..., 11=B. This is useful if you */
299 /* use a transposing instrument. In that case, this */
300 /* setting tells which 'real' note is played by the */
301 /* instrument if you play a written 'C'. Thus, this */
302 /* setting is the number of semitones from the real 'C' */
303 /* up to the 'instrument key'. */
297} settings; 304} settings;
298 305
306/* By default, the real 'C' is displayed as 'C' */
307#define DEFAULT_KEY_TRANSPOSITION 0
308
309
299/*=================================================================*/ 310/*=================================================================*/
300/* Settings loading and saving(adapted from the clock plugin) */ 311/* Settings loading and saving(adapted from the clock plugin) */
301/*=================================================================*/ 312/*=================================================================*/
@@ -326,6 +337,7 @@ static void tuner_settings_reset(void)
326 .freq_A = DEFAULT_FREQ_A, 337 .freq_A = DEFAULT_FREQ_A,
327 .use_sharps = true, 338 .use_sharps = true,
328 .display_hz = false, 339 .display_hz = false,
340 .key_transposition = DEFAULT_KEY_TRANSPOSITION,
329 }; 341 };
330} 342}
331 343
@@ -406,6 +418,22 @@ static const struct opt_items accidental_text[] =
406 { "Sharp", -1 }, 418 { "Sharp", -1 },
407}; 419};
408 420
421static const struct opt_items transpose_text[] =
422{
423 { "C (Concert Pitch)", -1 },
424 { "D-flat", -1 },
425 { "D", -1 },
426 { "E-flat", -1 },
427 { "E", -1 },
428 { "F", -1 },
429 { "G-flat", -1 },
430 { "G", -1 },
431 { "A-flat", -1 },
432 { "A", -1 },
433 { "B-flat", -1 },
434 { "B", -1 },
435};
436
409static void set_min_freq(int new_freq) 437static void set_min_freq(int new_freq)
410{ 438{
411 settings.sample_size = freq2period(new_freq) * 4; 439 settings.sample_size = freq2period(new_freq) * 4;
@@ -442,6 +470,7 @@ static bool main_menu(void)
442 "Lowest Frequency", 470 "Lowest Frequency",
443 "Algorithm Pickiness", 471 "Algorithm Pickiness",
444 "Accidentals", 472 "Accidentals",
473 "Key Transposition",
445 "Display Frequency (Hz)", 474 "Display Frequency (Hz)",
446 "Frequency of A (Hz)", 475 "Frequency of A (Hz)",
447 "Reset Settings", 476 "Reset Settings",
@@ -484,10 +513,15 @@ static bool main_menu(void)
484 BOOL, accidental_text, 2, NULL); 513 BOOL, accidental_text, 2, NULL);
485 break; 514 break;
486 case 6: 515 case 6:
516 rb->set_option("Key Transposition",
517 &settings.key_transposition,
518 INT, transpose_text, 12, NULL);
519 break;
520 case 7:
487 rb->set_bool("Display Frequency (Hz)", 521 rb->set_bool("Display Frequency (Hz)",
488 &settings.display_hz); 522 &settings.display_hz);
489 break; 523 break;
490 case 7: 524 case 8:
491 freq_val = freq_A[settings.freq_A].frequency; 525 freq_val = freq_A[settings.freq_A].frequency;
492 rb->set_int("Frequency of A (Hz)", 526 rb->set_int("Frequency of A (Hz)",
493 "Hz", UNIT_INT, &freq_val, NULL, 527 "Hz", UNIT_INT, &freq_val, NULL,
@@ -495,13 +529,13 @@ static bool main_menu(void)
495 NULL); 529 NULL);
496 settings.freq_A = freq_val - freq_A[0].frequency; 530 settings.freq_A = freq_val - freq_A[0].frequency;
497 break; 531 break;
498 case 8: 532 case 9:
499 reset = false; 533 reset = false;
500 rb->set_bool("Reset Tuner Settings?", &reset); 534 rb->set_bool("Reset Tuner Settings?", &reset);
501 if (reset) 535 if (reset)
502 tuner_settings_reset(); 536 tuner_settings_reset();
503 break; 537 break;
504 case 9: 538 case 10:
505 exit_tuner = true; 539 exit_tuner = true;
506 done = true; 540 done = true;
507 break; 541 break;
@@ -703,7 +737,13 @@ static void display_frequency (fixed freq)
703 draw_bar(ldf); /* The red bar */ 737 draw_bar(ldf); /* The red bar */
704 if(fp_round(freq) != 0) 738 if(fp_round(freq) != 0)
705 { 739 {
706 draw_note(notes[note].name); 740 /* Raise the displayed pitch an octave minus key_transposition */
741 /* semitones, effectively lowering it. Note that the pitch */
742 /* displayed alongside the frequency is unaffected. */
743 int transposition = 12 - settings.key_transposition;
744
745 draw_note(notes[(note + transposition) % 12].name);
746
707 if(settings.display_hz) 747 if(settings.display_hz)
708 { 748 {
709#if LCD_DEPTH > 1 749#if LCD_DEPTH > 1