diff --git a/app_windows.go b/app_windows.go index 6f492c3..0ae1a2e 100644 --- a/app_windows.go +++ b/app_windows.go @@ -107,6 +107,7 @@ type app struct { showAudioMu sync.Mutex showAudioUI *showAudioNative showAudioPresent showAudioPresentState + presFamily362 *demoComposed362 demoOutputGen uint64 presTok PatternToken presGen uint64 // +1 per rendered frame copied into pres (under presMu) @@ -574,7 +575,8 @@ func (a *app) closeProjector() { if a.pl != nil { a.pl.mu.Lock() a.pl.demoRoomStopLocked("projector closed") - a.pl.pumpkinAudioAllowed = false + if d:=a.pl.demoFamily362;d!=nil&&(d.output!=a.proj||d.outputGen!=a.demoOutputGen||!a.projOpen){a.pl.demoFamilyStopLocked362("projector output changed")} + a.pl.pumpkinAudioAllowed = false a.pl.pumpkinSceneVoiceStopLocked() a.pl.mu.Unlock() } @@ -673,7 +675,8 @@ func (a *app) renderFrame() { a.pumpkinUI.mu.Unlock() } a.pl.mu.Lock() - if d := a.pl.demoRoom; d != nil && !d.stopped && d.output != 0 && (d.output != a.proj || d.outputGen != a.demoOutputGen || !a.projOpen) { + if d:=a.pl.demoFamily362;d!=nil&&(d.output!=a.proj||d.outputGen!=a.demoOutputGen||!a.projOpen){a.pl.demoFamilyStopLocked362("projector output changed")} + if d := a.pl.demoRoom; d != nil && !d.stopped && d.output != 0 && (d.output != a.proj || d.outputGen != a.demoOutputGen || !a.projOpen) { a.pl.demoRoomStopLocked("projector output changed") } a.pl.pumpkinAudioAllowed = a.projOpen && !directPumpkin && a.portal338.Load() == nil @@ -775,7 +778,9 @@ func (a *app) renderFrame() { } hoverPres.Store(pub) } - a.presGen++ + a.presFamily362=nil + if !patternDrawn&&!autoDark&&!autoNoProjection&&!calibrationActive()&&!CS.on&&!a.pumpkinManualEditing()&&!directPumpkin&&!pkDirect&&!dpDirect{a.presFamily362=f.family362} + a.presGen++ if u := a.showAudioExisting(); u != nil { if patternDrawn || autoDark || autoNoProjection || calibrationActive() { audioReceipt = showAudioReceipt{SafetyDark: true} @@ -895,6 +900,7 @@ func viewProc(hwnd uintptr, m uint32, w, l uintptr) uintptr { } paintOK = blitted A.queuePlayedEffects(A.presPlayedFX, hwnd == A.proj, blitted) + if hwnd==A.proj&&A.presFamily362!=nil{A.presFamily362.painted(A.proj,A.demoOutputGen,blitted&&!patternLive.Load()&&!calibrationActive(),time.Now())} paintGen = A.presGen tok := A.presTok if u := A.showAudioExisting(); u != nil { diff --git a/common.go b/common.go index 59d4cf5..31fe5b4 100644 --- a/common.go +++ b/common.go @@ -11,7 +11,7 @@ import ( "time" ) -const version = "0.98.361-experimental1" +const version = "0.98.362-experimental1" const appDisplayName = "Projection Mapper - Built by Instinct" diff --git a/demo_family362.go b/demo_family362.go new file mode 100644 index 0000000..e387168 --- /dev/null +++ b/demo_family362.go @@ -0,0 +1,165 @@ +package main + +import ( + "errors" + "fmt" + "math" + "math/rand" +) + +// A family is a selectable library, not an individual preset. Providers must +// supply only locally runnable assignments, with unavailable families explicit. +// This immutable plan is rebuilt from the current mapped room on every Play. +type demoFamily362 struct { + Key, Name, Unavailable string + Choices []demoChoice362 +} +type demoChoice362 struct { + Name, Words string + Assign Assign +} +type demoStep362 struct { + Family, Name, Words string + Assign Assign + StartFrame, EndFrame int + PCM *showAudioPCM +} +type demoPlan362 struct { + Room demoRoomPlan + Steps []demoStep362 + Unavailable []string + Frames int +} + +const demoStepFrames362 = 5 * 44100 + +func demoBuildPlan362(room demoRoomPlan, families []demoFamily362, seed int64, tour int) (demoPlan362, error) { + room.Targets = append([]demoRoomTarget(nil), room.Targets...) + for i := range room.Targets { + room.Targets[i].Poly = append([][2]float64(nil), room.Targets[i].Poly...) + } + p := demoPlan362{Room: room} + if room.Fingerprint == "" || len(room.Targets) == 0 || tour < 0 || tour >= 5 { + return p, errors.New("mapped room and valid tour required") + } + if len(families) > 128 { + return p, errors.New("too many effect families") + } + rng := rand.New(rand.NewSource(seed)) + seen := map[string]bool{} + for _, f := range families { + if f.Key == "" || f.Name == "" || seen[f.Key] { + return p, errors.New("invalid or duplicate family identity") + } + seen[f.Key] = true + if f.Unavailable != "" { + p.Unavailable = append(p.Unavailable, f.Name+": "+f.Unavailable) + continue + } + valid := []demoChoice362{} + for _, c := range f.Choices { + if c.Name != "" && c.Words != "" && c.Assign.Type == "fx" && c.Assign.ID != "" && c.Assign.Inten > 0 && !math.IsNaN(c.Assign.Inten) && !math.IsInf(c.Assign.Inten, 0) { + valid = append(valid, c) + } + } + if len(valid) == 0 { + p.Unavailable = append(p.Unavailable, f.Name+": no runnable local selection") + continue + } + c := valid[rng.Intn(len(valid))] + if c.Assign.Phys != nil { + q := *c.Assign.Phys + q.HX = append([]float64(nil), q.HX...) + c.Assign.Phys = &q + } + p.Steps = append(p.Steps, demoStep362{Family: f.Key, Name: c.Name, Words: c.Words, Assign: c.Assign}) + } + if len(p.Steps) == 0 { + return p, errors.New("no runnable effect families") + } + // A fresh representative/order is chosen per launch. Tour changes ordering, + // not the inventory coverage: every admitted family still appears once. + rng.Shuffle(len(p.Steps), func(i, j int) { p.Steps[i], p.Steps[j] = p.Steps[j], p.Steps[i] }) + for i := range p.Steps { + p.Steps[i].StartFrame = i * demoStepFrames362 + p.Steps[i].EndFrame = (i + 1) * demoStepFrames362 + } + p.Frames = len(p.Steps) * demoStepFrames362 + return p, nil +} +func (p *demoPlan362) stepAt(frame int) (int, bool) { + if p == nil || frame < 0 || frame >= p.Frames { + return 0, false + } + i := frame / demoStepFrames362 + return i, i < len(p.Steps) +} + +// Only measured decoded PCM can be admitted. Never infer duration from words, +// silently truncate speech, change playback rate, or call a successful pipe +// write an audible start. Short narration leaves a silent tail to five seconds. +func (p *demoPlan362) admitVoice(step int, pcm *showAudioPCM) error { + if p == nil || step < 0 || step >= len(p.Steps) || pcm == nil || pcm.Rate != 44100 || pcm.Channels != 2 || len(pcm.Samples) == 0 || len(pcm.Samples)%2 != 0 { + return errors.New("invalid measured narration") + } + if len(pcm.Samples)/2 > demoStepFrames362 { + return fmt.Errorf("narration exceeds five-second slot for %s", p.Steps[step].Name) + } + copyPCM := *pcm + copyPCM.Samples = append([]int16(nil), pcm.Samples...) + p.Steps[step].PCM = ©PCM + return nil +} +func (p *demoPlan362) sampleFrame(frame int) (float64, float64) { + i, ok := p.stepAt(frame) + if !ok { + return 0, 0 + } + s := p.Steps[i] + j := (frame - s.StartFrame) * 2 + if s.PCM == nil || j < 0 || j+1 >= len(s.PCM.Samples) { + return 0, 0 + } + return float64(s.PCM.Samples[j]) / 32768, float64(s.PCM.Samples[j+1]) / 32768 +} + +// Real effect assignments, not the legacy demo wave shader. Invalid IDs are +// rejected rather than silently targeting a different or duplicate outline. +func (p *demoPlan362) sceneAt(frame int) (*Scene, error) { + i, ok := p.stepAt(frame) + if !ok { + return nil, errors.New("outside family timeline") + } + sc := &Scene{ID: fmt.Sprintf("av-family-%d", i), Name: p.Steps[i].Name, Duration: 5, Hold: true, Assign: map[string]Assign{}} + for _, t := range p.Room.Targets { + if t.ID == "" { + return nil, errors.New("family tour requires nonempty mapped outline IDs") + } + if _, dup := sc.Assign[t.ID]; dup { + return nil, errors.New("family tour requires unique mapped outline IDs") + } + sc.Assign[t.ID] = p.Steps[i].Assign + } + if len(sc.Assign) == 0 { + return nil, errors.New("no receiving outlines") + } + return sc, nil +} + +func demoRoomFamilies362(room demoRoomPlan, families []demoFamily362) []demoFamily362 { + out := append([]demoFamily362(nil), families...) + hasObject := false + for _, target := range room.Targets { + if target.Role != "wall" && target.Role != "floor" && target.Role != "ceiling" { + hasObject = true + } + } + if !hasObject { + for i := range out { + if out[i].Key == "Opus Effects" { + out[i].Unavailable = "requires a mapped object in this tour adapter" + } + } + } + return out +} diff --git a/demo_family362_test.go b/demo_family362_test.go new file mode 100644 index 0000000..d161659 --- /dev/null +++ b/demo_family362_test.go @@ -0,0 +1,350 @@ +package main + +import ( + "fmt" + "image" + "image/color" + "image/png" + "os" + "path/filepath" + "reflect" + "testing" + "time" +) + +func familyFixture362() []demoFamily362 { + return []demoFamily362{{Key: "ag", Name: "Anti-Gravity", Choices: []demoChoice362{{Name: "Basalt", Words: "Basalt ember seams.", Assign: Assign{Type: "fx", ID: "ag100-mat-obsidian", Inten: 1}}, {Name: "Nacre", Words: "Iridescent nacre.", Assign: Assign{Type: "fx", ID: "ag100-mat-pearl", Inten: 1}}}}, {Key: "xmas", Name: "Christmas", Choices: []demoChoice362{{Name: "Lights", Words: "Christmas lights.", Assign: Assign{Type: "fx", ID: "xmas:lights", Inten: 1}}}}, {Key: "live", Name: "Live camera", Unavailable: "no current segmentation"}} +} +func Test362FamilyPlanCoverageFreshAndExactSlots(t *testing.T) { + room := demoRoomPlan{Fingerprint: "synthetic", Targets: []demoRoomTarget{{ID: "wall"}}} + a, e := demoBuildPlan362(room, familyFixture362(), 1, 0) + if e != nil { + t.Fatal(e) + } + if len(a.Steps) != 2 || len(a.Unavailable) != 1 || a.Frames != 441000 { + t.Fatal("coverage", a) + } + seen := map[string]bool{} + for _, s := range a.Steps { + if seen[s.Family] { + t.Fatal("repeated family") + } + seen[s.Family] = true + } + for _, f := range []int{-1, a.Frames} { + if _, ok := a.stepAt(f); ok { + t.Fatal("out of timeline") + } + } + for f, want := range map[int]int{0: 0, 220499: 0, 220500: 1, 440999: 1} { + i, ok := a.stepAt(f) + if !ok || i != want { + t.Fatal("boundary", f) + } + } + different := false + for seed := int64(2); seed < 12; seed++ { + b, e := demoBuildPlan362(room, familyFixture362(), seed, 0) + if e != nil { + t.Fatal(e) + } + if !reflect.DeepEqual(a.Steps, b.Steps) { + different = true + } + } + if !different { + t.Fatal("same show every launch") + } +} +func Test362MeasuredVoiceNoTruncationOrBoundaryLeak(t *testing.T) { + p := demoPlan362{Frames: demoStepFrames362 * 2, Steps: []demoStep362{{StartFrame: 0, EndFrame: demoStepFrames362}, {StartFrame: demoStepFrames362, EndFrame: demoStepFrames362 * 2}}} + pcm := &showAudioPCM{Rate: 44100, Channels: 2, Samples: []int16{32767, -32768, 100, 200}} + if e := p.admitVoice(0, pcm); e != nil { + t.Fatal(e) + } + pcm.Samples[0] = 0 + l, r := p.sampleFrame(0) + if l < .99 || r != -1 { + t.Fatal("mutated audio", l, r) + } + for _, f := range []int{-1, 2, demoStepFrames362 - 1, demoStepFrames362, p.Frames} { + l, r := p.sampleFrame(f) + if l != 0 || r != 0 { + t.Fatal("tail/boundary leaked", f) + } + } + long := &showAudioPCM{Rate: 44100, Channels: 2, Samples: make([]int16, (demoStepFrames362+1)*2)} + if p.admitVoice(1, long) == nil { + t.Fatal("truncated long voice") + } +} +func Test362ActualAssignmentSceneMasksAndSnapshot(t *testing.T) { + p := roomTestProject(128, 80) + poly := [][2]float64{{.1, .1}, {.9, .1}, {.9, .9}, {.55, .9}, {.55, .6}, {.1, .6}} + p.Surfaces = []Surface{{ID: "wall", Cls: "wall", Poly: poly, Quad: polyBox(poly)}} + room, e := demoRoomPlanForProject(p) + if e != nil { + t.Fatal(e) + } + plan, e := demoBuildPlan362(room, familyFixture362(), 7, 0) + if e != nil { + t.Fatal(e) + } + room.Targets[0].Poly[0] = [2]float64{0, 0} + if plan.Room.Targets[0].Poly[0] == room.Targets[0].Poly[0] { + t.Fatal("mutable room snapshot") + } + r := newRenderer(p, "") + defer r.closeVideoResources() + r.exportVirtual = true + for i, s := range plan.Steps { + sc, e := plan.sceneAt(i * demoStepFrames362) + if e != nil { + t.Fatal(e) + } + if sc.Assign["wall"].ID != s.Assign.ID { + t.Fatal("not actual effect") + } + f := newFrame(128, 80) + for tick := 0; tick <= 10; tick++ { + r.RenderScene(sc, float64(tick)/5, f, 1, time.Time{}) + } + lit := 0 + for y := 0; y < 80; y++ { + for x := 0; x < 128; x++ { + o := (y*128 + x) * 4 + if f.Pix[o]|f.Pix[o+1]|f.Pix[o+2] != 0 { + lit++ + if !pointInPolyXY((float64(x)+.5)/128, (float64(y)+.5)/80, poly) { + t.Fatal("outside exact mask") + } + } + } + } + if lit == 0 { + t.Fatal("blank actual effect", s.Assign.ID) + } + } +} +func Test362RawVoiceFormatAndBounds(t *testing.T) { + p, e := demoDecodeRawNarration362([]byte{255, 127, 0, 128}) + if e != nil || p.Rate != 44100 || p.Channels != 2 || p.Samples[0] != 32767 || p.Samples[1] != -32768 { + t.Fatal("PCM parse", e) + } + for _, b := range [][]byte{nil, {1, 2, 3}, {1, 2, 3, 4, 5}} { + if _, e = demoDecodeRawNarration362(b); e == nil { + t.Fatal("bad PCM accepted") + } + } +} +func Test362BoundaryBarrierAndRefusedQueueCursor(t *testing.T) { + now := time.Unix(100, 0) + p := &demoPlan362{Frames: demoStepFrames362 * 2, Steps: []demoStep362{{StartFrame: 0, EndFrame: demoStepFrames362}, {StartFrame: demoStepFrames362, EndFrame: demoStepFrames362 * 2}}} + tr := demoTransport362{Plan: p, Generation: 1} + if b, _ := tr.nextBlock(now); b != nil { + t.Fatal("audio without painted effect") + } + if e := tr.paint(0, 1, now, now); e != nil { + t.Fatal(e) + } + for n := 0; n < 250; n++ { + a, e := tr.nextBlock(now) + if e != nil || len(a) != 1764 { + t.Fatal("block", n, e) + } + b, _ := tr.nextBlock(now) + if !reflect.DeepEqual(a, b) || tr.Queued != n*882 { + t.Fatal("refused write advanced") + } + if e = tr.committed(); e != nil { + t.Fatal(e) + } + } + if b, _ := tr.nextBlock(now); b != nil { + t.Fatal("next chapter prequeued") + } + boundary, e := tr.consumed(demoStepFrames362) + if e != nil || !boundary || tr.Step != 1 || tr.Armed { + t.Fatal("bad barrier") + } + if b, _ := tr.nextBlock(now); b != nil { + t.Fatal("next speech before next paint") + } + if tr.paint(0, 1, now, now) == nil { + t.Fatal("old image arms next audio") + } + if e = tr.paint(1, 2, now, now); e != nil { + t.Fatal(e) + } + if b, e := tr.nextBlock(now); e != nil || len(b) != 1764 { + t.Fatal("next image did not arm audio") + } +} +func Test362PlayerOwnershipFreshMappingAndStop(t *testing.T) { + p := roomTestProject(128, 80) + p.Surfaces = []Surface{{ID: "wall", Cls: "wall", Poly: [][2]float64{{.1, .1}, {.9, .1}, {.9, .9}, {.1, .9}}}} + room, e := demoRoomPlanForProject(p) + if e != nil { + t.Fatal(e) + } + plan, e := demoBuildPlan362(room, familyFixture362(), 1, 0) + if e != nil { + t.Fatal(e) + } + for i := range plan.Steps { + if e = plan.admitVoice(i, &showAudioPCM{Rate: 44100, Channels: 2, Samples: []int16{1, 2}}); e != nil { + t.Fatal(e) + } + } + pl := newPlayer(p, "") + defer pl.R.closeVideoResources() + d, e := newDemoFamilyPlayback362(p, pl.R, &plan, 1, 1) + if e != nil { + t.Fatal(e) + } + pl.demoFamily362 = d + pl.f1 = newFrame(128, 80) + if !pl.demoFamilyRenderLocked362(time.Now()) || pl.f1.family362 == nil { + t.Fatal("not actual family frame") + } + c := pl.f1.family362 + c.painted(1, 1, true, time.Now()) + d.runtime.mu.Lock() + armed := d.runtime.tr.Armed + d.runtime.mu.Unlock() + if !armed { + t.Fatal("actual frame not armed") + } + p.Surfaces[0].Poly[0][0] = .2 + if !pl.demoFamilyRenderLocked362(time.Now()) { + t.Fatal("map change not handled") + } + d.runtime.mu.Lock() + stopped := d.runtime.tr.Stopped + d.runtime.mu.Unlock() + if !stopped { + t.Fatal("mutable map retained") + } + pl.R.SetScenePreviewOwned("foreign", map[string]Assign{"wall": {Type: "fx", ID: "fire", Inten: 1}}) + pl.demoFamilyStopLocked362("old stop") + if pl.R.ScenePreviewOwner() != "foreign" { + t.Fatal("old stop cleared new owner") + } +} +func Test362PaintBarrierRejectsForeignGenerationAndStaleOutput(t *testing.T) { + now := time.Unix(200, 0) + r := &demoFamilyRuntime362{tr: demoTransport362{Plan: &demoPlan362{Steps: []demoStep362{{}}}, Generation: 2}, stop: make(chan struct{})} + c := demoComposed362{Runtime: r, Step: 0, Generation: 1, Composed: now, Output: 8, OutputGen: 5} + c.painted(8, 5, true, now) + if r.tr.Armed { + t.Fatal("stale generation armed") + } + c.Generation = 2 + c.painted(8, 5, true, now) + if !r.tr.Armed { + t.Fatal("fresh exact image not armed") + } + c.painted(8, 6, true, now) + if !r.tr.Stopped { + t.Fatal("rebound output accepted") + } +} +func Test362InventoryRealRenderEveryAdmittedChoice(t *testing.T) { + p := roomTestProject(128, 80) + poly := [][2]float64{{.1, .1}, {.9, .1}, {.9, .9}, {.55, .9}, {.55, .6}, {.1, .6}} + p.Surfaces = []Surface{{ID: "wall", Cls: "wall", Poly: poly, Quad: polyBox(poly)}, {ID: "object", Cls: "chair", Poly: [][2]float64{{.3, .3}, {.5, .3}, {.5, .5}, {.3, .5}}, Quad: [][2]float64{{.3, .3}, {.5, .3}, {.5, .5}, {.3, .5}}}} + r := newRenderer(p, "") + defer r.closeVideoResources() + r.exportVirtual = true + for _, fam := range demoCandidates362() { + for _, c := range fam.Choices { + sc := &Scene{ID: fam.Key + c.Name, Assign: map[string]Assign{"wall": c.Assign}} + f := newFrame(128, 80) + for tick := 0; tick <= 10; tick++ { + r.RenderScene(sc, float64(tick)/5, f, 1, time.Time{}) + } + lit := 0 + for y := 0; y < 80; y++ { + for x := 0; x < 128; x++ { + o := (y*128 + x) * 4 + if f.Pix[o]|f.Pix[o+1]|f.Pix[o+2] != 0 { + lit++ + if !pointInPolyXY((float64(x)+.5)/128, (float64(y)+.5)/80, poly) { + t.Fatal("outside", fam.Key, c.Name, x, y) + } + } + } + } + if lit < 5 { + t.Error("unqualified blank", fam.Key, c.Name, c.Assign.ID) + } + t.Log(fam.Key, c.Name, "lit", lit) + if dir := os.Getenv("PM362_PIXELS"); dir != "" { + im := image.NewRGBA(image.Rect(0, 0, f.W, f.H)) + for y := 0; y < f.H; y++ { + for x := 0; x < f.W; x++ { + o := (y*f.W + x) * 4 + im.SetRGBA(x, y, color.RGBA{f.Pix[o+2], f.Pix[o+1], f.Pix[o], 255}) + } + } + file, err := os.Create(filepath.Join(dir, fmt.Sprintf("%s-%d.png", fam.Key, choiceIndex362(fam.Choices, c.Assign.ID, c.Name)))) + if err != nil { + t.Fatal(err) + } + if err = png.Encode(file, im); err != nil { + t.Fatal(err) + } + file.Close() + } + + } + } +} + +func choiceIndex362(cs []demoChoice362, id, name string) int { + for i, c := range cs { + if c.Assign.ID == id && c.Name == name { + return i + } + } + return -1 +} + +func Test362ObjectFamilyNeedsMappedObject(t *testing.T) { + fs := demoCandidates362() + room := demoRoomPlan{Targets: []demoRoomTarget{{Role: "wall"}}} + for _, f := range demoRoomFamilies362(room, fs) { + if f.Key == "Opus Effects" && f.Unavailable == "" { + t.Fatal("object workflow admitted without object") + } + } + room.Targets = append(room.Targets, demoRoomTarget{Role: "seat"}) + for _, f := range demoRoomFamilies362(room, fs) { + if f.Key == "Opus Effects" && f.Unavailable != "" { + t.Fatal("mapped object rejected") + } + } +} + +func Test362ActiveTransportClockAndStalePaintFailClosed(t *testing.T) { + now := time.Unix(100, 0) + p := &demoPlan362{Steps: []demoStep362{{}}} + tr := demoTransport362{Plan: p, Generation: 1} + if e := tr.paint(0, 1, now, now); e != nil { + t.Fatal(e) + } + if _, e := tr.consumed(0); e != nil || tr.Consumed != 0 { + t.Fatal("wall time must not advance samples") + } + if _, e := tr.nextBlock(now.Add(251 * time.Millisecond)); e == nil || !tr.Stopped { + t.Fatal("stale paint accepted") + } + tr = demoTransport362{Plan: p, Generation: 1, Armed: true, Queued: 882, Consumed: 500} + if _, e := tr.consumed(499); e == nil || !tr.Stopped { + t.Fatal("backward clock accepted") + } + tr = demoTransport362{Plan: p, Generation: 1, Armed: true, Queued: 882} + if _, e := tr.consumed(883); e == nil || !tr.Stopped { + t.Fatal("unwritten clock accepted") + } +} diff --git a/demo_family362_windows.go b/demo_family362_windows.go new file mode 100644 index 0000000..93f97b3 --- /dev/null +++ b/demo_family362_windows.go @@ -0,0 +1,21 @@ +//go:build windows + +package main + +func (a *app) demoFamilies362() []demoFamily362 { + out := demoCandidates362() + covered := map[int]bool{7: true, ag100PageIdx: true, xmasPageIdx: true, antidemoPageIdx: true, carbonPageIdx: true, chimeraPageIdx: true, antidotPageIdx: true, roomFiltersPageIdx: true, antiRustPageIdx: true, physPageIdx: true, hxPageIdx: true, ixPageIdx: true, ofxPageIdx: true, objiqPageIdx: true, agPageIdx: true} + seen := map[int]bool{} + for _, page := range append([]int{7}, catalogPages326()...) { + if page < 0 || page >= len(pageNames) || seen[page] || !navInOrder(page) { + continue + } + seen[page] = true + if covered[page] { + continue + } + name := pageNames[page] + out = append(out, demoFamily362{Key: name, Name: name, Unavailable: "no qualified tour adapter; use this library's own controls"}) + } + return out +} diff --git a/demo_family362_windows_test.go b/demo_family362_windows_test.go new file mode 100644 index 0000000..ebdfe6a --- /dev/null +++ b/demo_family362_windows_test.go @@ -0,0 +1,42 @@ +//go:build windows + +package main + +import ( + "strings" + "testing" +) + +func Test362NativeCatalogFamilyInventory(t *testing.T) { + a := &app{} + families := a.demoFamilies362() + if len(families) < 10 { + t.Fatal("inventory incomplete", len(families)) + } + seen := map[string]bool{} + runnable := 0 + for _, f := range families { + if seen[f.Key] || f.Name == "" { + t.Fatal("family identity") + } + seen[f.Key] = true + if f.Unavailable != "" { + continue + } + runnable++ + if len(f.Choices) == 0 { + t.Fatal("empty admitted family", f.Name) + } + for _, c := range f.Choices { + if c.Assign.Type != "fx" || c.Assign.ID == "" || c.Assign.Inten <= 0 || c.Words == "" || releaseHiddenPhysID(c.Assign.ID) || strings.HasPrefix(c.Assign.ID, "demo-") { + t.Fatal("invalid family choice", f.Name, c.Name) + } + if !fxKnown(c.Assign.ID) { + t.Fatal("unknown actual assignment", c.Assign.ID) + } + } + } + if runnable != 15 { + t.Fatal("too few admitted libraries", runnable) + } +} diff --git a/demo_family_audio362_windows.go b/demo_family_audio362_windows.go new file mode 100644 index 0000000..0dcadf1 --- /dev/null +++ b/demo_family_audio362_windows.go @@ -0,0 +1,135 @@ +//go:build windows + +package main + +import "time" + +func demoRunAudio362(r *demoFamilyRuntime362) { + defer close(r.done) + var dev *showAudioDevice + defer func() { + if dev != nil { + _ = dev.close() + } + }() + stop := func(reason string) { + if dev != nil { + _ = dev.reset() + } + r.halt(reason) + } + ticker := time.NewTicker(10 * time.Millisecond) + defer ticker.Stop() + step := -1 + waitingSince := time.Now() + lastPosition := uint64(0) + progressedAt := time.Now() + for { + select { + case <-r.stop: + if dev != nil { + _ = dev.reset() + } + return + case now := <-ticker.C: + r.mu.Lock() + if r.tr.Stopped { + r.mu.Unlock() + stop("tour complete or stopped") + return + } + armed := r.tr.Armed + current := r.tr.Step + r.mu.Unlock() + if !armed { + if now.Sub(waitingSince) > 5*time.Second { + stop("next effect was not presented within five seconds") + return + } + continue + } + if dev == nil { + var e error + dev, e = newShowAudioDeviceSlots(3) + if e != nil { + stop("audio device open failed: " + e.Error()) + return + } + } + if current != step { + if e := dev.reset(); e != nil { + stop(e.Error()) + return + } + step = current + lastPosition = 0 + progressedAt = now + } + pos, e := dev.consumedFrames362() + if e != nil { + stop(e.Error()) + return + } + if pos != lastPosition { + lastPosition = pos + progressedAt = now + } else if now.Sub(progressedAt) > 2*time.Second { + stop("audio sample clock stalled") + return + } + r.mu.Lock() + boundary, e := r.tr.consumed(int(pos)) + r.mu.Unlock() + if e != nil { + stop(e.Error()) + return + } + if boundary { + waitingSince = now + continue + } + // Bounded fill, three 20ms slots maximum. A full device leaves cursor + // unchanged; next tick retries the exact same samples. + for n := 0; n < 3; n++ { + r.mu.Lock() + b, e := r.tr.nextBlock(now) + r.mu.Unlock() + if e != nil { + stop(e.Error()) + return + } + if b == nil { + break + } + vol := float64(demoShowcaseAudioVol.Load()) / 100 + if vol < 0 { + vol = 0 + } + if vol > 1 { + vol = 1 + } + for i := range b { + b[i] = int16(float64(b[i]) * vol) + } + r.mu.Lock() + if r.tr.Stopped { + r.mu.Unlock() + stop("tour revoked") + return + } + ok, e := dev.write(b) + if e == nil && ok { + e = r.tr.committed() + } + r.mu.Unlock() + if e == nil && !ok { + break + } + if e != nil { + stop(e.Error()) + return + } + } + } + } +} diff --git a/demo_family_device362_windows.go b/demo_family_device362_windows.go new file mode 100644 index 0000000..949850c --- /dev/null +++ b/demo_family_device362_windows.go @@ -0,0 +1,43 @@ +//go:build windows + +package main + +import ( + "errors" + "runtime" + "unsafe" +) + +var demoWavePosition362 = showAudioDLL.NewProc("waveOutGetPosition") + +type demoMMTime362 struct { + Kind uint32 + Value uint32 + Rest uint32 +} + +// Use a separate optional interface so existing audio backends/tests retain +// their contract. A device without a supported sample clock cannot run a +// synchronized family tour, and must report unavailable rather than estimate. +func (d *showAudioDevice) consumedFrames362() (uint64, error) { + if d == nil || d.handle == 0 || d.broken { + return 0, errors.New("family audio device unavailable") + } + m := demoMMTime362{Kind: 2} + rc, _, _ := demoWavePosition362.Call(d.handle, uintptr(unsafe.Pointer(&m)), unsafe.Sizeof(m)) + runtime.KeepAlive(d) + if rc != 0 { + return 0, showAudioMMError("waveOutGetPosition", rc) + } + switch m.Kind { + case 2: + return uint64(m.Value), nil + case 4: + if m.Value%4 != 0 { + return 0, errors.New("unaligned device byte clock") + } + return uint64(m.Value / 4), nil + default: + return 0, errors.New("device did not provide a sample-accurate clock") + } +} diff --git a/demo_family_inventory362.go b/demo_family_inventory362.go new file mode 100644 index 0000000..622c22e --- /dev/null +++ b/demo_family_inventory362.go @@ -0,0 +1,134 @@ +package main + +// Only inspected local assignment adapters enter this inventory. Each remains +// the real library ID; selected examples can expand after pixel qualification. +func demoCandidates362() []demoFamily362 { + out := []demoFamily362{} + add := func(key, name string, choices []demoChoice362) { + out = append(out, demoFamily362{Key: key, Name: name, Choices: choices}) + } + raw := func(id, name string) demoChoice362 { + return demoChoice362{Name: name, Words: name + ", an animated effect.", Assign: Assign{Type: "fx", ID: id, C1: "#ffffff", C2: "#3ddc97", Scale: 1, Speed: 1, Inten: 1, DepthRelief: true}} + } + phys := func(id, name string) demoChoice362 { + c := raw(id, name) + c.Assign.Phys = &PhysParams{Shared: true} + return c + } + add("Effects", "Effects", []demoChoice362{raw("m-fire", "Fire"), raw("m-droplets", "Rain on glass")}) + choices := []demoChoice362{} + for _, i := range []int{2, 5, 17, 30, 61, 80} { + e := agSpec361(i) + choices = append(choices, raw(e.ID, e.Name)) + } + add("Anti-Gravity Effects", "Anti-Gravity Effects", choices) + choices = nil + for _, i := range []int{0, 3, 7, 12} { + es := GetXmasEffects() + if i < len(es) { + e := es[i] + choices = append(choices, raw(e.ID, e.Name)) + } + } + add("Christmas", "Christmas", choices) + choices = nil + for _, i := range []int{1, 2, 9, 30} { + e := antidemoSpec360(i) + c := phys("phys:antidemo", e.Name) + c.Assign.Phys.HX = []float64{float64(i)} + choices = append(choices, c) + } + add("Antidemo", "Antidemo", choices) + choices = nil + for _, i := range []int{0, 1} { + if i < len(CarbonEffects) { + e := CarbonEffects[i] + choices = append(choices, raw(e.ID, e.Name)) + } + } + add("Carbon", "Carbon", choices) + choices = nil + for _, i := range []int{0, 1} { + if i < len(ChimeraEffects) { + e := ChimeraEffects[i] + choices = append(choices, raw(e.ID, e.Name)) + } + } + add("Chimera", "Chimera", choices) + choices = nil + for _, i := range []int{0, 1} { + if i < len(AntidotEffects20) { + e := AntidotEffects20[i] + choices = append(choices, raw(e.ID, e.Name)) + } + } + add("Antidot Effects", "Antidot Effects", choices) + choices = nil + for _, i := range []int{0, 1} { + if i < len(roomFilterSpecs) { + e := roomFilterSpecs[i] + c := phys("phys:roomfilter", e.Name) + c.Assign.Phys.HX = []float64{float64(i), 1, 0} + choices = append(choices, c) + } + } + add("Room Filters", "Room Filters", choices) + choices = nil + for _, i := range []int{0, 1} { + if i < len(antiCurated340) { + e := antiCurated340[i] + choices = append(choices, demoChoice362{Name: e.Name, Words: e.Name + ", an animated illustration.", Assign: antiCuratedAssign340(i)}) + } + } + add("Anti Effects", "Anti Effects", choices) + + choices = nil + for _, id := range []string{"phys:fireflies", "phys:embers"} { + if e, ok := physKindOf(id); ok { + choices = append(choices, phys(e.id, e.name)) + } + } + add("Physics", "Physics", choices) + choices = nil + for _, i := range []int{0, 1} { + if i < len(hxEffects) { + e := hxEffects[i] + choices = append(choices, phys(e.ID, e.Name)) + } + } + add("Hark Excitement", "Hark Excitement", choices) + choices = nil + for _, i := range []int{0, 1} { + if i < len(ixEffects) { + e := ixEffects[i] + choices = append(choices, phys(e.ID, e.Name)) + } + } + add("Instinct Extreme", "Instinct Extreme", choices) + choices = nil + for _, i := range []int{0, 1} { + if i < len(ofxEffects) { + e := ofxEffects[i] + choices = append(choices, phys(e.ID, e.Name)) + } + } + add("Opus Effects", "Opus Effects", choices) + choices = nil + for _, i := range []int{0, 1} { + if i < len(objiqEffects) { + e := objiqEffects[i] + choices = append(choices, phys(e.ID, e.Name)) + } + } + add("Object IQ", "Object IQ", choices) + choices = nil + for _, i := range []int{0, 1} { + es := GetAgEffects() + if i < len(es) { + e := es[i] + choices = append(choices, raw(e.ID, e.Name)) + } + } + add("Antigravity Gemini", "Antigravity Gemini", choices) + return out +} diff --git a/demo_family_player362.go b/demo_family_player362.go new file mode 100644 index 0000000..0ba5b20 --- /dev/null +++ b/demo_family_player362.go @@ -0,0 +1,163 @@ +package main + +import ( + "fmt" + "sync" + "time" +) + +const demoFamilyOwner362 = "demo-av-families" + +type demoFamilyRuntime362 struct { + mu sync.Mutex + tr demoTransport362 + reason string + stop chan struct{} + done chan struct{} + once sync.Once +} + +func (r *demoFamilyRuntime362) halt(reason string) { + if r == nil { + return + } + r.mu.Lock() + r.tr.Stopped = true + if r.reason == "" { + r.reason = reason + } + r.mu.Unlock() + r.once.Do(func() { close(r.stop) }) +} + +type demoFamilyPlayback362 struct { + runtime *demoFamilyRuntime362 + plan *demoPlan362 + project *Project + renderer *Renderer + previewGen uint64 + output uintptr + outputGen uint64 + scene *Scene + step int +} +type demoComposed362 struct { + Runtime *demoFamilyRuntime362 + Step int + Generation uint64 + Composed time.Time + Output uintptr + OutputGen uint64 +} + +func (c *demoComposed362) painted(output uintptr, outputGen uint64, ok bool, now time.Time) { + if c == nil || c.Runtime == nil { + return + } + r := c.Runtime + r.mu.Lock() + defer r.mu.Unlock() + if !ok || output != c.Output || outputGen != c.OutputGen || now.Before(c.Composed) || now.Sub(c.Composed) > 250*time.Millisecond { + r.tr.Stopped = true + r.reason = "projector presentation unavailable" + return + } + _ = r.tr.paint(c.Step, c.Generation, now, now) +} +func (pl *Player) demoFamilyStopLocked362(reason string) { + d := pl.demoFamily362 + if d == nil { + return + } + d.runtime.halt(reason) + if pl.R == d.renderer && pl.R.ScenePreviewOwner() == demoFamilyOwner362 && pl.R.scenePreviewGen.Load() == d.previewGen { + pl.R.SetScenePreviewOwned(demoFamilyOwner362, nil) + } +} +func (pl *Player) demoFamilyRenderLocked362(now time.Time) bool { + d := pl.demoFamily362 + if d == nil { + return false + } + r := d.runtime + r.mu.Lock() + stopped := r.tr.Stopped + reason := r.reason + frame, step, gen := r.tr.frame(), r.tr.Step, r.tr.Generation + r.mu.Unlock() + if stopped { + pl.demoFamilyStopLocked362(reason) + return false + } + bad := "" + switch { + case pl.P != d.project || pl.R != d.renderer: + bad = "project changed" + case pl.virtual || pl.exportOwned: + bad = "virtual/export output" + case pl.paused || pl.blackout || pl.calibrationPaused || pl.pumpkinAutoDark: + bad = "tour paused or dark" + case pl.manualPumpkin != nil || pl.pumpkin != nil || pl.door != nil: + bad = "another show owns output" + case pl.R.ScenePreviewOwner() != demoFamilyOwner362 || pl.R.scenePreviewGen.Load() != d.previewGen: + bad = "another preview owns output" + case pl.R.FocusID() != "" || pl.R.FocusAnimID() != "": + bad = "focus owns output" + } + if bad == "" { + room, e := demoRoomPlanForProject(pl.P) + if e != nil || room.Fingerprint != d.plan.Room.Fingerprint { + bad = "mapped room changed" + } + } + if bad != "" { + pl.demoFamilyStopLocked362(bad) + clear(pl.f1.Pix) + return true + } + if step >= len(d.plan.Steps) { + pl.demoFamilyStopLocked362("tour complete") + clear(pl.f1.Pix) + return true + } + if d.scene == nil || d.step != step { + sc, e := d.plan.sceneAt(step * demoStepFrames362) + if e != nil { + pl.demoFamilyStopLocked362(e.Error()) + clear(pl.f1.Pix) + return true + } + d.scene = sc + d.step = step + pl.R.SetScenePreviewOwned(demoFamilyOwner362, sc.Assign) + d.previewGen = pl.R.scenePreviewGen.Load() + } + sec := float64(frame-step*demoStepFrames362) / 44100 + pl.lastClockT = sec + pl.clockAt = clockNow() + pl.clockSet = true + pl.R.noEndFade = true + pl.R.exportVirtual = false + // A zero external clock makes stateful effects follow consumed audio time, + // while exportVirtual stays false so supported live inputs remain enabled. + pl.R.RenderScene(d.scene, sec, pl.f1, 1, time.Time{}) + pl.f1.family362 = &demoComposed362{Runtime: r, Step: step, Generation: gen, Composed: now, Output: d.output, OutputGen: d.outputGen} + return true +} +func newDemoFamilyPlayback362(p *Project, r *Renderer, plan *demoPlan362, output uintptr, outputGen uint64) (*demoFamilyPlayback362, error) { + if p == nil || r == nil || plan == nil || output == 0 { + return nil, fmt.Errorf("mapped project and projector required") + } + for i := range plan.Steps { + if plan.Steps[i].PCM == nil { + return nil, fmt.Errorf("narration not measured for %s", plan.Steps[i].Name) + } + } + sc, e := plan.sceneAt(0) + if e != nil { + return nil, e + } + r.SetScenePreviewOwned(demoFamilyOwner362, sc.Assign) + rt := &demoFamilyRuntime362{tr: demoTransport362{Plan: plan, Generation: 1}, stop: make(chan struct{}), done: make(chan struct{})} + return &demoFamilyPlayback362{runtime: rt, plan: plan, project: p, renderer: r, output: output, outputGen: outputGen, scene: sc, step: 0, previewGen: r.scenePreviewGen.Load()}, nil +} diff --git a/demo_family_transport362.go b/demo_family_transport362.go new file mode 100644 index 0000000..cda431c --- /dev/null +++ b/demo_family_transport362.go @@ -0,0 +1,95 @@ +package main + +import ( + "errors" + "time" +) + +// A step boundary is a presentation barrier. The queue never contains the +// next step's speech until that step's first image has been painted. This +// avoids playing a new effect's name while the last image is still on screen. +// The device must drain exactly five seconds, reset, then wait for the next +// image. A long render/presentation stall causes silence, never speech drift. +type demoTransport362 struct { + Plan *demoPlan362 + Step, Consumed, Queued int + Generation uint64 + Armed, Stopped bool + LastPaint time.Time +} + +func (t *demoTransport362) frame() int { + if t == nil { + return 0 + } + return t.Step*demoStepFrames362 + t.Consumed +} +func (t *demoTransport362) paint(step int, generation uint64, at, now time.Time) error { + if t == nil || t.Stopped || t.Plan == nil { + return errors.New("family transport stopped") + } + if step != t.Step || generation != t.Generation || at.IsZero() || now.Before(at) || now.Sub(at) > 250*time.Millisecond { + return errors.New("stale or foreign family paint") + } + t.LastPaint = at + t.Armed = true + return nil +} +func (t *demoTransport362) nextBlock(now time.Time) ([]int16, error) { + if t == nil || t.Stopped || t.Plan == nil || t.Step >= len(t.Plan.Steps) { + return nil, errors.New("family transport stopped") + } + if !t.Armed { + return nil, nil + } + if now.Before(t.LastPaint) || now.Sub(t.LastPaint) > 250*time.Millisecond { + t.Stopped = true + return nil, errors.New("family output stalled") + } + if t.Queued >= demoStepFrames362 { + return nil, nil + } + n := showAudioDeviceFrames + if demoStepFrames362-t.Queued < n { + n = demoStepFrames362 - t.Queued + } + b := make([]int16, showAudioDeviceFrames*2) + for f := 0; f < n; f++ { + l, r := t.Plan.sampleFrame(t.Step*demoStepFrames362 + t.Queued + f) + b[f*2] = int16(l * 32768) + b[f*2+1] = int16(r * 32768) + } + return b, nil +} + +// A refused queue write changes no cursor. Exactly 250 20ms blocks fit a +// five-second step. We do not prefill or skip any narration samples. +func (t *demoTransport362) committed() error { + if t == nil || !t.Armed || t.Stopped || t.Queued+showAudioDeviceFrames > demoStepFrames362 { + return errors.New("invalid family queue commit") + } + t.Queued += showAudioDeviceFrames + return nil +} +func (t *demoTransport362) consumed(frames int) (boundary bool, err error) { + if t == nil || t.Stopped || !t.Armed || frames < t.Consumed || frames > t.Queued { + if t != nil { + t.Stopped = true + } + return false, errors.New("invalid consumed sample clock") + } + t.Consumed = frames + if frames < demoStepFrames362 { + return false, nil + } + t.Step++ + t.Consumed = 0 + t.Queued = 0 + t.Armed = false + t.LastPaint = time.Time{} + t.Generation++ + if t.Plan == nil || t.Step >= len(t.Plan.Steps) { + t.Stopped = true + } + return true, nil +} diff --git a/demo_family_ui362_windows.go b/demo_family_ui362_windows.go new file mode 100644 index 0000000..2750ed6 --- /dev/null +++ b/demo_family_ui362_windows.go @@ -0,0 +1,156 @@ +//go:build windows + +package main + +import ( + "context" + "fmt" + + "time" +) + +func demoFailure362(text string) { + demoShowcaseUI.Lock() + demoShowcaseUI.avPlaying = false + demoShowcaseUI.status = text + demoShowcaseUI.Unlock() +} +func demoStatus362(text string) { + demoShowcaseUI.Lock() + demoShowcaseUI.status = text + demoShowcaseUI.Unlock() +} +func (a *app) demoFamilyStart362(idx int) { + a.demoAVStop() + if a.pl == nil || a.pl.R == nil { + demoStatus362("Open a mapped project first.") + return + } + pl := a.pl + pl.mu.Lock() + prior := pl.demoFamily362 + pl.mu.Unlock() + pl.mu.Lock() + room, e := demoRoomPlanForProject(pl.P) + p, r := pl.P, pl.R + pl.mu.Unlock() + if e != nil { + demoStatus362(e.Error()) + return + } + plan, e := demoBuildPlan362(room, demoRoomFamilies362(room, a.demoFamilies362()), time.Now().UnixNano(), idx) + if e != nil { + demoStatus362(e.Error()) + return + } + // Reject ambiguous source IDs now rather than render a different target. + if _, e = plan.sceneAt(0); e != nil { + demoStatus362(e.Error()) + return + } + gen := demoAVTourGen.Add(1) + ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute) + demoShowcaseUI.Lock() + demoShowcaseUI.avSel = idx + demoShowcaseUI.avPlaying = true + demoShowcaseUI.avCancel = cancel + demoShowcaseUI.status = fmt.Sprintf("Preparing local voice for %d effect families, five seconds each. %d unavailable. Nothing saved.", len(plan.Steps), len(plan.Unavailable)) + demoShowcaseUI.Unlock() + go func() { + if prior != nil && prior.runtime.done != nil { + select { + case <-prior.runtime.done: + case <-ctx.Done(): + return + } + } + e := demoPrepareVoice362(ctx, &plan) + if ctx.Err() != nil && e == nil { + e = ctx.Err() + } + if !a.studioOnUI(func() { + if demoAVTourGen.Load() != gen { + return + } + if e != nil { + demoShowcaseUI.Lock() + demoShowcaseUI.avPlaying = false + demoShowcaseUI.status = "Family tour not started: " + e.Error() + demoShowcaseUI.Unlock() + cancel() + return + } + if a.pl != pl { + demoShowcaseUI.Lock() + demoShowcaseUI.avPlaying = false + demoShowcaseUI.Unlock() + cancel() + return + } + pl.mu.Lock() + current, ce := demoRoomPlanForProject(pl.P) + valid := pl.P == p && pl.R == r && ce == nil && current.Fingerprint == plan.Room.Fingerprint + pl.mu.Unlock() + if !valid { + cancel() + demoShowcaseUI.Lock() + demoShowcaseUI.avPlaying = false + demoShowcaseUI.Unlock() + demoStatus362("Mapped room changed during preparation. Press Play again.") + return + } + if !a.spatialAudioStop("family tour started") { + cancel() + demoFailure362("Spatial audio cleanup pending.") + return + } + a.showAudioInvalidate() + u := a.showAudioNative() + releaseCtx, releaseCancel := context.WithTimeout(context.Background(), time.Second) + er := u.fileCommand(releaseCtx, showMusicOwnerCommand{Kind: "release-show"}) + releaseCancel() + if er != nil { + cancel() + demoFailure362("Audio owner unavailable: " + er.Error()) + return + } + if a.projOpen { + erText := a.rebindProjectorIfSelectionChanged() + if erText != "" { + cancel() + demoFailure362(erText) + return + } + } else if erText := a.openProjector(); erText != "" { + cancel() + demoFailure362(erText) + return + } + pl.mu.Lock() + if pl.P != p || pl.R != r || !a.projOpen || a.proj == 0 { + pl.mu.Unlock() + cancel() + demoFailure362("Projector or project changed during launch.") + return + } + pl.demoRoomStopLocked("family tour started") + d, er := newDemoFamilyPlayback362(p, r, &plan, a.proj, a.demoOutputGen) + if er == nil { + pl.demoFamily362 = d + physicsStopped.Store(false) + } + pl.mu.Unlock() + if er != nil { + cancel() + demoFailure362(er.Error()) + return + } + demoShowcaseUI.Lock() + demoShowcaseUI.status = fmt.Sprintf("Family tour: %d families, five seconds each, not every preset. %d unavailable; see list below.", len(plan.Steps), len(plan.Unavailable)) + demoShowcaseUI.Unlock() + go demoRunAudio362(d.runtime) + }) { + cancel() + } + }() +} diff --git a/demo_family_voice362.go b/demo_family_voice362.go new file mode 100644 index 0000000..c981e4b --- /dev/null +++ b/demo_family_voice362.go @@ -0,0 +1,17 @@ +package main + +import ( + "encoding/binary" + "errors" +) + +func demoDecodeRawNarration362(b []byte) (*showAudioPCM, error) { + if len(b) == 0 || len(b)%4 != 0 || len(b) > 11*1024*1024 { + return nil, errors.New("invalid local PCM length") + } + s := make([]int16, len(b)/2) + for i := range s { + s[i] = int16(binary.LittleEndian.Uint16(b[i*2 : i*2+2])) + } + return &showAudioPCM{ID: "family-narration", Rate: 44100, Channels: 2, Samples: s, LoopEnd: len(s) / 2}, nil +} diff --git a/demo_family_voice362_windows.go b/demo_family_voice362_windows.go new file mode 100644 index 0000000..03eb54c --- /dev/null +++ b/demo_family_voice362_windows.go @@ -0,0 +1,88 @@ +//go:build windows + +package main + +import ( + "context" + "encoding/base64" + "encoding/binary" + "fmt" + "io" + "os/exec" +) + +// Prepare local narration into measured PCM before any projector/audio start. +// One bounded worker per preparation, no network or persistent voice files. +// Base64 is data transport through stdin, never evaluated as PowerShell code. +// Output is raw PCM in the explicitly requested format, not a WAV container. +func demoPrepareVoice362(ctx context.Context, p *demoPlan362) error { + if p == nil || len(p.Steps) == 0 || len(p.Steps) > 128 { + return fmt.Errorf("invalid family voice plan") + } + ps := `Add-Type -AssemblyName System.Speech; $s=New-Object System.Speech.Synthesis.SpeechSynthesizer; $s.Rate=1; $out=[Console]::OpenStandardOutput(); $writer=New-Object System.IO.BinaryWriter($out); try { while(($line=[Console]::ReadLine()) -ne $null){ $text=[System.Text.Encoding]::UTF8.GetString([Convert]::FromBase64String($line)); $mem=New-Object System.IO.MemoryStream; try { $s.SetOutputToAudioStream($mem,([System.Speech.AudioFormat.SpeechAudioFormatInfo]::new(44100,[System.Speech.AudioFormat.AudioBitsPerSample]::Sixteen,[System.Speech.AudioFormat.AudioChannel]::Stereo))); $s.Speak($text); $s.SetOutputToNull(); $b=$mem.ToArray(); $writer.Write([uint32]$b.Length); $writer.Write($b); $writer.Flush() } finally { $mem.Dispose() } } } finally { $s.Dispose(); $writer.Dispose() }` + cmd := exec.CommandContext(ctx, "powershell", "-NoProfile", "-WindowStyle", "Hidden", "-Command", ps) + in, e := cmd.StdinPipe() + if e != nil { + return e + } + out, e := cmd.StdoutPipe() + if e != nil { + in.Close() + return e + } + if e = cmd.Start(); e != nil { + in.Close() + return e + } + done := false + defer func() { + in.Close() + if !done && cmd.Process != nil { + _ = cmd.Process.Kill() + } + if !done { + _ = cmd.Wait() + } + }() + // Explicit synthesis output format is 44.1kHz 16-bit stereo PCM. No word-count clock. + for i := range p.Steps { + text := p.Steps[i].Words + for attempt := 0; attempt < 2; attempt++ { + if _, e = fmt.Fprintln(in, base64.StdEncoding.EncodeToString([]byte(text))); e != nil { + return e + } + var size uint32 + if e = binary.Read(out, binary.LittleEndian, &size); e != nil { + return fmt.Errorf("local narration worker: %w", e) + } + if size < 4 || size > 11*1024*1024 { + return fmt.Errorf("local narration exceeds bounded PCM limit") + } + b := make([]byte, int(size)) + if _, e = io.ReadFull(out, b); e != nil { + return e + } + pcm, e := demoDecodeRawNarration362(b) + if e != nil { + return e + } + if e = p.admitVoice(i, pcm); e == nil { + break + } + if attempt == 1 { + return e + } + text = p.Steps[i].Name + "." + p.Steps[i].Words = text + } + } + if e = in.Close(); e != nil { + return e + } + e = cmd.Wait() + done = true + if e != nil { + return e + } + return nil +} diff --git a/demo_showcase_ui_windows.go b/demo_showcase_ui_windows.go index e3fd30f..24c633e 100644 --- a/demo_showcase_ui_windows.go +++ b/demo_showcase_ui_windows.go @@ -29,7 +29,6 @@ var demoShowcaseUI struct { playing bool avSel int avPlaying bool - avStart time.Time avCancel context.CancelFunc startTime time.Time chapter int @@ -64,76 +63,51 @@ func (a *app) demoShowcaseLayout(add func(widget) int, rx, rw, y, bh, pad int) { demoShowcaseUI.Lock() avSel := clampi(demoShowcaseUI.avSel, 0, len(demoAVList)-1) avPlaying := demoShowcaseUI.avPlaying - avStart := demoShowcaseUI.avStart playing := demoShowcaseUI.playing status := demoShowcaseUI.status demoShowcaseUI.Unlock() curAV := demoAVList[avSel] + curAV.Name="Fresh family shuffle" + curAV.Tagline="Actual available effects on your mapped outlines, named by the narration." avLine := curAV.Tagline - if avPlaying { - el := time.Since(avStart).Seconds() - chIdx, ch := demoAVTourChapter(avSel, el) - avLine = fmt.Sprintf("LIVE [%d/12 %s | %.0f/180s]: %q", chIdx+1, ch.title, el, ch.dialogue) - } + if avPlaying { avLine="Preparing a fresh representative from each supported family. Five seconds per family, not per preset." } + if a.pl!=nil{a.pl.mu.Lock();if d:=a.pl.demoFamily362;d!=nil{d.runtime.mu.Lock();step:=d.runtime.tr.Step;stopped:=d.runtime.tr.Stopped;reason:=d.runtime.reason;d.runtime.mu.Unlock();if !stopped&&step= 0, plan.Seat >= 0, plan.Picture >= 0) } } } y = a.fxStdHeaderLayout(add, rx, rw, y, pad, fxStdHeaderOpts{ - Title: "Demo Showcase — 5 Funny 3-Min Voiced AV Demos", - Subtitle: "Interactive 3-minute live-projector AV tours with funny voice narration showcasing 3D depth, normals, ObjectIQ, filters, Atmos & all engines.", + Title: "Demo Showcase: Fresh Voiced Family Tours", + Subtitle: "One representative per supported effect family, five seconds each. Fresh choices each Play, not every preset. Unavailable workflows are listed.", SubtitleH: 42, Sensing: roomLock, Selected: curAV.Name, - Index: avSel + 1, - Total: len(demoAVList), + Index: 0, + Total: 0, Description: avLine, Status: status, }) - // 5 AV Demo selector cards - for i, d := range demoAVList { - add(widget{ - kind: kBtn, - id: idDemoAVSelectBase + i, - text: d.Name + " (3:00 Voiced AV)", - l: rx + sc(16), - t: y, - r: rx + rw - sc(16), - b: y + bh, - enabled: true, - on: i == avSel, - }) - y += bh + sc(6) - } half := (rw - sc(32) - sc(8)) / 2 - add(widget{kind: kBtn, id: idDemoAVPlay, text: "Launch Selected 3-Min Voiced AV Demo", l: rx + sc(16), t: y, r: rx + sc(16) + half, b: y + bh, style: stPrimary, enabled: true}) + add(widget{kind: kBtn, id: idDemoAVPlay, text: "Play fresh voiced family tour", l: rx + sc(16), t: y, r: rx + sc(16) + half, b: y + bh, style: stPrimary, enabled: true}) add(widget{kind: kBtn, id: idDemoAVStop, text: "Stop AV Demo & Voice", l: rx + sc(16) + half + sc(8), t: y, r: rx + rw - sc(16), b: y + bh, enabled: avPlaying}) y += bh + sc(6) - // Narration pace: default 1.5x (shrinks the estimated silent tail in the - // contributor's fixed 15s windows); 1.0x restores the original pacing. - // Concise button labels (no truncation); the timing note is its own label. - add(widget{kind: kLabel, text: "Narration pace - applies at next launch:", l: rx + sc(16), t: y, r: rx + rw - sc(16), b: y + sc(18), small: true}) - y += sc(24) - pace := demoAVPaceX100.Load() - third := (rw - sc(32) - sc(16)) / 3 - add(widget{kind: kBtn, id: idDemoAVPace100, text: "Pace 1.0x", l: rx + sc(16), t: y, r: rx + sc(16) + third, b: y + bh, enabled: true, on: pace == 100}) - add(widget{kind: kBtn, id: idDemoAVPace150, text: "Pace 1.5x", l: rx + sc(16) + third + sc(8), t: y, r: rx + sc(16) + 2*third + sc(8), b: y + bh, enabled: true, on: pace == 150}) - add(widget{kind: kBtn, id: idDemoAVPace200, text: "Pace 2.0x", l: rx + sc(16) + 2*third + sc(16), t: y, r: rx + rw - sc(16), b: y + bh, enabled: true, on: pace == 200}) - y += bh + pad + add(widget{kind:kLabel,text:"Experimental: native audio sync NOT TESTED. Five seconds per family. Voice is measured first; Stop interrupts speech.",l:rx+sc(16),t:y,r:rx+rw-sc(16),b:y+sc(58),small:true,wrap:true});y+=sc(64) + // Each unavailable workflow has a separate wrapping row, not an overflowing status line. + if a.pl!=nil{a.pl.mu.Lock();p:=a.pl.P;room,e:=demoRoomPlanForProject(p);a.pl.mu.Unlock();if e==nil{for _,fam:=range demoRoomFamilies362(room,a.demoFamilies362()){if fam.Unavailable!=""{add(widget{kind:kLabel,text:fam.Name+": unavailable. "+fam.Unavailable,l:rx+sc(16),t:y,r:rx+rw-sc(16),b:y+sc(50),small:true,wrap:true});y+=sc(54)}}}} row := func(t string, h int) { add(widget{kind: kLabel, text: t, l: rx + sc(16), t: y, r: rx + rw - sc(16), b: y + sc(h), small: true}) y += sc(h + 8) @@ -164,95 +138,11 @@ func (a *app) demoShowcaseLayout(add func(widget) int, rx, rw, y, bh, pad int) { y += ((len(demoChapters) + 1) / 2) * (bh + sc(8)) } -func (a *app) demoAVStart(idx int) { - a.demoAVStop() - idx = clampi(idx, 0, len(demoAVList)-1) - if a.pl == nil || a.pl.P == nil { - demoShowcaseUI.Lock() - demoShowcaseUI.status = "Open a mapped project first." - demoShowcaseUI.Unlock() - return - } - id := fmt.Sprintf("demo-av-%d", idx) - m := map[string]Assign{} - a.pl.mu.Lock() - for _, sf := range a.pl.P.Surfaces { - if sf.visible() { - m[sf.ID] = Assign{Type: "fx", ID: id, Scale: 1, Speed: 1, Inten: 1, C1: "#ffffff", C2: "#3ddc97"} - } - } - a.pl.mu.Unlock() - sc := Scene{Name: demoAVList[idx].Name, Assign: m} - reason := a.scenePreviewShowOwner("demo-av", sc.Name, sc, len(m)) - - ctx, cancel := context.WithCancel(context.Background()) - demoShowcaseUI.Lock() - demoShowcaseUI.avSel = idx - demoShowcaseUI.avPlaying = true - demoShowcaseUI.avStart = time.Now() - demoShowcaseUI.avCancel = cancel - demoAVActivePaceX100.Store(demoAVPaceX100.Load()) - demoAVTourActiveIdx.Store(int32(idx)) - tourGen := int(demoAVTourGen.Add(1)) - if reason != "" { - demoShowcaseUI.status = "AV Demo preview set (" + reason + ")" - } else { - demoShowcaseUI.status = "Playing 3-Min Voiced AV Demo: " + demoAVList[idx].Name - } - demoShowcaseUI.Unlock() - - go func(avIdx int, start time.Time, gen int) { - lastCh := -1 - skips := 0 - tk := time.NewTicker(400 * time.Millisecond) - defer tk.Stop() - for { - select { - case <-ctx.Done(): - return - case <-tk.C: - el := time.Since(start).Seconds() - pel := el * demoAVTourPace() - if pel >= demoShowcaseDur { - // let the final utterance finish (estimated), bounded +10s; - // visuals hold the LAST chapter (clamped clock, no wrap). - // At the cap the tour stops anyway and the tail of the last - // line can be cut - a bounded cap, not a never-cut guarantee. - if demoVoiceSpeechActive() && pel < demoShowcaseDur+10 { - continue - } - if demoAVTourGen.Load() != int32(gen) { - return // a newer tour owns the state; never clear its pace/cancel - } - a.demoAVStop() - return - } - chIdx, ch := demoAVTourChapter(avIdx, el) - if chIdx != lastCh { - if demoVoiceSpeechActive() { - // The SAPI worker runs SpeakAsyncCancelAll before each new - // line, so speaking now would cut the previous line - // mid-word. Lag instead: speak when it ends (estimated). - // Visuals keep advancing (their clock is not held), so - // narration can fall behind; a chapter whose window fully - // passes is dropped - an honest skip, surfaced in status. - continue - } - if lastCh >= 0 && chIdx > lastCh+1 { - skips += chIdx - lastCh - 1 - demoShowcaseUI.Lock() - demoShowcaseUI.status = fmt.Sprintf("AV Demo: narration lagged visuals, skipped %d chapter line(s) (pace overran estimated speech)", skips) - demoShowcaseUI.Unlock() - } - lastCh = chIdx - demoVoiceSpeakChapter(avIdx, chIdx, ch.dialogue) - } - } - } - }(idx, time.Now(), tourGen) -} +func (a *app) demoAVStart(idx int) { a.demoFamilyStart362(idx) } func (a *app) demoAVStop() { + demoAVTourGen.Add(1) + if a.pl!=nil{a.pl.mu.Lock();a.pl.demoFamilyStopLocked362("user stopped or restarted");a.pl.mu.Unlock()} demoAVTourActiveIdx.Store(-1) demoAVActivePaceX100.Store(0) demoVoiceStop() @@ -264,7 +154,7 @@ func (a *app) demoAVStop() { was := demoShowcaseUI.avPlaying demoShowcaseUI.avPlaying = false demoShowcaseUI.Unlock() - if was { + if was && a.pl!=nil && a.pl.R!=nil && a.pl.R.ScenePreviewOwner()=="demo-av" { a.scenePreviewStop() } } @@ -293,19 +183,7 @@ func (a *app) demoShowcaseCommand(id int) bool { a.demoAVStop() return true } - if id == idDemoAVPace100 || id == idDemoAVPace150 || id == idDemoAVPace200 { - var p int32 = 150 - if id == idDemoAVPace100 { - p = 100 - } else if id == idDemoAVPace200 { - p = 200 - } - demoAVPaceX100.Store(p) - demoShowcaseUI.Lock() - demoShowcaseUI.status = fmt.Sprintf("AV narration pace %.2gx - applies at next launch (running tour keeps its launch pace)", float64(p)/100) - demoShowcaseUI.Unlock() - return true - } + if id==idDemoAVPace100||id==idDemoAVPace150||id==idDemoAVPace200{return true} // retired pace commands never change a family tour if id == idDemoShowcaseVol { cur := demoShowcaseAudioVol.Load() next := (cur + 25) % 125 diff --git a/player.go b/player.go index 5d1fb21..a1b9fd8 100644 --- a/player.go +++ b/player.go @@ -9,6 +9,7 @@ import ( var scaleSteps = []float64{1.0, 0.85, 0.70, 0.55} type Player struct { + demoFamily362 *demoFamilyPlayback362 roomProjectGeneration uint64 // Identity changes only on project publication, never Play/resume. (308 ownership semantics, preserved) demoRoom *demoRoomPlayback pumpkinSceneVoice *pumpkinSceneVoice @@ -511,7 +512,9 @@ func (pl *Player) renderLocked() *Frame { pl.R.invalidate() } - pl.f1.renderedFX = nil + pl.f1.family362=nil + pl.f1.renderedFX = nil + if pl.demoFamilyRenderLocked362(t0){return pl.f1} if pl.demoRoomRenderLocked(t0) { return pl.f1 } diff --git a/render.go b/render.go index 87ee0d6..273096b 100644 --- a/render.go +++ b/render.go @@ -24,6 +24,7 @@ import ( ) type Frame struct { + family362 *demoComposed362 glasslightLease *glasslightRenderLease glasslightComposed *glasslightComposedReceipt renderedFX []string // exact content plans that emitted nonblack pixels this render diff --git a/showaudio_player_snapshot.go b/showaudio_player_snapshot.go index fc5aee2..733a289 100644 --- a/showaudio_player_snapshot.go +++ b/showaudio_player_snapshot.go @@ -10,7 +10,9 @@ import ( func (pl *Player) renderWithShowAudio(proofOn bool) (*Frame, showAudioReceipt) { pl.mu.Lock() defer pl.mu.Unlock() - // Same entry hygiene as Render: retired vehicle dark and frozen returns + if d:=pl.demoFamily362;d!=nil&&(pl.virtual||pl.exportOwned||pl.blackout||pl.paused||pl.calibrationPaused||pl.pumpkinAutoDark){pl.demoFamilyStopLocked362("output paused, dark, or unavailable")} + if pl.f1!=nil{pl.f1.family362=nil};if pl.f2!=nil{pl.f2.family362=nil} + // Same entry hygiene as Render: retired vehicle dark and frozen returns // below are non-RenderScene content. if pl.R != nil { pl.R.hoverLineage.Store(nil) @@ -54,6 +56,7 @@ func (pl *Player) renderWithShowAudio(proofOn bool) (*Frame, showAudioReceipt) { func (pl *Player) showAudioSnapshotLocked(f *Frame, before uint64, rec *showAudioRenderRecord) showAudioReceipt { off := showAudioReceipt{SafetyDark: true} + if pl.demoFamily362!=nil{pl.demoFamily362.runtime.mu.Lock();on:=!pl.demoFamily362.runtime.tr.Stopped;pl.demoFamily362.runtime.mu.Unlock();if on{return off}} if pl.P == nil || pl.R == nil || f == nil || pl.virtual || pl.exportOwned || pl.blackout || pl.paused || pl.calibrationPaused || pl.pumpkinAutoDark || pl.door != nil || pl.pumpkin != nil || pl.manualPumpkin != nil || pl.R.FocusID() != "" || pl.R.FocusAnimID() != "" { return off }