Skip to content

Commit

Permalink
add Filter
Browse files Browse the repository at this point in the history
  • Loading branch information
nosuchtim committed Feb 10, 2024
1 parent 6165b5f commit e58b66f
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 5 deletions.
27 changes: 27 additions & 0 deletions kit/patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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_") {
Expand Down Expand Up @@ -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

Expand Down
29 changes: 24 additions & 5 deletions kit/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package kit
import (
"container/list"
"fmt"
"math/rand"
"runtime/debug"
"sync"
"time"
Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand Down
6 changes: 6 additions & 0 deletions python/palette_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit e58b66f

Please sign in to comment.