sonic-weave
    Preparing search index...

    Class RootContext

    Root context of a SonicWeave runtime containing the scale title, root pitch, value of the 'up' inflection etc.

    Index

    Constructors

    • Create a new root context.

      Parameters

      • Optionalgas: number

        Computational budget for evaluating the program.

      Returns RootContext

    Properties

    fragiles: Interval[]

    Values that depend on the current root pitch or up/lift inflections.

    gas: number

    The remaining computational budget.

    templateArguments: SonicWeaveValue[]

    Values passed to a tagged template literal converted to types understood by the SonicWeave runtime.

    title: string

    Title of the scale.

    trackingIndex: number

    Current tracking ID.

    unisonFrequency?: TimeMonzo

    Absolute frequency associated with 1/1 (linear) or P1 (logarithmic perfect unison).

    Accessors

    • get C4(): TimeMonzo

      Current value of middle C. With respect to the unison frequency if relative or with respect to 1 Hz if absolute.

      Returns TimeMonzo

    • set C4(value: TimeMonzo): void

      Parameters

      Returns void

    • get lift(): Interval

      Current value of the 'lift' / inflection and conversely of the 'drop' \ inflection.

      Returns Interval

    • set lift(value: Interval): void

      Parameters

      Returns void

    • get mosConfig(): MosConfig | undefined

      MOS declaration result.

      Returns MosConfig | undefined

    • set mosConfig(value: MosConfig | undefined): void

      Parameters

      Returns void

    • get up(): Interval

      Current value of the 'up' ^ inflection and conversely of the 'down' v inflection.

      Returns Interval

    • set up(value: Interval): void

      Parameters

      Returns void

    Methods

    • Create an independent clone of the context useable as a cache of runtime state.

      Returns RootContext

      A RootContext in the same state as this one.

    • Convert the state of this context into a block of text in the SonicWeave DSL.

      Parameters

      • defaults: RootContext

        Root context for determining if the root pitch etc. has changed.

      Returns string

      A string that when evaluated should recreate the same runtime context.

    • Obtain the next free tracking ID and advance the counter.

      Returns number

      An identifier for tracking the evolution of a Interval instance.

    • Update the internal counter when spending computational resources.

      Parameters

      • amount: number = 1

        How many ticks to spend.

      Returns void

      An error if the context runs out of gas.

    • Serialize the context to a JSON compatible object.

      WARNING: Template arguments or "fragile" dependencies are not serialized. A revived context is mainly intended to make stdlib.public functions work without full source code re-evaluation.

      Returns {
          C4: {
              p: number[];
              r: UnsignedFraction;
              t: UnsignedFraction;
              type: string;
          };
          gas: number;
          lift: any;
          mosConfig: | {
              am: | { t: number; type: string; v: string
              | number }
              | { p: number[]; r: UnsignedFraction; t: UnsignedFraction; type: string };
              degrees: {
                  center:
                      | { t: number; type: string; v: string
                      | number }
                      | {
                          p: number[];
                          r: UnsignedFraction;
                          t: UnsignedFraction;
                          type: string;
                      };
                  imperfect: boolean;
                  mid: | { t: number; type: string; v: string
                  | number }
                  | { p: number[]; r: UnsignedFraction; t: UnsignedFraction; type: string }
                  | null;
                  type: string;
              }[];
              equave: | { t: number; type: string; v: string
              | number }
              | { p: number[]; r: UnsignedFraction; t: UnsignedFraction; type: string };
              large:
                  | { t: number; type: string; v: string
                  | number }
                  | { p: number[]; r: UnsignedFraction; t: UnsignedFraction; type: string };
              pattern: string;
              period:
                  | { t: number; type: string; v: string
                  | number }
                  | { p: number[]; r: UnsignedFraction; t: UnsignedFraction; type: string };
              scale: Record<
                  string,
                  | { t: number; type: string; v: string
                  | number }
                  | { p: number[]; r: UnsignedFraction; t: UnsignedFraction; type: string },
              >;
              semiam:
                  | { t: number; type: string; v: string
                  | number }
                  | { p: number[]; r: UnsignedFraction; t: UnsignedFraction; type: string };
              small:
                  | { t: number; type: string; v: string
                  | number }
                  | { p: number[]; r: UnsignedFraction; t: UnsignedFraction; type: string };
              type: string;
          }
          | null;
          title: string;
          trackingIndex: number;
          type: string;
          unisonFrequency: | {
              p: number[];
              r: UnsignedFraction;
              t: UnsignedFraction;
              type: string;
          }
          | null;
          up: any;
      }

      The serialized object with property type set to 'RootContext'.

    • Revive a RootContext instance produced by RootContext.toJSON(). Return everything else as is.

      Intended usage:

      const data = JSON.parse(serializedData, RootContext.reviver);
      

      Parameters

      • key: string

        Property name.

      • value: any

        Property value.

      Returns any

      Deserialized RootContext instance or other data without modifications.