<commit_before>#ifndef BUFFER_H
#define BUFFER_H

#include <PololuLedStrip.h>
#include <render.h>
#include <zones.h>

#define DEFAULT_EFFECT 127
#define NO_EFFECT 0
#define OVERRIDE_OFF -1

#define DRAW_MODE_WRITE 0
#define DRAW_MODE_PLUS  1
#define DRAW_MODE_MINUS 2
#define DRAW_MODE_MIX   3
#define DRAW_MODE_DIFF  4

class Buffer
{
  public:
  void begin(PololuLedStripBase **ledStrips, byte default_brightness, byte safety_led_count, byte visible_led_count, Render *renderer, rgb_color **buffers, rgb_color *render, byte **effects_buffers, Zones * zones);

  void display_buffer(rgb_color * pbuffer);
  void render_display();
  void erase(bool display);
  void push_color(rgb_color color, byte times, bool display, byte effect, byte max, byte start, bool color_correction);
  void push_rgb_color(byte red, byte green, byte blue);
  void push_hsl_color(int hue, int sat, int lit);
  void push_carry_color();
  void shift(byte count, byte maxx, bool fast_render);
  void finalize_shift(byte count, byte max);
  // void set_color(byte pos, rgb_color color, bool display, byte effect);
  void fade(float rate);
  void fade_fast();
  void cross_fade(byte step);
  byte get_window();
  void set_display(byte display);
  void set_buffer(byte buffer);
  rgb_color * get_buffer();
  byte * get_effects_buffer();
  byte get_current_display();
  rgb_color * get_render_buffer();
  void set_offset_override(byte offset, bool fixup);
  void set_window_override(byte window, bool fixup);
  byte get_offset();
  byte get_width();
  void set_zone(byte zone);
  void reset();
  void set_reverse(bool reverse);
  bool get_reverse();
  void rotate();
  byte get_display();
  byte get_zones();
  void set_black_level(rgb_color black_level);
  void reset_black_level();
  rgb_color black;
  int get_default_brightness();
  void set_default_effect(byte effect);
  void set_draw_mode(byte mode = DRAW_MODE_WRITE);
  byte get_draw_mode();

  // todo: is there an alternative to storing all these pointers?
  private:

  static rgb_color *render;

  PololuLedStripBase **ledStrips;
  byte current_display;
  rgb_color **buffers;
  byte **effects_buffers;
  float default_brightness_scale;
  Render *renderer;
  byte visible_led_count;
  rgb_color carry_color;
  byte carry_effect;

  int window_override = OVERRIDE_OFF;
  int offset_override = OVERRIDE_OFF;

  Zones *zones;
  byte current_zone = 0;
  bool reverse = false;

  byte draw_mode = DRAW_MODE_WRITE;

  byte default_effect = NO_EFFECT;

  void shift_buffer(rgb_color * buffer, byte * effects, byte max, byte start, bool reverse);
};

rgb_color *Buffer::render;

void Buffer::begin(PololuLedStripBase **ledStrips, byte default_brightness, byte safety_led_count, byte visible_led_count, Render *renderer, rgb_color **buffers, rgb_color *render, byte **effects_buffers, Zones * zones){
  this->black = Render::black;
  this->ledStrips = ledStrips;
  this->current_display = 0;
  this->buffers = buffers;
  this->render = render;
  this->default_brightness_scale = default_brightness / 100.0;
  this->effects_buffers = effects_buffers;
  this->renderer = renderer;
  this->visible_led_count = visible_led_count;
  this->window_override = OVERRIDE_OFF;
  this->offset_override = OVERRIDE_OFF;
  this->zones = zones;
  this->reverse = false;
  this->carry_color = black;
  this->carry_effect = NO_EFFECT;
  this->draw_mode = DRAW_MODE_WRITE;
}

byte Buffer::get_display()
{
  return this->current_display;
}

void Buffer::reset()
{
  this->set_zone(0);
  this->set_reverse(false);
}

// always write from the render buffer to a pin,
// the render buffer having been rendered from a specific display buffer already
void Buffer::display_buffer(rgb_color * pbuffer)
{
  ledStrips[current_display]->write(pbuffer, visible_led_count);
}

// todo might want choice of slow or fast render
void Buffer::render_display()
{
  renderer->render_buffer(render, this->buffers[current_display], visible_led_count, this->effects_buffers[current_display]);
  display_buffer(render);
}

