Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
print('------ OUTPUT ------')
for port in mido.get_output_names():
print(port)
print('-------------------------')
mididevice = config.get('midi', 'device')
try:
inputport = mido.open_input(mididevice)
if debug>0:
print "Connected to MIDI input"
except:
print "Error: cannot connect to MIDI input"
exit()
try:
outputport = mido.open_output(mididevice)
if debug>0:
print "Connected to MIDI output"
except:
print "Error: cannot connect to MIDI output"
exit()
try:
# channel 1-16 in the ini file should be mapped to 0-15
midichannel = config.getint('midi', 'channel')-1
except:
# this happens if it is not specified in the ini file
# it will be determined on the basis of the first incoming message
midichannel = None
push = [int(a) for a in config.get('button', 'push').split(",")]
toggle1 = [int(a) for a in config.get('button', 'toggle1').split(",")]
import time
import random
import mido
from mido import Message
if len(sys.argv) > 1:
portname = sys.argv[1]
else:
portname = None # Use default port
# A pentatonic scale
notes = [60, 62, 64, 67, 69, 72]
try:
with mido.open_output(portname, autoreset=True) as port:
print('Using {}'.format(port))
while True:
note = random.choice(notes)
on = Message('note_on', note=note)
print('Sending {}'.format(on))
port.send(on)
time.sleep(0.05)
off = Message('note_off', note=note)
print('Sending {}'.format(off))
port.send(off)
time.sleep(0.1)
except KeyboardInterrupt:
pass
elif vol == 'f':
stops = [3, 4, 5, 6, 7, 11, 12, 15, 16, 19, 20, 27,
32, 33, 34, 35, 36, 38, 45]
elif vol == 'ff':
stops = [3, 4, 5, 6, 7, 8, 10, 11, 12, 15, 16, 17, 19, 20, 21,
22, 25, 27, 31, 32, 33, 34, 35, 36, 37, 38, 40,
42, 45]
elif vol == 't':
stops = [3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 15, 16, 17, 19, 20, 21,
22, 24, 25, 26, 27, 31, 32, 33, 34, 35, 36, 37, 38, 40,
41, 42, 43, 45]
organ = "MidiSport 1x1:MidiSport 1x1 MIDI 1 20:0"
outport = mido.open_output(organ)
msg = mido.Message('sysex', data=[0, 74, 79, 72, 65, 83, 127])
outport.send(msg)
for i in stops:
msg = mido.Message('program_change', channel=11, program=i)
# print(msg)
outport.send(msg)
import mido
import time
import requests
from datadog import statsd
from tonal import Tonal, mapping
API_KEY = "ADD_PI_KEY_HERE"
GEO = "40.712784,-74.005941"
call = "https://api.forecast.io/forecast/{0}/{1}"
output = mido.open_output()
tonal = Tonal()
mid_range = tonal.create_sorted_midi("HarmonicMajor", "C")
weather = call.format(API_KEY, GEO)
start = time.time()
max_time = 100
values = dict()
old_values = dict()
chans = dict(
temp=1,
app_temp=2,
dew=3,
humidity=4,
visibility=5,
ozone=6,
windBearing=7
#!/usr/bin/env python3
# From: https://github.com/mido/mido
import mido
import time
import subprocess, signal, os
# See what ports are out there
# print(mido.get_output_names())
# print(mido.get_input_names())
organ = "MidiSport 1x1:MidiSport 1x1 MIDI 1 20:0"
outport = mido.open_output(organ)
mypath = 'midifiles'
from os import listdir
from os.path import isfile, join
files = [f for f in listdir(mypath) if isfile(join(mypath, f))]
offset = 3 # Number of tabs in to start
files.sort()
print(files)
print(len(files))
def lightsOn(count):
print("Sending cancel")
msg = mido.Message('sysex', data=[0, 74, 79, 72, 65, 83, 127])
monitor.info('------ INPUT ------')
for port in mido.get_input_names():
monitor.info(port)
monitor.info('------ OUTPUT ------')
for port in mido.get_output_names():
monitor.info(port)
monitor.info('-------------------------')
try:
inputport = mido.open_input(mididevice_input)
monitor.info("Connected to MIDI input")
except:
raise RuntimeError("cannot connect to MIDI input")
try:
outputport = mido.open_output(mididevice_output)
monitor.info("Connected to MIDI output")
except:
raise RuntimeError("cannot connect to MIDI output")
# channel 1-16 in the ini file should be mapped to 0-15
if not midichannel is None:
midichannel-=1
monitor.update('midichannel', midichannel)
# these are the MIDI values for the LED color
Off = 12
Red_Low = 13
Red_Full = 15
Amber_Low = 29
Amber_Full = 63
Yellow_Full = 62
# get the options from the configuration file
debug = patch.getint('general', 'debug')
# this is only for debugging, check which MIDI devices are accessible
monitor.info('------ OUTPUT ------')
for port in mido.get_output_names():
monitor.info(port)
monitor.info('-------------------------')
midichannel = patch.getint('midi', 'channel') - 1 # channel 1-16 get mapped to 0-15
mididevice = patch.getstring('midi', 'device')
mididevice = EEGsynth.trimquotes(mididevice)
mididevice = process.extractOne(mididevice, mido.get_output_names())[0] # select the closest match
try:
outputport = mido.open_output(mididevice)
monitor.success('Connected to MIDI output')
except:
raise RuntimeError("cannot connect to MIDI output")
# the scale and offset are used to map Redis values to MIDI values
scale = patch.getfloat('input', 'scale', default=127)
offset = patch.getfloat('input', 'offset', default=0)
# this is to prevent two messages from being sent at the same time
lock = threading.Lock()
# each of the notes that can be played is mapped onto a different trigger
trigger = []
for name, code in zip(note_name, note_code):
if config.has_option('note', name):
# start the background thread that deals with this note
else:
type_ = 'note_off'
note = note_mapping[button]
message = mido.Message(type_, channel=9, note=note, velocity=64)
print(message)
out.send(message)
if __name__ == '__main__':
import sys
import mido
with open('/dev/input/js0') as dev:
with mido.open_output('SD-20 Part A') as out:
try:
# play_drums(dev, out)
play_scale(dev, out)
finally:
panic(out)
port = None
# Loop through the files in the filelist
for now_playing_number, current_midi_filename in enumerate(filelist):
display_string = 'Playing Local File...\n{} of {}\n{}'.format(
now_playing_number+1, len(filelist), current_midi_filename)
midi_title = filetitles[now_playing_number]
# --------------------------------- REFRESH THE GUI ----------------------------------------- #
pback.PlayerPlaybackGUIUpdate(display_string)
# ---===--- Output Filename is .MID --- #
midi_filename = current_midi_filename
# --------------------------------- MIDI - STARTS HERE ----------------------------------------- #
if not port: # if the midi output port not opened yet, then open it
port = mido.open_output(midi_port if midi_port else None)
try:
mid = mido.MidiFile(filename=midi_filename)
except:
print(' Fail at playing Midi file = {}****'.format(midi_filename))
sg.popup_error('Exception trying to play MIDI file:',
midi_filename, 'Skipping file')
continue
# Build list of data contained in MIDI File using only track 0
midi_length_in_seconds = mid.length
display_file_list = '>> ' + \
'\n'.join([f for i, f in enumerate(
filetitles[now_playing_number:]) if i < 10])
paused = cancelled = next_file = False
######################### Loop through MIDI Messages ###########################
Example:
python serve_ports.py :8080 'SH-201' 'SD-20 Part A'
This simply iterates through all incoming messages. More advanced and
flexible servers can be written by calling the ``accept()`` and
``accept(block=False) methods directly. See PortServer.__init__() for
an example.
"""
import sys
import mido
from mido import sockets
from mido.ports import MultiPort
# Todo: do this with a argument parser.
out = MultiPort([mido.open_output(name) for name in sys.argv[2:]])
(host, port) = sockets.parse_address(sys.argv[1])
with sockets.PortServer(host, port) as server:
for message in server:
print('Received {}'.format(message))
out.send(message)