Skip to content

Commit

Permalink
New Input Method
Browse files Browse the repository at this point in the history
No longer compatible with mac due to change of keyboard library.
  • Loading branch information
LordHenryVonHenry committed May 16, 2023
1 parent 4f50f77 commit 5b6b99c
Show file tree
Hide file tree
Showing 121 changed files with 117 additions and 8 deletions.
Binary file removed FolderOutput/MidiConnect.rar
Binary file not shown.
Binary file removed FolderOutput/MidiConnect/MidiConnect.exe
Binary file not shown.
Binary file removed FolderOutput/MidiConnect/PyQt5/Qt5/bin/Qt5Core.dll
Binary file not shown.
Binary file removed FolderOutput/MidiConnect/PyQt5/Qt5/bin/Qt5DBus.dll
Binary file not shown.
Binary file removed FolderOutput/MidiConnect/PyQt5/Qt5/bin/Qt5Gui.dll
Binary file not shown.
Binary file not shown.
Binary file removed FolderOutput/MidiConnect/PyQt5/Qt5/bin/Qt5Qml.dll
Binary file not shown.
Binary file not shown.
Binary file removed FolderOutput/MidiConnect/PyQt5/Qt5/bin/Qt5Quick.dll
Binary file not shown.
Binary file removed FolderOutput/MidiConnect/PyQt5/Qt5/bin/Qt5Svg.dll
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed FolderOutput/MidiConnect/PyQt5/Qt5/bin/libEGL.dll
Binary file not shown.
Binary file removed FolderOutput/MidiConnect/PyQt5/Qt5/bin/libGLESv2.dll
Binary file not shown.
Binary file removed FolderOutput/MidiConnect/PyQt5/Qt5/bin/msvcp140.dll
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

This file was deleted.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed FolderOutput/MidiConnect/PyQt5/QtCore.pyd
Binary file not shown.
Binary file removed FolderOutput/MidiConnect/PyQt5/QtGui.pyd
Binary file not shown.
Binary file removed FolderOutput/MidiConnect/PyQt5/QtWidgets.pyd
Binary file not shown.
Binary file not shown.
Binary file removed FolderOutput/MidiConnect/VCRUNTIME140.dll
Binary file not shown.
Binary file removed FolderOutput/MidiConnect/_bz2.pyd
Binary file not shown.
Binary file removed FolderOutput/MidiConnect/_ctypes.pyd
Binary file not shown.
Binary file removed FolderOutput/MidiConnect/_decimal.pyd
Binary file not shown.
Binary file removed FolderOutput/MidiConnect/_hashlib.pyd
Binary file not shown.
Binary file removed FolderOutput/MidiConnect/_lzma.pyd
Binary file not shown.
Binary file removed FolderOutput/MidiConnect/_queue.pyd
Binary file not shown.
Binary file removed FolderOutput/MidiConnect/_socket.pyd
Binary file not shown.
Binary file removed FolderOutput/MidiConnect/_ssl.pyd
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed FolderOutput/MidiConnect/base_library.zip
Binary file not shown.
Binary file removed FolderOutput/MidiConnect/libcrypto-1_1.dll
Binary file not shown.
Binary file removed FolderOutput/MidiConnect/libffi-7.dll
Binary file not shown.
Binary file removed FolderOutput/MidiConnect/libssl-1_1.dll
Binary file not shown.
Binary file removed FolderOutput/MidiConnect/python3.dll
Binary file not shown.
Binary file removed FolderOutput/MidiConnect/python310.dll
Binary file not shown.
Binary file not shown.
Binary file removed FolderOutput/MidiConnect/select.pyd
Binary file not shown.
Binary file removed FolderOutput/MidiConnect/ucrtbase.dll
Binary file not shown.
Binary file removed FolderOutput/MidiConnect/unicodedata.pyd
Binary file not shown.
Binary file modified MidiConnect.exe
Binary file not shown.
124 changes: 117 additions & 7 deletions MidiConnectSource/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@
import mido
from mido import MidiFile
import pynput
import math
import mido.backends.rtmidi
import pydirectinput
kb = pynput.keyboard
keyboard = kb.Controller()

ConnectThread = QThread()
PlayThread = QThread()
ProgressThread = QThread()
app = None
Expand All @@ -30,6 +32,30 @@
playback_time = 0
total_pause = 0
LengthString = None
SelectedMidiPort = None

