History

add orca cmd ($ glyph) and support for it on plan9 port

Sigrid Haflínudóttir committed 6 years ago

Commit a92bffa1 parent 825b4025 files · +92 −37Browse files

Unified · Split

5 files
  1. base.h +1 −0
  2. plan9.c +41 −35
  3. sim.c +28 −1
  4. tui_main.c +12 −1
  5. vmio.h +10 −0
base.h+1−0
@@ -111,6 +111,7 @@ static bool orca_is_valid_glyph(Glyph c) { · 110 unmodified lines
111 case ';':111 case ';':
112 case '=':112 case '=':
113 case '?':113 case '?':
114 case '$':
114 return true;115 return true;
115 }116 }
116 return false;117 return false;
plan9.c+41−35
@@ -185,16 +185,50 @@ orca_is_valid_glyph(Glyph c) · 184 unmodified lines
185 return false;185 return false;
186}186}
187 187
188static void
189command(char *s)
190{
191 char *a;
192 int x;
193
194 if ((a = strchr(s, ':')) != nil)
195 *a++ = 0;
196
197 if (strcmp(s, "play") == 0)
198 pause = false;
199 else if (strcmp(s, "stop") == 0)
200 pause = true;
201 else if (strcmp(s, "run") == 0)
202 forward = true;
203 else if (a != nil) {
204 x = atoi(a);
205
206 if (strcmp(s, "bpm") == 0)
207 apm = bpm = MAX(1, x);
208 else if (strcmp(s, "apm") == 0)
209 apm = MAX(1, x);
210 else if (strcmp(s, "frame") == 0)
211 tick = MAX(0, x);
212 else if (strcmp(s, "skip") == 0)
213 tick = MAX(0, tick+x);
214 else if (strcmp(s, "rewind") == 0)
215 tick = MAX(0, tick-x);
216
217 /* FIXME color, find, select, inject, write, time */
218 }
219}
220
188static void221static void
189process(Oevent_list *events)222process(Oevent_list *events)
190{223{
191 int i, off;224 int i, off;
192 Oevent *e;225 Oevent *e;
193 u8int u[4];226 u8int u[4];
227 char tmp[64];
194 228
195 for (e = events->buffer, i = 0; i < events->count; i++, e++) {229 for (e = events->buffer, i = 0; i < events->count; i++, e++) {
196 if (e->any.oevent_type == Oevent_type_midi_note) {230 if (e->any.oevent_type == Oevent_type_midi_note) {
197 Oevent_midi_note const *n = &e->midi_note;231 Oevent_midi_note *n = &e->midi_note;
198 u[0] = 1;232 u[0] = 1;
199 u[1] = 0x90 | n->channel;233 u[1] = 0x90 | n->channel;
200 u[2] = (n->octave + 1)*12 + n->note;234 u[2] = (n->octave + 1)*12 + n->note;
@@ -206,6 +240,11 @@ process(Oevent_list *events) · 5 unmodified lines
206 noteoff[off].u[2] = u[2];240 noteoff[off].u[2] = u[2];
207 noteoff[off].u[3] = 0;241 noteoff[off].u[3] = 0;
208 noteoff[off].at = tick + n->duration;242 noteoff[off].at = tick + n->duration;
243 } else if (e->any.oevent_type == Oevent_type_cmd_string) {
244 Oevent_cmd_string *c = &e->cmd_string;
245 memmove(tmp, c->chars, c->count);
246 tmp[c->count] = 0;
247 command(tmp);
209 }248 }
210 }249 }
211 250
@@ -695,39 +734,6 @@ kbdproc(void *k) · 483 unmodified lines
695 }734 }
696}735}
697 736
698static void
699command(char *s)
700{
701 char *a;
702 int x;
703
704 if ((a = strchr(s, ':')) != nil)
705 *a++ = 0;
706
707 if (strcmp(s, "play") == 0)
708 pause = false;
709 else if (strcmp(s, "stop") == 0)
710 pause = true;
711 else if (strcmp(s, "run") == 0)
712 forward = true;
713 else if (a != nil) {
714 x = atoi(a);
715
716 if (strcmp(s, "bpm") == 0)
717 apm = bpm = MAX(1, x);
718 else if (strcmp(s, "apm") == 0)
719 apm = MAX(1, x);
720 else if (strcmp(s, "frame") == 0)
721 tick = MAX(0, x);
722 else if (strcmp(s, "skip") == 0)
723 tick = MAX(0, tick+x);
724 else if (strcmp(s, "rewind") == 0)
725 tick = MAX(0, tick-x);
726
727 /* FIXME color, find, select, inject, write, time */
728 }
729}
730
731void737void
732threadmain(int argc, char **argv)738threadmain(int argc, char **argv)
733{739{
@@ -1034,7 +1040,7 @@ noredraw: · 300 unmodified lines
1034 default:1040 default:
1035 if (key.rune == Kdel || key.rune == ' ')1041 if (key.rune == Kdel || key.rune == ' ')
1036 key.rune = '.';1042 key.rune = '.';
1037 if (orca_is_valid_glyph(key.rune)) {1043 if (orca_is_valid_glyph(key.rune) || key.rune == '$') {
1038 fieldset(key.rune);1044 fieldset(key.rune);
1039 } else {1045 } else {
1040// fprint(2, "unhandled key %04x\n", key.rune);1046// fprint(2, "unhandled key %04x\n", key.rune);
sim.c+28−1
@@ -156,7 +156,8 @@ static void oper_poke_and_stun(Glyph *restrict gbuffer, Mark *restrict mbuffer, · 155 unmodified lines
156 _(':', midi) \156 _(':', midi) \
157 _(';', udp) \157 _(';', udp) \
158 _('=', osc) \158 _('=', osc) \
159 _('?', midipb)159 _('?', midipb) \
160 _('$', cmd)
160 161
161#define ALPHA_OPERATORS(_) \162#define ALPHA_OPERATORS(_) \
162 _('A', add) \163 _('A', add) \
@@ -393,6 +394,32 @@ BEGIN_OPERATOR(midipb) · 230 unmodified lines
393 oe->lsb = (U8)(index_of(lsb_g) * 127 / 35);394 oe->lsb = (U8)(index_of(lsb_g) * 127 / 35);
394END_OPERATOR395END_OPERATOR
395 396
397BEGIN_OPERATOR(cmd)
398 Usz n = width - x - 1;
399 if (n > 16)
400 n = 16;
401 Glyph const *restrict gline = gbuffer + y * width + x + 1;
402 Mark *restrict mline = mbuffer + y * width + x + 1;
403 Glyph cpy[Oevent_cmd_string_count];
404 Usz i;
405 for (i = 0; i < n; ++i) {
406 Glyph g = gline[i];
407 if (g == '.')
408 break;
409 cpy[i] = g;
410 mline[i] |= Mark_flag_lock;
411 }
412 n = i;
413 STOP_IF_NOT_BANGED;
414 Oevent_cmd_string *oe =
415 (Oevent_cmd_string *)oevent_list_alloc_item(extra_params->oevent_list);
416 oe->oevent_type = (U8)Oevent_type_cmd_string;
417 oe->count = (U8)n;
418 for (i = 0; i < n; ++i) {
419 oe->chars[i] = cpy[i];
420 }
421END_OPERATOR
422
396BEGIN_OPERATOR(add)423BEGIN_OPERATOR(add)
397 LOWERCASE_REQUIRES_BANG;424 LOWERCASE_REQUIRES_BANG;
398 PORT(0, -1, IN | PARAM);425 PORT(0, -1, IN | PARAM);
tui_main.c+12−1
@@ -86,6 +86,7 @@ static Glyph_class glyph_class_of(Glyph glyph) { · 85 unmodified lines
86 case '=':86 case '=':
87 case '%':87 case '%':
88 case '?':88 case '?':
89 case '$':
89 return Glyph_class_lowercase;90 return Glyph_class_lowercase;
90 case '*':91 case '*':
91 return Glyph_class_bang;92 return Glyph_class_bang;
@@ -650,6 +651,13 @@ staticni void draw_oevent_list(WINDOW *win, Oevent_list const *oevent_list) { · 558 unmodified lines
650 }651 }
651 break;652 break;
652 }653 }
654 case Oevent_type_cmd_string: {
655 Oevent_cmd_string const *ec = &ev->cmd_string;
656 wprintw(win, "CMD\tcount %d\t", (int)ec->count);
657 for (Usz j = 0; j < (Usz)ec->count; ++j) {
658 waddch(win, (chtype)ec->chars[j]);
659 }
660 }
653 }661 }
654 }662 }
655}663}
@@ -1161,6 +1169,9 @@ staticni void send_output_events(Oosc_dev *oosc_dev, Midi_mode *midi_mode, · 505 unmodified lines
1161 oosc_send_datagram(oosc_dev, eo->chars, eo->count);1169 oosc_send_datagram(oosc_dev, eo->chars, eo->count);
1162 break;1170 break;
1163 }1171 }
1172 case Oevent_type_cmd_string: {
1173 break;
1174 }
1164 }1175 }
1165 }1176 }
1166 1177
@@ -2273,13 +2284,13 @@ static void push_opers_guide_msg(void) { · 1106 unmodified lines
2273 {'Z', "lerp", "Transitions operand to target."},2284 {'Z', "lerp", "Transitions operand to target."},
2274 {'*', "bang", "Bangs neighboring operands."},2285 {'*', "bang", "Bangs neighboring operands."},
2275 {'#', "comment", "Halts line."},2286 {'#', "comment", "Halts line."},
2276 // {'*', "self", "Sends ORCA command."},
2277 {':', "midi", "Sends MIDI note."},2287 {':', "midi", "Sends MIDI note."},
2278 {'!', "cc", "Sends MIDI control change."},2288 {'!', "cc", "Sends MIDI control change."},
2279 {'?', "pb", "Sends MIDI pitch bend."},2289 {'?', "pb", "Sends MIDI pitch bend."},
2280 // {'%', "mono", "Sends MIDI monophonic note."},2290 // {'%', "mono", "Sends MIDI monophonic note."},
2281 {'=', "osc", "Sends OSC message."},2291 {'=', "osc", "Sends OSC message."},
2282 {';', "udp", "Sends UDP message."},2292 {';', "udp", "Sends UDP message."},
2293 //{'$', "cmd", "Sends ORCA command."},
2283 };2294 };
2284 int w_desc = 0;2295 int w_desc = 0;
2285 for (Usz i = 0; i < ORCA_ARRAY_COUNTOF(items); ++i) {2296 for (Usz i = 0; i < ORCA_ARRAY_COUNTOF(items); ++i) {
vmio.h+10−0
@@ -7,6 +7,7 @@ typedef enum { · 6 unmodified lines
7 Oevent_type_midi_pb,7 Oevent_type_midi_pb,
8 Oevent_type_osc_ints,8 Oevent_type_osc_ints,
9 Oevent_type_udp_string,9 Oevent_type_udp_string,
10 Oevent_type_cmd_string,
10} Oevent_types;11} Oevent_types;
11 12
12typedef struct {13typedef struct {
@@ -45,6 +46,14 @@ typedef struct { · 32 unmodified lines
45 char chars[Oevent_udp_string_count];46 char chars[Oevent_udp_string_count];
46} Oevent_udp_string;47} Oevent_udp_string;
47 48
49enum { Oevent_cmd_string_count = 16 };
50
51typedef struct {
52 U8 oevent_type;
53 U8 count;
54 char chars[Oevent_cmd_string_count];
55} Oevent_cmd_string;
56
48typedef union {57typedef union {
49 Oevent_any any;58 Oevent_any any;
50 Oevent_midi_note midi_note;59 Oevent_midi_note midi_note;
@@ -52,6 +61,7 @@ typedef union { · 1 unmodified line
52 Oevent_midi_pb midi_pb;61 Oevent_midi_pb midi_pb;
53 Oevent_osc_ints osc_ints;62 Oevent_osc_ints osc_ints;
54 Oevent_udp_string udp_string;63 Oevent_udp_string udp_string;
64 Oevent_cmd_string cmd_string;
55} Oevent;65} Oevent;
56 66
57typedef struct {67typedef struct {

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t