Skip to content

Simplify midi all #22

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions adafruit_midi/__init__.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@

"""

from .midi_message import MIDIMessage, ALL_CHANNELS
from .midi_message import MIDIMessage

__version__ = "0.0.0-auto.0"
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_MIDI.git"
Expand All @@ -58,8 +58,8 @@ class MIDI:
:param in_channel: The input channel(s).
This is used by ``receive`` to filter data.
This can either be an ``int`` for the wire protocol channel number (0-15)
a tuple of ``int`` to listen for multiple channels or ``"ALL"``.
Defaults to None.
a tuple of ``int`` to listen for multiple channels.
Defaults to all channels.
:param int out_channel: The wire protocol output channel number (0-15)
used by ``send`` if no channel is specified,
defaults to 0 (MIDI Channel 1).
Expand All @@ -82,9 +82,9 @@ def __init__(
raise ValueError("No midi_in or midi_out provided")
self._midi_in = midi_in
self._midi_out = midi_out
self._in_channel = in_channel # dealing with pylint inadequacy
self._in_channel = in_channel
self.in_channel = in_channel
self._out_channel = out_channel # dealing with pylint inadequacy
self._out_channel = out_channel
self.out_channel = out_channel
self._debug = debug
# This input buffer holds what has been read from midi_in
Expand All @@ -98,16 +98,16 @@ def in_channel(self):
"""The incoming MIDI channel. Must be 0-15. Correlates to MIDI channels 1-16, e.g.
``in_channel = 3`` will listen on MIDI channel 4.
Can also listen on multiple channels, e.g. ``in_channel = (0,1,2)``
will listen on MIDI channels 1-3 or ``in_channel = "ALL"`` for every channel.
Default is None."""
will listen on MIDI channels 1-3.
Default is all channels."""
return self._in_channel

@in_channel.setter
def in_channel(self, channel):
if channel is None or (isinstance(channel, int) and 0 <= channel <= 15):
if channel is None or channel == "ALL":
self._in_channel = tuple(range(16))
elif isinstance(channel, int) and 0 <= channel <= 15:
self._in_channel = channel
elif isinstance(channel, str) and channel == "ALL":
self._in_channel = ALL_CHANNELS
elif isinstance(channel, tuple) and all(0 <= c <= 15 for c in channel):
self._in_channel = channel
else:
Expand Down
16 changes: 4 additions & 12 deletions adafruit_midi/midi_message.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -42,28 +42,20 @@
__version__ = "0.0.0-auto.0"
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_MIDI.git"

# This is a special channel value outside of wire protocol range used to
# represent all of the sixteen channels
ALL_CHANNELS = -1

# From C3 - A and B are above G
# Semitones A B C D E F G
NOTE_OFFSET = [21, 23, 12, 14, 16, 17, 19]

# pylint: disable=no-else-return

def channel_filter(channel, channel_spec):
"""
Utility function to return True iff the given channel matches channel_spec.
"""
if isinstance(channel_spec, int):
if channel_spec == ALL_CHANNELS:
return True
else:
return channel == channel_spec
elif isinstance(channel_spec, tuple):
return channel == channel_spec
if isinstance(channel_spec, tuple):
return channel in channel_spec
else:
raise ValueError("Incorrect type for channel_spec")
raise ValueError("Incorrect type for channel_spec" + str(type(channel_spec)))


def note_parser(note):
Expand Down
16 changes: 8 additions & 8 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,18 @@
master_doc = "index"

# General information about the project.
project = u"Adafruit MIDI Library"
copyright = u"2019 Ladyada & Kevin J. Walters"
author = u"Ladyada & Kevin J. Walters"
project = "Adafruit MIDI Library"
copyright = "2019 Ladyada & Kevin J. Walters"
author = "Ladyada & Kevin J. Walters"

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
version = u"1.0"
version = "1.0"
# The full version, including alpha/beta/rc tags.
release = u"1.0"
release = "1.0"

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down Expand Up @@ -140,7 +140,7 @@
(
master_doc,
"AdafruitMIDILibrary.tex",
u"AdafruitMIDI Library Documentation",
"AdafruitMIDI Library Documentation",
author,
"manual",
),
Expand All @@ -154,7 +154,7 @@
(
master_doc,
"AdafruitMIDIlibrary",
u"Adafruit MIDI Library Documentation",
"Adafruit MIDI Library Documentation",
[author],
1,
)
Expand All @@ -169,7 +169,7 @@
(
master_doc,
"AdafruitMIDILibrary",
u"Adafruit MIDI Library Documentation",
"Adafruit MIDI Library Documentation",
author,
"AdafruitMIDILibrary",
"One line description of project.",
Expand Down