Skip to content

Commit 8bf1237

Browse files
authored
Merge pull request #22 from tannewt/simplify_midi_all
Simplify midi all
2 parents 5bc88cc + 2ddf8e7 commit 8bf1237

File tree

3 files changed

+22
-30
lines changed

3 files changed

+22
-30
lines changed

adafruit_midi/__init__.py

100644100755
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
4343
"""
4444

45-
from .midi_message import MIDIMessage, ALL_CHANNELS
45+
from .midi_message import MIDIMessage
4646

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

105105
@in_channel.setter
106106
def in_channel(self, channel):
107-
if channel is None or (isinstance(channel, int) and 0 <= channel <= 15):
107+
if channel is None or channel == "ALL":
108+
self._in_channel = tuple(range(16))
109+
elif isinstance(channel, int) and 0 <= channel <= 15:
108110
self._in_channel = channel
109-
elif isinstance(channel, str) and channel == "ALL":
110-
self._in_channel = ALL_CHANNELS
111111
elif isinstance(channel, tuple) and all(0 <= c <= 15 for c in channel):
112112
self._in_channel = channel
113113
else:

adafruit_midi/midi_message.py

100644100755
Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,28 +42,20 @@
4242
__version__ = "0.0.0-auto.0"
4343
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_MIDI.git"
4444

45-
# This is a special channel value outside of wire protocol range used to
46-
# represent all of the sixteen channels
47-
ALL_CHANNELS = -1
48-
4945
# From C3 - A and B are above G
5046
# Semitones A B C D E F G
5147
NOTE_OFFSET = [21, 23, 12, 14, 16, 17, 19]
5248

53-
# pylint: disable=no-else-return
49+
5450
def channel_filter(channel, channel_spec):
5551
"""
5652
Utility function to return True iff the given channel matches channel_spec.
5753
"""
5854
if isinstance(channel_spec, int):
59-
if channel_spec == ALL_CHANNELS:
60-
return True
61-
else:
62-
return channel == channel_spec
63-
elif isinstance(channel_spec, tuple):
55+
return channel == channel_spec
56+
if isinstance(channel_spec, tuple):
6457
return channel in channel_spec
65-
else:
66-
raise ValueError("Incorrect type for channel_spec")
58+
raise ValueError("Incorrect type for channel_spec" + str(type(channel_spec)))
6759

6860

6961
def note_parser(note):

docs/conf.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,18 @@
3838
master_doc = "index"
3939

4040
# General information about the project.
41-
project = u"Adafruit MIDI Library"
42-
copyright = u"2019 Ladyada & Kevin J. Walters"
43-
author = u"Ladyada & Kevin J. Walters"
41+
project = "Adafruit MIDI Library"
42+
copyright = "2019 Ladyada & Kevin J. Walters"
43+
author = "Ladyada & Kevin J. Walters"
4444

4545
# The version info for the project you're documenting, acts as replacement for
4646
# |version| and |release|, also used in various other places throughout the
4747
# built documents.
4848
#
4949
# The short X.Y version.
50-
version = u"1.0"
50+
version = "1.0"
5151
# The full version, including alpha/beta/rc tags.
52-
release = u"1.0"
52+
release = "1.0"
5353

5454
# The language for content autogenerated by Sphinx. Refer to documentation
5555
# for a list of supported languages.
@@ -140,7 +140,7 @@
140140
(
141141
master_doc,
142142
"AdafruitMIDILibrary.tex",
143-
u"AdafruitMIDI Library Documentation",
143+
"AdafruitMIDI Library Documentation",
144144
author,
145145
"manual",
146146
),
@@ -154,7 +154,7 @@
154154
(
155155
master_doc,
156156
"AdafruitMIDIlibrary",
157-
u"Adafruit MIDI Library Documentation",
157+
"Adafruit MIDI Library Documentation",
158158
[author],
159159
1,
160160
)
@@ -169,7 +169,7 @@
169169
(
170170
master_doc,
171171
"AdafruitMIDILibrary",
172-
u"Adafruit MIDI Library Documentation",
172+
"Adafruit MIDI Library Documentation",
173173
author,
174174
"AdafruitMIDILibrary",
175175
"One line description of project.",

0 commit comments

Comments
 (0)