pax_global_header00006660000000000000000000000064143374230650014521gustar00rootroot0000000000000052 comment=f88440c1fb5b7a9ac13d1a8a2500636334194934 tclpd-0.3.1/000077500000000000000000000000001433742306500126305ustar00rootroot00000000000000tclpd-0.3.1/AUTHORS.txt000066400000000000000000000002641433742306500145200ustar00rootroot00000000000000Authors of tclpd. Federico Ferri I'd like to thank also Mathieu Bouchard for sharing its knowledge and giving advices, thus contributing to this project. tclpd-0.3.1/ChangeLog.txt000066400000000000000000000020151433742306500152160ustar00rootroot00000000000000Version 0.3.0: - Big rewrite, fixing typemaps - Support for most binbuf atoms (COMMA, SEMI, DOLLAR, DOLLSYM, ...) Version 0.2.3: - Big rewrite, using tcl namespaces (more tidy, more efficient) Version 0.2.2: - Requires pd 0.43 (logpost, pdpost) - Fixed "tclpd_get_instance_text cmd not found" bug - Makefile for all platforms - Replaced std::map with a minimal hashtable implementation - Added support for te_binbuf retrieval (for savefn) Version 0.2.1: - Added support for properties function. - Added support for pd_bind/unbind. - Added destructor call in pd_free. - Added support for glist_grab (needed for mouse motion) - Added support for loadbang - Added iemgui-style general purpose property panel - Introduced Tcl package logic (package name: Tclpd) Version 0.2: - Added support for GUI externals (widgetbehavior). - Added support for save function. - Fixed memory leaks. Version 0.1.1: - Basic support for atom conversion, pd classes, methods. - Fixed issues with tcl obj reference counter (segfaults). tclpd-0.3.1/LICENSE.txt000066400000000000000000000360751433742306500144660ustar00rootroot00000000000000 GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS tclpd-0.3.1/Makefile000066400000000000000000000026331433742306500142740ustar00rootroot00000000000000# Makefile to build loader 'tclpd' for Pure Data. # Needs Makefile.pdlibbuilder as helper makefile for platform-dependent build # settings and rules. # library name lib.name = tclpd cflags = -std=c99 ldlibs = ########################################################### # Tcl stuff TCL_CFLAGS=$(shell pkg-config --cflags tcl) TCL_LIBS=$(shell pkg-config --libs tcl) ## Dawrin # TCL_CFLAGS = -I/Library/Frameworks/Tcl.framework/Headers # TCL_LIBS = -framework Tcl ## MSW # TCL_CFLAGS = # TCL_LIBS = -ltcl86 tclpd.def cflags += -DHASHTABLE_COPY_KEYS $(TCL_CFLAGS) ldlibs += $(TCL_LIBS) # ########################################################### # input source file (class name == source file basename) tclpd.class.sources = tclpd.c tclpd.class.sources += \ hashtable.c \ tcl_class.c \ tcl_loader.c \ tcl_proxyinlet.c \ tcl_typemap.c \ tcl_widgetbehavior.c \ $(empty) tclpd.class.sources += tcl_wrap.c # all extra files to be included in binary distribution of the library datafiles = \ LICENSE.txt \ README.txt \ tclpd.tcl \ tclpd-help.pd \ tclpd-meta.pd datadirs = examples # include Makefile.pdlibbuilder from submodule directory 'pd-lib-builder' PDLIBBUILDER_DIR=pd-lib-builder/ include $(PDLIBBUILDER_DIR)/Makefile.pdlibbuilder # create the tcl wrapper with 'swig' tcl_wrap.c: tclpd.i tclpd.h Makefile swig -v -tcl -o tcl_wrap.c -I$(PDINCLUDEDIR) tclpd.i clean-local: rm -f tcl_wrap.c clean: clean-local tclpd-0.3.1/README.txt000066400000000000000000000051541433742306500143330ustar00rootroot00000000000000 Tcl for Pd ========== This library allows one to write externals for Pd using the Tcl language. It wraps quite closely the pd API (m_pd.h, plus some private functions) Also a library of Tcl helper functions is provided. It is not mandatory to use it (moreover: it requires Tcl 8.5, while the tclpd external alone requires only Tcl 8.4), but it is a syntactic sugar and can simplify a lot the code. To use it simply add 'package require TclpdLib' in your Tcl external. Anyway, disregarding any approach chosen to develop Tcl externals, a general knowledge of Pd internals (atoms, symbols, symbol table, inlets, objects) is strongly required. (Pd-External-HOWTO is always a good reading) Compiling and installing ======================== To compile tclpd, simply type: make clean all To compile it with debug enabled: make clean alldebug Requirements are pd >= 0.39, swig, c compiler. To install tclpd, simply copy it to /usr/lib/pd/extra (or where you installed pure-data). Writing GUI externals ===================== Pd is split into two processes: pd (the core) and pd-gui. A pd external executes in the core. The same applies for a Tcl external loaded by tclpd, because tclpd creates a Tcl interpreter for that, running in the same process as pd. On the gui side (pd-gui) there is another Tcl interpreter living in a separate process, which communicates with pd using a network socket. Communication happens in one way (pd to gui) with the sys_gui function, and in the other way using ::pdsend. (needs to set up a receiver using pdbind, check the examples). Data conversion between Tcl <=> Pd ================================== In pd objects communicate using messages, and messages are made up of atoms. An atom could be a float, a symbol, a list, and so on. Tcl usually doesn't make distinction between strings and numbers. This means that simply translating a message text into a string could lose information about the atom type (to pd, symbol 456 is different from float 456, but if we just convert it as a string "456" the type information is lost). To maintain atom type infrmation, pd atoms are represented in Tcl as two element lists, where the first element indicates the atom type. Some examples of this conversion: Pd: 456 Tcl: {float 456} Pd: symbol foo Tcl: {symbol foo} Pd: list cat dog 123 456 weee Tcl: {{symbol cat} {symbol dog} {float 123} {float 456} {symbol wee}} Examples ======== Some examples externals are provided, including their helpfile. Authors ======= Please refer to AUTHORS file found in tclpd package. License ======= Please refer to COPYING file found in tclpd package. tclpd-0.3.1/TODO.txt000066400000000000000000000004031433742306500141330ustar00rootroot00000000000000TODO-list for tclpd (most important things first) ================================================= - bitmap's help make pd crash only when opened via context menu Help -> investigate - slider2.tcl is broken - add (or check) GOP - signal externals? (really?) tclpd-0.3.1/examples/000077500000000000000000000000001433742306500144465ustar00rootroot00000000000000tclpd-0.3.1/examples/binbuf-test.tcl000066400000000000000000000003661433742306500174010ustar00rootroot00000000000000package require Tclpd 0.3.0 package require TclpdLib 0.20 proc binbuf-test::constructor {self args} { pd::add_outlet $self list } proc binbuf-test::0_bang {self} { pd::outlet $self 0 list [pd::get_binbuf $self] } pd::class binbuf-test tclpd-0.3.1/examples/bitmap-help.pd000066400000000000000000000050271433742306500172010ustar00rootroot00000000000000#N canvas 625 330 742 518 10; #X obj 63 244 bitmap -cellsize 15 -uwidth 8 -uheight 8; #bitmap setdata 1 0 0 0 0 0 0 1 1 0 0 0 0 0 1 0 1 0 0 0 0 1 0 1 1 0 0 0 1 0 1 0 1 0 0 1 0 1 0 1 1 0 1 0 1 0 1 0 1 1 0 1 0 1 0 1 1 0 1 0 1 0 1 0; #X obj 87 410 print out; #X msg 39 117 getrow \$1; #X obj 42 245 vradio 15 1 0 8 empty empty empty 0 -8 0 10 -228856 -162280 -1 0; #X obj 42 410 s \$0r; #X obj 39 89 r \$0r; #X text 36 19 [bitmap] - a two dimensional array of bits (toggles) ; #X text 38 49 creation arguments -cellsize <#> -uwidth <#> -uheight <#>; #X msg 111 117 getcol \$1; #X obj 111 89 r \$0c; #X obj 63 213 r \$0b; #X obj 39 157 s \$0b; #X obj 63 372 hradio 15 1 0 8 empty empty empty 0 -8 0 10 -228856 -162280 -1 0; #X obj 157 410 s \$0c; #X obj 227 157 s \$0b; #X msg 227 117 getcell 0 1; #X msg 317 117 getcell 1 1; #X text 226 88 getcell ; #X obj 247 243 bitmap -cellsize 4 -uwidth 16 -uheight 16; #bitmap setdata 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 1 1 1 1 0 1 1 1 1 1 0 0 1 0 1 0 1 0 0 1 0 1 0 0 0 1 0 0 1 1 1 0 1 0 0 1 0 1 0 0 0 1 0 0 0 0 0 0 1 1 1 1 0 1 0 0 0 1 0 0 1 1 1 1 0 0 0 0 0 1 1 1 1 1 0 0 1 0 0 1 0 1 1 1 1 0 0 0 0 0 0 0 1 0 0 1 0 1 0 0 1 0 1 1 1 1 0 0 1 1 1 1 0 1 0 0 1 0 1 0 0 1 0 0 0 0 0 0 0 1 1 1 1 0 1 0 0 1 0 0 1 1 1 1 1 0 0 0 0 0 1 1 1 1 0 0 1 0 0 0 1 0 1 1 1 1 0 0 0 0 0 0 1 0 0 0 1 0 1 0 0 1 0 1 1 1 0 0 1 0 0 0 1 0 1 0 0 1 0 1 0 1 0 0 1 1 1 1 1 0 1 1 1 1 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; #X msg 447 200 setcell \$1 \$2 \$3; #N canvas 4 117 450 300 randomdata 0; #X obj 220 136 random 2; #X obj 62 89 t b b b; #X obj 62 35 inlet; #X obj 62 187 pack f f f; #X obj 62 222 outlet; #X obj 62 62 metro 10; #X obj 62 136 random 4; #X obj 141 136 random 4; #X connect 0 0 3 2; #X connect 1 0 6 0; #X connect 1 1 7 0; #X connect 1 2 0 0; #X connect 2 0 5 0; #X connect 3 0 4 0; #X connect 5 0 1 0; #X connect 6 0 3 0; #X connect 7 0 3 1; #X restore 447 175 pd randomdata; #X obj 447 151 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 1 1; #X obj 447 331 bitmap -cellsize 16 -uwidth 4 -uheight 4; #bitmap setdata 1 0 0 0 1 0 0 1 1 0 1 1 1 1 1 0; #X msg 465 231 setcol 1 0 0 0 0 \, setcol 2 0 0 0 0; #X msg 481 292 setrow \$1 \$2 \$2 \$3 \$3; #X msg 481 265 0 1 0 \, 1 1 0 \, 2 0 1 \, 3 0 1; #X connect 0 0 1 0; #X connect 2 0 11 0; #X connect 3 0 4 0; #X connect 5 0 2 0; #X connect 8 0 11 0; #X connect 9 0 8 0; #X connect 10 0 0 0; #X connect 12 0 13 0; #X connect 15 0 14 0; #X connect 16 0 14 0; #X connect 19 0 22 0; #X connect 20 0 19 0; #X connect 21 0 20 0; #X connect 23 0 22 0; #X connect 24 0 22 0; #X connect 25 0 24 0; tclpd-0.3.1/examples/bitmap-madness.pd000066400000000000000000000046501433742306500177040ustar00rootroot00000000000000#N canvas 5 140 311 321 10; #N canvas 322 138 514 645 in 1; #X obj 20 462 outlet; #X obj 51 8 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 0 1 ; #X obj 44 60 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 -1 -1; #N canvas 3 94 332 662 for_X_Y 0; #X obj 61 60 inlet; #X obj 71 223 until; #X msg 125 177 0; #X obj 72 261 f; #X obj 106 260 + 1; #X obj 68 141 t b b; #X obj 78 418 until; #X msg 132 372 0; #X obj 79 456 f; #X obj 113 455 + 1; #X obj 75 336 t b b; #X obj 73 297 t b f; #X obj 82 502 pack f f; #X msg 77 528 \$2 \$1; #X obj 74 589 outlet; #X msg 72 177 32; #X msg 79 372 32; #X connect 0 0 5 0; #X connect 1 0 3 0; #X connect 2 0 3 1; #X connect 3 0 4 0; #X connect 3 0 11 0; #X connect 4 0 3 1; #X connect 5 0 15 0; #X connect 5 1 2 0; #X connect 6 0 8 0; #X connect 7 0 8 1; #X connect 8 0 9 0; #X connect 8 0 12 0; #X connect 9 0 8 1; #X connect 10 0 16 0; #X connect 10 1 7 0; #X connect 11 0 10 0; #X connect 11 1 12 1; #X connect 12 0 13 0; #X connect 13 0 14 0; #X connect 15 0 1 0; #X connect 16 0 6 0; #X restore 50 125 pd for_X_Y; #X obj 78 270 sin; #X obj 78 227 / 64; #X obj 51 154 unpack f f; #X obj 107 190 t f f; #X obj 21 422 pack f f f; #X msg 21 442 setcell \$1 \$2 \$3; #X obj 76 297 + 0.5; #X obj 151 277 sin; #X obj 149 255 / 16; #X obj 79 321 +; #X obj 49 189 t f f f; #X obj 79 249 +; #X obj 228 155 f; #X obj 263 154 + 0.1; #X obj 49 94 t b b; #X obj 78 360 wrap; #X obj 77 401 i; #X obj 148 230 expr sqrt(pow(sin($f3)*32-$f1 \, 2)+pow(cos($f3)*34-$f2 \, 2)); #X obj 79 380 * 1.8; #X obj 79 341 * 1.2; #X obj 151 299 + 0.6; #X obj 52 35 metro 40; #X connect 1 0 25 0; #X connect 2 0 18 0; #X connect 3 0 6 0; #X connect 4 0 10 0; #X connect 5 0 15 0; #X connect 6 0 14 0; #X connect 6 1 7 0; #X connect 7 0 8 1; #X connect 7 1 21 1; #X connect 8 0 9 0; #X connect 9 0 0 0; #X connect 10 0 13 0; #X connect 11 0 24 0; #X connect 12 0 11 0; #X connect 13 0 23 0; #X connect 14 0 8 0; #X connect 14 1 5 0; #X connect 14 2 21 0; #X connect 15 0 4 0; #X connect 16 0 17 0; #X connect 16 0 21 2; #X connect 17 0 16 1; #X connect 18 0 3 0; #X connect 18 1 16 0; #X connect 19 0 22 0; #X connect 20 0 8 2; #X connect 21 0 12 0; #X connect 22 0 20 0; #X connect 23 0 19 0; #X connect 24 0 13 1; #X connect 25 0 18 0; #X restore 17 10 pd in; #X obj 17 34 bitmap -uwidth 32 -uheight 32 -cellsize 8 -label empty -labelpos top -sendsymbol empty -receivesymbol empty -fgcolor #000000 -bgcolor #ffffff -lblcolor #000000; #X connect 0 0 1 0; tclpd-0.3.1/examples/bitmap.tcl000066400000000000000000000247101433742306500164320ustar00rootroot00000000000000package require Tclpd 0.3.0 package require TclpdLib 0.20 set ::script_path [file dirname [info script]] pd::guiproc bitmap_draw_new {self c x y config data} { set w [dict get $config -uwidth] set h [dict get $config -uheight] set sz [dict get $config -cellsize] set fgcolor [dict get $config -fgcolor] set bgcolor [dict get $config -bgcolor] set colors [list $bgcolor $fgcolor] set z 0 for {set i 0} {$i < $h} {incr i} { for {set j 0} {$j < $w} {incr j} { $c create rectangle \ [expr {0+$x+$j*$sz}] [expr {0+$y+$i*$sz}] \ [expr {1+$x+($j+1)*$sz}] [expr {1+$y+($i+1)*$sz}] \ -outline $fgcolor -fill [lindex $colors [lindex $data $z]] \ -tags [list $self cell_${j}_${i}_$self] incr z } } set x2 [expr {$x+$w*$sz+1}] set y2 [expr {$y+$h*$sz+1}] $c create rectangle $x $y $x2 $y2 \ -outline $fgcolor -tags [list $self border$self] } proc+ bitmap::constructor {self args} { set @canvas [canvas_getcurrent] set s [file join $::script_path properties.tcl] sys_gui "source {$s}\n" pd::add_outlet $self float # set defaults: set @config [list] lappend @config -uwidth 8 lappend @config -uheight 8 lappend @config -cellsize 16 lappend @config -label {} lappend @config -labelpos {top} lappend @config -sendsymbol {} lappend @config -receivesymbol {} lappend @config -fgcolor {#000000} lappend @config -bgcolor {#ffffff} lappend @config -lblcolor {#000000} set @data { 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 } # expanded ($n) send/recv symbols: set @send {} set @recv {} 0_config $self {*}$args set @rcvLoadData {#bitmap} set x [pd_findbyclass $@rcvLoadData bitmap] if {$x ne "NULL"} { # prevent crash due to stale bound receivers: pd_unbind $x $@rcvLoadData } pd_bind $self $@rcvLoadData } proc+ bitmap::destructor {self} { set x [pd_findbyclass $@rcvLoadData bitmap] if {$x ne "NULL"} { pd_unbind $x $@rcvLoadData } if {[dict get $@config -receivesymbol] ne {}} { pd_unbind $self $@recv } } proc+ bitmap::0_config {self args} { if {$args eq {}} { return $@config } else { set newconf [list] set optlist [pd::strip_selectors $args] set optlist [pd::strip_empty $optlist] for {set i 0} {$i < [llength $optlist]} {} { set k [lindex $optlist $i] if {![dict exists $@config $k]} { return -code error "unknown option '$k'" } incr i set v [lindex $optlist $i] if {[lsearch -exact {-uwidth -uheight -cellsize} $k] != -1} { set v [expr {int($v)}] } dict set newconf $k $v incr i } if {[dict get $@config -uwidth] != [dict get $newconf -uwidth] || [dict get $@config -uheight] != [dict get $newconf -uheight]} { 0_resize $self {*}[pd::add_selectors [list \ [dict get $newconf -uwidth] \ [dict get $newconf -uheight] \ ]] } set ui 0 foreach opt {label labelpos cellsize fgcolor bgcolor lblcolor} { set old [dict get $@config -$opt] if {[dict exists $newconf -$opt]} { set new [dict get $newconf -$opt] if {$old ne $new} { dict set @config -$opt $new set ui 1 } } } foreach opt {sendsymbol receivesymbol} { set old [dict get $@config -$opt] if {[dict exists $newconf -$opt]} { set new [dict get $newconf -$opt] if {$old ne $new} { if {$opt eq {receivesymbol}} { if {$old ne {}} { pd_unbind $self $@recv } if {$new ne {}} { set @recv [canvas_realizedollar $@canvas $new] pd_bind $self $@recv } else { set @recv {} } } dict set @config -$opt $new } } } if {$ui && [info exists @c]} { sys_gui [list $@c delete $self]\n sys_gui [list bitmap_draw_new $self \ $@c $@x $@y $@config $@data]\n } } } proc+ bitmap::0_resize {self args} { set w [pd::arg 0 int] set h [pd::arg 1 int] set oldw [dict get $@config -uwidth] set oldh [dict get $@config -uheight] set newd {} for {set y 0} {$y < $h} {incr y} { for {set x 0} {$x < $w} {incr x} { if {$x < $oldw && $y < $oldh} { lappend newd [lindex $@data [expr {$y*$oldw+$x}]] } else { lappend newd 0 } } } dict set @config -uwidth $w dict set @config -uheight $h set @data $newd } proc+ bitmap::0_getrow {self args} { set r [list] set n [pd::arg 0 int] set w [dict get $@config -uwidth] for {set i [expr {$n*$w}]} {$i < [expr {($n+1)*$w}]} {incr i} { lappend r [list float [lindex $@data $i]] } pd::outlet $self 0 list $r } proc+ bitmap::0_getcol {self args} { set r [list] set n [pd::arg 0 int] set w [dict get $@config -uwidth] set h [dict get $@config -uheight] for {set i [expr {$n}]} {$i < [expr {$w*$h}]} {incr i $w} { lappend r [list float [lindex $@data $i]] } pd::outlet $self 0 list $r } proc+ bitmap::0_getcell {self args} { set r [pd::arg 0 int] set c [pd::arg 1 int] set w [dict get $@config -uwidth] pd::outlet $self 0 float [lindex $@data [expr {$r*$w+$c}]] } proc+ bitmap::0_setrow {self args} { set row [pd::arg 0 int] set z 1 set col 0 set w [dict get $@config -uwidth] set fgcolor [dict get $@config -fgcolor] set bgcolor [dict get $@config -bgcolor] set colors [list $bgcolor $fgcolor] for {set idx [expr {$row*$w}]} {$idx < [expr {($row+1)*$w}]} {incr idx} { set d [expr {0 != [pd::arg $z int]}] lset @data $idx $d sys_gui [list $@c itemconfigure cell_${col}_${row}_$self \ -fill [lindex $colors $d]]\n incr z incr col } } proc+ bitmap::0_setcol {self args} { set col [pd::arg 0 int] set z 1 set row 0 set w [dict get $@config -uwidth] set h [dict get $@config -uheight] set fgcolor [dict get $@config -fgcolor] set bgcolor [dict get $@config -bgcolor] set colors [list $bgcolor $fgcolor] for {set idx [expr {$col}]} {$idx < [expr {$w*$h}]} {incr idx $w} { set d [expr {0 != [pd::arg $z int]}] lset @data $idx $d sys_gui [list $@c itemconfigure cell_${col}_${row}_$self \ -fill [lindex $colors $d]]\n incr z incr row } } proc+ bitmap::0_setcell {self args} { set r [pd::arg 0 int] set c [pd::arg 1 int] set d [expr {0 != [pd::arg 2 int]}] set w [dict get $@config -uwidth] set fgcolor [dict get $@config -fgcolor] set bgcolor [dict get $@config -bgcolor] set colors [list $bgcolor $fgcolor] set idx [expr {$r*$w+$c}] lset @data $idx $d sys_gui [list $@c itemconfigure cell_${r}_${c}_$self \ -fill [lindex $colors $d]]\n } proc+ bitmap::0_setdata {self args} { set d [pd::strip_selectors $args] set l [llength $d] set w [dict get $@config -uwidth] set h [dict get $@config -uheight] if {$l != $w*$h} { return -code error "bad data size" } set @data [list] foreach i $d {lappend @data [expr {int($i)}]} set x [pd_findbyclass $@rcvLoadData bitmap] if {$x ne "NULL"} { pd_unbind $self $@rcvLoadData } } proc+ bitmap::save {self args} { return [list #X obj $@x $@y bitmap {*}[pd::add_empty $@config] \; \ \#bitmap setdata {*}$@data \; ] } proc+ bitmap::properties {self args} { set title "\[bitmap\] properties" set buf [list propertieswindow %s $@config $title]\n gfxstub_new $self $self $buf } proc+ bitmap::widgetbehavior_getrect {self args} { lassign $args x1 y1 set w [dict get $@config -uwidth] set h [dict get $@config -uheight] set sz [dict get $@config -cellsize] set x2 [expr {1+$x1+$w*$sz}] set y2 [expr {1+$y1+$h*$sz}] return [list $x1 $y1 $x2 $y2] } proc+ bitmap::widgetbehavior_displace {self args} { set dx [lindex $args 0] set dy [lindex $args 1] if {$dx != 0 || $dy != 0} { incr @x $dx incr @y $dy sys_gui [list $@c move $self $dx $dy]\n } return [list $@x $@y] } proc+ bitmap::widgetbehavior_select {self args} { set sel [lindex $args 0] set fgcolor [dict get $@config -fgcolor] set bgcolor [dict get $@config -bgcolor] set selcolor {blue} set colors [list $selcolor $fgcolor] sys_gui [list $@c itemconfigure $self \ -outline [lindex $colors $sel]]\n } proc+ bitmap::widgetbehavior_activate {self args} { } proc+ bitmap::widgetbehavior_vis {self args} { set @c [lindex $args 0] set @x [lindex $args 1] set @y [lindex $args 2] set vis [lindex $args 3] set w [dict get $@config -uwidth] set h [dict get $@config -uheight] set sz [dict get $@config -cellsize] if {$vis} { sys_gui [list bitmap_draw_new $self $@c $@x $@y $@config $@data]\n } else { sys_gui [list $@c delete $self]\n } } proc+ bitmap::widgetbehavior_click {self args} { set w [dict get $@config -uwidth] set h [dict get $@config -uheight] set sz [dict get $@config -cellsize] set fgcolor [dict get $@config -fgcolor] set bgcolor [dict get $@config -bgcolor] set colors [list $bgcolor $fgcolor] set xpix [expr {[lindex $args 0]-$@x-1}] set ypix [expr {[lindex $args 1]-$@y-1}] if {$xpix < 0 || $xpix >= $w*$sz} {return} if {$ypix < 0 || $ypix >= $h*$sz} {return} set shift [lindex $args 2] set alt [lindex $args 3] set dbl [lindex $args 4] set doit [lindex $args 5] if {$doit} { set j [expr {$xpix/$sz}] set i [expr {$ypix/$sz}] set idx [expr {$w*${i}+${j}}] set d [expr {[lindex $@data $idx] == 0}] lset @data $idx $d sys_gui [list $@c itemconfigure cell_${j}_${i}_$self \ -fill [lindex $colors $d]]\n } } pd::guiclass bitmap tclpd-0.3.1/examples/colorpicker.tcl000066400000000000000000000235111433742306500174700ustar00rootroot00000000000000if {[info exists ::colorpicker::version]} {return} namespace eval ::colorpicker { namespace export colorpicker # ========================================= # colorpicker set version 0.1 # (C) 2009 - Federico Ferri # mescalinum (at) gmail (dot) com # # Released under GPL-3 license: # http://www.gnu.org/licenses/gpl-3.0.html # ========================================= package provide colorpicker $version variable presets { ffffff dfdfdf bbbbbb ffc7c6 ffe3c6 feffc6 c6ffc7 c6feff c7c6ff e3c6ff 9f9f9f 7c7c7c 606060 ff0400 ff8300 faff00 00ff04 00faff 0400ff 9c00ff 404040 202020 000000 551312 553512 535512 0f4710 0e4345 131255 2f004d } proc colorpicker {w mode args} { variable {} set modes {switches hsv} if {[lsearch -exact $modes $mode] == -1} { error "bad mode: $mode. must be one of: $modes." } set ($w:mode) $mode set ($w:color) {#000000} set ($w:command) {} set ($w:textvar) {} frame $w init_$mode $w rename $w ::colorpicker::_$w interp alias {} $w {} ::colorpicker::dispatch $w if {$args ne {}} {uplevel 1 ::colorpicker::config $w $args} return $w } proc dispatch {w cmd args} { variable {} switch -glob -- $cmd { get {set ($w:color)} set {uplevel 1 [linsert $args 0 ::colorpicker::set_color_ext $w]} con* {uplevel 1 [linsert $args 0 ::colorpicker::config $w]} default {uplevel 1 [linsert $args 0 ::colorpicker::_$w $cmd]} } } proc config {w args} { variable {} set options {} set flag 0 foreach {key value} $args { switch -glob -- $key { -com* { set ($w:command) $value set flag 1 } -textvar* { set ($w:textvar) $value set flag 1 } default { lappend options $key $value } } } if {!$flag || $options ne {}} { uplevel 1 [linsert $options 0 ::scrolledframe::_$w config] } } proc set_color_ext {w c} { # called by the widget public method variable {} set c [string tolower $c] if {![regexp {^#[0-9a-f]{6,6}$} $c]} { error "Invalid color: $c. Specify a color in the format #HHHHHH" } switch -exact -- $($w:mode) { switches { set_color $w $c } hsv { set r [expr 0x[string range $c 1 2]] set g [expr 0x[string range $c 3 4]] set b [expr 0x[string range $c 5 6]] set hsv [rgbToHsv $r $g $b] hsv_set $w h [lindex $hsv 0] hsv_set $w s [lindex $hsv 1] hsv_set $w v [lindex $hsv 2] set_color $w $c } } } proc set_color {w c} { # called internally in reaction to events variable {} set c [string tolower $c] set ($w:color) $c if {$($w:command) ne {}} { set cmd $($w:command) lappend cmd $c uplevel #0 $cmd } if {$($w:textvar) ne {}} { uplevel #0 [list set $($w:textvar) $c] } switch -exact -- $($w:mode) { switches { variable presets set q 0 for {set row 0} {$row < 3} {incr row} { for {set col 0} {$col < 10} {incr col} { set b [expr {$c eq "#[lindex $presets $q]"}] ${w}.r${row}c${col} configure \ -relief [lindex {raised sunken} $b] incr q } } } hsv { } } } proc mkColor {rgb} { set r [lindex $rgb 0]; set g [lindex $rgb 1]; set b [lindex $rgb 2] if {$r < 0} {set r 0} elseif {$r > 255} {set r 255} if {$g < 0} {set g 0} elseif {$g > 255} {set g 255} if {$b < 0} {set b 0} elseif {$b > 255} {set b 255} return #[format {%2.2x%2.2x%2.2x} $r $g $b] } proc rgbToHsv {r g b} { set sorted [lsort -real [list $r $g $b]] set temp [lindex $sorted 0] set v [lindex $sorted 2] set value $v set bottom [expr {$v-$temp}] if {$bottom == 0} { set hue 0 set saturation 0 set value $v } else { if {$v == $r} { set top [expr {$g-$b}] if {$g >= $b} { set angle 0 } else { set angle 360 } } elseif {$v == $g} { set top [expr {$b-$r}] set angle 120 } elseif {$v == $b} { set top [expr {$r-$g}] set angle 240 } set hue [expr {round(60*(double($top)/$bottom)+$angle)}] } if {$v == 0} { set saturation 0 } else { set saturation [expr {round(255-255*(double($temp)/$v))}] } return [list $hue $saturation $value] } proc hsvToRgb {h s v} { set hi [expr {int(double($h)/60)%6}] set f [expr {double($h)/60-$hi}] set s [expr {double($s)/255}] set v [expr {double($v)/255}] set p [expr {double($v)*(1-$s)}] set q [expr {double($v)*(1-$f*$s)}] set t [expr {double($v)*(1-(1-$f)*$s)}] switch -- $hi { 0 {set r $v; set g $t; set b $p} 1 {set r $q; set g $v; set b $p} 2 {set r $p; set g $v; set b $t} 3 {set r $p; set g $q; set b $v} 4 {set r $t; set g $p; set b $v} 5 {set r $v; set g $p; set b $q} default {error "[lindex [info level 0] 0]: bad H value"} } set r [expr {round($r*255)}] set g [expr {round($g*255)}] set b [expr {round($b*255)}] return [list $r $g $b] } proc init_switches {w} { variable {} variable presets set q 0 for {set row 0} {$row < 3} {incr row} { for {set col 0} {$col < 10} {incr col} { set c "#[lindex $presets $q]" set b [expr {$($w:color) eq $c}] grid [frame ${w}.r${row}c${col} -width 18 -height 16 \ -borderwidth 1 -relief [lindex {raised sunken} $b] \ -background $c -highlightthickness 0] \ -row $row -column $col bind ${w}.r${row}c${col} \ "[namespace current]::set_color $w $c" incr q } } } proc init_hsv {w} { variable colorhsv set colorhsv($w:h) 0 set colorhsv($w:s) 255 set colorhsv($w:v) 255 grid [canvas ${w}.hue -width 130 -height 15 -borderwidth 1 \ -relief sunken -highlightthickness 0] -column 0 -row 0 grid [canvas ${w}.sat -width 130 -height 14 -borderwidth 1 \ -relief sunken -highlightthickness 0] -column 0 -row 1 grid [canvas ${w}.val -width 130 -height 14 -borderwidth 1 \ -relief sunken -highlightthickness 0] -column 0 -row 2 grid [canvas ${w}.test -width 46 -height 46 -borderwidth 1 \ -relief sunken -highlightthickness 0 -background red] \ -column 1 -row 0 -rowspan 3 variable mh variable ms variable mv set mh($w) 0; set ms($w) 0; set mv($w) 0; set sh "[namespace current]::hsv_set $w h \[expr {%x*360.0/130.0}\]" set ss "[namespace current]::hsv_set $w s \[expr {%x*255.0/130.0}\]" set sv "[namespace current]::hsv_set $w v \[expr {%x*255.0/130.0}\]" bind ${w}.hue "set [namespace current]::mh($w) 1; $sh" bind ${w}.sat "set [namespace current]::ms($w) 1; $ss" bind ${w}.val "set [namespace current]::mv($w) 1; $sv" bind ${w}.hue "set [namespace current]::mh($w) 0" bind ${w}.sat "set [namespace current]::ms($w) 0" bind ${w}.val "set [namespace current]::mv($w) 0" bind ${w}.hue "if {\$[namespace current]::mh($w)} {$sh}" bind ${w}.sat "if {\$[namespace current]::ms($w)} {$ss}" bind ${w}.val "if {\$[namespace current]::mv($w)} {$sv}" for {set x 0} {$x < 130} {incr x 3} { set c [mkColor [hsvToRgb [expr {$x*360.0/130.0}] 255 255]] ${w}.hue create rectangle $x 0 [expr {4+$x}] 16 -fill $c -outline {} } hsv_regen $w $colorhsv($w:h) } proc hsv_regen {w hue} { ${w}.sat delete all ${w}.val delete all for {set x 0} {$x < 130} {incr x 3} { set x1 [expr {$x*255.0/130.0}] set c1 [mkColor [hsvToRgb $hue $x1 255]] set c2 [mkColor [hsvToRgb $hue 255 $x1]] ${w}.sat create rectangle $x 0 [expr {4+$x}] 16 \ -fill $c1 -outline {} ${w}.val create rectangle $x 0 [expr {4+$x}] 16 \ -fill $c2 -outline {} } } proc hsv_set {w what val} { variable colorhsv if {$what ne {h} && $what ne {s} && $what ne {v}} {return} set colorhsv($w:$what) $val if {$colorhsv($w:$what) < 0.0} {set colorhsv($w:$what) 0} if {$what eq {h}} { if {$colorhsv($w:$what) >= 360.0} {set colorhsv($w:$what) 0} hsv_regen $w $colorhsv($w:$what) } else { if {$colorhsv($w:$what) > 255.0} {set colorhsv($w:$what) 255} } set c [mkColor [hsvToRgb \ $colorhsv($w:h) $colorhsv($w:s) $colorhsv($w:v)]] ${w}.test configure -background $c set_color $w $c } } tclpd-0.3.1/examples/dynreceive-help.pd000066400000000000000000000012361433742306500200600ustar00rootroot00000000000000#N canvas 416 120 513 409 10; #X obj 141 168 s \$0.foo; #X msg 46 120 bar baz; #X obj 60 320 dynreceive \$0.foo; #X floatatom 122 123 5 0 0 0 - - -; #X symbolatom 177 125 10 0 0 0 - - -; #X obj 267 125 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 -1 -1; #X text 43 86 1) send some symbols:; #X text 45 240 2) try to change the receive symbol:; #X msg 60 287 set xyz; #X msg 312 306 \; xyz 1 2 3; #X obj 60 350 print out; #X text 39 23 Works like [receive] \, but allows to dynamically set (or clear) the receive symbol.; #X text 139 288 <--; #X connect 1 0 0 0; #X connect 2 0 10 0; #X connect 3 0 0 0; #X connect 4 0 0 0; #X connect 5 0 0 0; #X connect 8 0 2 0; tclpd-0.3.1/examples/dynreceive.tcl000066400000000000000000000022071433742306500173100ustar00rootroot00000000000000package require Tclpd 0.3.0 package require TclpdLib 0.20 proc+ dynreceive::constructor {self args} { set @sym {} if {[pd::args] > 0} { set @sym [pd::arg 0 symbol] pd_bind $self $@sym } pd::add_outlet $self } proc+ dynreceive::destructor {self} { # don't forget to call pd_unbind, or sending things to a symbol # bound to dead object will crash pd! if {$@sym ne {}} { pd_unbind $self $@sym } } proc+ dynreceive::0_set {self args} { # send [set empty( to clear the receive symbol set s [pd::arg 0 symbol] if {$@sym eq {}} { pd_unbind $self $@sym } if {$s eq {empty}} { set @sym {} } else { set @sym $s pd_bind $self $@sym } } proc+ dynreceive::0_bang {self} { pd::outlet $self 0 bang } proc+ dynreceive::0_float {self args} { pd::outlet $self 0 float [pd::arg 0 float] } proc+ dynreceive::0_symbol {self args} { pd::outlet $self 0 symbol [pd::arg 0 symbol] } proc+ dynreceive::0_anything {self args} { set sel [pd::arg 0 symbol] set argz [lrange $args 1 end] pd::outlet $self 0 $sel $argz } pd::class dynreceive tclpd-0.3.1/examples/dynroute-help.pd000066400000000000000000000017201433742306500175720ustar00rootroot00000000000000#N canvas 342 108 616 430 10; #X obj 93 268 dynroute 4; #X msg 41 147 apple red \, banana yellow \, pear green \, apple yellow \, strawberry red; #X obj 41 194 list prepend; #X msg 200 224 clear \, add apple 0 \, add banana 1 \, add pear 2; #X msg 206 258 remove pear 2 \, add pear 0 \, add strawberry 2; #X text 39 32 Dynamically route lists based on first element \, according to the mapping specified on right inlet. Creation argument (float) specifies how many outlet to have (including last outlet \, which is used for sending unmatching items); #X text 44 120 Test it with some data:; #X obj 93 379 print out1; #X obj 115 352 print out2; #X obj 137 325 print out3; #X obj 160 298 print other; #X text 256 293 <-- non-matching stuff is sent here; #X text 196 192 Change the mapping:; #X connect 0 0 7 0; #X connect 0 1 8 0; #X connect 0 2 9 0; #X connect 0 3 10 0; #X connect 1 0 2 0; #X connect 2 0 0 0; #X connect 3 0 0 1; #X connect 4 0 0 1; tclpd-0.3.1/examples/dynroute.tcl000066400000000000000000000027141433742306500170270ustar00rootroot00000000000000package require Tclpd 0.3.0 package require TclpdLib 0.20 # dynroute: dynamically route messages based on first element # non-matching arguments are sent to last inlet # constructor: specify the number of outlets (default: 1) # send commands to the right inlet # available commands: # add route selector to output number # remove remove previously created routing # clear proc+ dynroute::constructor {self args} { pd::add_inlet $self list set @num_outlets [pd::arg 0 int] if {$@num_outlets < 0} {set @num_outlets 2} for {set i 0} {$i < $@num_outlets} {incr i} { pd::add_outlet $self list } set @routing {} } proc+ dynroute::0_list {self args} { set sel [pd::arg 0 any] set out [expr {$@num_outlets-1}] catch {set out [dict get $@routing $sel]} pd::outlet $self $out list $args } proc+ dynroute::1_add {self args} { set sel [pd::arg 0 any] set out [pd::arg 1 int] if {$out < 0 || $out >= $@num_outlets} { pd::post "error: add: outlet number out of range" return } dict set @routing $sel $out } proc+ dynroute::1_remove {self args} { set sel [pd::arg 0 any] set out [pd::arg 1 int] if {$out < 0 || $out >= $@num_outlets} { pd::post "error: add: outlet number out of range" return } catch {dict unset @routing $sel $out} } proc+ dynroute::1_clear {self} { set @routing {} } pd::class dynroute tclpd-0.3.1/examples/list_change-help.pd000066400000000000000000000012121433742306500201750ustar00rootroot00000000000000#N canvas 294 76 635 406 10; #X obj 54 240 list_change; #X text 144 236 right inlet sets internal value without output anything ; #X obj 71 271 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 -1 -1; #X obj 54 309 print; #X text 33 21 Outputs its input (a list) only when it changes. You can set the current value using the right inlet \, or bang to force output; #X msg 117 201 list foo bar; #X msg 69 140 list foo bar; #X msg 77 163 list bar baz; #X msg 54 104 bang; #X text 98 103 output current value; #X connect 0 0 2 0; #X connect 0 0 3 0; #X connect 5 0 0 1; #X connect 6 0 0 0; #X connect 7 0 0 0; #X connect 8 0 0 0; tclpd-0.3.1/examples/list_change.tcl000066400000000000000000000011701433742306500174310ustar00rootroot00000000000000package require Tclpd 0.3.0 package require TclpdLib 0.20 proc+ list_change::constructor {self args} { # add second inlet (first created by default) pd::add_inlet $self list # add outlet pd::add_outlet $self list set @curlist {} } proc+ list_change::0_list {self args} { # HOT inlet if {$args ne $@curlist} { set @curlist $args pd::outlet $self 0 list $@curlist } } proc+ list_change::0_bang {self} { if {$@curlist eq {}} return pd::outlet $self 0 list $@curlist } proc+ list_change::1_list {self args} { # COLD inlet set @curlist $args } pd::class list_change tclpd-0.3.1/examples/properties.tcl000066400000000000000000000353161433742306500173560ustar00rootroot00000000000000if {[catch {package require colorpicker}]} { source [file join [file dirname [info script]] colorpicker.tcl] package require colorpicker } namespace import ::colorpicker::colorpicker proc propertieswindow {gfxstub_id {options {}} {title {}}} { set win $gfxstub_id set ::id($win.p) $gfxstub_id set ::optkeys($win.p) [list] set options [string map {@ $} $options] foreach {k v} $options { if {$v eq {empty}} {set v {}} #set v [string map {\\$ $} $v] set ::config($win.p:$k) $v lappend ::optkeys($win.p) $k } toplevel $win pack [propertiespanel $win.p] wm resizable $win 0 0 wm title $win $title set win } proc has_key {w key} { expr {[lsearch -exact $::optkeys($w) $key] != -1} } proc propertiespanel {w} { set pad [propertiespanel_padding $w] incr pad $pad frame $w -borderwidth 0 -relief raised -padx $pad -pady $pad set subpanels {dimensions output behavior connective label colors} foreach subpanel $subpanels { set x [propertiespanel_$subpanel $w] if {$x ne {}} {grid $x -sticky ew -in $w} } set x [propertiespanel_buttons $w] grid $x -in $w grid columnconfigure . 0 -weight 1 set w } proc propertiespanel_padding {w} { return 3 } proc propertiespanel_dimensions {w} { set x ${w}.dimensions set pad [propertiespanel_padding $w] labelframe $x -text "Dimensions:" -borderwidth 1 -relief raised set count 0 set row 0; set col 0 if {[has_key $w -width]} { grid [label ${x}.wl -text "Width (px):" -anchor e] \ -row $row -column $col -sticky ew -padx $pad -pady $pad incr col grid [entry ${x}.w -textvar ::config($w:-width) -width 5] \ -row $row -column $col -sticky ew -padx $pad -pady $pad incr col incr count } if {[has_key $w -height]} { grid [label ${x}.hl -text "Height (px):" -anchor e] \ -row $row -column $col -sticky ew -padx $pad -pady $pad incr col grid [entry ${x}.h -textvar ::config($w:-height) -width 5] \ -row $row -column $col -sticky ew -padx $pad -pady $pad incr col incr count } incr row; set col 0 if {[has_key $w -uwidth]} { grid [label ${x}.uwl -text "Width (cells):" -anchor e] \ -row $row -column $col -sticky ew -padx $pad -pady $pad incr col grid [entry ${x}.uw -textvar ::config($w:-uwidth) -width 5] \ -row $row -column $col -sticky ew -padx $pad -pady $pad incr col incr count } if {[has_key $w -uheight]} { grid [label ${x}.uhl -text "Height (cells):" -anchor e] \ -row $row -column $col -sticky ew -padx $pad -pady $pad incr col grid [entry ${x}.uh -textvar ::config($w:-uheight) -width 5] \ -row $row -column $col -sticky ew -padx $pad -pady $pad incr col incr count } incr row; set col 0 if {[has_key $w -cellsize]} { grid [label ${x}.csl -text "Cell size (pixels):" -anchor e] \ -row $row -column $col -sticky ew -padx $pad -pady $pad incr col grid [entry ${x}.cs -textvar ::config($w:-cellsize) -width 5] \ -row $row -column $col -sticky ew -padx $pad -pady $pad incr col incr count } incr row; set col 0 if {[has_key $w -cellwidth]} { grid [label ${x}.uwl -text "Cell width:" -anchor e] \ -row $row -column $col -sticky ew -padx $pad -pady $pad incr col grid [entry ${x}.uw -textvar ::config($w:-cellwidth) -width 5] \ -row $row -column $col -sticky ew -padx $pad -pady $pad incr col incr count } if {[has_key $w -cellheight]} { grid [label ${x}.uhl -text "Cell height:" -anchor e] \ -row $row -column $col -sticky ew -padx $pad -pady $pad incr col grid [entry ${x}.uh -textvar ::config($w:-cellheight) -width 5] \ -row $row -column $col -sticky ew -padx $pad -pady $pad incr col incr count } incr row; set col 0 if {$count == 0} {return {}} set x } proc propertiespanel_output {w} { set x ${w}.output set pad [propertiespanel_padding $w] labelframe $x -text "Output range:" -borderwidth 1 -relief raised set count 0 set row 0; set col 0 if {[has_key $w -rangebottom]} { grid [label ${x}.rbl -text "Bottom:" -anchor e] \ -row $row -column $col -sticky ew -padx $pad -pady $pad incr col grid [entry ${x}.rb -textvar ::config($w:-rangebottom) -width 5] \ -row $row -column $col -sticky ew -padx $pad -pady $pad incr col incr count } if {[has_key $w -rangetop]} { grid [label ${x}.rtl -text "Top:" -anchor e] \ -row $row -column $col -sticky ew -padx $pad -pady $pad incr col grid [entry ${x}.rt -textvar ::config($w:-rangetop) -width 5] \ -row $row -column $col -sticky ew -padx $pad -pady $pad incr col incr count } incr row; set col 0 if {[has_key $w -rangeleft]} { grid [label ${x}.rll -text "Left:" -anchor e] \ -row $row -column $col -sticky ew -padx $pad -pady $pad incr col grid [entry ${x}.rl -textvar ::config($w:-rangeleft) -width 5] \ -row $row -column $col -sticky ew -padx $pad -pady $pad incr col incr count } if {[has_key $w -rangeright]} { grid [label ${x}.rrl -text "Right:" -anchor e] \ -row $row -column $col -sticky ew -padx $pad -pady $pad incr col grid [entry ${x}.rr -textvar ::config($w:-rangeright) -width 5] \ -row $row -column $col -sticky ew -padx $pad -pady $pad incr col incr count } incr row; set col 0 if {[has_key $w -rangemin]} { grid [label ${x}.rml -text "Min:" -anchor e] \ -row $row -column $col -sticky ew -padx $pad -pady $pad incr col grid [entry ${x}.rm -textvar ::config($w:-rangemin) -width 5] \ -row $row -column $col -sticky ew -padx $pad -pady $pad incr col incr count } if {[has_key $w -rangemax]} { grid [label ${x}.rMl -text "Max:" -anchor e] \ -row $row -column $col -sticky ew -padx $pad -pady $pad incr col grid [entry ${x}.rM -textvar ::config($w:-rangemax) -width 5] \ -row $row -column $col -sticky ew -padx $pad -pady $pad incr col incr count } incr row; set col 0 if {[has_key $w -logarithmic]} { incr col grid [checkbutton ${x}.rL -variable ::config($w:-logarithmic) \ -text "Logarithmic"] \ -row $row -column $col -columnspan 3 -sticky w -padx $pad -pady $pad incr col incr count } incr row; set col 0 if {$count == 0} {return {}} set x } proc propertiespanel_behavior {w} { set x ${w}.behavior set pad [propertiespanel_padding $w] labelframe $x -text "Widget behavior:" -borderwidth 1 -relief raised set count 0 set row 0; set col 0 if {[has_key $w -jumponclick]} { grid [checkbutton ${x}.joc -variable ::config($w:-jumponclick) \ -text "Jump on click"] \ -row $row -column $col -sticky w -padx $pad -pady $pad incr col incr count } if {[has_key $w -init]} { grid [checkbutton ${x}.init -variable ::config($w:-init) \ -text "Output init value"] \ -row $row -column $col -sticky w -padx $pad -pady $pad incr col incr count } incr row; set col 0 if {$count == 0} {return {}} set x } proc propertiespanel_label {w} { set x ${w}.label set pad [propertiespanel_padding $w] labelframe $x -text "Label:" -borderwidth 1 -relief raised set count 0 set row 0 if {[has_key $w -label]} { grid [label ${x}.ll -text "Text:" -anchor e] \ -row $row -column 0 -sticky ew -padx $pad -pady $pad grid [entry ${x}.l -textvar ::config($w:-label)] \ -row $row -column 1 -sticky ew -padx $pad -pady $pad incr row incr count } if {[has_key $w -labelpos]} { grid [label ${x}.lpl -text "Position:" -anchor e] \ -row $row -column 0 -sticky ew -padx $pad -pady $pad frame ${x}.f if {![info exists ::config($w:-labelpos)]} { set ::config($w:-labelpos) top } grid [radiobutton ${x}.f.lp1 -variable ::config($w:-labelpos) \ -value top -text Top] \ -row 1 -column 1 -sticky w -padx $pad -pady $pad -in ${x}.f grid [radiobutton ${x}.f.lp2 -variable ::config($w:-labelpos) \ -value bottom -text Bottom] \ -row 1 -column 2 -sticky w -padx $pad -pady $pad -in ${x}.f grid [radiobutton ${x}.f.lp3 -variable ::config($w:-labelpos) \ -value left -text Left] \ -row 2 -column 1 -sticky w -padx $pad -pady $pad -in ${x}.f grid [radiobutton ${x}.f.lp4 -variable ::config($w:-labelpos) \ -value right -text Right] \ -row 2 -column 2 -sticky w -padx $pad -pady $pad -in ${x}.f grid ${x}.f -sticky w -row $row -column 1 incr row incr count } if {$count == 0} {return {}} set x } proc propertiespanel_connective {w} { set x ${w}.connective set pad [propertiespanel_padding $w] labelframe $x -text "Messages:" -borderwidth 1 -relief raised set count 0 set row 0 if {[has_key $w -sendsymbol]} { grid [label ${x}.ssl -text "Send symbol:" -anchor e] \ -row $row -column 0 -sticky ew -padx $pad -pady $pad grid [entry ${x}.ss -textvar ::config($w:-sendsymbol) -width 15] \ -row $row -column 1 -sticky ew -padx $pad -pady $pad incr row incr count } if {[has_key $w -receivesymbol]} { grid [label ${x}.rsl -text "Receive symbol:" -anchor e] \ -row $row -column 0 -sticky ew -padx $pad -pady $pad grid [entry ${x}.rs -textvar ::config($w:-receivesymbol) -width 15] \ -row $row -column 1 -sticky ew -padx $pad -pady $pad incr row incr count } if {$count == 0} {return {}} set x } proc propertiespanel_colors {w} { set colors {-bgcolor Background -fgcolor Foreground -lblcolor Label} set x ${w}.colors set pad [propertiespanel_padding $w] labelframe $x -text "Colors:" -borderwidth 1 -relief raised set count 0 set row 0 foreach {optkey color} $colors { if {![has_key $w $optkey]} {continue} grid [label ${x}.l$color -text "${color}:" -anchor e] \ -row $row -column 0 -sticky ew -padx $pad -pady $pad grid [entry ${x}.t$color -textvar ::config($w:$optkey) -width 8] \ -row $row -column 1 -sticky ew -padx $pad -pady $pad grid [frame ${x}.p$color -width 20 -height 20 \ -borderwidth 1 -relief sunken] \ -row $row -column 2 -sticky ew -padx $pad -pady $pad grid [button ${x}.b$color -text "Pick..." -overrelief {} \ -command {} \ ] -row $row -column 3 -sticky ew -padx $pad -pady $pad bind ${x}.b$color {break} bind ${x}.b$color {break} bind ${x}.b$color [list \ propertiespanel_colors_pick \ $w $x $colors ${x}.b$color ${x}.p$color ${x}.t$color] trace add variable ::config($w:$optkey) write [list \ propertiespanel_colors_set_wrap $w $x ${x}.p$color $optkey] incr row incr count } if {![info exists ::cpt($w)]} {set ::cpt($w) switches} foreach {optkey color} $colors { if {![has_key $w $optkey]} {continue} # trigger the variable trace: if {[info exists ::config($w:$optkey)]} { set ::config($w:$optkey) $::config($w:$optkey) } } if {$count == 0} {return {}} frame ${x}.f grid [radiobutton ${x}.f.cpt1 -variable ::cpt($w) -justify right \ -value switches -text Switches] \ -row 0 -column 0 -sticky ew -padx $pad -pady $pad grid [radiobutton ${x}.f.cpt2 -variable ::cpt($w) -justify right \ -value hsv -text HSV] \ -row 1 -column 0 -sticky ew -padx $pad -pady $pad grid ${x}.f -row $row -column 0 grid [colorpicker ${x}.cp2 hsv] \ -row $row -column 1 -columnspan 3 -sticky ew -padx $pad -pady $pad grid [colorpicker ${x}.cp1 switches -command [list ${x}.cp2 set]] \ -row $row -column 1 -columnspan 3 -sticky ew -padx $pad -pady $pad raise ${x}.cp1 trace add variable ::cpt($w) write \ [list propertiespanel_colors_switchpicker $w $x $row] set x } proc propertiespanel_colors_set_wrap {w x wp optkey config_ idx op} { propertiespanel_colors_set $w $x $wp {} -1 $::config($w:$optkey) } proc propertiespanel_colors_switchpicker {w x row cpt idx op} { raise ${x}.cp[expr {1+($::cpt($w) eq {hsv})}] } proc propertiespanel_colors_pick {w x colors wb wp wt} { foreach {k color} $colors { ${x}.b$color configure -relief raised -state normal } set r [$wb cget -relief] if {$r eq {sunken}} { $wb configure -relief raised ${x}.cp1 configure -command {} ${x}.cp2 configure -command {} } else { $wb configure -relief sunken ${x}.cp1 configure -command \ [list propertiespanel_colors_set $w $x $wp $wt 1] ${x}.cp2 configure -command \ [list propertiespanel_colors_set $w $x $wp $wt 2] } } proc propertiespanel_colors_set {w x wp wt from color} { if {$wt ne {}} {$wt delete 0 end ; $wt insert 0 $color} $wp configure -background $color if {$::cpt($w) eq {switches} && $from == 1} { ${x}.cp2 set $color } } proc propertiespanel_buttons {w} { set x ${w}.buttons set pad [propertiespanel_padding $w] frame $x -padx $pad -pady $pad set col 0 foreach action {Cancel Apply Ok} { grid [button ${x}.btn$action \ -command [list propertiespanel_buttons_action $w $action] \ -text $action] \ -row 0 -column $col -padx $pad -pady $pad incr col } set x } proc propertiespanel_buttons_action {w action} { switch -- $action { Cancel { propertiespanel_close $w } Apply { propertiespanel_apply $w } Ok { propertiespanel_apply $w propertiespanel_close $w } } } proc propertiespanel_apply {w} { set newconf [list] foreach key $::optkeys($w) { set v $::config($w:$key) if {$v eq {}} {set v {empty}} lappend newconf $key $v } #set newconf [string map {$ \\$} $newconf] set newconf [string map {$ @} $newconf] pdsend "$::id($w) config2 $newconf" } proc propertiespanel_close {w} { pdsend "$::id($w) cancel" } tclpd-0.3.1/examples/slider2-help.pd000066400000000000000000000045001433742306500172640ustar00rootroot00000000000000#N canvas 79 235 731 505 10; #X obj 343 150 slider2 -width 15 -height 130 -headsz 3 -rangebottom 0 -rangetop 127 -init 0 -initvalue 94 -jumponclick 0 -label norm -labelpos top -orient vertical -sendsymbol empty -receivesymbol empty -fgcolor #000000 -bgcolor #ffffff -lblcolor #000000; #X obj 401 150 slider2 -width 15 -height 130 -headsz 3 -rangebottom 127 -rangetop 0 -init 0 -initvalue 63 -jumponclick 0 -label rev -labelpos top -orient vertical -sendsymbol empty -receivesymbol empty -fgcolor #000000 -bgcolor #ffffff -lblcolor #000000; #X obj 522 154 slider2 -width 130 -height 15 -headsz 3 -rangebottom 0 -rangetop 127 -init 0 -initvalue 95 -jumponclick 0 -label norm -labelpos top -orient horizontal -sendsymbol empty -receivesymbol empty -fgcolor #000000 -bgcolor #ffffff -lblcolor #000000; #X obj 522 213 slider2 -width 130 -height 15 -headsz 3 -rangebottom 127 -rangetop 0 -init 0 -initvalue 70 -jumponclick 0 -label rev -labelpos top -orient horizontal -sendsymbol empty -receivesymbol empty -fgcolor #000000 -bgcolor #ffffff -lblcolor #000000; #X floatatom 343 295 5 0 0 0 - - -; #X floatatom 401 295 5 0 0 0 - - -; #X floatatom 522 177 5 0 0 0 - - -; #X floatatom 522 236 5 0 0 0 - - -; #X text 324 109 -orient vertical; #X text 523 111 -orient horizontal; #X text 321 61 Output range test:; #X obj 46 174 slider2 -width 15 -height 130 -headsz 3 -rangebottom 0 -rangetop 127 -init 0 -initvalue 10 -jumponclick 0 -label empty -labelpos top -orient vertical -sendsymbol empty -receivesymbol empty -fgcolor #000000 -bgcolor #ffffff -lblcolor #000000; #X msg 46 143 config -orient vertical; #X msg 46 113 config -orient horizontal; #X floatatom 46 321 5 0 0 0 - - -; #X obj 159 358 slider2 -width 130 -height 15 -headsz 3 -rangebottom 0 -rangetop 255 -init 0 -initvalue 202.795 -jumponclick 0 -label empty -labelpos top -orient horizontal -sendsymbol \$0.sl-out -receivesymbol \$0.sl-in -fgcolor #000000 -bgcolor #20ca34 -lblcolor #000000; #X obj 45 358 r \$0.sl-out; #X obj 45 466 s \$0.sl-in; #X msg 45 439 config -bgcolor \$1; #X obj 45 412 makefilename #%6.6x; #X obj 45 385 expr (0x20 << 16) | ($f1 << 8) | (0xff - $f1); #X connect 0 0 4 0; #X connect 1 0 5 0; #X connect 2 0 6 0; #X connect 3 0 7 0; #X connect 11 0 14 0; #X connect 12 0 11 0; #X connect 13 0 11 0; #X connect 16 0 20 0; #X connect 18 0 17 0; #X connect 19 0 18 0; #X connect 20 0 19 0; tclpd-0.3.1/examples/slider2.tcl000066400000000000000000000237421433742306500165260ustar00rootroot00000000000000package require Tclpd 0.3.0 package require TclpdLib 0.20 set ::script_path [file dirname [info script]] pd::guiproc slider2_draw_new {self c x y config state} { # import variables from dicts: foreach v {headsz width height fgcolor bgcolor orient} \ {set $v [dict get $config -$v]} set x2 [expr {$x+$width+1}] set y2 [expr {$y+$height+1}] $c create rectangle $x $y $x2 $y2 \ -outline $fgcolor -fill $bgcolor -tags [list $self border$self] switch $orient { horizontal {set y1 $y; set x3 [expr {$x+$headsz}]} vertical {set y1 [expr {$y2-$headsz}]; set x3 $x2} } $c create rectangle $x $y1 $x3 $y2 -outline {} -fill $fgcolor \ -tags [list $self head$self] slider2_update $self $c $x $y $config $state } pd::guiproc slider2_update {self c x y config state} { # import variables from dicts: foreach v {initvalue headsz width height label labelpos lblcolor orient} \ {set $v [dict get $config -$v]} foreach v {min max rev} {set $v [dict get $state _$v]} set realvalue [expr {1.0*($initvalue-$min)/($max-$min)}] if {$realvalue < 0.0} {set realvalue 0} if {$realvalue > 1.0} {set realvalue 1} if {$rev} {set realvalue [expr {1.0-$realvalue}]} if {$orient eq {vertical}} {set realvalue [expr {1.0-$realvalue}]} switch $orient { horizontal { set hr [expr {$width-$headsz}] $c coords head$self [expr {$x+$hr*$realvalue}] $y \ [expr {$x+$hr*$realvalue+$headsz}] [expr {$y+$height+1}] } vertical { set vr [expr {$height-$headsz}] $c coords head$self $x [expr {$y+$vr*$realvalue}] \ [expr {$x+$width+1}] [expr {$y+$vr*$realvalue+$headsz}] } } $c delete label$self if {$label ne {}} { switch $labelpos { top {set lx [expr {$x+$width/2}]; set ly [expr {$y}]; set a "s"} bottom {set lx [expr {$x+$width/2}]; set ly [expr {$y+$height+2}]; set a "n"} left {set lx [expr {$x}]; set ly [expr {$y+$height/2}]; set a "e"} right {set lx [expr {$x+$width+2}]; set ly [expr {$y+$height/2}]; set a "w"} } $c create text $lx $ly -anchor $a -text $label -fill $lblcolor \ -tags [list $self label$self] } } proc+ slider2::constructor {self args} { set @canvas [canvas_getcurrent] pd::add_outlet $self float sys_gui "source {[file join $::script_path properties.tcl]}\n" # set defaults: set @config { -width 15 -height 130 -headsz 3 -rangebottom 0 -rangetop 127 -init 0 -initvalue 0 -jumponclick 0 -label {} -labelpos {top} -orient {vertical} -sendsymbol {} -receivesymbol {} -fgcolor {#000000} -bgcolor {#ffffff} -lblcolor {#000000} } set @state {_min 0 _max 127 _rev 0} # expanded ($n) send/recv symbols: set @send {} set @recv {} 0_config $self {*}$args } proc+ slider2::destructor {self} { if {[dict get $@config -receivesymbol] ne {}} { pd_unbind $self $@recv } } proc+ slider2::0_loadbang {self} { if {[dict get $@config -init]} {0_bang $self} } proc+ slider2::0_printconfig {self args} { if {[llength $args] == 0} { pd::post $@config return } } proc+ slider2::0_config2 {self args} { uplevel "0_config $self [string map {$ @} $args]" } proc+ slider2::0_config {self args} { pd::post [info level 0] set newconf [list] set optlist [pd::strip_selectors $args] set optlist [pd::strip_empty $optlist] set int_opts {-width -height -cellsize} set bool_opts {-init -jumponclick} set ui_opts {-fgcolor -bgcolor -lblcolor -orient -width -height} set upd_opts {-rangebottom -rangetop -label -labelpos} set conn_opts {-sendsymbol -receivesymbol} set ui 0 set upd 0 foreach {k v} $optlist { if {![dict exists $@config $k]} { return -code error "unknown option '$k'" } if {[dict get $@config $k] eq $v} {continue} if {[lsearch -exact $int_opts $k] != -1} {set v [expr {int($v)}]} if {[lsearch -exact $bool_opts $k] != -1} {set v [expr {int($v) != 0}]} if {[lsearch -exact $ui_opts $k] != -1} {set ui 1} if {[lsearch -exact $upd_opts $k] != -1} {set upd 1} dict set newconf $k $v } # process -{send,receive}symbol if {[dict exists $newconf -receivesymbol]} { set new_recv [dict get $newconf -receivesymbol] if {[dict get $@config -receivesymbol] ne {}} { pd_unbind $self $@recv } if {$new_recv ne {}} { set @recv [canvas_realizedollar $@canvas $new_recv] pd_bind $self $@recv } else {set @recv {}} } if {[dict exists $newconf -sendsymbol]} { set new_send [dict get $newconf -sendsymbol] if {$new_send ne {}} { set @send [canvas_realizedollar $@canvas $new_send] } else {set @send {}} } # changing orient -> swap sizes if {[dict exists $newconf -orient] && ![dict exists $newconf -width] && ![dict exists $newconf -height]} { dict set newconf -width [dict get $@config -height] dict set newconf -height [dict get $@config -width] } # no errors up to this point. we can safely merge options set @config [dict merge $@config $newconf] # adjust reverse range set a [dict get $@config -rangebottom] set b [dict get $@config -rangetop] dict set @state _min [expr {$a>$b?$b:$a}] dict set @state _max [expr {$a>$b?$a:$b}] dict set @state _rev [expr {$a>$b}] set orient [dict get $@config -orient] switch $orient { horizontal {set dim [dict get $@config -width]; set mul 1} vertical {set dim [dict get $@config -height]; set mul -1} default {return -code error "invalid value '$orient' for -orient"} } # recompute pix2units conversion set @pix2units [expr {(2.0 * [dict get $@state _rev] - 1.0) * ( [dict get $@state _max] - [dict get $@state _min] ) * $mul / ( $dim - [dict get $@config -headsz])}] # if ui changed, update it if {$ui && [info exists @c]} { sys_gui [list $@c delete $self]\n sys_gui [list slider2_draw_new $self $@c $@x $@y $@config $@state]\n } elseif {$upd && [info exists @c]} { sys_gui [list slider2_update $self $@c $@x $@y $@config $@state]\n } if {[dict exists $newconf -width] || [dict exists $newconf -height]} { canvas_fixlinesfor $@canvas $self } } proc+ slider2::0_set {self args} { foreach v {min max} {set $v [dict get $@state _$v]} set f [pd::arg 0 float] if {$f < $min} {set f $min} if {$f > $max} {set f $max} dict set @config -initvalue $f if {[info exists @c]} { # update ui: sys_gui [list slider2_update $self $@c $@x $@y $@config $@state]\n } } proc+ slider2::0_bang {self} { foreach v {initvalue} {set $v [dict get $@config -$v]} pd::outlet $self 0 float $initvalue if {$@send ne {}} { set s_thing [$@send cget -s_thing] if {$s_thing ne {NULL}} {pd_float $s_thing $initvalue} } } proc+ slider2::0_float {self args} { 0_set $self {*}$args 0_bang $self } proc+ slider2::save {self} { set c $@config # use -sendsymbol and -receivesymbol from original binbuf, because of '$' set c2 [pd::strip_selectors [lrange [pd::get_binbuf $self] 1 end]] foreach opt {-sendsymbol -receivesymbol} { dict set c $opt [dict get $c2 $opt] } set l [list #X obj $@x $@y slider2 {*}[pd::add_empty $c] \;] return $l } proc+ slider2::properties {self} { set c $@config # use -sendsymbol and -receivesymbol from original binbuf, because of '$' set c2 [pd::strip_selectors [lrange [pd::get_binbuf $self] 1 end]] foreach opt {-sendsymbol -receivesymbol} { dict set c $opt [dict get $c2 $opt] } set c [string map {$ @} $c] gfxstub_new $self $self \ [list propertieswindow %s $c "\[slider2\] properties"]\n } proc+ slider2::widgetbehavior_getrect {self args} { lassign $args x1 y1 set x2 [expr {1+$x1+[dict get $@config -width]}] set y2 [expr {1+$y1+[dict get $@config -height]}] return [list $x1 $y1 $x2 $y2] } proc+ slider2::widgetbehavior_displace {self args} { lassign $args dx dy if {$dx != 0 || $dy != 0} { incr @x $dx; incr @y $dy sys_gui [list $@c move $self $dx $dy]\n } return [list $@x $@y] } proc+ slider2::widgetbehavior_select {self args} { lassign $args sel sys_gui [list $@c itemconfigure $self&&!label$self -outline [lindex \ [list [dict get $@config -fgcolor] {blue}] $sel]]\n } proc+ slider2::widgetbehavior_vis {self args} { lassign $args @c @x @y vis if {$vis} { sys_gui [list slider2_draw_new $self $@c $@x $@y $@config $@state]\n } else { sys_gui [list $@c delete $self]\n } } proc+ slider2::widgetbehavior_click {self args} { lassign $args x y shift alt dbl doit set h [dict get $@config -height] set ypix [expr {[lindex $args 1]-$@y-1}] if {$ypix < 0 || $ypix >= $h} {return} if {$doit} { switch [dict get $@config -orient] { horizontal { set @motion_start_x $x set @motion_curr_x $x } vertical { set @motion_start_y $y set @motion_curr_y $y } } set @motion_start_v [dict get $@config -initvalue] tclpd_guiclass_grab $self $@canvas $x $y } } proc+ slider2::widgetbehavior_motion {self args} { lassign $args dx dy switch [dict get $@config -orient] { horizontal { set @motion_curr_x [expr {$dx+$@motion_curr_x}] set pixdelta [expr {-1*($@motion_curr_x-$@motion_start_x)}] } vertical { set @motion_curr_y [expr {$dy+$@motion_curr_y}] set pixdelta [expr {-1*($@motion_curr_y-$@motion_start_y)}] } } set f [expr {$@motion_start_v+$pixdelta*$@pix2units}] 0_float $self {*}[pd::add_selectors [list $f]] } pd::guiclass slider2 tclpd-0.3.1/examples/tclpd-console-help.pd000066400000000000000000000002741433742306500204720ustar00rootroot00000000000000#N canvas 115 296 450 300 10; #X obj 159 116 tclpd-console; #X text 46 62 You can get access to the Tcl console from an object: ; #X text 73 168 Youc an only create one of these objects.; tclpd-0.3.1/examples/tclpd-console.tcl000066400000000000000000000077771433742306500177420ustar00rootroot00000000000000package require Tclpd 0.3.0 package require TclpdLib 0.20 package require base64 pd::guiproc ::tclpd_console_exec {cmd} { if {$cmd eq {}} {return} global tclpd_console_hist global tclpd_console_histp if {$cmd ne [lindex $tclpd_console_hist end]} { lappend tclpd_console_hist $cmd set tclpd_console_histp [expr {[llength $tclpd_console_hist]-1}] } .pdwindow.tcl.tclpd.entry delete 0 end # encode message in base64 to prevent escaping and other FUDI annoyances set cmd [::base64::encode $cmd] set max_line_length 1024 while {$cmd ne {}} { set line [string range $cmd 0 [expr $max_line_length - 1]] set cmd [string range $cmd $max_line_length end] ::pdsend "$::tclpd_console base64data $line" } ::pdsend "$::tclpd_console base64data -" } pd::guiproc ::tclpd_console_history {dir} { global tclpd_console_hist global tclpd_console_histp incr tclpd_console_histp $dir set l [llength $tclpd_console_hist] if {$tclpd_console_histp < 0} {set tclpd_console_histp 0} if {$tclpd_console_histp >= $l} {set tclpd_console_histp [expr {$l-1}]} .pdwindow.tcl.tclpd.entry delete 0 end .pdwindow.tcl.tclpd.entry insert 0 \ [lindex $tclpd_console_hist $tclpd_console_histp] } proc tclpd-console::constructor {self} { if {[info exist ::tclpd-console::loaded]} { return -code error "only one instance of tclpd-console allowed" } set ::tclpd-console::loaded 1 set ::${self}_loaded 1 # beware: typemap magic (1st arg get cast to a t_pd, second to a t_symbol) pd_bind $self $self sys_gui "set ::tclpd_console $self" sys_gui { set ::tclpd_console_hist {} set ::tclpd_console_histp {} package require base64 set w .pdwindow.tcl.tclpd frame $w -borderwidth 0 pack $w -side bottom -fill x label $w.label -text [_ "tclpd: "] -anchor e pack $w.label -side left entry $w.entry -width 200 \ -exportselection 1 -insertwidth 2 -insertbackground blue \ -textvariable ::tclpd_cmd -font {$::font_family 12} pack $w.entry -side left -fill x bind $w.entry <$::modifier-Key-a> "%W selection range 0 end; break" bind $w.entry {::tclpd_console_exec $::tclpd_cmd} set bgrule {[lindex {#FFF0F0 #FFFFFF} [info complete $::tclpd_cmd]]} bind $w.entry "$w.entry configure -background $bgrule" bind $w.entry "::tclpd_console_history -1" bind $w.entry "::tclpd_console_history 1" bind .pdwindow.text "focus $w.entry; break" after idle .pdwindow.text.internal yview end } # make puts print into pdwindow if {[info procs puts_tclpd_console] eq {}} { rename puts puts_tclpd_console proc ::puts {args} { if {[llength $args] == 1} { uplevel "pd::post $args" } else { uplevel "puts_tclpd_console $args" } } } } proc tclpd-console::destructor {self} { if {[set ::${self}_loaded]} { sys_gui { destroy .pdwindow.tcl.tclpd ; unset ::tclpd_console } pd_unbind $self $self # restore original puts if {[info procs puts_tclpd_console] ne {}} { rename puts_tclpd_console puts } } unset ::tclpd-console::loaded unset ::${self}_loaded } proc tclpd-console::0_base64data {self data} { if {[llength $data] != 2 || [lindex $data 0] ne {symbol}} { return -code error "malformed arguments: $data" } global tclpd_console_buf set data [lindex $data 1] set op [string index $data 0] if {$op eq "-"} { set cmd [::base64::decode $tclpd_console_buf] set tclpd_console_buf {} pd::post [concat % $cmd] set result [uplevel #0 $cmd] if {$result ne {}} {pd::post $result} #sys_gui "tk_messageBox -message {Result:\n$result}" } else { append tclpd_console_buf $data } } pd::class tclpd-console -noinlet 1 tclpd-0.3.1/examples/tclpd-interp-info.tcl000066400000000000000000000010131433742306500205030ustar00rootroot00000000000000package require Tclpd 0.2.3 package require TclpdLib 0.19 # utilities for getting informations about tclpd's interpreter proc tclpd-interp-info::constructor {self} { } proc tclpd-interp-info::0_bang {self} { pd::post "-------- namespaces and procs: -------------" set nss [linsert [namespace children ::] 0 ::] foreach ns $nss { pd::post " $ns" set procs [info procs ${ns}::*] foreach p $procs { pd::post " $p" } } } pd::class tclpd-interp-info tclpd-0.3.1/hashtable.c000066400000000000000000000037461433742306500147410ustar00rootroot00000000000000#include "hashtable.h" uint32_t hash_str(const char *s) { const unsigned char *p = (const unsigned char *)s; uint32_t h = 5381; while (*p) { h *= 33; h ^= *p++; } return h ^ (h >> 16); } list_node_t * list_add(list_node_t *head, const char *k, void *v) { list_node_t *n = (list_node_t *)malloc(sizeof(list_node_t)); n->next = head; #ifdef HASHTABLE_COPY_KEYS n->k = strdup(k); #else n->k = k; #endif n->v = v; return n; } list_node_t * list_remove(list_node_t *head, const char *k) { if(!head) return NULL; list_node_t *tmp; // head remove while(head && strcmp(head->k, k) == 0) { tmp = head; head = head->next; #ifdef HASHTABLE_COPY_KEYS free(tmp->k); #endif free(tmp); } list_node_t *p = head; // normal (non-head) remove while(p->next) { if(strcmp(p->next->k, k) == 0) { tmp = p->next; p->next = p->next->next; #ifdef HASHTABLE_COPY_KEYS free(tmp->k); #endif free(tmp); continue; } p = p->next; } return head; } list_node_t * list_get(list_node_t *head, const char *k) { while(head) { if(strcmp(head->k, k) == 0) { return head; } head = head->next; } return NULL; } size_t list_length(list_node_t *head) { size_t length = 0; while(head) { length++; head = head->next; } return length; } hash_table_t * hashtable_new(size_t size) { hash_table_t *ht = NULL; if(size > 0) { ht = (hash_table_t *)malloc(sizeof(hash_table_t)); ht->sz = size; ht->t = (list_node_t **)malloc(sizeof(list_node_t *) * size); for(int i = 0; i < size; i++) ht->t[i] = NULL; } return ht; } void hashtable_free(hash_table_t *ht) { if(ht) { free(ht->t); free(ht); } } tclpd-0.3.1/hashtable.h000066400000000000000000000024741433742306500147430ustar00rootroot00000000000000#ifndef HASHTABLE_H_INCLUDED #define HASHTABLE_H_INCLUDED /* in order to get strdup(), this needs to be defined */ #define _BSD_SOURCE #include #include #include typedef struct list_node { const char *k; void *v; struct list_node *next; } list_node_t; typedef struct hash_table { list_node_t **t; size_t sz; } hash_table_t; uint32_t hash_str(const char *s); list_node_t * list_add(list_node_t *head, const char *k, void *v); list_node_t * list_remove(list_node_t *head, const char *k); list_node_t * list_get(list_node_t *head, const char *k); size_t list_length(list_node_t *head); hash_table_t * hashtable_new(size_t size); void hash_table_free(hash_table_t *ht); static inline void hashtable_add(hash_table_t *ht, const char *name, void *c) { uint32_t h = hash_str(name) % ht->sz; ht->t[h] = list_add(ht->t[h], name, (void *)c); } static inline void hashtable_remove(hash_table_t *ht, const char *name) { uint32_t h = hash_str(name) % ht->sz; ht->t[h] = list_remove(ht->t[h], name); } static inline void * hashtable_get(hash_table_t *ht, const char *name) { uint32_t h = hash_str(name) % ht->sz; list_node_t *n = list_get(ht->t[h], name); return n ? n->v : NULL; } #endif // HASHTABLE_H_INCLUDED tclpd-0.3.1/pd-lib-builder/000077500000000000000000000000001433742306500154235ustar00rootroot00000000000000tclpd-0.3.1/pd-lib-builder/CHANGELOG.txt000066400000000000000000000066431433742306500174640ustar00rootroot00000000000000Changelog for Makefile.pdlibbuilder. v0.6.0, dated 2019-12-21 - detect target platform (OS and architecture) rather than build platform (#55) - introduce optional user variable 'PLATFORM' for cross compilation - no longer build OSX/MacOS fat binaries by default (#21, #50) - do build fat binaries when 'extension=d_fat' is specified for OSX/MacOS - fix bug where minimum OSX/MacOS version wasn't defined, and set it to 10.6 v0.5.1, dated 2018-03-15 Fixes and improvements for Windows builds: - properly evaluate variables 'PDDIR' and 'PDBINDIR' to find pd.dll - define default path of 32 bit Pd on 64 bit Windows - link C++ externals with standard C libs on Windows, they don't load otherwise - strip installed Windows binaries by default (issues #34, #39, #41, #42 respectively) Warning for all platforms: variable 'PD_PATH' is no longer supported, use the equivalent 'PDDIR'. v0.5.0, dated 2018-01-23 Implement target architecture detection for Windows builds, and set appropriate options for 32 and 64 bit (used to be for 32 bit only). (feature, issue #37 #38, merge commit 215bf3e) v0.4.4, dated 2016-11-22 Use variable 'system' when evaluating 'for{Linux,Darwin,Windows}' (bugfix, issue #31, commit 2c14110) v0.4.3, dated 2016-11-02 Replace flags '-fpic' by 'fPIC'. (bugfix, issue #29, commit 426b38b) v0.4.2, dated 2016-10-30 Fix issue where incorrect message about m_pd.h is given. (bugfix, commit 2e13d8f) v0.4.1, dated 2016-10-27 Respect cflag for minimum OSX version when defined by lib makefile. (bugfix, pull request #22, commit 48c4127) v0.4.0, dated 2016-10-14 Introduced path variables PDDIR, PDINCLUDEDIR, PDBINDIR, PDLIBDIR which can also be defined in environment. (feature, issue #27, commit b0dab72) v0.3.1, dated 2016-10-13 Fix bug where pd.dll wouldn't be found. (bugfix, commit a0c87be) v0.3.0, dated 2016-10-09 Variable 'PD_PATH' introduced for pd-extended / pd-l2ork compatibility. (feature, issue #26, commit 41e9743) v0.2.8, dated 2016-10-09 Allow installed files to contain weird characters (notably '$'). (bugfix, pull request #20, commit 5b920b1) v0.2.7, dated 2016-10-04 Remove all default pd search paths except vanilla's. (discussion, issue #25, commit a6a89dc) v0.2.6, dated 2016-09-20 Redefined dependency checking so it won't stall rebuilds on OSX. (bugfix, issue #16, commit 9fd1795) v0.2.5, dated 2016-06-26 Fixed dependency checking for object files in other directories. (bugfix, commit f06e550) v0.2.4, dated 2016-06-25 Fixed regression bug that disabled all dependency checking. (bugfix, commit 1d7bb5e) v0.2.3, dated 2016-03-29 Disabled dependency checking for OSX <= 10.5 because it stalled rebuilds. (bugfix, issue #16, commit eb614fd) v0.2.2, dated 2016-03-28 Removed target 'pre' because it forced rebuild of everything in 'all'. (bugfix, issue #17, commit c989c8e) v0.2.1, dated 2015-12-27 Implement / respect 'CPPFLAGS','CFLAGS'and 'LDFLAGS'. (bugfix, issue #5, commit 98f3582) v0.2.0, dated 2015-12-19 Added per-platform multiline defines 'forLinux', 'forDarwin', 'forWindows'. (feature, pull request #9, commit 3946ea5) v0.1.0, dated 2015-12-08 Added targets 'pre' and 'post' to automatically run before and after 'all'. (feature, pull request #4, commit a5678ac) v0.0.2, dated 2015-12-06 Improved methods for searching pd paths. (bugfix, commit ed37e6b) v0.0.1, dated 2015-10-31 Fixed expansion of variable 'lib.version'. (bugfix, issue #1, commit 974b617) v0.0.0, dated 2015-06-24 Initial version. (commit 16517a2) tclpd-0.3.1/pd-lib-builder/Makefile.pdlibbuilder000066400000000000000000001266041433742306500215340ustar00rootroot00000000000000# Makefile.pdlibbuilder dated 2019-12-21 version = 0.6.0 # Helper makefile for Pure Data external libraries. # Written by Katja Vetter March-June 2015 for the public domain. No warranties. # Inspired by Hans Christoph Steiner's Makefile Template and Stephan Beal's # ShakeNMake. # # Grab the newest version of Makefile.pdlibbuilder from # https://github.com/pure-data/pd-lib-builder/ # # GNU make version >= 3.81 required. # # #=== characteristics =========================================================== # # # - defines build settings based on autodetected OS and architecture # - defines rules to build Pd class- or lib executables from C or C++ sources # - defines rules for libdir installation # - defines convenience targets for developer and user # - evaluates implicit dependencies for non-clean builds # # #=== basic usage =============================================================== # # # In your Makefile, define your Pd lib name and class files, and include # Makefile.pdlibbuilder at the end of the Makefile. Like so: # # ________________________________________________________________________ # # # Makefile for mylib # # lib.name = mylib # # class.sources = myclass1.c myclass2.c # # datafiles = myclass1-help.pd myclass2-help.pd README.txt LICENSE.txt # # include Makefile.pdlibbuilder # ________________________________________________________________________ # # # For files in class.sources it is assumed that class basename == source file # basename. The default target builds all classes as individual executables # with Pd's default extension for the platform. For anything more than the # most basic usage, continue reading. # # #=== list of Makefile.pdlibbuilder API variables =============================== # # # Variables available for definition in your library Makefile: # # - lib.name # - lib.setup.sources # - class.sources # - common.sources # - shared.sources # - .class.sources # - .class.ldflags # - .class.ldlibs # - cflags # - ldflags # - ldlibs # - datafiles # - datadirs # - makefiles # - makefiledirs # - externalsdir # # Optional multiline defines evaluated per operating system: # # - forLinux # - forDarwin # - forWindows # # Variables available for your makefile or make command line: # # - make-lib-executable # - suppress-wunused # # Path variables for make command line or environment: # # - PDDIR # - PDINCLUDEDIR # - PDBINDIR # - PDLIBDIR # # Standard make variables for make command line or environment: # # - CPPFLAGS # - CFLAGS # - LDFLAGS # - CC # - CXX # - INSTALL # - STRIP # - DESTDIR # # Optional user variables for make command line or environment: # # - PLATFORM # # Deprecated path variables: # # - pdincludepath # - pdbinpath # - objectsdir # # #=== descriptions of Makefile.pdlibbuilder API variables ======================= # # # lib.name: # Name of the library directory as it will be installed / distributed. Also the # name of the lib executable in the case where all classes are linked into # a single binary. # # lib.setup.sources: # Source file(s) (C or C++) which must be compiled only when linking all classes # into a single lib binary. # # class.sources: # All sources files (C or C++) for which the condition holds that # class name == source file basename. # # .class.sources: # Source file(s) (C or C++) specific to class . Use this for # multiple-source classes or when class name != source file basename. # # common.sources: # Source file(s) which must be statically linked to each class in the library. # # shared.sources: # Source file(s) (C or C++) to build a shared dynamic link lib, to be linked # with all class executables. # # cflags, ldflags, ldlibs: # Define cflags (preprocessor&compiler), ldflags (linker) and ldlibs (dynamic # link libs) for the whole library. These flags are added to platform-specific # flags defined by Makefile.pdlibbuilder. # # .class.ldflags and .class.ldlibs: # Define ldflags resp. ldlibs specific to class . These flags are # added to platform-specific flags defined by Makefile.pdlibbuilder, and flags # defined in your Makefile for the whole library. Note: cflags can not be # defined per class in the current implementation. # # datafiles and datadirs: # All extra files you want to include in binary distributions of the # library: abstractions and help patches, example patches, meta patch, readme # and license texts, manuals, sound files, etcetera. Use 'datafiles' for all # files that should go into your lib rootdir and 'datadirs' for complete # directories you want to copy from source to distribution. # # forLinux, forDarwin, forWindows: # Shorthand for 'variable definitions for Linux only' etc. Use like: # define forLinux # cflags += -DLINUX # class.sources += linuxthing.c # endef # # makefiles and makefiledirs: # Extra makefiles or directories with makefiles that should be made in sub-make # processes. # # make-lib-executable: # When this variable is defined 'yes' in your makefile or as command argument, # Makefile.pdlibbuilder will try to build all classes into a single library # executable (but it will force exit if lib.setup.sources is undefined). # If your makefile defines 'make-lib-executable=yes' as the library default, # this can still be overridden with 'make-lib-executable=no' as command argument # to build individual class executables (the Makefile.pdlibbuilder default.) # # suppress-wunused: # When this variable is defined ('yes' or any other value), -Wunused-variable, # -Wunused-parameter, -Wunused-value and -Wunused-function are suppressed, # but the other warnings from -Wall are retained. # # PDDIR: # Root directory of 'portable' pd package. When defined, PDINCLUDEDIR and # PDBINDIR will be evaluated as $(PDDIR)/src and $(PDDIR)/bin. # # PDINCLUDEDIR: # Directory where Pd API m_pd.h should be found, and other Pd header files. # Overrides the default search path. # # PDBINDIR: # Directory where pd.dll should be found for linking (Windows only). Overrides # the default search path. # # PDLIBDIR: # Root directory for installation of Pd library directories. Overrides the # default install location. # # DESTDIR: # Prepended path component for staged install. # # PLATFORM: # Target platform for cross compilation in the form of GNU triplet: # cpu-vendor-os. Example: x86_64-w64-mingw32. This specifies the tool chain that # pdlibbuilder will use, if installed and locatable. System and architecture # will then be autodefined accordingly. In most cases no other variables need to # be overridden. # # CPPFLAGS: # Preprocessor flags which are not strictly required for building. # # CFLAGS: # Compiler flags which are not strictly required for building. Compiler flags # defined by Makefile.pdlibbuilder for warning, optimization and architecture # specification are overriden by CFLAGS. # # LDFLAGS: # Linker flags which are not strictly required for building. Linker flags # defined by Makefile.pdlibbuilder for architecture specification are overriden # by LDFLAGS. # # CC and CXX: # C and C++ compiler programs as defined in your build environment. # # INSTALL # Definition of install program. # # STRIP # Name of strip program. Default 'strip' can be overridden in cross compilation # environments. # # objectsdir: # Root directory for installation of Pd library directories, like PDLIBDIR but # not overridable by environment. Supported for compatibility with pd-extended # central makefile, but deprecated otherwise. # # pdincludepath, pdbinpath: # As PDINCLUDEDIR and PDBINDIR but not overridable by environment. Deprecated # as user variables. # # #=== paths ===================================================================== # # # Source files in directories other than current working directory must be # prefixed with their relative path. Do not rely on VPATH or vpath. # Object (.o) files are built in the directory of their source files. # Executables are built in current working directory. # # Default search path for m_pd.h and other API header files is platform # dependent, and overridable by PDINCLUDEDIR: # # Linux: /usr/include/pd # # OSX: /Applications/Pd*.app/Contents/Resources/src # # Windows: %PROGRAMFILES%/Pd/src # %PROGRAMFILES(X86)%/Pd/src (32 bit builds on 64 bit Windows) # # Default search path for binary pd.dll (Windows), overridable by PDBINDIR # # %PROGRAMFILES%/Pd/bin # %PROGRAMFILES(X86)%/Pd/bin (32 bit builds on 64 bit Windows) # # Default location to install pd libraries is platform dependent, and # overridable by PDLIBDIR: # # Linux: /usr/local/lib/pd-externals # OSX: ~/Library/Pd # Windows: %APPDATA%/Pd # # https://puredata.info/docs/faq/how-do-i-install-externals-and-help-files # The rationale for not installing to ~/pd-externals by default on Linux # is that some people share the home dir between 32 and 64 bit installations. # # #=== targets =================================================================== # # # all: build $(executables) plus optional post target # post: target to build after $(executables) # alldebug: build all with -g option turned on for debug symbols # : force clean build of an individual class # .pre: make preprocessor output file in current working directory # .lst: make asm/source output file in current working directory # # install: install executables and data files # clean: remove build products from source tree # # help: print help text # vars: print makefile variables # allvars: print all variables # depend: print generated prerequisites # dumpmachine: print compiler output of option '-dumpmachine' # coffee: dummy target # # Variable $(executables) expands to class executables plus optional shared lib, # or alternatively to single lib executable when make-lib-executable=true. # Targets pre and post can be defined by library makefile. Make sure to include # Makefile.pdlibbuilder first so default target all will not be redefined. # # #=== Pd-extended libdir concept ================================================ # # # For libdir layout as conceived by Hans-Christoph Steiner, see: # # https://puredata.info/docs/developer/Libdir # # Files README.txt, LICENSE.txt and -meta.pd are part of the libdir # convention. Help patches for each class and abstraction are supposed to be # available. Makefile.pdlibbuilder does not force the presence of these files # however. It does not automatically include such files in libdir installations. # Data files you want to include in distributions must be defined explicitly in # your Makefile. # # #=== Makefile.pdlibbuilder syntax conventions ================================== # # # Makefile.pdlibbuilder variable names are lower case. Default make variables, # environment variables, and standard user variables (CC, CXX, CFLAGS, DESTDIR) # are upper case. Use target 'allvars' to print all variables and their values. # # 'Fields' in data variables are separated by dots, like in 'foo.class.sources'. # Words in variables expressing a function or command are separated by dashes, # like in 'make-lib-executable'. # # #=== useful make options ======================================================= # # # Use 'make -d ' to print debug details of the make process. # Use 'make -p ' to print make's database. # # #=== TODO ====================================================================== # # # - decide whether to use -static-libgcc or shared dll in MinGW # - cygwin support # - android support # - figure out how to handle '$' in filenames # - add makefile template targets dpkg-source dist libdir distclean tags? # # #=== end of documentation sections ============================================= # # ################################################################################ ################################################################################ ################################################################################ # GNU make version 3.81 (2006) or higher is required because of the following: # - function 'info' # - variable '.DEFAULT_GOAL' # force exit when make version is < 3.81 ifneq ($(firstword $(sort 3.81 $(MAKE_VERSION))), 3.81) $(error GNU make version 3.81 or higher is required) endif # Relative path to externals root dir in multi-lib source tree like # pd-extended SVN. Default is parent of current working directory. May be # defined differently in including makefile. externalsdir ?= .. # variable you can use to check if Makefile.pdlibbuilder is already included Makefile.pdlibbuilder = true ################################################################################ ### variables: library name and version ######################################## ################################################################################ # strip possibles spaces from lib.name, they mess up calculated file names lib.name := $(strip $(lib.name)) # if meta file exists, check library version metafile := $(wildcard $(lib.name)-meta.pd) ifdef metafile lib.version := $(shell sed -n \ 's|^\#X text [0-9][0-9]* [0-9][0-9]* VERSION \(.*\);|\1|p' \ $(metafile)) endif ################################################################################ ### variables: files ########################################################### ################################################################################ #=== sources =================================================================== # (re)define .class.sources using file names in class.sources define add-class-source $(notdir $(basename $v)).class.sources += $v endef $(foreach v, $(class.sources), $(eval $(add-class-source))) # derive class names from .class.sources variables sourcevariables := $(filter %.class.sources, $(.VARIABLES)) classes := $(basename $(basename $(sourcevariables))) # accumulate all source files specified in makefile classes.sources := $(sort $(foreach v, $(sourcevariables), $($v))) all.sources := $(classes.sources) $(lib.setup.sources) \ $(shared.sources) $(common.sources) #=== object files ============================================================== # construct object filenames from all C and C++ source file names classes.objects := $(addsuffix .o, $(basename $(classes.sources))) common.objects := $(addsuffix .o, $(basename $(common.sources))) shared.objects := $(addsuffix .o, $(basename $(shared.sources))) lib.setup.objects := $(addsuffix .o, $(basename $(lib.setup.sources))) all.objects = $(classes.objects) $(common.objects) $(shared.objects) \ $(lib.setup.objects) #=== executables =============================================================== # use recursive variables here because executable extension is not yet known # construct class executable names from class names classes.executables = $(addsuffix .$(extension), $(classes)) # construct shared lib executable name if shared sources are defined ifdef shared.sources shared.lib = lib$(lib.name).$(shared.extension) else shared.lib = endif ################################################################################ ### target platform detection ################################################## ################################################################################ #=== target platform =========================================================== # PLATFORM: optional user variable to define target platform for cross # compilation. Redefine build tools accordingly. PLATFORM should match # the exact target prefix of tools present in $PATH, like x86_64-w64-mingw32, # x86_64-apple-darwin12 etc. Tool definitions are exported to ensure submakes # will get the same. ifneq ($(PLATFORM),) ifneq ($(findstring darwin, $(PLATFORM)),) export CC = $(PLATFORM)-cc export CXX = $(PLATFORM)-c++ export CPP = $(PLATFORM)-cc else export CC = $(PLATFORM)-gcc export CXX = $(PLATFORM)-g++ export CPP = $(PLATFORM)-cpp endif STRIP = $(PLATFORM)-strip endif # Let (native or cross-) compiler report target triplet and isolate individual # words therein to facilitate later processing. target.triplet := $(subst -, ,$(shell $(CC) -dumpmachine)) #=== operating system ========================================================== # The following systems are defined: Linux, Darwin, Windows. GNU and # GNU/kFreeBSD are treated as Linux to get the same options. ifneq ($(filter linux gnu% kfreebsd, $(target.triplet)),) system = Linux endif ifneq ($(filter darwin%, $(target.triplet)),) system = Darwin endif ifneq ($(filter mingw% cygwin%, $(target.triplet)),) system = Windows endif # evaluate possible system-specific multiline defines from library makefile $(eval $(for$(system))) # TODO: Cygwin, Android #=== architecture ============================================================== # The following CPU names can be processed by pdlibbuilder: # i*86 Intel 32 bit # x86_64 Intel 64 bit # arm ARM 32 bit # aarch64 ARM 64 bit target.arch := $(firstword $(target.triplet)) ################################################################################ ### variables per platform ##################################################### ################################################################################ #=== flags per architecture ==================================================== # Set architecture-dependent cflags, mainly for Linux. For Mac and Windows, # arch.c.flags are overriden below. To see gcc's default architecture flags: # $ gcc -Q --help=target # ARMv6: Raspberry Pi 1st gen, not detectable from target.arch ifeq ($(shell uname), armv6l) arch.c.flags = -march=armv6 -mfpu=vfp -mfloat-abi=hard # ARMv7: Beagle, Udoo, RPi2 etc. else ifeq ($(target.arch), arm) arch.c.flags = -march=armv7-a -mfpu=vfpv3 -mfloat-abi=hard # ARMv8 64 bit, not tested yet else ifeq ($(target.arch), aarch64) arch.c.flags = -mcpu=cortex-a53 # Intel 32 bit, build with SSE and SSE2 instructions else ifneq ($(filter i%86, $(target.arch)),) arch.c.flags = -march=pentium4 -mfpmath=sse -msse -msse2 # Intel/AMD 64 bit, build with SSE, SSE2 and SSE3 instructions else ifeq ($(target.arch), x86_64) arch.c.flags = -march=core2 -mfpmath=sse -msse -msse2 -msse3 # if none of the above architectures detected else arch.c.flags = endif #=== flags and paths for Linux ================================================= ifeq ($(system), Linux) prefix = /usr/local libdir := $(prefix)/lib pkglibdir = $(libdir)/pd-externals pdincludepath := $(wildcard /usr/include/pd) extension = pd_linux cpp.flags := -DUNIX c.flags := -fPIC c.ldflags := -rdynamic -shared -fPIC -Wl,-rpath,"\$$ORIGIN",--enable-new-dtags c.ldlibs := -lc -lm cxx.flags := -fPIC -fcheck-new cxx.ldflags := -rdynamic -shared -fPIC -Wl,-rpath,"\$$ORIGIN",--enable-new-dtags cxx.ldlibs := -lc -lm -lstdc++ shared.extension = so shared.ldflags := -rdynamic -fPIC -shared -Wl,-soname,$(shared.lib) endif #=== flags and paths for Darwin ================================================ # LLVM-clang doesn't support -fcheck-new, therefore this flag is only used when # compiling with g++. ifeq ($(system), Darwin) pkglibdir = $(HOME)/Library/Pd pdincludepath := $(firstword $(wildcard \ /Applications/Pd*.app/Contents/Resources/src)) extension = pd_darwin cpp.flags := -DUNIX -DMACOSX -I /sw/include c.flags := c.ldflags := -undefined suppress -flat_namespace -bundle c.ldlibs := -lc cxx.ldflags := -undefined suppress -flat_namespace -bundle cxx.ldlibs := -lc shared.extension = dylib shared.ldflags = -dynamiclib -undefined dynamic_lookup \ -install_name @loader_path/$(shared.lib) \ -compatibility_version 1 -current_version 1.0 ifneq ($(filter %g++, $(CXX)),) cxx.flags := -fcheck-new endif ifeq ($(extension), d_fat) arch := i386 x86_64 else arch := $(target.arch) endif ifneq ($(filter -mmacosx-version-min=%, $(cflags)),) version.flag := $(filter -mmacosx-version-min=%, $(cflags)) else version.flag = -mmacosx-version-min=10.6 endif arch.c.flags := $(addprefix -arch , $(arch)) $(version.flag) arch.ld.flags := $(arch.c.flags) endif #=== flags and paths for Windows =============================================== # Standard paths on Windows contain spaces, and GNU make functions treat such # paths as lists, with unintended effects. Therefore we must use shell function # ls instead of make's wildcard when probing for a path, and use double quotes # when specifying a path in a command argument. # Default paths in Mingw / Mingw-w64 environments. 'PROGRAMFILES' is standard # location for builds with native architecture, 'ProgramFiles(x86)' for i686 # builds on x86_64 Windows (detection method by Lucas Cordiviola). Curly braces # required because of parentheses in variable name. ifeq ($(system), Windows) pkglibdir := $(APPDATA)/Pd ifeq ($(target.arch), i686) programfiles := ${ProgramFiles(x86)} else programfiles := $(PROGRAMFILES) endif pdbinpath := $(programfiles)/Pd/bin pdincludepath := $(programfiles)/Pd/src endif # Store default path to pd.dll in PDBINDIR if the latter is not user-defined. # For include path this is done in the platform-independent paths section below, # but for PDBINDIR it is done here so ld flags can be evaluated as immediate # variables. ifeq ($(system), Windows) ifdef PDDIR PDBINDIR := $(PDDIR)/bin endif PDBINDIR ?= $(pdbinpath) endif # TODO: decide whether -mms-bitfields should be specified. ifeq ($(system), Windows) cpp.flags := -DMSW -DNT ifeq ($(target.arch), i686) arch.c.flags := -march=pentium4 -msse -msse2 -mfpmath=sse else ifeq ($(target.arch), x86_64) cpp.flags := -DMSW -DNT -DPD_LONGINTTYPE=__int64 arch.c.flags := -march=core2 -msse -msse2 -msse3 -mfpmath=sse else arch.c.flags = endif extension = dll c.flags := c.ldflags := -static-libgcc -shared \ -Wl,--enable-auto-import "$(PDBINDIR)/pd.dll" c.ldlibs := cxx.flags := -fcheck-new cxx.ldflags := -static-libgcc -static-libstdc++ -shared \ -Wl,--enable-auto-import "$(PDBINDIR)/pd.dll" cxx.ldlibs := shared.extension = dll shared.ldflags := -static-libgcc -shared "$(PDBINDIR)/pd.dll" stripflags = --strip-all endif #=== paths ===================================================================== # Platform-dependent default paths are specified above, but overridable. # Path variables in upper case can be defined as make command argument or in the # environment. Variable 'objectsdir' is supported for compatibility with # the build system that pd-l2ork has inherited from pd-extended. PDINCLUDEDIR ?= $(pdincludepath) PDLIBDIR ?= $(firstword $(objectsdir) $(pkglibdir)) ifdef PDDIR PDINCLUDEDIR := $(wildcard $(PDDIR)/src) endif # base path where all components of the lib will be installed by default installpath := $(DESTDIR)$(PDLIBDIR)/$(lib.name) # check if include path contains spaces (as is often the case on Windows) # if so, store the path so we can later do checks with it pdincludepathwithspaces := $(if $(word 2, $(PDINCLUDEDIR)), $(PDINCLUDEDIR)) #=== accumulated build flags =================================================== # From GNU make docs: 'Users expect to be able to specify CFLAGS freely # themselves.' So we use CFLAGS to define options which are not strictly # required for compilation: optimizations, architecture specifications, and # warnings. CFLAGS can be safely overriden using a make command argument. # Variables cflags, ldflags and ldlibs may be defined in including makefile. optimization.flags = -O3 -ffast-math -funroll-loops -fomit-frame-pointer warn.flags = -Wall -Wextra -Wshadow -Winline -Wstrict-aliasing # suppress -Wunused-variable & Co if you don't want to clutter a build log ifdef suppress-wunused warn.flags += $(addprefix -Wno-unused-, function parameter value variable) endif CFLAGS = $(warn.flags) $(optimization.flags) $(arch.c.flags) # preprocessor flags cpp.flags := -DPD -I "$(PDINCLUDEDIR)" $(cpp.flags) $(CPPFLAGS) # flags for dependency checking (cflags from makefile may define -I options) depcheck.flags := $(cpp.flags) $(cflags) # architecture specifications for linker are overridable by LDFLAGS LDFLAGS := $(arch.ld.flags) # now add the same ld flags to shared dynamic lib shared.ldflags := $(shared.ldflags) $(LDFLAGS) # accumulated flags for C compiler / linker c.flags := $(cpp.flags) $(c.flags) $(cflags) $(CFLAGS) c.ldflags := $(c.ldflags) $(ldflags) $(LDFLAGS) c.ldlibs := $(c.ldlibs) $(ldlibs) # accumulated flags for C++ compiler / linker cxx.flags := $(cpp.flags) $(cxx.flags) $(cflags) $(CFLAGS) cxx.ldflags := $(cxx.ldflags) $(ldflags) $(LDFLAGS) cxx.ldlibs := $(cxx.ldlibs) $(ldlibs) ################################################################################ ### variables: tools ########################################################### ################################################################################ # aliases so we can later define 'compile-$1' and set 'c' or 'cxx' as argument compile-c := $(CC) compile-cxx := $(CXX) ################################################################################ ### checks ##################################################################### ################################################################################ # At this point most variables are defined. Now do some checks and info's # before rules begin. # print Makefile.pdlibbuilder version before possible termination $(info ++++ info: using Makefile.pdlibbuilder version $(version)) # Terminate if target triplet remained empty, to avoid all sorts of confusing # scenarios and spurious bugs. ifeq ($(target.triplet),) $(error Command "$(CC) -dumpmachine" did not return a target triplet, \ needed for a build. \ Is compiler "$(CC)" installed in your PATH? ($(PATH)). \ Does compiler "$(CC)" support option "-dumpmachine"?) endif # 'forward declaration' of default target, needed to do checks all: # To avoid unpredictable results, make sure the default target is not redefined # by including makefile. ifneq ($(.DEFAULT_GOAL), all) $(error Default target must be 'all'.) endif # find out which target(s) will be made ifdef MAKECMDGOALS goals := $(MAKECMDGOALS) else goals := all endif # store path to Pd API m_pd.h if it is found ifdef PDINCLUDEDIR mpdh := $(shell ls "$(PDINCLUDEDIR)/m_pd.h") endif # store path to pd.dll; if not found, ls will give a useful error ifeq ($(system), Windows) pddll := $(shell ls "$(PDBINDIR)/pd.dll") endif # when making target all, check if m_pd.h is found and print info about it ifeq ($(goals), all) $(if $(mpdh), \ $(info ++++ info: using Pd API $(mpdh)), \ $(warning Where is Pd API m_pd.h? Do 'make help' for info.)) endif # print target info $(info ++++ info: making target $(goals) $(if $(lib.name),in lib $(lib.name))) # when installing, print installpath info $(if $(filter install install-lib, $(goals)), $(info ++++ info: \ installpath is '$(installpath)')) #=== define executables ======================================================== # By default we build class executables, and optionally a shared dynamic link # lib. When make-lib-executable=yes we build all classes into a single lib # executable, on the condition that variable lib.setup.sources is defined. ifeq ($(make-lib-executable),yes) $(if $(lib.setup.sources), ,\ $(error Can not build library blob because lib.setup.sources is undefined)) executables := $(lib.name).$(extension) else executables := $(classes.executables) $(shared.lib) endif ################################################################################ ### rules: special targets ##################################################### ################################################################################ # Disable built-in rules. If some target can't be built with the specified # rules, it should not be built at all. MAKEFLAGS += --no-builtin-rules .PRECIOUS: .SUFFIXES: .PHONY: all post build-lib \ $(classes) $(makefiledirs) $(makefiles) \ install install-executables install-datafiles install-datadirs \ force clean vars allvars depend help ################################################################################ ### rules: build targets ####################################################### ################################################################################ # Target all forces the build of targets [$(executables) post] in # deterministic order. Target $(executables) builds class executables plus # optional shared lib or alternatively a single lib executable when # make-lib-executable=true. Target post is optionally defined by # library makefile. all: post post: $(executables) all: $(info ++++info: target all in lib $(lib.name) completed) # build all with -g option turned on for debug symbols alldebug: c.flags += -g alldebug: cxx.flags += -g alldebug: all #=== class executable ========================================================== # recipe for linking objects in class executable # argument $1 = compiler type (c or cxx) # argument $2 = class basename define link-class $(compile-$1) \ $($1.ldflags) $($2.class.ldflags) \ -o $2.$(extension) \ $(addsuffix .o, $(basename $($2.class.sources))) \ $(addsuffix .o, $(basename $(common.sources))) \ $($1.ldlibs) $($2.class.ldlibs) $(shared.lib) endef # general rule for linking object files in class executable %.$(extension): $(shared.lib) $(info ++++ info: linking objects in $@ for lib $(lib.name)) $(if $(filter %.cc %.cpp, $($*.class.sources)), \ $(call link-class,cxx,$*), \ $(call link-class,c,$*)) #=== library blob ============================================================== # build all classes into single executable build-lib: $(lib.name).$(extension) $(info ++++ info: library blob $(lib.name).$(extension) completed) # recipe for linking objects in lib executable # argument $1 = compiler type (c or cxx) define link-lib $(compile-$1) \ $($1.ldflags) $(lib.ldflags) \ -o $(lib.name).$(extension) $(all.objects) \ $($1.ldlibs) $(lib.ldlibs) endef # rule for linking objects in lib executable # declared conditionally to avoid name clashes ifeq ($(make-lib-executable),yes) $(lib.name).$(extension): $(all.objects) $(if $(filter %.cc %.cpp, $(all.sources)), \ $(call link-lib,cxx), \ $(call link-lib,c)) endif #=== shared dynamic lib ======================================================== # recipe for linking objects in shared executable # argument $1 = compiler type (c or cxx) define link-shared $(compile-$1) \ $(shared.ldflags) \ -o lib$(lib.name).$(shared.extension) $(shared.objects) \ $($1.ldlibs) $(shared.ldlibs) endef # rule for linking objects in shared executable # build recipe is in macro 'link-shared' lib$(lib.name).$(shared.extension): $(shared.objects) $(info ++++ info: linking objects in shared lib $@) $(if $(filter %.cc %.cpp, $(shared.sources)), \ $(call link-shared,cxx), \ $(call link-shared,c)) #=== object files ============================================================== # recipe to make .o file from source # argument $1 is compiler type (c or cxx) define make-object-file $(info ++++ info: making $@ in lib $(lib.name)) $(compile-$1) \ $($1.flags) \ -o $@ -c $< endef # Three rules to create .o files. These are double colon 'terminal' rules, # meaning they are the last in a rules chain. %.o:: %.c $(call make-object-file,c) %.o:: %.cc $(call make-object-file,cxx) %.o:: %.cpp $(call make-object-file,cxx) #=== explicit prerequisites for class executables ============================== # For class executables, prerequisite rules are declared in run time. Target # 'depend' prints these rules for debugging purposes. # declare explicit prerequisites rule like 'class: class.extension' # argument $v is class basename define declare-class-target $v: $v.$(extension) endef # declare explicit prerequisites rule like 'class.extension: object1.o object2.o' # argument $v is class basename define declare-class-executable-target $v.$(extension): $(addsuffix .o, $(basename $($v.class.sources))) \ $(addsuffix .o, $(basename $(common.sources))) endef # evaluate explicit prerequisite rules for all classes $(foreach v, $(classes), $(eval $(declare-class-target))) $(foreach v, $(classes), $(eval $(declare-class-executable-target))) #=== implicit prerequisites for class executables ============================== # Evaluating implicit prerequisites (header files) with help from the # preprocessor is 'expensive' so this is done conditionally and selectively. # Note that it is also possible to trigger a build via install targets, in # which case implicit prerequisites are not checked. # When the Pd include path contains spaces it will mess up the implicit # prerequisites rules. disable-dependency-tracking := $(strip $(pdincludepathwithspaces)) ifndef disable-dependency-tracking must-build-everything := $(filter all, $(goals)) must-build-class := $(filter $(classes), $(goals)) must-build-sources := $(foreach v, $(must-build-class), $($v.class.sources)) endif # declare implicit prerequisites rule like 'object.o: header1.h header2.h ...' # argument $1 is input source file(s) # dir is explicitly added because option -MM strips it by default define declare-object-target $(dir $1)$(filter %.o: %.h, $(shell $(CPP) $(depcheck.flags) -MM $1)) $(MAKEFILE_LIST) endef # evaluate implicit prerequisite rules when rebuilding everything ifdef must-build-everything $(if $(wildcard $(all.objects)), \ $(info ++++ info: evaluating implicit prerequisites in lib $(lib.name).....) \ $(foreach v, $(all.sources), $(eval $(call declare-object-target, $v)))) endif # evaluate implicit prerequisite rules when selectively building classes ifdef must-build-class $(foreach v, $(must-build-sources), \ $(eval $(call declare-object-target, $v))) $(foreach v, $(shared.sources), \ $(eval $(call declare-object-target, $v))) endif ################################################################################ ### rules: preprocessor and assembly files ##################################### ################################################################################ # Preprocessor and assembly output files for bug tracing etc. They are not part # of the build processes for executables. By default these files are created in # the current working directory. Dependency tracking is not performed, the build # is forced instead to make sure it's up to date. force: #=== preprocessor file ========================================================= # make preprocessor output file with extension .pre # argument $1 = compiler type (c or cxx) define make-preprocessor-file $(info ++++ info: making preprocessor output file $(notdir $*.pre) \ in current working directory) $(compile-$1) -E $< $(c.flags) $($1.flags) -o $(notdir $*.pre) endef %.pre:: %.c force $(call make-preprocessor-file,c) %.pre:: %.cc force $(call make-preprocessor-file,cxx) %.pre:: %.cpp force $(call make-preprocessor-file,cxx) #=== assembly file ============================================================= # make C / assembly interleaved output file with extension .lst # argument $1 = compiler type (c or cxx) define make-assembly-file $(info ++++ info: making assembly output file $(notdir $*.lst) \ in current working directory) $(compile-$1) \ -c -Wa,-a,-ad -fverbose-asm \ $($1.flags) \ $< > $(notdir $*.lst) endef %.lst:: %.c force $(call make-assembly-file,c) %.lst:: %.cc force $(call make-assembly-file,cxx) %.lst:: %.cpp force $(call make-assembly-file,cxx) ################################################################################ ### rules: installation targets ################################################ ################################################################################ #=== strip ===================================================================== # Stripping of installed binaries will only be done when variable 'stripflags' # is defined non-empty. No default definition is provided except for Windows # where the unstripped binaries are large, especially in the case of Mingw-w64. # Note: while stripping all symbols ('-s' or '--strip-all') is possible for # Linux and Windows, in the case of OSX only non-global symbols can be stripped # (option '-x' or '--discard-all'). # Make definition of strip command overridable so it can be defined in an # environment for cross-compilation. STRIP ?= strip # Commands in 'strip-executables' will be executed conditionally in the rule for # target 'install-executables'. strip-executables = cd "$(installpath)" && \ $(foreach v, $(executables), $(STRIP) $(stripflags) '$v';) #=== install =================================================================== # Install targets depend on successful exit status of target all because nothing # must be installed in case of a build error. # -p = preserve time stamps # -m = set permission mode (as in chmod) # -d = create all components of specified directories INSTALL = install INSTALL_PROGRAM := $(INSTALL) -p -m 644 INSTALL_DATA := $(INSTALL) -p -m 644 INSTALL_DIR := $(INSTALL) -m 755 -d # strip spaces from file names executables := $(strip $(executables)) datafiles := $(strip $(datafiles)) datadirs := $(strip $(datadirs)) # Do not make any install sub-target with empty variable definition because the # install program would exit with an error. install: $(if $(executables), install-executables) install: $(if $(datafiles), install-datafiles) install: $(if $(datadirs), install-datadirs) install-executables: all $(INSTALL_DIR) -v "$(installpath)" $(foreach v, $(executables), \ $(INSTALL_PROGRAM) '$v' "$(installpath)";) $(info ++++ info: executables of lib $(lib.name) installed \ from $(CURDIR) to $(installpath)) $(if $(stripflags), $(strip-executables),) install-datafiles: all $(INSTALL_DIR) -v "$(installpath)" $(foreach v, $(datafiles), \ $(INSTALL_DATA) '$(v)' "$(installpath)";) $(info ++++ info: data files of lib $(lib.name) installed \ from $(CURDIR) to $(installpath)) install-datadirs: all $(foreach v, $(datadirs), $(INSTALL_DIR) "$(installpath)/$v";) $(foreach v, $(datadirs), \ $(INSTALL_DATA) $(wildcard $v/*) "$(installpath)/$v";) $(info ++++ info: data directories of lib $(lib.name) installed \ from $(CURDIR) to $(installpath)) ################################################################################ ### rules: distribution targets ################################################ ################################################################################ # TODO # These targets are implemented in Makefile Template, but I have to figure out # how to do it under the not-so-strict conditions of Makefile.pdlibbuilder. # make source package dist: @echo "target dist not yet implemented" # make Debian source package dpkg-source: @echo "target dpkg-source not yet implemented" $(ORIGDIR): $(DISTDIR): ################################################################################ ### rules: clean targets ####################################################### ################################################################################ # delete build products from build tree clean: rm -f $(all.objects) rm -f $(classes.executables) $(lib.name).$(extension) $(shared.lib) rm -f *.pre *.lst # remove distribution directories and tarballs from build tree distclean: clean @echo "target distclean not yet implemented" ################################################################################ ### rules: submake targets ##################################################### ################################################################################ # Iterate over sub-makefiles or makefiles in other directories. # When 'continue-make=yes' is set, sub-makes will report 'true' to the parent # process regardless of their real exit status. This prevents the parent make # from being aborted by a sub-make error. Useful when you want to quickly find # out which sub-makes from a large set will succeed. ifeq ($(continue-make),yes) continue = || true endif # These targets will trigger sub-make processes for entries in 'makefiledirs' # and 'makefiles'. all alldebug install clean distclean dist dkpg-source: \ $(makefiledirs) $(makefiles) # this expands to identical rules for each entry in 'makefiledirs' $(makefiledirs): $(MAKE) --directory=$@ $(MAKECMDGOALS) $(continue) # this expands to identical rules for each entry in 'makefiles' $(makefiles): $(MAKE) --directory=$(dir $@) --makefile=$(notdir $@) $(MAKECMDGOALS) $(continue) ################################################################################ ### rules: convenience targets ################################################# ################################################################################ #=== show variables ============================================================ # Several 'function' macro's cause errors when expanded within a rule or without # proper arguments. Variables which are set with the define directive are only # shown by name for that reason. functions = \ add-class-source \ declare-class-target \ declare-class-executable-target \ declare-object-target \ link-class \ link-lib \ link-shared \ make-object-file \ make-preprocessor-file \ make-assembly-file # show variables from makefiles vars: $(info ++++ info: showing makefile variables:) $(foreach v,\ $(sort $(filter-out $(functions) functions, $(.VARIABLES))),\ $(if $(filter file, $(origin $v)),\ $(info variable $v = $($v)))) $(foreach v, $(functions), $(info 'function' name: $v)) @echo # show all variables allvars: $(info ++++ info: showing default, automatic and makefile variables:) $(foreach v, \ $(sort $(filter-out $(functions) functions, $(.VARIABLES))), \ $(info variable ($(origin $v)) $v = $($v))) $(foreach v, $(functions), $(info 'function' name: $v)) @echo #=== show dependencies ========================================================= # show generated prerequisites rules depend: $(info ++++ info: generated prerequisite rules) $(foreach v, $(classes), $(info $(declare-class-target))) $(foreach v, $(classes), $(info $(declare-class-executable-target))) $(foreach v, $(all.sources), $(info $(call declare-object-target, $v))) @echo #=== show help text ============================================================ # brief info about targets and paths ifdef mpdh mpdhinfo := $(mpdh) else mpdhinfo := m_pd.h was not found. Is Pd installed? endif help: @echo @echo " Main targets:" @echo " all: build executables (default target)" @echo " install: install all components of the library" @echo " vars: print makefile variables for troubleshooting" @echo " allvars: print all variables for troubleshooting" @echo " help: print this help text" @echo @echo " Pd API m_pd.h:" @echo " $(mpdhinfo)" @echo " You may specify your preferred Pd include directory as argument" @echo " to the make command, like 'PDINCLUDEDIR=path/to/pd/src'." @echo @echo " Path for installation of your libdir(s):" @echo " $(PDLIBDIR)" @echo " Alternatively you may specify your path for installation as argument" @echo " to the make command, like 'PDLIBDIR=path/to/pd-externals'." @echo @echo " Default paths are listed in the doc sections in Makefile.pdlibbuilder." @echo #=== platform test ============================================================= # This target can be used to test if the compiler for specified PLATFORM is # correctly defined and available. dumpmachine: @$(CC) -dumpmachine #=== dummy target ============================================================== coffee: @echo "Makefile.pdlibbuilder: Can not make coffee. Sorry." ################################################################################ ### end of rules sections ###################################################### ################################################################################ # for syntax highlighting in vim and github # vim: set filetype=make: tclpd-0.3.1/pd-lib-builder/README.md000066400000000000000000000102421433742306500167010ustar00rootroot00000000000000 ### Makefile.pdlibbuilder ### Helper makefile for Pure Data external libraries. Written by Katja Vetter March-June 2015 for the public domain and since then developed as a Pd community project. No warranties. Inspired by Hans Christoph Steiner's Makefile Template and Stephan Beal's ShakeNMake. GNU make version >= 3.81 required. ### characteristics ### * defines build settings based on autodetected target platform * defines rules to build Pd class- or lib executables from C or C++ sources * defines rules for libdir installation * defines convenience targets for developer and user * evaluates implicit dependencies for non-clean builds ### basic usage ### In your Makefile, define your Pd lib name and class files, and include Makefile.pdlibbuilder at the end of the Makefile. Like so: # Makefile for mylib lib.name = mylib class.sources = myclass1.c myclass2.c datafiles = myclass1-help.pd myclass2-help.pd README.txt LICENSE.txt include Makefile.pdlibbuilder For files in class.sources it is assumed that class name == source file basename. The default target builds all classes as individual executables with Pd's default extension for the platform. For anything more than the most basic usage, read the documentation sections in Makefile.pdlibbuilder. ### paths ### Makefile.pdlibbuilder >= v0.4.0 supports pd path variables which can be defined not only as make command argument but also in the environment, to override platform-dependent defaults: PDDIR: Root directory of 'portable' pd package. When defined, PDINCLUDEDIR and PDBINDIR will be evaluated as $(PDDIR)/src and $(PDDIR)/bin. PDINCLUDEDIR: Directory where Pd API m_pd.h should be found, and other Pd header files. Overrides the default search path. PDBINDIR: Directory where pd.dll should be found for linking (Windows only). Overrides the default search path. PDLIBDIR: Root directory for installation of Pd library directories. Overrides the default install location. ### documentation ### This README.md provides only basic information. A large comment section inside Makefile.pdlibbuilder lists and explains the available user variables, default paths, and targets. The internal documentation reflects the exact functionality of the particular version. For suggestions about project maintenance and advanced compilation see tips-tricks.md. ### versioning ### The project is versioned in MAJOR.MINOR.BUGFIX format (see http://semver.org), and maintained at https://github.com/pure-data/pd-lib-builder. Pd lib developers are invited to regulary check for updates, and to contribute and discuss improvements here. If you really need to distribute a personalized version with your library, rename Makefile.pdlibbuilder to avoid confusion. ### examples ### The list of projects using pd-lib-builder can be helpful if you are looking for examples, from the simplest use case to more complex implementations. - helloworld: traditional illustration of simplest use case - pd-windowing: straightforward real world use case of a small library - pd-nilwind / pd-cyclone: more elaborate source tree - zexy: migrated from autotools to pd-lib-builder ### projects using pd-lib-builder ### non-exhaustive list https://github.com/pure-data/helloworld https://github.com/electrickery/pd-nilwind https://github.com/electrickery/pd-maxlib https://github.com/electrickery/pd-sigpack https://github.com/electrickery/pd-tof https://github.com/electrickery/pd-windowing https://github.com/electrickery/pd-smlib https://github.com/porres/pd-cyclone https://github.com/porres/pd-else https://github.com/porres/pd-psycho https://git.iem.at/pd/comport https://git.iem.at/pd/hexloader https://git.iem.at/pd/iemgui https://git.iem.at/pd/iemguts https://git.iem.at/pd/iemlib https://git.iem.at/pd/iemnet https://git.iem.at/pd/iem_ambi https://git.iem.at/pd/iem_tab https://git.iem.at/pd/iem_adaptfilt https://git.iem.at/pd/iem_roomsim https://git.iem.at/pd/iem_spec2 https://git.iem.at/pd/mediasettings https://git.iem.at/pd/zexy https://git.iem.at/pd-gui/punish https://github.com/residuum/PuRestJson https://github.com/libpd/abl_link https://github.com/wbrent/timbreID https://github.com/MetaluNet/moonlib tclpd-0.3.1/pd-lib-builder/tips-tricks.md000066400000000000000000000162561433742306500202330ustar00rootroot00000000000000pd-lib-builder cheatsheet ========================= # Creating special builds ## cross-compiling on linux x86_64 for other platforms Using pd-lib-builder >=0.6.0 we can define variable `PLATFORM` to specify a target triplet for cross-compilation. Example to build W32 binaries (assuming package `mingw-w64` is installed and a W32 package for Pd is unzipped into a path `${PDWIN32}`: make PLATFORM=x86_64-w64-mingw32 PDDIR="${PDWIN32}" #### older pd-lib-builder versions Using pd-lib-builder < 0.6.0, in the absence of variable `PLATFORM`, you would instead override variables `system`, `target.arch`, `CC` and / or `CXX`, `STRIP`. Example: make system=Windows target.arch=i686 CC=i686-w64-mingw32-gcc STRIP=i686-w64-mingw32-strip PDDIR="${PDWIN32}" #### toolchains Cross toolchains for relevant platforms in Debian Buster (install g++ with dependencies for a given platform to get the whole tool chain): - `arm-linux-gnueabihf` - `aarch64-linux-gnu` - `i686-linux-gnu` - `i686-w64-mingw32` and `x86_64-w64-mingw32` (install `mingw-w64`) OSX/MacOS cross tool chains are not distributed by Debian. Use project `osxcross` from Thomas Poechtraeger to create the tools. ## building double-precision externals At the time of writing (2018-02) there is no official Pd that supports double-precision numbers yet. However, if you do get hold of an experimental double-precision Pd, you can easily build your externals for 64-bit numbers: make CPPFLAGS="-DPD_FLOATSIZE=64" ## building externals for W64 (64-bit Windows) At the time of writing (2018-02) there is no official Pd that supports W64 yet. However, if you do get hold of an experimental W64 Pd, you can easily build your externals for this environment with make CPPFLAGS="-DPD_LONGINTTYPE=__int64" CC=x86_64-w64-mingw32-gcc To build a double-precision external for W64, use something like: make CPPFLAGS="-DPD_LONGINTTYPE=__int64 -DPD_FLOATSIZE=64" CC=x86_64-w64-mingw32-gcc ## TODO universal binaries on OSX # Project management In general it is advised to put the `Makefile.pdlibbuilder` into a separate subdirectory (e.g. `pd-lib-builder/`). This makes it much easier to update the `Makefile.pdlibbuilder` later You *should* also use a variable to the actual path of the Makefile.pdlibbuilder (even if you keep it in the root-directory), as this allows easy experimenting with newer (or older) (or site-specific) versions of the pd-lib-builder Makefile. ~~~make PDLIBBUILDER_DIR=pd-lib-builder/ include $(PDLIBBUILDER_DIR)/Makefile.pdlibbuilder ~~~ ## Keeping pd-lib-builder up-to-date ### `git subtree` With git-subtrees, you make the pd-lib-builder repository (or any other repository for that matter) part of your own repository - with full history and everything - put nicely into a distinct subdirectory. Support for *manipulating* subtrees has been added with Git-v1.7.11 (May 2012). The nice thing however is, that from "outside" the subtree is part of your repository like any other directory. E.g. older versions of Git can clone your repository with the full subtree (and all it's history) just fine. You can also use git-archive to make a complete snapshot of your repository (including the subtree) - nice, if you e.g. want self-contained downloads of your project from git hosting platforms (like Github, Gitlab, Bitbucket,...) In short, `git subtree` is the better `git submodule`. So here's how to do it: #### Initial setup/check-out This will create a `pd-lib-builder/` directory containing the full history of the pd-lib-builder repository up to its release `v0.5.0` ~~~sh git subtree add --prefix=pd-lib-builder/ https://github.com/pure-data/pd-lib-builder v0.5.0 ~~~ This will automatically merge the `pd-lib-builder/` history into your current branch, so everything is ready to go. #### Cloning your repository with the subtree Nothing special, really. Just clone your repository as always: ~~~sh git clone https://git.example.org/pd/superbonk~.git ~~~ #### Updating the subtree Time passes and sooner or later you will find, that there is a shiny new pd-lib-builder with plenty of bugfixes and new features. To update your local copy to pd-lib-builder's current `master`, simply run: ~~~sh git subtree pull --prefix pd-lib-builder/ https://github.com/pure-data/pd-lib-builder master ~~~ #### Pulling the updated subtree into existing clones Again, nothing special. Just pull as always: ~~~sh git pull ~~~ #### Further reading More on the power of `git subtree` can be found online - https://medium.com/@v/git-subtrees-a-tutorial-6ff568381844 - https://www.atlassian.com/blog/git/alternatives-to-git-submodule-git-subtree - ... ### ~~`git submodule`~~ [DISCOURAGED] #### Initial setup/check-out To add a new submodule to your repository, just run `git submodule add` and commit the changes: ~~~sh git submodule add https://github.com/pure-data/pd-lib-builder git commit .gitmodules pd-lib-builder/ -m "Added pd-lib-builder as git-submodule" ~~~ #### Cloning your repository with the submodule When doing a fresh clone of your repository, pass the `--recursive` option to automatically fetch all submodules: ~~~sh git clone --recursive https://git.example.org/pd/superbonk~.git ~~~ If you've cloned non-recursively, you can initialize and update the submodules manually: ~~~sh git submodule init git submodule update ~~~ #### Updating the submodule Submodules are usually fixed to a given commit in their repository. To update the `pd-lib-builder` submodule to the current `master` do something like: ~~~sh cd pd-lib-builder git checkout master git pull cd .. git status pd-lib-builder git commit pd-lib-builder -m "Updated pd-lib-builder to current master" ~~~ #### Pulling the updated submodule into existing clones After you have pushed the submodule updates in your repository, other clones of the repository can be updated as follows: ~~~sh git pull ~~~ The above will make your repository aware, that the submodule is out-of-sync. ~~~sh $ LANG=C git status pd-lib-builder On branch master Your branch is up to date with 'origin/master'. Changes not staged for commit: (use "git add ..." to update what will be committed) (use "git checkout -- ..." to discard changes in working directory) modified: pd-lib-builder (new commits) $ ~~~ In order to sync the submodule to the correct commit, run the following: ~~~sh git submodule update ~~~ #### Drawbacks `git submodule` has a number of drawbacks: - it requires special commands to synchronize the submodules, in addition to synching your repository. - you must make sure to use an URL for the submodule that is accessible to your potential users. e.g. using `git@github.com:pure-data/pd-lib-builder` is bad, because it requires everybody who wants to checkout your sources to have a github-account - even if they could checkout *your* repository anonymously. - submodules will be excluded from `git archive`. This means, that if you use a mainstream git provider (like Github, GitLab, Bitbucket,...) and make releases by creating a `git tag`, the automatically generated zipfiles with the sources will lack the submodule - and your users will not be able to compile your source code. In general, I would suggest to **avoid** `git submodule`, and instead use the better `git subtree` (above). tclpd-0.3.1/tcl_class.c000066400000000000000000000321201433742306500147410ustar00rootroot00000000000000 /* in order to get strdup(), this needs to be defined */ #define _POSIX_C_SOURCE 200809L #include "tclpd.h" #include #include #include #include "hashtable.h" static hash_table_t *class_table = NULL; static hash_table_t *object_table = NULL; static hash_table_t *source_table = NULL; void class_table_add(const char *n, t_class *c) { hashtable_add(class_table, n, (void *)c); } void class_table_remove(const char *n) { hashtable_remove(class_table, n); } t_class * class_table_get(const char *n) { return (t_class *)hashtable_get(class_table, n); } void object_table_add(const char *n, t_tcl *o) { hashtable_add(object_table, n, (void *)o); } void object_table_remove(const char *n) { hashtable_remove(object_table, n); } t_tcl * object_table_get(const char *n) { return (t_tcl *)hashtable_get(object_table, n); } static unsigned long objectSequentialId = 0; /* set up the class that handles loading of tcl classes */ t_class * tclpd_class_new(const char *name, int flags) { t_class *c = class_new(gensym(name), (t_newmethod)tclpd_new, (t_method)tclpd_free, sizeof(t_tcl), flags, A_GIMME, A_NULL); if(!class_table) class_table = hashtable_new(1 << 7); if(!class_table_get(name)) class_table_add(name, c); class_addanything(c, tclpd_anything); // is this really necessary given that there is already a 'anything' handler? class_addmethod(c, (t_method)tclpd_loadbang, gensym("loadbang"), A_NULL); class_addmethod(c, (t_method)tclpd_open, gensym("menu-open"), A_NULL); char buf[80]; Tcl_Obj *res; int res_i; // use properties function if exists in tcl space. snprintf(buf, 80, "llength [info procs ::%s::properties]", name); if(Tcl_Eval(tclpd_interp, buf) == TCL_OK) { res = Tcl_GetObjResult(tclpd_interp); if(Tcl_GetIntFromObj(tclpd_interp, res, &res_i) == TCL_OK && res_i > 0) { class_setpropertiesfn(c, tclpd_properties); } } // use save function if exists in tcl space. snprintf(buf, 80, "llength [info procs ::%s::save]", name); if(Tcl_Eval(tclpd_interp, buf) == TCL_OK) { res = Tcl_GetObjResult(tclpd_interp); if(Tcl_GetIntFromObj(tclpd_interp, res, &res_i) == TCL_OK && res_i > 0) { class_setsavefn(c, tclpd_save); } } return c; } t_class * tclpd_guiclass_new(const char *name, int flags) { t_class *c = tclpd_class_new(name, flags); t_widgetbehavior *wb = (t_widgetbehavior *)getbytes(sizeof(t_widgetbehavior)); wb->w_getrectfn = tclpd_guiclass_getrect; wb->w_displacefn = tclpd_guiclass_displace; wb->w_selectfn = tclpd_guiclass_select; wb->w_activatefn = NULL; wb->w_deletefn = tclpd_guiclass_delete; wb->w_visfn = tclpd_guiclass_vis; wb->w_clickfn = tclpd_guiclass_click; class_setwidget(c, wb); return c; } t_tcl * tclpd_new(t_symbol *classsym, int ac, t_atom *at) { // lookup in class table const char *name = classsym->s_name; t_class *qlass = class_table_get(name); while(!qlass) { // try progressively skipping namespace/ prefixes (bug 3436716) name = strchr(name, '/'); if(!name || !*++name) break; qlass = class_table_get(name); } if(!qlass) { error("tclpd: class not found: %s", name); return NULL; } t_tcl *x = (t_tcl *)pd_new(qlass); if(!x) { error("tclpd: failed to create object of class %s", name); return NULL; } /* used for numbering proxy inlets: */ x->ninlets = 1 /* qlass->c_firstin ??? */; x->source_file = (char *)hashtable_get(source_table, name); if(!x->source_file) { post("tclpd: missing source file information. open command will not work."); } x->classname = Tcl_NewStringObj(name, -1); char so[64]; snprintf(so, 64, "tclpd.%s.x%lx", name, objectSequentialId++); x->self = Tcl_NewStringObj(so, -1); char sd[64]; snprintf(sd, 64, "::%s::dispatcher", name); x->dispatcher = Tcl_NewStringObj(sd, -1); // obj instance -> classname mapping char addmapcmd[256]; snprintf(addmapcmd, 256, "array set ::pd::classname {{%s} {%s}}", so, name); Tcl_Eval(tclpd_interp, addmapcmd); // the lifetime of x->{classname,self,dispatcher} is greater than this // function, hence they get an extra Tcl_IncrRefCount here: // (see tclpd_free()) Tcl_IncrRefCount(x->classname); Tcl_IncrRefCount(x->self); Tcl_IncrRefCount(x->dispatcher); // store in object table (for later lookup) if(!object_table) object_table = hashtable_new(1 << 10); if(!object_table_get(so)) object_table_add(so, x); // build constructor command Tcl_Obj *av[ac+3]; InitArray(av, ac+3, NULL); av[0] = x->dispatcher; Tcl_IncrRefCount(av[0]); av[1] = x->self; Tcl_IncrRefCount(av[1]); av[2] = Tcl_NewStringObj("constructor", -1); Tcl_IncrRefCount(av[2]); for(int i=0; idispatcher; Tcl_IncrRefCount(av[0]); av[1] = x->self; Tcl_IncrRefCount(av[1]); av[2] = Tcl_NewStringObj("destructor", -1); Tcl_IncrRefCount(av[2]); // call destructor if(Tcl_EvalObjv(tclpd_interp, 3, av, 0) != TCL_OK) { #ifdef DEBUG post("tclpd_free: failed to call destructor"); #endif } // decrement reference counter Tcl_DecrRefCount(av[0]); Tcl_DecrRefCount(av[1]); Tcl_DecrRefCount(av[2]); // remove obj instance -> classname mapping char delmapcmd[256]; snprintf(delmapcmd, 256, "unset ::pd::classname(%s)", Tcl_GetStringFromObj(x->self, NULL)); Tcl_Eval(tclpd_interp, delmapcmd); // here ends the lifetime of x->classname and x->self Tcl_DecrRefCount(x->self); Tcl_DecrRefCount(x->classname); Tcl_DecrRefCount(x->dispatcher); #ifdef DEBUG post("tclpd_free called"); #endif } void tclpd_anything(t_tcl *x, t_symbol *s, int ac, t_atom *at) { tclpd_inlet_anything(x, 0, s, ac, at); } void tclpd_inlet_anything(t_tcl *x, int inlet, t_symbol *s, int ac, t_atom *at) { // proxy method - format: method args... Tcl_Obj *av[ac+5]; InitArray(av, ac+5, NULL); int result; av[0] = x->dispatcher; Tcl_IncrRefCount(av[0]); av[1] = x->self; Tcl_IncrRefCount(av[1]); av[2] = Tcl_NewStringObj("method", -1); Tcl_IncrRefCount(av[2]); av[3] = Tcl_NewIntObj(inlet); Tcl_IncrRefCount(av[3]); av[4] = Tcl_NewStringObj(s->s_name, -1); Tcl_IncrRefCount(av[4]); for(int i=0; isource_file) return; sys_vgui("::pd_menucommands::menu_openfile {%s}\n", x->source_file); } /* Tcl glue: */ t_proxyinlet * tclpd_add_proxyinlet(t_tcl *x) { t_proxyinlet *proxy = (t_proxyinlet *)pd_new(proxyinlet_class); proxyinlet_init(proxy); proxy->target = x; proxy->ninlet = x->ninlets++; inlet_new(&x->o, &proxy->obj.ob_pd, 0, 0); return proxy; } /* t_tcl * tclpd_get_instance(const char *objectSequentialId) { return (t_tcl *)object_table_get(objectSequentialId); } t_pd * tclpd_get_instance_pd(const char *objectSequentialId) { return (t_pd *)object_table_get(objectSequentialId); } t_text * tclpd_get_instance_text(const char *objectSequentialId) { return (t_text *)object_table_get(objectSequentialId); } t_object * tclpd_get_object(const char *objectSequentialId) { t_tcl *x = tclpd_get_instance(objectSequentialId); return &x->o; } t_pd * tclpd_get_object_pd(const char *objectSequentialId) { t_object *o = tclpd_get_object(objectSequentialId); return &o->ob_pd; } t_binbuf * tclpd_get_object_binbuf(const char *objectSequentialId) { t_object *o = tclpd_get_object(objectSequentialId); return o->ob_binbuf; } t_glist * tclpd_get_glist(const char *objectSequentialId) { t_tcl *x = tclpd_get_instance(objectSequentialId); return x->x_glist; } t_atom * tclpd_binbuf_get_atom(t_binbuf *b, int n) { if(binbuf_getnatom(b) <= n || n < 0) return NULL; return binbuf_getvec(b) + n; } */ /* helper function for accessing binbuf's atoms cause, accessing C arrays and doing typemaps is not that easy */ t_atom * binbuf_getatom(t_binbuf *x, int index) { return binbuf_getvec(x) + index; } t_object * CAST_t_object(t_object *o) { return o; } t_pd * CAST_t_pd(t_pd *o) { return o; } t_text * CAST_t_text(t_text *o) { return o; } t_tcl * CAST_t_tcl(t_tcl *o) { return o; } void poststring2 (const char *s) { post("%s", s); } void tclpd_save(t_gobj *z, t_binbuf *b) { Tcl_Obj *av[3]; InitArray(av, 3, NULL); Tcl_Obj *res; t_tcl *x = (t_tcl *)z; av[0] = x->dispatcher; Tcl_IncrRefCount(av[0]); av[1] = x->self; Tcl_IncrRefCount(av[1]); av[2] = Tcl_NewStringObj("save", -1); Tcl_IncrRefCount(av[2]); int result = Tcl_EvalObjv(tclpd_interp, 3, av, 0); if(result == TCL_OK) { res = Tcl_GetObjResult(tclpd_interp); Tcl_IncrRefCount(res); int objc; Tcl_Obj **objv; result = Tcl_ListObjGetElements(tclpd_interp, res, &objc, &objv); if(result == TCL_OK) { if(objc == 0 && objv == NULL) { // call default savefn text_save(z, b); } else { // do custom savefn int i; double tmp; for(i = 0; i < objc; i++) { result = Tcl_GetDoubleFromObj(tclpd_interp, objv[i], &tmp); if(result == TCL_OK) { binbuf_addv(b, "f", (t_float)tmp); } else { char *tmps = Tcl_GetStringFromObj(objv[i], NULL); if(!strcmp(tmps, ";")) { binbuf_addv(b, ";"); } else { binbuf_addv(b, "s", gensym(tmps)); } } } } } else { pd_error(x, "Tcl: object save: failed"); tclpd_interp_error(x, result); } Tcl_DecrRefCount(res); } else { pd_error(x, "Tcl: object save: failed"); tclpd_interp_error(x, result); } Tcl_DecrRefCount(av[0]); Tcl_DecrRefCount(av[1]); Tcl_DecrRefCount(av[2]); } void tclpd_properties(t_gobj *z, t_glist *owner) { Tcl_Obj *av[3]; InitArray(av, 3, NULL); t_tcl *x = (t_tcl *)z; av[0] = x->dispatcher; Tcl_IncrRefCount(av[0]); av[1] = x->self; Tcl_IncrRefCount(av[1]); av[2] = Tcl_NewStringObj("properties", -1); Tcl_IncrRefCount(av[2]); int result = Tcl_EvalObjv(tclpd_interp, 3, av, 0); if(result != TCL_OK) { //res = Tcl_GetObjResult(tclpd_interp); pd_error(x, "Tcl: object properties: failed"); tclpd_interp_error(x, result); } Tcl_DecrRefCount(av[0]); Tcl_DecrRefCount(av[1]); Tcl_DecrRefCount(av[2]); } void tclpd_class_namespace_init(const char *classname) { char cmd[256]; snprintf(cmd, 256, "if [namespace exists ::%s] " "{namespace delete ::%s}; " "namespace eval ::%s {}", classname, classname, classname); Tcl_Eval(tclpd_interp, cmd); } void source_table_remove(const char *object_name) { if(!source_table) source_table = hashtable_new(1 << 7); hashtable_remove(source_table, object_name); } void source_table_add(const char *object_name, const char *source_file) { source_table_remove(object_name); hashtable_add(source_table, object_name, strdup(source_file)); } tclpd-0.3.1/tcl_loader.c000066400000000000000000000066471433742306500151210ustar00rootroot00000000000000#include "tclpd.h" #include #include extern int sys_verbose; /* included in pd, also defined in s_stuff.h */ /* from tcl_class.c: */ //void source_table_remove(const char *object_name); void source_table_add(const char *object_name, const char *source_path); extern int tclpd_do_load_lib(t_canvas *canvas, char *objectname) { char filename[MAXPDSTRING], dirbuf[MAXPDSTRING], buf[MAXPDSTRING], *classname, *nameptr; int fd; if ((classname = strrchr(objectname, '/')) != NULL) classname++; else classname = objectname; if(sys_onloadlist(objectname)) { verbose(-1, "tclpd loader: already loaded: %s", objectname); return 1; } /* try looking in the path for (objectname).(tcl) ... */ if(sys_verbose) verbose(-1, "tclpd loader: searching for %s in path...", objectname); if ((fd = canvas_open(canvas, objectname, ".tcl", dirbuf, &nameptr, MAXPDSTRING, 1)) >= 0) goto found; /* next try (objectname)/(classname).(tcl) ... */ strncpy(filename, objectname, MAXPDSTRING); filename[MAXPDSTRING - 2] = 0; strcat(filename, "/"); strncat(filename, classname, MAXPDSTRING-strlen(filename)); filename[MAXPDSTRING - 1] = 0; if(sys_verbose) verbose(-1, "tclpd loader: searching for %s in path...", filename); if ((fd = canvas_open(canvas, filename, ".tcl", dirbuf, &nameptr, MAXPDSTRING, 1)) >= 0) goto found; if(sys_verbose) verbose(-1, "tclpd loader: found nothing!"); return 0; found: verbose(-1, "tclpd loader: found!"); close(fd); class_set_extern_dir(gensym(dirbuf)); /* rebuild the absolute pathname */ strncpy(filename, dirbuf, MAXPDSTRING); filename[MAXPDSTRING - 2] = 0; strcat(filename, "/"); strncat(filename, nameptr, MAXPDSTRING - strlen(filename)); filename[MAXPDSTRING - 1] = 0; verbose(-1, "tclpd loader: absolute path is %s", filename); int result; // create the required tcl namespace for the class verbose(-1, "tclpd loader: init namespace for class %s", classname); tclpd_class_namespace_init(classname); // add current dir to the Tcl auto_path so objects can use local packages Tcl_Eval(tclpd_interp, "set current_auto_path $auto_path"); snprintf(buf, MAXPDSTRING, "set auto_path \"{%s} $auto_path\"", dirbuf); Tcl_Eval(tclpd_interp, buf); verbose(0, "%s", buf); // load tcl external: verbose(-1, "tclpd loader: loading tcl file %s", filename); result = Tcl_EvalFile(tclpd_interp, filename); if(result == TCL_OK) { source_table_add(classname, filename); verbose(0, "tclpd loader: loaded %s", filename); } else { error("tclpd loader: error trying to load %s", filename); tclpd_interp_error(NULL, result); return 0; } // reset auto_path Tcl_Eval(tclpd_interp, "set auto_path $current_auto_path"); #ifdef TCLPD_CALL_SETUP // call the setup method: char cmd[64]; snprintf(cmd, 64, "::%s::setup", classname); verbose(-1, "tclpd loader: calling setup function for %s", classname); result = Tcl_Eval(tclpd_interp, cmd); if(result == TCL_OK) { } else { error("tclpd loader: error in %s %s::setup", filename, classname); tclpd_interp_error(NULL, result); return 0; } #endif // TCLPD_CALL_SETUP class_set_extern_dir(&s_); sys_putonloadlist(objectname); return 1; } tclpd-0.3.1/tcl_proxyinlet.c000066400000000000000000000033721433742306500160600ustar00rootroot00000000000000#include "tclpd.h" t_class *proxyinlet_class; void proxyinlet_init(t_proxyinlet *x) { //x->pd = proxyinlet_class; x->target = NULL; x->sel = gensym("none"); x->argc = 0; x->argv = NULL; } void proxyinlet_clear(t_proxyinlet *x) { if(x->argv) { freebytes(x->argv, x->argc * sizeof(*x->argv)); } } #define PROXYINLET_SEL_TO_LIST 0 // 0 or 1 void proxyinlet_anything(t_proxyinlet *x, t_symbol *s, int argc, t_atom *argv) { proxyinlet_clear(x); if(!(x->argv = (t_atom *)getbytes((argc+PROXYINLET_SEL_TO_LIST) * sizeof(*x->argv)))) { x->argc = 0; error("proxyinlet: getbytes: out of memory"); return; } x->argc = argc + PROXYINLET_SEL_TO_LIST; if(PROXYINLET_SEL_TO_LIST == 1) SETSYMBOL(&x->argv[0], s); else x->sel = s; int i; for(i = 0; i < argc; i++) { x->argv[i+PROXYINLET_SEL_TO_LIST] = argv[i]; } proxyinlet_trigger(x); } void proxyinlet_trigger(t_proxyinlet *x) { if(x->target != NULL && x->sel != gensym("none")) { tclpd_inlet_anything(x->target, x->ninlet, x->sel, x->argc, x->argv); } } t_atom * proxyinlet_get_atoms(t_proxyinlet *x) { return x->argv; } void proxyinlet_clone(t_proxyinlet *x, t_proxyinlet *y) { y->target = x->target; y->sel = x->sel; y->argc = x->argc; if(!(y->argv = (t_atom *)getbytes(y->argc * sizeof(*y->argv)))) { y->argc = 0; error("proxyinlet: getbytes: out of memory"); return; } int i; for(i = 0; i < x->argc; i++) { y->argv[i] = x->argv[i]; } } void proxyinlet_setup(void) { proxyinlet_class = class_new(gensym("tclpd proxyinlet"), 0, 0, sizeof(t_proxyinlet), 0, A_NULL); class_addanything(proxyinlet_class, proxyinlet_anything); } tclpd-0.3.1/tcl_typemap.c000066400000000000000000000115651433742306500153250ustar00rootroot00000000000000#include "tclpd.h" #include #include static const char *atomtype_map[] = { /* A_NULL */ "null", /* A_FLOAT */ "float", /* A_SYMBOL */ "symbol", /* A_POINTER */ "pointer", /* A_SEMI */ "semi", /* A_COMMA */ "comma", /* A_DEFFLOAT */ "deffloat", /* A_DEFSYM */ "defsym", /* A_DOLLAR */ "dollar", /* A_DOLLSYM */ "dollsym", /* A_GIMME */ "gimme", /* A_CANT */ "cant", #ifdef A_BLOB /* A_BLOB */ "blob" #endif }; #define atomtype_map_size (sizeof(atomtype_map)/sizeof(atomtype_map[0])) static const char * fwd_atomtype_map(t_atomtype t) { if(t >= atomtype_map_size) return atomtype_map[A_NULL]; return atomtype_map[t]; } static t_atomtype rev_atomtype_map(const char *s) { for(t_atomtype i = 0; i < atomtype_map_size; i++) { if(strcmp(s, atomtype_map[i]) == 0) return i; } return A_NULL; } int tcl_to_pdatom(Tcl_Obj *input, t_atom *output) { int llength; if(Tcl_ListObjLength(tclpd_interp, input, &llength) == TCL_ERROR) return TCL_ERROR; if(llength != 2) return TCL_ERROR; int i; Tcl_Obj *obj[2]; for(i = 0; i < 2; i++) Tcl_ListObjIndex(tclpd_interp, input, i, &obj[i]); char *argv0 = Tcl_GetStringFromObj(obj[0], 0); t_atomtype a_type = rev_atomtype_map(argv0); switch(a_type) { case A_FLOAT: case A_DEFFLOAT: { double dbl; if(Tcl_GetDoubleFromObj(tclpd_interp, obj[1], &dbl) == TCL_ERROR) return TCL_ERROR; SETFLOAT(output, dbl); break; } case A_SYMBOL: case A_DEFSYM: { SETSYMBOL(output, gensym(Tcl_GetStringFromObj(obj[1], 0))); break; } case A_POINTER: { long gpointer; if(Tcl_GetLongFromObj(tclpd_interp, obj[1], &gpointer) == TCL_ERROR) return TCL_ERROR; SETPOINTER(output, (t_gpointer *)gpointer); break; } case A_SEMI: { SETSEMI(output); break; } case A_COMMA: { SETCOMMA(output); break; } case A_DOLLAR: { char *str = Tcl_GetStringFromObj(obj[1], 0); if(!str) { return TCL_ERROR; } if(*str == '$') str++; int ii = atoi(str); SETDOLLAR(output, ii); break; } case A_DOLLSYM: { SETSYMBOL(output, gensym(Tcl_GetStringFromObj(obj[1], 0))); break; } // case A_GIMME: // case A_CANT: // case A_BLOB: // case A_NULL: default: { // TODO: set error result return TCL_ERROR; } } return TCL_OK; } int tcl_to_pdsymbol(Tcl_Obj *input, t_symbol **output) { char *s = Tcl_GetStringFromObj(input, 0); *output = gensym(s); return TCL_OK; } int pdatom_to_tcl(t_atom *input, Tcl_Obj **output) { Tcl_Obj *tcl_t_atom[2]; tcl_t_atom[0] = Tcl_NewStringObj(fwd_atomtype_map(input->a_type), -1); switch (input->a_type) { case A_FLOAT: case A_DEFFLOAT: { tcl_t_atom[1] = Tcl_NewDoubleObj(input->a_w.w_float); break; } case A_SYMBOL: case A_DEFSYM: case A_DOLLSYM: { tcl_t_atom[1] = Tcl_NewStringObj(input->a_w.w_symbol->s_name, strlen(input->a_w.w_symbol->s_name)); break; } case A_POINTER: { tcl_t_atom[1] = Tcl_NewDoubleObj((long)input->a_w.w_gpointer); break; } case A_DOLLAR: { char dolbuf[8]; snprintf(dolbuf, 8, "$%d", (int)input->a_w.w_index); tcl_t_atom[1] = Tcl_NewStringObj(dolbuf, -1); break; } case A_SEMI: { tcl_t_atom[1] = Tcl_NewStringObj(";", 1); break; } case A_COMMA: { tcl_t_atom[1] = Tcl_NewStringObj(",", 1); break; } case A_GIMME: case A_CANT: #ifdef A_BLOB case A_BLOB: #endif case A_NULL: default: { tcl_t_atom[1] = Tcl_NewStringObj("?", 1); break; } } #if 0 verbose(-1, "tclpd: pdatom_to_tcl: atom [type = %s, value = %s]", Tcl_GetStringFromObj(tcl_t_atom[0], 0), Tcl_GetStringFromObj(tcl_t_atom[1], 0)); #endif *output = Tcl_NewListObj(2, &tcl_t_atom[0]); Tcl_IncrRefCount(*output); return TCL_OK; } int pdsymbol_to_tcl(t_symbol *input, Tcl_Obj **output) { #if 0 Tcl_Obj *s[2]; s[0] = Tcl_NewStringObj("symbol", -1); s[1] = Tcl_NewStringObj(input->s_name, -1); *output = Tcl_NewListObj(2, &s[0]); #else *output = Tcl_NewStringObj(input->s_name, -1); #endif Tcl_IncrRefCount(*output); return TCL_OK; } tclpd-0.3.1/tcl_widgetbehavior.c000066400000000000000000000226751433742306500166550ustar00rootroot00000000000000#include "tclpd.h" #include void tclpd_guiclass_motion(t_tcl *x, t_floatarg dx, t_floatarg dy) { Tcl_Obj *av[6]; InitArray(av, 6, NULL); av[0] = x->dispatcher; Tcl_IncrRefCount(av[0]); av[1] = x->self; Tcl_IncrRefCount(av[1]); av[2] = Tcl_NewStringObj("widgetbehavior", -1); Tcl_IncrRefCount(av[2]); av[3] = Tcl_NewStringObj("motion", -1); Tcl_IncrRefCount(av[3]); av[4] = Tcl_NewDoubleObj(dx); Tcl_IncrRefCount(av[4]); av[5] = Tcl_NewDoubleObj(dy); Tcl_IncrRefCount(av[5]); int result = Tcl_EvalObjv(tclpd_interp, 6, av, 0); if(result != TCL_OK) { tclpd_interp_error(x, result); goto error; } goto cleanup; error: cleanup: Tcl_DecrRefCount(av[0]); Tcl_DecrRefCount(av[1]); Tcl_DecrRefCount(av[2]); Tcl_DecrRefCount(av[3]); Tcl_DecrRefCount(av[4]); Tcl_DecrRefCount(av[5]); } void tclpd_guiclass_grab(t_tcl *x, t_glist *glist, int xpix, int ypix) { glist_grab(glist, &x->o.te_g, (t_glistmotionfn)tclpd_guiclass_motion, 0, \ (t_floatarg)xpix, (t_floatarg)ypix); } int tclpd_guiclass_click(t_gobj *z, t_glist *glist, int xpix, int ypix, int shift, int alt, int dbl, int doit) { Tcl_Obj *av[10]; InitArray(av, 10, NULL); Tcl_Obj *o = NULL; int i = 0; t_tcl *x = (t_tcl *)z; av[0] = x->dispatcher; Tcl_IncrRefCount(av[0]); av[1] = x->self; Tcl_IncrRefCount(av[1]); av[2] = Tcl_NewStringObj("widgetbehavior", -1); Tcl_IncrRefCount(av[2]); av[3] = Tcl_NewStringObj("click", -1); Tcl_IncrRefCount(av[3]); av[4] = Tcl_NewIntObj(xpix); Tcl_IncrRefCount(av[4]); av[5] = Tcl_NewIntObj(ypix); Tcl_IncrRefCount(av[5]); av[6] = Tcl_NewIntObj(shift); Tcl_IncrRefCount(av[6]); av[7] = Tcl_NewIntObj(alt); Tcl_IncrRefCount(av[7]); av[8] = Tcl_NewIntObj(dbl); Tcl_IncrRefCount(av[8]); av[9] = Tcl_NewIntObj(doit); Tcl_IncrRefCount(av[9]); int result = Tcl_EvalObjv(tclpd_interp, 10, av, 0); if(result != TCL_OK) { goto error; } o = Tcl_GetObjResult(tclpd_interp); Tcl_IncrRefCount(o); if(strlen(Tcl_GetStringFromObj(o, NULL)) > 0) { result = Tcl_GetIntFromObj(tclpd_interp, o, &i); if(result != TCL_OK) { goto error; } } goto cleanup; error: tclpd_interp_error(x, result); cleanup: if(o) Tcl_DecrRefCount(o); Tcl_DecrRefCount(av[0]); Tcl_DecrRefCount(av[1]); Tcl_DecrRefCount(av[2]); Tcl_DecrRefCount(av[3]); Tcl_DecrRefCount(av[4]); Tcl_DecrRefCount(av[5]); Tcl_DecrRefCount(av[6]); Tcl_DecrRefCount(av[7]); Tcl_DecrRefCount(av[8]); Tcl_DecrRefCount(av[9]); // return value (BOOL) means 'object wants to be clicked' (g_editor.c:1270) return i; } void tclpd_guiclass_getrect(t_gobj *z, t_glist *owner, int *xp1, int *yp1, int *xp2, int *yp2) { Tcl_Obj *av[6]; InitArray(av, 6, NULL); Tcl_Obj *o; Tcl_Obj *theList = NULL; int tmp[4], i, length; t_tcl *x = (t_tcl *)z; av[0] = x->dispatcher; Tcl_IncrRefCount(av[0]); av[1] = x->self; Tcl_IncrRefCount(av[1]); av[2] = Tcl_NewStringObj("widgetbehavior", -1); Tcl_IncrRefCount(av[2]); av[3] = Tcl_NewStringObj("getrect", -1); Tcl_IncrRefCount(av[3]); av[4] = Tcl_NewIntObj(text_xpix(&x->o, owner)); Tcl_IncrRefCount(av[4]); av[5] = Tcl_NewIntObj(text_ypix(&x->o, owner)); Tcl_IncrRefCount(av[5]); int result = Tcl_EvalObjv(tclpd_interp, 6, av, 0); if(result != TCL_OK) { tclpd_interp_error(x, result); goto error; } theList = Tcl_GetObjResult(tclpd_interp); Tcl_IncrRefCount(theList); length = 0; //result = Tcl_ListObjGetElements(tclpd_interp, theList, @, @); result = Tcl_ListObjLength(tclpd_interp, theList, &length); if(result != TCL_OK) { tclpd_interp_error(x, result); goto error; } if(length != 4) { pd_error(x, "widgetbehavior getrect: must return a list of 4 integers"); goto error; } o = NULL; for(i = 0; i < 4; i++) { result = Tcl_ListObjIndex(tclpd_interp, theList, i, &o); if(result != TCL_OK) { tclpd_interp_error(x, result); goto error; } result = Tcl_GetIntFromObj(tclpd_interp, o, &tmp[i]); if(result != TCL_OK) { tclpd_interp_error(x, result); goto error; } } *xp1 = tmp[0]; *yp1 = tmp[1]; *xp2 = tmp[2]; *yp2 = tmp[3]; goto cleanup; error: cleanup: if(theList) Tcl_DecrRefCount(theList); Tcl_DecrRefCount(av[0]); Tcl_DecrRefCount(av[1]); Tcl_DecrRefCount(av[2]); Tcl_DecrRefCount(av[3]); Tcl_DecrRefCount(av[4]); Tcl_DecrRefCount(av[5]); } void tclpd_guiclass_displace(t_gobj *z, t_glist *glist, int dx, int dy) { Tcl_Obj *av[6]; InitArray(av, 6, NULL); Tcl_Obj *theList = NULL; Tcl_Obj *o; int length, i, tmp[2]; t_tcl *x = (t_tcl *)z; av[0] = x->dispatcher; Tcl_IncrRefCount(av[0]); av[1] = x->self; Tcl_IncrRefCount(av[1]); av[2] = Tcl_NewStringObj("widgetbehavior", -1); Tcl_IncrRefCount(av[2]); av[3] = Tcl_NewStringObj("displace", -1); Tcl_IncrRefCount(av[3]); av[4] = Tcl_NewIntObj(dx); Tcl_IncrRefCount(av[4]); av[5] = Tcl_NewIntObj(dy); Tcl_IncrRefCount(av[5]); int result = Tcl_EvalObjv(tclpd_interp, 6, av, 0); if(result != TCL_OK) { tclpd_interp_error(x, result); goto error; } theList = Tcl_GetObjResult(tclpd_interp); Tcl_IncrRefCount(theList); length = 0; //result = Tcl_ListObjGetElements(tclpd_interp, theList, @, @); result = Tcl_ListObjLength(tclpd_interp, theList, &length); if(result != TCL_OK) { tclpd_interp_error(x, result); goto error; } if(length != 2) { pd_error(x, "widgetbehavior displace: must return a list of 2 integers"); goto error; } o = NULL; for(i = 0; i < 2; i++) { result = Tcl_ListObjIndex(tclpd_interp, theList, i, &o); if(result != TCL_OK) { tclpd_interp_error(x, result); goto error; } result = Tcl_GetIntFromObj(tclpd_interp, o, &tmp[i]); if(result != TCL_OK) { tclpd_interp_error(x, result); goto error; } } x->o.te_xpix = tmp[0]; x->o.te_ypix = tmp[1]; canvas_fixlinesfor(glist_getcanvas(glist), (t_text *)x); goto cleanup; error: cleanup: if(theList) Tcl_DecrRefCount(theList); Tcl_DecrRefCount(av[0]); Tcl_DecrRefCount(av[1]); Tcl_DecrRefCount(av[2]); Tcl_DecrRefCount(av[3]); Tcl_DecrRefCount(av[4]); Tcl_DecrRefCount(av[5]); } void tclpd_guiclass_select(t_gobj *z, t_glist *glist, int selected) { Tcl_Obj *av[5]; InitArray(av, 5, NULL); t_tcl *x = (t_tcl *)z; av[0] = x->dispatcher; Tcl_IncrRefCount(av[0]); av[1] = x->self; Tcl_IncrRefCount(av[1]); av[2] = Tcl_NewStringObj("widgetbehavior", -1); Tcl_IncrRefCount(av[2]); av[3] = Tcl_NewStringObj("select", -1); Tcl_IncrRefCount(av[3]); av[4] = Tcl_NewIntObj(selected); Tcl_IncrRefCount(av[4]); int result = Tcl_EvalObjv(tclpd_interp, 5, av, 0); if(result != TCL_OK) { tclpd_interp_error(x, result); goto error; } goto cleanup; error: cleanup: Tcl_DecrRefCount(av[0]); Tcl_DecrRefCount(av[1]); Tcl_DecrRefCount(av[2]); Tcl_DecrRefCount(av[3]); Tcl_DecrRefCount(av[4]); } void tclpd_guiclass_activate(t_gobj *z, t_glist *glist, int state) { Tcl_Obj *av[5]; InitArray(av, 5, NULL); t_tcl *x = (t_tcl *)z; av[0] = x->dispatcher; Tcl_IncrRefCount(av[0]); av[1] = x->self; Tcl_IncrRefCount(av[1]); av[2] = Tcl_NewStringObj("widgetbehavior", -1); Tcl_IncrRefCount(av[2]); av[3] = Tcl_NewStringObj("activate", -1); Tcl_IncrRefCount(av[3]); av[4] = Tcl_NewIntObj(state); Tcl_IncrRefCount(av[4]); int result = Tcl_EvalObjv(tclpd_interp, 5, av, 0); if(result != TCL_OK) { tclpd_interp_error(x, result); goto error; } goto cleanup; error: cleanup: Tcl_DecrRefCount(av[0]); Tcl_DecrRefCount(av[1]); Tcl_DecrRefCount(av[2]); Tcl_DecrRefCount(av[3]); Tcl_DecrRefCount(av[4]); } void tclpd_guiclass_delete(t_gobj *z, t_glist *glist) { /* will this be ever need to be accessed in Tcl land? */ canvas_deletelinesfor(glist_getcanvas(glist), (t_text *)z); } void tclpd_guiclass_vis(t_gobj *z, t_glist *glist, int vis) { Tcl_Obj *av[8]; InitArray(av, 8, NULL); t_tcl *x = (t_tcl *)z; av[0] = x->dispatcher; Tcl_IncrRefCount(av[0]); av[1] = x->self; Tcl_IncrRefCount(av[1]); av[2] = Tcl_NewStringObj("widgetbehavior", -1); Tcl_IncrRefCount(av[2]); av[3] = Tcl_NewStringObj("vis", -1); Tcl_IncrRefCount(av[3]); char buf[32]; snprintf(buf, 32, ".x%lx.c", glist_getcanvas(glist)); av[4] = Tcl_NewStringObj(buf, -1); Tcl_IncrRefCount(av[4]); av[5] = Tcl_NewIntObj(text_xpix(&x->o, glist)); Tcl_IncrRefCount(av[5]); av[6] = Tcl_NewIntObj(text_ypix(&x->o, glist)); Tcl_IncrRefCount(av[6]); av[7] = Tcl_NewIntObj(vis); Tcl_IncrRefCount(av[7]); int result = Tcl_EvalObjv(tclpd_interp, 8, av, 0); if(result != TCL_OK) { tclpd_interp_error(x, result); goto error; } goto cleanup; error: cleanup: Tcl_DecrRefCount(av[0]); Tcl_DecrRefCount(av[1]); Tcl_DecrRefCount(av[2]); Tcl_DecrRefCount(av[3]); Tcl_DecrRefCount(av[4]); Tcl_DecrRefCount(av[5]); Tcl_DecrRefCount(av[6]); Tcl_DecrRefCount(av[7]); } tclpd-0.3.1/tclpd-help.pd000066400000000000000000000007171433742306500152160ustar00rootroot00000000000000#N canvas 313 235 450 300 10; #X declare -lib tclpd; #X text 24 52 tclpd is a loader that allows Pd to load Tcl scripts as regular Pd objects. Normally you would load it when you start Pd \, so something like:; #X text 50 111 pd -lib tclpd; #X obj 51 169 declare -lib tclpd; #X text 26 135 or you can load it in the patch using:; #X text 24 202 You shouldn't try to create a [tclpd] object \, that will likely cause problems and not give you the desired effect.; tclpd-0.3.1/tclpd-meta.pd000066400000000000000000000002621433742306500152070ustar00rootroot00000000000000#N canvas 15 49 200 200 10; #N canvas 25 49 420 300 META 1; #X text 13 41 NAME tclpd; #X text 10 25 AUTHOR Federico Ferri; #X text 10 10 VERSION 0.3.0; #X restore 10 10 pd META; tclpd-0.3.1/tclpd.c000066400000000000000000000040451433742306500141050ustar00rootroot00000000000000#include "tclpd.h" #include #include #include #include Tcl_Interp *tclpd_interp = NULL; void tclpd_setup(void) { if(tclpd_interp) { return; } /* verbose(-1) post to the pd window at level 3 */ verbose(-1, "tclpd loader v" TCLPD_VERSION); proxyinlet_setup(); tclpd_interp = Tcl_CreateInterp(); Tcl_Init(tclpd_interp); Tclpd_SafeInit(tclpd_interp); Tcl_Eval(tclpd_interp, "package provide Tclpd " TCLPD_VERSION); t_class *foo_class = class_new(gensym("tclpd_init"), 0, 0, 0, 0, 0); char buf[PATH_MAX]; snprintf(buf, PATH_MAX, "%s/tclpd.tcl", foo_class->c_externdir->s_name); verbose(-1, "tclpd: trying to load %s...", buf); int result = Tcl_EvalFile(tclpd_interp, buf); switch(result) { case TCL_ERROR: error("tclpd: error loading %s", buf); break; case TCL_RETURN: error("tclpd: warning: %s exited with code return", buf); break; case TCL_BREAK: case TCL_CONTINUE: error("tclpd: warning: %s exited with code break/continue", buf); break; } verbose(-1, "tclpd: loaded %s", buf); sys_register_loader(tclpd_do_load_lib); } void tclpd_interp_error(t_tcl *x, int result) { error("tclpd error: %s", Tcl_GetStringResult(tclpd_interp)); logpost(x, 3, "------------------- Tcl error: -------------------"); // Tcl_GetReturnOptions and Tcl_DictObjGet only available in Tcl >= 8.5 #if ((TCL_MAJOR_VERSION == 8 && TCL_MINOR_VERSION >= 5) || (TCL_MAJOR_VERSION > 8)) Tcl_Obj *dict = Tcl_GetReturnOptions(tclpd_interp, result); Tcl_Obj *errorInfo = NULL; Tcl_Obj *errorInfoK = Tcl_NewStringObj("-errorinfo", -1); Tcl_IncrRefCount(errorInfoK); Tcl_DictObjGet(tclpd_interp, dict, errorInfoK, &errorInfo); Tcl_DecrRefCount(errorInfoK); logpost(x, 3, "%s\n", Tcl_GetStringFromObj(errorInfo, 0)); #else logpost(x, 3, "Backtrace not available in Tcl < 8.5. Please upgrade Tcl."); #endif logpost(x, 3, "--------------------------------------------------"); } tclpd-0.3.1/tclpd.def000077500000000000000000000000511433742306500144150ustar00rootroot00000000000000LIBRARY "tclpd.dll" EXPORTS tclpd_setup tclpd-0.3.1/tclpd.h000066400000000000000000000102161433742306500141070ustar00rootroot00000000000000#include "m_pd.h" //#include "m_imp.h" #include "g_canvas.h" //#include "s_stuff.h" #include /* PATH_MAX is not defined in limits.h on some platforms */ #ifndef PATH_MAX #define PATH_MAX 4096 #endif #define TCLPD_VERSION "0.3.0" #define InitArray(name, size, value) for(int zz=0; zz<(size); zz++) name[zz]=value typedef struct _t_tcl { t_object o; int ninlets; /* used for proxy inlet count */ char *source_file; // Tcl-interpreter related objects: Tcl_Obj *self; Tcl_Obj *classname; Tcl_Obj *dispatcher; } t_tcl; typedef struct _t_proxyinlet { t_object obj; t_tcl *target; int ninlet; t_symbol *sel; int argc; t_atom *argv; } t_proxyinlet; /* tcl_proxyinlet.c */ extern t_class *proxyinlet_class; void proxyinlet_init(t_proxyinlet *x); void proxyinlet_clear(t_proxyinlet *x); void proxyinlet_anything(t_proxyinlet *x, t_symbol *s, int argc, t_atom *argv); void proxyinlet_trigger(t_proxyinlet *x); t_atom * proxyinlet_get_atoms(t_proxyinlet *x); void proxyinlet_clone(t_proxyinlet *x, t_proxyinlet *y); void proxyinlet_setup(void); /* tcl_wrap.c */ extern int Tclpd_SafeInit(Tcl_Interp *interp); /* tcl_typemap.c */ int tcl_to_pdatom(Tcl_Obj *input, t_atom *output); int tcl_to_pdsymbol(Tcl_Obj *input, t_symbol **output); int pdatom_to_tcl(t_atom *input, Tcl_Obj **output); int pdsymbol_to_tcl(t_symbol *input, Tcl_Obj **output); /* tclpd.c */ extern Tcl_Interp *tclpd_interp; extern void tclpd_setup(void); void tclpd_interp_error(t_tcl *x, int result); /* tcl_class.c */ void class_table_add(const char *n, t_class *c); void class_table_remove(const char *n); t_class * class_table_get(const char *n); void object_table_add(const char *n, t_tcl *o); void object_table_remove(const char *n); t_tcl * object_table_get(const char *n); t_class * tclpd_class_new(const char *name, int flags); t_class * tclpd_guiclass_new(const char *name, int flags); t_tcl * tclpd_new(t_symbol *classsym, int ac, t_atom *at); void tclpd_free (t_tcl *self); void tclpd_anything(t_tcl *self, t_symbol *s, int ac, t_atom *at); void tclpd_inlet_anything(t_tcl *self, int inlet, t_symbol *s, int ac, t_atom *at); void tclpd_loadbang(t_tcl *x); void tclpd_open(t_tcl *x); t_proxyinlet * tclpd_add_proxyinlet(t_tcl *x); /* t_tcl * tclpd_get_instance(const char *objectSequentialId); t_pd * tclpd_get_instance_pd(const char *objectSequentialId); t_text * tclpd_get_instance_text(const char *objectSequentialId); t_object * tclpd_get_object(const char *objectSequentialId); t_pd * tclpd_get_object_pd(const char *objectSequentialId); t_binbuf * tclpd_get_object_binbuf(const char *objectSequentialId); t_glist * tclpd_get_glist(const char *objectSequentialId); t_atom * tclpd_binbuf_get_atom(t_binbuf *b, int n); */ t_atom * binbuf_getatom(t_binbuf *x, int index); t_object * CAST_t_object(t_object *o); t_pd * CAST_t_pd(t_pd *o); t_text * CAST_t_text(t_text *o); t_tcl * CAST_t_tcl(t_tcl *o); void poststring2(const char *s); extern void text_save(t_gobj *z, t_binbuf *b); void tclpd_save(t_gobj *z, t_binbuf *b); void tclpd_properties(t_gobj *z, t_glist *owner); void tclpd_class_namespace_init(const char *classname); /* tcl_widgetbehavior.c */ void tclpd_guiclass_getrect(t_gobj *z, t_glist *owner, int *xp1, int *yp1, int *xp2, int *yp2); void tclpd_guiclass_displace(t_gobj *z, t_glist *glist, int dx, int dy); void tclpd_guiclass_select(t_gobj *z, t_glist *glist, int selected); void tclpd_guiclass_activate(t_gobj *z, t_glist *glist, int state); void tclpd_guiclass_delete(t_gobj *z, t_glist *glist); void tclpd_guiclass_vis(t_gobj *z, t_glist *glist, int vis); int tclpd_guiclass_click(t_gobj *z, t_glist *glist, int xpix, int ypix, int shift, int alt, int dbl, int doit); void tclpd_guiclass_motion(t_tcl *x, t_floatarg dx, t_floatarg dy); void tclpd_guiclass_grab(t_tcl *x, t_glist *glist, int xpix, int ypix); /* tcl_loader.c */ extern int tclpd_do_load_lib(t_canvas *canvas, char *objectname); /* pd loader private stuff: */ typedef int (*loader_t)(t_canvas *canvas, char *classname); extern void sys_register_loader(loader_t loader); extern int sys_onloadlist(char *classname); extern void sys_putonloadlist(char *classname); extern void class_set_extern_dir(t_symbol *s); tclpd-0.3.1/tclpd.i000066400000000000000000000113651433742306500141160ustar00rootroot00000000000000%module tclpd %{ #undef EXTERN #include "tclpd.h" #define __attribute__(x) #ifdef __GNUC__ # pragma GCC diagnostic ignored "-Wunused-parameter" #endif %} %include exception.i %include cpointer.i %include carrays.i %include typemaps.i %pointer_functions(t_atom, atom); %pointer_functions(t_symbol, symbol); /* %array_functions(t_atom_array, atom_array); Creates four functions. type *new_name(int nelements) type *delete_name(type *ary) type name_getitem(type *ary, int index) void name_setitem(type *ary, int index, type value) */ %typemap(in) (int argc, t_atom *argv) { if(Tcl_ListObjLength(interp, $input, &$1) == TCL_ERROR) { SWIG_exception_fail(SWIG_RuntimeError, "failed to get list length"); } $2 = (t_atom *)getbytes(sizeof(t_atom) * $1); int i; Tcl_Obj *oi; for(i = 0; i < $1; i++) { if(Tcl_ListObjIndex(interp, $input, i, &oi) == TCL_ERROR) { SWIG_exception_fail(SWIG_RuntimeError, "failed to access list element"); } if(tcl_to_pdatom(oi, &$2[i]) == TCL_ERROR) { SWIG_exception_fail(SWIG_RuntimeError, "failed tcl_to_pdatom conversion"); } } } %typemap(freearg) (int argc, t_atom *argv) { if($2) freebytes($2, sizeof(t_atom) * $1); } %typemap(in) t_atom * { $1 = (t_atom *)getbytes(sizeof(t_atom)); if(tcl_to_pdatom($input, $1) == TCL_ERROR) { SWIG_exception_fail(SWIG_RuntimeError, "failed tcl_to_pdatom conversion"); } } %typemap(freearg) t_atom * { freebytes($1, sizeof(t_atom)); } %typemap(out) t_atom * { Tcl_Obj *lst; if(pdatom_to_tcl($1, &lst) == TCL_ERROR) { SWIG_exception_fail(SWIG_RuntimeError, "failed pdatom_to_tcl conversion"); } Tcl_SetObjResult(interp, lst); } %typemap(in) t_symbol * { if(tcl_to_pdsymbol($input, &$1) == TCL_ERROR) { SWIG_exception_fail(SWIG_RuntimeError, "failed tcl_to_pdsymbol conversion"); } } %typemap(out) t_symbol * { Tcl_Obj *lst; if(pdsymbol_to_tcl($1, &lst) == TCL_ERROR) { SWIG_exception_fail(SWIG_RuntimeError, "failed pdsymbol_to_tcl conversion"); } Tcl_SetObjResult(interp, lst); } %typemap(in) t_tcl * { const char *str = Tcl_GetStringFromObj($input, NULL); $1 = object_table_get(str); SWIG_contract_assert($1, "not a t_tcl * instance"); } %typemap(in) t_pd * { const char *str = Tcl_GetStringFromObj($input, NULL); $1 = object_table_get(str); SWIG_contract_assert($1, "not a t_pd * instance"); // XXX: %typemap(out) missing!!! } %typemap(in) t_text * { int res = SWIG_ConvertPtr($input, &$1, $1_descriptor, 0 | 0 ); if(!SWIG_IsOK(res)) { const char *str = Tcl_GetStringFromObj($input, NULL); t_tcl *x = object_table_get(str); SWIG_contract_assert(x, "not a t_text * instance"); $1 = &x->o; } } %typemap(in) t_object * { const char *str = Tcl_GetStringFromObj($input, NULL); t_tcl *x = object_table_get(str); SWIG_contract_assert(x, "not a t_object * instance"); $1 = &x->o; } %typemap(in) struct _class * { const char *str = Tcl_GetStringFromObj($input, NULL); t_class *c = class_table_get(str); SWIG_contract_assert(c, "invalid class name"); $1 = c; } /* functions that are in m_pd.h but don't exist in modern versions of pd */ %ignore pd_getfilename; %ignore pd_getdirname; %ignore pd_anything; %ignore class_parentwidget; %ignore sys_isreadablefile; %ignore garray_get; %ignore c_extern; %ignore c_addmess; /* functions that we can't auto-wrap, because they have varargs */ %ignore post; %ignore class_new; /* functions that we can't auto-wrap, because */ %ignore glist_new; %ignore canvas_zapallfortemplate; %ignore canvas_fattenforscalars; %ignore canvas_visforscalars; %ignore canvas_clicksub; %ignore text_xcoord; %ignore text_ycoord; %ignore canvas_getglistonsuper; %ignore canvas_getfont; %ignore canvas_setusedastemplate; %ignore canvas_vistext; %ignore rtext_remove; %ignore canvas_recurapply; %ignore gobj_properties; /* function that we don't want to wrap, because they are internal */ %ignore tclpd_setup; %ignore tclpd_interp_error; %ignore tcl_to_pdatom; %ignore tcl_to_pdsymbol; %ignore pdatom_to_tcl; %ignore pdsymbol_to_tcl; %ignore class_table_add; %ignore class_table_remove; %ignore class_table_get; %ignore object_table_add; %ignore object_table_remove; %ignore object_table_get; /* not needed - typemaps take care of this */ %ignore gensym; /* end of ignore-list */ %include "m_pd.h" %include "g_canvas.h" %include "tclpd.h" /* this does the trick of solving TypeError in method 'xyz', argument 4 of type 't_atom *' */ /*%name(outlet_list) EXTERN void outlet_list(t_outlet *x, t_symbol *s, int argc, t_atom_array *argv); %name(outlet_anything) EXTERN void outlet_anything(t_outlet *x, t_symbol *s, int argc, t_atom_array *argv); */ tclpd-0.3.1/tclpd.tcl000066400000000000000000000202511433742306500144420ustar00rootroot00000000000000# TCL helper library for PD/tclpd api # Copyright (c) 2007-2011 Federico Ferri package provide TclpdLib 0.20 package require Tcl 8.5 package require Tclpd 0.3.0 set verbose 0 namespace eval :: { proc proc+ {name arglist body} { set body2 [concat "global _;" [regsub -all @(\\\$?\[\\w\\?\]+) $body _(\$self:\\1)]] uplevel #0 [list proc $name $arglist $body2] } } namespace eval ::pd { proc error_msg {m} { return "pdlib: [uplevel {lindex [info level 0] 0}]: error: $m" } proc add_inlet {self sel} { if $::verbose {post [info level 0]} variable _ tclpd_add_proxyinlet $self } proc add_outlet {self {sel {}}} { if $::verbose {post [info level 0]} variable _ if {$sel eq {}} { set o [outlet_new $self NULL] } else { if {[lsearch -exact {bang float list symbol} $sel] == -1} { return -code error [error_msg "unsupported selector: $sel"] } set o [outlet_new $self $sel] } lappend _($self:x_outlet) $o return $o } # used inside class for outputting some value proc outlet {self numInlet selector args} { if $::verbose {post [info level 0]} variable _ set outlet [lindex $_($self:x_outlet) $numInlet] switch -- $selector { float { set v [lindex $args 0] outlet_float $outlet $v } symbol { set v [lindex $args 0] outlet_symbol $outlet $v } list { set v [lindex $args 0] outlet_list $outlet list $v } bang { outlet_bang $outlet } default { set v [lindex $args 0] outlet_anything $outlet $selector $v } } } proc read_class_options {classname options} { set flag $::CLASS_DEFAULT foreach {k v} $options { switch -- $k { -patchable { if {$v != 0 && $v != 1} { return -code error [error_msg "-patchable must be 0/1"] } set flag [expr {$flag|($::CLASS_PATCHABLE*$v)}] } -noinlet { if {$v != 0 && $v != 1} { return -code error [error_msg "-noinlet must be 0/1"] } set flag [expr {$flag|($::CLASS_NOINLET*$v)}] } default { return -code error [error_msg "unknown option: $k"] } } } # TODO: c->c_gobj = (typeflag >= CLASS_GOBJ) proc ::${classname}::dispatcher {self function args} " if {\$function eq {method}} { set inlet \[lindex \$args 0\] set selector \[lindex \$args 1\] set argsr \[lrange \$args 2 end\] set i_s ::${classname}::\${inlet}_\${selector} set i_a ::${classname}::\${inlet}_anything if {\[info procs \$i_s\] ne {}} { uplevel \[linsert \$argsr 0 \$i_s \$self\] } elseif {\[info procs \$i_s\] eq {} && \[info procs \$i_a\] ne {}} { uplevel \[linsert \$argsr 0 \$i_a \$self \[pd::add_selector \$selector\]\] } else { return -code error \"${classname}: no such method: \$i_s\" } } elseif {\$function eq {widgetbehavior}} { set subfunction \[lindex \$args 0\] set argsr \[lrange \$args 1 end\] set f ::${classname}::\${function}_\${subfunction} if {\[info procs \$f\] ne {}} { uplevel \[linsert \$argsr 0 \$f \$self] } } else { # feature request 3436774 if {\$function eq {constructor}} { namespace eval ::${classname}::\$self {} } uplevel \[linsert \$args 0 ::${classname}::\$function \$self\] } " # some dummy function to suppress eventual errors if they are not deifned: proc ::${classname}::0_loadbang {self} {} return $flag } # this handles the pd::class definition proc class {classname args} { if $::verbose {post [lrange [info level 0] 0 end-1]} set flag [read_class_options $classname $args] # this wraps the call to class_new() tclpd_class_new $classname $flag } proc guiclass {classname args} { if $::verbose {post [lrange [info level 0] 0 end-1]} set flag [read_class_options $classname $args] # this wraps the call to class_new() tclpd_guiclass_new $classname $flag } # wrapper to post() without vargs proc post {args} { poststring2 [concat {*}$args] } proc args {} { return [uplevel 1 "llength \$args"] } proc arg {n {assertion any}} { upvar 1 args up_args set up_args_len [llength $up_args] if {$n < 0 || $n >= $up_args_len} { return -code error "fatal: argument $n out of range" } set v [lindex $up_args $n] set i 0 if {[llength $v] != 2} { return -code error "fatal: malformed atom: $v (full args: $up_args)" } foreach {selector value} $v {break} if {$assertion eq {int}} { set assertion {float} set i 1 } if {$assertion ne {any}} { if {$selector ne $assertion} { return -code error "arg #$n is $selector, must be $assertion" } } if {$assertion eq {float} && $i && $value != int($value)} { return -code error "arg #$n is float, must be int" } if {$assertion eq {float} && $i} { return [expr {int($value)}] } else { return $value } } proc default_arg {n assertion defval} { if {$n < [uplevel "pd::args"]} { return [uplevel "pd::arg $n $assertion"] } else { return $defval } } proc strip_selectors {pdlist} { set r {} foreach atom $pdlist { if {[llength $atom] != 2} { return -code error "Malformed pd list!" } lappend r [lindex $atom 1] } return $r } proc add_selector {s} { return [list [lindex {float symbol} [catch {expr $s}]] $s] } proc add_selectors {tcllist} { set r {} foreach i $tcllist { lappend r [add_selector $i] } return $r } proc strip_empty {tcllist} { set r {} foreach i $tcllist { if {$i eq "empty"} {lappend r {}} {lappend r $i} } return $r } proc add_empty {tcllist} { set r {} foreach i $tcllist { if {$i eq {}} {lappend r "empty"} {lappend r $i} } return $r } # mechanism for uploading procs to gui interp, without the hassle of escaping [encoder] proc guiproc {name argz body} { # upload the decoder sys_gui "proc guiproc {name argz body} {set map {}; for {set i 0} {\$i < 256} {incr i} {lappend map %\[format %02x \$i\] \[format %c \$i\]}; foreach x {name argz body} {set \$x \[string map \$map \[set \$x\]\]}; uplevel \[list proc \$name \$argz \$body\]}\n" # build the mapping set map {} for {set i 0} {$i < 256} {incr i} { set chr [format %c $i] set hex [format %02x $i] if {[regexp {[^A-Za-z0-9]} $chr]} {lappend map $chr %$hex} } # encode data foreach x {name argz body} {set $x [string map $map [set $x]]} # upload proc sys_gui "guiproc $name $argz $body\n" } proc get_binbuf {self} { set ob [CAST_t_object $self] set binbuf [$ob cget -te_binbuf] set len [binbuf_getnatom $binbuf] set result {} for {set i 0} {$i < $len} {incr i} { set atom [binbuf_getatom $binbuf $i] lappend result $atom } return $result } } tclpd-0.3.1/tests/000077500000000000000000000000001433742306500137725ustar00rootroot00000000000000tclpd-0.3.1/tests/Makefile000066400000000000000000000006231433742306500154330ustar00rootroot00000000000000all: @# check that test-system itself is functional @# TODO: check that this check is functional? :-D @sh runtest.sh helloworld @# basic output test - outputting correct selector/atoms @sh runtest.sh basic_output @# basic input test - dispatching to correct methods @sh runtest.sh basic_input @# atoms conversion test & binbuf retrieval @sh runtest.sh binbuf clean: rm -fv *.out runtest-*.pd tclpd-0.3.1/tests/_test_template.pd000066400000000000000000000011641433742306500173320ustar00rootroot00000000000000#N canvas 237 169 450 300 10; #X obj 46 102 inlet; #X obj 46 236 outlet; #X obj 115 170 outlet; #X text 31 22 this is the template for a test; #X text 31 63 inlet 0 receives bang on load; #X text 160 119 send output to outlet 0 \; bang outlet 1 when test is complete; #N canvas 0 0 450 300 bang_swap 0; #X obj 63 58 inlet; #X obj 63 112 t b b; #X obj 112 172 outlet; #X obj 63 172 outlet; #X connect 0 0 1 0; #X connect 1 0 2 0; #X connect 1 1 3 0; #X restore 46 139 pd bang_swap; #X msg 46 202 first output \, second output; #X connect 0 0 6 0; #X connect 6 0 7 0; #X connect 6 1 2 0; #X connect 7 0 1 0; tclpd-0.3.1/tests/basic_input.pd000066400000000000000000000010251433742306500166150ustar00rootroot00000000000000#N canvas 306 152 450 300 10; #X obj 48 53 inlet; #X obj 48 234 outlet; #N canvas 0 0 450 300 bang_swap 0; #X obj 63 58 inlet; #X obj 63 112 t b b; #X obj 112 172 outlet; #X obj 63 172 outlet; #X connect 0 0 1 0; #X connect 1 0 2 0; #X connect 1 1 3 0; #X restore 48 89 pd bang_swap; #X obj 117 115 outlet; #X msg 48 144 123 \, symbol foo \, list 123 foo bar \, somethingelse ; #X obj 48 187 basic_input_helper; #X connect 0 0 2 0; #X connect 2 0 4 0; #X connect 2 1 3 0; #X connect 4 0 5 0; #X connect 5 0 1 0; tclpd-0.3.1/tests/basic_input.ref000066400000000000000000000000431433742306500167650ustar00rootroot00000000000000float; symbol; list; anything; tclpd-0.3.1/tests/basic_input_helper.tcl000066400000000000000000000010121433742306500203270ustar00rootroot00000000000000package require Tclpd 0.3.0 package require TclpdLib 0.20 proc basic_input_helper::constructor {self args} { pd::add_outlet $self list } proc basic_input_helper::0_float {self args} { pd::outlet $self 0 symbol float } proc basic_input_helper::0_symbol {self args} { pd::outlet $self 0 symbol symbol } proc basic_input_helper::0_list {self args} { pd::outlet $self 0 symbol list } proc basic_input_helper::0_anything {self args} { pd::outlet $self 0 symbol anything } pd::class basic_input_helper tclpd-0.3.1/tests/basic_output.pd000066400000000000000000000010121433742306500170120ustar00rootroot00000000000000#N canvas 306 152 450 300 10; #X obj 48 53 inlet; #X obj 48 234 outlet; #X obj 48 187 basic_output_helper; #X msg 48 144 symbol float \, symbol symbol \, symbol list; #N canvas 0 0 450 300 bang_swap 0; #X obj 63 58 inlet; #X obj 63 112 t b b; #X obj 112 172 outlet; #X obj 63 172 outlet; #X connect 0 0 1 0; #X connect 1 0 2 0; #X connect 1 1 3 0; #X restore 48 89 pd bang_swap; #X obj 117 115 outlet; #X connect 0 0 4 0; #X connect 2 0 1 0; #X connect 3 0 2 0; #X connect 4 0 3 0; #X connect 4 1 5 0; tclpd-0.3.1/tests/basic_output.ref000066400000000000000000000000321433742306500171640ustar00rootroot00000000000000123; baz; foo 123 bar; tclpd-0.3.1/tests/basic_output_helper.tcl000066400000000000000000000007771433742306500205510ustar00rootroot00000000000000package require Tclpd 0.3.0 package require TclpdLib 0.20 proc basic_output_helper::constructor {self args} { pd::add_outlet $self list } proc basic_output_helper::0_symbol {self args} { switch -exact -- [pd::arg 0 symbol] { float { pd::outlet $self 0 float 123 } symbol { pd::outlet $self 0 symbol baz } list { pd::outlet $self 0 list {{symbol foo} {float 123} {symbol bar}} } } } pd::class basic_output_helper tclpd-0.3.1/tests/binbuf.pd000066400000000000000000000007141433742306500155660ustar00rootroot00000000000000#N canvas 306 152 450 300 10; #X obj 48 53 inlet; #X obj 48 234 outlet; #N canvas 0 0 450 300 bang_swap 0; #X obj 63 58 inlet; #X obj 63 112 t b b; #X obj 112 172 outlet; #X obj 63 172 outlet; #X connect 0 0 1 0; #X connect 1 0 2 0; #X connect 1 1 3 0; #X restore 48 89 pd bang_swap; #X obj 117 115 outlet; #X obj 48 187 binbuf_helper \$0 \$1.foo foo 123 \, \;; #X connect 0 0 2 0; #X connect 2 0 4 0; #X connect 2 1 3 0; #X connect 4 0 1 0; tclpd-0.3.1/tests/binbuf.ref000066400000000000000000000003711433742306500157360ustar00rootroot00000000000000atomtype symbol; atomvalue binbuf_helper; atomtype dollar; atomvalue \$0; atomtype dollsym; atomvalue \$1.foo; atomtype symbol; atomvalue foo; atomtype float; atomvalue 123.0; atomtype comma; atomvalue \,; atomtype semi; atomvalue \;; tclpd-0.3.1/tests/binbuf_helper.tcl000066400000000000000000000007571433742306500173130ustar00rootroot00000000000000package require Tclpd 0.3.0 package require TclpdLib 0.20 proc binbuf_helper::constructor {self args} { pd::add_outlet $self list } proc binbuf_helper::0_bang {self} { set binbuf [pd::get_binbuf $self] foreach atom $binbuf { foreach {atomtype atomvalue} $atom break pd::outlet $self 0 list [list [list symbol atomtype] [list symbol $atomtype]] pd::outlet $self 0 list [list [list symbol atomvalue] [list symbol $atomvalue]] } } pd::class binbuf_helper tclpd-0.3.1/tests/helloworld.pd000066400000000000000000000003431433742306500164720ustar00rootroot00000000000000#N canvas 0 0 450 300 10; #X obj 42 54 inlet; #X obj 45 179 outlet; #X msg 69 115 hello world; #X obj 42 86 t b b; #X obj 91 179 outlet; #X connect 0 0 3 0; #X connect 2 0 1 0; #X connect 3 0 4 0; #X connect 3 1 2 0; tclpd-0.3.1/tests/helloworld.ref000066400000000000000000000000151433742306500166370ustar00rootroot00000000000000hello world; tclpd-0.3.1/tests/runtest.pd.in000066400000000000000000000006351433742306500164340ustar00rootroot00000000000000#N canvas 0 0 473 353 10; #X obj 188 235 textfile; #X obj 37 124 list prepend add; #X obj 37 150 list trim; #X msg 188 196 write %OUTPUT%; #X msg 161 274 \; pd quit; #X obj 37 37 loadbang; #X obj 37 63 %TESTCASE%; #X obj 161 124 t b b; #X connect 1 0 2 0; #X connect 2 0 0 0; #X connect 3 0 0 0; #X connect 5 0 6 0; #X connect 6 0 1 0; #X connect 6 1 7 0; #X connect 7 0 4 0; #X connect 7 1 3 0; tclpd-0.3.1/tests/runtest.sh000066400000000000000000000015341433742306500160350ustar00rootroot00000000000000if [ -z "$1" ]; then # no argument - run all tests found in current dir set -e for i in *.ref; do sh $0 "${i/.ref/}"; done exit 0 fi KEEP_OUTPUT=0 if [ "x$1" = "x-k" ]; then KEEP_OUTPUT=1 shift fi if [ ! -f "$1.pd" ]; then echo -e "error: $1.pd does not exist" 1>&2 exit 1 fi if [ ! -f "$1.ref" ]; then echo -e "error: $1.ref does not exist" 1>&2 exit 1 fi sed -e "s|%TESTCASE%|$1|" -e "s|%OUTPUT%|$1.out|" runtest.pd.in > "runtest-$1.pd" || exit 1 echo -n "Running test '$1'... "; "$PD_PATH/bin/pd" -noprefs -nogui -path .. -lib tclpd "runtest-$1.pd" diff --strip-trailing-cr "$1.ref" "$1.out" 1>/dev/null 2>&1 RESULT=$? if [ $RESULT -eq 0 ]; then echo "OK" else echo "FAIL" # show differences: diff -u --strip-trailing-cr "$1.ref" "$1.out" fi rm -f "runtest-$1.pd" if [ $KEEP_OUTPUT -eq 0 ]; then rm -f "$1.out" fi exit $RESULT