├── .gitignore ├── INSTALL.txt ├── LICENSE.txt ├── Makefile ├── README.md ├── TODO.txt ├── help ├── harppedal-temp.pd ├── hpp-format-o.pd ├── notes-help.pd └── notes_lib-meta.pd ├── include ├── getline.h └── notes_lib.h ├── samp ├── accordion.wav ├── flute.wav └── gong.wav └── src ├── line2score.c ├── mainscore.c ├── notes.c ├── notesLib.c └── notes_lib.c /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | *.o 3 | *.s 4 | *.pd_darwin 5 | *.pd_linux 6 | *.dll 7 | .vscode/ 8 | tests/ 9 | -------------------------------------------------------------------------------- /INSTALL.txt: -------------------------------------------------------------------------------- 1 | # about notes 2 | 3 | ############################## 4 | ## LOADING the library in Pd 5 | ############################## 6 | 7 | [notes] is a library that contains three Pd objects. To use it, you can either 1) tell Pd to load the notesLib binary file at startup via Pd's "Preferences/Startup" dialog, or 2) use the [declare] object to load notes as needed per patch. 8 | 9 | For method 1), make a new startup path in the Startup dialog, and provide the path to the notesLib binary in this directory. Note that you must not list the extension of the notesLib file (i.e., pd_linux, pd_darwin, or dll). For example: 10 | 11 | /home/yourname/Pd/externals/notes/notesLib 12 | 13 | When using Pd's Startup dialog on Windows, note that you still give the path with forward slashes, and spaces in the path are ok. There is still no need to list the library file extension of .dll. For instance: 14 | 15 | C:/Users/Your Name/Documents/Pd/externals/notes/notesLib 16 | 17 | Once you have listed the path to notesLib in the Startup dialog, you must quit and restart Pd. 18 | 19 | For method 2), assuming notes is installed to the default Externals Install Directory, you can simply use the [declare] object like this: 20 | 21 | [declare -lib notes/notesLib] 22 | 23 | If notes is loaded successfully (using either method), you will see a message in Pd's post window stating the notes version number. 24 | 25 | ############################## 26 | ## BUILDING notes from source 27 | ############################## 28 | 29 | As of notes 0.2, pd-lib-builder is used for building: 30 | 31 | 32 | 33 | Once you have installed pd-lib-builder, you must specify its location at the bottom of the Makefile in this directory (default is one directory above, ie: "../"). You will also need to specify the location of puredata at the top of the Makefile in this directory. 34 | 35 | Then, you can compile notesLib by typing "make" in this directory. 36 | 37 | ############################## 38 | ## INSTALLING LilyPond to compile PDFs directly from within Pd 39 | ############################## 40 | 41 | ## LINUX ## 42 | 43 | Install lilypond via apt-get, yum, or similar and make sure you can run it from the command line and notes will find it. 44 | 45 | ## OSX ## 46 | 47 | Install Lilypond with the regular installer from lilypond.org. Notes will use the default location in the Applications folder. If you install it elsewhere you will need to point to it from inside the patch by sending a lily_dir message to the notes object. See helpfile for further details. 48 | 49 | ## WINDOWS ## 50 | 51 | Install Lilypond with the regular installer from lilypond.org, and then follow these instructions to run it in the command line: https://lilypond.org/windows.html -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | 2 | GNU GENERAL PUBLIC LICENSE 3 | Version 3, 29 June 2007 4 | 5 | Copyright (C) 2007 Free Software Foundation, Inc. 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The GNU General Public License is a free, copyleft license for 12 | software and other kinds of works. 13 | 14 | The licenses for most software and other practical works are designed 15 | to take away your freedom to share and change the works. By contrast, 16 | the GNU General Public License is intended to guarantee your freedom to 17 | share and change all versions of a program--to make sure it remains free 18 | software for all its users. We, the Free Software Foundation, use the 19 | GNU General Public License for most of our software; it applies also to 20 | any other work released this way by its authors. You can apply it to 21 | your programs, too. 22 | 23 | When we speak of free software, we are referring to freedom, not 24 | price. Our General Public Licenses are designed to make sure that you 25 | have the freedom to distribute copies of free software (and charge for 26 | them if you wish), that you receive source code or can get it if you 27 | want it, that you can change the software or use pieces of it in new 28 | free programs, and that you know you can do these things. 29 | 30 | To protect your rights, we need to prevent others from denying you 31 | these rights or asking you to surrender the rights. Therefore, you have 32 | certain responsibilities if you distribute copies of the software, or if 33 | you modify it: responsibilities to respect the freedom of others. 34 | 35 | For example, if you distribute copies of such a program, whether 36 | gratis or for a fee, you must pass on to the recipients the same 37 | freedoms that you received. You must make sure that they, too, receive 38 | or can get the source code. And you must show them these terms so they 39 | know their rights. 40 | 41 | Developers that use the GNU GPL protect your rights with two steps: 42 | (1) assert copyright on the software, and (2) offer you this License 43 | giving you legal permission to copy, distribute and/or modify it. 44 | 45 | For the developers' and authors' protection, the GPL clearly explains 46 | that there is no warranty for this free software. For both users' and 47 | authors' sake, the GPL requires that modified versions be marked as 48 | changed, so that their problems will not be attributed erroneously to 49 | authors of previous versions. 50 | 51 | Some devices are designed to deny users access to install or run 52 | modified versions of the software inside them, although the manufacturer 53 | can do so. This is fundamentally incompatible with the aim of 54 | protecting users' freedom to change the software. The systematic 55 | pattern of such abuse occurs in the area of products for individuals to 56 | use, which is precisely where it is most unacceptable. Therefore, we 57 | have designed this version of the GPL to prohibit the practice for those 58 | products. If such problems arise substantially in other domains, we 59 | stand ready to extend this provision to those domains in future versions 60 | of the GPL, as needed to protect the freedom of users. 61 | 62 | Finally, every program is threatened constantly by software patents. 63 | States should not allow patents to restrict development and use of 64 | software on general-purpose computers, but in those that do, we wish to 65 | avoid the special danger that patents applied to a free program could 66 | make it effectively proprietary. To prevent this, the GPL assures that 67 | patents cannot be used to render the program non-free. 68 | 69 | The precise terms and conditions for copying, distribution and 70 | modification follow. 71 | 72 | TERMS AND CONDITIONS 73 | 74 | 0. Definitions. 75 | 76 | "This License" refers to version 3 of the GNU General Public License. 77 | 78 | "Copyright" also means copyright-like laws that apply to other kinds of 79 | works, such as semiconductor masks. 80 | 81 | "The Program" refers to any copyrightable work licensed under this 82 | License. Each licensee is addressed as "you". "Licensees" and 83 | "recipients" may be individuals or organizations. 84 | 85 | To "modify" a work means to copy from or adapt all or part of the work 86 | in a fashion requiring copyright permission, other than the making of an 87 | exact copy. The resulting work is called a "modified version" of the 88 | earlier work or a work "based on" the earlier work. 89 | 90 | A "covered work" means either the unmodified Program or a work based 91 | on the Program. 92 | 93 | To "propagate" a work means to do anything with it that, without 94 | permission, would make you directly or secondarily liable for 95 | infringement under applicable copyright law, except executing it on a 96 | computer or modifying a private copy. Propagation includes copying, 97 | distribution (with or without modification), making available to the 98 | public, and in some countries other activities as well. 99 | 100 | To "convey" a work means any kind of propagation that enables other 101 | parties to make or receive copies. Mere interaction with a user through 102 | a computer network, with no transfer of a copy, is not conveying. 103 | 104 | An interactive user interface displays "Appropriate Legal Notices" 105 | to the extent that it includes a convenient and prominently visible 106 | feature that (1) displays an appropriate copyright notice, and (2) 107 | tells the user that there is no warranty for the work (except to the 108 | extent that warranties are provided), that licensees may convey the 109 | work under this License, and how to view a copy of this License. If 110 | the interface presents a list of user commands or options, such as a 111 | menu, a prominent item in the list meets this criterion. 112 | 113 | 1. Source Code. 114 | 115 | The "source code" for a work means the preferred form of the work 116 | for making modifications to it. "Object code" means any non-source 117 | form of a work. 118 | 119 | A "Standard Interface" means an interface that either is an official 120 | standard defined by a recognized standards body, or, in the case of 121 | interfaces specified for a particular programming language, one that 122 | is widely used among developers working in that language. 123 | 124 | The "System Libraries" of an executable work include anything, other 125 | than the work as a whole, that (a) is included in the normal form of 126 | packaging a Major Component, but which is not part of that Major 127 | Component, and (b) serves only to enable use of the work with that 128 | Major Component, or to implement a Standard Interface for which an 129 | implementation is available to the public in source code form. A 130 | "Major Component", in this context, means a major essential component 131 | (kernel, window system, and so on) of the specific operating system 132 | (if any) on which the executable work runs, or a compiler used to 133 | produce the work, or an object code interpreter used to run it. 134 | 135 | The "Corresponding Source" for a work in object code form means all 136 | the source code needed to generate, install, and (for an executable 137 | work) run the object code and to modify the work, including scripts to 138 | control those activities. However, it does not include the work's 139 | System Libraries, or general-purpose tools or generally available free 140 | programs which are used unmodified in performing those activities but 141 | which are not part of the work. For example, Corresponding Source 142 | includes interface definition files associated with source files for 143 | the work, and the source code for shared libraries and dynamically 144 | linked subprograms that the work is specifically designed to require, 145 | such as by intimate data communication or control flow between those 146 | subprograms and other parts of the work. 147 | 148 | The Corresponding Source need not include anything that users 149 | can regenerate automatically from other parts of the Corresponding 150 | Source. 151 | 152 | The Corresponding Source for a work in source code form is that 153 | same work. 154 | 155 | 2. Basic Permissions. 156 | 157 | All rights granted under this License are granted for the term of 158 | copyright on the Program, and are irrevocable provided the stated 159 | conditions are met. This License explicitly affirms your unlimited 160 | permission to run the unmodified Program. The output from running a 161 | covered work is covered by this License only if the output, given its 162 | content, constitutes a covered work. This License acknowledges your 163 | rights of fair use or other equivalent, as provided by copyright law. 164 | 165 | You may make, run and propagate covered works that you do not 166 | convey, without conditions so long as your license otherwise remains 167 | in force. You may convey covered works to others for the sole purpose 168 | of having them make modifications exclusively for you, or provide you 169 | with facilities for running those works, provided that you comply with 170 | the terms of this License in conveying all material for which you do 171 | not control copyright. Those thus making or running the covered works 172 | for you must do so exclusively on your behalf, under your direction 173 | and control, on terms that prohibit them from making any copies of 174 | your copyrighted material outside their relationship with you. 175 | 176 | Conveying under any other circumstances is permitted solely under 177 | the conditions stated below. Sublicensing is not allowed; section 10 178 | makes it unnecessary. 179 | 180 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 181 | 182 | No covered work shall be deemed part of an effective technological 183 | measure under any applicable law fulfilling obligations under article 184 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 185 | similar laws prohibiting or restricting circumvention of such 186 | measures. 187 | 188 | When you convey a covered work, you waive any legal power to forbid 189 | circumvention of technological measures to the extent such circumvention 190 | is effected by exercising rights under this License with respect to 191 | the covered work, and you disclaim any intention to limit operation or 192 | modification of the work as a means of enforcing, against the work's 193 | users, your or third parties' legal rights to forbid circumvention of 194 | technological measures. 195 | 196 | 4. Conveying Verbatim Copies. 197 | 198 | You may convey verbatim copies of the Program's source code as you 199 | receive it, in any medium, provided that you conspicuously and 200 | appropriately publish on each copy an appropriate copyright notice; 201 | keep intact all notices stating that this License and any 202 | non-permissive terms added in accord with section 7 apply to the code; 203 | keep intact all notices of the absence of any warranty; and give all 204 | recipients a copy of this License along with the Program. 205 | 206 | You may charge any price or no price for each copy that you convey, 207 | and you may offer support or warranty protection for a fee. 208 | 209 | 5. Conveying Modified Source Versions. 210 | 211 | You may convey a work based on the Program, or the modifications to 212 | produce it from the Program, in the form of source code under the 213 | terms of section 4, provided that you also meet all of these conditions: 214 | 215 | a) The work must carry prominent notices stating that you modified 216 | it, and giving a relevant date. 217 | 218 | b) The work must carry prominent notices stating that it is 219 | released under this License and any conditions added under section 220 | 7. This requirement modifies the requirement in section 4 to 221 | "keep intact all notices". 222 | 223 | c) You must license the entire work, as a whole, under this 224 | License to anyone who comes into possession of a copy. This 225 | License will therefore apply, along with any applicable section 7 226 | additional terms, to the whole of the work, and all its parts, 227 | regardless of how they are packaged. This License gives no 228 | permission to license the work in any other way, but it does not 229 | invalidate such permission if you have separately received it. 230 | 231 | d) If the work has interactive user interfaces, each must display 232 | Appropriate Legal Notices; however, if the Program has interactive 233 | interfaces that do not display Appropriate Legal Notices, your 234 | work need not make them do so. 235 | 236 | A compilation of a covered work with other separate and independent 237 | works, which are not by their nature extensions of the covered work, 238 | and which are not combined with it such as to form a larger program, 239 | in or on a volume of a storage or distribution medium, is called an 240 | "aggregate" if the compilation and its resulting copyright are not 241 | used to limit the access or legal rights of the compilation's users 242 | beyond what the individual works permit. Inclusion of a covered work 243 | in an aggregate does not cause this License to apply to the other 244 | parts of the aggregate. 245 | 246 | 6. Conveying Non-Source Forms. 247 | 248 | You may convey a covered work in object code form under the terms 249 | of sections 4 and 5, provided that you also convey the 250 | machine-readable Corresponding Source under the terms of this License, 251 | in one of these ways: 252 | 253 | a) Convey the object code in, or embodied in, a physical product 254 | (including a physical distribution medium), accompanied by the 255 | Corresponding Source fixed on a durable physical medium 256 | customarily used for software interchange. 257 | 258 | b) Convey the object code in, or embodied in, a physical product 259 | (including a physical distribution medium), accompanied by a 260 | written offer, valid for at least three years and valid for as 261 | long as you offer spare parts or customer support for that product 262 | model, to give anyone who possesses the object code either (1) a 263 | copy of the Corresponding Source for all the software in the 264 | product that is covered by this License, on a durable physical 265 | medium customarily used for software interchange, for a price no 266 | more than your reasonable cost of physically performing this 267 | conveying of source, or (2) access to copy the 268 | Corresponding Source from a network server at no charge. 269 | 270 | c) Convey individual copies of the object code with a copy of the 271 | written offer to provide the Corresponding Source. This 272 | alternative is allowed only occasionally and noncommercially, and 273 | only if you received the object code with such an offer, in accord 274 | with subsection 6b. 275 | 276 | d) Convey the object code by offering access from a designated 277 | place (gratis or for a charge), and offer equivalent access to the 278 | Corresponding Source in the same way through the same place at no 279 | further charge. You need not require recipients to copy the 280 | Corresponding Source along with the object code. If the place to 281 | copy the object code is a network server, the Corresponding Source 282 | may be on a different server (operated by you or a third party) 283 | that supports equivalent copying facilities, provided you maintain 284 | clear directions next to the object code saying where to find the 285 | Corresponding Source. Regardless of what server hosts the 286 | Corresponding Source, you remain obligated to ensure that it is 287 | available for as long as needed to satisfy these requirements. 288 | 289 | e) Convey the object code using peer-to-peer transmission, provided 290 | you inform other peers where the object code and Corresponding 291 | Source of the work are being offered to the general public at no 292 | charge under subsection 6d. 293 | 294 | A separable portion of the object code, whose source code is excluded 295 | from the Corresponding Source as a System Library, need not be 296 | included in conveying the object code work. 297 | 298 | A "User Product" is either (1) a "consumer product", which means any 299 | tangible personal property which is normally used for personal, family, 300 | or household purposes, or (2) anything designed or sold for incorporation 301 | into a dwelling. In determining whether a product is a consumer product, 302 | doubtful cases shall be resolved in favor of coverage. For a particular 303 | product received by a particular user, "normally used" refers to a 304 | typical or common use of that class of product, regardless of the status 305 | of the particular user or of the way in which the particular user 306 | actually uses, or expects or is expected to use, the product. A product 307 | is a consumer product regardless of whether the product has substantial 308 | commercial, industrial or non-consumer uses, unless such uses represent 309 | the only significant mode of use of the product. 310 | 311 | "Installation Information" for a User Product means any methods, 312 | procedures, authorization keys, or other information required to install 313 | and execute modified versions of a covered work in that User Product from 314 | a modified version of its Corresponding Source. The information must 315 | suffice to ensure that the continued functioning of the modified object 316 | code is in no case prevented or interfered with solely because 317 | modification has been made. 318 | 319 | If you convey an object code work under this section in, or with, or 320 | specifically for use in, a User Product, and the conveying occurs as 321 | part of a transaction in which the right of possession and use of the 322 | User Product is transferred to the recipient in perpetuity or for a 323 | fixed term (regardless of how the transaction is characterized), the 324 | Corresponding Source conveyed under this section must be accompanied 325 | by the Installation Information. But this requirement does not apply 326 | if neither you nor any third party retains the ability to install 327 | modified object code on the User Product (for example, the work has 328 | been installed in ROM). 329 | 330 | The requirement to provide Installation Information does not include a 331 | requirement to continue to provide support service, warranty, or updates 332 | for a work that has been modified or installed by the recipient, or for 333 | the User Product in which it has been modified or installed. Access to a 334 | network may be denied when the modification itself materially and 335 | adversely affects the operation of the network or violates the rules and 336 | protocols for communication across the network. 337 | 338 | Corresponding Source conveyed, and Installation Information provided, 339 | in accord with this section must be in a format that is publicly 340 | documented (and with an implementation available to the public in 341 | source code form), and must require no special password or key for 342 | unpacking, reading or copying. 343 | 344 | 7. Additional Terms. 345 | 346 | "Additional permissions" are terms that supplement the terms of this 347 | License by making exceptions from one or more of its conditions. 348 | Additional permissions that are applicable to the entire Program shall 349 | be treated as though they were included in this License, to the extent 350 | that they are valid under applicable law. If additional permissions 351 | apply only to part of the Program, that part may be used separately 352 | under those permissions, but the entire Program remains governed by 353 | this License without regard to the additional permissions. 354 | 355 | When you convey a copy of a covered work, you may at your option 356 | remove any additional permissions from that copy, or from any part of 357 | it. (Additional permissions may be written to require their own 358 | removal in certain cases when you modify the work.) You may place 359 | additional permissions on material, added by you to a covered work, 360 | for which you have or can give appropriate copyright permission. 361 | 362 | Notwithstanding any other provision of this License, for material you 363 | add to a covered work, you may (if authorized by the copyright holders of 364 | that material) supplement the terms of this License with terms: 365 | 366 | a) Disclaiming warranty or limiting liability differently from the 367 | terms of sections 15 and 16 of this License; or 368 | 369 | b) Requiring preservation of specified reasonable legal notices or 370 | author attributions in that material or in the Appropriate Legal 371 | Notices displayed by works containing it; or 372 | 373 | c) Prohibiting misrepresentation of the origin of that material, or 374 | requiring that modified versions of such material be marked in 375 | reasonable ways as different from the original version; or 376 | 377 | d) Limiting the use for publicity purposes of names of licensors or 378 | authors of the material; or 379 | 380 | e) Declining to grant rights under trademark law for use of some 381 | trade names, trademarks, or service marks; or 382 | 383 | f) Requiring indemnification of licensors and authors of that 384 | material by anyone who conveys the material (or modified versions of 385 | it) with contractual assumptions of liability to the recipient, for 386 | any liability that these contractual assumptions directly impose on 387 | those licensors and authors. 388 | 389 | All other non-permissive additional terms are considered "further 390 | restrictions" within the meaning of section 10. If the Program as you 391 | received it, or any part of it, contains a notice stating that it is 392 | governed by this License along with a term that is a further 393 | restriction, you may remove that term. If a license document contains 394 | a further restriction but permits relicensing or conveying under this 395 | License, you may add to a covered work material governed by the terms 396 | of that license document, provided that the further restriction does 397 | not survive such relicensing or conveying. 398 | 399 | If you add terms to a covered work in accord with this section, you 400 | must place, in the relevant source files, a statement of the 401 | additional terms that apply to those files, or a notice indicating 402 | where to find the applicable terms. 403 | 404 | Additional terms, permissive or non-permissive, may be stated in the 405 | form of a separately written license, or stated as exceptions; 406 | the above requirements apply either way. 407 | 408 | 8. Termination. 409 | 410 | You may not propagate or modify a covered work except as expressly 411 | provided under this License. Any attempt otherwise to propagate or 412 | modify it is void, and will automatically terminate your rights under 413 | this License (including any patent licenses granted under the third 414 | paragraph of section 11). 415 | 416 | However, if you cease all violation of this License, then your 417 | license from a particular copyright holder is reinstated (a) 418 | provisionally, unless and until the copyright holder explicitly and 419 | finally terminates your license, and (b) permanently, if the copyright 420 | holder fails to notify you of the violation by some reasonable means 421 | prior to 60 days after the cessation. 422 | 423 | Moreover, your license from a particular copyright holder is 424 | reinstated permanently if the copyright holder notifies you of the 425 | violation by some reasonable means, this is the first time you have 426 | received notice of violation of this License (for any work) from that 427 | copyright holder, and you cure the violation prior to 30 days after 428 | your receipt of the notice. 429 | 430 | Termination of your rights under this section does not terminate the 431 | licenses of parties who have received copies or rights from you under 432 | this License. If your rights have been terminated and not permanently 433 | reinstated, you do not qualify to receive new licenses for the same 434 | material under section 10. 435 | 436 | 9. Acceptance Not Required for Having Copies. 437 | 438 | You are not required to accept this License in order to receive or 439 | run a copy of the Program. Ancillary propagation of a covered work 440 | occurring solely as a consequence of using peer-to-peer transmission 441 | to receive a copy likewise does not require acceptance. However, 442 | nothing other than this License grants you permission to propagate or 443 | modify any covered work. These actions infringe copyright if you do 444 | not accept this License. Therefore, by modifying or propagating a 445 | covered work, you indicate your acceptance of this License to do so. 446 | 447 | 10. Automatic Licensing of Downstream Recipients. 448 | 449 | Each time you convey a covered work, the recipient automatically 450 | receives a license from the original licensors, to run, modify and 451 | propagate that work, subject to this License. You are not responsible 452 | for enforcing compliance by third parties with this License. 453 | 454 | An "entity transaction" is a transaction transferring control of an 455 | organization, or substantially all assets of one, or subdividing an 456 | organization, or merging organizations. If propagation of a covered 457 | work results from an entity transaction, each party to that 458 | transaction who receives a copy of the work also receives whatever 459 | licenses to the work the party's predecessor in interest had or could 460 | give under the previous paragraph, plus a right to possession of the 461 | Corresponding Source of the work from the predecessor in interest, if 462 | the predecessor has it or can get it with reasonable efforts. 463 | 464 | You may not impose any further restrictions on the exercise of the 465 | rights granted or affirmed under this License. For example, you may 466 | not impose a license fee, royalty, or other charge for exercise of 467 | rights granted under this License, and you may not initiate litigation 468 | (including a cross-claim or counterclaim in a lawsuit) alleging that 469 | any patent claim is infringed by making, using, selling, offering for 470 | sale, or importing the Program or any portion of it. 471 | 472 | 11. Patents. 473 | 474 | A "contributor" is a copyright holder who authorizes use under this 475 | License of the Program or a work on which the Program is based. The 476 | work thus licensed is called the contributor's "contributor version". 477 | 478 | A contributor's "essential patent claims" are all patent claims 479 | owned or controlled by the contributor, whether already acquired or 480 | hereafter acquired, that would be infringed by some manner, permitted 481 | by this License, of making, using, or selling its contributor version, 482 | but do not include claims that would be infringed only as a 483 | consequence of further modification of the contributor version. For 484 | purposes of this definition, "control" includes the right to grant 485 | patent sublicenses in a manner consistent with the requirements of 486 | this License. 487 | 488 | Each contributor grants you a non-exclusive, worldwide, royalty-free 489 | patent license under the contributor's essential patent claims, to 490 | make, use, sell, offer for sale, import and otherwise run, modify and 491 | propagate the contents of its contributor version. 492 | 493 | In the following three paragraphs, a "patent license" is any express 494 | agreement or commitment, however denominated, not to enforce a patent 495 | (such as an express permission to practice a patent or covenant not to 496 | sue for patent infringement). To "grant" such a patent license to a 497 | party means to make such an agreement or commitment not to enforce a 498 | patent against the party. 499 | 500 | If you convey a covered work, knowingly relying on a patent license, 501 | and the Corresponding Source of the work is not available for anyone 502 | to copy, free of charge and under the terms of this License, through a 503 | publicly available network server or other readily accessible means, 504 | then you must either (1) cause the Corresponding Source to be so 505 | available, or (2) arrange to deprive yourself of the benefit of the 506 | patent license for this particular work, or (3) arrange, in a manner 507 | consistent with the requirements of this License, to extend the patent 508 | license to downstream recipients. "Knowingly relying" means you have 509 | actual knowledge that, but for the patent license, your conveying the 510 | covered work in a country, or your recipient's use of the covered work 511 | in a country, would infringe one or more identifiable patents in that 512 | country that you have reason to believe are valid. 513 | 514 | If, pursuant to or in connection with a single transaction or 515 | arrangement, you convey, or propagate by procuring conveyance of, a 516 | covered work, and grant a patent license to some of the parties 517 | receiving the covered work authorizing them to use, propagate, modify 518 | or convey a specific copy of the covered work, then the patent license 519 | you grant is automatically extended to all recipients of the covered 520 | work and works based on it. 521 | 522 | A patent license is "discriminatory" if it does not include within 523 | the scope of its coverage, prohibits the exercise of, or is 524 | conditioned on the non-exercise of one or more of the rights that are 525 | specifically granted under this License. You may not convey a covered 526 | work if you are a party to an arrangement with a third party that is 527 | in the business of distributing software, under which you make payment 528 | to the third party based on the extent of your activity of conveying 529 | the work, and under which the third party grants, to any of the 530 | parties who would receive the covered work from you, a discriminatory 531 | patent license (a) in connection with copies of the covered work 532 | conveyed by you (or copies made from those copies), or (b) primarily 533 | for and in connection with specific products or compilations that 534 | contain the covered work, unless you entered into that arrangement, 535 | or that patent license was granted, prior to 28 March 2007. 536 | 537 | Nothing in this License shall be construed as excluding or limiting 538 | any implied license or other defenses to infringement that may 539 | otherwise be available to you under applicable patent law. 540 | 541 | 12. No Surrender of Others' Freedom. 542 | 543 | If conditions are imposed on you (whether by court order, agreement or 544 | otherwise) that contradict the conditions of this License, they do not 545 | excuse you from the conditions of this License. If you cannot convey a 546 | covered work so as to satisfy simultaneously your obligations under this 547 | License and any other pertinent obligations, then as a consequence you may 548 | not convey it at all. For example, if you agree to terms that obligate you 549 | to collect a royalty for further conveying from those to whom you convey 550 | the Program, the only way you could satisfy both those terms and this 551 | License would be to refrain entirely from conveying the Program. 552 | 553 | 13. Use with the GNU Affero General Public License. 554 | 555 | Notwithstanding any other provision of this License, you have 556 | permission to link or combine any covered work with a work licensed 557 | under version 3 of the GNU Affero General Public License into a single 558 | combined work, and to convey the resulting work. The terms of this 559 | License will continue to apply to the part which is the covered work, 560 | but the special requirements of the GNU Affero General Public License, 561 | section 13, concerning interaction through a network will apply to the 562 | combination as such. 563 | 564 | 14. Revised Versions of this License. 565 | 566 | The Free Software Foundation may publish revised and/or new versions of 567 | the GNU General Public License from time to time. Such new versions will 568 | be similar in spirit to the present version, but may differ in detail to 569 | address new problems or concerns. 570 | 571 | Each version is given a distinguishing version number. If the 572 | Program specifies that a certain numbered version of the GNU General 573 | Public License "or any later version" applies to it, you have the 574 | option of following the terms and conditions either of that numbered 575 | version or of any later version published by the Free Software 576 | Foundation. If the Program does not specify a version number of the 577 | GNU General Public License, you may choose any version ever published 578 | by the Free Software Foundation. 579 | 580 | If the Program specifies that a proxy can decide which future 581 | versions of the GNU General Public License can be used, that proxy's 582 | public statement of acceptance of a version permanently authorizes you 583 | to choose that version for the Program. 584 | 585 | Later license versions may give you additional or different 586 | permissions. However, no additional obligations are imposed on any 587 | author or copyright holder as a result of your choosing to follow a 588 | later version. 589 | 590 | 15. Disclaimer of Warranty. 591 | 592 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 593 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 594 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 595 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 596 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 597 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 598 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 599 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 600 | 601 | 16. Limitation of Liability. 602 | 603 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 604 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 605 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 606 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 607 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 608 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 609 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 610 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 611 | SUCH DAMAGES. 612 | 613 | 17. Interpretation of Sections 15 and 16. 614 | 615 | If the disclaimer of warranty and limitation of liability provided 616 | above cannot be given local legal effect according to their terms, 617 | reviewing courts shall apply local law that most closely approximates 618 | an absolute waiver of all civil liability in connection with the 619 | Program, unless a warranty or assumption of liability accompanies a 620 | copy of the Program in return for a fee. 621 | 622 | END OF TERMS AND CONDITIONS 623 | 624 | How to Apply These Terms to Your New Programs 625 | 626 | If you develop a new program, and you want it to be of the greatest 627 | possible use to the public, the best way to achieve this is to make it 628 | free software which everyone can redistribute and change under these terms. 629 | 630 | To do so, attach the following notices to the program. It is safest 631 | to attach them to the start of each source file to most effectively 632 | state the exclusion of warranty; and each file should have at least 633 | the "copyright" line and a pointer to where the full notice is found. 634 | 635 | 636 | Copyright (C) 637 | 638 | This program is free software: you can redistribute it and/or modify 639 | it under the terms of the GNU General Public License as published by 640 | the Free Software Foundation, either version 3 of the License, or 641 | (at your option) any later version. 642 | 643 | This program is distributed in the hope that it will be useful, 644 | but WITHOUT ANY WARRANTY; without even the implied warranty of 645 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 646 | GNU General Public License for more details. 647 | 648 | You should have received a copy of the GNU General Public License 649 | along with this program. If not, see . 650 | 651 | Also add information on how to contact you by electronic and paper mail. 652 | 653 | If the program does terminal interaction, make it output a short 654 | notice like this when it starts in an interactive mode: 655 | 656 | Copyright (C) 657 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 658 | This is free software, and you are welcome to redistribute it 659 | under certain conditions; type `show c' for details. 660 | 661 | The hypothetical commands `show w' and `show c' should show the appropriate 662 | parts of the General Public License. Of course, your program's commands 663 | might be different; for a GUI interface, you would use an "about box". 664 | 665 | You should also get your employer (if you work as a programmer) or school, 666 | if any, to sign a "copyright disclaimer" for the program, if necessary. 667 | For more information on this, and how to apply and follow the GNU GPL, see 668 | . 669 | 670 | The GNU General Public License does not permit incorporating your program 671 | into proprietary programs. If your program is a subroutine library, you 672 | may consider it more useful to permit linking proprietary applications with 673 | the library. If this is what you want to do, use the GNU Lesser General 674 | Public License instead of this License. But first, please read 675 | . 676 | 677 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # Makefile for notes 2 | 3 | # specify a location for Pd if desired 4 | PDDIR = ../pd-0.52-2 5 | 6 | lib.name = notesLib 7 | 8 | cflags = -Iinclude 9 | 10 | lib.setup.sources = src/notesLib.c # blank Pd object that loads the library 11 | 12 | class.sources = src/notes.c src/mainscore.c src/line2score.c 13 | 14 | common.sources = src/notes_lib.c 15 | 16 | datafiles = help/notes-help.pd help/hpp-format-o.pd README.md 17 | 18 | # build a multi-object library 19 | make-lib-executable=yes 20 | 21 | PDLIBBUILDER_DIR=../pd-lib-builder 22 | include $(PDLIBBUILDER_DIR)/Makefile.pdlibbuilder 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # notes_lib 2 | notes Pd external object library for encoding music notation in lilypond syntax. 3 | 4 | It is sometimes the case that one needs to generate scores with traditional musical notation from with a Pure Data patch. 5 | 6 | The "notes" external object [1] for Pure Data [2] fits information generated on a patch into traditional music notation, and encodes it in lilypond syntax. See notes-help.pd to see what syntax must be used inside Pd to input information into notes. 7 | 8 | notes will generate .ly scores and you will need Lilypond to compile these scores and output sheet music in .pdf format. If Lilypond is installed, the object will compile the score directly and produce a .pdf document from within Pd. 9 | 10 | LilyPond is an open source music engraving program. Go to [3] to learn more about lilypond and how to install it. The INSTALL.txt file contained with this distribution gives OS-specific guidelines on installing Lilypond to work with notes_lib as well as instructions to compile the code. 11 | 12 | notes is programmed by Jaime Oliver La Rosa [4] [la.rosa@nyu.edu] with contributions by Fede Cámara Halac [5] at the NYU Waverly Labs [6] and is released under the GPL License [7]. It is currently in beta-ish stage. 13 | 14 | 15 | [1] https://github.com/lar0sa/notes_lib 16 | [2] http://msp.ucsd.edu/software.html 17 | [3] http://www.lilypond.org/ 18 | [4] http://www.jaimeoliver.pe 19 | [5] https://github.com/fdch 20 | [6] https://as.nyu.edu/departments/music.html 21 | [7] http://www.gnu.org/copyleft/gpl.html 22 | -------------------------------------------------------------------------------- /TODO.txt: -------------------------------------------------------------------------------- 1 | - check compatibility with other languages in OS X ie. "Applications" vs "Aplicaciones" -------------------------------------------------------------------------------- /help/harppedal-temp.pd: -------------------------------------------------------------------------------- 1 | #N canvas 0 58 462 167 10; 2 | #X msg 112 31 -1 0 1 -1 0 1 -1; 3 | #N canvas 0 58 1051 646 format-harp-pedal 0; 4 | #X msg 810 306 set \$1; 5 | #X obj 810 332 makefilename not-set-yet; 6 | #X obj 752 128 sel -1 0 1; 7 | #X floatatom 752 107 5 0 0 0 - - -, f 5; 8 | #X msg 752 150 v; 9 | #X msg 771 172 -; 10 | #X msg 790 150 ^; 11 | #X obj 771 194 symbol; 12 | #X obj 632 129 sel -1 0 1; 13 | #X floatatom 632 108 5 0 0 0 - - -, f 5; 14 | #X msg 632 151 v; 15 | #X msg 651 173 -; 16 | #X msg 670 151 ^; 17 | #X obj 651 195 symbol; 18 | #X msg 810 355 set \$1; 19 | #X obj 810 382 makefilename not-set-yet; 20 | #X obj 771 217 makefilename %%s%s"; 21 | #X obj 651 218 makefilename %%s%s; 22 | #X obj 510 129 sel -1 0 1; 23 | #X floatatom 510 108 5 0 0 0 - - -, f 5; 24 | #X msg 510 151 v; 25 | #X msg 529 173 -; 26 | #X msg 548 151 ^; 27 | #X obj 529 195 symbol; 28 | #X obj 529 218 makefilename %%s%s; 29 | #X obj 810 434 makefilename not-set-yet; 30 | #X obj 379 130 sel -1 0 1; 31 | #X floatatom 379 109 5 0 0 0 - - -, f 5; 32 | #X msg 379 152 v; 33 | #X msg 398 174 -; 34 | #X msg 417 152 ^; 35 | #X obj 398 196 symbol; 36 | #X msg 810 408 set \$1; 37 | #X obj 24 36 unpack f f f f f f f, f 117; 38 | #X obj 398 219 makefilename %%s|%s; 39 | #X obj 527 492 makefilename not-set-yet; 40 | #X obj 261 310 sel -1 0 1; 41 | #X floatatom 261 289 5 0 0 0 - - -, f 5; 42 | #X msg 261 332 v; 43 | #X msg 280 354 -; 44 | #X msg 299 332 ^; 45 | #X obj 280 376 symbol; 46 | #X msg 527 515 set \$1; 47 | #X obj 527 542 makefilename not-set-yet; 48 | #X obj 280 399 makefilename %%s%s; 49 | #X obj 140 310 sel -1 0 1; 50 | #X floatatom 140 289 5 0 0 0 - - -, f 5; 51 | #X msg 140 332 v; 52 | #X msg 159 354 -; 53 | #X msg 178 332 ^; 54 | #X obj 159 376 symbol; 55 | #X obj 159 399 makefilename %%s%s; 56 | #X obj 527 594 makefilename not-set-yet; 57 | #X obj 24 310 sel -1 0 1; 58 | #X floatatom 24 289 5 0 0 0 - - -, f 5; 59 | #X msg 24 332 v; 60 | #X msg 43 354 -; 61 | #X msg 62 332 ^; 62 | #X obj 43 376 symbol; 63 | #X msg 527 568 set \$1; 64 | #X msg 810 459 set \$1; 65 | #X obj 43 399 makefilename #"%s; 66 | #X obj 527 616 outlet; 67 | #X obj 24 10 inlet; 68 | #X connect 0 0 1 0; 69 | #X connect 1 0 14 0; 70 | #X connect 2 0 4 0; 71 | #X connect 2 1 5 0; 72 | #X connect 2 2 6 0; 73 | #X connect 3 0 2 0; 74 | #X connect 4 0 7 0; 75 | #X connect 5 0 7 0; 76 | #X connect 6 0 7 0; 77 | #X connect 7 0 16 0; 78 | #X connect 8 0 10 0; 79 | #X connect 8 1 11 0; 80 | #X connect 8 2 12 0; 81 | #X connect 9 0 8 0; 82 | #X connect 10 0 13 0; 83 | #X connect 11 0 13 0; 84 | #X connect 12 0 13 0; 85 | #X connect 13 0 17 0; 86 | #X connect 14 0 15 0; 87 | #X connect 15 0 32 0; 88 | #X connect 16 0 0 0; 89 | #X connect 17 0 1 0; 90 | #X connect 18 0 20 0; 91 | #X connect 18 1 21 0; 92 | #X connect 18 2 22 0; 93 | #X connect 19 0 18 0; 94 | #X connect 20 0 23 0; 95 | #X connect 21 0 23 0; 96 | #X connect 22 0 23 0; 97 | #X connect 23 0 24 0; 98 | #X connect 24 0 15 0; 99 | #X connect 25 0 60 0; 100 | #X connect 26 0 28 0; 101 | #X connect 26 1 29 0; 102 | #X connect 26 2 30 0; 103 | #X connect 27 0 26 0; 104 | #X connect 28 0 31 0; 105 | #X connect 29 0 31 0; 106 | #X connect 30 0 31 0; 107 | #X connect 31 0 34 0; 108 | #X connect 32 0 25 0; 109 | #X connect 33 0 54 0; 110 | #X connect 33 1 46 0; 111 | #X connect 33 2 37 0; 112 | #X connect 33 3 27 0; 113 | #X connect 33 4 19 0; 114 | #X connect 33 5 9 0; 115 | #X connect 33 6 3 0; 116 | #X connect 34 0 25 0; 117 | #X connect 35 0 42 0; 118 | #X connect 36 0 38 0; 119 | #X connect 36 1 39 0; 120 | #X connect 36 2 40 0; 121 | #X connect 37 0 36 0; 122 | #X connect 38 0 41 0; 123 | #X connect 39 0 41 0; 124 | #X connect 40 0 41 0; 125 | #X connect 41 0 44 0; 126 | #X connect 42 0 43 0; 127 | #X connect 43 0 59 0; 128 | #X connect 44 0 35 0; 129 | #X connect 45 0 47 0; 130 | #X connect 45 1 48 0; 131 | #X connect 45 2 49 0; 132 | #X connect 46 0 45 0; 133 | #X connect 47 0 50 0; 134 | #X connect 48 0 50 0; 135 | #X connect 49 0 50 0; 136 | #X connect 50 0 51 0; 137 | #X connect 51 0 43 0; 138 | #X connect 52 0 62 0; 139 | #X connect 53 0 55 0; 140 | #X connect 53 1 56 0; 141 | #X connect 53 2 57 0; 142 | #X connect 54 0 53 0; 143 | #X connect 55 0 58 0; 144 | #X connect 56 0 58 0; 145 | #X connect 57 0 58 0; 146 | #X connect 58 0 61 0; 147 | #X connect 59 0 52 0; 148 | #X connect 60 0 35 0; 149 | #X connect 61 0 52 0; 150 | #X connect 63 0 33 0; 151 | #X restore 112 54 pd format-harp-pedal; 152 | #X obj 112 76 print; 153 | #X connect 0 0 1 0; 154 | #X connect 1 0 2 0; 155 | -------------------------------------------------------------------------------- /help/hpp-format-o.pd: -------------------------------------------------------------------------------- 1 | #N canvas 0 58 459 444 10; 2 | #X obj 71 45 inlet; 3 | #X obj 146 111 sel -1 0 1; 4 | #X floatatom 146 90 5 0 0 0 - - -, f 5; 5 | #X msg 146 133 v; 6 | #X msg 165 155 -; 7 | #X msg 184 133 ^; 8 | #X obj 165 177 symbol; 9 | #X obj 284 334 outlet; 10 | #X obj 71 67 t f f, f 13; 11 | #X obj 71 89 change; 12 | #X obj 71 179 sel -1 0 1; 13 | #X floatatom 71 158 5 0 0 0 - - -, f 5; 14 | #X obj 90 245 symbol; 15 | #X msg 71 201 ov; 16 | #X msg 90 223 o-; 17 | #X msg 109 201 o^; 18 | #X obj 71 111 spigot; 19 | #X obj 223 42 inlet; 20 | #X obj 165 200 makefilename %%s%s; 21 | #X obj 90 268 makefilename %%s%s; 22 | #X connect 0 0 8 0; 23 | #X connect 1 0 3 0; 24 | #X connect 1 1 4 0; 25 | #X connect 1 2 5 0; 26 | #X connect 2 0 1 0; 27 | #X connect 3 0 6 0; 28 | #X connect 4 0 6 0; 29 | #X connect 5 0 6 0; 30 | #X connect 6 0 18 0; 31 | #X connect 8 0 9 0; 32 | #X connect 8 1 2 0; 33 | #X connect 9 0 16 0; 34 | #X connect 10 0 13 0; 35 | #X connect 10 1 14 0; 36 | #X connect 10 2 15 0; 37 | #X connect 11 0 10 0; 38 | #X connect 12 0 19 0; 39 | #X connect 13 0 12 0; 40 | #X connect 14 0 12 0; 41 | #X connect 15 0 12 0; 42 | #X connect 16 0 11 0; 43 | #X connect 17 0 16 1; 44 | #X connect 18 0 7 0; 45 | #X connect 19 0 7 0; 46 | -------------------------------------------------------------------------------- /help/notes_lib-meta.pd: -------------------------------------------------------------------------------- 1 | #N canvas 15 49 200 200 10; 2 | #N canvas 25 49 420 300 META 1; 3 | #X text 10 10 VERSION 0; 4 | #X text 10 25 AUTHOR la.rosa@nyu.edu; 5 | #X text 13 41 NAME notes_lib; 6 | #X restore 10 10 pd META; 7 | -------------------------------------------------------------------------------- /include/getline.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Code taken from 3 | * https://riptutorial.com/c/example/8274/get-lines-from-a-file-using-getline-- 4 | * to bring getline() to windows builds... 5 | * which might be an overkill, TODO: probably we could just 6 | * rewrite readbarfile() to use fgets() instead of getline() 7 | */ 8 | 9 | /* Only include our version of getline() if the POSIX version isn't available. */ 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | static ssize_t getline(char **pline_buf, size_t *pn, FILE *fin) 16 | { 17 | const size_t INITALLOC = 16; 18 | const size_t ALLOCSTEP = 16; 19 | size_t num_read = 0; 20 | 21 | /* First check that none of our input pointers are NULL. */ 22 | if ((NULL == pline_buf) || (NULL == pn) || (NULL == fin)) 23 | { 24 | errno = EINVAL; 25 | return -1; 26 | } 27 | 28 | /* If output buffer is NULL, then allocate a buffer. */ 29 | if (NULL == *pline_buf) 30 | { 31 | *pline_buf = malloc(INITALLOC); 32 | if (NULL == *pline_buf) 33 | { 34 | /* Can't allocate memory. */ 35 | return -1; 36 | } 37 | else 38 | { 39 | /* Note how big the buffer is at this time. */ 40 | *pn = INITALLOC; 41 | } 42 | } 43 | 44 | /* Step through the file, pulling characters until either a newline or EOF. */ 45 | 46 | { 47 | int c; 48 | while (EOF != (c = getc(fin))) 49 | { 50 | /* Note we read a character. */ 51 | num_read++; 52 | 53 | /* Reallocate the buffer if we need more room */ 54 | if (num_read >= *pn) 55 | { 56 | size_t n_realloc = *pn + ALLOCSTEP; 57 | char * tmp = realloc(*pline_buf, n_realloc + 1); /* +1 for the trailing NUL. */ 58 | if (NULL != tmp) 59 | { 60 | /* Use the new buffer and note the new buffer size. */ 61 | *pline_buf = tmp; 62 | *pn = n_realloc; 63 | } 64 | else 65 | { 66 | /* Exit with error and let the caller free the buffer. */ 67 | return -1; 68 | } 69 | 70 | /* Test for overflow. */ 71 | if (SSIZE_MAX < *pn) 72 | { 73 | errno = ERANGE; 74 | return -1; 75 | } 76 | } 77 | 78 | /* Add the character to the buffer. */ 79 | (*pline_buf)[num_read - 1] = (char) c; 80 | 81 | /* Break from the loop if we hit the ending character. */ 82 | if (c == '\n') 83 | { 84 | break; 85 | } 86 | } 87 | 88 | /* Note if we hit EOF. */ 89 | if (EOF == c) 90 | { 91 | errno = 0; 92 | return -1; 93 | } 94 | } 95 | 96 | /* Terminate the string by suffixing NUL. */ 97 | (*pline_buf)[num_read] = '\0'; 98 | 99 | return (ssize_t) num_read; 100 | } 101 | -------------------------------------------------------------------------------- /include/notes_lib.h: -------------------------------------------------------------------------------- 1 | // header file for the "notes_lib" c file 2 | // Encodes information created in Pd into a Lilypond score (lilypond.org) 3 | // developed by Jaime Oliver La Rosa (la.rosa@nyu.edu) 4 | // @ the NYU Waverly Labs in the Music Department - FAS. (nyu-waverlylabs.org) 5 | // with contributions by Fede Camara Halac (fch226@nyu.edu) 6 | // Released under the GNU General Public License. 7 | 8 | #include "m_pd.h" 9 | #include "g_canvas.h" 10 | #include 11 | #include 12 | #include 13 | 14 | #define MXV 128 // Maximum number of voices (for mainscore) 15 | #define MXS 4096 // Maximum size of arrays ( or input messages or notes per score...) 16 | 17 | #if defined(__APPLE__) || defined(unix) 18 | #define UNIX 1 19 | #else 20 | // We need this for getline() to work on windows. TODO: remove this dependency. 21 | #include "getline.h" 22 | #endif 23 | 24 | // The following are the definitions for the Lilypond path in different platforms. Used in the compile() function in notes_lib.c 25 | // The LYDIR path is the default value for lily_dir, settable from pd. 26 | #ifdef __APPLE__ 27 | // assume the lilypond is in Applications... 28 | #define LYDIR "/Applications/LilyPond.app" 29 | #define LYBINDIR "/Contents/Resources/bin/" 30 | // 31 | // #elif defined _WIN32 32 | // // assume lilypond is in Program Files (x86)... 33 | // #define LYDIR "C:\Program Files (x86)\LilyPond" 34 | // #define LYBINDIR "\\usr\\bin\\" 35 | 36 | #else // Do not define LY paths for other platforms. 37 | // assume the lilypond command exists in the Path 38 | #define LYDIR "" 39 | #define LYBINDIR "" 40 | #endif 41 | 42 | // these are defined in m_pd.h for file handling across platforms 43 | #define fopen sys_fopen 44 | #define fclose sys_fclose 45 | 46 | #define NOTESLIBVERSION "0.2: 2022-08-02" 47 | 48 | // helper functions in notes_lib.c 49 | float reduce_meter(int a); 50 | int get_beatsize(int a, int b, int c); 51 | int pow2test(int a); 52 | int pow2dottest(int a); 53 | int pow2ordot(int a); 54 | void find_relative(int a, FILE *f); 55 | void find_pitch(float a, int b, char g[]); 56 | int find_jump(int a, int b, int c, char g[]); 57 | void find_clef(int a, FILE *f); 58 | void find_articulation(int a, FILE *f); 59 | void find_dynamics(int a, FILE *f); 60 | void find_small_numbers(int a, FILE *f); 61 | void find_span(int a, FILE *f); 62 | void find_stafftext(int a, char g[]); 63 | void find_grace(int a, FILE *f); 64 | void find_arpeggio(int a, FILE *f); 65 | void find_notehead(int a, FILE *f); 66 | int readbarfile(int a[][8], FILE *f); 67 | void copyfiles(FILE *f, FILE *g); 68 | // score compiling and opening routines 69 | int compile(char *buf, char *name, int debug, char *lily_dir); 70 | void open_pdf(char *buf); 71 | int compile_and_open(char *buf, char *name, int debug, int SLAVE, int render, int open, char *lily_dir); 72 | 73 | // setup routines 74 | void mainscore_setup(); 75 | void line2score_setup(); 76 | void notes_setup(); 77 | -------------------------------------------------------------------------------- /samp/accordion.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lar0sa/notes_lib/c21d7298f7361c493c96f3855a5ffdf9bc344533/samp/accordion.wav -------------------------------------------------------------------------------- /samp/flute.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lar0sa/notes_lib/c21d7298f7361c493c96f3855a5ffdf9bc344533/samp/flute.wav -------------------------------------------------------------------------------- /samp/gong.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lar0sa/notes_lib/c21d7298f7361c493c96f3855a5ffdf9bc344533/samp/gong.wav -------------------------------------------------------------------------------- /src/line2score.c: -------------------------------------------------------------------------------- 1 | // code for the "line2score" pd class. 2 | // Encodes information created in Pd into a Lilypond score (lilypond.org) 3 | // developed by Jaime Oliver La Rosa (la.rosa@nyu.edu) 4 | // @ the NYU Waverly Labs in the Music Department - FAS. (nyu-waverlylabs.org) 5 | // updated by Fede Camara Halac (fch226@nyu.edu) 6 | // Released under the GNU General Public License. 7 | 8 | #include "notes_lib.h" 9 | 10 | typedef struct line2score 11 | { 12 | t_object x_ob; 13 | t_outlet *x_outlet; 14 | t_outlet *x_outlet2, *x_outlet3; 15 | float pit[MXS], o_pit[MXS], last_pit, o_grc[MXS]; 16 | int dur[MXS], gli[MXS], o_dur[MXS], o_tie[MXS], o_gli[MXS], o_bounds[MXS], index; 17 | const char *dummysym; 18 | 19 | } t_line2score; 20 | 21 | void line2score_input(t_line2score *x, t_symbol *s, int argcount, t_atom *argvec) { 22 | int i; 23 | x->dummysym = s->s_name; 24 | for(i=0;ipit[x->index] = argvec[i].a_w.w_float; 26 | else if (i==1) x->dur[x->index] = argvec[i].a_w.w_float; 27 | else if (i==2) x->gli[x->index] = argvec[i].a_w.w_float; 28 | } 29 | x->index++; 30 | } 31 | 32 | void line2score_output(t_line2score *x) 33 | { 34 | int i; 35 | t_atom at[4], ax[4]; 36 | 37 | SETFLOAT(&ax[0], 1); 38 | outlet_list(x->x_outlet3, 0, 1, ax); 39 | 40 | for (i=0;iindex;i++){ 41 | x->o_grc[i] = x->o_tie[i] = 0; x->o_gli[i] = 0; 42 | if(x->last_pit == 0 && i==0) x->last_pit = x->pit[i]; 43 | x->o_dur[i] = x->dur[i]; 44 | x->o_pit[i] = x->pit[i]; 45 | if(x->gli[i] > 0) { 46 | x->o_gli[i] = 1; 47 | x->o_pit[i] = x->last_pit; 48 | x->o_grc[i] = x->pit[i]; 49 | } 50 | x->last_pit = x->pit[i]; 51 | 52 | } 53 | for (i=0;iindex;i++){ 54 | if(i+1 == x->index) SETFLOAT(&ax[0], 0); 55 | if(i<(x->index-1) && x->o_grc[i] == x->o_pit[i+1]) x->o_grc[i] = 0; 56 | if(i<(x->index-1) && x->o_pit[i] == x->o_pit[i+1]) x->o_tie[i] = 1; 57 | SETFLOAT(&at[0], x->o_pit[i]); 58 | SETFLOAT(&at[1], x->o_dur[i]); 59 | SETFLOAT(&at[2], x->o_tie[i]); 60 | SETFLOAT(&at[3], x->o_gli[i]); 61 | if(i+1 == x->index) outlet_list(x->x_outlet3, 0, 1, ax); 62 | outlet_list(x->x_outlet, 0, 4, at); 63 | 64 | if (x->o_grc[i] > 0) { 65 | SETFLOAT(&at[0], x->o_grc[i]); 66 | if(i+1 == x->index) outlet_list(x->x_outlet3, 0, 1, ax); 67 | outlet_list(x->x_outlet2, 0, 1, at); 68 | } 69 | } 70 | x->index = 0; 71 | } 72 | 73 | void line2score_ft1(t_line2score *x, t_floatarg g) 74 | { 75 | x->last_pit = g; 76 | } 77 | 78 | void line2score_clear(t_line2score *x) { 79 | int i; 80 | for (i=0; iindex; i++) { 81 | x->pit[i] = x->last_pit = 0; 82 | x->gli[i] = x->dur[i] = 0; 83 | x->o_grc[i] = x->o_pit[i] = x->last_pit = 0; 84 | x->o_gli[i] = x->o_dur[i] = 0; 85 | } 86 | x->index = 0; 87 | } 88 | 89 | t_class *line2score_class; 90 | 91 | 92 | void *line2score_new() 93 | { 94 | t_line2score *x = (t_line2score *)pd_new(line2score_class); 95 | inlet_new(&x->x_ob, &x->x_ob.ob_pd, gensym("float"), gensym("ft1")); 96 | x->x_outlet = outlet_new(&x->x_ob, gensym("list")); 97 | x->x_outlet2 = outlet_new(&x->x_ob, gensym("list")); 98 | x->x_outlet3 = outlet_new(&x->x_ob, gensym("float")); 99 | x->index = 0; 100 | return (void *)x; 101 | } 102 | 103 | void line2score_setup(void) 104 | { 105 | line2score_class = class_new(gensym("line2score"), (t_newmethod)line2score_new, 106 | 0, sizeof(t_line2score), 0, A_DEFFLOAT, 0); 107 | class_addmethod(line2score_class, (t_method)line2score_input, gensym("input"), A_GIMME, 0); 108 | class_addmethod(line2score_class, (t_method)line2score_output, gensym("output"), 0); 109 | class_addmethod(line2score_class, (t_method)line2score_clear, gensym("clear"), 0); 110 | class_addmethod(line2score_class, (t_method)line2score_ft1, gensym("ft1"), A_FLOAT, 0); 111 | class_sethelpsymbol(line2score_class, gensym("notes")); 112 | 113 | } 114 | 115 | -------------------------------------------------------------------------------- /src/mainscore.c: -------------------------------------------------------------------------------- 1 | // code for the "mainscore" pd class. 2 | // Encodes information created in Pd into a Lilypond score (lilypond.org) 3 | // developed by Jaime Oliver La Rosa (la.rosa@nyu.edu) 4 | // @ the NYU Waverly Labs in the Music Department - FAS. (nyu-waverlylabs.org) 5 | // with contributions by Fede Camara Halac (fch226@nyu.edu) 6 | // Released under the GNU General Public License. 7 | 8 | #include "notes_lib.h" 9 | 10 | //// ____________________________________________________ MAIN STRUCT 11 | typedef struct mainscore { 12 | t_object x_ob; 13 | t_outlet *x_outlet0, *x_outlet1, *x_outlet2; 14 | t_canvas *x_canvas; 15 | FILE *fp1; 16 | 17 | int part_n[MXV][2], i_part_n[MXV][2]; 18 | char parts[MXV][2][130], i_parts[MXV][2][130]; 19 | char title[64][130], sub_title[64][130], author[64][130], osname[130], lily_dir[MAXPDSTRING], barfile[MAXPDSTRING], inst[150]; 20 | 21 | const char *dummysym; // const to remove warning 22 | int ii, debug, auth_n, titl_n, sub_title_n; 23 | int inst_n, papersize, paperorientation, part_i, i_part_i, voice, total_voices; 24 | int open; 25 | } 26 | t_mainscore; 27 | //// ____________________________________________________ INPUT 28 | void mainscore_part(t_mainscore *x, t_symbol *s, int argcount, t_atom *argvec) { 29 | int a; 30 | a = argcount; 31 | a = 0; 32 | x->dummysym = s->s_name; 33 | 34 | if (argvec[a].a_type == A_FLOAT && 35 | argvec[a+1].a_type == A_FLOAT && 36 | argvec[a+2].a_type == A_SYMBOL && 37 | argvec[a+3].a_type == A_SYMBOL ) { 38 | x->i_part_n[x->i_part_i][0] = argvec[a].a_w.w_float; /// part number 39 | x->i_part_n[x->i_part_i][1] = argvec[a+1].a_w.w_float; /// voice number 40 | strcpy(x->i_parts[x->i_part_i][0], argvec[a+2].a_w.w_symbol->s_name);/// inst name 41 | strcpy(x->i_parts[x->i_part_i][1], argvec[a+3].a_w.w_symbol->s_name);/// path 42 | // post("mainscore:path:: %i\t%i\t%i\t%s\t%s", x->i_part_i, x->i_part_n[x->i_part_i][0], x->i_part_n[x->i_part_i][1], x->i_parts[x->i_part_i][0], x->i_parts[x->i_part_i][1]); 43 | x->i_part_i++; 44 | } 45 | else { 46 | post("MAINSCORE:::::::::::: wrong input format, please format to: part no., voice no., inst name, file path."); 47 | } 48 | } 49 | //// ____________________________________________________ WRITE 50 | void mainscore_write(t_mainscore *x, t_symbol *s) { 51 | // post("WRITE METHOD"); 52 | int i, min, j, k, m, d, done[x->i_part_i]; 53 | char a; 54 | char buf[MAXPDSTRING], partpath[MAXPDSTRING], scorename[MAXPDSTRING], linename[MAXPDSTRING]; 55 | FILE *fp1, *fp2; 56 | //// _______________________________________________ REORDER INPUT 57 | post("mainscore: Sorting Input ..."); 58 | k=d=0; 59 | while(d < x->i_part_i){ 60 | min = 1000000; 61 | for (i=0; ii_part_i; i++){ 62 | if(x->i_part_n[i][0] <= min){ 63 | m = 0; 64 | for (j=0; ji_part_n[i][0]; 69 | k = i; 70 | } 71 | } 72 | } 73 | x->part_n[d][0] = x->i_part_n[k][0]; /// part number 74 | x->part_n[d][1] = x->i_part_n[k][1]; /// voice number 75 | strcpy(x->parts[d][0], x->i_parts[k][0]); /// inst name 76 | strcpy(x->parts[d][1], x->i_parts[k][1]); /// path 77 | done[d] = k; 78 | // post("%d\t%d\t%d\t%s\t%s\t", d, x->part_n[d][0], x->part_n[d][1], x->parts[d][0], x->parts[d][1]); 79 | d++; 80 | } 81 | // post("Copying"); 82 | x->part_i = x->i_part_i; 83 | for (i=0; ii_part_i; i++){ 84 | x->i_part_n[i][0] = x->part_n[i][0]; /// part number 85 | x->i_part_n[i][1] = x->part_n[i][1]; /// voice number 86 | strcpy(x->i_parts[i][0], x->parts[i][0]); /// inst name 87 | strcpy(x->i_parts[i][1], x->parts[i][1]); /// path 88 | } 89 | // post("sorting voices"); 90 | for (i=0; ii_part_i; i++){ 91 | if(x->i_part_n[i][0] == x->i_part_n[i+1][0]) { 92 | if(x->i_part_n[i][1] > x->i_part_n[i+1][1]) { 93 | // post("yyyyyyyyyyyyyyyy"); 94 | x->part_n[i][0] = x->i_part_n[i+1][0]; /// part number 95 | x->part_n[i][1] = x->i_part_n[i+1][1]; /// voice number 96 | strcpy(x->parts[i][0], x->i_parts[i+1][0]); /// inst name 97 | strcpy(x->parts[i][1], x->i_parts[i+1][1]); /// path 98 | x->part_n[i+1][0] = x->i_part_n[i][0]; /// part number 99 | x->part_n[i+1][1] = x->i_part_n[i][1]; /// voice number 100 | strcpy(x->parts[i+1][0], x->i_parts[i][0]); /// inst name 101 | strcpy(x->parts[i+1][1], x->i_parts[i][1]); /// path 102 | i++; 103 | } 104 | else { 105 | x->part_n[i][0] = x->i_part_n[i][0]; /// part number 106 | x->part_n[i][1] = x->i_part_n[i][1]; /// voice number 107 | strcpy(x->parts[i][0], x->i_parts[i][0]); /// inst name 108 | strcpy(x->parts[i][1], x->i_parts[i][1]); /// path 109 | } 110 | } 111 | else { 112 | x->part_n[i][0] = x->i_part_n[i][0]; /// part number 113 | x->part_n[i][1] = x->i_part_n[i][1]; /// voice number 114 | strcpy(x->parts[i][0], x->i_parts[i][0]); /// inst name 115 | strcpy(x->parts[i][1], x->i_parts[i][1]); /// path 116 | } 117 | } 118 | for (i=0; ii_part_i; i++){ 119 | // post("%d\t%d\t%d\t%s\t%s\t", i, x->part_n[i][0], x->part_n[i][1], x->parts[i][0], x->parts[i][1]); 120 | } 121 | //// _______________________________________________ OPEN FILE 122 | post("mainscore: ... Formatting Score... "); 123 | canvas_makefilename(x->x_canvas, s->s_name, buf, MAXPDSTRING); /// This is a Pd function to get the path relative to the canvas 124 | sys_bashfilename(buf, buf); 125 | strcpy( scorename, buf); 126 | strcat( scorename, ".ly"); 127 | fp1 = fopen(scorename, "w"); 128 | if(!fp1) { 129 | pd_error(x,"%s: couldn't create", buf); 130 | return; 131 | } 132 | //// _______________________________________________ WRITE SCORE 133 | else { 134 | post("mainscore: writing into %s", scorename); 135 | fprintf(fp1, "%% [notes] external for Pure Data\n%% version 0.2 August 2, 2022 \n%% by Jaime E. Oliver La Rosa\n%% la.rosa@nyu.edu\n%% @ the Waverly Labs in NYU MUSIC FAS\n%% With contributions from Fede Camara Halac\n%% Open this file with Lilypond\n%% more information is available at lilypond.org\n%% Released under the GNU General Public License.\n\n"); 136 | //// _______________________________________ COPY PARTS TO MAIN SCORE 137 | for (i=0; ipart_i; i++) { 138 | strcpy(partpath, x->parts[i][1]); 139 | post("mainscore: reading %s", partpath); 140 | fp2 = fopen(partpath, "r"); 141 | a = fgetc(fp2); 142 | if (a != EOF) fputc(a, fp1); 143 | while(a != EOF) { 144 | a = fgetc(fp2); 145 | if (a != EOF) fputc(a, fp1); 146 | } 147 | fprintf(fp1, "\n"); 148 | fclose(fp2); 149 | } 150 | //// __________________________________________ SCORE EXPRESSION 151 | if (x->auth_n > 0 || x->titl_n > 0 || x->sub_title_n > 0) { 152 | fprintf(fp1, "\n\\header {"); 153 | if (x->auth_n > 0) { 154 | fprintf(fp1, "\n\tcomposer = \""); 155 | for(i=0; iauth_n; i++){ 156 | fprintf(fp1, "%1.32s ", x->author[i]); 157 | } 158 | fprintf(fp1, "\""); 159 | } 160 | if (x->titl_n > 0) { 161 | fprintf(fp1, "\n\ttitle = \""); 162 | for(i=0; ititl_n; i++){ 163 | fprintf(fp1, "%1.32s ", x->title[i]); 164 | } 165 | fprintf(fp1, "\""); 166 | } 167 | if (x->sub_title_n > 0) { 168 | fprintf(fp1, "\n\tsubtitle = \""); 169 | for(i=0; isub_title_n; i++){ 170 | fprintf(fp1, "%1.32s ", x->sub_title[i]); 171 | } 172 | fprintf(fp1, "\""); 173 | } 174 | fprintf(fp1, "\n}\n\n"); 175 | } // HEADER Title, subtitle, and Author 176 | fprintf(fp1, "\n\\score {\n\t<<"); 177 | for (i=0; ipart_i; i++) { 178 | strcpy(linename, x->parts[i][0]); 179 | strcat(linename, "_part"); 180 | fprintf(fp1, "\n\t\\new Staff \\with { instrumentName = \"%s\" } ", x->parts[i][0]); 181 | fprintf(fp1, "{\n\t\t<<\n\t\t\\new Voice {"); 182 | if (x->part_n[i][0] == x->part_n[i+1][0]) { 183 | if (x->part_n[i][1] <= 1) { 184 | fprintf(fp1, "\n\t\t\t\\voiceOne"); 185 | fprintf(fp1, "\n\t\t\t\\%s\n\t\t}", linename); 186 | } 187 | while (x->part_n[i][0] == x->part_n[i+1][0]) { 188 | i++; 189 | strcpy(linename, x->parts[i][0]); 190 | strcat(linename, "_part"); 191 | fprintf(fp1, "\n\t\t\\new Voice {"); 192 | fprintf(fp1, "\n\t\t\t\\voiceTwo"); 193 | fprintf(fp1, "\n\t\t\t\\%s\n\t\t}", linename); 194 | } 195 | fprintf(fp1, "\n\t\t>>\n\t}"); 196 | } 197 | else { 198 | fprintf(fp1, "\n\t\t\t\\%s\n\t\t}\n\t\t>>\n\t}", linename); 199 | } 200 | } 201 | fprintf(fp1, "\n\t>>\n\t\\layout {"); 202 | fprintf(fp1, "\n\t\t\\mergeDifferentlyHeadedOn"); 203 | fprintf(fp1, "\n\t\t\\mergeDifferentlyDottedOn"); 204 | fprintf(fp1, "\n\t\t\\set Staff.pedalSustainStyle = #'mixed"); 205 | fprintf(fp1, "\n\t\t#(set-default-paper-size \"a%i", x->papersize); 206 | if(x->paperorientation==1) fprintf(fp1, "landscape\")"); 207 | else fprintf(fp1, "\")"); 208 | fprintf(fp1, "\n\t}\n\t\\midi { }\n}"); 209 | fprintf(fp1, "\n\n\\version \"2.18.2\"\n%% mainscore Pd External version 0.2 \n"); 210 | fclose(fp1); 211 | post("mainscore: .ly score finished"); 212 | // compile and open 213 | // if(compile_and_open(buf,scorename,x->debug,x->FOLLOW,x->render,x->open, x->lily_dir)){ //according to notes 214 | if(compile_and_open(buf, scorename, x->debug, 0, 1, x->open, x->lily_dir)){ 215 | //if(compile_and_open(buf, scorename, x->debug, 0, 1, x->open,LYBINDIR)){ 216 | pd_error(x, "mainscore: error compiling score"); 217 | } 218 | } // if a file is correctly provided. 219 | //*/ 220 | } 221 | //// ____________________________________________________ CLEAR 222 | void mainscore_clear(t_mainscore *x) { 223 | x->part_i = x->i_part_i = 0; 224 | x->auth_n = x->titl_n = x->sub_title_n = 0; 225 | post("mainscore: Cleared"); 226 | } 227 | //// ____________________________________________________ OPENING SWITCH 228 | void mainscore_open(t_mainscore *x, t_floatarg f) { 229 | int i; 230 | if (f == 0) { 231 | i = 0; 232 | post("mainscore: score opening off"); 233 | } 234 | else { 235 | i = 1; 236 | post("mainscore: score opening on"); 237 | } 238 | x->open = i; 239 | } 240 | //// ____________________________________________________ DEBUG 241 | void mainscore_debug(t_mainscore *x, t_floatarg f) { 242 | x->debug = (int) f; 243 | post("debugging level = %d", x->debug); 244 | } 245 | //// ____________________________________________________ TITLE 246 | void mainscore_title(t_mainscore *x, t_symbol *s, int argc, t_atom *argv) { 247 | x->dummysym = s->s_name; 248 | int i; 249 | for(i=0;ititle[i], 1000); 251 | // post(x->title[i]); 252 | } 253 | x->titl_n = argc; 254 | } 255 | //// ____________________________________________________ SUB_TITLE 256 | void mainscore_sub_title(t_mainscore *x, t_symbol *s, int argc, t_atom *argv) { 257 | x->dummysym = s->s_name; 258 | int i; 259 | for(i=0;isub_title[i], 1000); 261 | // post(x->sub_title[i]); 262 | } 263 | x->sub_title_n = argc; 264 | } 265 | //// ____________________________________________________ AUTHOR 266 | void mainscore_author(t_mainscore *x, t_symbol *s, int argc, t_atom *argv) { 267 | x->dummysym = s->s_name; 268 | int i; 269 | for(i=0;iauthor[i], 1000); 271 | // post(x->author[i]); 272 | } 273 | x->auth_n = argc; 274 | } 275 | //// ____________________________________________________ Lilypond Location 276 | void mainscore_lily_dir(t_mainscore *x, t_symbol *s, int argc, t_atom *argv) { 277 | int i; i = argc; i++; 278 | x->dummysym = s->s_name; 279 | atom_string(argv, x->lily_dir, MAXPDSTRING); 280 | post("mainscore: Lilypond directory set to: %s", x->lily_dir); 281 | } 282 | //// ____________________________________________________ PAPER SIZE 283 | void mainscore_paper(t_mainscore *x, t_floatarg f, t_floatarg g) { 284 | x->papersize = (int) f; 285 | x->paperorientation = (int) g; 286 | } 287 | t_class *mainscore_class; 288 | void *mainscore_new(t_floatarg ff) { 289 | t_mainscore *x = (t_mainscore *)pd_new(mainscore_class); 290 | // inlet_new(&x->x_ob, &x->x_ob.ob_pd, gensym("symbol"), gensym("readfile")); 291 | x->x_outlet0 = outlet_new(&x->x_ob, &s_symbol); 292 | // x->x_outlet1 = outlet_new(&x->x_ob, &s_symbol); 293 | x->x_canvas = canvas_getcurrent(); 294 | strcpy(x->lily_dir, LYDIR); // see notes_lib.h 295 | // strcpy( x->lily_dir, "~/bin"); 296 | strcpy (x->inst, "inst"); 297 | x->debug = 0; 298 | x->auth_n = x->titl_n = 0; 299 | x->papersize = 4; 300 | x->paperorientation = 0; 301 | x->part_i = x->part_i = 0; 302 | x->total_voices = (int) ff; 303 | x->open = 1; 304 | return (void *)x; 305 | } 306 | void mainscore_setup(void) { 307 | mainscore_class = class_new(gensym("mainscore"), (t_newmethod)mainscore_new, 0, sizeof(t_mainscore), 0, A_DEFFLOAT, 0); 308 | 309 | class_addmethod(mainscore_class, (t_method)mainscore_part, gensym("part"), A_GIMME, 0); 310 | class_addmethod(mainscore_class, (t_method)mainscore_write, gensym("write"), A_SYMBOL, 0); 311 | class_addmethod(mainscore_class, (t_method)mainscore_title, gensym("title"), A_GIMME, 0); 312 | class_addmethod(mainscore_class, (t_method)mainscore_sub_title, gensym("sub_title"),A_GIMME, 0); 313 | class_addmethod(mainscore_class, (t_method)mainscore_author, gensym("author"), A_GIMME, 0); 314 | class_addmethod(mainscore_class, (t_method)mainscore_lily_dir, gensym("lily_dir"), A_GIMME, 0); 315 | class_addmethod(mainscore_class, (t_method)mainscore_clear, gensym("clear"), 0); 316 | class_addmethod(mainscore_class, (t_method)mainscore_debug, gensym("debug"), A_DEFFLOAT, 0); 317 | class_addmethod(mainscore_class, (t_method)mainscore_paper, gensym("paper"), A_DEFFLOAT, A_DEFFLOAT, 0); 318 | class_addmethod(mainscore_class, (t_method)mainscore_open, gensym("open"), A_DEFFLOAT, 0); 319 | class_sethelpsymbol(mainscore_class, gensym("notes")); 320 | //post("mainscore:\ttesting: 20220802-1"); 321 | } -------------------------------------------------------------------------------- /src/notes.c: -------------------------------------------------------------------------------- 1 | // code for the "notes" pd class. 2 | // Encodes information created in Pd into a Lilypond score (lilypond.org) 3 | // developed by Jaime Oliver La Rosa (la.rosa@nyu.edu) 4 | // @ the NYU Waverly Labs in the Music Department - FAS. (nyu-waverlylabs.org) 5 | // with contributions by Fede Camara Halac (fch226@nyu.edu) 6 | // Released under the GNU General Public License. 7 | 8 | #include "notes_lib.h" 9 | 10 | //// ____________________________________________________ MAIN STRUCT 11 | typedef struct notes { 12 | t_object x_ob; 13 | t_outlet *x_outlet0, *x_outlet1, *x_outlet2, *x_outlet3; 14 | t_canvas *x_canvas; 15 | FILE *fp1; 16 | 17 | ////////////////// ******* RAW INPUT DATA: 18 | // pitch, duration, articulation, tie, dynamics, articulation, tempo, meter, text, harp-pedals 19 | // add rehearsal marks, tremolo 20 | 21 | int ri_index; 22 | int ri_cho[MXS], ri_dur[MXS], ri_tie[MXS], ri_clu[MXS], ri_clef[MXS], ri_acc[MXS], ri_trm[MXS], ri_arp[MXS]; 23 | int ri_dyn_n[MXS], ri_art_n[MXS], ri_smn_n[MXS], ri_spa_n[MXS], ri_txt_n[MXS], ri_txt_spn_n[MXS], ri_hrm_n[MXS], ri_nhs_n[MXS], ri_hpp_n[MXS]; 24 | float ri_pit[MXS][128], ri_spa_p[MXS]; 25 | int ri_mtr[MXS][2], ri_tmp[MXS][2], ri_grc[MXS][2], ri_tup[MXS][3], ri_dyn[MXS][16], ri_art[MXS][16], ri_smn[MXS][8], ri_spa[MXS][8], ri_hrm[MXS][8], ri_nhs[MXS][16], ri_txt_spn[MXS][6]; 26 | char ri_txt[MXS][32][64]; 27 | char ri_hpp[MXS][16]; 28 | 29 | int ri_index_sort[MXS]; 30 | 31 | ////////////////// ******* CLEAN INPUT DATA: 32 | int i_index, i_rii[MXS]; 33 | int i_cho[MXS], i_dur[MXS], i_mtr[MXS][2], i_tup[MXS], i_tie[MXS]; 34 | 35 | ////////////////// ******* TUPLET DATA: 36 | int tp_info[MXS][5], tp_n; 37 | int tp_index, tp_dur[MXS], tp_i[MXS], tp_ri[MXS], tp_tie[MXS], tp_num[MXS]; 38 | int b_tp_index, b_tp_dur[MXS], b_tp_i[MXS], b_tp_ri[MXS], b_tp_tie[MXS], b_tp_num[MXS]; 39 | int sb_tp_index, sb_tp_dur[MXS], sb_tp_i[MXS], sb_tp_ri[MXS], sb_tp_tie[MXS], sb_tp_num[MXS]; 40 | int sb_tp_start[MXS], sb_tp_end[MXS]; 41 | ////////////////// ******* GRACE DATA: 42 | int g_index, g_rii[MXS], g_dur[MXS]; 43 | 44 | ////////////////// ******* BAR DATA: 45 | int b_index, bar_n[MXS], b_tie[MXS], b_dur[MXS], b_i[MXS], b_mtr[MXS][2], b_tmp[MXS][2], b_rii[MXS], b_tup[MXS]; 46 | int bar_info[MXS][8]; // 0 = initial position, 1 = num, 2 = den 47 | ////////////////// ******* BEAT DATA: 48 | int be_index, be_bar_n[MXS], be_beat_n[MXS], be_tie[MXS], be_dur[MXS], be_i[MXS], be_rii[MXS], be_tup[MXS]; 49 | ////////////////// ******* SUB-BEAT DATA: 50 | int sb_index, sb_bar_n[MXS], sb_beat_n[MXS], sb_tie[MXS], sb_dur[MXS], sb_i[MXS], sb_rii[MXS], sb_tup[MXS]; 51 | 52 | char title[64][130], sub_title[64][130], author[64][130], osname[130], lily_dir[MAXPDSTRING], barfile[MAXPDSTRING], inst[150]; 53 | const char *dummysym; // const to remove warning 54 | int ii, refdur, debug, auth_n, titl_n, sub_title_n, tempo, OS, lastpit_ch, lastpit; 55 | int FOLLOW, inst_n, papersize, paperorientation, render, open; 56 | } 57 | t_notes; 58 | 59 | //// ____________________________________________________ INPUT 60 | void notes_input(t_notes *x, t_symbol *s, int argcount, t_atom *argvec) { 61 | int a, i, j, input_check[21]; 62 | float temp_f, temp_f_array[128]; 63 | x->dummysym = s->s_name; 64 | 65 | t_symbol *nt_pitch = gensym("-pit"); // float = single note & list = chord 66 | t_symbol *nt_rhythm = gensym("-dur"); // float = duration 67 | t_symbol *nt_dynamics = gensym("-dyn"); // float = dynamics list (0 = nothing, 1 = pppp, etc..) 68 | t_symbol *nt_tuplet = gensym("-tup"); // 1 3 4 (3 1's in the place of 4)? 69 | t_symbol *nt_meter = gensym("-mtr"); // meter num, denom 70 | t_symbol *nt_articulation = gensym("-art"); // articulation, n 71 | t_symbol *nt_tempo = gensym("-tmp"); // tempo 32 = msec 72 | t_symbol *nt_small_numbers = gensym("-smn"); // small numbers, mostly for fingering. 73 | t_symbol *nt_clef = gensym("-clf"); // Clef changes. 74 | t_symbol *nt_accidentals = gensym("-acc"); // accidentals. 75 | t_symbol *nt_tremolo = gensym("-trm"); // tremolo. 76 | t_symbol *nt_span = gensym("-spa"); // tremolo. 77 | t_symbol *nt_grace = gensym("-grc"); // grace notes 78 | t_symbol *nt_harmonic = gensym("-hrm"); // stopped harmonics 79 | t_symbol *nt_noteheads = gensym("-nhs"); // noteheads 80 | t_symbol *nt_tie = gensym("-tie"); // tie 81 | t_symbol *nt_cluster = gensym("-clu"); // clusters 82 | t_symbol *nt_arpeggio = gensym("-arp"); // arpeggio 83 | t_symbol *nt_text = gensym("-txt"); // text 84 | t_symbol *nt_harppedal = gensym("-hpp"); // harp_pedal 85 | 86 | if (x->debug >= 1) post("INDEX ========= %d", x->ri_index); 87 | for (a = 0; a < 21; a++) { input_check[a] = 0; }; 88 | for (a = 0; a < argcount; a++) { 89 | if (x->debug >= 1) post("notes: Input index %d received", x->ri_index); 90 | if (argvec[a].a_type == A_SYMBOL) { 91 | x->ri_spa_p[x->ri_index] = 0; 92 | //_____________________________________________________________________________ 93 | if ( argvec[a].a_w.w_symbol == nt_pitch) { 94 | i = 0; 95 | while (argvec[a+1].a_type == A_FLOAT && a < argcount-1) { 96 | a++; 97 | x->ri_pit[x->ri_index][i] = argvec[a].a_w.w_float; 98 | // post("pitch =\t%f", x->ri_pit[x->ri_index][i]); 99 | i++; 100 | } 101 | x->ri_cho[x->ri_index] = i; 102 | if (x->debug >= 1) post("chord size = %d", x->ri_cho[x->ri_index]); 103 | input_check[0] = 1; 104 | for (j=0; jri_cho[x->ri_index]; j++) { 105 | temp_f = 1000; 106 | for (i=0; iri_cho[x->ri_index]; i++) { 107 | if (j==0) { 108 | if (x->ri_pit[x->ri_index][i] <= temp_f) { 109 | temp_f = x->ri_pit[x->ri_index][i]; 110 | } 111 | } 112 | else { 113 | if (x->ri_pit[x->ri_index][i] < temp_f && 114 | x->ri_pit[x->ri_index][i] > temp_f_array[j-1]) { 115 | temp_f = x->ri_pit[x->ri_index][i]; 116 | } 117 | } 118 | } 119 | temp_f_array[j] = temp_f; 120 | if (x->debug >= 1) post("o.pitch =\t%f", temp_f_array[j]); 121 | } 122 | for (j=0; jri_cho[x->ri_index]; j++) { 123 | x->ri_pit[x->ri_index][j] = temp_f_array[j]; 124 | } 125 | } 126 | //_____________________________________________________________________________ 127 | else if ( argvec[a].a_w.w_symbol == nt_rhythm) { 128 | while (argvec[a+1].a_type == A_FLOAT && a < argcount-1) { 129 | a++; 130 | x->ri_dur[x->ri_index] = argvec[a].a_w.w_float; 131 | if ( x->ri_dur[x->ri_index] == 0) { 132 | post("notes: ERROR: durations of 0 are not allowed, changing it to last duration"); 133 | x->ri_dur[x->ri_index] = 0; 134 | input_check[1] = 0; 135 | } 136 | else { 137 | // post("duration = %d", x->ri_dur[x->ri_index]); 138 | input_check[1] = 1; 139 | } 140 | } 141 | 142 | } 143 | //_____________________________________________________________________________ 144 | else if ( argvec[a].a_w.w_symbol == nt_dynamics) { 145 | i = 0; 146 | while (argvec[a+1].a_type == A_FLOAT && a < argcount-1) { 147 | a++; 148 | x->ri_dyn[x->ri_index][i] = argvec[a].a_w.w_float; 149 | i++; 150 | } 151 | x->ri_dyn_n[x->ri_index] = i; 152 | if (x->debug >= 1) post("dynamics = %d", x->ri_dyn[x->ri_index]); 153 | input_check[2] = 1; 154 | } 155 | //_____________________________________________________________________________ 156 | else if ( argvec[a].a_w.w_symbol == nt_tuplet) { 157 | i = 0; 158 | while (argvec[a+1].a_type == A_FLOAT && a < argcount-1) { 159 | a++; 160 | x->ri_tup[x->ri_index][i] = argvec[a].a_w.w_float; 161 | i++; 162 | } 163 | if (i != 3) post("notes: ERROR: not enough arguments for tuplet (need 3... see help file)"); 164 | if (x->debug >= 1) post("tuplet = %d %d %d", x->ri_tup[x->ri_index][0], x->ri_tup[x->ri_index][1], x->ri_tup[x->ri_index][2]); 165 | input_check[3] = 1; 166 | } 167 | //_____________________________________________________________________________ 168 | else if ( argvec[a].a_w.w_symbol == nt_meter) { 169 | i = 0; 170 | while (argvec[a+1].a_type == A_FLOAT && a < argcount-1) { 171 | a++; 172 | x->ri_mtr[x->ri_index][i] = argvec[a].a_w.w_float; 173 | i++; 174 | } 175 | if (i != 2) { 176 | post("notes: ERROR: not enough arguments for meter (need 2... see help file)"); 177 | input_check[4] = 0; 178 | } 179 | else { 180 | if (x->debug >= 1) post("meter = %d / %d", x->ri_mtr[x->ri_index][0], x->ri_mtr[x->ri_index][1]); 181 | input_check[4] = 1; 182 | } 183 | } 184 | //_____________________________________________________________________________ 185 | else if ( argvec[a].a_w.w_symbol == nt_articulation) { 186 | i = 0; 187 | while (argvec[a+1].a_type == A_FLOAT && a < argcount-1) { 188 | a++; 189 | x->ri_art[x->ri_index][i] = argvec[a].a_w.w_float; 190 | i++; 191 | } 192 | x->ri_art_n[x->ri_index] = i; 193 | if (x->debug >= 1) post("articulation = %d", x->ri_art_n[x->ri_index]);//if (x->debug >= 1) 194 | input_check[5] = 1; 195 | } 196 | //_____________________________________________________________________________ 197 | else if ( argvec[a].a_w.w_symbol == nt_tempo) { 198 | i = 0; 199 | while (argvec[a+1].a_type == A_FLOAT && a < argcount-1) { 200 | a++; 201 | x->ri_tmp[x->ri_index][i] = argvec[a].a_w.w_float; 202 | i++; 203 | } 204 | if (i != 2) { 205 | post("notes: ERROR: not enough arguments for tempo (need 2... see help file)"); 206 | input_check[6] = 0; 207 | } 208 | else { 209 | if (x->debug >= 1) post("tempo: %d = %d", x->ri_tmp[x->ri_index][0], x->ri_tmp[x->ri_index][1]); 210 | input_check[6] = 1; 211 | x->tempo = 1; 212 | } 213 | } 214 | //_____________________________________________________________________________ 215 | else if ( argvec[a].a_w.w_symbol == nt_small_numbers) { 216 | i = 0; 217 | while (argvec[a+1].a_type == A_FLOAT && a < argcount-1) { 218 | a++; 219 | x->ri_smn[x->ri_index][i] = argvec[a].a_w.w_float; 220 | if (x->debug >= 1) post("small number = %d", x->ri_smn[x->ri_index][i]); 221 | i++; 222 | } 223 | x->ri_smn_n[x->ri_index] = i; 224 | 225 | input_check[7] = 1; 226 | } 227 | //_____________________________________________________________________________ 228 | else if ( argvec[a].a_w.w_symbol == nt_clef) { 229 | i = 0; 230 | while (argvec[a+1].a_type == A_FLOAT && a < argcount-1) { 231 | a++; 232 | x->ri_clef[x->ri_index] = argvec[a].a_w.w_float; 233 | } 234 | if (x->debug >= 1) post("clef = %d", x->ri_clef[x->ri_index]); 235 | input_check[8] = 1; 236 | } 237 | //_____________________________________________________________________________ 238 | else if ( argvec[a].a_w.w_symbol == nt_accidentals) { 239 | i = 0; 240 | while (argvec[a+1].a_type == A_FLOAT && a < argcount-1) { 241 | a++; 242 | x->ri_acc[x->ri_index] = argvec[a].a_w.w_float; 243 | } 244 | if (x->ri_acc[x->ri_index] < 0) {x->ri_acc[x->ri_index] = 0; post("ERROR accidentals can only be 0 or 1");} 245 | else if (x->ri_acc[x->ri_index] > 1) {x->ri_acc[x->ri_index] = 1; post("ERROR accidentals can only be 0 or 1");} 246 | if (x->debug >= 1) post("accidentals = %d", x->ri_acc[x->ri_index]); 247 | input_check[9] = 1; 248 | } 249 | //_____________________________________________________________________________ 250 | else if ( argvec[a].a_w.w_symbol == nt_tremolo) { 251 | i = 0; 252 | while (argvec[a+1].a_type == A_FLOAT && a < argcount-1) { 253 | a++; 254 | x->ri_trm[x->ri_index] = argvec[a].a_w.w_float; 255 | } 256 | i=x->ri_trm[x->ri_index]; 257 | if(i==128||i==64||i==32||i==16||i==8) { 258 | if (x->debug >= 1) post("tremolo = %d", x->ri_trm[x->ri_index]); /// shouldn't this be trm instead of acc? 259 | input_check[10] = 1; 260 | } 261 | else { 262 | post("notes: ERROR: tremolo is %d, but it cannot be a different number than 16, 32, 64, etc...", x->ri_acc[x->ri_index]); 263 | post("notes: changing tremolo to default of 32"); 264 | x->ri_trm[x->ri_index] = 32; 265 | input_check[10] = 1; 266 | } 267 | } 268 | //_____________________________________________________________________________ 269 | else if ( argvec[a].a_w.w_symbol == nt_span) { 270 | i = 0; 271 | while (argvec[a+1].a_type == A_FLOAT && a < argcount-1) { 272 | a++; 273 | x->ri_spa[x->ri_index][i] = argvec[a].a_w.w_float; 274 | if ( x->ri_spa[x->ri_index][i] == 5 && argvec[a+1].a_type == A_FLOAT){ 275 | a++; 276 | x->ri_spa_p[x->ri_index] = argvec[a].a_w.w_float; 277 | } 278 | if (x->debug >= 1) post("span=%d", (int) x->ri_spa[x->ri_index][i]); 279 | i++; 280 | } 281 | x->ri_spa_n[x->ri_index] = i; 282 | input_check[11] = 1; 283 | } 284 | //_____________________________________________________________________________ 285 | else if ( argvec[a].a_w.w_symbol == nt_harppedal) { 286 | if (argvec[a+1].a_type == A_SYMBOL && a < argcount-1){ 287 | a++; 288 | atom_string(argvec+a, x->ri_hpp[x->ri_index], 1000); 289 | x->ri_hpp_n[x->ri_index] = 1; 290 | input_check[20] = 1; 291 | // post("pedal:"); 292 | // post(x->ri_hpp[x->ri_index]); 293 | } 294 | } 295 | //_____________________________________________________________________________ 296 | else if ( argvec[a].a_w.w_symbol == nt_text) { 297 | j = 0; 298 | x->ri_txt_n[x->ri_index] = x->ri_txt_spn_n[x->ri_index] = 0; 299 | for (i=0; i<5; i++) {x->ri_txt_spn[x->ri_index][i] = 0;} 300 | i = 0; 301 | if (argvec[a+1].a_type == A_FLOAT) { 302 | x->ri_txt_spn_n[x->ri_index] = 1; 303 | if (i==0) post("text_span!"); 304 | if (argvec[a+1].a_w.w_float == 0 && j == 0) { 305 | post("first element is 0"); 306 | x->ri_txt_spn[x->ri_index][0] = 1; 307 | j++; a++; 308 | while (argvec[a+1].a_type == A_SYMBOL && a < argcount-1 && i < 32) { 309 | if (argvec[a+1].a_w.w_symbol != nt_pitch && argvec[a+1].a_w.w_symbol != nt_rhythm 310 | && argvec[a+1].a_w.w_symbol != nt_dynamics && argvec[a+1].a_w.w_symbol != nt_tuplet 311 | && argvec[a+1].a_w.w_symbol != nt_meter && argvec[a+1].a_w.w_symbol != nt_articulation 312 | && argvec[a+1].a_w.w_symbol != nt_tempo && argvec[a+1].a_w.w_symbol != nt_small_numbers 313 | && argvec[a+1].a_w.w_symbol != nt_clef && argvec[a+1].a_w.w_symbol != nt_accidentals 314 | && argvec[a+1].a_w.w_symbol != nt_tremolo && argvec[a+1].a_w.w_symbol != nt_span 315 | && argvec[a+1].a_w.w_symbol != nt_grace && argvec[a+1].a_w.w_symbol != nt_harmonic 316 | && argvec[a+1].a_w.w_symbol != nt_noteheads) { 317 | a++; 318 | atom_string(argvec+a, x->ri_txt[x->ri_index][i], 1000); 319 | post(x->ri_txt[x->ri_index][i]); // if (x->debug >= 1) 320 | i++; 321 | } 322 | else break; 323 | } 324 | x->ri_txt_spn[x->ri_index][1] = i; 325 | if (argvec[a+1].a_w.w_float == 1 && j == 1) { 326 | post("second element is 1"); 327 | x->ri_txt_spn[x->ri_index][2] = 1; 328 | a++; j++; 329 | while (argvec[a+1].a_type == A_SYMBOL && a < argcount-1 && i < 32) { 330 | if (argvec[a+1].a_w.w_symbol != nt_pitch && argvec[a+1].a_w.w_symbol != nt_rhythm 331 | && argvec[a+1].a_w.w_symbol != nt_dynamics && argvec[a+1].a_w.w_symbol != nt_tuplet 332 | && argvec[a+1].a_w.w_symbol != nt_meter && argvec[a+1].a_w.w_symbol != nt_articulation 333 | && argvec[a+1].a_w.w_symbol != nt_tempo && argvec[a+1].a_w.w_symbol != nt_small_numbers 334 | && argvec[a+1].a_w.w_symbol != nt_clef && argvec[a+1].a_w.w_symbol != nt_accidentals 335 | && argvec[a+1].a_w.w_symbol != nt_tremolo && argvec[a+1].a_w.w_symbol != nt_span 336 | && argvec[a+1].a_w.w_symbol != nt_grace && argvec[a+1].a_w.w_symbol != nt_harmonic 337 | && argvec[a+1].a_w.w_symbol != nt_noteheads) { 338 | a++; 339 | atom_string(argvec+a, x->ri_txt[x->ri_index][i], 1000); 340 | post(x->ri_txt[x->ri_index][i]); // if (x->debug >= 1) 341 | i++; 342 | } 343 | else break; 344 | } 345 | x->ri_txt_spn[x->ri_index][3] = i; 346 | if (argvec[a+1].a_type == A_FLOAT && j == 2) { 347 | x->ri_txt_spn[x->ri_index][4] = argvec[a+1].a_w.w_float; 348 | post("third element is %d", x->ri_txt_spn[x->ri_index][4]); 349 | j++; 350 | } 351 | if (argvec[a+1].a_type == A_FLOAT && j == 3) { 352 | x->ri_txt_spn[x->ri_index][5] = argvec[a+1].a_w.w_float; 353 | post("fourth element is %d", x->ri_txt_spn[x->ri_index][5]); 354 | j++; 355 | } 356 | } 357 | } 358 | else if (argvec[a+1].a_w.w_float == 1 && j == 0) { 359 | x->ri_txt_spn[x->ri_index][0] = 2; 360 | post("SPAN END RECEIVED"); 361 | // x->ri_txt_n[x->ri_index] = 1; 362 | } 363 | else { 364 | post("ERROR: if you start a -txt with a number, it has to be 0 to start a text span or 1 to end it."); 365 | } 366 | } 367 | else { 368 | while (argvec[a+1].a_type == A_SYMBOL && a < argcount-1 && i < 32) { 369 | if (argvec[a+1].a_w.w_symbol != nt_pitch && argvec[a+1].a_w.w_symbol != nt_rhythm 370 | && argvec[a+1].a_w.w_symbol != nt_dynamics && argvec[a+1].a_w.w_symbol != nt_tuplet 371 | && argvec[a+1].a_w.w_symbol != nt_meter && argvec[a+1].a_w.w_symbol != nt_articulation 372 | && argvec[a+1].a_w.w_symbol != nt_tempo && argvec[a+1].a_w.w_symbol != nt_small_numbers 373 | && argvec[a+1].a_w.w_symbol != nt_clef && argvec[a+1].a_w.w_symbol != nt_accidentals 374 | && argvec[a+1].a_w.w_symbol != nt_tremolo && argvec[a+1].a_w.w_symbol != nt_span 375 | && argvec[a+1].a_w.w_symbol != nt_grace && argvec[a+1].a_w.w_symbol != nt_harmonic 376 | && argvec[a+1].a_w.w_symbol != nt_noteheads) { 377 | a++; 378 | if (i==0) if (x->debug >= 1) post("regular text"); 379 | atom_string(argvec+a, x->ri_txt[x->ri_index][i], 1000); 380 | if (x->debug >= 1) post(x->ri_txt[x->ri_index][i]); 381 | i++; 382 | } 383 | else break; 384 | } 385 | } 386 | x->ri_txt_n[x->ri_index] = i; // 387 | if (x->ri_txt_n[x->ri_index] >= 1) input_check[15] = 1; 388 | if (x->ri_txt_spn_n[x->ri_index] >= 1) input_check[16] = 1; 389 | if (x->debug >= 1) post("text n = %d", x->ri_txt_n[x->ri_index]); 390 | } 391 | //_____________________________________________________________________________ 392 | else if ( argvec[a].a_w.w_symbol == nt_grace) { 393 | i = 0; 394 | if (x->debug >= 1) post ("GRACE!"); 395 | while (argvec[a+1].a_type == A_FLOAT && a < argcount-1) { 396 | a++; 397 | x->ri_grc[x->ri_index][i] = argvec[a].a_w.w_float; 398 | i++; 399 | } 400 | if (x->ri_grc[x->ri_index][0] < 0) x->ri_grc[x->ri_index][0] = 0; 401 | if (x->ri_grc[x->ri_index][0] > 3) x->ri_grc[x->ri_index][0] = 3; 402 | if (x->ri_grc[x->ri_index][1] == 0) { 403 | post("grace duration == 0, this is a bug, fix me"); 404 | x->ri_grc[x->ri_index][1] = 32; 405 | } 406 | 407 | i=x->ri_grc[x->ri_index][1]; 408 | if(i==128||i==64||i==32||i==16||i==8) { 409 | if (x->debug >= 1) post("grace = %d", i); 410 | input_check[12] = 1; 411 | } 412 | else { 413 | post("notes: ERROR: grace is %d, but it cannot be a different number than 8, 16, 32, 64, or 128", i); 414 | post("notes: changing grace duration to default of 32"); 415 | x->ri_grc[x->ri_index][1] = 32; 416 | input_check[12] = 1; 417 | } 418 | } 419 | //_____________________________________________________________________________ 420 | else if ( argvec[a].a_w.w_symbol == nt_harmonic) { 421 | i = 0; 422 | 423 | while (argvec[a+1].a_type == A_FLOAT && a < argcount-1) { 424 | a++; 425 | x->ri_hrm[x->ri_index][i] = argvec[a].a_w.w_float; 426 | 427 | i++; 428 | } 429 | x->ri_hrm_n[x->ri_index] = i; 430 | for (i=0; iri_hrm_n[x->ri_index]; i++){ 431 | if (x->ri_hrm[x->ri_index][i]<=0) {x->ri_hrm[x->ri_index][i] = 1;post("ERROR, you asked for %d, but only harmonics 1 through 5 are allowed", x->ri_hrm[x->ri_index][i]);} 432 | else if (x->ri_hrm[x->ri_index][i]> 6) {x->ri_hrm[x->ri_index][i] = 6;post("ERROR, you asked for %d, but only harmonics 1 through 5 are allowed", x->ri_hrm[x->ri_index][i]);} 433 | if (x->debug >= 1) post ("HARMONIC! %d", x->ri_hrm[x->ri_index][i]); 434 | } 435 | // post("harmonic = %d", x->ri_hrm_n[x->ri_index]);//if (x->debug >= 1) 436 | input_check[13] = 1; 437 | } 438 | //_____________________________________________________________________________ 439 | else if ( argvec[a].a_w.w_symbol == nt_noteheads) { 440 | i = 0; 441 | if (x->debug >= 1) post ("NOTE HEADS!"); 442 | while (argvec[a+1].a_type == A_FLOAT && a < argcount-1) { 443 | a++; 444 | x->ri_nhs[x->ri_index][i] = argvec[a].a_w.w_float; 445 | i++; 446 | } 447 | x->ri_nhs_n[x->ri_index] = i; 448 | if (x->debug >= 1) post("noteheads = %d", x->ri_art_n[x->ri_index]);//if (x->debug >= 1) 449 | input_check[14] = 1; 450 | } 451 | //_____________________________________________________________________________ 452 | else if ( argvec[a].a_w.w_symbol == nt_tie) { 453 | if (argvec[a+1].a_type == A_FLOAT && a < argcount-1) { 454 | a++; 455 | x->ri_tie[x->ri_index] = argvec[a].a_w.w_float; 456 | if (x->debug >= 1) post("tie = %d", x->ri_tie[x->ri_index]); 457 | } 458 | input_check[17] = 1; 459 | } 460 | //_____________________________________________________________________________ 461 | else if ( argvec[a].a_w.w_symbol == nt_arpeggio) { 462 | if (argvec[a+1].a_type == A_FLOAT && a < argcount-1) { 463 | a++; 464 | x->ri_arp[x->ri_index] = argvec[a].a_w.w_float; 465 | if (x->debug >= 1) post("arp = %d", x->ri_arp[x->ri_index]); 466 | } 467 | input_check[19] = 1; 468 | } 469 | //_____________________________________________________________________________ 470 | else if ( argvec[a].a_w.w_symbol == nt_cluster) { 471 | if (argvec[a+1].a_type == A_FLOAT && a < argcount-1) { 472 | a++; 473 | x->ri_clu[x->ri_index] = argvec[a].a_w.w_float; 474 | if (x->debug >= 1) post("tuplet = %d", x->ri_clu[x->ri_index]); 475 | } 476 | input_check[18] = 1; 477 | } 478 | //_____________________________________________________________________________ 479 | else if (argvec[a].a_type == A_FLOAT) post("WARNING::::::: this float escaped: %f", argvec[a].a_w.w_float); 480 | } 481 | } 482 | // post("INPUT CHECKs"); 483 | ////CHECK INPUT 484 | if (input_check[0] == 0) { // if no pitch value is provided then the previous one is kept. 485 | if (x->ri_index == 0) { 486 | x->ri_pit[x->ri_index][0] = 60; 487 | x->ri_cho[x->ri_index] = 1; 488 | } 489 | else { 490 | for (i = 0; i < x->ri_cho[x->ri_index - 1]; i++) { 491 | x->ri_pit[x->ri_index][i] = x->ri_pit[x->ri_index - 1][i]; 492 | } 493 | x->ri_cho[x->ri_index] = x->ri_cho[x->ri_index - 1]; 494 | } 495 | } // Pitch 496 | if (input_check[1] == 0) { // if no rhythmic value is provided then the previous one is kept. 497 | if (x->ri_index == 0) x->ri_dur[x->ri_index] = 8; 498 | else x->ri_dur[x->ri_index] = x->ri_dur[x->ri_index - 1]; 499 | } // Duration 500 | if (input_check[2] == 0) { 501 | x->ri_dyn_n[x->ri_index] = 0; 502 | } // Dynamics 503 | if (input_check[3] == 0) { 504 | x->ri_tup[x->ri_index][0] = x->ri_tup[x->ri_index][1] = x->ri_tup[x->ri_index][2] = 0; 505 | } // Tuplet 506 | if (input_check[4] == 0) { 507 | if (x->ri_index == 0) { 508 | x->ri_mtr[x->ri_index][0] = 4; 509 | x->ri_mtr[x->ri_index][1] = 4; 510 | } 511 | else { 512 | x->ri_mtr[x->ri_index][0] = x->ri_mtr[x->ri_index-1][0]; 513 | x->ri_mtr[x->ri_index][1] = x->ri_mtr[x->ri_index-1][1]; 514 | } 515 | } // Meter 516 | if (input_check[5] == 0) { 517 | x->ri_art_n[x->ri_index] = 0; 518 | } // Articulation 519 | if (input_check[6] == 0) { 520 | if (x->ri_index == 0) { 521 | x->ri_tmp[x->ri_index][0] = 8; 522 | x->ri_tmp[x->ri_index][1] = 60; 523 | } 524 | else { 525 | x->ri_tmp[x->ri_index][0] = x->ri_tmp[x->ri_index-1][0]; 526 | x->ri_tmp[x->ri_index][1] = x->ri_tmp[x->ri_index-1][1]; 527 | } 528 | // post("wrote tempo"); 529 | } // Tempo 530 | if (input_check[7] == 0) { 531 | x->ri_smn_n[x->ri_index] = 0; 532 | // post("no small numbers"); 533 | } // small numbers 534 | if (input_check[8] == 0) { 535 | if (x->ri_index == 0) { 536 | x->ri_clef[x->ri_index] = 0; 537 | } 538 | else { 539 | x->ri_clef[x->ri_index] = x->ri_clef[x->ri_index-1]; 540 | } 541 | // post("wrote clef"); 542 | } // Clef 543 | if (input_check[9] == 0) { 544 | if (x->ri_index == 0) { 545 | x->ri_acc[x->ri_index] = 0; 546 | } 547 | else { 548 | x->ri_acc[x->ri_index] = x->ri_acc[x->ri_index-1]; 549 | } 550 | // post("wrote clef"); 551 | } // accidentals 552 | if (input_check[10] == 0) { 553 | x->ri_trm[x->ri_index] = 0; 554 | // post("wrote tremolo"); 555 | } // tremolo 556 | if (input_check[11] == 0) { 557 | x->ri_spa_n[x->ri_index] = 0; 558 | } // Spans 559 | if (input_check[12] == 0) { 560 | x->ri_grc[x->ri_index][0] = 0; 561 | } // grace notes 562 | if (input_check[13] == 0) { 563 | x->ri_hrm_n[x->ri_index] = 0; 564 | } // harmonics 565 | if (input_check[14] == 0) { 566 | x->ri_nhs_n[x->ri_index] = 0; 567 | } // note heads 568 | if (input_check[15] == 0) { 569 | x->ri_txt_n[x->ri_index] = 0; 570 | } // text 571 | if (input_check[16] == 0) { 572 | x->ri_txt_spn_n[x->ri_index] = 0; 573 | } // text span 574 | if (input_check[17] == 0) { 575 | x->ri_tie[x->ri_index] = 0; 576 | } // tie 577 | if (input_check[18] == 0) { 578 | x->ri_clu[x->ri_index] = 0; 579 | } // cluster 580 | if (input_check[19] == 0) { 581 | x->ri_arp[x->ri_index] = 0; 582 | } // arpeggio 583 | if (input_check[20] == 0) { 584 | x->ri_hpp_n[x->ri_index] = 0; 585 | } // harp-pedal 586 | x->ri_index++; 587 | } 588 | //// ____________________________________________________ WRITE 589 | void notes_write(t_notes *x, t_symbol *s) { 590 | int i, j, k, barcount, barsize, beatsize, dur_remainder, bar_number, beatcount, beat_number, sub_beatsize, subdiv; 591 | int pow2dot_array[18] = {0, 1, 2, 3, 4, 6, 8, 12, 16, 24, 32, 48, 64, 96, 128, 192, 256, 384}; 592 | int harmonics[6][2] = { {12, 12}, {7, 19}, {5, 24}, {4, 28}, {3, 31}, {2, 34}}; 593 | float temp_f=0;//, temp_f2; 594 | bar_number=beatcount=barcount=dur_remainder=beat_number = j= i=k= 0; 595 | x->sb_tp_index = x->i_index = x->tp_index = x->tp_n = x->b_index = x->be_index = x->sb_index = 0; 596 | 597 | if (x->ri_index > 0) { 598 | post("notes: Generating Score ..."); 599 | //// ____________________________________________________________ INPUT SORTING 600 | if (x->debug >= 1) { 601 | post("\nRAW INPUT LIST :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::\n"); 602 | post("i\tdur\ttup\ttup\ttup\tmtr\tmtr"); 603 | } 604 | for(i=0; iri_index; i++) { 605 | if (x->ri_cho[i] == 1 && x->ri_pit[i][0] < 0){ 606 | temp_f = -1000; 607 | for (j=i; j>0; j--) { 608 | if (x->ri_pit[j][0] > 0) temp_f = x->ri_pit[j][0]; 609 | } 610 | if (temp_f == -1000) { 611 | for (j=i; jri_index; j++) { 612 | if (x->ri_pit[j][0] > 0) temp_f = x->ri_pit[j][0]; 613 | } 614 | } 615 | if (temp_f == -1000) post("notes: all pitches are negative you should know..."); 616 | else x->ri_pit[x->ri_index][0] = temp_f; 617 | } 618 | if (x->debug >= 1) post("%d\t%d\t%d\t%d\t%d\t%d\t%d\t rawrawraw1", i, (int) x->ri_dur[i], x->ri_tup[i][0], x->ri_tup[i][1], x->ri_tup[i][2], x->ri_mtr[i][0], x->ri_mtr[i][1]); 619 | } 620 | post("notes: Sorting Input ..."); 621 | if (x->debug >= 1) { 622 | post("\nSORTING INPUT :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::\n"); 623 | } 624 | x->tp_index = x->tp_n = 0; 625 | 626 | // SORT INTO TUPLETS, GRACE NOTES, AND REGULAR NOTES 627 | for(i=0; iri_index; i++) { 628 | if (x->ri_tup[i][0] != 0) { 629 | //if (x->debug >= 3) 630 | if (x->debug >= 1) post("TUP"); 631 | x->ri_index_sort[i] = 2; 632 | x->tp_info[x->tp_n][0] = x->ri_tup[i][0]; // reference beat duration 633 | x->tp_info[x->tp_n][1] = x->ri_tup[i][1]; // fit 634 | x->tp_info[x->tp_n][2] = x->ri_tup[i][2]; // into 635 | x->tp_info[x->tp_n][3] = i; // starting tp index************ 636 | 637 | x->i_mtr[x->i_index][0] = x->ri_mtr[i][0]; 638 | x->i_mtr[x->i_index][1] = x->ri_mtr[i][1]; 639 | x->i_tup[x->i_index] = x->tp_n; 640 | x->i_dur[x->i_index] = x->refdur/x->ri_tup[i][0] * x->ri_tup[i][2]; //(added / refdur 641 | x->i_tie[x->i_index] = 0; 642 | dur_remainder = x->refdur/x->ri_tup[i][0] * x->ri_tup[i][1]; 643 | x->i_rii[x->i_index] = i; 644 | 645 | x->tp_i[x->tp_index] = x->i_index; // reference to clean/precessed input or just "input" 646 | x->tp_ri[x->tp_index] = i; // reference to raw input indexes 647 | x->tp_dur[x->tp_index] = x->ri_dur[i]; 648 | x->tp_num[x->tp_index] = x->tp_n; 649 | beatcount = x->tp_dur[x->tp_index]; 650 | //post("a"); 651 | x->tp_index++; 652 | if (x->debug >= 1) post("PRE While Fx: beatcount=%d\tdur_remainder=%d", beatcount, dur_remainder); 653 | while ( (beatcount + x->ri_dur[i+1]) <= dur_remainder && i < x->ri_index && beatcount-dur_remainder !=0) { 654 | i++; 655 | if (x->ri_grc[i][0] > 0) { 656 | if (x->debug >= 1) post("GRACE"); 657 | x->ri_index_sort[i] = 3; 658 | x->g_rii[x->i_index] = i; 659 | x->g_dur[x->i_index] = x->ri_grc[i][1]; 660 | x->g_index++; 661 | } //// GRACE NOTES 662 | else { 663 | x->tp_i[x->tp_index] = x->i_index; // reference to clean/precessed input or just "input" 664 | x->tp_ri[x->tp_index] = i; // reference to raw input indexes 665 | x->ri_index_sort[i] = 1; 666 | x->tp_dur[x->tp_index] = x->ri_dur[i]; 667 | x->tp_tie[x->tp_index] = 0; 668 | x->tp_num[x->tp_index] = x->tp_n; 669 | beatcount += x->tp_dur[x->tp_index]; 670 | x->tp_index++; 671 | } 672 | // post("b"); 673 | } 674 | x->i_index++; 675 | if (x->debug >= 1) post("POST While Fx: beatcount=%d\tdur_remainder=%d", beatcount, dur_remainder); 676 | if (beatcount < dur_remainder) { 677 | post("¡¡¡¡¡¡¡WARNING!!!!!! Tuplet no. %d has a longer duration than declared length, tied to regular beat", x->tp_n); 678 | 679 | i++; 680 | x->tp_i[x->tp_index] = x->i_index; // reference to clean/precessed input or just "input" 681 | x->tp_ri[x->tp_index] = i; // reference to raw input indexes 682 | x->tp_dur[x->tp_index] = dur_remainder - beatcount; 683 | x->tp_tie[x->tp_index] = 1; 684 | x->tp_num[x->tp_index] = x->tp_n; 685 | 686 | x->i_mtr[x->i_index][0] = x->i_mtr[x->i_index-1][0]; 687 | x->i_mtr[x->i_index][1] = x->i_mtr[x->i_index-1][1]; 688 | x->i_dur[x->i_index] = x->ri_dur[i] - x->tp_dur[x->tp_index]; 689 | x->i_rii[x->i_index] = i; 690 | x->i_tie[x->i_index] = 1; 691 | x->i_tup[x->i_index] = -1; 692 | // x->tp_info[x->tp_n][4] = x->tp_index; // ending tp index 693 | //post("c"); 694 | x->i_index++; 695 | x->tp_index++; 696 | } 697 | x->tp_info[x->tp_n][4] = i; // ending tp index 698 | x->tp_n++; 699 | } //// TUPLETS 700 | else if (x->ri_grc[i][0] > 0) { 701 | // if (x->debug >= 3) 702 | if (x->debug >= 1) post("GRACE"); 703 | x->ri_index_sort[i] = 3; 704 | x->g_rii[x->i_index] = i; 705 | x->g_dur[x->i_index] = x->ri_grc[i][1]; 706 | x->g_index++; 707 | } //// GRACE NOTES 708 | else { 709 | //if (x->debug >= 3) 710 | if (x->debug >= 1) post("NO TUP"); 711 | x->ri_index_sort[i] = 2; 712 | x->i_mtr[x->i_index][0] = x->ri_mtr[i][0]; 713 | x->i_mtr[x->i_index][1] = x->ri_mtr[i][1]; 714 | x->i_dur[x->i_index] = x->ri_dur[i]; 715 | x->i_tie[x->i_index] = x->ri_tie[i]; 716 | x->i_rii[x->i_index] = i; 717 | x->i_tup[x->i_index] = -1; 718 | x->i_index++; 719 | } //// REGULAR NOTES 720 | } 721 | if (x->debug >= 1) post("INPUT TYPES\t(1:normal, 2:tuplet, 3:grace)\nrawi\ttype"); 722 | for (i=0; iri_index; i++) { 723 | if (x->debug >= 1) post("%d\t%d", i, x->ri_index_sort[i]); 724 | } 725 | //// ____________________________________________________________ GRACE PROGRAM 726 | for(i=0; ig_index; i++){ 727 | 728 | } 729 | //// ____________________________________________________________ TUPLET PROGRAM 730 | if (x->debug >= 1) { 731 | post("\nRAW TUPLET INFO :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::\n"); 732 | post("i\trefdur\tfit\tinto\tstart\tend"); 733 | } 734 | if (x->tp_n == 0) post("no tuplets!"); 735 | for(i=0; itp_n; i++) { 736 | if (x->debug >= 1) post("%d\t%d\t%d\t%d\t%d\t%d", i, x->tp_info[i][0], x->tp_info[i][1], x->tp_info[i][2], x->tp_info[i][3], x->tp_info[i][4]); 737 | } 738 | if (x->debug >= 1) { 739 | post("\nRAW TUPLET LIST :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::\n"); 740 | post("i\ttp_n\traw_i\tclean_i\tdur\ttie"); 741 | } 742 | x->b_tp_index = x->tp_index; 743 | for(i=0; itp_index; i++) { 744 | if (x->tp_num[i] != x->tp_num[i-1]) post("- - - - - - - - - - - - "); 745 | if (x->debug >= 1) post("%d\t%d\t%d\t%d\t%d\t%d", i, x->tp_num[i], x->tp_ri[i], x->tp_i[i], (int) x->tp_dur[i], x->tp_tie[i]); 746 | x->b_tp_dur[i] = x->tp_dur[i]; 747 | x->b_tp_ri[i] = x->tp_ri[i]; 748 | x->b_tp_i[i] = x->tp_i[i]; 749 | x->b_tp_tie[i] = x->tp_tie[i]; 750 | x->b_tp_num[i] = x->tp_num[i]; 751 | } /// RAW TUPLET LIST 752 | if (x->debug >= 1) { 753 | post("\nSORTING TUPLET RHYTHMS :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::\n"); 754 | } 755 | if (x->tp_n > 0) { 756 | for (k=0; k<4; k++) { 757 | beatcount = 0; 758 | subdiv = (int) exp2( (float) k ); 759 | if (x->debug >= 3) post("subdiv=%d", subdiv); 760 | beatsize = x->refdur/x->tp_info[0][0]; // i.e. 32 / 16 761 | sub_beatsize = beatsize / subdiv; 762 | if (sub_beatsize <= 2) break; 763 | x->sb_tp_index = 0; 764 | if (x->debug >= 3) post("beatsize=%d\tsubdiv=%d\tsub_beatsize=%d", beatsize, subdiv, sub_beatsize); 765 | i = 0; 766 | if (x->debug >= 3) post("%d 1*************** TUPLET %d *************** %d", i, i, i); 767 | for(i=0; ib_tp_index; i++) { 768 | while (beatcount >= beatsize) { 769 | beatcount -= beatsize; 770 | } 771 | if (i>0 && x->b_tp_num[i] != x->b_tp_num[i-1]) { 772 | if (x->debug >= 3) post("CASE 1"); 773 | if (x->debug >= 3) post("%d 2*************** TUPLET %d *************** %d", x->b_tp_num[i], x->b_tp_num[i], x->b_tp_num[i]); 774 | beatsize = x->tp_info[x->b_tp_num[i]][0]; 775 | sub_beatsize = beatsize / subdiv; 776 | if (x->debug >= 3) post("beatsize=%d\tsubdiv=%d\tsub_beatsize=%d", beatsize, subdiv, sub_beatsize); 777 | beatcount = 0; 778 | } 779 | if (sub_beatsize >= 4) { 780 | // if (x->debug >= 3) post("CASE 2"); 781 | if (((beatcount + x->b_tp_dur[i]) <= sub_beatsize)) { 782 | if (x->debug >= 3) post("CASE 2.1\tsub_beatsize=\t%d\tbeatcount=\t%d", sub_beatsize, beatcount); 783 | x->sb_tp_dur[x->sb_tp_index] = x->b_tp_dur[i]; 784 | x->sb_tp_ri[x->sb_tp_index] = x->b_tp_ri[i]; 785 | x->sb_tp_i[x->sb_tp_index] = x->b_tp_i[i]; 786 | x->sb_tp_tie[x->sb_tp_index] = x->b_tp_tie[i]; 787 | x->sb_tp_num[x->sb_tp_index] = x->b_tp_num[i]; 788 | if (x->debug >= 3) post("%d\t%d\t%d\t%d\t%d\t%d", x->sb_tp_index, x->sb_tp_num[x->sb_tp_index], x->sb_tp_ri[x->sb_tp_index], x->sb_tp_i[x->sb_tp_index], x->sb_tp_dur[x->sb_tp_index], x->sb_tp_tie[x->sb_tp_index]); 789 | beatcount += x->b_tp_dur[i]; 790 | while (beatcount >= sub_beatsize) { 791 | beatcount -= sub_beatsize; 792 | } 793 | if (x->debug >= 3 && beatcount % beatsize == 0) post("- - - - - - - - - - - - "); 794 | x->sb_tp_index++; 795 | } 796 | else if ((beatcount == 0) && ((x->b_tp_dur[i] % sub_beatsize) == 0)) { 797 | if (x->debug >= 3) post("CASE 2.2\tsub_beatsize=\t%d\tbeatcount=\t%d", sub_beatsize, beatcount); 798 | for(j=0; j<32; j++){ 799 | if (x->tp_dur[i] == sub_beatsize * j) { 800 | x->sb_tp_dur[x->sb_tp_index] = x->b_tp_dur[i]; 801 | x->sb_tp_ri[x->sb_tp_index] = x->b_tp_ri[i]; 802 | x->sb_tp_i[x->sb_tp_index] = x->b_tp_i[i]; 803 | x->sb_tp_tie[x->sb_tp_index] = x->b_tp_tie[i]; 804 | x->sb_tp_num[x->sb_tp_index] = x->b_tp_num[i]; 805 | if (x->debug >= 3) post("%d\t%d\t%d\t%d\t%d\t%d", x->sb_tp_index, x->sb_tp_num[x->sb_tp_index], x->sb_tp_ri[x->sb_tp_index], x->sb_tp_i[x->sb_tp_index], x->sb_tp_dur[x->sb_tp_index], x->sb_tp_tie[x->sb_tp_index]); 806 | beatcount += x->b_tp_dur[i]; 807 | while (beatcount >= sub_beatsize) { 808 | beatcount -= sub_beatsize; 809 | } 810 | if (x->debug >= 3 && beatcount % beatsize == 0) post("- - - - - - - - - - - - "); 811 | x->sb_tp_index++; 812 | break; 813 | } 814 | } 815 | } 816 | else if (sub_beatsize == beatcount || (sub_beatsize + x->b_tp_dur[i]) == beatcount) { 817 | if (x->debug >= 3) post("CASE 2.3\tsub_beatsize=\t%d\tbeatcount=\t%d", sub_beatsize, beatcount); 818 | x->sb_tp_dur[x->sb_tp_index] = x->b_tp_dur[i]; 819 | x->sb_tp_ri[x->sb_tp_index] = x->b_tp_ri[i]; 820 | x->sb_tp_i[x->sb_tp_index] = x->b_tp_i[i]; 821 | x->sb_tp_tie[x->sb_tp_index] = x->b_tp_tie[i]; 822 | x->sb_tp_num[x->sb_tp_index] = x->b_tp_num[i]; 823 | if (x->debug >= 3) post("%d\t%d\t%d\t%d\t%d\t%d", x->sb_tp_index, x->sb_tp_num[x->sb_tp_index], x->sb_tp_ri[x->sb_tp_index], x->sb_tp_i[x->sb_tp_index], x->sb_tp_dur[x->sb_tp_index], x->sb_tp_tie[x->sb_tp_index]); 824 | beatcount += x->b_tp_dur[i]; 825 | while (beatcount >= sub_beatsize) { 826 | beatcount -= sub_beatsize; 827 | } 828 | if (x->debug >= 3 && beatcount % beatsize == 0) post("- - - - - - - - - - - - "); 829 | x->sb_tp_index++; 830 | } 831 | else { 832 | if (x->debug >= 3) post("CASE 2.4\tsub_beatsize=\t%d\tbeatcount=\t%d", sub_beatsize, beatcount); 833 | if (sub_beatsize != beatcount) { 834 | if (x->debug >= 3) post("CASE 2.4.1"); 835 | x->sb_tp_dur[x->sb_tp_index] = abs(sub_beatsize - beatcount); 836 | x->sb_tp_ri[x->sb_tp_index] = x->b_tp_ri[i]; 837 | x->sb_tp_i[x->sb_tp_index] = x->b_tp_i[i]; 838 | x->sb_tp_tie[x->sb_tp_index] = 1; 839 | x->sb_tp_num[x->sb_tp_index] = x->b_tp_num[i]; 840 | if (x->debug >= 3) {post("%d\t%d\t%d\t%d\t%d\t%d", x->sb_tp_index, x->sb_tp_num[x->sb_tp_index], x->sb_tp_ri[x->sb_tp_index], x->sb_tp_i[x->sb_tp_index], x->sb_tp_dur[x->sb_tp_index], x->sb_tp_tie[x->sb_tp_index]); post("- - - - - - - - - - - - ");} 841 | x->sb_tp_index++; 842 | dur_remainder = x->b_tp_dur[i] - x->sb_tp_dur[x->sb_tp_index-1]; 843 | } 844 | else { 845 | if (x->debug >= 3) post("CASE 2.4.2~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"); 846 | dur_remainder = x->b_tp_dur[i]; 847 | } 848 | while (dur_remainder > sub_beatsize) { 849 | x->sb_tp_dur[x->sb_tp_index] = sub_beatsize; 850 | x->sb_tp_ri[x->sb_tp_index] = x->b_tp_ri[i]; 851 | x->sb_tp_i[x->sb_tp_index] = x->b_tp_i[i]; 852 | x->sb_tp_tie[x->sb_tp_index] = 1; 853 | x->sb_tp_num[x->sb_tp_index] = x->b_tp_num[i]; 854 | 855 | if (x->debug >= 3){ post("%d\t%d\t%d\t%d\t%d\t%d", x->sb_tp_index, x->sb_tp_num[x->sb_tp_index], x->sb_tp_ri[x->sb_tp_index], x->sb_tp_i[x->sb_tp_index], x->sb_tp_dur[x->sb_tp_index], x->sb_tp_tie[x->sb_tp_index]); post("- - - - - - - - - - - - ");} 856 | x->sb_tp_index++; 857 | 858 | dur_remainder -= sub_beatsize; 859 | } 860 | 861 | x->sb_tp_dur[x->sb_tp_index] = dur_remainder; 862 | x->sb_tp_ri[x->sb_tp_index] = x->b_tp_ri[i]; 863 | x->sb_tp_i[x->sb_tp_index] = x->b_tp_i[i]; 864 | x->sb_tp_tie[x->sb_tp_index] = x->b_tp_tie[i]; 865 | x->sb_tp_num[x->sb_tp_index] = x->b_tp_num[i]; 866 | 867 | beatcount += x->b_tp_dur[i]; 868 | while (beatcount >= sub_beatsize) { 869 | beatcount -= sub_beatsize; 870 | } 871 | if (x->debug >= 3)post("%d\t%d\t%d\t%d\t%d\t%d", x->sb_tp_index, x->sb_tp_num[x->sb_tp_index], x->sb_tp_ri[x->sb_tp_index], x->sb_tp_i[x->sb_tp_index], x->sb_tp_dur[x->sb_tp_index], x->sb_tp_tie[x->sb_tp_index]); 872 | if (x->debug >= 3 && beatcount % beatsize == 0) post("- - - - - - - - - - - - "); 873 | x->sb_tp_index++; 874 | } 875 | } 876 | else { 877 | if (x->debug >= 3) post("CASE else"); 878 | x->sb_tp_dur[x->sb_tp_index] = x->b_tp_dur[i]; 879 | x->sb_tp_ri[x->sb_tp_index] = x->b_tp_ri[i]; 880 | x->sb_tp_i[x->sb_tp_index] = x->b_tp_i[i]; 881 | x->sb_tp_tie[x->sb_tp_index] = x->b_tp_tie[i]; 882 | x->sb_tp_num[x->sb_tp_index] = x->b_tp_num[i]; 883 | if (x->debug >= 3) post("%d\t%d\t%d\t%d\t%d\t%d", x->sb_tp_index, x->sb_tp_num[x->sb_tp_index], x->sb_tp_ri[x->sb_tp_index], x->sb_tp_i[x->sb_tp_index], x->sb_tp_dur[x->sb_tp_index], x->sb_tp_tie[x->sb_tp_index]); 884 | beatcount += x->b_tp_dur[i]; 885 | if (x->debug >= 3 && beatcount % beatsize == 0) post("- - - - - - - - - - - - "); 886 | x->sb_tp_index++; 887 | } 888 | 889 | } 890 | for(i=0; isb_tp_index; i++){ 891 | x->b_tp_dur[i] = x->sb_tp_dur[i]; 892 | x->b_tp_ri[i] = x->sb_tp_ri[i]; 893 | x->b_tp_i[i] = x->sb_tp_i[i]; 894 | x->b_tp_tie[i] = x->sb_tp_tie[i]; 895 | x->b_tp_num[i] = x->sb_tp_num[i]; 896 | } 897 | x->b_tp_index = x->sb_tp_index; 898 | } 899 | } 900 | if (x->debug >= 1) { 901 | post("\nFINAL TUPLET LIST :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::\n"); 902 | post("i\ttp_n\traw_i\tclean_i\tdur\ttie"); 903 | } 904 | post("subbeat index = %d", x->sb_tp_index); 905 | for(i=0; isb_tp_index; i++) { 906 | if (x->sb_tp_num[i] != x->sb_tp_num[i-1]) if (x->debug >= 1) post("- - - - - - - - - - - - "); 907 | if (x->debug >= 1) post("%d\t%d\t%d\t%d\t%d\t%d", i, x->sb_tp_num[i], x->sb_tp_ri[i], x->sb_tp_i[i], (int) x->sb_tp_dur[i], x->sb_tp_tie[i]); 908 | } 909 | 910 | //// ____________________________________________________________ BAR and BEAT Programs 911 | if (x->debug >= 1) { 912 | post("\nCLEAN INPUT LIST :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::\n"); 913 | post("i\traw_i\tdur\ttie\ttup"); 914 | } 915 | for(i=0; ii_index; i++) { 916 | if (x->debug >= 1) post("%d\t%d\t%d\t%d\t%d", i, x->i_rii[i], (int) x->i_dur[i], x->i_tie[i], x->i_tup[i]); 917 | if ( x->i_tup[i] >= 0) { 918 | if (x->debug >= 1) post("Tuplet will replace last line"); 919 | } 920 | } 921 | // /* 922 | //// ____________________________________________________________ BAR SUBDIVISION 923 | if (x->debug >= 1) post(".\nBAR PROGRAMs ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::\n."); 924 | /////////////////////// BREAK INPUT INTO BARS 925 | int ii; 926 | if (x->FOLLOW == 0) { 927 | beatsize = exp2f( (float) (log2f((float) x->refdur) - log2f((float) x->i_mtr[0][1]))); 928 | barsize = (int) x->i_mtr[0][0] * beatsize; 929 | x->bar_info[0][0] = 0; 930 | x->bar_info[0][1] = x->i_mtr[0][0]; 931 | x->bar_info[0][2] = x->i_mtr[0][1]; 932 | x->bar_info[0][3] = beatsize; 933 | x->bar_info[0][4] = barsize; 934 | if (x->debug >= 1) { 935 | post("num=%d", (int) x->i_mtr[0][0]); 936 | post("refdur=%d denom=%d beatsize=%d", x->refdur, x->i_mtr[0][1], beatsize); 937 | post("barsize=%d\n", barsize); 938 | post("i\tbar no.\tclean i\traw i\tdur\ttie\ttuplet"); 939 | post("BAR %d - - - - - - - - - - - - - - - - - - - - - - - - - - - - ", bar_number); 940 | } 941 | barcount = 0; 942 | for(i=0; ii_index; i++) { 943 | if (i > 1 && (x->i_mtr[i][0] != x->i_mtr[i-1][0] || x->i_mtr[i][1] != x->i_mtr[i-1][1])) { 944 | if (barcount != 0) { 945 | x->bar_info[bar_number][1] = barcount; 946 | x->bar_info[bar_number][2] = 32; 947 | temp_f = reduce_meter(x->bar_info[bar_number][1]); 948 | if (temp_f != 0) { 949 | x->bar_info[bar_number][1] = (int) temp_f; 950 | temp_f = ((temp_f - (int) temp_f) * 100.) + 0.02; 951 | x->bar_info[bar_number][2] = (int) temp_f; 952 | } 953 | beatsize = exp2f( (float) (log2f((float) x->refdur) - log2f((float) x->bar_info[bar_number][2]))); 954 | barsize = (int) x->bar_info[bar_number][1] * beatsize; 955 | beatsize = get_beatsize(x->bar_info[bar_number][1], x->bar_info[bar_number][2], x->refdur); 956 | x->bar_info[bar_number][3] = beatsize; 957 | x->bar_info[bar_number][4] = barsize; 958 | if (x->debug >= 1) post("Meter change::: %d / %d", x->bar_info[bar_number][1], x->bar_info[bar_number][2]); 959 | bar_number++; 960 | x->bar_info[bar_number][0] = x->b_index; 961 | if (x->debug >= 1) post("BAR %d - - - - - - - - - - - - - - - - - - - - - - - - - - - - ", bar_number); 962 | } 963 | beatsize = exp2f( (float) (log2f((float) x->refdur) - log2f((float) x->i_mtr[0][1]))); 964 | barsize = (int) x->i_mtr[i][0] * beatsize; 965 | beatsize = get_beatsize(x->i_mtr[i][0], x->i_mtr[i][1], x->refdur); 966 | x->bar_info[bar_number][1] = x->i_mtr[i][0]; 967 | x->bar_info[bar_number][2] = x->i_mtr[i][1]; 968 | x->bar_info[bar_number][3] = beatsize; 969 | x->bar_info[bar_number][4] = barsize; 970 | barcount = 0; 971 | if (x->debug >= 1) post("Meter change::: %d / %d", x->bar_info[bar_number][1], x->bar_info[bar_number][2]); 972 | } 973 | if (barcount + x->i_dur[i] <= barsize){ 974 | x->b_dur[x->b_index] = x->i_dur[i]; //duration 975 | x->b_tie[x->b_index] = x->i_tie[i]; // tie 976 | x->b_i[x->b_index] = i; // clean input number 977 | x->bar_n[x->b_index] = bar_number; // bar number 978 | x->b_rii[x->b_index] = x->i_rii[i]; //raw input number 979 | x->b_tup[x->b_index] = x->i_tup[i]; //tuplet 980 | barcount += x->i_dur[i]; 981 | if (x->debug >= 1) post("%d\t%d\t%d\t%d\t%d\t%d\t%d", x->b_index, x->bar_n[x->b_index], x->b_i[x->b_index], x->b_rii[x->b_index], x->b_dur[x->b_index], x->b_tie[x->b_index], x->b_tup[x->b_index]); 982 | x->b_index++; 983 | if (barcount == barsize) { 984 | bar_number++; 985 | barcount = 0; 986 | x->bar_info[bar_number][0] = x->b_index; 987 | x->bar_info[bar_number][1] = x->i_mtr[i][0]; 988 | x->bar_info[bar_number][2] = x->i_mtr[i][1]; 989 | x->bar_info[bar_number][3] = beatsize; 990 | x->bar_info[bar_number][4] = barsize; 991 | if (x->debug >= 1) post("BAR %d - - - - - - - - - - - - - - - - - - - - - - - - - - - - ", bar_number); 992 | } 993 | } 994 | else { 995 | x->b_dur[x->b_index] = barsize - barcount; 996 | barcount = 0; 997 | dur_remainder = x->i_dur[i] - x->b_dur[x->b_index]; 998 | x->b_tie[x->b_index] = 1; 999 | x->b_i[x->b_index] = i; 1000 | x->bar_n[x->b_index] = bar_number; 1001 | x->b_rii[x->b_index] = x->i_rii[i]; //raw input number 1002 | x->b_tup[x->b_index] = x->i_tup[i]; //tuplet 1003 | if (x->debug >= 1) post("%d\t%d\t%d\t%d\t%d\t%d\t%d", x->b_index, x->bar_n[x->b_index], x->b_i[x->b_index], x->b_rii[x->b_index], x->b_dur[x->b_index], x->b_tie[x->b_index], x->b_tup[x->b_index]); 1004 | x->b_index++; 1005 | bar_number++; 1006 | x->bar_info[bar_number][0] = x->b_index; 1007 | x->bar_info[bar_number][1] = x->i_mtr[i][0]; 1008 | x->bar_info[bar_number][2] = x->i_mtr[i][1]; 1009 | x->bar_info[bar_number][3] = beatsize; 1010 | x->bar_info[bar_number][4] = barsize; 1011 | if (x->debug >= 1) post("BAR %d - - - - - - - - - - - - - - - - - - - - - - - - - - - - ", bar_number); 1012 | 1013 | while (dur_remainder > 0) { 1014 | if (barcount + dur_remainder <= barsize) { 1015 | x->b_dur[x->b_index] = dur_remainder; 1016 | x->b_tie[x->b_index] = x->i_tie[i]; 1017 | x->b_i[x->b_index] = i; 1018 | x->b_rii[x->b_index] = x->i_rii[i]; ////raw input number 1019 | x->b_tup[x->b_index] = x->i_tup[i]; //tuplet 1020 | x->bar_n[x->b_index] = bar_number; 1021 | barcount += dur_remainder; 1022 | if (x->debug >= 1) post("%d\t%d\t%d\t%d\t%d\t%d\t%d", x->b_index, x->bar_n[x->b_index], x->b_i[x->b_index], x->b_rii[x->b_index], x->b_dur[x->b_index], x->b_tie[x->b_index], x->b_tup[x->b_index]); 1023 | x->b_index++; 1024 | if (barcount == barsize) { 1025 | barcount = 0; 1026 | bar_number++; 1027 | x->bar_info[bar_number][0] = x->b_index; 1028 | x->bar_info[bar_number][1] = x->i_mtr[i][0]; 1029 | x->bar_info[bar_number][2] = x->i_mtr[i][1]; 1030 | x->bar_info[bar_number][3] = beatsize; 1031 | x->bar_info[bar_number][4] = barsize; 1032 | if (x->debug >= 1) post("BAR %d - - - - - - - - - - - - - - - - - - - - - - - - - - - - ", bar_number); 1033 | } 1034 | dur_remainder = 0; 1035 | } 1036 | else { 1037 | // copy pitches 1038 | x->b_dur[x->b_index] = barsize; 1039 | barcount = 0; 1040 | dur_remainder -= barsize; 1041 | x->b_tie[x->b_index] = 1; 1042 | x->b_i[x->b_index] = i; 1043 | x->b_rii[x->b_index] = x->i_rii[i]; //raw input number 1044 | x->b_tup[x->b_index] = x->i_tup[i]; //tuplet 1045 | x->bar_n[x->b_index] = bar_number; 1046 | if (x->debug >= 1) post("%d\t%d\t%d\t%d\t%d\t%d\t%d", x->b_index, x->bar_n[x->b_index], x->b_i[x->b_index], x->b_rii[x->b_index], x->b_dur[x->b_index], x->b_tie[x->b_index], x->b_tup[x->b_index]); 1047 | x->b_index++; 1048 | bar_number++; 1049 | x->bar_info[bar_number][0] = x->b_index; 1050 | x->bar_info[bar_number][1] = x->i_mtr[i][0]; 1051 | x->bar_info[bar_number][2] = x->i_mtr[i][1]; 1052 | x->bar_info[bar_number][3] = beatsize; 1053 | x->bar_info[bar_number][4] = barsize; 1054 | if (x->debug >= 1) post("BAR %d - - - - - - - - - - - - - - - - - - - - - - - - - - - - ", bar_number); 1055 | } 1056 | } 1057 | } 1058 | } 1059 | } 1060 | ////////// BREAK INPUT INTO THE (imported) MASTER BARS 1061 | else { 1062 | //////// READ BARFILE 1063 | FILE *fp3; 1064 | fp3 = fopen( x->barfile, "r"); 1065 | if(!fp3) { 1066 | pd_error(x, "%s: couldn't read barfile, send one to the second inlet", x->barfile); 1067 | return; 1068 | } 1069 | else ii = readbarfile(x->bar_info, (FILE *) fp3); //////sdsdfsdfsdfsdf 1070 | //////sdsdfsdfsdfsdf//////sdsdfsdfsdfsdf//////sdsdfsdfsdfsdf//////sdsdfsdfsdfsdf 1071 | //////sdsdfsdfsdfsdf//////sdsdfsdfsdfsdf//////sdsdfsdfsdfsdf//////sdsdfsdfsdfsdf 1072 | //////sdsdfsdfsdfsdf//////sdsdfsdfsdfsdf//////sdsdfsdfsdfsdf//////sdsdfsdfsdfsdf 1073 | //////sdsdfsdfsdfsdf//////sdsdfsdfsdfsdf//////sdsdfsdfsdfsdf//////sdsdfsdfsdfsdf 1074 | if (x->debug >= 1){ 1075 | post("Reading Master Bar File"); 1076 | post("i\tnum\tdenom\tbeatsize\tbarsize\t"); 1077 | for (i=0;ibar_info[i][1], x->bar_info[i][2], x->bar_info[i][3], x->bar_info[i][4]); 1079 | } 1080 | } 1081 | //////// BREAK INPUT BY BARFILE 1082 | beatsize = x->bar_info[0][3]; 1083 | barsize = x->bar_info[0][4]; 1084 | x->bar_info[0][0] = 0; 1085 | if (x->debug >= 1) { 1086 | post("num=%d", (int) x->bar_info[0][1]); 1087 | post("refdur=%d denom=%d beatsize=%d", x->refdur, x->bar_info[0][2], beatsize); 1088 | post("barsize=%d\n", barsize); 1089 | post("i\tbar no.\tclean i\traw i\tdur\ttie\ttuplet"); 1090 | post("BAR %d - - - - - - - - - - - - - - - - - - - - - - - - - - - - ", bar_number); 1091 | } 1092 | barcount = 0; 1093 | x->bar_info[bar_number][0] = x->b_index; 1094 | for(i=0; ii_index; i++) { 1095 | if (barcount + x->i_dur[i] <= barsize){ 1096 | x->b_dur[x->b_index] = x->i_dur[i]; //duration 1097 | x->b_tie[x->b_index] = x->i_tie[i]; // tie 1098 | x->b_i[x->b_index] = i; // clean input number 1099 | x->bar_n[x->b_index] = bar_number; // bar number 1100 | x->b_rii[x->b_index] = x->i_rii[i]; //raw input number 1101 | x->b_tup[x->b_index] = x->i_tup[i]; //tuplet 1102 | barcount += x->i_dur[i]; 1103 | if (x->debug >= 1) post("%d\t%d\t%d\t%d\t%d\t%d\t%d", x->b_index, x->bar_n[x->b_index], x->b_i[x->b_index], x->b_rii[x->b_index], x->b_dur[x->b_index], x->b_tie[x->b_index], x->b_tup[x->b_index]); 1104 | x->b_index++; 1105 | if (barcount == barsize) { 1106 | bar_number++; 1107 | barcount = 0; 1108 | x->bar_info[bar_number][0] = x->b_index; 1109 | beatsize = x->bar_info[bar_number][3]; 1110 | barsize = x->bar_info[bar_number][4]; 1111 | if (bar_number >= ii) { 1112 | x->bar_info[bar_number][1] = x->bar_info[bar_number-1][1]; 1113 | x->bar_info[bar_number][2] = x->bar_info[bar_number-1][2]; 1114 | x->bar_info[bar_number][3] = x->bar_info[bar_number-1][3]; 1115 | x->bar_info[bar_number][4] = x->bar_info[bar_number-1][4]; 1116 | beatsize = x->bar_info[bar_number][3]; 1117 | barsize = x->bar_info[bar_number][4]; 1118 | } 1119 | if (x->debug >= 1) post("BAR %d - - - - - - - - - - - - - - - - - - - - - - - - - - - - ", bar_number); 1120 | } 1121 | } 1122 | else { 1123 | x->b_dur[x->b_index] = barsize - barcount; 1124 | barcount = 0; 1125 | dur_remainder = x->i_dur[i] - x->b_dur[x->b_index]; 1126 | x->b_tie[x->b_index] = 1; 1127 | x->b_i[x->b_index] = i; 1128 | x->bar_n[x->b_index] = bar_number; 1129 | x->b_rii[x->b_index] = x->i_rii[i]; //raw input number 1130 | x->b_tup[x->b_index] = x->i_tup[i]; //tuplet 1131 | if (x->debug >= 1) post("%d\t%d\t%d\t%d\t%d\t%d\t%d", x->b_index, x->bar_n[x->b_index], x->b_i[x->b_index], x->b_rii[x->b_index], x->b_dur[x->b_index], x->b_tie[x->b_index], x->b_tup[x->b_index]); 1132 | x->b_index++; 1133 | bar_number++; 1134 | x->bar_info[bar_number][0] = x->b_index; 1135 | beatsize = x->bar_info[bar_number][3]; 1136 | barsize = x->bar_info[bar_number][4]; 1137 | if (bar_number >= ii) { 1138 | x->bar_info[bar_number][1] = x->bar_info[bar_number-1][1]; 1139 | x->bar_info[bar_number][2] = x->bar_info[bar_number-1][2]; 1140 | x->bar_info[bar_number][3] = x->bar_info[bar_number-1][3]; 1141 | x->bar_info[bar_number][4] = x->bar_info[bar_number-1][4]; 1142 | beatsize = x->bar_info[bar_number][3]; 1143 | barsize = x->bar_info[bar_number][4]; 1144 | } 1145 | if (x->debug >= 1) post("BAR %d - - - - - - - - - - - - - - - - - - - - - - - - - - - - ", bar_number); 1146 | 1147 | while (dur_remainder > 0) { 1148 | if (barcount + dur_remainder <= barsize) { 1149 | x->b_dur[x->b_index] = dur_remainder; 1150 | x->b_tie[x->b_index] = x->i_tie[i]; 1151 | x->b_i[x->b_index] = i; 1152 | x->b_rii[x->b_index] = x->i_rii[i]; ////raw input number 1153 | x->b_tup[x->b_index] = x->i_tup[i]; //tuplet 1154 | x->bar_n[x->b_index] = bar_number; 1155 | barcount += dur_remainder; 1156 | if (x->debug >= 1) post("%d\t%d\t%d\t%d\t%d\t%d\t%d", x->b_index, x->bar_n[x->b_index], x->b_i[x->b_index], x->b_rii[x->b_index], x->b_dur[x->b_index], x->b_tie[x->b_index], x->b_tup[x->b_index]); 1157 | x->b_index++; 1158 | if (barcount == barsize) { 1159 | barcount = 0; 1160 | bar_number++; 1161 | x->bar_info[bar_number][0] = x->b_index; 1162 | beatsize = x->bar_info[bar_number][3]; 1163 | barsize = x->bar_info[bar_number][4]; 1164 | if (bar_number >= ii) { 1165 | x->bar_info[bar_number][1] = x->bar_info[bar_number-1][1]; 1166 | x->bar_info[bar_number][2] = x->bar_info[bar_number-1][2]; 1167 | x->bar_info[bar_number][3] = x->bar_info[bar_number-1][3]; 1168 | x->bar_info[bar_number][4] = x->bar_info[bar_number-1][4]; 1169 | beatsize = x->bar_info[bar_number][3]; 1170 | barsize = x->bar_info[bar_number][4]; 1171 | } 1172 | if (x->debug >= 1) post("BAR %d - - - - - - - - - - - - - - - - - - - - - - - - - - - - ", bar_number); 1173 | } 1174 | dur_remainder = 0; 1175 | } 1176 | else { 1177 | // copy pitches 1178 | x->b_dur[x->b_index] = barsize; 1179 | barcount = 0; 1180 | dur_remainder -= barsize; 1181 | x->b_tie[x->b_index] = 1; 1182 | x->b_i[x->b_index] = i; 1183 | x->b_rii[x->b_index] = x->i_rii[i]; //raw input number 1184 | x->b_tup[x->b_index] = x->i_tup[i]; //tuplet 1185 | x->bar_n[x->b_index] = bar_number; 1186 | if (x->debug >= 1) post("%d\t%d\t%d\t%d\t%d\t%d\t%d", x->b_index, x->bar_n[x->b_index], x->b_i[x->b_index], x->b_rii[x->b_index], x->b_dur[x->b_index], x->b_tie[x->b_index], x->b_tup[x->b_index]); 1187 | x->b_index++; 1188 | bar_number++; 1189 | x->bar_info[bar_number][0] = x->b_index; 1190 | beatsize = x->bar_info[bar_number][3]; 1191 | barsize = x->bar_info[bar_number][4]; 1192 | if (bar_number >= ii) { 1193 | x->bar_info[bar_number][1] = x->bar_info[bar_number-1][1]; 1194 | x->bar_info[bar_number][2] = x->bar_info[bar_number-1][2]; 1195 | x->bar_info[bar_number][3] = x->bar_info[bar_number-1][3]; 1196 | x->bar_info[bar_number][4] = x->bar_info[bar_number-1][4]; 1197 | beatsize = x->bar_info[bar_number][3]; 1198 | barsize = x->bar_info[bar_number][4]; 1199 | } 1200 | if (x->debug >= 1) post("BAR %d - - - - - - - - - - - - - - - - - - - - - - - - - - - - ", bar_number); 1201 | } 1202 | } 1203 | } 1204 | } 1205 | } 1206 | if (x->debug >= 1) { 1207 | post("\nChecking for tuplet errors\n"); 1208 | } //// Check for tuplet errors 1209 | for(i=0; ii_index; i++) { 1210 | if (x->bar_n[i] != x->bar_n[i-1] && x->b_tup[i] == x->b_tup[i-1] && x->b_tup[i] > 0) post("¡¡¡¡¡¡¡ERROR!!!!!! Tuplet No. %d crosses the bar line between bars %d and %d", x->b_tup[i], x->bar_n[i-1], x->bar_n[i]); 1211 | } //// Print Tuplet Errors 1212 | // x->debug = 1; 1213 | if (x->debug >= 1) { 1214 | post("\nBAR INFORMATION\n"); 1215 | post("i\tinit\telems\tnum\tden\tbeatsize\tbarsize"); 1216 | } //// Print bar info headers 1217 | if (x->FOLLOW == 0) { 1218 | char bar_buf[MAXPDSTRING]; 1219 | FILE *fp; 1220 | 1221 | canvas_makefilename(x->x_canvas, s->s_name, bar_buf, MAXPDSTRING); /// This is a Pd function to get the path relative to the canvas 1222 | sys_bashfilename(bar_buf, bar_buf); 1223 | strcat( bar_buf, "_barinfo.txt"); 1224 | t_symbol *masterbar = gensym(bar_buf); 1225 | outlet_symbol(x->x_outlet1, masterbar); 1226 | fp = fopen(bar_buf, "w"); 1227 | if(!fp) { 1228 | pd_error(x, "%s: couldn't create", bar_buf); 1229 | return; 1230 | } 1231 | else { 1232 | for(i=0; i<=bar_number; i++) { 1233 | j = x->bar_info[i+1][0] - x->bar_info[i][0]; 1234 | if (i == bar_number) j = x->b_index - x->bar_info[i][0]; 1235 | if (x->debug >= 1) post("%d\t%d\t%d\t%d\t%d\t%d\t%d\t", i, x->bar_info[i][0], j, x->bar_info[i][1], x->bar_info[i][2], x->bar_info[i][3], x->bar_info[i][4]); 1236 | if (x->FOLLOW == 0) fprintf(fp, "%d %d %d %d %d\n", i, x->bar_info[i][1], x->bar_info[i][2], x->bar_info[i][3], x->bar_info[i][4]); 1237 | } 1238 | } 1239 | fclose(fp); 1240 | } //// GENERATE A BAR INFO FILE 1241 | else { 1242 | for(i=0; i<=bar_number; i++) { 1243 | j = x->bar_info[i+1][0] - x->bar_info[i][0]; 1244 | if (i == bar_number) j = x->b_index - x->bar_info[i][0]; 1245 | if (x->debug >= 1) post("%d\t%d\t%d\t%d\t%d\t%d\t%d", i, x->bar_info[i][0], j, x->bar_info[i][1], x->bar_info[i][2], x->bar_info[i][3], x->bar_info[i][4]); 1246 | } 1247 | } //// Print BAR INFOR 1248 | // x->debug = 0; 1249 | //// _______________________________________________ BEAT SUBDIVISION 1250 | if (x->debug >= 1) { 1251 | post(".\nBEAT PROGRAM :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::\n."); 1252 | post("beatsize=%d\n", beatsize); 1253 | post("i\tbar_n\tbeat_n\tclean_i\traw_i\tdur\ttie\ttuplet"); 1254 | post("METER = %d/%d\t beatsize = %d", x->bar_info[x->be_bar_n[0]][1], x->bar_info[x->be_bar_n[0]][2], beatsize); 1255 | post("BAR %d ===============================================", 0); 1256 | } 1257 | beatcount = beat_number = 0; 1258 | beatsize = x->bar_info[0][3]; 1259 | barsize = x->bar_info[0][4]; 1260 | for(i=0; ib_index; i++) { 1261 | ///// CHECK METER 1262 | if (i > 0 && x->bar_n[i] != x->bar_n[i-1]) { 1263 | if (x->debug >= 1) post("BAR %d ===============================================", x->bar_n[i]); 1264 | beatcount = 0; 1265 | beat_number = 0; 1266 | if (x->debug >= 1) post("beatsize = %d", beatsize); 1267 | if (x->bar_info[x->bar_n[i]][1] != x->bar_info[x->bar_n[i-1]][1] || 1268 | x->bar_info[x->bar_n[i]][2] != x->bar_info[x->bar_n[i-1]][2] ) { 1269 | beatsize = x->bar_info[x->bar_n[i]][3]; 1270 | barsize = x->bar_info[x->bar_n[i]][4]; 1271 | if (x->debug >= 1) post("METER = %d/%d\t beatsize = %d", x->bar_info[x->bar_n[i]][1], x->bar_info[x->bar_n[i]][2], beatsize); 1272 | } 1273 | } 1274 | ///// ASSIGN DURATIONS 1275 | /// less than beat? 1276 | if ((beatcount + x->b_dur[i]) <= beatsize) { 1277 | x->be_dur[x->be_index] = x->b_dur[i]; 1278 | x->be_tie[x->be_index] = x->b_tie[i]; 1279 | x->be_i[x->be_index] = x->b_i[i]; // clean input number (original input index) 1280 | x->be_rii[x->be_index] = x->b_rii[i]; // raw input number 1281 | x->be_tup[x->be_index] = x->b_tup[i]; // tuplet 1282 | x->be_bar_n[x->be_index] = x->bar_n[i]; // bar number 1283 | beatcount += x->b_dur[i]; 1284 | x->be_beat_n[x->be_index] = beat_number / x->bar_info[x->bar_n[i]][3]; 1285 | beat_number += x->b_dur[i]; 1286 | if (x->debug >= 1) post("%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d", x->be_index, x->be_bar_n[x->be_index], x->be_beat_n[x->be_index], x->be_i[x->be_index], x->be_rii[x->be_index], x->be_dur[x->be_index], x->be_tie[x->be_index], x->be_tup[x->be_index]); 1287 | if (x->debug >= 3) post("<<<<<<<<< beatcount = %d", beatcount); 1288 | if (beatcount == beatsize) { 1289 | beatcount = 0; 1290 | if (x->debug >= 1) post("- - - - - - - - - - - - - -"); 1291 | } 1292 | x->be_index++; 1293 | } 1294 | else if (beatcount == 0 && x->b_dur[i]%beatsize == 0) { 1295 | dur_remainder = x->b_dur[i]; 1296 | if (x->debug >= 3) post("durem=%d\tbarsize=%d", dur_remainder, barsize); 1297 | ////// EXACTLY EQUAL to A MULTIPLE 1298 | for(j=0; j<32; j++){ 1299 | if (dur_remainder == beatsize * j) { 1300 | if (pow2ordot(dur_remainder) == 1) { 1301 | x->be_dur[x->be_index] = dur_remainder; 1302 | dur_remainder = 0; 1303 | beatcount = 0; 1304 | x->be_tie[x->be_index] = x->b_tie[i]; 1305 | x->be_i[x->be_index] = x->b_i[i]; // input number (original input index) 1306 | x->be_rii[x->be_index] = x->b_rii[i]; // raw input number 1307 | x->be_tup[x->be_index] = x->b_tup[i]; // tuplet 1308 | x->be_bar_n[x->be_index] = x->bar_n[i]; // bar number 1309 | x->be_beat_n[x->be_index] = beat_number / x->bar_info[x->bar_n[i]][3]; 1310 | beat_number += x->be_dur[x->be_index]; 1311 | if (x->debug >= 1) post("%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d", x->be_index, x->be_bar_n[x->be_index], x->be_beat_n[x->be_index], x->be_i[x->be_index], x->be_rii[x->be_index], x->be_dur[x->be_index], x->be_tie[x->be_index], x->be_tup[x->be_index]); 1312 | if (x->debug >= 3) post("BEAT:::: EXACT-2orDOT beatcount = %d,\tdur:%d", beatcount, x->be_dur[x->be_index]); 1313 | if (x->debug >= 1) post("- - - - - - - - - - - - - -"); 1314 | x->be_index++; 1315 | } // If it is exactly power or dot 1316 | else { 1317 | beatcount += x->b_dur[i] % beatsize; 1318 | while (dur_remainder > 0) { 1319 | if (dur_remainder >= beatsize) { 1320 | for(j=0; j<18; j++){ 1321 | if (dur_remainder < pow2dot_array[j]) { 1322 | if (x->debug >= 3) post("%d, temp=%d", j, (int) temp_f); 1323 | break; 1324 | } 1325 | } 1326 | if (x->debug >= 3) post("rem=%d\tj=%d\tdur=%d", dur_remainder, j-1, pow2dot_array[j-1]); 1327 | x->be_dur[x->be_index] = pow2dot_array[j-1]; 1328 | dur_remainder -= x->be_dur[x->be_index]; 1329 | } 1330 | else { 1331 | x->be_dur[x->be_index] = dur_remainder; 1332 | dur_remainder = 0; 1333 | } 1334 | if (dur_remainder == 0) { x->be_tie[x->be_index] = x->b_tie[i]; } 1335 | else { x->be_tie[x->be_index] = 1; } 1336 | x->be_i[x->be_index] = x->b_i[i]; // input number (original input index) 1337 | x->be_rii[x->be_index] = x->b_rii[i]; // raw input number 1338 | x->be_tup[x->be_index] = x->b_tup[i]; // tuplet 1339 | x->be_bar_n[x->be_index] = x->bar_n[i]; // bar number 1340 | x->be_beat_n[x->be_index] = beat_number / x->bar_info[x->bar_n[i]][3]; 1341 | beat_number += x->be_dur[x->be_index]; 1342 | if (x->debug >= 1) post("%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d", x->be_index, x->be_bar_n[x->be_index], x->be_beat_n[x->be_index], x->be_i[x->be_index], x->be_rii[x->be_index], x->be_dur[x->be_index], x->be_tie[x->be_index], x->be_tup[x->be_index]); 1343 | if (x->debug >= 3) post("BEAT:::: ==0 Closest 2ordot beatcount = %d\tdur=%d", beatcount, x->be_dur[x->be_index]); 1344 | if (x->debug >= 1) post("- - - - - - - - - - - - - -"); 1345 | x->be_index++; 1346 | } 1347 | } 1348 | break; 1349 | } 1350 | } 1351 | } 1352 | else if (beatcount == 0 && x->b_dur[i]%beatsize != 0) { 1353 | dur_remainder = x->b_dur[i]; 1354 | while (dur_remainder > 0) { 1355 | if (dur_remainder >= beatsize) { 1356 | for(j=0; j<18; j++){ 1357 | if (dur_remainder < pow2dot_array[j]) { 1358 | if (x->debug >= 3) post("%d, temp=%d", j, (int) temp_f); 1359 | break; 1360 | } 1361 | } 1362 | if (x->debug >= 3) post("rem=%d\tj=%d\tdur=%d", dur_remainder, j-1, pow2dot_array[j-1]); 1363 | x->be_dur[x->be_index] = pow2dot_array[j-1]; 1364 | dur_remainder -= x->be_dur[x->be_index]; 1365 | } 1366 | else{ 1367 | x->be_dur[x->be_index] = dur_remainder; 1368 | dur_remainder = 0; 1369 | } 1370 | if (dur_remainder == 0) { x->be_tie[x->be_index] = x->b_tie[i]; } 1371 | else { x->be_tie[x->be_index] = 1; } 1372 | x->be_i[x->be_index] = x->b_i[i]; // input number (original input index) 1373 | x->be_rii[x->be_index] = x->b_rii[i]; // raw input number 1374 | x->be_tup[x->be_index] = x->b_tup[i]; // tuplet 1375 | x->be_bar_n[x->be_index] = x->bar_n[i]; // bar number 1376 | x->be_beat_n[x->be_index] = beat_number / x->bar_info[x->bar_n[i]][3]; 1377 | beat_number += x->be_dur[x->be_index]; 1378 | if (x->debug >= 1) post("%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d", x->be_index, x->be_bar_n[x->be_index], x->be_beat_n[x->be_index], x->be_i[x->be_index], x->be_rii[x->be_index], x->be_dur[x->be_index], x->be_tie[x->be_index], x->be_tup[x->be_index]); 1379 | if (x->debug >= 3) post("BEAT:::: !=0 Closest 2ordot beatcount = %d\tdur=%d", beatcount, x->be_dur[x->be_index]); 1380 | beatcount += x->be_dur[x->be_index] % beatsize; 1381 | if (beatcount == 0) if (x->debug >= 1) post("- - - - - - - - - - - - - -"); 1382 | x->be_index++; 1383 | } 1384 | } 1385 | ////// NOT ZERO 1386 | else { 1387 | x->be_dur[x->be_index] = beatsize - beatcount; 1388 | dur_remainder = x->b_dur[i] - x->be_dur[x->be_index]; 1389 | x->be_tie[x->be_index] = 1; 1390 | x->be_i[x->be_index] = x->b_i[i]; 1391 | x->be_rii[x->be_index] = x->b_rii[i]; // raw input number 1392 | x->be_tup[x->be_index] = x->b_tup[i]; // tuplet 1393 | x->be_bar_n[x->be_index] = x->bar_n[i]; // bar number 1394 | beatcount = 0; 1395 | x->be_beat_n[x->be_index] = beat_number / x->bar_info[x->bar_n[i]][3]; 1396 | beat_number += x->be_dur[x->be_index]; 1397 | if (x->debug >= 1) post("%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d", x->be_index, x->be_bar_n[x->be_index], x->be_beat_n[x->be_index], x->be_i[x->be_index], x->be_rii[x->be_index], x->be_dur[x->be_index], x->be_tie[x->be_index], x->be_tup[x->be_index]); 1398 | if (x->debug >= 3) post("BEAT::::not zero beatcount = %d", beatcount); 1399 | if (x->debug >= 1) post("- - - - - - - - - - - - - -"); 1400 | x->be_index++; 1401 | while (dur_remainder > 0) { 1402 | if (dur_remainder <= beatsize) { 1403 | x->be_dur[x->be_index] = dur_remainder; 1404 | x->be_tie[x->be_index] = x->b_tie[i]; 1405 | x->be_i[x->be_index] = x->b_i[i]; // input number (original input index) 1406 | x->be_rii[x->be_index] = x->b_rii[i]; // raw input number 1407 | x->be_tup[x->be_index] = x->b_tup[i]; // tuplet 1408 | x->be_bar_n[x->be_index] = x->bar_n[i]; // bar number 1409 | beatcount += dur_remainder; 1410 | x->be_beat_n[x->be_index] = beat_number / x->bar_info[x->bar_n[i]][3]; 1411 | beat_number += x->be_dur[x->be_index]; 1412 | if (x->debug >= 1) post("%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d", x->be_index, x->be_bar_n[x->be_index], x->be_beat_n[x->be_index], x->be_i[x->be_index], x->be_rii[x->be_index], x->be_dur[x->be_index], x->be_tie[x->be_index], x->be_tup[x->be_index]); 1413 | if (x->debug >= 3) post("BEAT::::ELSE while <= beatcount = %d", beatcount); 1414 | if (beatcount == beatsize) { 1415 | beatcount = 0; 1416 | if (x->debug >= 1) post("- - - - - - - - - - - - - -"); 1417 | } 1418 | dur_remainder = 0; 1419 | x->be_index++; 1420 | } 1421 | else { 1422 | for(j=0; j<32; j++){ 1423 | if (dur_remainder < (beatsize * j)) { //&& pow2ordot(beatsize * j) == 1) { 1424 | x->be_dur[x->be_index] = beatsize * (j - 1); 1425 | break; 1426 | } 1427 | } 1428 | dur_remainder -= x->be_dur[x->be_index]; 1429 | x->be_tie[x->be_index] = 1; 1430 | x->be_i[x->be_index] = x->b_i[i]; // input number (original input index) 1431 | x->be_rii[x->be_index] = x->b_rii[i]; // raw input number 1432 | x->be_tup[x->be_index] = x->b_tup[i]; // tuplet 1433 | x->be_bar_n[x->be_index] = x->bar_n[i]; // bar number 1434 | x->be_beat_n[x->be_index] = beat_number / x->bar_info[x->bar_n[i]][3]; 1435 | beat_number += x->be_dur[x->be_index]; 1436 | beatcount = 0; 1437 | if (x->debug >= 1) post("%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d", x->be_index, x->be_bar_n[x->be_index], x->be_beat_n[x->be_index], x->be_i[x->be_index], x->be_rii[x->be_index], x->be_dur[x->be_index], x->be_tie[x->be_index], x->be_tup[x->be_index]); 1438 | if (x->debug >= 3) post("BEAT::::while else beatcount = %d", beatcount); 1439 | if (x->debug >= 1) post("- - - - - - - - - - - - - -"); 1440 | x->be_index++; 1441 | } 1442 | } 1443 | } 1444 | } 1445 | //// _______________________________________________ SUB-BEAT SUBDIVISION 1446 | for (j=1; j<3; j++) { 1447 | if (x->debug >= 1) post("SUB-BEAT PROGRAM %d :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::", j); 1448 | beatsize = x->bar_info[x->be_bar_n[0]][3]; 1449 | if (x->debug >= 1) post("....\nbeatsize=%d\n", beatsize); 1450 | if (x->debug >= 1) post("i\tbar_n\tbeat_n\tclean_i\traw_i\tdur\ttie\ttuplet"); 1451 | if (x->debug >= 1) post("METER = %d/%d\t beatsize = %d", x->bar_info[x->be_bar_n[0]][1], x->bar_info[x->be_bar_n[0]][2], beatsize); 1452 | if (x->debug >= 1) post("BAR %d ===============================================", 0); 1453 | x->sb_index = beatcount = 0; 1454 | subdiv = j*2; if (x->debug >= 1) post("j=%d",j); 1455 | sub_beatsize = beatsize / subdiv; 1456 | for(i=0; ibe_index; i++){ 1457 | if (i > 0 && x->be_bar_n[i] != x->be_bar_n[i-1]) { 1458 | if (x->debug >= 1) post("BAR %d ============================================ BAR %d", x->be_bar_n[i], x->be_bar_n[i]); 1459 | if (x->debug >= 1) post("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - %d", x->be_beat_n[i]); 1460 | if (x->bar_info[x->be_bar_n[i]][1] != x->bar_info[x->be_bar_n[i-1]][1] || 1461 | x->bar_info[x->be_bar_n[i]][2] != x->bar_info[x->be_bar_n[i-1]][2] ) { 1462 | beatsize = x->bar_info[x->be_bar_n[i]][3]; 1463 | sub_beatsize = beatsize / subdiv; 1464 | if (sub_beatsize < 2) sub_beatsize = 2; 1465 | if (x->debug >= 1) post("METER = %d/%d\t beatsize = %d\t sub_beatsize = %d", x->bar_info[x->be_bar_n[i]][1], x->bar_info[x->be_bar_n[i]][2], beatsize, sub_beatsize); 1466 | beatcount = 0; 1467 | } 1468 | while (beatcount >= sub_beatsize) { 1469 | beatcount -= sub_beatsize; 1470 | // post("beatcount =\t%d", beatcount); 1471 | } 1472 | } 1473 | else if (i > 0 && x->be_beat_n[i] != x->be_beat_n[i-1] ) { 1474 | if (x->debug >= 1) post("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - %d", x->be_beat_n[i]); 1475 | while (beatcount >= sub_beatsize) { 1476 | beatcount -= sub_beatsize; 1477 | } 1478 | } 1479 | if (sub_beatsize < 4) { 1480 | x->sb_dur[x->sb_index] = x->be_dur[i]; 1481 | x->sb_tie[x->sb_index] = x->be_tie[i]; 1482 | x->sb_i[x->sb_index] = x->be_i[i]; // input number (original input index) 1483 | x->sb_rii[x->sb_index] = x->be_rii[i]; // raw input number 1484 | x->sb_tup[x->sb_index] = x->be_tup[i]; // tuplet 1485 | x->sb_bar_n[x->sb_index] = x->be_bar_n[i]; // bar number 1486 | x->sb_beat_n[x->sb_index] = x->be_beat_n[i]; 1487 | if (x->debug >= 1) post("%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d", x->sb_index, x->sb_bar_n[x->sb_index], x->sb_beat_n[x->sb_index], x->sb_i[x->sb_index], x->sb_rii[x->sb_index], x->sb_dur[x->sb_index], x->sb_tie[x->sb_index], x->sb_tup[x->sb_index]); 1488 | x->sb_index++; 1489 | beatcount += x->be_dur[i]; 1490 | if( (((beatcount + x->be_dur[i]) == sub_beatsize) || ((beatcount + x->be_dur[i]) % sub_beatsize == 0)) && (sub_beatsize > 2) ) { 1491 | if (x->debug >= 1) post(". . . . . . . . . . . . . . . . . . . . . . . . . . . . .%d", sub_beatsize); 1492 | } 1493 | while (beatcount >= sub_beatsize) { 1494 | beatcount -= sub_beatsize; 1495 | } 1496 | } 1497 | else { 1498 | if ( ((beatcount + x->be_dur[i]) <= sub_beatsize) ) { 1499 | x->sb_dur[x->sb_index] = x->be_dur[i]; 1500 | x->sb_tie[x->sb_index] = x->be_tie[i]; 1501 | x->sb_i[x->sb_index] = x->be_i[i]; // input number (original input index) 1502 | x->sb_rii[x->sb_index] = x->be_rii[i]; // raw input number 1503 | x->sb_tup[x->sb_index] = x->be_tup[i]; // tuplet 1504 | x->sb_bar_n[x->sb_index] = x->be_bar_n[i]; // bar number 1505 | x->sb_beat_n[x->sb_index] = x->be_beat_n[i]; 1506 | if (x->debug >= 1) post("%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d", x->sb_index, x->sb_bar_n[x->sb_index], x->sb_beat_n[x->sb_index], x->sb_i[x->sb_index], x->sb_rii[x->sb_index], x->sb_dur[x->sb_index], x->sb_tie[x->sb_index], x->sb_tup[x->sb_index]); 1507 | x->sb_index++; 1508 | beatcount += x->be_dur[i]; 1509 | if( (((beatcount + x->be_dur[i]) == sub_beatsize) || ((beatcount + x->be_dur[i]) % sub_beatsize == 0)) && (sub_beatsize > 2) ) { 1510 | if (x->debug >= 1) post(". . . . . . . . . . . . . . . . . . . . . . . . . . . . .%d", sub_beatsize); 1511 | } 1512 | while (beatcount >= sub_beatsize) { 1513 | beatcount -= sub_beatsize; 1514 | } 1515 | } /// less than sub_beatsize 1516 | else if ( (((beatcount % sub_beatsize) == 0) && (((beatcount + x->be_dur[i]) % sub_beatsize) == 0)) && (sub_beatsize > 2) ) { 1517 | x->sb_dur[x->sb_index] = x->be_dur[i]; 1518 | x->sb_tie[x->sb_index] = x->be_tie[i]; 1519 | x->sb_i[x->sb_index] = x->be_i[i]; // input number (original input index) 1520 | x->sb_rii[x->sb_index] = x->be_rii[i]; // raw input number 1521 | x->sb_tup[x->sb_index] = x->be_tup[i]; // tuplet 1522 | x->sb_bar_n[x->sb_index] = x->be_bar_n[i]; // bar number 1523 | x->sb_beat_n[x->sb_index] = x->be_beat_n[i]; 1524 | if (x->debug >= 1) post("%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d", x->sb_index, x->sb_bar_n[x->sb_index], x->sb_beat_n[x->sb_index], x->sb_i[x->sb_index], x->sb_rii[x->sb_index], x->sb_dur[x->sb_index], x->sb_tie[x->sb_index], x->sb_tup[x->sb_index]); 1525 | x->sb_index++; 1526 | beatcount += x->be_dur[i]; 1527 | if (beatcount % sub_beatsize == 0) if (x->debug >= 1) post(". . . . . . . . . . . . . . . . . . . . . . . . . . . . .%d", sub_beatsize); 1528 | while (beatcount >= sub_beatsize) { 1529 | beatcount -= sub_beatsize; 1530 | // post("beatcount =\t%d", beatcount); 1531 | } 1532 | } /// for cases like 4 12 or 8 24 in a subbeat of 8 or 16 OR if beatcount = 0 and duration == 48, 64, 16, etc... 1533 | else if ( (((beatcount % (sub_beatsize/2)) == 0) && (((beatcount + x->be_dur[i]) % (sub_beatsize/2)) == 0)) && (sub_beatsize > 2) ) { 1534 | x->sb_dur[x->sb_index] = x->be_dur[i]; 1535 | x->sb_tie[x->sb_index] = x->be_tie[i]; 1536 | x->sb_i[x->sb_index] = x->be_i[i]; // input number (original input index) 1537 | x->sb_rii[x->sb_index] = x->be_rii[i]; // raw input number 1538 | x->sb_tup[x->sb_index] = x->be_tup[i]; // tuplet 1539 | x->sb_bar_n[x->sb_index] = x->be_bar_n[i]; // bar number 1540 | x->sb_beat_n[x->sb_index] = x->be_beat_n[i]; 1541 | if (x->debug >= 1) post("%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d", x->sb_index, x->sb_bar_n[x->sb_index], x->sb_beat_n[x->sb_index], x->sb_i[x->sb_index], x->sb_rii[x->sb_index], x->sb_dur[x->sb_index], x->sb_tie[x->sb_index], x->sb_tup[x->sb_index]); 1542 | 1543 | x->sb_index++; 1544 | beatcount += x->be_dur[i]; 1545 | if (beatcount % sub_beatsize == 0) if (x->debug >= 1) post(". . . . . . . . . . . . . . . . . . . . . . . . . . . . .%d", sub_beatsize); 1546 | while (beatcount >= sub_beatsize) { 1547 | beatcount -= sub_beatsize; 1548 | // post("beatcount =\t%d", beatcount); 1549 | } 1550 | } /// for cases like 4 12 or 8 24 in a subbeat of 8 or 16 OR if beatcount = 0 and duration == 48, 64, 16, etc... 1551 | else { 1552 | if (sub_beatsize > 2) { 1553 | x->sb_dur[x->sb_index] = sub_beatsize - beatcount; 1554 | dur_remainder = x->be_dur[i] - x->sb_dur[x->sb_index]; 1555 | x->sb_tie[x->sb_index] = 1; 1556 | x->sb_i[x->sb_index] = x->be_i[i]; // input number (original input index) 1557 | x->sb_rii[x->sb_index] = x->be_rii[i]; // raw input number 1558 | x->sb_tup[x->sb_index] = x->be_tup[i]; // tuplet 1559 | x->sb_bar_n[x->sb_index] = x->be_bar_n[i]; // bar number 1560 | x->sb_beat_n[x->sb_index] = x->be_beat_n[i]; 1561 | if (x->debug >= 1) post("%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d", x->sb_index, x->sb_bar_n[x->sb_index], x->sb_beat_n[x->sb_index], x->sb_i[x->sb_index], x->sb_rii[x->sb_index], x->sb_dur[x->sb_index], x->sb_tie[x->sb_index], x->sb_tup[x->sb_index]); 1562 | if ((beatcount + x->sb_dur[x->sb_index]) % sub_beatsize == 0) if (x->debug >= 1) post(". . . . . . . . . . . . . . . . . . . . . . . . . . . . .%d", sub_beatsize); 1563 | x->sb_index++; 1564 | 1565 | x->sb_dur[x->sb_index] = dur_remainder; 1566 | x->sb_tie[x->sb_index] = x->be_tie[i]; 1567 | x->sb_i[x->sb_index] = x->be_i[i]; // input number (original input index) 1568 | x->sb_rii[x->sb_index] = x->be_rii[i]; // raw input number 1569 | x->sb_tup[x->sb_index] = x->be_tup[i]; // tuplet 1570 | x->sb_bar_n[x->sb_index] = x->be_bar_n[i]; // bar number 1571 | x->sb_beat_n[x->sb_index] = x->be_beat_n[i]; 1572 | if (x->debug >= 1) post("%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d", x->sb_index, x->sb_bar_n[x->sb_index], x->sb_beat_n[x->sb_index], x->sb_i[x->sb_index], x->sb_rii[x->sb_index], x->sb_dur[x->sb_index], x->sb_tie[x->sb_index], x->sb_tup[x->sb_index]); 1573 | x->sb_index++; 1574 | 1575 | beatcount += x->be_dur[i]; 1576 | if (beatcount % sub_beatsize == 0) if (x->debug >= 1) post(". . . . . . . . . . . . . . . . . . . . . . . . . . . . .%d", sub_beatsize); 1577 | while (beatcount >= sub_beatsize) { 1578 | beatcount -= sub_beatsize; 1579 | // post("beatcount =\t%d", beatcount); 1580 | } 1581 | } 1582 | } 1583 | } 1584 | } 1585 | for( i=0; isb_index; i++ ){ 1586 | x->be_dur[i] = x->sb_dur[i]; 1587 | x->be_tie[i] = x->sb_tie[i]; 1588 | x->be_i[i] = x->sb_i[i]; // input number (original input index) 1589 | x->be_rii[i] = x->sb_rii[i]; // raw input number 1590 | x->be_tup[i] = x->sb_tup[i]; // tuplet 1591 | x->be_bar_n[i] = x->sb_bar_n[i]; // bar number 1592 | x->be_beat_n[i] = x->sb_beat_n[i]; 1593 | x->be_index = x->sb_index; 1594 | } 1595 | } 1596 | post("notes: ... Rhythmic computation done"); 1597 | //// ____________________________________ produce a single final list 1598 | if (x->debug >= 1) post("\n......... beginning final list!!!!! "); 1599 | ii = 0; 1600 | x->sb_index = 0; 1601 | if (x->debug >= 1) post("i\tbar_n\tbeat_n\tclean_i\traw_i\tdur\ttie\ttuplet"); 1602 | for(i=0; ibe_index; i++) { 1603 | // post("i=%d", i); 1604 | if (x->be_bar_n[i] != x->be_bar_n[i-1]) if (x->debug >= 1) post("_______________________________________________________________________________________"); 1605 | if (x->be_beat_n[i] != x->be_beat_n[i-1]) if (x->debug >= 1) post("- - - - - - - - - - - - - - - - - - - - - - - - -"); 1606 | if (x->be_tup[i] >= 0) { 1607 | while( x->sb_tp_num[ii] == x->be_tup[i] && iisb_tp_index) { 1608 | // post("ii=%d", ii); 1609 | x->sb_dur[x->sb_index] = x->sb_tp_dur[ii]; 1610 | x->sb_tie[x->sb_index] = x->sb_tp_tie[ii]; 1611 | x->sb_i[x->sb_index] = x->sb_tp_i[ii]; 1612 | x->sb_rii[x->sb_index] = x->sb_tp_ri[ii]; 1613 | x->sb_tup[x->sb_index] = x->sb_tp_num[ii]; 1614 | x->sb_bar_n[x->sb_index] = x->be_bar_n[i]; 1615 | x->sb_beat_n[x->sb_index] = x->be_beat_n[i]; 1616 | if (x->debug >= 1) post("%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\ttuplet_loop", x->sb_index, x->sb_bar_n[x->sb_index], x->sb_beat_n[x->sb_index], x->sb_i[x->sb_index], x->sb_rii[x->sb_index], x->sb_dur[x->sb_index], x->sb_tie[x->sb_index], x->sb_tup[x->sb_index]); 1617 | x->sb_index++; 1618 | ii++; 1619 | } 1620 | } 1621 | else { 1622 | x->sb_dur[x->sb_index] = x->be_dur[i]; 1623 | x->sb_tie[x->sb_index] = x->be_tie[i]; 1624 | x->sb_i[x->sb_index] = x->be_i[i]; // input number (original input index) 1625 | x->sb_rii[x->sb_index] = x->be_rii[i]; // raw input number 1626 | x->sb_tup[x->sb_index] = x->be_tup[i]; // tuplet 1627 | x->sb_bar_n[x->sb_index] = x->be_bar_n[i]; // bar number 1628 | x->sb_beat_n[x->sb_index] = x->be_beat_n[i]; 1629 | if (x->debug >= 1) post("%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\tregular_loop", x->sb_index, x->sb_bar_n[x->sb_index], x->sb_beat_n[x->sb_index], x->sb_i[x->sb_index], x->sb_rii[x->sb_index], x->sb_dur[x->sb_index], x->sb_tie[x->sb_index], x->sb_tup[x->sb_index]); 1630 | x->sb_index++; 1631 | } 1632 | } 1633 | post("notes: ... Formatting Score... "); 1634 | //// _______________________________________________ ENGRAVING Programs 1635 | char o_pitch[10], o_jump[15], o_text[64]; 1636 | int o_dur, t, f, tp; 1637 | char buf[MAXPDSTRING], partname[MAXPDSTRING], scorename[MAXPDSTRING], linename[MAXPDSTRING]; 1638 | int m, tempint, span_switch, gliss_switch, clu_switch, gliss_break_switch; 1639 | int jj = t= m = tempint = tp = span_switch = gliss_switch = clu_switch = gliss_break_switch = 0; 1640 | f = 1; 1641 | 1642 | 1643 | FILE *fp1, *fp2; 1644 | //// _______________________________________________ OPEN FILE 1645 | canvas_makefilename(x->x_canvas, s->s_name, buf, MAXPDSTRING); /// This is a Pd function to get the path relative to the canvas 1646 | sys_bashfilename(buf, buf); 1647 | strcpy( scorename, buf); 1648 | strcat( scorename, ".ly"); 1649 | fp1 = fopen(scorename, "w"); 1650 | if(!fp1) { 1651 | pd_error(x, "%s: couldn't create", buf); 1652 | return; 1653 | } 1654 | //// _______________________________________________ WRITE SCORE 1655 | else { 1656 | post("notes: writing into %s", scorename); 1657 | fprintf(fp1, "%% [notes] external for Pure Data\n%% development-version August 16, 2018 \n%% by Jaime E. Oliver La Rosa\n%% la.rosa@nyu.edu\n%% @ the Waverly Labs in NYU MUSIC FAS\n%% Open this file with Lilypond\n%% more information is available at lilypond.org\n%% Released under the GNU General Public License.\n\n"); 1658 | fprintf(fp1, "%% HEADERS\n\nglissandoSkipOn = {\n\t\\override NoteColumn.glissando-skip = ##t\n\t\\hide NoteHead\n\t\\hide Accidental\n\t\\hide Tie\n\t\\override NoteHead.no-ledgers = ##t\n}\n\nglissandoSkipOff = {\n\t\\revert NoteColumn.glissando-skip\n\t\\undo \\hide NoteHead\n\t\\undo \\hide Tie\n\t\\undo \\hide Accidental\n\t\\revert NoteHead.no-ledgers\n}\n"); 1659 | 1660 | if (x->auth_n > 0 || x->titl_n > 0 || x->sub_title_n > 0) { 1661 | fprintf(fp1, "\n\\header {"); 1662 | if (x->auth_n > 0) { 1663 | fprintf(fp1, "\n\tcomposer = \""); 1664 | for(i=0; iauth_n; i++){ 1665 | fprintf(fp1, "%1.32s ", x->author[i]); 1666 | } 1667 | fprintf(fp1, "\""); 1668 | } 1669 | if (x->titl_n > 0) { 1670 | fprintf(fp1, "\n\ttitle = \""); 1671 | for(i=0; ititl_n; i++){ 1672 | fprintf(fp1, "%1.32s ", x->title[i]); 1673 | } 1674 | fprintf(fp1, "\""); 1675 | } 1676 | if (x->sub_title_n > 0) { 1677 | fprintf(fp1, "\n\tsubtitle = \""); 1678 | for(i=0; isub_title_n; i++){ 1679 | fprintf(fp1, "%1.32s ", x->sub_title[i]); 1680 | } 1681 | fprintf(fp1, "\""); 1682 | } 1683 | fprintf(fp1, "\n}\n\n"); 1684 | } // HEADER Title, subtitle, and Author 1685 | //// ___________________________________________________ OPEN PART FILE 1686 | strcpy( partname, buf); 1687 | strcat( partname, "_part.ly"); 1688 | fp2 = fopen(partname, "w"); 1689 | if(!fp2) { 1690 | pd_error(x, "%s: couldn't create", buf); 1691 | return; 1692 | } 1693 | else { 1694 | strcpy(linename, x->inst); 1695 | strcat(linename, "_part = "); 1696 | fprintf(fp2, "%s", linename); 1697 | for (i=0; isb_index; i++) { 1698 | j = x->sb_rii[i]; 1699 | // post("%d, pittttt=%f", j, x->ri_pit[j][0]); 1700 | if (x->ri_pit[j][0] > 0) { 1701 | // post("found first pitch"); 1702 | temp_f = x->ri_pit[j][0]; 1703 | find_relative((int) temp_f, (FILE *) fp2); 1704 | x->lastpit = (int) temp_f; 1705 | break; 1706 | } 1707 | } // find relative 1708 | fprintf(fp2, "\\time %i/%i\n\n", x->bar_info[0][1], x->bar_info[0][2]); // METER 1709 | if(x->tempo == 1) { 1710 | for(k=0; k<64; k++){ 1711 | t = (int) exp2( (float) k ); 1712 | if ( x->ri_tmp[0][0] == t ) { 1713 | k=t; 1714 | t=0; 1715 | k = x->refdur / k; 1716 | fprintf(fp2, "\\tempo %i = %i\n\n", k, x->ri_tmp[0][1]); 1717 | break; 1718 | } 1719 | else if ( x->ri_tmp[0][0] == t / 2 * 3) { 1720 | k=t; 1721 | t=1; 1722 | k = x->refdur / k; 1723 | fprintf(fp2, "\\tempo %i. = %i\n\n", k, x->ri_tmp[0][1]); 1724 | break; 1725 | } 1726 | } 1727 | } // TEMPO 1728 | find_clef((int) x->ri_clef[0], (FILE *) fp2); // CLEF 1729 | //// __________________________________________//// __________________________________________| 1730 | //// ________________________ WRITE SOME NOTES //// __________________________________________| 1731 | //// __________________________________________//// __________________________________________V 1732 | fprintf(fp2, "\n%% ________________________________________bar 1 :\n"); 1733 | for (i=0; isb_index; i++) { 1734 | jj=j+1; 1735 | j = x->sb_rii[i]; 1736 | ///////////////////////////// SEPARATION 1737 | // close tupletttt: ________________________________________________________ 1738 | if (i>0 &&((x->sb_tup[i] > x->sb_tup[i-1] && x->sb_tup[i-1] > -1) || (x->sb_tup[i]==-1 && x->sb_tup[i-1] > -1)) ) { 1739 | fprintf(fp2, "} "); 1740 | tp = 0; 1741 | } 1742 | // GRACES NOTES 1743 | if (i>0 && j!=jj && x->ri_index_sort[jj]==3 && x->sb_tie[i-1] != 1) { 1744 | // if (x->ri_index_sort[0]==3) jj=0; 1745 | // post("GRACEEEEEEEEEE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); 1746 | tempint=j; 1747 | find_grace((int) x->ri_grc[jj][0], (FILE *) fp2); 1748 | // post("j=%d\tjj=%d", j, jj); 1749 | for (j = jj; j < tempint; j++) { 1750 | if (x->ri_index_sort[j]!=3) { 1751 | post("breaking grace"); 1752 | j=jj+1; 1753 | break; 1754 | } 1755 | // post("grace loop=%d\t x->ri_index_sort[j] == %d", j, x->ri_index_sort[j]); 1756 | // text Spans_____________________________________________________ 1757 | if (x->ri_txt_spn[j][0] == 1 && x->ri_txt_spn_n[j] > 0) { 1758 | if (i==0 || j != x->sb_rii[i-1]) { 1759 | fprintf(fp2, "\n\t\\once \\override TextSpanner.bound-details.left.text = #\"" ); 1760 | for (k=0; kri_txt_spn[j][1]; k++){ 1761 | strcpy( o_text, x->ri_txt[j][k]); 1762 | fprintf(fp2, "%1.32s ", o_text); 1763 | } 1764 | fprintf(fp2, "\" "); 1765 | } 1766 | } 1767 | if (x->ri_txt_spn[j][2] == 1 && x->ri_txt_spn_n[j] > 0) { 1768 | if (i==0 || j != x->sb_rii[i-1]) { 1769 | fprintf(fp2, "\n\t\\once \\override TextSpanner.bound-details.right.text = #\" " ); 1770 | for (k=x->ri_txt_spn[j][1]; kri_txt_spn[j][3]; k++){ 1771 | strcpy( o_text, x->ri_txt[j][k]); 1772 | fprintf(fp2, "%1.32s ", o_text); 1773 | } 1774 | fprintf(fp2, "\" "); 1775 | } 1776 | } 1777 | if (x->ri_txt_spn[j][0] == 1 && x->ri_txt_spn_n[j] > 0) { 1778 | if (i==0 || j != x->sb_rii[i-1]) { 1779 | if (x->ri_txt_spn[j][4] == 4)fprintf(fp2, "\n\t\\once \\override TextSpanner.style = #'line "); 1780 | else if (x->ri_txt_spn[j][4] == 2 || x->ri_txt_spn[j][4] == 5) { 1781 | if (x->ri_txt_spn[j][4] == 2) fprintf(fp2, "\n\t\\once \\override TextSpanner.style = #'dashed-line "); 1782 | if (x->ri_txt_spn[j][4] == 5) fprintf(fp2, "\n\t\\once \\override TextSpanner.style = #'line "); 1783 | fprintf(fp2, "\n\t\\once \\override TextSpanner.bound-details.right.padding = #-2 "); 1784 | fprintf(fp2, "\n\t\\once \\override TextSpanner.bound-details.right.stencil-align-dir-y = #UP "); 1785 | fprintf(fp2, "\n\t\\once \\override TextSpanner.bound-details.right.text = \\markup { \\draw-line #'(0 . -1) \" "); 1786 | for (k=x->ri_txt_spn[j][1]; kri_txt_spn[j][3]; k++){ 1787 | strcpy( o_text, x->ri_txt[j][k]); 1788 | fprintf(fp2, "%1.32s ", o_text); 1789 | } 1790 | fprintf(fp2, "\"} "); 1791 | } 1792 | else if (x->ri_txt_spn[j][4] == 3 || x->ri_txt_spn[j][4] == 6) { 1793 | fprintf(fp2, "\n\t\\once \\override TextSpanner.bound-details.right.arrow = ##t "); 1794 | if (x->ri_txt_spn[j][4] == 3) fprintf(fp2, "\n\t\\once \\override TextSpanner.style = #'dashed-line "); 1795 | if (x->ri_txt_spn[j][4] == 6) fprintf(fp2, "\n\t\\once \\override TextSpanner.style = #'line "); 1796 | } 1797 | else fprintf(fp2, "\n\t\\once \\override TextSpanner.style = #'dashed-line "); 1798 | fprintf(fp2, "\n"); 1799 | } 1800 | } 1801 | // chord run ________________________________________________________ 1802 | if (x->ri_cho[j]>1 || x->ri_hrm_n[j]>0) fprintf(fp2, "<"); 1803 | for (k=0; kri_cho[j]; k++) { 1804 | // note heads 1805 | if (x->ri_nhs_n[j]>0) 1806 | find_notehead((int) x->ri_nhs[j][0], (FILE *) fp2); 1807 | // pitch 1808 | find_pitch(x->ri_pit[j][k], x->ri_acc[j], o_pitch); 1809 | fprintf(fp2, "%1.8s", o_pitch); 1810 | // jumps 1811 | if (i>0) { // interval jumps 1812 | if (k==0) { 1813 | if (find_jump((int) x->ri_pit[j][k], (int) x->lastpit, (int) x->ri_acc[j], o_jump)==1) 1814 | fprintf(fp2, "%1.8s", o_jump); 1815 | } 1816 | else { 1817 | if (find_jump((int) x->ri_pit[j][k], (int) x->lastpit_ch, (int) x->ri_acc[j], o_jump)==1) 1818 | fprintf(fp2, "%1.8s", o_jump); 1819 | } 1820 | } 1821 | else { 1822 | if (k==0) { 1823 | if (find_jump((int) x->ri_pit[j][k], (int) x->lastpit, (int) x->ri_acc[j], o_jump)==1) 1824 | fprintf(fp2, "%1.8s", o_jump); 1825 | } 1826 | else { 1827 | if (find_jump((int) x->ri_pit[j][k], (int) x->lastpit_ch, (int) x->ri_acc[j], o_jump)==1) 1828 | fprintf(fp2, "%1.8s", o_jump); 1829 | } 1830 | } 1831 | // stopped harmonics 1832 | m=0; 1833 | if (x->ri_hrm_n[j]>0) { 1834 | m = (int) x->ri_hrm[j][k] - 1; 1835 | temp_f = (float) harmonics[m][0]; 1836 | temp_f += x->ri_pit[j][k]; 1837 | fprintf(fp2, " "); 1838 | find_pitch(temp_f, x->ri_acc[j], o_pitch); 1839 | fprintf(fp2, "%1.8s", o_pitch); 1840 | if (find_jump((int) temp_f, (int) x->ri_pit[j][k], (int) x->ri_acc[j], o_jump)==1) 1841 | fprintf(fp2, "%1.8s", o_jump); 1842 | fprintf(fp2, "\\harmonic "); 1843 | 1844 | /* temp_f2 = (float) harmonics[m][1]; 1845 | temp_f2 += x->ri_pit[j][k]; 1846 | fprintf(fp2, " \\parenthesize "); 1847 | find_pitch(temp_f2, x->ri_acc[j], o_pitch); 1848 | fprintf(fp2, "%1.8s", o_pitch); 1849 | if (find_jump((int) temp_f2, (int) temp_f, (int) x->ri_acc[j], o_jump)==1) 1850 | fprintf(fp2, "%1.8s", o_jump);*/ 1851 | } 1852 | if (x->ri_cho[j]>1) fprintf(fp2, " "); 1853 | if (x->ri_pit[j][0] > 0) x->lastpit = x->ri_pit[j][0]; 1854 | if (x->ri_pit[j][k] > 0) x->lastpit_ch = x->ri_pit[j][k]; 1855 | } 1856 | if (x->ri_cho[j]>1 || x->ri_hrm_n[j]>0) { 1857 | if (x->ri_art_n[j] > 0 && j != x->sb_rii[i-1]) { 1858 | for (k=0; kri_art_n[j]; k++){ 1859 | if (x->ri_art[j][k]==25)find_articulation((int) x->ri_art[j][k], (FILE *) fp2); 1860 | } 1861 | } 1862 | else if (i == 0 && x->ri_art_n[j] > 0) { 1863 | for (k=0; kri_art_n[j]; k++){ 1864 | if (x->ri_art[j][k]==25)find_articulation((int) x->ri_art[j][k], (FILE *) fp2); 1865 | } 1866 | } 1867 | fprintf(fp2, ">"); 1868 | } 1869 | // GRACE duration _________________________________________ 1870 | o_dur = x->ri_grc[j][1]; 1871 | fprintf(fp2, "%i", o_dur); 1872 | // tie ________________________________________________________ 1873 | if (x->sb_tie[i] == 1) fprintf(fp2, "~"); 1874 | // smallnumbers ________________________________________________________ 1875 | if (x->ri_smn_n[j] > 0 && j != x->sb_rii[i-1]) { 1876 | for (k=0; kri_smn_n[j]; k++){ 1877 | find_small_numbers((int) x->ri_smn[j][k], (FILE *) fp2); 1878 | } 1879 | } 1880 | else if (i == 0 && x->ri_smn_n[j] > 0) { 1881 | for (k=0; kri_smn_n[j]; k++){ 1882 | find_small_numbers((int) x->ri_smn[j][k], (FILE *) fp2); 1883 | } 1884 | } 1885 | // articulation ________________________________________________________ 1886 | if (x->ri_art_n[j] > 0 && j != x->sb_rii[i-1]) { 1887 | for (k=0; kri_art_n[j]; k++){ 1888 | // post("JK:\tj=%d\tk=%d", j, k); 1889 | find_articulation((int) x->ri_art[j][k], (FILE *) fp2); //if (x->ri_art[j][k]!=24 || (x->ri_cho[j]>1 && x->ri_art[j][k]!=25)) 1890 | } 1891 | } 1892 | // dynamics ________________________________________________________ 1893 | if (x->ri_dyn_n[j] > 0 && j != x->sb_rii[i-1]) for (k=0; kri_dyn_n[j]; k++) find_dynamics((int) x->ri_dyn[j][k], (FILE *) fp2); 1894 | else if (i == 0 && x->ri_dyn_n[j] > 0) { 1895 | for (k=0; kri_dyn_n[j]; k++){ 1896 | find_dynamics((int) x->ri_dyn[j][k], (FILE *) fp2); 1897 | } 1898 | } 1899 | // harp-pedal ________________________________________________________ 1900 | if (x->ri_hpp_n[j] > 0 && j != x->sb_rii[i-1]) { 1901 | fprintf(fp2, "_\\markup { \\combine \\arrow-head #Y #UP ##t \\draw-line #'(0 . -2)}_\\markup { \\harp-pedal "); 1902 | strcpy( o_text, x->ri_hpp[j]); 1903 | fprintf(fp2, "%s", o_text); 1904 | fprintf(fp2, " }"); 1905 | } 1906 | // texts ________________________________________________________ 1907 | if (x->ri_txt_n[j] > 0 && j != x->sb_rii[i-1]) { 1908 | fprintf(fp2, "-\\markup {"); 1909 | for (k=0; kri_txt_n[j]; k++){ 1910 | strcpy( o_text, x->ri_txt[j][k]); 1911 | fprintf(fp2, "%1.32s ", o_text); 1912 | } 1913 | fprintf(fp2, "}"); 1914 | } 1915 | else if (i == 0 && x->ri_txt_n[j] > 0) { 1916 | fprintf(fp2, "_\\markup {"); 1917 | for (k=0; kri_txt_n[j]; k++){ 1918 | strcpy( o_text, x->ri_txt[j][k]); 1919 | fprintf(fp2, "%1.32s ", o_text); 1920 | } 1921 | fprintf(fp2, "}"); 1922 | } 1923 | 1924 | // text Spans_____________________________________________________ 1925 | if (x->ri_txt_spn[j][0] == 1 && x->ri_txt_spn_n[j] > 0) { 1926 | if (i==0 || j != x->sb_rii[i-1]) { 1927 | if (span_switch == 0) { 1928 | fprintf(fp2, "\\startTextSpan" ); 1929 | span_switch = 1; 1930 | } 1931 | } 1932 | } 1933 | else if (x->ri_txt_spn[j][0] == 2 && x->ri_txt_spn_n[j] > 0) { 1934 | if (i==0 || j != x->sb_rii[i-1]) { 1935 | if (span_switch == 1) { 1936 | fprintf(fp2, "\\stopTextSpan" ); 1937 | span_switch = 0; 1938 | } 1939 | } 1940 | } 1941 | 1942 | // spans ________________________________________________________ 1943 | if (x->ri_spa_n[j] > 0 && j != x->sb_rii[i-1]) { 1944 | for (k=0; kri_spa_n[j]; k++){ 1945 | //post("BANG"); 1946 | find_span((int) x->ri_spa[j][k], (FILE *) fp2); 1947 | } 1948 | } 1949 | else if (i == 0 && x->ri_spa_n[j] > 0) { 1950 | for (k=0; kri_spa_n[j]; k++){ 1951 | //post("BONG"); 1952 | find_span((int) x->ri_spa[j][k], (FILE *) fp2); 1953 | } 1954 | } 1955 | fprintf(fp2, " "); 1956 | } 1957 | fprintf(fp2, "} "); 1958 | fprintf(fp2, " "); 1959 | // post("close grace"); 1960 | //j+=1; 1961 | j=tempint; 1962 | } 1963 | // BAR BREAK ________________________________________________________ 1964 | if (i>0 && x->sb_bar_n[i] != x->sb_bar_n[i-1]) { 1965 | // if(f==2) fprintf(fp2, "]"); 1966 | fprintf(fp2, " |\n%% ________________________________________bar %i :\n", x->sb_bar_n[i]+1); 1967 | f = 1; 1968 | // write meter 1969 | if ( (i>0) && (x->bar_info[x->sb_bar_n[i]][1] != x->bar_info[x->sb_bar_n[i-1]][1] || x->bar_info[x->sb_bar_n[i]][2] != x->bar_info[x->sb_bar_n[i-1]][2] ) ) { 1970 | fprintf(fp2, "\\time %i/%i\n\n", x->bar_info[x->sb_bar_n[i]][1], x->bar_info[x->sb_bar_n[i]][2]); 1971 | } 1972 | } 1973 | // BEAT Tab ________________________________________________________ 1974 | else if (i>0 && x->sb_beat_n[i] != x->sb_beat_n[i-1]) { 1975 | // if(f==2) fprintf(fp2, "]"); 1976 | fprintf(fp2, "\n"); 1977 | for (k=0; ksb_beat_n[i]; k++) { 1978 | fprintf(fp2, "\t"); 1979 | } 1980 | f = 1; 1981 | } 1982 | // SPACE ________________________________________________________ 1983 | else { 1984 | fprintf(fp2, " "); 1985 | } 1986 | // write tempo 1987 | if(x->tempo == 1) { 1988 | if ( (x->ri_tmp[j][0] != x->ri_tmp[j-1][0] || x->ri_tmp[j][1] != x->ri_tmp[j-1][1]) && j != x->sb_rii[i-1] ) { 1989 | for(k=0; k<64; k++){ 1990 | t = (int) exp2( (float) k ); 1991 | if ( x->ri_tmp[j][0] == t ) { 1992 | k=t; 1993 | t=0; 1994 | k = x->refdur / k; 1995 | fprintf(fp2, " \\tempo %i = %i ", k, x->ri_tmp[j][1]); 1996 | break; 1997 | } 1998 | else if ( x->ri_tmp[j][0] == t / 2 * 3) { 1999 | k=t; 2000 | t=1; 2001 | k = x->refdur / k; 2002 | fprintf(fp2, " \\tempo %i. = %i ", k, x->ri_tmp[j][1]); 2003 | break; 2004 | } 2005 | } 2006 | } 2007 | } 2008 | //////////////////////////// NOTE EXPRESSION 2009 | // Clef 2010 | if (i>0 && x->ri_clef[j] != x->ri_clef[j-1]) { 2011 | find_clef((int) x->ri_clef[j], (FILE *) fp2); 2012 | } 2013 | // Pitched Trill 2014 | if (x->ri_spa_p[j] > 0 && ( i==0 || j != x->sb_rii[i-1] )) 2015 | fprintf(fp2, "\\pitchedTrill "); 2016 | // text Spans_____________________________________________________ 2017 | if (x->ri_txt_spn[j][0] == 1 && x->ri_txt_spn_n[j] > 0) { 2018 | if (i==0 || j != x->sb_rii[i-1]) { 2019 | fprintf(fp2, "\n\t\\once \\override TextSpanner.bound-details.left.text = #\"" ); 2020 | for (k=0; kri_txt_spn[j][1]; k++){ 2021 | strcpy( o_text, x->ri_txt[j][k]); 2022 | fprintf(fp2, "%1.32s ", o_text); 2023 | } 2024 | fprintf(fp2, "\" "); 2025 | } 2026 | } 2027 | if (x->ri_txt_spn[j][2] == 1 && x->ri_txt_spn_n[j] > 0) { 2028 | if (i==0 || j != x->sb_rii[i-1]) { 2029 | fprintf(fp2, "\n\t\\once \\override TextSpanner.bound-details.right.text = #\" " ); 2030 | for (k=x->ri_txt_spn[j][1]; kri_txt_spn[j][3]; k++){ 2031 | strcpy( o_text, x->ri_txt[j][k]); 2032 | fprintf(fp2, "%1.32s ", o_text); 2033 | } 2034 | fprintf(fp2, "\" "); 2035 | } 2036 | } 2037 | if (x->ri_txt_spn[j][0] == 1 && x->ri_txt_spn_n[j] > 0) { 2038 | if (i==0 || j != x->sb_rii[i-1]) { 2039 | if (x->ri_txt_spn[j][4] == 4)fprintf(fp2, "\n\t\\once \\override TextSpanner.style = #'line "); 2040 | else if (x->ri_txt_spn[j][4] == 2 || x->ri_txt_spn[j][4] == 5) { 2041 | if (x->ri_txt_spn[j][4] == 2) fprintf(fp2, "\n\t\\once \\override TextSpanner.style = #'dashed-line "); 2042 | if (x->ri_txt_spn[j][4] == 5) fprintf(fp2, "\n\t\\once \\override TextSpanner.style = #'line "); 2043 | fprintf(fp2, "\n\t\\once \\override TextSpanner.bound-details.right.padding = #-2 "); 2044 | fprintf(fp2, "\n\t\\once \\override TextSpanner.bound-details.right.stencil-align-dir-y = #UP "); 2045 | fprintf(fp2, "\n\t\\once \\override TextSpanner.bound-details.right.text = \\markup { \\draw-line #'(0 . -1) \" "); 2046 | for (k=x->ri_txt_spn[j][1]; kri_txt_spn[j][3]; k++){ 2047 | strcpy( o_text, x->ri_txt[j][k]); 2048 | fprintf(fp2, "%1.32s ", o_text); 2049 | } 2050 | fprintf(fp2, "\"} "); 2051 | } 2052 | else if (x->ri_txt_spn[j][4] == 3 || x->ri_txt_spn[j][4] == 6) { 2053 | fprintf(fp2, "\n\t\\once \\override TextSpanner.bound-details.right.arrow = ##t "); 2054 | if (x->ri_txt_spn[j][4] == 3) fprintf(fp2, "\n\t\\once \\override TextSpanner.style = #'dashed-line "); 2055 | if (x->ri_txt_spn[j][4] == 6) fprintf(fp2, "\n\t\\once \\override TextSpanner.style = #'line "); 2056 | } 2057 | else fprintf(fp2, "\n\t\\once \\override TextSpanner.style = #'dashed-line "); 2058 | fprintf(fp2, "\n"); 2059 | } 2060 | } 2061 | // tuplet start ________________________________________________________ 2062 | if (x->sb_tup[i] > -1 && x->sb_tup[i] != x->sb_tup[i-1] ) { 2063 | fprintf(fp2, " \\tuplet %i/%i { ", x->tp_info[x->sb_tup[i]][1], x->tp_info[x->sb_tup[i]][2]); 2064 | tp = 1; 2065 | } 2066 | /////// PITCH ________________________________________________________ 2067 | // note heads 2068 | if (x->ri_nhs_n[j]>0) 2069 | find_notehead((int) x->ri_nhs[j][0], (FILE *) fp2); 2070 | // Chord? ________________________________________________________ 2071 | //cluster 2072 | if (x->ri_clu[j]==1 && clu_switch == 0) { 2073 | fprintf(fp2, "\\makeClusters {"); 2074 | clu_switch = 1; 2075 | } 2076 | else if (x->ri_clu[j]==0 && clu_switch == 1) { 2077 | fprintf(fp2, "}"); 2078 | clu_switch = 0; 2079 | } 2080 | //arpeggio 2081 | if (x->ri_cho[j]>1 && x->ri_arp[j]>0) { 2082 | if (i==0 || j != x->sb_rii[i-1]) { 2083 | find_arpeggio((int) x->ri_arp[j], (FILE *) fp2); 2084 | } 2085 | } 2086 | // actual chord 2087 | if (x->ri_cho[j]>1 || x->ri_hrm_n[j]>0) fprintf(fp2, "<"); 2088 | //pitch, jumps, harmonics 2089 | for (k=0; kri_cho[j]; k++) { 2090 | // pitch 2091 | find_pitch(x->ri_pit[j][k], x->ri_acc[j], o_pitch); 2092 | fprintf(fp2, "%1.8s", o_pitch); 2093 | // jumps 2094 | if (i>0) { // interval jumps 2095 | if (k==0) { 2096 | if (find_jump((int) x->ri_pit[j][k], (int) x->lastpit, (int) x->ri_acc[j], o_jump)==1) 2097 | fprintf(fp2, "%1.8s", o_jump); 2098 | } 2099 | else { 2100 | if (find_jump((int) x->ri_pit[j][k], (int) x->lastpit_ch, (int) x->ri_acc[j], o_jump)==1) 2101 | fprintf(fp2, "%1.8s", o_jump); 2102 | } 2103 | } 2104 | else { 2105 | if (k==0) { 2106 | if (find_jump((int) x->ri_pit[j][k], (int) x->lastpit, (int) x->ri_acc[j], o_jump)==1) 2107 | fprintf(fp2, "%1.8s", o_jump); 2108 | } 2109 | else { 2110 | if (find_jump((int) x->ri_pit[j][k], (int) x->lastpit_ch, (int) x->ri_acc[j], o_jump)==1) 2111 | fprintf(fp2, "%1.8s", o_jump); 2112 | } 2113 | } 2114 | // harmonics 2115 | if (x->ri_hrm_n[j]>0) { 2116 | m = (int) x->ri_hrm[j][k] - 1; 2117 | temp_f = (float) harmonics[m][0]; 2118 | temp_f += x->ri_pit[j][k]; 2119 | fprintf(fp2, " "); 2120 | find_pitch(temp_f, x->ri_acc[j], o_pitch); 2121 | fprintf(fp2, "%1.8s", o_pitch); 2122 | if (find_jump((int) temp_f, (int) x->ri_pit[j][k], (int) x->ri_acc[j], o_jump)==1) 2123 | fprintf(fp2, "%1.8s", o_jump); 2124 | fprintf(fp2, "\\harmonic "); 2125 | 2126 | /* temp_f2 = (float) harmonics[m][1]; 2127 | temp_f2 += x->ri_pit[j][k]; 2128 | fprintf(fp2, " \\parenthesize "); 2129 | find_pitch(temp_f2, x->ri_acc[j], o_pitch); 2130 | fprintf(fp2, "%1.8s", o_pitch); 2131 | if (find_jump((int) temp_f2, (int) temp_f, (int) x->ri_acc[j], o_jump)==1) 2132 | fprintf(fp2, "%1.8s", o_jump); */ 2133 | } 2134 | //prepare for next loop cycle 2135 | if (x->ri_cho[j]>1 || x->ri_hrm_n[j]>0) fprintf(fp2, " "); 2136 | if (x->ri_pit[j][0] > 0) x->lastpit = x->ri_pit[j][0]; 2137 | if (x->ri_pit[j][k] > 0) x->lastpit_ch = x->ri_pit[j][k]; 2138 | } 2139 | // close chord 2140 | if (x->ri_cho[j]>1|| x->ri_hrm_n[j]>0) { 2141 | if (x->ri_art_n[j] > 0) { 2142 | if (i==0 || j != x->sb_rii[i-1]) { 2143 | for (k=0; kri_art_n[j]; k++){ 2144 | if (x->ri_art[j][k]==25)find_articulation((int) x->ri_art[j][k], (FILE *) fp2); 2145 | } 2146 | } 2147 | } 2148 | fprintf(fp2, ">"); 2149 | } 2150 | /////// DURATION ________________________________________________________ 2151 | for(k=0; k<64; k++){ 2152 | t = (int) exp2( (float) k ); 2153 | if ( x->sb_dur[i] == t ) { 2154 | k=t; 2155 | t=0; 2156 | break; 2157 | } 2158 | else if ( x->sb_dur[i] == t / 2 * 3) { 2159 | k=t; 2160 | t=1; 2161 | break; 2162 | } 2163 | } 2164 | o_dur = x->refdur / k; 2165 | /* // If Glissing, break quarter notes or longer into 8th notes 2166 | gliss_break_switch = 0; 2167 | if (i==0 || j != x->sb_rii[i-1]) { 2168 | for (k=0; kri_spa_n[j]; k++){ 2169 | if ( x->ri_spa[j][k] == 8 || 2170 | (gliss_switch == 1 && j != x->sb_rii[i+1]) 2171 | ){ 2172 | gliss_break_switch = 1; 2173 | } 2174 | } 2175 | } 2176 | if (gliss_switch != 0 && gliss_break_switch == 0) { 2177 | // post("------------------------ o_dur = %d", o_dur); 2178 | if (o_dur == 4){ 2179 | o_dur = 8; 2180 | fprintf(fp2, "%i", o_dur); 2181 | fprintf(fp2, " %1.8s", o_pitch); 2182 | if( t == 1) { 2183 | fprintf(fp2, " %1.8s", o_pitch); 2184 | } 2185 | } 2186 | else if (o_dur == 2) { 2187 | o_dur = 8; 2188 | fprintf(fp2, "%i", o_dur); 2189 | for (k=0; k<3; k++) { 2190 | fprintf(fp2, " %1.8s", o_pitch); 2191 | } 2192 | if( t == 1) { 2193 | for (k=0; k<2; k++) { 2194 | fprintf(fp2, " %1.8s", o_pitch); 2195 | } 2196 | } 2197 | } 2198 | else if (o_dur == 1) { 2199 | o_dur = 8; 2200 | fprintf(fp2, "%i", o_dur); 2201 | for (k=0; k<7; k++) { 2202 | fprintf(fp2, " %1.8s", o_pitch); 2203 | } 2204 | if( t == 1) { 2205 | for (k=0; k<4; k++) { 2206 | fprintf(fp2, " %1.8s", o_pitch); 2207 | } 2208 | } 2209 | } 2210 | } 2211 | else { 2212 | fprintf(fp2, "%i", o_dur); 2213 | // dot ________________________________________________________ 2214 | if (t==1) fprintf(fp2, "."); 2215 | }*/ 2216 | fprintf(fp2, "%i", o_dur); 2217 | // dot ________________________________________________________ 2218 | if (t==1) fprintf(fp2, "."); //replace till here when enabling gliss breaking 2219 | // tremolo ________________________________________________________ 2220 | if (x->ri_trm[j] > 0) fprintf(fp2, ":%i", x->ri_trm[j]); 2221 | // tie ________________________________________________________ 2222 | if ((x->ri_pit[j][0] > 0) && 2223 | (x->sb_tie[i] == 1 ) ) { 2224 | tempint = 1; 2225 | if (x->ri_spa_n[j] > 0) { 2226 | for (k=0; kri_spa_n[j]; k++){ 2227 | if (x->ri_spa[j][k] == 0 || x->ri_spa[j][k] == 7) { 2228 | tempint = 0; 2229 | } 2230 | } 2231 | } // && (x->ri_pit[i][0] == x->ri_pit[i+1][0]) 2232 | if (tempint == 1 ) fprintf(fp2, "~"); 2233 | } 2234 | // arpeggio 2235 | if ((x->ri_cho[j]>1 || x->ri_hrm_n[j]>0) && x->ri_arp[j]>0) { 2236 | if (i==0 || j != x->sb_rii[i-1]) { 2237 | fprintf(fp2, "\\arpeggio"); 2238 | } 2239 | } 2240 | // Close group at BAR and BEAT BREAK _________________________________________ 2241 | if ( (i>0 && x->sb_bar_n[i] != x->sb_bar_n[i+1]) || (i>0 && x->sb_beat_n[i] != x->sb_beat_n[i+1]) ) { 2242 | // if(f==2) fprintf(fp2, "]"); 2243 | } 2244 | /////// ARTICULATION, DYNAMICS, PHRASING, MARKUPS, ETC. 2245 | // smallnumbers ________________________________________________________ 2246 | if (x->ri_smn_n[j] > 0) { 2247 | if (i==0 || j != x->sb_rii[i-1]) { 2248 | for (k=0; kri_smn_n[j]; k++){ 2249 | find_small_numbers((int) x->ri_smn[j][k], (FILE *) fp2); 2250 | } 2251 | } 2252 | } 2253 | // articulation ________________________________________________________ 2254 | if (x->ri_art_n[j] > 0) { 2255 | if (i==0 || j != x->sb_rii[i-1]) { 2256 | for (k=0; kri_art_n[j]; k++){ 2257 | find_articulation((int) x->ri_art[j][k], (FILE *) fp2); //if (x->ri_art[j][k]!=24 || (x->ri_cho[j]>1 && x->ri_art[j][k]!=25)) 2258 | } 2259 | } 2260 | } 2261 | // dynamics ________________________________________________________ 2262 | if (x->ri_dyn_n[j] > 0) { 2263 | if (i==0 || j != x->sb_rii[i-1]) { 2264 | for (k=0; kri_dyn_n[j]; k++){ 2265 | find_dynamics((int) x->ri_dyn[j][k], (FILE *) fp2); 2266 | } 2267 | } 2268 | } 2269 | // harp-pedal ________________________________________________________ 2270 | if (x->ri_hpp_n[j] > 0 && j != x->sb_rii[i-1]) { 2271 | fprintf(fp2, "_\\markup { \\combine \\arrow-head #Y #UP ##t \\draw-line #'(0 . -2)}_\\markup { \\harp-pedal "); 2272 | strcpy( o_text, x->ri_hpp[j]); 2273 | fprintf(fp2, "%s", o_text); 2274 | fprintf(fp2, " }"); 2275 | } 2276 | // texts ________________________________________________________ 2277 | if (x->ri_txt_n[j] > 0 && x->ri_txt_spn[j][0] == 0) { 2278 | if (i==0 || j != x->sb_rii[i-1]) { 2279 | fprintf(fp2, "^\\markup {"); 2280 | for (k=0; kri_txt_n[j]; k++){ 2281 | strcpy( o_text, x->ri_txt[j][k]); 2282 | fprintf(fp2, "%1.32s ", o_text); 2283 | } 2284 | fprintf(fp2, "}"); 2285 | } 2286 | } 2287 | // text Spans_____________________________________________________ 2288 | if (x->ri_txt_spn[j][0] == 1 && x->ri_txt_spn_n[j] > 0) { 2289 | if (i==0 || j != x->sb_rii[i-1]) { 2290 | if (span_switch == 0) { 2291 | fprintf(fp2, "\\startTextSpan" ); 2292 | span_switch = 1; 2293 | } 2294 | } 2295 | } 2296 | else if (x->ri_txt_spn[j][0] == 2 && x->ri_txt_spn_n[j] > 0) { 2297 | if (i==0 || j != x->sb_rii[i-1]) { 2298 | if (span_switch == 1) { 2299 | fprintf(fp2, "\\stopTextSpan" ); 2300 | span_switch = 0; 2301 | } 2302 | } 2303 | } 2304 | // beat grouping ________________________________________________________ 2305 | if (f == 1 && tp != 1) { 2306 | if ( x->sb_beat_n[i] == x->sb_beat_n[i+1] && x->sb_bar_n[i] == x->sb_bar_n[i+1] ) { 2307 | // fprintf(fp2, "["); 2308 | f = 2; 2309 | } 2310 | else f = 0; 2311 | } 2312 | // spans ________________________________________________________ 2313 | if (x->ri_spa_n[j] > 0) { 2314 | if (i==0 || j != x->sb_rii[i-1]) { 2315 | for (k=0; kri_spa_n[j]; k++){ 2316 | if (x->ri_spa[j][k] == 0 && j == x->sb_rii[i+1]) { 2317 | x->ri_spa[j][k] = 7; 2318 | gliss_switch = 1; 2319 | } 2320 | find_span((int) x->ri_spa[j][k], (FILE *) fp2); 2321 | if (x->ri_spa[j][k] == 8) gliss_switch = 0; 2322 | } 2323 | if (x->ri_spa_p[j] > 0) { 2324 | // pitch 2325 | find_pitch(x->ri_spa_p[j], x->ri_acc[j], o_pitch); 2326 | fprintf(fp2, " %1.8s", o_pitch); 2327 | // jumps 2328 | if (find_jump((int) x->ri_spa_p[j], (int) x->lastpit, (int) x->ri_acc[j], o_jump)==1) 2329 | fprintf(fp2, "%1.8s ", o_jump); 2330 | } 2331 | } 2332 | } 2333 | if (gliss_switch == 1 && j != x->sb_rii[i+1]) { 2334 | gliss_switch = 8; 2335 | find_span((int) gliss_switch, (FILE *) fp2); 2336 | gliss_switch = 0; 2337 | } 2338 | if (gliss_switch == 1 && ( i==0 || j != x->sb_rii[i-1] )) { 2339 | fprintf(fp2, "\\glissandoSkipOn "); 2340 | } 2341 | else { 2342 | for (k=0; kri_spa_n[j]; k++){ 2343 | if (x->ri_spa[j][k] == 7 && ( i==0 || j != x->sb_rii[i-1] )) { 2344 | fprintf(fp2, "\\glissandoSkipOn "); 2345 | gliss_switch = 2; 2346 | } 2347 | } 2348 | } 2349 | fprintf(fp2, " "); 2350 | } 2351 | if(tp == 1) fprintf(fp2, "}"); 2352 | // if(f == 2) fprintf(fp2, "]"); 2353 | fprintf(fp2, "\n}\n"); 2354 | fclose( fp2); 2355 | //// _______________________________________ COPY PART TO MAIN SCORE 2356 | fp2 = fopen(partname, "r"); 2357 | char a; 2358 | a = fgetc(fp2); 2359 | if (a != EOF) fputc(a, fp1); 2360 | while(a != EOF) { 2361 | a = fgetc(fp2); 2362 | if (a != EOF) fputc(a, fp1); 2363 | } 2364 | fclose(fp2); 2365 | //// __________________________________________ SCORE EXPRESSION 2366 | strcpy(linename, x->inst); 2367 | strcat(linename, "_part"); 2368 | fprintf(fp1, "\n\\score {\n\t\\new Staff "); 2369 | if (x->inst_n == 1) fprintf(fp1, "\\with { instrumentName = \"%s\" } ", x->inst); 2370 | fprintf(fp1, "{\n\t\t\\new Voice {\n\t\t\t\\%s\n\t\t}\n\t}\n\t\\layout {", linename); 2371 | fprintf(fp1, "\n\t\t\\mergeDifferentlyHeadedOn"); 2372 | fprintf(fp1, "\n\t\t\\mergeDifferentlyDottedOn"); 2373 | fprintf(fp1, "\n\t\t\\set harmonicDots = ##t"); 2374 | fprintf(fp1, "\n\t\t\\override Glissando.thickness = #4"); 2375 | fprintf(fp1, "\n\t\t\\set Staff.pedalSustainStyle = #'mixed"); 2376 | fprintf(fp1, "\n\t\t\\override TextSpanner.bound-padding = #1.0"); 2377 | fprintf(fp1, "\n\t\t\\override TextSpanner.bound-details.right.padding = #1.3"); 2378 | fprintf(fp1, "\n\t\t\\override TextSpanner.bound-details.right.stencil-align-dir-y = #CENTER"); 2379 | fprintf(fp1, "\n\t\t\\override TextSpanner.bound-details.left.stencil-align-dir-y = #CENTER"); 2380 | fprintf(fp1, "\n\t\t\\override TextSpanner.bound-details.right-broken.text = ##f"); 2381 | fprintf(fp1, "\n\t\t\\override TextSpanner.bound-details.left-broken.text = ##f"); 2382 | fprintf(fp1, "\n\t\t\\override Glissando.minimum-length = #4"); 2383 | fprintf(fp1, "\n\t\t\\override Glissando.springs-and-rods = #ly:spanner::set-spacing-rods"); 2384 | fprintf(fp1, "\n\t\t\\override Glissando.breakable = ##t"); 2385 | fprintf(fp1, "\n\t\t\\override Glissando.after-line-breaking = ##t"); 2386 | fprintf(fp1, "\n\t\t\\set baseMoment = #(ly:make-moment 1/8)"); 2387 | fprintf(fp1, "\n\t\t\\set beatStructure = #'(2 2 2 2)"); 2388 | fprintf(fp1, "\n\t\t#(set-default-paper-size \"a%i", x->papersize); 2389 | if(x->paperorientation==1) fprintf(fp1, "landscape\")"); 2390 | else fprintf(fp1, "\")"); 2391 | fprintf(fp1, "\n\t}\n\t\\midi { }\n}"); 2392 | //// ____________________________________________________________ CLOSE SCORE 2393 | fprintf(fp1, "\n\n\\version \"2.18.2\"\n%% notes Pd External testing version \n"); 2394 | fclose(fp1); 2395 | post("notes: .ly score finished"); 2396 | 2397 | t_atom paths[MAXPDSTRING]; 2398 | SETSYMBOL(&paths[0], gensym(x->inst)); 2399 | SETSYMBOL(&paths[1], gensym(partname)); 2400 | outlet_list(x->x_outlet0, 0, 2, paths); 2401 | } 2402 | 2403 | } 2404 | // compile and open 2405 | if(compile_and_open(buf,scorename,x->debug,x->FOLLOW,x->render,x->open, x->lily_dir)){ 2406 | pd_error(x, "notes: error compiling score"); 2407 | } 2408 | } // if a file is correctly provided. 2409 | else { 2410 | post("notes: ERROR: Can't flush because no input has been provided... you have to enter some notes!"); 2411 | } //exit(1); 2412 | outlet_bang(x->x_outlet2); 2413 | } 2414 | //// ____________________________________________________ CLEAR 2415 | void notes_clear(t_notes *x) { 2416 | x->auth_n = x->titl_n = x->sb_tp_index = x->i_index = x->ri_index = x->tp_index = x->tp_n = x->b_index = x->be_index = x->sb_index = 0; 2417 | x->refdur = 32; 2418 | // x->debug = 0; 2419 | x->tempo = 0; 2420 | x->auth_n = x->titl_n = x->sub_title_n = 0; 2421 | x->ri_mtr[x->ri_index][0] = x->ri_mtr[x->ri_index][1] = 4; 2422 | post("notes: Cleared"); 2423 | } 2424 | //// ____________________________________________________ PRINT 2425 | void notes_print(t_notes *x) { 2426 | post("notes: x->sb_tp_index = %d\nx->i_index = %d\nx->ri_index = %d\nx->tp_index = %d\nx->tp_n = %d\nx->b_index = %d\nx->be_index = %d\nx->sb_index = %d\n", x->sb_tp_index, x->i_index, x->ri_index, x->tp_index, x->tp_n, x->b_index, x->be_index, x->sb_index); 2427 | } 2428 | //// ____________________________________________________ REFERENCE DURATION 2429 | void notes_refdur(t_notes *x, t_floatarg f) { 2430 | x->refdur = f; 2431 | post("notes: Reference duration set to a 1/%i note", x->refdur); 2432 | } 2433 | //// ____________________________________________________ RENDERING SWITCH 2434 | void notes_render(t_notes *x, t_floatarg f) { 2435 | int i; 2436 | if (f == 0) { 2437 | i = 0; 2438 | post("notes: score rendering off"); 2439 | } 2440 | else { 2441 | i = 1; 2442 | post("notes: score rendering on"); 2443 | } 2444 | x->render = i; 2445 | } 2446 | //// ____________________________________________________ OPENING SWITCH 2447 | void notes_open(t_notes *x, t_floatarg f) { 2448 | int i; 2449 | if (f == 0) { 2450 | i = 0; 2451 | post("notes: score opening off"); 2452 | } 2453 | else { 2454 | i = 1; 2455 | post("notes: score opening on"); 2456 | } 2457 | x->open = i; 2458 | } 2459 | //// ____________________________________________________ DEBUG 2460 | void notes_debug(t_notes *x, t_floatarg f) { 2461 | x->debug = (int) f; 2462 | post("debugging level = %d", x->debug); 2463 | } 2464 | //// ____________________________________________________ TITLE 2465 | void notes_title(t_notes *x, t_symbol *s, int argc, t_atom *argv) { 2466 | x->dummysym = s->s_name; 2467 | int i; 2468 | for(i=0;ititle[i], 1000); 2470 | // post(x->title[i]); 2471 | } 2472 | x->titl_n = argc; 2473 | } 2474 | //// ____________________________________________________ SUB_TITLE 2475 | void notes_sub_title(t_notes *x, t_symbol *s, int argc, t_atom *argv) { 2476 | x->dummysym = s->s_name; 2477 | int i; 2478 | for(i=0;isub_title[i], 1000); 2480 | // post(x->sub_title[i]); 2481 | } 2482 | x->sub_title_n = argc; 2483 | } 2484 | //// ____________________________________________________ AUTHOR 2485 | void notes_author(t_notes *x, t_symbol *s, int argc, t_atom *argv) { 2486 | x->dummysym = s->s_name; 2487 | int i; 2488 | for(i=0;iauthor[i], 1000); 2490 | // post(x->author[i]); 2491 | } 2492 | x->auth_n = argc; 2493 | } 2494 | //// ____________________________________________________ INSTRUMENT 2495 | void notes_inst(t_notes *x, t_symbol *s) { 2496 | strcpy (x->inst, s->s_name); 2497 | post("notes: instrument name = %s", x->inst); 2498 | x->inst_n = 1; 2499 | } 2500 | //// ____________________________________________________ Lilypond Location 2501 | void notes_lily_dir(t_notes *x, t_symbol *s, int argc, t_atom *argv) { 2502 | int i; i = argc; i++; 2503 | x->dummysym = s->s_name; 2504 | atom_string(argv, x->lily_dir, MAXPDSTRING); 2505 | post("notes: Lilypond directory set to: %s", x->lily_dir); 2506 | } 2507 | //// ____________________________________________________ READFILE 2508 | void notes_readfile(t_notes *x, t_symbol *s) { 2509 | char filename[100]; 2510 | strcpy( filename, s->s_name); 2511 | strcpy( x->barfile, filename); 2512 | post("notes: Master Bar File RECEIVED at %s", x->barfile); 2513 | } 2514 | //// ____________________________________________________ PAPER SIZE 2515 | void notes_paper(t_notes *x, t_floatarg f, t_floatarg g) { 2516 | x->papersize = (int) f; 2517 | x->paperorientation = (int) g; 2518 | } 2519 | 2520 | t_class *notes_class; 2521 | void *notes_new(t_floatarg ff) { 2522 | t_notes *x = (t_notes *)pd_new(notes_class); 2523 | inlet_new(&x->x_ob, &x->x_ob.ob_pd, gensym("symbol"), gensym("readfile")); 2524 | x->x_outlet0 = outlet_new(&x->x_ob, &s_symbol); 2525 | x->x_outlet1 = outlet_new(&x->x_ob, &s_symbol); 2526 | x->x_outlet2 = outlet_new(&x->x_ob, &s_symbol); 2527 | x->x_outlet3 = outlet_new(&x->x_ob, gensym("float")); 2528 | x->x_canvas = canvas_getcurrent(); 2529 | x->FOLLOW = (int) ff; 2530 | x->sb_tp_index = x->i_index = x->ri_index = x->tp_index = x->tp_n = x->b_index = x->be_index = 0; 2531 | x->debug = 0; 2532 | x->inst_n = x->tempo = x->auth_n = x->titl_n = 0; 2533 | x->refdur = 32; 2534 | x->render = 1; 2535 | x->open = 1; 2536 | x->papersize = 4; 2537 | x->paperorientation = 0; 2538 | strcpy(x->lily_dir, LYDIR); // see notes_lib.h 2539 | strcpy(x->inst, "inst"); 2540 | return (void *)x; 2541 | } 2542 | void notes_setup(void) { 2543 | notes_class = class_new(gensym("notes"), (t_newmethod)notes_new, 0, sizeof(t_notes), 0, A_DEFFLOAT, 0); 2544 | 2545 | class_addmethod(notes_class, (t_method)notes_input, gensym("input"), A_GIMME, 0); 2546 | class_addmethod(notes_class, (t_method)notes_write, gensym("write"), A_SYMBOL, 0); 2547 | class_addmethod(notes_class, (t_method)notes_title, gensym("title"), A_GIMME, 0); 2548 | class_addmethod(notes_class, (t_method)notes_sub_title, gensym("sub_title"),A_GIMME, 0); 2549 | class_addmethod(notes_class, (t_method)notes_author, gensym("author"), A_GIMME, 0); 2550 | class_addmethod(notes_class, (t_method)notes_inst, gensym("inst"), A_SYMBOL, 0); 2551 | class_addmethod(notes_class, (t_method)notes_lily_dir, gensym("lily_dir"), A_GIMME, 0); 2552 | class_addmethod(notes_class, (t_method)notes_clear, gensym("clear"), 0); 2553 | class_addmethod(notes_class, (t_method)notes_readfile, gensym("readfile"), A_SYMBOL, 0); 2554 | class_addmethod(notes_class, (t_method)notes_print, gensym("print"), 0); 2555 | class_addmethod(notes_class, (t_method)notes_refdur, gensym("refdur"), A_DEFFLOAT, 0); 2556 | class_addmethod(notes_class, (t_method)notes_render, gensym("render"), A_DEFFLOAT, 0); 2557 | class_addmethod(notes_class, (t_method)notes_debug, gensym("debug"), A_DEFFLOAT, 0); 2558 | class_addmethod(notes_class, (t_method)notes_paper, gensym("paper"), A_DEFFLOAT, A_DEFFLOAT, 0); 2559 | class_addmethod(notes_class, (t_method)notes_open, gensym("open"), A_DEFFLOAT, 0); 2560 | } 2561 | -------------------------------------------------------------------------------- /src/notesLib.c: -------------------------------------------------------------------------------- 1 | // code for the "notesLib" pd library. 2 | // Encodes information created in Pd into a Lilypond score (lilypond.org) 3 | // developed by Jaime Oliver La Rosa (la.rosa@nyu.edu) 4 | // @ the NYU Waverly Labs in the Music Department - FAS. (nyu-waverlylabs.org) 5 | // with contributions by Fede Camara Halac (fch226@nyu.edu) 6 | // Released under the GNU General Public License. 7 | 8 | #include "notes_lib.h" 9 | 10 | typedef struct notesLib 11 | { 12 | t_object t_ob; 13 | } t_notesLib; 14 | 15 | t_class *notesLib_class; 16 | 17 | 18 | static void *notesLib_new(void) 19 | { 20 | t_notesLib *x = (t_notesLib *)pd_new(notesLib_class); 21 | 22 | return (x); 23 | } 24 | 25 | void notesLib_setup(void) 26 | { 27 | notesLib_class = class_new(gensym("notesLib"), notesLib_new, 0, sizeof(t_notesLib), CLASS_PD, 0); 28 | 29 | post("notes:\t Pd external object library for encoding music notation in lilypond syntax"); 30 | post("notesLib version %s", NOTESLIBVERSION); 31 | post("notes:\t developed by Jaime Oliver La Rosa"); 32 | post("notes:\t with contributions by Fede Cámara Halac"); 33 | post("notes:\t at NYU Waverly Labs"); 34 | class_sethelpsymbol(notesLib_class, gensym("notes")); 35 | mainscore_setup(); 36 | line2score_setup(); 37 | notes_setup(); 38 | 39 | } -------------------------------------------------------------------------------- /src/notes_lib.c: -------------------------------------------------------------------------------- 1 | // code for the "notes_lib" common file. 2 | // Encodes information created in Pd into a Lilypond score (lilypond.org) 3 | // developed by Jaime Oliver La Rosa (la.rosa@nyu.edu) 4 | // @ the NYU Waverly Labs in the Music Department - FAS. (nyu-waverlylabs.org) 5 | // updated by Fede Camara Halac (fch226@nyu.edu) 6 | // Released under the GNU General Public License. 7 | 8 | #include "notes_lib.h" 9 | 10 | //// ____________________________________________________ FUNCTIONS 11 | float reduce_meter(int a) { 12 | float b, c; 13 | 14 | if (a == 2) { a = 1; b = .16; } 15 | else if (a == 6) { a = 3; b = .16; } 16 | else if (a == 10){ a = 5; b = .16; } 17 | else if (a == 14){ a = 7; b = .16; } 18 | else if (a == 18){ a = 9; b = .16; } 19 | else if (a == 22){ a = 11; b = .16; } 20 | else if (a == 26){ a = 13; b = .16; } 21 | else if (a == 30){ a = 15; b = .16; } 22 | 23 | else if (a == 4) { a = 1; b = .08; } 24 | else if (a == 12){ a = 3; b = .08; } 25 | else if (a == 20){ a = 5; b = .08; } 26 | else if (a == 28){ a = 7; b = .08; } 27 | 28 | else if (a == 8) { a = 1; b = .04; } 29 | else if (a == 16){ a = 2; b = .04; } 30 | else if (a == 24){ a = 3; b = .04; } 31 | else if (a == 32){ a = 4; b = .04; } 32 | 33 | else {a = 0; b = 0;} 34 | 35 | c = a + b; 36 | return (c); 37 | } 38 | int get_beatsize(int a, int b, int c) { 39 | // a = num, b = den, c = refdur 40 | int m, beatsize; 41 | 42 | if (b == 4) { 43 | beatsize = exp2f( (float) (log2f((float) c) - log2f((float) b))); 44 | } 45 | else if (b == 8 || b == 16 || b == 32) { 46 | m = b / 2; 47 | if (a == 4) { 48 | beatsize = exp2f( (float) (log2f((float) c) - log2f((float) m))); 49 | beatsize = beatsize / 2; 50 | } 51 | else if (a == 7 || a == 8 || a == 10 || a == 13) { 52 | beatsize = exp2f( (float) (log2f((float) c) - log2f((float) m))); 53 | } 54 | else if (a == 3 || a == 5 || a == 6 || a == 9 || a == 11 || a == 12) { 55 | beatsize = exp2f( (float) (log2f((float) c) - log2f((float) m))); 56 | // beatsize = (beatsize / 2); 57 | } 58 | else { 59 | beatsize = exp2f( (float) (log2f((float) c) - log2f((float) m))); 60 | beatsize = (beatsize / 2); 61 | } 62 | } 63 | else beatsize = exp2f( (float) (log2f((float) c) - log2f((float) a))); 64 | 65 | if (beatsize < 2) beatsize = 2; 66 | 67 | // if (beatsize == 16) beatsize = 8; 68 | 69 | return (beatsize); 70 | } 71 | int pow2test(int a) { 72 | if ((a & (a - 1)) == 0) {return 1;} 73 | else {return 0;} 74 | } 75 | int pow2dottest(int a) { 76 | int b; 77 | b = (int) ((a / 3) * 2); 78 | if (((b/2)*3) != a) {return 0;} 79 | else { 80 | if ((b & (b - 1)) == 0) {return 1;} 81 | else {return 0;} 82 | } 83 | } 84 | int pow2ordot(int a) { 85 | int t1, t2; 86 | if ((a & (a - 1)) == 0) {t1 = 1;} 87 | else {t1 = 0;} 88 | int b; 89 | b = (int) ((a / 3) * 2); 90 | if (((b/2)*3) != a) {t2 = 0;} 91 | else { 92 | if ((b & (b - 1)) == 0) {t2 = 1;} 93 | else {t2 = 0;} 94 | } 95 | t1 = t1+t2; 96 | if (t1>0) {return 1;} 97 | else {return 0;} 98 | } 99 | void find_relative(int a, FILE *f) { 100 | int temp; 101 | temp = (int) a - 48; 102 | // fprintf(f, " "); 103 | // post("find_relative function, float = %d", temp); 104 | if (temp >= 55 && temp <= 66) { fprintf(f, "\\relative c''''' \n\{\n\n"); } 105 | else if (temp >= 43 && temp <= 54) { fprintf(f, "\\relative c'''' \n\{\n\n"); } 106 | else if (temp >= 31 && temp <= 42) { fprintf(f, "\\relative c''' \n\{\n\n"); } 107 | else if (temp >= 19 && temp <= 30) { fprintf(f, "\\relative c'' \n\{\n\n"); } 108 | else if (temp >= 7 && temp <= 18) { fprintf(f, "\\relative c' \n\{\n\n"); } 109 | else if (temp >= -6 && temp <= 6) { fprintf(f, "\\relative c \n\{\n\n"); } 110 | else if (temp >= -18 && temp <= -7) { fprintf(f, "\\relative c, \n\{\n\n"); } 111 | else if (temp >= -30 && temp <= -18) { fprintf(f, "\\relative c,, \n\{\n\n"); } 112 | else if (temp >= -42 && temp <= -31) { fprintf(f, "\\relative c,,, \n\{\n\n"); } 113 | else if (temp >= -54 && temp <= -43) { fprintf(f, "\\relative c,,,, \n\{\n\n"); } 114 | else if (temp >= -66 && temp <= -55) { fprintf(f, "\\relative c,,,,, \n\{\n\n"); } 115 | } 116 | void find_pitch(float a, int b, char g[]) { 117 | ///////////////////////////// a = current note, b = accidentals 0 = is or 1= es 118 | ///////////////////////////// g=note[] (char) 119 | int p; 120 | float f; 121 | f = (float) a; 122 | p = a; 123 | // post ("f1=%f", f); 124 | // post ("p =%d", p); 125 | f -= ((float) p); 126 | // post ("f2=%f", f); 127 | 128 | if (p < 0) { 129 | g[0] = 'r'; 130 | g[1] = '\0'; 131 | } 132 | else { 133 | p = p % 12; // see if it is a natural or altered note (# or b) // assign note name, c, d, etc. 134 | if (p == 0) { g[0] = 'c'; g[1] = '\0'; 135 | if (b==0 && f==0.5) { g[0] = 'c'; g[1] = 'i'; g[2] = 'h'; g[3] = '\0';} 136 | if (b==1 && f==0.5) { g[0] = 'd'; g[1] = 'e'; g[2] = 's'; g[3] = 'e'; g[4] = 'h'; g[5] = '\0';} 137 | } 138 | else if (p == 1) { 139 | if (b == 0) { g[0] = 'c'; g[1] = 'i'; g[2] = 's'; g[3] = '\0';} 140 | if (b==1) { g[0] = 'd'; g[1] = 'e'; g[2] = 's'; g[3] = '\0';} 141 | if (b==0 && f==0.5) { g[0] = 'c'; g[1] = 'i'; g[2] = 's'; g[3] = 'i'; g[4] = 'h'; g[5] = '\0';} 142 | if (b==1 && f==0.5) { g[0] = 'd'; g[1] = 'e'; g[2] = 'h'; g[3] = '\0';} 143 | } 144 | else if (p == 2) { g[0] = 'd'; g[1] = '\0'; 145 | if (b==0 && f==0.5) { g[0] = 'd'; g[1] = 'i'; g[2] = 'h'; g[3] = '\0';} 146 | if (b==1 && f==0.5) { g[0] = 'e'; g[1] = 'e'; g[2] = 's'; g[3] = 'e'; g[4] = 'h'; g[5] = '\0';} 147 | } 148 | else if (p == 3) { 149 | if (b==0) { g[0] = 'd'; g[1] = 'i'; g[2] = 's'; g[3] = '\0';} 150 | if (b==1) { g[0] = 'e'; g[1] = 'e'; g[2] = 's'; g[3] = '\0';} 151 | if (b==0 && f==0.5) { g[0] = 'd'; g[1] = 'i'; g[2] = 's'; g[3] = 'i'; g[4] = 'h'; g[5] = '\0';} 152 | if (b==1 && f==0.5) { g[0] = 'e'; g[1] = 'e'; g[2] = 'h'; g[3] = '\0';} 153 | } 154 | else if (p == 4) { g[0] = 'e'; g[1] = '\0'; 155 | if (b==0 && f==0.5) { g[0] = 'e'; g[1] = 'i'; g[2] = 'h'; g[3] = '\0';} 156 | if (b==1 && f==0.5) { g[0] = 'f'; g[1] = 'e'; g[2] = 'h'; g[3] = '\0';} 157 | } 158 | else if (p == 5) { g[0] = 'f'; g[1] = '\0'; 159 | if (b==0 && f==0.5) { g[0] = 'f'; g[1] = 'i'; g[2] = 'h'; g[3] = '\0';} 160 | if (b==1 && f==0.5) { g[0] = 'g'; g[1] = 'e'; g[2] = 's'; g[3] = 'e'; g[4] = 'h'; g[5] = '\0';} 161 | } 162 | else if (p == 6) { 163 | if (b==0) { g[0] = 'f'; g[1] = 'i'; g[2] = 's'; g[3] = '\0';} 164 | if (b==1) { g[0] = 'g'; g[1] = 'e'; g[2] = 's'; g[3] = '\0';} 165 | if (b==0 && f==0.5) { g[0] = 'f'; g[1] = 'i'; g[2] = 's'; g[3] = 'i'; g[4] = 'h'; g[5] = '\0';} 166 | if (b==1 && f==0.5) { g[0] = 'g'; g[1] = 'e'; g[2] = 'h'; g[3] = '\0';} 167 | } 168 | else if (p == 7) { g[0] = 'g'; g[1] = '\0'; 169 | if (b==0 && f==0.5) { g[0] = 'g'; g[1] = 'i'; g[2] = 'h'; g[3] = '\0';} 170 | if (b==1 && f==0.5) { g[0] = 'a'; g[1] = 'e'; g[2] = 's'; g[3] = 'e'; g[4] = 'h'; g[5] = '\0';} 171 | } 172 | else if (p == 8) { 173 | if (b==0) { g[0] = 'g'; g[1] = 'i'; g[2] = 's'; g[3] = '\0';} 174 | if (b==1) { g[0] = 'a'; g[1] = 'e'; g[2] = 's'; g[3] = '\0';} 175 | if (b==0 && f==0.5) { g[0] = 'g'; g[1] = 'i'; g[2] = 's'; g[3] = 'i'; g[4] = 'h'; g[5] = '\0';} 176 | if (b==1 && f==0.5) { g[0] = 'a'; g[1] = 'e'; g[2] = 'h'; g[3] = '\0';} 177 | } 178 | else if (p == 9) { g[0] = 'a'; g[1] = '\0'; 179 | if (b==0 && f==0.5) { g[0] = 'a'; g[1] = 'i'; g[2] = 'h'; g[3] = '\0';} 180 | if (b==1 && f==0.5) { g[0] = 'b'; g[1] = 'e'; g[2] = 's'; g[3] = 'e'; g[4] = 'h'; g[5] = '\0';} 181 | } 182 | else if (p == 10) { 183 | if (b==0) { g[0] = 'a'; g[1] = 'i'; g[2] = 's'; g[3] = '\0';} 184 | if (b==1) { g[0] = 'b'; g[1] = 'e'; g[2] = 's'; g[3] = '\0';} 185 | if (b==0 && f==0.5) { g[0] = 'a'; g[1] = 'i'; g[2] = 's'; g[3] = 'i'; g[4] = 'h'; g[5] = '\0';} 186 | if (b==1 && f==0.5) { g[0] = 'b'; g[1] = 'e'; g[2] = 'h'; g[3] = '\0';} 187 | } 188 | else { g[0] = 'b'; g[1] = '\0'; 189 | if (b==0 && f==0.5) { g[0] = 'b'; g[1] = 'i'; g[2] = 'h'; g[3] = '\0';} 190 | if (b==1 && f==0.5) { g[0] = 'c'; g[1] = 'e'; g[2] = 'h'; g[3] = '\0';} 191 | } 192 | } 193 | } 194 | int find_jump(int a, int b, int c, char g[]) { 195 | int jmp, direction, i, accidental; 196 | accidental = c; 197 | int sharp_pitches[250] = { 1, 1, 2, 2, 3, 4, 4, 5, 5, 6, 6, 7, 8, 8, 9, 9, 10, 11, 11, 12, 12, 13, 13, 14, 15, 15, 16, 16, 17, 18, 18, 19, 19, 20, 20, 21, 22, 22, 23, 23, 24, 25, 25, 26, 26, 27, 27, 28, 29, 29, 30, 30, 31, 32, 32, 33, 33, 34, 34, 35, 36, 36, 37, 37, 38, 39, 39, 40, 40, 41, 41, 42, 43, 43, 44, 44, 45, 46, 46, 47, 47, 48, 48, 49, 50, 50, 51, 51, 52, 53, 53, 54, 54, 55, 55, 56, 57, 57, 58, 58, 59, 60, 60, 61, 61, 62, 62, 63, 64, 64, 65, 65, 66, 67, 67, 68, 68, 69, 69, 70, 71, 71, 72, 72, 73, 74, 74, 75, 75, 76, 76, 77, 78, 78, 79, 79, 80, 81, 81, 82, 82, 83, 83, 84, 85, 85, 86, 86, 87, 88, 88, 89, 89, 90, 90, 91, 92, 92, 93, 93, 94, 95, 95, 96, 96, 97, 97, 98, 99, 99, 100, 100, 101, 102, 102, 103, 103, 104, 104, 105, 106, 106, 107, 107, 108, 109, 109, 110, 110, 111, 111, 112, 113, 113, 114, 114, 115, 116, 116, 117, 117, 118, 118, 119}; 198 | int flat_pitches[250] = { 1, 2, 2, 3, 3, 4, 5, 5, 6, 6, 7, 7, 8, 9, 9, 10, 10, 11, 12, 12, 13, 13, 14, 14, 15, 16, 16, 17, 17, 18, 19, 19, 20, 20, 21, 21, 22, 23, 23, 24, 24, 25, 26, 26, 27, 27, 28, 28, 29, 30, 30, 31, 31, 32, 33, 33, 34, 34, 35, 35, 36, 37, 37, 38, 38, 39, 40, 40, 41, 41, 42, 42, 43, 44, 44, 45, 45, 46, 47, 47, 48, 48, 49, 49, 50, 51, 51, 52, 52, 53, 54, 54, 55, 55, 56, 56, 57, 58, 58, 59, 59, 60, 61, 61, 62, 62, 63, 63, 64, 65, 65, 66, 66, 67, 68, 68, 69, 69, 70, 70, 71, 72, 72, 73, 73, 74, 75, 75, 76, 76, 77, 77, 78, 79, 79, 80, 80, 81, 82, 82, 83, 83, 84, 84, 85, 86, 86, 87, 87, 88, 89, 89, 90, 90, 91, 91, 92, 93, 93, 94, 94, 95, 96, 96, 97, 97, 98, 98, 99, 100, 100, 101, 101, 102, 103, 103, 104, 104, 105, 105, 106, 107, 107, 108, 108, 109, 110, 110, 111, 111, 112, 112, 113, 114, 114, 115, 115, 116, 117, 117, 118, 118, 119, 119}; 199 | int pitch_current, pitch_previous, interval; 200 | i = 1; 201 | if (b < 0) b = abs(b); 202 | if(accidental == 0) { 203 | pitch_current = sharp_pitches[abs(a)]; 204 | pitch_previous = sharp_pitches[abs(b)]; 205 | } 206 | else { 207 | pitch_current = flat_pitches[abs(a)]; 208 | pitch_previous = flat_pitches[abs(b)]; 209 | } 210 | jmp = a - b; 211 | if (jmp >= 0) direction = 1; 212 | else direction = 0; 213 | if (a < 0) interval = 1; 214 | else { 215 | if (direction == 1) { 216 | interval = pitch_current - pitch_previous + 1; 217 | if (interval < 0) { 218 | interval = pitch_previous - pitch_current; 219 | interval = interval * -1 + 8; 220 | } 221 | } 222 | else { 223 | interval = pitch_previous - pitch_current + 1; 224 | if (interval < 0) { 225 | interval = pitch_current - pitch_previous; 226 | interval = interval * -1 + 8; 227 | } 228 | interval = interval * -1; 229 | } 230 | } 231 | if (interval < -67) {g[0] = ','; g[1] = ','; g[2] = ','; g[3] = ','; g[4] = ','; g[5] = ','; g[6] = ','; g[7] = ','; g[8] = ','; g[9] = '\0';} 232 | else if (interval >= -60 && interval < -53) {g[0] = ','; g[1] = ','; g[2] = ','; g[3] = ','; g[4] = ','; g[5] = ','; g[6] = ','; g[7] = ','; g[8] = '\0';} 233 | else if (interval >= -53 && interval < -46) {g[0] = ','; g[1] = ','; g[2] = ','; g[3] = ','; g[4] = ','; g[5] = ','; g[6] = ','; g[7] = '\0';} 234 | else if (interval >= -46 && interval < -39) {g[0] = ','; g[1] = ','; g[2] = ','; g[3] = ','; g[4] = ','; g[5] = ','; g[6] = '\0';} 235 | else if (interval >= -39 && interval < -32) {g[0] = ','; g[1] = ','; g[2] = ','; g[3] = ','; g[4] = ','; g[5] = '\0';} 236 | else if (interval >= -32 && interval < -25) {g[0] = ','; g[1] = ','; g[2] = ','; g[3] = ','; g[4] = '\0';} 237 | else if (interval >= -25 && interval < -18) {g[0] = ','; g[1] = ','; g[2] = ','; g[3] = '\0';} 238 | else if (interval >= -18 && interval < -11) {g[0] = ','; g[1] = ','; g[2] = '\0';} 239 | else if (interval >= -11 && interval < -4) {g[0] = ','; g[1] = '\0';} 240 | else if (interval >= -4 && interval <= 4) {i = 0; g[0] = '\0';} 241 | else if (interval >= 4 && interval <= 11) {g[0] = '\''; g[1] = '\0';} 242 | else if (interval > 11 && interval <= 18) {g[0] = '\''; g[1] = '\''; g[2] = '\0';} 243 | else if (interval > 18 && interval <= 25) {g[0] = '\''; g[1] = '\''; g[2] = '\''; g[3] = '\0';} 244 | else if (interval > 25 && interval <= 32) {g[0] = '\''; g[1] = '\''; g[2] = '\''; g[3] = '\''; g[4] = '\0';} 245 | else if (interval > 32 && interval <= 39) {g[0] = '\''; g[1] = '\''; g[2] = '\''; g[3] = '\''; g[4] = '\''; g[5] = '\0';} 246 | else if (interval > 39 && interval <= 46) {g[0] = '\''; g[1] = '\''; g[2] = '\''; g[3] = '\''; g[4] = '\''; g[5] = '\''; g[6] = '\0';} 247 | else if (interval > 46 && interval <= 53) {g[0] = '\''; g[1] = '\''; g[2] = '\''; g[3] = '\''; g[4] = '\''; g[5] = '\''; g[6] = '\''; g[7] = '\0';} 248 | else if (interval > 53 && interval <= 60) {g[0] = '\''; g[1] = '\''; g[2] = '\''; g[3] = '\''; g[4] = '\''; g[5] = '\''; g[6] = '\''; g[7] = '\''; g[8] = '\0';} 249 | else if (interval > 67) {g[0] = '\''; g[1] = '\''; g[2] = '\''; g[3] = '\''; g[4] = '\''; g[5] = '\''; g[6] = '\''; g[7] = '\''; g[8] = '\''; g[9] = '\0';} 250 | return(i); 251 | } 252 | void find_clef(int a, FILE *f) { 253 | if (a==0) fprintf(f, "\\clef treble "); // 254 | else if (a==1) fprintf(f, "\\clef alto "); // 255 | else if (a==2) fprintf(f, "\\clef tenor "); //, 256 | else if (a==3) fprintf(f, "\\clef bass "); //, 257 | else if (a==4) fprintf(f, "\\clef french "); // 258 | else if (a==5) fprintf(f, "\\clef soprano "); // , 259 | else if (a==6) fprintf(f, "\\clef mezzosoprano "); // 260 | else if (a==7) fprintf(f, "\\clef baritone "); // 261 | else if (a==8) fprintf(f, "\\clef varbaritone "); // 262 | else if (a==9) fprintf(f, "\\clef percussion "); // 263 | } 264 | void find_articulation(int a, FILE *f) { 265 | if (a==0) fprintf(f, "\\accent"); // 266 | else if (a==1) fprintf(f, "\\espressivo"); // 267 | else if (a==2) fprintf(f, "\\marcato"); //, 268 | else if (a==3) fprintf(f, "\\portato"); //, 269 | else if (a==4) fprintf(f, "\\staccatissimo"); // 270 | else if (a==5) fprintf(f, "\\staccato"); // 271 | else if (a==6) fprintf(f, "\\tenuto"); // 272 | else if (a==7) fprintf(f, "\\shortfermata"); // 273 | else if (a==8) fprintf(f, "\\fermata"); // 274 | else if (a==9) fprintf(f, "\\longfermata"); // 275 | else if (a==10) fprintf(f, "\\verylongfermata"); // 276 | else if (a==11) fprintf(f, "\\upbow "); // 277 | else if (a==12) fprintf(f, "\\downbow "); // 278 | else if (a==13) fprintf(f, "\\flageolet"); // 279 | else if (a==14) fprintf(f, "\\thumb"); // 280 | else if (a==15) fprintf(f, "\\snappizzicato"); // 281 | else if (a==16) fprintf(f, "\\open"); // 282 | else if (a==17) fprintf(f, "\\halfopen"); // 283 | else if (a==18) fprintf(f, "\\stopped"); // 284 | else if (a==19) fprintf(f, "\\lheel"); // 285 | else if (a==20) fprintf(f, "\\rheel"); // 286 | else if (a==21) fprintf(f, "\\ltoe"); // 287 | else if (a==22) fprintf(f, "\\rtoe"); // 288 | else if (a==23) fprintf(f, "\\laissezVibrer "); //, 289 | else if (a==24) fprintf(f, "^\\markup { \\sharp }"); //, \markup { \sharp } " \\xNote "); 290 | else if (a==25) fprintf(f, "^\\markup { \\flat }"); //, "\\harmonic"); //, 291 | else if (a==26) fprintf(f, "^\\markup { \\natural }"); // 292 | else if (a==27) fprintf(f, "\\trill"); // 293 | else if (a==28) fprintf(f, "\\prall"); // 294 | else if (a==29) fprintf(f, "\\mordent"); // 295 | else if (a==30) fprintf(f, "\\prallmordent"); // 296 | else if (a==31) fprintf(f, "\\upprall"); //, 297 | else if (a==32) fprintf(f, "\\downprall"); //, 298 | else if (a==33) fprintf(f, "\\upmordent"); //, 299 | else if (a==34) fprintf(f, "\\downmordent"); //, 300 | else if (a==35) fprintf(f, "\\lineprall"); //, 301 | else if (a==36) fprintf(f, "\\prallprall"); //, 302 | else if (a==37) fprintf(f, "\\pralldown"); //, 303 | else if (a==38) fprintf(f, "\\prallup"); //, 304 | else if (a==39) fprintf(f, "\\turn"); //, 305 | else if (a==40) fprintf(f, "\\reverseturn"); //, 306 | else if (a==41) fprintf(f, "\\segno"); // 307 | else if (a==42) fprintf(f, "\\coda"); // 308 | else if (a==43) fprintf(f, "\\varcoda"); // 309 | else if (a==44) fprintf(f, "\\breathe"); // 310 | else if (a==45) fprintf(f, "\\bendAfter #+4 "); // 311 | else if (a==46) fprintf(f, "\\bendAfter #-4 "); // 312 | else if (a==47) fprintf(f, "-\\markup{pizz.}"); // 313 | else if (a==48) fprintf(f, "-\\markup{arco}"); // 314 | else if (a==49) fprintf(f, "-\\markup{vib.}"); // 315 | else if (a==50) fprintf(f, "-\\markup{senza vib.}"); // 316 | } 317 | void find_dynamics(int a, FILE *f) { 318 | if (a==0) fprintf(f, "\\<"); // 319 | else if (a==1) fprintf(f, "\\>"); // 320 | else if (a==2) fprintf(f, "\\!"); // 321 | else if (a==3) fprintf(f, "\\ppppp"); // 322 | else if (a==4) fprintf(f, "\\pppp"); // 323 | else if (a==5) fprintf(f, "\\ppp"); // 324 | else if (a==6) fprintf(f, "\\pp"); // 325 | else if (a==7) fprintf(f, "\\p"); // 326 | else if (a==8) fprintf(f, "\\mp"); // 327 | else if (a==9) fprintf(f, "\\mf"); // 328 | else if (a==10) fprintf(f, "\\f"); // 329 | else if (a==11) fprintf(f, "\\ff"); // 330 | else if (a==12) fprintf(f, "\\fff"); // 331 | else if (a==13) fprintf(f, "\\ffff"); // 332 | else if (a==14) fprintf(f, "\\fffff"); // 333 | else if (a==15) fprintf(f, "\\fp"); 334 | else if (a==16) fprintf(f, "\\sf"); 335 | else if (a==17) fprintf(f, "\\sff"); 336 | else if (a==18) fprintf(f, "\\sp"); 337 | else if (a==19) fprintf(f, "\\spp"); 338 | else if (a==20) fprintf(f, "\\sfz"); 339 | else if (a==21) fprintf(f, "\\rfz"); 340 | else if (a>=22) post("notes: Warning: Only dynamics 0 through 21 are predefined"); 341 | } 342 | void find_small_numbers(int a, FILE *f) { 343 | fprintf(f, "-%i", a); 344 | } 345 | void find_span(int a, FILE *f) { 346 | if (a==0) fprintf(f, "\\glissando"); // GLISSANDO 347 | else if (a==1) fprintf(f, "\\sustainOn"); // SUSTAIN 348 | else if (a==2) fprintf(f, "\\sustainOff"); // STOP SUSTAIN 349 | else if (a==3) fprintf(f, "("); //, SLUR 350 | else if (a==4) fprintf(f, ")"); //, STOP SLUR 351 | else if (a==5) fprintf(f, "\\startTrillSpan"); // TRILL SPAN 352 | else if (a==6) fprintf(f, "\\stopTrillSpan"); //STOP TRILL SPAN 353 | else if (a==7) fprintf(f, "\\glissando");// \\glissandoSkipOn"); // 354 | else if (a==8) fprintf(f, "\\glissandoSkipOff"); // 355 | } 356 | void find_stafftext(int a, char g[]) { 357 | int n, total; 358 | char fst[6]; 359 | total = a; 360 | if (total < 10) { 361 | n = total; 362 | if (n==0) strcpy( fst, "zero"); 363 | else if (n==1) strcpy( fst, "one"); 364 | else if (n==2) strcpy( fst, "two"); 365 | else if (n==3) strcpy( fst, "three"); 366 | else if (n==4) strcpy( fst, "four"); 367 | else if (n==5) strcpy( fst, "five"); 368 | else if (n==6) strcpy( fst, "six"); 369 | else if (n==7) strcpy( fst, "seven"); 370 | else if (n==8) strcpy( fst, "eight"); 371 | else if (n==9) strcpy( fst, "nine"); 372 | } 373 | else { 374 | n = (int) ((float) total / 10.); 375 | if (n==0) strcpy( fst, "zero"); 376 | else if (n==1) strcpy( fst, "one"); 377 | else if (n==2) strcpy( fst, "two"); 378 | else if (n==3) strcpy( fst, "three"); 379 | else if (n==4) strcpy( fst, "four"); 380 | else if (n==5) strcpy( fst, "five"); 381 | else if (n==6) strcpy( fst, "six"); 382 | else if (n==7) strcpy( fst, "seven"); 383 | else if (n==8) strcpy( fst, "eight"); 384 | else if (n==9) strcpy( fst, "nine"); 385 | n = total - (n*10); 386 | if (n==0) strcat( fst, "zero"); 387 | else if (n==1) strcat( fst, "one"); 388 | else if (n==2) strcat( fst, "two"); 389 | else if (n==3) strcat( fst, "three"); 390 | else if (n==4) strcat( fst, "four"); 391 | else if (n==5) strcat( fst, "five"); 392 | else if (n==6) strcat( fst, "six"); 393 | else if (n==7) strcat( fst, "seven"); 394 | else if (n==8) strcat( fst, "eight"); 395 | else if (n==9) strcat( fst, "nine"); 396 | } /* if (n==0) { g[0]='z';g[1]='e';g[2]='r';g[3]='o';g[4]='\0';} 397 | else if (n==1) { g[0]='o';g[1]='n';g[2]='e';g[3]='\0';} 398 | else if (n==2) { g[0]='t';g[1]='w';g[2]='o';g[3]='\0';} 399 | else if (n==3) { g[0]='t';g[1]='h';g[2]='r';g[3]='e';g[4]='e';g[5]='\0';} 400 | else if (n==4) { g[0]='f';g[1]='o';g[2]='u';g[3]='r';g[4]='\0';} 401 | else if (n==5) { g[0]='f';g[1]='i';g[2]='v';g[3]='e';g[4]='\0';} 402 | else if (n==6) { g[0]='s';g[1]='i';g[2]='x';g[3]='\0';} 403 | else if (n==7) { g[0]='s';g[1]='e';g[2]='v';g[3]='e';g[4]='n';g[5]='\0';} 404 | else if (n==8) { g[0]='e';g[1]='i';g[2]='g';g[3]='h';g[4]='t';g[5]='\0';} 405 | else if (n==9) { g[0]='n';g[1]='i';g[2]='n';g[3]='e';g[4]='\0';}*/ 406 | strcpy (g, fst); 407 | } 408 | void find_grace(int a, FILE *f) { 409 | if (a==1) fprintf(f, " \\grace {"); // 410 | else if (a==2) fprintf(f, " \\slashedGrace {"); // 411 | else if (a==3) fprintf(f, " \\acciaccatura {"); // 412 | else if (a==4) fprintf(f, " \\appoggiatura {"); // 413 | } 414 | void find_arpeggio(int a, FILE *f) { 415 | if (a==1) fprintf(f, " \\arpeggioArrowUp "); // 416 | else if (a==2) fprintf(f, " \\arpeggioArrowDown "); // 417 | else if (a==3) fprintf(f, " \\arpeggioNormal "); // 418 | } 419 | void find_notehead(int a, FILE *f) { 420 | if (a==1) fprintf(f, "\\once \\override NoteHead.style = #'harmonic "); // 421 | else if (a==2) fprintf(f, "\\xNote "); // 422 | else if (a==3) fprintf(f, "\\once \\override NoteHead.style = #'triangle "); // 423 | else if (a==4) fprintf(f, "\\once \\override NoteHead.style = #'fa "); // 424 | else if (a==5) fprintf(f, "\\once \\override NoteHead.style = #'mensural "); // 425 | else if (a==6) fprintf(f, "\\once \\override NoteHead.style = #'xcircle "); // 426 | else if (a==7) fprintf(f, "\\once \\override NoteHead.style = #'diamond "); // 427 | else if (a==8) fprintf(f, "\\once \\override NoteHead.style = #'slash "); // 428 | else if (a==9) fprintf(f, "\\parenthesize "); // 429 | } 430 | int readbarfile(int a[][8], FILE *f) { 431 | int row = 0; 432 | char * line = NULL; 433 | size_t len = 0; 434 | 435 | while (getline(&line, &len, f) != -1) { 436 | // We expect 5 integer items so we can directly read into the output array because the data type (int) matches the %d specifier. 437 | if (sscanf(line, "%d%d%d%d%d", &a[row][0], &a[row][1], &a[row][2], &a[row][3], &a[row][4]) != 5) { 438 | post("barfile is not found or has the wrong number of items"); 439 | } 440 | row++; 441 | } 442 | free(line); 443 | return row; 444 | } 445 | 446 | void copyfiles(FILE *f, FILE *g) { 447 | char a; 448 | post("copyfiles"); 449 | a = fgetc(g); 450 | if (a != EOF) fputc(a, f); 451 | while(a != EOF) { 452 | post("copyfiles"); 453 | a = fgetc(g); 454 | if (a != EOF) fputc(a, f); 455 | } 456 | } // f1 into f2 457 | 458 | int compile(char *buf, char *name, int debug, char *lily_dir) { 459 | char cmdbuf[MAXPDSTRING]; 460 | if (debug >= 1) post("notes: compiling score"); 461 | 462 | snprintf(cmdbuf, MAXPDSTRING, "%s%slilypond -o %s %s", lily_dir, LYBINDIR, buf, name); 463 | 464 | cmdbuf[MAXPDSTRING-1] = 0; 465 | if (debug >= 1) post("notes: cmdbuf = %s", cmdbuf); 466 | // RENDER THE SCORE TO PDF 467 | if (!system(cmdbuf)) { 468 | if (debug >= 1) post("notes: score compiled"); 469 | return 0; 470 | } else { 471 | post("notes: score did not compile"); 472 | post("... you might want to run the following command manually:\n"); 473 | post("%s\n", cmdbuf); 474 | return 1; 475 | } 476 | } 477 | 478 | void open_pdf(char *buf) { 479 | char cmdbuf[MAXPDSTRING]; 480 | post("notes: Opening PDF score"); 481 | // OPEN THE .PDF SCORE (adapted from pdcontrol's browse method) 482 | snprintf(cmdbuf, MAXPDSTRING, "::pd_menucommands::menu_openfile {%s.pdf}\n", buf); 483 | cmdbuf[MAXPDSTRING-1] = 0; 484 | sys_gui(cmdbuf); 485 | } 486 | 487 | int compile_and_open(char *buf, char *name, int debug, int FOLLOW, int render, int OPEN, char *lily_dir) { 488 | if (!render) { 489 | if (debug >= 1) post("notes: skipping score rendering"); 490 | } else if (FOLLOW == 1) { 491 | if (debug >= 1) post("notes: render disabled in FOLLOW mode"); 492 | } else { // FOLLOW == 0 && render == 1 493 | if (!system(NULL)) { 494 | if (debug >= 1) post("notes: system() not found"); 495 | return 1; 496 | } else { 497 | if(!compile(buf, name, debug, lily_dir)) { 498 | if (OPEN) open_pdf(buf); 499 | } else { 500 | if (debug >= 1) post("notes: score did not compile"); 501 | return 1; 502 | } 503 | } 504 | } 505 | return 0; 506 | } --------------------------------------------------------------------------------