aboutsummaryrefslogtreecommitdiff
path: root/weightmap
diff options
context:
space:
mode:
Diffstat (limited to 'weightmap')
-rw-r--r--weightmap/COPYING290
-rw-r--r--weightmap/Changes7
-rw-r--r--weightmap/Makefile.am98
-rw-r--r--weightmap/README.cvs16
-rw-r--r--weightmap/README.pod40
-rwxr-xr-xweightmap/autogen.sh48
-rw-r--r--weightmap/config/Makefile.am66
-rw-r--r--weightmap/configure.in197
-rw-r--r--weightmap/src/Makefile.am135
-rw-r--r--weightmap/src/weightmap-help.pd74
-rw-r--r--weightmap/src/weightmap-test.pd135
-rw-r--r--weightmap/src/weightmap.c364
12 files changed, 1470 insertions, 0 deletions
diff --git a/weightmap/COPYING b/weightmap/COPYING
new file mode 100644
index 0000000..fa0bef4
--- /dev/null
+++ b/weightmap/COPYING
@@ -0,0 +1,290 @@
+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.
+
+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
diff --git a/weightmap/Changes b/weightmap/Changes
new file mode 100644
index 0000000..6e9711a
--- /dev/null
+++ b/weightmap/Changes
@@ -0,0 +1,7 @@
+Change log for PD external 'weightmap'
+
+v0.02 Thu, 02 Feb 2006 12:41:36 +0100
+ + automake'd version
+
+v0.01 Sat Apr 20 21:52:03 CEST 2002
+ + initial distributed version
diff --git a/weightmap/Makefile.am b/weightmap/Makefile.am
new file mode 100644
index 0000000..e1c1480
--- /dev/null
+++ b/weightmap/Makefile.am
@@ -0,0 +1,98 @@
+# File: ./Makefile.am
+# Package: weightmap
+# Description:
+# + top-level automake file
+#
+# Process this file with Automake to create Makefile.in.
+#-----------------------------------------------------------------------
+
+#-----------------------------------------------------------------------
+# Options & Subdirectories
+#-----------------------------------------------------------------------
+
+## --- automake options
+#AUTOMAKE_OPTIONS = foreign dist-bzip2 dist-zip
+AUTOMAKE_OPTIONS = foreign
+
+## --- recursion subdirectories
+SUBDIRS = config src
+
+## --- pseudo-deps for '.SUFFIXES'
+SUFFIXES = .pod .txt
+
+#-----------------------------------------------------------------------
+# Variables: cleanup
+#-----------------------------------------------------------------------
+## --- mostlyclean: built by 'make' & commonly rebuilt
+#MOSTLYCLEANFILES =
+
+## --- clean: built by 'make'
+#CLEANFILES =
+
+## --- distclean: built by 'configure'
+DISTCLEANFILES = \
+ config.log \
+ config.cache \
+ config.status
+
+## -- maintainerclean: built by maintainer / by hand
+MAINTAINERCLEANFILES = *~ \
+ $(PODS:.pod=.txt) \
+ Makefile Makefile.in \
+ aclocal.m4 \
+ configure \
+ install-sh \
+ stamp-h.in \
+ config.h.in
+
+maintainer-clean-local:
+ rm -rf autom4te.cache
+
+#CVSCLEAN_SUBDIRS = $(SUBDIRS)
+
+#CVSCLEANFILES = Makefile.in Makefile
+
+
+#-----------------------------------------------------------------------
+# Additional Variables & Rules: PODS
+#-----------------------------------------------------------------------
+PODS = README.pod
+
+.pod.txt:
+ pod2text $< $@
+
+all-local: $(PODS:.pod=.txt)
+
+#-----------------------------------------------------------------------
+# Variables: distribution
+#-----------------------------------------------------------------------
+
+## --- extra distribution files
+EXTRA_DIST = \
+ $(PODS:.pod=.txt) autogen.sh configure \
+ README.cvs COPYING
+
+## --- recursion subdirectories for 'make dist'
+#DIST_SUBDIRS = $(SUBDIRS)
+
+## --- dist-hook: when another 'Makefile.am' is overkill
+#DISTHOOK_DIRS = foo
+#DISTHOOK_FILES = foo/bar.txt foo/baz.txt
+#dist-hook:
+# for d in $(DISTHOOK_DIRS); do\
+# mkdir -p $(distdir)/$$d ;\
+# done
+# for f in $(DISTHOOK_FILES); do\
+# cp -p $(srcdir)/$$f $(distdir)/$$f ;\
+# done
+
+#dist-bz2: dist-bzip2 ;
+
+
+#-----------------------------------------------------------------------
+# Rules: cleanup
+#-----------------------------------------------------------------------
+.PHONY: cvsclean cvsclean-hook
+
+cvsclean: maintainer-clean ;
+
diff --git a/weightmap/README.cvs b/weightmap/README.cvs
new file mode 100644
index 0000000..96b1253
--- /dev/null
+++ b/weightmap/README.cvs
@@ -0,0 +1,16 @@
+To build from cvs, do the following:
+
+ ./autogen.sh
+ ./configure
+ make
+ make install
+
+You will need recent versions of GNU automake and
+autoconf in order to build from the CVS tree.
+
+NOTE: The README.txt file in the distribution
+is auto-generated from perl ".pod" format by
+the "pod2text" included in most perl distributions.
+
+marmosets,
+ Bryan
diff --git a/weightmap/README.pod b/weightmap/README.pod
new file mode 100644
index 0000000..a7cdde9
--- /dev/null
+++ b/weightmap/README.pod
@@ -0,0 +1,40 @@
+=pod
+
+README for weightmap
+
+Last updated for weightmap v0.02
+
+=head1 DESCRIPTION
+
+weightmap is a PD external which maps incoming probability
+values to integers, inspired in part by Yves Degoyon's 'probalizer' object.
+
+
+=head1 INSTALLATION
+
+Issue the following commands to the shell:
+
+ cd weightmap-X.YY (or wherever you extracted the distribution)
+ ./configure
+ make
+ make install
+
+=head1 ACKNOWLEDGEMENTS
+
+PD by Miller Puckette and others.
+
+probalizer object by Yves Degoyon.
+
+Ideas, black magic, and other nuggets of information drawn
+from code by Guenter Geiger, Larry Troxler, and iohannes m zmoelnig.
+
+=head1 BUGS
+
+It's a misleading name: higher input "weights" don't neccesarily
+correspond to higer stored "weights".
+
+Probably many more serious ones as well.
+
+=head1 AUTHOR
+
+Bryan Jurish E<lt>moocow@ling.uni-potsdam.deE<gt>
diff --git a/weightmap/autogen.sh b/weightmap/autogen.sh
new file mode 100755
index 0000000..845f276
--- /dev/null
+++ b/weightmap/autogen.sh
@@ -0,0 +1,48 @@
+#!/bin/sh
+
+#-----------------------------------------------------------------------
+# File: autogen.sh
+# Description:
+# + wrapper for m4 black-magic
+#-----------------------------------------------------------------------
+
+MY_ALDIRS="."
+MY_AHDIRS="."
+MY_AMDIRS="."
+MY_ACDIRS="."
+
+test -z "$ACLOCAL" && ACLOCAL=aclocal
+test -z "$AUTOHEADER" && AUTOHEADER=autoheader
+test -z "$AUTOMAKE" && AUTOMAKE=automake
+test -z "$AUTOCONF" && AUTOCONF=autoconf
+
+if test -n "$MY_ALDIRS"; then
+ for d in $MY_ALDIRS ; do
+ echo "(cd $d ; $ACLOCAL)"
+ (cd $d ; $ACLOCAL)
+ done
+fi
+
+if test -n "$MY_AHDIRS"; then
+ for d in $MY_AHDIRS ; do
+ echo "(cd $d ; $AUTOHEADER)"
+ (cd $d ; $AUTOHEADER)
+ done
+fi
+
+if test -n "$MY_AMDIRS"; then
+ for d in $MY_AMDIRS ; do
+ echo "(cd $d ; $AUTOMAKE -a)"
+ (cd $d ; $AUTOMAKE -a)
+ done
+fi
+
+if test -n "$MY_ACDIRS"; then
+ for d in $MY_ACDIRS ; do
+ echo "(cd $d ; $AUTOCONF)"
+ (cd $d ; $AUTOCONF)
+ done
+fi
+
+#echo "(./configure)"
+#./configure $*
diff --git a/weightmap/config/Makefile.am b/weightmap/config/Makefile.am
new file mode 100644
index 0000000..a2bb5d1
--- /dev/null
+++ b/weightmap/config/Makefile.am
@@ -0,0 +1,66 @@
+## File: config/Makefile.am
+## Package: weightmap
+## Description:
+## + automake file for 'config' package-subdir
+##
+## Process this file with Automake to create Makefile.in.
+##-----------------------------------------------------------------------
+
+##-----------------------------------------------------------------------
+## Variables: options
+##-----------------------------------------------------------------------
+
+##-----------------------------------------------------------------------
+## Variables: cleanup
+##-----------------------------------------------------------------------
+
+## --- mostlyclean: built by 'make' & commonly rebuilt
+#MOSTLYCLEANFILES =
+
+## --- clean: built by 'make'
+#CLEANFILES =
+
+## --- distclean: built by 'configure'
+#DISTCLEANFILES =
+
+## -- maintainerclean: built by maintainer / by hand
+MAINTAINERCLEANFILES = \
+ *~ .*~ \
+ compile Makefile Makefile.in \
+ config.guess \
+ config.sub \
+ depcomp \
+ install-sh \
+ ltmain.sh \
+ missing \
+ mkinstalldirs \
+ texinfo.tex \
+ ylwrap
+
+
+##-----------------------------------------------------------------------
+## Variables: distribution
+##-----------------------------------------------------------------------
+
+## --- extra distribution files
+EXTRA_DIST = \
+ Makefile.in \
+ depcomp \
+ install-sh \
+ mkinstalldirs \
+ missing
+
+# config.guess
+# config.sub
+# ltmain.sh
+# texinfo.tex
+
+## --- recursion subdirectories for 'make dist'
+#DIST_SUBDIRS = $(SUBDIRS)
+
+#-----------------------------------------------------------------------
+# Rules: cleanup
+#-----------------------------------------------------------------------
+.PHONY: cvsclean cvsclean-hook
+
+cvsclean: maintainer-clean ;
diff --git a/weightmap/configure.in b/weightmap/configure.in
new file mode 100644
index 0000000..958750b
--- /dev/null
+++ b/weightmap/configure.in
@@ -0,0 +1,197 @@
+dnl Process this file with autoconf to produce a configure script.
+dnl -- for a clean build, run: aclocal && autoheader && automake -a && autoconf
+AC_PREREQ(2.5)
+
+dnl Some handy macros
+define([THE_PACKAGE_NAME], [weightmap])
+define([THE_PACKAGE_VERSION], [0.01])
+define([THE_PACKAGE_AUTHOR], [moocow@ling.uni-potsdam.de])
+
+AC_INIT(THE_PACKAGE_NAME, THE_PACKAGE_VERSION, THE_PACKAGE_AUTHOR)
+
+dnl
+dnl source & aux
+dnl
+AC_CONFIG_AUX_DIR(config)
+
+dnl
+dnl save user's CFLAGS,CPPFLAGS
+dnl
+UCPPFLAGS="$CPPFLAGS"
+UCFLAGS="$CFLAGS"
+
+dnl
+dnl use automake
+dnl
+AM_INIT_AUTOMAKE(THE_PACKAGE_NAME, THE_PACKAGE_VERSION)
+
+dnl
+dnl use autoheader
+dnl
+AM_CONFIG_HEADER(src/config.h)
+
+
+dnl
+dnl Programs, prefix
+dnl
+AC_PROG_CC
+AC_PROG_INSTALL
+AC_PREFIX_DEFAULT(/usr/local)
+
+dnl
+dnl Substitutions
+dnl
+AC_SUBST(DEFS)
+AC_SUBST(AFLAGS)
+AC_SUBST(DFLAGS)
+AC_SUBST(IFLAGS)
+AC_SUBST(LFLAGS)
+AC_SUBST(OFLAGS)
+AC_SUBST(WFLAGS)
+AC_SUBST(LD)
+
+AC_SUBST(PDEXT)
+
+dnl version stuff (automatically exported?)
+AC_SUBST(PACKAGE_VERSION)
+AC_SUBST(PACKAGE_NAME)
+AC_SUBST(BUGREPORT)
+
+dnl other flags
+dnl AC_ISC_POSIX
+
+dnl Checks for header files.
+dnl AC_HEADER_STDC
+AC_CHECK_HEADERS([math.h],
+ [],
+ AC_MSG_WARN([-----------------------------------------------------------------])
+ AC_MSG_WARN([could not find standard C headers -- things may get ugly])
+ AC_MSG_WARN([-----------------------------------------------------------------]),
+ [/* nonempty includes: compile only */])
+
+
+dnl PD externals
+PD_OBJECT_EXTERNALS="weightmap\$(EXEEXT)"
+AC_SUBST(PD_OBJECT_EXTERNALS)
+
+
+dnl
+dnl pd-directory/ies
+dnl
+AC_ARG_WITH(pd-dir,
+ AC_HELP_STRING([--with-pd-dir=DIR], [PD base directory (default=PREFIX/pd)]),
+ [pddir="$withval"],
+ [pddir="\${prefix}/pd"])
+pddocdir="${pddir}/doc/5.reference"
+AC_SUBST(pddir)
+AC_SUBST(pddocdir)
+
+
+
+AC_ARG_WITH(pd-include,
+ AC_HELP_STRING([--with-pd-include=DIR], [PD include directory (default=NONE)]),
+ [pdincludedir="$withval"],
+ [pdincludedir=""])
+if test -n "$pdincludedir" ; then
+ IFLAGS="$IFLAGS -I$pdincludedir"
+fi
+AC_SUBST(pdincludedir)
+
+AC_ARG_WITH(pd-extdir,
+ AC_HELP_STRING([--with-pd-extdir=DIR], [Directory for PD externals (default=PDDIR/externs)]),
+ [pdexternsdir="$withval"],
+ [pdexternsdir="$pddir/externs"])
+AC_SUBST(pdexternsdir)
+
+dnl
+dnl Check for m_pd.h
+dnl
+CPPFLAGS="$CPPFLAGS $IFLAGS"
+AC_CHECK_HEADER(m_pd.h,[],
+ AC_MSG_WARN([-----------------------------------------------------------------])
+ AC_MSG_WARN([could not find PD header file 'm_pd.h' -- things might get ugly.])
+ AC_MSG_WARN([-----------------------------------------------------------------]),
+ [/* nonempty includes: compile only */])
+
+
+dnl
+dnl debug version?
+dnl
+AC_MSG_CHECKING([whether we are building a debug version])
+AC_ARG_ENABLE([debug],
+ AC_HELP_STRING([--enable-debug],[build debug version (default=no)]))
+if test "$enable_debug" == "yes" ; then
+ AC_MSG_RESULT(yes)
+ DEBUG="yes"
+ AC_DEFINE(WEIGHTMAP_DEBUG,1,
+ [Define this to include debugging code for the 'weightmap' external.])
+else
+ AC_MSG_RESULT(no)
+ DEBUG="no"
+fi
+AC_SUBST(DEBUG)
+
+
+
+dnl
+dnl machine-dependent variables
+dnl
+LD=ld
+if test `uname -s` = Linux;
+then
+ LFLAGS="-export_dynamic -shared"
+ if test "$DEBUG" == "no"; then
+ #OFLAGS="-O6 -funroll-loops -fomit-frame-pointer -finline-limit-10000000"
+ OFLAGS="-O6 -funroll-loops -fomit-frame-pointer"
+ else
+ OFLAGS="-g"
+ fi
+ PDEXT=pd_linux
+fi
+
+if test `uname -m` = alpha;
+then
+ AFLAGS="-mieee -mcpu=ev56";
+ OFLAGS="$CFLAGS"
+fi
+
+if test `uname -s` = IRIX64;
+then
+ LFLAGS="-n32 -DUNIX -DIRIX -DN32 -woff 1080,1064,1185 \
+ -OPT:roundoff=3 -OPT:IEEE_arithmetic=3 -OPT:cray_ivdep=true \
+ -shared -rdata_shared"
+ OFLAGS="$CFLAGS"
+ PDEXT=pd_irix6
+fi
+
+if test `uname -s` = IRIX32;
+then
+ LFLAGS="-o32 -DUNIX -DIRIX -O2 -shared -rdata_shared"
+ OFLAGS="$CFLAGS"
+ PDEXT=pd_irix5
+fi
+
+dnl
+dnl Flags for MacOSX, borrowed from pd-0.35-test16
+dnl
+if test `uname -s` = Darwin;
+then
+ LD=cc
+ LFLAGS="-bundle -undefined suppress -flat_namespace"
+ PDEXT=pd_darwin
+ DFLAGS="$DFLAGS -DMACOSX"
+
+ if test "$DEBUG" == "no"; then
+ OFLAGS="-O2"
+ else
+ OFLAGS="-g"
+ fi
+fi
+
+dnl
+dnl restore user's CFLAGS
+dnl
+CFLAGS="$UCFLAGS"
+CPPFLAGS="$UCPPFLAGS"
+
+AC_OUTPUT(config/Makefile src/Makefile Makefile)
diff --git a/weightmap/src/Makefile.am b/weightmap/src/Makefile.am
new file mode 100644
index 0000000..a7feb67
--- /dev/null
+++ b/weightmap/src/Makefile.am
@@ -0,0 +1,135 @@
+# File: ./src/Makefile.am
+# Package: weightmap
+# Description:
+# + src-level automake file
+#
+# Process this file with Automake to create Makefile.in.
+#-----------------------------------------------------------------------
+
+#-----------------------------------------------------------------------
+# Options & Subdirectories
+#-----------------------------------------------------------------------
+
+## --- recursion subdirectories
+#SUBDIRS =
+
+## --- pseudo-deps for '.SUFFIXES'
+SUFFIXES = .@PDEXT@
+
+#-----------------------------------------------------------------------
+# Flags and variables
+#-----------------------------------------------------------------------
+PDEXT = @PDEXT@
+EXEEXT = .@PDEXT@
+
+#-----------------------------------------------------------------------
+# pd externals (hacked _PROGRAMS target)
+#-----------------------------------------------------------------------
+
+## --- externals
+pdexterns_PROGRAMS = @PD_OBJECT_EXTERNALS@
+
+## --- possible externals
+EXTRA_PROGRAMS = \
+ weightmap
+
+## --- patches
+pdexterns_DATA =
+
+## --- documentation
+pddoc_DATA = weightmap-help.pd
+
+
+#-----------------------------------------------------------------------
+# sources
+#-----------------------------------------------------------------------
+
+weightmap_SOURCES = \
+ weightmap.c
+
+#-----------------------------------------------------------------------
+# external compilation : flags
+#-----------------------------------------------------------------------
+DEFS = @DEFS@
+AFLAGS = @AFLAGS@
+DFLAGS = @DFLAGS@
+IFLAGS = @IFLAGS@
+LFLAGS = @LFLAGS@
+OFLAGS = @OFLAGS@
+WFLAGS = -Wall -Winline
+
+#GLIB_IFLAGS = @GLIB_IFLAGS@
+#GLIB_LFLAGS = @GLIB_LFLAGS@
+
+AM_CPPFLAGS = $(IFLAGS) $(GLIB_IFLAGS) $(DFLAGS)
+AM_CFLAGS = $(OFLAGS) $(WFLAGS) $(AFLAGS)
+
+weightmap_LDFLAGS = $(LFLAGS)
+weightmap_LDADD = $(GLIB_LFLAGS)
+
+#-----------------------------------------------------------------------
+# Variables: cleanup
+#-----------------------------------------------------------------------
+## --- mostlyclean: built by 'make' & commonly rebuilt
+#MOSTLYCLEANFILES =
+
+## --- clean: built by 'make'
+CLEANFILES = *$(EXEEXT)
+
+## --- distclean: built by 'configure'
+DISTCLEANFILES = \
+ config.log \
+ config.cache \
+ config.status
+
+## -- maintainerclean: built by maintainer / by hand
+MAINTAINERCLEANFILES = *~ \
+ $(PODS:.pod=.txt) \
+ Makefile Makefile.in \
+ aclocal.m4 \
+ configure \
+ install-sh \
+ stamp-h.in \
+ config.h.in
+
+maintainer-clean-local:
+ rm -rf autom4te.cache
+
+#CVSCLEAN_SUBDIRS = $(SUBDIRS)
+
+#CVSCLEANFILES = Makefile.in Makefile
+
+
+#-----------------------------------------------------------------------
+# Variables: distribution
+#-----------------------------------------------------------------------
+
+## --- extra distribution files
+EXTRA_DIST = \
+ $(pddoc_DATA) \
+ $(pdexterns_DATA)
+
+## --- recursion subdirectories for 'make dist'
+DIST_SUBDIRS = $(SUBDIRS)
+
+## --- dist-hook: when another 'Makefile.am' is overkill
+#DISTHOOK_DIRS = foo
+#DISTHOOK_FILES = foo/bar.txt foo/baz.txt
+#dist-hook:
+# for d in $(DISTHOOK_DIRS); do\
+# mkdir -p $(distdir)/$$d ;\
+# done
+# for f in $(DISTHOOK_FILES); do\
+# cp -p $(srcdir)/$$f $(distdir)/$$f ;\
+# done
+
+#dist-bz2: dist-bzip2 ;
+
+
+#-----------------------------------------------------------------------
+# Rules: cleanup
+#-----------------------------------------------------------------------
+.PHONY: cvsclean cvsclean-hook
+
+cvsclean: maintainer-clean ;
+
diff --git a/weightmap/src/weightmap-help.pd b/weightmap/src/weightmap-help.pd
new file mode 100644
index 0000000..91709ff
--- /dev/null
+++ b/weightmap/src/weightmap-help.pd
@@ -0,0 +1,74 @@
+#N canvas 18 0 910 582 10;
+#X text 33 1 weightmap : map probabilities to associated integers;
+#X obj 114 364 print wmap_dump;
+#X obj 8 364 print wmap_out;
+#X obj 8 338 weightmap 3 100;
+#X text 463 79 SIZE : number of elements (integer);
+#X text 429 91 MAXWEIGHT : maximum expected input (float) [default=100]
+;
+#X text 395 65 weightmap SIZE [MAXWEIGHT];
+#X text 375 51 SYNTAX:;
+#X text 373 119 INLETS:;
+#X text 393 133 1 - floats ("weights" or "probabilities");
+#X text 421 147 OR messages;
+#X text 373 175 OUTLETS:;
+#X text 391 201 2 - miscellaneous output;
+#X text 391 187 1 - index (int) of stored weight matching input float
+;
+#X text 377 239 MESSAGES:;
+#X text 441 313 dump : dump the current weight-vector as a list to
+outlet-2;
+#X text 441 293 zero : resets all stored weights to zero;
+#X text 379 271 max MAXWEIGHT : change maximum expected input probability
+;
+#X msg 63 207 dump;
+#X msg 67 289 resize 4;
+#X msg 69 235 max 1;
+#X msg 69 257 max 100;
+#X msg 57 177 zero;
+#X msg 27 75 set 420 24 7;
+#X msg 33 97 set 50 25 25;
+#X text 127 85 set entire weight-vector;
+#X text 107 127 set selected weights;
+#X text 91 175 reset all weights;
+#X text 97 207 dump weights to 2nd outlet;
+#X text 113 239 adjust maximum input-value;
+#X text 131 297 adjust length of weight-vector;
+#X msg 67 311 resize 2;
+#X floatatom 14 44 5 0 0;
+#X text 63 43 output matching weight index;
+#X text 371 367 map IDX WEIGHT :;
+#X text 491 367 associate element IDX (int) of the stored weight-vector
+with weight WEIGHT (float). Multiple (index \, weight) pairs may also
+be specified.;
+#X text 393 335 set WEIGHTS :;
+#X text 600 556 Bryan Jurish <moocow@ling.uni-potsdam.de>;
+#X text 393 253 resize SIZE : resizes the weight-vector to SIZE elements
+;
+#X text 491 335 sets the stored weight-vector to WEIGHTS. possibly
+resizes the vector.;
+#X text 11 402 NOTES:;
+#X msg 41 125 map 1 42;
+#X msg 47 147 map 1 10 2 20 3 30;
+#X text 11 521 incoming floats are expected to be in the range 0..MAXWEIGHT
+\; floats which exceed MAXWEIGHT will cause the weightmap to outlet
+"0 "(zero) \, indicating a failed match.;
+#X text 11 418 weightmap stores a vector of "weights" -- arbitrary
+floats representing probability values \, which are matched against
+incoming floats to generate integers at the outlet. Greater input floats
+do not neccesarily correspond to greater stored "weights" \, but greater
+"weights" do cause their associated indices to be output more frequently
+for random input floats.;
+#X connect 3 0 2 0;
+#X connect 3 1 1 0;
+#X connect 18 0 3 0;
+#X connect 19 0 3 0;
+#X connect 20 0 3 0;
+#X connect 21 0 3 0;
+#X connect 22 0 3 0;
+#X connect 23 0 3 0;
+#X connect 24 0 3 0;
+#X connect 31 0 3 0;
+#X connect 32 0 3 0;
+#X connect 41 0 3 0;
+#X connect 42 0 3 0;
diff --git a/weightmap/src/weightmap-test.pd b/weightmap/src/weightmap-test.pd
new file mode 100644
index 0000000..41ca643
--- /dev/null
+++ b/weightmap/src/weightmap-test.pd
@@ -0,0 +1,135 @@
+#N canvas 33 18 810 430 10;
+#X obj 94 168 weightmap 3;
+#X msg 154 41 dump;
+#X obj 215 210 print wm_out2;
+#X msg 158 63 zero;
+#X msg 196 41 resize \$1;
+#X floatatom 195 12 5 0 0;
+#X floatatom 548 33 5 0 0;
+#X floatatom 598 33 5 0 0;
+#X obj 548 59 pack 0 0;
+#X text 549 116 bad input;
+#X msg 412 11 set 420 24 7;
+#X msg 549 82 map \$1 \$2;
+#X msg 549 132 map 0 1 1 2 2;
+#X floatatom 106 13 5 0 0;
+#N canvas 0 0 820 480 statistics 0;
+#X obj 146 16 inlet;
+#X msg 169 87 dump;
+#X msg 63 89 dump;
+#X obj 170 136 prependany del;
+#X obj 60 286 outlet;
+#X obj 274 210 pack 0 0;
+#X msg 453 127 0;
+#X obj 324 160 int;
+#X obj 274 86 t f b f b;
+#X obj 324 184 + 1;
+#X obj 306 10 maphash stats;
+#X obj 170 112 mapread stats;
+#X obj 62 116 mapread stats;
+#X obj 340 126 mapread stats;
+#X obj 274 242 mapwrite stats;
+#X text 569 30 Total;
+#X obj 570 121 int 0;
+#X msg 601 84 0;
+#X obj 616 121 + 1;
+#X obj 148 50 route dump clear;
+#X obj 62 153 unpack 0 0;
+#X obj 128 181 / 1;
+#X obj 62 233 pack 0 0 0;
+#X msg 61 258 \$1: \$2 = \$3%;
+#X obj 128 207 * 100;
+#X obj 540 191 int;
+#X msg 541 226 total = \$1;
+#X msg 519 167 bang;
+#X connect 0 0 19 0;
+#X connect 1 0 11 0;
+#X connect 2 0 12 0;
+#X connect 3 0 14 0;
+#X connect 5 0 14 0;
+#X connect 6 0 7 1;
+#X connect 7 0 9 0;
+#X connect 8 0 5 0;
+#X connect 8 1 7 0;
+#X connect 8 2 13 0;
+#X connect 8 3 6 0;
+#X connect 8 3 16 0;
+#X connect 9 0 5 1;
+#X connect 11 0 3 0;
+#X connect 12 0 20 0;
+#X connect 13 0 7 1;
+#X connect 16 0 18 0;
+#X connect 17 0 16 1;
+#X connect 17 0 25 1;
+#X connect 18 0 16 1;
+#X connect 18 0 25 1;
+#X connect 19 0 27 0;
+#X connect 19 0 2 0;
+#X connect 19 1 1 0;
+#X connect 19 1 17 0;
+#X connect 19 2 8 0;
+#X connect 20 0 22 0;
+#X connect 20 1 21 0;
+#X connect 20 1 22 1;
+#X connect 21 0 24 0;
+#X connect 22 0 23 0;
+#X connect 23 0 4 0;
+#X connect 24 0 22 2;
+#X connect 25 0 26 0;
+#X connect 25 0 21 1;
+#X connect 26 0 4 0;
+#X connect 27 0 25 0;
+#X restore 224 293 pd statistics;
+#X msg 261 260 dump;
+#X msg 303 260 clear;
+#X obj 224 325 print stats;
+#X obj 24 13 tgl 15 0 empty empty empty 20 8 0 8 -262144 -1 -1 0 1
+;
+#X obj 24 57 random 100;
+#X floatatom 49 12 5 0 0;
+#X obj 335 294 print -----;
+#X msg 412 37 set 10 20 30 40;
+#X msg 68 238 0;
+#X msg 70 268 1;
+#X obj 24 35 metro 1;
+#X msg 412 61 set 50 25 25;
+#X floatatom 285 12 5 0 0;
+#X msg 286 41 max \$1;
+#X msg 410 85 set 2 1 1;
+#X obj 6 101 tgl 15 0 empty empty empty 20 8 0 8 -262144 -1 -1 0 1
+;
+#X obj 6 145 random 100;
+#X obj 6 123 metro 1;
+#X obj 15 168 / 100;
+#X connect 0 0 14 0;
+#X connect 0 1 2 0;
+#X connect 1 0 0 0;
+#X connect 3 0 0 0;
+#X connect 4 0 0 0;
+#X connect 5 0 4 0;
+#X connect 6 0 8 0;
+#X connect 7 0 8 1;
+#X connect 8 0 11 0;
+#X connect 10 0 0 0;
+#X connect 11 0 0 0;
+#X connect 12 0 0 0;
+#X connect 13 0 0 0;
+#X connect 14 0 17 0;
+#X connect 15 0 21 0;
+#X connect 15 0 14 0;
+#X connect 16 0 14 0;
+#X connect 18 0 25 0;
+#X connect 19 0 0 0;
+#X connect 20 0 25 1;
+#X connect 22 0 0 0;
+#X connect 23 0 14 0;
+#X connect 24 0 14 0;
+#X connect 25 0 19 0;
+#X connect 26 0 0 0;
+#X connect 27 0 28 0;
+#X connect 28 0 0 0;
+#X connect 29 0 0 0;
+#X connect 30 0 32 0;
+#X connect 31 0 33 0;
+#X connect 32 0 31 0;
+#X connect 33 0 0 0;
diff --git a/weightmap/src/weightmap.c b/weightmap/src/weightmap.c
new file mode 100644
index 0000000..1406ddc
--- /dev/null
+++ b/weightmap/src/weightmap.c
@@ -0,0 +1,364 @@
+/* -*- Mode: C -*- */
+/*=============================================================================*\
+ * File: weightmap.c
+ * Author: Bryan Jurish <moocow@ling.uni-potsdam.de>
+ * Description: gui-less finer-grained probability-to-integer-map for PD
+ *
+ * - inspired in part by Yves Degoyon's 'probalizer' object
+ *
+
+ *
+ * Copyright (c) 2002-2006 Bryan Jurish.
+ *
+ * For information on usage and redistribution, and for a DISCLAIMER OF ALL
+ * WARRANTIES, see the file, "LICENSE.txt," in this distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * See file LICENSE for further informations on licensing terms.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *=============================================================================*/
+
+
+#include <m_pd.h>
+
+/* black magic */
+#ifdef NT
+#pragma warning( disable : 4244 )
+#pragma warning( disable : 4305 )
+#endif
+
+#include <math.h>
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+/*--------------------------------------------------------------------
+ * DEBUG
+ *--------------------------------------------------------------------*/
+//#define WEIGHTMAP_DEBUG 1
+
+
+/*=====================================================================
+ * Constants
+ *=====================================================================*/
+#define DEFAULT_WEIGHT_VALUE 0
+#define DEFAULT_WEIGHT_MAX 100
+
+/*=====================================================================
+ * Structures and Types
+ *=====================================================================*/
+
+static char *weightmap_banner = "weightmap version %s by Bryan Jurish : map probabilities to associated integers";
+
+static t_class *weightmap_class;
+
+typedef struct _weightmap
+{
+ t_object x_obj; /* black magic (probably inheritance-related) */
+ t_float x_wmax; /* maximum expected input weight */
+ t_int x_nvalues; /* number of stored values */
+ t_float *x_weights; /* weight of each event (0..x_wmax) */
+ t_float x_wsum; /* sum of all weights (internal use only) */
+ t_outlet *x_dumpoutlet; /* outlet for 'dump' messages */
+} t_weightmap;
+
+
+
+/*--------------------------------------------------------------------
+ * FLOAT : the guts : handle incoming weights
+ *--------------------------------------------------------------------*/
+void weightmap_float(t_weightmap *x, t_floatarg f) {
+ int i;
+ float wt;
+
+ // scale weight from (0..x->x_wmax) to (0..x->x_wsum)
+ wt = (f * x->x_wsum) / x->x_wmax;
+
+#ifdef WEIGHTMAP_DEBUG
+ post("weightmap_debug : float : rescale(%f : 0..%f) = %f : 0..%f", f, x->x_wmax, wt, x->x_wsum);
+#endif
+
+ // find match
+ for (i = 0; i < x->x_nvalues; i++) {
+ wt -= x->x_weights[i];
+ if (wt < 0) {
+ // end of search : outlet current index (counting from 1, for compatibility)
+ outlet_float(x->x_obj.ob_outlet, i+1);
+ return;
+ }
+ }
+ // no matching value found: ouput 0
+ outlet_float(x->x_obj.ob_outlet, 0);
+}
+
+
+/*--------------------------------------------------------------------
+ * map : set selected values (no resize)
+ *--------------------------------------------------------------------*/
+void weightmap_map(t_weightmap *x, t_symbol *s, int argc, t_atom *argv) {
+ int i, idx;
+ float wt;
+
+#ifdef WEIGHTMAP_DEBUG
+ post("weightmap_debug : map : argc=%d", argc);
+#endif
+
+ for (i = 0; i < argc; i += 2) {
+ // get index
+ idx = atom_getint(argv+i);
+ if (idx <= 0 || idx > x->x_nvalues) {
+ // sanity check: index-range
+ error("weightmap : map : index out of range : %d", idx);
+ continue;
+ }
+ idx--;
+
+ // get weight-value
+ wt = atom_getfloatarg(i+1, argc, argv);
+
+ // adjust sum
+ x->x_wsum += wt - x->x_weights[idx];
+
+ // assign weight
+ x->x_weights[idx] = wt;
+ }
+}
+
+/*--------------------------------------------------------------------
+ * zero : zero the weight-vector
+ *--------------------------------------------------------------------*/
+void weightmap_zero(t_weightmap *x) {
+ int i;
+ // zero all weights
+ for (i = 0; i < x->x_nvalues; i++) {
+ *(x->x_weights+i) = 0;
+ }
+ // reset sum
+ x->x_wsum = 0;
+}
+
+
+/*--------------------------------------------------------------------
+ * set : set the entire weight-vector in one go (with possible resize)
+ *--------------------------------------------------------------------*/
+void weightmap_set(t_weightmap *x, t_symbol *s, int argc, t_atom *argv) {
+ int i;
+ float wt;
+
+ if (x->x_nvalues != argc) {
+ // set number of elements
+ x->x_nvalues = argc;
+ if ( x->x_nvalues < 1 ) x->x_nvalues = 1;
+
+ // (re-)allocate weights
+ if (x->x_weights) {
+ freebytes(x->x_weights, x->x_nvalues*sizeof(t_float));
+ }
+ x->x_weights = (t_float *)getbytes(x->x_nvalues*sizeof(t_float));
+ if (!x->x_weights) {
+ error("weightmap : failed to allocate new weight vector");
+ return;
+ }
+ }
+
+ // zero sum
+ x->x_wsum = 0;
+
+ // assign new weight-vector
+ for (i = 0; i < x->x_nvalues; i++) {
+ if (i >= argc) {
+ // sanity check: existence
+ x->x_weights[i] = DEFAULT_WEIGHT_VALUE;
+ }
+ else {
+ // normal case: set weight value
+ x->x_weights[i] = atom_getfloat(argv);
+ }
+ x->x_wsum += x->x_weights[i];
+ argv++;
+ }
+}
+
+/*--------------------------------------------------------------------
+ * resize : reset number of values & re-allocate
+ *--------------------------------------------------------------------*/
+void weightmap_resize(t_weightmap *x, t_floatarg f) {
+ int i;
+ t_int old_nvalues = x->x_nvalues;
+ t_float *old_weights = x->x_weights;
+
+#ifdef WEIGHTMAP_DEBUG
+ post("weightmap_debug : resize : size=%d", (int)f);
+#endif
+
+ // reset number of elements
+ x->x_nvalues = f;
+ if ( x->x_nvalues < 1 ) x->x_nvalues = 1;
+
+ // allocate new weight-vector
+ x->x_weights = (t_float *)getbytes(x->x_nvalues*sizeof(t_float));
+ if (!x->x_weights) {
+ error("weightmap : resize : failed to allocate new weight vector");
+ return;
+ }
+
+ // zero sum
+ x->x_wsum = 0;
+
+ // copy old values
+ for (i = 0; i < x->x_nvalues; i++) {
+ if (i >= old_nvalues) {
+ x->x_weights[i] = DEFAULT_WEIGHT_VALUE;
+ } else {
+ x->x_weights[i] = old_weights[i];
+ x->x_wsum += old_weights[i];
+ }
+ }
+
+ // free old vector
+ freebytes(old_weights, old_nvalues*sizeof(t_float));
+}
+
+
+/*--------------------------------------------------------------------
+ * max : set maximum expected input-weight
+ *--------------------------------------------------------------------*/
+void weightmap_max(t_weightmap *x, t_floatarg f) {
+#ifdef WEIGHTMAP_DEBUG
+ post("weightmap_debug : max : max=%f", f);
+#endif
+ if (f > 0) {
+ x->x_wmax = f;
+ } else {
+ error("weightmap : invalid maximum weight : %f", f);
+ }
+}
+
+
+/*--------------------------------------------------------------------
+ * dump : outputs weight-vector as a list
+ *--------------------------------------------------------------------*/
+void weightmap_dump(t_weightmap *x) {
+ int i;
+ float f;
+ t_atom *dumpus;
+
+#ifdef WEIGHTMAP_DEBUG
+ post("weightmap_debug : dump : sum=%f, max=%f", x->x_wsum, x->x_wmax);
+#endif
+
+ // allocate dump-list
+ dumpus = (t_atom *)getbytes(x->x_nvalues*sizeof(t_atom));
+ if (!dumpus) {
+ error("weightmap : failed to allocate dump list");
+ return;
+ }
+
+ // populate dump-list
+ for (i = 0; i < x->x_nvalues; i++) {
+ f = x->x_weights[i];
+ SETFLOAT(dumpus+i, f);
+ }
+
+ // output dump-list
+ outlet_list(x->x_dumpoutlet,
+ &s_list,
+ x->x_nvalues,
+ dumpus);
+
+}
+
+
+/*--------------------------------------------------------------------
+ * new SIZE
+ *--------------------------------------------------------------------*/
+static void *weightmap_new(t_floatarg f, t_floatarg max)
+{
+ t_weightmap *x;
+ int i;
+
+ x = (t_weightmap *)pd_new(weightmap_class);
+
+ // create float (index) outlet
+ outlet_new(&x->x_obj, &s_float);
+ // create list (dump) outlet
+ x->x_dumpoutlet = outlet_new(&x->x_obj, &s_list);
+
+ // set number of elements
+ x->x_nvalues = f;
+ if ( x->x_nvalues < 1 ) x->x_nvalues = 1;
+
+ // set maximum expected input probability
+ x->x_wmax = max;
+ if (!x->x_wmax) x->x_wmax = DEFAULT_WEIGHT_MAX;
+
+ // allocate weight-vector
+ x->x_weights = (t_float *)getbytes(x->x_nvalues*sizeof(t_float));
+ if (!x->x_weights) {
+ error("weightmap : failed to allocate weight vector");
+ return NULL;
+ }
+
+ // initialize weights
+ for (i = 0; i < x->x_nvalues; i++) {
+ *(x->x_weights+i) = DEFAULT_WEIGHT_VALUE;
+ }
+ // initialize sum
+ x->x_wsum = DEFAULT_WEIGHT_VALUE * x->x_nvalues;
+
+#ifdef WEIGHTMAP_DEBUG
+ post("weightmap_debug : create : nvalues=%d , wmax=%f", x->x_nvalues, x->x_wmax);
+#endif
+
+ return (void *)x;
+}
+
+/*--------------------------------------------------------------------
+ * free
+ *--------------------------------------------------------------------*/
+static void weightmap_free(t_weightmap *x) {
+#ifdef WEIGHTMAP_DEBUG
+ post("weightmap_debug : free");
+#endif
+ if (x->x_weights) {
+ freebytes(x->x_weights, x->x_nvalues*sizeof(t_float));
+ }
+}
+
+/*--------------------------------------------------------------------
+ * setup
+ *--------------------------------------------------------------------*/
+void weightmap_setup(void) {
+ post(weightmap_banner, PACKAGE_VERSION);
+ weightmap_class = class_new(gensym("weightmap"), /* name */
+ (t_newmethod)weightmap_new, /* newmethod */
+ (t_method)weightmap_free, /* freemethod */
+ sizeof(t_weightmap), /* size */
+ 0, /* flags */
+ A_DEFFLOAT, /* ARGLIST: arg1 (size) */
+ A_DEFFLOAT, /* ARGLIST: arg2 (max) */
+ 0); /* ARGLIST: END */
+
+ class_addmethod(weightmap_class, (t_method)weightmap_float, &s_float, A_FLOAT, 0);
+ class_addmethod(weightmap_class, (t_method)weightmap_map, gensym("map"), A_GIMME, 0);
+ class_addmethod(weightmap_class, (t_method)weightmap_zero, gensym("zero"), 0);
+ class_addmethod(weightmap_class, (t_method)weightmap_set, gensym("set"), A_GIMME, 0);
+ class_addmethod(weightmap_class, (t_method)weightmap_resize, gensym("resize"), A_DEFFLOAT, 0);
+ class_addmethod(weightmap_class, (t_method)weightmap_max, gensym("max"), A_DEFFLOAT, 0);
+ class_addmethod(weightmap_class, (t_method)weightmap_dump, gensym("dump"), 0);
+
+ class_sethelpsymbol(weightmap_class, gensym("weightmap-help.pd"));
+}