shithub: orca

Download patch

ref: a92bffafd4ec2f8a22590249846ea376ea3e1011
parent: 825b4024ea54d406c397d5e22e9627b615b7a772
author: Sigrid Haflínudóttir <ftrvxmtrx@gmail.com>
date: Sun Feb 16 13:57:38 EST 2020

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

--- a/base.h
+++ b/base.h
@@ -111,6 +111,7 @@
   case ';':
   case '=':
   case '?':
+  case '$':
     return true;
   }
   return false;
--- a/plan9.c
+++ b/plan9.c
@@ -186,15 +186,49 @@
 }
 
 static void
+command(char *s)
+{
+	char *a;
+	int x;
+
+	if ((a = strchr(s, ':')) != nil)
+		*a++ = 0;
+
+	if (strcmp(s, "play") == 0)
+		pause = false;
+	else if (strcmp(s, "stop") == 0)
+		pause = true;
+	else if (strcmp(s, "run") == 0)
+		forward = true;
+	else if (a != nil) {
+		x = atoi(a);
+
+		if (strcmp(s, "bpm") == 0)
+			apm = bpm = MAX(1, x);
+		else if (strcmp(s, "apm") == 0)
+			apm = MAX(1, x);
+		else if (strcmp(s, "frame") == 0)
+			tick = MAX(0, x);
+		else if (strcmp(s, "skip") == 0)
+			tick = MAX(0, tick+x);
+		else if (strcmp(s, "rewind") == 0)
+			tick = MAX(0, tick-x);
+
+		/* FIXME color, find, select, inject, write, time */
+	}
+}
+
+static void
 process(Oevent_list *events)
 {
 	int i, off;
 	Oevent *e;
 	u8int u[4];
+	char tmp[64];
 
 	for (e = events->buffer, i = 0; i < events->count; i++, e++) {
 		if (e->any.oevent_type == Oevent_type_midi_note) {
-			Oevent_midi_note const *n = &e->midi_note;
+			Oevent_midi_note *n = &e->midi_note;
 			u[0] = 1;
 			u[1] = 0x90 | n->channel;
 			u[2] = (n->octave + 1)*12 + n->note;
@@ -206,6 +240,11 @@
 			noteoff[off].u[2] = u[2];
 			noteoff[off].u[3] = 0;
 			noteoff[off].at = tick + n->duration;
+		} else if (e->any.oevent_type == Oevent_type_cmd_string) {
+			Oevent_cmd_string *c = &e->cmd_string;
+			memmove(tmp, c->chars, c->count);
+			tmp[c->count] = 0;
+			command(tmp);
 		}
 	}
 
@@ -695,39 +734,6 @@
 	}
 }
 
