From e58b66fb8197622b674c2c46b6c25dd52ba6befb Mon Sep 17 00:00:00 2001 From: Tim Thompson Date: Sat, 10 Feb 2024 09:46:49 -0800 Subject: [PATCH] add Filter --- kit/patch.go | 27 +++++++++++++++++++++++++++ kit/scheduler.go | 29 ++++++++++++++++++++++++----- python/palette_gui.py | 6 ++++++ 3 files changed, 57 insertions(+), 5 deletions(-) diff --git a/kit/patch.go b/kit/patch.go index 2bfd3fb5..b2de470b 100644 --- a/kit/patch.go +++ b/kit/patch.go @@ -301,6 +301,10 @@ func (patch *Patch) Api(api string, apiargs map[string]string) (string, error) { patch.loopFade() return "", nil + case "filter": + patch.loopFilter() + return "", nil + default: // ignore errors on these for the moment if strings.HasPrefix(api, "loop_") || strings.HasPrefix(api, "midi_") { @@ -509,6 +513,29 @@ func (patch *Patch) loopFade() { TheScheduler.pendingMutex.Unlock() } +func (patch *Patch) loopFilter() { + tag := patch.name + + // TheCursorManager.DeleteActiveCursorsForTag(tag) + // LogInfo("loopClear before DeleteEvents") + TheScheduler.FilterEventsWithTag(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 diff --git a/kit/scheduler.go b/kit/scheduler.go index 2dda8c8f..6a19e5b5 100644 --- a/kit/scheduler.go +++ b/kit/scheduler.go @@ -3,6 +3,7 @@ package kit import ( "container/list" "fmt" + "math/rand" "runtime/debug" "sync" "time" @@ -198,6 +199,8 @@ func (sched *Scheduler) DeleteCursorEventsWhoseGidIs(gid int) { } } +// XXX - Fade, Filter, and Delete should be combined into one function + func (sched *Scheduler) FadeEventsWithTag(tag string) { sched.mutex.Lock() @@ -221,6 +224,27 @@ func (sched *Scheduler) FadeEventsWithTag(tag string) { } } +func (sched *Scheduler) FilterEventsWithTag(tag string) { + + sched.mutex.Lock() + defer sched.mutex.Unlock() + + rnd := rand.New(rand.NewSource(1)) + 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 + } + ce, isce := se.Value.(CursorEvent) + if isce && ce.Ddu == "up" && rnd.Float32() < 0.5 { + TheCursorManager.DeleteActiveCursor(ce.Gid) + } + sched.schedList.Remove(i) + } +} + func (sched *Scheduler) DeleteEventsWithTag(tag string) { sched.mutex.Lock() @@ -232,16 +256,11 @@ func (sched *Scheduler) DeleteEventsWithTag(tag string) { 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.Ddu == "up" { - // LogInfo("UP CURSOREVENT should be removing gid", "gid", v.Gid) TheCursorManager.DeleteActiveCursor(ce.Gid) - // LogInfo("UP CURSOREVENT after removing gid", "gid", v.Gid) } sched.schedList.Remove(i) - // keep going, there will be lots of them } sched.mutex.Unlock() diff --git a/python/palette_gui.py b/python/palette_gui.py index 88cbb01e..2911dfff 100644 --- a/python/palette_gui.py +++ b/python/palette_gui.py @@ -396,6 +396,11 @@ def fadeNotes(self): palette.palette_patch_api(patch.name(), "fade", "") self.patchChooser.refreshPatches() + def filterNotes(self): + for patch in self.PatchList(): + palette.palette_patch_api(patch.name(), "filter", "") + self.patchChooser.refreshPatches() + def setNextMode(self,mode): self.nextMode = mode @@ -2203,6 +2208,7 @@ def __init__(self, parent, controller): self.makePerformButton("SOFT_RESET", self.controller.softReset) self.makePerformButton("CLEAR_LOOP", self.controller.clearNotes) self.makePerformButton("FADE_LOOP", self.controller.fadeNotes) + self.makePerformButton("FILTER_LOOP", self.controller.filterNotes) self.makePerformButton("HELP_ ", self.controller.startHelp) # self.makePerformButton("Looping_OFF", self.controller.loopingOff) # if self.controller.guidefaultlevel > 0: