├── LICENSE ├── README.md └── lib ├── devices ├── apc_mini.lua ├── apc_mini_mk2.lua ├── deluge.lua ├── generic_device.lua ├── launchpad.lua ├── launchpad_minimk3.lua ├── launchpad_rgb.lua ├── launchpad_x.lua ├── linnstrument.lua ├── livid_block.lua ├── push2.lua └── tenori-on.lua ├── mg_128.lua ├── mg_256.lua ├── midigrid.lua ├── mod.lua ├── modmenu.lua ├── supported_devices.lua ├── tests ├── device_test.lua ├── ghost_in_the_grid.lua ├── led_test.lua └── raw_midi_test.lua └── vgrid.lua /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 | 2 | 3 | # norns midigrid library 4 | 5 | Please see the lines forum for details 6 | 7 | (https://llllllll.co/t/midigrid-use-launchpads-and-other-midi-grid-controllers-with-norns/42336) 8 | and 9 | (https://llllllll.co/t/norns-alternative-grids/26909) 10 | 11 | -------------------------------------------------------------------------------- /lib/devices/apc_mini.lua: -------------------------------------------------------------------------------- 1 | local apcmini = include('midigrid/lib/devices/generic_device') 2 | 3 | apcmini.brightness_map = {0,1,1,1,1,1,1,1,3,3,3,3,5,5,5,5} 4 | 5 | --these are the keys in the apc to the sides of our apc, not necessary for strict grid emulation but handy! 6 | --they are up to down, so 70 is the auxkey to row 1 7 | apcmini.aux = {} 8 | 9 | apcmini.aux.col = { 10 | {'note', 82, 1}, 11 | {'note', 83, 2}, 12 | {'note', 84, 3}, 13 | {'note', 85, 4}, 14 | {'note', 86, 10}, 15 | {'note', 87, 12}, 16 | {'note', 88, 14}, 17 | {'note', 89, 16} 18 | } 19 | --left to right, 52 is aux key to column 1 20 | apcmini.aux.row = { 21 | {'note', 64, 1}, 22 | {'note', 65, 2}, 23 | {'note', 66, 3}, 24 | {'note', 67, 4}, 25 | {'note', 68, 10}, 26 | {'note', 69, 12}, 27 | {'note', 70, 14}, 28 | {'note', 71, 16} 29 | } 30 | 31 | return apcmini 32 | -------------------------------------------------------------------------------- /lib/devices/apc_mini_mk2.lua: -------------------------------------------------------------------------------- 1 | local apcmini = include('midigrid/lib/devices/generic_device') 2 | -- in order to control the brightness of the apc mini mk2 pads the midi messages has to be transmitted over 3 | -- the channels below as per akai's specification documentation 4 | -- this can be modified in line no.95 of the generic_device.lua script, the default is channel 0 which in apc mini mk2 cases will be quite dim 5 | --|Channel |Byte 1 Value |Port |Function 6 | -- 0 90 0 On 10% brightness 7 | -- 1 91 0 On 25% brightness 8 | -- 2 92 0 On 50% brightness 9 | -- 3 93 0 On 65% brightness 10 | -- 4 94 0 On 75% brightness 11 | -- 5 95 0 On 90% brightness 12 | -- 6 96 0 On 100% brightness 13 | -- the brightness map colour scheme is as sames as for launcpad RGB , you can tweak them for your preferences 14 | apcmini.brightness_map = { 15 | 0, 16 | 11, 17 | 100, 18 | 125, 19 | 83, 20 | 117, 21 | 14, 22 | 62, 23 | 99, 24 | 118, 25 | 126, 26 | 97, 27 | 109, 28 | 13, 29 | 12, 30 | 119 31 | } 32 | 33 | --these are the keys in the apc to the sides of our apc, not necessary for strict grid emulation but handy! 34 | --they are up to down, so 112 is the auxkey to row 1 35 | apcmini.aux = {} 36 | 37 | apcmini.aux.col = { 38 | {'note', 112, 0}, 39 | {'note', 113, 0}, 40 | {'note', 114, 0}, 41 | {'note', 115, 0}, 42 | {'note', 116, 0}, 43 | {'note', 117, 0}, 44 | {'note', 118, 0}, 45 | {'note', 119, 0} 46 | } 47 | --left to right, 100 is aux key to column 1 48 | apcmini.aux.row = { 49 | {'note', 100, 0}, 50 | {'note', 101, 0}, 51 | {'note', 102, 0}, 52 | {'note', 103, 0}, 53 | {'note', 104, 0}, 54 | {'note', 105, 0}, 55 | {'note', 106, 0}, 56 | {'note', 107, 0} 57 | } 58 | 59 | return apcmini 60 | -------------------------------------------------------------------------------- /lib/devices/deluge.lua: -------------------------------------------------------------------------------- 1 | local deluge = include('midigrid/lib/devices/generic_device') 2 | 3 | deluge.channel_select = 16 -- channel 1 - 16, picking because it's probably least used 4 | deluge.LED_msg = 0x90 + (deluge.channel_select - 1) -- 1001 (9) is note_on, 1111 (15) is midi channel (1-16) 5 | 6 | deluge.width = 16 7 | deluge.height = 8 8 | 9 | -- mapping velocity (0-127) to LED brightness on deluge side, brightness map needs 16 values 10 | deluge.brightness_map = {0,15,23,31,39,47,55,63,71,79,87,95,103,111,119,126} 11 | 12 | -- 0 is bottom left of deluge main grid, 127 is top right of deluge main grid 13 | -- 0 is C-2, 127 is G8 14 | deluge.grid_notes= { 15 | {112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127}, 16 | { 96, 97, 98, 99,100,101,102,103,104,105,106,107,108,109,110,111}, 17 | { 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95}, 18 | { 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79}, 19 | { 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63}, 20 | { 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47}, 21 | { 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31}, 22 | { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15} 23 | } 24 | 25 | local prevBuffer1 = { 26 | {0,0,0,0,0,0,0,0}, 27 | {0,0,0,0,0,0,0,0}, 28 | {0,0,0,0,0,0,0,0}, 29 | {0,0,0,0,0,0,0,0}, 30 | {0,0,0,0,0,0,0,0}, 31 | {0,0,0,0,0,0,0,0}, 32 | {0,0,0,0,0,0,0,0}, 33 | {0,0,0,0,0,0,0,0}, 34 | } 35 | local prevBuffer2 = { 36 | {0,0,0,0,0,0,0,0}, 37 | {0,0,0,0,0,0,0,0}, 38 | {0,0,0,0,0,0,0,0}, 39 | {0,0,0,0,0,0,0,0}, 40 | {0,0,0,0,0,0,0,0}, 41 | {0,0,0,0,0,0,0,0}, 42 | {0,0,0,0,0,0,0,0}, 43 | {0,0,0,0,0,0,0,0}, 44 | } 45 | 46 | -- from deluge to norns 47 | -- hardcoding midi note_on commands from deluge to midigrid to only work with channel deluge.channel_select 48 | function deluge.event(self,vgrid,event) 49 | 50 | local midi_msg = midi.to_msg(event) 51 | 52 | -- Debug incomming midi messages 53 | -- print(midi_msg.type..midi_msg.cc..midi_msg.val..midi_msg.ch) 54 | 55 | if (midi_msg.type == 'note_on' or midi_msg.type == 'note_off') and (midi_msg.ch == self.channel_select) then 56 | local key = self.note_to_grid_lookup[midi_msg.note] 57 | local key_state = (midi_msg.type == 'note_on') and 1 or 0 58 | if key then 59 | self._key_callback(self.current_quad,key['x'],key['y'],key_state) 60 | else 61 | self:_aux_btn_handler('note',midi_msg.note,key_state) 62 | end 63 | elseif (midi_msg.type == 'cc') then 64 | self:_aux_btn_handler('cc',midi_msg.cc,(midi_msg.val>0) and 1 or 0) 65 | end 66 | end 67 | 68 | -- from norns to deluge 69 | -- using midi cc messages instead of note_on messages 70 | function deluge._update_led(self,x,y,z) 71 | if y < 1 or #self.grid_notes < y or x < 1 or #self.grid_notes[y] < x then 72 | print("_update_led: x="..x.."; y="..y.."; z="..z) 73 | return 74 | end 75 | local vel = self.brightness_map[z+1] 76 | local note = self.grid_notes[y][x] 77 | local midi_msg = {self.LED_msg,note,vel} 78 | if midi.devices[self.midi_id] then midi.devices[self.midi_id]:send(midi_msg) end 79 | end 80 | 81 | -- from norns to deluge 82 | -- mg_128 creates 2 quads of 64, copied from linnstrument.lua 83 | function deluge:refresh(quad) 84 | if quad.id == 1 then 85 | for x = 1,self.width do 86 | for y = 1,self.height do 87 | if x <= 8 then 88 | if self.vgrid.quads[1].buffer[x][y] ~= prevBuffer1[x][y] then 89 | self._update_led(self,x,y,self.vgrid.quads[1].buffer[x][y]) 90 | prevBuffer1[x][y] = self.vgrid.quads[1].buffer[x][y] 91 | end 92 | else 93 | if self.vgrid.quads[2].buffer[x-8][y] ~= prevBuffer2[x-8][y] then 94 | self._update_led(self,x,y,self.vgrid.quads[2].buffer[x-8][y]) 95 | prevBuffer2[x-8][y] = self.vgrid.quads[2].buffer[x-8][y] 96 | end 97 | end 98 | end 99 | end 100 | end 101 | end 102 | 103 | return deluge 104 | -------------------------------------------------------------------------------- /lib/devices/generic_device.lua: -------------------------------------------------------------------------------- 1 | local device={ 2 | --here we have the 'grid' this looks literally like the grid notes as they are mapped on the apc, they can be changed for other devices 3 | --note though, that a call to this table will look backwards, i.e, to get the visual x=1 and y=2, you have to enter midigrid[2][1], not the other way around! 4 | grid_notes= { 5 | {56,57,58,59,60,61,62,63}, 6 | {48,49,50,51,52,53,54,55}, 7 | {40,41,42,43,44,45,46,47}, 8 | {32,33,34,35,36,37,38,39}, 9 | {24,25,26,27,28,29,30,31}, 10 | {16,17,18,19,20,21,22,23}, 11 | { 8, 9,10,11,12,13,14,15}, 12 | { 0, 1, 2, 3, 4, 5, 6, 7} 13 | }, 14 | note_to_grid_lookup = {}, -- Intentionally left empty 15 | width=8, 16 | height=8, 17 | rotate_second_device=true, 18 | 19 | vgrid={}, 20 | midi_id = 1, 21 | refresh_counter = 0, 22 | 23 | -- This MUST contain 15 values that corospond to brightness. these can be strings or tables if you midi send handler requires (e.g. RGB) 24 | brightness_map = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}, 25 | 26 | -- This defines any Aux buttons, it expects at least one row and one column of 8 buttons 27 | -- See launchpad.lua for an example. More than 8 buttons could be used for multple row/cols (i.e. LP Mk3 Pro) 28 | -- Format is { 'cc'/'note', cc or note number, current/default state } 29 | aux = { 30 | col = {}, 31 | row = {} 32 | }, 33 | 34 | -- the currently displayed quad on the device 35 | quad_switching_enabled = true, 36 | current_quad = 1, 37 | -- here we set the buttons to use when switching quads in multi-quad mode 38 | 39 | force_full_refresh = false, 40 | 41 | } 42 | 43 | function device:change_quad(quad) 44 | self.current_quad = quad 45 | self.force_full_refresh = true 46 | end 47 | 48 | function device:_init(vgrid,device_number) 49 | self.vgrid = vgrid 50 | 51 | --if (self.) 52 | 53 | if (device_number == 2 and self.rotate_second_device) then 54 | self:rotate_ccw() 55 | end 56 | 57 | -- Create reverse lookup tables for device 58 | self:create_rev_lookups() 59 | 60 | -- Tabls for aux button handlers 61 | self.aux.row_handlers = {} 62 | self.aux.col_handlers = {} 63 | 64 | self:create_quad_handers(#vgrid.quads) 65 | 66 | -- Reset device 67 | self:_reset() 68 | end 69 | 70 | function device:create_quad_handers(quad_count) 71 | -- Auto create Quad switching handlers 72 | if quad_count > 1 then 73 | for q = 1,quad_count do 74 | self.aux.row_handlers[q] = function(self,val) self:change_quad(q) end 75 | end 76 | end 77 | end 78 | 79 | function device:_reset() 80 | if self.init_device_msg then 81 | midi.devices[self.midi_id]:send(self.init_device_msg) 82 | else 83 | --TODO: Reset all leds on device 84 | end 85 | end 86 | 87 | function device._update_led(self,x,y,z) 88 | if y < 1 or #self.grid_notes < y or x < 1 or #self.grid_notes[y] < x then 89 | print("_update_led: x="..x.."; y="..y.."; z="..z) 90 | return 91 | end 92 | 93 | local vel = self.brightness_map[z+1] 94 | local note = self.grid_notes[y][x] 95 | local midi_msg = {0x90,note,vel} 96 | --TODO: do we accept a few error msg on failed unmount and check device status in :refresh 97 | if midi.devices[self.midi_id] then midi.devices[self.midi_id]:send(midi_msg) end 98 | end 99 | 100 | function device.event(self,vgrid,event) 101 | -- type="note_on", note, vel, ch 102 | -- Note that midi msg already translates note on vel 0 to note off type 103 | local midi_msg = midi.to_msg(event) 104 | 105 | -- Debug incomming midi messages 106 | -- tab.print(midi_msg) 107 | 108 | -- device-dependent. Reject cc "notes" here. 109 | if (midi_msg.type == 'note_on' or midi_msg.type == 'note_off') then 110 | local key = self.note_to_grid_lookup[midi_msg.note] 111 | local key_state = (midi_msg.type == 'note_on') and 1 or 0 112 | if key then 113 | self._key_callback(self.current_quad,key['x'],key['y'],key_state) 114 | else 115 | self:_aux_btn_handler('note',midi_msg.note,key_state) 116 | end 117 | elseif (midi_msg.type == 'cc') then 118 | self:_aux_btn_handler('cc',midi_msg.cc,(midi_msg.val>0) and 1 or 0) 119 | end 120 | end 121 | 122 | device._key_callback = function() print('no vgrid event handle callback attached!') end 123 | 124 | function device:refresh(quad) 125 | if quad.id == self.current_quad then 126 | if self.refresh_counter > 9 then 127 | self.force_full_refresh = true 128 | self.refresh_counter = 0 129 | end 130 | if self.force_full_refresh then 131 | quad.each_with(quad,self,self._update_led) 132 | self.force_full_refresh = false 133 | else 134 | quad.updates_with(quad,self,self._update_led) 135 | self.refresh_counter=self.refresh_counter+1 136 | end 137 | end 138 | self:update_aux() 139 | end 140 | 141 | function device:_aux_btn_handler(type, msg, state) 142 | local aux_event 143 | if type == 'cc' then 144 | aux_event = self.aux.cc_lookup[msg] 145 | else 146 | aux_event = self.aux.note_lookup[msg] 147 | end 148 | 149 | if aux_event and aux_event[1] == 'row' then 150 | device:aux_row_handler(aux_event[2], state) 151 | elseif aux_event and aux_event[1] == 'col' then 152 | device:aux_col_handler(aux_event[2], state) 153 | else 154 | print 'Unrecognised Aux button event' 155 | end 156 | end 157 | 158 | function device:aux_row_led(btn,state) 159 | if (self.aux and self.aux.row and self.aux.row[btn]) then 160 | self.aux.row[btn][3] = state 161 | end 162 | end 163 | 164 | function device:aux_col_led(btn,state) 165 | if (self.aux and self.aux.col and self.aux.col[btn]) then 166 | self.aux.col[btn][3] = state 167 | end 168 | end 169 | 170 | function device:aux_row_handler(btn,val) 171 | if (self.aux and self.aux.row and self.aux.row_handlers and self.aux.row_handlers[btn]) then 172 | self.aux.row_handlers[btn](self,val) 173 | else 174 | print("aux row ", btn) 175 | end 176 | end 177 | 178 | function device:aux_col_handler(btn,val) 179 | if (self.aux and self.aux.col and self.aux.col_handlers and self.aux.col_handlers[btn]) then 180 | self.aux.col_handlers[btn](self,val) 181 | else 182 | print("aux col ", btn) 183 | end 184 | end 185 | 186 | function device:update_quad_btn_aux() 187 | -- TODO would be good to only update on dirty AUX? 188 | if self.vgrid and #self.vgrid.quads > 1 and self.quad_switching_enabled == true then 189 | for q = 1,#self.vgrid.quads do 190 | if self.current_quad == q then z = 15 else z = 2 end 191 | if self.aux.row and #self.aux.row >= 4 then 192 | self.aux.row[q][3] = z 193 | end 194 | end 195 | end 196 | end 197 | 198 | function device:update_aux() 199 | self:update_quad_btn_aux() 200 | -- Light the Aux LEDs 201 | if self.aux.row then 202 | for _,button in pairs(self.aux.row) do 203 | if button[3] == nil then 204 | --ignore handlers! 205 | else 206 | if button[1] == 'cc' then 207 | self:_send_cc(button[2],button[3]+1) 208 | else 209 | self:_send_note(button[2],button[3]+1) 210 | end 211 | end 212 | end 213 | end 214 | if self.aux.col then 215 | 216 | for _,button in pairs(self.aux.col) do 217 | if button[3] == nil then 218 | --ignore handlers! 219 | else 220 | if button[1] == 'cc' then 221 | self:_send_cc(button[2],button[3]+1) 222 | else 223 | self:_send_note(button[2],button[3]+1) 224 | end 225 | end 226 | end 227 | end 228 | end 229 | 230 | function device:_send_note(note,z) 231 | local vel = self.brightness_map[z] 232 | if vel == nil then print("sent nil note") end 233 | local midi_msg = {0x90,note,vel} 234 | if midi.devices[self.midi_id] then midi.devices[self.midi_id]:send(midi_msg) end 235 | end 236 | 237 | function device:_send_cc(cc,z) 238 | local vel = self.brightness_map[z] 239 | if vel == nil then print("sent nil cc") end 240 | local midi_msg = {0xb0,cc,vel} 241 | if midi.devices[self.midi_id] then midi.devices[self.midi_id]:send(midi_msg) end 242 | end 243 | 244 | function device:rotate_ccw() 245 | -- Rotate the grid 246 | local new_grid_notes = {} 247 | local row_offset = #self.grid_notes+1 248 | for col = 1,#self.grid_notes[1] do 249 | new_grid_notes[row_offset-col] = {} 250 | for row = 1,#self.grid_notes do 251 | --print (row_offset-col,',',row,' -- ',row,',',col) 252 | new_grid_notes[row_offset-col][row] = self.grid_notes[row][col] 253 | end 254 | end 255 | self.grid_notes = new_grid_notes 256 | 257 | --Rotate the Aux buttons 258 | --Unpack Quick&Dirty copy 259 | local new_aux_row = {table.unpack(self.aux.col)} 260 | local new_aux_col = {} 261 | 262 | 263 | --Flip the aux column, otherwise it will be upside down 264 | for i=#self.aux.row, 1, -1 do 265 | if self.aux.row[i] == nil then print("no aux row btn #",i) end 266 | new_aux_col[#new_aux_col+1] = { self.aux.row[i][1], self.aux.row[i][2], self.aux.row[i][3] } 267 | end 268 | 269 | --[[Copy the aux column, otherwise it will be upside down 270 | for i=1,#self.aux.col do 271 | if self.aux.col[i] == nil then print("no aux row btn #",i) end 272 | new_aux_row[#new_aux_row+1] = { self.aux.col[i][1], self.aux.col[i][2], self.aux.col[i][3] } 273 | end 274 | ]] 275 | 276 | self.aux.row = new_aux_row 277 | self.aux.col = new_aux_col 278 | end 279 | 280 | function device:create_rev_lookups() 281 | --Create reverse lookup for grid notes 282 | for col = 1,self.height do 283 | for row = 1,self.width do 284 | self.note_to_grid_lookup[self.grid_notes[col][row]] = {x=row,y=col} 285 | end 286 | end 287 | 288 | --Create reverse lookup for aux col and row 289 | if self.aux and self.aux.cc_lookup == nil then self.aux.cc_lookup = {} end 290 | if self.aux and self.aux.note_lookup == nil then self.aux.note_lookup = {} end 291 | if self.aux.row then 292 | for btn_number,btn_meta in ipairs(self.aux.row) do 293 | if btn_meta[1] == 'cc' then 294 | self.aux.cc_lookup[btn_meta[2]] = {'row', btn_number} 295 | else 296 | self.aux.note_lookup[btn_meta[2]] = {'row', btn_number} 297 | end 298 | end 299 | end 300 | if self.aux.col then 301 | for btn_number,btn_meta in ipairs(self.aux.col) do 302 | if btn_meta[1] == 'cc' then 303 | self.aux.cc_lookup[btn_meta[2]] = {'col', btn_number} 304 | else 305 | self.aux.note_lookup[btn_meta[2]] = {'col', btn_number} 306 | end 307 | end 308 | end 309 | end 310 | 311 | return device 312 | -------------------------------------------------------------------------------- /lib/devices/launchpad.lua: -------------------------------------------------------------------------------- 1 | local launchpad = include('midigrid/lib/devices/generic_device') 2 | 3 | launchpad.grid_notes= { 4 | { 0, 1, 2, 3, 4, 5, 6, 7 }, 5 | { 16, 17, 18, 19, 20, 21, 22, 23 }, 6 | { 32, 33, 34, 35, 36, 37, 38, 39 }, 7 | { 48, 49, 50, 51, 52, 53, 54, 55 }, 8 | { 64, 65, 66, 67, 68, 69, 70, 71 }, 9 | { 80, 81, 82, 83, 84, 85, 86, 87 }, 10 | { 96, 97, 98, 99,100,101,102,103 }, 11 | {112,113,114,115,116,117,118,119 } 12 | } 13 | 14 | -- Originally set the grid width to match the 9 columns of the launchpad (right column is A-H aux column) 15 | --launchpad.width = 9 16 | 17 | --[[ Valid Launchpad colours based on bits 0..1 Red, 4..5 Green 18 | id color 19 | 0, 16, 32, 48 - Full Green 20 | 1, 17, 33, 49 21 | 2, 18, 34, 50 22 | 3, 19, 35, 51 - Full Orange 23 | ]]-- 24 | -- Tropical 25 | launchpad.brightness_map = {0,16,16,32,32,48,48,49,49,33,33,50,50,34,51,51} 26 | -- Sunrise 27 | --launchpad.brightness_map = {0,16,16,32,32,48,48,49,49,50,50,33,33,51,2,3} 28 | -- Rainbow 29 | --launchpad.brightness_map = {0, 16, 32, 48, 1, 17, 33, 49, 2, 18, 34, 50, 3, 19, 35, 51} 30 | 31 | -- Reset and set mode to XY 32 | launchpad.init_device_msg = { 0xB0, 0x00, 0x00, 0xB0, 0x00, 0x01 } 33 | 34 | launchpad.aux = {} 35 | -- Format is { 'cc'/'note', cc or note number, current/default state (1-16) } 36 | --top to bottom 37 | launchpad.aux.col = { 38 | {'note', 8, 0}, 39 | {'note', 24, 0}, 40 | {'note', 40, 0}, 41 | {'note', 56, 0}, 42 | {'note', 72, 0}, 43 | {'note', 88, 0}, 44 | {'note', 104, 0}, 45 | {'note', 120, 0} 46 | } 47 | --left to right 48 | launchpad.aux.row = { 49 | {'cc', 104, 0}, 50 | {'cc', 105, 0}, 51 | {'cc', 106, 0}, 52 | {'cc', 107, 0}, 53 | {'cc', 108, 0}, 54 | {'cc', 109, 0}, 55 | {'cc', 110, 0}, 56 | {'cc', 111, 0} 57 | } 58 | 59 | return launchpad -------------------------------------------------------------------------------- /lib/devices/launchpad_minimk3.lua: -------------------------------------------------------------------------------- 1 | local launchpad = include('midigrid/lib/devices/launchpad_rgb') 2 | 3 | --Put the device into programmers mode 4 | launchpad.init_device_msg = { 0xf0,0x0,0x20,0x29,0x02,0x0D,0x00,0x7F,0xf7 } 5 | 6 | launchpad.aux.col = { 7 | {'cc', 89, 0}, 8 | {'cc', 79, 0}, 9 | {'cc', 69, 0}, 10 | {'cc', 59, 0}, 11 | {'cc', 49, 0}, 12 | {'cc', 39, 0}, 13 | {'cc', 29, 0}, 14 | {'cc', 19, 0} 15 | } 16 | 17 | launchpad.aux.row = { 18 | {'cc', 91, 0}, 19 | {'cc', 92, 0}, 20 | {'cc', 93, 0}, 21 | {'cc', 94, 0}, 22 | {'cc', 95, 0}, 23 | {'cc', 96, 0}, 24 | {'cc', 97, 0}, 25 | {'cc', 98, 0} 26 | } 27 | 28 | 29 | return launchpad 30 | -------------------------------------------------------------------------------- /lib/devices/launchpad_rgb.lua: -------------------------------------------------------------------------------- 1 | local launchpad = include('midigrid/lib/devices/generic_device') 2 | 3 | launchpad.grid_notes= { 4 | {81,82,83,84,85,86,87,88}, 5 | {71,72,73,74,75,76,77,78}, 6 | {61,62,63,64,65,66,67,68}, 7 | {51,52,53,54,55,56,57,58}, 8 | {41,42,43,44,45,46,47,48}, 9 | {31,32,33,34,35,36,37,38}, 10 | {21,22,23,24,25,26,27,28}, 11 | {11,12,13,14,15,16,17,18} 12 | } 13 | 14 | launchpad.brightness_map = { 15 | 0, 16 | 11, 17 | 100, 18 | 125, 19 | 83, 20 | 117, 21 | 14, 22 | 62, 23 | 99, 24 | 118, 25 | 126, 26 | 97, 27 | 109, 28 | 13, 29 | 12, 30 | 119 31 | } 32 | 33 | launchpad.aux = {} 34 | 35 | -- Format is { 'cc'/'note', cc or note number, current/default state (1-16) } 36 | --top to bottom 37 | 38 | --these are LP keys to the sides of our grid 39 | --not necessary for strict grid emulation but handy! 40 | --they are up to down, so 89 is the auxkey to row 1 41 | launchpad.aux.col = { 42 | {'note', 89, 0}, 43 | {'note', 79, 0}, 44 | {'note', 69, 0}, 45 | {'note', 59, 0}, 46 | {'note', 49, 0}, 47 | {'note', 39, 0}, 48 | {'note', 29, 0}, 49 | {'note', 19, 0} 50 | } 51 | --left to right, 91 is aux key to column 1 52 | launchpad.aux.row = { 53 | {'cc', 104, 0}, 54 | {'cc', 105, 0}, 55 | {'cc', 106, 0}, 56 | {'cc', 107, 0}, 57 | {'cc', 108, 0}, 58 | {'cc', 109, 0}, 59 | {'cc', 110, 0}, 60 | {'cc', 111, 0} 61 | } 62 | 63 | return launchpad 64 | -------------------------------------------------------------------------------- /lib/devices/launchpad_x.lua: -------------------------------------------------------------------------------- 1 | local launchpad = include('midigrid/lib/devices/launchpad_rgb') 2 | 3 | --Put the device into programmers mode 4 | launchpad.init_device_msg = { 0xf0,0x0,0x20,0x29,0x02,0x0D,0x00,0x7F,0xf7 } 5 | 6 | launchpad.aux.col = { 7 | {'cc', 89, 0}, 8 | {'cc', 79, 0}, 9 | {'cc', 69, 0}, 10 | {'cc', 59, 0}, 11 | {'cc', 49, 0}, 12 | {'cc', 39, 0}, 13 | {'cc', 29, 0}, 14 | {'cc', 19, 0} 15 | } 16 | 17 | launchpad.aux.row = { 18 | {'cc', 91, 0}, 19 | {'cc', 92, 0}, 20 | {'cc', 93, 0}, 21 | {'cc', 94, 0}, 22 | {'cc', 95, 0}, 23 | {'cc', 96, 0}, 24 | {'cc', 97, 0}, 25 | {'cc', 98, 0} 26 | } 27 | 28 | return launchpad 29 | -------------------------------------------------------------------------------- /lib/devices/linnstrument.lua: -------------------------------------------------------------------------------- 1 | -- Linnstrument support file by @nightmachines 2 | -- 2021-05-18 3 | -- 4 | -- Thanks to @jaggednz 5 | 6 | 7 | local prevBuffer1 = { 8 | {0,0,0,0,0,0,0,0}, 9 | {0,0,0,0,0,0,0,0}, 10 | {0,0,0,0,0,0,0,0}, 11 | {0,0,0,0,0,0,0,0}, 12 | {0,0,0,0,0,0,0,0}, 13 | {0,0,0,0,0,0,0,0}, 14 | {0,0,0,0,0,0,0,0}, 15 | {0,0,0,0,0,0,0,0}, 16 | } 17 | local prevBuffer2 = { 18 | {0,0,0,0,0,0,0,0}, 19 | {0,0,0,0,0,0,0,0}, 20 | {0,0,0,0,0,0,0,0}, 21 | {0,0,0,0,0,0,0,0}, 22 | {0,0,0,0,0,0,0,0}, 23 | {0,0,0,0,0,0,0,0}, 24 | {0,0,0,0,0,0,0,0}, 25 | {0,0,0,0,0,0,0,0}, 26 | } 27 | 28 | local device={ 29 | 30 | width=16, 31 | height=8, 32 | 33 | vgrid={}, 34 | midi_id = 1, 35 | refresh_counter = 0, 36 | 37 | brightness_map = {7,1,1,9,9,9,2,2,2,10,10,10,4,4,4,8}, 38 | -- 0=as set in Note Lights settings, 1=red, 2=yellow, 3=green, 4=cyan, 5=blue, 6=magenta, 7=OFF, 8=white, 9= orange, 10=lime and 11=pink 39 | 40 | 41 | init_device_msg = { 0x63, 0x01, 0x62, 0x75, 0x06, 0x00, 0x26, 0x00, 0x65, 0x7f, 0x64, 0x7f, -- send NPRN 245 value 0 to set Linnstrument to normal mode to clear LEDs afterwards 42 | 0x63, 0x01, 0x62, 0x75, 0x06, 0x00, 0x26, 0x01, 0x65, 0x7f, 0x64, 0x7f } , -- send NPRN 245 value 1 to set Linnstrument to user firmware mode, clearing all LEDs 43 | 44 | current_quad = 1, 45 | 46 | } 47 | 48 | function device:_init(vgrid,device_number) 49 | self.vgrid = vgrid 50 | self:_reset() 51 | end 52 | 53 | 54 | function device:_reset() 55 | if self.init_device_msg then 56 | midi.devices[self.midi_id]:send(self.init_device_msg) 57 | -- midi.devices[self.midi_id]:cc(99,1,1) -- NRPN most significant byte 58 | -- midi.devices[self.midi_id]:cc(98,117,1) -- NRPN least significant byte 59 | -- midi.devices[self.midi_id]:cc(6,0,1) -- 0 not used 60 | -- midi.devices[self.midi_id]:cc(38,1,1) -- 1 = enable user firmware mode 61 | -- midi.devices[self.midi_id]:cc(101,127,1) --reset 62 | -- midi.devices[self.midi_id]:cc(100,127,1) --reset 63 | print("msg") 64 | else 65 | 66 | end 67 | end 68 | 69 | function device._update_led(self,x,y,z) 70 | if midi.devices[self.midi_id] then 71 | midi.devices[self.midi_id]:cc(20,x,1) -- row 72 | midi.devices[self.midi_id]:cc(21,9-y-1,1) -- col 73 | midi.devices[self.midi_id]:cc(22,self.brightness_map[z+1],1) -- brightness 74 | end 75 | end 76 | 77 | function device.event(self,vgrid,event) 78 | 79 | local midi_msg = midi.to_msg(event) 80 | 81 | -- Debug incomming midi messages 82 | --print(midi_msg.type..midi_msg.cc..midi_msg.val..midi_msg.ch) 83 | 84 | if (midi_msg.type == 'note_on' or midi_msg.type == 'note_off') then 85 | local state = (midi_msg.type == 'note_on') and 1 or 0 86 | local x = midi_msg.note 87 | local y = midi_msg.ch 88 | if key then 89 | self._key_callback(self.current_quad,x,9-y,state) 90 | end 91 | end 92 | end 93 | 94 | 95 | 96 | device._key_callback = function() print('no vgrid event handle callback attached!') end 97 | 98 | 99 | 100 | 101 | function device:refresh(quad) 102 | if quad.id == 1 then 103 | for x = 1,self.width do 104 | for y = 1,self.height do 105 | if x <= 8 then 106 | if self.vgrid.quads[1].buffer[x][y] ~= prevBuffer1[x][y] then 107 | self._update_led(self,x,y,self.vgrid.quads[1].buffer[x][y]) 108 | prevBuffer1[x][y] = self.vgrid.quads[1].buffer[x][y] 109 | end 110 | else 111 | if self.vgrid.quads[2].buffer[x-8][y] ~= prevBuffer2[x-8][y] then 112 | self._update_led(self,x,y,self.vgrid.quads[2].buffer[x-8][y]) 113 | prevBuffer2[x-8][y] = self.vgrid.quads[2].buffer[x-8][y] 114 | end 115 | end 116 | end 117 | end 118 | end 119 | end 120 | 121 | return device 122 | -------------------------------------------------------------------------------- /lib/devices/livid_block.lua: -------------------------------------------------------------------------------- 1 | local block = include('midigrid/lib/devices/generic_device') 2 | 3 | block.grid_notes= { 4 | { 0, 1, 2, 3, 4, 5, 6, 7}, 5 | {16,17,18,19,20,21,22,23}, 6 | {32,33,34,35,36,37,38,39}, 7 | {48,49,50,51,52,53,54,55}, 8 | {64,65,66,67,68,69,70,71}, 9 | {80,81,82,83,84,85,86,87}, 10 | {96,97,98,99,100,101,102,103}, 11 | {112,113,114,115,116,117,118,119} 12 | } 13 | 14 | --block.init_device_msg = { } 15 | 16 | return block -------------------------------------------------------------------------------- /lib/devices/push2.lua: -------------------------------------------------------------------------------- 1 | -- mods on the generic device for Push 2 2 | local push = include('midigrid/lib/devices/generic_device') 3 | 4 | print('loading push') 5 | 6 | -- mapping for Push's main pads 7 | push.grid_notes = { 8 | {92, 93, 94, 95, 96, 97, 98, 99}, 9 | {84, 85, 86, 87, 88, 89, 90, 91}, 10 | {76, 77, 78, 79, 80, 81, 82, 83}, 11 | {68, 69, 70, 71, 72, 73, 74, 75}, 12 | {60, 61, 62, 63, 64, 65, 66, 67}, 13 | {52, 53, 54, 55, 56, 57, 58, 59}, 14 | {44, 45, 46, 47, 48, 49, 50, 51}, 15 | {36, 37, 38, 39, 40, 41, 42, 43} 16 | } 17 | 18 | -- probably want to change these as I've not thought to much about them at this point :-) 19 | push.brightness_map = {0,11,11,9,9,9,13,13,51,51,51,49,49,59,59,57} 20 | push.rotate_second_device = false 21 | 22 | push.aux = {} 23 | -- Format is { 'cc'/'note', cc or note number, current/default state (1-16) } 24 | --top to bottom 25 | push.aux.col = { 26 | {'cc', 43, 0}, 27 | {'cc', 42, 0}, 28 | {'cc', 41, 0}, 29 | {'cc', 40, 0}, 30 | {'cc', 39, 0}, 31 | {'cc', 38, 0}, 32 | {'cc', 37, 0}, 33 | {'cc', 36, 0} 34 | } 35 | --left to right 36 | push.aux.row = { 37 | {'cc', 20, 0}, 38 | {'cc', 21, 0}, 39 | {'cc', 22, 0}, 40 | {'cc', 23, 0}, 41 | {'cc', 24, 0}, 42 | {'cc', 25, 0}, 43 | {'cc', 26, 0}, 44 | {'cc', 27, 0}, 45 | {'cc', 44, 0}, -- Left arrow 46 | {'cc', 45, 0}, -- Right arrow 47 | {'cc', 46, 0}, -- Up arrow 48 | {'cc', 47, 0}, -- Down arrow 49 | 50 | } 51 | 52 | function push:create_quad_handers(quad_count) 53 | -- Auto create Quad switching handlers attached to left and right arrow buttons 54 | if quad_count > 1 then 55 | for q = 1,quad_count do 56 | self.aux.row_handlers[q+8] = function(self,val) self:change_quad(q) end 57 | end 58 | end 59 | end 60 | 61 | return push 62 | -------------------------------------------------------------------------------- /lib/devices/tenori-on.lua: -------------------------------------------------------------------------------- 1 | -- Tenori-ON support for Norns midigrid 2 | -- Requires pika.blue Tenori-ON firmware A042 (https://pika.blue) 3 | -- which introduces a new "Grid" layer mode on Tenori-ON 4 | 5 | local tenori_on = include('midigrid/lib/devices/generic_device') 6 | 7 | tenori_on.width=16 8 | tenori_on.height=16 9 | 10 | tenori_on.grid_layer_configured=0 11 | 12 | tenori_on.grid_notes= { 13 | {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, 14 | {16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31}, 15 | {32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47}, 16 | {48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63}, 17 | {64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79}, 18 | {80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95}, 19 | {96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111}, 20 | {112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127}, 21 | {128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143}, 22 | {144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159}, 23 | {160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175}, 24 | {176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191}, 25 | {192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207}, 26 | {208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223}, 27 | {224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239}, 28 | {240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255}, 29 | } 30 | 31 | 32 | local prevBuffer1 = { 33 | {0,0,0,0,0,0,0,0}, 34 | {0,0,0,0,0,0,0,0}, 35 | {0,0,0,0,0,0,0,0}, 36 | {0,0,0,0,0,0,0,0}, 37 | {0,0,0,0,0,0,0,0}, 38 | {0,0,0,0,0,0,0,0}, 39 | {0,0,0,0,0,0,0,0}, 40 | {0,0,0,0,0,0,0,0}, 41 | } 42 | local prevBuffer2 = { 43 | {0,0,0,0,0,0,0,0}, 44 | {0,0,0,0,0,0,0,0}, 45 | {0,0,0,0,0,0,0,0}, 46 | {0,0,0,0,0,0,0,0}, 47 | {0,0,0,0,0,0,0,0}, 48 | {0,0,0,0,0,0,0,0}, 49 | {0,0,0,0,0,0,0,0}, 50 | {0,0,0,0,0,0,0,0}, 51 | } 52 | local prevBuffer3 = { 53 | {0,0,0,0,0,0,0,0}, 54 | {0,0,0,0,0,0,0,0}, 55 | {0,0,0,0,0,0,0,0}, 56 | {0,0,0,0,0,0,0,0}, 57 | {0,0,0,0,0,0,0,0}, 58 | {0,0,0,0,0,0,0,0}, 59 | {0,0,0,0,0,0,0,0}, 60 | {0,0,0,0,0,0,0,0}, 61 | } 62 | local prevBuffer4 = { 63 | {0,0,0,0,0,0,0,0}, 64 | {0,0,0,0,0,0,0,0}, 65 | {0,0,0,0,0,0,0,0}, 66 | {0,0,0,0,0,0,0,0}, 67 | {0,0,0,0,0,0,0,0}, 68 | {0,0,0,0,0,0,0,0}, 69 | {0,0,0,0,0,0,0,0}, 70 | {0,0,0,0,0,0,0,0}, 71 | } 72 | 73 | tenori_on.brightness_map = {0,40,40,40,40,40,80,80,80,80,120,120,120,120,120,120} 74 | 75 | tenori_on.init_device_msg = { 0xB0, 0x55, 0x47 } 76 | 77 | 78 | function tenori_on._update_led(self,x,y,z) 79 | if (self.grid_layer_configured == 0) then 80 | if midi.devices[self.midi_id] then 81 | print("midigrid/lib/devices/tenori-on.lua sending Tenori-ON init message until it responds") 82 | midi.devices[self.midi_id]:send(tenori_on.init_device_msg) 83 | end 84 | return 85 | end 86 | 87 | if y < 1 or #self.grid_notes < y or x < 1 or #self.grid_notes[y] < x then 88 | return 89 | end 90 | 91 | local vel = self.brightness_map[z+1] 92 | local note = self.grid_notes[y][x] 93 | 94 | if note < 128 then 95 | local midi_msg = {0x90,note,vel} 96 | if midi.devices[self.midi_id] then midi.devices[self.midi_id]:send(midi_msg) end 97 | else 98 | local midi_msg = {0xA0, note-128,vel} 99 | if midi.devices[self.midi_id] then midi.devices[self.midi_id]:send(midi_msg) end 100 | end 101 | --TODO: do we accept a few error msg on failed unmount and check device status in :refresh 102 | 103 | end 104 | 105 | function tenori_on.event(self,vgrid,event) 106 | -- type="note_on", note, vel, ch 107 | -- Note that midi msg already translates note on vel 0 to note off type 108 | local midi_msg = midi.to_msg(event) 109 | 110 | if (midi_msg.type == 'note_on' or midi_msg.type == 'note_off') then 111 | print("tenori_on.event: midi_msg.type="..midi_msg.type.."; midi_msg.note="..midi_msg.note) 112 | local key = self.note_to_grid_lookup[midi_msg.note] 113 | local key_state = (midi_msg.type == 'note_on') and 1 or 0 114 | if key then 115 | self._key_callback(self.current_quad,key['x'],key['y'],key_state) 116 | else 117 | self:_aux_btn_handler('note',midi_msg.note,key_state) 118 | end 119 | elseif (midi_msg.type =='key_pressure') then 120 | print("tenori_on.event: key_pressure midi_msg.val="..midi_msg.val.."; midi_msg.note="..midi_msg.note) 121 | local key = self.note_to_grid_lookup[midi_msg.note + 128] 122 | local key_state = (midi_msg.val >0 ) and 1 or 0 123 | if key then 124 | self._key_callback(self.current_quad,key['x'],key['y'],key_state) 125 | else 126 | self:_aux_btn_handler('note',midi_msg.note,key_state) 127 | end 128 | 129 | elseif (midi_msg.type == 'cc') then 130 | if ((event[1] == 0xB0) and (event[2] == 0x55)) then 131 | 132 | if (event[3] == 0x23) then 133 | self.grid_layer_configured = 1 134 | end 135 | if (event[3] == 0x20) or (event[3] == 0x21) or (event[3] == 0x22) then 136 | self.grid_layer_configured = 0 137 | end 138 | 139 | if (event[3] == 0x16) then 140 | key(1, 1) 141 | end 142 | if (event[3] == 0x06) then 143 | key(1, 0) 144 | end 145 | if (event[3] == 0x17) then 146 | key(2, 1) 147 | end 148 | if (event[3] == 0x07) then 149 | key(2, 0) 150 | end 151 | if (event[3] == 0x18) then 152 | key(3, 1) 153 | end 154 | if (event[3] == 0x08) then 155 | key(3, 0) 156 | end 157 | if (event[3] == 0x14) then 158 | self._clear_all_buffers() 159 | end 160 | 161 | end 162 | end 163 | end 164 | 165 | function dumpTable(tbl, indent) 166 | indent = indent or 0 167 | for k, v in pairs(tbl) do 168 | print(string.rep(" ", indent) .. tostring(k) .. ":") 169 | if type(v) == "table" then 170 | dumpTable(v, indent + 2) 171 | else 172 | print(string.rep(" ", indent + 2) .. tostring(v)) 173 | end 174 | end 175 | end 176 | 177 | 178 | tenori_on.aux = {} 179 | 180 | function tenori_on:_clear_all_buffers(self) 181 | print("Clearing all buffers") 182 | for x = 1,8 do 183 | for y = 1,8 do 184 | prevBuffer1[x][y] = 0 185 | prevBuffer2[x][y] = 0 186 | prevBuffer3[x][y] = 0 187 | prevBuffer4[x][y] = 0 188 | end 189 | end 190 | end 191 | 192 | 193 | function tenori_on:refresh(quad) 194 | if quad.id == 1 then 195 | for x = 1,self.width do 196 | for y = 1,self.height do 197 | if x <= 8 and y<= 8 then 198 | 199 | if self.vgrid.quads[1].buffer[x][y] ~= prevBuffer1[x][y] then 200 | self._update_led(self,x,y,self.vgrid.quads[1].buffer[x][y]) 201 | prevBuffer1[x][y] = self.vgrid.quads[1].buffer[x][y] 202 | end 203 | 204 | elseif x > 8 and y <= 8 then 205 | 206 | if self.vgrid.quads[2].buffer[x-8][y] ~= prevBuffer2[x-8][y] then 207 | self._update_led(self,x,y,self.vgrid.quads[2].buffer[x-8][y]) 208 | prevBuffer2[x-8][y] = self.vgrid.quads[2].buffer[x-8][y] 209 | end 210 | 211 | elseif x <= 8 and y > 8 then 212 | 213 | if self.vgrid.quads[3].buffer[x][y-8] ~= prevBuffer3[x][y-8] then 214 | self._update_led(self,x,y,self.vgrid.quads[3].buffer[x][y-8]) 215 | prevBuffer3[x][y-8] = self.vgrid.quads[3].buffer[x][y-8] 216 | end 217 | elseif x >8 and y >8 then 218 | 219 | if self.vgrid.quads[4].buffer[x-8][y-8] ~= prevBuffer4[x-8][y-8] then 220 | self._update_led(self,x,y,self.vgrid.quads[4].buffer[x-8][y-8]) 221 | prevBuffer4[x-8][y-8] = self.vgrid.quads[4].buffer[x-8][y-8] 222 | end 223 | 224 | 225 | end 226 | end 227 | end 228 | end 229 | end 230 | 231 | return tenori_on 232 | -------------------------------------------------------------------------------- /lib/mg_128.lua: -------------------------------------------------------------------------------- 1 | -- This is for quick & easy integration and backwards compatibility. 2 | 3 | local grid = include "midigrid/lib/midigrid" 4 | grid:init('128') 5 | return grid -------------------------------------------------------------------------------- /lib/mg_256.lua: -------------------------------------------------------------------------------- 1 | -- This is for quick & easy integration and backwards compatibility. 2 | 3 | -- TODO 256 layout completely UNTESTED 4 | 5 | local grid = include "midigrid/lib/midigrid" 6 | grid:init('256') 7 | return grid -------------------------------------------------------------------------------- /lib/midigrid.lua: -------------------------------------------------------------------------------- 1 | --[[ cheapskate lib for getting midi grid devices to behave like monome grid devices 2 | two things are run before returning, `setup_connect_handling()` and `update_devices()`. 3 | `setup_connect_handling()` copies over 'og' midi "add" and "remove" callbacks, and 4 | provides its own add and remove handlers, i.e. the call backs for: 5 | - `midi.add()` 6 | - `midi.remove()` 7 | - `midi.update_devices()` 8 | `find_midi_device_id()` iterates through `midi.devices` to see if the name matches, then 9 | returns `id`, this system manages its own ids, which is why you have to initialize it and 10 | why first, you connect to it (`midigrid.connect()`), which returns a midigrid object and 11 | does `set_midi_handler()` 12 | ]] 13 | 14 | local vgrid = include('midigrid/lib/vgrid') 15 | local supported_devices = include('midigrid/lib/supported_devices') 16 | 17 | local midigrid = { 18 | is_midigrid = true, 19 | vgrid = vgrid, 20 | device = nil, 21 | 22 | -- If the global 'grid' object contains a 'real_grid' element, then it must 23 | -- have already been replaced by the midigrid mod. Use the mod's 'real_grid' 24 | -- if it exists, and the global 'grid' otherwise. 25 | -- 26 | -- This ensures that 'core_grid' actually points to the underlying grid 27 | -- subsystem. 28 | 29 | core_grid = grid.real_grid or grid, 30 | core_midi_add = nil, 31 | core_midi_remove = nil, 32 | cols = 8, 33 | rows = 8, 34 | key = nil, 35 | } 36 | 37 | function midigrid:init(layout) 38 | self.vgrid:init(layout) 39 | self.cols = self.vgrid.width 40 | self.rows = self.vgrid.height 41 | end 42 | 43 | function midigrid.connect(dummy_id) 44 | --Only instantate midigrid once! 45 | if _ENV.midigrid then return _ENV.midigrid end 46 | 47 | if midigrid.vgrid.layout == nil then 48 | print("Default 64 layout init") 49 | -- User is calling connect without calling init, default to 64 button layout 50 | midigrid:init('64') 51 | end 52 | 53 | local midi_devices = midigrid._find_midigrid_devices() 54 | 55 | -- If no midi devices found 56 | if next(midi_devices) == nil then 57 | print('No supported device found' .. #midi_devices) 58 | 59 | tab.print(midi_devices) 60 | -- Make midigrid transparent if no devices found and return the core grid connect() 61 | return midigrid.core_grid.connect() 62 | end 63 | 64 | local connected_devices = midigrid._load_midi_devices(midi_devices) 65 | 66 | -- Some script check grid.device is not nil to prove a grid is attached 67 | if connected_devices then 68 | midigrid.device = { 69 | id = 999, 70 | cols = midigrid.cols, 71 | rows = midigrid.rows, 72 | -- leaving out 'port' because a dummy value might cause undefined 73 | -- behavior. Better to have an error if some script actually needs to 74 | -- use the port number than to silently do something weird. 75 | name = "midigrid", 76 | serial = 1234567 77 | } 78 | end 79 | 80 | vgrid:attach_devices(connected_devices) 81 | midigrid.setup_connect_handling() 82 | 83 | --Expose midigrid globally 84 | _ENV.midigrid = midigrid 85 | 86 | return midigrid 87 | end 88 | 89 | function vgrid.key(x,y,z) 90 | if midigrid.key then 91 | midigrid.key(x,y,z) 92 | end 93 | end 94 | 95 | --this looks to the supported_devices.lua file and returns a table of supported midi devices currently connected 96 | function midigrid._find_midigrid_devices() 97 | local found_device = nil 98 | local mounted_devices = {} 99 | 100 | print(tab.count(midi.devices)," core midi devices") 101 | print("Scanning for supported midigrid devices:") 102 | for _, dev in pairs(midi.devices) do 103 | found_device = supported_devices.find_midi_device_type(dev) 104 | 105 | if found_device then 106 | print(found_device," -- Supported") 107 | mounted_devices[dev.id] = found_device 108 | else 109 | print(dev.name," -- Not supported") 110 | end 111 | end 112 | 113 | print("mounted_devices") 114 | tab.print(mounted_devices) 115 | 116 | return mounted_devices 117 | end 118 | 119 | function midigrid._load_midi_devices(midi_devs) 120 | local connected_devices = {} 121 | for midi_id,midi_device_type in pairs(midi_devs) do 122 | print("Loading midi device type:" .. midi_device_type .. " on midi port " .. midi_id) 123 | local device = include('midigrid/lib/devices/'..midi_device_type) 124 | device.midi_id = midi_id 125 | connected_devices[midi_id] = device 126 | end 127 | 128 | return connected_devices 129 | end 130 | 131 | function midigrid.setup_connect_handling() 132 | midigrid.core_midi_add = midi.add 133 | midigrid.core_midi_remove = midi.remove 134 | midi.add = midigrid._handle_dev_add 135 | midi.remove = midigrid._handle_dev_remove 136 | end 137 | 138 | function midigrid._handle_dev_add(id, name, dev) 139 | midigrid.core_midi_add(id, name, dev) 140 | -- midigrid.update_devices() 141 | end 142 | 143 | function midigrid._handle_dev_remove(id) 144 | midigrid.core_midi_remove(id) 145 | -- midigrid.update_devices() 146 | end 147 | 148 | function midigrid.update_devices() 149 | --TODO WTF does this do? 150 | midi.update_devices() 151 | end 152 | 153 | -- Grid emulation functions 154 | 155 | function midigrid:rotation(dir) 156 | --TODO Is there a sane way to implement this with multi device? 157 | --TODO impement for single 64 device 158 | end 159 | 160 | function midigrid:all(z) 161 | return self.vgrid:set_all(z) 162 | end 163 | 164 | function midigrid:led(x,y,z) 165 | return self.vgrid:set(x,y,z) 166 | end 167 | 168 | function midigrid:refresh() 169 | return self.vgrid:refresh() 170 | end 171 | 172 | midigrid.name = 'Midi Grid' 173 | midigrid.vports = { } 174 | midigrid.vports[1] = midigrid 175 | 176 | return midigrid 177 | -------------------------------------------------------------------------------- /lib/mod.lua: -------------------------------------------------------------------------------- 1 | -- 2 | -- A mod to enable and disable midigrid, and to configure user preferences such 3 | -- as grid size. 4 | -- 5 | -- The mod is controlled throught the SYSTEM > MODS > MIDIGRID menu, and the 6 | -- configuration is persisted when the user leaves that menu. 7 | -- 8 | -- In order for midigrid to function, the mod must be enabled, and the 9 | -- 'midigrid_active' setting must be set to "on" (as it is by default). This 10 | -- allows the user to enable and disable midigrid without needing to restart 11 | -- norns. However, due to the nature of midigrid, changes will have an effect 12 | -- the next time a script tries to connect to a grid. 13 | -- 14 | 15 | local mod = require 'core/mods' 16 | local script = require 'core/script' 17 | local modmenu = require 'midigrid/lib/modmenu' 18 | 19 | ------------------------------------------------------------------------------- 20 | -- Utilities 21 | ------------------------------------------------------------------------------- 22 | 23 | -- Debug and state persistence utilities: 24 | 25 | local log_prefix = "midigrid" 26 | local data_directory = _path.data .. "midigrid/" 27 | local state_file = data_directory .. "state" 28 | local log_file = data_directory .. "log" 29 | 30 | local function log(s) 31 | print(log_prefix .. ": " .. s) 32 | 33 | -- logging to a file is also possible, for debugging startup/shutdown issues: 34 | 35 | -- local f = io.open(log_file, "a+") 36 | -- if f then 37 | -- f:write(s .. "\n") 38 | -- f:close() 39 | -- end 40 | end 41 | 42 | ------------------------------------------------------------------------------- 43 | -- Mod Menu Support 44 | ------------------------------------------------------------------------------- 45 | 46 | -- The available grid sizes 47 | 48 | local grid_sizes = { "64", "128", "256" } 49 | 50 | -- The state of midigrid as controlled by this mod 51 | 52 | local state = { 53 | midigrid_active = true, -- is midigrid active? 54 | grid_size = 2, -- size of midigrid. default 2 -> grid 128 55 | dirty = false -- has the state been changed since last persisted? 56 | } 57 | 58 | ------------------------------------------------------------------------------- 59 | -- Midigrid Enablement 60 | ------------------------------------------------------------------------------- 61 | 62 | -- midigrid is enabled by substituting a facade 'fake_grid' for the real global 63 | -- 'grid' object. 64 | local fake_grid = { 65 | real_grid = grid 66 | } 67 | 68 | -- A grid has the following public functions: 69 | -- 70 | -- Grid.add (dev) -- static callback when any grid device is added; user 71 | -- scripts can redefine 72 | -- Grid.remove (dev) -- static callback when any grid device is removed; user 73 | -- scripts can redefine 74 | -- Grid.connect (n) -- create device, returns object with handler and send. 75 | -- Grid.cleanup () -- clear handlers. 76 | -- 77 | -- The fake grid substitutes its own 'connect' function and allows the rest to 78 | -- be handled by the real grid. 79 | 80 | setmetatable(fake_grid, {__index = grid}) 81 | 82 | -- We have substitude 'fake_grid' for the real grid, but midigrid doesn't know. 83 | -- So if midigrid has trouble it might fall back on trying to connect to the 84 | -- real grid and end up back here ... entering an infinite loop. 85 | -- 86 | -- This variable allows us to detect and avoid this situation. 87 | 88 | local reentrance_guard = false 89 | 90 | fake_grid.connect = function(idx) 91 | local v = idx and idx or '' 92 | log("'connect(" .. v .. ")' called") 93 | 94 | if idx == nil then 95 | idx = 1 96 | end 97 | 98 | -- For the moment, if midigrid is active we rather rudely provide midigrid no 99 | -- matter what index was requested. 100 | 101 | if not reentrance_guard then 102 | if state.midigrid_active then 103 | log("Connecting to midigrid") 104 | local midigrid = include "midigrid/lib/midigrid" 105 | midigrid:init(grid_sizes[state.grid_size]) 106 | 107 | reentrance_guard = true 108 | local g = midigrid.connect(idx) 109 | reentrance_guard = false 110 | return g 111 | end 112 | else 113 | log("Refusing to re-enter fake_grid.connect") 114 | end 115 | 116 | log("Connecting to real grid @ index " .. idx) 117 | 118 | return fake_grid.real_grid.connect(idx) 119 | end 120 | 121 | -- 122 | -- menu: Use the modmenu module to get a PARAMETERS-style menu for the mod. 123 | -- 124 | 125 | local m = modmenu.new("midigridmenu", mod.this_name:upper()) 126 | 127 | -- Register the mod menu 128 | 129 | mod.menu.register(mod.this_name, m) 130 | 131 | -- Install the parameters to be edited in the mod menu. 132 | 133 | local function init_params() 134 | m.params:add_option("midigrid_active", "midigrid active", 135 | {"on", "off"}, 136 | state.midigrid_active and 1 or 2) 137 | m.params:set_action("midigrid_active", 138 | function(v) 139 | local active = v == 1 and true or false 140 | if state.midigrid_active ~= active then 141 | state.dirty = true 142 | end 143 | state.midigrid_active = active 144 | end) 145 | 146 | m.params:add_option("midigrid_size", "midigrid size", 147 | grid_sizes, 148 | state.grid_size) 149 | m.params:set_action("midigrid_size", 150 | function(v) 151 | if state.grid_size ~= v then 152 | state.dirty = true 153 | end 154 | state.grid_size = v 155 | end) 156 | m.exit_hook = function(m) 157 | if state.dirty then 158 | log("saving midigrid configuration") 159 | 160 | if not util.file_exists(data_directory) then 161 | os.execute("mkdir -p " .. data_directory) 162 | end 163 | 164 | local t, error = tab.save(state, state_file) 165 | 166 | if error then 167 | log("Could not save midigrid configuration: " .. error) 168 | end 169 | end 170 | state.dirty = false 171 | end 172 | end 173 | 174 | -- Setup is done at system startup so that the fake grid is already in place by 175 | -- the time the script code is evaluated. 176 | 177 | mod.hook.register("system_post_startup", "midigrid startup", function() 178 | log("starting up") 179 | 180 | local t, error = tab.load(state_file) 181 | 182 | if not error then 183 | state.midigrid_active = t.midigrid_active 184 | state.grid_size = t.grid_size 185 | state.dirty = false 186 | else 187 | log("Could not load midigrid configuration: " .. error) 188 | end 189 | 190 | init_params() 191 | 192 | grid = fake_grid 193 | 194 | -- I am not sure if this is needed by the mods system. It is not used 195 | -- directly by this mod. 196 | 197 | state.system_post_startup = true 198 | end) 199 | 200 | mod.hook.register("system_pre_shutdown", "midigrid shutdown", function() 201 | -- Note that none of this code is run unless the user chooses SYSTEM>SLEEP 202 | -- from the menu, so this is strictly code for dealiing with powering down 203 | -- the device. 204 | -- 205 | -- That means the code here effectively does nothing. 206 | 207 | -- I am not sure if this is needed by the mods system. It is not used 208 | -- directly by this mod. 209 | 210 | state.system_post_startup = false 211 | 212 | grid = fake_grid.real_grid 213 | 214 | log("shutting down") 215 | end) 216 | 217 | -- This boilerplate is provided by convention. 218 | -- 219 | -- Returning a value from the module allows the mod to provide library 220 | -- functionality to scripts via the normal lua `require` function. 221 | 222 | local api = {} 223 | 224 | api.get_state = function() 225 | return state 226 | end 227 | 228 | return api 229 | -------------------------------------------------------------------------------- /lib/modmenu.lua: -------------------------------------------------------------------------------- 1 | -- A mod menu object that displays and interacts with a paramset in the same 2 | -- way as the user script PARAMETERS page. 3 | -- 4 | -- Code taken directly from 'lua/core/menu/params.lua', choosing only the parts 5 | -- that are relevant to 'm.mode == mEDIT'. 6 | -- 7 | -- Usage: 8 | -- 9 | -- ``` 10 | -- local mod = require 'core/mods' 11 | -- local modmenu = require 'midigrid/lib/modmenu' 12 | -- local my_mod_menu = modmenu.new("my_mod_menu_id", mod.this_name) 13 | -- my_mod_menu.params:add_option(...) 14 | -- ... add more parameters ... 15 | -- mod.menu.register(mod.this_name, my_mod_menu) 16 | -- ``` 17 | -- 18 | -- Now all of the parameters will show up in SYSTEM > MODS > MYMOD and can be 19 | -- navigated and edited in the familiar way. 20 | -- 21 | -- Additionally, the mod can assign an exit handler method to 22 | -- 'my_mod_menu.exit_hook' which will be called whenever the mod menu is 23 | -- exited. The exit handler is used for example in midigrid to persist any 24 | -- changed settings each time the menu is exited. 25 | -- 26 | -- ``` 27 | -- my_mod_menu.exit_hook = function(self) ... end 28 | -- ``` 29 | 30 | local mod = require 'core/mods' 31 | local fileselect = require 'fileselect' 32 | local textentry = require 'textentry' 33 | 34 | -- 'page' and 'm' are display state meaningful only while inside the menu. 35 | -- Since only one menu can be visible at a time, they can be shared among all 36 | -- instances of 'ModMenu'. 37 | 38 | local page = nil 39 | 40 | local m = { 41 | pos = 0, 42 | oldpos = 0, 43 | group = false, 44 | groupid = 0, 45 | alt = false, 46 | dir_prev = nil, 47 | } 48 | 49 | -- 50 | -- Menu navigation and display code from 'lua/core/menu/params.lua'. Functions 51 | -- originally of the form 'm.f(...)' have been changed to 'ModMenu:doF(...)' to 52 | -- allow access to the menu instance's params though 'self'. 53 | -- 54 | 55 | local ModMenu = {} 56 | 57 | local function build_page(params) 58 | page = {} 59 | local i = 1 60 | repeat 61 | if params:visible(i) then 62 | table.insert(page, i) 63 | end 64 | if params:t(i) == params.tGROUP then 65 | i = i + params:get(i) + 1 66 | else 67 | i = i + 1 68 | end 69 | until i > params.count 70 | end 71 | 72 | local function build_sub(sub, params) 73 | page = {} 74 | for i = 1, params:get(sub) do 75 | if params:visible(i + sub) then 76 | table.insert(page, i + sub) 77 | end 78 | end 79 | end 80 | 81 | function ModMenu:doKey(n, z) 82 | if n == 1 and z == 1 then 83 | m.alt = true 84 | elseif n == 1 and z == 0 then 85 | m.alt = false 86 | else 87 | local i = page[m.pos + 1] 88 | local t = self.params:t(i) 89 | if n == 2 and z == 1 then 90 | if m.group == true then 91 | m.group = false 92 | build_page(self.params) 93 | m.pos = m.oldpos 94 | else 95 | mod.menu.exit() 96 | end 97 | elseif n == 3 and z == 1 then 98 | if t == self.params.tGROUP then 99 | build_sub(i, self.params) 100 | m.group = true 101 | m.groupid = i 102 | m.groupname = self.params:string(i) 103 | m.oldpos = m.pos 104 | m.pos = 0 105 | elseif t == self.params.tSEPARATOR then 106 | local n = m.pos + 1 107 | repeat 108 | n = n + 1 109 | if n > #page then 110 | n = 1 111 | end 112 | until self.params:t(page[n]) == self.params.tSEPARATOR 113 | m.pos = n - 1 114 | elseif t == self.params.tFILE then 115 | fileselect.enter(_path.dust, m.newfile) 116 | local fparam = self.params:lookup_param(i) 117 | local dir_prev = fparam.dir or m.dir_prev 118 | if dir_prev ~= nil then 119 | fileselect.pushd(dir_prev) 120 | end 121 | elseif t == self.params.tTEXT then 122 | textentry.enter( 123 | m.newtext, 124 | self.params:get(i), 125 | "PARAM: " .. self.params:get_name(i) 126 | ) 127 | elseif t == self.params.tTRIGGER then 128 | self.params:set(i) 129 | m.triggered[i] = 2 130 | elseif t == self.params.tBINARY then 131 | self.params:delta(i, 1) 132 | if self.params:lookup_param(i).behavior == 'trigger' then 133 | m.triggered[i] = 2 134 | else 135 | m.on[i] = self.params:get(i) 136 | end 137 | else 138 | m.fine = true 139 | end 140 | elseif n == 3 and z == 0 then 141 | m.fine = false 142 | if t == self.params.tBINARY then 143 | self.params:delta(i, 0) 144 | if self.params:lookup_param(i).behavior ~= 'trigger' then 145 | m.on[i] = self.params:get(i) 146 | end 147 | end 148 | end 149 | end 150 | mod.menu.redraw() 151 | end 152 | 153 | ModMenu.newfile = function(file) 154 | if file ~= "cancel" then 155 | self.params:set(page[m.pos + 1], file) 156 | m.dir_prev = file:match("(.*/)") 157 | mod.menu.redraw() 158 | end 159 | end 160 | 161 | ModMenu.newtext = function(txt) 162 | print("SET TEXT: " .. txt) 163 | if txt ~= "cancel" then 164 | self.params:set(page[m.pos + 1], txt) 165 | mod.menu.redraw() 166 | end 167 | end 168 | 169 | function ModMenu:doEnc(n, d) 170 | -- normal scroll 171 | if n == 2 and m.alt == false then 172 | local prev = m.pos 173 | m.pos = util.clamp(m.pos + d, 0, #page - 1) 174 | if m.pos ~= prev then 175 | mod.menu.redraw() 176 | end 177 | 178 | -- jump section 179 | elseif n == 2 and m.alt == true then 180 | d = d > 0 and 1 or -1 181 | local i = m.pos + 1 182 | repeat 183 | i = i + d 184 | if i > #page then 185 | i = 1 186 | end 187 | if i < 1 then 188 | i = #page 189 | end 190 | until self.params:t(page[i]) == self.params.tSEPARATOR or i == 1 191 | m.pos = i - 1 192 | 193 | -- adjust value 194 | elseif n == 3 and self.params.count > 0 then 195 | local dx = m.fine and (d / 20) or d 196 | self.params:delta(page[m.pos + 1], dx) 197 | mod.menu.redraw() 198 | end 199 | 200 | -- tell the menu system to redraw, which in turn calls the mod's menu redraw 201 | -- function 202 | mod.menu.redraw() 203 | end 204 | 205 | function ModMenu:doRedraw() 206 | screen.clear() 207 | 208 | if m.pos == 0 then 209 | local n = self.name 210 | if m.group then 211 | n = n .. " / " .. m.groupname 212 | end 213 | screen.level(4) 214 | screen.move(0, 10) 215 | screen.text(n) 216 | end 217 | 218 | for i = 1, 6 do 219 | if (i > 2 - m.pos) and (i < #page - m.pos + 3) then 220 | if i == 3 then 221 | screen.level(15) 222 | else 223 | screen.level(4) 224 | end 225 | local p = page[i + m.pos - 2] 226 | local t = self.params:t(p) 227 | if t == self.params.tSEPARATOR then 228 | screen.move(0, 10 * i + 2.5) 229 | screen.line_rel(127, 0) 230 | screen.stroke() 231 | screen.move(63, 10 * i) 232 | screen.text_center(self.params:get_name(p)) 233 | elseif t == self.params.tGROUP then 234 | screen.move(0, 10 * i) 235 | screen.text(self.params:get_name(p) .. " >") 236 | else 237 | screen.move(0, 10 * i) 238 | screen.text(self.params:get_name(p)) 239 | screen.move(127, 10 * i) 240 | if t == self.params.tTRIGGER then 241 | if m.triggered[p] and m.triggered[p] > 0 then 242 | screen.rect(124, 10 * i - 4, 3, 3) 243 | screen.fill() 244 | end 245 | elseif t == self.params.tBINARY then 246 | fill = m.on[p] or m.triggered[p] 247 | if fill and fill > 0 then 248 | screen.rect(124, 10 * i - 4, 3, 3) 249 | screen.fill() 250 | end 251 | else 252 | screen.text_right(self.params:string(p)) 253 | end 254 | end 255 | end 256 | end 257 | screen.update() 258 | end 259 | 260 | -- Backup for the timer handler present before init 261 | -- Start it with a callable value. 262 | 263 | local old_timer_handler = function() end 264 | 265 | function ModMenu:doInit() 266 | -- on menu entry, ie, if you wanted to start timers 267 | 268 | if page == nil then 269 | build_page(self.params) 270 | end 271 | m.alt = false 272 | m.fine = false 273 | m.triggered = {} 274 | old_timer_handler = _menu.timer.event 275 | _menu.timer.event = function() 276 | local dirty = false 277 | for k, v in pairs(m.triggered) do 278 | if v > 0 then 279 | m.triggered[k] = v - 1 280 | dirty = true 281 | end 282 | end 283 | if dirty then 284 | mod.menu.redraw() 285 | end 286 | end 287 | m.on = {} 288 | for i, param in ipairs(self.params.params) do 289 | if param.t == self.params.tBINARY then 290 | if self.params:lookup_param(i).behavior == 'trigger' then 291 | m.triggered[i] = 2 292 | else 293 | m.on[i] = self.params:get(i) 294 | end 295 | end 296 | end 297 | _menu.timer.time = 0.2 298 | _menu.timer.count = -1 299 | _menu.timer:start() 300 | end 301 | 302 | function ModMenu:doDeinit() 303 | -- on menu exit 304 | 305 | _menu.timer:stop() 306 | _menu.timer.event = old_timer_handler 307 | 308 | page = nil 309 | 310 | m.pos = 0 311 | m.oldpos = 0 312 | m.group = false 313 | m.groupid = 0 314 | m.alt = false 315 | m.dir_prev = nil 316 | 317 | if self.exit_hook then 318 | self.exit_hook(self) 319 | end 320 | end 321 | 322 | -- Glue code to allow re-use of the menu navigation code in multiple mods. In 323 | -- order to be registered as a mod menu the object has to have non-method 324 | -- functions 'init', 'deinit', 'redraw', 'key' and 'enc'. We re-bind the 'do*' 325 | -- methods to the appropriate functions in 'new'. 326 | 327 | local paramset = require 'core/paramset' 328 | 329 | ModMenu.new = function(id, name) 330 | local this = setmetatable({}, {__index = ModMenu}) 331 | this.key = function(n, z) 332 | return this:doKey(n, z) 333 | end 334 | this.enc = function(n, d) 335 | return this:doEnc(n, d) 336 | end 337 | this.redraw = function() 338 | return this:doRedraw() 339 | end 340 | this.init = function() 341 | return this:doInit() 342 | end 343 | this.deinit = function() 344 | return this:doDeinit() 345 | end 346 | 347 | -- Install a paramset in the object for manipulation by the mod 348 | 349 | this.params = paramset.new(id, name) 350 | this.name = name 351 | 352 | return this 353 | end 354 | 355 | return ModMenu 356 | -------------------------------------------------------------------------------- /lib/supported_devices.lua: -------------------------------------------------------------------------------- 1 | local supported_devices = { 2 | midi_devices = { 3 | 4 | -- Basic midi grid devices 5 | { midi_base_name= 'apc mini', device_type='apc_mini' }, 6 | { midi_base_name= 'apc mini mk2 1', device_type='apc_mini_mk2' }, 7 | { midi_base_name= 'block 1', device_type='livid_block' }, 8 | 9 | -- Novation Launchpads Gen.1 10 | 11 | { midi_base_name= 'launchpad', device_type='launchpad' }, 12 | { midi_base_name= 'launchpad s', device_type='launchpad' }, 13 | { midi_base_name= 'launchpad mini', device_type='launchpad' }, 14 | 15 | -- Novation Launchpads Gen.2 16 | -- 17 | -- LP Mini MK3 presents two MIDI interfaces over USB: 18 | -- launchpad mini mk3 1 - LPMiniMK3 DAW I/O (or first interface): For use 19 | -- by DAWs and similar software to interact with the 20 | -- MK3’s Session mode. 21 | -- launchpad mini mk3 2 - LPMiniMK3 MIDI I/O (or second interface): Used 22 | -- to receive MIDI from Custom modes; and to provide 23 | -- external MIDI input or Light controls in 24 | -- Lighting Custom Modes and Programmer mode. 25 | -- 26 | -- A second LP Mini MK3 displays these device names: 27 | -- launchpad mini mk3 1 2 28 | -- launchpad mini mk3 2 2 29 | -- LP Mini MK3 needs to be put in Programmer mode manually for midigrid use. 30 | { midi_base_name= 'launchpad mk2', device_type='launchpad_rgb' }, 31 | { midi_base_name= 'launchpad mk2 2', device_type='launchpad_rgb' }, 32 | { midi_base_name= 'launchpad mini mk3 2', device_type='launchpad_minimk3' }, 33 | { midi_base_name= 'launchpad mini mk3 2 2', device_type='launchpad_minimk3' }, 34 | { midi_base_name= 'launchpad pro mk3', device_type='launchpad_rgb' }, 35 | { midi_base_name= 'launchpad x 2', device_type='launchpad_x' }, 36 | { midi_base_name= 'launchpad x 2 2', device_type='launchpad_x' }, 37 | { midi_base_name= 'launchpad open 2', device_type='launchpad_x' }, 38 | 39 | -- Ableton Push 2 40 | { midi_base_name= 'ableton push 2 1', device_type='push2' }, 41 | 42 | -- Linnstrument 43 | { midi_base_name= 'linnstrument midi', device_type='linnstrument' }, 44 | 45 | -- Synthstrom Deluge 46 | { midi_base_name = 'deluge 1', device_type='deluge' }, 47 | 48 | } 49 | } 50 | 51 | function supported_devices.find_midi_device_type(midi_device) 52 | --print('finding device: ' .. midi_device.id .. " with name " .. midi_device.name) 53 | local sysex_ident_resp = nil 54 | -- TODO get response to sysex indentify call 55 | 56 | if string.lower(midi_device.name):find 'launchpad mini %d' then 57 | -- Old launchpad mini's have user set hardware ID 1 - 16: 58 | -- e.g. ID 4 appears as midi_device.name "Launchpad Mini 4" 59 | return 'launchpad' 60 | else 61 | for _,device_def in pairs(supported_devices.midi_devices) do 62 | if sysex_ident_resp and device_def.sysex_ident then 63 | --TODO use General Sysex ident call to try and ID device 64 | end 65 | -- Fall back to midi name matching 66 | -- TODO strip / ignore device name suffix for multiple devices 67 | if (device_def.midi_base_name == string.lower(midi_device.name)) then return device_def.device_type end 68 | end 69 | return nil 70 | end 71 | end 72 | 73 | return supported_devices 74 | -------------------------------------------------------------------------------- /lib/tests/device_test.lua: -------------------------------------------------------------------------------- 1 | -- 2 | -- Sorry this script doesn't 3 | -- do anything useful 4 | -- yet... 5 | -- 6 | 7 | local device = include('midigrid/lib/devices/launchpad') 8 | --local device2 = include('midigrid/devices/launchpad') 9 | 10 | --device.midi_id = 2 11 | --device2.midi_id = 1 12 | 13 | device:_reset() 14 | --device2:_reset() 15 | 16 | device:_send_cc(108,4) 17 | device:_send_cc(109,8) 18 | device:_send_cc(110,12) 19 | device:_send_cc(111,16) 20 | 21 | for i = 1,8 do 22 | device:_update_led(i,4,i-1) 23 | --device2:_update_led(i,4,i-1) 24 | end 25 | for i = 1,8 do 26 | device:_update_led(i,5,i+7) 27 | --device2:_update_led(i,5,i+7) 28 | end 29 | 30 | device:_update_led(1,1,15) 31 | --device2:_update_led(2,1,15) 32 | -------------------------------------------------------------------------------- /lib/tests/ghost_in_the_grid.lua: -------------------------------------------------------------------------------- 1 | -- Randomly lights launchpad LED 2 | -- except the first 2 columns 3 | -- 4 | -- Compatible LP mini mk 1 & 2 5 | -- 6 | -- looks for the ghost LEDs 7 | -- 8 | -- (=o 9 | 10 | -- midigrid LED test 11 | -- 12 | -- K3 - Start LED test 13 | -- K2 - Stop LED test 14 | 15 | local grid = include "midigrid/lib/midigrid" 16 | grid:init('128') 17 | local g = grid.connect() 18 | 19 | local grid_metro = metro.init() 20 | 21 | local grid_clock = 0 22 | 23 | local light_pattern = {} 24 | for i = 1,16 do 25 | light_pattern[i] = i-1 26 | end 27 | 28 | grid_metro.event = function() 29 | --print("beat") 30 | local light_level = 0 31 | for x = 1,g.cols do 32 | if x == 1 or x == 9 then 33 | goto continue 34 | end 35 | -- Two rows showing full LED scale 36 | for y = 1,2 do 37 | if x <= 8 then 38 | light_level = x + (y*8)-8 39 | else 40 | light_level = (x-8) + (y*8)-8 41 | end 42 | g:led(x,y,light_pattern[light_level]) 43 | end 44 | -- Rest of the rows scrolling 45 | for y = 3,8 do 46 | light_level = ((x+(y-1)+(grid_clock)) % 16)+1 47 | g:led(x,y,light_pattern[light_level]) 48 | end 49 | 50 | ::continue:: 51 | end 52 | 53 | g:refresh() 54 | 55 | grid_clock = (grid_clock+1) 56 | end 57 | 58 | function init() 59 | print('init') 60 | g:all(0) 61 | g:refresh() 62 | end 63 | 64 | function redraw() 65 | 66 | end 67 | 68 | function key(n, z) 69 | print('key'..n..z) 70 | if n==2 and z==1 then 71 | grid_metro:stop() 72 | g:all(0) 73 | g:refresh() 74 | end 75 | if n==3 and z==1 then 76 | grid_metro:start(0.01) 77 | end 78 | end 79 | 80 | function enc(n, d) 81 | if n==3 then 82 | end 83 | end -------------------------------------------------------------------------------- /lib/tests/led_test.lua: -------------------------------------------------------------------------------- 1 | -- midigrid LED test 2 | -- 3 | -- K3 - Start LED test 4 | -- K2 - Stop LED test 5 | 6 | local grid = include "midigrid/lib/midigrid" 7 | grid:init('128') 8 | local g = grid.connect() 9 | 10 | local grid_metro = metro.init() 11 | 12 | local grid_clock = 0 13 | 14 | local light_pattern = {} 15 | for i = 1,16 do 16 | light_pattern[i] = i-1 17 | end 18 | 19 | grid_metro.event = function() 20 | --print("beat") 21 | local light_level = 0 22 | for x = 1,g.cols do 23 | -- Two rows showing full LED scale 24 | for y = 1,2 do 25 | if x <= 8 then 26 | light_level = x + (y*8)-8 27 | else 28 | light_level = (x-8) + (y*8)-8 29 | end 30 | g:led(x,y,light_pattern[light_level]) 31 | end 32 | -- Rest of the rows scrolling 33 | for y = 3,8 do 34 | light_level = ((x+(y-1)+(grid_clock)) % 16)+1 35 | g:led(x,y,light_pattern[light_level]) 36 | end 37 | end 38 | 39 | g:refresh() 40 | 41 | grid_clock = (grid_clock+1) 42 | end 43 | 44 | function init() 45 | print('init') 46 | g:all(0) 47 | g:refresh() 48 | end 49 | 50 | function redraw() 51 | 52 | end 53 | 54 | function key(n, z) 55 | print('key'..n..z) 56 | if n==2 and z==1 then 57 | grid_metro:stop() 58 | g:all(0) 59 | g:refresh() 60 | end 61 | if n==3 and z==1 then 62 | grid_metro:start(0.06) 63 | end 64 | end 65 | 66 | function enc(n, d) 67 | 68 | end -------------------------------------------------------------------------------- /lib/tests/raw_midi_test.lua: -------------------------------------------------------------------------------- 1 | -- Randomly lights launchpad LED 2 | -- Expects LP on Midi device 1 3 | -- 4 | -- Compatible LP mini mk 1 & 2 5 | -- 6 | -- looks for the ghost LEDs 7 | -- 8 | -- (=o 9 | 10 | local m = midi.connect(1) 11 | m.event = function(data) tab.print(data) end 12 | 13 | local grid_metro = metro.init() 14 | 15 | local brightness = {16,16,32,32,48,48,49,49,33,33,50,50,34,34,51} 16 | 17 | local notes = { 18 | --1, 19 | -- 2, 3, 4, 5, 6, 7, 8 , 20 | --17, 21 | --18, 19, 20, 21, 22, 23, 24, 22 | --33, 23 | 34, 35, 36, 37, 38, 39, 40, 24 | --49, 25 | 50, 51, 52, 53, 54, 55, 56, 26 | --65, 27 | 66, 67, 68, 69, 70, 71, 72, 28 | --81, 29 | 82, 83, 84, 85, 86, 87, 88, 30 | --97, 31 | 98, 99,100,101,102,103, 104, 32 | --113, 33 | 114,115,116,117,118,119,120 34 | } 35 | 36 | grid_metro.event = function() 37 | for n = 1,#notes do 38 | m:note_on(notes[n],brightness[ math.random( #brightness ) ]) 39 | end 40 | end 41 | 42 | 43 | function init() 44 | m:send({ 0xB0, 0x00, 0x00 }) 45 | grid_metro:start(0.01) 46 | end 47 | 48 | function redraw() 49 | 50 | end 51 | 52 | -------------------------------------------------------------------------------- /lib/vgrid.lua: -------------------------------------------------------------------------------- 1 | function create_buffer(width,height) 2 | local new_buffer = {} 3 | 4 | for r = 1,width do 5 | new_buffer[r] = {} 6 | for c = 1,height do 7 | new_buffer[r][c] = 0 8 | end 9 | end 10 | 11 | return new_buffer 12 | end 13 | 14 | local Vgrid = { 15 | layout=nil, 16 | width=8, 17 | height=8, 18 | quads = {}, 19 | devices = {}, 20 | key=nil 21 | } 22 | 23 | function Vgrid:init(layout) 24 | self.layout = layout or '128' 25 | print("vgrid init with layout: ".. self.layout) 26 | if self.layout == '64' then 27 | self.locate_in_layout = function(self,x,y) 28 | if (x > self.width or y > self.height) then 29 | return nil end 30 | return 1 end 31 | self.new_quad(1,8,8,0,0) 32 | 33 | elseif self.layout == '128' or '256' then 34 | self.locate_in_layout = function(self,x,y) 35 | if (x > self.width or y > self.height) then return nil end 36 | if (y <= self.quads[1].height) then 37 | if (x <= self.quads[1].width) then return 1 else return 2 end 38 | end 39 | if (x <= self.quads[1].width) then return 3 else return 4 end 40 | end 41 | 42 | self.new_quad(1,8,8,0,0) 43 | self.new_quad(2,8,8,8,0) 44 | self.width = 16 45 | if layout == '256' then 46 | self.new_quad(3,8,8,0,8) 47 | self.new_quad(4,8,8,8,8) 48 | self.height = 16 49 | end 50 | else 51 | print("ERROR: Unknown layout " .. layout) 52 | end 53 | end 54 | 55 | function Vgrid:attach_devices(compatible_devices) 56 | local device_number 57 | local device_count = tab.count(compatible_devices) 58 | print('Attaching devices:') 59 | for dev_id, dev in pairs(compatible_devices) do 60 | 61 | 62 | -- Yes, Midi grid mounts devices "backwards" 63 | device_number = device_count - tab.count(self.devices) 64 | 65 | -- Assign to quads based on number of currently attached devices 66 | -- e.g. dev1 = quad1, dev2 = quad2, ... 67 | if (device_count > 1) then 68 | dev.current_quad = (device_number % tab.count(self.quads))+1 69 | end 70 | 71 | table.insert(self.devices,dev) 72 | 73 | -- Set call back for real device events to become virtual grid events 74 | midi.devices[dev.midi_id].event = function(e) dev.event(dev,self,e) end 75 | 76 | dev._key_callback = function(dev_quad,dev_x,dev_y,state) 77 | self:_handle_grid_key(dev_quad,dev_x,dev_y,state) 78 | end 79 | 80 | -- Call device init 81 | dev:_init(self,device_number) 82 | end 83 | end 84 | 85 | function Vgrid:_handle_grid_key(quad_id,qx,qy,state) 86 | -- Send device event to quad 87 | --print('q:'..quad_id..' x:'.. qx ..' y:'..qy..' s:'..state) 88 | self.quads[quad_id]:key(qx,qy,state,self.key) 89 | end 90 | 91 | function Vgrid:find_quad(x,y) 92 | local qid = 1 93 | 94 | if self.locate_in_layout then qid = self.locate_in_layout(self,x,y) end 95 | return self.quads[qid] 96 | end 97 | 98 | function Vgrid:set(x,y,z) 99 | local q = self:find_quad(x,y) 100 | if q then 101 | q:_relative_set(x,y,z) 102 | else 103 | print('Coords '..x..', '..y..' (x,y) outside Virtual Grid!') 104 | end 105 | end 106 | 107 | function Vgrid:set_all(z) 108 | for qid = 1, #Vgrid.quads do 109 | q = self.quads[qid] 110 | for x = 1,q.width do 111 | for y = 1,q.height do 112 | q:_set(x,y,z) 113 | end 114 | end 115 | end 116 | end 117 | 118 | function Vgrid:refresh(device_id) 119 | for qid,quad in pairs(self.quads) do 120 | --print('vgrid refresh ' .. qid) 121 | 122 | quad:freeze_updates() 123 | 124 | if device_id then 125 | self.devices[device_id]:refresh(quad) 126 | else 127 | for _,device in pairs(self.devices) do 128 | device:refresh(quad) 129 | end 130 | end 131 | 132 | quad:reset_updates() 133 | end 134 | end 135 | 136 | function Vgrid.new_quad(id,width,height,offset_x,offset_y) 137 | q = { 138 | id=id, 139 | width=width, 140 | height=height, 141 | offset_x=offset_x, 142 | offset_y=offset_y, 143 | buffer = create_buffer(width,height), 144 | updates_x = {}, -- list of changed x values for delta updates 145 | updates_y = {}, -- list of changed y values for delta updates 146 | update_count = 0, 147 | force_full_redraw = false 148 | } 149 | function q:_set(qx,qy,qz) 150 | if (self.buffer[qx][qy] ~= qz) then 151 | self.update_count = self.update_count + 1 152 | table.insert(self.updates_x,qx) 153 | table.insert(self.updates_y,qy) 154 | self.buffer[qx][qy] = qz 155 | end 156 | end 157 | 158 | function q:freeze_updates() 159 | self.frozen_update = { 160 | update_count = self.update_count, 161 | updates_x = self.updates_x, 162 | updates_y = self.updates_y 163 | } 164 | end 165 | 166 | function q:reset_updates() 167 | self.update_count = 0 168 | self.updates_x = {} 169 | self.updates_y = {} 170 | end 171 | 172 | function q:_relative_set(rx,ry,qz) 173 | local qx = rx - self.offset_x 174 | local qy = ry - self.offset_y 175 | 176 | self:_set(qx,qy,qz) 177 | end 178 | 179 | function q:each_with(device,callback) 180 | for x = 1,self.width do 181 | for y = 1,self.height do 182 | callback(device,x,y,self.buffer[x][y]) 183 | end 184 | end 185 | end 186 | 187 | function q:updates_with(device,callback) 188 | if self.frozen_update and self.frozen_update.update_count > 0 then 189 | for u = 1,self.frozen_update.update_count do 190 | local x = self.frozen_update.updates_x[u] 191 | local y = self.frozen_update.updates_y[u] 192 | callback(device,x,y,self.buffer[x][y]) 193 | end 194 | end 195 | end 196 | 197 | function q:key(qx,qy,state,callback) 198 | local rx = qx + self.offset_x 199 | local ry = qy + self.offset_y 200 | callback(rx,ry,state) 201 | end 202 | 203 | table.insert(Vgrid.quads,q) 204 | 205 | return q 206 | end 207 | 208 | return Vgrid 209 | --------------------------------------------------------------------------------