├── LICENSE
├── README.md
├── config
├── apcmini_config.lua
├── launchpad_config.lua
├── launchpadmini_config.lua
├── launchpadmk2_config.lua
└── launchpadpro_config.lua
├── lib
├── core.lua
├── mg_128.lua
├── mg_128_cheat.lua
├── mg_256.lua
└── midigrid.lua
└── notes_todos.org
/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 | A few helper scripts for emulating and using midi grids like a monome grid, on the monome norns.
6 |
7 | Two scripts in the lib folder to include in scripts as 'grid', config files in the config folder for setups with different devices.
8 |
9 |
10 |
11 |
12 | ## instructions
13 | Install by downloading this repo into your dust scripts folder, and calling the library like regular norns libraries, i.e, `include('midigrid/lib/midigrid')`.
14 |
15 | `midigrid.lua` and `device_config.lua` the script should automatically detect which device you are running and use the correct profile
16 | currently supported devices are the launchpad, launchpad mini, launchpad mk2 (RGB), Launchpad Pro and apc mini.
17 | ```
18 | Then, in whatever script you are working in, it works well to override the global grid object with our own local one:
19 | ```lua
20 | --adding this to script to use and 8x8 gird
21 | local grid = include('cheapskate/lib/midigrid')
22 | --or this to use an 8x16 grid
23 | local grid = include('cheapskate/lib/midigrid_2pages')
24 | --which allows this call to work with our midi grid
25 | local g = grid.connect()
26 | ```
27 | Previous issues with the midi device being blocked are resolved with this new implementation taken from ryanlaws [lunchpaid](https://github.com/ryanlaws/lunchpaid).
28 |
29 | If a script expects incoming midi, **you need to set your midi device to a slot other than 1.**
30 |
31 | Finally, each config file has a `device_name` parameter that may need to be adjusted for different versions of launchpad. Check what the name of the device is on norns and adjust accordingly.
32 |
33 |
34 |
35 | ## two page mode
36 |
37 | This script aims to emulate a 128 (16x8) grid by spreading a virtual grid buffer over two grid pages that you can toggle with auxiliary buttons surprisingly this works quite well for the vast majority of scripts if modifier keys are on the second page
38 | having the modifier key held down when switching pages will keep it held down allowing it to be used across both sides of the grid.
39 |
40 |
41 |
42 |
43 | ### apc mini
44 |
45 | By default, the left and right arrow buttons on the bottom row of buttons on the grid
46 |
47 |
48 |
49 |
50 | ### launchpad
51 |
52 | The toggle buttons are the top two column buttons in launchpad auxiliary column. need to set them up so they can be the left and right arrows but this is non trivial as the top auxiliary buttons on the launchpad send control (176) messages not note on.
53 |
54 | ## todos
55 |
56 | ### TODO key aliasing feature, to use auxiliary keys in different ways per script
57 |
58 |
59 | ### TODO add config files for launchpad (and untz maybe)
60 |
61 |
62 |
63 |
64 | ### TODO allow config files to overide led and all functions, for more native launchpad support
65 |
66 |
67 |
68 |
69 | ### DONE add cols and rows function
70 |
71 |
72 |
73 |
74 | ### DONE make page changing more efficient code wise
75 |
76 |
77 |
78 |
79 | ### DONE consider how to make this more sensible with the midi device number thing…
80 |
81 |
82 |
83 |
84 | ## scripts
85 |
86 | Notes for norns scripts that either work or I wanna make work, or need a little love to make work
87 | all have only been tested on the apc mini
88 |
89 |
90 |
91 |
92 | ### step
93 |
94 | works, need to block out midi
95 |
96 |
97 |
98 |
99 | ### strum
100 |
101 | works but with midi blocking
102 |
103 |
104 |
105 |
106 | ### mlr64
107 |
108 | [mlr64](https://github.com/noiserock/custom64)
109 | works!
110 |
111 |
112 |
113 |
114 | ### earthsea for apc mini
115 |
116 | 1. this is pretty much ready to go, use the earthsea from the ash library
117 |
118 | its glitchy and not sure why
119 | working but glitchy?
120 |
121 |
122 |
123 |
124 | ### vials for apc mini
125 |
126 | 1. I think this can be implemented as just split view toggle
127 |
128 | if view2 then {new mapping}
129 |
130 | 2. status
131 |
132 | works pretty great two pages
133 |
134 |
135 |
136 |
137 | ### meadowphysics, this is one to look at
138 |
139 | 1. basic mode is simple, just subtract by half
140 |
141 | 2. Reset, Output, and Speeds
142 |
143 | this just needs a speed interface…
144 | if (config)
145 |
146 | 3. if rules then choose with encoder
147 |
148 |
149 |
150 |
151 | ### strides
152 |
153 | this one should be easy too, the second half of the grid is just pulled up from an alt key
154 |
155 |
156 |
157 |
158 | ### shfts
159 |
160 | a toggle button for the two views
161 |
162 |
163 |
164 |
165 | ### cranes
166 |
167 | this is split in two, but horizontally, so going to need to be a little more sophisticated in the mapping
168 |
169 |
170 |
171 |
172 | ### ekombi
173 |
174 | just make it half as precise
175 |
176 |
177 |
178 |
179 | ### takt
180 |
181 | maybe just a two pager?
182 |
183 |
184 |
185 |
186 | ### foulplay
187 |
188 | only 64 ready to go!
189 |
190 |
191 |
192 |
193 | ### zellen
194 |
195 | good to go with rows and cols, and adjusting led values
196 |
197 |
198 |
199 |
200 | ### isoseq
201 |
202 | just the max pattern length needs to change
203 |
204 |
--------------------------------------------------------------------------------
/config/apcmini_config.lua:
--------------------------------------------------------------------------------
1 | local apcmini={
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= {{56,57,58,59,60,61,62,63},
5 | {48,49,50,51,52,53,54,55},
6 | {40,41,42,43,44,45,46,47},
7 | {32,33,34,35,36,37,38,39},
8 | {24,25,26,27,28,29,30,31},
9 | {16,17,18,19,20,21,22,23},
10 | {8,9,10,11,12,13,14,15},
11 | {0,1,2,3,4,5,6,7}
12 | },
13 | --here, the function expects a brightness_handler val and spits out another val so your midi controller can understand, these values are generally great for apc with most scripts, but will also need to be adjusted for other controllers!
14 | --corresponds here to the 4 available states on apc: 0(off), 1(green) , 3(yellow), 5(red)
15 | brightness_handler = function (val)
16 | if val == 0 then
17 | return 0
18 | elseif (val > 0) and (val < 8) then
19 | return 1
20 | elseif (val > 7) and (val < 12) then
21 | return 3
22 | elseif (val > 11) and (val < 16) then
23 | return 5
24 | else
25 | return 0
26 | end
27 | end,
28 |
29 | -- dummy functions because it doesnt apply to apcmini
30 | all_led_sysex = function(self, color) return end,
31 | led_sysex = function(self, color) return end,
32 |
33 | -- table of device-specific capabilities
34 | caps = {
35 | -- can we use sysex to update the grid leds?
36 | sysex = false,
37 | -- is this an rgb device?
38 | rgb = false,
39 | -- can we double buffer?
40 | lp_double_buffer = false,
41 | -- do the edge buttons send cc?
42 | cc_edge_buttons = false
43 | },
44 | --these are the keys in the apc to the sides of our apc, not necessary for strict grid emulation but handy!
45 | --they are up to down, so 82 is the auxkey to row 1
46 | auxcol = {82,83,84,85,86,87,88,89},
47 | --left to right, 64 is aux key to column 1
48 | auxrow = {64,65,66,67,68,69,70,71},
49 |
50 | -- here we set the buttons to use when switching quads in multi-quad mode
51 | upper_left_quad_button = 64,
52 | upper_right_quad_button = 65,
53 | lower_left_quad_button = 66,
54 | lower_right_quad_button = 67,
55 |
56 | device_name='apc mini'
57 | }
58 |
59 | return apcmini
60 |
--------------------------------------------------------------------------------
/config/launchpad_config.lua:
--------------------------------------------------------------------------------
1 | local launchpad={
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 | { 0, 1, 2, 3, 4, 5, 6, 7},
6 | {16,17,18,19,20,21,22,23},
7 | {32,33,34,35,36,37,38,39},
8 | {48,49,50,51,52,53,54,55},
9 | {64,65,66,67,68,69,70,71},
10 | {80,81,82,83,84,85,86,87},
11 | {96,97,98,99,100,101,102,103},
12 | {112,113,114,115,116,117,118,119}
13 | },
14 | --here, the function expects a brightness_handler val and spits out another val so your midi controller can understand, these values are generally great for apc with most scripts, but will also need to be adjusted for other controllers!
15 | --corresponds here to the launchpad led settings found in the manual
16 | brightness_handler = function (val)
17 | if val == 0 then
18 | return 0
19 | elseif (val > 0) and (val < 3) then --0-2
20 | --low green
21 | return 28
22 | elseif (val > 2) and (val < 6) then --3-5
23 | --full green
24 | return 60
25 | elseif (val > 5) and (val < 8) then --6--7
26 | --full yellow
27 | return 62
28 | elseif (val > 7) and (val < 11) then--8-10
29 | --low amber
30 | return 29
31 | elseif (val > 10) and (val < 13) then--11-12
32 | --full amber
33 | return 63
34 | elseif (val > 12) and (val < 15) then--13-14
35 | --low red
36 | return 13
37 | elseif (val > 14) and (val < 17) then--15-16
38 | --full red
39 | return 15
40 | else
41 | return 0
42 | end
43 | end,
44 |
45 | --these are the keys in the apc to the sides of our apc, not necessary for strict grid emulation but handy!
46 | --they are up to down, so 8 is the auxkey to row 1
47 | auxcol = {8,24,40,56,72,88,104,120},
48 | --need to impletement launchpad row, they are 176 messages instead, which messes stuff up right now
49 | auxrow = {},
50 |
51 | -- table of device-specific capabilities
52 | caps = {
53 | -- can we use sysex to update the grid leds?
54 | -- TODO on the launchpad we could use sysex to fast update all leds at refresh.
55 | -- This would require a custom midigred led and refreash methods as 2 leds are written at once!
56 | sysex = false,
57 | -- is this an rgb device?
58 | rgb = false,
59 | -- can we double buffer?
60 | lp_double_buffer = true,
61 | -- do the edge buttons send cc?
62 | cc_edge_buttons = true
63 | },
64 |
65 | -- here we set the buttons to use when switching quads in multi-quad mode
66 | upper_left_quad_button = 8,
67 | upper_right_quad_button = 24,
68 | lower_left_quad_button = 40,
69 | lower_right_quad_button = 56,
70 |
71 | -- somewhere to keep track of current displayed buffer in double buffer mode
72 | current_double_buffer = 0,
73 |
74 | display_double_buffer_sysex = function(self)
75 | if (self.current_display_buffer == 0) then
76 | self.current_display_buffer = 1
77 | -- Display buffer 1, update buffer 0 (See Appendix Launchpad programmers guide)
78 | return tab.split('0xB0, 0x00, 0x31', ', ')
79 | else
80 | self.current_display_buffer = 0
81 | -- Display buffer 0, update buffer 1 (See Appendix Launchpad programmers guide)
82 | return tab.split('0xB0, 0x00, 0x34', ', ')
83 | end
84 | end,
85 |
86 | device_name='launchpad'
87 | }
88 |
89 | return launchpad
90 |
--------------------------------------------------------------------------------
/config/launchpadmini_config.lua:
--------------------------------------------------------------------------------
1 | local launchpad={
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 | { 0, 1, 2, 3, 4, 5, 6, 7},
6 | {16,17,18,19,20,21,22,23},
7 | {32,33,34,35,36,37,38,39},
8 | {48,49,50,51,52,53,54,55},
9 | {64,65,66,67,68,69,70,71},
10 | {80,81,82,83,84,85,86,87},
11 | {96,97,98,99,100,101,102,103},
12 | {112,113,114,115,116,117,118,119}
13 | },
14 | --here, the function expects a brightness_handler val and spits out another val so your midi controller can understand, these values are generally great for apc with most scripts, but will also need to be adjusted for other controllers!
15 | --corresponds here to the launchpad led settings found in the manual
16 | brightness_handler = function (val)
17 | if val == 0 then
18 | return 0
19 | elseif (val > 0) and (val < 3) then --0-2
20 | --low green
21 | return 28
22 | elseif (val > 2) and (val < 6) then --3-5
23 | --full green
24 | return 60
25 | elseif (val > 5) and (val < 8) then --6--7
26 | --full yellow
27 | return 62
28 | elseif (val > 7) and (val < 11) then--8-10
29 | --low amber
30 | return 29
31 | elseif (val > 10) and (val < 13) then--11-12
32 | --full amber
33 | return 63
34 | elseif (val > 12) and (val < 15) then--13-14
35 | --low red
36 | return 13
37 | elseif (val > 14) and (val < 17) then--15-16
38 | --full red
39 | return 15
40 | else
41 | return 0
42 | end
43 | end,
44 |
45 | --these are the keys in the apc to the sides of our apc, not necessary for strict grid emulation but handy!
46 | --they are up to down, so 8 is the auxkey to row 1
47 | auxcol = {8,24,40,56,72,88,104,120},
48 | --need to impletement launchpad row, they are 176 messages instead, which messes stuff up right now
49 | auxrow = {},
50 |
51 | -- table of device-specific capabilities
52 | caps = {
53 | -- can we use sysex to update the grid leds?
54 | -- TODO on the launchpad we could use sysex to fast update all leds at refresh.
55 | -- This would require a custom midigred led and refreash methods as 2 leds are written at once!
56 | sysex = true,
57 | -- is this an rgb device?
58 | rgb = false,
59 | -- can we double buffer?
60 | lp_double_buffer = true,
61 | -- do the edge buttons send cc?
62 | cc_edge_buttons = true
63 | },
64 |
65 | -- here we set the buttons to use when switching quads in multi-quad mode
66 | upper_left_quad_button = 8,
67 | upper_right_quad_button = 24,
68 | lower_left_quad_button = 40,
69 | lower_right_quad_button = 56,
70 |
71 | -- somewhere to keep track of current displayed buffer in double buffer mode
72 | current_double_buffer = 0,
73 |
74 | display_double_buffer_sysex = function(self)
75 | if (self.current_display_buffer == 0) then
76 | self.current_display_buffer = 1
77 | -- Display buffer 1, update buffer 0 (See Appendix Launchpad programmers guide)
78 | return tab.split('0xB0, 0x00, 0x31', ', ')
79 | else
80 | self.current_display_buffer = 0
81 | -- Display buffer 0, update buffer 1 (See Appendix Launchpad programmers guide)
82 | return tab.split('0xB0, 0x00, 0x34', ', ')
83 | end
84 | end,
85 |
86 | device_name='launchpad mini',
87 |
88 | --[[ this is the column of keys on the sides of the grid, not necessary for strict
89 | grid emulation but handy!
90 | the lp pro round buttons send midi ccs
91 | ]]
92 |
93 | split_string = function(color)
94 | local rgb = {}
95 | -- '([^,]+)' regex for 'group match any number of characters which are not `,`'
96 | for byte in string.gmatch(color, '([^,]+)') do
97 | rgb[#rgb + 1] = byte
98 | end
99 | return rgb[1], rgb[2], rgb[3]
100 | end,
101 |
102 |
103 | led_sysex = function(self, led, color)
104 | local set_led_rgb = '0x0b' -- magic number for "set led rgb"
105 | -- `color` is e.g. 'ff,f2,e6'
106 | local r, g, b = self.split_string(color)
107 | return self.do_sysex(set_led_rgb, led, r, g, b)
108 | end,
109 |
110 |
111 | all_led_sysex = function(self, color)
112 | local set_all_led_rgb = '0x0e' -- magic number for "set ALL leds"
113 | local r, g, b = self.split_string(color)
114 | return self.do_sysex(set_all_led_rgb, r, g, b)
115 | end,
116 |
117 |
118 | do_sysex = function(command, ...)
119 | local var_args = ', '
120 | for i = 1, select("#", ...) do
121 | var_args = var_args .. string.format('%s, ', select(i, ...))
122 | end
123 | local end_sysex = '0xf7'
124 | local sysex_str = string.format('0xf0, 0x00, 0x20, 0x29, 0x02, 0x10, %s%s%s',
125 | command, var_args, end_sysex)
126 | -- print(sysex_str)
127 | local sysex = tab.split(sysex_str, ', ')
128 | return sysex
129 | end
130 | }
131 |
132 | return launchpad
133 |
--------------------------------------------------------------------------------
/config/launchpadmk2_config.lua:
--------------------------------------------------------------------------------
1 | local launchpad = {
2 | -- here we have the 'grid'. this looks literally like the grid notes as they are on
3 | -- the device.
4 | -- note though, that a call to this table will look backwards, i.e, to get the
5 | -- visual x=1 and y=2, you have to enter midigrid[2][1], not the other way around!
6 | grid_notes = {
7 | {81, 82, 83, 84, 85, 86, 87, 88},
8 | {71, 72, 73, 74, 75, 76, 77, 78},
9 | {61, 62, 63, 64, 65, 66, 67, 68},
10 | {51, 52, 53, 54, 55, 56, 57, 58},
11 | {41, 42, 43, 44, 45, 46, 47, 48},
12 | {31, 32, 33, 34, 35, 36, 37, 38},
13 | {21, 22, 23, 24, 25, 26, 27, 28},
14 | {11, 12, 13, 14, 15, 16, 17, 18}
15 | },
16 |
17 |
18 | --[[ values here correspond to the launchpad mk2 led settings found in the programmer's
19 | reference.
20 | HOWEVER, the lp pro can do full rgb, so we'll take andvantage of that. this requires
21 | sending sysex, and lets us use the full 16 brightness levels. we'll use a table of
22 | values directly indexed by the value passed into the fn
23 | NOTE! Individual LED brightnesses only range from 0x0-0x3f (i.e. 0-63); 1/4 the
24 | resolution of what we're used to (i.e. 0x0-0xff or 0-255)
25 | ]]
26 | brightness_handler = function(val)
27 | local less_angry_rainbow = {
28 | '0x00,0x00,0x00',
29 | '0x00,0x09,0x19',
30 | '0x05,0x16,0x2f',
31 | '0x14,0x18,0x34',
32 | '0x08,0x07,0x21',
33 | '0x12,0x07,0x21',
34 | '0x19,0x04,0x22',
35 | '0x29,0x0e,0x2b',
36 | '0x1f,0x00,0x1a',
37 | '0x30,0x04,0x20',
38 | '0x34,0x08,0x19',
39 | '0x3f,0x15,0x1b',
40 | '0x3f,0x19,0x14',
41 | '0x3f,0x20,0x0e',
42 | '0x3c,0x26,0x0b',
43 | '0x37,0x2d,0x0b'
44 | }
45 | return less_angry_rainbow[val + 1]
46 | end,
47 |
48 | --[[ this is the column of keys on the sides of the grid, not necessary for strict
49 | grid emulation but handy!
50 | the lp pro round buttons send midi ccs
51 | ]]
52 | -- top to bottom
53 | -- right side
54 | auxcol = {89, 79, 69, 59, 49, 39, 29, 19},
55 |
56 | -- here we set the buttons to use when switching quads in multi-quad mode
57 | upper_left_quad_button = 89,
58 | upper_right_quad_button = 79,
59 | lower_left_quad_button = 69,
60 | lower_right_quad_button = 59,
61 |
62 | -- table of device-specific capabilities
63 | caps = {
64 | -- can we use sysex to update the grid leds?
65 | sysex = true,
66 | -- is this an rgb device?
67 | rgb = true,
68 | -- can we double buffer?
69 | lp_double_buffer = false,
70 | -- do the edge buttons send cc?
71 | cc_edge_buttons = true
72 | },
73 |
74 |
75 | split_string = function(color)
76 | local rgb = {}
77 | -- '([^,]+)' regex for 'group match any number of characters which are not `,`'
78 | for byte in string.gmatch(color, '([^,]+)') do
79 | rgb[#rgb + 1] = byte
80 | end
81 | return rgb[1], rgb[2], rgb[3]
82 | end,
83 |
84 |
85 | led_sysex = function(self, led, color)
86 | local set_led_rgb = '0x0b' -- magic number for "set led rgb"
87 | -- `color` is e.g. 'ff,f2,e6'
88 | local r, g, b = self.split_string(color)
89 | return self.do_sysex(set_led_rgb, led, r, g, b)
90 | end,
91 |
92 |
93 | all_led_sysex = function(self, color)
94 | local set_all_led_rgb = '0x0e' -- magic number for "set ALL leds"
95 | local r, g, b = self.split_string(color)
96 | return self.do_sysex(set_all_led_rgb, r, g, b)
97 | end,
98 |
99 |
100 | do_sysex = function(command, ...)
101 | local var_args = ', '
102 | for i = 1, select("#", ...) do
103 | var_args = var_args .. string.format('%s, ', select(i, ...))
104 | end
105 | local end_sysex = '0xf7'
106 | local sysex_str = string.format('0xf0, 0x00, 0x20, 0x29, 0x02, 0x10, %s%s%s',
107 | command, var_args, end_sysex)
108 | -- print(sysex_str)
109 | local sysex = tab.split(sysex_str, ', ')
110 | return sysex
111 | end,
112 |
113 | -- For unknown reason(s), allows us to use programmer mode
114 | device_name = 'launchpad mk2'
115 | }
116 |
117 | return launchpad
118 |
--------------------------------------------------------------------------------
/config/launchpadpro_config.lua:
--------------------------------------------------------------------------------
1 | --[[ Launchpad Pro's Programmer ("orange") mode is *required* for this to work.
2 | No other setup should be necessary, on either the LP or the norns/fates side.
3 | ]]
4 |
5 | local launchpad = {
6 | -- here we have the 'grid'. this looks literally like the grid notes as they are on
7 | -- the device.
8 | -- note though, that a call to this table will look backwards, i.e, to get the
9 | -- visual x=1 and y=2, you have to enter midigrid[2][1], not the other way around!
10 | grid_notes = {
11 | {81, 82, 83, 84, 85, 86, 87, 88},
12 | {71, 72, 73, 74, 75, 76, 77, 78},
13 | {61, 62, 63, 64, 65, 66, 67, 68},
14 | {51, 52, 53, 54, 55, 56, 57, 58},
15 | {41, 42, 43, 44, 45, 46, 47, 48},
16 | {31, 32, 33, 34, 35, 36, 37, 38},
17 | {21, 22, 23, 24, 25, 26, 27, 28},
18 | {11, 12, 13, 14, 15, 16, 17, 18}
19 | },
20 |
21 |
22 | --[[ values here correspond to the launchpad pro led settings found in the programmer's
23 | reference.
24 | HOWEVER, the lp pro can do full rgb, so we'll take andvantage of that. this requires
25 | sending sysex, and lets us use the full 16 brightness levels. we'll use a table of
26 | values directly indexed by the value passed into the fn
27 | NOTE! Individual LED brightnesses only range from 0x0-0x3f (i.e. 0-63); 1/4 the
28 | resolution of what we're used to (i.e. 0x0-0xff or 0-255)
29 | ]]
30 | brightness_handler = function(val)
31 | local less_angry_rainbow = {
32 | '0x00,0x00,0x00',
33 | '0x00,0x09,0x19',
34 | '0x05,0x16,0x2f',
35 | '0x14,0x18,0x34',
36 | '0x08,0x07,0x21',
37 | '0x12,0x07,0x21',
38 | '0x19,0x04,0x22',
39 | '0x29,0x0e,0x2b',
40 | '0x1f,0x00,0x1a',
41 | '0x30,0x04,0x20',
42 | '0x34,0x08,0x19',
43 | '0x3f,0x15,0x1b',
44 | '0x3f,0x19,0x14',
45 | '0x3f,0x20,0x0e',
46 | '0x3c,0x26,0x0b',
47 | '0x37,0x2d,0x0b'
48 | }
49 | return less_angry_rainbow[val + 1]
50 | end,
51 |
52 | --[[ this is the column of keys on the sides of the grid, not necessary for strict
53 | grid emulation but handy!
54 | the lp pro round buttons send midi ccs
55 | ]]
56 | -- top to bottom
57 | -- left side
58 | auxcol = {80, 70, 60, 50, 40, 30, 20, 10},
59 | -- right side
60 | auxcol2 = {89, 79, 69, 59, 49, 39, 29, 19},
61 | -- left to right
62 | -- top
63 | auxrow = {91, 92, 93, 94, 95, 96, 97, 98},
64 | -- bottom
65 | auxrow2 = {1, 2, 3, 4, 5, 6, 7, 8},
66 |
67 | -- here we set the buttons to use when switching quads in multi-quad mode
68 | -- we can simply use the cc # as-is
69 | upper_left_quad_button = 91,
70 | upper_right_quad_button = 92,
71 | lower_left_quad_button = 93,
72 | lower_right_quad_button = 94,
73 |
74 | -- table of device-specific capabilities
75 | caps = {
76 | -- can we use sysex to update the grid leds?
77 | sysex = true,
78 | -- is this an rgb device?
79 | rgb = true,
80 | -- can we double buffer?
81 | lp_double_buffer = false,
82 | -- do the edge buttons send cc?
83 | cc_edge_buttons = true
84 | },
85 |
86 |
87 | split_string = function(color)
88 | local rgb = {}
89 | -- '([^,]+)' regex for 'group match any number of characters which are not `,`'
90 | for byte in string.gmatch(color, '([^,]+)') do
91 | rgb[#rgb + 1] = byte
92 | end
93 | return rgb[1], rgb[2], rgb[3]
94 | end,
95 |
96 |
97 | led_sysex = function(self, led, color)
98 | local set_led_rgb = '0x0b' -- magic number for "set led rgb"
99 | -- `color` is e.g. 'ff,f2,e6'
100 | local r, g, b = self.split_string(color)
101 | return self.do_sysex(set_led_rgb, led, r, g, b)
102 | end,
103 |
104 |
105 | all_led_sysex = function(self, color)
106 | local set_all_led_rgb = '0x0e' -- magic number for "set ALL leds"
107 | local r, g, b = self.split_string(color)
108 | return self.do_sysex(set_all_led_rgb, r, g, b)
109 | end,
110 |
111 |
112 | do_sysex = function(command, ...)
113 | local var_args = ', '
114 | for i = 1, select("#", ...) do
115 | var_args = var_args .. string.format('%s, ', select(i, ...))
116 | end
117 | local end_sysex = '0xf7'
118 | local sysex_str = string.format('0xf0, 0x00, 0x20, 0x29, 0x02, 0x10, %s%s%s',
119 | command, var_args, end_sysex)
120 | local sysex = tab.split(sysex_str, ', ')
121 | return sysex
122 | end,
123 |
124 | -- For unknown reason(s), allows us to use Programmer mode; the other ports don't
125 | -- work for this.
126 | device_name = 'launchpad pro 2'
127 | }
128 |
129 | return launchpad
130 |
--------------------------------------------------------------------------------
/lib/core.lua:
--------------------------------------------------------------------------------
1 | --[[ midigrid core lib for getting midi grid devices to behave like monome grid devices, this is functions shared among the 64, 128, and 256 version.
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 | -- if there's no *monome* grid attached, norns returns a valid but unpopulated grid table
15 | -- so must we
16 | local midigrid = {
17 | midi_id = nil,
18 | device = nil,
19 | rows = 0,
20 | cols = 0,
21 | name = "none"
22 | }
23 |
24 |
25 | brightness_handler = function(val) return 0 end
26 |
27 | function midigrid.init()
28 | local supported_devices = {
29 | apcmini = 'apc mini',
30 | launchpadmk2 = 'launchpad mk2',
31 | launchpadpro = 'launchpad pro 2',
32 | launchpad = 'launchpad',
33 | launchpadmini = 'launchpad mini'
34 | }
35 | local config_name = 'none'
36 | config = nil
37 | for _, dev in pairs(midi.devices) do
38 | local name = string.lower(dev.name)
39 | for device, device_name in pairs(supported_devices) do
40 | if name == device_name then
41 | config_name = 'midigrid/config/' .. device .. '_config'
42 | end
43 | end
44 | end
45 | if config_name == 'none' then
46 | print('No supported device found')
47 | return midigrid
48 | end
49 | config = include(config_name)
50 | grid_notes = config.grid_notes
51 | brightness_handler = config.brightness_handler
52 | device_name = config.device_name
53 | og_dev_add = nil
54 | og_dev_remove = nil
55 | caps = config.caps
56 |
57 | -- adding midi device call backs---
58 | midigrid.led_buf = {}
59 | midigrid.rows = #grid_notes[1]
60 | midigrid.cols = #grid_notes
61 |
62 | -- here, using the grid from the config file, we generate the table to help us go the other
63 | -- way around so, if you press a midi note and you wanna know what it is, this will have an
64 | -- index with our coordinates
65 | note_coords = {}
66 | for row, notes in ipairs(grid_notes) do
67 | for col, note in ipairs(notes) do
68 | note_coords[note] = {col, row}
69 | end
70 | end
71 |
72 | -- setting up connection and connection callbacks before returning
73 | midigrid.setup_connect_handling()
74 | midigrid.update_devices()
75 | _local_midi_dev = midi.devices[midigrid.midi_id]
76 | end
77 |
78 | function midigrid.find_midi_device_id()
79 | local found_id = nil
80 | for _, dev in pairs(midi.devices) do
81 | local name = string.lower(dev.name)
82 | if midigrid.name_matches(name) then
83 | found_id = dev.id
84 | end
85 | end
86 | return found_id
87 | end
88 |
89 |
90 | function midigrid.connect(dummy_id)
91 | if config == nil then
92 | return midigrid
93 | end
94 | midigrid.set_midi_handler()
95 | print('midigrid "' .. device_name .. '" has ' .. midigrid.rows .. ' rows, ' .. midigrid.cols .. ' cols')
96 | midigrid:all(0)
97 | midigrid:refresh()
98 | return midigrid
99 | end
100 |
101 |
102 | function midigrid.set_key_handler(key_handler)
103 | midigrid.set_midi_handler()
104 | midigrid.key = key_handler
105 | end
106 |
107 |
108 | function midigrid.setup_connect_handling()
109 | og_dev_add = midi.add
110 | og_dev_remove = midi.remove
111 | midi.add = midigrid.handle_dev_add
112 | midi.remove = midigrid.handle_dev_remove
113 | end
114 |
115 |
116 | function midigrid.name_matches(name)
117 | return (name == device_name)
118 | end
119 |
120 |
121 | function midigrid.handle_dev_add(id, name, dev)
122 | og_dev_add(id, name, dev)
123 | midigrid.update_devices()
124 | if (midigrid.name_matches(name)) and (id ~= midigrid.midi_id) then
125 | midigrid.midi_id = id
126 | midigrid.set_midi_handler()
127 | end
128 | end
129 |
130 |
131 | function midigrid.handle_dev_remove(id)
132 | og_dev_remove(id)
133 | midigrid.update_devices()
134 | end
135 |
136 |
137 | -- this already expects it to have Midi_id
138 | function midigrid.set_midi_handler()
139 | if midigrid.midi_id == nil then
140 | return
141 | end
142 | local local_grid = midi.devices[midigrid.midi_id]
143 | if local_grid ~= nil then
144 | local_grid.event = midigrid.handle_key_midi
145 |
146 | -- need this for checking .device
147 | midigrid.device = local_grid
148 | print('`midigrid.device` is:')
149 | tab.print(midigrid.device)
150 | else
151 | midigrid.midi_id = nil
152 | end
153 | end
154 |
155 |
156 | function midigrid.cleanup()
157 | midigrid.key = nil
158 | end
159 |
160 |
161 | function midigrid.update_devices()
162 | midi.update_devices()
163 | local new_id = midigrid.find_midi_device_id()
164 |
165 | -- Only set id/handler when helpful
166 | if (midigrid.midi_id ~= new_id) and (new_id ~= nil) then
167 | midigrid.midi_id = new_id
168 | return midigrid.set_midi_handler()
169 | end
170 | return (midigrid.midi_id ~= nil)
171 | end
172 |
173 | midigrid.name = 'Midi Grid'
174 | midigrid.vports = { }
175 | midigrid.vports[1] = midigrid
176 |
177 | return midigrid
178 |
--------------------------------------------------------------------------------
/lib/mg_128.lua:
--------------------------------------------------------------------------------
1 | --[[ cheapskate library for midi grid devices, 2 quads, i.e. a "128" device.
2 | contains within itself a full 128 grid table, which can be viewed and played by pressing
3 | the '*_quad_button' buttons as defined in the relevant config file.
4 | ]]
5 |
6 | -- if there's no *monome* grid attached, norns returns a valid but unpopulated grid table
7 | -- so must we
8 | -------------------------------------------------------------------------------
9 | --
10 | -------------------------------------------------------------------------------
11 | -- views, everything goes to a grid buf, and a set of views defines grid behaviour
12 |
13 |
14 | local midigrid = include('midigrid/lib/core')
15 | local tab = require 'tabutil'
16 |
17 |
18 | --views are tables corresponding to a view of the grid_buf, as such they have correspondences between serialized grid bux indices and local midinote messages
19 | local views = {{},{}}
20 |
21 | local curr_view = 1
22 |
23 | --be sure to put this after midigrid.init()
24 | function midigrid.views_init()
25 | -- defined so that our table's indices correspond to the quad numbers we've decided on:
26 | -- 1|2
27 | view_btns = {
28 | config.upper_left_quad_button,
29 | config.upper_right_quad_button
30 | }
31 | -- start on "quad" 1
32 | -- make the grid buf, a hardcoded 128 grid
33 | grid_buf = {}
34 | for x = 1, 16 do
35 | grid_buf[x] = {}
36 | for y = 1, 8 do
37 | grid_buf[x][y] = 0
38 | _populate_view(x,y)
39 | end
40 | end
41 | --note coords for two view
42 | view_note_coords = {{},{}}
43 | for row, notes in ipairs(grid_notes) do
44 | for col, note in ipairs(notes) do
45 | view_note_coords[1][note] = {col, row}
46 | view_note_coords[2][note] = {col+8, row}
47 | end
48 | end
49 | midigrid.cols=16
50 | midigrid.rows=8
51 | midigrid:all(1)
52 | midigrid:all(0)
53 | midigrid:refresh()
54 | end
55 |
56 | function _populate_view(x,y)
57 | local index = 16*y+x --this is all goofy because we are not zero indexed, but it shouldnt matter...
58 | if x > 8 then
59 | --we are on the second view
60 | -- print('adding the note '..config.grid_notes[y][x-8]..' to the coordinates'..x..','..y..' at index '..index..' on view 2')
61 | views[2][index] = config.grid_notes[y][x-8]
62 | else
63 | -- print('adding the note '..config.grid_notes[y][x]..' to the coordinates'..x..','..y..' at index '..index..' on view 1')
64 | views[1][index] = config.grid_notes[y][x]
65 | end
66 | end
67 |
68 | function debug_views()
69 | print("debug"..#views[1])
70 | for i,v in ipairs(views[1]) do
71 | local x = math.tointeger(i/#views[1])
72 | local y = math.tointeger(i%#views[1])
73 | print("x is "..x.." and y is "..y)
74 | end
75 | end
76 |
77 | function _light_quad_button(which_quad)
78 | -- regardless of which quad button we wish to light, we still have to turn
79 | -- off all the others
80 | for quad, _ in ipairs(view_btns) do
81 | if quad == which_quad then
82 | _local_midi_dev:note_on(view_btns[quad], 1)
83 | else
84 | _local_midi_dev:note_on(view_btns[quad], 0)
85 | end
86 | end
87 | end
88 |
89 | function _brightness_to_buffer(note, vel, result)
90 | -- `result` is the table returned by whichever led fn we called as an arg to
91 | -- *this* fn
92 | if caps["sysex"] and caps["rgb"] then
93 | for _, bytes in ipairs(result) do
94 | table.insert(midigrid.led_buf, bytes)
95 | end
96 | else
97 | table.insert(midigrid.led_buf, 0x90)
98 | table.insert(midigrid.led_buf, note)
99 | table.insert(midigrid.led_buf, vel)
100 | end
101 | end
102 |
103 |
104 | -- led handling. *generally speaking*; first we clear the unchanged led buffer...
105 | function midigrid:all(brightness)
106 | local vel = brightness_handler(brightness)
107 | for x = 1, 16 do
108 | for y = 1, 8 do
109 | if grid_buf[x][y] ~= brightness then -- this led needs to be set
110 | grid_buf[x][y] = brightness
111 | local index = 16*y+x
112 | local note = views[curr_view][index]
113 | if note ~= nil then
114 | _brightness_to_buffer(note, vel, config:led_sysex(note, vel))
115 | end
116 | end
117 | end
118 | end
119 | end
120 |
121 |
122 | function midigrid:led(x, y, brightness)
123 | grid_buf[x][y] = brightness
124 | local index =16*y+x
125 | local note = views[curr_view][index]
126 | if note ~= nil then
127 | local vel = brightness_handler(brightness)
128 | _brightness_to_buffer(note, vel, config:led_sysex(note, vel))
129 | else
130 | print("not in view!")
131 | end
132 | end
133 |
134 |
135 | function midigrid:refresh()
136 | if midigrid.device then
137 | if caps['lp_double_buffer'] then
138 | _local_midi_dev:send(config:display_double_buffer_sysex())
139 | end
140 | _local_midi_dev:send(midigrid.led_buf)
141 | -- apparently, we need to refresh the quad button leds as well
142 | _light_quad_button(curr_view)
143 | -- ...and clear the buffer again.
144 | midigrid.led_buf = {}
145 | else
146 | print('Error: no device found')
147 | end
148 | end
149 |
150 | function midigrid:changeview(view)
151 | midigrid.led_buf = {}
152 | if view == 1 then
153 | for x = 1, 8 do
154 | for y = 1, 8 do
155 | midigrid:led(x, y, grid_buf[x][y])
156 | end
157 | end
158 | elseif view == 2 then
159 | for x = 9, 16 do
160 | for y= 1, 8 do
161 | midigrid:led(x, y, grid_buf[x][y])
162 | end
163 | end
164 | end
165 | midigrid:refresh()
166 | end
167 |
168 |
169 | function _handle_view(midi_msg, which_view)
170 | if midi_msg.type == "note_on" or caps["cc_edge_buttons"] then
171 | view = which_view
172 | curr_view = view
173 | _light_quad_button(view)
174 | midigrid:changeview(view)
175 | end
176 | end
177 |
178 |
179 | function midigrid.handle_key_midi(event)
180 | -- type="note_on", note, vel, ch
181 | -- type="cc", cc, val, ch
182 | -- so, tldr, `event[2]` is what we want
183 | local note = event[2]
184 | local midi_msg = midi.to_msg(event)
185 | -- first, intercept the quad buttons...
186 | if tab.contains(view_btns, note) then
187 | -- print("tab contains!")
188 | for view, button in ipairs(view_btns) do
189 | if note == button
190 | and curr_view ~= view then
191 | -- print("note==button and curr_view ~= view")
192 | -- ...and change the quad, if needed
193 | -- curr_view = view
194 | _handle_view(midi_msg, view)
195 | return
196 | end
197 | end
198 | -- "musical" notes, i.e. the main 8x8 grid, are in this range, BUT these values are
199 | -- device-dependent. Reject cc "notes" here.
200 | -- elseif (note >= 0 and note <= 88)
201 | elseif (midi_msg.type == 'note_on' or midi_msg.type == 'note_off') then
202 | local coords = view_note_coords[curr_view][note]
203 | local state = 0
204 | if coords then
205 | local x, y
206 | x, y = coords[1], coords[2]
207 | if midi_msg.type == 'note_on' then
208 | state = 1
209 | end
210 | if midigrid.key ~= nil then
211 | midigrid.key(x, y, state)
212 | end
213 | else
214 | print('Error: missing coordinates for this midi note!')
215 | end
216 | end
217 | end
218 |
219 | midigrid.init()
220 | midigrid.views_init()
221 |
222 | return midigrid
223 |
--------------------------------------------------------------------------------
/lib/mg_128_cheat.lua:
--------------------------------------------------------------------------------
1 | --[[ cheapskate library for midi grid devices, 2 quads, i.e. a "128" device.
2 | contains within itself a full 128 grid table, which can be viewed and played by pressing
3 | the '*_quad_button' buttons as defined in the relevant config file.
4 | ]]
5 |
6 | -- if there's no *monome* grid attached, norns returns a valid but unpopulated grid table
7 | -- so must we
8 | -------------------------------------------------------------------------------
9 | --
10 | -------------------------------------------------------------------------------
11 | -- views, everything goes to a grid buf, and a set of views defines grid behaviour
12 |
13 |
14 | local midigrid = include('midigrid/lib/core')
15 | local tab = require 'tabutil'
16 |
17 |
18 | --views are tables corresponding to a view of the grid_buf, as such they have correspondences between serialized grid bux indices and local midinote messages
19 | --cheat codes version, so three tables corresponding to :w
20 |
21 | local views = {{},{},{}}
22 |
23 | local curr_view = 1
24 |
25 | --be sure to put this after midigrid.init()
26 | function midigrid.views_init()
27 | -- defined so that our table's indices correspond to the quad numbers we've decided on:
28 | -- 1|2|3
29 | view_btns = {
30 | config.upper_left_quad_button,
31 | config.upper_right_quad_button,
32 | config.lower_left_quad_button
33 | }
34 | -- start on "quad" 1
35 | -- make the grid buf, a hardcoded 128 grid
36 | grid_buf = {}
37 | for x = 1, 16 do
38 | grid_buf[x] = {}
39 | for y = 1, 8 do
40 | grid_buf[x][y] = 0
41 | _populate_view(x,y)
42 | end
43 | end
44 | --rotating the grid just for notes part
45 | grid_notes_rot = _rotate_grid_notes(grid_notes)
46 |
47 | --note coords for three view
48 | view_note_coords = {{},{},{}}
49 | for row, notes in ipairs(grid_notes_rot) do
50 | for col, note in ipairs(notes) do
51 | view_note_coords[1][note] = {col, row}
52 | view_note_coords[2][note] = {col+6, row}
53 | view_note_coords[3][note] = {col+12, row}
54 | end
55 | end
56 | --see, still needs to be 16xs of 8y
57 | midigrid.cols=16
58 | midigrid.rows=8
59 | midigrid:refresh()
60 | end
61 |
62 | function _populate_view(x,y)
63 | local index = 16*y+x --this is all goofy because we are not zero indexed, but it shouldnt matter...
64 | if x > 12 then
65 | --we are on the second view
66 | views[3][index] = grid_notes_rot[y][x-8]
67 | elseif x > 6 then
68 | views[2][index] = grid_notes_rot[y][x]
69 | else
70 | views[1][index] = grid_notes_rot[y][x]
71 | end
72 | end
73 |
74 | -- this rotates a 64 grid_notes table, as specified in config as a table of rows, 90 degrees, so its a table of columns
75 | function _rotate_grid_notes(grid_notes)
76 | -- ok because we want to "flip this", we need to just do something very simple:
77 | -- if you flip a 128 grid into portrait mode, you can imagine that suddenly you have 8 columns of 16, rather than 16 columns of 8
78 | -- cheat codes to us like this, but the grid is not, its programmed always as 16 xs of y.
79 | -- this part of the code concerns filling out the 'view_note_coords' table, which deals with midi into the script as a grid
80 | -- it adds an index to a section of the table that represents a view, and gives a coordinate table
81 | -- now we want to say that our midigrid note for (1,1) is (8,1)
82 | -- (2,1) is (8,2)
83 | -- (3,1) is (8,3)
84 | -- (1,2) is (7,1)
85 | -- (1,3) is (6,1)
86 | -- (1,4) is (5,1)
87 | -- (1,5) is (4,1)
88 | -- (1,6) is (3,1)
89 | -- (7,1) is (8,7)
90 | -- (1,8) is (1,1)
91 | -- (2,8) is (1,2)
92 | -- (3,8) is (1,3)
93 | -- (3,7) is (1,3)
94 | --...ok
95 | -- (x,y) to (x',y'):
96 | -- x = y'
97 | -- y = 9 - y
98 | -- x' always seems to be = 9 - y
99 | -- y' always seems to equal x
100 | -- I think we can say this makes sense because the transformation on the x axis is one that makes y's original progression (x, (y1,y2,...)) be rather a decreasing distance from the x limit, and it seems random that its 9, but its just because we are base 1...
101 | --ok all the above is scrapped in favor of simply flipping this grid on init
102 | -- grid_notes= {
103 | -- {56,57,58,59,60,61,62,63},
104 | -- {48,49,50,51,52,53,54,55},
105 | -- {40,41,42,43,44,45,46,47},
106 | -- {32,33,34,35,36,37,38,39},
107 | -- {24,25,26,27,28,29,30,31},
108 | -- {16,17,18,19,20,21,22,23},
109 | -- {8,9,10,11,12,13,14,15},
110 | -- {0,1,2,3,4,5,6,7}
111 | -- }
112 | -- iterating, the first row is all the 1 columns
113 | --special cheat codes rotation cheat codes are:
114 | -- local x = 9 - row
115 | -- local y = col
116 | local rotated = {{},{},{},{},{},{},{},{}}
117 | for rows = 1, 8 do
118 | for cols = 8, 1, -1 do
119 | rotated[rows][cols] = config.grid_notes[cols][rows]
120 | end
121 | end
122 | return rotated
123 | end
124 |
125 | function debug_views()
126 | print("debug"..#views[1])
127 | for i,v in ipairs(views[1]) do
128 | local x = math.tointeger(i/#views[1])
129 | local y = math.tointeger(i%#views[1])
130 | print("x is "..x.." and y is "..y)
131 | end
132 | end
133 |
134 | function _light_quad_button(which_quad)
135 | -- regardless of which quad button we wish to light, we still have to turn
136 | -- off all the others
137 | for quad, _ in ipairs(view_btns) do
138 | if quad == which_quad then
139 | _local_midi_dev:note_on(view_btns[quad], 1)
140 | else
141 | _local_midi_dev:note_on(view_btns[quad], 0)
142 | end
143 | end
144 | end
145 |
146 | function _brightness_to_buffer(note, vel, result)
147 | -- `result` is the table returned by whichever led fn we called as an arg to
148 | -- *this* fn
149 | if caps["sysex"] and caps["rgb"] then
150 | for _, bytes in ipairs(result) do
151 | table.insert(midigrid.led_buf, bytes)
152 | end
153 | else
154 | table.insert(midigrid.led_buf, 0x90)
155 | table.insert(midigrid.led_buf, note)
156 | table.insert(midigrid.led_buf, vel)
157 | end
158 | end
159 |
160 |
161 | -- led handling. *generally speaking*; first we clear the unchanged led buffer...
162 | function midigrid:all(brightness)
163 | local vel = brightness_handler(brightness)
164 | for x = 1, 16 do
165 | for y = 1, 8 do
166 | if grid_buf[x][y] ~= brightness then -- this led needs to be set
167 | grid_buf[x][y] = brightness
168 | local index = 16*y+x
169 | local note = views[curr_view][index]
170 | if note ~= nil then
171 | _brightness_to_buffer(note, vel, config:led_sysex(note, vel))
172 | end
173 | end
174 | end
175 | end
176 | end
177 |
178 |
179 | function midigrid:led(x, y, brightness)
180 | grid_buf[x][y] = brightness
181 | local index =16*y+x
182 | local note = views[curr_view][index]
183 | if note ~= nil then
184 | local vel = brightness_handler(brightness)
185 | _brightness_to_buffer(note, vel, config:led_sysex(note, vel))
186 | else
187 | print("not in view!")
188 | end
189 | end
190 |
191 | function midigrid:refresh()
192 | if midigrid.device then
193 | if caps['lp_double_buffer'] then
194 | _local_midi_dev:send(config:display_double_buffer_sysex())
195 | end
196 | _local_midi_dev:send(midigrid.led_buf)
197 | -- apparently, we need to refresh the quad button leds as well
198 | _light_quad_button(curr_view)
199 | -- ...and clear the buffer again.
200 | midigrid.led_buf = {}
201 | else
202 | print('Error: no device found')
203 | end
204 | end
205 |
206 | function midigrid:changeview(view)
207 | midigrid.led_buf = {}
208 | if view == 1 then
209 | for x = 1, 8 do
210 | for y = 1, 8 do
211 | midigrid:led(x, y, grid_buf[x][y])
212 | end
213 | end
214 | elseif view == 2 then
215 | for x = 9, 16 do
216 | for y= 1, 8 do
217 | midigrid:led(x, y, grid_buf[x][y])
218 | end
219 | end
220 | end
221 | midigrid:refresh()
222 | end
223 |
224 |
225 | function _handle_view(midi_msg, which_view)
226 | if midi_msg.type == "note_on" or caps["cc_edge_buttons"] then
227 | view = which_view
228 | curr_view = view
229 | _light_quad_button(view)
230 | midigrid:changeview(view)
231 | end
232 | end
233 |
234 |
235 | function midigrid.handle_key_midi(event)
236 | -- type="note_on", note, vel, ch
237 | -- type="cc", cc, val, ch
238 | -- so, tldr, `event[2]` is what we want
239 | local note = event[2]
240 | local midi_msg = midi.to_msg(event)
241 | -- first, intercept the quad buttons...
242 | if tab.contains(view_btns, note) then
243 | -- print("tab contains!")
244 | for view, button in ipairs(view_btns) do
245 | if note == button
246 | and curr_view ~= view then
247 | -- print("note==button and curr_view ~= view")
248 | -- ...and change the quad, if needed
249 | -- curr_view = view
250 | _handle_view(midi_msg, view)
251 | return
252 | end
253 | end
254 | -- "musical" notes, i.e. the main 8x8 grid, are in this range, BUT these values are
255 | -- device-dependent. Reject cc "notes" here.
256 | -- elseif (note >= 0 and note <= 88)
257 | elseif (midi_msg.type == 'note_on' or midi_msg.type == 'note_off') then
258 | local coords = view_note_coords[curr_view][note]
259 | local state = 0
260 | if coords then
261 | local x, y
262 | x, y = coords[1], coords[2]
263 | if midi_msg.type == 'note_on' then
264 | state = 1
265 | end
266 | if midigrid.key ~= nil then
267 | midigrid.key(x, y, state)
268 | end
269 | else
270 | print('Error: missing coordinates for this midi note!')
271 | end
272 | end
273 | end
274 |
275 | midigrid.init()
276 | midigrid.views_init()
277 |
278 | return midigrid
279 |
--------------------------------------------------------------------------------
/lib/mg_256.lua:
--------------------------------------------------------------------------------
1 | --[[ cheapskate library for midi grid devices, 2 quads, i.e. a "128" device.
2 | contains within itself a full 128 grid table, which can be viewed and played by pressing
3 | the '*_quad_button' buttons as defined in the relevant config file.
4 | ]]
5 |
6 | -- if there's no *monome* grid attached, norns returns a valid but unpopulated grid table
7 | -- so must we
8 | -------------------------------------------------------------------------------
9 | --
10 | -------------------------------------------------------------------------------
11 | -- views, everything goes to a grid buf, and a set of views defines grid behaviour
12 |
13 |
14 | local midigrid = include('midigrid/lib/core')
15 | local tab = require 'tabutil'
16 |
17 |
18 | --views are tables corresponding to a view of the grid_buf, as such they have correspondences between serialized grid bux indices and local midinote messages
19 | local views = {{},{},{},{}}
20 |
21 | local curr_view = 1
22 |
23 | function midigrid.views_init()
24 | -- defined so that our table's indices correspond to the quad numbers we've decided on:
25 | -- 1|2
26 | view_btns = {
27 | config.upper_left_quad_button,
28 | config.upper_right_quad_button,
29 | config.lower_left_quad_button,
30 | config.lower_right_quad_button
31 | }
32 | -- start on "quad" 1
33 | curr_view = 1
34 | -- make the grid buf, a hardcoded 256 grid
35 | grid_buf = {}
36 | for x = 1, 16 do
37 | grid_buf[x] = {}
38 | for y = 1, 16 do
39 | grid_buf[x][y] = 0
40 | _populate_view(x,y)
41 | end
42 | end
43 | --note coords for two view
44 | view_note_coords = {{},{},{},{}}
45 | for row, notes in ipairs(grid_notes) do
46 | for col, note in ipairs(notes) do
47 | view_note_coords[1][note] = {col, row}
48 | view_note_coords[2][note] = {col+8, row}
49 | view_note_coords[3][note] = {col, row+8}
50 | view_note_coords[4][note] = {col+8, row+8}
51 | end
52 | end
53 | midigrid.cols=16
54 | midigrid.rows=16
55 | end
56 |
57 | function _populate_view(x,y)
58 | local index = 16*y+x --this is all goofy because we are not zero indexed, but it shouldnt matter...
59 | if x > 8 then
60 | --we are on the second view
61 | if y > 8 then
62 | views[4][index] = config.grid_notes[y-8][x-8]
63 | return
64 | end
65 | views[2][index] = config.grid_notes[y][x-8]
66 | else
67 | if y > 8 then
68 | views[3][index] = config.grid_notes[y-8][x]
69 | return
70 | end
71 | views[1][index] = config.grid_notes[y][x]
72 | end
73 | end
74 |
75 | function _light_quad_button(which_quad)
76 | -- regardless of which quad button we wish to light, we still have to turn
77 | -- off all the others
78 | for quad, _ in ipairs(view_btns) do
79 | if quad == which_quad then
80 | _local_midi_dev:note_on(view_btns[quad], 1)
81 | else
82 | _local_midi_dev:note_on(view_btns[quad], 0)
83 | end
84 | end
85 | end
86 |
87 | function _brightness_to_buffer(note, vel, result)
88 | -- `result` is the table returned by whichever led fn we called as an arg to
89 | -- *this* fn
90 | if caps["sysex"] and caps["rgb"] then
91 | for _, bytes in ipairs(result) do
92 | table.insert(midigrid.led_buf, bytes)
93 | end
94 | else
95 | table.insert(midigrid.led_buf, 0x90)
96 | table.insert(midigrid.led_buf, note)
97 | table.insert(midigrid.led_buf, vel)
98 | end
99 | end
100 |
101 |
102 | -- led handling. *generally speaking*; first we clear the unchanged led buffer...
103 | function midigrid:all(brightness)
104 | local vel = brightness_handler(brightness)
105 | for x = 1, 16 do
106 | for y = 1, 16 do
107 | if grid_buf[x][y] ~= brightness then -- this led needs to be set
108 | grid_buf[x][y] = brightness
109 | local index = 16*y+x
110 | local note = views[curr_view][index]
111 | if note ~= nil then
112 | _brightness_to_buffer(note, vel, config:led_sysex(note, vel))
113 | end
114 | end
115 | end
116 | end
117 | end
118 |
119 |
120 | function midigrid:led(x, y, brightness)
121 | grid_buf[x][y] = brightness
122 | local index =16*y+x
123 | local note = views[curr_view][index]
124 | if note ~= nil then
125 | local vel = brightness_handler(brightness)
126 | _brightness_to_buffer(note, vel, config:led_sysex(note, vel))
127 | else
128 | print("not in view!")
129 | end
130 | end
131 |
132 |
133 | function midigrid:refresh()
134 | if midigrid.device then
135 | if caps['lp_double_buffer'] then
136 | _local_midi_dev:send(config:display_double_buffer_sysex())
137 | end
138 | _local_midi_dev:send(midigrid.led_buf)
139 | -- apparently, we need to refresh the quad button leds as well
140 | _light_quad_button(curr_view)
141 | -- ...and clear the buffer again.
142 | midigrid.led_buf = {}
143 | else
144 | print('Error: no device found')
145 | end
146 | end
147 |
148 | function midigrid:changeview(view)
149 | midigrid.led_buf = {}
150 | if view == 1 then
151 | for x = 1, 8 do
152 | for y = 1, 8 do
153 | midigrid:led(x, y, grid_buf[x][y])
154 | end
155 | end
156 | elseif view == 2 then
157 | for x = 9, 16 do
158 | for y= 1, 8 do
159 | midigrid:led(x, y, grid_buf[x][y])
160 | end
161 | end
162 | elseif view == 3 then
163 | for x = 1, 8 do
164 | for y= 9, 16 do
165 | midigrid:led(x, y, grid_buf[x][y])
166 | end
167 | end
168 | elseif view == 4 then
169 | for x = 9, 16 do
170 | for y= 9, 16 do
171 | midigrid:led(x, y, grid_buf[x][y])
172 | end
173 | end
174 | end
175 | midigrid:refresh()
176 | end
177 |
178 |
179 | function _handle_view(midi_msg, which_view)
180 | if midi_msg.type == "note_on" or caps["cc_edge_buttons"] then
181 | view = which_view
182 | curr_view = view
183 | _light_quad_button(view)
184 | midigrid:changeview(view)
185 | end
186 | end
187 |
188 |
189 | function midigrid.handle_key_midi(event)
190 | -- type="note_on", note, vel, ch
191 | -- type="cc", cc, val, ch
192 | -- so, tldr, `event[2]` is what we want
193 | local note = event[2]
194 | local midi_msg = midi.to_msg(event)
195 | -- first, intercept the quad buttons...
196 | if tab.contains(view_btns, note) then
197 | -- print("tab contains!")
198 | for view, button in ipairs(view_btns) do
199 | if note == button
200 | and curr_view ~= view then
201 | -- print("note==button and curr_view ~= view")
202 | -- ...and change the quad, if needed
203 | -- curr_view = view
204 | _handle_view(midi_msg, view)
205 | return
206 | end
207 | end
208 | -- "musical" notes, i.e. the main 8x8 grid, are in this range, BUT these values are
209 | -- device-dependent. Reject cc "notes" here.
210 | -- elseif (note >= 0 and note <= 88)
211 | elseif (midi_msg.type == 'note_on' or midi_msg.type == 'note_off') then
212 | local coords = view_note_coords[curr_view][note]
213 | local state = 0
214 | if coords then
215 | local x, y
216 | x, y = coords[1], coords[2]
217 | if midi_msg.type == 'note_on' then
218 | state = 1
219 | end
220 | if midigrid.key ~= nil then
221 | midigrid.key(x, y, state)
222 | end
223 | else
224 | print('Error: missing coordinates for this midi note!')
225 | end
226 | end
227 | end
228 |
229 | midigrid.init()
230 | midigrid.views_init()
231 |
232 | return midigrid
233 |
--------------------------------------------------------------------------------
/lib/midigrid.lua:
--------------------------------------------------------------------------------
1 | --the straight, vanilla implementation of midigrid where midi keys correspond to grid leds 1 to 1
2 | local midigrid = include('midigrid/lib/core')
3 |
4 | --init is called before returning the final pseudo grid object
5 |
6 | function _brightness_to_buffer(note, vel, result)
7 | -- `result` is the table returned by whichever led fn we called as an arg to
8 | -- *this* fn
9 | if caps["sysex"] and caps["rgb"] then
10 | for _, bytes in ipairs(result) do
11 | table.insert(midigrid.led_buf, bytes)
12 | end
13 | else
14 | table.insert(midigrid.led_buf, 0x90)
15 | table.insert(midigrid.led_buf, note)
16 | table.insert(midigrid.led_buf, vel)
17 | end
18 | end
19 |
20 |
21 | -- led handling. *generally speaking*; first we clear the led buffer...
22 | function midigrid:all(brightness)
23 | local vel = brightness_handler(brightness)
24 | local note = nil
25 | if midigrid.device then
26 | midigrid.led_buf = {}
27 | for row = 1, midigrid.rows do
28 | for col = 1, midigrid.cols do
29 | note = grid_notes[row][col]
30 | -- the result of the fn call becomes the arg to `_brightness_to_buffer`
31 | _brightness_to_buffer(note, vel, config:all_led_sysex(vel))
32 | end
33 | end
34 | end
35 | end
36 |
37 |
38 | -- ...then we update the led buf at our leisure...
39 | function midigrid:led(col, row, brightness)
40 | if (col >= 1 and row >= 1) and (col <= midigrid.cols and row <= midigrid.rows) then
41 | local vel = brightness_handler(brightness)
42 | local note = nil
43 | if midigrid.device then
44 | note = grid_notes[row][col]
45 | if note then
46 | -- the result of the fn call becomes the arg to `_brightness_to_buffer`
47 | _brightness_to_buffer(note, vel, config:led_sysex(note, vel))
48 | else
49 | print('no note found! coordinates... x: ' .. col .. ' y: ' .. row .. ' z: ' .. brightness)
50 | end
51 | end
52 | end
53 | end
54 |
55 |
56 | -- ...then we send the whole buf at once
57 | function midigrid:refresh()
58 | if midigrid.device then
59 | if caps['lp_double_buffer'] then
60 | _local_midi_dev:send(config:display_double_buffer_sysex())
61 | end
62 | --TODO elseif here?
63 | _local_midi_dev:send(midigrid.led_buf)
64 |
65 | -- ...and clear the buffer again.
66 | midigrid.led_buf = {}
67 | else
68 | print('Error: no device found')
69 | end
70 | end
71 |
72 |
73 | function midigrid.handle_key_midi(event)
74 | -- type="note_on", note, vel, ch
75 | -- so, tldr, `event[2]` is what we want
76 | local note = event[2]
77 | local midi_msg = midi.to_msg(event)
78 |
79 | -- "musical" notes, i.e. the main 8x8 grid, are in this range, BUT these values are
80 | -- device-dependent. Reject cc "notes" here.
81 | if (note >= 0 and note <= 88)
82 | and (midi_msg.type == 'note_on' or midi_msg.type == 'note_off') then
83 | local coords = note_coords[note]
84 | local state = 0
85 | if coords then
86 | local x, y
87 | x, y = coords[1], coords[2]
88 | if midi_msg.type == 'note_on' then
89 | state = 1
90 | end
91 | if midigrid.key ~= nil then
92 | midigrid.key(x, y, state)
93 | end
94 | else
95 | print("missing coords!")
96 | end
97 | end
98 | end
99 |
100 |
101 | midigrid.init()
102 |
103 | return midigrid
104 |
--------------------------------------------------------------------------------
/notes_todos.org:
--------------------------------------------------------------------------------
1 |
2 | * norns midigrid library
3 | A few helper scripts for emulating and using midi grids like a monome grid, on the monome norns.
4 |
5 | Two scripts in the lib folder to include in scripts as 'grid', config files in the config folder for setups with different devices.
6 | ** instructions
7 | ~midigrid.lua~ and ~apcmini_config.lua~ is documented in the scripts themselves, setting up a new config file also means it needs to be loaded into the script itself:
8 | #+BEGIN_SRC lua
9 | -----------------------------
10 | --loading up config file here
11 | -----------------------------
12 | local config = include('midigrid/config/apcmini_config')
13 | -- local config = include('midigrid/config/launchpad_config')
14 | -- local config = include('midigrid/config/untz_config')
15 | -----------------------------
16 | #+END_SRC
17 |
18 | Then, in whatever script you are working in, it works well to override the global grid object with our own local one:
19 | #+BEGIN_SRC lua
20 | --adding this to script
21 | local grid = include('cheapskate/lib/midigrid')
22 | --or this
23 | local grid = include('cheapskate/lib/midigrid_2pages')
24 | --which allows this call to work with our midi grid
25 | local g = grid.connect()
26 | #+END_SRC
27 |
28 | Previous issues with the midi device being blocked are resolved with this new implementation taken from ryanlaws [https://github.com/ryanlaws/lunchpaid][lunchpaid].
29 | ** two page mode
30 | This script aims to emulate a 128 (16x8) grid by spreading a virtual grid buffer over two grid pages that you can toggle with auxiliary buttons
31 | *** apc mini
32 | By default, the left and right arrow buttons on the bottom row of buttons on the grid
33 | *** launchpad
34 | The toggle buttons are the top two column buttons in launchpad auxiliary column. need to set them up so they can be the left and right arrows but this is non trivial as the top auxiliary buttons on the launchpad send control (176) messages not note on.
35 | ** todos
36 | *** TODO add config files for launchpad (and untz maybe)
37 | *** TODO allow config files to overide led and all functions, for more native launchpad support
38 | *** DONE add cols and rows function
39 | CLOSED: [2019-11-13 Wed 17:58]
40 | *** DONE make page changing more efficient code wise
41 | CLOSED: [2019-11-18 Mon 11:27]
42 | *** DONE consider how to make this more sensible with the midi device number thing...
43 | CLOSED: [2019-11-18 Mon 11:27]
44 | ** scripts
45 | Notes for norns scripts that either work or I wanna make work, or need a little love to make work
46 | *** step
47 | works, need to block out midi
48 | *** strum
49 | works but with midi blocking
50 | *** mlr64
51 | [https://github.com/noiserock/custom64][mlr64]
52 | works!
53 | *** earthsea for apc mini
54 | **** this is pretty much ready to go, use the earthsea from the ash library
55 | its glitchy and not sure why
56 | working but glitchy?
57 | *** vials for apc mini
58 | **** I think this can be implemented as just split view toggle
59 | if view2 then {new mapping}
60 | **** status
61 | works pretty great two pages
62 | *** meadowphysics, this is one to look at
63 | **** basic mode is simple, just subtract by half
64 | **** Reset, Output, and Speeds
65 | this just needs a speed interface...
66 | if (config)
67 | **** if rules then choose with encoder
68 | *** strides
69 | this one should be easy too, the second half of the grid is just pulled up from an alt key
70 | *** shfts
71 | a toggle button for the two views
72 | *** cranes
73 | this is split in two, but horizontally, so going to need to be a little more sophisticated in the mapping
74 | *** ekombi
75 | just make it half as precise
76 | *** takt
77 | maybe just a two pager?
78 | *** foulplay
79 | only 64 ready to go!
80 | *** zellen
81 | good to go with rows and cols, and adjusting led values
82 | *** isoseq
83 | just the max pattern length needs to change
84 |
--------------------------------------------------------------------------------