patterns

package
v0.1.0-alpha.74 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 25, 2026 License: GPL-3.0 Imports: 17 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package patterns owns the durable motion pattern and program library, authoring transforms, import/export, and visible preference feedback.

Index

Constants

View Source
const (
	// OriginBuiltin identifies code-generated catalog content.
	OriginBuiltin = "builtin"
	// OriginUser identifies directly authored content.
	OriginUser = "user"
	// OriginGenerated identifies app-generated user content.
	OriginGenerated = "generated"
	// OriginImported identifies finite content imported from a file.
	OriginImported = "imported"

	// PatternFileSchema is the share-file schema for one loop pattern.
	PatternFileSchema = "magichandy.pattern.v1"
	// ProgramFileSchema is the share-file schema for one finite program.
	ProgramFileSchema = "magichandy.program.v1"

	// MaxImportBytes bounds pattern/program upload bodies at the HTTP edge.
	MaxImportBytes = 8 << 20
)

Variables

View Source
var (
	// ErrPatternNotFound reports an unknown pattern identifier.
	ErrPatternNotFound = errors.New("pattern not found")
	// ErrProgramNotFound reports an unknown program identifier.
	ErrProgramNotFound = errors.New("program not found")
	// ErrBuiltinPattern protects built-in content from edit/delete operations.
	ErrBuiltinPattern = errors.New("built-in pattern content is read-only")
	// ErrFeedbackOrder prevents undo from overwriting a newer preference edit.
	ErrFeedbackOrder = errors.New("only the latest feedback for a pattern can be undone")
	// ErrInvalidContent identifies user-authored or imported content that cannot
	// be normalized safely.
	ErrInvalidContent = errors.New("invalid pattern library content")
	// ErrLibraryLimit reports a configured pattern or program capacity limit.
	ErrLibraryLimit = errors.New("pattern library capacity reached")
	// ErrFeedbackNotFound reports an unknown feedback identifier.
	ErrFeedbackNotFound = errors.New("feedback entry not found")
	// ErrFeedbackReverted reports a second undo attempt.
	ErrFeedbackReverted = errors.New("feedback entry is already reverted")
)

Functions

func AuditionDefinition

func AuditionDefinition(definition motion.PatternDefinition, feel string) motion.PatternDefinition

AuditionDefinition applies a temporary backend-owned feel filter. It never mutates the saved pattern and still uses the shared PCHIP sampler.

Types

type CurationChoice

type CurationChoice struct {
	ID          string   `json:"id"`
	Name        string   `json:"name"`
	Description string   `json:"description,omitempty"`
	Tags        []string `json:"tags"`
	Weight      float64  `json:"weight"`
}

CurationChoice is prompt-safe enabled pattern metadata.

type Feedback

type Feedback struct {
	ID            int64   `json:"id"`
	PatternID     string  `json:"pattern_id"`
	Rating        int     `json:"rating"`
	WeightBefore  float64 `json:"weight_before"`
	WeightAfter   float64 `json:"weight_after"`
	EnabledBefore bool    `json:"enabled_before"`
	EnabledAfter  bool    `json:"enabled_after"`
	Reverted      bool    `json:"reverted"`
	CreatedAt     string  `json:"created_at"`
	RevertedAt    string  `json:"reverted_at,omitempty"`
}

Feedback is one visible, reversible preference adjustment.

type ImportResult

type ImportResult struct {
	Kind         string   `json:"kind"`
	Pattern      *Pattern `json:"pattern,omitempty"`
	Program      *Program `json:"program,omitempty"`
	GapsStripped int      `json:"gaps_stripped"`
}

ImportResult distinguishes imported loops from finite programs.

type Library

type Library struct {
	// contains filtered or unexported fields
}

Library owns durable pattern/program rows in the app datastore.

func Open

func Open(dataDir string) (*Library, error)

Open opens the library and seeds code-generated built-ins without replacing user names or feedback-derived weights. Retired built-ins are disabled on upgrade.

func OpenWithDatabase

func OpenWithDatabase(database *dbstore.DB) (*Library, error)

