Skip to content

Commit

Permalink
Fix bugs where forwarded events wouldn't be recognised
Browse files Browse the repository at this point in the history
  • Loading branch information
MaddyGuthridge committed Feb 2, 2022
1 parent 34a906a commit a71873c
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 6 deletions.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

// Spell checker
"cSpell.words": [
"buttondatastrat",
"capsys",
"deinitialise",
"dicttools",
Expand Down
7 changes: 4 additions & 3 deletions common/eventpattern/forwardedpattern.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

import device
from typing import TYPE_CHECKING

from common.util.events import eventToString
from . import IEventPattern

from common.types import eventData
Expand Down Expand Up @@ -40,9 +42,8 @@ def matchEvent(self, event: 'eventData') -> bool:
if event.sysex is None \
or not event.sysex.startswith(bytes([0xF0, 0x7D])):
return False

# Check if it matches this device's name
null = event.sysex[2:].find(bytes(0))
null = event.sysex[2:].index(b'\0') + 2
if event.sysex[2:null].decode() != device.getName():
return False

Expand All @@ -66,4 +67,4 @@ def matchEvent(self, event: 'eventData') -> bool:
event.sysex[null+3]
)

return super().matchEvent(decoded)
return self._pattern.matchEvent(decoded)
2 changes: 1 addition & 1 deletion common/util/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,6 @@ def eventToString(event: eventData) -> str:
assert event.status is not None
assert event.data1 is not None
assert event.data2 is not None
return f"(0x{event.status:X}, 0x{event.data1:X}, 0x{event.data2:X})"
return f"(0x{event.status:02X}, 0x{event.data1:02X}, 0x{event.data2:02X})"
else:
return bytesToString(event.sysex)
1 change: 1 addition & 0 deletions controlsurfaces/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from .controlsurface import ControlSurface
from .controlshadow import ControlShadow
from .controlmapping import ControlMapping
from .valuestrategies import *

from .nullevent import *
from .pedal import *
Expand Down
30 changes: 30 additions & 0 deletions devices/maudio/hammer88pro/buttondatastrat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

from common.types import eventData
from controlsurfaces import IValueStrategy


class HammerButtonStrat(IValueStrategy):
"""
Strategy for buttons on Hammer 88 Pro
Since it mashes events together we need a special way to get the data
"""
def __init__(self, on: int) -> None:
"""
Create Hammer 88 Pro button value strategy
### Args:
* `on` (`int`): value interpreted as a press (all others will be
interpreted as a release)
"""
self._on = on
super().__init__()

def getValueFromEvent(self, event: eventData):
return event.data2 == self._on

def getValueFromFloat(self, f: float):
return f == 1.0

def getFloatFromValue(self, value) -> float:
return 1.0 if value else 0.0
9 changes: 7 additions & 2 deletions devices/maudio/hammer88pro/hammer88pro.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
DirectionNext,
DirectionPrevious
)
from .buttondatastrat import HammerButtonStrat

class Hammer88Pro(Device):

Expand All @@ -35,10 +36,14 @@ def __init__(self) -> None:
matcher.addControl(NullEvent(
BasicEventPattern(0xFC, 0x0, 0x0)
))
matcher.addControl(NullEvent(
ForwardedEventPattern(3, BasicEventPattern(0xB0, 0x0F, 0x0E))
))

# Transport buttons
matcher.addControl(PlayButton(
ForwardedEventPattern(3, BasicEventPattern(0xB0, 0xF, ...)),
ButtonSinglePressStrategy(),
ForwardedEventPattern(3, BasicEventPattern(0xB0, 0x2F, (0x44, 0x4))),
HammerButtonStrat(0x44),
"transport"
))

Expand Down

0 comments on commit a71873c

Please sign in to comment.