event type added for toggline evet subscriptions.

level updates now disabled by default.

each event updater runs in its own goroutine.
This commit is contained in:
onyx-and-iris 2022-08-22 22:29:30 +01:00
parent 69476ffcd9
commit 3ea4aee863

View File

@ -40,41 +40,97 @@ func (p *publisher) notify(subject string) {
}
}
type event struct {
pdirty bool
mdirty bool
midi bool
ldirty bool
}
func newEvent() *event {
return &event{true, true, true, false}
}
func (e *event) Add(ev string) {
switch ev {
case "pdirty":
e.pdirty = true
case "mdirty":
e.mdirty = true
case "midi":
e.midi = true
case "ldirty":
e.ldirty = true
}
}
func (e *event) Remove(ev string) {
switch ev {
case "pdirty":
e.pdirty = false
case "mdirty":
e.mdirty = false
case "midi":
e.midi = false
case "ldirty":
e.ldirty = false
}
}
// pooler continuously polls the dirty paramters
// it is expected to be run in a goroutine
type pooler struct {
k *kind
run bool
k *kind
run bool
event *event
publisher
}
func newPooler(k *kind) *pooler {
p := &pooler{
k: k,
run: true,
k: k,
run: true,
event: newEvent(),
}
go p.runner()
go p.parameters()
go p.macrobuttons()
go p.midi()
go p.levels()
return p
}
func (p *pooler) runner() {
func (p *pooler) parameters() {
for p.run {
if pdirty() {
if p.event.pdirty && pdirty() {
p.notify("pdirty")
}
if mdirty() {
time.Sleep(33 * time.Millisecond)
}
}
func (p *pooler) macrobuttons() {
for p.run {
if p.event.mdirty && mdirty() {
p.notify("mdirty")
}
time.Sleep(33 * time.Millisecond)
}
}
func (p *pooler) midi() {
for p.run {
if getMidiMessage() {
p.notify("midi")
}
time.Sleep(33 * time.Millisecond)
}
}
func (p *pooler) levels() {
_levelCache = newLevelCache(p.k)
for p.run {
if ldirty(p.k) {
if p.event.ldirty && ldirty(p.k) {
update(_levelCache.stripLevels, _levelCache.stripLevelsBuff, (2*p.k.PhysIn)+(8*p.k.VirtIn))
update(_levelCache.busLevels, _levelCache.busLevelsBuff, 8*p.k.NumBus())
p.notify("ldirty")