-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Utilities refactored to have reusable code
- Loading branch information
Showing
4 changed files
with
96 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
General MIDI encoder utilities | ||
""" | ||
|
||
from . import event | ||
|
||
|
||
def get_rotation( | ||
value: int, | ||
range_cw: range, | ||
range_ccw: range, | ||
): | ||
""" | ||
For a CC value assigned on an encoder, it returns a | ||
negative number if it's being rotated counter-clockwise, | ||
a positive number if it's being rotated clockwise and | ||
zero (0) if it's not being rotated at all. | ||
""" | ||
|
||
if value in range_cw: | ||
return range_cw.stop - value + 1 | ||
elif value in range_ccw: | ||
return -(range_ccw.stop - value + 1) | ||
return 0 | ||
|
||
|
||
def send_event_on_rotation( | ||
er: int, # encoder rotation value (must be something returned from a function like get_rotation) | ||
*, | ||
evt_cw: int, | ||
evt_ccw: int, | ||
): | ||
""" | ||
Send event based on encoder rotation | ||
On relative modes, this function will detect whether your | ||
MIDI controller is doing a clockwise or a counter-clockwise rotation. | ||
In each case, it'll send a SimEvent of your choice. | ||
""" | ||
|
||
if er > 0: | ||
event.send(evt_cw) | ||
elif er < 0: | ||
event.send(evt_ccw) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
SimConnect event utilities | ||
""" | ||
|
||
from ..simc import send_event as simc_send_evt | ||
|
||
|
||
def send(e): | ||
if isinstance(e, tuple): | ||
simc_send_evt(*e) | ||
else: | ||
simc_send_evt(e) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
General MIDI note utilities | ||
""" | ||
|
||
from ..simc import send_event as simc_send_evt | ||
from . import event | ||
|
||
def send_evt_on_note_toggle(note, *, evt_on, evt_off): | ||
""" | ||
Send event based on whether a note has been set on or off | ||
""" | ||
|
||
if note.on: | ||
event.send(evt_on) | ||
else: | ||
event.send(evt_off) |