summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--apps/plugins/CATEGORIES1
-rw-r--r--apps/plugins/pdbox/PDa/CHANGELOG.PDa118
-rw-r--r--apps/plugins/pdbox/PDa/LICENSE.txt60
-rw-r--r--apps/plugins/pdbox/PDa/README.PDa106
-rw-r--r--apps/plugins/pdbox/PDa/README.txt88
-rw-r--r--apps/plugins/pdbox/PDa/extra/OSC-client.h376
-rw-r--r--apps/plugins/pdbox/PDa/extra/OSC.pd26
-rw-r--r--apps/plugins/pdbox/PDa/extra/OSCroute.c1204
-rw-r--r--apps/plugins/pdbox/PDa/extra/README24
-rw-r--r--apps/plugins/pdbox/PDa/extra/bandpass-help.pd34
-rw-r--r--apps/plugins/pdbox/PDa/extra/bandpass.c172
-rw-r--r--apps/plugins/pdbox/PDa/extra/dumpOSC.c1998
-rw-r--r--apps/plugins/pdbox/PDa/extra/equalizer.c178
-rw-r--r--apps/plugins/pdbox/PDa/extra/fatom.h970
-rw-r--r--apps/plugins/pdbox/PDa/extra/filters.h148
-rw-r--r--apps/plugins/pdbox/PDa/extra/g_canvas.h1204
-rw-r--r--apps/plugins/pdbox/PDa/extra/gcanvas-help.pd16
-rw-r--r--apps/plugins/pdbox/PDa/extra/gcanvas.c758
-rw-r--r--apps/plugins/pdbox/PDa/extra/highpass.c174
-rw-r--r--apps/plugins/pdbox/PDa/extra/highshelf.c180
-rw-r--r--apps/plugins/pdbox/PDa/extra/hlshelf.c452
-rw-r--r--apps/plugins/pdbox/PDa/extra/image.c434
-rw-r--r--apps/plugins/pdbox/PDa/extra/lowpass.c178
-rw-r--r--apps/plugins/pdbox/PDa/extra/lowshelf.c182
-rw-r--r--apps/plugins/pdbox/PDa/extra/m_pd.h1300
-rw-r--r--apps/plugins/pdbox/PDa/extra/makefile66
-rw-r--r--apps/plugins/pdbox/PDa/extra/moog~.c366
-rw-r--r--apps/plugins/pdbox/PDa/extra/notch.c178
-rw-r--r--apps/plugins/pdbox/PDa/extra/s_stuff.h430
-rw-r--r--apps/plugins/pdbox/PDa/extra/sendOSC.c2922
-rw-r--r--apps/plugins/pdbox/PDa/extra/sformat.h110
-rw-r--r--apps/plugins/pdbox/PDa/extra/shell.c624
-rw-r--r--apps/plugins/pdbox/PDa/extra/slider.c106
-rw-r--r--apps/plugins/pdbox/PDa/extra/sliderh.c126
-rw-r--r--apps/plugins/pdbox/PDa/extra/test-clip.pd26
-rw-r--r--apps/plugins/pdbox/PDa/extra/test-vcf.pd36
-rw-r--r--apps/plugins/pdbox/PDa/extra/zerox~.c114
-rw-r--r--apps/plugins/pdbox/PDa/intern/biquad~.c252
-rw-r--r--apps/plugins/pdbox/PDa/intern/bp~.c276
-rw-r--r--apps/plugins/pdbox/PDa/intern/clip~.c116
-rw-r--r--apps/plugins/pdbox/PDa/intern/cos_table.h6
-rw-r--r--apps/plugins/pdbox/PDa/intern/cos~.c122
-rw-r--r--apps/plugins/pdbox/PDa/intern/dbtopow~.c104
-rw-r--r--apps/plugins/pdbox/PDa/intern/dbtorms~.c106
-rw-r--r--apps/plugins/pdbox/PDa/intern/delay.h84
-rw-r--r--apps/plugins/pdbox/PDa/intern/delread~.c200
-rw-r--r--apps/plugins/pdbox/PDa/intern/delwrite~.c168
-rw-r--r--apps/plugins/pdbox/PDa/intern/env~.c254
-rw-r--r--apps/plugins/pdbox/PDa/intern/ftom~.c88
-rw-r--r--apps/plugins/pdbox/PDa/intern/hip~.c184
-rw-r--r--apps/plugins/pdbox/PDa/intern/intern_setup.c94
-rw-r--r--apps/plugins/pdbox/PDa/intern/line~.c202
-rw-r--r--apps/plugins/pdbox/PDa/intern/lop~.c180
-rw-r--r--apps/plugins/pdbox/PDa/intern/makefile48
-rw-r--r--apps/plugins/pdbox/PDa/intern/mtof~.c98
-rw-r--r--apps/plugins/pdbox/PDa/intern/noise~.c110
-rw-r--r--apps/plugins/pdbox/PDa/intern/osc~.c174
-rw-r--r--apps/plugins/pdbox/PDa/intern/phasor~.c138
-rw-r--r--apps/plugins/pdbox/PDa/intern/powtodb~.c106
-rw-r--r--apps/plugins/pdbox/PDa/intern/print~.c156
-rw-r--r--apps/plugins/pdbox/PDa/intern/rmstodb~.c104
-rw-r--r--apps/plugins/pdbox/PDa/intern/rsqrt~.c210
-rw-r--r--apps/plugins/pdbox/PDa/intern/samphold~.c150
-rw-r--r--apps/plugins/pdbox/PDa/intern/sformat.h110
-rw-r--r--apps/plugins/pdbox/PDa/intern/sfread~.c576
-rw-r--r--apps/plugins/pdbox/PDa/intern/sfwrite~.c480
-rw-r--r--apps/plugins/pdbox/PDa/intern/sig~.c134
-rw-r--r--apps/plugins/pdbox/PDa/intern/snapshot~.c114
-rw-r--r--apps/plugins/pdbox/PDa/intern/sqrt~.c154
-rw-r--r--apps/plugins/pdbox/PDa/intern/tabosc4~.c264
-rw-r--r--apps/plugins/pdbox/PDa/intern/tabplay~.c264
-rw-r--r--apps/plugins/pdbox/PDa/intern/tabread.c104
-rw-r--r--apps/plugins/pdbox/PDa/intern/tabread4~.c210
-rw-r--r--apps/plugins/pdbox/PDa/intern/tabread~.c194
-rw-r--r--apps/plugins/pdbox/PDa/intern/tabreceive~.c122
-rw-r--r--apps/plugins/pdbox/PDa/intern/tabsend~.c196
-rw-r--r--apps/plugins/pdbox/PDa/intern/tabwrite.c168
-rw-r--r--apps/plugins/pdbox/PDa/intern/tabwrite~.c264
-rw-r--r--apps/plugins/pdbox/PDa/intern/threshold~.c270
-rw-r--r--apps/plugins/pdbox/PDa/intern/vcf~.c238
-rw-r--r--apps/plugins/pdbox/PDa/intern/vd~.c184
-rw-r--r--apps/plugins/pdbox/PDa/intern/vline~.c368
-rw-r--r--apps/plugins/pdbox/PDa/intern/vsnapshot~.c176
-rw-r--r--apps/plugins/pdbox/PDa/intern/wrap~.c104
-rw-r--r--apps/plugins/pdbox/PDa/src/build.ipod10
-rw-r--r--apps/plugins/pdbox/PDa/src/d_arithmetic.c1684
-rw-r--r--apps/plugins/pdbox/PDa/src/d_array.c2148
-rw-r--r--apps/plugins/pdbox/PDa/src/d_ctl.c1568
-rw-r--r--apps/plugins/pdbox/PDa/src/d_dac.c368
-rw-r--r--apps/plugins/pdbox/PDa/src/d_delay.c638
-rw-r--r--apps/plugins/pdbox/PDa/src/d_fft.c688
-rw-r--r--apps/plugins/pdbox/PDa/src/d_fftroutine.c2002
-rw-r--r--apps/plugins/pdbox/PDa/src/d_filter.c1094
-rw-r--r--apps/plugins/pdbox/PDa/src/d_global.c616
-rw-r--r--apps/plugins/pdbox/PDa/src/d_imayer_fft.c1032
-rw-r--r--apps/plugins/pdbox/PDa/src/d_imayer_tables.h100
-rw-r--r--apps/plugins/pdbox/PDa/src/d_math.c1146
-rw-r--r--apps/plugins/pdbox/PDa/src/d_mayer_fft.c838
-rw-r--r--apps/plugins/pdbox/PDa/src/d_misc.c524
-rw-r--r--apps/plugins/pdbox/PDa/src/d_osc.c1070
-rw-r--r--apps/plugins/pdbox/PDa/src/d_resample.c450
-rw-r--r--apps/plugins/pdbox/PDa/src/d_soundfile.c4734
-rw-r--r--apps/plugins/pdbox/PDa/src/d_ugen.c2252
-rw-r--r--apps/plugins/pdbox/PDa/src/delme.pd16
-rw-r--r--apps/plugins/pdbox/PDa/src/g_all_guis.c1324
-rw-r--r--apps/plugins/pdbox/PDa/src/g_all_guis.h658
-rw-r--r--apps/plugins/pdbox/PDa/src/g_array.c2734
-rw-r--r--apps/plugins/pdbox/PDa/src/g_bang.c1108
-rw-r--r--apps/plugins/pdbox/PDa/src/g_canvas.c2952
-rw-r--r--apps/plugins/pdbox/PDa/src/g_canvas.h1204
-rw-r--r--apps/plugins/pdbox/PDa/src/g_editor.c4548
-rw-r--r--apps/plugins/pdbox/PDa/src/g_graph.c2224
-rw-r--r--apps/plugins/pdbox/PDa/src/g_guiconnect.c188
-rw-r--r--apps/plugins/pdbox/PDa/src/g_hdial.c1470
-rw-r--r--apps/plugins/pdbox/PDa/src/g_hslider.c1308
-rw-r--r--apps/plugins/pdbox/PDa/src/g_io.c1224
-rw-r--r--apps/plugins/pdbox/PDa/src/g_mycanvas.c770
-rw-r--r--apps/plugins/pdbox/PDa/src/g_numbox.c1814
-rw-r--r--apps/plugins/pdbox/PDa/src/g_readwrite.c1446
-rw-r--r--apps/plugins/pdbox/PDa/src/g_rtext.c972
-rw-r--r--apps/plugins/pdbox/PDa/src/g_scalar.c802
-rw-r--r--apps/plugins/pdbox/PDa/src/g_template.c3358
-rw-r--r--apps/plugins/pdbox/PDa/src/g_text.c2632
-rw-r--r--apps/plugins/pdbox/PDa/src/g_toggle.c948
-rw-r--r--apps/plugins/pdbox/PDa/src/g_traversal.c2168
-rw-r--r--apps/plugins/pdbox/PDa/src/g_vdial.c1432
-rw-r--r--apps/plugins/pdbox/PDa/src/g_vslider.c1254
-rw-r--r--apps/plugins/pdbox/PDa/src/g_vumeter.c1426
-rw-r--r--apps/plugins/pdbox/PDa/src/m_atom.c258
-rw-r--r--apps/plugins/pdbox/PDa/src/m_binbuf.c2438
-rw-r--r--apps/plugins/pdbox/PDa/src/m_class.c1648
-rw-r--r--apps/plugins/pdbox/PDa/src/m_conf.c202
-rw-r--r--apps/plugins/pdbox/PDa/src/m_fixed.c252
-rw-r--r--apps/plugins/pdbox/PDa/src/m_fixed.h110
-rw-r--r--apps/plugins/pdbox/PDa/src/m_glob.c210
-rw-r--r--apps/plugins/pdbox/PDa/src/m_imp.h156
-rw-r--r--apps/plugins/pdbox/PDa/src/m_memory.c178
-rw-r--r--apps/plugins/pdbox/PDa/src/m_obj.c1394
-rw-r--r--apps/plugins/pdbox/PDa/src/m_pd.c612
-rw-r--r--apps/plugins/pdbox/PDa/src/m_pd.h1300
-rw-r--r--apps/plugins/pdbox/PDa/src/m_sched.c1162
-rw-r--r--apps/plugins/pdbox/PDa/src/makecostab.c50
-rw-r--r--apps/plugins/pdbox/PDa/src/makefile354
-rw-r--r--apps/plugins/pdbox/PDa/src/s_audio.c1746
-rw-r--r--apps/plugins/pdbox/PDa/src/s_audio_alsa.c1890
-rw-r--r--apps/plugins/pdbox/PDa/src/s_audio_mmio.c1588
-rw-r--r--apps/plugins/pdbox/PDa/src/s_audio_oss.c1688
-rw-r--r--apps/plugins/pdbox/PDa/src/s_audio_pa.c584
-rw-r--r--apps/plugins/pdbox/PDa/src/s_entry.c102
-rw-r--r--apps/plugins/pdbox/PDa/src/s_file.c110
-rw-r--r--apps/plugins/pdbox/PDa/src/s_inter.c2000
-rw-r--r--apps/plugins/pdbox/PDa/src/s_loader.c338
-rw-r--r--apps/plugins/pdbox/PDa/src/s_main.c1676
-rw-r--r--apps/plugins/pdbox/PDa/src/s_midi.c1282
-rw-r--r--apps/plugins/pdbox/PDa/src/s_midi_oss.c718
-rw-r--r--apps/plugins/pdbox/PDa/src/s_midi_pm.c332
-rw-r--r--apps/plugins/pdbox/PDa/src/s_midi_sgi.c376
-rw-r--r--apps/plugins/pdbox/PDa/src/s_path.c820
-rw-r--r--apps/plugins/pdbox/PDa/src/s_print.c300
-rw-r--r--apps/plugins/pdbox/PDa/src/s_stuff.h430
-rw-r--r--apps/plugins/pdbox/PDa/src/s_watchdog.c94
-rw-r--r--apps/plugins/pdbox/PDa/src/t_main.c240
-rw-r--r--apps/plugins/pdbox/PDa/src/t_tk.h20
-rw-r--r--apps/plugins/pdbox/PDa/src/t_tkcmd.c796
-rw-r--r--apps/plugins/pdbox/PDa/src/u_main.tk6734
-rw-r--r--apps/plugins/pdbox/PDa/src/u_pdreceive.c650
-rw-r--r--apps/plugins/pdbox/PDa/src/u_pdsend.c314
-rw-r--r--apps/plugins/pdbox/PDa/src/x_acoustics.c386
-rw-r--r--apps/plugins/pdbox/PDa/src/x_arithmetic.c1792
-rw-r--r--apps/plugins/pdbox/PDa/src/x_connective.c2904
-rw-r--r--apps/plugins/pdbox/PDa/src/x_gui.c754
-rw-r--r--apps/plugins/pdbox/PDa/src/x_interface.c156
-rw-r--r--apps/plugins/pdbox/PDa/src/x_midi.c2626
-rw-r--r--apps/plugins/pdbox/PDa/src/x_misc.c642
-rw-r--r--apps/plugins/pdbox/PDa/src/x_net.c726
-rw-r--r--apps/plugins/pdbox/PDa/src/x_qlist.c690
-rw-r--r--apps/plugins/pdbox/PDa/src/x_time.c1040
-rw-r--r--apps/plugins/pdbox/README.rockbox16
-rw-r--r--apps/plugins/pdbox/SOURCES330
-rw-r--r--apps/plugins/pdbox/dbestfit-3.3/CHANGES24
-rw-r--r--apps/plugins/pdbox/dbestfit-3.3/FILES30
-rw-r--r--apps/plugins/pdbox/dbestfit-3.3/Makefile76
-rw-r--r--apps/plugins/pdbox/dbestfit-3.3/Malloc.c402
-rw-r--r--apps/plugins/pdbox/dbestfit-3.3/README44
-rw-r--r--apps/plugins/pdbox/dbestfit-3.3/bmalloc.c740
-rw-r--r--apps/plugins/pdbox/dbestfit-3.3/bmalloc.h12
-rw-r--r--apps/plugins/pdbox/dbestfit-3.3/bysize.c848
-rw-r--r--apps/plugins/pdbox/dbestfit-3.3/bysize.h8
-rw-r--r--apps/plugins/pdbox/dbestfit-3.3/dmalloc.c1380
-rw-r--r--apps/plugins/pdbox/dbestfit-3.3/dmalloc.h16
-rw-r--r--apps/plugins/pdbox/dbestfit-3.3/dmytest.c276
-rw-r--r--apps/plugins/pdbox/dbestfit-3.3/malloc.man190
-rw-r--r--apps/plugins/pdbox/dbestfit-3.3/mytest.c140
-rw-r--r--apps/plugins/pdbox/dbestfit-3.3/thoughts340
-rw-r--r--apps/plugins/pdbox/pdbox-net.c238
-rw-r--r--apps/plugins/pdbox/pdbox.c314
-rw-r--r--apps/plugins/pdbox/pdbox.h142
-rw-r--r--apps/plugins/pdbox/pdbox.make62
-rw-r--r--apps/plugins/viewers.config3
199 files changed, 139349 insertions, 1 deletions
diff --git a/apps/plugins/CATEGORIES b/apps/plugins/CATEGORIES
index 4b759b080f..8e4bb7d7c4 100644
--- a/apps/plugins/CATEGORIES
+++ b/apps/plugins/CATEGORIES
@@ -54,6 +54,7 @@ mpegplayer,viewers
nim,games
oscilloscope,demos
pacbox,games
+pdbox,apps
pegbox,games
pictureflow,demos
plasma,demos
diff --git a/apps/plugins/pdbox/PDa/CHANGELOG.PDa b/apps/plugins/pdbox/PDa/CHANGELOG.PDa
new file mode 100644
index 0000000000..f8afc2bd89
--- /dev/null
+++ b/apps/plugins/pdbox/PDa/CHANGELOG.PDa
@@ -0,0 +1,118 @@
+0.6:
+ - added compilation for blackfin architecture (blackfin.uclinux.org)
+ - added third outlet for mouseup to gcanvas.
+ - debian package support (for maemo)
+ - don't ask quit question
+
+0.5:
+ - fixed a crasher bug in sfread~.c
+
+0.4:
+ - added ipod gui communication in m_pd.c (pd_bind) and m_fixed.c
+ - moved the pd internal objects in a folder called interns
+ - restructuring of the makefile, you can build a static binary
+ now with "make static", needed for the iPod part mainly.
+ - the oscillator tables are precalculated now (faster startup).
+ see src/makecostable.c for that
+ - the scheduler is simplified (added an additional scheduler called
+ m_scheduler_pda(), this is a lot faster now
+ - changed the "look" of PDa
+ - The menubar in the patcher window is now optional, its off by default.
+ - stdin interface added. It is now possible to communicate with pd via the
+ keyboard even in -nogui mode
+ - fixed loading and saving of arrays (g_array.c)
+ - corrected rounding when calculation phase update osc~ and phasor~
+ (there are better methods to do this, but they are slower)
+ - fixed tabosc4~
+ - enabled array drawing
+ - fixed array saving in subpatch
+
+
+0.3test2:
+ - added the O_CREAT flag to sfwrite
+ - removed the OSC stuff (now in PDa-externals)
+
+0.3test1:
+ - moved all objects into the extra dir
+
+
+ d_arithmetic: t_float -> t_sample .. exchanged * with mult / with divide
+ d_fft: t_float -> t_sample
+ d_global: t_float -> t_sample
+ d_misc: put print~ into extra folder
+ d_resample: t_float -> t_sample
+ g_array: disable editing
+ fixtof()
+ t_float -> t_sample (check out the savefn thingy)
+
+ g_graph: 1 t_float -> t_sample
+ g_io: t_float -> t_sample
+ m_conf: remove calls to setup routines
+ m_obj.c ftofix
+ m_pd.h definition of t_sample
+ double -> t_time
+ ... and more
+ m_sched.c
+ double t_time
+ s_inter: check !!!
+ s_main: check !!!
+
+0.6:
+ - added compilation for blackfin architecture (blackfin.uclinux.org)
+ - added third outlet for mouseup to gcanvas.
+ - debian package support (for maemo)
+ - don't ask quit question
+
+0.5:
+ - fixed a crasher bug in sfread~.c
+
+0.4:
+ - added ipod gui communication in m_pd.c (pd_bind) and m_fixed.c
+ - moved the pd internal objects in a folder called interns
+ - restructuring of the makefile, you can build a static binary
+ now with "make static", needed for the iPod part mainly.
+ - the oscillator tables are precalculated now (faster startup).
+ see src/makecostable.c for that
+ - the scheduler is simplified (added an additional scheduler called
+ m_scheduler_pda(), this is a lot faster now
+ - changed the "look" of PDa
+ - The menubar in the patcher window is now optional, its off by default.
+ - stdin interface added. It is now possible to communicate with pd via the
+ keyboard even in -nogui mode
+ - fixed loading and saving of arrays (g_array.c)
+ - corrected rounding when calculation phase update osc~ and phasor~
+ (there are better methods to do this, but they are slower)
+ - fixed tabosc4~
+ - enabled array drawing
+ - fixed array saving in subpatch
+
+
+0.3test2:
+ - added the O_CREAT flag to sfwrite
+ - removed the OSC stuff (now in PDa-externals)
+
+0.3test1:
+ - moved all objects into the extra dir
+
+
+ d_arithmetic: t_float -> t_sample .. exchanged * with mult / with divide
+ d_fft: t_float -> t_sample
+ d_global: t_float -> t_sample
+ d_misc: put print~ into extra folder
+ d_resample: t_float -> t_sample
+ g_array: disable editing
+ fixtof()
+ t_float -> t_sample (check out the savefn thingy)
+
+ g_graph: 1 t_float -> t_sample
+ g_io: t_float -> t_sample
+ m_conf: remove calls to setup routines
+ m_obj.c ftofix
+ m_pd.h definition of t_sample
+ double -> t_time
+ ... and more
+ m_sched.c
+ double t_time
+ s_inter: check !!!
+ s_main: check !!!
+
diff --git a/apps/plugins/pdbox/PDa/LICENSE.txt b/apps/plugins/pdbox/PDa/LICENSE.txt
new file mode 100644
index 0000000000..3e104c77a2
--- /dev/null
+++ b/apps/plugins/pdbox/PDa/LICENSE.txt
@@ -0,0 +1,60 @@
+This software is copyrighted by Miller Puckette and others. The following
+terms (the "Standard Improved BSD License") apply to all files associated with
+the software unless explicitly disclaimed in individual files:
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+
+1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+2. Redistributions in binary form must reproduce the above
+ copyright notice, this list of conditions and the following
+ disclaimer in the documentation and/or other materials provided
+ with the distribution.
+3. The name of the author may not be used to endorse or promote
+ products derived from this software without specific prior
+ written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY
+EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR
+BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+THE POSSIBILITY OF SUCH DAMAGE.
+This software is copyrighted by Miller Puckette and others. The following
+terms (the "Standard Improved BSD License") apply to all files associated with
+the software unless explicitly disclaimed in individual files:
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+
+1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+2. Redistributions in binary form must reproduce the above
+ copyright notice, this list of conditions and the following
+ disclaimer in the documentation and/or other materials provided
+ with the distribution.
+3. The name of the author may not be used to endorse or promote
+ products derived from this software without specific prior
+ written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY
+EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR
+BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/apps/plugins/pdbox/PDa/README.PDa b/apps/plugins/pdbox/PDa/README.PDa
new file mode 100644
index 0000000000..7c567d70c2
--- /dev/null
+++ b/apps/plugins/pdbox/PDa/README.PDa
@@ -0,0 +1,106 @@
+PDa - Pure Data for Personal Digital Assistants
+===============================================
+
+Based on pd-0.37-4.
+
+This version of Pure Data is based on the original sources by
+Miller Puckette, but several part have been changed in order
+to run on embedded systems. Most of the changed objects are in
+the folder "intern".
+
+This means, that all the signal processing is done with fixed-point
+math. The control processing is still in floating point, therefor this
+might be a bit slow.
+
+The package is compilable under Linux. I would be glad if someone would
+make a version for windows or OSX, but I unfortunately don't have the
+time or resource to do so.
+
+In order to compile:
+cd src/
+make
+
+The default compilation flags are very conservative, you can add
+optimization flags through the CFLAGS variable.
+e.g
+
+make CFLAGS="-O6"
+
+Will turn on maximum optimization (almost).
+
+If you have tcl/tk installed in the right place this should work out,
+if you have problems with that, either adapt the makefile or ask me.
+On Debian you just have to install tk8.4-dev to get it going.
+
+Have fun !
+
+Guenter
+
+
+Additional information:
+---------------------------
+
+Instructions for compiling for iPods, using arm-elf-tools-20030314:
+
+cd src
+./build.ipod
+
+The tcl/tk interface will not be built for iPods, you can interface with
+Pd from the podzilla console or with this GUI for PDa on iPod:
+
+http://ipodlinux.org/Pdpod
+
+
+PDa - Pure Data for Personal Digital Assistants
+===============================================
+
+Based on pd-0.37-4.
+
+This version of Pure Data is based on the original sources by
+Miller Puckette, but several part have been changed in order
+to run on embedded systems. Most of the changed objects are in
+the folder "intern".
+
+This means, that all the signal processing is done with fixed-point
+math. The control processing is still in floating point, therefor this
+might be a bit slow.
+
+The package is compilable under Linux. I would be glad if someone would
+make a version for windows or OSX, but I unfortunately don't have the
+time or resource to do so.
+
+In order to compile:
+cd src/
+make
+
+The default compilation flags are very conservative, you can add
+optimization flags through the CFLAGS variable.
+e.g
+
+make CFLAGS="-O6"
+
+Will turn on maximum optimization (almost).
+
+If you have tcl/tk installed in the right place this should work out,
+if you have problems with that, either adapt the makefile or ask me.
+On Debian you just have to install tk8.4-dev to get it going.
+
+Have fun !
+
+Guenter
+
+
+Additional information:
+---------------------------
+
+Instructions for compiling for iPods, using arm-elf-tools-20030314:
+
+cd src
+./build.ipod
+
+The tcl/tk interface will not be built for iPods, you can interface with
+Pd from the podzilla console or with this GUI for PDa on iPod:
+
+http://ipodlinux.org/Pdpod
+
+
diff --git a/apps/plugins/pdbox/PDa/README.txt b/apps/plugins/pdbox/PDa/README.txt
new file mode 100644
index 0000000000..856ccaad62
--- /dev/null
+++ b/apps/plugins/pdbox/PDa/README.txt
@@ -0,0 +1,88 @@
+This is the README file for Pd, a free real-time computer music software
+package resembling Max. You can get Pd for Linux, Windows, Mac OSX, or IRIX
+from http://www.crca.ucsd.edu/~msp/software.html or ftp://felix.ucsd.edu.
+Installation instructions are in the HTML DOCUMENTATION at:
+
+ http://www.crca.ucsd.edu/~msp/Pd_documentation/index.htm
+
+If you download and unpack Pd, you will also find the html documentation
+locally in the file, .../pd-whatever/doc/1.manual/index.htm. To unpack Pd:
+
+LINUX (or freeBSD). Download Pd, which will be a ".tar.gz" file; to unpack it,
+type "zcat [name].tar.gz | tar xf -" to a shell. This creates a directory with
+a name like "pd-0.35". There are also RPMs available.
+
+Microsoft Windows. Pd is distributed as a "zip" file. Unzip this,
+creating a directory such as \pd.
+
+IRIX. Download Pd, which will be a "tar.Z" file. You can unpack this by
+typing "zcat [name].tar.Z | tar xf -" to a shell.
+
+Macintosh. The web browser will automatically unpack the distributions
+into a folder such as "pd-0.35" on your desktop.
+
+If you have qustions about Pd, or if you wish to be notified of releases,
+check the Pd mailing list: http://iem.mhsg.ac.at/mailinglists/pd-list/
+
+Many extensions to Pd are available, notably for handling video and 3D
+graphics; see the html documentation for pointers.
+
+COPYRIGHT. Except as otherwise noted, all files in the Pd distribution are
+
+ Copyright (c) 1997-2001 Miller Puckette and others.
+
+For information on usage and redistribution, and for a DISCLAIMER OF ALL
+WARRANTIES, see the file, "LICENSE.txt," included in the Pd distribution.
+(Note that tcl/tk, expr, and some other files are copyrighted separately).
+
+ACKNOWLEDGEMENTS. Thanks to Harry Castle, Krzysztof Czaja, Mark Danks,
+Christian Feldbauer, Guenter Geiger, Kerry Hagan, Trevor Johnson, Fernando
+Lopez-Lezcano, Adam Lindsay, Karl MacMillan, Thomas Musil, Toshinori Ohkouchi,
+Winfried Ritsch, Vibeke Sorensen, Rand Steiger, Shahrokh Yadegari, David
+Zicarelli, Iohannes Zmoelnig, and probably many others for contributions of
+code, documentation, ideas, and expertise. This work has received generous
+support from the Intel Research Council.
+This is the README file for Pd, a free real-time computer music software
+package resembling Max. You can get Pd for Linux, Windows, Mac OSX, or IRIX
+from http://www.crca.ucsd.edu/~msp/software.html or ftp://felix.ucsd.edu.
+Installation instructions are in the HTML DOCUMENTATION at:
+
+ http://www.crca.ucsd.edu/~msp/Pd_documentation/index.htm
+
+If you download and unpack Pd, you will also find the html documentation
+locally in the file, .../pd-whatever/doc/1.manual/index.htm. To unpack Pd:
+
+LINUX (or freeBSD). Download Pd, which will be a ".tar.gz" file; to unpack it,
+type "zcat [name].tar.gz | tar xf -" to a shell. This creates a directory with
+a name like "pd-0.35". There are also RPMs available.
+
+Microsoft Windows. Pd is distributed as a "zip" file. Unzip this,
+creating a directory such as \pd.
+
+IRIX. Download Pd, which will be a "tar.Z" file. You can unpack this by
+typing "zcat [name].tar.Z | tar xf -" to a shell.
+
+Macintosh. The web browser will automatically unpack the distributions
+into a folder such as "pd-0.35" on your desktop.
+
+If you have qustions about Pd, or if you wish to be notified of releases,
+check the Pd mailing list: http://iem.mhsg.ac.at/mailinglists/pd-list/
+
+Many extensions to Pd are available, notably for handling video and 3D
+graphics; see the html documentation for pointers.
+
+COPYRIGHT. Except as otherwise noted, all files in the Pd distribution are
+
+ Copyright (c) 1997-2001 Miller Puckette and others.
+
+For information on usage and redistribution, and for a DISCLAIMER OF ALL
+WARRANTIES, see the file, "LICENSE.txt," included in the Pd distribution.
+(Note that tcl/tk, expr, and some other files are copyrighted separately).
+
+ACKNOWLEDGEMENTS. Thanks to Harry Castle, Krzysztof Czaja, Mark Danks,
+Christian Feldbauer, Guenter Geiger, Kerry Hagan, Trevor Johnson, Fernando
+Lopez-Lezcano, Adam Lindsay, Karl MacMillan, Thomas Musil, Toshinori Ohkouchi,
+Winfried Ritsch, Vibeke Sorensen, Rand Steiger, Shahrokh Yadegari, David
+Zicarelli, Iohannes Zmoelnig, and probably many others for contributions of
+code, documentation, ideas, and expertise. This work has received generous
+support from the Intel Research Council.
diff --git a/apps/plugins/pdbox/PDa/extra/OSC-client.h b/apps/plugins/pdbox/PDa/extra/OSC-client.h
new file mode 100644
index 0000000000..196143f8e7
--- /dev/null
+++ b/apps/plugins/pdbox/PDa/extra/OSC-client.h
@@ -0,0 +1,376 @@
+/*
+Written by Matt Wright, The Center for New Music and Audio Technologies,
+University of California, Berkeley. Copyright (c) 1996,97,98,99,2000,01,02,03
+The Regents of the University of California (Regents).
+
+Permission to use, copy, modify, distribute, and distribute modified versions
+of this software and its documentation without fee and without a signed
+licensing agreement, is hereby granted, provided that the above copyright
+notice, this paragraph and the following two paragraphs appear in all copies,
+modifications, and distributions.
+
+IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
+SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING
+OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF REGENTS HAS
+BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE. THE SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED
+HEREUNDER IS PROVIDED "AS IS". REGENTS HAS NO OBLIGATION TO PROVIDE
+MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
+*/
+
+/*
+
+ OSC-client.h: library for constructing OpenSoundControl messages.
+ Derived from SynthControl.h
+ Author: Matt Wright
+ Version 0.1: 6/13/97
+ Version 0.2: 7/21/2000: Support for type-tagged messages
+
+
+ General notes:
+
+ This library abstracts away the data format for the OpenSoundControl
+ protocol. Users of this library can construct OpenSoundControl packets
+ with a function call interface instead of knowing how to lay out the bits.
+
+ All issues of memory allocation are deferred to the user of this library.
+ There are two data structures that the user must allocate. The first
+ is the actual buffer that the message will be written into. This buffer
+ can be any size, but if it's too small there's a possibility that it
+ will become overfull. The other data structure is called an OSCbuf,
+ and it holds all the state used by the library as it's constructing
+ a buffer.
+
+ All procedures that have the possibility of an error condition return int,
+ with 0 indicating no error and nonzero indicating an error. The variable
+ OSC_errorMessage will be set to point to a string containing an error
+ message explaining what the problem is.
+
+*/
+
+
+
+/* The int4byte type has to be a 4-byte integer. You may have to
+ change this to long or something else on your system. */
+#ifdef __MWERKS__
+ /* In Metrowerks you can set ints to be 2 or 4 bytes on 68K, but long is
+ always 4 bytes */
+ typedef long int4byte;
+#else
+ typedef int int4byte;
+#endif
+
+/* OSC_timetag.h */
+
+ typedef struct {
+ int seconds;
+ int fraction;
+ } OSCTimeTag;
+
+OSCTimeTag OSCTT_Immediately(void);
+OSCTimeTag OSCTT_PlusSeconds(OSCTimeTag original, float secondsOffset);
+OSCTimeTag OSCTT_CurrentTime(void);
+
+
+
+/* The maximum depth of bundles within bundles within bundles within...
+ This is the size of a static array. If you exceed this limit you'll
+ get an error message. */
+#define MAX_BUNDLE_NESTING 32
+
+
+/* Don't ever manipulate the data in the OSCbuf struct directly. (It's
+ declared here in the header file only so your program will be able to
+ declare variables of type OSCbuf and have the right amount of memory
+ be allocated.) */
+
+typedef struct OSCbuf_struct {
+ char *buffer; /* The buffer to hold the OSC packet */
+ int size; /* Size of the buffer */
+ char *bufptr; /* Current position as we fill the buffer */
+ int state; /* State of partially-constructed message */
+ int4byte *thisMsgSize; /* Pointer to count field before
+ currently-being-written message */
+ int4byte *prevCounts[MAX_BUNDLE_NESTING];
+ /* Pointers to count field before each currently
+ open bundle */
+ int bundleDepth; /* How many sub-sub-bundles are we in now? */
+ char *typeStringPtr; /* This pointer advances through the type
+ tag string as you add arguments. */
+ int gettingFirstUntypedArg; /* nonzero if this message doesn't have
+ a type tag and we're waiting for the 1st arg */
+} OSCbuf;
+
+
+
+/* Initialize the given OSCbuf. The user of this module must pass in the
+ block of memory that this OSCbuf will use for a buffer, and the number of
+ bytes in that block. (It's the user's job to allocate the memory because
+ you do it differently in different systems.) */
+void OSC_initBuffer(OSCbuf *buf, int size, char *byteArray);
+
+
+/* Reset the given OSCbuf. Do this after you send out the contents of
+ the buffer and want to start writing new data into it. */
+void OSC_resetBuffer(OSCbuf *buf);
+
+
+/* Is the buffer empty? (I.e., would it be stupid to send the buffer
+ contents to the synth?) */
+int OSC_isBufferEmpty(OSCbuf *buf);
+
+
+/* How much space is left in the buffer? */
+int OSC_freeSpaceInBuffer(OSCbuf *buf);
+
+/* Does the buffer contain a valid OSC packet? (Returns nonzero if yes.) */
+int OSC_isBufferDone(OSCbuf *buf);
+
+/* When you're ready to send out the buffer (i.e., when OSC_isBufferDone()
+ returns true), call these two procedures to get the OSC packet that's been
+ assembled and its size in bytes. (And then call OSC_resetBuffer() if you
+ want to re-use this OSCbuf for the next packet.) */
+char *OSC_getPacket(OSCbuf *buf);
+int OSC_packetSize(OSCbuf *buf);
+
+
+
+/* Here's the basic model for building up OSC messages in an OSCbuf:
+
+ - Make sure the OSCbuf has been initialized with OSC_initBuffer().
+
+ - To open a bundle, call OSC_openBundle(). You can then write
+ messages or open new bundles within the bundle you opened.
+ Call OSC_closeBundle() to close the bundle. Note that a packet
+ does not have to have a bundle; it can instead consist of just a
+ single message.
+
+
+ - For each message you want to send:
+
+ - Call OSC_writeAddress() with the name of your message. (In
+ addition to writing your message name into the buffer, this
+ procedure will also leave space for the size count of this message.)
+
+ - Alternately, call OSC_writeAddressAndTypes() with the name of
+ your message and with a type string listing the types of all the
+ arguments you will be putting in this message.
+
+ - Now write each of the arguments into the buffer, by calling one of:
+ OSC_writeFloatArg()
+ OSC_writeFloatArgs()
+ OSC_writeIntArg()
+ OSC_writeStringArg()
+
+ - Now your message is complete; you can send out the buffer or you can
+ add another message to it.
+*/
+
+int OSC_openBundle(OSCbuf *buf, OSCTimeTag tt);
+int OSC_closeBundle(OSCbuf *buf);
+int OSC_closeAllBundles(OSCbuf *buf);
+
+int OSC_writeAddress(OSCbuf *buf, char *name);
+int OSC_writeAddressAndTypes(OSCbuf *buf, char *name, char *types);
+int OSC_writeFloatArg(OSCbuf *buf, float arg);
+int OSC_writeFloatArgs(OSCbuf *buf, int numFloats, float *args);
+int OSC_writeIntArg(OSCbuf *buf, int4byte arg);
+int OSC_writeStringArg(OSCbuf *buf, char *arg);
+
+extern char *OSC_errorMessage;
+
+/* How many bytes will be needed in the OSC format to hold the given
+ string? The length of the string, plus the null char, plus any padding
+ needed for 4-byte alignment. */
+int OSC_effectiveStringLength(char *string);
+/*
+Written by Matt Wright, The Center for New Music and Audio Technologies,
+University of California, Berkeley. Copyright (c) 1996,97,98,99,2000,01,02,03
+The Regents of the University of California (Regents).
+
+Permission to use, copy, modify, distribute, and distribute modified versions
+of this software and its documentation without fee and without a signed
+licensing agreement, is hereby granted, provided that the above copyright
+notice, this paragraph and the following two paragraphs appear in all copies,
+modifications, and distributions.
+
+IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
+SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING
+OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF REGENTS HAS
+BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE. THE SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED
+HEREUNDER IS PROVIDED "AS IS". REGENTS HAS NO OBLIGATION TO PROVIDE
+MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
+*/
+
+/*
+
+ OSC-client.h: library for constructing OpenSoundControl messages.
+ Derived from SynthControl.h
+ Author: Matt Wright
+ Version 0.1: 6/13/97
+ Version 0.2: 7/21/2000: Support for type-tagged messages
+
+
+ General notes:
+
+ This library abstracts away the data format for the OpenSoundControl
+ protocol. Users of this library can construct OpenSoundControl packets
+ with a function call interface instead of knowing how to lay out the bits.
+
+ All issues of memory allocation are deferred to the user of this library.
+ There are two data structures that the user must allocate. The first
+ is the actual buffer that the message will be written into. This buffer
+ can be any size, but if it's too small there's a possibility that it
+ will become overfull. The other data structure is called an OSCbuf,
+ and it holds all the state used by the library as it's constructing
+ a buffer.
+
+ All procedures that have the possibility of an error condition return int,
+ with 0 indicating no error and nonzero indicating an error. The variable
+ OSC_errorMessage will be set to point to a string containing an error
+ message explaining what the problem is.
+
+*/
+
+
+
+/* The int4byte type has to be a 4-byte integer. You may have to
+ change this to long or something else on your system. */
+#ifdef __MWERKS__
+ /* In Metrowerks you can set ints to be 2 or 4 bytes on 68K, but long is
+ always 4 bytes */
+ typedef long int4byte;
+#else
+ typedef int int4byte;
+#endif
+
+/* OSC_timetag.h */
+
+ typedef struct {
+ int seconds;
+ int fraction;
+ } OSCTimeTag;
+
+OSCTimeTag OSCTT_Immediately(void);
+OSCTimeTag OSCTT_PlusSeconds(OSCTimeTag original, float secondsOffset);
+OSCTimeTag OSCTT_CurrentTime(void);
+
+
+
+/* The maximum depth of bundles within bundles within bundles within...
+ This is the size of a static array. If you exceed this limit you'll
+ get an error message. */
+#define MAX_BUNDLE_NESTING 32
+
+
+/* Don't ever manipulate the data in the OSCbuf struct directly. (It's
+ declared here in the header file only so your program will be able to
+ declare variables of type OSCbuf and have the right amount of memory
+ be allocated.) */
+
+typedef struct OSCbuf_struct {
+ char *buffer; /* The buffer to hold the OSC packet */
+ int size; /* Size of the buffer */
+ char *bufptr; /* Current position as we fill the buffer */
+ int state; /* State of partially-constructed message */
+ int4byte *thisMsgSize; /* Pointer to count field before
+ currently-being-written message */
+ int4byte *prevCounts[MAX_BUNDLE_NESTING];
+ /* Pointers to count field before each currently
+ open bundle */
+ int bundleDepth; /* How many sub-sub-bundles are we in now? */
+ char *typeStringPtr; /* This pointer advances through the type
+ tag string as you add arguments. */
+ int gettingFirstUntypedArg; /* nonzero if this message doesn't have
+ a type tag and we're waiting for the 1st arg */
+} OSCbuf;
+
+
+
+/* Initialize the given OSCbuf. The user of this module must pass in the
+ block of memory that this OSCbuf will use for a buffer, and the number of
+ bytes in that block. (It's the user's job to allocate the memory because
+ you do it differently in different systems.) */
+void OSC_initBuffer(OSCbuf *buf, int size, char *byteArray);
+
+
+/* Reset the given OSCbuf. Do this after you send out the contents of
+ the buffer and want to start writing new data into it. */
+void OSC_resetBuffer(OSCbuf *buf);
+
+
+/* Is the buffer empty? (I.e., would it be stupid to send the buffer
+ contents to the synth?) */
+int OSC_isBufferEmpty(OSCbuf *buf);
+
+
+/* How much space is left in the buffer? */
+int OSC_freeSpaceInBuffer(OSCbuf *buf);
+
+/* Does the buffer contain a valid OSC packet? (Returns nonzero if yes.) */
+int OSC_isBufferDone(OSCbuf *buf);
+
+/* When you're ready to send out the buffer (i.e., when OSC_isBufferDone()
+ returns true), call these two procedures to get the OSC packet that's been
+ assembled and its size in bytes. (And then call OSC_resetBuffer() if you
+ want to re-use this OSCbuf for the next packet.) */
+char *OSC_getPacket(OSCbuf *buf);
+int OSC_packetSize(OSCbuf *buf);
+
+
+
+/* Here's the basic model for building up OSC messages in an OSCbuf:
+
+ - Make sure the OSCbuf has been initialized with OSC_initBuffer().
+
+ - To open a bundle, call OSC_openBundle(). You can then write
+ messages or open new bundles within the bundle you opened.
+ Call OSC_closeBundle() to close the bundle. Note that a packet
+ does not have to have a bundle; it can instead consist of just a
+ single message.
+
+
+ - For each message you want to send:
+
+ - Call OSC_writeAddress() with the name of your message. (In
+ addition to writing your message name into the buffer, this
+ procedure will also leave space for the size count of this message.)
+
+ - Alternately, call OSC_writeAddressAndTypes() with the name of
+ your message and with a type string listing the types of all the
+ arguments you will be putting in this message.
+
+ - Now write each of the arguments into the buffer, by calling one of:
+ OSC_writeFloatArg()
+ OSC_writeFloatArgs()
+ OSC_writeIntArg()
+ OSC_writeStringArg()
+
+ - Now your message is complete; you can send out the buffer or you can
+ add another message to it.
+*/
+
+int OSC_openBundle(OSCbuf *buf, OSCTimeTag tt);
+int OSC_closeBundle(OSCbuf *buf);
+int OSC_closeAllBundles(OSCbuf *buf);
+
+int OSC_writeAddress(OSCbuf *buf, char *name);
+int OSC_writeAddressAndTypes(OSCbuf *buf, char *name, char *types);
+int OSC_writeFloatArg(OSCbuf *buf, float arg);
+int OSC_writeFloatArgs(OSCbuf *buf, int numFloats, float *args);
+int OSC_writeIntArg(OSCbuf *buf, int4byte arg);
+int OSC_writeStringArg(OSCbuf *buf, char *arg);
+
+extern char *OSC_errorMessage;
+
+/* How many bytes will be needed in the OSC format to hold the given
+ string? The length of the string, plus the null char, plus any padding
+ needed for 4-byte alignment. */
+int OSC_effectiveStringLength(char *string);
diff --git a/apps/plugins/pdbox/PDa/extra/OSC.pd b/apps/plugins/pdbox/PDa/extra/OSC.pd
new file mode 100644
index 0000000000..8873f308da
--- /dev/null
+++ b/apps/plugins/pdbox/PDa/extra/OSC.pd
@@ -0,0 +1,26 @@
+#N canvas 0 0 240 300 10;
+#X obj 32 185 dumpOSC 5550;
+#X obj 32 217 OSCroute /hello;
+#X obj 32 239 print;
+#X obj 133 238 print;
+#X obj 26 87 sendOSC;
+#X msg 50 43 connect localhost 5550;
+#X msg 21 13 send /hello PDa;
+#X connect 0 0 1 0;
+#X connect 1 0 2 0;
+#X connect 1 1 3 0;
+#X connect 5 0 4 0;
+#X connect 6 0 4 0;
+#N canvas 0 0 240 300 10;
+#X obj 32 185 dumpOSC 5550;
+#X obj 32 217 OSCroute /hello;
+#X obj 32 239 print;
+#X obj 133 238 print;
+#X obj 26 87 sendOSC;
+#X msg 50 43 connect localhost 5550;
+#X msg 21 13 send /hello PDa;
+#X connect 0 0 1 0;
+#X connect 1 0 2 0;
+#X connect 1 1 3 0;
+#X connect 5 0 4 0;
+#X connect 6 0 4 0;
diff --git a/apps/plugins/pdbox/PDa/extra/OSCroute.c b/apps/plugins/pdbox/PDa/extra/OSCroute.c
new file mode 100644
index 0000000000..437d34dc68
--- /dev/null
+++ b/apps/plugins/pdbox/PDa/extra/OSCroute.c
@@ -0,0 +1,1204 @@
+/*
+Written by Adrian Freed, The Center for New Music and Audio Technologies,
+University of California, Berkeley. Copyright (c) 1992,93,94,95,96,97,98,99,2000,01,02,03,04
+The Regents of the University of California (Regents).
+
+Permission to use, copy, modify, distribute, and distribute modified versions
+of this software and its documentation without fee and without a signed
+licensing agreement, is hereby granted, provided that the above copyright
+notice, this paragraph and the following two paragraphs appear in all copies,
+modifications, and distributions.
+
+IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
+SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING
+OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF REGENTS HAS
+BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE. THE SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED
+HEREUNDER IS PROVIDED "AS IS". REGENTS HAS NO OBLIGATION TO PROVIDE
+MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
+
+
+The OSC webpage is http://cnmat.cnmat.berkeley.edu/OpenSoundControl
+*/
+
+ /* OSC-route.c
+ Max object for OSC-style dispatching
+
+ To-do:
+
+ Match a pattern against a pattern?
+ Declare outlet types / distinguish leaf nodes from other children
+ More sophisticated (2-pass?) allmessages scheme
+ set message?
+
+
+ pd
+ -------------
+ -- tweaks for Win32 www.zeggz.com/raf 13-April-2002
+
+
+ */
+
+#ifdef WIN32
+ #include <stdlib.h>
+ #include <string.h>
+#endif
+#ifdef __APPLE__
+ #include <stdio.h>
+#endif
+#ifdef UNIX
+ #include <stdio.h>
+#endif
+
+/* structure definition of your object */
+
+#define MAX_NUM 20
+#define OSC_ROUTE_VERSION "1.05"
+#define OSCWarning(x...) post(x)
+
+/* the required include files */
+#include "m_pd.h"
+
+
+#ifndef TRUE
+typedef int Boolean;
+#define TRUE 1
+#define FALSE 0
+#endif
+
+
+/* Fixed byte width types */
+typedef int int4; /* 4 byte int */
+
+Boolean PatternMatch (const char *pattern, const char *test);
+
+
+
+/* Version 1.04: Allows #1 thru #9 as typed-in arguments
+ Version 1.05: Allows "list" messages as well as "message" messages.
+*/
+
+static t_class *OSCroute_class;
+
+typedef struct _OSCroute
+{
+ t_object x_obj; // required header
+ t_int x_num; // Number of address prefixes we store
+ t_int x_complainmode; // Do we print a message if no match?
+ t_int x_sendmode; // use pd internal sends instead of outlets
+ char *x_prefixes[MAX_NUM];
+ void *x_outlets[MAX_NUM+1];
+} t_OSCroute;
+
+t_symbol *ps_list, *ps_complain, *ps_emptySymbol;
+
+/* prototypes */
+
+void OSCroute_doanything(t_OSCroute *x, t_symbol *s, int argc, t_atom *argv);
+void OSCroute_anything(t_OSCroute *x, t_symbol *s, int argc, t_atom *argv);
+void OSCroute_list(t_OSCroute *x, t_symbol *s, int argc, t_atom *argv);
+/* //void *OSCroute_new(t_symbol *s, int argc, atom *argv); */
+void *OSCroute_new(t_symbol *s, int argc, t_atom *argv);
+void OSCroute_version (t_OSCroute *x);
+/* void OSCroute_assist (OSCroute *x, void *box, long msg, long arg, */
+/* char *dstString); */
+void OSCroute_allmessages(t_OSCroute *x, t_symbol *s, int argc, t_atom *argv);
+
+static char *NextSlashOrNull(char *p);
+static void StrCopyUntilSlash(char *target, const char *source);
+
+
+// free
+static void OSCroute_free(t_OSCroute *x)
+{
+ // freebytes(x->x_vec, x->x_nelement * sizeof(*x->x_vec));
+}
+
+/* initialization routine */
+
+// setup
+#ifdef WIN32
+ OSC_API void OSCroute_setup(void) {
+#else
+void OSCroute_setup(void) {
+#endif
+ OSCroute_class = class_new(gensym("OSCroute"), (t_newmethod)OSCroute_new,
+ (t_method)OSCroute_free,sizeof(t_OSCroute), 0, A_GIMME, 0);
+ class_addlist(OSCroute_class, OSCroute_list);
+ class_addanything(OSCroute_class, OSCroute_anything);
+ class_addmethod(OSCroute_class, (t_method)OSCroute_version, gensym("version"), A_NULL, 0, 0);
+ class_sethelpsymbol(OSCroute_class, gensym("OSCroute-help.pd"));
+
+ /*
+ class_addmethod(OSCroute_class, (t_method)OSCroute_connect,
+ gensym("connect"), A_SYMBOL, A_FLOAT, 0);
+ class_addmethod(OSCroute_class, (t_method)OSCroute_disconnect,
+ gensym("disconnect"), 0);
+ class_addmethod(OSCroute_class, (t_method)OSCroute_send, gensym("send"),
+ A_GIMME, 0);
+ */
+/* ps_list = gensym("list"); */
+/* ps_complain = gensym("complain"); */
+ ps_emptySymbol = gensym("");
+
+ post("OSCroute object version " OSC_ROUTE_VERSION " by Matt Wright. pd: jdl Win32 raf.");
+ post("OSCroute Copyright 1999 Regents of the University of California. All Rights Reserved.");
+}
+
+
+
+/* instance creation routine */
+
+void *OSCroute_new(t_symbol *s, int argc, t_atom *argv)
+{
+
+ t_OSCroute *x = (t_OSCroute *)pd_new(OSCroute_class); // get memory for a new object & initialize
+
+ int i; //{{raf}} n not used
+
+ // EnterCallback();
+
+ if (argc > MAX_NUM) {
+ post("* OSC-route: too many arguments: %ld (max %ld)", argc, MAX_NUM);
+ // ExitCallback();
+ return 0;
+ }
+
+ x->x_complainmode = 0;
+ x->x_num = 0;
+ for (i = 0; i < argc; ++i) {
+ if (argv[i].a_type == A_SYMBOL) {
+ if (argv[i].a_w.w_symbol->s_name[0] == '/') {
+ /* Now that's a nice prefix */
+ x->x_prefixes[i] = argv[i].a_w.w_symbol->s_name;
+ ++(x->x_num);
+ } else if (argv[i].a_w.w_symbol->s_name[0] == '#' &&
+ argv[i].a_w.w_symbol->s_name[1] >= '1' &&
+ argv[i].a_w.w_symbol->s_name[1] <= '9') {
+ /* The Max programmer is trying to make a patch that will be
+ a subpatch with arguments. We have to make an outlet for this
+ argument. */
+ x->x_prefixes[i] = "dummy";
+ ++(x->x_num);
+ } else {
+ /* Maybe this is an option we support */
+
+/* if (argv[i].a_w.w_sym == ps_complain) { */
+/* x->x_complainmode = 1; */
+/* } else { */
+/* post("* OSC-route: Unrecognized argument %s", argv[i].a_w.w_sym->s_name); */
+/* } */
+
+ }
+
+ // no LONG
+
+/* } else if (argv[i].a_type == A_FLOAD) { */
+/* // Convert to a numeral. Max ints are -2147483648 to 2147483647 */
+/* char *string = getbytes(12); */
+/* // I can't be bothered to plug this 12 byte memory leak */
+/* if (string == 0) { */
+/* post("* OSC-route: out of memory!"); */
+/* // ExitCallback(); */
+/* return 0; */
+/* } */
+/* sprintf(string, "%d", argv[i].a_w.w_long); */
+/* x->x_prefixes[i] = string; */
+/* ++(x->x_num); */
+
+ } else if (argv[i].a_type == A_FLOAT) {
+ post("* OSC-route: float arguments are not OK.");
+ // ExitCallback();
+ return 0;
+ } else {
+ post("* OSC-route: unrecognized argument type!");
+ // ExitCallback();
+ return 0;
+ }
+ }
+
+
+ /* Have to create the outlets in reverse order */
+ /* well, not in pd ? */
+ // for (i = x->x_num-1; i >= 0; --i) {
+ // for (i = 0; i <= x->x_num-1; i++) {
+ for (i = 0; i <= x->x_num; i++) {
+ // x->x_outlets[i] = listout(x);
+ x->x_outlets[i] = outlet_new(&x->x_obj, &s_list);
+ }
+
+ // ExitCallback();
+ return (x);
+}
+
+
+void OSCroute_version (t_OSCroute *x) {
+ // EnterCallback();
+ post("OSCroute Version " OSC_ROUTE_VERSION
+ ", by Matt Wright. pd jdl, win32: raf.\nOSCroute Compiled " __TIME__ " " __DATE__);
+ // ExitCallback();
+}
+
+/* I don't know why these aren't defined in some Max #include file. */
+#define ASSIST_INLET 1
+#define ASSIST_OUTLET 2
+
+void OSCroute_assist (t_OSCroute *x, void *box, long msg, long arg,
+ char *dstString) {
+ // EnterCallback();
+
+ if (msg==ASSIST_INLET) {
+ sprintf(dstString, "Incoming OSC messages");
+ } else if (msg==ASSIST_OUTLET) {
+ if (arg < 0 || arg >= x->x_num) {
+ post("* OSCroute_assist: No outlet corresponds to arg %ld!", arg);
+ } else {
+ sprintf(dstString, "subaddress + args for prefix %s", x->x_prefixes[arg]);
+ }
+ } else {
+ post("* OSCroute_assist: unrecognized message %ld", msg);
+ }
+
+ // ExitCallback();
+}
+
+void OSCroute_list(t_OSCroute *x, t_symbol *s, int argc, t_atom *argv) {
+ // EnterCallback();
+ if (argc > 0 && argv[0].a_type == A_SYMBOL) {
+ /* Ignore the fact that this is a "list" */
+ OSCroute_doanything(x, argv[0].a_w.w_symbol, argc-1, argv+1);
+ } else {
+ // post("* OSC-route: invalid list beginning with a number");
+ // output on unmatched outlet jdl 20020908
+ if (argv[0].a_type == A_FLOAT) {
+ outlet_float(x->x_outlets[x->x_num], argv[0].a_w.w_float);
+ } else {
+ post("* OSC-route: unrecognized atom type!");
+ }
+ }
+ // ExitCallback();
+}
+
+
+void OSCroute_anything(t_OSCroute *x, t_symbol *s, int argc, t_atom *argv) {
+ // EnterCallback();
+ OSCroute_doanything(x, s, argc, argv);
+ // ExitCallback();
+}
+
+
+
+
+void OSCroute_doanything(t_OSCroute *x, t_symbol *s, int argc, t_atom *argv) {
+ char *pattern, *nextSlash;
+ int i;
+ int matchedAnything;
+ // post("*** OSCroute_anything(s %s, argc %ld)", s->s_name, (long) argc);
+
+ pattern = s->s_name;
+ if (pattern[0] != '/') {
+ post("* OSC-route: invalid message pattern %s does not begin with /", s->s_name);
+ outlet_anything(x->x_outlets[x->x_num], s, argc, argv);
+ return;
+ }
+
+ matchedAnything = 0;
+
+ nextSlash = NextSlashOrNull(pattern+1);
+ if (*nextSlash == '\0') {
+ /* last level of the address, so we'll output the argument list */
+
+
+#ifdef NULL_IS_DIFFERENT_FROM_BANG
+ if (argc==0) {
+ post("* OSC-route: why are you matching one level pattern %s with no args?",
+ pattern);
+ return;
+ }
+#endif
+
+ for (i = 0; i < x->x_num; ++i) {
+ if (PatternMatch(pattern+1, x->x_prefixes[i]+1)) {
+ ++matchedAnything;
+
+ // I hate stupid Max lists with a special first element
+ if (argc == 0) {
+ outlet_bang(x->x_outlets[i]);
+ } else if (argv[0].a_type == A_SYMBOL) {
+ // Promote the symbol that was argv[0] to the special symbol
+ outlet_anything(x->x_outlets[i], argv[0].a_w.w_symbol, argc-1, argv+1);
+ } else if (argc > 1) {
+ // Multiple arguments starting with a number, so naturally we have
+ // to use a special function to output this "list", since it's what
+ // Max originally meant by "list".
+ outlet_list(x->x_outlets[i], 0L, argc, argv);
+ } else {
+ // There was only one argument, and it was a number, so we output it
+ // not as a list
+/* if (argv[0].a_type == A_LONG) { */
+
+/* outlet_int(x->x_outlets[i], argv[0].a_w.w_long); */
+ // } else
+ if (argv[0].a_type == A_FLOAT) {
+
+ outlet_float(x->x_outlets[i], argv[0].a_w.w_float);
+ } else {
+ post("* OSC-route: unrecognized atom type!");
+ }
+ }
+ }
+ }
+ } else {
+ /* There's more address after this part, so our output list will begin with
+ the next slash. */
+ t_symbol *restOfPattern = 0; /* avoid the gensym unless we have to output */
+ char patternBegin[1000];
+
+
+ /* Get the first level of the incoming pattern to match against all our prefixes */
+ StrCopyUntilSlash(patternBegin, pattern+1);
+
+ for (i = 0; i < x->x_num; ++i) {
+ if (PatternMatch(patternBegin, x->x_prefixes[i]+1)) {
+ ++matchedAnything;
+ if (restOfPattern == 0) {
+ restOfPattern = gensym(nextSlash);
+ }
+ outlet_anything(x->x_outlets[i], restOfPattern, argc, argv);
+ }
+ }
+ }
+
+ if (x->x_complainmode) {
+ if (!matchedAnything) {
+ post("* OSC-route: pattern %s did not match any prefixes", pattern);
+ }
+ }
+
+ // output unmatched data on rightmost outlet a la normal 'route' object, jdl 20020908
+ if (!matchedAnything) {
+ outlet_anything(x->x_outlets[x->x_num], s, argc, argv);
+ }
+
+
+}
+
+static char *NextSlashOrNull(char *p) {
+ while (*p != '/' && *p != '\0') {
+ p++;
+ }
+ return p;
+}
+
+static void StrCopyUntilSlash(char *target, const char *source) {
+ while (*source != '/' && *source != '\0') {
+ *target = *source;
+ ++target;
+ ++source;
+ }
+ *target = 0;
+}
+
+static int MyStrCopy(char *target, const char *source) {
+ int i = 0;
+ while (*source != '\0') {
+ *target = *source;
+ ++target;
+ ++source;
+ ++i;
+ }
+ *target = 0;
+ return i;
+}
+
+
+
+void OSCroute_allmessages(t_OSCroute *x, t_symbol *s, int argc, t_atom *argv) {
+ int i;
+ t_symbol *prefixSymbol = 0;
+ char prefixBuf[1000];
+ char *endOfPrefix;
+ t_atom a[1];
+
+ if (argc >= 1 && argv[0].a_type == A_SYMBOL) {
+ prefixSymbol = argv[0].a_w.w_symbol;
+ endOfPrefix = prefixBuf + MyStrCopy(prefixBuf,
+ prefixSymbol->s_name);
+ } else {
+ prefixSymbol = ps_emptySymbol;
+ prefixBuf[0] = '\0';
+ endOfPrefix = prefixBuf;
+ }
+
+
+ for (i = 0; i < x->x_num; ++i) {
+ post("OSC: %s%s", prefixSymbol->s_name, x->x_prefixes[i]);
+ MyStrCopy(endOfPrefix, x->x_prefixes[i]);
+ SETSYMBOL(a, gensym(prefixBuf));
+ outlet_anything(x->x_outlets[i], s, 1, a);
+ }
+}
+
+
+/* --------------------------------------------------- */
+
+
+
+static const char *theWholePattern; /* Just for warning messages */
+
+static Boolean MatchBrackets (const char *pattern, const char *test);
+static Boolean MatchList (const char *pattern, const char *test);
+
+Boolean PatternMatch (const char * pattern, const char * test) {
+ theWholePattern = pattern;
+
+ if (pattern == 0 || pattern[0] == 0) {
+ return test[0] == 0;
+ }
+
+ if (test[0] == 0) {
+ if (pattern[0] == '*')
+ return PatternMatch (pattern+1,test);
+ else
+ return FALSE;
+ }
+
+ switch (pattern[0]) {
+ case 0 : return test[0] == 0;
+ case '?' : return PatternMatch (pattern + 1, test + 1);
+ case '*' :
+ if (PatternMatch (pattern+1, test)) {
+ return TRUE;
+ } else {
+ return PatternMatch (pattern, test+1);
+ }
+ case ']' :
+ case '}' :
+ OSCWarning("Spurious %c in pattern \".../%s/...\"",pattern[0], theWholePattern);
+ return FALSE;
+ case '[' :
+ return MatchBrackets (pattern,test);
+ case '{' :
+ return MatchList (pattern,test);
+ case '\\' :
+ if (pattern[1] == 0) {
+ return test[0] == 0;
+ } else if (pattern[1] == test[0]) {
+ return PatternMatch (pattern+2,test+1);
+ } else {
+ return FALSE;
+ }
+ default :
+ if (pattern[0] == test[0]) {
+ return PatternMatch (pattern+1,test+1);
+ } else {
+ return FALSE;
+ }
+ }
+}
+
+
+/* we know that pattern[0] == '[' and test[0] != 0 */
+
+static Boolean MatchBrackets (const char *pattern, const char *test) {
+ Boolean result;
+ Boolean negated = FALSE;
+ const char *p = pattern;
+
+ if (pattern[1] == 0) {
+ OSCWarning("Unterminated [ in pattern \".../%s/...\"", theWholePattern);
+ return FALSE;
+ }
+
+ if (pattern[1] == '!') {
+ negated = TRUE;
+ p++;
+ }
+
+ while (*p != ']') {
+ if (*p == 0) {
+ OSCWarning("Unterminated [ in pattern \".../%s/...\"", theWholePattern);
+ return FALSE;
+ }
+ if (p[1] == '-' && p[2] != 0) {
+ if (test[0] >= p[0] && test[0] <= p[2]) {
+ result = !negated;
+ goto advance;
+ }
+ }
+ if (p[0] == test[0]) {
+ result = !negated;
+ goto advance;
+ }
+ p++;
+ }
+
+ result = negated;
+
+advance:
+
+ if (!result)
+ return FALSE;
+
+ while (*p != ']') {
+ if (*p == 0) {
+ OSCWarning("Unterminated [ in pattern \".../%s/...\"", theWholePattern);
+ return FALSE;
+ }
+ p++;
+ }
+
+ return PatternMatch (p+1,test+1);
+}
+
+static Boolean MatchList (const char *pattern, const char *test) {
+
+ const char *restOfPattern, *tp = test;
+
+
+ for(restOfPattern = pattern; *restOfPattern != '}'; restOfPattern++) {
+ if (*restOfPattern == 0) {
+ OSCWarning("Unterminated { in pattern \".../%s/...\"", theWholePattern);
+ return FALSE;
+ }
+ }
+
+ restOfPattern++; /* skip close curly brace */
+
+
+ pattern++; /* skip open curly brace */
+
+ while (1) {
+
+ if (*pattern == ',') {
+ if (PatternMatch (restOfPattern, tp)) {
+ return TRUE;
+ } else {
+ tp = test;
+ ++pattern;
+ }
+ } else if (*pattern == '}') {
+ return PatternMatch (restOfPattern, tp);
+ } else if (*pattern == *tp) {
+ ++pattern;
+ ++tp;
+ } else {
+ tp = test;
+ while (*pattern != ',' && *pattern != '}') {
+ pattern++;
+ }
+ if (*pattern == ',') {
+ pattern++;
+ }
+ }
+ }
+
+}
+
+
+
+/*
+Written by Adrian Freed, The Center for New Music and Audio Technologies,
+University of California, Berkeley. Copyright (c) 1992,93,94,95,96,97,98,99,2000,01,02,03,04
+The Regents of the University of California (Regents).
+
+Permission to use, copy, modify, distribute, and distribute modified versions
+of this software and its documentation without fee and without a signed
+licensing agreement, is hereby granted, provided that the above copyright
+notice, this paragraph and the following two paragraphs appear in all copies,
+modifications, and distributions.
+
+IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
+SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING
+OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF REGENTS HAS
+BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE. THE SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED
+HEREUNDER IS PROVIDED "AS IS". REGENTS HAS NO OBLIGATION TO PROVIDE
+MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
+
+
+The OSC webpage is http://cnmat.cnmat.berkeley.edu/OpenSoundControl
+*/
+
+ /* OSC-route.c
+ Max object for OSC-style dispatching
+
+ To-do:
+
+ Match a pattern against a pattern?
+ Declare outlet types / distinguish leaf nodes from other children
+ More sophisticated (2-pass?) allmessages scheme
+ set message?
+
+
+ pd
+ -------------
+ -- tweaks for Win32 www.zeggz.com/raf 13-April-2002
+
+
+ */
+
+#ifdef WIN32
+ #include <stdlib.h>
+ #include <string.h>
+#endif
+#ifdef __APPLE__
+ #include <stdio.h>
+#endif
+#ifdef UNIX
+ #include <stdio.h>
+#endif
+
+/* structure definition of your object */
+
+#define MAX_NUM 20
+#define OSC_ROUTE_VERSION "1.05"
+#define OSCWarning(x...) post(x)
+
+/* the required include files */
+#include "m_pd.h"
+
+
+#ifndef TRUE
+typedef int Boolean;
+#define TRUE 1
+#define FALSE 0
+#endif
+
+
+/* Fixed byte width types */
+typedef int int4; /* 4 byte int */
+
+Boolean PatternMatch (const char *pattern, const char *test);
+
+
+
+/* Version 1.04: Allows #1 thru #9 as typed-in arguments
+ Version 1.05: Allows "list" messages as well as "message" messages.
+*/
+
+static t_class *OSCroute_class;
+
+typedef struct _OSCroute
+{
+ t_object x_obj; // required header
+ t_int x_num; // Number of address prefixes we store
+ t_int x_complainmode; // Do we print a message if no match?
+ t_int x_sendmode; // use pd internal sends instead of outlets
+ char *x_prefixes[MAX_NUM];
+ void *x_outlets[MAX_NUM+1];
+} t_OSCroute;
+
+t_symbol *ps_list, *ps_complain, *ps_emptySymbol;
+
+/* prototypes */
+
+void OSCroute_doanything(t_OSCroute *x, t_symbol *s, int argc, t_atom *argv);
+void OSCroute_anything(t_OSCroute *x, t_symbol *s, int argc, t_atom *argv);
+void OSCroute_list(t_OSCroute *x, t_symbol *s, int argc, t_atom *argv);
+/* //void *OSCroute_new(t_symbol *s, int argc, atom *argv); */
+void *OSCroute_new(t_symbol *s, int argc, t_atom *argv);
+void OSCroute_version (t_OSCroute *x);
+/* void OSCroute_assist (OSCroute *x, void *box, long msg, long arg, */
+/* char *dstString); */
+void OSCroute_allmessages(t_OSCroute *x, t_symbol *s, int argc, t_atom *argv);
+
+static char *NextSlashOrNull(char *p);
+static void StrCopyUntilSlash(char *target, const char *source);
+
+
+// free
+static void OSCroute_free(t_OSCroute *x)
+{
+ // freebytes(x->x_vec, x->x_nelement * sizeof(*x->x_vec));
+}
+
+/* initialization routine */
+
+// setup
+#ifdef WIN32
+ OSC_API void OSCroute_setup(void) {
+#else
+void OSCroute_setup(void) {
+#endif
+ OSCroute_class = class_new(gensym("OSCroute"), (t_newmethod)OSCroute_new,
+ (t_method)OSCroute_free,sizeof(t_OSCroute), 0, A_GIMME, 0);
+ class_addlist(OSCroute_class, OSCroute_list);
+ class_addanything(OSCroute_class, OSCroute_anything);
+ class_addmethod(OSCroute_class, (t_method)OSCroute_version, gensym("version"), A_NULL, 0, 0);
+ class_sethelpsymbol(OSCroute_class, gensym("OSCroute-help.pd"));
+
+ /*
+ class_addmethod(OSCroute_class, (t_method)OSCroute_connect,
+ gensym("connect"), A_SYMBOL, A_FLOAT, 0);
+ class_addmethod(OSCroute_class, (t_method)OSCroute_disconnect,
+ gensym("disconnect"), 0);
+ class_addmethod(OSCroute_class, (t_method)OSCroute_send, gensym("send"),
+ A_GIMME, 0);
+ */
+/* ps_list = gensym("list"); */
+/* ps_complain = gensym("complain"); */
+ ps_emptySymbol = gensym("");
+
+ post("OSCroute object version " OSC_ROUTE_VERSION " by Matt Wright. pd: jdl Win32 raf.");
+ post("OSCroute Copyright 1999 Regents of the University of California. All Rights Reserved.");
+}
+
+
+
+/* instance creation routine */
+
+void *OSCroute_new(t_symbol *s, int argc, t_atom *argv)
+{
+
+ t_OSCroute *x = (t_OSCroute *)pd_new(OSCroute_class); // get memory for a new object & initialize
+
+ int i; //{{raf}} n not used
+
+ // EnterCallback();
+
+ if (argc > MAX_NUM) {
+ post("* OSC-route: too many arguments: %ld (max %ld)", argc, MAX_NUM);
+ // ExitCallback();
+ return 0;
+ }
+
+ x->x_complainmode = 0;
+ x->x_num = 0;
+ for (i = 0; i < argc; ++i) {
+ if (argv[i].a_type == A_SYMBOL) {
+ if (argv[i].a_w.w_symbol->s_name[0] == '/') {
+ /* Now that's a nice prefix */
+ x->x_prefixes[i] = argv[i].a_w.w_symbol->s_name;
+ ++(x->x_num);
+ } else if (argv[i].a_w.w_symbol->s_name[0] == '#' &&
+ argv[i].a_w.w_symbol->s_name[1] >= '1' &&
+ argv[i].a_w.w_symbol->s_name[1] <= '9') {
+ /* The Max programmer is trying to make a patch that will be
+ a subpatch with arguments. We have to make an outlet for this
+ argument. */
+ x->x_prefixes[i] = "dummy";
+ ++(x->x_num);
+ } else {
+ /* Maybe this is an option we support */
+
+/* if (argv[i].a_w.w_sym == ps_complain) { */
+/* x->x_complainmode = 1; */
+/* } else { */
+/* post("* OSC-route: Unrecognized argument %s", argv[i].a_w.w_sym->s_name); */
+/* } */
+
+ }
+
+ // no LONG
+
+/* } else if (argv[i].a_type == A_FLOAD) { */
+/* // Convert to a numeral. Max ints are -2147483648 to 2147483647 */
+/* char *string = getbytes(12); */
+/* // I can't be bothered to plug this 12 byte memory leak */
+/* if (string == 0) { */
+/* post("* OSC-route: out of memory!"); */
+/* // ExitCallback(); */
+/* return 0; */
+/* } */
+/* sprintf(string, "%d", argv[i].a_w.w_long); */
+/* x->x_prefixes[i] = string; */
+/* ++(x->x_num); */
+
+ } else if (argv[i].a_type == A_FLOAT) {
+ post("* OSC-route: float arguments are not OK.");
+ // ExitCallback();
+ return 0;
+ } else {
+ post("* OSC-route: unrecognized argument type!");
+ // ExitCallback();
+ return 0;
+ }
+ }
+
+
+ /* Have to create the outlets in reverse order */
+ /* well, not in pd ? */
+ // for (i = x->x_num-1; i >= 0; --i) {
+ // for (i = 0; i <= x->x_num-1; i++) {
+ for (i = 0; i <= x->x_num; i++) {
+ // x->x_outlets[i] = listout(x);
+ x->x_outlets[i] = outlet_new(&x->x_obj, &s_list);
+ }
+
+ // ExitCallback();
+ return (x);
+}
+
+
+void OSCroute_version (t_OSCroute *x) {
+ // EnterCallback();
+ post("OSCroute Version " OSC_ROUTE_VERSION
+ ", by Matt Wright. pd jdl, win32: raf.\nOSCroute Compiled " __TIME__ " " __DATE__);
+ // ExitCallback();
+}
+
+/* I don't know why these aren't defined in some Max #include file. */
+#define ASSIST_INLET 1
+#define ASSIST_OUTLET 2
+
+void OSCroute_assist (t_OSCroute *x, void *box, long msg, long arg,
+ char *dstString) {
+ // EnterCallback();
+
+ if (msg==ASSIST_INLET) {
+ sprintf(dstString, "Incoming OSC messages");
+ } else if (msg==ASSIST_OUTLET) {
+ if (arg < 0 || arg >= x->x_num) {
+ post("* OSCroute_assist: No outlet corresponds to arg %ld!", arg);
+ } else {
+ sprintf(dstString, "subaddress + args for prefix %s", x->x_prefixes[arg]);
+ }
+ } else {
+ post("* OSCroute_assist: unrecognized message %ld", msg);
+ }
+
+ // ExitCallback();
+}
+
+void OSCroute_list(t_OSCroute *x, t_symbol *s, int argc, t_atom *argv) {
+ // EnterCallback();
+ if (argc > 0 && argv[0].a_type == A_SYMBOL) {
+ /* Ignore the fact that this is a "list" */
+ OSCroute_doanything(x, argv[0].a_w.w_symbol, argc-1, argv+1);
+ } else {
+ // post("* OSC-route: invalid list beginning with a number");
+ // output on unmatched outlet jdl 20020908
+ if (argv[0].a_type == A_FLOAT) {
+ outlet_float(x->x_outlets[x->x_num], argv[0].a_w.w_float);
+ } else {
+ post("* OSC-route: unrecognized atom type!");
+ }
+ }
+ // ExitCallback();
+}
+
+
+void OSCroute_anything(t_OSCroute *x, t_symbol *s, int argc, t_atom *argv) {
+ // EnterCallback();
+ OSCroute_doanything(x, s, argc, argv);
+ // ExitCallback();
+}
+
+
+
+
+void OSCroute_doanything(t_OSCroute *x, t_symbol *s, int argc, t_atom *argv) {
+ char *pattern, *nextSlash;
+ int i;
+ int matchedAnything;
+ // post("*** OSCroute_anything(s %s, argc %ld)", s->s_name, (long) argc);
+
+ pattern = s->s_name;
+ if (pattern[0] != '/') {
+ post("* OSC-route: invalid message pattern %s does not begin with /", s->s_name);
+ outlet_anything(x->x_outlets[x->x_num], s, argc, argv);
+ return;
+ }
+
+ matchedAnything = 0;
+
+ nextSlash = NextSlashOrNull(pattern+1);
+ if (*nextSlash == '\0') {
+ /* last level of the address, so we'll output the argument list */
+
+
+#ifdef NULL_IS_DIFFERENT_FROM_BANG
+ if (argc==0) {
+ post("* OSC-route: why are you matching one level pattern %s with no args?",
+ pattern);
+ return;
+ }
+#endif
+
+ for (i = 0; i < x->x_num; ++i) {
+ if (PatternMatch(pattern+1, x->x_prefixes[i]+1)) {
+ ++matchedAnything;
+
+ // I hate stupid Max lists with a special first element
+ if (argc == 0) {
+ outlet_bang(x->x_outlets[i]);
+ } else if (argv[0].a_type == A_SYMBOL) {
+ // Promote the symbol that was argv[0] to the special symbol
+ outlet_anything(x->x_outlets[i], argv[0].a_w.w_symbol, argc-1, argv+1);
+ } else if (argc > 1) {
+ // Multiple arguments starting with a number, so naturally we have
+ // to use a special function to output this "list", since it's what
+ // Max originally meant by "list".
+ outlet_list(x->x_outlets[i], 0L, argc, argv);
+ } else {
+ // There was only one argument, and it was a number, so we output it
+ // not as a list
+/* if (argv[0].a_type == A_LONG) { */
+
+/* outlet_int(x->x_outlets[i], argv[0].a_w.w_long); */
+ // } else
+ if (argv[0].a_type == A_FLOAT) {
+
+ outlet_float(x->x_outlets[i], argv[0].a_w.w_float);
+ } else {
+ post("* OSC-route: unrecognized atom type!");
+ }
+ }
+ }
+ }
+ } else {
+ /* There's more address after this part, so our output list will begin with
+ the next slash. */
+ t_symbol *restOfPattern = 0; /* avoid the gensym unless we have to output */
+ char patternBegin[1000];
+
+
+ /* Get the first level of the incoming pattern to match against all our prefixes */
+ StrCopyUntilSlash(patternBegin, pattern+1);
+
+ for (i = 0; i < x->x_num; ++i) {
+ if (PatternMatch(patternBegin, x->x_prefixes[i]+1)) {
+ ++matchedAnything;
+ if (restOfPattern == 0) {
+ restOfPattern = gensym(nextSlash);
+ }
+ outlet_anything(x->x_outlets[i], restOfPattern, argc, argv);
+ }
+ }
+ }
+
+ if (x->x_complainmode) {
+ if (!matchedAnything) {
+ post("* OSC-route: pattern %s did not match any prefixes", pattern);
+ }
+ }
+
+ // output unmatched data on rightmost outlet a la normal 'route' object, jdl 20020908
+ if (!matchedAnything) {
+ outlet_anything(x->x_outlets[x->x_num], s, argc, argv);
+ }
+
+
+}
+
+static char *NextSlashOrNull(char *p) {
+ while (*p != '/' && *p != '\0') {
+ p++;
+ }
+ return p;
+}
+
+static void StrCopyUntilSlash(char *target, const char *source) {
+ while (*source != '/' && *source != '\0') {
+ *target = *source;
+ ++target;
+ ++source;
+ }
+ *target = 0;
+}
+
+static int MyStrCopy(char *target, const char *source) {
+ int i = 0;
+ while (*source != '\0') {
+ *target = *source;
+ ++target;
+ ++source;
+ ++i;
+ }
+ *target = 0;
+ return i;
+}
+
+
+
+void OSCroute_allmessages(t_OSCroute *x, t_symbol *s, int argc, t_atom *argv) {
+ int i;
+ t_symbol *prefixSymbol = 0;
+ char prefixBuf[1000];
+ char *endOfPrefix;
+ t_atom a[1];
+
+ if (argc >= 1 && argv[0].a_type == A_SYMBOL) {
+ prefixSymbol = argv[0].a_w.w_symbol;
+ endOfPrefix = prefixBuf + MyStrCopy(prefixBuf,
+ prefixSymbol->s_name);
+ } else {
+ prefixSymbol = ps_emptySymbol;
+ prefixBuf[0] = '\0';
+ endOfPrefix = prefixBuf;
+ }
+
+
+ for (i = 0; i < x->x_num; ++i) {
+ post("OSC: %s%s", prefixSymbol->s_name, x->x_prefixes[i]);
+ MyStrCopy(endOfPrefix, x->x_prefixes[i]);
+ SETSYMBOL(a, gensym(prefixBuf));
+ outlet_anything(x->x_outlets[i], s, 1, a);
+ }
+}
+
+
+/* --------------------------------------------------- */
+
+
+
+static const char *theWholePattern; /* Just for warning messages */
+
+static Boolean MatchBrackets (const char *pattern, const char *test);
+static Boolean MatchList (const char *pattern, const char *test);
+
+Boolean PatternMatch (const char * pattern, const char * test) {
+ theWholePattern = pattern;
+
+ if (pattern == 0 || pattern[0] == 0) {
+ return test[0] == 0;
+ }
+
+ if (test[0] == 0) {
+ if (pattern[0] == '*')
+ return PatternMatch (pattern+1,test);
+ else
+ return FALSE;
+ }
+
+ switch (pattern[0]) {
+ case 0 : return test[0] == 0;
+ case '?' : return PatternMatch (pattern + 1, test + 1);
+ case '*' :
+ if (PatternMatch (pattern+1, test)) {
+ return TRUE;
+ } else {
+ return PatternMatch (pattern, test+1);
+ }
+ case ']' :
+ case '}' :
+ OSCWarning("Spurious %c in pattern \".../%s/...\"",pattern[0], theWholePattern);
+ return FALSE;
+ case '[' :
+ return MatchBrackets (pattern,test);
+ case '{' :
+ return MatchList (pattern,test);
+ case '\\' :
+ if (pattern[1] == 0) {
+ return test[0] == 0;
+ } else if (pattern[1] == test[0]) {
+ return PatternMatch (pattern+2,test+1);
+ } else {
+ return FALSE;
+ }
+ default :
+ if (pattern[0] == test[0]) {
+ return PatternMatch (pattern+1,test+1);
+ } else {
+ return FALSE;
+ }
+ }
+}
+
+
+/* we know that pattern[0] == '[' and test[0] != 0 */
+
+static Boolean MatchBrackets (const char *pattern, const char *test) {
+ Boolean result;
+ Boolean negated = FALSE;
+ const char *p = pattern;
+
+ if (pattern[1] == 0) {
+ OSCWarning("Unterminated [ in pattern \".../%s/...\"", theWholePattern);
+ return FALSE;
+ }
+
+ if (pattern[1] == '!') {
+ negated = TRUE;
+ p++;
+ }
+
+ while (*p != ']') {
+ if (*p == 0) {
+ OSCWarning("Unterminated [ in pattern \".../%s/...\"", theWholePattern);
+ return FALSE;
+ }
+ if (p[1] == '-' && p[2] != 0) {
+ if (test[0] >= p[0] && test[0] <= p[2]) {
+ result = !negated;
+ goto advance;
+ }
+ }
+ if (p[0] == test[0]) {
+ result = !negated;
+ goto advance;
+ }
+ p++;
+ }
+
+ result = negated;
+
+advance:
+
+ if (!result)
+ return FALSE;
+
+ while (*p != ']') {
+ if (*p == 0) {
+ OSCWarning("Unterminated [ in pattern \".../%s/...\"", theWholePattern);
+ return FALSE;
+ }
+ p++;
+ }
+
+ return PatternMatch (p+1,test+1);
+}
+
+static Boolean MatchList (const char *pattern, const char *test) {
+
+ const char *restOfPattern, *tp = test;
+
+
+ for(restOfPattern = pattern; *restOfPattern != '}'; restOfPattern++) {
+ if (*restOfPattern == 0) {
+ OSCWarning("Unterminated { in pattern \".../%s/...\"", theWholePattern);
+ return FALSE;
+ }
+ }
+
+ restOfPattern++; /* skip close curly brace */
+
+
+ pattern++; /* skip open curly brace */
+
+ while (1) {
+
+ if (*pattern == ',') {
+ if (PatternMatch (restOfPattern, tp)) {
+ return TRUE;
+ } else {
+ tp = test;
+ ++pattern;
+ }
+ } else if (*pattern == '}') {
+ return PatternMatch (restOfPattern, tp);
+ } else if (*pattern == *tp) {
+ ++pattern;
+ ++tp;
+ } else {
+ tp = test;
+ while (*pattern != ',' && *pattern != '}') {
+ pattern++;
+ }
+ if (*pattern == ',') {
+ pattern++;
+ }
+ }
+ }
+
+}
+
+
+
diff --git a/apps/plugins/pdbox/PDa/extra/README b/apps/plugins/pdbox/PDa/extra/README
new file mode 100644
index 0000000000..6e0b4a1e67
--- /dev/null
+++ b/apps/plugins/pdbox/PDa/extra/README
@@ -0,0 +1,24 @@
+PDa - externals
+===============
+
+This is a collection of selected externals for PDa. The externals are
+all copyright by their authors, check out the copyright notice in
+each of the files.
+
+I have changed some of the files a bit, so the bugs are most likely my
+fault. Send feedback and wishes to
+
+geiger <AT> xdv dot org
+
+PDa - externals
+===============
+
+This is a collection of selected externals for PDa. The externals are
+all copyright by their authors, check out the copyright notice in
+each of the files.
+
+I have changed some of the files a bit, so the bugs are most likely my
+fault. Send feedback and wishes to
+
+geiger <AT> xdv dot org
+
diff --git a/apps/plugins/pdbox/PDa/extra/bandpass-help.pd b/apps/plugins/pdbox/PDa/extra/bandpass-help.pd
new file mode 100644
index 0000000000..65d41eafad
--- /dev/null
+++ b/apps/plugins/pdbox/PDa/extra/bandpass-help.pd
@@ -0,0 +1,34 @@
+#N canvas 428 285 240 300 8;
+#X obj 24 78 noise~;
+#X obj 15 215 dac~;
+#X obj 24 167 biquad~;
+#X floatatom 67 76 5 0 0 0 - - -;
+#X floatatom 83 111 5 0 0 0 - - -;
+#X obj 67 138 bandpass 600 10;
+#X text 77 97 bandwidth: 100 = 1 octave;
+#X text 67 58 frequency;
+#X text 8 11 Calculation of biquad coefficients;
+#X text 7 21 ==================================;
+#X connect 0 0 2 0;
+#X connect 2 0 1 0;
+#X connect 2 0 1 1;
+#X connect 3 0 5 0;
+#X connect 4 0 5 1;
+#X connect 5 0 2 0;
+#N canvas 428 285 240 300 8;
+#X obj 24 78 noise~;
+#X obj 15 215 dac~;
+#X obj 24 167 biquad~;
+#X floatatom 67 76 5 0 0 0 - - -;
+#X floatatom 83 111 5 0 0 0 - - -;
+#X obj 67 138 bandpass 600 10;
+#X text 77 97 bandwidth: 100 = 1 octave;
+#X text 67 58 frequency;
+#X text 8 11 Calculation of biquad coefficients;
+#X text 7 21 ==================================;
+#X connect 0 0 2 0;
+#X connect 2 0 1 0;
+#X connect 2 0 1 1;
+#X connect 3 0 5 0;
+#X connect 4 0 5 1;
+#X connect 5 0 2 0;
diff --git a/apps/plugins/pdbox/PDa/extra/bandpass.c b/apps/plugins/pdbox/PDa/extra/bandpass.c
new file mode 100644
index 0000000000..6de56d6174
--- /dev/null
+++ b/apps/plugins/pdbox/PDa/extra/bandpass.c
@@ -0,0 +1,172 @@
+
+/* (C) Guenter Geiger <geiger@epy.co.at> */
+
+
+/*
+
+ These filter coefficients computations are taken from
+ http://www.harmony-central.com/Computer/Programming/Audio-EQ-Cookbook.txt
+
+ written by Robert Bristow-Johnson
+
+*/
+
+#include "m_pd.h"
+#ifdef NT
+#pragma warning( disable : 4244 )
+#pragma warning( disable : 4305 )
+#endif
+#include <math.h>
+#include "filters.h"
+
+/* ------------------- bandpass ----------------------------*/
+
+static t_class *bandpass_class;
+
+void bandpass_bang(t_rbjfilter *x)
+{
+ t_atom at[5];
+ t_float omega = e_omega(x->x_freq,x->x_rate);
+ t_float alpha = e_alpha(x->x_bw* 0.01,omega);
+ t_float b1 = 0.;
+ t_float b0 = alpha;
+ t_float b2 = -alpha;
+ t_float a0 = 1 + alpha;
+ t_float a1 = -2.*cos(omega);
+ t_float a2 = 1 - alpha;
+
+/* post("bang %f %f %f",x->x_freq, x->x_gain, x->x_bw); */
+
+ if (!check_stability(-a1/a0,-a2/a0,b0/a0,b1/a0,b2/a0)) {
+ post("bandpass: filter unstable -> resetting");
+ a0=1.;a1=0.;a2=0.;
+ b0=1.;b1=0.;b2=0.;
+ }
+
+ SETFLOAT(at,-a1/a0);
+ SETFLOAT(at+1,-a2/a0);
+ SETFLOAT(at+2,b0/a0);
+ SETFLOAT(at+3,b1/a0);
+ SETFLOAT(at+4,b2/a0);
+
+ outlet_list(x->x_obj.ob_outlet,&s_list,5,at);
+}
+
+
+void bandpass_float(t_rbjfilter *x,t_floatarg f)
+{
+ x->x_freq = f;
+ bandpass_bang(x);
+}
+
+
+static void *bandpass_new(t_floatarg f,t_floatarg bw)
+{
+ t_rbjfilter *x = (t_rbjfilter *)pd_new(bandpass_class);
+
+ x->x_rate = 44100.0;
+ outlet_new(&x->x_obj,&s_float);
+/* floatinlet_new(&x->x_obj, &x->x_gain); */
+ floatinlet_new(&x->x_obj, &x->x_bw);
+ if (f > 0.) x->x_freq = f;
+ if (bw > 0.) x->x_bw = bw;
+ return (x);
+}
+
+
+void bandpass_setup(void)
+{
+ bandpass_class = class_new(gensym("bandpass"), (t_newmethod)bandpass_new, 0,
+ sizeof(t_rbjfilter), 0,A_DEFFLOAT,A_DEFFLOAT,0);
+ class_addbang(bandpass_class,bandpass_bang);
+ class_addfloat(bandpass_class,bandpass_float);
+}
+
+
+
+
+/* (C) Guenter Geiger <geiger@epy.co.at> */
+
+
+/*
+
+ These filter coefficients computations are taken from
+ http://www.harmony-central.com/Computer/Programming/Audio-EQ-Cookbook.txt
+
+ written by Robert Bristow-Johnson
+
+*/
+
+#include "m_pd.h"
+#ifdef NT
+#pragma warning( disable : 4244 )
+#pragma warning( disable : 4305 )
+#endif
+#include <math.h>
+#include "filters.h"
+
+/* ------------------- bandpass ----------------------------*/
+
+static t_class *bandpass_class;
+
+void bandpass_bang(t_rbjfilter *x)
+{
+ t_atom at[5];
+ t_float omega = e_omega(x->x_freq,x->x_rate);
+ t_float alpha = e_alpha(x->x_bw* 0.01,omega);
+ t_float b1 = 0.;
+ t_float b0 = alpha;
+ t_float b2 = -alpha;
+ t_float a0 = 1 + alpha;
+ t_float a1 = -2.*cos(omega);
+ t_float a2 = 1 - alpha;
+
+/* post("bang %f %f %f",x->x_freq, x->x_gain, x->x_bw); */
+
+ if (!check_stability(-a1/a0,-a2/a0,b0/a0,b1/a0,b2/a0)) {
+ post("bandpass: filter unstable -> resetting");
+ a0=1.;a1=0.;a2=0.;
+ b0=1.;b1=0.;b2=0.;
+ }
+
+ SETFLOAT(at,-a1/a0);
+ SETFLOAT(at+1,-a2/a0);
+ SETFLOAT(at+2,b0/a0);
+ SETFLOAT(at+3,b1/a0);
+ SETFLOAT(at+4,b2/a0);
+
+ outlet_list(x->x_obj.ob_outlet,&s_list,5,at);
+}
+
+
+void bandpass_float(t_rbjfilter *x,t_floatarg f)
+{
+ x->x_freq = f;
+ bandpass_bang(x);
+}
+
+
+static void *bandpass_new(t_floatarg f,t_floatarg bw)
+{
+ t_rbjfilter *x = (t_rbjfilter *)pd_new(bandpass_class);
+
+ x->x_rate = 44100.0;
+ outlet_new(&x->x_obj,&s_float);
+/* floatinlet_new(&x->x_obj, &x->x_gain); */
+ floatinlet_new(&x->x_obj, &x->x_bw);
+ if (f > 0.) x->x_freq = f;
+ if (bw > 0.) x->x_bw = bw;
+ return (x);
+}
+
+
+void bandpass_setup(void)
+{
+ bandpass_class = class_new(gensym("bandpass"), (t_newmethod)bandpass_new, 0,
+ sizeof(t_rbjfilter), 0,A_DEFFLOAT,A_DEFFLOAT,0);
+ class_addbang(bandpass_class,bandpass_bang);
+ class_addfloat(bandpass_class,bandpass_float);
+}
+
+
+
diff --git a/apps/plugins/pdbox/PDa/extra/dumpOSC.c b/apps/plugins/pdbox/PDa/extra/dumpOSC.c
new file mode 100644
index 0000000000..37767c2b03
--- /dev/null
+++ b/apps/plugins/pdbox/PDa/extra/dumpOSC.c
@@ -0,0 +1,1998 @@
+/*
+Written by Matt Wright and Adrian Freed, The Center for New Music and
+Audio Technologies, University of California, Berkeley. Copyright (c)
+1992,93,94,95,96,97,98,99,2000,01,02,03,04 The Regents of the University of
+California (Regents).
+
+Permission to use, copy, modify, distribute, and distribute modified versions
+of this software and its documentation without fee and without a signed
+licensing agreement, is hereby granted, provided that the above copyright
+notice, this paragraph and the following two paragraphs appear in all copies,
+modifications, and distributions.
+
+IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
+SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING
+OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF REGENTS HAS
+BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE. THE SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED
+HEREUNDER IS PROVIDED "AS IS". REGENTS HAS NO OBLIGATION TO PROVIDE
+MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
+
+
+The OSC webpage is http://cnmat.cnmat.berkeley.edu/OpenSoundControl
+*/
+
+
+ /*
+
+ dumpOSC.c
+ server that displays OpenSoundControl messages sent to it
+ for debugging client udp and UNIX protocol
+
+ by Matt Wright, 6/3/97
+ modified from dumpSC.c, by Matt Wright and Adrian Freed
+
+ version 0.2: Added "-silent" option a.k.a. "-quiet"
+
+ version 0.3: Incorporated patches from Nicola Bernardini to make
+ things Linux-friendly. Also added ntohl() in the right places
+ to support little-endian architectures.
+
+
+
+ compile:
+ cc -o dumpOSC dumpOSC.c
+
+ to-do:
+
+ More robustness in saying exactly what's wrong with ill-formed
+ messages. (If they don't make sense, show exactly what was
+ received.)
+
+ Time-based features: print time-received for each packet
+
+ Clean up to separate OSC parsing code from socket/select stuff
+
+ pd: branched from http://www.cnmat.berkeley.edu/OpenSoundControl/src/dumpOSC/dumpOSC.c
+ -------------
+ -- added pd functions
+ -- socket is made differently than original via pd mechanisms
+ -- tweaks for Win32 www.zeggz.com/raf 13-April-2002
+ -- the OSX changes from cnmat didnt make it here yet but this compiles
+ on OSX anyway.
+
+*/
+
+#if HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "m_pd.h"
+//#include "m_imp.h"
+#include "s_stuff.h"
+
+/* declarations */
+
+// typedef void (*t_fdpollfn)(void *ptr, int fd);
+void sys_addpollfn(int fd, t_fdpollfn fn, void *ptr);
+
+
+#if defined(__sgi) || defined(__linux) || defined(WIN32) || defined(__APPLE__)
+
+#ifdef WIN32
+ #include "OSC-common.h"
+ #include <winsock2.h>
+ #include <string.h>
+ #include <stdlib.h>
+ #include <fcntl.h>
+ #include <sys/types.h>
+ #include <sys/stat.h>
+ #include <ctype.h>
+ #include <signal.h>
+#else
+ #include <stdio.h>
+ #include <string.h>
+ #include <stdlib.h>
+ #include <unistd.h>
+ #include <fcntl.h>
+ #include <sys/types.h>
+ #include <sys/stat.h>
+ #include <netinet/in.h>
+ #include <rpc/rpc.h>
+ #include <sys/socket.h>
+ #include <sys/un.h>
+ #include <sys/times.h>
+ #include <sys/param.h>
+ #include <sys/time.h>
+ #include <sys/ioctl.h>
+ #include <ctype.h>
+ #include <arpa/inet.h>
+ #include <netdb.h>
+ #include <pwd.h>
+ #include <signal.h>
+ #include <grp.h>
+ #include <sys/file.h>
+ //#include <sys/prctl.h>
+
+ #ifdef NEED_SCHEDCTL_AND_LOCK
+ #include <sys/schedctl.h>
+ #include <sys/lock.h>
+ #endif
+#endif
+
+
+char *htm_error_string;
+typedef int Boolean;
+typedef void *OBJ;
+
+typedef struct ClientAddressStruct {
+ struct sockaddr_in cl_addr;
+ int clilen;
+ int sockfd;
+} *ClientAddr;
+
+typedef unsigned long long osc_time_t;
+
+Boolean ShowBytes = FALSE;
+Boolean Silent = FALSE;
+
+/* Declarations */
+#ifndef WIN32
+static int unixinitudp(int chan);
+#endif
+
+static int initudp(int chan);
+static void closeudp(int sockfd);
+Boolean ClientReply(int packetsize, void *packet, int socketfd,
+ void *clientaddresspointer, int clientaddressbufferlength);
+void sgi_CleanExit(void);
+Boolean sgi_HaveToQuit(void);
+int RegisterPollingDevice(int fd, void (*callbackfunction)(int , void *), void *dummy);
+static void catch_sigint();
+static int Synthmessage(char *m, int n, void *clientdesc, int clientdesclength, int fd) ;
+char *DataAfterAlignedString(char *string, char *boundary) ;
+Boolean IsNiceString(char *string, char *boundary) ;
+void complain(char *s, ...);
+
+#define MAXMESG 32768
+static char mbuf[MAXMESG];
+
+/* ----------------------------- dumpOSC ------------------------- */
+
+#define MAXOUTAT 50
+
+static t_class *dumpOSC_class;
+
+typedef struct _dumpOSC
+{
+ t_object x_obj;
+ t_outlet *x_msgout;
+ t_outlet *x_connectout;
+ t_atom x_outat[MAXOUTAT];
+ int x_outatc;
+ t_binbuf *x_b;
+ int x_connectsocket;
+ int x_nconnections;
+ int x_udp;
+ struct sockaddr_in x_server;
+ int x_clilen;
+} t_dumpOSC;
+
+void dumpOSC_ParsePacket(t_dumpOSC *x, char *buf, int n, ClientAddr returnAddr);
+Boolean dumpOSC_SendReply(char *buf, int n, void *clientDesc, int clientDescLenght, int fd);
+static void dumpOSC_Smessage(t_dumpOSC *x, char *address, void *v, int n, ClientAddr returnAddr);
+static void dumpOSC_PrintTypeTaggedArgs(t_dumpOSC *x, void *v, int n);
+static void dumpOSC_PrintHeuristicallyTypeGuessedArgs(t_dumpOSC *x, void *v, int n, int skipComma);
+
+static void dumpOSC_read(t_dumpOSC *x, int sockfd) {
+ int clilen = x->x_clilen;
+ int n;
+ struct ClientAddressStruct ras;
+ ClientAddr ra = &ras;
+
+ //catchupflag= FALSE;
+
+/* if (ShowBytes) { */
+/* int i; */
+/* printf("%d byte message:\n", n); */
+/* for (i = 0; i < n; ++i) { */
+/* printf(" %x (%c)\t", m[i], m[i]); */
+/* if (i%4 == 3) printf("\n"); */
+/* } */
+/* printf("\n"); */
+/* } */
+
+ // return catchupflag;
+ //struct sockaddr_in x->x_server;
+ //while( (n = recvfrom(sockfd, mbuf, MAXMESG, 0, &cl_addr, &clilen)) >0)
+ // while((
+
+ #ifdef WIN32
+ if ((n = recvfrom(sockfd, mbuf, MAXMESG, 0, (SOCKADDR*)&x->x_server, &clilen)) >0)
+ #else
+ if ((n = recvfrom(sockfd, mbuf, MAXMESG, 0, (struct sockaddr *)&x->x_server, &clilen)) >0)
+ #endif
+ {
+ //int r;
+ ras.cl_addr = *((struct sockaddr_in *) &x->x_server);
+ ras.clilen = x->x_clilen;
+ ras.sockfd = x->x_connectsocket;
+
+ #ifdef DEBUG
+ printf("dumpOSC_read: received UDP packet of length %d\n", n);
+ #endif
+
+ if(!dumpOSC_SendReply(mbuf, n, &x->x_server, clilen, sockfd))
+ {
+ dumpOSC_ParsePacket(x, mbuf, n, ra);
+ }
+ //r = Synthmessage(mbuf, n, &x->x_server, clilen, sockfd);
+ //post ("%d", r);
+ //outlet_anything(x->x_msgout, at[msg].a_w.w_symbol,
+ // emsg-msg-1, at + msg + 1);
+ // outlet_list(x->x_msgout, 0, n, mbuf);
+ //if( sgi_HaveToQuit()) goto out;
+ //if(r>0) goto back;
+ //clilen = maxclilen;
+ }
+}
+
+static void *dumpOSC_new(t_symbol *compatflag,
+ t_floatarg fportno) {
+ t_dumpOSC *x;
+ struct sockaddr_in server;
+ int clilen=sizeof(server);
+ int sockfd;
+ int portno=fportno;
+ int udp = 1;
+
+ //x->x_b = binbuf_new();
+ //x->x_outat = binbuf_getvec(x->x_b);
+
+ //{{raf}} pointer not valid yet...moving this down
+ //x->x_outatc = 0; {{raf}}
+
+ /* create a socket */
+ if ((sockfd = socket(AF_INET, (udp ? SOCK_DGRAM : SOCK_STREAM), 0)) == -1)
+ {
+ sys_sockerror("socket");
+ return (0);
+ }
+
+ server.sin_family = AF_INET;
+ server.sin_addr.s_addr = INADDR_ANY;
+ /* assign server port number */
+ server.sin_port = htons((u_short)portno);
+ /* name the socket */
+ if (bind(sockfd, (struct sockaddr *)&server, sizeof(server)) < 0)
+ {
+ sys_sockerror("bind");
+ sys_closesocket(sockfd);
+ return (0);
+ }
+
+ x = (t_dumpOSC *)pd_new(dumpOSC_class);
+ x->x_outatc = 0; // {{raf}} now pointer is valid (less invalid)
+
+ x->x_msgout = outlet_new(&x->x_obj, &s_anything);
+
+ // if (udp) /* datagram protocol */
+ {
+
+ sys_addpollfn(sockfd, (t_fdpollfn)dumpOSC_read, x);
+ x->x_connectout = 0;
+ }
+ // else /* streaming protocol */
+ /* { */
+ /* if (listen(sockfd, 5) < 0) */
+ /* { */
+ /* sys_sockerror("listen"); */
+ /* sys_closesocket(sockfd); */
+ /* sockfd = -1; */
+ /* } */
+ /* else */
+ /* { */
+ /* sys_addpollfn(sockfd, (t_fdpollfn)dumpOSC_connectpoll, x); */
+ /* x->x_connectout = outlet_new(&x->x_obj, &s_float); */
+ /* } */
+ /* } */
+
+ x->x_connectsocket = sockfd;
+ x->x_server = server;
+ x->x_clilen = clilen;
+ x->x_nconnections = 0;
+ x->x_udp = udp;
+
+ return (x);
+}
+
+static void dumpOSC_free(t_dumpOSC *x)
+{
+ /* LATER make me clean up open connections */
+ if (x->x_connectsocket >= 0)
+ {
+ sys_rmpollfn(x->x_connectsocket);
+ sys_closesocket(x->x_connectsocket);
+ }
+}
+
+#ifdef WIN32
+OSC_API void dumpOSC_setup(void)
+#else
+void dumpOSC_setup(void)
+#endif
+{
+ dumpOSC_class = class_new(gensym("dumpOSC"),
+ (t_newmethod)dumpOSC_new, (t_method)dumpOSC_free,
+ sizeof(t_dumpOSC), CLASS_NOINLET, A_DEFFLOAT, A_DEFFLOAT,
+ A_DEFSYM, 0);
+ class_sethelpsymbol(dumpOSC_class, gensym("dumpOSC-help.pd"));
+}
+
+
+#ifndef WIN32
+ #define UNIXDG_PATH "/tmp/htm"
+ #define UNIXDG_TMP "/tmp/htm.XXXXXX"
+ static int unixinitudp(int chan)
+ {
+ struct sockaddr_un serv_addr;
+ int sockfd;
+
+ if((sockfd = socket(AF_UNIX, SOCK_DGRAM, 0)) < 0)
+ return sockfd;
+
+ bzero((char *)&serv_addr, sizeof(serv_addr));
+ serv_addr.sun_family = AF_UNIX;
+ strcpy(serv_addr.sun_path, UNIXDG_PATH);
+ sprintf(serv_addr.sun_path+strlen(serv_addr.sun_path), "%d", chan);
+ unlink(serv_addr.sun_path);
+ if(bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr.sun_family)+strlen(serv_addr.sun_path)) < 0)
+ {
+ perror("unable to bind\n");
+ return -1;
+ }
+
+ fcntl(sockfd, F_SETFL, FNDELAY);
+ return sockfd;
+ }
+#endif // #ifndef WIN32
+
+
+
+static int initudp(int chan)
+{
+
+#ifdef WIN32
+ struct sockaddr_in serv_addr;
+ unsigned int sockfd;
+ ULONG nonBlocking = (ULONG) TRUE;
+
+ if( (sockfd = socket(AF_INET, SOCK_DGRAM, 0)) != INVALID_SOCKET ) {
+ ZeroMemory((char *)&serv_addr, sizeof(serv_addr));
+ serv_addr.sin_family = AF_INET;
+ serv_addr.sin_addr.s_addr = htonl(INADDR_ANY);
+ serv_addr.sin_port = htons(chan);
+ if(bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) >= 0) {
+ // set for non-blocking mode
+ if(ioctlsocket(sockfd, FIONBIO, &nonBlocking) == SOCKET_ERROR) {
+ perror("unable to set non-blocking\n");
+ return -1;
+ }
+ }
+ else { perror("unable to bind\n"); return -1; }
+ }
+ return (sockfd == INVALID_SOCKET ? -1 : (int)sockfd);
+#else
+ struct sockaddr_in serv_addr;
+ int sockfd;
+
+ if((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
+ return sockfd;
+
+ bzero((char *)&serv_addr, sizeof(serv_addr));
+ serv_addr.sin_family = AF_INET;
+ serv_addr.sin_addr.s_addr = htonl(INADDR_ANY);
+ serv_addr.sin_port = htons(chan);
+
+ if(bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0)
+ {
+ perror("unable to bind\n");
+ return -1;
+ }
+
+ fcntl(sockfd, F_SETFL, FNDELAY);
+ return sockfd;
+#endif
+}
+
+
+
+
+
+
+
+
+static void closeudp(int sockfd) {
+ #ifdef WIN32
+ closesocket(sockfd);
+ #else
+ close(sockfd);
+ #endif
+}
+
+static Boolean catchupflag=FALSE;
+Boolean ClientReply(int packetsize, void *packet, int socketfd,
+ void *clientaddresspointer, int clientaddressbufferlength)
+{
+ if(!clientaddresspointer) return FALSE;
+ catchupflag= TRUE;
+ return packetsize==sendto(socketfd, packet, packetsize, 0, clientaddresspointer, clientaddressbufferlength);
+}
+
+static Boolean exitflag= FALSE;
+void sgi_CleanExit(void) {
+ exitflag = TRUE;
+}
+
+Boolean sgi_HaveToQuit(void) {
+ return exitflag;
+}
+
+
+/* file descriptor poll table */
+static int npolldevs =0;
+typedef struct polldev
+{
+ int fd;
+ void (*callbackfunction)(int , void *);
+ void *dummy;
+} polldev;
+#define TABMAX 8
+static polldev polldevs[TABMAX];
+
+
+/* Register a device (referred to by a file descriptor that the caller
+ should have already successfully obtained from a system call) to be
+ polled as real-time constraints allowed.
+
+ When a select(2) call indicates activity on the file descriptor, the
+ callback function is called with the file descripter as first
+ argument and the given dummy argument (presumably a pointer to the
+ instance variables associated with the device).
+*/
+int RegisterPollingDevice(int fd, void (*callbackfunction)(int , void *), void *dummy)
+{
+ if(npolldevs<TABMAX)
+ {
+ polldevs[npolldevs].fd = fd;
+ polldevs[npolldevs].callbackfunction = callbackfunction;
+ polldevs[npolldevs].dummy = dummy;
+ }
+ else return -1;
+ return npolldevs++;
+}
+
+static int caught_sigint;
+
+static void catch_sigint() {
+ caught_sigint = 1;
+}
+static int sockfd, usockfd;
+
+
+void PrintClientAddr(ClientAddr CA) {
+ unsigned long addr = CA->cl_addr.sin_addr.s_addr;
+ printf("Client address %p:\n", CA);
+ printf(" clilen %d, sockfd %d\n", CA->clilen, CA->sockfd);
+ printf(" sin_family %d, sin_port %d\n", CA->cl_addr.sin_family,
+ CA->cl_addr.sin_port);
+ printf(" address: (%x) %s\n", addr, inet_ntoa(CA->cl_addr.sin_addr));
+
+ printf(" sin_zero = \"%c%c%c%c%c%c%c%c\"\n",
+ CA->cl_addr.sin_zero[0],
+ CA->cl_addr.sin_zero[1],
+ CA->cl_addr.sin_zero[2],
+ CA->cl_addr.sin_zero[3],
+ CA->cl_addr.sin_zero[4],
+ CA->cl_addr.sin_zero[5],
+ CA->cl_addr.sin_zero[6],
+ CA->cl_addr.sin_zero[7]);
+
+ printf("\n");
+}
+
+//*******************
+
+void WriteTime(char* dst, osc_time_t osctime)
+{
+ *(int32_t*)dst = htonl((int32_t)(osctime >> 32));
+ *(int32_t*)(dst+4) = htonl((int32_t)osctime);
+}
+
+void WriteMode(char* dst)
+{
+ *(int32_t*)dst = htonl(0);
+}
+
+osc_time_t ReadTime(const char* src)
+{
+ osc_time_t osctime = ntohl(*(int32_t*)src);
+ return (osctime << 32) + ntohl(*(int32_t*)(src+4));
+}
+
+double TimeToSeconds(osc_time_t osctime)
+{
+ return (double)osctime * 2.3283064365386962890625e-10 /* 1/2^32 */;
+}
+
+int timeRound(double x)
+{
+ return x >= 0.0 ? x+0.5 : x-0.5;
+}
+/*
+void WriteLogicalTime(char* dst)
+{
+ static double startTime = -1.0;
+ double sTime;
+
+ // Initialisierung der Startzeit.
+ // Knnte effizienter (ohne 'if') auch irgendwo vorher passieren.
+ // Knnte wahrscheinlich auch 0.0 sein.
+ if (startTime < 0.0) {
+ startTime = clock_getlogicaltime();
+ }
+
+ sTime = clock_gettimesince(startTime) * 0.001;
+ *(int32_t*)dst = hton'K l((int32_t)sTime);
+ *(int32_t*)(dst+4) = htonl((int32_t)(4294967296.0 * sTime));
+}
+*/
+
+void WriteLogicalTime(char* dst)
+{
+ double sTime = clock_gettimesince(19230720) / 1000.0;
+ double tau = sTime - timeRound(sTime);
+
+ //fprintf(stderr, "sSec = %f tau = %f\n", sTime, tau);
+
+ *(int32_t*)dst = htonl((int32_t)(sTime));
+ *(int32_t*)(dst+4) = htonl((int32_t)(4294967296 * tau));
+}
+
+Boolean dumpOSC_SendReply(char *buf, int n, void *clientDesc, int clientDescLenght, int fd)
+{
+ if((n == 24) && (strcmp(buf, "#time") == 0))
+ {
+ osc_time_t t0, t1, t2;
+ double dt0, dt1, dt2;
+
+ WriteMode(buf+6);
+
+ t0 = ReadTime(buf+8);
+
+ WriteLogicalTime(buf+16);
+ t1 = ReadTime(buf+16); // reverse
+ dt0 = TimeToSeconds(t0); // client time
+ dt1 = TimeToSeconds(t1); // server time
+
+ // fprintf(stderr, "%f\t%f\t%f\n", dt0, dt1, dt0 - dt1);
+
+ sendto(fd, buf, n, 0, (struct sockaddr *)clientDesc, clientDescLenght);
+ return TRUE;
+ }
+ else
+ {
+ return FALSE;
+ }
+}
+
+//**********************
+
+void dumpOSC_ParsePacket(t_dumpOSC *x, char *buf, int n, ClientAddr returnAddr) {
+ // t_dumpOSC *x;
+ int size, messageLen, i;
+ char *messageName;
+ char *args;
+
+ //#ifdef PRINTADDRS
+ #ifdef DEBUG
+ //PrintClientAddr(returnAddr);
+ #endif
+
+
+ if ((n%4) != 0) {
+ complain("SynthControl packet size (%d) not a multiple of 4 bytes: dropping", n);
+ return;
+ }
+
+ if ((n >= 8) && (strncmp(buf, "#bundle", 8) == 0)) {
+ /* This is a bundle message. */
+ #ifdef DEBUG
+ printf("dumpOSC_ParsePacket: bundle msg: bundles not yet supported\n");
+ #endif
+
+ if (n < 16) {
+ complain("Bundle message too small (%d bytes) for time tag", n);
+ return;
+ }
+
+ /* Print the time tag */
+ #ifdef DEBUG
+ printf("[ %lx%08lx\n", ntohl(*((unsigned long *)(buf+8))), ntohl(*((unsigned long *)(buf+12))));
+ #endif
+
+ /* Note: if we wanted to actually use the time tag as a little-endian
+ 64-bit int, we'd have to word-swap the two 32-bit halves of it */
+
+ i = 16; /* Skip "#group\0" and time tag */
+
+ while(i<n) {
+ size = ntohl(*((int *) (buf + i)));
+ if ((size % 4) != 0) {
+ complain("Bad size count %d in bundle (not a multiple of 4)", size);
+ return;
+ }
+ if ((size + i + 4) > n) {
+ complain("Bad size count %d in bundle (only %d bytes left in entire bundle)",
+ size, n-i-4);
+ return;
+ }
+
+ /* Recursively handle element of bundle */
+ dumpOSC_ParsePacket(x, buf+i+4, size, returnAddr);
+ i += 4 + size;
+ }
+
+ if (i != n) {
+ complain("This can't happen");
+ }
+ #ifdef DEBUG
+ printf("]\n");
+ #endif
+
+ }
+ else if ((n == 24) && (strcmp(buf, "#time") == 0))
+ {
+ complain("Time message: %s\n :).\n", htm_error_string);
+ return;
+
+ }
+ else
+ {
+ /* This is not a bundle message */
+
+ messageName = buf;
+ args = DataAfterAlignedString(messageName, buf+n);
+ if (args == 0) {
+ complain("Bad message name string: %s\nDropping entire message.\n",
+ htm_error_string);
+ return;
+ }
+ messageLen = args-messageName;
+ dumpOSC_Smessage(x, messageName, (void *)args, n-messageLen, returnAddr);
+ }
+}
+
+#define SMALLEST_POSITIVE_FLOAT 0.000001f
+
+static void dumpOSC_Smessage(t_dumpOSC *x, char *address, void *v, int n, ClientAddr returnAddr) {
+ char *chars = v;
+ t_atom at;
+ //t_atom myargv[50];
+
+ int myargc = x->x_outatc;
+ t_atom* mya = x->x_outat;
+ int myi;
+
+#ifdef DEBUG
+ printf("%s ", address);
+#endif
+
+ // ztoln+cvt from envgen.c, ggee-0.18 ..
+ // outlet_anything's 'symbol' gets set to address
+ // so we dont need to append address to the atomlist
+ /*
+ SETSYMBOL(mya,gensym(address));myargc++;
+ x->x_outatc = myargc;
+ */
+
+ if (n != 0) {
+ if (chars[0] == ',') {
+ if (chars[1] != ',') {
+ /* This message begins with a type-tag string */
+ dumpOSC_PrintTypeTaggedArgs(x, v, n);
+ } else {
+ /* Double comma means an escaped real comma, not a type string */
+ dumpOSC_PrintHeuristicallyTypeGuessedArgs(x, v, n, 1);
+ }
+ } else {
+ dumpOSC_PrintHeuristicallyTypeGuessedArgs(x, v, n, 0);
+ }
+ }
+
+ outlet_anything(x->x_msgout,gensym(address),x->x_outatc,(t_atom*)&x->x_outat);
+ x->x_outatc = 0;
+#ifdef DEBUG
+ printf("\n");
+#endif
+ fflush(stdout); /* Added for Sami 5/21/98 */
+}
+
+static void dumpOSC_PrintTypeTaggedArgs(t_dumpOSC *x, void *v, int n) {
+ char *typeTags, *thisType;
+ char *p;
+
+ int myargc = x->x_outatc;
+ t_atom* mya = x->x_outat;
+ int myi;
+
+ typeTags = v;
+
+ if (!IsNiceString(typeTags, typeTags+n)) {
+ /* No null-termination, so maybe it wasn't a type tag
+ string after all */
+ dumpOSC_PrintHeuristicallyTypeGuessedArgs(x, v, n, 0);
+ return;
+ }
+
+ p = DataAfterAlignedString(typeTags, typeTags+n);
+
+
+ for (thisType = typeTags + 1; *thisType != 0; ++thisType) {
+ switch (*thisType) {
+ case 'i': case 'r': case 'm': case 'c':
+#ifdef DEBUG
+ //post("integer: %d", ntohl(*((int *) p)));
+#endif
+ /* Martin Peach fix for negative floats:
+ * was: SETFLOAT(mya+myargc,ntohl(*((int *) p)));
+ * now is:
+ */
+ SETFLOAT(mya+myargc,(signed)ntohl(*((int *) p)));
+ myargc++;
+
+ p += 4;
+ break;
+
+ case 'f': {
+ int i = ntohl(*((int *) p));
+ float *floatp = ((float *) (&i));
+#ifdef DEBUG
+ post("float: %f", *floatp);
+#endif
+ SETFLOAT(mya+myargc,*floatp);
+ myargc++;
+
+ p += 4;
+ }
+ break;
+
+ case 'h': case 't':
+#ifdef DEBUG
+ printf("[A 64-bit int] ");
+#endif
+ post("[A 64-bit int] not implemented");
+
+ p += 8;
+ break;
+
+ case 'd':
+#ifdef DEBUG
+ printf("[A 64-bit float] ");
+#endif
+ post("[A 64-bit float] not implemented");
+
+ p += 8;
+ break;
+
+ case 's': case 'S':
+ if (!IsNiceString(p, typeTags+n)) {
+ post("Type tag said this arg is a string but it's not!\n");
+ return;
+ } else {
+#ifdef DEBUG
+ post("string: \"%s\"", p);
+#endif
+ SETSYMBOL(mya+myargc,gensym(p));
+ myargc++;
+ //outlet_list(x->x_msgout, 0,sizeof(p), p);
+ //outlet_anything(x->x_msgout, 0, sizeof(p), p);
+ p = DataAfterAlignedString(p, typeTags+n);
+ // append to output vector ..
+ }
+ break;
+
+ case 'T':
+#ifdef DEBUG
+ printf("[True] ");
+#endif
+ SETFLOAT(mya+myargc,1.);
+ myargc++;
+ break;
+ case 'F':
+#ifdef DEBUG
+ printf("[False] ");
+#endif
+ SETFLOAT(mya+myargc,0.);
+ myargc++;
+ break;
+ case 'N':
+#ifdef DEBUG
+ printf("[Nil]");
+#endif
+ post("sendOSC: [Nil] not implemented");
+ break;
+ case 'I':
+#ifdef DEBUG
+ printf("[Infinitum]");
+#endif
+ post("sendOSC: [Infinitum] not implemented");
+ break;
+
+ default:
+ post("sendOSC: [Unrecognized type tag %c]", *thisType);
+ // return;
+ }
+ }
+ x->x_outatc = myargc;
+}
+
+static void dumpOSC_PrintHeuristicallyTypeGuessedArgs(t_dumpOSC *x, void *v, int n, int skipComma) {
+ int i, thisi;
+ float thisf;
+ int *ints;
+ char *chars;
+ char *string, *nextString;
+
+ int myargc= x->x_outatc;
+ t_atom* mya = x->x_outat;
+ int myi;
+
+
+ /* Go through the arguments 32 bits at a time */
+ ints = v;
+ chars = v;
+
+ for (i = 0; i<n/4; ) {
+ string = &chars[i*4];
+ thisi = ntohl(ints[i]);
+ /* Reinterpret the (potentially byte-reversed) thisi as a float */
+ thisf = *(((float *) (&thisi)));
+
+ if (thisi >= -1000 && thisi <= 1000000) {
+#ifdef DEBUG
+ printf("%d ", thisi);
+#endif
+ // append to output vector ..
+ SETFLOAT(mya+myargc,(t_float) (thisi));
+ myargc++;
+ // outlet_float(x->x_msgout, thisi);
+ i++;
+ } else if (thisf >= -1000.f && thisf <= 1000000.f &&
+ (thisf <=0.0f || thisf >= SMALLEST_POSITIVE_FLOAT)) {
+#ifdef DEBUG
+ printf("%f ", thisf);
+#endif
+ // append to output vector ..
+ SETFLOAT(mya+myargc,thisf);
+ myargc++;
+ //outlet_float(x->x_msgout, thisf);
+ i++;
+ } else if (IsNiceString(string, chars+n)) {
+ nextString = DataAfterAlignedString(string, chars+n);
+#ifdef DEBUG
+ printf("\"%s\" ", (i == 0 && skipComma) ? string +1 : string);
+#endif
+ // append to output vector ..
+ SETSYMBOL(mya+myargc,gensym(string));
+ myargc++;
+ //outlet_symbol(x->x_msgout, gensym((i == 0 && skipComma) ? string +1 : string));
+ i += (nextString-string) / 4;
+ } else {
+ // unhandled .. ;)
+#ifdef DEBUG
+ printf("0x%x xx", ints[i]);
+#endif
+ i++;
+ }
+ x->x_outatc = myargc;
+ }
+}
+
+
+#define STRING_ALIGN_PAD 4
+
+char *DataAfterAlignedString(char *string, char *boundary)
+{
+ /* The argument is a block of data beginning with a string. The
+ string has (presumably) been padded with extra null characters
+ so that the overall length is a multiple of STRING_ALIGN_PAD
+ bytes. Return a pointer to the next byte after the null
+ byte(s). The boundary argument points to the character after
+ the last valid character in the buffer---if the string hasn't
+ ended by there, something's wrong.
+
+ If the data looks wrong, return 0, and set htm_error_string */
+
+ int i;
+
+ if ((boundary - string) %4 != 0) {
+ fprintf(stderr, "Internal error: DataAfterAlignedString: bad boundary\n");
+ return 0;
+ }
+
+ for (i = 0; string[i] != '\0'; i++) {
+ if (string + i >= boundary) {
+ htm_error_string = "DataAfterAlignedString: Unreasonably long string";
+ return 0;
+ }
+ }
+
+ /* Now string[i] is the first null character */
+ i++;
+
+ for (; (i % STRING_ALIGN_PAD) != 0; i++) {
+ if (string + i >= boundary) {
+ htm_error_string = "DataAfterAlignedString: Unreasonably long string";
+ return 0;
+ }
+ if (string[i] != '\0') {
+ htm_error_string = "DataAfterAlignedString: Incorrectly padded string.";
+ return 0;
+ }
+ }
+
+ return string+i;
+}
+
+Boolean IsNiceString(char *string, char *boundary)
+{
+ /* Arguments same as DataAfterAlignedString(). Is the given "string"
+ really a string? I.e., is it a sequence of isprint() characters
+ terminated with 1-4 null characters to align on a 4-byte boundary? */
+
+ int i;
+
+ if ((boundary - string) %4 != 0) {
+ fprintf(stderr, "Internal error: IsNiceString: bad boundary\n");
+ return 0;
+ }
+
+ for (i = 0; string[i] != '\0'; i++) {
+ if (!isprint(string[i])) return FALSE;
+ if (string + i >= boundary) return FALSE;
+ }
+
+ /* If we made it this far, it's a null-terminated sequence of printing characters
+ in the given boundary. Now we just make sure it's null padded... */
+
+ /* Now string[i] is the first null character */
+ i++;
+ for (; (i % STRING_ALIGN_PAD) != 0; i++) {
+ if (string[i] != '\0') return FALSE;
+ }
+
+ return TRUE;
+}
+
+
+
+
+
+
+
+
+
+#include <stdarg.h>
+void complain(char *s, ...) {
+ va_list ap;
+ va_start(ap, s);
+ fprintf(stderr, "*** ERROR: ");
+ vfprintf(stderr, s, ap);
+ fprintf(stderr, "\n");
+ va_end(ap);
+}
+
+#endif /* __sgi or LINUX or WIN32 */
+/*
+Written by Matt Wright and Adrian Freed, The Center for New Music and
+Audio Technologies, University of California, Berkeley. Copyright (c)
+1992,93,94,95,96,97,98,99,2000,01,02,03,04 The Regents of the University of
+California (Regents).
+
+Permission to use, copy, modify, distribute, and distribute modified versions
+of this software and its documentation without fee and without a signed
+licensing agreement, is hereby granted, provided that the above copyright
+notice, this paragraph and the following two paragraphs appear in all copies,
+modifications, and distributions.
+
+IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
+SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING
+OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF REGENTS HAS
+BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE. THE SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED
+HEREUNDER IS PROVIDED "AS IS". REGENTS HAS NO OBLIGATION TO PROVIDE
+MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
+
+
+The OSC webpage is http://cnmat.cnmat.berkeley.edu/OpenSoundControl
+*/
+
+
+ /*
+
+ dumpOSC.c
+ server that displays OpenSoundControl messages sent to it
+ for debugging client udp and UNIX protocol
+
+ by Matt Wright, 6/3/97
+ modified from dumpSC.c, by Matt Wright and Adrian Freed
+
+ version 0.2: Added "-silent" option a.k.a. "-quiet"
+
+ version 0.3: Incorporated patches from Nicola Bernardini to make
+ things Linux-friendly. Also added ntohl() in the right places
+ to support little-endian architectures.
+
+
+
+ compile:
+ cc -o dumpOSC dumpOSC.c
+
+ to-do:
+
+ More robustness in saying exactly what's wrong with ill-formed
+ messages. (If they don't make sense, show exactly what was
+ received.)
+
+ Time-based features: print time-received for each packet
+
+ Clean up to separate OSC parsing code from socket/select stuff
+
+ pd: branched from http://www.cnmat.berkeley.edu/OpenSoundControl/src/dumpOSC/dumpOSC.c
+ -------------
+ -- added pd functions
+ -- socket is made differently than original via pd mechanisms
+ -- tweaks for Win32 www.zeggz.com/raf 13-April-2002
+ -- the OSX changes from cnmat didnt make it here yet but this compiles
+ on OSX anyway.
+
+*/
+
+#if HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "m_pd.h"
+//#include "m_imp.h"
+#include "s_stuff.h"
+
+/* declarations */
+
+// typedef void (*t_fdpollfn)(void *ptr, int fd);
+void sys_addpollfn(int fd, t_fdpollfn fn, void *ptr);
+
+
+#if defined(__sgi) || defined(__linux) || defined(WIN32) || defined(__APPLE__)
+
+#ifdef WIN32
+ #include "OSC-common.h"
+ #include <winsock2.h>
+ #include <string.h>
+ #include <stdlib.h>
+ #include <fcntl.h>
+ #include <sys/types.h>
+ #include <sys/stat.h>
+ #include <ctype.h>
+ #include <signal.h>
+#else
+ #include <stdio.h>
+ #include <string.h>
+ #include <stdlib.h>
+ #include <unistd.h>
+ #include <fcntl.h>
+ #include <sys/types.h>
+ #include <sys/stat.h>
+ #include <netinet/in.h>
+ #include <rpc/rpc.h>
+ #include <sys/socket.h>
+ #include <sys/un.h>
+ #include <sys/times.h>
+ #include <sys/param.h>
+ #include <sys/time.h>
+ #include <sys/ioctl.h>
+ #include <ctype.h>
+ #include <arpa/inet.h>
+ #include <netdb.h>
+ #include <pwd.h>
+ #include <signal.h>
+ #include <grp.h>
+ #include <sys/file.h>
+ //#include <sys/prctl.h>
+
+ #ifdef NEED_SCHEDCTL_AND_LOCK
+ #include <sys/schedctl.h>
+ #include <sys/lock.h>
+ #endif
+#endif
+
+
+char *htm_error_string;
+typedef int Boolean;
+typedef void *OBJ;
+
+typedef struct ClientAddressStruct {
+ struct sockaddr_in cl_addr;
+ int clilen;
+ int sockfd;
+} *ClientAddr;
+
+typedef unsigned long long osc_time_t;
+
+Boolean ShowBytes = FALSE;
+Boolean Silent = FALSE;
+
+/* Declarations */
+#ifndef WIN32
+static int unixinitudp(int chan);
+#endif
+
+static int initudp(int chan);
+static void closeudp(int sockfd);
+Boolean ClientReply(int packetsize, void *packet, int socketfd,
+ void *clientaddresspointer, int clientaddressbufferlength);
+void sgi_CleanExit(void);
+Boolean sgi_HaveToQuit(void);
+int RegisterPollingDevice(int fd, void (*callbackfunction)(int , void *), void *dummy);
+static void catch_sigint();
+static int Synthmessage(char *m, int n, void *clientdesc, int clientdesclength, int fd) ;
+char *DataAfterAlignedString(char *string, char *boundary) ;
+Boolean IsNiceString(char *string, char *boundary) ;
+void complain(char *s, ...);
+
+#define MAXMESG 32768
+static char mbuf[MAXMESG];
+
+/* ----------------------------- dumpOSC ------------------------- */
+
+#define MAXOUTAT 50
+
+static t_class *dumpOSC_class;
+
+typedef struct _dumpOSC
+{
+ t_object x_obj;
+ t_outlet *x_msgout;
+ t_outlet *x_connectout;
+ t_atom x_outat[MAXOUTAT];
+ int x_outatc;
+ t_binbuf *x_b;
+ int x_connectsocket;
+ int x_nconnections;
+ int x_udp;
+ struct sockaddr_in x_server;
+ int x_clilen;
+} t_dumpOSC;
+
+void dumpOSC_ParsePacket(t_dumpOSC *x, char *buf, int n, ClientAddr returnAddr);
+Boolean dumpOSC_SendReply(char *buf, int n, void *clientDesc, int clientDescLenght, int fd);
+static void dumpOSC_Smessage(t_dumpOSC *x, char *address, void *v, int n, ClientAddr returnAddr);
+static void dumpOSC_PrintTypeTaggedArgs(t_dumpOSC *x, void *v, int n);
+static void dumpOSC_PrintHeuristicallyTypeGuessedArgs(t_dumpOSC *x, void *v, int n, int skipComma);
+
+static void dumpOSC_read(t_dumpOSC *x, int sockfd) {
+ int clilen = x->x_clilen;
+ int n;
+ struct ClientAddressStruct ras;
+ ClientAddr ra = &ras;
+
+ //catchupflag= FALSE;
+
+/* if (ShowBytes) { */
+/* int i; */
+/* printf("%d byte message:\n", n); */
+/* for (i = 0; i < n; ++i) { */
+/* printf(" %x (%c)\t", m[i], m[i]); */
+/* if (i%4 == 3) printf("\n"); */
+/* } */
+/* printf("\n"); */
+/* } */
+
+ // return catchupflag;
+ //struct sockaddr_in x->x_server;
+ //while( (n = recvfrom(sockfd, mbuf, MAXMESG, 0, &cl_addr, &clilen)) >0)
+ // while((
+
+ #ifdef WIN32
+ if ((n = recvfrom(sockfd, mbuf, MAXMESG, 0, (SOCKADDR*)&x->x_server, &clilen)) >0)
+ #else
+ if ((n = recvfrom(sockfd, mbuf, MAXMESG, 0, (struct sockaddr *)&x->x_server, &clilen)) >0)
+ #endif
+ {
+ //int r;
+ ras.cl_addr = *((struct sockaddr_in *) &x->x_server);
+ ras.clilen = x->x_clilen;
+ ras.sockfd = x->x_connectsocket;
+
+ #ifdef DEBUG
+ printf("dumpOSC_read: received UDP packet of length %d\n", n);
+ #endif
+
+ if(!dumpOSC_SendReply(mbuf, n, &x->x_server, clilen, sockfd))
+ {
+ dumpOSC_ParsePacket(x, mbuf, n, ra);
+ }
+ //r = Synthmessage(mbuf, n, &x->x_server, clilen, sockfd);
+ //post ("%d", r);
+ //outlet_anything(x->x_msgout, at[msg].a_w.w_symbol,
+ // emsg-msg-1, at + msg + 1);
+ // outlet_list(x->x_msgout, 0, n, mbuf);
+ //if( sgi_HaveToQuit()) goto out;
+ //if(r>0) goto back;
+ //clilen = maxclilen;
+ }
+}
+
+static void *dumpOSC_new(t_symbol *compatflag,
+ t_floatarg fportno) {
+ t_dumpOSC *x;
+ struct sockaddr_in server;
+ int clilen=sizeof(server);
+ int sockfd;
+ int portno=fportno;
+ int udp = 1;
+
+ //x->x_b = binbuf_new();
+ //x->x_outat = binbuf_getvec(x->x_b);
+
+ //{{raf}} pointer not valid yet...moving this down
+ //x->x_outatc = 0; {{raf}}
+
+ /* create a socket */
+ if ((sockfd = socket(AF_INET, (udp ? SOCK_DGRAM : SOCK_STREAM), 0)) == -1)
+ {
+ sys_sockerror("socket");
+ return (0);
+ }
+
+ server.sin_family = AF_INET;
+ server.sin_addr.s_addr = INADDR_ANY;
+ /* assign server port number */
+ server.sin_port = htons((u_short)portno);
+ /* name the socket */
+ if (bind(sockfd, (struct sockaddr *)&server, sizeof(server)) < 0)
+ {
+ sys_sockerror("bind");
+ sys_closesocket(sockfd);
+ return (0);
+ }
+
+ x = (t_dumpOSC *)pd_new(dumpOSC_class);
+ x->x_outatc = 0; // {{raf}} now pointer is valid (less invalid)
+
+ x->x_msgout = outlet_new(&x->x_obj, &s_anything);
+
+ // if (udp) /* datagram protocol */
+ {
+
+ sys_addpollfn(sockfd, (t_fdpollfn)dumpOSC_read, x);
+ x->x_connectout = 0;
+ }
+ // else /* streaming protocol */
+ /* { */
+ /* if (listen(sockfd, 5) < 0) */
+ /* { */
+ /* sys_sockerror("listen"); */
+ /* sys_closesocket(sockfd); */
+ /* sockfd = -1; */
+ /* } */
+ /* else */
+ /* { */
+ /* sys_addpollfn(sockfd, (t_fdpollfn)dumpOSC_connectpoll, x); */
+ /* x->x_connectout = outlet_new(&x->x_obj, &s_float); */
+ /* } */
+ /* } */
+
+ x->x_connectsocket = sockfd;
+ x->x_server = server;
+ x->x_clilen = clilen;
+ x->x_nconnections = 0;
+ x->x_udp = udp;
+
+ return (x);
+}
+
+static void dumpOSC_free(t_dumpOSC *x)
+{
+ /* LATER make me clean up open connections */
+ if (x->x_connectsocket >= 0)
+ {
+ sys_rmpollfn(x->x_connectsocket);
+ sys_closesocket(x->x_connectsocket);
+ }
+}
+
+#ifdef WIN32
+OSC_API void dumpOSC_setup(void)
+#else
+void dumpOSC_setup(void)
+#endif
+{
+ dumpOSC_class = class_new(gensym("dumpOSC"),
+ (t_newmethod)dumpOSC_new, (t_method)dumpOSC_free,
+ sizeof(t_dumpOSC), CLASS_NOINLET, A_DEFFLOAT, A_DEFFLOAT,
+ A_DEFSYM, 0);
+ class_sethelpsymbol(dumpOSC_class, gensym("dumpOSC-help.pd"));
+}
+
+
+#ifndef WIN32
+ #define UNIXDG_PATH "/tmp/htm"
+ #define UNIXDG_TMP "/tmp/htm.XXXXXX"
+ static int unixinitudp(int chan)
+ {
+ struct sockaddr_un serv_addr;
+ int sockfd;
+
+ if((sockfd = socket(AF_UNIX, SOCK_DGRAM, 0)) < 0)
+ return sockfd;
+
+ bzero((char *)&serv_addr, sizeof(serv_addr));
+ serv_addr.sun_family = AF_UNIX;
+ strcpy(serv_addr.sun_path, UNIXDG_PATH);
+ sprintf(serv_addr.sun_path+strlen(serv_addr.sun_path), "%d", chan);
+ unlink(serv_addr.sun_path);
+ if(bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr.sun_family)+strlen(serv_addr.sun_path)) < 0)
+ {
+ perror("unable to bind\n");
+ return -1;
+ }
+
+ fcntl(sockfd, F_SETFL, FNDELAY);
+ return sockfd;
+ }
+#endif // #ifndef WIN32
+
+
+
+static int initudp(int chan)
+{
+
+#ifdef WIN32
+ struct sockaddr_in serv_addr;
+ unsigned int sockfd;
+ ULONG nonBlocking = (ULONG) TRUE;
+
+ if( (sockfd = socket(AF_INET, SOCK_DGRAM, 0)) != INVALID_SOCKET ) {
+ ZeroMemory((char *)&serv_addr, sizeof(serv_addr));
+ serv_addr.sin_family = AF_INET;
+ serv_addr.sin_addr.s_addr = htonl(INADDR_ANY);
+ serv_addr.sin_port = htons(chan);
+ if(bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) >= 0) {
+ // set for non-blocking mode
+ if(ioctlsocket(sockfd, FIONBIO, &nonBlocking) == SOCKET_ERROR) {
+ perror("unable to set non-blocking\n");
+ return -1;
+ }
+ }
+ else { perror("unable to bind\n"); return -1; }
+ }
+ return (sockfd == INVALID_SOCKET ? -1 : (int)sockfd);
+#else
+ struct sockaddr_in serv_addr;
+ int sockfd;
+
+ if((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
+ return sockfd;
+
+ bzero((char *)&serv_addr, sizeof(serv_addr));
+ serv_addr.sin_family = AF_INET;
+ serv_addr.sin_addr.s_addr = htonl(INADDR_ANY);
+ serv_addr.sin_port = htons(chan);
+
+ if(bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0)
+ {
+ perror("unable to bind\n");
+ return -1;
+ }
+
+ fcntl(sockfd, F_SETFL, FNDELAY);
+ return sockfd;
+#endif
+}
+
+
+
+
+
+
+
+
+static void closeudp(int sockfd) {
+ #ifdef WIN32
+ closesocket(sockfd);
+ #else
+ close(sockfd);
+ #endif
+}
+
+static Boolean catchupflag=FALSE;
+Boolean ClientReply(int packetsize, void *packet, int socketfd,
+ void *clientaddresspointer, int clientaddressbufferlength)
+{
+ if(!clientaddresspointer) return FALSE;
+ catchupflag= TRUE;
+ return packetsize==sendto(socketfd, packet, packetsize, 0, clientaddresspointer, clientaddressbufferlength);
+}
+
+static Boolean exitflag= FALSE;
+void sgi_CleanExit(void) {
+ exitflag = TRUE;
+}
+
+Boolean sgi_HaveToQuit(void) {
+ return exitflag;
+}
+
+
+/* file descriptor poll table */
+static int npolldevs =0;
+typedef struct polldev
+{
+ int fd;
+ void (*callbackfunction)(int , void *);
+ void *dummy;
+} polldev;
+#define TABMAX 8
+static polldev polldevs[TABMAX];
+
+
+/* Register a device (referred to by a file descriptor that the caller
+ should have already successfully obtained from a system call) to be
+ polled as real-time constraints allowed.
+
+ When a select(2) call indicates activity on the file descriptor, the
+ callback function is called with the file descripter as first
+ argument and the given dummy argument (presumably a pointer to the
+ instance variables associated with the device).
+*/
+int RegisterPollingDevice(int fd, void (*callbackfunction)(int , void *), void *dummy)
+{
+ if(npolldevs<TABMAX)
+ {
+ polldevs[npolldevs].fd = fd;
+ polldevs[npolldevs].callbackfunction = callbackfunction;
+ polldevs[npolldevs].dummy = dummy;
+ }
+ else return -1;
+ return npolldevs++;
+}
+
+static int caught_sigint;
+
+static void catch_sigint() {
+ caught_sigint = 1;
+}
+static int sockfd, usockfd;
+
+
+void PrintClientAddr(ClientAddr CA) {
+ unsigned long addr = CA->cl_addr.sin_addr.s_addr;
+ printf("Client address %p:\n", CA);
+ printf(" clilen %d, sockfd %d\n", CA->clilen, CA->sockfd);
+ printf(" sin_family %d, sin_port %d\n", CA->cl_addr.sin_family,
+ CA->cl_addr.sin_port);
+ printf(" address: (%x) %s\n", addr, inet_ntoa(CA->cl_addr.sin_addr));
+
+ printf(" sin_zero = \"%c%c%c%c%c%c%c%c\"\n",
+ CA->cl_addr.sin_zero[0],
+ CA->cl_addr.sin_zero[1],
+ CA->cl_addr.sin_zero[2],
+ CA->cl_addr.sin_zero[3],
+ CA->cl_addr.sin_zero[4],
+ CA->cl_addr.sin_zero[5],
+ CA->cl_addr.sin_zero[6],
+ CA->cl_addr.sin_zero[7]);
+
+ printf("\n");
+}
+
+//*******************
+
+void WriteTime(char* dst, osc_time_t osctime)
+{
+ *(int32_t*)dst = htonl((int32_t)(osctime >> 32));
+ *(int32_t*)(dst+4) = htonl((int32_t)osctime);
+}
+
+void WriteMode(char* dst)
+{
+ *(int32_t*)dst = htonl(0);
+}
+
+osc_time_t ReadTime(const char* src)
+{
+ osc_time_t osctime = ntohl(*(int32_t*)src);
+ return (osctime << 32) + ntohl(*(int32_t*)(src+4));
+}
+
+double TimeToSeconds(osc_time_t osctime)
+{
+ return (double)osctime * 2.3283064365386962890625e-10 /* 1/2^32 */;
+}
+
+int timeRound(double x)
+{
+ return x >= 0.0 ? x+0.5 : x-0.5;
+}
+/*
+void WriteLogicalTime(char* dst)
+{
+ static double startTime = -1.0;
+ double sTime;
+
+ // Initialisierung der Startzeit.
+ // Knnte effizienter (ohne 'if') auch irgendwo vorher passieren.
+ // Knnte wahrscheinlich auch 0.0 sein.
+ if (startTime < 0.0) {
+ startTime = clock_getlogicaltime();
+ }
+
+ sTime = clock_gettimesince(startTime) * 0.001;
+ *(int32_t*)dst = hton'K l((int32_t)sTime);
+ *(int32_t*)(dst+4) = htonl((int32_t)(4294967296.0 * sTime));
+}
+*/
+
+void WriteLogicalTime(char* dst)
+{
+ double sTime = clock_gettimesince(19230720) / 1000.0;
+ double tau = sTime - timeRound(sTime);
+
+ //fprintf(stderr, "sSec = %f tau = %f\n", sTime, tau);
+
+ *(int32_t*)dst = htonl((int32_t)(sTime));
+ *(int32_t*)(dst+4) = htonl((int32_t)(4294967296 * tau));
+}
+
+Boolean dumpOSC_SendReply(char *buf, int n, void *clientDesc, int clientDescLenght, int fd)
+{
+ if((n == 24) && (strcmp(buf, "#time") == 0))
+ {
+ osc_time_t t0, t1, t2;
+ double dt0, dt1, dt2;
+
+ WriteMode(buf+6);
+
+ t0 = ReadTime(buf+8);
+
+ WriteLogicalTime(buf+16);
+ t1 = ReadTime(buf+16); // reverse
+ dt0 = TimeToSeconds(t0); // client time
+ dt1 = TimeToSeconds(t1); // server time
+
+ // fprintf(stderr, "%f\t%f\t%f\n", dt0, dt1, dt0 - dt1);
+
+ sendto(fd, buf, n, 0, (struct sockaddr *)clientDesc, clientDescLenght);
+ return TRUE;
+ }
+ else
+ {
+ return FALSE;
+ }
+}
+
+//**********************
+
+void dumpOSC_ParsePacket(t_dumpOSC *x, char *buf, int n, ClientAddr returnAddr) {
+ // t_dumpOSC *x;
+ int size, messageLen, i;
+ char *messageName;
+ char *args;
+
+ //#ifdef PRINTADDRS
+ #ifdef DEBUG
+ //PrintClientAddr(returnAddr);
+ #endif
+
+
+ if ((n%4) != 0) {
+ complain("SynthControl packet size (%d) not a multiple of 4 bytes: dropping", n);
+ return;
+ }
+
+ if ((n >= 8) && (strncmp(buf, "#bundle", 8) == 0)) {
+ /* This is a bundle message. */
+ #ifdef DEBUG
+ printf("dumpOSC_ParsePacket: bundle msg: bundles not yet supported\n");
+ #endif
+
+ if (n < 16) {
+ complain("Bundle message too small (%d bytes) for time tag", n);
+ return;
+ }
+
+ /* Print the time tag */
+ #ifdef DEBUG
+ printf("[ %lx%08lx\n", ntohl(*((unsigned long *)(buf+8))), ntohl(*((unsigned long *)(buf+12))));
+ #endif
+
+ /* Note: if we wanted to actually use the time tag as a little-endian
+ 64-bit int, we'd have to word-swap the two 32-bit halves of it */
+
+ i = 16; /* Skip "#group\0" and time tag */
+
+ while(i<n) {
+ size = ntohl(*((int *) (buf + i)));
+ if ((size % 4) != 0) {
+ complain("Bad size count %d in bundle (not a multiple of 4)", size);
+ return;
+ }
+ if ((size + i + 4) > n) {
+ complain("Bad size count %d in bundle (only %d bytes left in entire bundle)",
+ size, n-i-4);
+ return;
+ }
+
+ /* Recursively handle element of bundle */
+ dumpOSC_ParsePacket(x, buf+i+4, size, returnAddr);
+ i += 4 + size;
+ }
+
+ if (i != n) {
+ complain("This can't happen");
+ }
+ #ifdef DEBUG
+ printf("]\n");
+ #endif
+
+ }
+ else if ((n == 24) && (strcmp(buf, "#time") == 0))
+ {
+ complain("Time message: %s\n :).\n", htm_error_string);
+ return;
+
+ }
+ else
+ {
+ /* This is not a bundle message */
+
+ messageName = buf;
+ args = DataAfterAlignedString(messageName, buf+n);
+ if (args == 0) {
+ complain("Bad message name string: %s\nDropping entire message.\n",
+ htm_error_string);
+ return;
+ }
+ messageLen = args-messageName;
+ dumpOSC_Smessage(x, messageName, (void *)args, n-messageLen, returnAddr);
+ }
+}
+
+#define SMALLEST_POSITIVE_FLOAT 0.000001f
+
+static void dumpOSC_Smessage(t_dumpOSC *x, char *address, void *v, int n, ClientAddr returnAddr) {
+ char *chars = v;
+ t_atom at;
+ //t_atom myargv[50];
+
+ int myargc = x->x_outatc;
+ t_atom* mya = x->x_outat;
+ int myi;
+
+#ifdef DEBUG
+ printf("%s ", address);
+#endif
+
+ // ztoln+cvt from envgen.c, ggee-0.18 ..
+ // outlet_anything's 'symbol' gets set to address
+ // so we dont need to append address to the atomlist
+ /*
+ SETSYMBOL(mya,gensym(address));myargc++;
+ x->x_outatc = myargc;
+ */
+
+ if (n != 0) {
+ if (chars[0] == ',') {
+ if (chars[1] != ',') {
+ /* This message begins with a type-tag string */
+ dumpOSC_PrintTypeTaggedArgs(x, v, n);
+ } else {
+ /* Double comma means an escaped real comma, not a type string */
+ dumpOSC_PrintHeuristicallyTypeGuessedArgs(x, v, n, 1);
+ }
+ } else {
+ dumpOSC_PrintHeuristicallyTypeGuessedArgs(x, v, n, 0);
+ }
+ }
+
+ outlet_anything(x->x_msgout,gensym(address),x->x_outatc,(t_atom*)&x->x_outat);
+ x->x_outatc = 0;
+#ifdef DEBUG
+ printf("\n");
+#endif
+ fflush(stdout); /* Added for Sami 5/21/98 */
+}
+
+static void dumpOSC_PrintTypeTaggedArgs(t_dumpOSC *x, void *v, int n) {
+ char *typeTags, *thisType;
+ char *p;
+
+ int myargc = x->x_outatc;
+ t_atom* mya = x->x_outat;
+ int myi;
+
+ typeTags = v;
+
+ if (!IsNiceString(typeTags, typeTags+n)) {
+ /* No null-termination, so maybe it wasn't a type tag
+ string after all */
+ dumpOSC_PrintHeuristicallyTypeGuessedArgs(x, v, n, 0);
+ return;
+ }
+
+ p = DataAfterAlignedString(typeTags, typeTags+n);
+
+
+ for (thisType = typeTags + 1; *thisType != 0; ++thisType) {
+ switch (*thisType) {
+ case 'i': case 'r': case 'm': case 'c':
+#ifdef DEBUG
+ //post("integer: %d", ntohl(*((int *) p)));
+#endif
+ /* Martin Peach fix for negative floats:
+ * was: SETFLOAT(mya+myargc,ntohl(*((int *) p)));
+ * now is:
+ */
+ SETFLOAT(mya+myargc,(signed)ntohl(*((int *) p)));
+ myargc++;
+
+ p += 4;
+ break;
+
+ case 'f': {
+ int i = ntohl(*((int *) p));
+ float *floatp = ((float *) (&i));
+#ifdef DEBUG
+ post("float: %f", *floatp);
+#endif
+ SETFLOAT(mya+myargc,*floatp);
+ myargc++;
+
+ p += 4;
+ }
+ break;
+
+ case 'h': case 't':
+#ifdef DEBUG
+ printf("[A 64-bit int] ");
+#endif
+ post("[A 64-bit int] not implemented");
+
+ p += 8;
+ break;
+
+ case 'd':
+#ifdef DEBUG
+ printf("[A 64-bit float] ");
+#endif
+ post("[A 64-bit float] not implemented");
+
+ p += 8;
+ break;
+
+ case 's': case 'S':
+ if (!IsNiceString(p, typeTags+n)) {
+ post("Type tag said this arg is a string but it's not!\n");
+ return;
+ } else {
+#ifdef DEBUG
+ post("string: \"%s\"", p);
+#endif
+ SETSYMBOL(mya+myargc,gensym(p));
+ myargc++;
+ //outlet_list(x->x_msgout, 0,sizeof(p), p);
+ //outlet_anything(x->x_msgout, 0, sizeof(p), p);
+ p = DataAfterAlignedString(p, typeTags+n);
+ // append to output vector ..
+ }
+ break;
+
+ case 'T':
+#ifdef DEBUG
+ printf("[True] ");
+#endif
+ SETFLOAT(mya+myargc,1.);
+ myargc++;
+ break;
+ case 'F':
+#ifdef DEBUG
+ printf("[False] ");
+#endif
+ SETFLOAT(mya+myargc,0.);
+ myargc++;
+ break;
+ case 'N':
+#ifdef DEBUG
+ printf("[Nil]");
+#endif
+ post("sendOSC: [Nil] not implemented");
+ break;
+ case 'I':
+#ifdef DEBUG
+ printf("[Infinitum]");
+#endif
+ post("sendOSC: [Infinitum] not implemented");
+ break;
+
+ default:
+ post("sendOSC: [Unrecognized type tag %c]", *thisType);
+ // return;
+ }
+ }
+ x->x_outatc = myargc;
+}
+
+static void dumpOSC_PrintHeuristicallyTypeGuessedArgs(t_dumpOSC *x, void *v, int n, int skipComma) {
+ int i, thisi;
+ float thisf;
+ int *ints;
+ char *chars;
+ char *string, *nextString;
+
+ int myargc= x->x_outatc;
+ t_atom* mya = x->x_outat;
+ int myi;
+
+
+ /* Go through the arguments 32 bits at a time */
+ ints = v;
+ chars = v;
+
+ for (i = 0; i<n/4; ) {
+ string = &chars[i*4];
+ thisi = ntohl(ints[i]);
+ /* Reinterpret the (potentially byte-reversed) thisi as a float */
+ thisf = *(((float *) (&thisi)));
+
+ if (thisi >= -1000 && thisi <= 1000000) {
+#ifdef DEBUG
+ printf("%d ", thisi);
+#endif
+ // append to output vector ..
+ SETFLOAT(mya+myargc,(t_float) (thisi));
+ myargc++;
+ // outlet_float(x->x_msgout, thisi);
+ i++;
+ } else if (thisf >= -1000.f && thisf <= 1000000.f &&
+ (thisf <=0.0f || thisf >= SMALLEST_POSITIVE_FLOAT)) {
+#ifdef DEBUG
+ printf("%f ", thisf);
+#endif
+ // append to output vector ..
+ SETFLOAT(mya+myargc,thisf);
+ myargc++;
+ //outlet_float(x->x_msgout, thisf);
+ i++;
+ } else if (IsNiceString(string, chars+n)) {
+ nextString = DataAfterAlignedString(string, chars+n);
+#ifdef DEBUG
+ printf("\"%s\" ", (i == 0 && skipComma) ? string +1 : string);
+#endif
+ // append to output vector ..
+ SETSYMBOL(mya+myargc,gensym(string));
+ myargc++;
+ //outlet_symbol(x->x_msgout, gensym((i == 0 && skipComma) ? string +1 : string));
+ i += (nextString-string) / 4;
+ } else {
+ // unhandled .. ;)
+#ifdef DEBUG
+ printf("0x%x xx", ints[i]);
+#endif
+ i++;
+ }
+ x->x_outatc = myargc;
+ }
+}
+
+
+#define STRING_ALIGN_PAD 4
+
+char *DataAfterAlignedString(char *string, char *boundary)
+{
+ /* The argument is a block of data beginning with a string. The
+ string has (presumably) been padded with extra null characters
+ so that the overall length is a multiple of STRING_ALIGN_PAD
+ bytes. Return a pointer to the next byte after the null
+ byte(s). The boundary argument points to the character after
+ the last valid character in the buffer---if the string hasn't
+ ended by there, something's wrong.
+
+ If the data looks wrong, return 0, and set htm_error_string */
+
+ int i;
+
+ if ((boundary - string) %4 != 0) {
+ fprintf(stderr, "Internal error: DataAfterAlignedString: bad boundary\n");
+ return 0;
+ }
+
+ for (i = 0; string[i] != '\0'; i++) {
+ if (string + i >= boundary) {
+ htm_error_string = "DataAfterAlignedString: Unreasonably long string";
+ return 0;
+ }
+ }
+
+ /* Now string[i] is the first null character */
+ i++;
+
+ for (; (i % STRING_ALIGN_PAD) != 0; i++) {
+ if (string + i >= boundary) {
+ htm_error_string = "DataAfterAlignedString: Unreasonably long string";
+ return 0;
+ }
+ if (string[i] != '\0') {
+ htm_error_string = "DataAfterAlignedString: Incorrectly padded string.";
+ return 0;
+ }
+ }
+
+ return string+i;
+}
+
+Boolean IsNiceString(char *string, char *boundary)
+{
+ /* Arguments same as DataAfterAlignedString(). Is the given "string"
+ really a string? I.e., is it a sequence of isprint() characters
+ terminated with 1-4 null characters to align on a 4-byte boundary? */
+
+ int i;
+
+ if ((boundary - string) %4 != 0) {
+ fprintf(stderr, "Internal error: IsNiceString: bad boundary\n");
+ return 0;
+ }
+
+ for (i = 0; string[i] != '\0'; i++) {
+ if (!isprint(string[i])) return FALSE;
+ if (string + i >= boundary) return FALSE;
+ }
+
+ /* If we made it this far, it's a null-terminated sequence of printing characters
+ in the given boundary. Now we just make sure it's null padded... */
+
+ /* Now string[i] is the first null character */
+ i++;
+ for (; (i % STRING_ALIGN_PAD) != 0; i++) {
+ if (string[i] != '\0') return FALSE;
+ }
+
+ return TRUE;
+}
+
+
+
+
+
+
+
+
+
+#include <stdarg.h>
+void complain(char *s, ...) {
+ va_list ap;
+ va_start(ap, s);
+ fprintf(stderr, "*** ERROR: ");
+ vfprintf(stderr, s, ap);
+ fprintf(stderr, "\n");
+ va_end(ap);
+}
+
+#endif /* __sgi or LINUX or WIN32 */
diff --git a/apps/plugins/pdbox/PDa/extra/equalizer.c b/apps/plugins/pdbox/PDa/extra/equalizer.c
new file mode 100644
index 0000000000..1d21c4087c
--- /dev/null
+++ b/apps/plugins/pdbox/PDa/extra/equalizer.c
@@ -0,0 +1,178 @@
+/* (C) Guenter Geiger <geiger@epy.co.at> */
+
+
+/*
+
+ These filter coefficients computations are taken from
+ http://www.harmony-central.com/Computer/Programming/Audio-EQ-Cookbook.txt
+
+ written by Robert Bristow-Johnson
+
+*/
+
+#include "m_pd.h"
+#ifdef NT
+#pragma warning( disable : 4244 )
+#pragma warning( disable : 4305 )
+#endif
+#include <math.h>
+#include "filters.h"
+
+
+
+/* ------------------- equ ----------------------------*/
+static t_class *equ_class;
+
+void equ_bang(t_rbjfilter *x)
+{
+ t_atom at[5];
+ t_float omega = e_omega(x->x_freq,x->x_rate);
+ t_float alpha = e_alpha(x->x_bw*0.01,omega);
+ t_float b0 = 1 + alpha*e_A(x->x_gain);
+ t_float b1 = -2.*cos(omega);
+ t_float b2 = 1 - alpha*e_A(x->x_gain);
+ t_float a0 = 1 + alpha/e_A(x->x_gain);
+ t_float a1 = -2.*cos(omega);
+ t_float a2 = 1 - alpha/e_A(x->x_gain);
+
+/* post("bang %f %f %f",x->x_freq, x->x_gain, x->x_bw);*/
+
+ if (!check_stability(-a1/a0,-a2/a0,b0/a0,b1/a0,b2/a0)) {
+ post("equ: filter unstable -> resetting");
+ a0=1.;a1=0.;a2=0.;
+ b0=1.;b1=0.;b2=0.;
+ }
+
+ SETFLOAT(at,-a1/a0);
+ SETFLOAT(at+1,-a2/a0);
+ SETFLOAT(at+2,b0/a0);
+ SETFLOAT(at+3,b1/a0);
+ SETFLOAT(at+4,b2/a0);
+
+ outlet_list(x->x_obj.ob_outlet,&s_list,5,at);
+}
+
+
+void equ_float(t_rbjfilter *x,t_floatarg f)
+{
+ x->x_freq = f;
+ equ_bang(x);
+}
+
+
+static void *equ_new(t_floatarg f,t_floatarg g,t_floatarg bw)
+{
+ t_rbjfilter *x = (t_rbjfilter *)pd_new(equ_class);
+
+ x->x_rate = 44100.0;
+ outlet_new(&x->x_obj,&s_float);
+ floatinlet_new(&x->x_obj, &x->x_gain);
+ floatinlet_new(&x->x_obj, &x->x_bw);
+ if (f > 0.) x->x_freq = f;
+ if (bw > 0.) x->x_bw = bw;
+ if (g != 0.) x->x_gain = g;
+ return (x);
+}
+
+
+void equalizer_setup(void)
+{
+ equ_class = class_new(gensym("equalizer"), (t_newmethod)equ_new, 0,
+ sizeof(t_rbjfilter), 0,A_DEFFLOAT,A_DEFFLOAT,A_DEFFLOAT,0);
+ class_addbang(equ_class,equ_bang);
+ class_addfloat(equ_class,equ_float);
+}
+
+
+
+
+
+/* (C) Guenter Geiger <geiger@epy.co.at> */
+
+
+/*
+
+ These filter coefficients computations are taken from
+ http://www.harmony-central.com/Computer/Programming/Audio-EQ-Cookbook.txt
+
+ written by Robert Bristow-Johnson
+
+*/
+
+#include "m_pd.h"
+#ifdef NT
+#pragma warning( disable : 4244 )
+#pragma warning( disable : 4305 )
+#endif
+#include <math.h>
+#include "filters.h"
+
+
+
+/* ------------------- equ ----------------------------*/
+static t_class *equ_class;
+
+void equ_bang(t_rbjfilter *x)
+{
+ t_atom at[5];
+ t_float omega = e_omega(x->x_freq,x->x_rate);
+ t_float alpha = e_alpha(x->x_bw*0.01,omega);
+ t_float b0 = 1 + alpha*e_A(x->x_gain);
+ t_float b1 = -2.*cos(omega);
+ t_float b2 = 1 - alpha*e_A(x->x_gain);
+ t_float a0 = 1 + alpha/e_A(x->x_gain);
+ t_float a1 = -2.*cos(omega);
+ t_float a2 = 1 - alpha/e_A(x->x_gain);
+
+/* post("bang %f %f %f",x->x_freq, x->x_gain, x->x_bw);*/
+
+ if (!check_stability(-a1/a0,-a2/a0,b0/a0,b1/a0,b2/a0)) {
+ post("equ: filter unstable -> resetting");
+ a0=1.;a1=0.;a2=0.;
+ b0=1.;b1=0.;b2=0.;
+ }
+
+ SETFLOAT(at,-a1/a0);
+ SETFLOAT(at+1,-a2/a0);
+ SETFLOAT(at+2,b0/a0);
+ SETFLOAT(at+3,b1/a0);
+ SETFLOAT(at+4,b2/a0);
+
+ outlet_list(x->x_obj.ob_outlet,&s_list,5,at);
+}
+
+
+void equ_float(t_rbjfilter *x,t_floatarg f)
+{
+ x->x_freq = f;
+ equ_bang(x);
+}
+
+
+static void *equ_new(t_floatarg f,t_floatarg g,t_floatarg bw)
+{
+ t_rbjfilter *x = (t_rbjfilter *)pd_new(equ_class);
+
+ x->x_rate = 44100.0;
+ outlet_new(&x->x_obj,&s_float);
+ floatinlet_new(&x->x_obj, &x->x_gain);
+ floatinlet_new(&x->x_obj, &x->x_bw);
+ if (f > 0.) x->x_freq = f;
+ if (bw > 0.) x->x_bw = bw;
+ if (g != 0.) x->x_gain = g;
+ return (x);
+}
+
+
+void equalizer_setup(void)
+{
+ equ_class = class_new(gensym("equalizer"), (t_newmethod)equ_new, 0,
+ sizeof(t_rbjfilter), 0,A_DEFFLOAT,A_DEFFLOAT,A_DEFFLOAT,0);
+ class_addbang(equ_class,equ_bang);
+ class_addfloat(equ_class,equ_float);
+}
+
+
+
+
+
diff --git a/apps/plugins/pdbox/PDa/extra/fatom.h b/apps/plugins/pdbox/PDa/extra/fatom.h
new file mode 100644
index 0000000000..abaf9b91c1
--- /dev/null
+++ b/apps/plugins/pdbox/PDa/extra/fatom.h
@@ -0,0 +1,970 @@
+/* ------------------------ fatom ----------------------------- */
+
+#define x_val a_pos.a_w.w_float
+#define DEBUG(x)
+
+#include <string.h>
+#include <stdio.h>
+
+typedef struct _fatom
+{
+ t_object x_obj;
+ t_atom a_pos; /* the value of the fatom */
+
+ t_symbol* x_send;
+ t_symbol* x_receive;
+ t_glist * x_glist; /* value of the current canvas, intialized in _new */
+ int x_rect_width; /* width of the widget */
+ int x_rect_height; /* height of the widget */
+ t_symbol* x_sym; /* symbol for receiving callbacks from GUI */
+ t_symbol* x_type; /* type of fatom (vslider, hslider, checkbutton) */
+
+ t_symbol* x_text; /* associated widget text */
+ int x_max; /* maximum value of a_pos (x_val) */
+ int x_min; /* minimum value of a_pos (x_val) */
+ int x_width; /* width of widget (e.g x_rect_height + 15 for hslider, x_rect_width + 15 for slider) */
+ t_symbol* x_color;
+ t_symbol* x_bgcolor;
+} t_fatom;
+
+/* widget helper functions */
+
+
+
+
+static void draw_inlets(t_fatom *x, t_glist *glist, int firsttime, int nin, int nout)
+{
+ int n = nin;
+ int nplus, i;
+ nplus = (n == 1 ? 1 : n-1);
+ DEBUG(post("draw inlet");)
+ for (i = 0; i < n; i++)
+ {
+ int onset = text_xpix(&x->x_obj, glist) + (x->x_rect_width - IOWIDTH) * i / nplus;
+ if (firsttime)
+ sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xo%d\n",
+ glist_getcanvas(glist),
+ onset, text_ypix(&x->x_obj, glist) + x->x_rect_height - 1,
+ onset + IOWIDTH, text_ypix(&x->x_obj, glist) + x->x_rect_height,
+ x, i);
+ else
+ sys_vgui(".x%x.c coords %xo%d %d %d %d %d\n",
+ glist_getcanvas(glist), x, i,
+ onset, text_ypix(&x->x_obj, glist) + x->x_rect_height - 1,
+ onset + IOWIDTH, text_ypix(&x->x_obj, glist) + x->x_rect_height);
+ }
+ n = nout;
+ nplus = (n == 1 ? 1 : n-1);
+ for (i = 0; i < n; i++)
+ {
+ int onset = text_xpix(&x->x_obj, glist) + (x->x_rect_width - IOWIDTH) * i / nplus;
+ if (firsttime)
+ sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xi%d\n",
+ glist_getcanvas(glist),
+ onset, text_ypix(&x->x_obj, glist),
+ onset + IOWIDTH, text_ypix(&x->x_obj, glist) + 1,
+ x, i);
+ else
+ sys_vgui(".x%x.c coords %xi%d %d %d %d %d\n",
+ glist_getcanvas(glist), x, i,
+ onset, text_ypix(&x->x_obj, glist),
+ onset + IOWIDTH, text_ypix(&x->x_obj, glist) + 1);
+
+ }
+ DEBUG(post("draw inlet end");)
+}
+
+
+static void draw_handle(t_fatom *x, t_glist *glist, int firsttime) {
+ int onset = text_xpix(&x->x_obj, glist) + (x->x_rect_width - IOWIDTH+2);
+
+ if (firsttime)
+ sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xhandle\n",
+ glist_getcanvas(glist),
+ onset, text_ypix(&x->x_obj, glist) + x->x_rect_height - 12,
+ onset + IOWIDTH, text_ypix(&x->x_obj, glist) + x->x_rect_height-4,
+ x);
+ else
+ sys_vgui(".x%x.c coords %xhandle %d %d %d %d\n",
+ glist_getcanvas(glist), x,
+ onset, text_ypix(&x->x_obj, glist) + x->x_rect_height - 12,
+ onset + IOWIDTH, text_ypix(&x->x_obj, glist) + x->x_rect_height-4);
+}
+
+static void create_widget(t_fatom *x, t_glist *glist)
+{
+ t_canvas *canvas=glist_getcanvas(glist);
+
+ if (!strcmp(x->x_type->s_name,"vslider")) {
+ x->x_rect_width = x->x_width+15;
+ x->x_rect_height = x->x_max-x->x_min+26;
+
+ sys_vgui("scale .x%x.c.s%x \
+ -sliderlength 10 \
+ -showvalue 0 \
+ -length %d \
+ -resolution 0.01 \
+ -repeatinterval 20 \
+ -from %d -to %d \
+ -width %d \
+ -bg %s \
+ -activebackground %s \
+ -troughcolor %s \
+ -command fatom_cb%x\n",canvas,x,
+ x->x_max-x->x_min+14,
+ x->x_max,
+ x->x_min,
+ x->x_width,
+ x->x_color->s_name,
+ x->x_color->s_name,
+ x->x_bgcolor->s_name,
+ x);
+ } else if (!strcmp(x->x_type->s_name,"hslider")) {
+ x->x_rect_width = x->x_max-x->x_min + 24;
+ x->x_rect_height = x->x_width + 15;
+ sys_vgui("scale .x%x.c.s%x \
+ -sliderlength 10 \
+ -showvalue 0 \
+ -length %d \
+ -resolution 0.01 \
+ -orient horizontal \
+ -repeatinterval 20 \
+ -from %d -to %d \
+ -width %d \
+ -bg %s \
+ -activebackground %s \
+ -troughcolor %s \
+ -command fatom_cb%x\n",canvas,x,
+ x->x_max-x->x_min+14,
+ x->x_min,
+ x->x_max,
+ x->x_width,
+ x->x_color->s_name,
+ x->x_color->s_name,
+ x->x_bgcolor->s_name,
+ x);
+ } else if (!strcmp(x->x_type->s_name,"checkbutton")) {
+ x->x_rect_width = 32;
+ x->x_rect_height = 28;
+ sys_vgui("checkbutton .x%x.c.s%x \
+ -command { fatom_cb%x $fatom_val%x} -variable fatom_val%x -text \"%s\" \
+ -bg %s \
+ -activebackground %s \
+ \n",canvas,x,x,x,x,
+ x->x_text->s_name,
+ x->x_color->s_name,
+ x->x_bgcolor->s_name);
+ } else if (!strcmp(x->x_type->s_name,"hradio")) {
+ int i;
+ x->x_rect_width = 8*20;
+ x->x_rect_height = 25;
+ for (i=0;i<8;i++) {
+ sys_vgui("radiobutton .x%x.c.s%x%d \
+ -command { fatom_cb%x $fatom_val%x} -variable fatom_val%x -value %d\n",canvas,x,i,x,x,x,i);
+ }
+ /* TODO pack them */
+ } else if (!strcmp(x->x_type->s_name,"vradio")) {
+ int i;
+ x->x_rect_width = 30;
+ x->x_rect_height = 20*8+5;
+ for (i=0;i<8;i++) {
+ sys_vgui("radiobutton .x%x.c.s%x%d \
+ -command { fatom_cb%x $fatom_val%x} -variable fatom_val%x -value %d\n",canvas,x,i,x,x,x,i);
+ }
+ /* TODO pack them */
+ } else {
+ x->x_rect_width = 32;
+ x->x_rect_height = 140;
+ sys_vgui("scale .x%x.c.s%x \
+ -sliderlength 10 \
+ -showvalue 0 \
+ -length 131 \
+ -from 127 -to 0 \
+ -command fatom_cb%x\n",canvas,x,x);
+ }
+
+ /* set the start value */
+ if (!strcmp(x->x_type->s_name,"checkbutton")) {
+ if (x->x_val)
+ sys_vgui(".x%x.c.s%x select\n",canvas,x,x->x_val);
+ else
+ sys_vgui(".x%x.c.s%x deselect\n",canvas,x,x->x_val);
+ } else
+ sys_vgui(".x%x.c.s%x set %f\n",canvas,x,x->x_val);
+
+}
+
+
+
+
+
+static void fatom_drawme(t_fatom *x, t_glist *glist, int firsttime)
+{
+ t_canvas *canvas=glist_getcanvas(glist);// x->x_glist;//glist_getcanvas(glist);
+ DEBUG(post("drawme %d",firsttime);)
+ if (firsttime) {
+ DEBUG(post("glist %x canvas %x",x->x_glist,canvas));
+ create_widget(x,glist);
+ x->x_glist = canvas;
+ sys_vgui(".x%x.c create window %d %d -anchor nw -window .x%x.c.s%x -tags %xS\n",
+ canvas,text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist)+2,x->x_glist,x,x);
+
+ }
+ else {
+ sys_vgui(".x%x.c coords %xS \
+%d %d\n",
+ canvas, x,
+ text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist)+2);
+ }
+ draw_inlets(x, glist, firsttime, 1,1);
+ // draw_handle(x, glist, firsttime);
+
+}
+
+
+static void fatom_erase(t_fatom* x,t_glist* glist)
+{
+ int n;
+
+ DEBUG(post("erase");)
+ sys_vgui("destroy .x%x.c.s%x\n",glist_getcanvas(glist),x);
+
+ sys_vgui(".x%x.c delete %xS\n",glist_getcanvas(glist), x);
+
+ /* inlets and outlets */
+
+ sys_vgui(".x%x.c delete %xi%d\n",glist_getcanvas(glist),x,0);
+ sys_vgui(".x%x.c delete %xo%d\n",glist_getcanvas(glist),x,0);
+ sys_vgui(".x%x.c delete %xhandle\n",glist_getcanvas(glist),x,0);
+}
+
+
+
+/* ------------------------ fatom widgetbehaviour----------------------------- */
+
+
+static void fatom_getrect(t_gobj *z, t_glist *owner,
+ int *xp1, int *yp1, int *xp2, int *yp2)
+{
+ int width, height;
+ t_fatom* s = (t_fatom*)z;
+
+ width = s->x_rect_width;
+ height = s->x_rect_height;
+ *xp1 = text_xpix(&s->x_obj, owner);
+ *yp1 = text_ypix(&s->x_obj, owner);
+ *xp2 = text_xpix(&s->x_obj, owner) + width;
+ *yp2 = text_ypix(&s->x_obj, owner) + height;
+}
+
+static void fatom_displace(t_gobj *z, t_glist *glist,
+ int dx, int dy)
+{
+ t_fatom *x = (t_fatom *)z;
+ DEBUG(post("displace");)
+ x->x_obj.te_xpix += dx;
+ x->x_obj.te_ypix += dy;
+ if (glist_isvisible(glist))
+ {
+ sys_vgui(".x%x.c coords %xSEL %d %d %d %d\n",
+ glist_getcanvas(glist), x,
+ text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist),
+ text_xpix(&x->x_obj, glist) + x->x_rect_width, text_ypix(&x->x_obj, glist) + x->x_rect_height);
+
+ fatom_drawme(x, glist, 0);
+ canvas_fixlinesfor(glist_getcanvas(glist),(t_text*) x);
+ }
+ DEBUG(post("displace end");)
+}
+
+static void fatom_select(t_gobj *z, t_glist *glist, int state)
+{
+ t_fatom *x = (t_fatom *)z;
+ if (state) {
+ sys_vgui(".x%x.c create rectangle \
+%d %d %d %d -tags %xSEL -outline blue\n",
+ glist_getcanvas(glist),
+ text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist),
+ text_xpix(&x->x_obj, glist) + x->x_rect_width, text_ypix(&x->x_obj, glist) + x->x_rect_height,
+ x);
+ }
+ else {
+ sys_vgui(".x%x.c delete %xSEL\n",
+ glist_getcanvas(glist), x);
+ }
+
+
+
+}
+
+
+static void fatom_activate(t_gobj *z, t_glist *glist, int state)
+{
+/* t_text *x = (t_text *)z;
+ t_rtext *y = glist_findrtext(glist, x);
+ if (z->g_pd != gatom_class) rtext_activate(y, state);*/
+}
+
+static void fatom_delete(t_gobj *z, t_glist *glist)
+{
+ t_text *x = (t_text *)z;
+ canvas_deletelinesfor(glist_getcanvas(glist), x);
+}
+
+
+static void fatom_vis(t_gobj *z, t_glist *glist, int vis)
+{
+ t_fatom* s = (t_fatom*)z;
+ t_rtext *y;
+ DEBUG(post("vis: %d",vis);)
+ if (vis) {
+#ifdef PD_MINOR_VERSION
+ y = (t_rtext *) rtext_new(glist, (t_text *)z);
+#else
+ y = (t_rtext *) rtext_new(glist, (t_text *)z,0,0);
+#endif
+ fatom_drawme(s, glist, 1);
+ }
+ else {
+ y = glist_findrtext(glist, (t_text *)z);
+ fatom_erase(s,glist);
+ rtext_free(y);
+ }
+}
+
+static void fatom_save(t_gobj *z, t_binbuf *b);
+
+t_widgetbehavior fatom_widgetbehavior;
+
+
+
+
+static void fatom_size(t_fatom* x,t_floatarg w,t_floatarg h) {
+ x->x_rect_width = w;
+ x->x_rect_height = h;
+}
+
+static void fatom_color(t_fatom* x,t_symbol* col)
+{
+
+}
+
+
+static void fatom_f(t_fatom* x,t_floatarg f)
+{
+ x->x_val = f;
+ if (x->x_send == &s_)
+ outlet_float(x->x_obj.ob_outlet,f);
+ else
+ if (x->x_send->s_thing) pd_float(x->x_send->s_thing,f);
+}
+
+
+static void fatom_float(t_fatom* x,t_floatarg f)
+{
+ if (glist_isvisible(x->x_glist)) {
+ if (!strcmp(x->x_type->s_name,"checkbutton")) {
+ if (x->x_val)
+ sys_vgui(".x%x.c.s%x select\n",x->x_glist,x,f);
+ else
+ sys_vgui(".x%x.c.s%x deselect\n",x->x_glist,x,f);
+ } else
+ sys_vgui(".x%x.c.s%x set %f\n",x->x_glist,x,f);
+ }
+ fatom_f(x,f);
+}
+
+
+static void fatom_bang(t_fatom* x,t_floatarg f)
+{
+ outlet_float(x->x_obj.ob_outlet,x->x_val);
+}
+
+
+static void fatom_properties(t_gobj *z, t_glist *owner)
+{
+ post("N/I");
+}
+
+
+static void fatom_save(t_gobj *z, t_binbuf *b)
+{
+
+ t_fatom *x = (t_fatom *)z;
+
+ binbuf_addv(b, "ssiiss", gensym("#X"),gensym("obj"),
+ x->x_obj.te_xpix, x->x_obj.te_ypix ,
+ gensym("fatom"),x->x_type);
+ binbuf_addv(b, ";");
+}
+
+
+static void *fatom_new(t_fatom* x,int argc,t_atom* argv)
+{
+ char buf[256];
+ int n = 0;
+ x->x_glist = canvas_getcurrent();
+
+ x->x_text = gensym("");
+ x->x_max = 127;
+ x->x_min = 0;
+ x->x_width = 15;
+ x->x_color = gensym("grey");
+ x->x_bgcolor = gensym("grey");
+ x->x_send = &s_;
+
+ while (argc) {
+ if (argv->a_type == A_FLOAT) {
+ if (n==0) x->x_max = atom_getfloat(argv);
+ if (n==1) x->x_min = atom_getfloat(argv);
+ if (n==2) x->x_width = atom_getfloat(argv);
+ }
+
+ if (argv->a_type == A_SYMBOL) {
+ post("%d: symbol value %s",n,atom_getsymbol(argv)->s_name);
+ if (n==3) x->x_send = atom_getsymbol(argv);
+ if (n==4) x->x_color = atom_getsymbol(argv);
+ if (n==5) x->x_bgcolor = atom_getsymbol(argv);
+ }
+ argv++;
+ argc--;
+ n++;
+ }
+
+ /* bind to a symbol for slider callback (later make this based on the
+ filepath ??) */
+
+ sprintf(buf,"fatom%x",(t_int)x);
+ x->x_sym = gensym(buf);
+ pd_bind(&x->x_obj.ob_pd, x->x_sym);
+
+ /* pipe startup code to tk */
+
+ sys_vgui("proc fatom_cb%x {v} {\n pd [concat fatom%x f $v \\;]\n }\n",x,x);
+
+ outlet_new(&x->x_obj, &s_float);
+ return (x);
+}
+
+static void fatom_setup_common(t_class* class)
+{
+
+ fatom_widgetbehavior.w_getrectfn = fatom_getrect;
+ fatom_widgetbehavior.w_displacefn = fatom_displace;
+ fatom_widgetbehavior.w_selectfn = fatom_select;
+ fatom_widgetbehavior.w_activatefn = fatom_activate;
+ fatom_widgetbehavior.w_deletefn = fatom_delete;
+ fatom_widgetbehavior.w_visfn = fatom_vis;
+#if PD_MINOR_VERSION < 37
+ fatom_widgetbehavior.w_savefn = fatom_save;
+ fatom_widgetbehavior.w_propertiesfn = NULL;
+#endif
+ fatom_widgetbehavior.w_clickfn = NULL;
+
+ class_addfloat(class, (t_method)fatom_float);
+ class_addbang(class, (t_method)fatom_bang);
+ class_addmethod(class, (t_method)fatom_f, gensym("f"),
+ A_FLOAT, 0);
+
+/*
+ class_addmethod(class, (t_method)fatom_size, gensym("size"),
+ A_FLOAT, A_FLOAT, 0);
+
+ class_addmethod(class, (t_method)fatom_color, gensym("color"),
+ A_SYMBOL, 0);
+*/
+/*
+ class_addmethod(class, (t_method)fatom_open, gensym("open"),
+ A_SYMBOL, 0);
+*/
+
+ class_setwidget(class,&fatom_widgetbehavior);
+#if PD_MINOR_VERSION >= 37
+ class_setsavefn(class,&fatom_save);
+#endif
+}
+/* ------------------------ fatom ----------------------------- */
+
+#define x_val a_pos.a_w.w_float
+#define DEBUG(x)
+
+#include <string.h>
+#include <stdio.h>
+
+typedef struct _fatom
+{
+ t_object x_obj;
+ t_atom a_pos; /* the value of the fatom */
+
+ t_symbol* x_send;
+ t_symbol* x_receive;
+ t_glist * x_glist; /* value of the current canvas, intialized in _new */
+ int x_rect_width; /* width of the widget */
+ int x_rect_height; /* height of the widget */
+ t_symbol* x_sym; /* symbol for receiving callbacks from GUI */
+ t_symbol* x_type; /* type of fatom (vslider, hslider, checkbutton) */
+
+ t_symbol* x_text; /* associated widget text */
+ int x_max; /* maximum value of a_pos (x_val) */
+ int x_min; /* minimum value of a_pos (x_val) */
+ int x_width; /* width of widget (e.g x_rect_height + 15 for hslider, x_rect_width + 15 for slider) */
+ t_symbol* x_color;
+ t_symbol* x_bgcolor;
+} t_fatom;
+
+/* widget helper functions */
+
+
+
+
+static void draw_inlets(t_fatom *x, t_glist *glist, int firsttime, int nin, int nout)
+{
+ int n = nin;
+ int nplus, i;
+ nplus = (n == 1 ? 1 : n-1);
+ DEBUG(post("draw inlet");)
+ for (i = 0; i < n; i++)
+ {
+ int onset = text_xpix(&x->x_obj, glist) + (x->x_rect_width - IOWIDTH) * i / nplus;
+ if (firsttime)
+ sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xo%d\n",
+ glist_getcanvas(glist),
+ onset, text_ypix(&x->x_obj, glist) + x->x_rect_height - 1,
+ onset + IOWIDTH, text_ypix(&x->x_obj, glist) + x->x_rect_height,
+ x, i);
+ else
+ sys_vgui(".x%x.c coords %xo%d %d %d %d %d\n",
+ glist_getcanvas(glist), x, i,
+ onset, text_ypix(&x->x_obj, glist) + x->x_rect_height - 1,
+ onset + IOWIDTH, text_ypix(&x->x_obj, glist) + x->x_rect_height);
+ }
+ n = nout;
+ nplus = (n == 1 ? 1 : n-1);
+ for (i = 0; i < n; i++)
+ {
+ int onset = text_xpix(&x->x_obj, glist) + (x->x_rect_width - IOWIDTH) * i / nplus;
+ if (firsttime)
+ sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xi%d\n",
+ glist_getcanvas(glist),
+ onset, text_ypix(&x->x_obj, glist),
+ onset + IOWIDTH, text_ypix(&x->x_obj, glist) + 1,
+ x, i);
+ else
+ sys_vgui(".x%x.c coords %xi%d %d %d %d %d\n",
+ glist_getcanvas(glist), x, i,
+ onset, text_ypix(&x->x_obj, glist),
+ onset + IOWIDTH, text_ypix(&x->x_obj, glist) + 1);
+
+ }
+ DEBUG(post("draw inlet end");)
+}
+
+
+static void draw_handle(t_fatom *x, t_glist *glist, int firsttime) {
+ int onset = text_xpix(&x->x_obj, glist) + (x->x_rect_width - IOWIDTH+2);
+
+ if (firsttime)
+ sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xhandle\n",
+ glist_getcanvas(glist),
+ onset, text_ypix(&x->x_obj, glist) + x->x_rect_height - 12,
+ onset + IOWIDTH, text_ypix(&x->x_obj, glist) + x->x_rect_height-4,
+ x);
+ else
+ sys_vgui(".x%x.c coords %xhandle %d %d %d %d\n",
+ glist_getcanvas(glist), x,
+ onset, text_ypix(&x->x_obj, glist) + x->x_rect_height - 12,
+ onset + IOWIDTH, text_ypix(&x->x_obj, glist) + x->x_rect_height-4);
+}
+
+static void create_widget(t_fatom *x, t_glist *glist)
+{
+ t_canvas *canvas=glist_getcanvas(glist);
+
+ if (!strcmp(x->x_type->s_name,"vslider")) {
+ x->x_rect_width = x->x_width+15;
+ x->x_rect_height = x->x_max-x->x_min+26;
+
+ sys_vgui("scale .x%x.c.s%x \
+ -sliderlength 10 \
+ -showvalue 0 \
+ -length %d \
+ -resolution 0.01 \
+ -repeatinterval 20 \
+ -from %d -to %d \
+ -width %d \
+ -bg %s \
+ -activebackground %s \
+ -troughcolor %s \
+ -command fatom_cb%x\n",canvas,x,
+ x->x_max-x->x_min+14,
+ x->x_max,
+ x->x_min,
+ x->x_width,
+ x->x_color->s_name,
+ x->x_color->s_name,
+ x->x_bgcolor->s_name,
+ x);
+ } else if (!strcmp(x->x_type->s_name,"hslider")) {
+ x->x_rect_width = x->x_max-x->x_min + 24;
+ x->x_rect_height = x->x_width + 15;
+ sys_vgui("scale .x%x.c.s%x \
+ -sliderlength 10 \
+ -showvalue 0 \
+ -length %d \
+ -resolution 0.01 \
+ -orient horizontal \
+ -repeatinterval 20 \
+ -from %d -to %d \
+ -width %d \
+ -bg %s \
+ -activebackground %s \
+ -troughcolor %s \
+ -command fatom_cb%x\n",canvas,x,
+ x->x_max-x->x_min+14,
+ x->x_min,
+ x->x_max,
+ x->x_width,
+ x->x_color->s_name,
+ x->x_color->s_name,
+ x->x_bgcolor->s_name,
+ x);
+ } else if (!strcmp(x->x_type->s_name,"checkbutton")) {
+ x->x_rect_width = 32;
+ x->x_rect_height = 28;
+ sys_vgui("checkbutton .x%x.c.s%x \
+ -command { fatom_cb%x $fatom_val%x} -variable fatom_val%x -text \"%s\" \
+ -bg %s \
+ -activebackground %s \
+ \n",canvas,x,x,x,x,
+ x->x_text->s_name,
+ x->x_color->s_name,
+ x->x_bgcolor->s_name);
+ } else if (!strcmp(x->x_type->s_name,"hradio")) {
+ int i;
+ x->x_rect_width = 8*20;
+ x->x_rect_height = 25;
+ for (i=0;i<8;i++) {
+ sys_vgui("radiobutton .x%x.c.s%x%d \
+ -command { fatom_cb%x $fatom_val%x} -variable fatom_val%x -value %d\n",canvas,x,i,x,x,x,i);
+ }
+ /* TODO pack them */
+ } else if (!strcmp(x->x_type->s_name,"vradio")) {
+ int i;
+ x->x_rect_width = 30;
+ x->x_rect_height = 20*8+5;
+ for (i=0;i<8;i++) {
+ sys_vgui("radiobutton .x%x.c.s%x%d \
+ -command { fatom_cb%x $fatom_val%x} -variable fatom_val%x -value %d\n",canvas,x,i,x,x,x,i);
+ }
+ /* TODO pack them */
+ } else {
+ x->x_rect_width = 32;
+ x->x_rect_height = 140;
+ sys_vgui("scale .x%x.c.s%x \
+ -sliderlength 10 \
+ -showvalue 0 \
+ -length 131 \
+ -from 127 -to 0 \
+ -command fatom_cb%x\n",canvas,x,x);
+ }
+
+ /* set the start value */
+ if (!strcmp(x->x_type->s_name,"checkbutton")) {
+ if (x->x_val)
+ sys_vgui(".x%x.c.s%x select\n",canvas,x,x->x_val);
+ else
+ sys_vgui(".x%x.c.s%x deselect\n",canvas,x,x->x_val);
+ } else
+ sys_vgui(".x%x.c.s%x set %f\n",canvas,x,x->x_val);
+
+}
+
+
+
+
+
+static void fatom_drawme(t_fatom *x, t_glist *glist, int firsttime)
+{
+ t_canvas *canvas=glist_getcanvas(glist);// x->x_glist;//glist_getcanvas(glist);
+ DEBUG(post("drawme %d",firsttime);)
+ if (firsttime) {
+ DEBUG(post("glist %x canvas %x",x->x_glist,canvas));
+ create_widget(x,glist);
+ x->x_glist = canvas;
+ sys_vgui(".x%x.c create window %d %d -anchor nw -window .x%x.c.s%x -tags %xS\n",
+ canvas,text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist)+2,x->x_glist,x,x);
+
+ }
+ else {
+ sys_vgui(".x%x.c coords %xS \
+%d %d\n",
+ canvas, x,
+ text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist)+2);
+ }
+ draw_inlets(x, glist, firsttime, 1,1);
+ // draw_handle(x, glist, firsttime);
+
+}
+
+
+static void fatom_erase(t_fatom* x,t_glist* glist)
+{
+ int n;
+
+ DEBUG(post("erase");)
+ sys_vgui("destroy .x%x.c.s%x\n",glist_getcanvas(glist),x);
+
+ sys_vgui(".x%x.c delete %xS\n",glist_getcanvas(glist), x);
+
+ /* inlets and outlets */
+
+ sys_vgui(".x%x.c delete %xi%d\n",glist_getcanvas(glist),x,0);
+ sys_vgui(".x%x.c delete %xo%d\n",glist_getcanvas(glist),x,0);
+ sys_vgui(".x%x.c delete %xhandle\n",glist_getcanvas(glist),x,0);
+}
+
+
+
+/* ------------------------ fatom widgetbehaviour----------------------------- */
+
+
+static void fatom_getrect(t_gobj *z, t_glist *owner,
+ int *xp1, int *yp1, int *xp2, int *yp2)
+{
+ int width, height;
+ t_fatom* s = (t_fatom*)z;
+
+ width = s->x_rect_width;
+ height = s->x_rect_height;
+ *xp1 = text_xpix(&s->x_obj, owner);
+ *yp1 = text_ypix(&s->x_obj, owner);
+ *xp2 = text_xpix(&s->x_obj, owner) + width;
+ *yp2 = text_ypix(&s->x_obj, owner) + height;
+}
+
+static void fatom_displace(t_gobj *z, t_glist *glist,
+ int dx, int dy)
+{
+ t_fatom *x = (t_fatom *)z;
+ DEBUG(post("displace");)
+ x->x_obj.te_xpix += dx;
+ x->x_obj.te_ypix += dy;
+ if (glist_isvisible(glist))
+ {
+ sys_vgui(".x%x.c coords %xSEL %d %d %d %d\n",
+ glist_getcanvas(glist), x,
+ text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist),
+ text_xpix(&x->x_obj, glist) + x->x_rect_width, text_ypix(&x->x_obj, glist) + x->x_rect_height);
+
+ fatom_drawme(x, glist, 0);
+ canvas_fixlinesfor(glist_getcanvas(glist),(t_text*) x);
+ }
+ DEBUG(post("displace end");)
+}
+
+static void fatom_select(t_gobj *z, t_glist *glist, int state)
+{
+ t_fatom *x = (t_fatom *)z;
+ if (state) {
+ sys_vgui(".x%x.c create rectangle \
+%d %d %d %d -tags %xSEL -outline blue\n",
+ glist_getcanvas(glist),
+ text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist),
+ text_xpix(&x->x_obj, glist) + x->x_rect_width, text_ypix(&x->x_obj, glist) + x->x_rect_height,
+ x);
+ }
+ else {
+ sys_vgui(".x%x.c delete %xSEL\n",
+ glist_getcanvas(glist), x);
+ }
+
+
+
+}
+
+
+static void fatom_activate(t_gobj *z, t_glist *glist, int state)
+{
+/* t_text *x = (t_text *)z;
+ t_rtext *y = glist_findrtext(glist, x);
+ if (z->g_pd != gatom_class) rtext_activate(y, state);*/
+}
+
+static void fatom_delete(t_gobj *z, t_glist *glist)
+{
+ t_text *x = (t_text *)z;
+ canvas_deletelinesfor(glist_getcanvas(glist), x);
+}
+
+
+static void fatom_vis(t_gobj *z, t_glist *glist, int vis)
+{
+ t_fatom* s = (t_fatom*)z;
+ t_rtext *y;
+ DEBUG(post("vis: %d",vis);)
+ if (vis) {
+#ifdef PD_MINOR_VERSION
+ y = (t_rtext *) rtext_new(glist, (t_text *)z);
+#else
+ y = (t_rtext *) rtext_new(glist, (t_text *)z,0,0);
+#endif
+ fatom_drawme(s, glist, 1);
+ }
+ else {
+ y = glist_findrtext(glist, (t_text *)z);
+ fatom_erase(s,glist);
+ rtext_free(y);
+ }
+}
+
+static void fatom_save(t_gobj *z, t_binbuf *b);
+
+t_widgetbehavior fatom_widgetbehavior;
+
+
+
+
+static void fatom_size(t_fatom* x,t_floatarg w,t_floatarg h) {
+ x->x_rect_width = w;
+ x->x_rect_height = h;
+}
+
+static void fatom_color(t_fatom* x,t_symbol* col)
+{
+
+}
+
+
+static void fatom_f(t_fatom* x,t_floatarg f)
+{
+ x->x_val = f;
+ if (x->x_send == &s_)
+ outlet_float(x->x_obj.ob_outlet,f);
+ else
+ if (x->x_send->s_thing) pd_float(x->x_send->s_thing,f);
+}
+
+
+static void fatom_float(t_fatom* x,t_floatarg f)
+{
+ if (glist_isvisible(x->x_glist)) {
+ if (!strcmp(x->x_type->s_name,"checkbutton")) {
+ if (x->x_val)
+ sys_vgui(".x%x.c.s%x select\n",x->x_glist,x,f);
+ else
+ sys_vgui(".x%x.c.s%x deselect\n",x->x_glist,x,f);
+ } else
+ sys_vgui(".x%x.c.s%x set %f\n",x->x_glist,x,f);
+ }
+ fatom_f(x,f);
+}
+
+
+static void fatom_bang(t_fatom* x,t_floatarg f)
+{
+ outlet_float(x->x_obj.ob_outlet,x->x_val);
+}
+
+
+static void fatom_properties(t_gobj *z, t_glist *owner)
+{
+ post("N/I");
+}
+
+
+static void fatom_save(t_gobj *z, t_binbuf *b)
+{
+
+ t_fatom *x = (t_fatom *)z;
+
+ binbuf_addv(b, "ssiiss", gensym("#X"),gensym("obj"),
+ x->x_obj.te_xpix, x->x_obj.te_ypix ,
+ gensym("fatom"),x->x_type);
+ binbuf_addv(b, ";");
+}
+
+
+static void *fatom_new(t_fatom* x,int argc,t_atom* argv)
+{
+ char buf[256];
+ int n = 0;
+ x->x_glist = canvas_getcurrent();
+
+ x->x_text = gensym("");
+ x->x_max = 127;
+ x->x_min = 0;
+ x->x_width = 15;
+ x->x_color = gensym("grey");
+ x->x_bgcolor = gensym("grey");
+ x->x_send = &s_;
+
+ while (argc) {
+ if (argv->a_type == A_FLOAT) {
+ if (n==0) x->x_max = atom_getfloat(argv);
+ if (n==1) x->x_min = atom_getfloat(argv);
+ if (n==2) x->x_width = atom_getfloat(argv);
+ }
+
+ if (argv->a_type == A_SYMBOL) {
+ post("%d: symbol value %s",n,atom_getsymbol(argv)->s_name);
+ if (n==3) x->x_send = atom_getsymbol(argv);
+ if (n==4) x->x_color = atom_getsymbol(argv);
+ if (n==5) x->x_bgcolor = atom_getsymbol(argv);
+ }
+ argv++;
+ argc--;
+ n++;
+ }
+
+ /* bind to a symbol for slider callback (later make this based on the
+ filepath ??) */
+
+ sprintf(buf,"fatom%x",(t_int)x);
+ x->x_sym = gensym(buf);
+ pd_bind(&x->x_obj.ob_pd, x->x_sym);
+
+ /* pipe startup code to tk */
+
+ sys_vgui("proc fatom_cb%x {v} {\n pd [concat fatom%x f $v \\;]\n }\n",x,x);
+
+ outlet_new(&x->x_obj, &s_float);
+ return (x);
+}
+
+static void fatom_setup_common(t_class* class)
+{
+
+ fatom_widgetbehavior.w_getrectfn = fatom_getrect;
+ fatom_widgetbehavior.w_displacefn = fatom_displace;
+ fatom_widgetbehavior.w_selectfn = fatom_select;
+ fatom_widgetbehavior.w_activatefn = fatom_activate;
+ fatom_widgetbehavior.w_deletefn = fatom_delete;
+ fatom_widgetbehavior.w_visfn = fatom_vis;
+#if PD_MINOR_VERSION < 37
+ fatom_widgetbehavior.w_savefn = fatom_save;
+ fatom_widgetbehavior.w_propertiesfn = NULL;
+#endif
+ fatom_widgetbehavior.w_clickfn = NULL;
+
+ class_addfloat(class, (t_method)fatom_float);
+ class_addbang(class, (t_method)fatom_bang);
+ class_addmethod(class, (t_method)fatom_f, gensym("f"),
+ A_FLOAT, 0);
+
+/*
+ class_addmethod(class, (t_method)fatom_size, gensym("size"),
+ A_FLOAT, A_FLOAT, 0);
+
+ class_addmethod(class, (t_method)fatom_color, gensym("color"),
+ A_SYMBOL, 0);
+*/
+/*
+ class_addmethod(class, (t_method)fatom_open, gensym("open"),
+ A_SYMBOL, 0);
+*/
+
+ class_setwidget(class,&fatom_widgetbehavior);
+#if PD_MINOR_VERSION >= 37
+ class_setsavefn(class,&fatom_save);
+#endif
+}
diff --git a/apps/plugins/pdbox/PDa/extra/filters.h b/apps/plugins/pdbox/PDa/extra/filters.h
new file mode 100644
index 0000000000..72d997e425
--- /dev/null
+++ b/apps/plugins/pdbox/PDa/extra/filters.h
@@ -0,0 +1,148 @@
+/*
+
+ These filter coefficients computations are taken from
+ http://www.harmony-central.com/Computer/Programming/Audio-EQ-Cookbook.txt
+
+ written by Robert Bristow-Johnson
+
+*/
+
+
+#ifndef __GGEE_FILTERS_H__
+#define __GGEE_FILTERS_H__
+
+
+
+#ifndef M_PI
+#define M_PI 3.141593f
+#endif
+
+
+#include <math.h>
+#define LN2 0.69314718
+#define e_A(g) (pow(10,(g/40.)))
+#define e_omega(f,r) (2.0*M_PI*f/r)
+#define e_alpha(bw,omega) (sin(omega)*sinh(LN2/2. * bw * omega/sin(omega)))
+#define e_beta(a,S) (sqrt((a*a + 1)/(S) - (a-1)*(a-1)))
+
+
+
+
+typedef struct _rbjfilter
+{
+ t_object x_obj;
+ t_float x_rate;
+ t_float x_freq;
+ t_float x_gain;
+ t_float x_bw;
+} t_rbjfilter;
+
+
+static int check_stability(t_float fb1,
+ t_float fb2,
+ t_float ff1,
+ t_float ff2,
+ t_float ff3)
+{
+ float discriminant = fb1 * fb1 + 4 * fb2;
+
+ if (discriminant < 0) /* imaginary roots -- resonant filter */
+ {
+ /* they're conjugates so we just check that the product
+ is less than one */
+ if (fb2 >= -1.0f) goto stable;
+ }
+ else /* real roots */
+ {
+ /* check that the parabola 1 - fb1 x - fb2 x^2 has a
+ vertex between -1 and 1, and that it's nonnegative
+ at both ends, which implies both roots are in [1-,1]. */
+ if (fb1 <= 2.0f && fb1 >= -2.0f &&
+ 1.0f - fb1 -fb2 >= 0 && 1.0f + fb1 - fb2 >= 0)
+ goto stable;
+ }
+ return 0;
+stable:
+ return 1;
+}
+
+
+
+
+
+
+#endif
+/*
+
+ These filter coefficients computations are taken from
+ http://www.harmony-central.com/Computer/Programming/Audio-EQ-Cookbook.txt
+
+ written by Robert Bristow-Johnson
+
+*/
+
+
+#ifndef __GGEE_FILTERS_H__
+#define __GGEE_FILTERS_H__
+
+
+
+#ifndef M_PI
+#define M_PI 3.141593f
+#endif
+
+
+#include <math.h>
+#define LN2 0.69314718
+#define e_A(g) (pow(10,(g/40.)))
+#define e_omega(f,r) (2.0*M_PI*f/r)
+#define e_alpha(bw,omega) (sin(omega)*sinh(LN2/2. * bw * omega/sin(omega)))
+#define e_beta(a,S) (sqrt((a*a + 1)/(S) - (a-1)*(a-1)))
+
+
+
+
+typedef struct _rbjfilter
+{
+ t_object x_obj;
+ t_float x_rate;
+ t_float x_freq;
+ t_float x_gain;
+ t_float x_bw;
+} t_rbjfilter;
+
+
+static int check_stability(t_float fb1,
+ t_float fb2,
+ t_float ff1,
+ t_float ff2,
+ t_float ff3)
+{
+ float discriminant = fb1 * fb1 + 4 * fb2;
+
+ if (discriminant < 0) /* imaginary roots -- resonant filter */
+ {
+ /* they're conjugates so we just check that the product
+ is less than one */
+ if (fb2 >= -1.0f) goto stable;
+ }
+ else /* real roots */
+ {
+ /* check that the parabola 1 - fb1 x - fb2 x^2 has a
+ vertex between -1 and 1, and that it's nonnegative
+ at both ends, which implies both roots are in [1-,1]. */
+ if (fb1 <= 2.0f && fb1 >= -2.0f &&
+ 1.0f - fb1 -fb2 >= 0 && 1.0f + fb1 - fb2 >= 0)
+ goto stable;
+ }
+ return 0;
+stable:
+ return 1;
+}
+
+
+
+
+
+
+#endif
diff --git a/apps/plugins/pdbox/PDa/extra/g_canvas.h b/apps/plugins/pdbox/PDa/extra/g_canvas.h
new file mode 100644
index 0000000000..54ab985feb
--- /dev/null
+++ b/apps/plugins/pdbox/PDa/extra/g_canvas.h
@@ -0,0 +1,1204 @@
+/* Copyright (c) 1997-1999 Miller Puckette.
+* For information on usage and redistribution, and for a DISCLAIMER OF ALL
+* WARRANTIES, see the file, "LICENSE.txt," in this distribution. */
+
+/* this file defines the structure for "glists" and related structures and
+functions. "Glists" and "canvases" and "graphs" used to be different
+structures until being unified in version 0.35.
+
+A glist occupies its own window if the "gl_havewindow" flag is set. Its
+appearance on its "parent" or "owner" (if it has one) is as a graph if
+"gl_isgraph" is set, and otherwise as a text box.
+
+A glist is "root" if it has no owner, i.e., a document window. In this
+case "gl_havewindow" is always set.
+
+We maintain a list of root windows, so that we can traverse the whole
+collection of everything in a Pd process.
+
+If a glist has a window it may still not be "mapped." Miniaturized
+windows aren't mapped, for example, but a window is also not mapped
+immediately upon creation. In either case gl_havewindow is true but
+gl_mapped is false.
+
+Closing a non-root window makes it invisible; closing a root destroys it.
+
+A glist that's just a text object on its parent is always "toplevel." An
+embedded glist can switch back and forth to appear as a toplevel by double-
+clicking on it. Single-clicking a text box makes the toplevel become visible
+and raises the window it's in.
+
+If a glist shows up as a graph on its parent, the graph is blanked while the
+glist has its own window, even if miniaturized.
+
+*/
+
+/* NOTE: this file describes Pd implementation details which may change
+in future releases. The public (stable) API is in m_pd.h. */
+
+#if defined(_LANGUAGE_C_PLUS_PLUS) || defined(__cplusplus)
+extern "C" {
+#endif
+
+/* --------------------- geometry ---------------------------- */
+#define IOWIDTH 7 /* width of an inlet/outlet in pixels */
+#define IOMIDDLE ((IOWIDTH-1)/2)
+#define GLIST_DEFGRAPHWIDTH 200
+#define GLIST_DEFGRAPHHEIGHT 140
+/* ----------------------- data ------------------------------- */
+
+typedef struct _updateheader
+{
+ struct _updateheader *upd_next;
+ unsigned int upd_array:1; /* true if array, false if glist */
+ unsigned int upd_queued:1; /* true if we're queued */
+} t_updateheader;
+
+ /* types to support glists grabbing mouse motion or keys from parent */
+typedef void (*t_glistmotionfn)(void *z, t_floatarg dx, t_floatarg dy);
+typedef void (*t_glistkeyfn)(void *z, t_floatarg key);
+
+EXTERN_STRUCT _rtext;
+#define t_rtext struct _rtext
+
+EXTERN_STRUCT _gtemplate;
+#define t_gtemplate struct _gtemplate
+
+EXTERN_STRUCT _guiconnect;
+#define t_guiconnect struct _guiconnect
+
+EXTERN_STRUCT _tscalar;
+#define t_tscalar struct _tscalar
+
+EXTERN_STRUCT _canvasenvironment;
+#define t_canvasenvironment struct _canvasenvironment
+
+typedef struct _selection
+{
+ t_gobj *sel_what;
+ struct _selection *sel_next;
+} t_selection;
+
+ /* this structure is instantiated whenever a glist becomes visible. */
+typedef struct _editor
+{
+ t_updateheader e_upd; /* update header structure */
+ t_selection *e_updlist; /* list of objects to update */
+ t_rtext *e_rtext; /* text responder linked list */
+ t_selection *e_selection; /* head of the selection list */
+ t_rtext *e_textedfor; /* the rtext if any that we are editing */
+ t_gobj *e_grab; /* object being "dragged" */
+ t_glistmotionfn e_motionfn; /* ... motion callback */
+ t_glistkeyfn e_keyfn; /* ... keypress callback */
+ t_binbuf *e_connectbuf; /* connections to deleted objects */
+ t_binbuf *e_deleted; /* last stuff we deleted */
+ t_guiconnect *e_guiconnect; /* GUI connection for filtering messages */
+ struct _glist *e_glist; /* glist which owns this */
+ int e_xwas; /* xpos on last mousedown or motion event */
+ int e_ywas; /* ypos, similarly */
+ int e_selectline_index1; /* indices for the selected line if any */
+ int e_selectline_outno; /* (only valid if e_selectedline is set) */
+ int e_selectline_index2;
+ int e_selectline_inno;
+ t_outconnect *e_selectline_tag;
+ unsigned int e_onmotion: 3; /* action to take on motion */
+ unsigned int e_lastmoved: 1; /* one if mouse has moved since click */
+ unsigned int e_textdirty: 1; /* one if e_textedfor has changed */
+ unsigned int e_selectedline: 1; /* one if a line is selected */
+} t_editor;
+
+#define MA_NONE 0 /* e_onmotion: do nothing on mouse motion */
+#define MA_MOVE 1 /* drag the selection around */
+#define MA_CONNECT 2 /* make a connection */
+#define MA_REGION 3 /* selection region */
+#define MA_PASSOUT 4 /* send on to e_grab */
+#define MA_DRAGTEXT 5 /* drag in text editor to alter selection */
+
+/* editor structure for "garrays". We don't bother to delete and regenerate
+this structure when the "garray" becomes invisible or visible, although we
+could do so if the structure gets big (like the "editor" above.) */
+
+typedef struct _arrayvis
+{
+ t_updateheader av_upd; /* update header structure */
+ t_garray *av_garray; /* owning structure */
+} t_arrayvis;
+
+/* the t_tick structure describes where to draw x and y "ticks" for a glist */
+
+typedef struct _tick /* where to put ticks on x or y axes */
+{
+ float k_point; /* one point to draw a big tick at */
+ float k_inc; /* x or y increment per little tick */
+ int k_lperb; /* little ticks per big; 0 if no ticks to draw */
+} t_tick;
+
+/* the t_glist structure, which describes a list of elements that live on an
+area of a window.
+
+*/
+
+struct _glist
+{
+ t_object gl_obj; /* header in case we're a glist */
+ t_gobj *gl_list; /* the actual data */
+ struct _gstub *gl_stub; /* safe pointer handler */
+ int gl_valid; /* incremented when pointers might be stale */
+ struct _glist *gl_owner; /* parent glist, supercanvas, or 0 if none */
+ int gl_pixwidth; /* width in pixels (on parent, if a graph) */
+ int gl_pixheight;
+ float gl_x1; /* bounding rectangle in our own coordinates */
+ float gl_y1;
+ float gl_x2;
+ float gl_y2;
+ int gl_screenx1; /* screen coordinates when toplevel */
+ int gl_screeny1;
+ int gl_screenx2;
+ int gl_screeny2;
+ t_tick gl_xtick; /* ticks marking X values */
+ int gl_nxlabels; /* number of X coordinate labels */
+ t_symbol **gl_xlabel; /* ... an array to hold them */
+ float gl_xlabely; /* ... and their Y coordinates */
+ t_tick gl_ytick; /* same as above for Y ticks and labels */
+ int gl_nylabels;
+ t_symbol **gl_ylabel;
+ float gl_ylabelx;
+ t_editor *gl_editor; /* editor structure when visible */
+ t_symbol *gl_name; /* symbol bound here */
+ int gl_font; /* nominal font size in points, e.g., 10 */
+ struct _glist *gl_next; /* link in list of toplevels */
+ t_canvasenvironment *gl_env; /* root canvases and abstractions only */
+ unsigned int gl_havewindow:1; /* true if we own a window */
+ unsigned int gl_mapped:1; /* true if, moreover, it's "mapped" */
+ unsigned int gl_dirty:1; /* (root canvas only:) patch has changed */
+ unsigned int gl_loading:1; /* am now loading from file */
+ unsigned int gl_willvis:1; /* make me visible after loading */
+ unsigned int gl_edit:1; /* edit mode */
+ unsigned int gl_isdeleting:1; /* we're inside glist_delete -- hack! */
+ unsigned int gl_stretch:1; /* stretch contents on resize */
+ unsigned int gl_isgraph:1; /* show as graph on parent */
+};
+
+#define gl_gobj gl_obj.te_g
+#define gl_pd gl_gobj.g_pd
+
+/* a data structure to describe a field in a pure datum */
+
+#define DT_FLOAT 0
+#define DT_SYMBOL 1
+#define DT_LIST 2
+#define DT_ARRAY 3
+
+typedef struct _dataslot
+{
+ int ds_type;
+ t_symbol *ds_name;
+ t_symbol *ds_arraytemplate; /* filled in for arrays only */
+} t_dataslot;
+
+
+/* T.Grill - changed t_pd member to t_pdobj to avoid name clashed */
+typedef struct _template
+{
+ t_pd t_pdobj; /* header */
+ struct _gtemplate *t_list; /* list of "struct"/gtemplate objects */
+ t_symbol *t_sym; /* name */
+ int t_n; /* number of dataslots (fields) */
+ t_dataslot *t_vec; /* array of dataslots */
+} t_template;
+
+struct _array
+{
+ int a_n; /* number of elements */
+ int a_elemsize; /* size in bytes; LATER get this from template */
+ char *a_vec; /* array of elements */
+ t_symbol *a_templatesym; /* template for elements */
+ int a_valid; /* protection against stale pointers into array */
+ t_gpointer a_gp; /* pointer to scalar or array element we're in */
+ t_gstub *a_stub;
+};
+
+ /* structure for traversing all the connections in a glist */
+typedef struct _linetraverser
+{
+ t_canvas *tr_x;
+ t_object *tr_ob;
+ int tr_nout;
+ int tr_outno;
+ t_object *tr_ob2;
+ t_outlet *tr_outlet;
+ t_inlet *tr_inlet;
+ int tr_nin;
+ int tr_inno;
+ int tr_x11, tr_y11, tr_x12, tr_y12;
+ int tr_x21, tr_y21, tr_x22, tr_y22;
+ int tr_lx1, tr_ly1, tr_lx2, tr_ly2;
+ t_outconnect *tr_nextoc;
+ int tr_nextoutno;
+} t_linetraverser;
+
+/* function types used to define graphical behavior for gobjs, a bit like X
+widgets. We don't use Pd methods because Pd's typechecking can't specify the
+types of pointer arguments. Also it's more convenient this way, since
+every "patchable" object can just get the "text" behaviors. */
+
+ /* Call this to get a gobj's bounding rectangle in pixels */
+typedef void (*t_getrectfn)(t_gobj *x, struct _glist *glist,
+ int *x1, int *y1, int *x2, int *y2);
+ /* and this to displace a gobj: */
+typedef void (*t_displacefn)(t_gobj *x, struct _glist *glist, int dx, int dy);
+ /* change color to show selection: */
+typedef void (*t_selectfn)(t_gobj *x, struct _glist *glist, int state);
+ /* change appearance to show activation/deactivation: */
+typedef void (*t_activatefn)(t_gobj *x, struct _glist *glist, int state);
+ /* warn a gobj it's about to be deleted */
+typedef void (*t_deletefn)(t_gobj *x, struct _glist *glist);
+ /* making visible or invisible */
+typedef void (*t_visfn)(t_gobj *x, struct _glist *glist, int flag);
+ /* field a mouse click (when not in "edit" mode) */
+typedef int (*t_clickfn)(t_gobj *x, struct _glist *glist,
+ int xpix, int ypix, int shift, int alt, int dbl, int doit);
+ /* ... and later, resizing; getting/setting font or color... */
+
+struct _widgetbehavior
+{
+ t_getrectfn w_getrectfn;
+ t_displacefn w_displacefn;
+ t_selectfn w_selectfn;
+ t_activatefn w_activatefn;
+ t_deletefn w_deletefn;
+ t_visfn w_visfn;
+ t_clickfn w_clickfn;
+};
+
+/* -------- behaviors for scalars defined by objects in template --------- */
+/* these are set by "drawing commands" in g_template.c which add appearance to
+scalars, which live in some other window. If the scalar is just included
+in a canvas the "parent" is a misnomer. There is also a text scalar object
+which really does draw the scalar on the parent window; see g_scalar.c. */
+
+/* note how the click function wants the whole scalar, not the "data", so
+doesn't work on array elements... LATER reconsider this */
+
+ /* bounding rectangle: */
+typedef void (*t_parentgetrectfn)(t_gobj *x, struct _glist *glist,
+ t_word *data, t_template *tmpl, float basex, float basey,
+ int *x1, int *y1, int *x2, int *y2);
+ /* displace it */
+typedef void (*t_parentdisplacefn)(t_gobj *x, struct _glist *glist,
+ t_word *data, t_template *tmpl, float basex, float basey,
+ int dx, int dy);
+ /* change color to show selection */
+typedef void (*t_parentselectfn)(t_gobj *x, struct _glist *glist,
+ t_word *data, t_template *tmpl, float basex, float basey,
+ int state);
+ /* change appearance to show activation/deactivation: */
+typedef void (*t_parentactivatefn)(t_gobj *x, struct _glist *glist,
+ t_word *data, t_template *tmpl, float basex, float basey,
+ int state);
+ /* making visible or invisible */
+typedef void (*t_parentvisfn)(t_gobj *x, struct _glist *glist,
+ t_word *data, t_template *tmpl, float basex, float basey,
+ int flag);
+ /* field a mouse click */
+typedef int (*t_parentclickfn)(t_gobj *x, struct _glist *glist,
+ t_scalar *sc, t_template *tmpl, float basex, float basey,
+ int xpix, int ypix, int shift, int alt, int dbl, int doit);
+
+struct _parentwidgetbehavior
+{
+ t_parentgetrectfn w_parentgetrectfn;
+ t_parentdisplacefn w_parentdisplacefn;
+ t_parentselectfn w_parentselectfn;
+ t_parentactivatefn w_parentactivatefn;
+ t_parentvisfn w_parentvisfn;
+ t_parentclickfn w_parentclickfn;
+};
+
+ /* cursor definitions; used as return value for t_parentclickfn */
+#define CURSOR_RUNMODE_NOTHING 0
+#define CURSOR_RUNMODE_CLICKME 1
+#define CURSOR_RUNMODE_THICKEN 2
+#define CURSOR_RUNMODE_ADDPOINT 3
+#define CURSOR_EDITMODE_NOTHING 4
+#define CURSOR_EDITMODE_CONNECT 5
+#define CURSOR_EDITMODE_DISCONNECT 6
+EXTERN void canvas_setcursor(t_glist *x, unsigned int cursornum);
+
+extern t_canvas *canvas_editing; /* last canvas to start text edting */
+extern t_canvas *canvas_whichfind; /* last canvas we did a find in */
+extern t_canvas *canvas_list; /* list of all root canvases */
+extern t_class *vinlet_class, *voutlet_class;
+extern int glist_valid; /* incremented when pointers might be stale */
+
+/* ------------------- functions on any gobj ----------------------------- */
+EXTERN void gobj_getrect(t_gobj *x, t_glist *owner, int *x1, int *y1,
+ int *x2, int *y2);
+EXTERN void gobj_displace(t_gobj *x, t_glist *owner, int dx, int dy);
+EXTERN void gobj_select(t_gobj *x, t_glist *owner, int state);
+EXTERN void gobj_activate(t_gobj *x, t_glist *owner, int state);
+EXTERN void gobj_delete(t_gobj *x, t_glist *owner);
+EXTERN void gobj_vis(t_gobj *x, t_glist *glist, int flag);
+EXTERN int gobj_click(t_gobj *x, struct _glist *glist,
+ int xpix, int ypix, int shift, int alt, int dbl, int doit);
+EXTERN void gobj_save(t_gobj *x, t_binbuf *b);
+EXTERN void gobj_properties(t_gobj *x, struct _glist *glist);
+EXTERN void gobj_save(t_gobj *x, t_binbuf *b);
+
+/* -------------------- functions on glists --------------------- */
+EXTERN t_glist *glist_new( void);
+EXTERN void glist_init(t_glist *x);
+EXTERN void glist_add(t_glist *x, t_gobj *g);
+EXTERN void glist_cleanup(t_glist *x);
+EXTERN void glist_free(t_glist *x);
+
+EXTERN void glist_clear(t_glist *x);
+EXTERN t_canvas *glist_getcanvas(t_glist *x);
+EXTERN int glist_isselected(t_glist *x, t_gobj *y);
+EXTERN void glist_select(t_glist *x, t_gobj *y);
+EXTERN void glist_deselect(t_glist *x, t_gobj *y);
+EXTERN void glist_noselect(t_glist *x);
+EXTERN void glist_selectall(t_glist *x);
+EXTERN void glist_delete(t_glist *x, t_gobj *y);
+EXTERN void glist_retext(t_glist *x, t_text *y);
+EXTERN void glist_grab(t_glist *x, t_gobj *y, t_glistmotionfn motionfn,
+ t_glistkeyfn keyfn, int xpos, int ypos);
+EXTERN int glist_isvisible(t_glist *x);
+EXTERN int glist_istoplevel(t_glist *x);
+EXTERN t_glist *glist_findgraph(t_glist *x);
+EXTERN int glist_getfont(t_glist *x);
+EXTERN void glist_sort(t_glist *canvas);
+EXTERN void glist_read(t_glist *x, t_symbol *filename, t_symbol *format);
+EXTERN void glist_mergefile(t_glist *x, t_symbol *filename, t_symbol *format);
+
+EXTERN float glist_pixelstox(t_glist *x, float xpix);
+EXTERN float glist_pixelstoy(t_glist *x, float ypix);
+EXTERN float glist_xtopixels(t_glist *x, float xval);
+EXTERN float glist_ytopixels(t_glist *x, float yval);
+EXTERN float glist_dpixtodx(t_glist *x, float dxpix);
+EXTERN float glist_dpixtody(t_glist *x, float dypix);
+
+EXTERN void glist_redrawitem(t_glist *owner, t_gobj *gobj);
+EXTERN void glist_getnextxy(t_glist *gl, int *xval, int *yval);
+EXTERN void glist_glist(t_glist *g, t_symbol *s, int argc, t_atom *argv);
+EXTERN t_glist *glist_addglist(t_glist *g, t_symbol *sym,
+ float x1, float y1, float x2, float y2,
+ float px1, float py1, float px2, float py2);
+EXTERN void glist_arraydialog(t_glist *parent, t_symbol *name,
+ t_floatarg size, t_floatarg saveit, t_floatarg newgraph);
+EXTERN t_binbuf *glist_writetobinbuf(t_glist *x, int wholething);
+EXTERN int glist_isgraph(t_glist *x);
+EXTERN void glist_redraw(t_glist *x);
+EXTERN void glist_drawiofor(t_glist *glist, t_object *ob, int firsttime,
+ char *tag, int x1, int y1, int x2, int y2);
+EXTERN void glist_eraseiofor(t_glist *glist, t_object *ob, char *tag);
+EXTERN void canvas_create_editor(t_glist *x, int createit);
+void canvas_deletelinesforio(t_canvas *x, t_text *text,
+ t_inlet *inp, t_outlet *outp);
+
+
+/* -------------------- functions on texts ------------------------- */
+EXTERN void text_setto(t_text *x, t_glist *glist, char *buf, int bufsize);
+EXTERN void text_drawborder(t_text *x, t_glist *glist, char *tag,
+ int width, int height, int firsttime);
+EXTERN void text_eraseborder(t_text *x, t_glist *glist, char *tag);
+EXTERN int text_xcoord(t_text *x, t_glist *glist);
+EXTERN int text_ycoord(t_text *x, t_glist *glist);
+EXTERN int text_xpix(t_text *x, t_glist *glist);
+EXTERN int text_ypix(t_text *x, t_glist *glist);
+EXTERN int text_shouldvis(t_text *x, t_glist *glist);
+
+/* -------------------- functions on rtexts ------------------------- */
+#define RTEXT_DOWN 1
+#define RTEXT_DRAG 2
+#define RTEXT_DBL 3
+#define RTEXT_SHIFT 4
+
+EXTERN t_rtext *rtext_new(t_glist *glist, t_text *who);
+EXTERN t_rtext *glist_findrtext(t_glist *gl, t_text *who);
+EXTERN void rtext_draw(t_rtext *x);
+EXTERN void rtext_erase(t_rtext *x);
+EXTERN t_rtext *rtext_remove(t_rtext *first, t_rtext *x);
+EXTERN int rtext_height(t_rtext *x);
+EXTERN void rtext_displace(t_rtext *x, int dx, int dy);
+EXTERN void rtext_select(t_rtext *x, int state);
+EXTERN void rtext_activate(t_rtext *x, int state);
+EXTERN void rtext_free(t_rtext *x);
+EXTERN void rtext_key(t_rtext *x, int n, t_symbol *s);
+EXTERN void rtext_mouse(t_rtext *x, int xval, int yval, int flag);
+EXTERN void rtext_retext(t_rtext *x);
+EXTERN int rtext_width(t_rtext *x);
+EXTERN int rtext_height(t_rtext *x);
+EXTERN char *rtext_gettag(t_rtext *x);
+EXTERN void rtext_gettext(t_rtext *x, char **buf, int *bufsize);
+
+/* -------------------- functions on canvases ------------------------ */
+EXTERN t_class *canvas_class;
+
+EXTERN t_canvas *canvas_new(void *dummy, t_symbol *sel, int argc, t_atom *argv);
+EXTERN t_symbol *canvas_makebindsym(t_symbol *s);
+EXTERN void canvas_vistext(t_canvas *x, t_text *y);
+EXTERN void canvas_fixlinesfor(t_canvas *x, t_text *text);
+EXTERN void canvas_deletelinesfor(t_canvas *x, t_text *text);
+EXTERN void canvas_stowconnections(t_canvas *x);
+EXTERN void canvas_restoreconnections(t_canvas *x);
+EXTERN void canvas_redraw(t_canvas *x);
+
+EXTERN t_inlet *canvas_addinlet(t_canvas *x, t_pd *who, t_symbol *sym);
+EXTERN void canvas_rminlet(t_canvas *x, t_inlet *ip);
+EXTERN t_outlet *canvas_addoutlet(t_canvas *x, t_pd *who, t_symbol *sym);
+EXTERN void canvas_rmoutlet(t_canvas *x, t_outlet *op);
+EXTERN void canvas_redrawallfortemplate(t_canvas *tmpl);
+EXTERN void canvas_zapallfortemplate(t_canvas *tmpl);
+EXTERN void canvas_setusedastemplate(t_canvas *x);
+EXTERN t_canvas *canvas_getcurrent(void);
+EXTERN void canvas_setcurrent(t_canvas *x);
+EXTERN void canvas_unsetcurrent(t_canvas *x);
+EXTERN t_symbol *canvas_realizedollar(t_canvas *x, t_symbol *s);
+EXTERN t_canvas *canvas_getrootfor(t_canvas *x);
+EXTERN void canvas_dirty(t_canvas *x, t_int n);
+EXTERN int canvas_getfont(t_canvas *x);
+typedef int (*t_canvasapply)(t_canvas *x, t_int x1, t_int x2, t_int x3);
+
+EXTERN t_int *canvas_recurapply(t_canvas *x, t_canvasapply *fn,
+ t_int x1, t_int x2, t_int x3);
+
+EXTERN void canvas_resortinlets(t_canvas *x);
+EXTERN void canvas_resortoutlets(t_canvas *x);
+EXTERN void canvas_free(t_canvas *x);
+EXTERN void canvas_updatewindowlist( void);
+EXTERN void canvas_editmode(t_canvas *x, t_floatarg yesplease);
+EXTERN int canvas_isabstraction(t_canvas *x);
+EXTERN int canvas_istable(t_canvas *x);
+EXTERN int canvas_showtext(t_canvas *x);
+EXTERN void canvas_vis(t_canvas *x, t_floatarg f);
+EXTERN t_canvasenvironment *canvas_getenv(t_canvas *x);
+EXTERN void canvas_rename(t_canvas *x, t_symbol *s, t_symbol *dir);
+EXTERN void canvas_loadbang(t_canvas *x);
+EXTERN int canvas_hitbox(t_canvas *x, t_gobj *y, int xpos, int ypos,
+ int *x1p, int *y1p, int *x2p, int *y2p);
+EXTERN int canvas_setdeleting(t_canvas *x, int flag);
+
+typedef void (*t_undofn)(t_canvas *canvas, void *buf,
+ int action); /* a function that does UNDO/REDO */
+#define UNDO_FREE 0 /* free current undo/redo buffer */
+#define UNDO_UNDO 1 /* undo */
+#define UNDO_REDO 2 /* redo */
+EXTERN void canvas_setundo(t_canvas *x, t_undofn undofn, void *buf,
+ const char *name);
+EXTERN void canvas_noundo(t_canvas *x);
+EXTERN int canvas_getindex(t_canvas *x, t_gobj *y);
+
+/* T.Grill - made public for dynamic object creation */
+/* in g_editor.c */
+EXTERN void canvas_connect(t_canvas *x,
+ t_floatarg fwhoout, t_floatarg foutno,t_floatarg fwhoin, t_floatarg finno);
+EXTERN void canvas_disconnect(t_canvas *x,
+ float index1, float outno, float index2, float inno);
+EXTERN int canvas_isconnected (t_canvas *x,
+ t_text *ob1, int n1, t_text *ob2, int n2);
+EXTERN void canvas_selectinrect(t_canvas *x, int lox, int loy, int hix, int hiy);
+
+
+/* ---- functions on canvasses as objects --------------------- */
+
+EXTERN void canvas_fattenforscalars(t_canvas *x,
+ int *x1, int *y1, int *x2, int *y2);
+EXTERN void canvas_visforscalars(t_canvas *x, t_glist *glist, int vis);
+EXTERN int canvas_clicksub(t_canvas *x, int xpix, int ypix, int shift,
+ int alt, int dbl, int doit);
+EXTERN t_glist *canvas_getglistonsuper(void);
+
+EXTERN void linetraverser_start(t_linetraverser *t, t_canvas *x);
+EXTERN t_outconnect *linetraverser_next(t_linetraverser *t);
+EXTERN void linetraverser_skipobject(t_linetraverser *t);
+
+/* --------------------- functions on tscalars --------------------- */
+
+EXTERN void tscalar_getrect(t_tscalar *x, t_glist *owner,
+ int *xp1, int *yp1, int *xp2, int *yp2);
+EXTERN void tscalar_vis(t_tscalar *x, t_glist *owner, int flag);
+EXTERN int tscalar_click(t_tscalar *x, int xpix, int ypix, int shift,
+ int alt, int dbl, int doit);
+
+/* --------- functions on garrays (graphical arrays) -------------------- */
+
+EXTERN t_template *garray_template(t_garray *x);
+
+/* -------------------- arrays --------------------- */
+EXTERN t_garray *graph_array(t_glist *gl, t_symbol *s, t_symbol *tmpl,
+ t_floatarg f, t_floatarg saveit);
+EXTERN t_array *array_new(t_symbol *templatesym, t_gpointer *parent);
+EXTERN void array_resize(t_array *x, t_template *tmpl, int n);
+EXTERN void array_free(t_array *x);
+
+/* --------------------- gpointers and stubs ---------------- */
+EXTERN t_gstub *gstub_new(t_glist *gl, t_array *a);
+EXTERN void gstub_cutoff(t_gstub *gs);
+EXTERN void gpointer_setglist(t_gpointer *gp, t_glist *glist, t_scalar *x);
+
+/* --------------------- scalars ------------------------- */
+EXTERN void word_init(t_word *wp, t_template *tmpl, t_gpointer *gp);
+EXTERN void word_restore(t_word *wp, t_template *tmpl,
+ int argc, t_atom *argv);
+EXTERN t_scalar *scalar_new(t_glist *owner,
+ t_symbol *templatesym);
+EXTERN void scalar_getbasexy(t_scalar *x, float *basex, float *basey);
+
+/* ------helper routines for "garrays" and "plots" -------------- */
+EXTERN int array_doclick(t_array *array, t_glist *glist, t_gobj *gobj,
+ t_symbol *elemtemplatesym,
+ float linewidth, float xloc, float xinc, float yloc,
+ int xpix, int ypix, int shift, int alt, int dbl, int doit);
+
+EXTERN void array_getcoordinate(t_glist *glist,
+ char *elem, int xonset, int yonset, int wonset, int indx,
+ float basex, float basey, float xinc,
+ float *xp, float *yp, float *wp);
+
+EXTERN int array_getfields(t_symbol *elemtemplatesym,
+ t_canvas **elemtemplatecanvasp,
+ t_template **elemtemplatep, int *elemsizep,
+ int *xonsetp, int *yonsetp, int *wonsetp);
+
+/* --------------------- templates ------------------------- */
+EXTERN t_template *template_new(t_symbol *sym, int argc, t_atom *argv);
+EXTERN void template_free(t_template *x);
+EXTERN int template_match(t_template *x1, t_template *x2);
+EXTERN int template_find_field(t_template *x, t_symbol *name, int *p_onset,
+ int *p_type, t_symbol **p_arraytype);
+EXTERN t_float template_getfloat(t_template *x, t_symbol *fieldname, t_word *wp,
+ int loud);
+EXTERN void template_setfloat(t_template *x, t_symbol *fieldname, t_word *wp,
+ t_float f, int loud);
+EXTERN t_symbol *template_getsymbol(t_template *x, t_symbol *fieldname,
+ t_word *wp, int loud);
+EXTERN void template_setsymbol(t_template *x, t_symbol *fieldname,
+ t_word *wp, t_symbol *s, int loud);
+
+EXTERN t_template *gtemplate_get(t_gtemplate *x);
+EXTERN t_template *template_findbyname(t_symbol *s);
+EXTERN t_canvas *template_findcanvas(t_template *tmpl);
+
+EXTERN t_float template_getfloat(t_template *x, t_symbol *fieldname,
+ t_word *wp, int loud);
+EXTERN void template_setfloat(t_template *x, t_symbol *fieldname,
+ t_word *wp, t_float f, int loud);
+EXTERN t_symbol *template_getsymbol(t_template *x, t_symbol *fieldname,
+ t_word *wp, int loud);
+EXTERN void template_setsymbol(t_template *x, t_symbol *fieldname,
+ t_word *wp, t_symbol *s, int loud);
+
+/* ----------------------- guiconnects, g_guiconnect.c --------- */
+EXTERN t_guiconnect *guiconnect_new(t_pd *who, t_symbol *sym);
+EXTERN void guiconnect_notarget(t_guiconnect *x, double timedelay);
+
+/* ------------- IEMGUI routines used in other g_ files ---------------- */
+EXTERN t_symbol *iemgui_raute2dollar(t_symbol *s);
+EXTERN t_symbol *iemgui_dollar2raute(t_symbol *s);
+
+#if defined(_LANGUAGE_C_PLUS_PLUS) || defined(__cplusplus)
+}
+#endif
+/* Copyright (c) 1997-1999 Miller Puckette.
+* For information on usage and redistribution, and for a DISCLAIMER OF ALL
+* WARRANTIES, see the file, "LICENSE.txt," in this distribution. */
+
+/* this file defines the structure for "glists" and related structures and
+functions. "Glists" and "canvases" and "graphs" used to be different
+structures until being unified in version 0.35.
+
+A glist occupies its own window if the "gl_havewindow" flag is set. Its
+appearance on its "parent" or "owner" (if it has one) is as a graph if
+"gl_isgraph" is set, and otherwise as a text box.
+
+A glist is "root" if it has no owner, i.e., a document window. In this
+case "gl_havewindow" is always set.
+
+We maintain a list of root windows, so that we can traverse the whole
+collection of everything in a Pd process.
+
+If a glist has a window it may still not be "mapped." Miniaturized
+windows aren't mapped, for example, but a window is also not mapped
+immediately upon creation. In either case gl_havewindow is true but
+gl_mapped is false.
+
+Closing a non-root window makes it invisible; closing a root destroys it.
+
+A glist that's just a text object on its parent is always "toplevel." An
+embedded glist can switch back and forth to appear as a toplevel by double-
+clicking on it. Single-clicking a text box makes the toplevel become visible
+and raises the window it's in.
+
+If a glist shows up as a graph on its parent, the graph is blanked while the
+glist has its own window, even if miniaturized.
+
+*/
+
+/* NOTE: this file describes Pd implementation details which may change
+in future releases. The public (stable) API is in m_pd.h. */
+
+#if defined(_LANGUAGE_C_PLUS_PLUS) || defined(__cplusplus)
+extern "C" {
+#endif
+
+/* --------------------- geometry ---------------------------- */
+#define IOWIDTH 7 /* width of an inlet/outlet in pixels */
+#define IOMIDDLE ((IOWIDTH-1)/2)
+#define GLIST_DEFGRAPHWIDTH 200
+#define GLIST_DEFGRAPHHEIGHT 140
+/* ----------------------- data ------------------------------- */
+
+typedef struct _updateheader
+{
+ struct _updateheader *upd_next;
+ unsigned int upd_array:1; /* true if array, false if glist */
+ unsigned int upd_queued:1; /* true if we're queued */
+} t_updateheader;
+
+ /* types to support glists grabbing mouse motion or keys from parent */
+typedef void (*t_glistmotionfn)(void *z, t_floatarg dx, t_floatarg dy);
+typedef void (*t_glistkeyfn)(void *z, t_floatarg key);
+
+EXTERN_STRUCT _rtext;
+#define t_rtext struct _rtext
+
+EXTERN_STRUCT _gtemplate;
+#define t_gtemplate struct _gtemplate
+
+EXTERN_STRUCT _guiconnect;
+#define t_guiconnect struct _guiconnect
+
+EXTERN_STRUCT _tscalar;
+#define t_tscalar struct _tscalar
+
+EXTERN_STRUCT _canvasenvironment;
+#define t_canvasenvironment struct _canvasenvironment
+
+typedef struct _selection
+{
+ t_gobj *sel_what;
+ struct _selection *sel_next;
+} t_selection;
+
+ /* this structure is instantiated whenever a glist becomes visible. */
+typedef struct _editor
+{
+ t_updateheader e_upd; /* update header structure */
+ t_selection *e_updlist; /* list of objects to update */
+ t_rtext *e_rtext; /* text responder linked list */
+ t_selection *e_selection; /* head of the selection list */
+ t_rtext *e_textedfor; /* the rtext if any that we are editing */
+ t_gobj *e_grab; /* object being "dragged" */
+ t_glistmotionfn e_motionfn; /* ... motion callback */
+ t_glistkeyfn e_keyfn; /* ... keypress callback */
+ t_binbuf *e_connectbuf; /* connections to deleted objects */
+ t_binbuf *e_deleted; /* last stuff we deleted */
+ t_guiconnect *e_guiconnect; /* GUI connection for filtering messages */
+ struct _glist *e_glist; /* glist which owns this */
+ int e_xwas; /* xpos on last mousedown or motion event */
+ int e_ywas; /* ypos, similarly */
+ int e_selectline_index1; /* indices for the selected line if any */
+ int e_selectline_outno; /* (only valid if e_selectedline is set) */
+ int e_selectline_index2;
+ int e_selectline_inno;
+ t_outconnect *e_selectline_tag;
+ unsigned int e_onmotion: 3; /* action to take on motion */
+ unsigned int e_lastmoved: 1; /* one if mouse has moved since click */
+ unsigned int e_textdirty: 1; /* one if e_textedfor has changed */
+ unsigned int e_selectedline: 1; /* one if a line is selected */
+} t_editor;
+
+#define MA_NONE 0 /* e_onmotion: do nothing on mouse motion */
+#define MA_MOVE 1 /* drag the selection around */
+#define MA_CONNECT 2 /* make a connection */
+#define MA_REGION 3 /* selection region */
+#define MA_PASSOUT 4 /* send on to e_grab */
+#define MA_DRAGTEXT 5 /* drag in text editor to alter selection */
+
+/* editor structure for "garrays". We don't bother to delete and regenerate
+this structure when the "garray" becomes invisible or visible, although we
+could do so if the structure gets big (like the "editor" above.) */
+
+typedef struct _arrayvis
+{
+ t_updateheader av_upd; /* update header structure */
+ t_garray *av_garray; /* owning structure */
+} t_arrayvis;
+
+/* the t_tick structure describes where to draw x and y "ticks" for a glist */
+
+typedef struct _tick /* where to put ticks on x or y axes */
+{
+ float k_point; /* one point to draw a big tick at */
+ float k_inc; /* x or y increment per little tick */
+ int k_lperb; /* little ticks per big; 0 if no ticks to draw */
+} t_tick;
+
+/* the t_glist structure, which describes a list of elements that live on an
+area of a window.
+
+*/
+
+struct _glist
+{
+ t_object gl_obj; /* header in case we're a glist */
+ t_gobj *gl_list; /* the actual data */
+ struct _gstub *gl_stub; /* safe pointer handler */
+ int gl_valid; /* incremented when pointers might be stale */
+ struct _glist *gl_owner; /* parent glist, supercanvas, or 0 if none */
+ int gl_pixwidth; /* width in pixels (on parent, if a graph) */
+ int gl_pixheight;
+ float gl_x1; /* bounding rectangle in our own coordinates */
+ float gl_y1;
+ float gl_x2;
+ float gl_y2;
+ int gl_screenx1; /* screen coordinates when toplevel */
+ int gl_screeny1;
+ int gl_screenx2;
+ int gl_screeny2;
+ t_tick gl_xtick; /* ticks marking X values */
+ int gl_nxlabels; /* number of X coordinate labels */
+ t_symbol **gl_xlabel; /* ... an array to hold them */
+ float gl_xlabely; /* ... and their Y coordinates */
+ t_tick gl_ytick; /* same as above for Y ticks and labels */
+ int gl_nylabels;
+ t_symbol **gl_ylabel;
+ float gl_ylabelx;
+ t_editor *gl_editor; /* editor structure when visible */
+ t_symbol *gl_name; /* symbol bound here */
+ int gl_font; /* nominal font size in points, e.g., 10 */
+ struct _glist *gl_next; /* link in list of toplevels */
+ t_canvasenvironment *gl_env; /* root canvases and abstractions only */
+ unsigned int gl_havewindow:1; /* true if we own a window */
+ unsigned int gl_mapped:1; /* true if, moreover, it's "mapped" */
+ unsigned int gl_dirty:1; /* (root canvas only:) patch has changed */
+ unsigned int gl_loading:1; /* am now loading from file */
+ unsigned int gl_willvis:1; /* make me visible after loading */
+ unsigned int gl_edit:1; /* edit mode */
+ unsigned int gl_isdeleting:1; /* we're inside glist_delete -- hack! */
+ unsigned int gl_stretch:1; /* stretch contents on resize */
+ unsigned int gl_isgraph:1; /* show as graph on parent */
+};
+
+#define gl_gobj gl_obj.te_g
+#define gl_pd gl_gobj.g_pd
+
+/* a data structure to describe a field in a pure datum */
+
+#define DT_FLOAT 0
+#define DT_SYMBOL 1
+#define DT_LIST 2
+#define DT_ARRAY 3
+
+typedef struct _dataslot
+{
+ int ds_type;
+ t_symbol *ds_name;
+ t_symbol *ds_arraytemplate; /* filled in for arrays only */
+} t_dataslot;
+
+
+/* T.Grill - changed t_pd member to t_pdobj to avoid name clashed */
+typedef struct _template
+{
+ t_pd t_pdobj; /* header */
+ struct _gtemplate *t_list; /* list of "struct"/gtemplate objects */
+ t_symbol *t_sym; /* name */
+ int t_n; /* number of dataslots (fields) */
+ t_dataslot *t_vec; /* array of dataslots */
+} t_template;
+
+struct _array
+{
+ int a_n; /* number of elements */
+ int a_elemsize; /* size in bytes; LATER get this from template */
+ char *a_vec; /* array of elements */
+ t_symbol *a_templatesym; /* template for elements */
+ int a_valid; /* protection against stale pointers into array */
+ t_gpointer a_gp; /* pointer to scalar or array element we're in */
+ t_gstub *a_stub;
+};
+
+ /* structure for traversing all the connections in a glist */
+typedef struct _linetraverser
+{
+ t_canvas *tr_x;
+ t_object *tr_ob;
+ int tr_nout;
+ int tr_outno;
+ t_object *tr_ob2;
+ t_outlet *tr_outlet;
+ t_inlet *tr_inlet;
+ int tr_nin;
+ int tr_inno;
+ int tr_x11, tr_y11, tr_x12, tr_y12;
+ int tr_x21, tr_y21, tr_x22, tr_y22;
+ int tr_lx1, tr_ly1, tr_lx2, tr_ly2;
+ t_outconnect *tr_nextoc;
+ int tr_nextoutno;
+} t_linetraverser;
+
+/* function types used to define graphical behavior for gobjs, a bit like X
+widgets. We don't use Pd methods because Pd's typechecking can't specify the
+types of pointer arguments. Also it's more convenient this way, since
+every "patchable" object can just get the "text" behaviors. */
+
+ /* Call this to get a gobj's bounding rectangle in pixels */
+typedef void (*t_getrectfn)(t_gobj *x, struct _glist *glist,
+ int *x1, int *y1, int *x2, int *y2);
+ /* and this to displace a gobj: */
+typedef void (*t_displacefn)(t_gobj *x, struct _glist *glist, int dx, int dy);
+ /* change color to show selection: */
+typedef void (*t_selectfn)(t_gobj *x, struct _glist *glist, int state);
+ /* change appearance to show activation/deactivation: */
+typedef void (*t_activatefn)(t_gobj *x, struct _glist *glist, int state);
+ /* warn a gobj it's about to be deleted */
+typedef void (*t_deletefn)(t_gobj *x, struct _glist *glist);
+ /* making visible or invisible */
+typedef void (*t_visfn)(t_gobj *x, struct _glist *glist, int flag);
+ /* field a mouse click (when not in "edit" mode) */
+typedef int (*t_clickfn)(t_gobj *x, struct _glist *glist,
+ int xpix, int ypix, int shift, int alt, int dbl, int doit);
+ /* ... and later, resizing; getting/setting font or color... */
+
+struct _widgetbehavior
+{
+ t_getrectfn w_getrectfn;
+ t_displacefn w_displacefn;
+ t_selectfn w_selectfn;
+ t_activatefn w_activatefn;
+ t_deletefn w_deletefn;
+ t_visfn w_visfn;
+ t_clickfn w_clickfn;
+};
+
+/* -------- behaviors for scalars defined by objects in template --------- */
+/* these are set by "drawing commands" in g_template.c which add appearance to
+scalars, which live in some other window. If the scalar is just included
+in a canvas the "parent" is a misnomer. There is also a text scalar object
+which really does draw the scalar on the parent window; see g_scalar.c. */
+
+/* note how the click function wants the whole scalar, not the "data", so
+doesn't work on array elements... LATER reconsider this */
+
+ /* bounding rectangle: */
+typedef void (*t_parentgetrectfn)(t_gobj *x, struct _glist *glist,
+ t_word *data, t_template *tmpl, float basex, float basey,
+ int *x1, int *y1, int *x2, int *y2);
+ /* displace it */
+typedef void (*t_parentdisplacefn)(t_gobj *x, struct _glist *glist,
+ t_word *data, t_template *tmpl, float basex, float basey,
+ int dx, int dy);
+ /* change color to show selection */
+typedef void (*t_parentselectfn)(t_gobj *x, struct _glist *glist,
+ t_word *data, t_template *tmpl, float basex, float basey,
+ int state);
+ /* change appearance to show activation/deactivation: */
+typedef void (*t_parentactivatefn)(t_gobj *x, struct _glist *glist,
+ t_word *data, t_template *tmpl, float basex, float basey,
+ int state);
+ /* making visible or invisible */
+typedef void (*t_parentvisfn)(t_gobj *x, struct _glist *glist,
+ t_word *data, t_template *tmpl, float basex, float basey,
+ int flag);
+ /* field a mouse click */
+typedef int (*t_parentclickfn)(t_gobj *x, struct _glist *glist,
+ t_scalar *sc, t_template *tmpl, float basex, float basey,
+ int xpix, int ypix, int shift, int alt, int dbl, int doit);
+
+struct _parentwidgetbehavior
+{
+ t_parentgetrectfn w_parentgetrectfn;
+ t_parentdisplacefn w_parentdisplacefn;
+ t_parentselectfn w_parentselectfn;
+ t_parentactivatefn w_parentactivatefn;
+ t_parentvisfn w_parentvisfn;
+ t_parentclickfn w_parentclickfn;
+};
+
+ /* cursor definitions; used as return value for t_parentclickfn */
+#define CURSOR_RUNMODE_NOTHING 0
+#define CURSOR_RUNMODE_CLICKME 1
+#define CURSOR_RUNMODE_THICKEN 2
+#define CURSOR_RUNMODE_ADDPOINT 3
+#define CURSOR_EDITMODE_NOTHING 4
+#define CURSOR_EDITMODE_CONNECT 5
+#define CURSOR_EDITMODE_DISCONNECT 6
+EXTERN void canvas_setcursor(t_glist *x, unsigned int cursornum);
+
+extern t_canvas *canvas_editing; /* last canvas to start text edting */
+extern t_canvas *canvas_whichfind; /* last canvas we did a find in */
+extern t_canvas *canvas_list; /* list of all root canvases */
+extern t_class *vinlet_class, *voutlet_class;
+extern int glist_valid; /* incremented when pointers might be stale */
+
+/* ------------------- functions on any gobj ----------------------------- */
+EXTERN void gobj_getrect(t_gobj *x, t_glist *owner, int *x1, int *y1,
+ int *x2, int *y2);
+EXTERN void gobj_displace(t_gobj *x, t_glist *owner, int dx, int dy);
+EXTERN void gobj_select(t_gobj *x, t_glist *owner, int state);
+EXTERN void gobj_activate(t_gobj *x, t_glist *owner, int state);
+EXTERN void gobj_delete(t_gobj *x, t_glist *owner);
+EXTERN void gobj_vis(t_gobj *x, t_glist *glist, int flag);
+EXTERN int gobj_click(t_gobj *x, struct _glist *glist,
+ int xpix, int ypix, int shift, int alt, int dbl, int doit);
+EXTERN void gobj_save(t_gobj *x, t_binbuf *b);
+EXTERN void gobj_properties(t_gobj *x, struct _glist *glist);
+EXTERN void gobj_save(t_gobj *x, t_binbuf *b);
+
+/* -------------------- functions on glists --------------------- */
+EXTERN t_glist *glist_new( void);
+EXTERN void glist_init(t_glist *x);
+EXTERN void glist_add(t_glist *x, t_gobj *g);
+EXTERN void glist_cleanup(t_glist *x);
+EXTERN void glist_free(t_glist *x);
+
+EXTERN void glist_clear(t_glist *x);
+EXTERN t_canvas *glist_getcanvas(t_glist *x);
+EXTERN int glist_isselected(t_glist *x, t_gobj *y);
+EXTERN void glist_select(t_glist *x, t_gobj *y);
+EXTERN void glist_deselect(t_glist *x, t_gobj *y);
+EXTERN void glist_noselect(t_glist *x);
+EXTERN void glist_selectall(t_glist *x);
+EXTERN void glist_delete(t_glist *x, t_gobj *y);
+EXTERN void glist_retext(t_glist *x, t_text *y);
+EXTERN void glist_grab(t_glist *x, t_gobj *y, t_glistmotionfn motionfn,
+ t_glistkeyfn keyfn, int xpos, int ypos);
+EXTERN int glist_isvisible(t_glist *x);
+EXTERN int glist_istoplevel(t_glist *x);
+EXTERN t_glist *glist_findgraph(t_glist *x);
+EXTERN int glist_getfont(t_glist *x);
+EXTERN void glist_sort(t_glist *canvas);
+EXTERN void glist_read(t_glist *x, t_symbol *filename, t_symbol *format);
+EXTERN void glist_mergefile(t_glist *x, t_symbol *filename, t_symbol *format);
+
+EXTERN float glist_pixelstox(t_glist *x, float xpix);
+EXTERN float glist_pixelstoy(t_glist *x, float ypix);
+EXTERN float glist_xtopixels(t_glist *x, float xval);
+EXTERN float glist_ytopixels(t_glist *x, float yval);
+EXTERN float glist_dpixtodx(t_glist *x, float dxpix);
+EXTERN float glist_dpixtody(t_glist *x, float dypix);
+
+EXTERN void glist_redrawitem(t_glist *owner, t_gobj *gobj);
+EXTERN void glist_getnextxy(t_glist *gl, int *xval, int *yval);
+EXTERN void glist_glist(t_glist *g, t_symbol *s, int argc, t_atom *argv);
+EXTERN t_glist *glist_addglist(t_glist *g, t_symbol *sym,
+ float x1, float y1, float x2, float y2,
+ float px1, float py1, float px2, float py2);
+EXTERN void glist_arraydialog(t_glist *parent, t_symbol *name,
+ t_floatarg size, t_floatarg saveit, t_floatarg newgraph);
+EXTERN t_binbuf *glist_writetobinbuf(t_glist *x, int wholething);
+EXTERN int glist_isgraph(t_glist *x);
+EXTERN void glist_redraw(t_glist *x);
+EXTERN void glist_drawiofor(t_glist *glist, t_object *ob, int firsttime,
+ char *tag, int x1, int y1, int x2, int y2);
+EXTERN void glist_eraseiofor(t_glist *glist, t_object *ob, char *tag);
+EXTERN void canvas_create_editor(t_glist *x, int createit);
+void canvas_deletelinesforio(t_canvas *x, t_text *text,
+ t_inlet *inp, t_outlet *outp);
+
+
+/* -------------------- functions on texts ------------------------- */
+EXTERN void text_setto(t_text *x, t_glist *glist, char *buf, int bufsize);
+EXTERN void text_drawborder(t_text *x, t_glist *glist, char *tag,
+ int width, int height, int firsttime);
+EXTERN void text_eraseborder(t_text *x, t_glist *glist, char *tag);
+EXTERN int text_xcoord(t_text *x, t_glist *glist);
+EXTERN int text_ycoord(t_text *x, t_glist *glist);
+EXTERN int text_xpix(t_text *x, t_glist *glist);
+EXTERN int text_ypix(t_text *x, t_glist *glist);
+EXTERN int text_shouldvis(t_text *x, t_glist *glist);
+
+/* -------------------- functions on rtexts ------------------------- */
+#define RTEXT_DOWN 1
+#define RTEXT_DRAG 2
+#define RTEXT_DBL 3
+#define RTEXT_SHIFT 4
+
+EXTERN t_rtext *rtext_new(t_glist *glist, t_text *who);
+EXTERN t_rtext *glist_findrtext(t_glist *gl, t_text *who);
+EXTERN void rtext_draw(t_rtext *x);
+EXTERN void rtext_erase(t_rtext *x);
+EXTERN t_rtext *rtext_remove(t_rtext *first, t_rtext *x);
+EXTERN int rtext_height(t_rtext *x);
+EXTERN void rtext_displace(t_rtext *x, int dx, int dy);
+EXTERN void rtext_select(t_rtext *x, int state);
+EXTERN void rtext_activate(t_rtext *x, int state);
+EXTERN void rtext_free(t_rtext *x);
+EXTERN void rtext_key(t_rtext *x, int n, t_symbol *s);
+EXTERN void rtext_mouse(t_rtext *x, int xval, int yval, int flag);
+EXTERN void rtext_retext(t_rtext *x);
+EXTERN int rtext_width(t_rtext *x);
+EXTERN int rtext_height(t_rtext *x);
+EXTERN char *rtext_gettag(t_rtext *x);
+EXTERN void rtext_gettext(t_rtext *x, char **buf, int *bufsize);
+
+/* -------------------- functions on canvases ------------------------ */
+EXTERN t_class *canvas_class;
+
+EXTERN t_canvas *canvas_new(void *dummy, t_symbol *sel, int argc, t_atom *argv);
+EXTERN t_symbol *canvas_makebindsym(t_symbol *s);
+EXTERN void canvas_vistext(t_canvas *x, t_text *y);
+EXTERN void canvas_fixlinesfor(t_canvas *x, t_text *text);
+EXTERN void canvas_deletelinesfor(t_canvas *x, t_text *text);
+EXTERN void canvas_stowconnections(t_canvas *x);
+EXTERN void canvas_restoreconnections(t_canvas *x);
+EXTERN void canvas_redraw(t_canvas *x);
+
+EXTERN t_inlet *canvas_addinlet(t_canvas *x, t_pd *who, t_symbol *sym);
+EXTERN void canvas_rminlet(t_canvas *x, t_inlet *ip);
+EXTERN t_outlet *canvas_addoutlet(t_canvas *x, t_pd *who, t_symbol *sym);
+EXTERN void canvas_rmoutlet(t_canvas *x, t_outlet *op);
+EXTERN void canvas_redrawallfortemplate(t_canvas *tmpl);
+EXTERN void canvas_zapallfortemplate(t_canvas *tmpl);
+EXTERN void canvas_setusedastemplate(t_canvas *x);
+EXTERN t_canvas *canvas_getcurrent(void);
+EXTERN void canvas_setcurrent(t_canvas *x);
+EXTERN void canvas_unsetcurrent(t_canvas *x);
+EXTERN t_symbol *canvas_realizedollar(t_canvas *x, t_symbol *s);
+EXTERN t_canvas *canvas_getrootfor(t_canvas *x);
+EXTERN void canvas_dirty(t_canvas *x, t_int n);
+EXTERN int canvas_getfont(t_canvas *x);
+typedef int (*t_canvasapply)(t_canvas *x, t_int x1, t_int x2, t_int x3);
+
+EXTERN t_int *canvas_recurapply(t_canvas *x, t_canvasapply *fn,
+ t_int x1, t_int x2, t_int x3);
+
+EXTERN void canvas_resortinlets(t_canvas *x);
+EXTERN void canvas_resortoutlets(t_canvas *x);
+EXTERN void canvas_free(t_canvas *x);
+EXTERN void canvas_updatewindowlist( void);
+EXTERN void canvas_editmode(t_canvas *x, t_floatarg yesplease);
+EXTERN int canvas_isabstraction(t_canvas *x);
+EXTERN int canvas_istable(t_canvas *x);
+EXTERN int canvas_showtext(t_canvas *x);
+EXTERN void canvas_vis(t_canvas *x, t_floatarg f);
+EXTERN t_canvasenvironment *canvas_getenv(t_canvas *x);
+EXTERN void canvas_rename(t_canvas *x, t_symbol *s, t_symbol *dir);
+EXTERN void canvas_loadbang(t_canvas *x);
+EXTERN int canvas_hitbox(t_canvas *x, t_gobj *y, int xpos, int ypos,
+ int *x1p, int *y1p, int *x2p, int *y2p);
+EXTERN int canvas_setdeleting(t_canvas *x, int flag);
+
+typedef void (*t_undofn)(t_canvas *canvas, void *buf,
+ int action); /* a function that does UNDO/REDO */
+#define UNDO_FREE 0 /* free current undo/redo buffer */
+#define UNDO_UNDO 1 /* undo */
+#define UNDO_REDO 2 /* redo */
+EXTERN void canvas_setundo(t_canvas *x, t_undofn undofn, void *buf,
+ const char *name);
+EXTERN void canvas_noundo(t_canvas *x);
+EXTERN int canvas_getindex(t_canvas *x, t_gobj *y);
+
+/* T.Grill - made public for dynamic object creation */
+/* in g_editor.c */
+EXTERN void canvas_connect(t_canvas *x,
+ t_floatarg fwhoout, t_floatarg foutno,t_floatarg fwhoin, t_floatarg finno);
+EXTERN void canvas_disconnect(t_canvas *x,
+ float index1, float outno, float index2, float inno);
+EXTERN int canvas_isconnected (t_canvas *x,
+ t_text *ob1, int n1, t_text *ob2, int n2);
+EXTERN void canvas_selectinrect(t_canvas *x, int lox, int loy, int hix, int hiy);
+
+
+/* ---- functions on canvasses as objects --------------------- */
+
+EXTERN void canvas_fattenforscalars(t_canvas *x,
+ int *x1, int *y1, int *x2, int *y2);
+EXTERN void canvas_visforscalars(t_canvas *x, t_glist *glist, int vis);
+EXTERN int canvas_clicksub(t_canvas *x, int xpix, int ypix, int shift,
+ int alt, int dbl, int doit);
+EXTERN t_glist *canvas_getglistonsuper(void);
+
+EXTERN void linetraverser_start(t_linetraverser *t, t_canvas *x);
+EXTERN t_outconnect *linetraverser_next(t_linetraverser *t);
+EXTERN void linetraverser_skipobject(t_linetraverser *t);
+
+/* --------------------- functions on tscalars --------------------- */
+
+EXTERN void tscalar_getrect(t_tscalar *x, t_glist *owner,
+ int *xp1, int *yp1, int *xp2, int *yp2);
+EXTERN void tscalar_vis(t_tscalar *x, t_glist *owner, int flag);
+EXTERN int tscalar_click(t_tscalar *x, int xpix, int ypix, int shift,
+ int alt, int dbl, int doit);
+
+/* --------- functions on garrays (graphical arrays) -------------------- */
+
+EXTERN t_template *garray_template(t_garray *x);
+
+/* -------------------- arrays --------------------- */
+EXTERN t_garray *graph_array(t_glist *gl, t_symbol *s, t_symbol *tmpl,
+ t_floatarg f, t_floatarg saveit);
+EXTERN t_array *array_new(t_symbol *templatesym, t_gpointer *parent);
+EXTERN void array_resize(t_array *x, t_template *tmpl, int n);
+EXTERN void array_free(t_array *x);
+
+/* --------------------- gpointers and stubs ---------------- */
+EXTERN t_gstub *gstub_new(t_glist *gl, t_array *a);
+EXTERN void gstub_cutoff(t_gstub *gs);
+EXTERN void gpointer_setglist(t_gpointer *gp, t_glist *glist, t_scalar *x);
+
+/* --------------------- scalars ------------------------- */
+EXTERN void word_init(t_word *wp, t_template *tmpl, t_gpointer *gp);
+EXTERN void word_restore(t_word *wp, t_template *tmpl,
+ int argc, t_atom *argv);
+EXTERN t_scalar *scalar_new(t_glist *owner,
+ t_symbol *templatesym);
+EXTERN void scalar_getbasexy(t_scalar *x, float *basex, float *basey);
+
+/* ------helper routines for "garrays" and "plots" -------------- */
+EXTERN int array_doclick(t_array *array, t_glist *glist, t_gobj *gobj,
+ t_symbol *elemtemplatesym,
+ float linewidth, float xloc, float xinc, float yloc,
+ int xpix, int ypix, int shift, int alt, int dbl, int doit);
+
+EXTERN void array_getcoordinate(t_glist *glist,
+ char *elem, int xonset, int yonset, int wonset, int indx,
+ float basex, float basey, float xinc,
+ float *xp, float *yp, float *wp);
+
+EXTERN int array_getfields(t_symbol *elemtemplatesym,
+ t_canvas **elemtemplatecanvasp,
+ t_template **elemtemplatep, int *elemsizep,
+ int *xonsetp, int *yonsetp, int *wonsetp);
+
+/* --------------------- templates ------------------------- */
+EXTERN t_template *template_new(t_symbol *sym, int argc, t_atom *argv);
+EXTERN void template_free(t_template *x);
+EXTERN int template_match(t_template *x1, t_template *x2);
+EXTERN int template_find_field(t_template *x, t_symbol *name, int *p_onset,
+ int *p_type, t_symbol **p_arraytype);
+EXTERN t_float template_getfloat(t_template *x, t_symbol *fieldname, t_word *wp,
+ int loud);
+EXTERN void template_setfloat(t_template *x, t_symbol *fieldname, t_word *wp,
+ t_float f, int loud);
+EXTERN t_symbol *template_getsymbol(t_template *x, t_symbol *fieldname,
+ t_word *wp, int loud);
+EXTERN void template_setsymbol(t_template *x, t_symbol *fieldname,
+ t_word *wp, t_symbol *s, int loud);
+
+EXTERN t_template *gtemplate_get(t_gtemplate *x);
+EXTERN t_template *template_findbyname(t_symbol *s);
+EXTERN t_canvas *template_findcanvas(t_template *tmpl);
+
+EXTERN t_float template_getfloat(t_template *x, t_symbol *fieldname,
+ t_word *wp, int loud);
+EXTERN void template_setfloat(t_template *x, t_symbol *fieldname,
+ t_word *wp, t_float f, int loud);
+EXTERN t_symbol *template_getsymbol(t_template *x, t_symbol *fieldname,
+ t_word *wp, int loud);
+EXTERN void template_setsymbol(t_template *x, t_symbol *fieldname,
+ t_word *wp, t_symbol *s, int loud);
+
+/* ----------------------- guiconnects, g_guiconnect.c --------- */
+EXTERN t_guiconnect *guiconnect_new(t_pd *who, t_symbol *sym);
+EXTERN void guiconnect_notarget(t_guiconnect *x, double timedelay);
+
+/* ------------- IEMGUI routines used in other g_ files ---------------- */
+EXTERN t_symbol *iemgui_raute2dollar(t_symbol *s);
+EXTERN t_symbol *iemgui_dollar2raute(t_symbol *s);
+
+#if defined(_LANGUAGE_C_PLUS_PLUS) || defined(__cplusplus)
+}
+#endif
diff --git a/apps/plugins/pdbox/PDa/extra/gcanvas-help.pd b/apps/plugins/pdbox/PDa/extra/gcanvas-help.pd
new file mode 100644
index 0000000000..e0e3fd6f4d
--- /dev/null
+++ b/apps/plugins/pdbox/PDa/extra/gcanvas-help.pd
@@ -0,0 +1,16 @@
+#N canvas 0 0 240 300 8;
+#X obj 21 61 gcanvas 80 80;
+#X text 14 9 gcanvas .. mouse coordinate enabled canvas;
+#X text 13 22 ==========================================;
+#X floatatom 21 148 5 0 0 0 - - -;
+#X floatatom 94 147 5 0 0 0 - - -;
+#X connect 0 0 3 0;
+#X connect 0 1 4 0;
+#N canvas 0 0 240 300 8;
+#X obj 21 61 gcanvas 80 80;
+#X text 14 9 gcanvas .. mouse coordinate enabled canvas;
+#X text 13 22 ==========================================;
+#X floatatom 21 148 5 0 0 0 - - -;
+#X floatatom 94 147 5 0 0 0 - - -;
+#X connect 0 0 3 0;
+#X connect 0 1 4 0;
diff --git a/apps/plugins/pdbox/PDa/extra/gcanvas.c b/apps/plugins/pdbox/PDa/extra/gcanvas.c
new file mode 100644
index 0000000000..aed5c96cec
--- /dev/null
+++ b/apps/plugins/pdbox/PDa/extra/gcanvas.c
@@ -0,0 +1,758 @@
+/* (C) Guenter Geiger <geiger@xdv.org> */
+
+
+#include "m_pd.h"
+#include "g_canvas.h"
+
+/* ------------------------ gcanvas ----------------------------- */
+
+
+#define BACKGROUNDCOLOR "grey"
+
+#define DEFAULTSIZE 80
+
+static t_class *gcanvas_class;
+
+typedef struct _gcanvas
+{
+ t_object x_obj;
+ t_glist * x_glist;
+ t_outlet* out2;
+ t_outlet* out3;
+ int x_width;
+ int x_height;
+ int x;
+ int y;
+ int x_xgrid;
+ int x_ygrid;
+} t_gcanvas;
+
+
+static void rectangle(void* cv,void* o,char c,int x, int y,int w,int h,char* color) {
+ sys_vgui(".x%x.c create rectangle \
+ %d %d %d %d -tags %x%c -fill %s\n",cv,x,y,x+w,y+h,o,c,color);
+}
+
+static void move_object(void* cv,void* o,char c,int x, int y,int w,int h) {
+ sys_vgui(".x%x.c coords %x%c %d %d %d %d\n",
+ cv,o,c,x,y,x+w,y+h);
+
+}
+
+static void color_object(void* cv,void* o,char c,char* color) {
+ sys_vgui(".x%x.c itemconfigure %x%c -fill %s\n", cv,
+ o, c,color);
+}
+
+static void delete_object(void* cv,void* o,char c) {
+ sys_vgui(".x%x.c delete %x%c\n",
+ cv, o,c);
+}
+
+static void line(void* cv,void* o,char c,int x,int y,int w,int h,char* color) {
+ sys_vgui(".x%x.c create line \
+ %d %d %d %d -tags %x%c -fill %s\n",cv,x,y,x+w,y+h,o,c,color);
+}
+
+
+/* widget helper functions */
+
+void gcanvas_drawme(t_gcanvas *x, t_glist *glist, int firsttime)
+{
+ int i;
+ if (firsttime) {
+ rectangle(glist_getcanvas(glist),x,'a',
+ x->x_obj.te_xpix, x->x_obj.te_ypix,
+ x->x_width, x->x_height,BACKGROUNDCOLOR);
+ for (i=1;i<x->x_xgrid;i++)
+ line(glist_getcanvas(glist),x,'b'+ i,
+ x->x_obj.te_xpix + x->x_width*i/x->x_xgrid,
+ x->x_obj.te_ypix,
+ 0, x->x_height,"red");
+ for (i=1;i<x->x_ygrid;i++)
+ line(glist_getcanvas(glist),x,'B'+ i,
+ x->x_obj.te_xpix,
+ x->x_obj.te_ypix + x->x_height*i/x->x_ygrid,
+ x->x_width, 0,"blue");
+ }
+ else {
+ move_object(
+ glist_getcanvas(glist),x,'a',
+ x->x_obj.te_xpix, x->x_obj.te_ypix,
+ x->x_width, x->x_height);
+ for (i=1;i<x->x_xgrid;i++)
+ move_object(glist_getcanvas(glist),x,'b'+ i,
+ x->x_obj.te_xpix + x->x_width*i/x->x_xgrid,
+ x->x_obj.te_ypix,
+ 0, x->x_height);
+ for (i=1;i<x->x_ygrid;i++)
+ move_object(glist_getcanvas(glist),x,'B'+ i,
+ x->x_obj.te_xpix,
+ x->x_obj.te_ypix + x->x_height*i/x->x_ygrid,
+ x->x_width, 0);
+ }
+
+ {
+ /* outlets */
+ int n = 3;
+ int nplus, i;
+ nplus = (n == 1 ? 1 : n-1);
+ for (i = 0; i < n; i++)
+ {
+ int onset = x->x_obj.te_xpix + (x->x_width - IOWIDTH) * i / nplus;
+ if (firsttime)
+ sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xo%d\n",
+ glist_getcanvas(glist),
+ onset, x->x_obj.te_ypix + x->x_height - 1,
+ onset + IOWIDTH, x->x_obj.te_ypix + x->x_height,
+ x, i);
+ else
+ sys_vgui(".x%x.c coords %xo%d %d %d %d %d\n",
+ glist_getcanvas(glist), x, i,
+ onset, x->x_obj.te_ypix + x->x_height - 1,
+ onset + IOWIDTH, x->x_obj.te_ypix + x->x_height);
+ }
+ /* inlets */
+ n = 0;
+ nplus = (n == 1 ? 1 : n-1);
+ for (i = 0; i < n; i++)
+ {
+ int onset = x->x_obj.te_xpix + (x->x_width - IOWIDTH) * i / nplus;
+ if (firsttime)
+ sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xi%d\n",
+ glist_getcanvas(glist),
+ onset, x->x_obj.te_ypix,
+ onset + IOWIDTH, x->x_obj.te_ypix + 1,
+ x, i);
+ else
+ sys_vgui(".x%x.c coords %xi%d %d %d %d %d\n",
+ glist_getcanvas(glist), x, i,
+ onset, x->x_obj.te_ypix,
+ onset + IOWIDTH, x->x_obj.te_ypix + 1);
+
+ }
+ }
+
+}
+
+
+
+
+void gcanvas_erase(t_gcanvas* x,t_glist* glist)
+{
+ int n,i;
+ delete_object(glist_getcanvas(glist),x,'a');
+ for (i=1;i<x->x_xgrid;i++)
+ delete_object(glist_getcanvas(glist),x,'b'+ i);
+ for (i=1;i<x->x_ygrid;i++)
+ delete_object(glist_getcanvas(glist),x,'B'+ i);
+
+ n = 2;
+ while (n--) {
+ sys_vgui(".x%x.c delete %xo%d\n",glist_getcanvas(glist),x,n);
+ }
+}
+
+
+
+/* ------------------------ gcanvas widgetbehaviour----------------------------- */
+
+
+static void gcanvas_getrect(t_gobj *z, t_glist *owner,
+ int *xp1, int *yp1, int *xp2, int *yp2)
+{
+ int width, height;
+ t_gcanvas* s = (t_gcanvas*)z;
+
+
+ width = s->x_width;
+ height = s->x_height;
+ *xp1 = s->x_obj.te_xpix;
+ *yp1 = s->x_obj.te_ypix;
+ *xp2 = s->x_obj.te_xpix + width;
+ *yp2 = s->x_obj.te_ypix + height;
+}
+
+static void gcanvas_displace(t_gobj *z, t_glist *glist,
+ int dx, int dy)
+{
+ t_gcanvas *x = (t_gcanvas *)z;
+ x->x_obj.te_xpix += dx;
+ x->x_obj.te_ypix += dy;
+ gcanvas_drawme(x, glist, 0);
+ canvas_fixlinesfor(glist_getcanvas(glist),(t_text*) x);
+}
+
+static void gcanvas_select(t_gobj *z, t_glist *glist, int state)
+{
+ t_gcanvas *x = (t_gcanvas *)z;
+ color_object(glist,x,'a',state ? "blue" : BACKGROUNDCOLOR);
+}
+
+
+static void gcanvas_activate(t_gobj *z, t_glist *glist, int state)
+{
+/* t_text *x = (t_text *)z;
+ t_rtext *y = glist_findrtext(glist, x);
+ if (z->g_pd != gatom_class) rtext_activate(y, state);*/
+}
+
+static void gcanvas_delete(t_gobj *z, t_glist *glist)
+{
+ t_text *x = (t_text *)z;
+ canvas_deletelinesfor(glist_getcanvas(glist), x);
+}
+
+
+static void gcanvas_vis(t_gobj *z, t_glist *glist, int vis)
+{
+ t_gcanvas* s = (t_gcanvas*)z;
+ if (vis)
+ gcanvas_drawme(s, glist, 1);
+ else
+ gcanvas_erase(s,glist);
+}
+
+/* can we use the normal text save function ?? */
+
+static void gcanvas_save(t_gobj *z, t_binbuf *b)
+{
+ t_gcanvas *x = (t_gcanvas *)z;
+ binbuf_addv(b, "ssiisiiii", gensym("#X"),gensym("obj"),
+ (t_int)x->x_obj.te_xpix, (t_int)x->x_obj.te_ypix,
+ gensym("gcanvas"),x->x_width,x->x_height,
+ x->x_xgrid,
+ x->x_ygrid);
+ binbuf_addv(b, ";");
+}
+
+
+t_widgetbehavior gcanvas_widgetbehavior;
+
+static void gcanvas_motion(t_gcanvas *x, t_floatarg dx, t_floatarg dy)
+{
+ x->x += dx;
+ x->y += dy;
+ outlet_float(x->out2,x->y);
+ outlet_float(x->x_obj.ob_outlet,x->x);
+}
+
+void gcanvas_key(t_gcanvas *x, t_floatarg f)
+{
+ post("key");
+}
+
+
+static void gcanvas_click(t_gcanvas *x,
+ t_floatarg xpos, t_floatarg ypos, t_floatarg shift, t_floatarg ctrl,
+ t_floatarg doit,int up)
+{
+ glist_grab(x->x_glist, &x->x_obj.te_g, (t_glistmotionfn) gcanvas_motion,
+ (t_glistkeyfn) NULL, xpos, ypos);
+
+ x->x = xpos - x->x_obj.te_xpix;
+ x->y = ypos - x->x_obj.te_ypix;
+ outlet_float(x->out2,x->y);
+ outlet_float(x->x_obj.ob_outlet,x->x);
+ outlet_float(x->out3,0);
+}
+
+static int gcanvas_newclick(t_gobj *z, struct _glist *glist,
+ int xpix, int ypix, int shift, int alt, int dbl, int doit)
+{
+ if (doit)
+ gcanvas_click((t_gcanvas *)z, (t_floatarg)xpix, (t_floatarg)ypix,
+ (t_floatarg)shift, 0, (t_floatarg)alt,dbl);
+
+ if (dbl) outlet_float(((t_gcanvas*)z)->out3,1);
+ return (1);
+}
+
+void gcanvas_size(t_gcanvas* x,t_floatarg w,t_floatarg h) {
+ x->x_width = w;
+ x->x_height = h;
+ gcanvas_drawme(x, x->x_glist, 0);
+}
+
+static void gcanvas_setwidget(void)
+{
+ gcanvas_widgetbehavior.w_getrectfn = gcanvas_getrect;
+ gcanvas_widgetbehavior.w_displacefn = gcanvas_displace;
+ gcanvas_widgetbehavior.w_selectfn = gcanvas_select;
+ gcanvas_widgetbehavior.w_activatefn = gcanvas_activate;
+ gcanvas_widgetbehavior.w_deletefn = gcanvas_delete;
+ gcanvas_widgetbehavior.w_visfn = gcanvas_vis;
+ gcanvas_widgetbehavior.w_clickfn = gcanvas_newclick;
+ class_setsavefn(gcanvas_class,gcanvas_save);
+}
+
+
+static void *gcanvas_new(t_symbol* s,t_int ac,t_atom* at)
+{
+ t_gcanvas *x = (t_gcanvas *)pd_new(gcanvas_class);
+
+ x->x_glist = (t_glist*) canvas_getcurrent();
+
+
+ /* Fetch the width */
+
+ x->x_width = DEFAULTSIZE;
+ if (ac-- > 0) {
+ if (at->a_type != A_FLOAT)
+ error("gcanvas: wrong argument type");
+ else
+ x->x_width = atom_getfloat(at++);
+
+ if (x->x_width < 0 || x->x_width > 2000) {
+ error("gcanvas: unallowed width %f",x->x_width);
+ x->x_width = DEFAULTSIZE;
+ }
+ }
+
+ /* Fetch the height */
+
+ x->x_height = DEFAULTSIZE;
+ if (ac-- > 0) {
+ if (at->a_type != A_FLOAT)
+ error("gcanvas: wrong argument type");
+ else
+ x->x_height = atom_getfloat(at++);
+
+ if (x->x_height < 0 || x->x_height > 2000) {
+ error("gcanvas: unallowed height %f",x->x_height);
+ x->x_width = DEFAULTSIZE;
+ }
+ }
+
+ /* Fetch the xgrid */
+
+ x->x_xgrid = 0;
+ if (ac-- > 0) {
+ if (at->a_type != A_FLOAT)
+ error("gcanvas: wrong argument type");
+ else
+ x->x_xgrid = atom_getfloat(at++);
+
+ if (x->x_xgrid < 0 || x->x_xgrid > x->x_width/2) {
+ error("gcanvas: unallowed xgrid %f",x->x_xgrid);
+ x->x_xgrid = 0;
+ }
+ }
+
+ /* Fetch the ygrid */
+
+ x->x_ygrid = 0;
+ if (ac-- > 0) {
+ if (at->a_type != A_FLOAT)
+ error("gcanvas: wrong argument type");
+ else
+ x->x_ygrid = atom_getfloat(at++);
+
+ if (x->x_ygrid < 0 || x->x_ygrid > x->x_height/2) {
+ error("gcanvas: unallowed xgrid %f",x->x_ygrid);
+ x->x_ygrid = 0;
+ }
+ }
+
+ outlet_new(&x->x_obj, &s_float);
+ x->out2 = outlet_new(&x->x_obj, &s_float);
+ x->out3 = outlet_new(&x->x_obj, &s_float);
+ return (x);
+}
+
+
+
+void gcanvas_setup(void)
+{
+ gcanvas_class = class_new(gensym("gcanvas"), (t_newmethod)gcanvas_new, 0,
+ sizeof(t_gcanvas),0, A_GIMME,0);
+
+ class_addmethod(gcanvas_class, (t_method)gcanvas_click, gensym("click"),
+ A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, 0);
+ class_addmethod(gcanvas_class, (t_method)gcanvas_size, gensym("size"),
+ A_FLOAT, A_FLOAT, 0);
+
+ gcanvas_setwidget();
+ class_setwidget(gcanvas_class,&gcanvas_widgetbehavior);
+}
+
+
+/* (C) Guenter Geiger <geiger@xdv.org> */
+
+
+#include "m_pd.h"
+#include "g_canvas.h"
+
+/* ------------------------ gcanvas ----------------------------- */
+
+
+#define BACKGROUNDCOLOR "grey"
+
+#define DEFAULTSIZE 80
+
+static t_class *gcanvas_class;
+
+typedef struct _gcanvas
+{
+ t_object x_obj;
+ t_glist * x_glist;
+ t_outlet* out2;
+ t_outlet* out3;
+ int x_width;
+ int x_height;
+ int x;
+ int y;
+ int x_xgrid;
+ int x_ygrid;
+} t_gcanvas;
+
+
+static void rectangle(void* cv,void* o,char c,int x, int y,int w,int h,char* color) {
+ sys_vgui(".x%x.c create rectangle \
+ %d %d %d %d -tags %x%c -fill %s\n",cv,x,y,x+w,y+h,o,c,color);
+}
+
+static void move_object(void* cv,void* o,char c,int x, int y,int w,int h) {
+ sys_vgui(".x%x.c coords %x%c %d %d %d %d\n",
+ cv,o,c,x,y,x+w,y+h);
+
+}
+
+static void color_object(void* cv,void* o,char c,char* color) {
+ sys_vgui(".x%x.c itemconfigure %x%c -fill %s\n", cv,
+ o, c,color);
+}
+
+static void delete_object(void* cv,void* o,char c) {
+ sys_vgui(".x%x.c delete %x%c\n",
+ cv, o,c);
+}
+
+static void line(void* cv,void* o,char c,int x,int y,int w,int h,char* color) {
+ sys_vgui(".x%x.c create line \
+ %d %d %d %d -tags %x%c -fill %s\n",cv,x,y,x+w,y+h,o,c,color);
+}
+
+
+/* widget helper functions */
+
+void gcanvas_drawme(t_gcanvas *x, t_glist *glist, int firsttime)
+{
+ int i;
+ if (firsttime) {
+ rectangle(glist_getcanvas(glist),x,'a',
+ x->x_obj.te_xpix, x->x_obj.te_ypix,
+ x->x_width, x->x_height,BACKGROUNDCOLOR);
+ for (i=1;i<x->x_xgrid;i++)
+ line(glist_getcanvas(glist),x,'b'+ i,
+ x->x_obj.te_xpix + x->x_width*i/x->x_xgrid,
+ x->x_obj.te_ypix,
+ 0, x->x_height,"red");
+ for (i=1;i<x->x_ygrid;i++)
+ line(glist_getcanvas(glist),x,'B'+ i,
+ x->x_obj.te_xpix,
+ x->x_obj.te_ypix + x->x_height*i/x->x_ygrid,
+ x->x_width, 0,"blue");
+ }
+ else {
+ move_object(
+ glist_getcanvas(glist),x,'a',
+ x->x_obj.te_xpix, x->x_obj.te_ypix,
+ x->x_width, x->x_height);
+ for (i=1;i<x->x_xgrid;i++)
+ move_object(glist_getcanvas(glist),x,'b'+ i,
+ x->x_obj.te_xpix + x->x_width*i/x->x_xgrid,
+ x->x_obj.te_ypix,
+ 0, x->x_height);
+ for (i=1;i<x->x_ygrid;i++)
+ move_object(glist_getcanvas(glist),x,'B'+ i,
+ x->x_obj.te_xpix,
+ x->x_obj.te_ypix + x->x_height*i/x->x_ygrid,
+ x->x_width, 0);
+ }
+
+ {
+ /* outlets */
+ int n = 3;
+ int nplus, i;
+ nplus = (n == 1 ? 1 : n-1);
+ for (i = 0; i < n; i++)
+ {
+ int onset = x->x_obj.te_xpix + (x->x_width - IOWIDTH) * i / nplus;
+ if (firsttime)
+ sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xo%d\n",
+ glist_getcanvas(glist),
+ onset, x->x_obj.te_ypix + x->x_height - 1,
+ onset + IOWIDTH, x->x_obj.te_ypix + x->x_height,
+ x, i);
+ else
+ sys_vgui(".x%x.c coords %xo%d %d %d %d %d\n",
+ glist_getcanvas(glist), x, i,
+ onset, x->x_obj.te_ypix + x->x_height - 1,
+ onset + IOWIDTH, x->x_obj.te_ypix + x->x_height);
+ }
+ /* inlets */
+ n = 0;
+ nplus = (n == 1 ? 1 : n-1);
+ for (i = 0; i < n; i++)
+ {
+ int onset = x->x_obj.te_xpix + (x->x_width - IOWIDTH) * i / nplus;
+ if (firsttime)
+ sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xi%d\n",
+ glist_getcanvas(glist),
+ onset, x->x_obj.te_ypix,
+ onset + IOWIDTH, x->x_obj.te_ypix + 1,
+ x, i);
+ else
+ sys_vgui(".x%x.c coords %xi%d %d %d %d %d\n",
+ glist_getcanvas(glist), x, i,
+ onset, x->x_obj.te_ypix,
+ onset + IOWIDTH, x->x_obj.te_ypix + 1);
+
+ }
+ }
+
+}
+
+
+
+
+void gcanvas_erase(t_gcanvas* x,t_glist* glist)
+{
+ int n,i;
+ delete_object(glist_getcanvas(glist),x,'a');
+ for (i=1;i<x->x_xgrid;i++)
+ delete_object(glist_getcanvas(glist),x,'b'+ i);
+ for (i=1;i<x->x_ygrid;i++)
+ delete_object(glist_getcanvas(glist),x,'B'+ i);
+
+ n = 2;
+ while (n--) {
+ sys_vgui(".x%x.c delete %xo%d\n",glist_getcanvas(glist),x,n);
+ }
+}
+
+
+
+/* ------------------------ gcanvas widgetbehaviour----------------------------- */
+
+
+static void gcanvas_getrect(t_gobj *z, t_glist *owner,
+ int *xp1, int *yp1, int *xp2, int *yp2)
+{
+ int width, height;
+ t_gcanvas* s = (t_gcanvas*)z;
+
+
+ width = s->x_width;
+ height = s->x_height;
+ *xp1 = s->x_obj.te_xpix;
+ *yp1 = s->x_obj.te_ypix;
+ *xp2 = s->x_obj.te_xpix + width;
+ *yp2 = s->x_obj.te_ypix + height;
+}
+
+static void gcanvas_displace(t_gobj *z, t_glist *glist,
+ int dx, int dy)
+{
+ t_gcanvas *x = (t_gcanvas *)z;
+ x->x_obj.te_xpix += dx;
+ x->x_obj.te_ypix += dy;
+ gcanvas_drawme(x, glist, 0);
+ canvas_fixlinesfor(glist_getcanvas(glist),(t_text*) x);
+}
+
+static void gcanvas_select(t_gobj *z, t_glist *glist, int state)
+{
+ t_gcanvas *x = (t_gcanvas *)z;
+ color_object(glist,x,'a',state ? "blue" : BACKGROUNDCOLOR);
+}
+
+
+static void gcanvas_activate(t_gobj *z, t_glist *glist, int state)
+{
+/* t_text *x = (t_text *)z;
+ t_rtext *y = glist_findrtext(glist, x);
+ if (z->g_pd != gatom_class) rtext_activate(y, state);*/
+}
+
+static void gcanvas_delete(t_gobj *z, t_glist *glist)
+{
+ t_text *x = (t_text *)z;
+ canvas_deletelinesfor(glist_getcanvas(glist), x);
+}
+
+
+static void gcanvas_vis(t_gobj *z, t_glist *glist, int vis)
+{
+ t_gcanvas* s = (t_gcanvas*)z;
+ if (vis)
+ gcanvas_drawme(s, glist, 1);
+ else
+ gcanvas_erase(s,glist);
+}
+
+/* can we use the normal text save function ?? */
+
+static void gcanvas_save(t_gobj *z, t_binbuf *b)
+{
+ t_gcanvas *x = (t_gcanvas *)z;
+ binbuf_addv(b, "ssiisiiii", gensym("#X"),gensym("obj"),
+ (t_int)x->x_obj.te_xpix, (t_int)x->x_obj.te_ypix,
+ gensym("gcanvas"),x->x_width,x->x_height,
+ x->x_xgrid,
+ x->x_ygrid);
+ binbuf_addv(b, ";");
+}
+
+
+t_widgetbehavior gcanvas_widgetbehavior;
+
+static void gcanvas_motion(t_gcanvas *x, t_floatarg dx, t_floatarg dy)
+{
+ x->x += dx;
+ x->y += dy;
+ outlet_float(x->out2,x->y);
+ outlet_float(x->x_obj.ob_outlet,x->x);
+}
+
+void gcanvas_key(t_gcanvas *x, t_floatarg f)
+{
+ post("key");
+}
+
+
+static void gcanvas_click(t_gcanvas *x,
+ t_floatarg xpos, t_floatarg ypos, t_floatarg shift, t_floatarg ctrl,
+ t_floatarg doit,int up)
+{
+ glist_grab(x->x_glist, &x->x_obj.te_g, (t_glistmotionfn) gcanvas_motion,
+ (t_glistkeyfn) NULL, xpos, ypos);
+
+ x->x = xpos - x->x_obj.te_xpix;
+ x->y = ypos - x->x_obj.te_ypix;
+ outlet_float(x->out2,x->y);
+ outlet_float(x->x_obj.ob_outlet,x->x);
+ outlet_float(x->out3,0);
+}
+
+static int gcanvas_newclick(t_gobj *z, struct _glist *glist,
+ int xpix, int ypix, int shift, int alt, int dbl, int doit)
+{
+ if (doit)
+ gcanvas_click((t_gcanvas *)z, (t_floatarg)xpix, (t_floatarg)ypix,
+ (t_floatarg)shift, 0, (t_floatarg)alt,dbl);
+
+ if (dbl) outlet_float(((t_gcanvas*)z)->out3,1);
+ return (1);
+}
+
+void gcanvas_size(t_gcanvas* x,t_floatarg w,t_floatarg h) {
+ x->x_width = w;
+ x->x_height = h;
+ gcanvas_drawme(x, x->x_glist, 0);
+}
+
+static void gcanvas_setwidget(void)
+{
+ gcanvas_widgetbehavior.w_getrectfn = gcanvas_getrect;
+ gcanvas_widgetbehavior.w_displacefn = gcanvas_displace;
+ gcanvas_widgetbehavior.w_selectfn = gcanvas_select;
+ gcanvas_widgetbehavior.w_activatefn = gcanvas_activate;
+ gcanvas_widgetbehavior.w_deletefn = gcanvas_delete;
+ gcanvas_widgetbehavior.w_visfn = gcanvas_vis;
+ gcanvas_widgetbehavior.w_clickfn = gcanvas_newclick;
+ class_setsavefn(gcanvas_class,gcanvas_save);
+}
+
+
+static void *gcanvas_new(t_symbol* s,t_int ac,t_atom* at)
+{
+ t_gcanvas *x = (t_gcanvas *)pd_new(gcanvas_class);
+
+ x->x_glist = (t_glist*) canvas_getcurrent();
+
+
+ /* Fetch the width */
+
+ x->x_width = DEFAULTSIZE;
+ if (ac-- > 0) {
+ if (at->a_type != A_FLOAT)
+ error("gcanvas: wrong argument type");
+ else
+ x->x_width = atom_getfloat(at++);
+
+ if (x->x_width < 0 || x->x_width > 2000) {
+ error("gcanvas: unallowed width %f",x->x_width);
+ x->x_width = DEFAULTSIZE;
+ }
+ }
+
+ /* Fetch the height */
+
+ x->x_height = DEFAULTSIZE;
+ if (ac-- > 0) {
+ if (at->a_type != A_FLOAT)
+ error("gcanvas: wrong argument type");
+ else
+ x->x_height = atom_getfloat(at++);
+
+ if (x->x_height < 0 || x->x_height > 2000) {
+ error("gcanvas: unallowed height %f",x->x_height);
+ x->x_width = DEFAULTSIZE;
+ }
+ }
+
+ /* Fetch the xgrid */
+
+ x->x_xgrid = 0;
+ if (ac-- > 0) {
+ if (at->a_type != A_FLOAT)
+ error("gcanvas: wrong argument type");
+ else
+ x->x_xgrid = atom_getfloat(at++);
+
+ if (x->x_xgrid < 0 || x->x_xgrid > x->x_width/2) {
+ error("gcanvas: unallowed xgrid %f",x->x_xgrid);
+ x->x_xgrid = 0;
+ }
+ }
+
+ /* Fetch the ygrid */
+
+ x->x_ygrid = 0;
+ if (ac-- > 0) {
+ if (at->a_type != A_FLOAT)
+ error("gcanvas: wrong argument type");
+ else
+ x->x_ygrid = atom_getfloat(at++);
+
+ if (x->x_ygrid < 0 || x->x_ygrid > x->x_height/2) {
+ error("gcanvas: unallowed xgrid %f",x->x_ygrid);
+ x->x_ygrid = 0;
+ }
+ }
+
+ outlet_new(&x->x_obj, &s_float);
+ x->out2 = outlet_new(&x->x_obj, &s_float);
+ x->out3 = outlet_new(&x->x_obj, &s_float);
+ return (x);
+}
+
+
+
+void gcanvas_setup(void)
+{
+ gcanvas_class = class_new(gensym("gcanvas"), (t_newmethod)gcanvas_new, 0,
+ sizeof(t_gcanvas),0, A_GIMME,0);
+
+ class_addmethod(gcanvas_class, (t_method)gcanvas_click, gensym("click"),
+ A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, 0);
+ class_addmethod(gcanvas_class, (t_method)gcanvas_size, gensym("size"),
+ A_FLOAT, A_FLOAT, 0);
+
+ gcanvas_setwidget();
+ class_setwidget(gcanvas_class,&gcanvas_widgetbehavior);
+}
+
+
diff --git a/apps/plugins/pdbox/PDa/extra/highpass.c b/apps/plugins/pdbox/PDa/extra/highpass.c
new file mode 100644
index 0000000000..88ba4564e6
--- /dev/null
+++ b/apps/plugins/pdbox/PDa/extra/highpass.c
@@ -0,0 +1,174 @@
+/* (C) Guenter Geiger <geiger@epy.co.at> */
+
+
+/*
+
+ These filter coefficients computations are taken from
+ http://www.harmony-central.com/Computer/Programming/Audio-EQ-Cookbook.txt
+
+ written by Robert Bristow-Johnson
+
+*/
+
+#include "m_pd.h"
+#ifdef NT
+#pragma warning( disable : 4244 )
+#pragma warning( disable : 4305 )
+#endif
+#include <math.h>
+#include "filters.h"
+
+
+/* ------------------- highpass ----------------------------*/
+
+static t_class *highpass_class;
+
+void highpass_bang(t_rbjfilter *x)
+{
+ t_atom at[5];
+ t_float omega = e_omega(x->x_freq,x->x_rate);
+ t_float alpha = e_alpha(x->x_bw* 0.01,omega);
+ t_float b1 = -(1 + cos(omega));
+ t_float b0 = -b1/2.;
+ t_float b2 = b0;
+ t_float a0 = 1 + alpha;
+ t_float a1 = -2.*cos(omega);
+ t_float a2 = 1 - alpha;
+
+/* post("bang %f %f %f",x->x_freq, x->x_gain, x->x_bw); */
+
+ if (!check_stability(-a1/a0,-a2/a0,b0/a0,b1/a0,b2/a0)) {
+ post("highpass: filter unstable -> resetting");
+ a0=1.;a1=0.;a2=0.;
+ b0=1.;b1=0.;b2=0.;
+ }
+
+ SETFLOAT(at,-a1/a0);
+ SETFLOAT(at+1,-a2/a0);
+ SETFLOAT(at+2,b0/a0);
+ SETFLOAT(at+3,b1/a0);
+ SETFLOAT(at+4,b2/a0);
+
+ outlet_list(x->x_obj.ob_outlet,&s_list,5,at);
+}
+
+
+void highpass_float(t_rbjfilter *x,t_floatarg f)
+{
+ x->x_freq = f;
+ highpass_bang(x);
+}
+
+
+static void *highpass_new(t_floatarg f,t_floatarg bw)
+{
+ t_rbjfilter *x = (t_rbjfilter *)pd_new(highpass_class);
+
+ x->x_rate = 44100.0;
+ outlet_new(&x->x_obj,&s_float);
+/* floatinlet_new(&x->x_obj, &x->x_gain); */
+ floatinlet_new(&x->x_obj, &x->x_bw);
+ if (f > 0.) x->x_freq = f;
+ if (bw > 0.) x->x_bw = bw;
+ return (x);
+}
+
+
+void highpass_setup(void)
+{
+ highpass_class = class_new(gensym("highpass"), (t_newmethod)highpass_new, 0,
+ sizeof(t_rbjfilter), 0,A_DEFFLOAT,A_DEFFLOAT,0);
+ class_addbang(highpass_class,highpass_bang);
+ class_addfloat(highpass_class,highpass_float);
+}
+
+
+
+
+/* (C) Guenter Geiger <geiger@epy.co.at> */
+
+
+/*
+
+ These filter coefficients computations are taken from
+ http://www.harmony-central.com/Computer/Programming/Audio-EQ-Cookbook.txt
+
+ written by Robert Bristow-Johnson
+
+*/
+
+#include "m_pd.h"
+#ifdef NT
+#pragma warning( disable : 4244 )
+#pragma warning( disable : 4305 )
+#endif
+#include <math.h>
+#include "filters.h"
+
+
+/* ------------------- highpass ----------------------------*/
+
+static t_class *highpass_class;
+
+void highpass_bang(t_rbjfilter *x)
+{
+ t_atom at[5];
+ t_float omega = e_omega(x->x_freq,x->x_rate);
+ t_float alpha = e_alpha(x->x_bw* 0.01,omega);
+ t_float b1 = -(1 + cos(omega));
+ t_float b0 = -b1/2.;
+ t_float b2 = b0;
+ t_float a0 = 1 + alpha;
+ t_float a1 = -2.*cos(omega);
+ t_float a2 = 1 - alpha;
+
+/* post("bang %f %f %f",x->x_freq, x->x_gain, x->x_bw); */
+
+ if (!check_stability(-a1/a0,-a2/a0,b0/a0,b1/a0,b2/a0)) {
+ post("highpass: filter unstable -> resetting");
+ a0=1.;a1=0.;a2=0.;
+ b0=1.;b1=0.;b2=0.;
+ }
+
+ SETFLOAT(at,-a1/a0);
+ SETFLOAT(at+1,-a2/a0);
+ SETFLOAT(at+2,b0/a0);
+ SETFLOAT(at+3,b1/a0);
+ SETFLOAT(at+4,b2/a0);
+
+ outlet_list(x->x_obj.ob_outlet,&s_list,5,at);
+}
+
+
+void highpass_float(t_rbjfilter *x,t_floatarg f)
+{
+ x->x_freq = f;
+ highpass_bang(x);
+}
+
+
+static void *highpass_new(t_floatarg f,t_floatarg bw)
+{
+ t_rbjfilter *x = (t_rbjfilter *)pd_new(highpass_class);
+
+ x->x_rate = 44100.0;
+ outlet_new(&x->x_obj,&s_float);
+/* floatinlet_new(&x->x_obj, &x->x_gain); */
+ floatinlet_new(&x->x_obj, &x->x_bw);
+ if (f > 0.) x->x_freq = f;
+ if (bw > 0.) x->x_bw = bw;
+ return (x);
+}
+
+
+void highpass_setup(void)
+{
+ highpass_class = class_new(gensym("highpass"), (t_newmethod)highpass_new, 0,
+ sizeof(t_rbjfilter), 0,A_DEFFLOAT,A_DEFFLOAT,0);
+ class_addbang(highpass_class,highpass_bang);
+ class_addfloat(highpass_class,highpass_float);
+}
+
+
+
+
diff --git a/apps/plugins/pdbox/PDa/extra/highshelf.c b/apps/plugins/pdbox/PDa/extra/highshelf.c
new file mode 100644
index 0000000000..0060d896c2
--- /dev/null
+++ b/apps/plugins/pdbox/PDa/extra/highshelf.c
@@ -0,0 +1,180 @@
+/* (C) Guenter Geiger <geiger@epy.co.at> */
+
+
+/*
+
+ These filter coefficients computations are taken from
+ http://www.harmony-central.com/Computer/Programming/Audio-EQ-Cookbook.txt
+
+ written by Robert Bristow-Johnson
+
+*/
+
+#include "m_pd.h"
+#ifdef NT
+#pragma warning( disable : 4244 )
+#pragma warning( disable : 4305 )
+#endif
+#include <math.h>
+#include "filters.h"
+
+
+/* ------------------- highshelf ----------------------------*/
+
+static t_class *highshelf_class;
+
+void highshelf_bang(t_rbjfilter *x)
+{
+ t_atom at[5];
+ t_float omega = e_omega(x->x_freq,x->x_rate);
+ t_float A = e_A(x->x_gain);
+ t_float cs = cos(omega);
+ t_float sn = sin(omega);
+ t_float beta = e_beta(A,x->x_bw* 0.01);
+
+ t_float b0 = A*((A+1) + (A-1)*cs + beta*sn);
+ t_float b1 =-2.*A*((A-1) + (A+1)*cs);
+ t_float b2 = A*((A+1) + (A-1)*cs - beta*sn);
+ t_float a0 = ((A+1) - (A-1)*cs + beta*sn);
+ t_float a1 = 2.*((A-1) - (A+1)*cs);
+ t_float a2 = ((A+1) - (A-1)*cs - beta*sn);
+
+/* post("bang %f %f %f",x->x_freq, x->x_gain, x->x_bw);*/
+
+ if (!check_stability(-a1/a0,-a2/a0,b0/a0,b1/a0,b2/a0)) {
+ post("highshelf: filter unstable -> resetting");
+ a0=1.;a1=0.;a2=0.;
+ b0=1.;b1=0.;b2=0.;
+ }
+
+ SETFLOAT(at,-a1/a0);
+ SETFLOAT(at+1,-a2/a0);
+ SETFLOAT(at+2,b0/a0);
+ SETFLOAT(at+3,b1/a0);
+ SETFLOAT(at+4,b2/a0);
+
+ outlet_list(x->x_obj.ob_outlet,&s_list,5,at);
+}
+
+
+void highshelf_float(t_rbjfilter *x,t_floatarg f)
+{
+ x->x_freq = f;
+ highshelf_bang(x);
+}
+
+
+static void *highshelf_new(t_floatarg f,t_floatarg g,t_floatarg bw)
+{
+ t_rbjfilter *x = (t_rbjfilter *)pd_new(highshelf_class);
+
+ x->x_rate = 44100.0;
+ outlet_new(&x->x_obj,&s_float);
+ floatinlet_new(&x->x_obj, &x->x_gain);
+ floatinlet_new(&x->x_obj, &x->x_bw);
+ if (f > 0.) x->x_freq = f;
+ if (bw > 0.) x->x_bw = bw;
+ if (g != 0.) x->x_gain = g;
+ return (x);
+}
+
+
+void highshelf_setup(void)
+{
+ highshelf_class = class_new(gensym("highshelf"), (t_newmethod)highshelf_new, 0,
+ sizeof(t_rbjfilter), 0,A_DEFFLOAT,A_DEFFLOAT,A_DEFFLOAT,0);
+ class_addbang(highshelf_class,highshelf_bang);
+ class_addfloat(highshelf_class,highshelf_float);
+}
+
+
+/* (C) Guenter Geiger <geiger@epy.co.at> */
+
+
+/*
+
+ These filter coefficients computations are taken from
+ http://www.harmony-central.com/Computer/Programming/Audio-EQ-Cookbook.txt
+
+ written by Robert Bristow-Johnson
+
+*/
+
+#include "m_pd.h"
+#ifdef NT
+#pragma warning( disable : 4244 )
+#pragma warning( disable : 4305 )
+#endif
+#include <math.h>
+#include "filters.h"
+
+
+/* ------------------- highshelf ----------------------------*/
+
+static t_class *highshelf_class;
+
+void highshelf_bang(t_rbjfilter *x)
+{
+ t_atom at[5];
+ t_float omega = e_omega(x->x_freq,x->x_rate);
+ t_float A = e_A(x->x_gain);
+ t_float cs = cos(omega);
+ t_float sn = sin(omega);
+ t_float beta = e_beta(A,x->x_bw* 0.01);
+
+ t_float b0 = A*((A+1) + (A-1)*cs + beta*sn);
+ t_float b1 =-2.*A*((A-1) + (A+1)*cs);
+ t_float b2 = A*((A+1) + (A-1)*cs - beta*sn);
+ t_float a0 = ((A+1) - (A-1)*cs + beta*sn);
+ t_float a1 = 2.*((A-1) - (A+1)*cs);
+ t_float a2 = ((A+1) - (A-1)*cs - beta*sn);
+
+/* post("bang %f %f %f",x->x_freq, x->x_gain, x->x_bw);*/
+
+ if (!check_stability(-a1/a0,-a2/a0,b0/a0,b1/a0,b2/a0)) {
+ post("highshelf: filter unstable -> resetting");
+ a0=1.;a1=0.;a2=0.;
+ b0=1.;b1=0.;b2=0.;
+ }
+
+ SETFLOAT(at,-a1/a0);
+ SETFLOAT(at+1,-a2/a0);
+ SETFLOAT(at+2,b0/a0);
+ SETFLOAT(at+3,b1/a0);
+ SETFLOAT(at+4,b2/a0);
+
+ outlet_list(x->x_obj.ob_outlet,&s_list,5,at);
+}
+
+
+void highshelf_float(t_rbjfilter *x,t_floatarg f)
+{
+ x->x_freq = f;
+ highshelf_bang(x);
+}
+
+
+static void *highshelf_new(t_floatarg f,t_floatarg g,t_floatarg bw)
+{
+ t_rbjfilter *x = (t_rbjfilter *)pd_new(highshelf_class);
+
+ x->x_rate = 44100.0;
+ outlet_new(&x->x_obj,&s_float);
+ floatinlet_new(&x->x_obj, &x->x_gain);
+ floatinlet_new(&x->x_obj, &x->x_bw);
+ if (f > 0.) x->x_freq = f;
+ if (bw > 0.) x->x_bw = bw;
+ if (g != 0.) x->x_gain = g;
+ return (x);
+}
+
+
+void highshelf_setup(void)
+{
+ highshelf_class = class_new(gensym("highshelf"), (t_newmethod)highshelf_new, 0,
+ sizeof(t_rbjfilter), 0,A_DEFFLOAT,A_DEFFLOAT,A_DEFFLOAT,0);
+ class_addbang(highshelf_class,highshelf_bang);
+ class_addfloat(highshelf_class,highshelf_float);
+}
+
+
diff --git a/apps/plugins/pdbox/PDa/extra/hlshelf.c b/apps/plugins/pdbox/PDa/extra/hlshelf.c
new file mode 100644
index 0000000000..46190c9b7c
--- /dev/null
+++ b/apps/plugins/pdbox/PDa/extra/hlshelf.c
@@ -0,0 +1,452 @@
+/* (C) Guenter Geiger <geiger@epy.co.at> */
+
+
+#include <m_pd.h>
+#include <math.h>
+
+#ifdef NT
+#pragma warning( disable : 4244 )
+#pragma warning( disable : 4305 )
+#endif
+
+/* ------------------------ hlshelf ----------------------------- */
+
+
+#ifndef M_PI
+#define M_PI 3.141593f
+#endif
+
+#define SRATE 44100.0
+#define MAX_GAIN 120.0f
+
+static t_class *hlshelf_class;
+
+
+typedef struct _hlshelf
+{
+ t_object x_obj;
+ float s_rate;
+ float s_gain0;
+ float s_gain1;
+ float s_gain2;
+ float s_ltransfq;
+ float s_htransfq;
+ float s_lradians;
+ float s_hradians;
+} t_hlshelf;
+
+
+int hlshelf_check_stability(t_float fb1,
+ t_float fb2,
+ t_float ff1,
+ t_float ff2,
+ t_float ff3)
+{
+ float discriminant = fb1 * fb1 + 4 * fb2;
+
+ if (discriminant < 0) /* imaginary roots -- resonant filter */
+ {
+ /* they're conjugates so we just check that the product
+ is less than one */
+ if (fb2 >= -1.0f) goto stable;
+ }
+ else /* real roots */
+ {
+ /* check that the parabola 1 - fb1 x - fb2 x^2 has a
+ vertex between -1 and 1, and that it's nonnegative
+ at both ends, which implies both roots are in [1-,1]. */
+ if (fb1 <= 2.0f && fb1 >= -2.0f &&
+ 1.0f - fb1 -fb2 >= 0 && 1.0f + fb1 - fb2 >= 0)
+ goto stable;
+ }
+ return 0;
+stable:
+ return 1;
+}
+
+
+void hlshelf_check(t_hlshelf *x)
+{
+
+ if(x->s_gain0 - x->s_gain1 > MAX_GAIN) {
+ x->s_gain0 = x->s_gain1 + MAX_GAIN;
+ post("setting gain0 to %f",x->s_gain0);
+ }
+
+
+ if(x->s_gain1 > MAX_GAIN) {
+ x->s_gain1 = MAX_GAIN;
+ post("setting gain1 to %f",x->s_gain1);
+ }
+
+ if(x->s_gain2 - x->s_gain1 > MAX_GAIN) {
+ x->s_gain2 = x->s_gain1 + MAX_GAIN;
+ post("setting gain2 to %f",x->s_gain2);
+ }
+
+ /* constrain: 0 <= x->s_ltransfq < x->s_htransfq. */
+ x->s_ltransfq = (x->s_ltransfq < x->s_htransfq) ? x->s_ltransfq : x->s_htransfq - 0.5f;
+
+ if (x->s_ltransfq < 0) x->s_ltransfq = 0.0f;
+
+ x->s_lradians = M_PI * x->s_ltransfq / x->s_rate;
+ x->s_hradians= M_PI * (0.5f - (x->s_htransfq / x->s_rate));
+
+}
+
+
+void hlshelf_bang(t_hlshelf *x)
+{
+ t_atom at[6];
+ float c0, c1, c2, d0, d1, d2; /* output coefs */
+ float a1, a2, b1, b2, g1, g2; /* temp coefs */
+ double xf;
+
+ hlshelf_check(x);
+
+ /* low shelf */
+ xf = 0.5 * 0.115129255 * (double)(x->s_gain0 - x->s_gain1); /* ln(10) / 20 = 0.115129255 */
+ if(xf < -200.) /* exp(x) -> 0 */
+ {
+ a1 = 1.0f;
+ b1 = -1.0f;
+ g1 = 0.0f;
+ }
+ else
+ {
+ double t = tan(x->s_lradians);
+ double e = exp(xf);
+ double r = t / e;
+ double kr = t * e;
+
+ a1 = (r - 1) / (r + 1);
+ b1 = (kr - 1) / (kr + 1);
+ g1 = (kr + 1) / (r + 1);
+ }
+
+ /* high shelf */
+ xf = 0.5 * 0.115129255 * (double)(x->s_gain2 - x->s_gain1); /* ln(10) / 20 = 0.115129255 */
+ if(xf < -200.) /* exp(x) -> 0 */
+ {
+ a2 = -1.0f;
+ b2 = 1.0f;
+ g2 = 0.0f;
+ }
+ else
+ {
+ double t = tan(x->s_hradians);
+ double e = exp(xf);
+ double r = t / e;
+ double kr = t * e;
+
+ a2 = (1 - r) / (1 + r);
+ b2 = (1 - kr) / (1 + kr);
+ g2 = (1 + kr) / (1 + r);
+ }
+
+ /* form product */
+ c0 = g1 * g2 * (float)(exp((double)(x->s_gain1) * 0.05f * 2.302585093f)); ;
+ c1 = a1 + a2;
+ c2 = a1 * a2;
+ d0 = 1.0f;
+ d1 = b1 + b2;
+ d2 = b1 * b2;
+
+ if (!hlshelf_check_stability(-c1/d0,-c2/d0,d0/d0,d1/d0,d2/d0)) {
+ post("hlshelf: filter unstable -> resetting");
+ c0=1.;c1=0.;c2=0.;
+ d0=1.;d1=0.;d2=0.;
+ }
+
+ SETFLOAT(at,-c1/d0);
+ SETFLOAT(at+1,-c2/d0);
+ SETFLOAT(at+2,d0/d0);
+ SETFLOAT(at+3,d1/d0);
+ SETFLOAT(at+4,d2/d0);
+
+ outlet_list(x->x_obj.ob_outlet,&s_list,5,at);
+}
+
+void hlshelf_float(t_hlshelf *x,t_floatarg f)
+{
+ x->s_gain0 = f;
+ hlshelf_bang(x);
+}
+
+
+static void *hlshelf_new(t_symbol* s,t_int argc, t_atom* at)
+{
+ t_hlshelf *x = (t_hlshelf *)pd_new(hlshelf_class);
+ t_float k0 = atom_getfloat(at);
+ t_float k1 = atom_getfloat(at+1);
+ t_float k2 = atom_getfloat(at+2);
+ t_float f1 = atom_getfloat(at+3);
+ t_float f2 = atom_getfloat(at+4);
+
+
+ f1 = atom_getfloat(at);
+ f2 = atom_getfloat(at);
+
+ if ((f1 == 0.0f && f2 == 0.0f) || f1 > f2){ /* all gains = 0db */
+ f1 = 150.0f;
+ f2 = 5000.0f;
+ }
+
+ if (f1 < 0) f1 = 0.0f;
+ if (f2 > SRATE) f2 = .5f*SRATE;
+
+ x->s_rate = SRATE; /* srate default */
+ x->s_gain0 = k0;
+ x->s_gain1 = k1;
+ x->s_gain2 = k2;
+
+ x->s_ltransfq = 0.0f;
+ x->s_htransfq = SRATE/2;
+
+ x->s_lradians = M_PI * x->s_ltransfq / x->s_rate;
+ x->s_hradians= M_PI * (0.5f - (x->s_htransfq / x->s_rate));
+
+ floatinlet_new(&x->x_obj, &x->s_gain1);
+ floatinlet_new(&x->x_obj, &x->s_gain2);
+ floatinlet_new(&x->x_obj, &x->s_ltransfq);
+ floatinlet_new(&x->x_obj, &x->s_htransfq);
+ outlet_new(&x->x_obj, &s_list);
+
+ return (x);
+}
+
+void hlshelf_setup(void)
+{
+ hlshelf_class = class_new(gensym("hlshelf"), (t_newmethod)hlshelf_new, 0,
+ sizeof(t_hlshelf), 0, A_GIMME, 0);
+ class_addbang(hlshelf_class,hlshelf_bang);
+ class_addfloat(hlshelf_class,hlshelf_float);
+}
+
+
+/* (C) Guenter Geiger <geiger@epy.co.at> */
+
+
+#include <m_pd.h>
+#include <math.h>
+
+#ifdef NT
+#pragma warning( disable : 4244 )
+#pragma warning( disable : 4305 )
+#endif
+
+/* ------------------------ hlshelf ----------------------------- */
+
+
+#ifndef M_PI
+#define M_PI 3.141593f
+#endif
+
+#define SRATE 44100.0
+#define MAX_GAIN 120.0f
+
+static t_class *hlshelf_class;
+
+
+typedef struct _hlshelf
+{
+ t_object x_obj;
+ float s_rate;
+ float s_gain0;
+ float s_gain1;
+ float s_gain2;
+ float s_ltransfq;
+ float s_htransfq;
+ float s_lradians;
+ float s_hradians;
+} t_hlshelf;
+
+
+int hlshelf_check_stability(t_float fb1,
+ t_float fb2,
+ t_float ff1,
+ t_float ff2,
+ t_float ff3)
+{
+ float discriminant = fb1 * fb1 + 4 * fb2;
+
+ if (discriminant < 0) /* imaginary roots -- resonant filter */
+ {
+ /* they're conjugates so we just check that the product
+ is less than one */
+ if (fb2 >= -1.0f) goto stable;
+ }
+ else /* real roots */
+ {
+ /* check that the parabola 1 - fb1 x - fb2 x^2 has a
+ vertex between -1 and 1, and that it's nonnegative
+ at both ends, which implies both roots are in [1-,1]. */
+ if (fb1 <= 2.0f && fb1 >= -2.0f &&
+ 1.0f - fb1 -fb2 >= 0 && 1.0f + fb1 - fb2 >= 0)
+ goto stable;
+ }
+ return 0;
+stable:
+ return 1;
+}
+
+
+void hlshelf_check(t_hlshelf *x)
+{
+
+ if(x->s_gain0 - x->s_gain1 > MAX_GAIN) {
+ x->s_gain0 = x->s_gain1 + MAX_GAIN;
+ post("setting gain0 to %f",x->s_gain0);
+ }
+
+
+ if(x->s_gain1 > MAX_GAIN) {
+ x->s_gain1 = MAX_GAIN;
+ post("setting gain1 to %f",x->s_gain1);
+ }
+
+ if(x->s_gain2 - x->s_gain1 > MAX_GAIN) {
+ x->s_gain2 = x->s_gain1 + MAX_GAIN;
+ post("setting gain2 to %f",x->s_gain2);
+ }
+
+ /* constrain: 0 <= x->s_ltransfq < x->s_htransfq. */
+ x->s_ltransfq = (x->s_ltransfq < x->s_htransfq) ? x->s_ltransfq : x->s_htransfq - 0.5f;
+
+ if (x->s_ltransfq < 0) x->s_ltransfq = 0.0f;
+
+ x->s_lradians = M_PI * x->s_ltransfq / x->s_rate;
+ x->s_hradians= M_PI * (0.5f - (x->s_htransfq / x->s_rate));
+
+}
+
+
+void hlshelf_bang(t_hlshelf *x)
+{
+ t_atom at[6];
+ float c0, c1, c2, d0, d1, d2; /* output coefs */
+ float a1, a2, b1, b2, g1, g2; /* temp coefs */
+ double xf;
+
+ hlshelf_check(x);
+
+ /* low shelf */
+ xf = 0.5 * 0.115129255 * (double)(x->s_gain0 - x->s_gain1); /* ln(10) / 20 = 0.115129255 */
+ if(xf < -200.) /* exp(x) -> 0 */
+ {
+ a1 = 1.0f;
+ b1 = -1.0f;
+ g1 = 0.0f;
+ }
+ else
+ {
+ double t = tan(x->s_lradians);
+ double e = exp(xf);
+ double r = t / e;
+ double kr = t * e;
+
+ a1 = (r - 1) / (r + 1);
+ b1 = (kr - 1) / (kr + 1);
+ g1 = (kr + 1) / (r + 1);
+ }
+
+ /* high shelf */
+ xf = 0.5 * 0.115129255 * (double)(x->s_gain2 - x->s_gain1); /* ln(10) / 20 = 0.115129255 */
+ if(xf < -200.) /* exp(x) -> 0 */
+ {
+ a2 = -1.0f;
+ b2 = 1.0f;
+ g2 = 0.0f;
+ }
+ else
+ {
+ double t = tan(x->s_hradians);
+ double e = exp(xf);
+ double r = t / e;
+ double kr = t * e;
+
+ a2 = (1 - r) / (1 + r);
+ b2 = (1 - kr) / (1 + kr);
+ g2 = (1 + kr) / (1 + r);
+ }
+
+ /* form product */
+ c0 = g1 * g2 * (float)(exp((double)(x->s_gain1) * 0.05f * 2.302585093f)); ;
+ c1 = a1 + a2;
+ c2 = a1 * a2;
+ d0 = 1.0f;
+ d1 = b1 + b2;
+ d2 = b1 * b2;
+
+ if (!hlshelf_check_stability(-c1/d0,-c2/d0,d0/d0,d1/d0,d2/d0)) {
+ post("hlshelf: filter unstable -> resetting");
+ c0=1.;c1=0.;c2=0.;
+ d0=1.;d1=0.;d2=0.;
+ }
+
+ SETFLOAT(at,-c1/d0);
+ SETFLOAT(at+1,-c2/d0);
+ SETFLOAT(at+2,d0/d0);
+ SETFLOAT(at+3,d1/d0);
+ SETFLOAT(at+4,d2/d0);
+
+ outlet_list(x->x_obj.ob_outlet,&s_list,5,at);
+}
+
+void hlshelf_float(t_hlshelf *x,t_floatarg f)
+{
+ x->s_gain0 = f;
+ hlshelf_bang(x);
+}
+
+
+static void *hlshelf_new(t_symbol* s,t_int argc, t_atom* at)
+{
+ t_hlshelf *x = (t_hlshelf *)pd_new(hlshelf_class);
+ t_float k0 = atom_getfloat(at);
+ t_float k1 = atom_getfloat(at+1);
+ t_float k2 = atom_getfloat(at+2);
+ t_float f1 = atom_getfloat(at+3);
+ t_float f2 = atom_getfloat(at+4);
+
+
+ f1 = atom_getfloat(at);
+ f2 = atom_getfloat(at);
+
+ if ((f1 == 0.0f && f2 == 0.0f) || f1 > f2){ /* all gains = 0db */
+ f1 = 150.0f;
+ f2 = 5000.0f;
+ }
+
+ if (f1 < 0) f1 = 0.0f;
+ if (f2 > SRATE) f2 = .5f*SRATE;
+
+ x->s_rate = SRATE; /* srate default */
+ x->s_gain0 = k0;
+ x->s_gain1 = k1;
+ x->s_gain2 = k2;
+
+ x->s_ltransfq = 0.0f;
+ x->s_htransfq = SRATE/2;
+
+ x->s_lradians = M_PI * x->s_ltransfq / x->s_rate;
+ x->s_hradians= M_PI * (0.5f - (x->s_htransfq / x->s_rate));
+
+ floatinlet_new(&x->x_obj, &x->s_gain1);
+ floatinlet_new(&x->x_obj, &x->s_gain2);
+ floatinlet_new(&x->x_obj, &x->s_ltransfq);
+ floatinlet_new(&x->x_obj, &x->s_htransfq);
+ outlet_new(&x->x_obj, &s_list);
+
+ return (x);
+}
+
+void hlshelf_setup(void)
+{
+ hlshelf_class = class_new(gensym("hlshelf"), (t_newmethod)hlshelf_new, 0,
+ sizeof(t_hlshelf), 0, A_GIMME, 0);
+ class_addbang(hlshelf_class,hlshelf_bang);
+ class_addfloat(hlshelf_class,hlshelf_float);
+}
+
+
diff --git a/apps/plugins/pdbox/PDa/extra/image.c b/apps/plugins/pdbox/PDa/extra/image.c
new file mode 100644
index 0000000000..6de48ef8fb
--- /dev/null
+++ b/apps/plugins/pdbox/PDa/extra/image.c
@@ -0,0 +1,434 @@
+#include "m_pd.h"
+#include "g_canvas.h"
+
+#ifdef NT
+#pragma warning( disable : 4244 )
+#pragma warning( disable : 4305 )
+#endif
+
+/* ------------------------ image ----------------------------- */
+
+static t_class *image_class;
+
+typedef struct _image
+{
+ t_object x_obj;
+ t_glist * x_glist;
+ int x_width;
+ int x_height;
+ t_symbol* x_fname;
+} t_image;
+
+/* widget helper functions */
+
+void image_drawme(t_image *x, t_glist *glist, int firsttime)
+{
+ if (firsttime) {
+ char fname[MAXPDSTRING];
+ canvas_makefilename(glist_getcanvas(x->x_glist), x->x_fname->s_name,
+ fname, MAXPDSTRING);
+
+ sys_vgui("image create photo img%x -file %s\n",x,fname);
+ sys_vgui(".x%x.c create image %d %d -image img%x -tags %xS\n",
+ glist_getcanvas(glist),text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist),x,x);
+
+ /* TODO callback from gui
+ sys_vgui("image_size logo");
+ */
+ }
+ else {
+ sys_vgui(".x%x.c coords %xS \
+%d %d\n",
+ glist_getcanvas(glist), x,
+ text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist));
+ }
+
+}
+
+
+void image_erase(t_image* x,t_glist* glist)
+{
+ int n;
+ sys_vgui(".x%x.c delete %xS\n",
+ glist_getcanvas(glist), x);
+
+}
+
+
+
+/* ------------------------ image widgetbehaviour----------------------------- */
+
+
+static void image_getrect(t_gobj *z, t_glist *glist,
+ int *xp1, int *yp1, int *xp2, int *yp2)
+{
+ int width, height;
+ t_image* x = (t_image*)z;
+
+
+ width = x->x_width;
+ height = x->x_height;
+ *xp1 = text_xpix(&x->x_obj, glist);
+ *yp1 = text_ypix(&x->x_obj, glist);
+ *xp2 = text_xpix(&x->x_obj, glist) + width;
+ *yp2 = text_ypix(&x->x_obj, glist) + height;
+}
+
+static void image_displace(t_gobj *z, t_glist *glist,
+ int dx, int dy)
+{
+ t_image *x = (t_image *)z;
+ x->x_obj.te_xpix += dx;
+ x->x_obj.te_ypix += dy;
+ sys_vgui(".x%x.c coords %xSEL %d %d %d %d\n",
+ glist_getcanvas(glist), x,
+ text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist),
+ text_xpix(&x->x_obj, glist) + x->x_width, text_ypix(&x->x_obj, glist) + x->x_height);
+
+ image_drawme(x, glist, 0);
+ canvas_fixlinesfor(glist_getcanvas(glist),(t_text*) x);
+}
+
+static void image_select(t_gobj *z, t_glist *glist, int state)
+{
+ t_image *x = (t_image *)z;
+ if (state) {
+ sys_vgui(".x%x.c create rectangle \
+%d %d %d %d -tags %xSEL -outline blue\n",
+ glist_getcanvas(glist),
+ text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist),
+ text_xpix(&x->x_obj, glist) + x->x_width, text_ypix(&x->x_obj, glist) + x->x_height,
+ x);
+ }
+ else {
+ sys_vgui(".x%x.c delete %xSEL\n",
+ glist_getcanvas(glist), x);
+ }
+
+
+
+}
+
+
+static void image_activate(t_gobj *z, t_glist *glist, int state)
+{
+/* t_text *x = (t_text *)z;
+ t_rtext *y = glist_findrtext(glist, x);
+ if (z->g_pd != gatom_class) rtext_activate(y, state);*/
+}
+
+static void image_delete(t_gobj *z, t_glist *glist)
+{
+ t_text *x = (t_text *)z;
+ canvas_deletelinesfor(glist_getcanvas(glist), x);
+}
+
+
+static void image_vis(t_gobj *z, t_glist *glist, int vis)
+{
+ t_image* s = (t_image*)z;
+ if (vis)
+ image_drawme(s, glist, 1);
+ else
+ image_erase(s,glist);
+}
+
+/* can we use the normal text save function ?? */
+
+static void image_save(t_gobj *z, t_binbuf *b)
+{
+ t_image *x = (t_image *)z;
+ binbuf_addv(b, "ssiiss", gensym("#X"),gensym("obj"),
+ x->x_obj.te_xpix, x->x_obj.te_ypix,
+ gensym("image"),x->x_fname);
+ binbuf_addv(b, ";");
+}
+
+
+t_widgetbehavior image_widgetbehavior;
+
+void image_size(t_image* x,t_floatarg w,t_floatarg h) {
+ x->x_width = w;
+ x->x_height = h;
+}
+
+void image_color(t_image* x,t_symbol* col)
+{
+/* outlet_bang(x->x_obj.ob_outlet); only bang if there was a bang ..
+ so color black does the same as bang, but doesn't forward the bang
+*/
+}
+
+static void image_setwidget(void)
+{
+ image_widgetbehavior.w_getrectfn = image_getrect;
+ image_widgetbehavior.w_displacefn = image_displace;
+ image_widgetbehavior.w_selectfn = image_select;
+ image_widgetbehavior.w_activatefn = image_activate;
+ image_widgetbehavior.w_deletefn = image_delete;
+ image_widgetbehavior.w_visfn = image_vis;
+#if (PD_VERSION_MINOR > 31)
+ image_widgetbehavior.w_clickfn = NULL;
+ image_widgetbehavior.w_propertiesfn = NULL;
+#endif
+#if PD_MINOR_VERSION < 37
+ image_widgetbehavior.w_savefn = image_save;
+#endif
+}
+
+
+static void *image_new(t_symbol* fname)
+{
+ t_image *x = (t_image *)pd_new(image_class);
+
+ x->x_glist = (t_glist*) canvas_getcurrent();
+
+ x->x_width = 15;
+ x->x_height = 15;
+
+ x->x_fname = fname;
+ outlet_new(&x->x_obj, &s_float);
+ return (x);
+}
+
+void image_setup(void)
+{
+ image_class = class_new(gensym("image"), (t_newmethod)image_new, 0,
+ sizeof(t_image),0, A_DEFSYM,0);
+
+/*
+ class_addmethod(image_class, (t_method)image_size, gensym("size"),
+ A_FLOAT, A_FLOAT, 0);
+
+ class_addmethod(image_class, (t_method)image_color, gensym("color"),
+ A_SYMBOL, 0);
+*/
+/*
+ class_addmethod(image_class, (t_method)image_open, gensym("open"),
+ A_SYMBOL, 0);
+*/
+ image_setwidget();
+ class_setwidget(image_class,&image_widgetbehavior);
+#if PD_MINOR_VERSION >= 37
+ class_setsavefn(image_class,&image_save);
+#endif
+}
+
+
+#include "m_pd.h"
+#include "g_canvas.h"
+
+#ifdef NT
+#pragma warning( disable : 4244 )
+#pragma warning( disable : 4305 )
+#endif
+
+/* ------------------------ image ----------------------------- */
+
+static t_class *image_class;
+
+typedef struct _image
+{
+ t_object x_obj;
+ t_glist * x_glist;
+ int x_width;
+ int x_height;
+ t_symbol* x_fname;
+} t_image;
+
+/* widget helper functions */
+
+void image_drawme(t_image *x, t_glist *glist, int firsttime)
+{
+ if (firsttime) {
+ char fname[MAXPDSTRING];
+ canvas_makefilename(glist_getcanvas(x->x_glist), x->x_fname->s_name,
+ fname, MAXPDSTRING);
+
+ sys_vgui("image create photo img%x -file %s\n",x,fname);
+ sys_vgui(".x%x.c create image %d %d -image img%x -tags %xS\n",
+ glist_getcanvas(glist),text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist),x,x);
+
+ /* TODO callback from gui
+ sys_vgui("image_size logo");
+ */
+ }
+ else {
+ sys_vgui(".x%x.c coords %xS \
+%d %d\n",
+ glist_getcanvas(glist), x,
+ text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist));
+ }
+
+}
+
+
+void image_erase(t_image* x,t_glist* glist)
+{
+ int n;
+ sys_vgui(".x%x.c delete %xS\n",
+ glist_getcanvas(glist), x);
+
+}
+
+
+
+/* ------------------------ image widgetbehaviour----------------------------- */
+
+
+static void image_getrect(t_gobj *z, t_glist *glist,
+ int *xp1, int *yp1, int *xp2, int *yp2)
+{
+ int width, height;
+ t_image* x = (t_image*)z;
+
+
+ width = x->x_width;
+ height = x->x_height;
+ *xp1 = text_xpix(&x->x_obj, glist);
+ *yp1 = text_ypix(&x->x_obj, glist);
+ *xp2 = text_xpix(&x->x_obj, glist) + width;
+ *yp2 = text_ypix(&x->x_obj, glist) + height;
+}
+
+static void image_displace(t_gobj *z, t_glist *glist,
+ int dx, int dy)
+{
+ t_image *x = (t_image *)z;
+ x->x_obj.te_xpix += dx;
+ x->x_obj.te_ypix += dy;
+ sys_vgui(".x%x.c coords %xSEL %d %d %d %d\n",
+ glist_getcanvas(glist), x,
+ text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist),
+ text_xpix(&x->x_obj, glist) + x->x_width, text_ypix(&x->x_obj, glist) + x->x_height);
+
+ image_drawme(x, glist, 0);
+ canvas_fixlinesfor(glist_getcanvas(glist),(t_text*) x);
+}
+
+static void image_select(t_gobj *z, t_glist *glist, int state)
+{
+ t_image *x = (t_image *)z;
+ if (state) {
+ sys_vgui(".x%x.c create rectangle \
+%d %d %d %d -tags %xSEL -outline blue\n",
+ glist_getcanvas(glist),
+ text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist),
+ text_xpix(&x->x_obj, glist) + x->x_width, text_ypix(&x->x_obj, glist) + x->x_height,
+ x);
+ }
+ else {
+ sys_vgui(".x%x.c delete %xSEL\n",
+ glist_getcanvas(glist), x);
+ }
+
+
+
+}
+
+
+static void image_activate(t_gobj *z, t_glist *glist, int state)
+{
+/* t_text *x = (t_text *)z;
+ t_rtext *y = glist_findrtext(glist, x);
+ if (z->g_pd != gatom_class) rtext_activate(y, state);*/
+}
+
+static void image_delete(t_gobj *z, t_glist *glist)
+{
+ t_text *x = (t_text *)z;
+ canvas_deletelinesfor(glist_getcanvas(glist), x);
+}
+
+
+static void image_vis(t_gobj *z, t_glist *glist, int vis)
+{
+ t_image* s = (t_image*)z;
+ if (vis)
+ image_drawme(s, glist, 1);
+ else
+ image_erase(s,glist);
+}
+
+/* can we use the normal text save function ?? */
+
+static void image_save(t_gobj *z, t_binbuf *b)
+{
+ t_image *x = (t_image *)z;
+ binbuf_addv(b, "ssiiss", gensym("#X"),gensym("obj"),
+ x->x_obj.te_xpix, x->x_obj.te_ypix,
+ gensym("image"),x->x_fname);
+ binbuf_addv(b, ";");
+}
+
+
+t_widgetbehavior image_widgetbehavior;
+
+void image_size(t_image* x,t_floatarg w,t_floatarg h) {
+ x->x_width = w;
+ x->x_height = h;
+}
+
+void image_color(t_image* x,t_symbol* col)
+{
+/* outlet_bang(x->x_obj.ob_outlet); only bang if there was a bang ..
+ so color black does the same as bang, but doesn't forward the bang
+*/
+}
+
+static void image_setwidget(void)
+{
+ image_widgetbehavior.w_getrectfn = image_getrect;
+ image_widgetbehavior.w_displacefn = image_displace;
+ image_widgetbehavior.w_selectfn = image_select;
+ image_widgetbehavior.w_activatefn = image_activate;
+ image_widgetbehavior.w_deletefn = image_delete;
+ image_widgetbehavior.w_visfn = image_vis;
+#if (PD_VERSION_MINOR > 31)
+ image_widgetbehavior.w_clickfn = NULL;
+ image_widgetbehavior.w_propertiesfn = NULL;
+#endif
+#if PD_MINOR_VERSION < 37
+ image_widgetbehavior.w_savefn = image_save;
+#endif
+}
+
+
+static void *image_new(t_symbol* fname)
+{
+ t_image *x = (t_image *)pd_new(image_class);
+
+ x->x_glist = (t_glist*) canvas_getcurrent();
+
+ x->x_width = 15;
+ x->x_height = 15;
+
+ x->x_fname = fname;
+ outlet_new(&x->x_obj, &s_float);
+ return (x);
+}
+
+void image_setup(void)
+{
+ image_class = class_new(gensym("image"), (t_newmethod)image_new, 0,
+ sizeof(t_image),0, A_DEFSYM,0);
+
+/*
+ class_addmethod(image_class, (t_method)image_size, gensym("size"),
+ A_FLOAT, A_FLOAT, 0);
+
+ class_addmethod(image_class, (t_method)image_color, gensym("color"),
+ A_SYMBOL, 0);
+*/
+/*
+ class_addmethod(image_class, (t_method)image_open, gensym("open"),
+ A_SYMBOL, 0);
+*/
+ image_setwidget();
+ class_setwidget(image_class,&image_widgetbehavior);
+#if PD_MINOR_VERSION >= 37
+ class_setsavefn(image_class,&image_save);
+#endif
+}
+
+
diff --git a/apps/plugins/pdbox/PDa/extra/lowpass.c b/apps/plugins/pdbox/PDa/extra/lowpass.c
new file mode 100644
index 0000000000..c242aff0a8
--- /dev/null
+++ b/apps/plugins/pdbox/PDa/extra/lowpass.c
@@ -0,0 +1,178 @@
+/* (C) Guenter Geiger <geiger@epy.co.at> */
+
+
+/*
+
+ These filter coefficients computations are taken from
+ http://www.harmony-central.com/Computer/Programming/Audio-EQ-Cookbook.txt
+
+ written by Robert Bristow-Johnson
+
+*/
+
+#include "m_pd.h"
+#ifdef NT
+#pragma warning( disable : 4244 )
+#pragma warning( disable : 4305 )
+#endif
+#include <math.h>
+#include "filters.h"
+
+
+
+/* ------------------- lowpass ----------------------------*/
+
+static t_class *lowpass_class;
+
+void lowpass_bang(t_rbjfilter *x)
+{
+ t_atom at[5];
+ t_float omega = e_omega(x->x_freq,x->x_rate);
+ t_float alpha = e_alpha(x->x_bw*0.01,omega);
+ t_float b1 = 1 - cos(omega);
+ t_float b0 = b1/2.;
+ t_float b2 = b0;
+ t_float a0 = 1 + alpha;
+ t_float a1 = -2.*cos(omega);
+ t_float a2 = 1 - alpha;
+
+/* post("bang %f %f %f",x->x_freq, x->x_gain, x->x_bw); */
+
+ if (!check_stability(-a1/a0,-a2/a0,b0/a0,b1/a0,b2/a0)) {
+ post("lowpass: filter unstable -> resetting");
+ a0=1.;a1=0.;a2=0.;
+ b0=1.;b1=0.;b2=0.;
+ }
+
+ SETFLOAT(at,-a1/a0);
+ SETFLOAT(at+1,-a2/a0);
+ SETFLOAT(at+2,b0/a0);
+ SETFLOAT(at+3,b1/a0);
+ SETFLOAT(at+4,b2/a0);
+
+ outlet_list(x->x_obj.ob_outlet,&s_list,5,at);
+}
+
+
+void lowpass_float(t_rbjfilter *x,t_floatarg f)
+{
+ x->x_freq = f;
+ lowpass_bang(x);
+}
+
+
+static void *lowpass_new(t_floatarg f,t_floatarg bw)
+{
+ t_rbjfilter *x = (t_rbjfilter *)pd_new(lowpass_class);
+
+ x->x_rate = 44100.0;
+ outlet_new(&x->x_obj,&s_float);
+/* floatinlet_new(&x->x_obj, &x->x_gain); */
+ floatinlet_new(&x->x_obj, &x->x_bw);
+
+ if (f > 0.) x->x_freq = f;
+ if (bw > 0.) x->x_bw = bw;
+ return (x);
+}
+
+
+void lowpass_setup(void)
+{
+ lowpass_class = class_new(gensym("lowpass"), (t_newmethod)lowpass_new, 0,
+ sizeof(t_rbjfilter), 0,A_DEFFLOAT,A_DEFFLOAT,0);
+ class_addbang(lowpass_class,lowpass_bang);
+ class_addfloat(lowpass_class,lowpass_float);
+}
+
+
+
+
+/* (C) Guenter Geiger <geiger@epy.co.at> */
+
+
+/*
+
+ These filter coefficients computations are taken from
+ http://www.harmony-central.com/Computer/Programming/Audio-EQ-Cookbook.txt
+
+ written by Robert Bristow-Johnson
+
+*/
+
+#include "m_pd.h"
+#ifdef NT
+#pragma warning( disable : 4244 )
+#pragma warning( disable : 4305 )
+#endif
+#include <math.h>
+#include "filters.h"
+
+
+
+/* ------------------- lowpass ----------------------------*/
+
+static t_class *lowpass_class;
+
+void lowpass_bang(t_rbjfilter *x)
+{
+ t_atom at[5];
+ t_float omega = e_omega(x->x_freq,x->x_rate);
+ t_float alpha = e_alpha(x->x_bw*0.01,omega);
+ t_float b1 = 1 - cos(omega);
+ t_float b0 = b1/2.;
+ t_float b2 = b0;
+ t_float a0 = 1 + alpha;
+ t_float a1 = -2.*cos(omega);
+ t_float a2 = 1 - alpha;
+
+/* post("bang %f %f %f",x->x_freq, x->x_gain, x->x_bw); */
+
+ if (!check_stability(-a1/a0,-a2/a0,b0/a0,b1/a0,b2/a0)) {
+ post("lowpass: filter unstable -> resetting");
+ a0=1.;a1=0.;a2=0.;
+ b0=1.;b1=0.;b2=0.;
+ }
+
+ SETFLOAT(at,-a1/a0);
+ SETFLOAT(at+1,-a2/a0);
+ SETFLOAT(at+2,b0/a0);
+ SETFLOAT(at+3,b1/a0);
+ SETFLOAT(at+4,b2/a0);
+
+ outlet_list(x->x_obj.ob_outlet,&s_list,5,at);
+}
+
+
+void lowpass_float(t_rbjfilter *x,t_floatarg f)
+{
+ x->x_freq = f;
+ lowpass_bang(x);
+}
+
+
+static void *lowpass_new(t_floatarg f,t_floatarg bw)
+{
+ t_rbjfilter *x = (t_rbjfilter *)pd_new(lowpass_class);
+
+ x->x_rate = 44100.0;
+ outlet_new(&x->x_obj,&s_float);
+/* floatinlet_new(&x->x_obj, &x->x_gain); */
+ floatinlet_new(&x->x_obj, &x->x_bw);
+
+ if (f > 0.) x->x_freq = f;
+ if (bw > 0.) x->x_bw = bw;
+ return (x);
+}
+
+
+void lowpass_setup(void)
+{
+ lowpass_class = class_new(gensym("lowpass"), (t_newmethod)lowpass_new, 0,
+ sizeof(t_rbjfilter), 0,A_DEFFLOAT,A_DEFFLOAT,0);
+ class_addbang(lowpass_class,lowpass_bang);
+ class_addfloat(lowpass_class,lowpass_float);
+}
+
+
+
+
diff --git a/apps/plugins/pdbox/PDa/extra/lowshelf.c b/apps/plugins/pdbox/PDa/extra/lowshelf.c
new file mode 100644
index 0000000000..52c30d839d
--- /dev/null
+++ b/apps/plugins/pdbox/PDa/extra/lowshelf.c
@@ -0,0 +1,182 @@
+/* (C) Guenter Geiger <geiger@epy.co.at> */
+
+
+/*
+
+ These filter coefficients computations are taken from
+ http://www.harmony-central.com/Computer/Programming/Audio-EQ-Cookbook.txt
+
+ written by Robert Bristow-Johnson
+
+*/
+
+#include "m_pd.h"
+#ifdef NT
+#pragma warning( disable : 4244 )
+#pragma warning( disable : 4305 )
+#endif
+#include <math.h>
+#include "filters.h"
+
+
+
+/* ------------------- lowshelf ----------------------------*/
+
+static t_class *lowshelf_class;
+
+void lowshelf_bang(t_rbjfilter *x)
+{
+ t_atom at[5];
+ t_float omega = e_omega(x->x_freq,x->x_rate);
+ t_float A = e_A(x->x_gain);
+ t_float cs = cos(omega);
+ t_float sn = sin(omega);
+ t_float beta = e_beta(A,x->x_bw*0.01);
+
+ t_float b0 = A*((A+1) - (A-1)*cs + beta*sn);
+ t_float b1 = 2.*A*((A-1) - (A+1)*cs);
+ t_float b2 = A*((A+1) - (A-1)*cs - beta*sn);
+ t_float a0 = ((A+1) + (A-1)*cs + beta*sn);
+ t_float a1 = -2.*((A-1) + (A+1)*cs);
+ t_float a2 = ((A+1) + (A-1)*cs - beta*sn);
+
+/* post("bang %f %f %f",x->x_freq, x->x_gain, x->x_bw); */
+
+ if (!check_stability(-a1/a0,-a2/a0,b0/a0,b1/a0,b2/a0)) {
+ post("lowshelf: filter unstable -> resetting");
+ a0=1.;a1=0.;a2=0.;
+ b0=1.;b1=0.;b2=0.;
+ }
+
+ SETFLOAT(at,-a1/a0);
+ SETFLOAT(at+1,-a2/a0);
+ SETFLOAT(at+2,b0/a0);
+ SETFLOAT(at+3,b1/a0);
+ SETFLOAT(at+4,b2/a0);
+
+ outlet_list(x->x_obj.ob_outlet,&s_list,5,at);
+}
+
+
+void lowshelf_float(t_rbjfilter *x,t_floatarg f)
+{
+ x->x_freq = f;
+ lowshelf_bang(x);
+}
+
+
+static void *lowshelf_new(t_floatarg f,t_floatarg g,t_floatarg bw)
+{
+ t_rbjfilter *x = (t_rbjfilter *)pd_new(lowshelf_class);
+
+ x->x_rate = 44100.0;
+ outlet_new(&x->x_obj,&s_float);
+ floatinlet_new(&x->x_obj, &x->x_gain);
+ floatinlet_new(&x->x_obj, &x->x_bw);
+ if (f > 0.) x->x_freq = f;
+ if (bw > 0.) x->x_bw = bw;
+ if (g != 0.) x->x_gain = g;
+ return (x);
+}
+
+
+void lowshelf_setup(void)
+{
+ lowshelf_class = class_new(gensym("lowshelf"), (t_newmethod)lowshelf_new, 0,
+ sizeof(t_rbjfilter), 0,A_DEFFLOAT,A_DEFFLOAT,A_DEFFLOAT,0);
+ class_addbang(lowshelf_class,lowshelf_bang);
+ class_addfloat(lowshelf_class,lowshelf_float);
+}
+
+
+/* (C) Guenter Geiger <geiger@epy.co.at> */
+
+
+/*
+
+ These filter coefficients computations are taken from
+ http://www.harmony-central.com/Computer/Programming/Audio-EQ-Cookbook.txt
+
+ written by Robert Bristow-Johnson
+
+*/
+
+#include "m_pd.h"
+#ifdef NT
+#pragma warning( disable : 4244 )
+#pragma warning( disable : 4305 )
+#endif
+#include <math.h>
+#include "filters.h"
+
+
+
+/* ------------------- lowshelf ----------------------------*/
+
+static t_class *lowshelf_class;
+
+void lowshelf_bang(t_rbjfilter *x)
+{
+ t_atom at[5];
+ t_float omega = e_omega(x->x_freq,x->x_rate);
+ t_float A = e_A(x->x_gain);
+ t_float cs = cos(omega);
+ t_float sn = sin(omega);
+ t_float beta = e_beta(A,x->x_bw*0.01);
+
+ t_float b0 = A*((A+1) - (A-1)*cs + beta*sn);
+ t_float b1 = 2.*A*((A-1) - (A+1)*cs);
+ t_float b2 = A*((A+1) - (A-1)*cs - beta*sn);
+ t_float a0 = ((A+1) + (A-1)*cs + beta*sn);
+ t_float a1 = -2.*((A-1) + (A+1)*cs);
+ t_float a2 = ((A+1) + (A-1)*cs - beta*sn);
+
+/* post("bang %f %f %f",x->x_freq, x->x_gain, x->x_bw); */
+
+ if (!check_stability(-a1/a0,-a2/a0,b0/a0,b1/a0,b2/a0)) {
+ post("lowshelf: filter unstable -> resetting");
+ a0=1.;a1=0.;a2=0.;
+ b0=1.;b1=0.;b2=0.;
+ }
+
+ SETFLOAT(at,-a1/a0);
+ SETFLOAT(at+1,-a2/a0);
+ SETFLOAT(at+2,b0/a0);
+ SETFLOAT(at+3,b1/a0);
+ SETFLOAT(at+4,b2/a0);
+
+ outlet_list(x->x_obj.ob_outlet,&s_list,5,at);
+}
+
+
+void lowshelf_float(t_rbjfilter *x,t_floatarg f)
+{
+ x->x_freq = f;
+ lowshelf_bang(x);
+}
+
+
+static void *lowshelf_new(t_floatarg f,t_floatarg g,t_floatarg bw)
+{
+ t_rbjfilter *x = (t_rbjfilter *)pd_new(lowshelf_class);
+
+ x->x_rate = 44100.0;
+ outlet_new(&x->x_obj,&s_float);
+ floatinlet_new(&x->x_obj, &x->x_gain);
+ floatinlet_new(&x->x_obj, &x->x_bw);
+ if (f > 0.) x->x_freq = f;
+ if (bw > 0.) x->x_bw = bw;
+ if (g != 0.) x->x_gain = g;
+ return (x);
+}
+
+
+void lowshelf_setup(void)
+{
+ lowshelf_class = class_new(gensym("lowshelf"), (t_newmethod)lowshelf_new, 0,
+ sizeof(t_rbjfilter), 0,A_DEFFLOAT,A_DEFFLOAT,A_DEFFLOAT,0);
+ class_addbang(lowshelf_class,lowshelf_bang);
+ class_addfloat(lowshelf_class,lowshelf_float);
+}
+
+
diff --git a/apps/plugins/pdbox/PDa/extra/m_pd.h b/apps/plugins/pdbox/PDa/extra/m_pd.h
new file mode 100644
index 0000000000..403c5b382b
--- /dev/null
+++ b/apps/plugins/pdbox/PDa/extra/m_pd.h
@@ -0,0 +1,1300 @@
+/* Copyright (c) 1997-1999 Miller Puckette.
+* For information on usage and redistribution, and for a DISCLAIMER OF ALL
+* WARRANTIES, see the file, "LICENSE.txt," in this distribution. */
+
+#ifndef __m_pd_h_
+
+#if defined(_LANGUAGE_C_PLUS_PLUS) || defined(__cplusplus)
+extern "C" {
+#endif
+
+#define PD_VERSION 0.37 /* oops, don't use this... */ */
+#define PD_MAJOR_VERSION 0 /* ... use these two instead. */
+#define PD_MINOR_VERSION 37
+
+/* old name for "MSW" flag -- we have to take it for the sake of many old
+"nmakefiles" for externs, which will define NT and not MSW */
+#if defined(NT) && !defined(MSW)
+#define MSW
+#endif
+
+#ifdef MSW
+// #pragma warning( disable : 4091 )
+#pragma warning( disable : 4305 ) /* uncast const double to float */
+#pragma warning( disable : 4244 ) /* uncast float/int conversion etc. */
+#pragma warning( disable : 4101 ) /* unused automatic variables */
+#endif /* MSW */
+
+ /* the external storage class is "extern" in UNIX; in MSW it's ugly. */
+#ifdef MSW
+#ifdef PD_INTERNAL
+#define EXTERN __declspec(dllexport) extern
+#else
+#define EXTERN __declspec(dllimport) extern
+#endif /* PD_INTERNAL */
+#else
+#define EXTERN extern
+#endif /* MSW */
+
+ /* and depending on the compiler, hidden data structures are
+ declared differently: */
+#if defined( __GNUC__) || defined( __BORLANDC__ ) || defined( __MWERKS__ )
+#define EXTERN_STRUCT struct
+#else
+#define EXTERN_STRUCT extern struct
+#endif
+
+
+#if !defined(_SIZE_T) && !defined(_SIZE_T_)
+#include <stddef.h> /* just for size_t -- how lame! */
+#endif
+
+#define MAXPDSTRING 1000 /* use this for anything you want */
+#define MAXPDARG 5 /* max number of args we can typecheck today */
+
+ /* signed and unsigned integer types the size of a pointer: */
+#ifdef __alpha__
+typedef long t_int;
+#else
+typedef int t_int;
+#endif
+
+typedef float t_float; /* a floating-point number at most the same size */
+typedef float t_floatarg; /* floating-point type for function calls */
+
+typedef struct _symbol
+{
+ char *s_name;
+ struct _class **s_thing;
+ struct _symbol *s_next;
+} t_symbol;
+
+EXTERN_STRUCT _array;
+#define t_array struct _array /* g_canvas.h */
+
+/* pointers to glist and array elements go through a "stub" which sticks
+around after the glist or array is freed. The stub itself is deleted when
+both the glist/array is gone and the refcount is zero, ensuring that no
+gpointers are pointing here. */
+
+#define GP_NONE 0 /* the stub points nowhere (has been cut off) */
+#define GP_GLIST 1 /* the stub points to a glist element */
+#define GP_ARRAY 2 /* ... or array */
+
+typedef struct _gstub
+{
+ union
+ {
+ struct _glist *gs_glist; /* glist we're in */
+ struct _array *gs_array; /* array we're in */
+ } gs_un;
+ int gs_which; /* GP_GLIST/GP_ARRAY */
+ int gs_refcount; /* number of gpointers pointing here */
+} t_gstub;
+
+typedef struct _gpointer /* pointer to a gobj in a glist */
+{
+ union
+ {
+ struct _scalar *gp_scalar; /* scalar we're in (if glist) */
+ union word *gp_w; /* raw data (if array) */
+ } gp_un;
+ int gp_valid; /* number which must match gpointee */
+ t_gstub *gp_stub; /* stub which points to glist/array */
+} t_gpointer;
+
+typedef union word
+{
+ t_float w_float;
+ t_symbol *w_symbol;
+ t_gpointer *w_gpointer;
+ t_array *w_array;
+ struct _glist *w_list;
+ int w_index;
+} t_word;
+
+typedef enum
+{
+ A_NULL,
+ A_FLOAT,
+ A_SYMBOL,
+ A_POINTER,
+ A_SEMI,
+ A_COMMA,
+ A_DEFFLOAT,
+ A_DEFSYM,
+ A_DOLLAR,
+ A_DOLLSYM,
+ A_GIMME,
+ A_CANT
+} t_atomtype;
+
+#define A_DEFSYMBOL A_DEFSYM /* better name for this */
+
+typedef struct _atom
+{
+ t_atomtype a_type;
+ union word a_w;
+} t_atom;
+
+EXTERN_STRUCT _class;
+#define t_class struct _class
+
+EXTERN_STRUCT _outlet;
+#define t_outlet struct _outlet
+
+EXTERN_STRUCT _inlet;
+#define t_inlet struct _inlet
+
+EXTERN_STRUCT _binbuf;
+#define t_binbuf struct _binbuf
+
+EXTERN_STRUCT _clock;
+#define t_clock struct _clock
+
+EXTERN_STRUCT _outconnect;
+#define t_outconnect struct _outconnect
+
+EXTERN_STRUCT _glist;
+#define t_glist struct _glist
+#define t_canvas struct _glist /* LATER lose this */
+
+typedef t_class *t_pd; /* pure datum: nothing but a class pointer */
+
+typedef struct _gobj /* a graphical object */
+{
+ t_pd g_pd; /* pure datum header (class) */
+ struct _gobj *g_next; /* next in list */
+} t_gobj;
+
+typedef struct _scalar /* a graphical object holding data */
+{
+ t_gobj sc_gobj; /* header for graphical object */
+ t_symbol *sc_template; /* template name (LATER replace with pointer) */
+ t_word sc_vec[1]; /* indeterminate-length array of words */
+} t_scalar;
+
+typedef struct _text /* patchable object - graphical, with text */
+{
+ t_gobj te_g; /* header for graphical object */
+ t_binbuf *te_binbuf; /* holder for the text */
+ t_outlet *te_outlet; /* linked list of outlets */
+ t_inlet *te_inlet; /* linked list of inlets */
+ short te_xpix; /* x&y location (within the toplevel) */
+ short te_ypix;
+ short te_width; /* requested width in chars, 0 if auto */
+ unsigned int te_type:2; /* from defs below */
+} t_text;
+
+#define T_TEXT 0 /* just a textual comment */
+#define T_OBJECT 1 /* a MAX style patchable object */
+#define T_MESSAGE 2 /* a MAX stype message */
+#define T_ATOM 3 /* a cell to display a number or symbol */
+
+#define te_pd te_g.g_pd
+
+ /* t_object is synonym for t_text (LATER unify them) */
+
+typedef struct _text t_object;
+
+#define ob_outlet te_outlet
+#define ob_inlet te_inlet
+#define ob_binbuf te_binbuf
+#define ob_pd te_g.g_pd
+#define ob_g te_g
+
+typedef void (*t_method)(void);
+typedef void *(*t_newmethod)( void);
+typedef void (*t_gotfn)(void *x, ...);
+
+/* ---------------- pre-defined objects and symbols --------------*/
+EXTERN t_pd pd_objectmaker; /* factory for creating "object" boxes */
+EXTERN t_pd pd_canvasmaker; /* factory for creating canvases */
+EXTERN t_symbol s_pointer;
+EXTERN t_symbol s_float;
+EXTERN t_symbol s_symbol;
+EXTERN t_symbol s_bang;
+EXTERN t_symbol s_list;
+EXTERN t_symbol s_anything;
+EXTERN t_symbol s_signal;
+EXTERN t_symbol s__N;
+EXTERN t_symbol s__X;
+EXTERN t_symbol s_x;
+EXTERN t_symbol s_y;
+EXTERN t_symbol s_;
+
+/* --------- prototypes from the central message system ----------- */
+EXTERN void pd_typedmess(t_pd *x, t_symbol *s, int argc, t_atom *argv);
+EXTERN void pd_forwardmess(t_pd *x, int argc, t_atom *argv);
+EXTERN t_symbol *gensym(char *s);
+EXTERN t_gotfn getfn(t_pd *x, t_symbol *s);
+EXTERN t_gotfn zgetfn(t_pd *x, t_symbol *s);
+EXTERN void nullfn(void);
+EXTERN void pd_vmess(t_pd *x, t_symbol *s, char *fmt, ...);
+#define mess0(x, s) ((*getfn((x), (s)))((x)))
+#define mess1(x, s, a) ((*getfn((x), (s)))((x), (a)))
+#define mess2(x, s, a,b) ((*getfn((x), (s)))((x), (a),(b)))
+#define mess3(x, s, a,b,c) ((*getfn((x), (s)))((x), (a),(b),(c)))
+#define mess4(x, s, a,b,c,d) ((*getfn((x), (s)))((x), (a),(b),(c),(d)))
+#define mess5(x, s, a,b,c,d,e) ((*getfn((x), (s)))((x), (a),(b),(c),(d),(e)))
+EXTERN void obj_list(t_object *x, t_symbol *s, int argc, t_atom *argv);
+EXTERN t_pd *pd_newest(void);
+
+/* --------------- memory management -------------------- */
+EXTERN void *getbytes(size_t nbytes);
+EXTERN void *getzbytes(size_t nbytes);
+EXTERN void *copybytes(void *src, size_t nbytes);
+EXTERN void freebytes(void *x, size_t nbytes);
+EXTERN void *resizebytes(void *x, size_t oldsize, size_t newsize);
+
+/* -------------------- atoms ----------------------------- */
+
+#define SETSEMI(atom) ((atom)->a_type = A_SEMI, (atom)->a_w.w_index = 0)
+#define SETCOMMA(atom) ((atom)->a_type = A_COMMA, (atom)->a_w.w_index = 0)
+#define SETPOINTER(atom, gp) ((atom)->a_type = A_POINTER, \
+ (atom)->a_w.w_gpointer = (gp))
+#define SETFLOAT(atom, f) ((atom)->a_type = A_FLOAT, (atom)->a_w.w_float = (f))
+#define SETSYMBOL(atom, s) ((atom)->a_type = A_SYMBOL, \
+ (atom)->a_w.w_symbol = (s))
+#define SETDOLLAR(atom, n) ((atom)->a_type = A_DOLLAR, \
+ (atom)->a_w.w_index = (n))
+#define SETDOLLSYM(atom, s) ((atom)->a_type = A_DOLLSYM, \
+ (atom)->a_w.w_symbol= (s))
+
+EXTERN t_float atom_getfloat(t_atom *a);
+EXTERN t_int atom_getint(t_atom *a);
+EXTERN t_symbol *atom_getsymbol(t_atom *a);
+EXTERN t_symbol *atom_gensym(t_atom *a);
+EXTERN t_float atom_getfloatarg(int which, int argc, t_atom *argv);
+EXTERN t_int atom_getintarg(int which, int argc, t_atom *argv);
+EXTERN t_symbol *atom_getsymbolarg(int which, int argc, t_atom *argv);
+
+EXTERN void atom_string(t_atom *a, char *buf, unsigned int bufsize);
+
+/* ------------------ binbufs --------------- */
+
+EXTERN t_binbuf *binbuf_new(void);
+EXTERN void binbuf_free(t_binbuf *x);
+EXTERN t_binbuf *binbuf_duplicate(t_binbuf *y);
+
+EXTERN void binbuf_text(t_binbuf *x, char *text, size_t size);
+EXTERN void binbuf_gettext(t_binbuf *x, char **bufp, int *lengthp);
+EXTERN void binbuf_clear(t_binbuf *x);
+EXTERN void binbuf_add(t_binbuf *x, int argc, t_atom *argv);
+EXTERN void binbuf_addv(t_binbuf *x, char *fmt, ...);
+EXTERN void binbuf_addbinbuf(t_binbuf *x, t_binbuf *y);
+EXTERN void binbuf_addsemi(t_binbuf *x);
+EXTERN void binbuf_restore(t_binbuf *x, int argc, t_atom *argv);
+EXTERN void binbuf_print(t_binbuf *x);
+EXTERN int binbuf_getnatom(t_binbuf *x);
+EXTERN t_atom *binbuf_getvec(t_binbuf *x);
+EXTERN void binbuf_eval(t_binbuf *x, t_pd *target, int argc, t_atom *argv);
+EXTERN int binbuf_read(t_binbuf *b, char *filename, char *dirname,
+ int crflag);
+EXTERN int binbuf_read_via_path(t_binbuf *b, char *filename, char *dirname,
+ int crflag);
+EXTERN int binbuf_write(t_binbuf *x, char *filename, char *dir,
+ int crflag);
+EXTERN void binbuf_evalfile(t_symbol *name, t_symbol *dir);
+EXTERN t_symbol *binbuf_realizedollsym(t_symbol *s, int ac, t_atom *av,
+ int tonew);
+
+/* ------------------ clocks --------------- */
+
+typedef long long t_time;
+EXTERN t_clock *clock_new(void *owner, t_method fn);
+EXTERN void clock_set(t_clock *x, t_time systime);
+EXTERN void clock_delay(t_clock *x, t_time delaytime);
+EXTERN void clock_unset(t_clock *x);
+EXTERN t_time clock_getlogicaltime(void);
+EXTERN t_time clock_getsystime(void); /* OBSOLETE; use clock_getlogicaltime() */
+EXTERN t_time clock_gettimesince(t_time prevsystime);
+EXTERN t_time clock_getsystimeafter(t_time delaytime);
+EXTERN void clock_free(t_clock *x);
+
+/* ----------------- pure data ---------------- */
+EXTERN t_pd *pd_new(t_class *cls);
+EXTERN void pd_free(t_pd *x);
+EXTERN void pd_bind(t_pd *x, t_symbol *s);
+EXTERN void pd_unbind(t_pd *x, t_symbol *s);
+EXTERN t_pd *pd_findbyclass(t_symbol *s, t_class *c);
+EXTERN void pd_pushsym(t_pd *x);
+EXTERN void pd_popsym(t_pd *x);
+EXTERN t_symbol *pd_getfilename(void);
+EXTERN t_symbol *pd_getdirname(void);
+EXTERN void pd_bang(t_pd *x);
+EXTERN void pd_pointer(t_pd *x, t_gpointer *gp);
+EXTERN void pd_float(t_pd *x, t_float f);
+EXTERN void pd_symbol(t_pd *x, t_symbol *s);
+EXTERN void pd_list(t_pd *x, t_symbol *s, int argc, t_atom *argv);
+EXTERN void pd_anything(t_pd *x, t_symbol *s, int argc, t_atom *argv);
+#define pd_class(x) (*(x))
+
+/* ----------------- pointers ---------------- */
+EXTERN void gpointer_init(t_gpointer *gp);
+EXTERN void gpointer_copy(const t_gpointer *gpfrom, t_gpointer *gpto);
+EXTERN void gpointer_unset(t_gpointer *gp);
+EXTERN int gpointer_check(const t_gpointer *gp, int headok);
+
+/* ----------------- patchable "objects" -------------- */
+EXTERN_STRUCT _inlet;
+#define t_inlet struct _inlet
+EXTERN_STRUCT _outlet;
+#define t_outlet struct _outlet
+
+EXTERN t_inlet *inlet_new(t_object *owner, t_pd *dest, t_symbol *s1,
+ t_symbol *s2);
+EXTERN t_inlet *pointerinlet_new(t_object *owner, t_gpointer *gp);
+EXTERN t_inlet *floatinlet_new(t_object *owner, t_float *fp);
+EXTERN t_inlet *symbolinlet_new(t_object *owner, t_symbol **sp);
+EXTERN void inlet_free(t_inlet *x);
+
+EXTERN t_outlet *outlet_new(t_object *owner, t_symbol *s);
+EXTERN void outlet_bang(t_outlet *x);
+EXTERN void outlet_pointer(t_outlet *x, t_gpointer *gp);
+EXTERN void outlet_float(t_outlet *x, t_float f);
+EXTERN void outlet_symbol(t_outlet *x, t_symbol *s);
+EXTERN void outlet_list(t_outlet *x, t_symbol *s, int argc, t_atom *argv);
+EXTERN void outlet_anything(t_outlet *x, t_symbol *s, int argc, t_atom *argv);
+EXTERN t_symbol *outlet_getsymbol(t_outlet *x);
+EXTERN void outlet_free(t_outlet *x);
+EXTERN t_object *pd_checkobject(t_pd *x);
+
+
+/* -------------------- canvases -------------- */
+
+EXTERN void glob_setfilename(void *dummy, t_symbol *name, t_symbol *dir);
+
+EXTERN void canvas_setargs(int argc, t_atom *argv);
+EXTERN void canvas_getargs(int *argcp, t_atom **argvp);
+EXTERN t_symbol *canvas_getcurrentdir(void);
+EXTERN t_glist *canvas_getcurrent(void);
+EXTERN void canvas_makefilename(t_glist *c, char *file,
+ char *result,int resultsize);
+EXTERN t_symbol *canvas_getdir(t_glist *x);
+EXTERN int sys_fontwidth(int fontsize);
+EXTERN int sys_fontheight(int fontsize);
+EXTERN void canvas_dataproperties(t_glist *x, t_scalar *sc, t_binbuf *b);
+
+/* ---------------- widget behaviors ---------------------- */
+
+EXTERN_STRUCT _widgetbehavior;
+#define t_widgetbehavior struct _widgetbehavior
+
+EXTERN_STRUCT _parentwidgetbehavior;
+#define t_parentwidgetbehavior struct _parentwidgetbehavior
+EXTERN t_parentwidgetbehavior *pd_getparentwidget(t_pd *x);
+
+/* -------------------- classes -------------- */
+
+#define CLASS_DEFAULT 0 /* flags for new classes below */
+#define CLASS_PD 1
+#define CLASS_GOBJ 2
+#define CLASS_PATCHABLE 3
+#define CLASS_NOINLET 8
+
+#define CLASS_TYPEMASK 3
+
+
+EXTERN t_class *class_new(t_symbol *name, t_newmethod newmethod,
+ t_method freemethod, size_t size, int flags, t_atomtype arg1, ...);
+EXTERN void class_addcreator(t_newmethod newmethod, t_symbol *s,
+ t_atomtype type1, ...);
+EXTERN void class_addmethod(t_class *c, t_method fn, t_symbol *sel,
+ t_atomtype arg1, ...);
+EXTERN void class_addbang(t_class *c, t_method fn);
+EXTERN void class_addpointer(t_class *c, t_method fn);
+EXTERN void class_doaddfloat(t_class *c, t_method fn);
+EXTERN void class_addsymbol(t_class *c, t_method fn);
+EXTERN void class_addlist(t_class *c, t_method fn);
+EXTERN void class_addanything(t_class *c, t_method fn);
+EXTERN void class_sethelpsymbol(t_class *c, t_symbol *s);
+EXTERN void class_setwidget(t_class *c, t_widgetbehavior *w);
+EXTERN void class_setparentwidget(t_class *c, t_parentwidgetbehavior *w);
+EXTERN t_parentwidgetbehavior *class_parentwidget(t_class *c);
+EXTERN char *class_getname(t_class *c);
+EXTERN char *class_gethelpname(t_class *c);
+EXTERN void class_setdrawcommand(t_class *c);
+EXTERN int class_isdrawcommand(t_class *c);
+EXTERN void class_domainsignalin(t_class *c, int onset);
+#define CLASS_MAINSIGNALIN(c, type, field) \
+ class_domainsignalin(c, (char *)(&((type *)0)->field) - (char *)0)
+
+ /* prototype for functions to save Pd's to a binbuf */
+typedef void (*t_savefn)(t_gobj *x, t_binbuf *b);
+EXTERN void class_setsavefn(t_class *c, t_savefn f);
+EXTERN t_savefn class_getsavefn(t_class *c);
+ /* prototype for functions to open properties dialogs */
+typedef void (*t_propertiesfn)(t_gobj *x, struct _glist *glist);
+EXTERN void class_setpropertiesfn(t_class *c, t_propertiesfn f);
+EXTERN t_propertiesfn class_getpropertiesfn(t_class *c);
+
+#ifndef PD_CLASS_DEF
+#define class_addbang(x, y) class_addbang((x), (t_method)(y))
+#define class_addpointer(x, y) class_addpointer((x), (t_method)(y))
+#define class_addfloat(x, y) class_doaddfloat((x), (t_method)(y))
+#define class_addsymbol(x, y) class_addsymbol((x), (t_method)(y))
+#define class_addlist(x, y) class_addlist((x), (t_method)(y))
+#define class_addanything(x, y) class_addanything((x), (t_method)(y))
+#endif
+
+/* ------------ printing --------------------------------- */
+EXTERN void post(char *fmt, ...);
+EXTERN void startpost(char *fmt, ...);
+EXTERN void poststring(char *s);
+EXTERN void postfloat(float f);
+EXTERN void postatom(int argc, t_atom *argv);
+EXTERN void endpost(void);
+EXTERN void error(char *fmt, ...);
+EXTERN void bug(char *fmt, ...);
+EXTERN void pd_error(void *object, char *fmt, ...);
+EXTERN void sys_logerror(char *object, char *s);
+EXTERN void sys_unixerror(char *object);
+EXTERN void sys_ouch(void);
+
+#ifdef __linux__
+EXTERN char* sys_get_path( void);
+#endif
+EXTERN void sys_addpath(const char* p);
+
+
+/* ------------ system interface routines ------------------- */
+EXTERN int sys_isreadablefile(const char *name);
+EXTERN void sys_bashfilename(const char *from, char *to);
+EXTERN void sys_unbashfilename(const char *from, char *to);
+EXTERN int open_via_path(const char *name, const char *ext, const char *dir,
+ char *dirresult, char **nameresult, unsigned int size, int bin);
+EXTERN int sched_geteventno(void);
+EXTERN double sys_getrealtime(void);
+
+
+/* ------------ threading ------------------- */
+/* T.Grill - see m_sched.c */
+
+EXTERN void sys_lock(void);
+EXTERN void sys_unlock(void);
+EXTERN int sys_trylock(void);
+
+
+/* --------------- signals ----------------------------------- */
+
+#define MAXLOGSIG 32
+#define MAXSIGSIZE (1 << MAXLOGSIG)
+#ifndef FIXEDPOINT
+typedef float t_sample;
+#else
+#include "m_fixed.h"
+#endif
+
+
+typedef struct _signal
+{
+ int s_n; /* number of points in the array */
+ t_sample *s_vec; /* the array */
+ float s_sr; /* sample rate */
+ int s_refcount; /* number of times used */
+ int s_isborrowed; /* whether we're going to borrow our array */
+ struct _signal *s_borrowedfrom; /* signal to borrow it from */
+ struct _signal *s_nextfree; /* next in freelist */
+ struct _signal *s_nextused; /* next in used list */
+} t_signal;
+
+
+typedef t_int *(*t_perfroutine)(t_int *args);
+
+EXTERN t_int *plus_perform(t_int *args);
+EXTERN t_int *zero_perform(t_int *args);
+EXTERN t_int *copy_perform(t_int *args);
+
+EXTERN void dsp_add_plus(t_sample *in1, t_sample *in2, t_sample *out, int n);
+EXTERN void dsp_add_copy(t_sample *in, t_sample *out, int n);
+EXTERN void dsp_add_scalarcopy(t_sample *in, t_sample *out, int n);
+EXTERN void dsp_add_zero(t_sample *out, int n);
+
+EXTERN int sys_getblksize(void);
+EXTERN float sys_getsr(void);
+EXTERN int sys_get_inchannels(void);
+EXTERN int sys_get_outchannels(void);
+
+EXTERN void dsp_add(t_perfroutine f, int n, ...);
+EXTERN void dsp_addv(t_perfroutine f, int n, t_int *vec);
+EXTERN void pd_fft(float *buf, int npoints, int inverse);
+EXTERN int ilog2(int n);
+
+EXTERN void mayer_fht(t_sample *fz, int n);
+EXTERN void mayer_fft(int n, t_sample *real, t_sample *imag);
+EXTERN void mayer_ifft(int n, t_sample *real, t_sample *imag);
+EXTERN void mayer_realfft(int n, t_sample *real);
+EXTERN void mayer_realifft(int n, t_sample *real);
+
+EXTERN t_sample *cos_table;
+
+#define LOGCOSTABSIZE 9
+#define COSTABSIZE (1<<LOGCOSTABSIZE)
+
+EXTERN int canvas_suspend_dsp(void);
+EXTERN void canvas_resume_dsp(int oldstate);
+EXTERN void canvas_update_dsp(void);
+
+/* IOhannes { (up/downsampling) */
+typedef struct _resample
+{
+ int method; /* up/downsampling method ID */
+
+ t_int downsample; /* downsampling factor */
+ t_int upsample; /* upsampling factor */
+
+ t_sample *s_vec; /* here we hold the resampled data */
+ int s_n;
+
+ t_sample *coeffs; /* coefficients for filtering... */
+ int coefsize;
+
+ t_sample *buffer; /* buffer for filtering */
+ int bufsize;
+} t_resample;
+
+EXTERN void resample_init(t_resample *x);
+EXTERN void resample_free(t_resample *x);
+
+EXTERN void resample_dsp(t_resample *x, t_sample *in, int insize, t_sample *out, int outsize, int method);
+EXTERN void resamplefrom_dsp(t_resample *x, t_sample *in, int insize, int outsize, int method);
+EXTERN void resampleto_dsp(t_resample *x, t_sample *out, int insize, int outsize, int method);
+/* } IOhannes */
+
+/* ----------------------- utility functions for signals -------------- */
+EXTERN float mtof(float);
+EXTERN float ftom(float);
+EXTERN float rmstodb(float);
+EXTERN float powtodb(float);
+EXTERN float dbtorms(float);
+EXTERN float dbtopow(float);
+
+EXTERN float q8_sqrt(float);
+EXTERN float q8_rsqrt(float);
+#ifndef N32
+EXTERN float qsqrt(float); /* old names kept for extern compatibility */
+EXTERN float qrsqrt(float);
+#endif
+/* --------------------- data --------------------------------- */
+
+ /* graphical arrays */
+EXTERN_STRUCT _garray;
+#define t_garray struct _garray
+
+EXTERN t_class *garray_class;
+EXTERN int garray_getfloatarray(t_garray *x, int *size, t_sample **vec);
+EXTERN float garray_get(t_garray *x, t_symbol *s, t_int indx);
+EXTERN void garray_redraw(t_garray *x);
+EXTERN int garray_npoints(t_garray *x);
+EXTERN char *garray_vec(t_garray *x);
+EXTERN void garray_resize(t_garray *x, t_floatarg f);
+EXTERN void garray_usedindsp(t_garray *x);
+EXTERN void garray_setsaveit(t_garray *x, int saveit);
+EXTERN t_class *scalar_class;
+
+EXTERN t_float *value_get(t_symbol *s);
+EXTERN void value_release(t_symbol *s);
+EXTERN int value_getfloat(t_symbol *s, t_float *f);
+EXTERN int value_setfloat(t_symbol *s, t_float f);
+
+/* ------- GUI interface - functions to send strings to TK --------- */
+EXTERN void sys_vgui(char *fmt, ...);
+EXTERN void sys_gui(char *s);
+
+ /* dialog window creation and destruction */
+EXTERN void gfxstub_new(t_pd *owner, void *key, const char *cmd);
+EXTERN void gfxstub_deleteforkey(void *key);
+
+extern t_class *glob_pdobject; /* object to send "pd" messages */
+
+/*------------- Max 0.26 compatibility --------------------*/
+
+/* the following reflects the new way classes are laid out, with the class
+ pointing to the messlist and not vice versa. Externs shouldn't feel it. */
+typedef t_class *t_externclass;
+
+EXTERN void c_extern(t_externclass *cls, t_newmethod newroutine,
+ t_method freeroutine, t_symbol *name, size_t size, int tiny, \
+ t_atomtype arg1, ...);
+EXTERN void c_addmess(t_method fn, t_symbol *sel, t_atomtype arg1, ...);
+
+#define t_getbytes getbytes
+#define t_freebytes freebytes
+#define t_resizebytes resizebytes
+#define typedmess pd_typedmess
+#define vmess pd_vmess
+
+/* A definition to help gui objects straddle 0.34-0.35 changes. If this is
+defined, there is a "te_xpix" field in objects, not a "te_xpos" as before: */
+
+#define PD_USE_TE_XPIX
+
+#if 0
+/* a test for NANs and denormals. Should only be necessary on i386. */
+#define PD_BADFLOAT(f) ((((*(unsigned int*)&(f))&0x7f800000)==0) || \
+ (((*(unsigned int*)&(f))&0x7f800000)==0x7f800000))
+/* more stringent test: anything not between 1e-19 and 1e19 in absolute val */
+#define PD_BIGORSMALL(f) ((((*(unsigned int*)&(f))&0x60000000)==0) || \
+ (((*(unsigned int*)&(f))&0x60000000)==0x60000000))
+#else
+#define PD_BADFLOAT(f) 0
+#define PD_BIGORSMALL(f) 0
+#endif
+
+#if defined(_LANGUAGE_C_PLUS_PLUS) || defined(__cplusplus)
+}
+#endif
+
+#define __m_pd_h_
+#endif /* __m_pd_h_ */
+/* Copyright (c) 1997-1999 Miller Puckette.
+* For information on usage and redistribution, and for a DISCLAIMER OF ALL
+* WARRANTIES, see the file, "LICENSE.txt," in this distribution. */
+
+#ifndef __m_pd_h_
+
+#if defined(_LANGUAGE_C_PLUS_PLUS) || defined(__cplusplus)
+extern "C" {
+#endif
+
+#define PD_VERSION 0.37 /* oops, don't use this... */ */
+#define PD_MAJOR_VERSION 0 /* ... use these two instead. */
+#define PD_MINOR_VERSION 37
+
+/* old name for "MSW" flag -- we have to take it for the sake of many old
+"nmakefiles" for externs, which will define NT and not MSW */
+#if defined(NT) && !defined(MSW)
+#define MSW
+#endif
+
+#ifdef MSW
+// #pragma warning( disable : 4091 )
+#pragma warning( disable : 4305 ) /* uncast const double to float */
+#pragma warning( disable : 4244 ) /* uncast float/int conversion etc. */
+#pragma warning( disable : 4101 ) /* unused automatic variables */
+#endif /* MSW */
+
+ /* the external storage class is "extern" in UNIX; in MSW it's ugly. */
+#ifdef MSW
+#ifdef PD_INTERNAL
+#define EXTERN __declspec(dllexport) extern
+#else
+#define EXTERN __declspec(dllimport) extern
+#endif /* PD_INTERNAL */
+#else
+#define EXTERN extern
+#endif /* MSW */
+
+ /* and depending on the compiler, hidden data structures are
+ declared differently: */
+#if defined( __GNUC__) || defined( __BORLANDC__ ) || defined( __MWERKS__ )
+#define EXTERN_STRUCT struct
+#else
+#define EXTERN_STRUCT extern struct
+#endif
+
+
+#if !defined(_SIZE_T) && !defined(_SIZE_T_)
+#include <stddef.h> /* just for size_t -- how lame! */
+#endif
+
+#define MAXPDSTRING 1000 /* use this for anything you want */
+#define MAXPDARG 5 /* max number of args we can typecheck today */
+
+ /* signed and unsigned integer types the size of a pointer: */
+#ifdef __alpha__
+typedef long t_int;
+#else
+typedef int t_int;
+#endif
+
+typedef float t_float; /* a floating-point number at most the same size */
+typedef float t_floatarg; /* floating-point type for function calls */
+
+typedef struct _symbol
+{
+ char *s_name;
+ struct _class **s_thing;
+ struct _symbol *s_next;
+} t_symbol;
+
+EXTERN_STRUCT _array;
+#define t_array struct _array /* g_canvas.h */
+
+/* pointers to glist and array elements go through a "stub" which sticks
+around after the glist or array is freed. The stub itself is deleted when
+both the glist/array is gone and the refcount is zero, ensuring that no
+gpointers are pointing here. */
+
+#define GP_NONE 0 /* the stub points nowhere (has been cut off) */
+#define GP_GLIST 1 /* the stub points to a glist element */
+#define GP_ARRAY 2 /* ... or array */
+
+typedef struct _gstub
+{
+ union
+ {
+ struct _glist *gs_glist; /* glist we're in */
+ struct _array *gs_array; /* array we're in */
+ } gs_un;
+ int gs_which; /* GP_GLIST/GP_ARRAY */
+ int gs_refcount; /* number of gpointers pointing here */
+} t_gstub;
+
+typedef struct _gpointer /* pointer to a gobj in a glist */
+{
+ union
+ {
+ struct _scalar *gp_scalar; /* scalar we're in (if glist) */
+ union word *gp_w; /* raw data (if array) */
+ } gp_un;
+ int gp_valid; /* number which must match gpointee */
+ t_gstub *gp_stub; /* stub which points to glist/array */
+} t_gpointer;
+
+typedef union word
+{
+ t_float w_float;
+ t_symbol *w_symbol;
+ t_gpointer *w_gpointer;
+ t_array *w_array;
+ struct _glist *w_list;
+ int w_index;
+} t_word;
+
+typedef enum
+{
+ A_NULL,
+ A_FLOAT,
+ A_SYMBOL,
+ A_POINTER,
+ A_SEMI,
+ A_COMMA,
+ A_DEFFLOAT,
+ A_DEFSYM,
+ A_DOLLAR,
+ A_DOLLSYM,
+ A_GIMME,
+ A_CANT
+} t_atomtype;
+
+#define A_DEFSYMBOL A_DEFSYM /* better name for this */
+
+typedef struct _atom
+{
+ t_atomtype a_type;
+ union word a_w;
+} t_atom;
+
+EXTERN_STRUCT _class;
+#define t_class struct _class
+
+EXTERN_STRUCT _outlet;
+#define t_outlet struct _outlet
+
+EXTERN_STRUCT _inlet;
+#define t_inlet struct _inlet
+
+EXTERN_STRUCT _binbuf;
+#define t_binbuf struct _binbuf
+
+EXTERN_STRUCT _clock;
+#define t_clock struct _clock
+
+EXTERN_STRUCT _outconnect;
+#define t_outconnect struct _outconnect
+
+EXTERN_STRUCT _glist;
+#define t_glist struct _glist
+#define t_canvas struct _glist /* LATER lose this */
+
+typedef t_class *t_pd; /* pure datum: nothing but a class pointer */
+
+typedef struct _gobj /* a graphical object */
+{
+ t_pd g_pd; /* pure datum header (class) */
+ struct _gobj *g_next; /* next in list */
+} t_gobj;
+
+typedef struct _scalar /* a graphical object holding data */
+{
+ t_gobj sc_gobj; /* header for graphical object */
+ t_symbol *sc_template; /* template name (LATER replace with pointer) */
+ t_word sc_vec[1]; /* indeterminate-length array of words */
+} t_scalar;
+
+typedef struct _text /* patchable object - graphical, with text */
+{
+ t_gobj te_g; /* header for graphical object */
+ t_binbuf *te_binbuf; /* holder for the text */
+ t_outlet *te_outlet; /* linked list of outlets */
+ t_inlet *te_inlet; /* linked list of inlets */
+ short te_xpix; /* x&y location (within the toplevel) */
+ short te_ypix;
+ short te_width; /* requested width in chars, 0 if auto */
+ unsigned int te_type:2; /* from defs below */
+} t_text;
+
+#define T_TEXT 0 /* just a textual comment */
+#define T_OBJECT 1 /* a MAX style patchable object */
+#define T_MESSAGE 2 /* a MAX stype message */
+#define T_ATOM 3 /* a cell to display a number or symbol */
+
+#define te_pd te_g.g_pd
+
+ /* t_object is synonym for t_text (LATER unify them) */
+
+typedef struct _text t_object;
+
+#define ob_outlet te_outlet
+#define ob_inlet te_inlet
+#define ob_binbuf te_binbuf
+#define ob_pd te_g.g_pd
+#define ob_g te_g
+
+typedef void (*t_method)(void);
+typedef void *(*t_newmethod)( void);
+typedef void (*t_gotfn)(void *x, ...);
+
+/* ---------------- pre-defined objects and symbols --------------*/
+EXTERN t_pd pd_objectmaker; /* factory for creating "object" boxes */
+EXTERN t_pd pd_canvasmaker; /* factory for creating canvases */
+EXTERN t_symbol s_pointer;
+EXTERN t_symbol s_float;
+EXTERN t_symbol s_symbol;
+EXTERN t_symbol s_bang;
+EXTERN t_symbol s_list;
+EXTERN t_symbol s_anything;
+EXTERN t_symbol s_signal;
+EXTERN t_symbol s__N;
+EXTERN t_symbol s__X;
+EXTERN t_symbol s_x;
+EXTERN t_symbol s_y;
+EXTERN t_symbol s_;
+
+/* --------- prototypes from the central message system ----------- */
+EXTERN void pd_typedmess(t_pd *x, t_symbol *s, int argc, t_atom *argv);
+EXTERN void pd_forwardmess(t_pd *x, int argc, t_atom *argv);
+EXTERN t_symbol *gensym(char *s);
+EXTERN t_gotfn getfn(t_pd *x, t_symbol *s);
+EXTERN t_gotfn zgetfn(t_pd *x, t_symbol *s);
+EXTERN void nullfn(void);
+EXTERN void pd_vmess(t_pd *x, t_symbol *s, char *fmt, ...);
+#define mess0(x, s) ((*getfn((x), (s)))((x)))
+#define mess1(x, s, a) ((*getfn((x), (s)))((x), (a)))
+#define mess2(x, s, a,b) ((*getfn((x), (s)))((x), (a),(b)))
+#define mess3(x, s, a,b,c) ((*getfn((x), (s)))((x), (a),(b),(c)))
+#define mess4(x, s, a,b,c,d) ((*getfn((x), (s)))((x), (a),(b),(c),(d)))
+#define mess5(x, s, a,b,c,d,e) ((*getfn((x), (s)))((x), (a),(b),(c),(d),(e)))
+EXTERN void obj_list(t_object *x, t_symbol *s, int argc, t_atom *argv);
+EXTERN t_pd *pd_newest(void);
+
+/* --------------- memory management -------------------- */
+EXTERN void *getbytes(size_t nbytes);
+EXTERN void *getzbytes(size_t nbytes);
+EXTERN void *copybytes(void *src, size_t nbytes);
+EXTERN void freebytes(void *x, size_t nbytes);
+EXTERN void *resizebytes(void *x, size_t oldsize, size_t newsize);
+
+/* -------------------- atoms ----------------------------- */
+
+#define SETSEMI(atom) ((atom)->a_type = A_SEMI, (atom)->a_w.w_index = 0)
+#define SETCOMMA(atom) ((atom)->a_type = A_COMMA, (atom)->a_w.w_index = 0)
+#define SETPOINTER(atom, gp) ((atom)->a_type = A_POINTER, \
+ (atom)->a_w.w_gpointer = (gp))
+#define SETFLOAT(atom, f) ((atom)->a_type = A_FLOAT, (atom)->a_w.w_float = (f))
+#define SETSYMBOL(atom, s) ((atom)->a_type = A_SYMBOL, \
+ (atom)->a_w.w_symbol = (s))
+#define SETDOLLAR(atom, n) ((atom)->a_type = A_DOLLAR, \
+ (atom)->a_w.w_index = (n))
+#define SETDOLLSYM(atom, s) ((atom)->a_type = A_DOLLSYM, \
+ (atom)->a_w.w_symbol= (s))
+
+EXTERN t_float atom_getfloat(t_atom *a);
+EXTERN t_int atom_getint(t_atom *a);
+EXTERN t_symbol *atom_getsymbol(t_atom *a);
+EXTERN t_symbol *atom_gensym(t_atom *a);
+EXTERN t_float atom_getfloatarg(int which, int argc, t_atom *argv);
+EXTERN t_int atom_getintarg(int which, int argc, t_atom *argv);
+EXTERN t_symbol *atom_getsymbolarg(int which, int argc, t_atom *argv);
+
+EXTERN void atom_string(t_atom *a, char *buf, unsigned int bufsize);
+
+/* ------------------ binbufs --------------- */
+
+EXTERN t_binbuf *binbuf_new(void);
+EXTERN void binbuf_free(t_binbuf *x);
+EXTERN t_binbuf *binbuf_duplicate(t_binbuf *y);
+
+EXTERN void binbuf_text(t_binbuf *x, char *text, size_t size);
+EXTERN void binbuf_gettext(t_binbuf *x, char **bufp, int *lengthp);
+EXTERN void binbuf_clear(t_binbuf *x);
+EXTERN void binbuf_add(t_binbuf *x, int argc, t_atom *argv);
+EXTERN void binbuf_addv(t_binbuf *x, char *fmt, ...);
+EXTERN void binbuf_addbinbuf(t_binbuf *x, t_binbuf *y);
+EXTERN void binbuf_addsemi(t_binbuf *x);
+EXTERN void binbuf_restore(t_binbuf *x, int argc, t_atom *argv);
+EXTERN void binbuf_print(t_binbuf *x);
+EXTERN int binbuf_getnatom(t_binbuf *x);
+EXTERN t_atom *binbuf_getvec(t_binbuf *x);
+EXTERN void binbuf_eval(t_binbuf *x, t_pd *target, int argc, t_atom *argv);
+EXTERN int binbuf_read(t_binbuf *b, char *filename, char *dirname,
+ int crflag);
+EXTERN int binbuf_read_via_path(t_binbuf *b, char *filename, char *dirname,
+ int crflag);
+EXTERN int binbuf_write(t_binbuf *x, char *filename, char *dir,
+ int crflag);
+EXTERN void binbuf_evalfile(t_symbol *name, t_symbol *dir);
+EXTERN t_symbol *binbuf_realizedollsym(t_symbol *s, int ac, t_atom *av,
+ int tonew);
+
+/* ------------------ clocks --------------- */
+
+typedef long long t_time;
+EXTERN t_clock *clock_new(void *owner, t_method fn);
+EXTERN void clock_set(t_clock *x, t_time systime);
+EXTERN void clock_delay(t_clock *x, t_time delaytime);
+EXTERN void clock_unset(t_clock *x);
+EXTERN t_time clock_getlogicaltime(void);
+EXTERN t_time clock_getsystime(void); /* OBSOLETE; use clock_getlogicaltime() */
+EXTERN t_time clock_gettimesince(t_time prevsystime);
+EXTERN t_time clock_getsystimeafter(t_time delaytime);
+EXTERN void clock_free(t_clock *x);
+
+/* ----------------- pure data ---------------- */
+EXTERN t_pd *pd_new(t_class *cls);
+EXTERN void pd_free(t_pd *x);
+EXTERN void pd_bind(t_pd *x, t_symbol *s);
+EXTERN void pd_unbind(t_pd *x, t_symbol *s);
+EXTERN t_pd *pd_findbyclass(t_symbol *s, t_class *c);
+EXTERN void pd_pushsym(t_pd *x);
+EXTERN void pd_popsym(t_pd *x);
+EXTERN t_symbol *pd_getfilename(void);
+EXTERN t_symbol *pd_getdirname(void);
+EXTERN void pd_bang(t_pd *x);
+EXTERN void pd_pointer(t_pd *x, t_gpointer *gp);
+EXTERN void pd_float(t_pd *x, t_float f);
+EXTERN void pd_symbol(t_pd *x, t_symbol *s);
+EXTERN void pd_list(t_pd *x, t_symbol *s, int argc, t_atom *argv);
+EXTERN void pd_anything(t_pd *x, t_symbol *s, int argc, t_atom *argv);
+#define pd_class(x) (*(x))
+
+/* ----------------- pointers ---------------- */
+EXTERN void gpointer_init(t_gpointer *gp);
+EXTERN void gpointer_copy(const t_gpointer *gpfrom, t_gpointer *gpto);
+EXTERN void gpointer_unset(t_gpointer *gp);
+EXTERN int gpointer_check(const t_gpointer *gp, int headok);
+
+/* ----------------- patchable "objects" -------------- */
+EXTERN_STRUCT _inlet;
+#define t_inlet struct _inlet
+EXTERN_STRUCT _outlet;
+#define t_outlet struct _outlet
+
+EXTERN t_inlet *inlet_new(t_object *owner, t_pd *dest, t_symbol *s1,
+ t_symbol *s2);
+EXTERN t_inlet *pointerinlet_new(t_object *owner, t_gpointer *gp);
+EXTERN t_inlet *floatinlet_new(t_object *owner, t_float *fp);
+EXTERN t_inlet *symbolinlet_new(t_object *owner, t_symbol **sp);
+EXTERN void inlet_free(t_inlet *x);
+
+EXTERN t_outlet *outlet_new(t_object *owner, t_symbol *s);
+EXTERN void outlet_bang(t_outlet *x);
+EXTERN void outlet_pointer(t_outlet *x, t_gpointer *gp);
+EXTERN void outlet_float(t_outlet *x, t_float f);
+EXTERN void outlet_symbol(t_outlet *x, t_symbol *s);
+EXTERN void outlet_list(t_outlet *x, t_symbol *s, int argc, t_atom *argv);
+EXTERN void outlet_anything(t_outlet *x, t_symbol *s, int argc, t_atom *argv);
+EXTERN t_symbol *outlet_getsymbol(t_outlet *x);
+EXTERN void outlet_free(t_outlet *x);
+EXTERN t_object *pd_checkobject(t_pd *x);
+
+
+/* -------------------- canvases -------------- */
+
+EXTERN void glob_setfilename(void *dummy, t_symbol *name, t_symbol *dir);
+
+EXTERN void canvas_setargs(int argc, t_atom *argv);
+EXTERN void canvas_getargs(int *argcp, t_atom **argvp);
+EXTERN t_symbol *canvas_getcurrentdir(void);
+EXTERN t_glist *canvas_getcurrent(void);
+EXTERN void canvas_makefilename(t_glist *c, char *file,
+ char *result,int resultsize);
+EXTERN t_symbol *canvas_getdir(t_glist *x);
+EXTERN int sys_fontwidth(int fontsize);
+EXTERN int sys_fontheight(int fontsize);
+EXTERN void canvas_dataproperties(t_glist *x, t_scalar *sc, t_binbuf *b);
+
+/* ---------------- widget behaviors ---------------------- */
+
+EXTERN_STRUCT _widgetbehavior;
+#define t_widgetbehavior struct _widgetbehavior
+
+EXTERN_STRUCT _parentwidgetbehavior;
+#define t_parentwidgetbehavior struct _parentwidgetbehavior
+EXTERN t_parentwidgetbehavior *pd_getparentwidget(t_pd *x);
+
+/* -------------------- classes -------------- */
+
+#define CLASS_DEFAULT 0 /* flags for new classes below */
+#define CLASS_PD 1
+#define CLASS_GOBJ 2
+#define CLASS_PATCHABLE 3
+#define CLASS_NOINLET 8
+
+#define CLASS_TYPEMASK 3
+
+
+EXTERN t_class *class_new(t_symbol *name, t_newmethod newmethod,
+ t_method freemethod, size_t size, int flags, t_atomtype arg1, ...);
+EXTERN void class_addcreator(t_newmethod newmethod, t_symbol *s,
+ t_atomtype type1, ...);
+EXTERN void class_addmethod(t_class *c, t_method fn, t_symbol *sel,
+ t_atomtype arg1, ...);
+EXTERN void class_addbang(t_class *c, t_method fn);
+EXTERN void class_addpointer(t_class *c, t_method fn);
+EXTERN void class_doaddfloat(t_class *c, t_method fn);
+EXTERN void class_addsymbol(t_class *c, t_method fn);
+EXTERN void class_addlist(t_class *c, t_method fn);
+EXTERN void class_addanything(t_class *c, t_method fn);
+EXTERN void class_sethelpsymbol(t_class *c, t_symbol *s);
+EXTERN void class_setwidget(t_class *c, t_widgetbehavior *w);
+EXTERN void class_setparentwidget(t_class *c, t_parentwidgetbehavior *w);
+EXTERN t_parentwidgetbehavior *class_parentwidget(t_class *c);
+EXTERN char *class_getname(t_class *c);
+EXTERN char *class_gethelpname(t_class *c);
+EXTERN void class_setdrawcommand(t_class *c);
+EXTERN int class_isdrawcommand(t_class *c);
+EXTERN void class_domainsignalin(t_class *c, int onset);
+#define CLASS_MAINSIGNALIN(c, type, field) \
+ class_domainsignalin(c, (char *)(&((type *)0)->field) - (char *)0)
+
+ /* prototype for functions to save Pd's to a binbuf */
+typedef void (*t_savefn)(t_gobj *x, t_binbuf *b);
+EXTERN void class_setsavefn(t_class *c, t_savefn f);
+EXTERN t_savefn class_getsavefn(t_class *c);
+ /* prototype for functions to open properties dialogs */
+typedef void (*t_propertiesfn)(t_gobj *x, struct _glist *glist);
+EXTERN void class_setpropertiesfn(t_class *c, t_propertiesfn f);
+EXTERN t_propertiesfn class_getpropertiesfn(t_class *c);
+
+#ifndef PD_CLASS_DEF
+#define class_addbang(x, y) class_addbang((x), (t_method)(y))
+#define class_addpointer(x, y) class_addpointer((x), (t_method)(y))
+#define class_addfloat(x, y) class_doaddfloat((x), (t_method)(y))
+#define class_addsymbol(x, y) class_addsymbol((x), (t_method)(y))
+#define class_addlist(x, y) class_addlist((x), (t_method)(y))
+#define class_addanything(x, y) class_addanything((x), (t_method)(y))
+#endif
+
+/* ------------ printing --------------------------------- */
+EXTERN void post(char *fmt, ...);
+EXTERN void startpost(char *fmt, ...);
+EXTERN void poststring(char *s);
+EXTERN void postfloat(float f);
+EXTERN void postatom(int argc, t_atom *argv);
+EXTERN void endpost(void);
+EXTERN void error(char *fmt, ...);
+EXTERN void bug(char *fmt, ...);
+EXTERN void pd_error(void *object, char *fmt, ...);
+EXTERN void sys_logerror(char *object, char *s);
+EXTERN void sys_unixerror(char *object);
+EXTERN void sys_ouch(void);
+
+#ifdef __linux__
+EXTERN char* sys_get_path( void);
+#endif
+EXTERN void sys_addpath(const char* p);
+
+
+/* ------------ system interface routines ------------------- */
+EXTERN int sys_isreadablefile(const char *name);
+EXTERN void sys_bashfilename(const char *from, char *to);
+EXTERN void sys_unbashfilename(const char *from, char *to);
+EXTERN int open_via_path(const char *name, const char *ext, const char *dir,
+ char *dirresult, char **nameresult, unsigned int size, int bin);
+EXTERN int sched_geteventno(void);
+EXTERN double sys_getrealtime(void);
+
+
+/* ------------ threading ------------------- */
+/* T.Grill - see m_sched.c */
+
+EXTERN void sys_lock(void);
+EXTERN void sys_unlock(void);
+EXTERN int sys_trylock(void);
+
+
+/* --------------- signals ----------------------------------- */
+
+#define MAXLOGSIG 32
+#define MAXSIGSIZE (1 << MAXLOGSIG)
+#ifndef FIXEDPOINT
+typedef float t_sample;
+#else
+#include "m_fixed.h"
+#endif
+
+
+typedef struct _signal
+{
+ int s_n; /* number of points in the array */
+ t_sample *s_vec; /* the array */
+ float s_sr; /* sample rate */
+ int s_refcount; /* number of times used */
+ int s_isborrowed; /* whether we're going to borrow our array */
+ struct _signal *s_borrowedfrom; /* signal to borrow it from */
+ struct _signal *s_nextfree; /* next in freelist */
+ struct _signal *s_nextused; /* next in used list */
+} t_signal;
+
+
+typedef t_int *(*t_perfroutine)(t_int *args);
+
+EXTERN t_int *plus_perform(t_int *args);
+EXTERN t_int *zero_perform(t_int *args);
+EXTERN t_int *copy_perform(t_int *args);
+
+EXTERN void dsp_add_plus(t_sample *in1, t_sample *in2, t_sample *out, int n);
+EXTERN void dsp_add_copy(t_sample *in, t_sample *out, int n);
+EXTERN void dsp_add_scalarcopy(t_sample *in, t_sample *out, int n);
+EXTERN void dsp_add_zero(t_sample *out, int n);
+
+EXTERN int sys_getblksize(void);
+EXTERN float sys_getsr(void);
+EXTERN int sys_get_inchannels(void);
+EXTERN int sys_get_outchannels(void);
+
+EXTERN void dsp_add(t_perfroutine f, int n, ...);
+EXTERN void dsp_addv(t_perfroutine f, int n, t_int *vec);
+EXTERN void pd_fft(float *buf, int npoints, int inverse);
+EXTERN int ilog2(int n);
+
+EXTERN void mayer_fht(t_sample *fz, int n);
+EXTERN void mayer_fft(int n, t_sample *real, t_sample *imag);
+EXTERN void mayer_ifft(int n, t_sample *real, t_sample *imag);
+EXTERN void mayer_realfft(int n, t_sample *real);
+EXTERN void mayer_realifft(int n, t_sample *real);
+
+EXTERN t_sample *cos_table;
+
+#define LOGCOSTABSIZE 9
+#define COSTABSIZE (1<<LOGCOSTABSIZE)
+
+EXTERN int canvas_suspend_dsp(void);
+EXTERN void canvas_resume_dsp(int oldstate);
+EXTERN void canvas_update_dsp(void);
+
+/* IOhannes { (up/downsampling) */
+typedef struct _resample
+{
+ int method; /* up/downsampling method ID */
+
+ t_int downsample; /* downsampling factor */
+ t_int upsample; /* upsampling factor */
+
+ t_sample *s_vec; /* here we hold the resampled data */
+ int s_n;
+
+ t_sample *coeffs; /* coefficients for filtering... */
+ int coefsize;
+
+ t_sample *buffer; /* buffer for filtering */
+ int bufsize;
+} t_resample;
+
+EXTERN void resample_init(t_resample *x);
+EXTERN void resample_free(t_resample *x);
+
+EXTERN void resample_dsp(t_resample *x, t_sample *in, int insize, t_sample *out, int outsize, int method);
+EXTERN void resamplefrom_dsp(t_resample *x, t_sample *in, int insize, int outsize, int method);
+EXTERN void resampleto_dsp(t_resample *x, t_sample *out, int insize, int outsize, int method);
+/* } IOhannes */
+
+/* ----------------------- utility functions for signals -------------- */
+EXTERN float mtof(float);
+EXTERN float ftom(float);
+EXTERN float rmstodb(float);
+EXTERN float powtodb(float);
+EXTERN float dbtorms(float);
+EXTERN float dbtopow(float);
+
+EXTERN float q8_sqrt(float);
+EXTERN float q8_rsqrt(float);
+#ifndef N32
+EXTERN float qsqrt(float); /* old names kept for extern compatibility */
+EXTERN float qrsqrt(float);
+#endif
+/* --------------------- data --------------------------------- */
+
+ /* graphical arrays */
+EXTERN_STRUCT _garray;
+#define t_garray struct _garray
+
+EXTERN t_class *garray_class;
+EXTERN int garray_getfloatarray(t_garray *x, int *size, t_sample **vec);
+EXTERN float garray_get(t_garray *x, t_symbol *s, t_int indx);
+EXTERN void garray_redraw(t_garray *x);
+EXTERN int garray_npoints(t_garray *x);
+EXTERN char *garray_vec(t_garray *x);
+EXTERN void garray_resize(t_garray *x, t_floatarg f);
+EXTERN void garray_usedindsp(t_garray *x);
+EXTERN void garray_setsaveit(t_garray *x, int saveit);
+EXTERN t_class *scalar_class;
+
+EXTERN t_float *value_get(t_symbol *s);
+EXTERN void value_release(t_symbol *s);
+EXTERN int value_getfloat(t_symbol *s, t_float *f);
+EXTERN int value_setfloat(t_symbol *s, t_float f);
+
+/* ------- GUI interface - functions to send strings to TK --------- */
+EXTERN void sys_vgui(char *fmt, ...);
+EXTERN void sys_gui(char *s);
+
+ /* dialog window creation and destruction */
+EXTERN void gfxstub_new(t_pd *owner, void *key, const char *cmd);
+EXTERN void gfxstub_deleteforkey(void *key);
+
+extern t_class *glob_pdobject; /* object to send "pd" messages */
+
+/*------------- Max 0.26 compatibility --------------------*/
+
+/* the following reflects the new way classes are laid out, with the class
+ pointing to the messlist and not vice versa. Externs shouldn't feel it. */
+typedef t_class *t_externclass;
+
+EXTERN void c_extern(t_externclass *cls, t_newmethod newroutine,
+ t_method freeroutine, t_symbol *name, size_t size, int tiny, \
+ t_atomtype arg1, ...);
+EXTERN void c_addmess(t_method fn, t_symbol *sel, t_atomtype arg1, ...);
+
+#define t_getbytes getbytes
+#define t_freebytes freebytes
+#define t_resizebytes resizebytes
+#define typedmess pd_typedmess
+#define vmess pd_vmess
+
+/* A definition to help gui objects straddle 0.34-0.35 changes. If this is
+defined, there is a "te_xpix" field in objects, not a "te_xpos" as before: */
+
+#define PD_USE_TE_XPIX
+
+#if 0
+/* a test for NANs and denormals. Should only be necessary on i386. */
+#define PD_BADFLOAT(f) ((((*(unsigned int*)&(f))&0x7f800000)==0) || \
+ (((*(unsigned int*)&(f))&0x7f800000)==0x7f800000))
+/* more stringent test: anything not between 1e-19 and 1e19 in absolute val */
+#define PD_BIGORSMALL(f) ((((*(unsigned int*)&(f))&0x60000000)==0) || \
+ (((*(unsigned int*)&(f))&0x60000000)==0x60000000))
+#else
+#define PD_BADFLOAT(f) 0
+#define PD_BIGORSMALL(f) 0
+#endif
+
+#if defined(_LANGUAGE_C_PLUS_PLUS) || defined(__cplusplus)
+}
+#endif
+
+#define __m_pd_h_
+#endif /* __m_pd_h_ */
diff --git a/apps/plugins/pdbox/PDa/extra/makefile b/apps/plugins/pdbox/PDa/extra/makefile
new file mode 100644
index 0000000000..270491de63
--- /dev/null
+++ b/apps/plugins/pdbox/PDa/extra/makefile
@@ -0,0 +1,66 @@
+
+VERSION = 0.2
+SOURCE = $(shell ls *.c)
+TARGETS = $(SOURCE:.c=.pd_linux)
+
+EXT= pd_linux
+
+AFLAGS = -g -O2 -I./ -DFIXEDPOINT
+EFLAGS = -shared -Wl,-export-dynamic
+PREFIX = /usr
+
+
+all: $(TARGETS)
+
+clean:
+ -rm $(TARGETS)
+ -rm *.o *~
+
+tar: clean
+ cd ..;tar czvf PDa-externals-$(VERSION).tgz PDa-externals
+
+upload: tar
+ scp ../PDa-externals-$(VERSION).tgz gige@xdv.org:~/www/pda/release
+
+install:
+ install -d $(DESTDIR)/$(PREFIX)/lib/pd/extra
+ cp $(TARGETS) $(DESTDIR)/$(PREFIX)/lib/pd/extra
+
+%.$(EXT) : %.o
+ $(CC) -o $@ $(EFLAGS) $+
+
+%.o : %.c
+ $(CC) -c $(AFLAGS) $(CFLAGS) $+
+
+VERSION = 0.2
+SOURCE = $(shell ls *.c)
+TARGETS = $(SOURCE:.c=.pd_linux)
+
+EXT= pd_linux
+
+AFLAGS = -g -O2 -I./ -DFIXEDPOINT
+EFLAGS = -shared -Wl,-export-dynamic
+PREFIX = /usr
+
+
+all: $(TARGETS)
+
+clean:
+ -rm $(TARGETS)
+ -rm *.o *~
+
+tar: clean
+ cd ..;tar czvf PDa-externals-$(VERSION).tgz PDa-externals
+
+upload: tar
+ scp ../PDa-externals-$(VERSION).tgz gige@xdv.org:~/www/pda/release
+
+install:
+ install -d $(DESTDIR)/$(PREFIX)/lib/pd/extra
+ cp $(TARGETS) $(DESTDIR)/$(PREFIX)/lib/pd/extra
+
+%.$(EXT) : %.o
+ $(CC) -o $@ $(EFLAGS) $+
+
+%.o : %.c
+ $(CC) -c $(AFLAGS) $(CFLAGS) $+ \ No newline at end of file
diff --git a/apps/plugins/pdbox/PDa/extra/moog~.c b/apps/plugins/pdbox/PDa/extra/moog~.c
new file mode 100644
index 0000000000..ee7acc99aa
--- /dev/null
+++ b/apps/plugins/pdbox/PDa/extra/moog~.c
@@ -0,0 +1,366 @@
+/* (C) Guenter Geiger <geiger@epy.co.at> */
+
+
+#include "math.h"
+#include <m_pd.h>
+
+/* ----------------------------- moog ----------------------------- */
+static t_class *moog_class;
+
+
+typedef struct _moog
+{
+ t_object x_obj;
+ t_pd in2;
+ t_sample x_1,x_2,x_3,x_4;
+ t_sample y_1,y_2,y_3,y_4;
+} t_moog;
+
+static void moog_reset(t_moog *x)
+{
+ x->x_1 = x->x_2 = x->x_3 = x->x_4 = 0;
+ x->y_1 = x->y_2 = x->y_3 = x->y_4 = 0;
+
+}
+
+
+
+static void *moog_new(t_symbol *s, int argc, t_atom *argv)
+{
+ if (argc > 1) post("moog~: extra arguments ignored");
+ {
+ t_moog *x = (t_moog *)pd_new(moog_class);
+ outlet_new(&x->x_obj, &s_signal);
+ inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_signal, &s_signal);
+ inlet_new(&x->x_obj, &x->in2, &s_signal, &s_signal);
+ moog_reset(x);
+ return (x);
+ }
+
+
+}
+
+
+
+static t_sample calc_k(t_sample f,t_sample k) {
+ if (k>itofix(4)) k = itofix(4);
+ if (k < 0) k = 0;
+ if (f <= itofix(3800)) return k;
+ k = k - mult(0.5,(f-idiv(itofix(3800),itofix(4300))));
+ return k;
+}
+
+t_int *moog_perform(t_int *w)
+{
+ t_moog* x = (t_moog*) (w[1]);
+ t_sample *in1 = (t_sample *)(w[2]);
+ t_sample *p = (t_sample *)(w[3]);
+ t_sample *k = (t_sample *)(w[4]);
+
+ t_sample *out = (t_sample *)(w[5]);
+ int n = (int)(w[6]);
+ t_sample in;
+ t_sample pt,pt1;
+
+ t_sample x1 = x->x_1;
+ t_sample x2 = x->x_2;
+ t_sample x3 = x->x_3;
+ t_sample x4 = x->x_4;
+ t_sample ys1 = x->y_1;
+ t_sample ys2 = x->y_2;
+ t_sample ys3 = x->y_3;
+ t_sample ys4 = x->y_4;
+
+
+ while (n--) {
+ if (*p > itofix(8140)) *p = itofix(8140);
+ *k = calc_k(*p,*k);
+ pt =*p;
+ pt1=mult((pt+1),ftofix(0.76923077));
+ in = *in1++ - mult(*k,ys4);
+ ys1 = mult(pt1,in) + mult(0.3,x1) - mult(pt,ys1);
+ x1 = in;
+ ys2 = mult(pt1,ys1) + mult(0.3,x2) - mult(pt,ys2);
+ x2 = ys1;
+ ys3 = mult(pt1,ys2) + mult(0.3,x3) - mult(pt,ys3);
+ x3 = ys2;
+ ys4 = mult(pt1,ys3) + mult(0.3,x4) - mult(pt,ys4);
+ x4 = ys3;
+ *out++ = ys4;
+ }
+
+
+ x->y_1 = ys1;
+ x->y_2 = ys2;
+ x->y_3 = ys3;
+ x->y_4 = ys4;
+ x->x_1 = x1;
+ x->x_2 = x2;
+ x->x_3 = x3;
+ x->x_4 = x4;
+
+ return (w+7);
+}
+
+
+#define CLIP(x) x = ((x) > 1.0 ? (1.0) : (x))
+
+t_int *moog_perf8(t_int *w)
+{
+ t_moog* x = (t_moog*) (w[1]);
+ t_sample *in1 = (t_sample *)(w[2]);
+ t_sample *p = (t_sample *)(w[3]);
+ t_sample *k = (t_sample *)(w[4]);
+ t_sample *out = (t_sample *)(w[5]);
+ int n = (int)(w[6]);
+
+ t_sample x1 = x->x_1;
+ t_sample x2 = x->x_2;
+ t_sample x3 = x->x_3;
+ t_sample x4 = x->x_4;
+ t_sample ys1 = x->y_1;
+ t_sample ys2 = x->y_2;
+ t_sample ys3 = x->y_3;
+ t_sample ys4 = x->y_4;
+
+ t_sample temp,temp2;
+ t_sample pt,pt1;
+ t_sample in;
+
+ while (n--) {
+ if (*p > itofix(8140)) *p = itofix(8140);
+ *k = calc_k(*p,*k);
+
+ pt =mult(*p, ftofix(0.01*0.0140845)) - ftofix(0.9999999f);
+ pt1=mult((pt+itofix(1)),ftofix(0.76923077));
+ in = *in1++ - mult(*k,ys4);
+ ys1 = mult(pt1,(in + mult(ftofix(0.3),x1))) - mult(pt,ys1);
+ x1 = in;
+ ys2 = mult(pt1,(ys1 + mult(0.3,x2))) - mult(pt,ys2);
+ x2 = ys1;
+ ys3 = mult(pt1,(ys2 + mult(0.3,x3))) - mult(pt,ys3);
+ x3 = ys2;
+ ys4 = mult(pt1,(ys3 + mult(0.3,x4))) - mult(pt,ys4);
+ x4 = ys3;
+ *out++ = ys4;
+
+ p++;k++;
+ }
+
+ x->y_1 = ys1;
+ x->y_2 = ys2;
+ x->y_3 = ys3;
+ x->y_4 = ys4;
+ x->x_1 = x1;
+ x->x_2 = x2;
+ x->x_3 = x3;
+ x->x_4 = x4;
+
+ return (w+7);
+}
+
+void dsp_add_moog(t_moog *x, t_sample *in1, t_sample *in2, t_sample *in3, t_sample *out, int n)
+{
+ if (n&7)
+ dsp_add(moog_perform, 6,(t_int)x, in1,in2,in3, out, n);
+ else
+ dsp_add(moog_perf8, 6,(t_int) x, in1, in2, in3, out, n);
+}
+
+static void moog_dsp(t_moog *x, t_signal **sp)
+{
+ dsp_add_moog(x,sp[0]->s_vec, sp[1]->s_vec, sp[2]->s_vec, sp[3]->s_vec,sp[0]->s_n);
+}
+
+
+void moog_tilde_setup(void)
+{
+ moog_class = class_new(gensym("moog~"), (t_newmethod)moog_new, 0,
+ sizeof(t_moog), 0, A_GIMME, 0);
+ class_addmethod(moog_class, nullfn, gensym("signal"), 0);
+ class_addmethod(moog_class, (t_method)moog_reset, gensym("reset"), 0);
+ class_addmethod(moog_class, (t_method)moog_dsp, gensym("dsp"), A_NULL);
+}
+/* (C) Guenter Geiger <geiger@epy.co.at> */
+
+
+#include "math.h"
+#include <m_pd.h>
+
+/* ----------------------------- moog ----------------------------- */
+static t_class *moog_class;
+
+
+typedef struct _moog
+{
+ t_object x_obj;
+ t_pd in2;
+ t_sample x_1,x_2,x_3,x_4;
+ t_sample y_1,y_2,y_3,y_4;
+} t_moog;
+
+static void moog_reset(t_moog *x)
+{
+ x->x_1 = x->x_2 = x->x_3 = x->x_4 = 0;
+ x->y_1 = x->y_2 = x->y_3 = x->y_4 = 0;
+
+}
+
+
+
+static void *moog_new(t_symbol *s, int argc, t_atom *argv)
+{
+ if (argc > 1) post("moog~: extra arguments ignored");
+ {
+ t_moog *x = (t_moog *)pd_new(moog_class);
+ outlet_new(&x->x_obj, &s_signal);
+ inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_signal, &s_signal);
+ inlet_new(&x->x_obj, &x->in2, &s_signal, &s_signal);
+ moog_reset(x);
+ return (x);
+ }
+
+
+}
+
+
+
+static t_sample calc_k(t_sample f,t_sample k) {
+ if (k>itofix(4)) k = itofix(4);
+ if (k < 0) k = 0;
+ if (f <= itofix(3800)) return k;
+ k = k - mult(0.5,(f-idiv(itofix(3800),itofix(4300))));
+ return k;
+}
+
+t_int *moog_perform(t_int *w)
+{
+ t_moog* x = (t_moog*) (w[1]);
+ t_sample *in1 = (t_sample *)(w[2]);
+ t_sample *p = (t_sample *)(w[3]);
+ t_sample *k = (t_sample *)(w[4]);
+
+ t_sample *out = (t_sample *)(w[5]);
+ int n = (int)(w[6]);
+ t_sample in;
+ t_sample pt,pt1;
+
+ t_sample x1 = x->x_1;
+ t_sample x2 = x->x_2;
+ t_sample x3 = x->x_3;
+ t_sample x4 = x->x_4;
+ t_sample ys1 = x->y_1;
+ t_sample ys2 = x->y_2;
+ t_sample ys3 = x->y_3;
+ t_sample ys4 = x->y_4;
+
+
+ while (n--) {
+ if (*p > itofix(8140)) *p = itofix(8140);
+ *k = calc_k(*p,*k);
+ pt =*p;
+ pt1=mult((pt+1),ftofix(0.76923077));
+ in = *in1++ - mult(*k,ys4);
+ ys1 = mult(pt1,in) + mult(0.3,x1) - mult(pt,ys1);
+ x1 = in;
+ ys2 = mult(pt1,ys1) + mult(0.3,x2) - mult(pt,ys2);
+ x2 = ys1;
+ ys3 = mult(pt1,ys2) + mult(0.3,x3) - mult(pt,ys3);
+ x3 = ys2;
+ ys4 = mult(pt1,ys3) + mult(0.3,x4) - mult(pt,ys4);
+ x4 = ys3;
+ *out++ = ys4;
+ }
+
+
+ x->y_1 = ys1;
+ x->y_2 = ys2;
+ x->y_3 = ys3;
+ x->y_4 = ys4;
+ x->x_1 = x1;
+ x->x_2 = x2;
+ x->x_3 = x3;
+ x->x_4 = x4;
+
+ return (w+7);
+}
+
+
+#define CLIP(x) x = ((x) > 1.0 ? (1.0) : (x))
+
+t_int *moog_perf8(t_int *w)
+{
+ t_moog* x = (t_moog*) (w[1]);
+ t_sample *in1 = (t_sample *)(w[2]);
+ t_sample *p = (t_sample *)(w[3]);
+ t_sample *k = (t_sample *)(w[4]);
+ t_sample *out = (t_sample *)(w[5]);
+ int n = (int)(w[6]);
+
+ t_sample x1 = x->x_1;
+ t_sample x2 = x->x_2;
+ t_sample x3 = x->x_3;
+ t_sample x4 = x->x_4;
+ t_sample ys1 = x->y_1;
+ t_sample ys2 = x->y_2;
+ t_sample ys3 = x->y_3;
+ t_sample ys4 = x->y_4;
+
+ t_sample temp,temp2;
+ t_sample pt,pt1;
+ t_sample in;
+
+ while (n--) {
+ if (*p > itofix(8140)) *p = itofix(8140);
+ *k = calc_k(*p,*k);
+
+ pt =mult(*p, ftofix(0.01*0.0140845)) - ftofix(0.9999999f);
+ pt1=mult((pt+itofix(1)),ftofix(0.76923077));
+ in = *in1++ - mult(*k,ys4);
+ ys1 = mult(pt1,(in + mult(ftofix(0.3),x1))) - mult(pt,ys1);
+ x1 = in;
+ ys2 = mult(pt1,(ys1 + mult(0.3,x2))) - mult(pt,ys2);
+ x2 = ys1;
+ ys3 = mult(pt1,(ys2 + mult(0.3,x3))) - mult(pt,ys3);
+ x3 = ys2;
+ ys4 = mult(pt1,(ys3 + mult(0.3,x4))) - mult(pt,ys4);
+ x4 = ys3;
+ *out++ = ys4;
+
+ p++;k++;
+ }
+
+ x->y_1 = ys1;
+ x->y_2 = ys2;
+ x->y_3 = ys3;
+ x->y_4 = ys4;
+ x->x_1 = x1;
+ x->x_2 = x2;
+ x->x_3 = x3;
+ x->x_4 = x4;
+
+ return (w+7);
+}
+
+void dsp_add_moog(t_moog *x, t_sample *in1, t_sample *in2, t_sample *in3, t_sample *out, int n)
+{
+ if (n&7)
+ dsp_add(moog_perform, 6,(t_int)x, in1,in2,in3, out, n);
+ else
+ dsp_add(moog_perf8, 6,(t_int) x, in1, in2, in3, out, n);
+}
+
+static void moog_dsp(t_moog *x, t_signal **sp)
+{
+ dsp_add_moog(x,sp[0]->s_vec, sp[1]->s_vec, sp[2]->s_vec, sp[3]->s_vec,sp[0]->s_n);
+}
+
+
+void moog_tilde_setup(void)
+{
+ moog_class = class_new(gensym("moog~"), (t_newmethod)moog_new, 0,
+ sizeof(t_moog), 0, A_GIMME, 0);
+ class_addmethod(moog_class, nullfn, gensym("signal"), 0);
+ class_addmethod(moog_class, (t_method)moog_reset, gensym("reset"), 0);
+ class_addmethod(moog_class, (t_method)moog_dsp, gensym("dsp"), A_NULL);
+}
diff --git a/apps/plugins/pdbox/PDa/extra/notch.c b/apps/plugins/pdbox/PDa/extra/notch.c
new file mode 100644
index 0000000000..49be753ff2
--- /dev/null
+++ b/apps/plugins/pdbox/PDa/extra/notch.c
@@ -0,0 +1,178 @@
+/* (C) Guenter Geiger <geiger@epy.co.at> */
+
+
+/*
+
+ These filter coefficients computations are taken from
+ http://www.harmony-central.com/Computer/Programming/Audio-EQ-Cookbook.txt
+
+ written by Robert Bristow-Johnson
+
+*/
+
+#include "m_pd.h"
+#ifdef NT
+#pragma warning( disable : 4244 )
+#pragma warning( disable : 4305 )
+#endif
+#include <math.h>
+#include "filters.h"
+
+
+
+/* ------------------- notch ----------------------------*/
+
+static t_class *notch_class;
+
+void notch_bang(t_rbjfilter *x)
+{
+ t_atom at[5];
+ t_float omega = e_omega(x->x_freq,x->x_rate);
+ t_float alpha = e_alpha(x->x_bw* 0.01,omega);
+ t_float b1 = -2.*cos(omega);
+ t_float b0 = 1;
+ t_float b2 = b0;
+ t_float a0 = 1 + alpha;
+ t_float a1 = -2.*cos(omega);
+ t_float a2 = 1 - alpha;
+
+/* post("bang %f %f %f",x->x_freq, x->x_gain, x->x_bw); */
+
+ if (!check_stability(-a1/a0,-a2/a0,b0/a0,b1/a0,b2/a0)) {
+ post("notch: filter unstable -> resetting");
+ a0=1.;a1=0.;a2=0.;
+ b0=1.;b1=0.;b2=0.;
+ }
+
+ SETFLOAT(at,-a1/a0);
+ SETFLOAT(at+1,-a2/a0);
+ SETFLOAT(at+2,b0/a0);
+ SETFLOAT(at+3,b1/a0);
+ SETFLOAT(at+4,b2/a0);
+
+ outlet_list(x->x_obj.ob_outlet,&s_list,5,at);
+}
+
+
+void notch_float(t_rbjfilter *x,t_floatarg f)
+{
+ x->x_freq = f;
+ notch_bang(x);
+}
+
+
+static void *notch_new(t_floatarg f,t_floatarg bw)
+{
+ t_rbjfilter *x = (t_rbjfilter *)pd_new(notch_class);
+
+ x->x_rate = 44100.0;
+ outlet_new(&x->x_obj,&s_float);
+/* floatinlet_new(&x->x_obj, &x->x_gain); */
+ floatinlet_new(&x->x_obj, &x->x_bw);
+ if (f > 0.) x->x_freq = f;
+ if (bw > 0.) x->x_bw = bw;
+ return (x);
+}
+
+
+void notch_setup(void)
+{
+ notch_class = class_new(gensym("notch"), (t_newmethod)notch_new, 0,
+ sizeof(t_rbjfilter), 0,A_DEFFLOAT,A_DEFFLOAT,0);
+ class_addbang(notch_class,notch_bang);
+ class_addfloat(notch_class,notch_float);
+}
+
+
+
+
+
+/* (C) Guenter Geiger <geiger@epy.co.at> */
+
+
+/*
+
+ These filter coefficients computations are taken from
+ http://www.harmony-central.com/Computer/Programming/Audio-EQ-Cookbook.txt
+
+ written by Robert Bristow-Johnson
+
+*/
+
+#include "m_pd.h"
+#ifdef NT
+#pragma warning( disable : 4244 )
+#pragma warning( disable : 4305 )
+#endif
+#include <math.h>
+#include "filters.h"
+
+
+
+/* ------------------- notch ----------------------------*/
+
+static t_class *notch_class;
+
+void notch_bang(t_rbjfilter *x)
+{
+ t_atom at[5];
+ t_float omega = e_omega(x->x_freq,x->x_rate);
+ t_float alpha = e_alpha(x->x_bw* 0.01,omega);
+ t_float b1 = -2.*cos(omega);
+ t_float b0 = 1;
+ t_float b2 = b0;
+ t_float a0 = 1 + alpha;
+ t_float a1 = -2.*cos(omega);
+ t_float a2 = 1 - alpha;
+
+/* post("bang %f %f %f",x->x_freq, x->x_gain, x->x_bw); */
+
+ if (!check_stability(-a1/a0,-a2/a0,b0/a0,b1/a0,b2/a0)) {
+ post("notch: filter unstable -> resetting");
+ a0=1.;a1=0.;a2=0.;
+ b0=1.;b1=0.;b2=0.;
+ }
+
+ SETFLOAT(at,-a1/a0);
+ SETFLOAT(at+1,-a2/a0);
+ SETFLOAT(at+2,b0/a0);
+ SETFLOAT(at+3,b1/a0);
+ SETFLOAT(at+4,b2/a0);
+
+ outlet_list(x->x_obj.ob_outlet,&s_list,5,at);
+}
+
+
+void notch_float(t_rbjfilter *x,t_floatarg f)
+{
+ x->x_freq = f;
+ notch_bang(x);
+}
+
+
+static void *notch_new(t_floatarg f,t_floatarg bw)
+{
+ t_rbjfilter *x = (t_rbjfilter *)pd_new(notch_class);
+
+ x->x_rate = 44100.0;
+ outlet_new(&x->x_obj,&s_float);
+/* floatinlet_new(&x->x_obj, &x->x_gain); */
+ floatinlet_new(&x->x_obj, &x->x_bw);
+ if (f > 0.) x->x_freq = f;
+ if (bw > 0.) x->x_bw = bw;
+ return (x);
+}
+
+
+void notch_setup(void)
+{
+ notch_class = class_new(gensym("notch"), (t_newmethod)notch_new, 0,
+ sizeof(t_rbjfilter), 0,A_DEFFLOAT,A_DEFFLOAT,0);
+ class_addbang(notch_class,notch_bang);
+ class_addfloat(notch_class,notch_float);
+}
+
+
+
+
+
diff --git a/apps/plugins/pdbox/PDa/extra/s_stuff.h b/apps/plugins/pdbox/PDa/extra/s_stuff.h
new file mode 100644
index 0000000000..6dc9a88c4b
--- /dev/null
+++ b/apps/plugins/pdbox/PDa/extra/s_stuff.h
@@ -0,0 +1,430 @@
+/* Copyright (c) 1997-1999 Miller Puckette.
+* For information on usage and redistribution, and for a DISCLAIMER OF ALL
+* WARRANTIES, see the file, "LICENSE.txt," in this distribution. */
+
+/* Audio and MIDI I/O, and other scheduling and system stuff. */
+
+/* NOTE: this file describes Pd implementation details which may change
+in future releases. The public (stable) API is in m_pd.h. */
+
+/* in s_file.c */
+typedef struct _namelist
+{
+ struct _namelist *nl_next;
+ char *nl_string;
+} t_namelist;
+
+t_namelist *namelist_append(t_namelist *listwas, const char *s);
+void namelist_free(t_namelist *listwas);
+
+/* s_main.c */
+extern int sys_debuglevel;
+extern int sys_verbose;
+extern int sys_noloadbang;
+extern int sys_nogui;
+extern char *sys_guicmd;
+
+EXTERN int sys_nearestfontsize(int fontsize);
+EXTERN int sys_hostfontsize(int fontsize);
+
+extern int sys_defaultfont;
+extern t_symbol *sys_libdir; /* library directory for auxilliary files */
+
+/* s_loader.c */
+int sys_load_lib(char *dirname, char *filename);
+
+/* s_audio.c */
+
+#define SENDDACS_NO 0 /* return values for sys_send_dacs() */
+#define SENDDACS_YES 1
+#define SENDDACS_SLEPT 2
+
+#define DEFDACBLKSIZE 64
+extern int sys_schedblocksize; /* audio block size for scheduler */
+extern int sys_hipriority; /* real-time flag, true if priority boosted */
+extern t_sample *sys_soundout;
+extern t_sample *sys_soundin;
+extern int sys_inchannels;
+extern int sys_outchannels;
+extern int sys_advance_samples; /* scheduler advance in samples */
+extern int sys_blocksize; /* audio I/O block size in sample frames */
+extern float sys_dacsr;
+extern int sys_schedadvance;
+extern int sys_sleepgrain;
+void sys_open_audio(int naudioindev, int *audioindev,
+ int nchindev, int *chindev,
+ int naudiooutdev, int *audiooutdev, int nchoutdev, int *choutdev,
+ int srate, int advance, int enable);
+void sys_close_audio(void);
+
+ /* s_midi.c */
+void sys_open_midi(int nmidiin, int *midiinvec, int nmidiout, int *midioutvec);
+
+ /* implemented in the system dependent MIDI code (s_midi_pm.c, etc. ) */
+void sys_do_open_midi(int nmidiin, int *midiinvec,
+ int nmidiout, int *midioutvec);
+void sys_close_midi(void);
+void midi_getdevs(char *indevlist, int *nindevs,
+ char *outdevlist, int *noutdevs, int maxndev, int devdescsize);
+
+int sys_send_dacs(void);
+void sys_reportidle(void);
+void sys_set_priority(int higher);
+void sys_audiobuf(int nbufs);
+void sys_getmeters(float *inmax, float *outmax);
+void sys_listdevs(void);
+void sys_setblocksize(int n);
+
+/* s_midi.c */
+#define MAXMIDIINDEV 16 /* max. number of input ports */
+#define MAXMIDIOUTDEV 16 /* max. number of output ports */
+extern int sys_nmidiin;
+extern int sys_nmidiout;
+extern int sys_midiindevlist[];
+extern int sys_midioutdevlist[];
+
+EXTERN void sys_putmidimess(int portno, int a, int b, int c);
+EXTERN void sys_putmidibyte(int portno, int a);
+EXTERN void sys_poll_midi(void);
+EXTERN void sys_setmiditimediff(double inbuftime, double outbuftime);
+EXTERN void sys_midibytein(int portno, int byte);
+
+/* m_sched.c */
+EXTERN void sys_log_error(int type);
+#define ERR_NOTHING 0
+#define ERR_ADCSLEPT 1
+#define ERR_DACSLEPT 2
+#define ERR_RESYNC 3
+#define ERR_DATALATE 4
+void sched_set_using_dacs(int flag);
+
+/* s_inter.c */
+
+EXTERN void sys_microsleep(int microsec);
+
+EXTERN void sys_bail(int exitcode);
+EXTERN int sys_pollgui(void);
+
+EXTERN_STRUCT _socketreceiver;
+#define t_socketreceiver struct _socketreceiver
+
+typedef void (*t_socketnotifier)(void *x);
+typedef void (*t_socketreceivefn)(void *x, t_binbuf *b);
+
+EXTERN t_socketreceiver *socketreceiver_new(void *owner,
+ t_socketnotifier notifier, t_socketreceivefn socketreceivefn, int udp);
+EXTERN void socketreceiver_read(t_socketreceiver *x, int fd);
+EXTERN void sys_sockerror(char *s);
+EXTERN void sys_closesocket(int fd);
+
+typedef void (*t_fdpollfn)(void *ptr, int fd);
+EXTERN void sys_addpollfn(int fd, t_fdpollfn fn, void *ptr);
+EXTERN void sys_rmpollfn(int fd);
+#ifdef UNIX
+void sys_setalarm(int microsec);
+void sys_setvirtualalarm( void);
+#endif
+
+#define API_ALSA 1
+#define API_OSS 2
+#define API_MMIO 3
+#define API_PORTAUDIO 4
+#define API_JACK 5
+
+#ifdef __linux__
+#define API_DEFAULT API_OSS
+#define API_DEFSTRING "OSS"
+#endif
+#ifdef MSW
+#define API_DEFAULT API_MMIO
+#define API_DEFSTRING "MMIO"
+#endif
+#ifdef MACOSX
+#define API_DEFAULT API_PORTAUDIO
+#define API_DEFSTRING "portaudio"
+#endif
+#define DEFAULTAUDIODEV 0
+
+#define MAXAUDIOINDEV 4
+#define MAXAUDIOOUTDEV 4
+
+#define DEFMIDIDEV 0
+
+#define DEFAULTSRATE 44100
+#ifdef MSW
+#define DEFAULTADVANCE 70
+#else
+#define DEFAULTADVANCE 50
+#endif
+
+int pa_open_audio(int inchans, int outchans, int rate, t_sample *soundin,
+ t_sample *soundout, int framesperbuf, int nbuffers,
+ int indeviceno, int outdeviceno);
+void pa_close_audio(void);
+int pa_send_dacs(void);
+void sys_reportidle(void);
+void pa_listdevs(void);
+void pa_getdevs(char *indevlist, int *nindevs,
+ char *outdevlist, int *noutdevs, int *canmulti,
+ int maxndev, int devdescsize);
+
+int oss_open_audio(int naudioindev, int *audioindev, int nchindev,
+ int *chindev, int naudiooutdev, int *audiooutdev, int nchoutdev,
+ int *choutdev, int rate); /* IOhannes */
+void oss_close_audio(void);
+int oss_send_dacs(void);
+void oss_reportidle(void);
+void oss_getdevs(char *indevlist, int *nindevs,
+ char *outdevlist, int *noutdevs, int *canmulti,
+ int maxndev, int devdescsize);
+
+int alsa_open_audio(int naudioindev, int *audioindev, int nchindev,
+ int *chindev, int naudiooutdev, int *audiooutdev, int nchoutdev,
+ int *choutdev, int rate);
+void alsa_close_audio(void);
+int alsa_send_dacs(void);
+void alsa_reportidle(void);
+void alsa_getdevs(char *indevlist, int *nindevs,
+ char *outdevlist, int *noutdevs, int *canmulti,
+ int maxndev, int devdescsize);
+
+int jack_open_audio(int wantinchans, int wantoutchans, int srate);
+void jack_close_audio(void);
+int jack_send_dacs(void);
+void jack_reportidle(void);
+void jack_listdevs(void);
+
+void mmio_open_audio(int naudioindev, int *audioindev,
+ int nchindev, int *chindev, int naudiooutdev, int *audiooutdev,
+ int nchoutdev, int *choutdev, int rate);
+void mmio_close_audio( void);
+void mmio_reportidle(void);
+int mmio_send_dacs(void);
+void mmio_getdevs(char *indevlist, int *nindevs,
+ char *outdevlist, int *noutdevs, int *canmulti,
+ int maxndev, int devdescsize);
+
+void sys_listmididevs(void);
+void sys_set_audio_api(int whichapi);
+void sys_get_audio_apis(char *buf);
+extern int sys_audioapi;
+void sys_set_audio_state(int onoff);
+
+/* API dependent audio flags and settings */
+void oss_set32bit( void);
+void linux_alsa_devname(char *devname);
+/* Copyright (c) 1997-1999 Miller Puckette.
+* For information on usage and redistribution, and for a DISCLAIMER OF ALL
+* WARRANTIES, see the file, "LICENSE.txt," in this distribution. */
+
+/* Audio and MIDI I/O, and other scheduling and system stuff. */
+
+/* NOTE: this file describes Pd implementation details which may change
+in future releases. The public (stable) API is in m_pd.h. */
+
+/* in s_file.c */
+typedef struct _namelist
+{
+ struct _namelist *nl_next;
+ char *nl_string;
+} t_namelist;
+
+t_namelist *namelist_append(t_namelist *listwas, const char *s);
+void namelist_free(t_namelist *listwas);
+
+/* s_main.c */
+extern int sys_debuglevel;
+extern int sys_verbose;
+extern int sys_noloadbang;
+extern int sys_nogui;
+extern char *sys_guicmd;
+
+EXTERN int sys_nearestfontsize(int fontsize);
+EXTERN int sys_hostfontsize(int fontsize);
+
+extern int sys_defaultfont;
+extern t_symbol *sys_libdir; /* library directory for auxilliary files */
+
+/* s_loader.c */
+int sys_load_lib(char *dirname, char *filename);
+
+/* s_audio.c */
+
+#define SENDDACS_NO 0 /* return values for sys_send_dacs() */
+#define SENDDACS_YES 1
+#define SENDDACS_SLEPT 2
+
+#define DEFDACBLKSIZE 64
+extern int sys_schedblocksize; /* audio block size for scheduler */
+extern int sys_hipriority; /* real-time flag, true if priority boosted */
+extern t_sample *sys_soundout;
+extern t_sample *sys_soundin;
+extern int sys_inchannels;
+extern int sys_outchannels;
+extern int sys_advance_samples; /* scheduler advance in samples */
+extern int sys_blocksize; /* audio I/O block size in sample frames */
+extern float sys_dacsr;
+extern int sys_schedadvance;
+extern int sys_sleepgrain;
+void sys_open_audio(int naudioindev, int *audioindev,
+ int nchindev, int *chindev,
+ int naudiooutdev, int *audiooutdev, int nchoutdev, int *choutdev,
+ int srate, int advance, int enable);
+void sys_close_audio(void);
+
+ /* s_midi.c */
+void sys_open_midi(int nmidiin, int *midiinvec, int nmidiout, int *midioutvec);
+
+ /* implemented in the system dependent MIDI code (s_midi_pm.c, etc. ) */
+void sys_do_open_midi(int nmidiin, int *midiinvec,
+ int nmidiout, int *midioutvec);
+void sys_close_midi(void);
+void midi_getdevs(char *indevlist, int *nindevs,
+ char *outdevlist, int *noutdevs, int maxndev, int devdescsize);
+
+int sys_send_dacs(void);
+void sys_reportidle(void);
+void sys_set_priority(int higher);
+void sys_audiobuf(int nbufs);
+void sys_getmeters(float *inmax, float *outmax);
+void sys_listdevs(void);
+void sys_setblocksize(int n);
+
+/* s_midi.c */
+#define MAXMIDIINDEV 16 /* max. number of input ports */
+#define MAXMIDIOUTDEV 16 /* max. number of output ports */
+extern int sys_nmidiin;
+extern int sys_nmidiout;
+extern int sys_midiindevlist[];
+extern int sys_midioutdevlist[];
+
+EXTERN void sys_putmidimess(int portno, int a, int b, int c);
+EXTERN void sys_putmidibyte(int portno, int a);
+EXTERN void sys_poll_midi(void);
+EXTERN void sys_setmiditimediff(double inbuftime, double outbuftime);
+EXTERN void sys_midibytein(int portno, int byte);
+
+/* m_sched.c */
+EXTERN void sys_log_error(int type);
+#define ERR_NOTHING 0
+#define ERR_ADCSLEPT 1
+#define ERR_DACSLEPT 2
+#define ERR_RESYNC 3
+#define ERR_DATALATE 4
+void sched_set_using_dacs(int flag);
+
+/* s_inter.c */
+
+EXTERN void sys_microsleep(int microsec);
+
+EXTERN void sys_bail(int exitcode);
+EXTERN int sys_pollgui(void);
+
+EXTERN_STRUCT _socketreceiver;
+#define t_socketreceiver struct _socketreceiver
+
+typedef void (*t_socketnotifier)(void *x);
+typedef void (*t_socketreceivefn)(void *x, t_binbuf *b);
+
+EXTERN t_socketreceiver *socketreceiver_new(void *owner,
+ t_socketnotifier notifier, t_socketreceivefn socketreceivefn, int udp);
+EXTERN void socketreceiver_read(t_socketreceiver *x, int fd);
+EXTERN void sys_sockerror(char *s);
+EXTERN void sys_closesocket(int fd);
+
+typedef void (*t_fdpollfn)(void *ptr, int fd);
+EXTERN void sys_addpollfn(int fd, t_fdpollfn fn, void *ptr);
+EXTERN void sys_rmpollfn(int fd);
+#ifdef UNIX
+void sys_setalarm(int microsec);
+void sys_setvirtualalarm( void);
+#endif
+
+#define API_ALSA 1
+#define API_OSS 2
+#define API_MMIO 3
+#define API_PORTAUDIO 4
+#define API_JACK 5
+
+#ifdef __linux__
+#define API_DEFAULT API_OSS
+#define API_DEFSTRING "OSS"
+#endif
+#ifdef MSW
+#define API_DEFAULT API_MMIO
+#define API_DEFSTRING "MMIO"
+#endif
+#ifdef MACOSX
+#define API_DEFAULT API_PORTAUDIO
+#define API_DEFSTRING "portaudio"
+#endif
+#define DEFAULTAUDIODEV 0
+
+#define MAXAUDIOINDEV 4
+#define MAXAUDIOOUTDEV 4
+
+#define DEFMIDIDEV 0
+
+#define DEFAULTSRATE 44100
+#ifdef MSW
+#define DEFAULTADVANCE 70
+#else
+#define DEFAULTADVANCE 50
+#endif
+
+int pa_open_audio(int inchans, int outchans, int rate, t_sample *soundin,
+ t_sample *soundout, int framesperbuf, int nbuffers,
+ int indeviceno, int outdeviceno);
+void pa_close_audio(void);
+int pa_send_dacs(void);
+void sys_reportidle(void);
+void pa_listdevs(void);
+void pa_getdevs(char *indevlist, int *nindevs,
+ char *outdevlist, int *noutdevs, int *canmulti,
+ int maxndev, int devdescsize);
+
+int oss_open_audio(int naudioindev, int *audioindev, int nchindev,
+ int *chindev, int naudiooutdev, int *audiooutdev, int nchoutdev,
+ int *choutdev, int rate); /* IOhannes */
+void oss_close_audio(void);
+int oss_send_dacs(void);
+void oss_reportidle(void);
+void oss_getdevs(char *indevlist, int *nindevs,
+ char *outdevlist, int *noutdevs, int *canmulti,
+ int maxndev, int devdescsize);
+
+int alsa_open_audio(int naudioindev, int *audioindev, int nchindev,
+ int *chindev, int naudiooutdev, int *audiooutdev, int nchoutdev,
+ int *choutdev, int rate);
+void alsa_close_audio(void);
+int alsa_send_dacs(void);
+void alsa_reportidle(void);
+void alsa_getdevs(char *indevlist, int *nindevs,
+ char *outdevlist, int *noutdevs, int *canmulti,
+ int maxndev, int devdescsize);
+
+int jack_open_audio(int wantinchans, int wantoutchans, int srate);
+void jack_close_audio(void);
+int jack_send_dacs(void);
+void jack_reportidle(void);
+void jack_listdevs(void);
+
+void mmio_open_audio(int naudioindev, int *audioindev,
+ int nchindev, int *chindev, int naudiooutdev, int *audiooutdev,
+ int nchoutdev, int *choutdev, int rate);
+void mmio_close_audio( void);
+void mmio_reportidle(void);
+int mmio_send_dacs(void);
+void mmio_getdevs(char *indevlist, int *nindevs,
+ char *outdevlist, int *noutdevs, int *canmulti,
+ int maxndev, int devdescsize);
+
+void sys_listmididevs(void);
+void sys_set_audio_api(int whichapi);
+void sys_get_audio_apis(char *buf);
+extern int sys_audioapi;
+void sys_set_audio_state(int onoff);
+
+/* API dependent audio flags and settings */
+void oss_set32bit( void);
+void linux_alsa_devname(char *devname);
diff --git a/apps/plugins/pdbox/PDa/extra/sendOSC.c b/apps/plugins/pdbox/PDa/extra/sendOSC.c
new file mode 100644
index 0000000000..c00f693280
--- /dev/null
+++ b/apps/plugins/pdbox/PDa/extra/sendOSC.c
@@ -0,0 +1,2922 @@
+/*
+Written by Matt Wright, The Center for New Music and Audio Technologies,
+University of California, Berkeley. Copyright (c) 1996,97,98,99,2000,01,02,03
+The Regents of the University of California (Regents).
+
+Permission to use, copy, modify, distribute, and distribute modified versions
+of this software and its documentation without fee and without a signed
+licensing agreement, is hereby granted, provided that the above copyright
+notice, this paragraph and the following two paragraphs appear in all copies,
+modifications, and distributions.
+
+IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
+SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING
+OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF REGENTS HAS
+BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE. THE SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED
+HEREUNDER IS PROVIDED "AS IS". REGENTS HAS NO OBLIGATION TO PROVIDE
+MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
+
+
+The OSC webpage is http://cnmat.cnmat.berkeley.edu/OpenSoundControl
+*/
+
+
+/* sendOSC.c
+
+ Matt Wright, 6/3/97
+ based on sendOSC.c, which was based on a version by Adrian Freed
+
+ Text-based OpenSoundControl client. User can enter messages via command
+ line arguments or standard input.
+
+ Version 0.1: "play" feature
+ Version 0.2: Message type tags.
+
+ pd version branched from http://www.cnmat.berkeley.edu/OpenSoundControl/src/sendOSC/sendOSC.c
+ -------------
+ -- added bundle stuff to send. jdl 20020416
+ -- tweaks for Win32 www.zeggz.com/raf 13-April-2002
+ -- ost_at_test.at + i22_at_test.at, 2000-2002
+ modified to compile as pd externel
+*/
+
+#define MAX_ARGS 2000
+#define SC_BUFFER_SIZE 64000
+
+#include "m_pd.h"
+#include "OSC-client.h"
+
+#include <string.h>
+#include <sys/types.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+
+#ifdef WIN32
+#include <winsock2.h>
+#include <io.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <winsock2.h>
+#include <ctype.h>
+#include <signal.h>
+#else
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <rpc/rpc.h>
+#include <sys/times.h>
+#include <sys/param.h>
+#include <sys/time.h>
+#include <sys/ioctl.h>
+#include <netdb.h>
+#endif
+
+#ifdef __APPLE__
+ #include <string.h>
+#endif
+
+#define UNIXDG_PATH "/tmp/htm"
+#define UNIXDG_TMP "/tmp/htm.XXXXXX"
+
+
+
+OSCTimeTag OSCTT_Immediately(void) {
+ OSCTimeTag result;
+ result.seconds = 0;
+ result.fraction = 1;
+ return result;
+}
+
+
+OSCTimeTag OSCTT_CurrentTime(void) {
+ OSCTimeTag result;
+ result.seconds = 0;
+ result.fraction = 1;
+ return result;
+}
+
+OSCTimeTag OSCTT_PlusSeconds(OSCTimeTag original, float secondsOffset) {
+ OSCTimeTag result;
+ result.seconds = 0;
+ result.fraction = 1;
+ return result;
+}
+
+
+typedef int bool;
+
+typedef struct
+{
+ float srate;
+
+ struct sockaddr_in serv_addr; /* udp socket */
+ #ifndef WIN32
+ struct sockaddr_un userv_addr; /* UNIX socket */
+ #endif
+ int sockfd; /* socket file descriptor */
+ int index, len,uservlen;
+ void *addr;
+ int id;
+} desc;
+
+
+/* open a socket for HTM communication to given host on given portnumber */
+/* if host is 0 then UNIX protocol is used (i.e. local communication */
+void *OpenHTMSocket(char *host, int portnumber)
+{
+ struct sockaddr_in cl_addr;
+ #ifndef WIN32
+ int sockfd;
+ struct sockaddr_un ucl_addr;
+ #else
+ unsigned int sockfd;
+ #endif
+
+ desc *o;
+ int oval = 1;
+ o = malloc(sizeof(*o));
+ if(!o) return 0;
+
+ #ifndef WIN32
+
+ if(!host)
+ {
+ char *mktemp(char *);
+ int clilen;
+ o->len = sizeof(ucl_addr);
+ /*
+ * Fill in the structure "userv_addr" with the address of the
+ * server that we want to send to.
+ */
+
+ bzero((char *) &o->userv_addr, sizeof(o->userv_addr));
+ o->userv_addr.sun_family = AF_UNIX;
+ strcpy(o->userv_addr.sun_path, UNIXDG_PATH);
+ sprintf(o->userv_addr.sun_path+strlen(o->userv_addr.sun_path), "%d", portnumber);
+ o->uservlen = sizeof(o->userv_addr.sun_family) + strlen(o->userv_addr.sun_path);
+ o->addr = &(o->userv_addr);
+ /*
+ * Open a socket (a UNIX domain datagram socket).
+ */
+
+ if ( (sockfd = socket(AF_UNIX, SOCK_DGRAM, 0)) >= 0)
+ {
+ /*
+ * Bind a local address for us.
+ * In the UNIX domain we have to choose our own name (that
+ * should be unique). We'll use mktemp() to create a unique
+ * pathname, based on our process id.
+ */
+
+ bzero((char *) &ucl_addr, sizeof(ucl_addr)); /* zero out */
+ ucl_addr.sun_family = AF_UNIX;
+ strcpy(ucl_addr.sun_path, UNIXDG_TMP);
+
+ mktemp(ucl_addr.sun_path);
+ clilen = sizeof(ucl_addr.sun_family) + strlen(ucl_addr.sun_path);
+
+ if (bind(sockfd, (struct sockaddr *) &ucl_addr, clilen) < 0)
+ {
+ perror("client: can't bind local address");
+ close(sockfd);
+ sockfd = -1;
+ }
+ }
+ else
+ perror("unable to make socket\n");
+
+ }else
+
+ #endif
+
+ {
+ /*
+ * Fill in the structure "serv_addr" with the address of the
+ * server that we want to send to.
+ */
+ o->len = sizeof(cl_addr);
+
+ #ifdef WIN32
+ ZeroMemory((char *)&o->serv_addr, sizeof(o->serv_addr));
+ #else
+ bzero((char *)&o->serv_addr, sizeof(o->serv_addr));
+ #endif
+
+ o->serv_addr.sin_family = AF_INET;
+
+ /* MW 6/6/96: Call gethostbyname() instead of inet_addr(),
+ so that host can be either an Internet host name (e.g.,
+ "les") or an Internet address in standard dot notation
+ (e.g., "128.32.122.13") */
+ {
+ struct hostent *hostsEntry;
+ unsigned long address;
+
+ hostsEntry = gethostbyname(host);
+ if (hostsEntry == NULL) {
+ fprintf(stderr, "Couldn't decipher host name \"%s\"\n", host);
+ #ifndef WIN32
+ herror(NULL);
+ #endif
+ return 0;
+ }
+ address = *((unsigned long *) hostsEntry->h_addr_list[0]);
+ o->serv_addr.sin_addr.s_addr = address;
+ }
+
+ /* was: o->serv_addr.sin_addr.s_addr = inet_addr(host); */
+
+ /* End MW changes */
+
+ /*
+ * Open a socket (a UDP domain datagram socket).
+ */
+
+
+ #ifdef WIN32
+ o->serv_addr.sin_port = htons((USHORT)portnumber);
+ o->addr = &(o->serv_addr);
+ if((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) != INVALID_SOCKET) {
+ ZeroMemory((char *)&cl_addr, sizeof(cl_addr));
+ cl_addr.sin_family = AF_INET;
+ cl_addr.sin_addr.s_addr = htonl(INADDR_ANY);
+ cl_addr.sin_port = htons(0);
+
+ // enable broadcast: jdl ~2003
+ if(setsockopt(sockfd, SOL_SOCKET, SO_BROADCAST, &oval, sizeof(int)) == -1) {
+ perror("setsockopt");
+ }
+
+ if(bind(sockfd, (struct sockaddr *) &cl_addr, sizeof(cl_addr)) < 0) {
+ perror("could not bind\n");
+ closesocket(sockfd);
+ sockfd = -1;
+ }
+ }
+ else { perror("unable to make socket\n");}
+ #else
+ o->serv_addr.sin_port = htons(portnumber);
+ o->addr = &(o->serv_addr);
+ if((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) >= 0) {
+ bzero((char *)&cl_addr, sizeof(cl_addr));
+ cl_addr.sin_family = AF_INET;
+ cl_addr.sin_addr.s_addr = htonl(INADDR_ANY);
+ cl_addr.sin_port = htons(0);
+
+ // enable broadcast: jdl ~2003
+ if(setsockopt(sockfd, SOL_SOCKET, SO_BROADCAST, &oval, sizeof(int)) == -1) {
+ perror("setsockopt");
+ }
+
+ if(bind(sockfd, (struct sockaddr *) &cl_addr, sizeof(cl_addr)) < 0) {
+ perror("could not bind\n");
+ close(sockfd);
+ sockfd = -1;
+ }
+ }
+ else { perror("unable to make socket\n");}
+ #endif
+ }
+ #ifdef WIN32
+ if(sockfd == INVALID_SOCKET) {
+ #else
+ if(sockfd < 0) {
+ #endif
+ free(o);
+ o = 0;
+ }
+ else
+ o->sockfd = sockfd;
+ return o;
+}
+
+static bool sendudp(const struct sockaddr *sp, int sockfd,int length, int count, void *b)
+{
+ int rcount;
+ if((rcount=sendto(sockfd, b, count, 0, sp, length)) != count)
+ {
+ printf("sockfd %d count %d rcount %dlength %d\n", sockfd,count,rcount,length);
+ return FALSE;
+ }
+ return TRUE;
+}
+
+bool SendHTMSocket(void *htmsendhandle, int length_in_bytes, void *buffer)
+{
+ desc *o = (desc *)htmsendhandle;
+ return sendudp(o->addr, o->sockfd, o->len, length_in_bytes, buffer);
+}
+void CloseHTMSocket(void *htmsendhandle)
+{
+ desc *o = (desc *)htmsendhandle;
+ #ifdef WIN32
+ if(SOCKET_ERROR == closesocket(o->sockfd)) {
+ perror("CloseHTMSocket::closesocket failed\n");
+ return;
+ }
+ #else
+ if(close(o->sockfd) == -1)
+ {
+ perror("CloseHTMSocket::closesocket failed");
+ return;
+ }
+ #endif
+
+ free(o);
+}
+
+
+///////////////////////
+// from sendOSC
+
+typedef struct {
+ //enum {INT, FLOAT, STRING} type;
+ enum {INT_osc, FLOAT_osc, STRING_osc} type;
+ union {
+ int i;
+ float f;
+ char *s;
+ } datum;
+} typedArg;
+
+void CommandLineMode(int argc, char *argv[], void *htmsocket);
+OSCTimeTag ParseTimeTag(char *s);
+void ParseInteractiveLine(OSCbuf *buf, char *mesg);
+typedArg ParseToken(char *token);
+int WriteMessage(OSCbuf *buf, char *messageName, int numArgs, typedArg *args);
+void SendBuffer(void *htmsocket, OSCbuf *buf);
+void SendData(void *htmsocket, int size, char *data);
+/* defined in OSC-system-dependent.c now */
+
+//static void *htmsocket;
+static int exitStatus = 0;
+static int useTypeTags = 0;
+
+static char bufferForOSCbuf[SC_BUFFER_SIZE];
+
+
+/////////
+// end from sendOSC
+
+static t_class *sendOSC_class;
+
+typedef struct _sendOSC
+{
+ t_object x_obj;
+ int x_protocol; // UDP/TCP (udp only atm)
+ t_int x_typetags; // typetag flag
+ void *x_htmsocket; // sending socket
+ int x_bundle; // bundle open flag
+ OSCbuf x_oscbuf[1]; // OSCbuffer
+ t_outlet *x_bdpthout;// bundle-depth floatoutlet
+} t_sendOSC;
+
+static void *sendOSC_new(t_floatarg udpflag)
+{
+ t_sendOSC *x = (t_sendOSC *)pd_new(sendOSC_class);
+ outlet_new(&x->x_obj, &s_float);
+ x->x_htmsocket = 0; // {{raf}}
+ // set udp
+ x->x_protocol = SOCK_STREAM;
+ // set typetags to 1 by default
+ x->x_typetags = 1;
+ // bunlde is closed
+ x->x_bundle = 0;
+ OSC_initBuffer(x->x_oscbuf, SC_BUFFER_SIZE, bufferForOSCbuf);
+ x->x_bdpthout = outlet_new(&x->x_obj, 0); // outlet_float();
+ //x->x_oscbuf =
+ return (x);
+}
+
+
+void sendOSC_openbundle(t_sendOSC *x)
+{
+ if (x->x_oscbuf->bundleDepth + 1 >= MAX_BUNDLE_NESTING ||
+ OSC_openBundle(x->x_oscbuf, OSCTT_Immediately()))
+ {
+ post("Problem opening bundle: %s\n", OSC_errorMessage);
+ return;
+ }
+ x->x_bundle = 1;
+ outlet_float(x->x_bdpthout, (float)x->x_oscbuf->bundleDepth);
+}
+
+static void sendOSC_closebundle(t_sendOSC *x)
+{
+ if (OSC_closeBundle(x->x_oscbuf)) {
+ post("Problem closing bundle: %s\n", OSC_errorMessage);
+ return;
+ }
+ outlet_float(x->x_bdpthout, (float)x->x_oscbuf->bundleDepth);
+ // in bundle mode we send when bundle is closed?
+ if(!OSC_isBufferEmpty(x->x_oscbuf) > 0 && OSC_isBufferDone(x->x_oscbuf)) {
+ // post("x_oscbuf: something inside me?");
+ if (x->x_htmsocket) {
+ SendBuffer(x->x_htmsocket, x->x_oscbuf);
+ } else {
+ post("sendOSC: not connected");
+ }
+ OSC_initBuffer(x->x_oscbuf, SC_BUFFER_SIZE, bufferForOSCbuf);
+ x->x_bundle = 0;
+ return;
+ }
+ // post("x_oscbuf: something went wrong");
+}
+
+static void sendOSC_settypetags(t_sendOSC *x, t_float *f)
+ {
+ x->x_typetags = (int)f;
+ post("sendOSC.c: setting typetags %d",x->x_typetags);
+ }
+
+
+static void sendOSC_connect(t_sendOSC *x, t_symbol *hostname,
+ t_floatarg fportno)
+{
+ int portno = fportno;
+ /* create a socket */
+
+ // make sure handle is available
+ if(x->x_htmsocket == 0) {
+ //
+ x->x_htmsocket = OpenHTMSocket(hostname->s_name, portno);
+ if (!x->x_htmsocket)
+ post("Couldn't open socket: ");
+ else {
+ post("connected to port %s:%d (hSock=%d)", hostname->s_name, portno, x->x_htmsocket);
+ outlet_float(x->x_obj.ob_outlet, 1);
+ }
+ }
+ else
+ perror("call to sendOSC_connect() against UNavailable socket handle");
+}
+
+void sendOSC_disconnect(t_sendOSC *x)
+{
+ if (x->x_htmsocket)
+ {
+ post("disconnecting htmsock (hSock=%d)...", x->x_htmsocket);
+ CloseHTMSocket(x->x_htmsocket);
+ x->x_htmsocket = 0; // {{raf}} semi-quasi-semaphorize this
+ outlet_float(x->x_obj.ob_outlet, 0);
+ }
+ else {
+ perror("call to sendOSC_disconnect() against unused socket handle");
+ }
+}
+
+void sendOSC_senduntyped(t_sendOSC *x, t_symbol *s, int argc, t_atom *argv)
+{
+ char* targv[MAXPDARG];
+ char tmparg[MAXPDSTRING];
+ char* tmp = tmparg;
+ //char testarg[MAXPDSTRING];
+ int c;
+
+ post("sendOSC: use typetags 0/1 message and plain send method so send untypetagged...");
+ return;
+
+ //atom_string(argv,testarg, MAXPDSTRING);
+ for (c=0;c<argc;c++) {
+ atom_string(argv+c,tmp, 80);
+ targv[c] = tmp;
+ tmp += strlen(tmp)+1;
+ }
+
+ // this sock needs to be larger than 0, not >= ..
+ if (x->x_htmsocket)
+ {
+ CommandLineMode(argc, targv, x->x_htmsocket);
+ // post("test %d", c);
+ }
+ else {
+ post("sendOSC: not connected");
+ }
+}
+
+//////////////////////////////////////////////////////////////////////
+// this is the real and only sending routine now, for both typed and
+// undtyped mode.
+
+static void sendOSC_sendtyped(t_sendOSC *x, t_symbol *s, int argc, t_atom *argv)
+{
+ char* targv[MAX_ARGS];
+ char tmparg[MAXPDSTRING];
+ char* tmp = tmparg;
+ int c;
+
+ char *messageName;
+ char *token;
+ typedArg args[MAX_ARGS];
+ int i,j;
+ int numArgs = 0;
+
+ messageName = "";
+#ifdef DEBUG
+ post ("sendOSC: messageName: %s", messageName);
+#endif
+
+
+
+ for (c=0;c<argc;c++) {
+ atom_string(argv+c,tmp, 80);
+
+#ifdef DEBUG
+ // post ("sendOSC: %d, %s",c, tmp);
+#endif
+
+ targv[c] = tmp;
+ tmp += strlen(tmp)+1;
+
+#ifdef DEBUG
+ // post ("sendOSC: %d, %s",c, targv[c]);
+#endif
+ }
+
+ // this sock needs to be larger than 0, not >= ..
+ if (x->x_htmsocket > 0)
+ {
+#ifdef DEBUG
+ post ("sendOSC: type tags? %d", useTypeTags);
+#endif
+
+ messageName = strtok(targv[0], ",");
+ j = 1;
+ for (i = j; i < argc; i++) {
+ token = strtok(targv[i],",");
+ args[i-j] = ParseToken(token);
+#ifdef DEBUG
+ printf("cell-cont: %s\n", targv[i]);
+ printf(" type-id: %d\n", args[i-j]);
+#endif
+ numArgs = i;
+ }
+
+
+ if(WriteMessage(x->x_oscbuf, messageName, numArgs, args)) {
+ post("sendOSC: usage error, write-msg failed: %s", OSC_errorMessage);
+ return;
+ }
+
+ if(!x->x_bundle) {
+ SendBuffer(x->x_htmsocket, x->x_oscbuf);
+ OSC_initBuffer(x->x_oscbuf, SC_BUFFER_SIZE, bufferForOSCbuf);
+ }
+
+ //CommandLineMode(argc, targv, x->x_htmsocket);
+ //useTypeTags = 0;
+ }
+ else {
+ post("sendOSC: not connected");
+ }
+}
+
+void sendOSC_send(t_sendOSC *x, t_symbol *s, int argc, t_atom *argv)
+{
+ if(!argc) {
+ post("not sending empty message.");
+ return;
+ }
+ if(x->x_typetags) {
+ useTypeTags = 1;
+ sendOSC_sendtyped(x,s,argc,argv);
+ useTypeTags = 0;
+ } else {
+ sendOSC_sendtyped(x,s,argc,argv);
+ }
+}
+
+static void sendOSC_free(t_sendOSC *x)
+{
+ sendOSC_disconnect(x);
+}
+
+#ifdef WIN32
+ OSC_API void sendOSC_setup(void) {
+#else
+ void sendOSC_setup(void) {
+#endif
+ sendOSC_class = class_new(gensym("sendOSC"), (t_newmethod)sendOSC_new,
+ (t_method)sendOSC_free,
+ sizeof(t_sendOSC), 0, A_DEFFLOAT, 0);
+ class_addmethod(sendOSC_class, (t_method)sendOSC_connect,
+ gensym("connect"), A_SYMBOL, A_FLOAT, 0);
+ class_addmethod(sendOSC_class, (t_method)sendOSC_disconnect,
+ gensym("disconnect"), 0);
+ class_addmethod(sendOSC_class, (t_method)sendOSC_settypetags,
+ gensym("typetags"),
+ A_FLOAT, 0);
+ class_addmethod(sendOSC_class, (t_method)sendOSC_send,
+ gensym("send"),
+ A_GIMME, 0);
+ class_addmethod(sendOSC_class, (t_method)sendOSC_send,
+ gensym("senduntyped"),
+ A_GIMME, 0);
+ class_addmethod(sendOSC_class, (t_method)sendOSC_send,
+ gensym("sendtyped"),
+ A_GIMME, 0);
+ class_addmethod(sendOSC_class, (t_method)sendOSC_openbundle,
+ gensym("["),
+ 0, 0);
+ class_addmethod(sendOSC_class, (t_method)sendOSC_closebundle,
+ gensym("]"),
+ 0, 0);
+ class_sethelpsymbol(sendOSC_class, gensym("sendOSC-help.pd"));
+}
+
+
+
+
+
+/* Exit status codes:
+ 0: successful
+ 2: Message(s) dropped because of buffer overflow
+ 3: Socket error
+ 4: Usage error
+ 5: Internal error
+*/
+
+void CommandLineMode(int argc, char *argv[], void *htmsocket) {
+ char *messageName;
+ char *token;
+ typedArg args[MAX_ARGS];
+ int i,j, numArgs;
+ OSCbuf buf[1];
+
+ OSC_initBuffer(buf, SC_BUFFER_SIZE, bufferForOSCbuf);
+
+ if (argc > 1) {
+ post("argc (%d) > 1", argc);
+ }
+
+ // ParseInteractiveLine(buf, argv);
+ messageName = strtok(argv[0], ",");
+
+ j = 1;
+ for (i = j; i < argc; i++) {
+ token = strtok(argv[i],",");
+ args[i-j] = ParseToken(token);
+#ifdef DEBUG
+ printf("cell-cont: %s\n", argv[i]);
+ printf(" type-id: %d\n", args[i-j]);
+#endif
+ numArgs = i;
+ }
+
+ if(WriteMessage(buf, messageName, numArgs, args)) {
+ post("sendOSC: usage error. write-msg failed: %s", OSC_errorMessage);
+ return;
+ }
+
+ SendBuffer(htmsocket, buf);
+}
+
+#define MAXMESG 2048
+
+void InteractiveMode(void *htmsocket) {
+ char mesg[MAXMESG];
+ OSCbuf buf[1];
+ int bundleDepth = 0; /* At first, we haven't seen "[". */
+
+ OSC_initBuffer(buf, SC_BUFFER_SIZE, bufferForOSCbuf);
+
+ while (fgets(mesg, MAXMESG, stdin) != NULL) {
+ if (mesg[0] == '\n') {
+ if (bundleDepth > 0) {
+ /* Ignore blank lines inside a group. */
+ } else {
+ /* blank line => repeat previous send */
+ SendBuffer(htmsocket, buf);
+ }
+ continue;
+ }
+
+ if (bundleDepth == 0) {
+ OSC_resetBuffer(buf);
+ }
+
+ if (mesg[0] == '[') {
+ OSCTimeTag tt = ParseTimeTag(mesg+1);
+ if (OSC_openBundle(buf, tt)) {
+ post("Problem opening bundle: %s\n", OSC_errorMessage);
+ OSC_resetBuffer(buf);
+ bundleDepth = 0;
+ continue;
+ }
+ bundleDepth++;
+ } else if (mesg[0] == ']' && mesg[1] == '\n' && mesg[2] == '\0') {
+ if (bundleDepth == 0) {
+ post("Unexpected ']': not currently in a bundle.\n");
+ } else {
+ if (OSC_closeBundle(buf)) {
+ post("Problem closing bundle: %s\n", OSC_errorMessage);
+ OSC_resetBuffer(buf);
+ bundleDepth = 0;
+ continue;
+ }
+
+ bundleDepth--;
+ if (bundleDepth == 0) {
+ SendBuffer(htmsocket, buf);
+ }
+ }
+ } else {
+ ParseInteractiveLine(buf, mesg);
+ if (bundleDepth != 0) {
+ /* Don't send anything until we close all bundles */
+ } else {
+ SendBuffer(htmsocket, buf);
+ }
+ }
+ }
+}
+
+OSCTimeTag ParseTimeTag(char *s) {
+ char *p, *newline;
+ typedArg arg;
+
+ p = s;
+ while (isspace(*p)) p++;
+ if (*p == '\0') return OSCTT_Immediately();
+
+ if (*p == '+') {
+ /* Time tag is for some time in the future. It should be a
+ number of seconds as an int or float */
+
+ newline = strchr(s, '\n');
+ if (newline != NULL) *newline = '\0';
+
+ p++; /* Skip '+' */
+ while (isspace(*p)) p++;
+
+ arg = ParseToken(p);
+ if (arg.type == STRING_osc) {
+ post("warning: inscrutable time tag request: %s\n", s);
+ return OSCTT_Immediately();
+ } else if (arg.type == INT_osc) {
+ return OSCTT_PlusSeconds(OSCTT_CurrentTime(),
+ (float) arg.datum.i);
+ } else if (arg.type == FLOAT_osc) {
+ return OSCTT_PlusSeconds(OSCTT_CurrentTime(), arg.datum.f);
+ } else {
+ error("This can't happen!");
+ }
+ }
+
+ if (isdigit(*p) || (*p >= 'a' && *p <='f') || (*p >= 'A' && *p <='F')) {
+ /* They specified the 8-byte tag in hex */
+ OSCTimeTag tt;
+ if (sscanf(p, "%llx", &tt) != 1) {
+ post("warning: couldn't parse time tag %s\n", s);
+ return OSCTT_Immediately();
+ }
+#ifndef HAS8BYTEINT
+ if (ntohl(1) != 1) {
+ /* tt is a struct of seconds and fractional part,
+ and this machine is little-endian, so sscanf
+ wrote each half of the time tag in the wrong half
+ of the struct. */
+ int temp;
+ temp = tt.seconds;
+ tt.seconds = tt.fraction ;
+ tt.fraction = temp;
+ }
+#endif
+ return tt;
+ }
+
+ post("warning: invalid time tag: %s\n", s);
+ return OSCTT_Immediately();
+}
+
+
+void ParseInteractiveLine(OSCbuf *buf, char *mesg) {
+ char *messageName, *token, *p;
+ typedArg args[MAX_ARGS];
+ int thisArg;
+
+ p = mesg;
+ while (isspace(*p)) p++;
+ if (*p == '\0') return;
+
+ messageName = p;
+
+ if (strcmp(messageName, "play\n") == 0) {
+ /* Special kludge feature to save typing */
+ typedArg arg;
+
+ if (OSC_openBundle(buf, OSCTT_Immediately())) {
+ post("Problem opening bundle: %s\n", OSC_errorMessage);
+ return;
+ }
+
+ arg.type = INT_osc;
+ arg.datum.i = 0;
+ WriteMessage(buf, "/voices/0/tp/timbre_index", 1, &arg);
+
+ arg.type = FLOAT_osc;
+ arg.datum.i = 0.0f;
+ WriteMessage(buf, "/voices/0/tm/goto", 1, &arg);
+
+ if (OSC_closeBundle(buf)) {
+ post("Problem closing bundle: %s\n", OSC_errorMessage);
+ }
+
+ return;
+ }
+
+ while (!isspace(*p) && *p != '\0') p++;
+ if (isspace(*p)) {
+ *p = '\0';
+ p++;
+ }
+
+ thisArg = 0;
+ while (*p != '\0') {
+ /* flush leading whitespace */
+ while (isspace(*p)) p++;
+ if (*p == '\0') break;
+
+ if (*p == '"') {
+ /* A string argument: scan for close quotes */
+ p++;
+ args[thisArg].type = STRING_osc;
+ args[thisArg].datum.s = p;
+
+ while (*p != '"') {
+ if (*p == '\0') {
+ post("Unterminated quote mark: ignoring line\n");
+ return;
+ }
+ p++;
+ }
+ *p = '\0';
+ p++;
+ } else {
+ token = p;
+ while (!isspace(*p) && (*p != '\0')) p++;
+ if (isspace(*p)) {
+ *p = '\0';
+ p++;
+ }
+ args[thisArg] = ParseToken(token);
+ }
+ thisArg++;
+ if (thisArg >= MAX_ARGS) {
+ post("Sorry, your message has more than MAX_ARGS (%d) arguments; ignoring the rest.\n",
+ MAX_ARGS);
+ break;
+ }
+ }
+
+ if (WriteMessage(buf, messageName, thisArg, args) != 0) {
+ post("Problem sending message: %s\n", OSC_errorMessage);
+ }
+}
+
+typedArg ParseToken(char *token) {
+ char *p = token;
+ typedArg returnVal;
+
+ /* It might be an int, a float, or a string */
+
+ if (*p == '-') p++;
+
+ if (isdigit(*p) || *p == '.') {
+ while (isdigit(*p)) p++;
+ if (*p == '\0') {
+ returnVal.type = INT_osc;
+ returnVal.datum.i = atoi(token);
+ return returnVal;
+ }
+ if (*p == '.') {
+ p++;
+ while (isdigit(*p)) p++;
+ if (*p == '\0') {
+ returnVal.type = FLOAT_osc;
+ returnVal.datum.f = atof(token);
+ return returnVal;
+ }
+ }
+ }
+
+ returnVal.type = STRING_osc;
+ returnVal.datum.s = token;
+ return returnVal;
+}
+
+int WriteMessage(OSCbuf *buf, char *messageName, int numArgs, typedArg *args) {
+ int j, returnVal;
+ const int wmERROR = -1;
+
+ returnVal = 0;
+
+#ifdef DEBUG
+ printf("WriteMessage: %s ", messageName);
+
+ for (j = 0; j < numArgs; j++) {
+ switch (args[j].type) {
+ case INT_osc:
+ printf("%d ", args[j].datum.i);
+ break;
+
+ case FLOAT_osc:
+ printf("%f ", args[j].datum.f);
+ break;
+
+ case STRING_osc:
+ printf("%s ", args[j].datum.s);
+ break;
+
+ default:
+ error("Unrecognized arg type, (not exiting)");
+ return(wmERROR);
+ }
+ }
+ printf("\n");
+#endif
+
+ if (!useTypeTags) {
+ returnVal = OSC_writeAddress(buf, messageName);
+ if (returnVal) {
+ post("Problem writing address: %s\n", OSC_errorMessage);
+ }
+ } else {
+ /* First figure out the type tags */
+ char typeTags[MAX_ARGS+2];
+ int i;
+
+ typeTags[0] = ',';
+
+ for (i = 0; i < numArgs; ++i) {
+ switch (args[i].type) {
+ case INT_osc:
+ typeTags[i+1] = 'i';
+ break;
+
+ case FLOAT_osc:
+ typeTags[i+1] = 'f';
+ break;
+
+ case STRING_osc:
+ typeTags[i+1] = 's';
+ break;
+
+ default:
+ error("Unrecognized arg type (not exiting)");
+ return(wmERROR);
+ }
+ }
+ typeTags[i+1] = '\0';
+
+ returnVal = OSC_writeAddressAndTypes(buf, messageName, typeTags);
+ if (returnVal) {
+ post("Problem writing address: %s\n", OSC_errorMessage);
+ }
+ }
+
+ for (j = 0; j < numArgs; j++) {
+ switch (args[j].type) {
+ case INT_osc:
+ if ((returnVal = OSC_writeIntArg(buf, args[j].datum.i)) != 0) {
+ return returnVal;
+ }
+ break;
+
+ case FLOAT_osc:
+ if ((returnVal = OSC_writeFloatArg(buf, args[j].datum.f)) != 0) {
+ return returnVal;
+ }
+ break;
+
+ case STRING_osc:
+ if ((returnVal = OSC_writeStringArg(buf, args[j].datum.s)) != 0) {
+ return returnVal;
+ }
+ break;
+
+ default:
+ error("Unrecognized arg type (not exiting)");
+ returnVal = wmERROR;
+ }
+ }
+ return returnVal;
+}
+
+void SendBuffer(void *htmsocket, OSCbuf *buf) {
+#ifdef DEBUG
+ printf("Sending buffer...\n");
+#endif
+ if (OSC_isBufferEmpty(buf)) {
+ post("SendBuffer() called but buffer empty");
+ return;
+ }
+ if (!OSC_isBufferDone(buf)) {
+ error("SendBuffer() called but buffer not ready!, not exiting");
+ return; //{{raf}}
+ }
+ SendData(htmsocket, OSC_packetSize(buf), OSC_getPacket(buf));
+}
+
+void SendData(void *htmsocket, int size, char *data) {
+ if (!SendHTMSocket(htmsocket, size, data)) {
+ post("SendData::SendHTMSocket()failure -- not connected");
+ CloseHTMSocket(htmsocket);
+ }
+}
+
+
+
+/* ----------------------
+ OSC-client code
+
+ */
+
+/* Here are the possible values of the state field: */
+
+#define EMPTY 0 /* Nothing written to packet yet */
+#define ONE_MSG_ARGS 1 /* Packet has a single message; gathering arguments */
+#define NEED_COUNT 2 /* Just opened a bundle; must write message name or
+ open another bundle */
+#define GET_ARGS 3 /* Getting arguments to a message. If we see a message
+ name or a bundle open/close then the current message
+ will end. */
+#define DONE 4 /* All open bundles have been closed, so can't write
+ anything else */
+
+#ifdef WIN32
+ #include <winsock2.h>
+ #include <io.h>
+ #include <stdio.h>
+ #include <errno.h>
+ #include <fcntl.h>
+ #include <sys/types.h>
+ #include <sys/stat.h>
+#endif
+
+#ifdef __APPLE__
+ #include <sys/types.h>
+#endif
+
+#ifdef unix
+ #include <netinet/in.h>
+ #include <stdio.h>
+#endif
+
+
+char *OSC_errorMessage;
+
+static int OSC_padString(char *dest, char *str);
+static int OSC_padStringWithAnExtraStupidComma(char *dest, char *str);
+static int OSC_WritePadding(char *dest, int i);
+static int CheckTypeTag(OSCbuf *buf, char expectedType);
+
+void OSC_initBuffer(OSCbuf *buf, int size, char *byteArray) {
+ buf->buffer = byteArray;
+ buf->size = size;
+ OSC_resetBuffer(buf);
+}
+
+void OSC_resetBuffer(OSCbuf *buf) {
+ buf->bufptr = buf->buffer;
+ buf->state = EMPTY;
+ buf->bundleDepth = 0;
+ buf->prevCounts[0] = 0;
+ buf->gettingFirstUntypedArg = 0;
+ buf->typeStringPtr = 0;
+}
+
+int OSC_isBufferEmpty(OSCbuf *buf) {
+ return buf->bufptr == buf->buffer;
+}
+
+int OSC_freeSpaceInBuffer(OSCbuf *buf) {
+ return buf->size - (buf->bufptr - buf->buffer);
+}
+
+int OSC_isBufferDone(OSCbuf *buf) {
+ return (buf->state == DONE || buf->state == ONE_MSG_ARGS);
+}
+
+char *OSC_getPacket(OSCbuf *buf) {
+#ifdef ERROR_CHECK_GETPACKET
+ if (buf->state == DONE || buf->state == ONE_MSG_ARGS) {
+ return buf->buffer;
+ } else {
+ OSC_errorMessage = "Packet has unterminated bundles";
+ return 0;
+ }
+#else
+ return buf->buffer;
+#endif
+}
+
+int OSC_packetSize(OSCbuf *buf) {
+#ifdef ERROR_CHECK_PACKETSIZE
+ if (buf->state == DONE || buf->state == ONE_MSG_ARGS) {
+ return (buf->bufptr - buf->buffer);
+ } else {
+ OSC_errorMessage = "Packet has unterminated bundles";
+ return 0;
+ }
+#else
+ return (buf->bufptr - buf->buffer);
+#endif
+}
+
+#define CheckOverflow(buf, bytesNeeded) { if ((bytesNeeded) > OSC_freeSpaceInBuffer(buf)) {OSC_errorMessage = "buffer overflow"; return 1;}}
+
+static void PatchMessageSize(OSCbuf *buf) {
+ int4byte size;
+ size = buf->bufptr - ((char *) buf->thisMsgSize) - 4;
+ *(buf->thisMsgSize) = htonl(size);
+}
+
+int OSC_openBundle(OSCbuf *buf, OSCTimeTag tt) {
+ if (buf->state == ONE_MSG_ARGS) {
+ OSC_errorMessage = "Can't open a bundle in a one-message packet";
+ return 3;
+ }
+
+ if (buf->state == DONE) {
+ OSC_errorMessage = "This packet is finished; can't open a new bundle";
+ return 4;
+ }
+
+ if (++(buf->bundleDepth) >= MAX_BUNDLE_NESTING) {
+ OSC_errorMessage = "Bundles nested too deeply; change MAX_BUNDLE_NESTING in OpenSoundControl.h";
+ return 2;
+ }
+
+ if (CheckTypeTag(buf, '\0')) return 9;
+
+ if (buf->state == GET_ARGS) {
+ PatchMessageSize(buf);
+ }
+
+ if (buf->state == EMPTY) {
+ /* Need 16 bytes for "#bundle" and time tag */
+ CheckOverflow(buf, 16);
+ } else {
+ /* This bundle is inside another bundle, so we need to leave
+ a blank size count for the size of this current bundle. */
+ CheckOverflow(buf, 20);
+ *((int4byte *)buf->bufptr) = 0xaaaaaaaa;
+ buf->prevCounts[buf->bundleDepth] = (int4byte *)buf->bufptr;
+
+ buf->bufptr += 4;
+ }
+
+ buf->bufptr += OSC_padString(buf->bufptr, "#bundle");
+
+
+ *((OSCTimeTag *) buf->bufptr) = tt;
+
+ if (htonl(1) != 1) {
+ /* Byte swap the 8-byte integer time tag */
+ int4byte *intp = (int4byte *)buf->bufptr;
+ intp[0] = htonl(intp[0]);
+ intp[1] = htonl(intp[1]);
+
+#ifdef HAS8BYTEINT
+ { /* tt is a 64-bit int so we have to swap the two 32-bit words.
+ (Otherwise tt is a struct of two 32-bit words, and even though
+ each word was wrong-endian, they were in the right order
+ in the struct.) */
+ int4byte temp = intp[0];
+ intp[0] = intp[1];
+ intp[1] = temp;
+ }
+#endif
+ }
+
+ buf->bufptr += sizeof(OSCTimeTag);
+
+ buf->state = NEED_COUNT;
+
+ buf->gettingFirstUntypedArg = 0;
+ buf->typeStringPtr = 0;
+ return 0;
+}
+
+
+int OSC_closeBundle(OSCbuf *buf) {
+ if (buf->bundleDepth == 0) {
+ /* This handles EMPTY, ONE_MSG, ARGS, and DONE */
+ OSC_errorMessage = "Can't close bundle; no bundle is open!";
+ return 5;
+ }
+
+ if (CheckTypeTag(buf, '\0')) return 9;
+
+ if (buf->state == GET_ARGS) {
+ PatchMessageSize(buf);
+ }
+
+ if (buf->bundleDepth == 1) {
+ /* Closing the last bundle: No bundle size to patch */
+ buf->state = DONE;
+ } else {
+ /* Closing a sub-bundle: patch bundle size */
+ int size = buf->bufptr - ((char *) buf->prevCounts[buf->bundleDepth]) - 4;
+ *(buf->prevCounts[buf->bundleDepth]) = htonl(size);
+ buf->state = NEED_COUNT;
+ }
+
+ --buf->bundleDepth;
+ buf->gettingFirstUntypedArg = 0;
+ buf->typeStringPtr = 0;
+ return 0;
+}
+
+
+int OSC_closeAllBundles(OSCbuf *buf) {
+ if (buf->bundleDepth == 0) {
+ /* This handles EMPTY, ONE_MSG, ARGS, and DONE */
+ OSC_errorMessage = "Can't close all bundles; no bundle is open!";
+ return 6;
+ }
+
+ if (CheckTypeTag(buf, '\0')) return 9;
+
+ while (buf->bundleDepth > 0) {
+ OSC_closeBundle(buf);
+ }
+ buf->typeStringPtr = 0;
+ return 0;
+}
+
+int OSC_writeAddress(OSCbuf *buf, char *name) {
+ int4byte paddedLength;
+
+ if (buf->state == ONE_MSG_ARGS) {
+ OSC_errorMessage = "This packet is not a bundle, so you can't write another address";
+ return 7;
+ }
+
+ if (buf->state == DONE) {
+ OSC_errorMessage = "This packet is finished; can't write another address";
+ return 8;
+ }
+
+ if (CheckTypeTag(buf, '\0')) return 9;
+
+ paddedLength = OSC_effectiveStringLength(name);
+
+ if (buf->state == EMPTY) {
+ /* This will be a one-message packet, so no sizes to worry about */
+ CheckOverflow(buf, paddedLength);
+ buf->state = ONE_MSG_ARGS;
+ } else {
+ /* GET_ARGS or NEED_COUNT */
+ CheckOverflow(buf, 4+paddedLength);
+ if (buf->state == GET_ARGS) {
+ /* Close the old message */
+ PatchMessageSize(buf);
+ }
+ buf->thisMsgSize = (int4byte *)buf->bufptr;
+ *(buf->thisMsgSize) = 0xbbbbbbbb;
+ buf->bufptr += 4;
+ buf->state = GET_ARGS;
+ }
+
+ /* Now write the name */
+ buf->bufptr += OSC_padString(buf->bufptr, name);
+ buf->typeStringPtr = 0;
+ buf->gettingFirstUntypedArg = 1;
+
+ return 0;
+}
+
+int OSC_writeAddressAndTypes(OSCbuf *buf, char *name, char *types) {
+ int result;
+ int4byte paddedLength;
+
+ if (CheckTypeTag(buf, '\0')) return 9;
+
+ result = OSC_writeAddress(buf, name);
+
+ if (result) return result;
+
+ paddedLength = OSC_effectiveStringLength(types);
+
+ CheckOverflow(buf, paddedLength);
+
+ buf->typeStringPtr = buf->bufptr + 1; /* skip comma */
+ buf->bufptr += OSC_padString(buf->bufptr, types);
+
+ buf->gettingFirstUntypedArg = 0;
+ return 0;
+}
+
+static int CheckTypeTag(OSCbuf *buf, char expectedType) {
+ if (buf->typeStringPtr) {
+ if (*(buf->typeStringPtr) != expectedType) {
+ if (expectedType == '\0') {
+ OSC_errorMessage =
+ "According to the type tag I expected more arguments.";
+ } else if (*(buf->typeStringPtr) == '\0') {
+ OSC_errorMessage =
+ "According to the type tag I didn't expect any more arguments.";
+ } else {
+ OSC_errorMessage =
+ "According to the type tag I expected an argument of a different type.";
+ printf("* Expected %c, string now %s\n", expectedType, buf->typeStringPtr);
+ }
+ return 9;
+ }
+ ++(buf->typeStringPtr);
+ }
+ return 0;
+}
+
+
+int OSC_writeFloatArg(OSCbuf *buf, float arg) {
+ int4byte *intp;
+ //int result;
+
+ CheckOverflow(buf, 4);
+
+ if (CheckTypeTag(buf, 'f')) return 9;
+
+ /* Pretend arg is a long int so we can use htonl() */
+ intp = ((int4byte *) &arg);
+ *((int4byte *) buf->bufptr) = htonl(*intp);
+
+ buf->bufptr += 4;
+
+ buf->gettingFirstUntypedArg = 0;
+ return 0;
+}
+
+
+
+int OSC_writeFloatArgs(OSCbuf *buf, int numFloats, float *args) {
+ int i;
+ int4byte *intp;
+
+ CheckOverflow(buf, 4 * numFloats);
+
+ /* Pretend args are long ints so we can use htonl() */
+ intp = ((int4byte *) args);
+
+ for (i = 0; i < numFloats; i++) {
+ if (CheckTypeTag(buf, 'f')) return 9;
+ *((int4byte *) buf->bufptr) = htonl(intp[i]);
+ buf->bufptr += 4;
+ }
+
+ buf->gettingFirstUntypedArg = 0;
+ return 0;
+}
+
+int OSC_writeIntArg(OSCbuf *buf, int4byte arg) {
+ CheckOverflow(buf, 4);
+ if (CheckTypeTag(buf, 'i')) return 9;
+
+ *((int4byte *) buf->bufptr) = htonl(arg);
+ buf->bufptr += 4;
+
+ buf->gettingFirstUntypedArg = 0;
+ return 0;
+}
+
+int OSC_writeStringArg(OSCbuf *buf, char *arg) {
+ int len;
+
+ if (CheckTypeTag(buf, 's')) return 9;
+
+ len = OSC_effectiveStringLength(arg);
+
+ if (buf->gettingFirstUntypedArg && arg[0] == ',') {
+ /* This un-type-tagged message starts with a string
+ that starts with a comma, so we have to escape it
+ (with a double comma) so it won't look like a type
+ tag string. */
+
+ CheckOverflow(buf, len+4); /* Too conservative */
+ buf->bufptr +=
+ OSC_padStringWithAnExtraStupidComma(buf->bufptr, arg);
+
+ } else {
+ CheckOverflow(buf, len);
+ buf->bufptr += OSC_padString(buf->bufptr, arg);
+ }
+
+ buf->gettingFirstUntypedArg = 0;
+ return 0;
+
+}
+
+/* String utilities */
+
+#define STRING_ALIGN_PAD 4
+int OSC_effectiveStringLength(char *string) {
+ int len = strlen(string) + 1; /* We need space for the null char. */
+
+ /* Round up len to next multiple of STRING_ALIGN_PAD to account for alignment padding */
+ if ((len % STRING_ALIGN_PAD) != 0) {
+ len += STRING_ALIGN_PAD - (len % STRING_ALIGN_PAD);
+ }
+ return len;
+}
+
+static int OSC_padString(char *dest, char *str) {
+ int i;
+
+ for (i = 0; str[i] != '\0'; i++) {
+ dest[i] = str[i];
+ }
+
+ return OSC_WritePadding(dest, i);
+}
+
+static int OSC_padStringWithAnExtraStupidComma(char *dest, char *str) {
+ int i;
+
+ dest[0] = ',';
+ for (i = 0; str[i] != '\0'; i++) {
+ dest[i+1] = str[i];
+ }
+
+ return OSC_WritePadding(dest, i+1);
+}
+
+static int OSC_WritePadding(char *dest, int i) {
+ dest[i] = '\0';
+ i++;
+
+ for (; (i % STRING_ALIGN_PAD) != 0; i++) {
+ dest[i] = '\0';
+ }
+
+ return i;
+}
+
+
+/*
+Written by Matt Wright, The Center for New Music and Audio Technologies,
+University of California, Berkeley. Copyright (c) 1996,97,98,99,2000,01,02,03
+The Regents of the University of California (Regents).
+
+Permission to use, copy, modify, distribute, and distribute modified versions
+of this software and its documentation without fee and without a signed
+licensing agreement, is hereby granted, provided that the above copyright
+notice, this paragraph and the following two paragraphs appear in all copies,
+modifications, and distributions.
+
+IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
+SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING
+OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF REGENTS HAS
+BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE. THE SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED
+HEREUNDER IS PROVIDED "AS IS". REGENTS HAS NO OBLIGATION TO PROVIDE
+MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
+
+
+The OSC webpage is http://cnmat.cnmat.berkeley.edu/OpenSoundControl
+*/
+
+
+/* sendOSC.c
+
+ Matt Wright, 6/3/97
+ based on sendOSC.c, which was based on a version by Adrian Freed
+
+ Text-based OpenSoundControl client. User can enter messages via command
+ line arguments or standard input.
+
+ Version 0.1: "play" feature
+ Version 0.2: Message type tags.
+
+ pd version branched from http://www.cnmat.berkeley.edu/OpenSoundControl/src/sendOSC/sendOSC.c
+ -------------
+ -- added bundle stuff to send. jdl 20020416
+ -- tweaks for Win32 www.zeggz.com/raf 13-April-2002
+ -- ost_at_test.at + i22_at_test.at, 2000-2002
+ modified to compile as pd externel
+*/
+
+#define MAX_ARGS 2000
+#define SC_BUFFER_SIZE 64000
+
+#include "m_pd.h"
+#include "OSC-client.h"
+
+#include <string.h>
+#include <sys/types.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+
+#ifdef WIN32
+#include <winsock2.h>
+#include <io.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <winsock2.h>
+#include <ctype.h>
+#include <signal.h>
+#else
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <rpc/rpc.h>
+#include <sys/times.h>
+#include <sys/param.h>
+#include <sys/time.h>
+#include <sys/ioctl.h>
+#include <netdb.h>
+#endif
+
+#ifdef __APPLE__
+ #include <string.h>
+#endif
+
+#define UNIXDG_PATH "/tmp/htm"
+#define UNIXDG_TMP "/tmp/htm.XXXXXX"
+
+
+
+OSCTimeTag OSCTT_Immediately(void) {
+ OSCTimeTag result;
+ result.seconds = 0;
+ result.fraction = 1;
+ return result;
+}
+
+
+OSCTimeTag OSCTT_CurrentTime(void) {
+ OSCTimeTag result;
+ result.seconds = 0;
+ result.fraction = 1;
+ return result;
+}
+
+OSCTimeTag OSCTT_PlusSeconds(OSCTimeTag original, float secondsOffset) {
+ OSCTimeTag result;
+ result.seconds = 0;
+ result.fraction = 1;
+ return result;
+}
+
+
+typedef int bool;
+
+typedef struct
+{
+ float srate;
+
+ struct sockaddr_in serv_addr; /* udp socket */
+ #ifndef WIN32
+ struct sockaddr_un userv_addr; /* UNIX socket */
+ #endif
+ int sockfd; /* socket file descriptor */
+ int index, len,uservlen;
+ void *addr;
+ int id;
+} desc;
+
+
+/* open a socket for HTM communication to given host on given portnumber */
+/* if host is 0 then UNIX protocol is used (i.e. local communication */
+void *OpenHTMSocket(char *host, int portnumber)
+{
+ struct sockaddr_in cl_addr;
+ #ifndef WIN32
+ int sockfd;
+ struct sockaddr_un ucl_addr;
+ #else
+ unsigned int sockfd;
+ #endif
+
+ desc *o;
+ int oval = 1;
+ o = malloc(sizeof(*o));
+ if(!o) return 0;
+
+ #ifndef WIN32
+
+ if(!host)
+ {
+ char *mktemp(char *);
+ int clilen;
+ o->len = sizeof(ucl_addr);
+ /*
+ * Fill in the structure "userv_addr" with the address of the
+ * server that we want to send to.
+ */
+
+ bzero((char *) &o->userv_addr, sizeof(o->userv_addr));
+ o->userv_addr.sun_family = AF_UNIX;
+ strcpy(o->userv_addr.sun_path, UNIXDG_PATH);
+ sprintf(o->userv_addr.sun_path+strlen(o->userv_addr.sun_path), "%d", portnumber);
+ o->uservlen = sizeof(o->userv_addr.sun_family) + strlen(o->userv_addr.sun_path);
+ o->addr = &(o->userv_addr);
+ /*
+ * Open a socket (a UNIX domain datagram socket).
+ */
+
+ if ( (sockfd = socket(AF_UNIX, SOCK_DGRAM, 0)) >= 0)
+ {
+ /*
+ * Bind a local address for us.
+ * In the UNIX domain we have to choose our own name (that
+ * should be unique). We'll use mktemp() to create a unique
+ * pathname, based on our process id.
+ */
+
+ bzero((char *) &ucl_addr, sizeof(ucl_addr)); /* zero out */
+ ucl_addr.sun_family = AF_UNIX;
+ strcpy(ucl_addr.sun_path, UNIXDG_TMP);
+
+ mktemp(ucl_addr.sun_path);
+ clilen = sizeof(ucl_addr.sun_family) + strlen(ucl_addr.sun_path);
+
+ if (bind(sockfd, (struct sockaddr *) &ucl_addr, clilen) < 0)
+ {
+ perror("client: can't bind local address");
+ close(sockfd);
+ sockfd = -1;
+ }
+ }
+ else
+ perror("unable to make socket\n");
+
+ }else
+
+ #endif
+
+ {
+ /*
+ * Fill in the structure "serv_addr" with the address of the
+ * server that we want to send to.
+ */
+ o->len = sizeof(cl_addr);
+
+ #ifdef WIN32
+ ZeroMemory((char *)&o->serv_addr, sizeof(o->serv_addr));
+ #else
+ bzero((char *)&o->serv_addr, sizeof(o->serv_addr));
+ #endif
+
+ o->serv_addr.sin_family = AF_INET;
+
+ /* MW 6/6/96: Call gethostbyname() instead of inet_addr(),
+ so that host can be either an Internet host name (e.g.,
+ "les") or an Internet address in standard dot notation
+ (e.g., "128.32.122.13") */
+ {
+ struct hostent *hostsEntry;
+ unsigned long address;
+
+ hostsEntry = gethostbyname(host);
+ if (hostsEntry == NULL) {
+ fprintf(stderr, "Couldn't decipher host name \"%s\"\n", host);
+ #ifndef WIN32
+ herror(NULL);
+ #endif
+ return 0;
+ }
+ address = *((unsigned long *) hostsEntry->h_addr_list[0]);
+ o->serv_addr.sin_addr.s_addr = address;
+ }
+
+ /* was: o->serv_addr.sin_addr.s_addr = inet_addr(host); */
+
+ /* End MW changes */
+
+ /*
+ * Open a socket (a UDP domain datagram socket).
+ */
+
+
+ #ifdef WIN32
+ o->serv_addr.sin_port = htons((USHORT)portnumber);
+ o->addr = &(o->serv_addr);
+ if((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) != INVALID_SOCKET) {
+ ZeroMemory((char *)&cl_addr, sizeof(cl_addr));
+ cl_addr.sin_family = AF_INET;
+ cl_addr.sin_addr.s_addr = htonl(INADDR_ANY);
+ cl_addr.sin_port = htons(0);
+
+ // enable broadcast: jdl ~2003
+ if(setsockopt(sockfd, SOL_SOCKET, SO_BROADCAST, &oval, sizeof(int)) == -1) {
+ perror("setsockopt");
+ }
+
+ if(bind(sockfd, (struct sockaddr *) &cl_addr, sizeof(cl_addr)) < 0) {
+ perror("could not bind\n");
+ closesocket(sockfd);
+ sockfd = -1;
+ }
+ }
+ else { perror("unable to make socket\n");}
+ #else
+ o->serv_addr.sin_port = htons(portnumber);
+ o->addr = &(o->serv_addr);
+ if((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) >= 0) {
+ bzero((char *)&cl_addr, sizeof(cl_addr));
+ cl_addr.sin_family = AF_INET;
+ cl_addr.sin_addr.s_addr = htonl(INADDR_ANY);
+ cl_addr.sin_port = htons(0);
+
+ // enable broadcast: jdl ~2003
+ if(setsockopt(sockfd, SOL_SOCKET, SO_BROADCAST, &oval, sizeof(int)) == -1) {
+ perror("setsockopt");
+ }
+
+ if(bind(sockfd, (struct sockaddr *) &cl_addr, sizeof(cl_addr)) < 0) {
+ perror("could not bind\n");
+ close(sockfd);
+ sockfd = -1;
+ }
+ }
+ else { perror("unable to make socket\n");}
+ #endif
+ }
+ #ifdef WIN32
+ if(sockfd == INVALID_SOCKET) {
+ #else
+ if(sockfd < 0) {
+ #endif
+ free(o);
+ o = 0;
+ }
+ else
+ o->sockfd = sockfd;
+ return o;
+}
+
+static bool sendudp(const struct sockaddr *sp, int sockfd,int length, int count, void *b)
+{
+ int rcount;
+ if((rcount=sendto(sockfd, b, count, 0, sp, length)) != count)
+ {
+ printf("sockfd %d count %d rcount %dlength %d\n", sockfd,count,rcount,length);
+ return FALSE;
+ }
+ return TRUE;
+}
+
+bool SendHTMSocket(void *htmsendhandle, int length_in_bytes, void *buffer)
+{
+ desc *o = (desc *)htmsendhandle;
+ return sendudp(o->addr, o->sockfd, o->len, length_in_bytes, buffer);
+}
+void CloseHTMSocket(void *htmsendhandle)
+{
+ desc *o = (desc *)htmsendhandle;
+ #ifdef WIN32
+ if(SOCKET_ERROR == closesocket(o->sockfd)) {
+ perror("CloseHTMSocket::closesocket failed\n");
+ return;
+ }
+ #else
+ if(close(o->sockfd) == -1)
+ {
+ perror("CloseHTMSocket::closesocket failed");
+ return;
+ }
+ #endif
+
+ free(o);
+}
+
+
+///////////////////////
+// from sendOSC
+
+typedef struct {
+ //enum {INT, FLOAT, STRING} type;
+ enum {INT_osc, FLOAT_osc, STRING_osc} type;
+ union {
+ int i;
+ float f;
+ char *s;
+ } datum;
+} typedArg;
+
+void CommandLineMode(int argc, char *argv[], void *htmsocket);
+OSCTimeTag ParseTimeTag(char *s);
+void ParseInteractiveLine(OSCbuf *buf, char *mesg);
+typedArg ParseToken(char *token);
+int WriteMessage(OSCbuf *buf, char *messageName, int numArgs, typedArg *args);
+void SendBuffer(void *htmsocket, OSCbuf *buf);
+void SendData(void *htmsocket, int size, char *data);
+/* defined in OSC-system-dependent.c now */
+
+//static void *htmsocket;
+static int exitStatus = 0;
+static int useTypeTags = 0;
+
+static char bufferForOSCbuf[SC_BUFFER_SIZE];
+
+
+/////////
+// end from sendOSC
+
+static t_class *sendOSC_class;
+
+typedef struct _sendOSC
+{
+ t_object x_obj;
+ int x_protocol; // UDP/TCP (udp only atm)
+ t_int x_typetags; // typetag flag
+ void *x_htmsocket; // sending socket
+ int x_bundle; // bundle open flag
+ OSCbuf x_oscbuf[1]; // OSCbuffer
+ t_outlet *x_bdpthout;// bundle-depth floatoutlet
+} t_sendOSC;
+
+static void *sendOSC_new(t_floatarg udpflag)
+{
+ t_sendOSC *x = (t_sendOSC *)pd_new(sendOSC_class);
+ outlet_new(&x->x_obj, &s_float);
+ x->x_htmsocket = 0; // {{raf}}
+ // set udp
+ x->x_protocol = SOCK_STREAM;
+ // set typetags to 1 by default
+ x->x_typetags = 1;
+ // bunlde is closed
+ x->x_bundle = 0;
+ OSC_initBuffer(x->x_oscbuf, SC_BUFFER_SIZE, bufferForOSCbuf);
+ x->x_bdpthout = outlet_new(&x->x_obj, 0); // outlet_float();
+ //x->x_oscbuf =
+ return (x);
+}
+
+
+void sendOSC_openbundle(t_sendOSC *x)
+{
+ if (x->x_oscbuf->bundleDepth + 1 >= MAX_BUNDLE_NESTING ||
+ OSC_openBundle(x->x_oscbuf, OSCTT_Immediately()))
+ {
+ post("Problem opening bundle: %s\n", OSC_errorMessage);
+ return;
+ }
+ x->x_bundle = 1;
+ outlet_float(x->x_bdpthout, (float)x->x_oscbuf->bundleDepth);
+}
+
+static void sendOSC_closebundle(t_sendOSC *x)
+{
+ if (OSC_closeBundle(x->x_oscbuf)) {
+ post("Problem closing bundle: %s\n", OSC_errorMessage);
+ return;
+ }
+ outlet_float(x->x_bdpthout, (float)x->x_oscbuf->bundleDepth);
+ // in bundle mode we send when bundle is closed?
+ if(!OSC_isBufferEmpty(x->x_oscbuf) > 0 && OSC_isBufferDone(x->x_oscbuf)) {
+ // post("x_oscbuf: something inside me?");
+ if (x->x_htmsocket) {
+ SendBuffer(x->x_htmsocket, x->x_oscbuf);
+ } else {
+ post("sendOSC: not connected");
+ }
+ OSC_initBuffer(x->x_oscbuf, SC_BUFFER_SIZE, bufferForOSCbuf);
+ x->x_bundle = 0;
+ return;
+ }
+ // post("x_oscbuf: something went wrong");
+}
+
+static void sendOSC_settypetags(t_sendOSC *x, t_float *f)
+ {
+ x->x_typetags = (int)f;
+ post("sendOSC.c: setting typetags %d",x->x_typetags);
+ }
+
+
+static void sendOSC_connect(t_sendOSC *x, t_symbol *hostname,
+ t_floatarg fportno)
+{
+ int portno = fportno;
+ /* create a socket */
+
+ // make sure handle is available
+ if(x->x_htmsocket == 0) {
+ //
+ x->x_htmsocket = OpenHTMSocket(hostname->s_name, portno);
+ if (!x->x_htmsocket)
+ post("Couldn't open socket: ");
+ else {
+ post("connected to port %s:%d (hSock=%d)", hostname->s_name, portno, x->x_htmsocket);
+ outlet_float(x->x_obj.ob_outlet, 1);
+ }
+ }
+ else
+ perror("call to sendOSC_connect() against UNavailable socket handle");
+}
+
+void sendOSC_disconnect(t_sendOSC *x)
+{
+ if (x->x_htmsocket)
+ {
+ post("disconnecting htmsock (hSock=%d)...", x->x_htmsocket);
+ CloseHTMSocket(x->x_htmsocket);
+ x->x_htmsocket = 0; // {{raf}} semi-quasi-semaphorize this
+ outlet_float(x->x_obj.ob_outlet, 0);
+ }
+ else {
+ perror("call to sendOSC_disconnect() against unused socket handle");
+ }
+}
+
+void sendOSC_senduntyped(t_sendOSC *x, t_symbol *s, int argc, t_atom *argv)
+{
+ char* targv[MAXPDARG];
+ char tmparg[MAXPDSTRING];
+ char* tmp = tmparg;
+ //char testarg[MAXPDSTRING];
+ int c;
+
+ post("sendOSC: use typetags 0/1 message and plain send method so send untypetagged...");
+ return;
+
+ //atom_string(argv,testarg, MAXPDSTRING);
+ for (c=0;c<argc;c++) {
+ atom_string(argv+c,tmp, 80);
+ targv[c] = tmp;
+ tmp += strlen(tmp)+1;
+ }
+
+ // this sock needs to be larger than 0, not >= ..
+ if (x->x_htmsocket)
+ {
+ CommandLineMode(argc, targv, x->x_htmsocket);
+ // post("test %d", c);
+ }
+ else {
+ post("sendOSC: not connected");
+ }
+}
+
+//////////////////////////////////////////////////////////////////////
+// this is the real and only sending routine now, for both typed and
+// undtyped mode.
+
+static void sendOSC_sendtyped(t_sendOSC *x, t_symbol *s, int argc, t_atom *argv)
+{
+ char* targv[MAX_ARGS];
+ char tmparg[MAXPDSTRING];
+ char* tmp = tmparg;
+ int c;
+
+ char *messageName;
+ char *token;
+ typedArg args[MAX_ARGS];
+ int i,j;
+ int numArgs = 0;
+
+ messageName = "";
+#ifdef DEBUG
+ post ("sendOSC: messageName: %s", messageName);
+#endif
+
+
+
+ for (c=0;c<argc;c++) {
+ atom_string(argv+c,tmp, 80);
+
+#ifdef DEBUG
+ // post ("sendOSC: %d, %s",c, tmp);
+#endif
+
+ targv[c] = tmp;
+ tmp += strlen(tmp)+1;
+
+#ifdef DEBUG
+ // post ("sendOSC: %d, %s",c, targv[c]);
+#endif
+ }
+
+ // this sock needs to be larger than 0, not >= ..
+ if (x->x_htmsocket > 0)
+ {
+#ifdef DEBUG
+ post ("sendOSC: type tags? %d", useTypeTags);
+#endif
+
+ messageName = strtok(targv[0], ",");
+ j = 1;
+ for (i = j; i < argc; i++) {
+ token = strtok(targv[i],",");
+ args[i-j] = ParseToken(token);
+#ifdef DEBUG
+ printf("cell-cont: %s\n", targv[i]);
+ printf(" type-id: %d\n", args[i-j]);
+#endif
+ numArgs = i;
+ }
+
+
+ if(WriteMessage(x->x_oscbuf, messageName, numArgs, args)) {
+ post("sendOSC: usage error, write-msg failed: %s", OSC_errorMessage);
+ return;
+ }
+
+ if(!x->x_bundle) {
+ SendBuffer(x->x_htmsocket, x->x_oscbuf);
+ OSC_initBuffer(x->x_oscbuf, SC_BUFFER_SIZE, bufferForOSCbuf);
+ }
+
+ //CommandLineMode(argc, targv, x->x_htmsocket);
+ //useTypeTags = 0;
+ }
+ else {
+ post("sendOSC: not connected");
+ }
+}
+
+void sendOSC_send(t_sendOSC *x, t_symbol *s, int argc, t_atom *argv)
+{
+ if(!argc) {
+ post("not sending empty message.");
+ return;
+ }
+ if(x->x_typetags) {
+ useTypeTags = 1;
+ sendOSC_sendtyped(x,s,argc,argv);
+ useTypeTags = 0;
+ } else {
+ sendOSC_sendtyped(x,s,argc,argv);
+ }
+}
+
+static void sendOSC_free(t_sendOSC *x)
+{
+ sendOSC_disconnect(x);
+}
+
+#ifdef WIN32
+ OSC_API void sendOSC_setup(void) {
+#else
+ void sendOSC_setup(void) {
+#endif
+ sendOSC_class = class_new(gensym("sendOSC"), (t_newmethod)sendOSC_new,
+ (t_method)sendOSC_free,
+ sizeof(t_sendOSC), 0, A_DEFFLOAT, 0);
+ class_addmethod(sendOSC_class, (t_method)sendOSC_connect,
+ gensym("connect"), A_SYMBOL, A_FLOAT, 0);
+ class_addmethod(sendOSC_class, (t_method)sendOSC_disconnect,
+ gensym("disconnect"), 0);
+ class_addmethod(sendOSC_class, (t_method)sendOSC_settypetags,
+ gensym("typetags"),
+ A_FLOAT, 0);
+ class_addmethod(sendOSC_class, (t_method)sendOSC_send,
+ gensym("send"),
+ A_GIMME, 0);
+ class_addmethod(sendOSC_class, (t_method)sendOSC_send,
+ gensym("senduntyped"),
+ A_GIMME, 0);
+ class_addmethod(sendOSC_class, (t_method)sendOSC_send,
+ gensym("sendtyped"),
+ A_GIMME, 0);
+ class_addmethod(sendOSC_class, (t_method)sendOSC_openbundle,
+ gensym("["),
+ 0, 0);
+ class_addmethod(sendOSC_class, (t_method)sendOSC_closebundle,
+ gensym("]"),
+ 0, 0);
+ class_sethelpsymbol(sendOSC_class, gensym("sendOSC-help.pd"));
+}
+
+
+
+
+
+/* Exit status codes:
+ 0: successful
+ 2: Message(s) dropped because of buffer overflow
+ 3: Socket error
+ 4: Usage error
+ 5: Internal error
+*/
+
+void CommandLineMode(int argc, char *argv[], void *htmsocket) {
+ char *messageName;
+ char *token;
+ typedArg args[MAX_ARGS];
+ int i,j, numArgs;
+ OSCbuf buf[1];
+
+ OSC_initBuffer(buf, SC_BUFFER_SIZE, bufferForOSCbuf);
+
+ if (argc > 1) {
+ post("argc (%d) > 1", argc);
+ }
+
+ // ParseInteractiveLine(buf, argv);
+ messageName = strtok(argv[0], ",");
+
+ j = 1;
+ for (i = j; i < argc; i++) {
+ token = strtok(argv[i],",");
+ args[i-j] = ParseToken(token);
+#ifdef DEBUG
+ printf("cell-cont: %s\n", argv[i]);
+ printf(" type-id: %d\n", args[i-j]);
+#endif
+ numArgs = i;
+ }
+
+ if(WriteMessage(buf, messageName, numArgs, args)) {
+ post("sendOSC: usage error. write-msg failed: %s", OSC_errorMessage);
+ return;
+ }
+
+ SendBuffer(htmsocket, buf);
+}
+
+#define MAXMESG 2048
+
+void InteractiveMode(void *htmsocket) {
+ char mesg[MAXMESG];
+ OSCbuf buf[1];
+ int bundleDepth = 0; /* At first, we haven't seen "[". */
+
+ OSC_initBuffer(buf, SC_BUFFER_SIZE, bufferForOSCbuf);
+
+ while (fgets(mesg, MAXMESG, stdin) != NULL) {
+ if (mesg[0] == '\n') {
+ if (bundleDepth > 0) {
+ /* Ignore blank lines inside a group. */
+ } else {
+ /* blank line => repeat previous send */
+ SendBuffer(htmsocket, buf);
+ }
+ continue;
+ }
+
+ if (bundleDepth == 0) {
+ OSC_resetBuffer(buf);
+ }
+
+ if (mesg[0] == '[') {
+ OSCTimeTag tt = ParseTimeTag(mesg+1);
+ if (OSC_openBundle(buf, tt)) {
+ post("Problem opening bundle: %s\n", OSC_errorMessage);
+ OSC_resetBuffer(buf);
+ bundleDepth = 0;
+ continue;
+ }
+ bundleDepth++;
+ } else if (mesg[0] == ']' && mesg[1] == '\n' && mesg[2] == '\0') {
+ if (bundleDepth == 0) {
+ post("Unexpected ']': not currently in a bundle.\n");
+ } else {
+ if (OSC_closeBundle(buf)) {
+ post("Problem closing bundle: %s\n", OSC_errorMessage);
+ OSC_resetBuffer(buf);
+ bundleDepth = 0;
+ continue;
+ }
+
+ bundleDepth--;
+ if (bundleDepth == 0) {
+ SendBuffer(htmsocket, buf);
+ }
+ }
+ } else {
+ ParseInteractiveLine(buf, mesg);
+ if (bundleDepth != 0) {
+ /* Don't send anything until we close all bundles */
+ } else {
+ SendBuffer(htmsocket, buf);
+ }
+ }
+ }
+}
+
+OSCTimeTag ParseTimeTag(char *s) {
+ char *p, *newline;
+ typedArg arg;
+
+ p = s;
+ while (isspace(*p)) p++;
+ if (*p == '\0') return OSCTT_Immediately();
+
+ if (*p == '+') {
+ /* Time tag is for some time in the future. It should be a
+ number of seconds as an int or float */
+
+ newline = strchr(s, '\n');
+ if (newline != NULL) *newline = '\0';
+
+ p++; /* Skip '+' */
+ while (isspace(*p)) p++;
+
+ arg = ParseToken(p);
+ if (arg.type == STRING_osc) {
+ post("warning: inscrutable time tag request: %s\n", s);
+ return OSCTT_Immediately();
+ } else if (arg.type == INT_osc) {
+ return OSCTT_PlusSeconds(OSCTT_CurrentTime(),
+ (float) arg.datum.i);
+ } else if (arg.type == FLOAT_osc) {
+ return OSCTT_PlusSeconds(OSCTT_CurrentTime(), arg.datum.f);
+ } else {
+ error("This can't happen!");
+ }
+ }
+
+ if (isdigit(*p) || (*p >= 'a' && *p <='f') || (*p >= 'A' && *p <='F')) {
+ /* They specified the 8-byte tag in hex */
+ OSCTimeTag tt;
+ if (sscanf(p, "%llx", &tt) != 1) {
+ post("warning: couldn't parse time tag %s\n", s);
+ return OSCTT_Immediately();
+ }
+#ifndef HAS8BYTEINT
+ if (ntohl(1) != 1) {
+ /* tt is a struct of seconds and fractional part,
+ and this machine is little-endian, so sscanf
+ wrote each half of the time tag in the wrong half
+ of the struct. */
+ int temp;
+ temp = tt.seconds;
+ tt.seconds = tt.fraction ;
+ tt.fraction = temp;
+ }
+#endif
+ return tt;
+ }
+
+ post("warning: invalid time tag: %s\n", s);
+ return OSCTT_Immediately();
+}
+
+
+void ParseInteractiveLine(OSCbuf *buf, char *mesg) {
+ char *messageName, *token, *p;
+ typedArg args[MAX_ARGS];
+ int thisArg;
+
+ p = mesg;
+ while (isspace(*p)) p++;
+ if (*p == '\0') return;
+
+ messageName = p;
+
+ if (strcmp(messageName, "play\n") == 0) {
+ /* Special kludge feature to save typing */
+ typedArg arg;
+
+ if (OSC_openBundle(buf, OSCTT_Immediately())) {
+ post("Problem opening bundle: %s\n", OSC_errorMessage);
+ return;
+ }
+
+ arg.type = INT_osc;
+ arg.datum.i = 0;
+ WriteMessage(buf, "/voices/0/tp/timbre_index", 1, &arg);
+
+ arg.type = FLOAT_osc;
+ arg.datum.i = 0.0f;
+ WriteMessage(buf, "/voices/0/tm/goto", 1, &arg);
+
+ if (OSC_closeBundle(buf)) {
+ post("Problem closing bundle: %s\n", OSC_errorMessage);
+ }
+
+ return;
+ }
+
+ while (!isspace(*p) && *p != '\0') p++;
+ if (isspace(*p)) {
+ *p = '\0';
+ p++;
+ }
+
+ thisArg = 0;
+ while (*p != '\0') {
+ /* flush leading whitespace */
+ while (isspace(*p)) p++;
+ if (*p == '\0') break;
+
+ if (*p == '"') {
+ /* A string argument: scan for close quotes */
+ p++;
+ args[thisArg].type = STRING_osc;
+ args[thisArg].datum.s = p;
+
+ while (*p != '"') {
+ if (*p == '\0') {
+ post("Unterminated quote mark: ignoring line\n");
+ return;
+ }
+ p++;
+ }
+ *p = '\0';
+ p++;
+ } else {
+ token = p;
+ while (!isspace(*p) && (*p != '\0')) p++;
+ if (isspace(*p)) {
+ *p = '\0';
+ p++;
+ }
+ args[thisArg] = ParseToken(token);
+ }
+ thisArg++;
+ if (thisArg >= MAX_ARGS) {
+ post("Sorry, your message has more than MAX_ARGS (%d) arguments; ignoring the rest.\n",
+ MAX_ARGS);
+ break;
+ }
+ }
+
+ if (WriteMessage(buf, messageName, thisArg, args) != 0) {
+ post("Problem sending message: %s\n", OSC_errorMessage);
+ }
+}
+
+typedArg ParseToken(char *token) {
+ char *p = token;
+ typedArg returnVal;
+
+ /* It might be an int, a float, or a string */
+
+ if (*p == '-') p++;
+
+ if (isdigit(*p) || *p == '.') {
+ while (isdigit(*p)) p++;
+ if (*p == '\0') {
+ returnVal.type = INT_osc;
+ returnVal.datum.i = atoi(token);
+ return returnVal;
+ }
+ if (*p == '.') {
+ p++;
+ while (isdigit(*p)) p++;
+ if (*p == '\0') {
+ returnVal.type = FLOAT_osc;
+ returnVal.datum.f = atof(token);
+ return returnVal;
+ }
+ }
+ }
+
+ returnVal.type = STRING_osc;
+ returnVal.datum.s = token;
+ return returnVal;
+}
+
+int WriteMessage(OSCbuf *buf, char *messageName, int numArgs, typedArg *args) {
+ int j, returnVal;
+ const int wmERROR = -1;
+
+ returnVal = 0;
+
+#ifdef DEBUG
+ printf("WriteMessage: %s ", messageName);
+
+ for (j = 0; j < numArgs; j++) {
+ switch (args[j].type) {
+ case INT_osc:
+ printf("%d ", args[j].datum.i);
+ break;
+
+ case FLOAT_osc:
+ printf("%f ", args[j].datum.f);
+ break;
+
+ case STRING_osc:
+ printf("%s ", args[j].datum.s);
+ break;
+
+ default:
+ error("Unrecognized arg type, (not exiting)");
+ return(wmERROR);
+ }
+ }
+ printf("\n");
+#endif
+
+ if (!useTypeTags) {
+ returnVal = OSC_writeAddress(buf, messageName);
+ if (returnVal) {
+ post("Problem writing address: %s\n", OSC_errorMessage);
+ }
+ } else {
+ /* First figure out the type tags */
+ char typeTags[MAX_ARGS+2];
+ int i;
+
+ typeTags[0] = ',';
+
+ for (i = 0; i < numArgs; ++i) {
+ switch (args[i].type) {
+ case INT_osc:
+ typeTags[i+1] = 'i';
+ break;
+
+ case FLOAT_osc:
+ typeTags[i+1] = 'f';
+ break;
+
+ case STRING_osc:
+ typeTags[i+1] = 's';
+ break;
+
+ default:
+ error("Unrecognized arg type (not exiting)");
+ return(wmERROR);
+ }
+ }
+ typeTags[i+1] = '\0';
+
+ returnVal = OSC_writeAddressAndTypes(buf, messageName, typeTags);
+ if (returnVal) {
+ post("Problem writing address: %s\n", OSC_errorMessage);
+ }
+ }
+
+ for (j = 0; j < numArgs; j++) {
+ switch (args[j].type) {
+ case INT_osc:
+ if ((returnVal = OSC_writeIntArg(buf, args[j].datum.i)) != 0) {
+ return returnVal;
+ }
+ break;
+
+ case FLOAT_osc:
+ if ((returnVal = OSC_writeFloatArg(buf, args[j].datum.f)) != 0) {
+ return returnVal;
+ }
+ break;
+
+ case STRING_osc:
+ if ((returnVal = OSC_writeStringArg(buf, args[j].datum.s)) != 0) {
+ return returnVal;
+ }
+ break;
+
+ default:
+ error("Unrecognized arg type (not exiting)");
+ returnVal = wmERROR;
+ }
+ }
+ return returnVal;
+}
+
+void SendBuffer(void *htmsocket, OSCbuf *buf) {
+#ifdef DEBUG
+ printf("Sending buffer...\n");
+#endif
+ if (OSC_isBufferEmpty(buf)) {
+ post("SendBuffer() called but buffer empty");
+ return;
+ }
+ if (!OSC_isBufferDone(buf)) {
+ error("SendBuffer() called but buffer not ready!, not exiting");
+ return; //{{raf}}
+ }
+ SendData(htmsocket, OSC_packetSize(buf), OSC_getPacket(buf));
+}
+
+void SendData(void *htmsocket, int size, char *data) {
+ if (!SendHTMSocket(htmsocket, size, data)) {
+ post("SendData::SendHTMSocket()failure -- not connected");
+ CloseHTMSocket(htmsocket);
+ }
+}
+
+
+
+/* ----------------------
+ OSC-client code
+
+ */
+
+/* Here are the possible values of the state field: */
+
+#define EMPTY 0 /* Nothing written to packet yet */
+#define ONE_MSG_ARGS 1 /* Packet has a single message; gathering arguments */
+#define NEED_COUNT 2 /* Just opened a bundle; must write message name or
+ open another bundle */
+#define GET_ARGS 3 /* Getting arguments to a message. If we see a message
+ name or a bundle open/close then the current message
+ will end. */
+#define DONE 4 /* All open bundles have been closed, so can't write
+ anything else */
+
+#ifdef WIN32
+ #include <winsock2.h>
+ #include <io.h>
+ #include <stdio.h>
+ #include <errno.h>
+ #include <fcntl.h>
+ #include <sys/types.h>
+ #include <sys/stat.h>
+#endif
+
+#ifdef __APPLE__
+ #include <sys/types.h>
+#endif
+
+#ifdef unix
+ #include <netinet/in.h>
+ #include <stdio.h>
+#endif
+
+
+char *OSC_errorMessage;
+
+static int OSC_padString(char *dest, char *str);
+static int OSC_padStringWithAnExtraStupidComma(char *dest, char *str);
+static int OSC_WritePadding(char *dest, int i);
+static int CheckTypeTag(OSCbuf *buf, char expectedType);
+
+void OSC_initBuffer(OSCbuf *buf, int size, char *byteArray) {
+ buf->buffer = byteArray;
+ buf->size = size;
+ OSC_resetBuffer(buf);
+}
+
+void OSC_resetBuffer(OSCbuf *buf) {
+ buf->bufptr = buf->buffer;
+ buf->state = EMPTY;
+ buf->bundleDepth = 0;
+ buf->prevCounts[0] = 0;
+ buf->gettingFirstUntypedArg = 0;
+ buf->typeStringPtr = 0;
+}
+
+int OSC_isBufferEmpty(OSCbuf *buf) {
+ return buf->bufptr == buf->buffer;
+}
+
+int OSC_freeSpaceInBuffer(OSCbuf *buf) {
+ return buf->size - (buf->bufptr - buf->buffer);
+}
+
+int OSC_isBufferDone(OSCbuf *buf) {
+ return (buf->state == DONE || buf->state == ONE_MSG_ARGS);
+}
+
+char *OSC_getPacket(OSCbuf *buf) {
+#ifdef ERROR_CHECK_GETPACKET
+ if (buf->state == DONE || buf->state == ONE_MSG_ARGS) {
+ return buf->buffer;
+ } else {
+ OSC_errorMessage = "Packet has unterminated bundles";
+ return 0;
+ }
+#else
+ return buf->buffer;
+#endif
+}
+
+int OSC_packetSize(OSCbuf *buf) {
+#ifdef ERROR_CHECK_PACKETSIZE
+ if (buf->state == DONE || buf->state == ONE_MSG_ARGS) {
+ return (buf->bufptr - buf->buffer);
+ } else {
+ OSC_errorMessage = "Packet has unterminated bundles";
+ return 0;
+ }
+#else
+ return (buf->bufptr - buf->buffer);
+#endif
+}
+
+#define CheckOverflow(buf, bytesNeeded) { if ((bytesNeeded) > OSC_freeSpaceInBuffer(buf)) {OSC_errorMessage = "buffer overflow"; return 1;}}
+
+static void PatchMessageSize(OSCbuf *buf) {
+ int4byte size;
+ size = buf->bufptr - ((char *) buf->thisMsgSize) - 4;
+ *(buf->thisMsgSize) = htonl(size);
+}
+
+int OSC_openBundle(OSCbuf *buf, OSCTimeTag tt) {
+ if (buf->state == ONE_MSG_ARGS) {
+ OSC_errorMessage = "Can't open a bundle in a one-message packet";
+ return 3;
+ }
+
+ if (buf->state == DONE) {
+ OSC_errorMessage = "This packet is finished; can't open a new bundle";
+ return 4;
+ }
+
+ if (++(buf->bundleDepth) >= MAX_BUNDLE_NESTING) {
+ OSC_errorMessage = "Bundles nested too deeply; change MAX_BUNDLE_NESTING in OpenSoundControl.h";
+ return 2;
+ }
+
+ if (CheckTypeTag(buf, '\0')) return 9;
+
+ if (buf->state == GET_ARGS) {
+ PatchMessageSize(buf);
+ }
+
+ if (buf->state == EMPTY) {
+ /* Need 16 bytes for "#bundle" and time tag */
+ CheckOverflow(buf, 16);
+ } else {
+ /* This bundle is inside another bundle, so we need to leave
+ a blank size count for the size of this current bundle. */
+ CheckOverflow(buf, 20);
+ *((int4byte *)buf->bufptr) = 0xaaaaaaaa;
+ buf->prevCounts[buf->bundleDepth] = (int4byte *)buf->bufptr;
+
+ buf->bufptr += 4;
+ }
+
+ buf->bufptr += OSC_padString(buf->bufptr, "#bundle");
+
+
+ *((OSCTimeTag *) buf->bufptr) = tt;
+
+ if (htonl(1) != 1) {
+ /* Byte swap the 8-byte integer time tag */
+ int4byte *intp = (int4byte *)buf->bufptr;
+ intp[0] = htonl(intp[0]);
+ intp[1] = htonl(intp[1]);
+
+#ifdef HAS8BYTEINT
+ { /* tt is a 64-bit int so we have to swap the two 32-bit words.
+ (Otherwise tt is a struct of two 32-bit words, and even though
+ each word was wrong-endian, they were in the right order
+ in the struct.) */
+ int4byte temp = intp[0];
+ intp[0] = intp[1];
+ intp[1] = temp;
+ }
+#endif
+ }
+
+ buf->bufptr += sizeof(OSCTimeTag);
+
+ buf->state = NEED_COUNT;
+
+ buf->gettingFirstUntypedArg = 0;
+ buf->typeStringPtr = 0;
+ return 0;
+}
+
+
+int OSC_closeBundle(OSCbuf *buf) {
+ if (buf->bundleDepth == 0) {
+ /* This handles EMPTY, ONE_MSG, ARGS, and DONE */
+ OSC_errorMessage = "Can't close bundle; no bundle is open!";
+ return 5;
+ }
+
+ if (CheckTypeTag(buf, '\0')) return 9;
+
+ if (buf->state == GET_ARGS) {
+ PatchMessageSize(buf);
+ }
+
+ if (buf->bundleDepth == 1) {
+ /* Closing the last bundle: No bundle size to patch */
+ buf->state = DONE;
+ } else {
+ /* Closing a sub-bundle: patch bundle size */
+ int size = buf->bufptr - ((char *) buf->prevCounts[buf->bundleDepth]) - 4;
+ *(buf->prevCounts[buf->bundleDepth]) = htonl(size);
+ buf->state = NEED_COUNT;
+ }
+
+ --buf->bundleDepth;
+ buf->gettingFirstUntypedArg = 0;
+ buf->typeStringPtr = 0;
+ return 0;
+}
+
+
+int OSC_closeAllBundles(OSCbuf *buf) {
+ if (buf->bundleDepth == 0) {
+ /* This handles EMPTY, ONE_MSG, ARGS, and DONE */
+ OSC_errorMessage = "Can't close all bundles; no bundle is open!";
+ return 6;
+ }
+
+ if (CheckTypeTag(buf, '\0')) return 9;
+
+ while (buf->bundleDepth > 0) {
+ OSC_closeBundle(buf);
+ }
+ buf->typeStringPtr = 0;
+ return 0;
+}
+
+int OSC_writeAddress(OSCbuf *buf, char *name) {
+ int4byte paddedLength;
+
+ if (buf->state == ONE_MSG_ARGS) {
+ OSC_errorMessage = "This packet is not a bundle, so you can't write another address";
+ return 7;
+ }
+
+ if (buf->state == DONE) {
+ OSC_errorMessage = "This packet is finished; can't write another address";
+ return 8;
+ }
+
+ if (CheckTypeTag(buf, '\0')) return 9;
+
+ paddedLength = OSC_effectiveStringLength(name);
+
+ if (buf->state == EMPTY) {
+ /* This will be a one-message packet, so no sizes to worry about */
+ CheckOverflow(buf, paddedLength);
+ buf->state = ONE_MSG_ARGS;
+ } else {
+ /* GET_ARGS or NEED_COUNT */
+ CheckOverflow(buf, 4+paddedLength);
+ if (buf->state == GET_ARGS) {
+ /* Close the old message */
+ PatchMessageSize(buf);
+ }
+ buf->thisMsgSize = (int4byte *)buf->bufptr;
+ *(buf->thisMsgSize) = 0xbbbbbbbb;
+ buf->bufptr += 4;
+ buf->state = GET_ARGS;
+ }
+
+ /* Now write the name */
+ buf->bufptr += OSC_padString(buf->bufptr, name);
+ buf->typeStringPtr = 0;
+ buf->gettingFirstUntypedArg = 1;
+
+ return 0;
+}
+
+int OSC_writeAddressAndTypes(OSCbuf *buf, char *name, char *types) {
+ int result;
+ int4byte paddedLength;
+
+ if (CheckTypeTag(buf, '\0')) return 9;
+
+ result = OSC_writeAddress(buf, name);
+
+ if (result) return result;
+
+ paddedLength = OSC_effectiveStringLength(types);
+
+ CheckOverflow(buf, paddedLength);
+
+ buf->typeStringPtr = buf->bufptr + 1; /* skip comma */
+ buf->bufptr += OSC_padString(buf->bufptr, types);
+
+ buf->gettingFirstUntypedArg = 0;
+ return 0;
+}
+
+static int CheckTypeTag(OSCbuf *buf, char expectedType) {
+ if (buf->typeStringPtr) {
+ if (*(buf->typeStringPtr) != expectedType) {
+ if (expectedType == '\0') {
+ OSC_errorMessage =
+ "According to the type tag I expected more arguments.";
+ } else if (*(buf->typeStringPtr) == '\0') {
+ OSC_errorMessage =
+ "According to the type tag I didn't expect any more arguments.";
+ } else {
+ OSC_errorMessage =
+ "According to the type tag I expected an argument of a different type.";
+ printf("* Expected %c, string now %s\n", expectedType, buf->typeStringPtr);
+ }
+ return 9;
+ }
+ ++(buf->typeStringPtr);
+ }
+ return 0;
+}
+
+
+int OSC_writeFloatArg(OSCbuf *buf, float arg) {
+ int4byte *intp;
+ //int result;
+
+ CheckOverflow(buf, 4);
+
+ if (CheckTypeTag(buf, 'f')) return 9;
+
+ /* Pretend arg is a long int so we can use htonl() */
+ intp = ((int4byte *) &arg);
+ *((int4byte *) buf->bufptr) = htonl(*intp);
+
+ buf->bufptr += 4;
+
+ buf->gettingFirstUntypedArg = 0;
+ return 0;
+}
+
+
+
+int OSC_writeFloatArgs(OSCbuf *buf, int numFloats, float *args) {
+ int i;
+ int4byte *intp;
+
+ CheckOverflow(buf, 4 * numFloats);
+
+ /* Pretend args are long ints so we can use htonl() */
+ intp = ((int4byte *) args);
+
+ for (i = 0; i < numFloats; i++) {
+ if (CheckTypeTag(buf, 'f')) return 9;
+ *((int4byte *) buf->bufptr) = htonl(intp[i]);
+ buf->bufptr += 4;
+ }
+
+ buf->gettingFirstUntypedArg = 0;
+ return 0;
+}
+
+int OSC_writeIntArg(OSCbuf *buf, int4byte arg) {
+ CheckOverflow(buf, 4);
+ if (CheckTypeTag(buf, 'i')) return 9;
+
+ *((int4byte *) buf->bufptr) = htonl(arg);
+ buf->bufptr += 4;
+
+ buf->gettingFirstUntypedArg = 0;
+ return 0;
+}
+
+int OSC_writeStringArg(OSCbuf *buf, char *arg) {
+ int len;
+
+ if (CheckTypeTag(buf, 's')) return 9;
+
+ len = OSC_effectiveStringLength(arg);
+
+ if (buf->gettingFirstUntypedArg && arg[0] == ',') {
+ /* This un-type-tagged message starts with a string
+ that starts with a comma, so we have to escape it
+ (with a double comma) so it won't look like a type
+ tag string. */
+
+ CheckOverflow(buf, len+4); /* Too conservative */
+ buf->bufptr +=
+ OSC_padStringWithAnExtraStupidComma(buf->bufptr, arg);
+
+ } else {
+ CheckOverflow(buf, len);
+ buf->bufptr += OSC_padString(buf->bufptr, arg);
+ }
+
+ buf->gettingFirstUntypedArg = 0;
+ return 0;
+
+}
+
+/* String utilities */
+
+#define STRING_ALIGN_PAD 4
+int OSC_effectiveStringLength(char *string) {
+ int len = strlen(string) + 1; /* We need space for the null char. */
+
+ /* Round up len to next multiple of STRING_ALIGN_PAD to account for alignment padding */
+ if ((len % STRING_ALIGN_PAD) != 0) {
+ len += STRING_ALIGN_PAD - (len % STRING_ALIGN_PAD);
+ }
+ return len;
+}
+
+static int OSC_padString(char *dest, char *str) {
+ int i;
+
+ for (i = 0; str[i] != '\0'; i++) {
+ dest[i] = str[i];
+ }
+
+ return OSC_WritePadding(dest, i);
+}
+
+static int OSC_padStringWithAnExtraStupidComma(char *dest, char *str) {
+ int i;
+
+ dest[0] = ',';
+ for (i = 0; str[i] != '\0'; i++) {
+ dest[i+1] = str[i];
+ }
+
+ return OSC_WritePadding(dest, i+1);
+}
+
+static int OSC_WritePadding(char *dest, int i) {
+ dest[i] = '\0';
+ i++;
+
+ for (; (i % STRING_ALIGN_PAD) != 0; i++) {
+ dest[i] = '\0';
+ }
+
+ return i;
+}
+
+
diff --git a/apps/plugins/pdbox/PDa/extra/sformat.h b/apps/plugins/pdbox/PDa/extra/sformat.h
new file mode 100644
index 0000000000..b75ef98c9a
--- /dev/null
+++ b/apps/plugins/pdbox/PDa/extra/sformat.h
@@ -0,0 +1,110 @@
+
+#ifndef SFORMAT_H__
+#define SFORMAT_H__
+
+typedef unsigned short uint16;
+typedef unsigned long uint32;
+
+#define FORMAT_WAVE 0
+#define FORMAT_AIFF 1
+#define FORMAT_NEXT 2
+
+/* the NeXTStep sound header structure; can be big or little endian */
+
+typedef struct _nextstep
+{
+ char ns_fileid[4]; /* magic number '.snd' if file is big-endian */
+ uint32 ns_onset; /* byte offset of first sample */
+ uint32 ns_length; /* length of sound in bytes */
+ uint32 ns_format; /* format; see below */
+ uint32 ns_sr; /* sample rate */
+ uint32 ns_nchans; /* number of channels */
+ char ns_info[4]; /* comment */
+} t_nextstep;
+
+#define NS_FORMAT_LINEAR_16 3
+#define NS_FORMAT_LINEAR_24 4
+#define NS_FORMAT_FLOAT 6
+#define SCALE (1./(1024. * 1024. * 1024. * 2.))
+
+/* the WAVE header. All Wave files are little endian. We assume
+ the "fmt" chunk comes first which is usually the case but perhaps not
+ always; same for AIFF and the "COMM" chunk. */
+
+typedef unsigned word;
+typedef unsigned long dword;
+
+typedef struct _wave
+{
+ char w_fileid[4]; /* chunk id 'RIFF' */
+ uint32 w_chunksize; /* chunk size */
+ char w_waveid[4]; /* wave chunk id 'WAVE' */
+ char w_fmtid[4]; /* format chunk id 'fmt ' */
+ uint32 w_fmtchunksize; /* format chunk size */
+ uint16 w_fmttag; /* format tag, 1 for PCM */
+ uint16 w_nchannels; /* number of channels */
+ uint32 w_samplespersec; /* sample rate in hz */
+ uint32 w_navgbytespersec; /* average bytes per second */
+ uint16 w_nblockalign; /* number of bytes per sample */
+ uint16 w_nbitspersample; /* number of bits in a sample */
+ char w_datachunkid[4]; /* data chunk id 'data' */
+ uint32 w_datachunksize; /* length of data chunk */
+} t_wave;
+
+
+#endif
+
+#ifndef SFORMAT_H__
+#define SFORMAT_H__
+
+typedef unsigned short uint16;
+typedef unsigned long uint32;
+
+#define FORMAT_WAVE 0
+#define FORMAT_AIFF 1
+#define FORMAT_NEXT 2
+
+/* the NeXTStep sound header structure; can be big or little endian */
+
+typedef struct _nextstep
+{
+ char ns_fileid[4]; /* magic number '.snd' if file is big-endian */
+ uint32 ns_onset; /* byte offset of first sample */
+ uint32 ns_length; /* length of sound in bytes */
+ uint32 ns_format; /* format; see below */
+ uint32 ns_sr; /* sample rate */
+ uint32 ns_nchans; /* number of channels */
+ char ns_info[4]; /* comment */
+} t_nextstep;
+
+#define NS_FORMAT_LINEAR_16 3
+#define NS_FORMAT_LINEAR_24 4
+#define NS_FORMAT_FLOAT 6
+#define SCALE (1./(1024. * 1024. * 1024. * 2.))
+
+/* the WAVE header. All Wave files are little endian. We assume
+ the "fmt" chunk comes first which is usually the case but perhaps not
+ always; same for AIFF and the "COMM" chunk. */
+
+typedef unsigned word;
+typedef unsigned long dword;
+
+typedef struct _wave
+{
+ char w_fileid[4]; /* chunk id 'RIFF' */
+ uint32 w_chunksize; /* chunk size */
+ char w_waveid[4]; /* wave chunk id 'WAVE' */
+ char w_fmtid[4]; /* format chunk id 'fmt ' */
+ uint32 w_fmtchunksize; /* format chunk size */
+ uint16 w_fmttag; /* format tag, 1 for PCM */
+ uint16 w_nchannels; /* number of channels */
+ uint32 w_samplespersec; /* sample rate in hz */
+ uint32 w_navgbytespersec; /* average bytes per second */
+ uint16 w_nblockalign; /* number of bytes per sample */
+ uint16 w_nbitspersample; /* number of bits in a sample */
+ char w_datachunkid[4]; /* data chunk id 'data' */
+ uint32 w_datachunksize; /* length of data chunk */
+} t_wave;
+
+
+#endif
diff --git a/apps/plugins/pdbox/PDa/extra/shell.c b/apps/plugins/pdbox/PDa/extra/shell.c
new file mode 100644
index 0000000000..a0b6cef5b5
--- /dev/null
+++ b/apps/plugins/pdbox/PDa/extra/shell.c
@@ -0,0 +1,624 @@
+/* (C) Guenter Geiger <geiger@epy.co.at> */
+
+#include "m_pd.h"
+#ifdef NT
+#pragma warning( disable : 4244 )
+#pragma warning( disable : 4305 )
+#endif
+
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <signal.h>
+#include <sched.h>
+
+void sys_rmpollfn(int fd);
+void sys_addpollfn(int fd, void* fn, void *ptr);
+
+/* ------------------------ shell ----------------------------- */
+
+#define INBUFSIZE 1024
+
+static t_class *shell_class;
+
+
+static void drop_priority(void)
+{
+#ifdef _POSIX_PRIORITY_SCHEDULING
+ struct sched_param par;
+ int p1 ,p2, p3;
+ par.sched_priority = 0;
+ sched_setscheduler(0,SCHED_OTHER,&par);
+#endif
+}
+
+
+typedef struct _shell
+{
+ t_object x_obj;
+ int x_echo;
+ char *sr_inbuf;
+ int sr_inhead;
+ int sr_intail;
+ void* x_binbuf;
+ int fdpipe[2];
+ int fdinpipe[2];
+ int pid;
+ int x_del;
+ t_outlet* x_done;
+ t_clock* x_clock;
+} t_shell;
+
+static int shell_pid;
+
+
+void shell_cleanup(t_shell* x)
+{
+ sys_rmpollfn(x->fdpipe[0]);
+
+ if (x->fdpipe[0]>0) close(x->fdpipe[0]);
+ if (x->fdpipe[1]>0) close(x->fdpipe[1]);
+ if (x->fdinpipe[0]>0) close(x->fdinpipe[0]);
+ if (x->fdinpipe[1]>0) close(x->fdinpipe[1]);
+
+ x->fdpipe[0] = -1;
+ x->fdpipe[1] = -1;
+ x->fdinpipe[0] = -1;
+ x->fdinpipe[1] = -1;
+ clock_unset(x->x_clock);
+}
+
+void shell_check(t_shell* x)
+{
+ int ret;
+ int status;
+ ret = waitpid(x->pid,&status,WNOHANG);
+ if (ret == x->pid) {
+ shell_cleanup(x);
+ if (WIFEXITED(status)) {
+ outlet_float(x->x_done,WEXITSTATUS(status));
+ }
+ else outlet_float(x->x_done,0);
+ }
+ else {
+ if (x->x_del < 100) x->x_del+=2; /* increment poll times */
+ clock_delay(x->x_clock,x->x_del);
+ }
+}
+
+
+void shell_bang(t_shell *x)
+{
+ post("bang");
+}
+
+/* snippet from pd's code */
+static void shell_doit(void *z, t_binbuf *b)
+{
+ t_shell *x = (t_shell *)z;
+ int msg, natom = binbuf_getnatom(b);
+ t_atom *at = binbuf_getvec(b);
+
+ for (msg = 0; msg < natom;)
+ {
+ int emsg;
+ for (emsg = msg; emsg < natom && at[emsg].a_type != A_COMMA
+ && at[emsg].a_type != A_SEMI; emsg++)
+ ;
+ if (emsg > msg)
+ {
+ int i;
+ for (i = msg; i < emsg; i++)
+ if (at[i].a_type == A_DOLLAR || at[i].a_type == A_DOLLSYM)
+ {
+ pd_error(x, "netreceive: got dollar sign in message");
+ goto nodice;
+ }
+ if (at[msg].a_type == A_FLOAT)
+ {
+ if (emsg > msg + 1)
+ outlet_list(x->x_obj.ob_outlet, 0, emsg-msg, at + msg);
+ else outlet_float(x->x_obj.ob_outlet, at[msg].a_w.w_float);
+ }
+ else if (at[msg].a_type == A_SYMBOL)
+ outlet_anything(x->x_obj.ob_outlet, at[msg].a_w.w_symbol,
+ emsg-msg-1, at + msg + 1);
+ }
+ nodice:
+ msg = emsg + 1;
+ }
+}
+
+
+void shell_read(t_shell *x, int fd)
+{
+ char buf[INBUFSIZE];
+ t_binbuf* bbuf = binbuf_new();
+ int i;
+ int readto =
+ (x->sr_inhead >= x->sr_intail ? INBUFSIZE : x->sr_intail-1);
+ int ret;
+
+ ret = read(fd, buf,INBUFSIZE-1);
+ buf[ret] = '\0';
+
+ for (i=0;i<ret;i++)
+ if (buf[i] == '\n') buf[i] = ';';
+ if (ret < 0)
+ {
+ error("shell: pipe read error");
+ sys_rmpollfn(fd);
+ x->fdpipe[0] = -1;
+ close(fd);
+ return;
+ }
+ else if (ret == 0)
+ {
+ post("EOF on socket %d\n", fd);
+ sys_rmpollfn(fd);
+ x->fdpipe[0] = -1;
+ close(fd);
+ return;
+ }
+ else
+ {
+ int natom;
+ t_atom *at;
+ binbuf_text(bbuf, buf, strlen(buf));
+
+ natom = binbuf_getnatom(bbuf);
+ at = binbuf_getvec(bbuf);
+ shell_doit(x,bbuf);
+ }
+ binbuf_free(bbuf);
+}
+
+
+static void shell_send(t_shell *x, t_symbol *s,int ac, t_atom *at)
+{
+ int i;
+ char tmp[MAXPDSTRING];
+ int size = 0;
+
+ if (x->fdinpipe[0] == -1) return; /* nothing to send to */
+
+ for (i=0;i<ac;i++) {
+ atom_string(at,tmp+size,MAXPDSTRING - size);
+ at++;
+ size=strlen(tmp);
+ tmp[size++] = ' ';
+ }
+ tmp[size-1] = '\0';
+ post("sending %s",tmp);
+ write(x->fdinpipe[0],tmp,strlen(tmp));
+}
+
+static void shell_anything(t_shell *x, t_symbol *s, int ac, t_atom *at)
+{
+ int i;
+ char* argv[20];
+ t_symbol* sym;
+
+ if (!strcmp(s->s_name,"send")) {
+ post("send");
+ shell_send(x,s,ac,at);
+ return;
+ }
+
+ argv[0] = s->s_name;
+
+ if (x->fdpipe[0] != -1) {
+ post("shell: old process still running");
+ kill(x->pid,SIGKILL);
+ shell_cleanup(x);
+ }
+
+
+ if (pipe(x->fdpipe) < 0) {
+ error("unable to create pipe");
+ return;
+ }
+
+ if (pipe(x->fdinpipe) < 0) {
+ error("unable to create input pipe");
+ return;
+ }
+
+
+ sys_addpollfn(x->fdpipe[0],shell_read,x);
+
+ if (!(x->pid = fork())) {
+ int status;
+ char* cmd = getbytes(1024);
+ char* tcmd = getbytes(1024);
+ strcpy(cmd,s->s_name);
+
+#if 0
+ for (i=1;i<=ac;i++) {
+ argv[i] = getbytes(255);
+ atom_string(at,argv[i],255);
+/* post("argument %s",argv[i]); */
+ at++;
+ }
+ argv[i] = 0;
+#endif
+ for (i=1;i<=ac;i++) {
+ atom_string(at,tcmd,255);
+ strcat(cmd," ");
+ strcat(cmd,tcmd);
+ at++;
+ }
+
+
+ /* reassign stdout */
+ dup2(x->fdpipe[1],1);
+ dup2(x->fdinpipe[1],0);
+
+ /* drop privileges */
+ drop_priority();
+ seteuid(getuid()); /* lose setuid priveliges */
+
+ post("executing %s",cmd);
+ system(cmd);
+// execvp(s->s_name,argv);
+ exit(0);
+ }
+ x->x_del = 4;
+ clock_delay(x->x_clock,x->x_del);
+
+ if (x->x_echo)
+ outlet_anything(x->x_obj.ob_outlet, s, ac, at);
+}
+
+
+
+void shell_free(t_shell* x)
+{
+ binbuf_free(x->x_binbuf);
+}
+
+static void *shell_new(void)
+{
+ t_shell *x = (t_shell *)pd_new(shell_class);
+
+ x->x_echo = 0;
+ x->fdpipe[0] = -1;
+ x->fdpipe[1] = -1;
+ x->fdinpipe[0] = -1;
+ x->fdinpipe[1] = -1;
+
+ x->sr_inhead = x->sr_intail = 0;
+ if (!(x->sr_inbuf = (char*) malloc(INBUFSIZE))) bug("t_shell");;
+
+ x->x_binbuf = binbuf_new();
+
+ outlet_new(&x->x_obj, &s_list);
+ x->x_done = outlet_new(&x->x_obj, &s_bang);
+ x->x_clock = clock_new(x, (t_method) shell_check);
+ return (x);
+}
+
+void shell_setup(void)
+{
+ shell_class = class_new(gensym("shell"), (t_newmethod)shell_new,
+ (t_method)shell_free,sizeof(t_shell), 0,0);
+ class_addbang(shell_class,shell_bang);
+ class_addanything(shell_class, shell_anything);
+}
+
+
+/* (C) Guenter Geiger <geiger@epy.co.at> */
+
+#include "m_pd.h"
+#ifdef NT
+#pragma warning( disable : 4244 )
+#pragma warning( disable : 4305 )
+#endif
+
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <signal.h>
+#include <sched.h>
+
+void sys_rmpollfn(int fd);
+void sys_addpollfn(int fd, void* fn, void *ptr);
+
+/* ------------------------ shell ----------------------------- */
+
+#define INBUFSIZE 1024
+
+static t_class *shell_class;
+
+
+static void drop_priority(void)
+{
+#ifdef _POSIX_PRIORITY_SCHEDULING
+ struct sched_param par;
+ int p1 ,p2, p3;
+ par.sched_priority = 0;
+ sched_setscheduler(0,SCHED_OTHER,&par);
+#endif
+}
+
+
+typedef struct _shell
+{
+ t_object x_obj;
+ int x_echo;
+ char *sr_inbuf;
+ int sr_inhead;
+ int sr_intail;
+ void* x_binbuf;
+ int fdpipe[2];
+ int fdinpipe[2];
+ int pid;
+ int x_del;
+ t_outlet* x_done;
+ t_clock* x_clock;
+} t_shell;
+
+static int shell_pid;
+
+
+void shell_cleanup(t_shell* x)
+{
+ sys_rmpollfn(x->fdpipe[0]);
+
+ if (x->fdpipe[0]>0) close(x->fdpipe[0]);
+ if (x->fdpipe[1]>0) close(x->fdpipe[1]);
+ if (x->fdinpipe[0]>0) close(x->fdinpipe[0]);
+ if (x->fdinpipe[1]>0) close(x->fdinpipe[1]);
+
+ x->fdpipe[0] = -1;
+ x->fdpipe[1] = -1;
+ x->fdinpipe[0] = -1;
+ x->fdinpipe[1] = -1;
+ clock_unset(x->x_clock);
+}
+
+void shell_check(t_shell* x)
+{
+ int ret;
+ int status;
+ ret = waitpid(x->pid,&status,WNOHANG);
+ if (ret == x->pid) {
+ shell_cleanup(x);
+ if (WIFEXITED(status)) {
+ outlet_float(x->x_done,WEXITSTATUS(status));
+ }
+ else outlet_float(x->x_done,0);
+ }
+ else {
+ if (x->x_del < 100) x->x_del+=2; /* increment poll times */
+ clock_delay(x->x_clock,x->x_del);
+ }
+}
+
+
+void shell_bang(t_shell *x)
+{
+ post("bang");
+}
+
+/* snippet from pd's code */
+static void shell_doit(void *z, t_binbuf *b)
+{
+ t_shell *x = (t_shell *)z;
+ int msg, natom = binbuf_getnatom(b);
+ t_atom *at = binbuf_getvec(b);
+
+ for (msg = 0; msg < natom;)
+ {
+ int emsg;
+ for (emsg = msg; emsg < natom && at[emsg].a_type != A_COMMA
+ && at[emsg].a_type != A_SEMI; emsg++)
+ ;
+ if (emsg > msg)
+ {
+ int i;
+ for (i = msg; i < emsg; i++)
+ if (at[i].a_type == A_DOLLAR || at[i].a_type == A_DOLLSYM)
+ {
+ pd_error(x, "netreceive: got dollar sign in message");
+ goto nodice;
+ }
+ if (at[msg].a_type == A_FLOAT)
+ {
+ if (emsg > msg + 1)
+ outlet_list(x->x_obj.ob_outlet, 0, emsg-msg, at + msg);
+ else outlet_float(x->x_obj.ob_outlet, at[msg].a_w.w_float);
+ }
+ else if (at[msg].a_type == A_SYMBOL)
+ outlet_anything(x->x_obj.ob_outlet, at[msg].a_w.w_symbol,
+ emsg-msg-1, at + msg + 1);
+ }
+ nodice:
+ msg = emsg + 1;
+ }
+}
+
+
+void shell_read(t_shell *x, int fd)
+{
+ char buf[INBUFSIZE];
+ t_binbuf* bbuf = binbuf_new();
+ int i;
+ int readto =
+ (x->sr_inhead >= x->sr_intail ? INBUFSIZE : x->sr_intail-1);
+ int ret;
+
+ ret = read(fd, buf,INBUFSIZE-1);
+ buf[ret] = '\0';
+
+ for (i=0;i<ret;i++)
+ if (buf[i] == '\n') buf[i] = ';';
+ if (ret < 0)
+ {
+ error("shell: pipe read error");
+ sys_rmpollfn(fd);
+ x->fdpipe[0] = -1;
+ close(fd);
+ return;
+ }
+ else if (ret == 0)
+ {
+ post("EOF on socket %d\n", fd);
+ sys_rmpollfn(fd);
+ x->fdpipe[0] = -1;
+ close(fd);
+ return;
+ }
+ else
+ {
+ int natom;
+ t_atom *at;
+ binbuf_text(bbuf, buf, strlen(buf));
+
+ natom = binbuf_getnatom(bbuf);
+ at = binbuf_getvec(bbuf);
+ shell_doit(x,bbuf);
+ }
+ binbuf_free(bbuf);
+}
+
+
+static void shell_send(t_shell *x, t_symbol *s,int ac, t_atom *at)
+{
+ int i;
+ char tmp[MAXPDSTRING];
+ int size = 0;
+
+ if (x->fdinpipe[0] == -1) return; /* nothing to send to */
+
+ for (i=0;i<ac;i++) {
+ atom_string(at,tmp+size,MAXPDSTRING - size);
+ at++;
+ size=strlen(tmp);
+ tmp[size++] = ' ';
+ }
+ tmp[size-1] = '\0';
+ post("sending %s",tmp);
+ write(x->fdinpipe[0],tmp,strlen(tmp));
+}
+
+static void shell_anything(t_shell *x, t_symbol *s, int ac, t_atom *at)
+{
+ int i;
+ char* argv[20];
+ t_symbol* sym;
+
+ if (!strcmp(s->s_name,"send")) {
+ post("send");
+ shell_send(x,s,ac,at);
+ return;
+ }
+
+ argv[0] = s->s_name;
+
+ if (x->fdpipe[0] != -1) {
+ post("shell: old process still running");
+ kill(x->pid,SIGKILL);
+ shell_cleanup(x);
+ }
+
+
+ if (pipe(x->fdpipe) < 0) {
+ error("unable to create pipe");
+ return;
+ }
+
+ if (pipe(x->fdinpipe) < 0) {
+ error("unable to create input pipe");
+ return;
+ }
+
+
+ sys_addpollfn(x->fdpipe[0],shell_read,x);
+
+ if (!(x->pid = fork())) {
+ int status;
+ char* cmd = getbytes(1024);
+ char* tcmd = getbytes(1024);
+ strcpy(cmd,s->s_name);
+
+#if 0
+ for (i=1;i<=ac;i++) {
+ argv[i] = getbytes(255);
+ atom_string(at,argv[i],255);
+/* post("argument %s",argv[i]); */
+ at++;
+ }
+ argv[i] = 0;
+#endif
+ for (i=1;i<=ac;i++) {
+ atom_string(at,tcmd,255);
+ strcat(cmd," ");
+ strcat(cmd,tcmd);
+ at++;
+ }
+
+
+ /* reassign stdout */
+ dup2(x->fdpipe[1],1);
+ dup2(x->fdinpipe[1],0);
+
+ /* drop privileges */
+ drop_priority();
+ seteuid(getuid()); /* lose setuid priveliges */
+
+ post("executing %s",cmd);
+ system(cmd);
+// execvp(s->s_name,argv);
+ exit(0);
+ }
+ x->x_del = 4;
+ clock_delay(x->x_clock,x->x_del);
+
+ if (x->x_echo)
+ outlet_anything(x->x_obj.ob_outlet, s, ac, at);
+}
+
+
+
+void shell_free(t_shell* x)
+{
+ binbuf_free(x->x_binbuf);
+}
+
+static void *shell_new(void)
+{
+ t_shell *x = (t_shell *)pd_new(shell_class);
+
+ x->x_echo = 0;
+ x->fdpipe[0] = -1;
+ x->fdpipe[1] = -1;
+ x->fdinpipe[0] = -1;
+ x->fdinpipe[1] = -1;
+
+ x->sr_inhead = x->sr_intail = 0;
+ if (!(x->sr_inbuf = (char*) malloc(INBUFSIZE))) bug("t_shell");;
+
+ x->x_binbuf = binbuf_new();
+
+ outlet_new(&x->x_obj, &s_list);
+ x->x_done = outlet_new(&x->x_obj, &s_bang);
+ x->x_clock = clock_new(x, (t_method) shell_check);
+ return (x);
+}
+
+void shell_setup(void)
+{
+ shell_class = class_new(gensym("shell"), (t_newmethod)shell_new,
+ (t_method)shell_free,sizeof(t_shell), 0,0);
+ class_addbang(shell_class,shell_bang);
+ class_addanything(shell_class, shell_anything);
+}
+
+
diff --git a/apps/plugins/pdbox/PDa/extra/slider.c b/apps/plugins/pdbox/PDa/extra/slider.c
new file mode 100644
index 0000000000..4650050006
--- /dev/null
+++ b/apps/plugins/pdbox/PDa/extra/slider.c
@@ -0,0 +1,106 @@
+#include <stdio.h>
+#include "m_pd.h"
+#include "g_canvas.h" /* for widgetbehaviour */
+#include "fatom.h"
+
+static t_class *slider_class;
+
+static void slider_save(t_gobj *z, t_binbuf *b)
+{
+ t_fatom *x = (t_fatom *)z;
+
+ binbuf_addv(b, "ssiisiiisss", gensym("#X"),gensym("obj"),
+ x->x_obj.te_xpix, x->x_obj.te_ypix ,
+ gensym("slider"),x->x_max,x->x_min,x->x_width,x->x_send,x->x_color,x->x_bgcolor);
+ binbuf_addv(b, ";");
+}
+
+
+static void *slider_new(t_symbol* s,t_int argc, t_atom* argv)
+{
+ t_fatom *x = (t_fatom *)pd_new(slider_class);
+ x->x_type = gensym("vslider");
+ return fatom_new(x,argc,argv);
+}
+
+
+t_widgetbehavior slider_widgetbehavior;
+
+
+void slider_setup(void) {
+ slider_class = class_new(gensym("slider"), (t_newmethod)slider_new, 0,
+ sizeof(t_fatom),0,A_GIMME,0);
+
+ slider_widgetbehavior.w_getrectfn = fatom_getrect;
+ slider_widgetbehavior.w_displacefn = fatom_displace;
+ slider_widgetbehavior.w_selectfn = fatom_select;
+ slider_widgetbehavior.w_activatefn = fatom_activate;
+ slider_widgetbehavior.w_deletefn = fatom_delete;
+ slider_widgetbehavior.w_visfn= fatom_vis;
+ slider_widgetbehavior.w_clickfn = NULL;
+
+ fatom_setup_common(slider_class);
+ class_setwidget(slider_class,&slider_widgetbehavior);
+
+#if PD_MINOR_VERSION < 37
+ slider_widgetbehavior.w_savefn = slider_save;
+ slider_widgetbehavior.w_propertiesfn = NULL;
+#else
+ class_setsavefn(slider_class,&slider_save);
+ class_setpropertiesfn(slider_class,&fatom_properties);
+#endif
+
+}
+#include <stdio.h>
+#include "m_pd.h"
+#include "g_canvas.h" /* for widgetbehaviour */
+#include "fatom.h"
+
+static t_class *slider_class;
+
+static void slider_save(t_gobj *z, t_binbuf *b)
+{
+ t_fatom *x = (t_fatom *)z;
+
+ binbuf_addv(b, "ssiisiiisss", gensym("#X"),gensym("obj"),
+ x->x_obj.te_xpix, x->x_obj.te_ypix ,
+ gensym("slider"),x->x_max,x->x_min,x->x_width,x->x_send,x->x_color,x->x_bgcolor);
+ binbuf_addv(b, ";");
+}
+
+
+static void *slider_new(t_symbol* s,t_int argc, t_atom* argv)
+{
+ t_fatom *x = (t_fatom *)pd_new(slider_class);
+ x->x_type = gensym("vslider");
+ return fatom_new(x,argc,argv);
+}
+
+
+t_widgetbehavior slider_widgetbehavior;
+
+
+void slider_setup(void) {
+ slider_class = class_new(gensym("slider"), (t_newmethod)slider_new, 0,
+ sizeof(t_fatom),0,A_GIMME,0);
+
+ slider_widgetbehavior.w_getrectfn = fatom_getrect;
+ slider_widgetbehavior.w_displacefn = fatom_displace;
+ slider_widgetbehavior.w_selectfn = fatom_select;
+ slider_widgetbehavior.w_activatefn = fatom_activate;
+ slider_widgetbehavior.w_deletefn = fatom_delete;
+ slider_widgetbehavior.w_visfn= fatom_vis;
+ slider_widgetbehavior.w_clickfn = NULL;
+
+ fatom_setup_common(slider_class);
+ class_setwidget(slider_class,&slider_widgetbehavior);
+
+#if PD_MINOR_VERSION < 37
+ slider_widgetbehavior.w_savefn = slider_save;
+ slider_widgetbehavior.w_propertiesfn = NULL;
+#else
+ class_setsavefn(slider_class,&slider_save);
+ class_setpropertiesfn(slider_class,&fatom_properties);
+#endif
+
+}
diff --git a/apps/plugins/pdbox/PDa/extra/sliderh.c b/apps/plugins/pdbox/PDa/extra/sliderh.c
new file mode 100644
index 0000000000..23a6d256e0
--- /dev/null
+++ b/apps/plugins/pdbox/PDa/extra/sliderh.c
@@ -0,0 +1,126 @@
+#include "m_pd.h"
+#include "g_canvas.h"
+
+
+#ifdef NT
+#pragma warning( disable : 4244 )
+#pragma warning( disable : 4305 )
+#endif
+
+#include "fatom.h"
+
+/* can we use the normal text save function ?? */
+
+static t_class *sliderh_class;
+
+static void sliderh_save(t_gobj *z, t_binbuf *b)
+{
+
+ t_fatom *x = (t_fatom *)z;
+
+ binbuf_addv(b, "ssiisiiisss", gensym("#X"),gensym("obj"),
+ x->x_obj.te_xpix, x->x_obj.te_ypix ,
+ gensym("sliderh"),x->x_max,x->x_min,x->x_width,x->x_send,x->x_color,x->x_bgcolor);
+ binbuf_addv(b, ";");
+}
+
+
+static void *sliderh_new(t_symbol* s, int argc, t_atom* argv)
+{
+ t_fatom *x = (t_fatom *)pd_new(sliderh_class);
+ x->x_type = gensym("hslider");
+ return fatom_new(x,argc,argv);
+}
+
+
+t_widgetbehavior sliderh_widgetbehavior;
+
+
+
+
+void sliderh_setup(void) {
+ sliderh_class = class_new(gensym("sliderh"), (t_newmethod)sliderh_new, 0,
+ sizeof(t_fatom),0,A_DEFFLOAT,A_DEFFLOAT,A_DEFFLOAT,0);
+
+ fatom_setup_common(sliderh_class);
+
+ sliderh_widgetbehavior.w_getrectfn = fatom_getrect;
+ sliderh_widgetbehavior.w_displacefn= fatom_displace;
+ sliderh_widgetbehavior.w_selectfn= fatom_select;
+ sliderh_widgetbehavior.w_activatefn=fatom_activate;
+ sliderh_widgetbehavior.w_deletefn= fatom_delete;
+ sliderh_widgetbehavior.w_visfn= fatom_vis;
+#if PD_MINOR_VERSION < 37
+ sliderh_widgetbehavior.w_savefn= sliderh_save;
+ sliderh_widgetbehavior.w_propertiesfn= NULL;
+#endif
+ sliderh_widgetbehavior.w_clickfn= NULL;
+
+ class_setwidget(sliderh_class,&sliderh_widgetbehavior);
+#if PD_MINOR_VERSION >= 37
+ class_setsavefn(sliderh_class,&sliderh_save);
+#endif
+}
+#include "m_pd.h"
+#include "g_canvas.h"
+
+
+#ifdef NT
+#pragma warning( disable : 4244 )
+#pragma warning( disable : 4305 )
+#endif
+
+#include "fatom.h"
+
+/* can we use the normal text save function ?? */
+
+static t_class *sliderh_class;
+
+static void sliderh_save(t_gobj *z, t_binbuf *b)
+{
+
+ t_fatom *x = (t_fatom *)z;
+
+ binbuf_addv(b, "ssiisiiisss", gensym("#X"),gensym("obj"),
+ x->x_obj.te_xpix, x->x_obj.te_ypix ,
+ gensym("sliderh"),x->x_max,x->x_min,x->x_width,x->x_send,x->x_color,x->x_bgcolor);
+ binbuf_addv(b, ";");
+}
+
+
+static void *sliderh_new(t_symbol* s, int argc, t_atom* argv)
+{
+ t_fatom *x = (t_fatom *)pd_new(sliderh_class);
+ x->x_type = gensym("hslider");
+ return fatom_new(x,argc,argv);
+}
+
+
+t_widgetbehavior sliderh_widgetbehavior;
+
+
+
+
+void sliderh_setup(void) {
+ sliderh_class = class_new(gensym("sliderh"), (t_newmethod)sliderh_new, 0,
+ sizeof(t_fatom),0,A_DEFFLOAT,A_DEFFLOAT,A_DEFFLOAT,0);
+
+ fatom_setup_common(sliderh_class);
+
+ sliderh_widgetbehavior.w_getrectfn = fatom_getrect;
+ sliderh_widgetbehavior.w_displacefn= fatom_displace;
+ sliderh_widgetbehavior.w_selectfn= fatom_select;
+ sliderh_widgetbehavior.w_activatefn=fatom_activate;
+ sliderh_widgetbehavior.w_deletefn= fatom_delete;
+ sliderh_widgetbehavior.w_visfn= fatom_vis;
+#if PD_MINOR_VERSION < 37
+ sliderh_widgetbehavior.w_savefn= sliderh_save;
+ sliderh_widgetbehavior.w_propertiesfn= NULL;
+#endif
+ sliderh_widgetbehavior.w_clickfn= NULL;
+
+ class_setwidget(sliderh_class,&sliderh_widgetbehavior);
+#if PD_MINOR_VERSION >= 37
+ class_setsavefn(sliderh_class,&sliderh_save);
+#endif
+}
diff --git a/apps/plugins/pdbox/PDa/extra/test-clip.pd b/apps/plugins/pdbox/PDa/extra/test-clip.pd
new file mode 100644
index 0000000000..c682e31845
--- /dev/null
+++ b/apps/plugins/pdbox/PDa/extra/test-clip.pd
@@ -0,0 +1,26 @@
+#N canvas 0 0 240 300 10;
+#X obj 57 84 clip~ -0.1 0.1;
+#X obj 58 61 sig~;
+#X obj 57 111 snapshot~;
+#X floatatom 58 19 5 0 0 0 - - -;
+#X floatatom 57 144 5 0 0 0 - - -;
+#X obj 58 37 t f b;
+#X connect 0 0 2 0;
+#X connect 1 0 0 0;
+#X connect 2 0 4 0;
+#X connect 3 0 5 0;
+#X connect 5 0 1 0;
+#X connect 5 1 2 0;
+#N canvas 0 0 240 300 10;
+#X obj 57 84 clip~ -0.1 0.1;
+#X obj 58 61 sig~;
+#X obj 57 111 snapshot~;
+#X floatatom 58 19 5 0 0 0 - - -;
+#X floatatom 57 144 5 0 0 0 - - -;
+#X obj 58 37 t f b;
+#X connect 0 0 2 0;
+#X connect 1 0 0 0;
+#X connect 2 0 4 0;
+#X connect 3 0 5 0;
+#X connect 5 0 1 0;
+#X connect 5 1 2 0;
diff --git a/apps/plugins/pdbox/PDa/extra/test-vcf.pd b/apps/plugins/pdbox/PDa/extra/test-vcf.pd
new file mode 100644
index 0000000000..099d3d7958
--- /dev/null
+++ b/apps/plugins/pdbox/PDa/extra/test-vcf.pd
@@ -0,0 +1,36 @@
+#N canvas 0 0 240 300 10;
+#X obj 38 93 noise~;
+#X obj 44 161 vcf~;
+#X obj 48 191 dac~;
+#X floatatom 138 33 5 0 0 0 - - -;
+#X obj 44 18 osc~ 1;
+#X obj 46 75 *~ 800;
+#X obj 48 48 +~ 2;
+#X obj 106 125 sig~;
+#X floatatom 132 77 5 0 0 0 - - -;
+#X connect 0 0 1 0;
+#X connect 1 0 2 0;
+#X connect 1 0 2 1;
+#X connect 3 0 1 2;
+#X connect 4 0 6 0;
+#X connect 6 0 5 0;
+#X connect 7 0 1 1;
+#X connect 8 0 7 0;
+#N canvas 0 0 240 300 10;
+#X obj 38 93 noise~;
+#X obj 44 161 vcf~;
+#X obj 48 191 dac~;
+#X floatatom 138 33 5 0 0 0 - - -;
+#X obj 44 18 osc~ 1;
+#X obj 46 75 *~ 800;
+#X obj 48 48 +~ 2;
+#X obj 106 125 sig~;
+#X floatatom 132 77 5 0 0 0 - - -;
+#X connect 0 0 1 0;
+#X connect 1 0 2 0;
+#X connect 1 0 2 1;
+#X connect 3 0 1 2;
+#X connect 4 0 6 0;
+#X connect 6 0 5 0;
+#X connect 7 0 1 1;
+#X connect 8 0 7 0;
diff --git a/apps/plugins/pdbox/PDa/extra/zerox~.c b/apps/plugins/pdbox/PDa/extra/zerox~.c
new file mode 100644
index 0000000000..f97f412308
--- /dev/null
+++ b/apps/plugins/pdbox/PDa/extra/zerox~.c
@@ -0,0 +1,114 @@
+#include "m_pd.h"
+
+static t_class *zerox_class;
+
+typedef struct _zerox
+{
+ t_object x_obj;
+ t_sample x_f;
+ t_int x_zeros;
+} t_zerox;
+
+
+static t_int *zerox_perform(t_int *w)
+{
+ t_zerox* x = (t_zerox*)w[1];
+ t_sample *in = (t_sample *)(w[2]);
+ int n = (int)(w[3]) ;
+
+ if (*in * x->x_f < 0) x->x_zeros++;
+ n--;
+ while (n--)
+ {
+ float f = *(in++);
+ x->x_zeros += f * *in < 0;
+ }
+ return (w+4);
+}
+
+static void zerox_dsp(t_zerox *x, t_signal **sp)
+{
+ dsp_add(zerox_perform, 3, x, sp[0]->s_vec, sp[0]->s_n);
+}
+
+
+static void zerox_bang(t_zerox* x)
+{
+ outlet_float(x->x_obj.ob_outlet,x->x_zeros);
+ x->x_zeros=0;
+}
+
+static void *zerox_new(void)
+{
+ t_zerox *x = (t_zerox *)pd_new(zerox_class);
+ outlet_new(&x->x_obj, gensym("float"));
+ x->x_f = 0;
+ x->x_zeros=0;
+ return (x);
+}
+
+void zerox_tilde_setup(void)
+{
+ zerox_class = class_new(gensym("zerox~"), (t_newmethod)zerox_new, 0,
+ sizeof(t_zerox), 0, A_DEFFLOAT, 0);
+ CLASS_MAINSIGNALIN(zerox_class, t_zerox, x_f);
+ class_addmethod(zerox_class, (t_method)zerox_dsp, gensym("dsp"), 0);
+ class_addbang(zerox_class, (t_method)zerox_bang);
+}
+#include "m_pd.h"
+
+static t_class *zerox_class;
+
+typedef struct _zerox
+{
+ t_object x_obj;
+ t_sample x_f;
+ t_int x_zeros;
+} t_zerox;
+
+
+static t_int *zerox_perform(t_int *w)
+{
+ t_zerox* x = (t_zerox*)w[1];
+ t_sample *in = (t_sample *)(w[2]);
+ int n = (int)(w[3]) ;
+
+ if (*in * x->x_f < 0) x->x_zeros++;
+ n--;
+ while (n--)
+ {
+ float f = *(in++);
+ x->x_zeros += f * *in < 0;
+ }
+ return (w+4);
+}
+
+static void zerox_dsp(t_zerox *x, t_signal **sp)
+{
+ dsp_add(zerox_perform, 3, x, sp[0]->s_vec, sp[0]->s_n);
+}
+
+
+static void zerox_bang(t_zerox* x)
+{
+ outlet_float(x->x_obj.ob_outlet,x->x_zeros);
+ x->x_zeros=0;
+}
+
+static void *zerox_new(void)
+{
+ t_zerox *x = (t_zerox *)pd_new(zerox_class);
+ outlet_new(&x->x_obj, gensym("float"));
+ x->x_f = 0;
+ x->x_zeros=0;
+ return (x);
+}
+
+void zerox_tilde_setup(void)
+{
+ zerox_class = class_new(gensym("zerox~"), (t_newmethod)zerox_new, 0,
+ sizeof(t_zerox), 0, A_DEFFLOAT, 0);
+ CLASS_MAINSIGNALIN(zerox_class, t_zerox, x_f);
+ class_addmethod(zerox_class, (t_method)zerox_dsp, gensym("dsp"), 0);
+ class_addbang(zerox_class, (t_method)zerox_bang);
+}
diff --git a/apps/plugins/pdbox/PDa/intern/biquad~.c b/apps/plugins/pdbox/PDa/intern/biquad~.c
new file mode 100644
index 0000000000..c37182a911
--- /dev/null
+++ b/apps/plugins/pdbox/PDa/intern/biquad~.c
@@ -0,0 +1,252 @@
+#include <m_pd.h>
+#include <m_fixed.h>
+
+typedef struct biquadctl
+{
+ t_sample c_x1;
+ t_sample c_x2;
+ t_sample c_fb1;
+ t_sample c_fb2;
+ t_sample c_ff1;
+ t_sample c_ff2;
+ t_sample c_ff3;
+} t_biquadctl;
+
+typedef struct sigbiquad
+{
+ t_object x_obj;
+ float x_f;
+ t_biquadctl x_cspace;
+ t_biquadctl *x_ctl;
+} t_sigbiquad;
+
+t_class *sigbiquad_class;
+
+static void sigbiquad_list(t_sigbiquad *x, t_symbol *s, int argc, t_atom *argv);
+
+static void *sigbiquad_new(t_symbol *s, int argc, t_atom *argv)
+{
+ t_sigbiquad *x = (t_sigbiquad *)pd_new(sigbiquad_class);
+ outlet_new(&x->x_obj, gensym("signal"));
+ x->x_ctl = &x->x_cspace;
+ x->x_cspace.c_x1 = x->x_cspace.c_x2 = 0;
+ sigbiquad_list(x, s, argc, argv);
+ x->x_f = 0;
+ return (x);
+}
+
+static t_int *sigbiquad_perform(t_int *w)
+{
+ t_sample *in = (t_sample *)(w[1]);
+ t_sample *out = (t_sample *)(w[2]);
+ t_biquadctl *c = (t_biquadctl *)(w[3]);
+ int n = (t_int)(w[4]);
+ int i;
+ t_sample last = c->c_x1;
+ t_sample prev = c->c_x2;
+ t_sample fb1 = c->c_fb1;
+ t_sample fb2 = c->c_fb2;
+ t_sample ff1 = c->c_ff1;
+ t_sample ff2 = c->c_ff2;
+ t_sample ff3 = c->c_ff3;
+ for (i = 0; i < n; i++)
+ {
+ t_sample output = *in++ + mult(fb1,last) + mult(fb2,prev);
+ if (PD_BADFLOAT(output))
+ output = 0;
+ *out++ = mult(ff1,output) + mult(ff2,last) + mult(ff3,prev);
+ prev = last;
+ last = output;
+ }
+ c->c_x1 = last;
+ c->c_x2 = prev;
+ return (w+5);
+}
+
+static void sigbiquad_list(t_sigbiquad *x, t_symbol *s, int argc, t_atom *argv)
+{
+ float fb1 = atom_getfloatarg(0, argc, argv);
+ float fb2 = atom_getfloatarg(1, argc, argv);
+ float ff1 = atom_getfloatarg(2, argc, argv);
+ float ff2 = atom_getfloatarg(3, argc, argv);
+ float ff3 = atom_getfloatarg(4, argc, argv);
+ float discriminant = fb1 * fb1 + 4 * fb2;
+ t_biquadctl *c = x->x_ctl;
+ if (discriminant < 0) /* imaginary roots -- resonant filter */
+ {
+ /* they're conjugates so we just check that the product
+ is less than one */
+ if (fb2 >= -1.0f) goto stable;
+ }
+ else /* real roots */
+ {
+ /* check that the parabola 1 - fb1 x - fb2 x^2 has a
+ vertex between -1 and 1, and that it's nonnegative
+ at both ends, which implies both roots are in [1-,1]. */
+ if (fb1 <= 2.0f && fb1 >= -2.0f &&
+ 1.0f - fb1 -fb2 >= 0 && 1.0f + fb1 - fb2 >= 0)
+ goto stable;
+ }
+ /* if unstable, just bash to zero */
+ fb1 = fb2 = ff1 = ff2 = ff3 = 0;
+stable:
+ c->c_fb1 = ftofix(fb1);
+ c->c_fb2 = ftofix(fb2);
+ c->c_ff1 = ftofix(ff1);
+ c->c_ff2 = ftofix(ff2);
+ c->c_ff3 = ftofix(ff3);
+}
+
+static void sigbiquad_set(t_sigbiquad *x, t_symbol *s, int argc, t_atom *argv)
+{
+ t_biquadctl *c = x->x_ctl;
+ c->c_x1 = atom_getfloatarg(0, argc, argv);
+ c->c_x2 = atom_getfloatarg(1, argc, argv);
+}
+
+static void sigbiquad_dsp(t_sigbiquad *x, t_signal **sp)
+{
+ dsp_add(sigbiquad_perform, 4,
+ sp[0]->s_vec, sp[1]->s_vec,
+ x->x_ctl, sp[0]->s_n);
+
+}
+
+void biquad_tilde_setup(void)
+{
+ sigbiquad_class = class_new(gensym("biquad~"), (t_newmethod)sigbiquad_new,
+ 0, sizeof(t_sigbiquad), 0, A_GIMME, 0);
+ CLASS_MAINSIGNALIN(sigbiquad_class, t_sigbiquad, x_f);
+ class_addmethod(sigbiquad_class, (t_method)sigbiquad_dsp, gensym("dsp"), 0);
+ class_addlist(sigbiquad_class, sigbiquad_list);
+ class_addmethod(sigbiquad_class, (t_method)sigbiquad_set, gensym("set"),
+ A_GIMME, 0);
+ class_addmethod(sigbiquad_class, (t_method)sigbiquad_set, gensym("clear"),
+ A_GIMME, 0);
+}
+#include <m_pd.h>
+#include <m_fixed.h>
+
+typedef struct biquadctl
+{
+ t_sample c_x1;
+ t_sample c_x2;
+ t_sample c_fb1;
+ t_sample c_fb2;
+ t_sample c_ff1;
+ t_sample c_ff2;
+ t_sample c_ff3;
+} t_biquadctl;
+
+typedef struct sigbiquad
+{
+ t_object x_obj;
+ float x_f;
+ t_biquadctl x_cspace;
+ t_biquadctl *x_ctl;
+} t_sigbiquad;
+
+t_class *sigbiquad_class;
+
+static void sigbiquad_list(t_sigbiquad *x, t_symbol *s, int argc, t_atom *argv);
+
+static void *sigbiquad_new(t_symbol *s, int argc, t_atom *argv)
+{
+ t_sigbiquad *x = (t_sigbiquad *)pd_new(sigbiquad_class);
+ outlet_new(&x->x_obj, gensym("signal"));
+ x->x_ctl = &x->x_cspace;
+ x->x_cspace.c_x1 = x->x_cspace.c_x2 = 0;
+ sigbiquad_list(x, s, argc, argv);
+ x->x_f = 0;
+ return (x);
+}
+
+static t_int *sigbiquad_perform(t_int *w)
+{
+ t_sample *in = (t_sample *)(w[1]);
+ t_sample *out = (t_sample *)(w[2]);
+ t_biquadctl *c = (t_biquadctl *)(w[3]);
+ int n = (t_int)(w[4]);
+ int i;
+ t_sample last = c->c_x1;
+ t_sample prev = c->c_x2;
+ t_sample fb1 = c->c_fb1;
+ t_sample fb2 = c->c_fb2;
+ t_sample ff1 = c->c_ff1;
+ t_sample ff2 = c->c_ff2;
+ t_sample ff3 = c->c_ff3;
+ for (i = 0; i < n; i++)
+ {
+ t_sample output = *in++ + mult(fb1,last) + mult(fb2,prev);
+ if (PD_BADFLOAT(output))
+ output = 0;
+ *out++ = mult(ff1,output) + mult(ff2,last) + mult(ff3,prev);
+ prev = last;
+ last = output;
+ }
+ c->c_x1 = last;
+ c->c_x2 = prev;
+ return (w+5);
+}
+
+static void sigbiquad_list(t_sigbiquad *x, t_symbol *s, int argc, t_atom *argv)
+{
+ float fb1 = atom_getfloatarg(0, argc, argv);
+ float fb2 = atom_getfloatarg(1, argc, argv);
+ float ff1 = atom_getfloatarg(2, argc, argv);
+ float ff2 = atom_getfloatarg(3, argc, argv);
+ float ff3 = atom_getfloatarg(4, argc, argv);
+ float discriminant = fb1 * fb1 + 4 * fb2;
+ t_biquadctl *c = x->x_ctl;
+ if (discriminant < 0) /* imaginary roots -- resonant filter */
+ {
+ /* they're conjugates so we just check that the product
+ is less than one */
+ if (fb2 >= -1.0f) goto stable;
+ }
+ else /* real roots */
+ {
+ /* check that the parabola 1 - fb1 x - fb2 x^2 has a
+ vertex between -1 and 1, and that it's nonnegative
+ at both ends, which implies both roots are in [1-,1]. */
+ if (fb1 <= 2.0f && fb1 >= -2.0f &&
+ 1.0f - fb1 -fb2 >= 0 && 1.0f + fb1 - fb2 >= 0)
+ goto stable;
+ }
+ /* if unstable, just bash to zero */
+ fb1 = fb2 = ff1 = ff2 = ff3 = 0;
+stable:
+ c->c_fb1 = ftofix(fb1);
+ c->c_fb2 = ftofix(fb2);
+ c->c_ff1 = ftofix(ff1);
+ c->c_ff2 = ftofix(ff2);
+ c->c_ff3 = ftofix(ff3);
+}
+
+static void sigbiquad_set(t_sigbiquad *x, t_symbol *s, int argc, t_atom *argv)
+{
+ t_biquadctl *c = x->x_ctl;
+ c->c_x1 = atom_getfloatarg(0, argc, argv);
+ c->c_x2 = atom_getfloatarg(1, argc, argv);
+}
+
+static void sigbiquad_dsp(t_sigbiquad *x, t_signal **sp)
+{
+ dsp_add(sigbiquad_perform, 4,
+ sp[0]->s_vec, sp[1]->s_vec,
+ x->x_ctl, sp[0]->s_n);
+
+}
+
+void biquad_tilde_setup(void)
+{
+ sigbiquad_class = class_new(gensym("biquad~"), (t_newmethod)sigbiquad_new,
+ 0, sizeof(t_sigbiquad), 0, A_GIMME, 0);
+ CLASS_MAINSIGNALIN(sigbiquad_class, t_sigbiquad, x_f);
+ class_addmethod(sigbiquad_class, (t_method)sigbiquad_dsp, gensym("dsp"), 0);
+ class_addlist(sigbiquad_class, sigbiquad_list);
+ class_addmethod(sigbiquad_class, (t_method)sigbiquad_set, gensym("set"),
+ A_GIMME, 0);
+ class_addmethod(sigbiquad_class, (t_method)sigbiquad_set, gensym("clear"),
+ A_GIMME, 0);
+}
diff --git a/apps/plugins/pdbox/PDa/intern/bp~.c b/apps/plugins/pdbox/PDa/intern/bp~.c
new file mode 100644
index 0000000000..f247c1d66b
--- /dev/null
+++ b/apps/plugins/pdbox/PDa/intern/bp~.c
@@ -0,0 +1,276 @@
+#include <m_pd.h>
+#include <m_fixed.h>
+
+typedef struct bpctl
+{
+ t_sample c_x1;
+ t_sample c_x2;
+ t_sample c_coef1;
+ t_sample c_coef2;
+ t_sample c_gain;
+} t_bpctl;
+
+typedef struct sigbp
+{
+ t_object x_obj;
+ float x_sr;
+ float x_freq;
+ float x_q;
+ t_bpctl x_cspace;
+ t_bpctl *x_ctl;
+ float x_f;
+} t_sigbp;
+
+t_class *sigbp_class;
+
+static void sigbp_docoef(t_sigbp *x, t_floatarg f, t_floatarg q);
+
+static void *sigbp_new(t_floatarg f, t_floatarg q)
+{
+ t_sigbp *x = (t_sigbp *)pd_new(sigbp_class);
+ inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("float"), gensym("ft1"));
+ inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("float"), gensym("ft2"));
+ outlet_new(&x->x_obj, gensym("signal"));
+ x->x_sr = 44100;
+ x->x_ctl = &x->x_cspace;
+ x->x_cspace.c_x1 = 0;
+ x->x_cspace.c_x2 = 0;
+ sigbp_docoef(x, f, q);
+ x->x_f = 0;
+ return (x);
+}
+
+static float sigbp_qcos(float f)
+{
+ if (f >= -(0.5f*3.14159f) && f <= 0.5f*3.14159f)
+ {
+ float g = f*f;
+ return (((g*g*g * (-1.0f/720.0f) + g*g*(1.0f/24.0f)) - g*0.5) + 1);
+ }
+ else return (0);
+}
+
+static void sigbp_docoef(t_sigbp *x, t_floatarg f, t_floatarg q)
+{
+ float r, oneminusr, omega;
+ if (f < 0.001) f = 10;
+ if (q < 0) q = 0;
+ x->x_freq = f;
+ x->x_q = q;
+ omega = f * (2.0f * 3.14159f) / x->x_sr;
+ if (q < 0.001) oneminusr = 1.0f;
+ else oneminusr = omega/q;
+ if (oneminusr > 1.0f) oneminusr = 1.0f;
+ r = 1.0f - oneminusr;
+ x->x_ctl->c_coef1 = ftofix(2.0f * sigbp_qcos(omega) * r);
+ x->x_ctl->c_coef2 = ftofix(- r * r);
+ x->x_ctl->c_gain = ftofix(2 * oneminusr * (oneminusr + r * omega));
+ /* post("r %f, omega %f, coef1 %f, coef2 %f",
+ r, omega, x->x_ctl->c_coef1, x->x_ctl->c_coef2); */
+}
+
+static void sigbp_ft1(t_sigbp *x, t_floatarg f)
+{
+ sigbp_docoef(x, f, x->x_q);
+}
+
+static void sigbp_ft2(t_sigbp *x, t_floatarg q)
+{
+ sigbp_docoef(x, x->x_freq, q);
+}
+
+static void sigbp_clear(t_sigbp *x, t_floatarg q)
+{
+ x->x_ctl->c_x1 = x->x_ctl->c_x2 = 0;
+}
+
+static t_int *sigbp_perform(t_int *w)
+{
+ t_sample *in = (t_sample *)(w[1]);
+ t_sample *out = (t_sample *)(w[2]);
+ t_bpctl *c = (t_bpctl *)(w[3]);
+ int n = (t_int)(w[4]);
+ int i;
+ t_sample last = c->c_x1;
+ t_sample prev = c->c_x2;
+ t_sample coef1 = c->c_coef1;
+ t_sample coef2 = c->c_coef2;
+ t_sample gain = c->c_gain;
+ for (i = 0; i < n; i++)
+ {
+ t_sample output = *in++ + mult(coef1,last) + mult(coef2,prev);
+ *out++ = mult(gain,output);
+ prev = last;
+ last = output;
+ }
+ if (PD_BADFLOAT(last))
+ last = 0;
+ if (PD_BADFLOAT(prev))
+ prev = 0;
+ c->c_x1 = last;
+ c->c_x2 = prev;
+ return (w+5);
+}
+
+static void sigbp_dsp(t_sigbp *x, t_signal **sp)
+{
+ x->x_sr = sp[0]->s_sr;
+ sigbp_docoef(x, x->x_freq, x->x_q);
+ dsp_add(sigbp_perform, 4,
+ sp[0]->s_vec, sp[1]->s_vec,
+ x->x_ctl, sp[0]->s_n);
+
+}
+
+void bp_tilde_setup(void)
+{
+ sigbp_class = class_new(gensym("bp~"), (t_newmethod)sigbp_new, 0,
+ sizeof(t_sigbp), 0, A_DEFFLOAT, A_DEFFLOAT, 0);
+ CLASS_MAINSIGNALIN(sigbp_class, t_sigbp, x_f);
+ class_addmethod(sigbp_class, (t_method)sigbp_dsp, gensym("dsp"), 0);
+ class_addmethod(sigbp_class, (t_method)sigbp_ft1,
+ gensym("ft1"), A_FLOAT, 0);
+ class_addmethod(sigbp_class, (t_method)sigbp_ft2,
+ gensym("ft2"), A_FLOAT, 0);
+ class_addmethod(sigbp_class, (t_method)sigbp_clear, gensym("clear"), 0);
+ class_sethelpsymbol(sigbp_class, gensym("lop~-help.pd"));
+}
+
+#include <m_pd.h>
+#include <m_fixed.h>
+
+typedef struct bpctl
+{
+ t_sample c_x1;
+ t_sample c_x2;
+ t_sample c_coef1;
+ t_sample c_coef2;
+ t_sample c_gain;
+} t_bpctl;
+
+typedef struct sigbp
+{
+ t_object x_obj;
+ float x_sr;
+ float x_freq;
+ float x_q;
+ t_bpctl x_cspace;
+ t_bpctl *x_ctl;
+ float x_f;
+} t_sigbp;
+
+t_class *sigbp_class;
+
+static void sigbp_docoef(t_sigbp *x, t_floatarg f, t_floatarg q);
+
+static void *sigbp_new(t_floatarg f, t_floatarg q)
+{
+ t_sigbp *x = (t_sigbp *)pd_new(sigbp_class);
+ inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("float"), gensym("ft1"));
+ inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("float"), gensym("ft2"));
+ outlet_new(&x->x_obj, gensym("signal"));
+ x->x_sr = 44100;
+ x->x_ctl = &x->x_cspace;
+ x->x_cspace.c_x1 = 0;
+ x->x_cspace.c_x2 = 0;
+ sigbp_docoef(x, f, q);
+ x->x_f = 0;
+ return (x);
+}
+
+static float sigbp_qcos(float f)
+{
+ if (f >= -(0.5f*3.14159f) && f <= 0.5f*3.14159f)
+ {
+ float g = f*f;
+ return (((g*g*g * (-1.0f/720.0f) + g*g*(1.0f/24.0f)) - g*0.5) + 1);
+ }
+ else return (0);
+}
+
+static void sigbp_docoef(t_sigbp *x, t_floatarg f, t_floatarg q)
+{
+ float r, oneminusr, omega;
+ if (f < 0.001) f = 10;
+ if (q < 0) q = 0;
+ x->x_freq = f;
+ x->x_q = q;
+ omega = f * (2.0f * 3.14159f) / x->x_sr;
+ if (q < 0.001) oneminusr = 1.0f;
+ else oneminusr = omega/q;
+ if (oneminusr > 1.0f) oneminusr = 1.0f;
+ r = 1.0f - oneminusr;
+ x->x_ctl->c_coef1 = ftofix(2.0f * sigbp_qcos(omega) * r);
+ x->x_ctl->c_coef2 = ftofix(- r * r);
+ x->x_ctl->c_gain = ftofix(2 * oneminusr * (oneminusr + r * omega));
+ /* post("r %f, omega %f, coef1 %f, coef2 %f",
+ r, omega, x->x_ctl->c_coef1, x->x_ctl->c_coef2); */
+}
+
+static void sigbp_ft1(t_sigbp *x, t_floatarg f)
+{
+ sigbp_docoef(x, f, x->x_q);
+}
+
+static void sigbp_ft2(t_sigbp *x, t_floatarg q)
+{
+ sigbp_docoef(x, x->x_freq, q);
+}
+
+static void sigbp_clear(t_sigbp *x, t_floatarg q)
+{
+ x->x_ctl->c_x1 = x->x_ctl->c_x2 = 0;
+}
+
+static t_int *sigbp_perform(t_int *w)
+{
+ t_sample *in = (t_sample *)(w[1]);
+ t_sample *out = (t_sample *)(w[2]);
+ t_bpctl *c = (t_bpctl *)(w[3]);
+ int n = (t_int)(w[4]);
+ int i;
+ t_sample last = c->c_x1;
+ t_sample prev = c->c_x2;
+ t_sample coef1 = c->c_coef1;
+ t_sample coef2 = c->c_coef2;
+ t_sample gain = c->c_gain;
+ for (i = 0; i < n; i++)
+ {
+ t_sample output = *in++ + mult(coef1,last) + mult(coef2,prev);
+ *out++ = mult(gain,output);
+ prev = last;
+ last = output;
+ }
+ if (PD_BADFLOAT(last))
+ last = 0;
+ if (PD_BADFLOAT(prev))
+ prev = 0;
+ c->c_x1 = last;
+ c->c_x2 = prev;
+ return (w+5);
+}
+
+static void sigbp_dsp(t_sigbp *x, t_signal **sp)
+{
+ x->x_sr = sp[0]->s_sr;
+ sigbp_docoef(x, x->x_freq, x->x_q);
+ dsp_add(sigbp_perform, 4,
+ sp[0]->s_vec, sp[1]->s_vec,
+ x->x_ctl, sp[0]->s_n);
+
+}
+
+void bp_tilde_setup(void)
+{
+ sigbp_class = class_new(gensym("bp~"), (t_newmethod)sigbp_new, 0,
+ sizeof(t_sigbp), 0, A_DEFFLOAT, A_DEFFLOAT, 0);
+ CLASS_MAINSIGNALIN(sigbp_class, t_sigbp, x_f);
+ class_addmethod(sigbp_class, (t_method)sigbp_dsp, gensym("dsp"), 0);
+ class_addmethod(sigbp_class, (t_method)sigbp_ft1,
+ gensym("ft1"), A_FLOAT, 0);
+ class_addmethod(sigbp_class, (t_method)sigbp_ft2,
+ gensym("ft2"), A_FLOAT, 0);
+ class_addmethod(sigbp_class, (t_method)sigbp_clear, gensym("clear"), 0);
+ class_sethelpsymbol(sigbp_class, gensym("lop~-help.pd"));
+}
+
diff --git a/apps/plugins/pdbox/PDa/intern/clip~.c b/apps/plugins/pdbox/PDa/intern/clip~.c
new file mode 100644
index 0000000000..e2c697d1d8
--- /dev/null
+++ b/apps/plugins/pdbox/PDa/intern/clip~.c
@@ -0,0 +1,116 @@
+#include <m_pd.h>
+#include <m_fixed.h>
+
+static t_class *clip_class;
+
+typedef struct _clip
+{
+ t_object x_obj;
+ float x_f;
+ t_float x_lo;
+ t_float x_hi;
+} t_clip;
+
+static void *clip_new(t_floatarg lo, t_floatarg hi)
+{
+ t_clip *x = (t_clip *)pd_new(clip_class);
+ x->x_lo = lo;
+ x->x_hi = hi;
+ outlet_new(&x->x_obj, gensym("signal"));
+ floatinlet_new(&x->x_obj, &x->x_lo);
+ floatinlet_new(&x->x_obj, &x->x_hi);
+ x->x_f = 0;
+ return (x);
+}
+
+static t_int *clip_perform(t_int *w)
+{
+ t_clip *x = (t_clip *)(w[1]);
+ t_sample *in = (t_sample *)(w[2]);
+ t_sample *out = (t_sample *)(w[3]);
+ int n = (int)(w[4]);
+ t_sample lo;
+ t_sample hi;
+ lo = ftofix(x->x_lo);
+ hi = ftofix(x->x_hi);
+
+ while (n--)
+ {
+ t_sample f = *in++;
+ if (f < lo) f = lo;
+ if (f > hi) f = hi;
+ *out++ = f;
+ }
+ return (w+5);
+}
+
+static void clip_dsp(t_clip *x, t_signal **sp)
+{
+ dsp_add(clip_perform, 4, x, sp[0]->s_vec, sp[1]->s_vec, sp[0]->s_n);
+}
+
+void clip_tilde_setup(void)
+{
+ clip_class = class_new(gensym("clip~"), (t_newmethod)clip_new, 0,
+ sizeof(t_clip), 0, A_DEFFLOAT, A_DEFFLOAT, 0);
+ CLASS_MAINSIGNALIN(clip_class, t_clip, x_f);
+ class_addmethod(clip_class, (t_method)clip_dsp, gensym("dsp"), 0);
+}
+#include <m_pd.h>
+#include <m_fixed.h>
+
+static t_class *clip_class;
+
+typedef struct _clip
+{
+ t_object x_obj;
+ float x_f;
+ t_float x_lo;
+ t_float x_hi;
+} t_clip;
+
+static void *clip_new(t_floatarg lo, t_floatarg hi)
+{
+ t_clip *x = (t_clip *)pd_new(clip_class);
+ x->x_lo = lo;
+ x->x_hi = hi;
+ outlet_new(&x->x_obj, gensym("signal"));
+ floatinlet_new(&x->x_obj, &x->x_lo);
+ floatinlet_new(&x->x_obj, &x->x_hi);
+ x->x_f = 0;
+ return (x);
+}
+
+static t_int *clip_perform(t_int *w)
+{
+ t_clip *x = (t_clip *)(w[1]);
+ t_sample *in = (t_sample *)(w[2]);
+ t_sample *out = (t_sample *)(w[3]);
+ int n = (int)(w[4]);
+ t_sample lo;
+ t_sample hi;
+ lo = ftofix(x->x_lo);
+ hi = ftofix(x->x_hi);
+
+ while (n--)
+ {
+ t_sample f = *in++;
+ if (f < lo) f = lo;
+ if (f > hi) f = hi;
+ *out++ = f;
+ }
+ return (w+5);
+}
+
+static void clip_dsp(t_clip *x, t_signal **sp)
+{
+ dsp_add(clip_perform, 4, x, sp[0]->s_vec, sp[1]->s_vec, sp[0]->s_n);
+}
+
+void clip_tilde_setup(void)
+{
+ clip_class = class_new(gensym("clip~"), (t_newmethod)clip_new, 0,
+ sizeof(t_clip), 0, A_DEFFLOAT, A_DEFFLOAT, 0);
+ CLASS_MAINSIGNALIN(clip_class, t_clip, x_f);
+ class_addmethod(clip_class, (t_method)clip_dsp, gensym("dsp"), 0);
+}
diff --git a/apps/plugins/pdbox/PDa/intern/cos_table.h b/apps/plugins/pdbox/PDa/intern/cos_table.h
new file mode 100644
index 0000000000..b30bb4245b
--- /dev/null
+++ b/apps/plugins/pdbox/PDa/intern/cos_table.h
@@ -0,0 +1,6 @@
+#define ILOGCOSTABSIZE 15
+#define ICOSTABSIZE (1<<ILOGCOSTABSIZE)
+static t_sample cos_table[] = {262144,262144,262144,262144,262144,262144,262144,262144,262144,262144,262144,262143,262143,262143,262143,262143,262143,262143,262142,262142,262142,262142,262142,262141,262141,262141,262141,262140,262140,262140,262140,262139,262139,262139,262138,262138,262138,262137,262137,262137,262136,262136,262135,262135,262135,262134,262134,262133,262133,262132,262132,262131,262131,262130,262130,262129,262129,262128,262128,262127,262127,262126,262125,262125,262124,262124,262123,262122,262122,262121,262120,262120,262119,262118,262118,262117,262116,262115,262115,262114,262113,262112,262112,262111,262110,262109,262108,262108,262107,262106,262105,262104,262103,262102,262101,262101,262100,262099,262098,262097,262096,262095,262094,262093,262092,262091,262090,262089,262088,262087,262086,262085,262084,262082,262081,262080,262079,262078,262077,262076,262075,262073,262072,262071,262070,262069,262067,262066,262065,262064,262063,262061,262060,262059,262057,262056,262055,262054,262052,262051,262050,262048,262047,262045,262044,262043,262041,262040,262038,262037,262036,262034,262033,262031,262030,262028,262027,262025,262024,262022,262021,262019,262018,262016,262014,262013,262011,262010,262008,262006,262005,262003,262001,262000,261998,261996,261995,261993,261991,261990,261988,261986,261984,261983,261981,261979,261977,261975,261974,261972,261970,261968,261966,261965,261963,261961,261959,261957,261955,261953,261951,261949,261947,261945,261943,261942,261940,261938,261936,261934,261932,261929,261927,261925,261923,261921,261919,261917,261915,261913,261911,261909,261907,261904,261902,261900,261898,261896,261894,261891,261889,261887,261885,261882,261880,261878,261876,261873,261871,261869,261866,261864,261862,261859,261857,261855,261852,261850,261848,261845,261843,261840,261838,261836,261833,261831,261828,261826,261823,261821,261818,261816,261813,261811,261808,261806,261803,261801,261798,261795,261793,261790,261788,261785,261782,261780,261777,261774,261772,261769,261766,261764,261761,261758,261755,261753,261750,261747,261744,261742,261739,261736,261733,261730,261728,261725,261722,261719,261716,261713,261710,261708,261705,261702,261699,261696,261693,261690,261687,261684,261681,261678,261675,261672,261669,261666,261663,261660,261657,261654,261651,261648,261644,261641,261638,261635,261632,261629,261626,261623,261619,261616,261613,261610,261607,261603,261600,261597,261594,261590,261587,261584,261581,261577,261574,261571,261567,261564,261561,261557,261554,261551,261547,261544,261540,261537,261533,261530,261527,261523,261520,261516,261513,261509,261506,261502,261499,261495,261492,261488,261485,261481,261477,261474,261470,261467,261463,261459,261456,261452,261448,261445,261441,261437,261434,261430,261426,261423,261419,261415,261411,261408,261404,261400,261396,261392,261389,261385,261381,261377,261373,261369,261366,261362,261358,261354,261350,261346,261342,261338,261334,261330,261326,261322,261318,261314,261310,261306,261302,261298,261294,261290,261286,261282,261278,261274,261270,261266,261262,261258,261253,261249,261245,261241,261237,261233,261228,261224,261220,261216,261212,261207,261203,261199,261195,261190,261186,261182,261177,261173,261169,261164,261160,261156,261151,261147,261143,261138,261134,261129,261125,261120,261116,261112,261107,261103,261098,261094,261089,261085,261080,261076,261071,261067,261062,261057,261053,261048,261044,261039,261034,261030,261025,261021,261016,261011,261007,261002,260997,260992,260988,260983,260978,260974,260969,260964,260959,260955,260950,260945,260940,260935,260930,260926,260921,260916,260911,260906,260901,260896,260892,260887,260882,260877,260872,260867,260862,260857,260852,260847,260842,260837,260832,260827,260822,260817,260812,260807,260802,260797,260791,260786,260781,260776,260771,260766,260761,260756,260750,260745,260740,260735,260730,260724,260719,260714,260709,260703,260698,260693,260688,260682,260677,260672,260666,260661,260656,260650,260645,260640,260634,260629,260623,260618,260613,260607,260602,260596,260591,260585,260580,260574,260569,260563,260558,260552,260547,260541,260536,260530,260525,260519,260513,260508,260502,260496,260491,260485,260480,260474,260468,260463,260457,260451,260445,260440,260434,260428,260423,260417,260411,260405,260399,260394,260388,260382,260376,260370,260365,260359,260353,260347,260341,260335,260329,260323,260317,260312,260306,260300,260294,260288,260282,260276,260270,260264,260258,260252,260246,260240,260234,260228,260221,260215,260209,260203,260197,260191,260185,260179,260173,260166,260160,260154,260148,260142,260135,260129,260123,260117,260111,260104,260098,260092,260085,260079,260073,260067,260060,260054,260048,260041,260035,260029,260022,260016,260009,260003,259997,259990,259984,259977,259971,259964,259958,259951,259945,259938,259932,259925,259919,259912,259906,259899,259893,259886,259879,259873,259866,259860,259853,259846,259840,259833,259826,259820,259813,259806,259800,259793,259786,259779,259773,259766,259759,259752,259746,259739,259732,259725,259718,259712,259705,259698,259691,259684,259677,259670,259664,259657,259650,259643,259636,259629,259622,259615,259608,259601,259594,259587,259580,259573,259566,259559,259552,259545,259538,259531,259524,259517,259509,259502,259495,259488,259481,259474,259467,259459,259452,259445,259438,259431,259423,259416,259409,259402,259395,259387,259380,259373,259365,259358,259351,259343,259336,259329,259321,259314,259307,259299,259292,259285,259277,259270,259262,259255,259247,259240,259232,259225,259217,259210,259202,259195,259187,259180,259172,259165,259157,259150,259142,259135,259127,259119,259112,259104,259096,259089,259081,259073,259066,259058,259050,259043,259035,259027,259020,259012,259004,258996,258989,258981,258973,258965,258957,258950,258942,258934,258926,258918,258910,258902,258895,258887,258879,258871,258863,258855,258847,258839,258831,258823,258815,258807,258799,258791,258783,258775,258767,258759,258751,258743,258735,258727,258719,258711,258702,258694,258686,258678,258670,258662,258654,258645,258637,258629,258621,258613,258604,258596,258588,258580,258571,258563,258555,258546,258538,258530,258522,258513,258505,258496,258488,258480,258471,258463,258455,258446,258438,258429,258421,258412,258404,258396,258387,258379,258370,258362,258353,258345,258336,258327,258319,258310,258302,258293,258285,258276,258267,258259,258250,258242,258233,258224,258216,258207,258198,258190,258181,258172,258163,258155,258146,258137,258128,258120,258111,258102,258093,258084,258076,258067,258058,258049,258040,258031,258023,258014,258005,257996,257987,257978,257969,257960,257951,257942,257933,257924,257915,257906,257897,257888,257879,257870,257861,257852,257843,257834,257825,257816,257807,257798,257789,257779,257770,257761,257752,257743,257734,257724,257715,257706,257697,257688,257678,257669,257660,257651,257641,257632,257623,257613,257604,257595,257585,257576,257567,257557,257548,257539,257529,257520,257510,257501,257492,257482,257473,257463,257454,257444,257435,257425,257416,257406,257397,257387,257378,257368,257359,257349,257340,257330,257320,257311,257301,257292,257282,257272,257263,257253,257243,257234,257224,257214,257205,257195,257185,257175,257166,257156,257146,257136,257127,257117,257107,257097,257087,257078,257068,257058,257048,257038,257028,257018,257008,256999,256989,256979,256969,256959,256949,256939,256929,256919,256909,256899,256889,256879,256869,256859,256849,256839,256829,256819,256809,256798,256788,256778,256768,256758,256748,256738,256728,256717,256707,256697,256687,256677,256666,256656,256646,256636,256625,256615,256605,256595,256584,256574,256564,256553,256543,256533,256522,256512,256502,256491,256481,256470,256460,256450,256439,256429,256418,256408,256397,256387,256376,256366,256355,256345,256334,256324,256313,256303,256292,256282,256271,256261,256250,256239,256229,256218,256207,256197,256186,256176,256165,256154,256143,256133,256122,256111,256101,256090,256079,256068,256058,256047,256036,256025,256014,256004,255993,255982,255971,255960,255949,255939,255928,255917,255906,255895,255884,255873,255862,255851,255840,255829,255818,255807,255796,255785,255774,255763,255752,255741,255730,255719,255708,255697,255686,255675,255664,255653,255642,255630,255619,255608,255597,255586,255575,255564,255552,255541,255530,255519,255507,255496,255485,255474,255462,255451,255440,255429,255417,255406,255395,255383,255372,255361,255349,255338,255326,255315,255304,255292,255281,255269,255258,255246,255235,255224,255212,255201,255189,255178,255166,255155,255143,255131,255120,255108,255097,255085,255074,255062,255050,255039,255027,255015,255004,254992,254981,254969,254957,254945,254934,254922,254910,254899,254887,254875,254863,254852,254840,254828,254816,254804,254793,254781,254769,254757,254745,254733,254721,254710,254698,254686,254674,254662,254650,254638,254626,254614,254602,254590,254578,254566,254554,254542,254530,254518,254506,254494,254482,254470,254458,254446,254434,254422,254410,254397,254385,254373,254361,254349,254337,254324,254312,254300,254288,254276,254263,254251,254239,254227,254214,254202,254190,254178,254165,254153,254141,254128,254116,254104,254091,254079,254067,254054,254042,254029,254017,254004,253992,253980,253967,253955,253942,253930,253917,253905,253892,253880,253867,253855,253842,253830,253817,253804,253792,253779,253767,253754,253741,253729,253716,253704,253691,253678,253666,253653,253640,253627,253615,253602,253589,253577,253564,253551,253538,253525,253513,253500,253487,253474,253461,253449,253436,253423,253410,253397,253384,253371,253359,253346,253333,253320,253307,253294,253281,253268,253255,253242,253229,253216,253203,253190,253177,253164,253151,253138,253125,253112,253099,253085,253072,253059,253046,253033,253020,253007,252994,252980,252967,252954,252941,252928,252914,252901,252888,252875,252861,252848,252835,252822,252808,252795,252782,252768,252755,252742,252728,252715,252702,252688,252675,252662,252648,252635,252621,252608,252594,252581,252568,252554,252541,252527,252514,252500,252487,252473,252460,252446,252432,252419,252405,252392,252378,252365,252351,252337,252324,252310,252296,252283,252269,252255,252242,252228,252214,252201,252187,252173,252159,252146,252132,252118,252104,252091,252077,252063,252049,252035,252022,252008,251994,251980,251966,251952,251938,251925,251911,251897,251883,251869,251855,251841,251827,251813,251799,251785,251771,251757,251743,251729,251715,251701,251687,251673,251659,251645,251631,251617,251602,251588,251574,251560,251546,251532,251518,251503,251489,251475,251461,251447,251432,251418,251404,251390,251375,251361,251347,251333,251318,251304,251290,251275,251261,251247,251232,251218,251204,251189,251175,251161,251146,251132,251117,251103,251088,251074,251060,251045,251031,251016,251002,250987,250973,250958,250944,250929,250914,250900,250885,250871,250856,250842,250827,250812,250798,250783,250768,250754,250739,250724,250710,250695,250680,250666,250651,250636,250622,250607,250592,250577,250562,250548,250533,250518,250503,250489,250474,250459,250444,250429,250414,250399,250385,250370,250355,250340,250325,250310,250295,250280,250265,250250,250235,250220,250205,250190,250175,250160,250145,250130,250115,250100,250085,250070,250055,250040,250025,250009,249994,249979,249964,249949,249934,249919,249903,249888,249873,249858,249843,249827,249812,249797,249782,249766,249751,249736,249721,249705,249690,249675,249659,249644,249629,249613,249598,249583,249567,249552,249536,249521,249506,249490,249475,249459,249444,249428,249413,249398,249382,249367,249351,249335,249320,249304,249289,249273,249258,249242,249227,249211,249195,249180,249164,249149,249133,249117,249102,249086,249070,249055,249039,249023,249008,248992,248976,248960,248945,248929,248913,248897,248882,248866,248850,248834,248818,248803,248787,248771,248755,248739,248723,248707,248691,248676,248660,248644,248628,248612,248596,248580,248564,248548,248532,248516,248500,248484,248468,248452,248436,248420,248404,248388,248372,248356,248340,248323,248307,248291,248275,248259,248243,248227,248211,248194,248178,248162,248146,248130,248113,248097,248081,248065,248048,248032,248016,248000,247983,247967,247951,247934,247918,247902,247885,247869,247853,247836,247820,247803,247787,247771,247754,247738,247721,247705,247688,247672,247655,247639,247622,247606,247589,247573,247556,247540,247523,247507,247490,247474,247457,247440,247424,247407,247391,247374,247357,247341,247324,247307,247291,247274,247257,247241,247224,247207,247190,247174,247157,247140,247123,247107,247090,247073,247056,247040,247023,247006,246989,246972,246955,246938,246922,246905,246888,246871,246854,246837,246820,246803,246786,246769,246752,246735,246718,246701,246684,246667,246650,246633,246616,246599,246582,246565,246548,246531,246514,246497,246480,246463,246445,246428,246411,246394,246377,246360,246342,246325,246308,246291,246274,246256,246239,246222,246205,246187,246170,246153,246136,246118,246101,246084,246066,246049,246032,246014,245997,245979,245962,245945,245927,245910,245892,245875,245858,245840,245823,245805,245788,245770,245753,245735,245718,245700,245683,245665,245648,245630,245613,245595,245577,245560,245542,245525,245507,245489,245472,245454,245436,245419,245401,245383,245366,245348,245330,245313,245295,245277,245259,245242,245224,245206,245188,245171,245153,245135,245117,245099,245081,245064,245046,245028,245010,244992,244974,244956,244938,244921,244903,244885,244867,244849,244831,244813,244795,244777,244759,244741,244723,244705,244687,244669,244651,244633,244615,244597,244578,244560,244542,244524,244506,244488,244470,244452,244433,244415,244397,244379,244361,244343,244324,244306,244288,244270,244251,244233,244215,244197,244178,244160,244142,244123,244105,244087,244068,244050,244032,244013,243995,243977,243958,243940,243921,243903,243885,243866,243848,243829,243811,243792,243774,243755,243737,243718,243700,243681,243663,243644,243626,243607,243588,243570,243551,243533,243514,243496,243477,243458,243440,243421,243402,243384,243365,243346,243328,243309,243290,243271,243253,243234,243215,243196,243178,243159,243140,243121,243103,243084,243065,243046,243027,243008,242990,242971,242952,242933,242914,242895,242876,242857,242838,242819,242800,242782,242763,242744,242725,242706,242687,242668,242649,242630,242611,242591,242572,242553,242534,242515,242496,242477,242458,242439,242420,242401,242381,242362,242343,242324,242305,242286,242266,242247,242228,242209,242189,242170,242151,242132,242112,242093,242074,242055,242035,242016,241997,241977,241958,241939,241919,241900,241881,241861,241842,241822,241803,241784,241764,241745,241725,241706,241686,241667,241647,241628,241608,241589,241569,241550,241530,241511,241491,241472,241452,241433,241413,241393,241374,241354,241334,241315,241295,241276,241256,241236,241217,241197,241177,241157,241138,241118,241098,241079,241059,241039,241019,241000,240980,240960,240940,240920,240901,240881,240861,240841,240821,240801,240781,240762,240742,240722,240702,240682,240662,240642,240622,240602,240582,240562,240542,240522,240502,240482,240462,240442,240422,240402,240382,240362,240342,240322,240302,240282,240262,240242,240221,240201,240181,240161,240141,240121,240101,240080,240060,240040,240020,240000,239979,239959,239939,239919,239898,239878,239858,239838,239817,239797,239777,239756,239736,239716,239695,239675,239655,239634,239614,239593,239573,239553,239532,239512,239491,239471,239450,239430,239410,239389,239369,239348,239328,239307,239287,239266,239245,239225,239204,239184,239163,239143,239122,239101,239081,239060,239040,239019,238998,238978,238957,238936,238916,238895,238874,238853,238833,238812,238791,238771,238750,238729,238708,238688,238667,238646,238625,238604,238583,238563,238542,238521,238500,238479,238458,238437,238417,238396,238375,238354,238333,238312,238291,238270,238249,238228,238207,238186,238165,238144,238123,238102,238081,238060,238039,238018,237997,237976,237955,237934,237913,237891,237870,237849,237828,237807,237786,237765,237743,237722,237701,237680,237659,237637,237616,237595,237574,237552,237531,237510,237489,237467,237446,237425,237403,237382,237361,237339,237318,237297,237275,237254,237233,237211,237190,237168,237147,237126,237104,237083,237061,237040,237018,236997,236975,236954,236932,236911,236889,236868,236846,236825,236803,236782,236760,236738,236717,236695,236674,236652,236630,236609,236587,236565,236544,236522,236500,236479,236457,236435,236414,236392,236370,236348,236327,236305,236283,236261,236240,236218,236196,236174,236152,236131,236109,236087,236065,236043,236021,235999,235978,235956,235934,235912,235890,235868,235846,235824,235802,235780,235758,235736,235714,235692,235670,235648,235626,235604,235582,235560,235538,235516,235494,235472,235450,235428,235405,235383,235361,235339,235317,235295,235273,235250,235228,235206,235184,235162,235139,235117,235095,235073,235050,235028,235006,234984,234961,234939,234917,234894,234872,234850,234828,234805,234783,234760,234738,234716,234693,234671,234649,234626,234604,234581,234559,234536,234514,234491,234469,234446,234424,234401,234379,234356,234334,234311,234289,234266,234244,234221,234199,234176,234153,234131,234108,234086,234063,234040,234018,233995,233972,233950,233927,233904,233882,233859,233836,233813,233791,233768,233745,233722,233700,233677,233654,233631,233609,233586,233563,233540,233517,233494,233472,233449,233426,233403,233380,233357,233334,233311,233288,233265,233243,233220,233197,233174,233151,233128,233105,233082,233059,233036,233013,232990,232967,232944,232920,232897,232874,232851,232828,232805,232782,232759,232736,232713,232689,232666,232643,232620,232597,232574,232550,232527,232504,232481,232457,232434,232411,232388,232364,232341,232318,232295,232271,232248,232225,232201,232178,232155,232131,232108,232085,232061,232038,232014,231991,231968,231944,231921,231897,231874,231850,231827,231804,231780,231757,231733,231710,231686,231663,231639,231615,231592,231568,231545,231521,231498,231474,231450,231427,231403,231380,231356,231332,231309,231285,231261,231238,231214,231190,231167,231143,231119,231096,231072,231048,231024,231001,230977,230953,230929,230905,230882,230858,230834,230810,230786,230762,230739,230715,230691,230667,230643,230619,230595,230571,230548,230524,230500,230476,230452,230428,230404,230380,230356,230332,230308,230284,230260,230236,230212,230188,230164,230140,230116,230091,230067,230043,230019,229995,229971,229947,229923,229898,229874,229850,229826,229802,229778,229753,229729,229705,229681,229657,229632,229608,229584,229560,229535,229511,229487,229462,229438,229414,229389,229365,229341,229316,229292,229268,229243,229219,229194,229170,229146,229121,229097,229072,229048,229024,228999,228975,228950,228926,228901,228877,228852,228828,228803,228779,228754,228729,228705,228680,228656,228631,228607,228582,228557,228533,228508,228483,228459,228434,228409,228385,228360,228335,228311,228286,228261,228237,228212,228187,228162,228138,228113,228088,228063,228039,228014,227989,227964,227939,227914,227890,227865,227840,227815,227790,227765,227740,227716,227691,227666,227641,227616,227591,227566,227541,227516,227491,227466,227441,227416,227391,227366,227341,227316,227291,227266,227241,227216,227191,227166,227141,227115,227090,227065,227040,227015,226990,226965,226940,226914,226889,226864,226839,226814,226788,226763,226738,226713,226688,226662,226637,226612,226586,226561,226536,226511,226485,226460,226435,226409,226384,226359,226333,226308,226283,226257,226232,226206,226181,226156,226130,226105,226079,226054,226028,226003,225977,225952,225926,225901,225875,225850,225824,225799,225773,225748,225722,225697,225671,225646,225620,225594,225569,225543,225517,225492,225466,225441,225415,225389,225364,225338,225312,225287,225261,225235,225209,225184,225158,225132,225106,225081,225055,225029,225003,224978,224952,224926,224900,224874,224848,224823,224797,224771,224745,224719,224693,224667,224641,224615,224590,224564,224538,224512,224486,224460,224434,224408,224382,224356,224330,224304,224278,224252,224226,224200,224174,224148,224122,224096,224069,224043,224017,223991,223965,223939,223913,223887,223860,223834,223808,223782,223756,223730,223703,223677,223651,223625,223599,223572,223546,223520,223493,223467,223441,223415,223388,223362,223336,223309,223283,223257,223230,223204,223178,223151,223125,223099,223072,223046,223019,222993,222966,222940,222914,222887,222861,222834,222808,222781,222755,222728,222702,222675,222649,222622,222596,222569,222542,222516,222489,222463,222436,222410,222383,222356,222330,222303,222276,222250,222223,222196,222170,222143,222116,222090,222063,222036,222010,221983,221956,221929,221903,221876,221849,221822,221795,221769,221742,221715,221688,221661,221634,221608,221581,221554,221527,221500,221473,221446,221419,221393,221366,221339,221312,221285,221258,221231,221204,221177,221150,221123,221096,221069,221042,221015,220988,220961,220934,220907,220880,220853,220826,220798,220771,220744,220717,220690,220663,220636,220609,220581,220554,220527,220500,220473,220446,220418,220391,220364,220337,220309,220282,220255,220228,220200,220173,220146,220119,220091,220064,220037,220009,219982,219955,219927,219900,219873,219845,219818,219790,219763,219736,219708,219681,219653,219626,219598,219571,219544,219516,219489,219461,219434,219406,219379,219351,219324,219296,219268,219241,219213,219186,219158,219131,219103,219075,219048,219020,218993,218965,218937,218910,218882,218854,218827,218799,218771,218744,218716,218688,218660,218633,218605,218577,218549,218522,218494,218466,218438,218411,218383,218355,218327,218299,218271,218244,218216,218188,218160,218132,218104,218076,218049,218021,217993,217965,217937,217909,217881,217853,217825,217797,217769,217741,217713,217685,217657,217629,217601,217573,217545,217517,217489,217461,217433,217405,217377,217348,217320,217292,217264,217236,217208,217180,217152,217123,217095,217067,217039,217011,216982,216954,216926,216898,216870,216841,216813,216785,216757,216728,216700,216672,216643,216615,216587,216558,216530,216502,216473,216445,216417,216388,216360,216332,216303,216275,216246,216218,216190,216161,216133,216104,216076,216047,216019,215990,215962,215933,215905,215876,215848,215819,215791,215762,215734,215705,215677,215648,215619,215591,215562,215534,215505,215476,215448,215419,215390,215362,215333,215304,215276,215247,215218,215190,215161,215132,215104,215075,215046,215017,214989,214960,214931,214902,214873,214845,214816,214787,214758,214729,214701,214672,214643,214614,214585,214556,214527,214498,214470,214441,214412,214383,214354,214325,214296,214267,214238,214209,214180,214151,214122,214093,214064,214035,214006,213977,213948,213919,213890,213861,213832,213803,213774,213745,213715,213686,213657,213628,213599,213570,213541,213511,213482,213453,213424,213395,213366,213336,213307,213278,213249,213219,213190,213161,213132,213102,213073,213044,213015,212985,212956,212927,212897,212868,212839,212809,212780,212751,212721,212692,212662,212633,212604,212574,212545,212515,212486,212456,212427,212398,212368,212339,212309,212280,212250,212221,212191,212162,212132,212103,212073,212043,212014,211984,211955,211925,211896,211866,211836,211807,211777,211748,211718,211688,211659,211629,211599,211570,211540,211510,211481,211451,211421,211391,211362,211332,211302,211272,211243,211213,211183,211153,211124,211094,211064,211034,211004,210974,210945,210915,210885,210855,210825,210795,210765,210736,210706,210676,210646,210616,210586,210556,210526,210496,210466,210436,210406,210376,210346,210316,210286,210256,210226,210196,210166,210136,210106,210076,210046,210016,209986,209956,209926,209895,209865,209835,209805,209775,209745,209715,209684,209654,209624,209594,209564,209534,209503,209473,209443,209413,209382,209352,209322,209292,209261,209231,209201,209170,209140,209110,209080,209049,209019,208989,208958,208928,208897,208867,208837,208806,208776,208746,208715,208685,208654,208624,208593,208563,208533,208502,208472,208441,208411,208380,208350,208319,208289,208258,208228,208197,208166,208136,208105,208075,208044,208014,207983,207952,207922,207891,207861,207830,207799,207769,207738,207707,207677,207646,207615,207585,207554,207523,207492,207462,207431,207400,207370,207339,207308,207277,207246,207216,207185,207154,207123,207092,207062,207031,207000,206969,206938,206907,206877,206846,206815,206784,206753,206722,206691,206660,206629,206598,206567,206537,206506,206475,206444,206413,206382,206351,206320,206289,206258,206227,206196,206165,206133,206102,206071,206040,206009,205978,205947,205916,205885,205854,205823,205791,205760,205729,205698,205667,205636,205604,205573,205542,205511,205480,205448,205417,205386,205355,205324,205292,205261,205230,205198,205167,205136,205105,205073,205042,205011,204979,204948,204917,204885,204854,204823,204791,204760,204728,204697,204666,204634,204603,204571,204540,204508,204477,204446,204414,204383,204351,204320,204288,204257,204225,204194,204162,204131,204099,204067,204036,204004,203973,203941,203910,203878,203846,203815,203783,203752,203720,203688,203657,203625,203593,203562,203530,203498,203467,203435,203403,203372,203340,203308,203276,203245,203213,203181,203149,203118,203086,203054,203022,202990,202959,202927,202895,202863,202831,202799,202768,202736,202704,202672,202640,202608,202576,202544,202512,202481,202449,202417,202385,202353,202321,202289,202257,202225,202193,202161,202129,202097,202065,202033,202001,201969,201937,201905,201873,201841,201808,201776,201744,201712,201680,201648,201616,201584,201552,201519,201487,201455,201423,201391,201359,201326,201294,201262,201230,201198,201165,201133,201101,201069,201036,201004,200972,200940,200907,200875,200843,200810,200778,200746,200713,200681,200649,200616,200584,200552,200519,200487,200454,200422,200390,200357,200325,200292,200260,200228,200195,200163,200130,200098,200065,200033,200000,199968,199935,199903,199870,199838,199805,199773,199740,199708,199675,199642,199610,199577,199545,199512,199479,199447,199414,199382,199349,199316,199284,199251,199218,199186,199153,199120,199088,199055,199022,198989,198957,198924,198891,198858,198826,198793,198760,198727,198695,198662,198629,198596,198563,198531,198498,198465,198432,198399,198366,198334,198301,198268,198235,198202,198169,198136,198103,198070,198037,198004,197972,197939,197906,197873,197840,197807,197774,197741,197708,197675,197642,197609,197576,197543,197510,197476,197443,197410,197377,197344,197311,197278,197245,197212,197179,197146,197112,197079,197046,197013,196980,196947,196913,196880,196847,196814,196781,196747,196714,196681,196648,196615,196581,196548,196515,196481,196448,196415,196382,196348,196315,196282,196248,196215,196182,196148,196115,196082,196048,196015,195982,195948,195915,195881,195848,195815,195781,195748,195714,195681,195647,195614,195580,195547,195513,195480,195446,195413,195379,195346,195312,195279,195245,195212,195178,195145,195111,195078,195044,195010,194977,194943,194910,194876,194842,194809,194775,194741,194708,194674,194640,194607,194573,194539,194506,194472,194438,194405,194371,194337,194303,194270,194236,194202,194168,194135,194101,194067,194033,193999,193966,193932,193898,193864,193830,193796,193763,193729,193695,193661,193627,193593,193559,193525,193492,193458,193424,193390,193356,193322,193288,193254,193220,193186,193152,193118,193084,193050,193016,192982,192948,192914,192880,192846,192812,192778,192744,192710,192676,192641,192607,192573,192539,192505,192471,192437,192403,192369,192334,192300,192266,192232,192198,192164,192129,192095,192061,192027,191992,191958,191924,191890,191856,191821,191787,191753,191718,191684,191650,191616,191581,191547,191513,191478,191444,191410,191375,191341,191307,191272,191238,191203,191169,191135,191100,191066,191031,190997,190963,190928,190894,190859,190825,190790,190756,190721,190687,190652,190618,190583,190549,190514,190480,190445,190411,190376,190342,190307,190272,190238,190203,190169,190134,190099,190065,190030,189996,189961,189926,189892,189857,189822,189788,189753,189718,189684,189649,189614,189580,189545,189510,189475,189441,189406,189371,189336,189302,189267,189232,189197,189162,189128,189093,189058,189023,188988,188954,188919,188884,188849,188814,188779,188744,188709,188675,188640,188605,188570,188535,188500,188465,188430,188395,188360,188325,188290,188255,188220,188185,188150,188115,188080,188045,188010,187975,187940,187905,187870,187835,187800,187765,187730,187695,187660,187625,187589,187554,187519,187484,187449,187414,187379,187343,187308,187273,187238,187203,187168,187132,187097,187062,187027,186992,186956,186921,186886,186851,186815,186780,186745,186710,186674,186639,186604,186568,186533,186498,186462,186427,186392,186356,186321,186286,186250,186215,186179,186144,186109,186073,186038,186002,185967,185932,185896,185861,185825,185790,185754,185719,185683,185648,185612,185577,185541,185506,185470,185435,185399,185364,185328,185293,185257,185222,185186,185150,185115,185079,185044,185008,184972,184937,184901,184866,184830,184794,184759,184723,184687,184652,184616,184580,184545,184509,184473,184437,184402,184366,184330,184294,184259,184223,184187,184151,184116,184080,184044,184008,183972,183937,183901,183865,183829,183793,183757,183722,183686,183650,183614,183578,183542,183506,183470,183435,183399,183363,183327,183291,183255,183219,183183,183147,183111,183075,183039,183003,182967,182931,182895,182859,182823,182787,182751,182715,182679,182643,182607,182571,182535,182499,182463,182426,182390,182354,182318,182282,182246,182210,182174,182137,182101,182065,182029,181993,181957,181920,181884,181848,181812,181776,181739,181703,181667,181631,181594,181558,181522,181486,181449,181413,181377,181341,181304,181268,181232,181195,181159,181123,181086,181050,181014,180977,180941,180904,180868,180832,180795,180759,180723,180686,180650,180613,180577,180540,180504,180467,180431,180395,180358,180322,180285,180249,180212,180176,180139,180103,180066,180029,179993,179956,179920,179883,179847,179810,179774,179737,179700,179664,179627,179591,179554,179517,179481,179444,179407,179371,179334,179297,179261,179224,179187,179151,179114,179077,179041,179004,178967,178930,178894,178857,178820,178783,178747,178710,178673,178636,178600,178563,178526,178489,178452,178415,178379,178342,178305,178268,178231,178194,178158,178121,178084,178047,178010,177973,177936,177899,177862,177825,177788,177752,177715,177678,177641,177604,177567,177530,177493,177456,177419,177382,177345,177308,177271,177234,177197,177160,177123,177085,177048,177011,176974,176937,176900,176863,176826,176789,176752,176714,176677,176640,176603,176566,176529,176492,176454,176417,176380,176343,176306,176268,176231,176194,176157,176120,176082,176045,176008,175971,175933,175896,175859,175822,175784,175747,175710,175672,175635,175598,175560,175523,175486,175448,175411,175374,175336,175299,175262,175224,175187,175149,175112,175075,175037,175000,174962,174925,174887,174850,174813,174775,174738,174700,174663,174625,174588,174550,174513,174475,174438,174400,174363,174325,174288,174250,174212,174175,174137,174100,174062,174025,173987,173949,173912,173874,173837,173799,173761,173724,173686,173648,173611,173573,173535,173498,173460,173422,173385,173347,173309,173271,173234,173196,173158,173121,173083,173045,173007,172969,172932,172894,172856,172818,172781,172743,172705,172667,172629,172591,172554,172516,172478,172440,172402,172364,172326,172289,172251,172213,172175,172137,172099,172061,172023,171985,171947,171909,171871,171834,171796,171758,171720,171682,171644,171606,171568,171530,171492,171454,171416,171378,171339,171301,171263,171225,171187,171149,171111,171073,171035,170997,170959,170921,170883,170844,170806,170768,170730,170692,170654,170616,170577,170539,170501,170463,170425,170386,170348,170310,170272,170234,170195,170157,170119,170081,170042,170004,169966,169928,169889,169851,169813,169774,169736,169698,169660,169621,169583,169545,169506,169468,169430,169391,169353,169314,169276,169238,169199,169161,169122,169084,169046,169007,168969,168930,168892,168853,168815,168777,168738,168700,168661,168623,168584,168546,168507,168469,168430,168392,168353,168315,168276,168238,168199,168160,168122,168083,168045,168006,167968,167929,167890,167852,167813,167774,167736,167697,167659,167620,167581,167543,167504,167465,167427,167388,167349,167311,167272,167233,167194,167156,167117,167078,167040,167001,166962,166923,166885,166846,166807,166768,166729,166691,166652,166613,166574,166535,166497,166458,166419,166380,166341,166302,166264,166225,166186,166147,166108,166069,166030,165991,165952,165914,165875,165836,165797,165758,165719,165680,165641,165602,165563,165524,165485,165446,165407,165368,165329,165290,165251,165212,165173,165134,165095,165056,165017,164978,164939,164900,164861,164821,164782,164743,164704,164665,164626,164587,164548,164509,164469,164430,164391,164352,164313,164274,164234,164195,164156,164117,164078,164039,163999,163960,163921,163882,163842,163803,163764,163725,163685,163646,163607,163568,163528,163489,163450,163410,163371,163332,163292,163253,163214,163174,163135,163096,163056,163017,162978,162938,162899,162860,162820,162781,162741,162702,162663,162623,162584,162544,162505,162465,162426,162386,162347,162308,162268,162229,162189,162150,162110,162071,162031,161992,161952,161913,161873,161833,161794,161754,161715,161675,161636,161596,161557,161517,161477,161438,161398,161359,161319,161279,161240,161200,161160,161121,161081,161041,161002,160962,160922,160883,160843,160803,160764,160724,160684,160644,160605,160565,160525,160486,160446,160406,160366,160327,160287,160247,160207,160167,160128,160088,160048,160008,159968,159929,159889,159849,159809,159769,159729,159689,159650,159610,159570,159530,159490,159450,159410,159370,159330,159291,159251,159211,159171,159131,159091,159051,159011,158971,158931,158891,158851,158811,158771,158731,158691,158651,158611,158571,158531,158491,158451,158411,158371,158331,158291,158251,158211,158170,158130,158090,158050,158010,157970,157930,157890,157850,157809,157769,157729,157689,157649,157609,157569,157528,157488,157448,157408,157368,157327,157287,157247,157207,157167,157126,157086,157046,157006,156965,156925,156885,156845,156804,156764,156724,156683,156643,156603,156562,156522,156482,156441,156401,156361,156320,156280,156240,156199,156159,156119,156078,156038,155997,155957,155917,155876,155836,155795,155755,155715,155674,155634,155593,155553,155512,155472,155431,155391,155350,155310,155269,155229,155188,155148,155107,155067,155026,154986,154945,154905,154864,154824,154783,154742,154702,154661,154621,154580,154539,154499,154458,154418,154377,154336,154296,154255,154214,154174,154133,154093,154052,154011,153970,153930,153889,153848,153808,153767,153726,153686,153645,153604,153563,153523,153482,153441,153400,153360,153319,153278,153237,153197,153156,153115,153074,153033,152993,152952,152911,152870,152829,152788,152748,152707,152666,152625,152584,152543,152502,152461,152421,152380,152339,152298,152257,152216,152175,152134,152093,152052,152011,151970,151929,151888,151847,151806,151765,151724,151683,151642,151601,151560,151519,151478,151437,151396,151355,151314,151273,151232,151191,151150,151109,151068,151027,150986,150945,150904,150862,150821,150780,150739,150698,150657,150616,150575,150533,150492,150451,150410,150369,150328,150286,150245,150204,150163,150122,150080,150039,149998,149957,149916,149874,149833,149792,149751,149709,149668,149627,149585,149544,149503,149462,149420,149379,149338,149296,149255,149214,149172,149131,149090,149048,149007,148966,148924,148883,148842,148800,148759,148717,148676,148635,148593,148552,148510,148469,148428,148386,148345,148303,148262,148220,148179,148137,148096,148054,148013,147971,147930,147888,147847,147805,147764,147722,147681,147639,147598,147556,147515,147473,147432,147390,147348,147307,147265,147224,147182,147141,147099,147057,147016,146974,146932,146891,146849,146808,146766,146724,146683,146641,146599,146558,146516,146474,146433,146391,146349,146307,146266,146224,146182,146141,146099,146057,146015,145974,145932,145890,145848,145807,145765,145723,145681,145639,145598,145556,145514,145472,145430,145389,145347,145305,145263,145221,145179,145137,145096,145054,145012,144970,144928,144886,144844,144802,144761,144719,144677,144635,144593,144551,144509,144467,144425,144383,144341,144299,144257,144215,144173,144131,144089,144047,144005,143963,143921,143879,143837,143795,143753,143711,143669,143627,143585,143543,143501,143459,143417,143375,143333,143291,143248,143206,143164,143122,143080,143038,142996,142954,142912,142869,142827,142785,142743,142701,142659,142616,142574,142532,142490,142448,142405,142363,142321,142279,142237,142194,142152,142110,142068,142025,141983,141941,141899,141856,141814,141772,141730,141687,141645,141603,141560,141518,141476,141433,141391,141349,141306,141264,141222,141179,141137,141095,141052,141010,140968,140925,140883,140840,140798,140756,140713,140671,140628,140586,140544,140501,140459,140416,140374,140331,140289,140246,140204,140161,140119,140077,140034,139992,139949,139907,139864,139821,139779,139736,139694,139651,139609,139566,139524,139481,139439,139396,139353,139311,139268,139226,139183,139141,139098,139055,139013,138970,138927,138885,138842,138800,138757,138714,138672,138629,138586,138544,138501,138458,138416,138373,138330,138288,138245,138202,138159,138117,138074,138031,137988,137946,137903,137860,137817,137775,137732,137689,137646,137604,137561,137518,137475,137432,137390,137347,137304,137261,137218,137176,137133,137090,137047,137004,136961,136918,136876,136833,136790,136747,136704,136661,136618,136575,136532,136490,136447,136404,136361,136318,136275,136232,136189,136146,136103,136060,136017,135974,135931,135888,135845,135802,135759,135716,135673,135630,135587,135544,135501,135458,135415,135372,135329,135286,135243,135200,135157,135114,135071,135028,134984,134941,134898,134855,134812,134769,134726,134683,134640,134596,134553,134510,134467,134424,134381,134338,134294,134251,134208,134165,134122,134078,134035,133992,133949,133906,133862,133819,133776,133733,133690,133646,133603,133560,133517,133473,133430,133387,133343,133300,133257,133214,133170,133127,133084,133040,132997,132954,132910,132867,132824,132780,132737,132694,132650,132607,132564,132520,132477,132434,132390,132347,132303,132260,132217,132173,132130,132086,132043,132000,131956,131913,131869,131826,131782,131739,131695,131652,131609,131565,131522,131478,131435,131391,131348,131304,131261,131217,131174,131130,131087,131043,130999,130956,130912,130869,130825,130782,130738,130695,130651,130607,130564,130520,130477,130433,130389,130346,130302,130259,130215,130171,130128,130084,130040,129997,129953,129909,129866,129822,129778,129735,129691,129647,129604,129560,129516,129473,129429,129385,129341,129298,129254,129210,129167,129123,129079,129035,128992,128948,128904,128860,128816,128773,128729,128685,128641,128598,128554,128510,128466,128422,128378,128335,128291,128247,128203,128159,128115,128072,128028,127984,127940,127896,127852,127808,127764,127721,127677,127633,127589,127545,127501,127457,127413,127369,127325,127281,127237,127193,127150,127106,127062,127018,126974,126930,126886,126842,126798,126754,126710,126666,126622,126578,126534,126490,126446,126402,126358,126314,126269,126225,126181,126137,126093,126049,126005,125961,125917,125873,125829,125785,125741,125696,125652,125608,125564,125520,125476,125432,125388,125343,125299,125255,125211,125167,125123,125078,125034,124990,124946,124902,124857,124813,124769,124725,124681,124636,124592,124548,124504,124460,124415,124371,124327,124283,124238,124194,124150,124105,124061,124017,123973,123928,123884,123840,123795,123751,123707,123662,123618,123574,123529,123485,123441,123396,123352,123308,123263,123219,123175,123130,123086,123042,122997,122953,122908,122864,122820,122775,122731,122686,122642,122597,122553,122509,122464,122420,122375,122331,122286,122242,122197,122153,122108,122064,122019,121975,121931,121886,121842,121797,121752,121708,121663,121619,121574,121530,121485,121441,121396,121352,121307,121263,121218,121173,121129,121084,121040,120995,120950,120906,120861,120817,120772,120727,120683,120638,120594,120549,120504,120460,120415,120370,120326,120281,120236,120192,120147,120102,120058,120013,119968,119924,119879,119834,119790,119745,119700,119655,119611,119566,119521,119476,119432,119387,119342,119297,119253,119208,119163,119118,119074,119029,118984,118939,118894,118850,118805,118760,118715,118670,118626,118581,118536,118491,118446,118401,118357,118312,118267,118222,118177,118132,118087,118042,117998,117953,117908,117863,117818,117773,117728,117683,117638,117593,117549,117504,117459,117414,117369,117324,117279,117234,117189,117144,117099,117054,117009,116964,116919,116874,116829,116784,116739,116694,116649,116604,116559,116514,116469,116424,116379,116334,116289,116244,116199,116154,116109,116064,116018,115973,115928,115883,115838,115793,115748,115703,115658,115613,115567,115522,115477,115432,115387,115342,115297,115252,115206,115161,115116,115071,115026,114981,114935,114890,114845,114800,114755,114710,114664,114619,114574,114529,114483,114438,114393,114348,114303,114257,114212,114167,114122,114076,114031,113986,113941,113895,113850,113805,113759,113714,113669,113624,113578,113533,113488,113442,113397,113352,113306,113261,113216,113170,113125,113080,113034,112989,112944,112898,112853,112808,112762,112717,112671,112626,112581,112535,112490,112444,112399,112354,112308,112263,112217,112172,112126,112081,112036,111990,111945,111899,111854,111808,111763,111717,111672,111626,111581,111535,111490,111444,111399,111353,111308,111262,111217,111171,111126,111080,111035,110989,110944,110898,110853,110807,110762,110716,110670,110625,110579,110534,110488,110443,110397,110351,110306,110260,110215,110169,110123,110078,110032,109986,109941,109895,109850,109804,109758,109713,109667,109621,109576,109530,109484,109439,109393,109347,109302,109256,109210,109165,109119,109073,109027,108982,108936,108890,108845,108799,108753,108707,108662,108616,108570,108524,108479,108433,108387,108341,108295,108250,108204,108158,108112,108067,108021,107975,107929,107883,107838,107792,107746,107700,107654,107608,107563,107517,107471,107425,107379,107333,107287,107242,107196,107150,107104,107058,107012,106966,106920,106875,106829,106783,106737,106691,106645,106599,106553,106507,106461,106415,106369,106323,106278,106232,106186,106140,106094,106048,106002,105956,105910,105864,105818,105772,105726,105680,105634,105588,105542,105496,105450,105404,105358,105312,105266,105220,105174,105128,105082,105035,104989,104943,104897,104851,104805,104759,104713,104667,104621,104575,104529,104483,104436,104390,104344,104298,104252,104206,104160,104114,104067,104021,103975,103929,103883,103837,103791,103744,103698,103652,103606,103560,103514,103467,103421,103375,103329,103283,103236,103190,103144,103098,103052,103005,102959,102913,102867,102820,102774,102728,102682,102635,102589,102543,102497,102450,102404,102358,102312,102265,102219,102173,102126,102080,102034,101988,101941,101895,101849,101802,101756,101710,101663,101617,101571,101524,101478,101432,101385,101339,101293,101246,101200,101153,101107,101061,101014,100968,100922,100875,100829,100782,100736,100690,100643,100597,100550,100504,100457,100411,100365,100318,100272,100225,100179,100132,100086,100039,99993,99947,99900,99854,99807,99761,99714,99668,99621,99575,99528,99482,99435,99389,99342,99296,99249,99203,99156,99110,99063,99016,98970,98923,98877,98830,98784,98737,98691,98644,98597,98551,98504,98458,98411,98364,98318,98271,98225,98178,98131,98085,98038,97992,97945,97898,97852,97805,97758,97712,97665,97619,97572,97525,97479,97432,97385,97339,97292,97245,97199,97152,97105,97058,97012,96965,96918,96872,96825,96778,96732,96685,96638,96591,96545,96498,96451,96404,96358,96311,96264,96217,96171,96124,96077,96030,95984,95937,95890,95843,95796,95750,95703,95656,95609,95562,95516,95469,95422,95375,95328,95282,95235,95188,95141,95094,95047,95001,94954,94907,94860,94813,94766,94719,94673,94626,94579,94532,94485,94438,94391,94344,94297,94251,94204,94157,94110,94063,94016,93969,93922,93875,93828,93781,93734,93687,93640,93594,93547,93500,93453,93406,93359,93312,93265,93218,93171,93124,93077,93030,92983,92936,92889,92842,92795,92748,92701,92654,92607,92560,92513,92466,92419,92372,92325,92278,92230,92183,92136,92089,92042,91995,91948,91901,91854,91807,91760,91713,91666,91619,91571,91524,91477,91430,91383,91336,91289,91242,91195,91147,91100,91053,91006,90959,90912,90865,90817,90770,90723,90676,90629,90582,90534,90487,90440,90393,90346,90299,90251,90204,90157,90110,90063,90015,89968,89921,89874,89826,89779,89732,89685,89638,89590,89543,89496,89449,89401,89354,89307,89260,89212,89165,89118,89070,89023,88976,88929,88881,88834,88787,88739,88692,88645,88598,88550,88503,88456,88408,88361,88314,88266,88219,88172,88124,88077,88030,87982,87935,87888,87840,87793,87745,87698,87651,87603,87556,87509,87461,87414,87366,87319,87272,87224,87177,87129,87082,87035,86987,86940,86892,86845,86798,86750,86703,86655,86608,86560,86513,86465,86418,86371,86323,86276,86228,86181,86133,86086,86038,85991,85943,85896,85848,85801,85753,85706,85658,85611,85563,85516,85468,85421,85373,85326,85278,85231,85183,85136,85088,85040,84993,84945,84898,84850,84803,84755,84708,84660,84612,84565,84517,84470,84422,84374,84327,84279,84232,84184,84136,84089,84041,83994,83946,83898,83851,83803,83756,83708,83660,83613,83565,83517,83470,83422,83374,83327,83279,83231,83184,83136,83088,83041,82993,82945,82898,82850,82802,82755,82707,82659,82612,82564,82516,82468,82421,82373,82325,82278,82230,82182,82134,82087,82039,81991,81943,81896,81848,81800,81752,81705,81657,81609,81561,81514,81466,81418,81370,81322,81275,81227,81179,81131,81083,81036,80988,80940,80892,80844,80797,80749,80701,80653,80605,80557,80510,80462,80414,80366,80318,80270,80223,80175,80127,80079,80031,79983,79935,79887,79840,79792,79744,79696,79648,79600,79552,79504,79457,79409,79361,79313,79265,79217,79169,79121,79073,79025,78977,78929,78881,78834,78786,78738,78690,78642,78594,78546,78498,78450,78402,78354,78306,78258,78210,78162,78114,78066,78018,77970,77922,77874,77826,77778,77730,77682,77634,77586,77538,77490,77442,77394,77346,77298,77250,77202,77154,77106,77058,77010,76962,76914,76866,76818,76770,76721,76673,76625,76577,76529,76481,76433,76385,76337,76289,76241,76193,76144,76096,76048,76000,75952,75904,75856,75808,75760,75711,75663,75615,75567,75519,75471,75423,75375,75326,75278,75230,75182,75134,75086,75037,74989,74941,74893,74845,74797,74748,74700,74652,74604,74556,74508,74459,74411,74363,74315,74267,74218,74170,74122,74074,74025,73977,73929,73881,73833,73784,73736,73688,73640,73591,73543,73495,73447,73398,73350,73302,73254,73205,73157,73109,73061,73012,72964,72916,72867,72819,72771,72723,72674,72626,72578,72529,72481,72433,72384,72336,72288,72239,72191,72143,72095,72046,71998,71950,71901,71853,71805,71756,71708,71659,71611,71563,71514,71466,71418,71369,71321,71273,71224,71176,71127,71079,71031,70982,70934,70886,70837,70789,70740,70692,70644,70595,70547,70498,70450,70401,70353,70305,70256,70208,70159,70111,70062,70014,69966,69917,69869,69820,69772,69723,69675,69626,69578,69530,69481,69433,69384,69336,69287,69239,69190,69142,69093,69045,68996,68948,68899,68851,68802,68754,68705,68657,68608,68560,68511,68463,68414,68366,68317,68269,68220,68171,68123,68074,68026,67977,67929,67880,67832,67783,67735,67686,67637,67589,67540,67492,67443,67395,67346,67297,67249,67200,67152,67103,67055,67006,66957,66909,66860,66812,66763,66714,66666,66617,66568,66520,66471,66423,66374,66325,66277,66228,66179,66131,66082,66034,65985,65936,65888,65839,65790,65742,65693,65644,65596,65547,65498,65450,65401,65352,65304,65255,65206,65158,65109,65060,65011,64963,64914,64865,64817,64768,64719,64671,64622,64573,64524,64476,64427,64378,64329,64281,64232,64183,64135,64086,64037,63988,63940,63891,63842,63793,63745,63696,63647,63598,63550,63501,63452,63403,63354,63306,63257,63208,63159,63111,63062,63013,62964,62915,62867,62818,62769,62720,62671,62623,62574,62525,62476,62427,62378,62330,62281,62232,62183,62134,62085,62037,61988,61939,61890,61841,61792,61744,61695,61646,61597,61548,61499,61450,61402,61353,61304,61255,61206,61157,61108,61059,61011,60962,60913,60864,60815,60766,60717,60668,60619,60570,60522,60473,60424,60375,60326,60277,60228,60179,60130,60081,60032,59983,59935,59886,59837,59788,59739,59690,59641,59592,59543,59494,59445,59396,59347,59298,59249,59200,59151,59102,59053,59004,58955,58906,58857,58808,58759,58711,58662,58613,58564,58515,58466,58417,58368,58319,58270,58221,58171,58122,58073,58024,57975,57926,57877,57828,57779,57730,57681,57632,57583,57534,57485,57436,57387,57338,57289,57240,57191,57142,57093,57044,56995,56946,56896,56847,56798,56749,56700,56651,56602,56553,56504,56455,56406,56357,56308,56258,56209,56160,56111,56062,56013,55964,55915,55866,55816,55767,55718,55669,55620,55571,55522,55473,55424,55374,55325,55276,55227,55178,55129,55080,55030,54981,54932,54883,54834,54785,54736,54686,54637,54588,54539,54490,54441,54391,54342,54293,54244,54195,54145,54096,54047,53998,53949,53900,53850,53801,53752,53703,53654,53604,53555,53506,53457,53408,53358,53309,53260,53211,53161,53112,53063,53014,52965,52915,52866,52817,52768,52718,52669,52620,52571,52521,52472,52423,52374,52324,52275,52226,52177,52127,52078,52029,51980,51930,51881,51832,51782,51733,51684,51635,51585,51536,51487,51438,51388,51339,51290,51240,51191,51142,51092,51043,50994,50945,50895,50846,50797,50747,50698,50649,50599,50550,50501,50451,50402,50353,50303,50254,50205,50155,50106,50057,50007,49958,49909,49859,49810,49761,49711,49662,49613,49563,49514,49464,49415,49366,49316,49267,49218,49168,49119,49070,49020,48971,48921,48872,48823,48773,48724,48674,48625,48576,48526,48477,48427,48378,48329,48279,48230,48180,48131,48082,48032,47983,47933,47884,47835,47785,47736,47686,47637,47587,47538,47489,47439,47390,47340,47291,47241,47192,47142,47093,47044,46994,46945,46895,46846,46796,46747,46697,46648,46598,46549,46500,46450,46401,46351,46302,46252,46203,46153,46104,46054,46005,45955,45906,45856,45807,45757,45708,45658,45609,45559,45510,45460,45411,45361,45312,45262,45213,45163,45114,45064,45015,44965,44916,44866,44817,44767,44718,44668,44619,44569,44519,44470,44420,44371,44321,44272,44222,44173,44123,44074,44024,43974,43925,43875,43826,43776,43727,43677,43628,43578,43528,43479,43429,43380,43330,43281,43231,43181,43132,43082,43033,42983,42933,42884,42834,42785,42735,42686,42636,42586,42537,42487,42438,42388,42338,42289,42239,42190,42140,42090,42041,41991,41941,41892,41842,41793,41743,41693,41644,41594,41544,41495,41445,41396,41346,41296,41247,41197,41147,41098,41048,40998,40949,40899,40849,40800,40750,40701,40651,40601,40552,40502,40452,40403,40353,40303,40254,40204,40154,40105,40055,40005,39956,39906,39856,39806,39757,39707,39657,39608,39558,39508,39459,39409,39359,39310,39260,39210,39160,39111,39061,39011,38962,38912,38862,38813,38763,38713,38663,38614,38564,38514,38465,38415,38365,38315,38266,38216,38166,38116,38067,38017,37967,37917,37868,37818,37768,37719,37669,37619,37569,37520,37470,37420,37370,37321,37271,37221,37171,37122,37072,37022,36972,36922,36873,36823,36773,36723,36674,36624,36574,36524,36475,36425,36375,36325,36275,36226,36176,36126,36076,36027,35977,35927,35877,35827,35778,35728,35678,35628,35578,35529,35479,35429,35379,35329,35280,35230,35180,35130,35080,35030,34981,34931,34881,34831,34781,34732,34682,34632,34582,34532,34482,34433,34383,34333,34283,34233,34183,34134,34084,34034,33984,33934,33884,33835,33785,33735,33685,33635,33585,33535,33486,33436,33386,33336,33286,33236,33186,33137,33087,33037,32987,32937,32887,32837,32788,32738,32688,32638,32588,32538,32488,32438,32389,32339,32289,32239,32189,32139,32089,32039,31989,31940,31890,31840,31790,31740,31690,31640,31590,31540,31490,31441,31391,31341,31291,31241,31191,31141,31091,31041,30991,30942,30892,30842,30792,30742,30692,30642,30592,30542,30492,30442,30392,30342,30293,30243,30193,30143,30093,30043,29993,29943,29893,29843,29793,29743,29693,29643,29593,29543,29494,29444,29394,29344,29294,29244,29194,29144,29094,29044,28994,28944,28894,28844,28794,28744,28694,28644,28594,28544,28494,28444,28394,28344,28295,28245,28195,28145,28095,28045,27995,27945,27895,27845,27795,27745,27695,27645,27595,27545,27495,27445,27395,27345,27295,27245,27195,27145,27095,27045,26995,26945,26895,26845,26795,26745,26695,26645,26595,26545,26495,26445,26395,26345,26295,26245,26195,26145,26095,26045,25995,25945,25895,25845,25795,25745,25695,25645,25595,25545,25495,25444,25394,25344,25294,25244,25194,25144,25094,25044,24994,24944,24894,24844,24794,24744,24694,24644,24594,24544,24494,24444,24394,24344,24294,24244,24193,24143,24093,24043,23993,23943,23893,23843,23793,23743,23693,23643,23593,23543,23493,23443,23393,23342,23292,23242,23192,23142,23092,23042,22992,22942,22892,22842,22792,22742,22692,22641,22591,22541,22491,22441,22391,22341,22291,22241,22191,22141,22091,22040,21990,21940,21890,21840,21790,21740,21690,21640,21590,21540,21489,21439,21389,21339,21289,21239,21189,21139,21089,21039,20988,20938,20888,20838,20788,20738,20688,20638,20588,20538,20487,20437,20387,20337,20287,20237,20187,20137,20086,20036,19986,19936,19886,19836,19786,19736,19686,19635,19585,19535,19485,19435,19385,19335,19285,19234,19184,19134,19084,19034,18984,18934,18883,18833,18783,18733,18683,18633,18583,18532,18482,18432,18382,18332,18282,18232,18181,18131,18081,18031,17981,17931,17881,17830,17780,17730,17680,17630,17580,17530,17479,17429,17379,17329,17279,17229,17178,17128,17078,17028,16978,16928,16878,16827,16777,16727,16677,16627,16577,16526,16476,16426,16376,16326,16276,16225,16175,16125,16075,16025,15975,15924,15874,15824,15774,15724,15673,15623,15573,15523,15473,15423,15372,15322,15272,15222,15172,15122,15071,15021,14971,14921,14871,14820,14770,14720,14670,14620,14569,14519,14469,14419,14369,14319,14268,14218,14168,14118,14068,14017,13967,13917,13867,13817,13766,13716,13666,13616,13566,13515,13465,13415,13365,13315,13264,13214,13164,13114,13064,13013,12963,12913,12863,12813,12762,12712,12662,12612,12562,12511,12461,12411,12361,12311,12260,12210,12160,12110,12059,12009,11959,11909,11859,11808,11758,11708,11658,11608,11557,11507,11457,11407,11356,11306,11256,11206,11156,11105,11055,11005,10955,10904,10854,10804,10754,10704,10653,10603,10553,10503,10452,10402,10352,10302,10252,10201,10151,10101,10051,10000,9950,9900,9850,9799,9749,9699,9649,9599,9548,9498,9448,9398,9347,9297,9247,9197,9146,9096,9046,8996,8946,8895,8845,8795,8745,8694,8644,8594,8544,8493,8443,8393,8343,8292,8242,8192,8142,8091,8041,7991,7941,7890,7840,7790,7740,7690,7639,7589,7539,7489,7438,7388,7338,7288,7237,7187,7137,7087,7036,6986,6936,6886,6835,6785,6735,6685,6634,6584,6534,6484,6433,6383,6333,6283,6232,6182,6132,6082,6031,5981,5931,5881,5830,5780,5730,5680,5629,5579,5529,5479,5428,5378,5328,5278,5227,5177,5127,5076,5026,4976,4926,4875,4825,4775,4725,4674,4624,4574,4524,4473,4423,4373,4323,4272,4222,4172,4122,4071,4021,3971,3921,3870,3820,3770,3720,3669,3619,3569,3518,3468,3418,3368,3317,3267,3217,3167,3116,3066,3016,2966,2915,2865,2815,2765,2714,2664,2614,2563,2513,2463,2413,2362,2312,2262,2212,2161,2111,2061,2011,1960,1910,1860,1810,1759,1709,1659,1608,1558,1508,1458,1407,1357,1307,1257,1206,1156,1106,1056,1005,955,905,855,804,754,704,653,603,553,503,452,402,352,302,251,201,151,101,50,0,-49,-100,-150,-200,-250,-301,-351,-401,-451,-502,-552,-602,-652,-703,-753,-803,-854,-904,-954,-1004,-1055,-1105,-1155,-1205,-1256,-1306,-1356,-1406,-1457,-1507,-1557,-1607,-1658,-1708,-1758,-1809,-1859,-1909,-1959,-2010,-2060,-2110,-2160,-2211,-2261,-2311,-2361,-2412,-2462,-2512,-2562,-2613,-2663,-2713,-2764,-2814,-2864,-2914,-2965,-3015,-3065,-3115,-3166,-3216,-3266,-3316,-3367,-3417,-3467,-3517,-3568,-3618,-3668,-3719,-3769,-3819,-3869,-3920,-3970,-4020,-4070,-4121,-4171,-4221,-4271,-4322,-4372,-4422,-4472,-4523,-4573,-4623,-4673,-4724,-4774,-4824,-4874,-4925,-4975,-5025,-5075,-5126,-5176,-5226,-5277,-5327,-5377,-5427,-5478,-5528,-5578,-5628,-5679,-5729,-5779,-5829,-5880,-5930,-5980,-6030,-6081,-6131,-6181,-6231,-6282,-6332,-6382,-6432,-6483,-6533,-6583,-6633,-6684,-6734,-6784,-6834,-6885,-6935,-6985,-7035,-7086,-7136,-7186,-7236,-7287,-7337,-7387,-7437,-7488,-7538,-7588,-7638,-7689,-7739,-7789,-7839,-7889,-7940,-7990,-8040,-8090,-8141,-8191,-8241,-8291,-8342,-8392,-8442,-8492,-8543,-8593,-8643,-8693,-8744,-8794,-8844,-8894,-8945,-8995,-9045,-9095,-9145,-9196,-9246,-9296,-9346,-9397,-9447,-9497,-9547,-9598,-9648,-9698,-9748,-9798,-9849,-9899,-9949,-9999,-10050,-10100,-10150,-10200,-10251,-10301,-10351,-10401,-10451,-10502,-10552,-10602,-10652,-10703,-10753,-10803,-10853,-10903,-10954,-11004,-11054,-11104,-11155,-11205,-11255,-11305,-11355,-11406,-11456,-11506,-11556,-11607,-11657,-11707,-11757,-11807,-11858,-11908,-11958,-12008,-12058,-12109,-12159,-12209,-12259,-12310,-12360,-12410,-12460,-12510,-12561,-12611,-12661,-12711,-12761,-12812,-12862,-12912,-12962,-13012,-13063,-13113,-13163,-13213,-13263,-13314,-13364,-13414,-13464,-13514,-13565,-13615,-13665,-13715,-13765,-13816,-13866,-13916,-13966,-14016,-14067,-14117,-14167,-14217,-14267,-14318,-14368,-14418,-14468,-14518,-14568,-14619,-14669,-14719,-14769,-14819,-14870,-14920,-14970,-15020,-15070,-15121,-15171,-15221,-15271,-15321,-15371,-15422,-15472,-15522,-15572,-15622,-15672,-15723,-15773,-15823,-15873,-15923,-15974,-16024,-16074,-16124,-16174,-16224,-16275,-16325,-16375,-16425,-16475,-16525,-16576,-16626,-16676,-16726,-16776,-16826,-16877,-16927,-16977,-17027,-17077,-17127,-17177,-17228,-17278,-17328,-17378,-17428,-17478,-17529,-17579,-17629,-17679,-17729,-17779,-17829,-17880,-17930,-17980,-18030,-18080,-18130,-18180,-18231,-18281,-18331,-18381,-18431,-18481,-18531,-18582,-18632,-18682,-18732,-18782,-18832,-18882,-18933,-18983,-19033,-19083,-19133,-19183,-19233,-19284,-19334,-19384,-19434,-19484,-19534,-19584,-19634,-19685,-19735,-19785,-19835,-19885,-19935,-19985,-20035,-20085,-20136,-20186,-20236,-20286,-20336,-20386,-20436,-20486,-20537,-20587,-20637,-20687,-20737,-20787,-20837,-20887,-20937,-20987,-21038,-21088,-21138,-21188,-21238,-21288,-21338,-21388,-21438,-21488,-21539,-21589,-21639,-21689,-21739,-21789,-21839,-21889,-21939,-21989,-22039,-22090,-22140,-22190,-22240,-22290,-22340,-22390,-22440,-22490,-22540,-22590,-22640,-22691,-22741,-22791,-22841,-22891,-22941,-22991,-23041,-23091,-23141,-23191,-23241,-23291,-23341,-23392,-23442,-23492,-23542,-23592,-23642,-23692,-23742,-23792,-23842,-23892,-23942,-23992,-24042,-24092,-24142,-24192,-24243,-24293,-24343,-24393,-24443,-24493,-24543,-24593,-24643,-24693,-24743,-24793,-24843,-24893,-24943,-24993,-25043,-25093,-25143,-25193,-25243,-25293,-25343,-25393,-25443,-25494,-25544,-25594,-25644,-25694,-25744,-25794,-25844,-25894,-25944,-25994,-26044,-26094,-26144,-26194,-26244,-26294,-26344,-26394,-26444,-26494,-26544,-26594,-26644,-26694,-26744,-26794,-26844,-26894,-26944,-26994,-27044,-27094,-27144,-27194,-27244,-27294,-27344,-27394,-27444,-27494,-27544,-27594,-27644,-27694,-27744,-27794,-27844,-27894,-27944,-27994,-28044,-28094,-28144,-28194,-28244,-28294,-28343,-28393,-28443,-28493,-28543,-28593,-28643,-28693,-28743,-28793,-28843,-28893,-28943,-28993,-29043,-29093,-29143,-29193,-29243,-29293,-29343,-29393,-29443,-29493,-29542,-29592,-29642,-29692,-29742,-29792,-29842,-29892,-29942,-29992,-30042,-30092,-30142,-30192,-30242,-30292,-30341,-30391,-30441,-30491,-30541,-30591,-30641,-30691,-30741,-30791,-30841,-30891,-30941,-30990,-31040,-31090,-31140,-31190,-31240,-31290,-31340,-31390,-31440,-31489,-31539,-31589,-31639,-31689,-31739,-31789,-31839,-31889,-31939,-31988,-32038,-32088,-32138,-32188,-32238,-32288,-32338,-32388,-32437,-32487,-32537,-32587,-32637,-32687,-32737,-32787,-32836,-32886,-32936,-32986,-33036,-33086,-33136,-33185,-33235,-33285,-33335,-33385,-33435,-33485,-33534,-33584,-33634,-33684,-33734,-33784,-33834,-33883,-33933,-33983,-34033,-34083,-34133,-34182,-34232,-34282,-34332,-34382,-34432,-34481,-34531,-34581,-34631,-34681,-34731,-34780,-34830,-34880,-34930,-34980,-35029,-35079,-35129,-35179,-35229,-35279,-35328,-35378,-35428,-35478,-35528,-35577,-35627,-35677,-35727,-35777,-35826,-35876,-35926,-35976,-36026,-36075,-36125,-36175,-36225,-36274,-36324,-36374,-36424,-36474,-36523,-36573,-36623,-36673,-36722,-36772,-36822,-36872,-36921,-36971,-37021,-37071,-37121,-37170,-37220,-37270,-37320,-37369,-37419,-37469,-37519,-37568,-37618,-37668,-37718,-37767,-37817,-37867,-37916,-37966,-38016,-38066,-38115,-38165,-38215,-38265,-38314,-38364,-38414,-38464,-38513,-38563,-38613,-38662,-38712,-38762,-38812,-38861,-38911,-38961,-39010,-39060,-39110,-39159,-39209,-39259,-39309,-39358,-39408,-39458,-39507,-39557,-39607,-39656,-39706,-39756,-39805,-39855,-39905,-39955,-40004,-40054,-40104,-40153,-40203,-40253,-40302,-40352,-40402,-40451,-40501,-40551,-40600,-40650,-40700,-40749,-40799,-40848,-40898,-40948,-40997,-41047,-41097,-41146,-41196,-41246,-41295,-41345,-41395,-41444,-41494,-41543,-41593,-41643,-41692,-41742,-41792,-41841,-41891,-41940,-41990,-42040,-42089,-42139,-42189,-42238,-42288,-42337,-42387,-42437,-42486,-42536,-42585,-42635,-42685,-42734,-42784,-42833,-42883,-42932,-42982,-43032,-43081,-43131,-43180,-43230,-43280,-43329,-43379,-43428,-43478,-43527,-43577,-43627,-43676,-43726,-43775,-43825,-43874,-43924,-43973,-44023,-44073,-44122,-44172,-44221,-44271,-44320,-44370,-44419,-44469,-44518,-44568,-44618,-44667,-44717,-44766,-44816,-44865,-44915,-44964,-45014,-45063,-45113,-45162,-45212,-45261,-45311,-45360,-45410,-45459,-45509,-45558,-45608,-45657,-45707,-45756,-45806,-45855,-45905,-45954,-46004,-46053,-46103,-46152,-46202,-46251,-46301,-46350,-46400,-46449,-46499,-46548,-46597,-46647,-46696,-46746,-46795,-46845,-46894,-46944,-46993,-47043,-47092,-47141,-47191,-47240,-47290,-47339,-47389,-47438,-47488,-47537,-47586,-47636,-47685,-47735,-47784,-47834,-47883,-47932,-47982,-48031,-48081,-48130,-48179,-48229,-48278,-48328,-48377,-48426,-48476,-48525,-48575,-48624,-48673,-48723,-48772,-48822,-48871,-48920,-48970,-49019,-49069,-49118,-49167,-49217,-49266,-49315,-49365,-49414,-49463,-49513,-49562,-49612,-49661,-49710,-49760,-49809,-49858,-49908,-49957,-50006,-50056,-50105,-50154,-50204,-50253,-50302,-50352,-50401,-50450,-50500,-50549,-50598,-50648,-50697,-50746,-50796,-50845,-50894,-50944,-50993,-51042,-51091,-51141,-51190,-51239,-51289,-51338,-51387,-51437,-51486,-51535,-51584,-51634,-51683,-51732,-51781,-51831,-51880,-51929,-51979,-52028,-52077,-52126,-52176,-52225,-52274,-52323,-52373,-52422,-52471,-52520,-52570,-52619,-52668,-52717,-52767,-52816,-52865,-52914,-52964,-53013,-53062,-53111,-53160,-53210,-53259,-53308,-53357,-53407,-53456,-53505,-53554,-53603,-53653,-53702,-53751,-53800,-53849,-53899,-53948,-53997,-54046,-54095,-54144,-54194,-54243,-54292,-54341,-54390,-54440,-54489,-54538,-54587,-54636,-54685,-54735,-54784,-54833,-54882,-54931,-54980,-55029,-55079,-55128,-55177,-55226,-55275,-55324,-55373,-55423,-55472,-55521,-55570,-55619,-55668,-55717,-55766,-55815,-55865,-55914,-55963,-56012,-56061,-56110,-56159,-56208,-56257,-56307,-56356,-56405,-56454,-56503,-56552,-56601,-56650,-56699,-56748,-56797,-56846,-56895,-56945,-56994,-57043,-57092,-57141,-57190,-57239,-57288,-57337,-57386,-57435,-57484,-57533,-57582,-57631,-57680,-57729,-57778,-57827,-57876,-57925,-57974,-58023,-58072,-58121,-58170,-58220,-58269,-58318,-58367,-58416,-58465,-58514,-58563,-58612,-58661,-58710,-58758,-58807,-58856,-58905,-58954,-59003,-59052,-59101,-59150,-59199,-59248,-59297,-59346,-59395,-59444,-59493,-59542,-59591,-59640,-59689,-59738,-59787,-59836,-59885,-59934,-59982,-60031,-60080,-60129,-60178,-60227,-60276,-60325,-60374,-60423,-60472,-60521,-60569,-60618,-60667,-60716,-60765,-60814,-60863,-60912,-60961,-61010,-61058,-61107,-61156,-61205,-61254,-61303,-61352,-61401,-61449,-61498,-61547,-61596,-61645,-61694,-61743,-61791,-61840,-61889,-61938,-61987,-62036,-62084,-62133,-62182,-62231,-62280,-62329,-62377,-62426,-62475,-62524,-62573,-62622,-62670,-62719,-62768,-62817,-62866,-62914,-62963,-63012,-63061,-63110,-63158,-63207,-63256,-63305,-63353,-63402,-63451,-63500,-63549,-63597,-63646,-63695,-63744,-63792,-63841,-63890,-63939,-63987,-64036,-64085,-64134,-64182,-64231,-64280,-64328,-64377,-64426,-64475,-64523,-64572,-64621,-64670,-64718,-64767,-64816,-64864,-64913,-64962,-65010,-65059,-65108,-65157,-65205,-65254,-65303,-65351,-65400,-65449,-65497,-65546,-65595,-65643,-65692,-65741,-65789,-65838,-65887,-65935,-65984,-66033,-66081,-66130,-66178,-66227,-66276,-66324,-66373,-66422,-66470,-66519,-66567,-66616,-66665,-66713,-66762,-66811,-66859,-66908,-66956,-67005,-67054,-67102,-67151,-67199,-67248,-67296,-67345,-67394,-67442,-67491,-67539,-67588,-67636,-67685,-67734,-67782,-67831,-67879,-67928,-67976,-68025,-68073,-68122,-68170,-68219,-68268,-68316,-68365,-68413,-68462,-68510,-68559,-68607,-68656,-68704,-68753,-68801,-68850,-68898,-68947,-68995,-69044,-69092,-69141,-69189,-69238,-69286,-69335,-69383,-69432,-69480,-69529,-69577,-69625,-69674,-69722,-69771,-69819,-69868,-69916,-69965,-70013,-70061,-70110,-70158,-70207,-70255,-70304,-70352,-70400,-70449,-70497,-70546,-70594,-70643,-70691,-70739,-70788,-70836,-70885,-70933,-70981,-71030,-71078,-71126,-71175,-71223,-71272,-71320,-71368,-71417,-71465,-71513,-71562,-71610,-71658,-71707,-71755,-71804,-71852,-71900,-71949,-71997,-72045,-72094,-72142,-72190,-72238,-72287,-72335,-72383,-72432,-72480,-72528,-72577,-72625,-72673,-72722,-72770,-72818,-72866,-72915,-72963,-73011,-73060,-73108,-73156,-73204,-73253,-73301,-73349,-73397,-73446,-73494,-73542,-73590,-73639,-73687,-73735,-73783,-73832,-73880,-73928,-73976,-74024,-74073,-74121,-74169,-74217,-74266,-74314,-74362,-74410,-74458,-74507,-74555,-74603,-74651,-74699,-74747,-74796,-74844,-74892,-74940,-74988,-75036,-75085,-75133,-75181,-75229,-75277,-75325,-75374,-75422,-75470,-75518,-75566,-75614,-75662,-75710,-75759,-75807,-75855,-75903,-75951,-75999,-76047,-76095,-76143,-76192,-76240,-76288,-76336,-76384,-76432,-76480,-76528,-76576,-76624,-76672,-76720,-76769,-76817,-76865,-76913,-76961,-77009,-77057,-77105,-77153,-77201,-77249,-77297,-77345,-77393,-77441,-77489,-77537,-77585,-77633,-77681,-77729,-77777,-77825,-77873,-77921,-77969,-78017,-78065,-78113,-78161,-78209,-78257,-78305,-78353,-78401,-78449,-78497,-78545,-78593,-78641,-78689,-78737,-78785,-78833,-78880,-78928,-78976,-79024,-79072,-79120,-79168,-79216,-79264,-79312,-79360,-79408,-79456,-79503,-79551,-79599,-79647,-79695,-79743,-79791,-79839,-79886,-79934,-79982,-80030,-80078,-80126,-80174,-80222,-80269,-80317,-80365,-80413,-80461,-80509,-80556,-80604,-80652,-80700,-80748,-80796,-80843,-80891,-80939,-80987,-81035,-81082,-81130,-81178,-81226,-81274,-81321,-81369,-81417,-81465,-81513,-81560,-81608,-81656,-81704,-81751,-81799,-81847,-81895,-81942,-81990,-82038,-82086,-82133,-82181,-82229,-82277,-82324,-82372,-82420,-82467,-82515,-82563,-82611,-82658,-82706,-82754,-82801,-82849,-82897,-82944,-82992,-83040,-83087,-83135,-83183,-83230,-83278,-83326,-83373,-83421,-83469,-83516,-83564,-83612,-83659,-83707,-83755,-83802,-83850,-83897,-83945,-83993,-84040,-84088,-84135,-84183,-84231,-84278,-84326,-84373,-84421,-84469,-84516,-84564,-84611,-84659,-84707,-84754,-84802,-84849,-84897,-84944,-84992,-85039,-85087,-85135,-85182,-85230,-85277,-85325,-85372,-85420,-85467,-85515,-85562,-85610,-85657,-85705,-85752,-85800,-85847,-85895,-85942,-85990,-86037,-86085,-86132,-86180,-86227,-86275,-86322,-86370,-86417,-86464,-86512,-86559,-86607,-86654,-86702,-86749,-86797,-86844,-86891,-86939,-86986,-87034,-87081,-87128,-87176,-87223,-87271,-87318,-87365,-87413,-87460,-87508,-87555,-87602,-87650,-87697,-87744,-87792,-87839,-87887,-87934,-87981,-88029,-88076,-88123,-88171,-88218,-88265,-88313,-88360,-88407,-88455,-88502,-88549,-88597,-88644,-88691,-88738,-88786,-88833,-88880,-88928,-88975,-89022,-89069,-89117,-89164,-89211,-89259,-89306,-89353,-89400,-89448,-89495,-89542,-89589,-89637,-89684,-89731,-89778,-89825,-89873,-89920,-89967,-90014,-90062,-90109,-90156,-90203,-90250,-90298,-90345,-90392,-90439,-90486,-90533,-90581,-90628,-90675,-90722,-90769,-90816,-90864,-90911,-90958,-91005,-91052,-91099,-91146,-91194,-91241,-91288,-91335,-91382,-91429,-91476,-91523,-91570,-91618,-91665,-91712,-91759,-91806,-91853,-91900,-91947,-91994,-92041,-92088,-92135,-92182,-92229,-92277,-92324,-92371,-92418,-92465,-92512,-92559,-92606,-92653,-92700,-92747,-92794,-92841,-92888,-92935,-92982,-93029,-93076,-93123,-93170,-93217,-93264,-93311,-93358,-93405,-93452,-93499,-93546,-93593,-93639,-93686,-93733,-93780,-93827,-93874,-93921,-93968,-94015,-94062,-94109,-94156,-94203,-94250,-94296,-94343,-94390,-94437,-94484,-94531,-94578,-94625,-94672,-94718,-94765,-94812,-94859,-94906,-94953,-95000,-95046,-95093,-95140,-95187,-95234,-95281,-95327,-95374,-95421,-95468,-95515,-95561,-95608,-95655,-95702,-95749,-95795,-95842,-95889,-95936,-95983,-96029,-96076,-96123,-96170,-96216,-96263,-96310,-96357,-96403,-96450,-96497,-96544,-96590,-96637,-96684,-96731,-96777,-96824,-96871,-96917,-96964,-97011,-97057,-97104,-97151,-97198,-97244,-97291,-97338,-97384,-97431,-97478,-97524,-97571,-97618,-97664,-97711,-97757,-97804,-97851,-97897,-97944,-97991,-98037,-98084,-98130,-98177,-98224,-98270,-98317,-98363,-98410,-98457,-98503,-98550,-98596,-98643,-98690,-98736,-98783,-98829,-98876,-98922,-98969,-99015,-99062,-99109,-99155,-99202,-99248,-99295,-99341,-99388,-99434,-99481,-99527,-99574,-99620,-99667,-99713,-99760,-99806,-99853,-99899,-99946,-99992,-100038,-100085,-100131,-100178,-100224,-100271,-100317,-100364,-100410,-100456,-100503,-100549,-100596,-100642,-100689,-100735,-100781,-100828,-100874,-100921,-100967,-101013,-101060,-101106,-101152,-101199,-101245,-101292,-101338,-101384,-101431,-101477,-101523,-101570,-101616,-101662,-101709,-101755,-101801,-101848,-101894,-101940,-101987,-102033,-102079,-102125,-102172,-102218,-102264,-102311,-102357,-102403,-102449,-102496,-102542,-102588,-102634,-102681,-102727,-102773,-102819,-102866,-102912,-102958,-103004,-103051,-103097,-103143,-103189,-103235,-103282,-103328,-103374,-103420,-103466,-103513,-103559,-103605,-103651,-103697,-103743,-103790,-103836,-103882,-103928,-103974,-104020,-104066,-104113,-104159,-104205,-104251,-104297,-104343,-104389,-104435,-104482,-104528,-104574,-104620,-104666,-104712,-104758,-104804,-104850,-104896,-104942,-104988,-105034,-105081,-105127,-105173,-105219,-105265,-105311,-105357,-105403,-105449,-105495,-105541,-105587,-105633,-105679,-105725,-105771,-105817,-105863,-105909,-105955,-106001,-106047,-106093,-106139,-106185,-106231,-106277,-106322,-106368,-106414,-106460,-106506,-106552,-106598,-106644,-106690,-106736,-106782,-106828,-106874,-106919,-106965,-107011,-107057,-107103,-107149,-107195,-107241,-107286,-107332,-107378,-107424,-107470,-107516,-107562,-107607,-107653,-107699,-107745,-107791,-107837,-107882,-107928,-107974,-108020,-108066,-108111,-108157,-108203,-108249,-108294,-108340,-108386,-108432,-108478,-108523,-108569,-108615,-108661,-108706,-108752,-108798,-108844,-108889,-108935,-108981,-109026,-109072,-109118,-109164,-109209,-109255,-109301,-109346,-109392,-109438,-109483,-109529,-109575,-109620,-109666,-109712,-109757,-109803,-109849,-109894,-109940,-109985,-110031,-110077,-110122,-110168,-110214,-110259,-110305,-110350,-110396,-110442,-110487,-110533,-110578,-110624,-110669,-110715,-110761,-110806,-110852,-110897,-110943,-110988,-111034,-111079,-111125,-111170,-111216,-111261,-111307,-111352,-111398,-111443,-111489,-111534,-111580,-111625,-111671,-111716,-111762,-111807,-111853,-111898,-111944,-111989,-112035,-112080,-112125,-112171,-112216,-112262,-112307,-112353,-112398,-112443,-112489,-112534,-112580,-112625,-112670,-112716,-112761,-112807,-112852,-112897,-112943,-112988,-113033,-113079,-113124,-113169,-113215,-113260,-113305,-113351,-113396,-113441,-113487,-113532,-113577,-113623,-113668,-113713,-113758,-113804,-113849,-113894,-113940,-113985,-114030,-114075,-114121,-114166,-114211,-114256,-114302,-114347,-114392,-114437,-114482,-114528,-114573,-114618,-114663,-114709,-114754,-114799,-114844,-114889,-114934,-114980,-115025,-115070,-115115,-115160,-115205,-115251,-115296,-115341,-115386,-115431,-115476,-115521,-115566,-115612,-115657,-115702,-115747,-115792,-115837,-115882,-115927,-115972,-116017,-116063,-116108,-116153,-116198,-116243,-116288,-116333,-116378,-116423,-116468,-116513,-116558,-116603,-116648,-116693,-116738,-116783,-116828,-116873,-116918,-116963,-117008,-117053,-117098,-117143,-117188,-117233,-117278,-117323,-117368,-117413,-117458,-117503,-117548,-117592,-117637,-117682,-117727,-117772,-117817,-117862,-117907,-117952,-117997,-118041,-118086,-118131,-118176,-118221,-118266,-118311,-118356,-118400,-118445,-118490,-118535,-118580,-118625,-118669,-118714,-118759,-118804,-118849,-118893,-118938,-118983,-119028,-119073,-119117,-119162,-119207,-119252,-119296,-119341,-119386,-119431,-119475,-119520,-119565,-119610,-119654,-119699,-119744,-119789,-119833,-119878,-119923,-119967,-120012,-120057,-120101,-120146,-120191,-120235,-120280,-120325,-120369,-120414,-120459,-120503,-120548,-120593,-120637,-120682,-120726,-120771,-120816,-120860,-120905,-120949,-120994,-121039,-121083,-121128,-121172,-121217,-121262,-121306,-121351,-121395,-121440,-121484,-121529,-121573,-121618,-121662,-121707,-121751,-121796,-121841,-121885,-121930,-121974,-122018,-122063,-122107,-122152,-122196,-122241,-122285,-122330,-122374,-122419,-122463,-122508,-122552,-122596,-122641,-122685,-122730,-122774,-122819,-122863,-122907,-122952,-122996,-123041,-123085,-123129,-123174,-123218,-123262,-123307,-123351,-123395,-123440,-123484,-123528,-123573,-123617,-123661,-123706,-123750,-123794,-123839,-123883,-123927,-123972,-124016,-124060,-124104,-124149,-124193,-124237,-124282,-124326,-124370,-124414,-124459,-124503,-124547,-124591,-124635,-124680,-124724,-124768,-124812,-124856,-124901,-124945,-124989,-125033,-125077,-125122,-125166,-125210,-125254,-125298,-125342,-125387,-125431,-125475,-125519,-125563,-125607,-125651,-125695,-125740,-125784,-125828,-125872,-125916,-125960,-126004,-126048,-126092,-126136,-126180,-126224,-126268,-126313,-126357,-126401,-126445,-126489,-126533,-126577,-126621,-126665,-126709,-126753,-126797,-126841,-126885,-126929,-126973,-127017,-127061,-127105,-127149,-127192,-127236,-127280,-127324,-127368,-127412,-127456,-127500,-127544,-127588,-127632,-127676,-127720,-127763,-127807,-127851,-127895,-127939,-127983,-128027,-128071,-128114,-128158,-128202,-128246,-128290,-128334,-128377,-128421,-128465,-128509,-128553,-128597,-128640,-128684,-128728,-128772,-128815,-128859,-128903,-128947,-128991,-129034,-129078,-129122,-129166,-129209,-129253,-129297,-129340,-129384,-129428,-129472,-129515,-129559,-129603,-129646,-129690,-129734,-129777,-129821,-129865,-129908,-129952,-129996,-130039,-130083,-130127,-130170,-130214,-130258,-130301,-130345,-130388,-130432,-130476,-130519,-130563,-130606,-130650,-130694,-130737,-130781,-130824,-130868,-130911,-130955,-130998,-131042,-131086,-131129,-131173,-131216,-131260,-131303,-131347,-131390,-131434,-131477,-131521,-131564,-131608,-131651,-131694,-131738,-131781,-131825,-131868,-131912,-131955,-131999,-132042,-132085,-132129,-132172,-132216,-132259,-132302,-132346,-132389,-132433,-132476,-132519,-132563,-132606,-132649,-132693,-132736,-132779,-132823,-132866,-132909,-132953,-132996,-133039,-133083,-133126,-133169,-133213,-133256,-133299,-133342,-133386,-133429,-133472,-133516,-133559,-133602,-133645,-133689,-133732,-133775,-133818,-133861,-133905,-133948,-133991,-134034,-134077,-134121,-134164,-134207,-134250,-134293,-134337,-134380,-134423,-134466,-134509,-134552,-134595,-134639,-134682,-134725,-134768,-134811,-134854,-134897,-134940,-134983,-135027,-135070,-135113,-135156,-135199,-135242,-135285,-135328,-135371,-135414,-135457,-135500,-135543,-135586,-135629,-135672,-135715,-135758,-135801,-135844,-135887,-135930,-135973,-136016,-136059,-136102,-136145,-136188,-136231,-136274,-136317,-136360,-136403,-136446,-136489,-136531,-136574,-136617,-136660,-136703,-136746,-136789,-136832,-136875,-136917,-136960,-137003,-137046,-137089,-137132,-137175,-137217,-137260,-137303,-137346,-137389,-137431,-137474,-137517,-137560,-137603,-137645,-137688,-137731,-137774,-137816,-137859,-137902,-137945,-137987,-138030,-138073,-138116,-138158,-138201,-138244,-138287,-138329,-138372,-138415,-138457,-138500,-138543,-138585,-138628,-138671,-138713,-138756,-138799,-138841,-138884,-138926,-138969,-139012,-139054,-139097,-139140,-139182,-139225,-139267,-139310,-139352,-139395,-139438,-139480,-139523,-139565,-139608,-139650,-139693,-139735,-139778,-139820,-139863,-139906,-139948,-139991,-140033,-140076,-140118,-140160,-140203,-140245,-140288,-140330,-140373,-140415,-140458,-140500,-140543,-140585,-140627,-140670,-140712,-140755,-140797,-140839,-140882,-140924,-140967,-141009,-141051,-141094,-141136,-141178,-141221,-141263,-141305,-141348,-141390,-141432,-141475,-141517,-141559,-141602,-141644,-141686,-141729,-141771,-141813,-141855,-141898,-141940,-141982,-142024,-142067,-142109,-142151,-142193,-142236,-142278,-142320,-142362,-142404,-142447,-142489,-142531,-142573,-142615,-142658,-142700,-142742,-142784,-142826,-142868,-142911,-142953,-142995,-143037,-143079,-143121,-143163,-143205,-143247,-143290,-143332,-143374,-143416,-143458,-143500,-143542,-143584,-143626,-143668,-143710,-143752,-143794,-143836,-143878,-143920,-143962,-144004,-144046,-144088,-144130,-144172,-144214,-144256,-144298,-144340,-144382,-144424,-144466,-144508,-144550,-144592,-144634,-144676,-144718,-144760,-144801,-144843,-144885,-144927,-144969,-145011,-145053,-145095,-145136,-145178,-145220,-145262,-145304,-145346,-145388,-145429,-145471,-145513,-145555,-145597,-145638,-145680,-145722,-145764,-145806,-145847,-145889,-145931,-145973,-146014,-146056,-146098,-146140,-146181,-146223,-146265,-146306,-146348,-146390,-146432,-146473,-146515,-146557,-146598,-146640,-146682,-146723,-146765,-146807,-146848,-146890,-146931,-146973,-147015,-147056,-147098,-147140,-147181,-147223,-147264,-147306,-147347,-147389,-147431,-147472,-147514,-147555,-147597,-147638,-147680,-147721,-147763,-147804,-147846,-147887,-147929,-147970,-148012,-148053,-148095,-148136,-148178,-148219,-148261,-148302,-148344,-148385,-148427,-148468,-148509,-148551,-148592,-148634,-148675,-148716,-148758,-148799,-148841,-148882,-148923,-148965,-149006,-149047,-149089,-149130,-149171,-149213,-149254,-149295,-149337,-149378,-149419,-149461,-149502,-149543,-149584,-149626,-149667,-149708,-149750,-149791,-149832,-149873,-149915,-149956,-149997,-150038,-150079,-150121,-150162,-150203,-150244,-150285,-150327,-150368,-150409,-150450,-150491,-150532,-150574,-150615,-150656,-150697,-150738,-150779,-150820,-150861,-150903,-150944,-150985,-151026,-151067,-151108,-151149,-151190,-151231,-151272,-151313,-151354,-151395,-151436,-151477,-151518,-151559,-151600,-151641,-151682,-151723,-151764,-151805,-151846,-151887,-151928,-151969,-152010,-152051,-152092,-152133,-152174,-152215,-152256,-152297,-152338,-152379,-152420,-152460,-152501,-152542,-152583,-152624,-152665,-152706,-152747,-152787,-152828,-152869,-152910,-152951,-152992,-153032,-153073,-153114,-153155,-153196,-153236,-153277,-153318,-153359,-153399,-153440,-153481,-153522,-153562,-153603,-153644,-153685,-153725,-153766,-153807,-153847,-153888,-153929,-153969,-154010,-154051,-154092,-154132,-154173,-154213,-154254,-154295,-154335,-154376,-154417,-154457,-154498,-154538,-154579,-154620,-154660,-154701,-154741,-154782,-154823,-154863,-154904,-154944,-154985,-155025,-155066,-155106,-155147,-155187,-155228,-155268,-155309,-155349,-155390,-155430,-155471,-155511,-155552,-155592,-155633,-155673,-155714,-155754,-155794,-155835,-155875,-155916,-155956,-155996,-156037,-156077,-156118,-156158,-156198,-156239,-156279,-156319,-156360,-156400,-156440,-156481,-156521,-156561,-156602,-156642,-156682,-156723,-156763,-156803,-156844,-156884,-156924,-156964,-157005,-157045,-157085,-157125,-157166,-157206,-157246,-157286,-157326,-157367,-157407,-157447,-157487,-157527,-157568,-157608,-157648,-157688,-157728,-157768,-157808,-157849,-157889,-157929,-157969,-158009,-158049,-158089,-158129,-158169,-158210,-158250,-158290,-158330,-158370,-158410,-158450,-158490,-158530,-158570,-158610,-158650,-158690,-158730,-158770,-158810,-158850,-158890,-158930,-158970,-159010,-159050,-159090,-159130,-159170,-159210,-159250,-159290,-159329,-159369,-159409,-159449,-159489,-159529,-159569,-159609,-159649,-159688,-159728,-159768,-159808,-159848,-159888,-159928,-159967,-160007,-160047,-160087,-160127,-160166,-160206,-160246,-160286,-160326,-160365,-160405,-160445,-160485,-160524,-160564,-160604,-160643,-160683,-160723,-160763,-160802,-160842,-160882,-160921,-160961,-161001,-161040,-161080,-161120,-161159,-161199,-161239,-161278,-161318,-161358,-161397,-161437,-161476,-161516,-161556,-161595,-161635,-161674,-161714,-161753,-161793,-161832,-161872,-161912,-161951,-161991,-162030,-162070,-162109,-162149,-162188,-162228,-162267,-162307,-162346,-162385,-162425,-162464,-162504,-162543,-162583,-162622,-162662,-162701,-162740,-162780,-162819,-162859,-162898,-162937,-162977,-163016,-163055,-163095,-163134,-163173,-163213,-163252,-163291,-163331,-163370,-163409,-163449,-163488,-163527,-163567,-163606,-163645,-163684,-163724,-163763,-163802,-163841,-163881,-163920,-163959,-163998,-164038,-164077,-164116,-164155,-164194,-164233,-164273,-164312,-164351,-164390,-164429,-164468,-164508,-164547,-164586,-164625,-164664,-164703,-164742,-164781,-164820,-164860,-164899,-164938,-164977,-165016,-165055,-165094,-165133,-165172,-165211,-165250,-165289,-165328,-165367,-165406,-165445,-165484,-165523,-165562,-165601,-165640,-165679,-165718,-165757,-165796,-165835,-165874,-165913,-165951,-165990,-166029,-166068,-166107,-166146,-166185,-166224,-166263,-166301,-166340,-166379,-166418,-166457,-166496,-166534,-166573,-166612,-166651,-166690,-166728,-166767,-166806,-166845,-166884,-166922,-166961,-167000,-167039,-167077,-167116,-167155,-167193,-167232,-167271,-167310,-167348,-167387,-167426,-167464,-167503,-167542,-167580,-167619,-167658,-167696,-167735,-167773,-167812,-167851,-167889,-167928,-167967,-168005,-168044,-168082,-168121,-168159,-168198,-168237,-168275,-168314,-168352,-168391,-168429,-168468,-168506,-168545,-168583,-168622,-168660,-168699,-168737,-168776,-168814,-168852,-168891,-168929,-168968,-169006,-169045,-169083,-169121,-169160,-169198,-169237,-169275,-169313,-169352,-169390,-169429,-169467,-169505,-169544,-169582,-169620,-169659,-169697,-169735,-169773,-169812,-169850,-169888,-169927,-169965,-170003,-170041,-170080,-170118,-170156,-170194,-170233,-170271,-170309,-170347,-170385,-170424,-170462,-170500,-170538,-170576,-170615,-170653,-170691,-170729,-170767,-170805,-170843,-170882,-170920,-170958,-170996,-171034,-171072,-171110,-171148,-171186,-171224,-171262,-171300,-171338,-171377,-171415,-171453,-171491,-171529,-171567,-171605,-171643,-171681,-171719,-171757,-171795,-171833,-171870,-171908,-171946,-171984,-172022,-172060,-172098,-172136,-172174,-172212,-172250,-172288,-172325,-172363,-172401,-172439,-172477,-172515,-172553,-172590,-172628,-172666,-172704,-172742,-172780,-172817,-172855,-172893,-172931,-172968,-173006,-173044,-173082,-173120,-173157,-173195,-173233,-173270,-173308,-173346,-173384,-173421,-173459,-173497,-173534,-173572,-173610,-173647,-173685,-173723,-173760,-173798,-173836,-173873,-173911,-173948,-173986,-174024,-174061,-174099,-174136,-174174,-174211,-174249,-174287,-174324,-174362,-174399,-174437,-174474,-174512,-174549,-174587,-174624,-174662,-174699,-174737,-174774,-174812,-174849,-174886,-174924,-174961,-174999,-175036,-175074,-175111,-175148,-175186,-175223,-175261,-175298,-175335,-175373,-175410,-175447,-175485,-175522,-175559,-175597,-175634,-175671,-175709,-175746,-175783,-175821,-175858,-175895,-175932,-175970,-176007,-176044,-176081,-176119,-176156,-176193,-176230,-176267,-176305,-176342,-176379,-176416,-176453,-176491,-176528,-176565,-176602,-176639,-176676,-176713,-176751,-176788,-176825,-176862,-176899,-176936,-176973,-177010,-177047,-177084,-177122,-177159,-177196,-177233,-177270,-177307,-177344,-177381,-177418,-177455,-177492,-177529,-177566,-177603,-177640,-177677,-177714,-177751,-177787,-177824,-177861,-177898,-177935,-177972,-178009,-178046,-178083,-178120,-178157,-178193,-178230,-178267,-178304,-178341,-178378,-178414,-178451,-178488,-178525,-178562,-178599,-178635,-178672,-178709,-178746,-178782,-178819,-178856,-178893,-178929,-178966,-179003,-179040,-179076,-179113,-179150,-179186,-179223,-179260,-179296,-179333,-179370,-179406,-179443,-179480,-179516,-179553,-179590,-179626,-179663,-179699,-179736,-179773,-179809,-179846,-179882,-179919,-179955,-179992,-180028,-180065,-180102,-180138,-180175,-180211,-180248,-180284,-180321,-180357,-180394,-180430,-180466,-180503,-180539,-180576,-180612,-180649,-180685,-180722,-180758,-180794,-180831,-180867,-180903,-180940,-180976,-181013,-181049,-181085,-181122,-181158,-181194,-181231,-181267,-181303,-181340,-181376,-181412,-181448,-181485,-181521,-181557,-181593,-181630,-181666,-181702,-181738,-181775,-181811,-181847,-181883,-181919,-181956,-181992,-182028,-182064,-182100,-182136,-182173,-182209,-182245,-182281,-182317,-182353,-182389,-182425,-182462,-182498,-182534,-182570,-182606,-182642,-182678,-182714,-182750,-182786,-182822,-182858,-182894,-182930,-182966,-183002,-183038,-183074,-183110,-183146,-183182,-183218,-183254,-183290,-183326,-183362,-183398,-183434,-183469,-183505,-183541,-183577,-183613,-183649,-183685,-183721,-183756,-183792,-183828,-183864,-183900,-183936,-183971,-184007,-184043,-184079,-184115,-184150,-184186,-184222,-184258,-184293,-184329,-184365,-184401,-184436,-184472,-184508,-184544,-184579,-184615,-184651,-184686,-184722,-184758,-184793,-184829,-184865,-184900,-184936,-184971,-185007,-185043,-185078,-185114,-185149,-185185,-185221,-185256,-185292,-185327,-185363,-185398,-185434,-185469,-185505,-185540,-185576,-185611,-185647,-185682,-185718,-185753,-185789,-185824,-185860,-185895,-185931,-185966,-186001,-186037,-186072,-186108,-186143,-186178,-186214,-186249,-186285,-186320,-186355,-186391,-186426,-186461,-186497,-186532,-186567,-186603,-186638,-186673,-186709,-186744,-186779,-186814,-186850,-186885,-186920,-186955,-186991,-187026,-187061,-187096,-187131,-187167,-187202,-187237,-187272,-187307,-187342,-187378,-187413,-187448,-187483,-187518,-187553,-187588,-187624,-187659,-187694,-187729,-187764,-187799,-187834,-187869,-187904,-187939,-187974,-188009,-188044,-188079,-188114,-188149,-188184,-188219,-188254,-188289,-188324,-188359,-188394,-188429,-188464,-188499,-188534,-188569,-188604,-188639,-188674,-188708,-188743,-188778,-188813,-188848,-188883,-188918,-188953,-188987,-189022,-189057,-189092,-189127,-189161,-189196,-189231,-189266,-189301,-189335,-189370,-189405,-189440,-189474,-189509,-189544,-189579,-189613,-189648,-189683,-189717,-189752,-189787,-189821,-189856,-189891,-189925,-189960,-189995,-190029,-190064,-190098,-190133,-190168,-190202,-190237,-190271,-190306,-190341,-190375,-190410,-190444,-190479,-190513,-190548,-190582,-190617,-190651,-190686,-190720,-190755,-190789,-190824,-190858,-190893,-190927,-190962,-190996,-191030,-191065,-191099,-191134,-191168,-191202,-191237,-191271,-191306,-191340,-191374,-191409,-191443,-191477,-191512,-191546,-191580,-191615,-191649,-191683,-191717,-191752,-191786,-191820,-191855,-191889,-191923,-191957,-191991,-192026,-192060,-192094,-192128,-192163,-192197,-192231,-192265,-192299,-192333,-192368,-192402,-192436,-192470,-192504,-192538,-192572,-192606,-192640,-192675,-192709,-192743,-192777,-192811,-192845,-192879,-192913,-192947,-192981,-193015,-193049,-193083,-193117,-193151,-193185,-193219,-193253,-193287,-193321,-193355,-193389,-193423,-193457,-193491,-193524,-193558,-193592,-193626,-193660,-193694,-193728,-193762,-193795,-193829,-193863,-193897,-193931,-193965,-193998,-194032,-194066,-194100,-194134,-194167,-194201,-194235,-194269,-194302,-194336,-194370,-194404,-194437,-194471,-194505,-194538,-194572,-194606,-194639,-194673,-194707,-194740,-194774,-194808,-194841,-194875,-194909,-194942,-194976,-195009,-195043,-195077,-195110,-195144,-195177,-195211,-195244,-195278,-195311,-195345,-195378,-195412,-195445,-195479,-195512,-195546,-195579,-195613,-195646,-195680,-195713,-195747,-195780,-195814,-195847,-195880,-195914,-195947,-195981,-196014,-196047,-196081,-196114,-196147,-196181,-196214,-196247,-196281,-196314,-196347,-196381,-196414,-196447,-196480,-196514,-196547,-196580,-196614,-196647,-196680,-196713,-196746,-196780,-196813,-196846,-196879,-196912,-196946,-196979,-197012,-197045,-197078,-197111,-197145,-197178,-197211,-197244,-197277,-197310,-197343,-197376,-197409,-197442,-197475,-197509,-197542,-197575,-197608,-197641,-197674,-197707,-197740,-197773,-197806,-197839,-197872,-197905,-197938,-197971,-198003,-198036,-198069,-198102,-198135,-198168,-198201,-198234,-198267,-198300,-198333,-198365,-198398,-198431,-198464,-198497,-198530,-198562,-198595,-198628,-198661,-198694,-198726,-198759,-198792,-198825,-198857,-198890,-198923,-198956,-198988,-199021,-199054,-199087,-199119,-199152,-199185,-199217,-199250,-199283,-199315,-199348,-199381,-199413,-199446,-199478,-199511,-199544,-199576,-199609,-199641,-199674,-199707,-199739,-199772,-199804,-199837,-199869,-199902,-199934,-199967,-199999,-200032,-200064,-200097,-200129,-200162,-200194,-200227,-200259,-200291,-200324,-200356,-200389,-200421,-200453,-200486,-200518,-200551,-200583,-200615,-200648,-200680,-200712,-200745,-200777,-200809,-200842,-200874,-200906,-200939,-200971,-201003,-201035,-201068,-201100,-201132,-201164,-201197,-201229,-201261,-201293,-201325,-201358,-201390,-201422,-201454,-201486,-201518,-201551,-201583,-201615,-201647,-201679,-201711,-201743,-201775,-201807,-201840,-201872,-201904,-201936,-201968,-202000,-202032,-202064,-202096,-202128,-202160,-202192,-202224,-202256,-202288,-202320,-202352,-202384,-202416,-202448,-202480,-202511,-202543,-202575,-202607,-202639,-202671,-202703,-202735,-202767,-202798,-202830,-202862,-202894,-202926,-202958,-202989,-203021,-203053,-203085,-203117,-203148,-203180,-203212,-203244,-203275,-203307,-203339,-203371,-203402,-203434,-203466,-203497,-203529,-203561,-203592,-203624,-203656,-203687,-203719,-203751,-203782,-203814,-203845,-203877,-203909,-203940,-203972,-204003,-204035,-204066,-204098,-204130,-204161,-204193,-204224,-204256,-204287,-204319,-204350,-204382,-204413,-204445,-204476,-204507,-204539,-204570,-204602,-204633,-204665,-204696,-204727,-204759,-204790,-204822,-204853,-204884,-204916,-204947,-204978,-205010,-205041,-205072,-205104,-205135,-205166,-205197,-205229,-205260,-205291,-205323,-205354,-205385,-205416,-205447,-205479,-205510,-205541,-205572,-205603,-205635,-205666,-205697,-205728,-205759,-205790,-205822,-205853,-205884,-205915,-205946,-205977,-206008,-206039,-206070,-206101,-206132,-206164,-206195,-206226,-206257,-206288,-206319,-206350,-206381,-206412,-206443,-206474,-206505,-206536,-206566,-206597,-206628,-206659,-206690,-206721,-206752,-206783,-206814,-206845,-206876,-206906,-206937,-206968,-206999,-207030,-207061,-207091,-207122,-207153,-207184,-207215,-207245,-207276,-207307,-207338,-207369,-207399,-207430,-207461,-207491,-207522,-207553,-207584,-207614,-207645,-207676,-207706,-207737,-207768,-207798,-207829,-207860,-207890,-207921,-207951,-207982,-208013,-208043,-208074,-208104,-208135,-208165,-208196,-208227,-208257,-208288,-208318,-208349,-208379,-208410,-208440,-208471,-208501,-208532,-208562,-208592,-208623,-208653,-208684,-208714,-208745,-208775,-208805,-208836,-208866,-208896,-208927,-208957,-208988,-209018,-209048,-209079,-209109,-209139,-209169,-209200,-209230,-209260,-209291,-209321,-209351,-209381,-209412,-209442,-209472,-209502,-209533,-209563,-209593,-209623,-209653,-209683,-209714,-209744,-209774,-209804,-209834,-209864,-209894,-209925,-209955,-209985,-210015,-210045,-210075,-210105,-210135,-210165,-210195,-210225,-210255,-210285,-210315,-210345,-210375,-210405,-210435,-210465,-210495,-210525,-210555,-210585,-210615,-210645,-210675,-210705,-210735,-210764,-210794,-210824,-210854,-210884,-210914,-210944,-210973,-211003,-211033,-211063,-211093,-211123,-211152,-211182,-211212,-211242,-211271,-211301,-211331,-211361,-211390,-211420,-211450,-211480,-211509,-211539,-211569,-211598,-211628,-211658,-211687,-211717,-211747,-211776,-211806,-211835,-211865,-211895,-211924,-211954,-211983,-212013,-212042,-212072,-212102,-212131,-212161,-212190,-212220,-212249,-212279,-212308,-212338,-212367,-212397,-212426,-212455,-212485,-212514,-212544,-212573,-212603,-212632,-212661,-212691,-212720,-212750,-212779,-212808,-212838,-212867,-212896,-212926,-212955,-212984,-213014,-213043,-213072,-213101,-213131,-213160,-213189,-213218,-213248,-213277,-213306,-213335,-213365,-213394,-213423,-213452,-213481,-213510,-213540,-213569,-213598,-213627,-213656,-213685,-213714,-213744,-213773,-213802,-213831,-213860,-213889,-213918,-213947,-213976,-214005,-214034,-214063,-214092,-214121,-214150,-214179,-214208,-214237,-214266,-214295,-214324,-214353,-214382,-214411,-214440,-214469,-214497,-214526,-214555,-214584,-214613,-214642,-214671,-214700,-214728,-214757,-214786,-214815,-214844,-214872,-214901,-214930,-214959,-214988,-215016,-215045,-215074,-215103,-215131,-215160,-215189,-215217,-215246,-215275,-215303,-215332,-215361,-215389,-215418,-215447,-215475,-215504,-215533,-215561,-215590,-215618,-215647,-215676,-215704,-215733,-215761,-215790,-215818,-215847,-215875,-215904,-215932,-215961,-215989,-216018,-216046,-216075,-216103,-216132,-216160,-216189,-216217,-216245,-216274,-216302,-216331,-216359,-216387,-216416,-216444,-216472,-216501,-216529,-216557,-216586,-216614,-216642,-216671,-216699,-216727,-216756,-216784,-216812,-216840,-216869,-216897,-216925,-216953,-216981,-217010,-217038,-217066,-217094,-217122,-217151,-217179,-217207,-217235,-217263,-217291,-217319,-217347,-217376,-217404,-217432,-217460,-217488,-217516,-217544,-217572,-217600,-217628,-217656,-217684,-217712,-217740,-217768,-217796,-217824,-217852,-217880,-217908,-217936,-217964,-217992,-218020,-218048,-218075,-218103,-218131,-218159,-218187,-218215,-218243,-218270,-218298,-218326,-218354,-218382,-218410,-218437,-218465,-218493,-218521,-218548,-218576,-218604,-218632,-218659,-218687,-218715,-218743,-218770,-218798,-218826,-218853,-218881,-218909,-218936,-218964,-218992,-219019,-219047,-219074,-219102,-219130,-219157,-219185,-219212,-219240,-219267,-219295,-219323,-219350,-219378,-219405,-219433,-219460,-219488,-219515,-219543,-219570,-219597,-219625,-219652,-219680,-219707,-219735,-219762,-219789,-219817,-219844,-219872,-219899,-219926,-219954,-219981,-220008,-220036,-220063,-220090,-220118,-220145,-220172,-220199,-220227,-220254,-220281,-220308,-220336,-220363,-220390,-220417,-220445,-220472,-220499,-220526,-220553,-220580,-220608,-220635,-220662,-220689,-220716,-220743,-220770,-220797,-220825,-220852,-220879,-220906,-220933,-220960,-220987,-221014,-221041,-221068,-221095,-221122,-221149,-221176,-221203,-221230,-221257,-221284,-221311,-221338,-221365,-221392,-221418,-221445,-221472,-221499,-221526,-221553,-221580,-221607,-221633,-221660,-221687,-221714,-221741,-221768,-221794,-221821,-221848,-221875,-221902,-221928,-221955,-221982,-222009,-222035,-222062,-222089,-222115,-222142,-222169,-222195,-222222,-222249,-222275,-222302,-222329,-222355,-222382,-222409,-222435,-222462,-222488,-222515,-222541,-222568,-222595,-222621,-222648,-222674,-222701,-222727,-222754,-222780,-222807,-222833,-222860,-222886,-222913,-222939,-222965,-222992,-223018,-223045,-223071,-223098,-223124,-223150,-223177,-223203,-223229,-223256,-223282,-223308,-223335,-223361,-223387,-223414,-223440,-223466,-223492,-223519,-223545,-223571,-223598,-223624,-223650,-223676,-223702,-223729,-223755,-223781,-223807,-223833,-223859,-223886,-223912,-223938,-223964,-223990,-224016,-224042,-224068,-224095,-224121,-224147,-224173,-224199,-224225,-224251,-224277,-224303,-224329,-224355,-224381,-224407,-224433,-224459,-224485,-224511,-224537,-224563,-224589,-224614,-224640,-224666,-224692,-224718,-224744,-224770,-224796,-224822,-224847,-224873,-224899,-224925,-224951,-224977,-225002,-225028,-225054,-225080,-225105,-225131,-225157,-225183,-225208,-225234,-225260,-225286,-225311,-225337,-225363,-225388,-225414,-225440,-225465,-225491,-225516,-225542,-225568,-225593,-225619,-225645,-225670,-225696,-225721,-225747,-225772,-225798,-225823,-225849,-225874,-225900,-225925,-225951,-225976,-226002,-226027,-226053,-226078,-226104,-226129,-226155,-226180,-226205,-226231,-226256,-226282,-226307,-226332,-226358,-226383,-226408,-226434,-226459,-226484,-226510,-226535,-226560,-226585,-226611,-226636,-226661,-226687,-226712,-226737,-226762,-226787,-226813,-226838,-226863,-226888,-226913,-226939,-226964,-226989,-227014,-227039,-227064,-227089,-227114,-227140,-227165,-227190,-227215,-227240,-227265,-227290,-227315,-227340,-227365,-227390,-227415,-227440,-227465,-227490,-227515,-227540,-227565,-227590,-227615,-227640,-227665,-227690,-227715,-227739,-227764,-227789,-227814,-227839,-227864,-227889,-227913,-227938,-227963,-227988,-228013,-228038,-228062,-228087,-228112,-228137,-228161,-228186,-228211,-228236,-228260,-228285,-228310,-228334,-228359,-228384,-228408,-228433,-228458,-228482,-228507,-228532,-228556,-228581,-228606,-228630,-228655,-228679,-228704,-228728,-228753,-228778,-228802,-228827,-228851,-228876,-228900,-228925,-228949,-228974,-228998,-229023,-229047,-229071,-229096,-229120,-229145,-229169,-229193,-229218,-229242,-229267,-229291,-229315,-229340,-229364,-229388,-229413,-229437,-229461,-229486,-229510,-229534,-229559,-229583,-229607,-229631,-229656,-229680,-229704,-229728,-229752,-229777,-229801,-229825,-229849,-229873,-229897,-229922,-229946,-229970,-229994,-230018,-230042,-230066,-230090,-230115,-230139,-230163,-230187,-230211,-230235,-230259,-230283,-230307,-230331,-230355,-230379,-230403,-230427,-230451,-230475,-230499,-230523,-230547,-230570,-230594,-230618,-230642,-230666,-230690,-230714,-230738,-230761,-230785,-230809,-230833,-230857,-230881,-230904,-230928,-230952,-230976,-231000,-231023,-231047,-231071,-231095,-231118,-231142,-231166,-231189,-2312