Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def connect(self):
print('Connecting MIDI devices')
mido.set_backend('mido.backends.rtmidi')
controllerNames = mido.get_input_names()
if not controllerNames: return
for name in controllerNames:
try:
cleanName = name[:name.rfind(' ')]
print("Connecting " + cleanName)
mido.open_input(name, callback=lambda m, cn=cleanName: self.onMessage(cn, m))
except Exception as e:
print('Unable to open MIDI input: {}'.format(name), file=sys.stderr)
# Setup GPIO buttons
for button in config.buttons['stomp_buttons']:
GPIO.setup(button, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.add_event_detect(button, GPIO.RISING, bouncetime=500, callback=buttonPressed)
# Setup events for bank up and down buttons
GPIO.setup(config.buttons['bank_button_up'], GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(config.buttons['bank_button_down'], GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.add_event_detect(config.buttons['bank_button_up'], GPIO.BOTH, bouncetime=500, callback=bank_change)
GPIO.add_event_detect(config.buttons['bank_button_down'], GPIO.BOTH, bouncetime=500, callback=bank_change)
# Display loading screen, will probably only display if clear_true is true
print_lcd("Loading...","")
# Backend stuff
mido.set_backend(config.katana['backend'])
# Load parameter metadata
rangeObj = Range(config.files['ranges_file'])
# Load presets
banks = PresetsHandler.load_presets(config.files['preset_file'])
# Setup amp
katana = Katana(config.katana['amp'], config.katana['channel'], config.katana['clear_input'])
print_lcd("Katana Ready", "Select Patch")
try:
while (True):
c = str(input("> "))
if c == "list":
for i in banks:
"""
Try out the new printer port backend.
It also works with MIDO_BACKEND, so you can do:
$ MIDO_BACKEND=printer python
>>> import mido
>>> mido.get_output_names()
['The Printer Port']
"""
import mido
mido.set_backend('printer')
print('Available outputs: {!r}'.format(mido.get_output_names()))
with mido.open_output() as port:
print('Using {}.'.format(port))
port.send(mido.Message('program_change', program=10))
for i in [1, 2, 3]:
port.send(mido.Message('control_change', control=1, value=i))
result.append( {"group":"simple", "category":category, "type":type} )
# Complex devices have distinct parameter address ranges, so do all
# colors
for category in self.complex:
for color in self.name2enum.keys():
idx = self.assign_index2[category][color]
type = katana.query_sysex_byte( assign_base_addr, idx )
result.append( {"group":"complex", "category":category, "type":type} )
return result
if __name__ == '__main__':
from katana import Katana
import mido
mido.set_backend('mido.backends.rtmidi')
args = sys.argv
buttonObj = ColorButtons( args[1] )
katana = Katana( "KATANA:KATANA MIDI 1 20:0", 1, False )
result = buttonObj.read_knobs( katana )
pprint( result )
result = buttonObj.read_color_assign( katana )
pprint( result )
_DEFAULT_METRONOME_PROGRAM = 117 # Melodic Tom
_DEFAULT_METRONOME_MESSAGES = [
mido.Message(type='note_on', note=44, velocity=64),
mido.Message(type='note_on', note=35, velocity=64),
mido.Message(type='note_on', note=35, velocity=64),
mido.Message(type='note_on', note=35, velocity=64),
]
_DEFAULT_METRONOME_CHANNEL = 1
# 0-indexed.
_DRUM_CHANNEL = 9
try:
# The RtMidi backend is easier to install and has support for virtual ports.
import rtmidi # pylint: disable=unused-import,g-import-not-at-top
mido.set_backend('mido.backends.rtmidi')
except ImportError:
# Tries to use PortMidi backend by default.
tf.logging.warn('Could not import RtMidi. Virtual ports are disabled.')
class MidiHubError(Exception): # pylint:disable=g-bad-exception-name
"""Base class for exceptions in this module."""
pass
def get_available_input_ports():
"""Returns a list of available input MIDI ports."""
return mido.get_input_names()
def get_available_output_ports():
def do_start_logging(self, midi_port_name):
logging.info("start midi logging on {}".format(midi_port_name))
self.do_stop_logging()
MidiLogMessageHandler.midi_port_name = midi_port_name
try:
mido.set_backend('mido.backends.rtmidi/UNIX_JACK')
MidiLogMessageHandler.mido_port = mido.open_input(self.midi_port_name, callback=self.on_midi_in)
except:
logging.error("Can't open MIDI Port {}".format(self.midi_port_name))
blocks = [ [global_base, global_parms['length']], [dsp_base, dsp_parms['length']] ]
# Both mod and fx share the same global key setting
if name == "PitchShifter":
extra = [ self.master_key['baseAddr'], self.master_key['length'] ]
blocks.append( extra )
return { "name":name, "blocks":blocks }
if __name__ == '__main__':
from katana import Katana
import mido
from color_buttons import ColorButtons
mido.set_backend('mido.backends.rtmidi')
args = sys.argv
buttonObj = ColorButtons( args[1] )
katana = Katana( "KATANA:KATANA MIDI 1 20:0", 1, False )
dsp_recs = buttonObj.read_knobs( katana )
# pprint( dsp_recs )
complexObj = ComplexDSP( args[2] )
for dsp_rec in dsp_recs:
if dsp_rec['group'] == 'complex':
coords = complexObj.get_coords( dsp_rec['category'], dsp_rec['type'] )
print( "Name: ", coords['name'], ", Blocks: ", coords['blocks'] )
# coding: utf-8
import mido
from wcwidth import wcswidth
from pgpal.compat import pg, textwrap, unicode_literals
from pgpal.configpage import pyform
from pgpal.const import *
from pgpal import configspec, config, vdt
mido.set_backend('mido.backends.pygame')
translations = {
'path': '目录',
'volume': '音量',
'chip': '芯片',
'full': '全',
'screen': '屏',
'use': '使用',
'font': '字体',
'file': '文件',
'samplerate': '采样率',
'window': '窗口',
'music': '音乐',
'game': '游戏',
'enable': '启用',
'port': '端口',