diff --git a/adafruit_midi/__init__.py b/adafruit_midi/__init__.py old mode 100644 new mode 100755 index bee0070..5b30bc9 --- a/adafruit_midi/__init__.py +++ b/adafruit_midi/__init__.py @@ -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" @@ -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). @@ -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 @@ -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: diff --git a/adafruit_midi/midi_message.py b/adafruit_midi/midi_message.py old mode 100644 new mode 100755 index a19a637..95e3d6f --- a/adafruit_midi/midi_message.py +++ b/adafruit_midi/midi_message.py @@ -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): diff --git a/docs/conf.py b/docs/conf.py index 50745f7..157d822 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -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. @@ -140,7 +140,7 @@ ( master_doc, "AdafruitMIDILibrary.tex", - u"AdafruitMIDI Library Documentation", + "AdafruitMIDI Library Documentation", author, "manual", ), @@ -154,7 +154,7 @@ ( master_doc, "AdafruitMIDIlibrary", - u"Adafruit MIDI Library Documentation", + "Adafruit MIDI Library Documentation", [author], 1, ) @@ -169,7 +169,7 @@ ( master_doc, "AdafruitMIDILibrary", - u"Adafruit MIDI Library Documentation", + "Adafruit MIDI Library Documentation", author, "AdafruitMIDILibrary", "One line description of project.",