shithub: orca

Download patch

ref: 54983e79f525cb86636d43ac1d6b729c9177b393
parent: 135b743c45f29f404817e35fc1966bcb0d39d8e9
author: cancel <cancel@cancel.fm>
date: Thu Dec 20 21:38:49 EST 2018

Add start of osc operator

--- a/bank.h
+++ b/bank.h
@@ -34,6 +34,7 @@
 
 typedef enum {
   Oevent_type_midi,
+  Oevent_type_osc_ints,
 } Oevent_types;
 
 typedef struct {
@@ -49,9 +50,17 @@
   U8 bar_divisor;
 } Oevent_midi;
 
+typedef struct {
+  U8 oevent_type;
+  Glyph glyph;
+  U8 count;
+  U8 numbers[4];
+} Oevent_osc_ints;
+
 typedef union {
   Oevent_any any;
   Oevent_midi midi;
+  Oevent_osc_ints osc_ints;
 } Oevent;
 
 typedef struct {
--- a/tui_main.c
+++ b/tui_main.c
@@ -532,14 +532,22 @@
     Oevent_types evt = ev->any.oevent_type;
     switch (evt) {
     case Oevent_type_midi: {
-      Oevent_midi const* em = (Oevent_midi const*)ev;
+      Oevent_midi const* em = &ev->midi;
       wprintw(win,
               "MIDI\tchannel %d\toctave %d\tnote %d\tvelocity %d\tlength %d",
               (int)em->channel, (int)em->octave, (int)em->note,
               (int)em->velocity, (int)em->bar_divisor);
-      break;
+    } break;
+    case Oevent_type_osc_ints: {
+      Oevent_osc_ints const* eo = &ev->osc_ints;
+      wprintw(win, "OSC Ints\tname %c\tcount %d", eo->glyph, eo->count,
+              eo->count);
+      for (Usz i = 0; i < eo->count; ++i) {
+        wprintw(win, " %d", eo->numbers[i]);
+      }
+      (void)eo;
+    } break;
     }
-    }
   }
 }
 
@@ -819,7 +827,7 @@
     Oevent const* e = events + i;
     switch ((Oevent_types)e->any.oevent_type) {
     case Oevent_type_midi: {
-      Oevent_midi const* em = (Oevent_midi const*)&e->midi;
+      Oevent_midi const* em = &e->midi;
       Usz note_number = (Usz)(12u * em->octave + em->note);
       Usz channel = em->channel;
       Usz bar_div = em->bar_divisor;
@@ -837,34 +845,46 @@
 #endif
       ++midi_note_count;
     } break;
+    case Oevent_type_osc_ints: {
+      Oevent_osc_ints const* eo = &e->osc_ints;
+      char path_buff[3];
+      path_buff[0] = '/';
+      path_buff[1] = eo->glyph;
+      path_buff[2] = 0;
+      I32 ints[ORCA_ARRAY_COUNTOF(eo->numbers)];
+      Usz nnum = eo->count;
+      for (Usz inum = 0; inum < nnum; ++inum) {
+        ints[inum] = eo->numbers[inum];
+      }
+      oosc_send_int32s(oosc_dev, path_buff, ints, nnum);
+    } break;
     }
   }
 
-  if (midi_note_count == 0)
-    return;
-
-  Usz start_note_offs, end_note_offs;
-  susnote_list_add_notes(susnote_list, new_susnotes, midi_note_count,
-                         &start_note_offs, &end_note_offs);
-  if (start_note_offs != end_note_offs) {
-    Susnote const* restrict susnotes_off = susnote_list->buffer;
-    send_midi_note_offs(oosc_dev, midi_mode, susnotes_off + start_note_offs,
-                        susnotes_off + end_note_offs);
-  }
-  for (Usz i = 0; i < midi_note_count; ++i) {
-    Midi_note_on mno = midi_note_ons[i];
-    switch (midi_mode_type) {
-    case Midi_mode_type_null:
-      break;
-    case Midi_mode_type_osc_bidule: {
-      I32 ints[3];
-      ints[0] = (0x9 << 4) | mno.channel; // status
-      ints[1] = mno.note_number;          // note number
-      ints[2] = mno.velocity;             // velocity
-      oosc_send_int32s(oosc_dev, midi_mode->osc_bidule.path, ints,
-                       ORCA_ARRAY_COUNTOF(ints));
-    } break;
+  if (midi_note_count > 0 && midi_mode) {
+    Usz start_note_offs, end_note_offs;
+    susnote_list_add_notes(susnote_list, new_susnotes, midi_note_count,
+                           &start_note_offs, &end_note_offs);
+    if (start_note_offs != end_note_offs) {
+      Susnote const* restrict susnotes_off = susnote_list->buffer;
+      send_midi_note_offs(oosc_dev, midi_mode, susnotes_off + start_note_offs,
+                          susnotes_off + end_note_offs);
     }
+    for (Usz i = 0; i < midi_note_count; ++i) {
+      Midi_note_on mno = midi_note_ons[i];
+      switch (midi_mode_type) {
+      case Midi_mode_type_null:
+        break;
+      case Midi_mode_type_osc_bidule: {
+        I32 ints[3];
+        ints[0] = (0x9 << 4) | mno.channel; // status
+        ints[1] = mno.note_number;          // note number
+        ints[2] = mno.velocity;             // velocity
+        oosc_send_int32s(oosc_dev, midi_mode->osc_bidule.path, ints,
+                         ORCA_ARRAY_COUNTOF(ints));
+      } break;
+      }
+    }
   }
 }
 
@@ -923,11 +943,9 @@
     a->is_draw_dirty = true;
 
     Usz count = a->oevent_list.count;
-    if (oosc_dev && midi_mode) {
-      if (count > 0) {
-        send_output_events(oosc_dev, midi_mode, a->bpm, &a->susnote_list,
-                           a->oevent_list.buffer, count);
-      }
+    if (oosc_dev && count > 0) {
+      send_output_events(oosc_dev, midi_mode, a->bpm, &a->susnote_list,
+                         a->oevent_list.buffer, count);
     }
     a->meter_level += (float)count * 0.2f;
     a->meter_level = float_clamp(a->meter_level, 0.0f, 1.0f);