shithub: orca

Download patch

ref: f9255bbf99267dc360741461deea27d6dab92b3b
parent: 3ebe3285f07d426bdf5fc73fa381d499875a156a
author: cancel <cancel@cancel.fm>
date: Sun Jan 19 17:31:42 EST 2020

Change MIDI note duration to behave like orca JS

--- a/bank.h
+++ b/bank.h
@@ -13,7 +13,7 @@
 
 typedef struct {
   U8 oevent_type;
-  U8 channel, octave, note, velocity, bar_divisor;
+  U8 channel, octave, note, velocity, duration;
 } Oevent_midi;
 
 enum { Oevent_osc_int_count = 16 };
--- a/sim.c
+++ b/sim.c
@@ -321,7 +321,7 @@
   oe->octave = octave_num;
   oe->note = note_num;
   oe->velocity = (U8)vel_num;
-  oe->bar_divisor = (U8)(index_of(length_g) + 1);
+  oe->duration = (U8)(index_of(length_g));
 END_OPERATOR
 
 BEGIN_OPERATOR(udp)
--- a/tui_main.c
+++ b/tui_main.c
@@ -631,7 +631,7 @@
       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);
+              (int)em->velocity, (int)em->duration);
       break;
     }
     case Oevent_type_osc_ints: {
@@ -1026,7 +1026,7 @@
                         Susnote_list *susnote_list, Oevent const *events,
                         Usz count) {
   Midi_mode_type midi_mode_type = midi_mode->any.type;
-  double bar_secs = 60.0 / (double)bpm * 4.0;
+  double frame_secs = 60.0 / (double)bpm / 4.0;
 
   enum { Midi_on_capacity = 512 };
   typedef struct {
@@ -1049,15 +1049,14 @@
       if (note_number > 127)
         note_number = 127;
       Usz channel = em->channel;
-      Usz bar_div = em->bar_divisor;
+      Usz duration = em->duration;
       midi_note_ons[midi_note_count] =
           (Midi_note_on){.channel = (U8)channel,
                          .note_number = (U8)note_number,
                          .velocity = em->velocity};
-      new_susnotes[midi_note_count] = (Susnote){
-          .remaining =
-              bar_div == 0 ? 0.0f : (float)(bar_secs / (double)bar_div),
-          .chan_note = (U16)((channel << 8u) | note_number)};
+      new_susnotes[midi_note_count] =
+          (Susnote){.remaining = (float)(frame_secs * (double)duration),
+                    .chan_note = (U16)((channel << 8u) | note_number)};
 #if 0
       fprintf(stderr, "bar div: %d, time: %f\n", (int)bar_div,
               new_susnotes[midi_note_count].remaining);