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
111111 case ';':
112112 case '=':
113113 case '?':
114+ case '$':
114115 return true;
115116 }
116117 return false;
plan9.c+41−35
@@ -185,16 +185,50 @@ orca_is_valid_glyph(Glyph c) · 184 unmodified lines
185185 return false;
186186 }
187187
188+static void
189+command(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+
188221 static void
189222 process(Oevent_list *events)
190223 {
191224 int i, off;
192225 Oevent *e;
193226 u8int u[4];
227+ char tmp[64];
194228
195229 for (e = events->buffer, i = 0; i < events->count; i++, e++) {
196230 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;
198232 u[0] = 1;
199233 u[1] = 0x90 | n->channel;
200234 u[2] = (n->octave + 1)*12 + n->note;
@@ -206,6 +240,11 @@ process(Oevent_list *events) · 5 unmodified lines
206240 noteoff[off].u[2] = u[2];
207241 noteoff[off].u[3] = 0;
208242 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);
209248 }
210249 }
211250
@@ -695,39 +734,6 @@ kbdproc(void *k) · 483 unmodified lines
695734 }
696735 }
697736
698−static void
699−command(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−
731737 void
732738 threadmain(int argc, char **argv)
733739 {
@@ -1034,7 +1040,7 @@ noredraw: · 300 unmodified lines
10341040 default:
10351041 if (key.rune == Kdel || key.rune == ' ')
10361042 key.rune = '.';
1037− if (orca_is_valid_glyph(key.rune)) {
1043+ if (orca_is_valid_glyph(key.rune) || key.rune == '$') {
10381044 fieldset(key.rune);
10391045 } else {
10401046 // 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
156156 _(':', midi) \
157157 _(';', udp) \
158158 _('=', osc) \
159− _('?', midipb)
159+ _('?', midipb) \
160+ _('$', cmd)
160161
161162 #define ALPHA_OPERATORS(_) \
162163 _('A', add) \
@@ -393,6 +394,32 @@ BEGIN_OPERATOR(midipb) · 230 unmodified lines
393394 oe->lsb = (U8)(index_of(lsb_g) * 127 / 35);
394395 END_OPERATOR
395396
397+BEGIN_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+ }
421+END_OPERATOR
422+
396423 BEGIN_OPERATOR(add)
397424 LOWERCASE_REQUIRES_BANG;
398425 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
8686 case '=':
8787 case '%':
8888 case '?':
89+ case '$':
8990 return Glyph_class_lowercase;
9091 case '*':
9192 return Glyph_class_bang;
@@ -650,6 +651,13 @@ staticni void draw_oevent_list(WINDOW *win, Oevent_list const *oevent_list) { · 558 unmodified lines
650651 }
651652 break;
652653 }
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+ }
653661 }
654662 }
655663 }
@@ -1161,6 +1169,9 @@ staticni void send_output_events(Oosc_dev *oosc_dev, Midi_mode *midi_mode, · 505 unmodified lines
11611169 oosc_send_datagram(oosc_dev, eo->chars, eo->count);
11621170 break;
11631171 }
1172+ case Oevent_type_cmd_string: {
1173+ break;
1174+ }
11641175 }
11651176 }
11661177
@@ -2273,13 +2284,13 @@ static void push_opers_guide_msg(void) { · 1106 unmodified lines
22732284 {'Z', "lerp", "Transitions operand to target."},
22742285 {'*', "bang", "Bangs neighboring operands."},
22752286 {'#', "comment", "Halts line."},
2276− // {'*', "self", "Sends ORCA command."},
22772287 {':', "midi", "Sends MIDI note."},
22782288 {'!', "cc", "Sends MIDI control change."},
22792289 {'?', "pb", "Sends MIDI pitch bend."},
22802290 // {'%', "mono", "Sends MIDI monophonic note."},
22812291 {'=', "osc", "Sends OSC message."},
22822292 {';', "udp", "Sends UDP message."},
2293+ //{'$', "cmd", "Sends ORCA command."},
22832294 };
22842295 int w_desc = 0;
22852296 for (Usz i = 0; i < ORCA_ARRAY_COUNTOF(items); ++i) {
vmio.h+10−0
@@ -7,6 +7,7 @@ typedef enum { · 6 unmodified lines
77 Oevent_type_midi_pb,
88 Oevent_type_osc_ints,
99 Oevent_type_udp_string,
10+ Oevent_type_cmd_string,
1011 } Oevent_types;
1112
1213 typedef struct {
@@ -45,6 +46,14 @@ typedef struct { · 32 unmodified lines
4546 char chars[Oevent_udp_string_count];
4647 } Oevent_udp_string;
4748
49+enum { Oevent_cmd_string_count = 16 };
50+
51+typedef struct {
52+ U8 oevent_type;
53+ U8 count;
54+ char chars[Oevent_cmd_string_count];
55+} Oevent_cmd_string;
56+
4857 typedef union {
4958 Oevent_any any;
5059 Oevent_midi_note midi_note;
@@ -52,6 +61,7 @@ typedef union { · 1 unmodified line
5261 Oevent_midi_pb midi_pb;
5362 Oevent_osc_ints osc_ints;
5463 Oevent_udp_string udp_string;
64+ Oevent_cmd_string cmd_string;
5565 } Oevent;
5666
5767 typedef 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