OpenWithDatabase borrows the process-owned datastore for pattern content.

func (*Library) ApplyFeedback

func (l *Library) ApplyFeedback(patternID string, rating int) (Feedback, Pattern, error)

ApplyFeedback records one thumbs adjustment and returns the visible row.

func (*Library) ApplyFeedbackContext

func (l *Library) ApplyFeedbackContext(ctx context.Context, patternID string, rating int) (Feedback, Pattern, error)

ApplyFeedbackContext does not apply a queued adjustment after its caller loses authority or cancels the request.

func (*Library) AutoDisable

func (l *Library) AutoDisable() (bool, error)

AutoDisable reports the explicit opt-in setting.

func (*Library) Close

func (l *Library) Close() error

Close releases the library database handle.

func (*Library) CreatePattern

func (l *Library) CreatePattern(input PatternInput) (Pattern, error)

CreatePattern validates, simplifies, and stores one shareable user pattern.

func (*Library) CreateProgram

func (l *Library) CreateProgram(name, origin string, points []motion.CurvePoint, duration int64) (Program, error)

CreateProgram validates and stores finite motion content.

func (*Library) DeletePattern

func (l *Library) DeletePattern(id string) error

DeletePattern removes user/generated content; built-ins remain available.

func (*Library) DeleteProgram

func (l *Library) DeleteProgram(id string) error

DeleteProgram removes one finite entry.

func (*Library) EnabledChoices

func (l *Library) EnabledChoices() ([]CurationChoice, error)

EnabledChoices returns prompt-safe metadata, weighted preference first.

func (*Library) ExportPattern

func (l *Library) ExportPattern(id string) ([]byte, string, error)

ExportPattern returns one individual shareable pattern file.

func (*Library) ExportProgram

func (l *Library) ExportProgram(id string) ([]byte, string, error)

ExportProgram returns one individual finite program file.

func (*Library) FeedbackHistory

func (l *Library) FeedbackHistory(limit int) ([]Feedback, error)

FeedbackHistory returns newest entries first.

func (*Library) Import

func (l *Library) Import(filename string, data []byte, asKind string) (ImportResult, error)

Import parses a MagicHandy share file or standard funscript.

func (*Library) ListPatterns

func (l *Library) ListPatterns() ([]Pattern, error)

ListPatterns returns built-ins first, then user content by name.

func (*Library) ListPrograms

func (l *Library) ListPrograms() ([]Program, error)

ListPrograms returns finite content by name.

func (*Library) Pattern

func (l *Library) Pattern(id string) (Pattern, error)

Pattern returns one row by ID.

func (*Library) Program

func (l *Library) Program(id string) (Program, error)

Program returns one finite entry by ID.

func (*Library) ResolveEnabled

func (l *Library) ResolveEnabled(id string) (motion.PatternDefinition, bool, error)

ResolveEnabled returns engine content only when the entry remains enabled.

func (*Library) SetAutoDisable

func (l *Library) SetAutoDisable(enabled bool) error

SetAutoDisable updates the opt-in without changing any pattern immediately.

func (*Library) Snapshot

func (l *Library) Snapshot() (Snapshot, error)

Snapshot returns all content plus recent reversible feedback.

func (*Library) Summary

func (l *Library) Summary() (Summary, error)

Summary returns indexed counts for the regular app-state poll.

func (*Library) UndoFeedback

func (l *Library) UndoFeedback(id int64) (Feedback, Pattern, error)

UndoFeedback restores the exact prior weight/enablement when no newer feedback exists for that pattern.

func (*Library) UndoFeedbackContext

func (l *Library) UndoFeedbackContext(ctx context.Context, id int64) (Feedback, Pattern, error)

UndoFeedbackContext keeps the ordering checks and both updates in the same cancelable transaction.

func (*Library) UpdatePattern

func (l *Library) UpdatePattern(id string, patch PatternPatch) (Pattern, error)

UpdatePattern applies visible row controls and names; built-in curves remain immutable.

type Pattern

