summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--config.c18
-rw-r--r--config.h9
-rw-r--r--engine.c51
-rw-r--r--engine.h2
-rw-r--r--main-sdl.c17
5 files changed, 93 insertions, 4 deletions
diff --git a/config.c b/config.c
index 7467e8e..9e47044 100644
--- a/config.c
+++ b/config.c
@@ -14,8 +14,10 @@ int g_midi_three_octave_split_2 = 66;
14int g_midi_three_octave_split_inverse = 0; 14int g_midi_three_octave_split_inverse = 0;
15int g_settled_dist = 5; 15int g_settled_dist = 5;
16int g_timetosilence = 30; 16int g_timetosilence = 30;
17int g_pitchbend_delay = 500;
17 18
18int g_min_y = 0, g_max_y; 19int g_min_y = 0, g_max_y;
20int g_normalize_factor = 0;
19 21
20static int g_current_string; 22static int g_current_string;
21StringConfig 23StringConfig
@@ -43,6 +45,7 @@ config_reset()
43 g_midi_three_octave_split_inverse = 0; 45 g_midi_three_octave_split_inverse = 0;
44 g_settled_dist = 5; 46 g_settled_dist = 5;
45 g_timetosilence = 30; 47 g_timetosilence = 30;
48 g_pitchbend_delay = 500;
46 49
47 g_config_source = source_none; 50 g_config_source = source_none;
48} 51}
@@ -74,6 +77,8 @@ enum {
74 KEYWORD_STRINGS, 77 KEYWORD_STRINGS,
75 KEYWORD_STRING, 78 KEYWORD_STRING,
76 KEYWORD_LINE, 79 KEYWORD_LINE,
80 KEYWORD_LINEARIZE,
81 KEYWORD_PITCHBEND_DELAY,
77 KEYWORD_MODE, 82 KEYWORD_MODE,
78 KEYWORD_MODE_ONE_OCTAVE, 83 KEYWORD_MODE_ONE_OCTAVE,
79 KEYWORD_MODE_TWO_OCTAVES, 84 KEYWORD_MODE_TWO_OCTAVES,
@@ -108,6 +113,8 @@ static keyword keywords[] = {
108 {KEYWORD_STRINGS, "Strings"}, 113 {KEYWORD_STRINGS, "Strings"},
109 {KEYWORD_STRING, "String"}, 114 {KEYWORD_STRING, "String"},
110 {KEYWORD_LINE, "Line"}, 115 {KEYWORD_LINE, "Line"},
116 {KEYWORD_LINEARIZE, "LineSquareFactor"},
117 {KEYWORD_PITCHBEND_DELAY, "PitchBendDelay"},
111 {KEYWORD_MODE, "Mode"}, 118 {KEYWORD_MODE, "Mode"},
112 {KEYWORD_MODE_ONE_OCTAVE, "midi_one_octave"}, 119 {KEYWORD_MODE_ONE_OCTAVE, "midi_one_octave"},
113 {KEYWORD_MODE_TWO_OCTAVES, "midi_two_octaves"}, 120 {KEYWORD_MODE_TWO_OCTAVES, "midi_two_octaves"},
@@ -208,6 +215,12 @@ config_handle_line(char *line)
208 return -1; 215 return -1;
209 } 216 }
210 break; 217 break;
218 case KEYWORD_LINEARIZE:
219 g_normalize_factor = atol(line);
220 break;
221 case KEYWORD_PITCHBEND_DELAY:
222 g_pitchbend_delay = atol(line);
223 break;
211 case KEYWORD_LINE: 224 case KEYWORD_LINE:
212 { 225 {
213 LLine *l = &sc->line; 226 LLine *l = &sc->line;
@@ -394,6 +407,11 @@ config_dumpglobals(char *out, size_t outsize)
394 off += snprintf(out + off, outsize - off, 407 off += snprintf(out + off, outsize - off,
395 "midi_main_channel %d\n\n", g_midi_main_channel); 408 "midi_main_channel %d\n\n", g_midi_main_channel);
396 409
410 off += snprintf(out + off, outsize - off,
411 "LineSquareFactor %d\n\n", g_normalize_factor);
412 off += snprintf(out + off, outsize - off,
413 "PitchBendDelay %d\n\n", g_pitchbend_delay);
414
397 if (g_settled_dist != 5) 415 if (g_settled_dist != 5)
398 off += snprintf(out + off, outsize - off, 416 off += snprintf(out + off, outsize - off,
399 "SettledDist %d\n\n", g_settled_dist); 417 "SettledDist %d\n\n", g_settled_dist);
diff --git a/config.h b/config.h
index ed3f56c..25b9e0d 100644
--- a/config.h
+++ b/config.h
@@ -17,6 +17,8 @@ extern int g_midi_main_control;
17extern int g_midi_main_channel; 17extern int g_midi_main_channel;
18extern int g_settled_dist; 18extern int g_settled_dist;
19extern int g_timetosilence; 19extern int g_timetosilence;
20extern int g_pitchbend_delay;
21extern int g_normalize_factor;
20 22
21typedef enum { 23typedef enum {
22 midi_one_octave = 0, 24 midi_one_octave = 0,
@@ -35,9 +37,10 @@ typedef enum {
35} StringModifier; 37} StringModifier;
36 38
37typedef enum { 39typedef enum {
38 silent = 0, 40 string_is_silent = 0,
39 in_attack = 1, 41 string_is_in_attack = 1,
40 playing = 2 42 string_is_playing = 2,
43 string_is_bending = 3
41} StringPlaying; 44} StringPlaying;
42 45
43typedef enum { 46typedef enum {
diff --git a/engine.c b/engine.c
index d9b35f7..82f1355 100644
--- a/engine.c
+++ b/engine.c
@@ -8,6 +8,7 @@
8#include "midi.h" 8#include "midi.h"
9 9
10static int g_selected_string = -1; 10static int g_selected_string = -1;
11static 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;
19static void highlight_line(int value, int y, int max_x, uint32_t color); 20static 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)
23static int64_t
24engine_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
23void 31void
24engine_redraw() 32engine_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
187void
188engine_toggle_normalize_mode() {
189 if (g_normalize_mode)
190 g_config_source = source_edit;
191 g_normalize_mode = 1 - g_normalize_mode;
192}
193
194void
195engine_mouse_y(int y) {
196 if (g_normalize_mode)
197 g_normalize_factor = y;
198}
199
149ConfigSelect 200ConfigSelect
150engine_change_selected(int off) 201engine_change_selected(int off)
151{ 202{
diff --git a/engine.h b/engine.h
index 2d47dc7..6974d51 100644
--- a/engine.h
+++ b/engine.h
@@ -7,6 +7,8 @@ void engine_redraw();
7void engine_handle_point(LPoint * p, uint32_t monotime); 7void engine_handle_point(LPoint * p, uint32_t monotime);
8void engine_checksilence(uint32_t monotime); 8void engine_checksilence(uint32_t monotime);
9void engine_select_config(ConfigSelect sel); 9void engine_select_config(ConfigSelect sel);
10void engine_toggle_normalize_mode();
11void engine_mouse_y(int y);
10ConfigSelect engine_change_selected(int off); 12ConfigSelect engine_change_selected(int off);
11 13
12extern int g_harfe_width, g_harfe_height; 14extern int g_harfe_width, g_harfe_height;
diff --git a/main-sdl.c b/main-sdl.c
index b61806b..2ac648c 100644
--- a/main-sdl.c
+++ b/main-sdl.c
@@ -34,7 +34,8 @@ enum {
34int g_harfe_connected = 0; 34int g_harfe_connected = 0;
35int g_harfe_fd = -1; 35int g_harfe_fd = -1;
36 36
37static int g_up_pressed = 0, g_down_pressed = 0; 37static int g_up_pressed, g_down_pressed, g_mouse_down;
38static LPoint g_last_mouse;
38 39
39static char * 40static char *
40find_harfe() 41find_harfe()
@@ -387,6 +388,12 @@ handle_keydown(SDL_Event *ev) {
387 write(g_harfe_fd, "ME20020\nM824C00\n", 16); 388 write(g_harfe_fd, "ME20020\nM824C00\n", 16);
388 } 389 }
389 break; 390 break;
391 case SDL_SCANCODE_N:
392 engine_toggle_normalize_mode();
393 break;
394 case SDL_SCANCODE_P:
395 config_flip_pitch();
396 break;
390 case SDL_SCANCODE_Q: 397 case SDL_SCANCODE_Q:
391 config_reset(); 398 config_reset();
392 break; 399 break;
@@ -472,6 +479,8 @@ main(int argc, char **argv)
472 if (ev.motion.state & SDL_BUTTON_LMASK) { 479 if (ev.motion.state & SDL_BUTTON_LMASK) {
473 LPoint p = { display_scale_screen_to_harfe(ev.motion.x), 768 - display_scale_screen_to_harfe(ev.motion.y) }; 480 LPoint p = { display_scale_screen_to_harfe(ev.motion.x), 768 - display_scale_screen_to_harfe(ev.motion.y) };
474 engine_handle_point(&p, now()); 481 engine_handle_point(&p, now());
482 g_last_mouse = p;
483 engine_mouse_y((65336 * (SCREEN_HEIGHT-ev.motion.y))/ SCREEN_HEIGHT);
475 } 484 }
476 break; 485 break;
477 case SDL_MOUSEBUTTONDOWN: 486 case SDL_MOUSEBUTTONDOWN:
@@ -479,12 +488,15 @@ main(int argc, char **argv)
479 LPoint p = { display_scale_screen_to_harfe(ev.button.x), 768 - display_scale_screen_to_harfe(ev.button.y) }; 488 LPoint p = { display_scale_screen_to_harfe(ev.button.x), 768 - display_scale_screen_to_harfe(ev.button.y) };
480 if (menu_test_mouse_down(ev.button.x, ev.button.y)) 489 if (menu_test_mouse_down(ev.button.x, ev.button.y))
481 engine_handle_point(&p, now()); 490 engine_handle_point(&p, now());
491 g_last_mouse = p;
492 g_mouse_down = 1;
482 } 493 }
483 break; 494 break;
484 case SDL_MOUSEBUTTONUP: 495 case SDL_MOUSEBUTTONUP:
485 { 496 {
486 LPoint p = { display_scale_screen_to_harfe(ev.button.x), 768 - display_scale_screen_to_harfe(ev.button.y) }; 497 LPoint p = { display_scale_screen_to_harfe(ev.button.x), 768 - display_scale_screen_to_harfe(ev.button.y) };
487 menu_handle_button_up(ev.button.x, ev.button.y); 498 menu_handle_button_up(ev.button.x, ev.button.y);
499 g_mouse_down = 0;
488 } 500 }
489 501
490 break; 502 break;
@@ -502,6 +514,9 @@ main(int argc, char **argv)
502 break; 514 break;
503 } 515 }
504 516
517 if (g_mouse_down)
518 engine_handle_point(&g_last_mouse, now());
519
505 if (!g_calibration_running || !g_importing_config) 520 if (!g_calibration_running || !g_importing_config)
506 engine_checksilence(now()); 521 engine_checksilence(now());
507 522