From a892dabd61356d5b71070fd84126bcd8740c58f2 Mon Sep 17 00:00:00 2001 From: zzo38 Date: Thu, 5 Jul 2012 14:00:06 -0700 Subject: [PATCH] First commit --- .gitattributes | 1 + COPYING | 674 +++++++++++++++++++ compile | 2 + itmck.c | 1969 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ itmck_manual.tex | 438 ++++++++++++ vcslist | 6 + 6 files changed, 3090 insertions(+) create mode 100755 .gitattributes create mode 100755 COPYING create mode 100755 compile create mode 100755 itmck.c create mode 100755 itmck_manual.tex create mode 100755 vcslist diff --git a/.gitattributes b/.gitattributes new file mode 100755 index 0000000..9acf740 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +* text diff --git a/COPYING b/COPYING new file mode 100755 index 0000000..94a9ed0 --- /dev/null +++ b/COPYING @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. diff --git a/compile b/compile new file mode 100755 index 0000000..beff2df --- /dev/null +++ b/compile @@ -0,0 +1,2 @@ +#!/bin/bash -- +gcc -s -o itmck itmck.c -lm diff --git a/itmck.c b/itmck.c new file mode 100755 index 0000000..d841f01 --- /dev/null +++ b/itmck.c @@ -0,0 +1,1969 @@ +/* + ITMCK + Version 0.1 + Licensed under GNU GPL v3 or later version +*/ + +#define itmck_version "ITMCK v0.1" +#define itmck_version_code 0x7010 +#define impulse_tracker_version_code 0x0204 + +#include +#include +#include +#include +#include + +#define FX(x) ((x)&0x1F) +#define FXC(x) (FX(x)+26) +#define C_pitch 261.6255653 +#define tau (2.0*M_PI) +#define rand_double() (2.0 * ((double) rand() / (double)RAND_MAX - 0.5)) +#define unequal3(x,y,z) ((x)!=(y) && (x)!=(z) && (y)!=(z)) +#define unequal3lt(x,y,z) ((x)!=(y) && (x)<(z) && (y)<(z)) +#define ITout stdout + +typedef unsigned char byte; +typedef byte boolean; + +typedef struct chan_info { + short transpose; + byte octave; + short length; + byte instrument; + byte effectid; // 0=not set + byte effectpar; + byte volumeset; // 255=not set + short quantize; // <0=deduct frames >0=fraction of time + byte note_cuts; // 255=off, 254=cut, 253=fade, 250=continue + byte ch_vol; // use for .IT header: 0-64 + byte ch_pan; // use for .IT header: 0-64, 32=center, 100=surround + int row; + int row_cut; // use for slurs/ties and auto portamento + int row_tie; // use for ties + int loopstart; + int loopskip; + int loopend; + byte keytable; // 255=unuse + byte customfx; // 255=unuse + boolean auto_portamento; // set if next command should auto portamento + byte prev_note; // use for tie and auto portamento +} chan_info; + +typedef struct message_line { + char*data; + struct message_line*next; +} message_line; + +typedef struct chan_row { + byte note; // 200=unuse + byte instrument; // 255=unuse + byte effectid; // 255=unuse + byte effectpar; + byte volumeset; // 255=unuse + byte continue_flag; // 0x01=effect 0x02=volume 0x04=zero next effect 0x80=used +} chan_row; + +typedef struct chan_row_block { + chan_row data[17]; // data[16]=global effects + boolean used; // keep track of which row contains data +} chan_row_block; + +typedef struct key_setting { + byte note; + byte instrument; // 255=unuse + byte effectid; // 0=unuse + byte effectpar; + byte volumeset; // 255=unuse + byte customfx; // 255=unuse +} key_setting; + +typedef struct instrument_data { + byte heading[11]; // address 0x0011 to 0x001B + byte ifc; // cutoff 0-127; bit7=enable + byte ifr; // resonance 0-127; bit7=enable + byte keyboard[240]; + byte vol_env[82]; + byte pan_env[82]; + byte pitch_env[82]; // bit7 of flag enables filter envelope + boolean used; // set if instrument is selected in MML +} instrument_data; + +typedef struct sample_data { + byte global_volume; + byte flag; + byte default_volume; + byte convert; + byte pan; + int length; + int loop_start; + int loop_end; + int c5speed; + int sustain_start; + int sustain_end; + byte vibrato[4]; + byte make; // Mode to make data: 1=raw-file 2=synth 3=copy 4=IMPS-file + byte link; // Depend on 'make' + char*name; // Filename or depend on 'make' + boolean used; // set when compiling instruments, before compiling samples +} sample_data; + +typedef struct custom_fx { + short transpose; // 255=omit note + byte instrument; // 255=unuse + byte effectid; // 0=unuse + byte effectpar; + byte volumeset; // 255=unuse + byte continue_flag; // 0x01=effect 0x02=volume 0x04=zero next effect 0x80=continue pass note + int delta; + struct custom_fx*next; +} custom_fx; + +byte it_flags=0x0E; +chan_info channels[16]; +message_line*song_message; +message_line**next_song_message=&song_message; +int song_message_length=0; +short octave_dir=1; +char song_title[26]; +byte gate_denom=8; +byte whole_note=48; +byte panning_separation=128; +byte init_tempo=120; +char scale_base='c'; +char*macro_text[256][16]; +byte g_vol=128; +byte g_mixer=48; +key_setting keytab[64][120]; +custom_fx fxtab[64]; +unsigned short tracker_version=itmck_version_code; // Cwt +sample_data samples[100]; +instrument_data instruments[100]; +byte max_sample=0; +byte max_instrument=0; +byte compatibility=0; // 0=Impulse Tracker +int numeric_register[27]; // register 0 ('`') is special +char*filename_prefix=""; +byte export_sample=0; +chan_row_block*frames; +int max_frames=0; +boolean synth16bits=0; +int synth_len_mult=1; +boolean trace_input=0; +unsigned long out_offset=0x00000000UL; + +// A ' B | C ' D ' E | F ' G ' (h) (i) (j) +short note_letter[10] = { -3, -1, 0, 2, 4, 5, 7, 0, 0, 0 }; +int octave_tones=12; + +//Predeclare +void read_file(FILE*fp); + +inline void write8(int x) { + putchar(x&0xFF); +} + +inline void write16(int x) { + putchar(x&0xFF); + putchar((x>>8)&0xFF); +} + +inline void write32(int x) { + putchar(x&0xFF); + putchar((x>>8)&0xFF); + putchar((x>>16)&0xFF); + putchar((x>>24)&0xFF); +} + +int read_int(char**s) { + char c; + int r=0; + int q=1; + int b=10; + if(**s==',') (*s)++; + if(**s=='$' && (*s)[1]>='`' && (*s)[1]<='z') return numeric_register[(*s)[1]&0x1F]; + if(**s=='+') (*s)++; + if(**s=='-') { q=-1; (*s)++; } + if(**s=='$') { b=16; (*s)++; } + while((**s>='0' && **s<='9') || (b==16 && **s>='A'&& **s<='F')) { + c=*((*s)++); + r=r*b+c-('0'+7*(c>='A')); + } + return q*r; +} + +int read_note(char**s) { + int x; + if(**s=='n') { + ++*s; + return read_int(s); + } + if(**s<'a' || **s>'j') return -1; + x=*((*s)++); + x=note_letter[x-'a']+octave_tones*(x32) t++; + if(*t) *t++=0; + else t=0; + skip_spaces(&t); + if(!strcmp(s,"AMIGA-SLIDES")) { + it_flags&=~0x08; + } else if(!strcmp(s,"CHANNEL")) { + int x; + for(x=0;x<16;x++) { + channels[x].ch_vol=read_int(&t); + if(channels[x].ch_vol<0 || channels[x].ch_vol>64) fprintf(stderr,"Abnormal channel volume (%c).\n",x+'A'); + skip_spaces(&t); + channels[x].ch_pan=read_int(&t); + if((channels[x].ch_pan<0 || channels[x].ch_pan>64) && channels[x].ch_pan!=100) + fprintf(stderr,"Abnormal channel panning (%c).\n",x+'A'); + skip_spaces(&t); + } + } else if(!strcmp(s,"COMPATIBILITY")) { + compatibility=read_int(&t); + } else if(!strcmp(s,"GATE-DENOM")) { + gate_denom=read_int(&t); + if(gate_denom<1) fprintf(stderr,"Abnormal gate denominator.\n"); + } else if(!strcmp(s,"INCLUDE")) { + FILE*fp=fopen(t,"r"); + if(fp) { + read_file(fp); + fclose(fp); + } else { + fprintf(stderr,"File cannot be loaded: %s\n",t); + } + } else if(!strcmp(s,"LINEAR-SLIDES")) { + it_flags|=0x08; + } else if(!strcmp(s,"MINIMUM-VERSION")) { + if(read_int(&t)>(itmck_version_code&0x0FFF)) { + fprintf(stderr,"*FATAL* Input file requires later version of ITMCK.\n"); + exit(1); + } + } else if(!strcmp(s,"MIXER")) { + g_mixer=read_int(&t); + if(g_mixer==0 || g_mixer>128) fprintf(stderr,"Abnormal mix volume.\n"); + } else if(!strcmp(s,"MONO")) { + it_flags&=~0x01; + } else if(!strcmp(s,"OCTAVE-REV")) { + octave_dir=read_int(&t)?-1:1; + } else if(!strcmp(s,"OLD-EFFECTS")) { + it_flags|=0x10; + } else if(!strcmp(s,"PANNING-SEPARATION")) { + panning_separation=read_int(&t); + if(panning_separation<0 || panning_separation>128) fprintf(stderr,"Abnormal panning separation.\n"); + } else if(!strcmp(s,"PORTAMENTO-SHARE")) { + it_flags|=0x20; + } else if(!strcmp(s,"SCALE")) { + int x=0; + int b=0; + char*y=t; + while(*t++) { + if(*t=='|') b=x; + x+=(*t>' '); + } + x=-b; + while(*y++) { + if(*y>='a' && *y<='j') note_letter[*y-'a']=x; + x+=(*y>' ' && *y!='|'); + } + } else if(!strcmp(s,"SCALE-BASE")) { + scale_base=*t; + if(*t<'a' || *t>'j') fprintf(stderr,"Abnormal scale base (%s).\n",t); + } else if(!strcmp(s,"STEREO")) { + it_flags|=0x01; + } else if(!strcmp(s,"SYNTH-LENGTH")) { + synth_len_mult=read_int(&t); + } else if(!strcmp(s,"SYNTH16")) { + synth16bits=1; + } else if(!strcmp(s,"TEMPO")) { + init_tempo=read_int(&t); + if(init_tempo<32) fprintf(stderr,"Abnormal tempo.\n"); + } else if(!strcmp(s,"TITLE")) { + strncpy(song_title,t,26); + } else if(!strcmp(s,"TRACKER-VERSION")) { + tracker_version=read_int(&t); + } else if(!strcmp(s,"VOL0MIXOPT")) { + it_flags|=0x02; + } else if(!strcmp(s,"VOLUME")) { + g_vol=read_int(&t); + if(g_vol>128) fprintf(stderr,"Abnormal global volume.\n"); + } else if(!strcmp(s,"WHOLE-NOTE")) { + whole_note=read_int(&t); + if(!whole_note) fprintf(stderr,"Abnormal whole note time.\n"); + } else { + fprintf(stderr,"Unknown command: #%s\n",s); + } +} + +void read_sample_def(byte n, char*s) { + char*t; + int x,y; + while(skip_spaces(&s),*s) { + switch(*s++) { + + case '@': // Copy sample + if(*s=='s') s++; + x=read_int(&s); + if(x>=n || !x) { + fprintf(stderr,"Cannot copy sample %d to %d.\n",x,n); + } else if(samples[n].make || samples[x].make==3) { + fprintf(stderr,"Cannot copy a copy of a sample or change an existing sample into a copy.\n",x,n); + } else { + samples[n].make=3; + samples[n].link=x; + samples[n].global_volume=samples[x].global_volume; + samples[n].flag=samples[x].flag; + samples[n].default_volume=samples[x].default_volume; + samples[n].convert=samples[x].convert; + samples[n].pan=samples[x].pan; + samples[n].loop_start=samples[x].loop_start; + samples[n].loop_end=samples[x].loop_end; + samples[n].c5speed=samples[x].c5speed; + samples[n].sustain_start=samples[x].sustain_start; + samples[n].sustain_end=samples[x].sustain_end; + } + break; + + case 'F': // File(IMPS) + if(!samples[n].make) samples[n].make=4; + if(samples[n].make!=4) fprintf(stderr,"Conflicting sample loading modes (%d).\n",n); + if(*s++!='=') fprintf(stderr,"Equal sign expected before filename.\n",n); + t=s; + while(*s++>' '); + *s++=0; + samples[n].name=strdup(t); + //todo + break; + + case 'G': // Global volume + samples[n].global_volume=read_int(&s); + if(samples[n].global_volume>64) fprintf(stderr,"Abnormal sample global volume.\n"); + break; + + case 'L': // Loop + samples[n].flag|=0x10; + x=read_int(&s); y=read_int(&s); + if(x64) fprintf(stderr,"Abnormal sample default volume.\n"); + break; + + case 'f': // File(raw) + if(!samples[n].make) samples[n].make=1; + if(samples[n].make!=1) fprintf(stderr,"Conflicting sample loading modes (%d).\n",n); + if(*s++!='=') fprintf(stderr,"Equal sign expected before filename.\n",n); + t=s; + while(*s++>' '); + *s++=0; + samples[n].name=strdup(t); + break; + + case 'r': // C5 speed + if(!(samples[n].c5speed=read_int(&s))) fprintf(stderr,"Abnormal C5speed.\n"); + break; + + case 'v': // Vibrato + x=*s++; + if(x=='U') samples[n].vibrato[3]=0; + if(x=='N') samples[n].vibrato[3]=1; + if(x=='L') samples[n].vibrato[3]=2; + if(x=='R') samples[n].vibrato[3]=3; + else fprintf(stderr,"Invalid vibrato waveform: %c.\n",x); + samples[n].vibrato[2]=read_int(&s); + samples[n].vibrato[1]=read_int(&s); + samples[n].vibrato[0]=read_int(&s); + if(samples[n].vibrato[2]>64) fprintf(stderr,"Abnormal sample vibrato rate.\n"); + if(samples[n].vibrato[1]>64) fprintf(stderr,"Abnormal sample vibrato depth.\n"); + if(samples[n].vibrato[0]>64) fprintf(stderr,"Abnormal sample vibrato speed.\n"); + break; + + case 'y': // Pan + samples[n].pan=read_int(&s)|128; + break; + + case '}': // End of sample definition + skip_spaces(&s); + if(*s) fprintf(stderr,"Sample definition ends early.\n"); + return; + + default: + fprintf(stderr,"Unknown command in sample definition: %c\n",s[-1]); + } + } +} + +void read_envelope(byte*env,char**s) { + int x; + int skip=1; + int ticks=0; + byte*e2; + if(1&*env) { + fprintf(stderr,"This envelope is already set.\n"); + return; + } + *env|=1; + while(skip_spaces(s),**s) { + switch(*((*s)++)) { + + case '[': case '{': case '=': // Ignore + break; + + case ']': case '}': // End + if(!env[1]) fprintf(stderr,"This envelope has no nodes. (How does it smell?)\n"); + return; + + case '(': // Begin loop + env[2]=env[1]; + break; + + case ')': // End loop + env[3]=env[1]-1; + *env|=2; + break; + + case '<': // Begin sustain + env[4]=env[1]; + break; + + case '>': // End sustain + env[5]=env[1]-1; + *env|=4; + break; + + case '@': // Copy + x=read_int(s); + if(x<1 || x>max_instrument) { + fprintf(stderr,"Attempting to copy envelope from nonexisting instrument.\n"); + } else { + if(**s=='f' || **s=='i') e2=instruments[x].pitch_env; + else if(**s=='v') e2=instruments[x].vol_env; + else if(**s=='p') e2=instruments[x].pan_env; + else return; + *env|=*e2; + memcpy(env+1,e2+1,61); + } + (*s)++; + return; + + case 'a': // Advance + ticks+=read_int(s); + break; + + case 's': // Set skip + skip=read_int(s); + break; + + case '$': case '0' ... '9': case '-': case '+': // Values + env[env[1]*3+6]=x=read_int(s); + if(x<-32 || x>64) fprintf(stderr,"Abnormal envelope value.\n"); + env[env[1]*3+7]=ticks&0xFF; + env[env[1]*3+8]=ticks>>8; + env[1]++; + ticks+=skip; + break; + + default: + fprintf(stderr,"Unknown command in envelope: %c\n", (*s)[-1]); + } + if(env[1]>25) { + fprintf(stderr,"*FATAL* Too many nodes in envelope.\n"); + exit(1); + } + } + if(!env[1]) fprintf(stderr,"This envelope has no nodes.\n"); +} + +void read_instrument_key_table(byte n,char**s) { + int x,y,z1,z2,z3,z4; + while(skip_spaces(s),**s) { + switch(*((*s)++)) { + + case '[': case '{': case '=': // Ignore + break; + + case ']': case '}': // End + return; + + case '%': // Copy key assign along octaves + x=read_int(s); y=read_int(s); + if(y>0 && x>=y) { + for(z1=z2=z3=0;z1<120;z1++,z2=(z2+1)%x,z3+=y*!z2) { + instruments[n].keyboard[z1<<1]=instruments[n].keyboard[z2<<1]+z3; + instruments[n].keyboard[1|(z1<<1)]=instruments[n].keyboard[1|(z2<<1)]; + } + } else { + fprintf(stderr,"Abnormal %% command in instruments key table.\n"); + } + break; + + case 'a' ... 'j': case 'n': // Assign keys + --*s; + x=read_note(s); + if(**s==':') { + y=read_note(s); + if(y==-1) fprintf(stderr,"Wrong note of range of assign key instrument table.\n"); + else if(y-1) { + z1=0; + } else { + z1=1; + z2=read_int(s); + } + if(**s=='@') { + ++*s; + if(**s=='s') ++*s; + z3=read_int(s); + } else { + z3=0; + } + z4=(**s=='+'); *s+=z4; + while(x<=y) { + instruments[n].keyboard[x<<1]=x*z1+z2; + if(z3) instruments[n].keyboard[1|(x<<1)]=z3; + x++; + z3+=z4; + } + break; + + default: + fprintf(stderr,"Unknown command in instrument key table: %c\n", (*s)[-1]); + } + } +} + +void read_instrument_def(byte n, char*s) { + char*t; + int x,y; + while(skip_spaces(&s),*s) { + switch(*s++) { + + case '@': // Set sample for all notes, or copy instrument + if(*s=='s') { + s++; + x=read_int(&s); + for(y=0;y<120;y++) instruments[n].keyboard[1|(y<<1)]=x; + } else { + x=read_int(&s); + if(x<1 || x>99 || x==n) fprintf(stderr,"Instrument number out of range during copy.\n"); + else memcpy(instruments+n,instruments+x,sizeof(instrument_data)); + } + break; + + case 'A': // Note action + x=read_int(&s); + instruments[n].heading[0]=x&3; // NNA + instruments[n].heading[1]=(x/10)&3; // DCT + instruments[n].heading[2]=(x/100)&3; // DCA + if(x<0 || x%10>3 || (x/10)%10>3 || x/100>2) fprintf(stderr,"Abnormal NNA/DCT/DCA.\n"); + break; + + case 'G': // Global volume + instruments[n].heading[7]=x=read_int(&s); + if(x<0 || x>128) fprintf(stderr,"Abnormal instrument global volume.\n"); + break; + + case 'R': // Random volume/panning variation + instruments[n].heading[9]=x=read_int(&s); + if(x<0 || x>100) fprintf(stderr,"Abnormal random volume variation.\n"); + instruments[n].heading[10]=read_int(&s); + break; + + case 'Y': // Pitch-pan separation/center + x=read_int(&s); + if(x<-32 || x>32) fprintf(stderr,"Abnormal pitch-pan separation.\n"); + instruments[n].heading[5]=x; + if(!(x=*s++)) { + fprintf(stderr,"Instrument definition ends in a pitch-pan specification.\n"); + return; + } + if(x=='n') { + x=read_int(&s); + } else { + if(x<'a' || x>'j') { + fprintf(stderr,"*FATAL* Invalid pitch-pan center note letter.\n"); + exit(1); + } + x=(x119) fprintf(stderr,"Abnormal pitch-pan center.\n"); + instruments[n].heading[6]=x; + break; + + case 'c': // Initial filter cutoff + instruments[n].ifc=(x=read_int(&s))|128; + if(x<0 || x>127) fprintf(stderr,"Abnormal initial filter cutoff.\n"); + break; + + case 'f': // Filter envelope + instruments[n].pitch_env[0]|=0x80; + read_envelope(instruments[n].pitch_env,&s); + break; + + case 'k': // Key/sample table + read_instrument_key_table(n,&s); + break; + + case 'i': // Pitch envelope + instruments[n].pitch_env[0]&=~0x80; + read_envelope(instruments[n].pitch_env,&s); + break; + + case 'p': // Pan envelope + read_envelope(instruments[n].pan_env,&s); + break; + + case 'r': // Initial filter resonance + instruments[n].ifr=(x=read_int(&s))|128; + if(x<0 || x>127) fprintf(stderr,"Abnormal initial filter resonance.\n"); + break; + + case 'v': // Volume envelope + read_envelope(instruments[n].vol_env,&s); + break; + + case 'y': // Default pan + instruments[n].heading[8]=x=read_int(&s); + if(x<0 || x>64) fprintf(stderr,"Abnormal instrument default pan.\n"); + break; + + case '}': // End of instrument definition + skip_spaces(&s); + if(*s) fprintf(stderr,"Instrument definition ends early.\n"); + return; + + default: + fprintf(stderr,"Unknown command in instrument definition: %c\n",s[-1]); + } + } +} + +void read_key_table_def(byte n,char*s) { + char*t; + int k=0; + int x; + char*loop=0; + while(skip_spaces(&s),*s) { + switch(*s++) { + + case '*': // Volume + keytab[n][k].volumeset=read_int(&s); + break; + + case '@': // Adjust variable/direct effects/instrument/copy key table/cusfom effect sequence + if(*s=='=') { + s++; x=(*s++&0x1F)%27; numeric_register[x]=read_int(&s); + } else if(*s=='+') { + s++; x=(*s++&0x1F)%27; numeric_register[x]+=read_int(&s); + } else if(*s=='-') { + s++; x=(*s++&0x1F)%27; numeric_register[x]-=read_int(&s); + } else if(*s=='*') { + s++; x=(*s++&0x1F)%27; numeric_register[x]*=read_int(&s); + } else if(*s=='e') { + s++; keytab[n][k].effectid=read_int(&s); keytab[n][k].effectpar=read_int(&s); keytab[n][k].volumeset=read_int(&s); + } else if((*s>='0' && *s<='9') || *s=='$') { + keytab[n][k].instrument=read_int(&s)?:255; + if(keytab[n][k].instrument>max_instrument) fprintf(stderr,"Unuse instrument %d.\n",channels[ch].instrument); + } else if(*s=='@') { + t=++s; x=read_int(&s); + if(x!=n && x>=0 && x<64) memcpy(keytab[n]+k,keytab[x]+k,sizeof(key_setting)); + else fprintf(stderr,"Wrong key table number %d.\n",x); + } else if(*s=='u') { + t=++s; x=read_int(&s); keytab[n][k].customfx=(t==s)?255:x; + } else if(*s=='`') { + *numeric_register=at_backtick(n,k,*++s); + } else { + fprintf(stderr,"Unknown command in channel %c: @%c\n", ch+'A', *s++); + } + break; + + case '[': // Begin loop + if(loop) fprintf(stderr,"Nested loop in key table definition.\n"); + loop=s; + break; + + case ']': // End loop + x=read_note(&s); + if(x<0 || x>119) x=119; + if(loop) { + if(k0xDF) { + fprintf(stderr,"Abnormal portamento rate.\n"); + } else if(x>0) { + keytab[n][k].effectid=FX('F'); + keytab[n][k].effectpar=x; + } else { + keytab[n][k].effectid=FX('E'); + keytab[n][k].effectpar=-x; + } + break; + + case 'T': // Tremolo + keytab[n][k].effectid=FX('R'); + keytab[n][k].effectpar=read_int(&s)<<4; + keytab[n][k].effectpar|=read_int(&s); + break; + + case 'V': // Vibrato + x=read_int(&s); + if(x<1 || x>15) fprintf(stderr,"Abnormal vibrato speed.\n"); + keytab[n][k].effectpar=x<<4; + x=read_int(&s); + if(x>0 && x<16) { + keytab[n][k].effectid=FX('U'); + keytab[n][k].effectpar|=x; + } else if(x>0 && x<=60 && !(x&3)) { + keytab[n][k].effectid=FX('H'); + keytab[n][k].effectpar|=x>>2; + } else { + fprintf(stderr,"Abnormal vibrato depth.\n"); + } + break; + + case 'Y': // Panbello + keytab[n][k].effectid=FX('Y'); + keytab[n][k].effectpar=read_int(&s)<<4; + keytab[n][k].effectpar|=read_int(&s); + break; + + case 'a' ... 'j': case 'n': // Note entry + s--; + k=read_note(&s); + if(k<0 || k>119) { + fprintf(stderr,"Note out-of-range.\n"); + k=0; + } + break; + + case '}': // End of key table definition + skip_spaces(&s); + if(*s) fprintf(stderr,"Key table definition ends early.\n"); + return; + + default: + fprintf(stderr,"Unknown command in key table definition: %c\n",s[-1]); + } + } +} + +void read_custom_fx_def(byte n,char*s) { + custom_fx*cfx=fxtab+n; + custom_fx*tmp; + short cuts=255; + byte cont=0; // 0x80=continue sequence before/after note stopped + int x; + char*loop=0; + int loopc=0; + while(skip_spaces(&s),*s) { + switch(*s++) { + + case '-': case '+': case '$': case '0' ... '9': // Delta + s--; + cfx->delta=read_int(&s); + tmp=cfx->next; + cfx->next=malloc(sizeof(custom_fx)); + cfx=cfx->next; + cfx->transpose=0; + cfx->instrument=255; + cfx->effectid=0; + cfx->volumeset=255; + cfx->continue_flag=cont; + cfx->delta=0; + cfx->next=tmp; + break; + + case '(': // Begin continue sequence + cfx->continue_flag|=(cont=0x80); + break; + + case ')': // End continue sequence + cont=0; + break; + + case '*': // Note volume + cfx->volumeset=read_int(&s); + cfx->continue_flag&=~0x02; + break; + + case ':': // Final delta + cfx->delta=read_int(&s); + break; + + case '@': // Direct effect entry, chain to sequence, instrument select + if(*s=='=') { + s++; x=(*s++&0x1F)%27; numeric_register[x]=read_int(&s); + } else if(*s=='+') { + s++; x=(*s++&0x1F)%27; numeric_register[x]+=read_int(&s); + } else if(*s=='-') { + s++; x=(*s++&0x1F)%27; numeric_register[x]-=read_int(&s); + } else if(*s=='*') { + s++; x=(*s++&0x1F)%27; numeric_register[x]*=read_int(&s); + } else if(*s=='e') { + s++; cfx->effectid=read_int(&s); cfx->effectpar=read_int(&s); cfx->volumeset=read_int(&s); + cfx->continue_flag|=0x03; + } else if(*s=='f') { + s++; cfx->effectid=read_int(&s); cfx->effectpar=read_int(&s); + cfx->continue_flag&=~0x05; + } else if(*s=='u') { + s++; cfx->next=fxtab+(63&read_int(&s)); + } else if(*s=='v') { + s++; cfx->volumeset=read_int(&s); + cfx->continue_flag&=~0x02; + } else if(*s=='z') { + cfx->continue_flag|=0x04; + } else if((*s>='0' && *s<='9') || *s=='$') { + cfx->instrument=read_int(&s); + } else { + fprintf(stderr,"Unknown command in custom effect sequence: @%c\n", *s++); + } + break; + + case 'C': // Set note cuts + x=*s++; + if(x=='o') cfx->transpose=cuts=255; + else if(x=='c') cfx->transpose=cuts=254; + else if(x=='f') cfx->transpose=cuts=253; + else fprintf(stderr,"Unknown command in custom effect sequence: C%c\n",x); + break; + + case 'I': // Tremor + cfx->effectid=FX('I'); + cfx->effectpar=read_int(&s)<<4; + cfx->effectpar|=read_int(&s); + cfx->continue_flag|=0x01; + break; + + case 'J': // Arpeggio + cfx->effectid=FX('J'); + cfx->effectpar=read_int(&s)<<4; + cfx->effectpar|=read_int(&s); + cfx->continue_flag|=0x01; + break; + + case 'K': // Transpose + cfx->transpose=read_int(&s); + break; + + case 'Q': // Retrigger + cfx->effectid=FX('Q'); + cfx->effectpar=read_int(&s)<<4; + cfx->effectpar|=read_int(&s); + cfx->continue_flag|=0x01; + break; + + case 'R': // Portamento + x=read_int(&s); + if(x<-0xDF || !x || x>0xDF) { + fprintf(stderr,"Abnormal portamento rate.\n"); + } else if(x>0) { + cfx->effectid=FX('F'); + cfx->effectpar=x; + } else { + cfx->effectid=FX('E'); + cfx->effectpar=-x; + } + cfx->continue_flag|=0x01; + break; + + case 'T': // Tremolo + cfx->effectid=FX('R'); + cfx->effectpar=read_int(&s)<<4; + cfx->effectpar|=read_int(&s); + cfx->continue_flag|=0x01; + break; + + case 'V': // Vibrato + x=read_int(&s); + if(x<1 || x>15) fprintf(stderr,"Abnormal vibrato speed.\n"); + cfx->effectpar=x<<4; + x=read_int(&s); + if(x>0 && x<16) { + cfx->effectid=FX('U'); + cfx->effectpar|=x; + } else if(x>0 && x<=60 && !(x&3)) { + cfx->effectid=FX('H'); + cfx->effectpar|=x>>2; + } else { + fprintf(stderr,"Abnormal vibrato depth.\n"); + } + cfx->continue_flag|=0x01; + break; + + case 'Y': // Panbello + cfx->effectid=FX('Y'); + cfx->effectpar=read_int(&s)<<4; + cfx->effectpar|=read_int(&s); + cfx->continue_flag|=0x01; + break; + + case '[': // Repeat begin + if(loop) fprintf(stderr,"Prohibit nesting repeats.\n"); + loop=s; + loopc=0; + break; + + case ']': // Repeat end + if(!loop) { + fprintf(stderr,"*FATAL* Repeat block ends without starting.\n"); + exit(1); + } + if((x=read_int(&s))<0) fprintf(stderr,"Abnormal repeat count.\n"); + if(x==++loopc) loop=0; else s=loop; + break; + + case 'r': // Rest + cfx->transpose=cuts; + break; + + case 'w': // Wait + cfx->transpose=200; + break; + + case '|': // Loop mark + cfx->next=cfx; + break; + + case '}': // End of definition + skip_spaces(&s); + if(*s) fprintf(stderr,"Custom effect sequence definition ends early.\n"); + goto check_custom_fx; + + default: + fprintf(stderr,"Unknown command in custom effect sequence definition: %c\n",s[-1]); + } + } +check_custom_fx: + if(!cfx->next) return; + //todo +} + +void at_definition(char*s) { + int x,y; + char*t; + char*p; + switch(*s++) { + + case '0' ... '9': // Instrument + case '$': // Instrument (hex) + s--; + x=read_int(&s); + if(x<=0 || x>99) { + fprintf(stderr,"Wrong instrument number (%d).\n",x); + return; + } + if(max_instrument63) { + fprintf(stderr,"Wrong key table number (%d).\n",x); + return; + } + skip_equals_brace(&s); + read_key_table_def(x,s); + break; + + case 'A' ... 'P': // Channel setting + x=s[-1]-'A'; + skip_equals_brace(&s); channels[x].ch_vol=read_int(&s); + skip_spaces(&s); channels[x].ch_pan=read_int(&s); + if(channels[x].ch_vol<0 || channels[x].ch_vol>64) fprintf(stderr,"Abnormal channel volume (%c).\n",x+'A'); + if((channels[x].ch_pan<0 || channels[x].ch_pan>64) && channels[x].ch_pan!=100) + fprintf(stderr,"Abnormal channel panning (%c).\n",x+'A'); + break; + + case 'X': // Text macro + x=read_int(&s); + if(x&~0xFF) { + fprintf(stderr,"Wrong macro number (%d).\n",x); + return; + } + t=s; y=(*t>='A' && *t<='P'); + while(*s && *s!='=') s++; + if(!*s) { + fprintf(stderr,"Incomplete macro definition (%d).\n",x); + return; + } + s++; skip_spaces(&s); p=strdup(s); + if(y) { + while(*t>='A' && *t<='P') macro_text[x][*t++-'A']=p; + } else { + while(y<16) macro_text[x][y++]=p; + } + break; + + case 's': // Sample + x=read_int(&s); + if(x<=0 || x>99) { + fprintf(stderr,"Wrong sample number (%d).\n",x); + return; + } + if(max_sample63) { + fprintf(stderr,"Wrong custom effect sequence number (%d).\n",x); + return; + } + skip_equals_brace(&s); + read_custom_fx_def(x,s); + break; + + default: + fprintf(stderr,"Unknown command: @%c\n",*s); + } +} + +void send_note(byte ch,short no,int prelen,char**s) { + short dot; + short quan; + int len; + byte vol=255; + byte inst=channels[ch].instrument; + byte fxid=channels[ch].effectid; + byte fxpar=channels[ch].effectpar; + byte volfx=channels[ch].volumeset; + byte cusfx=channels[ch].customfx; + custom_fx*cfx; + int x; + boolean contfx=0; + channels[ch].row_tie=channels[ch].row; + if(s) { + while(**s) { + if(**s=='\'') no+=octave_tones; + else if(**s=='"') no+=octave_tones*2; + else if(**s=='-') no--; + else if(**s=='+') no++; + else break; + (*s)++; + } + len=read_int(s); + if(!len) len=channels[ch].length?:1; + if(whole_note%len) fprintf(stderr,"Inexact note length (%d).\n",(int)len); + dot=len=whole_note/len; + while(**s) { + if(**s=='.') len+=(dot/=2); + else break; + (*s)++; + } + if(**s=='*') { + (*s)++; vol=read_int(s); + } + } + if(!dot) fprintf(stderr,"Inexact note length.\n"); + if(channels[ch].quantize>0) { + len-=quan=(len*channels[ch].quantize)/gate_denom; + } else { + len-=quan=-channels[ch].quantize; + } + len+=prelen; + if(len<1) { + len=1; + quan=0; + fprintf(stderr,"Quantize results in too short note.\n"); + } + if(channels[ch].keytable!=255) { + x=channels[ch].keytable; + inst=keytab[x][no].instrument==255?inst:keytab[x][no].instrument; + fxid=keytab[x][no].effectid?:fxid; + fxpar=keytab[x][no].effectid?keytab[x][no].effectpar:fxpar; + volfx=keytab[x][no].volumeset==255?volfx:keytab[x][no].volumeset; + cusfx=keytab[x][no].customfx==255?cusfx:keytab[x][no].customfx; + no=keytab[x][no].note; + } + if(volfx!=255 && vol!=255 && vol!=volfx) fprintf(stderr,"Conflicting volume effects during note.\n"); + volfx=vol; + cfx=cusfx==255?0:fxtab+cusfx; + if(cfx && no<200) { + while(cfx && (len || contfx)) { + contfx=!!(cfx->continue_flag&0x80); + if(cfx->transpose<200) no+=cfx->transpose; + if(no<0 || no>119) { + no=0; fprintf(stderr,"Custom effect table causes note out of range error.\n"); + } + x=cfx->delta; + if(x>len && !contfx) x=len; + send_channel(ch,cfx->transpose>=200?cfx->transpose:no,(cfx->instrument==255 && cfx->transpose<200255)?inst:cfx->instrument, + cfx->effectid,cfx->effectpar,cfx->volumeset,cfx->continue_flag,x); + cfx=cfx->next; + len-=x; + } + channels[ch].row+=len; + } else { + send_channel(ch,no,inst,fxid,fxpar,volfx,1,len); + } + //todo: auto portamento + channels[ch].row_cut=channels[ch].row; + if(quan) send_channel(channels[ch].note_cut,no,inst,255,0,volfx,0,quan); + channels[ch].auto_portamento=0; +} + +void process_channel(byte ch,char*s) { + char c; + char*t; + int x; + char*loop=0; + int loopc=0; + skip_spaces(&s); + while(*s) { + switch(c=*s++) { + + case 'a' ... 'j': // Notes + send_note(ch,channels[ch].transpose+(channels[ch].octave+(c='0' && c<='9')) { + //todo (entry point by order number) + } else { + fprintf(stderr,"Unknown command in channel %c: :%c\n", ch+'A', c); + } + break; + + case '@': // Set instrument or key table or quantize or other channel or etc + if(*s=='{' || *s=='}') { + s++; // for use with text macros + } else if(*s=='=') { + s++; x=(*s++&0x1F)%27; numeric_register[x]=read_int(&s); + } else if(*s=='+') { + s++; x=(*s++&0x1F)%27; numeric_register[x]+=read_int(&s); + } else if(*s=='-') { + s++; x=(*s++&0x1F)%27; numeric_register[x]-=read_int(&s); + } else if(*s=='*') { + s++; x=(*s++&0x1F)%27; numeric_register[x]*=read_int(&s); + } else if(*s=='q') { + s++; channels[ch].quantize=-read_int(&s); + } else if(*s=='e') { + s++; channels[ch].effectid=read_int(&s); channels[ch].effectpar=read_int(&s); channels[ch].volumeset=read_int(&s); + } else if(*s>='A' && *s<='P') { + ch=*s++-'A'; + } else if((*s>='0' && *s<='9') || *s=='$') { + channels[ch].instrument=read_int(&s); channels[ch].keytable=255; + if(channels[ch].instrument>max_instrument) fprintf(stderr,"Unuse instrument %d.\n",channels[ch].instrument); + } else if(*s=='@') { + t=++s; x=read_int(&s); channels[ch].keytable=(t==s)?255:x; + } else if(*s=='u') { + t=++s; x=read_int(&s); channels[ch].customfx=(t==s)?255:x; + } else if(*s=='`') { + *numeric_register=at_backtick(ch,loopc,*++s); + } else { + fprintf(stderr,"Unknown command in channel %c: @%c\n", ch+'A', *s++); + } + break; + + case 'o': // Octave set + channels[ch].octave=read_int(&s); + if(channels[ch].octave>9) fprintf(stderr,"Abnormal octave number (o).\n"); + break; + + case '<': // Low octave + channels[ch].octave-=octave_dir; + if(channels[ch].octave>9) fprintf(stderr,"Abnormal octave number (<).\n"); + break; + + case '>': // High octave + channels[ch].octave+=octave_dir; + if(channels[ch].octave>9) fprintf(stderr,"Abnormal octave number (>).\n"); + break; + + case 'l': // Length + channels[ch].length=read_int(&s); + if(channels[ch].length<=0 || whole_note%channels[ch].length) + fprintf(stderr,"Abnormal note length (%d/%d).\n",whole_note,channels[ch].length); + break; + + case 'K': // Transpose + channels[ch].transpose=read_int(&s); + break; + + case 'v': // Volume + send_channel(ch,200,FX('M'),read_int(&s),0,255,0,0); + break; + + case 'G': // Global volume + send_global(channels[ch].row,FX('V'),read_int(&s),255,0,1); + break; + + case 'X': // Call macro + x=read_int(&s); skip_spaces(&s); + if(x&~0xFF) { + fprintf(stderr,"Wrong macro number (%d).\n",x); + break; + } + if(*s) { + process_channel(ch,macro_text[x][ch]); + } else { + s=macro_text[x][ch]; // tail recursive + } + break; + + case 'C': // Set note cuts + x=*s++; + if(x=='o') channels[ch].note_cuts=255; + else if(x=='c') channels[ch].note_cuts=254; + else if(x=='f') channels[ch].note_cuts=253; + else fprintf(stderr,"Unknown command in channel %c: C%c\n",ch+'A',x); + break; + + case 'q': // Set quantize + channels[ch].quantize=read_int(&s); + break; + + case 't': // Set tempo + send_global(channels[ch].row,FX('T'),read_int(&s),255,0,1); + break; + + case '[': // Repeat begin + if(loop) fprintf(stderr,"Prohibit nesting repeats.\n"); + loop=s; + loopc=0; + break; + + case ']': // Repeat end + if(!loop) { + fprintf(stderr,"*FATAL* Repeat block ends without starting.\n"); + exit(1); + } + if((x=read_int(&s))<0) fprintf(stderr,"Abnormal repeat count.\n"); + if(x==++loopc) loop=0; else s=loop; + break; + + case 'I': // Tremor + channels[ch].effectid=FX('I'); + channels[ch].effectpar=read_int(&s)<<4; + channels[ch].effectpar|=read_int(&s); + break; + + case 'J': // Arpeggio + channels[ch].effectid=FX('J'); + channels[ch].effectpar=read_int(&s)<<4; + channels[ch].effectpar|=read_int(&s); + break; + + case 'T': // Tremolo + channels[ch].effectid=FX('R'); + channels[ch].effectpar=read_int(&s)<<4; + channels[ch].effectpar|=read_int(&s); + break; + + case 'P': // Panning (volume column) + channels[ch].volumeset=read_int(&s)|128; + break; + + case 'Q': // Retrigger + channels[ch].effectid=FX('Q'); + channels[ch].effectpar=read_int(&s)<<4; + channels[ch].effectpar|=read_int(&s); + break; + + case 'V': // Vibrato + x=read_int(&s); + if(x<1 || x>15) fprintf(stderr,"Abnormal vibrato speed.\n"); + channels[ch].effectpar=x<<4; + x=read_int(&s); + if(x>0 && x<16) { + channels[ch].effectid=FX('U'); + channels[ch].effectpar|=x; + } else if(x>0 && x<=60 && !(x&3)) { + channels[ch].effectid=FX('H'); + channels[ch].effectpar|=x>>2; + } else { + fprintf(stderr,"Abnormal vibrato depth.\n"); + } + break; + + case 'Y': // Panbrello + channels[ch].effectid=FX('Y'); + channels[ch].effectpar=read_int(&s)<<4; + channels[ch].effectpar|=read_int(&s); + break; + + case 'R': // Portamento + x=read_int(&s); + if(x<-0xDF || !x || x>0xDF) { + fprintf(stderr,"Abnormal portamento rate.\n"); + } else if(x>0) { + channels[ch].effectid=FX('F'); + channels[ch].effectpar=x; + } else { + channels[ch].effectid=FX('E'); + channels[ch].effectpar=-x; + } + break; + + case 'z': // Cancel effects + channels[ch].effectid=0; + channels[ch].volumeset=255; + break; + + default: + fprintf(stderr,"Unknown command in channel %c: %c\n", ch+'A', c); + } + skip_spaces(&s); + } + if(loop) fprintf(stderr,"Repeat block not ended (repeat is ignored).\n"); +} + +void process_line(char*s) { + char*t; + switch(*s) { + case 0: case ';': break; + case '"': + *next_song_message=malloc(sizeof(message_line)); + (*next_song_message)->data=strdup(s+1); + (*next_song_message)->next=0; + next_song_message=&((*next_song_message)->next); + song_message_length+=strlen(s); // Includes the '"' which is the same length as newline marker + if(song_message_length>8000) fprintf(stderr,"Overlong song message.\n"); + break; + case '#': hash_directive(s+1); break; + case '@': at_definition(s+1); break; + case 'A' ... 'P': + for(t=s;0x40&*t;t++); + while(*s>='A' && *s<='P') process_channel(*s++-'A',t); + break; + default: + fprintf(stderr,"Illegal character at start of line: %c\n", *s); + } +} + +void read_file(FILE*fp) { + char buf[4096]; + int bp=0; // buffer mark + int ns=0; // not space + int c; + boolean bl=1; // 0 to block of multi lines + boolean com=1; // 0 to comment out + *buf=0; + while(!feof(fp)) { + if((c=fgetc(fp))==EOF) break; + + if(com) { + if(c>' ') ns=bp+1; + if(c>' ' || bp) { + buf[bp++]=c>' '?c:' '; + if(bp>=4096) { + fprintf(stderr,"*FATAL* Overlong line of input.\n"); + exit(1); + } + } + if(bp) buf[bp-1]*=(com=(*buf<36 || c!=';')); // cut off comment + if(*buf=='@') { + if(c=='{') bl=0; + if(c=='}') bl=1; + } + } + + if(c=='\r' || c=='\n') { + com=1; + if(bl && bp) { + buf[ns]=0; + if(trace_input) fprintf(stderr,"+ %s\n",buf); + process_line(buf); + bp=ns=0; + } + } + + } + if(trace_input) fprintf(stderr,"\n"); +} + +void make_defaults(void) { + int x,y; + for(x=1;x<100;x++) { + // Sample + samples[x].global_volume=64; + samples[x].flag=0x00; + samples[x].default_volume=64; + samples[x].convert=0x00; + samples[x].pan=64; + samples[x].length=samples[x].loop_start=samples[x].loop_end=0; + samples[x].c5speed=8363; + samples[x].sustain_start=samples[x].sustain_end=0; + samples[x].make=0; + samples[x].name=0; + samples[x].used=0; + // Instrument + for(y=0;y<11;y++) instruments[x].heading[y]=0; + instruments[x].heading[6]=60; + instruments[x].heading[7]=0x40; + instruments[x].heading[8]=0xA0; + instruments[x].ifc=instruments[x].ifr=0; + for(y=0;y<120;y++) { + instruments[x].keyboard[y<<1]=y; + instruments[x].keyboard[1|(y<<1)]=0; + } + instruments[x].used=0; + instruments[x].vol_env[0]=instruments[x].vol_env[1]=0; + instruments[x].pan_env[0]=instruments[x].pan_env[1]=0; + instruments[x].pitch_env[0]=instruments[x].pitch_env[1]=0; + } + for(x=0;x<64;x++) { + // Key table + for(y=0;y<120;y++) { + keytab[x][y].note=y; + keytab[x][y].effectid=0; + keytab[x][y].instrument=keytab[x][y].volumeset=keytab[x][y].customfx=255; + } + // Effect table + fxtab[x].transpose=0; + fxtab[x].instrument=255; + fxtab[x].effectid=0; + fxtab[x].volumeset=255; + fxtab[x].continue_flag=0; + fxtab[x].delta=0; + fxtab[x].next=0; + } + for(x=0;x<16;x++) { + // Channel + channels[x].transpose=0; + channels[x].octave=5; + channels[x].length=4; + channels[x].instrument=1; + channels[x].effectid=0; + channels[x].volumeset=255; + channels[x].quantize=0; + channels[x].note_cuts=255; + channels[x].ch_vol=64; + channels[x].ch_pan=32; + channels[x].row=channels[x].row_cut=channels[x].row_tie=0; + channels[x].loopstart=channels[x].loopskip=channels[x].loopend=-1; + channels[x].keytable=255; + channels[x].customfx=255; + channels[x].auto_portamento=0; + channels[x].prev_note=254; + } +} + +byte*synthesizer_a(byte n) { + char*cmd=samples[n].name+1; + int per=lround(((double)samples[n].c5speed)/C_pitch); // period (before multiply) + int len=lround(((double)(samples[n].c5speed*synth_len_mult))/C_pitch); + double*dbl; + byte*buf; + int x,z1,z2,z3; + double q,r; + double amp=1.0; + + // Amplitude/length + x=read_int(&cmd)?:1000; amp=0.001*(double)x; + len*=read_int(&cmd)?:1; + dbl=malloc(len*sizeof(double)); + buf=malloc(len<0x7FFF) z1=0x7FFF; + buf[x<<1]=z1; + buf[1|(x<<1)]=z1>>8; + } + } else { + for(x=0;x255) z1=255; + if(z1<0) z1=0; + buf[x]=z1; + } + } + free(dbl); + return buf; +} + +byte*synthesizer_b(byte n) { + char*cmd=samples[n].name+1; + byte*buf=malloc(0x5000); // limit=0x4000 + int len=0; + int loops[16]; + int slows[16]; + int loopnest=0; + int slow=1; + int x,y,z; + + // Read commands and make buffer + while(*cmd) { + skip_spaces(&cmd); + if(*cmd=='[') cmd++; + if(!*cmd) break; + if(*cmd=='|') { + // loop point + cmd++; + samples[n].flag|=0x10; + samples[n].loop_start=len; + } else if(*cmd=='(' || *cmd=='$' || (*cmd>='0' && *cmd<='9') || *cmd=='-' || *cmd=='+') { + x=read_int(&cmd); + if(*cmd=='(') { + if(loopnest==15) { + fprintf(stderr,"*FATAL* Too many nested repeats in sample %d.\n",n); + exit(1); + } + loops[loopnest]=len>>synth16bits; + slows[loopnest++]=slow; + slow*=x?:1; + } else { + y=slow; + while(y--) { + buf[len++]=x; + if(synth16bits) buf[len++]=x>>8; + } + } + } else if(*cmd==')') { + cmd++; + if(loopnest) { + x=read_int(&cmd)?:1; + z=len; + --loopnest; + while(x--) { + y=loops[loopnest]; + while(y' ') { + cmd++; + fprintf(stderr,"Improper synthesizer for sample %d.\n",n); + } + if(len>=0x3FFF) { + fprintf(stderr,"*FATAL* Overlong sample %d.\n",n); + exit(1); + } + } + + // Send buffer + samples[n].convert=0x00; + samples[n].length=samples[n].loop_end=len>>synth16bits; + if(synth16bits) { + samples[n].flag|=0x02; + samples[n].convert|=0x01; + } + return buf; +} + +void do_export_sample(void) { + sample_data*sam=samples+export_sample; + byte*buf; + int x; + if(export_sample<=max_sample && sam->make==2) { + if(sam->name[0]=='a') buf=synthesizer_a(export_sample); + if(sam->name[0]=='b') buf=synthesizer_b(export_sample); + fwrite(buf,1,sam->length< song.it} + +There are command-line parameters which can be activated as follows: + +{\tt-c}\quad Set compatibility setting. Give it an argument which is the +number for the compatibility setting. Compatibility setting is described +later in this document. + +{\tt-e}\quad Export raw sample data to standard output. The parameter will +be the number of the sample to export. This can only be used with +synthesized samples and cannot be used with external samples. The normal +output is suppressed when this mode is used. + +{\tt-p}\quad Set prefix for external samples. When loading an external +file, the text here will be given as a prefix for the filename when +accessing the external files. It is necessary to include the trailing +slash if it is the name of a directory. + +{\tt-t}\quad Trace input. No parameter is used. This will display each +line of input on standard error when it is being processed, including the +preprocessing, and errors for that line will appear with that line so that +you can debug the input file. + +{\tt-v}\quad Version number. No parameter is used. No input is requested +and the standard output will include the version number of ITMCK. + +{\tt-x}\quad Volume 0 mix optimization. No parameter is used. This command +will activate the ``volume 0 mix optimization'' flag in the output file. + +\headII: License + +ITMCK is licensed under GNU GPL v3 or later version. This document is +licensed under public domain. A copy of the GNU GPL v3 should have been +made available in a file named {\tt COPYING} in the same media that you +received the program with. + +\headI: Syntax + +\headII: Comments + +\headII: Musical Notes + +\headII: Numbers + +There are three ways to write numbers in ITMCK wherever they are expected. + +If multiple parameters are expected, you cannot normally separate numbers +by spaces. However, you can use commas if it would be ambiguous to put +them directly next to each other. + +\headIII: Decimal + +Write a decimal number optionally prefixed by a minus sign or plus sign. +(If the number is omitted, it is treated as zero.) + +Example: {\tt42} + +\headIII: Hexadecimal + +Hexadecimal numbers are prefixed by a dollar sign, and the letters must +be written in uppercase. + +Example: {\tt\$2A03} + +\headIII: Variables + +To use the value of a variable where a number is expected, use the +variable letter in lowercase after a dollar sign. There are 27 variables, +labeled {\tt\$a} to {\tt\$z} and the backquote variable {\tt\$`} (use of +the backquote variable is explained later). + +Example: {\tt\$x} + +\headI: Hash Directives + +\headII: \TT\#AMIGA-SLIDES + +\headII: \TT\#CHANNEL + +\headII: \TT\#COMPATIBILITY + +Set compatibility setting (same as {\tt-c} switch). Currently the only +valid setting is zero which has no effect. + +\headII: \TT\#GATE-DENOM + +\headII: \TT\#INCLUDE + +Specify a filename. It include a file with that name from the same +directory as another input file, which will be processed before continuing +with the current input file. + +\headII: \TT\#LINEAR-SLIDES + +\headII: \TT\#MINIMUM-VERSION + +Check the version of ITMCK. This number must be hex number of form +{\tt\$xyz} corresponding to version x.y.z of ITMCK. It is a fatal error if +the current version of ITMCK is less than the value given on this line. + +\headII: \TT\#MIXER + +Set master volume, which must range from 1 to 128. Default setting is 48. + +\headII: \TT\#MONO + +Select mono audio. + +\headII: \TT\#OCTAVE-REV + +Specify a number 0 or 1. If you specify 0 (default) then {\tt>} means high +octave and {\tt<} means low octave. If you specify 1 then {\tt<} means +high octave and {\tt>} means low octave. + +\headII: \TT\#OLD-EFFECTS + +\headII: \TT\#PANNING-SEPARATION + +\headII: \TT\#PORTAMENTO-SHARE + +\headII: \TT\#SCALE + +This command is used to customize the scale of notes. You can use the +letters {\tt a} to {\tt j} up to once each (although you need not use all +of them, and they need not be in order). Use full stops to indicate no +letters for that position (they can still be accessed by sharp/flat). +However many letter and dot is the number of tones per octave. You can +include a vertical bar to indicate what will be zero of scale (points +before that one are negative). + +The default setting is: {\tt a.b|c.d.ef.g.} (including full stop at end) + +As an example, the default setting means that there are twelve notes per +octave (don't count the vertical bar), {\tt a} has value $-3$, {\tt b} has +value $-1$, {\tt c} has value $0$, {\tt g} has value $7$, and so on. This +corresponds to the standard keys on a piano. + +You cannot comment anything out on this line. + +N.B.: If you change the scale other than twelve, you must affect the key +tables to reflect this!! + +\headII: \TT\#SCALE-BASE + +Allows to define which letter should be considered the lowest note of the +octave. The default value is `{\tt c}'. If you set it to `{\tt a}', then +entering `{\tt a}' where a note is expected will use the A note below C +instead of the A note above C. + +\headII: \TT\#STEREO + +Select stereo audio (default). + +\headII: \TT\#SYNTH-LENGTH + +\headII: \TT\#SYNTH16 + +If this command is activated, it causes raw samples that are imported and +any samples which are internally synthesized to use 16-bits, which can +result higher quality audio but larger file. + +\headII: \TT\#TEMPO + +Define initial tempo of song, in beats per minute, which must range from +32 to 255. The default value is 120. + +\headII: \TT\#TITLE + +Set the song title, which will probably be displayed in a program that +plays this music. There is a maximum of 25 ASCII characters. You cannot +comment anything out on this line. + +\headII: \TT\#TRACKER-VERSION + +Allows you to change the value of ``Cwt'' field in the header of output. +By default it uses the hexadecimal number {\tt\$7xyz} for ITMCK version +x.y.z although you can change it to pretend to be a different program or +a different version. + +\headII: \TT\#VOL0MIXOPT + +This has the same effect as the {\tt-v} command-line switch. + +\headII: \TT\#VOLUME + +Set initial global volume, which must range from 0 to 128. Default setting +is 128. + +\headII: \TT\#WHOLE-NOTE + +Set the number of frames of a whole note, which must be greater than zero. +The default is 48 frames. + +\headI: Channels + +There are up to sixteen channels, labeled with the uppercase letters +{\tt A} to {\tt P}. Each channel plays notes individually and can have its +own settings for volume, panning, note length, transpose, special effects, +etc. + +To define initial channel volume and panning, you can use the +{\tt\#CHANNEL} command or you may use a macro definition as follows: + +{\tt@A = 30 40} + +In this example, the channel being assigned is {\tt A} and the volume is +30 and the panning is 40. The volume ranges from 0 to 64. The panning +ranges from 0 to 64 (where 32 is centered), or enter 100 for surround +sound. + +\headI: Song Message + +A song message consists of any number of lines starting with {\tt"} and +followed by the text to place on that line. The text can include any ASCII +text, including semicolons and leading spaces. All of them are then put +together in the song message. This song message may be displayed in the +player. (Do not include another quotation mark at the end unless you want +it a part of the message.) + +You cannot comment anything out on this line. + +The song message should not exceed 8000 characters (counting line breaks +as one character each). + +\headI: Samples + +\headII: Synthesizer + +\headI: Instruments + +\headI: Music Entry + +\headII: {\TT a}--{\TT j} (note letters) + +\headII: {\TT l} (length) + +\headII: {\TT n} (direct note entry) + +\headII: {\TT o} (select octave) + +\headII: {\TT q} (quantize) + +\headII: {\TT r} (rest) + +\headII: {\TT t} (tempo) + +\headII: {\TT v} (volume) + +\headII: {\TT z} (cancel effects) + +\headII: {\TT C} (set note cuts) + +\headII: {\TT G} (global volume) + +\headII: {\TT I} (tremor) + +\headII: {\TT J} (arpeggio) + +\headII: {\TT K} (transpose) + +\headII: {\TT L} {\TT||} {\TT|L} (song loop) + +\headII: {\TT P} (panning) + +\headII: {\TT Q} (retrigger) + +\headII: {\TT R} (portamento) + +\headII: {\TT T} (tremolo) + +\headII: {\TT V} (vibrato) + +\headII: {\TT X} (call macro) + +\headII: {\TT Y} (panbrello) + +\headII: {\TT[} {\TT]} (repeat) + +\headII: {\TT<} {\TT>} (low octave/high octave) + +\headII: {\TT\&} (slur) + +\headII: {\TT\char`^} (tie) + +\headII: {\TT/} (auto-portamento) + +\headII: {\TT@} (instrument select) + +\headII: {\TT@@} (key table select) + +\headII: {\TT@e} (direct effect entry) + +\headII: {\TT@q} (quantize) + +\headII: {\TT@u} (effect table select) + +\headII: {\TT@A}--{\TT@P} (channel select) + +\headII: {\TT@`} (ask status) + +\headII: {\TT@=} {\TT@+} {\TT@-} {\TT@*} (assign variable) + +\headI: Macros + +\headI: Key Tables + +\headI: Effect Tables + +% === End main document text === + +\let\TT=\tentt +\let\Tt=\tentt + +\vfill\eject +\immediate\closeout\tocfile + +\headline={} +\footline={} + +\def\dotleaders{\leaders\hbox{ . }\hfill} +\def\tocI#1#2{\line{#1 \dotleaders\ #2}} +\def\tocII#1#2{\line{\quad#1\rm\ \dotleaders\ #2}} +\def\tocIII#1#2{\line{\qquad#1\ \dotleaders\ #2}} + +\vfill +\line{\headIfont Table of Contents\hfil} +\bigskip +\input\jobname.toc +\vfill + +\bye diff --git a/vcslist b/vcslist new file mode 100755 index 0000000..8288605 --- /dev/null +++ b/vcslist @@ -0,0 +1,6 @@ +.gitattributes +COPYING +compile +itmck.c +itmck_manual.tex +vcslist -- 2.11.4.GIT