├── .gitignore ├── CITATION.cff ├── LICENSE ├── README.md ├── custom_dx7.lib ├── download_patches.py ├── dx7_render.py ├── parse_dx7.py └── requirements.txt /.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 | 162 | DX7_AllTheWeb 163 | output_dx7 164 | dx7_patches.csv -------------------------------------------------------------------------------- /CITATION.cff: -------------------------------------------------------------------------------- 1 | cff-version: 1.2.0 2 | message: "If you use this software, please cite it as below." 3 | authors: 4 | - family-names: "Braun" 5 | given-names: "David" 6 | orcid: "https://orcid.org/0000-0001-8866-0756" 7 | title: "DX7-JAX" 8 | version: 0.0.1 9 | date-released: 2023-11-25 10 | url: "https://github.com/DBraun/DX7-JAX" -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # DX7-JAX 2 | 3 | This is a work-in-progress of using [JAX](https://jax.readthedocs.io/en/latest/) to batch-render [Yamaha DX7](https://en.wikipedia.org/wiki/Yamaha_DX7) presets. We also provide a script to parse `.syx` files and aggregate them into a single CSV. 4 | 5 | The [Faust](https://faust.grame.fr/) Libraries have an [implementation](https://faustlibraries.grame.fr/libs/dx7/#dxdx7_ui) of the DX7, but it lacks several features. We have improved it in several ways such as adding an LFO, **but our implementation (`custom_dx7.lib`) is imperfect, so please use this project with caution.** Pull requests are welcome. 6 | 7 | DX7-JAX uses [DawDreamer](https://github.com/DBraun/DawDreamer/) to convert the Faust code to JAX, which can then be executed on either the CPU or GPU. We hope this project can be a useful starter for research involving Faust and JAX, not necessarily involving the DX7. DawDreamer has other JAX [examples](https://github.com/DBraun/DawDreamer/blob/main/examples/Faust_to_JAX/Faust_to_JAX.ipynb), which we encourage you to check out. 8 | 9 | ## Download patches 10 | 11 | We mirror the `DX7_AllTheWeb.zip` (2023-08-08) from (saving them some bandwidth). Use this script to download it to the right location. 12 | 13 | ```bash 14 | python download_patches.py 15 | ``` 16 | 17 | ## Turn patches into a CSV 18 | 19 | This will parse a limited amount of presets. 20 | 21 | ```bash 22 | python parse_dx7.py --directory dx7_patches/DX7_AllTheWeb/Atari 23 | ``` 24 | 25 | This will parse all presets. You probably shouldn't do this because the later rendering output will be enormous. 26 | 27 | ```bash 28 | python parse_dx7.py 29 | ``` 30 | 31 | If you run it on all of `DX7_AllTheWeb`, then 388,650 presets will be de-duplicated into 44,884. 32 | 33 | ## Render an audio dataset 34 | 35 | Render the audio with default args (`python dx7_render.py --help` for help) 36 | 37 | ```bash 38 | python dx7_render.py 39 | ``` 40 | 41 | ## Use our DX7 in the Faust IDE. 42 | 43 | Go to the [Faust IDE](https://faustide.grame.fr) and paste the content of `custom_dx7.lib` into the text editor. Then at the bottom, paste 44 | 45 | `process = dx7_algorithm(1) <: _, _;` 46 | 47 | This selects the *1st* of the 32 DX7 algorithms. Enable "Poly Voices" on the left hand side. Four is a good number. Then press the play button towards the top of the screen and play around with your keyboard as the controller. 48 | 49 | ## Citation 50 | 51 | ``` 52 | @software{Braun_DX7-JAX_2023, 53 | author = {Braun, David}, 54 | month = nov, 55 | title = {{DX7-JAX}}, 56 | url = {https://github.com/DBraun/DX7-JAX}, 57 | version = {0.0.1}, 58 | year = {2023} 59 | } 60 | ``` 61 | -------------------------------------------------------------------------------- /custom_dx7.lib: -------------------------------------------------------------------------------- 1 | //#################################### dx7.lib ######################################### 2 | // Yamaha DX7 emulation library. Its official prefix is `dx`. 3 | // 4 | // #### References 5 | // * 6 | //######################################################################################## 7 | // Yamaha DX7 emulation library. The various functions available in this library 8 | // are used by the libraries generated from `.syx` DX7 preset files. This 9 | // toolkit was greatly inspired by the CSOUND DX7 emulation package: 10 | // . 11 | // 12 | // This library and its related tools are under development. Use it at your 13 | // own risk! 14 | //############################################################################## 15 | 16 | /************************************************************************ 17 | ************************************************************************ 18 | FAUST library file, GRAME section 19 | 20 | Except where noted otherwise, Copyright (C) 2003-2017 by GRAME, 21 | Centre National de Creation Musicale. 22 | ---------------------------------------------------------------------- 23 | GRAME LICENSE 24 | 25 | This program is free software; you can redistribute it and/or modify 26 | it under the terms of the GNU Lesser General Public License as 27 | published by the Free Software Foundation; either version 2.1 of the 28 | License, or (at your option) any later version. 29 | 30 | This program is distributed in the hope that it will be useful, 31 | but WITHOUT ANY WARRANTY; without even the implied warranty of 32 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 33 | GNU Lesser General Public License for more details. 34 | 35 | You should have received a copy of the GNU Lesser General Public 36 | License along with the GNU C Library; if not, write to the Free 37 | Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 38 | 02111-1307 USA. 39 | 40 | EXCEPTION TO THE LGPL LICENSE : As a special exception, you may create a 41 | larger FAUST program which directly or indirectly imports this library 42 | file and still distribute the compiled code generated by the FAUST 43 | compiler, or a modified version of this compiled code, under your own 44 | copyright and license. This EXCEPTION TO THE LGPL LICENSE explicitly 45 | grants you the right to freely choose the license for the resulting 46 | compiled code. In particular the resulting compiled code has no obligation 47 | to be LGPL or GPL. For example you are free to choose a commercial or 48 | closed source license or any other license if you decide so. 49 | ************************************************************************ 50 | ************************************************************************/ 51 | 52 | /* 53 | TODO: 54 | * Fix any "todo:" in this file 55 | * Fix or better justify hard-coded values related to feedback. 56 | */ 57 | 58 | ba = library("basics.lib"); 59 | en = library("envelopes.lib"); 60 | ma = library("maths.lib"); 61 | os = library("oscillators.lib"); 62 | no = library("noises.lib"); 63 | it = library("interpolators.lib"); 64 | 65 | declare version "2.0.0"; 66 | 67 | //----------------------`(dx.)dx7_ampf`-------------------------- 68 | // DX7 amplitude conversion function. 3 versions of this function 69 | // are available: 70 | // 71 | // * `dx7_amp_bpf`: BPF version (same as in the CSOUND toolkit) 72 | // * `dx7_amp_func`: estimated mathematical equivalent of `dx7_amp_bpf` 73 | // * `dx7_ampf`: default (sugar for `dx7_amp_func`) 74 | // 75 | // #### Usage: 76 | // 77 | // ``` 78 | // dx7AmpPreset : dx7_ampf_bpf : _ 79 | // ``` 80 | // 81 | // Where: 82 | // 83 | // * `dx7AmpPreset`: DX7 amplitude value (0-99) 84 | //---------------------------------------------------------- 85 | // CSOUND function implemented as a BPF 86 | // Corresponds to F2 in the CSOUND implementation. 87 | dx7_amp_bpf = ba.bpf.start(0,0) : seq(i,14,ba.bpf.point(xPoints(i)+1,yPoints(i))) : ba.bpf.end(127,1) 88 | with { 89 | xPoints(n) = ba.take(n+1,(9,19,29,39,49,59,64,69,74,79,84,89,94,98)); 90 | yPoints(n) = ba.take(n+1,(0.000227445,0.000985595,0.002350265,0.005989386,0.014253222,0.033813495,0.052312358,0.080970432,0.124260804,0.190447309,0.295223654,0.457088704,0.70227445,1)); 91 | }; 92 | dx7_amp_func = min(99, max(0, _))/99 : pow(_,8); 93 | dx7_ampf = dx7_amp_func; 94 | 95 | //----------------------`(dx.)dx7_egraterisef`-------------------------- 96 | // DX7 envelope generator rise conversion function. 3 versions of this function 97 | // are available: 98 | // 99 | // * `dx7_egraterise_bpf`: BPF version (same as in the CSOUND toolkit) 100 | // * `dx7_egraterise_func`: estimated mathematical equivalent of `dx7_egraterise_bpf` 101 | // * `dx7_egraterisef`: default (sugar for `dx7_egraterise_func`) 102 | // 103 | // #### Usage: 104 | // 105 | // ``` 106 | // dx7envelopeRise : dx7_egraterisef : _ 107 | // ``` 108 | // 109 | // Where: 110 | // 111 | // * `dx7envelopeRise`: DX7 envelope rise value (0-99) 112 | //---------------------------------------------------------- 113 | // CSOUND function implemented as a BPF 114 | // Corresponds to F4 in the CSOUND implementation. 115 | dx7_egraterise_bpf = ba.bpf.start(0,38) : seq(i,24,ba.bpf.point(xPoints(i)+1,yPoints(i))) : ba.bpf.end(127,0.003) 116 | with { 117 | xPoints(n) = ba.take(n+1,(4,9,14,19,24,29,34,42,45,48,51,54,60,66,68,71,74,77, 118 | 80,83,86,89,92,95)); 119 | yPoints(n) = ba.take(n+1,(22.8,12,7.5,4.8,2.7,1.8,1.3,.737,.615, 120 | .505,.409,.321,.080,.055,.032,.024,.018,.014,.011,.008,.008, 121 | .007,.005,.003)); 122 | }; 123 | // Function estimated from the CSOUND function (default) 124 | dx7_egraterise_func = 38*pow((127-_)/127,12) : max(0.003); 125 | dx7_egraterisef = dx7_egraterise_func; 126 | 127 | //----------------------`(dx.)dx7_egraterisepercf`-------------------------- 128 | // DX7 envelope generator percussive rise conversion function. 3 versions of 129 | // this function are available: 130 | // 131 | // * `dx7_egrateriseperc_bpf`: BPF version (same as in the CSOUND toolkit) 132 | // * `dx7_egrateriseperc_func`: estimated mathematical equivalent of `dx7_egrateriseperc_bpf` 133 | // * `dx7_egraterisepercf`: default (sugar for `dx7_egrateriseperc_func`) 134 | // 135 | // #### Usage: 136 | // 137 | // ``` 138 | // dx7envelopePercRise : dx7_egraterisepercf : _ 139 | // ``` 140 | // 141 | // Where: 142 | // 143 | // * `dx7envelopePercRise`: DX7 envelope percussive rise value (0-99) 144 | //---------------------------------------------------------- 145 | // CSOUND function implemented as a BPF 146 | // Corresponds to F5 in the CSOUND implementation. 147 | dx7_egrateriseperc_bpf = ba.bpf.start(0,0.00001) : seq(i,10,ba.bpf.point(xPoints(i)+1,yPoints(i))) : ba.bpf.end(127,1) 148 | with { 149 | xPoints(n) = ba.take(n+1,(30,34,39,49,59,69,79,89,94,98)); 150 | yPoints(n) = ba.take(n+1,(0.00001,0.02,0.06,0.14,0.24,0.35,0.5,0.7,0.86,1)); 151 | }; 152 | // Function estimated from the CSOUND function (default) 153 | dx7_egrateriseperc_func = >=(30)*min(_-30,68)/68 : pow(_,1.8); 154 | dx7_egraterisepercf = dx7_egrateriseperc_func; 155 | 156 | //----------------------`(dx.)dx7_egratedecayf`-------------------------- 157 | // DX7 envelope generator decay conversion function. 3 versions of 158 | // this function are available: 159 | // 160 | // * `dx7_egratedecay_bpf`: BPF version (same as in the CSOUND toolkit) 161 | // * `dx7_egratedecay_func`: estimated mathematical equivalent of `dx7_egratedecay_bpf` 162 | // * `dx7_egratedecayf`: default (sugar for `dx7_egratedecay_func`) 163 | // 164 | // #### Usage: 165 | // 166 | // ``` 167 | // dx7envelopeDecay : dx7_egratedecayf : _ 168 | // ``` 169 | // 170 | // Where: 171 | // 172 | // * `dx7envelopeDecay`: DX7 envelope decay value (0-99) 173 | //---------------------------------------------------------- 174 | // CSOUND function implemented as a BPF 175 | // Corresponds to F6 in the CSOUND implementation. 176 | dx7_egratedecay_bpf = ba.bpf.start(0,318) : seq(i,23,ba.bpf.point(xPoints(i)+1,yPoints(i))) : ba.bpf.end(127,.008) 177 | with { 178 | xPoints(n) = ba.take(n+1,(3,7,12,17,22,27,32,40,43,49,52,55,58,63,66,69,72,75, 179 | 78,81,84,87,90)); 180 | yPoints(n) = ba.take(n+1,(181,115,63,39.7,20,11.2,7,5.66,3.98,1.99, 181 | 1.34,.99,.71,.41,.15,.081,.068,.047,.037,.025,.02,.013,.008)); 182 | }; 183 | // Function estimated from the CSOUND function (default) 184 | dx7_egratedecay_func = 318*pow((127-_)/127,12.6) : max(0.008); 185 | dx7_egratedecayf = dx7_egratedecay_func; 186 | 187 | //----------------------`(dx.)dx7_egratedecaypercf`-------------------------- 188 | // DX7 envelope generator percussive decay conversion function. 3 versions of 189 | // this function are available: 190 | // 191 | // * `dx7_egratedecayperc_bpf`: BPF version (same as in the CSOUND toolkit) 192 | // * `dx7_egratedecayperc_func`: estimated mathematical equivalent of `dx7_egratedecayperc_bpf` 193 | // * `dx7_egratedecaypercf`: default (sugar for `dx7_egratedecayperc_func`) 194 | // 195 | // #### Usage: 196 | // 197 | // ``` 198 | // dx7envelopePercDecay : dx7_egratedecaypercf : _ 199 | // ``` 200 | // 201 | // Where: 202 | // 203 | // * `dx7envelopePercDecay`: DX7 envelope decay value (0-99) 204 | //---------------------------------------------------------- 205 | // CSOUND function implemented as a BPF 206 | // Corresponds to F7 in the CSOUND implementation. 207 | dx7_egratedecayperc_bpf = ba.bpf.start(0,0.00001) : seq(i,10,ba.bpf.point(xPoints(i),yPoints(i))) : ba.bpf.end(127,1) 208 | with { 209 | xPoints(n) = ba.take(n+1,(10,20,30,40,50,60,70,80,90,99)); 210 | yPoints(n) = ba.take(n+1,(0.25,0.35,0.43,0.52,0.59,0.7,0.77,0.84,0.92,1)); 211 | }; 212 | // Function estimated from the CSOUND function (default) 213 | dx7_egratedecayperc_func = min(99)/99 : pow(_,0.7); 214 | dx7_egratedecaypercf = dx7_egratedecayperc_func; 215 | 216 | //----------------------`(dx.)dx7_eglv2peakf`-------------------------- 217 | // DX7 envelope level to peak conversion function. 3 versions of 218 | // this function are available: 219 | // 220 | // * `dx7_eglv2peak_bpf`: BPF version (same as in the CSOUND toolkit) 221 | // * `dx7_eglv2peak_func`: estimated mathematical equivalent of `dx7_eglv2peak_bpf` 222 | // * `dx7_eglv2peakf`: default (sugar for `dx7_eglv2peak_func`) 223 | // 224 | // #### Usage: 225 | // 226 | // ``` 227 | // dx7Level : dx7_eglv2peakf : _ 228 | // ``` 229 | // 230 | // Where: 231 | // 232 | // * `dx7Level`: DX7 level value (0-99) 233 | //----------------------------------------------------------- 234 | // CSOUND function implemented as a BPF 235 | // Corresponds to F8 in the CSOUND implementation. 236 | dx7_eglv2peak_bpf = ba.bpf.start(0,0) : seq(i,14,ba.bpf.point(xPoints(i)+1,yPoints(i))) : ba.bpf.end(127,2.08795) 237 | with { 238 | xPoints(n) = ba.take(n+1,(9,19,29,39,49,59,64,59,74,79,84,89,94,98)); 239 | yPoints(n) = ba.take(n+1,(0.000477,0.002,0.00493,0.01257,0.02992,0.07098,0.10981,0.16997,0.260855,0.39979,0.61974,0.95954,1.47425,2.08795)); 240 | }; 241 | // Function estimated from the CSOUND function (default) 242 | dx7_eglv2peak_func = min(98)/98 : pow(_,8) : *(2.08795); 243 | dx7_eglv2peakf = dx7_eglv2peak_func; 244 | 245 | //----------------------`(dx.)dx7_fdbkscalef`-------------------------- 246 | // DX7 feedback scaling conversion function. 247 | // 248 | // #### Usage: 249 | // 250 | // ``` 251 | // dx7Feedback : dx7_fdbkscalef : _ 252 | // ``` 253 | // 254 | // Where: 255 | // 256 | // * `dx7Feedback`: DX7 feedback value 257 | //----------------------------------------------------------- 258 | // Corresponds to F11 in the CSOUND implementation 259 | dx7_fdbkscalef = *(0.875); 260 | 261 | //------------------------------`(dx.)dx7_op`--------------------------- 262 | // DX7 Operator. Implements a phase-modulable sine wave oscillator connected 263 | // to a DX7 envelope generator. 264 | // 265 | // #### Usage: 266 | // 267 | // ``` 268 | // dx7_op(mode,freqCoarse,freqFine,detune,outLev,R1,R2,R3,R4,L1,L2,L3,L4,keyVelSens,ampModSens,rateScale,lfoWave,lfoSpeed,lfoDelay,lfoPMD,lfoAMD,lfoSync,lfoPitchModSens,oscKeySync,pitch_egR1,pitch_egR2,pitch_egR3,pitch_egR4,pitch_egL1,pitch_egL2,pitch_egL3,pitch_egL4,breakpoint,breakpointLDepth,breakpointRDepth,breakpointLCurve,breakpointRCurve,transpose,phaseMod,type,base_freq,gain,gate) : _ 269 | // ``` 270 | // 271 | // Where: 272 | // 273 | // * `mode`: pitch mode (0=ratio; 1=fixed) 274 | // * `freqCoarse`: coarse frequency (0-31) 275 | // * `freqFine`: fine frequency (0-99) 276 | // * `detune`: detune in semitones (-7 - 7) 277 | // * `outLev`: output level (0-99) 278 | // * `R1`: envelope rate 1 (0-99) 279 | // * `R2`: envelope rate 2 (0-99) 280 | // * `R3`: envelope rate 3 (0-99) 281 | // * `R4`: envelope rate 4 (0-99) 282 | // * `L1`: envelope level 1 (0-99) 283 | // * `L2`: envelope level 2 (0-99) 284 | // * `L3`: envelope level 3 (0-99) 285 | // * `L4`: envelope level 4 (0-99) 286 | // * `keyVelSens`: key velocity sensitivity (0-7) 287 | // * `ampModSens`: amplitude sensitivity (0-3) 288 | // * `rateScale`: envelope rate scale (0-7) 289 | // * `breakpoint`: break point position (0-99) 290 | // * `breakpointLDepth`: break point left depth (0-99) 291 | // * `breakpointRDepth`: break point right depth (0-99) 292 | // * `breakpointLCurve`: break point left curve (0-3) (-LIN,-EXP,+EXP,+LIN) 293 | // * `breakpointRCurve`: break point right curve (0-3) (-LIN,-EXP,+EXP,+LIN) 294 | // * `lfoWave`: LFO wave mode (0-5) (triangle, saw down, saw up, square, sine, sample&hold) 295 | // * `lfoSpeed`: LFO speed (0-99) 296 | // * `lfoDelay`: LFO delay (0-99) 297 | // * `lfoPMD`: LFO pitch modulation depth (0-99) 298 | // * `lfoAMD`: LFO amplitude modulation depth (0-99) 299 | // * `lfoSync`: (0-1) (0=no retrigger; 1=retrigger) 300 | // * `lfoPitchModSens`: LFO Pitch modulation sensitivity (0-7) 301 | // * `oscKeySync`: osc key sync (0-1) 302 | // * `pitch_egR1`: pitch envelope generator rate 1 (0-99) 303 | // * `pitch_egR2`: pitch envelope generator rate 2 (0-99) 304 | // * `pitch_egR3`: pitch envelope generator rate 3 (0-99) 305 | // * `pitch_egR4`: pitch envelope generator rate 4 (0-99) 306 | // * `pitch_egL1`: pitch envelope generator level 1 (0-99) 307 | // * `pitch_egL2`: pitch envelope generator level 2 (0-99) 308 | // * `pitch_egL3`: pitch envelope generator level 3 (0-99) 309 | // * `pitch_egL4`: pitch envelope generator level 4 (0-99) 310 | // * `transpose`: global transpose (-24 - 24) 311 | // * `phaseMod`: phase deviation (-1 - 1) 312 | // * `type`: operator type (0-1) 313 | // * `base_freq`: frequency of the oscillator 314 | // * `gain`: general gain 315 | // * `gate`: trigger signal 316 | //----------------------------------------------------------------- 317 | dx7_op(mode,freqCoarse,freqFine,detune,outLev,R1,R2,R3,R4,L1,L2,L3,L4,keyVelSens,ampModSens,rateScale,breakpoint,breakpointLDepth,breakpointRDepth,breakpointLCurve,breakpointRCurve,lfoWave,lfoSpeed,lfoDelay,lfoPMD,lfoAMD,lfoSync,lfoPitchModSens,oscKeySync,pitch_egR1,pitch_egR2,pitch_egR3,pitch_egR4,pitch_egL1,pitch_egL2,pitch_egL3,pitch_egL4,transpose,phaseMod,type,base_freq,gain,gate) = output 318 | with { 319 | 320 | freq = select2(mode,freq_ratio*base_freq*ba.semi2ratio(transpose+detune+lfoDetune+pitchEnvDetune),freq_fixed) // todo: check this 321 | with { 322 | freq_ratio = rdtable(FreqTableCoarse_ratio, freqCoarse)*rdtable(FreqTableFine_ratio, freqFine); 323 | freq_fixed = rdtable(FreqTableCoarse_fixed, freqCoarse)*rdtable(FreqTableFine_fixed, freqFine); 324 | 325 | FreqTableCoarse_ratio = waveform{ 326 | 0.5,1,2,3,4,5,6,7,8,9,10,11,12,13, 327 | 14,15,16,17,18,19,20,21,22,23,24, 328 | 25,26,27,28,29,30,31 329 | }; 330 | 331 | FreqTableCoarse_fixed = waveform{ 332 | 1,10,100,1000, 333 | 1,10,100,1000, 334 | 1,10,100,1000, 335 | 1,10,100,1000, 336 | 1,10,100,1000, 337 | 1,10,100,1000, 338 | 1,10,100,1000, 339 | 1,10,100,1000 340 | }; 341 | 342 | FreqTableFine_ratio = waveform{ 343 | 1.00,1.01,1.02,1.03,1.04,1.05,1.06, 344 | 1.07,1.08,1.09,1.10,1.11,1.12,1.13, 345 | 1.14,1.15,1.16,1.17,1.18,1.19,1.20, 346 | 1.21,1.22,1.23,1.24,1.25,1.26,1.27, 347 | 1.28,1.29,1.30,1.31,1.32,1.33,1.34, 348 | 1.35,1.36,1.37,1.38,1.39,1.40,1.41, 349 | 1.42,1.43,1.44,1.45,1.46,1.47,1.48, 350 | 1.49,1.50,1.51,1.52,1.53,1.54,1.55, 351 | 1.56,1.57,1.58,1.59,1.60,1.61,1.62, 352 | 1.63,1.64,1.65,1.66,1.67,1.68,1.69, 353 | 1.70,1.71,1.72,1.73,1.74,1.75,1.76, 354 | 1.77,1.78,1.79,1.80,1.81,1.82,1.83, 355 | 1.84,1.85,1.86,1.87,1.88,1.89,1.90, 356 | 1.91,1.92,1.93,1.94,1.95,1.96,1.97, 357 | 1.98,1.99 358 | }; 359 | 360 | FreqTableFine_fixed = waveform{ 361 | 1.000,1.023,1.047,1.072,1.096,1.122, 362 | 1.148,1.175,1.202,1.230,1.259,1.288, 363 | 1.318,1.349,1.380,1.413,1.445,1.479, 364 | 1.514,1.549,1.585,1.622,1.660,1.698, 365 | 1.738,1.778,1.820,1.862,1.905,1.950, 366 | 1.995,2.042,2.089,2.138,2.188,2.239, 367 | 2.291,2.344,2.399,2.455,2.512,2.570, 368 | 2.630,2.692,2.716,2.818,2.884,2.951, 369 | 3.020,3.090,3.162,3.236,3.311,3.388, 370 | 3.467,3.548,3.631,3.715,3.802,3.890, 371 | 3.981,4.074,4.169,4.266,4.365,4.467, 372 | 4.571,4.677,4.786,4.898,5.012,5.129, 373 | 5.248,5.370,5.495,5.623,5.754,5.888, 374 | 6.026,6.166,6.310,6.457,6.607,6.761, 375 | 6.918,7.079,7.244,7.413,7.586,7.762, 376 | 7.943,8.128,8.318,8.511,8.718,8.913, 377 | 9.120,9.333,9.550,9.772 378 | }; 379 | }; 380 | 381 | tablesize = 1 << 16; 382 | 383 | // todo: the interaction between lfoDelay and lfoSync is ambiguous. 384 | lfo = lfo_tri, lfo_sawdown, lfo_sawup, lfo_square, lfo_sine, lfo_sh : ba.selectn(6, lfoWave) 385 | with { 386 | lfoTableSize = 1 << 16; 387 | 388 | hold_timer = 1 : (+~(*(ba.if(gate-gate',0,1)))); 389 | 390 | lfoFreq = lfoSpeed : pow(_/99, 4) : it.remap(0, 1, 1, 50); // todo: remap to "under 1 hz to about 50 Hz" according to official DX7 manual. 391 | phasor = os.hsp_phasor(lfoTableSize,lfoFreq,phasor_reset,0.5) 392 | with { 393 | lfoDelaySamples = lfoDelay * (.5 * ma.SR / 99); // todo: don't know how to scale, so set max to 0.5 seconds 394 | phasor_reset = (lfoDelaySamples >= hold_timer) | (lfoSync & (ba.impulsify(gate))); 395 | }; 396 | 397 | lfo_tri = rdtable(lfoTableSize, triwaveform, ma.modulo(phasor+int(lfoTableSize/4), lfoTableSize)) 398 | with { 399 | triwaveform = 2*abs((ba.period(lfoTableSize)*2/lfoTableSize-1))-1; 400 | }; 401 | lfo_sawdown = -1*lfo_sawup; 402 | lfo_sawup = (phasor/lfoTableSize)*2-1; 403 | lfo_square = select2(phasor < (lfoTableSize/2),-1,1); // todo: not sure about phase 404 | lfo_sine = 0-rdtable(lfoTableSize, os.sinwaveform(lfoTableSize), phasor); 405 | lfo_sh = no.lfnoise0(lfoFreq); // "random output" according to official DX7 manual 406 | }; 407 | 408 | lfoDetune = lfo * lfoPMD * lfoPitchModSens * (12 / (99*7)); // todo: it currently detunes to plus/minus 12 semitones when lfoPMD is maxed at 99 and lfoPitchModSens is 7 409 | 410 | lfoGain = it.interpolate_linear(lfoAMD*ampModSens/(99*3), 0, lfo*49); // todo: 411 | 412 | // phase modulation, not freq modulation 413 | sineWave = rdtable(tablesize, os.sinwaveform(tablesize), idx) 414 | with { 415 | idx = ma.modulo(int(os.hs_phasor(tablesize,freq, oscKeySync & (ba.impulsify(gate))) + phaseMod*tablesize),tablesize); 416 | }; 417 | 418 | pitchEnvDetune = makeEnvelope(pitch_egR1,pitch_egR2,pitch_egR3,pitch_egR4,pitch_egL1,pitch_egL2,pitch_egL3,pitch_egL4) : (ba.bpf.start(0,-48) : ba.bpf.point(50,0) : ba.bpf.end(99,48)); 419 | 420 | makeEnvelope(r1,r2,r3,r4,egl1,egl2,egl3,egl4) = en.dx7envelope(egr1,egr2,egr3,egr4,egl1,egl2,egl3,egl4,gate) 421 | with { 422 | // computing rates 423 | rs = (base_freq : ba.hz2midikey)-21 : /(105)*6*rateScale; // todo: 424 | egr1 = r1+rs : min(99) <: 425 | select2(egl1 > egl4,dx7_egratedecayf,dx7_egraterisef) <: 426 | *(egl4 <: select2( egl1 > egl4, dx7_egratedecaypercf, dx7_egraterisepercf)), 427 | *(egl1 <: select2( egl1 > egl4, dx7_egratedecaypercf, dx7_egraterisepercf)) : 428 | - : abs : max(0.001); 429 | egr2 = r2+rs : min(99) <: 430 | select2(egl2 > egl1,dx7_egratedecayf,dx7_egraterisef) <: 431 | *(egl1 <: select2( egl2 > egl1, dx7_egratedecaypercf, dx7_egraterisepercf)), 432 | *(egl2 <: select2( egl2 > egl1, dx7_egratedecaypercf, dx7_egraterisepercf)) : 433 | - : abs : max(0.001); 434 | egr3 = r3+rs : min(99) <: 435 | select2(egl3 > egl2,dx7_egratedecayf,dx7_egraterisef) <: 436 | *(egl2 <: select2( egl3 > egl2, dx7_egratedecaypercf, dx7_egraterisepercf)), 437 | *(egl3 <: select2( egl3 > egl2, dx7_egratedecaypercf, dx7_egraterisepercf)) : 438 | - : abs : max(0.001); 439 | egr4 = r4+rs : min(99) <: 440 | select2(egl4 >= egl3,dx7_egratedecayf,dx7_egraterisef) <: 441 | *(egl3 <: select2(egl4 >= egl3, dx7_egratedecaypercf, dx7_egraterisepercf)), 442 | *(egl4 <: select2(egl4 >= egl3, dx7_egratedecaypercf, dx7_egraterisepercf)) : 443 | - : abs : max(0.001); 444 | }; 445 | 446 | brkPointGain = brkDepth*select2((brkCurve == 1)|(brkCurve==2), normalized, pow(normalized, 2.)) // todo: exponential is not pow 447 | with { 448 | note = base_freq : ba.hz2midikey; 449 | breakpointNote = breakpoint : it.remap(0, 99, 33, 108); // A1 (33) to C8 (108) 450 | is_right_sec = note >= breakpointNote; 451 | 452 | brkCurve = select2(is_right_sec, breakpointLCurve, breakpointRCurve); 453 | brkDepth = select2(is_right_sec, breakpointLDepth, breakpointRDepth)*select2(brkCurve<2,1,-1); 454 | 455 | // A1 (33) to C8 (108) 456 | normalized = select2(is_right_sec, (breakpoint-note)/max(1, breakpointNote-33), (note-breakpoint)/max(1, 108-breakpointNote)) : min(1); 457 | }; 458 | 459 | envGain = makeEnvelope(R1,R2,R3,R4,L1,L2,L3,L4) + (outLev-99) + brkPointGain + lfoGain <: select2(type,dx7_eglv2peakf,dx7_ampf); 460 | velGain = it.interpolate_linear(keyVelSens/7, 1, gain); 461 | output = envGain*velGain*sineWave; 462 | }; 463 | 464 | //------------------------------`(dx.)dx7_all`--------------------------- 465 | // Generic DX7 function where all parameters are controllable using UI elements. 466 | // The `master-with-mute` branch must be used for this function to work... 467 | // This function is MIDI-compatible. 468 | // 469 | // #### Usage 470 | // 471 | // ``` 472 | // dx7_all : _ 473 | // ``` 474 | //----------------------------------------------------------------- 475 | dx7_all = par(i,32,dx7_algorithm(i+1) : control(algorithm-1 == i)) :> _ 476 | with { 477 | algorithm = nentry("h:DX7/v:Global/h:Main/Algorithm", 1, 1, 32, 1); 478 | }; 479 | 480 | //------------------------------`(dx.)dx7_algorithm`--------------------------- 481 | // DX7 function for a specific algorithm at compile-time. This function is 482 | // MIDI-compatible. 483 | // 484 | // #### Usage 485 | // 486 | // ``` 487 | // dx7_algorithm(algorithm) : _ 488 | // ``` 489 | // 490 | // Where: 491 | // * `algorithm`: algorithm identifier (1-32) 492 | // 493 | //----------------------------------------------------------------- 494 | dx7_algorithm(algorithm) = hgroup("DX7", dx7_algo(algorithm)) 495 | with { 496 | 497 | GLOBAL(x) = vgroup("Global", x); 498 | MAIN(x) = GLOBAL(hgroup("[0] Main", x)); 499 | PEGR(x) = GLOBAL(hgroup("[1] Pitch Env Generator Rates", x)); 500 | PEGL(x) = GLOBAL(hgroup("[2] Pitch Env Generator Levels", x)); 501 | LFO(x) = GLOBAL(hgroup("[3] LFO", x)); 502 | freq = GLOBAL(hslider("[4] freq",400,50,1000,0.01)); 503 | gain = GLOBAL(hslider("[5] gain",0.8,0,1,0.01)); 504 | gate = GLOBAL(button("[6] gate")); 505 | 506 | feedback = MAIN(hslider("[0] Feedback [style:knob]",0,0,7,1) : dx7_fdbkscalef/(2*ma.PI)); 507 | transpose = MAIN(hslider("[1] Transpose [style:knob]",0,-24,24,1)); 508 | oscKeySync = MAIN(hslider("[2] Osc Key Sync [style:knob]",1,0,1,1)); 509 | 510 | pegR1 = PEGR(hslider("[0] R1 [style:knob]",90,0,99,1)); 511 | pegR2 = PEGR(hslider("[1] R2 [style:knob]",90,0,99,1)); 512 | pegR3 = PEGR(hslider("[2] R3 [style:knob]",90,0,99,1)); 513 | pegR4 = PEGR(hslider("[3] R4 [style:knob]",90,0,99,1)); 514 | 515 | pegL1 = PEGL(hslider("[0] L1 [style:knob]",50,0,99,1)); 516 | pegL2 = PEGL(hslider("[1] L2 [style:knob]",50,0,99,1)); 517 | pegL3 = PEGL(hslider("[2] L3 [style:knob]",50,0,99,1)); 518 | pegL4 = PEGL(hslider("[3] L4 [style:knob]",50,0,99,1)); 519 | 520 | lfoWave = LFO(nentry("[0] Wave [style:menu{'Triangle':0;'Saw Down':1;'Saw Up':2;'Square':3;'Sine':4;'Sample & Hold':5}]",0,0,5,1)); 521 | lfoSpeed = LFO(hslider("[1] Speed [style:knob]",35,0,99,1)); 522 | lfoDelay = LFO(hslider("[2] Delay [style:knob]",0,0,99,1)); 523 | lfoPMD = LFO(hslider("[3] PMD [style:knob]",0,0,99,1)); 524 | lfoAMD = LFO(hslider("[4] AMD [style:knob]",0,0,99,1)); 525 | lfoSync = LFO(hslider("[5] Sync [style:knob]",1,0,1,1)); 526 | lfoPitchModSens = LFO(hslider("[6] Pitch Mod Sens [style:knob]",3,0,7,1)); 527 | 528 | // concise way of making the same UI element for all 6 operators. 529 | oppar(entry, n) = ba.take(n+1, par(i, 6, func(i))) 530 | with { 531 | func(i) = vgroup("[%i]Operator %j", entry) 532 | with { 533 | j = i+1; 534 | }; 535 | }; 536 | 537 | AEG(x) = vgroup("[0] Amp Env Generator", x); 538 | RATES(x) = AEG(hgroup("[0] Rates", x)); 539 | LEVELS(x) = AEG(hgroup("[1] Levels", x)); 540 | AEOTHER(x) = AEG(hgroup("[2] Other", x)); 541 | TONE(x) = hgroup("[1] Tone", x); 542 | BREAKPOINT(x) = hgroup("[2] Break Point", x); 543 | 544 | // Each of these is a `getSomeParameterForOperator(i)` for i [0-5] 545 | egR1 = oppar(RATES(hslider("[0] R1 [style:knob]",90,0,99,1))); 546 | egR2 = oppar(RATES(hslider("[1] R2 [style:knob]",90,0,99,1))); 547 | egR3 = oppar(RATES(hslider("[2] R3 [style:knob]",90,0,99,1))); 548 | egR4 = oppar(RATES(hslider("[3] R4 [style:knob]",90,0,99,1))); 549 | egL1 = oppar(LEVELS(hslider("[0] L1 [style:knob]",90,0,99,1))); 550 | egL2 = oppar(LEVELS(hslider("[1] L2 [style:knob]",90,0,99,1))); 551 | egL3 = oppar(LEVELS(hslider("[2] L3 [style:knob]",90,0,99,1))); 552 | egL4 = oppar(LEVELS(hslider("[3] L4 [style:knob]",0,0,99,1))); 553 | freqMode = oppar(AEOTHER(hslider("[0] Freq Mode [style:knob]",0,0,1,1))); 554 | rateScale = oppar(AEOTHER(hslider("[1] Rate Scale [style:knob]",0,0,7,1))); 555 | outLevel = oppar(AEOTHER(hslider("[2] Level [style:knob]",99,0,99,1))); 556 | keyVelSens = oppar(AEOTHER(hslider("[3] KeyVelSens [style:knob]",7,0,7,1))); 557 | ampModSens = oppar(AEOTHER(hslider("[4] AmpModSens [style:knob]",0,0,3,1))); 558 | 559 | freqCoarse = oppar(TONE(nentry("[0] Freq Coarse",1,0.0,31,1))); 560 | freqFine = oppar(TONE(nentry("[1] Freq Fine",0,0.0,99,1))); 561 | detune = oppar(TONE(hslider("[2] Detune [style:knob]",0,-7,7,1))); 562 | 563 | breakpoint = oppar(BREAKPOINT(hslider("[0] Break Point [style:knob]", 51, 0, 99, 1))); // todo: not sure about default 564 | breakpointLDepth = oppar(BREAKPOINT(hslider("[1] Left Depth [style:knob]", 0, 0, 99, 1))); 565 | breakpointRDepth = oppar(BREAKPOINT(hslider("[2] Right Depth [style:knob]", 0, 0, 99, 1))); 566 | breakpointLCurve = oppar(BREAKPOINT(nentry("[3] Left Curve [style:menu{'-LIN':0;'-EXP':1;'+EXP':2;'+LIN':3}]",0,0,3,1))); 567 | breakpointRCurve = oppar(BREAKPOINT(nentry("[4] Right Curve [style:menu{'-LIN':0;'-EXP':1;'+EXP':2;'+LIN':3}]",0,0,3,1))); 568 | 569 | make_dx7_op(i, phase_mod, type) = dx7_op( 570 | freqMode(i),freqCoarse(i),freqFine(i),detune(i),outLevel(i), 571 | egR1(i),egR2(i),egR3(i),egR4(i),egL1(i),egL2(i),egL3(i),egL4(i), 572 | keyVelSens(i),ampModSens(i),rateScale(i), 573 | breakpoint(i),breakpointLDepth(i),breakpointRDepth(i),breakpointLCurve(i),breakpointRCurve(i), 574 | lfoWave,lfoSpeed,lfoDelay,lfoPMD,lfoAMD,lfoSync,lfoPitchModSens, 575 | oscKeySync, 576 | pegR1,pegR2,pegR3,pegR4,pegL1,pegL2,pegL3,pegL4, 577 | transpose,phase_mod,type,freq,gain,gate 578 | ); 579 | 580 | // NOTE: the .2 for feedback was hardcoded in the csound orchestra, not sure why we need it 581 | dx7_algo(1) = (op2 : op1),(op6~*(feedback*.2) : op5 : op4 : op3) :> _ 582 | with { 583 | op6 = make_dx7_op(5, _, 1); 584 | op5 = make_dx7_op(4, _, 1); 585 | op4 = make_dx7_op(3, _, 1); 586 | op3 = make_dx7_op(2, _, 0); 587 | op2 = make_dx7_op(1, 0, 1); 588 | op1 = make_dx7_op(0, _, 0); 589 | }; 590 | 591 | // NOTE: the .2 for feedback was hardcoded in the csound orchestra, not sure why we need it 592 | dx7_algo(2) = (op2~*(feedback*.2) : op1),(op6 : op5 : op4 : op3) :> _ 593 | with { 594 | op6 = make_dx7_op(5, 0, 1); 595 | op5 = make_dx7_op(4, _, 1); 596 | op4 = make_dx7_op(3, _, 1); 597 | op3 = make_dx7_op(2, _, 0); 598 | op2 = make_dx7_op(1, _, 1); 599 | op1 = make_dx7_op(0, _, 0); 600 | }; 601 | 602 | // Note: weird rand and delay implemented in the csound orchestra and not really sure why... 603 | dx7_algo(3) = (op3 : op2 : op1),(op6~*(feedback) : op5 : op4) :> _ 604 | with { 605 | op6 = make_dx7_op(5, _, 1); 606 | op5 = make_dx7_op(4, _, 1); 607 | op4 = make_dx7_op(3, _, 0); 608 | op3 = make_dx7_op(2, 0, 1); 609 | op2 = make_dx7_op(1, _, 1); 610 | op1 = make_dx7_op(0, _, 0); 611 | }; 612 | 613 | dx7_algo(4) = (op3 : op2 : op1),(op6 : op5 : op4)~*(feedback) :> _ 614 | with { 615 | op6 = make_dx7_op(5, _, 1); 616 | op5 = make_dx7_op(4, _, 1); 617 | op4 = make_dx7_op(3, _, 0); 618 | op3 = make_dx7_op(2, 0, 1); 619 | op2 = make_dx7_op(1, _, 1); 620 | op1 = make_dx7_op(0, _, 0); 621 | }; 622 | 623 | // NOTE: the .1 for feedback was hardcoded in the csound orchestra, not sure why we need it 624 | dx7_algo(5) = (op2 : op1),(op4 : op3),(op6~*(feedback*.1) : op5) :> _ 625 | with { 626 | op6 = make_dx7_op(5, _, 1); 627 | op5 = make_dx7_op(4, _, 0); 628 | op4 = make_dx7_op(3, 0, 1); 629 | op3 = make_dx7_op(2, _, 0); 630 | op2 = make_dx7_op(1, 0, 1); 631 | op1 = make_dx7_op(0, _, 0); 632 | }; 633 | 634 | dx7_algo(6) = (op2 : op1),(op4 : op3),(op6 : op5)~*(feedback) :> _ 635 | with { 636 | op6 = make_dx7_op(5, _, 1); 637 | op5 = make_dx7_op(4, _, 0); 638 | op4 = make_dx7_op(3, 0, 1); 639 | op3 = make_dx7_op(2, _, 0); 640 | op2 = make_dx7_op(1, 0, 1); 641 | op1 = make_dx7_op(0, _, 0); 642 | }; 643 | 644 | dx7_algo(7) = (op2 : op1),(op4,(op6~*(feedback) : op5) :> op3) :> _ 645 | with { 646 | op6 = make_dx7_op(5, _, 1); 647 | op5 = make_dx7_op(4, _, 1); 648 | op4 = make_dx7_op(3, 0, 1); 649 | op3 = make_dx7_op(2, _, 0); 650 | op2 = make_dx7_op(1, 0, 1); 651 | op1 = make_dx7_op(0, _, 0); 652 | }; 653 | 654 | // NOTE: the .1 for feedback was hardcoded in the csound orchestra, not sure why we need it 655 | dx7_algo(8) = (op2 : op1),(op4~*(feedback*.1),(op6 : op5) :> op3) :> _ 656 | with { 657 | op6 = make_dx7_op(5, 0, 1); 658 | op5 = make_dx7_op(4, _, 1); 659 | op4 = make_dx7_op(3, _, 1); 660 | op3 = make_dx7_op(2, _, 0); 661 | op2 = make_dx7_op(1, 0, 1); 662 | op1 = make_dx7_op(0, _, 0); 663 | }; 664 | 665 | // NOTE: the .4 for feedback was hardcoded in the csound orchestra, not sure why we need it 666 | dx7_algo(9) = (op2~*(feedback*.4) : op1),(op4,(op6 : op5) :> op3) :> _ 667 | with { 668 | op6 = make_dx7_op(5, 0, 1); 669 | op5 = make_dx7_op(4, _, 1); 670 | op4 = make_dx7_op(3, 0, 1); 671 | op3 = make_dx7_op(2, _, 0); 672 | op2 = make_dx7_op(1, _, 1); 673 | op1 = make_dx7_op(0, _, 0); 674 | }; 675 | 676 | // NOTE: the .2 for feedback was hardcoded in the csound orchestra, not sure why we need it 677 | dx7_algo(10) = (op5,op6 :> op4),(op3~*(feedback*.2) : op2 : op1) :> _ 678 | with { 679 | op6 = make_dx7_op(5, 0, 1); 680 | op5 = make_dx7_op(4, 0, 1); 681 | op4 = make_dx7_op(3, _, 0); 682 | op3 = make_dx7_op(2, _, 1); 683 | op2 = make_dx7_op(1, _, 1); 684 | op1 = make_dx7_op(0, _, 0); 685 | }; 686 | 687 | // NOTE: the .2 for feedback was hardcoded in the csound orchestra, not sure why we need it 688 | dx7_algo(11) = (op5,op6~*(feedback*.2) :> op4),(op3 : op2 : op1) :> _ 689 | with { 690 | op6 = make_dx7_op(5, _, 1); 691 | op5 = make_dx7_op(4, 0, 1); 692 | op4 = make_dx7_op(3, _, 0); 693 | op3 = make_dx7_op(2, 0, 1); 694 | op2 = make_dx7_op(1, _, 1); 695 | op1 = make_dx7_op(0, _, 0); 696 | }; 697 | 698 | // NOTE: the .2 for feedback was hardcoded in the csound orchestra, not sure why we need it 699 | dx7_algo(12) = (op4,op5,op6 :> op3),(op2~*(feedback*.2) : op1) :> _ 700 | with { 701 | op6 = make_dx7_op(5, 0, 1); 702 | op5 = make_dx7_op(4, 0, 1); 703 | op4 = make_dx7_op(3, 0, 1); 704 | op3 = make_dx7_op(2, _, 0); 705 | op2 = make_dx7_op(1, _, 1); 706 | op1 = make_dx7_op(0, _, 0); 707 | }; 708 | 709 | dx7_algo(13) = (op4,op5,op6~*(feedback) :> op3),(op2 : op1) :> _ 710 | with { 711 | op6 = make_dx7_op(5, _, 1); 712 | op5 = make_dx7_op(4, 0, 1); 713 | op4 = make_dx7_op(3, 0, 1); 714 | op3 = make_dx7_op(2, _, 0); 715 | op2 = make_dx7_op(1, 0, 1); 716 | op1 = make_dx7_op(0, _, 0); 717 | }; 718 | 719 | dx7_algo(14) = (op2 : op1),(op5,op6~*(feedback) :> op4 : op3) :> _ 720 | with { 721 | op6 = make_dx7_op(5, _, 1); 722 | op5 = make_dx7_op(4, 0, 1); 723 | op4 = make_dx7_op(3, _, 1); 724 | op3 = make_dx7_op(2, _, 0); 725 | op2 = make_dx7_op(1, 0, 1); 726 | op1 = make_dx7_op(0, _, 0); 727 | }; 728 | 729 | // NOTE: the .4 for feedback was hardcoded in the csound orchestra, not sure why we need it 730 | dx7_algo(15) = (op2~*(feedback*.4) : op1),(op5,op6 :> op4 : op3) :> _ 731 | with { 732 | op6 = make_dx7_op(5, 0, 1); 733 | op5 = make_dx7_op(4, 0, 1); 734 | op4 = make_dx7_op(3, _, 1); 735 | op3 = make_dx7_op(2, _, 0); 736 | op2 = make_dx7_op(1, _, 1); 737 | op1 = make_dx7_op(0, _, 0); 738 | }; 739 | 740 | dx7_algo(16) = op2,(op4 : op3),(op6~*(feedback) : op5) :> op1 741 | with { 742 | op6 = make_dx7_op(5, _, 1); 743 | op5 = make_dx7_op(4, _, 1); 744 | op4 = make_dx7_op(3, 0, 1); 745 | op3 = make_dx7_op(2, _, 1); 746 | op2 = make_dx7_op(1, 0, 1); 747 | op1 = make_dx7_op(0, _, 0); 748 | }; 749 | 750 | // NOTE: the .5 for feedback was hardcoded in the csound orchestra, not sure why we need it 751 | dx7_algo(17) = op2~*(feedback*.5),(op4 : op3),(op6 : op5) :> op1 752 | with { 753 | op6 = make_dx7_op(5, 0, 1); 754 | op5 = make_dx7_op(4, _, 1); 755 | op4 = make_dx7_op(3, 0, 1); 756 | op3 = make_dx7_op(2, _, 1); 757 | op2 = make_dx7_op(1, _, 1); 758 | op1 = make_dx7_op(0, _, 0); 759 | }; 760 | 761 | dx7_algo(18) = op2,op3~*(feedback),(op6 : op5 : op4) :> op1 762 | with { 763 | op6 = make_dx7_op(5, 0, 1); 764 | op5 = make_dx7_op(4, _, 1); 765 | op4 = make_dx7_op(3, _, 1); 766 | op3 = make_dx7_op(2, _, 1); 767 | op2 = make_dx7_op(1, 0, 1); 768 | op1 = make_dx7_op(0, _, 0); 769 | }; 770 | 771 | // NOTE: the .4 for feedback was hardcoded in the csound orchestra, not sure why we need it 772 | dx7_algo(19) = (op3 : op2 : op1),(op6~*(feedback*.4) <: op4,op5) :> _ 773 | with { 774 | op6 = make_dx7_op(5, _, 1); 775 | op5 = make_dx7_op(4, _, 0); 776 | op4 = make_dx7_op(3, _, 0); 777 | op3 = make_dx7_op(2, 0, 1); 778 | op2 = make_dx7_op(1, _, 1); 779 | op1 = make_dx7_op(0, _, 0); 780 | }; 781 | 782 | dx7_algo(20) = (op3~*(feedback) <: op1,op2),(op5,op6 :> op4) :> _ 783 | with { 784 | op6 = make_dx7_op(5, 0, 1); 785 | op5 = make_dx7_op(4, 0, 1); 786 | op4 = make_dx7_op(3, _, 0); 787 | op3 = make_dx7_op(2, _, 1); 788 | op2 = make_dx7_op(1, _, 0); 789 | op1 = make_dx7_op(0, _, 0); 790 | }; 791 | 792 | dx7_algo(21) = (op3~*(feedback) <: op1,op2),(op6 <: op4,op5) :> _ 793 | with { 794 | op6 = make_dx7_op(5, 0, 1); 795 | op5 = make_dx7_op(4, _, 0); 796 | op4 = make_dx7_op(3, _, 0); 797 | op3 = make_dx7_op(2, _, 1); 798 | op2 = make_dx7_op(1, _, 0); 799 | op1 = make_dx7_op(0, _, 0); 800 | }; 801 | 802 | // NOTE: the .1 for feedback was hardcoded in the csound orchestra, not sure why we need it 803 | dx7_algo(22) = (op2 : op1),(op6~*(feedback*.1) <: op3,op4,op5) :> _ 804 | with { 805 | op6 = make_dx7_op(5, _, 1); 806 | op5 = make_dx7_op(4, _, 0); 807 | op4 = make_dx7_op(3, _, 0); 808 | op3 = make_dx7_op(2, _, 1); 809 | op2 = make_dx7_op(1, 0, 0); 810 | op1 = make_dx7_op(0, _, 0); 811 | }; 812 | 813 | dx7_algo(23) = op1,(op3 : op2),(op6~*(feedback) <: op4,op5) :> _ 814 | with { 815 | op6 = make_dx7_op(5, _, 1); 816 | op5 = make_dx7_op(4, _, 0); 817 | op4 = make_dx7_op(3, _, 0); 818 | op3 = make_dx7_op(2, 0, 1); 819 | op2 = make_dx7_op(1, _, 0); 820 | op1 = make_dx7_op(0, _, 0); 821 | }; 822 | 823 | // NOTE: the .6 for feedback was hardcoded in the csound orchestra, not sure why we need it 824 | dx7_algo(24) = op1,op2,(op6~*(feedback*.6) <: op3,op4,op5) :> _ 825 | with { 826 | op6 = make_dx7_op(5, _, 1); 827 | op5 = make_dx7_op(4, _, 0); 828 | op4 = make_dx7_op(3, _, 0); 829 | op3 = make_dx7_op(2, _, 0); 830 | op2 = make_dx7_op(1, 0, 0); 831 | op1 = make_dx7_op(0, 0, 0); 832 | }; 833 | 834 | dx7_algo(25) = op1,op2,op3,(op6~*(feedback) <: op4,op5) :> _ 835 | with { 836 | op6 = make_dx7_op(5, _, 1); 837 | op5 = make_dx7_op(4, _, 0); 838 | op4 = make_dx7_op(3, _, 0); 839 | op3 = make_dx7_op(2, 0, 0); 840 | op2 = make_dx7_op(1, 0, 0); 841 | op1 = make_dx7_op(0, 0, 0); 842 | }; 843 | 844 | dx7_algo(26) = op1,(op3 : op2),(op5,op6~*(feedback) :> op4) :> _ 845 | with { 846 | op6 = make_dx7_op(5, _, 1); 847 | op5 = make_dx7_op(4, 0, 1); 848 | op4 = make_dx7_op(3, _, 0); 849 | op3 = make_dx7_op(2, 0, 1); 850 | op2 = make_dx7_op(1, _, 0); 851 | op1 = make_dx7_op(0, 0, 0); 852 | }; 853 | 854 | dx7_algo(27) = op1,(op3~*(feedback) : op2),(op5,op6 :> op4) :> _ 855 | with { 856 | op6 = make_dx7_op(5, 0, 1); 857 | op5 = make_dx7_op(4, 0, 1); 858 | op4 = make_dx7_op(3, _, 0); 859 | op3 = make_dx7_op(2, _, 1); 860 | op2 = make_dx7_op(1, _, 0); 861 | op1 = make_dx7_op(0, 0, 0); 862 | }; 863 | 864 | dx7_algo(28) = (op2 : op1),(op5~*(feedback) : op4 : op3),op6 :> _ 865 | with { 866 | op6 = make_dx7_op(5, 0, 0); 867 | op5 = make_dx7_op(4, _, 1); 868 | op4 = make_dx7_op(3, _, 1); 869 | op3 = make_dx7_op(2, _, 0); 870 | op2 = make_dx7_op(1, 0, 1); 871 | op1 = make_dx7_op(0, _, 0); 872 | }; 873 | 874 | dx7_algo(29) = op1,op2,(op4 : op3),(op6~*(feedback) : op5) :> _ 875 | with { 876 | op6 = make_dx7_op(5, _, 1); 877 | op5 = make_dx7_op(4, _, 0); 878 | op4 = make_dx7_op(3, 0, 1); 879 | op3 = make_dx7_op(2, _, 0); 880 | op2 = make_dx7_op(1, 0, 0); 881 | op1 = make_dx7_op(0, 0, 0); 882 | }; 883 | 884 | dx7_algo(30) = op1,op2,(op5~*(feedback) : op4 : op3),op6 :> _ 885 | with { 886 | op6 = make_dx7_op(5, 0, 0); 887 | op5 = make_dx7_op(4, _, 1); 888 | op4 = make_dx7_op(3, _, 1); 889 | op3 = make_dx7_op(2, _, 0); 890 | op2 = make_dx7_op(1, 0, 0); 891 | op1 = make_dx7_op(0, 0, 0); 892 | }; 893 | 894 | dx7_algo(31) = op1,op2,op3,op4,(op6~*(feedback) : op5) :> _ 895 | with { 896 | op6 = make_dx7_op(5, _, 1); 897 | op5 = make_dx7_op(4, _, 0); 898 | op4 = make_dx7_op(3, 0, 0); 899 | op3 = make_dx7_op(2, 0, 0); 900 | op2 = make_dx7_op(1, 0, 0); 901 | op1 = make_dx7_op(0, 0, 0); 902 | }; 903 | 904 | dx7_algo(32) = op1,op2,op3,op4,op5,op6 :> _ 905 | with { 906 | op6 = make_dx7_op(5, 0, 0); 907 | op5 = make_dx7_op(4, 0, 0); 908 | op4 = make_dx7_op(3, 0, 0); 909 | op3 = make_dx7_op(2, 0, 0); 910 | op2 = make_dx7_op(1, 0, 0); 911 | op1 = make_dx7_op(0, 0, 0); 912 | }; 913 | 914 | }; 915 | -------------------------------------------------------------------------------- /download_patches.py: -------------------------------------------------------------------------------- 1 | import os 2 | import requests 3 | import argparse 4 | import zipfile 5 | 6 | 7 | def download_and_unzip(output_directory): 8 | 9 | url = "https://ccrma.stanford.edu/~braun/assets/DX7_AllTheWeb.zip" 10 | 11 | # Ensure the output directory exists 12 | os.makedirs(output_directory, exist_ok=True) 13 | 14 | # Download the zip file 15 | response = requests.get(url) 16 | if response.status_code == 200: 17 | zip_file_path = os.path.join(output_directory, "downloaded.zip") 18 | with open(zip_file_path, "wb") as file: 19 | file.write(response.content) 20 | 21 | # Unzip the file 22 | with zipfile.ZipFile(zip_file_path, "r") as zip_ref: 23 | zip_ref.extractall(output_directory) 24 | 25 | # Clean up the zip file 26 | os.remove(zip_file_path) 27 | 28 | print("Download and unzip completed successfully.") 29 | else: 30 | print(f"Failed to download the file. Status code: {response.status_code}") 31 | 32 | 33 | def main(): 34 | parser = argparse.ArgumentParser(description="Download and unzip a zip file from the internet.") 35 | # parser.add_argument("url", help="URL of the zip file") 36 | parser.add_argument("-o", "--output-directory", default="dx7_patches", help="Output directory for downloaded and extracted files") 37 | args = parser.parse_args() 38 | 39 | download_and_unzip(args.output_directory) 40 | 41 | 42 | if __name__ == "__main__": 43 | main() 44 | -------------------------------------------------------------------------------- /dx7_render.py: -------------------------------------------------------------------------------- 1 | from functools import partial 2 | from pathlib import Path 3 | import timeit 4 | import argparse 5 | import os 6 | import math 7 | 8 | import numpy as np 9 | 10 | import jax.numpy as jnp 11 | import jax 12 | from jax import random 13 | 14 | import flax.linen as nn 15 | 16 | from scipy.io import wavfile 17 | 18 | import pandas as pd 19 | 20 | from tqdm.auto import trange 21 | 22 | from dawdreamer.faust.box import boxFromDSP, boxToSource 23 | from dawdreamer.faust import FaustContext 24 | 25 | 26 | def note_number_to_hz(note_number): 27 | return 440.0 * (2.0 ** ((note_number - 69) / 12.0)) 28 | 29 | 30 | def note_to_tensor(note, gain, note_dur, total_dur): 31 | # Return 2D tensor shaped (3, total_dur) where 32 | # 1st dimension is (freq, gain, gate) 33 | # and 2nd dimension is audio sample 34 | tensor = jnp.zeros((3, total_dur)) 35 | 36 | # set freq and gain 37 | freq = note_number_to_hz(note) 38 | tensor = tensor.at[:2, :].set( 39 | jnp.array([freq, gain]).reshape(2, 1)) 40 | 41 | # set gate 42 | tensor = tensor.at[2, :note_dur].set(jnp.array([1])) 43 | return tensor 44 | 45 | 46 | def transform_k_v(k, v): 47 | if 'Levels/' in k or 'Rates/' in k: 48 | v = jnp.interp(v, jnp.array([0, 99]), jnp.array([-1., 1.])) 49 | elif 'LFO/AMD' in k or 'LFO/PMD' in k or 'LFO/Delay' in k or 'LFO/Speed' in k: 50 | v = jnp.interp(v, jnp.array([0, 99]), jnp.array([-1., 1.])) 51 | elif 'LFO/Pitch Mod Sens' in k: 52 | v = jnp.interp(v, jnp.array([0, 7]), jnp.array([-1., 1.])) 53 | elif 'LFO/Sync' in k: 54 | v = jnp.interp(v, jnp.array([0, 1]), jnp.array([-1., 1.])) 55 | elif 'LFO/Wave' in k: 56 | v = nn.one_hot(v, num_classes=6) 57 | elif 'Feedback' in k: 58 | v = jnp.interp(v, jnp.array([0, 7]), jnp.array([-1., 1.])) 59 | elif 'Osc Key Sync' in k: 60 | v = jnp.interp(v, jnp.array([0, 1]), jnp.array([-1., 1.])) 61 | elif 'Transpose' in k: 62 | v = jnp.interp(v, jnp.array([-24, 24]), jnp.array([-1., 1.])) 63 | 64 | # non global / Operator (1-6) parameters 65 | elif 'AmpModSens' in k: 66 | v = jnp.interp(v, jnp.array([0, 3]), jnp.array([-1., 1.])) 67 | elif 'KeyVelSens' in k: 68 | v = jnp.interp(v, jnp.array([0, 7]), jnp.array([-1., 1.])) 69 | elif 'Other/Level' in k: 70 | v = jnp.interp(v, jnp.array([0, 99]), jnp.array([-1., 1.])) 71 | elif 'Other/Freq Mode' in k: 72 | v = jnp.interp(v, jnp.array([0, 1]), jnp.array([-1., 1.])) 73 | elif 'Other/Rate Scale' in k: 74 | v = jnp.interp(v, jnp.array([0, 7]), jnp.array([-1., 1.])) 75 | 76 | elif 'Break Point/Break Point' in k or 'Break Point/Left Depth' in k or 'Break Point/Right Depth' in k: 77 | v = jnp.interp(v, jnp.array([0, 99]), jnp.array([-1., 1.])) 78 | elif 'Break Point/Left Curve' in k or 'Break Point/Right Curve' in k: 79 | v = nn.one_hot(v, num_classes=4) 80 | 81 | elif 'Tone/Detune' in k: 82 | v = jnp.interp(v, jnp.array([0, 14]), jnp.array([-1., 1.])) 83 | elif 'Tone/Freq Coarse' in k: 84 | v = nn.one_hot(v, num_classes=32) 85 | elif 'Tone/Freq Fine' in k: 86 | v = nn.one_hot(v, num_classes=100) 87 | else: 88 | raise ValueError(f'Unrecognized key {k}') 89 | return v 90 | 91 | 92 | def dx7_render(patches_df, algorithm: int, batch_size: int, sample_rate: int, note: int, note_dur: float, 93 | record_dur: float, do_normalize: bool, output_directory): 94 | 95 | # Note: algorithm is in range [0-31] 96 | 97 | # Note: It is possible to render different algorithms within the same batch. It might make sense to do this 98 | # if you only have a few presets to render, and they use different algorithms. 99 | # We assume we'll render a lot of presets, so we compile a different JAX module for each algorithm. 100 | df = patches_df[patches_df["global/algorithm"] == algorithm] 101 | 102 | df = df.drop(columns=["filename", "name"]) 103 | df = df.drop(columns=["global/algorithm"]) 104 | 105 | if not df.shape[0]: 106 | return 107 | 108 | rename_mapper = { 109 | 'global/lfoAMD': '_DX7/Global/LFO/AMD', 110 | 'global/lfoDelay': '_DX7/Global/LFO/Delay', 111 | 'global/lfoPMD': '_DX7/Global/LFO/PMD', 112 | 'global/lfoPitchModSens': '_DX7/Global/LFO/Pitch Mod Sens', 113 | 'global/lfoSpeed': '_DX7/Global/LFO/Speed', 114 | 'global/lfoSync': '_DX7/Global/LFO/Sync', 115 | 'global/lfoWave': '_DX7/Global/LFO/Wave', 116 | 117 | 'global/algorithm': '_DX7/Global/Main/Algorithm', 118 | 'global/feedback': '_DX7/Global/Main/Feedback', 119 | 'global/oscKeySync': '_DX7/Global/Main/Osc Key Sync', 120 | 'global/transpose': '_DX7/Global/Main/Transpose', 121 | 122 | 'global/pegL1': '_DX7/Global/Pitch Env Generator Levels/L1', 123 | 'global/pegL2': '_DX7/Global/Pitch Env Generator Levels/L2', 124 | 'global/pegL3': '_DX7/Global/Pitch Env Generator Levels/L3', 125 | 'global/pegL4': '_DX7/Global/Pitch Env Generator Levels/L4', 126 | 'global/pegR1': '_DX7/Global/Pitch Env Generator Rates/R1', 127 | 'global/pegR2': '_DX7/Global/Pitch Env Generator Rates/R2', 128 | 'global/pegR3': '_DX7/Global/Pitch Env Generator Rates/R3', 129 | 'global/pegR4': '_DX7/Global/Pitch Env Generator Rates/R4', 130 | } 131 | 132 | for i in range(1, 7): 133 | rename_mapper.update( 134 | { 135 | f'op{i}/egL1': f'_DX7/Operator {i}/Amp Env Generator/Levels/L1', 136 | f'op{i}/egL2': f'_DX7/Operator {i}/Amp Env Generator/Levels/L2', 137 | f'op{i}/egL3': f'_DX7/Operator {i}/Amp Env Generator/Levels/L3', 138 | f'op{i}/egL4': f'_DX7/Operator {i}/Amp Env Generator/Levels/L4', 139 | 140 | f'op{i}/ampModSens': f'_DX7/Operator {i}/Amp Env Generator/Other/AmpModSens', 141 | f'op{i}/touchSensitivity': f'_DX7/Operator {i}/Amp Env Generator/Other/KeyVelSens', 142 | f'op{i}/totalLev': f'_DX7/Operator {i}/Amp Env Generator/Other/Level', 143 | f'op{i}/freqMode': f'_DX7/Operator {i}/Amp Env Generator/Other/Freq Mode', 144 | f'op{i}/rateScaling': f'_DX7/Operator {i}/Amp Env Generator/Other/Rate Scale', 145 | 146 | f'op{i}/egR1': f'_DX7/Operator {i}/Amp Env Generator/Rates/R1', 147 | f'op{i}/egR2': f'_DX7/Operator {i}/Amp Env Generator/Rates/R2', 148 | f'op{i}/egR3': f'_DX7/Operator {i}/Amp Env Generator/Rates/R3', 149 | f'op{i}/egR4': f'_DX7/Operator {i}/Amp Env Generator/Rates/R4', 150 | 151 | f'op{i}/breakPoint': f'_DX7/Operator {i}/Break Point/Break Point', 152 | f'op{i}/leftCurve': f'_DX7/Operator {i}/Break Point/Left Curve', 153 | f'op{i}/leftDepth': f'_DX7/Operator {i}/Break Point/Left Depth', 154 | f'op{i}/rightCurve': f'_DX7/Operator {i}/Break Point/Right Curve', 155 | f'op{i}/rightDepth': f'_DX7/Operator {i}/Break Point/Right Depth', 156 | 157 | f'op{i}/detune': f'_DX7/Operator {i}/Tone/Detune', 158 | f'op{i}/freqCoarse': f'_DX7/Operator {i}/Tone/Freq Coarse', 159 | f'op{i}/freqFine': f'_DX7/Operator {i}/Tone/Freq Fine', 160 | } 161 | ) 162 | 163 | df.rename(columns=rename_mapper, inplace=True) 164 | 165 | # convert from seconds to samples 166 | record_dur = int(sample_rate*record_dur) 167 | note_dur = int(sample_rate*note_dur) 168 | 169 | tensor = note_to_tensor(note, 1, note_dur, record_dur) 170 | tensor = jnp.expand_dims(tensor, axis=0) 171 | 172 | tensor = jnp.tile(tensor, (batch_size, 1, 1)) 173 | 174 | with FaustContext(): 175 | 176 | dsp_content = f""" 177 | custom_dx7 = library("custom_dx7.lib"); 178 | 179 | replace = !,_; 180 | process = ["freq":replace, "gain":replace, "gate":replace -> custom_dx7.dx7_algorithm({algorithm+1})] <: _, _; 181 | """ 182 | 183 | box = boxFromDSP(dsp_content) 184 | 185 | module_name = 'FaustVoice' 186 | jax_code = boxToSource(box, 'jax', module_name, ['-a', 'jax/minimal.py']) 187 | 188 | custom_globals = {} 189 | exec(jax_code, custom_globals) # security risk! 190 | MonoVoice = custom_globals[module_name] 191 | 192 | # split parameters but don't split RNGs (DX7 doesn't use RNGs anyway). 193 | BatchedVoice = nn.vmap(MonoVoice, in_axes=(0, None), variable_axes={'params': 0}, split_rngs={'params': False}) 194 | 195 | batched_model = BatchedVoice(sample_rate=sample_rate) 196 | 197 | # optional shuffle 198 | df = df.sample(frac=1, ignore_index=True) 199 | 200 | # pad df with additional rows to match batch size evenly 201 | assert df.shape[0] 202 | total_presets = df.shape[0] 203 | while df.shape[0] % batch_size != 0: 204 | df = pd.concat([df, df[:batch_size-(total_presets % batch_size)]]) 205 | 206 | jit_inference_fn = jax.jit(batched_model.apply, static_argnums=[2]) 207 | 208 | # timeit_number = 3 209 | # key = random.PRNGKey(0) 210 | # key, subkey = random.split(key) 211 | # params = batched_model.init({'params': subkey}, tensor, DURATION)['params'] 212 | # result = timeit.timeit("jit_inference_fn({'params': params}, tensor, DURATION)", number=timeit_number, 213 | # globals=locals()) / timeit_number 214 | # print(f"Time it: {result:.3f} seconds average.") 215 | 216 | output_directory = Path(output_directory) / f'algo{algorithm+1}' 217 | os.makedirs(output_directory, exist_ok=True) 218 | 219 | num_batches = math.ceil(total_presets/batch_size) 220 | 221 | count = 0 222 | for batch_i in trange(num_batches, desc="Items Loop"): 223 | 224 | params = df[batch_i*batch_size:(batch_i+1)*batch_size].to_dict(orient='list') 225 | params = {k: transform_k_v(k, jnp.array(v)) for k, v in params.items()} 226 | 227 | audio = jit_inference_fn({'params': params}, tensor, record_dur) 228 | audio = np.array(audio) 229 | 230 | for i in range(batch_size): 231 | 232 | if count < total_presets: 233 | 234 | output_audio = audio[i].T 235 | 236 | if do_normalize: 237 | # normalize peak level 238 | output_audio = output_audio / np.abs(output_audio).max() 239 | 240 | output_path = str(output_directory / f"render_{str(count).zfill(5)}.wav") 241 | 242 | wavfile.write(output_path, sample_rate, output_audio) 243 | 244 | count += 1 245 | 246 | 247 | def main(): 248 | 249 | parser = argparse.ArgumentParser(description="Render many presets of a DX7 synthesizer with JAX.") 250 | parser.add_argument("--csv", default="dx7_patches.csv", help="Path to CSV file.") 251 | parser.add_argument("--batch-size", default=32, help="Batch size") 252 | parser.add_argument( "-sr", "--sample-rate", default=44100, help="Sample rate") 253 | parser.add_argument("--note-dur", default=2, help="Note on duration (seconds).") 254 | parser.add_argument("--record-dur", default=3, help="Recording duration (seconds).") 255 | parser.add_argument("--note", default=48, help="MIDI note to play.") 256 | parser.add_argument("--normalize", default=True, action=argparse.BooleanOptionalAction, 257 | help="Toggle for normalizing peak level.") 258 | parser.add_argument('--platform', default='cpu', choices=['cpu', 'gpu']) 259 | parser.add_argument("-o", "--output-directory", default="output_dx7", 260 | help="Output directory for saved files.") 261 | args = parser.parse_args() 262 | 263 | # Global flag to set a specific platform, must be used at startup. 264 | jax.config.update('jax_platform_name', args.platform) 265 | 266 | patches_csv = args.csv 267 | assert os.path.isfile(patches_csv), FileExistsError(f"CSV of patches not found at path: {patches_csv}") 268 | 269 | df = pd.read_csv(patches_csv) 270 | 271 | for algorithm in trange(32, desc="Algorithm"): 272 | 273 | dx7_render(df, algorithm, args.batch_size, args.sample_rate, args.note, args.note_dur, args.record_dur, 274 | args.normalize, args.output_directory) 275 | 276 | print('All done!') 277 | 278 | 279 | if __name__ == "__main__": 280 | 281 | main() 282 | -------------------------------------------------------------------------------- /parse_dx7.py: -------------------------------------------------------------------------------- 1 | import struct 2 | import os.path 3 | import os 4 | import argparse 5 | from pathlib import Path 6 | import pandas as pd 7 | 8 | # References: 9 | 10 | # https://web.archive.org/web/20010605031928/http://www.yamaha.com/ycaservice/pdf/553.pdf 11 | 12 | # DX7s manual is very similar to DX7 13 | # https://homepages.abdn.ac.uk/d.j.benson/pages/dx7/manuals/dx7s-man.pdf 14 | # Go to section 5-4 "Voice Memory Format" page 101/108 15 | 16 | # https://github.com/asb2m10/dexed/blob/master/Documentation/sysex-format.txt 17 | # which is basically right, but I think SCL_LEFT_CURVE and SCL_RIGHT_CURVE are swapped incorrectly 18 | 19 | 20 | def parse0to99(b): 21 | """ 22 | Normalize a 7-bit byte to the 0-99 range, matching Dexed's `normparm` behavior. 23 | """ 24 | b = b & 0b1111111 25 | if b <= 99: 26 | return b 27 | # Dexed maps out-of-range values proportionally: (value/255)*99, then truncated 28 | return int((b / 255.0) * 99) 29 | 30 | 31 | # Structure to store operator-specific parameters 32 | class Dx7Operator: 33 | 34 | def __repr__(self): 35 | return str(self.__dict__) 36 | 37 | def __init__(self, data): 38 | expected_length = 17 39 | if len(data) != expected_length: 40 | raise ValueError(f"Expected {expected_length} bytes of data, but got {len(data)}") 41 | 42 | # Unpack the data, excluding the bitfields for now 43 | op_params = struct.unpack('B' * expected_length, data) 44 | 45 | # Assign the unpacked values to the corresponding class attributes 46 | self.EG_R1 = parse0to99(op_params[0]) 47 | self.EG_R2 = parse0to99(op_params[1]) 48 | self.EG_R3 = parse0to99(op_params[2]) 49 | self.EG_R4 = parse0to99(op_params[3]) 50 | self.EG_L1 = parse0to99(op_params[4]) 51 | self.EG_L2 = parse0to99(op_params[5]) 52 | self.EG_L3 = parse0to99(op_params[6]) 53 | self.EG_L4 = parse0to99(op_params[7]) 54 | self.BREAK_POINT = parse0to99(op_params[8]) 55 | self.LEFT_DEPTH = parse0to99(op_params[9]) 56 | self.RIGHT_DEPTH = parse0to99(op_params[10]) 57 | 58 | # Process the bitfields for SCL_LEFT_CURVE and SCL_RIGHT_CURVE 59 | self.LEFT_CURVE = op_params[11] & 0b11 # (0-3) (-LIN, -EXP, +EXP, +LIN) 60 | self.RIGHT_CURVE = (op_params[11] >> 2) & 0b11 # (0-3) (-LIN, -EXP, +EXP, +LIN) 61 | 62 | # Process the bitfields for OSC_RATE_SCALE and OSC_DETUNE 63 | self.RATE_SCALING = op_params[12] & 0b111 # (0-7) 64 | self.DETUNE = min(14, (op_params[12] >> 3) & 0b1111) # (0-14) 65 | 66 | # Process the bitfields for AMP_MOD_SENS and TOUCH_SENSITIVITY 67 | self.AMP_MOD_SENS = op_params[13] & 0b11 # (0-3) 68 | self.TOUCH_SENSITIVITY = (op_params[13] >> 2) & 0b111 # (0-7) 69 | 70 | # Assign TOTAL_LEV 71 | self.TOTAL_LEV = parse0to99(op_params[14]) 72 | 73 | # Process the bitfields for FREQ_MODE and FREQ_COARSE 74 | self.FREQ_MODE = op_params[15] & 0b1 # (0-1) (ratio, fixed) 75 | self.FREQ_COARSE = (op_params[15] >> 1) & 0b11111 # (0-31) 76 | 77 | # Assign FREQ_FINE 78 | self.FREQ_FINE = parse0to99(op_params[16]) 79 | 80 | 81 | # Structure to store global parameters 82 | class Dx7Global: 83 | 84 | def __repr__(self): 85 | return str(self.__dict__) 86 | 87 | @staticmethod 88 | def format_name(name): 89 | """ 90 | Function to get rid of problematic characters in a string 91 | """ 92 | return ''.join(c for c in name.decode('ascii', 'ignore') if c.isalnum()) 93 | 94 | def __init__(self, data, name_data): 95 | expected_length = 16 96 | if len(data) != expected_length: 97 | raise ValueError(f"Expected {expected_length} bytes of data, but got {len(data)}") 98 | 99 | # Unpack the data, excluding the bitfields for now 100 | global_params = struct.unpack('B' * expected_length, data) 101 | 102 | # Assign the unpacked values to the corresponding class attributes 103 | self.PITCH_EG_R1 = parse0to99(global_params[0]) 104 | self.PITCH_EG_R2 = parse0to99(global_params[1]) 105 | self.PITCH_EG_R3 = parse0to99(global_params[2]) 106 | self.PITCH_EG_R4 = parse0to99(global_params[3]) 107 | self.PITCH_EG_L1 = parse0to99(global_params[4]) 108 | self.PITCH_EG_L2 = parse0to99(global_params[5]) 109 | self.PITCH_EG_L3 = parse0to99(global_params[6]) 110 | self.PITCH_EG_L4 = parse0to99(global_params[7]) 111 | 112 | self.ALGORITHM = global_params[8] & 0b11111 # (0-31) 113 | 114 | self.FEEDBACK = global_params[9] & 0b111 # (0-7) 115 | self.OSC_KEY_SYNC = (global_params[9] >> 3) & 0b1 # (0-1) 116 | 117 | self.LFO_SPEED = parse0to99(global_params[10]) 118 | self.LFO_DELAY = parse0to99(global_params[11]) 119 | self.LF_PT_MOD_DEP = parse0to99(global_params[12]) 120 | self.LF_AM_MOD_DEP = parse0to99(global_params[13]) 121 | 122 | # SYNC is the least significant bit of the 14th byte 123 | self.SYNC = global_params[14] & 0b1 # (0-1) 124 | # WAVE is the next 3 bits of the 14th byte. The 6 options are 125 | # (triangle, saw down, saw up, square, sine, sample&hold) 126 | self.WAVE = min(5, (global_params[14] >> 1) & 0b111) # (0-5) 127 | # LF_PT_MOD_SNS is the most significant 4 bits of the 14th byte 128 | self.LF_PT_MOD_SNS = (global_params[14] >> 4) & 0b111 # (0-7) 129 | 130 | self.TRANSPOSE = min(48, global_params[15] & 0b111111) # (0-48) 131 | 132 | self.NAME = self.format_name(name_data) # note: it may be an empty string 133 | 134 | 135 | def convert_patch(filename, rel_path): 136 | def get_operator_d(i: int, operator: Dx7Operator, name: str): 137 | 138 | return { 139 | f'op{i}/ampModSens': operator.AMP_MOD_SENS, 140 | f'op{i}/egL1': operator.EG_L1, 141 | f'op{i}/egL2': operator.EG_L2, 142 | f'op{i}/egL3': operator.EG_L3, 143 | f'op{i}/egL4': operator.EG_L4, 144 | f'op{i}/egR1': operator.EG_R1, 145 | f'op{i}/egR2': operator.EG_R2, 146 | f'op{i}/egR3': operator.EG_R3, 147 | f'op{i}/egR4': operator.EG_R4, 148 | 149 | f'op{i}/breakPoint': operator.BREAK_POINT, 150 | f'op{i}/leftDepth': operator.LEFT_DEPTH, 151 | f'op{i}/rightDepth': operator.RIGHT_DEPTH, 152 | 153 | f'op{i}/leftCurve': operator.LEFT_CURVE, 154 | f'op{i}/rightCurve': operator.RIGHT_CURVE, 155 | 156 | f'op{i}/touchSensitivity': operator.TOUCH_SENSITIVITY, 157 | f'op{i}/totalLev': operator.TOTAL_LEV, 158 | f'op{i}/detune': operator.DETUNE - 7, # note the minus 7 159 | f'op{i}/freqCoarse': operator.FREQ_COARSE, 160 | f'op{i}/freqFine': operator.FREQ_FINE, 161 | f'op{i}/freqMode': operator.FREQ_MODE, 162 | f'op{i}/rateScaling': operator.RATE_SCALING, 163 | } 164 | 165 | assert os.path.isfile(filename) 166 | 167 | with open(filename, 'rb') as file: 168 | header = file.read(6) 169 | n_voices = 32 # preset file always contain 32 voices 170 | 171 | instruments = [] 172 | 173 | # Parsing presets and converting them into Faust functions 174 | for count in range(n_voices): 175 | # Read operator data for each of the 6 operators 176 | operators_data = [file.read(17) for _ in range(6)] 177 | 178 | # According to the DX7 manual, the operators are stored in reverse order. 179 | operators_data.reverse() 180 | 181 | # Check if any operator data block is shorter than expected 182 | if any(len(data) != 17 for data in operators_data): 183 | # maybe the file doesn't have 32 voices 184 | # todo: show warning 185 | break 186 | 187 | operators = [Dx7Operator(data) for data in operators_data] 188 | 189 | global_params_data = file.read(16) 190 | if len(global_params_data) != 16: 191 | raise ValueError(f"Incomplete global parameters at voice {count + 1}") 192 | 193 | name_data = file.read(10) 194 | global_params = Dx7Global(global_params_data, name_data) 195 | 196 | d = { 197 | 'filename': rel_path, 198 | 'name': global_params.NAME, 199 | 'global/algorithm': global_params.ALGORITHM, # [0-31] 200 | 'global/feedback': global_params.FEEDBACK, 201 | 'global/transpose': global_params.TRANSPOSE - 24, # note the minus 24 202 | 203 | 'global/lfoDelay': global_params.LFO_DELAY, 204 | 'global/lfoPMD': global_params.LF_PT_MOD_DEP, 205 | 'global/lfoAMD': global_params.LF_AM_MOD_DEP, 206 | 'global/lfoSpeed': global_params.LFO_SPEED, 207 | 'global/lfoSync': global_params.SYNC, 208 | 'global/lfoWave': global_params.WAVE, 209 | 'global/lfoPitchModSens': global_params.LF_PT_MOD_SNS, 210 | 211 | 'global/pegR1': global_params.PITCH_EG_R1, 212 | 'global/pegR2': global_params.PITCH_EG_R2, 213 | 'global/pegR3': global_params.PITCH_EG_R3, 214 | 'global/pegR4': global_params.PITCH_EG_R4, 215 | 'global/pegL1': global_params.PITCH_EG_L1, 216 | 'global/pegL2': global_params.PITCH_EG_L2, 217 | 'global/pegL3': global_params.PITCH_EG_L3, 218 | 'global/pegL4': global_params.PITCH_EG_L4, 219 | 220 | 'global/oscKeySync': global_params.OSC_KEY_SYNC, 221 | } 222 | 223 | for i, operator in enumerate(operators): 224 | d.update(get_operator_d(i + 1, operator, global_params.NAME)) 225 | 226 | instruments.append(d) 227 | 228 | return instruments 229 | 230 | 231 | def main(directory, output_path): 232 | 233 | # Check if the given directory exists 234 | if not os.path.isdir(directory): 235 | raise ValueError(f"The directory {directory} does not exist.") 236 | 237 | # List to hold all instrument data 238 | all_instruments_data = [] 239 | 240 | # Traverse the directory and process each .syx file 241 | for root, dirs, files in os.walk(directory): 242 | for file in files: 243 | if file.lower().endswith('.syx'): 244 | syx_file_path = os.path.join(root, file) 245 | rel_path = os.path.relpath(syx_file_path, directory) 246 | 247 | try: 248 | instruments_data = convert_patch(syx_file_path, rel_path) 249 | except ValueError as e: 250 | print(f'Skipped file {syx_file_path}. {e}') 251 | all_instruments_data.extend(instruments_data) 252 | 253 | # Convert the list of dictionaries to a pandas DataFrame 254 | df = pd.DataFrame(all_instruments_data) 255 | print('size before dropping duplicates: ', df.shape[0]) 256 | dedup_columns = list(df.columns) 257 | dedup_columns.remove('filename') 258 | dedup_columns.remove('name') 259 | df = df.drop_duplicates(subset=dedup_columns) 260 | print('size after dropping duplicates: ', df.shape[0]) 261 | # Save the DataFrame to a CSV file 262 | df.to_csv(output_path, index=False) 263 | print(f"Saved data to {output_path}") 264 | 265 | 266 | if __name__ == "__main__": 267 | 268 | parser = argparse.ArgumentParser(description='Turn a directory of Yamaha DX7 .syx files into a CSV.') 269 | parser.add_argument('--directory', default='dx7_patches', type=str, help='Directory of .syx files') 270 | parser.add_argument('-o', '--output', default='dx7_patches.csv', type=str, help='Output CSV path') 271 | 272 | args = parser.parse_args() 273 | 274 | directory = Path(args.directory).absolute() 275 | 276 | main(directory, args.output) 277 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | dawdreamer 2 | flax 3 | pandas 4 | requests 5 | scipy 6 | tqdm --------------------------------------------------------------------------------