shithub: orca

Download patch

ref: 53df0684c326a5c462c46c618cdec41ed1b5126b
parent: 085a540f9ba47bd3f37ae107de6af53ded188b19
author: cancel <cancel@cancel.fm>
date: Tue Jan 22 04:12:34 EST 2019

Clean up naming of Markmap_ stuff

--- a/cli_main.c
+++ b/cli_main.c
@@ -96,17 +96,17 @@
     fprintf(stderr, "File load error: %s.\n", errstr);
     return 1;
   }
-  Markmap_reusable markmap_r;
-  markmap_reusable_init(&markmap_r);
-  markmap_reusable_ensure_size(&markmap_r, field.height, field.width);
+  Mbuf_reusable mbuf_r;
+  mbuf_reusable_init(&mbuf_r);
+  mbuf_reusable_ensure_size(&mbuf_r, field.height, field.width);
   Oevent_list oevent_list;
   oevent_list_init(&oevent_list);
   Usz max_ticks = (Usz)ticks;
   for (Usz i = 0; i < max_ticks; ++i) {
-    orca_run(field.buffer, markmap_r.buffer, field.height, field.width, i,
+    orca_run(field.buffer, mbuf_r.buffer, field.height, field.width, i,
              &oevent_list, ORCA_PIANO_BITS_NONE);
   }
-  markmap_reusable_deinit(&markmap_r);
+  mbuf_reusable_deinit(&mbuf_r);
   oevent_list_deinit(&oevent_list);
   field_fput(&field, stdout);
   field_deinit(&field);
--- a/mark.c
+++ b/mark.c
@@ -1,20 +1,19 @@
 #include "mark.h"
 
-void markmap_reusable_init(Markmap_reusable* map) {
-  map->buffer = NULL;
-  map->capacity = 0;
+void mbuf_reusable_init(Mbuf_reusable* mbr) {
+  mbr->buffer = NULL;
+  mbr->capacity = 0;
 }
 
-void markmap_reusable_ensure_size(Markmap_reusable* map, Usz height,
-                                  Usz width) {
+void mbuf_reusable_ensure_size(Mbuf_reusable* mbr, Usz height, Usz width) {
   Usz capacity = height * width;
-  if (map->capacity < capacity) {
-    map->buffer = realloc(map->buffer, capacity);
-    map->capacity = capacity;
+  if (mbr->capacity < capacity) {
+    mbr->buffer = realloc(mbr->buffer, capacity);
+    mbr->capacity = capacity;
   }
 }
 
-void markmap_reusable_deinit(Markmap_reusable* map) { free(map->buffer); }
+void mbuf_reusable_deinit(Mbuf_reusable* mbr) { free(mbr->buffer); }
 
 void mbuffer_clear(Mark* mbuf, Usz height, Usz width) {
   Usz cleared_size = height * width;
--- a/mark.h
+++ b/mark.h
@@ -10,68 +10,63 @@
   Mark_flag_sleep = 1 << 4,
 } Mark_flags;
 
-typedef struct Markmap_reusable {
+typedef struct Mbuf_reusable {
   Mark* buffer;
   Usz capacity;
-} Markmap_reusable;
+} Mbuf_reusable;
 
-void markmap_reusable_init(Markmap_reusable* map);
-void markmap_reusable_ensure_size(Markmap_reusable* map, Usz height, Usz width);
-void markmap_reusable_deinit(Markmap_reusable* map);
+void mbuf_reusable_init(Mbuf_reusable* mbr);
+void mbuf_reusable_ensure_size(Mbuf_reusable* mbr, Usz height, Usz width);
+void mbuf_reusable_deinit(Mbuf_reusable* mbr);
 
 void mbuffer_clear(Mark* mbuf, Usz height, Usz width);
 
 ORCA_OK_IF_UNUSED
-static Mark_flags mbuffer_peek(Mark* mbuf, Usz map_height, Usz map_width, Usz y,
-                               Usz x);
+static Mark_flags mbuffer_peek(Mark* mbuf, Usz height, Usz width, Usz y, Usz x);
 ORCA_OK_IF_UNUSED
-static Mark_flags mbuffer_peek_relative(Mark* mbuf, Usz map_height,
-                                        Usz map_width, Usz y, Usz x, Isz offs_y,
-                                        Isz offs_x);
+static Mark_flags mbuffer_peek_relative(Mark* mbuf, Usz height, Usz width,
+                                        Usz y, Usz x, Isz offs_y, Isz offs_x);
 ORCA_OK_IF_UNUSED
-static void mbuffer_poke_flags_or(Mark* mbuf, Usz map_height, Usz map_width,
-                                  Usz y, Usz x, Mark_flags flags);
+static void mbuffer_poke_flags_or(Mark* mbuf, Usz height, Usz width, Usz y,
+                                  Usz x, Mark_flags flags);
 ORCA_OK_IF_UNUSED
-static void mbuffer_poke_relative_flags_or(Mark* mbuf, Usz map_height,
-                                           Usz map_width, Usz y, Usz x,
-                                           Isz offs_y, Isz offs_x,
+static void mbuffer_poke_relative_flags_or(Mark* mbuf, Usz height, Usz width,
+                                           Usz y, Usz x, Isz offs_y, Isz offs_x,
                                            Mark_flags flags);
 
 // Inline implementation
 
 ORCA_OK_IF_UNUSED
-static Mark_flags mbuffer_peek(Mark* mbuf, Usz map_height, Usz map_width, Usz y,
+static Mark_flags mbuffer_peek(Mark* mbuf, Usz height, Usz width, Usz y,
                                Usz x) {
-  (void)map_height;
-  return mbuf[y * map_width + x];
+  (void)height;
+  return mbuf[y * width + x];
 }
 
 ORCA_OK_IF_UNUSED
-static Mark_flags mbuffer_peek_relative(Mark* mbuf, Usz map_height,
-                                        Usz map_width, Usz y, Usz x, Isz offs_y,
-                                        Isz offs_x) {
+static Mark_flags mbuffer_peek_relative(Mark* mbuf, Usz height, Usz width,
+                                        Usz y, Usz x, Isz offs_y, Isz offs_x) {
   Isz y0 = (Isz)y + offs_y;
   Isz x0 = (Isz)x + offs_x;
-  if (y0 >= (Isz)map_height || x0 >= (Isz)map_width || y0 < 0 || x0 < 0)
+  if (y0 >= (Isz)height || x0 >= (Isz)width || y0 < 0 || x0 < 0)
     return Mark_flag_none;
-  return mbuf[(Usz)y0 * map_width + (Usz)x0];
+  return mbuf[(Usz)y0 * width + (Usz)x0];
 }
 
 ORCA_OK_IF_UNUSED
-static void mbuffer_poke_flags_or(Mark* mbuf, Usz map_height, Usz map_width,
-                                  Usz y, Usz x, Mark_flags flags) {
-  (void)map_height;
-  mbuf[y * map_width + x] |= (Mark)flags;
+static void mbuffer_poke_flags_or(Mark* mbuf, Usz height, Usz width, Usz y,
+                                  Usz x, Mark_flags flags) {
+  (void)height;
+  mbuf[y * width + x] |= (Mark)flags;
 }
 
 ORCA_OK_IF_UNUSED
-static void mbuffer_poke_relative_flags_or(Mark* mbuf, Usz map_height,
-                                           Usz map_width, Usz y, Usz x,
-                                           Isz offs_y, Isz offs_x,
+static void mbuffer_poke_relative_flags_or(Mark* mbuf, Usz height, Usz width,
+                                           Usz y, Usz x, Isz offs_y, Isz offs_x,
                                            Mark_flags flags) {
   Isz y0 = (Isz)y + offs_y;
   Isz x0 = (Isz)x + offs_x;
-  if (y0 >= (Isz)map_height || x0 >= (Isz)map_width || y0 < 0 || x0 < 0)
+  if (y0 >= (Isz)height || x0 >= (Isz)width || y0 < 0 || x0 < 0)
     return;
-  mbuf[(Usz)y0 * map_width + (Usz)x0] |= (Mark)flags;
+  mbuf[(Usz)y0 * width + (Usz)x0] |= (Mark)flags;
 }
--- a/tui_main.c
+++ b/tui_main.c
@@ -599,7 +599,7 @@
   }
 }
 
-void ged_resize_grid(Field* field, Markmap_reusable* markmap, Usz new_height,
+void ged_resize_grid(Field* field, Mbuf_reusable* markmap, Usz new_height,
                      Usz new_width, Usz tick_num, Field* scratch_field,
                      Undo_history* undo_hist, Ged_cursor* ged_cursor) {
   assert(new_height > 0 && new_width > 0);
@@ -613,7 +613,7 @@
                        field->height, field->width, 0, 0, 0, 0,
                        scratch_field->height, scratch_field->width);
   ged_cursor_confine(ged_cursor, new_height, new_width);
-  markmap_reusable_ensure_size(markmap, new_height, new_width);
+  mbuf_reusable_ensure_size(markmap, new_height, new_width);
 }
 
 static Usz adjust_rulers_humanized(Usz ruler, Usz in, Isz delta_rulers) {
@@ -636,7 +636,7 @@
 // Resizes by number of ruler divisions, and snaps size to closest division in
 // a way a human would expect. Adds +1 to the output, so grid resulting size is
 // 1 unit longer than the actual ruler length.
-bool ged_resize_grid_snap_ruler(Field* field, Markmap_reusable* markmap,
+bool ged_resize_grid_snap_ruler(Field* field, Mbuf_reusable* markmap,
                                 Usz ruler_y, Usz ruler_x, Isz delta_h,
                                 Isz delta_w, Usz tick_num, Field* scratch_field,
                                 Undo_history* undo_hist,
@@ -734,7 +734,7 @@
   Field field;
   Field scratch_field;
   Field clipboard_field;
-  Markmap_reusable markmap_r;
+  Mbuf_reusable mbuf_r;
   Undo_history undo_hist;
   Oevent_list oevent_list;
   Oevent_list scratch_oevent_list;
@@ -772,7 +772,7 @@
   field_init(&a->field);
   field_init(&a->scratch_field);
   field_init(&a->clipboard_field);
-  markmap_reusable_init(&a->markmap_r);
+  mbuf_reusable_init(&a->mbuf_r);
   undo_history_init(&a->undo_hist, undo_limit);
   ged_cursor_init(&a->ged_cursor);
   oevent_list_init(&a->oevent_list);
@@ -811,7 +811,7 @@
   field_deinit(&a->field);
   field_deinit(&a->scratch_field);
   field_deinit(&a->clipboard_field);
-  markmap_reusable_deinit(&a->markmap_r);
+  mbuf_reusable_deinit(&a->mbuf_r);
   undo_history_deinit(&a->undo_hist);
   oevent_list_deinit(&a->oevent_list);
   oevent_list_deinit(&a->scratch_oevent_list);
@@ -1102,8 +1102,8 @@
   if (do_play) {
     apply_time_to_sustained_notes(oosc_dev, midi_mode, secs_span,
                                   &a->susnote_list, &a->time_to_next_note_off);
-    orca_run(a->field.buffer, a->markmap_r.buffer, a->field.height,
-             a->field.width, a->tick_num, &a->oevent_list, a->piano_bits);
+    orca_run(a->field.buffer, a->mbuf_r.buffer, a->field.height, a->field.width,
+             a->tick_num, &a->oevent_list, a->piano_bits);
     ++a->tick_num;
     a->piano_bits = ORCA_PIANO_BITS_NONE;
     a->needs_remarking = true;
@@ -1195,9 +1195,8 @@
     field_resize_raw_if_necessary(&a->scratch_field, a->field.height,
                                   a->field.width);
     field_copy(&a->field, &a->scratch_field);
-    markmap_reusable_ensure_size(&a->markmap_r, a->field.height,
-                                 a->field.width);
-    orca_run(a->scratch_field.buffer, a->markmap_r.buffer, a->field.height,
+    mbuf_reusable_ensure_size(&a->mbuf_r, a->field.height, a->field.width);
+    orca_run(a->scratch_field.buffer, a->mbuf_r.buffer, a->field.height,
              a->field.width, a->tick_num, &a->scratch_oevent_list,
              a->piano_bits);
     a->needs_remarking = false;
@@ -1205,8 +1204,8 @@
   int win_h = a->win_h;
   int win_w = a->win_w;
   draw_glyphs_grid_scrolled(win, 0, 0, a->grid_h, win_w, a->field.buffer,
-                            a->markmap_r.buffer, a->field.height,
-                            a->field.width, a->grid_scroll_y, a->grid_scroll_x,
+                            a->mbuf_r.buffer, a->field.height, a->field.width,
+                            a->grid_scroll_y, a->grid_scroll_x,
                             a->ruler_spacing_y, a->ruler_spacing_x);
   draw_grid_cursor(win, 0, 0, a->grid_h, win_w, a->field.buffer,
                    a->field.height, a->field.width, a->grid_scroll_y,
@@ -1419,7 +1418,7 @@
 }
 
 void ged_resize_grid_relative(Ged* a, Isz delta_y, Isz delta_x) {
-  ged_resize_grid_snap_ruler(&a->field, &a->markmap_r, a->ruler_spacing_y,
+  ged_resize_grid_snap_ruler(&a->field, &a->mbuf_r, a->ruler_spacing_y,
                              a->ruler_spacing_x, delta_y, delta_x, a->tick_num,
                              &a->scratch_field, &a->undo_hist, &a->ged_cursor);
   a->needs_remarking = true; // could check if we actually resized
@@ -1570,8 +1569,8 @@
     break;
   case Ged_input_cmd_step_forward:
     undo_history_push(&a->undo_hist, &a->field, a->tick_num);
-    orca_run(a->field.buffer, a->markmap_r.buffer, a->field.height,
-             a->field.width, a->tick_num, &a->oevent_list, a->piano_bits);
+    orca_run(a->field.buffer, a->mbuf_r.buffer, a->field.height, a->field.width,
+             a->tick_num, &a->oevent_list, a->piano_bits);
     ++a->tick_num;
     a->piano_bits = ORCA_PIANO_BITS_NONE;
     a->needs_remarking = true;