├── .gitignore ├── GPL.txt ├── LICENSE.md ├── Mapping.md ├── Midi_In_YM2151 ├── CCHandler.cpp ├── CCHandler.h ├── Common.h ├── EPROMManager.cpp ├── EPROMManager.h ├── Midi_In_YM2151.ino ├── Midi_In_YM2151.sln ├── Midi_In_YM2151.vcxproj ├── Midi_In_YM2151.vcxproj.filters ├── Midi_In_YM2151.vcxproj.user ├── NotePool.cpp ├── NotePool.h ├── PCHandler.cpp ├── PCHandler.h ├── SysExHandler.cpp ├── SysExHandler.h ├── YM2151.cpp ├── YM2151.h ├── YM2151Driver.cpp ├── YM2151Driver.h └── keywords.txt └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files 2 | *.slo 3 | *.lo 4 | *.o 5 | *.obj 6 | 7 | # Precompiled Headers 8 | *.gch 9 | *.pch 10 | 11 | # Compiled Dynamic libraries 12 | *.so 13 | *.dylib 14 | *.dll 15 | 16 | # Fortran module files 17 | *.mod 18 | *.smod 19 | 20 | # Compiled Static libraries 21 | *.lai 22 | *.la 23 | *.a 24 | *.lib 25 | 26 | # Executables 27 | *.exe 28 | *.out 29 | *.app 30 | 31 | 32 | #some Folders Generated by VS 33 | src/x64/** 34 | src/__vm/** 35 | *.suo 36 | -------------------------------------------------------------------------------- /GPL.txt: -------------------------------------------------------------------------------- 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 | {one line to give the program's name and a brief idea of what it does.} 635 | Copyright (C) {year} {name of author} 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 | {project} Copyright (C) {year} {fullname} 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 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | 2 | YM2151 - Chip Controller Software for ARDUINO 3 | --------------------------------------------- 4 | 5 | (C) 2016 Marcel Weiß 6 | (C) 2016 Charles Hobbs 7 | 8 | This program is free software : you can redistribute it and / or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | This program is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with this program.If not, see . 20 | 21 | 22 | 23 | 24 | #### Some portions of the software (YM2151.h, YM2151.cpp) are licensed under: 25 | 26 | 27 | The MIT License 28 | 29 | Copyright (c) 2010 www.ooishoo.org 30 | 31 | Permission is hereby granted, free of charge, to any person obtaining a copy 32 | of this software and associated documentation files (the "Software"), to deal 33 | in the Software without restriction, including without limitation the rights 34 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 35 | copies of the Software, and to permit persons to whom the Software is 36 | furnished to do so, subject to the following conditions: 37 | 38 | The above copyright notice and this permission notice shall be included in 39 | all copies or substantial portions of the Software. 40 | 41 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 42 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 43 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 44 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 45 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 46 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 47 | THE SOFTWARE. 48 | -------------------------------------------------------------------------------- /Mapping.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # MIDI CC: 4 | 5 | 6 | 7 | ### OPERATOR 1: 16 - 25 8 | 9 | | Name | CC | Allowed midi channels (polyphonic mode) | Allowed midi channels (monophonic mode)| 10 | |--------------|----|------------------------------------------|----------------------------------------| 11 | |Level | 16 | 1 | 1-8 | 12 | |Mul | 17 | 1 | 1-8 | 13 | |Det1 | 18 | 1 | 1-8 | 14 | |Det2 | 19 | 1 | 1-8 | 15 | |KSR | 20 | 1 | 1-8 | 16 | |At (Rate) | 21 | 1 | 1-8 | 17 | |Dec1 (Rate) | 22 | 1 | 1-8 | 18 | |Dec1 (Level) | 23 | 1 | 1-8 | 19 | |Dec2 (Rate) | 24 | 1 | 1-8 | 20 | |Rel (Rate) | 25 | 1 | 1-8 | 21 | 22 | ### OPERATOR 2: 26 - 35 23 | 24 | | Name | CC | Allowed midi channels (polyphonic mode) | Allowed midi channels (monophonic mode)| 25 | |--------------|----|------------------------------------------|----------------------------------------| 26 | |Level | 26 | 1 | 1-8 | 27 | |Mul | 27 | 1 | 1-8 | 28 | |Det1 | 28 | 1 | 1-8 | 29 | |Det2 | 29 | 1 | 1-8 | 30 | |KSR | 30 | 1 | 1-8 | 31 | |At (Rate) | 31 | 1 | 1-8 | 32 | |Dec1 (Rate) | 32 | 1 | 1-8 | 33 | |Dec1 (Level) | 33 | 1 | 1-8 | 34 | |Dec2 (Rate) | 34 | 1 | 1-8 | 35 | |Rel (Rate) | 35 | 1 | 1-8 | 36 | 37 | 38 | ### OPERATOR 3: 36 - 45 39 | 40 | | Name | CC | Allowed midi channels (polyphonic mode) | Allowed midi channels (monophonic mode)| 41 | |--------------|----|------------------------------------------|----------------------------------------| 42 | |Level | 36 | 1 | 1-8 | 43 | |Mul | 37 | 1 | 1-8 | 44 | |Det1 | 38 | 1 | 1-8 | 45 | |Det2 | 39 | 1 | 1-8 | 46 | |KSR | 40 | 1 | 1-8 | 47 | |At (Rate) | 41 | 1 | 1-8 | 48 | |Dec1 (Rate) | 42 | 1 | 1-8 | 49 | |Dec1 (Level) | 43 | 1 | 1-8 | 50 | |Dec2 (Rate) | 44 | 1 | 1-8 | 51 | |Rel (Rate) | 45 | 1 | 1-8 | 52 | 53 | 54 | ### OPERATOR 4: 46 - 55 55 | 56 | | Name | CC | Allowed midi channels (polyphonic mode) | Allowed midi channels (monophonic mode)| 57 | |--------------|----|------------------------------------------|----------------------------------------| 58 | |Level | 46 | 1 | 1-8 | 59 | |Mul | 47 | 1 | 1-8 | 60 | |Det1 | 48 | 1 | 1-8 | 61 | |Det2 | 49 | 1 | 1-8 | 62 | |KSR | 50 | 1 | 1-8 | 63 | |At (Rate) | 51 | 1 | 1-8 | 64 | |Dec1 (Rate) | 52 | 1 | 1-8 | 65 | |Dec1 (Level) | 53 | 1 | 1-8 | 66 | |Dec2 (Rate) | 54 | 1 | 1-8 | 67 | |Rel (Rate) | 55 | 1 | 1-8 | 68 | 69 | 70 | 71 | ### COMMON: 56 - 67 72 | 73 | | Name | CC | Allowed midi channels (polyphonic mode) | Allowed midi channels (monophonic mode)| 74 | |-------------------------|----|------------------------------------------|----------------------------------------| 75 | | Op #1 - ON/OFF | 56 | 1 | 1-8 | 76 | | Op #2 - ON/OFF | 57 | 1 | 1-8 | 77 | | Op #3 - ON/OFF | 58 | 1 | 1-8 | 78 | | Op #4 - ON/OFF | 59 | 1 | 1-8 | 79 | | AMSense Op #1 - ON/OFF | 60 | 1 | 1-8 | 80 | | AMSense Op #2 - ON/OFF | 61 | 1 | 1-8 | 81 | | AMSense Op #3 - ON/OFF | 62 | 1 | 1-8 | 82 | | AMSense Op #4 - ON/OFF | 63 | 1 | 1-8 | 83 | | FB | 64 | 1 | 1-8 | 84 | | AMS | 65 | 1 | 1-8 | 85 | | PMS | 66 | 1 | 1-8 | 86 | | Algorithm | 67 | 1 | 1-8 | 87 | 88 | 89 | ### LFO 68 - 71 90 | 91 | 92 | | Name | CC | Allowed midi channels (polyphonic mode) | Allowed midi channels (monophonic mode)| 93 | |-------------------------|----|------------------------------------------|----------------------------------------| 94 | | Freq | 68 | 1 | 1 | 95 | | LFO Wave | 69 | 1 | 1 | 96 | | AMP Mod Depth | 70 | 1 | 1 | 97 | | PHASE Mod Depth | 71 | 1 | 1 | 98 | 99 | 100 | ### Noise 72-74 101 | 102 | | Name | CC | Allowed midi channels (polyphonic mode) | Allowed midi channels (monophonic mode)| 103 | |-------------------------|----|------------------------------------------|----------------------------------------| 104 | | Noise Freq | 72 | 1 | 1 | 105 | | Noise Enable | 73 | 1 | 1 | 106 | 107 | 108 | ### OTHER: 109 | 110 | | Name | CC | Allowed midi channels (polyphonic mode) | Allowed midi channels (monophonic mode)| 111 | |---------------------------------------------|----|------------------------------------------|----------------------------------------| 112 | | Volume | 7 | 1 | 1-8 | 113 | | POLY/CHANNEL Mode (0 = CHANNEL; 127 = POLY) | 74 | 1 | 1 | 114 | 115 | 116 | # MIDI SYSEX: 117 | 118 | 119 | | Name | Code (in Hex) | Value Description | 120 | |-----------------|---------------------|---------------------------------------------------------| 121 | | Master Tune | f0 4d 54 [Value] f7 | [Value] has length of 8-Bit (Max Value is 127) Master Tune = [Value] - 63 | 122 | -------------------------------------------------------------------------------- /Midi_In_YM2151/CCHandler.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * YM2151 - Chip Controller Software for ARDUINO 3 | * (C) 2016 Marcel Weiß 4 | * 5 | * This program is free software : you can redistribute it and / or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program.If not, see . 17 | */ 18 | 19 | 20 | // 21 | // Class to Handle Midi CC incomming 22 | // 23 | 24 | 25 | /* 26 | * -------------------- 27 | * MIDI CC: | 28 | * -------------------- 29 | * 30 | * 31 | * 32 | * 07 Master Volume 33 | * 34 | * 35 | * 36 | * OPERATOR 1: 16 - 25 37 | * 16 Level 38 | * 17 Mul 39 | * 18 Det1 40 | * 19 Det2 41 | * 20 KSR 42 | * 21 At (Rate) 43 | * 22 Dec1 (Rate) 44 | * 23 Dec1 (Level) 45 | * 24 Dec2 (Rate) 46 | * 25 Rel (Rate) 47 | * 48 | * OPERATOR 2: 26 - 35 49 | * 26 Level 50 | * 27 Mul 51 | * 28 Det1 52 | * 29 Det2 53 | * 30 KSR 54 | * 31 At (R) 55 | * 32 Dec1 (R) 56 | * 33 Dec1 (L) 57 | * 34 Dec2 (R) 58 | * 35 Rel (R) 59 | * 60 | * OPERATOR 3: 36 - 45 61 | * 36 Level 62 | * 37 Mul 63 | * 38 Det1 64 | * 39 Det2 65 | * 40 KSR 66 | * 41 At (R) 67 | * 42 Dec1 (R) 68 | * 43 Dec1 (L) 69 | * 44 Dec2 (R) 70 | * 45 Rel (R) 71 | * 72 | * OPERATOR 4: 46 - 55 73 | * 46 Level 74 | * 47 Mul 75 | * 48 Det1 76 | * 49 Det2 77 | * 50 KSR 78 | * 51 At (R) 79 | * 52 Dec1 (R) 80 | * 53 Dec1 (L) 81 | * 54 Dec2 (R) 82 | * 55 Rel (R) 83 | * 84 | * COMMON: 56 - 67 85 | * 56 Op #1 - ON/OFF 86 | * 57 Op #2 - ON/OFF 87 | * 58 Op #3 - ON/OFF 88 | * 59 Op #4 - ON/OFF 89 | * 60 AMSense Op #1 - ON/OFF 90 | * 61 AMSense Op #2 - ON/OFF 91 | * 62 AMSense Op #3 - ON/OFF 92 | * 63 AMSense Op #4 - ON/OFF 93 | * 64 FB 94 | * 65 AMS 95 | * 66 PMS 96 | * 67 Algorithm 97 | * 98 | * LFO 68 - 71 99 | * 68 Freq 100 | * 69 LFO Wave 101 | * 70 AMP Mod Depth 102 | * 71 PHASE Mod Depth 103 | * 104 | * Noise 72-74 105 | * 106 | * 72 Noise Freq 107 | * 73 Noise Enable 108 | * 109 | * OTHER: 110 | * 74 POLY/CHANNEL Mode (0 = CHANNEL; 127 = POLY) 111 | * 112 | * */ 113 | 114 | 115 | #include "CCHandler.h" 116 | #include "YM2151Driver.h" 117 | #include "NotePool.h" 118 | 119 | 120 | void CCHandlerClass::init() 121 | { 122 | 123 | 124 | } 125 | 126 | 127 | void CCHandlerClass::handleCC(uint8_t channel, uint8_t number, uint8_t value){ 128 | 129 | //TODO Handle Poly Mode 130 | if (number == 74){ 131 | NotePool.setMode(value == 0); 132 | } 133 | 134 | if (number < 56 && number >= 16){ 135 | if (NotePool.getMode()){ 136 | handleOp(channel & 0x07, (number - 16) / 10, (number - 16) % 10, value & 0x7f); 137 | } 138 | else{ 139 | for (byte i = 0; i < 8; i++){ 140 | handleOp(i & 0x07, (number - 16) / 10, (number - 16) % 10, value & 0x7f); 141 | } 142 | } 143 | } 144 | 145 | else if (number <= 67 && number >= 56) { 146 | if (NotePool.getMode()) { 147 | handleCommon(channel, number, value); 148 | } 149 | else { 150 | for (byte i = 0; i < 8; i++) { 151 | handleCommon(i, number, value); 152 | } 153 | } 154 | }else if (number >= 68 && number <= 71) { 155 | handleLFO(number, value); 156 | } 157 | else if (number <= 73 && number >= 72) { 158 | handleNoise(number, value); 159 | } 160 | else if (number == 7) { 161 | if (NotePool.getMode()) { 162 | YM2151Driver.setMasterVolume(channel, value); 163 | } 164 | else { 165 | for (byte i = 0; i < 8; i++) { 166 | YM2151Driver.setMasterVolume(i, value); 167 | } 168 | } 169 | } 170 | } 171 | 172 | 173 | void CCHandlerClass::handleLFO(uint8_t number , uint8_t value) { 174 | switch (number){ 175 | case 68: 176 | YM2151Driver.setLFOFreq(value); 177 | break; 178 | case 69: 179 | YM2151Driver.setWaveForm(value); 180 | break; 181 | case 70: 182 | YM2151Driver.setAmpDepth(value); 183 | 184 | break; 185 | case 71: 186 | YM2151Driver.setPhaseDepth(value); 187 | break; 188 | default: 189 | break; 190 | } 191 | } 192 | 193 | void CCHandlerClass::handleNoise(uint8_t number, uint8_t value) { 194 | switch (number) { 195 | case 72: 196 | YM2151Driver.setNoiseFreq(value); 197 | break; 198 | case 73: 199 | YM2151Driver.setNoiseEnable(value); 200 | break; 201 | default: 202 | break; 203 | } 204 | } 205 | 206 | void CCHandlerClass::handleCommon(uint8_t channel, uint8_t number, uint8_t value) { 207 | switch (number) { 208 | case 56: 209 | YM2151Driver.setOpActive(channel, 0, value); 210 | break; 211 | case 57: 212 | YM2151Driver.setOpActive(channel, 1, value); 213 | break; 214 | case 58: 215 | YM2151Driver.setOpActive(channel, 2, value); 216 | break; 217 | case 59: 218 | YM2151Driver.setOpActive(channel, 3, value); 219 | break; 220 | case 60: 221 | YM2151Driver.setAMSenseEn(channel, 0, value); 222 | break; 223 | case 61: 224 | YM2151Driver.setAMSenseEn(channel, 1, value); 225 | break; 226 | case 62: 227 | YM2151Driver.setAMSenseEn(channel, 2, value); 228 | break; 229 | case 63: 230 | YM2151Driver.setAMSenseEn(channel, 3, value); 231 | break; 232 | case 64: 233 | YM2151Driver.setFeedback(channel, value); 234 | break; 235 | case 65: 236 | YM2151Driver.setAMSense(channel, value); 237 | break; 238 | case 66: 239 | YM2151Driver.setPMSense(channel, value); 240 | break; 241 | case 67: 242 | YM2151Driver.setAlgorithm(channel, value); 243 | break; 244 | default: 245 | break; 246 | } 247 | } 248 | 249 | 250 | 251 | void CCHandlerClass::handleOp(uint8_t channel, uint8_t op, uint8_t number, uint8_t value){ 252 | //op*8+channel 253 | switch (number){ 254 | case 0: 255 | //OP Volume 256 | YM2151Driver.setOpVolume(channel, op, value); 257 | break; 258 | case 1: 259 | //mul 260 | YM2151Driver.setMul(channel, op, value); 261 | break; 262 | case 2: 263 | //Det1 264 | YM2151Driver.setDet1(channel, op, value); 265 | break; 266 | case 3: 267 | //det2 268 | YM2151Driver.setDet2(channel, op, value); 269 | break; 270 | case 4: 271 | //KSR 272 | YM2151Driver.setKSR(channel, op, value); 273 | break; 274 | case 5: 275 | //AT R 276 | YM2151Driver.setATR(channel, op, value); 277 | break; 278 | case 6: 279 | //Dec1(R) 280 | YM2151Driver.setDec1R(channel, op, value); 281 | break; 282 | case 7: 283 | //Dec1(L) 284 | YM2151Driver.setDec1L(channel, op, value); 285 | break; 286 | case 8: 287 | //Dec2(R) 288 | YM2151Driver.setDec2R(channel, op, value); 289 | break; 290 | case 9: 291 | //Rel(R) 292 | YM2151Driver.setRel(channel, op, value); 293 | break; 294 | default: break; 295 | } 296 | } 297 | 298 | 299 | CCHandlerClass CCHandler; 300 | 301 | -------------------------------------------------------------------------------- /Midi_In_YM2151/CCHandler.h: -------------------------------------------------------------------------------- 1 | /** 2 | * YM2151 - Chip Controller Software for ARDUINO 3 | * (C) 2016 Marcel Weiß 4 | * 5 | * This program is free software : you can redistribute it and / or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program.If not, see . 17 | */ 18 | 19 | #ifndef _CCHANDLER_h 20 | #define _CCHANDLER_h 21 | 22 | #if defined(ARDUINO) && ARDUINO >= 100 23 | #include 24 | #else 25 | #include "WProgram.h" 26 | #endif 27 | 28 | class CCHandlerClass 29 | { 30 | protected: 31 | 32 | 33 | 34 | 35 | public: 36 | void init(); 37 | void handleCC(uint8_t channel, uint8_t number, uint8_t value); 38 | void handleLFO(uint8_t number, uint8_t value); 39 | void handleNoise(uint8_t number, uint8_t value); 40 | void handleCommon(uint8_t channel, uint8_t number, uint8_t value); 41 | void handleOp(uint8_t channel, uint8_t op, uint8_t number, uint8_t value); 42 | }; 43 | 44 | extern CCHandlerClass CCHandler; 45 | 46 | #endif 47 | 48 | -------------------------------------------------------------------------------- /Midi_In_YM2151/Common.h: -------------------------------------------------------------------------------- 1 | /** 2 | * YM2151 - Chip Controller Software for ARDUINO 3 | * (C) 2016 Marcel Weiß 4 | * 5 | * This program is free software : you can redistribute it and / or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program.If not, see . 17 | */ 18 | 19 | #if !defined( YM_COMMON_H_INCLUDED ) 20 | #define YM_COMMON_H_INCLUDED 21 | #include "Arduino.h" 22 | 23 | #define _DEBUG 24 | 25 | #ifdef _DEBUG 26 | #define ASSERT(msg) 27 | #define PRINTH(msg,data) 28 | #else 29 | #define ASSERT(msg) 30 | #define PRINTH(msg,data) 31 | #endif 32 | 33 | #endif //YM_COMMON_H_INCLUDED 34 | -------------------------------------------------------------------------------- /Midi_In_YM2151/EPROMManager.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * YM2151 - Chip Controller Software for ARDUINO 3 | * (C) 2016 Marcel Weiß 4 | * 5 | * This program is free software : you can redistribute it and / or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program.If not, see . 17 | */ 18 | 19 | #include 20 | 21 | #include "EPROMManager.h" 22 | 23 | 24 | void EPROMManagerClass::init() 25 | { 26 | } 27 | 28 | uint8_t* EPROMManagerClass::load(uint16_t address, uint8_t length) 29 | { 30 | uint8_t* values = new uint8_t[length]; 31 | for (uint8_t i = 0; i < length; i++) { 32 | values[i] = EEPROM.read(address + i); 33 | } 34 | return values; 35 | } 36 | 37 | void EPROMManagerClass::save(uint16_t address, uint8_t values[], uint8_t length) 38 | { 39 | for (uint8_t i = 0; i < length; i++) { 40 | EEPROM.write(address + i, values[i]); 41 | } 42 | } 43 | 44 | EPROMManagerClass EPROMManager; 45 | 46 | -------------------------------------------------------------------------------- /Midi_In_YM2151/EPROMManager.h: -------------------------------------------------------------------------------- 1 | /** 2 | * YM2151 - Chip Controller Software for ARDUINO 3 | * (C) 2016 Marcel Weiß 4 | * 5 | * This program is free software : you can redistribute it and / or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program.If not, see . 17 | */ 18 | 19 | #ifndef _EPROMMANAGER_h 20 | #define _EPROMMANAGER_h 21 | 22 | #if defined(ARDUINO) && ARDUINO >= 100 23 | #include 24 | #else 25 | #include "WProgram.h" 26 | #endif 27 | 28 | 29 | 30 | class EPROMManagerClass 31 | { 32 | protected: 33 | 34 | public: 35 | void init(); 36 | uint8_t* load(uint16_t address, uint8_t length); 37 | void save(uint16_t address , uint8_t values[], uint8_t length); 38 | }; 39 | 40 | extern EPROMManagerClass EPROMManager; 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /Midi_In_YM2151/Midi_In_YM2151.ino: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * YM2151 - Chip Controller Software for ARDUINO 4 | * (C) 2016 Marcel Weiß 5 | * 6 | * This program is free software : you can redistribute it and / or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program.If not, see . 18 | */ 19 | 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | #include "YM2151Driver.h" 33 | #include "NotePool.h" 34 | #include "SysExHandler.h" 35 | #include "PCHandler.h" 36 | #include "CCHandler.h" 37 | #include "EPROMManager.h" 38 | 39 | MIDI_CREATE_INSTANCE(HardwareSerial, Serial, MIDI); //Set Midi In to RX1 on Arduino 40 | //MIDI_CREATE_DEFAULT_INSTANCE(); 41 | 42 | 43 | void setup() { 44 | 45 | 46 | YM2151.begin(); 47 | YM2151.initLFO(); 48 | MIDI.begin(MIDI_CHANNEL_OMNI); 49 | 50 | 51 | //init 52 | EPROMManager.init(); 53 | YM2151Driver.init(); 54 | NotePool.init(); 55 | CCHandler.init(); 56 | PCHandler.init(); 57 | SysExHandler.init(); 58 | 59 | //set Handlers 60 | MIDI.setHandleSystemExclusive(handle_sysex); 61 | MIDI.setHandleNoteOn(handle_NoteOn); 62 | MIDI.setHandleNoteOff(handle_NoteOff); 63 | MIDI.setHandleProgramChange(handle_PC); 64 | MIDI.setHandleControlChange(handle_CC); 65 | } 66 | 67 | void loop() { 68 | MIDI.read(); 69 | } 70 | 71 | //SysEx: 72 | void handle_sysex(uint8_t* a, unsigned sizeofsysex){ 73 | SysExHandler.handleSysEx(a, sizeofsysex); 74 | delete a; // we don't need the sysex Array anymore 75 | } 76 | 77 | void handle_CC(uint8_t channel, uint8_t number, uint8_t value){ 78 | channel = channel - 1; 79 | CCHandler.handleCC(channel, number, value); 80 | } 81 | void handle_PC(uint8_t channel, uint8_t number){ 82 | 83 | } 84 | 85 | void handle_NoteOn(uint8_t channel, uint8_t note, uint8_t value){ 86 | channel = channel - 1; 87 | NotePool.handleNote(true, channel, note, value); 88 | } 89 | 90 | void handle_NoteOff(uint8_t channel, uint8_t note, uint8_t value){ 91 | channel = channel - 1; 92 | NotePool.handleNote(false, channel, note, value); 93 | } 94 | 95 | 96 | -------------------------------------------------------------------------------- /Midi_In_YM2151/Midi_In_YM2151.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.25123.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Midi_In_YM2151", "Midi_In_YM2151.vcxproj", "{237A7084-8FB5-4567-8E00-D5A4FE362F0A}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {237A7084-8FB5-4567-8E00-D5A4FE362F0A}.Debug|x64.ActiveCfg = Debug|x64 17 | {237A7084-8FB5-4567-8E00-D5A4FE362F0A}.Debug|x64.Build.0 = Debug|x64 18 | {237A7084-8FB5-4567-8E00-D5A4FE362F0A}.Debug|x86.ActiveCfg = Release|Win32 19 | {237A7084-8FB5-4567-8E00-D5A4FE362F0A}.Release|x64.ActiveCfg = Release|x64 20 | {237A7084-8FB5-4567-8E00-D5A4FE362F0A}.Release|x64.Build.0 = Release|x64 21 | {237A7084-8FB5-4567-8E00-D5A4FE362F0A}.Release|x86.ActiveCfg = Release|Win32 22 | {237A7084-8FB5-4567-8E00-D5A4FE362F0A}.Release|x86.Build.0 = Release|Win32 23 | EndGlobalSection 24 | GlobalSection(SolutionProperties) = preSolution 25 | HideSolutionNode = FALSE 26 | EndGlobalSection 27 | EndGlobal 28 | -------------------------------------------------------------------------------- /Midi_In_YM2151/Midi_In_YM2151.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | Debug 14 | x64 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | {237A7084-8FB5-4567-8E00-D5A4FE362F0A} 23 | Midi_In_YM2151 24 | 8.1 25 | 26 | 27 | 28 | Application 29 | true 30 | v140 31 | MultiByte 32 | 33 | 34 | Application 35 | false 36 | v140 37 | true 38 | MultiByte 39 | 40 | 41 | Application 42 | true 43 | v140 44 | MultiByte 45 | 46 | 47 | Application 48 | false 49 | v140 50 | true 51 | MultiByte 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | Level3 75 | Disabled 76 | true 77 | E:\DEV\Tools\Arduino\hardware\arduino\avr\cores\arduino;E:\DEV\Tools\Arduino\hardware\arduino\avr\variants\standard;G:\Dateien\Software Projects\Arduino YM2151\Midi_In_YM2151;E:\DEV\Tools\Arduino\hardware\arduino\avr\libraries\Wire\src;E:\DEV\Tools\Arduino\hardware\arduino\avr\libraries\Wire\src\utility;E:\DEV\Tools\Arduino\libraries;E:\DEV\Tools\Arduino\hardware\arduino\avr\libraries;E:\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\02wgbdjf.cnn\Micro Platforms\default\debuggers;C:\Users\Owner\Documents\Arduino\libraries;E:\DEV\Tools\Arduino\hardware\tools\avr/avr/include/;E:\DEV\Tools\Arduino\hardware\tools\avr//avr/include/avr/;E:\DEV\Tools\Arduino\hardware\tools\avr/lib\gcc\avr\4.8.1\include;%(AdditionalIncludeDirectories) 78 | G:\Dateien\Software Projects\Arduino YM2151\Midi_In_YM2151\__vm\.Midi_In_YM2151.vsarduino.h;%(ForcedIncludeFiles) 79 | __AVR_ATmega328p__;__AVR_ATmega328P__;F_CPU=16000000L;ARDUINO=10608;ARDUINO_AVR_UNO;ARDUINO_ARCH_AVR;__cplusplus=201103L;%(PreprocessorDefinitions) 80 | 81 | 82 | 83 | 84 | Level3 85 | Disabled 86 | true 87 | C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino;C:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\standard;H:\Dateien\Software Projects\Arduino YM2151\Midi_In_YM2151;C:\Users\Marcel\Documents\Arduino\libraries\arduino_midi_library-master\src;C:\Users\Marcel\Documents\Arduino\libraries\arduino_midi_library-master\src\utility;C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\Wire\src;C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\Wire\src\utility;C:\Program Files (x86)\Arduino\libraries;C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries;E:\Visual Studio 2015\Common7\IDE\Extensions\iayiaelg.uyj\Micro Platforms\default\debuggers;C:\Users\Marcel\Documents\Arduino\libraries;C:\Program Files (x86)\Arduino\hardware\tools\avr/avr/include/;C:\Program Files (x86)\Arduino\hardware\tools\avr//avr/include/avr/;C:\Program Files (x86)\Arduino\hardware\tools\avr/lib\gcc\avr\4.8.1\include;%(AdditionalIncludeDirectories) 88 | H:\Dateien\Software Projects\Arduino YM2151\Midi_In_YM2151\__vm\.Midi_In_YM2151.vsarduino.h;%(ForcedIncludeFiles) 89 | __AVR_ATmega328p__;__AVR_ATmega328P__;F_CPU=16000000L;ARDUINO=10801;ARDUINO_AVR_UNO;ARDUINO_ARCH_AVR;__cplusplus=201103L;%(PreprocessorDefinitions) 90 | 91 | 92 | 93 | 94 | Level3 95 | Disabled 96 | true 97 | true 98 | true 99 | C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino;C:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\standard;H:\Dateien\Software Projects\Arduino YM2151\Midi_In_YM2151;C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\Wire\src;C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\Wire\src\utility;C:\Program Files (x86)\Arduino\libraries;C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries;E:\Visual Studio 2015\Common7\IDE\Extensions\iayiaelg.uyj\Micro Platforms\default\debuggers;C:\Users\Marcel\Documents\Arduino\libraries;C:\Program Files (x86)\Arduino\hardware\tools\avr/avr/include/;C:\Program Files (x86)\Arduino\hardware\tools\avr//avr/include/avr/;C:\Program Files (x86)\Arduino\hardware\tools\avr/lib\gcc\avr\4.8.1\include;%(AdditionalIncludeDirectories) 100 | 101 | 102 | true 103 | true 104 | 105 | 106 | 107 | 108 | Level3 109 | MaxSpeed 110 | true 111 | true 112 | true 113 | 114 | 115 | true 116 | true 117 | 118 | 119 | 120 | 121 | CppCode 122 | 123 | 124 | 125 | 126 | CppCode 127 | 128 | 129 | CppCode 130 | 131 | 132 | CppCode 133 | 134 | 135 | CppCode 136 | 137 | 138 | CppCode 139 | 140 | 141 | CppCode 142 | 143 | 144 | CppCode 145 | 146 | 147 | CppCode 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | -------------------------------------------------------------------------------- /Midi_In_YM2151/Midi_In_YM2151.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Quelldateien 20 | 21 | 22 | Quelldateien 23 | 24 | 25 | Quelldateien 26 | 27 | 28 | Quelldateien 29 | 30 | 31 | Quelldateien 32 | 33 | 34 | Quelldateien 35 | 36 | 37 | Quelldateien 38 | 39 | 40 | 41 | 42 | Headerdateien 43 | 44 | 45 | Headerdateien 46 | 47 | 48 | Headerdateien 49 | 50 | 51 | Headerdateien 52 | 53 | 54 | Headerdateien 55 | 56 | 57 | Headerdateien 58 | 59 | 60 | Headerdateien 61 | 62 | 63 | Headerdateien 64 | 65 | 66 | Headerdateien 67 | 68 | 69 | Headerdateien 70 | 71 | 72 | 73 | 74 | 75 | -------------------------------------------------------------------------------- /Midi_In_YM2151/Midi_In_YM2151.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /Midi_In_YM2151/NotePool.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * YM2151 - Chip Controller Software for ARDUINO 3 | * (C) 2016 Marcel Weiß 4 | * 5 | * This program is free software : you can redistribute it and / or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program.If not, see . 17 | */ 18 | 19 | #include "NotePool.h" 20 | #include "YM2151Driver.h" 21 | 22 | 23 | void NotePoolClass::init() 24 | { 25 | NotePoolClass::notes = new uint8_t[8]; 26 | for (byte i = 0; i < 8; i++){ 27 | NotePoolClass::notes[i] = 0xFF; 28 | } 29 | NotePoolClass::resetNotes(); 30 | mode = false; 31 | } 32 | 33 | 34 | void NotePoolClass::handleNote(bool on, uint8_t channel, uint8_t pitch, uint8_t velocity){ 35 | 36 | if (NotePoolClass::mode){ 37 | if (on){ 38 | NotePoolClass::notes[channel] = pitch; 39 | YM2151Driver.setTone(channel, pitch, 0); 40 | YM2151Driver.noteOff(channel); 41 | YM2151Driver.noteOn(channel); 42 | } 43 | else if (NotePoolClass::notes[channel] == pitch){ 44 | NotePoolClass::notes[channel] = 0xFF; 45 | YM2151Driver.noteOff(channel); 46 | } 47 | } 48 | else{ 49 | 50 | uint8_t ymChannel = 0xFF; 51 | if (on){ 52 | 53 | 54 | ymChannel = findNote(pitch); 55 | if (ymChannel == 0xFF){ 56 | 57 | byte ch = getFreeChannel(); 58 | if (ch == 0xFF) { 59 | long r = random(0, 7); //just use a random Channel 60 | ch = (byte)r; 61 | } 62 | 63 | notes[ch] = pitch; 64 | YM2151Driver.setTone(ch, pitch, 0); 65 | YM2151Driver.noteOff(ch); 66 | YM2151Driver.noteOn(ch); 67 | } 68 | } 69 | else{ 70 | ymChannel = findNote(pitch); 71 | if (ymChannel != 0xFF){ 72 | notes[ymChannel] = 0xFF; 73 | YM2151Driver.noteOff(ymChannel); 74 | } 75 | } 76 | } 77 | } 78 | 79 | /** 80 | * false -> Poly 81 | * true -> Channel 82 | */ 83 | void NotePoolClass::setMode(bool channel){ 84 | if (channel != mode){ 85 | mode = channel; 86 | resetNotes(); 87 | } 88 | } 89 | 90 | bool NotePoolClass::getMode(){ 91 | return mode; 92 | } 93 | 94 | 95 | void NotePoolClass::resetNotes(){ 96 | for (uint8_t i = 0; i < 8; i++){ 97 | notes[i] = 0xFF; 98 | YM2151Driver.noteOff(i); 99 | } 100 | } 101 | 102 | uint8_t NotePoolClass::findNote(uint8_t note){ 103 | for (uint8_t i = 0; i < 8; i++){ 104 | if (notes[i] == note){ 105 | return i; 106 | } 107 | } 108 | return 0xFF; 109 | } 110 | 111 | uint8_t NotePoolClass::getFreeChannel(){ 112 | for (uint8_t i = 0; i < 8; i++){ 113 | if (notes[i] == 0xFF){ 114 | return i; 115 | } 116 | } 117 | return 0xFF; 118 | } 119 | 120 | 121 | NotePoolClass NotePool; 122 | 123 | -------------------------------------------------------------------------------- /Midi_In_YM2151/NotePool.h: -------------------------------------------------------------------------------- 1 | /** 2 | * YM2151 - Chip Controller Software for ARDUINO 3 | * (C) 2016 Marcel Weiß 4 | * 5 | * This program is free software : you can redistribute it and / or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program.If not, see . 17 | */ 18 | 19 | #ifndef _NOTEPOOL_h 20 | #define _NOTEPOOL_h 21 | 22 | #if defined(ARDUINO) && ARDUINO >= 100 23 | #include 24 | #else 25 | #include "WProgram.h" 26 | #endif 27 | 28 | #include "YM2151.h" 29 | 30 | 31 | 32 | 33 | 34 | class NotePoolClass 35 | { 36 | private: 37 | uint8_t* notes; 38 | bool mode; 39 | 40 | 41 | void resetNotes(); 42 | uint8_t findNote(uint8_t note); 43 | uint8_t getFreeChannel(); 44 | 45 | public: void init(); 46 | void handleNote(bool on, uint8_t channel, uint8_t pitch, uint8_t velocity); 47 | void setMode(bool channel); 48 | bool getMode(); 49 | }; 50 | 51 | extern NotePoolClass NotePool; 52 | 53 | #endif 54 | 55 | -------------------------------------------------------------------------------- /Midi_In_YM2151/PCHandler.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * YM2151 - Chip Controller Software for ARDUINO 3 | * (C) 2016 Marcel Weiß 4 | * 5 | * This program is free software : you can redistribute it and / or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program.If not, see . 17 | */ 18 | 19 | #include "PCHandler.h" 20 | 21 | void PCHandlerClass::init() 22 | { 23 | 24 | 25 | } 26 | 27 | 28 | PCHandlerClass PCHandler; 29 | 30 | -------------------------------------------------------------------------------- /Midi_In_YM2151/PCHandler.h: -------------------------------------------------------------------------------- 1 | /** 2 | * YM2151 - Chip Controller Software for ARDUINO 3 | * (C) 2016 Marcel Weiß 4 | * 5 | * This program is free software : you can redistribute it and / or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program.If not, see . 17 | */ 18 | 19 | #ifndef _PCHANDLER_h 20 | #define _PCHANDLER_h 21 | 22 | #if defined(ARDUINO) && ARDUINO >= 100 23 | #include 24 | #else 25 | #include "WProgram.h" 26 | #endif 27 | 28 | class PCHandlerClass 29 | { 30 | protected: 31 | 32 | 33 | public: 34 | void init(); 35 | }; 36 | 37 | extern PCHandlerClass PCHandler; 38 | 39 | #endif 40 | 41 | -------------------------------------------------------------------------------- /Midi_In_YM2151/SysExHandler.cpp: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * YM2151 - Chip Controller Software for ARDUINO 4 | * (C) 2016 Marcel Weiß 5 | * 6 | * This program is free software : you can redistribute it and / or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program.If not, see . 18 | */ 19 | 20 | #include "SysExHandler.h" 21 | #include "YM2151Driver.h" 22 | 23 | 24 | void SysExHandlerClass::init() 25 | { 26 | } 27 | 28 | void SysExHandlerClass::handleSysEx(uint8_t value[], uint8_t length) { 29 | if (length > 5 || value[1] != 0x4d || value[2] != 0x54) { 30 | return; 31 | } 32 | 33 | YM2151Driver.setMasterTune(value[3]); 34 | } 35 | SysExHandlerClass SysExHandler; 36 | 37 | -------------------------------------------------------------------------------- /Midi_In_YM2151/SysExHandler.h: -------------------------------------------------------------------------------- 1 | /** 2 | * YM2151 - Chip Controller Software for ARDUINO 3 | * (C) 2016 Marcel Weiß 4 | * 5 | * This program is free software : you can redistribute it and / or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program.If not, see . 17 | */ 18 | 19 | #ifndef _SYSEXHANDLER_h 20 | #define _SYSEXHANDLER_h 21 | 22 | #if defined(ARDUINO) && ARDUINO >= 100 23 | #include 24 | #else 25 | #include "WProgram.h" 26 | #endif 27 | 28 | class SysExHandlerClass 29 | { 30 | protected: 31 | 32 | 33 | public: 34 | void init(); 35 | void handleSysEx(uint8_t values[], uint8_t length); 36 | }; 37 | 38 | extern SysExHandlerClass SysExHandler; 39 | 40 | #endif 41 | 42 | -------------------------------------------------------------------------------- /Midi_In_YM2151/YM2151.cpp: -------------------------------------------------------------------------------- 1 | 2 | 3 | /* 4 | The MIT License 5 | 6 | Copyright (c) 2010 www.ooishoo.org 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in 16 | all copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | THE SOFTWARE. 25 | */ 26 | 27 | 28 | 29 | #include 30 | #include 31 | 32 | #include "Common.h" 33 | #include "YM2151.h" 34 | 35 | #define DIRECT_IO 36 | 37 | YM2151_Class YM2151; 38 | 39 | YM2151_Class::YM2151_Class() 40 | { 41 | } 42 | void YM2151_Class::begin() 43 | { 44 | digitalWrite(P_IC, HIGH); 45 | digitalWrite(P_A0, HIGH); 46 | digitalWrite(P_WR, HIGH); 47 | digitalWrite(P_RD, HIGH); 48 | 49 | pinMode(P_A0, OUTPUT); 50 | pinMode(P_WR, OUTPUT); 51 | pinMode(P_RD, OUTPUT); 52 | pinMode(P_IC, OUTPUT); 53 | digitalWrite(P_IC, LOW); 54 | delay(100); 55 | digitalWrite(P_IC, HIGH); 56 | delay(100); 57 | return; 58 | } 59 | 60 | // 61 | #define RD_HIGH (PORTB = PORTB | 0x4) 62 | #define RD_LOW (PORTB = PORTB & ~0x4) 63 | #define WR_HIGH (PORTB = PORTB | 0x8) 64 | #define WR_LOW (PORTB = PORTB & ~0x8) 65 | #define A0_HIGH (PORTB = PORTB | 0x10) 66 | #define A0_LOW (PORTB = PORTB & ~0x10) 67 | 68 | #define BUS_READ DDRD=0x02;DDRB=0x3c; 69 | #define BUS_WRITE DDRD=0xfe;DDRB=0x3f; 70 | 71 | #ifdef DIRECT_IO 72 | 73 | static uint8_t last_write_addr=0x00; 74 | 75 | /*! 76 | \param addr 77 | \param data 78 | */ 79 | void YM2151_Class::write(uint8_t addr,uint8_t data) 80 | { 81 | uint8_t i,wi; 82 | volatile uint8_t *ddrD=&DDRD; 83 | volatile uint8_t *ddrB=&DDRB; 84 | volatile uint8_t *portD=&PORTD; 85 | volatile uint8_t *portB=&PORTB; 86 | 87 | if(last_write_addr != 0x20){ 88 | *ddrD &= ~(_BV(2) | _BV(3) | _BV(4) | _BV(5) | _BV(6) | _BV(7)); 89 | *ddrB &= ~(_BV(0) | _BV(1)); 90 | wait(8); 91 | A0_LOW; 92 | wait(4); 93 | for(i=0;i<32;i++){ 94 | RD_LOW; 95 | wait(4); 96 | if((*portB & _BV(1))==0){ // Read Status 97 | RD_HIGH; 98 | wait(4); 99 | break; 100 | } 101 | RD_HIGH; 102 | wait(8); 103 | if(i>16){ 104 | wait(4); 105 | } 106 | } 107 | } 108 | wait(4); 109 | 110 | *ddrD |= (_BV(2) | _BV(3) | _BV(4) | _BV(5) | _BV(6) | _BV(7)); 111 | *ddrB |= (_BV(0) | _BV(1)); 112 | wait(4); 113 | A0_LOW; 114 | *portD = (addr << 2) | (*portD & 0x03); 115 | *portB = (addr >> 6) | (*portB & 0xfc); 116 | wait(4); 117 | WR_LOW; // Write Address 118 | wait(4); 119 | WR_HIGH; 120 | wait(2); 121 | A0_HIGH; 122 | wait(2); 123 | *portD = (data << 2) | (*portD & 0x03); 124 | *portB = (data >> 6) | (*portB & 0xfc); 125 | 126 | wait(4); 127 | WR_LOW; // Write Data 128 | wait(4); 129 | WR_HIGH; 130 | wait(2); 131 | last_write_addr = addr; 132 | } 133 | 134 | uint8_t YM2151_Class::read() 135 | { 136 | uint8_t i,wi,data; 137 | volatile uint8_t *ddrD=&DDRD; 138 | volatile uint8_t *ddrB=&DDRB; 139 | volatile uint8_t *portD=&PORTD; 140 | volatile uint8_t *portB=&PORTB; 141 | *ddrD &= ~(_BV(2) | _BV(3) | _BV(4) | _BV(5) | _BV(6) | _BV(7)); 142 | *ddrB &= ~(_BV(0) | _BV(1)); 143 | A0_HIGH; 144 | wait(4); 145 | RD_LOW; // Read Data 146 | wait(4); 147 | data = 0; 148 | data |= (*portD)>>2; 149 | data |= (*portB)<<6; 150 | RD_HIGH; 151 | wait(4); 152 | } 153 | 154 | void YM2151_Class::delayNanoseconds(unsigned int loop) 155 | { 156 | uint8_t wi, tmp_lp; 157 | tmp_lp = loop/60; 158 | for(wi=0;wi> 6); 206 | if (offset_note < 0) offset_note = 0; 207 | if (offset_note > 0xbf) offset_note = 0xbf; 208 | 209 | YM2151.write(0x30 + ch, offset_kf << 2); 210 | YM2151.write(0x28 + ch, pgm_read_byte_near(KeyCodeTable + offset_note)); 211 | } 212 | 213 | #endif 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | -------------------------------------------------------------------------------- /Midi_In_YM2151/YM2151.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | The MIT License 4 | 5 | Copyright (c) 2010 www.ooishoo.org 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | */ 25 | 26 | 27 | 28 | #if !defined( YM2151_H_INCLUDED ) 29 | #define YM2151_H_INCLUDED 30 | #include 31 | #include 32 | 33 | class YM2151_Class{ 34 | public: 35 | YM2151_Class(); 36 | void begin(); 37 | void initLFO(); 38 | void setTone(uint8_t ch, uint8_t keycode, int16_t kf); 39 | uint8_t read(); 40 | void write(uint8_t addr,uint8_t data); 41 | 42 | private: 43 | 44 | static const uint8_t P_D0 = 2; 45 | static const uint8_t P_D1 = 3; 46 | static const uint8_t P_D2 = 4; 47 | static const uint8_t P_D3 = 5; 48 | static const uint8_t P_D4 = 6; 49 | static const uint8_t P_D5 = 7; 50 | static const uint8_t P_D6 = 8; 51 | static const uint8_t P_D7 = 9; 52 | 53 | static const uint8_t P_RD = 10; 54 | static const uint8_t P_WR = 11; 55 | static const uint8_t P_A0 = 12; 56 | static const uint8_t P_IC = 13; 57 | 58 | void wait(uint8_t loop); 59 | void delayNanoseconds(unsigned int loop); 60 | }; 61 | extern YM2151_Class YM2151; 62 | #endif //YM2151H_INCLUDED 63 | -------------------------------------------------------------------------------- /Midi_In_YM2151/YM2151Driver.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * YM2151 - Chip Controller Software for ARDUINO 3 | * (C) 2016 Marcel Weiß 4 | * (C) 2016 Charles Hobbs 5 | * 6 | * This program is free software : you can redistribute it and / or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program.If not, see . 18 | */ 19 | 20 | 21 | 22 | //TODO Use Most Significant Bits instead of LSBs for Values (Top part of byte instead of bottom part) e.g. 23 | // 24 | // ((value & 0xf) << 4 --> ((value & 0x78) << 1) 25 | // ((value & 0x3) << 6) --> ((value & 0x60) << 1) 26 | // (value & 0x0F) --> ((value & 0x78) >> 3) 27 | // 28 | // ... DONE, but needs Testing 29 | 30 | 31 | 32 | #include "YM2151Driver.h" 33 | #include "EPROMManager.h" 34 | #include 35 | 36 | void YM2151DriverClass::init() 37 | { 38 | for (byte i = 0; i < 8; i++) { 39 | YM2151Driver.MasterVolume[i] = 63; 40 | } 41 | 42 | YM2151Driver.loadInitPatch(); 43 | 44 | 45 | for (byte i = 0; i < 8; i++) { 46 | YM2151Driver.setPan(i, 0x40); 47 | } 48 | 49 | YM2151.initLFO(); 50 | setMasterTune(*EPROMManager.load(0x00, 1)); 51 | } 52 | 53 | void YM2151DriverClass::setOpVolume(uint8_t channel, uint8_t op, uint8_t value){ 54 | uint8_t adr = getAdr(channel, op); 55 | TotalLevel[adr] = (TotalLevel[adr] & 0x80) | (value & 0x7F); 56 | 57 | int16_t att, tl; 58 | tl = map(MasterVolume[channel], 0, 127, 127, -127); 59 | 60 | 61 | //see setOpActive 62 | if (op == 1) { 63 | op = 2; 64 | } 65 | else if (op == 2) { 66 | op = 1; 67 | } 68 | 69 | if (OpOn[channel] & (1 << op)) { 70 | att = TotalLevel[adr] + tl; 71 | } 72 | else { 73 | att = TotalLevel[adr]; 74 | } 75 | 76 | att = constrain(att, 0, 0x7f); 77 | 78 | YM2151.write(0x60 + adr, att); 79 | } 80 | 81 | void YM2151DriverClass::setMul(uint8_t channel, uint8_t op, uint8_t value){ 82 | uint8_t adr = getAdr(channel, op); 83 | DetPhase_Mul[adr] = (DetPhase_Mul[adr] & 0xf0) | ((value & 0x78) >> 3); 84 | YM2151.write(0x40 + adr, DetPhase_Mul[adr]); 85 | } 86 | void YM2151DriverClass::setDet1(uint8_t channel, uint8_t op, uint8_t value){ 87 | uint8_t adr = getAdr(channel, op); 88 | DetPhase_Mul[adr] = (DetPhase_Mul[adr] & 0x0f) | ((value & 0x70)); 89 | YM2151.write(0x40 + adr, DetPhase_Mul[adr]); 90 | } 91 | void YM2151DriverClass::setDet2(uint8_t channel, uint8_t op, uint8_t value){ 92 | uint8_t adr = getAdr(channel, op); 93 | EG_Decay2[adr] = (EG_Decay2[adr] & 0x3F) | ((value & 0x60) << 1); 94 | YM2151.write(0xC0 + adr, EG_Decay2[adr]); 95 | } 96 | void YM2151DriverClass::setKSR(uint8_t channel, uint8_t op, uint8_t value){ 97 | uint8_t adr = getAdr(channel, op); 98 | EG_Attack[adr] = (EG_Attack[adr] & 0x3F) | ((value & 0x60) << 1); 99 | YM2151.write(0x80 + adr, EG_Attack[adr]); 100 | } 101 | void YM2151DriverClass::setATR(uint8_t channel, uint8_t op, uint8_t value){ 102 | uint8_t adr = getAdr(channel, op); 103 | EG_Attack[adr] = (EG_Attack[adr] & 0xC0) | ((value & 0x7C) >> 2); 104 | YM2151.write(0x80 + adr, EG_Attack[adr]); 105 | } 106 | void YM2151DriverClass::setDec1R(uint8_t channel, uint8_t op, uint8_t value){ 107 | uint8_t adr = getAdr(channel, op); 108 | EG_Decay1[adr] = (EG_Decay1[adr] & 0x80) | ((value & 0x7C) >> 2); 109 | YM2151.write(0xA0 + adr, EG_Decay1[adr]); 110 | } 111 | 112 | void YM2151DriverClass::setAMSenseEn(uint8_t channel, uint8_t op, uint8_t value) { 113 | uint8_t adr = getAdr(channel, op); 114 | EG_Decay1[adr] = (EG_Decay1[adr] & 0x7F) | ((value & 0x40) << 1); 115 | YM2151.write(0xA0 + adr, EG_Decay1[adr]); 116 | } 117 | 118 | void YM2151DriverClass::setDec1L(uint8_t channel, uint8_t op, uint8_t value){ 119 | uint8_t adr = getAdr(channel, op); 120 | EGDec_RelRate[adr] = (EGDec_RelRate[adr] & 0x0f) | ((value & 0x78) << 1); 121 | YM2151.write(0xE0 + adr, EGDec_RelRate[adr]); 122 | } 123 | void YM2151DriverClass::setDec2R(uint8_t channel, uint8_t op, uint8_t value){ 124 | uint8_t adr = getAdr(channel, op); 125 | EG_Decay2[adr] = (EG_Decay2[adr] & 0xf0) | ((value & 0x78) >> 3); 126 | YM2151.write(0xC0 + adr, EG_Decay2[adr]); 127 | } 128 | void YM2151DriverClass::setRel(uint8_t channel, uint8_t op, uint8_t value){ 129 | uint8_t adr = getAdr(channel, op); 130 | //uint8_t fix = (EGDec_RelRate[adr] & 0xf0) | (value & 0x0F); 131 | EGDec_RelRate[adr] = (EGDec_RelRate[adr] & 0xf0) | ((value & 0x78) >> 3); 132 | YM2151.write(0xE0 + adr, EGDec_RelRate[adr]); 133 | } 134 | 135 | 136 | void YM2151DriverClass::setOpActive(uint8_t channel, uint8_t op, uint8_t value) { 137 | 138 | bool value2 = value >= 64; 139 | 140 | //Switch the Values because the sequence (M1,M2,C1,C2) is Wrong in Register #0x08, but right for all other Registers 141 | if (op == 1) { 142 | op = 2; 143 | }else if (op == 2) { 144 | op = 1; 145 | } 146 | 147 | if (value2) { 148 | OpOn[channel] = OpOn[channel] | (1 << op); 149 | } 150 | else { 151 | OpOn[channel] = OpOn[channel] & (~(1 << op)); 152 | } 153 | } 154 | 155 | 156 | void YM2151DriverClass::setAlgorithm(uint8_t channel, uint8_t value){ 157 | ChannelControl[channel] = (ChannelControl[channel] & 0xf8) | ((value & 0x70)>>4); 158 | YM2151.write(0x20 + channel, ChannelControl[channel]); 159 | } 160 | 161 | 162 | void YM2151DriverClass::setFeedback(uint8_t channel, uint8_t value){ 163 | ChannelControl[channel] = (ChannelControl[channel] & 0xC7) | ((value & 0x70) >> 1); 164 | YM2151.write(0x20 + channel, ChannelControl[channel]); 165 | } 166 | 167 | 168 | 169 | 170 | void YM2151DriverClass::setPMSense(uint8_t channel, uint8_t value) { 171 | PhAmp_ModSens[channel] = (PhAmp_ModSens[channel] & 0x03) | ((value & 0x70)); 172 | YM2151.write(0x38 + channel, PhAmp_ModSens[channel]); 173 | } 174 | 175 | 176 | void YM2151DriverClass::setAMSense(uint8_t channel, uint8_t value) { 177 | PhAmp_ModSens[channel] = (PhAmp_ModSens[channel] & 0x70) | ((value & 0x60) >> 5); 178 | YM2151.write(0x38 + channel, PhAmp_ModSens[channel]); 179 | } 180 | 181 | 182 | 183 | void YM2151DriverClass::setLFOFreq(uint8_t value) { 184 | LFOFreq = value << 1; 185 | YM2151.write(0x18, LFOFreq); 186 | } 187 | 188 | 189 | void YM2151DriverClass::setWaveForm(uint8_t value) { 190 | CtrlOut_WF = (CtrlOut_WF & 0xC0) | ((value & 0x60) >> 5); 191 | YM2151.write(0x1B, CtrlOut_WF); 192 | } 193 | 194 | 195 | void YM2151DriverClass::setCTRLout(uint8_t value) { 196 | CtrlOut_WF = (CtrlOut_WF & 0x03) | ((value & 0x60) << 1); 197 | YM2151.write(0x1B, CtrlOut_WF); 198 | } 199 | 200 | 201 | void YM2151DriverClass::setPhaseDepth(uint8_t value) { 202 | PhAmpMod = ((value)) | 0x80; 203 | YM2151.write(0x19, PhAmpMod); 204 | } 205 | 206 | 207 | void YM2151DriverClass::setAmpDepth(uint8_t value) { 208 | PhAmpMod = ((value)) & 0x7F; 209 | YM2151.write(0x19, PhAmpMod); 210 | } 211 | 212 | 213 | void YM2151DriverClass::setNoiseEnable(uint8_t value) { 214 | Noize = (Noize & 0x1F) | ((value>=64)<<7); 215 | YM2151.write(0x0F, Noize); 216 | } 217 | 218 | 219 | void YM2151DriverClass::setNoiseFreq(uint8_t value) { 220 | Noize = (Noize & 0x80) | ((value & 0x7C) >> 2); 221 | YM2151.write(0x0F, Noize); 222 | } 223 | 224 | 225 | void YM2151DriverClass::setPan(uint8_t channel, uint8_t value){ 226 | 227 | //rethink about that (first switches on left, then right, then both, BUT should be left,both,right or so) 228 | byte pan[] = { 0x00, 0x01, 0x03, 0x02 }; 229 | ChannelControl[channel] = (ChannelControl[channel] & 0x3F) | (pan[(value & 0x60) >> 5] << 6); 230 | YM2151.write(0x20 + channel, ChannelControl[channel]); 231 | } 232 | 233 | 234 | void YM2151DriverClass::noteOn(uint8_t channel){ 235 | YM2151.write(0x08, (OpOn[channel]<<3) | (channel & 0x7)); 236 | } 237 | 238 | 239 | void YM2151DriverClass::noteOff(uint8_t channel){ 240 | YM2151.write(0x08, 0x00 | (channel & 0x7)); 241 | } 242 | 243 | void YM2151DriverClass::setTone(uint8_t ch, uint8_t keycode, int16_t kf) 244 | { 245 | YM2151.setTone(ch, keycode, kf + (MasterTune - 63)); 246 | } 247 | 248 | void YM2151DriverClass::setMasterTune(uint8_t value) 249 | { 250 | if (value != *EPROMManager.load(0x00, 1)) { 251 | EPROMManager.save(0x00, &value, 1); 252 | } 253 | 254 | this->MasterTune = value; 255 | } 256 | 257 | void YM2151DriverClass::setMasterVolume(uint8_t channel, uint8_t value) { 258 | YM2151DriverClass::MasterVolume[channel] = value; 259 | for (uint8_t i = 0; i < 4; i++) { 260 | uint8_t adr = getAdr(channel, i); 261 | setOpVolume(channel, i, YM2151DriverClass::TotalLevel[adr]); 262 | } 263 | 264 | } 265 | 266 | extern PROGMEM const unsigned char initPatch[]; 267 | 268 | void YM2151DriverClass::loadInitPatch() { 269 | //LFO 270 | setLFOFreq(pgm_read_byte_near(initPatch)); 271 | setAmpDepth(pgm_read_byte_near(initPatch + 1)); 272 | setPhaseDepth(pgm_read_byte_near(initPatch + 2)); 273 | setWaveForm(pgm_read_byte_near(initPatch + 3)); 274 | setNoiseFreq(pgm_read_byte_near(initPatch + 4)); 275 | setNoiseEnable(pgm_read_byte_near(initPatch + 11)); 276 | 277 | 278 | for (int i = 0; i < 8; i++) { 279 | //CH 280 | setPan(i, pgm_read_byte_near(initPatch + 5)); 281 | setFeedback(i, pgm_read_byte_near(initPatch + 6)); 282 | setAlgorithm(i, pgm_read_byte_near(initPatch + 7)); 283 | setAMSense(i, pgm_read_byte_near(initPatch + 8)); 284 | setPMSense(i, pgm_read_byte_near(initPatch + 9)); 285 | byte a = pgm_read_byte_near(initPatch + 10); 286 | setOpActive(i, 0, ((a >> 3) & 0x1) << 6); 287 | setOpActive(i, 2, ((a >> 4) & 0x1) << 6); 288 | setOpActive(i, 1, ((a >> 5) & 0x1) << 6); 289 | setOpActive(i, 3, ((a >> 6) & 0x1) << 6); 290 | 291 | //OPs 292 | for (int a = 0; a < 4; a++) { 293 | setATR(i, a, pgm_read_byte_near(initPatch + 12)); 294 | setDec1R(i, a, pgm_read_byte_near(initPatch + 13)); 295 | setDec2R(i, a, pgm_read_byte_near(initPatch + 14)); 296 | setRel(i, a, pgm_read_byte_near(initPatch + 15)); 297 | setDec1L(i, a, pgm_read_byte_near(initPatch + 16)); 298 | setOpVolume(i, a, pgm_read_byte_near(initPatch + 17)); 299 | setKSR(i, a, pgm_read_byte_near(initPatch + 18)); 300 | setMul(i, a, pgm_read_byte_near(initPatch + 19)); 301 | setDet1(i, a, pgm_read_byte_near(initPatch + 20)); 302 | setDet2(i, a, pgm_read_byte_near(initPatch + 21)); 303 | setAMSenseEn(i, a, pgm_read_byte_near(initPatch + 22)); 304 | } 305 | } 306 | } 307 | 308 | 309 | 310 | uint8_t YM2151DriverClass::getAdr(uint8_t channel, uint8_t op){ 311 | return (op * 8) + channel; 312 | } 313 | 314 | 315 | 316 | //Default Patch 317 | PROGMEM const unsigned char initPatch[] = { 318 | 0, 0, 0, 0, 0, //LFO 319 | 64, 0, 0 , 0, 0, 64 , 0, //CH 320 | 124 , 0, 0, 32 , 0 , 0 , 0, 8, 0, 0, 0, //OPs 321 | }; 322 | 323 | 324 | YM2151DriverClass YM2151Driver; 325 | 326 | -------------------------------------------------------------------------------- /Midi_In_YM2151/YM2151Driver.h: -------------------------------------------------------------------------------- 1 | /** 2 | * YM2151 - Chip Controller Software for ARDUINO 3 | * (C) 2016 Marcel Weiß 4 | * 5 | * This program is free software : you can redistribute it and / or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program.If not, see . 17 | */ 18 | 19 | #ifndef _YM2151DRIVER_h 20 | #define _YM2151DRIVER_h 21 | 22 | #if defined(ARDUINO) && ARDUINO >= 100 23 | #include 24 | #else 25 | #include "WProgram.h" 26 | #endif 27 | 28 | #include "YM2151.h" 29 | 30 | 31 | class YM2151DriverClass 32 | { 33 | 34 | private: 35 | uint8_t getAdr(uint8_t channel, uint8_t op); 36 | 37 | //CHANNELS 38 | uint8_t ChannelControl[8]; 39 | uint8_t PhAmp_ModSens[8]; 40 | uint8_t OpOn[8]; 41 | 42 | //OPS 43 | uint8_t TotalLevel[32]; 44 | uint8_t DetPhase_Mul[32]; 45 | uint8_t EG_Attack[32]; 46 | uint8_t EG_Decay1[32]; 47 | uint8_t EG_Decay2[32]; 48 | uint8_t EGDec_RelRate[32]; 49 | 50 | //LFO 51 | uint8_t Noize; 52 | uint8_t LFOFreq; 53 | uint8_t PhAmpMod; 54 | uint8_t CtrlOut_WF; 55 | 56 | uint8_t MasterTune = 63; 57 | uint8_t MasterVolume[8]; 58 | 59 | 60 | public: 61 | void init(); 62 | void setOpVolume(uint8_t channel, uint8_t op, uint8_t value); 63 | void setMul(uint8_t channel, uint8_t op, uint8_t value); 64 | void setDet1(uint8_t channel, uint8_t op, uint8_t value); 65 | void setDet2(uint8_t channel, uint8_t op, uint8_t value); 66 | void setKSR(uint8_t channel, uint8_t op, uint8_t value); 67 | void setATR(uint8_t channel, uint8_t op, uint8_t value); 68 | void setDec1R(uint8_t channel, uint8_t op, uint8_t value); 69 | void setDec1L(uint8_t channel, uint8_t op, uint8_t value); 70 | void setDec2R(uint8_t channel, uint8_t op, uint8_t value); 71 | void setRel(uint8_t channel, uint8_t op, uint8_t value); 72 | void setAMSenseEn(uint8_t channel, uint8_t op, uint8_t value); 73 | void setOpActive(uint8_t channel, uint8_t op, uint8_t value); 74 | void setAlgorithm(uint8_t channel, uint8_t value); 75 | void setFeedback(uint8_t channel, uint8_t value); 76 | void setPMSense(uint8_t channel, uint8_t value); 77 | void setAMSense(uint8_t channel, uint8_t value); 78 | void setLFOFreq(uint8_t value); 79 | void setWaveForm(uint8_t value); 80 | 81 | void setAmpDepth(uint8_t value); 82 | void setNoiseEnable(uint8_t value); 83 | void setNoiseFreq(uint8_t value); 84 | void setCTRLout(uint8_t value); 85 | void setPhaseDepth(uint8_t value); 86 | void setPan(uint8_t channel, uint8_t value); 87 | void noteOn(uint8_t channel); 88 | void noteOff(uint8_t channel); 89 | void setTone(uint8_t ch, uint8_t keycode, int16_t kf); 90 | 91 | void setMasterTune(uint8_t value); 92 | void setMasterVolume(uint8_t channel, uint8_t value); 93 | 94 | void loadInitPatch(); 95 | }; 96 | 97 | extern YM2151DriverClass YM2151Driver; 98 | 99 | #endif 100 | 101 | -------------------------------------------------------------------------------- /Midi_In_YM2151/keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Syntax Coloring Map For Test 3 | ####################################### 4 | 5 | ####################################### 6 | # Datatypes (KEYWORD1) 7 | ####################################### 8 | 9 | MIDI KEYWORD1 10 | MIDI.h KEYWORD1 11 | MidiInterface KEYWORD1 12 | DefaultSettings KEYWORD1 13 | 14 | ####################################### 15 | # Methods and Functions (KEYWORD2) 16 | ####################################### 17 | 18 | send KEYWORD2 19 | sendNoteOn KEYWORD2 20 | sendNoteOff KEYWORD2 21 | sendProgramChange KEYWORD2 22 | sendControlChange KEYWORD2 23 | sendPitchBend KEYWORD2 24 | sendPolyPressure KEYWORD2 25 | sendAfterTouch KEYWORD2 26 | sendSysEx KEYWORD2 27 | sendTimeCodeQuarterFrame KEYWORD2 28 | sendSongPosition KEYWORD2 29 | sendSongSelect KEYWORD2 30 | sendTuneRequest KEYWORD2 31 | sendRealTime KEYWORD2 32 | begin KEYWORD2 33 | read KEYWORD2 34 | getType KEYWORD2 35 | getChannel KEYWORD2 36 | getData1 KEYWORD2 37 | getData2 KEYWORD2 38 | getSysExArray KEYWORD2 39 | getFilterMode KEYWORD2 40 | getThruState KEYWORD2 41 | getInputChannel KEYWORD2 42 | check KEYWORD2 43 | delMsg KEYWORD2 44 | delSysEx KEYWORD2 45 | setInputChannel KEYWORD2 46 | setStatus KEYWORD2 47 | turnThruOn KEYWORD2 48 | turnThruOff KEYWORD2 49 | setThruFilterMode KEYWORD2 50 | disconnectCallbackFromType KEYWORD2 51 | setHandleNoteOff KEYWORD2 52 | setHandleNoteOn KEYWORD2 53 | setHandleAfterTouchPoly KEYWORD2 54 | setHandleControlChange KEYWORD2 55 | setHandleProgramChange KEYWORD2 56 | setHandleAfterTouchChannel KEYWORD2 57 | setHandlePitchBend KEYWORD2 58 | setHandleSystemExclusive KEYWORD2 59 | setHandleTimeCodeQuarterFrame KEYWORD2 60 | setHandleSongPosition KEYWORD2 61 | setHandleSongSelect KEYWORD2 62 | setHandleTuneRequest KEYWORD2 63 | setHandleClock KEYWORD2 64 | setHandleStart KEYWORD2 65 | setHandleContinue KEYWORD2 66 | setHandleStop KEYWORD2 67 | setHandleActiveSensing KEYWORD2 68 | setHandleSystemReset KEYWORD2 69 | getTypeFromStatusByte KEYWORD2 70 | encodeSysEx KEYWORD2 71 | decodeSysEx KEYWORD2 72 | 73 | 74 | ####################################### 75 | # Instances (KEYWORD2) 76 | ####################################### 77 | 78 | ####################################### 79 | # Constants (LITERAL1) 80 | ####################################### 81 | 82 | # Namespace, considering it as a literal 83 | midi LITERAL1 84 | 85 | NoteOff LITERAL1 86 | NoteOn LITERAL1 87 | AfterTouchPoly LITERAL1 88 | ControlChange LITERAL1 89 | ProgramChange LITERAL1 90 | AfterTouchChannel LITERAL1 91 | PitchBend LITERAL1 92 | SystemExclusive LITERAL1 93 | TimeCodeQuarterFrame LITERAL1 94 | SongPosition LITERAL1 95 | SongSelect LITERAL1 96 | TuneRequest LITERAL1 97 | Clock LITERAL1 98 | Start LITERAL1 99 | Stop LITERAL1 100 | Continue LITERAL1 101 | ActiveSensing LITERAL1 102 | SystemReset LITERAL1 103 | InvalidType LITERAL1 104 | Off LITERAL1 105 | Full LITERAL1 106 | SameChannel LITERAL1 107 | DifferentChannel LITERAL1 108 | MIDI_CHANNEL_OMNI LITERAL1 109 | MIDI_CHANNEL_OFF LITERAL1 110 | MIDI_CREATE_INSTANCE LITERAL1 111 | MIDI_CREATE_DEFAULT_INSTANCE LITERAL1 112 | MIDI_CREATE_CUSTOM_INSTANCE LITERAL1 113 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # YM2151-Arduino-Software 2 | Software for the ym2151-Shield for Arduino 3 | 4 | 5 | This is a Firmware to control the YM2151 Shield shown at this Website: http://www.ooishoo.org/ 6 |
You also can look at this Thread: http://chipmusic.org/forums/topic/17710/ym2151-shield-for-arduino/ for more informations about the Shield. 7 |