-static void
-command(char *s)
-{
-	char *a;
-	int x;
-
-	if ((a = strchr(s, ':')) != nil)
-		*a++ = 0;
-
-	if (strcmp(s, "play") == 0)
-		pause = false;
-	else if (strcmp(s, "stop") == 0)
-		pause = true;
-	else if (strcmp(s, "run") == 0)
-		forward = true;
-	else if (a != nil) {
-		x = atoi(a);
-
-		if (strcmp(s, "bpm") == 0)
-			apm = bpm = MAX(1, x);
-		else if (strcmp(s, "apm") == 0)
-			apm = MAX(1, x);
-		else if (strcmp(s, "frame") == 0)
-			tick = MAX(0, x);
-		else if (strcmp(s, "skip") == 0)
-			tick = MAX(0, tick+x);
-		else if (strcmp(s, "rewind") == 0)
-			tick = MAX(0, tick-x);
-
-		/* FIXME color, find, select, inject, write, time */
-	}
-}
-
 void
 threadmain(int argc, char **argv)
 {
@@ -1034,7 +1040,7 @@
 			default:
 				if (key.rune == Kdel || key.rune == ' ')
 					key.rune = '.';
-				if (orca_is_valid_glyph(key.rune)) {
+				if (orca_is_valid_glyph(key.rune) || key.rune == '$') {
 					fieldset(key.rune);
 				} else {
 //					fprint(2, "unhandled key %04x\n", key.rune);
--- a/sim.c
+++ b/sim.c
@@ -156,7 +156,8 @@
   _(':', midi)                                                                 \
   _(';', udp)                                                                  \
   _('=', osc)                                                                  \
-  _('?', midipb)
+  _('?', midipb)                                                               \
+  _('$', cmd)
 
 #define ALPHA_OPERATORS(_)                                                     \
   _('A', add)                                                                  \
@@ -391,6 +392,32 @@
   oe->channel = (U8)channel;
   oe->msb = (U8)(index_of(msb_g) * 127 / 35); // 0~35 -> 0~127
   oe->lsb = (U8)(index_of(lsb_g) * 127 / 35);
+END_OPERATOR
+
+BEGIN_OPERATOR(cmd)
+  Usz n = width - x - 1;
+  if (n > 16)
+    n = 16;
+  Glyph const *restrict gline = gbuffer + y * width + x + 1;
+  Mark *restrict mline = mbuffer + y * width + x + 1;
+  Glyph cpy[Oevent_cmd_string_count];
+  Usz i;
+  for (i = 0; i < n; ++i) {
+    Glyph g = gline[i];
+    if (g == '.')
+      break;
+    cpy[i] = g;
+    mline[i] |= Mark_flag_lock;
+  }
+  n = i;
+  STOP_IF_NOT_BANGED;
+  Oevent_cmd_string *oe =
+      (Oevent_cmd_string *)oevent_list_alloc_item(extra_params->oevent_list);
+  oe->oevent_type = (U8)Oevent_type_cmd_string;
+  oe->count = (U8)n;
+  for (i = 0; i < n; ++i) {
+    oe->chars[i] = cpy[i];
+  }
 END_OPERATOR
 
 BEGIN_OPERATOR(add)
--- a/tui_main.c
+++ b/tui_main.c
@@ -86,6 +86,7 @@
   case '=':
   case '%':
   case '?':
+  case '$':
     return Glyph_class_lowercase;
   case '*':
     return Glyph_class_bang;
@@ -650,7 +651,14 @@
       }
       break;
     }
+    case Oevent_type_cmd_string: {
+      Oevent_cmd_string const *ec = &ev->cmd_string;
+      wprintw(win, "CMD\tcount %d\t", (int)ec->count);
+      for (Usz j = 0; j < (Usz)ec->count; ++j) {
+        waddch(win, (chtype)ec->chars[j]);
+      }
     }
+    }
   }
 }
 
@@ -1161,7 +1169,10 @@
       oosc_send_datagram(oosc_dev, eo->chars, eo->count);
       break;
     }
+    case Oevent_type_cmd_string: {
+      break;
     }
+    }
   }
 
 do_note_ons:
@@ -2273,7 +2284,6 @@
       {'Z', "lerp", "Transitions operand to target."},
       {'*', "bang", "Bangs neighboring operands."},
       {'#', "comment", "Halts line."},
-      // {'*', "self", "Sends ORCA command."},
       {':', "midi", "Sends MIDI note."},
       {'!', "cc", "Sends MIDI control change."},
       {'?', "pb", "Sends MIDI pitch bend."},
@@ -2280,6 +2290,7 @@
       // {'%', "mono", "Sends MIDI monophonic note."},
       {'=', "osc", "Sends OSC message."},
       {';', "udp", "Sends UDP message."},
+      //{'$', "cmd", "Sends ORCA command."},
   };
   int w_desc = 0;
   for (Usz i = 0; i < ORCA_ARRAY_COUNTOF(items); ++i) {
--- a/vmio.h
+++ b/vmio.h
@@ -7,6 +7,7 @@
   Oevent_type_midi_pb,
   Oevent_type_osc_ints,
   Oevent_type_udp_string,
+  Oevent_type_cmd_string,
 } Oevent_types;
 
 typedef struct {
@@ -45,6 +46,14 @@
   char chars[Oevent_udp_string_count];
 } Oevent_udp_string;
 
+enum { Oevent_cmd_string_count = 16 };
+
+typedef struct {
+  U8 oevent_type;
+  U8 count;
+  char chars[Oevent_cmd_string_count];
+} Oevent_cmd_string;
+
 typedef union {
   Oevent_any any;
   Oevent_midi_note midi_note;
@@ -52,6 +61,7 @@
   Oevent_midi_pb midi_pb;
   Oevent_osc_ints osc_ints;
   Oevent_udp_string udp_string;
+  Oevent_cmd_string cmd_string;
 } Oevent;
 
 typedef struct {