diff options
| author | erdgeist <erdgeist@bauklotz.fritz.box> | 2018-04-16 15:37:20 +0200 |
|---|---|---|
| committer | erdgeist <erdgeist@bauklotz.fritz.box> | 2018-04-16 15:37:20 +0200 |
| commit | ed5ec5c193630c230e4a4d3a1a8b0f218381511b (patch) | |
| tree | 290352200fef48338d3f126c966a4cfbce6d5f23 /engine.c | |
| parent | 8c978328b0d69216a1e60c3330c07d83c1408e12 (diff) | |
Add normalizing and pitch bending delay code
Diffstat (limited to 'engine.c')
| -rw-r--r-- | engine.c | 51 |
1 files changed, 51 insertions, 0 deletions
| @@ -8,6 +8,7 @@ | |||
| 8 | #include "midi.h" | 8 | #include "midi.h" |
| 9 | 9 | ||
| 10 | static int g_selected_string = -1; | 10 | static int g_selected_string = -1; |
| 11 | static int g_normalize_mode = 0; | ||
| 11 | 12 | ||
| 12 | #ifndef NO_DISPLAY | 13 | #ifndef NO_DISPLAY |
| 13 | #include "display.h" | 14 | #include "display.h" |
| @@ -19,6 +20,13 @@ static ConfigSelect g_selected_config; | |||
| 19 | static void highlight_line(int value, int y, int max_x, uint32_t color); | 20 | static void highlight_line(int value, int y, int max_x, uint32_t color); |
| 20 | 21 | ||
| 21 | #define scale(X) display_scale_harfe_to_screen(X) | 22 | #define scale(X) display_scale_harfe_to_screen(X) |
| 23 | static int64_t | ||
| 24 | engine_normalize(int height, int y) | ||
| 25 | { | ||
| 26 | int64_t yf = (y << 16) / height; | ||
| 27 | yf = (((yf * yf - (yf << 16)) * ((int64_t)g_normalize_factor))) + (yf << 32); | ||
| 28 | return (((int64_t)height) * yf) >> 32; | ||
| 29 | } | ||
| 22 | 30 | ||
| 23 | void | 31 | void |
| 24 | engine_redraw() | 32 | engine_redraw() |
| @@ -28,6 +36,7 @@ engine_redraw() | |||
| 28 | const int tos1 = g_midi_three_octave_split_1, tos2 = g_midi_three_octave_split_2; | 36 | const int tos1 = g_midi_three_octave_split_1, tos2 = g_midi_three_octave_split_2; |
| 29 | const int height = g_max_y - g_min_y; | 37 | const int height = g_max_y - g_min_y; |
| 30 | int i, x2, MAX_X, MAX_Y, FONT_HEIGHT; | 38 | int i, x2, MAX_X, MAX_Y, FONT_HEIGHT; |
| 39 | int t1 = 0, t2 = 0, t3 = 0; | ||
| 31 | 40 | ||
| 32 | display_redraw(); | 41 | display_redraw(); |
| 33 | display_clear(); | 42 | display_clear(); |
| @@ -47,6 +56,35 @@ engine_redraw() | |||
| 47 | display_text( " 0", 4, scale(g_min_y + (tos1 + tos2) * height / 200) + FONT_HEIGHT / 2, 0x007f7f7fff); | 56 | display_text( " 0", 4, scale(g_min_y + (tos1 + tos2) * height / 200) + FONT_HEIGHT / 2, 0x007f7f7fff); |
| 48 | display_text( b ? "-1" : "+1", 4, scale(g_min_y + (tos2 / 2 + 50 ) * height / 100) + FONT_HEIGHT / 2, 0x007f7f7fff); | 57 | display_text( b ? "-1" : "+1", 4, scale(g_min_y + (tos2 / 2 + 50 ) * height / 100) + FONT_HEIGHT / 2, 0x007f7f7fff); |
| 49 | 58 | ||
| 59 | for (int x=0; x<height; x+=20) { | ||
| 60 | int y = engine_normalize(height, x); | ||
| 61 | /* | ||
| 62 | int64_t xf = (x << 16) / 100; | ||
| 63 | int64_t yf = (((xf * xf - (xf << 16)) * ((int64_t)g_normalize_factor))) + (xf << 32); | ||
| 64 | int64_t yo = (((int64_t)height) * yf) >> 48; | ||
| 65 | |||
| 66 | double xf = ((double)x) / 100.0f; | ||
| 67 | double yf = g_normalize_factor * (xf*xf-xf) + xf; | ||
| 68 | y = ax^2 + x - ax = a * (x^2 - x) + x | ||
| 69 | int y = scale(g_min_y + (int)(((double)height) * yf)); | ||
| 70 | */ | ||
| 71 | |||
| 72 | display_line_color(0, scale(g_min_y + (y>>16)), MAX_X, scale(g_min_y + (y>>16)), 0x1f1f1f1f); | ||
| 73 | if (y >> 16 > (tos2 * height) / 100 ) | ||
| 74 | t1++; | ||
| 75 | else if (y >> 16 > (tos1 * height) / 100 ) | ||
| 76 | t2++; | ||
| 77 | else | ||
| 78 | t3++; | ||
| 79 | } | ||
| 80 | |||
| 81 | if (g_normalize_mode) { | ||
| 82 | sprintf(text, "%lf", g_normalize_factor / 65336.0f); | ||
| 83 | display_text(text, 8, MAX_Y - 32, 0xff003fff ); | ||
| 84 | sprintf(text, "%d %d %d", t1, t2, t3); | ||
| 85 | display_text(text, 8, MAX_Y - 64, 0xff003fff ); | ||
| 86 | } | ||
| 87 | |||
| 50 | display_line_color(0, scale(g_min_y), MAX_X, scale(g_min_y), 0xff00ffff); | 88 | display_line_color(0, scale(g_min_y), MAX_X, scale(g_min_y), 0xff00ffff); |
| 51 | display_line_color(0, scale(g_max_y), MAX_X, scale(g_max_y), 0xff00ffff); | 89 | display_line_color(0, scale(g_max_y), MAX_X, scale(g_max_y), 0xff00ffff); |
| 52 | #ifdef HAVE_TWO_OCTAVE_MODE | 90 | #ifdef HAVE_TWO_OCTAVE_MODE |
| @@ -146,6 +184,19 @@ engine_select_config(ConfigSelect sel) { | |||
| 146 | g_selected_config = sel; | 184 | g_selected_config = sel; |
| 147 | } | 185 | } |
| 148 | 186 | ||
| 187 | void | ||
| 188 | engine_toggle_normalize_mode() { | ||
| 189 | if (g_normalize_mode) | ||
| 190 | g_config_source = source_edit; | ||
| 191 | g_normalize_mode = 1 - g_normalize_mode; | ||
| 192 | } | ||
| 193 | |||
| 194 | void | ||
| 195 | engine_mouse_y(int y) { | ||
| 196 | if (g_normalize_mode) | ||
| 197 | g_normalize_factor = y; | ||
| 198 | } | ||
| 199 | |||
| 149 | ConfigSelect | 200 | ConfigSelect |
| 150 | engine_change_selected(int off) | 201 | engine_change_selected(int off) |
| 151 | { | 202 | { |