8 | This Firmware allows you to control the YM2151-Synthesizer Chip over Midi. This includes parameters to control the timbre of the instrument, but also to choose from either the polyphonic-mode, where notes are assigned automatically to the eight voices of the Chip or the monophonic-mode, where for each voice-channel the timbre and the notes can be controlled. 9 | 10 | 11 | #### Polyphonic-mode: 12 | The notes which are sent over midi are assigned automatically to one of the free voices of the chip. All voices have the same timbre. There can be a maximum of eight notes playing at the same time. 13 | Midi notes and control change messages have to be sent over midi channel 1. The control messages which can be sent in polyphonic-mode over midi channel one, are described in [Mapping.md](Mapping.md). 14 | 15 | 16 | #### Monophonic-mode: 17 | This mode allows you to control up to eight different monophonic voices with different timbres. 18 | The notes and control change messages which are sent over midi are assigned to the same Voice as the Midi Channel number. So sending a message over midi channel 5, only affects voice no. 5 of the YM2151 Chip. As the YM2151-Chip has eight voices, only midi channels one through eight are used. The control messages which can be sent in monophonic-mode over midi channels one through eight, are described in [Mapping.md](Mapping.md). 19 | 20 |
- See [Mapping.md](Mapping.md) for the control-messages you can send over midi to control the parameters of the chip. 21 |
- See [LICENSE.md](LICENSE.md) for the Licensing terms. 22 | 23 |
24 | 25 | ### Requirements: 26 | The Arduino Midi Library: 27 | https://github.com/FortySevenEffects/arduino_midi_library 28 | 29 |
30 | 31 | ### Controller Software 32 | To make the use of the firmware a bit easier, there is a Controller Software for PC and Mac available which allows you to control the functions of the firmware: 33 | https://github.com/masl123/YM2151-Midi-Controller 34 | --------------------------------------------------------------------------------