├── LICENSE
├── MIDI Editor
└── MIDI Ex Machina
│ ├── README.md
│ ├── RobU - MIDI Ex Machina.lua
│ ├── eGUI.lua
│ └── euclid.lua
├── README.md
└── index.xml
/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 |
--------------------------------------------------------------------------------
/MIDI Editor/MIDI Ex Machina/README.md:
--------------------------------------------------------------------------------
1 | ### MIDI Ex Machina - A note randomizing sequencer for Reaper
2 |
3 | Features
4 | * Note randomizer
5 | * Note selection probability sliders
6 | * Drop down scale selection
7 | * Drop down octave selection
8 | * Drop down key selection
9 | * Octave multiplier
10 | * Permute selected notes
11 | * Randomizing sequencer
12 | * Note length probability sliders
13 | * Accent level and probability sliders
14 | * Legato probability slider
15 | * Shift notes left or right by grid size
16 | * Options toggle (seq, acc, leg, rnd, etc..)
17 | * Euclidean sequencer
18 | * Pulse, steps, and rotation euclidean sliders
19 | * Accent level and probability sliders
20 | * Options toggle (seq, acc, rnd)
21 |
22 | Credits
23 | * The GUI is a fork of [Eugen2771](https://github.com/EUGEN27771)'s superb Lua GUI Template for Reaper.
24 | * The Persistence library is provided by [Gerhard Roethlin](https://the-color-black.net/blog/LuaTablePersistence)
25 | * The Bjorklund library provided by https://codegists.com/snippet/lua/bjorklundlua_ptrv_lua
26 | * The Pickle table serialisation code is by [Steve Dekorte](http://lua-users.org/wiki/PickleTable)
27 |
--------------------------------------------------------------------------------
/MIDI Editor/MIDI Ex Machina/RobU - MIDI Ex Machina.lua:
--------------------------------------------------------------------------------
1 | --[[
2 | @description MIDI Ex Machina - Note Randomiser, Sequencer, and Euclidean Generator
3 | @about
4 | #### MIDI Ex Machina
5 | A scale-oriented, probability based composition tool
6 |
7 | #### Features
8 | note randomiser
9 | - selectable root note, octave, scale
10 | - note probability per scale note
11 | - randomise all or selected notes
12 | - octave doubler, with probability
13 | - force first note to root of the scale option
14 | - shuffle notes (fisher-yates)
15 |
16 | monophonic random sequence generator
17 | - note length probability
18 | - grid size control
19 | - velocity accent level, and probabilty
20 | - legato probability
21 | - various generation options
22 |
23 | euclidean sequence generator
24 | - grid size control
25 | - set pulses, steps, and rotation
26 | - velocity accent level and probability slider
27 | - various generation options
28 | @donation https://www.paypal.me/RobUrquhart
29 | @link Reaper http://reaper.fm
30 | @link Forum Thread http://reaper.fm
31 | @version 1.3.6
32 | @author RobU
33 | @changelog
34 | v1.3.6
35 | Added proper note shuffling using Fisher-Yates algorithm (polyphonic)
36 | Removed the shitty 'Permute' scale hack :)
37 | Fixed several corner-cases where notes might get eaten by the randomiser
38 | Code clean-up in preparation for GUI update
39 | @provides
40 | [main=midi_editor] .
41 | [nomain] eGUI.lua
42 | [nomain] euclid.lua
43 |
44 | Reaper 5.x
45 | Extensions: SWS
46 | Licenced under the GPL v3
47 | --]]
48 |
49 |
50 |
51 | -- requires ------------------------------------------------------------------
52 | --------------------------------------------------------------------------------
53 |
54 | package.path = debug.getinfo(1,"S").source:match[[^@?(.*[\/])[^\/]-$]] .."?.lua;".. package.path
55 | local e = require 'eGUI'
56 | local b = require 'euclid'
57 |
58 |
59 |
60 | -- globals -------------------------------------------------------------------
61 | --------------------------------------------------------------------------------
62 |
63 | m = {} -- all ex machina data
64 |
65 | -- user changeable defaults are marked with "(option)"
66 | m.OS = reaper.GetOS()
67 | -- window
68 | m.win_title = "RobU : MIDI Ex Machina - v1.3.6"; m.win_dockstate = 0
69 | m.win_x = 10; m.win_y = 10; m.win_w = 900; m.win_h = 280 -- window dimensions
70 | m.win_bg = {0, 0, 0} -- background colour
71 | m.def_zoom = 4 -- 100% (option)
72 | m.font_sz = 16
73 | -- zoom values are 1=70, 2=80, 3=90, 4=100, 5=110%, 6=120, 7=140, 8=160, 9=180, 10=200
74 | m.zoomF = false
75 |
76 | if string.match(m.OS, "Win") then
77 | -- nada
78 | elseif string.match(m.OS, "OSX") then
79 | m.font_sz = m.font_sz - 2
80 | else
81 | -- nada
82 | end
83 |
84 | -- default octave & key
85 | -- due to reaper.ini offset value, oct 4 might be oct 3... (fixed in next build)
86 | m.oct = 4; m.key = 1; m.root = 0 -- (options, except m.root)
87 |
88 | -- midi editor, take, grid
89 | m.activeEditor, m.activeTake = nil, nil
90 | m.ppqn = 960; -- default ppqn, no idea how to check if this has been changed..
91 | m.reaGrid = 0
92 |
93 | -- note randomiser
94 | m.rndAllNotesF = false -- all notes or only selected notes (option)
95 | m.rndOctX2F = false -- enable double scale randomisation (option)
96 | m.rndFirstNoteF = true; -- first note is always root (option)
97 | --m.rndPermuteF = false;
98 | m.pHash = 0 -- midi item state changes
99 | m.rndOctProb = 1 -- (option - min 0, max 10)
100 |
101 | -- sequence generator
102 | m.seqF = true -- generate sequence (option)
103 | m.seqFirstNoteF = true -- first note always (option)
104 | m.seqAccentF = true -- generate accents (option)
105 | m.seqLegatoF = false -- use legato (option)
106 | m.seqRndNotesF = true -- randomise notes (option)
107 | m.seqRepeatF = false -- repeat sequence by grid length (option - not implemented yet)
108 | m.legato = -10 -- default legatolessness value
109 | m.accentLow = 100; m.accentHigh = 127; m.accentProb = 3 -- default values (options)
110 | -- accentLow/High - min 0, max 127; accentProb - min 0, max 10
111 | m.legatoProb = 3 -- default value (option - min 0, max 10)
112 | m.seqGrid16 = {8, 4, 0, 2} -- sane default sequencer note length slider values
113 | m.seqGrid8 = {0, 8, 2, 2} -- sane default sequencer note length slider values
114 | m.seqGrid4 = {0, 2, 8, 1} -- sane default sequencer note length slider values
115 | m.seqShift = 0; m.seqShiftMin = -16; m.seqShiftMax = 16 -- shift notes left-right from sequencer
116 | m.repeatStart, m.repeatEnd, m.repeatLength, m.repeatTimes = 0, 0, 0, 0 -- repeat values (currently unused)
117 |
118 | -- euclidean generator
119 | m.eucF = true -- generate euclid (option)
120 | m.eucAccentF = false -- generate accents (option)
121 | m.eucRndNotesF = false -- randomise notes (option)
122 | m.eucPulses = 3; m.eucSteps = 8; m.eucRot = 0 -- default values (options)
123 |
124 | -- note buffers and current buffer index
125 | m.notebuf = {}; m.notebuf.i = 0; m.notebuf.max = 0
126 |
127 | m.dupes = {} -- for duplicate note detection while randomising
128 | m.euclid = {} -- for pattern generation
129 |
130 | m.notes = {'C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#', 'A', 'A#', 'B', 'C'}
131 | m.scales = {
132 | {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, name = "Chromatic"},
133 | {0, 2, 3, 5, 7, 8, 10, 12, name = "Aeolian / Minor"},
134 | {0, 2, 3, 5, 7, 9, 10, 12, name = "Dorian"},
135 | {0, 2, 4, 5, 7, 9, 11, 12, name = "Ionian / Major"},
136 | {0, 1, 3, 5, 6, 8, 10, 12, name = "Locrian"},
137 | {0, 2, 4, 6, 7, 9, 11, 12, name = "Lydian"},
138 | {0, 2, 4, 5, 7, 9, 10, 12, name = "Mixolydian"},
139 | {0, 1, 3, 5, 7, 8, 10, 12, name = "Phrygian"},
140 | {0, 3, 5, 6, 7, 10, 12, name = "Blues"},
141 | {0, 1, 4, 5, 7, 8, 11, 12, name = "Dbl. Harmonic"},
142 | {0, 1, 3, 6, 8, 10, 11, 12, name = "Enigmatic"},
143 | {0, 1, 4, 5, 7, 8, 11, 12, name = "Flamenco"},
144 | {0, 2, 4, 5, 7, 8, 11, 12, name = "Harmonic Maj"},
145 | {0, 2, 3, 5, 7, 8, 11, 12, name = "Harmonic min"},
146 | {0, 2, 3, 5, 7, 9, 11, 12, name = "Melodic min"},
147 | {0, 2, 4, 7, 9, 12, name = "Pentatonic Maj"},
148 | {0, 3, 5, 7, 10, 12, name = "Pentatonic min"},
149 | {0, 1, 4, 5, 6, 8, 11, 12, name = "Persian"},
150 | }
151 | -- a list of scales available to the note randomiser, more can be added manually if required
152 | -- each value is the interval step from the root note of the scale (0) including the octave (12)
153 |
154 | -- textual list of the available scale names for the GUI list selector
155 | m.scalelist = {}
156 | m.curScaleName = "Chromatic" -- (option - !must be a valid scale name!)
157 |
158 | -- various probability tables
159 | m.preNoteProbTable = {}; m.noteProbTable = {}
160 | m.preSeqProbTable = {}; m.seqProbTable = {}
161 | m.accProbTable = {}; m.octProbTable = {}
162 | m.legProbTable = {}
163 |
164 | pExtSaveStateF = false -- when true, update the pExtState for saving
165 | pExtLoadStateF = true -- when true, load the pExtState
166 | pExtState = {} -- Reaper project ext state table
167 | pExtStateStr = "" -- pickled string. a nom a nom a nom...
168 |
169 |
170 |
171 |
172 | -- midi ex machina functions -------------------------------------------------
173 | --------------------------------------------------------------------------------
174 |
175 | -- note buffers --------------------------------------------------------------
176 | --------------------------------------------------------------------------------
177 |
178 | local function NewNoteBuf()
179 | -- NewNoteBuf() - add a new note buffer to the table, returns handle
180 |
181 | m.notebuf.i = m.notebuf.i + 1
182 | m.notebuf.max = m.notebuf.max + 1
183 | m.notebuf[m.notebuf.i] = {}
184 |
185 | return m.notebuf[m.notebuf.i]
186 | end
187 |
188 | local function GetNoteBuf()
189 | -- GetNoteBuf() - returns handle to the current note buffer
190 |
191 | if m.notebuf.i >= 1 then
192 |
193 | return m.notebuf[m.notebuf.i]
194 | end
195 | end
196 |
197 | local function UndoNoteBuf()
198 | -- UndoNoteBuf() - points to previous note buffer
199 |
200 | if m.notebuf.i > 1 then
201 | m.notebuf.i = m.notebuf.i -1
202 | end
203 | end
204 |
205 | local function PurgeNoteBuf(idx)
206 | -- PurgeNoteBuf() - purge all note buffers from current+1 to end
207 |
208 | while m.notebuf.max > m.notebuf.i do
209 | m.notebuf[m.notebuf.max] = nil
210 | m.notebuf.max = m.notebuf.max - 1
211 | end
212 | end
213 |
214 |
215 |
216 | -- delete, get, insert -------------------------------------------------------
217 | --------------------------------------------------------------------------------
218 |
219 | function DeleteNotes()
220 | -- DeleteNotes() - delete all notes from the active take
221 |
222 | local i, num_notes = 0, 0
223 |
224 | if m.activeTake then
225 | __, num_notes, __, __ = reaper.MIDI_CountEvts(m.activeTake)
226 |
227 | for i = 0, num_notes do
228 | reaper.MIDI_DeleteNote(m.activeTake, 0)
229 | end --for
230 | end --m.activeTake
231 | end
232 |
233 | function GetNotesFromTake()
234 | -- GetNotesFromTake() - fill a note buffer from the active take
235 |
236 | local i, t
237 |
238 | if m.activeTake then
239 | reaper.MIDI_Sort(m.activeTake)
240 | local _retval, num_notes, num_cc, num_sysex = reaper.MIDI_CountEvts(m.activeTake)
241 |
242 | if num_notes > 0 then
243 | t = GetNoteBuf(); if t == nil then t = NewNoteBuf() end
244 | ClearTable(t)
245 |
246 | for i = 1, num_notes do
247 | _retval, selected, muted, startppq, endppq, channel, pitch, velocity = reaper.MIDI_GetNote(m.activeTake, i-1)
248 | t[i] = {}
249 | t[i][0] = i
250 | t[i][1] = selected
251 | t[i][2] = muted
252 | t[i][3] = startppq
253 | t[i][4] = endppq
254 | t[i][5] = endppq-startppq
255 | t[i][6] = channel
256 | t[i][7] = pitch
257 | t[i][8] = velocity
258 | end -- for i
259 | end -- num_notes
260 | end -- m.activeTake
261 | end
262 |
263 | function InsertNotes()
264 | -- InsertNotes(note_buffer) - insert notes in the active take
265 |
266 | DeleteNotes()
267 | local i = 1
268 |
269 | if m.activeTake and m.mItem then
270 | local noteLength = 0
271 | local gridSize = m.reaGrid * m.ppqn
272 | local itemLength = GetItemLength()
273 | local noteShift = m.seqShift * gridSize
274 | local t1 = GetNoteBuf()
275 | local t2 = {} -- for note shifting
276 | CopyTable(t1, t2)
277 |
278 | for k, v in pairs(t2) do -- do note shifting
279 | noteLength = v[4] - v[3]
280 | v[3] = v[3] + noteShift
281 | v[4] = v[4] + noteShift
282 |
283 | if v[3] >= itemLength then -- positive shift
284 | v[3] = v[3] - itemLength
285 | v[4] = v[4] - itemLength
286 |
287 | elseif v[3] < 0 then -- negative shift
288 | v[3] = v[3] + itemLength
289 | v[4] = v[4] + itemLength
290 |
291 | end
292 |
293 | if v[4] > itemLength then v[4] = itemLength - 1 end
294 |
295 | end
296 |
297 |
298 | while t2[i] do
299 | reaper.MIDI_InsertNote(m.activeTake, t2[i][1], t2[i][2], t2[i][3], t2[i][4], t2[i][6], t2[i][7], t2[i][8], false)
300 | --1=selected, 2=muted, 3=startppq, 4=endppq, 5=len, 6=chan, 7=pitch, 8=vel, noSort)
301 | i = i + 1
302 | end -- while t2[i]
303 |
304 | reaper.MIDI_Sort(m.activeTake)
305 | reaper.MIDIEditor_OnCommand(m.activeEditor, 40435) -- all notes off
306 |
307 | end -- m.activeTake
308 | end
309 |
310 |
311 |
312 | -- randomiser ----------------------------------------------------------------
313 | --------------------------------------------------------------------------------
314 |
315 | function GenOctaveTable(probTable, probSlider)
316 | -- GenOctaveTable(probTable, velSlider, probSlider)
317 | -- creates an event probability table using values from sliders
318 |
319 | local i, j = 1, 1
320 | ClearTable(probTable)
321 |
322 | -- single octave
323 | for i = 1, (probSlider.max - probSlider.val1) do
324 | probTable[j] = 0
325 | j = j + 1
326 | end
327 |
328 | -- double octave
329 | for i = 1, (probSlider.val1) do
330 | probTable[j] = 12
331 | j = j + 1
332 | end
333 | end
334 |
335 | function GetUniqueNote(note_in)
336 | -- GetUniqueNote - returns a random note number based on selected scale, and various flags
337 | local rand_note
338 |
339 | rand_note = (note_in[0]==1 and m.rndFirstNoteF) and -- select on note pos 1 && first note is root flag
340 | m.root or m.root + m.noteProbTable[math.random(1, #m.noteProbTable)] -- get appropriate note (fixed/random)
341 |
342 | if m.rndOctX2F then rand_note = rand_note + m.octProbTable[math.random(1, #m.octProbTable)] end -- get octave
343 |
344 | return rand_note
345 |
346 | --old code for posterity :P
347 | --t_sel[s][7] = (t_sel[s][0]==1 and m.rndFirstNoteF) and -- select on note pos 1 && first note is root flag
348 | -- m.root or m.root + m.noteProbTable[math.random(1, #m.noteProbTable)] -- get appropriate note (fixed/random)
349 | --if m.rndOctX2F then t_sel[s][7] = t_sel[s][7] + m.octProbTable[math.random(1, #m.octProbTable)] end -- get octave
350 | end
351 |
352 | function RandomiseNotes()
353 | -- RandomiseNotes - randomise all/selected notes
354 |
355 | local t1, t_all, t_sel = GetNoteBuf(), NewNoteBuf(), {}
356 | local a, s, t_all_len, t_sel_len = 0, 0, 0, 0
357 | local unique, retry = true, 0
358 | local overs = {}
359 |
360 | CopyNoteTable(t1, t_all)
361 | CopyNoteTable(t_all, t_sel, true)
362 |
363 | if #t_sel < 1 then return else t_sel_len = #t_sel end
364 |
365 | for s = 1, t_sel_len do -- for each note in t_sel
366 | unique = true -- assume unique
367 |
368 | t_sel[s][7] = GetUniqueNote(t_sel[s])
369 |
370 | for a = 1, #t_all do -- for all notes, find the overlaps between the selected notes and or notes
371 |
372 | if t_sel[s][0] ~= t_all[a][0] then -- exclude the same note ID
373 |
374 | if (t_sel[s][3] >= t_all[a][3] and t_sel[s][3] < t_all[a][4]) or -- sel start pos overlap with all?
375 | (t_all[a][3] >= t_sel[s][3] and t_all[a][3] < t_sel[s][4]) then -- all start pos overlap with sel?
376 | table.insert(overs, t_all[a]) -- update pos overlaps
377 |
378 | if t_sel[s][7] == t_all[a][7] then -- note overlap
379 | unique = false -- note is not unique
380 | end
381 | end
382 | end
383 | end -- for a = 1, #t_all do
384 |
385 | while not unique do
386 | unique = true -- assume the next random note will be unique
387 | t_sel[s][7] = GetUniqueNote(t_sel[s])
388 |
389 | for _, over in ipairs(overs) do -- check all overlapping notes for duplicates
390 | if t_sel[s][7] == over[7] then unique = false end -- not unique
391 | end
392 |
393 | retry = retry + 1; if retry > 10 then break end -- break loop if we can't find a solution
394 | end -- while not unique
395 |
396 | if retry > 11 then return 1 else retry = 1 end -- return if we can't find a solution
397 |
398 | overs={}
399 | end -- for s = 1, t_sel_len
400 |
401 | -- write back to the note buffer
402 | for s = 1, #t_sel do
403 | t_all[t_sel[s][0]][7] = t_sel[s][7]
404 | end
405 |
406 | PurgeNoteBuf()
407 | InsertNotes()
408 | if m.activeTake then
409 | __, pHash = reaper.MIDI_GetHash(m.activeTake, false, 0)
410 | m.pHash = pHash
411 | end
412 | end
413 |
414 | function SetRootNote(octave, key)
415 | -- SetRootNote(octave, key) - returns new root midi note
416 |
417 | local o = octave * 12
418 | local k = key - 1
419 |
420 | return o + k
421 | end
422 |
423 | function SetScale(scaleName, allScales, scale)
424 | -- SetScale()
425 | -- copies a scale from allScales to scale, key = scaleName
426 |
427 | ClearTable(scale)
428 |
429 | for i = 1, #allScales, 1 do
430 | if scaleName == allScales[i].name then
431 | for k, v in pairs(allScales[i]) do
432 | scale[k] = v
433 | end
434 | break
435 | end
436 | end
437 |
438 | end
439 |
440 | function ShuffleNotes()
441 | -- ShuffleNotes - shuffle all/selected notes using Fisher-Yates algo
442 |
443 | local t1, t_all, t_sel = GetNoteBuf(), NewNoteBuf(), {}
444 | local a, s, t, t_all_len, t_sel_len = 0, 0, 0, 0, 0
445 | local unique, retry = true, 0
446 | local overs = {}
447 |
448 | CopyNoteTable(t1, t_all) -- copy the note buffer to an empty stack note buffer
449 | CopyNoteTable(t_all, t_sel, true) -- copy selected notes only to a temp empty table
450 |
451 | if #t_sel < 2 then return else t_sel_len = #t_sel end
452 |
453 | for s = 1, t_sel_len do -- for each note in t_sel
454 | unique = true -- assume unique
455 |
456 | t = math.random(s, t_sel_len)
457 | t_sel[s][7], t_sel[t][7] = t_sel[t][7], t_sel[s][7] -- shuffle one note
458 |
459 | for a = 1, #t_all do -- for all notes, find the overlaps between the selected notes and or notes
460 |
461 | if t_sel[s][0] ~= t_all[a][0] then -- exclude the same note ID
462 |
463 | if (t_sel[s][3] >= t_all[a][3] and t_sel[s][3] < t_all[a][4]) or -- sel start pos overlap with all?
464 | (t_all[a][3] >= t_sel[s][3] and t_all[a][3] < t_sel[s][4]) then -- all start pos overlap with sel?
465 | table.insert(overs, t_all[a]) -- update pos overlaps
466 |
467 | if t_sel[s][7] == t_all[a][7] then -- note overlap
468 | unique = false -- note is not unique
469 | end
470 | end
471 | end
472 | end -- for a = 1, #t_all do
473 |
474 | while not unique do
475 | unique = true -- assume the next shuffled note will be unique
476 | t = math.random(s, t_sel_len)
477 | t_sel[s][7], t_sel[t][7] = t_sel[t][7], t_sel[s][7] -- shuffle one note
478 |
479 | for _, over in ipairs(overs) do -- check all overlapping notes for duplicates
480 | if t_sel[s][7] == over[7] then unique = false end -- not unique
481 | end
482 |
483 | retry = retry + 1; if retry > 10 then break end -- break loop if we can't find a solution
484 | end -- while not unique
485 |
486 | if retry > 11 then return 1 else retry = 1 end -- return if we can't find a solution
487 |
488 | overs={}
489 |
490 | end -- for i = 1, t_sel_len do
491 |
492 | -- write back to the note buffer
493 | for i = 1, #t_sel do
494 | t_all[t_sel[i][0]][7] = t_sel[i][7]
495 | end
496 |
497 | PurgeNoteBuf()
498 | InsertNotes()
499 |
500 | end
501 |
502 | function UpdateSliderLabels(sliderTable, preProbTable)
503 | -- UpdateSliderLabels() args t_noteSliders, m.preNoteProbTable
504 | -- sets the sliders to the appropriate scale notes, including blanks
505 |
506 | for k, v in pairs(sliderTable) do
507 | if preProbTable[k] then -- if there's a Scale note
508 | -- set the slider to the note name
509 | sliderTable[k].label = m.notes[Wrap((preProbTable[k] + 1) + m.root, 12)]
510 | if sliderTable[k].val1 == 0 then sliderTable[k].val1 = 1 end
511 | else
512 | sliderTable[k].label = ""
513 | sliderTable[k].val1 = 0
514 | end
515 | end
516 | end
517 |
518 |
519 |
520 | -- sequencer -----------------------------------------------------------------
521 | --------------------------------------------------------------------------------
522 |
523 | function GenSequence(seqProbTable, accProbTable, accSlider, legProbTable)
524 | -- GenSequence(seqProbTable, accProbTable, accSlider, legProbTable)
525 |
526 | local t, t2 = NewNoteBuf(), GetNoteBuf()
527 | CopyTable(t2, t)
528 | GetReaperGrid() -- populates m.reaGrid
529 | ClearTable(t)
530 |
531 | local itemPos = 0
532 | local gridSize = m.reaGrid * m.ppqn
533 | local itemLength = GetItemLength()
534 | local noteStart, noteEnd, noteLen, noteVel = 0, 0, 0, 0
535 | local newNote = 0
536 | local noteCount = 0; restCount = 0
537 |
538 | while itemPos < itemLength do
539 |
540 | if m.seqFirstNoteF and noteCount == 0 then -- handle first note flag
541 | newNote = seqProbTable[math.random(1, #seqProbTable)]
542 | while newNote == -1 do
543 | newNote = seqProbTable[math.random(1, #seqProbTable)]
544 | end
545 | else
546 | newNote = seqProbTable[math.random(1, #seqProbTable)]
547 | end -- m.seqFirstNoteF
548 |
549 | if newNote == -1 then
550 | itemPos = itemPos + gridSize
551 | restCount = restCount + 1
552 |
553 | else
554 | noteStart = itemPos
555 | noteLen = newNote * m.ppqn
556 | -- check if noteLen exceeds the item length
557 | if noteStart + noteLen > itemLength then noteLen = itemLength - noteStart end
558 | noteEnd = noteStart + noteLen
559 | itemPos = itemPos + noteLen
560 | if m.seqLegatoF then -- handle legato flag
561 | noteEnd = noteEnd + legProbTable[math.random(1, #legProbTable)]
562 | else
563 | noteEnd = noteEnd + m.legato
564 | end
565 | if m.seqAccentF then -- handle accent flag
566 | noteVel = accProbTable[math.random(1, #accProbTable)]
567 | else
568 | noteVel = math.floor(accSlider.val1)
569 | end -- m.seqAccentF
570 | noteCount = noteCount + 1
571 | t[noteCount] = {}
572 | t[noteCount][1] = true -- selected
573 | t[noteCount][2] = false -- muted
574 | t[noteCount][3] = noteStart -- startppqn
575 | t[noteCount][4] = noteEnd -- endppqn
576 | t[noteCount][5] = noteLen -- note length
577 | t[noteCount][6] = 0 -- channel
578 | t[noteCount][7] = m.root -- note number
579 | t[noteCount][8] = noteVel -- velocity
580 | end -- newNote
581 | end -- itemPos < itemLength
582 |
583 | PurgeNoteBuf()
584 | InsertNotes()
585 | end
586 |
587 | function GenAccentTable(probTable, velSlider, probSlider)
588 | -- GenAccentTable(probTable, velSlider, probSlider)
589 | -- creates an event probability table using values from sliders
590 |
591 | local i, j = 1, 1
592 | ClearTable(probTable)
593 |
594 | -- insert normal velocity
595 | for i = 1, (probSlider.max - probSlider.val1) do
596 | probTable[j] = math.floor(velSlider.val1)
597 | j = j + 1
598 | end
599 |
600 | -- insert the accented velocity
601 | for i = 1, (probSlider.val1) do
602 | probTable[j] = math.floor(velSlider.val2)
603 | j = j + 1
604 | end
605 | end
606 |
607 | function GenLegatoTable(probTable, probSlider)
608 | -- GenLegatoTable(probTable, velSlider, probSlider)
609 | -- creates an event probability table using values from sliders
610 |
611 | local i, j = 1, 1
612 | ClearTable(probTable)
613 |
614 | -- no legato
615 | for i = 1, (probSlider.max - probSlider.val1) do
616 | probTable[j] = m.legato
617 | j = j + 1
618 | end
619 |
620 | -- legato
621 | for i = 1, (probSlider.val1) do
622 | probTable[j] = 0
623 | j = j + 1
624 | end
625 | end
626 |
627 | function GenNoteAttributes(accF, accProbTable, accSlider, legF, legProbTable)
628 | -- GenNoteAttributes(accF, accProb, accVal, legF, legVal) -- accent, legato only
629 |
630 | if not accF and not legF then return end
631 | local t1, t2 = GetNoteBuf(), NewNoteBuf()
632 | local i = 1
633 | local noteStart, noteEnd, noteLen = 0, 0, 0
634 | CopyTable(t1, t2)
635 |
636 | while t2[i] do
637 |
638 | if t2[i][1] then
639 |
640 | if accF then -- handle accent flag (8 = velocity)
641 | t2[i][8] = accProbTable[math.random(1, #accProbTable)]
642 | end -- end accent
643 |
644 | if legF ~= 1 then -- no legato when called by euclid
645 |
646 | if legF then -- handle legato flag (3 = noteStart, 4 = noteEnd, 5 = noteLen)
647 | noteLen = t2[i][5]
648 | if noteLen >= 960 + m.legato and noteLen <= 960 - m.legato then noteLen = 960 -- 1/4
649 | elseif noteLen >= 480 + m.legato and noteLen <= 480 - m.legato then noteLen = 480 -- 1/8
650 | elseif noteLen >= 240 + m.legato and noteLen <= 240 - m.legato then noteLen = 240 -- 1/16
651 | end
652 | t2[i][4] = t2[i][3] + noteLen + legProbTable[math.random(1, #legProbTable)]
653 | end -- legato
654 | end -- t2[i]
655 | end --selected
656 | i = i + 1
657 | end -- while t1[i]
658 |
659 | PurgeNoteBuf()
660 | InsertNotes()
661 | end
662 |
663 | function GetItemLength()
664 | -- GetItemLength(t) - get length of take 't', set various global vars
665 | -- currently it only returns the item length (used in Sequencer and Euclid)
666 |
667 | --mItem = reaper.GetSelectedMediaItem(0, 0)
668 | mItemLen = reaper.GetMediaItemInfo_Value(m.mItem, "D_LENGTH")
669 | mBPM, mBPI = reaper.GetProjectTimeSignature2(0)
670 | msPerMin = 60000
671 | msPerQN = msPerMin / mBPM
672 | numQNPerItem = (mItemLen * 1000) / msPerQN
673 | numBarsPerItem = numQNPerItem / 4
674 | ItemPPQN = numQNPerItem * m.ppqn
675 | mItemTake = reaper.GetTake(m.mItem, 0) -- should fix looped items
676 | ItemPPQN = reaper.BR_GetMidiSourceLenPPQ(mItemTake) -- thanks Thrash!
677 | return ItemPPQN
678 |
679 | end
680 |
681 | function GetReaperGrid(gridRad)
682 | -- GetReaperGrid() - get the current grid size, set global var m.reaGrid
683 |
684 | if m.activeTake then
685 | m.reaGrid, __, __ = reaper.MIDI_GetGrid(m.activeTake) -- returns quarter notes
686 |
687 | if gridRad then -- if a grid object was passed, update it
688 | if m.reaGrid == 0.25 then gridRad.val1 = 1 -- 1/16
689 | elseif m.reaGrid == 0.5 then gridRad.val1 = 2 -- 1/8
690 | elseif m.reaGrid == 1 then gridRad.val1 = 3 -- 1/4
691 | end -- m.reaGrid
692 | end
693 | end -- m.activeTake
694 | end
695 |
696 | function GenProbTable(preProbTable, sliderTable, probTable)
697 | -- GenProbTable(preProbTable, slidersTable, probTable)
698 | -- creates an event probability table using values from sliders
699 |
700 | local i, j, k, l = 1, 1, 1, 1
701 | local floor = math.floor
702 | ClearTable(probTable)
703 |
704 | for i, v in ipairs(preProbTable) do
705 | if sliderTable[j].val1 > 0 then
706 | for l = 1, (sliderTable[j].val1) do
707 | probTable[k] = preProbTable[i]
708 | k = k + 1
709 | end -- for l
710 | end -- if sliderTable[j]
711 | j = j + 1
712 | end
713 | end
714 |
715 | function SetSeqGridSizes(sliderTable)
716 | -- SetSeqGridSizes()
717 | for k, v in pairs(sliderTable) do
718 | if sliderTable[k].label == "1/16" then m.preSeqProbTable[k] = 0.25
719 | elseif sliderTable[k].label == "1/8" then m.preSeqProbTable[k] = 0.5
720 | elseif sliderTable[k].label == "1/4" then m.preSeqProbTable[k] = 1.0
721 | elseif sliderTable[k].label == "Rest" then m.preSeqProbTable[k] = -1.0
722 | end
723 | end
724 | end
725 |
726 |
727 |
728 | -- euclidiser ----------------------------------------------------------------
729 | --------------------------------------------------------------------------------
730 | function GenBjorklund(pulses, steps, rotation, accProbTable, accSlider)
731 | -- GenBjorklund(pulses, steps, rotation, accProbTable, accSlider)
732 |
733 | local floor = math.floor
734 | local t, t2 = NewNoteBuf(), GetNoteBuf()
735 | CopyTable(t2, t)
736 | GetReaperGrid() -- populates m.reaGrid
737 | ClearTable(t)
738 |
739 | local itemPos = 0
740 | local gridSize = m.reaGrid * m.ppqn
741 | local itemLength = GetItemLength()
742 | local noteStart, noteEnd, noteLen, noteVel = 0, 0, 0, 0
743 | local newNote = 0
744 | local noteCount = 0; restCount = 0
745 | local pulse = floor(pulses.val1 + 0.5)
746 | local step = floor(steps.val1 + 0.5)
747 | local pattern = b.generate(pulse, step)
748 | local rot = floor(rotation.val1 + 0.5)
749 | local idx = (-rot) + 1; idx = Wrap(idx, step)
750 |
751 | while itemPos < itemLength do
752 |
753 | if pattern[idx] then
754 | noteStart = itemPos
755 | noteLen = gridSize
756 | noteEnd = noteStart + noteLen
757 | itemPos = itemPos + noteLen
758 |
759 | if m.eucAccentF then -- handle accent flag
760 | noteVel = accProbTable[math.random(1, #accProbTable)]
761 | else
762 | noteVel = floor(accSlider.val1)
763 | end -- m.seqAccentF
764 |
765 | --noteVel = accProbTable[math.random(1, #accProbTable)]
766 | noteCount = noteCount + 1
767 | t[noteCount] = {}
768 | t[noteCount][1] = true -- selected
769 | t[noteCount][2] = false -- muted
770 | t[noteCount][3] = noteStart -- startppqn
771 | t[noteCount][4] = noteEnd + m.legato -- endppqn
772 | t[noteCount][5] = noteLen -- note length
773 | t[noteCount][6] = 0 -- channel
774 | t[noteCount][7] = m.root -- note number
775 | t[noteCount][8] = noteVel -- velocity
776 |
777 | else
778 | itemPos = itemPos + gridSize
779 | restCount = restCount + 1
780 | end
781 | idx = idx + 1
782 | idx = Wrap(idx, step)
783 | end
784 |
785 | PurgeNoteBuf()
786 | InsertNotes()
787 | end
788 |
789 |
790 |
791 | -- utility functions ----------------------------------------------------------
792 | --------------------------------------------------------------------------------
793 |
794 | function ClearTable(t)
795 | -- ClearTable(t) - set all items in 2D table 't' to nil
796 |
797 | for k, v in pairs(t) do
798 | t[k] = nil
799 | end
800 | end
801 |
802 | function CopyTable(t1, t2) -- deprecated
803 | -- CopyTable(t1, t2) - copies note data from t1 to t2
804 | ClearTable(t2) -- safety, not needed if new table supplied
805 |
806 | local i, j = 1, 1
807 |
808 | while t1[i] do
809 | j = 1
810 | t2[i] = {}
811 |
812 | while (t1[i][j] ~= nil) do
813 | t2[i][j] = t1[i][j]
814 | j = j + 1
815 | end --while (t1[i][j]
816 |
817 | i = i + 1
818 | end -- while t1[i]
819 | end
820 |
821 | function CopyNoteTable(t1, t2, selected)
822 | -- Copies notes from table1 to table2, optionally filtered on selected notes
823 |
824 | ClearTable(t2)
825 |
826 | local i, j = 1, 1
827 |
828 | if not selected then-- copy all
829 | while t1[i] do
830 | table.insert(t2, t1[i])
831 | t2[i].idx = i
832 | i = i + 1
833 | end
834 |
835 | else -- copy selected
836 | while t1[i] do
837 | if t1[i][1] or m.rndAllNotesF then
838 | table.insert(t2, t1[i])
839 | t2[#t2].idx = i
840 | end
841 | i = i + 1
842 | end
843 | end
844 |
845 | end
846 |
847 | function PrintNote(t) -- debug code
848 | -- PrintNote - arg note t; print a single note to reaper console
849 |
850 | if not t then return end
851 |
852 | local j = 0
853 | local str = "id \t sel \t mut \t s_ppq \t e_ppq \t leng \t chan \t pitch \t vel \n"
854 |
855 | while t[j] ~= nil do
856 | str = str .. tostring(t[j]) .. "\t"
857 | j = j + 1
858 | end
859 |
860 | ConMsg(str)
861 | end
862 |
863 | function PrintNotes(t) -- debug code
864 | -- PrintNotes - arg note_buffer t; print note_buffer to reaper console
865 |
866 | if not t then return end
867 |
868 | local i, j = 1, 0
869 | local str = "id \t sel \t mut \t s_ppq \t e_ppq \t leng \t chan \t pitch \t vel \n"
870 |
871 | while t[i] do
872 | j = 0
873 |
874 | while (t[i][j] ~= nil) do
875 | str = str .. tostring(t[i][j]) .. "\t"
876 | j = j + 1
877 | end
878 |
879 | str = str .. "\n"
880 | i = i + 1
881 | end -- while t[i]
882 |
883 | str = str .. "\n"
884 | ConMsg(str)
885 | end
886 |
887 | function PrintTable(t) -- debug code (deprecate?)
888 | -- PrintTable - print table to reaper console
889 |
890 | local str = ""
891 | for k, v in pairs(t) do
892 | str = str .. tostring(v) .. "\t"
893 | end
894 | str = str .. "\n"
895 |
896 | end
897 |
898 |
899 | function Wrap (n, max)
900 | -- Wrap(n, max) -return n wrapped between 'n' and 'max'
901 |
902 | n = n % max
903 | if (n < 1) then n = n + max end
904 |
905 | return n
906 | end
907 |
908 | function RGB2Dec(r, g, b)
909 | -- RGB2Dec(r, g, b) - takes 8 bit r, g, b values, returns decimal (0 to 1)
910 |
911 | if r < 0 or r > 255 then r = wrap(r, 255) end
912 | if g < 0 or g > 255 then g = wrap(g, 255) end
913 | if b < 0 or b > 255 then b = wrap(b, 255) end
914 |
915 | return r/255, g/255, b/255
916 | end
917 |
918 | function RGB2Packed(r, g, b)
919 | -- RGB2Packed(r, g, b) - returns a packed rgb value
920 |
921 | local floor = math.floor
922 | g = (g << 8)
923 | b = (b << 16)
924 |
925 | return floor(r + g + b)
926 | end
927 |
928 | function ConMsg(str)
929 | -- ConMsg(str) - outputs 'str' to the Reaper console
930 | reaper.ShowConsoleMsg(str .."\n")
931 | end
932 |
933 | function ShowMessage(tb, msgNum)
934 | -- ShowMessage(textbox, message number) - display or hide a message for user
935 |
936 | if msgNum == 0 then
937 | tb.tab = (1 << 9)
938 | tb.label = ""
939 |
940 | elseif msgNum == 1 then
941 | tb.tab = 0
942 | tb.label = "MIDI Editor Closed"
943 |
944 | elseif msgNum == 2 then
945 | tb.tab = 0
946 | tb.label = "Please select a MIDI Item in the Arrange Window"
947 | end
948 |
949 | e.gScaleState = true
950 | end
951 |
952 |
953 | -- table serialization - steve dekorte ----------------------------------------
954 | --------------------------------------------------------------------------------
955 | function pickle(t)
956 | return Pickle:clone():pickle_(t)
957 | end
958 |
959 | Pickle = {
960 | clone = function (t) local nt = {}
961 | for i, v in pairs(t) do
962 | nt[i] = v
963 | end
964 | return nt
965 | end
966 | }
967 |
968 | function Pickle:pickle_(root)
969 |
970 | if type(root) ~= "table" then
971 | error("can only pickle tables, not " .. type(root) .. "s")
972 | end
973 |
974 | self._tableToRef = {}
975 | self._refToTable = {}
976 | local savecount = 0
977 | self:ref_(root)
978 | local s = ""
979 |
980 | while #self._refToTable > savecount do
981 | savecount = savecount + 1
982 | local t = self._refToTable[savecount]
983 | s = s .. "{\n"
984 |
985 | for i, v in pairs(t) do
986 | s = string.format("%s[%s]=%s,\n", s, self:value_(i), self:value_(v))
987 | end
988 |
989 | s = s .. "},\n"
990 | end
991 |
992 | return string.format("{%s}", s)
993 | end
994 |
995 | function Pickle:value_(v)
996 | local vtype = type(v)
997 |
998 | if vtype == "string" then return string.format("%q", v)
999 | elseif vtype == "number" then return v
1000 | elseif vtype == "boolean" then return tostring(v)
1001 | elseif vtype == "table" then return "{"..self:ref_(v).."}"
1002 | else error("pickle a " .. type(v) .. " is not supported")
1003 | end
1004 | end
1005 |
1006 | function Pickle:ref_(t)
1007 |
1008 | local ref = self._tableToRef[t]
1009 |
1010 | if not ref then
1011 | if t == self then error("can't pickle the pickle class") end
1012 | table.insert(self._refToTable, t)
1013 | ref = #self._refToTable
1014 | self._tableToRef[t] = ref
1015 | end
1016 |
1017 | return ref
1018 | end
1019 |
1020 | function unpickle(s)
1021 |
1022 | if type(s) ~= "string" then
1023 | error("can't unpickle a " .. type(s) .. ", only strings")
1024 | end
1025 |
1026 | local gentables = load("return " .. s)
1027 | local tables = gentables()
1028 |
1029 | for tnum = 1, #tables do
1030 | local t = tables[tnum]
1031 | local tcopy = {}
1032 | for i, v in pairs(t) do tcopy[i] = v end
1033 |
1034 | for i, v in pairs(tcopy) do
1035 | local ni, nv
1036 | if type(i) == "table" then ni = tables[i[1]] else ni = i end
1037 | if type(v) == "table" then nv = tables[v[1]] else nv = v end
1038 | t[i] = nil
1039 | t[ni] = nv
1040 | end
1041 | end
1042 |
1043 | return tables[1]
1044 | end
1045 |
1046 |
1047 |
1048 |
1049 | -- GUI Elements --------------------------------------------------------------
1050 | --------------------------------------------------------------------------------
1051 |
1052 | -- Main Window ---------------------------------------------------------------
1053 | --------------------------------------------------------------------------------
1054 |
1055 | -- Persistent window elements
1056 | local winFrame = e.Frame:new({0}, 5, 5, m.win_w - 10, m.win_h - 10, e.col_grey4)
1057 | local zoomDrop = e.Droplist:new({0}, 5, 5, 40, 22, e.col_green, "", e.Arial, m.font_sz, e.col_grey8, 4, {"70%", "80%", "90%", "100%", "110%", "120%", "140%", "160%", "180%", "200%"})
1058 | local winText = e.Textbox:new({0}, 45, 5, m.win_w - 50, 22, e.col_green, "MIDI Ex Machina ", e.Arial, m.font_sz, e.col_grey8)
1059 | local layerBtn01 = e.Button:new({0}, 5, m.win_h - 25, 100, 20, e.col_green, "Randomiser", e.Arial, m.font_sz, e.col_grey8)
1060 | local layerBtn02 = e.Button:new({0}, 105, m.win_h - 25, 100, 20, e.col_grey5, "Sequencer", e.Arial, m.font_sz, e.col_grey7)
1061 | local layerBtn03 = e.Button:new({0}, 205, m.win_h - 25, 100, 20, e.col_grey5, "Euclidiser", e.Arial, m.font_sz, e.col_grey7)
1062 | local layerBtn04 = e.Button:new({0}, 305, m.win_h - 25, 100, 20, e.col_grey5, "Options", e.Arial, m.font_sz, e.col_grey7)
1063 | local undoBtn = e.Button:new({0}, m.win_w-85, m.win_h -25, 40, 20, e.col_grey5, "Undo", e.Arial, m.font_sz, e.col_grey7)
1064 | local redoBtn = e.Button:new({0}, m.win_w-45, m.win_h -25, 40, 20, e.col_grey5, "Redo", e.Arial, m.font_sz, e.col_grey7)
1065 |
1066 | -- Persistent window element table
1067 | t_winElements = {winFrame, zoomDrop, winText, layerBtn01, layerBtn02, layerBtn03, layerBtn04, undoBtn, redoBtn}
1068 |
1069 |
1070 |
1071 | -- Common Elements -----------------------------------------------------------
1072 | --------------------------------------------------------------------------------
1073 |
1074 | -- key, octave, & scale droplists
1075 | dx, dy, dw, dh = 25, 70, 110, 20
1076 | local keyDrop = e.Droplist:new({1, 2, 3}, dx, dy, (dw*0.5)-5, dh, e.col_blue, "Key", e.Arial, m.font_sz, e.col_grey8, m.key, m.notes)
1077 | local octDrop = e.Droplist:new({1, 2, 3}, dx+(dw*0.5)+5, dy, (dw*0.5)-5, dh, e.col_blue, "Oct ", e.Arial, m.font_sz, e.col_grey8, m.oct,{0, 1, 2, 3, 4, 5, 6, 7})
1078 | local scaleDrop = e.Droplist:new({1, 2, 3}, dx, dy + 50, dw, dh, e.col_blue, "Scale", e.Arial, m.font_sz, e.col_grey8, 1, m.scalelist)
1079 | local t_Droplists = {keyDrop, octDrop, scaleDrop}
1080 |
1081 |
1082 |
1083 |
1084 | -- Randomiser Layer ----------------------------------------------------------
1085 | --------------------------------------------------------------------------------
1086 |
1087 | -- note shuffle button
1088 | local shuffleBtn = e.Button:new({1}, 25, 165, 110, 25, e.col_green, "Shuffle", e.Arial, m.font_sz, e.col_grey8)
1089 |
1090 | -- note randomise button
1091 | local randomBtn = e.Button:new({1}, 25, 205, 110, 25, e.col_green, "Randomise", e.Arial, m.font_sz, e.col_grey8)
1092 |
1093 |
1094 | -- note weight sliders
1095 | local nx, ny, nw, nh, np = 160, 50, 30, 150, 40
1096 | local noteSldr01 = e.Vert_Slider:new({1}, nx, ny, nw, nh, e.col_blue, "", e.Arial, m.font_sz, e.col_grey8, 1, 0, 0, 12, 1)
1097 | local noteSldr02 = e.Vert_Slider:new({1}, nx+(np*1), ny, nw, nh, e.col_blue, "", e.Arial, m.font_sz, e.col_grey8, 1, 0, 0, 12, 1)
1098 | local noteSldr03 = e.Vert_Slider:new({1}, nx+(np*2), ny, nw, nh, e.col_blue, "", e.Arial, m.font_sz, e.col_grey8, 1, 0, 0, 12, 1)
1099 | local noteSldr04 = e.Vert_Slider:new({1}, nx+(np*3), ny, nw, nh, e.col_blue, "", e.Arial, m.font_sz, e.col_grey8, 1, 0, 0, 12, 1)
1100 | local noteSldr05 = e.Vert_Slider:new({1}, nx+(np*4), ny, nw, nh, e.col_blue, "", e.Arial, m.font_sz, e.col_grey8, 1, 0, 0, 12, 1)
1101 | local noteSldr06 = e.Vert_Slider:new({1}, nx+(np*5), ny, nw, nh, e.col_blue, "", e.Arial, m.font_sz, e.col_grey8, 1, 0, 0, 12, 1)
1102 | local noteSldr07 = e.Vert_Slider:new({1}, nx+(np*6), ny, nw, nh, e.col_blue, "", e.Arial, m.font_sz, e.col_grey8, 1, 0, 0, 12, 1)
1103 | local noteSldr08 = e.Vert_Slider:new({1}, nx+(np*7), ny, nw, nh, e.col_blue, "", e.Arial, m.font_sz, e.col_grey8, 1, 0, 0, 12, 1)
1104 | local noteSldr09 = e.Vert_Slider:new({1}, nx+(np*8), ny, nw, nh, e.col_blue, "", e.Arial, m.font_sz, e.col_grey8, 1, 0, 0, 12, 1)
1105 | local noteSldr10 = e.Vert_Slider:new({1}, nx+(np*9), ny, nw, nh, e.col_blue, "", e.Arial, m.font_sz, e.col_grey8, 1, 0, 0, 12, 1)
1106 | local noteSldr11 = e.Vert_Slider:new({1}, nx+(np*10), ny, nw, nh, e.col_blue, "", e.Arial, m.font_sz, e.col_grey8, 1, 0, 0, 12, 1)
1107 | local noteSldr12 = e.Vert_Slider:new({1}, nx+(np*11), ny, nw, nh, e.col_blue, "", e.Arial, m.font_sz, e.col_grey8, 1, 0, 0, 12, 1)
1108 | local noteSldr13 = e.Vert_Slider:new({1}, nx+(np*12), ny, nw, nh, e.col_blue, "", e.Arial, m.font_sz, e.col_grey8, 1, 0, 0, 12, 1)
1109 |
1110 | -- Note probability slider table
1111 | local t_noteSliders = {noteSldr01, noteSldr02, noteSldr03, noteSldr04, noteSldr05, noteSldr06, noteSldr07,
1112 | noteSldr08, noteSldr09, noteSldr10, noteSldr11, noteSldr12, noteSldr13}
1113 |
1114 | -- Note probability slider label (Textbox) - right-click to reset all
1115 | local probSldrText = e.Textbox:new({1}, nx, 210, 510, 20, e.col_grey5, "Note Weight Sliders", e.Arial, m.font_sz, e.col_grey7)
1116 |
1117 | -- Note octave doubler probability slider
1118 | local octProbSldr = e.Vert_Slider:new({1}, nx+(np*13) + 10, ny, nw, nh, e.col_blue, "%", e.Arial, m.font_sz, e.col_grey8, m.rndOctProb, 0, 0, 10, 1)
1119 | local octProbText = e.Textbox:new({1}, nx+(np*13) + 10, 210, (nw), 20, e.col_grey5, "Oct", e.Arial, m.font_sz, e.col_grey7)
1120 |
1121 | -- Note randomiser options
1122 | local noteOptionsCb = e.Checkbox:new({1}, nx+(np*14)+10, ny+30, 30, 30, e.col_orange, "", e.Arial, m.font_sz, e.col_grey8, {0,0,0}, {"All / Sel Notes", "1st Note = Root", "Octave X2"})
1123 | local noteOptionText = e.Textbox:new({1}, nx+(np*14)+20, 210, (nw*4), 20, e.col_grey5, "Options", e.Arial, m.font_sz, e.col_grey7)
1124 |
1125 |
1126 |
1127 |
1128 | -- Sequencer Layer -----------------------------------------------------------
1129 | --------------------------------------------------------------------------------
1130 |
1131 | -- sequence generate button
1132 | local sequenceBtn = e.Button:new({2}, 25, 205, 110, 25, e.col_yellow, "Generate", e.Arial, m.font_sz, e.col_grey8)
1133 | local sx, sy, sw, sh, sp = 160, 50, 30, 150, 40
1134 |
1135 | -- sequencer grid size radio selector
1136 | local seqGridRad = e.Rad_Button:new({2,3}, sx, sy + 40, 30, 30, e.col_yellow, "", e.Arial, m.font_sz, e.col_grey8, 1, {"1/16", "1/8", "1/4"})
1137 | local seqGridText = e.Textbox:new({2,3}, sx, 210, (sw*2)+20, 20, e.col_grey5, "Grid Size", e.Arial, m.font_sz, e.col_grey7)
1138 |
1139 | -- sequence grid probability sliders
1140 | local seqSldr16 = e.Vert_Slider:new({2}, sx+(sp*3), sy, sw, sh, e.col_blue, "1/16", e.Arial, m.font_sz, e.col_grey8, 0, 0, 0, 16, 1)
1141 | local seqSldr8 = e.Vert_Slider:new({2}, sx+(sp*4), sy, sw, sh, e.col_blue, "1/8", e.Arial, m.font_sz, e.col_grey8, 0, 0, 0, 16, 1)
1142 | local seqSldr4 = e.Vert_Slider:new({2}, sx+(sp*5), sy, sw, sh, e.col_blue, "1/4", e.Arial, m.font_sz, e.col_grey8, 0, 0, 0, 16, 1)
1143 | local seqSldrRest = e.Vert_Slider:new({2}, sx+(sp*6), sy, sw, sh, e.col_blue, "Rest", e.Arial, m.font_sz, e.col_grey8, 0, 0, 0, 16, 1)
1144 |
1145 | -- sequence grid probability slider table
1146 | local t_seqSliders = {seqSldr16, seqSldr8, seqSldr4, seqSldrRest}
1147 |
1148 | -- sequence grid probability sliders label - right click to reset all (per grid size selection)
1149 | local seqSldrText = e.Textbox:new({2}, sx + (sp * 3), 210, (sw * 5), 20, e.col_grey5, "Size Weight Sliders", e.Arial, m.font_sz, e.col_grey7)
1150 |
1151 | -- velocity accent slider (shared with Euclid layer)
1152 | local seqAccRSldr = e.V_Rng_Slider:new({2,3}, sx + (sp * 8) - (sw / 2), sy, sw, sh, e.col_blue, "", e.Arial, m.font_sz, e.col_grey8, m.accentLow, m.accentHigh, 0, 127, 1)
1153 | local seqAccProbSldr = e.Vert_Slider:new({2,3}, sx + (sp * 9) - (sw / 2), sy, sw, sh, e.col_blue, "%", e.Arial, m.font_sz, e.col_grey8, m.accentProb, 0, 0, 10, 1)
1154 | local seqAccSldrText = e.Textbox:new({2,3}, sx + (sp * 8) - (sw / 2), 210, (sw * 2) + 10, 20, e.col_grey5, "Vel | Acc", e.Arial, m.font_sz, e.col_grey7)
1155 |
1156 | -- legato slider
1157 | local seqLegProbSldr = e.Vert_Slider:new({2}, sx + (sp * 10) - (sw / 2), sy, sw, sh, e.col_blue, "%", e.Arial, m.font_sz, e.col_grey8, m.legatoProb, 0, 0, 10, 1)
1158 | local seqLegSldrText = e.Textbox:new({2}, sx + (sp * 10) - (sw / 2), 210, sw, 20, e.col_grey5, "Leg", e.Arial, m.font_sz, e.col_grey7)
1159 |
1160 | -- sequence shift buttons
1161 | local seqShiftLBtn = e.Button:new({2}, sx + (sp * 11) + 10, sy + sh - 25, sw, 25, e.col_blue, "<<", e.Arial, m.font_sz, e.col_grey8)
1162 | local seqShiftRBtn = e.Button:new({2}, sx + (sp * 13) - 10, sy + sh - 25, sw, 25, e.col_blue, ">>", e.Arial, m.font_sz, e.col_grey8)
1163 | local seqShiftVal = e.Textbox:new({2}, sx + (sp * 12), sy + sh - 25, sw, 25, e.col_grey5, tostring(m.seqShift), e.Arial, m.font_sz, e.col_grey7)
1164 | local seqShiftText = e.Textbox:new({2}, sx + (sp * 11) + 10, 210, sw * 3, 20, e.col_grey5, "Shift Notes", e.Arial, m.font_sz, e.col_grey7)
1165 |
1166 | -- Sequencer options
1167 | local seqOptionsCb = e.Checkbox:new({2}, sx+(np * 14) + 10, sy + 5, 30, 30, e.col_orange, "", e.Arial, m.font_sz, e.col_grey8, {0,0,0,0,0}, {"Generate", "1st Note Always", "Accent", "Legato", "Rnd Notes"})
1168 |
1169 |
1170 |
1171 |
1172 | -- Euclidean Layer -----------------------------------------------------------
1173 | --------------------------------------------------------------------------------
1174 |
1175 | -- euclidean generate button
1176 | local euclidBtn = e.Button:new({3}, 25, 205, 110, 25, e.col_orange, "Generate", Arial, m.font_sz, e.col_grey8)
1177 |
1178 | -- euclidean sliders
1179 | local ex, ey, ew, eh, ep = 160, 50, 30, 150, 40
1180 | local euclidPulsesSldr = e.Vert_Slider:new({3}, ex+(ep*3), ey, ew, eh, e.col_blue, "Puls", Arial, m.font_sz, e.col_grey8, m.eucPulses, 0, 1, 24, 1)
1181 | local euclidStepsSldr = e.Vert_Slider:new({3}, ex+(ep*4), ey, ew, eh, e.col_blue, "Step", Arial, m.font_sz, e.col_grey8, m.eucSteps, 0, 1, 24, 1)
1182 | local euclidRotationSldr = e.Vert_Slider:new({3}, ex+(ep*5), ey, ew, eh, e.col_blue, "Rot", Arial, m.font_sz, e.col_grey8, m.eucRot, 0, 0, 24, 1)
1183 | local t_euclidSliders = {euclidPulsesSldr, euclidStepsSldr, euclidRotationSldr}
1184 |
1185 | -- euclidean slider label - right click to reset all
1186 | local txtEuclidLabel = e.Textbox:new({3}, ex + (ep * 3), 210, (ew * 3) + 20, 20, e.col_grey5, "Euclid Sliders", Arial, m.font_sz, e.col_grey7)
1187 |
1188 | -- euclidean options
1189 | local eucOptionsCb = e.Checkbox:new({3}, ex + (ep * 14) + 10, ey + 40, 30, 30, e.col_orange, "", e.Arial, m.font_sz, e.col_grey8, {0,0,0}, {"Generate", "Accent", "Rnd Notes"})
1190 |
1191 |
1192 |
1193 | -- Options Layer -------------------------------------------------------------
1194 | --------------------------------------------------------------------------------
1195 | local optText = e.Textbox:new({4}, m.win_x + 10, m.win_y + 30, m.win_w - 40, m.win_h - 80, e.col_grey5, "Nothing to see here, yet...", e.Arial, m.font_sz, e.col_grey8)
1196 |
1197 |
1198 |
1199 | -- Messages Layer ------------------------------------------------------------
1200 | --------------------------------------------------------------------------------
1201 | local msgText = e.Textbox:new({9}, m.win_x + 10, m.win_y + 30, m.win_w - 40, m.win_h - 80, e.col_greym, "", e.Arial, 22, e.col_grey9)
1202 |
1203 |
1204 |
1205 | -- Shared Element Tables -----------------------------------------------------
1206 | --------------------------------------------------------------------------------
1207 | local t_Buttons = {randomBtn, shuffleBtn, sequenceBtn, seqShiftLBtn, seqShiftRBtn, euclidBtn}
1208 | local t_Checkboxes = {noteOptionsCb, seqOptionsCb, eucOptionsCb}
1209 | local t_RadButtons = {seqGridRad}
1210 | local t_RSliders = {octProbSldr, seqAccRSldr, seqAccProbSldr, seqLegProbSldr}
1211 | local t_Textboxes = {probSldrText, octProbText, seqGridText, seqSldrText, seqShiftVal, seqShiftText, seqAccSldrText, seqLegSldrText, txtEuclidLabel, optText, msgText}
1212 |
1213 |
1214 |
1215 |
1216 | -- main window gui functions -------------------------------------------------
1217 | --------------------------------------------------------------------------------
1218 |
1219 | zoomDrop.onLClick = function() -- Window zoom droplist - window scaling
1220 |
1221 | if zoomDrop.val1 == 1 then e.gScale = 0.7
1222 | elseif zoomDrop.val1 == 2 then e.gScale = 0.8
1223 | elseif zoomDrop.val1 == 3 then e.gScale = 0.9
1224 | elseif zoomDrop.val1 == 4 then e.gScale = 1
1225 | elseif zoomDrop.val1 == 5 then e.gScale = 1.1
1226 | elseif zoomDrop.val1 == 6 then e.gScale = 1.2
1227 | elseif zoomDrop.val1 == 7 then e.gScale = 1.4
1228 | elseif zoomDrop.val1 == 8 then e.gScale = 1.6
1229 | elseif zoomDrop.val1 == 9 then e.gScale = 1.8
1230 | elseif zoomDrop.val1 == 10 then e.gScale = 2.0
1231 | end
1232 |
1233 | -- Save state, close and reopen GFX window
1234 | if not pExtState.win_x then
1235 | __, m.win_x, m.win_y, __, __ = gfx.dock(-1,0,0,0,0)
1236 | else
1237 | -- set project ext state
1238 | pExtState.zoomDrop = zoomDrop.val1
1239 | pExtSaveStateF = true
1240 | end
1241 |
1242 | m.zoomF = true
1243 | end
1244 |
1245 | layerBtn01.onLClick = function() -- Layer 1 button - randomiser
1246 |
1247 | e.gActiveLayer = 1
1248 | zoomDrop.r, zoomDrop.g, zoomDrop.b, zoomDrop.a = table.unpack(e.col_green)
1249 | winText.r, winText.g, winText.b, winText.a = table.unpack(e.col_green)
1250 |
1251 | layerBtn01.font_rgba = e.col_grey8 -- highlight layer 1
1252 | layerBtn01.r, layerBtn01.g, layerBtn01.b, layerBtn01.a = table.unpack(e.col_green)
1253 |
1254 | layerBtn02.font_rgba = e.col_grey7
1255 | layerBtn02.r, layerBtn02.g, layerBtn02.b, layerBtn02.a = table.unpack(e.col_grey5)
1256 |
1257 | layerBtn03.font_rgba = e.col_grey7
1258 | layerBtn03.r, layerBtn03.g, layerBtn03.b, layerBtn03.a = table.unpack(e.col_grey5)
1259 |
1260 | layerBtn04.font_rgba = e.col_grey7
1261 | layerBtn04.r, layerBtn04.g, layerBtn04.b, layerBtn04.a = table.unpack(e.col_grey5)
1262 |
1263 | e.gScaleState = true
1264 |
1265 | -- set project ext state
1266 | pExtState.activeLayer = e.gActiveLayer
1267 | pExtSaveStateF = true
1268 | end
1269 |
1270 | layerBtn02.onLClick = function() -- Layer 2 button - sequencer
1271 |
1272 | e.gActiveLayer = 2
1273 | zoomDrop.r, zoomDrop.g, zoomDrop.b, zoomDrop.a = table.unpack(e.col_yellow)
1274 | winText.r, winText.g, winText.b, winText.a = table.unpack(e.col_yellow)
1275 |
1276 | layerBtn01.font_rgba = e.col_grey7
1277 | layerBtn01.r, layerBtn01.g, layerBtn01.b, layerBtn01.a = table.unpack(e.col_grey5)
1278 |
1279 | layerBtn02.font_rgba = e.col_grey8 -- highlight layer 2
1280 | layerBtn02.r, layerBtn02.g, layerBtn02.b, layerBtn02.a = table.unpack(e.col_yellow)
1281 |
1282 | layerBtn03.font_rgba = e.col_grey7
1283 | layerBtn03.r, layerBtn03.g, layerBtn03.b, layerBtn03.a = table.unpack(e.col_grey5)
1284 |
1285 | layerBtn04.font_rgba = e.col_grey7
1286 | layerBtn04.r, layerBtn04.g, layerBtn04.b, layerBtn04.a = table.unpack(e.col_grey5)
1287 |
1288 | e.gScaleState = true
1289 |
1290 | -- set project ext state
1291 | pExtState.activeLayer = e.gActiveLayer
1292 | pExtSaveStateF = true
1293 | end
1294 |
1295 | layerBtn03.onLClick = function() -- Layer 3 button - euclidean
1296 |
1297 | e.gActiveLayer = 3
1298 | zoomDrop.r, zoomDrop.g, zoomDrop.b, zoomDrop.a = table.unpack(e.col_orange)
1299 | winText.r, winText.g, winText.b, winText.a = table.unpack(e.col_orange)
1300 |
1301 | layerBtn01.font_rgba = e.col_grey7
1302 | layerBtn01.r, layerBtn01.g, layerBtn01.b, layerBtn01.a = table.unpack(e.col_grey5)
1303 |
1304 | layerBtn02.font_rgba = e.col_grey7
1305 | layerBtn02.r, layerBtn02.g, layerBtn02.b, layerBtn02.a = table.unpack(e.col_grey5)
1306 |
1307 | layerBtn03.font_rgba = e.col_grey8 -- highlight layer 3
1308 | layerBtn03.r, layerBtn03.g, layerBtn03.b, layerBtn03.a = table.unpack(e.col_orange)
1309 |
1310 | layerBtn04.font_rgba = e.col_grey7
1311 | layerBtn04.r, layerBtn04.g, layerBtn04.b, layerBtn04.a = table.unpack(e.col_grey5)
1312 |
1313 | e.gScaleState = true
1314 |
1315 | -- set project ext state
1316 | pExtState.activeLayer = e.gActiveLayer
1317 | pExtSaveStateF = true
1318 | end
1319 |
1320 | layerBtn04.onLClick = function() -- Layer 4 button - options
1321 |
1322 | e.gActiveLayer = 4
1323 | zoomDrop.r, zoomDrop.g, zoomDrop.b, zoomDrop.a = table.unpack(e.col_grey5)
1324 | winText.r, winText.g, winText.b, winText.a = table.unpack(e.col_grey5)
1325 |
1326 | layerBtn01.font_rgba = e.col_grey7
1327 | layerBtn01.r, layerBtn01.g, layerBtn01.b, layerBtn01.a = table.unpack(e.col_grey5)
1328 |
1329 | layerBtn02.font_rgba = e.col_grey7
1330 | layerBtn02.r, layerBtn02.g, layerBtn02.b, layerBtn02.a = table.unpack(e.col_grey5)
1331 |
1332 | layerBtn03.font_rgba = e.col_grey7
1333 | layerBtn03.r, layerBtn03.g, layerBtn03.b, layerBtn03.a = table.unpack(e.col_grey5)
1334 |
1335 | layerBtn04.font_rgba = e.col_grey8 -- highlight layer 4
1336 | layerBtn04.r, layerBtn04.g, layerBtn04.b, layerBtn04.a = table.unpack(e.col_grey6)
1337 |
1338 | e.gScaleState = true
1339 |
1340 | -- set project ext state
1341 | pExtState.activeLayer = e.gActiveLayer
1342 | pExtSaveStateF = true
1343 | end
1344 |
1345 | undoBtn.onLClick = function() -- Undo button
1346 | UndoNoteBuf()
1347 | InsertNotes()
1348 | end
1349 |
1350 | redoBtn.onLClick = function() -- Redo button
1351 |
1352 | if m.notebuf[m.notebuf.i + 1] ~= nil then
1353 | m.notebuf.i = m.notebuf.i + 1
1354 | InsertNotes()
1355 | end
1356 | end
1357 |
1358 | -- defaults
1359 | function SetDefaultWindowOpts() -- Set default window options
1360 |
1361 | if pExtState.zoomDrop then
1362 | zoomDrop.val1 = pExtState.zoomDrop
1363 | end
1364 |
1365 | if pExtState.win_x or pExtState.win_y then
1366 | m.win_x = pExtState.win_x
1367 | m.win_y = pExtState.win_y
1368 | end
1369 | zoomDrop.onLClick()
1370 | end
1371 |
1372 | function SetDefaultLayer() -- Set default layer
1373 |
1374 | if pExtState.activeLayer then
1375 | if pExtState.activeLayer == 1 then layerBtn01.onLClick()
1376 | elseif pExtState.activeLayer == 2 then layerBtn02.onLClick()
1377 | elseif pExtState.activeLayer == 3 then layerBtn03.onLClick()
1378 | elseif pExtState.activeLayer == 4 then layerBtn04.onLClick()
1379 | end
1380 | end
1381 | end
1382 |
1383 |
1384 |
1385 | -- randomiser gui functions --------------------------------------------------
1386 | --------------------------------------------------------------------------------
1387 |
1388 | randomBtn.onLClick = function() -- Random button action
1389 |
1390 | if m.activeTake and m.mItem then
1391 | m.seqShift = 0; m.seqShiftMin = 0; m.seqShiftMax = 0 -- reset shift
1392 | seqShiftVal.label = tostring(m.seqShift)
1393 | GenProbTable(m.preNoteProbTable, t_noteSliders, m.noteProbTable)
1394 | if #m.noteProbTable == 0 then return end
1395 | GenOctaveTable(m.octProbTable, octProbSldr)
1396 | GetNotesFromTake()
1397 | RandomiseNotes()
1398 |
1399 | -- set project ext state
1400 | pExtState.noteSliders = {}
1401 |
1402 | for k, v in pairs(t_noteSliders) do
1403 | pExtState.noteSliders[k] = v.val1
1404 | end
1405 |
1406 | pExtState.rndOctProb = octProbSldr.val1
1407 | pExtSaveStateF = true
1408 | end --m.activeTake
1409 | end
1410 |
1411 | shuffleBtn.onLClick = function() -- Shuffle button action
1412 |
1413 | if m.activeTake and m.mItem then
1414 | m.seqShift = 0; m.seqShiftMin = 0; m.seqShiftMax = 0 -- reset shift
1415 | seqShiftVal.label = tostring(m.seqShift)
1416 | GetNotesFromTake()
1417 | ShuffleNotes()
1418 | end
1419 |
1420 | end
1421 |
1422 | noteOptionsCb.onLClick = function() -- Randomiser options toggle logic
1423 |
1424 | m.rndAllNotesF = noteOptionsCb.val1[1] == 1 and true or false -- All / Sel Notes
1425 | m.rndFirstNoteF = noteOptionsCb.val1[2] == 1 and true or false -- 1st Note Root
1426 | m.rndOctX2F = noteOptionsCb.val1[3] == 1 and true or false -- Octave X2
1427 |
1428 | pExtState.noteOptionsCb = {m.rndAllNotesF, m.rndFirstNoteF, m.rndOctX2F}
1429 | pExtSaveStateF = true
1430 |
1431 | end
1432 |
1433 | keyDrop.onLClick = function() -- Root Key droplist
1434 |
1435 | m.key = keyDrop.val1
1436 | m.root = SetRootNote(m.oct, m.key)
1437 | UpdateSliderLabels(t_noteSliders, m.preNoteProbTable)
1438 |
1439 | -- set project ext state
1440 | pExtState.key = m.key
1441 | pExtState.root = m.root
1442 | pExtSaveStateF = true
1443 | end
1444 |
1445 | octDrop.onLClick = function() -- Octave droplist
1446 |
1447 | m.oct = octDrop.val1
1448 | m.root = SetRootNote(m.oct, m.key)
1449 |
1450 | -- set project ext state
1451 | pExtState.oct = m.oct
1452 | pExtState.root = m.root
1453 | pExtSaveStateF = true
1454 | end
1455 |
1456 | scaleDrop.onLClick = function() -- Scale droplist
1457 |
1458 | SetScale(scaleDrop.val2[scaleDrop.val1], m.scales, m.preNoteProbTable)
1459 | UpdateSliderLabels(t_noteSliders, m.preNoteProbTable)
1460 |
1461 | -- set project ext state
1462 | pExtState.curScaleName = scaleDrop.val2[scaleDrop.val1]
1463 | pExtSaveStateF = true
1464 | end
1465 |
1466 | probSldrText.onRClick = function() -- Reset note probability sliders
1467 |
1468 | gfx.x = gfx.mouse_x; gfx.y = gfx.mouse_y
1469 | local result = gfx.showmenu("Reset Note Sliders")
1470 |
1471 | if result == 1 then
1472 |
1473 | for k, v in pairs(t_noteSliders) do -- reset the sliders
1474 | if v.label ~= "" then v.val1 = 1 end
1475 | end -- in pairs(t_noteSliders)
1476 |
1477 | if pExtState.noteSliders then -- write the new proj ext state
1478 | for k, v in pairs(t_noteSliders) do
1479 | if v.label ~= "" then pExtState.noteSliders[k] = v.val1 end
1480 | end -- in pairs(t_noteSliders)
1481 | end -- pExtState.noteSliders
1482 |
1483 | pExtSaveStateF = true -- set the ext state save flag
1484 | end -- result
1485 | end
1486 |
1487 | octProbText.onRClick = function() -- Reset octave probability slider
1488 |
1489 | gfx.x = gfx.mouse_x; gfx.y = gfx.mouse_y
1490 | local result = gfx.showmenu("Reset Octave Slider")
1491 |
1492 | if result == 1 then
1493 | octProbSldr.val1 = m.rndOctProb
1494 |
1495 | if pExtState.rndOctProb then -- write the new proj ext state
1496 | pExtState.rndOctProb = nil
1497 | end -- pExtState.noteSliders
1498 |
1499 | pExtSaveStateF = true -- set the ext state save flag
1500 | end -- result
1501 | end
1502 |
1503 | -- defaults
1504 | function SetDefaultScaleOpts() -- Set default scale options
1505 |
1506 | -- if key saved in project state, load it
1507 | if pExtState.key then
1508 | m.key = math.floor(tonumber(pExtState.key))
1509 | keyDrop.val1 = m.key
1510 | end
1511 |
1512 | -- if octave saved in project state, load it
1513 | if pExtState.oct then
1514 | m.oct = math.floor(tonumber(pExtState.oct))
1515 | octDrop.val1 = m.oct
1516 | end
1517 |
1518 | -- set the midi note number for scale root
1519 | m.root = SetRootNote(m.oct, m.key)
1520 |
1521 | -- create a scale name lookup table for the gui (scaleDrop)
1522 | for k, v in pairs(m.scales) do
1523 | m.scalelist[k] = m.scales[k]["name"]
1524 | end
1525 |
1526 | -- if scale name saved in project state, load it
1527 | if pExtState.curScaleName then
1528 | m.curScaleName = pExtState.curScaleName
1529 | end
1530 |
1531 | -- update the scale dropbox val1 to match the scale table index
1532 | for k, v in pairs(m.scales) do
1533 | if v.name == m.curScaleName then scaleDrop.val1 = k end
1534 | end
1535 |
1536 | SetScale(m.curScaleName, m.scales, m.preNoteProbTable) --set chosen scale
1537 | UpdateSliderLabels(t_noteSliders, m.preNoteProbTable) -- set sliders labels to current scale notes
1538 | end
1539 |
1540 | function SetDefaultRndOptions() -- Set default randomiser options
1541 |
1542 | -- if randomiser options were saved to project state, load them
1543 | if pExtState.noteOptionsCb then
1544 | m.rndAllNotesF = pExtState.noteOptionsCb[1] == true and true or false
1545 | m.rndFirstNoteF = pExtState.noteOptionsCb[2] == true and true or false
1546 | m.rndOctX2F = pExtState.noteOptionsCb[3] == true and true or false
1547 | end
1548 |
1549 | -- set randomiser options using defaults, or loaded project state
1550 | noteOptionsCb.val1[1] = (true and m.rndAllNotesF) and 1 or 0 -- all notes
1551 | noteOptionsCb.val1[2] = (true and m.rndFirstNoteF) and 1 or 0 -- first note root
1552 | noteOptionsCb.val1[3] = (true and m.rndOctX2F) and 1 or 0 -- octave doubler
1553 | end
1554 |
1555 | function SetDefaultRndSliders() -- Set default randomiser sliders
1556 |
1557 | -- if randomiser sliders were saved to project state, load them
1558 | if pExtState.noteSliders then
1559 | for k, v in pairs(t_noteSliders) do
1560 | v.val1 = pExtState.noteSliders[k]
1561 | end
1562 | else
1563 | for k, v in pairs(t_noteSliders) do
1564 | v.val1 = 1
1565 | end
1566 | end -- load note sliders pExtState
1567 |
1568 | if pExtState.rndOctProb then -- octave probability slider
1569 | octProbSldr.val1 = pExtState.rndOctProb
1570 | else
1571 | octProbSldr.val1 = m.rndOctProb
1572 | end
1573 | end
1574 |
1575 |
1576 |
1577 | -- sequencer gui functions ---------------------------------------------------
1578 | --------------------------------------------------------------------------------
1579 |
1580 | sequenceBtn.onLClick = function() -- Sequencer button
1581 |
1582 | if m.activeTake and m.mItem then
1583 | m.seqShift = 0; m.seqShiftMin = 0; m.seqShiftMax = 0 -- reset shift on new sequence
1584 | seqShiftVal.label = tostring(m.seqShift)
1585 |
1586 | if m.seqF then
1587 | SetSeqGridSizes(t_seqSliders)
1588 | GenProbTable(m.preSeqProbTable, t_seqSliders, m.seqProbTable)
1589 | GenAccentTable(m.accProbTable, seqAccRSldr, seqAccProbSldr)
1590 | GenLegatoTable(m.legProbTable, seqLegProbSldr)
1591 | GetNotesFromTake()
1592 | GenSequence(m.seqProbTable, m.accProbTable, seqAccRSldr, m.legProbTable)
1593 | if m.seqRndNotesF then
1594 | randomBtn.onLClick() -- call RandomiseNotes
1595 | end
1596 |
1597 | else -- not m.seqF
1598 | GenAccentTable(m.accProbTable, seqAccRSldr, seqAccProbSldr)
1599 | GenLegatoTable(m.legProbTable, seqLegProbSldr)
1600 | GetNotesFromTake()
1601 | GenNoteAttributes(m.seqAccentF, m.accProbTable, seqAccRSldr, m.seqLegatoF, m.legProbTable)
1602 | if m.seqRndNotesF then
1603 | randomBtn.onLClick() -- call RandomiseNotes
1604 | end
1605 | end -- m.seqF
1606 |
1607 | -- set project ext state
1608 | if seqGridRad.val1 == 1 then -- 1/16 grid
1609 | pExtState.seqGrid16 = {}
1610 | for k, v in pairs (t_seqSliders) do
1611 | pExtState.seqGrid16[k] = v.val1
1612 | end
1613 | end
1614 |
1615 | if seqGridRad.val1 == 2 then -- 1/8 grid
1616 | pExtState.seqGrid8 = {}
1617 | for k, v in pairs (t_seqSliders) do
1618 | pExtState.seqGrid8[k] = v.val1
1619 | end
1620 | end
1621 |
1622 | if seqGridRad.val1 == 3 then -- 1/4 grid
1623 | pExtState.seqGrid4 = {}
1624 | for k, v in pairs (t_seqSliders) do
1625 | pExtState.seqGrid4[k] = v.val1
1626 | end
1627 | end
1628 |
1629 | pExtState.seqAccRSldrLo = seqAccRSldr.val1
1630 | pExtState.seqAccRSldrHi = seqAccRSldr.val2
1631 | pExtState.seqAccProb = seqAccProbSldr.val1
1632 | pExtState.seqLegProb = seqLegProbSldr.val1
1633 | pExtSaveStateF = true
1634 | end --m.activeTake
1635 | end
1636 |
1637 | seqOptionsCb.onLClick = function() -- Sequencer options toggle logic
1638 |
1639 | m.seqF = seqOptionsCb.val1[1] == 1 and true or false -- Generate
1640 | m.seqFirstNoteF = seqOptionsCb.val1[2] == 1 and true or false -- 1st Note Always
1641 | m.seqAccentF = seqOptionsCb.val1[3] == 1 and true or false -- Accent
1642 | m.seqLegatoF = seqOptionsCb.val1[4] == 1 and true or false -- Legato
1643 | m.seqRndNotesF = seqOptionsCb.val1[5] == 1 and true or false -- Randomise Notes
1644 | m.seqRepeatF = seqOptionsCb.val1[6] == 1 and true or false -- Repeat
1645 |
1646 | pExtState.seqOptionsCb = {m.seqF, m.seqFirstNoteF, m.seqAccentF, m.seqLegatoF, m.seqRndNotesF, m.seqRepeatF}
1647 | pExtSaveStateF = true
1648 |
1649 | end
1650 |
1651 | seqGridRad.onLClick = function() -- Sequencer grid radio button
1652 |
1653 | if m.activeTake then
1654 |
1655 | if seqGridRad.val1 == 1 then -- 1/16 grid
1656 | reaper.MIDIEditor_OnCommand(m.activeEditor, 40192) -- set grid
1657 | if pExtState.seqGrid16 then
1658 | for k, v in pairs(t_seqSliders) do
1659 | v.val1 = pExtState.seqGrid16[k]
1660 | end -- in pairs(t_seqSliders)
1661 | else -- not pExtState.seqGrid16
1662 | for k, v in pairs(t_seqSliders) do
1663 | v.val1 = m.seqGrid16[k]
1664 | end -- in pairs(t_seqSliders)
1665 | end -- if pExtState.seqGrid16
1666 |
1667 | elseif seqGridRad.val1 == 2 then -- 1/8 grid
1668 | reaper.MIDIEditor_OnCommand(m.activeEditor, 40197) -- set grid
1669 | if pExtState.seqGrid8 then
1670 | for k, v in pairs(t_seqSliders) do
1671 | v.val1 = pExtState.seqGrid8[k]
1672 | end -- in pairs(t_seqSliders)
1673 | else -- not pExtState.seqGrid8
1674 | for k, v in pairs(t_seqSliders) do
1675 | v.val1 = m.seqGrid8[k]
1676 | end -- in pairs(t_seqSliders)
1677 | end -- if pExtState.seqGrid8
1678 |
1679 | elseif seqGridRad.val1 == 3 then -- 1/4 grid
1680 | reaper.MIDIEditor_OnCommand(m.activeEditor, 40201) -- set grid
1681 | if pExtState.seqGrid4 then -- 1/4 grid
1682 | for k, v in pairs(t_seqSliders) do
1683 | v.val1 = pExtState.seqGrid4[k]
1684 | end -- in pairs(t_seqSliders)
1685 | else -- not pExtState.seqGrid4
1686 | for k, v in pairs(t_seqSliders) do
1687 | v.val1 = m.seqGrid4[k]
1688 | end -- in pairs(t_seqSliders)
1689 | end -- pExtState.seqGrid4
1690 | end -- seGridRad
1691 |
1692 | -- reset the shift state
1693 | m.seqShift = 0; m.seqShiftMin = 0; m.seqShiftMax = 0
1694 | seqShiftVal.label = tostring(m.seqShift)
1695 | GetNotesFromTake() -- force an undo point on grid change
1696 | --InsertNotes()
1697 |
1698 | pExtSaveStateF = true
1699 |
1700 | end -- m.activeTake
1701 | end
1702 |
1703 | seqShiftLBtn.onLClick = function() -- Sequencer shift left
1704 |
1705 | if not m.mItem then return end
1706 | local gridSize = m.reaGrid * m.ppqn
1707 | local itemLength = GetItemLength()
1708 | m.seqShiftMin = -(math.floor(itemLength / gridSize)-1)
1709 |
1710 | if m.seqShift <= m.seqShiftMin then
1711 | m.seqShift = 0
1712 | else
1713 | m.seqShift = m.seqShift - 1
1714 | end
1715 |
1716 | seqShiftVal.label = tostring(m.seqShift)
1717 | InsertNotes()
1718 | end
1719 |
1720 | seqShiftRBtn.onLClick = function() -- Sequencer shift right
1721 |
1722 | if not m.mItem then return end
1723 |
1724 | local gridSize = m.reaGrid * m.ppqn
1725 | local itemLength = GetItemLength()
1726 | m.seqShiftMax = math.floor(itemLength / gridSize) - 1
1727 |
1728 | if m.seqShift >= m.seqShiftMax then
1729 | m.seqShift = 0
1730 | else
1731 | m.seqShift = m.seqShift + 1
1732 | end
1733 |
1734 | seqShiftVal.label = tostring(m.seqShift)
1735 | InsertNotes()
1736 | end
1737 |
1738 | seqSldrText.onRClick = function() -- Reset sequencer grid sliders
1739 |
1740 | gfx.x = gfx.mouse_x; gfx.y = gfx.mouse_y
1741 | local result = gfx.showmenu("Reset Sequence Sliders")
1742 |
1743 | if result == 1 then
1744 | if seqGridRad.val1 == 1 then -- 1/16ths
1745 | for k, v in pairs(t_seqSliders) do -- reset the sliders
1746 | v.val1 = m.seqGrid16[k]
1747 | end -- in pairs(t_seqSliders)
1748 | pExtState.seqGrid16 = nil
1749 |
1750 | elseif seqGridRad.val1 == 2 then -- 1/8ths
1751 | for k, v in pairs(t_seqSliders) do -- reset the sliders
1752 | v.val1 = m.seqGrid8[k]
1753 | end -- in pairs(t_seqSliders)
1754 | pExtState.seqGrid8 = nil
1755 |
1756 | elseif seqGridRad.val1 == 3 then -- 1/4ths
1757 | for k, v in pairs(t_seqSliders) do -- reset the sliders
1758 | v.val1 = m.seqGrid4[k]
1759 | end -- in pairs(t_seqSliders)
1760 | pExtState.seqGrid4 = nil
1761 |
1762 | end -- seqGridRad
1763 | pExtSaveStateF = true -- set the ext state save flag
1764 | end -- result
1765 | end
1766 |
1767 | seqAccSldrText.onRClick = function() -- Reset sequencer velocity slider
1768 |
1769 | gfx.x = gfx.mouse_x; gfx.y = gfx.mouse_y
1770 | local result = gfx.showmenu("Reset Accent Sliders")
1771 |
1772 | if result == 1 then
1773 | seqAccRSldr.val1 = m.accentLow
1774 | if pExtState.seqAccRSldrLo then pExtState.seqAccRSldrLo = nil end
1775 | seqAccRSldr.val2 = m.accentHigh
1776 | if pExtState.seqAccRSldrHi then pExtState.seqAccRSldrHi = nil end
1777 | seqAccProbSldr.val1 = m.accentProb
1778 | if pExtState.seqAccProb then pExtState.seqAccProb = nil end
1779 |
1780 | pExtSaveStateF = true -- set the ext state save flag
1781 | end -- result
1782 | end
1783 |
1784 | seqLegSldrText.onRClick = function() -- Reset sequencer legato slider
1785 |
1786 | gfx.x = gfx.mouse_x; gfx.y = gfx.mouse_y
1787 | local result = gfx.showmenu("Reset Legato Slider")
1788 |
1789 | if result == 1 then
1790 | seqLegProbSldr.val1 = m.legatoProb
1791 | if pExtState.seqLegProb then pExtState.seqLegProb = nil end
1792 | pExtSaveStateF = true
1793 | end -- result
1794 | end
1795 |
1796 | seqShiftText.onRClick = function() -- Reset sequencer shift
1797 |
1798 | gfx.x = gfx.mouse_x; gfx.y = gfx.mouse_y
1799 | local result = gfx.showmenu("Reset Note Shift")
1800 |
1801 | if result == 1 then
1802 | m.seqShift = 0; m.seqShiftMin = 0; m.seqShiftMax = 0
1803 | seqShiftVal.label = tostring(m.seqShift)
1804 | InsertNotes()
1805 | end -- result
1806 | end
1807 |
1808 | -- defaults
1809 | function SetDefaultSeqOptions() -- Set sequencer default options
1810 |
1811 | -- if sequencer options were saved to project state, load them
1812 | if pExtState.seqOptionsCb then
1813 | m.seqF = pExtState.seqOptionsCb[1] == true and true or false
1814 | m.seqFirstNoteF = pExtState.seqOptionsCb[2] == true and true or false
1815 | m.seqAccentF = pExtState.seqOptionsCb[3] == true and true or false
1816 | m.seqLegatoF = pExtState.seqOptionsCb[4] == true and true or false
1817 | m.seqRndNotesF = pExtState.seqOptionsCb[5] == true and true or false
1818 | m.seqRepeatF = pExtState.seqOptionsCb[6] == true and true or false
1819 | end
1820 |
1821 | -- set sequencer options using defaults, or loaded project state
1822 | seqOptionsCb.val1[1] = (true and m.seqF) and 1 or 0 -- generate
1823 | seqOptionsCb.val1[2] = (true and m.seqFirstNoteF) and 1 or 0 -- 1st Note Always
1824 | seqOptionsCb.val1[3] = (true and m.seqAccentF) and 1 or 0 -- accent
1825 | seqOptionsCb.val1[4] = (true and m.seqLegatoF) and 1 or 0 -- legato
1826 | seqOptionsCb.val1[5] = (true and m.seqRndNotesF) and 1 or 0 -- random notes
1827 | seqOptionsCb.val1[6] = (true and m.seqRepeatF) and 1 or 0 -- repeat
1828 | end
1829 |
1830 | function SetDefaultAccLegSliders() -- Set default accent & legato sliders
1831 |
1832 | -- if seq accent & legato sliders were saved to project state, load them
1833 | if pExtState.seqAccRSldrLo then
1834 | seqAccRSldr.val1 = pExtState.seqAccRSldrLo
1835 | else
1836 | seqAccRSldr.val1 = m.accentLow
1837 | end
1838 |
1839 | if pExtState.seqAccRSldrHi then
1840 | seqAccRSldr.val2 = pExtState.seqAccRSldrHi
1841 | else
1842 | seqAccRSldr.val2 = m.accentHigh
1843 | end
1844 |
1845 | if pExtState.seqAccProb then
1846 | seqAccProbSldr.val1 = pExtState.seqAccProb
1847 | else
1848 | seqAccProbSldr.val1 = m.accentProb
1849 | end
1850 |
1851 | if pExtState.seqLegProb then
1852 | seqLegProbSldr.val1 = pExtState.seqLegProb
1853 | else
1854 | seqLegProbSldr.val1 = m.legatoProb
1855 | end
1856 | end
1857 |
1858 | function SetDefaultSeqGridSliders() -- Set default grid sliders
1859 |
1860 | GetReaperGrid(seqGridRad)
1861 | SetSeqGridSizes(t_seqSliders)
1862 |
1863 | if seqGridRad.val1 == 1 then
1864 | if pExtState.seqGrid16 then -- 1/16 grid
1865 | for k, v in pairs(t_seqSliders) do
1866 | v.val1 = pExtState.seqGrid16[k]
1867 | end
1868 | else -- not pExtState.seqGrid16
1869 | for k, v in pairs(t_seqSliders) do
1870 | v.val1 = m.seqGrid16[k]
1871 | end
1872 | end -- pExtState.seqGrid16
1873 |
1874 | elseif seqGridRad.val1 == 2 then
1875 | if pExtState.seqGrid8 then -- 1/8 grid
1876 | for k, v in pairs(t_seqSliders) do
1877 | v.val1 = pExtState.seqGrid8[k]
1878 | end
1879 | else -- not pExtState.seqGrid8
1880 | for k, v in pairs(t_seqSliders) do
1881 | v.val1 = m.seqGrid8[k]
1882 | end
1883 | end -- pExtState.seqGrid8
1884 |
1885 | elseif seqGridRad.val1 == 3 then
1886 | if pExtState.seqGrid4 then -- 1/4 grid
1887 | for k, v in pairs(t_seqSliders) do
1888 | v.val1 = pExtState.seqGrid4[k]
1889 | end
1890 | else -- not pExtState.seqGrid4
1891 | for k, v in pairs(t_seqSliders) do
1892 | v.val1 = m.seqGrid4[k]
1893 | end
1894 | end
1895 | end -- pExtState.seqGrid4
1896 |
1897 | end
1898 |
1899 | function SetDefaultSeqShift() -- Set default sequencer shift state
1900 |
1901 | m.seqShift = 0
1902 | m.seqShiftMin = 0
1903 | m.seqShiftMax = 0
1904 | seqShiftVal.label = tostring(m.seqShift)
1905 | end
1906 |
1907 |
1908 |
1909 | -- euclidiser gui functions --------------------------------------------------
1910 | --------------------------------------------------------------------------------
1911 |
1912 | euclidBtn.onLClick = function() -- Euclidiser button
1913 |
1914 | if m.activeTake and m.mItem then
1915 | if m.eucF then
1916 | GenAccentTable(m.accProbTable, seqAccRSldr, seqAccProbSldr)
1917 | GetNotesFromTake()
1918 | GenBjorklund(euclidPulsesSldr, euclidStepsSldr, euclidRotationSldr, m.accProbTable, seqAccRSldr)
1919 | if m.eucRndNotesF then
1920 | randomBtn.onLClick() -- call RandomiseNotes
1921 | end
1922 |
1923 | else -- not m.eucF
1924 | GenAccentTable(m.accProbTable, seqAccRSldr, seqAccProbSldr)
1925 | GetNotesFromTake()
1926 | GenNoteAttributes(m.eucAccentF, m.accProbTable, seqAccRSldr, false, m.legProbTable)
1927 |
1928 | if m.eucRndNotesF then
1929 | randomBtn.onLClick() -- call RandomiseNotes
1930 | end
1931 | end -- m.eucF
1932 |
1933 | -- set project ext state
1934 | pExtState.eucSliders = {}
1935 | for k, v in pairs(t_euclidSliders) do
1936 | pExtState.eucSliders[k] = v.val1
1937 | end
1938 | pExtSaveStateF = true
1939 | end -- m.activeTake
1940 | end
1941 |
1942 | eucOptionsCb.onLClick = function() -- Euclidiser options
1943 |
1944 | m.eucF = eucOptionsCb.val1[1] == 1 and true or false -- Generate
1945 | m.eucAccentF = eucOptionsCb.val1[2] == 1 and true or false -- Accent
1946 | m.eucRndNotesF = eucOptionsCb.val1[3] == 1 and true or false -- Randomise notes
1947 | pExtState.eucOptionsCb = {m.eucF, m.eucAccentF, m.eucRndNotesF}
1948 | pExtSaveStateF = true
1949 |
1950 | end
1951 |
1952 | euclidPulsesSldr.onMove = function() -- Euclid pulses slider
1953 |
1954 | if euclidPulsesSldr.val1 > euclidStepsSldr.val1 then -- pulses > steps
1955 | euclidStepsSldr.val1 = euclidPulsesSldr.val1
1956 | euclidRotationSldr.max = euclidStepsSldr.val1
1957 | end
1958 | end
1959 |
1960 | euclidStepsSldr.onMove = function() -- Euclid steps slider
1961 |
1962 | if euclidStepsSldr.val1 < euclidPulsesSldr.val1 then -- steps < pulses
1963 | euclidPulsesSldr.val1 = euclidStepsSldr.val1
1964 | end
1965 | if euclidStepsSldr.val1 < euclidRotationSldr.val1 then -- steps < rotation
1966 | euclidRotationSldr.val1 = euclidStepsSldr.val1
1967 | euclidRotationSldr.max = euclidRotationSldr.val1
1968 | end
1969 | if euclidStepsSldr.val1 > euclidRotationSldr.max then -- steps > max rotation
1970 | euclidRotationSldr.max = euclidStepsSldr.val1
1971 | end
1972 | end
1973 |
1974 | euclidRotationSldr.onMove = function() -- Euclid rotation slider
1975 |
1976 | euclidRotationSldr.max = euclidStepsSldr.val1
1977 | if euclidRotationSldr.val1 > euclidStepsSldr.val1 then
1978 | euclidRotationSldr.val1 = euclidStepsSldr.val1
1979 | euclidRotationSldr.max = euclidRotationSldr.val1
1980 | end
1981 | end
1982 |
1983 | txtEuclidLabel.onRClick = function() -- Reset euclidean sliders
1984 |
1985 | gfx.x = gfx.mouse_x; gfx.y = gfx.mouse_y
1986 | local result = gfx.showmenu("Reset Euclid Sliders")
1987 |
1988 | if result == 1 then
1989 | euclidPulsesSldr.val1 = m.eucPulses
1990 | euclidStepsSldr.val1 = m.eucSteps
1991 | euclidRotationSldr.val1 = m.eucRot
1992 | pExtSaveStateF = true
1993 | pExtState.eucSliders = nil
1994 | end -- result
1995 | end
1996 |
1997 | function SetDefaultEucOptions() -- Set default euclid options
1998 |
1999 | -- if euclidean options were saved to project state, load them
2000 | if pExtState.eucOptionsCb then
2001 | m.eucF = pExtState.eucOptionsCb[1] == true and true or false
2002 | m.eucAccentF = pExtState.eucOptionsCb[2] == true and true or false
2003 | m.eucRndNotesF = pExtState.eucOptionsCb[3] == true and true or false
2004 | end
2005 | -- set euclidean options using defaults, or loaded project state
2006 | eucOptionsCb.val1[1] = (true and m.eucF) and 1 or 0 -- generate
2007 | eucOptionsCb.val1[2] = (true and m.eucAccentF) and 1 or 0 -- accents
2008 | eucOptionsCb.val1[3] = (true and m.eucRndNotesF) and 1 or 0 -- randomise notes
2009 | end
2010 |
2011 | function SetDefaultEucSliders() -- Set default euclid sliders
2012 |
2013 | -- if euclidean sliders were saved to project state, load them
2014 | if pExtState.eucSliders then
2015 | for k, v in pairs(t_euclidSliders) do
2016 | v.val1 = pExtState.eucSliders[k]
2017 | end
2018 | else
2019 | euclidPulsesSldr.val1 = m.eucPulses
2020 | euclidStepsSldr.val1 = m.eucSteps
2021 | euclidRotationSldr.val1 = m.eucRot
2022 | end -- load pExtState
2023 | end
2024 |
2025 |
2026 |
2027 | -- draw GUI ------------------------------------------------------------------
2028 | --------------------------------------------------------------------------------
2029 |
2030 | function DrawGUI()
2031 |
2032 | for key, winElms in pairs(t_winElements) do winElms:draw() end
2033 | --for key, frame in pairs(t_Frames) do frame:draw() end
2034 | for key, check in pairs(t_Checkboxes) do check:draw() end
2035 | for key, radio in pairs(t_RadButtons) do radio:draw() end
2036 | for key, btn in pairs(t_Buttons) do btn:draw() end
2037 | for key, dlist in pairs(t_Droplists) do dlist:draw() end
2038 | --for key, knb in pairs(t_Knobs) do knb:draw() end
2039 | for key, rsliders in pairs(t_RSliders) do rsliders:draw() end
2040 | for key, nsldrs in pairs(t_noteSliders) do nsldrs:draw() end
2041 | for key, ssldrs in pairs(t_seqSliders) do ssldrs:draw() end
2042 | for key, esldrs in pairs(t_euclidSliders) do esldrs:draw() end
2043 | for key, textb in pairs(t_Textboxes) do textb:draw() end
2044 |
2045 | end
2046 |
2047 |
2048 |
2049 | -- init ----------------------------------------------------------------------
2050 | --------------------------------------------------------------------------------
2051 |
2052 | function Init()
2053 |
2054 | math.randomseed(os.time())
2055 | for i = 1, 15 do math.random() end -- lua quirk, first random call always returns the same value...
2056 | reaper.ClearConsole()
2057 |
2058 | -- grab the midi editor, and active take
2059 | m.activeEditor = reaper.MIDIEditor_GetActive()
2060 | if m.activeEditor then
2061 | m.activeTake = reaper.MIDIEditor_GetTake(m.activeEditor)
2062 | __ = NewNoteBuf()
2063 | if not m.activeTake then ConMsg("Init() - No Active Take") end
2064 | else
2065 | ConMsg("Init() - No Active MIDI Editor")
2066 | end -- m.activeEditor
2067 |
2068 | -- Load ProjectExtState
2069 | if pExtLoadStateF then
2070 | __, pExtStateStr = reaper.GetProjExtState(0, "MEM", "pExtState")
2071 | if pExtStateStr ~= "" then
2072 | pExtState = unpickle(pExtStateStr)
2073 | end -- pExtStateStr
2074 | end -- pExtLoadStateF
2075 |
2076 | -- set GUI defaults or restore from project state
2077 | SetDefaultWindowOpts(); SetDefaultLayer()
2078 | SetDefaultScaleOpts()
2079 | SetDefaultRndOptions(); SetDefaultRndSliders()
2080 | SetDefaultSeqOptions(); SetDefaultSeqShift()
2081 | SetDefaultSeqGridSliders(); SetDefaultAccLegSliders()
2082 | SetDefaultEucOptions(); SetDefaultEucSliders()
2083 | m.mItem = reaper.GetSelectedMediaItem(0, 0)
2084 |
2085 | GetNotesFromTake() -- grab the original note data (if any...)
2086 | end
2087 |
2088 | function InitGFX()
2089 | -- Init window ------
2090 | gfx.clear = RGB2Packed(table.unpack(m.win_bg))
2091 | gfx.init(m.win_title, m.win_w * e.gScale, m.win_h * e.gScale, m.win_dockstate, m.win_x, m.win_y)
2092 |
2093 | -- Last mouse position and state
2094 | gLastMouseCap, gLastMouseX, gLastMouseY = 0, 0, 0
2095 | gMouseOX, gMouseOY = -1, -1
2096 | end
2097 |
2098 |
2099 |
2100 | -- main ----------------------------------------------------------------------
2101 | --------------------------------------------------------------------------------
2102 |
2103 | function MainLoop()
2104 |
2105 | -- Update mouse state and position
2106 | if gfx.mouse_cap & 1 == 1 and gLastMouseCap & 1 == 0 or -- L mouse
2107 | gfx.mouse_cap & 2 == 2 and gLastMouseCap & 2 == 0 or -- R mouse
2108 | gfx.mouse_cap & 64 == 64 and gLastMouseCap & 64 == 0 then -- M mouse
2109 | gMouseOX, gMouseOY = gfx.mouse_x, gfx.mouse_y
2110 | end
2111 |
2112 | -- Set modifier keys
2113 | Ctrl = gfx.mouse_cap & 4 == 4
2114 | Shift = gfx.mouse_cap & 8 == 8
2115 | Alt = gfx.mouse_cap & 16 == 16
2116 |
2117 | -- Check and save window position
2118 | __, pExtState.win_x, pExtState.win_y, __, __ = gfx.dock(-1,0,0,0,0)
2119 | if m.win_x ~= pExtState.win_x or m.win_y ~= pExtState.win_y then
2120 | m.win_x = pExtState.win_x
2121 | m.win_y = pExtState.win_y
2122 | pExtSaveStateF = true
2123 | end
2124 |
2125 | -- if resized, set scale flag and reset gfx
2126 | if m.zoomF == true then
2127 | e.gScaleState = true
2128 | gfx.quit()
2129 | InitGFX()
2130 | m.zoomF = false
2131 | end
2132 |
2133 | DrawGUI()
2134 | e.gScaleState = false -- prevent zoom code from running every loop
2135 |
2136 | -- Save last mouse state since GUI was refreshed
2137 | gLastMouseCap = gfx.mouse_cap
2138 | gLastMouseX, gLastMouseY = gfx.mouse_x, gfx.mouse_y
2139 | gfx.mouse_wheel = 0 -- reset gfx.mouse_wheel
2140 |
2141 | -- Get passthrough key for play/stop (spacebar)
2142 | char = gfx.getchar()
2143 | if char == 32 then reaper.Main_OnCommand(40044, 0) end
2144 |
2145 | -- Defer 'MainLoop' if not explicitly quiting (esc)
2146 | if char ~= -1 and char ~= 27 then
2147 | reaper.defer(MainLoop)
2148 | elseif pExtSaveStateF then -- quiting, save script state
2149 | pExtStateStr = pickle(pExtState)
2150 | reaper.SetProjExtState(0, "MEM", "pExtState", pExtStateStr )
2151 | --pExtSaveStateF = false
2152 | end
2153 |
2154 | -- Update Reaper GFX
2155 | gfx.update()
2156 |
2157 | -- check for selected item, midi editor and take
2158 | m.lmItem = m.mItem
2159 | m.lactiveTake = m.activeTake
2160 | m.mItem = reaper.GetSelectedMediaItem(0, 0)
2161 |
2162 | if m.mItem then
2163 |
2164 | if m.mItem ~= m.lmItem then
2165 | m.seqShift = 0; m.seqShiftMin = 0; m.seqShiftMax = 0
2166 | seqShiftVal.label = tostring(m.seqShift)
2167 | m.notebuf.i = 0 -- brutal hack
2168 | PurgeNoteBuf(); NewNoteBuf()
2169 | m.activeEditor, m.activeTake = nil, nil
2170 | end
2171 |
2172 | m.activeEditor = reaper.MIDIEditor_GetActive()
2173 |
2174 | if m.activeEditor then
2175 |
2176 | m.activeTake = reaper.MIDIEditor_GetTake(m.activeEditor)
2177 |
2178 | if m.activeTake ~= m.lactiveTake then GetNotesFromTake() end
2179 | if m.lmItem == nil and m.mItem then GetNotesFromTake() end
2180 |
2181 | if m.activeTake then
2182 | ShowMessage(msgText, 0) -- clear old messages
2183 | -- check for grid changes
2184 | local grid = m.reaGrid
2185 | m.reaGrid, __, __ = reaper.MIDI_GetGrid(m.activeTake)
2186 | if grid ~= m.reaGrid then
2187 | GetReaperGrid(seqGridRad)
2188 | seqGridRad.onLClick() -- update the sequence grid sizes
2189 | end -- grid
2190 | else -- handle m.activeTake error
2191 | ShowMessage(msgText, 1)
2192 | m.activeTake = nil
2193 | end -- m.activeTake
2194 |
2195 | else -- handle m.activeEditor error
2196 | -- pop up error message - switch layer on textbox element
2197 | ShowMessage(msgText, 1)
2198 | m.activeEditor = nil
2199 | m.activeTake = nil
2200 | end -- m.activeEditor
2201 | else
2202 | ShowMessage(msgText, 2)
2203 | m.mItem = nil
2204 | end
2205 | end
2206 |
2207 |
2208 | -- run -----------------------------------------------------------------------
2209 | --------------------------------------------------------------------------------
2210 |
2211 | Init()
2212 | InitGFX()
2213 | MainLoop()
2214 |
--------------------------------------------------------------------------------
/MIDI Editor/MIDI Ex Machina/eGUI.lua:
--------------------------------------------------------------------------------
1 | --[[
2 | @description eGUI - A Lua GUI library for REAPER
3 | @about
4 | #### eGUI - A Lua GUI library for Cockos Reaper
5 |
6 | A mod of Eugen27771's original Lua GUI Template for Reaper
7 |
8 | Additional code by Lokasenna and Stephane
9 |
10 | #### Features
11 | - Layers
12 | - Buttons
13 | - Checklists
14 | - Dropdown Lists
15 | - Knobs
16 | - Frames
17 | - Horizontal & Vertical Sliders
18 | - Horizontal & Vertical Range Sliders
19 | - Radio Buttons
20 | - Textboxes
21 | - Resizable
22 | - Modularised for import to other scripts
23 | - Licenced under the GPL v3
24 | @link Forum Thread http://reaper.fm
25 | @noindex
26 | @version 2.0
27 | @author RobU
28 | @changelog
29 | v2.0
30 | Forked from EUGEN27771's GUI for Lua
31 | Modularised
32 | Refactoring of original code
33 | Added Vertical Range Slider widget
34 | Added Textbox widget
35 | Added polar coordinate support to Knob widgets
36 | Added Min/Max/Step attributes to all widgets
37 | Added mousewheel support to range sliders
38 | Added Layers/Tabs
39 | Removed dynamic zoom-by-drag
40 | Added symetrical fixed-step zoom (eg 80%, 90%, 100%...)
41 | Rewrote Radio Button and Checkbox initialisation and drawing code
42 | Improved general readability (variable naming, etc.)
43 | Added standard colour tables (e.g - e.col_red, e.col_grey5, etc.)
44 | --]]
45 | --------------------------------------------------------------------------------
46 | -- eGUI Global variables
47 | --------------------------------------------------------------------------------
48 | -- All eGUI code is stored in this table, which is imported by the calling script.
49 | e = {}
50 | e.gScale = 1; e.gScaleState = false; e.gActiveLayer = 1
51 |
52 | -- eGUI colours
53 | e.col_red = {.78, .21, .23, .50}
54 | e.col_orange = {.90, .60, .10, .50}
55 | e.col_yellow = {.80, .80, .10, .50}
56 | e.col_green = {.27, .61, .36, .50}
57 | e.col_blue = {.27, .43, .58, .50}
58 | e.col_grey4 = {.40, .40, .40, .40}
59 | e.col_grey5 = {.50, .50, .50, .50}
60 | e.col_grey6 = {.60, .60, .60, .60}
61 | e.col_grey7 = {.70, .70, .70, .70}
62 | e.col_grey8 = {.80, .80, .80, .80}
63 | e.col_grey9 = {.90, .90, .90, .90}
64 | e.col_greym = {.50, .50, .50, .90}
65 |
66 | -- common shared Windows and Mac sans-serif fonts
67 | e.Arial = "Arial"
68 | e.Lucinda = "Lucinda Sans Unicode"
69 | e.Tahoma = "Tahoma"
70 | e.Trebuchet = "Trebuchet MS"
71 | e.Verdana = "Verdana"
72 | e.MSSans = "MS Sans Serif"
73 | --------------------------------------------------------------------------------
74 | -- eGUI Utility functions
75 | --------------------------------------------------------------------------------
76 | --------------------------------------------------------------------------------
77 | -- wrap(n, max) - returns n wrapped between 0 and max
78 | --------------------------------------------------------------------------------
79 | function e.wrap(n, max)
80 | n = n % max
81 | if (n < 1) then
82 | n = n + max
83 | end
84 | return n
85 | end
86 | --------------------------------------------------------------------------------
87 | -- RGB2Packed(r, g, b) - returns a packed rgb value
88 | --------------------------------------------------------------------------------
89 | function e.RGB2Packed(r, g, b)
90 | local floor = math.floor
91 | g = (g << 8)
92 | b = (b << 16)
93 | return floor(r + g + b)
94 | end
95 | --------------------------------------------------------------------------------
96 | -- Packed2RGB(p) - returns r, g, b from a packed rgb value
97 | --------------------------------------------------------------------------------
98 | function e.Packed2RGB(p)
99 | local floor = math.floor
100 | local b, lsb, g, lsg, r = 0, 0, 0, 0, 0
101 | b = (p >> 16); lsb = (b << 16); p = p - lsb
102 | g = (p >> 8); lsg = (g << 8); p = p - lsg
103 | return floor(p), floor(g), floor(b)
104 | end
105 | --------------------------------------------------------------------------------
106 | -- RGB2Dec(r, g, b) - takes 8 bit r, g, b values, returns decimal (0 to 1)
107 | --------------------------------------------------------------------------------
108 | function e.RGB2Dec(r, g, b)
109 | if r < 0 or r > 255 then r = wrap(r, 255) end
110 | if g < 0 or g > 255 then g = wrap(g, 255) end
111 | if b < 0 or b > 255 then b = wrap(b, 255) end
112 | return r/255, g/255, b/255
113 | end
114 | --------------------------------------------------------------------------------
115 | -- Cart2Polar(x_pos, y_pos, orig_x, orig_y) - returns radius and angle
116 | --------------------------------------------------------------------------------
117 | function e.Cart2Polar(p_x, p_y, orig_x, orig_y)
118 | local x, y = p_x - orig_x, p_y - orig_y
119 | local radius = (x^2 + y^2) ^ 0.5
120 | local angle = math.deg(math.atan(y, x))
121 | if angle < 0 then angle = angle + 360 end
122 | return radius, angle
123 | end
124 | --------------------------------------------------------------------------------
125 | -- Polar2Cart(radias, angle, orig_x, orig_y) - returns x_pos and y_pos
126 | --------------------------------------------------------------------------------
127 | function e.Polar2Cart(radius, angle, orig_x, orig_y)
128 | local angle = angle * math.pi
129 | local x, y = radius * math.cos(angle), radius * math.sin(angle)
130 | return x + orig_x, y + orig_y
131 | end
132 | --------------------------------------------------------------------------------
133 | -- Element Class
134 | --------------------------------------------------------------------------------
135 | e.Element = {}
136 | function e.Element:new(tab, x,y,w,h, rgba, label, font, font_sz, font_rgba, val1, val2, min, max, step)
137 | local elm = {}
138 | local bf = 0
139 | if tab[1] == 0 then -- convert the tabs table to a bitfield
140 | bf = 0
141 | else
142 | for i = 1, #tab do
143 | bf = bf + (1 << tab[i])
144 | end
145 | end
146 | elm.tab = bf
147 | elm.def_xywh = {x,y,w,h, font_sz} -- default coordinates, used for zoom and some Element initialisation
148 | elm.x, elm.y, elm.w, elm.h = x, y, w, h -- position and size
149 | elm.r, elm.g, elm.b, elm.a = table.unpack(rgba) -- Element colour
150 | elm.label, elm.font, elm.font_sz, elm.font_rgba = label, font, font_sz, font_rgba -- all things fonty
151 | elm.val1 = val1; elm.val2 = val2 -- general purpose variables or tables
152 | elm.min, elm.max, elm.step = min, max, step -- for incrementing or decrementing values
153 | setmetatable(elm, self)
154 | self.__index = self
155 | return elm
156 | end
157 | --------------------------------------------------------------------------------
158 | -- Element Class Methods
159 | --------------------------------------------------------------------------------
160 | function e.Element:update_zoom() -- generic e.Element scaling
161 | if not e.gScaleState then return end
162 | self.x = math.ceil(self.def_xywh[1] * e.gScale) -- update x position
163 | self.w = math.ceil(self.def_xywh[3] * e.gScale) -- update width
164 | self.y = math.ceil(self.def_xywh[2] * e.gScale) -- update y position
165 | self.h = math.ceil(self.def_xywh[4] * e.gScale) -- update height
166 | if self.font_sz then -- required for the Frame e.Element which has no font defined
167 | self.font_sz = math.max(10, self.def_xywh[5] * e.gScale) -- update font
168 | self.font_sz = math.min(28, self.font_sz)
169 | end
170 | end
171 | --------------------------------------------------------------------------------
172 | function e.Element:pointIN(p_x, p_y)
173 | return p_x >= self.x and p_x <= self.x + self.w and p_y >= self.y and p_y <= self.y + self.h
174 | end
175 | --------------------------------------------------------------------------------
176 | function e.Element:mouseIN()
177 | return gfx.mouse_cap & 1 == 0 and self:pointIN(gfx.mouse_x, gfx.mouse_y)
178 | end
179 | --------------------------------------------------------------------------------
180 | function e.Element:mouseLDown()
181 | return gfx.mouse_cap & 1 == 1 and self:pointIN(gMouseOX, gMouseOY)
182 | end
183 | --------------------------------------------------------------------------------
184 | function e.Element:mouseUp()
185 | return gfx.mouse_cap & 1 == 0 and self:pointIN(gMouseOX, gMouseOY)
186 | end
187 | --------------------------------------------------------------------------------
188 | function e.Element:mouseLClick()
189 | return gfx.mouse_cap & 1 == 0 and gLastMouseCap & 1 == 1 and
190 | self:pointIN(gfx.mouse_x, gfx.mouse_y) and self:pointIN(gMouseOX, gMouseOY)
191 | end
192 | --------------------------------------------------------------------------------
193 | function e.Element:mouseRClick()
194 | return gfx.mouse_cap & 2 == 0 and gLastMouseCap & 2 == 2 and
195 | self:pointIN(gfx.mouse_x, gfx.mouse_y) and self:pointIN(gMouseOX, gMouseOY)
196 | end
197 | --------------------------------------------------------------------------------
198 | function e.Element:mouseRDown()
199 | return gfx.mouse_cap & 2 == 2 and self:pointIN(gMouseOX, gMouseOY)
200 | end
201 | --------------------------------------------------------------------------------
202 | function e.Element:mouseMDown()
203 | return gfx.mouse_cap & 64 == 64 and self:pointIN(gMouseOX, gMouseOY)
204 | end
205 | --------------------------------------------------------------------------------
206 | function e.Element:draw_frame() -- generic e.Element frame drawing
207 | gfx.rect(self.x, self.y, self.w, self.h, false) -- frame1
208 | gfx.roundrect(self.x, self.y, self.w - 1, self.h - 1, 3, true) -- frame2
209 | end
210 | --------------------------------------------------------------------------------
211 | -- Metatable funtion for child classes(args = Child, Parent Class)
212 | --------------------------------------------------------------------------------
213 | function e.extended(Child, Parent)
214 | setmetatable(Child, {__index = Parent})
215 | end
216 | --------------------------------------------------------------------------------
217 | -- Create Element Child Classes
218 | -- Button, Checkbox, Droplist, Frame, Knob, Sliders, Textbox
219 | --------------------------------------------------------------------------------
220 | -- removed local
221 | e.Button = {}; e.extended(e.Button, e.Element)
222 | e.Checkbox = {}; e.extended(e.Checkbox, e.Element)
223 | e.Droplist = {}; e.extended(e.Droplist, e.Element)
224 | e.Frame = {}; e.extended(e.Frame, e.Element)
225 | e.Knob = {}; e.extended(e.Knob, e.Element)
226 | e.Rad_Button = {}; e.extended(e.Rad_Button, e.Element)
227 | e.H_Rng_Slider = {}; e.extended(e.H_Rng_Slider, e.Element)
228 | e.V_Rng_Slider = {}; e.extended(e.V_Rng_Slider, e.Element)
229 | e.Slider = {}; e.extended(e.Slider, e.Element)
230 | e.Horz_Slider = {}; e.extended(e.Horz_Slider, e.Slider)
231 | e.Vert_Slider = {}; e.extended(e.Vert_Slider, e.Slider)
232 | e.Textbox = {}; e.extended(e.Textbox, e.Element)
233 | --------------------------------------------------------------------------------
234 | -- Button Class Methods
235 | --------------------------------------------------------------------------------
236 | function e.Button:draw_body()
237 | gfx.rect(self.x, self.y, self.w, self.h, true)
238 | end
239 | --------------------------------------------------------------------------------
240 | function e.Button:draw_label()
241 | local labelWidth, labelHeight = gfx.measurestr(self.label)
242 | gfx.x = self.x + (self.w - labelWidth) / 2
243 | gfx.y = self.y + (self.h - labelHeight) / 2
244 | gfx.drawstr(self.label)
245 | end
246 | ---------------------------------------------------------------------------------
247 | function e.Button:draw()
248 | if (self.tab & (1 << e.gActiveLayer)) == 0 and self.tab ~= 0 then return end
249 | self:update_zoom()
250 | local a = self.a -- local alpha value for highlight
251 | -- Get mouse state
252 | if self:mouseIN() then a = a + 0.1 end -- if in e.Element, increase opacity
253 | if self:mouseLDown() then a = a + 0.2 end -- if e.Element clicked, increase opacity more
254 | -- in elm L_up (released and was previously pressed), run onLClick (user defined)
255 | if self:mouseLClick() and self.onLClick then self.onLClick() end
256 | -- in elm R_up (released and was previously pressed), run onRClick (user defined)
257 | if self:mouseRClick() and self.onRClick then self.onRClick() end
258 | gfx.set(self.r, self.g, self.b, a) -- set e.Element color
259 | self:draw_body()
260 | self:draw_frame()
261 | gfx.set(table.unpack(self.font_rgba)) -- set label color
262 | gfx.setfont(1, self.font, self.font_sz) -- set label font & size
263 | self:draw_label()
264 | end
265 | --------------------------------------------------------------------------------
266 | -- Checkbox Class Methods
267 | --------------------------------------------------------------------------------
268 | function e.Checkbox:update_zoom() -- handle window zooming
269 | if not e.gScaleState then return end
270 | -- zoom font
271 | self.font_sz = math.max(10, self.def_xywh[5] * e.gScale)
272 | self.font_sz = math.min(28, self.font_sz)
273 | -- zoom x pos, y pos
274 | self.x = math.ceil(self.def_xywh[1] * e.gScale)
275 | self.y = math.ceil(self.def_xywh[2] * e.gScale)
276 | -- zoom checkboxes
277 | self.cbox_w = math.ceil(self.def_xywh[6] * e.gScale)
278 | self.cbox_h = math.ceil(self.def_xywh[7] * e.gScale)
279 | -- zoom width
280 | local str_w, str_h, max_w = 0, 0, 0
281 | gfx.setfont(1, self.font, self.font_sz)
282 | for i = 1, #self.val2 do
283 | str_w, str_h = gfx.measurestr(self.val2[i])
284 | if str_w > max_w then max_w = str_w end
285 | end
286 | self.def_xywh[3] = max_w + self.cbox_w + 15
287 | self.w = math.ceil(self.def_xywh[3])
288 | -- zoom height
289 | self.def_xywh[4] = self.cbox_h * #self.val2
290 | self.h = math.ceil(self.def_xywh[4])
291 | end
292 | --------------------------------------------------------------------------------
293 | function e.Checkbox:set_val1()
294 | local y, h = self.y + 2, self.h -4 -- padding
295 | local tOptState = self.val1 -- contains the current state of each option
296 | local tOptions = self.val2 -- the table of options
297 | local optIdx = math.floor(((gfx.mouse_y - y) / h) * #tOptions) + 1
298 | if optIdx < 1 then optIdx = 1 elseif optIdx > #tOptions then optIdx = #tOptions end
299 | if tOptState[optIdx] == 0 then tOptState[optIdx] = 1
300 | elseif tOptState[optIdx] == 1 then tOptState[optIdx] = 0 end
301 | end
302 | --------------------------------------------------------------------------------
303 | function e.Checkbox:draw_body()
304 | local x, y = self.x + 2, self.y -- padding
305 | local padSize = 0.5 * e.gScale -- more padding...
306 | local tOptState = self.val1 -- current state of each option
307 | local square = 2 * self.cbox_w / 3
308 | local centerOffset = ((self.cbox_w - square) / 2)
309 | -- adjust the options to be centered
310 | local cx, cy = x + centerOffset, y + centerOffset
311 | -- necessary to keep the GUI's resizing code from making the square wobble
312 | --square = math.floor((square / 4) + 0.5) * 4
313 | for optIdx = 1, #self.val2 do
314 | local optY = cy + ((optIdx - 1) * self.cbox_w)
315 | gfx.roundrect(cx, optY, square, square, true)
316 | gfx.rect(cx, optY, square, square, false)
317 | if tOptState[optIdx] == 1 then
318 | gfx.rect(cx, optY, square + 1, square + 1, true) -- big square
319 | gfx.rect(cx + (square / 4), optY + (square / 4), square / 2, square / 2, true) -- small square
320 | gfx.roundrect(cx + (square / 4), optY + (square / 4), square / 2 - 1, square / 2 - 1, true) -- small frame
321 | end
322 | end
323 | end
324 | --------------------------------------------------------------------------------
325 | function e.Checkbox:draw_vals()
326 | local x, y, optY = self.x + 2, self.y + 2 -- padding
327 | local tOptions = self.val2 -- table of options
328 | -- to match up with the options
329 | local square = 2 * self.cbox_w / 3
330 | local centerOffset = ((self.cbox_w - square) / 2)
331 | cx, cy = x + self.cbox_w + centerOffset, y + centerOffset
332 | for i = 1, #tOptions do
333 | optY = cy + ((i - 1) * self.cbox_w)
334 | gfx.x, gfx.y = cx, optY
335 | gfx.drawstr(tOptions[i])
336 | end
337 | end
338 | --------------------------------------------------------------------------------
339 | function e.Checkbox:draw_label()
340 | local x, y = self.x, self.y + 2 -- padding
341 | -- to match up with the first option
342 | local square = 2 * self.cbox_w / 3
343 | local centerOffset = ((self.cbox_w - square) / 2)
344 | sy = y + centerOffset
345 | local labelWidth, labelHeight = gfx.measurestr(self.label)
346 | gfx.x = x + centerOffset -- labelWidth - 5;
347 | gfx.y = self.y + self.h + labelHeight / 2 --gfx.y = sy
348 | gfx.drawstr(self.label)
349 | end
350 | --------------------------------------------------------------------------------
351 | function e.Checkbox:draw()
352 | while not self.setup do -- on first run, set the correct width and height
353 | local str_w, str_h, max_w = 0, 0, 0
354 | self.cbox_w, self.cbox_h = self.w, self.h
355 | gfx.setfont(1, self.font, self.font_sz)
356 | for i = 1, #self.val2 do
357 | str_w, str_h = gfx.measurestr(self.val2[i])
358 | if str_w > max_w then max_w = str_w end
359 | end
360 | self.def_xywh[3] = self.cbox_w + max_w + 15; self.w = self.def_xywh[3]
361 | self.def_xywh[4] = self.cbox_h * #self.val2; self.h = self.def_xywh[4]
362 | self.def_xywh[6] = self.cbox_w; self.def_xywh[7] = self.cbox_h
363 | self.setup = true
364 | end
365 | if (self.tab & (1 << e.gActiveLayer)) == 0 and self.tab ~= 0 then return end
366 | self:update_zoom() -- check and update if window resized
367 | local a = self.a -- local alpha value for highlighting the e.Element
368 | if self:mouseIN() then a = a + 0.1 end -- if in e.Element, increase opacity
369 | if self:mouseLDown() then a = a + 0.2 end -- if e.Element clicked, increase opacity more
370 | -- in elm L_up(released and was previously pressed)
371 | if self:mouseLClick() then
372 | self:set_val1()
373 | if self.onLClick then self.onLClick() end -- if mouseL clicked and released, execute onLClick()
374 | end
375 | if self:mouseRClick() and self.onRClick then self.onRClick() end -- if mouseR clicked and released, execute onRClick()
376 | gfx.set(self.r, self.g, self.b, a) -- set the drawing colour for the e.Element
377 | -- allow for a simple toggle with no frame
378 | -- if #self.val2 > 1 then self:draw_frame() end -- looks better without the frame...
379 | self:draw_body()
380 | gfx.set(table.unpack(self.font_rgba)) -- set label color
381 | gfx.setfont(1, self.font, self.font_sz) -- set label font
382 | self:draw_vals()
383 | if #self.val2 > 1 then self:draw_label() end -- allow for single toggle
384 | end
385 | --------------------------------------------------------------------------------
386 | -- Droplist Class Methods
387 | --------------------------------------------------------------------------------
388 | function e.Droplist:set_norm_val_m_wheel()
389 | if gfx.mouse_wheel == 0 then return false end -- return if m_wheel = 0
390 | if gfx.mouse_wheel < 0 then self.val1 = math.min(self.val1 + 1, #self.val2) end
391 | if gfx.mouse_wheel > 0 then self.val1 = math.max(self.val1 - 1, 1) end
392 | return true
393 | end
394 | --------------------------------------------------------------------------------
395 | function e.Droplist:set_val1()
396 | local x, y, w, h = self.x, self.y, self.w, self.h
397 | local val = self.val1
398 | local menu_tb = self.val2
399 | local menu_str = ""
400 | for i = 1, #menu_tb, 1 do
401 | if i ~= val then menu_str = menu_str .. menu_tb[i] .. "|"
402 | else menu_str = menu_str .. "!" .. menu_tb[i] .. "|" -- add check
403 | end
404 | end
405 | gfx.x = self.x; gfx.y = self.y + self.h
406 | local new_val = gfx.showmenu(menu_str) -- show Droplist menu
407 | if new_val > 0 then self.val1 = new_val end
408 | end
409 | --------------------------------------------------------------------------------
410 | function e.Droplist:draw_body()
411 | gfx.rect(self.x, self.y, self.w, self.h, true)
412 | end
413 | --------------------------------------------------------------------------------
414 | function e.Droplist:draw_label()
415 | local labelW, labelH = gfx.measurestr(self.label)
416 | local pad = 5
417 | gfx.x = self.x + ((self.w / 2) - (labelW / 2))
418 | gfx.y = self.y - ((labelH) + (labelH / 3))
419 | gfx.drawstr(self.label)
420 | end
421 | --------------------------------------------------------------------------------
422 | function e.Droplist:draw_val()
423 | local x, y, w, h = self.x, self.y, self.w, self.h
424 | local val = self.val2[self.val1]
425 | local val_w, val_h = gfx.measurestr(val)
426 | gfx.x = x + ((w / 2) - (val_w / 2))
427 | gfx.y = y + (h - val_h) / 2
428 | gfx.drawstr(val)
429 | end
430 | --------------------------------------------------------------------------------
431 | function e.Droplist:draw()
432 | if (self.tab & (1 << e.gActiveLayer)) == 0 and self.tab ~= 0 then return end
433 | self:update_zoom() -- check and update if window resized
434 | local a = self.a -- local alpha value for highlighting the e.Element
435 | if self:mouseIN() then a = a + 0.1 -- if in e.Element, increase opacity
436 | if self:set_norm_val_m_wheel() then
437 | if self.onLClick then self.onLClick() end
438 | end
439 | end
440 | if self:mouseLDown() then a = a + 0.2 end -- if e.Element clicked, increase opacity more
441 | -- in elm L_up(released and was previously pressed)
442 | if self:mouseLClick() then self:set_val1()
443 | if self:mouseLClick() and self.onLClick then self.onLClick() end
444 | end
445 | -- right click support
446 | if self:mouseRClick() and self.onRClick then self.onRClick() end
447 | -- Draw combo body, frame
448 | gfx.set(self.r, self.g, self.b, a) -- set the drawing colour for the e.Element
449 | self:draw_body()
450 | self:draw_frame()
451 | -- Draw label
452 | gfx.set(table.unpack(self.font_rgba)) -- set label color
453 | gfx.setfont(1, self.font, self.font_sz) -- set label font
454 | self:draw_label() -- draw label
455 | self:draw_val() -- draw val
456 | end
457 | --------------------------------------------------------------------------------
458 | -- Frame Class Methods
459 | --------------------------------------------------------------------------------
460 | function e.Frame:draw()
461 | if (self.tab & (1 << e.gActiveLayer)) == 0 and self.tab ~= 0 then return end
462 | self:update_zoom() -- check and update if window resized
463 | local a = self.a -- local alpha value required for highlighting the e.Element
464 | if self:mouseIN() then a = a + 0.1 end -- if in e.Element, increase opacity
465 | gfx.set(self.r, self.g, self.b, a) -- set the drawing colour for the e.Element
466 | self:draw_frame()
467 | end
468 | --------------------------------------------------------------------------------
469 | -- Knob Class Methods
470 | --------------------------------------------------------------------------------
471 | function e.Knob:pointIN(p_x, p_y)
472 | local radius, angle = e.Cart2Polar(p_x, p_y, self.ox, self.oy)
473 | return radius <= self.radius
474 | end
475 | --------------------------------------------------------------------------------
476 | function e.Knob:set_val1()
477 | local val, K = 0, 5 -- val = temp value; K = coefficient(when Ctrl pressed)
478 | if Ctrl then
479 | val = self.val1 + ((gLastMouseY-gfx.mouse_y) / (self.h * K)) * self.max
480 | else
481 | val = self.val1 + ((gLastMouseY-gfx.mouse_y) / self.h) * self.max
482 | end
483 | if val < self.min then val = self.min elseif val > self.max then val = self.max end
484 | self.val1 = val
485 | end
486 | --------------------------------------------------------------------------------
487 | function e.Knob:set_norm_val_m_wheel()
488 | if gfx.mouse_wheel == 0 then return end -- return if m_wheel = 0
489 | if gfx.mouse_wheel > 0 then self.val1 = math.min(self.val1 + self.step, self.max) end
490 | if gfx.mouse_wheel < 0 then self.val1 = math.max(self.val1 - self.step, self.min) end
491 | return true
492 | end
493 | --------------------------------------------------------------------------------
494 | function e.Knob:draw_body()
495 | local floor = math.floor
496 | local radius = self.w / 2
497 | local ox, oy = self.x + self.w / 2, self.y + self.h / 2 -- knob centre origin
498 | local mx, my = floor(gfx.mouse_x), floor(gfx.mouse_y) -- get the mouse pos - debug only
499 | local r1, ang = e.Cart2Polar(mx, my, ox, oy) -- debug only
500 | gfx.circle(ox, oy, radius / 2, true) -- inner
501 | gfx.circle(ox, oy, radius, false, true); gfx.circle(ox, oy, radius-0.5, false, true) -- outer
502 | local pi = math.pi
503 | local offs = pi + pi / 4 -- quarter of a circle offset to start of range
504 | local val1 = 1.5 * pi / self.max * self.val1 -- offset
505 | local ang1, ang2 = offs - 0.01, offs + val1
506 | for i = 1, 10 do -- draw outer circle value range
507 | gfx.arc(ox, oy, radius - 1, ang1, ang2, true)
508 | radius = radius - 0.5
509 | end
510 | end
511 | --------------------------------------------------------------------------------
512 | function e.Knob:draw_label()
513 | local labelWidth, labelHeight = gfx.measurestr(self.label)
514 | gfx.x = self.ox - labelWidth / 2; gfx.y = self.oy + self.radius + (labelHeight / 2)
515 | gfx.drawstr(self.label)
516 | end
517 | --------------------------------------------------------------------------------
518 | function e.Knob:draw_val()
519 | local str = string.format("%.0f", self.val1)
520 | local strW, strH = gfx.measurestr(str)
521 | gfx.x = self.ox - (strW / 2)
522 | gfx.y = self.oy - (strH / 2)
523 | gfx.drawstr(str) -- draw knob Value
524 | end
525 | --------------------------------------------------------------------------------
526 | function e.Knob:draw()
527 | if (self.tab & (1 << e.gActiveLayer)) == 0 and self.tab ~= 0 then return end
528 | self:update_zoom() -- check and update if window resized
529 | local a = self.a -- local alpha for highlighting the e.Element
530 | -- set additional knob specific state
531 | self.radius = self.w / 2
532 | self.ox, self.oy = self.x + self.w / 2, self.y + self.h / 2
533 | if self:mouseIN() then a = a + 0.1 -- if in e.Element, increase opacity
534 | if self:set_norm_val_m_wheel() then
535 | if self.onMove then self.onMove() end
536 | end
537 | end
538 | if self:mouseLDown() then a = a + 0.2 -- if e.Element clicked, increase opacity more
539 | self:set_val1()
540 | if self.onMove then self.onMove() end
541 | end
542 | if self:mouseRClick() and self.onRClick then self.onRClick() end -- if mouseR clicked and released, execute onRClick()
543 | gfx.set(self.r, self.g, self.b, a + 0.1) -- set the drawing colour for the e.Element
544 | self:draw_body()
545 | gfx.set(table.unpack(self.font_rgba)) -- set label color
546 | gfx.setfont(1, self.font, self.font_sz) -- set label font
547 | self:draw_label() -- draw label(if need)
548 | self:draw_val() -- draw value
549 | end
550 | --------------------------------------------------------------------------------
551 | -- Radio Button Class Methods
552 | --------------------------------------------------------------------------------
553 | function e.Rad_Button:update_zoom() -- handle window zooming
554 | if not e.gScaleState then return end
555 | -- zoom font
556 | self.font_sz = math.max(10, self.def_xywh[5] * e.gScale)
557 | self.font_sz = math.min(28, self.font_sz)
558 | -- zoom x pos, y pos
559 | self.x = math.ceil(self.def_xywh[1] * e.gScale)
560 | self.y = math.ceil(self.def_xywh[2] * e.gScale)
561 | -- zoom checkboxes
562 | self.cbox_w = math.ceil(self.def_xywh[6] * e.gScale)
563 | self.cbox_h = math.ceil(self.def_xywh[7] * e.gScale)
564 | -- zoom width
565 | local str_w, str_h, max_w = 0, 0, 0
566 | gfx.setfont(1, self.font, self.font_sz)
567 | for i = 1, #self.val2 do
568 | str_w, str_h = gfx.measurestr(self.val2[i])
569 | if str_w > max_w then max_w = str_w end
570 | end
571 | self.def_xywh[3] = max_w + self.cbox_w + 15
572 | self.w = math.ceil(self.def_xywh[3])
573 | -- zoom height
574 | self.def_xywh[4] = self.cbox_h * #self.val2
575 | self.h = math.ceil(self.def_xywh[4]) -- * gZoomH) --scale)
576 | end
577 | --------------------------------------------------------------------------------
578 | function e.Rad_Button:set_norm_val_m_wheel()
579 | if gfx.mouse_wheel == 0 then return false end -- return if m_wheel = 0
580 | if gfx.mouse_wheel < 0 then self.val1 = math.min(self.val1 + 1, #self.val2) end
581 | if gfx.mouse_wheel > 0 then self.val1 = math.max(self.val1 - 1, 1) end
582 | return true
583 | end
584 | --------------------------------------------------------------------------------
585 | function e.Rad_Button:set_val1()
586 | local y, h = self.y + 2, self.h - 4 -- padding
587 | local tOptions = self.val2
588 | local val = math.floor(((gfx.mouse_y - y) / h) * #tOptions) + 1
589 | if val < 1 then val = 1 elseif val > #tOptions then val = #tOptions end
590 | self.val1 = val
591 | end
592 | --------------------------------------------------------------------------------
593 | function e.Rad_Button:draw_body()
594 | local x, y = self.x + 2, self.y -- padding
595 | local padSize = .25 * e.gScale -- more padding...
596 | local r = self.cbox_w / 3
597 | local centerOffset = ((self.cbox_w - (2 * r)) / 2)
598 | -- adjust the options to be centered
599 | cx, cy = x + centerOffset, y + centerOffset
600 | for i = 1, #self.val2 do
601 | local optY = cy + ((i - 1) * self.cbox_w)
602 | gfx.circle(cx + r, optY + r, r, false)
603 | gfx.circle(cx + r, optY + r, r - padSize, false, true)
604 | if i == self.val1 then
605 | gfx.circle(cx + r, optY + r, r, true) -- big circle
606 | gfx.circle(cx + r, optY + r, r * 0.5, true) -- small circle
607 | gfx.circle(cx + r, optY + r, r * 0.5, false) -- small frame
608 | end
609 | end
610 | end
611 | --------------------------------------------------------------------------------
612 | function e.Rad_Button:draw_vals()
613 | local x, y, optY = self.x + 2, self.y + 2 -- padding
614 | local tOptions = self.val2 -- table of options
615 | -- to match up with the options
616 | local r = self.cbox_w / 3
617 | local centerOffset = ((self.optSpacing - (2 * r)) / 2)
618 | cx, cy = x + self.cbox_w + centerOffset, y + centerOffset
619 | for i = 1, #tOptions do
620 | optY = cy + ((i - 1) * self.cbox_w)
621 | gfx.x, gfx.y = cx, optY
622 | gfx.drawstr(tOptions[i])
623 | end
624 | end
625 | --------------------------------------------------------------------------------
626 | function e.Rad_Button:draw_label()
627 | local x, y = self.x, self.y + 2 -- padding
628 | local optSpacing = self.optSpacing
629 | -- to match up with the first option
630 | local r = self.cbox_w / 3
631 | local centerOffset = ((self.cbox_w - (2 * r)) / 2)
632 | y = y + centerOffset
633 | local labelWidth, labelHeight = gfx.measurestr(self.label)
634 | gfx.x = x + centerOffset-- labelWidth - 5
635 | gfx.y = self.y + self.h + labelHeight / 2
636 | gfx.drawstr(self.label)
637 | end
638 | --------------------------------------------------------------------------------
639 | function e.Rad_Button:draw()
640 | while not self.setup do -- on first run, set the correct width and height
641 | local str_w, str_h, max_w = 0, 0, 0
642 | self.cbox_w, self.cbox_h = self.w, self.h
643 | gfx.setfont(1, self.font, self.font_sz)
644 | for i = 1, #self.val2 do
645 | str_w, str_h = gfx.measurestr(self.val2[i])
646 | if str_w > max_w then max_w = str_w end
647 | end
648 | self.def_xywh[3] = self.cbox_w + max_w + 15; self.w = self.def_xywh[3]
649 | self.def_xywh[4] = self.cbox_h * #self.val2; self.h = self.def_xywh[4]
650 | self.def_xywh[6] = self.cbox_w; self.def_xywh[7] = self.cbox_h
651 | self.setup = true
652 | end
653 | if (self.tab & (1 << e.gActiveLayer)) == 0 and self.tab ~= 0 then return end
654 | self:update_zoom() -- check and update if window resized
655 | local a = self.a -- local alpha value required for highlighting the e.Element
656 | self.optSpacing = (self.h / (#self.val2 or 1)) -- e.Element height / number of options
657 | if self:mouseIN() then a = a + 0.1 -- if in e.Element, increase opacity
658 | if self:set_norm_val_m_wheel() then
659 | if self.onLClick then self.onLClick() end
660 | end
661 | end
662 | -- in elm L_up(released and was previously pressed)
663 | if self:mouseLDown() then a = a + 0.2 end -- if e.Element clicked, increase opacity more
664 | -- in elm L_up(released and was previously pressed)
665 | if self:mouseLClick() then
666 | self:set_val1()
667 | if self.onLClick then self.onLClick() end -- if mouseL clicked and released, execute onLClick()
668 | end
669 | if self:mouseRClick() and self.onRClick then self.onRClick() end -- if mouseR clicked and released, execute onRClick()
670 | gfx.set(self.r, self.g, self.b, a) -- set the drawing colour for the e.Element
671 | -- self:draw_frame() -- looks better without the frame
672 | self:draw_body()
673 | gfx.set(table.unpack(self.font_rgba)) -- set label color
674 | gfx.setfont(1, self.font, self.font_sz) -- set label font
675 | self:draw_vals()
676 | self:draw_label()
677 | end
678 | --------------------------------------------------------------------------------
679 | -- Slider Class Methods
680 | --------------------------------------------------------------------------------
681 | function e.Slider:set_norm_val_m_wheel()
682 | if gfx.mouse_wheel == 0 then return false end -- return if m_wheel = 0
683 | local K = 1 -- K = coefficient
684 | if Ctrl then K = 5 end
685 | if gfx.mouse_wheel > 0 then self.val1 = math.min(self.val1 + self.step * K, self.max) end
686 | if gfx.mouse_wheel < 0 then self.val1 = math.max(self.val1 - self.step * K, self.min) end
687 | return true
688 | end
689 | --------------------------------------------------------------------------------
690 | function e.Horz_Slider:set_val1()
691 | local val, K = 0, 5 -- val = temp value; K = coefficient (when Ctrl pressed)
692 | if Ctrl then
693 | val = self.val1 + ((gfx.mouse_x - gLastMouseX) / (self.w * K) * self.max)
694 | else
695 | val =(gfx.mouse_x - self.x) / self.w * self.max
696 | end
697 | if val < self.min then val = self.min elseif val > self.max then val = self.max end
698 | self.val1 = val
699 | end
700 | --------------------------------------------------------------------------------
701 | function e.Horz_Slider:draw_body()
702 | local rng_width = self.w / self.max * self.val1
703 | gfx.rect(self.x, self.y, rng_width, self.h, true)
704 | end
705 | --------------------------------------------------------------------------------
706 | function e.Horz_Slider:draw_label()
707 | local labelWidth, labelHeight = gfx.measurestr(self.label)
708 | gfx.x = self.x + 5; gfx.y = self.y + (self.h - labelHeight) / 2;
709 | gfx.drawstr(self.label)
710 | end
711 | --------------------------------------------------------------------------------
712 | function e.Horz_Slider:draw_val()
713 | local val = string.format("%.0f", self.val1)
714 | local val_w, val_h = gfx.measurestr(val)
715 | gfx.x = self.x + self.w - val_w - 5; gfx.y = self.y + (self.h - val_h) / 2;
716 | gfx.drawstr(val)
717 | end
718 | --------------------------------------------------------------------------------
719 | function e.Vert_Slider:set_val1()
720 | local val, K = 0, 5 -- val=temp value; K=coefficient (when Ctrl pressed)
721 | if Ctrl then
722 | val = self.val1 + ((gLastMouseY - gfx.mouse_y) / (self.h * K)) * self.max
723 | else
724 | val = (self.h - (gfx.mouse_y - self.y)) / self.h * self.max
725 | end
726 | if val < self.min then val = self.min elseif val > self.max then val = self.max end
727 | self.val1 = val
728 | end
729 | --------------------------------------------------------------------------------
730 | function e.Vert_Slider:draw_body()
731 | local rng_height = self.h / self.max * self.val1
732 | gfx.rect(self.x, self.y + self.h - rng_height, self.w, rng_height, true)
733 | end
734 | --------------------------------------------------------------------------------
735 | function e.Vert_Slider:draw_label()
736 | local labelWidth, labelHeight = gfx.measurestr(self.label)
737 | gfx.x = self.x + (self.w - labelWidth) / 2
738 | --gfx.y = self.y + self.h + (labelHeight / 2) -- bottom of slider
739 | gfx.y = self.y + self.h - labelHeight - 5; -- inside slider
740 | gfx.drawstr(self.label)
741 | end
742 | --------------------------------------------------------------------------------
743 | function e.Vert_Slider:draw_val()
744 | local val = string.format("%.0f", self.val1)
745 | local val_w, val_h = gfx.measurestr(val)
746 | gfx.x = self.x + (self.w - val_w) / 2
747 | gfx.y = self.y + 5
748 | gfx.drawstr(val)
749 | end
750 | --------------------------------------------------------------------------------
751 | function e.Slider:draw()
752 | if (self.tab & (1 << e.gActiveLayer)) == 0 and self.tab ~= 0 then return end
753 | self:update_zoom() -- check and update if window resized
754 | local a = self.a -- local alpha value required for highlighting the e.Element
755 | if self:mouseIN() then a = a + 0.1 -- if in e.Element, increase opacity
756 | if self:set_norm_val_m_wheel() then
757 | if self.onMove then self.onMove() end
758 | end
759 | end
760 | if self:mouseLDown() then
761 | a = a + 0.2 -- if e.Element clicked, increase opacity more
762 | self:set_val1()
763 | if self.onMove then self.onMove() end
764 | end
765 | if self:mouseRClick() and self.onRClick then self.onRClick() end
766 | gfx.set(self.r, self.g, self.b, a) -- set the drawing colour for the e.Element
767 | self:draw_body()
768 | self:draw_frame()
769 | gfx.set(table.unpack(self.font_rgba)) -- set label color
770 | gfx.setfont(1, self.font, self.font_sz) -- set label font
771 | self:draw_label()
772 | self:draw_val()
773 | end
774 | --------------------------------------------------------------------------------
775 | -- Horizontal Range Slider Class Methods
776 | --------------------------------------------------------------------------------
777 | function e.H_Rng_Slider:pointIN_LHnd(p_x, p_y)
778 | local range_lx = self.rng_x + self.rng_w / self.max * self.val1 -- x pos of left edge of range (abs)
779 | return p_x >= range_lx - self.hnd_w and p_x <= range_lx and p_y >= self.y and p_y <= self.y + self.h
780 | end
781 | --------------------------------------------------------------------------------
782 | function e.H_Rng_Slider:pointIN_RHnd(p_x, p_y)
783 | local range_rx = self.rng_x + self.rng_w / self.max * self.val2 -- x pos of right edge of range (abs)
784 | return p_x >= range_rx and p_x <= self.hnd_w + range_rx and p_y >= self.y and p_y <= self.y + self.h
785 | end
786 | --------------------------------------------------------------------------------
787 | function e.H_Rng_Slider:pointIN_Rng(p_x, p_y)
788 | local range_lx = self.rng_x + self.rng_w / self.max * self.val1 -- x pos of left edge of range (abs)
789 | local range_rx = self.rng_x + self.rng_w / self.max * self.val2 -- x pos of right edge of range (abs)
790 | return p_x >= range_lx and p_x <= range_rx and p_y >= self.y and p_y <= self.y + self.h
791 | end
792 | --------------------------------------------------------------------------------
793 | function e.H_Rng_Slider:mouseIN_LHnd()
794 | return gfx.mouse_cap & 1 == 0 and self:pointIN_LHnd(gfx.mouse_x, gfx.mouse_y)
795 | end
796 | --------------------------------------------------------------------------------
797 | function e.H_Rng_Slider:mouseIN_RHnd()
798 | return gfx.mouse_cap & 1 == 0 and self:pointIN_RHnd(gfx.mouse_x, gfx.mouse_y)
799 | end
800 | --------------------------------------------------------------------------------
801 | function e.H_Rng_Slider:mouseIN_Rng()
802 | return gfx.mouse_cap & 1 == 0 and self:pointIN_Rng(gfx.mouse_x, gfx.mouse_y)
803 | end
804 | --------------------------------------------------------------------------------
805 | function e.H_Rng_Slider:mouseLDown_LHnd()
806 | return gfx.mouse_cap & 1 == 1 and gLastMouseCap & 1 == 0 and self:pointIN_LHnd(gMouseOX, gMouseOY)
807 | end
808 | --------------------------------------------------------------------------------
809 | function e.H_Rng_Slider:mouseLDown_RHnd()
810 | return gfx.mouse_cap & 1 == 1 and gLastMouseCap & 1 == 0 and self:pointIN_RHnd(gMouseOX, gMouseOY)
811 | end
812 | --------------------------------------------------------------------------------
813 | function e.H_Rng_Slider:mouseLDown_rng()
814 | return gfx.mouse_cap & 1 == 1 and gLastMouseCap & 1 == 0 and self:pointIN_Rng(gMouseOX, gMouseOY)
815 | end
816 | --------------------------------------------------------------------------------
817 | function e.H_Rng_Slider:set_val1()
818 | local K = 1 -- K = coefficient
819 | if Ctrl then K = 5 end
820 | local val = self.val1 + ((gfx.mouse_x - gLastMouseX) / (self.rng_w * K) * self.max)
821 | if val < self.min then val = self.min elseif val > self.val2 then val = self.val2 end
822 | self.val1 = val
823 | end
824 | --------------------------------------------------------------------------------
825 | function e.H_Rng_Slider:set_val2()
826 | local K = 1 -- K = coefficient
827 | if Ctrl then K = 5 end
828 | local val = self.val2 + ((gfx.mouse_x - gLastMouseX) / (self.rng_w * K) * self.max)
829 | if val < self.val1 then val = self.val1 elseif val > self.max then val = self.max end
830 | self.val2 = val
831 | end
832 | --------------------------------------------------------------------------------
833 | function e.H_Rng_Slider:set_val_both()
834 | local diff = self.val2 - self.val1 -- range size
835 | local K = 1 -- K = coefficient
836 | if Ctrl then K = 5 end
837 | local val = self.val1 + (gfx.mouse_x - gLastMouseX) / (self.w * K) * self.max
838 | if val < self.min then val = self.min elseif val > self.max - diff then val = self.max - diff end
839 | self.val1 = val
840 | self.val2 = val + diff
841 | end
842 | --------------------------------------------------------------------------------
843 | function e.H_Rng_Slider:set_vals_m_wheel()
844 | if gfx.mouse_wheel == 0 then return false end -- return if m_wheel = 0
845 | local diff = self.val2 - self.val1 -- range size
846 | local K = 1 -- K = coefficient
847 | if Ctrl then K = 5 end
848 | if gfx.mouse_wheel > 0 then
849 | self.val1 = math.min(self.val1 + self.step * K, self.max - diff)
850 | self.val2 = math.min(self.val2 + self.step * K, self.max)
851 | end
852 | if gfx.mouse_wheel < 0 then
853 | self.val1 = math.max(self.val1 - self.step * K, self.min)
854 | self.val2 = math.max(self.val2 - self.step * K, self.min + diff)
855 | end
856 | return true
857 | end
858 | --------------------------------------------------------------------------------
859 | function e.H_Rng_Slider:draw_body()
860 | local range_lx = self.rng_w / self.max * self.val1 -- x pos of left edge of range (abs)
861 | local range_rx = self.rng_w / self.max * self.val2 -- x pos of right edge of range (abs)
862 | gfx.rect(self.rng_x + range_lx, self.y, range_rx - range_lx, self.h, true)
863 | end
864 | --------------------------------------------------------------------------------
865 | function e.H_Rng_Slider:draw_hnds()
866 | local range_lx = self.rng_w / self.max * self.val1 -- x pos of left edge of range (abs)
867 | local range_rx = self.rng_w / self.max * self.val2 -- x pos of right edge of range (abs)
868 | gfx.set(self.r, self.g, self.b, 0.9) -- handle body color
869 | gfx.rect(self.rng_x + range_lx - self.hnd_w, self.y, self.hnd_w, self.h, true) -- left
870 | gfx.rect(self.rng_x + range_rx, self.y, self.hnd_w, self.h, true) -- right
871 | gfx.set(0, 0, 0, 1) -- handle frame color
872 | gfx.rect(self.rng_x + range_lx - self.hnd_w - 1, self.y - 1, self.hnd_w + 2, self.h + 2, false) -- left
873 | gfx.rect(self.rng_x + range_rx - 1, self.y - 1, self.hnd_w + 2, self.h + 2, false) -- right
874 | end
875 | --------------------------------------------------------------------------------
876 | function e.H_Rng_Slider:draw_val()
877 | local val1 = string.format("%.0f", self.val1)
878 | local val2 = string.format("%.0f", self.val2)
879 | local val1_w, val1_h = gfx.measurestr(val1)
880 | local val2_w, val2_h = gfx.measurestr(val2)
881 | gfx.x = self.x + 5
882 | gfx.y = self.y + (self.h - val1_h) / 2
883 | gfx.drawstr(val1)
884 | gfx.x = self.x + self.w - val2_w - 5
885 | gfx.y = self.y + (self.h - val2_h) / 2
886 | gfx.drawstr(val2)
887 | end
888 | --------------------------------------------------------------------------------
889 | function e.H_Rng_Slider:draw_label()
890 | local labelWidth, labelHeight = gfx.measurestr(self.label)
891 | gfx.x = self.x + (self.w - labelWidth) / 2
892 | gfx.y = self.y + (self.h - labelHeight) / 2
893 | gfx.drawstr(self.label)
894 | end
895 | --------------------------------------------------------------------------------
896 | function e.H_Rng_Slider:draw()
897 | if (self.tab & (1 << e.gActiveLayer)) == 0 and self.tab ~= 0 then return end
898 | self:update_zoom() -- check and update if window resized
899 | local a = self.a -- local alpha for highlighting the e.Element
900 | -- set additional range slider specific state
901 | self.hnd_w = math.floor(self.w / 20) -- handle width (pixels)
902 | self.rng_x = self.x + self.hnd_w -- range start x_pos, w/o handle (screen)
903 | self.rng_w = self.w - (self.hnd_w * 2) -- range length, w/o handles (pixels)
904 | self.rng_e = self.rng_x + self.rng_w -- range end_pos inc' 1 handle (screen)
905 | if self:mouseIN() then
906 | if self:set_vals_m_wheel() then
907 | if self.onMove then self.onMove() end
908 | end
909 | end
910 | if gfx.mouse_cap & 1 == 0 then self.LHnd_state, self.RHnd_state, self.rng_state = false, false, false end -- Reset Ls / Rs / range state
911 | if self:mouseIN_LHnd() or self:mouseIN_RHnd() then a = a + 0.1 end -- if in e.Element handles, increase opacity
912 | if self:mouseIN_Rng() then a = a + 0.2 end -- if in range, increase opacity
913 | if self:mouseLDown_LHnd() then self.LHnd_state = true end -- MouseLButton on left handle down
914 | if self:mouseLDown_RHnd() then self.RHnd_state = true end -- MouseLButton on right handle down
915 | if self:mouseLDown_rng() then self.rng_state = true end -- MouseLButton in range down
916 | if self.LHnd_state == true then a = a + 0.2; self:set_val1() end -- if e.Element left handle clicked, increase opacity more
917 | if self.RHnd_state == true then a = a + 0.2; self:set_val2() end -- if e.Element right handle clicked, increase opacity more
918 | if self.rng_state == true then a = a + 0.2; self:set_val_both() end -- if e.Element range clicked, increase opacity more
919 | if (self.LHnd_state or self.RHnd_state or self.rng_state) and self.onMove then self.onMove() end
920 | if self:mouseRClick() and self.onRClick then self.onRClick() end -- if mouseR clicked and released, execute onRClick()
921 | gfx.set(self.r, self.g, self.b, a) -- set e.Element color
922 | self:draw_body()
923 | self:draw_frame()
924 | self:draw_hnds()
925 | gfx.set(table.unpack(self.font_rgba)) -- set label color
926 | gfx.setfont(1, self.font, self.font_sz) -- set label font
927 | self:draw_label()
928 | self:draw_val()
929 | end
930 | --------------------------------------------------------------------------------
931 | -- Vertical Range Slider Class Methods
932 | --------------------------------------------------------------------------------
933 | function e.V_Rng_Slider:pointIN_THnd(p_x, p_y)
934 | local range_ty = self.rng_e - (self.rng_h / self.max * self.val2) -- y pos of upper edge of range (abs)
935 | return p_x >= self.x and p_x <= self.x + self.w and p_y >= range_ty - self.hnd_h and p_y <= range_ty
936 | end
937 | --------------------------------------------------------------------------------
938 | function e.V_Rng_Slider:pointIN_BHnd(p_x, p_y)
939 | local range_by = self.rng_e - (self.rng_h / self.max * self.val1) -- y pos of lower edge of range (abs)
940 | return p_x >= self.x and p_x <= self.x + self.w and p_y >= range_by and p_y <= range_by + self.hnd_h
941 | end
942 | --------------------------------------------------------------------------------
943 | function e.V_Rng_Slider:pointIN_Rng(p_x, p_y)
944 | local range_ty = self.rng_e - (self.rng_h / self.max * self.val2) -- y pos of upper edge of range (abs)
945 | local range_by = self.rng_e - (self.rng_h / self.max * self.val1) -- y pos of lower edge of range (abs)
946 | return p_x >= self.x and p_x <= self.x + self.w and p_y >= range_ty and p_y <= range_by
947 | end
948 | --------------------------------------------------------------------------------
949 | function e.V_Rng_Slider:mouseIN_THnd()
950 | return gfx.mouse_cap & 1 == 0 and self:pointIN_THnd(gfx.mouse_x, gfx.mouse_y)
951 | end
952 | --------------------------------------------------------------------------------
953 | function e.V_Rng_Slider:mouseIN_BHnd()
954 | return gfx.mouse_cap & 1 == 0 and self:pointIN_BHnd(gfx.mouse_x, gfx.mouse_y)
955 | end
956 | --------------------------------------------------------------------------------
957 | function e.V_Rng_Slider:mouseIN_Rng()
958 | return gfx.mouse_cap & 1 == 0 and self:pointIN_Rng(gfx.mouse_x, gfx.mouse_y)
959 | end
960 | --------------------------------------------------------------------------------
961 | function e.V_Rng_Slider:mouseLDown_THnd()
962 | return gfx.mouse_cap & 1 == 1 and gLastMouseCap & 1 == 0 and self:pointIN_THnd(gMouseOX, gMouseOY)
963 | end
964 | --------------------------------------------------------------------------------
965 | function e.V_Rng_Slider:mouseLDown_BHnd()
966 | return gfx.mouse_cap & 1 == 1 and gLastMouseCap & 1 == 0 and self:pointIN_BHnd(gMouseOX, gMouseOY)
967 | end
968 | --------------------------------------------------------------------------------
969 | function e.V_Rng_Slider:mouseLDown_rng()
970 | return gfx.mouse_cap & 1 == 1 and gLastMouseCap & 1 == 0 and self:pointIN_Rng(gMouseOX, gMouseOY)
971 | end
972 | --------------------------------------------------------------------------------
973 | function e.V_Rng_Slider:set_val1()
974 | local K = 1 -- K = coefficient
975 | if Ctrl then K = 5 end
976 | local val = self.val1 + ((gLastMouseY - gfx.mouse_y) / (self.rng_h * K) * self.max)
977 | if val < self.min then val = self.min elseif val > self.val2 then val = self.val2 end
978 | self.val1 = val
979 | end
980 | --------------------------------------------------------------------------------
981 | function e.V_Rng_Slider:set_val2()
982 | local K = 1 -- K = coefficient
983 | if Ctrl then K = 5 end
984 | local val = self.val2 + ((gLastMouseY - gfx.mouse_y) / (self.rng_h * K) * self.max)
985 | if val < self.val1 then val = self.val1 elseif val > self.max then val = self.max end
986 | self.val2 = val
987 | end
988 | --------------------------------------------------------------------------------
989 | function e.V_Rng_Slider:set_val_both()
990 | local diff = self.val2 - self.val1 -- range size
991 | local K = 1 -- K = coefficient
992 | if Ctrl then K = 5 end
993 | local val = self.val1 + (gLastMouseY - gfx.mouse_y) / (self.h * K) * self.max
994 | if val < self.min then val = self.min elseif val > self.max - diff then val = self.max - diff end
995 | self.val1 = val
996 | self.val2 = val + diff
997 | end
998 | --------------------------------------------------------------------------------
999 | function e.V_Rng_Slider:set_vals_m_wheel()
1000 | if gfx.mouse_wheel == 0 then return false end -- return if m_wheel = 0
1001 | local diff = self.val2 - self.val1 -- range size
1002 | local K = 1 -- K = coefficient
1003 | if Ctrl then K = 5 end
1004 | if gfx.mouse_wheel > 0 then
1005 | self.val1 = math.min(self.val1 + self.step * K, self.max - diff)
1006 | self.val2 = math.min(self.val2 + self.step * K, self.max)
1007 | end
1008 | if gfx.mouse_wheel < 0 then
1009 | self.val1 = math.max(self.val1 - self.step * K, self.min)
1010 | self.val2 = math.max(self.val2 - self.step * K, self.min + diff)
1011 | end
1012 | return true
1013 | end
1014 | --------------------------------------------------------------------------------
1015 | function e.V_Rng_Slider:draw_body()
1016 | local range_ty = self.rng_e - (self.rng_h / self.max * self.val2) -- y pos of upper edge of range (abs)
1017 | local range_by = self.rng_e - (self.rng_h / self.max * self.val1) -- y pos of lower edge of range (abs)
1018 | gfx.rect(self.x, range_ty, self.w, range_by - range_ty, true)
1019 | end
1020 | --------------------------------------------------------------------------------
1021 | function e.V_Rng_Slider:draw_hnds()
1022 | local range_ty = self.rng_e - (self.rng_h / self.max * self.val2) -- y pos of upper edge of range (abs)
1023 | local range_by = self.rng_e - (self.rng_h / self.max * self.val1) -- y pos of lower range (abs)
1024 | gfx.set(self.r, self.g, self.b, 0.9) -- handle body color
1025 | gfx.rect(self.x, range_ty - self.hnd_h, self.w, self.hnd_h, true) -- upper
1026 | gfx.rect(self.x, range_by, self.w, self.hnd_h, true) -- lower
1027 | gfx.set(0, 0, 0, 1) -- handle frame colour
1028 | gfx.rect(self.x - 1, range_ty - self.hnd_h - 1, self.w + 2, self.hnd_h + 2, false) -- upper
1029 | gfx.rect(self.x - 1, range_by - 1 , self.w + 2, self.hnd_h + 2, false) -- lower
1030 | end
1031 | --------------------------------------------------------------------------------
1032 | function e.V_Rng_Slider:draw_val()
1033 | local val1 = string.format("%.0f", self.val1)
1034 | local val2 = string.format("%.0f", self.val2)
1035 | local val1_w, val1_h = gfx.measurestr(val1)
1036 | local val2_w, val2_h = gfx.measurestr(val2)
1037 | gfx.x = self.x + (self.w - val2_w) / 2
1038 | gfx.y = self.y + 5
1039 | gfx.drawstr(val2)
1040 | gfx.x = self.x + (self.w - val1_w) / 2
1041 | gfx.y = self.y + self.h - val1_h - 5
1042 | gfx.drawstr(val1)
1043 | end
1044 | --------------------------------------------------------------------------------
1045 | function e.V_Rng_Slider:draw_label()
1046 | local labelWidth, labelHeight = gfx.measurestr(self.label)
1047 | gfx.x = self.x + (self.w - labelWidth) / 2
1048 | gfx.y = self.y + self.h + (labelHeight) / 3 * 2
1049 | gfx.drawstr(self.label)
1050 | end
1051 | --------------------------------------------------------------------------------
1052 | function e.V_Rng_Slider:draw()
1053 | if (self.tab & (1 << e.gActiveLayer)) == 0 and self.tab ~= 0 then return end
1054 | self:update_zoom() -- check and update if window resized
1055 | local a = self.a -- local alpha value for highlighting the e.Element
1056 | -- set additional range slider specific state
1057 | self.hnd_h = math.floor(self.h / 20) -- handle height (pixels)
1058 | self.rng_y = self.y + self.hnd_h -- range start y_pos, w/o handle (screen)
1059 | self.rng_h = self.h - (self.hnd_h * 2) -- range length, w/o handles (pixels)
1060 | self.rng_e = self.rng_y + self.rng_h -- range end_pos w/o handle (screen)
1061 | if self:mouseIN() then
1062 | if self:set_vals_m_wheel() then
1063 | if self.onMove then self.onMove() end
1064 | end
1065 | end
1066 | if gfx.mouse_cap & 1 == 0 then self.BHnd_state, self.THnd_state, self.rng_state = false, false, false end -- Reset Bs / Ts / Range states
1067 | if self:mouseIN_THnd() or self:mouseIN_BHnd() then a = a + 0.1 end -- if in e.Element handles, increase opacity
1068 | if self:mouseIN_Rng() then a = a + 0.2 end -- if in range, increase opacity
1069 | if self:mouseLDown_THnd() then self.THnd_state = true end -- MouseLButton on upper handle down
1070 | if self:mouseLDown_BHnd() then self.BHnd_state = true end -- MouseLButton on lower handle down
1071 | if self:mouseLDown_rng() then self.rng_state = true end -- MouseLButton in range down
1072 | if self.THnd_state == true then a = a + 0.2; self:set_val2() end -- if e.Element top handle clicked, increase opacity more
1073 | if self.BHnd_state == true then a = a + 0.2; self:set_val1() end -- if e.Element top handle clicked, increase opacity more
1074 | if self.rng_state == true then a = a + 0.2; self:set_val_both() end -- if e.Element range clicked, increase opacity more
1075 | if (self.THnd_state or self.BHnd_state or self.rng_state) and self.onMove then self.onMove() end
1076 | if self:mouseRClick() and self.onRClick then self.onRClick() end -- if mouseR clicked and released, execute onRClick()
1077 | gfx.set(self.r, self.g, self.b, a) -- set color
1078 | self:draw_body()
1079 | self:draw_frame()
1080 | self:draw_hnds()
1081 | gfx.set(table.unpack(self.font_rgba)) -- set label color
1082 | gfx.setfont(1, self.font, self.font_sz) -- set label font
1083 | self:draw_label()
1084 | self:draw_val()
1085 | end
1086 | --------------------------------------------------------------------------------
1087 | -- Textbox Class Methods
1088 | --------------------------------------------------------------------------------
1089 | function e.Textbox:draw_body()
1090 | gfx.rect(self.x, self.y, self.w, self.h, true)
1091 | end
1092 | --------------------------------------------------------------------------------
1093 | function e.Textbox:draw_label()
1094 | local labelWidth, labelHeight = gfx.measurestr(self.label)
1095 | gfx.x = self.x + (self.w - labelWidth) / 2
1096 | gfx.y = self.y + (self.h - labelHeight) / 2
1097 | gfx.drawstr(self.label)
1098 | end
1099 | --------------------------------------------------------------------------------
1100 | function e.Textbox:draw()
1101 | if (self.tab & (1 << e.gActiveLayer)) == 0 and self.tab ~= 0 then return end
1102 | self:update_zoom() -- check and update if window resized
1103 | -- in elm R_up (released and was previously pressed), run onRClick (user defined)
1104 | if self:mouseRClick() and self.onRClick then self.onRClick() end
1105 | gfx.set(self.r, self.g, self.b, self.a) -- set the drawing colour for the e.Element
1106 | self:draw_body()
1107 | self:draw_frame()
1108 | gfx.set(table.unpack(self.font_rgba)) -- set label color
1109 | gfx.setfont(1, self.font, self.font_sz) -- set label font
1110 | self:draw_label()
1111 | end
1112 | --------------------------------------------------------------------------------
1113 | return e -- pass eGUI to calling script
1114 |
1115 | --[[
1116 | Example e.Element declarations
1117 | local elem = e.element:new( {tabs} x, y, w, h, colour, "Label", Font, Sz, font col, val1, val2, min, max, step)
1118 | local frame01 = e.Frame:new( {0}, x, y, w, h, e.col_grey4)
1119 | local textbox01 = e.Textbox:new( {1}, x, y, w, h, e.col_grey5, "Label", e.Arial, 16, e.col_grey7)
1120 | local button01 = e.Button:new( {1}, x, y, w, h, e.col_grey6, "Label", e.Arial, 16, e.col_grey8)
1121 | local toggle01 = e.Checkbox:new( {1, 3}, x, y, w, h, e.col_orange, "", e.Arial, 16, e.col_grey8, {1}, {"Option"})
1122 | local checkbox01 = e.Checkbox:new( {1}, x, y, cbw, cbh, e.col_orange, "Label", e.Arial, 16, e.col_grey8, {0,0,1}, {"Opt1", "Opt2", "Opt3"})
1123 | local radbutton01 = e.Rad_Button:new( {1}, x, y, rbw, rbh, e.col_yellow, "Label", e.Arial, 16, e.col_grey8, 1, {"Opt1", "Opt2", "Opt3", "Opt4"})
1124 | local droplist01 = e.Droplist:new( {1}, x, y, w, h, e.col_grey5, "Label", e.Arial, 16, e.col_grey7, 1, {"One", "Two", "Three", "Four"})
1125 | local knob01 = e.Knob:new( {1, 3}, x, y, w, h, e.col_red, "Label", e.Arial, 16, e.col_grey8, curr_val, 0, min, max, step)
1126 | local hslider01 = e.Horz_Slider:new( {1, 2}, x, y, w, h, e.col_blue, "Label", e.Arial, 16, e.col_grey8, curr_val, 0, min, max, step)
1127 | local vslider01 = e.Vert_Slider:new( {1, 3}, x, y, w, h, e.col_blue, "Label", e.Arial, 16, e.col_grey8, curr_val, 0, min, max, step)
1128 | local hrslider01 = e.H_Rng_Slider:new( {1, 2}, x, y, w, h, e.col_blue, "Label", e.Arial, 16, e.col_grey8, lo_val, hi_val, min, max, step)
1129 | local vrslider01 = e.V_Rng_Slider:new( {1, 3}, x, y, w, h, e.col_blue, "Label", e.Arial, 16, e.col_grey8, lo_val, hi_val, min, max, step)
1130 |
1131 | Elements can be displayed on multiple layers, defined in the 'tabs' table. 0 means all layers.
1132 |
1133 | Checkbox and Radiobutton elements use 'w' and 'h' to define the width and height of each checkbox or radiobutton.
1134 | The overall element height is derived from the total number of options multiplied by 'h', plus padding
1135 | The overall element width is derived from 'w' plus the length of the longest label string, plus padding
1136 | --]]
1137 |
1138 | --[[
1139 | Example e.Element functions
1140 | button01.onLClick = function()
1141 | reaper.ShowConsoleMsg("Button Example")
1142 | end
1143 |
1144 | droplist01.onLClick = function()
1145 | if droplist01.val1 == 1 then e.gScale = 0.7
1146 | elseif droplist01.val1 == 2 then e.gScale = 0.8
1147 | elseif droplist01.val1 == 3 then e.gScale = 0.9
1148 | elseif droplist01.val1 == 4 then e.gScale = 1
1149 | end
1150 | -- Save state, close and reopen GFX window
1151 | __,gWinX,gWinY,__,__ = gfx.dock(-1,0,0,0,0)
1152 | gScaleState = true
1153 | gfx.quit()
1154 | InitGFX()
1155 | end
1156 | --]]
1157 |
--------------------------------------------------------------------------------
/MIDI Editor/MIDI Ex Machina/euclid.lua:
--------------------------------------------------------------------------------
1 | --[[
2 | @description Euclidean Algorithm Library
3 | @about
4 | #### Implements the Bjorklund Euclidean Algorithm
5 | @noindex
6 | @version 1.0
7 | --]]
8 |
9 | b = {}
10 | function b.bjorklund(pulses, steps)
11 | local pattern, counts, remainders = {}, {}, {}
12 | if pulses > steps then steps = pulses - 1 end
13 | local divisor = steps - pulses
14 | table.insert(remainders, pulses)
15 | local level = 1
16 | local run = true
17 | while run do
18 | table.insert(counts, divisor / remainders[level])
19 | table.insert(remainders, divisor % remainders[level])
20 | divisor = remainders[level]
21 | level = level + 1
22 | if remainders[level] <= 1 then
23 | run = false
24 | end
25 | end
26 | table.insert(counts, divisor)
27 | local build
28 | build = function(l)
29 | if l == -1 then
30 | table.insert(pattern, false)
31 | elseif l == -2 then
32 | table.insert(pattern, true)
33 | else
34 | for i = 1, counts[l+1] do
35 | build(l - 1)
36 | end
37 | if remainders[l+1] ~= 0 then
38 | build(l - 2)
39 | end
40 | end
41 | end -- build = function()
42 | build(level - 1)
43 | local i = b.get_index(pattern, true)
44 | pattern = b.rotate(pattern, i - 1)
45 | return pattern
46 | end
47 |
48 | function b.get_index(t, key)
49 | for i, k in ipairs(t) do
50 | if k == key then
51 | return i
52 | end
53 | end
54 | return 0
55 | end
56 |
57 | function b.rotate(p, d)
58 | local res = {}
59 | for i = d+1, #p do
60 | table.insert(res, p[i])
61 | end
62 | for i = 1, d do
63 | table.insert(res, p[i])
64 | end
65 | return res
66 | end
67 |
68 | function b.print_pattern(p)
69 | local pat = ""
70 | for i, v in ipairs(p) do
71 | pat = pat .. (v == true and 1 or 0)
72 | end
73 | print(pat)
74 | end
75 |
76 | function b.generate(pulses, steps)
77 | local pat = b.bjorklund(pulses, steps)
78 | return pat
79 | end
80 |
81 | return b
82 |
83 |
84 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # ReaScripts
2 |
3 | Lua scripts for REAPER - http://reaper.fm/
4 |
5 | See the [Wiki](https://github.com/RobU23/ReaScripts/wiki) for details
6 |
7 | This repository is [ReaPack](https://reapack.com/) compatible - The import URL is `https://github.com/RobU23/ReaScripts/raw/master/index.xml`
8 |
9 | ---
10 | *If you find any of this stuff useful, and would like to buy me a beer, the internets has the answer...*
11 | [Beer Donation](https://www.paypal.me/RobUrquhart)
12 |
--------------------------------------------------------------------------------
/index.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
33 | Forum Thread
34 | https://www.paypal.me/RobUrquhart
35 |
36 |
37 |
42 | https://github.com/RobU23/ReaScripts/raw/b425115e55ea654c8916ef6c3a3ee71b359a87d0/MIDI%20Editor/MIDI%20Ex%20Machina/RobU%20-%20MIDI%20Ex%20Machina.lua
43 | https://github.com/RobU23/ReaScripts/raw/b425115e55ea654c8916ef6c3a3ee71b359a87d0/MIDI%20Editor/MIDI%20Ex%20Machina/eGUI.lua
44 | https://github.com/RobU23/ReaScripts/raw/b425115e55ea654c8916ef6c3a3ee71b359a87d0/MIDI%20Editor/MIDI%20Ex%20Machina/euclid.lua
45 | https://github.com/RobU23/ReaScripts/raw/b425115e55ea654c8916ef6c3a3ee71b359a87d0/MIDI%20Editor/MIDI%20Ex%20Machina/persistence.lua
46 |
47 |
48 |
64 | https://github.com/RobU23/ReaScripts/raw/2116b22f05844ed25267fb03e6190063c1480afe/MIDI%20Editor/MIDI%20Ex%20Machina/RobU%20-%20MIDI%20Ex%20Machina.lua
65 | https://github.com/RobU23/ReaScripts/raw/2116b22f05844ed25267fb03e6190063c1480afe/MIDI%20Editor/MIDI%20Ex%20Machina/eGUI.lua
66 | https://github.com/RobU23/ReaScripts/raw/2116b22f05844ed25267fb03e6190063c1480afe/MIDI%20Editor/MIDI%20Ex%20Machina/euclid.lua
67 | https://github.com/RobU23/ReaScripts/raw/2116b22f05844ed25267fb03e6190063c1480afe/MIDI%20Editor/MIDI%20Ex%20Machina/persistence.lua
68 |
69 |
70 |
88 | https://github.com/RobU23/ReaScripts/raw/af80cdadc76b1dbe4fcfc4cc3f946f4b9df5dd36/MIDI%20Editor/MIDI%20Ex%20Machina/RobU%20-%20MIDI%20Ex%20Machina.lua
89 | https://github.com/RobU23/ReaScripts/raw/af80cdadc76b1dbe4fcfc4cc3f946f4b9df5dd36/MIDI%20Editor/MIDI%20Ex%20Machina/eGUI.lua
90 | https://github.com/RobU23/ReaScripts/raw/af80cdadc76b1dbe4fcfc4cc3f946f4b9df5dd36/MIDI%20Editor/MIDI%20Ex%20Machina/euclid.lua
91 | https://github.com/RobU23/ReaScripts/raw/af80cdadc76b1dbe4fcfc4cc3f946f4b9df5dd36/MIDI%20Editor/MIDI%20Ex%20Machina/persistence.lua
92 |
93 |
94 |
116 | https://github.com/RobU23/ReaScripts/raw/2ac1c28669a5dc429a83b3c0e84e6230e8d14ce3/MIDI%20Editor/MIDI%20Ex%20Machina/RobU%20-%20MIDI%20Ex%20Machina.lua
117 | https://github.com/RobU23/ReaScripts/raw/2ac1c28669a5dc429a83b3c0e84e6230e8d14ce3/MIDI%20Editor/MIDI%20Ex%20Machina/eGUI.lua
118 | https://github.com/RobU23/ReaScripts/raw/2ac1c28669a5dc429a83b3c0e84e6230e8d14ce3/MIDI%20Editor/MIDI%20Ex%20Machina/euclid.lua
119 | https://github.com/RobU23/ReaScripts/raw/2ac1c28669a5dc429a83b3c0e84e6230e8d14ce3/MIDI%20Editor/MIDI%20Ex%20Machina/persistence.lua
120 |
121 |
122 |
124 | https://github.com/RobU23/ReaScripts/raw/6fc14048fee05b74b2888e5a5a69061eabe3630f/MIDI%20Editor/MIDI%20Ex%20Machina/RobU%20-%20MIDI%20Ex%20Machina.lua
125 | https://github.com/RobU23/ReaScripts/raw/6fc14048fee05b74b2888e5a5a69061eabe3630f/MIDI%20Editor/MIDI%20Ex%20Machina/eGUI.lua
126 | https://github.com/RobU23/ReaScripts/raw/6fc14048fee05b74b2888e5a5a69061eabe3630f/MIDI%20Editor/MIDI%20Ex%20Machina/euclid.lua
127 | https://github.com/RobU23/ReaScripts/raw/6fc14048fee05b74b2888e5a5a69061eabe3630f/MIDI%20Editor/MIDI%20Ex%20Machina/persistence.lua
128 |
129 |
130 |
133 | https://github.com/RobU23/ReaScripts/raw/e697cda55c3306c429bcc1c40d89736ab537f20d/MIDI%20Editor/MIDI%20Ex%20Machina/RobU%20-%20MIDI%20Ex%20Machina.lua
134 | https://github.com/RobU23/ReaScripts/raw/e697cda55c3306c429bcc1c40d89736ab537f20d/MIDI%20Editor/MIDI%20Ex%20Machina/eGUI.lua
135 | https://github.com/RobU23/ReaScripts/raw/e697cda55c3306c429bcc1c40d89736ab537f20d/MIDI%20Editor/MIDI%20Ex%20Machina/euclid.lua
136 | https://github.com/RobU23/ReaScripts/raw/e697cda55c3306c429bcc1c40d89736ab537f20d/MIDI%20Editor/MIDI%20Ex%20Machina/persistence.lua
137 |
138 |
139 |
144 | https://github.com/RobU23/ReaScripts/raw/0692c3bb7ceaa9490f27172749f0a5af51c992bc/MIDI%20Editor/MIDI%20Ex%20Machina/RobU%20-%20MIDI%20Ex%20Machina.lua
145 | https://github.com/RobU23/ReaScripts/raw/0692c3bb7ceaa9490f27172749f0a5af51c992bc/MIDI%20Editor/MIDI%20Ex%20Machina/eGUI.lua
146 | https://github.com/RobU23/ReaScripts/raw/0692c3bb7ceaa9490f27172749f0a5af51c992bc/MIDI%20Editor/MIDI%20Ex%20Machina/euclid.lua
147 |
148 |
149 |
150 |
151 |
--------------------------------------------------------------------------------