Skip to content

Commit

Permalink
aiz/state: add series
Browse files Browse the repository at this point in the history
  • Loading branch information
nyiyui committed Apr 3, 2024
1 parent 03eeabe commit 75eb6b3
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 33 deletions.
10 changes: 7 additions & 3 deletions aiz/aiz.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,20 @@ type Cue struct {
}

type SG struct {
State State `json:"state"`
Gradient Gradient `json:"gradient"`
Series SeriesName `json:"seriesName"`
State State `json:"state"`
Gradient Gradient `json:"gradient"`
}

func (sg *SG) Clone() *SG {
return &SG{sg.State.Clone(), sg.Gradient.Clone()}
return &SG{sg.Series, sg.State.Clone(), sg.Gradient.Clone()}
}

var StateTypes = map[string]func() State{}
var GradientTypes = map[string]func() Gradient{}

type sgJSON struct {
Series string
StateType string
State json.RawMessage
GradientType string
Expand All @@ -38,6 +40,7 @@ type sgJSON struct {
func (sg *SG) MarshalJSON() ([]byte, error) {
var j sgJSON
var err error
j.Series = sg.Series
if sg.State != nil {
j.State, err = json.Marshal(sg.State)
if err != nil {
Expand Down Expand Up @@ -81,6 +84,7 @@ func (sg *SG) UnmarshalJSON(data []byte) error {
}
sg.State = s
sg.Gradient = g
sg.Series = j.Series
return nil
}

Expand Down
14 changes: 10 additions & 4 deletions aiz/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ import (
"nyiyui.ca/halation/notify"
)

type SeriesName = string

type Runner struct {
Specific map[string]interface{}
CurrentStates map[string]State
CurrentStates map[SeriesName]map[string]State

sgAppliedMuxS *notify.MultiplexerSender[*SG]
SGAppliedMux *notify.Multiplexer[*SG]
Expand All @@ -17,7 +19,7 @@ type Runner struct {
func NewRunner() *Runner {
r := new(Runner)
r.Specific = map[string]interface{}{}
r.CurrentStates = map[string]State{}
r.CurrentStates = map[SeriesName]map[string]State{}
r.sgAppliedMuxS, r.SGAppliedMux = notify.NewMultiplexerSender[*SG]("Runner.sgAppliedMuxS")
return r
}
Expand All @@ -26,9 +28,13 @@ func NewRunner() *Runner {
// sg must not be mutated once this function is called.
func (r *Runner) ApplySG(sg *SG, ctx context.Context) error {
r.sgAppliedMuxS.Send(sg)
prev := r.CurrentStates[sg.State.TypeName()]
_, ok := r.CurrentStates[sg.Series]
if !ok {
r.CurrentStates[sg.Series] = map[string]State{}
}
prev := r.CurrentStates[sg.Series][sg.State.TypeName()]
defer func() {
r.CurrentStates[sg.State.TypeName()] = sg.State
r.CurrentStates[sg.Series][sg.State.TypeName()] = sg.State
}()
return sg.State.Reify(r, sg.Gradient, prev)
}
17 changes: 8 additions & 9 deletions cmd/web/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"nyiyui.ca/halation/aiz"
"nyiyui.ca/halation/node"
"nyiyui.ca/halation/osc"
"nyiyui.ca/halation/web"
)

Expand Down Expand Up @@ -41,15 +42,13 @@ func initShow() (*aiz.Runner, *node.NodeRunner, *node.Cuelist) {
runner := aiz.NewRunner()
var err error
_ = err
/*
c := osc.NewDefaultClient()
c.Register(runner)
err = c.Blackout()
if err != nil {
panic(err)
}
log.Printf("osc setup ok")
*/
c := osc.NewDefaultClient()
c.Register(runner)
err = c.Blackout()
if err != nil {
panic(err)
}
log.Printf("osc setup ok")
//mpvClient, err := mpv.NewClientUsingSubprocess()
//if err != nil {
// panic(err)
Expand Down
3 changes: 2 additions & 1 deletion node/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import (

type SetState struct {
*BaseNode
SG *aiz.SG `halation:""`
SG *aiz.SG `halation:""`
Series string `halation:""`
}

func newSetStateBlank() *SetState {
Expand Down
7 changes: 4 additions & 3 deletions test/aiz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,26 @@ package test

import (
"encoding/json"
"testing"

"github.com/google/go-cmp/cmp"
. "nyiyui.ca/halation/aiz"
"nyiyui.ca/halation/gradient"
"nyiyui.ca/halation/osc"
"testing"
)

func TestJSON(t *testing.T) {
s := &Show{
Cues: []Cue{
{
SGs: []SG{
{&osc.State{
{"a", &osc.State{
Blackout: true,
}, &gradient.LinearGradient{
Duration_: 1000,
PreferredResolution_: 100,
}},
{&osc.State{
{"b", &osc.State{
Channels: []osc.Channel{
{1, 100, 0, 0},
},
Expand Down
2 changes: 1 addition & 1 deletion tsapi/tsapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func main() {
}
defer f.Close()
fmt.Fprint(f, `
type SG = { State: State, StateType: string, Gradient: Gradient, GradientType: string }
type SG = { Series: string, State: State, StateType: string, Gradient: Gradient, GradientType: string }
type Channel = {
ChannelID: number,
Level: number,
Expand Down
20 changes: 8 additions & 12 deletions yukiakari/src/lib/NodeEdit.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
if (node.NodeType == "nyiyui.ca/halation/node.SetState") {
if (!node.Node.SG) {
node.Node.SG = {
Series: "",
StateType: "",
State: {},
GradientType: "",
Expand Down Expand Up @@ -62,21 +63,12 @@
}
}
function updateColour(i) {
return (e) => {
console.log(i, e.detail.hsv);
// node.Node.SG.State.channels[i].hue = e.detail.hsv.h;
// node.Node.SG.State.channels[i].saturation = e.detail.hsv.s;
// node.Node.SG.State.channels[i].level = e.detail.hsv.v;
}
}
let channelProps = {
0: {name: "invalid"},
1: {name: "left small"},
2: {name: "left podium", colour: false},
1: {name: "left flood", colour: false},
2: {name: "left podium"},
3: {name: "left front"},
4: {name: "left side"},
4: {name: "left podium-right"},
5: {name: "left flood (LED)", colour: true},
6: {name: "left ground"},
7: {name: "left centre wall"},
Expand Down Expand Up @@ -187,6 +179,10 @@
<input bind:value={node.Node.delay} />
</label>
{:else if node.NodeType == "nyiyui.ca/halation/node.SetState" && node.Node.SG}
<label>
Series
<input type=text bind:value={node.Node.SG.Series} />
</label>
<fieldset>
<legend>State</legend>
<label>
Expand Down

0 comments on commit 75eb6b3

Please sign in to comment.