Skip to content

Removing the original method per MIDI message (event) API #13

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 5 commits into from
Nov 1, 2019
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
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2019 Ladyada for Adafruit Industries
Copyright (c) 2019 Ladyada for Adafruit Industries, Kevin J. Walters

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
13 changes: 8 additions & 5 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,14 @@ Usage Example
print("Default output MIDI channel:", midi.out_channel + 1)

while True:
midi.note_on(44, 120)
midi.note_off(44, 120)
midi.control_change(3, 44)
midi.pitch_bend(random.randint(0,16383))
time.sleep(1)
midi.send(NoteOn(44, 120)) # G sharp 2nd octave
time.sleep(0.25)
a_pitch_bend = PitchBend(random.randint(0, 16383))
midi.send(a_pitch_bend)
time.sleep(0.25)
midi.send([NoteOff("G#2", 120),
ControlChange(3, 44)])
time.sleep(0.5)


Contributing
Expand Down
54 changes: 0 additions & 54 deletions adafruit_midi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,6 @@ class MIDI:

"""

NOTE_ON = 0x90
NOTE_OFF = 0x80
PITCH_BEND = 0xE0
CONTROL_CHANGE = 0xB0

def __init__(self, midi_in=None, midi_out=None, *,
in_channel=None, out_channel=0, in_buf_size=30, debug=False):
if midi_in is None and midi_out is None:
Expand Down Expand Up @@ -173,55 +168,6 @@ def send(self, msg, channel=None):

self._send(data, len(data))

def note_on(self, note, vel, channel=None):
"""Sends a MIDI Note On message.

:param int note: The note number. Must be 0-127.
:param int vel: The note velocity. Must be 0-127.

"""
self._generic_3(self.NOTE_ON, note, vel, channel)

def note_off(self, note, vel, channel=None):
"""Sends a MIDI Note Off message.

:param int note: The note number. Must be 0-127.
:param int vel: The note velocity. Must be 0-127.

"""
self._generic_3(self.NOTE_OFF, note, vel, channel)

def pitch_bend(self, value, channel=None):
"""Send a MIDI Pitch Wheel message.

:param int value: Range is 0-16383. A ``value`` of 8192 equates to no pitch bend, a value
of less than 8192 equates to a negative pitch bend, and a value of more
than 8192 equates to a positive pitch bend.

"""
self._generic_3(self.PITCH_BEND, value & 0x7F, value >> 7, channel)

def control_change(self, control, value, channel=None):
"""Sends a MIDI CC message.

:param int control: The controller number. Must be 0-127.
:param int value: The control value. Must be 0-127.

"""
self._generic_3(self.CONTROL_CHANGE, control, value, channel)

def _generic_3(self, cmd, arg1, arg2, channel=None):
if not 0 <= arg1 <= 0x7F:
raise RuntimeError("Argument 1 value %d invalid" % arg1)
if not 0 <= arg2 <= 0x7F:
raise RuntimeError("Argument 2 value %d invalid" % arg2)
if channel is None:
channel = self._out_channel
self._outbuf[0] = (cmd & 0xF0) | (channel & 0x0f)
self._outbuf[1] = arg1
self._outbuf[2] = arg2
self._send(self._outbuf, 3)

def _send(self, packet, num):
if self._debug:
print("Sending: ", [hex(i) for i in packet[:num]])
Expand Down
2 changes: 1 addition & 1 deletion examples/midi_intest1.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
print("Midi input test with pauses")

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

# play with the pause to simulate code doing other stuff
# in the loop
Expand Down
19 changes: 14 additions & 5 deletions examples/midi_simpletest.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
# simple_test
import time
import random
import usb_midi
import adafruit_midi
from adafruit_midi.control_change import ControlChange
from adafruit_midi.note_off import NoteOff
from adafruit_midi.note_on import NoteOn
from adafruit_midi.pitch_bend import PitchBend

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

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

while True:
midi.note_on(44, 120)
midi.note_off(44, 120)
midi.control_change(3, 44)
midi.pitch_bend(random.randint(0, 16383))
time.sleep(1)
midi.send(NoteOn(44, 120)) # G sharp 2nd octave
time.sleep(0.25)
a_pitch_bend = PitchBend(random.randint(0, 16383))
midi.send(a_pitch_bend)
time.sleep(0.25)
# note how a list of messages can be used
midi.send([NoteOff("G#2", 120),
ControlChange(3, 44)])
time.sleep(0.5)
37 changes: 0 additions & 37 deletions examples/midi_simpletest2.py

This file was deleted.