diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..c90a468 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,26 @@ +name: Tests + +on: + - push + - pull_request + +jobs: + test: + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest, windows-latest] + python-version: ['3.8', '3.9'] + + steps: + - uses: actions/checkout@v2 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install tox tox-gh-actions + - name: Test with tox + run: tox \ No newline at end of file diff --git a/README.md b/README.md index 04057cb..dc2068e 100644 --- a/README.md +++ b/README.md @@ -26,37 +26,4 @@ To do so add a custom patch (or use a currently defined one, but chances are pat * 56/cond = lambda x: x==50 # Function choosing conditions on the value to send * 57/toggle = 0/127: Toggle the val between 127 and 0 every time the note is received * 68/func = functionMappedInTheMappingInterface(note,intensity,parameters) - -# Adding another mapping interface -* TODO: Explain it better than just "look at the ones I made" - -# Improvements -* Better note / cc / pc notation -* Add Fade (in ms) from one value to another -* Have a way to know last value for the note/cc (the last one sent/received) -* Make toggles a function modifying a variable/state and sending result -* Allow for a multi-in interfaces -* TODO: More testing for null interface out -* URGENT : /funct with an existing trigger might not work, should be with an empty trigger anyway. -* Add asynchroneous mode ? -* URGENT : Crash when assigning to an existing trigger -* TODO: Make a @armtake decorator -* TODO: Async and Disconnection protect for VPs -* TODO: Disconnect: 'NoneType' object has no attribute 'groups' : Should handle disconnect & Crashes -* TODO: Color and uncolor VP as it connects -* TODO: Unified verbose printing & usage - - -* TODO: Pagehandler: make a note handler -* TODO: Color management, get colors associated to all statuses -* TODO: General decorators @armtake - -* URGENT : Fix the connection issue -* TODO: More explicit midi output/input connection error (and backup or exit) -* TODO: CLEAN CONNECTION TO A RACK, ANYTHING BUT THIS CLUSTERFCK -* TODO: Connect the IOHandler with handler, binding and vice-versa, check some. -* TODO : Clean this step : Do a better IO handler -* URGENT : Error on non existing patch is incorrect (win) -* URGENT : line 341, in POSTMATCH_SCRNUPD / if match.group("postargs")[-1]=="1" trigger out of range on incorrect formatted return args (no args) -* TODO: Get rid of match.group("postargs").split -* TODO: clean the dprint("Using RM/Forb") and maybe rebind some of it \ No newline at end of file + \ No newline at end of file diff --git a/TODO.md b/TODO.md new file mode 100644 index 0000000..99b9640 --- /dev/null +++ b/TODO.md @@ -0,0 +1,38 @@ + +# Adding another mapping interface +* TODO: Explain it better than just "look at the ones I made" + +# Improvements +* Better note / cc / pc notation +* Add Fade (in ms) from one value to another +* Have a way to know last value for the note/cc (the last one sent/received) +* Make toggles a function modifying a variable/state and sending result +* Allow for a multi-in interfaces +* TODO: More testing for null interface out +* URGENT : /funct with an existing trigger might not work, should be with an empty trigger anyway. +* Add asynchronous mode ? +* URGENT : Crash when assigning to an existing trigger +* TODO: Make an @armtake decorator +* TODO: Async and Disconnection protect for VPs +* TODO: Disconnect: 'NoneType' object has no attribute 'groups' : Should handle disconnect & Crashes +* TODO: Color and un-color VP as it connects +* TODO: Unified verbose printing & usage + + +* TODO: Pagehandler: make a note handler +* TODO: Color management, get colors associated to all statuses +* TODO: General decorators @armtake + +* URGENT : Fix the connection issue +* TODO: More explicit midi output/input connection error (and backup or exit) +* TODO: CLEAN CONNECTION TO A RACK, ANYTHING BUT THIS CLUSTERF*CK +* TODO: Connect the IOHandler with handler, binding and vice-versa, check some. +* TODO : Clean this step : Do a better IO handler +* URGENT : Error on non-existing patch is incorrect (win) +* URGENT : line 341, in POSTMATCH_SCRNUPD / if match.group("postargs")[-1]=="1" trigger out of range on incorrect formatted return args (no args) +* TODO: Get rid of match.group("postargs").split +* TODO: Asyncio lib to clean up the whole pyAnalogWay (which was neat but cumbersome) +* TODO: Use logging instead of this clusterfk +* TODO: Sysexit not working +* URGENT: Network interruption not working +* TODO: Empty triggers should give a little more info \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..cf4144c --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,27 @@ +[build-system] +requires = ["setuptools>=42.0", "wheel"] +build-backend = "setuptools.build_meta" + +[tool.pytest.ini_options] +addopts = ["--cov=midiRebind", +# "--cov=midiRebind/pythonAnalogWay", +# "--cov=midiRebind/panaremote", +] +testpaths = [ + "tests", +] + +[tool.mypy] +mypy_path = "src" +check_untyped_defs = true +disallow_any_generics = true +ignore_missing_imports = true +no_implicit_optional = true +show_error_codes = true +strict_equality = true +warn_redundant_casts = true +warn_return_any = true +warn_unreachable = true +warn_unused_configs = true +no_implicit_reexport = true + diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..fb0d7ab --- /dev/null +++ b/requirements.txt @@ -0,0 +1,4 @@ +urllib3~=1.26.4 +setuptools>=52.0.0 +mido~=1.2.9 +python-rtmidi~=1.4.1 diff --git a/requirements_dev.txt b/requirements_dev.txt new file mode 100644 index 0000000..436cd19 --- /dev/null +++ b/requirements_dev.txt @@ -0,0 +1,51 @@ +pytest==6.2.5 +pytest-cov==2.12.1 +mypy===0.910 +alabaster==0.7.12 +appdirs==1.4.4 +atomicwrites==1.4.0 +attrs==20.2.0 +Babel==2.9.1 +certifi==2020.6.20 +chardet==3.0.4 +coverage==5.3 +Cython==0.29.21 +distlib==0.3.1 +docutils==0.16 +filelock==3.0.12 +flake8==3.8.4 +idna==2.8 +imagesize==1.2.0 +iniconfig==1.0.1 +Jinja2==2.11.3 +MarkupSafe==1.1.1 +mccabe==0.6.1 +mock==4.0.2 +more-itertools==8.5.0 +packaging==20.4 +pbr==5.5.0 +pluggy==0.13.1 +py==1.10.0 +pycodestyle==2.6.0 +pydocstyle==5.1.1 +pyflakes==2.2.0 +Pygments==2.7.4 +pyparsing==2.4.7 +pytest==6.1.1 +pytz==2020.1 +requests==2.24.0 +six==1.15.0 +snowballstemmer==2.0.0 +Sphinx==3.2.1 +sphinxcontrib-applehelp==1.0.2 +sphinxcontrib-devhelp==1.0.2 +sphinxcontrib-htmlhelp==1.0.3 +sphinxcontrib-jsmath==1.0.1 +sphinxcontrib-qthelp==1.0.3 +sphinxcontrib-serializinghtml==1.1.4 +sphinxcontrib-websupport==1.2.4 +sphinx-rtd-theme==0.5.0 +toml==0.10.1 +tox==3.20.0 +urllib3==1.26.5 +virtualenv==20.0.33 \ No newline at end of file diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..513279b --- /dev/null +++ b/setup.cfg @@ -0,0 +1,45 @@ +[metadata] +name=midiRebind +description=A python midi rebinder +author=Dandaedre +license=GPLv3 +licence_file=LICENCE +version = 0.0.1 +platforms=unix,linux,osx,cygwin,win32 +classifier = + Programming Language :: Python :: 3 + +[options] +version=0.1a +packages= + midiRebind +; midiRebind/panaremote +; midiRebind/pythonAnalogWay +; midiRebind/minitest +install_requires= + mido>=1.2.9 + python-rtmidi>=1.4.1 +python_requires = >=3.8 +package_dir= + =src +zip_safe=no + +[options.extras_require] +testing = + pytest>=6.0 + pytest-cov>=2.0 + mypy>=0.910 + flake8>=3.9 + tox>=3.24 + libasound2>=1.1.3 + libasound2-dev>=1.1.3 + libjack>=1.9.9 + libjack-dev>=1.9.9 + +[options.package_data] +midiRebind=py.typed + +[flake8] +max-line-length=160 +select = E +extend-ignore = E \ No newline at end of file diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_midiRebind.py b/tests/test_midiRebind.py new file mode 100644 index 0000000..3bcfcf8 --- /dev/null +++ b/tests/test_midiRebind.py @@ -0,0 +1,278 @@ +import configparser + +import mido + +from src.midiRebind.minitest import minitest + + +# from mapping import GrandMA2 + +class GmaPyTest(minitest.simpleTestUnit): + """Testing the General interface""" + + def __init__(self): + super(GmaPyTest, self).__init__("gmaPy") + + def _test_custom(self): + self.currentTest("testing true") + if True: + self.addSuccess() + + +class MappingTest(minitest.simpleTestUnit): + """Testing the parsing/mapping""" + + def __init__(self): + super(MappingTest, self).__init__("parsing/mapping") + self.verbose = True + + def _test_parsing(self): + self.currentTest("Loading default mappings") + from src.midiRebind.mapping import GrandMA2 + self.gm = GrandMA2 + self.addSuccess() + + self.currentTest("Creating Parser") + self.parser = GrandMA2.MessageParse() + self.addSuccess() + + self.currentTest("Testing hex2dec") + testX = ["22", "19 22", "3 4 5 6 22 FF"] + testD = [[34], [25, 34], [3, 4, 5, 6, 34, 255]] + success = 1 + for X, D in zip(testX, testD): + # print("{} / {} : {} [{}]".format(X,D,self.toDec(X),D==self.toDec(X))) + if toDec(X) != D: + self.addFailure("Can't convert Hex to Dec") + success = 0 + break + if success: + self.addSuccess() + + # I'm ignoring the None case on purpose because I can't be bothered with, if it fails, it might as well fail big + self.currentTest("Test with ill-formed message") + if self.testParse([22, 12]): + self.addFailure("The message is not supposed to be parsed") + else: + self.addSuccess() + + self.currentTest("Test with well-formed message") + msg = toDec("7F 7F 02 7F 01 32 31 2E 35 30 30") + if self.testParse(msg): + self.addSuccess() + else: + self.addFailure("Can't parse the message {}".format(msg)) + + self.currentTest("Checking sanity of parse") + di = self.parser(mido.Message("sysex", data=msg)) + inc = "" + if di.command != 1: + inc = "command {} ".format(di.command) + if list(di.data) != [50, 49, 46, 53, 48, 48]: + inc += "data {} ".format(di.data) + if di.deviceid != 127: + inc += "deviceid {} ".format(di.deviceid) + if di.commandformat != 127: + inc += "commandformat {}".format(di.commandformat) + if inc == "": + self.addSuccess() + else: + self.addFailure("Incorrect fields: " + inc[:-1]) + + self.currentTest("Loading Config") + try: + def testfunction(*params): + print("| > testfunction used in test", params) + return 1 + + class Emptyconfig: + def __init__(self, configfile): + self.config = configparser.ConfigParser() + self.config.read(configfile) + self.functionlist = {"testfunction": testfunction} + + def interface_out(self, nb): + class EmptySender(): + def __init__(self): + self.name = "none:none" + pass + + def send(self, wev, **kwargs): + pass + + return EmptySender() + + self.e_config = Emptyconfig("patch/test.ini") + self.act = GrandMA2.Actions(self.e_config) + self.addSuccess() + except IOError: + self.addFailure("Can't load config file") + + # self.act.prettyprint() + self.currentTest("Testing the request formatter") + try: + self.act.findAction("set", "1", "1") + try: + self.act.findAction("set", "2", "3") + self.addFailure("Not supposed to load page 3") + except: + try: + self.act.findAction("fire", "13", "2") + self.addSuccess() + except: + self.addFailure("Can't access the fire section") + except: + self.addFailure("Can't get (note 1 on page 1)") + + self.currentTest("Testing the loaded config") + try: + if len(self.act.findAction("set", 1, '5')) == 2: + self.addSuccess() + else: + self.addFailure("Action 1 section 5 (set/5) is supposed to contain 2 elements") + except: + self.addFailure("Can't find action 1 (set/5)") + # A couple more test would be wise, but nearing completion seems more important atm + + self.currentTest("Testing a message") + try: + self.act.findAction("set", 1, "5") + self.addSuccess() + except: + self.addFailure("Failed to load action") + + self.currentTest("Testing the valuefn") + try: + acts = self.act.findAction("set", 56, "1") + for act in acts: + if act.valuefn(51) == 100: + self.addSuccess() + except: + self.addFailure("Function for key {} isn't working".format(56)) + + self.currentTest("Testing the toggle") + try: + st = True + acts = self.act.findAction("fire", 38, "1") + for act in acts: + if not act.toggle: + self.addFailure("Trigger isn't assigned") + st = False + break + except: + self.addFailure("Toggle for key 38 isn't assigned") + st = False + if st: + self.addSuccess() + + self.currentTest("Testing custom function") + try: + st = True + acts = self.act.findAction("custom", 77, "2") + # print(acts) + for act in acts: + # print(act,act.funct) + if not act.funct or not act.execspecialfn(55): + st = False + self.addFailure("No custom function defined") + break + except KeyError: + self.addFailure("Can't use custom function") + st = False + if st: + self.addSuccess() + + self.currentTest("Testing call") + acts = self.act.findAction("fire", 38, "1") + for act in acts: + act(12) + st = act.toggle + act(12) + st1 = act.toggle + if st == st1: + self.addFailure("State not changing after a call") + # self.act.prettyprint() + + def testParse(self, message): + try: + message = mido.Message("sysex", data=message) + parsed = self.parser(message) + return True + except self.gm.MatchError: + return False + except: + import sys + print(sys.exc_info()) + self.addCritical("Can't parse (not supposed to happen)") + + +def toDec(message): + """Taken care of by mido, but testing needs to be done otherwise""" + res = [] + for hx in message.split(" "): + if res == []: + res = [int(hx, 16)] + else: + res += [int(hx, 16)] + return res + + +class ConfigTest(minitest.simpleTestUnit): + def __init__(self): + super(ConfigTest, self).__init__("Testing the config loader") + + def _testAll(self): + self.currentTest("Loading config") + from src.midiRebind.mapping import GrandMA2 + GrandMA2.MidiInterface("patch/test.ini") + self.addSuccess() + + +class LiveTest(minitest.simpleTestUnit): + def __init__(self): + super(LiveTest, self).__init__("Live test") + + def _testAll(self): + self.currentTest("Loading config") + from src.midiRebind.mapping import GrandMA2 + Inter = GrandMA2.MidiInterface("patch/test.ini") + self.addSuccess() + + self.currentTest("Loading message parser") + Par = GrandMA2.MessageParse() + self.addSuccess() + + self.currentTest("Loading Patch") + + # print(GrandMA2.Actions) + + Acts = GrandMA2.Actions(Inter) + self.addSuccess() + # Act.prettyprint() + + self.currentTest("Trying match") + + message = toDec("7F 7F 02 7F 01 33 37 2E 32 30 30 00 35 20 31") + message = toDec("7F 7F 02 7F 06 02 02 4C 39") + match = None + try: + match = Par(mido.Message("sysex", data=message)) + self.addSuccess() + except GrandMA2.MatchError: + self.addFailure("Can't match '{}'".format(mido.Message(message))) + except: + self.addFailure("Error while matching") + + self.currentTest("Sending message") + match = Acts(match) + self.addSuccess() + + +if __name__ == '__main__': + + allTests = minitest.testGroup("Nominal test units", verbose=True, align=50) + + allTests.addTest(MappingTest()) + allTests.addTest(ConfigTest()) + allTests.addTest(LiveTest()) + allTests.test() diff --git a/tests/test_panaremote.py b/tests/test_panaremote.py new file mode 100644 index 0000000..cf2bc9b --- /dev/null +++ b/tests/test_panaremote.py @@ -0,0 +1,6 @@ +import midiRebind +from midiRebind import panaremote, pythonAnalogWay + + +def test_panaremote(): + print(panaremote, midiRebind, pythonAnalogWay) diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..8e1ae34 --- /dev/null +++ b/tox.ini @@ -0,0 +1,28 @@ +[tox] +minversion = 3.8.0 +envlist = py38, flake8, mypy +isolated_build = true + +[gh-actions] +python = + 3.8: py38, mypy, flake8 + 3.9: py39 + +[testenv] +setenv = + PYTHONPATH = {toxinidir} +deps = + -r{toxinidir}/requirements_dev.txt +commands = + pytest --basetemp={envtmpdir} + +[testenv:flake8] +basepython = python3.8 +deps = flake8 +commands = flake8 src tests + +[testenv:mypy] +basepython = python3.8 +deps = + -r{toxinidir}/requirements_dev.txt +commands = mypy src \ No newline at end of file