Home /Modules/user-interface/SLCalculus8.sleela

SLCalculus8.sleela

lib/user-interface/SLCalculus8.sleela · 88 line(s) · sleela

<< lib/user-interface/SLCalculus8.sleela
   SLeeLa Standard Library Definition.
   Definition: Defines SLCalculus8 — the careful 8-stage calculus with 100
     differentiable inputs that maps a SleelaUI light's control points directly
     into a MOOD. Each of the 100 inputs is a "differentiable" the host nudges in
     [0,1]; eight smooth, analytically-differentiable basis stages (identity,
     quadratic, smoothstep, sine, cosine, logistic, gaussian, tanh) combine them
     into a mood scalar in [0,1]. Because every stage is differentiable, eval
     returns both the mood and the slope d(mood)/d(input) so an adjuster can walk
     the gradient into a mood. Each method bottoms out in a `calc8*` SLVM
     built-in that calls the genuine C ABI (sleela_ui_mood.h).
   
   A calculus is a VM-local handle (-1 = none). Attach it to an SLMood with
   SLMood.setCalculus to drive where the mood's wash is sampled.
   
   Family: user-interface. Native VM/UI work crosses the explicit `calc8*` SLVM
   bridge. >>
#sleela 2.5
material;
class SLCalculus8 {
  < ---- Descriptive metadata (version 1.11 nested-friendly accessors) ---- >
  << Eleven catalogued attributes with getter/setter pairs, so a GUI, loader,
     or catalog can read and (where appropriate) override this record.
     Values are faithful to the subject's real origin where publicly known. >>
  String metaVersion = "1.0.0";
  int metaId = 10351;
  String metaAuthor = "Kiro Agent";
  String metaDate = "2026-10-16";
  String metaCopyright = "SLeeLa project";
  String metaTrademark = "none";
  String metaCorporation = "none";
  < metaOrigin: National | <nation> | International | Galactic >
  String metaOrigin = "International";
  String metaBirthDate = "2026-10-07";
  < metaScienceRating: maturity/robustness on a 1..10 scale >
  int metaScienceRating = 9;
  < metaNationalSchedule: a real, citable instrument or "none" >
  String metaNationalSchedule = "none";

  String getMetaVersion() { return metaVersion; }
  void setMetaVersion(String v) { metaVersion = v; }
  int getMetaId() { return metaId; }
  void setMetaId(int v) { metaId = v; }
  String getAuthor() { return metaAuthor; }
  void setAuthor(String v) { metaAuthor = v; }
  String getDate() { return metaDate; }
  void setDate(String v) { metaDate = v; }
  String getCopyright() { return metaCopyright; }
  void setCopyright(String v) { metaCopyright = v; }
  String getTrademark() { return metaTrademark; }
  void setTrademark(String v) { metaTrademark = v; }
  String getCorporation() { return metaCorporation; }
  void setCorporation(String v) { metaCorporation = v; }
  String getOrigin() { return metaOrigin; }
  void setOrigin(String v) { metaOrigin = v; }
  String getBirthDate() { return metaBirthDate; }
  void setBirthDate(String v) { metaBirthDate = v; }
  int getScienceRating() { return metaScienceRating; }
  void setScienceRating(int v) { metaScienceRating = v; }
  String getNationalSchedule() { return metaNationalSchedule; }
  void setNationalSchedule(String v) { metaNationalSchedule = v; }
  < the 100 differentiables >
  static final int INPUTS = 100;
  < the careful 8 stages >
  static final int STAGES = 8;

  < VM-local handle (-1 = none) >
  int calc;

  void create() { calc = calc8Create(); }
  int handle() { return calc; }
  boolean valid() { return calc >= 0; }
  void destroy() { if (calc >= 0) { calc8Destroy(calc); calc = -1; } }

  < Set/get one of the 100 differentiables (index 0..99), each in [0,1]. >
  void set(int index, double value) { if (calc >= 0) { calc8Set(calc, index, value); } }
  double get(int index) { if (calc < 0) { return 0.0; } return calc8Get(calc, index); }

  < Evaluate: the mood scalar in [0,1]. >
  double mood() { if (calc < 0) { return 0.5; } return calc8Eval(calc, -1); }
  < The slope d(mood)/d(input) along a given differentiable (differentiable >
  < calculus: nudging that input moves the mood by this slope). >
  double slope(int wrtIndex) {
    if (calc < 0) { return 0.0; }
    return calc8Slope(calc, wrtIndex);
  }
}