void Buffer::erase(bool display = false)
{
  byte offset = get_offset();
  byte window = get_window();
  rgb_color * buf = buffers[current_display];
  byte * effects = effects_buffers[current_display];

  rgb_color erase_color = ColorMath ::correct_color(black);

  for(byte i = offset; i < window; i++)
  {
    buf[i] = erase_color;
    effects[i] = NO_EFFECT;
  }

  if(display)
    render_display();<commit_msg>fix erasure when window is zero-width<commit_after>#ifndef BUFFER_H
#define BUFFER_H

#include <PololuLedStrip.h>
#include <render.h>
#include <zones.h>

#define DEFAULT_EFFECT 127
#define NO_EFFECT 0
#define OVERRIDE_OFF -1

#define DRAW_MODE_WRITE 0
#define DRAW_MODE_PLUS  1
#define DRAW_MODE_MINUS 2
#define DRAW_MODE_MIX   3
#define DRAW_MODE_DIFF  4

class Buffer
{
  public:
  void begin(PololuLedStripBase **ledStrips, byte default_brightness, byte safety_led_count, byte visible_led_count, Render *renderer, rgb_color **buffers, rgb_color *render, byte **effects_buffers, Zones * zones);

  void display_buffer(rgb_color * pbuffer);
  void render_display();
  void erase(bool display);
  void push_color(rgb_color color, byte times, bool display, byte effect, byte max, byte start, bool color_correction);
  void push_rgb_color(byte red, byte green, byte blue);
  void push_hsl_color(int hue, int sat, int lit);
  void push_carry_color();
  void shift(byte count, byte maxx, bool fast_render);
  void finalize_shift(byte count, byte max);
  // void set_color(byte pos, rgb_color color, bool display, byte effect);
  void fade(float rate);
  void fade_fast();
  void cross_fade(byte step);
  byte get_window();
  void set_display(byte display);
  void set_buffer(byte buffer);
  rgb_color * get_buffer();
  byte * get_effects_buffer();
  byte get_current_display();
  rgb_color * get_render_buffer();
  void set_offset_override(byte offset, bool fixup);
  void set_window_override(byte window, bool fixup);
  byte get_offset();
  byte get_width();
  void set_zone(byte zone);
  void reset();
  void set_reverse(bool reverse);
  bool get_reverse();
  void rotate();
  byte get_display();
  byte get_zones();
  void set_black_level(rgb_color black_level);
  void reset_black_level();
  rgb_color black;
  int get_default_brightness();
  void set_default_effect(byte effect);
  void set_draw_mode(byte mode = DRAW_MODE_WRITE);
  byte get_draw_mode();

  // todo: is there an alternative to storing all these pointers?
  private:

  static rgb_color *render;

  PololuLedStripBase **ledStrips;
  byte current_display;
  rgb_color **buffers;
  byte **effects_buffers;
  float default_brightness_scale;
  Render *renderer;
  byte visible_led_count;
  rgb_color carry_color;
  byte carry_effect;

  int window_override = OVERRIDE_OFF;
  int offset_override = OVERRIDE_OFF;

  Zones *zones;
  byte current_zone = 0;
  bool reverse = false;

  byte draw_mode = DRAW_MODE_WRITE;

  byte default_effect = NO_EFFECT;

  void shift_buffer(rgb_color * buffer, byte * effects, byte max, byte start, bool reverse);
};

rgb_color *Buffer::render;

void Buffer::begin(PololuLedStripBase **ledStrips, byte default_brightness, byte safety_led_count, byte visible_led_count, Render *renderer, rgb_color **buffers, rgb_color *render, byte **effects_buffers, Zones * zones){
  this->black = Render::black;
  this->ledStrips = ledStrips;
  this->current_display = 0;
  this->buffers = buffers;
  this->render = render;
  this->default_brightness_scale = default_brightness / 100.0;
  this->effects_buffers = effects_buffers;
  this->renderer = renderer;
  this->visible_led_count = visible_led_count;
  this->window_override = OVERRIDE_OFF;
  this->offset_override = OVERRIDE_OFF;
  this->zones = zones;
  this->reverse = false;
  this->carry_color = black;
  this->carry_effect = NO_EFFECT;
  this->draw_mode = DRAW_MODE_WRITE;
}

byte Buffer::get_display()
{
  return this->current_display;
}

void Buffer::reset()
{
  this->set_zone(0);
  this->set_reverse(false);
}

// always write from the render buffer to a pin,
// the render buffer having been rendered from a specific display buffer already
void Buffer::display_buffer(rgb_color * pbuffer)
{
  ledStrips[current_display]->write(pbuffer, visible_led_count);
}

// todo might want choice of slow or fast render
void Buffer::render_display()
{
  renderer->render_buffer(render, this->buffers[current_display], visible_led_count, this->effects_buffers[current_display]);
  display_buffer(render);
}

void Buffer::erase(bool display = false)
{
  byte offset = get_offset();
  byte window = get_window();
  rgb_color * buf = buffers[current_display];
  byte * effects = effects_buffers[current_display];

  rgb_color erase_color = ColorMath ::correct_color(black);

  if(offset == window)
  {
    buf[offset] = erase_color;
    effects[offset] = NO_EFFECT;
  }
  else
  {
    for(byte i = offset; i < window; i++)
    {
      buf[i] = erase_color;
      effects[i] = NO_EFFECT;
    }
  }

  if(display)
    render_display();
{'fraction_non_alphanumeric': 0.10278396436525612, 'fraction_numerical': 0.0037861915367483298, 'mean_word_length': 5.105370496261047, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 55, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3724629', 'n_tokens_mistral': 3112, 'n_tokens_neox': 3005, 'n_words': 785}