Skip to content

Commit

Permalink
move main changes over to vizdesk
Browse files Browse the repository at this point in the history
  • Loading branch information
nosuchtim committed Nov 25, 2023
1 parent e87792e commit 90276e0
Show file tree
Hide file tree
Showing 10 changed files with 397 additions and 6 deletions.
50 changes: 49 additions & 1 deletion cmd/palette_monitor/palette_monitor.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"context"
"flag"
"fmt"
"os/exec"
Expand All @@ -10,6 +11,8 @@ import (
"github.com/0xcafed00d/joystick"
"github.com/vizicist/palette/engine"

"github.com/reugn/go-quartz/quartz"

midi "gitlab.com/gomidi/midi/v2"
_ "gitlab.com/gomidi/midi/v2/drivers/rtmididrv" // autoregisters driver
)
Expand All @@ -18,22 +21,67 @@ func main() {

engine.InitLog("monitor")

pcheck := flag.Bool("engine", true, "Check Engine")
// pcheck := flag.Bool("engine", true, "Check Engine")
pjsid := flag.Int("joystick", -1, "Joystick ID")

flag.Parse()

engine.LogInfo("HACK - palette_monitor is not checking engine")
/*
if *pcheck {
engine.LogInfo("monitor is checking the engine.")
go checkEngine()
} else {
engine.LogInfo("monitor is NOT checking the engine.")
}
*/

go joystickMonitor(*pjsid)

go midiMonitor("Logidy UMI3")

go scheduler()

select {}
}

func scheduler() {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

// create scheduler
sched := quartz.NewStdScheduler()

// async start scheduler
sched.Start(ctx)

// create jobs
// "0 15 10 * * ?" Fire at 10:15am every day
cronTrigger, _ := quartz.NewCronTrigger("0,15,30,45 * * * * *")
shellJob := quartz.NewShellJob("palette status")
fjob := quartz.NewFunctionJob(func(_ context.Context) (int, error) {
fmt.Printf("hi from function!\n")
return 0, nil
})

// request, _ := http.NewRequest(http.MethodGet, "https://worldtimeapi.org/api/timezone/utc", nil)
// curlJob := quartz.NewCurlJob(request)

// functionJob := quartz.NewFunctionJob(func(_ context.Context) (int, error) { return 42, nil })

// register jobs to scheduler
// sched.ScheduleJob(ctx, shellJob, cronTrigger)
sched.ScheduleJob(ctx, fjob, cronTrigger)
sched.ScheduleJob(ctx, shellJob, cronTrigger)
// sched.ScheduleJob(ctx, curlJob, quartz.NewSimpleTrigger(time.Second*7))
// sched.ScheduleJob(ctx, functionJob, quartz.NewSimpleTrigger(time.Second*5))

// stop scheduler
// sched.Stop()

// wait for all workers to exit
// sched.Wait(ctx)

select {}
}

Expand Down
1 change: 1 addition & 0 deletions data/config/paramdefs.json
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@
"engine.mmtt_xexpand": {"valuetype": "float", "min": "0.5", "max": "2.0", "init": "1.25", "comment": "#" },
"engine.mmtt_yexpand": {"valuetype": "float", "min": "0.5", "max": "2.0", "init": "1.25", "comment": "#" },
"engine.mmtt_zexpand": {"valuetype": "float", "min": "0.5", "max": "10.0", "init": "4.0", "comment": "#" },
"engine.nats": {"valuetype":"bool", "min":"false", "max":"true", "init":"false", "comment":"#" },
"engine.notifygui": {"valuetype":"bool", "min":"false", "max":"true", "init":"true", "comment":"#" },
"engine.obspath": {"valuetype":"string", "min":"", "max":"", "init":"C:/Program Files/obs-studio/bin/64bit/obs64.exe", "comment":"# OBS executable path" },
"engine.obsstream": {"valuetype":"bool", "min":"false", "max":"true", "init":"false", "comment":"# turn on OBS streaming" },
Expand Down
1 change: 1 addition & 0 deletions engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ func InitEngine() {
TheQuadPro = NewQuadPro()
TheMidiIO = NewMidiIO()
TheErae = NewErae()
TheNats = NewNats()

InitLogTypes()

Expand Down
9 changes: 9 additions & 0 deletions engine/engineapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,15 @@ func (e *Engine) Set(name string, value string) (err error) {
TheProcessManager.processCheckSecs = f
}

case "engine.nats":
if !e.loading {
if IsTrueValue(value) {
TheNats.Connect()
} else {
TheNats.Disconnect()
}
}

case "engine.obsstream":
if !e.loading {
if IsTrueValue(value) {
Expand Down
7 changes: 6 additions & 1 deletion engine/misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,11 @@ func ConfigDir() string {
return filepath.Join(PaletteDataPath(), "config")
}

func GetConfigFileData(filename string) ([]byte, error) {
path := ConfigFilePath(filename)
return os.ReadFile(path)
}

func ConfigFilePath(nm string) string {
return filepath.Join(ConfigDir(), nm)
}
Expand Down Expand Up @@ -550,7 +555,7 @@ func ArchiveLogs() error {

err = ziplogs(logsdir, zippath)
if err != nil {
return fmt.Errorf("Archivelogs: err=%s", err)
return fmt.Errorf("archivelogs: err=%s", err)
} else {
// If archiving is successful, clear the logs
return ClearLogs()
Expand Down
Loading

0 comments on commit 90276e0

Please sign in to comment.