Skip to content

Commit

Permalink
add manual fade control
Browse files Browse the repository at this point in the history
  • Loading branch information
spacepalette committed Feb 10, 2024
1 parent dccbbcd commit 6165b5f
Show file tree
Hide file tree
Showing 25 changed files with 121 additions and 70 deletions.
22 changes: 11 additions & 11 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@
"version": "0.2.0",
"configurations": [

{
"name": "ENGINE - palette_engine.go",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${env:PALETTE_SOURCE}/cmd/palette_engine/palette_engine.go",
"env": {
"Path": "${env:Path};${workspaceFolder};c:/Users/me/Documents/github/vizicist/palette/SenselLib/x64;" },
"args": []
},
{
"name": "palette osc listen",
"type": "go",
Expand Down Expand Up @@ -45,7 +55,7 @@
},
{
"name": "GUI - palette_gui.py",
"type": "python",
"type": "debugpy",
"request": "launch",
"program": "${env:PALETTE_SOURCE}/python/palette_gui.py",
"console": "integratedTerminal",
Expand All @@ -62,16 +72,6 @@
"Path": "${env:Path};${workspaceFolder};c:/Users/me/Documents/github/vizicist/palette/SenselLib/x64;" },
"args": []
},
{
"name": "ENGINE - palette_engine.go",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${env:PALETTE_SOURCE}/cmd/palette_engine/palette_engine.go",
"env": {
"Path": "${env:Path};${workspaceFolder};c:/Users/me/Documents/github/vizicist/palette/SenselLib/x64;" },
"args": []
},
{
"name": "MONITOR - palette_monitor.go",
"type": "go",
Expand Down
6 changes: 0 additions & 6 deletions data/saved/global/External_Scale On.json

This file was deleted.

1 change: 1 addition & 0 deletions data/saved/global/Thru_Compression.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"params": {
"global.midisetexternalscale":"false",
"global.midithru":"true",
"global.midithrusynth":"P_08_C_06"
}
Expand Down
1 change: 1 addition & 0 deletions data/saved/global/Thru_Darkness.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"params": {
"global.midisetexternalscale":"false",
"global.midithru":"true",
"global.midithrusynth":"P_08_C_05"
}
Expand Down
1 change: 1 addition & 0 deletions data/saved/global/Thru_Drive.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"params": {
"global.midisetexternalscale":"false",
"global.midithru":"true",
"global.midithrusynth":"P_07_C_01"
}
Expand Down
1 change: 1 addition & 0 deletions data/saved/global/Thru_Flutes.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"params": {
"global.midisetexternalscale":"false",
"global.midithru":"true",
"global.midithrusynth":"P_11_C_04"
}
Expand Down
1 change: 1 addition & 0 deletions data/saved/global/Thru_Glass.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"params": {
"global.midisetexternalscale":"false",
"global.midithru":"true",
"global.midithrusynth":"P_04_C_08"
}
Expand Down
1 change: 1 addition & 0 deletions data/saved/global/Thru_JazzDooDah.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"params": {
"global.midisetexternalscale":"false",
"global.midithru":"true",
"global.midithrusynth":"P_10_C_06"
}
Expand Down
1 change: 1 addition & 0 deletions data/saved/global/Thru_Moog.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"params": {
"global.midisetexternalscale":"false",
"global.midithru":"true",
"global.midithrusynth":"P_07_C_03"
}
Expand Down
1 change: 1 addition & 0 deletions data/saved/global/Thru_Picking.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"params": {
"global.midisetexternalscale":"false",
"global.midithru":"true",
"global.midithrusynth":"P_11_C_02"
}
Expand Down
1 change: 1 addition & 0 deletions data/saved/global/Thru_Polylead.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"params": {
"global.midisetexternalscale":"false",
"global.midithru":"true",
"global.midithrusynth":"P_08_C_07"
}
Expand Down
1 change: 1 addition & 0 deletions data/saved/global/Thru_RezBass.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"params": {
"global.midisetexternalscale":"false",
"global.midithru":"true",
"global.midithrusynth":"P_09_C_06"
}
Expand Down
1 change: 1 addition & 0 deletions data/saved/global/Thru_Rhodes.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"params": {
"global.midisetexternalscale":"false",
"global.midithru":"true",
"global.midithrusynth":"P_09_C_02"
}
Expand Down
1 change: 1 addition & 0 deletions data/saved/global/Thru_Simple.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"params": {
"global.midisetexternalscale":"false",
"global.midithru":"true",
"global.midithrusynth":"P_09_C_07"
}
Expand Down
1 change: 1 addition & 0 deletions data/saved/global/Thru_SquareLead.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"params": {
"global.midisetexternalscale":"false",
"global.midithru":"true",
"global.midithrusynth":"P_12_C_03"
}
Expand Down
1 change: 1 addition & 0 deletions data/saved/global/Thru_Theremin.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"params": {
"global.midisetexternalscale":"false",
"global.midithru":"true",
"global.midithrusynth":"P_04_C_06"
}
Expand Down
1 change: 1 addition & 0 deletions data/saved/global/Thru_TriangleLead.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"params": {
"global.midisetexternalscale":"false",
"global.midithru":"true",
"global.midithrusynth":"P_11_C_01"
}
Expand Down
22 changes: 12 additions & 10 deletions kit/engineapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ import (
// ExecuteApi xxx
func ExecuteApi(api string, apiargs map[string]string) (result string, err error) {

LogOfType("api", "ExecuteApi", "api", api, "apiargs", apiargs)
if api != "global.status" { // global.status happens every few seconds
LogOfType("api", "ExecuteApi", "api", api, "apiargs", apiargs)
}

words := strings.Split(api, ".")
if len(words) <= 1 {
Expand Down Expand Up @@ -124,7 +126,7 @@ func ExecuteGlobalApi(api string, apiargs map[string]string) (result string, err
return "", fmt.Errorf("ExecuteGlobalApi: missing filename parameter")
}
err := LoadGlobalParamsFrom(fname)
return "",err
return "", err

case "set":
name, value, err := GetNameValue(apiargs)
Expand All @@ -140,7 +142,7 @@ func ExecuteGlobalApi(api string, apiargs map[string]string) (result string, err
if err != nil {
return "", err
}
return "", SaveGlobalParams()
return "", SaveCurrentGlobalParams()

case "setparams":
for name, value := range apiargs {
Expand All @@ -158,7 +160,7 @@ func ExecuteGlobalApi(api string, apiargs map[string]string) (result string, err
if err != nil {
return "", err
}
return "", SaveGlobalParams()
return "", SaveCurrentGlobalParams()

case "get":
name, ok := apiargs["name"]
Expand Down Expand Up @@ -350,13 +352,13 @@ func ApplyGlobalParam(name string, value string) (err error) {
}

/*
if TheNats.enabled && TheNats.natsConn == nil {
err = TheNats.Connect()
if err != nil {
LogIfError(err)
return err
if TheNats.enabled && TheNats.natsConn == nil {
err = TheNats.Connect()
if err != nil {
LogIfError(err)
return err
}
}
}
*/

case "global.attract":
Expand Down
32 changes: 11 additions & 21 deletions kit/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,36 +309,22 @@ func LoadParamsMapFromPath(path string) (ParamsMap, error) {
if err != nil {
return nil, err
}
var f any
err = json.Unmarshal(bytes, &f)
pmap, err := MakeParamsMapFromBytes(bytes)
if err != nil {
return nil, fmt.Errorf("unable to Unmarshal path=%s, err=%s", path, err)
}
toplevel, ok := f.(map[string]any)
if !ok {
return nil, fmt.Errorf("unable to convert params to map[string]any")

}
params, okparams := toplevel["params"]
if !okparams {
return nil, fmt.Errorf("no params value in json")
return nil, fmt.Errorf("unable to load params from path=%s err=%s",path, err)
}
paramsmap, okmap := params.(map[string]any)
if !okmap {
return nil, fmt.Errorf("params value is not a map[string]string in jsom")
}
return paramsmap, nil
return pmap, nil
}

func LoadParamsMapFromString(s string) (ParamsMap, error) {
func MakeParamsMapFromBytes(bytes []byte) (ParamsMap, error) {
var f any
err := json.Unmarshal([]byte(s), &f)
err := json.Unmarshal(bytes, &f)
if err != nil {
return nil, fmt.Errorf("unable to Unmarshal, err=%s, s=%s", err, s)
return nil, fmt.Errorf("unable to Unmarshal bytes, err=%s", err)
}
toplevel, ok := f.(map[string]any)
if !ok {
return nil, fmt.Errorf("unable to convert to ParamsMap - %s", s)
return nil, fmt.Errorf("unable to convert params to map[string]any")

}
params, okparams := toplevel["params"]
Expand All @@ -352,6 +338,10 @@ func LoadParamsMapFromString(s string) (ParamsMap, error) {
return paramsmap, nil
}

func LoadParamsMapFromString(s string) (ParamsMap, error) {
return MakeParamsMapFromBytes([]byte(s))
}

func (vals *ParamValues) SetParamWithString(origname, value string) (err error) {

vals.mutex.Lock()
Expand Down
27 changes: 27 additions & 0 deletions kit/patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,10 @@ func (patch *Patch) Api(api string, apiargs map[string]string) (string, error) {
patch.clearGraphics()
return "", nil

case "fade":
patch.loopFade()
return "", nil

default:
// ignore errors on these for the moment
if strings.HasPrefix(api, "loop_") || strings.HasPrefix(api, "midi_") {
Expand Down Expand Up @@ -482,6 +486,29 @@ func (patch *Patch) Status() string {
return fmt.Sprintf("%d", nevents)
}

func (patch *Patch) loopFade() {
tag := patch.name

// TheCursorManager.DeleteActiveCursorsForTag(tag)
// LogInfo("loopClear before DeleteEvents")
TheScheduler.FadeEventsWithTag(tag)
// LogInfo("loopClear after DeleteEvents")

TheScheduler.pendingMutex.Lock()
clearPending := false
for _, se := range TheScheduler.pendingScheduled {
if se.Tag == tag {
LogInfo("HEY!, saw pendingSchedule with tag prefix!", "prefix", tag, "se", se)
clearPending = true
}
}
if clearPending {
// LogInfo("loopClear is clearing pendingScheduled")
TheScheduler.pendingScheduled = nil
}
TheScheduler.pendingMutex.Unlock()
}

func (patch *Patch) loopClear() {
tag := patch.name

Expand Down
2 changes: 1 addition & 1 deletion kit/quad.go
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ func (quad *Quad) Load(category string, filename string) error {
case "global":
// No need to save _Current if we're loading it.
if filename != "_Current" {
err = SaveGlobalParams()
err = SaveCurrentGlobalParams()
}
case "quad":
if filename != "_Current" {
Expand Down
27 changes: 25 additions & 2 deletions kit/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,29 @@ func (sched *Scheduler) DeleteCursorEventsWhoseGidIs(gid int) {
}
}

func (sched *Scheduler) FadeEventsWithTag(tag string) {

sched.mutex.Lock()
defer sched.mutex.Unlock()

var nexti *list.Element
for i := sched.schedList.Front(); i != nil; i = nexti {
nexti = i.Next()
se := i.Value.(*SchedElement)
if se.Tag != tag {
continue
}
// LogInfo("DeleteEventsWithTag Removing schedList entry", "tag", tag, "i", i, "se", se)
ce, isce := se.Value.(CursorEvent)
// LogInfo("SAW CURSOREVENT", "v", v, "ddu", v.Ddu)
if isce {
ce.Pos.Z *= 0.3
se.Value = ce
// LogInfo("FadeEvents", "Z", se.Value.(CursorEvent).Pos.Z)
}
}
}

func (sched *Scheduler) DeleteEventsWithTag(tag string) {

sched.mutex.Lock()
Expand Down Expand Up @@ -327,8 +350,8 @@ func (sched *Scheduler) triggerItemsScheduledAtOrBefore(thisClick Clicks) {
tobeExecuted = append(tobeExecuted, ce)

default:
t := fmt.Sprintf("%T",v)
LogError(fmt.Errorf("triggerItemsScheduleAt: unhandled Value"),"type",t)
t := fmt.Sprintf("%T", v)
LogError(fmt.Errorf("triggerItemsScheduleAt: unhandled Value"), "type", t)
}

// This is where
Expand Down
3 changes: 0 additions & 3 deletions palette.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
"folders": [
{
"path": "."
},
{
"path": "cmd/fyne_demo"
}
],
"settings": {
Expand Down
Loading

0 comments on commit 6165b5f

Please sign in to comment.