aboutsummaryrefslogtreecommitdiff
path: root/interface.c
diff options
context:
space:
mode:
Diffstat (limited to 'interface.c')
-rw-r--r--interface.c100
1 files changed, 96 insertions, 4 deletions
diff --git a/interface.c b/interface.c
index 26aca55..1347ce2 100644
--- a/interface.c
+++ b/interface.c
@@ -1,16 +1,108 @@
1#include <stdlib.h>
1#include <stdio.h> 2#include <stdio.h>
3#include <locale.h>
2#include <unistd.h> 4#include <unistd.h>
3 5
4#include "interface.h" 6#include "interface.h"
5#include "mutex.h" 7#include "mutex.h"
6 8
9#define TB_IMPL
10#include "termbox2.h"
11
12static int block_width = 14;
13static int block_height = 4;
14
15void draw_block(int x, int y, const char *label, int empty) {
16
17 tb_set_cell(x, y, 0x250C, TB_WHITE, TB_DEFAULT);
18 tb_set_cell(x+block_width-1, y, 0x2510, TB_WHITE, TB_DEFAULT);
19 tb_set_cell(x, y+block_height-1, 0x2514, TB_WHITE, TB_DEFAULT);
20 tb_set_cell(x+block_width-1, y+block_height-1, 0x2518, TB_WHITE, TB_DEFAULT);
21
22 tb_printf(x+(block_width/2) - (strlen(label)/2), y+(block_height/2)-1 ,TB_YELLOW, 0, label);
23 tb_printf(x+(block_width/2) - (strlen("empty")/2), y+(block_height/2) ,TB_DIM, 0, "empty");
24
25 tb_present();
26}
27
28void draw_blocks() {
29 int offset_x = 0;
30 int offset_y = 6;
31 char col_names[6] = {'A', 'B', 'C', 'D', 'E', 'F'};
32
33 for (int r = 0; r < 4; r++) {
34 for (int c = 0; c < 6; c++) {
35 char label[3];
36 label[0] = col_names[c];
37 label[1] = '1' + r;
38 label[2] = '\0';
39 draw_block(offset_x+(block_width*c), offset_y+(block_height*r), label, 0);
40 }
41 }
42}
43
44void draw_help_tooltip(const char* tooltip_text) {
45 tb_printf(tb_width() - strlen(tooltip_text) - 1, tb_height()-1, TB_DIM, 0, tooltip_text);
46 tb_present();
47}
48
7void *interface(void *arg) { 49void *interface(void *arg) {
8 InterfaceArgs* args = (InterfaceArgs*)arg; 50 InterfaceArgs* args = (InterfaceArgs*)arg;
9 (void)args; 51
52 int ret;
53 setlocale(LC_ALL, "");
54
55 ret = tb_init();
56 if (ret) {
57 fprintf(stderr, "tb_init() failed with error code %d\n", ret);
58 exit(1);
59 }
60
61 tb_set_input_mode(TB_INPUT_ESC | TB_INPUT_MOUSE);
62 struct tb_event ev;
63
64 tb_clear();
65 tb_present();
66
67 // Show currently selected soundfont.
68 tb_printf(0, 0, TB_GREEN, 0, "Soundfont: %s", args->soundfont_file);
69 tb_printf(0, 1, TB_GREEN, 0, "Preset: %s", args->soundfont_preset);
70 tb_present();
71
72 // Draw interface.
73 draw_help_tooltip("Ctrl+q - Quit");
74 draw_blocks();
75 /* draw_block(10, 10, "A1"); */
10 76
11 while(1) { 77 while(1) {
12 // Do the thread stuff here. 78 ret = tb_poll_event(&ev);
13 sleep(1); 79
14 fprintf(stdout, "hi from interface thread\n"); 80 if (ret != TB_OK) {
81 if (ret == TB_ERR_POLL && tb_last_errno() == EINTR) {
82 /* Poll was interrupted, maybe by a SIGWINCH; try again */
83 continue;
84 }
85 /* Some other error occurred; bail */
86 break;
87 }
88
89 switch (ev.type) {
90 case TB_EVENT_KEY:
91 if (ev.key == TB_KEY_CTRL_Q) {
92 tb_shutdown();
93 exit(0);
94 }
95
96 if (ev.key == TB_KEY_ARROW_UP) {
97
98 }
99
100 if (ev.key == TB_KEY_ARROW_DOWN) {
101
102 }
103
104 break;
105 }
15 } 106 }
16} 107}
108