Unified · Split
| @@ -8,6 +8,8 @@ · 7 unmodified lines | |||
| 8 | #include <keyboard.h> | 8 | #include <keyboard.h> |
| 9 | #include <thread.h> | 9 | #include <thread.h> |
| 10 | 10 | ||
| 11 | typedef struct Key Key; | ||
| 12 | |||
| 11 | #define MIN(x,y) ((x)<(y)?(x):(y)) | 13 | #define MIN(x,y) ((x)<(y)?(x):(y)) |
| 12 | #define MAX(x,y) ((x)>(y)?(x):(y)) | 14 | #define MAX(x,y) ((x)>(y)?(x):(y)) |
| 13 | 15 | ||
| @@ -33,6 +35,12 @@ enum { · 19 unmodified lines | |||
| 33 | Mselect, | 35 | Mselect, |
| 34 | Nummodes, | 36 | Nummodes, |
| 35 | 37 | ||
| 38 | Menu3load = 0, | ||
| 39 | Menu3save, | ||
| 40 | Menu3dotstyle, | ||
| 41 | Menu3rulerstyle, | ||
| 42 | Nummenu3, | ||
| 43 | |||
| 36 | Dback = 0, | 44 | Dback = 0, |
| 37 | Dfhigh, | 45 | Dfhigh, |
| 38 | Dfmed, | 46 | Dfmed, |
| @@ -45,18 +53,35 @@ enum { · 6 unmodified lines | |||
| 45 | Numcolors, | 53 | Numcolors, |
| 46 | }; | 54 | }; |
| 47 | 55 | ||
| 48 | typedef struct Key Key; | ||
| 49 | |||
| 50 | static struct { | ||
| 51 | u8int u[4]; | ||
| 52 | Usz at; | ||
| 53 | }noteoff[16*128]; /* 16 channels, 128 notes each */ | ||
| 54 | |||
| 55 | struct Key { | 56 | struct Key { |
| 56 | int down; | 57 | int down; |
| 57 | Rune rune; | 58 | Rune rune; |
| 58 | }; | 59 | }; |
| 59 | 60 | ||
| 61 | static Rune *linebuf; | ||
| 62 | static Usz tick; | ||
| 63 | static int gridw = 8, gridh = 8; | ||
| 64 | static int rulerstyle = Sfancy, dotstyle = Sfancy; | ||
| 65 | static int bpm = 120, pause; | ||
| 66 | static int curx, cury; | ||
| 67 | static int selw = 1, selh = 1; | ||
| 68 | static int charw, charh; | ||
| 69 | static Field field; | ||
| 70 | static Mbuf_reusable mbuf; | ||
| 71 | static Oevent_list events; | ||
| 72 | static char filename[256]; | ||
| 73 | static Channel *cchan; | ||
| 74 | static Field copyfield; | ||
| 75 | static int altdown; | ||
| 76 | static int mode = Minsert; | ||
| 77 | static long framedev; /* frame deviation >= 1µs */ | ||
| 78 | |||
| 79 | static char *style[Numstyles] = { | ||
| 80 | [Sfancy] = "fancy", | ||
| 81 | [Splain] = "plain", | ||
| 82 | [Snone] = "none", | ||
| 83 | }; | ||
| 84 | |||
| 60 | static Rune dot[Numstyles] = { | 85 | static Rune dot[Numstyles] = { |
| 61 | [Sfancy] = L'·', | 86 | [Sfancy] = L'·', |
| 62 | [Splain] = '.', | 87 | [Splain] = '.', |
| @@ -81,23 +106,10 @@ static Rune ruler[Numstyles][9] = { · 18 unmodified lines | |||
| 81 | }, | 106 | }, |
| 82 | }; | 107 | }; |
| 83 | 108 | ||
| 84 | static Rune *linebuf; | 109 | static struct { |
| 85 | static Usz tick; | 110 | u8int u[4]; |
| 86 | static int gridw = 8, gridh = 8; | 111 | Usz at; |
| 87 | static int rulerstyle = Sfancy, dotstyle = Sfancy; | 112 | }noteoff[16*128]; /* 16 channels, 128 notes each */ |
| 88 | static int bpm = 120, pause; | ||
| 89 | static int curx, cury; | ||
| 90 | static int selw = 1, selh = 1; | ||
| 91 | static int charw, charh; | ||
| 92 | static Field field; | ||
| 93 | static Mbuf_reusable mbuf; | ||
| 94 | static Oevent_list events; | ||
| 95 | static char filename[256]; | ||
| 96 | static Channel *cchan; | ||
| 97 | static Field copyfield; | ||
| 98 | static int altdown; | ||
| 99 | static int mode = Minsert; | ||
| 100 | static long framedev; /* frame deviation >= 1µs */ | ||
| 101 | 113 | ||
| 102 | static u32int theme[Numcolors] = { | 114 | static u32int theme[Numcolors] = { |
| 103 | [Dback] = 0x000000ff, | 115 | [Dback] = 0x000000ff, |
| @@ -120,10 +132,9 @@ static char *modes[Nummodes] = { · 16 unmodified lines | |||
| 120 | [Mselect] = "select", | 132 | [Mselect] = "select", |
| 121 | }; | 133 | }; |
| 122 | 134 | ||
| 123 | static char *menu3i[] = { | 135 | static char *menu3i[Nummenu3+1] = { |
| 124 | "load", | 136 | [Menu3load] = "load", |
| 125 | "save", | 137 | [Menu3save] = "save", |
| 126 | nil, | ||
| 127 | }; | 138 | }; |
| 128 | 139 | ||
| 129 | static Menu menu3 = { | 140 | static Menu menu3 = { |
| @@ -309,9 +320,9 @@ redraw(void) · 179 unmodified lines | |||
| 309 | if (c == '.') { | 320 | if (c == '.') { |
| 310 | c = dot[dotstyle]; | 321 | c = dot[dotstyle]; |
| 311 | if ((x % gridw) == 0 && (y % gridh) == 0) { | 322 | if ((x % gridw) == 0 && (y % gridh) == 0) { |
| 312 | rx = x == 0 ? 0 : (x == field.width-1 ? 2 : 1); | 323 | rx = !!x + (x + 1) / field.width; |
| 313 | ry = y == 0 ? 0 : (y == field.height-1 ? 2 : 1); | 324 | ry = !!y + (y + 1) / field.height; |
| 314 | c = ruler[dotstyle][ry*3+rx]; | 325 | c = ruler[rulerstyle][ry*3+rx]; |
| 315 | } | 326 | } |
| 316 | } | 327 | } |
| 317 | linebuf[x] = c; | 328 | linebuf[x] = c; |
| @@ -680,18 +691,25 @@ threadmain(int argc, char **argv) · 362 unmodified lines | |||
| 680 | case 2: | 691 | case 2: |
| 681 | break; | 692 | break; |
| 682 | case 4: | 693 | case 4: |
| 694 | menu3i[Menu3dotstyle] = tmp; | ||
| 695 | menu3i[Menu3rulerstyle] = 1 + menu3i[Menu3dotstyle] + sprintf(tmp, "%s dots", style[(dotstyle+1) % Numstyles]); | ||
| 696 | sprintf(menu3i[Menu3rulerstyle], "%s rulers", style[(rulerstyle+1) % Numstyles]); | ||
| 683 | n = menuhit(3, mctl, &menu3, nil); | 697 | n = menuhit(3, mctl, &menu3, nil); |
| 684 | if (n == 0 || n == 1) { | 698 | if (n == Menu3load || n == Menu3save) { |
| 685 | strncpy(tmp, filename, sizeof(tmp)); | 699 | strncpy(tmp, filename, sizeof(tmp)); |
| 686 | if (enter("file path:", tmp, sizeof(tmp), mctl, &kctl, nil) > 0) { | 700 | if (enter("file path:", tmp, sizeof(tmp), mctl, &kctl, nil) > 0) { |
| 687 | if (n == 0 && fieldload(tmp) == 0) { | 701 | if (n == Menu3load && fieldload(tmp) == 0) { |
| 688 | w = field.width; | 702 | w = field.width; |
| 689 | h = field.height; | 703 | h = field.height; |
| 690 | strncpy(filename, tmp, sizeof(filename)); | 704 | strncpy(filename, tmp, sizeof(filename)); |
| 691 | } else if (n == 1 && fieldsave(tmp) == 0) { | 705 | } else if (n == Menu3save && fieldsave(tmp) == 0) { |
| 692 | strncpy(filename, tmp, sizeof(filename)); | 706 | strncpy(filename, tmp, sizeof(filename)); |
| 693 | } | 707 | } |
| 694 | } | 708 | } |
| 709 | } else if (n == Menu3dotstyle) { | ||
| 710 | dotstyle = ++dotstyle % Numstyles; | ||
| 711 | } else if (n == Menu3rulerstyle) { | ||
| 712 | rulerstyle = ++rulerstyle % Numstyles; | ||
| 695 | } | 713 | } |
| 696 | break; | 714 | break; |
| 697 | } | 715 | } |