class Keys:
NUM0 = 'num0'
NUM1 = 'numpad1'
NUM2 = 'numpad2'
NUM3 = 'numpad3'
NUM4 = 'numpad4'
NUM5 = 'numpad5'
NUM6 = 'numpad6'
NUM7 = 'numpad7'
NUM8 = 'numpad8'
NUM9 = 'numpad9'
pydirectinput.PAUSE = 0
pydirectinput.KEYBOARD_MAPPING[Keys.NUM0] = 0x52
pydirectinput.KEYBOARD_MAPPING[Keys.NUM1] = 0x4F
pydirectinput.KEYBOARD_MAPPING[Keys.NUM2] = 0x50
pydirectinput.KEYBOARD_MAPPING[Keys.NUM3] = 0x51
pydirectinput.KEYBOARD_MAPPING[Keys.NUM4] = 0x4B
pydirectinput.KEYBOARD_MAPPING[Keys.NUM5] = 0x4C
pydirectinput.KEYBOARD_MAPPING[Keys.NUM6] = 0x4D
pydirectinput.KEYBOARD_MAPPING[Keys.NUM7] = 0x47
pydirectinput.KEYBOARD_MAPPING[Keys.NUM8] = 0x48
pydirectinput.KEYBOARD_MAPPING[Keys.NUM9] = 0x49

class Worker2(QObject):
finished = pyqtSignal()
Expand Down Expand Up @@ -99,6 +125,23 @@ def run(self):
print("Thread 1 Finished")
self.finished.emit()

class Worker3(QObject):
finished = pyqtSignal()
progress = pyqtSignal(int)

def run(self):
print("Thread 3 Start")
global SelectedMidiPort
try:
with mido.open_input(SelectedMidiPort) as inport:
for msg in inport:
ProcessMsg(msg)
except:
print("Error")

print("Thread 1 Finished")
self.finished.emit()

class Window(QMainWindow):
def __init__(self):
super().__init__()
Expand Down Expand Up @@ -271,12 +314,22 @@ def ConnectInput():
if Selected in AvailableInputs:
print("Input Found, Connecting")
print("Connecting to "+Selected)
try:
with mido.open_input(Selected) as inport:
for msg in inport:
ProcessMsg(msg)
except:
print("Error")
global SelectedMidiPort
SelectedMidiPort = Selected
self.thread3 = ConnectThread
self.worker3 = Worker3()
self.worker3.moveToThread(self.thread3)
self.thread3.started.connect(self.worker3.run)
self.worker3.finished.connect(self.thread3.quit)
self.worker3.finished.connect(self.worker3.deleteLater)
self.thread3.start()
#
#try:
# with mido.open_input(Selected) as inport:
# for msg in inport:
# ProcessMsg(msg)
#except:
# print("Error")
pass

InputConnectButton.clicked.connect(ConnectInput)
Expand Down Expand Up @@ -338,7 +391,64 @@ def onDel():
def for_canonical(f):
return lambda k: f(listener.canonical(k))

def SendKey(KeyCode):
#keyboard.press(kb.KeyCode.from_vk(KeyCode))
#keyboard.release(kb.KeyCode.from_vk(KeyCode))
pydirectinput.press(KeyCode)
#pydirectinput.keyDown(KeyCode)
#pydirectinput.keyUp(KeyCode)
def get_digit(number, n):
return number // 10 ** n % 10


def ProcessMsg(msg):

if msg.type == "clock":
pass
elif msg.type == "note_on":
Array = ['num0', 'numpad1', 'numpad2', 'numpad3', 'numpad4', 'numpad5', 'numpad6', 'numpad7', 'numpad8', 'numpad9', 'subtract', 'add']
print(str(msg.note) + " " + str(msg.velocity))
ToSend = [math.floor(msg.note/12),math.floor(msg.note%12),math.floor(msg.velocity/12),math.floor(msg.velocity%12)]

SendKey('multiply')
for x in ToSend:
SendKey(Array[x])
pass
elif msg.type == "note_off":
Array = ['num0', 'numpad1', 'numpad2', 'numpad3', 'numpad4', 'numpad5', 'numpad6', 'numpad7', 'numpad8',
'numpad9', 'subtract', 'add']
print(str(msg.note) + " " + str(msg.velocity))
ToSend = [math.floor(msg.note / 12), math.floor(msg.note % 12), 0,0]

SendKey('multiply')
for x in ToSend:
SendKey(Array[x])
pass
elif msg.type == "control_change":
control = None
if msg.control == 64:
control = 143
if control:
Array = ['num0', 'numpad1', 'numpad2', 'numpad3', 'numpad4', 'numpad5', 'numpad6', 'numpad7', 'numpad8',
'numpad9', 'subtract', 'add']
ToSend = [math.floor(control / 12), math.floor(control % 12),math.floor(msg.value / 12), math.floor(msg.value % 12)]

SendKey('multiply')
for x in ToSend:
SendKey(Array[x])
#Array = [96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 109, 107]#110 111 cuz roblox keycodes differ
#ToSend = [math.floor(msg.control / 12), math.floor(msg.value % 12), 0, 0]
#keyboard.press(kb.KeyCode.from_vk(107))
#keyboard.release(kb.KeyCode.from_vk(107))
#for x in ToSend:
# keyboard.press(kb.KeyCode.from_vk(Array[x]))
# keyboard.release(kb.KeyCode.from_vk(Array[x]))
pass
else:
print(msg)


def ProcessMsg2(msg):
if msg.type == "clock":
pass
elif msg.type == "note_on":
Expand Down

0 comments on commit 5b6b99c

Please sign in to comment.