├── .gitignore ├── LICENSE ├── README.md ├── client ├── audioclient.py ├── bin │ ├── Activate.ps1 │ ├── activate │ ├── activate.csh │ ├── activate.fish │ ├── f2py │ ├── normalizer │ ├── pip │ ├── pip3 │ ├── pip3.12 │ ├── python │ ├── python3 │ ├── python3.12 │ └── range-detector ├── pyvenv.cfg ├── requirements.txt └── webcamclient.py ├── experiments ├── gensound.ipynb ├── musicalbeeps.ipynb ├── scamp.ipynb └── webcam.ipynb ├── images ├── architecture.png └── screenshot.png ├── presets.md └── server ├── bin ├── Activate.ps1 ├── accelerate ├── accelerate-config ├── accelerate-estimate-memory ├── accelerate-launch ├── accelerate-merge-weights ├── activate ├── activate.csh ├── activate.fish ├── convert-caffe2-to-onnx ├── convert-onnx-to-caffe2 ├── distro ├── dotenv ├── email_validator ├── f2py ├── fastapi ├── httpx ├── huggingface-cli ├── isympy ├── jsondiff ├── jsonpatch ├── jsonpointer ├── langchain-server ├── langsmith ├── markdown-it ├── normalizer ├── openai ├── pip ├── pip3 ├── pip3.12 ├── pygmentize ├── python ├── python3 ├── python3.12 ├── torchrun ├── tqdm ├── transformers-cli ├── typer ├── uvicorn └── watchfiles ├── framecapture └── README.md ├── handlestream.py ├── pyvenv.cfg ├── requirements.txt ├── server.py └── share └── man └── man1 └── isympy.1 /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | share/python-wheels/ 24 | *.egg-info/ 25 | .installed.cfg 26 | *.egg 27 | MANIFEST 28 | 29 | # PyInstaller 30 | # Usually these files are written by a python script from a template 31 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 32 | *.manifest 33 | *.spec 34 | 35 | # Installer logs 36 | pip-log.txt 37 | pip-delete-this-directory.txt 38 | 39 | # Unit test / coverage reports 40 | htmlcov/ 41 | .tox/ 42 | .nox/ 43 | .coverage 44 | .coverage.* 45 | .cache 46 | nosetests.xml 47 | coverage.xml 48 | *.cover 49 | *.py,cover 50 | .hypothesis/ 51 | .pytest_cache/ 52 | cover/ 53 | 54 | # Translations 55 | *.mo 56 | *.pot 57 | 58 | # Django stuff: 59 | *.log 60 | local_settings.py 61 | db.sqlite3 62 | db.sqlite3-journal 63 | 64 | # Flask stuff: 65 | instance/ 66 | .webassets-cache 67 | 68 | # Scrapy stuff: 69 | .scrapy 70 | 71 | # Sphinx documentation 72 | docs/_build/ 73 | 74 | # PyBuilder 75 | .pybuilder/ 76 | target/ 77 | 78 | # Jupyter Notebook 79 | .ipynb_checkpoints 80 | 81 | # IPython 82 | profile_default/ 83 | ipython_config.py 84 | 85 | # pyenv 86 | # For a library or package, you might want to ignore these files since the code is 87 | # intended to run in multiple environments; otherwise, check them in: 88 | # .python-version 89 | 90 | # pipenv 91 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 92 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 93 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 94 | # install all needed dependencies. 95 | #Pipfile.lock 96 | 97 | # poetry 98 | # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. 99 | # This is especially recommended for binary packages to ensure reproducibility, and is more 100 | # commonly ignored for libraries. 101 | # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control 102 | #poetry.lock 103 | 104 | # pdm 105 | # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. 106 | #pdm.lock 107 | # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it 108 | # in version control. 109 | # https://pdm.fming.dev/#use-with-ide 110 | .pdm.toml 111 | 112 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm 113 | __pypackages__/ 114 | 115 | # Celery stuff 116 | celerybeat-schedule 117 | celerybeat.pid 118 | 119 | # SageMath parsed files 120 | *.sage.py 121 | 122 | # Environments 123 | .env 124 | .venv 125 | env/ 126 | venv/ 127 | ENV/ 128 | env.bak/ 129 | venv.bak/ 130 | 131 | # Spyder project settings 132 | .spyderproject 133 | .spyproject 134 | 135 | # Rope project settings 136 | .ropeproject 137 | 138 | # mkdocs documentation 139 | /site 140 | 141 | # mypy 142 | .mypy_cache/ 143 | .dmypy.json 144 | dmypy.json 145 | 146 | # Pyre type checker 147 | .pyre/ 148 | 149 | # pytype static type analyzer 150 | .pytype/ 151 | 152 | # Cython debug symbols 153 | cython_debug/ 154 | 155 | # PyCharm 156 | # JetBrains specific template is maintained in a separate JetBrains.gitignore that can 157 | # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore 158 | # and can be added to the global gitignore or merged into this file. For a more nuclear 159 | # option (not recommended) you can uncomment the following to ignore the entire idea folder. 160 | #.idea/ 161 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 🎵 papermusic ✏️ 2 | 3 | draw an instrument, and play it! (fun with [PaliGemma](https://ai.google.dev/gemma/docs/paligemma) and [SCAMP](http://scamp.marcevanstein.com/)) 4 | 5 | ### video walkthrough 6 | 7 | (click to play) 8 | 9 | [![Video Walkthrough](https://img.youtube.com/vi/Gxjok5h7HIU/maxresdefault.jpg)](https://youtu.be/Gxjok5h7HIU) 10 | 11 | ([📺 Original implementation](https://www.youtube.com/watch?v=G5sSaLUskis&t=1s)) 12 | 13 | ### architecture 14 | 15 | ![](images/architecture.png) 16 | 17 | 18 | ### screenshot 19 | 20 | ![](images/screenshot.png) 21 | 22 | ## how to run 23 | 24 | Note - this is a prototype, not a production-grade app. (The OpenCV streaming setup is a bit buggy and occasionally crashes. You may need to restart.) 25 | 26 | **You will need:** 27 | - A local machine with a webcam, and Python 3.11+. (Client has been tested on MacOS Sonoma / M1 Mac). 28 | - A Google Cloud project, with access to Google Compute Engine. 29 | - A HuggingFace account with an [Access Token](https://huggingface.co/docs/hub/en/security-tokens) 30 | 31 | #### Setup (Server) 32 | 33 | 1. Create a Google Compute Engine instance with at least one GPU. I used two NVIDIA T4 GPUs, but adjust to whatever your quota allows. Set "Allow HTTP/HTTPS" traffic to `true`. 34 | 2. SSH into the instance. 35 | 3. Install Python packages for the server workloads. 36 | ```bash 37 | git clone https://github.com/askmeegs/papermusic 38 | cd papermusic 39 | python3 -m venv . 40 | source ./bin/activate 41 | pip install -r requirements.txt 42 | ``` 43 | 4. Set your HuggingFace Access Token as an environment variable. 44 | ```bash 45 | export HUGGINGFACE_USER_ACCESS_TOKEN=your_token_here 46 | ``` 47 | 48 | #### Setup (Client) 49 | 50 | 1. Clone the repo on your local machine. 51 | ``` 52 | git clone https://github.com/askmeegs/papermusic 53 | cd papermusic 54 | ``` 55 | 56 | 2. Install client packages. 57 | ``` 58 | python3 -m venv . 59 | source ./bin/activate 60 | pip install -r requirements.txt 61 | ``` 62 | 63 | #### Run all components 64 | 65 | Place a hand-drawn musical instrument in front of your webcam, like the screenshot shown above. Make sure the notes are written clearly on the instrument. 66 | 67 | 1. Start `server/handlestream.py` on GCE, to listen for the webcam stream. 68 | 2. Start `client/webcamclient.py` on your local machine, to send your webcam stream to GCE. 69 | 3. Start `server/server.py` on GCE, to process the webcam stream and identify the notes. 70 | 4. Start `client/audioclient.py` on your local machine, to poll the Server and play the notes over local audio. 71 | 72 | ### 📚 sources 73 | 74 | - [PaliGemma](https://huggingface.co/google/paligemma-3b-pt-224?library=transformers) (vision-language model) 75 | - [HuggingFace Transformers](https://huggingface.co/docs/transformers/index) 76 | - [HuggingFace Inference Optimization](https://huggingface.co/docs/transformers/main/en/llm_optims) 77 | - [SCAMP (Suite for Computer-Assisted Music in Python)](http://scamp.marcevanstein.com/) 78 | - [ASCII Art Generator](https://patorjk.com/software/taag/#p=display&f=Graffiti&t=Type%20Something%20) 79 | -------------------------------------------------------------------------------- /client/audioclient.py: -------------------------------------------------------------------------------- 1 | # while streaming webcam over UDP to GCE, receive the GCE server's response 2 | # (note identification) so it can be played over local mac's audio. 3 | 4 | from scamp import * 5 | import requests 6 | import time 7 | 8 | # GCE server URL 9 | SERVER_URL = "http://35.231.102.158:8000" 10 | 11 | 12 | # configure music generation 13 | s = Session() 14 | # default instrument 15 | inst = s.new_part("music box") 16 | 17 | # s.timing_policy = 0.7 18 | 19 | # maps note name to MIDI note number 20 | nm = { 21 | "C3": 48, 22 | "C#3": 49, 23 | "D3": 50, 24 | "D#3": 51, 25 | "E3": 52, 26 | "F3": 53, 27 | "F#3": 54, 28 | "G3": 55, 29 | "G#3": 56, 30 | "A3": 57, 31 | "A#3": 58, 32 | "B3": 59, 33 | "C4": 60, 34 | "C#4": 61, 35 | "D4": 62, 36 | "D#4": 63, 37 | "E4": 64, 38 | "F4": 65, 39 | "F#4": 66, 40 | "G4": 67, 41 | "G#4": 68, 42 | "A4": 69, 43 | "A#4": 70, 44 | "B4": 71, 45 | "C5": 72, 46 | "C#5": 73, 47 | "D5": 74, 48 | "D#5": 75, 49 | "E5": 76, 50 | "F5": 77, 51 | "F#5": 78, 52 | "G5": 79, 53 | "G#5": 80, 54 | "A5": 81, 55 | "A#5": 82, 56 | "B5": 83, 57 | "C6": 84, 58 | "C#6": 85, 59 | "D6": 86, 60 | "D#6": 87, 61 | "E6": 88, 62 | "F6": 89, 63 | "F#6": 90, 64 | "G6": 91, 65 | "G#6": 92, 66 | "A6": 93, 67 | "A#6": 94, 68 | "B6": 95, 69 | "C7": 96, 70 | } 71 | 72 | 73 | def set_instrument(): 74 | global inst 75 | # HTTP requests to GCE server 76 | # response = requests.get(SERVER_URL + "/instrument") 77 | # inst_name = response.json()["instrument"] 78 | # print("🎹 PaliGemma identified the instrument as: ", inst_name) 79 | # inst = s.new_part(inst_name) 80 | inst = s.new_part("xylophone") 81 | 82 | 83 | # https://scamp.marcevanstein.com/narrative/note_properties.html 84 | def play_note(): 85 | global inst 86 | # HTTP requests to GCE server 87 | response = requests.get(SERVER_URL + "/note") 88 | note_id = response.json()["note"] 89 | # if PaliGemma IDed a note without an octave, add default octave 90 | if note_id in ["C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"]: 91 | note_id += "4" 92 | if note_id in nm: 93 | print("🔈 PLAYING: ", note_id) 94 | midinote = nm[note_id] 95 | inst.play_note(midinote, 1, 1, {"articulations": ["staccato"]}) 96 | else: 97 | print("🤫 Unrecognized note: {}".format(note_id)) 98 | 99 | 100 | def run_client(): 101 | print( 102 | """ 103 | 🎹 🎹 🎹 🎹 🎹 🎹 🎹 🎹 🎹 🎹 104 | ┌─┐┌─┐┌─┐┌─┐┬─┐┌┬┐┌┐┌┬ ┬┌─┐┬┌─┐ 105 | ├─┘├─┤├─┘├┤ ├┬┘│││││││ │└─┐││ 106 | ┴ ┴ ┴┴ └─┘┴└─┴ ┴┘└┘└─┘└─┘┴└─┘ 107 | ✏️ ✏️ ✏️ ✏️ ✏️ ✏️ ✏️ ✏️ ✏️ ✏️ 108 | """ 109 | ) 110 | # NOTE - assumes webcamclient.py is also running 111 | # first, poll the GCE server for the instrument 112 | time.sleep(3) 113 | set_instrument() 114 | 115 | # then, continously poll for the note currently being played by the webcam stream. exit on ctrl-c. 116 | while True: 117 | try: 118 | play_note() 119 | except KeyboardInterrupt: 120 | print("👋 Exiting...") 121 | break 122 | 123 | 124 | if __name__ == "__main__": 125 | run_client() 126 | -------------------------------------------------------------------------------- /client/bin/Activate.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .Synopsis 3 | Activate a Python virtual environment for the current PowerShell session. 4 | 5 | .Description 6 | Pushes the python executable for a virtual environment to the front of the 7 | $Env:PATH environment variable and sets the prompt to signify that you are 8 | in a Python virtual environment. Makes use of the command line switches as 9 | well as the `pyvenv.cfg` file values present in the virtual environment. 10 | 11 | .Parameter VenvDir 12 | Path to the directory that contains the virtual environment to activate. The 13 | default value for this is the parent of the directory that the Activate.ps1 14 | script is located within. 15 | 16 | .Parameter Prompt 17 | The prompt prefix to display when this virtual environment is activated. By 18 | default, this prompt is the name of the virtual environment folder (VenvDir) 19 | surrounded by parentheses and followed by a single space (ie. '(.venv) '). 20 | 21 | .Example 22 | Activate.ps1 23 | Activates the Python virtual environment that contains the Activate.ps1 script. 24 | 25 | .Example 26 | Activate.ps1 -Verbose 27 | Activates the Python virtual environment that contains the Activate.ps1 script, 28 | and shows extra information about the activation as it executes. 29 | 30 | .Example 31 | Activate.ps1 -VenvDir C:\Users\MyUser\Common\.venv 32 | Activates the Python virtual environment located in the specified location. 33 | 34 | .Example 35 | Activate.ps1 -Prompt "MyPython" 36 | Activates the Python virtual environment that contains the Activate.ps1 script, 37 | and prefixes the current prompt with the specified string (surrounded in 38 | parentheses) while the virtual environment is active. 39 | 40 | .Notes 41 | On Windows, it may be required to enable this Activate.ps1 script by setting the 42 | execution policy for the user. You can do this by issuing the following PowerShell 43 | command: 44 | 45 | PS C:\> Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser 46 | 47 | For more information on Execution Policies: 48 | https://go.microsoft.com/fwlink/?LinkID=135170 49 | 50 | #> 51 | Param( 52 | [Parameter(Mandatory = $false)] 53 | [String] 54 | $VenvDir, 55 | [Parameter(Mandatory = $false)] 56 | [String] 57 | $Prompt 58 | ) 59 | 60 | <# Function declarations --------------------------------------------------- #> 61 | 62 | <# 63 | .Synopsis 64 | Remove all shell session elements added by the Activate script, including the 65 | addition of the virtual environment's Python executable from the beginning of 66 | the PATH variable. 67 | 68 | .Parameter NonDestructive 69 | If present, do not remove this function from the global namespace for the 70 | session. 71 | 72 | #> 73 | function global:deactivate ([switch]$NonDestructive) { 74 | # Revert to original values 75 | 76 | # The prior prompt: 77 | if (Test-Path -Path Function:_OLD_VIRTUAL_PROMPT) { 78 | Copy-Item -Path Function:_OLD_VIRTUAL_PROMPT -Destination Function:prompt 79 | Remove-Item -Path Function:_OLD_VIRTUAL_PROMPT 80 | } 81 | 82 | # The prior PYTHONHOME: 83 | if (Test-Path -Path Env:_OLD_VIRTUAL_PYTHONHOME) { 84 | Copy-Item -Path Env:_OLD_VIRTUAL_PYTHONHOME -Destination Env:PYTHONHOME 85 | Remove-Item -Path Env:_OLD_VIRTUAL_PYTHONHOME 86 | } 87 | 88 | # The prior PATH: 89 | if (Test-Path -Path Env:_OLD_VIRTUAL_PATH) { 90 | Copy-Item -Path Env:_OLD_VIRTUAL_PATH -Destination Env:PATH 91 | Remove-Item -Path Env:_OLD_VIRTUAL_PATH 92 | } 93 | 94 | # Just remove the VIRTUAL_ENV altogether: 95 | if (Test-Path -Path Env:VIRTUAL_ENV) { 96 | Remove-Item -Path env:VIRTUAL_ENV 97 | } 98 | 99 | # Just remove VIRTUAL_ENV_PROMPT altogether. 100 | if (Test-Path -Path Env:VIRTUAL_ENV_PROMPT) { 101 | Remove-Item -Path env:VIRTUAL_ENV_PROMPT 102 | } 103 | 104 | # Just remove the _PYTHON_VENV_PROMPT_PREFIX altogether: 105 | if (Get-Variable -Name "_PYTHON_VENV_PROMPT_PREFIX" -ErrorAction SilentlyContinue) { 106 | Remove-Variable -Name _PYTHON_VENV_PROMPT_PREFIX -Scope Global -Force 107 | } 108 | 109 | # Leave deactivate function in the global namespace if requested: 110 | if (-not $NonDestructive) { 111 | Remove-Item -Path function:deactivate 112 | } 113 | } 114 | 115 | <# 116 | .Description 117 | Get-PyVenvConfig parses the values from the pyvenv.cfg file located in the 118 | given folder, and returns them in a map. 119 | 120 | For each line in the pyvenv.cfg file, if that line can be parsed into exactly 121 | two strings separated by `=` (with any amount of whitespace surrounding the =) 122 | then it is considered a `key = value` line. The left hand string is the key, 123 | the right hand is the value. 124 | 125 | If the value starts with a `'` or a `"` then the first and last character is 126 | stripped from the value before being captured. 127 | 128 | .Parameter ConfigDir 129 | Path to the directory that contains the `pyvenv.cfg` file. 130 | #> 131 | function Get-PyVenvConfig( 132 | [String] 133 | $ConfigDir 134 | ) { 135 | Write-Verbose "Given ConfigDir=$ConfigDir, obtain values in pyvenv.cfg" 136 | 137 | # Ensure the file exists, and issue a warning if it doesn't (but still allow the function to continue). 138 | $pyvenvConfigPath = Join-Path -Resolve -Path $ConfigDir -ChildPath 'pyvenv.cfg' -ErrorAction Continue 139 | 140 | # An empty map will be returned if no config file is found. 141 | $pyvenvConfig = @{ } 142 | 143 | if ($pyvenvConfigPath) { 144 | 145 | Write-Verbose "File exists, parse `key = value` lines" 146 | $pyvenvConfigContent = Get-Content -Path $pyvenvConfigPath 147 | 148 | $pyvenvConfigContent | ForEach-Object { 149 | $keyval = $PSItem -split "\s*=\s*", 2 150 | if ($keyval[0] -and $keyval[1]) { 151 | $val = $keyval[1] 152 | 153 | # Remove extraneous quotations around a string value. 154 | if ("'""".Contains($val.Substring(0, 1))) { 155 | $val = $val.Substring(1, $val.Length - 2) 156 | } 157 | 158 | $pyvenvConfig[$keyval[0]] = $val 159 | Write-Verbose "Adding Key: '$($keyval[0])'='$val'" 160 | } 161 | } 162 | } 163 | return $pyvenvConfig 164 | } 165 | 166 | 167 | <# Begin Activate script --------------------------------------------------- #> 168 | 169 | # Determine the containing directory of this script 170 | $VenvExecPath = Split-Path -Parent $MyInvocation.MyCommand.Definition 171 | $VenvExecDir = Get-Item -Path $VenvExecPath 172 | 173 | Write-Verbose "Activation script is located in path: '$VenvExecPath'" 174 | Write-Verbose "VenvExecDir Fullname: '$($VenvExecDir.FullName)" 175 | Write-Verbose "VenvExecDir Name: '$($VenvExecDir.Name)" 176 | 177 | # Set values required in priority: CmdLine, ConfigFile, Default 178 | # First, get the location of the virtual environment, it might not be 179 | # VenvExecDir if specified on the command line. 180 | if ($VenvDir) { 181 | Write-Verbose "VenvDir given as parameter, using '$VenvDir' to determine values" 182 | } 183 | else { 184 | Write-Verbose "VenvDir not given as a parameter, using parent directory name as VenvDir." 185 | $VenvDir = $VenvExecDir.Parent.FullName.TrimEnd("\\/") 186 | Write-Verbose "VenvDir=$VenvDir" 187 | } 188 | 189 | # Next, read the `pyvenv.cfg` file to determine any required value such 190 | # as `prompt`. 191 | $pyvenvCfg = Get-PyVenvConfig -ConfigDir $VenvDir 192 | 193 | # Next, set the prompt from the command line, or the config file, or 194 | # just use the name of the virtual environment folder. 195 | if ($Prompt) { 196 | Write-Verbose "Prompt specified as argument, using '$Prompt'" 197 | } 198 | else { 199 | Write-Verbose "Prompt not specified as argument to script, checking pyvenv.cfg value" 200 | if ($pyvenvCfg -and $pyvenvCfg['prompt']) { 201 | Write-Verbose " Setting based on value in pyvenv.cfg='$($pyvenvCfg['prompt'])'" 202 | $Prompt = $pyvenvCfg['prompt']; 203 | } 204 | else { 205 | Write-Verbose " Setting prompt based on parent's directory's name. (Is the directory name passed to venv module when creating the virtual environment)" 206 | Write-Verbose " Got leaf-name of $VenvDir='$(Split-Path -Path $venvDir -Leaf)'" 207 | $Prompt = Split-Path -Path $venvDir -Leaf 208 | } 209 | } 210 | 211 | Write-Verbose "Prompt = '$Prompt'" 212 | Write-Verbose "VenvDir='$VenvDir'" 213 | 214 | # Deactivate any currently active virtual environment, but leave the 215 | # deactivate function in place. 216 | deactivate -nondestructive 217 | 218 | # Now set the environment variable VIRTUAL_ENV, used by many tools to determine 219 | # that there is an activated venv. 220 | $env:VIRTUAL_ENV = $VenvDir 221 | 222 | if (-not $Env:VIRTUAL_ENV_DISABLE_PROMPT) { 223 | 224 | Write-Verbose "Setting prompt to '$Prompt'" 225 | 226 | # Set the prompt to include the env name 227 | # Make sure _OLD_VIRTUAL_PROMPT is global 228 | function global:_OLD_VIRTUAL_PROMPT { "" } 229 | Copy-Item -Path function:prompt -Destination function:_OLD_VIRTUAL_PROMPT 230 | New-Variable -Name _PYTHON_VENV_PROMPT_PREFIX -Description "Python virtual environment prompt prefix" -Scope Global -Option ReadOnly -Visibility Public -Value $Prompt 231 | 232 | function global:prompt { 233 | Write-Host -NoNewline -ForegroundColor Green "($_PYTHON_VENV_PROMPT_PREFIX) " 234 | _OLD_VIRTUAL_PROMPT 235 | } 236 | $env:VIRTUAL_ENV_PROMPT = $Prompt 237 | } 238 | 239 | # Clear PYTHONHOME 240 | if (Test-Path -Path Env:PYTHONHOME) { 241 | Copy-Item -Path Env:PYTHONHOME -Destination Env:_OLD_VIRTUAL_PYTHONHOME 242 | Remove-Item -Path Env:PYTHONHOME 243 | } 244 | 245 | # Add the venv to the PATH 246 | Copy-Item -Path Env:PATH -Destination Env:_OLD_VIRTUAL_PATH 247 | $Env:PATH = "$VenvExecDir$([System.IO.Path]::PathSeparator)$Env:PATH" 248 | -------------------------------------------------------------------------------- /client/bin/activate: -------------------------------------------------------------------------------- 1 | # This file must be used with "source bin/activate" *from bash* 2 | # You cannot run it directly 3 | 4 | deactivate () { 5 | # reset old environment variables 6 | if [ -n "${_OLD_VIRTUAL_PATH:-}" ] ; then 7 | PATH="${_OLD_VIRTUAL_PATH:-}" 8 | export PATH 9 | unset _OLD_VIRTUAL_PATH 10 | fi 11 | if [ -n "${_OLD_VIRTUAL_PYTHONHOME:-}" ] ; then 12 | PYTHONHOME="${_OLD_VIRTUAL_PYTHONHOME:-}" 13 | export PYTHONHOME 14 | unset _OLD_VIRTUAL_PYTHONHOME 15 | fi 16 | 17 | # Call hash to forget past commands. Without forgetting 18 | # past commands the $PATH changes we made may not be respected 19 | hash -r 2> /dev/null 20 | 21 | if [ -n "${_OLD_VIRTUAL_PS1:-}" ] ; then 22 | PS1="${_OLD_VIRTUAL_PS1:-}" 23 | export PS1 24 | unset _OLD_VIRTUAL_PS1 25 | fi 26 | 27 | unset VIRTUAL_ENV 28 | unset VIRTUAL_ENV_PROMPT 29 | if [ ! "${1:-}" = "nondestructive" ] ; then 30 | # Self destruct! 31 | unset -f deactivate 32 | fi 33 | } 34 | 35 | # unset irrelevant variables 36 | deactivate nondestructive 37 | 38 | # on Windows, a path can contain colons and backslashes and has to be converted: 39 | if [ "${OSTYPE:-}" = "cygwin" ] || [ "${OSTYPE:-}" = "msys" ] ; then 40 | # transform D:\path\to\venv to /d/path/to/venv on MSYS 41 | # and to /cygdrive/d/path/to/venv on Cygwin 42 | export VIRTUAL_ENV=$(cygpath "/Users/mokeefe/dev/papermusic/client") 43 | else 44 | # use the path as-is 45 | export VIRTUAL_ENV="/Users/mokeefe/dev/papermusic/client" 46 | fi 47 | 48 | _OLD_VIRTUAL_PATH="$PATH" 49 | PATH="$VIRTUAL_ENV/bin:$PATH" 50 | export PATH 51 | 52 | # unset PYTHONHOME if set 53 | # this will fail if PYTHONHOME is set to the empty string (which is bad anyway) 54 | # could use `if (set -u; : $PYTHONHOME) ;` in bash 55 | if [ -n "${PYTHONHOME:-}" ] ; then 56 | _OLD_VIRTUAL_PYTHONHOME="${PYTHONHOME:-}" 57 | unset PYTHONHOME 58 | fi 59 | 60 | if [ -z "${VIRTUAL_ENV_DISABLE_PROMPT:-}" ] ; then 61 | _OLD_VIRTUAL_PS1="${PS1:-}" 62 | PS1="(client) ${PS1:-}" 63 | export PS1 64 | VIRTUAL_ENV_PROMPT="(client) " 65 | export VIRTUAL_ENV_PROMPT 66 | fi 67 | 68 | # Call hash to forget past commands. Without forgetting 69 | # past commands the $PATH changes we made may not be respected 70 | hash -r 2> /dev/null 71 | -------------------------------------------------------------------------------- /client/bin/activate.csh: -------------------------------------------------------------------------------- 1 | # This file must be used with "source bin/activate.csh" *from csh*. 2 | # You cannot run it directly. 3 | 4 | # Created by Davide Di Blasi . 5 | # Ported to Python 3.3 venv by Andrew Svetlov 6 | 7 | alias deactivate 'test $?_OLD_VIRTUAL_PATH != 0 && setenv PATH "$_OLD_VIRTUAL_PATH" && unset _OLD_VIRTUAL_PATH; rehash; test $?_OLD_VIRTUAL_PROMPT != 0 && set prompt="$_OLD_VIRTUAL_PROMPT" && unset _OLD_VIRTUAL_PROMPT; unsetenv VIRTUAL_ENV; unsetenv VIRTUAL_ENV_PROMPT; test "\!:*" != "nondestructive" && unalias deactivate' 8 | 9 | # Unset irrelevant variables. 10 | deactivate nondestructive 11 | 12 | setenv VIRTUAL_ENV "/Users/mokeefe/dev/papermusic/client" 13 | 14 | set _OLD_VIRTUAL_PATH="$PATH" 15 | setenv PATH "$VIRTUAL_ENV/bin:$PATH" 16 | 17 | 18 | set _OLD_VIRTUAL_PROMPT="$prompt" 19 | 20 | if (! "$?VIRTUAL_ENV_DISABLE_PROMPT") then 21 | set prompt = "(client) $prompt" 22 | setenv VIRTUAL_ENV_PROMPT "(client) " 23 | endif 24 | 25 | alias pydoc python -m pydoc 26 | 27 | rehash 28 | -------------------------------------------------------------------------------- /client/bin/activate.fish: -------------------------------------------------------------------------------- 1 | # This file must be used with "source /bin/activate.fish" *from fish* 2 | # (https://fishshell.com/). You cannot run it directly. 3 | 4 | function deactivate -d "Exit virtual environment and return to normal shell environment" 5 | # reset old environment variables 6 | if test -n "$_OLD_VIRTUAL_PATH" 7 | set -gx PATH $_OLD_VIRTUAL_PATH 8 | set -e _OLD_VIRTUAL_PATH 9 | end 10 | if test -n "$_OLD_VIRTUAL_PYTHONHOME" 11 | set -gx PYTHONHOME $_OLD_VIRTUAL_PYTHONHOME 12 | set -e _OLD_VIRTUAL_PYTHONHOME 13 | end 14 | 15 | if test -n "$_OLD_FISH_PROMPT_OVERRIDE" 16 | set -e _OLD_FISH_PROMPT_OVERRIDE 17 | # prevents error when using nested fish instances (Issue #93858) 18 | if functions -q _old_fish_prompt 19 | functions -e fish_prompt 20 | functions -c _old_fish_prompt fish_prompt 21 | functions -e _old_fish_prompt 22 | end 23 | end 24 | 25 | set -e VIRTUAL_ENV 26 | set -e VIRTUAL_ENV_PROMPT 27 | if test "$argv[1]" != "nondestructive" 28 | # Self-destruct! 29 | functions -e deactivate 30 | end 31 | end 32 | 33 | # Unset irrelevant variables. 34 | deactivate nondestructive 35 | 36 | set -gx VIRTUAL_ENV "/Users/mokeefe/dev/papermusic/client" 37 | 38 | set -gx _OLD_VIRTUAL_PATH $PATH 39 | set -gx PATH "$VIRTUAL_ENV/bin" $PATH 40 | 41 | # Unset PYTHONHOME if set. 42 | if set -q PYTHONHOME 43 | set -gx _OLD_VIRTUAL_PYTHONHOME $PYTHONHOME 44 | set -e PYTHONHOME 45 | end 46 | 47 | if test -z "$VIRTUAL_ENV_DISABLE_PROMPT" 48 | # fish uses a function instead of an env var to generate the prompt. 49 | 50 | # Save the current fish_prompt function as the function _old_fish_prompt. 51 | functions -c fish_prompt _old_fish_prompt 52 | 53 | # With the original prompt function renamed, we can override with our own. 54 | function fish_prompt 55 | # Save the return status of the last command. 56 | set -l old_status $status 57 | 58 | # Output the venv prompt; color taken from the blue of the Python logo. 59 | printf "%s%s%s" (set_color 4B8BBE) "(client) " (set_color normal) 60 | 61 | # Restore the return status of the previous command. 62 | echo "exit $old_status" | . 63 | # Output the original/"old" prompt. 64 | _old_fish_prompt 65 | end 66 | 67 | set -gx _OLD_FISH_PROMPT_OVERRIDE "$VIRTUAL_ENV" 68 | set -gx VIRTUAL_ENV_PROMPT "(client) " 69 | end 70 | -------------------------------------------------------------------------------- /client/bin/f2py: -------------------------------------------------------------------------------- 1 | #!/Users/mokeefe/dev/papermusic/client/bin/python3.12 2 | # -*- coding: utf-8 -*- 3 | import re 4 | import sys 5 | from numpy.f2py.f2py2e import main 6 | if __name__ == '__main__': 7 | sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0]) 8 | sys.exit(main()) 9 | -------------------------------------------------------------------------------- /client/bin/normalizer: -------------------------------------------------------------------------------- 1 | #!/Users/mokeefe/dev/papermusic/client/bin/python3.12 2 | # -*- coding: utf-8 -*- 3 | import re 4 | import sys 5 | from charset_normalizer.cli import cli_detect 6 | if __name__ == '__main__': 7 | sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0]) 8 | sys.exit(cli_detect()) 9 | -------------------------------------------------------------------------------- /client/bin/pip: -------------------------------------------------------------------------------- 1 | #!/Users/mokeefe/dev/papermusic/client/bin/python3.12 2 | # -*- coding: utf-8 -*- 3 | import re 4 | import sys 5 | from pip._internal.cli.main import main 6 | if __name__ == '__main__': 7 | sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0]) 8 | sys.exit(main()) 9 | -------------------------------------------------------------------------------- /client/bin/pip3: -------------------------------------------------------------------------------- 1 | #!/Users/mokeefe/dev/papermusic/client/bin/python3.12 2 | # -*- coding: utf-8 -*- 3 | import re 4 | import sys 5 | from pip._internal.cli.main import main 6 | if __name__ == '__main__': 7 | sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0]) 8 | sys.exit(main()) 9 | -------------------------------------------------------------------------------- /client/bin/pip3.12: -------------------------------------------------------------------------------- 1 | #!/Users/mokeefe/dev/papermusic/client/bin/python3.12 2 | # -*- coding: utf-8 -*- 3 | import re 4 | import sys 5 | from pip._internal.cli.main import main 6 | if __name__ == '__main__': 7 | sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0]) 8 | sys.exit(main()) 9 | -------------------------------------------------------------------------------- /client/bin/python: -------------------------------------------------------------------------------- 1 | python3.12 -------------------------------------------------------------------------------- /client/bin/python3: -------------------------------------------------------------------------------- 1 | python3.12 -------------------------------------------------------------------------------- /client/bin/python3.12: -------------------------------------------------------------------------------- 1 | /opt/homebrew/opt/python@3.12/bin/python3.12 -------------------------------------------------------------------------------- /client/bin/range-detector: -------------------------------------------------------------------------------- 1 | #!/Users/mokeefe/dev/papermusic/client/bin/python3.12 2 | # -*- coding: utf-8 -*- 3 | 4 | # USAGE: You need to specify a filter and "only one" image source 5 | # 6 | # (python) range-detector --filter RGB --image /path/to/image.png 7 | # or 8 | # (python) range-detector --filter HSV --webcam 9 | 10 | import cv2 11 | import argparse 12 | from operator import xor 13 | 14 | 15 | def callback(value): 16 | pass 17 | 18 | 19 | def setup_trackbars(range_filter): 20 | cv2.namedWindow("Trackbars", 0) 21 | 22 | for i in ["MIN", "MAX"]: 23 | v = 0 if i == "MIN" else 255 24 | 25 | for j in range_filter: 26 | cv2.createTrackbar("%s_%s" % (j, i), "Trackbars", v, 255, callback) 27 | 28 | 29 | def get_arguments(): 30 | ap = argparse.ArgumentParser() 31 | ap.add_argument('-f', '--filter', required=True, 32 | help='Range filter. RGB or HSV') 33 | ap.add_argument('-i', '--image', required=False, 34 | help='Path to the image') 35 | ap.add_argument('-w', '--webcam', required=False, 36 | help='Use webcam', action='store_true') 37 | ap.add_argument('-p', '--preview', required=False, 38 | help='Show a preview of the image after applying the mask', 39 | action='store_true') 40 | args = vars(ap.parse_args()) 41 | 42 | if not xor(bool(args['image']), bool(args['webcam'])): 43 | ap.error("Please specify only one image source") 44 | 45 | if not args['filter'].upper() in ['RGB', 'HSV']: 46 | ap.error("Please speciy a correct filter.") 47 | 48 | return args 49 | 50 | 51 | def get_trackbar_values(range_filter): 52 | values = [] 53 | 54 | for i in ["MIN", "MAX"]: 55 | for j in range_filter: 56 | v = cv2.getTrackbarPos("%s_%s" % (j, i), "Trackbars") 57 | values.append(v) 58 | 59 | return values 60 | 61 | 62 | def main(): 63 | args = get_arguments() 64 | 65 | range_filter = args['filter'].upper() 66 | 67 | if args['image']: 68 | image = cv2.imread(args['image']) 69 | 70 | if range_filter == 'RGB': 71 | frame_to_thresh = image.copy() 72 | else: 73 | frame_to_thresh = cv2.cvtColor(image, cv2.COLOR_BGR2HSV) 74 | else: 75 | camera = cv2.VideoCapture(0) 76 | 77 | setup_trackbars(range_filter) 78 | 79 | while True: 80 | if args['webcam']: 81 | ret, image = camera.read() 82 | 83 | if not ret: 84 | break 85 | 86 | if range_filter == 'RGB': 87 | frame_to_thresh = image.copy() 88 | else: 89 | frame_to_thresh = cv2.cvtColor(image, cv2.COLOR_BGR2HSV) 90 | 91 | v1_min, v2_min, v3_min, v1_max, v2_max, v3_max = get_trackbar_values(range_filter) 92 | 93 | thresh = cv2.inRange(frame_to_thresh, (v1_min, v2_min, v3_min), (v1_max, v2_max, v3_max)) 94 | 95 | if args['preview']: 96 | preview = cv2.bitwise_and(image, image, mask=thresh) 97 | cv2.imshow("Preview", preview) 98 | else: 99 | cv2.imshow("Original", image) 100 | cv2.imshow("Thresh", thresh) 101 | 102 | if cv2.waitKey(1) & 0xFF is ord('q'): 103 | break 104 | 105 | 106 | if __name__ == '__main__': 107 | main() 108 | -------------------------------------------------------------------------------- /client/pyvenv.cfg: -------------------------------------------------------------------------------- 1 | home = /opt/homebrew/opt/python@3.12/bin 2 | include-system-site-packages = false 3 | version = 3.12.3 4 | executable = /opt/homebrew/Cellar/python@3.12/3.12.3/Frameworks/Python.framework/Versions/3.12/bin/python3.12 5 | command = /opt/homebrew/opt/python@3.12/bin/python3.12 -m venv /Users/mokeefe/dev/papermusic/client 6 | -------------------------------------------------------------------------------- /client/requirements.txt: -------------------------------------------------------------------------------- 1 | imutils 2 | numpy 3 | opencv-python 4 | pydantic 5 | python-rtmidi 6 | requests 7 | scamp 8 | scamp_extensions -------------------------------------------------------------------------------- /client/webcamclient.py: -------------------------------------------------------------------------------- 1 | import socket 2 | import cv2 3 | import struct 4 | import sys 5 | import time 6 | 7 | # configure recipient host/port (server websocket) 8 | host = sys.argv[1] 9 | port = 5000 10 | 11 | 12 | def send_webcam_stream(): 13 | try: 14 | sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 15 | sock.connect((host, port)) 16 | print("📡 Connected to server: {}:{}".format(host, port)) 17 | cap = cv2.VideoCapture(0) 18 | print("➡️ Streaming webcam to: {}:{}...".format(host, port)) 19 | ret, frame = cap.read() 20 | except Exception as e: 21 | print("❌ Error connecting to server: {}".format(e)) 22 | return 23 | print("Sending stream...") 24 | while ret: 25 | try: 26 | # compress frame 27 | retval, buffer = cv2.imencode(".jpg", frame) 28 | 29 | if retval: 30 | # convert to byte array 31 | buffer = buffer.tobytes() 32 | # get size of the frame 33 | buffer_size = len(buffer) 34 | 35 | # send size of the frame 36 | sock.sendall(struct.pack("!I", buffer_size)) 37 | 38 | # send the frame 39 | sock.sendall(buffer) 40 | # print("🟪 Sent frame of buffer_size: {}".format(buffer_size)) 41 | 42 | ret, frame = cap.read() 43 | time.sleep(0.4) 44 | except Exception as e: 45 | print("❌ Error sending frame... {}".format(e)) 46 | continue 47 | 48 | print("☎️ Quitting client...") 49 | sock.close() 50 | 51 | 52 | if __name__ == "__main__": 53 | send_webcam_stream() 54 | -------------------------------------------------------------------------------- /experiments/gensound.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 2, 6 | "metadata": {}, 7 | "outputs": [ 8 | { 9 | "name": "stdout", 10 | "output_type": "stream", 11 | "text": [ 12 | "Requirement already satisfied: gensound in /opt/homebrew/lib/python3.10/site-packages (0.5.3)\n", 13 | "Requirement already satisfied: numpy in /opt/homebrew/lib/python3.10/site-packages (from gensound) (1.23.3)\n" 14 | ] 15 | } 16 | ], 17 | "source": [ 18 | "! pip install gensound" 19 | ] 20 | }, 21 | { 22 | "cell_type": "code", 23 | "execution_count": 3, 24 | "metadata": {}, 25 | "outputs": [], 26 | "source": [ 27 | "# https://github.com/Quefumas/gensound/wiki/Melodic-Shorthand-Notation \n", 28 | "from gensound import Sine, Triangle\n", 29 | "\n" 30 | ] 31 | }, 32 | { 33 | "cell_type": "code", 34 | "execution_count": 6, 35 | "metadata": {}, 36 | "outputs": [], 37 | "source": [ 38 | "# Syntax: \n", 39 | "# [Pitch name][sharps/flats][octave (default 4)][+- cents]\n", 40 | "s = Sine('D5 C# A F# B G# E# C# F#', duration=0.5e3)\n", 41 | "s.play()" 42 | ] 43 | }, 44 | { 45 | "cell_type": "code", 46 | "execution_count": 5, 47 | "metadata": {}, 48 | "outputs": [], 49 | "source": [ 50 | "t = Triangle(\"C3 D E G F# E B D C# A B G# F#\", duration=0.5e3) # all notes with same duration\n", 51 | "t.play()" 52 | ] 53 | }, 54 | { 55 | "cell_type": "code", 56 | "execution_count": 7, 57 | "metadata": {}, 58 | "outputs": [ 59 | { 60 | "name": "stderr", 61 | "output_type": "stream", 62 | "text": [ 63 | "UserWarning: Output audio signal amplitude exceeds 1 (max abs. amplitude 2.58). By default, the signal will be shrunk to fit range of [-1, 1] to prevent clipping. To prevent this behaviour, set the max_amplitude argument to zero, which leaves the signal untouched, or to any positive number, which will stretch/shrink it to match the given peak amplitude.\n" 64 | ] 65 | } 66 | ], 67 | "source": [ 68 | "from gensound import Sine, Triangle, Square, Pan\n", 69 | "\n", 70 | "sig = Triangle # Sine? Square?\n", 71 | "\n", 72 | "beat = 0.5e3 # 120 bpm\n", 73 | "fermata = 0.1 # make fermatas in the melody slightly longer\n", 74 | "pause = 0.6 # and breathe for a moment before starting the next phrase\n", 75 | "\n", 76 | "S = sig(f\"r D5 D=2 C#=1 B-13=2 A=1 D E=2 F#-13={2+fermata} r={pause} F#=1 F#=2 F#=1 E=2 F#-13=1 G F#-13=2 E={2+fermata} r={pause} \"\n", 77 | " f\"D+16=1 E=2 F#-13=1 E=2 D+16=1 B-13 C#=2 D+9={2+fermata} r={pause} A'=1 F#-13=2 D+16=1 E=2 G=1 F#-13 E=2 D=3\", beat)\n", 78 | "A = sig(f\"r A4 B=2 A+16=1 G=2 F#-13=1 F# B-13 A A={2+fermata} r={pause} C#=1 B=2 B=1 B A A A D A A={2+fermata} r={pause} \"\n", 79 | " f\"B=1 A=2 A=1 B-13 A=0.5 G F#=1 B-13 B A#-13 B={2+fermata} r={pause} A=1 A=2 B=1 A=2 A=1 A B-13 A F#-13=3\", beat)\n", 80 | "T = sig(f\"r F#4-13 F#=2 F#=1 D=2 D=1 D D C#-13 D={2+fermata} r={pause} C#=1 D+16=2 D+16=1 D C#-13 D E A, D C#-13={2+fermata} r={pause} \"\n", 81 | " f\"F#=1 E=2 D=1 D C#-13 D+16 D G+5 F# F#={2+fermata} r={pause} E=1 F#-13=2 F#=1 E=2 C#-13=1 A B C#-13 D=3\", beat)\n", 82 | "B = sig(f\"r D3 B-16 D F# G B-13 D B-16 G A D,={2+fermata} r={pause} A#'-13=1 B=2 A=1 G#-13 A F#-13 C#-13 D F#-13 A={2+fermata} r={pause} \"\n", 83 | " f\"B=1 C#-13=2 D=1 G, A B G E F# B,={2+fermata} r={pause} C#'-13=1 D C# B C#-13 B A D G, A D,=3\", beat)\n", 84 | "\n", 85 | "chorale = S*Pan(25) + B*Pan(-25) + T*Pan(80) + A*Pan(-80) # position the voices in the stereo field\n", 86 | "chorale.play() # can you spot the parallel octaves?" 87 | ] 88 | }, 89 | { 90 | "cell_type": "code", 91 | "execution_count": null, 92 | "metadata": {}, 93 | "outputs": [], 94 | "source": [] 95 | } 96 | ], 97 | "metadata": { 98 | "kernelspec": { 99 | "display_name": "Python 3", 100 | "language": "python", 101 | "name": "python3" 102 | }, 103 | "language_info": { 104 | "codemirror_mode": { 105 | "name": "ipython", 106 | "version": 3 107 | }, 108 | "file_extension": ".py", 109 | "mimetype": "text/x-python", 110 | "name": "python", 111 | "nbconvert_exporter": "python", 112 | "pygments_lexer": "ipython3", 113 | "version": "3.10.13" 114 | } 115 | }, 116 | "nbformat": 4, 117 | "nbformat_minor": 2 118 | } 119 | -------------------------------------------------------------------------------- /experiments/musicalbeeps.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 2, 6 | "metadata": {}, 7 | "outputs": [ 8 | { 9 | "name": "stdout", 10 | "output_type": "stream", 11 | "text": [ 12 | "Requirement already satisfied: musicalbeeps in /opt/homebrew/lib/python3.10/site-packages (0.2.9)\n", 13 | "Requirement already satisfied: numpy in /opt/homebrew/lib/python3.10/site-packages (from musicalbeeps) (1.23.3)\n", 14 | "Requirement already satisfied: simpleaudio in /opt/homebrew/lib/python3.10/site-packages (from musicalbeeps) (1.0.4)\n" 15 | ] 16 | } 17 | ], 18 | "source": [ 19 | "! pip install musicalbeeps\n", 20 | "import musicalbeeps\n" 21 | ] 22 | }, 23 | { 24 | "cell_type": "code", 25 | "execution_count": 3, 26 | "metadata": {}, 27 | "outputs": [], 28 | "source": [ 29 | "player = musicalbeeps.Player(volume = 0.3,\n", 30 | " mute_output = False)" 31 | ] 32 | }, 33 | { 34 | "cell_type": "markdown", 35 | "metadata": {}, 36 | "source": [ 37 | "```\n", 38 | "note format:\n", 39 | " Each note must be formatted like so: 'A5#:1.5' (without quotes)\n", 40 | " Where:\n", 41 | " - 'A' is the note (between A and G, can be lowercase)\n", 42 | " - '5' is the octave (between 0 and 8, default=4)\n", 43 | " - '#' (or 'b') is optional and used to play a sharp or flat note\n", 44 | " - ':1.5' is the duration of the note (1.5 seconds here, default=0.5)\n", 45 | "```\n" 46 | ] 47 | }, 48 | { 49 | "cell_type": "code", 50 | "execution_count": 4, 51 | "metadata": {}, 52 | "outputs": [ 53 | { 54 | "name": "stdout", 55 | "output_type": "stream", 56 | "text": [ 57 | "Playing A (440.00 Hz) for 0.8s\n", 58 | "Playing G3b (185.00 Hz) for 2.5s\n", 59 | "Playing F5# (739.99 Hz) for 0.5s\n", 60 | "Pausing for 0.5s\n" 61 | ] 62 | } 63 | ], 64 | "source": [ 65 | "# https://pypi.org/project/musicalbeeps/\n", 66 | "# To play an A on default octave n°4 for 0.2 seconds\n", 67 | "player.play_note(\"A\", 0.8)\n", 68 | "\n", 69 | "# To play a G flat on octave n°3 for 2.5 seconds\n", 70 | "player.play_note(\"G3b\", 2.5)\n", 71 | "\n", 72 | "# To play a F sharp on octave n°5 for the default duration of 0.5 seconds\n", 73 | "player.play_note(\"F5#\")\n", 74 | "\n", 75 | "# To pause the player for 0.5 seconds\n", 76 | "player.play_note(\"pause\", 0.5)\n" 77 | ] 78 | }, 79 | { 80 | "cell_type": "code", 81 | "execution_count": 5, 82 | "metadata": {}, 83 | "outputs": [ 84 | { 85 | "name": "stdout", 86 | "output_type": "stream", 87 | "text": [ 88 | "Playing B3b (233.08 Hz) for 0.5s\n" 89 | ] 90 | } 91 | ], 92 | "source": [ 93 | "player.play_note(\"B3b\")\n" 94 | ] 95 | }, 96 | { 97 | "cell_type": "code", 98 | "execution_count": null, 99 | "metadata": {}, 100 | "outputs": [], 101 | "source": [] 102 | } 103 | ], 104 | "metadata": { 105 | "kernelspec": { 106 | "display_name": "src", 107 | "language": "python", 108 | "name": "python3" 109 | }, 110 | "language_info": { 111 | "codemirror_mode": { 112 | "name": "ipython", 113 | "version": 3 114 | }, 115 | "file_extension": ".py", 116 | "mimetype": "text/x-python", 117 | "name": "python", 118 | "nbconvert_exporter": "python", 119 | "pygments_lexer": "ipython3", 120 | "version": "3.10.13" 121 | } 122 | }, 123 | "nbformat": 4, 124 | "nbformat_minor": 2 125 | } 126 | -------------------------------------------------------------------------------- /experiments/scamp.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 1, 6 | "metadata": {}, 7 | "outputs": [ 8 | { 9 | "name": "stdout", 10 | "output_type": "stream", 11 | "text": [ 12 | "Requirement already satisfied: scamp in /Users/mokeefe/Library/Python/3.10/lib/python/site-packages (0.9.2.post2)\n", 13 | "Requirement already satisfied: arpeggio in /Users/mokeefe/Library/Python/3.10/lib/python/site-packages (from scamp) (2.0.2)\n", 14 | "Requirement already satisfied: clockblocks>=0.6.9 in /Users/mokeefe/Library/Python/3.10/lib/python/site-packages (from scamp) (0.6.9.post1)\n", 15 | "Requirement already satisfied: expenvelope>=0.7.2 in /Users/mokeefe/Library/Python/3.10/lib/python/site-packages (from scamp) (0.7.2)\n", 16 | "Requirement already satisfied: midiutil in /Users/mokeefe/Library/Python/3.10/lib/python/site-packages (from scamp) (1.2.1)\n", 17 | "Requirement already satisfied: pymusicxml>=0.5.6 in /Users/mokeefe/Library/Python/3.10/lib/python/site-packages (from scamp) (0.5.6)\n", 18 | "Requirement already satisfied: python-osc in /Users/mokeefe/Library/Python/3.10/lib/python/site-packages (from scamp) (1.8.3)\n" 19 | ] 20 | } 21 | ], 22 | "source": [ 23 | "! pip3 install --user scamp\n" 24 | ] 25 | }, 26 | { 27 | "cell_type": "code", 28 | "execution_count": 2, 29 | "metadata": {}, 30 | "outputs": [ 31 | { 32 | "name": "stdout", 33 | "output_type": "stream", 34 | "text": [ 35 | "Requirement already satisfied: python-rtmidi in /Users/mokeefe/Library/Python/3.10/lib/python/site-packages (1.5.8)\n" 36 | ] 37 | } 38 | ], 39 | "source": [ 40 | "! pip3 install --user python-rtmidi\n" 41 | ] 42 | }, 43 | { 44 | "cell_type": "code", 45 | "execution_count": 3, 46 | "metadata": {}, 47 | "outputs": [ 48 | { 49 | "name": "stdout", 50 | "output_type": "stream", 51 | "text": [ 52 | "Requirement already satisfied: scamp_extensions in /Users/mokeefe/Library/Python/3.10/lib/python/site-packages (0.3.5.post2)\n", 53 | "Requirement already satisfied: scamp>=0.9.2 in /Users/mokeefe/Library/Python/3.10/lib/python/site-packages (from scamp_extensions) (0.9.2.post2)\n", 54 | "Requirement already satisfied: arpeggio in /Users/mokeefe/Library/Python/3.10/lib/python/site-packages (from scamp>=0.9.2->scamp_extensions) (2.0.2)\n", 55 | "Requirement already satisfied: clockblocks>=0.6.9 in /Users/mokeefe/Library/Python/3.10/lib/python/site-packages (from scamp>=0.9.2->scamp_extensions) (0.6.9.post1)\n", 56 | "Requirement already satisfied: expenvelope>=0.7.2 in /Users/mokeefe/Library/Python/3.10/lib/python/site-packages (from scamp>=0.9.2->scamp_extensions) (0.7.2)\n", 57 | "Requirement already satisfied: midiutil in /Users/mokeefe/Library/Python/3.10/lib/python/site-packages (from scamp>=0.9.2->scamp_extensions) (1.2.1)\n", 58 | "Requirement already satisfied: pymusicxml>=0.5.6 in /Users/mokeefe/Library/Python/3.10/lib/python/site-packages (from scamp>=0.9.2->scamp_extensions) (0.5.6)\n", 59 | "Requirement already satisfied: python-osc in /Users/mokeefe/Library/Python/3.10/lib/python/site-packages (from scamp>=0.9.2->scamp_extensions) (1.8.3)\n" 60 | ] 61 | } 62 | ], 63 | "source": [ 64 | "! pip3 install --user scamp_extensions\n" 65 | ] 66 | }, 67 | { 68 | "cell_type": "code", 69 | "execution_count": 7, 70 | "metadata": {}, 71 | "outputs": [ 72 | { 73 | "name": "stderr", 74 | "output_type": "stream", 75 | "text": [ 76 | "WARNING:root:pynput was not found; mouse and keyboard input will not be available.\n" 77 | ] 78 | } 79 | ], 80 | "source": [ 81 | "from scamp import *" 82 | ] 83 | }, 84 | { 85 | "cell_type": "code", 86 | "execution_count": 8, 87 | "metadata": {}, 88 | "outputs": [], 89 | "source": [ 90 | "s = Session()" 91 | ] 92 | }, 93 | { 94 | "cell_type": "code", 95 | "execution_count": 3, 96 | "metadata": {}, 97 | "outputs": [ 98 | { 99 | "name": "stdout", 100 | "output_type": "stream", 101 | "text": [ 102 | "Using preset Clarinet for clarinet\n" 103 | ] 104 | } 105 | ], 106 | "source": [ 107 | "clarinet = s.new_part(\"clarinet\")" 108 | ] 109 | }, 110 | { 111 | "cell_type": "code", 112 | "execution_count": 7, 113 | "metadata": {}, 114 | "outputs": [], 115 | "source": [ 116 | "# pitch, volume, length\n", 117 | "clarinet.play_note(60, 0.8, 2.0)" 118 | ] 119 | }, 120 | { 121 | "cell_type": "code", 122 | "execution_count": 11, 123 | "metadata": {}, 124 | "outputs": [ 125 | { 126 | "name": "stderr", 127 | "output_type": "stream", 128 | "text": [ 129 | "WARNING:root:Clock MASTER (beat=6.0) is running noticeably behind real time (22.19198 s) on a wait call of 4.0 s; probably processing is too heavy.\n" 130 | ] 131 | }, 132 | { 133 | "name": "stdout", 134 | "output_type": "stream", 135 | "text": [ 136 | "Using preset French Horns for french horns\n" 137 | ] 138 | } 139 | ], 140 | "source": [ 141 | "\n", 142 | "f = s.new_part(\"french horns\")\n", 143 | "f.play_note(60, 0.8, 4.0)\n" 144 | ] 145 | }, 146 | { 147 | "cell_type": "code", 148 | "execution_count": 14, 149 | "metadata": {}, 150 | "outputs": [ 151 | { 152 | "name": "stdout", 153 | "output_type": "stream", 154 | "text": [ 155 | "PRESETS FOR default (general_midi)\n", 156 | " Preset[000:047] Timpani Half 2 bag(s) from #0\n", 157 | " Preset[000:051] Synth Str 2 3 bag(s) from #2\n", 158 | " Preset[000:009] Glockenspiel 2 bag(s) from #5\n", 159 | " Preset[000:048] Strings SP1 2 bag(s) from #7\n", 160 | " Preset[000:073] Flute Gold 2 bag(s) from #9\n", 161 | " Preset[000:075] Pan Flute 2 bag(s) from #11\n", 162 | " Preset[000:001] Bright Piano 2 bag(s) from #13\n", 163 | " Preset[000:000] Piano Merlin 6 bag(s) from #15\n", 164 | " Preset[000:049] Slow Strings SP 2 bag(s) from #21\n", 165 | " Preset[000:060] French Horns 2 bag(s) from #23\n", 166 | " Preset[128:048] Orchestra 2 bag(s) from #25\n", 167 | " Preset[128:032] Jazz 2 bag(s) from #27\n", 168 | " Preset[128:025] TR 808 2 bag(s) from #29\n", 169 | " Preset[128:016] Power 2 bag(s) from #31\n", 170 | " Preset[128:000] Standard 2 bag(s) from #33\n", 171 | " Preset[000:044] Tremolande 2 bag(s) from #35\n", 172 | " Preset[000:046] Harp LP2 2 bag(s) from #37\n", 173 | " Preset[000:045] Pizzicato Strings 2 bag(s) from #39\n", 174 | " Preset[000:025] Steel Guitar PH 2 bag(s) from #41\n", 175 | " Preset[000:065] Alto SAX 2 bag(s) from #43\n", 176 | " Preset[000:067] Baritone Sax 2 bag(s) from #45\n", 177 | " Preset[000:066] Tenor Sax New 2 bag(s) from #47\n", 178 | " Preset[000:024] Guitar Nylon X 2 bag(s) from #49\n", 179 | " Preset[000:022] Harmonica 2 bag(s) from #51\n", 180 | " Preset[000:041] Viola LP 2 bag(s) from #53\n", 181 | " Preset[000:064] Soprano Sax 3 bag(s) from #55\n", 182 | " Preset[000:026] Jazz Guitar 2 bag(s) from #58\n", 183 | " Preset[000:013] Xylophone 3 bag(s) from #60\n", 184 | " Preset[000:012] Marimba 2 bag(s) from #63\n", 185 | " Preset[000:050] Synth Strings 1 2 bag(s) from #65\n", 186 | " Preset[000:019] Church Organ 2 4 bag(s) from #67\n", 187 | " Preset[000:043] Contrabass 2 bag(s) from #71\n", 188 | " Preset[000:042] Cello LP 3 bag(s) from #73\n", 189 | " Preset[000:040] Violin LP3 2 bag(s) from #76\n", 190 | " Preset[000:068] Oboe 2 bag(s) from #78\n", 191 | " Preset[000:071] Clarinet 2 bag(s) from #80\n", 192 | " Preset[000:070] Bassoon (Rea) 2 bag(s) from #82\n", 193 | " Preset[000:069] English Horn (Rea) 2 bag(s) from #84\n", 194 | " Preset[000:002] Piano 3 3 bag(s) from #86\n", 195 | " Preset[000:003] Honky Tonk 3 bag(s) from #89\n", 196 | " Preset[000:004] E.Piano 1 3 bag(s) from #92\n", 197 | " Preset[000:005] E.Piano 2 2 bag(s) from #95\n", 198 | " Preset[000:007] Clavinet 2 bag(s) from #97\n", 199 | " Preset[000:008] Celesta 2 bag(s) from #99\n", 200 | " Preset[000:010] Music Box 2 bag(s) from #101\n", 201 | " Preset[000:011] Vibraphone 2 bag(s) from #103\n", 202 | " Preset[000:014] Tubular Bells 2 bag(s) from #105\n", 203 | " Preset[000:015] Dulcimer 2 bag(s) from #107\n", 204 | " Preset[000:016] Organ 1 2 bag(s) from #109\n", 205 | " Preset[000:017] Organ 2 2 bag(s) from #111\n", 206 | " Preset[000:018] Organ 3 3 bag(s) from #113\n", 207 | " Preset[000:020] Reed Organ 3 bag(s) from #116\n", 208 | " Preset[000:021] Accordion 3 bag(s) from #119\n", 209 | " Preset[000:023] Bandoneon 2 bag(s) from #122\n", 210 | " Preset[000:027] Clean Guitar 2 bag(s) from #124\n", 211 | " Preset[000:028] Guitar Mutes 2 bag(s) from #126\n", 212 | " Preset[000:029] Overdrive Guitar 2 bag(s) from #128\n", 213 | " Preset[000:030] DistortionGuitar 2 bag(s) from #130\n", 214 | " Preset[000:031] Guitar Harmonics 2 bag(s) from #132\n", 215 | " Preset[000:032] Acoustic Bass 2 bag(s) from #134\n", 216 | " Preset[000:033] Fingered Bass 2 bag(s) from #136\n", 217 | " Preset[000:034] Picked Bass 2 bag(s) from #138\n", 218 | " Preset[000:035] Fretless Bass 2 bag(s) from #140\n", 219 | " Preset[000:036] Slap Bass 1 2 bag(s) from #142\n", 220 | " Preset[000:037] Slap Bass 2 2 bag(s) from #144\n", 221 | " Preset[000:038] Synth Bass 1 2 bag(s) from #146\n", 222 | " Preset[000:039] Synth Bass 2 2 bag(s) from #148\n", 223 | " Preset[000:052] Choir Aahs 4 bag(s) from #150\n", 224 | " Preset[000:053] Voice Oohs 3 bag(s) from #154\n", 225 | " Preset[000:054] Synth Vox 2 bag(s) from #157\n", 226 | " Preset[000:055] Orchestra Hit 2 bag(s) from #159\n", 227 | " Preset[000:056] Trumpet 2 bag(s) from #161\n", 228 | " Preset[000:057] Trombone 2 bag(s) from #163\n", 229 | " Preset[000:058] Tuba 2 bag(s) from #165\n", 230 | " Preset[000:059] Mute Trumpet 2 bag(s) from #167\n", 231 | " Preset[000:061] Brass 2 bag(s) from #169\n", 232 | " Preset[000:062] Synth Brass 1 2 bag(s) from #171\n", 233 | " Preset[000:063] Synth Brass 2 2 bag(s) from #173\n", 234 | " Preset[000:072] Piccolo 2 bag(s) from #175\n", 235 | " Preset[000:074] Recorder 2 bag(s) from #177\n", 236 | " Preset[000:076] Bottle Chiff 2 bag(s) from #179\n", 237 | " Preset[000:077] Shakuhachi 2 bag(s) from #181\n", 238 | " Preset[000:078] Whistle 2 bag(s) from #183\n", 239 | " Preset[000:079] Ocarina 2 bag(s) from #185\n", 240 | " Preset[000:080] Square Wave 3 bag(s) from #187\n", 241 | " Preset[000:081] Saw Wave 3 bag(s) from #190\n", 242 | " Preset[000:082] Synth Calliope 2 bag(s) from #193\n", 243 | " Preset[000:083] Chiffer Lead 2 bag(s) from #195\n", 244 | " Preset[000:084] Charang 2 bag(s) from #197\n", 245 | " Preset[000:085] Solo Vox 2 bag(s) from #199\n", 246 | " Preset[000:086] 5th Saw Wave 2 bag(s) from #201\n", 247 | " Preset[000:087] Bass & Lead 2 bag(s) from #203\n", 248 | " Preset[000:088] Fantasia 5 bag(s) from #205\n", 249 | " Preset[000:089] Warm Pad 2 bag(s) from #210\n", 250 | " Preset[000:090] Poly Synth 2 bag(s) from #212\n", 251 | " Preset[000:091] Space Voice 2 bag(s) from #214\n", 252 | " Preset[000:092] Bowed Glass 3 bag(s) from #216\n", 253 | " Preset[000:093] Metal Pad 2 bag(s) from #219\n", 254 | " Preset[000:094] Halo Pad 2 bag(s) from #221\n", 255 | " Preset[000:095] Sweep Pad 2 bag(s) from #223\n", 256 | " Preset[000:096] Ice Rain 2 bag(s) from #225\n", 257 | " Preset[000:097] Soundtrack 2 bag(s) from #227\n", 258 | " Preset[000:098] Crystal 2 bag(s) from #229\n", 259 | " Preset[000:099] Atmosphere 2 bag(s) from #231\n", 260 | " Preset[000:100] Brightness 2 bag(s) from #233\n", 261 | " Preset[000:101] Goblin 2 bag(s) from #235\n", 262 | " Preset[000:102] Echo Drops 2 bag(s) from #237\n", 263 | " Preset[000:103] Star Theme 2 bag(s) from #239\n", 264 | " Preset[000:104] Sitar 2 bag(s) from #241\n", 265 | " Preset[000:105] Banjo 2 bag(s) from #243\n", 266 | " Preset[000:106] Shamisen 2 bag(s) from #245\n", 267 | " Preset[000:107] Koto 2 bag(s) from #247\n", 268 | " Preset[000:108] Kalimba 2 bag(s) from #249\n", 269 | " Preset[000:109] Bagpipe 2 bag(s) from #251\n", 270 | " Preset[000:110] Fiddle 2 bag(s) from #253\n", 271 | " Preset[000:111] Shenai 2 bag(s) from #255\n", 272 | " Preset[000:112] Tinker Bell 2 bag(s) from #257\n", 273 | " Preset[000:113] Agogo 2 bag(s) from #259\n", 274 | " Preset[000:114] Steel Drum 2 bag(s) from #261\n", 275 | " Preset[000:115] Wood Block 2 bag(s) from #263\n", 276 | " Preset[000:116] Taiko Drum 2 bag(s) from #265\n", 277 | " Preset[000:117] Melodic Tom 2 bag(s) from #267\n", 278 | " Preset[000:118] Synth Drum 2 bag(s) from #269\n", 279 | " Preset[000:119] Reverse Cymbal 2 bag(s) from #271\n", 280 | " Preset[000:120] Fret Noise 2 bag(s) from #273\n", 281 | " Preset[000:121] Breath Noise 2 bag(s) from #275\n", 282 | " Preset[000:122] Seashore 2 bag(s) from #277\n", 283 | " Preset[000:123] Bird 2 bag(s) from #279\n", 284 | " Preset[000:124] Telephone 2 bag(s) from #281\n", 285 | " Preset[000:125] Helicopter 2 bag(s) from #283\n", 286 | " Preset[000:126] Applause 2 bag(s) from #285\n", 287 | " Preset[000:127] Gun Shot 2 bag(s) from #287\n", 288 | " Preset[000:006] Coupled Harpsichord 3 bag(s) from #289\n", 289 | " Preset EOP\n" 290 | ] 291 | } 292 | ], 293 | "source": [ 294 | "presets = s.print_default_soundfont_presets()" 295 | ] 296 | }, 297 | { 298 | "cell_type": "code", 299 | "execution_count": 15, 300 | "metadata": {}, 301 | "outputs": [ 302 | { 303 | "name": "stdout", 304 | "output_type": "stream", 305 | "text": [ 306 | "Using preset Music Box for music box\n" 307 | ] 308 | } 309 | ], 310 | "source": [ 311 | "m = s.new_part(\"music box\")\n" 312 | ] 313 | }, 314 | { 315 | "cell_type": "code", 316 | "execution_count": 17, 317 | "metadata": {}, 318 | "outputs": [ 319 | { 320 | "name": "stderr", 321 | "output_type": "stream", 322 | "text": [ 323 | "WARNING:root:Clock MASTER (beat=11.5) is running noticeably behind real time (0.75399 s) on a wait call of 0.5 s; probably processing is too heavy.\n" 324 | ] 325 | } 326 | ], 327 | "source": [ 328 | "# http://scamp.marcevanstein.com/narrative/tutorial_videos.html#playing-notes\n", 329 | "m.play_note(80, 0.8, 0.5) \n", 330 | "m.play_note(76, 0.8, 0.5) \n", 331 | "m.play_note(80, 0.8, 0.5) " 332 | ] 333 | }, 334 | { 335 | "cell_type": "code", 336 | "execution_count": 21, 337 | "metadata": {}, 338 | "outputs": [ 339 | { 340 | "name": "stderr", 341 | "output_type": "stream", 342 | "text": [ 343 | "WARNING:root:Clock MASTER (beat=15.0) is running noticeably behind real time (1.02064 s) on a wait call of 2.0 s; probably processing is too heavy.\n" 344 | ] 345 | } 346 | ], 347 | "source": [ 348 | "m.play_chord([80, 76, 80], 0.8, 2.0)" 349 | ] 350 | }, 351 | { 352 | "cell_type": "code", 353 | "execution_count": 35, 354 | "metadata": {}, 355 | "outputs": [ 356 | { 357 | "name": "stderr", 358 | "output_type": "stream", 359 | "text": [ 360 | "WARNING:root:Clock MASTER (beat=58.1) is running noticeably behind real time (9.06179 s) on a wait call of 1.0 s; probably processing is too heavy.\n" 361 | ] 362 | } 363 | ], 364 | "source": [ 365 | "clarinet.play_note(60, 1, 1)\n", 366 | "clarinet.play_note(62, 1, 1)\n", 367 | "clarinet.play_note(64, 1, 1)\n", 368 | "clarinet.play_note(65, 1, 1)\n", 369 | "clarinet.play_note(67, 1, 1)\n", 370 | "clarinet.play_note(69, 1, 1)\n", 371 | "clarinet.play_note(71, 1, 1)\n", 372 | "clarinet.play_note(72, 1, 1)" 373 | ] 374 | }, 375 | { 376 | "cell_type": "code", 377 | "execution_count": 4, 378 | "metadata": {}, 379 | "outputs": [], 380 | "source": [ 381 | "clarinet.play_note(60, 1, 1)\n", 382 | "clarinet.play_note(62, 1, 1)\n", 383 | "clarinet.play_note(64, 1, 1)\n", 384 | "clarinet.play_note(67, 1, 1)\n", 385 | "clarinet.play_note(69, 1, 1)\n", 386 | "clarinet.play_note(72, 1, 1)\n", 387 | "clarinet.play_note(74, 1, 1)\n", 388 | "clarinet.play_note(76, 1, 1)" 389 | ] 390 | }, 391 | { 392 | "cell_type": "code", 393 | "execution_count": 2, 394 | "metadata": {}, 395 | "outputs": [], 396 | "source": [ 397 | "nm = {\n", 398 | " \"C4\": 60,\n", 399 | " \"C#4\": 61,\n", 400 | " \"D4\": 62,\n", 401 | " \"D#4\": 63,\n", 402 | " \"E4\": 64,\n", 403 | " \"F4\": 65,\n", 404 | " \"F#4\": 66,\n", 405 | " \"G4\": 67,\n", 406 | " \"G#4\": 68,\n", 407 | " \"A4\": 69,\n", 408 | " \"A#4\": 70,\n", 409 | " \"B34\": 71,\n", 410 | " \"C5\": 72,\n", 411 | " \"C#5\": 73,\n", 412 | " \"D5\": 74,\n", 413 | " \"D#5\": 75,\n", 414 | " \"E5\": 76,\n", 415 | " \"F5\": 77,\n", 416 | " \"F#5\": 78,\n", 417 | " \"G5\": 79,\n", 418 | " \"G#5\": 80,\n", 419 | " \"A5\": 81,\n", 420 | " \"A#5\": 82,\n", 421 | " \"B5\": 83,\n", 422 | " \"C6\": 84,\n", 423 | " \"C#6\": 85,\n", 424 | " \"D6\": 86,\n", 425 | " \"D#6\": 87,\n", 426 | " \"E6\": 88,\n", 427 | " \"F6\": 89,\n", 428 | " \"F#6\": 90,\n", 429 | " \"G6\": 91,\n", 430 | " \"G#6\": 92,\n", 431 | " \"A6\": 93,\n", 432 | " \"A#6\": 94,\n", 433 | " \"B6\": 95,\n", 434 | " \"C7\": 96\n", 435 | "}" 436 | ] 437 | }, 438 | { 439 | "cell_type": "code", 440 | "execution_count": 9, 441 | "metadata": {}, 442 | "outputs": [], 443 | "source": [ 444 | "def create_instrument(name : str):\n", 445 | " s = Session()\n", 446 | " try: \n", 447 | " inst = s.new_part(name)\n", 448 | " return inst \n", 449 | " except: \n", 450 | " print(\"unrecognized instrument, returning music box!\")\n", 451 | " inst = s.new_part(\"music box\")\n", 452 | " return inst " 453 | ] 454 | }, 455 | { 456 | "cell_type": "code", 457 | "execution_count": 5, 458 | "metadata": {}, 459 | "outputs": [], 460 | "source": [ 461 | "def play(inst, notename): \n", 462 | " try: \n", 463 | " inst.play_note(nm[notename], 0.8, 0.5)\n", 464 | " except: \n", 465 | " print(\"unrecognized note, skipping\")" 466 | ] 467 | }, 468 | { 469 | "cell_type": "code", 470 | "execution_count": 22, 471 | "metadata": {}, 472 | "outputs": [ 473 | { 474 | "name": "stdout", 475 | "output_type": "stream", 476 | "text": [ 477 | "Using preset Accordion for accordion\n" 478 | ] 479 | } 480 | ], 481 | "source": [ 482 | "i = create_instrument(\"accordion\")\n", 483 | "play(i, \"E4\")\n", 484 | "play(i, \"A4\")\n", 485 | "play(i, \"C#5\")" 486 | ] 487 | }, 488 | { 489 | "cell_type": "code", 490 | "execution_count": null, 491 | "metadata": {}, 492 | "outputs": [], 493 | "source": [] 494 | } 495 | ], 496 | "metadata": { 497 | "kernelspec": { 498 | "display_name": "Python 3", 499 | "language": "python", 500 | "name": "python3" 501 | }, 502 | "language_info": { 503 | "codemirror_mode": { 504 | "name": "ipython", 505 | "version": 3 506 | }, 507 | "file_extension": ".py", 508 | "mimetype": "text/x-python", 509 | "name": "python", 510 | "nbconvert_exporter": "python", 511 | "pygments_lexer": "ipython3", 512 | "version": "3.10.13" 513 | } 514 | }, 515 | "nbformat": 4, 516 | "nbformat_minor": 2 517 | } 518 | -------------------------------------------------------------------------------- /experiments/webcam.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 1, 6 | "metadata": {}, 7 | "outputs": [], 8 | "source": [ 9 | "# goal - capture a webcam frame every second. " 10 | ] 11 | }, 12 | { 13 | "cell_type": "code", 14 | "execution_count": 3, 15 | "metadata": {}, 16 | "outputs": [ 17 | { 18 | "name": "stdout", 19 | "output_type": "stream", 20 | "text": [ 21 | "Collecting opencv-python\n", 22 | " Downloading opencv_python-4.9.0.80-cp37-abi3-macosx_11_0_arm64.whl.metadata (20 kB)\n", 23 | "Requirement already satisfied: numpy>=1.21.2 in /opt/homebrew/lib/python3.10/site-packages (from opencv-python) (1.23.3)\n", 24 | "Downloading opencv_python-4.9.0.80-cp37-abi3-macosx_11_0_arm64.whl (35.4 MB)\n", 25 | "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m35.4/35.4 MB\u001b[0m \u001b[31m58.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m00:01\u001b[0m00:01\u001b[0m\n", 26 | "\u001b[?25hInstalling collected packages: opencv-python\n", 27 | "Successfully installed opencv-python-4.9.0.80\n" 28 | ] 29 | } 30 | ], 31 | "source": [ 32 | "! pip install opencv-python" 33 | ] 34 | }, 35 | { 36 | "cell_type": "code", 37 | "execution_count": 10, 38 | "metadata": {}, 39 | "outputs": [ 40 | { 41 | "ename": "KeyboardInterrupt", 42 | "evalue": "", 43 | "output_type": "error", 44 | "traceback": [ 45 | "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", 46 | "\u001b[0;31mKeyboardInterrupt\u001b[0m Traceback (most recent call last)", 47 | "Cell \u001b[0;32mIn [10], line 8\u001b[0m\n\u001b[1;32m 5\u001b[0m fps \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mint\u001b[39m(cap\u001b[38;5;241m.\u001b[39mget(cv2\u001b[38;5;241m.\u001b[39mCAP_PROP_FPS)) \u001b[38;5;66;03m# Get frames per second\u001b[39;00m\n\u001b[1;32m 7\u001b[0m \u001b[38;5;28;01mwhile\u001b[39;00m cap\u001b[38;5;241m.\u001b[39misOpened():\n\u001b[0;32m----> 8\u001b[0m ret, frame \u001b[38;5;241m=\u001b[39m cap\u001b[38;5;241m.\u001b[39mread()\n\u001b[1;32m 9\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m ret:\n\u001b[1;32m 10\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m count \u001b[38;5;241m%\u001b[39m fps \u001b[38;5;241m==\u001b[39m \u001b[38;5;241m0\u001b[39m: \u001b[38;5;66;03m# Capture frame every second\u001b[39;00m\n", 48 | "\u001b[0;31mKeyboardInterrupt\u001b[0m: " 49 | ] 50 | } 51 | ], 52 | "source": [ 53 | "import cv2\n", 54 | "\n", 55 | "cap = cv2.VideoCapture(0) # 0 is the default webcam\n", 56 | "count = 0\n", 57 | "fps = int(cap.get(cv2.CAP_PROP_FPS)) # Get frames per second\n", 58 | "\n", 59 | "while cap.isOpened():\n", 60 | " ret, frame = cap.read()\n", 61 | " if ret:\n", 62 | " if count % fps == 0: # Capture frame every second\n", 63 | " cv2.imwrite('framecapture/{:d}.jpg'.format(count//fps), frame)\n", 64 | " count += 1\n", 65 | " if cv2.waitKey(1) & 0xFF == ord('q'): # Press 'q' to quit\n", 66 | " break\n", 67 | " else:\n", 68 | " break\n", 69 | "\n", 70 | "cap.release()\n", 71 | "cv2.destroyAllWindows()" 72 | ] 73 | }, 74 | { 75 | "cell_type": "code", 76 | "execution_count": 11, 77 | "metadata": {}, 78 | "outputs": [], 79 | "source": [ 80 | "def cleanup():\n", 81 | " # delete all files in framecapture/ \n", 82 | " import os\n", 83 | " import shutil\n", 84 | " folder = 'framecapture/'\n", 85 | " for filename in os.listdir(folder):\n", 86 | " file_path = os.path.join(folder, filename)\n", 87 | " try:\n", 88 | " if os.path.isfile(file_path) or os.path.islink(file_path):\n", 89 | " os.unlink(file_path)\n", 90 | " elif os.path.isdir(file_path):\n", 91 | " shutil.rmtree(file_path)\n", 92 | " except Exception as e:\n", 93 | " print('Failed to delete %s. Reason: %s' % (file_path, e))\n", 94 | " " 95 | ] 96 | }, 97 | { 98 | "cell_type": "code", 99 | "execution_count": 12, 100 | "metadata": {}, 101 | "outputs": [], 102 | "source": [ 103 | "cleanup()" 104 | ] 105 | }, 106 | { 107 | "cell_type": "code", 108 | "execution_count": null, 109 | "metadata": {}, 110 | "outputs": [], 111 | "source": [] 112 | } 113 | ], 114 | "metadata": { 115 | "kernelspec": { 116 | "display_name": "Python 3", 117 | "language": "python", 118 | "name": "python3" 119 | }, 120 | "language_info": { 121 | "codemirror_mode": { 122 | "name": "ipython", 123 | "version": 3 124 | }, 125 | "file_extension": ".py", 126 | "mimetype": "text/x-python", 127 | "name": "python", 128 | "nbconvert_exporter": "python", 129 | "pygments_lexer": "ipython3", 130 | "version": "3.10.13" 131 | } 132 | }, 133 | "nbformat": 4, 134 | "nbformat_minor": 2 135 | } 136 | -------------------------------------------------------------------------------- /images/architecture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/askmeegs/papermusic/8ae6813a3438612a170c75a60e63edf5be844e1f/images/architecture.png -------------------------------------------------------------------------------- /images/screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/askmeegs/papermusic/8ae6813a3438612a170c75a60e63edf5be844e1f/images/screenshot.png -------------------------------------------------------------------------------- /presets.md: -------------------------------------------------------------------------------- 1 | ``` 2 | PRESETS FOR default (general_midi) 3 | Preset[000:047] Timpani Half 2 bag(s) from #0 4 | Preset[000:051] Synth Str 2 3 bag(s) from #2 5 | Preset[000:009] Glockenspiel 2 bag(s) from #5 6 | Preset[000:048] Strings SP1 2 bag(s) from #7 7 | Preset[000:073] Flute Gold 2 bag(s) from #9 8 | Preset[000:075] Pan Flute 2 bag(s) from #11 9 | Preset[000:001] Bright Piano 2 bag(s) from #13 10 | Preset[000:000] Piano Merlin 6 bag(s) from #15 11 | Preset[000:049] Slow Strings SP 2 bag(s) from #21 12 | Preset[000:060] French Horns 2 bag(s) from #23 13 | Preset[128:048] Orchestra 2 bag(s) from #25 14 | Preset[128:032] Jazz 2 bag(s) from #27 15 | Preset[128:025] TR 808 2 bag(s) from #29 16 | Preset[128:016] Power 2 bag(s) from #31 17 | Preset[128:000] Standard 2 bag(s) from #33 18 | Preset[000:044] Tremolande 2 bag(s) from #35 19 | Preset[000:046] Harp LP2 2 bag(s) from #37 20 | Preset[000:045] Pizzicato Strings 2 bag(s) from #39 21 | Preset[000:025] Steel Guitar PH 2 bag(s) from #41 22 | Preset[000:065] Alto SAX 2 bag(s) from #43 23 | Preset[000:067] Baritone Sax 2 bag(s) from #45 24 | Preset[000:066] Tenor Sax New 2 bag(s) from #47 25 | Preset[000:024] Guitar Nylon X 2 bag(s) from #49 26 | Preset[000:022] Harmonica 2 bag(s) from #51 27 | Preset[000:041] Viola LP 2 bag(s) from #53 28 | Preset[000:064] Soprano Sax 3 bag(s) from #55 29 | Preset[000:026] Jazz Guitar 2 bag(s) from #58 30 | Preset[000:013] Xylophone 3 bag(s) from #60 31 | Preset[000:012] Marimba 2 bag(s) from #63 32 | Preset[000:050] Synth Strings 1 2 bag(s) from #65 33 | Preset[000:019] Church Organ 2 4 bag(s) from #67 34 | Preset[000:043] Contrabass 2 bag(s) from #71 35 | Preset[000:042] Cello LP 3 bag(s) from #73 36 | Preset[000:040] Violin LP3 2 bag(s) from #76 37 | Preset[000:068] Oboe 2 bag(s) from #78 38 | Preset[000:071] Clarinet 2 bag(s) from #80 39 | Preset[000:070] Bassoon (Rea) 2 bag(s) from #82 40 | Preset[000:069] English Horn (Rea) 2 bag(s) from #84 41 | Preset[000:002] Piano 3 3 bag(s) from #86 42 | Preset[000:003] Honky Tonk 3 bag(s) from #89 43 | Preset[000:004] E.Piano 1 3 bag(s) from #92 44 | Preset[000:005] E.Piano 2 2 bag(s) from #95 45 | Preset[000:007] Clavinet 2 bag(s) from #97 46 | Preset[000:008] Celesta 2 bag(s) from #99 47 | Preset[000:010] Music Box 2 bag(s) from #101 48 | Preset[000:011] Vibraphone 2 bag(s) from #103 49 | Preset[000:014] Tubular Bells 2 bag(s) from #105 50 | Preset[000:015] Dulcimer 2 bag(s) from #107 51 | Preset[000:016] Organ 1 2 bag(s) from #109 52 | Preset[000:017] Organ 2 2 bag(s) from #111 53 | Preset[000:018] Organ 3 3 bag(s) from #113 54 | Preset[000:020] Reed Organ 3 bag(s) from #116 55 | Preset[000:021] Accordion 3 bag(s) from #119 56 | Preset[000:023] Bandoneon 2 bag(s) from #122 57 | Preset[000:027] Clean Guitar 2 bag(s) from #124 58 | Preset[000:028] Guitar Mutes 2 bag(s) from #126 59 | Preset[000:029] Overdrive Guitar 2 bag(s) from #128 60 | Preset[000:030] DistortionGuitar 2 bag(s) from #130 61 | Preset[000:031] Guitar Harmonics 2 bag(s) from #132 62 | Preset[000:032] Acoustic Bass 2 bag(s) from #134 63 | Preset[000:033] Fingered Bass 2 bag(s) from #136 64 | Preset[000:034] Picked Bass 2 bag(s) from #138 65 | Preset[000:035] Fretless Bass 2 bag(s) from #140 66 | Preset[000:036] Slap Bass 1 2 bag(s) from #142 67 | Preset[000:037] Slap Bass 2 2 bag(s) from #144 68 | Preset[000:038] Synth Bass 1 2 bag(s) from #146 69 | Preset[000:039] Synth Bass 2 2 bag(s) from #148 70 | Preset[000:052] Choir Aahs 4 bag(s) from #150 71 | Preset[000:053] Voice Oohs 3 bag(s) from #154 72 | Preset[000:054] Synth Vox 2 bag(s) from #157 73 | Preset[000:055] Orchestra Hit 2 bag(s) from #159 74 | Preset[000:056] Trumpet 2 bag(s) from #161 75 | Preset[000:057] Trombone 2 bag(s) from #163 76 | Preset[000:058] Tuba 2 bag(s) from #165 77 | Preset[000:059] Mute Trumpet 2 bag(s) from #167 78 | Preset[000:061] Brass 2 bag(s) from #169 79 | Preset[000:062] Synth Brass 1 2 bag(s) from #171 80 | Preset[000:063] Synth Brass 2 2 bag(s) from #173 81 | Preset[000:072] Piccolo 2 bag(s) from #175 82 | Preset[000:074] Recorder 2 bag(s) from #177 83 | Preset[000:076] Bottle Chiff 2 bag(s) from #179 84 | Preset[000:077] Shakuhachi 2 bag(s) from #181 85 | Preset[000:078] Whistle 2 bag(s) from #183 86 | Preset[000:079] Ocarina 2 bag(s) from #185 87 | Preset[000:080] Square Wave 3 bag(s) from #187 88 | Preset[000:081] Saw Wave 3 bag(s) from #190 89 | Preset[000:082] Synth Calliope 2 bag(s) from #193 90 | Preset[000:083] Chiffer Lead 2 bag(s) from #195 91 | Preset[000:084] Charang 2 bag(s) from #197 92 | Preset[000:085] Solo Vox 2 bag(s) from #199 93 | Preset[000:086] 5th Saw Wave 2 bag(s) from #201 94 | Preset[000:087] Bass & Lead 2 bag(s) from #203 95 | Preset[000:088] Fantasia 5 bag(s) from #205 96 | Preset[000:089] Warm Pad 2 bag(s) from #210 97 | Preset[000:090] Poly Synth 2 bag(s) from #212 98 | Preset[000:091] Space Voice 2 bag(s) from #214 99 | Preset[000:092] Bowed Glass 3 bag(s) from #216 100 | Preset[000:093] Metal Pad 2 bag(s) from #219 101 | Preset[000:094] Halo Pad 2 bag(s) from #221 102 | Preset[000:095] Sweep Pad 2 bag(s) from #223 103 | Preset[000:096] Ice Rain 2 bag(s) from #225 104 | Preset[000:097] Soundtrack 2 bag(s) from #227 105 | Preset[000:098] Crystal 2 bag(s) from #229 106 | Preset[000:099] Atmosphere 2 bag(s) from #231 107 | Preset[000:100] Brightness 2 bag(s) from #233 108 | Preset[000:101] Goblin 2 bag(s) from #235 109 | Preset[000:102] Echo Drops 2 bag(s) from #237 110 | Preset[000:103] Star Theme 2 bag(s) from #239 111 | Preset[000:104] Sitar 2 bag(s) from #241 112 | Preset[000:105] Banjo 2 bag(s) from #243 113 | Preset[000:106] Shamisen 2 bag(s) from #245 114 | Preset[000:107] Koto 2 bag(s) from #247 115 | Preset[000:108] Kalimba 2 bag(s) from #249 116 | Preset[000:109] Bagpipe 2 bag(s) from #251 117 | Preset[000:110] Fiddle 2 bag(s) from #253 118 | Preset[000:111] Shenai 2 bag(s) from #255 119 | Preset[000:112] Tinker Bell 2 bag(s) from #257 120 | Preset[000:113] Agogo 2 bag(s) from #259 121 | Preset[000:114] Steel Drum 2 bag(s) from #261 122 | Preset[000:115] Wood Block 2 bag(s) from #263 123 | Preset[000:116] Taiko Drum 2 bag(s) from #265 124 | Preset[000:117] Melodic Tom 2 bag(s) from #267 125 | Preset[000:118] Synth Drum 2 bag(s) from #269 126 | Preset[000:119] Reverse Cymbal 2 bag(s) from #271 127 | Preset[000:120] Fret Noise 2 bag(s) from #273 128 | Preset[000:121] Breath Noise 2 bag(s) from #275 129 | Preset[000:122] Seashore 2 bag(s) from #277 130 | Preset[000:123] Bird 2 bag(s) from #279 131 | Preset[000:124] Telephone 2 bag(s) from #281 132 | Preset[000:125] Helicopter 2 bag(s) from #283 133 | Preset[000:126] Applause 2 bag(s) from #285 134 | Preset[000:127] Gun Shot 2 bag(s) from #287 135 | Preset[000:006] Coupled Harpsichord 3 bag(s) from #289 136 | ``` 137 | -------------------------------------------------------------------------------- /server/bin/Activate.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .Synopsis 3 | Activate a Python virtual environment for the current PowerShell session. 4 | 5 | .Description 6 | Pushes the python executable for a virtual environment to the front of the 7 | $Env:PATH environment variable and sets the prompt to signify that you are 8 | in a Python virtual environment. Makes use of the command line switches as 9 | well as the `pyvenv.cfg` file values present in the virtual environment. 10 | 11 | .Parameter VenvDir 12 | Path to the directory that contains the virtual environment to activate. The 13 | default value for this is the parent of the directory that the Activate.ps1 14 | script is located within. 15 | 16 | .Parameter Prompt 17 | The prompt prefix to display when this virtual environment is activated. By 18 | default, this prompt is the name of the virtual environment folder (VenvDir) 19 | surrounded by parentheses and followed by a single space (ie. '(.venv) '). 20 | 21 | .Example 22 | Activate.ps1 23 | Activates the Python virtual environment that contains the Activate.ps1 script. 24 | 25 | .Example 26 | Activate.ps1 -Verbose 27 | Activates the Python virtual environment that contains the Activate.ps1 script, 28 | and shows extra information about the activation as it executes. 29 | 30 | .Example 31 | Activate.ps1 -VenvDir C:\Users\MyUser\Common\.venv 32 | Activates the Python virtual environment located in the specified location. 33 | 34 | .Example 35 | Activate.ps1 -Prompt "MyPython" 36 | Activates the Python virtual environment that contains the Activate.ps1 script, 37 | and prefixes the current prompt with the specified string (surrounded in 38 | parentheses) while the virtual environment is active. 39 | 40 | .Notes 41 | On Windows, it may be required to enable this Activate.ps1 script by setting the 42 | execution policy for the user. You can do this by issuing the following PowerShell 43 | command: 44 | 45 | PS C:\> Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser 46 | 47 | For more information on Execution Policies: 48 | https://go.microsoft.com/fwlink/?LinkID=135170 49 | 50 | #> 51 | Param( 52 | [Parameter(Mandatory = $false)] 53 | [String] 54 | $VenvDir, 55 | [Parameter(Mandatory = $false)] 56 | [String] 57 | $Prompt 58 | ) 59 | 60 | <# Function declarations --------------------------------------------------- #> 61 | 62 | <# 63 | .Synopsis 64 | Remove all shell session elements added by the Activate script, including the 65 | addition of the virtual environment's Python executable from the beginning of 66 | the PATH variable. 67 | 68 | .Parameter NonDestructive 69 | If present, do not remove this function from the global namespace for the 70 | session. 71 | 72 | #> 73 | function global:deactivate ([switch]$NonDestructive) { 74 | # Revert to original values 75 | 76 | # The prior prompt: 77 | if (Test-Path -Path Function:_OLD_VIRTUAL_PROMPT) { 78 | Copy-Item -Path Function:_OLD_VIRTUAL_PROMPT -Destination Function:prompt 79 | Remove-Item -Path Function:_OLD_VIRTUAL_PROMPT 80 | } 81 | 82 | # The prior PYTHONHOME: 83 | if (Test-Path -Path Env:_OLD_VIRTUAL_PYTHONHOME) { 84 | Copy-Item -Path Env:_OLD_VIRTUAL_PYTHONHOME -Destination Env:PYTHONHOME 85 | Remove-Item -Path Env:_OLD_VIRTUAL_PYTHONHOME 86 | } 87 | 88 | # The prior PATH: 89 | if (Test-Path -Path Env:_OLD_VIRTUAL_PATH) { 90 | Copy-Item -Path Env:_OLD_VIRTUAL_PATH -Destination Env:PATH 91 | Remove-Item -Path Env:_OLD_VIRTUAL_PATH 92 | } 93 | 94 | # Just remove the VIRTUAL_ENV altogether: 95 | if (Test-Path -Path Env:VIRTUAL_ENV) { 96 | Remove-Item -Path env:VIRTUAL_ENV 97 | } 98 | 99 | # Just remove VIRTUAL_ENV_PROMPT altogether. 100 | if (Test-Path -Path Env:VIRTUAL_ENV_PROMPT) { 101 | Remove-Item -Path env:VIRTUAL_ENV_PROMPT 102 | } 103 | 104 | # Just remove the _PYTHON_VENV_PROMPT_PREFIX altogether: 105 | if (Get-Variable -Name "_PYTHON_VENV_PROMPT_PREFIX" -ErrorAction SilentlyContinue) { 106 | Remove-Variable -Name _PYTHON_VENV_PROMPT_PREFIX -Scope Global -Force 107 | } 108 | 109 | # Leave deactivate function in the global namespace if requested: 110 | if (-not $NonDestructive) { 111 | Remove-Item -Path function:deactivate 112 | } 113 | } 114 | 115 | <# 116 | .Description 117 | Get-PyVenvConfig parses the values from the pyvenv.cfg file located in the 118 | given folder, and returns them in a map. 119 | 120 | For each line in the pyvenv.cfg file, if that line can be parsed into exactly 121 | two strings separated by `=` (with any amount of whitespace surrounding the =) 122 | then it is considered a `key = value` line. The left hand string is the key, 123 | the right hand is the value. 124 | 125 | If the value starts with a `'` or a `"` then the first and last character is 126 | stripped from the value before being captured. 127 | 128 | .Parameter ConfigDir 129 | Path to the directory that contains the `pyvenv.cfg` file. 130 | #> 131 | function Get-PyVenvConfig( 132 | [String] 133 | $ConfigDir 134 | ) { 135 | Write-Verbose "Given ConfigDir=$ConfigDir, obtain values in pyvenv.cfg" 136 | 137 | # Ensure the file exists, and issue a warning if it doesn't (but still allow the function to continue). 138 | $pyvenvConfigPath = Join-Path -Resolve -Path $ConfigDir -ChildPath 'pyvenv.cfg' -ErrorAction Continue 139 | 140 | # An empty map will be returned if no config file is found. 141 | $pyvenvConfig = @{ } 142 | 143 | if ($pyvenvConfigPath) { 144 | 145 | Write-Verbose "File exists, parse `key = value` lines" 146 | $pyvenvConfigContent = Get-Content -Path $pyvenvConfigPath 147 | 148 | $pyvenvConfigContent | ForEach-Object { 149 | $keyval = $PSItem -split "\s*=\s*", 2 150 | if ($keyval[0] -and $keyval[1]) { 151 | $val = $keyval[1] 152 | 153 | # Remove extraneous quotations around a string value. 154 | if ("'""".Contains($val.Substring(0, 1))) { 155 | $val = $val.Substring(1, $val.Length - 2) 156 | } 157 | 158 | $pyvenvConfig[$keyval[0]] = $val 159 | Write-Verbose "Adding Key: '$($keyval[0])'='$val'" 160 | } 161 | } 162 | } 163 | return $pyvenvConfig 164 | } 165 | 166 | 167 | <# Begin Activate script --------------------------------------------------- #> 168 | 169 | # Determine the containing directory of this script 170 | $VenvExecPath = Split-Path -Parent $MyInvocation.MyCommand.Definition 171 | $VenvExecDir = Get-Item -Path $VenvExecPath 172 | 173 | Write-Verbose "Activation script is located in path: '$VenvExecPath'" 174 | Write-Verbose "VenvExecDir Fullname: '$($VenvExecDir.FullName)" 175 | Write-Verbose "VenvExecDir Name: '$($VenvExecDir.Name)" 176 | 177 | # Set values required in priority: CmdLine, ConfigFile, Default 178 | # First, get the location of the virtual environment, it might not be 179 | # VenvExecDir if specified on the command line. 180 | if ($VenvDir) { 181 | Write-Verbose "VenvDir given as parameter, using '$VenvDir' to determine values" 182 | } 183 | else { 184 | Write-Verbose "VenvDir not given as a parameter, using parent directory name as VenvDir." 185 | $VenvDir = $VenvExecDir.Parent.FullName.TrimEnd("\\/") 186 | Write-Verbose "VenvDir=$VenvDir" 187 | } 188 | 189 | # Next, read the `pyvenv.cfg` file to determine any required value such 190 | # as `prompt`. 191 | $pyvenvCfg = Get-PyVenvConfig -ConfigDir $VenvDir 192 | 193 | # Next, set the prompt from the command line, or the config file, or 194 | # just use the name of the virtual environment folder. 195 | if ($Prompt) { 196 | Write-Verbose "Prompt specified as argument, using '$Prompt'" 197 | } 198 | else { 199 | Write-Verbose "Prompt not specified as argument to script, checking pyvenv.cfg value" 200 | if ($pyvenvCfg -and $pyvenvCfg['prompt']) { 201 | Write-Verbose " Setting based on value in pyvenv.cfg='$($pyvenvCfg['prompt'])'" 202 | $Prompt = $pyvenvCfg['prompt']; 203 | } 204 | else { 205 | Write-Verbose " Setting prompt based on parent's directory's name. (Is the directory name passed to venv module when creating the virtual environment)" 206 | Write-Verbose " Got leaf-name of $VenvDir='$(Split-Path -Path $venvDir -Leaf)'" 207 | $Prompt = Split-Path -Path $venvDir -Leaf 208 | } 209 | } 210 | 211 | Write-Verbose "Prompt = '$Prompt'" 212 | Write-Verbose "VenvDir='$VenvDir'" 213 | 214 | # Deactivate any currently active virtual environment, but leave the 215 | # deactivate function in place. 216 | deactivate -nondestructive 217 | 218 | # Now set the environment variable VIRTUAL_ENV, used by many tools to determine 219 | # that there is an activated venv. 220 | $env:VIRTUAL_ENV = $VenvDir 221 | 222 | if (-not $Env:VIRTUAL_ENV_DISABLE_PROMPT) { 223 | 224 | Write-Verbose "Setting prompt to '$Prompt'" 225 | 226 | # Set the prompt to include the env name 227 | # Make sure _OLD_VIRTUAL_PROMPT is global 228 | function global:_OLD_VIRTUAL_PROMPT { "" } 229 | Copy-Item -Path function:prompt -Destination function:_OLD_VIRTUAL_PROMPT 230 | New-Variable -Name _PYTHON_VENV_PROMPT_PREFIX -Description "Python virtual environment prompt prefix" -Scope Global -Option ReadOnly -Visibility Public -Value $Prompt 231 | 232 | function global:prompt { 233 | Write-Host -NoNewline -ForegroundColor Green "($_PYTHON_VENV_PROMPT_PREFIX) " 234 | _OLD_VIRTUAL_PROMPT 235 | } 236 | $env:VIRTUAL_ENV_PROMPT = $Prompt 237 | } 238 | 239 | # Clear PYTHONHOME 240 | if (Test-Path -Path Env:PYTHONHOME) { 241 | Copy-Item -Path Env:PYTHONHOME -Destination Env:_OLD_VIRTUAL_PYTHONHOME 242 | Remove-Item -Path Env:PYTHONHOME 243 | } 244 | 245 | # Add the venv to the PATH 246 | Copy-Item -Path Env:PATH -Destination Env:_OLD_VIRTUAL_PATH 247 | $Env:PATH = "$VenvExecDir$([System.IO.Path]::PathSeparator)$Env:PATH" 248 | -------------------------------------------------------------------------------- /server/bin/accelerate: -------------------------------------------------------------------------------- 1 | #!/Users/mokeefe/dev/papermusic/server/bin/python3.12 2 | # -*- coding: utf-8 -*- 3 | import re 4 | import sys 5 | from accelerate.commands.accelerate_cli import main 6 | if __name__ == '__main__': 7 | sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0]) 8 | sys.exit(main()) 9 | -------------------------------------------------------------------------------- /server/bin/accelerate-config: -------------------------------------------------------------------------------- 1 | #!/Users/mokeefe/dev/papermusic/server/bin/python3.12 2 | # -*- coding: utf-8 -*- 3 | import re 4 | import sys 5 | from accelerate.commands.config import main 6 | if __name__ == '__main__': 7 | sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0]) 8 | sys.exit(main()) 9 | -------------------------------------------------------------------------------- /server/bin/accelerate-estimate-memory: -------------------------------------------------------------------------------- 1 | #!/Users/mokeefe/dev/papermusic/server/bin/python3.12 2 | # -*- coding: utf-8 -*- 3 | import re 4 | import sys 5 | from accelerate.commands.estimate import main 6 | if __name__ == '__main__': 7 | sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0]) 8 | sys.exit(main()) 9 | -------------------------------------------------------------------------------- /server/bin/accelerate-launch: -------------------------------------------------------------------------------- 1 | #!/Users/mokeefe/dev/papermusic/server/bin/python3.12 2 | # -*- coding: utf-8 -*- 3 | import re 4 | import sys 5 | from accelerate.commands.launch import main 6 | if __name__ == '__main__': 7 | sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0]) 8 | sys.exit(main()) 9 | -------------------------------------------------------------------------------- /server/bin/accelerate-merge-weights: -------------------------------------------------------------------------------- 1 | #!/Users/mokeefe/dev/papermusic/server/bin/python3.12 2 | # -*- coding: utf-8 -*- 3 | import re 4 | import sys 5 | from accelerate.commands.merge import main 6 | if __name__ == '__main__': 7 | sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0]) 8 | sys.exit(main()) 9 | -------------------------------------------------------------------------------- /server/bin/activate: -------------------------------------------------------------------------------- 1 | # This file must be used with "source bin/activate" *from bash* 2 | # You cannot run it directly 3 | 4 | deactivate () { 5 | # reset old environment variables 6 | if [ -n "${_OLD_VIRTUAL_PATH:-}" ] ; then 7 | PATH="${_OLD_VIRTUAL_PATH:-}" 8 | export PATH 9 | unset _OLD_VIRTUAL_PATH 10 | fi 11 | if [ -n "${_OLD_VIRTUAL_PYTHONHOME:-}" ] ; then 12 | PYTHONHOME="${_OLD_VIRTUAL_PYTHONHOME:-}" 13 | export PYTHONHOME 14 | unset _OLD_VIRTUAL_PYTHONHOME 15 | fi 16 | 17 | # Call hash to forget past commands. Without forgetting 18 | # past commands the $PATH changes we made may not be respected 19 | hash -r 2> /dev/null 20 | 21 | if [ -n "${_OLD_VIRTUAL_PS1:-}" ] ; then 22 | PS1="${_OLD_VIRTUAL_PS1:-}" 23 | export PS1 24 | unset _OLD_VIRTUAL_PS1 25 | fi 26 | 27 | unset VIRTUAL_ENV 28 | unset VIRTUAL_ENV_PROMPT 29 | if [ ! "${1:-}" = "nondestructive" ] ; then 30 | # Self destruct! 31 | unset -f deactivate 32 | fi 33 | } 34 | 35 | # unset irrelevant variables 36 | deactivate nondestructive 37 | 38 | # on Windows, a path can contain colons and backslashes and has to be converted: 39 | if [ "${OSTYPE:-}" = "cygwin" ] || [ "${OSTYPE:-}" = "msys" ] ; then 40 | # transform D:\path\to\venv to /d/path/to/venv on MSYS 41 | # and to /cygdrive/d/path/to/venv on Cygwin 42 | export VIRTUAL_ENV=$(cygpath "/Users/mokeefe/dev/papermusic/server") 43 | else 44 | # use the path as-is 45 | export VIRTUAL_ENV="/Users/mokeefe/dev/papermusic/server" 46 | fi 47 | 48 | _OLD_VIRTUAL_PATH="$PATH" 49 | PATH="$VIRTUAL_ENV/bin:$PATH" 50 | export PATH 51 | 52 | # unset PYTHONHOME if set 53 | # this will fail if PYTHONHOME is set to the empty string (which is bad anyway) 54 | # could use `if (set -u; : $PYTHONHOME) ;` in bash 55 | if [ -n "${PYTHONHOME:-}" ] ; then 56 | _OLD_VIRTUAL_PYTHONHOME="${PYTHONHOME:-}" 57 | unset PYTHONHOME 58 | fi 59 | 60 | if [ -z "${VIRTUAL_ENV_DISABLE_PROMPT:-}" ] ; then 61 | _OLD_VIRTUAL_PS1="${PS1:-}" 62 | PS1="(server) ${PS1:-}" 63 | export PS1 64 | VIRTUAL_ENV_PROMPT="(server) " 65 | export VIRTUAL_ENV_PROMPT 66 | fi 67 | 68 | # Call hash to forget past commands. Without forgetting 69 | # past commands the $PATH changes we made may not be respected 70 | hash -r 2> /dev/null 71 | -------------------------------------------------------------------------------- /server/bin/activate.csh: -------------------------------------------------------------------------------- 1 | # This file must be used with "source bin/activate.csh" *from csh*. 2 | # You cannot run it directly. 3 | 4 | # Created by Davide Di Blasi . 5 | # Ported to Python 3.3 venv by Andrew Svetlov 6 | 7 | alias deactivate 'test $?_OLD_VIRTUAL_PATH != 0 && setenv PATH "$_OLD_VIRTUAL_PATH" && unset _OLD_VIRTUAL_PATH; rehash; test $?_OLD_VIRTUAL_PROMPT != 0 && set prompt="$_OLD_VIRTUAL_PROMPT" && unset _OLD_VIRTUAL_PROMPT; unsetenv VIRTUAL_ENV; unsetenv VIRTUAL_ENV_PROMPT; test "\!:*" != "nondestructive" && unalias deactivate' 8 | 9 | # Unset irrelevant variables. 10 | deactivate nondestructive 11 | 12 | setenv VIRTUAL_ENV "/Users/mokeefe/dev/papermusic/server" 13 | 14 | set _OLD_VIRTUAL_PATH="$PATH" 15 | setenv PATH "$VIRTUAL_ENV/bin:$PATH" 16 | 17 | 18 | set _OLD_VIRTUAL_PROMPT="$prompt" 19 | 20 | if (! "$?VIRTUAL_ENV_DISABLE_PROMPT") then 21 | set prompt = "(server) $prompt" 22 | setenv VIRTUAL_ENV_PROMPT "(server) " 23 | endif 24 | 25 | alias pydoc python -m pydoc 26 | 27 | rehash 28 | -------------------------------------------------------------------------------- /server/bin/activate.fish: -------------------------------------------------------------------------------- 1 | # This file must be used with "source /bin/activate.fish" *from fish* 2 | # (https://fishshell.com/). You cannot run it directly. 3 | 4 | function deactivate -d "Exit virtual environment and return to normal shell environment" 5 | # reset old environment variables 6 | if test -n "$_OLD_VIRTUAL_PATH" 7 | set -gx PATH $_OLD_VIRTUAL_PATH 8 | set -e _OLD_VIRTUAL_PATH 9 | end 10 | if test -n "$_OLD_VIRTUAL_PYTHONHOME" 11 | set -gx PYTHONHOME $_OLD_VIRTUAL_PYTHONHOME 12 | set -e _OLD_VIRTUAL_PYTHONHOME 13 | end 14 | 15 | if test -n "$_OLD_FISH_PROMPT_OVERRIDE" 16 | set -e _OLD_FISH_PROMPT_OVERRIDE 17 | # prevents error when using nested fish instances (Issue #93858) 18 | if functions -q _old_fish_prompt 19 | functions -e fish_prompt 20 | functions -c _old_fish_prompt fish_prompt 21 | functions -e _old_fish_prompt 22 | end 23 | end 24 | 25 | set -e VIRTUAL_ENV 26 | set -e VIRTUAL_ENV_PROMPT 27 | if test "$argv[1]" != "nondestructive" 28 | # Self-destruct! 29 | functions -e deactivate 30 | end 31 | end 32 | 33 | # Unset irrelevant variables. 34 | deactivate nondestructive 35 | 36 | set -gx VIRTUAL_ENV "/Users/mokeefe/dev/papermusic/server" 37 | 38 | set -gx _OLD_VIRTUAL_PATH $PATH 39 | set -gx PATH "$VIRTUAL_ENV/bin" $PATH 40 | 41 | # Unset PYTHONHOME if set. 42 | if set -q PYTHONHOME 43 | set -gx _OLD_VIRTUAL_PYTHONHOME $PYTHONHOME 44 | set -e PYTHONHOME 45 | end 46 | 47 | if test -z "$VIRTUAL_ENV_DISABLE_PROMPT" 48 | # fish uses a function instead of an env var to generate the prompt. 49 | 50 | # Save the current fish_prompt function as the function _old_fish_prompt. 51 | functions -c fish_prompt _old_fish_prompt 52 | 53 | # With the original prompt function renamed, we can override with our own. 54 | function fish_prompt 55 | # Save the return status of the last command. 56 | set -l old_status $status 57 | 58 | # Output the venv prompt; color taken from the blue of the Python logo. 59 | printf "%s%s%s" (set_color 4B8BBE) "(server) " (set_color normal) 60 | 61 | # Restore the return status of the previous command. 62 | echo "exit $old_status" | . 63 | # Output the original/"old" prompt. 64 | _old_fish_prompt 65 | end 66 | 67 | set -gx _OLD_FISH_PROMPT_OVERRIDE "$VIRTUAL_ENV" 68 | set -gx VIRTUAL_ENV_PROMPT "(server) " 69 | end 70 | -------------------------------------------------------------------------------- /server/bin/convert-caffe2-to-onnx: -------------------------------------------------------------------------------- 1 | #!/Users/mokeefe/dev/papermusic/server/bin/python3.12 2 | # -*- coding: utf-8 -*- 3 | import re 4 | import sys 5 | from caffe2.python.onnx.bin.conversion import caffe2_to_onnx 6 | if __name__ == '__main__': 7 | sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0]) 8 | sys.exit(caffe2_to_onnx()) 9 | -------------------------------------------------------------------------------- /server/bin/convert-onnx-to-caffe2: -------------------------------------------------------------------------------- 1 | #!/Users/mokeefe/dev/papermusic/server/bin/python3.12 2 | # -*- coding: utf-8 -*- 3 | import re 4 | import sys 5 | from caffe2.python.onnx.bin.conversion import onnx_to_caffe2 6 | if __name__ == '__main__': 7 | sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0]) 8 | sys.exit(onnx_to_caffe2()) 9 | -------------------------------------------------------------------------------- /server/bin/distro: -------------------------------------------------------------------------------- 1 | #!/Users/mokeefe/dev/papermusic/server/bin/python3.12 2 | # -*- coding: utf-8 -*- 3 | import re 4 | import sys 5 | from distro.distro import main 6 | if __name__ == '__main__': 7 | sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0]) 8 | sys.exit(main()) 9 | -------------------------------------------------------------------------------- /server/bin/dotenv: -------------------------------------------------------------------------------- 1 | #!/Users/mokeefe/dev/papermusic/server/bin/python3.12 2 | # -*- coding: utf-8 -*- 3 | import re 4 | import sys 5 | from dotenv.__main__ import cli 6 | if __name__ == '__main__': 7 | sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0]) 8 | sys.exit(cli()) 9 | -------------------------------------------------------------------------------- /server/bin/email_validator: -------------------------------------------------------------------------------- 1 | #!/Users/mokeefe/dev/papermusic/server/bin/python3.12 2 | # -*- coding: utf-8 -*- 3 | import re 4 | import sys 5 | from email_validator.__main__ import main 6 | if __name__ == '__main__': 7 | sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0]) 8 | sys.exit(main()) 9 | -------------------------------------------------------------------------------- /server/bin/f2py: -------------------------------------------------------------------------------- 1 | #!/Users/mokeefe/dev/papermusic/server/bin/python3.12 2 | # -*- coding: utf-8 -*- 3 | import re 4 | import sys 5 | from numpy.f2py.f2py2e import main 6 | if __name__ == '__main__': 7 | sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0]) 8 | sys.exit(main()) 9 | -------------------------------------------------------------------------------- /server/bin/fastapi: -------------------------------------------------------------------------------- 1 | #!/Users/mokeefe/dev/papermusic/server/bin/python3.12 2 | # -*- coding: utf-8 -*- 3 | import re 4 | import sys 5 | from fastapi_cli.cli import main 6 | if __name__ == '__main__': 7 | sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0]) 8 | sys.exit(main()) 9 | -------------------------------------------------------------------------------- /server/bin/httpx: -------------------------------------------------------------------------------- 1 | #!/Users/mokeefe/dev/papermusic/server/bin/python3.12 2 | # -*- coding: utf-8 -*- 3 | import re 4 | import sys 5 | from httpx import main 6 | if __name__ == '__main__': 7 | sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0]) 8 | sys.exit(main()) 9 | -------------------------------------------------------------------------------- /server/bin/huggingface-cli: -------------------------------------------------------------------------------- 1 | #!/Users/mokeefe/dev/papermusic/server/bin/python3.12 2 | # -*- coding: utf-8 -*- 3 | import re 4 | import sys 5 | from huggingface_hub.commands.huggingface_cli import main 6 | if __name__ == '__main__': 7 | sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0]) 8 | sys.exit(main()) 9 | -------------------------------------------------------------------------------- /server/bin/isympy: -------------------------------------------------------------------------------- 1 | #!/Users/mokeefe/dev/papermusic/server/bin/python3.12 2 | # -*- coding: utf-8 -*- 3 | import re 4 | import sys 5 | from isympy import main 6 | if __name__ == '__main__': 7 | sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0]) 8 | sys.exit(main()) 9 | -------------------------------------------------------------------------------- /server/bin/jsondiff: -------------------------------------------------------------------------------- 1 | #!/Users/mokeefe/dev/papermusic/server/bin/python3.12 2 | # -*- coding: utf-8 -*- 3 | 4 | from __future__ import print_function 5 | 6 | import sys 7 | import json 8 | import jsonpatch 9 | import argparse 10 | 11 | 12 | parser = argparse.ArgumentParser(description='Diff two JSON files') 13 | parser.add_argument('FILE1', type=argparse.FileType('r')) 14 | parser.add_argument('FILE2', type=argparse.FileType('r')) 15 | parser.add_argument('--indent', type=int, default=None, 16 | help='Indent output by n spaces') 17 | parser.add_argument('-u', '--preserve-unicode', action='store_true', 18 | help='Output Unicode character as-is without using Code Point') 19 | parser.add_argument('-v', '--version', action='version', 20 | version='%(prog)s ' + jsonpatch.__version__) 21 | 22 | 23 | def main(): 24 | try: 25 | diff_files() 26 | except KeyboardInterrupt: 27 | sys.exit(1) 28 | 29 | 30 | def diff_files(): 31 | """ Diffs two JSON files and prints a patch """ 32 | args = parser.parse_args() 33 | doc1 = json.load(args.FILE1) 34 | doc2 = json.load(args.FILE2) 35 | patch = jsonpatch.make_patch(doc1, doc2) 36 | if patch.patch: 37 | print(json.dumps(patch.patch, indent=args.indent, ensure_ascii=not(args.preserve_unicode))) 38 | sys.exit(1) 39 | 40 | if __name__ == "__main__": 41 | main() 42 | -------------------------------------------------------------------------------- /server/bin/jsonpatch: -------------------------------------------------------------------------------- 1 | #!/Users/mokeefe/dev/papermusic/server/bin/python3.12 2 | # -*- coding: utf-8 -*- 3 | 4 | import sys 5 | import os.path 6 | import json 7 | import jsonpatch 8 | import tempfile 9 | import argparse 10 | 11 | 12 | parser = argparse.ArgumentParser( 13 | description='Apply a JSON patch on a JSON file') 14 | parser.add_argument('ORIGINAL', type=argparse.FileType('r'), 15 | help='Original file') 16 | parser.add_argument('PATCH', type=argparse.FileType('r'), 17 | nargs='?', default=sys.stdin, 18 | help='Patch file (read from stdin if omitted)') 19 | parser.add_argument('--indent', type=int, default=None, 20 | help='Indent output by n spaces') 21 | parser.add_argument('-b', '--backup', action='store_true', 22 | help='Back up ORIGINAL if modifying in-place') 23 | parser.add_argument('-i', '--in-place', action='store_true', 24 | help='Modify ORIGINAL in-place instead of to stdout') 25 | parser.add_argument('-v', '--version', action='version', 26 | version='%(prog)s ' + jsonpatch.__version__) 27 | parser.add_argument('-u', '--preserve-unicode', action='store_true', 28 | help='Output Unicode character as-is without using Code Point') 29 | 30 | def main(): 31 | try: 32 | patch_files() 33 | except KeyboardInterrupt: 34 | sys.exit(1) 35 | 36 | 37 | def patch_files(): 38 | """ Diffs two JSON files and prints a patch """ 39 | args = parser.parse_args() 40 | doc = json.load(args.ORIGINAL) 41 | patch = json.load(args.PATCH) 42 | result = jsonpatch.apply_patch(doc, patch) 43 | 44 | if args.in_place: 45 | dirname = os.path.abspath(os.path.dirname(args.ORIGINAL.name)) 46 | 47 | try: 48 | # Attempt to replace the file atomically. We do this by 49 | # creating a temporary file in the same directory as the 50 | # original file so we can atomically move the new file over 51 | # the original later. (This is done in the same directory 52 | # because atomic renames do not work across mount points.) 53 | 54 | fd, pathname = tempfile.mkstemp(dir=dirname) 55 | fp = os.fdopen(fd, 'w') 56 | atomic = True 57 | 58 | except OSError: 59 | # We failed to create the temporary file for an atomic 60 | # replace, so fall back to non-atomic mode by backing up 61 | # the original (if desired) and writing a new file. 62 | 63 | if args.backup: 64 | os.rename(args.ORIGINAL.name, args.ORIGINAL.name + '.orig') 65 | fp = open(args.ORIGINAL.name, 'w') 66 | atomic = False 67 | 68 | else: 69 | # Since we're not replacing the original file in-place, write 70 | # the modified JSON to stdout instead. 71 | 72 | fp = sys.stdout 73 | 74 | # By this point we have some sort of file object we can write the 75 | # modified JSON to. 76 | 77 | json.dump(result, fp, indent=args.indent, ensure_ascii=not(args.preserve_unicode)) 78 | fp.write('\n') 79 | 80 | if args.in_place: 81 | # Close the new file. If we aren't replacing atomically, this 82 | # is our last step, since everything else is already in place. 83 | 84 | fp.close() 85 | 86 | if atomic: 87 | try: 88 | # Complete the atomic replace by linking the original 89 | # to a backup (if desired), fixing up the permissions 90 | # on the temporary file, and moving it into place. 91 | 92 | if args.backup: 93 | os.link(args.ORIGINAL.name, args.ORIGINAL.name + '.orig') 94 | os.chmod(pathname, os.stat(args.ORIGINAL.name).st_mode) 95 | os.rename(pathname, args.ORIGINAL.name) 96 | 97 | except OSError: 98 | # In the event we could not actually do the atomic 99 | # replace, unlink the original to move it out of the 100 | # way and finally move the temporary file into place. 101 | 102 | os.unlink(args.ORIGINAL.name) 103 | os.rename(pathname, args.ORIGINAL.name) 104 | 105 | 106 | if __name__ == "__main__": 107 | main() 108 | -------------------------------------------------------------------------------- /server/bin/jsonpointer: -------------------------------------------------------------------------------- 1 | #!/Users/mokeefe/dev/papermusic/server/bin/python3.12 2 | # -*- coding: utf-8 -*- 3 | 4 | from __future__ import print_function 5 | 6 | import sys 7 | import os.path 8 | import json 9 | import jsonpointer 10 | import argparse 11 | 12 | 13 | parser = argparse.ArgumentParser( 14 | description='Resolve a JSON pointer on JSON files') 15 | 16 | # Accept pointer as argument or as file 17 | ptr_group = parser.add_mutually_exclusive_group(required=True) 18 | 19 | ptr_group.add_argument('-f', '--pointer-file', type=argparse.FileType('r'), 20 | nargs='?', 21 | help='File containing a JSON pointer expression') 22 | 23 | ptr_group.add_argument('POINTER', type=str, nargs='?', 24 | help='A JSON pointer expression') 25 | 26 | parser.add_argument('FILE', type=argparse.FileType('r'), nargs='+', 27 | help='Files for which the pointer should be resolved') 28 | parser.add_argument('--indent', type=int, default=None, 29 | help='Indent output by n spaces') 30 | parser.add_argument('-v', '--version', action='version', 31 | version='%(prog)s ' + jsonpointer.__version__) 32 | 33 | 34 | def main(): 35 | try: 36 | resolve_files() 37 | except KeyboardInterrupt: 38 | sys.exit(1) 39 | 40 | 41 | def parse_pointer(args): 42 | if args.POINTER: 43 | ptr = args.POINTER 44 | elif args.pointer_file: 45 | ptr = args.pointer_file.read().strip() 46 | else: 47 | parser.print_usage() 48 | sys.exit(1) 49 | 50 | return ptr 51 | 52 | 53 | def resolve_files(): 54 | """ Resolve a JSON pointer on JSON files """ 55 | args = parser.parse_args() 56 | 57 | ptr = parse_pointer(args) 58 | 59 | for f in args.FILE: 60 | doc = json.load(f) 61 | try: 62 | result = jsonpointer.resolve_pointer(doc, ptr) 63 | print(json.dumps(result, indent=args.indent)) 64 | except jsonpointer.JsonPointerException as e: 65 | print('Could not resolve pointer: %s' % str(e), file=sys.stderr) 66 | 67 | 68 | if __name__ == "__main__": 69 | main() 70 | -------------------------------------------------------------------------------- /server/bin/langchain-server: -------------------------------------------------------------------------------- 1 | #!/Users/mokeefe/dev/papermusic/server/bin/python3.12 2 | # -*- coding: utf-8 -*- 3 | import re 4 | import sys 5 | from langchain.server import main 6 | if __name__ == '__main__': 7 | sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0]) 8 | sys.exit(main()) 9 | -------------------------------------------------------------------------------- /server/bin/langsmith: -------------------------------------------------------------------------------- 1 | #!/Users/mokeefe/dev/papermusic/server/bin/python3.12 2 | # -*- coding: utf-8 -*- 3 | import re 4 | import sys 5 | from langsmith.cli.main import main 6 | if __name__ == '__main__': 7 | sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0]) 8 | sys.exit(main()) 9 | -------------------------------------------------------------------------------- /server/bin/markdown-it: -------------------------------------------------------------------------------- 1 | #!/Users/mokeefe/dev/papermusic/server/bin/python3.12 2 | # -*- coding: utf-8 -*- 3 | import re 4 | import sys 5 | from markdown_it.cli.parse import main 6 | if __name__ == '__main__': 7 | sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0]) 8 | sys.exit(main()) 9 | -------------------------------------------------------------------------------- /server/bin/normalizer: -------------------------------------------------------------------------------- 1 | #!/Users/mokeefe/dev/papermusic/server/bin/python3.12 2 | # -*- coding: utf-8 -*- 3 | import re 4 | import sys 5 | from charset_normalizer.cli import cli_detect 6 | if __name__ == '__main__': 7 | sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0]) 8 | sys.exit(cli_detect()) 9 | -------------------------------------------------------------------------------- /server/bin/openai: -------------------------------------------------------------------------------- 1 | #!/Users/mokeefe/dev/papermusic/server/bin/python3.12 2 | # -*- coding: utf-8 -*- 3 | import re 4 | import sys 5 | from openai.cli import main 6 | if __name__ == '__main__': 7 | sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0]) 8 | sys.exit(main()) 9 | -------------------------------------------------------------------------------- /server/bin/pip: -------------------------------------------------------------------------------- 1 | #!/Users/mokeefe/dev/papermusic/server/bin/python3.12 2 | # -*- coding: utf-8 -*- 3 | import re 4 | import sys 5 | from pip._internal.cli.main import main 6 | if __name__ == '__main__': 7 | sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0]) 8 | sys.exit(main()) 9 | -------------------------------------------------------------------------------- /server/bin/pip3: -------------------------------------------------------------------------------- 1 | #!/Users/mokeefe/dev/papermusic/server/bin/python3.12 2 | # -*- coding: utf-8 -*- 3 | import re 4 | import sys 5 | from pip._internal.cli.main import main 6 | if __name__ == '__main__': 7 | sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0]) 8 | sys.exit(main()) 9 | -------------------------------------------------------------------------------- /server/bin/pip3.12: -------------------------------------------------------------------------------- 1 | #!/Users/mokeefe/dev/papermusic/server/bin/python3.12 2 | # -*- coding: utf-8 -*- 3 | import re 4 | import sys 5 | from pip._internal.cli.main import main 6 | if __name__ == '__main__': 7 | sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0]) 8 | sys.exit(main()) 9 | -------------------------------------------------------------------------------- /server/bin/pygmentize: -------------------------------------------------------------------------------- 1 | #!/Users/mokeefe/dev/papermusic/server/bin/python3.12 2 | # -*- coding: utf-8 -*- 3 | import re 4 | import sys 5 | from pygments.cmdline import main 6 | if __name__ == '__main__': 7 | sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0]) 8 | sys.exit(main()) 9 | -------------------------------------------------------------------------------- /server/bin/python: -------------------------------------------------------------------------------- 1 | python3.12 -------------------------------------------------------------------------------- /server/bin/python3: -------------------------------------------------------------------------------- 1 | python3.12 -------------------------------------------------------------------------------- /server/bin/python3.12: -------------------------------------------------------------------------------- 1 | /opt/homebrew/Cellar/python@3.12/3.12.3/Frameworks/Python.framework/Versions/3.12/bin/python3.12 -------------------------------------------------------------------------------- /server/bin/torchrun: -------------------------------------------------------------------------------- 1 | #!/Users/mokeefe/dev/papermusic/server/bin/python3.12 2 | # -*- coding: utf-8 -*- 3 | import re 4 | import sys 5 | from torch.distributed.run import main 6 | if __name__ == '__main__': 7 | sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0]) 8 | sys.exit(main()) 9 | -------------------------------------------------------------------------------- /server/bin/tqdm: -------------------------------------------------------------------------------- 1 | #!/Users/mokeefe/dev/papermusic/server/bin/python3.12 2 | # -*- coding: utf-8 -*- 3 | import re 4 | import sys 5 | from tqdm.cli import main 6 | if __name__ == '__main__': 7 | sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0]) 8 | sys.exit(main()) 9 | -------------------------------------------------------------------------------- /server/bin/transformers-cli: -------------------------------------------------------------------------------- 1 | #!/Users/mokeefe/dev/papermusic/server/bin/python3.12 2 | # -*- coding: utf-8 -*- 3 | import re 4 | import sys 5 | from transformers.commands.transformers_cli import main 6 | if __name__ == '__main__': 7 | sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0]) 8 | sys.exit(main()) 9 | -------------------------------------------------------------------------------- /server/bin/typer: -------------------------------------------------------------------------------- 1 | #!/Users/mokeefe/dev/papermusic/server/bin/python3.12 2 | # -*- coding: utf-8 -*- 3 | import re 4 | import sys 5 | from typer.cli import main 6 | if __name__ == '__main__': 7 | sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0]) 8 | sys.exit(main()) 9 | -------------------------------------------------------------------------------- /server/bin/uvicorn: -------------------------------------------------------------------------------- 1 | #!/Users/mokeefe/dev/papermusic/server/bin/python3.12 2 | # -*- coding: utf-8 -*- 3 | import re 4 | import sys 5 | from uvicorn.main import main 6 | if __name__ == '__main__': 7 | sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0]) 8 | sys.exit(main()) 9 | -------------------------------------------------------------------------------- /server/bin/watchfiles: -------------------------------------------------------------------------------- 1 | #!/Users/mokeefe/dev/papermusic/server/bin/python3.12 2 | # -*- coding: utf-8 -*- 3 | import re 4 | import sys 5 | from watchfiles.cli import cli 6 | if __name__ == '__main__': 7 | sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0]) 8 | sys.exit(cli()) 9 | -------------------------------------------------------------------------------- /server/framecapture/README.md: -------------------------------------------------------------------------------- 1 | this is where the captured frames are stored -------------------------------------------------------------------------------- /server/handlestream.py: -------------------------------------------------------------------------------- 1 | from PIL import Image 2 | import asyncio 3 | import cv2 4 | import numpy as np 5 | import socket 6 | import struct 7 | 8 | 9 | # prepare to receive mac webcam stream 10 | host = "0.0.0.0" 11 | port = 5000 12 | max_length = 10000 13 | 14 | 15 | async def listen(): 16 | print("enter Listen") 17 | sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 18 | sock.bind((host, port)) 19 | sock.listen(1) 20 | 21 | print("🤔 Listening for stream {}:{}...".format(host, port)) 22 | 23 | conn, addr = sock.accept() 24 | print("✅ Connection from: ", addr) 25 | 26 | j = 0 27 | while True: 28 | try: 29 | # receive size of the frame 30 | buffer_size = conn.recv(4) 31 | buffer_size = struct.unpack("!I", buffer_size)[0] 32 | 33 | # receive the frame 34 | buffer = b"" 35 | while len(buffer) < buffer_size: 36 | packet = conn.recv(buffer_size - len(buffer)) 37 | if not packet: 38 | break 39 | buffer += packet 40 | 41 | frame = np.frombuffer(buffer, dtype=np.uint8) 42 | frame = cv2.imdecode(frame, cv2.IMREAD_COLOR) 43 | frame = cv2.flip(frame, 1) 44 | 45 | if frame is not None and type(frame) == np.ndarray: 46 | if cv2.waitKey(1) == 27: 47 | break 48 | # if j is a multiple of 2, save frame 49 | if j % 2 == 0: 50 | cv2.imwrite(f"framecapture/frame_{j}.jpg", frame) 51 | print("📸 Saved frame: framecapture/frame_{}.jpg".format(j)) 52 | j += 1 53 | 54 | except Exception as e: 55 | continue 56 | 57 | 58 | if __name__ == "__main__": 59 | asyncio.run(listen()) 60 | -------------------------------------------------------------------------------- /server/pyvenv.cfg: -------------------------------------------------------------------------------- 1 | home = /opt/homebrew/Cellar/python@3.12/3.12.3/Frameworks/Python.framework/Versions/3.12/bin 2 | include-system-site-packages = false 3 | version = 3.12.3 4 | executable = /opt/homebrew/Cellar/python@3.12/3.12.3/Frameworks/Python.framework/Versions/3.12/bin/python3.12 5 | command = /Users/mokeefe/dev/papermusic/src/bin/python3 -m venv /Users/mokeefe/dev/papermusic/server 6 | -------------------------------------------------------------------------------- /server/requirements.txt: -------------------------------------------------------------------------------- 1 | accelerate 2 | bitsandbytes 3 | fastapi 4 | glob2 5 | imutils 6 | numpy 7 | opencv-python 8 | pillow 9 | pydantic 10 | requests 11 | swarms 12 | termcolor 13 | torch 14 | transformers -------------------------------------------------------------------------------- /server/server.py: -------------------------------------------------------------------------------- 1 | from fastapi import FastAPI 2 | from PIL import Image 3 | from pydantic import BaseModel 4 | from swarms import BaseMultiModalModel 5 | from transformers import BitsAndBytesConfig 6 | from transformers import PaliGemmaForConditionalGeneration, AutoProcessor 7 | import numpy as np 8 | import os 9 | import glob 10 | import sys 11 | import time 12 | import torch 13 | 14 | 15 | app = FastAPI() 16 | 17 | # verify CUDA (Nvidia GPU) is available 18 | if not torch.cuda.is_available(): 19 | print("🚫 No CUDA device available.") 20 | sys.exit() 21 | else: 22 | print("✅ NVIDIA CUDA device available. Loading model...") 23 | 24 | 25 | # load paligemma - quantized for performance optimization 26 | hf_token = os.getenv("HUGGINGFACE_USER_ACCESS_TOKEN") 27 | model_id = "google/paligemma-3b-mix-224" 28 | bnb_config = BitsAndBytesConfig( 29 | load_in_4bit=True, # 4 bit precision 30 | bnb_4bit_quant_type="nf4", 31 | bnb_4bit_compute_dtype=torch.bfloat16, # computation datatype 32 | ) 33 | model = PaliGemmaForConditionalGeneration.from_pretrained( 34 | model_id, 35 | quantization_config=bnb_config, 36 | device_map={"": 0}, 37 | token=hf_token, 38 | ) 39 | processor = AutoProcessor.from_pretrained(model_id, token=hf_token) 40 | print("✅ PaliGemma model loaded.") 41 | # -------------- SERVER FUNCTIONS --------------------------- 42 | 43 | 44 | @app.get("/") 45 | def index(): 46 | return {"response": "this is the papermusic note-player server"} 47 | 48 | 49 | @app.get("/health") 50 | def health(): 51 | return {"status": "ok"} 52 | 53 | 54 | # returns cur instrument name 55 | @app.get("/instrument") 56 | def instrument(): 57 | # get the img_path of the OLDEST frame file in framecapture/ 58 | # (this is the first frame of the stream) 59 | img_path = "framecapture/" + sorted(os.listdir("framecapture"))[0] 60 | 61 | instrument = inference_paligemma( 62 | "Identify the musical instrument using 1-2 words", img_path 63 | ) 64 | 65 | # remove all whitespace and punctuation 66 | instrument = instrument.strip().replace(" ", "").replace(",", "").replace(".", "") 67 | print("🎹 Instrument is: {}".format(instrument)) 68 | return {"instrument": instrument} 69 | 70 | 71 | # returns cur note name 72 | @app.get("/note") 73 | def note(): 74 | # get the most recently-streamed frame 75 | list_of_files = glob.glob("framecapture/*") 76 | img_path = max(list_of_files, key=os.path.getctime) 77 | 78 | print("\n PaliGemma reading frame: " + img_path) 79 | start_time = time.time() 80 | n = inference_paligemma( 81 | "Identify the musical note INSIDE the green rectangle, for example: C, D, E, F, G, A, or B. Return ONLY the name of the note.", 82 | img_path, 83 | ) 84 | end_time = time.time() 85 | elapsed_time = end_time - start_time 86 | print("Local inference in: {:.2f} seconds".format(elapsed_time)) 87 | 88 | # remove all whitespace and punctuation 89 | n = n.strip().replace(" ", "").replace(",", "").replace(".", "") 90 | # convert to all caps 91 | n = n.upper() 92 | print("🎵 Identified: {}".format(n)) 93 | return {"note": n} 94 | 95 | 96 | # ------------- PALIGEMMA HELPER FUNCTION --------------------------- 97 | 98 | 99 | # source: 100 | # https://medium.com/@kyeg/get-started-with-paligemma-locally-on-cloud-the-all-new-multi-modal-model-from-google-f88a97b9ead6 101 | def inference_paligemma(prompt, img_path): 102 | raw_image = Image.open(img_path) 103 | inputs = processor(prompt, raw_image, return_tensors="pt") 104 | output = model.generate(**inputs, max_new_tokens=50) 105 | return processor.decode(output[0], skip_special_tokens=True)[len(prompt) :] 106 | -------------------------------------------------------------------------------- /server/share/man/man1/isympy.1: -------------------------------------------------------------------------------- 1 | '\" -*- coding: us-ascii -*- 2 | .if \n(.g .ds T< \\FC 3 | .if \n(.g .ds T> \\F[\n[.fam]] 4 | .de URL 5 | \\$2 \(la\\$1\(ra\\$3 6 | .. 7 | .if \n(.g .mso www.tmac 8 | .TH isympy 1 2007-10-8 "" "" 9 | .SH NAME 10 | isympy \- interactive shell for SymPy 11 | .SH SYNOPSIS 12 | 'nh 13 | .fi 14 | .ad l 15 | \fBisympy\fR \kx 16 | .if (\nx>(\n(.l/2)) .nr x (\n(.l/5) 17 | 'in \n(.iu+\nxu 18 | [\fB-c\fR | \fB--console\fR] [\fB-p\fR ENCODING | \fB--pretty\fR ENCODING] [\fB-t\fR TYPE | \fB--types\fR TYPE] [\fB-o\fR ORDER | \fB--order\fR ORDER] [\fB-q\fR | \fB--quiet\fR] [\fB-d\fR | \fB--doctest\fR] [\fB-C\fR | \fB--no-cache\fR] [\fB-a\fR | \fB--auto\fR] [\fB-D\fR | \fB--debug\fR] [ 19 | -- | PYTHONOPTIONS] 20 | 'in \n(.iu-\nxu 21 | .ad b 22 | 'hy 23 | 'nh 24 | .fi 25 | .ad l 26 | \fBisympy\fR \kx 27 | .if (\nx>(\n(.l/2)) .nr x (\n(.l/5) 28 | 'in \n(.iu+\nxu 29 | [ 30 | {\fB-h\fR | \fB--help\fR} 31 | | 32 | {\fB-v\fR | \fB--version\fR} 33 | ] 34 | 'in \n(.iu-\nxu 35 | .ad b 36 | 'hy 37 | .SH DESCRIPTION 38 | isympy is a Python shell for SymPy. It is just a normal python shell 39 | (ipython shell if you have the ipython package installed) that executes 40 | the following commands so that you don't have to: 41 | .PP 42 | .nf 43 | \*(T< 44 | >>> from __future__ import division 45 | >>> from sympy import * 46 | >>> x, y, z = symbols("x,y,z") 47 | >>> k, m, n = symbols("k,m,n", integer=True) 48 | \*(T> 49 | .fi 50 | .PP 51 | So starting isympy is equivalent to starting python (or ipython) and 52 | executing the above commands by hand. It is intended for easy and quick 53 | experimentation with SymPy. For more complicated programs, it is recommended 54 | to write a script and import things explicitly (using the "from sympy 55 | import sin, log, Symbol, ..." idiom). 56 | .SH OPTIONS 57 | .TP 58 | \*(T<\fB\-c \fR\*(T>\fISHELL\fR, \*(T<\fB\-\-console=\fR\*(T>\fISHELL\fR 59 | Use the specified shell (python or ipython) as 60 | console backend instead of the default one (ipython 61 | if present or python otherwise). 62 | 63 | Example: isympy -c python 64 | 65 | \fISHELL\fR could be either 66 | \&'ipython' or 'python' 67 | .TP 68 | \*(T<\fB\-p \fR\*(T>\fIENCODING\fR, \*(T<\fB\-\-pretty=\fR\*(T>\fIENCODING\fR 69 | Setup pretty printing in SymPy. By default, the most pretty, unicode 70 | printing is enabled (if the terminal supports it). You can use less 71 | pretty ASCII printing instead or no pretty printing at all. 72 | 73 | Example: isympy -p no 74 | 75 | \fIENCODING\fR must be one of 'unicode', 76 | \&'ascii' or 'no'. 77 | .TP 78 | \*(T<\fB\-t \fR\*(T>\fITYPE\fR, \*(T<\fB\-\-types=\fR\*(T>\fITYPE\fR 79 | Setup the ground types for the polys. By default, gmpy ground types 80 | are used if gmpy2 or gmpy is installed, otherwise it falls back to python 81 | ground types, which are a little bit slower. You can manually 82 | choose python ground types even if gmpy is installed (e.g., for testing purposes). 83 | 84 | Note that sympy ground types are not supported, and should be used 85 | only for experimental purposes. 86 | 87 | Note that the gmpy1 ground type is primarily intended for testing; it the 88 | use of gmpy even if gmpy2 is available. 89 | 90 | This is the same as setting the environment variable 91 | SYMPY_GROUND_TYPES to the given ground type (e.g., 92 | SYMPY_GROUND_TYPES='gmpy') 93 | 94 | The ground types can be determined interactively from the variable 95 | sympy.polys.domains.GROUND_TYPES inside the isympy shell itself. 96 | 97 | Example: isympy -t python 98 | 99 | \fITYPE\fR must be one of 'gmpy', 100 | \&'gmpy1' or 'python'. 101 | .TP 102 | \*(T<\fB\-o \fR\*(T>\fIORDER\fR, \*(T<\fB\-\-order=\fR\*(T>\fIORDER\fR 103 | Setup the ordering of terms for printing. The default is lex, which 104 | orders terms lexicographically (e.g., x**2 + x + 1). You can choose 105 | other orderings, such as rev-lex, which will use reverse 106 | lexicographic ordering (e.g., 1 + x + x**2). 107 | 108 | Note that for very large expressions, ORDER='none' may speed up 109 | printing considerably, with the tradeoff that the order of the terms 110 | in the printed expression will have no canonical order 111 | 112 | Example: isympy -o rev-lax 113 | 114 | \fIORDER\fR must be one of 'lex', 'rev-lex', 'grlex', 115 | \&'rev-grlex', 'grevlex', 'rev-grevlex', 'old', or 'none'. 116 | .TP 117 | \*(T<\fB\-q\fR\*(T>, \*(T<\fB\-\-quiet\fR\*(T> 118 | Print only Python's and SymPy's versions to stdout at startup, and nothing else. 119 | .TP 120 | \*(T<\fB\-d\fR\*(T>, \*(T<\fB\-\-doctest\fR\*(T> 121 | Use the same format that should be used for doctests. This is 122 | equivalent to '\fIisympy -c python -p no\fR'. 123 | .TP 124 | \*(T<\fB\-C\fR\*(T>, \*(T<\fB\-\-no\-cache\fR\*(T> 125 | Disable the caching mechanism. Disabling the cache may slow certain 126 | operations down considerably. This is useful for testing the cache, 127 | or for benchmarking, as the cache can result in deceptive benchmark timings. 128 | 129 | This is the same as setting the environment variable SYMPY_USE_CACHE 130 | to 'no'. 131 | .TP 132 | \*(T<\fB\-a\fR\*(T>, \*(T<\fB\-\-auto\fR\*(T> 133 | Automatically create missing symbols. Normally, typing a name of a 134 | Symbol that has not been instantiated first would raise NameError, 135 | but with this option enabled, any undefined name will be 136 | automatically created as a Symbol. This only works in IPython 0.11. 137 | 138 | Note that this is intended only for interactive, calculator style 139 | usage. In a script that uses SymPy, Symbols should be instantiated 140 | at the top, so that it's clear what they are. 141 | 142 | This will not override any names that are already defined, which 143 | includes the single character letters represented by the mnemonic 144 | QCOSINE (see the "Gotchas and Pitfalls" document in the 145 | documentation). You can delete existing names by executing "del 146 | name" in the shell itself. You can see if a name is defined by typing 147 | "'name' in globals()". 148 | 149 | The Symbols that are created using this have default assumptions. 150 | If you want to place assumptions on symbols, you should create them 151 | using symbols() or var(). 152 | 153 | Finally, this only works in the top level namespace. So, for 154 | example, if you define a function in isympy with an undefined 155 | Symbol, it will not work. 156 | .TP 157 | \*(T<\fB\-D\fR\*(T>, \*(T<\fB\-\-debug\fR\*(T> 158 | Enable debugging output. This is the same as setting the 159 | environment variable SYMPY_DEBUG to 'True'. The debug status is set 160 | in the variable SYMPY_DEBUG within isympy. 161 | .TP 162 | -- \fIPYTHONOPTIONS\fR 163 | These options will be passed on to \fIipython (1)\fR shell. 164 | Only supported when ipython is being used (standard python shell not supported). 165 | 166 | Two dashes (--) are required to separate \fIPYTHONOPTIONS\fR 167 | from the other isympy options. 168 | 169 | For example, to run iSymPy without startup banner and colors: 170 | 171 | isympy -q -c ipython -- --colors=NoColor 172 | .TP 173 | \*(T<\fB\-h\fR\*(T>, \*(T<\fB\-\-help\fR\*(T> 174 | Print help output and exit. 175 | .TP 176 | \*(T<\fB\-v\fR\*(T>, \*(T<\fB\-\-version\fR\*(T> 177 | Print isympy version information and exit. 178 | .SH FILES 179 | .TP 180 | \*(T<\fI${HOME}/.sympy\-history\fR\*(T> 181 | Saves the history of commands when using the python 182 | shell as backend. 183 | .SH BUGS 184 | The upstreams BTS can be found at \(lahttps://github.com/sympy/sympy/issues\(ra 185 | Please report all bugs that you find in there, this will help improve 186 | the overall quality of SymPy. 187 | .SH "SEE ALSO" 188 | \fBipython\fR(1), \fBpython\fR(1) 189 | --------------------------------------------------------------------------------