commit 6bcd0af329f62f5a64a3bf29726630f18ae777b0 Author: soyouzpanda Date: Wed Dec 20 18:27:24 2023 +0100 Finished K-Fêt config diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..d4a2c44 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,21 @@ +# http://editorconfig.org + +root = true + +[*] +indent_style = space +indent_size = 4 +trim_trailing_whitespace = true +insert_final_newline = true +charset = utf-8 +end_of_line = lf + +[*.bat] +indent_style = tab +end_of_line = crlf + +[LICENSE] +insert_final_newline = false + +[Makefile] +indent_style = tab diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md new file mode 100644 index 0000000..6ab88ba --- /dev/null +++ b/.github/ISSUE_TEMPLATE.md @@ -0,0 +1,15 @@ +* eos-midi version: +* Python version: +* Operating System: + +### Description + +Describe what you were trying to get done. +Tell us what happened, what went wrong, and what you expected to happen. + +### What I Did + +``` +Paste the command(s) you ran and the output. +If there was a crash, please include the traceback here. +``` diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4c915d1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,106 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +env/ +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +*.egg-info/ +.installed.cfg +*.egg + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +.hypothesis/ +.pytest_cache/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# pyenv +.python-version + +# celery beat schedule file +celerybeat-schedule + +# SageMath parsed files +*.sage.py + +# dotenv +.env + +# virtualenv +.venv +venv/ +ENV/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ + +# IDE settings +.vscode/ +.idea/ diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..a44b0b9 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,28 @@ +# Config file for automatic testing at travis-ci.com + +language: python +python: + - 3.8 + - 3.7 + - 3.6 + +# Command to install dependencies, e.g. pip install -r requirements.txt --use-mirrors +install: pip install -U tox-travis + +# Command to run tests, e.g. python setup.py test +script: tox + +# Assuming you have installed the travis-ci CLI tool, after you +# create the Github repo and add it to Travis, run the +# following command to finish PyPI deployment setup: +# $ travis encrypt --add deploy.password +deploy: + provider: pypi + distributions: sdist bdist_wheel + user: soyouzpanda + password: + secure: PLEASE_REPLACE_ME + on: + tags: true + repo: soyouzpanda/eos_midi + python: 3.8 diff --git a/AUTHORS.rst b/AUTHORS.rst new file mode 100644 index 0000000..78d8c68 --- /dev/null +++ b/AUTHORS.rst @@ -0,0 +1,13 @@ +======= +Credits +======= + +Development Lead +---------------- + +* soyouzpanda + +Contributors +------------ + +None yet. Why not be the first? diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst new file mode 100644 index 0000000..5c04831 --- /dev/null +++ b/CONTRIBUTING.rst @@ -0,0 +1,128 @@ +.. highlight:: shell + +============ +Contributing +============ + +Contributions are welcome, and they are greatly appreciated! Every little bit +helps, and credit will always be given. + +You can contribute in many ways: + +Types of Contributions +---------------------- + +Report Bugs +~~~~~~~~~~~ + +Report bugs at https://github.com/soyouzpanda/eos_midi/issues. + +If you are reporting a bug, please include: + +* Your operating system name and version. +* Any details about your local setup that might be helpful in troubleshooting. +* Detailed steps to reproduce the bug. + +Fix Bugs +~~~~~~~~ + +Look through the GitHub issues for bugs. Anything tagged with "bug" and "help +wanted" is open to whoever wants to implement it. + +Implement Features +~~~~~~~~~~~~~~~~~~ + +Look through the GitHub issues for features. Anything tagged with "enhancement" +and "help wanted" is open to whoever wants to implement it. + +Write Documentation +~~~~~~~~~~~~~~~~~~~ + +eos-midi could always use more documentation, whether as part of the +official eos-midi docs, in docstrings, or even on the web in blog posts, +articles, and such. + +Submit Feedback +~~~~~~~~~~~~~~~ + +The best way to send feedback is to file an issue at https://github.com/soyouzpanda/eos_midi/issues. + +If you are proposing a feature: + +* Explain in detail how it would work. +* Keep the scope as narrow as possible, to make it easier to implement. +* Remember that this is a volunteer-driven project, and that contributions + are welcome :) + +Get Started! +------------ + +Ready to contribute? Here's how to set up `eos_midi` for local development. + +1. Fork the `eos_midi` repo on GitHub. +2. Clone your fork locally:: + + $ git clone git@github.com:your_name_here/eos_midi.git + +3. Install your local copy into a virtualenv. Assuming you have virtualenvwrapper installed, this is how you set up your fork for local development:: + + $ mkvirtualenv eos_midi + $ cd eos_midi/ + $ python setup.py develop + +4. Create a branch for local development:: + + $ git checkout -b name-of-your-bugfix-or-feature + + Now you can make your changes locally. + +5. When you're done making changes, check that your changes pass flake8 and the + tests, including testing other Python versions with tox:: + + $ flake8 eos_midi tests + $ python setup.py test or pytest + $ tox + + To get flake8 and tox, just pip install them into your virtualenv. + +6. Commit your changes and push your branch to GitHub:: + + $ git add . + $ git commit -m "Your detailed description of your changes." + $ git push origin name-of-your-bugfix-or-feature + +7. Submit a pull request through the GitHub website. + +Pull Request Guidelines +----------------------- + +Before you submit a pull request, check that it meets these guidelines: + +1. The pull request should include tests. +2. If the pull request adds functionality, the docs should be updated. Put + your new functionality into a function with a docstring, and add the + feature to the list in README.rst. +3. The pull request should work for Python 3.5, 3.6, 3.7 and 3.8, and for PyPy. Check + https://travis-ci.com/soyouzpanda/eos_midi/pull_requests + and make sure that the tests pass for all supported Python versions. + +Tips +---- + +To run a subset of tests:: + + + $ python -m unittest tests.test_eos_midi + +Deploying +--------- + +A reminder for the maintainers on how to deploy. +Make sure all your changes are committed (including an entry in HISTORY.rst). +Then run:: + +$ bump2version patch # possible: major / minor / patch +$ git push +$ git push --tags + +Travis will then deploy to PyPI if tests pass. diff --git a/HISTORY.rst b/HISTORY.rst new file mode 100644 index 0000000..2aa0b07 --- /dev/null +++ b/HISTORY.rst @@ -0,0 +1,8 @@ +======= +History +======= + +0.1.0 (2023-12-17) +------------------ + +* First release on PyPI. diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..007d7b0 --- /dev/null +++ b/LICENSE @@ -0,0 +1,22 @@ +MIT License + +Copyright (c) 2023, soyouzpanda + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..965b2dd --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1,11 @@ +include AUTHORS.rst +include CONTRIBUTING.rst +include HISTORY.rst +include LICENSE +include README.rst + +recursive-include tests * +recursive-exclude * __pycache__ +recursive-exclude * *.py[co] + +recursive-include docs *.rst conf.py Makefile make.bat *.jpg *.png *.gif diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..7c33cd4 --- /dev/null +++ b/Makefile @@ -0,0 +1,87 @@ +.PHONY: clean clean-build clean-pyc clean-test coverage dist docs help install lint lint/flake8 +.DEFAULT_GOAL := help + +define BROWSER_PYSCRIPT +import os, webbrowser, sys + +from urllib.request import pathname2url + +webbrowser.open("file://" + pathname2url(os.path.abspath(sys.argv[1]))) +endef +export BROWSER_PYSCRIPT + +define PRINT_HELP_PYSCRIPT +import re, sys + +for line in sys.stdin: + match = re.match(r'^([a-zA-Z_-]+):.*?## (.*)$$', line) + if match: + target, help = match.groups() + print("%-20s %s" % (target, help)) +endef +export PRINT_HELP_PYSCRIPT + +BROWSER := python -c "$$BROWSER_PYSCRIPT" + +help: + @python -c "$$PRINT_HELP_PYSCRIPT" < $(MAKEFILE_LIST) + +clean: clean-build clean-pyc clean-test ## remove all build, test, coverage and Python artifacts + +clean-build: ## remove build artifacts + rm -fr build/ + rm -fr dist/ + rm -fr .eggs/ + find . -name '*.egg-info' -exec rm -fr {} + + find . -name '*.egg' -exec rm -f {} + + +clean-pyc: ## remove Python file artifacts + find . -name '*.pyc' -exec rm -f {} + + find . -name '*.pyo' -exec rm -f {} + + find . -name '*~' -exec rm -f {} + + find . -name '__pycache__' -exec rm -fr {} + + +clean-test: ## remove test and coverage artifacts + rm -fr .tox/ + rm -f .coverage + rm -fr htmlcov/ + rm -fr .pytest_cache + +lint/flake8: ## check style with flake8 + flake8 eos_midi tests + +lint: lint/flake8 ## check style + +test: ## run tests quickly with the default Python + python setup.py test + +test-all: ## run tests on every Python version with tox + tox + +coverage: ## check code coverage quickly with the default Python + coverage run --source eos_midi setup.py test + coverage report -m + coverage html + $(BROWSER) htmlcov/index.html + +docs: ## generate Sphinx HTML documentation, including API docs + rm -f docs/eos_midi.rst + rm -f docs/modules.rst + sphinx-apidoc -o docs/ eos_midi + $(MAKE) -C docs clean + $(MAKE) -C docs html + $(BROWSER) docs/_build/html/index.html + +servedocs: docs ## compile the docs watching for changes + watchmedo shell-command -p '*.rst' -c '$(MAKE) -C docs html' -R -D . + +release: dist ## package and upload a release + twine upload dist/* + +dist: clean ## builds source and wheel package + python setup.py sdist + python setup.py bdist_wheel + ls -l dist + +install: clean ## install the package to the active Python's site-packages + python setup.py install diff --git a/README.rst b/README.rst new file mode 100644 index 0000000..9934134 --- /dev/null +++ b/README.rst @@ -0,0 +1,37 @@ +======== +eos-midi +======== + + +.. image:: https://img.shields.io/pypi/v/eos_midi.svg + :target: https://pypi.python.org/pypi/eos_midi + +.. image:: https://img.shields.io/travis/soyouzpanda/eos_midi.svg + :target: https://travis-ci.com/soyouzpanda/eos_midi + +.. image:: https://readthedocs.org/projects/eos-midi/badge/?version=latest + :target: https://eos-midi.readthedocs.io/en/latest/?version=latest + :alt: Documentation Status + + + + +EOS interface to use midi keyboard + + +* Free software: MIT license +* Documentation: https://eos-midi.readthedocs.io. + + +Features +-------- + +* TODO + +Credits +------- + +This package was created with Cookiecutter_ and the `audreyr/cookiecutter-pypackage`_ project template. + +.. _Cookiecutter: https://github.com/audreyr/cookiecutter +.. _`audreyr/cookiecutter-pypackage`: https://github.com/audreyr/cookiecutter-pypackage diff --git a/docs/Makefile b/docs/Makefile new file mode 100644 index 0000000..2a8a18e --- /dev/null +++ b/docs/Makefile @@ -0,0 +1,20 @@ +# Minimal makefile for Sphinx documentation +# + +# You can set these variables from the command line. +SPHINXOPTS = +SPHINXBUILD = python -msphinx +SPHINXPROJ = eos_midi +SOURCEDIR = . +BUILDDIR = _build + +# Put it first so that "make" without argument is like "make help". +help: + @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) + +.PHONY: help Makefile + +# Catch-all target: route all unknown targets to Sphinx using the new +# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). +%: Makefile + @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) diff --git a/docs/authors.rst b/docs/authors.rst new file mode 100644 index 0000000..e122f91 --- /dev/null +++ b/docs/authors.rst @@ -0,0 +1 @@ +.. include:: ../AUTHORS.rst diff --git a/docs/conf.py b/docs/conf.py new file mode 100755 index 0000000..d30b2f0 --- /dev/null +++ b/docs/conf.py @@ -0,0 +1,162 @@ +#!/usr/bin/env python +# +# eos_midi documentation build configuration file, created by +# sphinx-quickstart on Fri Jun 9 13:47:02 2017. +# +# This file is execfile()d with the current directory set to its +# containing dir. +# +# Note that not all possible configuration values are present in this +# autogenerated file. +# +# All configuration values have a default; values that are commented out +# serve to show the default. + +# If extensions (or modules to document with autodoc) are in another +# directory, add these directories to sys.path here. If the directory is +# relative to the documentation root, use os.path.abspath to make it +# absolute, like shown here. +# +import os +import sys +sys.path.insert(0, os.path.abspath('..')) + +import eos_midi + +# -- General configuration --------------------------------------------- + +# If your documentation needs a minimal Sphinx version, state it here. +# +# needs_sphinx = '1.0' + +# Add any Sphinx extension module names here, as strings. They can be +# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom ones. +extensions = ['sphinx.ext.autodoc', 'sphinx.ext.viewcode'] + +# Add any paths that contain templates here, relative to this directory. +templates_path = ['_templates'] + +# The suffix(es) of source filenames. +# You can specify multiple suffix as a list of string: +# +# source_suffix = ['.rst', '.md'] +source_suffix = '.rst' + +# The master toctree document. +master_doc = 'index' + +# General information about the project. +project = 'eos-midi' +copyright = "2023, soyouzpanda" +author = "soyouzpanda" + +# The version info for the project you're documenting, acts as replacement +# for |version| and |release|, also used in various other places throughout +# the built documents. +# +# The short X.Y version. +version = eos_midi.__version__ +# The full version, including alpha/beta/rc tags. +release = eos_midi.__version__ + +# The language for content autogenerated by Sphinx. Refer to documentation +# for a list of supported languages. +# +# This is also used if you do content translation via gettext catalogs. +# Usually you set "language" from the command line for these cases. +language = None + +# List of patterns, relative to source directory, that match files and +# directories to ignore when looking for source files. +# This patterns also effect to html_static_path and html_extra_path +exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store'] + +# The name of the Pygments (syntax highlighting) style to use. +pygments_style = 'sphinx' + +# If true, `todo` and `todoList` produce output, else they produce nothing. +todo_include_todos = False + + +# -- Options for HTML output ------------------------------------------- + +# The theme to use for HTML and HTML Help pages. See the documentation for +# a list of builtin themes. +# +html_theme = 'alabaster' + +# Theme options are theme-specific and customize the look and feel of a +# theme further. For a list of options available for each theme, see the +# documentation. +# +# html_theme_options = {} + +# Add any paths that contain custom static files (such as style sheets) here, +# relative to this directory. They are copied after the builtin static files, +# so a file named "default.css" will overwrite the builtin "default.css". +html_static_path = ['_static'] + + +# -- Options for HTMLHelp output --------------------------------------- + +# Output file base name for HTML help builder. +htmlhelp_basename = 'eos_mididoc' + + +# -- Options for LaTeX output ------------------------------------------ + +latex_elements = { + # The paper size ('letterpaper' or 'a4paper'). + # + # 'papersize': 'letterpaper', + + # The font size ('10pt', '11pt' or '12pt'). + # + # 'pointsize': '10pt', + + # Additional stuff for the LaTeX preamble. + # + # 'preamble': '', + + # Latex figure (float) alignment + # + # 'figure_align': 'htbp', +} + +# Grouping the document tree into LaTeX files. List of tuples +# (source start file, target name, title, author, documentclass +# [howto, manual, or own class]). +latex_documents = [ + (master_doc, 'eos_midi.tex', + 'eos-midi Documentation', + 'soyouzpanda', 'manual'), +] + + +# -- Options for manual page output ------------------------------------ + +# One entry per manual page. List of tuples +# (source start file, name, description, authors, manual section). +man_pages = [ + (master_doc, 'eos_midi', + 'eos-midi Documentation', + [author], 1) +] + + +# -- Options for Texinfo output ---------------------------------------- + +# Grouping the document tree into Texinfo files. List of tuples +# (source start file, target name, title, author, +# dir menu entry, description, category) +texinfo_documents = [ + (master_doc, 'eos_midi', + 'eos-midi Documentation', + author, + 'eos_midi', + 'One line description of project.', + 'Miscellaneous'), +] + + + diff --git a/docs/contributing.rst b/docs/contributing.rst new file mode 100644 index 0000000..e582053 --- /dev/null +++ b/docs/contributing.rst @@ -0,0 +1 @@ +.. include:: ../CONTRIBUTING.rst diff --git a/docs/history.rst b/docs/history.rst new file mode 100644 index 0000000..2506499 --- /dev/null +++ b/docs/history.rst @@ -0,0 +1 @@ +.. include:: ../HISTORY.rst diff --git a/docs/index.rst b/docs/index.rst new file mode 100644 index 0000000..1f6b2fd --- /dev/null +++ b/docs/index.rst @@ -0,0 +1,20 @@ +Welcome to eos-midi's documentation! +====================================== + +.. toctree:: + :maxdepth: 2 + :caption: Contents: + + readme + installation + usage + modules + contributing + authors + history + +Indices and tables +================== +* :ref:`genindex` +* :ref:`modindex` +* :ref:`search` diff --git a/docs/installation.rst b/docs/installation.rst new file mode 100644 index 0000000..f687d32 --- /dev/null +++ b/docs/installation.rst @@ -0,0 +1,51 @@ +.. highlight:: shell + +============ +Installation +============ + + +Stable release +-------------- + +To install eos-midi, run this command in your terminal: + +.. code-block:: console + + $ pip install eos_midi + +This is the preferred method to install eos-midi, as it will always install the most recent stable release. + +If you don't have `pip`_ installed, this `Python installation guide`_ can guide +you through the process. + +.. _pip: https://pip.pypa.io +.. _Python installation guide: http://docs.python-guide.org/en/latest/starting/installation/ + + +From sources +------------ + +The sources for eos-midi can be downloaded from the `Github repo`_. + +You can either clone the public repository: + +.. code-block:: console + + $ git clone git://github.com/soyouzpanda/eos_midi + +Or download the `tarball`_: + +.. code-block:: console + + $ curl -OJL https://github.com/soyouzpanda/eos_midi/tarball/master + +Once you have a copy of the source, you can install it with: + +.. code-block:: console + + $ python setup.py install + + +.. _Github repo: https://github.com/soyouzpanda/eos_midi +.. _tarball: https://github.com/soyouzpanda/eos_midi/tarball/master diff --git a/docs/make.bat b/docs/make.bat new file mode 100644 index 0000000..9d92535 --- /dev/null +++ b/docs/make.bat @@ -0,0 +1,36 @@ +@ECHO OFF + +pushd %~dp0 + +REM Command file for Sphinx documentation + +if "%SPHINXBUILD%" == "" ( + set SPHINXBUILD=python -msphinx +) +set SOURCEDIR=. +set BUILDDIR=_build +set SPHINXPROJ=eos_midi + +if "%1" == "" goto help + +%SPHINXBUILD% >NUL 2>NUL +if errorlevel 9009 ( + echo. + echo.The Sphinx module was not found. Make sure you have Sphinx installed, + echo.then set the SPHINXBUILD environment variable to point to the full + echo.path of the 'sphinx-build' executable. Alternatively you may add the + echo.Sphinx directory to PATH. + echo. + echo.If you don't have Sphinx installed, grab it from + echo.http://sphinx-doc.org/ + exit /b 1 +) + +%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% +goto end + +:help +%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% + +:end +popd diff --git a/docs/readme.rst b/docs/readme.rst new file mode 100644 index 0000000..72a3355 --- /dev/null +++ b/docs/readme.rst @@ -0,0 +1 @@ +.. include:: ../README.rst diff --git a/docs/usage.rst b/docs/usage.rst new file mode 100644 index 0000000..9311676 --- /dev/null +++ b/docs/usage.rst @@ -0,0 +1,7 @@ +===== +Usage +===== + +To use eos-midi in a project:: + + import eos_midi diff --git a/eos_midi/__init__.py b/eos_midi/__init__.py new file mode 100644 index 0000000..fd0f33d --- /dev/null +++ b/eos_midi/__init__.py @@ -0,0 +1,9 @@ +"""Top-level module""" + +__author__ = """soyouzpanda""" +__email__ = 'soyouzpanda@soyouzpanda.fr' +__version__ = '0.1.0' + +from .eos_object import * +from .eos import * +from .pad import * diff --git a/eos_midi/__main__.py b/eos_midi/__main__.py new file mode 100644 index 0000000..21f031e --- /dev/null +++ b/eos_midi/__main__.py @@ -0,0 +1,202 @@ +"""Main module.""" +from .eos import EOSConnection +from .pad import Pad, EventHandler +from .eos_object import FaderBank, Fader, Macro +from lpminimk3 import LaunchpadMiniMk3, find_launchpads, ButtonEvent, Mode + +COLORS = [3, 21, 37, 45, 81, 95, 5, 9] +FOCUS_MACROS = [901, 902, 903, 906] +SELECT_MACROS = [304, 303, 305, 302, 301] +SELECT_COLORS = [78, 21, 13, 5, 3] + + +class AbstractColorEventHandler(EventHandler): + """Abstract color event handler""" + def __init__(self, launchpad: LaunchpadMiniMk3, line: int, column: int): + super().__init__(f'{column}x{line}') + self._launchpad = launchpad + self._line = line + self._column = column + self._launchpad.panel.led( + self.button_name).color = COLORS[self._column] + + def flash(self): + """Flash only the current button on the line""" + for color in range(8): + self._launchpad.panel.led( + f'{color}x{self._line}').color = COLORS[color] + self._launchpad.panel.led(self.button_name).reset() + self._launchpad.panel.led(self.button_name, + mode='flash').color = COLORS[self._column] + + +class ColorBumpEventHandler(AbstractColorEventHandler): + """Bump button Event handler""" + def __init__(self, fader_bank: FaderBank, + launchpad: LaunchpadMiniMk3, color_id: int): + super().__init__(launchpad, 5, color_id) + self._fader = fader_bank.fader(14, color_id + 1) + + def on_press(self, _: ButtonEvent): + self._fader.fire(1.0) + + def on_release(self, _: ButtonEvent): + self._fader.fire(0.0) + + +class ColorFxEventHandler(AbstractColorEventHandler): + """FX button Event handler""" + def __init__(self, fader_bank: FaderBank, + launchpad: LaunchpadMiniMk3, color_id: int): + super().__init__(launchpad, 6, color_id) + self._fader = fader_bank.fader(17, color_id + 1) + + def on_press(self, _: ButtonEvent): + self.flash() + self._fader.fire() + + +class ColorEventHandler(AbstractColorEventHandler): + """Non-FX button Event handler""" + def __init__(self, fader_bank: FaderBank, + launchpad: LaunchpadMiniMk3, color_id: int): + super().__init__(launchpad, 7, color_id) + self._fader = fader_bank.fader(18, color_id + 1) + + def on_press(self, _: ButtonEvent): + self.flash() + self._fader.fire() + + +class FocusEventHandler(EventHandler): + """Focus event handler""" + def __init__(self, eos: EOSConnection, + launchpad: LaunchpadMiniMk3, column: int): + super().__init__(f'{column}x2') + self._macro = eos.macro(FOCUS_MACROS[column]) + self._launchpad = launchpad + self._launchpad.panel.led(self.button_name).color = 5 + + def on_press(self, _: ButtonEvent): + for col in range(4): + self._launchpad.panel.led(f'{col}x2').color = 5 + self._launchpad.panel.led(self.button_name).reset() + self._launchpad.panel.led(self.button_name, + mode='flash').color = 5 + + self._macro.fire() + + +class SimpleFaderEventHandler(EventHandler): + """Simple fader Event handler""" + def __init__(self, fader: Fader, + launchpad: LaunchpadMiniMk3, + button: str, color: int): + super().__init__(button) + launchpad.panel.led(button).color = color + self._fader = fader + + def on_press(self, _: ButtonEvent): + self._fader.fire(1.0) + + def on_release(self, _: ButtonEvent): + self._fader.fire(0.0) + + +class SimpleMacroEventHandler(EventHandler): + """Simple macro Event handler""" + def __init__(self, macro: Macro, + launchpad: LaunchpadMiniMk3, + button: str, color: int): + super().__init__(button) + launchpad.panel.led(button).color = color + self._macro = macro + + def on_press(self, _: ButtonEvent): + self._macro.fire() + + +class SelectEventHandler(EventHandler): + """Select Event handler""" + def __init__(self, eos: EOSConnection, + launchpad: LaunchpadMiniMk3, + select_id: int): + super().__init__(f'{select_id + 3}x0') + self._launchpad = launchpad + self._select_id = select_id + self._macro = eos.macro(SELECT_MACROS[self._select_id]) + self._launchpad.panel.led( + self.button_name).color = SELECT_COLORS[self._select_id] + + def on_press(self, _: ButtonEvent): + for i in range(3, 8): + self._launchpad.panel.led( + f'{i}x0').color = SELECT_COLORS[i - 3] + self._launchpad.panel.led( + self.button_name).reset() + self._launchpad.panel.led( + self.button_name, + mode='flash').color = SELECT_COLORS[self._select_id] + self._macro.fire() + + +def main(): + """main function""" + launchpad = find_launchpads()[0] + launchpad.open() + launchpad.mode = Mode.PROG + launchpad.panel.reset() + launchpad.clear_event_queue() + + eos = EOSConnection("192.168.50.36", 8000) + faderbank = eos.fader_bank() + + pad = Pad(launchpad) + + # 6è-7è-8è ligne + + for i in range(8): + pad.add_event_handler(ColorBumpEventHandler(faderbank, launchpad, i)) + pad.add_event_handler(ColorFxEventHandler(faderbank, launchpad, i)) + pad.add_event_handler(ColorEventHandler(faderbank, launchpad, i)) + + # 3è ligne + + for i in range(4): + pad.add_event_handler(FocusEventHandler(eos, launchpad, i)) + pad.add_event_handler(SimpleFaderEventHandler( + faderbank.fader(6, 7), launchpad, '4x2', 9)) + pad.add_event_handler(SimpleFaderEventHandler( + faderbank.fader(5, 2), launchpad, '6x2', 4)) + pad.add_event_handler(SimpleFaderEventHandler( + faderbank.fader(5, 4), launchpad, '7x2', 4)) + + # 2è ligne + pad.add_event_handler(SimpleFaderEventHandler( + faderbank.fader(5, 5), launchpad, '0x1', 21)) + pad.add_event_handler(SimpleFaderEventHandler( + faderbank.fader(5, 6), launchpad, '1x1', 88)) + pad.add_event_handler(SimpleFaderEventHandler( + faderbank.fader(7, 1), launchpad, '2x1', 78)) + pad.add_event_handler(SimpleFaderEventHandler( + faderbank.fader(7, 2), launchpad, '3x1', 32)) + pad.add_event_handler(SimpleMacroEventHandler( + eos.macro(401), launchpad, '5x1', 95)) + pad.add_event_handler(SimpleMacroEventHandler( + eos.macro(402), launchpad, '6x1', 95)) + pad.add_event_handler(SimpleMacroEventHandler( + eos.macro(403), launchpad, '7x1', 95)) + + # 1ère ligne + + pad.add_event_handler(SimpleMacroEventHandler( + eos.macro(6), launchpad, '0x0', 3)) + for i in range(5): + pad.add_event_handler(SelectEventHandler( + eos, launchpad, i)) + + pad.serve_forever() + + +if __name__ == '__main__': + main() diff --git a/eos_midi/eos.py b/eos_midi/eos.py new file mode 100644 index 0000000..011c778 --- /dev/null +++ b/eos_midi/eos.py @@ -0,0 +1,23 @@ +"""EOS""" +from pythonosc.udp_client import SimpleUDPClient +from .eos_object.fader import FaderBank +from .eos_object.channel import Channel +from .eos_object.macro import Macro + + +class EOSConnection: + """EOS Connection""" + def __init__(self, address: str, port: int): + self.osc_client = SimpleUDPClient(address, port) + + def fader_bank(self): + """Returns the FaderBank""" + return FaderBank(self.osc_client) + + def channel(self, channel_id: int): + """Returns the Channel {channel_id}""" + return Channel(channel_id, self.osc_client) + + def macro(self, macro_id: int): + """Returns the Macro {macro_id}""" + return Macro(macro_id, self.osc_client) diff --git a/eos_midi/eos_object/__init__.py b/eos_midi/eos_object/__init__.py new file mode 100644 index 0000000..e481503 --- /dev/null +++ b/eos_midi/eos_object/__init__.py @@ -0,0 +1,3 @@ +from .channel import * +from .fader import * +from .macro import * diff --git a/eos_midi/eos_object/channel.py b/eos_midi/eos_object/channel.py new file mode 100644 index 0000000..a4f065f --- /dev/null +++ b/eos_midi/eos_object/channel.py @@ -0,0 +1,29 @@ +"""EOS Channel""" +from pythonosc.udp_client import SimpleUDPClient + + +class Channel: + """EOS Channel""" + def __init__(self, channel_id: int, osc_client: SimpleUDPClient): + self.channel_id = channel_id + self.osc_client = osc_client + + def full(self): + """Sets channel intensity to full""" + self.osc_client.send_message(f"/eos/chan/{self.channel_id}/full", []) + + def min(self): + """Sets channel intensity to min""" + self.osc_client.send_message(f"/eos/chan/{self.channel_id}/min", []) + + def max(self): + """Sets channel intensity to max""" + self.osc_client.send_message(f"/eos/chan/{self.channel_id}/max", []) + + def plus_10(self): + """Increases channel intensity by 10%""" + self.osc_client.send_message(f"/eos/chan/{self.channel_id}/+%", []) + + def minus_10(self): + """Decreases channel intensity by 10%""" + self.osc_client.send_message(f"/eos/chan/{self.channel_id}/-%", []) diff --git a/eos_midi/eos_object/fader.py b/eos_midi/eos_object/fader.py new file mode 100644 index 0000000..f9a4a97 --- /dev/null +++ b/eos_midi/eos_object/fader.py @@ -0,0 +1,87 @@ +"""EOS Fader""" +from typing import Optional +from pythonosc.udp_client import SimpleUDPClient + + +class FaderBank: + """EOS Fader bank""" + def __init__(self, osc_client: SimpleUDPClient): + self.osc_client = osc_client + for i in range(1, 101): + self.osc_client.send_message( + f"/eos/fader/{i}/config/{i}/10", []) + + def page(self, page: int): + """Returns the page {page}""" + return FaderPage(page, self.osc_client) + + def fader(self, page: int, fader: int): + """Returns the fader {fader} of page {page}""" + return FaderPage(page, self.osc_client).fader(fader) + + +class FaderPage: + """EOS Fader page""" + def __init__(self, page: int, osc_client: SimpleUDPClient): + self.page = page + self.osc_client = osc_client + + def fader(self, fader: int): + """Returns the fader {fader} of the page""" + return Fader(self.page, fader, self.osc_client) + + def next(self): + """Returns the next page""" + return FaderPage(min(100, self.page + 1), self.osc_client) + + def previous(self): + """Returns the previous page""" + return FaderPage(max(1, self.page - 1), self.osc_client) + + +class Fader: + """EOS Fader""" + def __init__(self, page: int, fader: int, + osc_client: SimpleUDPClient): + self.page = page + self.fader = fader + self.osc_client = osc_client + + def fire(self, value: Optional[float] = None): + """Starts effect of the fader""" + if value: + self.osc_client.send_message( + f"/eos/fader/{self.page}/{self.fader}/fire", [value]) + else: + self.osc_client.send_message( + f"/eos/fader/{self.page}/{self.fader}/fire", []) + + def stop(self): + """Stops effect of the fader""" + self.osc_client.send_message( + f"/eos/fader/{self.page}/{self.fader}/stop", []) + + def full(self): + """Sets the fader to full""" + self.osc_client.send_message( + f"/eos/fader/{self.page}/{self.fader}/full", []) + + def min(self): + """Sets the fader to minimum""" + self.osc_client.send_message( + f"/eos/fader/{self.page}/{self.fader}/min", []) + + def max(self): + """Sets the fader to maximum""" + self.osc_client.send_message( + f"/eos/fader/{self.page}/{self.fader}/max", []) + + def plus_10(self): + """Increases the fader by 10%""" + self.osc_client.send_message( + f"/eos/fader/{self.page}/{self.fader}/+%", []) + + def minus_10(self): + """Decreases the fader by 10%""" + self.osc_client.send_message( + f"/eos/fader/{self.page}/{self.fader}/-%", []) diff --git a/eos_midi/eos_object/macro.py b/eos_midi/eos_object/macro.py new file mode 100644 index 0000000..def56a8 --- /dev/null +++ b/eos_midi/eos_object/macro.py @@ -0,0 +1,13 @@ +""""EOS Macro""" +from pythonosc.udp_client import SimpleUDPClient + + +class Macro: + """EOS Macro""" + def __init__(self, macro_id: int, osc_client: SimpleUDPClient): + self.macro_id = macro_id + self.osc_client = osc_client + + def fire(self): + """Fires macro""" + self.osc_client.send_message(f"/eos/macro/{self.macro_id}/fire", []) diff --git a/eos_midi/midi_controller.py b/eos_midi/midi_controller.py new file mode 100644 index 0000000..b7147f9 --- /dev/null +++ b/eos_midi/midi_controller.py @@ -0,0 +1,3 @@ +"""MIDI Controller, Launchpad Mini MK3""" +from lpminimk3 import Mode, find_launchpad + diff --git a/eos_midi/pad.py b/eos_midi/pad.py new file mode 100644 index 0000000..a9434e8 --- /dev/null +++ b/eos_midi/pad.py @@ -0,0 +1,74 @@ +"""Launchpad""" +from lpminimk3 import LaunchpadMiniMk3, ButtonEvent + +VALID_BUTTONS = [ + 'up', 'down', 'left', 'right', 'session', 'drums', 'keys', 'user', + 'scene_launch_1', 'scene_launch_2', 'scene_launch_3', 'scene_launch_4', + 'scene_launch_5', 'scene_launch_6', 'scene_launch_7', 'stop_solo_mute', +] + + +class EventHandler: + """Event handler for launchpad""" + def __init__(self, button_name: str): + self._button_name = button_name + + @property + def button_name(self): + """Returns button name""" + return self._button_name + + def on_press(self, _: ButtonEvent): + """On button pressed""" + + def on_release(self, _: ButtonEvent): + """On button released""" + + +class Pad: + """Pad Wrapper""" + def __init__(self, launchpad: LaunchpadMiniMk3): + self._launchpad = launchpad + self._event_handlers: dict[str, list[EventHandler]] = {} + + def _validate_button(self, button: str | tuple[int, int]) -> str: + if isinstance(button, str): + if button in VALID_BUTTONS: + return button + split = button.split('x') + if len(split) == 2 and \ + split[0].isdigit() and split[1].isdigit() and \ + int(split[0]) >= 0 and int(split[0]) < 8 and \ + int(split[1]) >= 0 and int(split[1]) < 8: + return button + raise ValueError(button) + if isinstance(button, tuple) and len(button) == 2 and \ + isinstance(button[0], int) and isinstance(button[1], int) and \ + button[0] >= 0 and button[0] < 8 and \ + button[1] >= 0 and button[1] < 8: + return str(button[0]) + 'x' + str(button[1]) + raise ValueError(button) + + def add_event_handler(self, handler: EventHandler): + """Adds a event handler""" + button = self._validate_button(handler.button_name) + lst = self._event_handlers.get(button) + if lst: + lst.append(handler) + else: + self._event_handlers[button] = [handler] + + def serve_forever(self): + """Servers forever""" + buttons = self._launchpad.panel.buttons() + while True: + event = buttons.poll_for_event() + if isinstance(event, ButtonEvent): + if event.type == ButtonEvent.PRESS: + for handler in self._event_handlers.get( + event.button.name, []): + handler.on_press(event) + elif event.type == ButtonEvent.RELEASE: + for handler in self._event_handlers.get( + event.button.name, []): + handler.on_release(event) diff --git a/requirements_dev.txt b/requirements_dev.txt new file mode 100644 index 0000000..27f1988 --- /dev/null +++ b/requirements_dev.txt @@ -0,0 +1,12 @@ +pip==23.3.2 +bump2version==1.0.1 +wheel==0.42.0 +watchdog==3.0.0 +flake8==6.1.0 +tox==4.11.4 +coverage==7.3.3 +Sphinx==7.2.6 +twine==4.0.2 +python-osc==1.8.3 +lpminimk3==0.6.2 +asyncio==3.4.3 diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..d9aaa1f --- /dev/null +++ b/setup.cfg @@ -0,0 +1,18 @@ +[bumpversion] +current_version = 0.1.0 +commit = True +tag = True + +[bumpversion:file:setup.py] +search = version='{current_version}' +replace = version='{new_version}' + +[bumpversion:file:eos_midi/__init__.py] +search = __version__ = '{current_version}' +replace = __version__ = '{new_version}' + +[bdist_wheel] +universal = 1 + +[flake8] +exclude = docs diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..2592aaf --- /dev/null +++ b/setup.py @@ -0,0 +1,44 @@ +#!/usr/bin/env python + +"""The setup script.""" + +from setuptools import setup, find_packages + +with open('README.rst') as readme_file: + readme = readme_file.read() + +with open('HISTORY.rst') as history_file: + history = history_file.read() + +requirements = [ ] + +test_requirements = [ ] + +setup( + author="soyouzpanda", + author_email='soyouzpanda@soyouzpanda.fr', + python_requires='>=3.6', + classifiers=[ + 'Development Status :: 2 - Pre-Alpha', + 'Intended Audience :: Developers', + 'License :: OSI Approved :: MIT License', + 'Natural Language :: English', + 'Programming Language :: Python :: 3', + 'Programming Language :: Python :: 3.6', + 'Programming Language :: Python :: 3.7', + 'Programming Language :: Python :: 3.8', + ], + description="EOS interface to use midi keyboard", + install_requires=requirements, + license="MIT license", + long_description=readme + '\n\n' + history, + include_package_data=True, + keywords='eos_midi', + name='eos_midi', + packages=find_packages(include=['eos_midi', 'eos_midi.*']), + test_suite='tests', + tests_require=test_requirements, + url='https://github.com/soyouzpanda/eos_midi', + version='0.1.0', + zip_safe=False, +) diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..7efcf19 --- /dev/null +++ b/tests/__init__.py @@ -0,0 +1 @@ +"""Unit test package for eos_midi.""" diff --git a/tests/test_eos_midi.py b/tests/test_eos_midi.py new file mode 100644 index 0000000..6f5a168 --- /dev/null +++ b/tests/test_eos_midi.py @@ -0,0 +1,21 @@ +#!/usr/bin/env python + +"""Tests for `eos_midi` package.""" + + +import unittest + +from eos_midi import eos_midi + + +class TestEos_midi(unittest.TestCase): + """Tests for `eos_midi` package.""" + + def setUp(self): + """Set up test fixtures, if any.""" + + def tearDown(self): + """Tear down test fixtures, if any.""" + + def test_000_something(self): + """Test something.""" diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..3bd53ee --- /dev/null +++ b/tox.ini @@ -0,0 +1,19 @@ +[tox] +envlist = py36, py37, py38, flake8 + +[travis] +python = + 3.8: py38 + 3.7: py37 + 3.6: py36 + +[testenv:flake8] +basepython = python +deps = flake8 +commands = flake8 eos_midi tests + +[testenv] +setenv = + PYTHONPATH = {toxinidir} + +commands = python setup.py test