type Pattern struct {
	ID          string              `json:"id"`
	Name        string              `json:"name"`
	Description string              `json:"description,omitempty"`
	Origin      string              `json:"origin"`
	Kind        string              `json:"kind"`
	Enabled     bool                `json:"enabled"`
	Deprecated  bool                `json:"deprecated,omitempty"`
	Continuous  bool                `json:"continuous,omitempty"`
	Weight      float64             `json:"weight"`
	CycleMillis int64               `json:"cycle_ms"`
	Points      []motion.CurvePoint `json:"points"`
	// PreviewSamples are generated by the backend playback sampler and are not
	// persisted as a second motion representation.
	PreviewSamples []motion.CurvePoint `json:"preview_samples"`
	Tags           []string            `json:"tags"`
	CreatedAt      string              `json:"created_at"`
	UpdatedAt      string              `json:"updated_at"`
}

Pattern is one persisted library entry.

func (Pattern) Definition

func (p Pattern) Definition() motion.PatternDefinition

Definition converts a stored row to engine-owned semantic content.

type PatternInput

type PatternInput struct {
	Name          string              `json:"name"`
	Description   string              `json:"description,omitempty"`
	Kind          string              `json:"kind"`
	CycleMillis   int64               `json:"cycle_ms"`
	Points        []motion.CurvePoint `json:"points"`
	Tags          []string            `json:"tags,omitempty"`
	SimplifyError float64             `json:"simplify_error,omitempty"`
}

PatternInput is authoring/import content before persistence assigns an ID.

type PatternPatch

type PatternPatch struct {
	Name        *string              `json:"name,omitempty"`
	Description *string              `json:"description,omitempty"`
	Kind        *string              `json:"kind,omitempty"`
	Enabled     *bool                `json:"enabled,omitempty"`
	Weight      *float64             `json:"weight,omitempty"`
	CycleMillis *int64               `json:"cycle_ms,omitempty"`
	Points      *[]motion.CurvePoint `json:"points,omitempty"`
	Tags        *[]string            `json:"tags,omitempty"`
}

PatternPatch contains optional row/content changes.

type PreviewResult

type PreviewResult struct {
	Points          []motion.CurvePoint `json:"points"`
	Samples         []motion.CurvePoint `json:"samples"`
	CycleMillis     int64               `json:"cycle_ms"`
	OriginalCount   int                 `json:"original_count"`
	SimplifiedCount int                 `json:"simplified_count"`
}

PreviewResult returns the exact sparse curve and backend sampler output.

func PreviewPattern

func PreviewPattern(input PatternInput) (PreviewResult, error)

PreviewPattern simplifies authored points, closes/floor-stretches the loop, and samples it with the same backend PCHIP implementation used for playback.

type Program

type Program struct {
	ID             string              `json:"id"`
	Name           string              `json:"name"`
	Origin         string              `json:"origin"`
	DurationMillis int64               `json:"duration_ms"`
	Points         []motion.CurvePoint `json:"points"`
	// PreviewSamples are generated by the backend playback sampler and are not
	// persisted as a second motion representation.
	PreviewSamples []motion.CurvePoint `json:"preview_samples"`
	CreatedAt      string              `json:"created_at"`
	UpdatedAt      string              `json:"updated_at"`
}

Program is finite content kept distinct from repeatable patterns.

func (Program) Definition

func (p Program) Definition() motion.ProgramDefinition

Definition converts a stored program to finite engine content.

type Snapshot

type Snapshot struct {
	Patterns    []Pattern  `json:"patterns"`
	Programs    []Program  `json:"programs"`
	Feedback    []Feedback `json:"feedback"`
	AutoDisable bool       `json:"auto_disable"`
}

Snapshot is the backend-authoritative library workspace state.

type Summary

type Summary struct {
	Available           bool `json:"available"`
	PatternCount        int  `json:"pattern_count"`
	EnabledPatternCount int  `json:"enabled_pattern_count"`
	ProgramCount        int  `json:"program_count"`
	AutoDisable         bool `json:"auto_disable"`
}

Summary is the compact polling state; large point arrays stay off /api/state.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL