Skip to content

Commit

Permalink
🐶 Ruff (#9)
Browse files Browse the repository at this point in the history
# Ruff
Adds [ruff](https://github.com/charliermarsh/ruff) linter (rust)
- Integrates with `pyproject.toml`
- No separate configuration needed!
- Uses
[qm/workflows/ruff.yml](https://github.com/quaternionmedia/.github/blob/main/.github/workflows/ruff.yml)
  • Loading branch information
mrharpo authored Jan 16, 2024
2 parents 6042fe1 + 2ed7812 commit a71fe45
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 26 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name: 🐶 Ruff linter
on: [push, pull_request]

jobs:
ruff:
name: 🦮 Lint codebase with Ruff
uses: quaternionmedia/.github/.github/workflows/ruff.yml@main
with:
args: .
2 changes: 2 additions & 0 deletions holophonor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@

holoimpl = HookimplMarker("holophonor")
"""Marker to be imported and used in plugins (and for own implementations)"""

__all__ = ["__version__", "holoimpl"]
12 changes: 6 additions & 6 deletions holophonor/freewheeling.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
class Fweelin(Holophonor):
@holoimpl
def playLoop(self, loop: int, volume: int):
if self.loops[loop] and self.loops[loop] != volume:
if self.loops[loop] and self.loops[loop] is not volume:
# loop was playing at a differet volume
# stop first
self.stopLoop(loop)
Expand All @@ -34,7 +34,7 @@ def stopLoop(self, loop: int):

@holoimpl
def recordLoop(self, loop: int):
if self.loops[loop] == None:
if self.loops[loop] is None:
self.playLoop(loop, 127)
self.loops[loop] = -1

Expand All @@ -61,9 +61,9 @@ def recallScene(self, scene: int):
self.current_scene = scene
s = self.scenes[scene]
for l in range(NUMBER_LOOPS):
if self.loops[l] != None:
if self.loops[l] is not None:
# loop exists
if s[l] != self.loops[l]:
if s[l] is not self.loops[l]:
# loop needs to be changed
if s[l] in (0, None):
if self.loops[l]:
Expand All @@ -77,11 +77,11 @@ def recallScene(self, scene: int):

@holoimpl
def storeScene(self, scene: int):
if self.current_scene != None and self.scenes[self.current_scene] == -1:
if self.current_scene is not None and self.scenes[self.current_scene] == -1:
# store changes to old scene
self.scenes[self.current_scene] = self.loops.copy()
self.current_scene = scene
if self.scenes[scene] == None:
if self.scenes[scene] is None:
self.scenes[scene] = -1
elif self.scenes[scene] == -1:
self.scenes[scene] = self.loops.copy()
Expand Down
6 changes: 3 additions & 3 deletions holophonor/launchpadS.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,15 @@ def playLoop(self, loop, volume):
def recallScene(self, scene: int):
# need to overwrite LaunchpadX implementation
# because scene light can't recieve flashing signal
if self.current_scene != None:
if self.current_scene is not None:
self.midi.send_message(
[CONTROL_CHANGE, self.SCENES[self.current_scene], self.STOPPED]
)
self.current_scene = scene
self.midi.send_message([CONTROL_CHANGE, self.SCENES[scene], self.GREEN[-1]])
s = self.scenes[scene]
for l, b in enumerate(self.map):
if self.loops[l] != None:
if self.loops[l] is not None:
# loop exists
if s[l] != self.loops[l]:
# loop needs to be changed
Expand All @@ -103,7 +103,7 @@ def recallScene(self, scene: int):
# stop loop
self.stopLoop(l)
self.loops[l] = 0
elif s[l] != None and self.loops[l] == 0:
elif s[l] is not None and self.loops[l] == 0:
# start loop
self.playLoop(l, s[l])
else:
Expand Down
32 changes: 16 additions & 16 deletions holophonor/launchpadX.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def lightButton(self, note):

@holoimpl
def close(self):
log.info(f'Closing launchpadX: exiting live mode')
log.info('Closing launchpadX: exiting live mode')

# exit programming mode
self.midi.send_message([240, 0, 32, 41, 2, 12, 14, 0, 247])
Expand Down Expand Up @@ -163,15 +163,15 @@ def overdubLoop(self, loop: int):
@holoimpl
def recallScene(self, scene: int):
log.info(f'recalling scene {scene}')
if self.current_scene != None:
if self.current_scene is not None:
self.midi.send_message([NOTE_ON, self.SCENES[self.current_scene], STOPPED])
if self.scenes[self.current_scene] == -1:
self.scenes[self.current_scene] = self.loops.copy()
self.current_scene = scene
self.midi.send_message([NOTE_ON | 0x2, self.SCENES[scene], GREEN[-1]])
s = self.scenes[scene]
for l in range(len(self.map)):
if self.loops[l] != None:
if self.loops[l] is not None:
# loop exists
if s[l] != self.loops[l]:
# loop needs to be changed
Expand All @@ -189,7 +189,7 @@ def recallScene(self, scene: int):
@holoimpl
def storeScene(self, scene: int):
log.info(f'storing scene {scene}')
if self.current_scene != None:
if self.current_scene is not None:
# if we are playing a scene currently, stop the light
self.midi.send_message([NOTE_ON, self.SCENES[self.current_scene], STOPPED])
if self.scenes[self.current_scene] == -1:
Expand All @@ -198,7 +198,7 @@ def storeScene(self, scene: int):
# also send green light
self.midi.send_message([NOTE_ON | 0x2, self.SCENES[scene], GREEN[-1]])
self.current_scene = scene
if self.scenes[scene] == None:
if self.scenes[scene] is None:
self.scenes[scene] = -1
self.midi.send_message([NOTE_ON | 0x2, self.SCENES[scene], RECORDING])

Expand Down Expand Up @@ -241,7 +241,7 @@ def toggleOverdub(self):

@holoimpl
def deletePulse(self):
log.info(f'Deleting pulse')
log.info('Deleting pulse')
self.midi.send_message([CONTROL_CHANGE, self.SESSION_BUTTON, ERASE])
self.clear()
self.pulse = False
Expand All @@ -251,18 +251,18 @@ def deletePulse(self):

@holoimpl
def clearPulse(self):
log.info(f'Clearing pulse')
log.info('Clearing pulse')
self.midi.send_message([CONTROL_CHANGE, self.SESSION_BUTTON, INACTIVE])

@holoimpl
def stopAllLoops(self):
log.info(f'Stopping all loops')
log.info('Stopping all loops')
for i, l in enumerate(self.loops):
if l:
self.midi.send_message([NOTE_ON, self.map[i], STOPPED])
self.loops[i] = 0

if self.current_scene != None:
if self.current_scene is not None:
self.midi.send_message([NOTE_ON, self.SCENES[self.current_scene], STOPPED])
self.current_scene = None

Expand Down Expand Up @@ -313,16 +313,16 @@ def __call__(self, event, data=None):
message, deltatime = event
log.debug(message)
if message[0] == NOTE_ON:
log.trace(f'NOTE ON detected')
log.trace('NOTE ON detected')
if message[1] in self.map:
log.trace(f'This is a loop button')
log.trace('This is a loop button')
l = self.map.index(message[1])
loop = self.loops[l]
if message[2]:
log.trace('note on event')
if not self.shift:
log.trace('normal (unshifted) mode')
if loop == None:
if loop is None:
log.trace('no existing loop, we are now recording.')
self.hook.recordLoop(loop=l, volume=message[2])
elif self.cut:
Expand All @@ -346,7 +346,7 @@ def __call__(self, event, data=None):
self.hook.eraseLoop(loop=l)
else:
log.trace('note off. Button released')
if self.loops[l] == None:
if self.loops[l] is None:
log.trace('if we erased the loop, clear the color')
self.hook.clearLoop(loop=l)
elif message[1] in self.DRUMS:
Expand Down Expand Up @@ -399,7 +399,7 @@ def __call__(self, event, data=None):
self.hook.recallScene(scene=s)
else:
log.trace('scene button released')
if self.scenes[s] == None:
if self.scenes[s] is None:
log.trace('if we erased the scene, clear the color')
self.hook.clearScene(scene=s)
if message[0] == CONTROL_CHANGE:
Expand Down Expand Up @@ -442,7 +442,7 @@ def __call__(self, event, data=None):
if message[2] == 127:
log.trace('session button pressed. tap pulse')
self.hook.tapPulse()
elif self.pulse == False:
elif self.pulse is False:
log.trace('session button released. clear pulse')
# this clears the ERASE color from the Session button if shift mode is released first
self.hook.clearPulse()
Expand All @@ -452,7 +452,7 @@ def __call__(self, event, data=None):
log.trace('This is a loop button')
l = self.map.index(message[1])
loop = self.loops[l]
if loop == None:
if loop is None:
log.trace('Clearing erased loop')
self.clearLoop(loop=l)
elif message[1] in self.DRUMS:
Expand Down
2 changes: 1 addition & 1 deletion holophonor/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@


def main():
from sys import stderr, stdout
from sys import stderr

log.configure(handlers=[{"sink": stderr, "level": "TRACE"}])
pm = get_plugin_manager()
Expand Down

0 comments on commit a71fe45

Please sign in to comment.