Skip to content

Commit 889da3f

Browse files
authored
Merge pull request #13 from kevinjwalters/master
Removing the original method per MIDI message (event) API
2 parents b95ab8a + d933879 commit 889da3f

File tree

6 files changed

+24
-103
lines changed

6 files changed

+24
-103
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2019 Ladyada for Adafruit Industries
3+
Copyright (c) 2019 Ladyada for Adafruit Industries, Kevin J. Walters
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.rst

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,14 @@ Usage Example
6868
print("Default output MIDI channel:", midi.out_channel + 1)
6969
7070
while True:
71-
midi.note_on(44, 120)
72-
midi.note_off(44, 120)
73-
midi.control_change(3, 44)
74-
midi.pitch_bend(random.randint(0,16383))
75-
time.sleep(1)
71+
midi.send(NoteOn(44, 120)) # G sharp 2nd octave
72+
time.sleep(0.25)
73+
a_pitch_bend = PitchBend(random.randint(0, 16383))
74+
midi.send(a_pitch_bend)
75+
time.sleep(0.25)
76+
midi.send([NoteOff("G#2", 120),
77+
ControlChange(3, 44)])
78+
time.sleep(0.5)
7679
7780
7881
Contributing

adafruit_midi/__init__.py

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,6 @@ class MIDI:
6868
6969
"""
7070

71-
NOTE_ON = 0x90
72-
NOTE_OFF = 0x80
73-
PITCH_BEND = 0xE0
74-
CONTROL_CHANGE = 0xB0
75-
7671
def __init__(self, midi_in=None, midi_out=None, *,
7772
in_channel=None, out_channel=0, in_buf_size=30, debug=False):
7873
if midi_in is None and midi_out is None:
@@ -173,55 +168,6 @@ def send(self, msg, channel=None):
173168

174169
self._send(data, len(data))
175170

176-
def note_on(self, note, vel, channel=None):
177-
"""Sends a MIDI Note On message.
178-
179-
:param int note: The note number. Must be 0-127.
180-
:param int vel: The note velocity. Must be 0-127.
181-
182-
"""
183-
self._generic_3(self.NOTE_ON, note, vel, channel)
184-
185-
def note_off(self, note, vel, channel=None):
186-
"""Sends a MIDI Note Off message.
187-
188-
:param int note: The note number. Must be 0-127.
189-
:param int vel: The note velocity. Must be 0-127.
190-
191-
"""
192-
self._generic_3(self.NOTE_OFF, note, vel, channel)
193-
194-
def pitch_bend(self, value, channel=None):
195-
"""Send a MIDI Pitch Wheel message.
196-
197-
:param int value: Range is 0-16383. A ``value`` of 8192 equates to no pitch bend, a value
198-
of less than 8192 equates to a negative pitch bend, and a value of more
199-
than 8192 equates to a positive pitch bend.
200-
201-
"""
202-
self._generic_3(self.PITCH_BEND, value & 0x7F, value >> 7, channel)
203-
204-
def control_change(self, control, value, channel=None):
205-
"""Sends a MIDI CC message.
206-
207-
:param int control: The controller number. Must be 0-127.
208-
:param int value: The control value. Must be 0-127.
209-
210-
"""
211-
self._generic_3(self.CONTROL_CHANGE, control, value, channel)
212-
213-
def _generic_3(self, cmd, arg1, arg2, channel=None):
214-
if not 0 <= arg1 <= 0x7F:
215-
raise RuntimeError("Argument 1 value %d invalid" % arg1)
216-
if not 0 <= arg2 <= 0x7F:
217-
raise RuntimeError("Argument 2 value %d invalid" % arg2)
218-
if channel is None:
219-
channel = self._out_channel
220-
self._outbuf[0] = (cmd & 0xF0) | (channel & 0x0f)
221-
self._outbuf[1] = arg1
222-
self._outbuf[2] = arg2
223-
self._send(self._outbuf, 3)
224-
225171
def _send(self, packet, num):
226172
if self._debug:
227173
print("Sending: ", [hex(i) for i in packet[:num]])

examples/midi_intest1.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
print("Midi input test with pauses")
1919

2020
# Convert channel numbers at the presentation layer to the ones musicians use
21-
print("Input channel:", midi.in_channel + 1 )
21+
print("Input channel:", midi.in_channel + 1)
2222

2323
# play with the pause to simulate code doing other stuff
2424
# in the loop

examples/midi_simpletest.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1+
# simple_test
12
import time
23
import random
34
import usb_midi
45
import adafruit_midi
6+
from adafruit_midi.control_change import ControlChange
7+
from adafruit_midi.note_off import NoteOff
8+
from adafruit_midi.note_on import NoteOn
9+
from adafruit_midi.pitch_bend import PitchBend
510

611
midi = adafruit_midi.MIDI(midi_out=usb_midi.ports[1], out_channel=0)
712

@@ -13,8 +18,12 @@
1318
midi.in_channel + 1 if midi.in_channel is not None else None)
1419

1520
while True:
16-
midi.note_on(44, 120)
17-
midi.note_off(44, 120)
18-
midi.control_change(3, 44)
19-
midi.pitch_bend(random.randint(0, 16383))
20-
time.sleep(1)
21+
midi.send(NoteOn(44, 120)) # G sharp 2nd octave
22+
time.sleep(0.25)
23+
a_pitch_bend = PitchBend(random.randint(0, 16383))
24+
midi.send(a_pitch_bend)
25+
time.sleep(0.25)
26+
# note how a list of messages can be used
27+
midi.send([NoteOff("G#2", 120),
28+
ControlChange(3, 44)])
29+
time.sleep(0.5)

examples/midi_simpletest2.py

Lines changed: 0 additions & 37 deletions
This file was deleted.

0 commit comments

Comments
 (0)