aboutsummaryrefslogtreecommitdiff
path: root/pd
diff options
context:
space:
mode:
authorMiller Puckette <millerpuckette@users.sourceforge.net>2004-09-06 20:20:36 +0000
committerMiller Puckette <millerpuckette@users.sourceforge.net>2004-09-06 20:20:36 +0000
commited932acb5860bf8b9296169676499562a55d139e (patch)
treedc6a40dba908deb07c175cd40ee19c197318f72d /pd
parentdad636821f6e7d3ead02c157f308c0ceeba9af3d (diff)
checking in version 0.38test5.
Oops, I realize I forgot some more nice files, will add them and re-commit. svn path=/trunk/; revision=2010
Diffstat (limited to 'pd')
-rw-r--r--pd/doc/1.manual/1.introduction.txt6
-rw-r--r--pd/doc/1.manual/x1.htm2
-rw-r--r--pd/doc/1.manual/x2.htm2
-rw-r--r--pd/doc/1.manual/x3.htm54
-rw-r--r--pd/doc/1.manual/x5.htm43
-rw-r--r--pd/doc/2.control.examples/03.connections.pd46
-rw-r--r--pd/doc/5.reference/cpole~-help.pd119
-rw-r--r--pd/doc/5.reference/czero_rev~-help.pd142
-rw-r--r--pd/doc/5.reference/czero~-help.pd124
-rw-r--r--pd/doc/5.reference/line-help.pd17
-rw-r--r--pd/doc/5.reference/lop~-help.pd48
-rw-r--r--pd/doc/5.reference/rpole~-help.pd79
-rw-r--r--pd/doc/5.reference/rzero_rev~-help.pd81
-rw-r--r--pd/doc/5.reference/rzero~-help.pd79
-rw-r--r--pd/doc/7.stuff/tools/testtone.pd477
-rw-r--r--pd/extra/README.txt17
-rw-r--r--pd/extra/bonk~/makefile6
-rw-r--r--pd/extra/choice/help-choice.pd63
-rw-r--r--pd/extra/choice/makefile6
-rw-r--r--pd/extra/expr~/makefile6
-rw-r--r--pd/extra/expr~/vexp.c358
-rw-r--r--pd/extra/expr~/vexp_if.c20
-rw-r--r--pd/extra/fiddle~/fiddle~.c3
-rw-r--r--pd/extra/fiddle~/makefile6
-rw-r--r--pd/extra/loop~/makefile6
-rw-r--r--pd/extra/lrshift~/makefile6
-rw-r--r--pd/extra/pique/makefile6
-rw-r--r--pd/portaudio_v18/docs/index.html20
-rw-r--r--pd/portaudio_v18/docs/pa_tut_mac_osx.html28
-rw-r--r--pd/portaudio_v18/docs/portaudio_icmc2001.pdfbin49434 -> 50968 bytes
-rw-r--r--pd/portaudio_v18/pa_asio/Callback_adaptation_.pdfbin49765 -> 50527 bytes
-rw-r--r--pd/portaudio_v18/pa_asio/Pa_ASIO.pdfbin50109 -> 50778 bytes
-rw-r--r--pd/portaudio_v18/pa_asio/pa_asio.cpp38
-rw-r--r--pd/portaudio_v18/pa_mac_core/notes.txt2
-rw-r--r--pd/portaudio_v18/pa_mac_core/pa_mac_core.c95
-rw-r--r--pd/portmidi_osx/README2
-rw-r--r--pd/portmidi_osx/pmdarwin.c2
-rw-r--r--pd/portmidi_osx/pmmacosx.c2
-rw-r--r--pd/portmidi_osx/ptdarwin.c2
-rw-r--r--pd/src/CHANGELOG.txt11
-rw-r--r--pd/src/configure.in55
-rw-r--r--pd/src/configure.in.ok248
-rw-r--r--pd/src/configure.in.oops272
-rw-r--r--pd/src/configure.in.pa_v19231
-rw-r--r--pd/src/d_arithmetic.c462
-rw-r--r--pd/src/d_array.c493
-rw-r--r--pd/src/d_ctl.c458
-rw-r--r--pd/src/d_dac.c94
-rw-r--r--pd/src/d_delay.c164
-rw-r--r--pd/src/d_fft.c108
-rw-r--r--pd/src/d_fftroutine.c1288
-rw-r--r--pd/src/d_filter.c646
-rw-r--r--pd/src/d_global.c158
-rw-r--r--pd/src/d_math.c174
-rw-r--r--pd/src/d_mayer_fft.c268
-rw-r--r--pd/src/d_misc.c56
-rw-r--r--pd/src/d_osc.c214
-rw-r--r--pd/src/d_resample.c20
-rw-r--r--pd/src/d_soundfile.c2784
-rw-r--r--pd/src/d_ugen.c862
-rw-r--r--pd/src/g_all_guis.c238
-rw-r--r--pd/src/g_all_guis.h16
-rw-r--r--pd/src/g_array.c1264
-rw-r--r--pd/src/g_bang.c286
-rw-r--r--pd/src/g_canvas.c936
-rw-r--r--pd/src/g_canvas.h170
-rw-r--r--pd/src/g_editor.c2331
-rw-r--r--pd/src/g_graph.c970
-rw-r--r--pd/src/g_guiconnect.c30
-rw-r--r--pd/src/g_hdial.c564
-rw-r--r--pd/src/g_hslider.c408
-rw-r--r--pd/src/g_io.c352
-rw-r--r--pd/src/g_mycanvas.c194
-rw-r--r--pd/src/g_numbox.c716
-rw-r--r--pd/src/g_readwrite.c680
-rw-r--r--pd/src/g_rtext.c500
-rw-r--r--pd/src/g_scalar.c234
-rw-r--r--pd/src/g_template.c1340
-rw-r--r--pd/src/g_text.c981
-rw-r--r--pd/src/g_toggle.c268
-rw-r--r--pd/src/g_traversal.c448
-rw-r--r--pd/src/g_vdial.c540
-rw-r--r--pd/src/g_vslider.c382
-rw-r--r--pd/src/g_vumeter.c596
-rw-r--r--pd/src/m_atom.c96
-rw-r--r--pd/src/m_binbuf.c1626
-rw-r--r--pd/src/m_class.c613
-rw-r--r--pd/src/m_glob.c50
-rw-r--r--pd/src/m_imp.h36
-rw-r--r--pd/src/m_memory.c18
-rw-r--r--pd/src/m_obj.c333
-rw-r--r--pd/src/m_pd.c168
-rw-r--r--pd/src/m_pd.h158
-rw-r--r--pd/src/m_sched.c350
-rw-r--r--pd/src/makefile.in14
-rw-r--r--pd/src/makefile.irix190
-rw-r--r--pd/src/makefile.nt15
-rw-r--r--pd/src/notes.txt182
-rw-r--r--pd/src/s_audio.c739
-rw-r--r--pd/src/s_audio_alsa.c1298
-rw-r--r--pd/src/s_audio_alsa.h40
-rw-r--r--pd/src/s_audio_alsamm.c1359
-rw-r--r--pd/src/s_audio_jack.c354
-rw-r--r--pd/src/s_audio_mmio.c723
-rw-r--r--pd/src/s_audio_oss.c976
-rw-r--r--pd/src/s_audio_pa.c248
-rw-r--r--pd/src/s_audio_pablio.c404
-rw-r--r--pd/src/s_audio_pablio.h112
-rw-r--r--pd/src/s_audio_paring.c217
-rw-r--r--pd/src/s_audio_paring.h102
-rw-r--r--pd/src/s_audio_sgi.c460
-rw-r--r--pd/src/s_entry.c78
-rw-r--r--pd/src/s_file.c472
-rw-r--r--pd/src/s_inter.c1301
-rw-r--r--pd/src/s_loader.c66
-rw-r--r--pd/src/s_main.c1010
-rw-r--r--pd/src/s_midi.c439
-rw-r--r--pd/src/s_midi_mmio.c205
-rw-r--r--pd/src/s_midi_oss.c458
-rw-r--r--pd/src/s_midi_pm.c308
-rw-r--r--pd/src/s_midi_sgi.c169
-rw-r--r--pd/src/s_path.c477
-rw-r--r--pd/src/s_print.c116
-rw-r--r--pd/src/s_stuff.h129
-rw-r--r--pd/src/s_watchdog.c52
-rw-r--r--pd/src/t_main.c50
-rw-r--r--pd/src/t_tkcmd.c565
-rw-r--r--pd/src/u_main.tk345
-rw-r--r--pd/src/u_pdreceive.c239
-rw-r--r--pd/src/u_pdsend.c110
-rw-r--r--pd/src/x_acoustics.c34
-rw-r--r--pd/src/x_arithmetic.c128
-rw-r--r--pd/src/x_connective.c626
-rw-r--r--pd/src/x_gui.c88
-rw-r--r--pd/src/x_interface.c6
-rw-r--r--pd/src/x_midi.c424
-rw-r--r--pd/src/x_misc.c63
-rw-r--r--pd/src/x_net.c288
-rw-r--r--pd/src/x_qlist.c220
-rw-r--r--pd/src/x_time.c254
140 files changed, 25216 insertions, 19908 deletions
diff --git a/pd/doc/1.manual/1.introduction.txt b/pd/doc/1.manual/1.introduction.txt
index c8fa88a8..f9209702 100644
--- a/pd/doc/1.manual/1.introduction.txt
+++ b/pd/doc/1.manual/1.introduction.txt
@@ -8,12 +8,16 @@ Pd is copyrighted, but is free for you to use for any reasonable purpose.
See the file:
PD_BASEDIR/LICENSE.txt
-HTML documentation for Pd lives in:
+Reference documentation for Pd lives in:
file:PD_BASEDIR/doc/1.manual/index.htm
or:
http://www.crca.ucsd.edu/~msp/Pd_documentation/index.htm
+Much more documentation and other resources live on:
+ http://puredata.org
+
The Pd mailing list archive lives in:
http://iem.kug.ac.at/mailinglists/pd-list/
+
Many more useful links are listed in the HTML documentation, section 1.2.
diff --git a/pd/doc/1.manual/x1.htm b/pd/doc/1.manual/x1.htm
index e46098cd..c115a510 100644
--- a/pd/doc/1.manual/x1.htm
+++ b/pd/doc/1.manual/x1.htm
@@ -71,7 +71,7 @@ To get started writing your own C extensions, refer to chapter 4 of this manual.
<H3> <A name=s2> 1.2. other resources </A> </H3>
<P> There is a new Pd community web site,
-<a href="http://www.pure-data.org/"> pure-data.org</a>, which aims to be the
+<a href="http://www.pure-data.info/"> pure-data.info</a>, which aims to be the
central resource for Pd, from documentation and
downloads; to forums, member pages, a patch exchange.
diff --git a/pd/doc/1.manual/x2.htm b/pd/doc/1.manual/x2.htm
index 8d656a64..f68dfe0a 100644
--- a/pd/doc/1.manual/x2.htm
+++ b/pd/doc/1.manual/x2.htm
@@ -393,7 +393,7 @@ scheduler will wake the delay back up later.
2.3.3. hot and cold inlets and right to left outlet order </A> </H3>
<P> With few exceptions (notably "timer"), objects treat their leftmost
-inlet as "hot" in the sense that messages to right inlets can result in output
+inlet as "hot" in the sense that messages to left inlets can result in output
messages. So the following is a legal (and reasonable) loop construct:
<CENTER><P>
diff --git a/pd/doc/1.manual/x3.htm b/pd/doc/1.manual/x3.htm
index d432a2a9..f23e09a6 100644
--- a/pd/doc/1.manual/x3.htm
+++ b/pd/doc/1.manual/x3.htm
@@ -246,7 +246,7 @@ to file such as "pd-linux-033.tar.gz". Open a "shell"
window, cd to
the directory containing the file, and type the command,
<PRE>
- zcat pd-linux-033.tar.gz | tar xf -
+ tar xzf pd-linux-033.tar.gz
</PRE>
<P>which creates a directory named "pd". I do this from my home directory.
Next, compile it. "CD" to pd and read the INSTALL.txt, or else just cd
@@ -262,11 +262,13 @@ to "pd/src" and type
<PRE>
To enable debugging (and losing code optimization) add "--enable-debug".
- To enable ALSA 0.9x or up, add "--enable-alsa".
To use Portaudio version 19 (experimental), add "--enable-portaudio".
To put Pd in /usr/bin instead of /usr/local/bin, add "--prefix=/bin".
</PRE>
+Alsa and Jack support should auto-configure, but "--enable-alsa" od
+"--enable-jack" will force their inclusion.
+
<P> After "make", just type "~/pd/bin/pd" to run pd.
<P> Alternatively, as superuser, you can run "make install" after "make depend"
@@ -427,17 +429,14 @@ I/O ports and one SPDIF. There is a "baby hammerfall" also, which I think is
the "9632." DO NOT CONFUSE THE 9652/9632 WITH OTHER RME BOARDS WHICH MIGHT
NOT WORK WITH PD.
-<P> Hammerfalls now have an ALSA driver; aapparently, it works well to install
-this and then run Pd using OSS emulation. (Unfortunately, this will only give
-you 16 bit resolution. Maybe the also "plug" device will work better; I
-haven't tried this.)
+<P> Word on the Pd mailing list is that the only way at present (7/04) to use
+Hammerfall boards in Pd is via ALSA and jack.
<H6> MIDIMAN </H6>
<P>Midiman sells PCI devices (delta 44, 66, 1010, and 1010LT)
with between 4 and 10 channels in and out, for
-which there are ALSA drivers.
-I'm running mine in Alsa 0.9 beta 10. The driver name is "ice1712".
+which there are ALSA drivers. The driver name is "ice1712".
<P> Alsa provides an "envy24control" program (in "utils". You should run
this and check that your ice1712's sync source is internal if you have no
@@ -452,16 +451,16 @@ ALSA.
<H3> <A name="s1.3"> 3.3. Installing Pd in Macintosh OSX </A> </H3>
-<P>Pd version 0.35 and up support Macintosh OSX. You need the Jaguar
-distribution (10.2) of OSX.
+<P>Pd version 0.35 and up support Macintosh OSX. You need the OSX Jaguar
+distribution (10.2) or later.
<P> To install Pd you can always just download
the sources and compile them yourself, or (easier)
find a MacOSX-style "package". The first package was put together by Adam
Lindsay; the most current one seems to be the one by Hans
on
-<A href="http://www.pure-data.org/Members/hans/">
-http://www.pure-data.org/Members/hans/</A>.
+<A href="http://www.pure-data.info/Members/hans/">
+http://www.pure-data.info/Members/hans/</A>.
The package simply installs itself
and you needn't follow the directions below.
</P>
@@ -474,9 +473,9 @@ http://www.crca.ucsd.edu/~msp/software.html</A>
take more steps to install but are more "official". To install them:
<P> If you haven't already, first download and install Tcl/Tk; there are pointers on
-Hans's page, or try:
-<A href="http://prdownloads.sourceforge.net/tcltkaqua/">
-http://prdownloads.sourceforge.net/tcltkaqua/</A>. Double click on what you
+Hans's page, or try: http://tcltkaqua.sourceforge.net/
+<A href="http://tcltkaqua.sourceforge.net/">
+http://tcltkaqua.sourceforge.net/</A>. Double click on what you
get (a disk image opens) and then double click on the "package" icon, and the
installer should tell you how to proceed from there.
@@ -498,31 +497,10 @@ specifically in
/Applications/Wish Shell.app
and /Library/Frameworks/Tk.framework and /Library/Frameworks/Tcl.framework.
-<P> First download and install TK for OSX
-(http://sourceforge.net/projects/tcl/). Get a recent one compiled for
-OSX, by chasing through "latest file releases", and finding a "download"
-link for TCL. Then download "TclTkAqua-8.4.1-Jaguar.dmg" (the version
-number may change). Click on this file and a "folder" will open. Click
-on the "package" icon in that folder and an auto-installer will put Tcl/Tk
-on your system.
-
-<P> For old versions of Tcl/Tk you also had to get the "h" files from XFree86
-and put them in
-/usr/X11R6/include. You can download just the H files from:
-
-<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
-<CODE>
-<A HREF="http://www.crca.ucsd.edu/~msp/x.tgz">http://www.crca.ucsd.edu/~msp/x.tgz</A>
-</CODE>
-
-<P>
-(the individual files seem to have adequate copyright notices so that
-I can just redistribute them.) ((I hope this is no longer necessary but I
-notice people keep downloading these files anyway, so I'll leave them there
-a while longer until I'm sure they're not needed.))
+<P> First download and install TK for OSX as described above.
<P> Then, just as for linux, just unload pd-whatever.tar.gz into a directory
-such as ~/pd-0.35-test17 , cd to pd-0.36-0/src, type "./configure"
+such as ~/pd-0.36-0, cd to pd-0.36-0/src, type "./configure"
and "make". Then type ~/pd-0.36-0/bin/pd to a shell and enjoy!
<P> If you wish you can put a line such as,
diff --git a/pd/doc/1.manual/x5.htm b/pd/doc/1.manual/x5.htm
index ac7b6e5a..1a1b2e2f 100644
--- a/pd/doc/1.manual/x5.htm
+++ b/pd/doc/1.manual/x5.htm
@@ -20,6 +20,49 @@
<H3> <A name="s2"> 5.1. release notes </A> </H3>
+<P> ------------------ 0.37.3 --------------------------
+
+<P> Oops- added __i386__ macro to windows makefile so it would test for
+underflows correctly. This affects only Microsoft Windows; the other
+two platformas are fine as 0.37.2. Thanks to Thomas Musil...
+
+<P> ------------------ 0.37.2 --------------------------
+
+<P> fixed a bug in soundfile reading (soundfiles now default to wav better.)
+
+<P> fixed gfx update problem in hradio and vradio
+
+<P> minor changes to built-in Max import feature (but you should
+still use cyclone's instead.)
+
+<P> colors for scalars fixed (probably never worked before!)
+
+<P> added a "set" message to the line object
+
+<P> aliased spaces to underscores in GUI labels so that at least they won't
+destroy the object.
+
+<P> ------------------ 0.37.1 --------------------------
+
+<P> fixed the apple key on OSX so it does key accelerators
+
+<P> fixed bug in -inchannels/-outchannels arg parsing
+
+<P> major editions to the IEM GUIs to fix bugs in how "$" variables are handled.
+The code still isn't pretty but hopefully at least works now.
+
+<P> bug fix in vd~ for very small delays
+
+<P> fixed MSW version not to make windows grow by 2 pixels on save/restore
+
+<P> added an "nrt" flag for OSX to defeat real-time priritization
+(useful when runnig Gem.)
+
+<P> on some platforms, audio open failures are handled more gracefully.
+
+<P> added a "changelog" file in the source directory to document source-level
+changes.
+
<P> ------------------ 0.37 --------------------------
<P> Pd is finally fixed so that it can open and close audio and MIDI devices
diff --git a/pd/doc/2.control.examples/03.connections.pd b/pd/doc/2.control.examples/03.connections.pd
index 3cde81fa..97d32f82 100644
--- a/pd/doc/2.control.examples/03.connections.pd
+++ b/pd/doc/2.control.examples/03.connections.pd
@@ -1,19 +1,15 @@
#N canvas 185 28 660 552 12;
-#X floatatom 76 400 0 0 0;
-#X floatatom 189 401 0 0 0;
-#X floatatom 76 307 0 0 0;
-#X floatatom 553 161 0 0 0;
-#X floatatom 599 162 0 0 0;
+#X floatatom 76 400 0 0 0 0 - - -;
+#X floatatom 189 401 0 0 0 0 - - -;
+#X floatatom 76 307 0 0 0 0 - - -;
+#X floatatom 553 161 0 0 0 0 - - -;
+#X floatatom 599 162 0 0 0 0 - - -;
#X obj 553 135 +;
-#X floatatom 553 105 0 0 0;
+#X floatatom 553 105 0 0 0 0 - - -;
#X obj 599 136 +;
-#X text 114 16 In Pd \, most objects carry out their functions when
-they get messages in their rightmost inlets \, and their other inlets
-are for storing values that can modify the next action. Here \, the
-"+" object does its thing only when the left-hand input changes.;
-#X floatatom 26 109 0 0 0;
-#X floatatom 26 17 0 0 0;
-#X floatatom 48 41 0 0 0;
+#X floatatom 26 109 0 0 0 0 - - -;
+#X floatatom 26 17 0 0 0 0 - - -;
+#X floatatom 48 41 0 0 0 0 - - -;
#X obj 26 85 +;
#X text 3 64 hot;
#X text 53 66 cold;
@@ -40,19 +36,23 @@ when all the data are good. The "bad adder" happens to receive its
inputs in the wrong order and is perpetually doing its addition before
all the data are in. There's an object that exists solely to allow
you to control message order explicitly:;
-#X connect 2 0 22 0;
+#X text 114 16 In Pd \, most objects carry out their functions when
+they get messages in their leftmost inlets \, and their other inlets
+are for storing values that can modify the next action. Here \, the
+"+" object does its thing only when the left-hand input changes.;
+#X connect 2 0 21 0;
#X connect 5 0 3 0;
#X connect 6 0 7 0;
#X connect 6 0 7 1;
#X connect 6 0 5 1;
#X connect 6 0 5 0;
#X connect 7 0 4 0;
-#X connect 10 0 12 0;
-#X connect 11 0 12 1;
-#X connect 12 0 9 0;
-#X connect 18 0 0 0;
-#X connect 19 0 1 0;
-#X connect 22 0 18 0;
-#X connect 22 0 19 1;
-#X connect 22 1 18 1;
-#X connect 22 1 19 0;
+#X connect 9 0 11 0;
+#X connect 10 0 11 1;
+#X connect 11 0 8 0;
+#X connect 17 0 0 0;
+#X connect 18 0 1 0;
+#X connect 21 0 17 0;
+#X connect 21 0 18 1;
+#X connect 21 1 17 1;
+#X connect 21 1 18 0;
diff --git a/pd/doc/5.reference/cpole~-help.pd b/pd/doc/5.reference/cpole~-help.pd
new file mode 100644
index 00000000..e0df0339
--- /dev/null
+++ b/pd/doc/5.reference/cpole~-help.pd
@@ -0,0 +1,119 @@
+#N canvas 281 13 533 567 12;
+#X obj 54 90 osc~ 100;
+#X msg 62 117 clear;
+#X obj 79 547 lop~;
+#X text 10 550 see also:;
+#X text 333 549 updated for Pd version-0.38;
+#X obj 86 497 rzero~;
+#X obj 37 517 cpole~;
+#X obj 37 497 rpole~;
+#X obj 135 497 rzero_rev~;
+#X obj 86 517 czero~;
+#X obj 135 517 czero_rev~;
+#X text 213 497 real;
+#X text 212 518 complex;
+#X text 34 481 1-pole;
+#X text 83 481 1-zero;
+#X text 133 481 1-zero \, reversed;
+#X text 59 466 summary of raw filters:;
+#X text 73 300 y[n] = y[n-1] + a[n] * x[n];
+#X text 12 369 The transfer function is H(Z) = 1/(1 - aZ^-1).;
+#X text 106 116 <-- clear internal state to zero;
+#N canvas 168 90 498 357 test 0;
+#X obj 76 78 osc~;
+#X floatatom 76 55 5 0 0 0 - - -;
+#X obj 18 287 env~ 16384;
+#X floatatom 18 311 5 0 0 0 - - -;
+#X obj 104 107 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0
+1;
+#X obj 76 105 *~;
+#X msg 85 132 set 1;
+#X floatatom 350 112 4 -1000 1000 0 - - -;
+#X obj 215 315 dac~;
+#X obj 215 279 *~;
+#X text 80 18 Stuff to test it:;
+#X obj 241 106 cos~;
+#X obj 77 227 cpole~;
+#X obj 261 65 phasor~;
+#X floatatom 261 44 5 0 0 0 - - -;
+#X floatatom 132 55 5 0 0 0 - - -;
+#X obj 160 107 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0
+1;
+#X obj 132 105 *~;
+#X obj 132 78 phasor~;
+#X floatatom 324 42 5 0 0 0 - - -;
+#X obj 324 65 / 1000;
+#X obj 274 107 -~ 0.25;
+#X obj 274 129 cos~;
+#X obj 350 131 / 1000;
+#X obj 240 157 *~;
+#X obj 274 157 *~;
+#X obj 94 287 env~ 16384;
+#X floatatom 94 311 5 0 0 0 - - -;
+#X obj 247 275 dbtorms;
+#X floatatom 248 255 5 0 0 0 - - -;
+#X connect 0 0 5 0;
+#X connect 1 0 0 0;
+#X connect 2 0 3 0;
+#X connect 4 0 5 1;
+#X connect 5 0 12 0;
+#X connect 6 0 12 0;
+#X connect 7 0 23 0;
+#X connect 9 0 8 0;
+#X connect 9 0 8 1;
+#X connect 11 0 24 0;
+#X connect 12 0 2 0;
+#X connect 12 0 9 0;
+#X connect 12 1 26 0;
+#X connect 13 0 21 0;
+#X connect 13 0 11 0;
+#X connect 14 0 13 0;
+#X connect 15 0 18 0;
+#X connect 16 0 17 1;
+#X connect 17 0 12 0;
+#X connect 18 0 17 0;
+#X connect 19 0 20 0;
+#X connect 20 0 13 1;
+#X connect 21 0 22 0;
+#X connect 22 0 25 0;
+#X connect 23 0 25 1;
+#X connect 23 0 24 1;
+#X connect 24 0 12 2;
+#X connect 25 0 12 3;
+#X connect 26 0 27 0;
+#X connect 28 0 9 1;
+#X connect 29 0 28 0;
+#X restore 459 483 pd test;
+#X text 113 550 etc.: user-friendly filters;
+#X text 10 387 (Pd also provides a suite of user-friendly filters.
+This and other raw filters are provided for situations which the user-friendly
+ones can't handle. See Chapter 8 of http://crca.ucsd.edu/~msp/techniques
+for an introduction to the necessary theory.);
+#X obj 52 7 cpole~;
+#X text 114 7 complex one-pole (recursive) filter \, raw;
+#X text 118 91 <-- signal to filter (real part);
+#X text 117 173 <-- signal to filter (imaginary part);
+#X obj 84 172 sig~;
+#X obj 115 197 sig~;
+#X text 149 199 <-- filter coefficient (real part);
+#X obj 145 219 sig~;
+#X obj 53 244 cpole~ 0.9 0.4;
+#X text 159 246 <-- creation arguments initialize filter;
+#X text 187 262 coefficient (real and imaginary part);
+#X text 14 278 The action of cpole~ is:;
+#X text 11 320 where y[n] is the output \, x[n] the input \, and a[n]
+the filter coefficient (all complex numbers). The filter is unstable
+if/when |a[n]|>1.;
+#X text 8 31 Cpole~ filters a complex audio signal (first two inlets)
+via a one-pole filter \, whose coefficients are controlled by creation
+arguments or by another complex audio signal (remaining two inlets).
+;
+#X text 150 144 <-- set internal state (real&imaginary parts);
+#X msg 64 143 set 0.6 0.8;
+#X text 179 221 <-- filter coefficient (imaginary part);
+#X connect 0 0 31 0;
+#X connect 1 0 31 0;
+#X connect 27 0 31 1;
+#X connect 28 0 31 2;
+#X connect 30 0 31 3;
+#X connect 38 0 31 0;
diff --git a/pd/doc/5.reference/czero_rev~-help.pd b/pd/doc/5.reference/czero_rev~-help.pd
new file mode 100644
index 00000000..77b5cee6
--- /dev/null
+++ b/pd/doc/5.reference/czero_rev~-help.pd
@@ -0,0 +1,142 @@
+#N canvas 118 9 534 590 12;
+#X obj 57 106 osc~ 100;
+#X msg 65 133 clear;
+#X obj 82 563 lop~;
+#X text 13 566 see also:;
+#X text 336 565 updated for Pd version-0.38;
+#X obj 89 513 rzero~;
+#X obj 40 533 cpole~;
+#X obj 40 513 rpole~;
+#X obj 138 513 rzero_rev~;
+#X obj 89 533 czero~;
+#X obj 138 533 czero_rev~;
+#X text 216 513 real;
+#X text 215 534 complex;
+#X text 37 497 1-pole;
+#X text 86 497 1-zero;
+#X text 136 497 1-zero \, reversed;
+#X text 62 482 summary of raw filters:;
+#X text 109 132 <-- clear internal state to zero;
+#N canvas 255 257 585 372 test 0;
+#X obj 152 296 env~ 16384;
+#X floatatom 152 320 5 0 0 0 - - -;
+#X floatatom 499 76 4 -1000 1000 0 - - -;
+#X obj 349 324 dac~;
+#X obj 349 288 *~;
+#X obj 390 70 cos~;
+#X floatatom 298 8 5 0 0 0 - - -;
+#X obj 298 31 phasor~;
+#X floatatom 398 14 5 0 0 0 - - -;
+#X obj 397 39 / 1000;
+#X obj 423 71 -~ 0.25;
+#X obj 423 93 cos~;
+#X obj 499 95 / 1000;
+#X obj 389 121 *~;
+#X obj 423 121 *~;
+#X obj 228 296 env~ 16384;
+#X floatatom 228 320 5 0 0 0 - - -;
+#X obj 381 284 dbtorms;
+#X floatatom 382 264 5 0 0 0 - - -;
+#X obj 117 89 phasor~;
+#X floatatom 115 60 5 0 0 0 - - -;
+#X text 77 13 Stuff to test it:;
+#X obj 131 149 cpole~;
+#X obj 241 262 *~ -1;
+#X obj 21 261 env~ 16384;
+#X floatatom 21 285 5 0 0 0 - - -;
+#X obj 50 312 env~ 16384;
+#X floatatom 50 336 5 0 0 0 - - -;
+#X obj 138 181 cpole~;
+#X obj 146 216 czero_rev~;
+#X obj 154 264 czero_rev~;
+#X msg 204 103 clear;
+#X obj 262 50 cos~;
+#X obj 261 83 *~ 0.02;
+#X obj 193 50 sig~ 1.1;
+#X obj 448 296 *~;
+#X connect 0 0 1 0;
+#X connect 2 0 12 0;
+#X connect 4 0 3 0;
+#X connect 5 0 13 0;
+#X connect 6 0 7 0;
+#X connect 7 0 32 0;
+#X connect 8 0 9 0;
+#X connect 9 0 7 1;
+#X connect 10 0 11 0;
+#X connect 11 0 14 0;
+#X connect 12 0 14 1;
+#X connect 12 0 13 1;
+#X connect 13 0 22 2;
+#X connect 13 0 28 2;
+#X connect 13 0 29 2;
+#X connect 13 0 30 2;
+#X connect 14 0 22 3;
+#X connect 14 0 23 0;
+#X connect 14 0 29 3;
+#X connect 15 0 16 0;
+#X connect 17 0 4 1;
+#X connect 17 0 35 1;
+#X connect 18 0 17 0;
+#X connect 19 0 22 0;
+#X connect 19 0 24 0;
+#X connect 19 0 35 0;
+#X connect 20 0 19 0;
+#X connect 22 0 28 0;
+#X connect 22 1 28 1;
+#X connect 23 0 28 3;
+#X connect 23 0 30 3;
+#X connect 24 0 25 0;
+#X connect 26 0 27 0;
+#X connect 28 0 26 0;
+#X connect 28 0 29 0;
+#X connect 28 1 29 1;
+#X connect 29 0 30 0;
+#X connect 29 1 30 1;
+#X connect 30 0 0 0;
+#X connect 30 0 4 0;
+#X connect 30 1 15 0;
+#X connect 31 0 22 0;
+#X connect 31 0 28 0;
+#X connect 32 0 33 0;
+#X connect 33 0 5 0;
+#X connect 33 0 10 0;
+#X connect 34 0 33 0;
+#X connect 35 0 3 1;
+#X restore 462 499 pd test;
+#X text 116 566 etc.: user-friendly filters;
+#X text 13 403 (Pd also provides a suite of user-friendly filters.
+This and other raw filters are provided for situations which the user-friendly
+ones can't handle. See Chapter 8 of http://crca.ucsd.edu/~msp/techniques
+for an introduction to the necessary theory.);
+#X text 121 107 <-- signal to filter (real part);
+#X text 120 189 <-- signal to filter (imaginary part);
+#X obj 87 188 sig~;
+#X obj 118 213 sig~;
+#X text 152 215 <-- filter coefficient (real part);
+#X obj 148 235 sig~;
+#X text 162 262 <-- creation arguments initialize filter;
+#X text 190 278 coefficient (real and imaginary part);
+#X text 153 160 <-- set internal state (real&imaginary parts);
+#X msg 67 159 set 0.6 0.8;
+#X text 182 237 <-- filter coefficient (imaginary part);
+#X text 17 295 The action of czero~ is:;
+#X text 14 336 where y[n] is the output \, x[n] the input \, and a[n]
+the filter coefficient (all complex numbers). The filter is always
+stable.;
+#X obj 56 260 czero~ 0.9 0.4;
+#X obj 36 7 czero_rev~;
+#X text 114 9 complex one-zero (non-recursive) "reverse" filter \,
+raw;
+#X text 11 34 Czero_rev~ filters a complex audio signal (first two
+inlets) via a one-zero filter \, whose coefficients are controlled
+by creation arguments or by another complex audio signal (remaining
+two inlets). The impulse response is that of "rzero" reversed in time.
+;
+#X text 77 316 y[n] = - a[n] * x[n] + x[n-1];
+#X text 15 385 The transfer function is H(Z) = -a + Z^-1.;
+#X connect 0 0 34 0;
+#X connect 1 0 34 0;
+#X connect 23 0 34 1;
+#X connect 24 0 34 2;
+#X connect 26 0 34 3;
+#X connect 30 0 34 0;
diff --git a/pd/doc/5.reference/czero~-help.pd b/pd/doc/5.reference/czero~-help.pd
new file mode 100644
index 00000000..58dab9cc
--- /dev/null
+++ b/pd/doc/5.reference/czero~-help.pd
@@ -0,0 +1,124 @@
+#N canvas 79 19 533 567 12;
+#X obj 54 90 osc~ 100;
+#X msg 62 117 clear;
+#X obj 79 547 lop~;
+#X text 10 550 see also:;
+#X text 333 549 updated for Pd version-0.38;
+#X obj 86 497 rzero~;
+#X obj 37 517 cpole~;
+#X obj 37 497 rpole~;
+#X obj 135 497 rzero_rev~;
+#X obj 86 517 czero~;
+#X obj 135 517 czero_rev~;
+#X text 213 497 real;
+#X text 212 518 complex;
+#X text 34 481 1-pole;
+#X text 83 481 1-zero;
+#X text 133 481 1-zero \, reversed;
+#X text 59 466 summary of raw filters:;
+#X text 106 116 <-- clear internal state to zero;
+#N canvas 255 257 585 372 test 0;
+#X obj 152 296 env~ 16384;
+#X floatatom 152 320 5 0 0 0 - - -;
+#X floatatom 484 121 4 -1000 1000 0 - - -;
+#X obj 349 324 dac~;
+#X obj 349 288 *~;
+#X obj 375 115 cos~;
+#X floatatom 301 60 5 0 0 0 - - -;
+#X obj 329 112 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0
+1;
+#X obj 301 110 *~;
+#X obj 301 83 phasor~;
+#X floatatom 382 66 5 0 0 0 - - -;
+#X obj 382 89 / 1000;
+#X obj 408 116 -~ 0.25;
+#X obj 408 138 cos~;
+#X obj 484 140 / 1000;
+#X obj 374 166 *~;
+#X obj 408 166 *~;
+#X obj 228 296 env~ 16384;
+#X floatatom 228 320 5 0 0 0 - - -;
+#X obj 381 284 dbtorms;
+#X floatatom 382 264 5 0 0 0 - - -;
+#X obj 245 220 czero~;
+#X floatatom 201 132 4 -1000 1000 0 - - -;
+#X obj 92 126 cos~;
+#X obj 112 85 phasor~;
+#X floatatom 115 60 5 0 0 0 - - -;
+#X obj 125 127 -~ 0.25;
+#X obj 125 149 cos~;
+#X obj 201 151 / 1000;
+#X obj 91 177 *~;
+#X obj 125 177 *~;
+#X text 214 27 Stuff to test it:;
+#X connect 0 0 1 0;
+#X connect 2 0 14 0;
+#X connect 4 0 3 0;
+#X connect 4 0 3 1;
+#X connect 5 0 15 0;
+#X connect 6 0 9 0;
+#X connect 7 0 8 1;
+#X connect 8 0 21 0;
+#X connect 9 0 8 0;
+#X connect 10 0 11 0;
+#X connect 11 0 5 0;
+#X connect 11 0 12 0;
+#X connect 12 0 13 0;
+#X connect 13 0 16 0;
+#X connect 14 0 16 1;
+#X connect 14 0 15 1;
+#X connect 15 0 21 2;
+#X connect 16 0 21 3;
+#X connect 17 0 18 0;
+#X connect 19 0 4 1;
+#X connect 20 0 19 0;
+#X connect 21 0 0 0;
+#X connect 21 0 4 0;
+#X connect 21 1 17 0;
+#X connect 22 0 28 0;
+#X connect 23 0 29 0;
+#X connect 24 0 26 0;
+#X connect 24 0 23 0;
+#X connect 25 0 24 0;
+#X connect 26 0 27 0;
+#X connect 27 0 30 0;
+#X connect 28 0 30 1;
+#X connect 28 0 29 1;
+#X connect 29 0 21 0;
+#X connect 30 0 21 1;
+#X restore 459 483 pd test;
+#X text 113 550 etc.: user-friendly filters;
+#X text 10 387 (Pd also provides a suite of user-friendly filters.
+This and other raw filters are provided for situations which the user-friendly
+ones can't handle. See Chapter 8 of http://crca.ucsd.edu/~msp/techniques
+for an introduction to the necessary theory.);
+#X text 118 91 <-- signal to filter (real part);
+#X text 117 173 <-- signal to filter (imaginary part);
+#X obj 84 172 sig~;
+#X obj 115 197 sig~;
+#X text 149 199 <-- filter coefficient (real part);
+#X obj 145 219 sig~;
+#X text 159 246 <-- creation arguments initialize filter;
+#X text 187 262 coefficient (real and imaginary part);
+#X text 150 144 <-- set internal state (real&imaginary parts);
+#X msg 64 143 set 0.6 0.8;
+#X obj 52 7 czero~;
+#X text 112 7 complex one-zero (non-recursive) filter \, raw;
+#X text 8 31 Czero~ filters a complex audio signal (first two inlets)
+via a one-zero filter \, whose coefficients are controlled by creation
+arguments or by another complex audio signal (remaining two inlets).
+;
+#X text 179 221 <-- filter coefficient (imaginary part);
+#X text 14 279 The action of czero~ is:;
+#X text 73 300 y[n] = x[n] - a[n] * x[n-1];
+#X text 11 320 where y[n] is the output \, x[n] the input \, and a[n]
+the filter coefficient (all complex numbers). The filter is always
+stable.;
+#X text 12 369 The transfer function is H(Z) = 1 - aZ^-1.;
+#X obj 53 244 czero~ 0.9 0.4;
+#X connect 0 0 39 0;
+#X connect 1 0 39 0;
+#X connect 23 0 39 1;
+#X connect 24 0 39 2;
+#X connect 26 0 39 3;
+#X connect 30 0 39 0;
diff --git a/pd/doc/5.reference/line-help.pd b/pd/doc/5.reference/line-help.pd
index fd0c02d4..f5d5ad38 100644
--- a/pd/doc/5.reference/line-help.pd
+++ b/pd/doc/5.reference/line-help.pd
@@ -1,10 +1,10 @@
#N canvas 31 15 669 403 12;
#X floatatom 22 339 0 0 0 0 - - -;
-#X msg 31 232 0 1000;
-#X msg 46 254 39;
+#X msg 31 205 0 1000;
+#X msg 46 227 39;
#X obj 66 15 line;
#X text 106 14 - ramp generator;
-#X msg 22 209 1 1000;
+#X msg 22 182 1 1000;
#X text 18 36 The line object takes (target \, time) pairs and slews
to the specified target over the time given \, updating its output
at a "grain rate" given by the creation argument. If you dont' specify
@@ -14,19 +14,22 @@ a float causes a jump in the output regardless of whatever time value
was specified in some previous message. If the line object receives
a message specifying some new target before reaching the previous one
\, it takes off from its current value.;
-#X text 93 221 send a pair to ramp to a new value;
-#X text 105 251 send a single number to jump;
+#X text 93 194 send a pair to ramp to a new value;
+#X text 105 224 send a single number to jump;
#X text 46 363 see also:;
#X obj 132 361 line~;
-#X msg 57 279 stop;
-#X text 98 278 "stop" message to stop output;
+#X msg 57 252 stop;
+#X text 98 251 "stop" message to stop output;
#X obj 22 313 line 0 100;
#X text 383 369 updated for Pd version 0.37;
#X text 125 310 creation arguments:;
#X text 316 310 1 initial value;
#X text 318 330 2 time grain in milliseconds;
+#X msg 51 282 set 5;
+#X text 99 282 "set" to change value (and stop) without output;
#X connect 1 0 13 0;
#X connect 2 0 13 0;
#X connect 5 0 13 0;
#X connect 11 0 13 0;
#X connect 13 0 0 0;
+#X connect 18 0 13 0;
diff --git a/pd/doc/5.reference/lop~-help.pd b/pd/doc/5.reference/lop~-help.pd
index 9f3e85f8..92b5ed22 100644
--- a/pd/doc/5.reference/lop~-help.pd
+++ b/pd/doc/5.reference/lop~-help.pd
@@ -1,31 +1,37 @@
-#N canvas 402 99 566 329 12;
+#N canvas 390 359 566 329 12;
#X obj 70 228 env~;
-#X floatatom 70 248;
-#X floatatom 107 178;
-#X obj 70 206 hip~ 5;
-#X text 119 201 The high pass filter is initialized to cutoff frequencies below 5 Hz.;
+#X floatatom 70 248 0 0 0 0 - - -;
+#X floatatom 107 178 0 0 0 0 - - -;
#X obj 12 226 env~;
-#X floatatom 12 245;
-#X text 108 227 env~ gives the amplitude of the signal envelop in dB.;
-#X floatatom 12 107;
-#X msg 452 24 \; pd dsp 1;
-#X msg 452 58 \; pd dsp 0;
+#X floatatom 12 245 0 0 0 0 - - -;
+#X floatatom 12 107 0 0 0 0 - - -;
#X obj 83 6 lop~;
-#X text 9 68 The left inlet is the incoming audio signal. The right inlet is the cutoff frequency in Hz.;
+#X text 9 68 The left inlet is the incoming audio signal. The right
+inlet is the cutoff frequency in Hz.;
#X obj 12 130 osc~ 100;
#X text 57 105 <-- scroll to change input frequency;
-#X text 12 266 Compare the value of the original signal on the left with the value of the filtered signal on the right.;
-#X text 8 35 lop~ is a one-pole low pass filter with a specified rolloff frequency.;
+#X text 8 35 lop~ is a one-pole low pass filter with a specified rolloff
+frequency.;
#X text 114 7 - one-pole low pass filter;
#X msg 70 154 clear;
#X text 114 153 <-- reinitialize internal state;
#X text 139 179 <-- set cutoff frequency;
-#X text 364 306 updated for Pd version-0.30;
+#X obj 70 206 lop~ 5;
+#X text 121 209 The filter is initialized to cut off frequencies above
+5 Hz.;
+#X text 12 266 Compare the strength of the original signal on the left
+with that of the filtered signal on the right.;
+#X text 104 228 env~ gives the amplitude of the signal in dB.;
+#X text 8 305 see also:;
+#X obj 77 304 hip~;
+#X obj 112 304 bp~;
+#X obj 139 304 vcf~;
+#X text 364 306 updated for Pd version-0.38;
#X connect 0 0 1 0;
-#X connect 2 0 3 1;
-#X connect 3 0 0 0;
-#X connect 5 0 6 0;
-#X connect 8 0 13 0;
-#X connect 13 0 5 0;
-#X connect 13 0 3 0;
-#X connect 18 0 3 0;
+#X connect 2 0 15 1;
+#X connect 3 0 4 0;
+#X connect 5 0 8 0;
+#X connect 8 0 3 0;
+#X connect 8 0 15 0;
+#X connect 12 0 15 0;
+#X connect 15 0 0 0;
diff --git a/pd/doc/5.reference/rpole~-help.pd b/pd/doc/5.reference/rpole~-help.pd
new file mode 100644
index 00000000..07d50267
--- /dev/null
+++ b/pd/doc/5.reference/rpole~-help.pd
@@ -0,0 +1,79 @@
+#N canvas 56 7 526 510 12;
+#X floatatom 118 172 0 0 0 0 - - -;
+#X obj 54 85 osc~ 100;
+#X msg 69 117 clear;
+#X obj 77 483 lop~;
+#X text 8 483 see also:;
+#X obj 52 7 rpole~;
+#X text 114 7 real one-pole (recursive) filter \, raw;
+#X text 8 35 Rpole~ filters an audio signal (left inlet) via a one-pole
+real filter \, whose coefficient is controlled by a creation argument
+or by an audio signal (right inlet).;
+#X text 331 482 updated for Pd version-0.38;
+#X obj 84 430 rzero~;
+#X obj 35 450 cpole~;
+#X obj 35 430 rpole~;
+#X obj 133 430 rzero_rev~;
+#X obj 84 450 czero~;
+#X obj 133 450 czero_rev~;
+#X text 211 430 real;
+#X text 210 451 complex;
+#X text 32 414 1-pole;
+#X text 81 414 1-zero;
+#X text 131 414 1-zero \, reversed;
+#X text 57 399 summary of raw filters:;
+#X msg 71 143 set 1;
+#X text 117 143 <-- set internal state;
+#X text 118 86 <-- signal to filter;
+#X text 142 173 <-- filter coefficient (may be a signal);
+#X text 129 198 <-- creation argument initializes filter coefficient
+;
+#X text 73 252 y[n] = y[n-1] + a[n] * x[n];
+#X text 10 302 The transfer function is H(Z) = 1/(1 - aZ^-1).;
+#X text 113 116 <-- clear internal state to zero;
+#X text 8 270 where y[n] is the output \, x[n] the input \, and a[n]
+the filter coefficient. The filter is unstable if/when |a[n]|>1.;
+#X obj 53 195 rpole~ 0.9;
+#X text 14 230 The action of rpole~ is:;
+#N canvas 393 91 326 287 test 0;
+#X obj 76 78 osc~;
+#X floatatom 76 55 5 0 0 0 - - -;
+#X obj 77 219 env~ 16384;
+#X floatatom 77 243 5 0 0 0 - - -;
+#X obj 76 168 rpole~;
+#X obj 104 107 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0
+1;
+#X obj 76 105 *~;
+#X msg 97 137 set 1;
+#X floatatom 172 157 4 -100 100 0 - - -;
+#X obj 172 182 / 100;
+#X obj 214 256 dac~;
+#X obj 228 177 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0
+1;
+#X obj 214 220 *~;
+#X obj 230 197 / 10;
+#X text 80 18 Stuff to test it:;
+#X connect 0 0 6 0;
+#X connect 1 0 0 0;
+#X connect 2 0 3 0;
+#X connect 4 0 2 0;
+#X connect 4 0 12 0;
+#X connect 5 0 6 1;
+#X connect 6 0 4 0;
+#X connect 7 0 4 0;
+#X connect 8 0 9 0;
+#X connect 9 0 4 1;
+#X connect 11 0 13 0;
+#X connect 12 0 10 0;
+#X connect 12 0 10 1;
+#X connect 13 0 12 1;
+#X restore 457 416 pd test;
+#X text 111 483 etc.: user-friendly filters;
+#X text 8 320 (Pd also provides a suite of user-friendly filters. This
+and other raw filters are provided for situations which the user-friendly
+ones can't handle. See Chapter 8 of http://crca.ucsd.edu/~msp/techniques
+for an introduction to the necessary theory.);
+#X connect 0 0 30 1;
+#X connect 1 0 30 0;
+#X connect 2 0 30 0;
+#X connect 21 0 30 0;
diff --git a/pd/doc/5.reference/rzero_rev~-help.pd b/pd/doc/5.reference/rzero_rev~-help.pd
new file mode 100644
index 00000000..ae85dcea
--- /dev/null
+++ b/pd/doc/5.reference/rzero_rev~-help.pd
@@ -0,0 +1,81 @@
+#N canvas 717 52 526 510 12;
+#X floatatom 127 186 0 0 0 0 - - -;
+#X obj 49 98 osc~ 100;
+#X msg 64 130 clear;
+#X obj 77 483 lop~;
+#X text 8 483 see also:;
+#X text 331 482 updated for Pd version-0.38;
+#X obj 84 430 rzero~;
+#X obj 35 450 cpole~;
+#X obj 35 430 rpole~;
+#X obj 133 430 rzero_rev~;
+#X obj 84 450 czero~;
+#X obj 133 450 czero_rev~;
+#X text 211 430 real;
+#X text 210 451 complex;
+#X text 32 414 1-pole;
+#X text 81 414 1-zero;
+#X text 131 414 1-zero \, reversed;
+#X text 57 399 summary of raw filters:;
+#X msg 66 156 set 1;
+#X text 112 156 <-- set internal state;
+#X text 113 99 <-- signal to filter;
+#X text 155 189 <-- filter coefficient (may be a signal);
+#X text 143 210 <-- creation argument initializes filter coefficient
+;
+#X text 108 129 <-- clear internal state to zero;
+#N canvas 393 91 326 287 test 0;
+#X obj 76 78 osc~;
+#X floatatom 76 55 5 0 0 0 - - -;
+#X obj 77 219 env~ 16384;
+#X floatatom 77 243 5 0 0 0 - - -;
+#X obj 104 107 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0
+1;
+#X obj 76 105 *~;
+#X msg 97 137 set 1;
+#X floatatom 172 157 4 -100 100 0 - - -;
+#X obj 172 182 / 100;
+#X obj 214 256 dac~;
+#X obj 228 177 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0
+1;
+#X obj 214 220 *~;
+#X obj 230 197 / 10;
+#X text 80 18 Stuff to test it:;
+#X obj 76 168 rzero_rev~;
+#X connect 0 0 5 0;
+#X connect 1 0 0 0;
+#X connect 2 0 3 0;
+#X connect 4 0 5 1;
+#X connect 5 0 14 0;
+#X connect 6 0 14 0;
+#X connect 7 0 8 0;
+#X connect 8 0 14 1;
+#X connect 10 0 12 0;
+#X connect 11 0 9 0;
+#X connect 11 0 9 1;
+#X connect 12 0 11 1;
+#X connect 14 0 2 0;
+#X connect 14 0 11 0;
+#X restore 457 416 pd test;
+#X text 111 483 etc.: user-friendly filters;
+#X text 8 270 where y[n] is the output \, x[n] the input \, and a[n]
+the filter coefficient. The filter is always stable.;
+#X obj 52 7 rzero_rev~;
+#X text 139 7 real one-zero (non-recursive) "reverse" filter \, raw
+;
+#X obj 48 208 rzero_rev~ 1;
+#X text 7 35 Rzero_rev~ filters an audio signal (left inlet) via a
+one-zero real filter \, whose coefficient is controlled by a creation
+argument or by an audio signal (right inlet). The impulse response
+is that of "rzero" reversed in time.;
+#X text 14 230 The action of rpole_rev~ is:;
+#X text 71 251 y[n] = -a[n] * x[n] + x[n-1];
+#X text 6 302 The transfer function is H(Z) = -a + Z^-1.;
+#X text 5 321 (Pd also provides a suite of user-friendly filters. This
+and other raw filters are provided for situations which the user-friendly
+ones can't handle. See Chapter 8 of http://crca.ucsd.edu/~msp/techniques
+for an introduction to the necessary theory.);
+#X connect 0 0 29 1;
+#X connect 1 0 29 0;
+#X connect 2 0 29 0;
+#X connect 18 0 29 0;
diff --git a/pd/doc/5.reference/rzero~-help.pd b/pd/doc/5.reference/rzero~-help.pd
new file mode 100644
index 00000000..c2200371
--- /dev/null
+++ b/pd/doc/5.reference/rzero~-help.pd
@@ -0,0 +1,79 @@
+#N canvas 56 7 526 510 12;
+#X floatatom 104 172 0 0 0 0 - - -;
+#X obj 54 85 osc~ 100;
+#X msg 69 117 clear;
+#X obj 77 483 lop~;
+#X text 8 483 see also:;
+#X text 331 482 updated for Pd version-0.38;
+#X obj 84 430 rzero~;
+#X obj 35 450 cpole~;
+#X obj 35 430 rpole~;
+#X obj 133 430 rzero_rev~;
+#X obj 84 450 czero~;
+#X obj 133 450 czero_rev~;
+#X text 211 430 real;
+#X text 210 451 complex;
+#X text 32 414 1-pole;
+#X text 81 414 1-zero;
+#X text 131 414 1-zero \, reversed;
+#X text 57 399 summary of raw filters:;
+#X msg 71 143 set 1;
+#X text 117 143 <-- set internal state;
+#X text 118 86 <-- signal to filter;
+#X text 128 173 <-- filter coefficient (may be a signal);
+#X text 115 198 <-- creation argument initializes filter coefficient
+;
+#X text 113 116 <-- clear internal state to zero;
+#X text 14 230 The action of rpole~ is:;
+#N canvas 393 91 326 287 test 0;
+#X obj 76 78 osc~;
+#X floatatom 76 55 5 0 0 0 - - -;
+#X obj 77 219 env~ 16384;
+#X floatatom 77 243 5 0 0 0 - - -;
+#X obj 104 107 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0
+1;
+#X obj 76 105 *~;
+#X msg 97 137 set 1;
+#X floatatom 172 157 4 -100 100 0 - - -;
+#X obj 172 182 / 100;
+#X obj 214 256 dac~;
+#X obj 228 177 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0
+1;
+#X obj 214 220 *~;
+#X obj 230 197 / 10;
+#X text 80 18 Stuff to test it:;
+#X obj 76 168 rzero~;
+#X connect 0 0 5 0;
+#X connect 1 0 0 0;
+#X connect 2 0 3 0;
+#X connect 4 0 5 1;
+#X connect 5 0 14 0;
+#X connect 6 0 14 0;
+#X connect 7 0 8 0;
+#X connect 8 0 14 1;
+#X connect 10 0 12 0;
+#X connect 11 0 9 0;
+#X connect 11 0 9 1;
+#X connect 12 0 11 1;
+#X connect 14 0 2 0;
+#X connect 14 0 11 0;
+#X restore 457 416 pd test;
+#X text 111 483 etc.: user-friendly filters;
+#X obj 52 7 rzero~;
+#X text 114 7 real one-zero (non-recursive) filter \, raw;
+#X text 8 35 Rzero~ filters an audio signal (left inlet) via a one-zero
+real filter \, whose coefficient is controlled by a creation argument
+or by an audio signal (right inlet).;
+#X obj 53 195 rzero~ 1;
+#X text 8 270 where y[n] is the output \, x[n] the input \, and a[n]
+the filter coefficient. The filter is always stable.;
+#X text 10 302 The transfer function is H(Z) = 1 - aZ^-1.;
+#X text 73 252 y[n] = x[n] - a[n] * x[n-1];
+#X text 8 320 (Pd also provides a suite of user-friendly filters. This
+and other raw filters are provided for situations which the user-friendly
+ones can't handle. See Chapter 8 of http://crca.ucsd.edu/~msp/techniques
+for an introduction to the necessary theory.);
+#X connect 0 0 30 1;
+#X connect 1 0 30 0;
+#X connect 2 0 30 0;
+#X connect 18 0 30 0;
diff --git a/pd/doc/7.stuff/tools/testtone.pd b/pd/doc/7.stuff/tools/testtone.pd
index 80e4e475..30ed70cc 100644
--- a/pd/doc/7.stuff/tools/testtone.pd
+++ b/pd/doc/7.stuff/tools/testtone.pd
@@ -1,4 +1,4 @@
-#N canvas 137 26 581 402 12;
+#N canvas 182 142 581 402 12;
#X floatatom 83 307 3 0 0 0 - - -;
#X obj 33 257 notein;
#X obj 33 283 stripnote;
@@ -55,24 +55,22 @@ started" in the Help menu.;
#X connect 15 0 11 0;
#X connect 21 0 20 0;
#X restore 236 308 pd midi;
-#X floatatom 149 183 3 0 0 0 - - -;
-#X floatatom 182 183 3 0 0 0 - - -;
+#X floatatom 139 185 3 0 0 0 - - -;
+#X floatatom 172 185 3 0 0 0 - - -;
#X text 24 341 PD is COPYRIGHT 1997-2002 by Miller Puckette and others
but is free for you to use for any reasonable purpose. See the file
\, LICENSE.txt in the distribution.;
-#X obj 145 115 tgl 20 0 tone-ch1 tone-ch1 1 5 -8 0 12 -262144 -1 -1
-0 1;
-#X obj 170 115 tgl 20 0 tone-ch2 tone-ch2 2 5 -8 0 12 -262144 -1 -1
-0 1;
+#X obj 135 117 tgl 20 0 tone-ch1 tone-ch1 1 5 -8 0 12 -262144 -1 -1
+1 1;
+#X obj 160 117 tgl 20 0 tone-ch2 tone-ch2 2 5 -8 0 12 -262144 -1 -1
+1 1;
#X obj 236 282 tgl 20 0 empty empty empty 20 8 0 8 -262144 -1 -1 0
1;
#X obj 394 110 tgl 20 0 tone-monitor set-tone-monitor monitor 25 10
0 12 -262144 -1 -1 0 1;
-#X obj 36 132 vdl 20 1 0 3 tone-radio set-tone-radio empty 20 8 192
-8 -262144 -1 -1 2;
-#X text 62 177 OFF;
-#X text 62 154 -40;
-#X text 62 131 -20;
+#X text 70 137 OFF;
+#X text 67 121 -40;
+#X text 67 103 -20;
#N canvas 0 0 536 251 more 0;
#X floatatom 42 209 0 0 0 0 - - -;
#X obj 42 183 f;
@@ -94,263 +92,300 @@ but is free for you to use for any reasonable purpose. See the file
#X restore 459 298 pd more;
#X obj 393 148 tgl 20 0 tone-hipass set-tone-hipass input-hipass 25
10 0 12 -262144 -1 -1 0 1;
-#X obj 195 115 tgl 20 0 tone-ch3 tone-ch3 3 5 -8 0 12 -262144 -1 -1
-0 1;
-#X obj 220 115 tgl 20 0 tone-ch4 tone-ch4 4 5 -8 0 12 -262144 -1 -1
-0 1;
-#X obj 245 115 tgl 20 0 tone-ch5 tone-ch5 5 5 -8 0 12 -262144 -1 -1
-0 1;
-#X obj 270 115 tgl 20 0 tone-ch6 tone-ch6 6 5 -8 0 12 -262144 -1 -1
-0 1;
-#X obj 304 106 bng 15 250 50 0 tone-all empty ALL 20 8 0 12 -262144
+#X obj 185 117 tgl 20 0 tone-ch3 tone-ch3 3 5 -8 0 12 -262144 -1 -1
+1 1;
+#X obj 210 117 tgl 20 0 tone-ch4 tone-ch4 4 5 -8 0 12 -262144 -1 -1
+1 1;
+#X obj 235 117 tgl 20 0 tone-ch5 tone-ch5 5 5 -8 0 12 -262144 -1 -1
+1 1;
+#X obj 260 117 tgl 20 0 tone-ch6 tone-ch6 6 5 -8 0 12 -262144 -1 -1
+1 1;
+#X obj 294 108 bng 15 250 50 0 tone-all empty ALL 20 8 0 12 -262144
-1 -1;
-#X obj 304 127 bng 15 250 50 0 tone-none empty NONE 20 8 0 12 -262144
+#X obj 294 129 bng 15 250 50 0 tone-none empty NONE 20 8 0 12 -262144
-1 -1;
-#X floatatom 215 183 3 0 0 0 - - -;
-#X floatatom 248 183 3 0 0 0 - - -;
-#X floatatom 281 184 3 0 0 0 - - -;
-#X floatatom 315 184 3 0 0 0 - - -;
-#X text 164 208 AUDIO INPUT (RMS dB);
-#X text 41 83 TEST;
-#X text 40 103 TONE;
-#X text 152 76 test tone channels:;
-#N canvas 54 126 908 548 -------audio---- 0;
-#X obj 23 351 *~;
-#X obj 45 324 line~;
-#X obj 190 169 outlet;
-#X obj 45 297 pack 0 50;
-#X obj 22 134 osc~;
-#X floatatom 45 245 0 0 0 0 - - -;
-#X obj 45 270 dbtorms;
-#X obj 190 143 int;
-#X obj 22 66 mtof;
-#X floatatom 22 43 0 0 0 0 - - -;
-#X floatatom 22 88 0 0 0 0 - - -;
-#X obj 22 110 sig~;
-#X obj 190 117 env~ 8192;
-#X obj 182 39 adc~ 1;
-#X obj 23 377 s~ tone-osc;
-#X obj 45 162 r tone-radio;
-#X obj 22 18 r tone-pitch;
-#X obj 45 190 sel 0 1 2;
-#X msg 114 213 0;
-#X msg 45 215 80;
-#X msg 78 215 60;
-#X obj 192 192 r~ tone-mon;
-#X obj 201 327 line~;
-#X obj 182 217 *~;
-#X obj 201 274 r tone-ch1;
-#X obj 192 247 r~ tone-osc;
-#X obj 192 352 *~;
-#X obj 182 407 dac~ 1;
-#X obj 182 382 +~;
-#X obj 190 65 r tone-hip;
-#X obj 16 487 s~ tone-mon;
-#X obj 16 461 line~;
-#X obj 17 433 pack 0 50;
-#X obj 17 407 r tone-monitor;
-#X obj 310 168 outlet;
-#X obj 310 142 int;
-#X obj 310 116 env~ 8192;
-#X obj 312 191 r~ tone-mon;
-#X obj 321 326 line~;
-#X obj 302 216 *~;
-#X obj 312 246 r~ tone-osc;
-#X obj 312 351 *~;
-#X obj 302 381 +~;
-#X obj 310 64 r tone-hip;
-#X obj 302 38 adc~ 2;
-#X obj 302 406 dac~ 2;
-#X obj 321 273 r tone-ch2;
-#X obj 177 485 * 5;
-#X obj 177 510 s tone-hip;
-#X obj 179 459 r tone-hipass;
+#X floatatom 205 185 3 0 0 0 - - -;
+#X floatatom 238 185 3 0 0 0 - - -;
+#X floatatom 271 186 3 0 0 0 - - -;
+#X floatatom 305 186 3 0 0 0 - - -;
+#X text 154 210 AUDIO INPUT (RMS dB);
+#X text 45 62 TEST;
+#N canvas 162 353 903 462 -------audio---- 0;
+#X obj 186 95 hip~ 5;
+#X obj 194 172 outlet;
+#X obj 194 146 int;
+#X obj 194 120 env~ 8192;
+#X obj 186 42 adc~ 1;
+#X obj 196 195 r~ tone-mon;
+#X obj 205 330 line~;
+#X obj 186 220 *~;
+#X obj 205 303 pack 0 50;
+#X obj 205 277 r tone-ch1;
+#X obj 196 250 r~ tone-osc;
+#X obj 196 355 *~;
+#X obj 186 410 dac~ 1;
+#X obj 186 385 +~;
+#X obj 194 68 r tone-hip;
+#X obj 25 303 s~ tone-mon;
+#X obj 25 277 line~;
+#X obj 25 249 pack 0 50;
+#X obj 25 223 r tone-monitor;
+#X obj 306 94 hip~ 5;
+#X obj 314 171 outlet;
+#X obj 314 145 int;
+#X obj 314 119 env~ 8192;
+#X obj 316 194 r~ tone-mon;
+#X obj 325 329 line~;
+#X obj 306 219 *~;
+#X obj 325 302 pack 0 50;
+#X obj 316 249 r~ tone-osc;
+#X obj 316 354 *~;
+#X obj 306 384 +~;
+#X obj 314 67 r tone-hip;
+#X obj 306 41 adc~ 2;
+#X obj 306 409 dac~ 2;
+#X obj 325 276 r tone-ch2;
+#X obj 28 140 * 5;
+#X obj 28 165 s tone-hip;
+#X obj 28 114 r tone-hipass;
#N canvas 499 63 548 519 glue+loadbang 0;
#X obj 171 21 loadbang;
-#X msg 171 49 \; pd dsp 1 \; tone-pitch 69 \; tone-radio 2 \; set-tone-radio
-2 \; tone-all 1 \;;
#X obj 171 176 r tone-all;
#X msg 171 204 \; tone-ch1 1 \; tone-ch2 1 \; tone-ch3 1 \; tone-ch4
1 \; tone-ch5 1 \; tone-ch6 1;
#X obj 168 323 r tone-none;
#X msg 168 352 \; tone-ch1 0 \; tone-ch2 0 \; tone-ch3 0 \; tone-ch4
0 \; tone-ch5 0 \; tone-ch6 0;
-#X connect 0 0 1 0;
-#X connect 2 0 3 0;
-#X connect 4 0 5 0;
-#X restore 14 516 pd glue+loadbang;
-#X obj 432 170 outlet;
-#X obj 432 144 int;
-#X obj 432 118 env~ 8192;
-#X obj 434 193 r~ tone-mon;
-#X obj 443 328 line~;
-#X obj 424 218 *~;
-#X obj 434 248 r~ tone-osc;
-#X obj 434 353 *~;
-#X obj 424 383 +~;
-#X obj 432 66 r tone-hip;
+#X msg 171 49 \; pd dsp 1 \; tone-pitch 69 \; tone-radio 2 \; tone-radio-set
+2 \; tone-type 1 \; tone-type-set 1 \; tone-all 1 \;;
+#X connect 0 0 5 0;
+#X connect 1 0 2 0;
+#X connect 3 0 4 0;
+#X restore 22 332 pd glue+loadbang;
+#X obj 428 96 hip~ 5;
+#X obj 436 173 outlet;
+#X obj 436 147 int;
+#X obj 436 121 env~ 8192;
+#X obj 438 196 r~ tone-mon;
+#X obj 447 331 line~;
+#X obj 428 221 *~;
+#X obj 447 304 pack 0 50;
+#X obj 438 251 r~ tone-osc;
+#X obj 438 356 *~;
+#X obj 428 386 +~;
+#X obj 436 69 r tone-hip;
+#X obj 544 92 hip~ 5;
#X obj 552 169 outlet;
#X obj 552 143 int;
#X obj 552 117 env~ 8192;
#X obj 554 192 r~ tone-mon;
#X obj 563 327 line~;
#X obj 544 217 *~;
+#X obj 563 300 pack 0 50;
#X obj 554 247 r~ tone-osc;
#X obj 554 352 *~;
#X obj 544 382 +~;
#X obj 552 65 r tone-hip;
+#X obj 661 92 hip~ 5;
#X obj 669 169 outlet;
#X obj 669 143 int;
#X obj 669 117 env~ 8192;
#X obj 671 192 r~ tone-mon;
#X obj 680 327 line~;
#X obj 661 217 *~;
+#X obj 680 300 pack 0 50;
#X obj 671 247 r~ tone-osc;
#X obj 671 352 *~;
#X obj 661 382 +~;
#X obj 669 65 r tone-hip;
+#X obj 781 91 hip~ 5;
#X obj 789 168 outlet;
#X obj 789 142 int;
#X obj 789 116 env~ 8192;
#X obj 791 191 r~ tone-mon;
#X obj 800 326 line~;
#X obj 781 216 *~;
+#X obj 800 299 pack 0 50;
#X obj 791 246 r~ tone-osc;
#X obj 791 351 *~;
#X obj 781 381 +~;
#X obj 789 64 r tone-hip;
-#X obj 424 40 adc~ 3;
+#X obj 428 43 adc~ 3;
#X obj 544 39 adc~ 4;
#X obj 661 39 adc~ 5;
#X obj 781 38 adc~ 6;
-#X obj 443 275 r tone-ch3;
+#X obj 447 278 r tone-ch3;
#X obj 563 273 r tone-ch4;
#X obj 680 274 r tone-ch5;
#X obj 800 273 r tone-ch6;
-#X obj 424 408 dac~ 3;
+#X obj 428 411 dac~ 3;
#X obj 543 406 dac~ 4;
#X obj 661 407 dac~ 5;
#X obj 781 406 dac~ 6;
-#X obj 182 92 hip~;
-#X obj 302 91 hip~;
-#X obj 424 93 hip~;
-#X obj 544 92 hip~;
-#X obj 661 92 hip~;
-#X obj 781 91 hip~;
-#X obj 201 300 pack 0 0;
-#X obj 321 299 pack 0 0;
-#X obj 443 301 pack 0 0;
-#X obj 563 300 pack 0 0;
-#X obj 679 300 pack 0 0;
-#X obj 800 299 pack 0 0;
-#X connect 0 0 14 0;
-#X connect 1 0 0 1;
-#X connect 3 0 1 0;
+#N canvas 487 35 468 559 tone-generator 0;
+#X obj 22 134 osc~;
+#X obj 22 66 mtof;
+#X floatatom 22 43 0 0 0 0 - - -;
+#X floatatom 22 88 0 0 0 0 - - -;
+#X obj 22 110 sig~;
+#X obj 22 18 r tone-pitch;
+#X obj 119 60 noise~;
+#X obj 65 196 +~;
+#X obj 282 87 - 1;
+#X obj 282 119 * -1;
+#X obj 191 175 line~;
+#X obj 281 176 line~;
+#X obj 22 158 *~;
+#X obj 119 157 *~;
+#X msg 191 146 \$1 20;
+#X msg 281 147 \$1 20;
+#X floatatom 239 54 0 0 0 0 - - -;
+#X obj 64 451 *~;
+#X obj 86 424 line~;
+#X obj 86 397 pack 0 50;
+#X floatatom 86 345 0 0 0 0 - - -;
+#X obj 86 370 dbtorms;
+#X obj 64 477 s~ tone-osc;
+#X obj 86 262 r tone-radio;
+#X obj 86 290 sel 0 1 2;
+#X msg 155 313 0;
+#X msg 86 315 80;
+#X msg 119 315 60;
+#X obj 239 31 r tone-type;
+#X connect 0 0 12 0;
+#X connect 1 0 3 0;
+#X connect 2 0 1 0;
+#X connect 3 0 4 0;
#X connect 4 0 0 0;
-#X connect 5 0 6 0;
-#X connect 6 0 3 0;
-#X connect 7 0 2 0;
-#X connect 8 0 10 0;
+#X connect 5 0 2 0;
+#X connect 6 0 13 0;
+#X connect 7 0 17 0;
+#X connect 8 0 9 0;
+#X connect 9 0 15 0;
+#X connect 10 0 12 1;
+#X connect 11 0 13 1;
+#X connect 12 0 7 0;
+#X connect 13 0 7 1;
+#X connect 14 0 10 0;
+#X connect 15 0 11 0;
+#X connect 16 0 8 0;
+#X connect 16 0 14 0;
+#X connect 17 0 22 0;
+#X connect 18 0 17 1;
+#X connect 19 0 18 0;
+#X connect 20 0 21 0;
+#X connect 21 0 19 0;
+#X connect 23 0 24 0;
+#X connect 24 0 26 0;
+#X connect 24 1 27 0;
+#X connect 24 2 25 0;
+#X connect 25 0 20 0;
+#X connect 26 0 20 0;
+#X connect 27 0 20 0;
+#X connect 28 0 16 0;
+#X restore 24 68 pd tone-generator;
+#X connect 0 0 7 0;
+#X connect 0 0 3 0;
+#X connect 2 0 1 0;
+#X connect 3 0 2 0;
+#X connect 4 0 0 0;
+#X connect 5 0 7 1;
+#X connect 6 0 11 1;
+#X connect 7 0 13 0;
+#X connect 8 0 6 0;
#X connect 9 0 8 0;
#X connect 10 0 11 0;
-#X connect 11 0 4 0;
-#X connect 12 0 7 0;
-#X connect 13 0 103 0;
-#X connect 15 0 17 0;
-#X connect 16 0 9 0;
-#X connect 17 0 19 0;
-#X connect 17 1 20 0;
-#X connect 17 2 18 0;
-#X connect 18 0 5 0;
-#X connect 19 0 5 0;
-#X connect 20 0 5 0;
-#X connect 21 0 23 1;
-#X connect 22 0 26 1;
-#X connect 23 0 28 0;
-#X connect 24 0 109 0;
-#X connect 25 0 26 0;
-#X connect 26 0 28 1;
-#X connect 28 0 27 0;
-#X connect 29 0 103 1;
-#X connect 31 0 30 0;
-#X connect 32 0 31 0;
-#X connect 33 0 32 0;
-#X connect 35 0 34 0;
-#X connect 36 0 35 0;
-#X connect 37 0 39 1;
-#X connect 38 0 41 1;
-#X connect 39 0 42 0;
-#X connect 40 0 41 0;
-#X connect 41 0 42 1;
-#X connect 42 0 45 0;
-#X connect 43 0 104 1;
-#X connect 44 0 104 0;
-#X connect 46 0 110 0;
-#X connect 47 0 48 0;
-#X connect 49 0 47 0;
+#X connect 11 0 13 1;
+#X connect 13 0 12 0;
+#X connect 14 0 0 1;
+#X connect 16 0 15 0;
+#X connect 17 0 16 0;
+#X connect 18 0 17 0;
+#X connect 19 0 25 0;
+#X connect 19 0 22 0;
+#X connect 21 0 20 0;
+#X connect 22 0 21 0;
+#X connect 23 0 25 1;
+#X connect 24 0 28 1;
+#X connect 25 0 29 0;
+#X connect 26 0 24 0;
+#X connect 27 0 28 0;
+#X connect 28 0 29 1;
+#X connect 29 0 32 0;
+#X connect 30 0 19 1;
+#X connect 31 0 19 0;
+#X connect 33 0 26 0;
+#X connect 34 0 35 0;
+#X connect 36 0 34 0;
+#X connect 38 0 44 0;
+#X connect 38 0 41 0;
+#X connect 40 0 39 0;
+#X connect 41 0 40 0;
+#X connect 42 0 44 1;
+#X connect 43 0 47 1;
+#X connect 44 0 48 0;
+#X connect 45 0 43 0;
+#X connect 46 0 47 0;
+#X connect 47 0 48 1;
+#X connect 48 0 94 0;
+#X connect 49 0 38 1;
+#X connect 50 0 56 0;
+#X connect 50 0 53 0;
#X connect 52 0 51 0;
#X connect 53 0 52 0;
#X connect 54 0 56 1;
-#X connect 55 0 58 1;
-#X connect 56 0 59 0;
-#X connect 57 0 58 0;
-#X connect 58 0 59 1;
-#X connect 59 0 99 0;
-#X connect 60 0 105 1;
-#X connect 62 0 61 0;
-#X connect 63 0 62 0;
-#X connect 64 0 66 1;
-#X connect 65 0 68 1;
-#X connect 66 0 69 0;
-#X connect 67 0 68 0;
-#X connect 68 0 69 1;
-#X connect 69 0 100 0;
-#X connect 70 0 106 1;
-#X connect 72 0 71 0;
-#X connect 73 0 72 0;
-#X connect 74 0 76 1;
-#X connect 75 0 78 1;
-#X connect 76 0 79 0;
-#X connect 77 0 78 0;
-#X connect 78 0 79 1;
-#X connect 79 0 101 0;
-#X connect 80 0 107 1;
-#X connect 82 0 81 0;
-#X connect 83 0 82 0;
-#X connect 84 0 86 1;
-#X connect 85 0 88 1;
-#X connect 86 0 89 0;
-#X connect 87 0 88 0;
-#X connect 88 0 89 1;
-#X connect 89 0 102 0;
-#X connect 90 0 108 1;
-#X connect 91 0 105 0;
-#X connect 92 0 106 0;
-#X connect 93 0 107 0;
-#X connect 94 0 108 0;
-#X connect 95 0 111 0;
-#X connect 96 0 112 0;
-#X connect 97 0 113 0;
-#X connect 98 0 114 0;
-#X connect 103 0 23 0;
-#X connect 103 0 12 0;
-#X connect 104 0 39 0;
-#X connect 104 0 36 0;
-#X connect 105 0 56 0;
-#X connect 105 0 53 0;
-#X connect 106 0 66 0;
-#X connect 106 0 63 0;
-#X connect 107 0 76 0;
-#X connect 107 0 73 0;
-#X connect 108 0 86 0;
-#X connect 108 0 83 0;
-#X connect 109 0 22 0;
-#X connect 110 0 38 0;
-#X connect 111 0 55 0;
-#X connect 112 0 65 0;
-#X connect 113 0 75 0;
-#X connect 114 0 85 0;
-#X restore 149 157 pd -------audio----;
+#X connect 55 0 59 1;
+#X connect 56 0 60 0;
+#X connect 57 0 55 0;
+#X connect 58 0 59 0;
+#X connect 59 0 60 1;
+#X connect 60 0 95 0;
+#X connect 61 0 50 1;
+#X connect 62 0 68 0;
+#X connect 62 0 65 0;
+#X connect 64 0 63 0;
+#X connect 65 0 64 0;
+#X connect 66 0 68 1;
+#X connect 67 0 71 1;
+#X connect 68 0 72 0;
+#X connect 69 0 67 0;
+#X connect 70 0 71 0;
+#X connect 71 0 72 1;
+#X connect 72 0 96 0;
+#X connect 73 0 62 1;
+#X connect 74 0 80 0;
+#X connect 74 0 77 0;
+#X connect 76 0 75 0;
+#X connect 77 0 76 0;
+#X connect 78 0 80 1;
+#X connect 79 0 83 1;
+#X connect 80 0 84 0;
+#X connect 81 0 79 0;
+#X connect 82 0 83 0;
+#X connect 83 0 84 1;
+#X connect 84 0 97 0;
+#X connect 85 0 74 1;
+#X connect 86 0 38 0;
+#X connect 87 0 50 0;
+#X connect 88 0 62 0;
+#X connect 89 0 74 0;
+#X connect 90 0 45 0;
+#X connect 91 0 57 0;
+#X connect 92 0 69 0;
+#X connect 93 0 81 0;
+#X restore 139 159 pd -------audio----;
+#X text 72 174 noise;
+#X text 71 191 tone;
+#X text 44 80 SIGNAL;
+#X text 131 78 test signal channels:;
+#X obj 52 174 vradio 15 1 0 2 tone-type tone-type-set empty 0 -6 0
+8 -262144 -1 -1 1;
+#X obj 51 104 vradio 15 1 0 3 tone-radio tone-radio-set empty 0 -6
+0 8 -262144 -1 -1 2;
+#X obj 379 220 adc~;
+#X obj 379 256 print~;
+#X obj 438 227 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1
+-1;
#X connect 1 0 2 0;
#X connect 1 1 2 1;
#X connect 2 0 3 0;
@@ -358,9 +393,11 @@ but is free for you to use for any reasonable purpose. See the file
#X connect 9 0 8 0;
#X connect 9 1 7 0;
#X connect 16 0 10 0;
-#X connect 38 0 11 0;
-#X connect 38 1 12 0;
-#X connect 38 2 30 0;
-#X connect 38 3 31 0;
-#X connect 38 4 32 0;
-#X connect 38 5 33 0;
+#X connect 35 0 11 0;
+#X connect 35 1 12 0;
+#X connect 35 2 29 0;
+#X connect 35 3 30 0;
+#X connect 35 4 31 0;
+#X connect 35 5 32 0;
+#X connect 42 0 43 0;
+#X connect 44 0 43 0;
diff --git a/pd/extra/README.txt b/pd/extra/README.txt
index aaac513a..850e3032 100644
--- a/pd/extra/README.txt
+++ b/pd/extra/README.txt
@@ -1,15 +1,8 @@
This is the README file for the "extras" library, consisting of Pd
objects which are too specialized or otherwise non-canonical for
-inclusion into Pd proper. Except as noted otherwise, all
-included materiels are Copyright 1999 Miller Puckette and others.
-Permission is granted to use this software for any purpose, commercial
-or noncommercial, as long as this notice is included with all copies.
-
-NEITHER THE AUTHORS NOR THEIR EMPLOYERS MAKE ANY WARRANTY, EXPRESS
-OR IMPLIED, IN CONNECTION WITH THIS SOFTWARE!
-
-Note that "expr" is under the GPL, which is more restrictive than Pd's own
-license agreement.
+inclusion into Pd proper. These files are open source; see
+LICENSE.txt in this distribution for details.
+Note however that "expr" is GPL (the rest is all BSD).
This package should run in Pd under linux, MSW, or Mac OSX.
You can additionally compile fiddle~. bonk~, and paf~ for Max/MSP.
@@ -23,11 +16,13 @@ choose - find the "best fit" of incoming vector with stored profiles
paf~ -- phase aligned formant generator
loop~ -- sample looper
expr -- arithmetic expression evaluation (Shahrokh Yadegari)
+pique - fft-based peak finder
+lrshift~ - left or right shift an audio vector
abstractions:
hilbert~ - Hilbert transform for SSB modulation
complex-mod~ - ring modulation for complex (real+imaginary) audio signals
-rev1~ - experimental reverberator
+rev1~, etc. - reverberators
These objects are part of the regular Pd distribution as of Pd version
0.30. Macintosh versions of fiddle~, bonk~, and paf~ are available
diff --git a/pd/extra/bonk~/makefile b/pd/extra/bonk~/makefile
index 979dd2b7..578f7b8d 100644
--- a/pd/extra/bonk~/makefile
+++ b/pd/extra/bonk~/makefile
@@ -60,9 +60,9 @@ pd_linux: $(NAME).pd_linux
.SUFFIXES: .pd_linux
-LINUXCFLAGS = -DPD -O2 -funroll-loops -fomit-frame-pointer \
- -Wall -W -Wshadow -Wstrict-prototypes -Werror \
- -Wno-unused -Wno-parentheses -Wno-switch
+LINUXCFLAGS = -DPD -O2 -funroll-loops -fomit-frame-pointer -fPIC \
+ -Wall -W -Wshadow -Wstrict-prototypes \
+ -Wno-unused -Wno-parentheses -Wno-switch $(CFLAGS)
LINUXINCLUDE = -I../../src
diff --git a/pd/extra/choice/help-choice.pd b/pd/extra/choice/help-choice.pd
index df46ddc0..0677db87 100644
--- a/pd/extra/choice/help-choice.pd
+++ b/pd/extra/choice/help-choice.pd
@@ -1,30 +1,47 @@
-#N canvas 16 5 488 531 12;
-#X obj 8 186 choice;
+#N canvas 16 5 609 600 12;
+#X obj 8 195 choice;
#X msg 41 86 print;
#X msg 29 63 clear;
-#X msg 8 34 add 1 0 0 \, add 0 1 0 \, add 0 0 1 \, add 1 1 1 \, add 1 1 0;
-#X obj 77 162 pack 0 0 0;
-#X floatatom 182 120;
-#X floatatom 148 120;
-#X floatatom 115 120;
-#X obj 77 142 f;
-#X msg 77 120 bang;
-#X floatatom 8 207;
-#X obj 53 187 choice 1;
-#X floatatom 53 208;
+#X msg 8 34 add 1 0 0 \, add 0 1 0 \, add 0 0 1 \, add 1 1 1 \, add
+1 1 0;
+#X obj 77 171 pack 0 0 0;
+#X floatatom 182 125 0 0 0 0 - - -;
+#X floatatom 148 125 0 0 0 0 - - -;
+#X floatatom 115 125 0 0 0 0 - - -;
+#X obj 77 147 f;
+#X msg 77 125 bang;
+#X floatatom 8 216 0 0 0 0 - - -;
+#X obj 71 196 choice 1;
+#X floatatom 71 217 0 0 0 0 - - -;
#X obj 76 4 choice;
-#X text 122 5 - search for a best match to an incoming list;
-#X text 19 234 The choice object holds a list of vectors \, each having up to ten elements. When sent a list of numbers \, it outputs the index of the known vector that matches most closely. The quality of the match is the dot product of the two vectors after normalizing them \, i.e. \, the vector whose direction is closest to that of the input wins.;
-#X text 19 316 If given a nonzero creation argument \, choice tries to avoid repetitious outputs by weighting less recently output vectors preferentially.;
-#X text 18 354 You can use this to choose interactively between a number of behaviors depending on their attributes. For example \, you might have stored a number of melodies \, of which some are syncopated \, some chromatic \, some are more than 100 years old \, some are bugle calls \, and some are Christmas carols. You could then ask to find a syncopated bugle call (1 \, 0 \, 0 \, 1 \, 0) and you'll get the thing most closely matching the request.;
-#X text 17 461 You can use numbers other than 0 and 1 to indicate relative strengths of the attributes \, or even use negative numbers to indicate opposites \, either in the incoming lists or in the stored ones.;
-#X text 273 513 updated for Pd version-0.30;
-#X text 72 63 delete all stored vectors;
-#X text 394 36 add vectors;
-#X text 81 85 debugging printout;
+#X text 135 3 - search for a best match to an incoming list;
+#X text 19 243 The choice object holds a list of vectors \, each having
+up to ten elements. When sent a list of numbers \, it outputs the index
+of the known vector that matches most closely. The quality of the match
+is the dot product of the two vectors after normalizing them \, i.e.
+\, the vector whose direction is closest to that of the input wins.
+;
+#X text 19 340 If given a nonzero creation argument \, choice tries
+to avoid repetitious outputs by weighting less recently output vectors
+preferentially.;
+#X text 20 389 You can use this to choose interactively between a number
+of behaviors depending on their attributes. For example \, you might
+have stored a number of melodies \, of which some are syncopated \,
+some chromatic \, some are more than 100 years old \, some are bugle
+calls \, and some are Christmas carols. You could then ask to find
+a syncopated bugle call (1 \, 0 \, 0 \, 1 \, 0) and you'll get the
+thing most closely matching the request.;
+#X text 19 514 You can use numbers other than 0 and 1 to indicate relative
+strengths of the attributes \, or even use negative numbers to indicate
+opposites \, either in the incoming lists or in the stored ones.;
+#X text 320 572 updated for Pd version-0.30;
+#X text 79 62 delete all stored vectors;
+#X text 498 34 add vectors;
+#X text 94 84 debugging printout;
#X text 69 104 tweak the numbers and hit "bang" to input a list;
-#X text 115 187 creation argument to avoid repeated outout;
-#X text 85 208 output is the index of best match \, counting from zero;
+#X text 151 197 creation argument to avoid repeated outout;
+#X text 108 219 output is the index of best match \, counting from
+zero;
#X connect 0 0 10 0;
#X connect 1 0 0 0;
#X connect 2 0 0 0;
diff --git a/pd/extra/choice/makefile b/pd/extra/choice/makefile
index 10021e24..7345eed7 100644
--- a/pd/extra/choice/makefile
+++ b/pd/extra/choice/makefile
@@ -60,9 +60,9 @@ pd_linux: $(NAME).pd_linux
.SUFFIXES: .pd_linux
-LINUXCFLAGS = -DPD -O2 -funroll-loops -fomit-frame-pointer \
- -Wall -W -Wshadow -Wstrict-prototypes -Werror \
- -Wno-unused -Wno-parentheses -Wno-switch
+LINUXCFLAGS = -DPD -O2 -funroll-loops -fomit-frame-pointer -fPIC \
+ -Wall -W -Wshadow -Wstrict-prototypes \
+ -Wno-unused -Wno-parentheses -Wno-switch $(CFLAGS)
LINUXINCLUDE = -I../../src
diff --git a/pd/extra/expr~/makefile b/pd/extra/expr~/makefile
index 942615f4..042380dd 100644
--- a/pd/extra/expr~/makefile
+++ b/pd/extra/expr~/makefile
@@ -79,9 +79,9 @@ SGIINCLUDE = -I/usr/people/msp/pd/pd/src
LINUXOBJ = vexp.pd_linux_o vexp_fun.pd_linux_o vexp_if.pd_linux_o
.SUFFIXES: .pd_linux_o
-LINUXCFLAGS = -DPD -O2 -funroll-loops -fomit-frame-pointer \
- -Wall -W -Wshadow -Wstrict-prototypes \
- -Wno-unused -Wno-parentheses -Wno-switch
+LINUXCFLAGS = -DPD -O2 -funroll-loops -fomit-frame-pointer -fPIC \
+ -Wall -W -Wshadow -Wstrict-prototypes \
+ -Wno-unused -Wno-parentheses -Wno-switch $(CFLAGS)
LINUXINCLUDE = -I../../src
diff --git a/pd/extra/expr~/vexp.c b/pd/extra/expr~/vexp.c
index d75ab539..c0001e1f 100644
--- a/pd/extra/expr~/vexp.c
+++ b/pd/extra/expr~/vexp.c
@@ -78,23 +78,23 @@
char *atoif(char *s, long int *value, long int *type);
-static struct ex_ex *ex_lex(struct expr *exp, long int *n);
+static struct ex_ex *ex_lex(struct expr *expr, long int *n);
struct ex_ex *ex_match(struct ex_ex *eptr, long int op);
-struct ex_ex *ex_parse(struct expr *exp, struct ex_ex *iptr,
+struct ex_ex *ex_parse(struct expr *expr, struct ex_ex *iptr,
struct ex_ex *optr, long int *argc);
-struct ex_ex *ex_eval(struct expr *exp, struct ex_ex *eptr,
+struct ex_ex *ex_eval(struct expr *expr, struct ex_ex *eptr,
struct ex_ex *optr, int i);
-int expr_donew(struct expr *expr, int ac, t_atom *av);
-struct ex_ex *eval_func(struct expr *exp,struct ex_ex *eptr,
+int expr_donew(struct expr *exprr, int ac, t_atom *av);
+struct ex_ex *eval_func(struct expr *expr,struct ex_ex *eptr,
struct ex_ex *optr, int i);
-struct ex_ex *eval_tab(struct expr *exp, struct ex_ex *eptr,
+struct ex_ex *eval_tab(struct expr *expr, struct ex_ex *eptr,
struct ex_ex *optr, int i);
-struct ex_ex *eval_var(struct expr *exp, struct ex_ex *eptr,
+struct ex_ex *eval_var(struct expr *expr, struct ex_ex *eptr,
struct ex_ex *optr, int i);
-struct ex_ex *eval_store(struct expr *exp, struct ex_ex *eptr,
+struct ex_ex *eval_store(struct expr *expr, struct ex_ex *eptr,
struct ex_ex *optr, int i);
-struct ex_ex *eval_sigidx(struct expr *exp, struct ex_ex *eptr,
+struct ex_ex *eval_sigidx(struct expr *expr, struct ex_ex *eptr,
struct ex_ex *optr, int i);
static int cal_sigidx(struct ex_ex *optr, /* The output value */
int i, float rem_i, /* integer and fractinal part of index */
@@ -102,7 +102,7 @@ static int cal_sigidx(struct ex_ex *optr, /* The output value */
int vsize, /* vector size */
float *curvec, float *prevec); /* current and previous table */
t_ex_func *find_func(char *s);
-void ex_dzdetect(struct expr *exp);
+void ex_dzdetect(struct expr *expr);
#define MAX_ARGS 10
extern t_ex_func ex_funcs[];
@@ -110,7 +110,7 @@ extern t_ex_func ex_funcs[];
struct ex_ex nullex;
void set_tokens (char *s);
-int getoken (struct expr *exp, struct ex_ex *eptr);
+int getoken (struct expr *expr, struct ex_ex *eptr);
void ex_print (struct ex_ex *eptr);
#ifdef MSP
void atom_string(t_atom *a, char *buf, unsigned int bufsize);
@@ -294,7 +294,7 @@ error:
* It will also put the number of the nodes in *n.
*/
struct ex_ex *
-ex_lex(struct expr *exp, long int *n)
+ex_lex(struct expr *expr, long int *n)
{
struct ex_ex *list_arr;
struct ex_ex *exptr;
@@ -323,7 +323,7 @@ ex_lex(struct expr *exp, long int *n)
exptr = &(list_arr)[non];
}
- if (getoken(exp, exptr)) {
+ if (getoken(expr, exptr)) {
fts_free(list_arr);
return ((struct ex_ex *)0);
}
@@ -684,7 +684,7 @@ ex_parse(struct expr *x, struct ex_ex *iptr, struct ex_ex *optr, long int *argc)
#define DZC(ARG1,OPR,ARG2) (ARG1 OPR ARG2)
#define EVAL(OPR); \
-eptr = ex_eval(exp, ex_eval(exp, eptr, &left, idx), &right, idx); \
+eptr = ex_eval(expr, ex_eval(expr, eptr, &left, idx), &right, idx); \
switch (left.ex_type) { \
case ET_INT: \
switch(right.ex_type) { \
@@ -692,7 +692,7 @@ case ET_INT: \
if (optr->ex_type == ET_VEC) { \
op = optr->ex_vec; \
scalar = (float)DZC(left.ex_int, OPR, right.ex_int); \
- for (j = 0; j < exp->exp_vsize; j++) \
+ for (j = 0; j < expr->exp_vsize; j++) \
*op++ = scalar; \
} else { \
optr->ex_type = ET_INT; \
@@ -703,7 +703,7 @@ case ET_INT: \
if (optr->ex_type == ET_VEC) { \
op = optr->ex_vec; \
scalar = DZC(((float)left.ex_int), OPR, right.ex_flt);\
- for (j = 0; j < exp->exp_vsize; j++) \
+ for (j = 0; j < expr->exp_vsize; j++) \
*op++ = scalar; \
} else { \
optr->ex_type = ET_FLT; \
@@ -720,19 +720,19 @@ case ET_INT: \
} \
optr->ex_type = ET_VEC; \
optr->ex_vec = (t_float *) \
- fts_malloc(sizeof (t_float)*exp->exp_vsize); \
+ fts_malloc(sizeof (t_float)*expr->exp_vsize); \
} \
scalar = left.ex_int; \
rp = right.ex_vec; \
op = optr->ex_vec; \
- for (i = 0; i < exp->exp_vsize; i++) { \
+ for (i = 0; i < expr->exp_vsize; i++) { \
*op++ = DZC (scalar, OPR, *rp); \
rp++; \
} \
break; \
case ET_SYM: \
default: \
- post_error((fts_object_t *) exp, \
+ post_error((fts_object_t *) expr, \
"expr: ex_eval(%d): bad right type %ld\n", \
__LINE__, right.ex_type); \
nullret = 1; \
@@ -744,7 +744,7 @@ case ET_FLT: \
if (optr->ex_type == ET_VEC) { \
op = optr->ex_vec; \
scalar = DZC((float) left.ex_flt, OPR, right.ex_int); \
- for (j = 0; j < exp->exp_vsize; j++) \
+ for (j = 0; j < expr->exp_vsize; j++) \
*op++ = scalar; \
} else { \
optr->ex_type = ET_FLT; \
@@ -755,7 +755,7 @@ case ET_FLT: \
if (optr->ex_type == ET_VEC) { \
op = optr->ex_vec; \
scalar = DZC(left.ex_flt, OPR, right.ex_flt); \
- for (j = 0; j < exp->exp_vsize; j++) \
+ for (j = 0; j < expr->exp_vsize; j++) \
*op++ = scalar; \
} else { \
optr->ex_type = ET_FLT; \
@@ -771,19 +771,19 @@ case ET_FLT: \
} \
optr->ex_type = ET_VEC; \
optr->ex_vec = (t_float *) \
- fts_malloc(sizeof (t_float)*exp->exp_vsize); \
+ fts_malloc(sizeof (t_float)*expr->exp_vsize); \
} \
scalar = left.ex_flt; \
rp = right.ex_vec; \
op = optr->ex_vec; \
- for (i = 0; i < exp->exp_vsize; i++) { \
+ for (i = 0; i < expr->exp_vsize; i++) { \
*op++ = DZC(scalar, OPR, *rp); \
rp++; \
} \
break; \
case ET_SYM: \
default: \
- post_error((fts_object_t *) exp, \
+ post_error((fts_object_t *) expr, \
"expr: ex_eval(%d): bad right type %ld\n", \
__LINE__, right.ex_type); \
nullret = 1; \
@@ -798,21 +798,21 @@ case ET_VI: \
} \
optr->ex_type = ET_VEC; \
optr->ex_vec = (t_float *) \
- fts_malloc(sizeof (t_float)*exp->exp_vsize); \
+ fts_malloc(sizeof (t_float)*expr->exp_vsize); \
} \
op = optr->ex_vec; \
lp = left.ex_vec; \
switch(right.ex_type) { \
case ET_INT: \
scalar = right.ex_int; \
- for (i = 0; i < exp->exp_vsize; i++) { \
+ for (i = 0; i < expr->exp_vsize; i++) { \
*op++ = DZC(*lp, OPR, scalar); \
lp++; \
} \
break; \
case ET_FLT: \
scalar = right.ex_flt; \
- for (i = 0; i < exp->exp_vsize; i++) { \
+ for (i = 0; i < expr->exp_vsize; i++) { \
*op++ = DZC(*lp, OPR, scalar); \
lp++; \
} \
@@ -820,7 +820,7 @@ case ET_VI: \
case ET_VEC: \
case ET_VI: \
rp = right.ex_vec; \
- for (i = 0; i < exp->exp_vsize; i++) { \
+ for (i = 0; i < expr->exp_vsize; i++) { \
/* \
* on a RISC processor one could copy \
* 8 times in each round to get a considerable \
@@ -832,7 +832,7 @@ case ET_VI: \
break; \
case ET_SYM: \
default: \
- post_error((fts_object_t *) exp, \
+ post_error((fts_object_t *) expr, \
"expr: ex_eval(%d): bad right type %ld\n", \
__LINE__, right.ex_type); \
nullret = 1; \
@@ -840,7 +840,7 @@ case ET_VI: \
break; \
case ET_SYM: \
default: \
- post_error((fts_object_t *) exp, \
+ post_error((fts_object_t *) expr, \
"expr: ex_eval(%d): bad left type %ld\n", \
__LINE__, left.ex_type); \
} \
@@ -850,12 +850,12 @@ break;
* evaluate a unary operator, TYPE is applied to float operands
*/
#define EVAL_UNARY(OPR, TYPE) \
- eptr = ex_eval(exp, eptr, &left, idx); \
+ eptr = ex_eval(expr, eptr, &left, idx); \
switch(left.ex_type) { \
case ET_INT: \
if (optr->ex_type == ET_VEC) { \
ex_mkvector(optr->ex_vec,(float)(OPR left.ex_int),\
- exp->exp_vsize);\
+ expr->exp_vsize);\
break; \
} \
optr->ex_type = ET_INT; \
@@ -864,7 +864,7 @@ break;
case ET_FLT: \
if (optr->ex_type == ET_VEC) { \
ex_mkvector(optr->ex_vec, OPR (TYPE left.ex_flt),\
- exp->exp_vsize);\
+ expr->exp_vsize);\
break; \
} \
optr->ex_type = ET_FLT; \
@@ -872,20 +872,20 @@ break;
break; \
case ET_VI: \
case ET_VEC: \
- j = exp->exp_vsize; \
+ j = expr->exp_vsize; \
if (optr->ex_type != ET_VEC) { \
optr->ex_type = ET_VEC; \
optr->ex_vec = (t_float *) \
- fts_malloc(sizeof (t_float)*exp->exp_vsize); \
+ fts_malloc(sizeof (t_float)*expr->exp_vsize); \
} \
op = optr->ex_vec; \
lp = left.ex_vec; \
- j = exp->exp_vsize; \
+ j = expr->exp_vsize; \
for (i = 0; i < j; i++) \
*op++ = OPR (TYPE *lp++); \
break; \
default: \
- post_error((fts_object_t *) exp, \
+ post_error((fts_object_t *) expr, \
"expr: ex_eval(%d): bad left type %ld\n", \
__LINE__, left.ex_type); \
nullret++; \
@@ -903,23 +903,23 @@ ex_mkvector(t_float *fp, t_float x, int size)
* ex_dzdetect -- divide by zero detected
*/
void
-ex_dzdetect(struct expr *exp)
+ex_dzdetect(struct expr *expr)
{
char *etype;
- if (!exp->exp_error & EE_DZ) {
- if (IS_EXPR(exp))
+ if (!expr->exp_error & EE_DZ) {
+ if (IS_EXPR(expr))
etype = "expr";
- else if (IS_EXPR_TILDE(exp))
+ else if (IS_EXPR_TILDE(expr))
etype = "expr~";
- else if (IS_FEXPR_TILDE(exp))
+ else if (IS_FEXPR_TILDE(expr))
etype = "fexpr~";
else {
post ("expr -- ex_dzdetect internal error");
etype = "";
}
post ("%s divide by zero detected", etype);
- exp->exp_error |= EE_DZ;
+ expr->exp_error |= EE_DZ;
}
}
@@ -938,7 +938,7 @@ need to be freed
look into the variable nullret
*/
struct ex_ex *
-ex_eval(struct expr *exp, struct ex_ex *eptr, struct ex_ex *optr, int idx)
+ex_eval(struct expr *expr, struct ex_ex *eptr, struct ex_ex *optr, int idx)
/* the expr object data pointer */
/* the operation stack */
/* the result pointer */
@@ -961,7 +961,7 @@ ex_eval(struct expr *exp, struct ex_ex *eptr, struct ex_ex *optr, int idx)
case ET_INT:
if (optr->ex_type == ET_VEC)
ex_mkvector(optr->ex_vec, (float) eptr->ex_int,
- exp->exp_vsize);
+ expr->exp_vsize);
else
*optr = *eptr;
return (++eptr);
@@ -969,14 +969,14 @@ ex_eval(struct expr *exp, struct ex_ex *eptr, struct ex_ex *optr, int idx)
case ET_FLT:
if (optr->ex_type == ET_VEC)
- ex_mkvector(optr->ex_vec, eptr->ex_flt, exp->exp_vsize);
+ ex_mkvector(optr->ex_vec, eptr->ex_flt, expr->exp_vsize);
else
*optr = *eptr;
return (++eptr);
case ET_SYM:
if (optr->ex_type == ET_VEC) {
- post_error((fts_object_t *) exp,
+ post_error((fts_object_t *) expr,
"expr: ex_eval: cannot turn string to vector\n");
return (exNULL);
}
@@ -984,55 +984,55 @@ ex_eval(struct expr *exp, struct ex_ex *eptr, struct ex_ex *optr, int idx)
return (++eptr);
case ET_II:
if (eptr->ex_int == -1) {
- post_error((fts_object_t *) exp,
+ post_error((fts_object_t *) expr,
"expr: ex_eval: inlet number not set\n");
return (exNULL);
}
if (optr->ex_type == ET_VEC) {
ex_mkvector(optr->ex_vec,
- (t_float)exp->exp_var[eptr->ex_int].ex_int,
- exp->exp_vsize);
+ (t_float)expr->exp_var[eptr->ex_int].ex_int,
+ expr->exp_vsize);
} else {
optr->ex_type = ET_INT;
- optr->ex_int = exp->exp_var[eptr->ex_int].ex_int;
+ optr->ex_int = expr->exp_var[eptr->ex_int].ex_int;
}
return (++eptr);
case ET_FI:
if (eptr->ex_int == -1) {
- post_error((fts_object_t *) exp,
+ post_error((fts_object_t *) expr,
"expr: ex_eval: inlet number not set\n");
return (exNULL);
}
if (optr->ex_type == ET_VEC) {
ex_mkvector(optr->ex_vec,
- exp->exp_var[eptr->ex_int].ex_flt, exp->exp_vsize);
+ expr->exp_var[eptr->ex_int].ex_flt, expr->exp_vsize);
} else {
optr->ex_type = ET_FLT;
- optr->ex_flt = exp->exp_var[eptr->ex_int].ex_flt;
+ optr->ex_flt = expr->exp_var[eptr->ex_int].ex_flt;
}
return (++eptr);
case ET_VSYM:
if (optr->ex_type == ET_VEC) {
- post_error((fts_object_t *) exp,
+ post_error((fts_object_t *) expr,
"expr: IntErr. vsym in for vec out\n");
return (exNULL);
}
if (eptr->ex_int == -1) {
- post_error((fts_object_t *) exp,
+ post_error((fts_object_t *) expr,
"expr: ex_eval: inlet number not set\n");
return (exNULL);
}
optr->ex_type = ET_SYM;
- optr->ex_ptr = exp->exp_var[eptr->ex_int].ex_ptr;
+ optr->ex_ptr = expr->exp_var[eptr->ex_int].ex_ptr;
return(++eptr);
case ET_VI:
if (optr->ex_type != ET_VEC)
- *optr = exp->exp_var[eptr->ex_int];
- else if (optr->ex_vec != exp->exp_var[eptr->ex_int].ex_vec)
- memcpy(optr->ex_vec, exp->exp_var[eptr->ex_int].ex_vec,
- exp->exp_vsize * sizeof (t_float));
+ *optr = expr->exp_var[eptr->ex_int];
+ else if (optr->ex_vec != expr->exp_var[eptr->ex_int].ex_vec)
+ memcpy(optr->ex_vec, expr->exp_var[eptr->ex_int].ex_vec,
+ expr->exp_vsize * sizeof (t_float));
return(++eptr);
case ET_VEC:
if (optr->ex_type != ET_VEC) {
@@ -1042,7 +1042,7 @@ ex_eval(struct expr *exp, struct ex_ex *eptr, struct ex_ex *optr, int idx)
eptr->ex_int = 0;
} else if (optr->ex_vec != eptr->ex_vec) {
memcpy(optr->ex_vec, eptr->ex_vec,
- exp->exp_vsize * sizeof (t_float));
+ expr->exp_vsize * sizeof (t_float));
/* do we need to free here? or can we free higher up */
/* SDY the next lines do not make sense */
post("calling fts_free\n");
@@ -1059,12 +1059,12 @@ abort();
/* short hand for $x?[0] */
/* SDY delete the following check */
- if (!IS_FEXPR_TILDE(exp) || optr->ex_type==ET_VEC) {
- post("%d:exp->exp_flags = %d", __LINE__,exp->exp_flags);
+ if (!IS_FEXPR_TILDE(expr) || optr->ex_type==ET_VEC) {
+ post("%d:exp->exp_flags = %d", __LINE__,expr->exp_flags);
abort();
}
optr->ex_type = ET_FLT;
- optr->ex_flt = exp->exp_var[eptr->ex_int].ex_vec[idx];
+ optr->ex_flt = expr->exp_var[eptr->ex_int].ex_vec[idx];
return(++eptr);
case ET_YOM1:
/*
@@ -1075,51 +1075,51 @@ abort();
optr->ex_type = ET_FLT;
if (idx == 0)
optr->ex_flt =
- exp->exp_p_res[eptr->ex_int][exp->exp_vsize - 1];
+ expr->exp_p_res[eptr->ex_int][expr->exp_vsize - 1];
else
- optr->ex_flt=exp->exp_tmpres[eptr->ex_int][idx-1];
+ optr->ex_flt=expr->exp_tmpres[eptr->ex_int][idx-1];
return(++eptr);
case ET_YO:
case ET_XI:
/* SDY delete the following */
- if (!IS_FEXPR_TILDE(exp) || optr->ex_type==ET_VEC) {
- post("%d:exp->exp_flags = %d", __LINE__,exp->exp_flags);
+ if (!IS_FEXPR_TILDE(expr) || optr->ex_type==ET_VEC) {
+ post("%d:expr->exp_flags = %d", __LINE__,expr->exp_flags);
abort();
}
- return (eval_sigidx(exp, eptr, optr, idx));
+ return (eval_sigidx(expr, eptr, optr, idx));
case ET_TBL:
case ET_SI:
- return (eval_tab(exp, eptr, optr, idx));
+ return (eval_tab(expr, eptr, optr, idx));
case ET_FUNC:
- return (eval_func(exp, eptr, optr, idx));
+ return (eval_func(expr, eptr, optr, idx));
case ET_VAR:
- return (eval_var(exp, eptr, optr, idx));
+ return (eval_var(expr, eptr, optr, idx));
case ET_OP:
break;
case ET_STR:
case ET_LP:
case ET_LB:
default:
- post_error((fts_object_t *) exp,
+ post_error((fts_object_t *) expr,
"expr: ex_eval: unexpected type %d\n", eptr->ex_type);
return (exNULL);
}
if (!eptr[1].ex_type) {
- post_error((fts_object_t *) exp,
+ post_error((fts_object_t *) expr,
"expr: ex_eval: not enough nodes 1\n");
return (exNULL);
}
if (!unary_op(eptr->ex_op) && !eptr[2].ex_type) {
- post_error((fts_object_t *) exp,
+ post_error((fts_object_t *) expr,
"expr: ex_eval: not enough nodes 2\n");
return (exNULL);
}
switch((eptr++)->ex_op) {
case OP_STORE:
- return (eval_store(exp, eptr, optr, idx));
+ return (eval_store(expr, eptr, optr, idx));
case OP_NOT:
EVAL_UNARY(!, +);
case OP_NEG:
@@ -1168,14 +1168,14 @@ abort();
*/
#undef DZC
#define DZC(ARG1,OPR,ARG2) (((ARG2)?(((int)ARG1) OPR ((int)ARG2)) \
- : (ex_dzdetect(exp),0)))
+ : (ex_dzdetect(expr),0)))
case OP_MOD:
EVAL(%);
/*
* define the divide by zero check for divide
*/
#undef DZC
-#define DZC(ARG1,OPR,ARG2) (((ARG2)?(ARG1 OPR ARG2):(ex_dzdetect(exp),0)))
+#define DZC(ARG1,OPR,ARG2) (((ARG2)?(ARG1 OPR ARG2):(ex_dzdetect(expr),0)))
case OP_DIV:
EVAL(/);
case OP_LP:
@@ -1185,7 +1185,7 @@ abort();
case OP_COMMA:
case OP_SEMI:
default:
- post_error((fts_object_t *) exp, "expr: ex_print: bad op 0x%x\n", eptr->ex_op);
+ post_error((fts_object_t *) expr, "expr: ex_print: bad op 0x%x\n", eptr->ex_op);
return (exNULL);
}
@@ -1210,7 +1210,7 @@ abort();
* appropriate function
*/
struct ex_ex *
-eval_func(struct expr *exp, struct ex_ex *eptr, struct ex_ex *optr, int idx)
+eval_func(struct expr *expr, struct ex_ex *eptr, struct ex_ex *optr, int idx)
/* the expr object data pointer */
/* the operation stack */
/* the result pointer */
@@ -1224,16 +1224,16 @@ eval_func(struct expr *exp, struct ex_ex *eptr, struct ex_ex *optr, int idx)
return (exNULL);
}
if (f->f_argc > MAX_ARGS) {
- post_error((fts_object_t *) exp, "expr: eval_func: asking too many arguments\n");
+ post_error((fts_object_t *) expr, "expr: eval_func: asking too many arguments\n");
return (exNULL);
}
for (i = 0; i < f->f_argc; i++) {
args[i].ex_type = 0;
args[i].ex_int = 0;
- eptr = ex_eval(exp, eptr, &args[i], idx);
+ eptr = ex_eval(expr, eptr, &args[i], idx);
}
- (*f->f_func)(exp, f->f_argc, args, optr);
+ (*f->f_func)(expr, f->f_argc, args, optr);
for (i = 0; i < f->f_argc; i++) {
if (args[i].ex_type == ET_VEC)
fts_free(args[i].ex_vec);
@@ -1248,7 +1248,7 @@ eval_func(struct expr *exp, struct ex_ex *eptr, struct ex_ex *optr, int idx)
* and call ex_eval on the right operator
*/
struct ex_ex *
-eval_store(struct expr *exp, struct ex_ex *eptr, struct ex_ex *optr, int idx)
+eval_store(struct expr *expr, struct ex_ex *eptr, struct ex_ex *optr, int idx)
/* the expr object data pointer */
/* the operation stack */
/* the result pointer */
@@ -1261,7 +1261,7 @@ eval_store(struct expr *exp, struct ex_ex *eptr, struct ex_ex *optr, int idx)
post("store called\n");
ex_print(eptr);
-eptr = ex_eval(exp, ++eptr, optr, idx);
+eptr = ex_eval(expr, ++eptr, optr, idx);
return (eptr);
#ifdef notdef /* SDY */
@@ -1270,8 +1270,8 @@ return (eptr);
if (eptr->ex_type == ET_VAR) {
var = (char *) eptr->ex_ptr;
- eptr = ex_eval(exp, ++eptr, &arg, idx);
- (void)max_ex_var_store(exp, (t_symbol *)var, &arg, optr);
+ eptr = ex_eval(expr, ++eptr, &arg, idx);
+ (void)max_ex_var_store(expr, (t_symbol *)var, &arg, optr);
if (arg.ex_type == ET_VEC)
fts_free(arg.ex_vec);
}
@@ -1287,16 +1287,16 @@ return (eptr);
case ET_SI:
if ((eptr + 1)->ex_type == OP_LB) {
}
- if (!exp->exp_var[eptr->ex_int].ex_ptr) {
- if (!(exp->exp_error & EE_NOTABLE)) {
+ if (!expr->exp_var[eptr->ex_int].ex_ptr) {
+ if (!(expr->exp_error & EE_NOTABLE)) {
post("expr: syntax error: no string for inlet %d", eptr->ex_int + 1);
post("expr: No more table errors will be reported");
post("expr: till the next reset");
- exp->exp_error |= EE_NOTABLE;
+ expr->exp_error |= EE_NOTABLE;
}
badleft++;
} else
- tbl = (char *) exp->exp_var[eptr->ex_int].ex_ptr;
+ tbl = (char *) expr->exp_var[eptr->ex_int].ex_ptr;
break;
case ET_TBL:
}
@@ -1307,7 +1307,7 @@ return (eptr);
* eval_tab -- evaluate a table operation
*/
struct ex_ex *
-eval_tab(struct expr *exp, struct ex_ex *eptr, struct ex_ex *optr, int idx)
+eval_tab(struct expr *expr, struct ex_ex *eptr, struct ex_ex *optr, int idx)
/* the expr object data pointer */
/* the operation stack */
/* the result pointer */
@@ -1317,35 +1317,35 @@ eval_tab(struct expr *exp, struct ex_ex *eptr, struct ex_ex *optr, int idx)
int notable = 0;
if (eptr->ex_type == ET_SI) {
- if (!exp->exp_var[eptr->ex_int].ex_ptr) {
+ if (!expr->exp_var[eptr->ex_int].ex_ptr) {
/* SDY post_error() does not work in MAX/MSP yet
- post_error((fts_object_t *) exp,
+ post_error((fts_object_t *) expr,
"expr: syntax error: no string for inlet %d\n", eptr->ex_int + 1);
*/
- if (!(exp->exp_error & EE_NOTABLE)) {
+ if (!(expr->exp_error & EE_NOTABLE)) {
post("expr: syntax error: no string for inlet %d", eptr->ex_int + 1);
post("expr: No more table errors will be reported");
post("expr: till the next reset");
- exp->exp_error |= EE_NOTABLE;
+ expr->exp_error |= EE_NOTABLE;
}
notable++;
} else
- tbl = (char *) exp->exp_var[eptr->ex_int].ex_ptr;
+ tbl = (char *) expr->exp_var[eptr->ex_int].ex_ptr;
} else if (eptr->ex_type == ET_TBL)
tbl = (char *) eptr->ex_ptr;
else {
- post_error((fts_object_t *) exp, "expr: eval_tbl: bad type %ld\n", eptr->ex_type);
+ post_error((fts_object_t *) expr, "expr: eval_tbl: bad type %ld\n", eptr->ex_type);
notable++;
}
arg.ex_type = 0;
arg.ex_int = 0;
- eptr = ex_eval(exp, ++eptr, &arg, idx);
+ eptr = ex_eval(expr, ++eptr, &arg, idx);
optr->ex_type = ET_INT;
optr->ex_int = 0;
if (!notable)
- (void)max_ex_tab(exp, (t_symbol *)tbl, &arg, optr);
+ (void)max_ex_tab(expr, (t_symbol *)tbl, &arg, optr);
if (arg.ex_type == ET_VEC)
fts_free(arg.ex_vec);
return (eptr);
@@ -1355,7 +1355,7 @@ eval_tab(struct expr *exp, struct ex_ex *eptr, struct ex_ex *optr, int idx)
* eval_var -- evaluate a variable
*/
struct ex_ex *
-eval_var(struct expr *exp, struct ex_ex *eptr, struct ex_ex *optr, int idx)
+eval_var(struct expr *expr, struct ex_ex *eptr, struct ex_ex *optr, int idx)
/* the expr object data pointer */
/* the operation stack */
/* the result pointer */
@@ -1365,24 +1365,24 @@ eval_var(struct expr *exp, struct ex_ex *eptr, struct ex_ex *optr, int idx)
int novar = 0;
if (eptr->ex_type == ET_SI) {
- if (!exp->exp_var[eptr->ex_int].ex_ptr) {
+ if (!expr->exp_var[eptr->ex_int].ex_ptr) {
/* SDY post_error() does not work in MAX/MSP yet
-post_error((fts_object_t *) exp,
+post_error((fts_object_t *) expr,
"expr: syntax error: no string for inlet %d\n", eptr->ex_int + 1);
*/
- if (!(exp->exp_error & EE_NOVAR)) {
+ if (!(expr->exp_error & EE_NOVAR)) {
post("expr: syntax error: no string for inlet %d", eptr->ex_int + 1);
post("expr: No more table errors will be reported");
post("expr: till the next reset");
- exp->exp_error |= EE_NOVAR;
+ expr->exp_error |= EE_NOVAR;
}
novar++;
} else
- var = (char *) exp->exp_var[eptr->ex_int].ex_ptr;
+ var = (char *) expr->exp_var[eptr->ex_int].ex_ptr;
} else if (eptr->ex_type == ET_VAR)
var = (char *) eptr->ex_ptr;
else {
- post_error((fts_object_t *) exp, "expr: eval_tbl: bad type %ld\n", eptr->ex_type);
+ post_error((fts_object_t *) expr, "expr: eval_tbl: bad type %ld\n", eptr->ex_type);
novar++;
}
@@ -1390,7 +1390,7 @@ post_error((fts_object_t *) exp,
optr->ex_type = ET_INT;
optr->ex_int = 0;
if (!novar)
- (void)max_ex_var(exp, (t_symbol *)var, optr);
+ (void)max_ex_var(expr, (t_symbol *)var, optr);
return (++eptr);
}
@@ -1398,7 +1398,7 @@ post_error((fts_object_t *) exp,
* eval_sigidx -- evaluate the value of an indexed signal for fexpr~
*/
struct ex_ex *
-eval_sigidx(struct expr *exp, struct ex_ex *eptr, struct ex_ex *optr, int idx)
+eval_sigidx(struct expr *expr, struct ex_ex *eptr, struct ex_ex *optr, int idx)
/* the expr object data pointer */
/* the operation stack */
/* the result pointer */
@@ -1413,7 +1413,7 @@ eval_sigidx(struct expr *exp, struct ex_ex *eptr, struct ex_ex *optr, int idx)
arg.ex_type = 0;
arg.ex_int = 0;
- reteptr = ex_eval(exp, eptr + 1, &arg, idx);
+ reteptr = ex_eval(expr, eptr + 1, &arg, idx);
if (arg.ex_type == ET_FLT) {
fi = arg.ex_flt; /* float index */
i = (int) arg.ex_flt; /* integer index */
@@ -1431,8 +1431,8 @@ eval_sigidx(struct expr *exp, struct ex_ex *eptr, struct ex_ex *optr, int idx)
*/
if (eptr->ex_type == ET_XI) {
if (fi > 0) {
- if (!(exp->exp_error & EE_BI_INPUT)) {
- exp->exp_error |= EE_BI_INPUT;
+ if (!(expr->exp_error & EE_BI_INPUT)) {
+ expr->exp_error |= EE_BI_INPUT;
post("expr: input vector index > 0, (vector x%d[%f])",
eptr->ex_int + 1, i + rem_i);
post("fexpr~: index assumed to be = 0");
@@ -1443,15 +1443,15 @@ eval_sigidx(struct expr *exp, struct ex_ex *eptr, struct ex_ex *optr, int idx)
i = 0;
rem_i = 0;
}
- if (cal_sigidx(optr, i, rem_i, idx, exp->exp_vsize,
- exp->exp_var[eptr->ex_int].ex_vec,
- exp->exp_p_var[eptr->ex_int])) {
- if (!(exp->exp_error & EE_BI_INPUT)) {
- exp->exp_error |= EE_BI_INPUT;
+ if (cal_sigidx(optr, i, rem_i, idx, expr->exp_vsize,
+ expr->exp_var[eptr->ex_int].ex_vec,
+ expr->exp_p_var[eptr->ex_int])) {
+ if (!(expr->exp_error & EE_BI_INPUT)) {
+ expr->exp_error |= EE_BI_INPUT;
post("expr: input vector index < -VectorSize, (vector x%d[%f])", eptr->ex_int + 1, fi);
ex_print(eptr);
post("fexpr~: index assumed to be = -%d",
- exp->exp_vsize);
+ expr->exp_vsize);
post("fexpr~: no error report till next reset");
}
}
@@ -1462,8 +1462,8 @@ eval_sigidx(struct expr *exp, struct ex_ex *eptr, struct ex_ex *optr, int idx)
} else if (eptr->ex_type == ET_YO) {
/* for output vectors index of zero is not legal */
if (fi >= 0) {
- if (!(exp->exp_error & EE_BI_OUTPUT)) {
- exp->exp_error |= EE_BI_OUTPUT;
+ if (!(expr->exp_error & EE_BI_OUTPUT)) {
+ expr->exp_error |= EE_BI_OUTPUT;
post("fexpr~: bad output index, (%f)", fi);
ex_print(eptr);
post("fexpr~: no error report till next reset");
@@ -1471,21 +1471,21 @@ eval_sigidx(struct expr *exp, struct ex_ex *eptr, struct ex_ex *optr, int idx)
}
i = -1;
}
- if (eptr->ex_int >= exp->exp_nexpr) {
+ if (eptr->ex_int >= expr->exp_nexpr) {
post("fexpr~: $y%d illegal: not that many exprs",
eptr->ex_int);
optr->ex_flt = 0;
return (reteptr);
}
- if (cal_sigidx(optr, i, rem_i, idx, exp->exp_vsize,
- exp->exp_tmpres[eptr->ex_int],
- exp->exp_p_res[eptr->ex_int])) {
- if (!(exp->exp_error & EE_BI_OUTPUT)) {
- exp->exp_error |= EE_BI_OUTPUT;
+ if (cal_sigidx(optr, i, rem_i, idx, expr->exp_vsize,
+ expr->exp_tmpres[eptr->ex_int],
+ expr->exp_p_res[eptr->ex_int])) {
+ if (!(expr->exp_error & EE_BI_OUTPUT)) {
+ expr->exp_error |= EE_BI_OUTPUT;
post("fexpr~: bad output index, (%f)", fi);
ex_print(eptr);
post("fexpr~: index assumed to be = -%d",
- exp->exp_vsize);
+ expr->exp_vsize);
}
}
} else {
@@ -1552,30 +1552,30 @@ cal_sigidx(struct ex_ex *optr, /* The output value */
* getoken -- return 1 on syntax error otherwise 0
*/
int
-getoken(struct expr *exp, struct ex_ex *eptr)
+getoken(struct expr *expr, struct ex_ex *eptr)
{
char *p;
long i;
- if (!exp->exp_str) {
+ if (!expr->exp_str) {
post("expr: getoken: expression string not set\n");
return (0);
}
retry:
- if (!*exp->exp_str) {
+ if (!*expr->exp_str) {
eptr->ex_type = 0;
eptr->ex_int = 0;
return (0);
}
- if (*exp->exp_str == ';') {
- exp->exp_str++;
+ if (*expr->exp_str == ';') {
+ expr->exp_str++;
eptr->ex_type = 0;
eptr->ex_int = 0;
return (0);
}
eptr->ex_type = ET_OP;
- switch (*exp->exp_str++) {
+ switch (*expr->exp_str++) {
case '\\':
case ' ':
case '\t':
@@ -1621,21 +1621,21 @@ retry:
eptr->ex_op = OP_LB;
break;
case '!':
- if (*exp->exp_str == '=') {
+ if (*expr->exp_str == '=') {
eptr->ex_op = OP_NE;
- exp->exp_str++;
+ expr->exp_str++;
} else
eptr->ex_op = OP_NOT;
break;
case '<':
- switch (*exp->exp_str) {
+ switch (*expr->exp_str) {
case '<':
eptr->ex_op = OP_SL;
- exp->exp_str++;
+ expr->exp_str++;
break;
case '=':
eptr->ex_op = OP_LE;
- exp->exp_str++;
+ expr->exp_str++;
break;
default:
eptr->ex_op = OP_LT;
@@ -1643,14 +1643,14 @@ retry:
}
break;
case '>':
- switch (*exp->exp_str) {
+ switch (*expr->exp_str) {
case '>':
eptr->ex_op = OP_SR;
- exp->exp_str++;
+ expr->exp_str++;
break;
case '=':
eptr->ex_op = OP_GE;
- exp->exp_str++;
+ expr->exp_str++;
break;
default:
eptr->ex_op = OP_GT;
@@ -1658,39 +1658,39 @@ retry:
}
break;
case '=':
- if (*exp->exp_str++ != '=') {
+ if (*expr->exp_str++ != '=') {
post("expr: syntax error: =\n");
return (1);
}
eptr->ex_op = OP_EQ;
break;
/* do not allow the store till the function is fixed
- if (*exp->exp_str != '=')
+ if (*expr->exp_str != '=')
eptr->ex_op = OP_STORE;
else {
- exp->exp_str++;
+ expr->exp_str++;
eptr->ex_op = OP_EQ;
}
break;
*/
case '&':
- if (*exp->exp_str == '&') {
- exp->exp_str++;
+ if (*expr->exp_str == '&') {
+ expr->exp_str++;
eptr->ex_op = OP_LAND;
} else
eptr->ex_op = OP_AND;
break;
case '|':
- if ((*exp->exp_str == '|')) {
- exp->exp_str++;
+ if ((*expr->exp_str == '|')) {
+ expr->exp_str++;
eptr->ex_op = OP_LOR;
} else
eptr->ex_op = OP_OR;
break;
case '$':
- switch (*exp->exp_str++) {
+ switch (*expr->exp_str++) {
case 'I':
case 'i':
eptr->ex_type = ET_II;
@@ -1705,32 +1705,32 @@ retry:
break;
case 'V':
case 'v':
- if (IS_EXPR_TILDE(exp)) {
+ if (IS_EXPR_TILDE(expr)) {
eptr->ex_type = ET_VI;
break;
}
post("$v? works only for expr~");
- post("expr: syntax error: %s\n", &exp->exp_str[-2]);
+ post("expr: syntax error: %s\n", &expr->exp_str[-2]);
return (1);
case 'X':
case 'x':
- if (IS_FEXPR_TILDE(exp)) {
+ if (IS_FEXPR_TILDE(expr)) {
eptr->ex_type = ET_XI;
- if (isdigit(*exp->exp_str))
+ if (isdigit(*expr->exp_str))
break;
/* for $x[] is a shorhand for $x1[] */
eptr->ex_int = 0;
goto noinletnum;
}
post("$x? works only for fexpr~");
- post("expr: syntax error: %s\n", &exp->exp_str[-2]);
+ post("expr: syntax error: %s\n", &expr->exp_str[-2]);
return (1);
case 'y':
case 'Y':
- if (IS_FEXPR_TILDE(exp)) {
+ if (IS_FEXPR_TILDE(expr)) {
eptr->ex_type = ET_YO;
/*$y takes no number */
- if (isdigit(*exp->exp_str))
+ if (isdigit(*expr->exp_str))
break;
/* for $y[] is a shorhand for $y1[] */
eptr->ex_int = 0;
@@ -1738,16 +1738,16 @@ retry:
}
post("$y works only for fexpr~");
default:
- post("expr: syntax error: %s\n", &exp->exp_str[-2]);
+ post("expr: syntax error: %s\n", &expr->exp_str[-2]);
return (1);
}
- p = atoif(exp->exp_str, &eptr->ex_op, &i);
+ p = atoif(expr->exp_str, &eptr->ex_op, &i);
if (!p) {
- post("expr: syntax error: %s\n", &exp->exp_str[-2]);
+ post("expr: syntax error: %s\n", &expr->exp_str[-2]);
return (1);
}
if (i != ET_INT) {
- post("expr: syntax error: %s\n", exp->exp_str);
+ post("expr: syntax error: %s\n", expr->exp_str);
return (1);
}
/*
@@ -1756,7 +1756,7 @@ retry:
*/
if (!eptr->ex_op || (eptr->ex_op)-- > MAX_VARS) {
post("expr: syntax error: inlet or outlet out of range: %s\n",
- exp->exp_str);
+ expr->exp_str);
return (1);
}
@@ -1768,7 +1768,7 @@ retry:
* illegal for fexr~
*/
if (eptr->ex_op == 0 &&
- (IS_FEXPR_TILDE(exp) || IS_EXPR_TILDE(exp)) &&
+ (IS_FEXPR_TILDE(expr) || IS_EXPR_TILDE(expr)) &&
(eptr->ex_type==ET_II || eptr->ex_type==ET_FI ||
eptr->ex_type==ET_SI)) {
post("first inlet of expr~/fexpr~ can only be a vector");
@@ -1779,25 +1779,25 @@ retry:
/* it is an outlet for fexpr~*/
/* no need to do anything */
;
- } else if (!exp->exp_var[eptr->ex_op].ex_type)
- exp->exp_var[eptr->ex_op].ex_type = eptr->ex_type;
- else if (exp->exp_var[eptr->ex_op].ex_type != eptr->ex_type) {
- post("expr: syntax error: inlets can only have one type: %s\n", exp->exp_str);
+ } else if (!expr->exp_var[eptr->ex_op].ex_type)
+ expr->exp_var[eptr->ex_op].ex_type = eptr->ex_type;
+ else if (expr->exp_var[eptr->ex_op].ex_type != eptr->ex_type) {
+ post("expr: syntax error: inlets can only have one type: %s\n", expr->exp_str);
return (1);
}
- exp->exp_str = p;
+ expr->exp_str = p;
noinletnum:
break;
case '"':
{
struct ex_ex ex;
- p = exp->exp_str;
- if (!*exp->exp_str || *exp->exp_str == '"') {
- post("expr: syntax error: empty symbol: %s\n", --exp->exp_str);
+ p = expr->exp_str;
+ if (!*expr->exp_str || *expr->exp_str == '"') {
+ post("expr: syntax error: empty symbol: %s\n", --expr->exp_str);
return (1);
}
- if (getoken(exp, &ex))
+ if (getoken(expr, &ex))
return (1);
switch (ex.ex_type) {
case ET_STR:
@@ -1815,7 +1815,7 @@ noinletnum:
post("expr: syntax error: bad symbol name: %s\n", p);
return (1);
}
- if (*exp->exp_str++ != '"') {
+ if (*expr->exp_str++ != '"') {
post("expr: syntax error: missing '\"'\n");
return (1);
}
@@ -1832,10 +1832,10 @@ noinletnum:
case '7':
case '8':
case '9':
- p = atoif(--exp->exp_str, &eptr->ex_int, &eptr->ex_type);
+ p = atoif(--expr->exp_str, &eptr->ex_int, &eptr->ex_type);
if (!p)
return (1);
- exp->exp_str = p;
+ expr->exp_str = p;
break;
default:
@@ -1843,17 +1843,17 @@ noinletnum:
* has to be a string, it should either be a
* function or a table
*/
- p = --exp->exp_str;
+ p = --expr->exp_str;
for (i = 0; name_ok(*p); i++)
p++;
if (!i) {
- post("expr: syntax error: %s\n", exp->exp_str);
+ post("expr: syntax error: %s\n", expr->exp_str);
return (1);
}
eptr->ex_ptr = (char *)fts_malloc(i + 1);
- strncpy(eptr->ex_ptr, exp->exp_str, (int) i);
+ strncpy(eptr->ex_ptr, expr->exp_str, (int) i);
(eptr->ex_ptr)[i] = 0;
- exp->exp_str = p;
+ expr->exp_str = p;
/*
* we mark this as a string and later we will change this
* to either a function or a table
diff --git a/pd/extra/expr~/vexp_if.c b/pd/extra/expr~/vexp_if.c
index c75013ba..b183b620 100644
--- a/pd/extra/expr~/vexp_if.c
+++ b/pd/extra/expr~/vexp_if.c
@@ -39,12 +39,11 @@
#include <string.h>
#include <stdlib.h>
-
#include "vexp.h"
static char *exp_version = "0.4";
-extern struct ex_ex *ex_eval(struct expr *exp, struct ex_ex *eptr,
+extern struct ex_ex *ex_eval(struct expr *expr, struct ex_ex *eptr,
struct ex_ex *optr, int n);
#ifdef PD
@@ -81,13 +80,15 @@ expr_list(t_expr *x, t_symbol *s, int argc, const fts_atom_t *argv)
x->exp_var[i].ex_flt = argv[i].a_w.w_float;
else if (x->exp_var[i].ex_type == ET_II)
x->exp_var[i].ex_int = argv[i].a_w.w_float;
- else pd_error(x, "expr: type mismatch");
+ else if (x->exp_var[i].ex_type)
+ pd_error(x, "expr: type mismatch");
}
else if (argv[i].a_type == A_SYMBOL)
{
if (x->exp_var[i].ex_type == ET_SI)
x->exp_var[i].ex_ptr = (char *)argv[i].a_w.w_symbol;
- else pd_error(x, "expr: type mismatch");
+ else if (x->exp_var[i].ex_type)
+ pd_error(x, "expr: type mismatch");
}
}
expr_bang(x);
@@ -888,7 +889,8 @@ ex_symname(fts_symbol_t s)
* the result pointer
*/
int
-max_ex_tab(struct expr *exp,fts_symbol_t s,struct ex_ex *arg,struct ex_ex *optr)
+max_ex_tab(struct expr *expr, fts_symbol_t s, struct ex_ex *arg,
+ struct ex_ex *optr)
{
#ifdef PD
t_garray *garray;
@@ -900,7 +902,7 @@ max_ex_tab(struct expr *exp,fts_symbol_t s,struct ex_ex *arg,struct ex_ex *optr)
{
optr->ex_type = ET_FLT;
optr->ex_flt = 0;
- pd_error(exp, "no such table '%s'", s->s_name);
+ pd_error(expr, "no such table '%s'", s->s_name);
return (1);
}
optr->ex_type = ET_FLT;
@@ -915,7 +917,7 @@ max_ex_tab(struct expr *exp,fts_symbol_t s,struct ex_ex *arg,struct ex_ex *optr)
break;
default: /* do something with strings */
- pd_error(exp, "expr: bad argument for table '%s'\n", fts_symbol_name(s));
+ pd_error(expr, "expr: bad argument for table '%s'\n", fts_symbol_name(s));
indx = 0;
}
if (indx < 0) indx = 0;
@@ -933,13 +935,13 @@ max_ex_tab(struct expr *exp,fts_symbol_t s,struct ex_ex *arg,struct ex_ex *optr)
}
int
-max_ex_var(struct expr *exp, fts_symbol_t var, struct ex_ex *optr)
+max_ex_var(struct expr *expr, fts_symbol_t var, struct ex_ex *optr)
{
optr->ex_type = ET_FLT;
if (value_getfloat(var, &(optr->ex_flt))) {
optr->ex_type = ET_FLT;
optr->ex_flt = 0;
- pd_error(exp, "no such var '%s'", var->s_name);
+ pd_error(expr, "no such var '%s'", var->s_name);
return (1);
}
return (0);
diff --git a/pd/extra/fiddle~/fiddle~.c b/pd/extra/fiddle~/fiddle~.c
index 3c0b2719..594c2ff4 100644
--- a/pd/extra/fiddle~/fiddle~.c
+++ b/pd/extra/fiddle~/fiddle~.c
@@ -1125,7 +1125,8 @@ int sigfiddle_doinit(t_sigfiddle *x, long npoints, long npitch,
if (npitch <= 0) npitch = 0;
else if (npitch > MAXNPITCH) npitch = MAXNPITCH;
if (npeakanal && !npitch) npitch = 1;
-
+ if (!npoints)
+ npoints = DEFAULTPOINTS;
if (!sigfiddle_setnpoints(x, npoints))
{
error("fiddle~: out of memory");
diff --git a/pd/extra/fiddle~/makefile b/pd/extra/fiddle~/makefile
index 313bc504..bda5303e 100644
--- a/pd/extra/fiddle~/makefile
+++ b/pd/extra/fiddle~/makefile
@@ -60,9 +60,9 @@ pd_linux: $(NAME).pd_linux
.SUFFIXES: .pd_linux
-LINUXCFLAGS = -DPD -O2 -funroll-loops -fomit-frame-pointer \
- -Wall -W -Wshadow -Wstrict-prototypes -Werror \
- -Wno-unused -Wno-parentheses -Wno-switch
+LINUXCFLAGS = -DPD -O2 -funroll-loops -fomit-frame-pointer -fPIC \
+ -Wall -W -Wshadow -Wstrict-prototypes \
+ -Wno-unused -Wno-parentheses -Wno-switch $(CFLAGS)
LINUXINCLUDE = -I../../src
diff --git a/pd/extra/loop~/makefile b/pd/extra/loop~/makefile
index eb58997d..9585cebe 100644
--- a/pd/extra/loop~/makefile
+++ b/pd/extra/loop~/makefile
@@ -61,9 +61,9 @@ pd_linux: $(NAME).pd_linux
.SUFFIXES: .pd_linux
-LINUXCFLAGS = -DPD -O2 -funroll-loops -fomit-frame-pointer \
- -Wall -W -Wshadow -Wstrict-prototypes -Werror \
- -Wno-unused -Wno-parentheses -Wno-switch
+LINUXCFLAGS = -DPD -O2 -funroll-loops -fomit-frame-pointer -fPIC \
+ -Wall -W -Wshadow -Wstrict-prototypes \
+ -Wno-unused -Wno-parentheses -Wno-switch $(CFLAGS)
LINUXINCLUDE = -I../../src
diff --git a/pd/extra/lrshift~/makefile b/pd/extra/lrshift~/makefile
index 4fee4687..d278e82a 100644
--- a/pd/extra/lrshift~/makefile
+++ b/pd/extra/lrshift~/makefile
@@ -61,9 +61,9 @@ pd_linux: $(NAME).pd_linux
.SUFFIXES: .pd_linux
-LINUXCFLAGS = -DPD -O2 -funroll-loops -fomit-frame-pointer \
- -Wall -W -Wshadow -Wstrict-prototypes -Werror \
- -Wno-unused -Wno-parentheses -Wno-switch
+LINUXCFLAGS = -DPD -O2 -funroll-loops -fomit-frame-pointer -fPIC \
+ -Wall -W -Wshadow -Wstrict-prototypes \
+ -Wno-unused -Wno-parentheses -Wno-switch $(CFLAGS)
LINUXINCLUDE = -I../../src
diff --git a/pd/extra/pique/makefile b/pd/extra/pique/makefile
index 1c1f9326..dd9a3350 100644
--- a/pd/extra/pique/makefile
+++ b/pd/extra/pique/makefile
@@ -60,9 +60,9 @@ pd_linux: $(NAME).pd_linux
.SUFFIXES: .pd_linux
-LINUXCFLAGS = -DPD -O2 -funroll-loops -fomit-frame-pointer \
- -Wall -W -Wshadow -Wstrict-prototypes -Werror \
- -Wno-unused -Wno-parentheses -Wno-switch
+LINUXCFLAGS = -DPD -O2 -funroll-loops -fomit-frame-pointer -fPIC \
+ -Wall -W -Wshadow -Wstrict-prototypes \
+ -Wno-unused -Wno-parentheses -Wno-switch $(CFLAGS)
LINUXINCLUDE = -I../../src
diff --git a/pd/portaudio_v18/docs/index.html b/pd/portaudio_v18/docs/index.html
index bd94eaa7..f92cd110 100644
--- a/pd/portaudio_v18/docs/index.html
+++ b/pd/portaudio_v18/docs/index.html
@@ -61,8 +61,24 @@ Feedback welcome.</blockquote>
<h3>
<a href="v19-doxydocs/">API Reference for V19</a></h3>
-<blockquote>Reference documents for the Application Programmer Interface
-for V19 generated by doxygen.</blockquote>
+<blockquote>
+ <p>Reference documents for the Application Programmer Interface
+ for V19 generated by doxygen.</p>
+</blockquote>
+ <h3> Paper presented at ACMC2003</h3>
+ <blockquote>
+ <p>"PortAudio and Media Synchronisation" - Discusses how the V19 API relates to
+ various synchronisation tasks including MIDI controlled playback, GUI/Audio
+ sync and MIDI sync. <a href="http://www.portaudio.com/docs/portaudio_sync_acmc2003.pdf">http://www.portaudio.com/docs/portaudio_sync_acmc2003.pdf </a> (PDF)</p>
+</blockquote>
+ <h3>Programmer's Guides</h3>
+
+<ul>
+<li>
+<a href="http://www.numerix-dsp.com/files/portaudio.html" target="_blank">
+Compilation Information For Borland C/C++ And wxWindows by John Edwards
+</li>
+</ul>
<hr WIDTH="100%">
<h2>
diff --git a/pd/portaudio_v18/docs/pa_tut_mac_osx.html b/pd/portaudio_v18/docs/pa_tut_mac_osx.html
index 44b13883..bc33f44a 100644
--- a/pd/portaudio_v18/docs/pa_tut_mac_osx.html
+++ b/pd/portaudio_v18/docs/pa_tut_mac_osx.html
@@ -30,13 +30,15 @@ Compiling for Macintosh OS X</h2>
<blockquote>To compile a Macintosh OS X CoreAudio application with the
PortAudio library you will use the following source files:
-<blockquote>pa_mac_core/pa_mac_core.c<br>
-pa_common/pa_lib.c<br>
-pa_common/portaudio.h<br>
-pa_common/pa_host.h<br>
-pa_common/pa_convert.c<br>
-pablio/ringbuffer.c<br>
-pablio/ringbuffer.h</blockquote>
+<blockquote>pa_mac_core/pa_mac_core.c
+<br>pa_common/pa_lib.c
+<br>pa_common/portaudio.h
+<br>pa_common/pa_host.h
+<br>pa_common/pa_convert.c
+<br>pa_common/pa_trace.c
+<br>pa_common/pa_trace.h
+<br>pablio/ringbuffer.c
+<br>pablio/ringbuffer.h</blockquote>
</blockquote>
<h3>
@@ -53,7 +55,7 @@ the simplest.</blockquote>
<h3>
Or Using Metrowerks CodeWarrior 8</h3>
-<blockquote>by James Vanlommel</blockquote>
+<blockquote>by James Van Lommel</blockquote>
<blockquote>Create a new CodeWarrior project using Mac OS C++ Stationery.
<br>Then choose Mac OS X Mach-O > Standard Console > C++ Console Mach-O.
@@ -61,19 +63,19 @@ Or Using Metrowerks CodeWarrior 8</h3>
files from above to your Project.
<p>Add a test file of your choosing, like
<br>&nbsp;&nbsp; patests&nbsp;&nbsp;&nbsp; /patest_sine8.c
-<br>&nbsp;
-<br>Add the frameworks to the Frameworks tab using Project > Add Files...
+<p>Add the frameworks to the Frameworks tab using Project > Add Files...
<br>&nbsp;&nbsp; CoreAudio
<br>&nbsp;&nbsp; AudioToolbox
<p>(The System framework should already be a part of the project.)
<p>Open the current target's settings, and in Language Settings > C/C++
Language, uncheck (disable) the "ANSI Strict" setting. (Do this for both
-Debug and Release projects, if necessary.)
+Debug and Release projects, if necessary.) You may also choose to disable
+RTTI and exceptions; the most important settings are 'Force C++ compilation'
+(enabled) and 'ANSI Strict' (disabled)."
<p>Edit pa_mac_core.c:
<br>&nbsp;&nbsp; On line 1546, cast the PaHost_AllocateFastMemory() result
to a (char *) or you will get a compile error.
-<br>&nbsp;
-<br>Compile and run. (may need to run from a terminal window)
+<p>Compile and run. (may need to run from a terminal window)
<p>I've successfully built patest_sine8.c this way using the CVS .tar version
of portaudio (date: 2003-04-27). I get 17 warnings during compilation,
all of which deal with unused variables or arguments.</blockquote>
diff --git a/pd/portaudio_v18/docs/portaudio_icmc2001.pdf b/pd/portaudio_v18/docs/portaudio_icmc2001.pdf
index 747016e1..dd074b7d 100644
--- a/pd/portaudio_v18/docs/portaudio_icmc2001.pdf
+++ b/pd/portaudio_v18/docs/portaudio_icmc2001.pdf
Binary files differ
diff --git a/pd/portaudio_v18/pa_asio/Callback_adaptation_.pdf b/pd/portaudio_v18/pa_asio/Callback_adaptation_.pdf
index b1014959..76bf6786 100644
--- a/pd/portaudio_v18/pa_asio/Callback_adaptation_.pdf
+++ b/pd/portaudio_v18/pa_asio/Callback_adaptation_.pdf
Binary files differ
diff --git a/pd/portaudio_v18/pa_asio/Pa_ASIO.pdf b/pd/portaudio_v18/pa_asio/Pa_ASIO.pdf
index 1b5d668f..ac5ecadb 100644
--- a/pd/portaudio_v18/pa_asio/Pa_ASIO.pdf
+++ b/pd/portaudio_v18/pa_asio/Pa_ASIO.pdf
Binary files differ
diff --git a/pd/portaudio_v18/pa_asio/pa_asio.cpp b/pd/portaudio_v18/pa_asio/pa_asio.cpp
index cec01134..717ee558 100644
--- a/pd/portaudio_v18/pa_asio/pa_asio.cpp
+++ b/pd/portaudio_v18/pa_asio/pa_asio.cpp
@@ -1,5 +1,5 @@
/*
- * $Id: pa_asio.cpp,v 1.7.4.5 2003/06/30 16:27:10 stephane Exp $
+ * $Id: pa_asio.cpp,v 1.7.4.8 2003/08/14 06:44:25 stephane Exp $
* Portable Audio I/O Library for ASIO Drivers
*
* Author: Stephane Letz
@@ -66,8 +66,11 @@
we try again with the preferred size. Fix an old (never detected?) bug in the buffer adapdation code : S Letz
30-06-03 The audio callback was not protected against reentrancy : some drivers (like the Hoontech DSP24) seems to cause this behaviour
that corrupted the buffer adapdation state and finally caused crashes. The reentrancy state is now checked in bufferSwitchTimeInfo : S Letz
-
- TO DO :
+ 17-07-03 Correct bug in Pa_ASIO_Convert_Inter_Output : parameter past_InputSampleFormat was used instead of past_OutputSampleFormat : J Maillard, S Letz
+ 25-07-03 Use of atomic operations for reenterCounter management on Windows, need to be implemented on MacOS9 : S Letz
+ 14-08-03 OutTime value in the audio callback was not updated correctly : S Letz
+
+ TO DO :
- Check Pa_StopSteam and Pa_AbortStream
- Optimization for Input only or Ouput only (really necessary ??)
@@ -158,7 +161,6 @@ typedef struct PaHostSoundControl
bool stopped;
ASIOCallbacks pahsc_asioCallbacks;
-
int32 pahsc_userInputBufferFrameOffset; // Position in Input user buffer
int32 pahsc_userOutputBufferFrameOffset; // Position in Output user buffer
@@ -301,7 +303,6 @@ unsigned long get_sys_reference_time();
#define max(a,b) ((a)>=(b)?(a):(b))
#endif
-
static bool Pa_ASIO_loadAsioDriver(char *name)
{
#ifdef WINDOWS
@@ -311,7 +312,6 @@ static bool Pa_ASIO_loadAsioDriver(char *name)
}
-
// Utilities for alignement buffer size computation
static int PGCD (int a, int b) {return (b == 0) ? a : PGCD (b,a%b);}
static int PPCM (int a, int b) {return (a*b) / PGCD (a,b);}
@@ -574,8 +574,7 @@ static PaError Pa_ASIO_QueryDeviceInfo( internalPortAudioDevice * ipad )
sNumDevices++;
}
-
- }
+ }
}
}
@@ -668,6 +667,17 @@ long asioMessages(long selector, long value, void* message, double* opt)
return ret;
}
+//----------------------------------------------------------------------------------
+// Atomic increment and decrement operations
+#if MAC
+ /* need to be implemented on Mac */
+ inline long Pa_AtomicIncrement(long* v) {return ++(*v);}
+ inline long Pa_AtomicDecrement(long* v) {return --(*v);}
+#elif WINDOWS
+ inline long Pa_AtomicIncrement(long* v) {return InterlockedIncrement(v);}
+ inline long Pa_AtomicDecrement(long* v) {return InterlockedDecrement(v);}
+#endif
+
//----------------------------------------------------------------------------------
// conversion from 64 bit ASIOSample/ASIOTimeStamp to double float
@@ -725,9 +735,9 @@ static ASIOTime *bufferSwitchTimeInfo(ASIOTime *timeInfo, long index, ASIOBool p
// Keep sample position
asioDriverInfo.pahsc_NumFramesDone = timeInfo->timeInfo.samplePosition.lo;
-
+
// Reentrancy control
- if( ++asioDriverInfo.reenterCount) {
+ if(Pa_AtomicIncrement(&asioDriverInfo.reenterCount)) {
asioDriverInfo.reenterError++;
DBUG(("bufferSwitchTimeInfo : reentrancy detection = %d\n", asioDriverInfo.reenterError));
return 0L;
@@ -751,7 +761,7 @@ static ASIOTime *bufferSwitchTimeInfo(ASIOTime *timeInfo, long index, ASIOBool p
// Finally if the driver supports the ASIOOutputReady() optimization, do it here, all data are in place
if (asioDriverInfo.pahsc_postOutput) ASIOOutputReady();
- }else {
+ }else{
/* CPU usage */
Pa_StartUsageCalculation(asioDriverInfo.past);
@@ -767,7 +777,7 @@ static ASIOTime *bufferSwitchTimeInfo(ASIOTime *timeInfo, long index, ASIOBool p
Pa_EndUsageCalculation(asioDriverInfo.past);
}
- } while(asioDriverInfo.reenterCount--);
+ } while(Pa_AtomicDecrement(&asioDriverInfo.reenterCount) >= 0);
return 0L;
}
@@ -1789,6 +1799,8 @@ static void Pa_ASIO_Callback_Input(long index)
/* Call PortAudio callback */
userResult = asioDriverInfo.past->past_Callback(past->past_InputBuffer, past->past_OutputBuffer,
past->past_FramesPerUserBuffer,past->past_FrameCount,past->past_UserData );
+
+ past->past_FrameCount += (PaTimestamp) past->past_FramesPerUserBuffer;
/* User callback has asked us to stop in the middle of the host buffer */
if( userResult != 0) {
@@ -1861,7 +1873,7 @@ static void Pa_ASIO_Callback_Output(long index, long framePerBuffer)
asioDriverInfo.pahsc_hostOutputBufferFrameOffset,
asioDriverInfo.pahsc_userOutputBufferFrameOffset,
asioDriverInfo.pahsc_channelInfos[0].type,
- past->past_InputSampleFormat,
+ past->past_OutputSampleFormat,
past->past_Flags,
index);
diff --git a/pd/portaudio_v18/pa_mac_core/notes.txt b/pd/portaudio_v18/pa_mac_core/notes.txt
index 3b557d9a..0abdd3db 100644
--- a/pd/portaudio_v18/pa_mac_core/notes.txt
+++ b/pd/portaudio_v18/pa_mac_core/notes.txt
@@ -32,3 +32,5 @@ input, output or both.
When we query devices, we first get a list of CoreAudio devices. Then
we scan the list and add a PortAudio device for each CoreAudio device
that supports input. Then we make a scan for output devices.
+
+(minor change to test CVS)
diff --git a/pd/portaudio_v18/pa_mac_core/pa_mac_core.c b/pd/portaudio_v18/pa_mac_core/pa_mac_core.c
index e0a31374..983d0e4f 100644
--- a/pd/portaudio_v18/pa_mac_core/pa_mac_core.c
+++ b/pd/portaudio_v18/pa_mac_core/pa_mac_core.c
@@ -1,5 +1,5 @@
/*
- * $Id: pa_mac_core.c,v 1.8.4.12 2003/04/16 19:06:01 philburk Exp $
+ * $Id: pa_mac_core.c,v 1.8.4.13 2003/12/09 19:04:54 philburk Exp $
* pa_mac_core.c
* Implementation of PortAudio for Mac OS X Core Audio
*
@@ -108,13 +108,17 @@
Overlap creation and deletion of AudioConverters to prevent thread death when device rate changes.
04.16.2003 - Phil Burk - Fixed input channel scrambling when numChannels != 2^N. Caused by alignment
error when filling RingBuffer with 2^N zero bytes.
+ 04.26.2003 - Phil Burk - Removed code to turn up volume and unmute to prevent blown eardrums.
+ 12.08.2003 - Phil Burk - Move declaration of oldConverter to top of PAOSX_DevicePropertyListener()
+ 12.08.2003 - Phil Burk - Removed need for #include "pa_trace.h", just for debug
+ 12.09.2003 - Phil Burk - Only change sampleRate or numChannels if we need to improve over
+ current setting.
*/
#include <CoreServices/CoreServices.h>
#include <CoreAudio/CoreAudio.h>
#include <sys/time.h>
#include <sys/resource.h>
-#include <unistd.h>
#include <AudioUnit/AudioUnit.h>
#include <AudioToolbox/DefaultAudioOutput.h>
#include <AudioToolbox/AudioConverter.h>
@@ -122,7 +126,6 @@
#include "portaudio.h"
#include "pa_host.h"
-#include "pa_trace.h"
#include "ringbuffer.h"
/************************************************* Configuration ********/
@@ -795,7 +798,6 @@ static OSStatus PaOSX_LoadAndProcess( internalPortAudioStream *past,
if( outputBuffer )
{
/* Clear remainder of audio buffer if we are waiting for stop. */
- AddTraceMessage("PaOSX_LoadAndProcess: zero rest of wave buffer ", i );
memset( outputBuffer, 0, pahsc->output.bytesPerUserNativeBuffer );
}
}
@@ -1218,11 +1220,13 @@ static PaError PaOSX_SetFormat( AudioDeviceID devID, Boolean isInput,
originalRate = formatDesc.mSampleRate;
originalChannels = formatDesc.mChannelsPerFrame;
- // Is it already set to the correct format?
- if( (originalRate != desiredRate) || (originalChannels != desiredNumChannels) )
+ // Changing the format can mess up other apps.
+ // So only change the format if the original format
+ // has a lower sample rate, or fewer channels, than the desired format.
+ if( (originalRate < desiredRate) || (originalChannels < desiredNumChannels) )
{
- DBUG(("PaOSX_SetFormat: try to change sample rate to %f.\n", desiredRate ));
- DBUG(("PaOSX_SetFormat: try to set number of channels to %d\n", desiredNumChannels));
+ DBUG(("PaOSX_SetFormat: try to change sample rate from %f to %f.\n", originalRate, desiredRate ));
+ DBUG(("PaOSX_SetFormat: try to set number of channels %d to %d\n", originalChannels, desiredNumChannels));
formatDesc.mSampleRate = desiredRate;
formatDesc.mChannelsPerFrame = desiredNumChannels;
@@ -1256,76 +1260,6 @@ static PaError PaOSX_SetFormat( AudioDeviceID devID, Boolean isInput,
return result;
}
-/*******************************************************************
- * Check volume level of device. If below threshold, then set to newLevel.
- * Using volume instead of decibels because decibel range varies by device.
- */
-static void PaOSX_FixVolumeScalars( AudioDeviceID devID, Boolean isInput,
- int numChannels, double threshold, double newLevel )
-{
- OSStatus err = noErr;
- UInt32 dataSize;
- int iChannel;
-
-/* The master channel is 0. Left and right are channels 1 and 2. */
-/* Fix volume. */
- for( iChannel = 0; iChannel<=numChannels; iChannel++ )
- {
- Float32 fdata32;
- dataSize = sizeof( fdata32 );
- err = AudioDeviceGetProperty( devID, iChannel, isInput,
- kAudioDevicePropertyVolumeScalar, &dataSize, &fdata32 );
- if( err == noErr )
- {
- DBUG(("kAudioDevicePropertyVolumeScalar for channel %d = %f\n", iChannel, fdata32));
- if( fdata32 <= (Float32) threshold )
- {
- dataSize = sizeof( fdata32 );
- fdata32 = (Float32) newLevel;
- err = AudioDeviceSetProperty( devID, 0, iChannel, isInput,
- kAudioDevicePropertyVolumeScalar, dataSize, &fdata32 );
- if( err != noErr )
- {
- PRINT(("Warning: audio volume is very low and could not be turned up.\n"));
- }
- else
- {
- PRINT(("Volume for audio channel %d was <= %4.2f so set to %4.2f by PortAudio!\n",
- iChannel, threshold, newLevel ));
- }
- }
- }
- }
-/* Unmute if muted. */
- for( iChannel = 0; iChannel<=numChannels; iChannel++ )
- {
- UInt32 uidata32;
- dataSize = sizeof( uidata32 );
- err = AudioDeviceGetProperty( devID, iChannel, isInput,
- kAudioDevicePropertyMute, &dataSize, &uidata32 );
- if( err == noErr )
- {
- DBUG(("mute for channel %d = %ld\n", iChannel, uidata32));
- if( uidata32 == 1 ) // muted?
- {
- dataSize = sizeof( uidata32 );
- uidata32 = 0; // unmute
- err = AudioDeviceSetProperty( devID, 0, iChannel, isInput,
- kAudioDevicePropertyMute, dataSize, &uidata32 );
- if( err != noErr )
- {
- PRINT(("Warning: audio is muted and could not be unmuted!\n"));
- }
- else
- {
- PRINT(("Audio channel %d was unmuted by PortAudio!\n", iChannel ));
- }
- }
- }
- }
-
-}
-
#if 0
static void PaOSX_DumpDeviceInfo( AudioDeviceID devID, Boolean isInput )
{
@@ -1413,6 +1347,7 @@ static OSStatus PAOSX_DevicePropertyListener (AudioDeviceID inDevice,
AudioStreamBasicDescription userStreamFormat, hardwareStreamFormat;
PaHostInOut *hostInOut;
AudioStreamBasicDescription *destFormatPtr, *srcFormatPtr;
+ AudioConverterRef oldConverter = NULL; // PLB 20031208 - Declare here for standard 'C'.
past = (internalPortAudioStream *) inClientData;
pahsc = (PaHostSoundControl *) past->past_DeviceData;
@@ -1465,7 +1400,7 @@ static OSStatus PAOSX_DevicePropertyListener (AudioDeviceID inDevice,
// Don't delete old converter until we create new one so we don't pull
// the rug out from under other audio threads.
- AudioConverterRef oldConverter = hostInOut->converter;
+ oldConverter = hostInOut->converter;
// Make converter to change sample rate.
err = AudioConverterNew (
@@ -1595,8 +1530,6 @@ static PaError PaOSX_OpenCommonDevice( internalPortAudioStream *past,
OSStatus err = noErr;
Float64 deviceRate;
- PaOSX_FixVolumeScalars( inOut->audioDeviceID, isInput,
- inOut->numChannels, 0.1, 0.9 );
// The HW device format changes are asynchronous.
// So we don't know when or if the PAOSX_DevicePropertyListener() will
diff --git a/pd/portmidi_osx/README b/pd/portmidi_osx/README
index de44270b..bbbbbfe9 100644
--- a/pd/portmidi_osx/README
+++ b/pd/portmidi_osx/README
@@ -1,6 +1,6 @@
PortMidi for MacOS X / Darwin
Jon Parise <jparise@cmu.edu>
-$Date: 2004-02-22 16:21:33 $
+$Date: 2004-09-06 20:20:32 $
This is the MacOS X / Darwin port of the PortMidi library from the Carnegie
Mellon Computer Music Group. It is based on the Apple CoreAudio MIDI
diff --git a/pd/portmidi_osx/pmdarwin.c b/pd/portmidi_osx/pmdarwin.c
index 4fe71033..17696dad 100644
--- a/pd/portmidi_osx/pmdarwin.c
+++ b/pd/portmidi_osx/pmdarwin.c
@@ -2,7 +2,7 @@
* PortMidi OS-dependent interface for Darwin (MacOS X)
* Jon Parise <jparise@cmu.edu>
*
- * $Id: pmdarwin.c,v 1.2 2004-02-22 16:21:47 ggeiger Exp $
+ * $Id: pmdarwin.c,v 1.3 2004-09-06 20:20:33 millerpuckette Exp $
*
* CHANGE LOG:
* 03Jul03 - X. J. Scott (xjs):
diff --git a/pd/portmidi_osx/pmmacosx.c b/pd/portmidi_osx/pmmacosx.c
index e40d90a2..de8fe59a 100644
--- a/pd/portmidi_osx/pmmacosx.c
+++ b/pd/portmidi_osx/pmmacosx.c
@@ -3,7 +3,7 @@
*
* Jon Parise <jparise@cmu.edu>
*
- * $Id: pmmacosx.c,v 1.2 2004-02-22 16:21:47 ggeiger Exp $
+ * $Id: pmmacosx.c,v 1.3 2004-09-06 20:20:33 millerpuckette Exp $
*
* 27Jun02 XJS (X. J. Scott)
* - midi_length():
diff --git a/pd/portmidi_osx/ptdarwin.c b/pd/portmidi_osx/ptdarwin.c
index 879b60f1..31537f1f 100644
--- a/pd/portmidi_osx/ptdarwin.c
+++ b/pd/portmidi_osx/ptdarwin.c
@@ -3,7 +3,7 @@
*
* Jon Parise <jparise@cmu.edu>
*
- * $Id: ptdarwin.c,v 1.2 2004-02-22 16:21:47 ggeiger Exp $
+ * $Id: ptdarwin.c,v 1.3 2004-09-06 20:20:33 millerpuckette Exp $
*/
#include <stdio.h>
diff --git a/pd/src/CHANGELOG.txt b/pd/src/CHANGELOG.txt
index 27441d36..c8cc8f49 100644
--- a/pd/src/CHANGELOG.txt
+++ b/pd/src/CHANGELOG.txt
@@ -1,6 +1,17 @@
This file describes implementation and API changes; stuff more visible to the
user appears in the "release notes" instead.
+0.38.0
+
+fixed empty lists automatically to call "bang" method if one is supplied.
+
+rewrote the "namelist" stuff to facilitate preference saving (s_stuff.h,
+s_path.c, s_file.c, s_main.c)
+
+0.37.2
+
+expr() "exp" temporary variables renamed to avoid compilation problems
+
0.37.1
makefile.in: MANINSTDIR = $(DESTDIR)/$(MANDIR) changed to
diff --git a/pd/src/configure.in b/pd/src/configure.in
index 7d0346bf..66ba7178 100644
--- a/pd/src/configure.in
+++ b/pd/src/configure.in
@@ -4,6 +4,7 @@ AC_INIT(d_arithmetic.c)
AC_SUBST(alsa, yes)
AC_SUBST(jack, no)
AC_SUBST(portaudio, no)
+AC_SUBST(binarymode, -m755)
AC_SUBST(PDLIB)
AC_SUBST(MORECFLAGS)
AC_SUBST(EXT)
@@ -20,16 +21,18 @@ dnl other defaults
dnl check for features
-AC_ARG_ENABLE(alsa, [ --disable-alsa disable ALSA],
+AC_ARG_ENABLE(alsa, [ --disable-alsa disable ALSA],
alsa="no")
-AC_ARG_ENABLE(jack, [ --enable-jack jack audio server],
+AC_ARG_ENABLE(jack, [ --enable-jack jack audio server],
jack="yes")
-AC_ARG_ENABLE(portaudio, [ --enable-portaudio portaudio],
+AC_ARG_ENABLE(portaudio,[ --enable-portaudio portaudio],
portaudio="yes")
-AC_ARG_ENABLE(debug, [ --enable-debug debugging support],
+AC_ARG_ENABLE(debug, [ --enable-debug debugging support],
USE_OPT_CFLAGS="no")
AC_ARG_ENABLE(static, [ --enable-static link statically],
static=yes)
+AC_ARG_ENABLE(setuid, [ --enable-setuid install as setuid (linux)],
+ setuid=yes)
dnl Checks for programs.
AC_PROG_CC
@@ -159,22 +162,24 @@ dnl This should be fixed so Pd can use ALSA shared libraries where appropriate.
LDFLAGS="$LDFLAGS -static"
fi
EXT=pd_linux
- MORECFLAGS="-DDL_OPEN -DPA_USE_OSS -DPA_LITTLE_ENDIAN \
+ MORECFLAGS="-DDL_OPEN -DPA_USE_OSS -DPA_LITTLE_ENDIAN -DUNIX -DUNISTD\
-DUSEAPI_OSS \
- -I../portaudio/pa_common \
- -I../portaudio/pablio -I../portaudio/portmidi-macosx \
+ -I../portaudio/pa_common -I../portaudio/pablio \
+ -I../portaudio/portmidi-macosx \
-fno-strict-aliasing"
SYSSRC="s_midi_oss.c s_audio_oss.c"
if test x$alsa == "xyes";
then
- SYSSRC=$SYSSRC" s_audio_alsa.c"
+ SYSSRC=$SYSSRC" s_audio_alsa.c s_audio_alsamm.c"
MORECFLAGS=$MORECFLAGS" -DPA_USE_ALSA -DUSEAPI_ALSA"
LDFLAGS=$LDFLAGS" -lasound"
fi
if test x$portaudio == "xyes";
then
- MORECFLAGS="-DUSEAPI_PORTAUDIO "$MORECFLAGS
+ MORECFLAGS="-DUSEAPI_PORTAUDIO -DPA19 "$MORECFLAGS
SYSSRC="s_audio_pa.c \
+ s_audio_pablio.c \
+ s_audio_paring.c \
../portaudio/pa_common/pa_allocation.c \
../portaudio/pa_common/pa_converters.c \
../portaudio/pa_common/pa_cpuload.c \
@@ -184,19 +189,19 @@ dnl This should be fixed so Pd can use ALSA shared libraries where appropriate.
../portaudio/pa_common/pa_skeleton.c \
../portaudio/pa_common/pa_stream.c \
../portaudio/pa_common/pa_trace.c \
- ../portaudio/pablio/pablio_pd.c \
- ../portaudio/pablio/ringbuffer_pd.c \
../portaudio/pa_unix/pa_unix_hostapis.c \
../portaudio/pa_unix/pa_unix_util.c \
../portaudio/pa_unix_oss/pa_unix_oss.c "$SYSSRC
if test x$alsa == "xyes";
then
- SYSSRC=$SYSSRC" \
- ../portaudio/pa_linux_alsa/callback_thread.c \
- ../portaudio/pa_linux_alsa/pa_linux_alsa.c \
- ../portaudio/pa_linux_alsa/blocking_calls.c "
+ SYSSRC=$SYSSRC" ../portaudio/pa_linux_alsa/pa_linux_alsa.c"
+ MORECFLAGS=$MORECFLAGS" -Wno-error"
fi
fi
+ if test x$setuid == "xyes";
+ then
+ binarymode="-m4755"
+ fi
STRIPFLAG=-s
GUINAME="pd-gui"
if test x$USE_OPT_CFLAGS == "xyes";
@@ -211,22 +216,21 @@ fi
if test `uname -s` = Darwin;
then
- LDFLAGS="-Wl -framework Tcl -framework Tk -framework CoreAudio \
+ LDFLAGS="-Wl -framework CoreAudio \
-framework AudioUnit -framework AudioToolbox \
-framework Carbon -framework CoreMIDI"
EXT=pd_darwin
- MORECFLAGS="-DMACOSX -I/usr/X11R6/include \
- -I../portaudio_v18/pa_common \
- -I../portaudio_v18/pablio \
+ MORECFLAGS="-DMACOSX -DUNISTD -I/usr/X11R6/include \
+ -I../portaudio_v18/pa_common -I../portaudio_v18/pablio \
-I../portmidi_osx \
-Wno-error \
-DUSEAPI_PORTAUDIO -DPA_BIG_ENDIAN"
SYSSRC="s_midi_pm.c s_audio_pa.c \
+ s_audio_pablio.c \
+ s_audio_paring.c \
../portaudio_v18/pa_common/pa_lib.c \
../portaudio_v18/pa_common/pa_trace.c \
../portaudio_v18/pa_common/pa_convert.c \
- ../portaudio_v18/pablio/pablio_pd.c \
- ../portaudio_v18/pablio/ringbuffer_pd.c \
../portaudio_v18/pa_mac_core/pa_mac_core.c \
../portmidi_osx/pmdarwin.c \
../portmidi_osx/pmmacosx.c \
@@ -235,10 +239,10 @@ then
../portmidi_osx/ptdarwin.c "
STRIPFLAG=""
GUINAME="pdtcl"
- GUIFLAGS="-framework Tcl -framework Tk \
- -I/Library/Frameworks/Tk.framework/Versions/Current/Headers \
- -I/Library/Frameworks/Tcl.framework/Versions/Current/Headers \
- -I/Library/Frameworks/Tcl.framework/Versions/8.4/PrivateHeaders"
+ GUIFLAGS="-F../../Frameworks -framework Tcl -framework Tk \
+ -I../../Frameworks/Tk.framework/Versions/Current/Headers \
+ -I../../Frameworks/Tcl.framework/Versions/Current/Headers \
+ -I../../Frameworks/Tcl.framework/Versions/8.4/PrivateHeaders"
if test x$USE_OPT_CFLAGS == "xyes";
then
OPT_CFLAGS="-O2"
@@ -256,6 +260,7 @@ then
fi
# support for jack, on either linux or darwin:
+
if test x$jack == "xyes";
then
MORECFLAGS=$MORECFLAGS" -DUSEAPI_JACK"
diff --git a/pd/src/configure.in.ok b/pd/src/configure.in.ok
deleted file mode 100644
index 897eafdf..00000000
--- a/pd/src/configure.in.ok
+++ /dev/null
@@ -1,248 +0,0 @@
-dnl Process this file with autoconf to produce a configure script.
-AC_INIT(d_arithmetic.c)
-
-AC_SUBST(alsa)
-AC_SUBST(jack, no)
-AC_SUBST(portaudio)
-AC_SUBST(PDLIB)
-AC_SUBST(DEFINES)
-AC_SUBST(MORECFLAGS)
-AC_SUBST(EXT)
-AC_SUBST(OPT_CFLAGS)
-AC_SUBST(USE_OPT_CFLAGS, YES)
-AC_SUBST(SYSSRC)
-AC_SUBST(STRIPFLAG)
-AC_SUBST(GUINAME)
-AC_SUBST(GUIFLAGS)
-AC_SUBST(OSNUMBER)
-AC_SUBST(EXTERNTARGET)
-
-dnl other defaults
-
-dnl check for features
-
-AC_ARG_ENABLE(alsa, [ --disable-alsa disable ALSA],
- alsa="no")
-AC_ARG_ENABLE(jack, [ --enable-jack jack audio server],
- jack="yes")
-AC_ARG_ENABLE(portaudio, [ --enable-portaudio portaudio],
- portaudio="yes")
-AC_ARG_ENABLE(debug, [ --enable-debug debugging support],
- USE_OPT_CFLAGS="no")
-
-dnl Checks for programs.
-AC_PROG_CC
-AC_PROG_INSTALL
-AC_PROG_MAKE_SET
-AC_PROG_CPP
-
-dnl Checks for typedefs, structures, and compiler characteristics.
-AC_C_CONST
-AC_TYPE_PID_T
-AC_TYPE_SIZE_T
-AC_HEADER_TIME
-
-dnl Checks for header files.
-AC_HEADER_STDC
-AC_CHECK_HEADERS(fcntl.h limits.h malloc.h sys/ioctl.h sys/time.h unistd.h bstring.h)
-
-dnl Checks for library functions.
-AC_PROG_GCC_TRADITIONAL
-AC_TYPE_SIGNAL
-AC_FUNC_VPRINTF
-AC_CHECK_FUNCS(gettimeofday select socket strerror)
-
-
-dnl Checks for libraries.
-dnl Checking for `dlopen' function in -ldl:
-AC_CHECK_LIB(dl, dlopen,PDLIB="$PDLIB -ldl",
- echo "dynamic link support required" || exit 1)
-
-dnl Checking for `sin' function in -lffm:
-dnl ffm is the fast math library on the alpha
-AC_CHECK_LIB(ffm, sin,PDLIB="$PDLIB -lffm")
-
-dnl Checking for `sin' function in -lm:
-AC_CHECK_LIB(m, sin,PDLIB="$PDLIB -lm",
- echo "math library required" || exit 1)
-
-dnl Checking for `pthread_create' function in -pthread
-AC_CHECK_LIB(pthread, pthread_create,PDLIB="$PDLIB -lpthread",
- echo "pthreads required" || exit 1)
-
-dnl This should be fixed so Pd can use ALSA shared libraries where appropriate.
-if test "$alsa" != no; then
- AC_CHECK_LIB(asound,snd_pcm_info,PDLIB="$PDLIB -lasound" ; alsa="yes",alsa="")
-fi
-
-dnl Find paths to includes and libraries for X11
-AC_PATH_X
-dnl Checking for `XCreateWindow' function in -lX11:
-AC_CHECK_LIB(X11, XCreateWindow, LIBS="$LIBS -lX11 -L$x_libraries",
- echo "no X11 found" || exit 1, -L$x_libraries)
-
-dnl look for tcl 8.x... do I really have to go through all this!?
-
-foundit=no
-if test $foundit == "no";
-then
- AC_CHECK_HEADER(tcl.h,foundit=yes,)
-fi
-if test $foundit == "no";
-then
- AC_CHECK_HEADER(tcl8.7/tcl.h,
- GUIFLAGS="$GUIFLAGS -I/usr/include/tcl8.7";foundit=yes,)
-fi
-if test $foundit == "no";
-then
- AC_CHECK_HEADER(tcl8.6/tcl.h,
- GUIFLAGS="$GUIFLAGS -I/usr/include/tcl8.6";foundit=yes,)
-fi
-if test $foundit == "no";
-then
- AC_CHECK_HEADER(tcl8.5/tcl.h,
- GUIFLAGS="$GUIFLAGS -I/usr/include/tcl8.5";foundit=yes,)
-fi
-if test $foundit == "no";
-then
- AC_CHECK_HEADER(tcl8.4/tcl.h,
- GUIFLAGS="$GUIFLAGS -I/usr/include/tcl8.4";foundit=yes,)
-fi
-if test $foundit == "no";
-then
- AC_CHECK_HEADER(tcl8.3/tcl.h,
- GUIFLAGS="$GUIFLAGS -I/usr/include/tcl8.3";foundit=yes,)
-fi
-if test $foundit == "no";
-then
- AC_CHECK_HEADER(tcl8.2/tcl.h,
- GUIFLAGS="$GUIFLAGS -I/usr/include/tcl8.2";foundit=yes,)
-fi
-if test $foundit == "no";
-then
- echo no tcl header found
- exit -1
-fi
-
-AC_CHECK_LIB(tcl8.7, main,,
- AC_CHECK_LIB(tcl8.6, main,,
- AC_CHECK_LIB(tcl8.5, main,,
- AC_CHECK_LIB(tcl8.4, main,,
- AC_CHECK_LIB(tcl8.3, main,,
- AC_CHECK_LIB(tcl8.2, main,,
- AC_CHECK_LIB(tcl8.0, main,,echo no tcl library found || exit 1)))))))
-
-AC_CHECK_LIB(tk8.7, main,,
- AC_CHECK_LIB(tk8.6, main,,
- AC_CHECK_LIB(tk8.5, main,,
- AC_CHECK_LIB(tk8.4, main,,
- AC_CHECK_LIB(tk8.3, main,,
- AC_CHECK_LIB(tk8.2, main,,
- AC_CHECK_LIB(tk8.0, main,,echo no tk library found || exit 1)))))))
-
-dnl Checking for tk.h or tkstep.h - not used at the moment
-dnl AC_CHECK_HEADER(tk.h,DEFINES="$DEFINES -DTKINC=\\\"tk.h\\\"")
-dnl AC_CHECK_HEADER(tkstep.h,DEFINES="$DEFINES -DTKINC=\\\"tkstep.h\\\"")
-
-if test `uname -s` = Linux;
-then
- LDFLAGS="-Wl,-export-dynamic"
- EXT=pd_linux
- MORECFLAGS="-DDL_OPEN -DUSEAPI_PORTAUDIO -DPA_USE_OSS -DPA_LITTLE_ENDIAN \
- -DUSEAPI_OSS \
- -I../portaudio/pa_common \
- -I../portaudio/pablio -I../portaudio/portmidi-macosx -Werror"
- SYSSRC="s_midi_oss.c s_audio_pa.c s_audio_oss.c \
- ../portaudio/pa_common/pa_allocation.c \
- ../portaudio/pa_common/pa_converters.c \
- ../portaudio/pa_common/pa_cpuload.c \
- ../portaudio/pa_common/pa_dither.c \
- ../portaudio/pa_common/pa_front.c \
- ../portaudio/pa_common/pa_process.c \
- ../portaudio/pa_common/pa_skeleton.c \
- ../portaudio/pa_common/pa_stream.c \
- ../portaudio/pa_common/pa_trace.c \
- ../portaudio/pablio/pablio_pd.c \
- ../portaudio/pablio/ringbuffer_pd.c \
- ../portaudio/pa_unix/pa_unix_hostapis.c \
- ../portaudio/pa_unix/pa_unix_util.c \
- ../portaudio/pa_unix_oss/pa_unix_oss.c "
- STRIPFLAG=-s
- GUINAME="pd-gui"
- if test $USE_OPT_CFLAGS == "YES";
- then
- OPT_CFLAGS="-O6 -funroll-loops -fomit-frame-pointer"
- else
- OPT_CFLAGS="-g"
- fi
- OSNUMBER=0
-fi
-
-dnl **** note -- SGI/IRIX code is broken here!!! ***
-
-if test `uname -s` = IRIX64;
-then
- LDFLAGS="-n32 -DUNIX -DIRIX -DN32 -woff 1080,1064,1185 \
- -OPT:roundoff=3 -OPT:IEEE_arithmetic=3 -OPT:cray_ivdep=true \
- -shared -rdata_shared"
- EXT=pd_irix6
- MORECFLAGS=-DDL_OPEN
- SYSSRC=s_sgi.c
- STRIPFLAG=-s
- GUINAME="pd-gui"
- OSNUMBER=0
-fi
-
-if test `uname -s` = IRIX32;
-then
- LDFLAGS="-o32 -DUNIX -DIRIX -O2 -shared -rdata_shared"
- EXT=pd_irix5
- MORECFLAGS=-DDL_OPEN
- SYSSRC=s_sgi.c
- STRIPFLAG=-s
- GUINAME="pd-gui"
- OSNUMBER=0
-fi
-
-if test `uname -s` = Darwin;
-then
- LDFLAGS="-Wl -framework Tcl -framework Tk -framework CoreAudio \
- -framework AudioUnit -framework AudioToolbox \
- -framework Carbon -framework CoreMIDI"
- EXT=pd_darwin
- MORECFLAGS="-DMACOSX -I/usr/X11R6/include \
- -I../portaudio_v18/pa_common \
- -I../portaudio_v18/pablio \
- -I../portmidi_osx \
- -Wno-error \
- -DUSEAPI_PORTAUDIO -DPA_BIG_ENDIAN"
- SYSSRC="s_midi_pm.c s_audio_pa.c \
- ../portaudio_v18/pa_common/pa_lib.c \
- ../portaudio_v18/pa_common/pa_trace.c \
- ../portaudio_v18/pa_common/pa_convert.c \
- ../portaudio_v18/pablio/pablio_pd.c \
- ../portaudio_v18/pablio/ringbuffer_pd.c \
- ../portaudio_v18/pa_mac_core/pa_mac_core.c \
- ../portmidi_osx/pmdarwin.c \
- ../portmidi_osx/pmmacosx.c \
- ../portmidi_osx/pmutil.c \
- ../portmidi_osx/portmidi.c \
- ../portmidi_osx/ptdarwin.c "
- STRIPFLAG=""
- GUINAME="pdtcl"
- GUIFLAGS="-framework Tcl -framework Tk \
- -I/Library/Frameworks/Tk.framework/Versions/Current/Headers \
- -I/Library/Frameworks/Tcl.framework/Versions/Current/Headers \
- -I/Library/Frameworks/Tcl.framework/Versions/8.4/PrivateHeaders"
- if test $USE_OPT_CFLAGS == "YES";
- then
- OPT_CFLAGS="-O2"
- else
- OPT_CFLAGS="-g"
- fi
- OSNUMBER=2
- EXTERNTARGET=pd_darwin
-fi
-
-AC_OUTPUT(makefile)
-
diff --git a/pd/src/configure.in.oops b/pd/src/configure.in.oops
deleted file mode 100644
index 5a7be36e..00000000
--- a/pd/src/configure.in.oops
+++ /dev/null
@@ -1,272 +0,0 @@
-dnl Process this file with autoconf to produce a configure script.
-AC_INIT(d_arithmetic.c)
-
-AC_SUBST(alsa)
-AC_SUBST(jack, no)
-AC_SUBST(portaudio)
-AC_SUBST(PDLIB)
-AC_SUBST(DEFINES)
-AC_SUBST(MORECFLAGS)
-AC_SUBST(EXT)
-AC_SUBST(OPT_CFLAGS)
-AC_SUBST(USE_OPT_CFLAGS, YES)
-AC_SUBST(SYSSRC)
-AC_SUBST(STRIPFLAG)
-AC_SUBST(GUINAME)
-AC_SUBST(GUIFLAGS)
-AC_SUBST(OSNUMBER)
-AC_SUBST(EXTERNTARGET)
-
-dnl other defaults
-
-dnl check for features
-
-AC_ARG_ENABLE(alsa, [ --disable-alsa disable ALSA],
- alsa="no")
-AC_ARG_ENABLE(jack, [ --enable-jack jack audio server],
- jack="yes")
-AC_ARG_ENABLE(portaudio, [ --enable-portaudio portaudio],
- portaudio="yes")
-AC_ARG_ENABLE(debug, [ --enable-debug debugging support],
- USE_OPT_CFLAGS="no")
-
-dnl Checks for programs.
-AC_PROG_CC
-AC_PROG_INSTALL
-AC_PROG_MAKE_SET
-AC_PROG_CPP
-
-dnl Checks for typedefs, structures, and compiler characteristics.
-AC_C_CONST
-AC_TYPE_PID_T
-AC_TYPE_SIZE_T
-AC_HEADER_TIME
-
-dnl Checks for header files.
-AC_HEADER_STDC
-AC_CHECK_HEADERS(fcntl.h limits.h malloc.h sys/ioctl.h sys/time.h unistd.h bstring.h)
-
-dnl Checks for library functions.
-AC_PROG_GCC_TRADITIONAL
-AC_TYPE_SIGNAL
-AC_FUNC_VPRINTF
-AC_CHECK_FUNCS(gettimeofday select socket strerror)
-
-
-dnl Checks for libraries.
-dnl Checking for `dlopen' function in -ldl:
-AC_CHECK_LIB(dl, dlopen,PDLIB="$PDLIB -ldl",
- echo "dynamic link support required" || exit 1)
-
-dnl Checking for `sin' function in -lffm:
-dnl ffm is the fast math library on the alpha
-AC_CHECK_LIB(ffm, sin,PDLIB="$PDLIB -lffm")
-
-dnl Checking for `sin' function in -lm:
-AC_CHECK_LIB(m, sin,PDLIB="$PDLIB -lm",
- echo "math library required" || exit 1)
-
-dnl Checking for `pthread_create' function in -pthread
-AC_CHECK_LIB(pthread, pthread_create,PDLIB="$PDLIB -lpthread",
- echo "pthreads required" || exit 1)
-
-dnl This should be fixed so Pd can use ALSA shared libraries where appropriate.
-if test "$alsa" != no; then
- AC_CHECK_LIB(asound,snd_pcm_info,PDLIB="$PDLIB -lasound" ; alsa="yes",alsa="")
-fi
-
-dnl Find paths to includes and libraries for X11
-AC_PATH_X
-dnl Checking for `XCreateWindow' function in -lX11:
-AC_CHECK_LIB(X11, XCreateWindow, LIBS="$LIBS -lX11 -L$x_libraries",
- echo "no X11 found" || exit 1, -L$x_libraries)
-
-dnl look for tcl 8.x... do I really have to go through all this!?
-
-foundit=no
-if test $foundit == "no";
-then
- AC_CHECK_HEADER(tcl.h,foundit=yes,)
-fi
-if test $foundit == "no";
-then
- AC_CHECK_HEADER(tcl8.7/tcl.h,
- GUIFLAGS="$GUIFLAGS -I/usr/include/tcl8.7";foundit=yes,)
-fi
-if test $foundit == "no";
-then
- AC_CHECK_HEADER(tcl8.6/tcl.h,
- GUIFLAGS="$GUIFLAGS -I/usr/include/tcl8.6";foundit=yes,)
-fi
-if test $foundit == "no";
-then
- AC_CHECK_HEADER(tcl8.5/tcl.h,
- GUIFLAGS="$GUIFLAGS -I/usr/include/tcl8.5";foundit=yes,)
-fi
-if test $foundit == "no";
-then
- AC_CHECK_HEADER(tcl8.4/tcl.h,
- GUIFLAGS="$GUIFLAGS -I/usr/include/tcl8.4";foundit=yes,)
-fi
-if test $foundit == "no";
-then
- AC_CHECK_HEADER(tcl8.3/tcl.h,
- GUIFLAGS="$GUIFLAGS -I/usr/include/tcl8.3";foundit=yes,)
-fi
-if test $foundit == "no";
-then
- AC_CHECK_HEADER(tcl8.2/tcl.h,
- GUIFLAGS="$GUIFLAGS -I/usr/include/tcl8.2";foundit=yes,)
-fi
-if test $foundit == "no";
-then
- echo no tcl header found
- exit -1
-fi
-
-AC_CHECK_LIB(tcl8.7, main,,
- AC_CHECK_LIB(tcl8.6, main,,
- AC_CHECK_LIB(tcl8.5, main,,
- AC_CHECK_LIB(tcl8.4, main,,
- AC_CHECK_LIB(tcl8.3, main,,
- AC_CHECK_LIB(tcl8.2, main,,
- AC_CHECK_LIB(tcl8.0, main,,echo no tcl library found || exit 1)))))))
-
-AC_CHECK_LIB(tk8.7, main,,
- AC_CHECK_LIB(tk8.6, main,,
- AC_CHECK_LIB(tk8.5, main,,
- AC_CHECK_LIB(tk8.4, main,,
- AC_CHECK_LIB(tk8.3, main,,
- AC_CHECK_LIB(tk8.2, main,,
- AC_CHECK_LIB(tk8.0, main,,echo no tk library found || exit 1)))))))
-
-dnl Checking for tk.h or tkstep.h - not used at the moment
-dnl AC_CHECK_HEADER(tk.h,DEFINES="$DEFINES -DTKINC=\\\"tk.h\\\"")
-dnl AC_CHECK_HEADER(tkstep.h,DEFINES="$DEFINES -DTKINC=\\\"tkstep.h\\\"")
-
-if test `uname -s` = Linux;
-then
- dnl Ckecking for ALSA
-
- AC_CHECK_LIB(asound,snd_pcm_open,LIBS="$LIBS -lasound";alsa=yes,alsa=no)
-
- dnl Checking for JACK
-
- AC_CHECK_LIB(rt,shm_open,LIBS="$LIBS -lrt")
- AC_CHECK_LIB(jack,jack_set_xrun_callback,LIBS="$LIBS -ljack";jack=xrun,jack=no)
- AC_CHECK_LIB(jack,jack_set_error_function,LIBS="$LIBS -ljack";jack=yes,jack=no)
-
- LDFLAGS="-Wl,-export-dynamic"
- EXT=pd_linux
- MORECFLAGS="-DDL_OPEN -DPA_USE_OSS -DPA_LITTLE_ENDIAN \
- -DUSEAPI_OSS \
- -I../portaudio/pa_common \
- -I../portaudio/pablio -I../portaudio/portmidi-macosx -Werror"
- SYSSRC="s_midi_oss.c s_audio_oss.c"
- if test x$portaudio == "xYES";
- then
- MORECFLAGS="-DUSEAPI_PORTAUDIO "$MORECFLAGS
- SYSSRC="s_audio_pa.c \
- ../portaudio/pa_common/pa_allocation.c \
- ../portaudio/pa_common/pa_converters.c \
- ../portaudio/pa_common/pa_cpuload.c \
- ../portaudio/pa_common/pa_dither.c \
- ../portaudio/pa_common/pa_front.c \
- ../portaudio/pa_common/pa_process.c \
- ../portaudio/pa_common/pa_skeleton.c \
- ../portaudio/pa_common/pa_stream.c \
- ../portaudio/pa_common/pa_trace.c \
- ../portaudio/pablio/pablio_pd.c \
- ../portaudio/pablio/ringbuffer_pd.c \
- ../portaudio/pa_linux_alsa/callback_thread.c \
- ../portaudio/pa_linux_alsa/pa_linux_alsa.c \
- ../portaudio/pa_linux_alsa/blocking_calls.c \
- ../portaudio/pa_unix/pa_unix_hostapis.c \
- ../portaudio/pa_unix/pa_unix_util.c \
- ../portaudio/pa_unix_oss/pa_unix_oss.c "$SYSSRC
- fi
- STRIPFLAG=-s
- GUINAME="pd-gui"
- if test x$USE_OPT_CFLAGS == "xYES";
- then
- OPT_CFLAGS="-O6 -funroll-loops -fomit-frame-pointer"
- else
- OPT_CFLAGS="-g"
- fi
- OSNUMBER=0
-fi
-
-dnl **** note -- SGI/IRIX code is broken here!!! ***
-
-if test `uname -s` = IRIX64;
-then
- LDFLAGS="-n32 -DUNIX -DIRIX -DN32 -woff 1080,1064,1185 \
- -OPT:roundoff=3 -OPT:IEEE_arithmetic=3 -OPT:cray_ivdep=true \
- -shared -rdata_shared"
- EXT=pd_irix6
- MORECFLAGS=-DDL_OPEN
- SYSSRC=s_sgi.c
- STRIPFLAG=-s
- GUINAME="pd-gui"
- OSNUMBER=0
-fi
-
-if test `uname -s` = IRIX32;
-then
- LDFLAGS="-o32 -DUNIX -DIRIX -O2 -shared -rdata_shared"
- EXT=pd_irix5
- MORECFLAGS=-DDL_OPEN
- SYSSRC=s_sgi.c
- STRIPFLAG=-s
- GUINAME="pd-gui"
- OSNUMBER=0
-fi
-
-if test `uname -s` = Darwin;
-then
- LDFLAGS="-Wl -framework Tcl -framework Tk -framework CoreAudio \
- -framework AudioUnit -framework AudioToolbox \
- -framework Carbon -framework CoreMIDI"
- EXT=pd_darwin
- MORECFLAGS="-DMACOSX -I/usr/X11R6/include \
- -I../portaudio_v18/pa_common \
- -I../portaudio_v18/pablio \
- -I../portmidi_osx \
- -Wno-error \
- -DUSEAPI_PORTAUDIO -DPA_BIG_ENDIAN"
- SYSSRC="s_midi_pm.c s_audio_pa.c \
- ../portaudio_v18/pa_common/pa_lib.c \
- ../portaudio_v18/pa_common/pa_trace.c \
- ../portaudio_v18/pa_common/pa_convert.c \
- ../portaudio_v18/pablio/pablio_pd.c \
- ../portaudio_v18/pablio/ringbuffer_pd.c \
- ../portaudio_v18/pa_mac_core/pa_mac_core.c \
- ../portmidi_osx/pmdarwin.c \
- ../portmidi_osx/pmmacosx.c \
- ../portmidi_osx/pmutil.c \
- ../portmidi_osx/portmidi.c \
- ../portmidi_osx/ptdarwin.c "
- STRIPFLAG=""
- GUINAME="pdtcl"
- GUIFLAGS="-framework Tcl -framework Tk \
- -I/Library/Frameworks/Tk.framework/Versions/Current/Headers \
- -I/Library/Frameworks/Tcl.framework/Versions/Current/Headers \
- -I/Library/Frameworks/Tcl.framework/Versions/8.4/PrivateHeaders"
- if test x$USE_OPT_CFLAGS == "xYES";
- then
- OPT_CFLAGS="-O2"
- else
- OPT_CFLAGS="-g"
- fi
- OSNUMBER=2
- EXTERNTARGET=pd_darwin
- if test "x$jack == "xyes";
- then
- LDFLAGS=$LDFLAGS" -framework Jack"
- MORECFLAGS=$MORECFLAGS" -DUSEAPI_JACK"
- SYSSRC=$SYSSRC" s_audio_jack.c"
- endif
-fi
-
-AC_OUTPUT(makefile)
-
diff --git a/pd/src/configure.in.pa_v19 b/pd/src/configure.in.pa_v19
deleted file mode 100644
index 5d82597b..00000000
--- a/pd/src/configure.in.pa_v19
+++ /dev/null
@@ -1,231 +0,0 @@
-dnl Process this file with autoconf to produce a configure script.
-AC_INIT(d_arithmetic.c)
-
-AC_SUBST(alsa)
-AC_SUBST(jack)
-AC_SUBST(PDLIB)
-AC_SUBST(DEFINES)
-AC_SUBST(MORECFLAGS)
-AC_SUBST(EXT)
-AC_SUBST(OPT_CFLAGS)
-AC_SUBST(USE_OPT_CFLAGS)
-AC_SUBST(SYSSRC)
-AC_SUBST(STRIPFLAG)
-AC_SUBST(GUINAME)
-AC_SUBST(GUIFLAGS)
-AC_SUBST(OSNUMBER)
-AC_SUBST(EXTERNTARGET)
-
-dnl other defaults
-
-dnl check for features
-
-AC_ARG_ENABLE(alsa, [ --disable-alsa disable ALSA],
- alsa="no")
-AC_ARG_ENABLE(jack, [ --enable-jack jack audio server],
- jack="yes")
-AC_ARG_ENABLE(debug, [ --enable-debug debugging support],
- USE_OPT_CFLAGS="NO", USE_OPT_CFLAGS="YES")
-
-dnl Checks for programs.
-AC_PROG_CC
-AC_PROG_INSTALL
-AC_PROG_MAKE_SET
-AC_PROG_CPP
-
-dnl Checks for typedefs, structures, and compiler characteristics.
-AC_C_CONST
-AC_TYPE_PID_T
-AC_TYPE_SIZE_T
-AC_HEADER_TIME
-
-dnl Checks for header files.
-AC_HEADER_STDC
-AC_CHECK_HEADERS(fcntl.h limits.h malloc.h sys/ioctl.h sys/time.h unistd.h bstring.h)
-
-dnl Checks for library functions.
-AC_PROG_GCC_TRADITIONAL
-AC_TYPE_SIGNAL
-AC_FUNC_VPRINTF
-AC_CHECK_FUNCS(gettimeofday select socket strerror)
-
-
-dnl Checks for libraries.
-dnl Checking for `dlopen' function in -ldl:
-AC_CHECK_LIB(dl, dlopen,PDLIB="$PDLIB -ldl",
- echo "dynamic link support required" || exit 1)
-
-dnl Checking for `sin' function in -lffm:
-dnl ffm is the fast math library on the alpha
-AC_CHECK_LIB(ffm, sin,PDLIB="$PDLIB -lffm")
-
-dnl Checking for `sin' function in -lm:
-AC_CHECK_LIB(m, sin,PDLIB="$PDLIB -lm",
- echo "math library required" || exit 1)
-
-dnl Checking for `pthread_create' function in -pthread
-AC_CHECK_LIB(pthread, pthread_create,PDLIB="$PDLIB -lpthread",
- echo "pthreads required" || exit 1)
-
-dnl This should be fixed so Pd can use ALSA shared libraries where appropriate.
-if test "$alsa" != no; then
- AC_CHECK_LIB(asound,snd_pcm_info,PDLIB="$PDLIB -lasound" ; alsa="yes",alsa="")
-fi
-
-dnl Find paths to includes and libraries for X11
-AC_PATH_X
-dnl Checking for `XCreateWindow' function in -lX11:
-AC_CHECK_LIB(X11, XCreateWindow, LIBS="$LIBS -lX11 -L$x_libraries",
- echo "no X11 found" || exit 1, -L$x_libraries)
-
-dnl look for tcl 8.x... do I really have to go through all this!?
-
-AC_CHECK_HEADER(tcl8.7/tcl.h,GUIFLAGS="$GUIFLAGS -I/usr/include/tcl8.7",
- AC_CHECK_HEADER(tcl8.6/tcl.h,GUIFLAGS="$GUIFLAGS -I/usr/include/tcl8.6",
- AC_CHECK_HEADER(tcl8.5/tcl.h,GUIFLAGS="$GUIFLAGS -I/usr/include/tcl8.5",
- AC_CHECK_HEADER(tcl8.4/tcl.h,GUIFLAGS="$GUIFLAGS -I/usr/include/tcl8.4",
- AC_CHECK_HEADER(tcl8.3/tcl.h,GUIFLAGS="$GUIFLAGS -I/usr/include/tcl8.3",
- AC_CHECK_HEADER(tcl8.2/tcl.h,GUIFLAGS="$GUIFLAGS -I/usr/include/tcl8.2",
- AC_CHECK_HEADER(tcl.h,, echo no tcl/tk headers found)))))))
-
-
-AC_CHECK_LIB(tcl8.7, main,,
- AC_CHECK_LIB(tcl8.6, main,,
- AC_CHECK_LIB(tcl8.5, main,,
- AC_CHECK_LIB(tcl8.4, main,,
- AC_CHECK_LIB(tcl8.3, main,,
- AC_CHECK_LIB(tcl8.2, main,,
- AC_CHECK_LIB(tcl8.0, main)))))))
-
-AC_CHECK_LIB(tk8.7, main,,
- AC_CHECK_LIB(tk8.6, main,,
- AC_CHECK_LIB(tk8.5, main,,
- AC_CHECK_LIB(tk8.4, main,,
- AC_CHECK_LIB(tk8.3, main,,
- AC_CHECK_LIB(tk8.2, main,,
- AC_CHECK_LIB(tk8.0, main)))))))
-
-dnl Checking for tk.h or tkstep.h - not used at the moment
-dnl AC_CHECK_HEADER(tk.h,DEFINES="$DEFINES -DTKINC=\\\"tk.h\\\"")
-dnl AC_CHECK_HEADER(tkstep.h,DEFINES="$DEFINES -DTKINC=\\\"tkstep.h\\\"")
-
-if test `uname -s` = Linux;
-then
- dnl Ckecking for ALSA
-
- AC_CHECK_LIB(asound,snd_pcm_open,LIBS="$LIBS -lasound";alsa=yes,alsa=no)
-
- dnl Checking for JACK
-
- AC_CHECK_LIB(rt,shm_open,LIBS="$LIBS -lrt")
- AC_CHECK_LIB(jack,jack_set_xrun_callback,LIBS="$LIBS -ljack";jack=xrun,jack=no)
- AC_CHECK_LIB(jack,jack_set_error_function,LIBS="$LIBS -ljack";jack=yes,jack=no)
-
- LDFLAGS="-Wl,-export-dynamic"
- EXT=pd_linux
- MORECFLAGS="-DDL_OPEN -DUSEAPI_PORTAUDIO -DPA_USE_OSS -DPA_LITTLE_ENDIAN \
- -DUSEAPI_OSS \
- -I../portaudio_v18/pa_common \
- -I../portaudio_v18/pablio \
- -I../portaudio/portmidi-macosx -Werror"
- SYSSRC="s_midi_oss.c s_audio_pa.c s_audio_oss.c \
- ../portaudio_v18/pa_common/pa_lib.c \
- ../portaudio_v18/pa_common/pa_trace.c \
- ../portaudio_v18/pa_common/pa_convert.c \
- ../portaudio_v18/pablio/pablio_pd.c \
- ../portaudio_v18/pablio/ringbuffer_pd.c \
-
- \
- ../portaudio/pa_common/pa_allocation.c \
- ../portaudio/pa_common/pa_converters.c \
- ../portaudio/pa_common/pa_cpuload.c \
- ../portaudio/pa_common/pa_dither.c \
- ../portaudio/pa_common/pa_front.c \
- ../portaudio/pa_common/pa_process.c \
- ../portaudio/pa_common/pa_skeleton.c \
- ../portaudio/pa_common/pa_stream.c \
- ../portaudio/pa_common/pa_trace.c \
- ../portaudio/pablio/pablio_pd.c \
- ../portaudio/pablio/ringbuffer_pd.c \
- ../portaudio/pa_unix/pa_unix_hostapis.c \
- ../portaudio/pa_unix/pa_unix_util.c \
- ../portaudio/pa_unix_oss/pa_unix_oss.c "
- STRIPFLAG=-s
- GUINAME="pd-gui"
- if test $USE_OPT_CFLAGS == "YES";
- then
- OPT_CFLAGS="-O6 -funroll-loops -fomit-frame-pointer"
- else
- OPT_CFLAGS="-g"
- fi
- OSNUMBER=0
-fi
-
-dnl **** note -- SGI/IRIX code is broken here!!! ***
-
-if test `uname -s` = IRIX64;
-then
- LDFLAGS="-n32 -DUNIX -DIRIX -DN32 -woff 1080,1064,1185 \
- -OPT:roundoff=3 -OPT:IEEE_arithmetic=3 -OPT:cray_ivdep=true \
- -shared -rdata_shared"
- EXT=pd_irix6
- MORECFLAGS=-DDL_OPEN
- SYSSRC=s_sgi.c
- STRIPFLAG=-s
- GUINAME="pd-gui"
- OSNUMBER=0
-fi
-
-if test `uname -s` = IRIX32;
-then
- LDFLAGS="-o32 -DUNIX -DIRIX -O2 -shared -rdata_shared"
- EXT=pd_irix5
- MORECFLAGS=-DDL_OPEN
- SYSSRC=s_sgi.c
- STRIPFLAG=-s
- GUINAME="pd-gui"
- OSNUMBER=0
-fi
-
-if test `uname -s` = Darwin;
-then
- LDFLAGS="-Wl -framework Tcl -framework Tk -framework CoreAudio \
- -framework AudioUnit -framework AudioToolbox \
- -framework Carbon -framework CoreMIDI"
- EXT=pd_darwin
- MORECFLAGS="-DMACOSX -I/usr/X11R6/include \
- -I../portaudio_v18/pa_common \
- -I../portaudio_v18/pablio \
- -I../portmidi_osx \
- -Wno-error \
- -DUSEAPI_PORTAUDIO -DPA_BIG_ENDIAN"
- SYSSRC="s_midi_pm.c s_audio_pa.c \
- ../portaudio_v18/pa_common/pa_lib.c \
- ../portaudio_v18/pa_common/pa_trace.c \
- ../portaudio_v18/pa_common/pa_convert.c \
- ../portaudio_v18/pablio/pablio_pd.c \
- ../portaudio_v18/pablio/ringbuffer_pd.c \
- ../portaudio_v18/pa_mac_core/pa_mac_core.c \
- ../portmidi_osx/pmdarwin.c \
- ../portmidi_osx/pmmacosx.c \
- ../portmidi_osx/pmutil.c \
- ../portmidi_osx/portmidi.c \
- ../portmidi_osx/ptdarwin.c "
- STRIPFLAG=""
- GUINAME="pdtcl"
- GUIFLAGS="-framework Tcl -framework Tk \
- -I/Library/Frameworks/Tk.framework/Versions/Current/Headers \
- -I/Library/Frameworks/Tcl.framework/Versions/Current/Headers \
- -I/Library/Frameworks/Tcl.framework/Versions/8.4/PrivateHeaders"
- if test $USE_OPT_CFLAGS == "YES";
- then
- OPT_CFLAGS="-O2"
- else
- OPT_CFLAGS="-g"
- fi
- OSNUMBER=2
- EXTERNTARGET=pd_darwin
-fi
-
-AC_OUTPUT(makefile)
-
diff --git a/pd/src/d_arithmetic.c b/pd/src/d_arithmetic.c
index 0ca4e846..47eb25c5 100644
--- a/pd/src/d_arithmetic.c
+++ b/pd/src/d_arithmetic.c
@@ -23,7 +23,7 @@ typedef struct _scalarplus
{
t_object x_obj;
float x_f;
- t_float x_g; /* inlet value */
+ t_float x_g; /* inlet value */
} t_scalarplus;
static void *plus_new(t_symbol *s, int argc, t_atom *argv)
@@ -31,20 +31,20 @@ static void *plus_new(t_symbol *s, int argc, t_atom *argv)
if (argc > 1) post("+~: extra arguments ignored");
if (argc)
{
- t_scalarplus *x = (t_scalarplus *)pd_new(scalarplus_class);
- floatinlet_new(&x->x_obj, &x->x_g);
- x->x_g = atom_getfloatarg(0, argc, argv);
- outlet_new(&x->x_obj, &s_signal);
- x->x_f = 0;
- return (x);
+ t_scalarplus *x = (t_scalarplus *)pd_new(scalarplus_class);
+ floatinlet_new(&x->x_obj, &x->x_g);
+ x->x_g = atom_getfloatarg(0, argc, argv);
+ outlet_new(&x->x_obj, &s_signal);
+ x->x_f = 0;
+ return (x);
}
else
{
- t_plus *x = (t_plus *)pd_new(plus_class);
- inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_signal, &s_signal);
- outlet_new(&x->x_obj, &s_signal);
- x->x_f = 0;
- return (x);
+ t_plus *x = (t_plus *)pd_new(plus_class);
+ inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_signal, &s_signal);
+ outlet_new(&x->x_obj, &s_signal);
+ x->x_f = 0;
+ return (x);
}
}
@@ -66,14 +66,14 @@ t_int *plus_perf8(t_int *w)
int n = (int)(w[4]);
for (; n; n -= 8, in1 += 8, in2 += 8, out += 8)
{
- float f0 = in1[0], f1 = in1[1], f2 = in1[2], f3 = in1[3];
- float f4 = in1[4], f5 = in1[5], f6 = in1[6], f7 = in1[7];
+ float f0 = in1[0], f1 = in1[1], f2 = in1[2], f3 = in1[3];
+ float f4 = in1[4], f5 = in1[5], f6 = in1[6], f7 = in1[7];
- float g0 = in2[0], g1 = in2[1], g2 = in2[2], g3 = in2[3];
- float g4 = in2[4], g5 = in2[5], g6 = in2[6], g7 = in2[7];
+ float g0 = in2[0], g1 = in2[1], g2 = in2[2], g3 = in2[3];
+ float g4 = in2[4], g5 = in2[5], g6 = in2[6], g7 = in2[7];
- out[0] = f0 + g0; out[1] = f1 + g1; out[2] = f2 + g2; out[3] = f3 + g3;
- out[4] = f4 + g4; out[5] = f5 + g5; out[6] = f6 + g6; out[7] = f7 + g7;
+ out[0] = f0 + g0; out[1] = f1 + g1; out[2] = f2 + g2; out[3] = f3 + g3;
+ out[4] = f4 + g4; out[5] = f5 + g5; out[6] = f6 + g6; out[7] = f7 + g7;
}
return (w+5);
}
@@ -96,11 +96,11 @@ t_int *scalarplus_perf8(t_int *w)
int n = (int)(w[4]);
for (; n; n -= 8, in += 8, out += 8)
{
- float f0 = in[0], f1 = in[1], f2 = in[2], f3 = in[3];
- float f4 = in[4], f5 = in[5], f6 = in[6], f7 = in[7];
+ float f0 = in[0], f1 = in[1], f2 = in[2], f3 = in[3];
+ float f4 = in[4], f5 = in[5], f6 = in[6], f7 = in[7];
- out[0] = f0 + g; out[1] = f1 + g; out[2] = f2 + g; out[3] = f3 + g;
- out[4] = f4 + g; out[5] = f5 + g; out[6] = f6 + g; out[7] = f7 + g;
+ out[0] = f0 + g; out[1] = f1 + g; out[2] = f2 + g; out[3] = f3 + g;
+ out[4] = f4 + g; out[5] = f5 + g; out[6] = f6 + g; out[7] = f7 + g;
}
return (w+5);
}
@@ -108,9 +108,9 @@ t_int *scalarplus_perf8(t_int *w)
void dsp_add_plus(t_sample *in1, t_sample *in2, t_sample *out, int n)
{
if (n&7)
- dsp_add(plus_perform, 4, in1, in2, out, n);
- else
- dsp_add(plus_perf8, 4, in1, in2, out, n);
+ dsp_add(plus_perform, 4, in1, in2, out, n);
+ else
+ dsp_add(plus_perf8, 4, in1, in2, out, n);
}
static void plus_dsp(t_plus *x, t_signal **sp)
@@ -121,25 +121,25 @@ static void plus_dsp(t_plus *x, t_signal **sp)
static void scalarplus_dsp(t_scalarplus *x, t_signal **sp)
{
if (sp[0]->s_n&7)
- dsp_add(scalarplus_perform, 4, sp[0]->s_vec, &x->x_g,
- sp[1]->s_vec, sp[0]->s_n);
- else
- dsp_add(scalarplus_perf8, 4, sp[0]->s_vec, &x->x_g,
- sp[1]->s_vec, sp[0]->s_n);
+ dsp_add(scalarplus_perform, 4, sp[0]->s_vec, &x->x_g,
+ sp[1]->s_vec, sp[0]->s_n);
+ else
+ dsp_add(scalarplus_perf8, 4, sp[0]->s_vec, &x->x_g,
+ sp[1]->s_vec, sp[0]->s_n);
}
static void plus_setup(void)
{
plus_class = class_new(gensym("+~"), (t_newmethod)plus_new, 0,
- sizeof(t_plus), 0, A_GIMME, 0);
+ sizeof(t_plus), 0, A_GIMME, 0);
class_addmethod(plus_class, (t_method)plus_dsp, gensym("dsp"), 0);
CLASS_MAINSIGNALIN(plus_class, t_plus, x_f);
class_sethelpsymbol(plus_class, gensym("sigbinops"));
scalarplus_class = class_new(gensym("+~"), 0, 0,
- sizeof(t_scalarplus), 0, 0);
+ sizeof(t_scalarplus), 0, 0);
CLASS_MAINSIGNALIN(scalarplus_class, t_scalarplus, x_f);
class_addmethod(scalarplus_class, (t_method)scalarplus_dsp, gensym("dsp"),
- 0);
+ 0);
class_sethelpsymbol(scalarplus_class, gensym("sigbinops"));
}
@@ -164,20 +164,20 @@ static void *minus_new(t_symbol *s, int argc, t_atom *argv)
if (argc > 1) post("-~: extra arguments ignored");
if (argc)
{
- t_scalarminus *x = (t_scalarminus *)pd_new(scalarminus_class);
- floatinlet_new(&x->x_obj, &x->x_g);
- x->x_g = atom_getfloatarg(0, argc, argv);
- outlet_new(&x->x_obj, &s_signal);
- x->x_f = 0;
- return (x);
+ t_scalarminus *x = (t_scalarminus *)pd_new(scalarminus_class);
+ floatinlet_new(&x->x_obj, &x->x_g);
+ x->x_g = atom_getfloatarg(0, argc, argv);
+ outlet_new(&x->x_obj, &s_signal);
+ x->x_f = 0;
+ return (x);
}
else
{
- t_minus *x = (t_minus *)pd_new(minus_class);
- inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_signal, &s_signal);
- outlet_new(&x->x_obj, &s_signal);
- x->x_f = 0;
- return (x);
+ t_minus *x = (t_minus *)pd_new(minus_class);
+ inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_signal, &s_signal);
+ outlet_new(&x->x_obj, &s_signal);
+ x->x_f = 0;
+ return (x);
}
}
@@ -199,14 +199,14 @@ t_int *minus_perf8(t_int *w)
int n = (int)(w[4]);
for (; n; n -= 8, in1 += 8, in2 += 8, out += 8)
{
- float f0 = in1[0], f1 = in1[1], f2 = in1[2], f3 = in1[3];
- float f4 = in1[4], f5 = in1[5], f6 = in1[6], f7 = in1[7];
+ float f0 = in1[0], f1 = in1[1], f2 = in1[2], f3 = in1[3];
+ float f4 = in1[4], f5 = in1[5], f6 = in1[6], f7 = in1[7];
- float g0 = in2[0], g1 = in2[1], g2 = in2[2], g3 = in2[3];
- float g4 = in2[4], g5 = in2[5], g6 = in2[6], g7 = in2[7];
+ float g0 = in2[0], g1 = in2[1], g2 = in2[2], g3 = in2[3];
+ float g4 = in2[4], g5 = in2[5], g6 = in2[6], g7 = in2[7];
- out[0] = f0 - g0; out[1] = f1 - g1; out[2] = f2 - g2; out[3] = f3 - g3;
- out[4] = f4 - g4; out[5] = f5 - g5; out[6] = f6 - g6; out[7] = f7 - g7;
+ out[0] = f0 - g0; out[1] = f1 - g1; out[2] = f2 - g2; out[3] = f3 - g3;
+ out[4] = f4 - g4; out[5] = f5 - g5; out[6] = f6 - g6; out[7] = f7 - g7;
}
return (w+5);
}
@@ -229,11 +229,11 @@ t_int *scalarminus_perf8(t_int *w)
int n = (int)(w[4]);
for (; n; n -= 8, in += 8, out += 8)
{
- float f0 = in[0], f1 = in[1], f2 = in[2], f3 = in[3];
- float f4 = in[4], f5 = in[5], f6 = in[6], f7 = in[7];
+ float f0 = in[0], f1 = in[1], f2 = in[2], f3 = in[3];
+ float f4 = in[4], f5 = in[5], f6 = in[6], f7 = in[7];
- out[0] = f0 - g; out[1] = f1 - g; out[2] = f2 - g; out[3] = f3 - g;
- out[4] = f4 - g; out[5] = f5 - g; out[6] = f6 - g; out[7] = f7 - g;
+ out[0] = f0 - g; out[1] = f1 - g; out[2] = f2 - g; out[3] = f3 - g;
+ out[4] = f4 - g; out[5] = f5 - g; out[6] = f6 - g; out[7] = f7 - g;
}
return (w+5);
}
@@ -241,35 +241,35 @@ t_int *scalarminus_perf8(t_int *w)
static void minus_dsp(t_minus *x, t_signal **sp)
{
if (sp[0]->s_n&7)
- dsp_add(minus_perform, 4,
- sp[0]->s_vec, sp[1]->s_vec, sp[2]->s_vec, sp[0]->s_n);
- else
- dsp_add(minus_perf8, 4,
- sp[0]->s_vec, sp[1]->s_vec, sp[2]->s_vec, sp[0]->s_n);
+ dsp_add(minus_perform, 4,
+ sp[0]->s_vec, sp[1]->s_vec, sp[2]->s_vec, sp[0]->s_n);
+ else
+ dsp_add(minus_perf8, 4,
+ sp[0]->s_vec, sp[1]->s_vec, sp[2]->s_vec, sp[0]->s_n);
}
static void scalarminus_dsp(t_scalarminus *x, t_signal **sp)
{
if (sp[0]->s_n&7)
- dsp_add(scalarminus_perform, 4, sp[0]->s_vec, &x->x_g,
- sp[1]->s_vec, sp[0]->s_n);
- else
- dsp_add(scalarminus_perf8, 4, sp[0]->s_vec, &x->x_g,
- sp[1]->s_vec, sp[0]->s_n);
+ dsp_add(scalarminus_perform, 4, sp[0]->s_vec, &x->x_g,
+ sp[1]->s_vec, sp[0]->s_n);
+ else
+ dsp_add(scalarminus_perf8, 4, sp[0]->s_vec, &x->x_g,
+ sp[1]->s_vec, sp[0]->s_n);
}
static void minus_setup(void)
{
minus_class = class_new(gensym("-~"), (t_newmethod)minus_new, 0,
- sizeof(t_minus), 0, A_GIMME, 0);
+ sizeof(t_minus), 0, A_GIMME, 0);
CLASS_MAINSIGNALIN(minus_class, t_minus, x_f);
class_addmethod(minus_class, (t_method)minus_dsp, gensym("dsp"), 0);
class_sethelpsymbol(minus_class, gensym("sigbinops"));
scalarminus_class = class_new(gensym("-~"), 0, 0,
- sizeof(t_scalarminus), 0, 0);
+ sizeof(t_scalarminus), 0, 0);
CLASS_MAINSIGNALIN(scalarminus_class, t_scalarminus, x_f);
class_addmethod(scalarminus_class, (t_method)scalarminus_dsp, gensym("dsp"),
- 0);
+ 0);
class_sethelpsymbol(scalarminus_class, gensym("sigbinops"));
}
@@ -295,20 +295,20 @@ static void *times_new(t_symbol *s, int argc, t_atom *argv)
if (argc > 1) post("*~: extra arguments ignored");
if (argc)
{
- t_scalartimes *x = (t_scalartimes *)pd_new(scalartimes_class);
- floatinlet_new(&x->x_obj, &x->x_g);
- x->x_g = atom_getfloatarg(0, argc, argv);
- outlet_new(&x->x_obj, &s_signal);
- x->x_f = 0;
- return (x);
+ t_scalartimes *x = (t_scalartimes *)pd_new(scalartimes_class);
+ floatinlet_new(&x->x_obj, &x->x_g);
+ x->x_g = atom_getfloatarg(0, argc, argv);
+ outlet_new(&x->x_obj, &s_signal);
+ x->x_f = 0;
+ return (x);
}
else
{
- t_times *x = (t_times *)pd_new(times_class);
- inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_signal, &s_signal);
- outlet_new(&x->x_obj, &s_signal);
- x->x_f = 0;
- return (x);
+ t_times *x = (t_times *)pd_new(times_class);
+ inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_signal, &s_signal);
+ outlet_new(&x->x_obj, &s_signal);
+ x->x_f = 0;
+ return (x);
}
}
@@ -330,14 +330,14 @@ t_int *times_perf8(t_int *w)
int n = (int)(w[4]);
for (; n; n -= 8, in1 += 8, in2 += 8, out += 8)
{
- float f0 = in1[0], f1 = in1[1], f2 = in1[2], f3 = in1[3];
- float f4 = in1[4], f5 = in1[5], f6 = in1[6], f7 = in1[7];
+ float f0 = in1[0], f1 = in1[1], f2 = in1[2], f3 = in1[3];
+ float f4 = in1[4], f5 = in1[5], f6 = in1[6], f7 = in1[7];
- float g0 = in2[0], g1 = in2[1], g2 = in2[2], g3 = in2[3];
- float g4 = in2[4], g5 = in2[5], g6 = in2[6], g7 = in2[7];
+ float g0 = in2[0], g1 = in2[1], g2 = in2[2], g3 = in2[3];
+ float g4 = in2[4], g5 = in2[5], g6 = in2[6], g7 = in2[7];
- out[0] = f0 * g0; out[1] = f1 * g1; out[2] = f2 * g2; out[3] = f3 * g3;
- out[4] = f4 * g4; out[5] = f5 * g5; out[6] = f6 * g6; out[7] = f7 * g7;
+ out[0] = f0 * g0; out[1] = f1 * g1; out[2] = f2 * g2; out[3] = f3 * g3;
+ out[4] = f4 * g4; out[5] = f5 * g5; out[6] = f6 * g6; out[7] = f7 * g7;
}
return (w+5);
}
@@ -360,11 +360,11 @@ t_int *scalartimes_perf8(t_int *w)
int n = (int)(w[4]);
for (; n; n -= 8, in += 8, out += 8)
{
- float f0 = in[0], f1 = in[1], f2 = in[2], f3 = in[3];
- float f4 = in[4], f5 = in[5], f6 = in[6], f7 = in[7];
+ float f0 = in[0], f1 = in[1], f2 = in[2], f3 = in[3];
+ float f4 = in[4], f5 = in[5], f6 = in[6], f7 = in[7];
- out[0] = f0 * g; out[1] = f1 * g; out[2] = f2 * g; out[3] = f3 * g;
- out[4] = f4 * g; out[5] = f5 * g; out[6] = f6 * g; out[7] = f7 * g;
+ out[0] = f0 * g; out[1] = f1 * g; out[2] = f2 * g; out[3] = f3 * g;
+ out[4] = f4 * g; out[5] = f5 * g; out[6] = f6 * g; out[7] = f7 * g;
}
return (w+5);
}
@@ -372,35 +372,35 @@ t_int *scalartimes_perf8(t_int *w)
static void times_dsp(t_times *x, t_signal **sp)
{
if (sp[0]->s_n&7)
- dsp_add(times_perform, 4,
- sp[0]->s_vec, sp[1]->s_vec, sp[2]->s_vec, sp[0]->s_n);
- else
- dsp_add(times_perf8, 4,
- sp[0]->s_vec, sp[1]->s_vec, sp[2]->s_vec, sp[0]->s_n);
+ dsp_add(times_perform, 4,
+ sp[0]->s_vec, sp[1]->s_vec, sp[2]->s_vec, sp[0]->s_n);
+ else
+ dsp_add(times_perf8, 4,
+ sp[0]->s_vec, sp[1]->s_vec, sp[2]->s_vec, sp[0]->s_n);
}
static void scalartimes_dsp(t_scalartimes *x, t_signal **sp)
{
if (sp[0]->s_n&7)
- dsp_add(scalartimes_perform, 4, sp[0]->s_vec, &x->x_g,
- sp[1]->s_vec, sp[0]->s_n);
- else
- dsp_add(scalartimes_perf8, 4, sp[0]->s_vec, &x->x_g,
- sp[1]->s_vec, sp[0]->s_n);
+ dsp_add(scalartimes_perform, 4, sp[0]->s_vec, &x->x_g,
+ sp[1]->s_vec, sp[0]->s_n);
+ else
+ dsp_add(scalartimes_perf8, 4, sp[0]->s_vec, &x->x_g,
+ sp[1]->s_vec, sp[0]->s_n);
}
static void times_setup(void)
{
times_class = class_new(gensym("*~"), (t_newmethod)times_new, 0,
- sizeof(t_times), 0, A_GIMME, 0);
+ sizeof(t_times), 0, A_GIMME, 0);
CLASS_MAINSIGNALIN(times_class, t_times, x_f);
class_addmethod(times_class, (t_method)times_dsp, gensym("dsp"), 0);
class_sethelpsymbol(times_class, gensym("sigbinops"));
scalartimes_class = class_new(gensym("*~"), 0, 0,
- sizeof(t_scalartimes), 0, 0);
+ sizeof(t_scalartimes), 0, 0);
CLASS_MAINSIGNALIN(scalartimes_class, t_scalartimes, x_f);
class_addmethod(scalartimes_class, (t_method)scalartimes_dsp, gensym("dsp"),
- 0);
+ 0);
class_sethelpsymbol(scalartimes_class, gensym("sigbinops"));
}
@@ -425,20 +425,20 @@ static void *over_new(t_symbol *s, int argc, t_atom *argv)
if (argc > 1) post("/~: extra arguments ignored");
if (argc)
{
- t_scalarover *x = (t_scalarover *)pd_new(scalarover_class);
- floatinlet_new(&x->x_obj, &x->x_g);
- x->x_g = atom_getfloatarg(0, argc, argv);
- outlet_new(&x->x_obj, &s_signal);
- x->x_f = 0;
- return (x);
+ t_scalarover *x = (t_scalarover *)pd_new(scalarover_class);
+ floatinlet_new(&x->x_obj, &x->x_g);
+ x->x_g = atom_getfloatarg(0, argc, argv);
+ outlet_new(&x->x_obj, &s_signal);
+ x->x_f = 0;
+ return (x);
}
else
{
- t_over *x = (t_over *)pd_new(over_class);
- inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_signal, &s_signal);
- outlet_new(&x->x_obj, &s_signal);
- x->x_f = 0;
- return (x);
+ t_over *x = (t_over *)pd_new(over_class);
+ inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_signal, &s_signal);
+ outlet_new(&x->x_obj, &s_signal);
+ x->x_f = 0;
+ return (x);
}
}
@@ -450,8 +450,8 @@ t_int *over_perform(t_int *w)
int n = (int)(w[4]);
while (n--)
{
- float g = *in2++;
- *out++ = (g ? *in1++ / g : 0);
+ float g = *in2++;
+ *out++ = (g ? *in1++ / g : 0);
}
return (w+5);
}
@@ -464,30 +464,32 @@ t_int *over_perf8(t_int *w)
int n = (int)(w[4]);
for (; n; n -= 8, in1 += 8, in2 += 8, out += 8)
{
- float f0 = in1[0], f1 = in1[1], f2 = in1[2], f3 = in1[3];
- float f4 = in1[4], f5 = in1[5], f6 = in1[6], f7 = in1[7];
-
- float g0 = in2[0], g1 = in2[1], g2 = in2[2], g3 = in2[3];
- float g4 = in2[4], g5 = in2[5], g6 = in2[6], g7 = in2[7];
-
- out[0] = (g0? f0 / g0 : 0);
- out[1] = (g1? f1 / g1 : 0);
- out[2] = (g2? f2 / g2 : 0);
- out[3] = (g3? f3 / g3 : 0);
- out[4] = (g4? f4 / g4 : 0);
- out[5] = (g5? f5 / g5 : 0);
- out[6] = (g6? f6 / g6 : 0);
- out[7] = (g7? f7 / g7 : 0);
+ float f0 = in1[0], f1 = in1[1], f2 = in1[2], f3 = in1[3];
+ float f4 = in1[4], f5 = in1[5], f6 = in1[6], f7 = in1[7];
+
+ float g0 = in2[0], g1 = in2[1], g2 = in2[2], g3 = in2[3];
+ float g4 = in2[4], g5 = in2[5], g6 = in2[6], g7 = in2[7];
+
+ out[0] = (g0? f0 / g0 : 0);
+ out[1] = (g1? f1 / g1 : 0);
+ out[2] = (g2? f2 / g2 : 0);
+ out[3] = (g3? f3 / g3 : 0);
+ out[4] = (g4? f4 / g4 : 0);
+ out[5] = (g5? f5 / g5 : 0);
+ out[6] = (g6? f6 / g6 : 0);
+ out[7] = (g7? f7 / g7 : 0);
}
return (w+5);
}
+/* T.Grill - added check for zero */
t_int *scalarover_perform(t_int *w)
{
t_float *in = (t_float *)(w[1]);
- t_float f = 1. / *(t_float *)(w[2]);
+ t_float f = *(t_float *)(w[2]);
t_float *out = (t_float *)(w[3]);
int n = (int)(w[4]);
+ if(f) f = 1./f;
while (n--) *out++ = *in++ * f;
return (w+5);
}
@@ -501,11 +503,11 @@ t_int *scalarover_perf8(t_int *w)
if (g) g = 1.f / g;
for (; n; n -= 8, in += 8, out += 8)
{
- float f0 = in[0], f1 = in[1], f2 = in[2], f3 = in[3];
- float f4 = in[4], f5 = in[5], f6 = in[6], f7 = in[7];
+ float f0 = in[0], f1 = in[1], f2 = in[2], f3 = in[3];
+ float f4 = in[4], f5 = in[5], f6 = in[6], f7 = in[7];
- out[0] = f0 * g; out[1] = f1 * g; out[2] = f2 * g; out[3] = f3 * g;
- out[4] = f4 * g; out[5] = f5 * g; out[6] = f6 * g; out[7] = f7 * g;
+ out[0] = f0 * g; out[1] = f1 * g; out[2] = f2 * g; out[3] = f3 * g;
+ out[4] = f4 * g; out[5] = f5 * g; out[6] = f6 * g; out[7] = f7 * g;
}
return (w+5);
}
@@ -513,35 +515,35 @@ t_int *scalarover_perf8(t_int *w)
static void over_dsp(t_over *x, t_signal **sp)
{
if (sp[0]->s_n&7)
- dsp_add(over_perform, 4,
- sp[0]->s_vec, sp[1]->s_vec, sp[2]->s_vec, sp[0]->s_n);
- else
- dsp_add(over_perf8, 4,
- sp[0]->s_vec, sp[1]->s_vec, sp[2]->s_vec, sp[0]->s_n);
+ dsp_add(over_perform, 4,
+ sp[0]->s_vec, sp[1]->s_vec, sp[2]->s_vec, sp[0]->s_n);
+ else
+ dsp_add(over_perf8, 4,
+ sp[0]->s_vec, sp[1]->s_vec, sp[2]->s_vec, sp[0]->s_n);
}
static void scalarover_dsp(t_scalarover *x, t_signal **sp)
{
if (sp[0]->s_n&7)
- dsp_add(scalarover_perform, 4, sp[0]->s_vec, &x->x_g,
- sp[1]->s_vec, sp[0]->s_n);
- else
- dsp_add(scalarover_perf8, 4, sp[0]->s_vec, &x->x_g,
- sp[1]->s_vec, sp[0]->s_n);
+ dsp_add(scalarover_perform, 4, sp[0]->s_vec, &x->x_g,
+ sp[1]->s_vec, sp[0]->s_n);
+ else
+ dsp_add(scalarover_perf8, 4, sp[0]->s_vec, &x->x_g,
+ sp[1]->s_vec, sp[0]->s_n);
}
static void over_setup(void)
{
over_class = class_new(gensym("/~"), (t_newmethod)over_new, 0,
- sizeof(t_over), 0, A_GIMME, 0);
+ sizeof(t_over), 0, A_GIMME, 0);
CLASS_MAINSIGNALIN(over_class, t_over, x_f);
class_addmethod(over_class, (t_method)over_dsp, gensym("dsp"), 0);
class_sethelpsymbol(over_class, gensym("sigbinops"));
scalarover_class = class_new(gensym("/~"), 0, 0,
- sizeof(t_scalarover), 0, 0);
+ sizeof(t_scalarover), 0, 0);
CLASS_MAINSIGNALIN(scalarover_class, t_scalarover, x_f);
class_addmethod(scalarover_class, (t_method)scalarover_dsp, gensym("dsp"),
- 0);
+ 0);
class_sethelpsymbol(scalarover_class, gensym("sigbinops"));
}
@@ -566,20 +568,20 @@ static void *max_new(t_symbol *s, int argc, t_atom *argv)
if (argc > 1) post("max~: extra arguments ignored");
if (argc)
{
- t_scalarmax *x = (t_scalarmax *)pd_new(scalarmax_class);
- floatinlet_new(&x->x_obj, &x->x_g);
- x->x_g = atom_getfloatarg(0, argc, argv);
- outlet_new(&x->x_obj, &s_signal);
- x->x_f = 0;
- return (x);
+ t_scalarmax *x = (t_scalarmax *)pd_new(scalarmax_class);
+ floatinlet_new(&x->x_obj, &x->x_g);
+ x->x_g = atom_getfloatarg(0, argc, argv);
+ outlet_new(&x->x_obj, &s_signal);
+ x->x_f = 0;
+ return (x);
}
else
{
- t_max *x = (t_max *)pd_new(max_class);
- inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_signal, &s_signal);
- outlet_new(&x->x_obj, &s_signal);
- x->x_f = 0;
- return (x);
+ t_max *x = (t_max *)pd_new(max_class);
+ inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_signal, &s_signal);
+ outlet_new(&x->x_obj, &s_signal);
+ x->x_f = 0;
+ return (x);
}
}
@@ -591,8 +593,8 @@ t_int *max_perform(t_int *w)
int n = (int)(w[4]);
while (n--)
{
- float f = *in1++, g = *in2++;
- *out++ = (f > g ? f : g);
+ float f = *in1++, g = *in2++;
+ *out++ = (f > g ? f : g);
}
return (w+5);
}
@@ -605,16 +607,16 @@ t_int *max_perf8(t_int *w)
int n = (int)(w[4]);
for (; n; n -= 8, in1 += 8, in2 += 8, out += 8)
{
- float f0 = in1[0], f1 = in1[1], f2 = in1[2], f3 = in1[3];
- float f4 = in1[4], f5 = in1[5], f6 = in1[6], f7 = in1[7];
+ float f0 = in1[0], f1 = in1[1], f2 = in1[2], f3 = in1[3];
+ float f4 = in1[4], f5 = in1[5], f6 = in1[6], f7 = in1[7];
- float g0 = in2[0], g1 = in2[1], g2 = in2[2], g3 = in2[3];
- float g4 = in2[4], g5 = in2[5], g6 = in2[6], g7 = in2[7];
+ float g0 = in2[0], g1 = in2[1], g2 = in2[2], g3 = in2[3];
+ float g4 = in2[4], g5 = in2[5], g6 = in2[6], g7 = in2[7];
- out[0] = (f0 > g0 ? f0 : g0); out[1] = (f1 > g1 ? f1 : g1);
- out[2] = (f2 > g2 ? f2 : g2); out[3] = (f3 > g3 ? f3 : g3);
- out[4] = (f4 > g4 ? f4 : g4); out[5] = (f5 > g5 ? f5 : g5);
- out[6] = (f6 > g6 ? f6 : g6); out[7] = (f7 > g7 ? f7 : g7);
+ out[0] = (f0 > g0 ? f0 : g0); out[1] = (f1 > g1 ? f1 : g1);
+ out[2] = (f2 > g2 ? f2 : g2); out[3] = (f3 > g3 ? f3 : g3);
+ out[4] = (f4 > g4 ? f4 : g4); out[5] = (f5 > g5 ? f5 : g5);
+ out[6] = (f6 > g6 ? f6 : g6); out[7] = (f7 > g7 ? f7 : g7);
}
return (w+5);
}
@@ -627,8 +629,8 @@ t_int *scalarmax_perform(t_int *w)
int n = (int)(w[4]);
while (n--)
{
- t_float g = *in++;
- *out++ = (f > g ? f : g);
+ t_float g = *in++;
+ *out++ = (f > g ? f : g);
}
return (w+5);
}
@@ -641,13 +643,13 @@ t_int *scalarmax_perf8(t_int *w)
int n = (int)(w[4]);
for (; n; n -= 8, in += 8, out += 8)
{
- float f0 = in[0], f1 = in[1], f2 = in[2], f3 = in[3];
- float f4 = in[4], f5 = in[5], f6 = in[6], f7 = in[7];
+ float f0 = in[0], f1 = in[1], f2 = in[2], f3 = in[3];
+ float f4 = in[4], f5 = in[5], f6 = in[6], f7 = in[7];
- out[0] = (f0 > g ? f0 : g); out[1] = (f1 > g ? f1 : g);
- out[2] = (f2 > g ? f2 : g); out[3] = (f3 > g ? f3 : g);
- out[4] = (f4 > g ? f4 : g); out[5] = (f5 > g ? f5 : g);
- out[6] = (f6 > g ? f6 : g); out[7] = (f7 > g ? f7 : g);
+ out[0] = (f0 > g ? f0 : g); out[1] = (f1 > g ? f1 : g);
+ out[2] = (f2 > g ? f2 : g); out[3] = (f3 > g ? f3 : g);
+ out[4] = (f4 > g ? f4 : g); out[5] = (f5 > g ? f5 : g);
+ out[6] = (f6 > g ? f6 : g); out[7] = (f7 > g ? f7 : g);
}
return (w+5);
}
@@ -655,35 +657,35 @@ t_int *scalarmax_perf8(t_int *w)
static void max_dsp(t_max *x, t_signal **sp)
{
if (sp[0]->s_n&7)
- dsp_add(max_perform, 4,
- sp[0]->s_vec, sp[1]->s_vec, sp[2]->s_vec, sp[0]->s_n);
- else
- dsp_add(max_perf8, 4,
- sp[0]->s_vec, sp[1]->s_vec, sp[2]->s_vec, sp[0]->s_n);
+ dsp_add(max_perform, 4,
+ sp[0]->s_vec, sp[1]->s_vec, sp[2]->s_vec, sp[0]->s_n);
+ else
+ dsp_add(max_perf8, 4,
+ sp[0]->s_vec, sp[1]->s_vec, sp[2]->s_vec, sp[0]->s_n);
}
static void scalarmax_dsp(t_scalarmax *x, t_signal **sp)
{
if (sp[0]->s_n&7)
- dsp_add(scalarmax_perform, 4, sp[0]->s_vec, &x->x_g,
- sp[1]->s_vec, sp[0]->s_n);
- else
- dsp_add(scalarmax_perf8, 4, sp[0]->s_vec, &x->x_g,
- sp[1]->s_vec, sp[0]->s_n);
+ dsp_add(scalarmax_perform, 4, sp[0]->s_vec, &x->x_g,
+ sp[1]->s_vec, sp[0]->s_n);
+ else
+ dsp_add(scalarmax_perf8, 4, sp[0]->s_vec, &x->x_g,
+ sp[1]->s_vec, sp[0]->s_n);
}
static void max_setup(void)
{
max_class = class_new(gensym("max~"), (t_newmethod)max_new, 0,
- sizeof(t_max), 0, A_GIMME, 0);
+ sizeof(t_max), 0, A_GIMME, 0);
CLASS_MAINSIGNALIN(max_class, t_max, x_f);
class_addmethod(max_class, (t_method)max_dsp, gensym("dsp"), 0);
class_sethelpsymbol(max_class, gensym("sigbinops"));
scalarmax_class = class_new(gensym("max~"), 0, 0,
- sizeof(t_scalarmax), 0, 0);
+ sizeof(t_scalarmax), 0, 0);
CLASS_MAINSIGNALIN(scalarmax_class, t_scalarmax, x_f);
class_addmethod(scalarmax_class, (t_method)scalarmax_dsp, gensym("dsp"),
- 0);
+ 0);
class_sethelpsymbol(scalarmax_class, gensym("sigbinops"));
}
@@ -708,20 +710,20 @@ static void *min_new(t_symbol *s, int argc, t_atom *argv)
if (argc > 1) post("min~: extra arguments ignored");
if (argc)
{
- t_scalarmin *x = (t_scalarmin *)pd_new(scalarmin_class);
- floatinlet_new(&x->x_obj, &x->x_g);
- x->x_g = atom_getfloatarg(0, argc, argv);
- outlet_new(&x->x_obj, &s_signal);
- x->x_f = 0;
- return (x);
+ t_scalarmin *x = (t_scalarmin *)pd_new(scalarmin_class);
+ floatinlet_new(&x->x_obj, &x->x_g);
+ x->x_g = atom_getfloatarg(0, argc, argv);
+ outlet_new(&x->x_obj, &s_signal);
+ x->x_f = 0;
+ return (x);
}
else
{
- t_min *x = (t_min *)pd_new(min_class);
- inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_signal, &s_signal);
- outlet_new(&x->x_obj, &s_signal);
- x->x_f = 0;
- return (x);
+ t_min *x = (t_min *)pd_new(min_class);
+ inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_signal, &s_signal);
+ outlet_new(&x->x_obj, &s_signal);
+ x->x_f = 0;
+ return (x);
}
}
@@ -733,8 +735,8 @@ t_int *min_perform(t_int *w)
int n = (int)(w[4]);
while (n--)
{
- float f = *in1++, g = *in2++;
- *out++ = (f < g ? f : g);
+ float f = *in1++, g = *in2++;
+ *out++ = (f < g ? f : g);
}
return (w+5);
}
@@ -747,16 +749,16 @@ t_int *min_perf8(t_int *w)
int n = (int)(w[4]);
for (; n; n -= 8, in1 += 8, in2 += 8, out += 8)
{
- float f0 = in1[0], f1 = in1[1], f2 = in1[2], f3 = in1[3];
- float f4 = in1[4], f5 = in1[5], f6 = in1[6], f7 = in1[7];
+ float f0 = in1[0], f1 = in1[1], f2 = in1[2], f3 = in1[3];
+ float f4 = in1[4], f5 = in1[5], f6 = in1[6], f7 = in1[7];
- float g0 = in2[0], g1 = in2[1], g2 = in2[2], g3 = in2[3];
- float g4 = in2[4], g5 = in2[5], g6 = in2[6], g7 = in2[7];
+ float g0 = in2[0], g1 = in2[1], g2 = in2[2], g3 = in2[3];
+ float g4 = in2[4], g5 = in2[5], g6 = in2[6], g7 = in2[7];
- out[0] = (f0 < g0 ? f0 : g0); out[1] = (f1 < g1 ? f1 : g1);
- out[2] = (f2 < g2 ? f2 : g2); out[3] = (f3 < g3 ? f3 : g3);
- out[4] = (f4 < g4 ? f4 : g4); out[5] = (f5 < g5 ? f5 : g5);
- out[6] = (f6 < g6 ? f6 : g6); out[7] = (f7 < g7 ? f7 : g7);
+ out[0] = (f0 < g0 ? f0 : g0); out[1] = (f1 < g1 ? f1 : g1);
+ out[2] = (f2 < g2 ? f2 : g2); out[3] = (f3 < g3 ? f3 : g3);
+ out[4] = (f4 < g4 ? f4 : g4); out[5] = (f5 < g5 ? f5 : g5);
+ out[6] = (f6 < g6 ? f6 : g6); out[7] = (f7 < g7 ? f7 : g7);
}
return (w+5);
}
@@ -769,8 +771,8 @@ t_int *scalarmin_perform(t_int *w)
int n = (int)(w[4]);
while (n--)
{
- t_float g = *in++;
- *out++ = (f < g ? f : g);
+ t_float g = *in++;
+ *out++ = (f < g ? f : g);
}
return (w+5);
}
@@ -783,13 +785,13 @@ t_int *scalarmin_perf8(t_int *w)
int n = (int)(w[4]);
for (; n; n -= 8, in += 8, out += 8)
{
- float f0 = in[0], f1 = in[1], f2 = in[2], f3 = in[3];
- float f4 = in[4], f5 = in[5], f6 = in[6], f7 = in[7];
+ float f0 = in[0], f1 = in[1], f2 = in[2], f3 = in[3];
+ float f4 = in[4], f5 = in[5], f6 = in[6], f7 = in[7];
- out[0] = (f0 < g ? f0 : g); out[1] = (f1 < g ? f1 : g);
- out[2] = (f2 < g ? f2 : g); out[3] = (f3 < g ? f3 : g);
- out[4] = (f4 < g ? f4 : g); out[5] = (f5 < g ? f5 : g);
- out[6] = (f6 < g ? f6 : g); out[7] = (f7 < g ? f7 : g);
+ out[0] = (f0 < g ? f0 : g); out[1] = (f1 < g ? f1 : g);
+ out[2] = (f2 < g ? f2 : g); out[3] = (f3 < g ? f3 : g);
+ out[4] = (f4 < g ? f4 : g); out[5] = (f5 < g ? f5 : g);
+ out[6] = (f6 < g ? f6 : g); out[7] = (f7 < g ? f7 : g);
}
return (w+5);
}
@@ -797,35 +799,35 @@ t_int *scalarmin_perf8(t_int *w)
static void min_dsp(t_min *x, t_signal **sp)
{
if (sp[0]->s_n&7)
- dsp_add(min_perform, 4,
- sp[0]->s_vec, sp[1]->s_vec, sp[2]->s_vec, sp[0]->s_n);
- else
- dsp_add(min_perf8, 4,
- sp[0]->s_vec, sp[1]->s_vec, sp[2]->s_vec, sp[0]->s_n);
+ dsp_add(min_perform, 4,
+ sp[0]->s_vec, sp[1]->s_vec, sp[2]->s_vec, sp[0]->s_n);
+ else
+ dsp_add(min_perf8, 4,
+ sp[0]->s_vec, sp[1]->s_vec, sp[2]->s_vec, sp[0]->s_n);
}
static void scalarmin_dsp(t_scalarmin *x, t_signal **sp)
{
if (sp[0]->s_n&7)
- dsp_add(scalarmin_perform, 4, sp[0]->s_vec, &x->x_g,
- sp[1]->s_vec, sp[0]->s_n);
- else
- dsp_add(scalarmin_perf8, 4, sp[0]->s_vec, &x->x_g,
- sp[1]->s_vec, sp[0]->s_n);
+ dsp_add(scalarmin_perform, 4, sp[0]->s_vec, &x->x_g,
+ sp[1]->s_vec, sp[0]->s_n);
+ else
+ dsp_add(scalarmin_perf8, 4, sp[0]->s_vec, &x->x_g,
+ sp[1]->s_vec, sp[0]->s_n);
}
static void min_setup(void)
{
min_class = class_new(gensym("min~"), (t_newmethod)min_new, 0,
- sizeof(t_min), 0, A_GIMME, 0);
+ sizeof(t_min), 0, A_GIMME, 0);
CLASS_MAINSIGNALIN(min_class, t_min, x_f);
class_addmethod(min_class, (t_method)min_dsp, gensym("dsp"), 0);
class_sethelpsymbol(min_class, gensym("sigbinops"));
scalarmin_class = class_new(gensym("min~"), 0, 0,
- sizeof(t_scalarmin), 0, 0);
+ sizeof(t_scalarmin), 0, 0);
CLASS_MAINSIGNALIN(scalarmin_class, t_scalarmin, x_f);
class_addmethod(scalarmin_class, (t_method)scalarmin_dsp, gensym("dsp"),
- 0);
+ 0);
class_sethelpsymbol(scalarmin_class, gensym("sigbinops"));
}
diff --git a/pd/src/d_array.c b/pd/src/d_array.c
index 9b68b758..55e866bd 100644
--- a/pd/src/d_array.c
+++ b/pd/src/d_array.c
@@ -20,7 +20,6 @@ typedef struct _tabwrite_tilde
int x_nsampsintab;
float *x_vec;
t_symbol *x_arrayname;
- t_clock *x_clock;
float x_f;
} t_tabwrite_tilde;
@@ -29,13 +28,20 @@ static void tabwrite_tilde_tick(t_tabwrite_tilde *x);
static void *tabwrite_tilde_new(t_symbol *s)
{
t_tabwrite_tilde *x = (t_tabwrite_tilde *)pd_new(tabwrite_tilde_class);
- x->x_clock = clock_new(x, (t_method)tabwrite_tilde_tick);
x->x_phase = 0x7fffffff;
x->x_arrayname = s;
x->x_f = 0;
return (x);
}
+static void tabwrite_tilde_redraw(t_tabwrite_tilde *x)
+{
+ t_garray *a = (t_garray *)pd_findbyclass(x->x_arrayname, garray_class);
+ if (!a)
+ bug("tabwrite_tilde_redraw");
+ else garray_redraw(a);
+}
+
static t_int *tabwrite_tilde_perform(t_int *w)
{
t_tabwrite_tilde *x = (t_tabwrite_tilde *)(w[1]);
@@ -45,24 +51,25 @@ static t_int *tabwrite_tilde_perform(t_int *w)
if (endphase > phase)
{
- int nxfer = endphase - phase;
- float *fp = x->x_vec + phase;
- if (nxfer > n) nxfer = n;
- phase += nxfer;
- while (nxfer--)
- {
- float f = *in++;
- if (PD_BADFLOAT(f))
- f = 0;
- *fp++ = f;
- }
- if (phase >= endphase)
- {
- clock_delay(x->x_clock, 0);
- phase = 0x7fffffff;
- }
- x->x_phase = phase;
+ int nxfer = endphase - phase;
+ float *fp = x->x_vec + phase;
+ if (nxfer > n) nxfer = n;
+ phase += nxfer;
+ while (nxfer--)
+ {
+ float f = *in++;
+ if (PD_BIGORSMALL(f))
+ f = 0;
+ *fp++ = f;
+ }
+ if (phase >= endphase)
+ {
+ tabwrite_tilde_redraw(x);
+ phase = 0x7fffffff;
+ }
+ x->x_phase = phase;
}
+ else x->x_phase = 0x7fffffff;
bad:
return (w+4);
}
@@ -74,14 +81,14 @@ void tabwrite_tilde_set(t_tabwrite_tilde *x, t_symbol *s)
x->x_arrayname = s;
if (!(a = (t_garray *)pd_findbyclass(x->x_arrayname, garray_class)))
{
- if (*s->s_name) pd_error(x, "tabwrite~: %s: no such array",
- x->x_arrayname->s_name);
- x->x_vec = 0;
+ if (*s->s_name) pd_error(x, "tabwrite~: %s: no such array",
+ x->x_arrayname->s_name);
+ x->x_vec = 0;
}
else if (!garray_getfloatarray(a, &x->x_nsampsintab, &x->x_vec))
{
- pd_error(x, "%s: bad template for tabwrite~", x->x_arrayname->s_name);
- x->x_vec = 0;
+ pd_error(x, "%s: bad template for tabwrite~", x->x_arrayname->s_name);
+ x->x_vec = 0;
}
else garray_usedindsp(a);
}
@@ -97,39 +104,34 @@ static void tabwrite_tilde_bang(t_tabwrite_tilde *x)
x->x_phase = 0;
}
+static void tabwrite_tilde_start(t_tabwrite_tilde *x, t_floatarg f)
+{
+ x->x_phase = (f > 0 ? f : 0);
+}
+
static void tabwrite_tilde_stop(t_tabwrite_tilde *x)
{
if (x->x_phase != 0x7fffffff)
{
- tabwrite_tilde_tick(x);
- x->x_phase = 0x7fffffff;
+ tabwrite_tilde_redraw(x);
+ x->x_phase = 0x7fffffff;
}
}
-static void tabwrite_tilde_tick(t_tabwrite_tilde *x)
-{
- t_garray *a = (t_garray *)pd_findbyclass(x->x_arrayname, garray_class);
- if (!a) bug("tabwrite_tilde_tick");
- else garray_redraw(a);
-}
-
-static void tabwrite_tilde_free(t_tabwrite_tilde *x)
-{
- clock_free(x->x_clock);
-}
-
static void tabwrite_tilde_setup(void)
{
tabwrite_tilde_class = class_new(gensym("tabwrite~"),
- (t_newmethod)tabwrite_tilde_new, (t_method)tabwrite_tilde_free,
- sizeof(t_tabwrite_tilde), 0, A_DEFSYM, 0);
+ (t_newmethod)tabwrite_tilde_new, 0,
+ sizeof(t_tabwrite_tilde), 0, A_DEFSYM, 0);
CLASS_MAINSIGNALIN(tabwrite_tilde_class, t_tabwrite_tilde, x_f);
class_addmethod(tabwrite_tilde_class, (t_method)tabwrite_tilde_dsp,
- gensym("dsp"), 0);
+ gensym("dsp"), 0);
class_addmethod(tabwrite_tilde_class, (t_method)tabwrite_tilde_set,
- gensym("set"), A_SYMBOL, 0);
+ gensym("set"), A_SYMBOL, 0);
class_addmethod(tabwrite_tilde_class, (t_method)tabwrite_tilde_stop,
- gensym("stop"), 0);
+ gensym("stop"), 0);
+ class_addmethod(tabwrite_tilde_class, (t_method)tabwrite_tilde_start,
+ gensym("start"), A_DEFFLOAT, 0);
class_addbang(tabwrite_tilde_class, tabwrite_tilde_bang);
}
@@ -168,25 +170,25 @@ static t_int *tabplay_tilde_perform(t_int *w)
t_tabplay_tilde *x = (t_tabplay_tilde *)(w[1]);
t_float *out = (t_float *)(w[2]), *fp;
int n = (int)(w[3]), phase = x->x_phase,
- endphase = (x->x_nsampsintab < x->x_limit ?
- x->x_nsampsintab : x->x_limit), nxfer, n3;
+ endphase = (x->x_nsampsintab < x->x_limit ?
+ x->x_nsampsintab : x->x_limit), nxfer, n3;
if (!x->x_vec || phase >= endphase)
- goto zero;
+ goto zero;
nxfer = endphase - phase;
fp = x->x_vec + phase;
if (nxfer > n)
- nxfer = n;
+ nxfer = n;
n3 = n - nxfer;
phase += nxfer;
while (nxfer--)
- *out++ = *fp++;
+ *out++ = *fp++;
if (phase >= endphase)
{
- clock_delay(x->x_clock, 0);
- x->x_phase = 0x7fffffff;
- while (n3--)
- *out++ = 0;
+ clock_delay(x->x_clock, 0);
+ x->x_phase = 0x7fffffff;
+ while (n3--)
+ *out++ = 0;
}
else x->x_phase = phase;
@@ -203,14 +205,14 @@ void tabplay_tilde_set(t_tabplay_tilde *x, t_symbol *s)
x->x_arrayname = s;
if (!(a = (t_garray *)pd_findbyclass(x->x_arrayname, garray_class)))
{
- if (*s->s_name) pd_error(x, "tabplay~: %s: no such array",
- x->x_arrayname->s_name);
- x->x_vec = 0;
+ if (*s->s_name) pd_error(x, "tabplay~: %s: no such array",
+ x->x_arrayname->s_name);
+ x->x_vec = 0;
}
else if (!garray_getfloatarray(a, &x->x_nsampsintab, &x->x_vec))
{
- pd_error(x, "%s: bad template for tabplay~", x->x_arrayname->s_name);
- x->x_vec = 0;
+ pd_error(x, "%s: bad template for tabplay~", x->x_arrayname->s_name);
+ x->x_vec = 0;
}
else garray_usedindsp(a);
}
@@ -228,9 +230,9 @@ static void tabplay_tilde_list(t_tabplay_tilde *x, t_symbol *s,
long length = atom_getfloatarg(1, argc, argv);
if (start < 0) start = 0;
if (length <= 0)
- x->x_limit = 0x7fffffff;
+ x->x_limit = 0x7fffffff;
else
- x->x_limit = start + length;
+ x->x_limit = start + length;
x->x_phase = start;
}
@@ -252,14 +254,14 @@ static void tabplay_tilde_free(t_tabplay_tilde *x)
static void tabplay_tilde_setup(void)
{
tabplay_tilde_class = class_new(gensym("tabplay~"),
- (t_newmethod)tabplay_tilde_new, (t_method)tabplay_tilde_free,
- sizeof(t_tabplay_tilde), 0, A_DEFSYM, 0);
+ (t_newmethod)tabplay_tilde_new, (t_method)tabplay_tilde_free,
+ sizeof(t_tabplay_tilde), 0, A_DEFSYM, 0);
class_addmethod(tabplay_tilde_class, (t_method)tabplay_tilde_dsp,
- gensym("dsp"), 0);
+ gensym("dsp"), 0);
class_addmethod(tabplay_tilde_class, (t_method)tabplay_tilde_stop,
- gensym("stop"), 0);
+ gensym("stop"), 0);
class_addmethod(tabplay_tilde_class, (t_method)tabplay_tilde_set,
- gensym("set"), A_DEFSYM, 0);
+ gensym("set"), A_DEFSYM, 0);
class_addlist(tabplay_tilde_class, tabplay_tilde_list);
}
@@ -301,12 +303,12 @@ static t_int *tabread_tilde_perform(t_int *w)
for (i = 0; i < n; i++)
{
- int index = *in++;
- if (index < 0)
- index = 0;
- else if (index > maxindex)
- index = maxindex;
- *out++ = buf[index];
+ int index = *in++;
+ if (index < 0)
+ index = 0;
+ else if (index > maxindex)
+ index = maxindex;
+ *out++ = buf[index];
}
return (w+5);
zero:
@@ -322,14 +324,14 @@ void tabread_tilde_set(t_tabread_tilde *x, t_symbol *s)
x->x_arrayname = s;
if (!(a = (t_garray *)pd_findbyclass(x->x_arrayname, garray_class)))
{
- if (*s->s_name)
- pd_error(x, "tabread~: %s: no such array", x->x_arrayname->s_name);
- x->x_vec = 0;
+ if (*s->s_name)
+ pd_error(x, "tabread~: %s: no such array", x->x_arrayname->s_name);
+ x->x_vec = 0;
}
else if (!garray_getfloatarray(a, &x->x_npoints, &x->x_vec))
{
- pd_error(x, "%s: bad template for tabread~", x->x_arrayname->s_name);
- x->x_vec = 0;
+ pd_error(x, "%s: bad template for tabread~", x->x_arrayname->s_name);
+ x->x_vec = 0;
}
else garray_usedindsp(a);
}
@@ -339,7 +341,7 @@ static void tabread_tilde_dsp(t_tabread_tilde *x, t_signal **sp)
tabread_tilde_set(x, x->x_arrayname);
dsp_add(tabread_tilde_perform, 4, x,
- sp[0]->s_vec, sp[1]->s_vec, sp[0]->s_n);
+ sp[0]->s_vec, sp[1]->s_vec, sp[0]->s_n);
}
@@ -350,13 +352,13 @@ static void tabread_tilde_free(t_tabread_tilde *x)
static void tabread_tilde_setup(void)
{
tabread_tilde_class = class_new(gensym("tabread~"),
- (t_newmethod)tabread_tilde_new, (t_method)tabread_tilde_free,
- sizeof(t_tabread_tilde), 0, A_DEFSYM, 0);
+ (t_newmethod)tabread_tilde_new, (t_method)tabread_tilde_free,
+ sizeof(t_tabread_tilde), 0, A_DEFSYM, 0);
CLASS_MAINSIGNALIN(tabread_tilde_class, t_tabread_tilde, x_f);
class_addmethod(tabread_tilde_class, (t_method)tabread_tilde_dsp,
- gensym("dsp"), 0);
+ gensym("dsp"), 0);
class_addmethod(tabread_tilde_class, (t_method)tabread_tilde_set,
- gensym("set"), A_SYMBOL, 0);
+ gensym("set"), A_SYMBOL, 0);
}
/******************** tabread4~ ***********************/
@@ -396,46 +398,46 @@ static t_int *tabread4_tilde_perform(t_int *w)
if (!buf) goto zero;
-#if 0 /* test for spam -- I'm not ready to deal with this */
+#if 0 /* test for spam -- I'm not ready to deal with this */
for (i = 0, xmax = 0, xmin = maxindex, fp = in1; i < n; i++, fp++)
{
- float f = *in1;
- if (f < xmin) xmin = f;
- else if (f > xmax) xmax = f;
+ float f = *in1;
+ if (f < xmin) xmin = f;
+ else if (f > xmax) xmax = f;
}
if (xmax < xmin + x->c_maxextent) xmax = xmin + x->c_maxextent;
for (i = 0, splitlo = xmin+ x->c_maxextent, splithi = xmax - x->c_maxextent,
- fp = in1; i < n; i++, fp++)
+ fp = in1; i < n; i++, fp++)
{
- float f = *in1;
- if (f > splitlo && f < splithi) goto zero;
+ float f = *in1;
+ if (f > splitlo && f < splithi) goto zero;
}
#endif
for (i = 0; i < n; i++)
{
- float findex = *in++;
- int index = findex;
- float frac, a, b, c, d, cminusb;
- static int count;
- if (index < 1)
- index = 1, frac = 0;
- else if (index > maxindex)
- index = maxindex, frac = 1;
- else frac = findex - index;
- fp = buf + index;
- a = fp[-1];
- b = fp[0];
- c = fp[1];
- d = fp[2];
- /* if (!i && !(count++ & 1023))
- post("fp = %lx, shit = %lx, b = %f", fp, buf->b_shit, b); */
- cminusb = c-b;
- *out++ = b + frac * (
- cminusb - 0.1666667f * (1.-frac) * (
- (d - a - 3.0f * cminusb) * frac + (d + 2.0f*a - 3.0f*b)
- )
- );
+ float findex = *in++;
+ int index = findex;
+ float frac, a, b, c, d, cminusb;
+ static int count;
+ if (index < 1)
+ index = 1, frac = 0;
+ else if (index > maxindex)
+ index = maxindex, frac = 1;
+ else frac = findex - index;
+ fp = buf + index;
+ a = fp[-1];
+ b = fp[0];
+ c = fp[1];
+ d = fp[2];
+ /* if (!i && !(count++ & 1023))
+ post("fp = %lx, shit = %lx, b = %f", fp, buf->b_shit, b); */
+ cminusb = c-b;
+ *out++ = b + frac * (
+ cminusb - 0.1666667f * (1.-frac) * (
+ (d - a - 3.0f * cminusb) * frac + (d + 2.0f*a - 3.0f*b)
+ )
+ );
}
return (w+5);
zero:
@@ -451,14 +453,14 @@ void tabread4_tilde_set(t_tabread4_tilde *x, t_symbol *s)
x->x_arrayname = s;
if (!(a = (t_garray *)pd_findbyclass(x->x_arrayname, garray_class)))
{
- if (*s->s_name)
- pd_error(x, "tabread4~: %s: no such array", x->x_arrayname->s_name);
- x->x_vec = 0;
+ if (*s->s_name)
+ pd_error(x, "tabread4~: %s: no such array", x->x_arrayname->s_name);
+ x->x_vec = 0;
}
else if (!garray_getfloatarray(a, &x->x_npoints, &x->x_vec))
{
- pd_error(x, "%s: bad template for tabread4~", x->x_arrayname->s_name);
- x->x_vec = 0;
+ pd_error(x, "%s: bad template for tabread4~", x->x_arrayname->s_name);
+ x->x_vec = 0;
}
else garray_usedindsp(a);
}
@@ -468,7 +470,7 @@ static void tabread4_tilde_dsp(t_tabread4_tilde *x, t_signal **sp)
tabread4_tilde_set(x, x->x_arrayname);
dsp_add(tabread4_tilde_perform, 4, x,
- sp[0]->s_vec, sp[1]->s_vec, sp[0]->s_n);
+ sp[0]->s_vec, sp[1]->s_vec, sp[0]->s_n);
}
@@ -479,13 +481,13 @@ static void tabread4_tilde_free(t_tabread4_tilde *x)
static void tabread4_tilde_setup(void)
{
tabread4_tilde_class = class_new(gensym("tabread4~"),
- (t_newmethod)tabread4_tilde_new, (t_method)tabread4_tilde_free,
- sizeof(t_tabread4_tilde), 0, A_DEFSYM, 0);
+ (t_newmethod)tabread4_tilde_new, (t_method)tabread4_tilde_free,
+ sizeof(t_tabread4_tilde), 0, A_DEFSYM, 0);
CLASS_MAINSIGNALIN(tabread4_tilde_class, t_tabread4_tilde, x_f);
class_addmethod(tabread4_tilde_class, (t_method)tabread4_tilde_dsp,
- gensym("dsp"), 0);
+ gensym("dsp"), 0);
class_addmethod(tabread4_tilde_class, (t_method)tabread4_tilde_set,
- gensym("set"), A_SYMBOL, 0);
+ gensym("set"), A_SYMBOL, 0);
}
/******************** tabosc4~ ***********************/
@@ -604,22 +606,22 @@ static t_int *tabosc4_tilde_perform(t_int *w)
#if 1
while (n--)
{
- float frac, a, b, c, d, cminusb;
- tf.tf_d = dphase;
- dphase += *in++ * conv;
- addr = tab + (tf.tf_i[HIOFFSET] & mask);
- tf.tf_i[HIOFFSET] = normhipart;
- frac = tf.tf_d - UNITBIT32;
- a = addr[0];
- b = addr[1];
- c = addr[2];
- d = addr[3];
- cminusb = c-b;
- *out++ = b + frac * (
- cminusb - 0.1666667f * (1.-frac) * (
- (d - a - 3.0f * cminusb) * frac + (d + 2.0f*a - 3.0f*b)
- )
- );
+ float frac, a, b, c, d, cminusb;
+ tf.tf_d = dphase;
+ dphase += *in++ * conv;
+ addr = tab + (tf.tf_i[HIOFFSET] & mask);
+ tf.tf_i[HIOFFSET] = normhipart;
+ frac = tf.tf_d - UNITBIT32;
+ a = addr[0];
+ b = addr[1];
+ c = addr[2];
+ d = addr[3];
+ cminusb = c-b;
+ *out++ = b + frac * (
+ cminusb - 0.1666667f * (1.-frac) * (
+ (d - a - 3.0f * cminusb) * frac + (d + 2.0f*a - 3.0f*b)
+ )
+ );
}
#endif
@@ -643,27 +645,27 @@ void tabosc4_tilde_set(t_tabosc4_tilde *x, t_symbol *s)
x->x_arrayname = s;
if (!(a = (t_garray *)pd_findbyclass(x->x_arrayname, garray_class)))
{
- if (*s->s_name)
- pd_error(x, "tabosc4~: %s: no such array", x->x_arrayname->s_name);
- x->x_vec = 0;
+ if (*s->s_name)
+ pd_error(x, "tabosc4~: %s: no such array", x->x_arrayname->s_name);
+ x->x_vec = 0;
}
else if (!garray_getfloatarray(a, &pointsinarray, &x->x_vec))
{
- pd_error(x, "%s: bad template for tabosc4~", x->x_arrayname->s_name);
- x->x_vec = 0;
+ pd_error(x, "%s: bad template for tabosc4~", x->x_arrayname->s_name);
+ x->x_vec = 0;
}
else if ((npoints = pointsinarray - 3) != (1 << ilog2(pointsinarray - 3)))
{
- pd_error(x, "%s: number of points (%d) not a power of 2 plus three",
- x->x_arrayname->s_name, pointsinarray);
- x->x_vec = 0;
- garray_usedindsp(a);
+ pd_error(x, "%s: number of points (%d) not a power of 2 plus three",
+ x->x_arrayname->s_name, pointsinarray);
+ x->x_vec = 0;
+ garray_usedindsp(a);
}
else
{
- x->x_fnpoints = npoints;
- x->x_finvnpoints = 1./npoints;
- garray_usedindsp(a);
+ x->x_fnpoints = npoints;
+ x->x_finvnpoints = 1./npoints;
+ garray_usedindsp(a);
}
}
@@ -678,21 +680,21 @@ static void tabosc4_tilde_dsp(t_tabosc4_tilde *x, t_signal **sp)
tabosc4_tilde_set(x, x->x_arrayname);
dsp_add(tabosc4_tilde_perform, 4, x,
- sp[0]->s_vec, sp[1]->s_vec, sp[0]->s_n);
+ sp[0]->s_vec, sp[1]->s_vec, sp[0]->s_n);
}
static void tabosc4_tilde_setup(void)
{
tabosc4_tilde_class = class_new(gensym("tabosc4~"),
- (t_newmethod)tabosc4_tilde_new, 0,
- sizeof(t_tabosc4_tilde), 0, A_DEFSYM, 0);
+ (t_newmethod)tabosc4_tilde_new, 0,
+ sizeof(t_tabosc4_tilde), 0, A_DEFSYM, 0);
CLASS_MAINSIGNALIN(tabosc4_tilde_class, t_tabosc4_tilde, x_f);
class_addmethod(tabosc4_tilde_class, (t_method)tabosc4_tilde_dsp,
- gensym("dsp"), 0);
+ gensym("dsp"), 0);
class_addmethod(tabosc4_tilde_class, (t_method)tabosc4_tilde_set,
- gensym("set"), A_SYMBOL, 0);
+ gensym("set"), A_SYMBOL, 0);
class_addmethod(tabosc4_tilde_class, (t_method)tabosc4_tilde_ft1,
- gensym("ft1"), A_FLOAT, 0);
+ gensym("ft1"), A_FLOAT, 0);
}
/* ------------------------ tabsend~ ------------------------- */
@@ -706,7 +708,6 @@ typedef struct _tabsend
int x_graphperiod;
int x_graphcount;
t_symbol *x_arrayname;
- t_clock *x_clock;
float x_f;
} t_tabsend;
@@ -717,7 +718,6 @@ static void *tabsend_new(t_symbol *s)
t_tabsend *x = (t_tabsend *)pd_new(tabsend_class);
x->x_graphcount = 0;
x->x_arrayname = s;
- x->x_clock = clock_new(x, (t_method)tabsend_tick);
x->x_f = 0;
return (x);
}
@@ -732,16 +732,19 @@ static t_int *tabsend_perform(t_int *w)
if (!x->x_vec) goto bad;
while (n--)
- {
- float f = *in++;
- if (PD_BADFLOAT(f))
- f = 0;
- *dest++ = f;
+ {
+ float f = *in++;
+ if (PD_BIGORSMALL(f))
+ f = 0;
+ *dest++ = f;
}
if (!i--)
{
- clock_delay(x->x_clock, 0);
- i = x->x_graphperiod;
+ t_garray *a = (t_garray *)pd_findbyclass(x->x_arrayname, garray_class);
+ if (!a)
+ bug("tabsend_dsp");
+ else garray_redraw(a);
+ i = x->x_graphperiod;
}
x->x_graphcount = i;
bad:
@@ -755,40 +758,28 @@ static void tabsend_dsp(t_tabsend *x, t_signal **sp)
if (!(a = (t_garray *)pd_findbyclass(x->x_arrayname, garray_class)))
{
- if (*x->x_arrayname->s_name)
- pd_error(x, "tabsend~: %s: no such array", x->x_arrayname->s_name);
+ if (*x->x_arrayname->s_name)
+ pd_error(x, "tabsend~: %s: no such array", x->x_arrayname->s_name);
}
else if (!garray_getfloatarray(a, &vecsize, &x->x_vec))
- pd_error(x, "%s: bad template for tabsend~", x->x_arrayname->s_name);
+ pd_error(x, "%s: bad template for tabsend~", x->x_arrayname->s_name);
else
{
- int n = sp[0]->s_n;
- int ticksper = sp[0]->s_sr/n;
- if (ticksper < 1) ticksper = 1;
- x->x_graphperiod = ticksper;
- if (x->x_graphcount > ticksper) x->x_graphcount = ticksper;
- if (n < vecsize) vecsize = n;
- garray_usedindsp(a);
- dsp_add(tabsend_perform, 3, x, sp[0]->s_vec, vecsize);
+ int n = sp[0]->s_n;
+ int ticksper = sp[0]->s_sr/n;
+ if (ticksper < 1) ticksper = 1;
+ x->x_graphperiod = ticksper;
+ if (x->x_graphcount > ticksper) x->x_graphcount = ticksper;
+ if (n < vecsize) vecsize = n;
+ garray_usedindsp(a);
+ dsp_add(tabsend_perform, 3, x, sp[0]->s_vec, vecsize);
}
}
-static void tabsend_tick(t_tabsend *x)
-{
- t_garray *a = (t_garray *)pd_findbyclass(x->x_arrayname, garray_class);
- if (!a) bug("tabsend_tick");
- else garray_redraw(a);
-}
-
-static void tabsend_free(t_tabsend *x)
-{
- clock_free(x->x_clock);
-}
-
static void tabsend_setup(void)
{
tabsend_class = class_new(gensym("tabsend~"), (t_newmethod)tabsend_new,
- (t_method)tabsend_free, sizeof(t_tabsend), 0, A_DEFSYM, 0);
+ 0, sizeof(t_tabsend), 0, A_DEFSYM, 0);
CLASS_MAINSIGNALIN(tabsend_class, t_tabsend, x_f);
class_addmethod(tabsend_class, (t_method)tabsend_dsp, gensym("dsp"), 0);
}
@@ -822,17 +813,17 @@ static void tabreceive_dsp(t_tabreceive *x, t_signal **sp)
if (!(a = (t_garray *)pd_findbyclass(x->x_arrayname, garray_class)))
{
- if (*x->x_arrayname->s_name)
- pd_error(x, "tabsend~: %s: no such array", x->x_arrayname->s_name);
+ if (*x->x_arrayname->s_name)
+ pd_error(x, "tabsend~: %s: no such array", x->x_arrayname->s_name);
}
else if (!garray_getfloatarray(a, &vecsize, &x->x_vec))
- pd_error(x, "%s: bad template for tabreceive~", x->x_arrayname->s_name);
+ pd_error(x, "%s: bad template for tabreceive~", x->x_arrayname->s_name);
else
{
- int n = sp[0]->s_n;
- if (n < vecsize) vecsize = n;
- garray_usedindsp(a);
- dsp_add(tabreceive_perform, 3, x, sp[0]->s_vec, vecsize);
+ int n = sp[0]->s_n;
+ if (n < vecsize) vecsize = n;
+ garray_usedindsp(a);
+ dsp_add(tabreceive_perform, 3, x, sp[0]->s_vec, vecsize);
}
}
@@ -847,10 +838,10 @@ static void *tabreceive_new(t_symbol *s)
static void tabreceive_setup(void)
{
tabreceive_class = class_new(gensym("tabreceive~"),
- (t_newmethod)tabreceive_new, 0,
- sizeof(t_tabreceive), 0, A_DEFSYM, 0);
+ (t_newmethod)tabreceive_new, 0,
+ sizeof(t_tabreceive), 0, A_DEFSYM, 0);
class_addmethod(tabreceive_class, (t_method)tabreceive_dsp,
- gensym("dsp"), 0);
+ gensym("dsp"), 0);
}
/* ---------- tabread: control, non-interpolating ------------------------ */
@@ -870,15 +861,15 @@ static void tabread_float(t_tabread *x, t_float f)
t_float *vec;
if (!(a = (t_garray *)pd_findbyclass(x->x_arrayname, garray_class)))
- pd_error(x, "%s: no such array", x->x_arrayname->s_name);
+ pd_error(x, "%s: no such array", x->x_arrayname->s_name);
else if (!garray_getfloatarray(a, &npoints, &vec))
- pd_error(x, "%s: bad template for tabread", x->x_arrayname->s_name);
+ pd_error(x, "%s: bad template for tabread", x->x_arrayname->s_name);
else
{
- int n = f;
- if (n < 0) n = 0;
- else if (n >= npoints) n = npoints - 1;
- outlet_float(x->x_obj.ob_outlet, (npoints ? vec[n] : 0));
+ int n = f;
+ if (n < 0) n = 0;
+ else if (n >= npoints) n = npoints - 1;
+ outlet_float(x->x_obj.ob_outlet, (npoints ? vec[n] : 0));
}
}
@@ -898,10 +889,10 @@ static void *tabread_new(t_symbol *s)
static void tabread_setup(void)
{
tabread_class = class_new(gensym("tabread"), (t_newmethod)tabread_new,
- 0, sizeof(t_tabread), 0, A_DEFSYM, 0);
+ 0, sizeof(t_tabread), 0, A_DEFSYM, 0);
class_addfloat(tabread_class, (t_method)tabread_float);
class_addmethod(tabread_class, (t_method)tabread_set, gensym("set"),
- A_SYMBOL, 0);
+ A_SYMBOL, 0);
}
/* ---------- tabread4: control, non-interpolating ------------------------ */
@@ -921,31 +912,31 @@ static void tabread4_float(t_tabread4 *x, t_float f)
t_float *vec;
if (!(a = (t_garray *)pd_findbyclass(x->x_arrayname, garray_class)))
- pd_error(x, "%s: no such array", x->x_arrayname->s_name);
+ pd_error(x, "%s: no such array", x->x_arrayname->s_name);
else if (!garray_getfloatarray(a, &npoints, &vec))
- pd_error(x, "%s: bad template for tabread4", x->x_arrayname->s_name);
+ pd_error(x, "%s: bad template for tabread4", x->x_arrayname->s_name);
else if (npoints < 4)
- outlet_float(x->x_obj.ob_outlet, 0);
+ outlet_float(x->x_obj.ob_outlet, 0);
else if (f <= 1)
- outlet_float(x->x_obj.ob_outlet, vec[1]);
+ outlet_float(x->x_obj.ob_outlet, vec[1]);
else if (f >= npoints - 2)
- outlet_float(x->x_obj.ob_outlet, vec[npoints - 2]);
+ outlet_float(x->x_obj.ob_outlet, vec[npoints - 2]);
else
{
- int n = f;
- float a, b, c, d, cminusb, frac, *fp;
- if (n >= npoints - 2)
- n = npoints - 3;
- fp = vec + n;
- frac = f - n;
- a = fp[-1];
- b = fp[0];
- c = fp[1];
- d = fp[2];
- cminusb = c-b;
- outlet_float(x->x_obj.ob_outlet, b + frac * (
- cminusb - 0.1666667f * (1.-frac) * (
- (d - a - 3.0f * cminusb) * frac + (d + 2.0f*a - 3.0f*b))));
+ int n = f;
+ float a, b, c, d, cminusb, frac, *fp;
+ if (n >= npoints - 2)
+ n = npoints - 3;
+ fp = vec + n;
+ frac = f - n;
+ a = fp[-1];
+ b = fp[0];
+ c = fp[1];
+ d = fp[2];
+ cminusb = c-b;
+ outlet_float(x->x_obj.ob_outlet, b + frac * (
+ cminusb - 0.1666667f * (1.-frac) * (
+ (d - a - 3.0f * cminusb) * frac + (d + 2.0f*a - 3.0f*b))));
}
}
@@ -965,10 +956,10 @@ static void *tabread4_new(t_symbol *s)
static void tabread4_setup(void)
{
tabread4_class = class_new(gensym("tabread4"), (t_newmethod)tabread4_new,
- 0, sizeof(t_tabread4), 0, A_DEFSYM, 0);
+ 0, sizeof(t_tabread4), 0, A_DEFSYM, 0);
class_addfloat(tabread4_class, (t_method)tabread4_float);
class_addmethod(tabread4_class, (t_method)tabread4_set, gensym("set"),
- A_SYMBOL, 0);
+ A_SYMBOL, 0);
}
/* ------------------ tabwrite: control ------------------------ */
@@ -979,21 +970,9 @@ typedef struct _tabwrite
{
t_object x_obj;
t_symbol *x_arrayname;
- t_clock *x_clock;
float x_ft1;
- double x_updtime;
- int x_set;
} t_tabwrite;
-static void tabwrite_tick(t_tabwrite *x)
-{
- t_garray *a = (t_garray *)pd_findbyclass(x->x_arrayname, garray_class);
- if (!a) bug("tabwrite_tick");
- else garray_redraw(a);
- x->x_set = 0;
- x->x_updtime = clock_getsystime();
-}
-
static void tabwrite_float(t_tabwrite *x, t_float f)
{
int i, vecsize;
@@ -1001,28 +980,18 @@ static void tabwrite_float(t_tabwrite *x, t_float f)
t_float *vec;
if (!(a = (t_garray *)pd_findbyclass(x->x_arrayname, garray_class)))
- pd_error(x, "%s: no such array", x->x_arrayname->s_name);
+ pd_error(x, "%s: no such array", x->x_arrayname->s_name);
else if (!garray_getfloatarray(a, &vecsize, &vec))
- pd_error(x, "%s: bad template for tabwrite", x->x_arrayname->s_name);
+ pd_error(x, "%s: bad template for tabwrite", x->x_arrayname->s_name);
else
{
- int n = x->x_ft1;
- double timesince = clock_gettimesince(x->x_updtime);
- if (n < 0) n = 0;
- else if (n >= vecsize) n = vecsize-1;
- vec[n] = f;
- if (timesince > 1000)
- {
- tabwrite_tick(x);
- }
- else
- {
- if (x->x_set == 0)
- {
- clock_delay(x->x_clock, 1000 - timesince);
- x->x_set = 1;
- }
- }
+ int n = x->x_ft1;
+ if (n < 0)
+ n = 0;
+ else if (n >= vecsize)
+ n = vecsize-1;
+ vec[n] = f;
+ garray_redraw(a);
}
}
@@ -1031,18 +1000,11 @@ static void tabwrite_set(t_tabwrite *x, t_symbol *s)
x->x_arrayname = s;
}
-static void tabwrite_free(t_tabwrite *x)
-{
- clock_free(x->x_clock);
-}
-
static void *tabwrite_new(t_symbol *s)
{
t_tabwrite *x = (t_tabwrite *)pd_new(tabwrite_class);
x->x_ft1 = 0;
x->x_arrayname = s;
- x->x_updtime = clock_getsystime();
- x->x_clock = clock_new(x, (t_method)tabwrite_tick);
floatinlet_new(&x->x_obj, &x->x_ft1);
return (x);
}
@@ -1050,9 +1012,10 @@ static void *tabwrite_new(t_symbol *s)
void tabwrite_setup(void)
{
tabwrite_class = class_new(gensym("tabwrite"), (t_newmethod)tabwrite_new,
- (t_method)tabwrite_free, sizeof(t_tabwrite), 0, A_DEFSYM, 0);
+ 0, sizeof(t_tabwrite), 0, A_DEFSYM, 0);
class_addfloat(tabwrite_class, (t_method)tabwrite_float);
- class_addmethod(tabwrite_class, (t_method)tabwrite_set, gensym("set"), A_SYMBOL, 0);
+ class_addmethod(tabwrite_class, (t_method)tabwrite_set, gensym("set"),
+ A_SYMBOL, 0);
}
/* ------------------------ global setup routine ------------------------- */
diff --git a/pd/src/d_ctl.c b/pd/src/d_ctl.c
index e94a598d..8dc2345f 100644
--- a/pd/src/d_ctl.c
+++ b/pd/src/d_ctl.c
@@ -24,7 +24,7 @@ static t_int *sig_tilde_perform(t_int *w)
t_float *out = (t_float *)(w[2]);
int n = (int)(w[3]);
while (n--)
- *out++ = f;
+ *out++ = f;
return (w+4);
}
@@ -36,14 +36,14 @@ static t_int *sig_tilde_perf8(t_int *w)
for (; n; n -= 8, out += 8)
{
- out[0] = f;
- out[1] = f;
- out[2] = f;
- out[3] = f;
- out[4] = f;
- out[5] = f;
- out[6] = f;
- out[7] = f;
+ out[0] = f;
+ out[1] = f;
+ out[2] = f;
+ out[3] = f;
+ out[4] = f;
+ out[5] = f;
+ out[6] = f;
+ out[7] = f;
}
return (w+4);
}
@@ -51,9 +51,9 @@ static t_int *sig_tilde_perf8(t_int *w)
void dsp_add_scalarcopy(t_sample *in, t_sample *out, int n)
{
if (n&7)
- dsp_add(sig_tilde_perform, 3, in, out, n);
- else
- dsp_add(sig_tilde_perf8, 3, in, out, n);
+ dsp_add(sig_tilde_perform, 3, in, out, n);
+ else
+ dsp_add(sig_tilde_perf8, 3, in, out, n);
}
static void sig_tilde_float(t_sig *x, t_float f)
@@ -77,7 +77,7 @@ static void *sig_tilde_new(t_floatarg f)
static void sig_tilde_setup(void)
{
sig_tilde_class = class_new(gensym("sig~"), (t_newmethod)sig_tilde_new, 0,
- sizeof(t_sig), 0, A_DEFFLOAT, 0);
+ sizeof(t_sig), 0, A_DEFFLOAT, 0);
class_addfloat(sig_tilde_class, (t_method)sig_tilde_float);
class_addmethod(sig_tilde_class, (t_method)sig_tilde_dsp, gensym("dsp"), 0);
}
@@ -107,28 +107,67 @@ static t_int *line_tilde_perform(t_int *w)
int n = (int)(w[3]);
float f = x->x_value;
- if (PD_BADFLOAT(f))
- x->x_value = f = 0;
+ if (PD_BIGORSMALL(f))
+ x->x_value = f = 0;
if (x->x_retarget)
{
- int nticks = x->x_inletwas * x->x_dspticktomsec;
- if (!nticks) nticks = 1;
- x->x_ticksleft = nticks;
- x->x_biginc = (x->x_target - x->x_value)/(float)nticks;
- x->x_inc = x->x_1overn * x->x_biginc;
- x->x_retarget = 0;
+ int nticks = x->x_inletwas * x->x_dspticktomsec;
+ if (!nticks) nticks = 1;
+ x->x_ticksleft = nticks;
+ x->x_biginc = (x->x_target - x->x_value)/(float)nticks;
+ x->x_inc = x->x_1overn * x->x_biginc;
+ x->x_retarget = 0;
}
if (x->x_ticksleft)
{
- float f = x->x_value;
- while (n--) *out++ = f, f += x->x_inc;
- x->x_value += x->x_biginc;
- x->x_ticksleft--;
+ float f = x->x_value;
+ while (n--) *out++ = f, f += x->x_inc;
+ x->x_value += x->x_biginc;
+ x->x_ticksleft--;
}
else
{
- x->x_value = x->x_target;
- while (n--) *out++ = x->x_value;
+ float g = x->x_value = x->x_target;
+ while (n--)
+ *out++ = g;
+ }
+ return (w+4);
+}
+
+/* TB: vectorized version */
+static t_int *line_tilde_perf8(t_int *w)
+{
+ t_line *x = (t_line *)(w[1]);
+ t_float *out = (t_float *)(w[2]);
+ int n = (int)(w[3]);
+ float f = x->x_value;
+
+ if (PD_BIGORSMALL(f))
+ x->x_value = f = 0;
+ if (x->x_retarget)
+ {
+ int nticks = x->x_inletwas * x->x_dspticktomsec;
+ if (!nticks) nticks = 1;
+ x->x_ticksleft = nticks;
+ x->x_biginc = (x->x_target - x->x_value)/(float)nticks;
+ x->x_inc = x->x_1overn * x->x_biginc;
+ x->x_retarget = 0;
+ }
+ if (x->x_ticksleft)
+ {
+ float f = x->x_value;
+ while (n--) *out++ = f, f += x->x_inc;
+ x->x_value += x->x_biginc;
+ x->x_ticksleft--;
+ }
+ else
+ {
+ float f = x->x_value = x->x_target;
+ for (; n; n -= 8, out += 8)
+ {
+ out[0] = f; out[1] = f; out[2] = f; out[3] = f;
+ out[4] = f; out[5] = f; out[6] = f; out[7] = f;
+ }
}
return (w+4);
}
@@ -137,15 +176,15 @@ static void line_tilde_float(t_line *x, t_float f)
{
if (x->x_inletvalue <= 0)
{
- x->x_target = x->x_value = f;
- x->x_ticksleft = x->x_retarget = 0;
+ x->x_target = x->x_value = f;
+ x->x_ticksleft = x->x_retarget = 0;
}
else
{
- x->x_target = f;
- x->x_retarget = 1;
- x->x_inletwas = x->x_inletvalue;
- x->x_inletvalue = 0;
+ x->x_target = f;
+ x->x_retarget = 1;
+ x->x_inletwas = x->x_inletvalue;
+ x->x_inletvalue = 0;
}
}
@@ -157,7 +196,10 @@ static void line_tilde_stop(t_line *x)
static void line_tilde_dsp(t_line *x, t_signal **sp)
{
- dsp_add(line_tilde_perform, 3, x, sp[0]->s_vec, sp[0]->s_n);
+ if(sp[0]->s_n&7)
+ dsp_add(line_tilde_perform, 3, x, sp[0]->s_vec, sp[0]->s_n);
+ else
+ dsp_add(line_tilde_perf8, 3, x, sp[0]->s_vec, sp[0]->s_n);
x->x_1overn = 1./sp[0]->s_n;
x->x_dspticktomsec = sp[0]->s_sr / (1000 * sp[0]->s_n);
}
@@ -175,12 +217,12 @@ static void *line_tilde_new(void)
static void line_tilde_setup(void)
{
line_tilde_class = class_new(gensym("line~"), line_tilde_new, 0,
- sizeof(t_line), 0, 0);
+ sizeof(t_line), 0, 0);
class_addfloat(line_tilde_class, (t_method)line_tilde_float);
class_addmethod(line_tilde_class, (t_method)line_tilde_dsp,
- gensym("dsp"), 0);
+ gensym("dsp"), 0);
class_addmethod(line_tilde_class, (t_method)line_tilde_stop,
- gensym("stop"), 0);
+ gensym("stop"), 0);
}
/* -------------------------- vline~ ------------------------------ */
@@ -222,42 +264,42 @@ static t_int *vline_tilde_perform(t_int *w)
t_vseg *s = x->x_list;
for (i = 0; i < n; i++)
{
- double timenext = timenow + msecpersamp;
+ double timenext = timenow + msecpersamp;
checknext:
- if (s)
- {
- /* has starttime elapsed? If so update value and increment */
- if (s->s_starttime < timenext)
- {
- if (x->x_targettime <= timenext)
- f = x->x_target, inc = 0;
- /* if zero-length segment bash output value */
- if (s->s_targettime <= s->s_starttime)
- {
- f = s->s_target;
- inc = 0;
- }
- else
- {
- double incpermsec = (s->s_target - f)/
- (s->s_targettime - s->s_starttime);
- f = f + incpermsec * (timenext - s->s_starttime);
- inc = incpermsec * msecpersamp;
- }
- x->x_inc = inc;
- x->x_target = s->s_target;
- x->x_targettime = s->s_targettime;
- x->x_list = s->s_next;
- t_freebytes(s, sizeof(*s));
- s = x->x_list;
- goto checknext;
- }
- }
- if (x->x_targettime <= timenext)
- f = x->x_target, inc = x->x_inc = 0, x->x_targettime = 1e20;
- *out++ = f;
- f = f + inc;
- timenow = timenext;
+ if (s)
+ {
+ /* has starttime elapsed? If so update value and increment */
+ if (s->s_starttime < timenext)
+ {
+ if (x->x_targettime <= timenext)
+ f = x->x_target, inc = 0;
+ /* if zero-length segment bash output value */
+ if (s->s_targettime <= s->s_starttime)
+ {
+ f = s->s_target;
+ inc = 0;
+ }
+ else
+ {
+ double incpermsec = (s->s_target - f)/
+ (s->s_targettime - s->s_starttime);
+ f = f + incpermsec * (timenext - s->s_starttime);
+ inc = incpermsec * msecpersamp;
+ }
+ x->x_inc = inc;
+ x->x_target = s->s_target;
+ x->x_targettime = s->s_targettime;
+ x->x_list = s->s_next;
+ t_freebytes(s, sizeof(*s));
+ s = x->x_list;
+ goto checknext;
+ }
+ }
+ if (x->x_targettime <= timenext)
+ f = x->x_target, inc = x->x_inc = 0, x->x_targettime = 1e20;
+ *out++ = f;
+ f = f + inc;
+ timenow = timenext;
}
x->x_value = f;
return (w+4);
@@ -267,7 +309,7 @@ static void vline_tilde_stop(t_vline *x)
{
t_vseg *s1, *s2;
for (s1 = x->x_list; s1; s1 = s2)
- s2 = s1->s_next, t_freebytes(s1, sizeof(*s1));
+ s2 = s1->s_next, t_freebytes(s1, sizeof(*s1));
x->x_list = 0;
x->x_inc = 0;
x->x_inlet1 = x->x_inlet2 = 0;
@@ -282,50 +324,50 @@ static void vline_tilde_float(t_vline *x, t_float f)
float inlet2 = x->x_inlet2;
double starttime = timenow + inlet2;
t_vseg *s1, *s2, *deletefrom = 0, *snew;
- if (PD_BADFLOAT(f))
- f = 0;
+ if (PD_BIGORSMALL(f))
+ f = 0;
- /* negative delay input means stop and jump immediately to new value */
+ /* negative delay input means stop and jump immediately to new value */
if (inlet2 < 0)
{
- x->x_value = f;
- vline_tilde_stop(x);
- return;
+ x->x_value = f;
+ vline_tilde_stop(x);
+ return;
}
snew = (t_vseg *)t_getbytes(sizeof(*snew));
- /* check if we supplant the first item in the list. We supplant
- an item by having an earlier starttime, or an equal starttime unless
- the equal one was instantaneous and the new one isn't (in which case
- we'll do a jump-and-slide starting at that time.) */
+ /* check if we supplant the first item in the list. We supplant
+ an item by having an earlier starttime, or an equal starttime unless
+ the equal one was instantaneous and the new one isn't (in which case
+ we'll do a jump-and-slide starting at that time.) */
if (!x->x_list || x->x_list->s_starttime > starttime ||
- (x->x_list->s_starttime == starttime &&
- (x->x_list->s_targettime > x->x_list->s_starttime || inlet1 <= 0)))
+ (x->x_list->s_starttime == starttime &&
+ (x->x_list->s_targettime > x->x_list->s_starttime || inlet1 <= 0)))
{
- deletefrom = x->x_list;
- x->x_list = snew;
+ deletefrom = x->x_list;
+ x->x_list = snew;
}
else
{
- for (s1 = x->x_list; s2 = s1->s_next; s1 = s2)
- {
- if (s2->s_starttime > starttime ||
- (s2->s_starttime == starttime &&
- (s2->s_targettime > s2->s_starttime || inlet1 <= 0)))
- {
- deletefrom = s2;
- s1->s_next = snew;
- goto didit;
- }
- }
- s1->s_next = snew;
- deletefrom = 0;
+ for (s1 = x->x_list; s2 = s1->s_next; s1 = s2)
+ {
+ if (s2->s_starttime > starttime ||
+ (s2->s_starttime == starttime &&
+ (s2->s_targettime > s2->s_starttime || inlet1 <= 0)))
+ {
+ deletefrom = s2;
+ s1->s_next = snew;
+ goto didit;
+ }
+ }
+ s1->s_next = snew;
+ deletefrom = 0;
didit: ;
}
while (deletefrom)
{
- s1 = deletefrom->s_next;
- t_freebytes(deletefrom, sizeof(*deletefrom));
- deletefrom = s1;
+ s1 = deletefrom->s_next;
+ t_freebytes(deletefrom, sizeof(*deletefrom));
+ deletefrom = s1;
}
snew->s_next = 0;
snew->s_target = f;
@@ -359,12 +401,12 @@ static void *vline_tilde_new(void)
static void vline_tilde_setup(void)
{
vline_tilde_class = class_new(gensym("vline~"), vline_tilde_new,
- (t_method)vline_tilde_stop, sizeof(t_vline), 0, 0);
+ (t_method)vline_tilde_stop, sizeof(t_vline), 0, 0);
class_addfloat(vline_tilde_class, (t_method)vline_tilde_float);
class_addmethod(vline_tilde_class, (t_method)vline_tilde_dsp,
- gensym("dsp"), 0);
+ gensym("dsp"), 0);
class_addmethod(vline_tilde_class, (t_method)vline_tilde_stop,
- gensym("stop"), 0);
+ gensym("stop"), 0);
}
/* -------------------------- snapshot~ ------------------------------ */
@@ -397,7 +439,7 @@ static t_int *snapshot_tilde_perform(t_int *w)
static void snapshot_tilde_dsp(t_snapshot *x, t_signal **sp)
{
dsp_add(snapshot_tilde_perform, 2, sp[0]->s_vec + (sp[0]->s_n-1),
- &x->x_value);
+ &x->x_value);
}
static void snapshot_tilde_bang(t_snapshot *x)
@@ -413,12 +455,12 @@ static void snapshot_tilde_set(t_snapshot *x, t_floatarg f)
static void snapshot_tilde_setup(void)
{
snapshot_tilde_class = class_new(gensym("snapshot~"), snapshot_tilde_new, 0,
- sizeof(t_snapshot), 0, 0);
+ sizeof(t_snapshot), 0, 0);
CLASS_MAINSIGNALIN(snapshot_tilde_class, t_snapshot, x_f);
class_addmethod(snapshot_tilde_class, (t_method)snapshot_tilde_dsp,
- gensym("dsp"), 0);
+ gensym("dsp"), 0);
class_addmethod(snapshot_tilde_class, (t_method)snapshot_tilde_set,
- gensym("set"), A_DEFFLOAT, 0);
+ gensym("set"), A_DEFFLOAT, 0);
class_addbang(snapshot_tilde_class, snapshot_tilde_bang);
}
@@ -454,7 +496,7 @@ static t_int *vsnapshot_tilde_perform(t_int *w)
t_float *out = x->x_vec;
int n = x->x_n, i;
for (i = 0; i < n; i++)
- out[i] = in[i];
+ out[i] = in[i];
x->x_time = clock_getlogicaltime();
x->x_gotone = 1;
return (w+3);
@@ -465,11 +507,11 @@ static void vsnapshot_tilde_dsp(t_vsnapshot *x, t_signal **sp)
int n = sp[0]->s_n;
if (n != x->x_n)
{
- if (x->x_vec)
- t_freebytes(x->x_vec, x->x_n * sizeof(t_sample));
- x->x_vec = (t_sample *)getbytes(n * sizeof(t_sample));
- x->x_gotone = 0;
- x->x_n = n;
+ if (x->x_vec)
+ t_freebytes(x->x_vec, x->x_n * sizeof(t_sample));
+ x->x_vec = (t_sample *)getbytes(n * sizeof(t_sample));
+ x->x_gotone = 0;
+ x->x_n = n;
}
x->x_sampspermsec = sp[0]->s_sr / 1000;
dsp_add(vsnapshot_tilde_perform, 2, sp[0]->s_vec, x);
@@ -480,12 +522,12 @@ static void vsnapshot_tilde_bang(t_vsnapshot *x)
float val;
if (x->x_gotone)
{
- int indx = clock_gettimesince(x->x_time) * x->x_sampspermsec;
- if (indx < 0)
- indx = 0;
- else if (indx >= x->x_n)
- indx = x->x_n - 1;
- val = x->x_vec[indx];
+ int indx = clock_gettimesince(x->x_time) * x->x_sampspermsec;
+ if (indx < 0)
+ indx = 0;
+ else if (indx >= x->x_n)
+ indx = x->x_n - 1;
+ val = x->x_vec[indx];
}
else val = 0;
outlet_float(x->x_obj.ob_outlet, val);
@@ -494,14 +536,14 @@ static void vsnapshot_tilde_bang(t_vsnapshot *x)
static void vsnapshot_tilde_ff(t_vsnapshot *x)
{
if (x->x_vec)
- t_freebytes(x->x_vec, x->x_n * sizeof(t_sample));
+ t_freebytes(x->x_vec, x->x_n * sizeof(t_sample));
}
static void vsnapshot_tilde_setup(void)
{
vsnapshot_tilde_class = class_new(gensym("vsnapshot~"),
- vsnapshot_tilde_new, (t_method)vsnapshot_tilde_ff,
- sizeof(t_vsnapshot), 0, 0);
+ vsnapshot_tilde_new, (t_method)vsnapshot_tilde_ff,
+ sizeof(t_vsnapshot), 0, 0);
CLASS_MAINSIGNALIN(vsnapshot_tilde_class, t_vsnapshot, x_f);
class_addmethod(vsnapshot_tilde_class, (t_method)vsnapshot_tilde_dsp, gensym("dsp"), 0);
class_addbang(vsnapshot_tilde_class, vsnapshot_tilde_bang);
@@ -515,16 +557,16 @@ static void vsnapshot_tilde_setup(void)
typedef struct sigenv
{
- t_object x_obj; /* header */
- void *x_outlet; /* a "float" outlet */
- void *x_clock; /* a "clock" object */
- float *x_buf; /* a Hanning window */
- int x_phase; /* number of points since last output */
- int x_period; /* requested period of output */
- int x_realperiod; /* period rounded up to vecsize multiple */
- int x_npoints; /* analysis window size in samples */
- float x_result; /* result to output */
- float x_sumbuf[MAXOVERLAP]; /* summing buffer */
+ t_object x_obj; /* header */
+ void *x_outlet; /* a "float" outlet */
+ void *x_clock; /* a "clock" object */
+ float *x_buf; /* a Hanning window */
+ int x_phase; /* number of points since last output */
+ int x_period; /* requested period of output */
+ int x_realperiod; /* period rounded up to vecsize multiple */
+ int x_npoints; /* analysis window size in samples */
+ float x_result; /* result to output */
+ float x_sumbuf[MAXOVERLAP]; /* summing buffer */
float x_f;
} t_sigenv;
@@ -542,11 +584,11 @@ static void *env_tilde_new(t_floatarg fnpoints, t_floatarg fperiod)
if (npoints < 1) npoints = 1024;
if (period < 1) period = npoints/2;
if (period < npoints / MAXOVERLAP + 1)
- period = npoints / MAXOVERLAP + 1;
+ period = npoints / MAXOVERLAP + 1;
if (!(buf = getbytes(sizeof(float) * (npoints + MAXVSTAKEN))))
{
- error("env: couldn't allocate buffer");
- return (0);
+ error("env: couldn't allocate buffer");
+ return (0);
}
x = (t_sigenv *)pd_new(env_tilde_class);
x->x_buf = buf;
@@ -555,7 +597,7 @@ static void *env_tilde_new(t_floatarg fnpoints, t_floatarg fperiod)
x->x_period = period;
for (i = 0; i < MAXOVERLAP; i++) x->x_sumbuf[i] = 0;
for (i = 0; i < npoints; i++)
- buf[i] = (1. - cos((2 * 3.14159 * i) / npoints))/npoints;
+ buf[i] = (1. - cos((2 * 3.14159 * i) / npoints))/npoints;
for (; i < npoints+MAXVSTAKEN; i++) buf[i] = 0;
x->x_clock = clock_new(x, (t_method)env_tilde_tick);
x->x_outlet = outlet_new(&x->x_obj, gensym("float"));
@@ -572,31 +614,31 @@ static t_int *env_tilde_perform(t_int *w)
float *sump;
in += n;
for (count = x->x_phase, sump = x->x_sumbuf;
- count < x->x_npoints; count += x->x_realperiod, sump++)
+ count < x->x_npoints; count += x->x_realperiod, sump++)
{
- float *hp = x->x_buf + count;
- float *fp = in;
- float sum = *sump;
- int i;
-
- for (i = 0; i < n; i++)
- {
- fp--;
- sum += *hp++ * (*fp * *fp);
- }
- *sump = sum;
+ float *hp = x->x_buf + count;
+ float *fp = in;
+ float sum = *sump;
+ int i;
+
+ for (i = 0; i < n; i++)
+ {
+ fp--;
+ sum += *hp++ * (*fp * *fp);
+ }
+ *sump = sum;
}
sump[0] = 0;
x->x_phase -= n;
if (x->x_phase < 0)
{
- x->x_result = x->x_sumbuf[0];
- for (count = x->x_realperiod, sump = x->x_sumbuf;
- count < x->x_npoints; count += x->x_realperiod, sump++)
- sump[0] = sump[1];
- sump[0] = 0;
- x->x_phase = x->x_realperiod - n;
- clock_delay(x->x_clock, 0L);
+ x->x_result = x->x_sumbuf[0];
+ for (count = x->x_realperiod, sump = x->x_sumbuf;
+ count < x->x_npoints; count += x->x_realperiod, sump++)
+ sump[0] = sump[1];
+ sump[0] = 0;
+ x->x_phase = x->x_realperiod - n;
+ clock_delay(x->x_clock, 0L);
}
return (w+4);
}
@@ -604,18 +646,18 @@ static t_int *env_tilde_perform(t_int *w)
static void env_tilde_dsp(t_sigenv *x, t_signal **sp)
{
if (x->x_period % sp[0]->s_n) x->x_realperiod =
- x->x_period + sp[0]->s_n - (x->x_period % sp[0]->s_n);
+ x->x_period + sp[0]->s_n - (x->x_period % sp[0]->s_n);
else x->x_realperiod = x->x_period;
dsp_add(env_tilde_perform, 3, x, sp[0]->s_vec, sp[0]->s_n);
if (sp[0]->s_n > MAXVSTAKEN) bug("env_tilde_dsp");
}
-static void env_tilde_tick(t_sigenv *x) /* callback function for the clock */
+static void env_tilde_tick(t_sigenv *x) /* callback function for the clock */
{
outlet_float(x->x_outlet, powtodb(x->x_result));
}
-static void env_tilde_ff(t_sigenv *x) /* cleanup on free */
+static void env_tilde_ff(t_sigenv *x) /* cleanup on free */
{
clock_free(x->x_clock);
freebytes(x->x_buf, (x->x_npoints + MAXVSTAKEN) * sizeof(float));
@@ -625,7 +667,7 @@ static void env_tilde_ff(t_sigenv *x) /* cleanup on free */
void env_tilde_setup(void )
{
env_tilde_class = class_new(gensym("env~"), (t_newmethod)env_tilde_new,
- (t_method)env_tilde_ff, sizeof(t_sigenv), 0, A_DEFFLOAT, A_DEFFLOAT, 0);
+ (t_method)env_tilde_ff, sizeof(t_sigenv), 0, A_DEFFLOAT, A_DEFFLOAT, 0);
CLASS_MAINSIGNALIN(env_tilde_class, t_sigenv, x_f);
class_addmethod(env_tilde_class, (t_method)env_tilde_dsp, gensym("dsp"), 0);
}
@@ -637,17 +679,17 @@ static t_class *threshold_tilde_class;
typedef struct _threshold_tilde
{
t_object x_obj;
- t_outlet *x_outlet1; /* bang out for high thresh */
- t_outlet *x_outlet2; /* bang out for low thresh */
- t_clock *x_clock; /* wakeup for message output */
- float x_f; /* scalar inlet */
- int x_state; /* 1 = high, 0 = low */
- float x_hithresh; /* value of high threshold */
- float x_lothresh; /* value of low threshold */
- float x_deadwait; /* msec remaining in dead period */
- float x_msecpertick; /* msec per DSP tick */
- float x_hideadtime; /* hi dead time in msec */
- float x_lodeadtime; /* lo dead time in msec */
+ t_outlet *x_outlet1; /* bang out for high thresh */
+ t_outlet *x_outlet2; /* bang out for low thresh */
+ t_clock *x_clock; /* wakeup for message output */
+ float x_f; /* scalar inlet */
+ int x_state; /* 1 = high, 0 = low */
+ float x_hithresh; /* value of high threshold */
+ float x_lothresh; /* value of low threshold */
+ float x_deadwait; /* msec remaining in dead period */
+ float x_msecpertick; /* msec per DSP tick */
+ float x_hideadtime; /* hi dead time in msec */
+ float x_lodeadtime; /* lo dead time in msec */
} t_threshold_tilde;
static void threshold_tilde_tick(t_threshold_tilde *x);
@@ -659,9 +701,9 @@ static t_threshold_tilde *threshold_tilde_new(t_floatarg hithresh,
t_floatarg hideadtime, t_floatarg lothresh, t_floatarg lodeadtime)
{
t_threshold_tilde *x = (t_threshold_tilde *)
- pd_new(threshold_tilde_class);
- x->x_state = 0; /* low state */
- x->x_deadwait = 0; /* no dead time */
+ pd_new(threshold_tilde_class);
+ x->x_state = 0; /* low state */
+ x->x_deadwait = 0; /* no dead time */
x->x_clock = clock_new(x, (t_method)threshold_tilde_tick);
x->x_outlet1 = outlet_new(&x->x_obj, &s_bang);
x->x_outlet2 = outlet_new(&x->x_obj, &s_bang);
@@ -678,7 +720,7 @@ static void threshold_tilde_set(t_threshold_tilde *x,
t_floatarg lothresh, t_floatarg lodeadtime)
{
if (lothresh > hithresh)
- lothresh = hithresh;
+ lothresh = hithresh;
x->x_hithresh = hithresh;
x->x_hideadtime = hideadtime;
x->x_lothresh = lothresh;
@@ -693,10 +735,10 @@ static void threshold_tilde_ft1(t_threshold_tilde *x, t_floatarg f)
x->x_deadwait = 0;
}
-static void threshold_tilde_tick(t_threshold_tilde *x)
+static void threshold_tilde_tick(t_threshold_tilde *x)
{
if (x->x_state)
- outlet_bang(x->x_outlet1);
+ outlet_bang(x->x_outlet1);
else outlet_bang(x->x_outlet2);
}
@@ -706,34 +748,34 @@ static t_int *threshold_tilde_perform(t_int *w)
t_threshold_tilde *x = (t_threshold_tilde *)(w[2]);
int n = (t_int)(w[3]);
if (x->x_deadwait > 0)
- x->x_deadwait -= x->x_msecpertick;
+ x->x_deadwait -= x->x_msecpertick;
else if (x->x_state)
{
- /* we're high; look for low sample */
- for (; n--; in1++)
- {
- if (*in1 < x->x_lothresh)
- {
- clock_delay(x->x_clock, 0L);
- x->x_state = 0;
- x->x_deadwait = x->x_lodeadtime;
- goto done;
- }
- }
+ /* we're high; look for low sample */
+ for (; n--; in1++)
+ {
+ if (*in1 < x->x_lothresh)
+ {
+ clock_delay(x->x_clock, 0L);
+ x->x_state = 0;
+ x->x_deadwait = x->x_lodeadtime;
+ goto done;
+ }
+ }
}
else
{
- /* we're low; look for high sample */
- for (; n--; in1++)
- {
- if (*in1 >= x->x_hithresh)
- {
- clock_delay(x->x_clock, 0L);
- x->x_state = 1;
- x->x_deadwait = x->x_hideadtime;
- goto done;
- }
- }
+ /* we're low; look for high sample */
+ for (; n--; in1++)
+ {
+ if (*in1 >= x->x_hithresh)
+ {
+ clock_delay(x->x_clock, 0L);
+ x->x_state = 1;
+ x->x_deadwait = x->x_hideadtime;
+ goto done;
+ }
+ }
}
done:
return (w+4);
@@ -753,16 +795,16 @@ static void threshold_tilde_ff(t_threshold_tilde *x)
static void threshold_tilde_setup( void)
{
threshold_tilde_class = class_new(gensym("threshold~"),
- (t_newmethod)threshold_tilde_new, (t_method)threshold_tilde_ff,
- sizeof(t_threshold_tilde), 0,
- A_DEFFLOAT, A_DEFFLOAT, A_DEFFLOAT, A_DEFFLOAT, 0);
+ (t_newmethod)threshold_tilde_new, (t_method)threshold_tilde_ff,
+ sizeof(t_threshold_tilde), 0,
+ A_DEFFLOAT, A_DEFFLOAT, A_DEFFLOAT, A_DEFFLOAT, 0);
CLASS_MAINSIGNALIN(threshold_tilde_class, t_threshold_tilde, x_f);
class_addmethod(threshold_tilde_class, (t_method)threshold_tilde_set,
- gensym("set"), A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, 0);
+ gensym("set"), A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, 0);
class_addmethod(threshold_tilde_class, (t_method)threshold_tilde_ft1,
- gensym("ft1"), A_FLOAT, 0);
+ gensym("ft1"), A_FLOAT, 0);
class_addmethod(threshold_tilde_class, (t_method)threshold_tilde_dsp,
- gensym("dsp"), 0);
+ gensym("dsp"), 0);
}
/* ------------------------ global setup routine ------------------------- */
diff --git a/pd/src/d_dac.c b/pd/src/d_dac.c
index 1606b3a1..77643844 100644
--- a/pd/src/d_dac.c
+++ b/pd/src/d_dac.c
@@ -26,17 +26,17 @@ static void *dac_new(t_symbol *s, int argc, t_atom *argv)
int i;
if (!argc)
{
- argv = defarg;
- argc = 2;
- SETFLOAT(&defarg[0], 1);
- SETFLOAT(&defarg[1], 2);
+ argv = defarg;
+ argc = 2;
+ SETFLOAT(&defarg[0], 1);
+ SETFLOAT(&defarg[1], 2);
}
x->x_n = argc;
x->x_vec = (t_int *)getbytes(argc * sizeof(*x->x_vec));
for (i = 0; i < argc; i++)
- x->x_vec[i] = atom_getintarg(i, argc, argv);
+ x->x_vec[i] = atom_getintarg(i, argc, argv);
for (i = 1; i < argc; i++)
- inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_signal, &s_signal);
+ inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_signal, &s_signal);
x->x_f = 0;
return (x);
}
@@ -47,12 +47,12 @@ static void dac_dsp(t_dac *x, t_signal **sp)
t_signal **sp2;
for (i = x->x_n, ip = x->x_vec, sp2 = sp; i--; ip++, sp2++)
{
- int ch = *ip - 1;
- if ((*sp2)->s_n != DEFDACBLKSIZE)
- error("dac~: bad vector size");
- else if (ch >= 0 && ch < sys_get_outchannels())
- dsp_add(plus_perform, 4, sys_soundout + DEFDACBLKSIZE*ch,
- (*sp2)->s_vec, sys_soundout + DEFDACBLKSIZE*ch, DEFDACBLKSIZE);
+ int ch = *ip - 1;
+ if ((*sp2)->s_n != DEFDACBLKSIZE)
+ error("dac~: bad vector size");
+ else if (ch >= 0 && ch < sys_get_outchannels())
+ dsp_add(plus_perform, 4, sys_soundout + DEFDACBLKSIZE*ch,
+ (*sp2)->s_vec, sys_soundout + DEFDACBLKSIZE*ch, DEFDACBLKSIZE);
}
}
@@ -64,7 +64,7 @@ static void dac_free(t_dac *x)
static void dac_setup(void)
{
dac_class = class_new(gensym("dac~"), (t_newmethod)dac_new,
- (t_method)dac_free, sizeof(t_dac), 0, A_GIMME, 0);
+ (t_method)dac_free, sizeof(t_dac), 0, A_GIMME, 0);
CLASS_MAINSIGNALIN(dac_class, t_dac, x_f);
class_addmethod(dac_class, (t_method)dac_dsp, gensym("dsp"), A_CANT, 0);
class_sethelpsymbol(dac_class, gensym("adc~_dac~"));
@@ -87,17 +87,17 @@ static void *adc_new(t_symbol *s, int argc, t_atom *argv)
int i;
if (!argc)
{
- argv = defarg;
- argc = 2;
- SETFLOAT(&defarg[0], 1);
- SETFLOAT(&defarg[1], 2);
+ argv = defarg;
+ argc = 2;
+ SETFLOAT(&defarg[0], 1);
+ SETFLOAT(&defarg[1], 2);
}
x->x_n = argc;
x->x_vec = (t_int *)getbytes(argc * sizeof(*x->x_vec));
for (i = 0; i < argc; i++)
- x->x_vec[i] = atom_getintarg(i, argc, argv);
+ x->x_vec[i] = atom_getintarg(i, argc, argv);
for (i = 0; i < argc; i++)
- outlet_new(&x->x_obj, &s_signal);
+ outlet_new(&x->x_obj, &s_signal);
return (x);
}
@@ -118,23 +118,23 @@ t_int *copy_perf8(t_int *w)
for (; n; n -= 8, in1 += 8, out += 8)
{
- float f0 = in1[0];
- float f1 = in1[1];
- float f2 = in1[2];
- float f3 = in1[3];
- float f4 = in1[4];
- float f5 = in1[5];
- float f6 = in1[6];
- float f7 = in1[7];
-
- out[0] = f0;
- out[1] = f1;
- out[2] = f2;
- out[3] = f3;
- out[4] = f4;
- out[5] = f5;
- out[6] = f6;
- out[7] = f7;
+ float f0 = in1[0];
+ float f1 = in1[1];
+ float f2 = in1[2];
+ float f3 = in1[3];
+ float f4 = in1[4];
+ float f5 = in1[5];
+ float f6 = in1[6];
+ float f7 = in1[7];
+
+ out[0] = f0;
+ out[1] = f1;
+ out[2] = f2;
+ out[3] = f3;
+ out[4] = f4;
+ out[5] = f5;
+ out[6] = f6;
+ out[7] = f7;
}
return (w+4);
}
@@ -142,9 +142,9 @@ t_int *copy_perf8(t_int *w)
void dsp_add_copy(t_sample *in, t_sample *out, int n)
{
if (n&7)
- dsp_add(copy_perform, 3, in, out, n);
- else
- dsp_add(copy_perf8, 3, in, out, n);
+ dsp_add(copy_perform, 3, in, out, n);
+ else
+ dsp_add(copy_perf8, 3, in, out, n);
}
static void adc_dsp(t_adc *x, t_signal **sp)
@@ -153,13 +153,13 @@ static void adc_dsp(t_adc *x, t_signal **sp)
t_signal **sp2;
for (i = x->x_n, ip = x->x_vec, sp2 = sp; i--; ip++, sp2++)
{
- int ch = *ip - 1;
- if ((*sp2)->s_n != DEFDACBLKSIZE)
- error("adc~: bad vector size");
- else if (ch >= 0 && ch < sys_get_inchannels())
- dsp_add_copy(sys_soundin + DEFDACBLKSIZE*ch,
- (*sp2)->s_vec, DEFDACBLKSIZE);
- else dsp_add_zero((*sp2)->s_vec, DEFDACBLKSIZE);
+ int ch = *ip - 1;
+ if ((*sp2)->s_n != DEFDACBLKSIZE)
+ error("adc~: bad vector size");
+ else if (ch >= 0 && ch < sys_get_inchannels())
+ dsp_add_copy(sys_soundin + DEFDACBLKSIZE*ch,
+ (*sp2)->s_vec, DEFDACBLKSIZE);
+ else dsp_add_zero((*sp2)->s_vec, DEFDACBLKSIZE);
}
}
@@ -171,7 +171,7 @@ static void adc_free(t_adc *x)
static void adc_setup(void)
{
adc_class = class_new(gensym("adc~"), (t_newmethod)adc_new,
- (t_method)adc_free, sizeof(t_adc), 0, A_GIMME, 0);
+ (t_method)adc_free, sizeof(t_adc), 0, A_GIMME, 0);
class_addmethod(adc_class, (t_method)adc_dsp, gensym("dsp"), A_CANT, 0);
class_sethelpsymbol(adc_class, gensym("adc~_dac~"));
}
diff --git a/pd/src/d_delay.c b/pd/src/d_delay.c
index 920b28e5..f808e292 100644
--- a/pd/src/d_delay.c
+++ b/pd/src/d_delay.c
@@ -7,8 +7,8 @@
#include "m_pd.h"
extern int ugen_getsortno(void);
-#define DEFDELVS 64 /* LATER get this from canvas at DSP time */
-static int delread_zero = 0; /* four bytes of zero for delread~, vd~ */
+#define DEFDELVS 64 /* LATER get this from canvas at DSP time */
+static int delread_zero = 0; /* four bytes of zero for delread~, vd~ */
/* ----------------------------- delwrite~ ----------------------------- */
static t_class *sigdelwrite_class;
@@ -37,13 +37,19 @@ typedef struct _sigdelwrite
/* routine to check that all delwrites/delreads/vds have same vecsize */
static void sigdelwrite_checkvecsize(t_sigdelwrite *x, int vecsize)
{
+ /*
+ LATER this should really check sample rate and blocking, once that is
+ supported. Probably we don't actually care about vecsize.
+ For now just suppress this check... */
+#if 0
if (x->x_rsortno != ugen_getsortno())
{
- x->x_vecsize = vecsize;
- x->x_rsortno = ugen_getsortno();
+ x->x_vecsize = vecsize;
+ x->x_rsortno = ugen_getsortno();
}
else if (vecsize != x->x_vecsize)
- pd_error(x, "delread/delwrite/vd vector size mismatch");
+ pd_error(x, "delread/delwrite/vd vector size mismatch");
+#endif
}
static void *sigdelwrite_new(t_symbol *s, t_floatarg msec)
@@ -59,7 +65,7 @@ static void *sigdelwrite_new(t_symbol *s, t_floatarg msec)
nsamps += DEFDELVS;
x->x_cspace.c_n = nsamps;
x->x_cspace.c_vec =
- (float *)getbytes((nsamps + XTRASAMPS) * sizeof(float));
+ (float *)getbytes((nsamps + XTRASAMPS) * sizeof(float));
x->x_cspace.c_phase = XTRASAMPS;
x->x_sortno = 0;
x->x_vecsize = 0;
@@ -77,19 +83,19 @@ static t_int *sigdelwrite_perform(t_int *w)
phase += n;
while (n--)
{
- float f = *in++;
- if (PD_BADFLOAT(f))
- f = 0;
- *bp++ = f;
- if (bp == ep)
- {
- vp[0] = ep[-4];
- vp[1] = ep[-3];
- vp[2] = ep[-2];
- vp[3] = ep[-1];
- bp = vp + XTRASAMPS;
- phase -= nsamps;
- }
+ float f = *in++;
+ if (PD_BIGORSMALL(f))
+ f = 0;
+ *bp++ = f;
+ if (bp == ep)
+ {
+ vp[0] = ep[-4];
+ vp[1] = ep[-3];
+ vp[2] = ep[-2];
+ vp[3] = ep[-1];
+ bp = vp + XTRASAMPS;
+ phase -= nsamps;
+ }
}
c->c_phase = phase;
return (w+4);
@@ -106,17 +112,17 @@ static void sigdelwrite_free(t_sigdelwrite *x)
{
pd_unbind(&x->x_obj.ob_pd, x->x_sym);
freebytes(x->x_cspace.c_vec,
- (x->x_cspace.c_n + XTRASAMPS) * sizeof(float));
+ (x->x_cspace.c_n + XTRASAMPS) * sizeof(float));
}
static void sigdelwrite_setup(void)
{
sigdelwrite_class = class_new(gensym("delwrite~"),
- (t_newmethod)sigdelwrite_new, (t_method)sigdelwrite_free,
- sizeof(t_sigdelwrite), 0, A_DEFSYM, A_DEFFLOAT, 0);
+ (t_newmethod)sigdelwrite_new, (t_method)sigdelwrite_free,
+ sizeof(t_sigdelwrite), 0, A_DEFSYM, A_DEFFLOAT, 0);
CLASS_MAINSIGNALIN(sigdelwrite_class, t_sigdelwrite, x_f);
class_addmethod(sigdelwrite_class, (t_method)sigdelwrite_dsp,
- gensym("dsp"), 0);
+ gensym("dsp"), 0);
}
/* ----------------------------- delread~ ----------------------------- */
@@ -126,11 +132,11 @@ typedef struct _sigdelread
{
t_object x_obj;
t_symbol *x_sym;
- t_float x_deltime; /* delay in msec */
- int x_delsamps; /* delay in samples */
- t_float x_sr; /* samples per msec */
- t_float x_n; /* vector size */
- int x_zerodel; /* 0 or vecsize depending on read/write order */
+ t_float x_deltime; /* delay in msec */
+ int x_delsamps; /* delay in samples */
+ t_float x_sr; /* samples per msec */
+ t_float x_n; /* vector size */
+ int x_zerodel; /* 0 or vecsize depending on read/write order */
} t_sigdelread;
static void sigdelread_float(t_sigdelread *x, t_float f);
@@ -151,16 +157,16 @@ static void sigdelread_float(t_sigdelread *x, t_float f)
{
int samps;
t_sigdelwrite *delwriter =
- (t_sigdelwrite *)pd_findbyclass(x->x_sym, sigdelwrite_class);
+ (t_sigdelwrite *)pd_findbyclass(x->x_sym, sigdelwrite_class);
x->x_deltime = f;
if (delwriter)
{
- int delsize = delwriter->x_cspace.c_n;
- x->x_delsamps = (int)(0.5 + x->x_sr * x->x_deltime)
- + x->x_n - x->x_zerodel;
- if (x->x_delsamps < x->x_n) x->x_delsamps = x->x_n;
- else if (x->x_delsamps > delwriter->x_cspace.c_n - DEFDELVS)
- x->x_delsamps = delwriter->x_cspace.c_n - DEFDELVS;
+ int delsize = delwriter->x_cspace.c_n;
+ x->x_delsamps = (int)(0.5 + x->x_sr * x->x_deltime)
+ + x->x_n - x->x_zerodel;
+ if (x->x_delsamps < x->x_n) x->x_delsamps = x->x_n;
+ else if (x->x_delsamps > delwriter->x_cspace.c_n - DEFDELVS)
+ x->x_delsamps = delwriter->x_cspace.c_n - DEFDELVS;
}
}
@@ -177,8 +183,8 @@ static t_int *sigdelread_perform(t_int *w)
bp = vp + phase;
while (n--)
{
- *out++ = *bp++;
- if (bp == ep) bp -= nsamps;
+ *out++ = *bp++;
+ if (bp == ep) bp -= nsamps;
}
return (w+5);
}
@@ -186,29 +192,29 @@ static t_int *sigdelread_perform(t_int *w)
static void sigdelread_dsp(t_sigdelread *x, t_signal **sp)
{
t_sigdelwrite *delwriter =
- (t_sigdelwrite *)pd_findbyclass(x->x_sym, sigdelwrite_class);
+ (t_sigdelwrite *)pd_findbyclass(x->x_sym, sigdelwrite_class);
x->x_sr = sp[0]->s_sr * 0.001;
x->x_n = sp[0]->s_n;
if (delwriter)
{
- sigdelwrite_checkvecsize(delwriter, sp[0]->s_n);
- x->x_zerodel = (delwriter->x_sortno == ugen_getsortno() ?
- 0 : delwriter->x_vecsize);
- sigdelread_float(x, x->x_deltime);
- dsp_add(sigdelread_perform, 4,
- sp[0]->s_vec, &delwriter->x_cspace, &x->x_delsamps, sp[0]->s_n);
+ sigdelwrite_checkvecsize(delwriter, sp[0]->s_n);
+ x->x_zerodel = (delwriter->x_sortno == ugen_getsortno() ?
+ 0 : delwriter->x_vecsize);
+ sigdelread_float(x, x->x_deltime);
+ dsp_add(sigdelread_perform, 4,
+ sp[0]->s_vec, &delwriter->x_cspace, &x->x_delsamps, sp[0]->s_n);
}
else if (*x->x_sym->s_name)
- error("delread~: %s: no such delwrite~",x->x_sym->s_name);
+ error("delread~: %s: no such delwrite~",x->x_sym->s_name);
}
static void sigdelread_setup(void)
{
sigdelread_class = class_new(gensym("delread~"),
- (t_newmethod)sigdelread_new, 0,
- sizeof(t_sigdelread), 0, A_DEFSYM, A_DEFFLOAT, 0);
+ (t_newmethod)sigdelread_new, 0,
+ sizeof(t_sigdelread), 0, A_DEFSYM, A_DEFFLOAT, 0);
class_addmethod(sigdelread_class, (t_method)sigdelread_dsp,
- gensym("dsp"), 0);
+ gensym("dsp"), 0);
class_addfloat(sigdelread_class, (t_method)sigdelread_float);
}
@@ -220,8 +226,8 @@ typedef struct _sigvd
{
t_object x_obj;
t_symbol *x_sym;
- t_float x_sr; /* samples per msec */
- int x_zerodel; /* 0 or vecsize depending on read/write order */
+ t_float x_sr; /* samples per msec */
+ int x_zerodel; /* 0 or vecsize depending on read/write order */
float x_f;
} t_sigvd;
@@ -252,27 +258,27 @@ static t_int *sigvd_perform(t_int *w)
float zerodel = x->x_zerodel;
while (n--)
{
- float delsamps = x->x_sr * *in++ - zerodel, frac;
- int idelsamps;
- float a, b, c, d, cminusb;
- if (delsamps < 1.00001f) delsamps = 1.00001f;
- if (delsamps > limit) delsamps = limit;
- delsamps += fn;
- fn = fn - 1.0f;
- idelsamps = delsamps;
- frac = delsamps - (float)idelsamps;
- bp = wp - idelsamps;
- if (bp < vp + 4) bp += nsamps;
- d = bp[-3];
- c = bp[-2];
- b = bp[-1];
- a = bp[0];
- cminusb = c-b;
- *out++ = b + frac * (
- cminusb - 0.1666667f * (1.-frac) * (
- (d - a - 3.0f * cminusb) * frac + (d + 2.0f*a - 3.0f*b)
- )
- );
+ float delsamps = x->x_sr * *in++ - zerodel, frac;
+ int idelsamps;
+ float a, b, c, d, cminusb;
+ if (delsamps < 1.00001f) delsamps = 1.00001f;
+ if (delsamps > limit) delsamps = limit;
+ delsamps += fn;
+ fn = fn - 1.0f;
+ idelsamps = delsamps;
+ frac = delsamps - (float)idelsamps;
+ bp = wp - idelsamps;
+ if (bp < vp + 4) bp += nsamps;
+ d = bp[-3];
+ c = bp[-2];
+ b = bp[-1];
+ a = bp[0];
+ cminusb = c-b;
+ *out++ = b + frac * (
+ cminusb - 0.1666667f * (1.-frac) * (
+ (d - a - 3.0f * cminusb) * frac + (d + 2.0f*a - 3.0f*b)
+ )
+ );
}
return (w+6);
}
@@ -280,16 +286,16 @@ static t_int *sigvd_perform(t_int *w)
static void sigvd_dsp(t_sigvd *x, t_signal **sp)
{
t_sigdelwrite *delwriter =
- (t_sigdelwrite *)pd_findbyclass(x->x_sym, sigdelwrite_class);
+ (t_sigdelwrite *)pd_findbyclass(x->x_sym, sigdelwrite_class);
x->x_sr = sp[0]->s_sr * 0.001;
if (delwriter)
{
- sigdelwrite_checkvecsize(delwriter, sp[0]->s_n);
- x->x_zerodel = (delwriter->x_sortno == ugen_getsortno() ?
- 0 : delwriter->x_vecsize);
- dsp_add(sigvd_perform, 5,
- sp[0]->s_vec, sp[1]->s_vec,
- &delwriter->x_cspace, x, sp[0]->s_n);
+ sigdelwrite_checkvecsize(delwriter, sp[0]->s_n);
+ x->x_zerodel = (delwriter->x_sortno == ugen_getsortno() ?
+ 0 : delwriter->x_vecsize);
+ dsp_add(sigvd_perform, 5,
+ sp[0]->s_vec, sp[1]->s_vec,
+ &delwriter->x_cspace, x, sp[0]->s_n);
}
else error("vd~: %s: no such delwrite~",x->x_sym->s_name);
}
@@ -297,7 +303,7 @@ static void sigvd_dsp(t_sigvd *x, t_signal **sp)
static void sigvd_setup(void)
{
sigvd_class = class_new(gensym("vd~"), (t_newmethod)sigvd_new, 0,
- sizeof(t_sigvd), 0, A_DEFSYM, 0);
+ sizeof(t_sigvd), 0, A_DEFSYM, 0);
class_addmethod(sigvd_class, (t_method)sigvd_dsp, gensym("dsp"), 0);
CLASS_MAINSIGNALIN(sigvd_class, t_sigvd, x_f);
}
diff --git a/pd/src/d_fft.c b/pd/src/d_fft.c
index 7e5a95a3..6a5a1372 100644
--- a/pd/src/d_fft.c
+++ b/pd/src/d_fft.c
@@ -39,10 +39,10 @@ static t_int *sigfft_swap(t_int *w)
float *in2 = (t_float *)(w[2]);
int n = w[3];
for (;n--; in1++, in2++)
- {
- float f = *in1;
- *in1 = *in2;
- *in2 = f;
+ {
+ float f = *in1;
+ *in1 = *in2;
+ *in2 = f;
}
return (w+4);
}
@@ -73,16 +73,16 @@ static void sigfft_dspx(t_sigfft *x, t_signal **sp, t_int *(*f)(t_int *w))
float *out1 = sp[2]->s_vec;
float *out2 = sp[3]->s_vec;
if (out1 == in2 && out2 == in1)
- dsp_add(sigfft_swap, 3, out1, out2, n);
+ dsp_add(sigfft_swap, 3, out1, out2, n);
else if (out1 == in2)
{
- dsp_add(copy_perform, 3, in2, out2, n);
- dsp_add(copy_perform, 3, in1, out1, n);
+ dsp_add(copy_perform, 3, in2, out2, n);
+ dsp_add(copy_perform, 3, in1, out1, n);
}
else
{
- if (out1 != in1) dsp_add(copy_perform, 3, in1, out1, n);
- if (out2 != in2) dsp_add(copy_perform, 3, in2, out2, n);
+ if (out1 != in1) dsp_add(copy_perform, 3, in1, out1, n);
+ if (out2 != in2) dsp_add(copy_perform, 3, in2, out2, n);
}
dsp_add(f, 3, sp[2]->s_vec, sp[3]->s_vec, n);
}
@@ -100,12 +100,12 @@ static void sigifft_dsp(t_sigfft *x, t_signal **sp)
static void sigfft_setup(void)
{
sigfft_class = class_new(gensym("fft~"), sigfft_new, 0,
- sizeof(t_sigfft), 0, 0);
+ sizeof(t_sigfft), 0, 0);
CLASS_MAINSIGNALIN(sigfft_class, t_sigfft, x_f);
class_addmethod(sigfft_class, (t_method)sigfft_dsp, gensym("dsp"), 0);
sigifft_class = class_new(gensym("ifft~"), sigifft_new, 0,
- sizeof(t_sigfft), 0, 0);
+ sizeof(t_sigfft), 0, 0);
CLASS_MAINSIGNALIN(sigifft_class, t_sigfft, x_f);
class_addmethod(sigifft_class, (t_method)sigifft_dsp, gensym("dsp"), 0);
class_sethelpsymbol(sigifft_class, gensym("fft~"));
@@ -136,7 +136,7 @@ static t_int *sigrfft_flip(t_int *w)
float *out = (t_float *)(w[2]);
int n = w[3];
while (n--) *(--out) = *in++;
- *(--out) = 0; /* to hell with it */
+ *(--out) = 0; /* to hell with it */
return (w+4);
}
@@ -156,20 +156,20 @@ static void sigrfft_dsp(t_sigrfft *x, t_signal **sp)
float *out2 = sp[2]->s_vec;
if (n < 4)
{
- error("fft: minimum 4 points");
- return;
+ error("fft: minimum 4 points");
+ return;
}
- if (in1 == out2) /* this probably never happens */
+ if (in1 == out2) /* this probably never happens */
{
- dsp_add(sigrfft_perform, 2, out2, n);
- dsp_add(copy_perform, 3, out2, out1, n2);
- dsp_add(sigrfft_flip, 3, out2 + (n2+1), out2 + n2, n2-1);
+ dsp_add(sigrfft_perform, 2, out2, n);
+ dsp_add(copy_perform, 3, out2, out1, n2);
+ dsp_add(sigrfft_flip, 3, out2 + (n2+1), out2 + n2, n2-1);
}
else
{
- if (in1 != out1) dsp_add(copy_perform, 3, in1, out1, n);
- dsp_add(sigrfft_perform, 2, out1, n);
- dsp_add(sigrfft_flip, 3, out1 + (n2+1), out2 + n2, n2-1);
+ if (in1 != out1) dsp_add(copy_perform, 3, in1, out1, n);
+ dsp_add(sigrfft_perform, 2, out1, n);
+ dsp_add(sigrfft_flip, 3, out1 + (n2+1), out2 + n2, n2-1);
}
dsp_add_zero(out1 + n2, n2);
dsp_add_zero(out2 + n2, n2);
@@ -178,7 +178,7 @@ static void sigrfft_dsp(t_sigrfft *x, t_signal **sp)
static void sigrfft_setup(void)
{
sigrfft_class = class_new(gensym("rfft~"), sigrfft_new, 0,
- sizeof(t_sigrfft), 0, 0);
+ sizeof(t_sigrfft), 0, 0);
CLASS_MAINSIGNALIN(sigrfft_class, t_sigrfft, x_f);
class_addmethod(sigrfft_class, (t_method)sigrfft_dsp, gensym("dsp"), 0);
class_sethelpsymbol(sigrfft_class, gensym("fft~"));
@@ -219,18 +219,18 @@ static void sigrifft_dsp(t_sigrifft *x, t_signal **sp)
float *out1 = sp[2]->s_vec;
if (n < 4)
{
- error("fft: minimum 4 points");
- return;
+ error("fft: minimum 4 points");
+ return;
}
if (in2 == out1)
{
- dsp_add(sigrfft_flip, 3, out1+1, out1 + n, (n2-1));
- dsp_add(copy_perform, 3, in1, out1, n2);
+ dsp_add(sigrfft_flip, 3, out1+1, out1 + n, (n2-1));
+ dsp_add(copy_perform, 3, in1, out1, n2);
}
else
{
- if (in1 != out1) dsp_add(copy_perform, 3, in1, out1, n2);
- dsp_add(sigrfft_flip, 3, in2+1, out1 + n, n2-1);
+ if (in1 != out1) dsp_add(copy_perform, 3, in1, out1, n2);
+ dsp_add(sigrfft_flip, 3, in2+1, out1 + n, n2-1);
}
dsp_add(sigrifft_perform, 2, out1, n);
}
@@ -238,7 +238,7 @@ static void sigrifft_dsp(t_sigrifft *x, t_signal **sp)
static void sigrifft_setup(void)
{
sigrifft_class = class_new(gensym("rifft~"), sigrifft_new, 0,
- sizeof(t_sigrifft), 0, 0);
+ sizeof(t_sigrifft), 0, 0);
CLASS_MAINSIGNALIN(sigrifft_class, t_sigrifft, x_f);
class_addmethod(sigrifft_class, (t_method)sigrifft_dsp, gensym("dsp"), 0);
class_sethelpsymbol(sigrifft_class, gensym("fft~"));
@@ -282,27 +282,27 @@ static t_int *sigframp_perform(t_int *w)
n -= 2;
while (n--)
{
- float re, im, pow, freq;
- lastreal = currentreal;
- currentreal = nextreal;
- nextreal = *inreal++;
- lastimag = currentimag;
- currentimag = nextimag;
- nextimag = *inimag++;
- re = currentreal - 0.5f * (lastreal + nextreal);
- im = currentimag - 0.5f * (lastimag + nextimag);
- pow = re * re + im * im;
- if (pow > 1e-19)
- {
- float detune = ((lastreal - nextreal) * re +
- (lastimag - nextimag) * im) / (2.0f * pow);
- if (detune > 2 || detune < -2) freq = pow = 0;
- else freq = fbin + detune;
- }
- else freq = pow = 0;
- *outfreq++ = freq;
- *outamp++ = oneovern2 * pow;
- fbin += 1.0f;
+ float re, im, pow, freq;
+ lastreal = currentreal;
+ currentreal = nextreal;
+ nextreal = *inreal++;
+ lastimag = currentimag;
+ currentimag = nextimag;
+ nextimag = *inimag++;
+ re = currentreal - 0.5f * (lastreal + nextreal);
+ im = currentimag - 0.5f * (lastimag + nextimag);
+ pow = re * re + im * im;
+ if (pow > 1e-19)
+ {
+ float detune = ((lastreal - nextreal) * re +
+ (lastimag - nextimag) * im) / (2.0f * pow);
+ if (detune > 2 || detune < -2) freq = pow = 0;
+ else freq = fbin + detune;
+ }
+ else freq = pow = 0;
+ *outfreq++ = freq;
+ *outamp++ = oneovern2 * pow;
+ fbin += 1.0f;
}
while (m--) *outamp++ = *outfreq++ = 0;
return (w+6);
@@ -315,18 +315,18 @@ static void sigframp_dsp(t_sigframp *x, t_signal **sp)
int n = sp[0]->s_n, n2 = (n>>1);
if (n < 4)
{
- error("framp: minimum 4 points");
- return;
+ error("framp: minimum 4 points");
+ return;
}
dsp_add(sigframp_perform, 5, sp[0]->s_vec, sp[1]->s_vec,
- sp[2]->s_vec, sp[3]->s_vec, n2);
+ sp[2]->s_vec, sp[3]->s_vec, n2);
dsp_add(sigsqrt_perform, 3, sp[3]->s_vec, sp[3]->s_vec, n2);
}
static void sigframp_setup(void)
{
sigframp_class = class_new(gensym("framp~"), sigframp_new, 0,
- sizeof(t_sigframp), 0, 0);
+ sizeof(t_sigframp), 0, 0);
CLASS_MAINSIGNALIN(sigframp_class, t_sigframp, x_f);
class_addmethod(sigframp_class, (t_method)sigframp_dsp, gensym("dsp"), 0);
}
diff --git a/pd/src/d_fftroutine.c b/pd/src/d_fftroutine.c
index 1920aca5..4678d38a 100644
--- a/pd/src/d_fftroutine.c
+++ b/pd/src/d_fftroutine.c
@@ -21,7 +21,7 @@
/*****************************************************************************/
/* Overview:
-
+
My realization of the FFT involves a representation of a network of
"butterfly" elements that takes a set of 'N' sound samples as input and
computes the discrete Fourier transform. This network consists of a
@@ -31,7 +31,7 @@
an associated multiplicative coefficient.
FFT NETWORK:
- -----------
+ -----------
____ _ ____ _ ____ _ ____ _ ____
o--| |o-| |-o| |o-| |-o| |o-| |-o| |o-| |-o| |--o
|reg1| | | |W^r1| | | |reg1| | | |W^r1| | | |reg1|
@@ -68,7 +68,7 @@
|
|
Interconnect
- Paths
+ Paths
The use of "in-place" computation permits one to use only one set of
registers realized by an array of complex number structures. To describe
@@ -98,7 +98,7 @@
#define FALSE 0
#endif
-#define SAMPLE float /* data type used in calculation */
+#define SAMPLE float /* data type used in calculation */
#define SHORT_SIZE sizeof(short)
#define INT_SIZE sizeof(int)
@@ -134,22 +134,22 @@
/* network structure definition */
typedef struct Tfft_net {
- int n;
- int stages;
- int bps;
- int direction;
- int window_type;
- int *load_index;
- SAMPLE *window, *inv_window;
+ int n;
+ int stages;
+ int bps;
+ int direction;
+ int window_type;
+ int *load_index;
+ SAMPLE *window, *inv_window;
SAMPLE *regr;
- SAMPLE *regi;
- SAMPLE **indexpr;
- SAMPLE **indexpi;
- SAMPLE **indexqr;
- SAMPLE **indexqi;
+ SAMPLE *regi;
+ SAMPLE **indexpr;
+ SAMPLE **indexpi;
+ SAMPLE **indexqr;
+ SAMPLE **indexqi;
SAMPLE *coeffr, *inv_coeffr;
SAMPLE *coeffi, *inv_coeffi;
- struct Tfft_net *next;
+ struct Tfft_net *next;
} FFT_NET;
@@ -175,7 +175,7 @@ void short_to_float(short *short_buf, float *float_buf, int n);
void load_registers(FFT_NET *fft_net, float *buf, int buf_form,
int buf_scale, int trnsfrm_dir);
void compute_fft(FFT_NET *fft_net);
-void store_registers(FFT_NET *fft_net, float *buf, int buf_form,
+void store_registers(FFT_NET *fft_net, float *buf, int buf_form,
int buf_scale, int debug);
void build_fft_network(FFT_NET *fft_net, int n, int window_type);
@@ -190,79 +190,79 @@ void cfft(int trnsfrm_dir, int npnt, int window,
/* modifies: result_buf
effects: Computes npnt FFT specified by form, scale, and dir parameters.
Source samples (single precision float) are taken from soure_buf and
- the transfrmd representation is stored in result_buf (single precision
- float). The parameters are defined as follows:
-
- trnsfrm_dir = FORWARD | INVERSE
- npnt = 2^k for some any positive integer k
- window = HANNING | RECTANGULAR
- (RECT = real and imag parts, POLAR = magnitude and phase)
- source_form = REAL | IMAG | RECT | POLAR
- result_form = REAL | IMAG | RECT | MAG | PHASE | POLAR
- xxxxxx_scale= LINEAR | DB ( 20log10 |mag| )
-
- The input/output buffers are stored in a form appropriate to the type.
- For example: REAL => {real, real, real ...},
- MAG => {mag, mag, mag, ... },
- RECT => {real, imag, real, imag, ... },
- POLAR => {mag, phase, mag, phase, ... }.
+ the transfrmd representation is stored in result_buf (single precision
+ float). The parameters are defined as follows:
+
+ trnsfrm_dir = FORWARD | INVERSE
+ npnt = 2^k for some any positive integer k
+ window = HANNING | RECTANGULAR
+ (RECT = real and imag parts, POLAR = magnitude and phase)
+ source_form = REAL | IMAG | RECT | POLAR
+ result_form = REAL | IMAG | RECT | MAG | PHASE | POLAR
+ xxxxxx_scale= LINEAR | DB ( 20log10 |mag| )
+
+ The input/output buffers are stored in a form appropriate to the type.
+ For example: REAL => {real, real, real ...},
+ MAG => {mag, mag, mag, ... },
+ RECT => {real, imag, real, imag, ... },
+ POLAR => {mag, phase, mag, phase, ... }.
To look at the magnitude (in db) of a 1024 point FFT of a real time
- signal we have:
+ signal we have:
- fft(FORWARD, 1024, RECTANGULAR, input, REAL, LINEAR, output, MAG, DB)
+ fft(FORWARD, 1024, RECTANGULAR, input, REAL, LINEAR, output, MAG, DB)
- All possible input and output combinations are possible given the
- choice of type and scale parameters.
+ All possible input and output combinations are possible given the
+ choice of type and scale parameters.
*/
{
- FFT_NET *thisnet = (FFT_NET *)0;
- FFT_NET *lastnet = (FFT_NET *)0;
-
- /* A linked list of fft networks of different sizes is maintained to
- avoid building with every call. The network is built on the first
- call but reused for subsequent calls requesting the same size
- transformation.
- */
+ FFT_NET *thisnet = (FFT_NET *)0;
+ FFT_NET *lastnet = (FFT_NET *)0;
+
+ /* A linked list of fft networks of different sizes is maintained to
+ avoid building with every call. The network is built on the first
+ call but reused for subsequent calls requesting the same size
+ transformation.
+ */
- thisnet=firstnet;
- while (thisnet) {
- if (!(thisnet->n == npnt) || !(thisnet->window_type == window)) {
- /* current net doesn't match size or window type */
- lastnet=thisnet;
- thisnet=thisnet->next;
- continue; /* keep looking */
- }
-
- else { /* network matches desired size */
- load_registers(thisnet, source_buf, source_form, source_scale,
- trnsfrm_dir);
- compute_fft(thisnet); /* do transformation */
- store_registers(thisnet, result_buf, result_form, result_scale,debug);
- return;
- }
- }
-
- /* none of existing networks match required size*/
-
- if (lastnet) { /* add new network to end of list */
- thisnet = (FFT_NET *)malloc(sizeof(FFT_NET)); /* allocate */
- thisnet->next = 0;
- lastnet->next = thisnet; /* add to end of list */
- }
- else { /* first network to be created */
- thisnet=firstnet=(FFT_NET *)malloc(sizeof(FFT_NET)); /* alloc. */
- thisnet->next = 0;
- }
-
- /* build new network and compute transformation */
- build_fft_network(thisnet, npnt, window);
- load_registers(thisnet, source_buf, source_form, source_scale,
- trnsfrm_dir);
- compute_fft(thisnet);
- store_registers(thisnet, result_buf, result_form, result_scale,debug);
- return;
+ thisnet=firstnet;
+ while (thisnet) {
+ if (!(thisnet->n == npnt) || !(thisnet->window_type == window)) {
+ /* current net doesn't match size or window type */
+ lastnet=thisnet;
+ thisnet=thisnet->next;
+ continue; /* keep looking */
+ }
+
+ else { /* network matches desired size */
+ load_registers(thisnet, source_buf, source_form, source_scale,
+ trnsfrm_dir);
+ compute_fft(thisnet); /* do transformation */
+ store_registers(thisnet, result_buf, result_form, result_scale,debug);
+ return;
+ }
+ }
+
+ /* none of existing networks match required size*/
+
+ if (lastnet) { /* add new network to end of list */
+ thisnet = (FFT_NET *)malloc(sizeof(FFT_NET)); /* allocate */
+ thisnet->next = 0;
+ lastnet->next = thisnet; /* add to end of list */
+ }
+ else { /* first network to be created */
+ thisnet=firstnet=(FFT_NET *)malloc(sizeof(FFT_NET)); /* alloc. */
+ thisnet->next = 0;
+ }
+
+ /* build new network and compute transformation */
+ build_fft_network(thisnet, npnt, window);
+ load_registers(thisnet, source_buf, source_form, source_scale,
+ trnsfrm_dir);
+ compute_fft(thisnet);
+ store_registers(thisnet, result_buf, result_form, result_scale,debug);
+ return;
}
void fft_clear(void)
@@ -274,16 +274,16 @@ void fft_clear(void)
{
FFT_NET *thisnet, *nextnet;
- if (firstnet) {
- thisnet=firstnet;
- do {
- nextnet = thisnet->next;
- net_dealloc(thisnet);
- free((char *)thisnet);
- } while (thisnet = nextnet);
- }
+ if (firstnet) {
+ thisnet=firstnet;
+ do {
+ nextnet = thisnet->next;
+ net_dealloc(thisnet);
+ free((char *)thisnet);
+ } while (thisnet = nextnet);
+ }
}
-
+
/*****************************************************************************/
/* NETWORK CONSTRUCTION */
@@ -295,174 +295,174 @@ void build_fft_network(FFT_NET *fft_net, int n, int window_type)
/* modifies:fft_net
effects: Constructs the fft network as described in fft.h. Butterfly
coefficients, read/write indicies, bit reversed load indicies,
- and array allocations are computed.
+ and array allocations are computed.
*/
{
- int cntr, i, j, s;
- int stages, bps;
+ int cntr, i, j, s;
+ int stages, bps;
int **p, **q, *pp, *qp;
- SAMPLE two_pi_div_n = TWO_PI / n;
-
-
- /* network definition */
- fft_net->n = n;
- fft_net->bps = bps = n/2;
- for (i = 0, j = n; j > 1; j >>= 1, i++);
- fft_net->stages = stages = i;
- fft_net->direction = FORWARD;
- fft_net->window_type = window_type;
- fft_net->next = (FFT_NET *)0;
-
- /* allocate registers, index, coefficient arrays */
- net_alloc(fft_net);
-
-
- /* create appropriate windows */
- if (window_type==HANNING) {
- create_hanning(fft_net->window, n, 1.);
- create_hanning(fft_net->inv_window, n, 1./n);
- }
- else {
- create_rectangular(fft_net->window, n, 1.);
- create_rectangular(fft_net->inv_window, n, 1./n);
- }
-
-
- /* calculate butterfly coefficients */ {
-
- int num_diff_coeffs, power_inc, power;
- SAMPLE *coeffpr = fft_net->coeffr;
- SAMPLE *coeffpi = fft_net->coeffi;
- SAMPLE *inv_coeffpr = fft_net->inv_coeffr;
- SAMPLE *inv_coeffpi = fft_net->inv_coeffi;
-
- /* stage one coeffs are 1 + 0j */
- for (i = 0; i < bps; i++) {
- *coeffpr = *inv_coeffpr = 1.;
- *coeffpi = *inv_coeffpi = 0.;
- coeffpr++; inv_coeffpr++;
- coeffpi++; inv_coeffpi++;
- }
-
- /* stage 2 to last stage coeffs need calculation */
- /* (1<<r <=> 2^r */
- for (s = 2; s <= stages; s++) {
-
- num_diff_coeffs = n / (1 << (stages - s + 1));
- power_inc = 1 << (stages -s);
- cntr = 0;
-
- for (i = bps/num_diff_coeffs; i > 0; i--) {
-
- power = 0;
-
- for (j = num_diff_coeffs; j > 0; j--) {
- *coeffpr = cos(two_pi_div_n*power);
- *inv_coeffpr = cos(two_pi_div_n*power);
-/* AAA change these signs */ *coeffpi = -sin(two_pi_div_n*power);
-/* change back */ *inv_coeffpi = sin(two_pi_div_n*power);
- power += power_inc;
- coeffpr++; inv_coeffpr++;
- coeffpi++; inv_coeffpi++;
- }
- }
- }
- }
-
- /* calculate network indicies: stage exchange indicies are
- calculated and then used as offset values from the base
- register locations. The final addresses are then stored in
- fft_net.
- */ {
-
- int index, inc;
- SAMPLE **indexpr = fft_net->indexpr;
- SAMPLE **indexpi = fft_net->indexpi;
- SAMPLE **indexqr = fft_net->indexqr;
- SAMPLE **indexqi = fft_net->indexqi;
- SAMPLE *regr = fft_net->regr;
- SAMPLE *regi = fft_net->regi;
-
-
- /* allocate temporary 2d stage exchange index, 1d temp
- load index */
- p = (int **)malloc(stages * PNTR_SIZE);
- q = (int **)malloc(stages * PNTR_SIZE);
-
- for (s = 0; s < stages; s++) {
- p[s] = (int *)malloc(bps * INT_SIZE);
- q[s] = (int *)malloc(bps * INT_SIZE);
- }
-
- /* calculate stage exchange indicies: */
- for (s = 0; s < stages; s++) {
- pp = p[s];
- qp = q[s];
- inc = 1 << s;
- cntr = 1 << (stages-s-1);
- i = j = index = 0;
-
- do {
- do {
- qp[i] = index + inc;
- pp[i++] = index++;
- } while (++j < inc);
- index = qp[i-1] + 1;
- j = 0;
- } while (--cntr);
- }
-
- /* compute actual address values using indicies as offsets */
- for (s = 0; s < stages; s++) {
- for (i = 0; i < bps; i++) {
- *indexpr++ = regr + p[s][i];
- *indexpi++ = regi + p[s][i];
- *indexqr++ = regr + q[s][i];
- *indexqi++ = regi + q[s][i];
- }
- }
- }
+ SAMPLE two_pi_div_n = TWO_PI / n;
+
+
+ /* network definition */
+ fft_net->n = n;
+ fft_net->bps = bps = n/2;
+ for (i = 0, j = n; j > 1; j >>= 1, i++);
+ fft_net->stages = stages = i;
+ fft_net->direction = FORWARD;
+ fft_net->window_type = window_type;
+ fft_net->next = (FFT_NET *)0;
+
+ /* allocate registers, index, coefficient arrays */
+ net_alloc(fft_net);
+
+
+ /* create appropriate windows */
+ if (window_type==HANNING) {
+ create_hanning(fft_net->window, n, 1.);
+ create_hanning(fft_net->inv_window, n, 1./n);
+ }
+ else {
+ create_rectangular(fft_net->window, n, 1.);
+ create_rectangular(fft_net->inv_window, n, 1./n);
+ }
+
+
+ /* calculate butterfly coefficients */ {
+
+ int num_diff_coeffs, power_inc, power;
+ SAMPLE *coeffpr = fft_net->coeffr;
+ SAMPLE *coeffpi = fft_net->coeffi;
+ SAMPLE *inv_coeffpr = fft_net->inv_coeffr;
+ SAMPLE *inv_coeffpi = fft_net->inv_coeffi;
+
+ /* stage one coeffs are 1 + 0j */
+ for (i = 0; i < bps; i++) {
+ *coeffpr = *inv_coeffpr = 1.;
+ *coeffpi = *inv_coeffpi = 0.;
+ coeffpr++; inv_coeffpr++;
+ coeffpi++; inv_coeffpi++;
+ }
+
+ /* stage 2 to last stage coeffs need calculation */
+ /* (1<<r <=> 2^r */
+ for (s = 2; s <= stages; s++) {
+
+ num_diff_coeffs = n / (1 << (stages - s + 1));
+ power_inc = 1 << (stages -s);
+ cntr = 0;
+
+ for (i = bps/num_diff_coeffs; i > 0; i--) {
+
+ power = 0;
+
+ for (j = num_diff_coeffs; j > 0; j--) {
+ *coeffpr = cos(two_pi_div_n*power);
+ *inv_coeffpr = cos(two_pi_div_n*power);
+/* AAA change these signs */ *coeffpi = -sin(two_pi_div_n*power);
+/* change back */ *inv_coeffpi = sin(two_pi_div_n*power);
+ power += power_inc;
+ coeffpr++; inv_coeffpr++;
+ coeffpi++; inv_coeffpi++;
+ }
+ }
+ }
+ }
+
+ /* calculate network indicies: stage exchange indicies are
+ calculated and then used as offset values from the base
+ register locations. The final addresses are then stored in
+ fft_net.
+ */ {
+
+ int index, inc;
+ SAMPLE **indexpr = fft_net->indexpr;
+ SAMPLE **indexpi = fft_net->indexpi;
+ SAMPLE **indexqr = fft_net->indexqr;
+ SAMPLE **indexqi = fft_net->indexqi;
+ SAMPLE *regr = fft_net->regr;
+ SAMPLE *regi = fft_net->regi;
+
+
+ /* allocate temporary 2d stage exchange index, 1d temp
+ load index */
+ p = (int **)malloc(stages * PNTR_SIZE);
+ q = (int **)malloc(stages * PNTR_SIZE);
+
+ for (s = 0; s < stages; s++) {
+ p[s] = (int *)malloc(bps * INT_SIZE);
+ q[s] = (int *)malloc(bps * INT_SIZE);
+ }
+
+ /* calculate stage exchange indicies: */
+ for (s = 0; s < stages; s++) {
+ pp = p[s];
+ qp = q[s];
+ inc = 1 << s;
+ cntr = 1 << (stages-s-1);
+ i = j = index = 0;
+
+ do {
+ do {
+ qp[i] = index + inc;
+ pp[i++] = index++;
+ } while (++j < inc);
+ index = qp[i-1] + 1;
+ j = 0;
+ } while (--cntr);
+ }
+
+ /* compute actual address values using indicies as offsets */
+ for (s = 0; s < stages; s++) {
+ for (i = 0; i < bps; i++) {
+ *indexpr++ = regr + p[s][i];
+ *indexpi++ = regi + p[s][i];
+ *indexqr++ = regr + q[s][i];
+ *indexqi++ = regi + q[s][i];
+ }
+ }
+ }
/* calculate load indicies (bit reverse ordering) */
/* bit reverse ordering achieved by passing normal
- order indicies backwards through the network */
-
- /* init to normal order indicies */ {
- int *load_index,*load_indexp;
- int *temp_indexp, *temp_index;
- temp_index=temp_indexp=(int *)malloc(n * INT_SIZE);
-
- i = 0; j = n;
- load_index = load_indexp = fft_net->load_index;
-
- while (j--)
- *load_indexp++ = i++;
-
- /* pass indicies backwards through net */
- for (s = stages - 1; s > 0; s--) {
- pp = p[s];
- qp = q[s];
-
- for (i = 0; i < bps; i++) {
- temp_index[pp[i]]=load_index[2*i];
- temp_index[qp[i]]=load_index[2*i+1];
- }
- j = n;
- load_indexp = load_index;
- temp_indexp = temp_index;
- while (j--)
- *load_indexp++ = *temp_indexp++;
- }
-
- /* free all temporary arrays */
- free((char *)temp_index);
- for (s = 0; s < stages; s++) {
- free((char *)p[s]);free((char *)q[s]);
- }
- free((char *)p);free((char *)q);
- }
+ order indicies backwards through the network */
+
+ /* init to normal order indicies */ {
+ int *load_index,*load_indexp;
+ int *temp_indexp, *temp_index;
+ temp_index=temp_indexp=(int *)malloc(n * INT_SIZE);
+
+ i = 0; j = n;
+ load_index = load_indexp = fft_net->load_index;
+
+ while (j--)
+ *load_indexp++ = i++;
+
+ /* pass indicies backwards through net */
+ for (s = stages - 1; s > 0; s--) {
+ pp = p[s];
+ qp = q[s];
+
+ for (i = 0; i < bps; i++) {
+ temp_index[pp[i]]=load_index[2*i];
+ temp_index[qp[i]]=load_index[2*i+1];
+ }
+ j = n;
+ load_indexp = load_index;
+ temp_indexp = temp_index;
+ while (j--)
+ *load_indexp++ = *temp_indexp++;
+ }
+
+ /* free all temporary arrays */
+ free((char *)temp_index);
+ for (s = 0; s < stages; s++) {
+ free((char *)p[s]);free((char *)q[s]);
+ }
+ free((char *)p);free((char *)q);
+ }
}
@@ -476,293 +476,293 @@ void load_registers(FFT_NET *fft_net, float *buf, int buf_form,
/* effects: Multiplies the input buffer with the appropriate window and
stores the resulting values in the initial registers of the
- network. Input buffer must contain values appropriate to form.
- For RECT, the buffer contains real num. followed by imag num,
- and for POLAR, it contains magnitude followed by phase. Pure
- inputs are listed normally. Both LINEAR and DB scales are
- interpreted.
+ network. Input buffer must contain values appropriate to form.
+ For RECT, the buffer contains real num. followed by imag num,
+ and for POLAR, it contains magnitude followed by phase. Pure
+ inputs are listed normally. Both LINEAR and DB scales are
+ interpreted.
*/
{
- int *load_index = fft_net->load_index;
- SAMPLE *window;
- int index, i = 0, n = fft_net->n;
-
- if (trnsfrm_dir==FORWARD) window = fft_net->window;
- else if (trnsfrm_dir==INVERSE) window = fft_net->inv_window;
- else {
- fprintf(stderr, "load_registers:illegal transform direction\n");
- exit(0);
- }
- fft_net->direction = trnsfrm_dir;
-
- switch(buf_scale) {
- case LINEAR: {
-
- switch (buf_form) {
- case REAL: { /* pure REAL */
- while (i < fft_net->n) {
- index = load_index[i];
- fft_net->regr[i]=(SAMPLE)buf[index] * window[index];
- fft_net->regi[i]=0.;
- i++;
- }
- } break;
-
- case IMAG: { /* pure IMAGinary */
- while (i < fft_net->n) {
- index = load_index[i];
- fft_net->regr[i]=0;
- fft_net->regi[i]=(SAMPLE)buf[index] * window[index];
- i++;
- }
- } break;
+ int *load_index = fft_net->load_index;
+ SAMPLE *window;
+ int index, i = 0, n = fft_net->n;
+
+ if (trnsfrm_dir==FORWARD) window = fft_net->window;
+ else if (trnsfrm_dir==INVERSE) window = fft_net->inv_window;
+ else {
+ fprintf(stderr, "load_registers:illegal transform direction\n");
+ exit(0);
+ }
+ fft_net->direction = trnsfrm_dir;
+
+ switch(buf_scale) {
+ case LINEAR: {
+
+ switch (buf_form) {
+ case REAL: { /* pure REAL */
+ while (i < fft_net->n) {
+ index = load_index[i];
+ fft_net->regr[i]=(SAMPLE)buf[index] * window[index];
+ fft_net->regi[i]=0.;
+ i++;
+ }
+ } break;
+
+ case IMAG: { /* pure IMAGinary */
+ while (i < fft_net->n) {
+ index = load_index[i];
+ fft_net->regr[i]=0;
+ fft_net->regi[i]=(SAMPLE)buf[index] * window[index];
+ i++;
+ }
+ } break;
case RECT: { /* both REAL and IMAGinary */
- while (i < fft_net->n) {
- index = load_index[i];
- fft_net->regr[i]=(SAMPLE)buf[index*2] * window[index];
- fft_net->regi[i]=(SAMPLE)buf[index*2+1] * window[index];
- i++;
- }
- } break;
-
- case POLAR: { /* magnitude followed by phase */
- while (i < fft_net->n) {
- index = load_index[i];
- fft_net->regr[i]=(SAMPLE)(buf[index*2] * cos(buf[index*2+1]))
- * window[index];
- fft_net->regi[i]=(SAMPLE)(buf[index*2] * sin(buf[index*2+1]))
- * window[index];
- i++;
- }
- } break;
-
- default: {
- fprintf(stderr, "load_registers:illegal input form\n");
- exit(0);
- } break;
+ while (i < fft_net->n) {
+ index = load_index[i];
+ fft_net->regr[i]=(SAMPLE)buf[index*2] * window[index];
+ fft_net->regi[i]=(SAMPLE)buf[index*2+1] * window[index];
+ i++;
+ }
+ } break;
+
+ case POLAR: { /* magnitude followed by phase */
+ while (i < fft_net->n) {
+ index = load_index[i];
+ fft_net->regr[i]=(SAMPLE)(buf[index*2] * cos(buf[index*2+1]))
+ * window[index];
+ fft_net->regi[i]=(SAMPLE)(buf[index*2] * sin(buf[index*2+1]))
+ * window[index];
+ i++;
+ }
+ } break;
+
+ default: {
+ fprintf(stderr, "load_registers:illegal input form\n");
+ exit(0);
+ } break;
}
- } break;
+ } break;
case DB: {
-
- switch (buf_form) {
- case REAL: { /* log pure REAL */
- while (i < fft_net->n) {
- index = load_index[i];
- fft_net->regr[i]=(SAMPLE)pow(10., (1./20.)*buf[index])
- * window[index]; /* window scaling after linearization */
- fft_net->regi[i]=0.;
- i++;
- }
- } break;
-
- case IMAG: { /* log pure IMAGinary */
- while (i < fft_net->n) {
- index = load_index[i];
- fft_net->regr[i]=0.;
- fft_net->regi[i]=(SAMPLE)pow(10., (1./20.)*buf[index])
- * window[index];
- i++;
- }
- } break;
+
+ switch (buf_form) {
+ case REAL: { /* log pure REAL */
+ while (i < fft_net->n) {
+ index = load_index[i];
+ fft_net->regr[i]=(SAMPLE)pow(10., (1./20.)*buf[index])
+ * window[index]; /* window scaling after linearization */
+ fft_net->regi[i]=0.;
+ i++;
+ }
+ } break;
+
+ case IMAG: { /* log pure IMAGinary */
+ while (i < fft_net->n) {
+ index = load_index[i];
+ fft_net->regr[i]=0.;
+ fft_net->regi[i]=(SAMPLE)pow(10., (1./20.)*buf[index])
+ * window[index];
+ i++;
+ }
+ } break;
case RECT: { /* log REAL and log IMAGinary */
- while (i < fft_net->n) {
- index = load_index[i];
- fft_net->regr[i]=(SAMPLE)pow(10., (1./20.)*buf[index*2])
- * window[index];
- fft_net->regi[i]=(SAMPLE)pow(10., (1./20.)*buf[index*2+1])
- * window[index];
- i++;
- }
- } break;
-
- case POLAR: { /* log mag followed by phase */
- while (i < fft_net->n) {
- index = load_index[i];
- fft_net->regr[i]=(SAMPLE)(pow(10., (1./20.)*buf[index*2])
- * cos(buf[index*2+1])) * window[index];
- fft_net->regi[i]=(SAMPLE)(pow(10., (1./20.)*buf[index*2])
- * sin(buf[index*2+1])) * window[index];
- i++;
- }
- } break;
-
- default: {
- fprintf(stderr, "load_registers:illegal input form\n");
- exit(0);
- } break;
- }
- } break;
+ while (i < fft_net->n) {
+ index = load_index[i];
+ fft_net->regr[i]=(SAMPLE)pow(10., (1./20.)*buf[index*2])
+ * window[index];
+ fft_net->regi[i]=(SAMPLE)pow(10., (1./20.)*buf[index*2+1])
+ * window[index];
+ i++;
+ }
+ } break;
+
+ case POLAR: { /* log mag followed by phase */
+ while (i < fft_net->n) {
+ index = load_index[i];
+ fft_net->regr[i]=(SAMPLE)(pow(10., (1./20.)*buf[index*2])
+ * cos(buf[index*2+1])) * window[index];
+ fft_net->regi[i]=(SAMPLE)(pow(10., (1./20.)*buf[index*2])
+ * sin(buf[index*2+1])) * window[index];
+ i++;
+ }
+ } break;
+
+ default: {
+ fprintf(stderr, "load_registers:illegal input form\n");
+ exit(0);
+ } break;
+ }
+ } break;
default: {
- fprintf(stderr, "load_registers:illegal input scale\n");
- exit(0);
- } break;
- }
+ fprintf(stderr, "load_registers:illegal input scale\n");
+ exit(0);
+ } break;
+ }
}
-void store_registers(FFT_NET *fft_net, float *buf, int buf_form,
+void store_registers(FFT_NET *fft_net, float *buf, int buf_form,
int buf_scale, int debug)
/* modifies: buf
effects: Writes the final contents of the network registers into buf in
either linear or db scale, polar or rectangular form. If any of
- the pure forms(REAL, IMAG, MAG, or PHASE) are used then only the
- corresponding part of the registers is stored in buf.
+ the pure forms(REAL, IMAG, MAG, or PHASE) are used then only the
+ corresponding part of the registers is stored in buf.
*/
{
- int i;
- SAMPLE real, imag, mag, phase;
- int n;
-
- i = 0;
- n = fft_net->n;
-
- switch (buf_scale) {
- case LINEAR: {
-
- switch (buf_form) {
- case REAL: { /* pure REAL */
- do {
- *buf++ = (float)fft_net->regr[i];
- } while (++i < n);
- } break;
-
- case IMAG: { /* pure IMAGinary */
- do {
- *buf++ = (float)fft_net->regi[i];
- } while (++i < n);
- } break;
-
- case RECT: { /* both REAL and IMAGinary */
- do {
- *buf++ = (float)fft_net->regr[i];
- *buf++ = (float)fft_net->regi[i];
- } while (++i < n);
- } break;
-
- case MAG: { /* magnitude only */
- do {
- real = fft_net->regr[i];
- imag = fft_net->regi[i];
- *buf++ = (float)sqrt(real*real+imag*imag);
- } while (++i < n);
- } break;
-
- case PHASE: { /* phase only */
- do {
- real = fft_net->regr[i];
- imag = fft_net->regi[i];
- if (real > .00001)
- *buf++ = (float)atan2(imag, real);
- else { /* deal with bad case */
- if (imag > 0){ *buf++ = PI / 2.;
- if(debug) fprintf(stderr,"real=0 and imag > 0\n");}
- else if (imag < 0){ *buf++ = -PI / 2.;
- if(debug) fprintf(stderr,"real=0 and imag < 0\n");}
- else { *buf++ = 0;
- if(debug) fprintf(stderr,"real=0 and imag=0\n");}
- }
- } while (++i < n);
- } break;
-
- case POLAR: { /* magnitude and phase */
- do {
- real = fft_net->regr[i];
- imag = fft_net->regi[i];
- *buf++ = (float)sqrt(real*real+imag*imag);
- if (real) /* a hack to avoid div by zero */
- *buf++ = (float)atan2(imag, real);
- else { /* deal with bad case */
- if (imag > 0) *buf++ = PI / 2.;
- else if (imag < 0) *buf++ = -PI / 2.;
- else *buf++ = 0;
- }
- } while (++i < n);
- } break;
-
- default: {
- fprintf(stderr, "store_registers:illegal output form\n");
- exit(0);
- } break;
- }
- } break;
-
+ int i;
+ SAMPLE real, imag, mag, phase;
+ int n;
+
+ i = 0;
+ n = fft_net->n;
+
+ switch (buf_scale) {
+ case LINEAR: {
+
+ switch (buf_form) {
+ case REAL: { /* pure REAL */
+ do {
+ *buf++ = (float)fft_net->regr[i];
+ } while (++i < n);
+ } break;
+
+ case IMAG: { /* pure IMAGinary */
+ do {
+ *buf++ = (float)fft_net->regi[i];
+ } while (++i < n);
+ } break;
+
+ case RECT: { /* both REAL and IMAGinary */
+ do {
+ *buf++ = (float)fft_net->regr[i];
+ *buf++ = (float)fft_net->regi[i];
+ } while (++i < n);
+ } break;
+
+ case MAG: { /* magnitude only */
+ do {
+ real = fft_net->regr[i];
+ imag = fft_net->regi[i];
+ *buf++ = (float)sqrt(real*real+imag*imag);
+ } while (++i < n);
+ } break;
+
+ case PHASE: { /* phase only */
+ do {
+ real = fft_net->regr[i];
+ imag = fft_net->regi[i];
+ if (real > .00001)
+ *buf++ = (float)atan2(imag, real);
+ else { /* deal with bad case */
+ if (imag > 0){ *buf++ = PI / 2.;
+ if(debug) fprintf(stderr,"real=0 and imag > 0\n");}
+ else if (imag < 0){ *buf++ = -PI / 2.;
+ if(debug) fprintf(stderr,"real=0 and imag < 0\n");}
+ else { *buf++ = 0;
+ if(debug) fprintf(stderr,"real=0 and imag=0\n");}
+ }
+ } while (++i < n);
+ } break;
+
+ case POLAR: { /* magnitude and phase */
+ do {
+ real = fft_net->regr[i];
+ imag = fft_net->regi[i];
+ *buf++ = (float)sqrt(real*real+imag*imag);
+ if (real) /* a hack to avoid div by zero */
+ *buf++ = (float)atan2(imag, real);
+ else { /* deal with bad case */
+ if (imag > 0) *buf++ = PI / 2.;
+ else if (imag < 0) *buf++ = -PI / 2.;
+ else *buf++ = 0;
+ }
+ } while (++i < n);
+ } break;
+
+ default: {
+ fprintf(stderr, "store_registers:illegal output form\n");
+ exit(0);
+ } break;
+ }
+ } break;
+
case DB: {
- switch (buf_form) {
- case REAL: { /* real only */
- do {
- *buf++ = (float)20.*log10(fft_net->regr[i]);
- } while (++i < n);
- } break;
-
- case IMAG: { /* imag only */
- do {
- *buf++ = (float)20.*log10(fft_net->regi[i]);
- } while (++i < n);
- } break;
-
- case RECT: { /* real and imag */
- do {
- *buf++ = (float)20.*log10(fft_net->regr[i]);
- *buf++ = (float)20.*log10(fft_net->regi[i]);
- } while (++i < n);
- } break;
-
- case MAG: { /* magnitude only */
- do {
- real = fft_net->regr[i];
- imag = fft_net->regi[i];
- *buf++ = (float)20.*log10(sqrt(real*real+imag*imag));
- } while (++i < n);
- } break;
-
- case PHASE: { /* phase only */
- do {
- real = fft_net->regr[i];
- imag = fft_net->regi[i];
- if (real)
- *buf++ = (float)atan2(imag, real);
- else { /* deal with bad case */
- if (imag > 0) *buf++ = PI / 2.;
- else if (imag < 0) *buf++ = -PI / 2.;
- else *buf++ = 0;
- }
- } while (++i < n);
- } break;
-
- case POLAR: { /* magnitude and phase */
- do {
- real = fft_net->regr[i];
- imag = fft_net->regi[i];
- *buf++ = (float)20.*log10(sqrt(real*real+imag*imag));
- if (real)
- *buf++ = (float)atan2(imag, real);
- else { /* deal with bad case */
- if (imag > 0) *buf++ = PI / 2.;
- else if (imag < 0) *buf++ = -PI / 2.;
- else *buf++ = 0;
- }
- } while (++i < n);
- } break;
-
- default: {
- fprintf(stderr, "store_registers:illegal output form\n");
- exit(0);
- } break;
- }
- } break;
+ switch (buf_form) {
+ case REAL: { /* real only */
+ do {
+ *buf++ = (float)20.*log10(fft_net->regr[i]);
+ } while (++i < n);
+ } break;
+
+ case IMAG: { /* imag only */
+ do {
+ *buf++ = (float)20.*log10(fft_net->regi[i]);
+ } while (++i < n);
+ } break;
+
+ case RECT: { /* real and imag */
+ do {
+ *buf++ = (float)20.*log10(fft_net->regr[i]);
+ *buf++ = (float)20.*log10(fft_net->regi[i]);
+ } while (++i < n);
+ } break;
+
+ case MAG: { /* magnitude only */
+ do {
+ real = fft_net->regr[i];
+ imag = fft_net->regi[i];
+ *buf++ = (float)20.*log10(sqrt(real*real+imag*imag));
+ } while (++i < n);
+ } break;
+
+ case PHASE: { /* phase only */
+ do {
+ real = fft_net->regr[i];
+ imag = fft_net->regi[i];
+ if (real)
+ *buf++ = (float)atan2(imag, real);
+ else { /* deal with bad case */
+ if (imag > 0) *buf++ = PI / 2.;
+ else if (imag < 0) *buf++ = -PI / 2.;
+ else *buf++ = 0;
+ }
+ } while (++i < n);
+ } break;
+
+ case POLAR: { /* magnitude and phase */
+ do {
+ real = fft_net->regr[i];
+ imag = fft_net->regi[i];
+ *buf++ = (float)20.*log10(sqrt(real*real+imag*imag));
+ if (real)
+ *buf++ = (float)atan2(imag, real);
+ else { /* deal with bad case */
+ if (imag > 0) *buf++ = PI / 2.;
+ else if (imag < 0) *buf++ = -PI / 2.;
+ else *buf++ = 0;
+ }
+ } while (++i < n);
+ } break;
+
+ default: {
+ fprintf(stderr, "store_registers:illegal output form\n");
+ exit(0);
+ } break;
+ }
+ } break;
default: {
- fprintf(stderr, "store_registers:illegal output scale\n");
- exit(0);
- } break;
+ fprintf(stderr, "store_registers:illegal output scale\n");
+ exit(0);
+ } break;
}
}
@@ -777,93 +777,93 @@ void compute_fft(FFT_NET *fft_net)
/* modifies: fft_net
effects: Passes the values (already loaded) in the registers through
- the network, multiplying with appropriate coefficients at each
- stage. The fft result will be in the registers at the end of
- the computation. The direction of the transformation is indicated
- by the network flag 'direction'. The form of the computation is:
-
- X(pn) = X(p) + C*X(q)
- X(qn) = X(p) - C*X(q)
-
- where X(pn,qn) represents the output of the registers at each stage.
- The calculations are actually done in place. Register pointers are
- used to speed up the calculations.
-
- Register and coefficient addresses involved in the calculations
- are stored sequentially and are accessed as such. fft_net->indexp,
- indexq contain pointers to the relevant addresses, and fft_net->coeffs,
- inv_coeffs points to the appropriate coefficients at each stage of the
- computation.
+ the network, multiplying with appropriate coefficients at each
+ stage. The fft result will be in the registers at the end of
+ the computation. The direction of the transformation is indicated
+ by the network flag 'direction'. The form of the computation is:
+
+ X(pn) = X(p) + C*X(q)
+ X(qn) = X(p) - C*X(q)
+
+ where X(pn,qn) represents the output of the registers at each stage.
+ The calculations are actually done in place. Register pointers are
+ used to speed up the calculations.
+
+ Register and coefficient addresses involved in the calculations
+ are stored sequentially and are accessed as such. fft_net->indexp,
+ indexq contain pointers to the relevant addresses, and fft_net->coeffs,
+ inv_coeffs points to the appropriate coefficients at each stage of the
+ computation.
*/
{
- SAMPLE **xpr, **xpi, **xqr, **xqi, *cr, *ci;
- int i;
- SAMPLE tpr, tpi, tqr, tqi;
- int bps = fft_net->bps;
- int cnt = bps * (fft_net->stages - 1);
-
- /* predetermined register addresses and coefficients */
- xpr = fft_net->indexpr;
- xpi = fft_net->indexpi;
- xqr = fft_net->indexqr;
- xqi = fft_net->indexqi;
-
- if (fft_net->direction==FORWARD) { /* FORWARD FFT coefficients */
- cr = fft_net->coeffr;
- ci = fft_net->coeffi;
- }
- else { /* INVERSE FFT coefficients */
- cr = fft_net->inv_coeffr;
- ci = fft_net->inv_coeffi;
- }
-
- /* stage one coefficients are 1 + 0j so C*X(q)=X(q) */
- /* bps mults can be avoided */
-
- for (i = 0; i < bps; i++) {
-
- /* add X(p) and X(q) */
- tpr = **xpr + **xqr;
- tpi = **xpi + **xqi;
- tqr = **xpr - **xqr;
- tqi = **xpi - **xqi;
-
- /* exchange register with temp */
- **xpr = tpr;
- **xpi = tpi;
- **xqr = tqr;
- **xqi = tqi;
-
- /* next set of register for calculations: */
- xpr++; xpi++; xqr++; xqi++; cr++; ci++;
-
- }
-
- for (i = 0; i < cnt; i++) {
-
- /* mult X(q) by coeff C */
- tqr = **xqr * *cr - **xqi * *ci;
- tqi = **xqr * *ci + **xqi * *cr;
-
- /* exchange register with temp */
- **xqr = tqr;
- **xqi = tqi;
-
- /* add X(p) and X(q) */
- tpr = **xpr + **xqr;
- tpi = **xpi + **xqi;
- tqr = **xpr - **xqr;
- tqi = **xpi - **xqi;
-
- /* exchange register with temp */
- **xpr = tpr;
- **xpi = tpi;
- **xqr = tqr;
- **xqi = tqi;
- /* next set of register for calculations: */
- xpr++; xpi++; xqr++; xqi++; cr++; ci++;
- }
+ SAMPLE **xpr, **xpi, **xqr, **xqi, *cr, *ci;
+ int i;
+ SAMPLE tpr, tpi, tqr, tqi;
+ int bps = fft_net->bps;
+ int cnt = bps * (fft_net->stages - 1);
+
+ /* predetermined register addresses and coefficients */
+ xpr = fft_net->indexpr;
+ xpi = fft_net->indexpi;
+ xqr = fft_net->indexqr;
+ xqi = fft_net->indexqi;
+
+ if (fft_net->direction==FORWARD) { /* FORWARD FFT coefficients */
+ cr = fft_net->coeffr;
+ ci = fft_net->coeffi;
+ }
+ else { /* INVERSE FFT coefficients */
+ cr = fft_net->inv_coeffr;
+ ci = fft_net->inv_coeffi;
+ }
+
+ /* stage one coefficients are 1 + 0j so C*X(q)=X(q) */
+ /* bps mults can be avoided */
+
+ for (i = 0; i < bps; i++) {
+
+ /* add X(p) and X(q) */
+ tpr = **xpr + **xqr;
+ tpi = **xpi + **xqi;
+ tqr = **xpr - **xqr;
+ tqi = **xpi - **xqi;
+
+ /* exchange register with temp */
+ **xpr = tpr;
+ **xpi = tpi;
+ **xqr = tqr;
+ **xqi = tqi;
+
+ /* next set of register for calculations: */
+ xpr++; xpi++; xqr++; xqi++; cr++; ci++;
+
+ }
+
+ for (i = 0; i < cnt; i++) {
+
+ /* mult X(q) by coeff C */
+ tqr = **xqr * *cr - **xqi * *ci;
+ tqi = **xqr * *ci + **xqi * *cr;
+
+ /* exchange register with temp */
+ **xqr = tqr;
+ **xqi = tqi;
+
+ /* add X(p) and X(q) */
+ tpr = **xpr + **xqr;
+ tpi = **xpi + **xqi;
+ tqr = **xpr - **xqr;
+ tqi = **xpi - **xqi;
+
+ /* exchange register with temp */
+ **xpr = tpr;
+ **xpi = tpi;
+ **xqr = tqr;
+ **xqi = tqi;
+ /* next set of register for calculations: */
+ xpr++; xpi++; xqr++; xqi++; cr++; ci++;
+ }
}
@@ -875,35 +875,35 @@ void net_alloc(FFT_NET *fft_net)
/* effects: Allocates appropriate two dimensional arrays and assigns
- correct internal pointers.
+ correct internal pointers.
*/
{
- int stages, bps, n;
+ int stages, bps, n;
- n = fft_net->n;
- stages = fft_net->stages;
- bps = fft_net->bps;
+ n = fft_net->n;
+ stages = fft_net->stages;
+ bps = fft_net->bps;
- /* two dimensional arrays with elements stored sequentially */
+ /* two dimensional arrays with elements stored sequentially */
- fft_net->load_index = (int *)malloc(n * INT_SIZE);
- fft_net->regr = (SAMPLE *)malloc(n * SAMPLE_SIZE);
- fft_net->regi = (SAMPLE *)malloc(n * SAMPLE_SIZE);
- fft_net->coeffr = (SAMPLE *)malloc(stages*bps*SAMPLE_SIZE);
- fft_net->coeffi = (SAMPLE *)malloc(stages*bps*SAMPLE_SIZE);
- fft_net->inv_coeffr = (SAMPLE *)malloc(stages*bps*SAMPLE_SIZE);
- fft_net->inv_coeffi = (SAMPLE *)malloc(stages*bps*SAMPLE_SIZE);
- fft_net->indexpr = (SAMPLE **)malloc(stages * bps * PNTR_SIZE);
- fft_net->indexpi = (SAMPLE **)malloc(stages * bps * PNTR_SIZE);
- fft_net->indexqr = (SAMPLE **)malloc(stages * bps * PNTR_SIZE);
- fft_net->indexqi = (SAMPLE **)malloc(stages * bps * PNTR_SIZE);
+ fft_net->load_index = (int *)malloc(n * INT_SIZE);
+ fft_net->regr = (SAMPLE *)malloc(n * SAMPLE_SIZE);
+ fft_net->regi = (SAMPLE *)malloc(n * SAMPLE_SIZE);
+ fft_net->coeffr = (SAMPLE *)malloc(stages*bps*SAMPLE_SIZE);
+ fft_net->coeffi = (SAMPLE *)malloc(stages*bps*SAMPLE_SIZE);
+ fft_net->inv_coeffr = (SAMPLE *)malloc(stages*bps*SAMPLE_SIZE);
+ fft_net->inv_coeffi = (SAMPLE *)malloc(stages*bps*SAMPLE_SIZE);
+ fft_net->indexpr = (SAMPLE **)malloc(stages * bps * PNTR_SIZE);
+ fft_net->indexpi = (SAMPLE **)malloc(stages * bps * PNTR_SIZE);
+ fft_net->indexqr = (SAMPLE **)malloc(stages * bps * PNTR_SIZE);
+ fft_net->indexqi = (SAMPLE **)malloc(stages * bps * PNTR_SIZE);
- /* one dimensional load window */
- fft_net->window = (SAMPLE *)malloc(n * SAMPLE_SIZE);
- fft_net->inv_window = (SAMPLE *)malloc(n * SAMPLE_SIZE);
+ /* one dimensional load window */
+ fft_net->window = (SAMPLE *)malloc(n * SAMPLE_SIZE);
+ fft_net->inv_window = (SAMPLE *)malloc(n * SAMPLE_SIZE);
}
void net_dealloc(FFT_NET *fft_net)
@@ -914,19 +914,19 @@ void net_dealloc(FFT_NET *fft_net)
{
- free((char *)fft_net->load_index);
- free((char *)fft_net->regr);
- free((char *)fft_net->regi);
- free((char *)fft_net->coeffr);
- free((char *)fft_net->coeffi);
- free((char *)fft_net->inv_coeffr);
- free((char *)fft_net->inv_coeffi);
- free((char *)fft_net->indexpr);
- free((char *)fft_net->indexpi);
- free((char *)fft_net->indexqr);
- free((char *)fft_net->indexqi);
- free((char *)fft_net->window);
- free((char *)fft_net->inv_window);
+ free((char *)fft_net->load_index);
+ free((char *)fft_net->regr);
+ free((char *)fft_net->regi);
+ free((char *)fft_net->coeffr);
+ free((char *)fft_net->coeffi);
+ free((char *)fft_net->inv_coeffr);
+ free((char *)fft_net->inv_coeffi);
+ free((char *)fft_net->indexpr);
+ free((char *)fft_net->indexpi);
+ free((char *)fft_net->indexqr);
+ free((char *)fft_net->indexqi);
+ free((char *)fft_net->window);
+ free((char *)fft_net->inv_window);
}
@@ -938,11 +938,11 @@ int n;
*/
{
- int i;
+ int i;
- for (i = n; i > 1; i >>= 1)
- if (i & 1) return FALSE; /* more than one bit high */
- return TRUE;
+ for (i = n; i > 1; i >>= 1)
+ if (i & 1) return FALSE; /* more than one bit high */
+ return TRUE;
}
@@ -953,13 +953,13 @@ void create_hanning(SAMPLE *window, int n, SAMPLE scale)
*/
{
- SAMPLE a, pi_div_n = PI/n;
- int k;
+ SAMPLE a, pi_div_n = PI/n;
+ int k;
- for (k=1; k <= n; k++) {
- a = sin(k * pi_div_n);
- *window++ = scale * a * a;
- }
+ for (k=1; k <= n; k++) {
+ a = sin(k * pi_div_n);
+ *window++ = scale * a * a;
+ }
}
@@ -970,8 +970,8 @@ void create_rectangular(SAMPLE *window, int n, SAMPLE scale)
*/
{
- while (n--)
- *window++ = scale;
+ while (n--)
+ *window++ = scale;
}
@@ -981,9 +981,9 @@ void short_to_float(short *short_buf, float *float_buf, int n)
*/
{
- while (n--) {
- *float_buf++ = (float)*short_buf++;
- }
+ while (n--) {
+ *float_buf++ = (float)*short_buf++;
+ }
}
diff --git a/pd/src/d_filter.c b/pd/src/d_filter.c
index 732bd3d6..7a5649ee 100644
--- a/pd/src/d_filter.c
+++ b/pd/src/d_filter.c
@@ -32,7 +32,7 @@ static void *sighip_new(t_floatarg f)
{
t_sighip *x = (t_sighip *)pd_new(sighip_class);
inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("float"), gensym("ft1"));
- outlet_new(&x->x_obj, gensym("signal"));
+ outlet_new(&x->x_obj, &s_signal);
x->x_sr = 44100;
x->x_ctl = &x->x_cspace;
x->x_cspace.c_x = 0;
@@ -47,9 +47,9 @@ static void sighip_ft1(t_sighip *x, t_floatarg f)
x->x_hz = f;
x->x_ctl->c_coef = 1 - f * (2 * 3.14159) / x->x_sr;
if (x->x_ctl->c_coef < 0)
- x->x_ctl->c_coef = 0;
+ x->x_ctl->c_coef = 0;
else if (x->x_ctl->c_coef > 1)
- x->x_ctl->c_coef = 1;
+ x->x_ctl->c_coef = 1;
}
static t_int *sighip_perform(t_int *w)
@@ -63,21 +63,21 @@ static t_int *sighip_perform(t_int *w)
float coef = c->c_coef;
if (coef < 1)
{
- for (i = 0; i < n; i++)
- {
- float new = *in++ + coef * last;
- *out++ = new - last;
- last = new;
- }
- if (PD_BADFLOAT(last))
- last = 0;
- c->c_x = last;
+ for (i = 0; i < n; i++)
+ {
+ float new = *in++ + coef * last;
+ *out++ = new - last;
+ last = new;
+ }
+ if (PD_BIGORSMALL(last))
+ last = 0;
+ c->c_x = last;
}
else
{
- for (i = 0; i < n; i++)
- *out++ = *in++;
- c->c_x = 0;
+ for (i = 0; i < n; i++)
+ *out++ = *in++;
+ c->c_x = 0;
}
return (w+5);
}
@@ -87,8 +87,8 @@ static void sighip_dsp(t_sighip *x, t_signal **sp)
x->x_sr = sp[0]->s_sr;
sighip_ft1(x, x->x_hz);
dsp_add(sighip_perform, 4,
- sp[0]->s_vec, sp[1]->s_vec,
- x->x_ctl, sp[0]->s_n);
+ sp[0]->s_vec, sp[1]->s_vec,
+ x->x_ctl, sp[0]->s_n);
}
@@ -100,11 +100,11 @@ static void sighip_clear(t_sighip *x, t_floatarg q)
void sighip_setup(void)
{
sighip_class = class_new(gensym("hip~"), (t_newmethod)sighip_new, 0,
- sizeof(t_sighip), 0, A_DEFFLOAT, 0);
+ sizeof(t_sighip), 0, A_DEFFLOAT, 0);
CLASS_MAINSIGNALIN(sighip_class, t_sighip, x_f);
class_addmethod(sighip_class, (t_method)sighip_dsp, gensym("dsp"), 0);
class_addmethod(sighip_class, (t_method)sighip_ft1,
- gensym("ft1"), A_FLOAT, 0);
+ gensym("ft1"), A_FLOAT, 0);
class_addmethod(sighip_class, (t_method)sighip_clear, gensym("clear"), 0);
}
@@ -134,7 +134,7 @@ static void *siglop_new(t_floatarg f)
{
t_siglop *x = (t_siglop *)pd_new(siglop_class);
inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("float"), gensym("ft1"));
- outlet_new(&x->x_obj, gensym("signal"));
+ outlet_new(&x->x_obj, &s_signal);
x->x_sr = 44100;
x->x_ctl = &x->x_cspace;
x->x_cspace.c_x = 0;
@@ -149,9 +149,9 @@ static void siglop_ft1(t_siglop *x, t_floatarg f)
x->x_hz = f;
x->x_ctl->c_coef = f * (2 * 3.14159) / x->x_sr;
if (x->x_ctl->c_coef > 1)
- x->x_ctl->c_coef = 1;
+ x->x_ctl->c_coef = 1;
else if (x->x_ctl->c_coef < 0)
- x->x_ctl->c_coef = 0;
+ x->x_ctl->c_coef = 0;
}
static void siglop_clear(t_siglop *x, t_floatarg q)
@@ -170,9 +170,9 @@ static t_int *siglop_perform(t_int *w)
float coef = c->c_coef;
float feedback = 1 - coef;
for (i = 0; i < n; i++)
- last = *out++ = coef * *in++ + feedback * last;
- if (PD_BADFLOAT(last))
- last = 0;
+ last = *out++ = coef * *in++ + feedback * last;
+ if (PD_BIGORSMALL(last))
+ last = 0;
c->c_x = last;
return (w+5);
}
@@ -182,19 +182,19 @@ static void siglop_dsp(t_siglop *x, t_signal **sp)
x->x_sr = sp[0]->s_sr;
siglop_ft1(x, x->x_hz);
dsp_add(siglop_perform, 4,
- sp[0]->s_vec, sp[1]->s_vec,
- x->x_ctl, sp[0]->s_n);
+ sp[0]->s_vec, sp[1]->s_vec,
+ x->x_ctl, sp[0]->s_n);
}
void siglop_setup(void)
{
siglop_class = class_new(gensym("lop~"), (t_newmethod)siglop_new, 0,
- sizeof(t_siglop), 0, A_DEFFLOAT, 0);
+ sizeof(t_siglop), 0, A_DEFFLOAT, 0);
CLASS_MAINSIGNALIN(siglop_class, t_siglop, x_f);
class_addmethod(siglop_class, (t_method)siglop_dsp, gensym("dsp"), 0);
class_addmethod(siglop_class, (t_method)siglop_ft1,
- gensym("ft1"), A_FLOAT, 0);
+ gensym("ft1"), A_FLOAT, 0);
class_addmethod(siglop_class, (t_method)siglop_clear, gensym("clear"), 0);
}
@@ -229,7 +229,7 @@ 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"));
+ outlet_new(&x->x_obj, &s_signal);
x->x_sr = 44100;
x->x_ctl = &x->x_cspace;
x->x_cspace.c_x1 = 0;
@@ -243,8 +243,8 @@ 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);
+ 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);
}
@@ -265,7 +265,7 @@ static void sigbp_docoef(t_sigbp *x, t_floatarg f, t_floatarg q)
x->x_ctl->c_coef2 = - r * r;
x->x_ctl->c_gain = 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); */
+ r, omega, x->x_ctl->c_coef1, x->x_ctl->c_coef2); */
}
static void sigbp_ft1(t_sigbp *x, t_floatarg f)
@@ -297,15 +297,15 @@ static t_int *sigbp_perform(t_int *w)
float gain = c->c_gain;
for (i = 0; i < n; i++)
{
- float output = *in++ + coef1 * last + coef2 * prev;
- *out++ = gain * output;
- prev = last;
- last = output;
+ float output = *in++ + coef1 * last + coef2 * prev;
+ *out++ = gain * output;
+ prev = last;
+ last = output;
}
- if (PD_BADFLOAT(last))
- last = 0;
- if (PD_BADFLOAT(prev))
- prev = 0;
+ if (PD_BIGORSMALL(last))
+ last = 0;
+ if (PD_BIGORSMALL(prev))
+ prev = 0;
c->c_x1 = last;
c->c_x2 = prev;
return (w+5);
@@ -316,21 +316,21 @@ 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);
+ sp[0]->s_vec, sp[1]->s_vec,
+ x->x_ctl, sp[0]->s_n);
}
void sigbp_setup(void)
{
sigbp_class = class_new(gensym("bp~"), (t_newmethod)sigbp_new, 0,
- sizeof(t_sigbp), 0, A_DEFFLOAT, A_DEFFLOAT, 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);
+ gensym("ft1"), A_FLOAT, 0);
class_addmethod(sigbp_class, (t_method)sigbp_ft2,
- gensym("ft2"), A_FLOAT, 0);
+ gensym("ft2"), A_FLOAT, 0);
class_addmethod(sigbp_class, (t_method)sigbp_clear, gensym("clear"), 0);
}
@@ -362,7 +362,7 @@ 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"));
+ outlet_new(&x->x_obj, &s_signal);
x->x_ctl = &x->x_cspace;
x->x_cspace.c_x1 = x->x_cspace.c_x2 = 0;
sigbiquad_list(x, s, argc, argv);
@@ -386,12 +386,12 @@ static t_int *sigbiquad_perform(t_int *w)
float ff3 = c->c_ff3;
for (i = 0; i < n; i++)
{
- float output = *in++ + fb1 * last + fb2 * prev;
- if (PD_BADFLOAT(output))
- output = 0;
- *out++ = ff1 * output + ff2 * last + ff3 * prev;
- prev = last;
- last = output;
+ float output = *in++ + fb1 * last + fb2 * prev;
+ if (PD_BIGORSMALL(output))
+ output = 0;
+ *out++ = ff1 * output + ff2 * last + ff3 * prev;
+ prev = last;
+ last = output;
}
c->c_x1 = last;
c->c_x2 = prev;
@@ -409,20 +409,20 @@ static void sigbiquad_list(t_sigbiquad *x, t_symbol *s, int argc, t_atom *argv)
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;
+ /* 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;
+ /* 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 */
+ /* if unstable, just bash to zero */
fb1 = fb2 = ff1 = ff2 = ff3 = 0;
stable:
c->c_fb1 = fb1;
@@ -442,22 +442,22 @@ static void sigbiquad_set(t_sigbiquad *x, t_symbol *s, int argc, t_atom *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);
+ sp[0]->s_vec, sp[1]->s_vec,
+ x->x_ctl, sp[0]->s_n);
}
void sigbiquad_setup(void)
{
sigbiquad_class = class_new(gensym("biquad~"), (t_newmethod)sigbiquad_new,
- 0, sizeof(t_sigbiquad), 0, A_GIMME, 0);
+ 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);
+ A_GIMME, 0);
class_addmethod(sigbiquad_class, (t_method)sigbiquad_set, gensym("clear"),
- A_GIMME, 0);
+ A_GIMME, 0);
}
/* ---------------- samphold~ - sample and hold ----------------- */
@@ -476,7 +476,7 @@ static void *sigsamphold_new(void)
{
t_sigsamphold *x = (t_sigsamphold *)pd_new(sigsamphold_class);
inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_signal, &s_signal);
- outlet_new(&x->x_obj, gensym("signal"));
+ outlet_new(&x->x_obj, &s_signal);
x->x_lastin = 0;
x->x_lastout = 0;
x->x_f = 0;
@@ -495,10 +495,10 @@ static t_int *sigsamphold_perform(t_int *w)
float lastout = x->x_lastout;
for (i = 0; i < n; i++, *in1++)
{
- float next = *in2++;
- if (next < lastin) lastout = *in1;
- *out++ = lastout;
- lastin = next;
+ float next = *in2++;
+ if (next < lastin) lastout = *in1;
+ *out++ = lastout;
+ lastin = next;
}
x->x_lastin = lastin;
x->x_lastout = lastout;
@@ -508,8 +508,8 @@ static t_int *sigsamphold_perform(t_int *w)
static void sigsamphold_dsp(t_sigsamphold *x, t_signal **sp)
{
dsp_add(sigsamphold_perform, 5,
- sp[0]->s_vec, sp[1]->s_vec, sp[2]->s_vec,
- x, sp[0]->s_n);
+ sp[0]->s_vec, sp[1]->s_vec, sp[2]->s_vec,
+ x, sp[0]->s_n);
}
static void sigsamphold_reset(t_sigsamphold *x)
@@ -525,14 +525,496 @@ static void sigsamphold_set(t_sigsamphold *x, t_float f)
void sigsamphold_setup(void)
{
sigsamphold_class = class_new(gensym("samphold~"),
- (t_newmethod)sigsamphold_new, 0, sizeof(t_sigsamphold), 0, 0);
+ (t_newmethod)sigsamphold_new, 0, sizeof(t_sigsamphold), 0, 0);
CLASS_MAINSIGNALIN(sigsamphold_class, t_sigsamphold, x_f);
class_addmethod(sigsamphold_class, (t_method)sigsamphold_set,
- gensym("set"), A_FLOAT, 0);
+ gensym("set"), A_DEFFLOAT, 0);
class_addmethod(sigsamphold_class, (t_method)sigsamphold_reset,
- gensym("reset"), 0);
+ gensym("reset"), 0);
class_addmethod(sigsamphold_class, (t_method)sigsamphold_dsp,
- gensym("dsp"), 0);
+ gensym("dsp"), 0);
+}
+
+/* ---------------- rpole~ - real one-pole filter (raw) ----------------- */
+
+typedef struct sigrpole
+{
+ t_object x_obj;
+ float x_f;
+ float x_last;
+} t_sigrpole;
+
+t_class *sigrpole_class;
+
+static void *sigrpole_new(t_float f)
+{
+ t_sigrpole *x = (t_sigrpole *)pd_new(sigrpole_class);
+ inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_signal, &s_signal);
+ outlet_new(&x->x_obj, &s_signal);
+ x->x_last = 0;
+ x->x_f = f;
+ return (x);
+}
+
+static t_int *sigrpole_perform(t_int *w)
+{
+ float *in1 = (float *)(w[1]);
+ float *in2 = (float *)(w[2]);
+ float *out = (float *)(w[3]);
+ t_sigrpole *x = (t_sigrpole *)(w[4]);
+ int n = (t_int)(w[5]);
+ int i;
+ float last = x->x_last;
+ for (i = 0; i < n; i++)
+ {
+ float next = *in1++;
+ float coef = *in2++;
+ *out++ = last = coef * last + next;
+ }
+ x->x_last = last;
+ return (w+6);
+}
+
+static void sigrpole_dsp(t_sigrpole *x, t_signal **sp)
+{
+ dsp_add(sigrpole_perform, 5,
+ sp[0]->s_vec, sp[1]->s_vec, sp[2]->s_vec,
+ x, sp[0]->s_n);
+}
+
+static void sigrpole_clear(t_sigrpole *x)
+{
+ x->x_last = 0;
+}
+
+static void sigrpole_set(t_sigrpole *x, t_float f)
+{
+ x->x_last = f;
+}
+
+void sigrpole_setup(void)
+{
+ sigrpole_class = class_new(gensym("rpole~"),
+ (t_newmethod)sigrpole_new, 0, sizeof(t_sigrpole), 0, A_DEFFLOAT, 0);
+ CLASS_MAINSIGNALIN(sigrpole_class, t_sigrpole, x_f);
+ class_addmethod(sigrpole_class, (t_method)sigrpole_set,
+ gensym("set"), A_DEFFLOAT, 0);
+ class_addmethod(sigrpole_class, (t_method)sigrpole_clear,
+ gensym("clear"), 0);
+ class_addmethod(sigrpole_class, (t_method)sigrpole_dsp,
+ gensym("dsp"), 0);
+}
+
+/* ---------------- rzero~ - real one-zero filter (raw) ----------------- */
+
+typedef struct sigrzero
+{
+ t_object x_obj;
+ float x_f;
+ float x_last;
+} t_sigrzero;
+
+t_class *sigrzero_class;
+
+static void *sigrzero_new(t_float f)
+{
+ t_sigrzero *x = (t_sigrzero *)pd_new(sigrzero_class);
+ inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_signal, &s_signal);
+ outlet_new(&x->x_obj, &s_signal);
+ x->x_last = 0;
+ x->x_f = f;
+ return (x);
+}
+
+static t_int *sigrzero_perform(t_int *w)
+{
+ float *in1 = (float *)(w[1]);
+ float *in2 = (float *)(w[2]);
+ float *out = (float *)(w[3]);
+ t_sigrzero *x = (t_sigrzero *)(w[4]);
+ int n = (t_int)(w[5]);
+ int i;
+ float last = x->x_last;
+ for (i = 0; i < n; i++)
+ {
+ float next = *in1++;
+ float coef = *in2++;
+ *out++ = next - coef * last;
+ last = next;
+ }
+ x->x_last = last;
+ return (w+6);
+}
+
+static void sigrzero_dsp(t_sigrzero *x, t_signal **sp)
+{
+ dsp_add(sigrzero_perform, 5,
+ sp[0]->s_vec, sp[1]->s_vec, sp[2]->s_vec,
+ x, sp[0]->s_n);
+}
+
+static void sigrzero_clear(t_sigrzero *x)
+{
+ x->x_last = 0;
+}
+
+static void sigrzero_set(t_sigrzero *x, t_float f)
+{
+ x->x_last = f;
+}
+
+void sigrzero_setup(void)
+{
+ sigrzero_class = class_new(gensym("rzero~"),
+ (t_newmethod)sigrzero_new, 0, sizeof(t_sigrzero), 0, A_DEFFLOAT, 0);
+ CLASS_MAINSIGNALIN(sigrzero_class, t_sigrzero, x_f);
+ class_addmethod(sigrzero_class, (t_method)sigrzero_set,
+ gensym("set"), A_DEFFLOAT, 0);
+ class_addmethod(sigrzero_class, (t_method)sigrzero_clear,
+ gensym("clear"), 0);
+ class_addmethod(sigrzero_class, (t_method)sigrzero_dsp,
+ gensym("dsp"), 0);
+}
+
+/* ---------- rzero_rev~ - real, reverse one-zero filter (raw) ------------ */
+
+typedef struct sigrzero_rev
+{
+ t_object x_obj;
+ float x_f;
+ float x_last;
+} t_sigrzero_rev;
+
+t_class *sigrzero_rev_class;
+
+static void *sigrzero_rev_new(t_float f)
+{
+ t_sigrzero_rev *x = (t_sigrzero_rev *)pd_new(sigrzero_rev_class);
+ inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_signal, &s_signal);
+ outlet_new(&x->x_obj, &s_signal);
+ x->x_last = 0;
+ x->x_f = f;
+ return (x);
+}
+
+static t_int *sigrzero_rev_perform(t_int *w)
+{
+ float *in1 = (float *)(w[1]);
+ float *in2 = (float *)(w[2]);
+ float *out = (float *)(w[3]);
+ t_sigrzero_rev *x = (t_sigrzero_rev *)(w[4]);
+ int n = (t_int)(w[5]);
+ int i;
+ float last = x->x_last;
+ for (i = 0; i < n; i++)
+ {
+ float next = *in1++;
+ float coef = *in2++;
+ *out++ = last - coef * next;
+ last = next;
+ }
+ x->x_last = last;
+ return (w+6);
+}
+
+static void sigrzero_rev_dsp(t_sigrzero_rev *x, t_signal **sp)
+{
+ dsp_add(sigrzero_rev_perform, 5,
+ sp[0]->s_vec, sp[1]->s_vec, sp[2]->s_vec,
+ x, sp[0]->s_n);
+}
+
+static void sigrzero_rev_clear(t_sigrzero_rev *x)
+{
+ x->x_last = 0;
+}
+
+static void sigrzero_rev_set(t_sigrzero_rev *x, t_float f)
+{
+ x->x_last = f;
+}
+
+void sigrzero_rev_setup(void)
+{
+ sigrzero_rev_class = class_new(gensym("rzero_rev~"),
+ (t_newmethod)sigrzero_rev_new, 0, sizeof(t_sigrzero_rev),
+ 0, A_DEFFLOAT, 0);
+ CLASS_MAINSIGNALIN(sigrzero_rev_class, t_sigrzero_rev, x_f);
+ class_addmethod(sigrzero_rev_class, (t_method)sigrzero_rev_set,
+ gensym("set"), A_DEFFLOAT, 0);
+ class_addmethod(sigrzero_rev_class, (t_method)sigrzero_rev_clear,
+ gensym("clear"), 0);
+ class_addmethod(sigrzero_rev_class, (t_method)sigrzero_rev_dsp,
+ gensym("dsp"), 0);
+}
+
+/* -------------- cpole~ - complex one-pole filter (raw) --------------- */
+
+typedef struct sigcpole
+{
+ t_object x_obj;
+ float x_f;
+ float x_lastre;
+ float x_lastim;
+} t_sigcpole;
+
+t_class *sigcpole_class;
+
+static void *sigcpole_new(t_float re, t_float im)
+{
+ t_sigcpole *x = (t_sigcpole *)pd_new(sigcpole_class);
+ inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_signal, &s_signal);
+ pd_float(
+ (t_pd *)inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_signal, &s_signal),
+ re);
+ pd_float(
+ (t_pd *)inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_signal, &s_signal),
+ im);
+ outlet_new(&x->x_obj, &s_signal);
+ outlet_new(&x->x_obj, &s_signal);
+ x->x_lastre = x->x_lastim = 0;
+ x->x_f = 0;
+ return (x);
+}
+
+static t_int *sigcpole_perform(t_int *w)
+{
+ float *inre1 = (float *)(w[1]);
+ float *inim1 = (float *)(w[2]);
+ float *inre2 = (float *)(w[3]);
+ float *inim2 = (float *)(w[4]);
+ float *outre = (float *)(w[5]);
+ float *outim = (float *)(w[6]);
+ t_sigcpole *x = (t_sigcpole *)(w[7]);
+ int n = (t_int)(w[8]);
+ int i;
+ float lastre = x->x_lastre;
+ float lastim = x->x_lastim;
+ for (i = 0; i < n; i++)
+ {
+ float nextre = *inre1++;
+ float nextim = *inim1++;
+ float coefre = *inre2++;
+ float coefim = *inim2++;
+ float tempre = *outre++ = nextre + lastre * coefre - lastim * coefim;
+ lastim = *outim++ = nextim + lastre * coefim + lastim * coefre;
+ lastre = tempre;
+ }
+ x->x_lastre = lastre;
+ x->x_lastim = lastim;
+ return (w+9);
+}
+
+static void sigcpole_dsp(t_sigcpole *x, t_signal **sp)
+{
+ dsp_add(sigcpole_perform, 8,
+ sp[0]->s_vec, sp[1]->s_vec, sp[2]->s_vec, sp[3]->s_vec,
+ sp[4]->s_vec, sp[5]->s_vec, x, sp[0]->s_n);
+}
+
+static void sigcpole_clear(t_sigcpole *x)
+{
+ x->x_lastre = x->x_lastim = 0;
+}
+
+static void sigcpole_set(t_sigcpole *x, t_float re, t_float im)
+{
+ x->x_lastre = re;
+ x->x_lastim = im;
+}
+
+void sigcpole_setup(void)
+{
+ sigcpole_class = class_new(gensym("cpole~"),
+ (t_newmethod)sigcpole_new, 0, sizeof(t_sigcpole), 0,
+ A_DEFFLOAT, A_DEFFLOAT, 0);
+ CLASS_MAINSIGNALIN(sigcpole_class, t_sigcpole, x_f);
+ class_addmethod(sigcpole_class, (t_method)sigcpole_set,
+ gensym("set"), A_DEFFLOAT, A_DEFFLOAT, 0);
+ class_addmethod(sigcpole_class, (t_method)sigcpole_clear,
+ gensym("clear"), 0);
+ class_addmethod(sigcpole_class, (t_method)sigcpole_dsp,
+ gensym("dsp"), 0);
+}
+
+/* -------------- czero~ - complex one-pole filter (raw) --------------- */
+
+typedef struct sigczero
+{
+ t_object x_obj;
+ float x_f;
+ float x_lastre;
+ float x_lastim;
+} t_sigczero;
+
+t_class *sigczero_class;
+
+static void *sigczero_new(t_float re, t_float im)
+{
+ t_sigczero *x = (t_sigczero *)pd_new(sigczero_class);
+ inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_signal, &s_signal);
+ pd_float(
+ (t_pd *)inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_signal, &s_signal),
+ re);
+ pd_float(
+ (t_pd *)inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_signal, &s_signal),
+ im);
+ outlet_new(&x->x_obj, &s_signal);
+ outlet_new(&x->x_obj, &s_signal);
+ x->x_lastre = x->x_lastim = 0;
+ x->x_f = 0;
+ return (x);
+}
+
+static t_int *sigczero_perform(t_int *w)
+{
+ float *inre1 = (float *)(w[1]);
+ float *inim1 = (float *)(w[2]);
+ float *inre2 = (float *)(w[3]);
+ float *inim2 = (float *)(w[4]);
+ float *outre = (float *)(w[5]);
+ float *outim = (float *)(w[6]);
+ t_sigczero *x = (t_sigczero *)(w[7]);
+ int n = (t_int)(w[8]);
+ int i;
+ float lastre = x->x_lastre;
+ float lastim = x->x_lastim;
+ for (i = 0; i < n; i++)
+ {
+ float nextre = *inre1++;
+ float nextim = *inim1++;
+ float coefre = *inre2++;
+ float coefim = *inim2++;
+ *outre++ = nextre - lastre * coefre + lastim * coefim;
+ *outim++ = nextim - lastre * coefim - lastim * coefre;
+ lastre = nextre;
+ lastim = nextim;
+ }
+ x->x_lastre = lastre;
+ x->x_lastim = lastim;
+ return (w+9);
+}
+
+static void sigczero_dsp(t_sigczero *x, t_signal **sp)
+{
+ dsp_add(sigczero_perform, 8,
+ sp[0]->s_vec, sp[1]->s_vec, sp[2]->s_vec, sp[3]->s_vec,
+ sp[4]->s_vec, sp[5]->s_vec, x, sp[0]->s_n);
+}
+
+static void sigczero_clear(t_sigczero *x)
+{
+ x->x_lastre = x->x_lastim = 0;
+}
+
+static void sigczero_set(t_sigczero *x, t_float re, t_float im)
+{
+ x->x_lastre = re;
+ x->x_lastim = im;
+}
+
+void sigczero_setup(void)
+{
+ sigczero_class = class_new(gensym("czero~"),
+ (t_newmethod)sigczero_new, 0, sizeof(t_sigczero), 0,
+ A_DEFFLOAT, A_DEFFLOAT, 0);
+ CLASS_MAINSIGNALIN(sigczero_class, t_sigczero, x_f);
+ class_addmethod(sigczero_class, (t_method)sigczero_set,
+ gensym("set"), A_DEFFLOAT, A_DEFFLOAT, 0);
+ class_addmethod(sigczero_class, (t_method)sigczero_clear,
+ gensym("clear"), 0);
+ class_addmethod(sigczero_class, (t_method)sigczero_dsp,
+ gensym("dsp"), 0);
+}
+
+/* -------------- czero_rev~ - complex one-pole filter (raw) --------------- */
+
+typedef struct sigczero_rev
+{
+ t_object x_obj;
+ float x_f;
+ float x_lastre;
+ float x_lastim;
+} t_sigczero_rev;
+
+t_class *sigczero_rev_class;
+
+static void *sigczero_rev_new(t_float re, t_float im)
+{
+ t_sigczero_rev *x = (t_sigczero_rev *)pd_new(sigczero_rev_class);
+ inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_signal, &s_signal);
+ pd_float(
+ (t_pd *)inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_signal, &s_signal),
+ re);
+ pd_float(
+ (t_pd *)inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_signal, &s_signal),
+ im);
+ outlet_new(&x->x_obj, &s_signal);
+ outlet_new(&x->x_obj, &s_signal);
+ x->x_lastre = x->x_lastim = 0;
+ x->x_f = 0;
+ return (x);
+}
+
+static t_int *sigczero_rev_perform(t_int *w)
+{
+ float *inre1 = (float *)(w[1]);
+ float *inim1 = (float *)(w[2]);
+ float *inre2 = (float *)(w[3]);
+ float *inim2 = (float *)(w[4]);
+ float *outre = (float *)(w[5]);
+ float *outim = (float *)(w[6]);
+ t_sigczero_rev *x = (t_sigczero_rev *)(w[7]);
+ int n = (t_int)(w[8]);
+ int i;
+ float lastre = x->x_lastre;
+ float lastim = x->x_lastim;
+ for (i = 0; i < n; i++)
+ {
+ float nextre = *inre1++;
+ float nextim = *inim1++;
+ float coefre = *inre2++;
+ float coefim = *inim2++;
+ *outre++ = lastre - nextre * coefre + nextim * coefim;
+ *outim++ = lastim - nextre * coefim - nextim * coefre;
+ lastre = nextre;
+ lastim = nextim;
+ }
+ x->x_lastre = lastre;
+ x->x_lastim = lastim;
+ return (w+9);
+}
+
+static void sigczero_rev_dsp(t_sigczero_rev *x, t_signal **sp)
+{
+ dsp_add(sigczero_rev_perform, 8,
+ sp[0]->s_vec, sp[1]->s_vec, sp[2]->s_vec, sp[3]->s_vec,
+ sp[4]->s_vec, sp[5]->s_vec, x, sp[0]->s_n);
+}
+
+static void sigczero_rev_clear(t_sigczero_rev *x)
+{
+ x->x_lastre = x->x_lastim = 0;
+}
+
+static void sigczero_rev_set(t_sigczero_rev *x, t_float re, t_float im)
+{
+ x->x_lastre = re;
+ x->x_lastim = im;
+}
+
+void sigczero_rev_setup(void)
+{
+ sigczero_rev_class = class_new(gensym("czero_rev~"),
+ (t_newmethod)sigczero_rev_new, 0, sizeof(t_sigczero_rev), 0,
+ A_DEFFLOAT, A_DEFFLOAT, 0);
+ CLASS_MAINSIGNALIN(sigczero_rev_class, t_sigczero_rev, x_f);
+ class_addmethod(sigczero_rev_class, (t_method)sigczero_rev_set,
+ gensym("set"), A_DEFFLOAT, A_DEFFLOAT, 0);
+ class_addmethod(sigczero_rev_class, (t_method)sigczero_rev_clear,
+ gensym("clear"), 0);
+ class_addmethod(sigczero_rev_class, (t_method)sigczero_rev_dsp,
+ gensym("dsp"), 0);
}
/* ------------------------ setup routine ------------------------- */
@@ -544,4 +1026,10 @@ void d_filter_setup(void)
sigbp_setup();
sigbiquad_setup();
sigsamphold_setup();
+ sigrpole_setup();
+ sigrzero_setup();
+ sigrzero_rev_setup();
+ sigcpole_setup();
+ sigczero_setup();
+ sigczero_rev_setup();
}
diff --git a/pd/src/d_global.c b/pd/src/d_global.c
index d764ee1b..ea6615be 100644
--- a/pd/src/d_global.c
+++ b/pd/src/d_global.c
@@ -7,7 +7,7 @@
#include "m_pd.h"
#include <string.h>
-#define DEFSENDVS 64 /* LATER get send to get this from canvas */
+#define DEFSENDVS 64 /* LATER get send to get this from canvas */
/* ----------------------------- send~ ----------------------------- */
static t_class *sigsend_class;
@@ -40,9 +40,9 @@ static t_int *sigsend_perform(t_int *w)
int n = (int)(w[3]);
while (n--)
{
- *out = (PD_BADFLOAT(*in) ? 0 : *in);
- out++;
- in++;
+ *out = (PD_BIGORSMALL(*in) ? 0 : *in);
+ out++;
+ in++;
}
return (w+4);
}
@@ -50,7 +50,7 @@ static t_int *sigsend_perform(t_int *w)
static void sigsend_dsp(t_sigsend *x, t_signal **sp)
{
if (x->x_n == sp[0]->s_n)
- dsp_add(sigsend_perform, 3, sp[0]->s_vec, x->x_vec, sp[0]->s_n);
+ dsp_add(sigsend_perform, 3, sp[0]->s_vec, x->x_vec, sp[0]->s_n);
else error("sigsend %s: unexpected vector size", x->x_sym->s_name);
}
@@ -63,7 +63,7 @@ static void sigsend_free(t_sigsend *x)
static void sigsend_setup(void)
{
sigsend_class = class_new(gensym("send~"), (t_newmethod)sigsend_new,
- (t_method)sigsend_free, sizeof(t_sigsend), 0, A_DEFSYM, 0);
+ (t_method)sigsend_free, sizeof(t_sigsend), 0, A_DEFSYM, 0);
class_addcreator((t_newmethod)sigsend_new, gensym("s~"), A_DEFSYM, 0);
CLASS_MAINSIGNALIN(sigsend_class, t_sigsend, x_f);
class_addmethod(sigsend_class, (t_method)sigsend_dsp, gensym("dsp"), 0);
@@ -83,7 +83,7 @@ typedef struct _sigreceive
static void *sigreceive_new(t_symbol *s)
{
t_sigreceive *x = (t_sigreceive *)pd_new(sigreceive_class);
- x->x_n = DEFSENDVS; /* LATER find our vector size correctly */
+ x->x_n = DEFSENDVS; /* LATER find our vector size correctly */
x->x_sym = s;
x->x_wherefrom = 0;
outlet_new(&x->x_obj, &s_signal);
@@ -98,13 +98,39 @@ static t_int *sigreceive_perform(t_int *w)
t_float *in = x->x_wherefrom;
if (in)
{
- while (n--)
- *out++ = *in++;
+ while (n--)
+ *out++ = *in++;
}
else
{
- while (n--)
- *out++ = 0;
+ while (n--)
+ *out++ = 0;
+ }
+ return (w+4);
+}
+
+/* tb: vectorized receive function */
+static t_int *sigreceive_perf8(t_int *w)
+{
+ t_sigreceive *x = (t_sigreceive *)(w[1]);
+ t_float *out = (t_float *)(w[2]);
+ int n = (int)(w[3]);
+ t_float *in = x->x_wherefrom;
+ if (in)
+ {
+ for (; n; n -= 8, in += 8, out += 8)
+ {
+ out[0] = in[0]; out[1] = in[1]; out[2] = in[2]; out[3] = in[3];
+ out[4] = in[4]; out[5] = in[5]; out[6] = in[6]; out[7] = in[7];
+ }
+ }
+ else
+ {
+ for (; n; n -= 8, in += 8, out += 8)
+ {
+ out[0] = 0; out[1] = 0; out[2] = 0; out[3] = 0;
+ out[4] = 0; out[5] = 0; out[6] = 0; out[7] = 0;
+ }
}
return (w+4);
}
@@ -112,21 +138,21 @@ static t_int *sigreceive_perform(t_int *w)
static void sigreceive_set(t_sigreceive *x, t_symbol *s)
{
t_sigsend *sender = (t_sigsend *)pd_findbyclass((x->x_sym = s),
- sigsend_class);
+ sigsend_class);
if (sender)
{
- if (sender->x_n == x->x_n)
- x->x_wherefrom = sender->x_vec;
- else
- {
- pd_error(x, "receive~ %s: vector size mismatch", x->x_sym->s_name);
- x->x_wherefrom = 0;
- }
+ if (sender->x_n == x->x_n)
+ x->x_wherefrom = sender->x_vec;
+ else
+ {
+ pd_error(x, "receive~ %s: vector size mismatch", x->x_sym->s_name);
+ x->x_wherefrom = 0;
+ }
}
else
{
- pd_error(x, "receive~ %s: no matching send", x->x_sym->s_name);
- x->x_wherefrom = 0;
+ pd_error(x, "receive~ %s: no matching send", x->x_sym->s_name);
+ x->x_wherefrom = 0;
}
}
@@ -134,26 +160,29 @@ static void sigreceive_dsp(t_sigreceive *x, t_signal **sp)
{
if (sp[0]->s_n != x->x_n)
{
- pd_error(x, "receive~ %s: vector size mismatch", x->x_sym->s_name);
+ pd_error(x, "receive~ %s: vector size mismatch", x->x_sym->s_name);
}
else
{
- sigreceive_set(x, x->x_sym);
- dsp_add(sigreceive_perform, 3,
- x, sp[0]->s_vec, sp[0]->s_n);
+ sigreceive_set(x, x->x_sym);
+ if (sp[0]->s_n&7)
+ dsp_add(sigreceive_perform, 3,
+ x, sp[0]->s_vec, sp[0]->s_n);
+ else dsp_add(sigreceive_perf8, 3,
+ x, sp[0]->s_vec, sp[0]->s_n);
}
}
static void sigreceive_setup(void)
{
sigreceive_class = class_new(gensym("receive~"),
- (t_newmethod)sigreceive_new, 0,
- sizeof(t_sigreceive), 0, A_DEFSYM, 0);
+ (t_newmethod)sigreceive_new, 0,
+ sizeof(t_sigreceive), 0, A_DEFSYM, 0);
class_addcreator((t_newmethod)sigreceive_new, gensym("r~"), A_DEFSYM, 0);
class_addmethod(sigreceive_class, (t_method)sigreceive_set, gensym("set"),
- A_SYMBOL, 0);
+ A_SYMBOL, 0);
class_addmethod(sigreceive_class, (t_method)sigreceive_dsp, gensym("dsp"),
- 0);
+ 0);
class_sethelpsymbol(sigreceive_class, gensym("send~"));
}
@@ -189,10 +218,32 @@ static t_int *sigcatch_perform(t_int *w)
return (w+4);
}
+/* tb: vectorized catch function */
+static t_int *sigcatch_perf8(t_int *w)
+{
+ t_float *in = (t_float *)(w[1]);
+ t_float *out = (t_float *)(w[2]);
+ int n = (int)(w[3]);
+ for (; n; n -= 8, in += 8, out += 8)
+ {
+ out[0] = in[0]; out[1] = in[1]; out[2] = in[2]; out[3] = in[3];
+ out[4] = in[4]; out[5] = in[5]; out[6] = in[6]; out[7] = in[7];
+
+ in[0] = 0; in[1] = 0; in[2] = 0; in[3] = 0;
+ in[4] = 0; in[5] = 0; in[6] = 0; in[7] = 0;
+ }
+ return (w+4);
+}
+
static void sigcatch_dsp(t_sigcatch *x, t_signal **sp)
{
if (x->x_n == sp[0]->s_n)
- dsp_add(sigcatch_perform, 3, x->x_vec, sp[0]->s_vec, sp[0]->s_n);
+ {
+ if(sp[0]->s_n&7)
+ dsp_add(sigcatch_perform, 3, x->x_vec, sp[0]->s_vec, sp[0]->s_n);
+ else
+ dsp_add(sigcatch_perf8, 3, x->x_vec, sp[0]->s_vec, sp[0]->s_n);
+ }
else error("sigcatch %s: unexpected vector size", x->x_sym->s_name);
}
@@ -205,7 +256,7 @@ static void sigcatch_free(t_sigcatch *x)
static void sigcatch_setup(void)
{
sigcatch_class = class_new(gensym("catch~"), (t_newmethod)sigcatch_new,
- (t_method)sigcatch_free, sizeof(t_sigcatch), CLASS_NOINLET, A_DEFSYM, 0);
+ (t_method)sigcatch_free, sizeof(t_sigcatch), CLASS_NOINLET, A_DEFSYM, 0);
class_addmethod(sigcatch_class, (t_method)sigcatch_dsp, gensym("dsp"), 0);
class_sethelpsymbol(sigcatch_class, gensym("throw~"));
}
@@ -240,12 +291,12 @@ static t_int *sigthrow_perform(t_int *w)
t_float *out = x->x_whereto;
if (out)
{
- while (n--)
- {
- *out += (PD_BADFLOAT(*in) ? 0 : *in);
- out++;
- in++;
- }
+ while (n--)
+ {
+ *out += (PD_BIGORSMALL(*in) ? 0 : *in);
+ out++;
+ in++;
+ }
}
return (w+4);
}
@@ -253,21 +304,21 @@ static t_int *sigthrow_perform(t_int *w)
static void sigthrow_set(t_sigthrow *x, t_symbol *s)
{
t_sigcatch *catcher = (t_sigcatch *)pd_findbyclass((x->x_sym = s),
- sigcatch_class);
+ sigcatch_class);
if (catcher)
{
- if (catcher->x_n == x->x_n)
- x->x_whereto = catcher->x_vec;
- else
- {
- pd_error(x, "throw~ %s: vector size mismatch", x->x_sym->s_name);
- x->x_whereto = 0;
- }
+ if (catcher->x_n == x->x_n)
+ x->x_whereto = catcher->x_vec;
+ else
+ {
+ pd_error(x, "throw~ %s: vector size mismatch", x->x_sym->s_name);
+ x->x_whereto = 0;
+ }
}
else
{
- pd_error(x, "throw~ %s: no matching catch", x->x_sym->s_name);
- x->x_whereto = 0;
+ pd_error(x, "throw~ %s: no matching catch", x->x_sym->s_name);
+ x->x_whereto = 0;
}
}
@@ -275,23 +326,22 @@ static void sigthrow_dsp(t_sigthrow *x, t_signal **sp)
{
if (sp[0]->s_n != x->x_n)
{
- pd_error(x, "throw~ %s: vector size mismatch", x->x_sym->s_name);
+ pd_error(x, "throw~ %s: vector size mismatch", x->x_sym->s_name);
}
else
{
- sigthrow_set(x, x->x_sym);
- dsp_add(sigthrow_perform, 3,
- x, sp[0]->s_vec, sp[0]->s_n);
+ sigthrow_set(x, x->x_sym);
+ dsp_add(sigthrow_perform, 3,
+ x, sp[0]->s_vec, sp[0]->s_n);
}
}
static void sigthrow_setup(void)
{
sigthrow_class = class_new(gensym("throw~"), (t_newmethod)sigthrow_new, 0,
- sizeof(t_sigthrow), 0, A_DEFSYM, 0);
- class_addcreator((t_newmethod)sigthrow_new, gensym("r~"), A_DEFSYM, 0);
+ sizeof(t_sigthrow), 0, A_DEFSYM, 0);
class_addmethod(sigthrow_class, (t_method)sigthrow_set, gensym("set"),
- A_SYMBOL, 0);
+ A_SYMBOL, 0);
CLASS_MAINSIGNALIN(sigthrow_class, t_sigthrow, x_f);
class_addmethod(sigthrow_class, (t_method)sigthrow_dsp, gensym("dsp"), 0);
}
diff --git a/pd/src/d_math.c b/pd/src/d_math.c
index d64e2e34..e04a6738 100644
--- a/pd/src/d_math.c
+++ b/pd/src/d_math.c
@@ -41,10 +41,10 @@ static t_int *clip_perform(t_int *w)
int n = (int)(w[4]);
while (n--)
{
- float f = *in++;
- if (f < x->x_lo) f = x->x_lo;
- if (f > x->x_hi) f = x->x_hi;
- *out++ = f;
+ float f = *in++;
+ if (f < x->x_lo) f = x->x_lo;
+ if (f > x->x_hi) f = x->x_hi;
+ *out++ = f;
}
return (w+5);
}
@@ -57,7 +57,7 @@ static void clip_dsp(t_clip *x, t_signal **sp)
static void clip_setup(void)
{
clip_class = class_new(gensym("clip~"), (t_newmethod)clip_new, 0,
- sizeof(t_clip), 0, A_DEFFLOAT, A_DEFFLOAT, 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);
}
@@ -74,15 +74,15 @@ static void init_rsqrt(void)
int i;
for (i = 0; i < DUMTAB1SIZE; i++)
{
- float f;
- long l = (i ? (i == DUMTAB1SIZE-1 ? DUMTAB1SIZE-2 : i) : 1)<< 23;
- *(long *)(&f) = l;
- rsqrt_exptab[i] = 1./sqrt(f);
+ float f;
+ long l = (i ? (i == DUMTAB1SIZE-1 ? DUMTAB1SIZE-2 : i) : 1)<< 23;
+ *(long *)(&f) = l;
+ rsqrt_exptab[i] = 1./sqrt(f);
}
for (i = 0; i < DUMTAB2SIZE; i++)
{
- float f = 1 + (1./DUMTAB2SIZE) * i;
- rsqrt_mantissatab[i] = 1./sqrt(f);
+ float f = 1 + (1./DUMTAB2SIZE) * i;
+ rsqrt_mantissatab[i] = 1./sqrt(f);
}
}
@@ -93,7 +93,7 @@ float q8_rsqrt(float f)
long l = *(long *)(&f);
if (f < 0) return (0);
else return (rsqrt_exptab[(l >> 23) & 0xff] *
- rsqrt_mantissatab[(l >> 13) & 0x3ff]);
+ rsqrt_mantissatab[(l >> 13) & 0x3ff]);
}
float q8_sqrt(float f)
@@ -101,7 +101,7 @@ float q8_sqrt(float f)
long l = *(long *)(&f);
if (f < 0) return (0);
else return (f * rsqrt_exptab[(l >> 23) & 0xff] *
- rsqrt_mantissatab[(l >> 13) & 0x3ff]);
+ rsqrt_mantissatab[(l >> 13) & 0x3ff]);
}
/* the old names are OK unless we're in IRIX N32 */
@@ -134,16 +134,16 @@ static t_int *sigrsqrt_perform(t_int *w)
float *in = *(t_float **)(w+1), *out = *(t_float **)(w+2);
t_int n = *(t_int *)(w+3);
while (n--)
- {
- float f = *in;
- long l = *(long *)(in++);
- if (f < 0) *out++ = 0;
- else
- {
- float g = rsqrt_exptab[(l >> 23) & 0xff] *
- rsqrt_mantissatab[(l >> 13) & 0x3ff];
- *out++ = 1.5 * g - 0.5 * g * g * g * f;
- }
+ {
+ float f = *in;
+ long l = *(long *)(in++);
+ if (f < 0) *out++ = 0;
+ else
+ {
+ float g = rsqrt_exptab[(l >> 23) & 0xff] *
+ rsqrt_mantissatab[(l >> 13) & 0x3ff];
+ *out++ = 1.5 * g - 0.5 * g * g * g * f;
+ }
}
return (w + 4);
}
@@ -157,8 +157,8 @@ void sigrsqrt_setup(void)
{
init_rsqrt();
sigrsqrt_class = class_new(gensym("rsqrt~"), (t_newmethod)sigrsqrt_new, 0,
- sizeof(t_sigrsqrt), 0, 0);
- /* an old name for it: */
+ sizeof(t_sigrsqrt), 0, 0);
+ /* an old name for it: */
class_addcreator(sigrsqrt_new, gensym("q8_rsqrt~"), 0);
CLASS_MAINSIGNALIN(sigrsqrt_class, t_sigrsqrt, x_f);
class_addmethod(sigrsqrt_class, (t_method)sigrsqrt_dsp, gensym("dsp"), 0);
@@ -188,16 +188,16 @@ t_int *sigsqrt_perform(t_int *w) /* not static; also used in d_fft.c */
float *in = *(t_float **)(w+1), *out = *(t_float **)(w+2);
t_int n = *(t_int *)(w+3);
while (n--)
- {
- float f = *in;
- long l = *(long *)(in++);
- if (f < 0) *out++ = 0;
- else
- {
- float g = rsqrt_exptab[(l >> 23) & 0xff] *
- rsqrt_mantissatab[(l >> 13) & 0x3ff];
- *out++ = f * (1.5 * g - 0.5 * g * g * g * f);
- }
+ {
+ float f = *in;
+ long l = *(long *)(in++);
+ if (f < 0) *out++ = 0;
+ else
+ {
+ float g = rsqrt_exptab[(l >> 23) & 0xff] *
+ rsqrt_mantissatab[(l >> 13) & 0x3ff];
+ *out++ = f * (1.5 * g - 0.5 * g * g * g * f);
+ }
}
return (w + 4);
}
@@ -210,7 +210,7 @@ static void sigsqrt_dsp(t_sigsqrt *x, t_signal **sp)
void sigsqrt_setup(void)
{
sigsqrt_class = class_new(gensym("sqrt~"), (t_newmethod)sigsqrt_new, 0,
- sizeof(t_sigsqrt), 0, 0);
+ sizeof(t_sigsqrt), 0, 0);
class_addcreator(sigsqrt_new, gensym("q8_sqrt~"), 0); /* old name */
CLASS_MAINSIGNALIN(sigsqrt_class, t_sigsqrt, x_f);
class_addmethod(sigsqrt_class, (t_method)sigsqrt_dsp, gensym("dsp"), 0);
@@ -239,11 +239,11 @@ static t_int *sigwrap_perform(t_int *w)
float *in = *(t_float **)(w+1), *out = *(t_float **)(w+2);
t_int n = *(t_int *)(w+3);
while (n--)
- {
- float f = *in++;
- int k = f;
- if (f > 0) *out++ = f-k;
- else *out++ = f - (k-1);
+ {
+ float f = *in++;
+ int k = f;
+ if (f > 0) *out++ = f-k;
+ else *out++ = f - (k-1);
}
return (w + 4);
}
@@ -256,7 +256,7 @@ static void sigwrap_dsp(t_sigwrap *x, t_signal **sp)
void sigwrap_setup(void)
{
sigwrap_class = class_new(gensym("wrap~"), (t_newmethod)sigwrap_new, 0,
- sizeof(t_sigwrap), 0, 0);
+ sizeof(t_sigwrap), 0, 0);
CLASS_MAINSIGNALIN(sigwrap_class, t_sigwrap, x_f);
class_addmethod(sigwrap_class, (t_method)sigwrap_dsp, gensym("dsp"), 0);
}
@@ -285,13 +285,13 @@ static t_int *mtof_tilde_perform(t_int *w)
t_int n = *(t_int *)(w+3);
for (; n--; in++, out++)
{
- float f = *in;
- if (f <= -1500) *out = 0;
- else
- {
- if (f > 1499) f = 1499;
- *out = 8.17579891564 * exp(.0577622650 * f);
- }
+ float f = *in;
+ if (f <= -1500) *out = 0;
+ else
+ {
+ if (f > 1499) f = 1499;
+ *out = 8.17579891564 * exp(.0577622650 * f);
+ }
}
return (w + 4);
}
@@ -304,7 +304,7 @@ static void mtof_tilde_dsp(t_mtof_tilde *x, t_signal **sp)
void mtof_tilde_setup(void)
{
mtof_tilde_class = class_new(gensym("mtof~"), (t_newmethod)mtof_tilde_new, 0,
- sizeof(t_mtof_tilde), 0, 0);
+ sizeof(t_mtof_tilde), 0, 0);
CLASS_MAINSIGNALIN(mtof_tilde_class, t_mtof_tilde, x_f);
class_addmethod(mtof_tilde_class, (t_method)mtof_tilde_dsp, gensym("dsp"), 0);
}
@@ -333,8 +333,8 @@ static t_int *ftom_tilde_perform(t_int *w)
t_int n = *(t_int *)(w+3);
for (; n--; *in++, out++)
{
- float f = *in;
- *out = (f > 0 ? 17.3123405046 * log(.12231220585 * f) : -1500);
+ float f = *in;
+ *out = (f > 0 ? 17.3123405046 * log(.12231220585 * f) : -1500);
}
return (w + 4);
}
@@ -347,7 +347,7 @@ static void ftom_tilde_dsp(t_ftom_tilde *x, t_signal **sp)
void ftom_tilde_setup(void)
{
ftom_tilde_class = class_new(gensym("ftom~"), (t_newmethod)ftom_tilde_new, 0,
- sizeof(t_ftom_tilde), 0, 0);
+ sizeof(t_ftom_tilde), 0, 0);
CLASS_MAINSIGNALIN(ftom_tilde_class, t_ftom_tilde, x_f);
class_addmethod(ftom_tilde_class, (t_method)ftom_tilde_dsp, gensym("dsp"), 0);
}
@@ -376,14 +376,14 @@ static t_int *dbtorms_tilde_perform(t_int *w)
t_int n = *(t_int *)(w+3);
for (; n--; in++, out++)
{
- float f = *in;
- if (f <= 0) *out = 0;
- else
- {
- if (f > 485)
- f = 485;
- *out = exp((LOGTEN * 0.05) * (f-100.));
- }
+ float f = *in;
+ if (f <= 0) *out = 0;
+ else
+ {
+ if (f > 485)
+ f = 485;
+ *out = exp((LOGTEN * 0.05) * (f-100.));
+ }
}
return (w + 4);
}
@@ -396,7 +396,7 @@ static void dbtorms_tilde_dsp(t_dbtorms_tilde *x, t_signal **sp)
void dbtorms_tilde_setup(void)
{
dbtorms_tilde_class = class_new(gensym("dbtorms~"), (t_newmethod)dbtorms_tilde_new, 0,
- sizeof(t_dbtorms_tilde), 0, 0);
+ sizeof(t_dbtorms_tilde), 0, 0);
CLASS_MAINSIGNALIN(dbtorms_tilde_class, t_dbtorms_tilde, x_f);
class_addmethod(dbtorms_tilde_class, (t_method)dbtorms_tilde_dsp, gensym("dsp"), 0);
}
@@ -425,13 +425,13 @@ static t_int *rmstodb_tilde_perform(t_int *w)
t_int n = *(t_int *)(w+3);
for (; n--; in++, out++)
{
- float f = *in;
- if (f <= 0) *out = 0;
- else
- {
- float g = 100 + 20./LOGTEN * log(f);
- *out = (g < 0 ? 0 : g);
- }
+ float f = *in;
+ if (f <= 0) *out = 0;
+ else
+ {
+ float g = 100 + 20./LOGTEN * log(f);
+ *out = (g < 0 ? 0 : g);
+ }
}
return (w + 4);
}
@@ -444,7 +444,7 @@ static void rmstodb_tilde_dsp(t_rmstodb_tilde *x, t_signal **sp)
void rmstodb_tilde_setup(void)
{
rmstodb_tilde_class = class_new(gensym("rmstodb~"), (t_newmethod)rmstodb_tilde_new, 0,
- sizeof(t_rmstodb_tilde), 0, 0);
+ sizeof(t_rmstodb_tilde), 0, 0);
CLASS_MAINSIGNALIN(rmstodb_tilde_class, t_rmstodb_tilde, x_f);
class_addmethod(rmstodb_tilde_class, (t_method)rmstodb_tilde_dsp, gensym("dsp"), 0);
}
@@ -473,14 +473,14 @@ static t_int *dbtopow_tilde_perform(t_int *w)
t_int n = *(t_int *)(w+3);
for (; n--; in++, out++)
{
- float f = *in;
- if (f <= 0) *out = 0;
- else
- {
- if (f > 870)
- f = 870;
- *out = exp((LOGTEN * 0.1) * (f-100.));
- }
+ float f = *in;
+ if (f <= 0) *out = 0;
+ else
+ {
+ if (f > 870)
+ f = 870;
+ *out = exp((LOGTEN * 0.1) * (f-100.));
+ }
}
return (w + 4);
}
@@ -493,7 +493,7 @@ static void dbtopow_tilde_dsp(t_dbtopow_tilde *x, t_signal **sp)
void dbtopow_tilde_setup(void)
{
dbtopow_tilde_class = class_new(gensym("dbtopow~"), (t_newmethod)dbtopow_tilde_new, 0,
- sizeof(t_dbtopow_tilde), 0, 0);
+ sizeof(t_dbtopow_tilde), 0, 0);
CLASS_MAINSIGNALIN(dbtopow_tilde_class, t_dbtopow_tilde, x_f);
class_addmethod(dbtopow_tilde_class, (t_method)dbtopow_tilde_dsp, gensym("dsp"), 0);
}
@@ -522,13 +522,13 @@ static t_int *powtodb_tilde_perform(t_int *w)
t_int n = *(t_int *)(w+3);
for (; n--; in++, out++)
{
- float f = *in;
- if (f <= 0) *out = 0;
- else
- {
- float g = 100 + 10./LOGTEN * log(f);
- *out = (g < 0 ? 0 : g);
- }
+ float f = *in;
+ if (f <= 0) *out = 0;
+ else
+ {
+ float g = 100 + 10./LOGTEN * log(f);
+ *out = (g < 0 ? 0 : g);
+ }
}
return (w + 4);
}
@@ -541,7 +541,7 @@ static void powtodb_tilde_dsp(t_powtodb_tilde *x, t_signal **sp)
void powtodb_tilde_setup(void)
{
powtodb_tilde_class = class_new(gensym("powtodb~"), (t_newmethod)powtodb_tilde_new, 0,
- sizeof(t_powtodb_tilde), 0, 0);
+ sizeof(t_powtodb_tilde), 0, 0);
CLASS_MAINSIGNALIN(powtodb_tilde_class, t_powtodb_tilde, x_f);
class_addmethod(powtodb_tilde_class, (t_method)powtodb_tilde_dsp, gensym("dsp"), 0);
}
diff --git a/pd/src/d_mayer_fft.c b/pd/src/d_mayer_fft.c
index ea884018..0e2242b7 100644
--- a/pd/src/d_mayer_fft.c
+++ b/pd/src/d_mayer_fft.c
@@ -64,29 +64,29 @@
#if defined(GOOD_TRIG)
#define FHT_SWAP(a,b,t) {(t)=(a);(a)=(b);(b)=(t);}
-#define TRIG_VARS \
+#define TRIG_VARS \
int t_lam=0;
-#define TRIG_INIT(k,c,s) \
- { \
- int i; \
- for (i=2 ; i<=k ; i++) \
- {coswrk[i]=costab[i];sinwrk[i]=sintab[i];} \
- t_lam = 0; \
- c = 1; \
- s = 0; \
+#define TRIG_INIT(k,c,s) \
+ { \
+ int i; \
+ for (i=2 ; i<=k ; i++) \
+ {coswrk[i]=costab[i];sinwrk[i]=sintab[i];} \
+ t_lam = 0; \
+ c = 1; \
+ s = 0; \
}
-#define TRIG_NEXT(k,c,s) \
- { \
- int i,j; \
- (t_lam)++; \
- for (i=0 ; !((1<<i)&t_lam) ; i++); \
- i = k-i; \
- s = sinwrk[i]; \
- c = coswrk[i]; \
- if (i>1) \
- { \
- for (j=k-i+2 ; (1<<j)&t_lam ; j++); \
- j = k - j; \
+#define TRIG_NEXT(k,c,s) \
+ { \
+ int i,j; \
+ (t_lam)++; \
+ for (i=0 ; !((1<<i)&t_lam) ; i++); \
+ i = k-i; \
+ s = sinwrk[i]; \
+ c = coswrk[i]; \
+ if (i>1) \
+ { \
+ for (j=k-i+2 ; (1<<j)&t_lam ; j++); \
+ j = k - j; \
sinwrk[i] = halsec[i] * (sinwrk[i-1] + sinwrk[j]); \
coswrk[i] = halsec[i] * (coswrk[i-1] + coswrk[j]); \
} \
@@ -95,20 +95,20 @@
#endif
#if defined(FAST_TRIG)
-#define TRIG_VARS \
+#define TRIG_VARS \
REAL t_c,t_s;
-#define TRIG_INIT(k,c,s) \
- { \
- t_c = costab[k]; \
- t_s = sintab[k]; \
- c = 1; \
- s = 0; \
+#define TRIG_INIT(k,c,s) \
+ { \
+ t_c = costab[k]; \
+ t_s = sintab[k]; \
+ c = 1; \
+ s = 0; \
}
-#define TRIG_NEXT(k,c,s) \
+#define TRIG_NEXT(k,c,s) \
{ \
REAL t = c; \
- c = t*t_c - s*t_s; \
- s = t*t_s + s*t_c; \
+ c = t*t_c - s*t_s; \
+ s = t*t_s + s*t_c; \
}
#define TRIG_RESET(k,c,s)
#endif
@@ -227,58 +227,58 @@ REAL c1,s1,s2,c2,s3,c3,s4,c4;
REAL aa;
for (k=n>>1; (!((k2^=k)&k)); k>>=1);
if (k1>k2)
- {
- aa=fz[k1];fz[k1]=fz[k2];fz[k2]=aa;
- }
+ {
+ aa=fz[k1];fz[k1]=fz[k2];fz[k2]=aa;
+ }
}
for ( k=0 ; (1<<k)<n ; k++ );
k &= 1;
if (k==0)
{
- for (fi=fz,fn=fz+n;fi<fn;fi+=4)
- {
- REAL f0,f1,f2,f3;
- f1 = fi[0 ]-fi[1 ];
- f0 = fi[0 ]+fi[1 ];
- f3 = fi[2 ]-fi[3 ];
- f2 = fi[2 ]+fi[3 ];
- fi[2 ] = (f0-f2);
- fi[0 ] = (f0+f2);
- fi[3 ] = (f1-f3);
- fi[1 ] = (f1+f3);
- }
+ for (fi=fz,fn=fz+n;fi<fn;fi+=4)
+ {
+ REAL f0,f1,f2,f3;
+ f1 = fi[0 ]-fi[1 ];
+ f0 = fi[0 ]+fi[1 ];
+ f3 = fi[2 ]-fi[3 ];
+ f2 = fi[2 ]+fi[3 ];
+ fi[2 ] = (f0-f2);
+ fi[0 ] = (f0+f2);
+ fi[3 ] = (f1-f3);
+ fi[1 ] = (f1+f3);
+ }
}
else
{
- for (fi=fz,fn=fz+n,gi=fi+1;fi<fn;fi+=8,gi+=8)
- {
- REAL bs1,bc1,bs2,bc2,bs3,bc3,bs4,bc4,
- bg0,bf0,bf1,bg1,bf2,bg2,bf3,bg3;
- bc1 = fi[0 ] - gi[0 ];
- bs1 = fi[0 ] + gi[0 ];
- bc2 = fi[2 ] - gi[2 ];
- bs2 = fi[2 ] + gi[2 ];
- bc3 = fi[4 ] - gi[4 ];
- bs3 = fi[4 ] + gi[4 ];
- bc4 = fi[6 ] - gi[6 ];
- bs4 = fi[6 ] + gi[6 ];
- bf1 = (bs1 - bs2);
- bf0 = (bs1 + bs2);
- bg1 = (bc1 - bc2);
- bg0 = (bc1 + bc2);
- bf3 = (bs3 - bs4);
- bf2 = (bs3 + bs4);
- bg3 = SQRT2*bc4;
- bg2 = SQRT2*bc3;
- fi[4 ] = bf0 - bf2;
- fi[0 ] = bf0 + bf2;
- fi[6 ] = bf1 - bf3;
- fi[2 ] = bf1 + bf3;
- gi[4 ] = bg0 - bg2;
- gi[0 ] = bg0 + bg2;
- gi[6 ] = bg1 - bg3;
- gi[2 ] = bg1 + bg3;
- }
+ for (fi=fz,fn=fz+n,gi=fi+1;fi<fn;fi+=8,gi+=8)
+ {
+ REAL bs1,bc1,bs2,bc2,bs3,bc3,bs4,bc4,
+ bg0,bf0,bf1,bg1,bf2,bg2,bf3,bg3;
+ bc1 = fi[0 ] - gi[0 ];
+ bs1 = fi[0 ] + gi[0 ];
+ bc2 = fi[2 ] - gi[2 ];
+ bs2 = fi[2 ] + gi[2 ];
+ bc3 = fi[4 ] - gi[4 ];
+ bs3 = fi[4 ] + gi[4 ];
+ bc4 = fi[6 ] - gi[6 ];
+ bs4 = fi[6 ] + gi[6 ];
+ bf1 = (bs1 - bs2);
+ bf0 = (bs1 + bs2);
+ bg1 = (bc1 - bc2);
+ bg0 = (bc1 + bc2);
+ bf3 = (bs3 - bs4);
+ bf2 = (bs3 + bs4);
+ bg3 = SQRT2*bc4;
+ bg2 = SQRT2*bc3;
+ fi[4 ] = bf0 - bf2;
+ fi[0 ] = bf0 + bf2;
+ fi[6 ] = bf1 - bf3;
+ fi[2 ] = bf1 + bf3;
+ gi[4 ] = bg0 - bg2;
+ gi[0 ] = bg0 + bg2;
+ gi[6 ] = bg1 - bg3;
+ gi[2 ] = bg1 + bg3;
+ }
}
if (n<16) return;
@@ -292,71 +292,71 @@ REAL c1,s1,s2,c2,s3,c3,s4,c4;
k4 = k2 << 1;
k3 = k2 + k1;
kx = k1 >> 1;
- fi = fz;
- gi = fi + kx;
- fn = fz + n;
- do
- {
- REAL g0,f0,f1,g1,f2,g2,f3,g3;
- f1 = fi[0 ] - fi[k1];
- f0 = fi[0 ] + fi[k1];
- f3 = fi[k2] - fi[k3];
- f2 = fi[k2] + fi[k3];
- fi[k2] = f0 - f2;
- fi[0 ] = f0 + f2;
- fi[k3] = f1 - f3;
- fi[k1] = f1 + f3;
- g1 = gi[0 ] - gi[k1];
- g0 = gi[0 ] + gi[k1];
- g3 = SQRT2 * gi[k3];
- g2 = SQRT2 * gi[k2];
- gi[k2] = g0 - g2;
- gi[0 ] = g0 + g2;
- gi[k3] = g1 - g3;
- gi[k1] = g1 + g3;
- gi += k4;
- fi += k4;
- } while (fi<fn);
+ fi = fz;
+ gi = fi + kx;
+ fn = fz + n;
+ do
+ {
+ REAL g0,f0,f1,g1,f2,g2,f3,g3;
+ f1 = fi[0 ] - fi[k1];
+ f0 = fi[0 ] + fi[k1];
+ f3 = fi[k2] - fi[k3];
+ f2 = fi[k2] + fi[k3];
+ fi[k2] = f0 - f2;
+ fi[0 ] = f0 + f2;
+ fi[k3] = f1 - f3;
+ fi[k1] = f1 + f3;
+ g1 = gi[0 ] - gi[k1];
+ g0 = gi[0 ] + gi[k1];
+ g3 = SQRT2 * gi[k3];
+ g2 = SQRT2 * gi[k2];
+ gi[k2] = g0 - g2;
+ gi[0 ] = g0 + g2;
+ gi[k3] = g1 - g3;
+ gi[k1] = g1 + g3;
+ gi += k4;
+ fi += k4;
+ } while (fi<fn);
TRIG_INIT(k,c1,s1);
for (ii=1;ii<kx;ii++)
{
- REAL c2,s2;
+ REAL c2,s2;
TRIG_NEXT(k,c1,s1);
c2 = c1*c1 - s1*s1;
s2 = 2*(c1*s1);
- fn = fz + n;
- fi = fz +ii;
- gi = fz +k1-ii;
- do
- {
- REAL a,b,g0,f0,f1,g1,f2,g2,f3,g3;
- b = s2*fi[k1] - c2*gi[k1];
- a = c2*fi[k1] + s2*gi[k1];
- f1 = fi[0 ] - a;
- f0 = fi[0 ] + a;
- g1 = gi[0 ] - b;
- g0 = gi[0 ] + b;
- b = s2*fi[k3] - c2*gi[k3];
- a = c2*fi[k3] + s2*gi[k3];
- f3 = fi[k2] - a;
- f2 = fi[k2] + a;
- g3 = gi[k2] - b;
- g2 = gi[k2] + b;
- b = s1*f2 - c1*g3;
- a = c1*f2 + s1*g3;
- fi[k2] = f0 - a;
- fi[0 ] = f0 + a;
- gi[k3] = g1 - b;
- gi[k1] = g1 + b;
- b = c1*g2 - s1*f3;
- a = s1*g2 + c1*f3;
- gi[k2] = g0 - a;
- gi[0 ] = g0 + a;
- fi[k3] = f1 - b;
- fi[k1] = f1 + b;
- gi += k4;
- fi += k4;
- } while (fi<fn);
+ fn = fz + n;
+ fi = fz +ii;
+ gi = fz +k1-ii;
+ do
+ {
+ REAL a,b,g0,f0,f1,g1,f2,g2,f3,g3;
+ b = s2*fi[k1] - c2*gi[k1];
+ a = c2*fi[k1] + s2*gi[k1];
+ f1 = fi[0 ] - a;
+ f0 = fi[0 ] + a;
+ g1 = gi[0 ] - b;
+ g0 = gi[0 ] + b;
+ b = s2*fi[k3] - c2*gi[k3];
+ a = c2*fi[k3] + s2*gi[k3];
+ f3 = fi[k2] - a;
+ f2 = fi[k2] + a;
+ g3 = gi[k2] - b;
+ g2 = gi[k2] + b;
+ b = s1*f2 - c1*g3;
+ a = c1*f2 + s1*g3;
+ fi[k2] = f0 - a;
+ fi[0 ] = f0 + a;
+ gi[k3] = g1 - b;
+ gi[k1] = g1 + b;
+ b = c1*g2 - s1*f3;
+ a = s1*g2 + c1*f3;
+ gi[k2] = g0 - a;
+ gi[0 ] = g0 + a;
+ fi[k3] = f1 - b;
+ fi[k1] = f1 + b;
+ gi += k4;
+ fi += k4;
+ } while (fi<fn);
}
TRIG_RESET(k,c1,s1);
} while (k4<n);
diff --git a/pd/src/d_misc.c b/pd/src/d_misc.c
index 35f4af0b..c67f4ba6 100644
--- a/pd/src/d_misc.c
+++ b/pd/src/d_misc.c
@@ -27,19 +27,19 @@ static t_int *print_perform(t_int *w)
int n = (int)(w[3]);
if (x->x_count)
{
- post("%s:", x->x_sym->s_name);
- if (n == 1) post("%8g", in[0]);
- else if (n == 2) post("%8g %8g", in[0], in[1]);
- else if (n == 4) post("%8g %8g %8g %8g",
- in[0], in[1], in[2], in[3]);
- else while (n > 0)
- {
- post("%-8.5g %-8.5g %-8.5g %-8.5g %-8.5g %-8.5g %-8.5g %-8.5g",
- in[0], in[1], in[2], in[3], in[4], in[5], in[6], in[7]);
- n -= 8;
- in += 8;
- }
- x->x_count--;
+ post("%s:", x->x_sym->s_name);
+ if (n == 1) post("%8g", in[0]);
+ else if (n == 2) post("%8g %8g", in[0], in[1]);
+ else if (n == 4) post("%8g %8g %8g %8g",
+ in[0], in[1], in[2], in[3]);
+ else while (n > 0)
+ {
+ post("%-8.5g %-8.5g %-8.5g %-8.5g %-8.5g %-8.5g %-8.5g %-8.5g",
+ in[0], in[1], in[2], in[3], in[4], in[5], in[6], in[7]);
+ n -= 8;
+ in += 8;
+ }
+ x->x_count--;
}
return (w+4);
}
@@ -72,7 +72,7 @@ static void *print_new(t_symbol *s)
static void print_setup(void)
{
print_class = class_new(gensym("print~"), (t_newmethod)print_new, 0,
- sizeof(t_print), 0, A_DEFSYM, 0);
+ sizeof(t_print), 0, A_DEFSYM, 0);
CLASS_MAINSIGNALIN(print_class, t_print, x_f);
class_addmethod(print_class, (t_method)print_dsp, gensym("dsp"), 0);
class_addbang(print_class, print_bang);
@@ -104,8 +104,8 @@ static t_int *scope_perform(t_int *w)
int n = (int)(w[3]), phase = x->x_phase;
while (n--)
{
- x->x_samps[phase] = *in++;
- phase = (phase + 1) & (SCOPESIZE-1);
+ x->x_samps[phase] = *in++;
+ phase = (phase + 1) & (SCOPESIZE-1);
}
x->x_phase = phase;
return (w+4);
@@ -118,7 +118,7 @@ static void scope_dsp(t_scope *x, t_signal **sp)
static void scope_erase(t_scope *x)
{
- if (x->x_drawn) sys_vgui(".x%x.c delete gumbo\n", x->x_canvas);
+ if (x->x_drawn) sys_vgui(".x%lx.c delete gumbo\n", x->x_canvas);
}
#define X1 10.
@@ -129,16 +129,16 @@ static void scope_bang(t_scope *x)
int n, phase;
char hugebuf[10000], *s = hugebuf;
scope_erase(x);
- sys_vgui(".x%x.c create line 10c 5c 20c 5c -tags gumbo\n", x->x_canvas);
- sprintf(s, ".x%x.c create line ", (t_int)x->x_canvas);
+ sys_vgui(".x%lx.c create line 10c 5c 20c 5c -tags gumbo\n", x->x_canvas);
+ sprintf(s, ".x%lx.c create line ", (t_int)x->x_canvas);
s += strlen(s);
for (n = 0, phase = x->x_phase;
- n < SCOPESIZE; phase = ((phase+1) & (SCOPESIZE-1)), n++)
+ n < SCOPESIZE; phase = ((phase+1) & (SCOPESIZE-1)), n++)
{
- sprintf(s, "%fc %fc ", X1 + (X2 - X1) * (float)n * (1./SCOPESIZE),
- YC - 5 * x->x_samps[phase]);
- s += strlen(s);
- /* post("phase %d", phase); */
+ sprintf(s, "%fc %fc ", X1 + (X2 - X1) * (float)n * (1./SCOPESIZE),
+ YC - 5 * x->x_samps[phase]);
+ s += strlen(s);
+ /* post("phase %d", phase); */
}
sprintf(s, "-tags gumbo\n");
sys_gui(hugebuf);
@@ -163,7 +163,7 @@ static void *scope_new(t_symbol *s)
static void scope_setup(void)
{
scope_class = class_new(gensym("scope~"), (t_newmethod)scope_new,
- (t_method)scope_free, sizeof(t_scope), 0, A_DEFSYM, 0);
+ (t_method)scope_free, sizeof(t_scope), 0, A_DEFSYM, 0);
class_addmethod(scope_class, nullfn, gensym("signal"), 0);
class_addmethod(scope_class, (t_method)scope_dsp, gensym("dsp"), 0);
class_addbang(scope_class, scope_bang);
@@ -212,9 +212,9 @@ static void *bang_tilde_new(t_symbol *s)
static void bang_tilde_setup(void)
{
bang_tilde_class = class_new(gensym("bang~"), (t_newmethod)bang_tilde_new,
- (t_method)bang_tilde_free, sizeof(t_bang), 0, 0);
+ (t_method)bang_tilde_free, sizeof(t_bang), 0, 0);
class_addmethod(bang_tilde_class, (t_method)bang_tilde_dsp,
- gensym("dsp"), 0);
+ gensym("dsp"), 0);
}
/* ------------------------ samplerate~~ -------------------------- */
@@ -241,7 +241,7 @@ static void *samplerate_tilde_new(t_symbol *s)
static void samplerate_tilde_setup(void)
{
samplerate_tilde_class = class_new(gensym("samplerate~"),
- (t_newmethod)samplerate_tilde_new, 0, sizeof(t_samplerate), 0, 0);
+ (t_newmethod)samplerate_tilde_new, 0, sizeof(t_samplerate), 0, 0);
class_addbang(samplerate_tilde_class, samplerate_tilde_bang);
}
diff --git a/pd/src/d_osc.c b/pd/src/d_osc.c
index 8fe7f29b..37821564 100644
--- a/pd/src/d_osc.c
+++ b/pd/src/d_osc.c
@@ -76,14 +76,14 @@ union tabfudge
/* -------------------------- phasor~ ------------------------------ */
static t_class *phasor_class, *scalarphasor_class;
-#if 1 /* in the style of R. Hoeldrich (ICMC 1995 Banff) */
+#if 1 /* in the style of R. Hoeldrich (ICMC 1995 Banff) */
typedef struct _phasor
{
t_object x_obj;
double x_phase;
float x_conv;
- float x_f; /* scalar frequency */
+ float x_f; /* scalar frequency */
} t_phasor;
static void *phasor_new(t_floatarg f)
@@ -114,10 +114,10 @@ static t_int *phasor_perform(t_int *w)
while (n--)
{
- tf.tf_i[HIOFFSET] = normhipart;
- dphase += *in++ * conv;
- *out++ = tf.tf_d - UNITBIT32;
- tf.tf_d = dphase;
+ tf.tf_i[HIOFFSET] = normhipart;
+ dphase += *in++ * conv;
+ *out++ = tf.tf_d - UNITBIT32;
+ tf.tf_d = dphase;
}
tf.tf_i[HIOFFSET] = normhipart;
x->x_phase = tf.tf_d - UNITBIT32;
@@ -138,14 +138,14 @@ static void phasor_ft1(t_phasor *x, t_float f)
static void phasor_setup(void)
{
phasor_class = class_new(gensym("phasor~"), (t_newmethod)phasor_new, 0,
- sizeof(t_phasor), 0, A_DEFFLOAT, 0);
+ sizeof(t_phasor), 0, A_DEFFLOAT, 0);
CLASS_MAINSIGNALIN(phasor_class, t_phasor, x_f);
class_addmethod(phasor_class, (t_method)phasor_dsp, gensym("dsp"), 0);
class_addmethod(phasor_class, (t_method)phasor_ft1,
- gensym("ft1"), A_FLOAT, 0);
+ gensym("ft1"), A_FLOAT, 0);
}
-#endif /* Hoeldrich version */
+#endif /* Hoeldrich version */
/* ------------------------ cos~ ----------------------------- */
@@ -180,39 +180,39 @@ static t_int *cos_perform(t_int *w)
tf.tf_d = UNITBIT32;
normhipart = tf.tf_i[HIOFFSET];
-#if 0 /* this is the readable version of the code. */
+#if 0 /* this is the readable version of the code. */
while (n--)
{
- dphase = (double)(*in++ * (float)(COSTABSIZE)) + UNITBIT32;
- tf.tf_d = dphase;
- addr = tab + (tf.tf_i[HIOFFSET] & (COSTABSIZE-1));
- tf.tf_i[HIOFFSET] = normhipart;
- frac = tf.tf_d - UNITBIT32;
- f1 = addr[0];
- f2 = addr[1];
- *out++ = f1 + frac * (f2 - f1);
+ dphase = (double)(*in++ * (float)(COSTABSIZE)) + UNITBIT32;
+ tf.tf_d = dphase;
+ addr = tab + (tf.tf_i[HIOFFSET] & (COSTABSIZE-1));
+ tf.tf_i[HIOFFSET] = normhipart;
+ frac = tf.tf_d - UNITBIT32;
+ f1 = addr[0];
+ f2 = addr[1];
+ *out++ = f1 + frac * (f2 - f1);
}
#endif
-#if 1 /* this is the same, unwrapped by hand. */
- dphase = (double)(*in++ * (float)(COSTABSIZE)) + UNITBIT32;
- tf.tf_d = dphase;
- addr = tab + (tf.tf_i[HIOFFSET] & (COSTABSIZE-1));
- tf.tf_i[HIOFFSET] = normhipart;
+#if 1 /* this is the same, unwrapped by hand. */
+ dphase = (double)(*in++ * (float)(COSTABSIZE)) + UNITBIT32;
+ tf.tf_d = dphase;
+ addr = tab + (tf.tf_i[HIOFFSET] & (COSTABSIZE-1));
+ tf.tf_i[HIOFFSET] = normhipart;
while (--n)
{
- dphase = (double)(*in++ * (float)(COSTABSIZE)) + UNITBIT32;
- frac = tf.tf_d - UNITBIT32;
- tf.tf_d = dphase;
- f1 = addr[0];
- f2 = addr[1];
- addr = tab + (tf.tf_i[HIOFFSET] & (COSTABSIZE-1));
- *out++ = f1 + frac * (f2 - f1);
- tf.tf_i[HIOFFSET] = normhipart;
+ dphase = (double)(*in++ * (float)(COSTABSIZE)) + UNITBIT32;
+ frac = tf.tf_d - UNITBIT32;
+ tf.tf_d = dphase;
+ f1 = addr[0];
+ f2 = addr[1];
+ addr = tab + (tf.tf_i[HIOFFSET] & (COSTABSIZE-1));
+ *out++ = f1 + frac * (f2 - f1);
+ tf.tf_i[HIOFFSET] = normhipart;
}
- frac = tf.tf_d - UNITBIT32;
- f1 = addr[0];
- f2 = addr[1];
- *out++ = f1 + frac * (f2 - f1);
+ frac = tf.tf_d - UNITBIT32;
+ f1 = addr[0];
+ f2 = addr[1];
+ *out++ = f1 + frac * (f2 - f1);
#endif
return (w+4);
}
@@ -231,21 +231,21 @@ static void cos_maketable(void)
if (cos_table) return;
cos_table = (float *)getbytes(sizeof(float) * (COSTABSIZE+1));
for (i = COSTABSIZE + 1, fp = cos_table, phase = 0; i--;
- fp++, phase += phsinc)
- *fp = cos(phase);
+ fp++, phase += phsinc)
+ *fp = cos(phase);
- /* here we check at startup whether the byte alignment
- is as we declared it. If not, the code has to be
- recompiled the other way. */
+ /* here we check at startup whether the byte alignment
+ is as we declared it. If not, the code has to be
+ recompiled the other way. */
tf.tf_d = UNITBIT32 + 0.5;
if ((unsigned)tf.tf_i[LOWOFFSET] != 0x80000000)
- bug("cos~: unexpected machine alignment");
+ bug("cos~: unexpected machine alignment");
}
static void cos_setup(void)
{
cos_class = class_new(gensym("cos~"), (t_newmethod)cos_new, 0,
- sizeof(t_cos), 0, A_DEFFLOAT, 0);
+ sizeof(t_cos), 0, A_DEFFLOAT, 0);
CLASS_MAINSIGNALIN(cos_class, t_cos, x_f);
class_addmethod(cos_class, (t_method)cos_dsp, gensym("dsp"), 0);
cos_maketable();
@@ -260,7 +260,7 @@ typedef struct _osc
t_object x_obj;
double x_phase;
float x_conv;
- float x_f; /* frequency if scalar */
+ float x_f; /* frequency if scalar */
} t_osc;
static void *osc_new(t_floatarg f)
@@ -291,36 +291,36 @@ static t_int *osc_perform(t_int *w)
#if 0
while (n--)
{
- tf.tf_d = dphase;
- dphase += *in++ * conv;
- addr = tab + (tf.tf_i[HIOFFSET] & (COSTABSIZE-1));
- tf.tf_i[HIOFFSET] = normhipart;
- frac = tf.tf_d - UNITBIT32;
- f1 = addr[0];
- f2 = addr[1];
- *out++ = f1 + frac * (f2 - f1);
+ tf.tf_d = dphase;
+ dphase += *in++ * conv;
+ addr = tab + (tf.tf_i[HIOFFSET] & (COSTABSIZE-1));
+ tf.tf_i[HIOFFSET] = normhipart;
+ frac = tf.tf_d - UNITBIT32;
+ f1 = addr[0];
+ f2 = addr[1];
+ *out++ = f1 + frac * (f2 - f1);
}
#endif
#if 1
- tf.tf_d = dphase;
- dphase += *in++ * conv;
- addr = tab + (tf.tf_i[HIOFFSET] & (COSTABSIZE-1));
- tf.tf_i[HIOFFSET] = normhipart;
- frac = tf.tf_d - UNITBIT32;
+ tf.tf_d = dphase;
+ dphase += *in++ * conv;
+ addr = tab + (tf.tf_i[HIOFFSET] & (COSTABSIZE-1));
+ tf.tf_i[HIOFFSET] = normhipart;
+ frac = tf.tf_d - UNITBIT32;
while (--n)
{
- tf.tf_d = dphase;
- f1 = addr[0];
- dphase += *in++ * conv;
- f2 = addr[1];
- addr = tab + (tf.tf_i[HIOFFSET] & (COSTABSIZE-1));
- tf.tf_i[HIOFFSET] = normhipart;
- *out++ = f1 + frac * (f2 - f1);
- frac = tf.tf_d - UNITBIT32;
+ tf.tf_d = dphase;
+ f1 = addr[0];
+ dphase += *in++ * conv;
+ f2 = addr[1];
+ addr = tab + (tf.tf_i[HIOFFSET] & (COSTABSIZE-1));
+ tf.tf_i[HIOFFSET] = normhipart;
+ *out++ = f1 + frac * (f2 - f1);
+ frac = tf.tf_d - UNITBIT32;
}
- f1 = addr[0];
- f2 = addr[1];
- *out++ = f1 + frac * (f2 - f1);
+ f1 = addr[0];
+ f2 = addr[1];
+ *out++ = f1 + frac * (f2 - f1);
#endif
tf.tf_d = UNITBIT32 * COSTABSIZE;
@@ -345,7 +345,7 @@ static void osc_ft1(t_osc *x, t_float f)
static void osc_setup(void)
{
osc_class = class_new(gensym("osc~"), (t_newmethod)osc_new, 0,
- sizeof(t_osc), 0, A_DEFFLOAT, 0);
+ sizeof(t_osc), 0, A_DEFFLOAT, 0);
CLASS_MAINSIGNALIN(osc_class, t_osc, x_f);
class_addmethod(osc_class, (t_method)osc_dsp, gensym("dsp"), 0);
class_addmethod(osc_class, (t_method)osc_ft1, gensym("ft1"), A_FLOAT, 0);
@@ -420,38 +420,38 @@ static t_int *sigvcf_perform(t_int *w)
for (i = 0; i < n; i++)
{
- float cf, cfindx, r, oneminusr;
- cf = *in2++ * isr;
- if (cf < 0) cf = 0;
- cfindx = cf * (float)(COSTABSIZE/6.28318f);
- r = (qinv > 0 ? 1 - cf * qinv : 0);
- if (r < 0) r = 0;
- oneminusr = 1.0f - r;
- dphase = ((double)(cfindx)) + UNITBIT32;
- tf.tf_d = dphase;
- tabindex = tf.tf_i[HIOFFSET] & (COSTABSIZE-1);
- addr = tab + tabindex;
- tf.tf_i[HIOFFSET] = normhipart;
- frac = tf.tf_d - UNITBIT32;
- f1 = addr[0];
- f2 = addr[1];
- coefr = r * (f1 + frac * (f2 - f1));
-
- addr = tab + ((tabindex - (COSTABSIZE/4)) & (COSTABSIZE-1));
- f1 = addr[0];
- f2 = addr[1];
- coefi = r * (f1 + frac * (f2 - f1));
-
- f1 = *in1++;
- re2 = re;
- *out1++ = re = ampcorrect * oneminusr * f1
- + coefr * re2 - coefi * im;
- *out2++ = im = coefi * re2 + coefr * im;
+ float cf, cfindx, r, oneminusr;
+ cf = *in2++ * isr;
+ if (cf < 0) cf = 0;
+ cfindx = cf * (float)(COSTABSIZE/6.28318f);
+ r = (qinv > 0 ? 1 - cf * qinv : 0);
+ if (r < 0) r = 0;
+ oneminusr = 1.0f - r;
+ dphase = ((double)(cfindx)) + UNITBIT32;
+ tf.tf_d = dphase;
+ tabindex = tf.tf_i[HIOFFSET] & (COSTABSIZE-1);
+ addr = tab + tabindex;
+ tf.tf_i[HIOFFSET] = normhipart;
+ frac = tf.tf_d - UNITBIT32;
+ f1 = addr[0];
+ f2 = addr[1];
+ coefr = r * (f1 + frac * (f2 - f1));
+
+ addr = tab + ((tabindex - (COSTABSIZE/4)) & (COSTABSIZE-1));
+ f1 = addr[0];
+ f2 = addr[1];
+ coefi = r * (f1 + frac * (f2 - f1));
+
+ f1 = *in1++;
+ re2 = re;
+ *out1++ = re = ampcorrect * oneminusr * f1
+ + coefr * re2 - coefi * im;
+ *out2++ = im = coefi * re2 + coefr * im;
}
- if (PD_BADFLOAT(re))
- re = 0;
- if (PD_BADFLOAT(im))
- im = 0;
+ if (PD_BIGORSMALL(re))
+ re = 0;
+ if (PD_BIGORSMALL(im))
+ im = 0;
c->c_re = re;
c->c_im = im;
return (w+7);
@@ -461,19 +461,19 @@ static void sigvcf_dsp(t_sigvcf *x, t_signal **sp)
{
x->x_ctl->c_isr = 6.28318f/sp[0]->s_sr;
dsp_add(sigvcf_perform, 6,
- sp[0]->s_vec, sp[1]->s_vec, sp[2]->s_vec, sp[3]->s_vec,
- x->x_ctl, sp[0]->s_n);
+ sp[0]->s_vec, sp[1]->s_vec, sp[2]->s_vec, sp[3]->s_vec,
+ x->x_ctl, sp[0]->s_n);
}
void sigvcf_setup(void)
{
sigvcf_class = class_new(gensym("vcf~"), (t_newmethod)sigvcf_new, 0,
- sizeof(t_sigvcf), 0, A_DEFFLOAT, 0);
+ sizeof(t_sigvcf), 0, A_DEFFLOAT, 0);
CLASS_MAINSIGNALIN(sigvcf_class, t_sigvcf, x_f);
class_addmethod(sigvcf_class, (t_method)sigvcf_dsp, gensym("dsp"), 0);
class_addmethod(sigvcf_class, (t_method)sigvcf_ft1,
- gensym("ft1"), A_FLOAT, 0);
+ gensym("ft1"), A_FLOAT, 0);
}
/* -------------------------- noise~ ------------------------------ */
@@ -502,9 +502,9 @@ static t_int *noise_perform(t_int *w)
int val = *vp;
while (n--)
{
- *out++ = ((float)((val & 0x7fffffff) - 0x40000000)) *
- (float)(1.0 / 0x40000000);
- val = val * 435898247 + 382842987;
+ *out++ = ((float)((val & 0x7fffffff) - 0x40000000)) *
+ (float)(1.0 / 0x40000000);
+ val = val * 435898247 + 382842987;
}
*vp = val;
return (w+4);
@@ -518,7 +518,7 @@ static void noise_dsp(t_noise *x, t_signal **sp)
static void noise_setup(void)
{
noise_class = class_new(gensym("noise~"), (t_newmethod)noise_new, 0,
- sizeof(t_noise), 0, 0);
+ sizeof(t_noise), 0, 0);
class_addmethod(noise_class, (t_method)noise_dsp, gensym("dsp"), 0);
}
diff --git a/pd/src/d_resample.c b/pd/src/d_resample.c
index 83ed7498..e8a0a598 100644
--- a/pd/src/d_resample.c
+++ b/pd/src/d_resample.c
@@ -134,9 +134,9 @@ void resample_free(t_resample *x)
/* dsp-adding */
void resample_dsp(t_resample *x,
- t_sample* in, int insize,
- t_sample* out, int outsize,
- int method)
+ t_sample* in, int insize,
+ t_sample* out, int outsize,
+ int method)
{
if (insize == outsize){
bug("nothing to be done");
@@ -165,9 +165,9 @@ void resample_dsp(t_resample *x,
break;
case 2:
if (x->bufsize != 1) {
- t_freebytes(x->buffer, x->bufsize*sizeof(*x->buffer));
- x->bufsize = 1;
- x->buffer = t_getbytes(x->bufsize*sizeof(*x->buffer));
+ t_freebytes(x->buffer, x->bufsize*sizeof(*x->buffer));
+ x->bufsize = 1;
+ x->buffer = t_getbytes(x->bufsize*sizeof(*x->buffer));
}
dsp_add(upsampling_perform_linear, 5, x, in, out, outsize/insize, insize);
break;
@@ -178,8 +178,8 @@ void resample_dsp(t_resample *x,
}
void resamplefrom_dsp(t_resample *x,
- t_sample *in,
- int insize, int outsize, int method)
+ t_sample *in,
+ int insize, int outsize, int method)
{
if (insize==outsize) {
t_freebytes(x->s_vec, x->s_n * sizeof(*x->s_vec));
@@ -201,8 +201,8 @@ void resamplefrom_dsp(t_resample *x,
}
void resampleto_dsp(t_resample *x,
- t_sample *out,
- int insize, int outsize, int method)
+ t_sample *out,
+ int insize, int outsize, int method)
{
if (insize==outsize) {
if (x->s_n)t_freebytes(x->s_vec, x->s_n * sizeof(*x->s_vec));
diff --git a/pd/src/d_soundfile.c b/pd/src/d_soundfile.c
index f9b9d802..c4b058b1 100644
--- a/pd/src/d_soundfile.c
+++ b/pd/src/d_soundfile.c
@@ -8,11 +8,10 @@ uses the routines to read or write soundfiles, synchronously, from garrays.
These operations are not to be done in "real time" as they may have to wait
for disk accesses (even the write routine.) Finally, the realtime objects
readsf~ and writesf~ are defined which confine disk operations to a separate
-thread so that they can be used in real time. The real-time disk access
-objects are available for linux only so far, although they could be compiled
-for Windows if someone were willing to find a Pthreads package for it. */
+thread so that they can be used in real time. The readsf~ and writesf~
+objects use Posix-like threads. */
-#ifdef UNIX
+#ifndef MSW
#include <unistd.h>
#include <fcntl.h>
#endif
@@ -41,17 +40,17 @@ typedef unsigned long uint32;
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 */
+ 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 */
+ 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_LINEAR_16 3
+#define NS_FORMAT_LINEAR_24 4
#define NS_FORMAT_FLOAT 6
#define SCALE (1./(1024. * 1024. * 1024. * 2.))
@@ -64,35 +63,35 @@ 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 (WAV_INT etc) */
- 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 frame */
- uint16 w_nbitspersample; /* number of bits in a sample */
- char w_datachunkid[4]; /* data chunk id 'data' */
+ 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 (WAV_INT etc) */
+ 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 frame */
+ 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;
-typedef struct _fmt /* format chunk */
+typedef struct _fmt /* format chunk */
{
- uint16 f_fmttag; /* format tag, 1 for PCM */
- uint16 f_nchannels; /* number of channels */
- uint32 f_samplespersec; /* sample rate in hz */
- uint32 f_navgbytespersec; /* average bytes per second */
- uint16 f_nblockalign; /* number of bytes per frame */
- uint16 f_nbitspersample; /* number of bits in a sample */
+ uint16 f_fmttag; /* format tag, 1 for PCM */
+ uint16 f_nchannels; /* number of channels */
+ uint32 f_samplespersec; /* sample rate in hz */
+ uint32 f_navgbytespersec; /* average bytes per second */
+ uint16 f_nblockalign; /* number of bytes per frame */
+ uint16 f_nbitspersample; /* number of bits in a sample */
} t_fmt;
-typedef struct _wavechunk /* ... and the last two items */
+typedef struct _wavechunk /* ... and the last two items */
{
- char wc_id[4]; /* data chunk id, e.g., 'data' or 'fmt ' */
- uint32 wc_size; /* length of data chunk */
+ char wc_id[4]; /* data chunk id, e.g., 'data' or 'fmt ' */
+ uint32 wc_size; /* length of data chunk */
} t_wavechunk;
#define WAV_INT 1
@@ -103,35 +102,35 @@ typedef struct _wavechunk /* ... and the last two items */
typedef struct _datachunk
{
- char dc_id[4]; /* data chunk id 'SSND' */
- uint32 dc_size; /* length of data chunk */
+ char dc_id[4]; /* data chunk id 'SSND' */
+ uint32 dc_size; /* length of data chunk */
} t_datachunk;
typedef struct _comm
{
- uint16 c_nchannels; /* number of channels */
- uint16 c_nframeshi; /* # of sample frames (hi) */
- uint16 c_nframeslo; /* # of sample frames (lo) */
- uint16 c_bitspersamp; /* bits per sample */
+ uint16 c_nchannels; /* number of channels */
+ uint16 c_nframeshi; /* # of sample frames (hi) */
+ uint16 c_nframeslo; /* # of sample frames (lo) */
+ uint16 c_bitspersamp; /* bits per sample */
unsigned char c_samprate[10]; /* sample rate, 80-bit float! */
} t_comm;
/* this version is more convenient for writing them out: */
typedef struct _aiff
{
- char a_fileid[4]; /* chunk id 'FORM' */
- uint32 a_chunksize; /* chunk size */
- char a_aiffid[4]; /* aiff chunk id 'AIFF' */
- char a_fmtid[4]; /* format chunk id 'COMM' */
- uint32 a_fmtchunksize; /* format chunk size, 18 */
- uint16 a_nchannels; /* number of channels */
- uint16 a_nframeshi; /* # of sample frames (hi) */
- uint16 a_nframeslo; /* # of sample frames (lo) */
- uint16 a_bitspersamp; /* bits per sample */
+ char a_fileid[4]; /* chunk id 'FORM' */
+ uint32 a_chunksize; /* chunk size */
+ char a_aiffid[4]; /* aiff chunk id 'AIFF' */
+ char a_fmtid[4]; /* format chunk id 'COMM' */
+ uint32 a_fmtchunksize; /* format chunk size, 18 */
+ uint16 a_nchannels; /* number of channels */
+ uint16 a_nframeshi; /* # of sample frames (hi) */
+ uint16 a_nframeslo; /* # of sample frames (lo) */
+ uint16 a_bitspersamp; /* bits per sample */
unsigned char a_samprate[10]; /* sample rate, 80-bit float! */
} t_aiff;
-#define AIFFHDRSIZE 38 /* probably not what sizeof() gives */
+#define AIFFHDRSIZE 38 /* probably not what sizeof() gives */
#define AIFFPLUS (AIFFHDRSIZE + 8) /* header size including first chunk hdr */
@@ -162,15 +161,15 @@ extern int garray_ambigendian(void);
static uint32 swap4(uint32 n, int doit)
{
if (doit)
- return (((n & 0xff) << 24) | ((n & 0xff00) << 8) |
- ((n & 0xff0000) >> 8) | ((n & 0xff000000) >> 24));
+ return (((n & 0xff) << 24) | ((n & 0xff00) << 8) |
+ ((n & 0xff0000) >> 8) | ((n & 0xff000000) >> 24));
else return (n);
}
static uint16 swap2(uint32 n, int doit)
{
if (doit)
- return (((n & 0xff) << 8) | ((n & 0xff00) >> 8));
+ return (((n & 0xff) << 8) | ((n & 0xff00) >> 8));
else return (n);
}
@@ -178,15 +177,13 @@ static void swapstring(char *foo, int doit)
{
if (doit)
{
- char a = foo[0], b = foo[1], c = foo[2], d = foo[3];
- foo[0] = d; foo[1] = c; foo[2] = b; foo[3] = a;
+ char a = foo[0], b = foo[1], c = foo[2], d = foo[3];
+ foo[0] = d; foo[1] = c; foo[2] = b; foo[3] = a;
}
}
/******************** soundfile access routines **********************/
-void readsf_banana( void); /* debugging */
-
/* This routine opens a file, looks for either a nextstep or "wave" header,
* seeks to end of it, and fills in bytes per sample and number of channels.
* Only 2- and 3-byte fixed-point samples and 4-byte floating point samples
@@ -205,182 +202,185 @@ int open_soundfile(const char *dirname, const char *filename, int headersize,
long bytelimit = 0x7fffffff;
errno = 0;
fd = open_via_path(dirname, filename,
- "", buf, &bufptr, MAXPDSTRING, 1);
+ "", buf, &bufptr, MAXPDSTRING, 1);
if (fd < 0)
- return (-1);
+ return (-1);
if (headersize >= 0) /* header detection overridden */
{
- bigendian = *p_bigendian;
- nchannels = *p_nchannels;
- bytespersamp = *p_bytespersamp;
- bytelimit = *p_bytelimit;
+ bigendian = *p_bigendian;
+ nchannels = *p_nchannels;
+ bytespersamp = *p_bytespersamp;
+ bytelimit = *p_bytelimit;
}
else
{
- int bytesread = read(fd, buf, READHDRSIZE);
- int format;
- if (bytesread < 4)
- goto badheader;
- if (!strncmp(buf, ".snd", 4))
- format = FORMAT_NEXT, bigendian = 1;
- else if (!strncmp(buf, "dns.", 4))
- format = FORMAT_NEXT, bigendian = 0;
- else if (!strncmp(buf, "RIFF", 4))
- {
- if (bytesread < 12 || strncmp(buf + 8, "WAVE", 4))
- goto badheader;
- format = FORMAT_WAVE, bigendian = 0;
- }
- else if (!strncmp(buf, "FORM", 4))
- {
- if (bytesread < 12 || strncmp(buf + 8, "AIFF", 4))
- goto badheader;
- format = FORMAT_AIFF, bigendian = 1;
- }
- else
- goto badheader;
- swap = (bigendian != garray_ambigendian());
- if (format == FORMAT_NEXT) /* nextstep header */
- {
- uint32 param;
- if (bytesread < (int)sizeof(t_nextstep))
- goto badheader;
- nchannels = swap4(((t_nextstep *)buf)->ns_nchans, swap);
- format = swap4(((t_nextstep *)buf)->ns_format, swap);
- headersize = swap4(((t_nextstep *)buf)->ns_onset, swap);
- if (format == NS_FORMAT_LINEAR_16)
- bytespersamp = 2;
- else if (format == NS_FORMAT_LINEAR_24)
- bytespersamp = 3;
- else if (format == NS_FORMAT_FLOAT)
- bytespersamp = 4;
- else goto badheader;
- bytelimit = 0x7fffffff;
- }
- else if (format == FORMAT_WAVE) /* wave header */
- {
- /* This is awful. You have to skip over chunks,
- except that if one happens to be a "fmt" chunk, you want to
- find out the format from that one. The case where the
- "fmt" chunk comes after the audio isn't handled. */
- headersize = 12;
- if (bytesread < 20)
- goto badheader;
- /* First we guess a number of channels, etc., in case there's
- no "fmt" chunk to follow. */
- nchannels = 1;
- bytespersamp = 2;
- /* copy the first chunk header to beginnning of buffer. */
- memcpy(buf, buf + headersize, sizeof(t_wavechunk));
- /* post("chunk %c %c %c %c",
- ((t_wavechunk *)buf)->wc_id[0],
- ((t_wavechunk *)buf)->wc_id[1],
- ((t_wavechunk *)buf)->wc_id[2],
- ((t_wavechunk *)buf)->wc_id[3]); */
- /* read chunks in loop until we get to the data chunk */
- while (strncmp(((t_wavechunk *)buf)->wc_id, "data", 4))
- {
- long chunksize = swap4(((t_wavechunk *)buf)->wc_size,
- swap), seekto = headersize + chunksize + 8, seekout;
-
- if (!strncmp(((t_wavechunk *)buf)->wc_id, "fmt ", 4))
- {
- long commblockonset = headersize + 8;
- seekout = lseek(fd, commblockonset, SEEK_SET);
- if (seekout != commblockonset)
- goto badheader;
- if (read(fd, buf, sizeof(t_fmt)) < (int) sizeof(t_fmt))
- goto badheader;
- nchannels = swap2(((t_fmt *)buf)->f_nchannels, swap);
- format = swap2(((t_fmt *)buf)->f_nbitspersample, swap);
- if (format == 16)
- bytespersamp = 2;
- else if (format == 24)
- bytespersamp = 3;
- else if (format == 32)
- bytespersamp = 4;
- else goto badheader;
- }
- seekout = lseek(fd, seekto, SEEK_SET);
- if (seekout != seekto)
- goto badheader;
- if (read(fd, buf, sizeof(t_wavechunk)) <
- (int) sizeof(t_wavechunk))
- goto badheader;
- /* post("new chunk %c %c %c %c at %d",
- ((t_wavechunk *)buf)->wc_id[0],
- ((t_wavechunk *)buf)->wc_id[1],
- ((t_wavechunk *)buf)->wc_id[2],
- ((t_wavechunk *)buf)->wc_id[3], seekto); */
- headersize = seekto;
- }
- bytelimit = swap4(((t_wavechunk *)buf)->wc_size, swap);
- headersize += 8;
- }
- else
- {
- /* AIFF. same as WAVE; actually predates it. Disgusting. */
- headersize = 12;
- if (bytesread < 20)
- goto badheader;
- /* First we guess a number of channels, etc., in case there's
- no COMM block to follow. */
- nchannels = 1;
- bytespersamp = 2;
- /* copy the first chunk header to beginnning of buffer. */
- memcpy(buf, buf + headersize, sizeof(t_datachunk));
- /* read chunks in loop until we get to the data chunk */
- while (strncmp(((t_datachunk *)buf)->dc_id, "SSND", 4))
- {
- long chunksize = swap4(((t_datachunk *)buf)->dc_size,
- swap), seekto = headersize + chunksize + 8, seekout;
- /* post("chunk %c %c %c %c seek %d",
- ((t_datachunk *)buf)->dc_id[0],
- ((t_datachunk *)buf)->dc_id[1],
- ((t_datachunk *)buf)->dc_id[2],
- ((t_datachunk *)buf)->dc_id[3], seekto); */
- if (!strncmp(((t_datachunk *)buf)->dc_id, "COMM", 4))
- {
- long commblockonset = headersize + 8;
- seekout = lseek(fd, commblockonset, SEEK_SET);
- if (seekout != commblockonset)
- goto badheader;
- if (read(fd, buf, sizeof(t_comm)) <
- (int) sizeof(t_comm))
- goto badheader;
- nchannels = swap2(((t_comm *)buf)->c_nchannels, swap);
- format = swap2(((t_comm *)buf)->c_bitspersamp, swap);
- if (format == 16)
- bytespersamp = 2;
- else if (format == 24)
- bytespersamp = 3;
- else goto badheader;
- }
- seekout = lseek(fd, seekto, SEEK_SET);
- if (seekout != seekto)
- goto badheader;
- if (read(fd, buf, sizeof(t_datachunk)) <
- (int) sizeof(t_datachunk))
- goto badheader;
- headersize = seekto;
- }
- bytelimit = swap4(((t_datachunk *)buf)->dc_size, swap);
- headersize += 8;
- }
+ int bytesread = read(fd, buf, READHDRSIZE);
+ int format;
+ if (bytesread < 4)
+ goto badheader;
+ if (!strncmp(buf, ".snd", 4))
+ format = FORMAT_NEXT, bigendian = 1;
+ else if (!strncmp(buf, "dns.", 4))
+ format = FORMAT_NEXT, bigendian = 0;
+ else if (!strncmp(buf, "RIFF", 4))
+ {
+ if (bytesread < 12 || strncmp(buf + 8, "WAVE", 4))
+ goto badheader;
+ format = FORMAT_WAVE, bigendian = 0;
+ }
+ else if (!strncmp(buf, "FORM", 4))
+ {
+ if (bytesread < 12 || strncmp(buf + 8, "AIFF", 4))
+ goto badheader;
+ format = FORMAT_AIFF, bigendian = 1;
+ }
+ else
+ goto badheader;
+ swap = (bigendian != garray_ambigendian());
+ if (format == FORMAT_NEXT) /* nextstep header */
+ {
+ uint32 param;
+ if (bytesread < (int)sizeof(t_nextstep))
+ goto badheader;
+ nchannels = swap4(((t_nextstep *)buf)->ns_nchans, swap);
+ format = swap4(((t_nextstep *)buf)->ns_format, swap);
+ headersize = swap4(((t_nextstep *)buf)->ns_onset, swap);
+ if (format == NS_FORMAT_LINEAR_16)
+ bytespersamp = 2;
+ else if (format == NS_FORMAT_LINEAR_24)
+ bytespersamp = 3;
+ else if (format == NS_FORMAT_FLOAT)
+ bytespersamp = 4;
+ else goto badheader;
+ bytelimit = 0x7fffffff;
+ }
+ else if (format == FORMAT_WAVE) /* wave header */
+ {
+ /* This is awful. You have to skip over chunks,
+ except that if one happens to be a "fmt" chunk, you want to
+ find out the format from that one. The case where the
+ "fmt" chunk comes after the audio isn't handled. */
+ headersize = 12;
+ if (bytesread < 20)
+ goto badheader;
+ /* First we guess a number of channels, etc., in case there's
+ no "fmt" chunk to follow. */
+ nchannels = 1;
+ bytespersamp = 2;
+ /* copy the first chunk header to beginnning of buffer. */
+ memcpy(buf, buf + headersize, sizeof(t_wavechunk));
+ /* post("chunk %c %c %c %c",
+ ((t_wavechunk *)buf)->wc_id[0],
+ ((t_wavechunk *)buf)->wc_id[1],
+ ((t_wavechunk *)buf)->wc_id[2],
+ ((t_wavechunk *)buf)->wc_id[3]); */
+ /* read chunks in loop until we get to the data chunk */
+ while (strncmp(((t_wavechunk *)buf)->wc_id, "data", 4))
+ {
+ long chunksize = swap4(((t_wavechunk *)buf)->wc_size,
+ swap), seekto = headersize + chunksize + 8, seekout;
+
+ if (!strncmp(((t_wavechunk *)buf)->wc_id, "fmt ", 4))
+ {
+ long commblockonset = headersize + 8;
+ seekout = lseek(fd, commblockonset, SEEK_SET);
+ if (seekout != commblockonset)
+ goto badheader;
+ if (read(fd, buf, sizeof(t_fmt)) < (int) sizeof(t_fmt))
+ goto badheader;
+ nchannels = swap2(((t_fmt *)buf)->f_nchannels, swap);
+ format = swap2(((t_fmt *)buf)->f_nbitspersample, swap);
+ if (format == 16)
+ bytespersamp = 2;
+ else if (format == 24)
+ bytespersamp = 3;
+ else if (format == 32)
+ bytespersamp = 4;
+ else goto badheader;
+ }
+ seekout = lseek(fd, seekto, SEEK_SET);
+ if (seekout != seekto)
+ goto badheader;
+ if (read(fd, buf, sizeof(t_wavechunk)) <
+ (int) sizeof(t_wavechunk))
+ goto badheader;
+ /* post("new chunk %c %c %c %c at %d",
+ ((t_wavechunk *)buf)->wc_id[0],
+ ((t_wavechunk *)buf)->wc_id[1],
+ ((t_wavechunk *)buf)->wc_id[2],
+ ((t_wavechunk *)buf)->wc_id[3], seekto); */
+ headersize = seekto;
+ }
+ bytelimit = swap4(((t_wavechunk *)buf)->wc_size, swap);
+ headersize += 8;
+ }
+ else
+ {
+ /* AIFF. same as WAVE; actually predates it. Disgusting. */
+ headersize = 12;
+ if (bytesread < 20)
+ goto badheader;
+ /* First we guess a number of channels, etc., in case there's
+ no COMM block to follow. */
+ nchannels = 1;
+ bytespersamp = 2;
+ /* copy the first chunk header to beginnning of buffer. */
+ memcpy(buf, buf + headersize, sizeof(t_datachunk));
+ /* read chunks in loop until we get to the data chunk */
+ while (strncmp(((t_datachunk *)buf)->dc_id, "SSND", 4))
+ {
+ long chunksize = swap4(((t_datachunk *)buf)->dc_size,
+ swap), seekto = headersize + chunksize + 8, seekout;
+ /* post("chunk %c %c %c %c seek %d",
+ ((t_datachunk *)buf)->dc_id[0],
+ ((t_datachunk *)buf)->dc_id[1],
+ ((t_datachunk *)buf)->dc_id[2],
+ ((t_datachunk *)buf)->dc_id[3], seekto); */
+ if (!strncmp(((t_datachunk *)buf)->dc_id, "COMM", 4))
+ {
+ long commblockonset = headersize + 8;
+ seekout = lseek(fd, commblockonset, SEEK_SET);
+ if (seekout != commblockonset)
+ goto badheader;
+ if (read(fd, buf, sizeof(t_comm)) <
+ (int) sizeof(t_comm))
+ goto badheader;
+ nchannels = swap2(((t_comm *)buf)->c_nchannels, swap);
+ format = swap2(((t_comm *)buf)->c_bitspersamp, swap);
+ if (format == 16)
+ bytespersamp = 2;
+ else if (format == 24)
+ bytespersamp = 3;
+ else goto badheader;
+ }
+ seekout = lseek(fd, seekto, SEEK_SET);
+ if (seekout != seekto)
+ goto badheader;
+ if (read(fd, buf, sizeof(t_datachunk)) <
+ (int) sizeof(t_datachunk))
+ goto badheader;
+ headersize = seekto;
+ }
+ bytelimit = swap4(((t_datachunk *)buf)->dc_size, swap);
+ headersize += 8;
+ }
}
- /* seek past header and any sample frames to skip */
+ /* seek past header and any sample frames to skip */
sysrtn = lseek(fd, nchannels * bytespersamp * skipframes + headersize, 0);
if (sysrtn != nchannels * bytespersamp * skipframes + headersize)
- return (-1);
- /* copy sample format back to caller */
+ return (-1);
+ bytelimit -= nchannels * bytespersamp * skipframes;
+ if (bytelimit < 0)
+ bytelimit = 0;
+ /* copy sample format back to caller */
*p_bigendian = bigendian;
*p_nchannels = nchannels;
*p_bytespersamp = bytespersamp;
*p_bytelimit = bytelimit;
return (fd);
badheader:
- /* the header wasn't recognized. We're threadable here so let's not
- print out the error... */
+ /* the header wasn't recognized. We're threadable here so let's not
+ print out the error... */
errno = EIO;
return (-1);
}
@@ -396,60 +396,60 @@ static void soundfile_xferin(int sfchannels, int nvecs, float **vecs,
int bytesperframe = bytespersamp * sfchannels;
for (i = 0, sp = buf; i < nchannels; i++, sp += bytespersamp)
{
- if (bytespersamp == 2)
- {
- if (bigendian)
- {
- for (j = 0, sp2 = sp, fp=vecs[i] + itemsread;
- j < nitems; j++, sp2 += bytesperframe, fp++)
- *fp = SCALE * ((sp2[0] << 24) | (sp2[1] << 16));
- }
- else
- {
- for (j = 0, sp2 = sp, fp=vecs[i] + itemsread;
- j < nitems; j++, sp2 += bytesperframe, fp++)
- *fp = SCALE * ((sp2[1] << 24) | (sp2[0] << 16));
- }
- }
- else if (bytespersamp == 3)
- {
- if (bigendian)
- {
- for (j = 0, sp2 = sp, fp=vecs[i] + itemsread;
- j < nitems; j++, sp2 += bytesperframe, fp++)
- *fp = SCALE * ((sp2[0] << 24) | (sp2[1] << 16)
- | (sp2[2] << 8));
- }
- else
- {
- for (j = 0, sp2 = sp, fp=vecs[i] + itemsread;
- j < nitems; j++, sp2 += bytesperframe, fp++)
- *fp = SCALE * ((sp2[2] << 24) | (sp2[1] << 16)
- | (sp2[0] << 8));
- }
- }
- else if (bytespersamp == 4)
- {
- if (bigendian)
- {
- for (j = 0, sp2 = sp, fp=vecs[i] + itemsread;
- j < nitems; j++, sp2 += bytesperframe, fp++)
- *(long *)fp = ((sp2[0] << 24) | (sp2[1] << 16)
- | (sp2[2] << 8) | sp2[3]);
- }
- else
- {
- for (j = 0, sp2 = sp, fp=vecs[i] + itemsread;
- j < nitems; j++, sp2 += bytesperframe, fp++)
- *(long *)fp = ((sp2[3] << 24) | (sp2[2] << 16)
- | (sp2[1] << 8) | sp2[0]);
- }
- }
+ if (bytespersamp == 2)
+ {
+ if (bigendian)
+ {
+ for (j = 0, sp2 = sp, fp=vecs[i] + itemsread;
+ j < nitems; j++, sp2 += bytesperframe, fp++)
+ *fp = SCALE * ((sp2[0] << 24) | (sp2[1] << 16));
+ }
+ else
+ {
+ for (j = 0, sp2 = sp, fp=vecs[i] + itemsread;
+ j < nitems; j++, sp2 += bytesperframe, fp++)
+ *fp = SCALE * ((sp2[1] << 24) | (sp2[0] << 16));
+ }
+ }
+ else if (bytespersamp == 3)
+ {
+ if (bigendian)
+ {
+ for (j = 0, sp2 = sp, fp=vecs[i] + itemsread;
+ j < nitems; j++, sp2 += bytesperframe, fp++)
+ *fp = SCALE * ((sp2[0] << 24) | (sp2[1] << 16)
+ | (sp2[2] << 8));
+ }
+ else
+ {
+ for (j = 0, sp2 = sp, fp=vecs[i] + itemsread;
+ j < nitems; j++, sp2 += bytesperframe, fp++)
+ *fp = SCALE * ((sp2[2] << 24) | (sp2[1] << 16)
+ | (sp2[0] << 8));
+ }
+ }
+ else if (bytespersamp == 4)
+ {
+ if (bigendian)
+ {
+ for (j = 0, sp2 = sp, fp=vecs[i] + itemsread;
+ j < nitems; j++, sp2 += bytesperframe, fp++)
+ *(long *)fp = ((sp2[0] << 24) | (sp2[1] << 16)
+ | (sp2[2] << 8) | sp2[3]);
+ }
+ else
+ {
+ for (j = 0, sp2 = sp, fp=vecs[i] + itemsread;
+ j < nitems; j++, sp2 += bytesperframe, fp++)
+ *(long *)fp = ((sp2[3] << 24) | (sp2[2] << 16)
+ | (sp2[1] << 8) | sp2[0]);
+ }
+ }
}
- /* zero out other outputs */
+ /* zero out other outputs */
for (i = sfchannels; i < nvecs; i++)
- for (j = nitems, fp = vecs[i]; j--; )
- *fp++ = 0;
+ for (j = nitems, fp = vecs[i]; j--; )
+ *fp++ = 0;
}
@@ -457,14 +457,14 @@ static void soundfile_xferin(int sfchannels, int nvecs, float **vecs,
usage: write [flags] filename table ...
flags:
- -nframes <frames>
- -skip <frames>
- -bytes <bytes per sample>
- -normalize
- -nextstep
- -wave
- -big
- -little
+ -nframes <frames>
+ -skip <frames>
+ -bytes <bytes per sample>
+ -normalize
+ -nextstep
+ -wave
+ -big
+ -little
*/
/* the routine which actually does the work should LATER also be called
@@ -483,105 +483,131 @@ static int soundfiler_writeargparse(void *obj, int *p_argc, t_atom **p_argv,
int argc = *p_argc;
t_atom *argv = *p_argv;
int bytespersamp = 2, bigendian = 0,
- endianness = -1, swap, filetype = FORMAT_WAVE, normalize = 0;
+ endianness = -1, swap, filetype = -1, normalize = 0;
long onset = 0, nframes = 0x7fffffff;
t_symbol *filesym;
float rate = -1;
+
while (argc > 0 && argv->a_type == A_SYMBOL &&
- *argv->a_w.w_symbol->s_name == '-')
+ *argv->a_w.w_symbol->s_name == '-')
+ {
+ char *flag = argv->a_w.w_symbol->s_name + 1;
+ if (!strcmp(flag, "skip"))
+ {
+ if (argc < 2 || argv[1].a_type != A_FLOAT ||
+ ((onset = argv[1].a_w.w_float) < 0))
+ goto usage;
+ argc -= 2; argv += 2;
+ }
+ else if (!strcmp(flag, "nframes"))
+ {
+ if (argc < 2 || argv[1].a_type != A_FLOAT ||
+ ((nframes = argv[1].a_w.w_float) < 0))
+ goto usage;
+ argc -= 2; argv += 2;
+ }
+ else if (!strcmp(flag, "bytes"))
+ {
+ if (argc < 2 || argv[1].a_type != A_FLOAT ||
+ ((bytespersamp = argv[1].a_w.w_float) < 2) ||
+ bytespersamp > 4)
+ goto usage;
+ argc -= 2; argv += 2;
+ }
+ else if (!strcmp(flag, "normalize"))
+ {
+ normalize = 1;
+ argc -= 1; argv += 1;
+ }
+ else if (!strcmp(flag, "wave"))
+ {
+ filetype = FORMAT_WAVE;
+ argc -= 1; argv += 1;
+ }
+ else if (!strcmp(flag, "nextstep"))
+ {
+ filetype = FORMAT_NEXT;
+ argc -= 1; argv += 1;
+ }
+ else if (!strcmp(flag, "aiff"))
+ {
+ filetype = FORMAT_AIFF;
+ argc -= 1; argv += 1;
+ }
+ else if (!strcmp(flag, "big"))
+ {
+ endianness = 1;
+ argc -= 1; argv += 1;
+ }
+ else if (!strcmp(flag, "little"))
+ {
+ endianness = 0;
+ argc -= 1; argv += 1;
+ }
+ else if (!strcmp(flag, "r") || !strcmp(flag, "rate"))
+ {
+ if (argc < 2 || argv[1].a_type != A_FLOAT ||
+ ((rate = argv[1].a_w.w_float) <= 0))
+ goto usage;
+ argc -= 2; argv += 2;
+ }
+ else goto usage;
+ }
+ if (!argc || argv->a_type != A_SYMBOL)
+ goto usage;
+ filesym = argv->a_w.w_symbol;
+
+ /* check if format not specified and fill in */
+ if (filetype < 0)
{
- char *flag = argv->a_w.w_symbol->s_name + 1;
- if (!strcmp(flag, "skip"))
- {
- if (argc < 2 || argv[1].a_type != A_FLOAT ||
- ((onset = argv[1].a_w.w_float) < 0))
- goto usage;
- argc -= 2; argv += 2;
- }
- else if (!strcmp(flag, "nframes"))
- {
- if (argc < 2 || argv[1].a_type != A_FLOAT ||
- ((nframes = argv[1].a_w.w_float) < 0))
- goto usage;
- argc -= 2; argv += 2;
- }
- else if (!strcmp(flag, "bytes"))
- {
- if (argc < 2 || argv[1].a_type != A_FLOAT ||
- ((bytespersamp = argv[1].a_w.w_float) < 2) ||
- bytespersamp > 4)
- goto usage;
- argc -= 2; argv += 2;
- }
- else if (!strcmp(flag, "normalize"))
- {
- normalize = 1;
- argc -= 1; argv += 1;
- }
- else if (!strcmp(flag, "wave"))
- {
- filetype = FORMAT_WAVE;
- argc -= 1; argv += 1;
- }
- else if (!strcmp(flag, "nextstep"))
- {
- filetype = FORMAT_NEXT;
- argc -= 1; argv += 1;
- }
- else if (!strcmp(flag, "aiff"))
- {
- filetype = FORMAT_AIFF;
- argc -= 1; argv += 1;
- }
- else if (!strcmp(flag, "big"))
- {
- endianness = 1;
- argc -= 1; argv += 1;
- }
- else if (!strcmp(flag, "little"))
- {
- endianness = 0;
- argc -= 1; argv += 1;
- }
- else if (!strcmp(flag, "r") || !strcmp(flag, "rate"))
- {
- if (argc < 2 || argv[1].a_type != A_FLOAT ||
- ((rate = argv[1].a_w.w_float) <= 0))
- goto usage;
- argc -= 2; argv += 2;
- }
- else goto usage;
+ if (strlen(filesym->s_name) >= 5 &&
+ (!strcmp(filesym->s_name + strlen(filesym->s_name) - 4, ".aif") ||
+ !strcmp(filesym->s_name + strlen(filesym->s_name) - 4, ".AIF")))
+ filetype = FORMAT_AIFF;
+ if (strlen(filesym->s_name) >= 6 &&
+ (!strcmp(filesym->s_name + strlen(filesym->s_name) - 5, ".aiff") ||
+ !strcmp(filesym->s_name + strlen(filesym->s_name) - 5, ".AIFF")))
+ filetype = FORMAT_AIFF;
+ if (strlen(filesym->s_name) >= 5 &&
+ (!strcmp(filesym->s_name + strlen(filesym->s_name) - 4, ".snd") ||
+ !strcmp(filesym->s_name + strlen(filesym->s_name) - 4, ".SND")))
+ filetype = FORMAT_NEXT;
+ if (strlen(filesym->s_name) >= 4 &&
+ (!strcmp(filesym->s_name + strlen(filesym->s_name) - 3, ".au") ||
+ !strcmp(filesym->s_name + strlen(filesym->s_name) - 3, ".AU")))
+ filetype = FORMAT_NEXT;
+ if (filetype < 0)
+ filetype = FORMAT_WAVE;
}
- /* don't handle AIFF floating point samples */
+ /* don't handle AIFF floating point samples */
if (bytespersamp == 4)
{
- if (filetype == FORMAT_AIFF)
- {
- pd_error(obj, "AIFF floating-point file format unavailable");
- goto usage;
- }
+ if (filetype == FORMAT_AIFF)
+ {
+ pd_error(obj, "AIFF floating-point file format unavailable");
+ goto usage;
+ }
}
- /* for WAVE force little endian; for nextstep use machine native */
+ /* for WAVE force little endian; for nextstep use machine native */
if (filetype == FORMAT_WAVE)
{
- bigendian = 0;
- if (endianness == 1)
- pd_error(obj, "WAVE file forced to little endian");
+ bigendian = 0;
+ if (endianness == 1)
+ pd_error(obj, "WAVE file forced to little endian");
}
else if (filetype == FORMAT_AIFF)
{
- bigendian = 1;
- if (endianness == 0)
- pd_error(obj, "AIFF file forced to big endian");
+ bigendian = 1;
+ if (endianness == 0)
+ pd_error(obj, "AIFF file forced to big endian");
}
else if (endianness == -1)
{
- bigendian = garray_ambigendian();
+ bigendian = garray_ambigendian();
}
+ else bigendian = endianness;
swap = (bigendian != garray_ambigendian());
- if (!argc || argv->a_type != A_SYMBOL)
- goto usage;
- filesym = argv->a_w.w_symbol;
+
argc--; argv++;
*p_argc = argc;
@@ -616,76 +642,76 @@ static int create_soundfile(t_canvas *canvas, const char *filename,
if (filetype == FORMAT_NEXT)
{
- if (strcmp(filenamebuf + strlen(filenamebuf)-4, ".snd"))
- strcat(filenamebuf, ".snd");
- if (bigendian)
- strncpy(nexthdr->ns_fileid, ".snd", 4);
- else strncpy(nexthdr->ns_fileid, "dns.", 4);
- nexthdr->ns_onset = swap4(sizeof(*nexthdr), swap);
- nexthdr->ns_length = 0;
- nexthdr->ns_format = swap4((bytespersamp == 3 ? NS_FORMAT_LINEAR_24 :
- (bytespersamp == 4 ? NS_FORMAT_FLOAT : NS_FORMAT_LINEAR_16)), swap);;
- nexthdr->ns_sr = swap4(samplerate, swap);
- nexthdr->ns_nchans = swap4(nchannels, swap);
- strcpy(nexthdr->ns_info, "Pd ");
- swapstring(nexthdr->ns_info, swap);
- headersize = sizeof(t_nextstep);
+ if (strcmp(filenamebuf + strlen(filenamebuf)-4, ".snd"))
+ strcat(filenamebuf, ".snd");
+ if (bigendian)
+ strncpy(nexthdr->ns_fileid, ".snd", 4);
+ else strncpy(nexthdr->ns_fileid, "dns.", 4);
+ nexthdr->ns_onset = swap4(sizeof(*nexthdr), swap);
+ nexthdr->ns_length = 0;
+ nexthdr->ns_format = swap4((bytespersamp == 3 ? NS_FORMAT_LINEAR_24 :
+ (bytespersamp == 4 ? NS_FORMAT_FLOAT : NS_FORMAT_LINEAR_16)), swap);
+ nexthdr->ns_sr = swap4(samplerate, swap);
+ nexthdr->ns_nchans = swap4(nchannels, swap);
+ strcpy(nexthdr->ns_info, "Pd ");
+ swapstring(nexthdr->ns_info, swap);
+ headersize = sizeof(t_nextstep);
}
else if (filetype == FORMAT_AIFF)
{
- long datasize = nframes * nchannels * bytespersamp;
- long longtmp;
- static unsigned char dogdoo[] =
- {0x40, 0x0e, 0xac, 0x44, 0, 0, 0, 0, 0, 0, 'S', 'S', 'N', 'D'};
- if (strcmp(filenamebuf + strlen(filenamebuf)-4, ".aif") &&
- strcmp(filenamebuf + strlen(filenamebuf)-5, ".aiff"))
- strcat(filenamebuf, ".aif");
- strncpy(aiffhdr->a_fileid, "FORM", 4);
- aiffhdr->a_chunksize = swap4(datasize + sizeof(*aiffhdr) + 4, swap);
- strncpy(aiffhdr->a_aiffid, "AIFF", 4);
- strncpy(aiffhdr->a_fmtid, "COMM", 4);
- aiffhdr->a_fmtchunksize = swap4(18, swap);
- aiffhdr->a_nchannels = swap2(nchannels, swap);
- longtmp = swap4(nframes, swap);
- memcpy(&aiffhdr->a_nframeshi, &longtmp, 4);
- aiffhdr->a_bitspersamp = swap2(8 * bytespersamp, swap);
- memcpy(aiffhdr->a_samprate, dogdoo, sizeof(dogdoo));
- longtmp = swap4(datasize, swap);
- memcpy(aiffhdr->a_samprate + sizeof(dogdoo), &longtmp, 4);
- headersize = AIFFPLUS;
+ long datasize = nframes * nchannels * bytespersamp;
+ long longtmp;
+ static unsigned char dogdoo[] =
+ {0x40, 0x0e, 0xac, 0x44, 0, 0, 0, 0, 0, 0, 'S', 'S', 'N', 'D'};
+ if (strcmp(filenamebuf + strlen(filenamebuf)-4, ".aif") &&
+ strcmp(filenamebuf + strlen(filenamebuf)-5, ".aiff"))
+ strcat(filenamebuf, ".aif");
+ strncpy(aiffhdr->a_fileid, "FORM", 4);
+ aiffhdr->a_chunksize = swap4(datasize + sizeof(*aiffhdr) + 4, swap);
+ strncpy(aiffhdr->a_aiffid, "AIFF", 4);
+ strncpy(aiffhdr->a_fmtid, "COMM", 4);
+ aiffhdr->a_fmtchunksize = swap4(18, swap);
+ aiffhdr->a_nchannels = swap2(nchannels, swap);
+ longtmp = swap4(nframes, swap);
+ memcpy(&aiffhdr->a_nframeshi, &longtmp, 4);
+ aiffhdr->a_bitspersamp = swap2(8 * bytespersamp, swap);
+ memcpy(aiffhdr->a_samprate, dogdoo, sizeof(dogdoo));
+ longtmp = swap4(datasize, swap);
+ memcpy(aiffhdr->a_samprate + sizeof(dogdoo), &longtmp, 4);
+ headersize = AIFFPLUS;
}
else /* WAVE format */
{
- long datasize = nframes * nchannels * bytespersamp;
- if (strcmp(filenamebuf + strlen(filenamebuf)-4, ".wav"))
- strcat(filenamebuf, ".wav");
- strncpy(wavehdr->w_fileid, "RIFF", 4);
- wavehdr->w_chunksize = swap4(datasize + sizeof(*wavehdr) - 8, swap);
- strncpy(wavehdr->w_waveid, "WAVE", 4);
- strncpy(wavehdr->w_fmtid, "fmt ", 4);
- wavehdr->w_fmtchunksize = swap4(16, swap);
- wavehdr->w_fmttag =
- swap2((bytespersamp == 4 ? WAV_FLOAT : WAV_INT), swap);
- wavehdr->w_nchannels = swap2(nchannels, swap);
- wavehdr->w_samplespersec = swap4(samplerate, swap);
- wavehdr->w_navgbytespersec =
- swap4((int)(samplerate * nchannels * bytespersamp), swap);
- wavehdr->w_nblockalign = swap2(nchannels * bytespersamp, swap);
- wavehdr->w_nbitspersample = swap2(8 * bytespersamp, swap);
- strncpy(wavehdr->w_datachunkid, "data", 4);
- wavehdr->w_datachunksize = swap4(datasize, swap);
- headersize = sizeof(t_wave);
+ long datasize = nframes * nchannels * bytespersamp;
+ if (strcmp(filenamebuf + strlen(filenamebuf)-4, ".wav"))
+ strcat(filenamebuf, ".wav");
+ strncpy(wavehdr->w_fileid, "RIFF", 4);
+ wavehdr->w_chunksize = swap4(datasize + sizeof(*wavehdr) - 8, swap);
+ strncpy(wavehdr->w_waveid, "WAVE", 4);
+ strncpy(wavehdr->w_fmtid, "fmt ", 4);
+ wavehdr->w_fmtchunksize = swap4(16, swap);
+ wavehdr->w_fmttag =
+ swap2((bytespersamp == 4 ? WAV_FLOAT : WAV_INT), swap);
+ wavehdr->w_nchannels = swap2(nchannels, swap);
+ wavehdr->w_samplespersec = swap4(samplerate, swap);
+ wavehdr->w_navgbytespersec =
+ swap4((int)(samplerate * nchannels * bytespersamp), swap);
+ wavehdr->w_nblockalign = swap2(nchannels * bytespersamp, swap);
+ wavehdr->w_nbitspersample = swap2(8 * bytespersamp, swap);
+ strncpy(wavehdr->w_datachunkid, "data", 4);
+ wavehdr->w_datachunksize = swap4(datasize, swap);
+ headersize = sizeof(t_wave);
}
canvas_makefilename(canvas, filenamebuf, buf2, MAXPDSTRING);
sys_bashfilename(buf2, buf2);
if ((fd = open(buf2, BINCREATE, 0666)) < 0)
- return (-1);
+ return (-1);
if (write(fd, headerbuf, headersize) < headersize)
{
- close (fd);
- return (-1);
+ close (fd);
+ return (-1);
}
return (fd);
}
@@ -695,53 +721,53 @@ static void soundfile_finishwrite(void *obj, char *filename, int fd,
{
if (itemswritten < nframes)
{
- if (nframes < 0x7fffffff)
- pd_error(obj, "soundfiler_write: %d out of %d bytes written",
- itemswritten, nframes);
- /* try to fix size fields in header */
- if (filetype == FORMAT_WAVE)
- {
- long datasize = itemswritten * bytesperframe, mofo;
-
- if (lseek(fd,
- ((char *)(&((t_wave *)0)->w_chunksize)) - (char *)0,
- SEEK_SET) == 0)
- goto baddonewrite;
- mofo = swap4(datasize + sizeof(t_wave) - 8, swap);
- if (write(fd, (char *)(&mofo), 4) < 4)
- goto baddonewrite;
- if (lseek(fd,
- ((char *)(&((t_wave *)0)->w_datachunksize)) - (char *)0,
- SEEK_SET) == 0)
- goto baddonewrite;
- mofo = swap4(datasize, swap);
- if (write(fd, (char *)(&mofo), 4) < 4)
- goto baddonewrite;
- }
- if (filetype == FORMAT_AIFF)
- {
- long mofo;
- if (lseek(fd,
- ((char *)(&((t_aiff *)0)->a_nframeshi)) - (char *)0,
- SEEK_SET) == 0)
- goto baddonewrite;
- mofo = swap4(nframes, swap);
- if (write(fd, (char *)(&mofo), 4) < 4)
- goto baddonewrite;
- }
- if (filetype == FORMAT_NEXT)
- {
- /* do it the lazy way: just set the size field to 'unknown size'*/
- uint32 nextsize = 0xffffffff;
- if (lseek(fd, 8, SEEK_SET) == 0)
- {
- goto baddonewrite;
- }
- if (write(fd, &nextsize, 4) < 4)
- {
- goto baddonewrite;
- }
- }
+ if (nframes < 0x7fffffff)
+ pd_error(obj, "soundfiler_write: %d out of %d bytes written",
+ itemswritten, nframes);
+ /* try to fix size fields in header */
+ if (filetype == FORMAT_WAVE)
+ {
+ long datasize = itemswritten * bytesperframe, mofo;
+
+ if (lseek(fd,
+ ((char *)(&((t_wave *)0)->w_chunksize)) - (char *)0,
+ SEEK_SET) == 0)
+ goto baddonewrite;
+ mofo = swap4(datasize + sizeof(t_wave) - 8, swap);
+ if (write(fd, (char *)(&mofo), 4) < 4)
+ goto baddonewrite;
+ if (lseek(fd,
+ ((char *)(&((t_wave *)0)->w_datachunksize)) - (char *)0,
+ SEEK_SET) == 0)
+ goto baddonewrite;
+ mofo = swap4(datasize, swap);
+ if (write(fd, (char *)(&mofo), 4) < 4)
+ goto baddonewrite;
+ }
+ if (filetype == FORMAT_AIFF)
+ {
+ long mofo;
+ if (lseek(fd,
+ ((char *)(&((t_aiff *)0)->a_nframeshi)) - (char *)0,
+ SEEK_SET) == 0)
+ goto baddonewrite;
+ mofo = swap4(nframes, swap);
+ if (write(fd, (char *)(&mofo), 4) < 4)
+ goto baddonewrite;
+ }
+ if (filetype == FORMAT_NEXT)
+ {
+ /* do it the lazy way: just set the size field to 'unknown size'*/
+ uint32 nextsize = 0xffffffff;
+ if (lseek(fd, 8, SEEK_SET) == 0)
+ {
+ goto baddonewrite;
+ }
+ if (write(fd, &nextsize, 4) < 4)
+ {
+ goto baddonewrite;
+ }
+ }
}
return;
baddonewrite:
@@ -759,107 +785,107 @@ static void soundfile_xferout(int nchannels, float **vecs,
long xx;
for (i = 0, sp = buf; i < nchannels; i++, sp += bytespersamp)
{
- if (bytespersamp == 2)
- {
- float ff = normalfactor * 32768.;
- if (bigendian)
- {
- for (j = 0, sp2 = sp, fp = vecs[i] + onset;
- j < nitems; j++, sp2 += bytesperframe, fp++)
- {
- int xx = 32768. + (*fp * ff);
- xx -= 32768;
- if (xx < -32767)
- xx = -32767;
- if (xx > 32767)
- xx = 32767;
- sp2[0] = (xx >> 8);
- sp2[1] = xx;
- }
- }
- else
- {
- for (j = 0, sp2 = sp, fp=vecs[i] + onset;
- j < nitems; j++, sp2 += bytesperframe, fp++)
- {
- int xx = 32768. + (*fp * ff);
- xx -= 32768;
- if (xx < -32767)
- xx = -32767;
- if (xx > 32767)
- xx = 32767;
- sp2[1] = (xx >> 8);
- sp2[0] = xx;
- }
- }
- }
- else if (bytespersamp == 3)
- {
- float ff = normalfactor * 8388608.;
- if (bigendian)
- {
- for (j = 0, sp2 = sp, fp=vecs[i] + onset;
- j < nitems; j++, sp2 += bytesperframe, fp++)
- {
- int xx = 8388608. + (*fp * ff);
- xx -= 8388608;
- if (xx < -8388607)
- xx = -8388607;
- if (xx > 8388607)
- xx = 8388607;
- sp2[0] = (xx >> 16);
- sp2[1] = (xx >> 8);
- sp2[2] = xx;
- }
- }
- else
- {
- for (j = 0, sp2 = sp, fp=vecs[i] + onset;
- j < nitems; j++, sp2 += bytesperframe, fp++)
- {
- int xx = 8388608. + (*fp * ff);
- xx -= 8388608;
- if (xx < -8388607)
- xx = -8388607;
- if (xx > 8388607)
- xx = 8388607;
- sp2[2] = (xx >> 16);
- sp2[1] = (xx >> 8);
- sp2[0] = xx;
- }
- }
- }
- else if (bytespersamp == 4)
- {
- if (bigendian)
- {
- for (j = 0, sp2 = sp, fp=vecs[i] + onset;
- j < nitems; j++, sp2 += bytesperframe, fp++)
- {
- float f2 = *fp * normalfactor;
- xx = *(long *)&f2;
- sp2[0] = (xx >> 24); sp2[1] = (xx >> 16);
- sp2[2] = (xx >> 8); sp2[3] = xx;
- }
- }
- else
- {
- for (j = 0, sp2 = sp, fp=vecs[i] + onset;
- j < nitems; j++, sp2 += bytesperframe, fp++)
- {
- float f2 = *fp * normalfactor;
- xx = *(long *)&f2;
- sp2[3] = (xx >> 24); sp2[2] = (xx >> 16);
- sp2[1] = (xx >> 8); sp2[0] = xx;
- }
- }
- }
+ if (bytespersamp == 2)
+ {
+ float ff = normalfactor * 32768.;
+ if (bigendian)
+ {
+ for (j = 0, sp2 = sp, fp = vecs[i] + onset;
+ j < nitems; j++, sp2 += bytesperframe, fp++)
+ {
+ int xx = 32768. + (*fp * ff);
+ xx -= 32768;
+ if (xx < -32767)
+ xx = -32767;
+ if (xx > 32767)
+ xx = 32767;
+ sp2[0] = (xx >> 8);
+ sp2[1] = xx;
+ }
+ }
+ else
+ {
+ for (j = 0, sp2 = sp, fp=vecs[i] + onset;
+ j < nitems; j++, sp2 += bytesperframe, fp++)
+ {
+ int xx = 32768. + (*fp * ff);
+ xx -= 32768;
+ if (xx < -32767)
+ xx = -32767;
+ if (xx > 32767)
+ xx = 32767;
+ sp2[1] = (xx >> 8);
+ sp2[0] = xx;
+ }
+ }
+ }
+ else if (bytespersamp == 3)
+ {
+ float ff = normalfactor * 8388608.;
+ if (bigendian)
+ {
+ for (j = 0, sp2 = sp, fp=vecs[i] + onset;
+ j < nitems; j++, sp2 += bytesperframe, fp++)
+ {
+ int xx = 8388608. + (*fp * ff);
+ xx -= 8388608;
+ if (xx < -8388607)
+ xx = -8388607;
+ if (xx > 8388607)
+ xx = 8388607;
+ sp2[0] = (xx >> 16);
+ sp2[1] = (xx >> 8);
+ sp2[2] = xx;
+ }
+ }
+ else
+ {
+ for (j = 0, sp2 = sp, fp=vecs[i] + onset;
+ j < nitems; j++, sp2 += bytesperframe, fp++)
+ {
+ int xx = 8388608. + (*fp * ff);
+ xx -= 8388608;
+ if (xx < -8388607)
+ xx = -8388607;
+ if (xx > 8388607)
+ xx = 8388607;
+ sp2[2] = (xx >> 16);
+ sp2[1] = (xx >> 8);
+ sp2[0] = xx;
+ }
+ }
+ }
+ else if (bytespersamp == 4)
+ {
+ if (bigendian)
+ {
+ for (j = 0, sp2 = sp, fp=vecs[i] + onset;
+ j < nitems; j++, sp2 += bytesperframe, fp++)
+ {
+ float f2 = *fp * normalfactor;
+ xx = *(long *)&f2;
+ sp2[0] = (xx >> 24); sp2[1] = (xx >> 16);
+ sp2[2] = (xx >> 8); sp2[3] = xx;
+ }
+ }
+ else
+ {
+ for (j = 0, sp2 = sp, fp=vecs[i] + onset;
+ j < nitems; j++, sp2 += bytesperframe, fp++)
+ {
+ float f2 = *fp * normalfactor;
+ xx = *(long *)&f2;
+ sp2[3] = (xx >> 24); sp2[2] = (xx >> 16);
+ sp2[1] = (xx >> 8); sp2[0] = xx;
+ }
+ }
+ }
}
}
/* ------- soundfiler - reads and writes soundfiles to/from "garrays" ---- */
-#define DEFMAXSIZE 4000000 /* default maximum 16 MB per channel */
+#define DEFMAXSIZE 4000000 /* default maximum 16 MB per channel */
#define SAMPBUFSIZE 1024
@@ -883,21 +909,21 @@ static t_soundfiler *soundfiler_new(void)
usage: read [flags] filename table ...
flags:
- -skip <frames> ... frames to skip in file
- -nframes <frames>
- -onset <frames> ... onset in table to read into (NOT DONE YET)
- -raw <headersize channels bytes endian>
- -resize
- -maxsize <max-size>
+ -skip <frames> ... frames to skip in file
+ -nframes <frames>
+ -onset <frames> ... onset in table to read into (NOT DONE YET)
+ -raw <headersize channels bytes endian>
+ -resize
+ -maxsize <max-size>
*/
static void soundfiler_read(t_soundfiler *x, t_symbol *s,
int argc, t_atom *argv)
{
int headersize = -1, channels = 0, bytespersamp = 0, bigendian = 0,
- resize = 0, i, j;
+ resize = 0, i, j;
long skipframes = 0, nframes = 0, finalsize = 0, itemsleft,
- maxsize = DEFMAXSIZE, itemsread = 0, bytelimit = 0x7fffffff;
+ maxsize = DEFMAXSIZE, itemsread = 0, bytelimit = 0x7fffffff;
int fd = -1;
char endianness, *filename;
t_garray *garrays[MAXSFCHANS];
@@ -906,173 +932,173 @@ static void soundfiler_read(t_soundfiler *x, t_symbol *s,
int bufframes, nitems;
FILE *fp;
while (argc > 0 && argv->a_type == A_SYMBOL &&
- *argv->a_w.w_symbol->s_name == '-')
+ *argv->a_w.w_symbol->s_name == '-')
{
- char *flag = argv->a_w.w_symbol->s_name + 1;
- if (!strcmp(flag, "skip"))
- {
- if (argc < 2 || argv[1].a_type != A_FLOAT ||
- ((skipframes = argv[1].a_w.w_float) < 0))
- goto usage;
- argc -= 2; argv += 2;
- }
- else if (!strcmp(flag, "nframes"))
- {
- if (argc < 2 || argv[1].a_type != A_FLOAT ||
- ((nframes = argv[1].a_w.w_float) < 0))
- goto usage;
- argc -= 2; argv += 2;
- }
- else if (!strcmp(flag, "raw"))
- {
- if (argc < 5 ||
- argv[1].a_type != A_FLOAT ||
- ((headersize = argv[1].a_w.w_float) < 0) ||
- argv[2].a_type != A_FLOAT ||
- ((channels = argv[2].a_w.w_float) < 1) ||
- (channels > MAXSFCHANS) ||
- argv[3].a_type != A_FLOAT ||
- ((bytespersamp = argv[3].a_w.w_float) < 2) ||
- (bytespersamp > 4) ||
- argv[4].a_type != A_SYMBOL ||
- ((endianness = argv[4].a_w.w_symbol->s_name[0]) != 'b'
- && endianness != 'l' && endianness != 'n'))
- goto usage;
- if (endianness == 'b')
- bigendian = 1;
- else if (endianness == 'l')
- bigendian = 0;
- else
- bigendian = garray_ambigendian();
- argc -= 5; argv += 5;
- }
- else if (!strcmp(flag, "resize"))
- {
- resize = 1;
- argc -= 1; argv += 1;
- }
- else if (!strcmp(flag, "maxsize"))
- {
- if (argc < 2 || argv[1].a_type != A_FLOAT ||
- ((maxsize = argv[1].a_w.w_float) < 0))
- goto usage;
- resize = 1; /* maxsize implies resize. */
- argc -= 2; argv += 2;
- }
- else goto usage;
+ char *flag = argv->a_w.w_symbol->s_name + 1;
+ if (!strcmp(flag, "skip"))
+ {
+ if (argc < 2 || argv[1].a_type != A_FLOAT ||
+ ((skipframes = argv[1].a_w.w_float) < 0))
+ goto usage;
+ argc -= 2; argv += 2;
+ }
+ else if (!strcmp(flag, "nframes"))
+ {
+ if (argc < 2 || argv[1].a_type != A_FLOAT ||
+ ((nframes = argv[1].a_w.w_float) < 0))
+ goto usage;
+ argc -= 2; argv += 2;
+ }
+ else if (!strcmp(flag, "raw"))
+ {
+ if (argc < 5 ||
+ argv[1].a_type != A_FLOAT ||
+ ((headersize = argv[1].a_w.w_float) < 0) ||
+ argv[2].a_type != A_FLOAT ||
+ ((channels = argv[2].a_w.w_float) < 1) ||
+ (channels > MAXSFCHANS) ||
+ argv[3].a_type != A_FLOAT ||
+ ((bytespersamp = argv[3].a_w.w_float) < 2) ||
+ (bytespersamp > 4) ||
+ argv[4].a_type != A_SYMBOL ||
+ ((endianness = argv[4].a_w.w_symbol->s_name[0]) != 'b'
+ && endianness != 'l' && endianness != 'n'))
+ goto usage;
+ if (endianness == 'b')
+ bigendian = 1;
+ else if (endianness == 'l')
+ bigendian = 0;
+ else
+ bigendian = garray_ambigendian();
+ argc -= 5; argv += 5;
+ }
+ else if (!strcmp(flag, "resize"))
+ {
+ resize = 1;
+ argc -= 1; argv += 1;
+ }
+ else if (!strcmp(flag, "maxsize"))
+ {
+ if (argc < 2 || argv[1].a_type != A_FLOAT ||
+ ((maxsize = argv[1].a_w.w_float) < 0))
+ goto usage;
+ resize = 1; /* maxsize implies resize. */
+ argc -= 2; argv += 2;
+ }
+ else goto usage;
}
if (argc < 2 || argc > MAXSFCHANS + 1 || argv[0].a_type != A_SYMBOL)
- goto usage;
+ goto usage;
filename = argv[0].a_w.w_symbol->s_name;
argc--; argv++;
for (i = 0; i < argc; i++)
{
- int vecsize;
- if (argv[i].a_type != A_SYMBOL)
- goto usage;
- if (!(garrays[i] =
- (t_garray *)pd_findbyclass(argv[i].a_w.w_symbol, garray_class)))
- {
- pd_error(x, "%s: no such table", argv[i].a_w.w_symbol->s_name);
- goto done;
- }
- else if (!garray_getfloatarray(garrays[i], &vecsize, &vecs[i]))
- error("%s: bad template for tabwrite",
- argv[i].a_w.w_symbol->s_name);
- if (finalsize && finalsize != vecsize && !resize)
- {
- post("soundfiler_read: arrays have different lengths; resizing...");
- resize = 1;
- }
- finalsize = vecsize;
+ int vecsize;
+ if (argv[i].a_type != A_SYMBOL)
+ goto usage;
+ if (!(garrays[i] =
+ (t_garray *)pd_findbyclass(argv[i].a_w.w_symbol, garray_class)))
+ {
+ pd_error(x, "%s: no such table", argv[i].a_w.w_symbol->s_name);
+ goto done;
+ }
+ else if (!garray_getfloatarray(garrays[i], &vecsize, &vecs[i]))
+ error("%s: bad template for tabwrite",
+ argv[i].a_w.w_symbol->s_name);
+ if (finalsize && finalsize != vecsize && !resize)
+ {
+ post("soundfiler_read: arrays have different lengths; resizing...");
+ resize = 1;
+ }
+ finalsize = vecsize;
}
fd = open_soundfile(canvas_getdir(x->x_canvas)->s_name, filename,
- headersize, &bytespersamp, &bigendian, &channels, &bytelimit,
- skipframes);
+ headersize, &bytespersamp, &bigendian, &channels, &bytelimit,
+ skipframes);
if (fd < 0)
{
- pd_error(x, "soundfiler_read: %s: %s", filename, (errno == EIO ?
- "unknown or bad header format" : strerror(errno)));
- goto done;
+ pd_error(x, "soundfiler_read: %s: %s", filename, (errno == EIO ?
+ "unknown or bad header format" : strerror(errno)));
+ goto done;
}
if (resize)
{
- /* figure out what to resize to */
- long poswas, eofis, framesinfile;
-
- poswas = lseek(fd, 0, SEEK_CUR);
- eofis = lseek(fd, 0, SEEK_END);
- if (poswas < 0 || eofis < 0)
- {
- pd_error(x, "lseek failed");
- goto done;
- }
- lseek(fd, poswas, SEEK_SET);
- framesinfile = (eofis - poswas) / (channels * bytespersamp);
- if (framesinfile > maxsize)
- {
- pd_error(x, "soundfiler_read: truncated to %d elements", maxsize);
- framesinfile = maxsize;
- }
- if (framesinfile > bytelimit / bytespersamp)
- framesinfile = bytelimit / bytespersamp;
- finalsize = framesinfile;
- for (i = 0; i < argc; i++)
- {
- int vecsize;
-
- garray_resize(garrays[i], finalsize);
- /* for sanity's sake let's clear the save-in-patch flag here */
- garray_setsaveit(garrays[i], 0);
- garray_getfloatarray(garrays[i], &vecsize, &vecs[i]);
- /* if the resize failed, garray_resize reported the error */
- if (vecsize != framesinfile)
- {
- pd_error(x, "resize failed");
- goto done;
- }
- }
+ /* figure out what to resize to */
+ long poswas, eofis, framesinfile;
+
+ poswas = lseek(fd, 0, SEEK_CUR);
+ eofis = lseek(fd, 0, SEEK_END);
+ if (poswas < 0 || eofis < 0)
+ {
+ pd_error(x, "lseek failed");
+ goto done;
+ }
+ lseek(fd, poswas, SEEK_SET);
+ framesinfile = (eofis - poswas) / (channels * bytespersamp);
+ if (framesinfile > maxsize)
+ {
+ pd_error(x, "soundfiler_read: truncated to %d elements", maxsize);
+ framesinfile = maxsize;
+ }
+ if (framesinfile > bytelimit / (channels * bytespersamp))
+ framesinfile = bytelimit / (channels * bytespersamp);
+ finalsize = framesinfile;
+ for (i = 0; i < argc; i++)
+ {
+ int vecsize;
+
+ garray_resize(garrays[i], finalsize);
+ /* for sanity's sake let's clear the save-in-patch flag here */
+ garray_setsaveit(garrays[i], 0);
+ garray_getfloatarray(garrays[i], &vecsize, &vecs[i]);
+ /* if the resize failed, garray_resize reported the error */
+ if (vecsize != framesinfile)
+ {
+ pd_error(x, "resize failed");
+ goto done;
+ }
+ }
}
if (!finalsize) finalsize = 0x7fffffff;
- if (finalsize > bytelimit / bytespersamp)
- finalsize = bytelimit / bytespersamp;
+ if (finalsize > bytelimit / (channels * bytespersamp))
+ finalsize = bytelimit / (channels * bytespersamp);
fp = fdopen(fd, "rb");
bufframes = SAMPBUFSIZE / (channels * bytespersamp);
for (itemsread = 0; itemsread < finalsize; )
{
- int thisread = finalsize - itemsread;
- thisread = (thisread > bufframes ? bufframes : thisread);
- nitems = fread(sampbuf, channels * bytespersamp, thisread, fp);
- if (nitems <= 0) break;
- soundfile_xferin(channels, argc, vecs, itemsread,
- (unsigned char *)sampbuf, nitems, bytespersamp, bigendian);
- itemsread += nitems;
+ int thisread = finalsize - itemsread;
+ thisread = (thisread > bufframes ? bufframes : thisread);
+ nitems = fread(sampbuf, channels * bytespersamp, thisread, fp);
+ if (nitems <= 0) break;
+ soundfile_xferin(channels, argc, vecs, itemsread,
+ (unsigned char *)sampbuf, nitems, bytespersamp, bigendian);
+ itemsread += nitems;
}
- /* zero out remaining elements of vectors */
-
+ /* zero out remaining elements of vectors */
+
for (i = 0; i < argc; i++)
{
- int nzero, vecsize;
- garray_getfloatarray(garrays[i], &vecsize, &vecs[i]);
- for (j = itemsread; j < vecsize; j++)
- vecs[i][j] = 0;
+ int nzero, vecsize;
+ garray_getfloatarray(garrays[i], &vecsize, &vecs[i]);
+ for (j = itemsread; j < vecsize; j++)
+ vecs[i][j] = 0;
}
- /* zero out vectors in excess of number of channels */
+ /* zero out vectors in excess of number of channels */
for (i = channels; i < argc; i++)
{
- int vecsize;
- float *foo;
- garray_getfloatarray(garrays[i], &vecsize, &foo);
- for (j = 0; j < vecsize; j++)
- foo[j] = 0;
+ int vecsize;
+ float *foo;
+ garray_getfloatarray(garrays[i], &vecsize, &foo);
+ for (j = 0; j < vecsize; j++)
+ foo[j] = 0;
}
- /* do all graphics updates */
+ /* do all graphics updates */
for (i = 0; i < argc; i++)
- garray_redraw(garrays[i]);
+ garray_redraw(garrays[i]);
fclose(fp);
fd = -1;
goto done;
@@ -1082,7 +1108,7 @@ usage:
post("-raw <headerbytes> <channels> <bytespersamp> <endian (b, l, or n)>.");
done:
if (fd >= 0)
- close (fd);
+ close (fd);
outlet_float(x->x_obj.ob_outlet, (float)itemsread);
}
@@ -1093,9 +1119,9 @@ long soundfiler_dowrite(void *obj, t_canvas *canvas,
int argc, t_atom *argv)
{
int headersize, bytespersamp, bigendian,
- endianness, swap, filetype, normalize, i, j, nchannels;
+ endianness, swap, filetype, normalize, i, j, nchannels;
long onset, nframes, itemsleft,
- maxsize = DEFMAXSIZE, itemswritten = 0;
+ maxsize = DEFMAXSIZE, itemswritten = 0;
t_garray *garrays[MAXSFCHANS];
t_float *vecs[MAXSFCHANS];
char sampbuf[SAMPBUFSIZE];
@@ -1105,89 +1131,89 @@ long soundfiler_dowrite(void *obj, t_canvas *canvas,
t_symbol *filesym;
if (soundfiler_writeargparse(obj, &argc, &argv, &filesym, &filetype,
- &bytespersamp, &swap, &bigendian, &normalize, &onset, &nframes,
- &samplerate))
- goto usage;
+ &bytespersamp, &swap, &bigendian, &normalize, &onset, &nframes,
+ &samplerate))
+ goto usage;
nchannels = argc;
if (nchannels < 1 || nchannels > MAXSFCHANS)
- goto usage;
+ goto usage;
if (samplerate < 0)
- samplerate = sys_getsr();
+ samplerate = sys_getsr();
for (i = 0; i < nchannels; i++)
{
- int vecsize;
- if (argv[i].a_type != A_SYMBOL)
- goto usage;
- if (!(garrays[i] =
- (t_garray *)pd_findbyclass(argv[i].a_w.w_symbol, garray_class)))
- {
- pd_error(obj, "%s: no such table", argv[i].a_w.w_symbol->s_name);
- goto fail;
- }
- else if (!garray_getfloatarray(garrays[i], &vecsize, &vecs[i]))
- error("%s: bad template for tabwrite",
- argv[i].a_w.w_symbol->s_name);
- if (nframes > vecsize - onset)
- nframes = vecsize - onset;
-
- for (j = 0; j < vecsize; j++)
- {
- if (vecs[i][j] > biggest)
- biggest = vecs[i][j];
- else if (-vecs[i][j] > biggest)
- biggest = -vecs[i][j];
- }
+ int vecsize;
+ if (argv[i].a_type != A_SYMBOL)
+ goto usage;
+ if (!(garrays[i] =
+ (t_garray *)pd_findbyclass(argv[i].a_w.w_symbol, garray_class)))
+ {
+ pd_error(obj, "%s: no such table", argv[i].a_w.w_symbol->s_name);
+ goto fail;
+ }
+ else if (!garray_getfloatarray(garrays[i], &vecsize, &vecs[i]))
+ error("%s: bad template for tabwrite",
+ argv[i].a_w.w_symbol->s_name);
+ if (nframes > vecsize - onset)
+ nframes = vecsize - onset;
+
+ for (j = 0; j < vecsize; j++)
+ {
+ if (vecs[i][j] > biggest)
+ biggest = vecs[i][j];
+ else if (-vecs[i][j] > biggest)
+ biggest = -vecs[i][j];
+ }
}
if (nframes <= 0)
{
- pd_error(obj, "soundfiler_write: no samples at onset %ld", onset);
- goto fail;
+ pd_error(obj, "soundfiler_write: no samples at onset %ld", onset);
+ goto fail;
}
if ((fd = create_soundfile(canvas, filesym->s_name, filetype,
- nframes, bytespersamp, bigendian, nchannels,
- swap, samplerate)) < 0)
+ nframes, bytespersamp, bigendian, nchannels,
+ swap, samplerate)) < 0)
{
- post("%s: %s\n", filesym->s_name, strerror(errno));
- goto fail;
+ post("%s: %s\n", filesym->s_name, strerror(errno));
+ goto fail;
}
if (!normalize)
{
- if ((bytespersamp != 4) && (biggest > 1))
- {
- post("%s: normalizing max amplitude %f to 1", filesym->s_name, biggest);
- normalize = 1;
- }
- else post("%s: biggest amplitude = %f", filesym->s_name, biggest);
+ if ((bytespersamp != 4) && (biggest > 1))
+ {
+ post("%s: normalizing max amplitude %f to 1", filesym->s_name, biggest);
+ normalize = 1;
+ }
+ else post("%s: biggest amplitude = %f", filesym->s_name, biggest);
}
if (normalize)
- normfactor = (biggest > 0 ? 32767./(32768. * biggest) : 1);
+ normfactor = (biggest > 0 ? 32767./(32768. * biggest) : 1);
else normfactor = 1;
bufframes = SAMPBUFSIZE / (nchannels * bytespersamp);
for (itemswritten = 0; itemswritten < nframes; )
{
- int thiswrite = nframes - itemswritten, nitems, nbytes;
- thiswrite = (thiswrite > bufframes ? bufframes : thiswrite);
- soundfile_xferout(argc, vecs, (unsigned char *)sampbuf, thiswrite,
- onset, bytespersamp, bigendian, normfactor);
- nbytes = write(fd, sampbuf, nchannels * bytespersamp * thiswrite);
- if (nbytes < nchannels * bytespersamp * thiswrite)
- {
- post("%s: %s", filesym->s_name, strerror(errno));
- if (nbytes > 0)
- itemswritten += nbytes / (nchannels * bytespersamp);
- break;
- }
- itemswritten += thiswrite;
- onset += thiswrite;
+ int thiswrite = nframes - itemswritten, nitems, nbytes;
+ thiswrite = (thiswrite > bufframes ? bufframes : thiswrite);
+ soundfile_xferout(argc, vecs, (unsigned char *)sampbuf, thiswrite,
+ onset, bytespersamp, bigendian, normfactor);
+ nbytes = write(fd, sampbuf, nchannels * bytespersamp * thiswrite);
+ if (nbytes < nchannels * bytespersamp * thiswrite)
+ {
+ post("%s: %s", filesym->s_name, strerror(errno));
+ if (nbytes > 0)
+ itemswritten += nbytes / (nchannels * bytespersamp);
+ break;
+ }
+ itemswritten += thiswrite;
+ onset += thiswrite;
}
if (fd >= 0)
{
- soundfile_finishwrite(obj, filesym->s_name, fd,
- filetype, nframes, itemswritten, nchannels * bytespersamp, swap);
- close (fd);
+ soundfile_finishwrite(obj, filesym->s_name, fd,
+ filetype, nframes, itemswritten, nchannels * bytespersamp, swap);
+ close (fd);
}
return ((float)itemswritten);
usage:
@@ -1197,7 +1223,7 @@ usage:
post("(defaults to a 16-bit wave file).");
fail:
if (fd >= 0)
- close (fd);
+ close (fd);
return (0);
}
@@ -1205,18 +1231,18 @@ static void soundfiler_write(t_soundfiler *x, t_symbol *s,
int argc, t_atom *argv)
{
long bozo = soundfiler_dowrite(x, x->x_canvas,
- argc, argv);
+ argc, argv);
outlet_float(x->x_obj.ob_outlet, (float)bozo);
}
static void soundfiler_setup(void)
{
soundfiler_class = class_new(gensym("soundfiler"), (t_newmethod)soundfiler_new,
- 0, sizeof(t_soundfiler), 0, 0);
+ 0, sizeof(t_soundfiler), 0, 0);
class_addmethod(soundfiler_class, (t_method)soundfiler_read, gensym("read"),
- A_GIMME, 0);
+ A_GIMME, 0);
class_addmethod(soundfiler_class, (t_method)soundfiler_write,
- gensym("write"), A_GIMME, 0);
+ gensym("write"), A_GIMME, 0);
}
@@ -1225,11 +1251,11 @@ static void soundfiler_setup(void)
/* READSF uses the Posix threads package; for the moment we're Linux
only although this should be portable to the other platforms.
-Each instance of readsf~ owns a "child" thread for doing the UNIX (MSW?) file
+Each instance of readsf~ owns a "child" thread for doing the unix (MSW?) file
reading. The parent thread signals the child each time:
(1) a file wants opening or closing;
(2) we've eaten another 1/16 of the shared buffer (so that the
- child thread should check if it's time to read some more.)
+ child thread should check if it's time to read some more.)
The child signals the parent whenever a read has completed. Signalling
is done by setting "conditions" and putting data in mutex-controlled common
areas.
@@ -1242,7 +1268,7 @@ areas.
#define WRITESIZE 65536
#define DEFBUFPERCHAN 262144
#define MINBUFSIZE (4 * READSIZE)
-#define MAXBUFSIZE 16777216 /* arbitrary; just don't want to hang malloc */
+#define MAXBUFSIZE 16777216 /* arbitrary; just don't want to hang malloc */
#define REQUEST_NOTHING 0
#define REQUEST_OPEN 1
@@ -1261,36 +1287,36 @@ typedef struct _readsf
t_object x_obj;
t_canvas *x_canvas;
t_clock *x_clock;
- char *x_buf; /* soundfile buffer */
- int x_bufsize; /* buffer size in bytes */
- int x_noutlets; /* number of audio outlets */
- t_sample *(x_outvec[MAXSFCHANS]); /* audio vectors */
- int x_vecsize; /* vector size for transfers */
- t_outlet *x_bangout; /* bang-on-done outlet */
- int x_state; /* opened, running, or idle */
+ char *x_buf; /* soundfile buffer */
+ int x_bufsize; /* buffer size in bytes */
+ int x_noutlets; /* number of audio outlets */
+ t_sample *(x_outvec[MAXSFCHANS]); /* audio vectors */
+ int x_vecsize; /* vector size for transfers */
+ t_outlet *x_bangout; /* bang-on-done outlet */
+ int x_state; /* opened, running, or idle */
float x_insamplerate; /* sample rate of input signal if known */
- /* parameters to communicate with subthread */
- int x_requestcode; /* pending request from parent to I/O thread */
- char *x_filename; /* file to open (string is permanently allocated) */
- int x_fileerror; /* slot for "errno" return */
+ /* parameters to communicate with subthread */
+ int x_requestcode; /* pending request from parent to I/O thread */
+ char *x_filename; /* file to open (string is permanently allocated) */
+ int x_fileerror; /* slot for "errno" return */
int x_skipheaderbytes; /* size of header we'll skip */
int x_bytespersample; /* bytes per sample (2 or 3) */
int x_bigendian; /* true if file is big-endian */
- int x_sfchannels; /* number of channels in soundfile */
+ int x_sfchannels; /* number of channels in soundfile */
float x_samplerate; /* sample rate of soundfile */
- long x_onsetframes; /* number of sample frames to skip */
- long x_bytelimit; /* max number of data bytes to read */
- int x_fd; /* filedesc */
- int x_fifosize; /* buffer size appropriately rounded down */
- int x_fifohead; /* index of next byte to get from file */
- int x_fifotail; /* index of next byte the ugen will read */
- int x_eof; /* true if fifohead has stopped changing */
+ long x_onsetframes; /* number of sample frames to skip */
+ long x_bytelimit; /* max number of data bytes to read */
+ int x_fd; /* filedesc */
+ int x_fifosize; /* buffer size appropriately rounded down */
+ int x_fifohead; /* index of next byte to get from file */
+ int x_fifotail; /* index of next byte the ugen will read */
+ int x_eof; /* true if fifohead has stopped changing */
int x_sigcountdown; /* counter for signalling child for more data */
- int x_sigperiod; /* number of ticks per signal */
- int x_filetype; /* writesf~ only; type of file to create */
+ int x_sigperiod; /* number of ticks per signal */
+ int x_filetype; /* writesf~ only; type of file to create */
int x_itemswritten; /* writesf~ only; items writen */
- int x_swap; /* writesf~ only; true if byte swapping */
- float x_f; /* writesf~ only; scalar for signal inlet */
+ int x_swap; /* writesf~ only; true if byte swapping */
+ float x_f; /* writesf~ only; scalar for signal inlet */
pthread_mutex_t x_mutex;
pthread_cond_t x_requestcondition;
pthread_cond_t x_answercondition;
@@ -1305,8 +1331,7 @@ static void pute(char *s) /* debug routine */
{
write(2, s, strlen(s));
}
-#else
-#define pute(x)
+#define DEBUG_SOUNDFILE
#endif
#if 1
@@ -1325,17 +1350,6 @@ static void readsf_fakewait(pthread_mutex_t *b)
pthread_mutex_lock(b);
}
-void readsf_banana( void)
-{
- struct timeval timout;
- timout.tv_sec = 0;
- timout.tv_usec = 200000;
- pute("banana1\n");
- select(0, 0, 0, 0, &timout);
- pute("banana2\n");
-}
-
-
#define sfread_cond_wait(a,b) readsf_fakewait(b)
#define sfread_cond_signal(a)
#endif
@@ -1343,240 +1357,284 @@ void readsf_banana( void)
static void *readsf_child_main(void *zz)
{
t_readsf *x = zz;
+#ifdef DEBUG_SOUNDFILE
pute("1\n");
+#endif
pthread_mutex_lock(&x->x_mutex);
while (1)
{
- int fd, fifohead;
- char *buf;
- pute("0\n");
- if (x->x_requestcode == REQUEST_NOTHING)
- {
- pute("wait 2\n");
- sfread_cond_signal(&x->x_answercondition);
- sfread_cond_wait(&x->x_requestcondition, &x->x_mutex);
- pute("3\n");
- }
- else if (x->x_requestcode == REQUEST_OPEN)
- {
- char boo[80];
- int sysrtn, wantbytes;
-
- /* copy file stuff out of the data structure so we can
- relinquish the mutex while we're in open_soundfile(). */
- long onsetframes = x->x_onsetframes;
- long bytelimit = 0x7fffffff;
- int skipheaderbytes = x->x_skipheaderbytes;
- int bytespersample = x->x_bytespersample;
- int sfchannels = x->x_sfchannels;
- int bigendian = x->x_bigendian;
- char *filename = x->x_filename;
- char *dirname = canvas_getdir(x->x_canvas)->s_name;
- /* alter the request code so that an ensuing "open" will get
- noticed. */
- pute("4\n");
- x->x_requestcode = REQUEST_BUSY;
- x->x_fileerror = 0;
-
- /* if there's already a file open, close it */
- if (x->x_fd >= 0)
- {
- fd = x->x_fd;
- pthread_mutex_unlock(&x->x_mutex);
- close (fd);
- pthread_mutex_lock(&x->x_mutex);
- x->x_fd = -1;
- if (x->x_requestcode != REQUEST_BUSY)
- goto lost;
- }
- /* open the soundfile with the mutex unlocked */
- pthread_mutex_unlock(&x->x_mutex);
- fd = open_soundfile(dirname, filename,
- skipheaderbytes, &bytespersample, &bigendian,
- &sfchannels, &bytelimit, onsetframes);
- pthread_mutex_lock(&x->x_mutex);
-
- pute("5\n");
- /* copy back into the instance structure. */
- x->x_bytespersample = bytespersample;
- x->x_sfchannels = sfchannels;
- x->x_bigendian = bigendian;
- x->x_fd = fd;
- x->x_bytelimit = bytelimit;
- if (fd < 0)
- {
- x->x_fileerror = errno;
- x->x_eof = 1;
- pute("open failed\n");
- pute(filename);
- pute(dirname);
- goto lost;
- }
- /* check if another request has been made; if so, field it */
- if (x->x_requestcode != REQUEST_BUSY)
- goto lost;
- pute("6\n");
- x->x_fifohead = 0;
- /* set fifosize from bufsize. fifosize must be a
- multiple of the number of bytes eaten for each DSP
- tick. We pessimistically assume MAXVECSIZE samples
- per tick since that could change. There could be a
- problem here if the vector size increases while a
- soundfile is being played... */
- x->x_fifosize = x->x_bufsize - (x->x_bufsize %
- (x->x_bytespersample * x->x_sfchannels * MAXVECSIZE));
- /* arrange for the "request" condition to be signalled 16
- times per buffer */
- sprintf(boo, "fifosize %d\n",
- x->x_fifosize);
- pute(boo);
- x->x_sigcountdown = x->x_sigperiod =
- (x->x_fifosize /
- (16 * x->x_bytespersample * x->x_sfchannels *
- x->x_vecsize));
- /* in a loop, wait for the fifo to get hungry and feed it */
-
- while (x->x_requestcode == REQUEST_BUSY)
- {
- int fifosize = x->x_fifosize;
- pute("77\n");
- if (x->x_eof)
- break;
- if (x->x_fifohead >= x->x_fifotail)
- {
- /* if the head is >= the tail, we can immediately read
- to the end of the fifo. Unless, that is, we would
- read all the way to the end of the buffer and the
- "tail" is zero; this would fill the buffer completely
- which isn't allowed because you can't tell a completely
- full buffer from an empty one. */
- if (x->x_fifotail || (fifosize - x->x_fifohead > READSIZE))
- {
- wantbytes = fifosize - x->x_fifohead;
- if (wantbytes > READSIZE)
- wantbytes = READSIZE;
- if (wantbytes > x->x_bytelimit)
- wantbytes = x->x_bytelimit;
- sprintf(boo, "head %d, tail %d, size %d\n",
- x->x_fifohead, x->x_fifotail, wantbytes);
- pute(boo);
- }
- else
- {
- pute("wait 7a ...\n");
- sfread_cond_signal(&x->x_answercondition);
- pute("signalled\n");
- sfread_cond_wait(&x->x_requestcondition,
- &x->x_mutex);
- pute("7a done\n");
- continue;
- }
- }
- else
- {
- /* otherwise check if there are at least READSIZE
- bytes to read. If not, wait and loop back. */
- wantbytes = x->x_fifotail - x->x_fifohead - 1;
- if (wantbytes < READSIZE)
- {
- pute("wait 7...\n");
- sfread_cond_signal(&x->x_answercondition);
- sfread_cond_wait(&x->x_requestcondition,
- &x->x_mutex);
- pute("7 done\n");
- continue;
- }
- else wantbytes = READSIZE;
- }
- pute("8\n");
- fd = x->x_fd;
- buf = x->x_buf;
- fifohead = x->x_fifohead;
- pthread_mutex_unlock(&x->x_mutex);
- sysrtn = read(fd, buf + fifohead, wantbytes);
- pthread_mutex_lock(&x->x_mutex);
- if (x->x_requestcode != REQUEST_BUSY)
- break;
- if (sysrtn < 0)
- {
- pute("fileerror\n");
- x->x_fileerror = errno;
- break;
- }
- else if (sysrtn == 0)
- {
- x->x_eof = 1;
- break;
- }
- else
- {
- x->x_fifohead += sysrtn;
- x->x_bytelimit -= sysrtn;
- if (x->x_bytelimit <= 0)
- {
- x->x_eof = 1;
- break;
- }
- if (x->x_fifohead == fifosize)
- x->x_fifohead = 0;
- }
- sprintf(boo, "after: head %d, tail %d\n",
- x->x_fifohead, x->x_fifotail);
- pute(boo);
- /* signal parent in case it's waiting for data */
- sfread_cond_signal(&x->x_answercondition);
- }
- lost:
-
- if (x->x_requestcode == REQUEST_BUSY)
- x->x_requestcode = REQUEST_NOTHING;
- /* fell out of read loop: close file if necessary,
- set EOF and signal once more */
- if (x->x_fd >= 0)
- {
- fd = x->x_fd;
- pthread_mutex_unlock(&x->x_mutex);
- close (fd);
- pthread_mutex_lock(&x->x_mutex);
- x->x_fd = -1;
- }
- sfread_cond_signal(&x->x_answercondition);
-
- }
- else if (x->x_requestcode == REQUEST_CLOSE)
- {
- if (x->x_fd >= 0)
- {
- fd = x->x_fd;
- pthread_mutex_unlock(&x->x_mutex);
- close (fd);
- pthread_mutex_lock(&x->x_mutex);
- x->x_fd = -1;
- }
- if (x->x_requestcode == REQUEST_CLOSE)
- x->x_requestcode = REQUEST_NOTHING;
- sfread_cond_signal(&x->x_answercondition);
- }
- else if (x->x_requestcode == REQUEST_QUIT)
- {
- if (x->x_fd >= 0)
- {
- fd = x->x_fd;
- pthread_mutex_unlock(&x->x_mutex);
- close (fd);
- pthread_mutex_lock(&x->x_mutex);
- x->x_fd = -1;
- }
- x->x_requestcode = REQUEST_NOTHING;
- sfread_cond_signal(&x->x_answercondition);
- break;
- }
- else
- {
- pute("13\n");
- }
+ int fd, fifohead;
+ char *buf;
+#ifdef DEBUG_SOUNDFILE
+ pute("0\n");
+#endif
+ if (x->x_requestcode == REQUEST_NOTHING)
+ {
+#ifdef DEBUG_SOUNDFILE
+ pute("wait 2\n");
+#endif
+ sfread_cond_signal(&x->x_answercondition);
+ sfread_cond_wait(&x->x_requestcondition, &x->x_mutex);
+#ifdef DEBUG_SOUNDFILE
+ pute("3\n");
+#endif
+ }
+ else if (x->x_requestcode == REQUEST_OPEN)
+ {
+ char boo[80];
+ int sysrtn, wantbytes;
+
+ /* copy file stuff out of the data structure so we can
+ relinquish the mutex while we're in open_soundfile(). */
+ long onsetframes = x->x_onsetframes;
+ long bytelimit = 0x7fffffff;
+ int skipheaderbytes = x->x_skipheaderbytes;
+ int bytespersample = x->x_bytespersample;
+ int sfchannels = x->x_sfchannels;
+ int bigendian = x->x_bigendian;
+ char *filename = x->x_filename;
+ char *dirname = canvas_getdir(x->x_canvas)->s_name;
+ /* alter the request code so that an ensuing "open" will get
+ noticed. */
+#ifdef DEBUG_SOUNDFILE
+ pute("4\n");
+#endif
+ x->x_requestcode = REQUEST_BUSY;
+ x->x_fileerror = 0;
+
+ /* if there's already a file open, close it */
+ if (x->x_fd >= 0)
+ {
+ fd = x->x_fd;
+ pthread_mutex_unlock(&x->x_mutex);
+ close (fd);
+ pthread_mutex_lock(&x->x_mutex);
+ x->x_fd = -1;
+ if (x->x_requestcode != REQUEST_BUSY)
+ goto lost;
+ }
+ /* open the soundfile with the mutex unlocked */
+ pthread_mutex_unlock(&x->x_mutex);
+ fd = open_soundfile(dirname, filename,
+ skipheaderbytes, &bytespersample, &bigendian,
+ &sfchannels, &bytelimit, onsetframes);
+ pthread_mutex_lock(&x->x_mutex);
+
+#ifdef DEBUG_SOUNDFILE
+ pute("5\n");
+#endif
+ /* copy back into the instance structure. */
+ x->x_bytespersample = bytespersample;
+ x->x_sfchannels = sfchannels;
+ x->x_bigendian = bigendian;
+ x->x_fd = fd;
+ x->x_bytelimit = bytelimit;
+ if (fd < 0)
+ {
+ x->x_fileerror = errno;
+ x->x_eof = 1;
+#ifdef DEBUG_SOUNDFILE
+ pute("open failed\n");
+ pute(filename);
+ pute(dirname);
+#endif
+ goto lost;
+ }
+ /* check if another request has been made; if so, field it */
+ if (x->x_requestcode != REQUEST_BUSY)
+ goto lost;
+#ifdef DEBUG_SOUNDFILE
+ pute("6\n");
+#endif
+ x->x_fifohead = 0;
+ /* set fifosize from bufsize. fifosize must be a
+ multiple of the number of bytes eaten for each DSP
+ tick. We pessimistically assume MAXVECSIZE samples
+ per tick since that could change. There could be a
+ problem here if the vector size increases while a
+ soundfile is being played... */
+ x->x_fifosize = x->x_bufsize - (x->x_bufsize %
+ (x->x_bytespersample * x->x_sfchannels * MAXVECSIZE));
+ /* arrange for the "request" condition to be signalled 16
+ times per buffer */
+#ifdef DEBUG_SOUNDFILE
+ sprintf(boo, "fifosize %d\n",
+ x->x_fifosize);
+ pute(boo);
+#endif
+ x->x_sigcountdown = x->x_sigperiod =
+ (x->x_fifosize /
+ (16 * x->x_bytespersample * x->x_sfchannels *
+ x->x_vecsize));
+ /* in a loop, wait for the fifo to get hungry and feed it */
+
+ while (x->x_requestcode == REQUEST_BUSY)
+ {
+ int fifosize = x->x_fifosize;
+#ifdef DEBUG_SOUNDFILE
+ pute("77\n");
+#endif
+ if (x->x_eof)
+ break;
+ if (x->x_fifohead >= x->x_fifotail)
+ {
+ /* if the head is >= the tail, we can immediately read
+ to the end of the fifo. Unless, that is, we would
+ read all the way to the end of the buffer and the
+ "tail" is zero; this would fill the buffer completely
+ which isn't allowed because you can't tell a completely
+ full buffer from an empty one. */
+ if (x->x_fifotail || (fifosize - x->x_fifohead > READSIZE))
+ {
+ wantbytes = fifosize - x->x_fifohead;
+ if (wantbytes > READSIZE)
+ wantbytes = READSIZE;
+ if (wantbytes > x->x_bytelimit)
+ wantbytes = x->x_bytelimit;
+#ifdef DEBUG_SOUNDFILE
+ sprintf(boo, "head %d, tail %d, size %d\n",
+ x->x_fifohead, x->x_fifotail, wantbytes);
+ pute(boo);
+#endif
+ }
+ else
+ {
+#ifdef DEBUG_SOUNDFILE
+ pute("wait 7a ...\n");
+#endif
+ sfread_cond_signal(&x->x_answercondition);
+#ifdef DEBUG_SOUNDFILE
+ pute("signalled\n");
+#endif
+ sfread_cond_wait(&x->x_requestcondition,
+ &x->x_mutex);
+#ifdef DEBUG_SOUNDFILE
+ pute("7a done\n");
+#endif
+ continue;
+ }
+ }
+ else
+ {
+ /* otherwise check if there are at least READSIZE
+ bytes to read. If not, wait and loop back. */
+ wantbytes = x->x_fifotail - x->x_fifohead - 1;
+ if (wantbytes < READSIZE)
+ {
+#ifdef DEBUG_SOUNDFILE
+ pute("wait 7...\n");
+#endif
+ sfread_cond_signal(&x->x_answercondition);
+ sfread_cond_wait(&x->x_requestcondition,
+ &x->x_mutex);
+#ifdef DEBUG_SOUNDFILE
+ pute("7 done\n");
+#endif
+ continue;
+ }
+ else wantbytes = READSIZE;
+ if (wantbytes > x->x_bytelimit)
+ wantbytes = x->x_bytelimit;
+ }
+#ifdef DEBUG_SOUNDFILE
+ pute("8\n");
+#endif
+ fd = x->x_fd;
+ buf = x->x_buf;
+ fifohead = x->x_fifohead;
+ pthread_mutex_unlock(&x->x_mutex);
+ sysrtn = read(fd, buf + fifohead, wantbytes);
+ pthread_mutex_lock(&x->x_mutex);
+ if (x->x_requestcode != REQUEST_BUSY)
+ break;
+ if (sysrtn < 0)
+ {
+#ifdef DEBUG_SOUNDFILE
+ pute("fileerror\n");
+#endif
+ x->x_fileerror = errno;
+ break;
+ }
+ else if (sysrtn == 0)
+ {
+ x->x_eof = 1;
+ break;
+ }
+ else
+ {
+ x->x_fifohead += sysrtn;
+ x->x_bytelimit -= sysrtn;
+ if (x->x_bytelimit <= 0)
+ {
+ x->x_eof = 1;
+ break;
+ }
+ if (x->x_fifohead == fifosize)
+ x->x_fifohead = 0;
+ }
+#ifdef DEBUG_SOUNDFILE
+ sprintf(boo, "after: head %d, tail %d\n",
+ x->x_fifohead, x->x_fifotail);
+ pute(boo);
+#endif
+ /* signal parent in case it's waiting for data */
+ sfread_cond_signal(&x->x_answercondition);
+ }
+ lost:
+
+ if (x->x_requestcode == REQUEST_BUSY)
+ x->x_requestcode = REQUEST_NOTHING;
+ /* fell out of read loop: close file if necessary,
+ set EOF and signal once more */
+ if (x->x_fd >= 0)
+ {
+ fd = x->x_fd;
+ pthread_mutex_unlock(&x->x_mutex);
+ close (fd);
+ pthread_mutex_lock(&x->x_mutex);
+ x->x_fd = -1;
+ }
+ sfread_cond_signal(&x->x_answercondition);
+
+ }
+ else if (x->x_requestcode == REQUEST_CLOSE)
+ {
+ if (x->x_fd >= 0)
+ {
+ fd = x->x_fd;
+ pthread_mutex_unlock(&x->x_mutex);
+ close (fd);
+ pthread_mutex_lock(&x->x_mutex);
+ x->x_fd = -1;
+ }
+ if (x->x_requestcode == REQUEST_CLOSE)
+ x->x_requestcode = REQUEST_NOTHING;
+ sfread_cond_signal(&x->x_answercondition);
+ }
+ else if (x->x_requestcode == REQUEST_QUIT)
+ {
+ if (x->x_fd >= 0)
+ {
+ fd = x->x_fd;
+ pthread_mutex_unlock(&x->x_mutex);
+ close (fd);
+ pthread_mutex_lock(&x->x_mutex);
+ x->x_fd = -1;
+ }
+ x->x_requestcode = REQUEST_NOTHING;
+ sfread_cond_signal(&x->x_answercondition);
+ break;
+ }
+ else
+ {
+#ifdef DEBUG_SOUNDFILE
+ pute("13\n");
+#endif
+ }
}
+#ifdef DEBUG_SOUNDFILE
pute("thread exit\n");
+#endif
pthread_mutex_unlock(&x->x_mutex);
return (0);
}
@@ -1592,21 +1650,21 @@ static void *readsf_new(t_floatarg fnchannels, t_floatarg fbufsize)
char *buf;
if (nchannels < 1)
- nchannels = 1;
+ nchannels = 1;
else if (nchannels > MAXSFCHANS)
- nchannels = MAXSFCHANS;
+ nchannels = MAXSFCHANS;
if (bufsize <= 0) bufsize = DEFBUFPERCHAN * nchannels;
else if (bufsize < MINBUFSIZE)
- bufsize = MINBUFSIZE;
+ bufsize = MINBUFSIZE;
else if (bufsize > MAXBUFSIZE)
- bufsize = MAXBUFSIZE;
+ bufsize = MAXBUFSIZE;
buf = getbytes(bufsize);
if (!buf) return (0);
x = (t_readsf *)pd_new(readsf_class);
for (i = 0; i < nchannels; i++)
- outlet_new(&x->x_obj, gensym("signal"));
+ outlet_new(&x->x_obj, gensym("signal"));
x->x_noutlets = nchannels;
x->x_bangout = outlet_new(&x->x_obj, &s_bang);
pthread_mutex_init(&x->x_mutex, 0);
@@ -1635,60 +1693,81 @@ static t_int *readsf_perform(t_int *w)
{
t_readsf *x = (t_readsf *)(w[1]);
int vecsize = x->x_vecsize, noutlets = x->x_noutlets, i, j,
- bytespersample = x->x_bytespersample,
- bigendian = x->x_bigendian;
+ bytespersample = x->x_bytespersample,
+ bigendian = x->x_bigendian;
float *fp;
if (x->x_state == STATE_STREAM)
{
- int wantbytes, nchannels, sfchannels = x->x_sfchannels;
- pthread_mutex_lock(&x->x_mutex);
- wantbytes = sfchannels * vecsize * bytespersample;
- while (
- !x->x_eof && x->x_fifohead >= x->x_fifotail &&
- x->x_fifohead < x->x_fifotail + wantbytes-1)
- {
- pute("wait...\n");
- sfread_cond_signal(&x->x_requestcondition);
- sfread_cond_wait(&x->x_answercondition, &x->x_mutex);
- pute("done\n");
- }
- if (x->x_eof && x->x_fifohead >= x->x_fifotail &&
- x->x_fifohead < x->x_fifotail + wantbytes-1)
- {
- if (x->x_fileerror)
- {
- pd_error(x, "dsp: %s: %s", x->x_filename,
- (x->x_fileerror == EIO ?
- "unknown or bad header format" :
- strerror(x->x_fileerror)));
- }
- clock_delay(x->x_clock, 0);
- x->x_state = STATE_IDLE;
- sfread_cond_signal(&x->x_requestcondition);
- pthread_mutex_unlock(&x->x_mutex);
- goto idle;
- }
-
- soundfile_xferin(sfchannels, noutlets, x->x_outvec, 0,
- (unsigned char *)(x->x_buf + x->x_fifotail), vecsize,
- bytespersample, bigendian);
-
- x->x_fifotail += wantbytes;
- if (x->x_fifotail >= x->x_fifosize)
- x->x_fifotail = 0;
- if ((--x->x_sigcountdown) <= 0)
- {
- sfread_cond_signal(&x->x_requestcondition);
- x->x_sigcountdown = x->x_sigperiod;
- }
- pthread_mutex_unlock(&x->x_mutex);
+ int wantbytes, nchannels, sfchannels = x->x_sfchannels;
+ pthread_mutex_lock(&x->x_mutex);
+ wantbytes = sfchannels * vecsize * bytespersample;
+ while (
+ !x->x_eof && x->x_fifohead >= x->x_fifotail &&
+ x->x_fifohead < x->x_fifotail + wantbytes-1)
+ {
+#ifdef DEBUG_SOUNDFILE
+ pute("wait...\n");
+#endif
+ sfread_cond_signal(&x->x_requestcondition);
+ sfread_cond_wait(&x->x_answercondition, &x->x_mutex);
+#ifdef DEBUG_SOUNDFILE
+ pute("done\n");
+#endif
+ }
+ if (x->x_eof && x->x_fifohead >= x->x_fifotail &&
+ x->x_fifohead < x->x_fifotail + wantbytes-1)
+ {
+ int xfersize;
+ if (x->x_fileerror)
+ {
+ pd_error(x, "dsp: %s: %s", x->x_filename,
+ (x->x_fileerror == EIO ?
+ "unknown or bad header format" :
+ strerror(x->x_fileerror)));
+ }
+ clock_delay(x->x_clock, 0);
+ x->x_state = STATE_IDLE;
+
+ /* if there's a partial buffer left, copy it out. */
+ xfersize = (x->x_fifohead - x->x_fifotail + 1) /
+ (sfchannels * bytespersample);
+ if (xfersize)
+ {
+ soundfile_xferin(sfchannels, noutlets, x->x_outvec, 0,
+ (unsigned char *)(x->x_buf + x->x_fifotail), xfersize,
+ bytespersample, bigendian);
+ vecsize -= xfersize;
+ }
+ /* then zero out the (rest of the) output */
+ for (i = 0; i < noutlets; i++)
+ for (j = vecsize, fp = x->x_outvec[i] + xfersize; j--; )
+ *fp++ = 0;
+
+ sfread_cond_signal(&x->x_requestcondition);
+ pthread_mutex_unlock(&x->x_mutex);
+ return (w+2);
+ }
+
+ soundfile_xferin(sfchannels, noutlets, x->x_outvec, 0,
+ (unsigned char *)(x->x_buf + x->x_fifotail), vecsize,
+ bytespersample, bigendian);
+
+ x->x_fifotail += wantbytes;
+ if (x->x_fifotail >= x->x_fifosize)
+ x->x_fifotail = 0;
+ if ((--x->x_sigcountdown) <= 0)
+ {
+ sfread_cond_signal(&x->x_requestcondition);
+ x->x_sigcountdown = x->x_sigperiod;
+ }
+ pthread_mutex_unlock(&x->x_mutex);
}
else
{
idle:
- for (i = 0; i < noutlets; i++)
- for (j = vecsize, fp = x->x_outvec[i]; j--; )
- *fp++ = 0;
+ for (i = 0; i < noutlets; i++)
+ for (j = vecsize, fp = x->x_outvec[i]; j--; )
+ *fp++ = 0;
}
return (w+2);
}
@@ -1698,13 +1777,13 @@ static void readsf_start(t_readsf *x)
/* start making output. If we're in the "startup" state change
to the "running" state. */
if (x->x_state == STATE_STARTUP)
- x->x_state = STATE_STREAM;
+ x->x_state = STATE_STREAM;
else pd_error(x, "readsf: start requested with no prior 'open'");
}
static void readsf_stop(t_readsf *x)
{
- /* LATER rethink whether you need the mutex just to set a variable? */
+ /* LATER rethink whether you need the mutex just to set a variable? */
pthread_mutex_lock(&x->x_mutex);
x->x_state = STATE_IDLE;
x->x_requestcode = REQUEST_CLOSE;
@@ -1715,14 +1794,14 @@ static void readsf_stop(t_readsf *x)
static void readsf_float(t_readsf *x, t_floatarg f)
{
if (f != 0)
- readsf_start(x);
+ readsf_start(x);
else readsf_stop(x);
}
/* open method. Called as:
open filename [skipframes headersize channels bytespersamp endianness]
- (if headersize is zero, header is taken to be automatically
- detected; thus, use the special "-1" to mean a truly headerless file.)
+ (if headersize is zero, header is taken to be automatically
+ detected; thus, use the special "-1" to mean a truly headerless file.)
*/
static void readsf_open(t_readsf *x, t_symbol *s, int argc, t_atom *argv)
@@ -1734,22 +1813,22 @@ static void readsf_open(t_readsf *x, t_symbol *s, int argc, t_atom *argv)
t_float bytespersamp = atom_getfloatarg(4, argc, argv);
t_symbol *endian = atom_getsymbolarg(5, argc, argv);
if (!*filesym->s_name)
- return;
+ return;
pthread_mutex_lock(&x->x_mutex);
x->x_requestcode = REQUEST_OPEN;
x->x_filename = filesym->s_name;
x->x_fifotail = 0;
x->x_fifohead = 0;
if (*endian->s_name == 'b')
- x->x_bigendian = 1;
+ x->x_bigendian = 1;
else if (*endian->s_name == 'l')
- x->x_bigendian = 0;
+ x->x_bigendian = 0;
else if (*endian->s_name)
- pd_error(x, "endianness neither 'b' nor 'l'");
+ pd_error(x, "endianness neither 'b' nor 'l'");
else x->x_bigendian = garray_ambigendian();
x->x_onsetframes = (onsetframes > 0 ? onsetframes : 0);
x->x_skipheaderbytes = (headerbytes > 0 ? headerbytes :
- (headerbytes == 0 ? -1 : 0));
+ (headerbytes == 0 ? -1 : 0));
x->x_sfchannels = (channels >= 1 ? channels : 1);
x->x_bytespersample = (bytespersamp > 2 ? bytespersamp : 2);
x->x_eof = 0;
@@ -1766,9 +1845,9 @@ static void readsf_dsp(t_readsf *x, t_signal **sp)
x->x_vecsize = sp[0]->s_n;
x->x_sigperiod = (x->x_fifosize /
- (x->x_bytespersample * x->x_sfchannels * x->x_vecsize));
+ (x->x_bytespersample * x->x_sfchannels * x->x_vecsize));
for (i = 0; i < noutlets; i++)
- x->x_outvec[i] = sp[i]->s_vec;
+ x->x_outvec[i] = sp[i]->s_vec;
pthread_mutex_unlock(&x->x_mutex);
dsp_add(readsf_perform, 1, x);
}
@@ -1785,19 +1864,19 @@ static void readsf_print(t_readsf *x)
static void readsf_free(t_readsf *x)
{
- /* request QUIT and wait for acknowledge */
+ /* request QUIT and wait for acknowledge */
void *threadrtn;
pthread_mutex_lock(&x->x_mutex);
x->x_requestcode = REQUEST_QUIT;
sfread_cond_signal(&x->x_requestcondition);
while (x->x_requestcode != REQUEST_NOTHING)
{
- sfread_cond_signal(&x->x_requestcondition);
- sfread_cond_wait(&x->x_answercondition, &x->x_mutex);
+ sfread_cond_signal(&x->x_requestcondition);
+ sfread_cond_wait(&x->x_answercondition, &x->x_mutex);
}
pthread_mutex_unlock(&x->x_mutex);
if (pthread_join(x->x_childthread, &threadrtn))
- error("readsf_free: join failed");
+ error("readsf_free: join failed");
pthread_cond_destroy(&x->x_requestcondition);
pthread_cond_destroy(&x->x_answercondition);
@@ -1809,13 +1888,13 @@ static void readsf_free(t_readsf *x)
static void readsf_setup(void)
{
readsf_class = class_new(gensym("readsf~"), (t_newmethod)readsf_new,
- (t_method)readsf_free, sizeof(t_readsf), 0, A_DEFFLOAT, A_DEFFLOAT, 0);
+ (t_method)readsf_free, sizeof(t_readsf), 0, A_DEFFLOAT, A_DEFFLOAT, 0);
class_addfloat(readsf_class, (t_method)readsf_float);
class_addmethod(readsf_class, (t_method)readsf_start, gensym("start"), 0);
class_addmethod(readsf_class, (t_method)readsf_stop, gensym("stop"), 0);
class_addmethod(readsf_class, (t_method)readsf_dsp, gensym("dsp"), 0);
class_addmethod(readsf_class, (t_method)readsf_open, gensym("open"),
- A_GIMME, 0);
+ A_GIMME, 0);
class_addmethod(readsf_class, (t_method)readsf_print, gensym("print"), 0);
}
@@ -1823,184 +1902,217 @@ static void readsf_setup(void)
static t_class *writesf_class;
-#define t_writesf t_readsf /* just re-use the structure */
+#define t_writesf t_readsf /* just re-use the structure */
/************** the child thread which performs file I/O ***********/
static void *writesf_child_main(void *zz)
{
t_writesf *x = zz;
+#ifdef DEBUG_SOUNDFILE
pute("1\n");
+#endif
pthread_mutex_lock(&x->x_mutex);
while (1)
{
- pute("0\n");
- if (x->x_requestcode == REQUEST_NOTHING)
- {
- pute("wait 2\n");
- sfread_cond_signal(&x->x_answercondition);
- sfread_cond_wait(&x->x_requestcondition, &x->x_mutex);
- pute("3\n");
- }
- else if (x->x_requestcode == REQUEST_OPEN)
- {
- char boo[80];
- int fd, sysrtn, writebytes;
-
- /* copy file stuff out of the data structure so we can
- relinquish the mutex while we're in open_soundfile(). */
- long onsetframes = x->x_onsetframes;
- long bytelimit = 0x7fffffff;
- int skipheaderbytes = x->x_skipheaderbytes;
- int bytespersample = x->x_bytespersample;
- int sfchannels = x->x_sfchannels;
- int bigendian = x->x_bigendian;
- int filetype = x->x_filetype;
- char *filename = x->x_filename;
- t_canvas *canvas = x->x_canvas;
- float samplerate = x->x_samplerate;
-
- /* alter the request code so that an ensuing "open" will get
- noticed. */
- pute("4\n");
- x->x_requestcode = REQUEST_BUSY;
- x->x_fileerror = 0;
-
- /* if there's already a file open, close it */
- if (x->x_fd >= 0)
- {
- pthread_mutex_unlock(&x->x_mutex);
- close (x->x_fd);
- pthread_mutex_lock(&x->x_mutex);
- x->x_fd = -1;
- if (x->x_requestcode != REQUEST_BUSY)
- continue;
- }
- /* open the soundfile with the mutex unlocked */
- pthread_mutex_unlock(&x->x_mutex);
- fd = create_soundfile(canvas, filename, filetype, 0,
- bytespersample, bigendian, sfchannels,
- garray_ambigendian() != bigendian, samplerate);
- pthread_mutex_lock(&x->x_mutex);
-
- pute("5\n");
-
- if (fd < 0)
- {
- x->x_fd = -1;
- x->x_eof = 1;
- x->x_fileerror = errno;
- pute("open failed\n");
- pute(filename);
- x->x_requestcode = REQUEST_NOTHING;
- continue;
- }
- /* check if another request has been made; if so, field it */
- if (x->x_requestcode != REQUEST_BUSY)
- continue;
- pute("6\n");
- x->x_fd = fd;
- x->x_fifotail = 0;
- x->x_itemswritten = 0;
- x->x_swap = garray_ambigendian() != bigendian;
- /* in a loop, wait for the fifo to have data and write it
- to disk */
- while (x->x_requestcode == REQUEST_BUSY ||
- (x->x_requestcode == REQUEST_CLOSE &&
- x->x_fifohead != x->x_fifotail))
- {
- int fifosize = x->x_fifosize, fifotail;
- char *buf = x->x_buf;
- pute("77\n");
-
- /* if the head is < the tail, we can immediately write
- from tail to end of fifo to disk; otherwise we hold off
- writing until there are at least WRITESIZE bytes in the
- buffer */
- if (x->x_fifohead < x->x_fifotail ||
- x->x_fifohead >= x->x_fifotail + WRITESIZE
- || (x->x_requestcode == REQUEST_CLOSE &&
- x->x_fifohead != x->x_fifotail))
- {
- writebytes = (x->x_fifohead < x->x_fifotail ?
- fifosize : x->x_fifohead) - x->x_fifotail;
- if (writebytes > READSIZE)
- writebytes = READSIZE;
- }
- else
- {
- pute("wait 7a ...\n");
- sfread_cond_signal(&x->x_answercondition);
- pute("signalled\n");
- sfread_cond_wait(&x->x_requestcondition,
- &x->x_mutex);
- pute("7a done\n");
- continue;
- }
- pute("8\n");
- fifotail = x->x_fifotail;
- fd = x->x_fd;
- pthread_mutex_unlock(&x->x_mutex);
- sysrtn = write(fd, buf + fifotail, writebytes);
- pthread_mutex_lock(&x->x_mutex);
- if (x->x_requestcode != REQUEST_BUSY &&
- x->x_requestcode != REQUEST_CLOSE)
- break;
- if (sysrtn < writebytes)
- {
- pute("fileerror\n");
- x->x_fileerror = errno;
- break;
- }
- else
- {
- x->x_fifotail += sysrtn;
- if (x->x_fifotail == fifosize)
- x->x_fifotail = 0;
- }
- x->x_itemswritten +=
- sysrtn / (x->x_bytespersample * x->x_sfchannels);
- sprintf(boo, "after: head %d, tail %d\n",
- x->x_fifohead, x->x_fifotail);
- pute(boo);
- /* signal parent in case it's waiting for data */
- sfread_cond_signal(&x->x_answercondition);
- }
- }
- else if (x->x_requestcode == REQUEST_CLOSE ||
- x->x_requestcode == REQUEST_QUIT)
- {
- int quit = (x->x_requestcode == REQUEST_QUIT);
- if (x->x_fd >= 0)
- {
- int bytesperframe = x->x_bytespersample * x->x_sfchannels;
- int bigendian = x->x_bigendian;
- char *filename = x->x_filename;
- int fd = x->x_fd;
- int filetype = x->x_filetype;
- int itemswritten = x->x_itemswritten;
- int swap = x->x_swap;
- pthread_mutex_unlock(&x->x_mutex);
-
- soundfile_finishwrite(x, filename, fd,
- filetype, 0x7fffffff, itemswritten,
- bytesperframe, swap);
- close (fd);
-
- pthread_mutex_lock(&x->x_mutex);
- x->x_fd = -1;
- }
- x->x_requestcode = REQUEST_NOTHING;
- sfread_cond_signal(&x->x_answercondition);
- if (quit)
- break;
- }
- else
- {
- pute("13\n");
- }
+#ifdef DEBUG_SOUNDFILE
+ pute("0\n");
+#endif
+ if (x->x_requestcode == REQUEST_NOTHING)
+ {
+#ifdef DEBUG_SOUNDFILE
+ pute("wait 2\n");
+#endif
+ sfread_cond_signal(&x->x_answercondition);
+ sfread_cond_wait(&x->x_requestcondition, &x->x_mutex);
+#ifdef DEBUG_SOUNDFILE
+ pute("3\n");
+#endif
+ }
+ else if (x->x_requestcode == REQUEST_OPEN)
+ {
+ char boo[80];
+ int fd, sysrtn, writebytes;
+
+ /* copy file stuff out of the data structure so we can
+ relinquish the mutex while we're in open_soundfile(). */
+ long onsetframes = x->x_onsetframes;
+ long bytelimit = 0x7fffffff;
+ int skipheaderbytes = x->x_skipheaderbytes;
+ int bytespersample = x->x_bytespersample;
+ int sfchannels = x->x_sfchannels;
+ int bigendian = x->x_bigendian;
+ int filetype = x->x_filetype;
+ char *filename = x->x_filename;
+ t_canvas *canvas = x->x_canvas;
+ float samplerate = x->x_samplerate;
+
+ /* alter the request code so that an ensuing "open" will get
+ noticed. */
+#ifdef DEBUG_SOUNDFILE
+ pute("4\n");
+#endif
+ x->x_requestcode = REQUEST_BUSY;
+ x->x_fileerror = 0;
+
+ /* if there's already a file open, close it */
+ if (x->x_fd >= 0)
+ {
+ pthread_mutex_unlock(&x->x_mutex);
+ close (x->x_fd);
+ pthread_mutex_lock(&x->x_mutex);
+ x->x_fd = -1;
+ if (x->x_requestcode != REQUEST_BUSY)
+ continue;
+ }
+ /* open the soundfile with the mutex unlocked */
+ pthread_mutex_unlock(&x->x_mutex);
+ fd = create_soundfile(canvas, filename, filetype, 0,
+ bytespersample, bigendian, sfchannels,
+ garray_ambigendian() != bigendian, samplerate);
+ pthread_mutex_lock(&x->x_mutex);
+#ifdef DEBUG_SOUNDFILE
+ pute("5\n");
+#endif
+
+ if (fd < 0)
+ {
+ x->x_fd = -1;
+ x->x_eof = 1;
+ x->x_fileerror = errno;
+#ifdef DEBUG_SOUNDFILE
+ pute("open failed\n");
+ pute(filename);
+#endif
+ x->x_requestcode = REQUEST_NOTHING;
+ continue;
+ }
+ /* check if another request has been made; if so, field it */
+ if (x->x_requestcode != REQUEST_BUSY)
+ continue;
+#ifdef DEBUG_SOUNDFILE
+ pute("6\n");
+#endif
+ x->x_fd = fd;
+ x->x_fifotail = 0;
+ x->x_itemswritten = 0;
+ x->x_swap = garray_ambigendian() != bigendian;
+ /* in a loop, wait for the fifo to have data and write it
+ to disk */
+ while (x->x_requestcode == REQUEST_BUSY ||
+ (x->x_requestcode == REQUEST_CLOSE &&
+ x->x_fifohead != x->x_fifotail))
+ {
+ int fifosize = x->x_fifosize, fifotail;
+ char *buf = x->x_buf;
+#ifdef DEBUG_SOUNDFILE
+ pute("77\n");
+#endif
+
+ /* if the head is < the tail, we can immediately write
+ from tail to end of fifo to disk; otherwise we hold off
+ writing until there are at least WRITESIZE bytes in the
+ buffer */
+ if (x->x_fifohead < x->x_fifotail ||
+ x->x_fifohead >= x->x_fifotail + WRITESIZE
+ || (x->x_requestcode == REQUEST_CLOSE &&
+ x->x_fifohead != x->x_fifotail))
+ {
+ writebytes = (x->x_fifohead < x->x_fifotail ?
+ fifosize : x->x_fifohead) - x->x_fifotail;
+ if (writebytes > READSIZE)
+ writebytes = READSIZE;
+ }
+ else
+ {
+#ifdef DEBUG_SOUNDFILE
+ pute("wait 7a ...\n");
+#endif
+ sfread_cond_signal(&x->x_answercondition);
+#ifdef DEBUG_SOUNDFILE
+ pute("signalled\n");
+#endif
+ sfread_cond_wait(&x->x_requestcondition,
+ &x->x_mutex);
+#ifdef DEBUG_SOUNDFILE
+ pute("7a done\n");
+#endif
+ continue;
+ }
+#ifdef DEBUG_SOUNDFILE
+ pute("8\n");
+#endif
+ fifotail = x->x_fifotail;
+ fd = x->x_fd;
+ pthread_mutex_unlock(&x->x_mutex);
+ sysrtn = write(fd, buf + fifotail, writebytes);
+ pthread_mutex_lock(&x->x_mutex);
+ if (x->x_requestcode != REQUEST_BUSY &&
+ x->x_requestcode != REQUEST_CLOSE)
+ break;
+ if (sysrtn < writebytes)
+ {
+#ifdef DEBUG_SOUNDFILE
+ pute("fileerror\n");
+#endif
+ x->x_fileerror = errno;
+ break;
+ }
+ else
+ {
+ x->x_fifotail += sysrtn;
+ if (x->x_fifotail == fifosize)
+ x->x_fifotail = 0;
+ }
+ x->x_itemswritten +=
+ sysrtn / (x->x_bytespersample * x->x_sfchannels);
+ sprintf(boo, "after: head %d, tail %d\n",
+ x->x_fifohead, x->x_fifotail);
+#ifdef DEBUG_SOUNDFILE
+ pute(boo);
+#endif
+ /* signal parent in case it's waiting for data */
+ sfread_cond_signal(&x->x_answercondition);
+ }
+ }
+ else if (x->x_requestcode == REQUEST_CLOSE ||
+ x->x_requestcode == REQUEST_QUIT)
+ {
+ int quit = (x->x_requestcode == REQUEST_QUIT);
+ if (x->x_fd >= 0)
+ {
+ int bytesperframe = x->x_bytespersample * x->x_sfchannels;
+ int bigendian = x->x_bigendian;
+ char *filename = x->x_filename;
+ int fd = x->x_fd;
+ int filetype = x->x_filetype;
+ int itemswritten = x->x_itemswritten;
+ int swap = x->x_swap;
+ pthread_mutex_unlock(&x->x_mutex);
+
+ soundfile_finishwrite(x, filename, fd,
+ filetype, 0x7fffffff, itemswritten,
+ bytesperframe, swap);
+ close (fd);
+
+ pthread_mutex_lock(&x->x_mutex);
+ x->x_fd = -1;
+ }
+ x->x_requestcode = REQUEST_NOTHING;
+ sfread_cond_signal(&x->x_answercondition);
+ if (quit)
+ break;
+ }
+ else
+ {
+#ifdef DEBUG_SOUNDFILE
+ pute("13\n");
+#endif
+ }
}
+#ifdef DEBUG_SOUNDFILE
pute("thread exit\n");
+#endif
pthread_mutex_unlock(&x->x_mutex);
return (0);
}
@@ -2016,21 +2128,21 @@ static void *writesf_new(t_floatarg fnchannels, t_floatarg fbufsize)
char *buf;
if (nchannels < 1)
- nchannels = 1;
+ nchannels = 1;
else if (nchannels > MAXSFCHANS)
- nchannels = MAXSFCHANS;
+ nchannels = MAXSFCHANS;
if (bufsize <= 0) bufsize = DEFBUFPERCHAN * nchannels;
else if (bufsize < MINBUFSIZE)
- bufsize = MINBUFSIZE;
+ bufsize = MINBUFSIZE;
else if (bufsize > MAXBUFSIZE)
- bufsize = MAXBUFSIZE;
+ bufsize = MAXBUFSIZE;
buf = getbytes(bufsize);
if (!buf) return (0);
x = (t_writesf *)pd_new(writesf_class);
for (i = 1; i < nchannels; i++)
- inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_signal, &s_signal);
+ inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_signal, &s_signal);
x->x_f = 0;
x->x_sfchannels = nchannels;
@@ -2040,7 +2152,7 @@ static void *writesf_new(t_floatarg fnchannels, t_floatarg fbufsize)
x->x_vecsize = MAXVECSIZE;
x->x_insamplerate = x->x_samplerate = 0;
x->x_state = STATE_IDLE;
- x->x_clock = 0; /* no callback needed here */
+ x->x_clock = 0; /* no callback needed here */
x->x_canvas = canvas_getcurrent();
x->x_bytespersample = 2;
x->x_fd = -1;
@@ -2055,37 +2167,43 @@ static t_int *writesf_perform(t_int *w)
{
t_writesf *x = (t_writesf *)(w[1]);
int vecsize = x->x_vecsize, sfchannels = x->x_sfchannels, i, j,
- bytespersample = x->x_bytespersample,
- bigendian = x->x_bigendian;
+ bytespersample = x->x_bytespersample,
+ bigendian = x->x_bigendian;
float *fp;
if (x->x_state == STATE_STREAM)
{
- int wantbytes;
- pthread_mutex_lock(&x->x_mutex);
- wantbytes = sfchannels * vecsize * bytespersample;
- while (x->x_fifotail > x->x_fifohead &&
- x->x_fifotail < x->x_fifohead + wantbytes + 1)
- {
- pute("wait...\n");
- sfread_cond_signal(&x->x_requestcondition);
- sfread_cond_wait(&x->x_answercondition, &x->x_mutex);
- pute("done\n");
- }
-
- soundfile_xferout(sfchannels, x->x_outvec,
- (unsigned char *)(x->x_buf + x->x_fifohead), vecsize, 0,
- bytespersample, bigendian, 1.);
-
- x->x_fifohead += wantbytes;
- if (x->x_fifohead >= x->x_fifosize)
- x->x_fifohead = 0;
- if ((--x->x_sigcountdown) <= 0)
- {
- pute("signal 1\n");
- sfread_cond_signal(&x->x_requestcondition);
- x->x_sigcountdown = x->x_sigperiod;
- }
- pthread_mutex_unlock(&x->x_mutex);
+ int wantbytes;
+ pthread_mutex_lock(&x->x_mutex);
+ wantbytes = sfchannels * vecsize * bytespersample;
+ while (x->x_fifotail > x->x_fifohead &&
+ x->x_fifotail < x->x_fifohead + wantbytes + 1)
+ {
+#ifdef DEBUG_SOUNDFILE
+ pute("wait...\n");
+#endif
+ sfread_cond_signal(&x->x_requestcondition);
+ sfread_cond_wait(&x->x_answercondition, &x->x_mutex);
+#ifdef DEBUG_SOUNDFILE
+ pute("done\n");
+#endif
+ }
+
+ soundfile_xferout(sfchannels, x->x_outvec,
+ (unsigned char *)(x->x_buf + x->x_fifohead), vecsize, 0,
+ bytespersample, bigendian, 1.);
+
+ x->x_fifohead += wantbytes;
+ if (x->x_fifohead >= x->x_fifosize)
+ x->x_fifohead = 0;
+ if ((--x->x_sigcountdown) <= 0)
+ {
+#ifdef DEBUG_SOUNDFILE
+ pute("signal 1\n");
+#endif
+ sfread_cond_signal(&x->x_requestcondition);
+ x->x_sigcountdown = x->x_sigperiod;
+ }
+ pthread_mutex_unlock(&x->x_mutex);
}
return (w+2);
}
@@ -2095,25 +2213,27 @@ static void writesf_start(t_writesf *x)
/* start making output. If we're in the "startup" state change
to the "running" state. */
if (x->x_state == STATE_STARTUP)
- x->x_state = STATE_STREAM;
+ x->x_state = STATE_STREAM;
else
- pd_error(x, "writesf: start requested with no prior 'open'");
+ pd_error(x, "writesf: start requested with no prior 'open'");
}
static void writesf_stop(t_writesf *x)
{
- /* LATER rethink whether you need the mutex just to set a Svariable? */
+ /* LATER rethink whether you need the mutex just to set a Svariable? */
pthread_mutex_lock(&x->x_mutex);
x->x_state = STATE_IDLE;
x->x_requestcode = REQUEST_CLOSE;
+#ifdef DEBUG_SOUNDFILE
pute("signal 2\n");
+#endif
sfread_cond_signal(&x->x_requestcondition);
pthread_mutex_unlock(&x->x_mutex);
}
/* open method. Called as: open [args] filename with args as in
- soundfiler_writeargparse().
+ soundfiler_writeargparse().
*/
static void writesf_open(t_writesf *x, t_symbol *s, int argc, t_atom *argv)
@@ -2123,17 +2243,17 @@ static void writesf_open(t_writesf *x, t_symbol *s, int argc, t_atom *argv)
long onset, nframes;
float samplerate;
if (soundfiler_writeargparse(x, &argc,
- &argv, &filesym, &filetype, &bytespersamp, &swap, &bigendian,
+ &argv, &filesym, &filetype, &bytespersamp, &swap, &bigendian,
&normalize, &onset, &nframes, &samplerate))
{
- pd_error(x,
- "writesf~: usage: open [-bytes [234]] [-wave,-nextstep,-aiff] ...");
- post("... [-big,-little] [-rate ####] filename");
+ pd_error(x,
+ "writesf~: usage: open [-bytes [234]] [-wave,-nextstep,-aiff] ...");
+ post("... [-big,-little] [-rate ####] filename");
}
if (normalize || onset || (nframes != 0x7fffffff))
- pd_error(x, "normalize/onset/nframes argument to writesf~: ignored");
+ pd_error(x, "normalize/onset/nframes argument to writesf~: ignored");
if (argc)
- pd_error(x, "extra argument(s) to writesf~: ignored");
+ pd_error(x, "extra argument(s) to writesf~: ignored");
pthread_mutex_lock(&x->x_mutex);
x->x_bytespersample = bytespersamp;
x->x_swap = swap;
@@ -2149,21 +2269,21 @@ static void writesf_open(t_writesf *x, t_symbol *s, int argc, t_atom *argv)
x->x_state = STATE_STARTUP;
x->x_bytespersample = (bytespersamp > 2 ? bytespersamp : 2);
if (samplerate > 0)
- x->x_samplerate = samplerate;
+ x->x_samplerate = samplerate;
else if (x->x_insamplerate > 0)
- x->x_samplerate = x->x_insamplerate;
+ x->x_samplerate = x->x_insamplerate;
else x->x_samplerate = sys_getsr();
- /* set fifosize from bufsize. fifosize must be a
- multiple of the number of bytes eaten for each DSP
- tick. */
+ /* set fifosize from bufsize. fifosize must be a
+ multiple of the number of bytes eaten for each DSP
+ tick. */
x->x_fifosize = x->x_bufsize - (x->x_bufsize %
- (x->x_bytespersample * x->x_sfchannels * MAXVECSIZE));
- /* arrange for the "request" condition to be signalled 16
- times per buffer */
+ (x->x_bytespersample * x->x_sfchannels * MAXVECSIZE));
+ /* arrange for the "request" condition to be signalled 16
+ times per buffer */
x->x_sigcountdown = x->x_sigperiod =
- (x->x_fifosize /
- (16 * x->x_bytespersample * x->x_sfchannels *
- x->x_vecsize));
+ (x->x_fifosize /
+ (16 * x->x_bytespersample * x->x_sfchannels *
+ x->x_vecsize));
sfread_cond_signal(&x->x_requestcondition);
pthread_mutex_unlock(&x->x_mutex);
}
@@ -2175,9 +2295,9 @@ static void writesf_dsp(t_writesf *x, t_signal **sp)
x->x_vecsize = sp[0]->s_n;
x->x_sigperiod = (x->x_fifosize /
- (x->x_bytespersample * ninlets * x->x_vecsize));
+ (x->x_bytespersample * ninlets * x->x_vecsize));
for (i = 0; i < ninlets; i++)
- x->x_outvec[i] = sp[i]->s_vec;
+ x->x_outvec[i] = sp[i]->s_vec;
x->x_insamplerate = sp[0]->s_sr;
pthread_mutex_unlock(&x->x_mutex);
dsp_add(writesf_perform, 1, x);
@@ -2195,7 +2315,7 @@ static void writesf_print(t_writesf *x)
static void writesf_free(t_writesf *x)
{
- /* request QUIT and wait for acknowledge */
+ /* request QUIT and wait for acknowledge */
void *threadrtn;
pthread_mutex_lock(&x->x_mutex);
x->x_requestcode = REQUEST_QUIT;
@@ -2203,13 +2323,13 @@ static void writesf_free(t_writesf *x)
sfread_cond_signal(&x->x_requestcondition);
while (x->x_requestcode != REQUEST_NOTHING)
{
- /* post("signalling..."); */
- sfread_cond_signal(&x->x_requestcondition);
- sfread_cond_wait(&x->x_answercondition, &x->x_mutex);
+ /* post("signalling..."); */
+ sfread_cond_signal(&x->x_requestcondition);
+ sfread_cond_wait(&x->x_answercondition, &x->x_mutex);
}
pthread_mutex_unlock(&x->x_mutex);
if (pthread_join(x->x_childthread, &threadrtn))
- error("writesf_free: join failed");
+ error("writesf_free: join failed");
/* post("... done."); */
pthread_cond_destroy(&x->x_requestcondition);
@@ -2221,12 +2341,12 @@ static void writesf_free(t_writesf *x)
static void writesf_setup(void)
{
writesf_class = class_new(gensym("writesf~"), (t_newmethod)writesf_new,
- (t_method)writesf_free, sizeof(t_writesf), 0, A_DEFFLOAT, A_DEFFLOAT, 0);
+ (t_method)writesf_free, sizeof(t_writesf), 0, A_DEFFLOAT, A_DEFFLOAT, 0);
class_addmethod(writesf_class, (t_method)writesf_start, gensym("start"), 0);
class_addmethod(writesf_class, (t_method)writesf_stop, gensym("stop"), 0);
class_addmethod(writesf_class, (t_method)writesf_dsp, gensym("dsp"), 0);
class_addmethod(writesf_class, (t_method)writesf_open, gensym("open"),
- A_GIMME, 0);
+ A_GIMME, 0);
class_addmethod(writesf_class, (t_method)writesf_print, gensym("print"), 0);
CLASS_MAINSIGNALIN(writesf_class, t_writesf, x_f);
}
diff --git a/pd/src/d_ugen.c b/pd/src/d_ugen.c
index 2c359c38..b72bad50 100644
--- a/pd/src/d_ugen.c
+++ b/pd/src/d_ugen.c
@@ -43,7 +43,7 @@ void voutlet_dspepilog(struct _voutlet *x, t_signal **parentsigs,
int myvecsize, int phase, int period, int frequency, int downsample, int upsample /* IOhannes */, int reblock,
int switched);
-t_int *zero_perform(t_int *w) /* zero out a vector */
+t_int *zero_perform(t_int *w) /* zero out a vector */
{
t_float *out = (t_float *)(w[1]);
int n = (int)(w[2]);
@@ -58,14 +58,14 @@ t_int *zero_perf8(t_int *w)
for (; n; n -= 8, out += 8)
{
- out[0] = 0;
- out[1] = 0;
- out[2] = 0;
- out[3] = 0;
- out[4] = 0;
- out[5] = 0;
- out[6] = 0;
- out[7] = 0;
+ out[0] = 0;
+ out[1] = 0;
+ out[2] = 0;
+ out[3] = 0;
+ out[4] = 0;
+ out[5] = 0;
+ out[6] = 0;
+ out[7] = 0;
}
return (w+3);
}
@@ -73,9 +73,9 @@ t_int *zero_perf8(t_int *w)
void dsp_add_zero(t_sample *out, int n)
{
if (n&7)
- dsp_add(zero_perform, 2, out, n);
- else
- dsp_add(zero_perf8, 2, out, n);
+ dsp_add(zero_perform, 2, out, n);
+ else
+ dsp_add(zero_perf8, 2, out, n);
}
/* ---------------------------- block~ ----------------------------- */
@@ -116,15 +116,15 @@ typedef struct _block
t_object x_obj;
int x_vecsize;
int x_overlap;
- int x_phase; /* from 0 to period-1; when zero we run the block */
- int x_period; /* submultiple of containing canvas */
- int x_frequency; /* supermultiple of comtaining canvas */
+ int x_phase; /* from 0 to period-1; when zero we run the block */
+ int x_period; /* submultiple of containing canvas */
+ int x_frequency; /* supermultiple of comtaining canvas */
int x_count;
- int x_blocklength; /* length of dspchain for this block */
- int x_epiloglength; /* length of epilog */
- char x_switched; /* true if we're acting as a a switch */
- char x_switchon; /* true if we're switched on */
- char x_reblock; /* true if inlets and outlets are reblocking */
+ int x_blocklength; /* length of dspchain for this block */
+ int x_epiloglength; /* length of epilog */
+ char x_switched; /* true if we're acting as a a switch */
+ char x_switchon; /* true if we're switched on */
+ char x_reblock; /* true if inlets and outlets are reblocking */
int x_upsample; /* IOhannes: upsampling-factor */
int x_downsample; /* IOhannes: downsampling-factor */
@@ -134,7 +134,7 @@ static void block_set(t_block *x, t_floatarg fvecsize, t_floatarg foverlap,
t_floatarg fupsample);
static void *block_new(t_floatarg fvecsize, t_floatarg foverlap,
- t_floatarg fupsample) /* IOhannes */
+ t_floatarg fupsample) /* IOhannes */
{
t_block *x = (t_block *)pd_new(block_class);
x->x_phase = 0;
@@ -154,9 +154,9 @@ static void block_set(t_block *x, t_floatarg fvecsize, t_floatarg foverlap,
int overlap = foverlap;
int dspstate = canvas_suspend_dsp();
if (overlap < 1)
- overlap = 1;
+ overlap = 1;
if (vecsize < 0)
- vecsize = 0; /* this means we'll get it from parent later. */
+ vecsize = 0; /* this means we'll get it from parent later. */
/* IOhannes { */
if (fupsample <= 0) upsample = downsample = 1;
@@ -171,24 +171,24 @@ static void block_set(t_block *x, t_floatarg fvecsize, t_floatarg foverlap,
if (vecsize && (vecsize != (1 << ilog2(vecsize))))
{
- pd_error(x, "block~: vector size not a power of 2");
- vecsize = 64;
+ pd_error(x, "block~: vector size not a power of 2");
+ vecsize = 64;
}
if (overlap != (1 << ilog2(overlap)))
{
- pd_error(x, "block~: overlap not a power of 2");
- overlap = 1;
+ pd_error(x, "block~: overlap not a power of 2");
+ overlap = 1;
}
/* IOhannes { */
if (downsample != (1 << ilog2(downsample)))
{
- pd_error(x, "block~: downsampling not a power of 2");
- downsample = 1;
+ pd_error(x, "block~: downsampling not a power of 2");
+ downsample = 1;
}
if (upsample != (1 << ilog2(upsample)))
{
- pd_error(x, "block~: upsampling not a power of 2");
- upsample = 1;
+ pd_error(x, "block~: upsampling not a power of 2");
+ upsample = 1;
}
/* } IOhannes */
@@ -203,7 +203,7 @@ static void block_set(t_block *x, t_floatarg fvecsize, t_floatarg foverlap,
}
static void *switch_new(t_floatarg fvecsize, t_floatarg foverlap,
- t_floatarg fupsample) /* IOhannes */
+ t_floatarg fupsample) /* IOhannes */
{
t_block *x = (t_block *)(block_new(fvecsize, foverlap, fupsample)); /* IOhannes */
x->x_switched = 1;
@@ -214,7 +214,7 @@ static void *switch_new(t_floatarg fvecsize, t_floatarg foverlap,
static void block_float(t_block *x, t_floatarg f)
{
if (x->x_switched)
- x->x_switchon = (f != 0);
+ x->x_switchon = (f != 0);
}
#define PROLOGCALL 2
#define EPILOGCALL 2
@@ -223,21 +223,21 @@ static t_int *block_prolog(t_int *w)
{
t_block *x = (t_block *)w[1];
int phase = x->x_phase;
- /* if we're switched off, jump past the epilog code */
+ /* if we're switched off, jump past the epilog code */
if (!x->x_switchon)
- return (w + x->x_blocklength);
+ return (w + x->x_blocklength);
if (phase)
{
- phase++;
- if (phase == x->x_period) phase = 0;
- x->x_phase = phase;
- return (w + x->x_blocklength); /* skip block; jump past epilog */
+ phase++;
+ if (phase == x->x_period) phase = 0;
+ x->x_phase = phase;
+ return (w + x->x_blocklength); /* skip block; jump past epilog */
}
else
{
- x->x_count = x->x_frequency;
- x->x_phase = (x->x_period > 1 ? 1 : 0);
- return (w + PROLOGCALL); /* beginning of block is next ugen */
+ x->x_count = x->x_frequency;
+ x->x_phase = (x->x_period > 1 ? 1 : 0);
+ return (w + PROLOGCALL); /* beginning of block is next ugen */
}
}
@@ -246,12 +246,12 @@ static t_int *block_epilog(t_int *w)
t_block *x = (t_block *)w[1];
int count = x->x_count - 1;
if (!x->x_reblock)
- return (w + x->x_epiloglength + EPILOGCALL);
+ return (w + x->x_epiloglength + EPILOGCALL);
if (count)
{
- x->x_count = count;
- return (w - (x->x_blocklength -
- (PROLOGCALL + EPILOGCALL))); /* go to ugen after prolog */
+ x->x_count = count;
+ return (w - (x->x_blocklength -
+ (PROLOGCALL + EPILOGCALL))); /* go to ugen after prolog */
}
else return (w + EPILOGCALL);
}
@@ -272,11 +272,11 @@ void dsp_add(t_perfroutine f, int n, ...)
va_list ap;
dsp_chain = t_resizebytes(dsp_chain, dsp_chainsize * sizeof (t_int),
- newsize * sizeof (t_int));
+ newsize * sizeof (t_int));
dsp_chain[dsp_chainsize-1] = (t_int)f;
va_start(ap, n);
for (i = 0; i < n; i++)
- dsp_chain[dsp_chainsize + i] = va_arg(ap, t_int);
+ dsp_chain[dsp_chainsize + i] = va_arg(ap, t_int);
va_end(ap);
dsp_chain[newsize-1] = 0;
dsp_chainsize = newsize;
@@ -288,10 +288,10 @@ void dsp_addv(t_perfroutine f, int n, t_int *vec)
int newsize = dsp_chainsize + n+1, i;
dsp_chain = t_resizebytes(dsp_chain, dsp_chainsize * sizeof (t_int),
- newsize * sizeof (t_int));
+ newsize * sizeof (t_int));
dsp_chain[dsp_chainsize-1] = (t_int)f;
for (i = 0; i < n; i++)
- dsp_chain[dsp_chainsize + i] = vec[i];
+ dsp_chain[dsp_chainsize + i] = vec[i];
dsp_chain[newsize-1] = 0;
dsp_chainsize = newsize;
}
@@ -300,9 +300,9 @@ void dsp_tick(void)
{
if (dsp_chain)
{
- t_int *ip;
- for (ip = dsp_chain; *ip; ) ip = (*(t_perfroutine)(*ip))(ip);
- dsp_phase++;
+ t_int *ip;
+ for (ip = dsp_chain; *ip; ) ip = (*(t_perfroutine)(*ip))(ip);
+ dsp_phase++;
}
}
@@ -314,8 +314,8 @@ int ilog2(int n)
if (n <= 0) return(0);
while (n)
{
- r++;
- n >>= 1;
+ r++;
+ n >>= 1;
}
return (r);
}
@@ -334,13 +334,13 @@ void signal_cleanup(void)
int i;
while (sig = signal_usedlist)
{
- signal_usedlist = sig->s_nextused;
- if (!sig->s_isborrowed)
- t_freebytes(sig->s_vec, sig->s_n * sizeof (*sig->s_vec));
- t_freebytes(sig, sizeof *sig);
+ signal_usedlist = sig->s_nextused;
+ if (!sig->s_isborrowed)
+ t_freebytes(sig->s_vec, sig->s_n * sizeof (*sig->s_vec));
+ t_freebytes(sig, sizeof *sig);
}
for (i = 0; i <= MAXLOGSIG; i++)
- signal_freelist[i] = 0;
+ signal_freelist[i] = 0;
signal_freeborrowed = 0;
}
@@ -352,42 +352,42 @@ void signal_makereusable(t_signal *sig)
t_signal *s5;
for (s5 = signal_freeborrowed; s5; s5 = s5->s_nextfree)
{
- if (s5 == sig)
- {
- bug("signal_free 3");
- return;
- }
+ if (s5 == sig)
+ {
+ bug("signal_free 3");
+ return;
+ }
}
for (s5 = signal_freelist[logn]; s5; s5 = s5->s_nextfree)
{
- if (s5 == sig)
- {
- bug("signal_free 4");
- return;
- }
+ if (s5 == sig)
+ {
+ bug("signal_free 4");
+ return;
+ }
}
#endif
- if (ugen_loud) post("free %x: %d", sig, sig->s_isborrowed);
+ if (ugen_loud) post("free %lx: %d", sig, sig->s_isborrowed);
if (sig->s_isborrowed)
{
- /* if the signal is borrowed, decrement the borrowed-from signal's
- reference count, possibly marking it reusable too */
- t_signal *s2 = sig->s_borrowedfrom;
- if ((s2 == sig) || !s2)
- bug("signal_free");
- s2->s_refcount--;
- if (!s2->s_refcount)
- signal_makereusable(s2);
- sig->s_nextfree = signal_freeborrowed;
- signal_freeborrowed = sig;
+ /* if the signal is borrowed, decrement the borrowed-from signal's
+ reference count, possibly marking it reusable too */
+ t_signal *s2 = sig->s_borrowedfrom;
+ if ((s2 == sig) || !s2)
+ bug("signal_free");
+ s2->s_refcount--;
+ if (!s2->s_refcount)
+ signal_makereusable(s2);
+ sig->s_nextfree = signal_freeborrowed;
+ signal_freeborrowed = sig;
}
else
{
- /* if it's a real signal (not borrowed), put it on the free list
- so we can reuse it. */
- if (signal_freelist[logn] == sig) bug("signal_free 2");
- sig->s_nextfree = signal_freelist[logn];
- signal_freelist[logn] = sig;
+ /* if it's a real signal (not borrowed), put it on the free list
+ so we can reuse it. */
+ if (signal_freelist[logn] == sig) bug("signal_free 2");
+ sig->s_nextfree = signal_freelist[logn];
+ signal_freelist[logn] = sig;
}
}
@@ -403,40 +403,40 @@ t_signal *signal_new(int n, float sr)
logn = ilog2(n);
if (n)
{
- if (n != (1 << logn))
- bug("signal buffer not a power of 2");
- if (logn > MAXLOGSIG)
- bug("signal buffer too large");
- whichlist = signal_freelist + logn;
+ if (n != (1 << logn))
+ bug("signal buffer not a power of 2");
+ if (logn > MAXLOGSIG)
+ bug("signal buffer too large");
+ whichlist = signal_freelist + logn;
}
else
- whichlist = &signal_freeborrowed;
+ whichlist = &signal_freeborrowed;
- /* first try to reclaim one from the free list */
+ /* first try to reclaim one from the free list */
if (ret = *whichlist)
- *whichlist = ret->s_nextfree;
+ *whichlist = ret->s_nextfree;
else
{
- /* LATER figure out what to do for out-of-space here! */
- ret = (t_signal *)t_getbytes(sizeof *ret);
- if (n)
- {
- ret->s_vec = (t_sample *)getbytes(n * sizeof (*ret->s_vec));
- ret->s_isborrowed = 0;
- }
- else
- {
- ret->s_vec = 0;
- ret->s_isborrowed = 1;
- }
- ret->s_nextused = signal_usedlist;
- signal_usedlist = ret;
+ /* LATER figure out what to do for out-of-space here! */
+ ret = (t_signal *)t_getbytes(sizeof *ret);
+ if (n)
+ {
+ ret->s_vec = (t_sample *)getbytes(n * sizeof (*ret->s_vec));
+ ret->s_isborrowed = 0;
+ }
+ else
+ {
+ ret->s_vec = 0;
+ ret->s_isborrowed = 1;
+ }
+ ret->s_nextused = signal_usedlist;
+ signal_usedlist = ret;
}
ret->s_n = n;
ret->s_sr = sr;
ret->s_refcount = 0;
ret->s_borrowedfrom = 0;
- if (ugen_loud) post("new %x: %d", ret, ret->s_isborrowed);
+ if (ugen_loud) post("new %lx: %d", ret, ret->s_isborrowed);
return (ret);
}
@@ -448,9 +448,9 @@ static t_signal *signal_newlike(const t_signal *sig)
void signal_setborrowed(t_signal *sig, t_signal *sig2)
{
if (!sig->s_isborrowed || sig->s_borrowedfrom)
- bug("signal_setborrowed");
+ bug("signal_setborrowed");
if (sig == sig2)
- bug("signal_setborrowed 2");
+ bug("signal_setborrowed 2");
sig->s_borrowedfrom = sig2;
sig->s_vec = sig2->s_vec;
sig->s_n = sig2->s_n;
@@ -507,9 +507,9 @@ struct _dspcontext
t_signal **dc_iosigs;
float dc_srate;
int dc_vecsize;
- char dc_toplevel; /* true if "iosigs" is invalid. */
- char dc_reblock; /* true if we have to reblock inlets/outlets */
- char dc_switched; /* true if we're switched */
+ char dc_toplevel; /* true if "iosigs" is invalid. */
+ char dc_reblock; /* true if we have to reblock inlets/outlets */
+ char dc_switched; /* true if we're switched */
};
@@ -524,8 +524,8 @@ void ugen_stop(void)
int i;
if (dsp_chain)
{
- freebytes(dsp_chain, dsp_chainsize * sizeof (t_int));
- dsp_chain = 0;
+ freebytes(dsp_chain, dsp_chainsize * sizeof (t_int));
+ dsp_chain = 0;
}
signal_cleanup();
@@ -552,20 +552,20 @@ void glob_foo(void *dummy, t_symbol *s, int argc, t_atom *argv)
int i, count;
t_signal *sig;
for (count = 0, sig = signal_usedlist; sig;
- count++, sig = sig->s_nextused)
- ;
+ count++, sig = sig->s_nextused)
+ ;
post("used signals %d", count);
for (i = 0; i < MAXLOGSIG; i++)
{
- for (count = 0, sig = signal_freelist[i]; sig;
- count++, sig = sig->s_nextfree)
- ;
- if (count)
- post("size %d: free %d", (1 << i), count);
+ for (count = 0, sig = signal_freelist[i]; sig;
+ count++, sig = sig->s_nextfree)
+ ;
+ if (count)
+ post("size %d: free %d", (1 << i), count);
}
for (count = 0, sig = signal_freeborrowed; sig;
- count++, sig = sig->s_nextfree)
- ;
+ count++, sig = sig->s_nextfree)
+ ;
post("free borrowed %d", count);
ugen_loud = argc;
@@ -606,11 +606,11 @@ void ugen_add(t_dspcontext *dc, t_object *obj)
x->u_nin = obj_nsiginlets(obj);
x->u_in = getbytes(x->u_nin * sizeof (*x->u_in));
for (uin = x->u_in, i = x->u_nin; i--; uin++)
- uin->i_nconnect = 0;
+ uin->i_nconnect = 0;
x->u_nout = obj_nsigoutlets(obj);
x->u_out = getbytes(x->u_nout * sizeof (*x->u_out));
for (uout = x->u_out, i = x->u_nout; i--; uout++)
- uout->o_connections = 0, uout->o_nconnect = 0;
+ uout->o_connections = 0, uout->o_nconnect = 0;
}
/* and then this to make all the connections. */
@@ -624,34 +624,34 @@ void ugen_connect(t_dspcontext *dc, t_object *x1, int outno, t_object *x2,
int sigoutno = obj_sigoutletindex(x1, outno);
int siginno = obj_siginletindex(x2, inno);
if (ugen_loud)
- post("%s -> %s: %d->%d",
- class_getname(x1->ob_pd),
- class_getname(x2->ob_pd), outno, inno);
+ post("%s -> %s: %d->%d",
+ class_getname(x1->ob_pd),
+ class_getname(x2->ob_pd), outno, inno);
for (u1 = dc->dc_ugenlist; u1 && u1->u_obj != x1; u1 = u1->u_next);
for (u2 = dc->dc_ugenlist; u2 && u2->u_obj != x2; u2 = u2->u_next);
if (!u1 || !u2 || siginno < 0)
{
- pd_error(u1->u_obj,
- "signal outlet connect to nonsignal inlet (ignored)");
- return;
+ pd_error(u1->u_obj,
+ "signal outlet connect to nonsignal inlet (ignored)");
+ return;
}
if (sigoutno < 0 || sigoutno >= u1->u_nout || siginno >= u2->u_nin)
{
- bug("ugen_connect %s %s %d %d (%d %d)",
- class_getname(x1->ob_pd),
- class_getname(x2->ob_pd), sigoutno, siginno, u1->u_nout,
- u2->u_nin);
+ bug("ugen_connect %s %s %d %d (%d %d)",
+ class_getname(x1->ob_pd),
+ class_getname(x2->ob_pd), sigoutno, siginno, u1->u_nout,
+ u2->u_nin);
}
uout = u1->u_out + sigoutno;
uin = u2->u_in + siginno;
- /* add a new connection to the outlet's list */
+ /* add a new connection to the outlet's list */
oc = (t_sigoutconnect *)getbytes(sizeof *oc);
oc->oc_next = uout->o_connections;
uout->o_connections = oc;
oc->oc_who = u2;
oc->oc_inno = siginno;
- /* update inlet and outlet counts */
+ /* update inlet and outlet counts */
uout->o_nconnect++;
uin->i_nconnect++;
}
@@ -662,7 +662,7 @@ static int ugen_index(t_dspcontext *dc, t_ugenbox *x)
int ret;
t_ugenbox *u;
for (u = dc->dc_ugenlist, ret = 0; u; u = u->u_next, ret++)
- if (u == x) return (ret);
+ if (u == x) return (ret);
return (-1);
}
@@ -675,144 +675,144 @@ static void ugen_doit(t_dspcontext *dc, t_ugenbox *u)
t_sigoutconnect *oc, *oc2;
t_class *class = pd_class(&u->u_obj->ob_pd);
int i, n;
- /* suppress creating new signals for the outputs of signal
- inlets and subpatchs; except in the case we're an inlet and "blocking"
- is set. We don't yet know if a subcanvas will be "blocking" so there
- we delay new signal creation, which will be handled by calling
- signal_setborrowed in the ugen_done_graph routine below. */
+ /* suppress creating new signals for the outputs of signal
+ inlets and subpatchs; except in the case we're an inlet and "blocking"
+ is set. We don't yet know if a subcanvas will be "blocking" so there
+ we delay new signal creation, which will be handled by calling
+ signal_setborrowed in the ugen_done_graph routine below. */
int nonewsigs = (class == canvas_class ||
- (class == vinlet_class) && !(dc->dc_reblock));
- /* when we encounter a subcanvas or a signal outlet, suppress freeing
- the input signals as they may be "borrowed" for the super or sub
- patch; same exception as above, but also if we're "switched" we
- have to do a copy rather than a borrow. */
+ (class == vinlet_class) && !(dc->dc_reblock));
+ /* when we encounter a subcanvas or a signal outlet, suppress freeing
+ the input signals as they may be "borrowed" for the super or sub
+ patch; same exception as above, but also if we're "switched" we
+ have to do a copy rather than a borrow. */
int nofreesigs = (class == canvas_class ||
- (class == voutlet_class) && !(dc->dc_reblock || dc->dc_switched));
+ (class == voutlet_class) && !(dc->dc_reblock || dc->dc_switched));
t_signal **insig, **outsig, **sig, *s1, *s2, *s3;
t_ugenbox *u2;
if (ugen_loud) post("doit %s %d %d", class_getname(class), nofreesigs,
- nonewsigs);
+ nonewsigs);
for (i = 0, uin = u->u_in; i < u->u_nin; i++, uin++)
{
- if (!uin->i_nconnect)
- {
- t_sample *scalar;
- s3 = signal_new(dc->dc_vecsize, dc->dc_srate);
- /* post("%s: unconnected signal inlet set to zero",
- class_getname(u->u_obj->ob_pd)); */
- if (scalar = obj_findsignalscalar(u->u_obj, i))
- dsp_add_scalarcopy(scalar, s3->s_vec, s3->s_n);
- else
- dsp_add_zero(s3->s_vec, s3->s_n);
- uin->i_signal = s3;
- s3->s_refcount = 1;
- }
+ if (!uin->i_nconnect)
+ {
+ t_sample *scalar;
+ s3 = signal_new(dc->dc_vecsize, dc->dc_srate);
+ /* post("%s: unconnected signal inlet set to zero",
+ class_getname(u->u_obj->ob_pd)); */
+ if (scalar = obj_findsignalscalar(u->u_obj, i))
+ dsp_add_scalarcopy(scalar, s3->s_vec, s3->s_n);
+ else
+ dsp_add_zero(s3->s_vec, s3->s_n);
+ uin->i_signal = s3;
+ s3->s_refcount = 1;
+ }
}
insig = (t_signal **)getbytes((u->u_nin + u->u_nout) * sizeof(t_signal *));
outsig = insig + u->u_nin;
for (sig = insig, uin = u->u_in, i = u->u_nin; i--; sig++, uin++)
{
- int newrefcount;
- *sig = uin->i_signal;
- newrefcount = --(*sig)->s_refcount;
- /* if the reference count went to zero, we free the signal now,
- unless it's a subcanvas or outlet; these might keep the
- signal around to send to objects connected to them. In this
- case we increment the reference count; the corresponding decrement
- is in sig_makereusable(). */
- if (nofreesigs)
- (*sig)->s_refcount++;
- else if (!newrefcount)
- signal_makereusable(*sig);
+ int newrefcount;
+ *sig = uin->i_signal;
+ newrefcount = --(*sig)->s_refcount;
+ /* if the reference count went to zero, we free the signal now,
+ unless it's a subcanvas or outlet; these might keep the
+ signal around to send to objects connected to them. In this
+ case we increment the reference count; the corresponding decrement
+ is in sig_makereusable(). */
+ if (nofreesigs)
+ (*sig)->s_refcount++;
+ else if (!newrefcount)
+ signal_makereusable(*sig);
}
for (sig = outsig, uout = u->u_out, i = u->u_nout; i--; sig++, uout++)
{
- /* similarly, for outlets of subcanvases we delay creating
- them; instead we create "borrowed" ones so that the refcount
- is known. The subcanvas replaces the fake signal with one showing
- where the output data actually is, to avoid having to copy it.
- For any other object, we just allocate a new output vector;
- since we've already freed the inputs the objects might get called
- "in place." */
- if (nonewsigs)
- {
- *sig = uout->o_signal =
- signal_new(0, dc->dc_srate);
- }
- else
- *sig = uout->o_signal = signal_new(dc->dc_vecsize, dc->dc_srate);
- (*sig)->s_refcount = uout->o_nconnect;
+ /* similarly, for outlets of subcanvases we delay creating
+ them; instead we create "borrowed" ones so that the refcount
+ is known. The subcanvas replaces the fake signal with one showing
+ where the output data actually is, to avoid having to copy it.
+ For any other object, we just allocate a new output vector;
+ since we've already freed the inputs the objects might get called
+ "in place." */
+ if (nonewsigs)
+ {
+ *sig = uout->o_signal =
+ signal_new(0, dc->dc_srate);
+ }
+ else
+ *sig = uout->o_signal = signal_new(dc->dc_vecsize, dc->dc_srate);
+ (*sig)->s_refcount = uout->o_nconnect;
}
- /* now call the DSP scheduling routine for the ugen. This
- routine must fill in "borrowed" signal outputs in case it's either
- a subcanvas or a signal inlet. */
+ /* now call the DSP scheduling routine for the ugen. This
+ routine must fill in "borrowed" signal outputs in case it's either
+ a subcanvas or a signal inlet. */
mess1(&u->u_obj->ob_pd, gensym("dsp"), insig);
- /* if any output signals aren't connected to anyone, free them
- now; otherwise they'll either get freed when the reference count
- goes back to zero, or even later as explained above. */
+ /* if any output signals aren't connected to anyone, free them
+ now; otherwise they'll either get freed when the reference count
+ goes back to zero, or even later as explained above. */
for (sig = outsig, uout = u->u_out, i = u->u_nout; i--; sig++, uout++)
{
- if (!(*sig)->s_refcount)
- signal_makereusable(*sig);
+ if (!(*sig)->s_refcount)
+ signal_makereusable(*sig);
}
if (ugen_loud)
{
- if (u->u_nin + u->u_nout == 0) post("put %s %d",
- class_getname(u->u_obj->ob_pd), ugen_index(dc, u));
- else if (u->u_nin + u->u_nout == 1) post("put %s %d (%x)",
- class_getname(u->u_obj->ob_pd), ugen_index(dc, u), sig[0]);
- else if (u->u_nin + u->u_nout == 2) post("put %s %d (%x %x)",
- class_getname(u->u_obj->ob_pd), ugen_index(dc, u),
- sig[0], sig[1]);
- else post("put %s %d (%x %x %x ...)",
- class_getname(u->u_obj->ob_pd), ugen_index(dc, u),
- sig[0], sig[1], sig[2]);
+ if (u->u_nin + u->u_nout == 0) post("put %s %d",
+ class_getname(u->u_obj->ob_pd), ugen_index(dc, u));
+ else if (u->u_nin + u->u_nout == 1) post("put %s %d (%lx)",
+ class_getname(u->u_obj->ob_pd), ugen_index(dc, u), sig[0]);
+ else if (u->u_nin + u->u_nout == 2) post("put %s %d (%lx %lx)",
+ class_getname(u->u_obj->ob_pd), ugen_index(dc, u),
+ sig[0], sig[1]);
+ else post("put %s %d (%lx %lx %lx ...)",
+ class_getname(u->u_obj->ob_pd), ugen_index(dc, u),
+ sig[0], sig[1], sig[2]);
}
- /* pass it on and trip anyone whose last inlet was filled */
+ /* pass it on and trip anyone whose last inlet was filled */
for (uout = u->u_out, i = u->u_nout; i--; uout++)
{
- s1 = uout->o_signal;
- for (oc = uout->o_connections; oc; oc = oc->oc_next)
- {
- u2 = oc->oc_who;
- uin = &u2->u_in[oc->oc_inno];
- /* if there's already someone here, sum the two */
- if (s2 = uin->i_signal)
- {
- s1->s_refcount--;
- s2->s_refcount--;
- if (!signal_compatible(s1, s2))
- {
- pd_error(u->u_obj, "%s: incompatible signal inputs",
- class_getname(u->u_obj->ob_pd));
- return;
- }
- s3 = signal_newlike(s1);
- dsp_add_plus(s1->s_vec, s2->s_vec, s3->s_vec, s1->s_n);
- uin->i_signal = s3;
- s3->s_refcount = 1;
- if (!s1->s_refcount) signal_makereusable(s1);
- if (!s2->s_refcount) signal_makereusable(s2);
- }
- else uin->i_signal = s1;
- uin->i_ngot++;
- /* if we didn't fill this inlet don't bother yet */
- if (uin->i_ngot < uin->i_nconnect)
- goto notyet;
- /* if there's more than one, check them all */
- if (u2->u_nin > 1)
- {
- for (uin = u2->u_in, n = u2->u_nin; n--; uin++)
- if (uin->i_ngot < uin->i_nconnect) goto notyet;
- }
- /* so now we can schedule the ugen. */
- ugen_doit(dc, u2);
- notyet: ;
- }
+ s1 = uout->o_signal;
+ for (oc = uout->o_connections; oc; oc = oc->oc_next)
+ {
+ u2 = oc->oc_who;
+ uin = &u2->u_in[oc->oc_inno];
+ /* if there's already someone here, sum the two */
+ if (s2 = uin->i_signal)
+ {
+ s1->s_refcount--;
+ s2->s_refcount--;
+ if (!signal_compatible(s1, s2))
+ {
+ pd_error(u->u_obj, "%s: incompatible signal inputs",
+ class_getname(u->u_obj->ob_pd));
+ return;
+ }
+ s3 = signal_newlike(s1);
+ dsp_add_plus(s1->s_vec, s2->s_vec, s3->s_vec, s1->s_n);
+ uin->i_signal = s3;
+ s3->s_refcount = 1;
+ if (!s1->s_refcount) signal_makereusable(s1);
+ if (!s2->s_refcount) signal_makereusable(s2);
+ }
+ else uin->i_signal = s1;
+ uin->i_ngot++;
+ /* if we didn't fill this inlet don't bother yet */
+ if (uin->i_ngot < uin->i_nconnect)
+ goto notyet;
+ /* if there's more than one, check them all */
+ if (u2->u_nin > 1)
+ {
+ for (uin = u2->u_in, n = u2->u_nin; n--; uin++)
+ if (uin->i_ngot < uin->i_nconnect) goto notyet;
+ }
+ /* so now we can schedule the ugen. */
+ ugen_doit(dc, u2);
+ notyet: ;
+ }
}
t_freebytes(insig,(u->u_nin + u->u_nout) * sizeof(t_signal *));
u->u_done = 1;
@@ -837,265 +837,265 @@ void ugen_done_graph(t_dspcontext *dc)
int period, frequency, phase, vecsize;
float srate;
int chainblockbegin; /* DSP chain onset before block prolog code */
- int chainblockend; /* and after block epilog code */
- int chainafterall; /* and after signal outlet epilog */
+ int chainblockend; /* and after block epilog code */
+ int chainafterall; /* and after signal outlet epilog */
int reblock = 0, switched;
int downsample = 1, upsample = 1; /* IOhannes */
/* debugging printout */
if (ugen_loud)
{
- post("ugen_done_graph...");
- for (u = dc->dc_ugenlist; u; u = u->u_next)
- {
- post("ugen: %s", class_getname(u->u_obj->ob_pd));
- for (uout = u->u_out, i = 0; i < u->u_nout; uout++, i++)
- for (oc = uout->o_connections; oc; oc = oc->oc_next)
- {
- post("... out %d to %s, index %d, inlet %d", i,
- class_getname(oc->oc_who->u_obj->ob_pd),
- ugen_index(dc, oc->oc_who), oc->oc_inno);
- }
- }
+ post("ugen_done_graph...");
+ for (u = dc->dc_ugenlist; u; u = u->u_next)
+ {
+ post("ugen: %s", class_getname(u->u_obj->ob_pd));
+ for (uout = u->u_out, i = 0; i < u->u_nout; uout++, i++)
+ for (oc = uout->o_connections; oc; oc = oc->oc_next)
+ {
+ post("... out %d to %s, index %d, inlet %d", i,
+ class_getname(oc->oc_who->u_obj->ob_pd),
+ ugen_index(dc, oc->oc_who), oc->oc_inno);
+ }
+ }
}
- /* search for an object of class "block~" */
+ /* search for an object of class "block~" */
for (u = dc->dc_ugenlist, blk = 0; u; u = u->u_next)
{
- t_pd *zz = &u->u_obj->ob_pd;
- if (pd_class(zz) == block_class)
- {
- if (blk)
- pd_error(blk, "conflicting block~ objects in same page");
- else blk = (t_block *)zz;
- }
+ t_pd *zz = &u->u_obj->ob_pd;
+ if (pd_class(zz) == block_class)
+ {
+ if (blk)
+ pd_error(blk, "conflicting block~ objects in same page");
+ else blk = (t_block *)zz;
+ }
}
- /* figure out block size, calling frequency, sample rate */
+ /* figure out block size, calling frequency, sample rate */
if (parent_context)
{
- parent_srate = parent_context->dc_srate;
- parent_vecsize = parent_context->dc_vecsize;
+ parent_srate = parent_context->dc_srate;
+ parent_vecsize = parent_context->dc_vecsize;
}
else
{
- parent_srate = sys_getsr();
- parent_vecsize = sys_getblksize();
+ parent_srate = sys_getsr();
+ parent_vecsize = sys_getblksize();
}
if (blk)
{
- int realoverlap;
- vecsize = blk->x_vecsize;
- if (vecsize == 0)
- vecsize = parent_vecsize;
- realoverlap = blk->x_overlap;
- if (realoverlap > vecsize) realoverlap = vecsize;
- /* IOhannes { */
- downsample = blk->x_downsample;
- upsample = blk->x_upsample;
- if (downsample > parent_vecsize) downsample=parent_vecsize;
- period = (vecsize * downsample)/
- (parent_vecsize * realoverlap * upsample);
- frequency = (parent_vecsize * realoverlap * upsample)/
- (vecsize * downsample);
- /* } IOhannes*/
- phase = blk->x_phase;
- srate = parent_srate * realoverlap * upsample / downsample;
- /* IOhannes */
- if (period < 1) period = 1;
- if (frequency < 1) frequency = 1;
- blk->x_frequency = frequency;
- blk->x_period = period;
- blk->x_phase = dsp_phase & (period - 1);
- if (! parent_context || (realoverlap != 1) ||
- (vecsize != parent_vecsize) ||
- (downsample != 1) || (upsample != 1)) /* IOhannes */
- reblock = 1;
- switched = blk->x_switched;
+ int realoverlap;
+ vecsize = blk->x_vecsize;
+ if (vecsize == 0)
+ vecsize = parent_vecsize;
+ realoverlap = blk->x_overlap;
+ if (realoverlap > vecsize) realoverlap = vecsize;
+ /* IOhannes { */
+ downsample = blk->x_downsample;
+ upsample = blk->x_upsample;
+ if (downsample > parent_vecsize) downsample=parent_vecsize;
+ period = (vecsize * downsample)/
+ (parent_vecsize * realoverlap * upsample);
+ frequency = (parent_vecsize * realoverlap * upsample)/
+ (vecsize * downsample);
+ /* } IOhannes*/
+ phase = blk->x_phase;
+ srate = parent_srate * realoverlap * upsample / downsample;
+ /* IOhannes */
+ if (period < 1) period = 1;
+ if (frequency < 1) frequency = 1;
+ blk->x_frequency = frequency;
+ blk->x_period = period;
+ blk->x_phase = dsp_phase & (period - 1);
+ if (! parent_context || (realoverlap != 1) ||
+ (vecsize != parent_vecsize) ||
+ (downsample != 1) || (upsample != 1)) /* IOhannes */
+ reblock = 1;
+ switched = blk->x_switched;
}
else
{
- srate = parent_srate;
- vecsize = parent_vecsize;
- downsample = upsample = 1;/* IOhannes */
- period = frequency = 1;
- phase = 0;
- if (!parent_context) reblock = 1;
- switched = 0;
+ srate = parent_srate;
+ vecsize = parent_vecsize;
+ downsample = upsample = 1;/* IOhannes */
+ period = frequency = 1;
+ phase = 0;
+ if (!parent_context) reblock = 1;
+ switched = 0;
}
dc->dc_reblock = reblock;
dc->dc_switched = switched;
dc->dc_srate = srate;
dc->dc_vecsize = vecsize;
- /* if we're reblocking or switched, we now have to create output
- signals to fill in for the "borrowed" ones we have now. This
- is also possibly true even if we're not blocked/switched, in
- the case that there was a signal loop. But we don't know this
- yet. */
+ /* if we're reblocking or switched, we now have to create output
+ signals to fill in for the "borrowed" ones we have now. This
+ is also possibly true even if we're not blocked/switched, in
+ the case that there was a signal loop. But we don't know this
+ yet. */
if (dc->dc_iosigs && (switched || reblock))
{
- t_signal **sigp;
- for (i = 0, sigp = dc->dc_iosigs + dc->dc_ninlets; i < dc->dc_noutlets;
- i++, sigp++)
- {
- if ((*sigp)->s_isborrowed && !(*sigp)->s_borrowedfrom)
- {
- signal_setborrowed(*sigp,
- signal_new(parent_vecsize, parent_srate));
- (*sigp)->s_refcount++;
-
- if (ugen_loud) post("set %x->%x", *sigp,
- (*sigp)->s_borrowedfrom);
- }
- }
+ t_signal **sigp;
+ for (i = 0, sigp = dc->dc_iosigs + dc->dc_ninlets; i < dc->dc_noutlets;
+ i++, sigp++)
+ {
+ if ((*sigp)->s_isborrowed && !(*sigp)->s_borrowedfrom)
+ {
+ signal_setborrowed(*sigp,
+ signal_new(parent_vecsize, parent_srate));
+ (*sigp)->s_refcount++;
+
+ if (ugen_loud) post("set %lx->%lx", *sigp,
+ (*sigp)->s_borrowedfrom);
+ }
+ }
}
if (ugen_loud)
- post("reblock %d, switched %d", reblock, switched);
-
- /* schedule prologs for inlets and outlets. If the "reblock" flag
- is set, an inlet will put code on the DSP chain to copy its input
- into an internal buffer here, before any unit generators' DSP code
- gets scheduled. If we don't "reblock", inlets will need to get
- pointers to their corresponding inlets/outlets on the box we're inside,
- if any. Outlets will also need pointers, unless we're switched, in
- which case outlet epilog code will kick in. */
-
+ post("reblock %d, switched %d", reblock, switched);
+
+ /* schedule prologs for inlets and outlets. If the "reblock" flag
+ is set, an inlet will put code on the DSP chain to copy its input
+ into an internal buffer here, before any unit generators' DSP code
+ gets scheduled. If we don't "reblock", inlets will need to get
+ pointers to their corresponding inlets/outlets on the box we're inside,
+ if any. Outlets will also need pointers, unless we're switched, in
+ which case outlet epilog code will kick in. */
+
for (u = dc->dc_ugenlist; u; u = u->u_next)
{
- t_pd *zz = &u->u_obj->ob_pd;
- t_signal **insigs = dc->dc_iosigs, **outsigs = dc->dc_iosigs;
- if (outsigs) outsigs += dc->dc_ninlets;
-
- if (pd_class(zz) == vinlet_class)
- vinlet_dspprolog((struct _vinlet *)zz,
- dc->dc_iosigs, vecsize, dsp_phase, period, frequency,
- downsample, upsample, /* IOhannes */
- reblock, switched);
- else if (pd_class(zz) == voutlet_class)
- voutlet_dspprolog((struct _voutlet *)zz,
- outsigs, vecsize, dsp_phase, period, frequency,
- downsample, upsample, /* IOhannes */
- reblock, switched);
+ t_pd *zz = &u->u_obj->ob_pd;
+ t_signal **insigs = dc->dc_iosigs, **outsigs = dc->dc_iosigs;
+ if (outsigs) outsigs += dc->dc_ninlets;
+
+ if (pd_class(zz) == vinlet_class)
+ vinlet_dspprolog((struct _vinlet *)zz,
+ dc->dc_iosigs, vecsize, dsp_phase, period, frequency,
+ downsample, upsample, /* IOhannes */
+ reblock, switched);
+ else if (pd_class(zz) == voutlet_class)
+ voutlet_dspprolog((struct _voutlet *)zz,
+ outsigs, vecsize, dsp_phase, period, frequency,
+ downsample, upsample, /* IOhannes */
+ reblock, switched);
}
chainblockbegin = dsp_chainsize;
- if (blk && (reblock || switched)) /* add the block DSP prolog */
- dsp_add(block_prolog, 1, blk);
+ if (blk && (reblock || switched)) /* add the block DSP prolog */
+ dsp_add(block_prolog, 1, blk);
- /* Initialize for sorting */
+ /* Initialize for sorting */
for (u = dc->dc_ugenlist; u; u = u->u_next)
{
- u->u_done = 0;
- for (uout = u->u_out, i = u->u_nout; i--; uout++)
- uout->o_nsent = 0;
- for (uin = u->u_in, i = u->u_nin; i--; uin++)
- uin->i_ngot = 0, uin->i_signal = 0;
+ u->u_done = 0;
+ for (uout = u->u_out, i = u->u_nout; i--; uout++)
+ uout->o_nsent = 0;
+ for (uin = u->u_in, i = u->u_nin; i--; uin++)
+ uin->i_ngot = 0, uin->i_signal = 0;
}
- /* Do the sort */
+ /* Do the sort */
for (u = dc->dc_ugenlist; u; u = u->u_next)
{
- /* check that we have no connected signal inlets */
- if (u->u_done) continue;
- for (uin = u->u_in, i = u->u_nin; i--; uin++)
- if (uin->i_nconnect) goto next;
+ /* check that we have no connected signal inlets */
+ if (u->u_done) continue;
+ for (uin = u->u_in, i = u->u_nin; i--; uin++)
+ if (uin->i_nconnect) goto next;
- ugen_doit(dc, u);
+ ugen_doit(dc, u);
next: ;
}
- /* check for a DSP loop, which is evidenced here by the presence
- of ugens not yet scheduled. */
-
+ /* check for a DSP loop, which is evidenced here by the presence
+ of ugens not yet scheduled. */
+
for (u = dc->dc_ugenlist; u; u = u->u_next)
- if (!u->u_done)
+ if (!u->u_done)
{
- t_signal **sigp;
- pd_error(u->u_obj,
- "DSP loop detected (some tilde objects not scheduled)");
- /* this might imply that we have unfilled "borrowed" outputs
- which we'd better fill in now. */
- for (i = 0, sigp = dc->dc_iosigs + dc->dc_ninlets; i < dc->dc_noutlets;
- i++, sigp++)
- {
- if ((*sigp)->s_isborrowed && !(*sigp)->s_borrowedfrom)
- {
- t_signal *s3 = signal_new(parent_vecsize, parent_srate);
- signal_setborrowed(*sigp, s3);
- (*sigp)->s_refcount++;
- dsp_add_zero(s3->s_vec, s3->s_n);
- if (ugen_loud)
- post("oops, belatedly set %x->%x", *sigp,
- (*sigp)->s_borrowedfrom);
- }
- }
- break; /* don't need to keep looking. */
+ t_signal **sigp;
+ pd_error(u->u_obj,
+ "DSP loop detected (some tilde objects not scheduled)");
+ /* this might imply that we have unfilled "borrowed" outputs
+ which we'd better fill in now. */
+ for (i = 0, sigp = dc->dc_iosigs + dc->dc_ninlets; i < dc->dc_noutlets;
+ i++, sigp++)
+ {
+ if ((*sigp)->s_isborrowed && !(*sigp)->s_borrowedfrom)
+ {
+ t_signal *s3 = signal_new(parent_vecsize, parent_srate);
+ signal_setborrowed(*sigp, s3);
+ (*sigp)->s_refcount++;
+ dsp_add_zero(s3->s_vec, s3->s_n);
+ if (ugen_loud)
+ post("oops, belatedly set %lx->%lx", *sigp,
+ (*sigp)->s_borrowedfrom);
+ }
+ }
+ break; /* don't need to keep looking. */
}
if (blk && (reblock || switched)) /* add block DSP epilog */
- dsp_add(block_epilog, 1, blk);
+ dsp_add(block_epilog, 1, blk);
chainblockend = dsp_chainsize;
- /* add epilogs for outlets. */
+ /* add epilogs for outlets. */
for (u = dc->dc_ugenlist; u; u = u->u_next)
{
- t_pd *zz = &u->u_obj->ob_pd;
- if (pd_class(zz) == voutlet_class)
- {
- t_signal **iosigs = dc->dc_iosigs;
- if (iosigs) iosigs += dc->dc_ninlets;
- voutlet_dspepilog((struct _voutlet *)zz,
- iosigs, vecsize, dsp_phase, period, frequency,
- downsample, upsample, /* IOhannes */
- reblock, switched);
- }
+ t_pd *zz = &u->u_obj->ob_pd;
+ if (pd_class(zz) == voutlet_class)
+ {
+ t_signal **iosigs = dc->dc_iosigs;
+ if (iosigs) iosigs += dc->dc_ninlets;
+ voutlet_dspepilog((struct _voutlet *)zz,
+ iosigs, vecsize, dsp_phase, period, frequency,
+ downsample, upsample, /* IOhannes */
+ reblock, switched);
+ }
}
chainafterall = dsp_chainsize;
if (blk)
{
- blk->x_blocklength = chainblockend - chainblockbegin;
- blk->x_epiloglength = chainafterall - chainblockend;
- blk->x_reblock = reblock;
+ blk->x_blocklength = chainblockend - chainblockbegin;
+ blk->x_epiloglength = chainafterall - chainblockend;
+ blk->x_reblock = reblock;
}
if (ugen_loud)
{
- t_int *ip;
- if (!dc->dc_parentcontext)
- for (i = dsp_chainsize, ip = dsp_chain; i--; ip++)
- post("chain %x", *ip);
- post("... ugen_done_graph done.");
+ t_int *ip;
+ if (!dc->dc_parentcontext)
+ for (i = dsp_chainsize, ip = dsp_chain; i--; ip++)
+ post("chain %lx", *ip);
+ post("... ugen_done_graph done.");
}
- /* now delete everything. */
+ /* now delete everything. */
while (dc->dc_ugenlist)
{
- for (uout = dc->dc_ugenlist->u_out, n = dc->dc_ugenlist->u_nout;
- n--; uout++)
- {
- oc = uout->o_connections;
- while (oc)
- {
- oc2 = oc->oc_next;
- freebytes(oc, sizeof *oc);
- oc = oc2;
- }
- }
+ for (uout = dc->dc_ugenlist->u_out, n = dc->dc_ugenlist->u_nout;
+ n--; uout++)
+ {
+ oc = uout->o_connections;
+ while (oc)
+ {
+ oc2 = oc->oc_next;
+ freebytes(oc, sizeof *oc);
+ oc = oc2;
+ }
+ }
freebytes(dc->dc_ugenlist->u_out, dc->dc_ugenlist->u_nout *
sizeof (*dc->dc_ugenlist->u_out));
freebytes(dc->dc_ugenlist->u_in, dc->dc_ugenlist->u_nin *
sizeof(*dc->dc_ugenlist->u_in));
- u = dc->dc_ugenlist;
- dc->dc_ugenlist = u->u_next;
- freebytes(u, sizeof *u);
+ u = dc->dc_ugenlist;
+ dc->dc_ugenlist = u->u_next;
+ freebytes(u, sizeof *u);
}
if (ugen_currentcontext == dc)
- ugen_currentcontext = dc->dc_parentcontext;
+ ugen_currentcontext = dc->dc_parentcontext;
else bug("ugen_currentcontext");
freebytes(dc, sizeof(*dc));
@@ -1115,11 +1115,11 @@ t_signal *ugen_getiosig(int index, int inout)
void d_ugen_setup(void) /* really just block_setup */
{
block_class = class_new(gensym("block~"), (t_newmethod)block_new, 0,
- sizeof(t_block), 0, A_DEFFLOAT, A_DEFFLOAT, A_DEFFLOAT/*IOhannes*/, 0);
+ sizeof(t_block), 0, A_DEFFLOAT, A_DEFFLOAT, A_DEFFLOAT/*IOhannes*/, 0);
class_addcreator((t_newmethod)switch_new, gensym("switch~"),
- A_DEFFLOAT, A_DEFFLOAT, A_DEFFLOAT/*IOhannes*/, 0);
+ A_DEFFLOAT, A_DEFFLOAT, A_DEFFLOAT/*IOhannes*/, 0);
class_addmethod(block_class, (t_method)block_set, gensym("set"),
- A_DEFFLOAT, A_DEFFLOAT, A_DEFFLOAT, 0);
+ A_DEFFLOAT, A_DEFFLOAT, A_DEFFLOAT, 0);
class_addmethod(block_class, (t_method)block_dsp, gensym("dsp"), 0);
class_addfloat(block_class, block_float);
}
diff --git a/pd/src/g_all_guis.c b/pd/src/g_all_guis.c
index 08a07f74..085ba9a3 100644
--- a/pd/src/g_all_guis.c
+++ b/pd/src/g_all_guis.c
@@ -127,23 +127,23 @@ char *iemgui_vu_scale_str[]=
int iemgui_clip_size(int size)
{
if(size < IEM_GUI_MINSIZE)
- size = IEM_GUI_MINSIZE;
+ size = IEM_GUI_MINSIZE;
return(size);
}
int iemgui_clip_font(int size)
{
if(size < IEM_FONT_MINSIZE)
- size = IEM_FONT_MINSIZE;
+ size = IEM_FONT_MINSIZE;
return(size);
}
int iemgui_modulo_color(int col)
{
while(col >= IEM_GUI_MAX_COLOR)
- col -= IEM_GUI_MAX_COLOR;
+ col -= IEM_GUI_MAX_COLOR;
while(col < 0)
- col += IEM_GUI_MAX_COLOR;
+ col += IEM_GUI_MAX_COLOR;
return(col);
}
@@ -151,11 +151,11 @@ t_symbol *iemgui_raute2dollar(t_symbol *s)
{
if (s->s_name[0] == '#')
{
- char buf[MAXPDSTRING];
- strncpy(buf, s->s_name, MAXPDSTRING);
- buf[MAXPDSTRING-1] = 0;
- buf[0] = '$';
- return (gensym(buf));
+ char buf[MAXPDSTRING];
+ strncpy(buf, s->s_name, MAXPDSTRING);
+ buf[MAXPDSTRING-1] = 0;
+ buf[0] = '$';
+ return (gensym(buf));
}
else return (s);
}
@@ -164,11 +164,11 @@ t_symbol *iemgui_dollar2raute(t_symbol *s)
{
if (s->s_name[0] == '$')
{
- char buf[MAXPDSTRING];
- strncpy(buf, s->s_name, MAXPDSTRING);
- buf[MAXPDSTRING-1] = 0;
- buf[0] = '#';
- return (gensym(buf));
+ char buf[MAXPDSTRING];
+ strncpy(buf, s->s_name, MAXPDSTRING);
+ buf[MAXPDSTRING-1] = 0;
+ buf[0] = '#';
+ return (gensym(buf));
}
else return (s);
}
@@ -178,20 +178,20 @@ void iemgui_verify_snd_ne_rcv(t_iemgui *iemgui)
iemgui->x_fsf.x_put_in2out = 1;
if(iemgui->x_fsf.x_snd_able && iemgui->x_fsf.x_rcv_able)
{
- if(!strcmp(iemgui->x_snd->s_name, iemgui->x_rcv->s_name))
- iemgui->x_fsf.x_put_in2out = 0;
+ if(!strcmp(iemgui->x_snd->s_name, iemgui->x_rcv->s_name))
+ iemgui->x_fsf.x_put_in2out = 0;
}
}
t_symbol *iemgui_new_dogetname(t_iemgui *iemgui, int indx, t_atom *argv)
{
if (IS_A_SYMBOL(argv, indx))
- return (atom_getsymbolarg(indx, 100000, argv));
+ return (atom_getsymbolarg(indx, 100000, argv));
else if (IS_A_FLOAT(argv, indx))
{
- char str[80];
- sprintf(str, "%d", (int)atom_getintarg(indx, 100000, argv));
- return (gensym(str));
+ char str[80];
+ sprintf(str, "%d", (int)atom_getintarg(indx, 100000, argv));
+ return (gensym(str));
}
else return (gensym("empty"));
}
@@ -200,13 +200,13 @@ void iemgui_new_getnames(t_iemgui *iemgui, int indx, t_atom *argv)
{
if (argv)
{
- iemgui->x_snd = iemgui_new_dogetname(iemgui, indx, argv);
- iemgui->x_rcv = iemgui_new_dogetname(iemgui, indx+1, argv);
- iemgui->x_lab = iemgui_new_dogetname(iemgui, indx+2, argv);
+ iemgui->x_snd = iemgui_new_dogetname(iemgui, indx, argv);
+ iemgui->x_rcv = iemgui_new_dogetname(iemgui, indx+1, argv);
+ iemgui->x_lab = iemgui_new_dogetname(iemgui, indx+2, argv);
}
else iemgui->x_snd = iemgui->x_rcv = iemgui->x_lab = gensym("empty");
iemgui->x_snd_unexpanded = iemgui->x_rcv_unexpanded =
- iemgui->x_lab_unexpanded = 0;
+ iemgui->x_lab_unexpanded = 0;
iemgui->x_binbufindex = indx;
iemgui->x_labelbindex = indx + 3;
}
@@ -214,7 +214,7 @@ void iemgui_new_getnames(t_iemgui *iemgui, int indx, t_atom *argv)
/* convert symbols in "$" form to the expanded symbols */
void iemgui_all_dollararg2sym(t_iemgui *iemgui, t_symbol **srlsym)
{
- /* save unexpanded ones for later */
+ /* save unexpanded ones for later */
iemgui->x_snd_unexpanded = srlsym[0];
iemgui->x_rcv_unexpanded = srlsym[1];
iemgui->x_lab_unexpanded = srlsym[2];
@@ -231,16 +231,16 @@ static void iemgui_init_sym2dollararg(t_iemgui *iemgui, t_symbol **symp,
{
if (!*symp)
{
- t_binbuf *b = iemgui->x_obj.ob_binbuf;
- if (binbuf_getnatom(b) > indx)
- {
- char buf[80];
- atom_string(binbuf_getvec(b) + indx, buf, 80);
- *symp = gensym(buf);
- }
- else if (fallback)
- *symp = fallback;
- else *symp = gensym("empty");
+ t_binbuf *b = iemgui->x_obj.ob_binbuf;
+ if (binbuf_getnatom(b) > indx)
+ {
+ char buf[80];
+ atom_string(binbuf_getvec(b) + indx, buf, 80);
+ *symp = gensym(buf);
+ }
+ else if (fallback)
+ *symp = fallback;
+ else *symp = gensym("empty");
}
}
@@ -249,11 +249,11 @@ static void iemgui_init_sym2dollararg(t_iemgui *iemgui, t_symbol **symp,
void iemgui_all_sym2dollararg(t_iemgui *iemgui, t_symbol **srlsym)
{
iemgui_init_sym2dollararg(iemgui, &iemgui->x_snd_unexpanded,
- iemgui->x_binbufindex+1, iemgui->x_snd);
+ iemgui->x_binbufindex+1, iemgui->x_snd);
iemgui_init_sym2dollararg(iemgui, &iemgui->x_rcv_unexpanded,
- iemgui->x_binbufindex+2, iemgui->x_rcv);
+ iemgui->x_binbufindex+2, iemgui->x_rcv);
iemgui_init_sym2dollararg(iemgui, &iemgui->x_lab_unexpanded,
- iemgui->x_labelbindex, iemgui->x_lab);
+ iemgui->x_labelbindex, iemgui->x_lab);
srlsym[0] = iemgui->x_snd_unexpanded;
srlsym[1] = iemgui->x_rcv_unexpanded;
srlsym[2] = iemgui->x_lab_unexpanded;
@@ -267,47 +267,47 @@ void iemgui_first_dollararg2sym(t_iemgui *iemgui, t_symbol **srlsym)
void iemgui_all_col2save(t_iemgui *iemgui, int *bflcol)
{
bflcol[0] = -1 - (((0xfc0000 & iemgui->x_bcol) >> 6)|
- ((0xfc00 & iemgui->x_bcol) >> 4)|((0xfc & iemgui->x_bcol) >> 2));
+ ((0xfc00 & iemgui->x_bcol) >> 4)|((0xfc & iemgui->x_bcol) >> 2));
bflcol[1] = -1 - (((0xfc0000 & iemgui->x_fcol) >> 6)|
- ((0xfc00 & iemgui->x_fcol) >> 4)|((0xfc & iemgui->x_fcol) >> 2));
+ ((0xfc00 & iemgui->x_fcol) >> 4)|((0xfc & iemgui->x_fcol) >> 2));
bflcol[2] = -1 - (((0xfc0000 & iemgui->x_lcol) >> 6)|
- ((0xfc00 & iemgui->x_lcol) >> 4)|((0xfc & iemgui->x_lcol) >> 2));
+ ((0xfc00 & iemgui->x_lcol) >> 4)|((0xfc & iemgui->x_lcol) >> 2));
}
void iemgui_all_colfromload(t_iemgui *iemgui, int *bflcol)
{
if(bflcol[0] < 0)
{
- bflcol[0] = -1 - bflcol[0];
- iemgui->x_bcol = ((bflcol[0] & 0x3f000) << 6)|((bflcol[0] & 0xfc0) << 4)|
- ((bflcol[0] & 0x3f) << 2);
+ bflcol[0] = -1 - bflcol[0];
+ iemgui->x_bcol = ((bflcol[0] & 0x3f000) << 6)|((bflcol[0] & 0xfc0) << 4)|
+ ((bflcol[0] & 0x3f) << 2);
}
else
{
- bflcol[0] = iemgui_modulo_color(bflcol[0]);
- iemgui->x_bcol = iemgui_color_hex[bflcol[0]];
+ bflcol[0] = iemgui_modulo_color(bflcol[0]);
+ iemgui->x_bcol = iemgui_color_hex[bflcol[0]];
}
if(bflcol[1] < 0)
{
- bflcol[1] = -1 - bflcol[1];
- iemgui->x_fcol = ((bflcol[1] & 0x3f000) << 6)|((bflcol[1] & 0xfc0) << 4)|
- ((bflcol[1] & 0x3f) << 2);
+ bflcol[1] = -1 - bflcol[1];
+ iemgui->x_fcol = ((bflcol[1] & 0x3f000) << 6)|((bflcol[1] & 0xfc0) << 4)|
+ ((bflcol[1] & 0x3f) << 2);
}
else
{
- bflcol[1] = iemgui_modulo_color(bflcol[1]);
- iemgui->x_fcol = iemgui_color_hex[bflcol[1]];
+ bflcol[1] = iemgui_modulo_color(bflcol[1]);
+ iemgui->x_fcol = iemgui_color_hex[bflcol[1]];
}
if(bflcol[2] < 0)
{
- bflcol[2] = -1 - bflcol[2];
- iemgui->x_lcol = ((bflcol[2] & 0x3f000) << 6)|((bflcol[2] & 0xfc0) << 4)|
- ((bflcol[2] & 0x3f) << 2);
+ bflcol[2] = -1 - bflcol[2];
+ iemgui->x_lcol = ((bflcol[2] & 0x3f000) << 6)|((bflcol[2] & 0xfc0) << 4)|
+ ((bflcol[2] & 0x3f) << 2);
}
else
{
- bflcol[2] = iemgui_modulo_color(bflcol[2]);
- iemgui->x_lcol = iemgui_color_hex[bflcol[2]];
+ bflcol[2] = iemgui_modulo_color(bflcol[2]);
+ iemgui->x_lcol = iemgui_color_hex[bflcol[2]];
}
}
@@ -317,11 +317,11 @@ int iemgui_compatible_col(int i)
if(i >= 0)
{
- j = iemgui_modulo_color(i);
- return(iemgui_color_hex[(j)]);
+ j = iemgui_modulo_color(i);
+ return(iemgui_color_hex[(j)]);
}
else
- return((-1 -i)&0xffffff);
+ return((-1 -i)&0xffffff);
}
void iemgui_all_dollar2raute(t_symbol **srlsym)
@@ -345,7 +345,7 @@ void iemgui_send(void *x, t_iemgui *iemgui, t_symbol *s)
t_atom *pargv;
if(iemgui->x_fsf.x_rcv_able)
- oldsndrcvable += IEM_GUI_OLD_RCV_FLAG;
+ oldsndrcvable += IEM_GUI_OLD_RCV_FLAG;
if(iemgui->x_fsf.x_snd_able)
oldsndrcvable += IEM_GUI_OLD_SND_FLAG;
@@ -354,7 +354,7 @@ void iemgui_send(void *x, t_iemgui *iemgui, t_symbol *s)
iemgui->x_snd_unexpanded = snd;
iemgui->x_snd = snd = canvas_realizedollar(iemgui->x_glist, snd);
post("send: before %s, after %s", iemgui->x_snd_unexpanded->s_name,
- iemgui->x_snd->s_name);
+ iemgui->x_snd->s_name);
iemgui->x_fsf.x_snd_able = sndable;
iemgui_verify_snd_ne_rcv(iemgui);
@@ -368,7 +368,7 @@ void iemgui_receive(void *x, t_iemgui *iemgui, t_symbol *s)
t_atom *pargv;
if(iemgui->x_fsf.x_rcv_able)
- oldsndrcvable += IEM_GUI_OLD_RCV_FLAG;
+ oldsndrcvable += IEM_GUI_OLD_RCV_FLAG;
if(iemgui->x_fsf.x_snd_able)
oldsndrcvable += IEM_GUI_OLD_SND_FLAG;
@@ -378,18 +378,18 @@ void iemgui_receive(void *x, t_iemgui *iemgui, t_symbol *s)
iemgui->x_rcv = rcv = canvas_realizedollar(iemgui->x_glist, rcv);
if(rcvable)
{
- if(strcmp(rcv->s_name, iemgui->x_rcv->s_name))
- {
- if(iemgui->x_fsf.x_rcv_able)
- pd_unbind(&iemgui->x_obj.ob_pd, iemgui->x_rcv);
- iemgui->x_rcv = rcv;
- pd_bind(&iemgui->x_obj.ob_pd, iemgui->x_rcv);
- }
+ if(strcmp(rcv->s_name, iemgui->x_rcv->s_name))
+ {
+ if(iemgui->x_fsf.x_rcv_able)
+ pd_unbind(&iemgui->x_obj.ob_pd, iemgui->x_rcv);
+ iemgui->x_rcv = rcv;
+ pd_bind(&iemgui->x_obj.ob_pd, iemgui->x_rcv);
+ }
}
else if(!rcvable && iemgui->x_fsf.x_rcv_able)
{
- pd_unbind(&iemgui->x_obj.ob_pd, iemgui->x_rcv);
- iemgui->x_rcv = rcv;
+ pd_unbind(&iemgui->x_obj.ob_pd, iemgui->x_rcv);
+ iemgui->x_rcv = rcv;
}
iemgui->x_fsf.x_rcv_able = rcvable;
iemgui_verify_snd_ne_rcv(iemgui);
@@ -407,9 +407,9 @@ void iemgui_label(void *x, t_iemgui *iemgui, t_symbol *s)
iemgui->x_lab = lab = canvas_realizedollar(iemgui->x_glist, lab);
if(glist_isvisible(iemgui->x_glist))
- sys_vgui(".x%x.c itemconfigure %xLABEL -text {%s} \n",
- glist_getcanvas(iemgui->x_glist), x,
- strcmp(s->s_name, "empty")?iemgui->x_lab->s_name:"");
+ sys_vgui(".x%lx.c itemconfigure %lxLABEL -text {%s} \n",
+ glist_getcanvas(iemgui->x_glist), x,
+ strcmp(s->s_name, "empty")?iemgui->x_lab->s_name:"");
}
void iemgui_label_pos(void *x, t_iemgui *iemgui, t_symbol *s, int ac, t_atom *av)
@@ -417,10 +417,10 @@ void iemgui_label_pos(void *x, t_iemgui *iemgui, t_symbol *s, int ac, t_atom *av
iemgui->x_ldx = (int)atom_getintarg(0, ac, av);
iemgui->x_ldy = (int)atom_getintarg(1, ac, av);
if(glist_isvisible(iemgui->x_glist))
- sys_vgui(".x%x.c coords %xLABEL %d %d\n",
- glist_getcanvas(iemgui->x_glist), x,
- iemgui->x_obj.te_xpix+iemgui->x_ldx,
- iemgui->x_obj.te_ypix+iemgui->x_ldy);
+ sys_vgui(".x%lx.c coords %lxLABEL %d %d\n",
+ glist_getcanvas(iemgui->x_glist), x,
+ iemgui->x_obj.te_xpix+iemgui->x_ldx,
+ iemgui->x_obj.te_ypix+iemgui->x_ldy);
}
void iemgui_label_font(void *x, t_iemgui *iemgui, t_symbol *s, int ac, t_atom *av)
@@ -431,25 +431,25 @@ void iemgui_label_font(void *x, t_iemgui *iemgui, t_symbol *s, int ac, t_atom *a
else if(f == 2) strcpy(iemgui->x_font, "times");
else
{
- f = 0;
- strcpy(iemgui->x_font, "courier");
+ f = 0;
+ strcpy(iemgui->x_font, "courier");
}
iemgui->x_fsf.x_font_style = f;
f = (int)atom_getintarg(1, ac, av);
if(f < 4)
- f = 4;
+ f = 4;
iemgui->x_fontsize = f;
if(glist_isvisible(iemgui->x_glist))
- sys_vgui(".x%x.c itemconfigure %xLABEL -font {%s %d bold}\n",
- glist_getcanvas(iemgui->x_glist), x, iemgui->x_font, iemgui->x_fontsize);
+ sys_vgui(".x%lx.c itemconfigure %lxLABEL -font {%s %d bold}\n",
+ glist_getcanvas(iemgui->x_glist), x, iemgui->x_font, iemgui->x_fontsize);
}
void iemgui_size(void *x, t_iemgui *iemgui)
{
if(glist_isvisible(iemgui->x_glist))
{
- (*iemgui->x_draw)(x, iemgui->x_glist, IEM_GUI_DRAW_MODE_MOVE);
- canvas_fixlinesfor(glist_getcanvas(iemgui->x_glist), (t_text*)x);
+ (*iemgui->x_draw)(x, iemgui->x_glist, IEM_GUI_DRAW_MODE_MOVE);
+ canvas_fixlinesfor(glist_getcanvas(iemgui->x_glist), (t_text*)x);
}
}
@@ -459,8 +459,8 @@ void iemgui_delta(void *x, t_iemgui *iemgui, t_symbol *s, int ac, t_atom *av)
iemgui->x_obj.te_ypix += (int)atom_getintarg(1, ac, av);
if(glist_isvisible(iemgui->x_glist))
{
- (*iemgui->x_draw)(x, iemgui->x_glist, IEM_GUI_DRAW_MODE_MOVE);
- canvas_fixlinesfor(glist_getcanvas(iemgui->x_glist), (t_text*)x);
+ (*iemgui->x_draw)(x, iemgui->x_glist, IEM_GUI_DRAW_MODE_MOVE);
+ canvas_fixlinesfor(glist_getcanvas(iemgui->x_glist), (t_text*)x);
}
}
@@ -470,8 +470,8 @@ void iemgui_pos(void *x, t_iemgui *iemgui, t_symbol *s, int ac, t_atom *av)
iemgui->x_obj.te_ypix = (int)atom_getintarg(1, ac, av);
if(glist_isvisible(iemgui->x_glist))
{
- (*iemgui->x_draw)(x, iemgui->x_glist, IEM_GUI_DRAW_MODE_MOVE);
- canvas_fixlinesfor(glist_getcanvas(iemgui->x_glist), (t_text*)x);
+ (*iemgui->x_draw)(x, iemgui->x_glist, IEM_GUI_DRAW_MODE_MOVE);
+ canvas_fixlinesfor(glist_getcanvas(iemgui->x_glist), (t_text*)x);
}
}
@@ -480,13 +480,13 @@ void iemgui_color(void *x, t_iemgui *iemgui, t_symbol *s, int ac, t_atom *av)
iemgui->x_bcol = iemgui_compatible_col(atom_getintarg(0, ac, av));
if(ac > 2)
{
- iemgui->x_fcol = iemgui_compatible_col(atom_getintarg(1, ac, av));
- iemgui->x_lcol = iemgui_compatible_col(atom_getintarg(2, ac, av));
+ iemgui->x_fcol = iemgui_compatible_col(atom_getintarg(1, ac, av));
+ iemgui->x_lcol = iemgui_compatible_col(atom_getintarg(2, ac, av));
}
else
- iemgui->x_lcol = iemgui_compatible_col(atom_getintarg(1, ac, av));
+ iemgui->x_lcol = iemgui_compatible_col(atom_getintarg(1, ac, av));
if(glist_isvisible(iemgui->x_glist))
- (*iemgui->x_draw)(x, iemgui->x_glist, IEM_GUI_DRAW_MODE_CONFIG);
+ (*iemgui->x_draw)(x, iemgui->x_glist, IEM_GUI_DRAW_MODE_CONFIG);
}
void iemgui_displace(t_gobj *z, t_glist *glist, int dx, int dy)
@@ -517,9 +517,9 @@ void iemgui_vis(t_gobj *z, t_glist *glist, int vis)
t_iemguidummy *x = (t_iemguidummy *)z;
if (vis)
- (*x->x_gui.x_draw)((void *)z, glist, IEM_GUI_DRAW_MODE_NEW);
+ (*x->x_gui.x_draw)((void *)z, glist, IEM_GUI_DRAW_MODE_NEW);
else
- (*x->x_gui.x_draw)((void *)z, glist, IEM_GUI_DRAW_MODE_ERASE);
+ (*x->x_gui.x_draw)((void *)z, glist, IEM_GUI_DRAW_MODE_ERASE);
}
void iemgui_save(t_iemgui *iemgui, t_symbol **srl, int *bflcol)
@@ -554,29 +554,29 @@ int iemgui_dialog(t_iemgui *iemgui, t_symbol **srl, int argc, t_atom *argv)
int sndable=1, rcvable=1, oldsndrcvable=0;
if(iemgui->x_fsf.x_rcv_able)
- oldsndrcvable += IEM_GUI_OLD_RCV_FLAG;
+ oldsndrcvable += IEM_GUI_OLD_RCV_FLAG;
if(iemgui->x_fsf.x_snd_able)
oldsndrcvable += IEM_GUI_OLD_SND_FLAG;
if(IS_A_SYMBOL(argv,7))
- srl[0] = atom_getsymbolarg(7, argc, argv);
+ srl[0] = atom_getsymbolarg(7, argc, argv);
else if(IS_A_FLOAT(argv,7))
{
- sprintf(str, "%d", (int)atom_getintarg(7, argc, argv));
- srl[0] = gensym(str);
+ sprintf(str, "%d", (int)atom_getintarg(7, argc, argv));
+ srl[0] = gensym(str);
}
if(IS_A_SYMBOL(argv,8))
- srl[1] = atom_getsymbolarg(8, argc, argv);
+ srl[1] = atom_getsymbolarg(8, argc, argv);
else if(IS_A_FLOAT(argv,8))
{
- sprintf(str, "%d", (int)atom_getintarg(8, argc, argv));
- srl[1] = gensym(str);
+ sprintf(str, "%d", (int)atom_getintarg(8, argc, argv));
+ srl[1] = gensym(str);
}
if(IS_A_SYMBOL(argv,9))
- srl[2] = atom_getsymbolarg(9, argc, argv);
+ srl[2] = atom_getsymbolarg(9, argc, argv);
else if(IS_A_FLOAT(argv,9))
{
- sprintf(str, "%d", (int)atom_getintarg(9, argc, argv));
- srl[2] = gensym(str);
+ sprintf(str, "%d", (int)atom_getintarg(9, argc, argv));
+ srl[2] = gensym(str);
}
if(init != 0) init = 1;
iemgui->x_isa.x_loadinit = init;
@@ -586,18 +586,18 @@ int iemgui_dialog(t_iemgui *iemgui, t_symbol **srl, int argc, t_atom *argv)
iemgui_all_dollararg2sym(iemgui, srl);
if(rcvable)
{
- if(strcmp(srl[1]->s_name, iemgui->x_rcv->s_name))
- {
- if(iemgui->x_fsf.x_rcv_able)
- pd_unbind(&iemgui->x_obj.ob_pd, iemgui->x_rcv);
- iemgui->x_rcv = srl[1];
- pd_bind(&iemgui->x_obj.ob_pd, iemgui->x_rcv);
- }
+ if(strcmp(srl[1]->s_name, iemgui->x_rcv->s_name))
+ {
+ if(iemgui->x_fsf.x_rcv_able)
+ pd_unbind(&iemgui->x_obj.ob_pd, iemgui->x_rcv);
+ iemgui->x_rcv = srl[1];
+ pd_bind(&iemgui->x_obj.ob_pd, iemgui->x_rcv);
+ }
}
else if(!rcvable && iemgui->x_fsf.x_rcv_able)
{
- pd_unbind(&iemgui->x_obj.ob_pd, iemgui->x_rcv);
- iemgui->x_rcv = srl[1];
+ pd_unbind(&iemgui->x_obj.ob_pd, iemgui->x_rcv);
+ iemgui->x_rcv = srl[1];
}
iemgui->x_snd = srl[0];
iemgui->x_fsf.x_snd_able = sndable;
@@ -612,12 +612,12 @@ int iemgui_dialog(t_iemgui *iemgui, t_symbol **srl, int argc, t_atom *argv)
else if(f == 2) strcpy(iemgui->x_font, "times");
else
{
- f = 0;
- strcpy(iemgui->x_font, "courier");
+ f = 0;
+ strcpy(iemgui->x_font, "courier");
}
iemgui->x_fsf.x_font_style = f;
if(fs < 4)
- fs = 4;
+ fs = 4;
iemgui->x_fontsize = fs;
iemgui_verify_snd_ne_rcv(iemgui);
return(oldsndrcvable);
@@ -637,8 +637,8 @@ void iem_inttosymargs(t_iem_init_symargs *symargp, int n)
int iem_symargstoint(t_iem_init_symargs *symargp)
{
return (
- (((symargp->x_loadinit & 1) << 0) |
- ((symargp->x_scale & 1) << 20)));
+ (((symargp->x_loadinit & 1) << 0) |
+ ((symargp->x_scale & 1) << 20)));
}
void iem_inttofstyle(t_iem_fstyle_flags *fstylep, int n)
diff --git a/pd/src/g_all_guis.h b/pd/src/g_all_guis.h
index 66d79bc9..2bc38f12 100644
--- a/pd/src/g_all_guis.h
+++ b/pd/src/g_all_guis.h
@@ -151,14 +151,14 @@ typedef struct _iemgui
int x_fcol;
int x_bcol;
int x_lcol;
- t_symbol *x_snd; /* send symbol */
- t_symbol *x_rcv; /* receive */
- t_symbol *x_lab; /* label */
- t_symbol *x_snd_unexpanded; /* same 3, with '$' unexpanded */
- t_symbol *x_rcv_unexpanded;
- t_symbol *x_lab_unexpanded;
- int x_binbufindex; /* where in binbuf to find these */
- int x_labelbindex; /* where in binbuf to find label */
+ t_symbol *x_snd; /* send symbol */
+ t_symbol *x_rcv; /* receive */
+ t_symbol *x_lab; /* label */
+ t_symbol *x_snd_unexpanded; /* same 3, with '$' unexpanded */
+ t_symbol *x_rcv_unexpanded;
+ t_symbol *x_lab_unexpanded;
+ int x_binbufindex; /* where in binbuf to find these */
+ int x_labelbindex; /* where in binbuf to find label */
} t_iemgui;
typedef struct _iemguidummy
diff --git a/pd/src/g_array.c b/pd/src/g_array.c
index f42e913e..434cea72 100644
--- a/pd/src/g_array.c
+++ b/pd/src/g_array.c
@@ -4,7 +4,7 @@
#include <stdlib.h>
#include <string.h>
-#include <stdio.h> /* for read/write to files */
+#include <stdio.h> /* for read/write to files */
#include "m_pd.h"
#include "g_canvas.h"
#include <math.h>
@@ -21,11 +21,11 @@ static t_symbol *sharptodollar(t_symbol *s)
{
if (*s->s_name == '#')
{
- char buf[MAXPDSTRING];
- strncpy(buf, s->s_name, MAXPDSTRING);
- buf[MAXPDSTRING-1] = 0;
- buf[0] = '$';
- return (gensym(buf));
+ char buf[MAXPDSTRING];
+ strncpy(buf, s->s_name, MAXPDSTRING);
+ buf[MAXPDSTRING-1] = 0;
+ buf[0] = '$';
+ return (gensym(buf));
}
else return (s);
}
@@ -46,10 +46,10 @@ t_array *array_new(t_symbol *templatesym, t_gpointer *parent)
x->a_n = 1;
x->a_elemsize = sizeof(t_word) * template->t_n;
x->a_vec = (char *)getbytes(x->a_elemsize);
- /* note here we blithely copy a gpointer instead of "setting" a
- new one; this gpointer isn't accounted for and needn't be since
- we'll be deleted before the thing pointed to gets deleted anyway;
- see array_free. */
+ /* note here we blithely copy a gpointer instead of "setting" a
+ new one; this gpointer isn't accounted for and needn't be since
+ we'll be deleted before the thing pointed to gets deleted anyway;
+ see array_free. */
x->a_gp = *parent;
x->a_stub = gstub_new(0, x);
word_init((t_word *)(x->a_vec), template, parent);
@@ -62,22 +62,22 @@ void array_resize(t_array *x, t_template *template, int n)
t_gpointer *gp;
if (n < 1)
- n = 1;
+ n = 1;
oldn = x->a_n;
elemsize = sizeof(t_word) * template->t_n;
x->a_vec = (char *)resizebytes(x->a_vec, oldn * elemsize,
- n * elemsize);
+ n * elemsize);
x->a_n = n;
if (n > oldn)
{
- char *cp = x->a_vec + elemsize * oldn;
- int i = n - oldn;
- for (; i--; cp += elemsize)
- {
- t_word *wp = (t_word *)cp;
- word_init(wp, template, &x->a_gp);
- }
+ char *cp = x->a_vec + elemsize * oldn;
+ int i = n - oldn;
+ for (; i--; cp += elemsize)
+ {
+ t_word *wp = (t_word *)cp;
+ word_init(wp, template, &x->a_gp);
+ }
}
}
@@ -87,13 +87,13 @@ void array_free(t_array *x)
{
int i;
t_template *scalartemplate = template_findbyname(x->a_templatesym);
- /* we don't unset our gpointer here since it was never "set." */
+ /* we don't unset our gpointer here since it was never "set." */
/* gpointer_unset(&x->a_gp); */
gstub_cutoff(x->a_stub);
for (i = 0; i < x->a_n; i++)
{
- t_word *wp = (t_word *)(x->a_vec + x->a_elemsize * i);
- word_free(wp, scalartemplate);
+ t_word *wp = (t_word *)(x->a_vec + x->a_elemsize * i);
+ word_free(wp, scalartemplate);
}
freebytes(x->a_vec, x->a_elemsize * x->a_n);
freebytes(x, sizeof *x);
@@ -108,13 +108,14 @@ struct _garray
{
t_gobj x_gobj;
t_glist *x_glist;
- t_array x_array; /* actual array; note only 4 fields used as below */
+ t_array x_array; /* actual array; note only 4 fields used as below */
t_symbol *x_name;
t_symbol *x_realname; /* name with "$" expanded */
- t_float x_firstx; /* X value of first item */
- t_float x_xinc; /* X increment */
- char x_usedindsp; /* true if some DSP routine is using this */
- char x_saveit; /* true if we should save this with parent */
+ t_float x_firstx; /* X value of first item */
+ t_float x_xinc; /* X increment */
+ char x_usedindsp; /* true if some DSP routine is using this */
+ char x_saveit; /* true if we should save this with parent */
+ char x_drawasrects; /* draw as rectangles, not a polygon */
};
/* macros to get into the "array" structure */
@@ -124,7 +125,7 @@ struct _garray
#define x_templatesym x_array.a_templatesym
t_garray *graph_array(t_glist *gl, t_symbol *s, t_symbol *templatesym,
- t_floatarg f, t_floatarg saveit)
+ t_floatarg f, t_floatarg fflags)
{
int n = f, i;
int zz, nwords;
@@ -132,34 +133,35 @@ t_garray *graph_array(t_glist *gl, t_symbol *s, t_symbol *templatesym,
t_pd *x2;
t_template *template;
char *str;
+ int flags = fflags;
if (s == &s_)
{
- char buf[40];
- sprintf(buf, "array%d", ++gcount);
- s = gensym(buf);
- templatesym = &s_float;
- n = 100;
+ char buf[40];
+ sprintf(buf, "array%d", ++gcount);
+ s = gensym(buf);
+ templatesym = &s_float;
+ n = 100;
}
else if (!strncmp((str = s->s_name), "array", 5)
- && (zz = atoi(str + 5)) > gcount) gcount = zz;
+ && (zz = atoi(str + 5)) > gcount) gcount = zz;
template = template_findbyname(templatesym);
if (!template)
{
- error("array: couldn't find template %s", templatesym->s_name);
- return (0);
+ error("array: couldn't find template %s", templatesym->s_name);
+ return (0);
}
nwords = template->t_n;
for (i = 0; i < nwords; i++)
{
- /* we can't have array or list elements yet because what scalar
- can act as their "parent"??? */
- if (template->t_vec[i].ds_type == DT_ARRAY
- || template->t_vec[i].ds_type == DT_LIST)
- {
- error("array: template %s can't have sublists or arrays",
- templatesym->s_name);
- return (0);
- }
+ /* we can't have array or list elements yet because what scalar
+ can act as their "parent"??? */
+ if (template->t_vec[i].ds_type == DT_ARRAY
+ || template->t_vec[i].ds_type == DT_LIST)
+ {
+ error("array: template %s can't have sublists or arrays",
+ templatesym->s_name);
+ return (0);
+ }
}
x = (t_garray *)pd_new(garray_class);
@@ -168,19 +170,20 @@ t_garray *graph_array(t_glist *gl, t_symbol *s, t_symbol *templatesym,
x->x_elemsize = nwords * sizeof(t_word);
x->x_vec = getbytes(x->x_n * x->x_elemsize);
memset(x->x_vec, 0, x->x_n * x->x_elemsize);
- /* LATER should check that malloc */
+ /* LATER should check that malloc */
x->x_name = s;
x->x_realname = canvas_realizedollar(gl, s);
pd_bind(&x->x_gobj.g_pd, x->x_realname);
x->x_templatesym = templatesym;
x->x_firstx = 0;
- x->x_xinc = 1; /* LATER make methods to set this... */
+ x->x_xinc = 1; /* LATER make methods to set this... */
+ x->x_drawasrects = ((flags & 2) != 0);
+ x->x_usedindsp = 0;
+ x->x_saveit = ((flags & 1) != 0);
glist_add(gl, &x->x_gobj);
x->x_glist = gl;
- x->x_usedindsp = 0;
- x->x_saveit = (saveit != 0);
if (x2 = pd_findbyclass(gensym("#A"), garray_class))
- pd_unbind(x2, gensym("#A"));
+ pd_unbind(x2, gensym("#A"));
pd_bind(&x->x_gobj.g_pd, gensym("#A"));
@@ -192,8 +195,8 @@ void canvas_menuarray(t_glist *canvas)
{
t_glist *x = (t_glist *)canvas;
char cmdbuf[200];
- sprintf(cmdbuf, "pdtk_array_dialog %%s array%d 100 1 1\n",
- ++gcount);
+ sprintf(cmdbuf, "pdtk_array_dialog %%s array%d 100 3 1\n",
+ ++gcount);
gfxstub_new(&x->gl_pd, x, cmdbuf);
}
@@ -202,58 +205,63 @@ void garray_properties(t_garray *x)
{
char cmdbuf[200];
gfxstub_deleteforkey(x);
- /* create dialog window. LATER fix this to escape '$'
- properly; right now we just detect a leading '$' and escape
- it. There should be a systematic way of doing this. */
+ /* create dialog window. LATER fix this to escape '$'
+ properly; right now we just detect a leading '$' and escape
+ it. There should be a systematic way of doing this. */
if (x->x_name->s_name[0] == '$')
- sprintf(cmdbuf, "pdtk_array_dialog %%s \\%s %d %d 0\n",
- x->x_name->s_name, x->x_n, x->x_saveit);
+ sprintf(cmdbuf, "pdtk_array_dialog %%s \\%s %d %d 0\n",
+ x->x_name->s_name, x->x_n, x->x_saveit);
else sprintf(cmdbuf, "pdtk_array_dialog %%s %s %d %d 0\n",
- x->x_name->s_name, x->x_n, x->x_saveit);
+ x->x_name->s_name, x->x_n, x->x_saveit + (x->x_drawasrects<<1));
gfxstub_new(&x->x_gobj.g_pd, x, cmdbuf);
}
/* this is called back from the dialog window to create a garray.
The otherflag requests that we find an existing graph to put it in. */
void glist_arraydialog(t_glist *parent, t_symbol *name, t_floatarg size,
- t_floatarg saveit, t_floatarg otherflag)
+ t_floatarg fflags, t_floatarg otherflag)
{
t_glist *gl;
t_garray *a;
+ int flags = fflags;
if (size < 1)
- size = 1;
+ size = 1;
if (otherflag == 0 || (!(gl = glist_findgraph(parent))))
- gl = glist_addglist(parent, &s_, 0, 1,
- (size > 1 ? size-1 : size), -1, 0, 0, 0, 0);
- a = graph_array(gl, sharptodollar(name), &s_float, size, saveit);
+ gl = glist_addglist(parent, &s_, 0, 1,
+ (size > 1 ? size-1 : size), -1, 0, 0, 0, 0);
+ a = graph_array(gl, sharptodollar(name), &s_float, size, flags);
}
/* this is called from the properties dialog window for an existing array */
void garray_arraydialog(t_garray *x, t_symbol *name, t_floatarg fsize,
- t_floatarg saveit, t_floatarg deleteit)
+ t_floatarg fflags, t_floatarg deleteit)
{
+ int flags = fflags;
+ int saveit = ((flags & 1) != 0);
+ int drawasrects = ((flags & 2) != 0);
if (deleteit != 0)
{
- glist_delete(x->x_glist, &x->x_gobj);
+ glist_delete(x->x_glist, &x->x_gobj);
}
else
{
- int size;
- t_symbol *argname = sharptodollar(name);
- if (argname != x->x_name)
- {
- x->x_name = argname;
- pd_unbind(&x->x_gobj.g_pd, x->x_realname);
- x->x_realname = canvas_realizedollar(x->x_glist, argname);
- pd_bind(&x->x_gobj.g_pd, x->x_realname);
- }
- size = fsize;
- if (size < 1)
- size = 1;
- if (size != x->x_n)
- garray_resize(x, size);
- garray_setsaveit(x, (saveit != 0));
- garray_redraw(x);
+ int size;
+ t_symbol *argname = sharptodollar(name);
+ if (argname != x->x_name)
+ {
+ x->x_name = argname;
+ pd_unbind(&x->x_gobj.g_pd, x->x_realname);
+ x->x_realname = canvas_realizedollar(x->x_glist, argname);
+ pd_bind(&x->x_gobj.g_pd, x->x_realname);
+ }
+ size = fsize;
+ if (size < 1)
+ size = 1;
+ if (size != x->x_n)
+ garray_resize(x, size);
+ x->x_drawasrects = drawasrects;
+ garray_setsaveit(x, (saveit != 0));
+ garray_redraw(x);
}
}
@@ -262,9 +270,9 @@ static void garray_free(t_garray *x)
t_pd *x2;
gfxstub_deleteforkey(x);
pd_unbind(&x->x_gobj.g_pd, x->x_realname);
- /* LATER find a way to get #A unbound earlier (at end of load?) */
+ /* LATER find a way to get #A unbound earlier (at end of load?) */
while (x2 = pd_findbyclass(gensym("#A"), garray_class))
- pd_unbind(x2, gensym("#A"));
+ pd_unbind(x2, gensym("#A"));
freebytes(x->x_vec, x->x_n * x->x_elemsize);
}
@@ -278,19 +286,19 @@ void array_getcoordinate(t_glist *glist,
{
float xval, yval, ypix, wpix;
if (xonset >= 0)
- xval = *(float *)(elem + xonset);
+ xval = *(float *)(elem + xonset);
else xval = indx * xinc;
if (yonset >= 0)
- yval = *(float *)(elem + yonset);
+ yval = *(float *)(elem + yonset);
else yval = 0;
ypix = glist_ytopixels(glist, basey + yval);
if (wonset >= 0)
{
- /* found "w" field which controls linewidth. */
- float wval = *(float *)(elem + wonset);
- wpix = glist_ytopixels(glist, basey + yval + wval) - ypix;
- if (wpix < 0)
- wpix = -wpix;
+ /* found "w" field which controls linewidth. */
+ float wval = *(float *)(elem + wonset);
+ wpix = glist_ytopixels(glist, basey + yval + wval) - ypix;
+ if (wpix < 0)
+ wpix = -wpix;
}
else wpix = 1;
*xp = glist_xtopixels(glist, basex + xval);
@@ -324,73 +332,73 @@ static void array_motion(void *z, t_floatarg dx, t_floatarg dy)
array_motion_ycumulative += dy * array_motion_yperpix;
if (*array_motion_xfield->s_name)
{
- /* it's an x, y plot; can drag many points at once */
- int i;
- char *charword = (char *)array_motion_wp;
- for (i = 0; i < array_motion_npoints; i++)
- {
- t_word *thisword = (t_word *)(charword + i * array_motion_elemsize);
- if (*array_motion_xfield->s_name)
- {
- float xwas = template_getfloat(array_motion_template,
- array_motion_xfield, thisword, 1);
- template_setfloat(array_motion_template,
- array_motion_xfield, thisword, xwas + dx, 1);
- }
- if (*array_motion_yfield->s_name)
- {
- float ywas = template_getfloat(array_motion_template,
- array_motion_yfield, thisword, 1);
- if (array_motion_fatten)
- {
- if (i == 0)
- {
- float newy = ywas + dy * array_motion_yperpix;
- if (newy < 0)
- newy = 0;
- template_setfloat(array_motion_template,
- array_motion_yfield, thisword, newy, 1);
- }
- }
- else
- {
- template_setfloat(array_motion_template,
- array_motion_yfield, thisword,
- ywas + dy * array_motion_yperpix, 1);
- }
- }
- }
+ /* it's an x, y plot; can drag many points at once */
+ int i;
+ char *charword = (char *)array_motion_wp;
+ for (i = 0; i < array_motion_npoints; i++)
+ {
+ t_word *thisword = (t_word *)(charword + i * array_motion_elemsize);
+ if (*array_motion_xfield->s_name)
+ {
+ float xwas = template_getfloat(array_motion_template,
+ array_motion_xfield, thisword, 1);
+ template_setfloat(array_motion_template,
+ array_motion_xfield, thisword, xwas + dx, 1);
+ }
+ if (*array_motion_yfield->s_name)
+ {
+ float ywas = template_getfloat(array_motion_template,
+ array_motion_yfield, thisword, 1);
+ if (array_motion_fatten)
+ {
+ if (i == 0)
+ {
+ float newy = ywas + dy * array_motion_yperpix;
+ if (newy < 0)
+ newy = 0;
+ template_setfloat(array_motion_template,
+ array_motion_yfield, thisword, newy, 1);
+ }
+ }
+ else
+ {
+ template_setfloat(array_motion_template,
+ array_motion_yfield, thisword,
+ ywas + dy * array_motion_yperpix, 1);
+ }
+ }
+ }
}
else
{
- /* a y-only plot. */
- int thisx = array_motion_initx +
- array_motion_xcumulative, x2;
- int increment, i, nchange;
- char *charword = (char *)array_motion_wp;
- float newy = array_motion_ycumulative,
- oldy = template_getfloat(
- array_motion_template, array_motion_yfield,
- (t_word *)(charword + array_motion_elemsize * array_motion_lastx), 1);
- float ydiff = newy - oldy;
- if (thisx < 0) thisx = 0;
- else if (thisx >= array_motion_npoints)
- thisx = array_motion_npoints - 1;
- increment = (thisx > array_motion_lastx ? -1 : 1);
- nchange = 1 + increment * (array_motion_lastx - thisx);
-
- for (i = 0, x2 = thisx; i < nchange; i++, x2 += increment)
- {
- template_setfloat(array_motion_template,
- array_motion_yfield,
- (t_word *)(charword + array_motion_elemsize * x2),
- newy, 1);
- if (nchange > 1)
- newy -= ydiff * (1./(nchange - 1));
- }
- array_motion_lastx = thisx;
+ /* a y-only plot. */
+ int thisx = array_motion_initx +
+ array_motion_xcumulative, x2;
+ int increment, i, nchange;
+ char *charword = (char *)array_motion_wp;
+ float newy = array_motion_ycumulative,
+ oldy = template_getfloat(
+ array_motion_template, array_motion_yfield,
+ (t_word *)(charword + array_motion_elemsize * array_motion_lastx), 1);
+ float ydiff = newy - oldy;
+ if (thisx < 0) thisx = 0;
+ else if (thisx >= array_motion_npoints)
+ thisx = array_motion_npoints - 1;
+ increment = (thisx > array_motion_lastx ? -1 : 1);
+ nchange = 1 + increment * (array_motion_lastx - thisx);
+
+ for (i = 0, x2 = thisx; i < nchange; i++, x2 += increment)
+ {
+ template_setfloat(array_motion_template,
+ array_motion_yfield,
+ (t_word *)(charword + array_motion_elemsize * x2),
+ newy, 1);
+ if (nchange > 1)
+ newy -= ydiff * (1./(nchange - 1));
+ }
+ array_motion_lastx = thisx;
}
- glist_redrawitem(array_motion_glist, array_motion_gobj);
+ sys_queuegui(array_motion_gobj, array_motion_glist, gobj_redraw);
}
int array_doclick(t_array *array, t_glist *glist, t_gobj *gobj,
@@ -403,153 +411,153 @@ int array_doclick(t_array *array, t_glist *glist, t_gobj *gobj,
int elemsize, yonset, wonset, xonset, i;
if (!array_getfields(elemtemplatesym, &elemtemplatecanvas,
- &elemtemplate, &elemsize, &xonset, &yonset, &wonset))
+ &elemtemplate, &elemsize, &xonset, &yonset, &wonset))
{
- float best = 100;
- int incr;
- /* if it has more than 2000 points, just check 300 of them. */
- if (array->a_n < 2000)
- incr = 1;
- else incr = array->a_n / 300;
- for (i = 0; i < array->a_n; i += incr)
- {
- float pxpix, pypix, pwpix, dx, dy;
- array_getcoordinate(glist, (char *)(array->a_vec) + i * elemsize,
- xonset, yonset, wonset, i, xloc, yloc, xinc,
- &pxpix, &pypix, &pwpix);
- if (pwpix < 4)
- pwpix = 4;
- dx = pxpix - xpix;
- if (dx < 0) dx = -dx;
- if (dx > 8)
- continue;
- dy = pypix - ypix;
- if (dy < 0) dy = -dy;
- if (dx + dy < best)
- best = dx + dy;
- if (wonset >= 0)
- {
- dy = (pypix + pwpix) - ypix;
- if (dy < 0) dy = -dy;
- if (dx + dy < best)
- best = dx + dy;
- dy = (pypix - pwpix) - ypix;
- if (dy < 0) dy = -dy;
- if (dx + dy < best)
- best = dx + dy;
- }
- }
- if (best > 8)
- return (0);
- best += 0.001; /* add truncation error margin */
- for (i = 0; i < array->a_n; i += incr)
- {
- float pxpix, pypix, pwpix, dx, dy, dy2, dy3;
- array_getcoordinate(glist, (char *)(array->a_vec) + i * elemsize,
- xonset, yonset, wonset, i, xloc, yloc, xinc,
- &pxpix, &pypix, &pwpix);
- if (pwpix < 4)
- pwpix = 4;
- dx = pxpix - xpix;
- if (dx < 0) dx = -dx;
- dy = pypix - ypix;
- if (dy < 0) dy = -dy;
- if (wonset >= 0)
- {
- dy2 = (pypix + pwpix) - ypix;
- if (dy2 < 0) dy2 = -dy2;
- dy3 = (pypix - pwpix) - ypix;
- if (dy3 < 0) dy3 = -dy3;
- if (yonset <= 0)
- dy = 100;
- }
- else dy2 = dy3 = 100;
- if (dx + dy <= best || dx + dy2 <= best || dx + dy3 <= best)
- {
- if (dy < dy2 && dy < dy3)
- array_motion_fatten = 0;
- else if (dy2 < dy3)
- array_motion_fatten = -1;
- else array_motion_fatten = 1;
- if (doit)
- {
- char *elem = (char *)array->a_vec;
- array_motion_elemsize = elemsize;
- array_motion_glist = glist;
- array_motion_gobj = gobj;
- array_motion_template = elemtemplate;
- array_motion_xperpix = glist_dpixtodx(glist, 1);
- array_motion_yperpix = glist_dpixtody(glist, 1);
- if (alt && xpix < pxpix) /* delete a point */
- {
- if (array->a_n <= 1)
- return (0);
- memmove((char *)(array->a_vec) + elemsize * i,
- (char *)(array->a_vec) + elemsize * (i+1),
- (array->a_n - 1 - i) * elemsize);
- array_resize(array, elemtemplate, array->a_n - 1);
- glist_redrawitem(array_motion_glist, array_motion_gobj);
- return (0);
- }
- else if (alt)
- {
- /* add a point (after the clicked-on one) */
- array_resize(array, elemtemplate, array->a_n + 1);
- elem = (char *)array->a_vec;
- memmove(elem + elemsize * (i+1),
- elem + elemsize * i,
- (array->a_n - i - 1) * elemsize);
- i++;
- }
- if (xonset >= 0)
- {
- array_motion_xfield = gensym("x");
- array_motion_xcumulative =
- *(float *)((elem + elemsize * i) + xonset);
- array_motion_wp = (t_word *)(elem + i * elemsize);
- array_motion_npoints = array->a_n - i;
- }
- else
- {
- array_motion_xfield = &s_;
- array_motion_xcumulative = 0;
- array_motion_wp = (t_word *)elem;
- array_motion_npoints = array->a_n;
-
- array_motion_initx = i;
- array_motion_lastx = i;
- array_motion_xperpix *= (xinc == 0 ? 1 : 1./xinc);
- }
- if (array_motion_fatten)
- {
- array_motion_yfield = gensym("w");
- array_motion_ycumulative =
- *(float *)((elem + elemsize * i) + wonset);
- array_motion_yperpix *= array_motion_fatten;
- }
- else if (yonset >= 0)
- {
- array_motion_yfield = gensym("y");
- array_motion_ycumulative =
- *(float *)((elem + elemsize * i) + yonset);
- }
- else
- {
- array_motion_yfield = &s_;
- array_motion_ycumulative = 0;
- }
- glist_grab(glist, 0, array_motion, 0, xpix, ypix);
- }
- if (alt)
- {
- if (xpix < pxpix)
- return (CURSOR_EDITMODE_DISCONNECT);
- else return (CURSOR_RUNMODE_ADDPOINT);
- }
- else return (array_motion_fatten ?
- CURSOR_RUNMODE_THICKEN : CURSOR_RUNMODE_CLICKME);
- }
- }
+ float best = 100;
+ int incr;
+ /* if it has more than 2000 points, just check 300 of them. */
+ if (array->a_n < 2000)
+ incr = 1;
+ else incr = array->a_n / 300;
+ for (i = 0; i < array->a_n; i += incr)
+ {
+ float pxpix, pypix, pwpix, dx, dy;
+ array_getcoordinate(glist, (char *)(array->a_vec) + i * elemsize,
+ xonset, yonset, wonset, i, xloc, yloc, xinc,
+ &pxpix, &pypix, &pwpix);
+ if (pwpix < 4)
+ pwpix = 4;
+ dx = pxpix - xpix;
+ if (dx < 0) dx = -dx;
+ if (dx > 8)
+ continue;
+ dy = pypix - ypix;
+ if (dy < 0) dy = -dy;
+ if (dx + dy < best)
+ best = dx + dy;
+ if (wonset >= 0)
+ {
+ dy = (pypix + pwpix) - ypix;
+ if (dy < 0) dy = -dy;
+ if (dx + dy < best)
+ best = dx + dy;
+ dy = (pypix - pwpix) - ypix;
+ if (dy < 0) dy = -dy;
+ if (dx + dy < best)
+ best = dx + dy;
+ }
+ }
+ if (best > 8)
+ return (0);
+ best += 0.001; /* add truncation error margin */
+ for (i = 0; i < array->a_n; i += incr)
+ {
+ float pxpix, pypix, pwpix, dx, dy, dy2, dy3;
+ array_getcoordinate(glist, (char *)(array->a_vec) + i * elemsize,
+ xonset, yonset, wonset, i, xloc, yloc, xinc,
+ &pxpix, &pypix, &pwpix);
+ if (pwpix < 4)
+ pwpix = 4;
+ dx = pxpix - xpix;
+ if (dx < 0) dx = -dx;
+ dy = pypix - ypix;
+ if (dy < 0) dy = -dy;
+ if (wonset >= 0)
+ {
+ dy2 = (pypix + pwpix) - ypix;
+ if (dy2 < 0) dy2 = -dy2;
+ dy3 = (pypix - pwpix) - ypix;
+ if (dy3 < 0) dy3 = -dy3;
+ if (yonset < 0)
+ dy = 100;
+ }
+ else dy2 = dy3 = 100;
+ if (dx + dy <= best || dx + dy2 <= best || dx + dy3 <= best)
+ {
+ if (dy < dy2 && dy < dy3)
+ array_motion_fatten = 0;
+ else if (dy2 < dy3)
+ array_motion_fatten = -1;
+ else array_motion_fatten = 1;
+ if (doit)
+ {
+ char *elem = (char *)array->a_vec;
+ array_motion_elemsize = elemsize;
+ array_motion_glist = glist;
+ array_motion_gobj = gobj;
+ array_motion_template = elemtemplate;
+ array_motion_xperpix = glist_dpixtodx(glist, 1);
+ array_motion_yperpix = glist_dpixtody(glist, 1);
+ if (alt && xpix < pxpix) /* delete a point */
+ {
+ if (array->a_n <= 1)
+ return (0);
+ memmove((char *)(array->a_vec) + elemsize * i,
+ (char *)(array->a_vec) + elemsize * (i+1),
+ (array->a_n - 1 - i) * elemsize);
+ array_resize(array, elemtemplate, array->a_n - 1);
+ glist_redrawitem(array_motion_glist, array_motion_gobj);
+ return (0);
+ }
+ else if (alt)
+ {
+ /* add a point (after the clicked-on one) */
+ array_resize(array, elemtemplate, array->a_n + 1);
+ elem = (char *)array->a_vec;
+ memmove(elem + elemsize * (i+1),
+ elem + elemsize * i,
+ (array->a_n - i - 1) * elemsize);
+ i++;
+ }
+ if (xonset >= 0)
+ {
+ array_motion_xfield = gensym("x");
+ array_motion_xcumulative =
+ *(float *)((elem + elemsize * i) + xonset);
+ array_motion_wp = (t_word *)(elem + i * elemsize);
+ array_motion_npoints = array->a_n - i;
+ }
+ else
+ {
+ array_motion_xfield = &s_;
+ array_motion_xcumulative = 0;
+ array_motion_wp = (t_word *)elem;
+ array_motion_npoints = array->a_n;
+
+ array_motion_initx = i;
+ array_motion_lastx = i;
+ array_motion_xperpix *= (xinc == 0 ? 1 : 1./xinc);
+ }
+ if (array_motion_fatten)
+ {
+ array_motion_yfield = gensym("w");
+ array_motion_ycumulative =
+ *(float *)((elem + elemsize * i) + wonset);
+ array_motion_yperpix *= array_motion_fatten;
+ }
+ else if (yonset >= 0)
+ {
+ array_motion_yfield = gensym("y");
+ array_motion_ycumulative =
+ *(float *)((elem + elemsize * i) + yonset);
+ }
+ else
+ {
+ array_motion_yfield = &s_;
+ array_motion_ycumulative = 0;
+ }
+ glist_grab(glist, 0, array_motion, 0, xpix, ypix);
+ }
+ if (alt)
+ {
+ if (xpix < pxpix)
+ return (CURSOR_EDITMODE_DISCONNECT);
+ else return (CURSOR_RUNMODE_ADDPOINT);
+ }
+ else return (array_motion_fatten ?
+ CURSOR_RUNMODE_THICKEN : CURSOR_RUNMODE_CLICKME);
+ }
+ }
}
return (0);
}
@@ -566,31 +574,31 @@ static void garray_getrect(t_gobj *z, t_glist *glist,
int elemsize, yonset, wonset, xonset, i;
if (!array_getfields(x->x_templatesym, &elemtemplatecanvas,
- &elemtemplate, &elemsize, &xonset, &yonset, &wonset))
+ &elemtemplate, &elemsize, &xonset, &yonset, &wonset))
{
- int incr;
- /* if it has more than 2000 points, just check 300 of them. */
- if (x->x_array.a_n < 2000)
- incr = 1;
- else incr = x->x_array.a_n / 300;
- for (i = 0; i < x->x_array.a_n; i += incr)
- {
- float pxpix, pypix, pwpix, dx, dy;
- array_getcoordinate(glist, (char *)(x->x_array.a_vec) +
- i * elemsize,
- xonset, yonset, wonset, i, 0, 0, 1,
- &pxpix, &pypix, &pwpix);
- if (pwpix < 2)
- pwpix = 2;
- if (pxpix < x1)
- x1 = pxpix;
- if (pxpix > x2)
- x2 = pxpix;
- if (pypix - pwpix < y1)
- y1 = pypix - pwpix;
- if (pypix + pwpix > y2)
- y2 = pypix + pwpix;
- }
+ int incr;
+ /* if it has more than 2000 points, just check 300 of them. */
+ if (x->x_array.a_n < 2000)
+ incr = 1;
+ else incr = x->x_array.a_n / 300;
+ for (i = 0; i < x->x_array.a_n; i += incr)
+ {
+ float pxpix, pypix, pwpix, dx, dy;
+ array_getcoordinate(glist, (char *)(x->x_array.a_vec) +
+ i * elemsize,
+ xonset, yonset, wonset, i, 0, 0, 1,
+ &pxpix, &pypix, &pwpix);
+ if (pwpix < 2)
+ pwpix = 2;
+ if (pxpix < x1)
+ x1 = pxpix;
+ if (pxpix > x2)
+ x2 = pxpix;
+ if (pypix - pwpix < y1)
+ y1 = pypix - pwpix;
+ if (pypix + pwpix > y2)
+ y2 = pypix + pwpix;
+ }
}
*xp1 = x1;
*yp1 = y1;
@@ -623,67 +631,111 @@ static void garray_vis(t_gobj *z, t_glist *glist, int vis)
t_garray *x = (t_garray *)z;
if (vis)
{
- int i, xonset, yonset, type;
- t_symbol *arraytype;
- t_template *template = template_findbyname(x->x_templatesym);
- if (!template)
- return;
- if (!template_find_field(template, gensym("y"), &yonset, &type,
- &arraytype) || type != DT_FLOAT)
- {
- error("%s: needs floating-point 'y' field",
- x->x_templatesym->s_name);
- sys_vgui(".x%x.c create text 50 50 -text foo\
- -tags .x%x.a%x\n",
- glist_getcanvas(glist), glist_getcanvas(glist), x);
- }
- else if (!template_find_field(template, gensym("x"), &xonset, &type,
- &arraytype) || type != DT_FLOAT)
- {
- float firsty, xcum = x->x_firstx;
- int lastpixel = -1, ndrawn = 0;
- float yval = 0, xpix;
- int ixpix = 0;
- sys_vgui(".x%x.c create line \\\n", glist_getcanvas(glist));
- for (i = 0; i < x->x_n; i++)
- {
- yval = *(float *)(x->x_vec +
- template->t_n * i * sizeof (t_word) + yonset);
- xpix = glist_xtopixels(glist, xcum);
- ixpix = xpix + 0.5;
- if (ixpix != lastpixel)
- {
- sys_vgui("%d %f \\\n", ixpix,
- glist_ytopixels(glist, yval));
- ndrawn++;
- }
- lastpixel = ixpix;
- if (ndrawn >= 1000) break;
- xcum += x->x_xinc;
- }
- /* TK will complain if there aren't at least 2 points... */
- if (ndrawn == 0) sys_vgui("0 0 0 0 \\\n");
- else if (ndrawn == 1) sys_vgui("%d %f \\\n", ixpix,
- glist_ytopixels(glist, yval));
- sys_vgui("-tags .x%x.a%x\n", glist_getcanvas(glist), x);
- firsty = *(float *)(x->x_vec + yonset);
- sys_vgui(".x%x.c create text %f %f -text {%s} -anchor e\
- -font -*-courier-bold--normal--%d-* -tags .x%x.a%x\n",
- glist_getcanvas(glist),
- glist_xtopixels(glist, x->x_firstx) - 5.,
- glist_ytopixels(glist, firsty),
- x->x_name->s_name, glist_getfont(glist),
- glist_getcanvas(glist), x);
- }
- else
- {
- post("x, y arrays not yet supported");
- }
+ int i, xonset, yonset, type;
+ t_symbol *arraytype;
+ t_template *template = template_findbyname(x->x_templatesym);
+ if (!template)
+ return;
+ if (!template_find_field(template, gensym("y"), &yonset, &type,
+ &arraytype) || type != DT_FLOAT)
+ {
+ error("%s: needs floating-point 'y' field",
+ x->x_templatesym->s_name);
+ sys_vgui(".x%lx.c create text 50 50 -text foo\
+ -tags .x%lx.a%lx\n",
+ glist_getcanvas(glist), glist_getcanvas(glist), x);
+ }
+ else if (!template_find_field(template, gensym("x"), &xonset, &type,
+ &arraytype) || type != DT_FLOAT)
+ {
+ if (x->x_drawasrects)
+ {
+ float xcum = x->x_firstx;
+ float minyval = 1e20, maxyval = -1e20;
+ float nextxpix = glist_xtopixels(glist, xcum);
+ int lastpixel = -0x7fffffff;
+ int ndrawn = 0;
+ for (i = 0; i < x->x_n; i++)
+ {
+ float yval, xpix, ypix;
+ int ixpix;
+
+ xpix = nextxpix;
+ xcum += x->x_xinc;
+ nextxpix = glist_xtopixels(glist, xcum);
+
+ yval = *(float *)(x->x_vec +
+ template->t_n * i * sizeof (t_word) + yonset);
+ if (yval > maxyval)
+ maxyval = yval;
+ if (yval < minyval)
+ minyval = yval;
+ ixpix = xpix + 0.5;
+ if (lastpixel == -0x7fffffff)
+ lastpixel = ixpix;
+ if (i == x->x_n-1 || (int)(0.5+nextxpix) != ixpix)
+ {
+ sys_vgui(
+".x%lx.c create rectangle %d %d %d %d -fill black -width 0 -tags .x%lx.a%lx\n",
+ glist_getcanvas(glist),
+ lastpixel, (int)glist_ytopixels(glist, minyval),
+ ixpix, (int)glist_ytopixels(glist, maxyval)+2,
+ glist_getcanvas(glist), x);
+ ndrawn++;
+ minyval = 1e20;
+ maxyval = -1e20;
+ lastpixel = ixpix;
+ }
+ if (ndrawn > 2000 || ixpix >= 3000) break;
+ }
+ }
+ else /* draw as a polygon */
+ {
+ float xcum = x->x_firstx;
+ int lastpixel = -1, ndrawn = 0;
+ float yval = 0, xpix;
+ int ixpix = 0;
+ sys_vgui(".x%lx.c create line \\\n", glist_getcanvas(glist));
+ for (i = 0; i < x->x_n; i++)
+ {
+ yval = *(float *)(x->x_vec +
+ template->t_n * i * sizeof (t_word) + yonset);
+ xpix = glist_xtopixels(glist, xcum);
+ ixpix = xpix + 0.5;
+ if (ixpix != lastpixel)
+ {
+ sys_vgui("%d %f \\\n", ixpix,
+ glist_ytopixels(glist, yval));
+ ndrawn++;
+ }
+ lastpixel = ixpix;
+ if (ndrawn >= 1000) break;
+ xcum += x->x_xinc;
+ }
+ /* TK will complain if there aren't at least 2 points... */
+ if (ndrawn == 0) sys_vgui("0 0 0 0 \\\n");
+ else if (ndrawn == 1) sys_vgui("%d %f \\\n", ixpix,
+ glist_ytopixels(glist, yval));
+ sys_vgui("-tags .x%lx.a%lx\n", glist_getcanvas(glist), x);
+ }
+ sys_vgui(".x%lx.c create text %f %f -text {%s} -anchor e\
+ -font -*-courier-bold--normal--%d-* -tags .x%lx.a%lx\n",
+ glist_getcanvas(glist),
+ glist_xtopixels(glist, x->x_firstx) - 5.,
+ glist_ytopixels(glist, *(float *)(x->x_vec + yonset)),
+ x->x_name->s_name, glist_getfont(glist),
+ glist_getcanvas(glist), x);
+ }
+ else
+ {
+ post("x, y arrays not yet supported");
+ }
}
else
{
- sys_vgui(".x%x.c delete .x%x.a%x\n",
- glist_getcanvas(glist), glist_getcanvas(glist), x);
+ sys_vgui(".x%lx.c delete .x%lx.a%lx\n",
+ glist_getcanvas(glist), glist_getcanvas(glist), x);
+ sys_unqueuegui(x);
}
}
@@ -692,7 +744,7 @@ static int garray_click(t_gobj *z, struct _glist *glist,
{
t_garray *x = (t_garray *)z;
return (array_doclick(&x->x_array, glist, z, x->x_templatesym, 1, 0, 1, 0,
- xpix, ypix, shift, alt, dbl, doit));
+ xpix, ypix, shift, alt, dbl, doit));
}
#define ARRAYWRITECHUNKSIZE 1000
@@ -701,28 +753,29 @@ static void garray_save(t_gobj *z, t_binbuf *b)
{
t_garray *x = (t_garray *)z;
binbuf_addv(b, "sssisi;", gensym("#X"), gensym("array"),
- x->x_name, x->x_n, x->x_templatesym, x->x_saveit);
+ x->x_name, x->x_n, x->x_templatesym,
+ x->x_saveit + 2 * x->x_drawasrects);
if (x->x_saveit)
{
- int n = x->x_n, n2 = 0;
- if (x->x_templatesym != &s_float)
- {
- pd_error(x, "sorry, you can only save 'float' arrays now");
- return;
- }
- if (n > 200000)
- post("warning: I'm saving an array with %d points!\n", n);
- while (n2 < n)
- {
- int chunk = n - n2, i;
- if (chunk > ARRAYWRITECHUNKSIZE)
- chunk = ARRAYWRITECHUNKSIZE;
- binbuf_addv(b, "si", gensym("#A"), n2);
- for (i = 0; i < chunk; i++)
- binbuf_addv(b, "f", ((float *)(x->x_vec))[n2+i]);
- binbuf_addv(b, ";");
- n2 += chunk;
- }
+ int n = x->x_n, n2 = 0;
+ if (x->x_templatesym != &s_float)
+ {
+ pd_error(x, "sorry, you can only save 'float' arrays now");
+ return;
+ }
+ if (n > 200000)
+ post("warning: I'm saving an array with %d points!\n", n);
+ while (n2 < n)
+ {
+ int chunk = n - n2, i;
+ if (chunk > ARRAYWRITECHUNKSIZE)
+ chunk = ARRAYWRITECHUNKSIZE;
+ binbuf_addv(b, "si", gensym("#A"), n2);
+ for (i = 0; i < chunk; i++)
+ binbuf_addv(b, "f", ((float *)(x->x_vec))[n2+i]);
+ binbuf_addv(b, ";");
+ n2 += chunk;
+ }
}
}
@@ -744,15 +797,22 @@ void garray_usedindsp(t_garray *x)
x->x_usedindsp = 1;
}
-void garray_redraw(t_garray *x)
+static void garray_doredraw(t_gobj *client, t_glist *glist)
{
+ t_garray *x = (t_garray *)client;
if (glist_isvisible(x->x_glist))
{
- garray_vis(&x->x_gobj, x->x_glist, 0);
- garray_vis(&x->x_gobj, x->x_glist, 1);
+ garray_vis(&x->x_gobj, x->x_glist, 0);
+ garray_vis(&x->x_gobj, x->x_glist, 1);
}
}
+void garray_redraw(t_garray *x)
+{
+ if (glist_isvisible(x->x_glist))
+ sys_queuegui(&x->x_gobj, x->x_glist, garray_doredraw);
+}
+
/* This functiopn gets the template of an array; if we can't figure
out what template an array's elements belong to we're in grave trouble
when it's time to free or resize it. */
@@ -760,11 +820,11 @@ t_template *garray_template(t_garray *x)
{
t_template *template = template_findbyname(x->x_templatesym);
if (!template)
- bug("garray_template");
+ bug("garray_template");
return (template);
}
-int garray_npoints(t_garray *x) /* get the length */
+int garray_npoints(t_garray *x) /* get the length */
{
return (x->x_n);
}
@@ -783,16 +843,16 @@ int garray_getfloatarray(t_garray *x, int *size, t_float **vec)
int yonset, type;
t_symbol *arraytype;
if (!template_find_field(template, gensym("y"), &yonset,
- &type, &arraytype) || type != DT_FLOAT)
- error("%s: needs floating-point 'y' field",
- x->x_templatesym->s_name);
+ &type, &arraytype) || type != DT_FLOAT)
+ error("%s: needs floating-point 'y' field",
+ x->x_templatesym->s_name);
else if (template->t_n != 1)
- error("%s: has more than one field", x->x_templatesym->s_name);
+ error("%s: has more than one field", x->x_templatesym->s_name);
else
{
- *size = garray_npoints(x);
- *vec = (float *)garray_vec(x);
- return (1);
+ *size = garray_npoints(x);
+ *vec = (float *)garray_vec(x);
+ return (1);
}
return (0);
}
@@ -804,11 +864,11 @@ float garray_get(t_garray *x, t_symbol *s, t_int indx)
int yonset, type;
t_symbol *arraytype;
if (!template_find_field(template, gensym("y"), &yonset,
- &type, &arraytype) || type != DT_FLOAT)
+ &type, &arraytype) || type != DT_FLOAT)
{
- error("%s: needs floating-point '%s' field", x->x_templatesym->s_name,
- s->s_name);
- return (0);
+ error("%s: needs floating-point '%s' field", x->x_templatesym->s_name,
+ s->s_name);
+ return (0);
}
if (indx < 0) indx = 0;
else if (indx >= x->x_n) indx = x->x_n - 1;
@@ -819,8 +879,8 @@ float garray_get(t_garray *x, t_symbol *s, t_int indx)
void garray_setsaveit(t_garray *x, int saveit)
{
if (x->x_saveit && !saveit)
- post("warning: array %s: clearing save-in-patch flag",
- x->x_name->s_name);
+ post("warning: array %s: clearing save-in-patch flag",
+ x->x_name->s_name);
x->x_saveit = saveit;
}
@@ -831,11 +891,11 @@ static void garray_const(t_garray *x, t_floatarg g)
int yonset, type, i;
t_symbol *arraytype;
if (!template_find_field(template, gensym("y"), &yonset,
- &type, &arraytype) || type != DT_FLOAT)
- error("%s: needs floating-point 'y' field",
- x->x_templatesym->s_name);
+ &type, &arraytype) || type != DT_FLOAT)
+ error("%s: needs floating-point 'y' field",
+ x->x_templatesym->s_name);
else for (i = 0; i < x->x_n; i++)
- *(float *)(((char *)x->x_vec + sizeof(t_word) * i) + yonset) = g;
+ *(float *)(((char *)x->x_vec + sizeof(t_word) * i) + yonset) = g;
garray_redraw(x);
}
@@ -848,28 +908,28 @@ static void garray_dofo(t_garray *x, int npoints, float dcval,
t_symbol *arraytype;
double phase, phaseincr, fj;
if (npoints == 0)
- npoints = 512; /* dunno what a good default would be... */
+ npoints = 512; /* dunno what a good default would be... */
if (npoints != (1 << ilog2(npoints)))
- post("%s: rounnding to %d points", x->x_templatesym->s_name,
- (npoints = (1<<ilog2(npoints))));
+ post("%s: rounnding to %d points", x->x_templatesym->s_name,
+ (npoints = (1<<ilog2(npoints))));
garray_resize(x, npoints + 3);
phaseincr = 2. * 3.14159 / npoints;
if (!template_find_field(template, gensym("y"), &yonset,
- &type, &arraytype) || type != DT_FLOAT)
+ &type, &arraytype) || type != DT_FLOAT)
{
- error("%s: needs floating-point 'y' field", x->x_templatesym->s_name);
- return;
+ error("%s: needs floating-point 'y' field", x->x_templatesym->s_name);
+ return;
}
for (i = 0, phase = -phaseincr; i < x->x_n; i++, phase += phaseincr )
{
- double sum = dcval;
- if (sineflag)
- for (j = 0, fj = phase; j < nsin; j++, fj += phase)
- sum += vsin[j] * sin(fj);
- else
- for (j = 0, fj = 0; j < nsin; j++, fj += phase)
- sum += vsin[j] * cos(fj);
- *(float *)((x->x_vec + sizeof(t_word) * i) + yonset) = sum;
+ double sum = dcval;
+ if (sineflag)
+ for (j = 0, fj = phase; j < nsin; j++, fj += phase)
+ sum += vsin[j] * sin(fj);
+ else
+ for (j = 0, fj = 0; j < nsin; j++, fj += phase)
+ sum += vsin[j] * cos(fj);
+ *(float *)((x->x_vec + sizeof(t_word) * i) + yonset) = sum;
}
garray_redraw(x);
}
@@ -882,9 +942,9 @@ static void garray_sinesum(t_garray *x, t_symbol *s, int argc, t_atom *argv)
int npoints, i;
if (argc < 2)
{
- error("sinesum: %s: need number of points and partial strengths",
- x->x_templatesym->s_name);
- return;
+ error("sinesum: %s: need number of points and partial strengths",
+ x->x_templatesym->s_name);
+ return;
}
npoints = atom_getfloatarg(0, argc, argv);
@@ -894,7 +954,7 @@ static void garray_sinesum(t_garray *x, t_symbol *s, int argc, t_atom *argv)
if (!svec) return;
for (i = 0; i < argc; i++)
- svec[i] = atom_getfloatarg(i, argc, argv);
+ svec[i] = atom_getfloatarg(i, argc, argv);
garray_dofo(x, npoints, 0, argc, svec, 1);
t_freebytes(svec, sizeof(t_float) * argc);
}
@@ -907,9 +967,9 @@ static void garray_cosinesum(t_garray *x, t_symbol *s, int argc, t_atom *argv)
int npoints, i;
if (argc < 2)
{
- error("sinesum: %s: need number of points and partial strengths",
- x->x_templatesym->s_name);
- return;
+ error("sinesum: %s: need number of points and partial strengths",
+ x->x_templatesym->s_name);
+ return;
}
npoints = atom_getfloatarg(0, argc, argv);
@@ -919,7 +979,7 @@ static void garray_cosinesum(t_garray *x, t_symbol *s, int argc, t_atom *argv)
if (!svec) return;
for (i = 0; i < argc; i++)
- svec[i] = atom_getfloatarg(i, argc, argv);
+ svec[i] = atom_getfloatarg(i, argc, argv);
garray_dofo(x, npoints, 0, argc, svec, 0);
t_freebytes(svec, sizeof(t_float) * argc);
}
@@ -932,30 +992,30 @@ static void garray_normalize(t_garray *x, t_float f)
t_symbol *arraytype;
if (f <= 0)
- f = 1;
+ f = 1;
if (!template_find_field(template, gensym("y"), &yonset,
- &type, &arraytype) || type != DT_FLOAT)
+ &type, &arraytype) || type != DT_FLOAT)
{
- error("%s: needs floating-point 'y' field", x->x_templatesym->s_name);
- return;
+ error("%s: needs floating-point 'y' field", x->x_templatesym->s_name);
+ return;
}
for (i = 0, maxv = 0; i < x->x_n; i++)
{
- double v = *(float *)((x->x_vec + sizeof(t_word) * i) + yonset);
- if (v > maxv)
- maxv = v;
- if (-v > maxv)
- maxv = -v;
+ double v = *(float *)((x->x_vec + sizeof(t_word) * i) + yonset);
+ if (v > maxv)
+ maxv = v;
+ if (-v > maxv)
+ maxv = -v;
}
- if (maxv >= 0)
+ if (maxv > 0)
{
- renormer = f / maxv;
- for (i = 0; i < x->x_n; i++)
- {
- *(float *)((x->x_vec + sizeof(t_word) * i) + yonset)
- *= renormer;
- }
+ renormer = f / maxv;
+ for (i = 0; i < x->x_n; i++)
+ {
+ *(float *)((x->x_vec + sizeof(t_word) * i) + yonset)
+ *= renormer;
+ }
}
garray_redraw(x);
}
@@ -968,31 +1028,31 @@ static void garray_list(t_garray *x, t_symbol *s, int argc, t_atom *argv)
int yonset, type, i;
t_symbol *arraytype;
if (!template_find_field(template, gensym("y"), &yonset,
- &type, &arraytype) || type != DT_FLOAT)
- error("%s: needs floating-point 'y' field",
- x->x_templatesym->s_name);
+ &type, &arraytype) || type != DT_FLOAT)
+ error("%s: needs floating-point 'y' field",
+ x->x_templatesym->s_name);
else if (argc < 2) return;
else
{
- int firstindex = atom_getfloat(argv);
- argc--;
- argv++;
- /* drop negative x values */
- if (firstindex < 0)
- {
- argc += firstindex;
- argv -= firstindex;
- firstindex = 0;
- if (argc <= 0) return;
- }
- if (argc + firstindex > x->x_n)
- {
- argc = x->x_n - firstindex;
- if (argc <= 0) return;
- }
- for (i = 0; i < argc; i++)
- *(float *)((x->x_vec + sizeof(t_word) * (i + firstindex)) + yonset) =
- atom_getfloat(argv + i);
+ int firstindex = atom_getfloat(argv);
+ argc--;
+ argv++;
+ /* drop negative x values */
+ if (firstindex < 0)
+ {
+ argc += firstindex;
+ argv -= firstindex;
+ firstindex = 0;
+ if (argc <= 0) return;
+ }
+ if (argc + firstindex > x->x_n)
+ {
+ argc = x->x_n - firstindex;
+ if (argc <= 0) return;
+ }
+ for (i = 0; i < argc; i++)
+ *(float *)((x->x_vec + sizeof(t_word) * (i + firstindex)) + yonset) =
+ atom_getfloat(argv + i);
}
garray_redraw(x);
}
@@ -1043,31 +1103,31 @@ static void garray_read(t_garray *x, t_symbol *filename)
int yonset, type, i;
t_symbol *arraytype;
if (!template_find_field(template, gensym("y"), &yonset,
- &type, &arraytype) || type != DT_FLOAT)
+ &type, &arraytype) || type != DT_FLOAT)
{
- error("%s: needs floating-point 'y' field", x->x_templatesym->s_name);
- return;
+ error("%s: needs floating-point 'y' field", x->x_templatesym->s_name);
+ return;
}
if ((filedesc = open_via_path(
- canvas_getdir(glist_getcanvas(x->x_glist))->s_name,
- filename->s_name, "", buf, &bufptr, MAXPDSTRING, 0)) < 0
- || !(fd = fdopen(filedesc, "r")))
+ canvas_getdir(glist_getcanvas(x->x_glist))->s_name,
+ filename->s_name, "", buf, &bufptr, MAXPDSTRING, 0)) < 0
+ || !(fd = fdopen(filedesc, "r")))
{
- error("%s: can't open", filename->s_name);
- return;
+ error("%s: can't open", filename->s_name);
+ return;
}
for (i = 0; i < nelem; i++)
{
- if (!fscanf(fd, "%f", (float *)((x->x_vec + sizeof(t_word) * i) +
- yonset)))
- {
- post("%s: read %d elements into table of size %d",
- filename->s_name, i, nelem);
- break;
- }
+ if (!fscanf(fd, "%f", (float *)((x->x_vec + sizeof(t_word) * i) +
+ yonset)))
+ {
+ post("%s: read %d elements into table of size %d",
+ filename->s_name, i, nelem);
+ break;
+ }
}
while (i < nelem)
- *(float *)((x->x_vec + sizeof(t_word) * i) + yonset) = 0, i++;
+ *(float *)((x->x_vec + sizeof(t_word) * i) + yonset) = 0, i++;
fclose(fd);
garray_redraw(x);
}
@@ -1096,51 +1156,51 @@ static void garray_read16(t_garray *x, t_symbol *filename,
char c = endian->s_name[0];
if (c == 'b')
{
- if (!cpubig) swap = 1;
+ if (!cpubig) swap = 1;
}
else if (c == 'l')
{
- if (cpubig) swap = 1;
+ if (cpubig) swap = 1;
}
else if (c)
{
- error("array_read16: endianness is 'l' (low byte first ala INTEL)");
- post("... or 'b' (high byte first ala MIPS,DEC,PPC)");
+ error("array_read16: endianness is 'l' (low byte first ala INTEL)");
+ post("... or 'b' (high byte first ala MIPS,DEC,PPC)");
}
if (!garray_getfloatarray(x, &nelem, &vec))
{
- error("%s: not a float array", x->x_templatesym->s_name);
- return;
+ error("%s: not a float array", x->x_templatesym->s_name);
+ return;
}
if ((filedesc = open_via_path(
- canvas_getdir(glist_getcanvas(x->x_glist))->s_name,
- filename->s_name, "", buf, &bufptr, MAXPDSTRING, 1)) < 0
- || !(fd = fdopen(filedesc, BINREADMODE)))
+ canvas_getdir(glist_getcanvas(x->x_glist))->s_name,
+ filename->s_name, "", buf, &bufptr, MAXPDSTRING, 1)) < 0
+ || !(fd = fdopen(filedesc, BINREADMODE)))
{
- error("%s: can't open", filename->s_name);
- return;
+ error("%s: can't open", filename->s_name);
+ return;
}
if (skip)
{
- long pos = fseek(fd, (long)skip, SEEK_SET);
- if (pos < 0)
- {
- error("%s: can't seek to byte %d", buf, skip);
- fclose(fd);
- return;
- }
+ long pos = fseek(fd, (long)skip, SEEK_SET);
+ if (pos < 0)
+ {
+ error("%s: can't seek to byte %d", buf, skip);
+ fclose(fd);
+ return;
+ }
}
for (i = 0; i < nelem; i++)
{
- if (fread(&s, sizeof(s), 1, fd) < 1)
- {
- post("%s: read %d elements into table of size %d",
- filename->s_name, i, nelem);
- break;
- }
- if (swap) s = ((s & 0xff) << 8) | ((s & 0xff00) >> 8);
- vec[i] = s * (1./32768.);
+ if (fread(&s, sizeof(s), 1, fd) < 1)
+ {
+ post("%s: read %d elements into table of size %d",
+ filename->s_name, i, nelem);
+ break;
+ }
+ if (swap) s = ((s & 0xff) << 8) | ((s & 0xff00) >> 8);
+ vec[i] = s * (1./32768.);
}
while (i < nelem) vec[i++] = 0;
fclose(fd);
@@ -1155,27 +1215,27 @@ static void garray_write(t_garray *x, t_symbol *filename)
int yonset, type, i;
t_symbol *arraytype;
if (!template_find_field(template, gensym("y"), &yonset,
- &type, &arraytype) || type != DT_FLOAT)
+ &type, &arraytype) || type != DT_FLOAT)
{
- error("%s: needs floating-point 'y' field", x->x_templatesym->s_name);
- return;
+ error("%s: needs floating-point 'y' field", x->x_templatesym->s_name);
+ return;
}
canvas_makefilename(glist_getcanvas(x->x_glist), filename->s_name,
- buf, MAXPDSTRING);
+ buf, MAXPDSTRING);
sys_bashfilename(buf, buf);
if (!(fd = fopen(buf, "w")))
{
- error("%s: can't create", buf);
- return;
+ error("%s: can't create", buf);
+ return;
}
for (i = 0; i < x->x_n; i++)
{
- if (fprintf(fd, "%g\n",
- *(float *)((x->x_vec + sizeof(t_word) * i) + yonset)) < 1)
- {
- post("%s: write error", filename->s_name);
- break;
- }
+ if (fprintf(fd, "%g\n",
+ *(float *)((x->x_vec + sizeof(t_word) * i) + yonset)) < 1)
+ {
+ post("%s: write error", filename->s_name);
+ break;
+ }
}
fclose(fd);
}
@@ -1205,73 +1265,73 @@ static void garray_write16(t_garray *x, t_symbol *filename, t_symbol *format)
FILE *fd;
int aiff = (format == gensym("aiff"));
char filenamebuf[MAXPDSTRING], buf2[MAXPDSTRING];
- int swap = garray_ambigendian(); /* wave is only little endian */
+ int swap = garray_ambigendian(); /* wave is only little endian */
int intbuf;
strncpy(filenamebuf, filename->s_name, MAXPDSTRING-10);
filenamebuf[MAXPDSTRING-10] = 0;
if (sizeof(int) != 4) post("write16: only works on 32-bit machines");
if (aiff)
{
- if (strcmp(filenamebuf + strlen(filenamebuf)-5, ".aiff"))
- strcat(filenamebuf, ".aiff");
+ if (strcmp(filenamebuf + strlen(filenamebuf)-5, ".aiff"))
+ strcat(filenamebuf, ".aiff");
}
else
{
- if (strcmp(filenamebuf + strlen(filenamebuf)-4, ".wav"))
- strcat(filenamebuf, ".wav");
+ if (strcmp(filenamebuf + strlen(filenamebuf)-4, ".wav"))
+ strcat(filenamebuf, ".wav");
}
if (!template_find_field(template, gensym("y"), &yonset,
- &type, &arraytype) || type != DT_FLOAT)
+ &type, &arraytype) || type != DT_FLOAT)
{
- error("%s: needs floating-point 'y' field", x->x_templatesym->s_name);
- return;
+ error("%s: needs floating-point 'y' field", x->x_templatesym->s_name);
+ return;
}
canvas_makefilename(glist_getcanvas(x->x_glist), filenamebuf,
- buf2, MAXPDSTRING);
+ buf2, MAXPDSTRING);
sys_bashfilename(buf2, buf2);
if (!(fd = fopen(buf2, BINWRITEMODE)))
{
- error("%s: can't create", buf2);
- return;
+ error("%s: can't create", buf2);
+ return;
}
intbuf = 2 * x->x_n + 36;
if (swap)
{
- unsigned char *foo = (unsigned char *)&intbuf, xxx;
- xxx = foo[0]; foo[0] = foo[3]; foo[3] = xxx;
- xxx = foo[1]; foo[1] = foo[2]; foo[2] = xxx;
+ unsigned char *foo = (unsigned char *)&intbuf, xxx;
+ xxx = foo[0]; foo[0] = foo[3]; foo[3] = xxx;
+ xxx = foo[1]; foo[1] = foo[2]; foo[2] = xxx;
}
memcpy((void *)(waveheader + 4), (void *)(&intbuf), 4);
intbuf = 2 * x->x_n;
if (swap)
{
- unsigned char *foo = (unsigned char *)&intbuf, xxx;
- xxx = foo[0]; foo[0] = foo[3]; foo[3] = xxx;
- xxx = foo[1]; foo[1] = foo[2]; foo[2] = xxx;
+ unsigned char *foo = (unsigned char *)&intbuf, xxx;
+ xxx = foo[0]; foo[0] = foo[3]; foo[3] = xxx;
+ xxx = foo[1]; foo[1] = foo[2]; foo[2] = xxx;
}
memcpy((void *)(waveheader + 40), (void *)(&intbuf), 4);
if (fwrite(waveheader, sizeof(waveheader), 1, fd) < 1)
{
- post("%s: write error", buf2);
- goto closeit;
+ post("%s: write error", buf2);
+ goto closeit;
}
for (i = 0; i < x->x_n; i++)
{
- float f = 32767. * *(float *)((x->x_vec + sizeof(t_word) * i) + yonset);
- short sh;
- if (f < -32768) f = -32768;
- else if (f > 32767) f = 32767;
- sh = f;
- if (swap)
- {
- unsigned char *foo = (unsigned char *)&sh, xxx;
- xxx = foo[0]; foo[0] = foo[1]; foo[1] = xxx;
- }
- if (fwrite(&sh, sizeof(sh), 1, fd) < 1)
- {
- post("%s: write error", buf2);
- goto closeit;
- }
+ float f = 32767. * *(float *)((x->x_vec + sizeof(t_word) * i) + yonset);
+ short sh;
+ if (f < -32768) f = -32768;
+ else if (f > 32767) f = 32767;
+ sh = f;
+ if (swap)
+ {
+ unsigned char *foo = (unsigned char *)&sh, xxx;
+ xxx = foo[0]; foo[0] = foo[1]; foo[1] = xxx;
+ }
+ if (fwrite(&sh, sizeof(sh), 1, fd) < 1)
+ {
+ post("%s: write error", buf2);
+ goto closeit;
+ }
}
closeit:
fclose(fd);
@@ -1290,25 +1350,25 @@ void garray_resize(t_garray *x, t_floatarg f)
nvec = t_resizebytes(x->x_vec, was * elemsize, n * elemsize);
if (!nvec)
{
- pd_error(x, "array resize failed: out of memory");
- return;
+ pd_error(x, "array resize failed: out of memory");
+ return;
}
x->x_vec = nvec;
- /* LATER should check t_resizebytes result */
+ /* LATER should check t_resizebytes result */
if (n > was)
- memset(x->x_vec + was*elemsize,
- 0, (n - was) * elemsize);
+ memset(x->x_vec + was*elemsize,
+ 0, (n - was) * elemsize);
x->x_n = n;
- /* if this is the only array in the graph,
- reset the graph's coordinates */
+ /* if this is the only array in the graph,
+ reset the graph's coordinates */
gl = x->x_glist;
if (gl->gl_list == &x->x_gobj && !x->x_gobj.g_next)
{
- vmess(&gl->gl_pd, gensym("bounds"), "ffff",
- 0., gl->gl_y1, (double)(n > 1 ? n-1 : 1), gl->gl_y2);
- /* close any dialogs that might have the wrong info now... */
- gfxstub_deleteforkey(gl);
+ vmess(&gl->gl_pd, gensym("bounds"), "ffff",
+ 0., gl->gl_y1, (double)(n > 1 ? n-1 : 1), gl->gl_y2);
+ /* close any dialogs that might have the wrong info now... */
+ gfxstub_deleteforkey(gl);
}
else garray_redraw(x);
if (x->x_usedindsp) canvas_update_dsp();
@@ -1317,49 +1377,49 @@ void garray_resize(t_garray *x, t_floatarg f)
static void garray_print(t_garray *x)
{
post("garray %s: template %s, length %d",
- x->x_name->s_name, x->x_templatesym->s_name, x->x_n);
+ x->x_name->s_name, x->x_templatesym->s_name, x->x_n);
}
void g_array_setup(void)
{
garray_class = class_new(gensym("array"), 0, (t_method)garray_free,
- sizeof(t_garray), CLASS_GOBJ, 0);
+ sizeof(t_garray), CLASS_GOBJ, 0);
class_setwidget(garray_class, &garray_widgetbehavior);
class_addmethod(garray_class, (t_method)garray_const, gensym("const"),
- A_DEFFLOAT, A_NULL);
+ A_DEFFLOAT, A_NULL);
class_addlist(garray_class, garray_list);
class_addmethod(garray_class, (t_method)garray_bounds, gensym("bounds"),
- A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, A_NULL);
+ A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, A_NULL);
class_addmethod(garray_class, (t_method)garray_xticks, gensym("xticks"),
- A_FLOAT, A_FLOAT, A_FLOAT, 0);
+ A_FLOAT, A_FLOAT, A_FLOAT, 0);
class_addmethod(garray_class, (t_method)garray_xlabel, gensym("xlabel"),
- A_GIMME, 0);
+ A_GIMME, 0);
class_addmethod(garray_class, (t_method)garray_yticks, gensym("yticks"),
- A_FLOAT, A_FLOAT, A_FLOAT, 0);
+ A_FLOAT, A_FLOAT, A_FLOAT, 0);
class_addmethod(garray_class, (t_method)garray_ylabel, gensym("ylabel"),
- A_GIMME, 0);
+ A_GIMME, 0);
class_addmethod(garray_class, (t_method)garray_rename, gensym("rename"),
- A_SYMBOL, 0);
+ A_SYMBOL, 0);
class_addmethod(garray_class, (t_method)garray_read, gensym("read"),
- A_SYMBOL, A_NULL);
+ A_SYMBOL, A_NULL);
class_addmethod(garray_class, (t_method)garray_read16, gensym("read16"),
- A_SYMBOL, A_DEFFLOAT, A_DEFSYM, A_NULL);
+ A_SYMBOL, A_DEFFLOAT, A_DEFSYM, A_NULL);
class_addmethod(garray_class, (t_method)garray_write, gensym("write"),
- A_SYMBOL, A_NULL);
+ A_SYMBOL, A_NULL);
class_addmethod(garray_class, (t_method)garray_write16, gensym("write16"),
- A_SYMBOL, A_DEFSYM, A_NULL);
+ A_SYMBOL, A_DEFSYM, A_NULL);
class_addmethod(garray_class, (t_method)garray_resize, gensym("resize"),
- A_FLOAT, A_NULL);
+ A_FLOAT, A_NULL);
class_addmethod(garray_class, (t_method)garray_print, gensym("print"),
- A_NULL);
+ A_NULL);
class_addmethod(garray_class, (t_method)garray_sinesum, gensym("sinesum"),
- A_GIMME, 0);
+ A_GIMME, 0);
class_addmethod(garray_class, (t_method)garray_cosinesum,
- gensym("cosinesum"), A_GIMME, 0);
+ gensym("cosinesum"), A_GIMME, 0);
class_addmethod(garray_class, (t_method)garray_normalize,
- gensym("normalize"), A_DEFFLOAT, 0);
+ gensym("normalize"), A_DEFFLOAT, 0);
class_addmethod(garray_class, (t_method)garray_arraydialog,
- gensym("arraydialog"), A_SYMBOL, A_FLOAT, A_FLOAT, A_FLOAT, A_NULL);
+ gensym("arraydialog"), A_SYMBOL, A_FLOAT, A_FLOAT, A_FLOAT, A_NULL);
class_setsavefn(garray_class, garray_save);
}
diff --git a/pd/src/g_bang.c b/pd/src/g_bang.c
index 6e4ee5ff..7c0cc091 100644
--- a/pd/src/g_bang.c
+++ b/pd/src/g_bang.c
@@ -35,8 +35,8 @@ void bng_draw_update(t_bng *x, t_glist *glist)
{
if(glist_isvisible(glist))
{
- sys_vgui(".x%x.c itemconfigure %xBUT -fill #%6.6x\n", glist_getcanvas(glist), x,
- x->x_flashed?x->x_gui.x_fcol:x->x_gui.x_bcol);
+ sys_vgui(".x%lx.c itemconfigure %lxBUT -fill #%6.6x\n", glist_getcanvas(glist), x,
+ x->x_flashed?x->x_gui.x_fcol:x->x_gui.x_bcol);
}
}
@@ -46,29 +46,29 @@ void bng_draw_new(t_bng *x, t_glist *glist)
int ypos=text_ypix(&x->x_gui.x_obj, glist);
t_canvas *canvas=glist_getcanvas(glist);
- sys_vgui(".x%x.c create rectangle %d %d %d %d -fill #%6.6x -tags %xBASE\n",
- canvas, xpos, ypos,
- xpos + x->x_gui.x_w, ypos + x->x_gui.x_h,
- x->x_gui.x_bcol, x);
- sys_vgui(".x%x.c create oval %d %d %d %d -fill #%6.6x -tags %xBUT\n",
- canvas, xpos+1, ypos+1,
- xpos + x->x_gui.x_w-1, ypos + x->x_gui.x_h-1,
- x->x_flashed?x->x_gui.x_fcol:x->x_gui.x_bcol, x);
- sys_vgui(".x%x.c create text %d %d -text {%s} -anchor w \
- -font {%s %d bold} -fill #%6.6x -tags %xLABEL\n",
- canvas, xpos+x->x_gui.x_ldx,
- ypos+x->x_gui.x_ldy,
- strcmp(x->x_gui.x_lab->s_name, "empty")?x->x_gui.x_lab->s_name:"",
- x->x_gui.x_font, x->x_gui.x_fontsize, x->x_gui.x_lcol, x);
+ sys_vgui(".x%lx.c create rectangle %d %d %d %d -fill #%6.6x -tags %lxBASE\n",
+ canvas, xpos, ypos,
+ xpos + x->x_gui.x_w, ypos + x->x_gui.x_h,
+ x->x_gui.x_bcol, x);
+ sys_vgui(".x%lx.c create oval %d %d %d %d -fill #%6.6x -tags %lxBUT\n",
+ canvas, xpos+1, ypos+1,
+ xpos + x->x_gui.x_w-1, ypos + x->x_gui.x_h-1,
+ x->x_flashed?x->x_gui.x_fcol:x->x_gui.x_bcol, x);
+ sys_vgui(".x%lx.c create text %d %d -text {%s} -anchor w \
+ -font {%s %d bold} -fill #%6.6x -tags %lxLABEL\n",
+ canvas, xpos+x->x_gui.x_ldx,
+ ypos+x->x_gui.x_ldy,
+ strcmp(x->x_gui.x_lab->s_name, "empty")?x->x_gui.x_lab->s_name:"",
+ x->x_gui.x_font, x->x_gui.x_fontsize, x->x_gui.x_lcol, x);
if(!x->x_gui.x_fsf.x_snd_able)
- sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xOUT%d\n",
- canvas, xpos,
- ypos + x->x_gui.x_h-1, xpos + IOWIDTH,
- ypos + x->x_gui.x_h, x, 0);
+ sys_vgui(".x%lx.c create rectangle %d %d %d %d -tags %lxOUT%d\n",
+ canvas, xpos,
+ ypos + x->x_gui.x_h-1, xpos + IOWIDTH,
+ ypos + x->x_gui.x_h, x, 0);
if(!x->x_gui.x_fsf.x_rcv_able)
- sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xIN%d\n",
- canvas, xpos, ypos,
- xpos + IOWIDTH, ypos+1, x, 0);
+ sys_vgui(".x%lx.c create rectangle %d %d %d %d -tags %lxIN%d\n",
+ canvas, xpos, ypos,
+ xpos + IOWIDTH, ypos+1, x, 0);
}
void bng_draw_move(t_bng *x, t_glist *glist)
@@ -77,51 +77,51 @@ void bng_draw_move(t_bng *x, t_glist *glist)
int ypos=text_ypix(&x->x_gui.x_obj, glist);
t_canvas *canvas=glist_getcanvas(glist);
- sys_vgui(".x%x.c coords %xBASE %d %d %d %d\n",
- canvas, x, xpos, ypos,
- xpos + x->x_gui.x_w, ypos + x->x_gui.x_h);
- sys_vgui(".x%x.c coords %xBUT %d %d %d %d\n",
- canvas, x, xpos+1,ypos+1,
- xpos + x->x_gui.x_w-1, ypos + x->x_gui.x_h-1);
- sys_vgui(".x%x.c itemconfigure %xBUT -fill #%6.6x\n", canvas, x,
- x->x_flashed?x->x_gui.x_fcol:x->x_gui.x_bcol);
- sys_vgui(".x%x.c coords %xLABEL %d %d\n",
- canvas, x, xpos+x->x_gui.x_ldx, ypos+x->x_gui.x_ldy);
+ sys_vgui(".x%lx.c coords %lxBASE %d %d %d %d\n",
+ canvas, x, xpos, ypos,
+ xpos + x->x_gui.x_w, ypos + x->x_gui.x_h);
+ sys_vgui(".x%lx.c coords %lxBUT %d %d %d %d\n",
+ canvas, x, xpos+1,ypos+1,
+ xpos + x->x_gui.x_w-1, ypos + x->x_gui.x_h-1);
+ sys_vgui(".x%lx.c itemconfigure %lxBUT -fill #%6.6x\n", canvas, x,
+ x->x_flashed?x->x_gui.x_fcol:x->x_gui.x_bcol);
+ sys_vgui(".x%lx.c coords %lxLABEL %d %d\n",
+ canvas, x, xpos+x->x_gui.x_ldx, ypos+x->x_gui.x_ldy);
if(!x->x_gui.x_fsf.x_snd_able)
- sys_vgui(".x%x.c coords %xOUT%d %d %d %d %d\n",
- canvas, x, 0, xpos,
- ypos + x->x_gui.x_h-1, xpos + IOWIDTH,
- ypos + x->x_gui.x_h);
+ sys_vgui(".x%lx.c coords %lxOUT%d %d %d %d %d\n",
+ canvas, x, 0, xpos,
+ ypos + x->x_gui.x_h-1, xpos + IOWIDTH,
+ ypos + x->x_gui.x_h);
if(!x->x_gui.x_fsf.x_rcv_able)
- sys_vgui(".x%x.c coords %xIN%d %d %d %d %d\n",
- canvas, x, 0, xpos, ypos,
- xpos + IOWIDTH, ypos+1);
+ sys_vgui(".x%lx.c coords %lxIN%d %d %d %d %d\n",
+ canvas, x, 0, xpos, ypos,
+ xpos + IOWIDTH, ypos+1);
}
void bng_draw_erase(t_bng* x, t_glist* glist)
{
t_canvas *canvas=glist_getcanvas(glist);
- sys_vgui(".x%x.c delete %xBASE\n", canvas, x);
- sys_vgui(".x%x.c delete %xBUT\n", canvas, x);
- sys_vgui(".x%x.c delete %xLABEL\n", canvas, x);
+ sys_vgui(".x%lx.c delete %lxBASE\n", canvas, x);
+ sys_vgui(".x%lx.c delete %lxBUT\n", canvas, x);
+ sys_vgui(".x%lx.c delete %lxLABEL\n", canvas, x);
if(!x->x_gui.x_fsf.x_snd_able)
- sys_vgui(".x%x.c delete %xOUT%d\n", canvas, x, 0);
+ sys_vgui(".x%lx.c delete %lxOUT%d\n", canvas, x, 0);
if(!x->x_gui.x_fsf.x_rcv_able)
- sys_vgui(".x%x.c delete %xIN%d\n", canvas, x, 0);
+ sys_vgui(".x%lx.c delete %lxIN%d\n", canvas, x, 0);
}
void bng_draw_config(t_bng* x, t_glist* glist)
{
t_canvas *canvas=glist_getcanvas(glist);
- sys_vgui(".x%x.c itemconfigure %xLABEL -font {%s %d bold} -fill #%6.6x -text {%s} \n",
- canvas, x, x->x_gui.x_font, x->x_gui.x_fontsize,
- x->x_gui.x_fsf.x_selected?IEM_GUI_COLOR_SELECTED:x->x_gui.x_lcol,
- strcmp(x->x_gui.x_lab->s_name, "empty")?x->x_gui.x_lab->s_name:"");
- sys_vgui(".x%x.c itemconfigure %xBASE -fill #%6.6x\n", canvas, x, x->x_gui.x_bcol);
- sys_vgui(".x%x.c itemconfigure %xBUT -fill #%6.6x\n", canvas, x,
- x->x_flashed?x->x_gui.x_fcol:x->x_gui.x_bcol);
+ sys_vgui(".x%lx.c itemconfigure %lxLABEL -font {%s %d bold} -fill #%6.6x -text {%s} \n",
+ canvas, x, x->x_gui.x_font, x->x_gui.x_fontsize,
+ x->x_gui.x_fsf.x_selected?IEM_GUI_COLOR_SELECTED:x->x_gui.x_lcol,
+ strcmp(x->x_gui.x_lab->s_name, "empty")?x->x_gui.x_lab->s_name:"");
+ sys_vgui(".x%lx.c itemconfigure %lxBASE -fill #%6.6x\n", canvas, x, x->x_gui.x_bcol);
+ sys_vgui(".x%lx.c itemconfigure %lxBUT -fill #%6.6x\n", canvas, x,
+ x->x_flashed?x->x_gui.x_fcol:x->x_gui.x_bcol);
}
void bng_draw_io(t_bng* x, t_glist* glist, int old_snd_rcv_flags)
@@ -131,18 +131,18 @@ void bng_draw_io(t_bng* x, t_glist* glist, int old_snd_rcv_flags)
t_canvas *canvas=glist_getcanvas(glist);
if((old_snd_rcv_flags & IEM_GUI_OLD_SND_FLAG) && !x->x_gui.x_fsf.x_snd_able)
- sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xOUT%d\n",
- canvas, xpos,
- ypos + x->x_gui.x_h-1, xpos + IOWIDTH,
- ypos + x->x_gui.x_h, x, 0);
+ sys_vgui(".x%lx.c create rectangle %d %d %d %d -tags %lxOUT%d\n",
+ canvas, xpos,
+ ypos + x->x_gui.x_h-1, xpos + IOWIDTH,
+ ypos + x->x_gui.x_h, x, 0);
if(!(old_snd_rcv_flags & IEM_GUI_OLD_SND_FLAG) && x->x_gui.x_fsf.x_snd_able)
- sys_vgui(".x%x.c delete %xOUT%d\n", canvas, x, 0);
+ sys_vgui(".x%lx.c delete %lxOUT%d\n", canvas, x, 0);
if((old_snd_rcv_flags & IEM_GUI_OLD_RCV_FLAG) && !x->x_gui.x_fsf.x_rcv_able)
- sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xIN%d\n",
- canvas, xpos, ypos,
- xpos + IOWIDTH, ypos+1, x, 0);
+ sys_vgui(".x%lx.c create rectangle %d %d %d %d -tags %lxIN%d\n",
+ canvas, xpos, ypos,
+ xpos + IOWIDTH, ypos+1, x, 0);
if(!(old_snd_rcv_flags & IEM_GUI_OLD_RCV_FLAG) && x->x_gui.x_fsf.x_rcv_able)
- sys_vgui(".x%x.c delete %xIN%d\n", canvas, x, 0);
+ sys_vgui(".x%lx.c delete %lxIN%d\n", canvas, x, 0);
}
void bng_draw_select(t_bng* x, t_glist* glist)
@@ -151,34 +151,34 @@ void bng_draw_select(t_bng* x, t_glist* glist)
if(x->x_gui.x_fsf.x_selected)
{
- sys_vgui(".x%x.c itemconfigure %xBASE -outline #%6.6x\n", canvas, x, IEM_GUI_COLOR_SELECTED);
- sys_vgui(".x%x.c itemconfigure %xBUT -outline #%6.6x\n", canvas, x, IEM_GUI_COLOR_SELECTED);
- sys_vgui(".x%x.c itemconfigure %xLABEL -fill #%6.6x\n", canvas, x, IEM_GUI_COLOR_SELECTED);
+ sys_vgui(".x%lx.c itemconfigure %lxBASE -outline #%6.6x\n", canvas, x, IEM_GUI_COLOR_SELECTED);
+ sys_vgui(".x%lx.c itemconfigure %lxBUT -outline #%6.6x\n", canvas, x, IEM_GUI_COLOR_SELECTED);
+ sys_vgui(".x%lx.c itemconfigure %lxLABEL -fill #%6.6x\n", canvas, x, IEM_GUI_COLOR_SELECTED);
}
else
{
- sys_vgui(".x%x.c itemconfigure %xBASE -outline #%6.6x\n", canvas, x, IEM_GUI_COLOR_NORMAL);
- sys_vgui(".x%x.c itemconfigure %xBUT -outline #%6.6x\n", canvas, x, IEM_GUI_COLOR_NORMAL);
- sys_vgui(".x%x.c itemconfigure %xLABEL -fill #%6.6x\n", canvas, x, x->x_gui.x_lcol);
+ sys_vgui(".x%lx.c itemconfigure %lxBASE -outline #%6.6x\n", canvas, x, IEM_GUI_COLOR_NORMAL);
+ sys_vgui(".x%lx.c itemconfigure %lxBUT -outline #%6.6x\n", canvas, x, IEM_GUI_COLOR_NORMAL);
+ sys_vgui(".x%lx.c itemconfigure %lxLABEL -fill #%6.6x\n", canvas, x, x->x_gui.x_lcol);
}
}
void bng_draw(t_bng *x, t_glist *glist, int mode)
{
if(mode == IEM_GUI_DRAW_MODE_UPDATE)
- bng_draw_update(x, glist);
+ bng_draw_update(x, glist);
else if(mode == IEM_GUI_DRAW_MODE_MOVE)
- bng_draw_move(x, glist);
+ bng_draw_move(x, glist);
else if(mode == IEM_GUI_DRAW_MODE_NEW)
- bng_draw_new(x, glist);
+ bng_draw_new(x, glist);
else if(mode == IEM_GUI_DRAW_MODE_SELECT)
- bng_draw_select(x, glist);
+ bng_draw_select(x, glist);
else if(mode == IEM_GUI_DRAW_MODE_ERASE)
- bng_draw_erase(x, glist);
+ bng_draw_erase(x, glist);
else if(mode == IEM_GUI_DRAW_MODE_CONFIG)
- bng_draw_config(x, glist);
+ bng_draw_config(x, glist);
else if(mode >= IEM_GUI_DRAW_MODE_IO)
- bng_draw_io(x, glist, mode - IEM_GUI_DRAW_MODE_IO);
+ bng_draw_io(x, glist, mode - IEM_GUI_DRAW_MODE_IO);
}
/* ------------------------ bng widgetbehaviour----------------------------- */
@@ -201,14 +201,14 @@ static void bng_save(t_gobj *z, t_binbuf *b)
iemgui_save(&x->x_gui, srl, bflcol);
binbuf_addv(b, "ssiisiiiisssiiiiiii", gensym("#X"),gensym("obj"),
- (t_int)x->x_gui.x_obj.te_xpix, (t_int)x->x_gui.x_obj.te_ypix,
- gensym("bng"), x->x_gui.x_w,
- x->x_flashtime_hold, x->x_flashtime_break,
- iem_symargstoint(&x->x_gui.x_isa),
- srl[0], srl[1], srl[2],
- x->x_gui.x_ldx, x->x_gui.x_ldy,
- iem_fstyletoint(&x->x_gui.x_fsf), x->x_gui.x_fontsize,
- bflcol[0], bflcol[1], bflcol[2]);
+ (int)x->x_gui.x_obj.te_xpix, (int)x->x_gui.x_obj.te_ypix,
+ gensym("bng"), x->x_gui.x_w,
+ x->x_flashtime_hold, x->x_flashtime_break,
+ iem_symargstoint(&x->x_gui.x_isa),
+ srl[0], srl[1], srl[2],
+ x->x_gui.x_ldx, x->x_gui.x_ldy,
+ iem_fstyletoint(&x->x_gui.x_fsf), x->x_gui.x_fontsize,
+ bflcol[0], bflcol[1], bflcol[2]);
binbuf_addv(b, ";");
}
@@ -216,16 +216,16 @@ void bng_check_minmax(t_bng *x, int ftbreak, int fthold)
{
if(ftbreak > fthold)
{
- int h;
+ int h;
- h = ftbreak;
- ftbreak = fthold;
- fthold = h;
+ h = ftbreak;
+ ftbreak = fthold;
+ fthold = h;
}
if(ftbreak < IEM_BNG_MINBREAKFLASHTIME)
- ftbreak = IEM_BNG_MINBREAKFLASHTIME;
+ ftbreak = IEM_BNG_MINBREAKFLASHTIME;
if(fthold < IEM_BNG_MINHOLDFLASHTIME)
- fthold = IEM_BNG_MINHOLDFLASHTIME;
+ fthold = IEM_BNG_MINHOLDFLASHTIME;
x->x_flashtime_break = ftbreak;
x->x_flashtime_hold = fthold;
}
@@ -238,20 +238,20 @@ static void bng_properties(t_gobj *z, t_glist *owner)
iemgui_properties(&x->x_gui, srl);
sprintf(buf, "pdtk_iemgui_dialog %%s BANG \
- ----------dimensions(pix):----------- %d %d size: 0 0 empty \
- --------flash-time(ms)(ms):--------- %d intrrpt: %d hold: %d \
- %d empty empty %d %d empty %d \
- %s %s \
- %s %d %d \
- %d %d \
- %d %d %d\n",
- x->x_gui.x_w, IEM_GUI_MINSIZE,
- x->x_flashtime_break, x->x_flashtime_hold, 2,/*min_max_schedule+clip*/
- -1, x->x_gui.x_isa.x_loadinit, -1, -1,/*no linlog, no multi*/
- srl[0]->s_name, srl[1]->s_name,
- srl[2]->s_name, x->x_gui.x_ldx, x->x_gui.x_ldy,
- x->x_gui.x_fsf.x_font_style, x->x_gui.x_fontsize,
- 0xffffff & x->x_gui.x_bcol, 0xffffff & x->x_gui.x_fcol, 0xffffff & x->x_gui.x_lcol);
+ ----------dimensions(pix):----------- %d %d size: 0 0 empty \
+ --------flash-time(ms)(ms):--------- %d intrrpt: %d hold: %d \
+ %d empty empty %d %d empty %d \
+ %s %s \
+ %s %d %d \
+ %d %d \
+ %d %d %d\n",
+ x->x_gui.x_w, IEM_GUI_MINSIZE,
+ x->x_flashtime_break, x->x_flashtime_hold, 2,/*min_max_schedule+clip*/
+ -1, x->x_gui.x_isa.x_loadinit, -1, -1,/*no linlog, no multi*/
+ srl[0]->s_name, srl[1]->s_name,
+ srl[2]->s_name, x->x_gui.x_ldx, x->x_gui.x_ldy,
+ x->x_gui.x_fsf.x_font_style, x->x_gui.x_fontsize,
+ 0xffffff & x->x_gui.x_bcol, 0xffffff & x->x_gui.x_fcol, 0xffffff & x->x_gui.x_lcol);
gfxstub_new(&x->x_gui.x_obj.ob_pd, x, buf);
}
@@ -259,15 +259,15 @@ static void bng_set(t_bng *x)
{
if(x->x_flashed)
{
- x->x_flashed = 0;
- (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
- clock_delay(x->x_clock_brk, x->x_flashtime_break);
- x->x_flashed = 1;
+ x->x_flashed = 0;
+ (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
+ clock_delay(x->x_clock_brk, x->x_flashtime_break);
+ x->x_flashed = 1;
}
else
{
- x->x_flashed = 1;
- (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
+ x->x_flashed = 1;
+ (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
}
clock_delay(x->x_clock_hld, x->x_flashtime_hold);
}
@@ -276,32 +276,32 @@ static void bng_bout1(t_bng *x)/*wird nur mehr gesendet, wenn snd != rcv*/
{
if(!x->x_gui.x_fsf.x_put_in2out)
{
- x->x_gui.x_isa.x_locked = 1;
- clock_delay(x->x_clock_lck, 2);
+ x->x_gui.x_isa.x_locked = 1;
+ clock_delay(x->x_clock_lck, 2);
}
outlet_bang(x->x_gui.x_obj.ob_outlet);
if(x->x_gui.x_fsf.x_snd_able && x->x_gui.x_snd->s_thing && x->x_gui.x_fsf.x_put_in2out)
- pd_bang(x->x_gui.x_snd->s_thing);
+ pd_bang(x->x_gui.x_snd->s_thing);
}
static void bng_bout2(t_bng *x)/*wird immer gesendet, wenn moeglich*/
{
if(!x->x_gui.x_fsf.x_put_in2out)
{
- x->x_gui.x_isa.x_locked = 1;
- clock_delay(x->x_clock_lck, 2);
+ x->x_gui.x_isa.x_locked = 1;
+ clock_delay(x->x_clock_lck, 2);
}
outlet_bang(x->x_gui.x_obj.ob_outlet);
if(x->x_gui.x_fsf.x_snd_able && x->x_gui.x_snd->s_thing)
- pd_bang(x->x_gui.x_snd->s_thing);
+ pd_bang(x->x_gui.x_snd->s_thing);
}
static void bng_bang(t_bng *x)/*wird nur mehr gesendet, wenn snd != rcv*/
{
if(!x->x_gui.x_isa.x_locked)
{
- bng_set(x);
- bng_bout1(x);
+ bng_set(x);
+ bng_bout1(x);
}
}
@@ -309,8 +309,8 @@ static void bng_bang2(t_bng *x)/*wird immer gesendet, wenn moeglich*/
{
if(!x->x_gui.x_isa.x_locked)
{
- bng_set(x);
- bng_bout2(x);
+ bng_set(x);
+ bng_bout2(x);
}
}
@@ -340,7 +340,7 @@ static void bng_click(t_bng *x, t_floatarg xpos, t_floatarg ypos, t_floatarg shi
static int bng_newclick(t_gobj *z, struct _glist *glist, int xpix, int ypix, int shift, int alt, int dbl, int doit)
{
if(doit)
- bng_click((t_bng *)z, (t_floatarg)xpix, (t_floatarg)ypix, (t_floatarg)shift, 0, (t_floatarg)alt);
+ bng_click((t_bng *)z, (t_floatarg)xpix, (t_floatarg)ypix, (t_floatarg)shift, 0, (t_floatarg)alt);
return (1);
}
@@ -366,7 +366,7 @@ static void bng_loadbang(t_bng *x)
if(!sys_noloadbang && x->x_gui.x_isa.x_loadinit)
{
bng_set(x);
- bng_bout2(x);
+ bng_bout2(x);
}
}
@@ -386,7 +386,7 @@ static void bng_pos(t_bng *x, t_symbol *s, int ac, t_atom *av)
static void bng_flashtime(t_bng *x, t_symbol *s, int ac, t_atom *av)
{
bng_check_minmax(x, (int)atom_getintarg(0, ac, av),
- (int)atom_getintarg(1, ac, av));
+ (int)atom_getintarg(1, ac, av));
}
static void bng_color(t_bng *x, t_symbol *s, int ac, t_atom *av)
@@ -436,7 +436,7 @@ static void *bng_new(t_symbol *s, int argc, t_atom *argv)
int ldx=0, ldy=-6;
int fs=8;
int ftbreak=IEM_BNG_DEFAULTBREAKFLASHTIME,
- fthold=IEM_BNG_DEFAULTHOLDFLASHTIME;
+ fthold=IEM_BNG_DEFAULTHOLDFLASHTIME;
char str[144];
iem_inttosymargs(&x->x_gui.x_isa, 0);
@@ -453,18 +453,18 @@ static void *bng_new(t_symbol *s, int argc, t_atom *argv)
&&IS_A_FLOAT(argv,12)&&IS_A_FLOAT(argv,13))
{
- a = (int)atom_getintarg(0, argc, argv);
- fthold = (int)atom_getintarg(1, argc, argv);
- ftbreak = (int)atom_getintarg(2, argc, argv);
- iem_inttosymargs(&x->x_gui.x_isa, atom_getintarg(3, argc, argv));
- iemgui_new_getnames(&x->x_gui, 4, argv);
- ldx = (int)atom_getintarg(7, argc, argv);
- ldy = (int)atom_getintarg(8, argc, argv);
- iem_inttofstyle(&x->x_gui.x_fsf, atom_getintarg(9, argc, argv));
- fs = (int)atom_getintarg(10, argc, argv);
- bflcol[0] = (int)atom_getintarg(11, argc, argv);
- bflcol[1] = (int)atom_getintarg(12, argc, argv);
- bflcol[2] = (int)atom_getintarg(13, argc, argv);
+ a = (int)atom_getintarg(0, argc, argv);
+ fthold = (int)atom_getintarg(1, argc, argv);
+ ftbreak = (int)atom_getintarg(2, argc, argv);
+ iem_inttosymargs(&x->x_gui.x_isa, atom_getintarg(3, argc, argv));
+ iemgui_new_getnames(&x->x_gui, 4, argv);
+ ldx = (int)atom_getintarg(7, argc, argv);
+ ldy = (int)atom_getintarg(8, argc, argv);
+ iem_inttofstyle(&x->x_gui.x_fsf, atom_getintarg(9, argc, argv));
+ fs = (int)atom_getintarg(10, argc, argv);
+ bflcol[0] = (int)atom_getintarg(11, argc, argv);
+ bflcol[1] = (int)atom_getintarg(12, argc, argv);
+ bflcol[2] = (int)atom_getintarg(13, argc, argv);
}
else iemgui_new_getnames(&x->x_gui, 4, 0);
@@ -475,21 +475,21 @@ static void *bng_new(t_symbol *s, int argc, t_atom *argv)
x->x_flashed = 0;
x->x_gui.x_glist = (t_glist *)canvas_getcurrent();
if (!strcmp(x->x_gui.x_snd->s_name, "empty"))
- x->x_gui.x_fsf.x_snd_able = 0;
+ x->x_gui.x_fsf.x_snd_able = 0;
if (!strcmp(x->x_gui.x_rcv->s_name, "empty"))
- x->x_gui.x_fsf.x_rcv_able = 0;
+ x->x_gui.x_fsf.x_rcv_able = 0;
if(x->x_gui.x_fsf.x_font_style == 1) strcpy(x->x_gui.x_font, "helvetica");
else if(x->x_gui.x_fsf.x_font_style == 2) strcpy(x->x_gui.x_font, "times");
else { x->x_gui.x_fsf.x_font_style = 0;
- strcpy(x->x_gui.x_font, "courier"); }
+ strcpy(x->x_gui.x_font, "courier"); }
if (x->x_gui.x_fsf.x_rcv_able)
- pd_bind(&x->x_gui.x_obj.ob_pd, x->x_gui.x_rcv);
+ pd_bind(&x->x_gui.x_obj.ob_pd, x->x_gui.x_rcv);
x->x_gui.x_ldx = ldx;
x->x_gui.x_ldy = ldy;
if(fs < 4)
- fs = 4;
+ fs = 4;
x->x_gui.x_fontsize = fs;
x->x_gui.x_w = iemgui_clip_size(a);
x->x_gui.x_h = x->x_gui.x_w;
@@ -507,7 +507,7 @@ static void *bng_new(t_symbol *s, int argc, t_atom *argv)
static void bng_ff(t_bng *x)
{
if(x->x_gui.x_fsf.x_rcv_able)
- pd_unbind(&x->x_gui.x_obj.ob_pd, x->x_gui.x_rcv);
+ pd_unbind(&x->x_gui.x_obj.ob_pd, x->x_gui.x_rcv);
clock_free(x->x_clock_lck);
clock_free(x->x_clock_brk);
clock_free(x->x_clock_hld);
@@ -517,7 +517,7 @@ static void bng_ff(t_bng *x)
void g_bang_setup(void)
{
bng_class = class_new(gensym("bng"), (t_newmethod)bng_new,
- (t_method)bng_ff, sizeof(t_bng), 0, A_GIMME, 0);
+ (t_method)bng_ff, sizeof(t_bng), 0, A_GIMME, 0);
class_addbang(bng_class, bng_bang);
class_addfloat(bng_class, bng_float);
class_addsymbol(bng_class, bng_symbol);
@@ -525,9 +525,9 @@ void g_bang_setup(void)
class_addlist(bng_class, bng_list);
class_addanything(bng_class, bng_anything);
class_addmethod(bng_class, (t_method)bng_click, gensym("click"),
- A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, 0);
+ A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, 0);
class_addmethod(bng_class, (t_method)bng_dialog, gensym("dialog"),
- A_GIMME, 0);
+ A_GIMME, 0);
class_addmethod(bng_class, (t_method)bng_loadbang, gensym("loadbang"), 0);
class_addmethod(bng_class, (t_method)bng_size, gensym("size"), A_GIMME, 0);
class_addmethod(bng_class, (t_method)bng_delta, gensym("delta"), A_GIMME, 0);
diff --git a/pd/src/g_canvas.c b/pd/src/g_canvas.c
index 980db26e..2d124ac3 100644
--- a/pd/src/g_canvas.c
+++ b/pd/src/g_canvas.c
@@ -29,10 +29,10 @@ to be different but are now unified except for some fossilized names.) */
struct _canvasenvironment
{
- t_symbol *ce_dir; /* directory patch lives in */
- int ce_argc; /* number of "$" arguments */
- t_atom *ce_argv; /* array of "$" arguments */
- int ce_dollarzero; /* value of "$0" */
+ t_symbol *ce_dir; /* directory patch lives in */
+ int ce_argc; /* number of "$" arguments */
+ t_atom *ce_argv; /* array of "$" arguments */
+ int ce_dollarzero; /* value of "$0" */
};
#define GLIST_DEFCANVASWIDTH 450
@@ -48,10 +48,10 @@ struct _canvasenvironment
extern t_pd *newest;
t_class *canvas_class;
-static int canvas_dspstate; /* whether DSP is on or off */
-t_canvas *canvas_editing; /* last canvas to start text edting */
-t_canvas *canvas_whichfind; /* last canvas we did a find in */
-t_canvas *canvas_list; /* list of all root canvases */
+static int canvas_dspstate; /* whether DSP is on or off */
+t_canvas *canvas_editing; /* last canvas to start text edting */
+t_canvas *canvas_whichfind; /* last canvas we did a find in */
+t_canvas *canvas_list; /* list of all root canvases */
/* ------------------ forward function declarations --------------- */
static void canvas_start_dsp(void);
@@ -76,22 +76,23 @@ static void glist_doupdatewindowlist(t_glist *gl, char *sbuf)
t_gobj *g;
if (!gl->gl_owner)
{
- /* this is a canvas; if we have a window, put on "windows" list */
- t_canvas *canvas = (t_canvas *)gl;
- if (canvas->gl_havewindow)
- {
- if (strlen(sbuf) + strlen(gl->gl_name->s_name) + 100 <= 1024)
- {
- char tbuf[1024];
- sprintf(tbuf, "{%s .x%x} ", gl->gl_name->s_name, (t_int)canvas);
- strcat(sbuf, tbuf);
- }
- }
+ /* this is a canvas; if we have a window, put on "windows" list */
+ t_canvas *canvas = (t_canvas *)gl;
+ if (canvas->gl_havewindow)
+ {
+ if (strlen(sbuf) + strlen(gl->gl_name->s_name) + 100 <= 1024)
+ {
+ char tbuf[1024];
+ sprintf(tbuf, "{%s .x%lx} ", gl->gl_name->s_name,
+ (t_int)canvas);
+ strcat(sbuf, tbuf);
+ }
+ }
}
for (g = gl->gl_list; g; g = g->g_next)
{
- if (pd_class(&g->g_pd) == canvas_class)
- glist_doupdatewindowlist((t_glist *)g, sbuf);
+ if (pd_class(&g->g_pd) == canvas_class)
+ glist_doupdatewindowlist((t_glist *)g, sbuf);
}
return;
}
@@ -102,9 +103,9 @@ void canvas_updatewindowlist( void)
t_canvas *x;
char sbuf[1024];
strcpy(sbuf, "set menu_windowlist {");
- /* find all root canvases */
+ /* find all root canvases */
for (x = canvas_list; x; x = x->gl_next)
- glist_doupdatewindowlist(x, sbuf);
+ glist_doupdatewindowlist(x, sbuf);
/* next line updates the window menu state before -postcommand tries it */
strcat(sbuf, "}\npdtk_fixwindowmenu\n");
sys_gui(sbuf);
@@ -119,25 +120,25 @@ static void canvas_addtolist(t_canvas *x)
static void canvas_takeofflist(t_canvas *x)
{
- /* take it off the window list */
+ /* take it off the window list */
if (x == canvas_list) canvas_list = x->gl_next;
else
{
- t_canvas *z;
- for (z = canvas_list; z->gl_next != x; z = z->gl_next)
- ;
- z->gl_next = x->gl_next;
+ t_canvas *z;
+ for (z = canvas_list; z->gl_next != x; z = z->gl_next)
+ ;
+ z->gl_next = x->gl_next;
}
}
void canvas_setargs(int argc, t_atom *argv)
{
- /* if there's an old one lying around free it here. This
- happens if an abstraction is loaded but never gets as far
- as calling canvas_new(). */
+ /* if there's an old one lying around free it here. This
+ happens if an abstraction is loaded but never gets as far
+ as calling canvas_new(). */
if (canvas_newargv)
- freebytes(canvas_newargv, canvas_newargc * sizeof(t_atom));
+ freebytes(canvas_newargv, canvas_newargc * sizeof(t_atom));
canvas_newargc = argc;
canvas_newargv = copybytes(argv, argc * sizeof(t_atom));
}
@@ -167,8 +168,8 @@ t_canvasenvironment *canvas_getenv(t_canvas *x)
{
if (!x) bug("canvas_getenv");
while (!x->gl_env)
- if (!(x = x->gl_owner))
- bug("t_canvasenvironment", x);
+ if (!(x = x->gl_owner))
+ bug("t_canvasenvironment", x);
return (x->gl_env);
}
@@ -177,7 +178,7 @@ int canvas_getdollarzero( void)
t_canvas *x = canvas_getcurrent();
t_canvasenvironment *env = (x ? canvas_getenv(x) : 0);
if (env)
- return (env->ce_dollarzero);
+ return (env->ce_dollarzero);
else return (0);
}
@@ -194,11 +195,11 @@ t_symbol *canvas_realizedollar(t_canvas *x, t_symbol *s)
char *name = s->s_name;
if (*name == '$' && name[1] >= '0' && name[1] <= '9')
{
- t_canvasenvironment *env = canvas_getenv(x);
- canvas_setcurrent(x);
- ret = binbuf_realizedollsym(gensym(name+1),
- env->ce_argc, env->ce_argv, 1);
- canvas_unsetcurrent(x);
+ t_canvasenvironment *env = canvas_getenv(x);
+ canvas_setcurrent(x);
+ ret = binbuf_realizedollsym(gensym(name+1),
+ env->ce_argc, env->ce_argv, 1);
+ canvas_unsetcurrent(x);
}
else ret = s;
return (ret);
@@ -221,35 +222,35 @@ void canvas_makefilename(t_canvas *x, char *file, char *result, int resultsize)
char *dir = canvas_getenv(x)->ce_dir->s_name;
if (file[0] == '/' || (file[0] && file[1] == ':') || !*dir)
{
- strncpy(result, file, resultsize);
- result[resultsize-1] = 0;
+ strncpy(result, file, resultsize);
+ result[resultsize-1] = 0;
}
else
{
- int nleft;
- strncpy(result, dir, resultsize);
- result[resultsize-1] = 0;
- nleft = resultsize - strlen(result) - 1;
- if (nleft <= 0) return;
- strcat(result, "/");
- strncat(result, file, nleft);
- result[resultsize-1] = 0;
- }
+ int nleft;
+ strncpy(result, dir, resultsize);
+ result[resultsize-1] = 0;
+ nleft = resultsize - strlen(result) - 1;
+ if (nleft <= 0) return;
+ strcat(result, "/");
+ strncat(result, file, nleft);
+ result[resultsize-1] = 0;
+ }
}
void canvas_rename(t_canvas *x, t_symbol *s, t_symbol *dir)
{
if (strcmp(x->gl_name->s_name, "Pd"))
- pd_unbind(&x->gl_pd, canvas_makebindsym(x->gl_name));
+ pd_unbind(&x->gl_pd, canvas_makebindsym(x->gl_name));
x->gl_name = s;
if (strcmp(x->gl_name->s_name, "Pd"))
- pd_bind(&x->gl_pd, canvas_makebindsym(x->gl_name));
+ pd_bind(&x->gl_pd, canvas_makebindsym(x->gl_name));
if (glist_isvisible(x))
- canvas_reflecttitle(x);
+ canvas_reflecttitle(x);
if (dir && dir != &s_)
{
- t_canvasenvironment *e = canvas_getenv(x);
- e->ce_dir = dir;
+ t_canvasenvironment *e = canvas_getenv(x);
+ e->ce_dir = dir;
}
}
@@ -260,7 +261,7 @@ int canvas_getindex(t_canvas *x, t_gobj *y)
t_gobj *y2;
int indexno;
for (indexno = 0, y2 = x->gl_list; y2 && y2 != y; y2 = y2->g_next)
- indexno++;
+ indexno++;
return (indexno);
}
@@ -278,51 +279,51 @@ t_outconnect *linetraverser_next(t_linetraverser *t)
int outno;
while (!rval)
{
- outno = t->tr_nextoutno;
- while (outno == t->tr_nout)
- {
- t_gobj *y;
- t_object *ob = 0;
- if (!t->tr_ob) y = t->tr_x->gl_list;
- else y = t->tr_ob->ob_g.g_next;
- for (; y; y = y->g_next)
- if (ob = pd_checkobject(&y->g_pd)) break;
- if (!ob) return (0);
- t->tr_ob = ob;
- t->tr_nout = obj_noutlets(ob);
- outno = 0;
- if (glist_isvisible(t->tr_x))
- gobj_getrect(y, t->tr_x,
- &t->tr_x11, &t->tr_y11, &t->tr_x12, &t->tr_y12);
- else t->tr_x11 = t->tr_y11 = t->tr_x12 = t->tr_y12 = 0;
- }
- t->tr_nextoutno = outno + 1;
- rval = obj_starttraverseoutlet(t->tr_ob, &t->tr_outlet, outno);
- t->tr_outno = outno;
+ outno = t->tr_nextoutno;
+ while (outno == t->tr_nout)
+ {
+ t_gobj *y;
+ t_object *ob = 0;
+ if (!t->tr_ob) y = t->tr_x->gl_list;
+ else y = t->tr_ob->ob_g.g_next;
+ for (; y; y = y->g_next)
+ if (ob = pd_checkobject(&y->g_pd)) break;
+ if (!ob) return (0);
+ t->tr_ob = ob;
+ t->tr_nout = obj_noutlets(ob);
+ outno = 0;
+ if (glist_isvisible(t->tr_x))
+ gobj_getrect(y, t->tr_x,
+ &t->tr_x11, &t->tr_y11, &t->tr_x12, &t->tr_y12);
+ else t->tr_x11 = t->tr_y11 = t->tr_x12 = t->tr_y12 = 0;
+ }
+ t->tr_nextoutno = outno + 1;
+ rval = obj_starttraverseoutlet(t->tr_ob, &t->tr_outlet, outno);
+ t->tr_outno = outno;
}
t->tr_nextoc = obj_nexttraverseoutlet(rval, &t->tr_ob2,
- &t->tr_inlet, &t->tr_inno);
+ &t->tr_inlet, &t->tr_inno);
t->tr_nin = obj_ninlets(t->tr_ob2);
if (!t->tr_nin) bug("drawline");
if (glist_isvisible(t->tr_x))
{
- int inplus = (t->tr_nin == 1 ? 1 : t->tr_nin - 1);
- int outplus = (t->tr_nout == 1 ? 1 : t->tr_nout - 1);
- gobj_getrect(&t->tr_ob2->ob_g, t->tr_x,
- &t->tr_x21, &t->tr_y21, &t->tr_x22, &t->tr_y22);
- t->tr_lx1 = t->tr_x11 +
- ((t->tr_x12 - t->tr_x11 - IOWIDTH) * t->tr_outno) /
- outplus + IOMIDDLE;
- t->tr_ly1 = t->tr_y12;
- t->tr_lx2 = t->tr_x21 +
- ((t->tr_x22 - t->tr_x21 - IOWIDTH) * t->tr_inno)/inplus +
- IOMIDDLE;
- t->tr_ly2 = t->tr_y21;
+ int inplus = (t->tr_nin == 1 ? 1 : t->tr_nin - 1);
+ int outplus = (t->tr_nout == 1 ? 1 : t->tr_nout - 1);
+ gobj_getrect(&t->tr_ob2->ob_g, t->tr_x,
+ &t->tr_x21, &t->tr_y21, &t->tr_x22, &t->tr_y22);
+ t->tr_lx1 = t->tr_x11 +
+ ((t->tr_x12 - t->tr_x11 - IOWIDTH) * t->tr_outno) /
+ outplus + IOMIDDLE;
+ t->tr_ly1 = t->tr_y12;
+ t->tr_lx2 = t->tr_x21 +
+ ((t->tr_x22 - t->tr_x21 - IOWIDTH) * t->tr_inno)/inplus +
+ IOMIDDLE;
+ t->tr_ly2 = t->tr_y21;
}
else
{
- t->tr_x21 = t->tr_y21 = t->tr_x22 = t->tr_y22 = 0;
- t->tr_lx1 = t->tr_ly1 = t->tr_lx2 = t->tr_ly2 = 0;
+ t->tr_x21 = t->tr_y21 = t->tr_x22 = t->tr_y22 = 0;
+ t->tr_lx1 = t->tr_ly1 = t->tr_lx2 = t->tr_ly2 = 0;
}
return (rval);
@@ -339,7 +340,7 @@ int glist_valid = 10000;
void glist_init(t_glist *x)
{
- /* zero out everyone except "pd" field */
+ /* zero out everyone except "pd" field */
memset(((char *)x) + sizeof(x->gl_pd), 0, sizeof(*x) - sizeof(x->gl_pd));
x->gl_stub = gstub_new(x, 0);
x->gl_valid = ++glist_valid;
@@ -361,40 +362,40 @@ t_canvas *canvas_new(void *dummy, t_symbol *sel, int argc, t_atom *argv)
glist_init(x);
x->gl_obj.te_type = T_OBJECT;
if (!owner)
- canvas_addtolist(x);
- /* post("canvas %x, owner %x", x, owner); */
+ canvas_addtolist(x);
+ /* post("canvas %lx, owner %lx", x, owner); */
if (argc == 5) /* toplevel: x, y, w, h, font */
{
- xloc = atom_getintarg(0, argc, argv);
- yloc = atom_getintarg(1, argc, argv);
- width = atom_getintarg(2, argc, argv);
- height = atom_getintarg(3, argc, argv);
- font = atom_getintarg(4, argc, argv);
+ xloc = atom_getintarg(0, argc, argv);
+ yloc = atom_getintarg(1, argc, argv);
+ width = atom_getintarg(2, argc, argv);
+ height = atom_getintarg(3, argc, argv);
+ font = atom_getintarg(4, argc, argv);
}
else if (argc == 6) /* subwindow: x, y, w, h, name, vis */
{
- xloc = atom_getintarg(0, argc, argv);
- yloc = atom_getintarg(1, argc, argv);
- width = atom_getintarg(2, argc, argv);
- height = atom_getintarg(3, argc, argv);
- s = atom_getsymbolarg(4, argc, argv);
- vis = atom_getintarg(5, argc, argv);
+ xloc = atom_getintarg(0, argc, argv);
+ yloc = atom_getintarg(1, argc, argv);
+ width = atom_getintarg(2, argc, argv);
+ height = atom_getintarg(3, argc, argv);
+ s = atom_getsymbolarg(4, argc, argv);
+ vis = atom_getintarg(5, argc, argv);
}
- /* (otherwise assume we're being created from the menu.) */
+ /* (otherwise assume we're being created from the menu.) */
if (canvas_newdirectory->s_name[0])
{
- static int dollarzero = 1000;
- t_canvasenvironment *env = x->gl_env =
- (t_canvasenvironment *)getbytes(sizeof(*x->gl_env));
- env->ce_dir = canvas_newdirectory;
- env->ce_argc = canvas_newargc;
- env->ce_argv = canvas_newargv;
- env->ce_dollarzero = dollarzero++;
- canvas_newdirectory = &s_;
- canvas_newargc = 0;
- canvas_newargv = 0;
+ static int dollarzero = 1000;
+ t_canvasenvironment *env = x->gl_env =
+ (t_canvasenvironment *)getbytes(sizeof(*x->gl_env));
+ env->ce_dir = canvas_newdirectory;
+ env->ce_argc = canvas_newargc;
+ env->ce_argv = canvas_newargv;
+ env->ce_dollarzero = dollarzero++;
+ canvas_newdirectory = &s_;
+ canvas_newargc = 0;
+ canvas_newargv = 0;
}
else x->gl_env = 0;
@@ -409,9 +410,9 @@ t_canvas *canvas_new(void *dummy, t_symbol *sel, int argc, t_atom *argv)
canvas_setbounds(x, xloc, yloc, xloc + width, yloc + height);
x->gl_owner = owner;
x->gl_name = (*s->s_name ? s :
- (canvas_newfilename ? canvas_newfilename : gensym("Pd")));
+ (canvas_newfilename ? canvas_newfilename : gensym("Pd")));
if (strcmp(x->gl_name->s_name, "Pd"))
- pd_bind(&x->gl_pd, canvas_makebindsym(x->gl_name));
+ pd_bind(&x->gl_pd, canvas_makebindsym(x->gl_name));
x->gl_loading = 1;
x->gl_willvis = vis;
x->gl_edit = !strncmp(x->gl_name->s_name, "Untitled", 8);
@@ -448,33 +449,33 @@ t_glist *glist_addglist(t_glist *g, t_symbol *sym,
x->gl_obj.te_type = T_OBJECT;
if (!*sym->s_name)
{
- char buf[40];
- sprintf(buf, "graph%d", ++gcount);
- sym = gensym(buf);
- menu = 1;
+ char buf[40];
+ sprintf(buf, "graph%d", ++gcount);
+ sym = gensym(buf);
+ menu = 1;
}
else if (!strncmp((str = sym->s_name), "graph", 5)
- && (zz = atoi(str + 5)) > gcount)
- gcount = zz;
- /* in 0.34 and earlier, the pixel rectangle and the y bounds were
- reversed; this would behave the same, except that the dialog window
- would be confusing. The "correct" way is to have "py1" be the value
- that is higher on the screen. */
+ && (zz = atoi(str + 5)) > gcount)
+ gcount = zz;
+ /* in 0.34 and earlier, the pixel rectangle and the y bounds were
+ reversed; this would behave the same, except that the dialog window
+ would be confusing. The "correct" way is to have "py1" be the value
+ that is higher on the screen. */
if (py2 < py1)
{
- float zz;
- zz = y2;
- y2 = y1;
- y1 = zz;
- zz = py2;
- py2 = py1;
- py1 = zz;
+ float zz;
+ zz = y2;
+ y2 = y1;
+ y1 = zz;
+ zz = py2;
+ py2 = py1;
+ py1 = zz;
}
if (x1 == x2 || y1 == y2)
- x1 = 0, x2 = 100, y1 = 1, y2 = -1;
+ x1 = 0, x2 = 100, y1 = 1, y2 = -1;
if (px1 >= px2 || py1 >= py2)
- px1 = 100, py1 = 20, px2 = 100 + GLIST_DEFGRAPHWIDTH,
- py2 = 20 + GLIST_DEFGRAPHHEIGHT;
+ px1 = 100, py1 = 20, px2 = 100 + GLIST_DEFGRAPHWIDTH,
+ py2 = 20 + GLIST_DEFGRAPHHEIGHT;
x->gl_name = sym;
x->gl_x1 = x1;
x->gl_x2 = x2;
@@ -485,22 +486,22 @@ t_glist *glist_addglist(t_glist *g, t_symbol *sym,
x->gl_pixwidth = px2 - px1;
x->gl_pixheight = py2 - py1;
x->gl_font = (canvas_getcurrent() ?
- canvas_getcurrent()->gl_font : sys_defaultfont);
+ canvas_getcurrent()->gl_font : sys_defaultfont);
x->gl_screenx1 = x->gl_screeny1 = 0;
x->gl_screenx2 = 450;
x->gl_screeny2 = 300;
if (strcmp(x->gl_name->s_name, "Pd"))
- pd_bind(&x->gl_pd, canvas_makebindsym(x->gl_name));
+ pd_bind(&x->gl_pd, canvas_makebindsym(x->gl_name));
x->gl_owner = g;
x->gl_stretch = 1;
x->gl_isgraph = 1;
x->gl_obj.te_binbuf = binbuf_new();
binbuf_addv(x->gl_obj.te_binbuf, "s", gensym("graph"));
if (!menu)
- pd_pushsym(&x->gl_pd);
+ pd_pushsym(&x->gl_pd);
glist_add(g, &x->gl_gobj);
if (glist_isvisible(g))
- canvas_create_editor(x, 1);
+ canvas_create_editor(x, 1);
return (x);
}
@@ -532,6 +533,9 @@ static void canvas_setbounds(t_canvas *x, int x1, int y1, int x2, int y2)
{
int heightwas = y2 - y1;
int heightchange = y2 - y1 - (x->gl_screeny2 - x->gl_screeny1);
+ if (x->gl_screenx1 == x1 && x->gl_screeny1 == y1 &&
+ x->gl_screenx2 == x2 && x->gl_screeny2 == y2)
+ return;
x->gl_screenx1 = x1;
x->gl_screeny1 = y1;
x->gl_screenx2 = x2;
@@ -539,20 +543,20 @@ static void canvas_setbounds(t_canvas *x, int x1, int y1, int x2, int y2)
/* post("set bounds %d %d %d %d", x1, y1, x2, y2); */
if (!glist_isgraph(x) && (x->gl_y2 < x->gl_y1))
{
- /* if it's flipped so that y grows upward,
- fix so that zero is bottom edge and redraw. This is
- only appropriate if we're a regular "text" object on the
- parent. */
- float diff = x->gl_y1 - x->gl_y2;
- t_gobj *y;
- x->gl_y1 = heightwas * diff;
- x->gl_y2 = x->gl_y1 - diff;
- /* and move text objects accordingly; they should stick
- to the bottom, not the top. */
- for (y = x->gl_list; y; y = y->g_next)
- if (pd_checkobject(&y->g_pd))
- gobj_displace(y, x, 0, heightchange);
- canvas_redraw(x);
+ /* if it's flipped so that y grows upward,
+ fix so that zero is bottom edge and redraw. This is
+ only appropriate if we're a regular "text" object on the
+ parent. */
+ float diff = x->gl_y1 - x->gl_y2;
+ t_gobj *y;
+ x->gl_y1 = heightwas * diff;
+ x->gl_y2 = x->gl_y1 - diff;
+ /* and move text objects accordingly; they should stick
+ to the bottom, not the top. */
+ for (y = x->gl_list; y; y = y->g_next)
+ if (pd_checkobject(&y->g_pd))
+ gobj_displace(y, x, 0, heightchange);
+ canvas_redraw(x);
}
}
@@ -570,23 +574,23 @@ void canvas_reflecttitle(t_canvas *x)
t_canvasenvironment *env = canvas_getenv(x);
if (env->ce_argc)
{
- int i;
- strcpy(namebuf, " (");
- for (i = 0; i < env->ce_argc; i++)
- {
- if (strlen(namebuf) > MAXPDSTRING/2 - 5)
- break;
- if (i != 0)
- strcat(namebuf, " ");
- atom_string(&env->ce_argv[i], namebuf + strlen(namebuf),
- MAXPDSTRING/2);
- }
- strcat(namebuf, ")");
+ int i;
+ strcpy(namebuf, " (");
+ for (i = 0; i < env->ce_argc; i++)
+ {
+ if (strlen(namebuf) > MAXPDSTRING/2 - 5)
+ break;
+ if (i != 0)
+ strcat(namebuf, " ");
+ atom_string(&env->ce_argv[i], namebuf + strlen(namebuf),
+ MAXPDSTRING/2);
+ }
+ strcat(namebuf, ")");
}
else namebuf[0] = 0;
- sys_vgui("wm title .x%x {%s%c%s - %s}\n",
- x, x->gl_name->s_name, (x->gl_dirty? '*' : ' '), namebuf,
- canvas_getdir(x)->s_name);
+ sys_vgui("wm title .x%lx {%s%c%s - %s}\n",
+ x, x->gl_name->s_name, (x->gl_dirty? '*' : ' '), namebuf,
+ canvas_getdir(x)->s_name);
}
void canvas_dirty(t_canvas *x, t_int n)
@@ -594,8 +598,8 @@ void canvas_dirty(t_canvas *x, t_int n)
t_canvas *x2 = canvas_getrootfor(x);
if ((unsigned)n != x2->gl_dirty)
{
- x2->gl_dirty = n;
- canvas_reflecttitle(x2);
+ x2->gl_dirty = n;
+ canvas_reflecttitle(x2);
}
}
@@ -608,38 +612,36 @@ void canvas_map(t_canvas *x, t_floatarg f)
t_gobj *y;
if (flag)
{
- if (!glist_isvisible(x))
- {
- t_selection *sel;
- if (!x->gl_havewindow)
- {
- bug("canvas_map");
- canvas_vis(x, 1);
- }
- for (y = x->gl_list; y; y = y->g_next)
- gobj_vis(y, x, 1);
- for (sel = x->gl_editor->e_selection; sel; sel = sel->sel_next)
- gobj_select(sel->sel_what, x, 1);
- x->gl_mapped = 1;
- canvas_drawlines(x);
- /* simulate a mouse up so u_main will calculate scrollbars...
- ugly! */
- sys_vgui("pdtk_canvas_mouseup .x%x.c 0 0 0\n", x);
- }
+ if (!glist_isvisible(x))
+ {
+ t_selection *sel;
+ if (!x->gl_havewindow)
+ {
+ bug("canvas_map");
+ canvas_vis(x, 1);
+ }
+ for (y = x->gl_list; y; y = y->g_next)
+ gobj_vis(y, x, 1);
+ for (sel = x->gl_editor->e_selection; sel; sel = sel->sel_next)
+ gobj_select(sel->sel_what, x, 1);
+ x->gl_mapped = 1;
+ canvas_drawlines(x);
+ sys_vgui("pdtk_canvas_getscroll .x%lx.c\n", x);
+ }
}
else
{
- if (glist_isvisible(x))
- {
- /* just clear out the whole canvas... */
- sys_vgui(".x%x.c delete all\n", x);
- /* alternatively, we could have erased them one by one...
- for (y = x->gl_list; y; y = y->g_next)
- gobj_vis(y, x, 0);
- ... but we should go through and erase the lines as well
- if we do it that way. */
- x->gl_mapped = 0;
- }
+ if (glist_isvisible(x))
+ {
+ /* just clear out the whole canvas... */
+ sys_vgui(".x%lx.c delete all\n", x);
+ /* alternatively, we could have erased them one by one...
+ for (y = x->gl_list; y; y = y->g_next)
+ gobj_vis(y, x, 0);
+ ... but we should go through and erase the lines as well
+ if we do it that way. */
+ x->gl_mapped = 0;
+ }
}
}
@@ -647,8 +649,8 @@ void canvas_redraw(t_canvas *x)
{
if (glist_isvisible(x))
{
- canvas_map(x, 0);
- canvas_map(x, 1);
+ canvas_map(x, 0);
+ canvas_map(x, 1);
}
}
@@ -661,7 +663,7 @@ static t_editor *editor_new(t_glist *owner)
x->e_connectbuf = binbuf_new();
x->e_deleted = binbuf_new();
x->e_glist = owner;
- sprintf(buf, ".x%x", (t_int)owner);
+ sprintf(buf, ".x%lx", (t_int)owner);
x->e_guiconnect = guiconnect_new(&owner->gl_pd, gensym(buf));
return (x);
}
@@ -683,33 +685,33 @@ void canvas_create_editor(t_glist *x, int createit)
t_object *ob;
if (createit)
{
- if (x->gl_editor)
- bug("canvas_create_editor");
- else
- {
- x->gl_editor = editor_new(x);
- for (y = x->gl_list; y; y = y->g_next)
- if (ob = pd_checkobject(&y->g_pd))
- rtext_new(x, ob);
- }
+ if (x->gl_editor)
+ bug("canvas_create_editor");
+ else
+ {
+ x->gl_editor = editor_new(x);
+ for (y = x->gl_list; y; y = y->g_next)
+ if (ob = pd_checkobject(&y->g_pd))
+ rtext_new(x, ob);
+ }
}
else
{
- if (!x->gl_editor)
- bug("canvas_create_editor");
- else
- {
- for (y = x->gl_list; y; y = y->g_next)
- if (ob = pd_checkobject(&y->g_pd))
- rtext_free(glist_findrtext(x, ob));
- editor_free(x->gl_editor, x);
- x->gl_editor = 0;
- }
+ if (!x->gl_editor)
+ bug("canvas_create_editor");
+ else
+ {
+ for (y = x->gl_list; y; y = y->g_next)
+ if (ob = pd_checkobject(&y->g_pd))
+ rtext_free(glist_findrtext(x, ob));
+ editor_free(x->gl_editor, x);
+ x->gl_editor = 0;
+ }
}
for (y = x->gl_list; y; y = y->g_next)
- if (pd_class(&y->g_pd) == canvas_class &&
- ((t_canvas *)y)->gl_isgraph)
- canvas_create_editor((t_canvas *)y, createit);
+ if (pd_class(&y->g_pd) == canvas_class &&
+ ((t_canvas *)y)->gl_isgraph)
+ canvas_create_editor((t_canvas *)y, createit);
}
/* we call this when we want the window to become visible, mapped, and
@@ -721,68 +723,68 @@ void canvas_vis(t_canvas *x, t_floatarg f)
int flag = (f != 0);
if (flag)
{
- /* test if we're already visible and toplevel */
- if (glist_isvisible(x) && !x->gl_isgraph)
- { /* just put us in front */
+ /* test if we're already visible and toplevel */
+ if (glist_isvisible(x) && !x->gl_isgraph)
+ { /* just put us in front */
#ifdef MSW
- canvas_vis(x, 0);
- canvas_vis(x, 1);
+ canvas_vis(x, 0);
+ canvas_vis(x, 1);
#else
- sys_vgui("raise .x%x\n", x);
- sys_vgui("focus .x%x.c\n", x);
- sys_vgui("wm deiconify .x%x\n", x);
+ sys_vgui("raise .x%lx\n", x);
+ sys_vgui("focus .x%lx.c\n", x);
+ sys_vgui("wm deiconify .x%lx\n", x);
#endif
- }
- else
- {
- canvas_create_editor(x, 1);
- sys_vgui("pdtk_canvas_new .x%x %d %d +%d+%d %d\n", x,
- (int)(x->gl_screenx2 - x->gl_screenx1),
- (int)(x->gl_screeny2 - x->gl_screeny1),
- (int)(x->gl_screenx1), (int)(x->gl_screeny1),
- x->gl_edit);
- canvas_reflecttitle(x);
- x->gl_havewindow = 1;
- canvas_updatewindowlist();
- }
+ }
+ else
+ {
+ canvas_create_editor(x, 1);
+ sys_vgui("pdtk_canvas_new .x%lx %d %d +%d+%d %d\n", x,
+ (int)(x->gl_screenx2 - x->gl_screenx1),
+ (int)(x->gl_screeny2 - x->gl_screeny1),
+ (int)(x->gl_screenx1), (int)(x->gl_screeny1),
+ x->gl_edit);
+ canvas_reflecttitle(x);
+ x->gl_havewindow = 1;
+ canvas_updatewindowlist();
+ }
}
else /* make invisible */
{
- int i;
- t_canvas *x2;
- if (!x->gl_havewindow)
- {
- /* bug workaround -- a graph in a visible patch gets "invised"
- when the patch is closed, and must lose the editor here. It's
- probably not the natural place to do this. Other cases like
- subpatches fall here too but don'd need the editor freed, so
- we check if it exists. */
- if (x->gl_editor)
- canvas_create_editor(x, 0);
- return;
- }
- glist_noselect(x);
- if (glist_isvisible(x))
- canvas_map(x, 0);
- canvas_create_editor(x, 0);
- sys_vgui("destroy .x%x\n", x);
- for (i = 1, x2 = x; x2; x2 = x2->gl_next, i++)
- ;
- sys_vgui(".mbar.find delete %d\n", i);
- /* if we're a graph on our parent, and if the parent exists
- and is visible, show ourselves on parent. */
- if (glist_isgraph(x) && x->gl_owner)
- {
- t_glist *gl2 = x->gl_owner;
- canvas_create_editor(x, 1);
- if (glist_isvisible(gl2))
- gobj_vis(&x->gl_gobj, gl2, 0);
- x->gl_havewindow = 0;
- if (glist_isvisible(gl2))
- gobj_vis(&x->gl_gobj, gl2, 1);
- }
- else x->gl_havewindow = 0;
- canvas_updatewindowlist();
+ int i;
+ t_canvas *x2;
+ if (!x->gl_havewindow)
+ {
+ /* bug workaround -- a graph in a visible patch gets "invised"
+ when the patch is closed, and must lose the editor here. It's
+ probably not the natural place to do this. Other cases like
+ subpatches fall here too but don'd need the editor freed, so
+ we check if it exists. */
+ if (x->gl_editor)
+ canvas_create_editor(x, 0);
+ return;
+ }
+ glist_noselect(x);
+ if (glist_isvisible(x))
+ canvas_map(x, 0);
+ canvas_create_editor(x, 0);
+ sys_vgui("destroy .x%lx\n", x);
+ for (i = 1, x2 = x; x2; x2 = x2->gl_next, i++)
+ ;
+ sys_vgui(".mbar.find delete %d\n", i);
+ /* if we're a graph on our parent, and if the parent exists
+ and is visible, show ourselves on parent. */
+ if (glist_isgraph(x) && x->gl_owner)
+ {
+ t_glist *gl2 = x->gl_owner;
+ canvas_create_editor(x, 1);
+ if (glist_isvisible(gl2))
+ gobj_vis(&x->gl_gobj, gl2, 0);
+ x->gl_havewindow = 0;
+ if (glist_isvisible(gl2))
+ gobj_vis(&x->gl_gobj, gl2, 1);
+ }
+ else x->gl_havewindow = 0;
+ canvas_updatewindowlist();
}
}
@@ -792,19 +794,19 @@ void glist_menu_open(t_glist *x)
{
if (glist_isvisible(x) && !glist_istoplevel(x))
{
- t_glist *gl2 = x->gl_owner;
- if (!gl2)
- bug("canvas_vis"); /* shouldn't happen but don't get too upset. */
- else
- {
- /* erase ourself in parent window */
- gobj_vis(&x->gl_gobj, gl2, 0);
- /* get rid of our editor (and subeditors) */
- canvas_create_editor(x, 0);
- x->gl_havewindow = 1;
- /* redraw ourself in parent window (blanked out this time) */
- gobj_vis(&x->gl_gobj, gl2, 1);
- }
+ t_glist *gl2 = x->gl_owner;
+ if (!gl2)
+ bug("canvas_vis"); /* shouldn't happen but don't get too upset. */
+ else
+ {
+ /* erase ourself in parent window */
+ gobj_vis(&x->gl_gobj, gl2, 0);
+ /* get rid of our editor (and subeditors) */
+ canvas_create_editor(x, 0);
+ x->gl_havewindow = 1;
+ /* redraw ourself in parent window (blanked out this time) */
+ gobj_vis(&x->gl_gobj, gl2, 1);
+ }
}
canvas_vis(x, 1);
}
@@ -816,9 +818,9 @@ int glist_isvisible(t_glist *x)
int glist_istoplevel(t_glist *x)
{
- /* we consider a graph "toplevel" if it has its own window
- or if it appears as a box in its parent window so that we
- don't draw the actual contents there. */
+ /* we consider a graph "toplevel" if it has its own window
+ or if it appears as a box in its parent window so that we
+ don't draw the actual contents there. */
return (x->gl_havewindow || !x->gl_isgraph);
}
@@ -833,26 +835,26 @@ void canvas_free(t_canvas *x)
int dspstate = canvas_suspend_dsp();
canvas_noundo(x);
if (canvas_editing == x)
- canvas_editing = 0;
+ canvas_editing = 0;
if (canvas_whichfind == x)
- canvas_whichfind = 0;
+ canvas_whichfind = 0;
glist_noselect(x);
while (y = x->gl_list)
- glist_delete(x, y);
+ glist_delete(x, y);
canvas_vis(x, 0);
if (strcmp(x->gl_name->s_name, "Pd"))
- pd_unbind(&x->gl_pd, canvas_makebindsym(x->gl_name));
+ pd_unbind(&x->gl_pd, canvas_makebindsym(x->gl_name));
if (x->gl_env)
{
- freebytes(x->gl_env->ce_argv, x->gl_env->ce_argc * sizeof(t_atom));
- freebytes(x->gl_env, sizeof(*x->gl_env));
+ freebytes(x->gl_env->ce_argv, x->gl_env->ce_argc * sizeof(t_atom));
+ freebytes(x->gl_env, sizeof(*x->gl_env));
}
canvas_resume_dsp(dspstate);
glist_cleanup(x);
- gfxstub_deleteforkey(x); /* probably unnecessary */
+ gfxstub_deleteforkey(x); /* probably unnecessary */
if (!x->gl_owner)
- canvas_takeofflist(x);
+ canvas_takeofflist(x);
}
/* ----------------- lines ---------- */
@@ -862,13 +864,13 @@ static void canvas_drawlines(t_canvas *x)
t_linetraverser t;
t_outconnect *oc;
{
- linetraverser_start(&t, x);
- while (oc = linetraverser_next(&t))
- sys_vgui(".x%x.c create line %d %d %d %d -width %d -tags l%x\n",
- glist_getcanvas(x),
- t.tr_lx1, t.tr_ly1, t.tr_lx2, t.tr_ly2,
- (outlet_getsymbol(t.tr_outlet) == &s_signal ? 2:1),
- oc);
+ linetraverser_start(&t, x);
+ while (oc = linetraverser_next(&t))
+ sys_vgui(".x%lx.c create line %d %d %d %d -width %d -tags l%lx\n",
+ glist_getcanvas(x),
+ t.tr_lx1, t.tr_ly1, t.tr_lx2, t.tr_ly2,
+ (outlet_getsymbol(t.tr_outlet) == &s_signal ? 2:1),
+ oc);
}
}
@@ -880,12 +882,12 @@ void canvas_fixlinesfor(t_canvas *x, t_text *text)
linetraverser_start(&t, x);
while (oc = linetraverser_next(&t))
{
- if (t.tr_ob == text || t.tr_ob2 == text)
- {
- sys_vgui(".x%x.c coords l%x %d %d %d %d\n",
- glist_getcanvas(x), oc,
- t.tr_lx1, t.tr_ly1, t.tr_lx2, t.tr_ly2);
- }
+ if (t.tr_ob == text || t.tr_ob2 == text)
+ {
+ sys_vgui(".x%lx.c coords l%lx %d %d %d %d\n",
+ glist_getcanvas(x), oc,
+ t.tr_lx1, t.tr_ly1, t.tr_lx2, t.tr_ly2);
+ }
}
}
@@ -897,15 +899,15 @@ void canvas_deletelinesfor(t_canvas *x, t_text *text)
linetraverser_start(&t, x);
while (oc = linetraverser_next(&t))
{
- if (t.tr_ob == text || t.tr_ob2 == text)
- {
- if (x->gl_editor)
- {
- sys_vgui(".x%x.c delete l%x\n",
- glist_getcanvas(x), oc);
- }
- obj_disconnect(t.tr_ob, t.tr_outno, t.tr_ob2, t.tr_inno);
- }
+ if (t.tr_ob == text || t.tr_ob2 == text)
+ {
+ if (x->gl_editor)
+ {
+ sys_vgui(".x%lx.c delete l%lx\n",
+ glist_getcanvas(x), oc);
+ }
+ obj_disconnect(t.tr_ob, t.tr_outno, t.tr_ob2, t.tr_inno);
+ }
}
}
@@ -918,23 +920,23 @@ void canvas_deletelinesforio(t_canvas *x, t_text *text,
linetraverser_start(&t, x);
while (oc = linetraverser_next(&t))
{
- if ((t.tr_ob == text && t.tr_outlet == outp) ||
- (t.tr_ob2 == text && t.tr_inlet == inp))
- {
- if (x->gl_editor)
- {
- sys_vgui(".x%x.c delete l%x\n",
- glist_getcanvas(x), oc);
- }
- obj_disconnect(t.tr_ob, t.tr_outno, t.tr_ob2, t.tr_inno);
- }
+ if ((t.tr_ob == text && t.tr_outlet == outp) ||
+ (t.tr_ob2 == text && t.tr_inlet == inp))
+ {
+ if (x->gl_editor)
+ {
+ sys_vgui(".x%lx.c delete l%lx\n",
+ glist_getcanvas(x), oc);
+ }
+ obj_disconnect(t.tr_ob, t.tr_outno, t.tr_ob2, t.tr_inno);
+ }
}
}
static void canvas_pop(t_canvas *x, t_floatarg fvis)
{
if (fvis != 0)
- canvas_vis(x, 1);
+ canvas_vis(x, 1);
pd_popsym(&x->gl_pd);
canvas_resortinlets(x);
canvas_resortoutlets(x);
@@ -947,35 +949,35 @@ void canvas_objfor(t_glist *gl, t_text *x, int argc, t_atom *argv);
void canvas_restore(t_canvas *x, t_symbol *s, int argc, t_atom *argv)
{ /* IOhannes */
t_pd *z;
- /* this should be unnecessary, but sometimes the canvas's name gets
- out of sync with the owning box's argument; this fixes that */
+ /* this should be unnecessary, but sometimes the canvas's name gets
+ out of sync with the owning box's argument; this fixes that */
if (argc > 3)
{
- t_atom *ap=argv+3;
- if (ap->a_type == A_SYMBOL)
- {
- char *buf=ap->a_w.w_symbol->s_name, *bufp;
- if (*buf == '$' && buf[1] >= '0' && buf[1] <= '9')
- {
- for (bufp = buf+2; *bufp; bufp++)
- if (*bufp < '0' || *bufp > '9')
- {
- SETDOLLSYM(ap, gensym(buf+1));
- goto didit;
- }
- SETDOLLAR(ap, atoi(buf+1));
- didit: ;
- }
- }
-
- if (ap->a_type == A_DOLLSYM)
- {
- t_canvasenvironment *e = canvas_getenv(canvas_getcurrent());
- canvas_rename(x, binbuf_realizedollsym(ap->a_w.w_symbol,
- e->ce_argc, e->ce_argv, 1), 0);
- }
- else if (ap->a_type == A_SYMBOL)
- canvas_rename(x, argv[3].a_w.w_symbol, 0);
+ t_atom *ap=argv+3;
+ if (ap->a_type == A_SYMBOL)
+ {
+ char *buf=ap->a_w.w_symbol->s_name, *bufp;
+ if (*buf == '$' && buf[1] >= '0' && buf[1] <= '9')
+ {
+ for (bufp = buf+2; *bufp; bufp++)
+ if (*bufp < '0' || *bufp > '9')
+ {
+ SETDOLLSYM(ap, gensym(buf+1));
+ goto didit;
+ }
+ SETDOLLAR(ap, atoi(buf+1));
+ didit: ;
+ }
+ }
+
+ if (ap->a_type == A_DOLLSYM)
+ {
+ t_canvasenvironment *e = canvas_getenv(canvas_getcurrent());
+ canvas_rename(x, binbuf_realizedollsym(ap->a_w.w_symbol,
+ e->ce_argc, e->ce_argv, 1), 0);
+ }
+ else if (ap->a_type == A_SYMBOL)
+ canvas_rename(x, argv[3].a_w.w_symbol, 0);
}
canvas_pop(x, x->gl_willvis);
@@ -983,9 +985,9 @@ void canvas_restore(t_canvas *x, t_symbol *s, int argc, t_atom *argv)
else if (*z != canvas_class) error("canvas_restore: wasn't a canvas");
else
{
- t_canvas *x2 = (t_canvas *)z;
- x->gl_owner = x2;
- canvas_objfor(x2, &x->gl_obj, argc, argv);
+ t_canvas *x2 = (t_canvas *)z;
+ x->gl_owner = x2;
+ canvas_objfor(x2, &x->gl_obj, argc, argv);
}
}
@@ -994,12 +996,12 @@ static void canvas_loadbangabstractions(t_canvas *x)
t_gobj *y;
t_symbol *s = gensym("loadbang");
for (y = x->gl_list; y; y = y->g_next)
- if (pd_class(&y->g_pd) == canvas_class)
+ if (pd_class(&y->g_pd) == canvas_class)
{
- if (canvas_isabstraction((t_canvas *)y))
- canvas_loadbang((t_canvas *)y);
- else
- canvas_loadbangabstractions((t_canvas *)y);
+ if (canvas_isabstraction((t_canvas *)y))
+ canvas_loadbang((t_canvas *)y);
+ else
+ canvas_loadbangabstractions((t_canvas *)y);
}
}
@@ -1008,15 +1010,15 @@ void canvas_loadbangsubpatches(t_canvas *x)
t_gobj *y;
t_symbol *s = gensym("loadbang");
for (y = x->gl_list; y; y = y->g_next)
- if (pd_class(&y->g_pd) == canvas_class)
+ if (pd_class(&y->g_pd) == canvas_class)
{
- if (!canvas_isabstraction((t_canvas *)y))
- canvas_loadbangsubpatches((t_canvas *)y);
+ if (!canvas_isabstraction((t_canvas *)y))
+ canvas_loadbangsubpatches((t_canvas *)y);
}
for (y = x->gl_list; y; y = y->g_next)
- if ((pd_class(&y->g_pd) != canvas_class) &&
- zgetfn(&y->g_pd, s))
- pd_vmess(&y->g_pd, s, "");
+ if ((pd_class(&y->g_pd) != canvas_class) &&
+ zgetfn(&y->g_pd, s))
+ pd_vmess(&y->g_pd, s, "");
}
void canvas_loadbang(t_canvas *x)
@@ -1044,14 +1046,14 @@ static void canvas_relocate(t_canvas *x, t_symbol *canvasgeom,
{
int cxpix, cypix, cw, ch, txpix, typix, tw, th;
if (sscanf(canvasgeom->s_name, "%dx%d+%d+%d", &cw, &ch, &cxpix, &cypix)
- < 4 ||
- sscanf(topgeom->s_name, "%dx%d+%d+%d", &tw, &th, &txpix, &typix) < 4)
- bug("canvas_relocate");
- /* for some reason this is initially called with cw=ch=1 so
- we just suppress that here. */
+ < 4 ||
+ sscanf(topgeom->s_name, "%dx%d+%d+%d", &tw, &th, &txpix, &typix) < 4)
+ bug("canvas_relocate");
+ /* for some reason this is initially called with cw=ch=1 so
+ we just suppress that here. */
if (cw > 5 && ch > 5)
- canvas_setbounds(x, txpix, typix,
- txpix + cw - HORIZBORDER, typix + ch - VERTBORDER);
+ canvas_setbounds(x, txpix, typix,
+ txpix + cw - HORIZBORDER, typix + ch - VERTBORDER);
}
void canvas_popabstraction(t_canvas *x)
@@ -1068,7 +1070,7 @@ void canvas_logerror(t_object *y)
#ifdef LATER
canvas_vis(x, 1);
if (!glist_isselected(x, &y->ob_g))
- glist_select(x, &y->ob_g);
+ glist_select(x, &y->ob_g);
#endif
}
@@ -1093,7 +1095,7 @@ static void *subcanvas_new(t_symbol *s)
static void canvas_click(t_canvas *x,
t_floatarg xpos, t_floatarg ypos,
- t_floatarg shift, t_floatarg ctrl, t_floatarg alt)
+ t_floatarg shift, t_floatarg ctrl, t_floatarg alt)
{
canvas_vis(x, 1);
}
@@ -1111,7 +1113,7 @@ void canvas_fattensub(t_canvas *x,
static void canvas_rename_method(t_canvas *x, t_symbol *s, int ac, t_atom *av)
{
if (ac && av->a_type == A_SYMBOL)
- canvas_rename(x, av->a_w.w_symbol, 0);
+ canvas_rename(x, av->a_w.w_symbol, 0);
else canvas_rename(x, gensym("Pd"), 0);
}
@@ -1126,13 +1128,13 @@ static void *table_new(t_symbol *s, t_floatarg f)
t_canvas *x, *z = canvas_getcurrent();
if (s == &s_)
{
- char tabname[255];
- t_symbol *t = gensym("table");
- sprintf(tabname, "%s%d", t->s_name, tabcount++);
- s = gensym(tabname);
+ char tabname[255];
+ t_symbol *t = gensym("table");
+ sprintf(tabname, "%s%d", t->s_name, tabcount++);
+ s = gensym(tabname);
}
if (f <= 1)
- f = 100;
+ f = 100;
SETFLOAT(a, 0);
SETFLOAT(a+1, GLIST_DEFCANVASYLOC);
SETFLOAT(a+2, 600);
@@ -1143,9 +1145,9 @@ static void *table_new(t_symbol *s, t_floatarg f)
x->gl_owner = z;
- /* create a graph for the table */
+ /* create a graph for the table */
gl = glist_addglist((t_glist*)x, &s_, 0, -1, (f > 1 ? f-1 : 1), 1,
- 50, 350, 550, 50);
+ 50, 350, 550, 50);
graph_array(gl, s, &s_float, f, 0);
@@ -1167,7 +1169,7 @@ int canvas_istable(t_canvas *x)
t_atom *argv = (x->gl_obj.te_binbuf? binbuf_getvec(x->gl_obj.te_binbuf):0);
int argc = (x->gl_obj.te_binbuf? binbuf_getnatom(x->gl_obj.te_binbuf) : 0);
int istable = (argc && argv[0].a_type == A_SYMBOL &&
- argv[0].a_w.w_symbol == gensym("table"));
+ argv[0].a_w.w_symbol == gensym("table"));
return (istable);
}
@@ -1178,7 +1180,7 @@ int canvas_showtext(t_canvas *x)
t_atom *argv = (x->gl_obj.te_binbuf? binbuf_getvec(x->gl_obj.te_binbuf):0);
int argc = (x->gl_obj.te_binbuf? binbuf_getnatom(x->gl_obj.te_binbuf) : 0);
int isarray = (argc && argv[0].a_type == A_SYMBOL &&
- argv[0].a_w.w_symbol == gensym("graph"));
+ argv[0].a_w.w_symbol == gensym("graph"));
return (!isarray);
}
@@ -1192,7 +1194,7 @@ static void canvas_dsp(t_canvas *x, t_signal **sp)
t_canvas *canvas_getrootfor(t_canvas *x)
{
if ((!x->gl_owner) || canvas_isabstraction(x))
- return (x);
+ return (x);
else return (canvas_getrootfor(x->gl_owner));
}
@@ -1224,26 +1226,26 @@ static void canvas_dodsp(t_canvas *x, int toplevel, t_signal **sp)
t_symbol *dspsym = gensym("dsp");
t_dspcontext *dc;
- /* create a new "DSP graph" object to use in sorting this canvas.
- If we aren't toplevel, there are already other dspcontexts around. */
+ /* create a new "DSP graph" object to use in sorting this canvas.
+ If we aren't toplevel, there are already other dspcontexts around. */
dc = ugen_start_graph(toplevel, sp,
- obj_nsiginlets(&x->gl_obj),
- obj_nsigoutlets(&x->gl_obj));
+ obj_nsiginlets(&x->gl_obj),
+ obj_nsigoutlets(&x->gl_obj));
- /* find all the "dsp" boxes and add them to the graph */
+ /* find all the "dsp" boxes and add them to the graph */
for (y = x->gl_list; y; y = y->g_next)
- if ((ob = pd_checkobject(&y->g_pd)) && zgetfn(&y->g_pd, dspsym))
- ugen_add(dc, ob);
+ if ((ob = pd_checkobject(&y->g_pd)) && zgetfn(&y->g_pd, dspsym))
+ ugen_add(dc, ob);
- /* ... and all dsp interconnections */
+ /* ... and all dsp interconnections */
linetraverser_start(&t, x);
while (oc = linetraverser_next(&t))
- if (obj_issignaloutlet(t.tr_ob, t.tr_outno))
- ugen_connect(dc, t.tr_ob, t.tr_outno, t.tr_ob2, t.tr_inno);
+ if (obj_issignaloutlet(t.tr_ob, t.tr_outno))
+ ugen_connect(dc, t.tr_ob, t.tr_outno, t.tr_ob2, t.tr_inno);
- /* finally, sort them and add them to the DSP chain */
+ /* finally, sort them and add them to the DSP chain */
ugen_done_graph(dc);
}
@@ -1256,7 +1258,7 @@ static void canvas_start_dsp(void)
ugen_start();
for (x = canvas_list; x; x = x->gl_next)
- canvas_dodsp(x, 1, 0);
+ canvas_dodsp(x, 1, 0);
canvas_dspstate = 1;
}
@@ -1265,9 +1267,9 @@ static void canvas_stop_dsp(void)
{
if (canvas_dspstate)
{
- ugen_stop();
- sys_gui("pdtk_pd_dsp OFF\n");
- canvas_dspstate = 0;
+ ugen_stop();
+ sys_gui("pdtk_pd_dsp OFF\n");
+ canvas_dspstate = 0;
}
}
@@ -1299,17 +1301,17 @@ void glob_dsp(void *dummy, t_symbol *s, int argc, t_atom *argv)
int newstate;
if (argc)
{
- newstate = atom_getintarg(0, argc, argv);
- if (newstate && !canvas_dspstate)
- {
- sys_set_audio_state(1);
- canvas_start_dsp();
- }
- else if (!newstate && canvas_dspstate)
- {
- canvas_stop_dsp();
- sys_set_audio_state(0);
- }
+ newstate = atom_getintarg(0, argc, argv);
+ if (newstate && !canvas_dspstate)
+ {
+ sys_set_audio_state(1);
+ canvas_start_dsp();
+ }
+ else if (!newstate && canvas_dspstate)
+ {
+ canvas_stop_dsp();
+ sys_set_audio_state(0);
+ }
}
else post("dsp state %d", canvas_dspstate);
}
@@ -1319,8 +1321,8 @@ void glist_redrawitem(t_glist *owner, t_gobj *gobj)
{
if (glist_isvisible(owner))
{
- gobj_vis(gobj, owner, 0);
- gobj_vis(gobj, owner, 1);
+ gobj_vis(gobj, owner, 0);
+ gobj_vis(gobj, owner, 1);
}
}
@@ -1333,11 +1335,11 @@ static void glist_redrawall(t_glist *gl)
int vis = glist_isvisible(gl);
for (g = gl->gl_list; g; g = g->g_next)
{
- t_class *cl;
- if (vis && g->g_pd == scalar_class)
- glist_redrawitem(gl, g);
- else if (g->g_pd == canvas_class)
- glist_redrawall((t_glist *)g);
+ t_class *cl;
+ if (vis && g->g_pd == scalar_class)
+ glist_redrawitem(gl, g);
+ else if (g->g_pd == canvas_class)
+ glist_redrawall((t_glist *)g);
}
}
@@ -1345,9 +1347,9 @@ static void glist_redrawall(t_glist *gl)
void canvas_redrawallfortemplate(t_canvas *templatecanvas)
{
t_canvas *x;
- /* find all root canvases */
+ /* find all root canvases */
for (x = canvas_list; x; x = x->gl_next)
- glist_redrawall(x);
+ glist_redrawall(x);
}
/* ------------------------------- setup routine ------------------------ */
@@ -1381,39 +1383,39 @@ extern void graph_properties(t_gobj *z, t_glist *owner);
void g_canvas_setup(void)
{
- /* we prevent the user from typing "canvas" in an object box
- by sending 0 for a creator function. */
+ /* we prevent the user from typing "canvas" in an object box
+ by sending 0 for a creator function. */
canvas_class = class_new(gensym("canvas"), 0,
- (t_method)canvas_free, sizeof(t_canvas), CLASS_NOINLET, 0);
- /* here is the real creator function, invoked in patch files
- by sending the "canvas" message to #N, which is bound
- to pd_camvasmaker. */
+ (t_method)canvas_free, sizeof(t_canvas), CLASS_NOINLET, 0);
+ /* here is the real creator function, invoked in patch files
+ by sending the "canvas" message to #N, which is bound
+ to pd_camvasmaker. */
class_addmethod(pd_canvasmaker, (t_method)canvas_new, gensym("canvas"),
- A_GIMME, 0);
+ A_GIMME, 0);
class_addmethod(canvas_class, (t_method)canvas_restore,
- gensym("restore"), A_GIMME, 0);
+ gensym("restore"), A_GIMME, 0);
class_addmethod(canvas_class, (t_method)canvas_coords,
- gensym("coords"), A_GIMME, 0);
+ gensym("coords"), A_GIMME, 0);
/* -------------------------- objects ----------------------------- */
class_addmethod(canvas_class, (t_method)canvas_obj,
- gensym("obj"), A_GIMME, A_NULL);
+ gensym("obj"), A_GIMME, A_NULL);
class_addmethod(canvas_class, (t_method)canvas_msg,
- gensym("msg"), A_GIMME, A_NULL);
+ gensym("msg"), A_GIMME, A_NULL);
class_addmethod(canvas_class, (t_method)canvas_floatatom,
- gensym("floatatom"), A_GIMME, A_NULL);
+ gensym("floatatom"), A_GIMME, A_NULL);
class_addmethod(canvas_class, (t_method)canvas_symbolatom,
- gensym("symbolatom"), A_GIMME, A_NULL);
+ gensym("symbolatom"), A_GIMME, A_NULL);
class_addmethod(canvas_class, (t_method)glist_text,
- gensym("text"), A_GIMME, A_NULL);
+ gensym("text"), A_GIMME, A_NULL);
class_addmethod(canvas_class, (t_method)glist_glist, gensym("graph"),
- A_GIMME, A_NULL);
+ A_GIMME, A_NULL);
class_addmethod(canvas_class, (t_method)glist_scalar,
- gensym("scalar"), A_GIMME, A_NULL);
+ gensym("scalar"), A_GIMME, A_NULL);
/* -------------- Thomas Musil's GUI objects ------------ */
class_addmethod(canvas_class, (t_method)canvas_bng, gensym("bng"),
- A_GIMME, A_NULL);
+ A_GIMME, A_NULL);
class_addmethod(canvas_class, (t_method)canvas_toggle, gensym("toggle"),
A_GIMME, A_NULL);
class_addmethod(canvas_class, (t_method)canvas_vslider, gensym("vslider"),
@@ -1421,7 +1423,7 @@ void g_canvas_setup(void)
class_addmethod(canvas_class, (t_method)canvas_hslider, gensym("hslider"),
A_GIMME, A_NULL);
class_addmethod(canvas_class, (t_method)canvas_hdial, gensym("hdial"),
- A_GIMME, A_NULL);
+ A_GIMME, A_NULL);
class_addmethod(canvas_class, (t_method)canvas_vdial, gensym("vdial"),
A_GIMME, A_NULL);
class_addmethod(canvas_class, (t_method)canvas_hradio, gensym("hradio"),
@@ -1431,43 +1433,43 @@ void g_canvas_setup(void)
class_addmethod(canvas_class, (t_method)canvas_vumeter, gensym("vumeter"),
A_GIMME, A_NULL);
class_addmethod(canvas_class, (t_method)canvas_mycnv, gensym("mycnv"),
- A_GIMME, A_NULL);
+ A_GIMME, A_NULL);
class_addmethod(canvas_class, (t_method)canvas_numbox, gensym("numbox"),
A_GIMME, A_NULL);
/* ------------------------ gui stuff --------------------------- */
class_addmethod(canvas_class, (t_method)canvas_pop, gensym("pop"),
- A_DEFFLOAT, A_NULL);
+ A_DEFFLOAT, A_NULL);
class_addmethod(canvas_class, (t_method)canvas_loadbang,
- gensym("loadbang"), A_NULL);
+ gensym("loadbang"), A_NULL);
class_addmethod(canvas_class, (t_method)canvas_relocate,
- gensym("relocate"), A_SYMBOL, A_SYMBOL, A_NULL);
+ gensym("relocate"), A_SYMBOL, A_SYMBOL, A_NULL);
class_addmethod(canvas_class, (t_method)canvas_vis,
- gensym("vis"), A_FLOAT, A_NULL);
+ gensym("vis"), A_FLOAT, A_NULL);
class_addmethod(canvas_class, (t_method)glist_menu_open,
- gensym("menu-open"), A_NULL);
+ gensym("menu-open"), A_NULL);
class_addmethod(canvas_class, (t_method)canvas_map,
- gensym("map"), A_FLOAT, A_NULL);
+ gensym("map"), A_FLOAT, A_NULL);
class_setpropertiesfn(canvas_class, graph_properties);
/* ---------------------- list handling ------------------------ */
class_addmethod(canvas_class, (t_method)glist_clear, gensym("clear"),
- A_NULL);
+ A_NULL);
/* ----- subcanvases, which you get by typing "pd" in a box ---- */
class_addcreator((t_newmethod)subcanvas_new, gensym("pd"), A_DEFSYMBOL, 0);
class_addcreator((t_newmethod)subcanvas_new, gensym("page"), A_DEFSYMBOL, 0);
class_addmethod(canvas_class, (t_method)canvas_click,
- gensym("click"), A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, 0);
+ gensym("click"), A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, 0);
class_addmethod(canvas_class, (t_method)canvas_dsp, gensym("dsp"), 0);
class_addmethod(canvas_class, (t_method)canvas_rename_method,
- gensym("rename"), A_GIMME, 0);
+ gensym("rename"), A_GIMME, 0);
/*---------------------------- tables -- GG ------------------- */
class_addcreator((t_newmethod)table_new, gensym("table"),
- A_DEFSYM, A_DEFFLOAT, 0);
+ A_DEFSYM, A_DEFFLOAT, 0);
/* -------------- setups from other files for canvas_class ---------------- */
g_graph_setup();
diff --git a/pd/src/g_canvas.h b/pd/src/g_canvas.h
index d3070849..0433f4a2 100644
--- a/pd/src/g_canvas.h
+++ b/pd/src/g_canvas.h
@@ -41,7 +41,7 @@ extern "C" {
#endif
/* --------------------- geometry ---------------------------- */
-#define IOWIDTH 7 /* width of an inlet/outlet in pixels */
+#define IOWIDTH 7 /* width of an inlet/outlet in pixels */
#define IOMIDDLE ((IOWIDTH-1)/2)
#define GLIST_DEFGRAPHWIDTH 200
#define GLIST_DEFGRAPHHEIGHT 140
@@ -50,8 +50,8 @@ extern "C" {
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 */
+ 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 */
@@ -82,22 +82,22 @@ typedef struct _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_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_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) */
+ 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;
@@ -107,12 +107,12 @@ typedef struct _editor
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 */
+#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
@@ -120,17 +120,17 @@ 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_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 */
+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 */
+ 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
@@ -140,43 +140,43 @@ 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) */
+ 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_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_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 */
+ 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_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_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 */
+ 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
@@ -193,28 +193,28 @@ typedef struct _dataslot
{
int ds_type;
t_symbol *ds_name;
- t_symbol *ds_arraytemplate; /* filled in for arrays only */
+ 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_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 */
+ 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;
};
@@ -242,23 +242,23 @@ 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 */
+ /* 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: */
+ /* 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: */
+ /* change color to show selection: */
typedef void (*t_selectfn)(t_gobj *x, struct _glist *glist, int state);
- /* change appearance to show activation/deactivation: */
+ /* 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 */
+ /* warn a gobj it's about to be deleted */
typedef void (*t_deletefn)(t_gobj *x, struct _glist *glist);
- /* making visible or invisible */
+ /* 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) */
+ /* 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... */
+ /* ... and later, resizing; getting/setting font or color... */
struct _widgetbehavior
{
@@ -280,27 +280,27 @@ 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: */
+ /* 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 */
+ /* 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 */
+ /* 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: */
+ /* 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 */
+ /* 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 */
+ /* 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);
@@ -327,9 +327,9 @@ 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_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 */
+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,
@@ -344,6 +344,7 @@ EXTERN int gobj_click(t_gobj *x, struct _glist *glist,
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);
+EXTERN void gobj_redraw(t_gobj *gobj, t_glist *glist);
/* -------------------- functions on glists --------------------- */
EXTERN t_glist *glist_new( void);
@@ -431,6 +432,7 @@ 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);
+EXTERN void rtext_getseltext(t_rtext *x, char **buf, int *bufsize);
/* -------------------- functions on canvases ------------------------ */
EXTERN t_class *canvas_class;
@@ -480,10 +482,10 @@ EXTERN int canvas_hitbox(t_canvas *x, t_gobj *y, int xpos, int ypos,
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 */
+ 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);
diff --git a/pd/src/g_editor.c b/pd/src/g_editor.c
index 48efb3ae..b01939fa 100644
--- a/pd/src/g_editor.c
+++ b/pd/src/g_editor.c
@@ -25,6 +25,8 @@ static void canvas_dopaste(t_canvas *x, t_binbuf *b);
static void canvas_paste(t_canvas *x);
static void canvas_clearline(t_canvas *x);
static t_binbuf *copy_binbuf;
+static char *canvas_textcopybuf;
+static int canvas_textcopybufsize;
/* ---------------- generic widget behavior ------------------------- */
@@ -32,48 +34,53 @@ void gobj_getrect(t_gobj *x, t_glist *glist, int *x1, int *y1,
int *x2, int *y2)
{
if (x->g_pd->c_wb && x->g_pd->c_wb->w_getrectfn)
- (*x->g_pd->c_wb->w_getrectfn)(x, glist, x1, y1, x2, y2);
+ (*x->g_pd->c_wb->w_getrectfn)(x, glist, x1, y1, x2, y2);
}
void gobj_displace(t_gobj *x, t_glist *glist, int dx, int dy)
{
if (x->g_pd->c_wb && x->g_pd->c_wb->w_displacefn)
- (*x->g_pd->c_wb->w_displacefn)(x, glist, dx, dy);
+ (*x->g_pd->c_wb->w_displacefn)(x, glist, dx, dy);
}
void gobj_select(t_gobj *x, t_glist *glist, int state)
{
if (x->g_pd->c_wb && x->g_pd->c_wb->w_selectfn)
- (*x->g_pd->c_wb->w_selectfn)(x, glist, state);
+ (*x->g_pd->c_wb->w_selectfn)(x, glist, state);
}
void gobj_activate(t_gobj *x, t_glist *glist, int state)
{
if (x->g_pd->c_wb && x->g_pd->c_wb->w_activatefn)
- (*x->g_pd->c_wb->w_activatefn)(x, glist, state);
+ (*x->g_pd->c_wb->w_activatefn)(x, glist, state);
}
void gobj_delete(t_gobj *x, t_glist *glist)
{
if (x->g_pd->c_wb && x->g_pd->c_wb->w_deletefn)
- (*x->g_pd->c_wb->w_deletefn)(x, glist);
+ (*x->g_pd->c_wb->w_deletefn)(x, glist);
}
void gobj_vis(t_gobj *x, struct _glist *glist, int flag)
{
if (x->g_pd->c_wb && x->g_pd->c_wb->w_visfn)
- (*x->g_pd->c_wb->w_visfn)(x, glist, flag);
+ (*x->g_pd->c_wb->w_visfn)(x, glist, flag);
}
int gobj_click(t_gobj *x, struct _glist *glist,
int xpix, int ypix, int shift, int alt, int dbl, int doit)
{
if (x->g_pd->c_wb && x->g_pd->c_wb->w_clickfn)
- return ((*x->g_pd->c_wb->w_clickfn)(x,
- glist, xpix, ypix, shift, alt, dbl, doit));
+ return ((*x->g_pd->c_wb->w_clickfn)(x,
+ glist, xpix, ypix, shift, alt, dbl, doit));
else return (0);
}
+void gobj_redraw(t_gobj *gobj, t_glist *glist)
+{
+ glist_redrawitem(glist, gobj);
+}
+
/* ------------------------ managing the selection ----------------- */
void glist_selectline(t_glist *x, t_outconnect *oc, int index1,
@@ -81,15 +88,15 @@ void glist_selectline(t_glist *x, t_outconnect *oc, int index1,
{
if (x->gl_editor)
{
- glist_noselect(x);
- x->gl_editor->e_selectedline = 1;
- x->gl_editor->e_selectline_index1 = index1;
- x->gl_editor->e_selectline_outno = outno;
- x->gl_editor->e_selectline_index2 = index2;
- x->gl_editor->e_selectline_inno = inno;
- x->gl_editor->e_selectline_tag = oc;
- sys_vgui(".x%x.c itemconfigure l%x -fill blue\n",
- x, x->gl_editor->e_selectline_tag);
+ glist_noselect(x);
+ x->gl_editor->e_selectedline = 1;
+ x->gl_editor->e_selectline_index1 = index1;
+ x->gl_editor->e_selectline_outno = outno;
+ x->gl_editor->e_selectline_index2 = index2;
+ x->gl_editor->e_selectline_inno = inno;
+ x->gl_editor->e_selectline_tag = oc;
+ sys_vgui(".x%lx.c itemconfigure l%lx -fill blue\n",
+ x, x->gl_editor->e_selectline_tag);
}
}
@@ -97,9 +104,9 @@ void glist_deselectline(t_glist *x)
{
if (x->gl_editor)
{
- x->gl_editor->e_selectedline = 0;
- sys_vgui(".x%x.c itemconfigure l%x -fill black\n",
- x, x->gl_editor->e_selectline_tag);
+ x->gl_editor->e_selectedline = 0;
+ sys_vgui(".x%lx.c itemconfigure l%lx -fill black\n",
+ x, x->gl_editor->e_selectline_tag);
}
}
@@ -107,9 +114,9 @@ int glist_isselected(t_glist *x, t_gobj *y)
{
if (x->gl_editor)
{
- t_selection *sel;
- for (sel = x->gl_editor->e_selection; sel; sel = sel->sel_next)
- if (sel->sel_what == y) return (1);
+ t_selection *sel;
+ for (sel = x->gl_editor->e_selection; sel; sel = sel->sel_next)
+ if (sel->sel_what == y) return (1);
}
return (0);
}
@@ -119,15 +126,15 @@ void glist_select(t_glist *x, t_gobj *y)
{
if (x->gl_editor)
{
- t_selection *sel = (t_selection *)getbytes(sizeof(*sel));
- if (x->gl_editor->e_selectedline)
- glist_deselectline(x);
- /* LATER #ifdef out the following check */
- if (glist_isselected(x, y)) bug("glist_select");
- sel->sel_next = x->gl_editor->e_selection;
- sel->sel_what = y;
- x->gl_editor->e_selection = sel;
- gobj_select(y, x, 1);
+ t_selection *sel = (t_selection *)getbytes(sizeof(*sel));
+ if (x->gl_editor->e_selectedline)
+ glist_deselectline(x);
+ /* LATER #ifdef out the following check */
+ if (glist_isselected(x, y)) bug("glist_select");
+ sel->sel_next = x->gl_editor->e_selection;
+ sel->sel_what = y;
+ x->gl_editor->e_selection = sel;
+ gobj_select(y, x, 1);
}
}
@@ -140,56 +147,56 @@ void glist_deselect(t_glist *x, t_gobj *y)
reenter = 1;
if (x->gl_editor)
{
- t_selection *sel, *sel2;
- t_rtext *z = 0;
- if (!glist_isselected(x, y)) bug("glist_deselect");
- if (x->gl_editor->e_textedfor)
- {
- t_rtext *fuddy = glist_findrtext(x, (t_text *)y);
- if (x->gl_editor->e_textedfor == fuddy)
- {
- if (x->gl_editor->e_textdirty)
- {
- z = fuddy;
- canvas_stowconnections(glist_getcanvas(x));
- }
- gobj_activate(y, x, 0);
- }
- if (zgetfn(&y->g_pd, gensym("dsp")))
- fixdsp = 1;
- }
- if ((sel = x->gl_editor->e_selection)->sel_what == y)
- {
- x->gl_editor->e_selection = x->gl_editor->e_selection->sel_next;
- gobj_select(sel->sel_what, x, 0);
- freebytes(sel, sizeof(*sel));
- }
- else
- {
- for (sel = x->gl_editor->e_selection; sel2 = sel->sel_next;
- sel = sel2)
- {
- if (sel2->sel_what == y)
- {
- sel->sel_next = sel2->sel_next;
- gobj_select(sel2->sel_what, x, 0);
- freebytes(sel2, sizeof(*sel2));
- break;
- }
- }
- }
- if (z)
- {
- char *buf;
- int bufsize;
-
- rtext_gettext(z, &buf, &bufsize);
- text_setto((t_text *)y, x, buf, bufsize);
- canvas_fixlinesfor(glist_getcanvas(x), (t_text *)y);
- x->gl_editor->e_textedfor = 0;
- }
- if (fixdsp)
- canvas_update_dsp();
+ t_selection *sel, *sel2;
+ t_rtext *z = 0;
+ if (!glist_isselected(x, y)) bug("glist_deselect");
+ if (x->gl_editor->e_textedfor)
+ {
+ t_rtext *fuddy = glist_findrtext(x, (t_text *)y);
+ if (x->gl_editor->e_textedfor == fuddy)
+ {
+ if (x->gl_editor->e_textdirty)
+ {
+ z = fuddy;
+ canvas_stowconnections(glist_getcanvas(x));
+ }
+ gobj_activate(y, x, 0);
+ }
+ if (zgetfn(&y->g_pd, gensym("dsp")))
+ fixdsp = canvas_suspend_dsp();
+ }
+ if ((sel = x->gl_editor->e_selection)->sel_what == y)
+ {
+ x->gl_editor->e_selection = x->gl_editor->e_selection->sel_next;
+ gobj_select(sel->sel_what, x, 0);
+ freebytes(sel, sizeof(*sel));
+ }
+ else
+ {
+ for (sel = x->gl_editor->e_selection; sel2 = sel->sel_next;
+ sel = sel2)
+ {
+ if (sel2->sel_what == y)
+ {
+ sel->sel_next = sel2->sel_next;
+ gobj_select(sel2->sel_what, x, 0);
+ freebytes(sel2, sizeof(*sel2));
+ break;
+ }
+ }
+ }
+ if (z)
+ {
+ char *buf;
+ int bufsize;
+
+ rtext_gettext(z, &buf, &bufsize);
+ text_setto((t_text *)y, x, buf, bufsize);
+ canvas_fixlinesfor(glist_getcanvas(x), (t_text *)y);
+ x->gl_editor->e_textedfor = 0;
+ }
+ if (fixdsp)
+ canvas_resume_dsp(1);
}
reenter = 0;
}
@@ -198,10 +205,10 @@ void glist_noselect(t_glist *x)
{
if (x->gl_editor)
{
- while (x->gl_editor->e_selection)
- glist_deselect(x, x->gl_editor->e_selection->sel_what);
- if (x->gl_editor->e_selectedline)
- glist_deselectline(x);
+ while (x->gl_editor->e_selection)
+ glist_deselect(x, x->gl_editor->e_selection->sel_what);
+ if (x->gl_editor->e_selectedline)
+ glist_deselectline(x);
}
}
@@ -209,24 +216,24 @@ void glist_selectall(t_glist *x)
{
if (x->gl_editor)
{
- glist_noselect(x);
- if (x->gl_list)
- {
- t_selection *sel = (t_selection *)getbytes(sizeof(*sel));
- t_gobj *y = x->gl_list;
- x->gl_editor->e_selection = sel;
- sel->sel_what = y;
- gobj_select(y, x, 1);
- while (y = y->g_next)
- {
- t_selection *sel2 = (t_selection *)getbytes(sizeof(*sel2));
- sel->sel_next = sel2;
- sel = sel2;
- sel->sel_what = y;
- gobj_select(y, x, 1);
- }
- sel->sel_next = 0;
- }
+ glist_noselect(x);
+ if (x->gl_list)
+ {
+ t_selection *sel = (t_selection *)getbytes(sizeof(*sel));
+ t_gobj *y = x->gl_list;
+ x->gl_editor->e_selection = sel;
+ sel->sel_what = y;
+ gobj_select(y, x, 1);
+ while (y = y->g_next)
+ {
+ t_selection *sel2 = (t_selection *)getbytes(sizeof(*sel2));
+ sel->sel_next = sel2;
+ sel = sel2;
+ sel->sel_what = y;
+ gobj_select(y, x, 1);
+ }
+ sel->sel_next = 0;
+ }
}
}
@@ -238,7 +245,7 @@ int glist_getindex(t_glist *x, t_gobj *y)
int indx;
for (y2 = x->gl_list, indx = 0; y2 && y2 != y; y2 = y2->g_next)
- indx++;
+ indx++;
return (indx);
}
@@ -251,8 +258,8 @@ int glist_selectionindex(t_glist *x, t_gobj *y, int selected)
int indx;
for (y2 = x->gl_list, indx = 0; y2 && y2 != y; y2 = y2->g_next)
- if (selected == glist_isselected(x, y2))
- indx++;
+ if (selected == glist_isselected(x, y2))
+ indx++;
return (indx);
}
@@ -261,16 +268,16 @@ static t_gobj *glist_nth(t_glist *x, int n)
t_gobj *y;
int indx;
for (y = x->gl_list, indx = 0; y; y = y->g_next, indx++)
- if (indx == n)
- return (y);
+ if (indx == n)
+ return (y);
return (0);
}
/* ------------------- support for undo/redo -------------------------- */
-static t_undofn canvas_undo_fn; /* current undo function if any */
-static int canvas_undo_whatnext; /* whether we can now UNDO or REDO */
-static void *canvas_undo_buf; /* data private to the undo function */
+static t_undofn canvas_undo_fn; /* current undo function if any */
+static int canvas_undo_whatnext; /* whether we can now UNDO or REDO */
+static void *canvas_undo_buf; /* data private to the undo function */
static t_canvas *canvas_undo_canvas; /* which canvas we can undo on */
static const char *canvas_undo_name;
@@ -278,12 +285,12 @@ void canvas_setundo(t_canvas *x, t_undofn undofn, void *buf,
const char *name)
{
int hadone = 0;
- /* blow away the old undo information. In one special case the
- old undo info is re-used; if so we shouldn't free it here. */
+ /* blow away the old undo information. In one special case the
+ old undo info is re-used; if so we shouldn't free it here. */
if (canvas_undo_fn && canvas_undo_buf && (buf != canvas_undo_buf))
{
- (*canvas_undo_fn)(canvas_undo_canvas, canvas_undo_buf, UNDO_FREE);
- hadone = 1;
+ (*canvas_undo_fn)(canvas_undo_canvas, canvas_undo_buf, UNDO_FREE);
+ hadone = 1;
}
canvas_undo_canvas = x;
canvas_undo_fn = undofn;
@@ -291,10 +298,10 @@ void canvas_setundo(t_canvas *x, t_undofn undofn, void *buf,
canvas_undo_whatnext = UNDO_UNDO;
canvas_undo_name = name;
if (x && glist_isvisible(x) && glist_istoplevel(x))
- /* enable undo in menu */
- sys_vgui("pdtk_undomenu .x%x %s no\n", x, name);
+ /* enable undo in menu */
+ sys_vgui("pdtk_undomenu .x%lx %s no\n", x, name);
else if (hadone)
- sys_vgui("pdtk_undomenu nobody no no\n");
+ sys_vgui("pdtk_undomenu nobody no no\n");
}
/* clear undo if it happens to be for the canvas x.
@@ -302,46 +309,46 @@ void canvas_setundo(t_canvas *x, t_undofn undofn, void *buf,
void canvas_noundo(t_canvas *x)
{
if (!x || (x == canvas_undo_canvas))
- canvas_setundo(0, 0, 0, "foo");
+ canvas_setundo(0, 0, 0, "foo");
}
static void canvas_undo(t_canvas *x)
{
if (x != canvas_undo_canvas)
- bug("canvas_undo 1");
+ bug("canvas_undo 1");
else if (canvas_undo_whatnext != UNDO_UNDO)
- bug("canvas_undo 2");
+ bug("canvas_undo 2");
else
{
- /* post("undo"); */
- (*canvas_undo_fn)(canvas_undo_canvas, canvas_undo_buf, UNDO_UNDO);
- /* enable redo in menu */
- if (glist_isvisible(x) && glist_istoplevel(x))
- sys_vgui("pdtk_undomenu .x%x no %s\n", x, canvas_undo_name);
- canvas_undo_whatnext = UNDO_REDO;
+ /* post("undo"); */
+ (*canvas_undo_fn)(canvas_undo_canvas, canvas_undo_buf, UNDO_UNDO);
+ /* enable redo in menu */
+ if (glist_isvisible(x) && glist_istoplevel(x))
+ sys_vgui("pdtk_undomenu .x%lx no %s\n", x, canvas_undo_name);
+ canvas_undo_whatnext = UNDO_REDO;
}
}
static void canvas_redo(t_canvas *x)
{
if (x != canvas_undo_canvas)
- bug("canvas_undo 1");
+ bug("canvas_undo 1");
else if (canvas_undo_whatnext != UNDO_REDO)
- bug("canvas_undo 2");
+ bug("canvas_undo 2");
else
{
- /* post("redo"); */
- (*canvas_undo_fn)(canvas_undo_canvas, canvas_undo_buf, UNDO_REDO);
- /* enable undo in menu */
- if (glist_isvisible(x) && glist_istoplevel(x))
- sys_vgui("pdtk_undomenu .x%x %s no\n", x, canvas_undo_name);
- canvas_undo_whatnext = UNDO_UNDO;
+ /* post("redo"); */
+ (*canvas_undo_fn)(canvas_undo_canvas, canvas_undo_buf, UNDO_REDO);
+ /* enable undo in menu */
+ if (glist_isvisible(x) && glist_istoplevel(x))
+ sys_vgui("pdtk_undomenu .x%lx %s no\n", x, canvas_undo_name);
+ canvas_undo_whatnext = UNDO_UNDO;
}
}
/* ------- specific undo methods: 1. connect and disconnect -------- */
-typedef struct _undo_connect
+typedef struct _undo_connect
{
int u_index1;
int u_outletno;
@@ -368,15 +375,15 @@ void canvas_disconnect(t_canvas *x,
linetraverser_start(&t, x);
while (oc = linetraverser_next(&t))
{
- int srcno = canvas_getindex(x, &t.tr_ob->ob_g);
- int sinkno = canvas_getindex(x, &t.tr_ob2->ob_g);
- if (srcno == index1 && t.tr_outno == outno &&
- sinkno == index2 && t.tr_inno == inno)
- {
- sys_vgui(".x%x.c delete l%x\n", x, oc);
- obj_disconnect(t.tr_ob, t.tr_outno, t.tr_ob2, t.tr_inno);
- break;
- }
+ int srcno = canvas_getindex(x, &t.tr_ob->ob_g);
+ int sinkno = canvas_getindex(x, &t.tr_ob2->ob_g);
+ if (srcno == index1 && t.tr_outno == outno &&
+ sinkno == index2 && t.tr_inno == inno)
+ {
+ sys_vgui(".x%lx.c delete l%lx\n", x, oc);
+ obj_disconnect(t.tr_ob, t.tr_outno, t.tr_ob2, t.tr_inno);
+ break;
+ }
}
}
@@ -385,16 +392,16 @@ static void canvas_undo_disconnect(t_canvas *x, void *z, int action)
t_undo_connect *buf = z;
if (action == UNDO_UNDO)
{
- canvas_connect(x, buf->u_index1, buf->u_outletno,
- buf->u_index2, buf->u_inletno);
+ canvas_connect(x, buf->u_index1, buf->u_outletno,
+ buf->u_index2, buf->u_inletno);
}
else if (action == UNDO_REDO)
{
- canvas_disconnect(x, buf->u_index1, buf->u_outletno,
- buf->u_index2, buf->u_inletno);
+ canvas_disconnect(x, buf->u_index1, buf->u_outletno,
+ buf->u_index2, buf->u_inletno);
}
else if (action == UNDO_FREE)
- t_freebytes(buf, sizeof(*buf));
+ t_freebytes(buf, sizeof(*buf));
}
/* connect just calls disconnect actions backward... */
@@ -408,25 +415,25 @@ static void canvas_undo_connect(t_canvas *x, void *z, int action)
{
int myaction;
if (action == UNDO_UNDO)
- myaction = UNDO_REDO;
+ myaction = UNDO_REDO;
else if (action == UNDO_REDO)
- myaction = UNDO_UNDO;
+ myaction = UNDO_UNDO;
else myaction = action;
canvas_undo_disconnect(x, z, myaction);
}
/* ---------- ... 2. cut, clear, and typing into objects: -------- */
-#define UCUT_CUT 1 /* operation was a cut */
-#define UCUT_CLEAR 2 /* .. a clear */
-#define UCUT_TEXT 3 /* text typed into a box */
+#define UCUT_CUT 1 /* operation was a cut */
+#define UCUT_CLEAR 2 /* .. a clear */
+#define UCUT_TEXT 3 /* text typed into a box */
-typedef struct _undo_cut
+typedef struct _undo_cut
{
- t_binbuf *u_objectbuf; /* the object cleared or typed into */
+ t_binbuf *u_objectbuf; /* the object cleared or typed into */
t_binbuf *u_reconnectbuf; /* connections into and out of object */
- t_binbuf *u_redotextbuf; /* buffer to paste back for redo if TEXT */
- int u_mode; /* from flags above */
+ t_binbuf *u_redotextbuf; /* buffer to paste back for redo if TEXT */
+ int u_mode; /* from flags above */
} t_undo_cut;
static void *canvas_undo_set_cut(t_canvas *x, int mode)
@@ -440,36 +447,36 @@ static void *canvas_undo_set_cut(t_canvas *x, int mode)
buf->u_mode = mode;
buf->u_redotextbuf = 0;
- /* store connections into/out of the selection */
+ /* store connections into/out of the selection */
buf->u_reconnectbuf = binbuf_new();
linetraverser_start(&t, x);
while (oc = linetraverser_next(&t))
{
- int issel1 = glist_isselected(x, &t.tr_ob->ob_g);
- int issel2 = glist_isselected(x, &t.tr_ob2->ob_g);
- if (issel1 != issel2)
- {
- binbuf_addv(buf->u_reconnectbuf, "ssiiii;",
- gensym("#X"), gensym("connect"),
- (issel1 ? nnotsel : 0)
- + glist_selectionindex(x, &t.tr_ob->ob_g, issel1),
- t.tr_outno,
- (issel2 ? nnotsel : 0) +
- glist_selectionindex(x, &t.tr_ob2->ob_g, issel2),
- t.tr_inno);
- }
+ int issel1 = glist_isselected(x, &t.tr_ob->ob_g);
+ int issel2 = glist_isselected(x, &t.tr_ob2->ob_g);
+ if (issel1 != issel2)
+ {
+ binbuf_addv(buf->u_reconnectbuf, "ssiiii;",
+ gensym("#X"), gensym("connect"),
+ (issel1 ? nnotsel : 0)
+ + glist_selectionindex(x, &t.tr_ob->ob_g, issel1),
+ t.tr_outno,
+ (issel2 ? nnotsel : 0) +
+ glist_selectionindex(x, &t.tr_ob2->ob_g, issel2),
+ t.tr_inno);
+ }
}
if (mode == UCUT_TEXT)
{
- buf->u_objectbuf = canvas_docopy(x);
+ buf->u_objectbuf = canvas_docopy(x);
}
else if (mode == UCUT_CUT)
{
- buf->u_objectbuf = 0;
+ buf->u_objectbuf = 0;
}
else if (mode == UCUT_CLEAR)
{
- buf->u_objectbuf = canvas_docopy(x);
+ buf->u_objectbuf = canvas_docopy(x);
}
return (buf);
}
@@ -480,72 +487,72 @@ static void canvas_undo_cut(t_canvas *x, void *z, int action)
int mode = buf->u_mode;
if (action == UNDO_UNDO)
{
- if (mode == UCUT_CUT)
- canvas_dopaste(x, copy_binbuf);
- else if (mode == UCUT_CLEAR)
- canvas_dopaste(x, buf->u_objectbuf);
- else if (mode == UCUT_TEXT)
- {
- t_gobj *y1, *y2;
- glist_noselect(x);
- for (y1 = x->gl_list; y2 = y1->g_next; y1 = y2)
- ;
- if (y1)
- {
- if (!buf->u_redotextbuf)
- {
- glist_noselect(x);
- glist_select(x, y1);
- buf->u_redotextbuf = canvas_docopy(x);
- glist_noselect(x);
- }
- glist_delete(x, y1);
- }
- canvas_dopaste(x, buf->u_objectbuf);
- }
- pd_bind(&x->gl_pd, gensym("#X"));
- binbuf_eval(buf->u_reconnectbuf, 0, 0, 0);
- pd_unbind(&x->gl_pd, gensym("#X"));
+ if (mode == UCUT_CUT)
+ canvas_dopaste(x, copy_binbuf);
+ else if (mode == UCUT_CLEAR)
+ canvas_dopaste(x, buf->u_objectbuf);
+ else if (mode == UCUT_TEXT)
+ {
+ t_gobj *y1, *y2;
+ glist_noselect(x);
+ for (y1 = x->gl_list; y2 = y1->g_next; y1 = y2)
+ ;
+ if (y1)
+ {
+ if (!buf->u_redotextbuf)
+ {
+ glist_noselect(x);
+ glist_select(x, y1);
+ buf->u_redotextbuf = canvas_docopy(x);
+ glist_noselect(x);
+ }
+ glist_delete(x, y1);
+ }
+ canvas_dopaste(x, buf->u_objectbuf);
+ }
+ pd_bind(&x->gl_pd, gensym("#X"));
+ binbuf_eval(buf->u_reconnectbuf, 0, 0, 0);
+ pd_unbind(&x->gl_pd, gensym("#X"));
}
else if (action == UNDO_REDO)
{
- if (mode == UCUT_CUT || mode == UCUT_CLEAR)
- canvas_doclear(x);
- else if (mode == UCUT_TEXT)
- {
- t_gobj *y1, *y2;
- for (y1 = x->gl_list; y2 = y1->g_next; y1 = y2)
- ;
- if (y1)
- glist_delete(x, y1);
- canvas_dopaste(x, buf->u_redotextbuf);
- pd_bind(&x->gl_pd, gensym("#X"));
- binbuf_eval(buf->u_reconnectbuf, 0, 0, 0);
- pd_unbind(&x->gl_pd, gensym("#X"));
- }
+ if (mode == UCUT_CUT || mode == UCUT_CLEAR)
+ canvas_doclear(x);
+ else if (mode == UCUT_TEXT)
+ {
+ t_gobj *y1, *y2;
+ for (y1 = x->gl_list; y2 = y1->g_next; y1 = y2)
+ ;
+ if (y1)
+ glist_delete(x, y1);
+ canvas_dopaste(x, buf->u_redotextbuf);
+ pd_bind(&x->gl_pd, gensym("#X"));
+ binbuf_eval(buf->u_reconnectbuf, 0, 0, 0);
+ pd_unbind(&x->gl_pd, gensym("#X"));
+ }
}
else if (action == UNDO_FREE)
{
- if (buf->u_objectbuf)
- binbuf_free(buf->u_objectbuf);
- if (buf->u_reconnectbuf)
- binbuf_free(buf->u_reconnectbuf);
- if (buf->u_redotextbuf)
- binbuf_free(buf->u_redotextbuf);
- t_freebytes(buf, sizeof(*buf));
+ if (buf->u_objectbuf)
+ binbuf_free(buf->u_objectbuf);
+ if (buf->u_reconnectbuf)
+ binbuf_free(buf->u_reconnectbuf);
+ if (buf->u_redotextbuf)
+ binbuf_free(buf->u_redotextbuf);
+ t_freebytes(buf, sizeof(*buf));
}
}
/* --------- 3. motion, including "tidy up" and stretching ----------- */
-typedef struct _undo_move_elem
+typedef struct _undo_move_elem
{
int e_index;
int e_xpix;
int e_ypix;
} t_undo_move_elem;
-typedef struct _undo_move
+typedef struct _undo_move
{
t_undo_move_elem *u_vec;
int u_n;
@@ -560,28 +567,28 @@ static void *canvas_undo_set_move(t_canvas *x, int selected)
t_undo_move *buf = (t_undo_move *)getbytes(sizeof(*buf));
buf->u_n = selected ? glist_selectionindex(x, 0, 1) : glist_getindex(x, 0);
buf->u_vec = (t_undo_move_elem *)getbytes(sizeof(*buf->u_vec) *
- (selected ? glist_selectionindex(x, 0, 1) : glist_getindex(x, 0)));
+ (selected ? glist_selectionindex(x, 0, 1) : glist_getindex(x, 0)));
if (selected)
{
- for (y = x->gl_list, i = indx = 0; y; y = y->g_next, indx++)
- if (glist_isselected(x, y))
- {
- gobj_getrect(y, x, &x1, &y1, &x2, &y2);
- buf->u_vec[i].e_index = indx;
- buf->u_vec[i].e_xpix = x1;
- buf->u_vec[i].e_ypix = y1;
- i++;
- }
+ for (y = x->gl_list, i = indx = 0; y; y = y->g_next, indx++)
+ if (glist_isselected(x, y))
+ {
+ gobj_getrect(y, x, &x1, &y1, &x2, &y2);
+ buf->u_vec[i].e_index = indx;
+ buf->u_vec[i].e_xpix = x1;
+ buf->u_vec[i].e_ypix = y1;
+ i++;
+ }
}
else
{
- for (y = x->gl_list, indx = 0; y; y = y->g_next, indx++)
- {
- gobj_getrect(y, x, &x1, &y1, &x2, &y2);
- buf->u_vec[indx].e_index = indx;
- buf->u_vec[indx].e_xpix = x1;
- buf->u_vec[indx].e_ypix = y1;
- }
+ for (y = x->gl_list, indx = 0; y; y = y->g_next, indx++)
+ {
+ gobj_getrect(y, x, &x1, &y1, &x2, &y2);
+ buf->u_vec[indx].e_index = indx;
+ buf->u_vec[indx].e_xpix = x1;
+ buf->u_vec[indx].e_ypix = y1;
+ }
}
canvas_undo_already_set_move = 1;
return (buf);
@@ -592,35 +599,35 @@ static void canvas_undo_move(t_canvas *x, void *z, int action)
t_undo_move *buf = z;
if (action == UNDO_UNDO || action == UNDO_REDO)
{
- int i;
- for (i = 0; i < buf->u_n; i++)
- {
- int x1, y1, x2, y2, newx, newy;
- t_gobj *y;
- newx = buf->u_vec[i].e_xpix;
- newy = buf->u_vec[i].e_ypix;
- y = glist_nth(x, buf->u_vec[i].e_index);
- if (y)
- {
- gobj_getrect(y, x, &x1, &y1, &x2, &y2);
- gobj_displace(y, x, newx-x1, newy - y1);
- buf->u_vec[i].e_xpix = x1;
- buf->u_vec[i].e_ypix = y1;
- }
- }
+ int i;
+ for (i = 0; i < buf->u_n; i++)
+ {
+ int x1, y1, x2, y2, newx, newy;
+ t_gobj *y;
+ newx = buf->u_vec[i].e_xpix;
+ newy = buf->u_vec[i].e_ypix;
+ y = glist_nth(x, buf->u_vec[i].e_index);
+ if (y)
+ {
+ gobj_getrect(y, x, &x1, &y1, &x2, &y2);
+ gobj_displace(y, x, newx-x1, newy - y1);
+ buf->u_vec[i].e_xpix = x1;
+ buf->u_vec[i].e_ypix = y1;
+ }
+ }
}
else if (action == UNDO_FREE)
{
- t_freebytes(buf->u_vec, buf->u_n * sizeof(*buf->u_vec));
- t_freebytes(buf, sizeof(*buf));
+ t_freebytes(buf->u_vec, buf->u_n * sizeof(*buf->u_vec));
+ t_freebytes(buf, sizeof(*buf));
}
}
/* --------- 4. paste (also duplicate) ----------- */
-typedef struct _undo_paste
+typedef struct _undo_paste
{
- int u_index; /* index of first object pasted */
+ int u_index; /* index of first object pasted */
} t_undo_paste;
static void *canvas_undo_set_paste(t_canvas *x)
@@ -635,23 +642,23 @@ static void canvas_undo_paste(t_canvas *x, void *z, int action)
t_undo_paste *buf = z;
if (action == UNDO_UNDO)
{
- t_gobj *y;
- glist_noselect(x);
- for (y = glist_nth(x, buf->u_index); y; y = y->g_next)
- glist_select(x, y);
- canvas_doclear(x);
+ t_gobj *y;
+ glist_noselect(x);
+ for (y = glist_nth(x, buf->u_index); y; y = y->g_next)
+ glist_select(x, y);
+ canvas_doclear(x);
}
else if (action == UNDO_REDO)
{
- t_selection *sel;
- canvas_dopaste(x, copy_binbuf);
- /* if it was "duplicate" have to re-enact the displacement. */
- if (canvas_undo_name && canvas_undo_name[0] == 'd')
- for (sel = x->gl_editor->e_selection; sel; sel = sel->sel_next)
- gobj_displace(sel->sel_what, x, 10, 10);
+ t_selection *sel;
+ canvas_dopaste(x, copy_binbuf);
+ /* if it was "duplicate" have to re-enact the displacement. */
+ if (canvas_undo_name && canvas_undo_name[0] == 'd')
+ for (sel = x->gl_editor->e_selection; sel; sel = sel->sel_next)
+ gobj_displace(sel->sel_what, x, 10, 10);
}
else if (action == UNDO_FREE)
- t_freebytes(buf, sizeof(*buf));
+ t_freebytes(buf, sizeof(*buf));
}
/* recursively check for abstractions to reload as result of a save.
@@ -664,33 +671,33 @@ static void glist_doreload(t_glist *gl, t_symbol *name, t_symbol *dir,
int i, nobj = glist_getindex(gl, 0); /* number of objects */
for (g = gl->gl_list, i = 0; g && i < nobj; i++)
{
- if (g != except && pd_class(&g->g_pd) == canvas_class &&
- canvas_isabstraction((t_canvas *)g) &&
- ((t_canvas *)g)->gl_name == name &&
- canvas_getdir((t_canvas *)g) == dir)
- {
- /* we're going to remake the object, so "g" will go stale.
- Get its index here, and afterward restore g. Also, the
- replacement will be at teh end of the list, so we don't
- do g = g->g_next in this case. */
- int j = glist_getindex(gl, g);
- if (!gl->gl_havewindow)
- canvas_vis(glist_getcanvas(gl), 1);
- glist_noselect(gl);
- glist_select(gl, g);
- canvas_setundo(gl, canvas_undo_cut,
- canvas_undo_set_cut(gl, UCUT_CLEAR), "clear");
- canvas_doclear(gl);
- canvas_undo(gl);
- glist_noselect(gl);
- g = glist_nth(gl, j);
- }
- else
- {
- if (g != except && pd_class(&g->g_pd) == canvas_class)
- glist_doreload((t_canvas *)g, name, dir, except);
- g = g->g_next;
- }
+ if (g != except && pd_class(&g->g_pd) == canvas_class &&
+ canvas_isabstraction((t_canvas *)g) &&
+ ((t_canvas *)g)->gl_name == name &&
+ canvas_getdir((t_canvas *)g) == dir)
+ {
+ /* we're going to remake the object, so "g" will go stale.
+ Get its index here, and afterward restore g. Also, the
+ replacement will be at teh end of the list, so we don't
+ do g = g->g_next in this case. */
+ int j = glist_getindex(gl, g);
+ if (!gl->gl_havewindow)
+ canvas_vis(glist_getcanvas(gl), 1);
+ glist_noselect(gl);
+ glist_select(gl, g);
+ canvas_setundo(gl, canvas_undo_cut,
+ canvas_undo_set_cut(gl, UCUT_CLEAR), "clear");
+ canvas_doclear(gl);
+ canvas_undo(gl);
+ glist_noselect(gl);
+ g = glist_nth(gl, j);
+ }
+ else
+ {
+ if (g != except && pd_class(&g->g_pd) == canvas_class)
+ glist_doreload((t_canvas *)g, name, dir, except);
+ g = g->g_next;
+ }
}
}
@@ -698,9 +705,9 @@ static void glist_doreload(t_glist *gl, t_symbol *name, t_symbol *dir,
void canvas_reload(t_symbol *name, t_symbol *dir, t_gobj *except)
{
t_canvas *x;
- /* find all root canvases */
+ /* find all root canvases */
for (x = canvas_list; x; x = x->gl_next)
- glist_doreload(x, name, dir, except);
+ glist_doreload(x, name, dir, except);
}
/* ------------------------ event handling ------------------------ */
@@ -715,16 +722,16 @@ void canvas_reload(t_symbol *name, t_symbol *dir, t_gobj *except)
static char *cursorlist[] = {
#ifdef MSW
- "right_ptr", /* CURSOR_RUNMODE_NOTHING */
+ "right_ptr", /* CURSOR_RUNMODE_NOTHING */
#else
- "left_ptr", /* CURSOR_RUNMODE_NOTHING */
+ "left_ptr", /* CURSOR_RUNMODE_NOTHING */
#endif
- "arrow", /* CURSOR_RUNMODE_CLICKME */
+ "arrow", /* CURSOR_RUNMODE_CLICKME */
"sb_v_double_arrow", /* CURSOR_RUNMODE_THICKEN */
- "plus", /* CURSOR_RUNMODE_ADDPOINT */
- "hand2", /* CURSOR_EDITMODE_NOTHING */
- "circle", /* CURSOR_EDITMODE_CONNECT */
- "X_cursor" /* CURSOR_EDITMODE_DISCONNECT */
+ "plus", /* CURSOR_RUNMODE_ADDPOINT */
+ "hand2", /* CURSOR_EDITMODE_NOTHING */
+ "circle", /* CURSOR_EDITMODE_CONNECT */
+ "X_cursor" /* CURSOR_EDITMODE_DISCONNECT */
};
void canvas_setcursor(t_canvas *x, unsigned int cursornum)
@@ -733,14 +740,14 @@ void canvas_setcursor(t_canvas *x, unsigned int cursornum)
static unsigned int cursorwas;
if (cursornum >= sizeof(cursorlist)/sizeof *cursorlist)
{
- bug("canvas_setcursor");
- return;
+ bug("canvas_setcursor");
+ return;
}
if (xwas != x || cursorwas != cursornum)
{
- sys_vgui(".x%x configure -cursor %s\n", x, cursorlist[cursornum]);
- xwas = x;
- cursorwas = cursornum;
+ sys_vgui(".x%lx configure -cursor %s\n", x, cursorlist[cursornum]);
+ xwas = x;
+ cursorwas = cursornum;
}
}
@@ -751,16 +758,16 @@ int canvas_hitbox(t_canvas *x, t_gobj *y, int xpos, int ypos,
int x1, y1, x2, y2;
t_text *ob;
if ((ob = pd_checkobject(&y->g_pd)) &&
- !text_shouldvis(ob, x))
- return (0);
+ !text_shouldvis(ob, x))
+ return (0);
gobj_getrect(y, x, &x1, &y1, &x2, &y2);
if (xpos >= x1 && xpos <= x2 && ypos >= y1 && ypos <= y2)
{
- *x1p = x1;
- *y1p = y1;
- *x2p = x2;
- *y2p = y2;
- return (1);
+ *x1p = x1;
+ *y1p = y1;
+ *x2p = x2;
+ *y2p = y2;
+ return (1);
}
else return (0);
}
@@ -772,8 +779,8 @@ static t_gobj *canvas_findhitbox(t_canvas *x, int xpos, int ypos,
t_gobj *y, *rval = 0;
for (y = x->gl_list; y; y = y->g_next)
{
- if (canvas_hitbox(x, y, xpos, ypos, x1p, y1p, x2p, y2p))
- rval = y;
+ if (canvas_hitbox(x, y, xpos, ypos, x1p, y1p, x2p, y2p))
+ rval = y;
}
return (rval);
}
@@ -784,8 +791,8 @@ static void canvas_rightclick(t_canvas *x, int xpos, int ypos, t_gobj *y)
int canprop, canopen;
canprop = (!y || (y && class_getpropertiesfn(pd_class(&y->g_pd))));
canopen = (y && zgetfn(&y->g_pd, gensym("menu-open")));
- sys_vgui("pdtk_canvas_popup .x%x %d %d %d %d\n",
- x, xpos, ypos, canprop, canopen);
+ sys_vgui("pdtk_canvas_popup .x%lx %d %d %d %d\n",
+ x, xpos, ypos, canprop, canopen);
}
/* tell GUI to create a properties dialog on the canvas. We tell
@@ -795,8 +802,8 @@ static void canvas_properties(t_glist *x)
{
char graphbuf[200];
sprintf(graphbuf, "pdtk_canvas_dialog %%s %g %g %g %g \n",
- glist_dpixtodx(x, 1), -glist_dpixtody(x, 1),
- (float)glist_isgraph(x), (float)x->gl_stretch);
+ glist_dpixtodx(x, 1), -glist_dpixtody(x, 1),
+ (float)glist_isgraph(x), (float)x->gl_stretch);
gfxstub_new(&x->gl_pd, x, graphbuf);
}
@@ -805,140 +812,140 @@ void canvas_setgraph(t_glist *x, int flag)
{
if (!flag && glist_isgraph(x))
{
- if (x->gl_owner && !x->gl_loading && glist_isvisible(x->gl_owner))
- gobj_vis(&x->gl_gobj, x->gl_owner, 0);
- x->gl_isgraph = 0;
- if (x->gl_owner && !x->gl_loading && glist_isvisible(x->gl_owner))
- {
- gobj_vis(&x->gl_gobj, x->gl_owner, 1);
- canvas_fixlinesfor(x->gl_owner, &x->gl_obj);
- }
+ if (x->gl_owner && !x->gl_loading && glist_isvisible(x->gl_owner))
+ gobj_vis(&x->gl_gobj, x->gl_owner, 0);
+ x->gl_isgraph = 0;
+ if (x->gl_owner && !x->gl_loading && glist_isvisible(x->gl_owner))
+ {
+ gobj_vis(&x->gl_gobj, x->gl_owner, 1);
+ canvas_fixlinesfor(x->gl_owner, &x->gl_obj);
+ }
}
else if (flag && !glist_isgraph(x))
{
- if (x->gl_pixwidth <= 0)
- x->gl_pixwidth = GLIST_DEFGRAPHWIDTH;
+ if (x->gl_pixwidth <= 0)
+ x->gl_pixwidth = GLIST_DEFGRAPHWIDTH;
- if (x->gl_pixheight <= 0)
- x->gl_pixheight = GLIST_DEFGRAPHHEIGHT;
+ if (x->gl_pixheight <= 0)
+ x->gl_pixheight = GLIST_DEFGRAPHHEIGHT;
- if (x->gl_owner && !x->gl_loading && glist_isvisible(x->gl_owner))
- gobj_vis(&x->gl_gobj, x->gl_owner, 0);
- x->gl_isgraph = 1;
- /* if (x->gl_owner && glist_isvisible(x->gl_owner))
- canvas_vis(x, 1); */
- if (x->gl_loading && x->gl_owner && glist_isvisible(x->gl_owner))
- canvas_create_editor(x, 1);
- if (x->gl_owner && !x->gl_loading && glist_isvisible(x->gl_owner))
- {
- gobj_vis(&x->gl_gobj, x->gl_owner, 1);
- canvas_fixlinesfor(x->gl_owner, &x->gl_obj);
- }
+ if (x->gl_owner && !x->gl_loading && glist_isvisible(x->gl_owner))
+ gobj_vis(&x->gl_gobj, x->gl_owner, 0);
+ x->gl_isgraph = 1;
+ /* if (x->gl_owner && glist_isvisible(x->gl_owner))
+ canvas_vis(x, 1); */
+ if (x->gl_loading && x->gl_owner && glist_isvisible(x->gl_owner))
+ canvas_create_editor(x, 1);
+ if (x->gl_owner && !x->gl_loading && glist_isvisible(x->gl_owner))
+ {
+ gobj_vis(&x->gl_gobj, x->gl_owner, 1);
+ canvas_fixlinesfor(x->gl_owner, &x->gl_obj);
+ }
}
}
/* called from the gui when "OK" is selected on the canvas properties
- dialog. Again we negate "y" scale. */
+ dialog. Again we negate "y" scale. */
static void canvas_donecanvasdialog(t_glist *x, t_floatarg xperpix,
t_floatarg yperpix, t_floatarg fgraphme)
{
int graphme = (fgraphme != 0), redraw = 0;
yperpix = -yperpix;
if (xperpix == 0)
- xperpix = 1;
+ xperpix = 1;
if (yperpix == 0)
- yperpix = 1;
+ yperpix = 1;
canvas_setgraph(x, graphme);
if (!x->gl_isgraph && (xperpix != glist_dpixtodx(x, 1)))
{
- if (xperpix > 0)
- {
- x->gl_x1 = 0;
- x->gl_x2 = xperpix;
- }
- else
- {
- x->gl_x1 = -xperpix * (x->gl_screenx2 - x->gl_screenx1);
- x->gl_x2 = x->gl_x1 + xperpix;
- }
- redraw = 1;
- }
+ if (xperpix > 0)
+ {
+ x->gl_x1 = 0;
+ x->gl_x2 = xperpix;
+ }
+ else
+ {
+ x->gl_x1 = -xperpix * (x->gl_screenx2 - x->gl_screenx1);
+ x->gl_x2 = x->gl_x1 + xperpix;
+ }
+ redraw = 1;
+ }
if (!x->gl_isgraph && (yperpix != glist_dpixtody(x, 1)))
{
- if (yperpix > 0)
- {
- x->gl_y1 = 0;
- x->gl_y2 = yperpix;
- }
- else
- {
- x->gl_y1 = -yperpix * (x->gl_screeny2 - x->gl_screeny1);
- x->gl_y2 = x->gl_y1 + yperpix;
- }
- redraw = 1;
+ if (yperpix > 0)
+ {
+ x->gl_y1 = 0;
+ x->gl_y2 = yperpix;
+ }
+ else
+ {
+ x->gl_y1 = -yperpix * (x->gl_screeny2 - x->gl_screeny1);
+ x->gl_y2 = x->gl_y1 + yperpix;
+ }
+ redraw = 1;
}
if (redraw)
- canvas_redraw(x);
+ canvas_redraw(x);
}
/* called from the gui when a popup menu comes back with "properties,"
- "open," or "help." */
+ "open," or "help." */
static void canvas_done_popup(t_canvas *x, float which, float xpos, float ypos)
{
char pathbuf[MAXPDSTRING], namebuf[MAXPDSTRING];
t_gobj *y;
for (y = x->gl_list; y; y = y->g_next)
{
- int x1, y1, x2, y2;
- if (canvas_hitbox(x, y, xpos, ypos, &x1, &y1, &x2, &y2))
- {
- if (which == 0) /* properties */
- {
- if (!class_getpropertiesfn(pd_class(&y->g_pd)))
- continue;
- (*class_getpropertiesfn(pd_class(&y->g_pd)))(y, x);
- return;
- }
- else if (which == 1) /* open */
- {
- if (!zgetfn(&y->g_pd, gensym("menu-open")))
- continue;
- vmess(&y->g_pd, gensym("menu-open"), "");
- return;
- }
- else /* help */
- {
- char *dir;
- if (pd_class(&y->g_pd) == canvas_class &&
- canvas_isabstraction((t_canvas *)y))
- {
- t_object *ob = (t_object *)y;
- int ac = binbuf_getnatom(ob->te_binbuf);
- t_atom *av = binbuf_getvec(ob->te_binbuf);
- if (ac < 1)
- return;
- atom_string(av, namebuf, MAXPDSTRING);
- dir = canvas_getdir((t_canvas *)y)->s_name;
- }
- else
- {
- strcpy(namebuf, class_gethelpname(pd_class(&y->g_pd)));
- dir = class_gethelpdir(pd_class(&y->g_pd));
- }
- if (strcmp(namebuf + strlen(namebuf) - 3, ".pd"))
- strcat(namebuf, ".pd");
- open_via_helppath(namebuf, dir);
- return;
- }
- }
+ int x1, y1, x2, y2;
+ if (canvas_hitbox(x, y, xpos, ypos, &x1, &y1, &x2, &y2))
+ {
+ if (which == 0) /* properties */
+ {
+ if (!class_getpropertiesfn(pd_class(&y->g_pd)))
+ continue;
+ (*class_getpropertiesfn(pd_class(&y->g_pd)))(y, x);
+ return;
+ }
+ else if (which == 1) /* open */
+ {
+ if (!zgetfn(&y->g_pd, gensym("menu-open")))
+ continue;
+ vmess(&y->g_pd, gensym("menu-open"), "");
+ return;
+ }
+ else /* help */
+ {
+ char *dir;
+ if (pd_class(&y->g_pd) == canvas_class &&
+ canvas_isabstraction((t_canvas *)y))
+ {
+ t_object *ob = (t_object *)y;
+ int ac = binbuf_getnatom(ob->te_binbuf);
+ t_atom *av = binbuf_getvec(ob->te_binbuf);
+ if (ac < 1)
+ return;
+ atom_string(av, namebuf, MAXPDSTRING);
+ dir = canvas_getdir((t_canvas *)y)->s_name;
+ }
+ else
+ {
+ strcpy(namebuf, class_gethelpname(pd_class(&y->g_pd)));
+ dir = class_gethelpdir(pd_class(&y->g_pd));
+ }
+ if (strcmp(namebuf + strlen(namebuf) - 3, ".pd"))
+ strcat(namebuf, ".pd");
+ open_via_helppath(namebuf, dir);
+ return;
+ }
+ }
}
if (which == 0)
- canvas_properties(x);
+ canvas_properties(x);
else if (which == 2)
{
- strcpy(pathbuf, sys_libdir->s_name);
- strcat(pathbuf, "/doc/5.reference/0.INTRO.txt");
- sys_vgui("menu_opentext %s\n", pathbuf);
+ strcpy(pathbuf, sys_libdir->s_name);
+ strcat(pathbuf, "/doc/5.reference/0.INTRO.txt");
+ sys_vgui("menu_opentext %s\n", pathbuf);
}
}
@@ -954,24 +961,22 @@ static void canvas_done_popup(t_canvas *x, float which, float xpos, float ypos)
#define SIMULATERIGHTCLICK
#endif
-#ifdef SIMULATERIGHTCLICK
static double canvas_upclicktime;
static int canvas_upx, canvas_upy;
#define DCLICKINTERVAL 0.25
-#endif
/* mouse click */
void canvas_doclick(t_canvas *x, int xpos, int ypos, int which,
int mod, int doit)
{
t_gobj *y;
- int shiftmod, runmode, altmod, rightclick;
+ int shiftmod, runmode, altmod, doublemod = 0, rightclick;
int x1, y1, x2, y2, clickreturned = 0;
if (!x->gl_editor)
{
- bug("editor");
- return;
+ bug("editor");
+ return;
}
shiftmod = (mod & SHIFTMOD);
@@ -981,188 +986,190 @@ void canvas_doclick(t_canvas *x, int xpos, int ypos, int which,
canvas_undo_already_set_move = 0;
- /* if keyboard was grabbed, notify grabber and cancel the grab */
+ /* if keyboard was grabbed, notify grabber and cancel the grab */
if (doit && x->gl_editor->e_grab && x->gl_editor->e_keyfn)
{
- (* x->gl_editor->e_keyfn) (x->gl_editor->e_grab, 0);
- glist_grab(x, 0, 0, 0, 0, 0);
+ (* x->gl_editor->e_keyfn) (x->gl_editor->e_grab, 0);
+ glist_grab(x, 0, 0, 0, 0, 0);
}
-#ifdef SIMULATERIGHTCLICK
if (doit && !runmode && xpos == canvas_upx && ypos == canvas_upy &&
- sys_getrealtime() - canvas_upclicktime < DCLICKINTERVAL)
- rightclick = 1;
+ sys_getrealtime() - canvas_upclicktime < DCLICKINTERVAL)
+#ifdef SIMULATERIGHTCLICK
+ rightclick = 1;
+#else
+ doublemod = 1;
#endif
-
x->gl_editor->e_lastmoved = 0;
if (doit)
{
- x->gl_editor->e_grab = 0;
- x->gl_editor->e_onmotion = MA_NONE;
+ x->gl_editor->e_grab = 0;
+ x->gl_editor->e_onmotion = MA_NONE;
}
/* post("click %d %d %d %d", xpos, ypos, which, mod); */
if (x->gl_editor->e_onmotion != MA_NONE)
- return;
+ return;
x->gl_editor->e_xwas = xpos;
x->gl_editor->e_ywas = ypos;
if (runmode && !rightclick)
{
- for (y = x->gl_list; y; y = y->g_next)
- {
- /* check if the object wants to be clicked */
- if (canvas_hitbox(x, y, xpos, ypos, &x1, &y1, &x2, &y2)
- && (clickreturned = gobj_click(y, x, xpos, ypos,
- shiftmod, altmod, 0, doit)))
- break;
- }
- if (!doit)
- {
- if (y)
- canvas_setcursor(x, clickreturned);
- else canvas_setcursor(x, CURSOR_RUNMODE_NOTHING);
- }
- return;
- }
- /* if not a runmode left click, fall here. */
+ for (y = x->gl_list; y; y = y->g_next)
+ {
+ /* check if the object wants to be clicked */
+ if (canvas_hitbox(x, y, xpos, ypos, &x1, &y1, &x2, &y2)
+ && (clickreturned = gobj_click(y, x, xpos, ypos,
+ shiftmod, altmod, 0, doit)))
+ break;
+ }
+ if (!doit)
+ {
+ if (y)
+ canvas_setcursor(x, clickreturned);
+ else canvas_setcursor(x, CURSOR_RUNMODE_NOTHING);
+ }
+ return;
+ }
+ /* if not a runmode left click, fall here. */
if (y = canvas_findhitbox(x, xpos, ypos, &x1, &y1, &x2, &y2))
{
- t_object *ob = pd_checkobject(&y->g_pd);
- /* check you're in the rectangle */
- ob = pd_checkobject(&y->g_pd);
- if (rightclick)
- canvas_rightclick(x, xpos, ypos, y);
- else if (shiftmod)
- {
- if (doit)
- {
- t_rtext *rt;
- if (ob && (rt = x->gl_editor->e_textedfor) &&
- rt == glist_findrtext(x, ob))
- {
- rtext_mouse(rt, xpos - x1, ypos - y1, RTEXT_SHIFT);
- x->gl_editor->e_onmotion = MA_DRAGTEXT;
- x->gl_editor->e_xwas = x1;
- x->gl_editor->e_ywas = y1;
- }
- else
- {
- if (glist_isselected(x, y))
- glist_deselect(x, y);
- else glist_select(x, y);
- }
- }
- }
- else
- {
- /* look for an outlet */
- int noutlet;
- if (ob && (noutlet = obj_noutlets(ob)) && ypos >= y2-4)
- {
- int width = x2 - x1;
- int nout1 = (noutlet > 1 ? noutlet - 1 : 1);
- int closest = ((xpos-x1) * (nout1) + width/2)/width;
- int hotspot = x1 +
- (width - IOWIDTH) * closest / (nout1);
- if (closest < noutlet &&
- xpos >= (hotspot-1) && xpos <= hotspot + (IOWIDTH+1))
- {
- if (doit)
- {
- int issignal = obj_issignaloutlet(ob, closest);
- x->gl_editor->e_onmotion = MA_CONNECT;
- x->gl_editor->e_xwas = xpos;
- x->gl_editor->e_ywas = ypos;
- sys_vgui(
- ".x%x.c create line %d %d %d %d -width %d -tags x\n",
- x, xpos, ypos, xpos, ypos,
- (issignal ? 2 : 1));
- }
- else canvas_setcursor(x, CURSOR_EDITMODE_CONNECT);
- }
- else if (doit)
- goto nooutletafterall;
- }
- /* not in an outlet; select and move */
- else if (doit)
- {
- t_rtext *rt;
- /* check if the box is being text edited */
- nooutletafterall:
- if (ob && (rt = x->gl_editor->e_textedfor) &&
- rt == glist_findrtext(x, ob))
- {
- rtext_mouse(rt, xpos - x1, ypos - y1, RTEXT_DOWN);
- x->gl_editor->e_onmotion = MA_DRAGTEXT;
- x->gl_editor->e_xwas = x1;
- x->gl_editor->e_ywas = y1;
- }
- else
- {
- /* otherwise select and drag to displace */
- if (!glist_isselected(x, y))
- {
- glist_noselect(x);
- glist_select(x, y);
- }
- x->gl_editor->e_onmotion = MA_MOVE;
- }
- }
- else canvas_setcursor(x, CURSOR_EDITMODE_NOTHING);
- }
- return;
- }
- /* if right click doesn't hit any boxes, call rightclick
- routine anyway */
+ t_object *ob = pd_checkobject(&y->g_pd);
+ /* check you're in the rectangle */
+ ob = pd_checkobject(&y->g_pd);
+ if (rightclick)
+ canvas_rightclick(x, xpos, ypos, y);
+ else if (shiftmod)
+ {
+ if (doit)
+ {
+ t_rtext *rt;
+ if (ob && (rt = x->gl_editor->e_textedfor) &&
+ rt == glist_findrtext(x, ob))
+ {
+ rtext_mouse(rt, xpos - x1, ypos - y1, RTEXT_SHIFT);
+ x->gl_editor->e_onmotion = MA_DRAGTEXT;
+ x->gl_editor->e_xwas = x1;
+ x->gl_editor->e_ywas = y1;
+ }
+ else
+ {
+ if (glist_isselected(x, y))
+ glist_deselect(x, y);
+ else glist_select(x, y);
+ }
+ }
+ }
+ else
+ {
+ /* look for an outlet */
+ int noutlet;
+ if (ob && (noutlet = obj_noutlets(ob)) && ypos >= y2-4)
+ {
+ int width = x2 - x1;
+ int nout1 = (noutlet > 1 ? noutlet - 1 : 1);
+ int closest = ((xpos-x1) * (nout1) + width/2)/width;
+ int hotspot = x1 +
+ (width - IOWIDTH) * closest / (nout1);
+ if (closest < noutlet &&
+ xpos >= (hotspot-1) && xpos <= hotspot + (IOWIDTH+1))
+ {
+ if (doit)
+ {
+ int issignal = obj_issignaloutlet(ob, closest);
+ x->gl_editor->e_onmotion = MA_CONNECT;
+ x->gl_editor->e_xwas = xpos;
+ x->gl_editor->e_ywas = ypos;
+ sys_vgui(
+ ".x%lx.c create line %d %d %d %d -width %d -tags x\n",
+ x, xpos, ypos, xpos, ypos,
+ (issignal ? 2 : 1));
+ }
+ else canvas_setcursor(x, CURSOR_EDITMODE_CONNECT);
+ }
+ else if (doit)
+ goto nooutletafterall;
+ }
+ /* not in an outlet; select and move */
+ else if (doit)
+ {
+ t_rtext *rt;
+ /* check if the box is being text edited */
+ nooutletafterall:
+ if (ob && (rt = x->gl_editor->e_textedfor) &&
+ rt == glist_findrtext(x, ob))
+ {
+ rtext_mouse(rt, xpos - x1, ypos - y1,
+ (doublemod ? RTEXT_DBL : RTEXT_DOWN));
+ x->gl_editor->e_onmotion = MA_DRAGTEXT;
+ x->gl_editor->e_xwas = x1;
+ x->gl_editor->e_ywas = y1;
+ }
+ else
+ {
+ /* otherwise select and drag to displace */
+ if (!glist_isselected(x, y))
+ {
+ glist_noselect(x);
+ glist_select(x, y);
+ }
+ x->gl_editor->e_onmotion = MA_MOVE;
+ }
+ }
+ else canvas_setcursor(x, CURSOR_EDITMODE_NOTHING);
+ }
+ return;
+ }
+ /* if right click doesn't hit any boxes, call rightclick
+ routine anyway */
if (rightclick)
- canvas_rightclick(x, xpos, ypos, 0);
+ canvas_rightclick(x, xpos, ypos, 0);
- /* if not an editing action, and if we didn't hit a
- box, set cursor and return */
+ /* if not an editing action, and if we didn't hit a
+ box, set cursor and return */
if (runmode || rightclick)
{
- canvas_setcursor(x, CURSOR_RUNMODE_NOTHING);
- return;
+ canvas_setcursor(x, CURSOR_RUNMODE_NOTHING);
+ return;
}
- /* having failed to find a box, we try lines now. */
+ /* having failed to find a box, we try lines now. */
if (!runmode && !altmod && !shiftmod)
{
- t_linetraverser t;
- t_outconnect *oc;
- float fx = xpos, fy = ypos;
- t_glist *glist2 = glist_getcanvas(x);
- linetraverser_start(&t, glist2);
- while (oc = linetraverser_next(&t))
- {
- float lx1 = t.tr_lx1, ly1 = t.tr_ly1,
- lx2 = t.tr_lx2, ly2 = t.tr_ly2;
- float area = (lx2 - lx1) * (fy - ly1) -
- (ly2 - ly1) * (fx - lx1);
- float dsquare = (lx2-lx1) * (lx2-lx1) + (ly2-ly1) * (ly2-ly1);
- if (area * area >= 50 * dsquare) continue;
- if ((lx2-lx1) * (fx-lx1) + (ly2-ly1) * (fy-ly1) < 0) continue;
- if ((lx2-lx1) * (lx2-fx) + (ly2-ly1) * (ly2-fy) < 0) continue;
- if (doit)
- {
- glist_selectline(glist2, oc,
- canvas_getindex(glist2, &t.tr_ob->ob_g), t.tr_outno,
- canvas_getindex(glist2, &t.tr_ob2->ob_g), t.tr_inno);
- }
- canvas_setcursor(x, CURSOR_EDITMODE_DISCONNECT);
- return;
- }
+ t_linetraverser t;
+ t_outconnect *oc;
+ float fx = xpos, fy = ypos;
+ t_glist *glist2 = glist_getcanvas(x);
+ linetraverser_start(&t, glist2);
+ while (oc = linetraverser_next(&t))
+ {
+ float lx1 = t.tr_lx1, ly1 = t.tr_ly1,
+ lx2 = t.tr_lx2, ly2 = t.tr_ly2;
+ float area = (lx2 - lx1) * (fy - ly1) -
+ (ly2 - ly1) * (fx - lx1);
+ float dsquare = (lx2-lx1) * (lx2-lx1) + (ly2-ly1) * (ly2-ly1);
+ if (area * area >= 50 * dsquare) continue;
+ if ((lx2-lx1) * (fx-lx1) + (ly2-ly1) * (fy-ly1) < 0) continue;
+ if ((lx2-lx1) * (lx2-fx) + (ly2-ly1) * (ly2-fy) < 0) continue;
+ if (doit)
+ {
+ glist_selectline(glist2, oc,
+ canvas_getindex(glist2, &t.tr_ob->ob_g), t.tr_outno,
+ canvas_getindex(glist2, &t.tr_ob2->ob_g), t.tr_inno);
+ }
+ canvas_setcursor(x, CURSOR_EDITMODE_DISCONNECT);
+ return;
+ }
}
canvas_setcursor(x, CURSOR_EDITMODE_NOTHING);
if (doit)
{
- if (!shiftmod) glist_noselect(x);
- sys_vgui(".x%x.c create rectangle %d %d %d %d -tags x\n",
- x, xpos, ypos, xpos, ypos);
- x->gl_editor->e_xwas = xpos;
- x->gl_editor->e_ywas = ypos;
- x->gl_editor->e_onmotion = MA_REGION;
+ if (!shiftmod) glist_noselect(x);
+ sys_vgui(".x%lx.c create rectangle %d %d %d %d -tags x\n",
+ x, xpos, ypos, xpos, ypos);
+ x->gl_editor->e_xwas = xpos;
+ x->gl_editor->e_ywas = ypos;
+ x->gl_editor->e_onmotion = MA_REGION;
}
}
@@ -1179,9 +1186,9 @@ int canvas_isconnected (t_canvas *x, t_text *ob1, int n1,
t_outconnect *oc;
linetraverser_start(&t, x);
while (oc = linetraverser_next(&t))
- if (t.tr_ob == ob1 && t.tr_outno == n1 &&
- t.tr_ob2 == ob2 && t.tr_inno == n2)
- return (1);
+ if (t.tr_ob == ob1 && t.tr_outno == n1 &&
+ t.tr_ob2 == ob2 && t.tr_inno == n2)
+ return (1);
return (0);
}
@@ -1192,85 +1199,85 @@ void canvas_doconnect(t_canvas *x, int xpos, int ypos, int which, int doit)
int x21, y21, x22, y22;
t_gobj *y2;
int xwas = x->gl_editor->e_xwas,
- ywas = x->gl_editor->e_ywas;
- if (doit) sys_vgui(".x%x.c delete x\n", x);
- else sys_vgui(".x%x.c coords x %d %d %d %d\n",
- x, x->gl_editor->e_xwas,
- x->gl_editor->e_ywas, xpos, ypos);
+ ywas = x->gl_editor->e_ywas;
+ if (doit) sys_vgui(".x%lx.c delete x\n", x);
+ else sys_vgui(".x%lx.c coords x %d %d %d %d\n",
+ x, x->gl_editor->e_xwas,
+ x->gl_editor->e_ywas, xpos, ypos);
if ((y1 = canvas_findhitbox(x, xwas, ywas, &x11, &y11, &x12, &y12))
- && (y2 = canvas_findhitbox(x, xpos, ypos, &x21, &y21, &x22, &y22)))
- {
- t_object *ob1 = pd_checkobject(&y1->g_pd);
- t_object *ob2 = pd_checkobject(&y2->g_pd);
- int noutlet1, ninlet2;
- if (ob1 && ob2 && ob1 != ob2 &&
- (noutlet1 = obj_noutlets(ob1))
- && (ninlet2 = obj_ninlets(ob2)))
- {
- int width1 = x12 - x11, closest1, hotspot1;
- int width2 = x22 - x21, closest2, hotspot2;
- int lx1, lx2, ly1, ly2;
- t_outconnect *oc;
-
- if (noutlet1 > 1)
- {
- closest1 = ((xwas-x11) * (noutlet1-1) + width1/2)/width1;
- hotspot1 = x11 +
- (width1 - IOWIDTH) * closest1 / (noutlet1-1);
- }
- else closest1 = 0, hotspot1 = x11;
-
- if (ninlet2 > 1)
- {
- closest2 = ((xpos-x21) * (ninlet2-1) + width2/2)/width2;
- hotspot2 = x21 +
- (width2 - IOWIDTH) * closest2 / (ninlet2-1);
- }
- else closest2 = 0, hotspot2 = x21;
-
- if (closest1 >= noutlet1)
- closest1 = noutlet1 - 1;
- if (closest2 >= ninlet2)
- closest2 = ninlet2 - 1;
-
- if (canvas_isconnected (x, ob1, closest1, ob2, closest2))
- {
- canvas_setcursor(x, CURSOR_EDITMODE_NOTHING);
- return;
- }
- if (obj_issignaloutlet(ob1, closest1) &&
- !obj_issignalinlet(ob2, closest2))
- {
- if (doit)
- error("can't connect signal outlet to control inlet");
- canvas_setcursor(x, CURSOR_EDITMODE_NOTHING);
- return;
- }
- if (doit)
- {
- oc = obj_connect(ob1, closest1, ob2, closest2);
- lx1 = x11 + (noutlet1 > 1 ?
- ((x12-x11-IOWIDTH) * closest1)/(noutlet1-1) : 0)
- + IOMIDDLE;
- ly1 = y12;
- lx2 = x21 + (ninlet2 > 1 ?
- ((x22-x21-IOWIDTH) * closest2)/(ninlet2-1) : 0)
- + IOMIDDLE;
- ly2 = y21;
- sys_vgui(".x%x.c create line %d %d %d %d -width %d -tags l%x\n",
- glist_getcanvas(x),
- lx1, ly1, lx2, ly2,
- (obj_issignaloutlet(ob1, closest1) ? 2 : 1), oc);
- canvas_setundo(x, canvas_undo_connect,
- canvas_undo_set_connect(x,
- canvas_getindex(x, &ob1->ob_g), closest1,
- canvas_getindex(x, &ob2->ob_g), closest2),
- "connect");
- }
- else canvas_setcursor(x, CURSOR_EDITMODE_CONNECT);
- return;
- }
+ && (y2 = canvas_findhitbox(x, xpos, ypos, &x21, &y21, &x22, &y22)))
+ {
+ t_object *ob1 = pd_checkobject(&y1->g_pd);
+ t_object *ob2 = pd_checkobject(&y2->g_pd);
+ int noutlet1, ninlet2;
+ if (ob1 && ob2 && ob1 != ob2 &&
+ (noutlet1 = obj_noutlets(ob1))
+ && (ninlet2 = obj_ninlets(ob2)))
+ {
+ int width1 = x12 - x11, closest1, hotspot1;
+ int width2 = x22 - x21, closest2, hotspot2;
+ int lx1, lx2, ly1, ly2;
+ t_outconnect *oc;
+
+ if (noutlet1 > 1)
+ {
+ closest1 = ((xwas-x11) * (noutlet1-1) + width1/2)/width1;
+ hotspot1 = x11 +
+ (width1 - IOWIDTH) * closest1 / (noutlet1-1);
+ }
+ else closest1 = 0, hotspot1 = x11;
+
+ if (ninlet2 > 1)
+ {
+ closest2 = ((xpos-x21) * (ninlet2-1) + width2/2)/width2;
+ hotspot2 = x21 +
+ (width2 - IOWIDTH) * closest2 / (ninlet2-1);
+ }
+ else closest2 = 0, hotspot2 = x21;
+
+ if (closest1 >= noutlet1)
+ closest1 = noutlet1 - 1;
+ if (closest2 >= ninlet2)
+ closest2 = ninlet2 - 1;
+
+ if (canvas_isconnected (x, ob1, closest1, ob2, closest2))
+ {
+ canvas_setcursor(x, CURSOR_EDITMODE_NOTHING);
+ return;
+ }
+ if (obj_issignaloutlet(ob1, closest1) &&
+ !obj_issignalinlet(ob2, closest2))
+ {
+ if (doit)
+ error("can't connect signal outlet to control inlet");
+ canvas_setcursor(x, CURSOR_EDITMODE_NOTHING);
+ return;
+ }
+ if (doit)
+ {
+ oc = obj_connect(ob1, closest1, ob2, closest2);
+ lx1 = x11 + (noutlet1 > 1 ?
+ ((x12-x11-IOWIDTH) * closest1)/(noutlet1-1) : 0)
+ + IOMIDDLE;
+ ly1 = y12;
+ lx2 = x21 + (ninlet2 > 1 ?
+ ((x22-x21-IOWIDTH) * closest2)/(ninlet2-1) : 0)
+ + IOMIDDLE;
+ ly2 = y21;
+ sys_vgui(".x%lx.c create line %d %d %d %d -width %d -tags l%lx\n",
+ glist_getcanvas(x),
+ lx1, ly1, lx2, ly2,
+ (obj_issignaloutlet(ob1, closest1) ? 2 : 1), oc);
+ canvas_setundo(x, canvas_undo_connect,
+ canvas_undo_set_connect(x,
+ canvas_getindex(x, &ob1->ob_g), closest1,
+ canvas_getindex(x, &ob2->ob_g), closest2),
+ "connect");
+ }
+ else canvas_setcursor(x, CURSOR_EDITMODE_CONNECT);
+ return;
+ }
}
canvas_setcursor(x, CURSOR_EDITMODE_NOTHING);
}
@@ -1280,11 +1287,11 @@ void canvas_selectinrect(t_canvas *x, int lox, int loy, int hix, int hiy)
t_gobj *y;
for (y = x->gl_list; y; y = y->g_next)
{
- int x1, y1, x2, y2;
- gobj_getrect(y, x, &x1, &y1, &x2, &y2);
- if (hix >= x1 && lox <= x2 && hiy >= y1 && loy <= y2
- && !glist_isselected(x, y))
- glist_select(x, y);
+ int x1, y1, x2, y2;
+ gobj_getrect(y, x, &x1, &y1, &x2, &y2);
+ if (hix >= x1 && lox <= x2 && hiy >= y1 && loy <= y2
+ && !glist_isselected(x, y))
+ glist_select(x, y);
}
}
@@ -1292,20 +1299,20 @@ static void canvas_doregion(t_canvas *x, int xpos, int ypos, int doit)
{
if (doit)
{
- int lox, loy, hix, hiy;
- if (x->gl_editor->e_xwas < xpos)
- lox = x->gl_editor->e_xwas, hix = xpos;
- else hix = x->gl_editor->e_xwas, lox = xpos;
- if (x->gl_editor->e_ywas < ypos)
- loy = x->gl_editor->e_ywas, hiy = ypos;
- else hiy = x->gl_editor->e_ywas, loy = ypos;
- canvas_selectinrect(x, lox, loy, hix, hiy);
- sys_vgui(".x%x.c delete x\n", x);
- x->gl_editor->e_onmotion = 0;
+ int lox, loy, hix, hiy;
+ if (x->gl_editor->e_xwas < xpos)
+ lox = x->gl_editor->e_xwas, hix = xpos;
+ else hix = x->gl_editor->e_xwas, lox = xpos;
+ if (x->gl_editor->e_ywas < ypos)
+ loy = x->gl_editor->e_ywas, hiy = ypos;
+ else hiy = x->gl_editor->e_ywas, loy = ypos;
+ canvas_selectinrect(x, lox, loy, hix, hiy);
+ sys_vgui(".x%lx.c delete x\n", x);
+ x->gl_editor->e_onmotion = 0;
}
- else sys_vgui(".x%x.c coords x %d %d %d %d\n",
- x, x->gl_editor->e_xwas,
- x->gl_editor->e_ywas, xpos, ypos);
+ else sys_vgui(".x%lx.c coords x %d %d %d %d\n",
+ x, x->gl_editor->e_xwas,
+ x->gl_editor->e_ywas, xpos, ypos);
}
void canvas_mouseup(t_canvas *x,
@@ -1315,29 +1322,28 @@ void canvas_mouseup(t_canvas *x,
/* post("mouseup %d %d %d", xpos, ypos, which); */
if (!x->gl_editor)
{
- bug("editor");
- return;
+ bug("editor");
+ return;
}
-#ifdef SIMULATERIGHTCLICK
+
canvas_upclicktime = sys_getrealtime();
canvas_upx = xpos;
canvas_upy = ypos;
-#endif
if (x->gl_editor->e_onmotion == MA_CONNECT)
- canvas_doconnect(x, xpos, ypos, which, 1);
+ canvas_doconnect(x, xpos, ypos, which, 1);
else if (x->gl_editor->e_onmotion == MA_REGION)
- canvas_doregion(x, xpos, ypos, 1);
+ canvas_doregion(x, xpos, ypos, 1);
else if (x->gl_editor->e_onmotion == MA_MOVE)
{
- /* after motion, if there's only one item selected, activate it */
- if (x->gl_editor->e_selection &&
- !(x->gl_editor->e_selection->sel_next))
- gobj_activate(x->gl_editor->e_selection->sel_what,
- x, 1);
+ /* after motion, if there's only one item selected, activate it */
+ if (x->gl_editor->e_selection &&
+ !(x->gl_editor->e_selection->sel_next))
+ gobj_activate(x->gl_editor->e_selection->sel_what,
+ x, 1);
}
else if (x->gl_editor->e_onmotion == MA_PASSOUT)
- x->gl_editor->e_onmotion = 0;
+ x->gl_editor->e_onmotion = 0;
x->gl_editor->e_onmotion = MA_NONE;
}
@@ -1348,16 +1354,16 @@ static void canvas_displaceselection(t_canvas *x, int dx, int dy)
int resortin = 0, resortout = 0;
if (!canvas_undo_already_set_move)
{
- canvas_setundo(x, canvas_undo_move, canvas_undo_set_move(x, 1),
- "motion");
- canvas_undo_already_set_move = 1;
+ canvas_setundo(x, canvas_undo_move, canvas_undo_set_move(x, 1),
+ "motion");
+ canvas_undo_already_set_move = 1;
}
for (y = x->gl_editor->e_selection; y; y = y->sel_next)
{
- t_class *cl = pd_class(&y->sel_what->g_pd);
- gobj_displace(y->sel_what, x, dx, dy);
- if (cl == vinlet_class) resortin = 1;
- else if (cl == voutlet_class) resortout = 1;
+ t_class *cl = pd_class(&y->sel_what->g_pd);
+ gobj_displace(y->sel_what, x, dx, dy);
+ if (cl == vinlet_class) resortin = 1;
+ else if (cl == voutlet_class) resortout = 1;
}
if (resortin) canvas_resortinlets(x);
if (resortout) canvas_resortoutlets(x);
@@ -1366,117 +1372,122 @@ static void canvas_displaceselection(t_canvas *x, int dx, int dy)
/* this routine is called whenever a key is pressed or released. "x"
may be zero if there's no current canvas. The first argument is true or
- fals for down/up; the second one is either a symbolic key name (e.g.,
- "Right" or an Ascii key number. */
+ false for down/up; the second one is either a symbolic key name (e.g.,
+ "Right" or an Ascii key number. The third is the shift key. */
void canvas_key(t_canvas *x, t_symbol *s, int ac, t_atom *av)
{
static t_symbol *keynumsym, *keyupsym, *keynamesym;
int keynum, fflag;
t_symbol *gotkeysym;
-
+
int down, shift;
if (ac < 3)
- return;
- if (!x->gl_editor)
- {
- bug("editor");
- return;
- }
+ return;
+ if (!x || !x->gl_editor)
+ return;
canvas_undo_already_set_move = 0;
down = (atom_getfloat(av) != 0); /* nonzero if it's a key down */
shift = (atom_getfloat(av+2) != 0); /* nonzero if shift-ed */
if (av[1].a_type == A_SYMBOL)
- gotkeysym = av[1].a_w.w_symbol;
+ gotkeysym = av[1].a_w.w_symbol;
else if (av[1].a_type == A_FLOAT)
{
- char buf[3];
- sprintf(buf, "%c", (int)(av[1].a_w.w_float));
- gotkeysym = gensym(buf);
+ char buf[3];
+ sprintf(buf, "%c", (int)(av[1].a_w.w_float));
+ gotkeysym = gensym(buf);
}
else gotkeysym = gensym("?");
fflag = (av[0].a_type == A_FLOAT ? av[0].a_w.w_float : 0);
keynum = (av[1].a_type == A_FLOAT ? av[1].a_w.w_float : 0);
if (keynum == '\\' || keynum == '{' || keynum == '}')
{
- post("%c: dropped", (int)keynum);
- return;
+ post("%c: dropped", (int)keynum);
+ return;
}
+#if 0
+ post("keynum %d, down %d", (int)keynum, down);
+#endif
if (keynum == '\r') keynum = '\n';
if (av[1].a_type == A_SYMBOL &&
- !strcmp(av[1].a_w.w_symbol->s_name, "Return"))
- keynum = '\n';
+ !strcmp(av[1].a_w.w_symbol->s_name, "Return"))
+ keynum = '\n';
if (!keynumsym)
{
- keynumsym = gensym("#key");
- keyupsym = gensym("#keyup");
- keynamesym = gensym("#keyname");
+ keynumsym = gensym("#key");
+ keyupsym = gensym("#keyup");
+ keynamesym = gensym("#keyname");
}
#ifdef MACOSX
- if (keynum == 30)
- keynum = 0, gotkeysym = gensym("Up");
- else if (keynum == 31)
- keynum = 0, gotkeysym = gensym("Down");
- else if (keynum == 28)
- keynum = 0, gotkeysym = gensym("Left");
- else if (keynum == 29)
- keynum = 0, gotkeysym = gensym("Right");
+ if (keynum == 30)
+ keynum = 0, gotkeysym = gensym("Up");
+ else if (keynum == 31)
+ keynum = 0, gotkeysym = gensym("Down");
+ else if (keynum == 28)
+ keynum = 0, gotkeysym = gensym("Left");
+ else if (keynum == 29)
+ keynum = 0, gotkeysym = gensym("Right");
#endif
if (keynumsym->s_thing && down)
- pd_float(keynumsym->s_thing, (float)keynum);
+ pd_float(keynumsym->s_thing, (float)keynum);
if (keyupsym->s_thing && !down)
- pd_float(keyupsym->s_thing, (float)keynum);
+ pd_float(keyupsym->s_thing, (float)keynum);
if (keynamesym->s_thing)
{
- t_atom at[2];
- at[0] = av[0];
- SETFLOAT(at, down);
- SETSYMBOL(at+1, gotkeysym);
- pd_list(keynamesym->s_thing, 0, 2, at);
+ t_atom at[2];
+ at[0] = av[0];
+ SETFLOAT(at, down);
+ SETSYMBOL(at+1, gotkeysym);
+ pd_list(keynamesym->s_thing, 0, 2, at);
}
- if (!x->gl_editor) /* if that 'invis'ed the window, we'd better stop. */
- return;
+ if (!x->gl_editor) /* if that 'invis'ed the window, we'd better stop. */
+ return;
if (x && down)
{
- /* if an object has "grabbed" keys just send them on */
- if (x->gl_editor->e_grab
- && x->gl_editor->e_keyfn && keynum)
- (* x->gl_editor->e_keyfn)
- (x->gl_editor->e_grab, (float)keynum);
- /* if a text editor is open send it on */
- else if (x->gl_editor->e_textedfor)
- {
- if (!x->gl_editor->e_textdirty)
- {
- canvas_setundo(x, canvas_undo_cut,
- canvas_undo_set_cut(x, UCUT_TEXT), "typing");
- }
- rtext_key(x->gl_editor->e_textedfor,
- (int)keynum, gotkeysym);
- if (x->gl_editor->e_textdirty)
- canvas_dirty(x, 1);
- }
- /* check for backspace or clear */
- else if (keynum == 8 || keynum == 127)
- {
- if (x->gl_editor->e_selectedline)
- canvas_clearline(x);
- else if (x->gl_editor->e_selection)
- {
- canvas_setundo(x, canvas_undo_cut,
- canvas_undo_set_cut(x, UCUT_CLEAR), "clear");
- canvas_doclear(x);
- }
- }
- /* check for arrow keys */
- else if (!strcmp(gotkeysym->s_name, "Up"))
- canvas_displaceselection(x, 0, shift ? -10 : -1);
- else if (!strcmp(gotkeysym->s_name, "Down"))
- canvas_displaceselection(x, 0, shift ? 10 : 1);
- else if (!strcmp(gotkeysym->s_name, "Left"))
- canvas_displaceselection(x, shift ? -10 : -1, 0);
- else if (!strcmp(gotkeysym->s_name, "Right"))
- canvas_displaceselection(x, shift ? 10 : 1, 0);
+ /* if an object has "grabbed" keys just send them on */
+ if (x->gl_editor->e_grab
+ && x->gl_editor->e_keyfn && keynum)
+ (* x->gl_editor->e_keyfn)
+ (x->gl_editor->e_grab, (float)keynum);
+ /* if a text editor is open send the key on, as long as
+ it is either "real" (has a key number) or else is an arrow key. */
+ else if (x->gl_editor->e_textedfor && (keynum
+ || !strcmp(gotkeysym->s_name, "Up")
+ || !strcmp(gotkeysym->s_name, "Down")
+ || !strcmp(gotkeysym->s_name, "Left")
+ || !strcmp(gotkeysym->s_name, "Right")))
+ {
+ if (!x->gl_editor->e_textdirty)
+ {
+ canvas_setundo(x, canvas_undo_cut,
+ canvas_undo_set_cut(x, UCUT_TEXT), "typing");
+ }
+ rtext_key(x->gl_editor->e_textedfor,
+ (int)keynum, gotkeysym);
+ if (x->gl_editor->e_textdirty)
+ canvas_dirty(x, 1);
+ }
+ /* check for backspace or clear */
+ else if (keynum == 8 || keynum == 127)
+ {
+ if (x->gl_editor->e_selectedline)
+ canvas_clearline(x);
+ else if (x->gl_editor->e_selection)
+ {
+ canvas_setundo(x, canvas_undo_cut,
+ canvas_undo_set_cut(x, UCUT_CLEAR), "clear");
+ canvas_doclear(x);
+ }
+ }
+ /* check for arrow keys */
+ else if (!strcmp(gotkeysym->s_name, "Up"))
+ canvas_displaceselection(x, 0, shift ? -10 : -1);
+ else if (!strcmp(gotkeysym->s_name, "Down"))
+ canvas_displaceselection(x, 0, shift ? 10 : 1);
+ else if (!strcmp(gotkeysym->s_name, "Left"))
+ canvas_displaceselection(x, shift ? -10 : -1, 0);
+ else if (!strcmp(gotkeysym->s_name, "Right"))
+ canvas_displaceselection(x, shift ? 10 : 1, 0);
}
}
@@ -1487,37 +1498,37 @@ void canvas_motion(t_canvas *x, t_floatarg xpos, t_floatarg ypos,
int mod = fmod;
if (!x->gl_editor)
{
- bug("editor");
- return;
+ bug("editor");
+ return;
}
glist_setlastxy(x, xpos, ypos);
if (x->gl_editor->e_onmotion == MA_MOVE)
{
- canvas_displaceselection(x,
- xpos - x->gl_editor->e_xwas, ypos - x->gl_editor->e_ywas);
- x->gl_editor->e_xwas = xpos;
- x->gl_editor->e_ywas = ypos;
+ canvas_displaceselection(x,
+ xpos - x->gl_editor->e_xwas, ypos - x->gl_editor->e_ywas);
+ x->gl_editor->e_xwas = xpos;
+ x->gl_editor->e_ywas = ypos;
}
else if (x->gl_editor->e_onmotion == MA_REGION)
- canvas_doregion(x, xpos, ypos, 0);
+ canvas_doregion(x, xpos, ypos, 0);
else if (x->gl_editor->e_onmotion == MA_CONNECT)
- canvas_doconnect(x, xpos, ypos, 0, 0);
+ canvas_doconnect(x, xpos, ypos, 0, 0);
else if (x->gl_editor->e_onmotion == MA_PASSOUT)
{
- if (!x->gl_editor->e_motionfn)
- bug("e_motionfn");
- (*x->gl_editor->e_motionfn)(&x->gl_editor->e_grab->g_pd,
- xpos - x->gl_editor->e_xwas,
- ypos - x->gl_editor->e_ywas);
- x->gl_editor->e_xwas = xpos;
- x->gl_editor->e_ywas = ypos;
+ if (!x->gl_editor->e_motionfn)
+ bug("e_motionfn");
+ (*x->gl_editor->e_motionfn)(&x->gl_editor->e_grab->g_pd,
+ xpos - x->gl_editor->e_xwas,
+ ypos - x->gl_editor->e_ywas);
+ x->gl_editor->e_xwas = xpos;
+ x->gl_editor->e_ywas = ypos;
}
else if (x->gl_editor->e_onmotion == MA_DRAGTEXT)
{
- t_rtext *rt = x->gl_editor->e_textedfor;
- if (rt)
- rtext_mouse(rt, xpos - x->gl_editor->e_xwas,
- ypos - x->gl_editor->e_ywas, RTEXT_DRAG);
+ t_rtext *rt = x->gl_editor->e_textedfor;
+ if (rt)
+ rtext_mouse(rt, xpos - x->gl_editor->e_xwas,
+ ypos - x->gl_editor->e_ywas, RTEXT_DRAG);
}
else canvas_doclick(x, xpos, ypos, 0, mod, 0);
@@ -1539,18 +1550,18 @@ void canvas_startmotion(t_canvas *x)
void canvas_print(t_canvas *x, t_symbol *s)
{
- if (*s->s_name) sys_vgui(".x%x.c postscript -file %s\n", x, s->s_name);
- else sys_vgui(".x%x.c postscript -file x.ps\n", x);
+ if (*s->s_name) sys_vgui(".x%lx.c postscript -file %s\n", x, s->s_name);
+ else sys_vgui(".x%lx.c postscript -file x.ps\n", x);
}
void canvas_menuclose(t_canvas *x, t_floatarg force)
{
if (x->gl_owner)
- canvas_vis(x, 0);
+ canvas_vis(x, 0);
else if ((force != 0) || (!x->gl_dirty))
- pd_free(&x->gl_pd);
+ pd_free(&x->gl_pd);
else sys_vgui("pdtk_check {This window has been modified. Close anyway?}\
- {.x%x menuclose 1;\n}\n", x);
+ {.x%lx menuclose 1;\n}\n", x);
}
/* put up a dialog which may call canvas_font back to do the work */
@@ -1574,38 +1585,38 @@ static int canvas_dofind(t_canvas *x, int *myindex1p)
int myindex1 = *myindex1p, myindex2;
if (myindex1 >= canvas_find_index1)
{
- for (y = x->gl_list, myindex2 = 0; y;
- y = y->g_next, myindex2++)
- {
- t_object *ob = 0;
- if (ob = pd_checkobject(&y->g_pd))
- {
- if (binbuf_match(ob->ob_binbuf, canvas_findbuf))
- {
- if (myindex1 > canvas_find_index1 ||
- myindex1 == canvas_find_index1 &&
- myindex2 > canvas_find_index2)
- {
- canvas_find_index1 = myindex1;
- canvas_find_index2 = myindex2;
- glist_noselect(x);
- canvas_vis(x, 1);
- canvas_editmode(x, 1.);
- glist_select(x, y);
- return (1);
- }
- }
- }
- }
+ for (y = x->gl_list, myindex2 = 0; y;
+ y = y->g_next, myindex2++)
+ {
+ t_object *ob = 0;
+ if (ob = pd_checkobject(&y->g_pd))
+ {
+ if (binbuf_match(ob->ob_binbuf, canvas_findbuf))
+ {
+ if (myindex1 > canvas_find_index1 ||
+ myindex1 == canvas_find_index1 &&
+ myindex2 > canvas_find_index2)
+ {
+ canvas_find_index1 = myindex1;
+ canvas_find_index2 = myindex2;
+ glist_noselect(x);
+ canvas_vis(x, 1);
+ canvas_editmode(x, 1.);
+ glist_select(x, y);
+ return (1);
+ }
+ }
+ }
+ }
}
for (y = x->gl_list, myindex2 = 0; y; y = y->g_next, myindex2++)
{
- if (pd_class(&y->g_pd) == canvas_class)
- {
- (*myindex1p)++;
- if (canvas_dofind((t_canvas *)y, myindex1p))
- return (1);
- }
+ if (pd_class(&y->g_pd) == canvas_class)
+ {
+ (*myindex1p)++;
+ if (canvas_dofind((t_canvas *)y, myindex1p))
+ return (1);
+ }
}
return (0);
}
@@ -1615,16 +1626,16 @@ static void canvas_find(t_canvas *x, t_symbol *s, int ac, t_atom *av)
int myindex1 = 0, i;
for (i = 0; i < ac; i++)
{
- if (av[i].a_type == A_SYMBOL)
- {
- if (!strcmp(av[i].a_w.w_symbol->s_name, "_semi_"))
- SETSEMI(&av[i]);
- else if (!strcmp(av[i].a_w.w_symbol->s_name, "_comma_"))
- SETCOMMA(&av[i]);
- }
+ if (av[i].a_type == A_SYMBOL)
+ {
+ if (!strcmp(av[i].a_w.w_symbol->s_name, "_semi_"))
+ SETSEMI(&av[i]);
+ else if (!strcmp(av[i].a_w.w_symbol->s_name, "_comma_"))
+ SETCOMMA(&av[i]);
+ }
}
if (!canvas_findbuf)
- canvas_findbuf = binbuf_new();
+ canvas_findbuf = binbuf_new();
binbuf_clear(canvas_findbuf);
binbuf_add(canvas_findbuf, ac, av);
canvas_find_index1 = 0;
@@ -1632,8 +1643,8 @@ static void canvas_find(t_canvas *x, t_symbol *s, int ac, t_atom *av)
canvas_whichfind = x;
if (!canvas_dofind(x, &myindex1))
{
- binbuf_print(canvas_findbuf);
- post("... couldn't find");
+ binbuf_print(canvas_findbuf);
+ post("... couldn't find");
}
}
@@ -1641,18 +1652,18 @@ static void canvas_find_again(t_canvas *x)
{
int myindex1 = 0;
if (!canvas_findbuf || !canvas_whichfind)
- return;
+ return;
if (!canvas_dofind(canvas_whichfind, &myindex1))
{
- binbuf_print(canvas_findbuf);
- post("... couldn't find");
+ binbuf_print(canvas_findbuf);
+ post("... couldn't find");
}
}
static void canvas_find_parent(t_canvas *x)
{
if (x->gl_owner)
- canvas_vis(glist_getcanvas(x->gl_owner), 1);
+ canvas_vis(glist_getcanvas(x->gl_owner), 1);
}
static int glist_dofinderror(t_glist *gl, void *error_object)
@@ -1660,20 +1671,20 @@ static int glist_dofinderror(t_glist *gl, void *error_object)
t_gobj *g;
for (g = gl->gl_list; g; g = g->g_next)
{
- if ((void *)g == error_object)
- {
- /* got it... now show it. */
- glist_noselect(gl);
- canvas_vis(glist_getcanvas(gl), 1);
- canvas_editmode(glist_getcanvas(gl), 1.);
- glist_select(gl, g);
- return (1);
- }
- else if (g->g_pd == canvas_class)
- {
- if (glist_dofinderror((t_canvas *)g, error_object))
- return (1);
- }
+ if ((void *)g == error_object)
+ {
+ /* got it... now show it. */
+ glist_noselect(gl);
+ canvas_vis(glist_getcanvas(gl), 1);
+ canvas_editmode(glist_getcanvas(gl), 1.);
+ glist_select(gl, g);
+ return (1);
+ }
+ else if (g->g_pd == canvas_class)
+ {
+ if (glist_dofinderror((t_canvas *)g, error_object))
+ return (1);
+ }
}
return (0);
}
@@ -1681,11 +1692,11 @@ static int glist_dofinderror(t_glist *gl, void *error_object)
void canvas_finderror(void *error_object)
{
t_canvas *x;
- /* find all root canvases */
+ /* find all root canvases */
for (x = canvas_list; x; x = x->gl_next)
{
- if (glist_dofinderror(x, error_object))
- return;
+ if (glist_dofinderror(x, error_object))
+ return;
}
post("... sorry, I couldn't find the source of that error.");
}
@@ -1696,55 +1707,55 @@ void canvas_stowconnections(t_canvas *x)
t_linetraverser t;
t_outconnect *oc;
if (!x->gl_editor) return;
- /* split list to "selected" and "unselected" parts */
+ /* split list to "selected" and "unselected" parts */
for (y = x->gl_list; y; y = y2)
{
- y2 = y->g_next;
- if (glist_isselected(x, y))
- {
- if (seltail)
- {
- seltail->g_next = y;
- seltail = y;
- y->g_next = 0;
- }
- else
- {
- selhead = seltail = y;
- seltail->g_next = 0;
- }
- }
- else
- {
- if (nontail)
- {
- nontail->g_next = y;
- nontail = y;
- y->g_next = 0;
- }
- else
- {
- nonhead = nontail = y;
- nontail->g_next = 0;
- }
- }
- }
- /* move the selected part to the end */
+ y2 = y->g_next;
+ if (glist_isselected(x, y))
+ {
+ if (seltail)
+ {
+ seltail->g_next = y;
+ seltail = y;
+ y->g_next = 0;
+ }
+ else
+ {
+ selhead = seltail = y;
+ seltail->g_next = 0;
+ }
+ }
+ else
+ {
+ if (nontail)
+ {
+ nontail->g_next = y;
+ nontail = y;
+ y->g_next = 0;
+ }
+ else
+ {
+ nonhead = nontail = y;
+ nontail->g_next = 0;
+ }
+ }
+ }
+ /* move the selected part to the end */
if (!nonhead) x->gl_list = selhead;
else x->gl_list = nonhead, nontail->g_next = selhead;
- /* add connections to binbuf */
+ /* add connections to binbuf */
binbuf_clear(x->gl_editor->e_connectbuf);
linetraverser_start(&t, x);
while (oc = linetraverser_next(&t))
{
- int s1 = glist_isselected(x, &t.tr_ob->ob_g);
- int s2 = glist_isselected(x, &t.tr_ob2->ob_g);
- if (s1 != s2)
- binbuf_addv(x->gl_editor->e_connectbuf, "ssiiii;",
- gensym("#X"), gensym("connect"),
- glist_getindex(x, &t.tr_ob->ob_g), t.tr_outno,
- glist_getindex(x, &t.tr_ob2->ob_g), t.tr_inno);
+ int s1 = glist_isselected(x, &t.tr_ob->ob_g);
+ int s2 = glist_isselected(x, &t.tr_ob2->ob_g);
+ if (s1 != s2)
+ binbuf_addv(x->gl_editor->e_connectbuf, "ssiiii;",
+ gensym("#X"), gensym("connect"),
+ glist_getindex(x, &t.tr_ob->ob_g), t.tr_outno,
+ glist_getindex(x, &t.tr_ob2->ob_g), t.tr_inno);
}
}
@@ -1763,19 +1774,19 @@ static t_binbuf *canvas_docopy(t_canvas *x)
t_binbuf *b = binbuf_new();
for (y = x->gl_list; y; y = y->g_next)
{
- if (glist_isselected(x, y))
- gobj_save(y, b);
+ if (glist_isselected(x, y))
+ gobj_save(y, b);
}
linetraverser_start(&t, x);
while (oc = linetraverser_next(&t))
{
- if (glist_isselected(x, &t.tr_ob->ob_g)
- && glist_isselected(x, &t.tr_ob2->ob_g))
- {
- binbuf_addv(b, "ssiiii;", gensym("#X"), gensym("connect"),
- glist_selectionindex(x, &t.tr_ob->ob_g, 1), t.tr_outno,
- glist_selectionindex(x, &t.tr_ob2->ob_g, 1), t.tr_inno);
- }
+ if (glist_isselected(x, &t.tr_ob->ob_g)
+ && glist_isselected(x, &t.tr_ob2->ob_g))
+ {
+ binbuf_addv(b, "ssiiii;", gensym("#X"), gensym("connect"),
+ glist_selectionindex(x, &t.tr_ob->ob_g, 1), t.tr_outno,
+ glist_selectionindex(x, &t.tr_ob2->ob_g, 1), t.tr_inno);
+ }
}
return (b);
}
@@ -1783,26 +1794,49 @@ static t_binbuf *canvas_docopy(t_canvas *x)
static void canvas_copy(t_canvas *x)
{
if (!x->gl_editor || !x->gl_editor->e_selection)
- return;
+ return;
binbuf_free(copy_binbuf);
copy_binbuf = canvas_docopy(x);
+ if (x->gl_editor->e_textedfor)
+ {
+ char *buf;
+ int bufsize;
+ rtext_getseltext(x->gl_editor->e_textedfor, &buf, &bufsize);
+
+#ifdef UNIX
+ /* in X windows (i.e., UNIX) the selection already went to the
+ clipboard when it was made; here we "copy" it to our own buffer
+ as well, because, annoyingly, the clipboard will usually be
+ destroyed by the time the user asks to "paste". */
+ if (canvas_textcopybuf)
+ t_freebytes(canvas_textcopybuf, canvas_textcopybufsize);
+ canvas_textcopybuf = (char *)getbytes(bufsize);
+ memcpy(canvas_textcopybuf, buf, bufsize);
+ canvas_textcopybufsize = bufsize;
+ post("buf size %d", bufsize);
+#else /* UNIX */
+ /* otherwise just copy the text to the clipboard here */
+ sys_vgui("clipboard clear\n", bufsize, buf);
+ sys_vgui("clipboard append {%.*s}\n", bufsize, buf);
+#endif /* UNIX */
+ }
}
static void canvas_clearline(t_canvas *x)
{
if (x->gl_editor->e_selectedline)
{
- canvas_disconnect(x, x->gl_editor->e_selectline_index1,
- x->gl_editor->e_selectline_outno,
- x->gl_editor->e_selectline_index2,
- x->gl_editor->e_selectline_inno);
- canvas_setundo(x, canvas_undo_disconnect,
- canvas_undo_set_disconnect(x,
- x->gl_editor->e_selectline_index1,
- x->gl_editor->e_selectline_outno,
- x->gl_editor->e_selectline_index2,
- x->gl_editor->e_selectline_inno),
- "disconnect");
+ canvas_disconnect(x, x->gl_editor->e_selectline_index1,
+ x->gl_editor->e_selectline_outno,
+ x->gl_editor->e_selectline_index2,
+ x->gl_editor->e_selectline_inno);
+ canvas_setundo(x, canvas_undo_disconnect,
+ canvas_undo_set_disconnect(x,
+ x->gl_editor->e_selectline_index1,
+ x->gl_editor->e_selectline_outno,
+ x->gl_editor->e_selectline_index2,
+ x->gl_editor->e_selectline_inno),
+ "disconnect");
}
}
@@ -1812,50 +1846,51 @@ static void canvas_doclear(t_canvas *x)
t_gobj *y, *y2;
int dspstate;
+ post("doclear");
dspstate = canvas_suspend_dsp();
if (x->gl_editor->e_selectedline)
{
- canvas_disconnect(x, x->gl_editor->e_selectline_index1,
- x->gl_editor->e_selectline_outno,
- x->gl_editor->e_selectline_index2,
- x->gl_editor->e_selectline_inno);
- canvas_setundo(x, canvas_undo_disconnect,
- canvas_undo_set_disconnect(x,
- x->gl_editor->e_selectline_index1,
- x->gl_editor->e_selectline_outno,
- x->gl_editor->e_selectline_index2,
- x->gl_editor->e_selectline_inno),
- "disconnect");
- }
- /* if text is selected, deselecting it might remake the
- object. So we deselect it and hunt for a "new" object on
- the glist to reselect. */
+ canvas_disconnect(x, x->gl_editor->e_selectline_index1,
+ x->gl_editor->e_selectline_outno,
+ x->gl_editor->e_selectline_index2,
+ x->gl_editor->e_selectline_inno);
+ canvas_setundo(x, canvas_undo_disconnect,
+ canvas_undo_set_disconnect(x,
+ x->gl_editor->e_selectline_index1,
+ x->gl_editor->e_selectline_outno,
+ x->gl_editor->e_selectline_index2,
+ x->gl_editor->e_selectline_inno),
+ "disconnect");
+ }
+ /* if text is selected, deselecting it might remake the
+ object. So we deselect it and hunt for a "new" object on
+ the glist to reselect. */
if (x->gl_editor->e_textedfor)
{
- newest = 0;
- glist_noselect(x);
- if (newest)
- {
- for (y = x->gl_list; y; y = y->g_next)
- if (&y->g_pd == newest) glist_select(x, y);
- }
- }
- while (1) /* this is pretty wierd... should rewrite it */
- {
- for (y = x->gl_list; y; y = y2)
- {
- y2 = y->g_next;
- if (glist_isselected(x, y))
- {
- glist_delete(x, y);
+ newest = 0;
+ glist_noselect(x);
+ if (newest)
+ {
+ for (y = x->gl_list; y; y = y->g_next)
+ if (&y->g_pd == newest) glist_select(x, y);
+ }
+ }
+ while (1) /* this is pretty wierd... should rewrite it */
+ {
+ for (y = x->gl_list; y; y = y2)
+ {
+ y2 = y->g_next;
+ if (glist_isselected(x, y))
+ {
+ glist_delete(x, y);
#if 0
- if (y2) post("cut 5 %x %x", y2, y2->g_next);
- else post("cut 6");
+ if (y2) post("cut 5 %lx %lx", y2, y2->g_next);
+ else post("cut 6");
#endif
- goto next;
- }
- }
- goto restore;
+ goto next;
+ }
+ }
+ goto restore;
next: ;
}
restore:
@@ -1866,13 +1901,24 @@ restore:
static void canvas_cut(t_canvas *x)
{
if (x->gl_editor && x->gl_editor->e_selectedline)
- canvas_clearline(x);
+ canvas_clearline(x);
+ else if (x->gl_editor->e_textedfor)
+ {
+ char *buf;
+ int bufsize;
+ rtext_getseltext(x->gl_editor->e_textedfor, &buf, &bufsize);
+ if (!bufsize)
+ return;
+ canvas_copy(x);
+ rtext_key(x->gl_editor->e_textedfor, 127, &s_);
+ canvas_dirty(x, 1);
+ }
else if (x->gl_editor && x->gl_editor->e_selection)
{
- canvas_setundo(x, canvas_undo_cut,
- canvas_undo_set_cut(x, UCUT_CUT), "cut");
- canvas_copy(x);
- canvas_doclear(x);
+ canvas_setundo(x, canvas_undo_cut,
+ canvas_undo_set_cut(x, UCUT_CUT), "cut");
+ canvas_copy(x);
+ canvas_doclear(x);
}
}
@@ -1883,10 +1929,10 @@ static void glist_donewloadbangs(t_glist *x)
{
if (x->gl_editor)
{
- t_selection *sel;
- for (sel = x->gl_editor->e_selection; sel; sel = sel->sel_next)
- if (pd_class(&sel->sel_what->g_pd) == canvas_class)
- canvas_loadbang((t_canvas *)(&sel->sel_what->g_pd));
+ t_selection *sel;
+ for (sel = x->gl_editor->e_selection; sel; sel = sel->sel_next)
+ if (pd_class(&sel->sel_what->g_pd) == canvas_class)
+ canvas_loadbang((t_canvas *)(&sel->sel_what->g_pd));
}
}
@@ -1906,8 +1952,8 @@ static void canvas_dopaste(t_canvas *x, t_binbuf *b)
binbuf_eval(b, 0, 0, 0);
pd_unbind(&x->gl_pd, gensym("#X"));
for (g2 = x->gl_list, count = 0; g2; g2 = g2->g_next, count++)
- if (count >= nbox)
- glist_select(x, g2);
+ if (count >= nbox)
+ glist_select(x, g2);
paste_canvas = 0;
canvas_resume_dsp(dspstate);
canvas_dirty(x, 1);
@@ -1916,23 +1962,46 @@ static void canvas_dopaste(t_canvas *x, t_binbuf *b)
static void canvas_paste(t_canvas *x)
{
- canvas_setundo(x, canvas_undo_paste, canvas_undo_set_paste(x), "paste");
- canvas_dopaste(x, copy_binbuf);
+ if (!x->gl_editor)
+ return;
+ if (x->gl_editor->e_textedfor)
+ {
+ /* simulate keystrokes as if the copy buffer were typed in. */
+#ifdef UNIX
+ /* in UNIX we kept the text in our own copy buffer */
+ int i;
+ for (i = 0; i < canvas_textcopybufsize; i++)
+ {
+ pd_vmess(&x->gl_gobj.g_pd, gensym("key"), "iii",
+ 1, canvas_textcopybuf[i]&0xff, 0);
+ }
+#else /* UNIX */
+ /* otherwise appeal to the GUI to send the clipboard down */
+ sys_gui("pdtk_pastetext\n");
+#endif /* UNIX */
+
+ }
+ else
+ {
+ canvas_setundo(x, canvas_undo_paste, canvas_undo_set_paste(x),
+ "paste");
+ canvas_dopaste(x, copy_binbuf);
+ }
}
static void canvas_duplicate(t_canvas *x)
{
if (x->gl_editor->e_onmotion == MA_NONE)
{
- t_selection *y;
- canvas_copy(x);
- canvas_setundo(x, canvas_undo_paste, canvas_undo_set_paste(x),
- "duplicate");
- canvas_dopaste(x, copy_binbuf);
- for (y = x->gl_editor->e_selection; y; y = y->sel_next)
- gobj_displace(y->sel_what, x,
- 10, 10);
- canvas_dirty(x, 1);
+ t_selection *y;
+ canvas_copy(x);
+ canvas_setundo(x, canvas_undo_paste, canvas_undo_set_paste(x),
+ "duplicate");
+ canvas_dopaste(x, copy_binbuf);
+ for (y = x->gl_editor->e_selection; y; y = y->sel_next)
+ gobj_displace(y->sel_what, x,
+ 10, 10);
+ canvas_dirty(x, 1);
}
}
@@ -1940,14 +2009,16 @@ static void canvas_selectall(t_canvas *x)
{
t_gobj *y;
if (!x->gl_edit)
- canvas_editmode(x, 1);
+ canvas_editmode(x, 1);
for (y = x->gl_list; y; y = y->g_next)
{
- if (!glist_isselected(x, y))
- glist_select(x, y);
+ if (!glist_isselected(x, y))
+ glist_select(x, y);
}
}
+extern t_class *text_class;
+
void canvas_connect(t_canvas *x, t_floatarg fwhoout, t_floatarg foutno,
t_floatarg fwhoin, t_floatarg finno)
{
@@ -1958,27 +2029,39 @@ void canvas_connect(t_canvas *x, t_floatarg fwhoout, t_floatarg foutno,
int nin = whoin, nout = whoout;
if (paste_canvas == x) whoout += paste_onset, whoin += paste_onset;
for (src = x->gl_list; whoout; src = src->g_next, whoout--)
- if (!src->g_next) goto bad; /* bug fix thanks to Hannes */
+ if (!src->g_next) goto bad; /* bug fix thanks to Hannes */
for (sink = x->gl_list; whoin; sink = sink->g_next, whoin--)
- if (!sink->g_next) goto bad;
+ if (!sink->g_next) goto bad;
+
+ /* check they're both patchable objects */
if (!(objsrc = pd_checkobject(&src->g_pd)) ||
- !(objsink = pd_checkobject(&sink->g_pd)))
- goto bad;
+ !(objsink = pd_checkobject(&sink->g_pd)))
+ goto bad;
+
+ /* if object creation failed, make dummy inlets or outlets
+ as needed */
+ if (pd_class(&src->g_pd) == text_class && objsrc->te_type == T_OBJECT)
+ while (outno >= obj_noutlets(objsrc))
+ outlet_new(objsrc, &s_);
+ if (pd_class(&sink->g_pd) == text_class && objsink->te_type == T_OBJECT)
+ while (inno >= obj_ninlets(objsink))
+ inlet_new(objsink, &objsink->ob_pd, &s_, &s_);
+
if (!(oc = obj_connect(objsrc, outno, objsink, inno))) goto bad;
if (glist_isvisible(x))
{
- sys_vgui(".x%x.c create line %d %d %d %d -width %d -tags l%x\n",
- glist_getcanvas(x), 0, 0, 0, 0,
- (obj_issignaloutlet(objsrc, outno) ? 2 : 1),oc);
- canvas_fixlinesfor(x, objsrc);
+ sys_vgui(".x%lx.c create line %d %d %d %d -width %d -tags l%lx\n",
+ glist_getcanvas(x), 0, 0, 0, 0,
+ (obj_issignaloutlet(objsrc, outno) ? 2 : 1),oc);
+ canvas_fixlinesfor(x, objsrc);
}
return;
bad:
post("%s %d %d %d %d (%s->%s) connection failed",
- x->gl_name->s_name, nout, outno, nin, inno,
- (src? class_getname(pd_class(&src->g_pd)) : "???"),
- (sink? class_getname(pd_class(&sink->g_pd)) : "???"));
+ x->gl_name->s_name, nout, outno, nin, inno,
+ (src? class_getname(pd_class(&src->g_pd)) : "???"),
+ (sink? class_getname(pd_class(&sink->g_pd)) : "???"));
}
#define XTOLERANCE 4
@@ -1991,99 +2074,99 @@ static void canvas_tidy(t_canvas *x)
t_gobj *y, *y2, *y3;
int ax1, ay1, ax2, ay2, bx1, by1, bx2, by2;
int histogram[NHIST], *ip, i, besthist, bestdist;
- /* if nobody is selected, this means do it to all boxes;
- othewise just the selection */
+ /* if nobody is selected, this means do it to all boxes;
+ othewise just the selection */
int all = (x->gl_editor ? (x->gl_editor->e_selection == 0) : 1);
canvas_setundo(x, canvas_undo_move, canvas_undo_set_move(x, !all),
- "motion");
+ "motion");
- /* tidy horizontally */
+ /* tidy horizontally */
for (y = x->gl_list; y; y = y->g_next)
- if (all || glist_isselected(x, y))
- {
- gobj_getrect(y, x, &ax1, &ay1, &ax2, &ay2);
-
- for (y2 = x->gl_list; y2; y2 = y2->g_next)
- if (all || glist_isselected(x, y2))
- {
- gobj_getrect(y2, x, &bx1, &by1, &bx2, &by2);
- if (by1 <= ay1 + YTOLERANCE && by1 >= ay1 - YTOLERANCE &&
- bx1 < ax1)
- goto nothorizhead;
- }
-
- for (y2 = x->gl_list; y2; y2 = y2->g_next)
- if (all || glist_isselected(x, y2))
- {
- gobj_getrect(y2, x, &bx1, &by1, &bx2, &by2);
- if (by1 <= ay1 + YTOLERANCE && by1 >= ay1 - YTOLERANCE
- && by1 != ay1)
- gobj_displace(y2, x, 0, ay1-by1);
- }
+ if (all || glist_isselected(x, y))
+ {
+ gobj_getrect(y, x, &ax1, &ay1, &ax2, &ay2);
+
+ for (y2 = x->gl_list; y2; y2 = y2->g_next)
+ if (all || glist_isselected(x, y2))
+ {
+ gobj_getrect(y2, x, &bx1, &by1, &bx2, &by2);
+ if (by1 <= ay1 + YTOLERANCE && by1 >= ay1 - YTOLERANCE &&
+ bx1 < ax1)
+ goto nothorizhead;
+ }
+
+ for (y2 = x->gl_list; y2; y2 = y2->g_next)
+ if (all || glist_isselected(x, y2))
+ {
+ gobj_getrect(y2, x, &bx1, &by1, &bx2, &by2);
+ if (by1 <= ay1 + YTOLERANCE && by1 >= ay1 - YTOLERANCE
+ && by1 != ay1)
+ gobj_displace(y2, x, 0, ay1-by1);
+ }
nothorizhead: ;
}
- /* tidy vertically. First guess the user's favorite vertical spacing */
+ /* tidy vertically. First guess the user's favorite vertical spacing */
for (i = NHIST, ip = histogram; i--; ip++) *ip = 0;
for (y = x->gl_list; y; y = y->g_next)
- if (all || glist_isselected(x, y))
- {
- gobj_getrect(y, x, &ax1, &ay1, &ax2, &ay2);
- for (y2 = x->gl_list; y2; y2 = y2->g_next)
- if (all || glist_isselected(x, y2))
- {
- gobj_getrect(y2, x, &bx1, &by1, &bx2, &by2);
- if (bx1 <= ax1 + XTOLERANCE && bx1 >= ax1 - XTOLERANCE)
- {
- int distance = by1-ay2;
- if (distance >= 0 && distance < NHIST)
- histogram[distance]++;
- }
- }
+ if (all || glist_isselected(x, y))
+ {
+ gobj_getrect(y, x, &ax1, &ay1, &ax2, &ay2);
+ for (y2 = x->gl_list; y2; y2 = y2->g_next)
+ if (all || glist_isselected(x, y2))
+ {
+ gobj_getrect(y2, x, &bx1, &by1, &bx2, &by2);
+ if (bx1 <= ax1 + XTOLERANCE && bx1 >= ax1 - XTOLERANCE)
+ {
+ int distance = by1-ay2;
+ if (distance >= 0 && distance < NHIST)
+ histogram[distance]++;
+ }
+ }
}
for (i = 1, besthist = 0, bestdist = 4, ip = histogram + 1;
- i < (NHIST-1); i++, ip++)
+ i < (NHIST-1); i++, ip++)
{
- int hit = ip[-1] + 2 * ip[0] + ip[1];
- if (hit > besthist)
- {
- besthist = hit;
- bestdist = i;
- }
+ int hit = ip[-1] + 2 * ip[0] + ip[1];
+ if (hit > besthist)
+ {
+ besthist = hit;
+ bestdist = i;
+ }
}
post("best vertical distance %d", bestdist);
for (y = x->gl_list; y; y = y->g_next)
- if (all || glist_isselected(x, y))
- {
- int keep = 1;
- gobj_getrect(y, x, &ax1, &ay1, &ax2, &ay2);
- for (y2 = x->gl_list; y2; y2 = y2->g_next)
- if (all || glist_isselected(x, y2))
- {
- gobj_getrect(y2, x, &bx1, &by1, &bx2, &by2);
- if (bx1 <= ax1 + XTOLERANCE && bx1 >= ax1 - XTOLERANCE &&
- ay1 >= by2 - 10 && ay1 < by2 + NHIST)
- goto nothead;
- }
- while (keep)
- {
- keep = 0;
- for (y2 = x->gl_list; y2; y2 = y2->g_next)
- if (all || glist_isselected(x, y2))
- {
- gobj_getrect(y2, x, &bx1, &by1, &bx2, &by2);
- if (bx1 <= ax1 + XTOLERANCE && bx1 >= ax1 - XTOLERANCE &&
- by1 > ay1 && by1 < ay2 + NHIST)
- {
- int vmove = ay2 + bestdist - by1;
- gobj_displace(y2, x, ax1-bx1, vmove);
- ay1 = by1 + vmove;
- ay2 = by2 + vmove;
- keep = 1;
- break;
- }
- }
- }
+ if (all || glist_isselected(x, y))
+ {
+ int keep = 1;
+ gobj_getrect(y, x, &ax1, &ay1, &ax2, &ay2);
+ for (y2 = x->gl_list; y2; y2 = y2->g_next)
+ if (all || glist_isselected(x, y2))
+ {
+ gobj_getrect(y2, x, &bx1, &by1, &bx2, &by2);
+ if (bx1 <= ax1 + XTOLERANCE && bx1 >= ax1 - XTOLERANCE &&
+ ay1 >= by2 - 10 && ay1 < by2 + NHIST)
+ goto nothead;
+ }
+ while (keep)
+ {
+ keep = 0;
+ for (y2 = x->gl_list; y2; y2 = y2->g_next)
+ if (all || glist_isselected(x, y2))
+ {
+ gobj_getrect(y2, x, &bx1, &by1, &bx2, &by2);
+ if (bx1 <= ax1 + XTOLERANCE && bx1 >= ax1 - XTOLERANCE &&
+ by1 > ay1 && by1 < ay2 + NHIST)
+ {
+ int vmove = ay2 + bestdist - by1;
+ gobj_displace(y2, x, ax1-bx1, vmove);
+ ay1 = by1 + vmove;
+ ay2 = by2 + vmove;
+ keep = 1;
+ break;
+ }
+ }
+ }
nothead: ;
}
canvas_dirty(x, 1);
@@ -2095,7 +2178,7 @@ static void canvas_texteditor(t_canvas *x)
char *buf;
int bufsize;
if (foo = x->gl_editor->e_textedfor)
- rtext_gettext(foo, &buf, &bufsize);
+ rtext_gettext(foo, &buf, &bufsize);
else buf = "", bufsize = 0;
sys_vgui("pdtk_pd_texteditor {%.*s}\n", bufsize, buf);
@@ -2103,7 +2186,7 @@ static void canvas_texteditor(t_canvas *x)
void glob_key(void *dummy, t_symbol *s, int ac, t_atom *av)
{
- /* canvas_editing can be zero; canvas_key checks for that */
+ /* canvas_editing can be zero; canvas_key checks for that */
canvas_key(canvas_editing, s, ac, av);
}
@@ -2111,18 +2194,18 @@ void canvas_editmode(t_canvas *x, t_floatarg fyesplease)
{
int yesplease = fyesplease;
if (yesplease && x->gl_edit)
- return;
+ return;
x->gl_edit = !x->gl_edit;
if (x->gl_edit && glist_isvisible(x) && glist_istoplevel(x))
- canvas_setcursor(x, CURSOR_EDITMODE_NOTHING);
+ canvas_setcursor(x, CURSOR_EDITMODE_NOTHING);
else
{
- glist_noselect(x);
- if (glist_isvisible(x) && glist_istoplevel(x))
- canvas_setcursor(x, CURSOR_RUNMODE_NOTHING);
+ glist_noselect(x);
+ if (glist_isvisible(x) && glist_istoplevel(x))
+ canvas_setcursor(x, CURSOR_RUNMODE_NOTHING);
}
- sys_vgui("pdtk_canvas_editval .x%x %d\n",
- glist_getcanvas(x), x->gl_edit);
+ sys_vgui("pdtk_canvas_editval .x%lx %d\n",
+ glist_getcanvas(x), x->gl_edit);
}
/* called by canvas_font below */
@@ -2133,23 +2216,23 @@ static void canvas_dofont(t_canvas *x, t_floatarg font, t_floatarg xresize,
x->gl_font = font;
if (xresize != 1 || yresize != 1)
{
- canvas_setundo(x, canvas_undo_move, canvas_undo_set_move(x, 0),
- "motion");
- for (y = x->gl_list; y; y = y->g_next)
- {
- int x1, x2, y1, y2, nx1, ny1;
- gobj_getrect(y, x, &x1, &y1, &x2, &y2);
- nx1 = x1 * xresize + 0.5;
- ny1 = y1 * yresize + 0.5;
- gobj_displace(y, x, nx1-x1, ny1-y1);
- }
+ canvas_setundo(x, canvas_undo_move, canvas_undo_set_move(x, 0),
+ "motion");
+ for (y = x->gl_list; y; y = y->g_next)
+ {
+ int x1, x2, y1, y2, nx1, ny1;
+ gobj_getrect(y, x, &x1, &y1, &x2, &y2);
+ nx1 = x1 * xresize + 0.5;
+ ny1 = y1 * yresize + 0.5;
+ gobj_displace(y, x, nx1-x1, ny1-y1);
+ }
}
if (glist_isvisible(x))
- glist_redraw(x);
+ glist_redraw(x);
for (y = x->gl_list; y; y = y->g_next)
- if (pd_class(&y->g_pd) == canvas_class
- && !canvas_isabstraction((t_canvas *)y))
- canvas_dofont((t_canvas *)y, font, xresize, yresize);
+ if (pd_class(&y->g_pd) == canvas_class
+ && !canvas_isabstraction((t_canvas *)y))
+ canvas_dofont((t_canvas *)y, font, xresize, yresize);
}
/* canvas_menufont calls up a TK dialog which calls this back */
@@ -2161,9 +2244,9 @@ static void canvas_font(t_canvas *x, t_floatarg font, t_floatarg resize,
if (!resize) realresize = 1;
else
{
- if (resize < 20) resize = 20;
- if (resize > 500) resize = 500;
- realresize = resize * 0.01;
+ if (resize < 20) resize = 20;
+ if (resize > 500) resize = 500;
+ realresize = resize * 0.01;
}
if (whichresize != 3) realresx = realresize;
if (whichresize != 2) realresy = realresize;
@@ -2177,7 +2260,7 @@ static int canvas_last_glist_x, canvas_last_glist_y;
void glist_getnextxy(t_glist *gl, int *xpix, int *ypix)
{
if (canvas_last_glist == gl)
- *xpix = canvas_last_glist_x, *ypix = canvas_last_glist_y;
+ *xpix = canvas_last_glist_x, *ypix = canvas_last_glist_y;
else *xpix = *ypix = 40;
}
@@ -2193,62 +2276,62 @@ void g_editor_setup(void)
{
/* ------------------------ events ---------------------------------- */
class_addmethod(canvas_class, (t_method)canvas_mousedown, gensym("mouse"),
- A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, A_NULL);
+ A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, A_NULL);
class_addmethod(canvas_class, (t_method)canvas_mouseup, gensym("mouseup"),
- A_FLOAT, A_FLOAT, A_FLOAT, A_NULL);
+ A_FLOAT, A_FLOAT, A_FLOAT, A_NULL);
class_addmethod(canvas_class, (t_method)canvas_key, gensym("key"),
- A_GIMME, A_NULL);
+ A_GIMME, A_NULL);
class_addmethod(canvas_class, (t_method)canvas_motion, gensym("motion"),
- A_FLOAT, A_FLOAT, A_FLOAT, A_NULL);
+ A_FLOAT, A_FLOAT, A_FLOAT, A_NULL);
/* ------------------------ menu actions ---------------------------- */
class_addmethod(canvas_class, (t_method)canvas_menuclose,
- gensym("menuclose"), A_DEFFLOAT, 0);
+ gensym("menuclose"), A_DEFFLOAT, 0);
class_addmethod(canvas_class, (t_method)canvas_cut,
- gensym("cut"), A_NULL);
+ gensym("cut"), A_NULL);
class_addmethod(canvas_class, (t_method)canvas_copy,
- gensym("copy"), A_NULL);
+ gensym("copy"), A_NULL);
class_addmethod(canvas_class, (t_method)canvas_paste,
- gensym("paste"), A_NULL);
+ gensym("paste"), A_NULL);
class_addmethod(canvas_class, (t_method)canvas_duplicate,
- gensym("duplicate"), A_NULL);
+ gensym("duplicate"), A_NULL);
class_addmethod(canvas_class, (t_method)canvas_selectall,
- gensym("selectall"), A_NULL);
+ gensym("selectall"), A_NULL);
class_addmethod(canvas_class, (t_method)canvas_undo,
- gensym("undo"), A_NULL);
+ gensym("undo"), A_NULL);
class_addmethod(canvas_class, (t_method)canvas_redo,
- gensym("redo"), A_NULL);
+ gensym("redo"), A_NULL);
class_addmethod(canvas_class, (t_method)canvas_tidy,
- gensym("tidy"), A_NULL);
+ gensym("tidy"), A_NULL);
class_addmethod(canvas_class, (t_method)canvas_texteditor,
- gensym("texteditor"), A_NULL);
+ gensym("texteditor"), A_NULL);
class_addmethod(canvas_class, (t_method)canvas_editmode,
- gensym("editmode"), A_DEFFLOAT, A_NULL);
+ gensym("editmode"), A_DEFFLOAT, A_NULL);
class_addmethod(canvas_class, (t_method)canvas_print,
- gensym("print"), A_SYMBOL, A_NULL);
+ gensym("print"), A_SYMBOL, A_NULL);
class_addmethod(canvas_class, (t_method)canvas_menufont,
- gensym("menufont"), A_NULL);
+ gensym("menufont"), A_NULL);
class_addmethod(canvas_class, (t_method)canvas_font,
- gensym("font"), A_FLOAT, A_FLOAT, A_FLOAT, A_NULL);
+ gensym("font"), A_FLOAT, A_FLOAT, A_FLOAT, A_NULL);
class_addmethod(canvas_class, (t_method)canvas_find,
- gensym("find"), A_GIMME, A_NULL);
+ gensym("find"), A_GIMME, A_NULL);
class_addmethod(canvas_class, (t_method)canvas_find_again,
- gensym("findagain"), A_NULL);
+ gensym("findagain"), A_NULL);
class_addmethod(canvas_class, (t_method)canvas_find_parent,
- gensym("findparent"), A_NULL);
+ gensym("findparent"), A_NULL);
class_addmethod(canvas_class, (t_method)canvas_done_popup,
- gensym("done-popup"), A_FLOAT, A_FLOAT, A_FLOAT, A_NULL);
+ gensym("done-popup"), A_FLOAT, A_FLOAT, A_FLOAT, A_NULL);
class_addmethod(canvas_class, (t_method)canvas_donecanvasdialog,
- gensym("donecanvasdialog"), A_FLOAT, A_FLOAT, A_FLOAT, A_NULL);
+ gensym("donecanvasdialog"), A_FLOAT, A_FLOAT, A_FLOAT, A_NULL);
class_addmethod(canvas_class, (t_method)glist_arraydialog,
- gensym("arraydialog"), A_SYMBOL, A_FLOAT, A_FLOAT, A_FLOAT, A_NULL);
+ gensym("arraydialog"), A_SYMBOL, A_FLOAT, A_FLOAT, A_FLOAT, A_NULL);
/* -------------- connect method used in reading files ------------------ */
class_addmethod(canvas_class, (t_method)canvas_connect,
- gensym("connect"), A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, A_NULL);
+ gensym("connect"), A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, A_NULL);
class_addmethod(canvas_class, (t_method)canvas_disconnect,
- gensym("disconnect"), A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, A_NULL);
+ gensym("disconnect"), A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, A_NULL);
/* -------------- copy buffer ------------------ */
copy_binbuf = binbuf_new();
}
diff --git a/pd/src/g_graph.c b/pd/src/g_graph.c
index 3347fb9b..b7ae4d81 100644
--- a/pd/src/g_graph.c
+++ b/pd/src/g_graph.c
@@ -30,16 +30,16 @@ void glist_add(t_glist *x, t_gobj *y)
if (!x->gl_list) x->gl_list = y;
else
{
- t_gobj *y2;
- for (y2 = x->gl_list; y2->g_next; y2 = y2->g_next);
- y2->g_next = y;
+ t_gobj *y2;
+ for (y2 = x->gl_list; y2->g_next; y2 = y2->g_next);
+ y2->g_next = y;
}
if (x->gl_editor && (ob = pd_checkobject(&y->g_pd)))
- rtext_new(x, ob);
+ rtext_new(x, ob);
if (glist_isvisible(x))
- gobj_vis(y, x, 1);
+ gobj_vis(y, x, 1);
if (class_isdrawcommand(y->g_pd))
- canvas_redrawallfortemplate(glist_getcanvas(x));
+ canvas_redrawallfortemplate(glist_getcanvas(x));
}
/* this is to protect against a hairy problem in which deleting
@@ -65,42 +65,42 @@ void glist_delete(t_glist *x, t_gobj *y)
wasdeleting = canvas_setdeleting(canvas, 1);
if (x->gl_editor)
{
- if (x->gl_editor->e_grab == y) x->gl_editor->e_grab = 0;
- if (glist_isselected(x, y)) glist_deselect(x, y);
-
- /* HACK -- we had phantom outlets not getting erased on the
- screen because the canvas_setdeleting() mechanism is too
- crude. LATER carefully set up rules for when the rtexts
- should exist, so that they stay around until all the
- steps of becoming invisible are done. In the meantime, just
- zap the inlets and outlets here... */
- if (pd_class(&y->g_pd) == canvas_class)
- {
- t_glist *gl = (t_glist *)y;
- if (gl->gl_isgraph)
- {
- char tag[80];
- sprintf(tag, "graph%x", (int)gl);
- glist_eraseiofor(x, &gl->gl_obj, tag);
- }
- else
- {
- text_eraseborder(&gl->gl_obj, x,
- rtext_gettag(glist_findrtext(x, &gl->gl_obj)));
- }
- }
+ if (x->gl_editor->e_grab == y) x->gl_editor->e_grab = 0;
+ if (glist_isselected(x, y)) glist_deselect(x, y);
+
+ /* HACK -- we had phantom outlets not getting erased on the
+ screen because the canvas_setdeleting() mechanism is too
+ crude. LATER carefully set up rules for when the rtexts
+ should exist, so that they stay around until all the
+ steps of becoming invisible are done. In the meantime, just
+ zap the inlets and outlets here... */
+ if (pd_class(&y->g_pd) == canvas_class)
+ {
+ t_glist *gl = (t_glist *)y;
+ if (gl->gl_isgraph)
+ {
+ char tag[80];
+ sprintf(tag, "graph%lx", (t_int)gl);
+ glist_eraseiofor(x, &gl->gl_obj, tag);
+ }
+ else
+ {
+ text_eraseborder(&gl->gl_obj, x,
+ rtext_gettag(glist_findrtext(x, &gl->gl_obj)));
+ }
+ }
}
gobj_delete(y, x);
if (glist_isvisible(canvas))
- gobj_vis(y, x, 0);
+ gobj_vis(y, x, 0);
if (x->gl_editor && (ob = pd_checkobject(&y->g_pd)))
- rtext_new(x, ob);
+ rtext_new(x, ob);
if (x->gl_list == y) x->gl_list = y->g_next;
else for (g = x->gl_list; g; g = g->g_next)
- if (g->g_next == y)
+ if (g->g_next == y)
{
- g->g_next = y->g_next;
- break;
+ g->g_next = y->g_next;
+ break;
}
pd_free(&y->g_pd);
if (chkdsp) canvas_update_dsp();
@@ -115,19 +115,19 @@ void glist_clear(t_glist *x)
t_gobj *y, *y2;
int dspstate = canvas_suspend_dsp();
while (y = x->gl_list)
- glist_delete(x, y);
+ glist_delete(x, y);
canvas_resume_dsp(dspstate);
}
void glist_retext(t_glist *glist, t_text *y)
{
t_canvas *c = glist_getcanvas(glist);
- /* check that we have built rtexts yet. LATER need a better test. */
+ /* check that we have built rtexts yet. LATER need a better test. */
if (glist->gl_editor && glist->gl_editor->e_rtext)
{
- t_rtext *rt = glist_findrtext(glist, y);
- if (rt)
- rtext_retext(rt);
+ t_rtext *rt = glist_findrtext(glist, y);
+ if (rt)
+ rtext_retext(rt);
}
}
@@ -136,7 +136,7 @@ void glist_grab(t_glist *x, t_gobj *y, t_glistmotionfn motionfn,
{
t_glist *x2 = glist_getcanvas(x);
if (motionfn)
- x2->gl_editor->e_onmotion = MA_PASSOUT;
+ x2->gl_editor->e_onmotion = MA_PASSOUT;
else x2->gl_editor->e_onmotion = 0;
x2->gl_editor->e_grab = y;
x2->gl_editor->e_motionfn = motionfn;
@@ -148,7 +148,7 @@ void glist_grab(t_glist *x, t_gobj *y, t_glistmotionfn motionfn,
t_canvas *glist_getcanvas(t_glist *x)
{
while (x->gl_owner && !x->gl_havewindow && x->gl_isgraph)
- x = x->gl_owner;
+ x = x->gl_owner;
return((t_canvas *)x);
}
@@ -156,9 +156,9 @@ static float gobj_getxforsort(t_gobj *g)
{
if (pd_class(&g->g_pd) == scalar_class)
{
- float x1, y1;
- scalar_getbasexy((t_scalar *)g, &x1, &y1);
- return(x1);
+ float x1, y1;
+ scalar_getbasexy((t_scalar *)g, &x1, &y1);
+ return(x1);
}
else return (0);
}
@@ -168,40 +168,40 @@ static t_gobj *glist_merge(t_glist *x, t_gobj *g1, t_gobj *g2)
t_gobj *g = 0, *g9 = 0;
float f1 = 0, f2 = 0;
if (g1)
- f1 = gobj_getxforsort(g1);
+ f1 = gobj_getxforsort(g1);
if (g2)
- f2 = gobj_getxforsort(g2);
+ f2 = gobj_getxforsort(g2);
while (1)
{
- if (g1)
- {
- if (g2)
- {
- if (f1 <= f2)
- goto put1;
- else goto put2;
- }
- else goto put1;
- }
- else if (g2)
- goto put2;
- else break;
+ if (g1)
+ {
+ if (g2)
+ {
+ if (f1 <= f2)
+ goto put1;
+ else goto put2;
+ }
+ else goto put1;
+ }
+ else if (g2)
+ goto put2;
+ else break;
put1:
- if (g9)
- g9->g_next = g1, g9 = g1;
- else g9 = g = g1;
- if (g1 = g1->g_next)
- f1 = gobj_getxforsort(g1);
- g9->g_next = 0;
- continue;
+ if (g9)
+ g9->g_next = g1, g9 = g1;
+ else g9 = g = g1;
+ if (g1 = g1->g_next)
+ f1 = gobj_getxforsort(g1);
+ g9->g_next = 0;
+ continue;
put2:
- if (g9)
- g9->g_next = g2, g9 = g2;
- else g9 = g = g2;
- if (g2 = g2->g_next)
- f2 = gobj_getxforsort(g2);
- g9->g_next = 0;
- continue;
+ if (g9)
+ g9->g_next = g2, g9 = g2;
+ else g9 = g = g2;
+ if (g2 = g2->g_next)
+ f2 = gobj_getxforsort(g2);
+ g9->g_next = 0;
+ continue;
}
return (g);
}
@@ -210,18 +210,18 @@ static t_gobj *glist_dosort(t_glist *x,
t_gobj *g, int nitems)
{
if (nitems < 2)
- return (g);
+ return (g);
else
{
- int n1 = nitems/2, n2 = nitems - n1, i;
- t_gobj *g2, *g3;
- for (g2 = g, i = n1-1; i--; g2 = g2->g_next)
- ;
- g3 = g2->g_next;
- g2->g_next = 0;
- g = glist_dosort(x, g, n1);
- g3 = glist_dosort(x, g3, n2);
- return (glist_merge(x, g, g3));
+ int n1 = nitems/2, n2 = nitems - n1, i;
+ t_gobj *g2, *g3;
+ for (g2 = g, i = n1-1; i--; g2 = g2->g_next)
+ ;
+ g3 = g2->g_next;
+ g2->g_next = 0;
+ g = glist_dosort(x, g, n1);
+ g3 = glist_dosort(x, g3, n2);
+ return (glist_merge(x, g, g3));
}
}
@@ -232,14 +232,14 @@ void glist_sort(t_glist *x)
t_gobj *g;
for (g = x->gl_list; g; g = g->g_next)
{
- float x1 = gobj_getxforsort(g);
- if (x1 < lastx)
- foo = 1;
- lastx = x1;
- nitems++;
+ float x1 = gobj_getxforsort(g);
+ if (x1 < lastx)
+ foo = 1;
+ lastx = x1;
+ nitems++;
}
if (foo)
- x->gl_list = glist_dosort(x, x->gl_list, nitems);
+ x->gl_list = glist_dosort(x, x->gl_list, nitems);
}
void glist_cleanup(t_glist *x)
@@ -263,9 +263,9 @@ t_inlet *canvas_addinlet(t_canvas *x, t_pd *who, t_symbol *s)
t_inlet *ip = inlet_new(&x->gl_obj, who, s, 0);
if (!x->gl_loading && x->gl_owner && glist_isvisible(x->gl_owner))
{
- gobj_vis(&x->gl_gobj, x->gl_owner, 0);
- gobj_vis(&x->gl_gobj, x->gl_owner, 1);
- canvas_fixlinesfor(x->gl_owner, &x->gl_obj);
+ gobj_vis(&x->gl_gobj, x->gl_owner, 0);
+ gobj_vis(&x->gl_gobj, x->gl_owner, 1);
+ canvas_fixlinesfor(x->gl_owner, &x->gl_obj);
}
if (!x->gl_loading) canvas_resortinlets(x);
return (ip);
@@ -275,16 +275,16 @@ void canvas_rminlet(t_canvas *x, t_inlet *ip)
{
t_canvas *owner = x->gl_owner;
int redraw = (owner && glist_isvisible(owner) && (!owner->gl_isdeleting)
- && glist_istoplevel(owner));
+ && glist_istoplevel(owner));
if (owner) canvas_deletelinesforio(owner, &x->gl_obj, ip, 0);
if (redraw)
- gobj_vis(&x->gl_gobj, x->gl_owner, 0);
+ gobj_vis(&x->gl_gobj, x->gl_owner, 0);
inlet_free(ip);
if (redraw)
{
- gobj_vis(&x->gl_gobj, x->gl_owner, 1);
- canvas_fixlinesfor(x->gl_owner, &x->gl_obj);
+ gobj_vis(&x->gl_gobj, x->gl_owner, 1);
+ canvas_fixlinesfor(x->gl_owner, &x->gl_obj);
}
}
@@ -297,37 +297,37 @@ void canvas_resortinlets(t_canvas *x)
t_gobj *y, **vec, **vp, **maxp;
for (ninlets = 0, y = x->gl_list; y; y = y->g_next)
- if (pd_class(&y->g_pd) == vinlet_class) ninlets++;
+ if (pd_class(&y->g_pd) == vinlet_class) ninlets++;
if (ninlets < 2) return;
vec = (t_gobj **)getbytes(ninlets * sizeof(*vec));
for (y = x->gl_list, vp = vec; y; y = y->g_next)
- if (pd_class(&y->g_pd) == vinlet_class) *vp++ = y;
+ if (pd_class(&y->g_pd) == vinlet_class) *vp++ = y;
for (i = ninlets; i--;)
{
- t_inlet *ip;
- for (vp = vec, xmax = -0x7fffffff, maxp = 0, j = ninlets;
- j--; vp++)
- {
- int x1, y1, x2, y2;
- t_gobj *g = *vp;
- if (!g) continue;
- gobj_getrect(g, x, &x1, &y1, &x2, &y2);
- if (x1 > xmax) xmax = x1, maxp = vp;
- }
- if (!maxp) break;
- y = *maxp;
- *maxp = 0;
- ip = vinlet_getit(&y->g_pd);
-
- obj_moveinletfirst(&x->gl_obj, ip);
+ t_inlet *ip;
+ for (vp = vec, xmax = -0x7fffffff, maxp = 0, j = ninlets;
+ j--; vp++)
+ {
+ int x1, y1, x2, y2;
+ t_gobj *g = *vp;
+ if (!g) continue;
+ gobj_getrect(g, x, &x1, &y1, &x2, &y2);
+ if (x1 > xmax) xmax = x1, maxp = vp;
+ }
+ if (!maxp) break;
+ y = *maxp;
+ *maxp = 0;
+ ip = vinlet_getit(&y->g_pd);
+
+ obj_moveinletfirst(&x->gl_obj, ip);
}
freebytes(vec, ninlets * sizeof(*vec));
if (x->gl_owner && glist_isvisible(x->gl_owner))
- canvas_fixlinesfor(x->gl_owner, &x->gl_obj);
+ canvas_fixlinesfor(x->gl_owner, &x->gl_obj);
}
t_outlet *canvas_addoutlet(t_canvas *x, t_pd *who, t_symbol *s)
@@ -335,9 +335,9 @@ t_outlet *canvas_addoutlet(t_canvas *x, t_pd *who, t_symbol *s)
t_outlet *op = outlet_new(&x->gl_obj, s);
if (!x->gl_loading && x->gl_owner && glist_isvisible(x->gl_owner))
{
- gobj_vis(&x->gl_gobj, x->gl_owner, 0);
- gobj_vis(&x->gl_gobj, x->gl_owner, 1);
- canvas_fixlinesfor(x->gl_owner, &x->gl_obj);
+ gobj_vis(&x->gl_gobj, x->gl_owner, 0);
+ gobj_vis(&x->gl_gobj, x->gl_owner, 1);
+ canvas_fixlinesfor(x->gl_owner, &x->gl_obj);
}
if (!x->gl_loading) canvas_resortoutlets(x);
return (op);
@@ -347,17 +347,17 @@ void canvas_rmoutlet(t_canvas *x, t_outlet *op)
{
t_canvas *owner = x->gl_owner;
int redraw = (owner && glist_isvisible(owner) && (!owner->gl_isdeleting)
- && glist_istoplevel(owner));
+ && glist_istoplevel(owner));
if (owner) canvas_deletelinesforio(owner, &x->gl_obj, 0, op);
if (redraw)
- gobj_vis(&x->gl_gobj, x->gl_owner, 0);
+ gobj_vis(&x->gl_gobj, x->gl_owner, 0);
outlet_free(op);
if (redraw)
{
- gobj_vis(&x->gl_gobj, x->gl_owner, 1);
- canvas_fixlinesfor(x->gl_owner, &x->gl_obj);
+ gobj_vis(&x->gl_gobj, x->gl_owner, 1);
+ canvas_fixlinesfor(x->gl_owner, &x->gl_obj);
}
}
@@ -370,37 +370,37 @@ void canvas_resortoutlets(t_canvas *x)
t_gobj *y, **vec, **vp, **maxp;
for (noutlets = 0, y = x->gl_list; y; y = y->g_next)
- if (pd_class(&y->g_pd) == voutlet_class) noutlets++;
+ if (pd_class(&y->g_pd) == voutlet_class) noutlets++;
if (noutlets < 2) return;
vec = (t_gobj **)getbytes(noutlets * sizeof(*vec));
for (y = x->gl_list, vp = vec; y; y = y->g_next)
- if (pd_class(&y->g_pd) == voutlet_class) *vp++ = y;
+ if (pd_class(&y->g_pd) == voutlet_class) *vp++ = y;
for (i = noutlets; i--;)
{
- t_outlet *ip;
- for (vp = vec, xmax = -0x7fffffff, maxp = 0, j = noutlets;
- j--; vp++)
- {
- int x1, y1, x2, y2;
- t_gobj *g = *vp;
- if (!g) continue;
- gobj_getrect(g, x, &x1, &y1, &x2, &y2);
- if (x1 > xmax) xmax = x1, maxp = vp;
- }
- if (!maxp) break;
- y = *maxp;
- *maxp = 0;
- ip = voutlet_getit(&y->g_pd);
-
- obj_moveoutletfirst(&x->gl_obj, ip);
+ t_outlet *ip;
+ for (vp = vec, xmax = -0x7fffffff, maxp = 0, j = noutlets;
+ j--; vp++)
+ {
+ int x1, y1, x2, y2;
+ t_gobj *g = *vp;
+ if (!g) continue;
+ gobj_getrect(g, x, &x1, &y1, &x2, &y2);
+ if (x1 > xmax) xmax = x1, maxp = vp;
+ }
+ if (!maxp) break;
+ y = *maxp;
+ *maxp = 0;
+ ip = voutlet_getit(&y->g_pd);
+
+ obj_moveoutletfirst(&x->gl_obj, ip);
}
freebytes(vec, noutlets * sizeof(*vec));
if (x->gl_owner && glist_isvisible(x->gl_owner))
- canvas_fixlinesfor(x->gl_owner, &x->gl_obj);
+ canvas_fixlinesfor(x->gl_owner, &x->gl_obj);
}
/* ----------calculating coordinates and controlling appearance --------- */
@@ -414,11 +414,11 @@ static void graph_bounds(t_glist *x, t_floatarg x1, t_floatarg y1,
x->gl_y1 = y1;
x->gl_y2 = y2;
if (x->gl_x2 == x->gl_x1 ||
- x->gl_y2 == x->gl_y1)
+ x->gl_y2 == x->gl_y1)
{
- error("graph: empty bounds rectangle");
- x1 = y1 = 0;
- x2 = y2 = 1;
+ error("graph: empty bounds rectangle");
+ x1 = y1 = 0;
+ x2 = y2 = 1;
}
glist_redraw(x);
}
@@ -447,12 +447,12 @@ static void graph_xlabel(t_glist *x, t_symbol *s, int argc, t_atom *argv)
if (argc < 1) error("graph_xlabel: no y value given");
else
{
- x->gl_xlabely = atom_getfloat(argv);
- argv++; argc--;
- x->gl_xlabel = (t_symbol **)t_resizebytes(x->gl_xlabel,
- x->gl_nxlabels * sizeof (t_symbol *), argc * sizeof (t_symbol *));
- x->gl_nxlabels = argc;
- for (i = 0; i < argc; i++) x->gl_xlabel[i] = atom_gensym(&argv[i]);
+ x->gl_xlabely = atom_getfloat(argv);
+ argv++; argc--;
+ x->gl_xlabel = (t_symbol **)t_resizebytes(x->gl_xlabel,
+ x->gl_nxlabels * sizeof (t_symbol *), argc * sizeof (t_symbol *));
+ x->gl_nxlabels = argc;
+ for (i = 0; i < argc; i++) x->gl_xlabel[i] = atom_gensym(&argv[i]);
}
glist_redraw(x);
}
@@ -463,12 +463,12 @@ static void graph_ylabel(t_glist *x, t_symbol *s, int argc, t_atom *argv)
if (argc < 1) error("graph_ylabel: no x value given");
else
{
- x->gl_ylabelx = atom_getfloat(argv);
- argv++; argc--;
- x->gl_ylabel = (t_symbol **)t_resizebytes(x->gl_ylabel,
- x->gl_nylabels * sizeof (t_symbol *), argc * sizeof (t_symbol *));
- x->gl_nylabels = argc;
- for (i = 0; i < argc; i++) x->gl_ylabel[i] = atom_gensym(&argv[i]);
+ x->gl_ylabelx = atom_getfloat(argv);
+ argv++; argc--;
+ x->gl_ylabel = (t_symbol **)t_resizebytes(x->gl_ylabel,
+ x->gl_nylabels * sizeof (t_symbol *), argc * sizeof (t_symbol *));
+ x->gl_nylabels = argc;
+ for (i = 0; i < argc; i++) x->gl_ylabel[i] = atom_gensym(&argv[i]);
}
glist_redraw(x);
}
@@ -478,28 +478,28 @@ static void graph_ylabel(t_glist *x, t_symbol *s, int argc, t_atom *argv)
/* convert an x pixel value to an x coordinate value */
float glist_pixelstox(t_glist *x, float xpix)
{
- /* if we appear as a text box on parent, our range in our
- coordinates (x1, etc.) specifies the coordinate range
- of a one-pixel square at top left of the window. */
+ /* if we appear as a text box on parent, our range in our
+ coordinates (x1, etc.) specifies the coordinate range
+ of a one-pixel square at top left of the window. */
if (!x->gl_isgraph)
- return (x->gl_x1 + (x->gl_x2 - x->gl_x1) * xpix);
+ return (x->gl_x1 + (x->gl_x2 - x->gl_x1) * xpix);
- /* if we're a graph when shown on parent, but own our own
- window right now, our range in our coordinates (x1, etc.) is spread
- over the visible window size, given by screenx1, etc. */
+ /* if we're a graph when shown on parent, but own our own
+ window right now, our range in our coordinates (x1, etc.) is spread
+ over the visible window size, given by screenx1, etc. */
else if (x->gl_isgraph && x->gl_havewindow)
- return (x->gl_x1 + (x->gl_x2 - x->gl_x1) *
+ return (x->gl_x1 + (x->gl_x2 - x->gl_x1) *
(xpix) / (x->gl_screenx2 - x->gl_screenx1));
- /* otherwise, we appear in a graph within a parent glist,
- so get our screen rectangle on parent and transform. */
+ /* otherwise, we appear in a graph within a parent glist,
+ so get our screen rectangle on parent and transform. */
else
{
- int x1, y1, x2, y2;
- if (!x->gl_owner)
- bug("glist_pixelstox");
- graph_graphrect(&x->gl_gobj, x->gl_owner, &x1, &y1, &x2, &y2);
- return (x->gl_x1 + (x->gl_x2 - x->gl_x1) *
+ int x1, y1, x2, y2;
+ if (!x->gl_owner)
+ bug("glist_pixelstox");
+ graph_graphrect(&x->gl_gobj, x->gl_owner, &x1, &y1, &x2, &y2);
+ return (x->gl_x1 + (x->gl_x2 - x->gl_x1) *
(xpix - x1) / (x2 - x1));
}
}
@@ -507,17 +507,17 @@ float glist_pixelstox(t_glist *x, float xpix)
float glist_pixelstoy(t_glist *x, float ypix)
{
if (!x->gl_isgraph)
- return (x->gl_y1 + (x->gl_y2 - x->gl_y1) * ypix);
+ return (x->gl_y1 + (x->gl_y2 - x->gl_y1) * ypix);
else if (x->gl_isgraph && x->gl_havewindow)
- return (x->gl_y1 + (x->gl_y2 - x->gl_y1) *
- (ypix) / (x->gl_screeny2 - x->gl_screeny1));
+ return (x->gl_y1 + (x->gl_y2 - x->gl_y1) *
+ (ypix) / (x->gl_screeny2 - x->gl_screeny1));
else
{
- int x1, y1, x2, y2;
- if (!x->gl_owner)
- bug("glist_pixelstox");
- graph_graphrect(&x->gl_gobj, x->gl_owner, &x1, &y1, &x2, &y2);
- return (x->gl_y1 + (x->gl_y2 - x->gl_y1) *
+ int x1, y1, x2, y2;
+ if (!x->gl_owner)
+ bug("glist_pixelstox");
+ graph_graphrect(&x->gl_gobj, x->gl_owner, &x1, &y1, &x2, &y2);
+ return (x->gl_y1 + (x->gl_y2 - x->gl_y1) *
(ypix - y1) / (y2 - y1));
}
}
@@ -526,34 +526,34 @@ float glist_pixelstoy(t_glist *x, float ypix)
float glist_xtopixels(t_glist *x, float xval)
{
if (!x->gl_isgraph)
- return ((xval - x->gl_x1) / (x->gl_x2 - x->gl_x1));
+ return ((xval - x->gl_x1) / (x->gl_x2 - x->gl_x1));
else if (x->gl_isgraph && x->gl_havewindow)
- return (x->gl_screenx2 - x->gl_screenx1) *
- (xval - x->gl_x1) / (x->gl_x2 - x->gl_x1);
+ return (x->gl_screenx2 - x->gl_screenx1) *
+ (xval - x->gl_x1) / (x->gl_x2 - x->gl_x1);
else
{
- int x1, y1, x2, y2;
- if (!x->gl_owner)
- bug("glist_pixelstox");
- graph_graphrect(&x->gl_gobj, x->gl_owner, &x1, &y1, &x2, &y2);
- return (x1 + (x2 - x1) * (xval - x->gl_x1) / (x->gl_x2 - x->gl_x1));
+ int x1, y1, x2, y2;
+ if (!x->gl_owner)
+ bug("glist_pixelstox");
+ graph_graphrect(&x->gl_gobj, x->gl_owner, &x1, &y1, &x2, &y2);
+ return (x1 + (x2 - x1) * (xval - x->gl_x1) / (x->gl_x2 - x->gl_x1));
}
}
float glist_ytopixels(t_glist *x, float yval)
{
if (!x->gl_isgraph)
- return ((yval - x->gl_y1) / (x->gl_y2 - x->gl_y1));
+ return ((yval - x->gl_y1) / (x->gl_y2 - x->gl_y1));
else if (x->gl_isgraph && x->gl_havewindow)
- return (x->gl_screeny2 - x->gl_screeny1) *
- (yval - x->gl_y1) / (x->gl_y2 - x->gl_y1);
+ return (x->gl_screeny2 - x->gl_screeny1) *
+ (yval - x->gl_y1) / (x->gl_y2 - x->gl_y1);
else
{
- int x1, y1, x2, y2;
- if (!x->gl_owner)
- bug("glist_pixelstox");
- graph_graphrect(&x->gl_gobj, x->gl_owner, &x1, &y1, &x2, &y2);
- return (y1 + (y2 - y1) * (yval - x->gl_y1) / (x->gl_y2 - x->gl_y1));
+ int x1, y1, x2, y2;
+ if (!x->gl_owner)
+ bug("glist_pixelstox");
+ graph_graphrect(&x->gl_gobj, x->gl_owner, &x1, &y1, &x2, &y2);
+ return (y1 + (y2 - y1) * (yval - x->gl_y1) / (x->gl_y2 - x->gl_y1));
}
}
@@ -577,19 +577,19 @@ float glist_dpixtody(t_glist *x, float dypix)
int text_xpix(t_text *x, t_glist *glist)
{
if (glist->gl_havewindow || !glist->gl_isgraph)
- return (x->te_xpix);
+ return (x->te_xpix);
else return (glist_xtopixels(glist,
- glist->gl_x1 + (glist->gl_x2 - glist->gl_x1) *
- x->te_xpix / (glist->gl_screenx2 - glist->gl_screenx1)));
+ glist->gl_x1 + (glist->gl_x2 - glist->gl_x1) *
+ x->te_xpix / (glist->gl_screenx2 - glist->gl_screenx1)));
}
int text_ypix(t_text *x, t_glist *glist)
{
if (glist->gl_havewindow || !glist->gl_isgraph)
- return (x->te_ypix);
+ return (x->te_ypix);
else return (glist_ytopixels(glist,
- glist->gl_y1 + (glist->gl_y2 - glist->gl_y1) *
- x->te_ypix / (glist->gl_screeny2 - glist->gl_screeny1)));
+ glist->gl_y1 + (glist->gl_y2 - glist->gl_y1) *
+ x->te_ypix / (glist->gl_screeny2 - glist->gl_screeny1)));
}
/* redraw all the items in a glist. We construe this to mean
@@ -600,29 +600,29 @@ void glist_redraw(t_glist *x)
{
if (glist_isvisible(x))
{
- /* LATER fix the graph_vis() code to handle both cases */
- if (glist_istoplevel(x))
- {
- t_gobj *g;
- t_linetraverser t;
- t_outconnect *oc;
- for (g = x->gl_list; g; g = g->g_next)
- {
- gobj_vis(g, x, 0);
- gobj_vis(g, x, 1);
- }
- /* redraw all the lines */
- linetraverser_start(&t, x);
- while (oc = linetraverser_next(&t))
- sys_vgui(".x%x.c coords l%x %d %d %d %d\n",
- glist_getcanvas(x), oc,
- t.tr_lx1, t.tr_ly1, t.tr_lx2, t.tr_ly2);
- }
- if (x->gl_owner)
- {
- graph_vis(&x->gl_gobj, x->gl_owner, 0);
- graph_vis(&x->gl_gobj, x->gl_owner, 1);
- }
+ /* LATER fix the graph_vis() code to handle both cases */
+ if (glist_istoplevel(x))
+ {
+ t_gobj *g;
+ t_linetraverser t;
+ t_outconnect *oc;
+ for (g = x->gl_list; g; g = g->g_next)
+ {
+ gobj_vis(g, x, 0);
+ gobj_vis(g, x, 1);
+ }
+ /* redraw all the lines */
+ linetraverser_start(&t, x);
+ while (oc = linetraverser_next(&t))
+ sys_vgui(".x%lx.c coords l%lx %d %d %d %d\n",
+ glist_getcanvas(x), oc,
+ t.tr_lx1, t.tr_ly1, t.tr_lx2, t.tr_ly2);
+ }
+ if (x->gl_owner)
+ {
+ graph_vis(&x->gl_gobj, x->gl_owner, 0);
+ graph_vis(&x->gl_gobj, x->gl_owner, 1);
+ }
}
}
@@ -638,157 +638,157 @@ static void graph_vis(t_gobj *gr, t_glist *parent_glist, int vis)
char tag[50];
t_gobj *g;
int x1, y1, x2, y2;
- /* ordinary subpatches: just act like a text object */
+ /* ordinary subpatches: just act like a text object */
if (!x->gl_isgraph)
{
- text_widgetbehavior.w_visfn(gr, parent_glist, vis);
- return;
+ text_widgetbehavior.w_visfn(gr, parent_glist, vis);
+ return;
}
if (vis && canvas_showtext(x))
- rtext_draw(glist_findrtext(parent_glist, &x->gl_obj));
+ rtext_draw(glist_findrtext(parent_glist, &x->gl_obj));
graph_getrect(gr, parent_glist, &x1, &y1, &x2, &y2);
if (!vis)
- rtext_erase(glist_findrtext(parent_glist, &x->gl_obj));
+ rtext_erase(glist_findrtext(parent_glist, &x->gl_obj));
- sprintf(tag, "graph%x", (int)x);
+ sprintf(tag, "graph%lx", (t_int)x);
if (vis)
- glist_drawiofor(parent_glist, &x->gl_obj, 1,
- tag, x1, y1, x2, y2);
+ glist_drawiofor(parent_glist, &x->gl_obj, 1,
+ tag, x1, y1, x2, y2);
else glist_eraseiofor(parent_glist, &x->gl_obj, tag);
- /* if we look like a graph but have been moved to a toplevel,
- just show the bounding rectangle */
+ /* if we look like a graph but have been moved to a toplevel,
+ just show the bounding rectangle */
if (x->gl_havewindow)
{
- if (vis)
- {
- sys_vgui(".x%x.c create polygon\
+ if (vis)
+ {
+ sys_vgui(".x%lx.c create polygon\
%d %d %d %d %d %d %d %d %d %d -tags %s -fill #c0c0c0\n",
- glist_getcanvas(x->gl_owner),
- x1, y1, x1, y2, x2, y2, x2, y1, x1, y1, tag);
- }
- else
- {
- sys_vgui(".x%x.c delete %s\n",
- glist_getcanvas(x->gl_owner), tag);
- }
- return;
+ glist_getcanvas(x->gl_owner),
+ x1, y1, x1, y2, x2, y2, x2, y1, x1, y1, tag);
+ }
+ else
+ {
+ sys_vgui(".x%lx.c delete %s\n",
+ glist_getcanvas(x->gl_owner), tag);
+ }
+ return;
}
- /* otherwise draw (or erase) us as a graph inside another glist. */
+ /* otherwise draw (or erase) us as a graph inside another glist. */
if (vis)
{
- int i;
- float f;
-
- /* draw a rectangle around the graph */
- sys_vgui(".x%x.c create line\
- %d %d %d %d %d %d %d %d %d %d -tags %s\n",
- glist_getcanvas(x->gl_owner),
- x1, y1, x1, y2, x2, y2, x2, y1, x1, y1, tag);
-
- /* draw ticks on horizontal borders. If lperb field is
- zero, this is disabled. */
- if (x->gl_xtick.k_lperb)
- {
- float upix, lpix;
- if (y2 < y1)
- upix = y1, lpix = y2;
- else upix = y2, lpix = y1;
- for (i = 0, f = x->gl_xtick.k_point;
- f < 0.99 * x->gl_x2 + 0.01*x->gl_x1; i++,
- f += x->gl_xtick.k_inc)
- {
- int tickpix = (i % x->gl_xtick.k_lperb ? 2 : 4);
- sys_vgui(".x%x.c create line %d %d %d %d -tags %s\n",
- glist_getcanvas(x->gl_owner),
- (int)glist_xtopixels(x, f), (int)upix,
- (int)glist_xtopixels(x, f), (int)upix - tickpix, tag);
- sys_vgui(".x%x.c create line %d %d %d %d -tags %s\n",
- glist_getcanvas(x->gl_owner),
- (int)glist_xtopixels(x, f), (int)lpix,
- (int)glist_xtopixels(x, f), (int)lpix + tickpix, tag);
- }
- for (i = 1, f = x->gl_xtick.k_point - x->gl_xtick.k_inc;
- f > 0.99 * x->gl_x1 + 0.01*x->gl_x2;
- i++, f -= x->gl_xtick.k_inc)
- {
- int tickpix = (i % x->gl_xtick.k_lperb ? 2 : 4);
- sys_vgui(".x%x.c create line %d %d %d %d -tags %s\n",
- glist_getcanvas(x->gl_owner),
- (int)glist_xtopixels(x, f), (int)upix,
- (int)glist_xtopixels(x, f), (int)upix - tickpix, tag);
- sys_vgui(".x%x.c create line %d %d %d %d -tags %s\n",
- glist_getcanvas(x->gl_owner),
- (int)glist_xtopixels(x, f), (int)lpix,
- (int)glist_xtopixels(x, f), (int)lpix + tickpix, tag);
- }
- }
-
- /* draw ticks in vertical borders*/
- if (x->gl_ytick.k_lperb)
- {
- float ubound, lbound;
- if (x->gl_y2 < x->gl_y1)
- ubound = x->gl_y1, lbound = x->gl_y2;
- else ubound = x->gl_y2, lbound = x->gl_y1;
- for (i = 0, f = x->gl_ytick.k_point;
- f < 0.99 * ubound + 0.01 * lbound;
- i++, f += x->gl_ytick.k_inc)
- {
- int tickpix = (i % x->gl_ytick.k_lperb ? 2 : 4);
- sys_vgui(".x%x.c create line %d %d %d %d -tags %s\n",
- glist_getcanvas(x->gl_owner),
- x1, (int)glist_ytopixels(x, f),
- x1 + tickpix, (int)glist_ytopixels(x, f), tag);
- sys_vgui(".x%x.c create line %d %d %d %d -tags %s\n",
- glist_getcanvas(x->gl_owner),
- x2, (int)glist_ytopixels(x, f),
- x2 - tickpix, (int)glist_ytopixels(x, f), tag);
- }
- for (i = 1, f = x->gl_ytick.k_point - x->gl_ytick.k_inc;
- f > 0.99 * lbound + 0.01 * ubound;
- i++, f -= x->gl_ytick.k_inc)
- {
- int tickpix = (i % x->gl_ytick.k_lperb ? 2 : 4);
- sys_vgui(".x%x.c create line %d %d %d %d -tags %s\n",
- glist_getcanvas(x->gl_owner),
- x1, (int)glist_ytopixels(x, f),
- x1 + tickpix, (int)glist_ytopixels(x, f), tag);
- sys_vgui(".x%x.c create line %d %d %d %d -tags %s\n",
- glist_getcanvas(x->gl_owner),
- x2, (int)glist_ytopixels(x, f),
- x2 - tickpix, (int)glist_ytopixels(x, f), tag);
- }
- }
- /* draw x labels */
- for (i = 0; i < x->gl_nxlabels; i++)
- sys_vgui(".x%x.c create text\
- %d %d -text {%s} -font -*-courier-bold--normal--%d-* -tags %s\n",
- glist_getcanvas(x),
- (int)glist_xtopixels(x, atof(x->gl_xlabel[i]->s_name)),
- (int)glist_ytopixels(x, x->gl_xlabely), x->gl_xlabel[i]->s_name,
- glist_getfont(x), tag);
-
- /* draw y labels */
- for (i = 0; i < x->gl_nylabels; i++)
- sys_vgui(".x%x.c create text\
- %d %d -text {%s} -font -*-courier-bold--normal--%d-* -tags %s\n",
- glist_getcanvas(x),
- (int)glist_xtopixels(x, x->gl_ylabelx),
- (int)glist_ytopixels(x, atof(x->gl_ylabel[i]->s_name)),
- x->gl_ylabel[i]->s_name,
- glist_getfont(x), tag);
-
- /* draw contents of graph as glist */
- for (g = x->gl_list; g; g = g->g_next)
- gobj_vis(g, x, 1);
+ int i;
+ float f;
+
+ /* draw a rectangle around the graph */
+ sys_vgui(".x%lx.c create line\
+ %d %d %d %d %d %d %d %d %d %d -tags %s\n",
+ glist_getcanvas(x->gl_owner),
+ x1, y1, x1, y2, x2, y2, x2, y1, x1, y1, tag);
+
+ /* draw ticks on horizontal borders. If lperb field is
+ zero, this is disabled. */
+ if (x->gl_xtick.k_lperb)
+ {
+ float upix, lpix;
+ if (y2 < y1)
+ upix = y1, lpix = y2;
+ else upix = y2, lpix = y1;
+ for (i = 0, f = x->gl_xtick.k_point;
+ f < 0.99 * x->gl_x2 + 0.01*x->gl_x1; i++,
+ f += x->gl_xtick.k_inc)
+ {
+ int tickpix = (i % x->gl_xtick.k_lperb ? 2 : 4);
+ sys_vgui(".x%lx.c create line %d %d %d %d -tags %s\n",
+ glist_getcanvas(x->gl_owner),
+ (int)glist_xtopixels(x, f), (int)upix,
+ (int)glist_xtopixels(x, f), (int)upix - tickpix, tag);
+ sys_vgui(".x%lx.c create line %d %d %d %d -tags %s\n",
+ glist_getcanvas(x->gl_owner),
+ (int)glist_xtopixels(x, f), (int)lpix,
+ (int)glist_xtopixels(x, f), (int)lpix + tickpix, tag);
+ }
+ for (i = 1, f = x->gl_xtick.k_point - x->gl_xtick.k_inc;
+ f > 0.99 * x->gl_x1 + 0.01*x->gl_x2;
+ i++, f -= x->gl_xtick.k_inc)
+ {
+ int tickpix = (i % x->gl_xtick.k_lperb ? 2 : 4);
+ sys_vgui(".x%lx.c create line %d %d %d %d -tags %s\n",
+ glist_getcanvas(x->gl_owner),
+ (int)glist_xtopixels(x, f), (int)upix,
+ (int)glist_xtopixels(x, f), (int)upix - tickpix, tag);
+ sys_vgui(".x%lx.c create line %d %d %d %d -tags %s\n",
+ glist_getcanvas(x->gl_owner),
+ (int)glist_xtopixels(x, f), (int)lpix,
+ (int)glist_xtopixels(x, f), (int)lpix + tickpix, tag);
+ }
+ }
+
+ /* draw ticks in vertical borders*/
+ if (x->gl_ytick.k_lperb)
+ {
+ float ubound, lbound;
+ if (x->gl_y2 < x->gl_y1)
+ ubound = x->gl_y1, lbound = x->gl_y2;
+ else ubound = x->gl_y2, lbound = x->gl_y1;
+ for (i = 0, f = x->gl_ytick.k_point;
+ f < 0.99 * ubound + 0.01 * lbound;
+ i++, f += x->gl_ytick.k_inc)
+ {
+ int tickpix = (i % x->gl_ytick.k_lperb ? 2 : 4);
+ sys_vgui(".x%lx.c create line %d %d %d %d -tags %s\n",
+ glist_getcanvas(x->gl_owner),
+ x1, (int)glist_ytopixels(x, f),
+ x1 + tickpix, (int)glist_ytopixels(x, f), tag);
+ sys_vgui(".x%lx.c create line %d %d %d %d -tags %s\n",
+ glist_getcanvas(x->gl_owner),
+ x2, (int)glist_ytopixels(x, f),
+ x2 - tickpix, (int)glist_ytopixels(x, f), tag);
+ }
+ for (i = 1, f = x->gl_ytick.k_point - x->gl_ytick.k_inc;
+ f > 0.99 * lbound + 0.01 * ubound;
+ i++, f -= x->gl_ytick.k_inc)
+ {
+ int tickpix = (i % x->gl_ytick.k_lperb ? 2 : 4);
+ sys_vgui(".x%lx.c create line %d %d %d %d -tags %s\n",
+ glist_getcanvas(x->gl_owner),
+ x1, (int)glist_ytopixels(x, f),
+ x1 + tickpix, (int)glist_ytopixels(x, f), tag);
+ sys_vgui(".x%lx.c create line %d %d %d %d -tags %s\n",
+ glist_getcanvas(x->gl_owner),
+ x2, (int)glist_ytopixels(x, f),
+ x2 - tickpix, (int)glist_ytopixels(x, f), tag);
+ }
+ }
+ /* draw x labels */
+ for (i = 0; i < x->gl_nxlabels; i++)
+ sys_vgui(".x%lx.c create text\
+ %d %d -text {%s} -font -*-courier-bold--normal--%d-* -tags %s\n",
+ glist_getcanvas(x),
+ (int)glist_xtopixels(x, atof(x->gl_xlabel[i]->s_name)),
+ (int)glist_ytopixels(x, x->gl_xlabely), x->gl_xlabel[i]->s_name,
+ glist_getfont(x), tag);
+
+ /* draw y labels */
+ for (i = 0; i < x->gl_nylabels; i++)
+ sys_vgui(".x%lx.c create text\
+ %d %d -text {%s} -font -*-courier-bold--normal--%d-* -tags %s\n",
+ glist_getcanvas(x),
+ (int)glist_xtopixels(x, x->gl_ylabelx),
+ (int)glist_ytopixels(x, atof(x->gl_ylabel[i]->s_name)),
+ x->gl_ylabel[i]->s_name,
+ glist_getfont(x), tag);
+
+ /* draw contents of graph as glist */
+ for (g = x->gl_list; g; g = g->g_next)
+ gobj_vis(g, x, 1);
}
else
{
- sys_vgui(".x%x.c delete %s\n",
- glist_getcanvas(x->gl_owner), tag);
- for (g = x->gl_list; g; g = g->g_next)
- gobj_vis(g, x, 0);
+ sys_vgui(".x%lx.c delete %s\n",
+ glist_getcanvas(x->gl_owner), tag);
+ for (g = x->gl_list; g; g = g->g_next)
+ gobj_vis(g, x, 0);
}
}
@@ -802,24 +802,24 @@ static void graph_graphrect(t_gobj *z, t_glist *glist,
int x1 = text_xpix(&x->gl_obj, glist);
int y1 = text_ypix(&x->gl_obj, glist);
int x2, y2;
-#if 0 /* this used to adjust graph size when it was in another graph;
- now we just preserve the size. */
- /* same logic here as in text_xpix(): */
+#if 0 /* this used to adjust graph size when it was in another graph;
+ now we just preserve the size. */
+ /* same logic here as in text_xpix(): */
if (glist->gl_havewindow)
{
- x2 = x1 + x->gl_pixwidth;
- y2 = y1 + x->gl_pixheight;
+ x2 = x1 + x->gl_pixwidth;
+ y2 = y1 + x->gl_pixheight;
}
else
{
- x2 = glist_xtopixels(glist,
- glist->gl_x1 + (glist->gl_x2 - glist->gl_x1) *
- (x->gl_obj.te_xpix + x->gl_pixwidth) /
- (glist->gl_screenx2 - glist->gl_screenx1));
- y2 = glist_ytopixels(glist,
- glist->gl_y1 + (glist->gl_y2 - glist->gl_y1) *
- (x->gl_obj.te_ypix + x->gl_pixheight) /
- (glist->gl_screeny2 - glist->gl_screeny1));
+ x2 = glist_xtopixels(glist,
+ glist->gl_x1 + (glist->gl_x2 - glist->gl_x1) *
+ (x->gl_obj.te_xpix + x->gl_pixwidth) /
+ (glist->gl_screenx2 - glist->gl_screenx1));
+ y2 = glist_ytopixels(glist,
+ glist->gl_y1 + (glist->gl_y2 - glist->gl_y1) *
+ (x->gl_obj.te_ypix + x->gl_pixheight) /
+ (glist->gl_screeny2 - glist->gl_screeny1));
}
#endif
x2 = x1 + x->gl_pixwidth;
@@ -840,38 +840,38 @@ static void graph_getrect(t_gobj *z, t_glist *glist,
t_glist *x = (t_glist *)z;
if (x->gl_isgraph)
{
- int hadwindow;
- t_gobj *g;
- t_text *ob;
- int x21, y21, x22, y22;
-
- graph_graphrect(z, glist, &x1, &y1, &x2, &y2);
- if (canvas_showtext(x))
- {
- text_widgetbehavior.w_getrectfn(z, glist, &x21, &y21, &x22, &y22);
- if (x22 > x2)
- x2 = x22;
- if (y22 > y2)
- y2 = y22;
- }
- /* lie about whether we have our own window to affect gobj_getrect
- calls below. (LATER add argument to gobj_getrect()?) */
- hadwindow = x->gl_havewindow;
- x->gl_havewindow = 0;
- for (g = x->gl_list; g; g = g->g_next)
- if ((!(ob = pd_checkobject(&g->g_pd))) || text_shouldvis(ob, x))
- {
- /* don't do this for arrays, just let them hang outsize the
- box. */
- if (pd_class(&g->g_pd) == garray_class)
- continue;
- gobj_getrect(g, x, &x21, &y21, &x22, &y22);
- if (x22 > x2)
- x2 = x22;
- if (y22 > y2)
- y2 = y22;
- }
- x->gl_havewindow = hadwindow;
+ int hadwindow;
+ t_gobj *g;
+ t_text *ob;
+ int x21, y21, x22, y22;
+
+ graph_graphrect(z, glist, &x1, &y1, &x2, &y2);
+ if (canvas_showtext(x))
+ {
+ text_widgetbehavior.w_getrectfn(z, glist, &x21, &y21, &x22, &y22);
+ if (x22 > x2)
+ x2 = x22;
+ if (y22 > y2)
+ y2 = y22;
+ }
+ /* lie about whether we have our own window to affect gobj_getrect
+ calls below. (LATER add argument to gobj_getrect()?) */
+ hadwindow = x->gl_havewindow;
+ x->gl_havewindow = 0;
+ for (g = x->gl_list; g; g = g->g_next)
+ if ((!(ob = pd_checkobject(&g->g_pd))) || text_shouldvis(ob, x))
+ {
+ /* don't do this for arrays, just let them hang outsize the
+ box. */
+ if (pd_class(&g->g_pd) == garray_class)
+ continue;
+ gobj_getrect(g, x, &x21, &y21, &x22, &y22);
+ if (x22 > x2)
+ x2 = x22;
+ if (y22 > y2)
+ y2 = y22;
+ }
+ x->gl_havewindow = hadwindow;
}
else text_widgetbehavior.w_getrectfn(z, glist, &x1, &y1, &x2, &y2);
*xp1 = x1;
@@ -884,13 +884,13 @@ static void graph_displace(t_gobj *z, t_glist *glist, int dx, int dy)
{
t_glist *x = (t_glist *)z;
if (!x->gl_isgraph)
- text_widgetbehavior.w_displacefn(z, glist, dx, dy);
+ text_widgetbehavior.w_displacefn(z, glist, dx, dy);
else
{
- x->gl_obj.te_xpix += dx;
- x->gl_obj.te_ypix += dy;
- glist_redraw(x);
- canvas_fixlinesfor(glist_getcanvas(glist), &x->gl_obj);
+ x->gl_obj.te_xpix += dx;
+ x->gl_obj.te_ypix += dy;
+ glist_redraw(x);
+ canvas_fixlinesfor(glist_getcanvas(glist), &x->gl_obj);
}
}
@@ -898,16 +898,16 @@ static void graph_select(t_gobj *z, t_glist *glist, int state)
{
t_glist *x = (t_glist *)z;
if (!x->gl_isgraph)
- text_widgetbehavior.w_selectfn(z, glist, state);
+ text_widgetbehavior.w_selectfn(z, glist, state);
else
{
- t_rtext *y = glist_findrtext(glist, &x->gl_obj);
- if (canvas_showtext(x))
- rtext_select(y, state);
- sys_vgui(".x%x.c itemconfigure %sR -fill %s\n", glist,
- rtext_gettag(y), (state? "blue" : "black"));
- sys_vgui(".x%x.c itemconfigure graph%x -fill %s\n",
- glist_getcanvas(glist), z, (state? "blue" : "black"));
+ t_rtext *y = glist_findrtext(glist, &x->gl_obj);
+ if (canvas_showtext(x))
+ rtext_select(y, state);
+ sys_vgui(".x%lx.c itemconfigure %sR -fill %s\n", glist,
+ rtext_gettag(y), (state? "blue" : "black"));
+ sys_vgui(".x%lx.c itemconfigure graph%lx -fill %s\n",
+ glist_getcanvas(glist), z, (state? "blue" : "black"));
}
}
@@ -915,7 +915,7 @@ static void graph_activate(t_gobj *z, t_glist *glist, int state)
{
t_glist *x = (t_glist *)z;
if (canvas_showtext(x))
- text_widgetbehavior.w_activatefn(z, glist, state);
+ text_widgetbehavior.w_activatefn(z, glist, state);
}
#if 0
@@ -923,14 +923,14 @@ static void graph_delete(t_gobj *z, t_glist *glist)
{
t_glist *x = (t_glist *)z;
if (!x->gl_isgraph)
- text_widgetbehavior.w_deletefn(z, glist);
+ text_widgetbehavior.w_deletefn(z, glist);
else
{
- t_gobj *y;
- while (y = x->gl_list) glist_delete(x, y);
-#if 0 /* I think this was just wrong. */
- if (glist_isvisible(x))
- sys_vgui(".x%x.c delete graph%x\n", glist_getcanvas(glist), x);
+ t_gobj *y;
+ while (y = x->gl_list) glist_delete(x, y);
+#if 0 /* I think this was just wrong. */
+ if (glist_isvisible(x))
+ sys_vgui(".x%lx.c delete graph%lx\n", glist_getcanvas(glist), x);
#endif
}
}
@@ -942,7 +942,7 @@ static void graph_delete(t_gobj *z, t_glist *glist)
t_gobj *y;
text_widgetbehavior.w_deletefn(z, glist);
while (y = x->gl_list)
- glist_delete(x, y);
+ glist_delete(x, y);
}
static float graph_lastxpix, graph_lastypix;
@@ -960,28 +960,28 @@ static void graph_motion(void *z, t_floatarg dx, t_floatarg dy)
float newy = glist_pixelstoy(x, newypix);
graph_lastxpix = newxpix;
graph_lastypix = newypix;
- /* verify that the array is OK */
+ /* verify that the array is OK */
if (!a || pd_class((t_pd *)a) != garray_class)
- return;
+ return;
if (!garray_getfloatarray(a, &nelem, &vec))
- return;
+ return;
if (oldx < 0) oldx = 0;
if (oldx >= nelem)
- oldx = nelem - 1;
+ oldx = nelem - 1;
if (newx < 0) newx = 0;
if (newx >= nelem)
- newx = nelem - 1;
+ newx = nelem - 1;
if (oldx < newx - 1)
{
- for (i = oldx + 1; i <= newx; i++)
- vec[i] = newy + (oldy - newy) *
- ((float)(newx - i))/(float)(newx - oldx);
+ for (i = oldx + 1; i <= newx; i++)
+ vec[i] = newy + (oldy - newy) *
+ ((float)(newx - i))/(float)(newx - oldx);
}
else if (oldx > newx + 1)
{
- for (i = oldx - 1; i >= newx; i--)
- vec[i] = newy + (oldy - newy) *
- ((float)(newx - i))/(float)(newx - oldx);
+ for (i = oldx - 1; i >= newx; i--)
+ vec[i] = newy + (oldy - newy) *
+ ((float)(newx - i))/(float)(newx - oldx);
}
else vec[newx] = newy;
garray_redraw(a);
@@ -994,28 +994,28 @@ static int graph_click(t_gobj *z, struct _glist *glist,
t_gobj *y;
int clickreturned = 0;
if (!x->gl_isgraph)
- return (text_widgetbehavior.w_clickfn(z, glist,
- xpix, ypix, shift, alt, dbl, doit));
+ return (text_widgetbehavior.w_clickfn(z, glist,
+ xpix, ypix, shift, alt, dbl, doit));
else if (x->gl_havewindow)
- return (0);
+ return (0);
else
{
- for (y = x->gl_list; y; y = y->g_next)
- {
- int x1, y1, x2, y2;
- /* check if the object wants to be clicked */
- if (canvas_hitbox(x, y, xpix, ypix, &x1, &y1, &x2, &y2)
- && (clickreturned = gobj_click(y, x, xpix, ypix,
- shift, alt, 0, doit)))
- break;
- }
- if (!doit)
- {
- if (y)
- canvas_setcursor(glist_getcanvas(x), clickreturned);
- else canvas_setcursor(glist_getcanvas(x), CURSOR_RUNMODE_NOTHING);
- }
- return (clickreturned);
+ for (y = x->gl_list; y; y = y->g_next)
+ {
+ int x1, y1, x2, y2;
+ /* check if the object wants to be clicked */
+ if (canvas_hitbox(x, y, xpix, ypix, &x1, &y1, &x2, &y2)
+ && (clickreturned = gobj_click(y, x, xpix, ypix,
+ shift, alt, 0, doit)))
+ break;
+ }
+ if (!doit)
+ {
+ if (y)
+ canvas_setcursor(glist_getcanvas(x), clickreturned);
+ else canvas_setcursor(glist_getcanvas(x), CURSOR_RUNMODE_NOTHING);
+ }
+ return (clickreturned);
}
}
@@ -1036,33 +1036,33 @@ void graph_properties(t_gobj *z, t_glist *owner)
{
t_glist *x = (t_glist *)z;
{
- t_gobj *y;
- char graphbuf[200];
- sprintf(graphbuf, "pdtk_graph_dialog %%s %g %g %g %g %d %d\n",
- x->gl_x1, x->gl_y1, x->gl_x2, x->gl_y2,
- x->gl_pixwidth, x->gl_pixheight);
- gfxstub_new(&x->gl_pd, x, graphbuf);
-
- for (y = x->gl_list; y; y = y->g_next)
- if (pd_class(&y->g_pd) == garray_class)
- garray_properties((t_garray *)y);
+ t_gobj *y;
+ char graphbuf[200];
+ sprintf(graphbuf, "pdtk_graph_dialog %%s %g %g %g %g %d %d\n",
+ x->gl_x1, x->gl_y1, x->gl_x2, x->gl_y2,
+ x->gl_pixwidth, x->gl_pixheight);
+ gfxstub_new(&x->gl_pd, x, graphbuf);
+
+ for (y = x->gl_list; y; y = y->g_next)
+ if (pd_class(&y->g_pd) == garray_class)
+ garray_properties((t_garray *)y);
}
}
/* find the graph most recently added to this glist;
- if none exists, return 0. */
+ if none exists, return 0. */
t_glist *glist_findgraph(t_glist *x)
{
t_gobj *y = 0, *z;
for (z = x->gl_list; z; z = z->g_next)
- if (pd_class(&z->g_pd) == canvas_class && ((t_glist *)z)->gl_isgraph)
- y = z;
+ if (pd_class(&z->g_pd) == canvas_class && ((t_glist *)z)->gl_isgraph)
+ y = z;
return ((t_glist *)y);
}
/* message back from dialog GUI to set parameters. Args are:
- 1-4: bounds in our coordinates; 5-6: size in parent */
+ 1-4: bounds in our coordinates; 5-6: size in parent */
static void graph_dialog(t_glist *x, t_symbol *s, int argc, t_atom *argv)
{
t_float x1 = atom_getfloatarg(0, argc, argv);
@@ -1072,15 +1072,15 @@ static void graph_dialog(t_glist *x, t_symbol *s, int argc, t_atom *argv)
t_float xpix = atom_getfloatarg(4, argc, argv);
t_float ypix = atom_getfloatarg(5, argc, argv);
if (x1 != x->gl_x1 || x2 != x->gl_x2 ||
- y1 != x->gl_y1 || y2 != x->gl_y2)
- graph_bounds(x, x1, y1, x2, y2);
+ y1 != x->gl_y1 || y2 != x->gl_y2)
+ graph_bounds(x, x1, y1, x2, y2);
if (xpix != x->gl_pixwidth || ypix != x->gl_pixheight)
{
- x->gl_pixwidth = xpix;
- x->gl_pixheight = ypix;
- glist_redraw(x);
- if (x->gl_owner)
- canvas_fixlinesfor(x->gl_owner, &x->gl_obj);
+ x->gl_pixwidth = xpix;
+ x->gl_pixheight = ypix;
+ glist_redraw(x);
+ if (x->gl_owner)
+ canvas_fixlinesfor(x->gl_owner, &x->gl_obj);
}
}
@@ -1090,23 +1090,23 @@ void g_graph_setup(void)
{
class_setwidget(canvas_class, &graph_widgetbehavior);
class_addmethod(canvas_class, (t_method)graph_bounds, gensym("bounds"),
- A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, 0);
+ A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, 0);
class_addmethod(canvas_class, (t_method)graph_xticks, gensym("xticks"),
- A_FLOAT, A_FLOAT, A_FLOAT, 0);
+ A_FLOAT, A_FLOAT, A_FLOAT, 0);
class_addmethod(canvas_class, (t_method)graph_xlabel, gensym("xlabel"),
- A_GIMME, 0);
+ A_GIMME, 0);
class_addmethod(canvas_class, (t_method)graph_yticks, gensym("yticks"),
- A_FLOAT, A_FLOAT, A_FLOAT, 0);
+ A_FLOAT, A_FLOAT, A_FLOAT, 0);
class_addmethod(canvas_class, (t_method)graph_ylabel, gensym("ylabel"),
- A_GIMME, 0);
+ A_GIMME, 0);
class_addmethod(canvas_class, (t_method)graph_array, gensym("array"),
- A_SYMBOL, A_FLOAT, A_SYMBOL, A_DEFFLOAT, A_NULL);
+ A_SYMBOL, A_FLOAT, A_SYMBOL, A_DEFFLOAT, A_NULL);
class_addmethod(canvas_class, (t_method)canvas_menuarray,
- gensym("menuarray"), A_NULL);
+ gensym("menuarray"), A_NULL);
class_addmethod(canvas_class, (t_method)graph_dialog, gensym("dialog"),
- A_GIMME, 0);
+ A_GIMME, 0);
class_addmethod(canvas_class, (t_method)glist_arraydialog,
- gensym("arraydialog"), A_SYMBOL, A_FLOAT, A_FLOAT, A_FLOAT, A_NULL);
+ gensym("arraydialog"), A_SYMBOL, A_FLOAT, A_FLOAT, A_FLOAT, A_NULL);
class_addmethod(canvas_class, (t_method)glist_sort,
- gensym("sort"), A_NULL);
+ gensym("sort"), A_NULL);
}
diff --git a/pd/src/g_guiconnect.c b/pd/src/g_guiconnect.c
index aef8acb6..561ee1a8 100644
--- a/pd/src/g_guiconnect.c
+++ b/pd/src/g_guiconnect.c
@@ -32,9 +32,9 @@ t_guiconnect *guiconnect_new(t_pd *who, t_symbol *sym)
static void guiconnect_free(t_guiconnect *x)
{
if (x->x_sym)
- pd_unbind(&x->x_obj.ob_pd, x->x_sym);
+ pd_unbind(&x->x_obj.ob_pd, x->x_sym);
if (x->x_clock)
- clock_free(x->x_clock);
+ clock_free(x->x_clock);
}
/* this is called when the clock times out to indicate the GUI should
@@ -50,15 +50,15 @@ static void guiconnect_tick(t_guiconnect *x)
void guiconnect_notarget(t_guiconnect *x, double timedelay)
{
if (!x->x_sym)
- pd_free(&x->x_obj.ob_pd);
+ pd_free(&x->x_obj.ob_pd);
else
{
- x->x_who = 0;
- if (timedelay > 0)
- {
- x->x_clock = clock_new(x, (t_method)guiconnect_tick);
- clock_delay(x->x_clock, timedelay);
- }
+ x->x_who = 0;
+ if (timedelay > 0)
+ {
+ x->x_clock = clock_new(x, (t_method)guiconnect_tick);
+ clock_delay(x->x_clock, timedelay);
+ }
}
}
@@ -67,7 +67,7 @@ static void guiconnect_anything(t_guiconnect *x,
t_symbol *s, int ac, t_atom *av)
{
if (x->x_who)
- typedmess(x->x_who, s, ac, av);
+ typedmess(x->x_who, s, ac, av);
}
/* the GUI calls this when it disappears. (If there's any chance the
@@ -76,19 +76,19 @@ static void guiconnect_anything(t_guiconnect *x,
static void guiconnect_signoff(t_guiconnect *x)
{
if (!x->x_who)
- pd_free(&x->x_obj.ob_pd);
+ pd_free(&x->x_obj.ob_pd);
else
{
- pd_unbind(&x->x_obj.ob_pd, x->x_sym);
- x->x_sym = 0;
+ pd_unbind(&x->x_obj.ob_pd, x->x_sym);
+ x->x_sym = 0;
}
}
void g_guiconnect_setup(void)
{
guiconnect_class = class_new(gensym("guiconnect"), 0,
- (t_method)guiconnect_free, sizeof(t_guiconnect), CLASS_PD, 0);
+ (t_method)guiconnect_free, sizeof(t_guiconnect), CLASS_PD, 0);
class_addanything(guiconnect_class, guiconnect_anything);
class_addmethod(guiconnect_class, (t_method)guiconnect_signoff,
- gensym("signoff"), 0);
+ gensym("signoff"), 0);
}
diff --git a/pd/src/g_hdial.c b/pd/src/g_hdial.c
index 79c87aeb..cedb4770 100644
--- a/pd/src/g_hdial.c
+++ b/pd/src/g_hdial.c
@@ -35,14 +35,14 @@ void hradio_draw_update(t_hradio *x, t_glist *glist)
{
if(glist_isvisible(glist))
{
- t_canvas *canvas=glist_getcanvas(glist);
-
- sys_vgui(".x%x.c itemconfigure %xBUT%d -fill #%6.6x -outline #%6.6x\n",
- canvas, x, x->x_on_old,
- x->x_gui.x_bcol, x->x_gui.x_bcol);
- sys_vgui(".x%x.c itemconfigure %xBUT%d -fill #%6.6x -outline #%6.6x\n",
- canvas, x, x->x_on,
- x->x_gui.x_fcol, x->x_gui.x_fcol);
+ t_canvas *canvas=glist_getcanvas(glist);
+
+ sys_vgui(".x%lx.c itemconfigure %lxBUT%d -fill #%6.6x -outline #%6.6x\n",
+ canvas, x, x->x_on_old,
+ x->x_gui.x_bcol, x->x_gui.x_bcol);
+ sys_vgui(".x%lx.c itemconfigure %lxBUT%d -fill #%6.6x -outline #%6.6x\n",
+ canvas, x, x->x_on,
+ x->x_gui.x_fcol, x->x_gui.x_fcol);
}
}
@@ -58,29 +58,29 @@ void hradio_draw_new(t_hradio *x, t_glist *glist)
for(i=0; i<n; i++)
{
- sys_vgui(".x%x.c create rectangle %d %d %d %d -fill #%6.6x -tags %xBASE%d\n",
- canvas, xx11, yy11, xx11+dx, yy12,
- x->x_gui.x_bcol, x, i);
- sys_vgui(".x%x.c create rectangle %d %d %d %d -fill #%6.6x -outline #%6.6x -tags %xBUT%d\n",
- canvas, xx21, yy21, xx22, yy22,
- (x->x_on==i)?x->x_gui.x_fcol:x->x_gui.x_bcol,
- (x->x_on==i)?x->x_gui.x_fcol:x->x_gui.x_bcol, x, i);
- xx11 += dx;
- xx21 += dx;
- xx22 += dx;
+ sys_vgui(".x%lx.c create rectangle %d %d %d %d -fill #%6.6x -tags %lxBASE%d\n",
+ canvas, xx11, yy11, xx11+dx, yy12,
+ x->x_gui.x_bcol, x, i);
+ sys_vgui(".x%lx.c create rectangle %d %d %d %d -fill #%6.6x -outline #%6.6x -tags %lxBUT%d\n",
+ canvas, xx21, yy21, xx22, yy22,
+ (x->x_on==i)?x->x_gui.x_fcol:x->x_gui.x_bcol,
+ (x->x_on==i)?x->x_gui.x_fcol:x->x_gui.x_bcol, x, i);
+ xx11 += dx;
+ xx21 += dx;
+ xx22 += dx;
}
- sys_vgui(".x%x.c create text %d %d -text {%s} -anchor w \
- -font {%s %d bold} -fill #%6.6x -tags %xLABEL\n",
- canvas, xx11b+x->x_gui.x_ldx, yy11+x->x_gui.x_ldy,
- strcmp(x->x_gui.x_lab->s_name, "empty")?x->x_gui.x_lab->s_name:"",
- x->x_gui.x_font, x->x_gui.x_fontsize,
- x->x_gui.x_lcol, x);
+ sys_vgui(".x%lx.c create text %d %d -text {%s} -anchor w \
+ -font {%s %d bold} -fill #%6.6x -tags %lxLABEL\n",
+ canvas, xx11b+x->x_gui.x_ldx, yy11+x->x_gui.x_ldy,
+ strcmp(x->x_gui.x_lab->s_name, "empty")?x->x_gui.x_lab->s_name:"",
+ x->x_gui.x_font, x->x_gui.x_fontsize,
+ x->x_gui.x_lcol, x);
if(!x->x_gui.x_fsf.x_snd_able)
- sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xOUT%d\n",
- canvas, xx11b, yy12-1, xx11b + IOWIDTH, yy12, x, 0);
+ sys_vgui(".x%lx.c create rectangle %d %d %d %d -tags %lxOUT%d\n",
+ canvas, xx11b, yy12-1, xx11b + IOWIDTH, yy12, x, 0);
if(!x->x_gui.x_fsf.x_rcv_able)
- sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xIN%d\n",
- canvas, xx11b, yy11, xx11b + IOWIDTH, yy11+1, x, 0);
+ sys_vgui(".x%lx.c create rectangle %d %d %d %d -tags %lxIN%d\n",
+ canvas, xx11b, yy11, xx11b + IOWIDTH, yy11+1, x, 0);
}
@@ -98,22 +98,22 @@ void hradio_draw_move(t_hradio *x, t_glist *glist)
xx22=xx11b+dx-s4;
for(i=0; i<n; i++)
{
- sys_vgui(".x%x.c coords %xBASE%d %d %d %d %d\n",
- canvas, x, i, xx11, yy11, xx11+dx, yy12);
- sys_vgui(".x%x.c coords %xBUT%d %d %d %d %d\n",
- canvas, x, i, xx21, yy21, xx22, yy22);
- xx11 += dx;
- xx21 += dx;
- xx22 += dx;
+ sys_vgui(".x%lx.c coords %lxBASE%d %d %d %d %d\n",
+ canvas, x, i, xx11, yy11, xx11+dx, yy12);
+ sys_vgui(".x%lx.c coords %lxBUT%d %d %d %d %d\n",
+ canvas, x, i, xx21, yy21, xx22, yy22);
+ xx11 += dx;
+ xx21 += dx;
+ xx22 += dx;
}
- sys_vgui(".x%x.c coords %xLABEL %d %d\n",
- canvas, x, xx11b+x->x_gui.x_ldx, yy11+x->x_gui.x_ldy);
+ sys_vgui(".x%lx.c coords %lxLABEL %d %d\n",
+ canvas, x, xx11b+x->x_gui.x_ldx, yy11+x->x_gui.x_ldy);
if(!x->x_gui.x_fsf.x_snd_able)
- sys_vgui(".x%x.c coords %xOUT%d %d %d %d %d\n",
- canvas, x, 0, xx11b, yy12-1, xx11b + IOWIDTH, yy12);
+ sys_vgui(".x%lx.c coords %lxOUT%d %d %d %d %d\n",
+ canvas, x, 0, xx11b, yy12-1, xx11b + IOWIDTH, yy12);
if(!x->x_gui.x_fsf.x_rcv_able)
- sys_vgui(".x%x.c coords %xIN%d %d %d %d %d\n",
- canvas, x, 0, xx11b, yy11, xx11b + IOWIDTH, yy11+1);
+ sys_vgui(".x%lx.c coords %lxIN%d %d %d %d %d\n",
+ canvas, x, 0, xx11b, yy11, xx11b + IOWIDTH, yy11+1);
}
void hradio_draw_erase(t_hradio* x, t_glist* glist)
@@ -123,14 +123,14 @@ void hradio_draw_erase(t_hradio* x, t_glist* glist)
for(i=0; i<n; i++)
{
- sys_vgui(".x%x.c delete %xBASE%d\n", canvas, x, i);
- sys_vgui(".x%x.c delete %xBUT%d\n", canvas, x, i);
+ sys_vgui(".x%lx.c delete %lxBASE%d\n", canvas, x, i);
+ sys_vgui(".x%lx.c delete %lxBUT%d\n", canvas, x, i);
}
- sys_vgui(".x%x.c delete %xLABEL\n", canvas, x);
+ sys_vgui(".x%lx.c delete %lxLABEL\n", canvas, x);
if(!x->x_gui.x_fsf.x_snd_able)
- sys_vgui(".x%x.c delete %xOUT%d\n", canvas, x, 0);
+ sys_vgui(".x%lx.c delete %lxOUT%d\n", canvas, x, 0);
if(!x->x_gui.x_fsf.x_rcv_able)
- sys_vgui(".x%x.c delete %xIN%d\n", canvas, x, 0);
+ sys_vgui(".x%lx.c delete %lxIN%d\n", canvas, x, 0);
}
void hradio_draw_config(t_hradio* x, t_glist* glist)
@@ -138,17 +138,17 @@ void hradio_draw_config(t_hradio* x, t_glist* glist)
t_canvas *canvas=glist_getcanvas(glist);
int n=x->x_number, i;
- sys_vgui(".x%x.c itemconfigure %xLABEL -font {%s %d bold} -fill #%6.6x -text {%s} \n",
- canvas, x, x->x_gui.x_font, x->x_gui.x_fontsize,
- x->x_gui.x_fsf.x_selected?IEM_GUI_COLOR_SELECTED:x->x_gui.x_lcol,
- strcmp(x->x_gui.x_lab->s_name, "empty")?x->x_gui.x_lab->s_name:"");
+ sys_vgui(".x%lx.c itemconfigure %lxLABEL -font {%s %d bold} -fill #%6.6x -text {%s} \n",
+ canvas, x, x->x_gui.x_font, x->x_gui.x_fontsize,
+ x->x_gui.x_fsf.x_selected?IEM_GUI_COLOR_SELECTED:x->x_gui.x_lcol,
+ strcmp(x->x_gui.x_lab->s_name, "empty")?x->x_gui.x_lab->s_name:"");
for(i=0; i<n; i++)
{
- sys_vgui(".x%x.c itemconfigure %xBASE%d -fill #%6.6x\n", canvas, x, i,
- x->x_gui.x_bcol);
- sys_vgui(".x%x.c itemconfigure %xBUT%d -fill #%6.6x -outline #%6.6x\n", canvas, x, i,
- (x->x_on==i)?x->x_gui.x_fcol:x->x_gui.x_bcol,
- (x->x_on==i)?x->x_gui.x_fcol:x->x_gui.x_bcol);
+ sys_vgui(".x%lx.c itemconfigure %lxBASE%d -fill #%6.6x\n", canvas, x, i,
+ x->x_gui.x_bcol);
+ sys_vgui(".x%lx.c itemconfigure %lxBUT%d -fill #%6.6x -outline #%6.6x\n", canvas, x, i,
+ (x->x_on==i)?x->x_gui.x_fcol:x->x_gui.x_bcol,
+ (x->x_on==i)?x->x_gui.x_fcol:x->x_gui.x_bcol);
}
}
@@ -159,20 +159,20 @@ void hradio_draw_io(t_hradio* x, t_glist* glist, int old_snd_rcv_flags)
int ypos=text_ypix(&x->x_gui.x_obj, glist);
if((old_snd_rcv_flags & IEM_GUI_OLD_SND_FLAG) && !x->x_gui.x_fsf.x_snd_able)
- sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xOUT%d\n",
- canvas,
- xpos, ypos + x->x_gui.x_w-1,
- xpos + IOWIDTH, ypos + x->x_gui.x_w,
- x, 0);
+ sys_vgui(".x%lx.c create rectangle %d %d %d %d -tags %lxOUT%d\n",
+ canvas,
+ xpos, ypos + x->x_gui.x_w-1,
+ xpos + IOWIDTH, ypos + x->x_gui.x_w,
+ x, 0);
if(!(old_snd_rcv_flags & IEM_GUI_OLD_SND_FLAG) && x->x_gui.x_fsf.x_snd_able)
- sys_vgui(".x%x.c delete %xOUT%d\n", canvas, x, 0);
+ sys_vgui(".x%lx.c delete %lxOUT%d\n", canvas, x, 0);
if((old_snd_rcv_flags & IEM_GUI_OLD_RCV_FLAG) && !x->x_gui.x_fsf.x_rcv_able)
- sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xIN%d\n",
- canvas,
- xpos, ypos,
- xpos + IOWIDTH, ypos+1, x, 0);
+ sys_vgui(".x%lx.c create rectangle %d %d %d %d -tags %lxIN%d\n",
+ canvas,
+ xpos, ypos,
+ xpos + IOWIDTH, ypos+1, x, 0);
if(!(old_snd_rcv_flags & IEM_GUI_OLD_RCV_FLAG) && x->x_gui.x_fsf.x_rcv_able)
- sys_vgui(".x%x.c delete %xIN%d\n", canvas, x, 0);
+ sys_vgui(".x%lx.c delete %lxIN%d\n", canvas, x, 0);
}
void hradio_draw_select(t_hradio* x, t_glist* glist)
@@ -182,41 +182,41 @@ void hradio_draw_select(t_hradio* x, t_glist* glist)
if(x->x_gui.x_fsf.x_selected)
{
- for(i=0; i<n; i++)
- {
- sys_vgui(".x%x.c itemconfigure %xBASE%d -outline #%6.6x\n", canvas, x, i,
- IEM_GUI_COLOR_SELECTED);
- }
- sys_vgui(".x%x.c itemconfigure %xLABEL -fill #%6.6x\n", canvas, x, IEM_GUI_COLOR_SELECTED);
+ for(i=0; i<n; i++)
+ {
+ sys_vgui(".x%lx.c itemconfigure %lxBASE%d -outline #%6.6x\n", canvas, x, i,
+ IEM_GUI_COLOR_SELECTED);
+ }
+ sys_vgui(".x%lx.c itemconfigure %lxLABEL -fill #%6.6x\n", canvas, x, IEM_GUI_COLOR_SELECTED);
}
else
{
- for(i=0; i<n; i++)
- {
- sys_vgui(".x%x.c itemconfigure %xBASE%d -outline #%6.6x\n", canvas, x, i,
- IEM_GUI_COLOR_NORMAL);
- }
- sys_vgui(".x%x.c itemconfigure %xLABEL -fill #%6.6x\n", canvas, x,
- x->x_gui.x_lcol);
+ for(i=0; i<n; i++)
+ {
+ sys_vgui(".x%lx.c itemconfigure %lxBASE%d -outline #%6.6x\n", canvas, x, i,
+ IEM_GUI_COLOR_NORMAL);
+ }
+ sys_vgui(".x%lx.c itemconfigure %lxLABEL -fill #%6.6x\n", canvas, x,
+ x->x_gui.x_lcol);
}
}
void hradio_draw(t_hradio *x, t_glist *glist, int mode)
{
if(mode == IEM_GUI_DRAW_MODE_UPDATE)
- hradio_draw_update(x, glist);
+ hradio_draw_update(x, glist);
else if(mode == IEM_GUI_DRAW_MODE_MOVE)
- hradio_draw_move(x, glist);
+ hradio_draw_move(x, glist);
else if(mode == IEM_GUI_DRAW_MODE_NEW)
- hradio_draw_new(x, glist);
+ hradio_draw_new(x, glist);
else if(mode == IEM_GUI_DRAW_MODE_SELECT)
- hradio_draw_select(x, glist);
+ hradio_draw_select(x, glist);
else if(mode == IEM_GUI_DRAW_MODE_ERASE)
- hradio_draw_erase(x, glist);
+ hradio_draw_erase(x, glist);
else if(mode == IEM_GUI_DRAW_MODE_CONFIG)
- hradio_draw_config(x, glist);
+ hradio_draw_config(x, glist);
else if(mode >= IEM_GUI_DRAW_MODE_IO)
- hradio_draw_io(x, glist, mode - IEM_GUI_DRAW_MODE_IO);
+ hradio_draw_io(x, glist, mode - IEM_GUI_DRAW_MODE_IO);
}
/* ------------------------ hdl widgetbehaviour----------------------------- */
@@ -239,16 +239,16 @@ static void hradio_save(t_gobj *z, t_binbuf *b)
iemgui_save(&x->x_gui, srl, bflcol);
binbuf_addv(b, "ssiisiiiisssiiiiiiii", gensym("#X"),gensym("obj"),
- (t_int)text_xpix(&x->x_gui.x_obj, x->x_gui.x_glist),
- (t_int)text_ypix(&x->x_gui.x_obj, x->x_gui.x_glist),
- (pd_class(&x->x_gui.x_obj.ob_pd) == hradio_old_class ?
- gensym("hdl") : gensym("hradio")),
- x->x_gui.x_w,
- x->x_change, iem_symargstoint(&x->x_gui.x_isa), x->x_number,
- srl[0], srl[1], srl[2],
- x->x_gui.x_ldx, x->x_gui.x_ldy,
- iem_fstyletoint(&x->x_gui.x_fsf), x->x_gui.x_fontsize,
- bflcol[0], bflcol[1], bflcol[2], x->x_on);
+ (int)text_xpix(&x->x_gui.x_obj, x->x_gui.x_glist),
+ (int)text_ypix(&x->x_gui.x_obj, x->x_gui.x_glist),
+ (pd_class(&x->x_gui.x_obj.ob_pd) == hradio_old_class ?
+ gensym("hdl") : gensym("hradio")),
+ x->x_gui.x_w,
+ x->x_change, iem_symargstoint(&x->x_gui.x_isa), x->x_number,
+ srl[0], srl[1], srl[2],
+ x->x_gui.x_ldx, x->x_gui.x_ldy,
+ iem_fstyletoint(&x->x_gui.x_fsf), x->x_gui.x_fontsize,
+ bflcol[0], bflcol[1], bflcol[2], x->x_on);
binbuf_addv(b, ";");
}
@@ -257,23 +257,26 @@ static void hradio_properties(t_gobj *z, t_glist *owner)
t_hradio *x = (t_hradio *)z;
char buf[800];
t_symbol *srl[3];
+ int hchange=-1;
iemgui_properties(&x->x_gui, srl);
+ if (pd_class(&x->x_gui.x_obj.ob_pd) == hradio_old_class)
+ hchange = x->x_change;
sprintf(buf, "pdtk_iemgui_dialog %%s hradio \
- ----------dimensions(pix):----------- %d %d size: 0 0 empty \
- empty 0.0 empty 0.0 empty %d \
- %d new-only new&old %d %d number: %d \
- %s %s \
- %s %d %d \
- %d %d \
- %d %d %d\n",
- x->x_gui.x_w, IEM_GUI_MINSIZE,
- 0,/*no_schedule*/
- x->x_change, x->x_gui.x_isa.x_loadinit, -1, x->x_number,
- srl[0]->s_name, srl[1]->s_name,
- srl[2]->s_name, x->x_gui.x_ldx, x->x_gui.x_ldy,
- x->x_gui.x_fsf.x_font_style, x->x_gui.x_fontsize,
- 0xffffff & x->x_gui.x_bcol, 0xffffff & x->x_gui.x_fcol, 0xffffff & x->x_gui.x_lcol);
+ ----------dimensions(pix):----------- %d %d size: 0 0 empty \
+ empty 0.0 empty 0.0 empty %d \
+ %d new-only new&old %d %d number: %d \
+ %s %s \
+ %s %d %d \
+ %d %d \
+ %d %d %d\n",
+ x->x_gui.x_w, IEM_GUI_MINSIZE,
+ 0,/*no_schedule*/
+ hchange, x->x_gui.x_isa.x_loadinit, -1, x->x_number,
+ srl[0]->s_name, srl[1]->s_name,
+ srl[2]->s_name, x->x_gui.x_ldx, x->x_gui.x_ldy,
+ x->x_gui.x_fsf.x_font_style, x->x_gui.x_fontsize,
+ 0xffffff & x->x_gui.x_bcol, 0xffffff & x->x_gui.x_fcol, 0xffffff & x->x_gui.x_lcol);
gfxstub_new(&x->x_gui.x_obj.ob_pd, x, buf);
}
@@ -292,21 +295,21 @@ static void hradio_dialog(t_hradio *x, t_symbol *s, int argc, t_atom *argv)
x->x_gui.x_h = x->x_gui.x_w;
if(x->x_number != num)
{
- (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_ERASE);
- x->x_number = num;
- if(x->x_on >= x->x_number)
- {
- x->x_on = x->x_number - 1;
- x->x_on_old = x->x_on;
- }
- (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_NEW);
+ (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_ERASE);
+ x->x_number = num;
+ if(x->x_on >= x->x_number)
+ {
+ x->x_on = x->x_number - 1;
+ x->x_on_old = x->x_on;
+ }
+ (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_NEW);
}
else
{
- (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_CONFIG);
+ (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_CONFIG);
(*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_IO + sr_flags);
- (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_MOVE);
- canvas_fixlinesfor(glist_getcanvas(x->x_gui.x_glist), (t_text*)x);
+ (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_MOVE);
+ canvas_fixlinesfor(glist_getcanvas(x->x_gui.x_glist), (t_text*)x);
}
}
@@ -317,49 +320,49 @@ static void hradio_set(t_hradio *x, t_floatarg f)
int old=x->x_on_old;
if(i < 0)
- i = 0;
+ i = 0;
if(i >= x->x_number)
- i = x->x_number-1;
+ i = x->x_number-1;
if(x->x_on != x->x_on_old)
{
- old = x->x_on_old;
- x->x_on_old = x->x_on;
- x->x_on = i;
- (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
- x->x_on_old = old;
+ old = x->x_on_old;
+ x->x_on_old = x->x_on;
+ x->x_on = i;
+ (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
+ x->x_on_old = old;
}
else
{
- x->x_on = i;
- (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
+ x->x_on = i;
+ (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
}
}
static void hradio_bang(t_hradio *x)
{
- /* compatibility with earlier "hdial" behavior */
+ /* compatibility with earlier "hdial" behavior */
if (pd_class(&x->x_gui.x_obj.ob_pd) == hradio_old_class)
{
- if((x->x_change)&&(x->x_on != x->x_on_old))
- {
+ if((x->x_change)&&(x->x_on != x->x_on_old))
+ {
SETFLOAT(x->x_at, (float)x->x_on_old);
- SETFLOAT(x->x_at+1, 0.0);
- outlet_list(x->x_gui.x_obj.ob_outlet, &s_list, 2, x->x_at);
- if(x->x_gui.x_fsf.x_snd_able && x->x_gui.x_snd->s_thing)
- pd_list(x->x_gui.x_snd->s_thing, &s_list, 2, x->x_at);
- }
- x->x_on_old = x->x_on;
- SETFLOAT(x->x_at, (float)x->x_on);
- SETFLOAT(x->x_at+1, 1.0);
- outlet_list(x->x_gui.x_obj.ob_outlet, &s_list, 2, x->x_at);
- if(x->x_gui.x_fsf.x_snd_able && x->x_gui.x_snd->s_thing)
- pd_list(x->x_gui.x_snd->s_thing, &s_list, 2, x->x_at);
+ SETFLOAT(x->x_at+1, 0.0);
+ outlet_list(x->x_gui.x_obj.ob_outlet, &s_list, 2, x->x_at);
+ if(x->x_gui.x_fsf.x_snd_able && x->x_gui.x_snd->s_thing)
+ pd_list(x->x_gui.x_snd->s_thing, &s_list, 2, x->x_at);
+ }
+ x->x_on_old = x->x_on;
+ SETFLOAT(x->x_at, (float)x->x_on);
+ SETFLOAT(x->x_at+1, 1.0);
+ outlet_list(x->x_gui.x_obj.ob_outlet, &s_list, 2, x->x_at);
+ if(x->x_gui.x_fsf.x_snd_able && x->x_gui.x_snd->s_thing)
+ pd_list(x->x_gui.x_snd->s_thing, &s_list, 2, x->x_at);
}
else
{
- outlet_float(x->x_gui.x_obj.ob_outlet, x->x_on);
- if(x->x_gui.x_fsf.x_snd_able && x->x_gui.x_snd->s_thing)
- pd_float(x->x_gui.x_snd->s_thing, x->x_on);
+ outlet_float(x->x_gui.x_obj.ob_outlet, x->x_on);
+ if(x->x_gui.x_fsf.x_snd_able && x->x_gui.x_snd->s_thing)
+ pd_float(x->x_gui.x_snd->s_thing, x->x_on);
}
}
@@ -368,38 +371,39 @@ static void hradio_fout(t_hradio *x, t_floatarg f)
int i=(int)f;
if(i < 0)
- i = 0;
+ i = 0;
if(i >= x->x_number)
- i = x->x_number-1;
+ i = x->x_number-1;
if (pd_class(&x->x_gui.x_obj.ob_pd) == hradio_old_class)
{
- if((x->x_change)&&(i != x->x_on_old))
- {
- SETFLOAT(x->x_at, (float)x->x_on_old);
- SETFLOAT(x->x_at+1, 0.0);
- outlet_list(x->x_gui.x_obj.ob_outlet, &s_list, 2, x->x_at);
- if(x->x_gui.x_fsf.x_snd_able && x->x_gui.x_snd->s_thing)
- pd_list(x->x_gui.x_snd->s_thing, &s_list, 2, x->x_at);
- }
- if(x->x_on != x->x_on_old)
- x->x_on_old = x->x_on;
- x->x_on = i;
- (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
- x->x_on_old = x->x_on;
- SETFLOAT(x->x_at, (float)x->x_on);
- SETFLOAT(x->x_at+1, 1.0);
- outlet_list(x->x_gui.x_obj.ob_outlet, &s_list, 2, x->x_at);
- if(x->x_gui.x_fsf.x_snd_able && x->x_gui.x_snd->s_thing)
- pd_list(x->x_gui.x_snd->s_thing, &s_list, 2, x->x_at);
+ if((x->x_change)&&(i != x->x_on_old))
+ {
+ SETFLOAT(x->x_at, (float)x->x_on_old);
+ SETFLOAT(x->x_at+1, 0.0);
+ outlet_list(x->x_gui.x_obj.ob_outlet, &s_list, 2, x->x_at);
+ if(x->x_gui.x_fsf.x_snd_able && x->x_gui.x_snd->s_thing)
+ pd_list(x->x_gui.x_snd->s_thing, &s_list, 2, x->x_at);
+ }
+ if(x->x_on != x->x_on_old)
+ x->x_on_old = x->x_on;
+ x->x_on = i;
+ (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
+ x->x_on_old = x->x_on;
+ SETFLOAT(x->x_at, (float)x->x_on);
+ SETFLOAT(x->x_at+1, 1.0);
+ outlet_list(x->x_gui.x_obj.ob_outlet, &s_list, 2, x->x_at);
+ if(x->x_gui.x_fsf.x_snd_able && x->x_gui.x_snd->s_thing)
+ pd_list(x->x_gui.x_snd->s_thing, &s_list, 2, x->x_at);
}
else
{
- outlet_float(x->x_gui.x_obj.ob_outlet, x->x_on = i);
- if(x->x_gui.x_fsf.x_snd_able && x->x_gui.x_snd->s_thing)
- pd_float(x->x_gui.x_snd->s_thing, x->x_on);
- (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
- x->x_on_old = x->x_on;
+ x->x_on_old = x->x_on;
+ x->x_on = i;
+ (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
+ outlet_float(x->x_gui.x_obj.ob_outlet, x->x_on);
+ if(x->x_gui.x_fsf.x_snd_able && x->x_gui.x_snd->s_thing)
+ pd_float(x->x_gui.x_snd->s_thing, x->x_on);
}
}
@@ -408,49 +412,49 @@ static void hradio_float(t_hradio *x, t_floatarg f)
int i=(int)f;
if(i < 0)
- i = 0;
+ i = 0;
if(i >= x->x_number)
- i = x->x_number-1;
+ i = x->x_number-1;
if (pd_class(&x->x_gui.x_obj.ob_pd) == hradio_old_class)
{
- /* compatibility with earlier "vdial" behavior */
- if((x->x_change)&&(i != x->x_on_old))
- {
- if(x->x_gui.x_fsf.x_put_in2out)
- {
- SETFLOAT(x->x_at, (float)x->x_on_old);
- SETFLOAT(x->x_at+1, 0.0);
- outlet_list(x->x_gui.x_obj.ob_outlet, &s_list, 2, x->x_at);
- if(x->x_gui.x_fsf.x_snd_able && x->x_gui.x_snd->s_thing)
- pd_list(x->x_gui.x_snd->s_thing, &s_list, 2, x->x_at);
- }
- }
- if(x->x_on != x->x_on_old)
- x->x_on_old = x->x_on;
- x->x_on = i;
- (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
- x->x_on_old = x->x_on;
- if(x->x_gui.x_fsf.x_put_in2out)
- {
- SETFLOAT(x->x_at, (float)x->x_on);
+ /* compatibility with earlier "vdial" behavior */
+ if((x->x_change)&&(i != x->x_on_old))
+ {
+ if(x->x_gui.x_fsf.x_put_in2out)
+ {
+ SETFLOAT(x->x_at, (float)x->x_on_old);
+ SETFLOAT(x->x_at+1, 0.0);
+ outlet_list(x->x_gui.x_obj.ob_outlet, &s_list, 2, x->x_at);
+ if(x->x_gui.x_fsf.x_snd_able && x->x_gui.x_snd->s_thing)
+ pd_list(x->x_gui.x_snd->s_thing, &s_list, 2, x->x_at);
+ }
+ }
+ if(x->x_on != x->x_on_old)
+ x->x_on_old = x->x_on;
+ x->x_on = i;
+ (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
+ x->x_on_old = x->x_on;
+ if(x->x_gui.x_fsf.x_put_in2out)
+ {
+ SETFLOAT(x->x_at, (float)x->x_on);
SETFLOAT(x->x_at+1, 1.0);
- outlet_list(x->x_gui.x_obj.ob_outlet, &s_list, 2, x->x_at);
- if(x->x_gui.x_fsf.x_snd_able && x->x_gui.x_snd->s_thing)
- pd_list(x->x_gui.x_snd->s_thing, &s_list, 2, x->x_at);
- }
+ outlet_list(x->x_gui.x_obj.ob_outlet, &s_list, 2, x->x_at);
+ if(x->x_gui.x_fsf.x_snd_able && x->x_gui.x_snd->s_thing)
+ pd_list(x->x_gui.x_snd->s_thing, &s_list, 2, x->x_at);
+ }
}
else
{
- x->x_on = i;
- if (x->x_gui.x_fsf.x_put_in2out)
- {
- outlet_float(x->x_gui.x_obj.ob_outlet, x->x_on);
- if(x->x_gui.x_fsf.x_snd_able && x->x_gui.x_snd->s_thing)
- pd_float(x->x_gui.x_snd->s_thing, x->x_on);
- }
- (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
- x->x_on_old = x->x_on;
+ x->x_on_old = x->x_on;
+ x->x_on = i;
+ (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
+ if (x->x_gui.x_fsf.x_put_in2out)
+ {
+ outlet_float(x->x_gui.x_obj.ob_outlet, x->x_on);
+ if(x->x_gui.x_fsf.x_snd_able && x->x_gui.x_snd->s_thing)
+ pd_float(x->x_gui.x_snd->s_thing, x->x_on);
+ }
}
}
@@ -464,14 +468,14 @@ static void hradio_click(t_hradio *x, t_floatarg xpos, t_floatarg ypos, t_floata
static int hradio_newclick(t_gobj *z, struct _glist *glist, int xpix, int ypix, int shift, int alt, int dbl, int doit)
{
if(doit)
- hradio_click((t_hradio *)z, (t_floatarg)xpix, (t_floatarg)ypix, (t_floatarg)shift, 0, (t_floatarg)alt);
+ hradio_click((t_hradio *)z, (t_floatarg)xpix, (t_floatarg)ypix, (t_floatarg)shift, 0, (t_floatarg)alt);
return (1);
}
static void hradio_loadbang(t_hradio *x)
{
if(!sys_noloadbang && x->x_gui.x_isa.x_loadinit)
- hradio_bang(x);
+ hradio_bang(x);
}
static void hradio_number(t_hradio *x, t_floatarg num)
@@ -479,17 +483,17 @@ static void hradio_number(t_hradio *x, t_floatarg num)
int n=(int)num;
if(n < 1)
- n = 1;
+ n = 1;
if(n > IEM_RADIO_MAX)
- n = IEM_RADIO_MAX;
+ n = IEM_RADIO_MAX;
if(n != x->x_number)
{
- (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_ERASE);
- x->x_number = n;
- if(x->x_on >= x->x_number)
- x->x_on = x->x_number - 1;
- x->x_on_old = x->x_on;
- (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_NEW);
+ (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_ERASE);
+ x->x_number = n;
+ if(x->x_on >= x->x_number)
+ x->x_on = x->x_number - 1;
+ x->x_on_old = x->x_on;
+ (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_NEW);
}
}
@@ -557,19 +561,19 @@ static void *hradio_donew(t_symbol *s, int argc, t_atom *argv, int old)
&&IS_A_FLOAT(argv,9)&&IS_A_FLOAT(argv,10)&&IS_A_FLOAT(argv,11)
&&IS_A_FLOAT(argv,12)&&IS_A_FLOAT(argv,13)&&IS_A_FLOAT(argv,14))
{
- a = (int)atom_getintarg(0, argc, argv);
- chg = (int)atom_getintarg(1, argc, argv);
- iem_inttosymargs(&x->x_gui.x_isa, atom_getintarg(2, argc, argv));
- num = (int)atom_getintarg(3, argc, argv);
- iemgui_new_getnames(&x->x_gui, 4, argv);
- ldx = (int)atom_getintarg(7, argc, argv);
- ldy = (int)atom_getintarg(8, argc, argv);
- iem_inttofstyle(&x->x_gui.x_fsf, atom_getintarg(9, argc, argv));
- fs = (int)atom_getintarg(10, argc, argv);
- bflcol[0] = (int)atom_getintarg(11, argc, argv);
- bflcol[1] = (int)atom_getintarg(12, argc, argv);
- bflcol[2] = (int)atom_getintarg(13, argc, argv);
- on = (int)atom_getintarg(14, argc, argv);
+ a = (int)atom_getintarg(0, argc, argv);
+ chg = (int)atom_getintarg(1, argc, argv);
+ iem_inttosymargs(&x->x_gui.x_isa, atom_getintarg(2, argc, argv));
+ num = (int)atom_getintarg(3, argc, argv);
+ iemgui_new_getnames(&x->x_gui, 4, argv);
+ ldx = (int)atom_getintarg(7, argc, argv);
+ ldy = (int)atom_getintarg(8, argc, argv);
+ iem_inttofstyle(&x->x_gui.x_fsf, atom_getintarg(9, argc, argv));
+ fs = (int)atom_getintarg(10, argc, argv);
+ bflcol[0] = (int)atom_getintarg(11, argc, argv);
+ bflcol[1] = (int)atom_getintarg(12, argc, argv);
+ bflcol[2] = (int)atom_getintarg(13, argc, argv);
+ on = (int)atom_getintarg(14, argc, argv);
}
else iemgui_new_getnames(&x->x_gui, 4, 0);
x->x_gui.x_draw = (t_iemfunptr)hradio_draw;
@@ -577,34 +581,34 @@ static void *hradio_donew(t_symbol *s, int argc, t_atom *argv, int old)
x->x_gui.x_fsf.x_rcv_able = 1;
x->x_gui.x_glist = (t_glist *)canvas_getcurrent();
if (!strcmp(x->x_gui.x_snd->s_name, "empty"))
- x->x_gui.x_fsf.x_snd_able = 0;
+ x->x_gui.x_fsf.x_snd_able = 0;
if (!strcmp(x->x_gui.x_rcv->s_name, "empty"))
- x->x_gui.x_fsf.x_rcv_able = 0;
+ x->x_gui.x_fsf.x_rcv_able = 0;
if(x->x_gui.x_fsf.x_font_style == 1) strcpy(x->x_gui.x_font, "helvetica");
else if(x->x_gui.x_fsf.x_font_style == 2) strcpy(x->x_gui.x_font, "times");
else { x->x_gui.x_fsf.x_font_style = 0;
- strcpy(x->x_gui.x_font, "courier"); }
+ strcpy(x->x_gui.x_font, "courier"); }
if(num < 1)
- num = 1;
+ num = 1;
if(num > IEM_RADIO_MAX)
- num = IEM_RADIO_MAX;
+ num = IEM_RADIO_MAX;
x->x_number = num;
if(on < 0)
- on = 0;
+ on = 0;
if(on >= x->x_number)
- on = x->x_number - 1;
+ on = x->x_number - 1;
if(x->x_gui.x_isa.x_loadinit)
- x->x_on = on;
+ x->x_on = on;
else
- x->x_on = 0;
+ x->x_on = 0;
x->x_on_old = x->x_on;
x->x_change = (chg==0)?0:1;
if (x->x_gui.x_fsf.x_rcv_able)
- pd_bind(&x->x_gui.x_obj.ob_pd, x->x_gui.x_rcv);
+ pd_bind(&x->x_gui.x_obj.ob_pd, x->x_gui.x_rcv);
x->x_gui.x_ldx = ldx;
x->x_gui.x_ldy = ldy;
if(fs < 4)
- fs = 4;
+ fs = 4;
x->x_gui.x_fontsize = fs;
x->x_gui.x_w = iemgui_clip_size(a);
x->x_gui.x_h = x->x_gui.x_w;
@@ -627,50 +631,50 @@ static void *hdial_new(t_symbol *s, int argc, t_atom *argv)
static void hradio_ff(t_hradio *x)
{
if(x->x_gui.x_fsf.x_rcv_able)
- pd_unbind(&x->x_gui.x_obj.ob_pd, x->x_gui.x_rcv);
+ pd_unbind(&x->x_gui.x_obj.ob_pd, x->x_gui.x_rcv);
gfxstub_deleteforkey(x);
}
void g_hradio_setup(void)
{
hradio_class = class_new(gensym("hradio"), (t_newmethod)hradio_new,
- (t_method)hradio_ff, sizeof(t_hradio), 0, A_GIMME, 0);
+ (t_method)hradio_ff, sizeof(t_hradio), 0, A_GIMME, 0);
class_addbang(hradio_class, hradio_bang);
class_addfloat(hradio_class, hradio_float);
class_addmethod(hradio_class, (t_method)hradio_click, gensym("click"),
- A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, 0);
+ A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, 0);
class_addmethod(hradio_class, (t_method)hradio_dialog, gensym("dialog"),
- A_GIMME, 0);
+ A_GIMME, 0);
class_addmethod(hradio_class, (t_method)hradio_loadbang,
- gensym("loadbang"), 0);
+ gensym("loadbang"), 0);
class_addmethod(hradio_class, (t_method)hradio_set,
- gensym("set"), A_FLOAT, 0);
+ gensym("set"), A_FLOAT, 0);
class_addmethod(hradio_class, (t_method)hradio_size,
- gensym("size"), A_GIMME, 0);
+ gensym("size"), A_GIMME, 0);
class_addmethod(hradio_class, (t_method)hradio_delta,
- gensym("delta"), A_GIMME, 0);
+ gensym("delta"), A_GIMME, 0);
class_addmethod(hradio_class, (t_method)hradio_pos,
- gensym("pos"), A_GIMME, 0);
+ gensym("pos"), A_GIMME, 0);
class_addmethod(hradio_class, (t_method)hradio_color,
- gensym("color"), A_GIMME, 0);
+ gensym("color"), A_GIMME, 0);
class_addmethod(hradio_class, (t_method)hradio_send,
- gensym("send"), A_DEFSYM, 0);
+ gensym("send"), A_DEFSYM, 0);
class_addmethod(hradio_class, (t_method)hradio_receive,
- gensym("receive"), A_DEFSYM, 0);
+ gensym("receive"), A_DEFSYM, 0);
class_addmethod(hradio_class, (t_method)hradio_label,
- gensym("label"), A_DEFSYM, 0);
+ gensym("label"), A_DEFSYM, 0);
class_addmethod(hradio_class, (t_method)hradio_label_pos,
- gensym("label_pos"), A_GIMME, 0);
+ gensym("label_pos"), A_GIMME, 0);
class_addmethod(hradio_class, (t_method)hradio_label_font,
- gensym("label_font"), A_GIMME, 0);
+ gensym("label_font"), A_GIMME, 0);
class_addmethod(hradio_class, (t_method)hradio_init,
- gensym("init"), A_FLOAT, 0);
+ gensym("init"), A_FLOAT, 0);
class_addmethod(hradio_class, (t_method)hradio_number,
- gensym("number"), A_FLOAT, 0);
+ gensym("number"), A_FLOAT, 0);
class_addmethod(hradio_class, (t_method)hradio_single_change,
- gensym("single_change"), 0);
+ gensym("single_change"), 0);
class_addmethod(hradio_class, (t_method)hradio_double_change,
- gensym("double_change"), 0);
+ gensym("double_change"), 0);
hradio_widgetbehavior.w_getrectfn = hradio_getrect;
hradio_widgetbehavior.w_displacefn = iemgui_displace;
hradio_widgetbehavior.w_selectfn = iemgui_select;
@@ -683,49 +687,49 @@ void g_hradio_setup(void)
class_setsavefn(hradio_class, hradio_save);
class_setpropertiesfn(hradio_class, hradio_properties);
- /*obsolete version (0.34-0.35) */
+ /*obsolete version (0.34-0.35) */
hradio_old_class = class_new(gensym("hdl"), (t_newmethod)hdial_new,
- (t_method)hradio_ff, sizeof(t_hradio), 0, A_GIMME, 0);
+ (t_method)hradio_ff, sizeof(t_hradio), 0, A_GIMME, 0);
class_addcreator((t_newmethod)hradio_new, gensym("rdb"), A_GIMME, 0);
class_addcreator((t_newmethod)hradio_new, gensym("radiobut"), A_GIMME, 0);
class_addcreator((t_newmethod)hradio_new, gensym("radiobutton"),
- A_GIMME, 0);
+ A_GIMME, 0);
class_addbang(hradio_old_class, hradio_bang);
class_addfloat(hradio_old_class, hradio_float);
class_addmethod(hradio_old_class, (t_method)hradio_click, gensym("click"),
- A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, 0);
+ A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, 0);
class_addmethod(hradio_old_class, (t_method)hradio_dialog, gensym("dialog"),
- A_GIMME, 0);
+ A_GIMME, 0);
class_addmethod(hradio_old_class, (t_method)hradio_loadbang,
- gensym("loadbang"), 0);
+ gensym("loadbang"), 0);
class_addmethod(hradio_old_class, (t_method)hradio_set,
- gensym("set"), A_FLOAT, 0);
+ gensym("set"), A_FLOAT, 0);
class_addmethod(hradio_old_class, (t_method)hradio_size,
- gensym("size"), A_GIMME, 0);
+ gensym("size"), A_GIMME, 0);
class_addmethod(hradio_old_class, (t_method)hradio_delta,
- gensym("delta"), A_GIMME, 0);
+ gensym("delta"), A_GIMME, 0);
class_addmethod(hradio_old_class, (t_method)hradio_pos,
- gensym("pos"), A_GIMME, 0);
+ gensym("pos"), A_GIMME, 0);
class_addmethod(hradio_old_class, (t_method)hradio_color,
- gensym("color"), A_GIMME, 0);
+ gensym("color"), A_GIMME, 0);
class_addmethod(hradio_old_class, (t_method)hradio_send,
- gensym("send"), A_DEFSYM, 0);
+ gensym("send"), A_DEFSYM, 0);
class_addmethod(hradio_old_class, (t_method)hradio_receive,
- gensym("receive"), A_DEFSYM, 0);
+ gensym("receive"), A_DEFSYM, 0);
class_addmethod(hradio_old_class, (t_method)hradio_label,
- gensym("label"), A_DEFSYM, 0);
+ gensym("label"), A_DEFSYM, 0);
class_addmethod(hradio_old_class, (t_method)hradio_label_pos,
- gensym("label_pos"), A_GIMME, 0);
+ gensym("label_pos"), A_GIMME, 0);
class_addmethod(hradio_old_class, (t_method)hradio_label_font,
- gensym("label_font"), A_GIMME, 0);
+ gensym("label_font"), A_GIMME, 0);
class_addmethod(hradio_old_class, (t_method)hradio_init,
- gensym("init"), A_FLOAT, 0);
+ gensym("init"), A_FLOAT, 0);
class_addmethod(hradio_old_class, (t_method)hradio_number,
- gensym("number"), A_FLOAT, 0);
+ gensym("number"), A_FLOAT, 0);
class_addmethod(hradio_old_class, (t_method)hradio_single_change,
- gensym("single_change"), 0);
+ gensym("single_change"), 0);
class_addmethod(hradio_old_class, (t_method)hradio_double_change,
- gensym("double_change"), 0);
+ gensym("double_change"), 0);
class_setwidget(hradio_old_class, &hradio_widgetbehavior);
class_sethelpsymbol(hradio_old_class, gensym("hradio"));
}
diff --git a/pd/src/g_hslider.c b/pd/src/g_hslider.c
index 57c60cff..be744d41 100644
--- a/pd/src/g_hslider.c
+++ b/pd/src/g_hslider.c
@@ -37,26 +37,26 @@ static void hslider_draw_update(t_hslider *x, t_glist *glist)
if (glist_isvisible(glist))
{
- int r = text_xpix(&x->x_gui.x_obj, glist) + (x->x_val + 50)/100;
- sys_vgui(".x%x.c coords %xKNOB %d %d %d %d\n",
- canvas, x, r, ypos+1,
- r, ypos + x->x_gui.x_h);
- if(x->x_val == x->x_center)
- {
- if(!x->x_thick)
- {
- sys_vgui(".x%x.c itemconfigure %xKNOB -width 7\n", canvas, x);
- x->x_thick = 1;
- }
- }
- else
- {
- if(x->x_thick)
- {
- sys_vgui(".x%x.c itemconfigure %xKNOB -width 3\n", canvas, x);
- x->x_thick = 0;
- }
- }
+ int r = text_xpix(&x->x_gui.x_obj, glist) + (x->x_val + 50)/100;
+ sys_vgui(".x%lx.c coords %lxKNOB %d %d %d %d\n",
+ canvas, x, r, ypos+1,
+ r, ypos + x->x_gui.x_h);
+ if(x->x_val == x->x_center)
+ {
+ if(!x->x_thick)
+ {
+ sys_vgui(".x%lx.c itemconfigure %lxKNOB -width 7\n", canvas, x);
+ x->x_thick = 1;
+ }
+ }
+ else
+ {
+ if(x->x_thick)
+ {
+ sys_vgui(".x%lx.c itemconfigure %lxKNOB -width 3\n", canvas, x);
+ x->x_thick = 0;
+ }
+ }
}
}
@@ -67,27 +67,27 @@ static void hslider_draw_new(t_hslider *x, t_glist *glist)
int r = xpos + (x->x_val + 50)/100;
t_canvas *canvas=glist_getcanvas(glist);
- sys_vgui(".x%x.c create rectangle %d %d %d %d -fill #%6.6x -tags %xBASE\n",
- canvas, xpos-3, ypos,
- xpos + x->x_gui.x_w+2, ypos + x->x_gui.x_h,
- x->x_gui.x_bcol, x);
- sys_vgui(".x%x.c create line %d %d %d %d -width 3 -fill #%6.6x -tags %xKNOB\n",
- canvas, r, ypos+1, r,
- ypos + x->x_gui.x_h, x->x_gui.x_fcol, x);
- sys_vgui(".x%x.c create text %d %d -text {%s} -anchor w \
- -font {%s %d bold} -fill #%6.6x -tags %xLABEL\n",
- canvas, xpos+x->x_gui.x_ldx,
- ypos+x->x_gui.x_ldy,
- strcmp(x->x_gui.x_lab->s_name, "empty")?x->x_gui.x_lab->s_name:"",
- x->x_gui.x_font, x->x_gui.x_fontsize, x->x_gui.x_lcol, x);
+ sys_vgui(".x%lx.c create rectangle %d %d %d %d -fill #%6.6x -tags %lxBASE\n",
+ canvas, xpos-3, ypos,
+ xpos + x->x_gui.x_w+2, ypos + x->x_gui.x_h,
+ x->x_gui.x_bcol, x);
+ sys_vgui(".x%lx.c create line %d %d %d %d -width 3 -fill #%6.6x -tags %lxKNOB\n",
+ canvas, r, ypos+1, r,
+ ypos + x->x_gui.x_h, x->x_gui.x_fcol, x);
+ sys_vgui(".x%lx.c create text %d %d -text {%s} -anchor w \
+ -font {%s %d bold} -fill #%6.6x -tags %lxLABEL\n",
+ canvas, xpos+x->x_gui.x_ldx,
+ ypos+x->x_gui.x_ldy,
+ strcmp(x->x_gui.x_lab->s_name, "empty")?x->x_gui.x_lab->s_name:"",
+ x->x_gui.x_font, x->x_gui.x_fontsize, x->x_gui.x_lcol, x);
if(!x->x_gui.x_fsf.x_snd_able)
- sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xOUT%d\n",
- canvas, xpos-3, ypos + x->x_gui.x_h-1,
- xpos+4, ypos + x->x_gui.x_h, x, 0);
+ sys_vgui(".x%lx.c create rectangle %d %d %d %d -tags %lxOUT%d\n",
+ canvas, xpos-3, ypos + x->x_gui.x_h-1,
+ xpos+4, ypos + x->x_gui.x_h, x, 0);
if(!x->x_gui.x_fsf.x_rcv_able)
- sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xIN%d\n",
- canvas, xpos-3, ypos,
- xpos+4, ypos+1, x, 0);
+ sys_vgui(".x%lx.c create rectangle %d %d %d %d -tags %lxIN%d\n",
+ canvas, xpos-3, ypos,
+ xpos+4, ypos+1, x, 0);
}
static void hslider_draw_move(t_hslider *x, t_glist *glist)
@@ -97,50 +97,50 @@ static void hslider_draw_move(t_hslider *x, t_glist *glist)
int r = xpos + (x->x_val + 50)/100;
t_canvas *canvas=glist_getcanvas(glist);
- sys_vgui(".x%x.c coords %xBASE %d %d %d %d\n",
- canvas, x,
- xpos-3, ypos,
- xpos + x->x_gui.x_w+2, ypos + x->x_gui.x_h);
- sys_vgui(".x%x.c coords %xKNOB %d %d %d %d\n",
- canvas, x, r, ypos+1,
- r, ypos + x->x_gui.x_h);
- sys_vgui(".x%x.c coords %xLABEL %d %d\n",
- canvas, x, xpos+x->x_gui.x_ldx, ypos+x->x_gui.x_ldy);
+ sys_vgui(".x%lx.c coords %lxBASE %d %d %d %d\n",
+ canvas, x,
+ xpos-3, ypos,
+ xpos + x->x_gui.x_w+2, ypos + x->x_gui.x_h);
+ sys_vgui(".x%lx.c coords %lxKNOB %d %d %d %d\n",
+ canvas, x, r, ypos+1,
+ r, ypos + x->x_gui.x_h);
+ sys_vgui(".x%lx.c coords %lxLABEL %d %d\n",
+ canvas, x, xpos+x->x_gui.x_ldx, ypos+x->x_gui.x_ldy);
if(!x->x_gui.x_fsf.x_snd_able)
- sys_vgui(".x%x.c coords %xOUT%d %d %d %d %d\n",
- canvas, x, 0,
- xpos-3, ypos + x->x_gui.x_h-1,
- xpos+4, ypos + x->x_gui.x_h);
+ sys_vgui(".x%lx.c coords %lxOUT%d %d %d %d %d\n",
+ canvas, x, 0,
+ xpos-3, ypos + x->x_gui.x_h-1,
+ xpos+4, ypos + x->x_gui.x_h);
if(!x->x_gui.x_fsf.x_rcv_able)
- sys_vgui(".x%x.c coords %xIN%d %d %d %d %d\n",
- canvas, x, 0,
- xpos-3, ypos,
- xpos+4, ypos+1);
+ sys_vgui(".x%lx.c coords %lxIN%d %d %d %d %d\n",
+ canvas, x, 0,
+ xpos-3, ypos,
+ xpos+4, ypos+1);
}
static void hslider_draw_erase(t_hslider* x,t_glist* glist)
{
t_canvas *canvas=glist_getcanvas(glist);
- sys_vgui(".x%x.c delete %xBASE\n", canvas, x);
- sys_vgui(".x%x.c delete %xKNOB\n", canvas, x);
- sys_vgui(".x%x.c delete %xLABEL\n", canvas, x);
+ sys_vgui(".x%lx.c delete %lxBASE\n", canvas, x);
+ sys_vgui(".x%lx.c delete %lxKNOB\n", canvas, x);
+ sys_vgui(".x%lx.c delete %lxLABEL\n", canvas, x);
if(!x->x_gui.x_fsf.x_snd_able)
- sys_vgui(".x%x.c delete %xOUT%d\n", canvas, x, 0);
+ sys_vgui(".x%lx.c delete %lxOUT%d\n", canvas, x, 0);
if(!x->x_gui.x_fsf.x_rcv_able)
- sys_vgui(".x%x.c delete %xIN%d\n", canvas, x, 0);
+ sys_vgui(".x%lx.c delete %lxIN%d\n", canvas, x, 0);
}
static void hslider_draw_config(t_hslider* x,t_glist* glist)
{
t_canvas *canvas=glist_getcanvas(glist);
- sys_vgui(".x%x.c itemconfigure %xLABEL -font {%s %d bold} -fill #%6.6x -text {%s} \n",
- canvas, x, x->x_gui.x_font, x->x_gui.x_fontsize,
- x->x_gui.x_fsf.x_selected?IEM_GUI_COLOR_SELECTED:x->x_gui.x_lcol,
- strcmp(x->x_gui.x_lab->s_name, "empty")?x->x_gui.x_lab->s_name:"");
- sys_vgui(".x%x.c itemconfigure %xKNOB -fill #%6.6x\n", canvas, x, x->x_gui.x_fcol);
- sys_vgui(".x%x.c itemconfigure %xBASE -fill #%6.6x\n", canvas, x, x->x_gui.x_bcol);
+ sys_vgui(".x%lx.c itemconfigure %lxLABEL -font {%s %d bold} -fill #%6.6x -text {%s} \n",
+ canvas, x, x->x_gui.x_font, x->x_gui.x_fontsize,
+ x->x_gui.x_fsf.x_selected?IEM_GUI_COLOR_SELECTED:x->x_gui.x_lcol,
+ strcmp(x->x_gui.x_lab->s_name, "empty")?x->x_gui.x_lab->s_name:"");
+ sys_vgui(".x%lx.c itemconfigure %lxKNOB -fill #%6.6x\n", canvas, x, x->x_gui.x_fcol);
+ sys_vgui(".x%lx.c itemconfigure %lxBASE -fill #%6.6x\n", canvas, x, x->x_gui.x_bcol);
}
static void hslider_draw_io(t_hslider* x,t_glist* glist, int old_snd_rcv_flags)
@@ -150,17 +150,17 @@ static void hslider_draw_io(t_hslider* x,t_glist* glist, int old_snd_rcv_flags)
t_canvas *canvas=glist_getcanvas(glist);
if((old_snd_rcv_flags & IEM_GUI_OLD_SND_FLAG) && !x->x_gui.x_fsf.x_snd_able)
- sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xOUT%d\n",
- canvas, xpos-3, ypos + x->x_gui.x_h-1,
- xpos+4, ypos + x->x_gui.x_h, x, 0);
+ sys_vgui(".x%lx.c create rectangle %d %d %d %d -tags %lxOUT%d\n",
+ canvas, xpos-3, ypos + x->x_gui.x_h-1,
+ xpos+4, ypos + x->x_gui.x_h, x, 0);
if(!(old_snd_rcv_flags & IEM_GUI_OLD_SND_FLAG) && x->x_gui.x_fsf.x_snd_able)
- sys_vgui(".x%x.c delete %xOUT%d\n", canvas, x, 0);
+ sys_vgui(".x%lx.c delete %lxOUT%d\n", canvas, x, 0);
if((old_snd_rcv_flags & IEM_GUI_OLD_RCV_FLAG) && !x->x_gui.x_fsf.x_rcv_able)
- sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xIN%d\n",
- canvas, xpos-3, ypos,
- xpos+4, ypos+1, x, 0);
+ sys_vgui(".x%lx.c create rectangle %d %d %d %d -tags %lxIN%d\n",
+ canvas, xpos-3, ypos,
+ xpos+4, ypos+1, x, 0);
if(!(old_snd_rcv_flags & IEM_GUI_OLD_RCV_FLAG) && x->x_gui.x_fsf.x_rcv_able)
- sys_vgui(".x%x.c delete %xIN%d\n", canvas, x, 0);
+ sys_vgui(".x%lx.c delete %lxIN%d\n", canvas, x, 0);
}
static void hslider_draw_select(t_hslider* x,t_glist* glist)
@@ -169,39 +169,39 @@ static void hslider_draw_select(t_hslider* x,t_glist* glist)
if(x->x_gui.x_fsf.x_selected)
{
- sys_vgui(".x%x.c itemconfigure %xBASE -outline #%6.6x\n", canvas, x, IEM_GUI_COLOR_SELECTED);
- sys_vgui(".x%x.c itemconfigure %xLABEL -fill #%6.6x\n", canvas, x, IEM_GUI_COLOR_SELECTED);
+ sys_vgui(".x%lx.c itemconfigure %lxBASE -outline #%6.6x\n", canvas, x, IEM_GUI_COLOR_SELECTED);
+ sys_vgui(".x%lx.c itemconfigure %lxLABEL -fill #%6.6x\n", canvas, x, IEM_GUI_COLOR_SELECTED);
}
else
{
- sys_vgui(".x%x.c itemconfigure %xBASE -outline #%6.6x\n", canvas, x, IEM_GUI_COLOR_NORMAL);
- sys_vgui(".x%x.c itemconfigure %xLABEL -fill #%6.6x\n", canvas, x, x->x_gui.x_lcol);
+ sys_vgui(".x%lx.c itemconfigure %lxBASE -outline #%6.6x\n", canvas, x, IEM_GUI_COLOR_NORMAL);
+ sys_vgui(".x%lx.c itemconfigure %lxLABEL -fill #%6.6x\n", canvas, x, x->x_gui.x_lcol);
}
}
void hslider_draw(t_hslider *x, t_glist *glist, int mode)
{
if(mode == IEM_GUI_DRAW_MODE_UPDATE)
- hslider_draw_update(x, glist);
+ hslider_draw_update(x, glist);
else if(mode == IEM_GUI_DRAW_MODE_MOVE)
- hslider_draw_move(x, glist);
+ hslider_draw_move(x, glist);
else if(mode == IEM_GUI_DRAW_MODE_NEW)
- hslider_draw_new(x, glist);
+ hslider_draw_new(x, glist);
else if(mode == IEM_GUI_DRAW_MODE_SELECT)
- hslider_draw_select(x, glist);
+ hslider_draw_select(x, glist);
else if(mode == IEM_GUI_DRAW_MODE_ERASE)
- hslider_draw_erase(x, glist);
+ hslider_draw_erase(x, glist);
else if(mode == IEM_GUI_DRAW_MODE_CONFIG)
- hslider_draw_config(x, glist);
+ hslider_draw_config(x, glist);
else if(mode >= IEM_GUI_DRAW_MODE_IO)
- hslider_draw_io(x, glist, mode - IEM_GUI_DRAW_MODE_IO);
+ hslider_draw_io(x, glist, mode - IEM_GUI_DRAW_MODE_IO);
}
/* ------------------------ hsl widgetbehaviour----------------------------- */
static void hslider_getrect(t_gobj *z, t_glist *glist,
- int *xp1, int *yp1, int *xp2, int *yp2)
+ int *xp1, int *yp1, int *xp2, int *yp2)
{
t_hslider* x = (t_hslider*)z;
@@ -219,62 +219,62 @@ static void hslider_save(t_gobj *z, t_binbuf *b)
iemgui_save(&x->x_gui, srl, bflcol);
binbuf_addv(b, "ssiisiiffiisssiiiiiiiii", gensym("#X"),gensym("obj"),
- (t_int)x->x_gui.x_obj.te_xpix, (t_int)x->x_gui.x_obj.te_ypix,
- gensym("hsl"), x->x_gui.x_w, x->x_gui.x_h,
- (float)x->x_min, (float)x->x_max,
- x->x_lin0_log1, iem_symargstoint(&x->x_gui.x_isa),
- srl[0], srl[1], srl[2],
- x->x_gui.x_ldx, x->x_gui.x_ldy,
- iem_fstyletoint(&x->x_gui.x_fsf), x->x_gui.x_fontsize,
- bflcol[0], bflcol[1], bflcol[2],
- x->x_val, x->x_steady);
+ (int)x->x_gui.x_obj.te_xpix, (int)x->x_gui.x_obj.te_ypix,
+ gensym("hsl"), x->x_gui.x_w, x->x_gui.x_h,
+ (float)x->x_min, (float)x->x_max,
+ x->x_lin0_log1, iem_symargstoint(&x->x_gui.x_isa),
+ srl[0], srl[1], srl[2],
+ x->x_gui.x_ldx, x->x_gui.x_ldy,
+ iem_fstyletoint(&x->x_gui.x_fsf), x->x_gui.x_fontsize,
+ bflcol[0], bflcol[1], bflcol[2],
+ x->x_val, x->x_steady);
binbuf_addv(b, ";");
}
void hslider_check_width(t_hslider *x, int w)
{
if(w < IEM_SL_MINSIZE)
- w = IEM_SL_MINSIZE;
+ w = IEM_SL_MINSIZE;
x->x_gui.x_w = w;
x->x_center = (x->x_gui.x_w-1)*50;
if(x->x_val > (x->x_gui.x_w*100 - 100))
{
- x->x_pos = x->x_gui.x_w*100 - 100;
- x->x_val = x->x_pos;
+ x->x_pos = x->x_gui.x_w*100 - 100;
+ x->x_val = x->x_pos;
}
if(x->x_lin0_log1)
- x->x_k = log(x->x_max/x->x_min)/(double)(x->x_gui.x_w - 1);
+ x->x_k = log(x->x_max/x->x_min)/(double)(x->x_gui.x_w - 1);
else
- x->x_k = (x->x_max - x->x_min)/(double)(x->x_gui.x_w - 1);
+ x->x_k = (x->x_max - x->x_min)/(double)(x->x_gui.x_w - 1);
}
void hslider_check_minmax(t_hslider *x, double min, double max)
{
if(x->x_lin0_log1)
{
- if((min == 0.0)&&(max == 0.0))
- max = 1.0;
- if(max > 0.0)
- {
- if(min <= 0.0)
- min = 0.01*max;
- }
- else
- {
- if(min > 0.0)
- max = 0.01*min;
- }
+ if((min == 0.0)&&(max == 0.0))
+ max = 1.0;
+ if(max > 0.0)
+ {
+ if(min <= 0.0)
+ min = 0.01*max;
+ }
+ else
+ {
+ if(min > 0.0)
+ max = 0.01*min;
+ }
}
x->x_min = min;
x->x_max = max;
if(x->x_min > x->x_max) /* bugfix */
- x->x_gui.x_isa.x_reverse = 1;
+ x->x_gui.x_isa.x_reverse = 1;
else
x->x_gui.x_isa.x_reverse = 0;
if(x->x_lin0_log1)
- x->x_k = log(x->x_max/x->x_min)/(double)(x->x_gui.x_w - 1);
+ x->x_k = log(x->x_max/x->x_min)/(double)(x->x_gui.x_w - 1);
else
- x->x_k = (x->x_max - x->x_min)/(double)(x->x_gui.x_w - 1);
+ x->x_k = (x->x_max - x->x_min)/(double)(x->x_gui.x_w - 1);
}
static void hslider_properties(t_gobj *z, t_glist *owner)
@@ -285,20 +285,20 @@ static void hslider_properties(t_gobj *z, t_glist *owner)
iemgui_properties(&x->x_gui, srl);
sprintf(buf, "pdtk_iemgui_dialog %%s HSLIDER \
- --------dimensions(pix)(pix):-------- %d %d width: %d %d height: \
- -----------output-range:----------- %g left: %g right: %g \
- %d lin log %d %d empty %d \
- %s %s \
- %s %d %d \
- %d %d \
- %d %d %d\n",
- x->x_gui.x_w, IEM_SL_MINSIZE, x->x_gui.x_h, IEM_GUI_MINSIZE,
- x->x_min, x->x_max, 0.0,/*no_schedule*/
- x->x_lin0_log1, x->x_gui.x_isa.x_loadinit, x->x_steady, -1,/*no multi, but iem-characteristic*/
- srl[0]->s_name, srl[1]->s_name,
- srl[2]->s_name, x->x_gui.x_ldx, x->x_gui.x_ldy,
- x->x_gui.x_fsf.x_font_style, x->x_gui.x_fontsize,
- 0xffffff & x->x_gui.x_bcol, 0xffffff & x->x_gui.x_fcol, 0xffffff & x->x_gui.x_lcol);
+ --------dimensions(pix)(pix):-------- %d %d width: %d %d height: \
+ -----------output-range:----------- %g left: %g right: %g \
+ %d lin log %d %d empty %d \
+ %s %s \
+ %s %d %d \
+ %d %d \
+ %d %d %d\n",
+ x->x_gui.x_w, IEM_SL_MINSIZE, x->x_gui.x_h, IEM_GUI_MINSIZE,
+ x->x_min, x->x_max, 0.0,/*no_schedule*/
+ x->x_lin0_log1, x->x_gui.x_isa.x_loadinit, x->x_steady, -1,/*no multi, but iem-characteristic*/
+ srl[0]->s_name, srl[1]->s_name,
+ srl[2]->s_name, x->x_gui.x_ldx, x->x_gui.x_ldy,
+ x->x_gui.x_fsf.x_font_style, x->x_gui.x_fontsize,
+ 0xffffff & x->x_gui.x_bcol, 0xffffff & x->x_gui.x_fcol, 0xffffff & x->x_gui.x_lcol);
gfxstub_new(&x->x_gui.x_obj.ob_pd, x, buf);
}
@@ -308,22 +308,22 @@ static void hslider_set(t_hslider *x, t_floatarg f) /* bugfix */
if(x->x_gui.x_isa.x_reverse) /* bugfix */
{
- if(f > x->x_min)
- f = x->x_min;
- if(f < x->x_max)
- f = x->x_max;
+ if(f > x->x_min)
+ f = x->x_min;
+ if(f < x->x_max)
+ f = x->x_max;
}
else
{
- if(f > x->x_max)
- f = x->x_max;
- if(f < x->x_min)
- f = x->x_min;
+ if(f > x->x_max)
+ f = x->x_max;
+ if(f < x->x_min)
+ f = x->x_min;
}
if(x->x_lin0_log1)
- g = log(f/x->x_min)/x->x_k;
+ g = log(f/x->x_min)/x->x_k;
else
- g = (f - x->x_min) / x->x_k;
+ g = (f - x->x_min) / x->x_k;
x->x_val = (int)(100.0*g + 0.49999);
x->x_pos = x->x_val;
(*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
@@ -334,11 +334,11 @@ static void hslider_bang(t_hslider *x)
double out;
if(x->x_lin0_log1)
- out = x->x_min*exp(x->x_k*(double)(x->x_val)*0.01);
+ out = x->x_min*exp(x->x_k*(double)(x->x_val)*0.01);
else
- out = (double)(x->x_val)*0.01*x->x_k + x->x_min;
+ out = (double)(x->x_val)*0.01*x->x_k + x->x_min;
if((out < 1.0e-10)&&(out > -1.0e-10))
- out = 0.0;
+ out = 0.0;
outlet_float(x->x_gui.x_obj.ob_outlet, out);
if(x->x_gui.x_fsf.x_snd_able && x->x_gui.x_snd->s_thing)
pd_float(x->x_gui.x_snd->s_thing, out);
@@ -358,9 +358,9 @@ static void hslider_dialog(t_hslider *x, t_symbol *s, int argc, t_atom *argv)
if(lilo != 0) lilo = 1;
x->x_lin0_log1 = lilo;
if(steady)
- x->x_steady = 1;
+ x->x_steady = 1;
else
- x->x_steady = 0;
+ x->x_steady = 0;
sr_flags = iemgui_dialog(&x->x_gui, srl, argc, argv);
x->x_gui.x_h = iemgui_clip_size(h);
hslider_check_width(x, w);
@@ -376,58 +376,58 @@ static void hslider_motion(t_hslider *x, t_floatarg dx, t_floatarg dy)
int old = x->x_val;
if(x->x_gui.x_fsf.x_finemoved)
- x->x_pos += (int)dx;
+ x->x_pos += (int)dx;
else
- x->x_pos += 100*(int)dx;
+ x->x_pos += 100*(int)dx;
x->x_val = x->x_pos;
if(x->x_val > (100*x->x_gui.x_w - 100))
{
- x->x_val = 100*x->x_gui.x_w - 100;
- x->x_pos += 50;
- x->x_pos -= x->x_pos%100;
+ x->x_val = 100*x->x_gui.x_w - 100;
+ x->x_pos += 50;
+ x->x_pos -= x->x_pos%100;
}
if(x->x_val < 0)
{
- x->x_val = 0;
- x->x_pos -= 50;
- x->x_pos -= x->x_pos%100;
+ x->x_val = 0;
+ x->x_pos -= 50;
+ x->x_pos -= x->x_pos%100;
}
if(old != x->x_val)
{
- (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
- hslider_bang(x);
+ (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
+ hslider_bang(x);
}
}
static void hslider_click(t_hslider *x, t_floatarg xpos, t_floatarg ypos,
- t_floatarg shift, t_floatarg ctrl, t_floatarg alt)
+ t_floatarg shift, t_floatarg ctrl, t_floatarg alt)
{
if(!x->x_steady)
- x->x_val = (int)(100.0 * (xpos - text_xpix(&x->x_gui.x_obj, x->x_gui.x_glist)));
+ x->x_val = (int)(100.0 * (xpos - text_xpix(&x->x_gui.x_obj, x->x_gui.x_glist)));
if(x->x_val > (100*x->x_gui.x_w - 100))
- x->x_val = 100*x->x_gui.x_w - 100;
+ x->x_val = 100*x->x_gui.x_w - 100;
if(x->x_val < 0)
- x->x_val = 0;
+ x->x_val = 0;
x->x_pos = x->x_val;
(*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
hslider_bang(x);
glist_grab(x->x_gui.x_glist, &x->x_gui.x_obj.te_g, (t_glistmotionfn)hslider_motion,
- 0, xpos, ypos);
+ 0, xpos, ypos);
}
static int hslider_newclick(t_gobj *z, struct _glist *glist,
- int xpix, int ypix, int shift, int alt, int dbl, int doit)
+ int xpix, int ypix, int shift, int alt, int dbl, int doit)
{
t_hslider* x = (t_hslider *)z;
if(doit)
{
- hslider_click( x, (t_floatarg)xpix, (t_floatarg)ypix, (t_floatarg)shift,
- 0, (t_floatarg)alt);
- if(shift)
- x->x_gui.x_fsf.x_finemoved = 1;
- else
- x->x_gui.x_fsf.x_finemoved = 0;
+ hslider_click( x, (t_floatarg)xpix, (t_floatarg)ypix, (t_floatarg)shift,
+ 0, (t_floatarg)alt);
+ if(shift)
+ x->x_gui.x_fsf.x_finemoved = 1;
+ else
+ x->x_gui.x_fsf.x_finemoved = 0;
}
return (1);
}
@@ -436,7 +436,7 @@ static void hslider_size(t_hslider *x, t_symbol *s, int ac, t_atom *av)
{
hslider_check_width(x, (int)atom_getintarg(0, ac, av));
if(ac > 1)
- x->x_gui.x_h = iemgui_clip_size((int)atom_getintarg(1, ac, av));
+ x->x_gui.x_h = iemgui_clip_size((int)atom_getintarg(1, ac, av));
iemgui_size((void *)x, &x->x_gui);
}
@@ -449,7 +449,7 @@ static void hslider_pos(t_hslider *x, t_symbol *s, int ac, t_atom *av)
static void hslider_range(t_hslider *x, t_symbol *s, int ac, t_atom *av)
{
hslider_check_minmax(x, (double)atom_getfloatarg(0, ac, av),
- (double)atom_getfloatarg(1, ac, av));
+ (double)atom_getfloatarg(1, ac, av));
}
static void hslider_color(t_hslider *x, t_symbol *s, int ac, t_atom *av)
@@ -498,16 +498,16 @@ static void hslider_float(t_hslider *x, t_floatarg f)
hslider_set(x, f);
if(x->x_lin0_log1)
- out = x->x_min*exp(x->x_k*(double)(x->x_val)*0.01);
+ out = x->x_min*exp(x->x_k*(double)(x->x_val)*0.01);
else
- out = (double)(x->x_val)*0.01*x->x_k + x->x_min;
+ out = (double)(x->x_val)*0.01*x->x_k + x->x_min;
if((out < 1.0e-10)&&(out > -1.0e-10))
- out = 0.0;
+ out = 0.0;
if(x->x_gui.x_fsf.x_put_in2out)
{
- outlet_float(x->x_gui.x_obj.ob_outlet, out);
- if(x->x_gui.x_fsf.x_snd_able && x->x_gui.x_snd->s_thing)
- pd_float(x->x_gui.x_snd->s_thing, out);
+ outlet_float(x->x_gui.x_obj.ob_outlet, out);
+ if(x->x_gui.x_fsf.x_snd_able && x->x_gui.x_snd->s_thing)
+ pd_float(x->x_gui.x_snd->s_thing, out);
}
}
@@ -515,8 +515,8 @@ static void hslider_loadbang(t_hslider *x)
{
if(!sys_noloadbang && x->x_gui.x_isa.x_loadinit)
{
- (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
- hslider_bang(x);
+ (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
+ hslider_bang(x);
}
}
@@ -543,25 +543,25 @@ static void *hslider_new(t_symbol *s, int argc, t_atom *argv)
&&IS_A_FLOAT(argv,11)&&IS_A_FLOAT(argv,12)&&IS_A_FLOAT(argv,13)
&&IS_A_FLOAT(argv,14)&&IS_A_FLOAT(argv,15)&&IS_A_FLOAT(argv,16))
{
- w = (int)atom_getintarg(0, argc, argv);
- h = (int)atom_getintarg(1, argc, argv);
- min = (double)atom_getfloatarg(2, argc, argv);
- max = (double)atom_getfloatarg(3, argc, argv);
- lilo = (int)atom_getintarg(4, argc, argv);
- iem_inttosymargs(&x->x_gui.x_isa, atom_getintarg(5, argc, argv));
- iemgui_new_getnames(&x->x_gui, 6, argv);
- ldx = (int)atom_getintarg(9, argc, argv);
- ldy = (int)atom_getintarg(10, argc, argv);
- iem_inttofstyle(&x->x_gui.x_fsf, atom_getintarg(11, argc, argv));
- fs = (int)atom_getintarg(12, argc, argv);
- bflcol[0] = (int)atom_getintarg(13, argc, argv);
- bflcol[1] = (int)atom_getintarg(14, argc, argv);
- bflcol[2] = (int)atom_getintarg(15, argc, argv);
- v = (int)atom_getintarg(16, argc, argv);
+ w = (int)atom_getintarg(0, argc, argv);
+ h = (int)atom_getintarg(1, argc, argv);
+ min = (double)atom_getfloatarg(2, argc, argv);
+ max = (double)atom_getfloatarg(3, argc, argv);
+ lilo = (int)atom_getintarg(4, argc, argv);
+ iem_inttosymargs(&x->x_gui.x_isa, atom_getintarg(5, argc, argv));
+ iemgui_new_getnames(&x->x_gui, 6, argv);
+ ldx = (int)atom_getintarg(9, argc, argv);
+ ldy = (int)atom_getintarg(10, argc, argv);
+ iem_inttofstyle(&x->x_gui.x_fsf, atom_getintarg(11, argc, argv));
+ fs = (int)atom_getintarg(12, argc, argv);
+ bflcol[0] = (int)atom_getintarg(13, argc, argv);
+ bflcol[1] = (int)atom_getintarg(14, argc, argv);
+ bflcol[2] = (int)atom_getintarg(15, argc, argv);
+ v = (int)atom_getintarg(16, argc, argv);
}
else iemgui_new_getnames(&x->x_gui, 6, 0);
if((argc == 18)&&IS_A_FLOAT(argv,17))
- steady = (int)atom_getintarg(17, argc, argv);
+ steady = (int)atom_getintarg(17, argc, argv);
x->x_gui.x_draw = (t_iemfunptr)hslider_draw;
@@ -570,28 +570,28 @@ static void *hslider_new(t_symbol *s, int argc, t_atom *argv)
x->x_gui.x_glist = (t_glist *)canvas_getcurrent();
if(x->x_gui.x_isa.x_loadinit)
- x->x_val = v;
+ x->x_val = v;
else
- x->x_val = 0;
+ x->x_val = 0;
x->x_pos = x->x_val;
if(lilo != 0) lilo = 1;
x->x_lin0_log1 = lilo;
if(steady != 0) steady = 1;
x->x_steady = steady;
if (!strcmp(x->x_gui.x_snd->s_name, "empty"))
- x->x_gui.x_fsf.x_snd_able = 0;
+ x->x_gui.x_fsf.x_snd_able = 0;
if (!strcmp(x->x_gui.x_rcv->s_name, "empty"))
- x->x_gui.x_fsf.x_rcv_able = 0;
+ x->x_gui.x_fsf.x_rcv_able = 0;
if(x->x_gui.x_fsf.x_font_style == 1) strcpy(x->x_gui.x_font, "helvetica");
else if(x->x_gui.x_fsf.x_font_style == 2) strcpy(x->x_gui.x_font, "times");
else { x->x_gui.x_fsf.x_font_style = 0;
- strcpy(x->x_gui.x_font, "courier"); }
+ strcpy(x->x_gui.x_font, "courier"); }
if(x->x_gui.x_fsf.x_rcv_able)
- pd_bind(&x->x_gui.x_obj.ob_pd, x->x_gui.x_rcv);
+ pd_bind(&x->x_gui.x_obj.ob_pd, x->x_gui.x_rcv);
x->x_gui.x_ldx = ldx;
x->x_gui.x_ldy = ldy;
if(fs < 4)
- fs = 4;
+ fs = 4;
x->x_gui.x_fontsize = fs;
x->x_gui.x_h = iemgui_clip_size(h);
hslider_check_width(x, w);
@@ -606,23 +606,23 @@ static void *hslider_new(t_symbol *s, int argc, t_atom *argv)
static void hslider_free(t_hslider *x)
{
if(x->x_gui.x_fsf.x_rcv_able)
- pd_unbind(&x->x_gui.x_obj.ob_pd, x->x_gui.x_rcv);
+ pd_unbind(&x->x_gui.x_obj.ob_pd, x->x_gui.x_rcv);
gfxstub_deleteforkey(x);
}
void g_hslider_setup(void)
{
hslider_class = class_new(gensym("hsl"), (t_newmethod)hslider_new,
- (t_method)hslider_free, sizeof(t_hslider), 0, A_GIMME, 0);
+ (t_method)hslider_free, sizeof(t_hslider), 0, A_GIMME, 0);
#ifndef GGEE_HSLIDER_COMPATIBLE
class_addcreator((t_newmethod)hslider_new, gensym("hslider"), A_GIMME, 0);
#endif
class_addbang(hslider_class,hslider_bang);
class_addfloat(hslider_class,hslider_float);
class_addmethod(hslider_class, (t_method)hslider_click, gensym("click"),
- A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, 0);
+ A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, 0);
class_addmethod(hslider_class, (t_method)hslider_motion, gensym("motion"),
- A_FLOAT, A_FLOAT, 0);
+ A_FLOAT, A_FLOAT, 0);
class_addmethod(hslider_class, (t_method)hslider_dialog, gensym("dialog"), A_GIMME, 0);
class_addmethod(hslider_class, (t_method)hslider_loadbang, gensym("loadbang"), 0);
class_addmethod(hslider_class, (t_method)hslider_set, gensym("set"), A_FLOAT, 0);
diff --git a/pd/src/g_io.c b/pd/src/g_io.c
index 196d44d8..d252fc47 100644
--- a/pd/src/g_io.c
+++ b/pd/src/g_io.c
@@ -37,7 +37,7 @@ typedef struct _vinlet
t_canvas *x_canvas;
t_inlet *x_inlet;
int x_bufsize;
- t_float *x_buf; /* signal buffer; zero if not a signal */
+ t_float *x_buf; /* signal buffer; zero if not a signal */
t_float *x_endbuf;
t_float *x_fill;
t_float *x_read;
@@ -117,8 +117,8 @@ t_int *vinlet_perform(t_int *w)
int n = (int)(w[3]);
t_float *in = x->x_read;
#if 0
- if (tot < 5) post("-in %x out %x n %d", in, out, n);
- if (tot < 5) post("-buf %x endbuf %x", x->x_buf, x->x_endbuf);
+ if (tot < 5) post("-in %lx out %lx n %d", in, out, n);
+ if (tot < 5) post("-buf %lx endbuf %lx", x->x_buf, x->x_endbuf);
if (tot < 5) post("in[0] %f in[1] %f in[2] %f", in[0], in[1], in[2]);
#endif
while (n--) *out++ = *in++;
@@ -130,18 +130,18 @@ t_int *vinlet_perform(t_int *w)
static void vinlet_dsp(t_vinlet *x, t_signal **sp)
{
t_signal *outsig;
- /* no buffer means we're not a signal inlet */
+ /* no buffer means we're not a signal inlet */
if (!x->x_buf)
- return;
+ return;
outsig = sp[0];
if (x->x_directsignal)
{
- signal_setborrowed(sp[0], x->x_directsignal);
+ signal_setborrowed(sp[0], x->x_directsignal);
}
else
{
- dsp_add(vinlet_perform, 3, x, outsig->s_vec, outsig->s_n);
- x->x_read = x->x_buf;
+ dsp_add(vinlet_perform, 3, x, outsig->s_vec, outsig->s_n);
+ x->x_read = x->x_buf;
}
}
@@ -155,12 +155,12 @@ t_int *vinlet_doprolog(t_int *w)
if (out == x->x_endbuf)
{
t_float *f1 = x->x_buf, *f2 = x->x_buf + x->x_hop;
- int nshift = x->x_bufsize - x->x_hop;
- out -= x->x_hop;
- while (nshift--) *f1++ = *f2++;
+ int nshift = x->x_bufsize - x->x_hop;
+ out -= x->x_hop;
+ while (nshift--) *f1++ = *f2++;
}
#if 0
- if (tot < 5) post("in %x out %x n %x", in, out, n), tot++;
+ if (tot < 5) post("in %lx out %lx n %lx", in, out, n), tot++;
if (tot < 5) post("in[0] %f in[1] %f in[2] %f", in[0], in[1], in[2]);
#endif
@@ -171,82 +171,82 @@ t_int *vinlet_doprolog(t_int *w)
int inlet_getsignalindex(t_inlet *x);
- /* set up prolog DSP code */
+ /* set up prolog DSP code */
void vinlet_dspprolog(t_vinlet *x, t_signal **parentsigs,
- int myvecsize, int phase, int period, int frequency, int downsample, int upsample/* IOhannes */, int reblock,
- int switched)
+ int myvecsize, int phase, int period, int frequency, int downsample, int upsample/* IOhannes */, int reblock,
+ int switched)
{
t_signal *insig, *outsig;
x->x_updown.downsample = downsample;
x->x_updown.upsample = upsample;
- /* if the "reblock" flag is set, arrange to copy data in from the
- parent. */
+ /* if the "reblock" flag is set, arrange to copy data in from the
+ parent. */
if (reblock)
{
- int parentvecsize, bufsize, oldbufsize, prologphase;
- int re_parentvecsize; /* resampled parentvectorsize: IOhannes */
- /* this should never happen: */
- if (!x->x_buf) return;
-
- /* the prolog code counts from 0 to period-1; the
- phase is backed up by one so that AFTER the prolog code
- runs, the "x_fill" phase is in sync with the "x_read" phase. */
- prologphase = (phase - 1) & (period - 1);
- if (parentsigs)
- {
- insig = parentsigs[inlet_getsignalindex(x->x_inlet)];
- parentvecsize = insig->s_n;
- re_parentvecsize = parentvecsize * upsample / downsample;
- }
- else
- {
- insig = 0;
- parentvecsize = 1;
- re_parentvecsize = 1;
- }
-
- bufsize = re_parentvecsize;
- if (bufsize < myvecsize) bufsize = myvecsize;
- if (bufsize != (oldbufsize = x->x_bufsize))
- {
- t_float *buf = x->x_buf;
- t_freebytes(buf, oldbufsize * sizeof(*buf));
- buf = (t_float *)t_getbytes(bufsize * sizeof(*buf));
- memset((char *)buf, 0, bufsize * sizeof(*buf));
- x->x_bufsize = bufsize;
- x->x_endbuf = buf + bufsize;
- x->x_buf = buf;
- }
- if (parentsigs)
- {
- /* IOhannes { */
- x->x_hop = period * re_parentvecsize;
-
- x->x_fill = x->x_endbuf -
- (x->x_hop - prologphase * re_parentvecsize);
-
- if (upsample * downsample == 1)
- dsp_add(vinlet_doprolog, 3, x, insig->s_vec, re_parentvecsize);
- else {
- resamplefrom_dsp(&x->x_updown, insig->s_vec, parentvecsize, re_parentvecsize, x->x_updown.method);
- dsp_add(vinlet_doprolog, 3, x, x->x_updown.s_vec, re_parentvecsize);
- }
-
- /* } IOhannes */
- /* if the input signal's reference count is zero, we have
- to free it here because we didn't in ugen_doit(). */
- if (!insig->s_refcount)
- signal_makereusable(insig);
- }
- else memset((char *)(x->x_buf), 0, bufsize * sizeof(*x->x_buf));
- x->x_directsignal = 0;
+ int parentvecsize, bufsize, oldbufsize, prologphase;
+ int re_parentvecsize; /* resampled parentvectorsize: IOhannes */
+ /* this should never happen: */
+ if (!x->x_buf) return;
+
+ /* the prolog code counts from 0 to period-1; the
+ phase is backed up by one so that AFTER the prolog code
+ runs, the "x_fill" phase is in sync with the "x_read" phase. */
+ prologphase = (phase - 1) & (period - 1);
+ if (parentsigs)
+ {
+ insig = parentsigs[inlet_getsignalindex(x->x_inlet)];
+ parentvecsize = insig->s_n;
+ re_parentvecsize = parentvecsize * upsample / downsample;
+ }
+ else
+ {
+ insig = 0;
+ parentvecsize = 1;
+ re_parentvecsize = 1;
+ }
+
+ bufsize = re_parentvecsize;
+ if (bufsize < myvecsize) bufsize = myvecsize;
+ if (bufsize != (oldbufsize = x->x_bufsize))
+ {
+ t_float *buf = x->x_buf;
+ t_freebytes(buf, oldbufsize * sizeof(*buf));
+ buf = (t_float *)t_getbytes(bufsize * sizeof(*buf));
+ memset((char *)buf, 0, bufsize * sizeof(*buf));
+ x->x_bufsize = bufsize;
+ x->x_endbuf = buf + bufsize;
+ x->x_buf = buf;
+ }
+ if (parentsigs)
+ {
+ /* IOhannes { */
+ x->x_hop = period * re_parentvecsize;
+
+ x->x_fill = x->x_endbuf -
+ (x->x_hop - prologphase * re_parentvecsize);
+
+ if (upsample * downsample == 1)
+ dsp_add(vinlet_doprolog, 3, x, insig->s_vec, re_parentvecsize);
+ else {
+ resamplefrom_dsp(&x->x_updown, insig->s_vec, parentvecsize, re_parentvecsize, x->x_updown.method);
+ dsp_add(vinlet_doprolog, 3, x, x->x_updown.s_vec, re_parentvecsize);
+ }
+
+ /* } IOhannes */
+ /* if the input signal's reference count is zero, we have
+ to free it here because we didn't in ugen_doit(). */
+ if (!insig->s_refcount)
+ signal_makereusable(insig);
+ }
+ else memset((char *)(x->x_buf), 0, bufsize * sizeof(*x->x_buf));
+ x->x_directsignal = 0;
}
else
{
- /* no reblocking; in this case our output signal is "borrowed"
- and merely needs to be pointed to the real one. */
- x->x_directsignal = parentsigs[inlet_getsignalindex(x->x_inlet)];
+ /* no reblocking; in this case our output signal is "borrowed"
+ and merely needs to be pointed to the real one. */
+ x->x_directsignal = parentsigs[inlet_getsignalindex(x->x_inlet)];
}
}
@@ -279,7 +279,7 @@ static void *vinlet_newsig(t_symbol *s)
static void vinlet_setup(void)
{
vinlet_class = class_new(gensym("inlet"), (t_newmethod)vinlet_new,
- (t_method)vinlet_free, sizeof(t_vinlet), CLASS_NOINLET, A_DEFSYM, 0);
+ (t_method)vinlet_free, sizeof(t_vinlet), CLASS_NOINLET, A_DEFSYM, 0);
class_addcreator((t_newmethod)vinlet_newsig, gensym("inlet~"), A_DEFSYM, 0);
class_addbang(vinlet_class, vinlet_bang);
class_addpointer(vinlet_class, vinlet_pointer);
@@ -301,17 +301,17 @@ typedef struct _voutlet
t_canvas *x_canvas;
t_outlet *x_parentoutlet;
int x_bufsize;
- t_float *x_buf; /* signal buffer; zero if not a signal */
+ t_float *x_buf; /* signal buffer; zero if not a signal */
t_float *x_endbuf;
- t_float *x_empty; /* next to read out of buffer in epilog code */
- t_float *x_write; /* next to write in to buffer */
- int x_hop; /* hopsize */
- /* vice versa from the inlet, if we don't block, this holds the
- parent's outlet signal, valid between the prolog and the dsp setup
- routines. */
+ t_float *x_empty; /* next to read out of buffer in epilog code */
+ t_float *x_write; /* next to write in to buffer */
+ int x_hop; /* hopsize */
+ /* vice versa from the inlet, if we don't block, this holds the
+ parent's outlet signal, valid between the prolog and the dsp setup
+ routines. */
t_signal *x_directsignal;
- /* and here's a flag indicating that we aren't blocked but have to
- do a copy (because we're switched). */
+ /* and here's a flag indicating that we aren't blocked but have to
+ do a copy (because we're switched). */
char x_justcopyout;
t_resample x_updown; /* IOhannes */
} t_voutlet;
@@ -384,13 +384,13 @@ t_int *voutlet_perform(t_int *w)
int n = (int)(w[3]);
t_float *out = x->x_write, *outwas = out;
#if 0
- if (tot < 5) post("-in %x out %x n %d", in, out, n);
- if (tot < 5) post("-buf %x endbuf %x", x->x_buf, x->x_endbuf);
+ if (tot < 5) post("-in %lx out %lx n %d", in, out, n);
+ if (tot < 5) post("-buf %lx endbuf %lx", x->x_buf, x->x_endbuf);
#endif
while (n--)
{
- *out++ += *in++;
- if (out == x->x_endbuf) out = x->x_buf;
+ *out++ += *in++;
+ if (out == x->x_endbuf) out = x->x_buf;
}
outwas += x->x_hop;
if (outwas >= x->x_endbuf) outwas = x->x_buf;
@@ -409,7 +409,7 @@ static t_int *voutlet_doepilog(t_int *w)
if (x->x_updown.downsample != x->x_updown.upsample) out = x->x_updown.s_vec; /* IOhannes */
#if 0
- if (tot < 5) post("outlet in %x out %x n %x", in, out, n), tot++;
+ if (tot < 5) post("outlet in %lx out %lx n %lx", in, out, n), tot++;
#endif
for (; n--; in++) *out++ = *in, *in = 0;
if (in == x->x_endbuf) in = x->x_buf;
@@ -427,7 +427,7 @@ static t_int *voutlet_doepilog_resampling(t_int *w)
t_float *out = x->x_updown.s_vec; /* IOhannes */
#if 0
- if (tot < 5) post("outlet in %x out %x n %x", in, out, n), tot++;
+ if (tot < 5) post("outlet in %lx out %lx n %lx", in, out, n), tot++;
#endif
for (; n--; in++) *out++ = *in, *in = 0;
if (in == x->x_endbuf) in = x->x_buf;
@@ -437,25 +437,25 @@ static t_int *voutlet_doepilog_resampling(t_int *w)
/* } IOhannes */
int outlet_getsignalindex(t_outlet *x);
- /* prolog for outlets -- store pointer to the outlet on the
- parent, which, if "reblock" is false, will want to refer
- back to whatever we see on our input during the "dsp" method
- called later. */
+ /* prolog for outlets -- store pointer to the outlet on the
+ parent, which, if "reblock" is false, will want to refer
+ back to whatever we see on our input during the "dsp" method
+ called later. */
void voutlet_dspprolog(t_voutlet *x, t_signal **parentsigs,
int myvecsize, int phase, int period, int frequency, int downsample, int upsample /* IOhannes */, int reblock,
- int switched)
+ int switched)
{
x->x_updown.downsample=downsample; x->x_updown.upsample=upsample; /* IOhannes */
x->x_justcopyout = (switched && !reblock);
if (reblock)
{
- x->x_directsignal = 0;
+ x->x_directsignal = 0;
}
else
{
- if (!parentsigs) bug("voutlet_dspprolog");
- x->x_directsignal =
- parentsigs[outlet_getsignalindex(x->x_parentoutlet)];
+ if (!parentsigs) bug("voutlet_dspprolog");
+ x->x_directsignal =
+ parentsigs[outlet_getsignalindex(x->x_parentoutlet)];
}
}
@@ -468,18 +468,18 @@ static void voutlet_dsp(t_voutlet *x, t_signal **sp)
dsp_add_copy(insig->s_vec, x->x_directsignal->s_vec, insig->s_n);
else if (x->x_directsignal)
{
- /* if we're just going to make the signal available on the
- parent patch, hand it off to the parent signal. */
- /* this is done elsewhere--> sp[0]->s_refcount++; */
- signal_setborrowed(x->x_directsignal, sp[0]);
+ /* if we're just going to make the signal available on the
+ parent patch, hand it off to the parent signal. */
+ /* this is done elsewhere--> sp[0]->s_refcount++; */
+ signal_setborrowed(x->x_directsignal, sp[0]);
}
else
- dsp_add(voutlet_perform, 3, x, insig->s_vec, insig->s_n);
+ dsp_add(voutlet_perform, 3, x, insig->s_vec, insig->s_n);
}
- /* set up epilog DSP code. If we're reblocking, this is the
- time to copy the samples out to the containing object's outlets.
- If we aren't reblocking, there's nothing to do here. */
+ /* set up epilog DSP code. If we're reblocking, this is the
+ time to copy the samples out to the containing object's outlets.
+ If we aren't reblocking, there's nothing to do here. */
void voutlet_dspepilog(t_voutlet *x, t_signal **parentsigs,
int myvecsize, int phase, int period, int frequency, int downsample,
int upsample /* IOhannes */, int reblock, int switched)
@@ -489,75 +489,75 @@ void voutlet_dspepilog(t_voutlet *x, t_signal **parentsigs,
x->x_updown.upsample=upsample; /* IOhannes */
if (reblock)
{
- t_signal *insig, *outsig;
- int parentvecsize, bufsize, oldbufsize;
- int re_parentvecsize; /* IOhannes */
- int bigperiod, epilogphase, blockphase;
- if (parentsigs)
- {
- outsig = parentsigs[outlet_getsignalindex(x->x_parentoutlet)];
- parentvecsize = outsig->s_n;
- re_parentvecsize = parentvecsize * upsample / downsample;
- }
- else
- {
- outsig = 0;
- parentvecsize = 1;
- re_parentvecsize = 1;
- }
- // bigperiod = (downsample * myvecsize)/(upsample * parentvecsize); /* IOhannes */
- bigperiod = myvecsize/re_parentvecsize; /* IOhannes */
- if (!bigperiod) bigperiod = 1;
- epilogphase = phase & (bigperiod - 1);
- blockphase = (phase + period - 1) & (bigperiod - 1) & (- period);
- // bufsize = parentvecsize * upsample; /* IOhannes */
- bufsize = re_parentvecsize; /* IOhannes */
- if (bufsize < myvecsize) bufsize = myvecsize;
- if (bufsize != (oldbufsize = x->x_bufsize))
- {
- t_float *buf = x->x_buf;
- t_freebytes(buf, oldbufsize * sizeof(*buf));
- buf = (t_float *)t_getbytes(bufsize * sizeof(*buf));
- memset((char *)buf, 0, bufsize * sizeof(*buf));
- x->x_bufsize = bufsize;
- x->x_endbuf = buf + bufsize;
- x->x_buf = buf;
- }
+ t_signal *insig, *outsig;
+ int parentvecsize, bufsize, oldbufsize;
+ int re_parentvecsize; /* IOhannes */
+ int bigperiod, epilogphase, blockphase;
+ if (parentsigs)
+ {
+ outsig = parentsigs[outlet_getsignalindex(x->x_parentoutlet)];
+ parentvecsize = outsig->s_n;
+ re_parentvecsize = parentvecsize * upsample / downsample;
+ }
+ else
+ {
+ outsig = 0;
+ parentvecsize = 1;
+ re_parentvecsize = 1;
+ }
+ // bigperiod = (downsample * myvecsize)/(upsample * parentvecsize); /* IOhannes */
+ bigperiod = myvecsize/re_parentvecsize; /* IOhannes */
+ if (!bigperiod) bigperiod = 1;
+ epilogphase = phase & (bigperiod - 1);
+ blockphase = (phase + period - 1) & (bigperiod - 1) & (- period);
+ // bufsize = parentvecsize * upsample; /* IOhannes */
+ bufsize = re_parentvecsize; /* IOhannes */
+ if (bufsize < myvecsize) bufsize = myvecsize;
+ if (bufsize != (oldbufsize = x->x_bufsize))
+ {
+ t_float *buf = x->x_buf;
+ t_freebytes(buf, oldbufsize * sizeof(*buf));
+ buf = (t_float *)t_getbytes(bufsize * sizeof(*buf));
+ memset((char *)buf, 0, bufsize * sizeof(*buf));
+ x->x_bufsize = bufsize;
+ x->x_endbuf = buf + bufsize;
+ x->x_buf = buf;
+ }
/* IOhannes: { */
- if (re_parentvecsize * period > bufsize) bug("voutlet_dspepilog");
- x->x_write = x->x_buf + re_parentvecsize * blockphase;
- if (x->x_write == x->x_endbuf) x->x_write = x->x_buf;
- if (period == 1 && frequency > 1)
- x->x_hop = re_parentvecsize / frequency;
- else x->x_hop = period * re_parentvecsize;
+ if (re_parentvecsize * period > bufsize) bug("voutlet_dspepilog");
+ x->x_write = x->x_buf + re_parentvecsize * blockphase;
+ if (x->x_write == x->x_endbuf) x->x_write = x->x_buf;
+ if (period == 1 && frequency > 1)
+ x->x_hop = re_parentvecsize / frequency;
+ else x->x_hop = period * re_parentvecsize;
/* } IOhannes */
- /* post("phase %d, block %d, parent %d", phase & 63,
- parentvecsize * blockphase, parentvecsize * epilogphase); */
- if (parentsigs)
- {
- /* set epilog pointer and schedule it */
- /* IOhannes { */
- x->x_empty = x->x_buf + re_parentvecsize * epilogphase;
- if (upsample * downsample == 1)
- dsp_add(voutlet_doepilog, 3, x, outsig->s_vec, re_parentvecsize);
- else {
- dsp_add(voutlet_doepilog_resampling, 2, x, re_parentvecsize);
- resampleto_dsp(&x->x_updown, outsig->s_vec, re_parentvecsize, parentvecsize, x->x_updown.method);
- }
- /* } IOhannes */
- }
+ /* post("phase %d, block %d, parent %d", phase & 63,
+ parentvecsize * blockphase, parentvecsize * epilogphase); */
+ if (parentsigs)
+ {
+ /* set epilog pointer and schedule it */
+ /* IOhannes { */
+ x->x_empty = x->x_buf + re_parentvecsize * epilogphase;
+ if (upsample * downsample == 1)
+ dsp_add(voutlet_doepilog, 3, x, outsig->s_vec, re_parentvecsize);
+ else {
+ dsp_add(voutlet_doepilog_resampling, 2, x, re_parentvecsize);
+ resampleto_dsp(&x->x_updown, outsig->s_vec, re_parentvecsize, parentvecsize, x->x_updown.method);
+ }
+ /* } IOhannes */
+ }
}
- /* if we aren't blocked but we are switched, the epilog code just
- copies zeros to the output. In this case the blocking code actually
- jumps over the epilog if the block is running. */
+ /* if we aren't blocked but we are switched, the epilog code just
+ copies zeros to the output. In this case the blocking code actually
+ jumps over the epilog if the block is running. */
else if (switched)
{
- if (parentsigs)
- {
- t_signal *outsig =
- parentsigs[outlet_getsignalindex(x->x_parentoutlet)];
- dsp_add_zero(outsig->s_vec, outsig->s_n);
- }
+ if (parentsigs)
+ {
+ t_signal *outsig =
+ parentsigs[outlet_getsignalindex(x->x_parentoutlet)];
+ dsp_add_zero(outsig->s_vec, outsig->s_n);
+ }
}
}
@@ -566,7 +566,7 @@ static void *voutlet_newsig(t_symbol *s)
t_voutlet *x = (t_voutlet *)pd_new(voutlet_class);
x->x_canvas = canvas_getcurrent();
x->x_parentoutlet = canvas_addoutlet(x->x_canvas,
- &x->x_obj.ob_pd, &s_signal);
+ &x->x_obj.ob_pd, &s_signal);
inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_signal, &s_signal);
x->x_endbuf = x->x_buf = (t_float *)getbytes(0);
x->x_bufsize = 0;
@@ -591,7 +591,7 @@ static void *voutlet_newsig(t_symbol *s)
static void voutlet_setup(void)
{
voutlet_class = class_new(gensym("outlet"), (t_newmethod)voutlet_new,
- (t_method)voutlet_free, sizeof(t_voutlet), CLASS_NOINLET, A_DEFSYM, 0);
+ (t_method)voutlet_free, sizeof(t_voutlet), CLASS_NOINLET, A_DEFSYM, 0);
class_addcreator((t_newmethod)voutlet_newsig, gensym("outlet~"), A_DEFSYM, 0);
class_addbang(voutlet_class, voutlet_bang);
class_addpointer(voutlet_class, voutlet_pointer);
diff --git a/pd/src/g_mycanvas.c b/pd/src/g_mycanvas.c
index ff55e86b..93f96ff5 100644
--- a/pd/src/g_mycanvas.c
+++ b/pd/src/g_mycanvas.c
@@ -35,19 +35,19 @@ void my_canvas_draw_new(t_my_canvas *x, t_glist *glist)
int ypos=text_ypix(&x->x_gui.x_obj, glist);
t_canvas *canvas=glist_getcanvas(glist);
- sys_vgui(".x%x.c create rectangle %d %d %d %d -fill #%6.6x -outline #%6.6x -tags %xRECT\n",
- canvas, xpos, ypos,
- xpos + x->x_vis_w, ypos + x->x_vis_h,
- x->x_gui.x_bcol, x->x_gui.x_bcol, x);
- sys_vgui(".x%x.c create rectangle %d %d %d %d -outline #%6.6x -tags %xBASE\n",
- canvas, xpos, ypos,
- xpos + x->x_gui.x_w, ypos + x->x_gui.x_h,
- x->x_gui.x_bcol, x);
- sys_vgui(".x%x.c create text %d %d -text {%s} -anchor w \
- -font {%s %d bold} -fill #%6.6x -tags %xLABEL\n",
- canvas, xpos+x->x_gui.x_ldx, ypos+x->x_gui.x_ldy,
- strcmp(x->x_gui.x_lab->s_name, "empty")?x->x_gui.x_lab->s_name:"",
- x->x_gui.x_font, x->x_gui.x_fontsize, x->x_gui.x_lcol, x);
+ sys_vgui(".x%lx.c create rectangle %d %d %d %d -fill #%6.6x -outline #%6.6x -tags %lxRECT\n",
+ canvas, xpos, ypos,
+ xpos + x->x_vis_w, ypos + x->x_vis_h,
+ x->x_gui.x_bcol, x->x_gui.x_bcol, x);
+ sys_vgui(".x%lx.c create rectangle %d %d %d %d -outline #%6.6x -tags %lxBASE\n",
+ canvas, xpos, ypos,
+ xpos + x->x_gui.x_w, ypos + x->x_gui.x_h,
+ x->x_gui.x_bcol, x);
+ sys_vgui(".x%lx.c create text %d %d -text {%s} -anchor w \
+ -font {%s %d bold} -fill #%6.6x -tags %lxLABEL\n",
+ canvas, xpos+x->x_gui.x_ldx, ypos+x->x_gui.x_ldy,
+ strcmp(x->x_gui.x_lab->s_name, "empty")?x->x_gui.x_lab->s_name:"",
+ x->x_gui.x_font, x->x_gui.x_fontsize, x->x_gui.x_lcol, x);
}
void my_canvas_draw_move(t_my_canvas *x, t_glist *glist)
@@ -56,37 +56,37 @@ void my_canvas_draw_move(t_my_canvas *x, t_glist *glist)
int ypos=text_ypix(&x->x_gui.x_obj, glist);
t_canvas *canvas=glist_getcanvas(glist);
- sys_vgui(".x%x.c coords %xRECT %d %d %d %d\n",
- canvas, x, xpos, ypos, xpos + x->x_vis_w,
- ypos + x->x_vis_h);
- sys_vgui(".x%x.c coords %xBASE %d %d %d %d\n",
- canvas, x, xpos, ypos,
- xpos + x->x_gui.x_w, ypos + x->x_gui.x_h);
- sys_vgui(".x%x.c coords %xLABEL %d %d\n",
- canvas, x, xpos+x->x_gui.x_ldx,
- ypos+x->x_gui.x_ldy);
+ sys_vgui(".x%lx.c coords %lxRECT %d %d %d %d\n",
+ canvas, x, xpos, ypos, xpos + x->x_vis_w,
+ ypos + x->x_vis_h);
+ sys_vgui(".x%lx.c coords %lxBASE %d %d %d %d\n",
+ canvas, x, xpos, ypos,
+ xpos + x->x_gui.x_w, ypos + x->x_gui.x_h);
+ sys_vgui(".x%lx.c coords %lxLABEL %d %d\n",
+ canvas, x, xpos+x->x_gui.x_ldx,
+ ypos+x->x_gui.x_ldy);
}
void my_canvas_draw_erase(t_my_canvas* x, t_glist* glist)
{
t_canvas *canvas=glist_getcanvas(glist);
- sys_vgui(".x%x.c delete %xBASE\n", canvas, x);
- sys_vgui(".x%x.c delete %xRECT\n", canvas, x);
- sys_vgui(".x%x.c delete %xLABEL\n", canvas, x);
+ sys_vgui(".x%lx.c delete %lxBASE\n", canvas, x);
+ sys_vgui(".x%lx.c delete %lxRECT\n", canvas, x);
+ sys_vgui(".x%lx.c delete %lxLABEL\n", canvas, x);
}
void my_canvas_draw_config(t_my_canvas* x, t_glist* glist)
{
t_canvas *canvas=glist_getcanvas(glist);
- sys_vgui(".x%x.c itemconfigure %xRECT -fill #%6.6x -outline #%6.6x\n", canvas, x,
- x->x_gui.x_bcol, x->x_gui.x_bcol);
- sys_vgui(".x%x.c itemconfigure %xBASE -outline #%6.6x\n", canvas, x,
- x->x_gui.x_fsf.x_selected?IEM_GUI_COLOR_SELECTED:x->x_gui.x_bcol);
- sys_vgui(".x%x.c itemconfigure %xLABEL -font {%s %d bold} -fill #%6.6x -text {%s} \n",
- canvas, x, x->x_gui.x_font, x->x_gui.x_fontsize, x->x_gui.x_lcol,
- strcmp(x->x_gui.x_lab->s_name, "empty")?x->x_gui.x_lab->s_name:"");
+ sys_vgui(".x%lx.c itemconfigure %lxRECT -fill #%6.6x -outline #%6.6x\n", canvas, x,
+ x->x_gui.x_bcol, x->x_gui.x_bcol);
+ sys_vgui(".x%lx.c itemconfigure %lxBASE -outline #%6.6x\n", canvas, x,
+ x->x_gui.x_fsf.x_selected?IEM_GUI_COLOR_SELECTED:x->x_gui.x_bcol);
+ sys_vgui(".x%lx.c itemconfigure %lxLABEL -font {%s %d bold} -fill #%6.6x -text {%s} \n",
+ canvas, x, x->x_gui.x_font, x->x_gui.x_fontsize, x->x_gui.x_lcol,
+ strcmp(x->x_gui.x_lab->s_name, "empty")?x->x_gui.x_lab->s_name:"");
}
void my_canvas_draw_select(t_my_canvas* x, t_glist* glist)
@@ -95,26 +95,26 @@ void my_canvas_draw_select(t_my_canvas* x, t_glist* glist)
if(x->x_gui.x_fsf.x_selected)
{
- sys_vgui(".x%x.c itemconfigure %xBASE -outline #%6.6x\n", canvas, x, IEM_GUI_COLOR_SELECTED);
+ sys_vgui(".x%lx.c itemconfigure %lxBASE -outline #%6.6x\n", canvas, x, IEM_GUI_COLOR_SELECTED);
}
else
{
- sys_vgui(".x%x.c itemconfigure %xBASE -outline #%6.6x\n", canvas, x, x->x_gui.x_bcol);
+ sys_vgui(".x%lx.c itemconfigure %lxBASE -outline #%6.6x\n", canvas, x, x->x_gui.x_bcol);
}
}
void my_canvas_draw(t_my_canvas *x, t_glist *glist, int mode)
{
if(mode == IEM_GUI_DRAW_MODE_MOVE)
- my_canvas_draw_move(x, glist);
+ my_canvas_draw_move(x, glist);
else if(mode == IEM_GUI_DRAW_MODE_NEW)
- my_canvas_draw_new(x, glist);
+ my_canvas_draw_new(x, glist);
else if(mode == IEM_GUI_DRAW_MODE_SELECT)
- my_canvas_draw_select(x, glist);
+ my_canvas_draw_select(x, glist);
else if(mode == IEM_GUI_DRAW_MODE_ERASE)
- my_canvas_draw_erase(x, glist);
+ my_canvas_draw_erase(x, glist);
else if(mode == IEM_GUI_DRAW_MODE_CONFIG)
- my_canvas_draw_config(x, glist);
+ my_canvas_draw_config(x, glist);
}
/* ------------------------ cnv widgetbehaviour----------------------------- */
@@ -137,11 +137,11 @@ static void my_canvas_save(t_gobj *z, t_binbuf *b)
iemgui_save(&x->x_gui, srl, bflcol);
binbuf_addv(b, "ssiisiiisssiiiiiii", gensym("#X"),gensym("obj"),
- (t_int)x->x_gui.x_obj.te_xpix, (t_int)x->x_gui.x_obj.te_ypix,
- gensym("cnv"), x->x_gui.x_w, x->x_vis_w, x->x_vis_h,
- srl[0], srl[1], srl[2], x->x_gui.x_ldx, x->x_gui.x_ldy,
- iem_fstyletoint(&x->x_gui.x_fsf), x->x_gui.x_fontsize,
- bflcol[0], bflcol[2], iem_symargstoint(&x->x_gui.x_isa));
+ (int)x->x_gui.x_obj.te_xpix, (int)x->x_gui.x_obj.te_ypix,
+ gensym("cnv"), x->x_gui.x_w, x->x_vis_w, x->x_vis_h,
+ srl[0], srl[1], srl[2], x->x_gui.x_ldx, x->x_gui.x_ldy,
+ iem_fstyletoint(&x->x_gui.x_fsf), x->x_gui.x_fontsize,
+ bflcol[0], bflcol[2], iem_symargstoint(&x->x_gui.x_isa));
binbuf_addv(b, ";");
}
@@ -153,20 +153,20 @@ static void my_canvas_properties(t_gobj *z, t_glist *owner)
iemgui_properties(&x->x_gui, srl);
sprintf(buf, "pdtk_iemgui_dialog %%s MY_CANVAS \
- ------selectable_dimensions(pix):------ %d %d size: 0.0 0.0 empty \
- ------visible_rectangle(pix)(pix):------ %d width: %d height: %d \
- %d empty empty %d %d empty %d \
- %s %s \
- %s %d %d \
- %d %d \
- %d %d %d\n",
- x->x_gui.x_w, 1,
- x->x_vis_w, x->x_vis_h, 0,/*no_schedule*/
- -1, -1, -1, -1,/*no linlog, no init, no multi*/
- srl[0]->s_name, srl[1]->s_name,
- srl[2]->s_name, x->x_gui.x_ldx, x->x_gui.x_ldy,
- x->x_gui.x_fsf.x_font_style, x->x_gui.x_fontsize,
- 0xffffff & x->x_gui.x_bcol, -1/*no frontcolor*/, 0xffffff & x->x_gui.x_lcol);
+ ------selectable_dimensions(pix):------ %d %d size: 0.0 0.0 empty \
+ ------visible_rectangle(pix)(pix):------ %d width: %d height: %d \
+ %d empty empty %d %d empty %d \
+ %s %s \
+ %s %d %d \
+ %d %d \
+ %d %d %d\n",
+ x->x_gui.x_w, 1,
+ x->x_vis_w, x->x_vis_h, 0,/*no_schedule*/
+ -1, -1, -1, -1,/*no linlog, no init, no multi*/
+ srl[0]->s_name, srl[1]->s_name,
+ srl[2]->s_name, x->x_gui.x_ldx, x->x_gui.x_ldy,
+ x->x_gui.x_fsf.x_font_style, x->x_gui.x_fontsize,
+ 0xffffff & x->x_gui.x_bcol, -1/*no frontcolor*/, 0xffffff & x->x_gui.x_lcol);
gfxstub_new(&x->x_gui.x_obj.ob_pd, x, buf);
}
@@ -174,9 +174,9 @@ static void my_canvas_get_pos(t_my_canvas *x)
{
if(x->x_gui.x_fsf.x_snd_able && x->x_gui.x_snd->s_thing)
{
- x->x_at[0].a_w.w_float = text_xpix(&x->x_gui.x_obj, x->x_gui.x_glist);
- x->x_at[1].a_w.w_float = text_ypix(&x->x_gui.x_obj, x->x_gui.x_glist);
- pd_list(x->x_gui.x_snd->s_thing, &s_list, 2, x->x_at);
+ x->x_at[0].a_w.w_float = text_xpix(&x->x_gui.x_obj, x->x_gui.x_glist);
+ x->x_at[1].a_w.w_float = text_ypix(&x->x_gui.x_obj, x->x_gui.x_glist);
+ pd_list(x->x_gui.x_snd->s_thing, &s_list, 2, x->x_at);
}
}
@@ -190,14 +190,14 @@ static void my_canvas_dialog(t_my_canvas *x, t_symbol *s, int argc, t_atom *argv
x->x_gui.x_isa.x_loadinit = 0;
if(a < 1)
- a = 1;
+ a = 1;
x->x_gui.x_w = a;
x->x_gui.x_h = x->x_gui.x_w;
if(w < 1)
- w = 1;
+ w = 1;
x->x_vis_w = w;
if(h < 1)
- h = 1;
+ h = 1;
x->x_vis_h = h;
(*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_CONFIG);
(*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_MOVE);
@@ -208,7 +208,7 @@ static void my_canvas_size(t_my_canvas *x, t_symbol *s, int ac, t_atom *av)
int i = (int)atom_getintarg(0, ac, av);
if(i < 1)
- i = 1;
+ i = 1;
x->x_gui.x_w = i;
x->x_gui.x_h = i;
iemgui_size((void *)x, &x->x_gui);
@@ -226,17 +226,17 @@ static void my_canvas_vis_size(t_my_canvas *x, t_symbol *s, int ac, t_atom *av)
i = (int)atom_getintarg(0, ac, av);
if(i < 1)
- i = 1;
+ i = 1;
x->x_vis_w = i;
if(ac > 1)
{
i = (int)atom_getintarg(1, ac, av);
if(i < 1)
- i = 1;
+ i = 1;
}
x->x_vis_h = i;
if(glist_isvisible(x->x_gui.x_glist))
- (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_MOVE);
+ (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_MOVE);
}
static void my_canvas_color(t_my_canvas *x, t_symbol *s, int ac, t_atom *av)
@@ -272,19 +272,19 @@ static void *my_canvas_new(t_symbol *s, int argc, t_atom *argv)
if(((argc >= 10)&&(argc <= 13))
&&IS_A_FLOAT(argv,0)&&IS_A_FLOAT(argv,1)&&IS_A_FLOAT(argv,2))
{
- a = (int)atom_getintarg(0, argc, argv);
- w = (int)atom_getintarg(1, argc, argv);
- h = (int)atom_getintarg(2, argc, argv);
+ a = (int)atom_getintarg(0, argc, argv);
+ w = (int)atom_getintarg(1, argc, argv);
+ h = (int)atom_getintarg(2, argc, argv);
}
if((argc >= 12)&&(IS_A_SYMBOL(argv,3)||IS_A_FLOAT(argv,3))&&(IS_A_SYMBOL(argv,4)||IS_A_FLOAT(argv,4)))
{
- i = 2;
- iemgui_new_getnames(&x->x_gui, 3, argv);
+ i = 2;
+ iemgui_new_getnames(&x->x_gui, 3, argv);
}
else if((argc == 11)&&(IS_A_SYMBOL(argv,3)||IS_A_FLOAT(argv,3)))
{
- i = 1;
- iemgui_new_getnames(&x->x_gui, 3, argv);
+ i = 1;
+ iemgui_new_getnames(&x->x_gui, 3, argv);
}
else iemgui_new_getnames(&x->x_gui, 3, 0);
@@ -294,50 +294,50 @@ static void *my_canvas_new(t_symbol *s, int argc, t_atom *argv)
&&IS_A_FLOAT(argv,i+7)&&IS_A_FLOAT(argv,i+8)
&&IS_A_FLOAT(argv,i+9))
{
- /* disastrously, the "label" sits in a different part of the
- message. So we have to track its location separately (in
- the slot x_labelbindex) and initialize it specially here. */
- iemgui_new_dogetname(&x->x_gui, i+3, argv);
- x->x_gui.x_labelbindex = i+4;
- ldx = (int)atom_getintarg(i+4, argc, argv);
- ldy = (int)atom_getintarg(i+5, argc, argv);
- iem_inttofstyle(&x->x_gui.x_fsf, atom_getintarg(i+6, argc, argv));
- fs = (int)atom_getintarg(i+7, argc, argv);
- bflcol[0] = (int)atom_getintarg(i+8, argc, argv);
- bflcol[2] = (int)atom_getintarg(i+9, argc, argv);
+ /* disastrously, the "label" sits in a different part of the
+ message. So we have to track its location separately (in
+ the slot x_labelbindex) and initialize it specially here. */
+ iemgui_new_dogetname(&x->x_gui, i+3, argv);
+ x->x_gui.x_labelbindex = i+4;
+ ldx = (int)atom_getintarg(i+4, argc, argv);
+ ldy = (int)atom_getintarg(i+5, argc, argv);
+ iem_inttofstyle(&x->x_gui.x_fsf, atom_getintarg(i+6, argc, argv));
+ fs = (int)atom_getintarg(i+7, argc, argv);
+ bflcol[0] = (int)atom_getintarg(i+8, argc, argv);
+ bflcol[2] = (int)atom_getintarg(i+9, argc, argv);
}
if((argc == 13)&&IS_A_FLOAT(argv,i+10))
{
- iem_inttosymargs(&x->x_gui.x_isa, atom_getintarg(i+10, argc, argv));
+ iem_inttosymargs(&x->x_gui.x_isa, atom_getintarg(i+10, argc, argv));
}
x->x_gui.x_draw = (t_iemfunptr)my_canvas_draw;
x->x_gui.x_fsf.x_snd_able = 1;
x->x_gui.x_fsf.x_rcv_able = 1;
x->x_gui.x_glist = (t_glist *)canvas_getcurrent();
if (!strcmp(x->x_gui.x_snd->s_name, "empty"))
- x->x_gui.x_fsf.x_snd_able = 0;
+ x->x_gui.x_fsf.x_snd_able = 0;
if (!strcmp(x->x_gui.x_rcv->s_name, "empty"))
- x->x_gui.x_fsf.x_rcv_able = 0;
+ x->x_gui.x_fsf.x_rcv_able = 0;
if(a < 1)
- a = 1;
+ a = 1;
x->x_gui.x_w = a;
x->x_gui.x_h = x->x_gui.x_w;
if(w < 1)
- w = 1;
+ w = 1;
x->x_vis_w = w;
if(h < 1)
- h = 1;
+ h = 1;
x->x_vis_h = h;
if(x->x_gui.x_fsf.x_font_style == 1) strcpy(x->x_gui.x_font, "helvetica");
else if(x->x_gui.x_fsf.x_font_style == 2) strcpy(x->x_gui.x_font, "times");
else { x->x_gui.x_fsf.x_font_style = 0;
- strcpy(x->x_gui.x_font, "courier"); }
+ strcpy(x->x_gui.x_font, "courier"); }
if (x->x_gui.x_fsf.x_rcv_able)
- pd_bind(&x->x_gui.x_obj.ob_pd, x->x_gui.x_rcv);
+ pd_bind(&x->x_gui.x_obj.ob_pd, x->x_gui.x_rcv);
x->x_gui.x_ldx = ldx;
x->x_gui.x_ldy = ldy;
if(fs < 4)
- fs = 4;
+ fs = 4;
x->x_gui.x_fontsize = fs;
iemgui_all_colfromload(&x->x_gui, bflcol);
x->x_at[0].a_type = A_FLOAT;
@@ -349,14 +349,14 @@ static void *my_canvas_new(t_symbol *s, int argc, t_atom *argv)
static void my_canvas_ff(t_my_canvas *x)
{
if(x->x_gui.x_fsf.x_rcv_able)
- pd_unbind(&x->x_gui.x_obj.ob_pd, x->x_gui.x_rcv);
+ pd_unbind(&x->x_gui.x_obj.ob_pd, x->x_gui.x_rcv);
gfxstub_deleteforkey(x);
}
void g_mycanvas_setup(void)
{
my_canvas_class = class_new(gensym("cnv"), (t_newmethod)my_canvas_new,
- (t_method)my_canvas_ff, sizeof(t_my_canvas), CLASS_NOINLET, A_GIMME, 0);
+ (t_method)my_canvas_ff, sizeof(t_my_canvas), CLASS_NOINLET, A_GIMME, 0);
class_addcreator((t_newmethod)my_canvas_new, gensym("my_canvas"), A_GIMME, 0);
class_addmethod(my_canvas_class, (t_method)my_canvas_dialog, gensym("dialog"), A_GIMME, 0);
class_addmethod(my_canvas_class, (t_method)my_canvas_size, gensym("size"), A_GIMME, 0);
diff --git a/pd/src/g_numbox.c b/pd/src/g_numbox.c
index 9fc7091b..9418e3fd 100644
--- a/pd/src/g_numbox.c
+++ b/pd/src/g_numbox.c
@@ -38,9 +38,9 @@ static void my_numbox_tick_reset(t_my_numbox *x)
{
if(x->x_gui.x_fsf.x_change)
{
- x->x_gui.x_fsf.x_change = 0;
- glist_grab(x->x_gui.x_glist, 0, 0, 0, 0, 0);
- (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
+ x->x_gui.x_fsf.x_change = 0;
+ glist_grab(x->x_gui.x_glist, 0, 0, 0, 0, 0);
+ (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
}
}
@@ -52,9 +52,9 @@ static void my_numbox_tick_wait(t_my_numbox *x)
void my_numbox_clip(t_my_numbox *x)
{
if(x->x_val < x->x_min)
- x->x_val = x->x_min;
+ x->x_val = x->x_min;
if(x->x_val > x->x_max)
- x->x_val = x->x_max;
+ x->x_val = x->x_max;
}
void my_numbox_calc_fontwidth(t_my_numbox *x)
@@ -62,9 +62,9 @@ void my_numbox_calc_fontwidth(t_my_numbox *x)
int w, f=31;
if(x->x_gui.x_fsf.x_font_style == 1)
- f = 27;
+ f = 27;
else if(x->x_gui.x_fsf.x_font_style == 2)
- f = 25;
+ f = 25;
w = x->x_gui.x_fontsize * f * x->x_gui.x_w;
w /= 36;
@@ -80,51 +80,51 @@ void my_numbox_ftoa(t_my_numbox *x)
bufsize = strlen(x->x_buf);
if(bufsize >= 5)/* if it is in exponential mode */
{
- i = bufsize - 4;
- if((x->x_buf[i] == 'e') || (x->x_buf[i] == 'E'))
- is_exp = 1;
+ i = bufsize - 4;
+ if((x->x_buf[i] == 'e') || (x->x_buf[i] == 'E'))
+ is_exp = 1;
}
if(bufsize > x->x_gui.x_w)/* if to reduce */
{
- if(is_exp)
- {
- if(x->x_gui.x_w <= 5)
- {
- x->x_buf[0] = (f < 0.0 ? '-' : '+');
- x->x_buf[1] = 0;
- }
- i = bufsize - 4;
- for(idecimal=0; idecimal < i; idecimal++)
- if(x->x_buf[idecimal] == '.')
- break;
- if(idecimal > (x->x_gui.x_w - 4))
- {
- x->x_buf[0] = (f < 0.0 ? '-' : '+');
- x->x_buf[1] = 0;
- }
- else
- {
- int new_exp_index=x->x_gui.x_w-4, old_exp_index=bufsize-4;
-
- for(i=0; i < 4; i++, new_exp_index++, old_exp_index++)
- x->x_buf[new_exp_index] = x->x_buf[old_exp_index];
- x->x_buf[x->x_gui.x_w] = 0;
- }
-
- }
- else
- {
- for(idecimal=0; idecimal < bufsize; idecimal++)
- if(x->x_buf[idecimal] == '.')
- break;
- if(idecimal > x->x_gui.x_w)
- {
- x->x_buf[0] = (f < 0.0 ? '-' : '+');
- x->x_buf[1] = 0;
- }
- else
- x->x_buf[x->x_gui.x_w] = 0;
- }
+ if(is_exp)
+ {
+ if(x->x_gui.x_w <= 5)
+ {
+ x->x_buf[0] = (f < 0.0 ? '-' : '+');
+ x->x_buf[1] = 0;
+ }
+ i = bufsize - 4;
+ for(idecimal=0; idecimal < i; idecimal++)
+ if(x->x_buf[idecimal] == '.')
+ break;
+ if(idecimal > (x->x_gui.x_w - 4))
+ {
+ x->x_buf[0] = (f < 0.0 ? '-' : '+');
+ x->x_buf[1] = 0;
+ }
+ else
+ {
+ int new_exp_index=x->x_gui.x_w-4, old_exp_index=bufsize-4;
+
+ for(i=0; i < 4; i++, new_exp_index++, old_exp_index++)
+ x->x_buf[new_exp_index] = x->x_buf[old_exp_index];
+ x->x_buf[x->x_gui.x_w] = 0;
+ }
+
+ }
+ else
+ {
+ for(idecimal=0; idecimal < bufsize; idecimal++)
+ if(x->x_buf[idecimal] == '.')
+ break;
+ if(idecimal > x->x_gui.x_w)
+ {
+ x->x_buf[0] = (f < 0.0 ? '-' : '+');
+ x->x_buf[1] = 0;
+ }
+ else
+ x->x_buf[x->x_gui.x_w] = 0;
+ }
}
}
@@ -132,42 +132,42 @@ static void my_numbox_draw_update(t_my_numbox *x, t_glist *glist)
{
if (glist_isvisible(glist))
{
- if(x->x_gui.x_fsf.x_change)
- {
- if(x->x_buf[0])
- {
- char *cp=x->x_buf;
- int sl = strlen(x->x_buf);
-
- x->x_buf[sl] = '>';
- x->x_buf[sl+1] = 0;
- if(sl >= x->x_gui.x_w)
- cp += sl - x->x_gui.x_w + 1;
- sys_vgui(
- ".x%x.c itemconfigure %xNUMBER -fill #%6.6x -text {%s} \n",
- glist_getcanvas(glist), x, IEM_GUI_COLOR_EDITED, cp);
- x->x_buf[sl] = 0;
- }
- else
- {
- my_numbox_ftoa(x);
- sys_vgui(
- ".x%x.c itemconfigure %xNUMBER -fill #%6.6x -text {%s} \n",
- glist_getcanvas(glist), x, IEM_GUI_COLOR_EDITED, x->x_buf);
- x->x_buf[0] = 0;
- }
- }
- else
- {
- my_numbox_ftoa(x);
+ if(x->x_gui.x_fsf.x_change)
+ {
+ if(x->x_buf[0])
+ {
+ char *cp=x->x_buf;
+ int sl = strlen(x->x_buf);
+
+ x->x_buf[sl] = '>';
+ x->x_buf[sl+1] = 0;
+ if(sl >= x->x_gui.x_w)
+ cp += sl - x->x_gui.x_w + 1;
+ sys_vgui(
+ ".x%lx.c itemconfigure %lxNUMBER -fill #%6.6x -text {%s} \n",
+ glist_getcanvas(glist), x, IEM_GUI_COLOR_EDITED, cp);
+ x->x_buf[sl] = 0;
+ }
+ else
+ {
+ my_numbox_ftoa(x);
+ sys_vgui(
+ ".x%lx.c itemconfigure %lxNUMBER -fill #%6.6x -text {%s} \n",
+ glist_getcanvas(glist), x, IEM_GUI_COLOR_EDITED, x->x_buf);
+ x->x_buf[0] = 0;
+ }
+ }
+ else
+ {
+ my_numbox_ftoa(x);
sys_vgui(
- ".x%x.c itemconfigure %xNUMBER -fill #%6.6x -text {%s} \n",
- glist_getcanvas(glist), x,
- x->x_gui.x_fsf.x_selected?
- IEM_GUI_COLOR_SELECTED:x->x_gui.x_fcol,
- x->x_buf);
- x->x_buf[0] = 0;
- }
+ ".x%lx.c itemconfigure %lxNUMBER -fill #%6.6x -text {%s} \n",
+ glist_getcanvas(glist), x,
+ x->x_gui.x_fsf.x_selected?
+ IEM_GUI_COLOR_SELECTED:x->x_gui.x_fcol,
+ x->x_buf);
+ x->x_buf[0] = 0;
+ }
}
}
@@ -179,42 +179,42 @@ static void my_numbox_draw_new(t_my_numbox *x, t_glist *glist)
t_canvas *canvas=glist_getcanvas(glist);
sys_vgui(
-".x%x.c create polygon %d %d %d %d %d %d %d %d %d %d -outline #%6.6x \
--fill #%6.6x -tags %xBASE1\n",
- canvas, xpos, ypos,
- xpos + x->x_numwidth-4, ypos,
- xpos + x->x_numwidth, ypos+4,
- xpos + x->x_numwidth, ypos + x->x_gui.x_h,
- xpos, ypos + x->x_gui.x_h,
- IEM_GUI_COLOR_NORMAL, x->x_gui.x_bcol, x);
+".x%lx.c create polygon %d %d %d %d %d %d %d %d %d %d -outline #%6.6x \
+-fill #%6.6x -tags %lxBASE1\n",
+ canvas, xpos, ypos,
+ xpos + x->x_numwidth-4, ypos,
+ xpos + x->x_numwidth, ypos+4,
+ xpos + x->x_numwidth, ypos + x->x_gui.x_h,
+ xpos, ypos + x->x_gui.x_h,
+ IEM_GUI_COLOR_NORMAL, x->x_gui.x_bcol, x);
sys_vgui(
- ".x%x.c create line %d %d %d %d %d %d -fill #%6.6x -tags %xBASE2\n",
- canvas, xpos, ypos,
- xpos + half, ypos + half,
- xpos, ypos + x->x_gui.x_h,
- x->x_gui.x_fcol, x);
- sys_vgui(".x%x.c create text %d %d -text {%s} -anchor w \
- -font {%s %d bold} -fill #%6.6x -tags %xLABEL\n",
- canvas, xpos+x->x_gui.x_ldx, ypos+x->x_gui.x_ldy,
- strcmp(x->x_gui.x_lab->s_name, "empty")?x->x_gui.x_lab->s_name:"",
- x->x_gui.x_font, x->x_gui.x_fontsize, x->x_gui.x_lcol, x);
+ ".x%lx.c create line %d %d %d %d %d %d -fill #%6.6x -tags %lxBASE2\n",
+ canvas, xpos, ypos,
+ xpos + half, ypos + half,
+ xpos, ypos + x->x_gui.x_h,
+ x->x_gui.x_fcol, x);
+ sys_vgui(".x%lx.c create text %d %d -text {%s} -anchor w \
+ -font {%s %d bold} -fill #%6.6x -tags %lxLABEL\n",
+ canvas, xpos+x->x_gui.x_ldx, ypos+x->x_gui.x_ldy,
+ strcmp(x->x_gui.x_lab->s_name, "empty")?x->x_gui.x_lab->s_name:"",
+ x->x_gui.x_font, x->x_gui.x_fontsize, x->x_gui.x_lcol, x);
my_numbox_ftoa(x);
- sys_vgui(".x%x.c create text %d %d -text {%s} -anchor w \
- -font {%s %d bold} -fill #%6.6x -tags %xNUMBER\n",
- canvas, xpos+half+2, ypos+half+d,
- x->x_buf, x->x_gui.x_font, x->x_gui.x_fontsize, x->x_gui.x_fcol, x);
+ sys_vgui(".x%lx.c create text %d %d -text {%s} -anchor w \
+ -font {%s %d bold} -fill #%6.6x -tags %lxNUMBER\n",
+ canvas, xpos+half+2, ypos+half+d,
+ x->x_buf, x->x_gui.x_font, x->x_gui.x_fontsize, x->x_gui.x_fcol, x);
if(!x->x_gui.x_fsf.x_snd_able)
- sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xOUT%d\n",
- canvas,
- xpos, ypos + x->x_gui.x_h-1,
- xpos+IOWIDTH, ypos + x->x_gui.x_h,
- x, 0);
+ sys_vgui(".x%lx.c create rectangle %d %d %d %d -tags %lxOUT%d\n",
+ canvas,
+ xpos, ypos + x->x_gui.x_h-1,
+ xpos+IOWIDTH, ypos + x->x_gui.x_h,
+ x, 0);
if(!x->x_gui.x_fsf.x_rcv_able)
- sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xIN%d\n",
- canvas,
- xpos, ypos,
- xpos+IOWIDTH, ypos+1,
- x, 0);
+ sys_vgui(".x%lx.c create rectangle %d %d %d %d -tags %lxIN%d\n",
+ canvas,
+ xpos, ypos,
+ xpos+IOWIDTH, ypos+1,
+ x, 0);
}
static void my_numbox_draw_move(t_my_numbox *x, t_glist *glist)
@@ -224,61 +224,61 @@ static void my_numbox_draw_move(t_my_numbox *x, t_glist *glist)
int ypos=text_ypix(&x->x_gui.x_obj, glist);
t_canvas *canvas=glist_getcanvas(glist);
- sys_vgui(".x%x.c coords %xBASE1 %d %d %d %d %d %d %d %d %d %d\n",
- canvas, x, xpos, ypos,
- xpos + x->x_numwidth-4, ypos,
- xpos + x->x_numwidth, ypos+4,
- xpos + x->x_numwidth, ypos + x->x_gui.x_h,
- xpos, ypos + x->x_gui.x_h);
- sys_vgui(".x%x.c coords %xBASE2 %d %d %d %d %d %d\n",
- canvas, x, xpos, ypos,
- xpos + half, ypos + half,
- xpos, ypos + x->x_gui.x_h);
- sys_vgui(".x%x.c coords %xLABEL %d %d\n",
- canvas, x, xpos+x->x_gui.x_ldx, ypos+x->x_gui.x_ldy);
- sys_vgui(".x%x.c coords %xNUMBER %d %d\n",
- canvas, x, xpos+half+2, ypos+half+d);
+ sys_vgui(".x%lx.c coords %lxBASE1 %d %d %d %d %d %d %d %d %d %d\n",
+ canvas, x, xpos, ypos,
+ xpos + x->x_numwidth-4, ypos,
+ xpos + x->x_numwidth, ypos+4,
+ xpos + x->x_numwidth, ypos + x->x_gui.x_h,
+ xpos, ypos + x->x_gui.x_h);
+ sys_vgui(".x%lx.c coords %lxBASE2 %d %d %d %d %d %d\n",
+ canvas, x, xpos, ypos,
+ xpos + half, ypos + half,
+ xpos, ypos + x->x_gui.x_h);
+ sys_vgui(".x%lx.c coords %lxLABEL %d %d\n",
+ canvas, x, xpos+x->x_gui.x_ldx, ypos+x->x_gui.x_ldy);
+ sys_vgui(".x%lx.c coords %lxNUMBER %d %d\n",
+ canvas, x, xpos+half+2, ypos+half+d);
if(!x->x_gui.x_fsf.x_snd_able)
- sys_vgui(".x%x.c coords %xOUT%d %d %d %d %d\n",
- canvas, x, 0,
- xpos, ypos + x->x_gui.x_h-1,
- xpos+IOWIDTH, ypos + x->x_gui.x_h);
+ sys_vgui(".x%lx.c coords %lxOUT%d %d %d %d %d\n",
+ canvas, x, 0,
+ xpos, ypos + x->x_gui.x_h-1,
+ xpos+IOWIDTH, ypos + x->x_gui.x_h);
if(!x->x_gui.x_fsf.x_rcv_able)
- sys_vgui(".x%x.c coords %xIN%d %d %d %d %d\n",
- canvas, x, 0,
- xpos, ypos,
- xpos+IOWIDTH, ypos+1);
+ sys_vgui(".x%lx.c coords %lxIN%d %d %d %d %d\n",
+ canvas, x, 0,
+ xpos, ypos,
+ xpos+IOWIDTH, ypos+1);
}
static void my_numbox_draw_erase(t_my_numbox* x,t_glist* glist)
{
t_canvas *canvas=glist_getcanvas(glist);
- sys_vgui(".x%x.c delete %xBASE1\n", canvas, x);
- sys_vgui(".x%x.c delete %xBASE2\n", canvas, x);
- sys_vgui(".x%x.c delete %xLABEL\n", canvas, x);
- sys_vgui(".x%x.c delete %xNUMBER\n", canvas, x);
+ sys_vgui(".x%lx.c delete %lxBASE1\n", canvas, x);
+ sys_vgui(".x%lx.c delete %lxBASE2\n", canvas, x);
+ sys_vgui(".x%lx.c delete %lxLABEL\n", canvas, x);
+ sys_vgui(".x%lx.c delete %lxNUMBER\n", canvas, x);
if(!x->x_gui.x_fsf.x_snd_able)
- sys_vgui(".x%x.c delete %xOUT%d\n", canvas, x, 0);
+ sys_vgui(".x%lx.c delete %lxOUT%d\n", canvas, x, 0);
if(!x->x_gui.x_fsf.x_rcv_able)
- sys_vgui(".x%x.c delete %xIN%d\n", canvas, x, 0);
+ sys_vgui(".x%lx.c delete %lxIN%d\n", canvas, x, 0);
}
static void my_numbox_draw_config(t_my_numbox* x,t_glist* glist)
{
t_canvas *canvas=glist_getcanvas(glist);
- sys_vgui(".x%x.c itemconfigure %xLABEL -font {%s %d bold} -fill #%6.6x -text {%s} \n",
- canvas, x, x->x_gui.x_font, x->x_gui.x_fontsize,
- x->x_gui.x_fsf.x_selected?IEM_GUI_COLOR_SELECTED:x->x_gui.x_lcol,
- strcmp(x->x_gui.x_lab->s_name, "empty")?x->x_gui.x_lab->s_name:"");
- sys_vgui(".x%x.c itemconfigure %xNUMBER -font {%s %d bold} -fill #%6.6x \n",
- canvas, x, x->x_gui.x_font, x->x_gui.x_fontsize,
- x->x_gui.x_fsf.x_selected?IEM_GUI_COLOR_SELECTED:x->x_gui.x_fcol);
- sys_vgui(".x%x.c itemconfigure %xBASE1 -fill #%6.6x\n", canvas,
- x, x->x_gui.x_bcol);
- sys_vgui(".x%x.c itemconfigure %xBASE2 -fill #%6.6x\n", canvas,
- x, x->x_gui.x_fsf.x_selected?IEM_GUI_COLOR_SELECTED:x->x_gui.x_fcol);
+ sys_vgui(".x%lx.c itemconfigure %lxLABEL -font {%s %d bold} -fill #%6.6x -text {%s} \n",
+ canvas, x, x->x_gui.x_font, x->x_gui.x_fontsize,
+ x->x_gui.x_fsf.x_selected?IEM_GUI_COLOR_SELECTED:x->x_gui.x_lcol,
+ strcmp(x->x_gui.x_lab->s_name, "empty")?x->x_gui.x_lab->s_name:"");
+ sys_vgui(".x%lx.c itemconfigure %lxNUMBER -font {%s %d bold} -fill #%6.6x \n",
+ canvas, x, x->x_gui.x_font, x->x_gui.x_fontsize,
+ x->x_gui.x_fsf.x_selected?IEM_GUI_COLOR_SELECTED:x->x_gui.x_fcol);
+ sys_vgui(".x%lx.c itemconfigure %lxBASE1 -fill #%6.6x\n", canvas,
+ x, x->x_gui.x_bcol);
+ sys_vgui(".x%lx.c itemconfigure %lxBASE2 -fill #%6.6x\n", canvas,
+ x, x->x_gui.x_fsf.x_selected?IEM_GUI_COLOR_SELECTED:x->x_gui.x_fcol);
}
static void my_numbox_draw_io(t_my_numbox* x,t_glist* glist, int old_snd_rcv_flags)
@@ -288,21 +288,21 @@ static void my_numbox_draw_io(t_my_numbox* x,t_glist* glist, int old_snd_rcv_fla
t_canvas *canvas=glist_getcanvas(glist);
if((old_snd_rcv_flags & IEM_GUI_OLD_SND_FLAG) && !x->x_gui.x_fsf.x_snd_able)
- sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xOUT%d\n",
- canvas,
- xpos, ypos + x->x_gui.x_h-1,
- xpos+IOWIDTH, ypos + x->x_gui.x_h,
- x, 0);
+ sys_vgui(".x%lx.c create rectangle %d %d %d %d -tags %lxOUT%d\n",
+ canvas,
+ xpos, ypos + x->x_gui.x_h-1,
+ xpos+IOWIDTH, ypos + x->x_gui.x_h,
+ x, 0);
if(!(old_snd_rcv_flags & IEM_GUI_OLD_SND_FLAG) && x->x_gui.x_fsf.x_snd_able)
- sys_vgui(".x%x.c delete %xOUT%d\n", canvas, x, 0);
+ sys_vgui(".x%lx.c delete %lxOUT%d\n", canvas, x, 0);
if((old_snd_rcv_flags & IEM_GUI_OLD_RCV_FLAG) && !x->x_gui.x_fsf.x_rcv_able)
- sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xIN%d\n",
- canvas,
- xpos, ypos,
- xpos+IOWIDTH, ypos+1,
- x, 0);
+ sys_vgui(".x%lx.c create rectangle %d %d %d %d -tags %lxIN%d\n",
+ canvas,
+ xpos, ypos,
+ xpos+IOWIDTH, ypos+1,
+ x, 0);
if(!(old_snd_rcv_flags & IEM_GUI_OLD_RCV_FLAG) && x->x_gui.x_fsf.x_rcv_able)
- sys_vgui(".x%x.c delete %xIN%d\n", canvas, x, 0);
+ sys_vgui(".x%lx.c delete %lxIN%d\n", canvas, x, 0);
}
static void my_numbox_draw_select(t_my_numbox *x, t_glist *glist)
@@ -311,58 +311,58 @@ static void my_numbox_draw_select(t_my_numbox *x, t_glist *glist)
if(x->x_gui.x_fsf.x_selected)
{
- if(x->x_gui.x_fsf.x_change)
- {
- x->x_gui.x_fsf.x_change = 0;
+ if(x->x_gui.x_fsf.x_change)
+ {
+ x->x_gui.x_fsf.x_change = 0;
clock_unset(x->x_clock_reset);
- x->x_buf[0] = 0;
- (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
- }
- sys_vgui(".x%x.c itemconfigure %xBASE1 -outline #%6.6x\n",
- canvas, x, IEM_GUI_COLOR_SELECTED);
- sys_vgui(".x%x.c itemconfigure %xBASE2 -fill #%6.6x\n",
- canvas, x, IEM_GUI_COLOR_SELECTED);
- sys_vgui(".x%x.c itemconfigure %xLABEL -fill #%6.6x\n",
- canvas, x, IEM_GUI_COLOR_SELECTED);
- sys_vgui(".x%x.c itemconfigure %xNUMBER -fill #%6.6x\n",
- canvas, x, IEM_GUI_COLOR_SELECTED);
+ x->x_buf[0] = 0;
+ (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
+ }
+ sys_vgui(".x%lx.c itemconfigure %lxBASE1 -outline #%6.6x\n",
+ canvas, x, IEM_GUI_COLOR_SELECTED);
+ sys_vgui(".x%lx.c itemconfigure %lxBASE2 -fill #%6.6x\n",
+ canvas, x, IEM_GUI_COLOR_SELECTED);
+ sys_vgui(".x%lx.c itemconfigure %lxLABEL -fill #%6.6x\n",
+ canvas, x, IEM_GUI_COLOR_SELECTED);
+ sys_vgui(".x%lx.c itemconfigure %lxNUMBER -fill #%6.6x\n",
+ canvas, x, IEM_GUI_COLOR_SELECTED);
}
else
{
- sys_vgui(".x%x.c itemconfigure %xBASE1 -outline #%6.6x\n",
- canvas, x, IEM_GUI_COLOR_NORMAL);
- sys_vgui(".x%x.c itemconfigure %xBASE2 -fill #%6.6x\n",
- canvas, x, x->x_gui.x_fcol);
- sys_vgui(".x%x.c itemconfigure %xLABEL -fill #%6.6x\n",
- canvas, x, x->x_gui.x_lcol);
- sys_vgui(".x%x.c itemconfigure %xNUMBER -fill #%6.6x\n",
- canvas, x, x->x_gui.x_fcol);
+ sys_vgui(".x%lx.c itemconfigure %lxBASE1 -outline #%6.6x\n",
+ canvas, x, IEM_GUI_COLOR_NORMAL);
+ sys_vgui(".x%lx.c itemconfigure %lxBASE2 -fill #%6.6x\n",
+ canvas, x, x->x_gui.x_fcol);
+ sys_vgui(".x%lx.c itemconfigure %lxLABEL -fill #%6.6x\n",
+ canvas, x, x->x_gui.x_lcol);
+ sys_vgui(".x%lx.c itemconfigure %lxNUMBER -fill #%6.6x\n",
+ canvas, x, x->x_gui.x_fcol);
}
}
void my_numbox_draw(t_my_numbox *x, t_glist *glist, int mode)
{
if(mode == IEM_GUI_DRAW_MODE_UPDATE)
- my_numbox_draw_update(x, glist);
+ my_numbox_draw_update(x, glist);
else if(mode == IEM_GUI_DRAW_MODE_MOVE)
- my_numbox_draw_move(x, glist);
+ my_numbox_draw_move(x, glist);
else if(mode == IEM_GUI_DRAW_MODE_NEW)
- my_numbox_draw_new(x, glist);
+ my_numbox_draw_new(x, glist);
else if(mode == IEM_GUI_DRAW_MODE_SELECT)
- my_numbox_draw_select(x, glist);
+ my_numbox_draw_select(x, glist);
else if(mode == IEM_GUI_DRAW_MODE_ERASE)
- my_numbox_draw_erase(x, glist);
+ my_numbox_draw_erase(x, glist);
else if(mode == IEM_GUI_DRAW_MODE_CONFIG)
- my_numbox_draw_config(x, glist);
+ my_numbox_draw_config(x, glist);
else if(mode >= IEM_GUI_DRAW_MODE_IO)
- my_numbox_draw_io(x, glist, mode - IEM_GUI_DRAW_MODE_IO);
+ my_numbox_draw_io(x, glist, mode - IEM_GUI_DRAW_MODE_IO);
}
/* ------------------------ nbx widgetbehaviour----------------------------- */
static void my_numbox_getrect(t_gobj *z, t_glist *glist,
- int *xp1, int *yp1, int *xp2, int *yp2)
+ int *xp1, int *yp1, int *xp2, int *yp2)
{
t_my_numbox* x = (t_my_numbox*)z;
@@ -381,22 +381,22 @@ static void my_numbox_save(t_gobj *z, t_binbuf *b)
iemgui_save(&x->x_gui, srl, bflcol);
if(x->x_gui.x_fsf.x_change)
{
- x->x_gui.x_fsf.x_change = 0;
+ x->x_gui.x_fsf.x_change = 0;
clock_unset(x->x_clock_reset);
- glist_grab(x->x_gui.x_glist, 0, 0, 0, 0, 0);
- (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
+ glist_grab(x->x_gui.x_glist, 0, 0, 0, 0, 0);
+ (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
}
binbuf_addv(b, "ssiisiiffiisssiiiiiiifi", gensym("#X"),gensym("obj"),
- (t_int)x->x_gui.x_obj.te_xpix, (t_int)x->x_gui.x_obj.te_ypix,
- gensym("nbx"), x->x_gui.x_w, x->x_gui.x_h,
- (float)x->x_min, (float)x->x_max,
- x->x_lin0_log1, iem_symargstoint(&x->x_gui.x_isa),
- srl[0], srl[1], srl[2],
- x->x_gui.x_ldx, x->x_gui.x_ldy,
- iem_fstyletoint(&x->x_gui.x_fsf), x->x_gui.x_fontsize,
- bflcol[0], bflcol[1], bflcol[2],
- x->x_val, x->x_log_height);
+ (int)x->x_gui.x_obj.te_xpix, (int)x->x_gui.x_obj.te_ypix,
+ gensym("nbx"), x->x_gui.x_w, x->x_gui.x_h,
+ (float)x->x_min, (float)x->x_max,
+ x->x_lin0_log1, iem_symargstoint(&x->x_gui.x_isa),
+ srl[0], srl[1], srl[2],
+ x->x_gui.x_ldx, x->x_gui.x_ldy,
+ iem_fstyletoint(&x->x_gui.x_fsf), x->x_gui.x_fontsize,
+ bflcol[0], bflcol[1], bflcol[2],
+ x->x_val, x->x_log_height);
binbuf_addv(b, ";");
}
@@ -406,35 +406,35 @@ int my_numbox_check_minmax(t_my_numbox *x, double min, double max)
if(x->x_lin0_log1)
{
- if((min == 0.0)&&(max == 0.0))
- max = 1.0;
- if(max > 0.0)
- {
- if(min <= 0.0)
- min = 0.01*max;
- }
- else
- {
- if(min > 0.0)
- max = 0.01*min;
- }
+ if((min == 0.0)&&(max == 0.0))
+ max = 1.0;
+ if(max > 0.0)
+ {
+ if(min <= 0.0)
+ min = 0.01*max;
+ }
+ else
+ {
+ if(min > 0.0)
+ max = 0.01*min;
+ }
}
x->x_min = min;
x->x_max = max;
if(x->x_val < x->x_min)
{
- x->x_val = x->x_min;
- ret = 1;
+ x->x_val = x->x_min;
+ ret = 1;
}
if(x->x_val > x->x_max)
{
- x->x_val = x->x_max;
+ x->x_val = x->x_max;
ret = 1;
}
if(x->x_lin0_log1)
- x->x_k = exp(log(x->x_max/x->x_min)/(double)(x->x_log_height));
+ x->x_k = exp(log(x->x_max/x->x_min)/(double)(x->x_log_height));
else
- x->x_k = 1.0;
+ x->x_k = 1.0;
return(ret);
}
@@ -447,29 +447,29 @@ static void my_numbox_properties(t_gobj *z, t_glist *owner)
iemgui_properties(&x->x_gui, srl);
if(x->x_gui.x_fsf.x_change)
{
- x->x_gui.x_fsf.x_change = 0;
+ x->x_gui.x_fsf.x_change = 0;
clock_unset(x->x_clock_reset);
- glist_grab(x->x_gui.x_glist, 0, 0, 0, 0, 0);
- (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
+ glist_grab(x->x_gui.x_glist, 0, 0, 0, 0, 0);
+ (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
}
sprintf(buf, "pdtk_iemgui_dialog %%s NUMBERBOX \
- -------dimensions(digits)(pix):------- %d %d width: %d %d height: \
- -----------output-range:----------- %g min: %g max: %d \
- %d lin log %d %d log-height: %d \
- %s %s \
- %s %d %d \
- %d %d \
- %d %d %d\n",
- x->x_gui.x_w, 1, x->x_gui.x_h, 8,
- x->x_min, x->x_max, 0,/*no_schedule*/
- x->x_lin0_log1, x->x_gui.x_isa.x_loadinit, -1,
- x->x_log_height, /*no multi, but iem-characteristic*/
- srl[0]->s_name, srl[1]->s_name,
- srl[2]->s_name, x->x_gui.x_ldx, x->x_gui.x_ldy,
- x->x_gui.x_fsf.x_font_style, x->x_gui.x_fontsize,
- 0xffffff & x->x_gui.x_bcol, 0xffffff & x->x_gui.x_fcol,
- 0xffffff & x->x_gui.x_lcol);
+ -------dimensions(digits)(pix):------- %d %d width: %d %d height: \
+ -----------output-range:----------- %g min: %g max: %d \
+ %d lin log %d %d log-height: %d \
+ %s %s \
+ %s %d %d \
+ %d %d \
+ %d %d %d\n",
+ x->x_gui.x_w, 1, x->x_gui.x_h, 8,
+ x->x_min, x->x_max, 0,/*no_schedule*/
+ x->x_lin0_log1, x->x_gui.x_isa.x_loadinit, -1,
+ x->x_log_height, /*no multi, but iem-characteristic*/
+ srl[0]->s_name, srl[1]->s_name,
+ srl[2]->s_name, x->x_gui.x_ldx, x->x_gui.x_ldy,
+ x->x_gui.x_fsf.x_font_style, x->x_gui.x_fontsize,
+ 0xffffff & x->x_gui.x_bcol, 0xffffff & x->x_gui.x_fcol,
+ 0xffffff & x->x_gui.x_lcol);
gfxstub_new(&x->x_gui.x_obj.ob_pd, x, buf);
}
@@ -477,7 +477,7 @@ static void my_numbox_bang(t_my_numbox *x)
{
outlet_float(x->x_gui.x_obj.ob_outlet, x->x_val);
if(x->x_gui.x_fsf.x_snd_able && x->x_gui.x_snd->s_thing)
- pd_float(x->x_gui.x_snd->s_thing, x->x_val);
+ pd_float(x->x_gui.x_snd->s_thing, x->x_val);
}
static void my_numbox_dialog(t_my_numbox *x, t_symbol *s, int argc,
@@ -496,10 +496,10 @@ static void my_numbox_dialog(t_my_numbox *x, t_symbol *s, int argc,
x->x_lin0_log1 = lilo;
sr_flags = iemgui_dialog(&x->x_gui, srl, argc, argv);
if(w < 1)
- w = 1;
+ w = 1;
x->x_gui.x_w = w;
if(h < 8)
- h = 8;
+ h = 8;
x->x_gui.x_h = h;
if(log_height < 10)
log_height = 10;
@@ -520,11 +520,11 @@ static void my_numbox_motion(t_my_numbox *x, t_floatarg dx, t_floatarg dy)
double k2=1.0;
if(x->x_gui.x_fsf.x_finemoved)
- k2 = 0.01;
+ k2 = 0.01;
if(x->x_lin0_log1)
- x->x_val *= pow(x->x_k, -k2*dy);
+ x->x_val *= pow(x->x_k, -k2*dy);
else
- x->x_val -= k2*dy;
+ x->x_val -= k2*dy;
my_numbox_clip(x);
(*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
my_numbox_bang(x);
@@ -532,10 +532,10 @@ static void my_numbox_motion(t_my_numbox *x, t_floatarg dx, t_floatarg dy)
}
static void my_numbox_click(t_my_numbox *x, t_floatarg xpos, t_floatarg ypos,
- t_floatarg shift, t_floatarg ctrl, t_floatarg alt)
+ t_floatarg shift, t_floatarg ctrl, t_floatarg alt)
{
glist_grab(x->x_gui.x_glist, &x->x_gui.x_obj.te_g,
- (t_glistmotionfn)my_numbox_motion, my_numbox_key, xpos, ypos);
+ (t_glistmotionfn)my_numbox_motion, my_numbox_key, xpos, ypos);
}
static int my_numbox_newclick(t_gobj *z, struct _glist *glist,
@@ -545,30 +545,30 @@ static int my_numbox_newclick(t_gobj *z, struct _glist *glist,
if(doit)
{
- my_numbox_click( x, (t_floatarg)xpix, (t_floatarg)ypix,
- (t_floatarg)shift, 0, (t_floatarg)alt);
- if(shift)
- x->x_gui.x_fsf.x_finemoved = 1;
- else
- x->x_gui.x_fsf.x_finemoved = 0;
- if(!x->x_gui.x_fsf.x_change)
- {
+ my_numbox_click( x, (t_floatarg)xpix, (t_floatarg)ypix,
+ (t_floatarg)shift, 0, (t_floatarg)alt);
+ if(shift)
+ x->x_gui.x_fsf.x_finemoved = 1;
+ else
+ x->x_gui.x_fsf.x_finemoved = 0;
+ if(!x->x_gui.x_fsf.x_change)
+ {
clock_delay(x->x_clock_wait, 50);
- x->x_gui.x_fsf.x_change = 1;
- clock_delay(x->x_clock_reset, 3000);
+ x->x_gui.x_fsf.x_change = 1;
+ clock_delay(x->x_clock_reset, 3000);
/* glist_grab(x->x_gui.x_glist, &x->x_gui.x_obj.ob_g,
- 0, my_numbox_key, 0, 0); */
+ 0, my_numbox_key, 0, 0); */
- x->x_buf[0] = 0;
- }
+ x->x_buf[0] = 0;
+ }
else
- {
- x->x_gui.x_fsf.x_change = 0;
+ {
+ x->x_gui.x_fsf.x_change = 0;
clock_unset(x->x_clock_reset);
- glist_grab(x->x_gui.x_glist, 0, 0, 0, 0, 0);
+ glist_grab(x->x_gui.x_glist, 0, 0, 0, 0, 0);
x->x_buf[0] = 0;
(*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
- }
+ }
}
return (1);
}
@@ -583,12 +583,12 @@ static void my_numbox_set(t_my_numbox *x, t_floatarg f)
static void my_numbox_log_height(t_my_numbox *x, t_floatarg lh)
{
if(lh < 10.0)
- lh = 10.0;
+ lh = 10.0;
x->x_log_height = (int)lh;
if(x->x_lin0_log1)
- x->x_k = exp(log(x->x_max/x->x_min)/(double)(x->x_log_height));
+ x->x_k = exp(log(x->x_max/x->x_min)/(double)(x->x_log_height));
else
- x->x_k = 1.0;
+ x->x_k = 1.0;
}
@@ -596,7 +596,7 @@ static void my_numbox_float(t_my_numbox *x, t_floatarg f)
{
my_numbox_set(x, f);
if(x->x_gui.x_fsf.x_put_in2out)
- my_numbox_bang(x);
+ my_numbox_bang(x);
}
static void my_numbox_size(t_my_numbox *x, t_symbol *s, int ac, t_atom *av)
@@ -605,14 +605,14 @@ static void my_numbox_size(t_my_numbox *x, t_symbol *s, int ac, t_atom *av)
w = (int)atom_getintarg(0, ac, av);
if(w < 1)
- w = 1;
+ w = 1;
x->x_gui.x_w = w;
if(ac > 1)
{
- h = (int)atom_getintarg(1, ac, av);
- if(h < 8)
- h = 8;
- x->x_gui.x_h = h;
+ h = (int)atom_getintarg(1, ac, av);
+ if(h < 8)
+ h = 8;
+ x->x_gui.x_h = h;
}
my_numbox_calc_fontwidth(x);
iemgui_size((void *)x, &x->x_gui);
@@ -627,10 +627,10 @@ static void my_numbox_pos(t_my_numbox *x, t_symbol *s, int ac, t_atom *av)
static void my_numbox_range(t_my_numbox *x, t_symbol *s, int ac, t_atom *av)
{
if(my_numbox_check_minmax(x, (double)atom_getfloatarg(0, ac, av),
- (double)atom_getfloatarg(1, ac, av)))
+ (double)atom_getfloatarg(1, ac, av)))
{
- (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
- /*my_numbox_bang(x);*/
+ (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
+ /*my_numbox_bang(x);*/
}
}
@@ -655,11 +655,11 @@ static void my_numbox_label_font(t_my_numbox *x,
int f = (int)atom_getintarg(1, ac, av);
if(f < 4)
- f = 4;
+ f = 4;
x->x_gui.x_fontsize = f;
f = (int)atom_getintarg(0, ac, av);
if((f < 0) || (f > 2))
- f = 0;
+ f = 0;
x->x_gui.x_fsf.x_font_style = f;
my_numbox_calc_fontwidth(x);
iemgui_label_font((void *)x, &x->x_gui, s, ac, av);
@@ -670,8 +670,8 @@ static void my_numbox_log(t_my_numbox *x)
x->x_lin0_log1 = 1;
if(my_numbox_check_minmax(x, x->x_min, x->x_max))
{
- (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
- /*my_numbox_bang(x);*/
+ (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
+ /*my_numbox_bang(x);*/
}
}
@@ -689,8 +689,8 @@ static void my_numbox_loadbang(t_my_numbox *x)
{
if(!sys_noloadbang && x->x_gui.x_isa.x_loadinit)
{
- (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
- my_numbox_bang(x);
+ (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
+ my_numbox_bang(x);
}
}
@@ -703,39 +703,39 @@ static void my_numbox_key(void *z, t_floatarg fkey)
if (c == 0)
{
- x->x_gui.x_fsf.x_change = 0;
- clock_unset(x->x_clock_reset);
- (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
- return;
+ x->x_gui.x_fsf.x_change = 0;
+ clock_unset(x->x_clock_reset);
+ (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
+ return;
}
if(((c>='0')&&(c<='9'))||(c=='.')||(c=='-')||
- (c=='e')||(c=='+')||(c=='E'))
+ (c=='e')||(c=='+')||(c=='E'))
{
- if(strlen(x->x_buf) < (IEMGUI_MAX_NUM_LEN-2))
- {
- buf[0] = c;
- strcat(x->x_buf, buf);
- (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
- }
+ if(strlen(x->x_buf) < (IEMGUI_MAX_NUM_LEN-2))
+ {
+ buf[0] = c;
+ strcat(x->x_buf, buf);
+ (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
+ }
}
else if((c=='\b')||(c==127))
{
- int sl=strlen(x->x_buf)-1;
+ int sl=strlen(x->x_buf)-1;
- if(sl < 0)
- sl = 0;
- x->x_buf[sl] = 0;
- (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
+ if(sl < 0)
+ sl = 0;
+ x->x_buf[sl] = 0;
+ (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
}
else if((c=='\n')||(c==13))
{
- x->x_val = atof(x->x_buf);
- x->x_buf[0] = 0;
- x->x_gui.x_fsf.x_change = 0;
- clock_unset(x->x_clock_reset);
+ x->x_val = atof(x->x_buf);
+ x->x_buf[0] = 0;
+ x->x_gui.x_fsf.x_change = 0;
+ clock_unset(x->x_clock_reset);
my_numbox_clip(x);
- my_numbox_bang(x);
- (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
+ my_numbox_bang(x);
+ (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
}
clock_delay(x->x_clock_reset, 3000);
}
@@ -744,8 +744,8 @@ static void my_numbox_list(t_my_numbox *x, t_symbol *s, int ac, t_atom *av)
{
if (IS_A_FLOAT(av,0))
{
- my_numbox_set(x, atom_getfloatarg(0, ac, av));
- my_numbox_bang(x);
+ my_numbox_set(x, atom_getfloatarg(0, ac, av));
+ my_numbox_bang(x);
}
}
@@ -770,21 +770,21 @@ static void *my_numbox_new(t_symbol *s, int argc, t_atom *argv)
&&IS_A_FLOAT(argv,11)&&IS_A_FLOAT(argv,12)&&IS_A_FLOAT(argv,13)
&&IS_A_FLOAT(argv,14)&&IS_A_FLOAT(argv,15)&&IS_A_FLOAT(argv,16))
{
- w = (int)atom_getintarg(0, argc, argv);
- h = (int)atom_getintarg(1, argc, argv);
- min = (double)atom_getfloatarg(2, argc, argv);
- max = (double)atom_getfloatarg(3, argc, argv);
- lilo = (int)atom_getintarg(4, argc, argv);
- iem_inttosymargs(&x->x_gui.x_isa, atom_getintarg(5, argc, argv));
- iemgui_new_getnames(&x->x_gui, 6, argv);
- ldx = (int)atom_getintarg(9, argc, argv);
- ldy = (int)atom_getintarg(10, argc, argv);
- iem_inttofstyle(&x->x_gui.x_fsf, atom_getintarg(11, argc, argv));
- fs = (int)atom_getintarg(12, argc, argv);
- bflcol[0] = (int)atom_getintarg(13, argc, argv);
- bflcol[1] = (int)atom_getintarg(14, argc, argv);
- bflcol[2] = (int)atom_getintarg(15, argc, argv);
- v = atom_getfloatarg(16, argc, argv);
+ w = (int)atom_getintarg(0, argc, argv);
+ h = (int)atom_getintarg(1, argc, argv);
+ min = (double)atom_getfloatarg(2, argc, argv);
+ max = (double)atom_getfloatarg(3, argc, argv);
+ lilo = (int)atom_getintarg(4, argc, argv);
+ iem_inttosymargs(&x->x_gui.x_isa, atom_getintarg(5, argc, argv));
+ iemgui_new_getnames(&x->x_gui, 6, argv);
+ ldx = (int)atom_getintarg(9, argc, argv);
+ ldy = (int)atom_getintarg(10, argc, argv);
+ iem_inttofstyle(&x->x_gui.x_fsf, atom_getintarg(11, argc, argv));
+ fs = (int)atom_getintarg(12, argc, argv);
+ bflcol[0] = (int)atom_getintarg(13, argc, argv);
+ bflcol[1] = (int)atom_getintarg(14, argc, argv);
+ bflcol[2] = (int)atom_getintarg(15, argc, argv);
+ v = atom_getfloatarg(16, argc, argv);
}
else iemgui_new_getnames(&x->x_gui, 6, 0);
if((argc == 18)&&IS_A_FLOAT(argv,17))
@@ -796,34 +796,34 @@ static void *my_numbox_new(t_symbol *s, int argc, t_atom *argv)
x->x_gui.x_fsf.x_rcv_able = 1;
x->x_gui.x_glist = (t_glist *)canvas_getcurrent();
if(x->x_gui.x_isa.x_loadinit)
- x->x_val = v;
+ x->x_val = v;
else
- x->x_val = 0.0;
+ x->x_val = 0.0;
if(lilo != 0) lilo = 1;
x->x_lin0_log1 = lilo;
if(log_height < 10)
log_height = 10;
x->x_log_height = log_height;
if (!strcmp(x->x_gui.x_snd->s_name, "empty"))
- x->x_gui.x_fsf.x_snd_able = 0;
+ x->x_gui.x_fsf.x_snd_able = 0;
if (!strcmp(x->x_gui.x_rcv->s_name, "empty"))
- x->x_gui.x_fsf.x_rcv_able = 0;
+ x->x_gui.x_fsf.x_rcv_able = 0;
if(x->x_gui.x_fsf.x_font_style == 1) strcpy(x->x_gui.x_font, "helvetica");
else if(x->x_gui.x_fsf.x_font_style == 2) strcpy(x->x_gui.x_font, "times");
else { x->x_gui.x_fsf.x_font_style = 0;
- strcpy(x->x_gui.x_font, "courier"); }
+ strcpy(x->x_gui.x_font, "courier"); }
if (x->x_gui.x_fsf.x_rcv_able)
- pd_bind(&x->x_gui.x_obj.ob_pd, x->x_gui.x_rcv);
+ pd_bind(&x->x_gui.x_obj.ob_pd, x->x_gui.x_rcv);
x->x_gui.x_ldx = ldx;
x->x_gui.x_ldy = ldy;
if(fs < 4)
- fs = 4;
+ fs = 4;
x->x_gui.x_fontsize = fs;
if(w < 1)
- w = 1;
+ w = 1;
x->x_gui.x_w = w;
if(h < 8)
- h = 8;
+ h = 8;
x->x_gui.x_h = h;
x->x_buf[0] = 0;
my_numbox_calc_fontwidth(x);
@@ -840,7 +840,7 @@ static void *my_numbox_new(t_symbol *s, int argc, t_atom *argv)
static void my_numbox_free(t_my_numbox *x)
{
if(x->x_gui.x_fsf.x_rcv_able)
- pd_unbind(&x->x_gui.x_obj.ob_pd, x->x_gui.x_rcv);
+ pd_unbind(&x->x_gui.x_obj.ob_pd, x->x_gui.x_rcv);
clock_free(x->x_clock_reset);
clock_free(x->x_clock_wait);
gfxstub_deleteforkey(x);
@@ -849,50 +849,50 @@ static void my_numbox_free(t_my_numbox *x)
void g_numbox_setup(void)
{
my_numbox_class = class_new(gensym("nbx"), (t_newmethod)my_numbox_new,
- (t_method)my_numbox_free, sizeof(t_my_numbox), 0, A_GIMME, 0);
+ (t_method)my_numbox_free, sizeof(t_my_numbox), 0, A_GIMME, 0);
class_addcreator((t_newmethod)my_numbox_new, gensym("my_numbox"),
- A_GIMME, 0);
+ A_GIMME, 0);
class_addbang(my_numbox_class,my_numbox_bang);
class_addfloat(my_numbox_class,my_numbox_float);
class_addlist(my_numbox_class, my_numbox_list);
class_addmethod(my_numbox_class, (t_method)my_numbox_click,
- gensym("click"), A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, 0);
+ gensym("click"), A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, 0);
class_addmethod(my_numbox_class, (t_method)my_numbox_motion,
- gensym("motion"), A_FLOAT, A_FLOAT, 0);
+ gensym("motion"), A_FLOAT, A_FLOAT, 0);
class_addmethod(my_numbox_class, (t_method)my_numbox_dialog,
- gensym("dialog"), A_GIMME, 0);
+ gensym("dialog"), A_GIMME, 0);
class_addmethod(my_numbox_class, (t_method)my_numbox_loadbang,
- gensym("loadbang"), 0);
+ gensym("loadbang"), 0);
class_addmethod(my_numbox_class, (t_method)my_numbox_set,
- gensym("set"), A_FLOAT, 0);
+ gensym("set"), A_FLOAT, 0);
class_addmethod(my_numbox_class, (t_method)my_numbox_size,
- gensym("size"), A_GIMME, 0);
+ gensym("size"), A_GIMME, 0);
class_addmethod(my_numbox_class, (t_method)my_numbox_delta,
- gensym("delta"), A_GIMME, 0);
+ gensym("delta"), A_GIMME, 0);
class_addmethod(my_numbox_class, (t_method)my_numbox_pos,
- gensym("pos"), A_GIMME, 0);
+ gensym("pos"), A_GIMME, 0);
class_addmethod(my_numbox_class, (t_method)my_numbox_range,
- gensym("range"), A_GIMME, 0);
+ gensym("range"), A_GIMME, 0);
class_addmethod(my_numbox_class, (t_method)my_numbox_color,
- gensym("color"), A_GIMME, 0);
+ gensym("color"), A_GIMME, 0);
class_addmethod(my_numbox_class, (t_method)my_numbox_send,
- gensym("send"), A_DEFSYM, 0);
+ gensym("send"), A_DEFSYM, 0);
class_addmethod(my_numbox_class, (t_method)my_numbox_receive,
- gensym("receive"), A_DEFSYM, 0);
+ gensym("receive"), A_DEFSYM, 0);
class_addmethod(my_numbox_class, (t_method)my_numbox_label,
- gensym("label"), A_DEFSYM, 0);
+ gensym("label"), A_DEFSYM, 0);
class_addmethod(my_numbox_class, (t_method)my_numbox_label_pos,
- gensym("label_pos"), A_GIMME, 0);
+ gensym("label_pos"), A_GIMME, 0);
class_addmethod(my_numbox_class, (t_method)my_numbox_label_font,
- gensym("label_font"), A_GIMME, 0);
+ gensym("label_font"), A_GIMME, 0);
class_addmethod(my_numbox_class, (t_method)my_numbox_log,
- gensym("log"), 0);
+ gensym("log"), 0);
class_addmethod(my_numbox_class, (t_method)my_numbox_lin,
- gensym("lin"), 0);
+ gensym("lin"), 0);
class_addmethod(my_numbox_class, (t_method)my_numbox_init,
- gensym("init"), A_FLOAT, 0);
+ gensym("init"), A_FLOAT, 0);
class_addmethod(my_numbox_class, (t_method)my_numbox_log_height,
- gensym("log_height"), A_FLOAT, 0);
+ gensym("log_height"), A_FLOAT, 0);
my_numbox_widgetbehavior.w_getrectfn = my_numbox_getrect;
my_numbox_widgetbehavior.w_displacefn = iemgui_displace;
my_numbox_widgetbehavior.w_selectfn = iemgui_select;
diff --git a/pd/src/g_readwrite.c b/pd/src/g_readwrite.c
index edcd5e24..77c05126 100644
--- a/pd/src/g_readwrite.c
+++ b/pd/src/g_readwrite.c
@@ -23,11 +23,11 @@ static int canvas_scanbinbuf(int natoms, t_atom *vec, int *p_indexout,
int indexwas = *p_next;
*p_indexout = indexwas;
if (indexwas >= natoms)
- return (0);
+ return (0);
for (i = indexwas; i < natoms && vec[i].a_type != A_SEMI; i++)
- ;
+ ;
if (i >= natoms)
- *p_next = i;
+ *p_next = i;
else *p_next = i + 1;
return (i - indexwas);
}
@@ -54,50 +54,50 @@ static void glist_readatoms(t_glist *x, int natoms, t_atom *vec,
t_template *template = template_findbyname(templatesym);
if (!template)
{
- error("%s: no such template", templatesym->s_name);
- *p_nextmsg = natoms;
- return;
+ error("%s: no such template", templatesym->s_name);
+ *p_nextmsg = natoms;
+ return;
}
word_restore(w, template, argc, argv);
n = template->t_n;
for (i = 0; i < n; i++)
{
- if (template->t_vec[i].ds_type == DT_ARRAY)
- {
- int j;
- t_array *a = w[i].w_array;
- int elemsize = a->a_elemsize, nitems = 0;
- t_symbol *arraytemplatesym = template->t_vec[i].ds_arraytemplate;
- t_template *arraytemplate =
- template_findbyname(arraytemplatesym);
- if (!arraytemplate)
- {
- error("%s: no such template", arraytemplatesym->s_name);
- }
- else while (1)
- {
- t_word *element;
- int nline = canvas_scanbinbuf(natoms, vec, &message, p_nextmsg);
- /* empty line terminates array */
- if (!nline)
- break;
- array_resize(a, arraytemplate, nitems + 1);
- element = (t_word *)(((char *)a->a_vec) +
- nitems * elemsize);
- glist_readatoms(x, natoms, vec, p_nextmsg, arraytemplatesym,
- element, nline, vec + message);
- nitems++;
- }
- }
- else if (template->t_vec[i].ds_type == DT_LIST)
- {
- while (1)
- {
- if (!glist_readscalar(w->w_list, natoms, vec,
- p_nextmsg, 0))
- break;
- }
- }
+ if (template->t_vec[i].ds_type == DT_ARRAY)
+ {
+ int j;
+ t_array *a = w[i].w_array;
+ int elemsize = a->a_elemsize, nitems = 0;
+ t_symbol *arraytemplatesym = template->t_vec[i].ds_arraytemplate;
+ t_template *arraytemplate =
+ template_findbyname(arraytemplatesym);
+ if (!arraytemplate)
+ {
+ error("%s: no such template", arraytemplatesym->s_name);
+ }
+ else while (1)
+ {
+ t_word *element;
+ int nline = canvas_scanbinbuf(natoms, vec, &message, p_nextmsg);
+ /* empty line terminates array */
+ if (!nline)
+ break;
+ array_resize(a, arraytemplate, nitems + 1);
+ element = (t_word *)(((char *)a->a_vec) +
+ nitems * elemsize);
+ glist_readatoms(x, natoms, vec, p_nextmsg, arraytemplatesym,
+ element, nline, vec + message);
+ nitems++;
+ }
+ }
+ else if (template->t_vec[i].ds_type == DT_LIST)
+ {
+ while (1)
+ {
+ if (!glist_readscalar(w->w_list, natoms, vec,
+ p_nextmsg, 0))
+ break;
+ }
+ }
}
}
@@ -113,46 +113,46 @@ int glist_readscalar(t_glist *x, int natoms, t_atom *vec,
if (nextmsg >= natoms || vec[nextmsg].a_type != A_SYMBOL)
{
- if (nextmsg < natoms)
- post("stopping early: type %d", vec[nextmsg].a_type);
- *p_nextmsg = natoms;
- return (0);
+ if (nextmsg < natoms)
+ post("stopping early: type %d", vec[nextmsg].a_type);
+ *p_nextmsg = natoms;
+ return (0);
}
templatesym = canvas_makebindsym(vec[nextmsg].a_w.w_symbol);
*p_nextmsg = nextmsg + 1;
if (!(template = template_findbyname(templatesym)))
{
- error("canvas_read: %s: no such template", templatesym->s_name);
- *p_nextmsg = natoms;
- return (0);
+ error("canvas_read: %s: no such template", templatesym->s_name);
+ *p_nextmsg = natoms;
+ return (0);
}
sc = scalar_new(x, templatesym);
if (!sc)
{
- error("couldn't create scalar \"%s\"", templatesym->s_name);
- *p_nextmsg = natoms;
- return (0);
+ error("couldn't create scalar \"%s\"", templatesym->s_name);
+ *p_nextmsg = natoms;
+ return (0);
}
if (wasvis)
{
- /* temporarily lie about vis flag while this is built */
- glist_getcanvas(x)->gl_mapped = 0;
+ /* temporarily lie about vis flag while this is built */
+ glist_getcanvas(x)->gl_mapped = 0;
}
glist_add(x, &sc->sc_gobj);
nline = canvas_scanbinbuf(natoms, vec, &message, p_nextmsg);
glist_readatoms(x, natoms, vec, p_nextmsg, templatesym, sc->sc_vec,
- nline, vec + message);
+ nline, vec + message);
if (wasvis)
{
- /* reset vis flag as before */
- glist_getcanvas(x)->gl_mapped = 1;
- gobj_vis(&sc->sc_gobj, x, 1);
+ /* reset vis flag as before */
+ glist_getcanvas(x)->gl_mapped = 1;
+ gobj_vis(&sc->sc_gobj, x, 1);
}
if (selectit)
{
- glist_select(x, &sc->sc_gobj);
+ glist_select(x, &sc->sc_gobj);
}
return (1);
}
@@ -168,73 +168,73 @@ void glist_readfrombinbuf(t_glist *x, t_binbuf *b, char *filename, int selectem)
vec = binbuf_getvec(b);
- /* check for file type */
+ /* check for file type */
nline = canvas_scanbinbuf(natoms, vec, &message, &nextmsg);
if (nline != 1 && vec[message].a_type != A_SYMBOL &&
- strcmp(vec[message].a_w.w_symbol->s_name, "data"))
+ strcmp(vec[message].a_w.w_symbol->s_name, "data"))
{
- pd_error(x, "%s: file apparently of wrong type", filename);
- binbuf_free(b);
- return;
+ pd_error(x, "%s: file apparently of wrong type", filename);
+ binbuf_free(b);
+ return;
}
- /* read in templates and check for consistency */
+ /* read in templates and check for consistency */
while (1)
{
- t_template *newtemplate, *existtemplate;
- t_symbol *templatesym;
- t_atom *templateargs = getbytes(0);
- int ntemplateargs = 0, newnargs;
- nline = canvas_scanbinbuf(natoms, vec, &message, &nextmsg);
- if (nline < 2)
- break;
- else if (nline > 2)
- canvas_readerror(natoms, vec, message, nline,
- "extra items ignored");
- else if (vec[message].a_type != A_SYMBOL ||
- strcmp(vec[message].a_w.w_symbol->s_name, "template") ||
- vec[message + 1].a_type != A_SYMBOL)
- {
- canvas_readerror(natoms, vec, message, nline,
- "bad template header");
- continue;
- }
- templatesym = canvas_makebindsym(vec[message + 1].a_w.w_symbol);
- while (1)
- {
- nline = canvas_scanbinbuf(natoms, vec, &message, &nextmsg);
- if (nline != 2 && nline != 3)
- break;
- newnargs = ntemplateargs + nline;
- templateargs = (t_atom *)t_resizebytes(templateargs,
- sizeof(*templateargs) * ntemplateargs,
- sizeof(*templateargs) * newnargs);
- templateargs[ntemplateargs] = vec[message];
- templateargs[ntemplateargs + 1] = vec[message + 1];
- if (nline == 3)
- templateargs[ntemplateargs + 2] = vec[message + 2];
- ntemplateargs = newnargs;
- }
- newtemplate = template_new(templatesym, ntemplateargs, templateargs);
- t_freebytes(templateargs, sizeof (*templateargs) * ntemplateargs);
- if (!(existtemplate = template_findbyname(templatesym)))
- {
- error("%s: template not found in current patch",
- templatesym->s_name);
- template_free(newtemplate);
- return;
- }
- if (!template_match(existtemplate, newtemplate))
- {
- error("%s: template doesn't match current one",
- templatesym->s_name);
- template_free(newtemplate);
- return;
- }
- template_free(newtemplate);
+ t_template *newtemplate, *existtemplate;
+ t_symbol *templatesym;
+ t_atom *templateargs = getbytes(0);
+ int ntemplateargs = 0, newnargs;
+ nline = canvas_scanbinbuf(natoms, vec, &message, &nextmsg);
+ if (nline < 2)
+ break;
+ else if (nline > 2)
+ canvas_readerror(natoms, vec, message, nline,
+ "extra items ignored");
+ else if (vec[message].a_type != A_SYMBOL ||
+ strcmp(vec[message].a_w.w_symbol->s_name, "template") ||
+ vec[message + 1].a_type != A_SYMBOL)
+ {
+ canvas_readerror(natoms, vec, message, nline,
+ "bad template header");
+ continue;
+ }
+ templatesym = canvas_makebindsym(vec[message + 1].a_w.w_symbol);
+ while (1)
+ {
+ nline = canvas_scanbinbuf(natoms, vec, &message, &nextmsg);
+ if (nline != 2 && nline != 3)
+ break;
+ newnargs = ntemplateargs + nline;
+ templateargs = (t_atom *)t_resizebytes(templateargs,
+ sizeof(*templateargs) * ntemplateargs,
+ sizeof(*templateargs) * newnargs);
+ templateargs[ntemplateargs] = vec[message];
+ templateargs[ntemplateargs + 1] = vec[message + 1];
+ if (nline == 3)
+ templateargs[ntemplateargs + 2] = vec[message + 2];
+ ntemplateargs = newnargs;
+ }
+ newtemplate = template_new(templatesym, ntemplateargs, templateargs);
+ t_freebytes(templateargs, sizeof (*templateargs) * ntemplateargs);
+ if (!(existtemplate = template_findbyname(templatesym)))
+ {
+ error("%s: template not found in current patch",
+ templatesym->s_name);
+ template_free(newtemplate);
+ return;
+ }
+ if (!template_match(existtemplate, newtemplate))
+ {
+ error("%s: template doesn't match current one",
+ templatesym->s_name);
+ template_free(newtemplate);
+ return;
+ }
+ template_free(newtemplate);
}
while (nextmsg < natoms)
{
- glist_readscalar(x, natoms, vec, &nextmsg, selectem);
+ glist_readscalar(x, natoms, vec, &nextmsg, selectem);
}
}
@@ -248,24 +248,24 @@ static void glist_doread(t_glist *x, t_symbol *filename, t_symbol *format,
t_atom *vec;
if (!strcmp(format->s_name, "cr"))
- cr = 1;
+ cr = 1;
else if (*format->s_name)
- error("qlist_read: unknown flag: %s", format->s_name);
+ error("qlist_read: unknown flag: %s", format->s_name);
if (binbuf_read_via_path(b, filename->s_name,
- canvas_getdir(canvas)->s_name, cr))
+ canvas_getdir(canvas)->s_name, cr))
{
- pd_error(x, "read failed");
- binbuf_free(b);
- return;
+ pd_error(x, "read failed");
+ binbuf_free(b);
+ return;
}
if (wasvis)
- canvas_vis(canvas, 0);
+ canvas_vis(canvas, 0);
if (clearme)
- glist_clear(x);
+ glist_clear(x);
glist_readfrombinbuf(x, b, filename->s_name, 0);
if (wasvis)
- canvas_vis(canvas, 1);
+ canvas_vis(canvas, 1);
binbuf_free(b);
}
@@ -288,51 +288,51 @@ void canvas_dataproperties(t_canvas *x, t_scalar *sc, t_binbuf *b)
t_gobj *y, *y2 = 0, *newone, *oldone = 0;
for (y = x->gl_list, ntotal = 0, scindex = -1; y; y = y->g_next)
{
- if (y == &sc->sc_gobj)
- scindex = ntotal, oldone = y;
- ntotal++;
+ if (y == &sc->sc_gobj)
+ scindex = ntotal, oldone = y;
+ ntotal++;
}
if (scindex == -1)
- bug("data_properties: scalar disappeared");
+ bug("data_properties: scalar disappeared");
glist_readfrombinbuf(x, b, "properties dialog", 0);
newone = 0;
if (scindex >= 0)
{
- /* take the new object off the list */
- if (ntotal)
- {
- for (y = x->gl_list, nnew = 1; y2 = y->g_next;
- y = y2, nnew++)
- if (nnew == ntotal)
- {
- newone = y2;
- y->g_next = y2->g_next;
- break;
- }
- }
- else newone = x->gl_list, x->gl_list = newone->g_next;
+ /* take the new object off the list */
+ if (ntotal)
+ {
+ for (y = x->gl_list, nnew = 1; y2 = y->g_next;
+ y = y2, nnew++)
+ if (nnew == ntotal)
+ {
+ newone = y2;
+ y->g_next = y2->g_next;
+ break;
+ }
+ }
+ else newone = x->gl_list, x->gl_list = newone->g_next;
}
if (!newone)
- error("couldn't update properties (perhaps a format problem?)");
+ error("couldn't update properties (perhaps a format problem?)");
else if (!oldone)
- bug("data_properties: couldn't find old element");
+ bug("data_properties: couldn't find old element");
else
{
- glist_delete(x, oldone);
- if (scindex > 0)
- {
- for (y = x->gl_list, nnew = 1; y;
- y = y->g_next, nnew++)
- if (nnew == scindex || !y->g_next)
- {
- newone->g_next = y->g_next;
- y->g_next = newone;
- goto didit;
- }
- bug("data_properties: can't reinsert");
- }
- else newone->g_next = x->gl_list, x->gl_list = newone;
+ glist_delete(x, oldone);
+ if (scindex > 0)
+ {
+ for (y = x->gl_list, nnew = 1; y;
+ y = y->g_next, nnew++)
+ if (nnew == scindex || !y->g_next)
+ {
+ newone->g_next = y->g_next;
+ y->g_next = newone;
+ goto didit;
+ }
+ bug("data_properties: can't reinsert");
+ }
+ else newone->g_next = x->gl_list, x->gl_list = newone;
}
didit:
;
@@ -346,10 +346,10 @@ void canvas_doaddtemplate(t_symbol *templatesym,
int n = *p_ntemplates, i;
t_symbol **templatevec = *p_templatevec;
for (i = 0; i < n; i++)
- if (templatevec[i] == templatesym)
- return;
+ if (templatevec[i] == templatesym)
+ return;
templatevec = (t_symbol **)t_resizebytes(templatevec,
- n * sizeof(*templatevec), (n+1) * sizeof(*templatevec));
+ n * sizeof(*templatevec), (n+1) * sizeof(*templatevec));
templatevec[n] = templatesym;
*p_templatevec = templatevec;
*p_ntemplates = n+1;
@@ -366,50 +366,50 @@ void canvas_writescalar(t_symbol *templatesym, t_word *w, t_binbuf *b,
int i, n = template->t_n, natom = 0;
if (!amarrayelement)
{
- t_atom templatename;
- SETSYMBOL(&templatename, gensym(templatesym->s_name + 3));
- binbuf_add(b, 1, &templatename);
+ t_atom templatename;
+ SETSYMBOL(&templatename, gensym(templatesym->s_name + 3));
+ binbuf_add(b, 1, &templatename);
}
if (!template)
- bug("canvas_writescalar");
- /* write the atoms (floats and symbols) */
+ bug("canvas_writescalar");
+ /* write the atoms (floats and symbols) */
for (i = 0; i < n; i++)
{
- if (template->t_vec[i].ds_type == DT_FLOAT ||
- template->t_vec[i].ds_type == DT_SYMBOL)
- {
- a = (t_atom *)t_resizebytes(a,
- natom * sizeof(*a), (natom + 1) * sizeof (*a));
- if (template->t_vec[i].ds_type == DT_FLOAT)
- SETFLOAT(a + natom, w[i].w_float);
- else SETSYMBOL(a + natom, w[i].w_symbol);
- natom++;
- }
+ if (template->t_vec[i].ds_type == DT_FLOAT ||
+ template->t_vec[i].ds_type == DT_SYMBOL)
+ {
+ a = (t_atom *)t_resizebytes(a,
+ natom * sizeof(*a), (natom + 1) * sizeof (*a));
+ if (template->t_vec[i].ds_type == DT_FLOAT)
+ SETFLOAT(a + natom, w[i].w_float);
+ else SETSYMBOL(a + natom, w[i].w_symbol);
+ natom++;
+ }
}
- /* array elements have to have at least something */
+ /* array elements have to have at least something */
if (natom == 0 && amarrayelement)
- SETSYMBOL(a + natom, &s_bang), natom++;
+ SETSYMBOL(a + natom, &s_bang), natom++;
binbuf_add(b, natom, a);
binbuf_addsemi(b);
t_freebytes(a, natom * sizeof(*a));
for (i = 0; i < n; i++)
{
- if (template->t_vec[i].ds_type == DT_ARRAY)
- {
- int j;
- t_array *a = w[i].w_array;
- int elemsize = a->a_elemsize, nitems = a->a_n;
- t_symbol *arraytemplatesym = template->t_vec[i].ds_arraytemplate;
- for (j = 0; j < nitems; j++)
- canvas_writescalar(arraytemplatesym,
- (t_word *)(((char *)a->a_vec) + elemsize * j), b, 1);
- binbuf_addsemi(b);
- }
- else if (template->t_vec[i].ds_type == DT_LIST)
- {
- glist_writelist(w->w_list->gl_list, b);
- binbuf_addsemi(b);
- }
+ if (template->t_vec[i].ds_type == DT_ARRAY)
+ {
+ int j;
+ t_array *a = w[i].w_array;
+ int elemsize = a->a_elemsize, nitems = a->a_n;
+ t_symbol *arraytemplatesym = template->t_vec[i].ds_arraytemplate;
+ for (j = 0; j < nitems; j++)
+ canvas_writescalar(arraytemplatesym,
+ (t_word *)(((char *)a->a_vec) + elemsize * j), b, 1);
+ binbuf_addsemi(b);
+ }
+ else if (template->t_vec[i].ds_type == DT_LIST)
+ {
+ glist_writelist(w->w_list->gl_list, b);
+ binbuf_addsemi(b);
+ }
}
}
@@ -417,11 +417,11 @@ static void glist_writelist(t_gobj *y, t_binbuf *b)
{
for (; y; y = y->g_next)
{
- if (pd_class(&y->g_pd) == scalar_class)
- {
- canvas_writescalar(((t_scalar *)y)->sc_template,
- ((t_scalar *)y)->sc_vec, b, 0);
- }
+ if (pd_class(&y->g_pd) == scalar_class)
+ {
+ canvas_writescalar(((t_scalar *)y)->sc_template,
+ ((t_scalar *)y)->sc_vec, b, 0);
+ }
}
}
@@ -438,24 +438,24 @@ static void canvas_addtemplatesforscalar(t_symbol *templatesym,
t_template *template = template_findbyname(templatesym);
canvas_doaddtemplate(templatesym, p_ntemplates, p_templatevec);
if (!template)
- bug("canvas_addtemplatesforscalar");
+ bug("canvas_addtemplatesforscalar");
else for (ds = template->t_vec, i = template->t_n; i--; ds++, w++)
{
- if (ds->ds_type == DT_ARRAY)
- {
- int j;
- t_array *a = w->w_array;
- int elemsize = a->a_elemsize, nitems = a->a_n;
- t_symbol *arraytemplatesym = ds->ds_arraytemplate;
- canvas_doaddtemplate(arraytemplatesym, p_ntemplates, p_templatevec);
- for (j = 0; j < nitems; j++)
- canvas_addtemplatesforscalar(arraytemplatesym,
- (t_word *)(((char *)a->a_vec) + elemsize * j),
- p_ntemplates, p_templatevec);
- }
- else if (ds->ds_type == DT_LIST)
- canvas_addtemplatesforlist(w->w_list->gl_list,
- p_ntemplates, p_templatevec);
+ if (ds->ds_type == DT_ARRAY)
+ {
+ int j;
+ t_array *a = w->w_array;
+ int elemsize = a->a_elemsize, nitems = a->a_n;
+ t_symbol *arraytemplatesym = ds->ds_arraytemplate;
+ canvas_doaddtemplate(arraytemplatesym, p_ntemplates, p_templatevec);
+ for (j = 0; j < nitems; j++)
+ canvas_addtemplatesforscalar(arraytemplatesym,
+ (t_word *)(((char *)a->a_vec) + elemsize * j),
+ p_ntemplates, p_templatevec);
+ }
+ else if (ds->ds_type == DT_LIST)
+ canvas_addtemplatesforlist(w->w_list->gl_list,
+ p_ntemplates, p_templatevec);
}
}
@@ -464,11 +464,11 @@ static void canvas_addtemplatesforlist(t_gobj *y,
{
for (; y; y = y->g_next)
{
- if (pd_class(&y->g_pd) == scalar_class)
- {
- canvas_addtemplatesforscalar(((t_scalar *)y)->sc_template,
- ((t_scalar *)y)->sc_vec, p_ntemplates, p_templatevec);
- }
+ if (pd_class(&y->g_pd) == scalar_class)
+ {
+ canvas_addtemplatesforscalar(((t_scalar *)y)->sc_template,
+ ((t_scalar *)y)->sc_vec, p_ntemplates, p_templatevec);
+ }
}
}
@@ -483,49 +483,49 @@ t_binbuf *glist_writetobinbuf(t_glist *x, int wholething)
for (y = x->gl_list; y; y = y->g_next)
{
- if ((pd_class(&y->g_pd) == scalar_class) &&
- (wholething || glist_isselected(x, y)))
- {
- canvas_addtemplatesforscalar(((t_scalar *)y)->sc_template,
- ((t_scalar *)y)->sc_vec, &ntemplates, &templatevec);
- }
+ if ((pd_class(&y->g_pd) == scalar_class) &&
+ (wholething || glist_isselected(x, y)))
+ {
+ canvas_addtemplatesforscalar(((t_scalar *)y)->sc_template,
+ ((t_scalar *)y)->sc_vec, &ntemplates, &templatevec);
+ }
}
binbuf_addv(b, "s;", gensym("data"));
for (i = 0; i < ntemplates; i++)
{
- t_template *template = template_findbyname(templatevec[i]);
- int j, m = template->t_n;
- /* drop "pd-" prefix from template symbol to print it: */
- binbuf_addv(b, "ss;", gensym("template"),
- gensym(templatevec[i]->s_name + 3));
- for (j = 0; j < m; j++)
- {
- t_symbol *type;
- switch (template->t_vec[j].ds_type)
- {
- case DT_FLOAT: type = &s_float; break;
- case DT_SYMBOL: type = &s_symbol; break;
- case DT_ARRAY: type = gensym("array"); break;
- case DT_LIST: type = &s_list; break;
- default: type = &s_float; bug("canvas_write");
- }
- if (template->t_vec[j].ds_type == DT_ARRAY)
- binbuf_addv(b, "sss;", type, template->t_vec[j].ds_name,
- gensym(template->t_vec[j].ds_arraytemplate->s_name + 3));
- else binbuf_addv(b, "ss;", type, template->t_vec[j].ds_name);
- }
- binbuf_addsemi(b);
+ t_template *template = template_findbyname(templatevec[i]);
+ int j, m = template->t_n;
+ /* drop "pd-" prefix from template symbol to print it: */
+ binbuf_addv(b, "ss;", gensym("template"),
+ gensym(templatevec[i]->s_name + 3));
+ for (j = 0; j < m; j++)
+ {
+ t_symbol *type;
+ switch (template->t_vec[j].ds_type)
+ {
+ case DT_FLOAT: type = &s_float; break;
+ case DT_SYMBOL: type = &s_symbol; break;
+ case DT_ARRAY: type = gensym("array"); break;
+ case DT_LIST: type = &s_list; break;
+ default: type = &s_float; bug("canvas_write");
+ }
+ if (template->t_vec[j].ds_type == DT_ARRAY)
+ binbuf_addv(b, "sss;", type, template->t_vec[j].ds_name,
+ gensym(template->t_vec[j].ds_arraytemplate->s_name + 3));
+ else binbuf_addv(b, "ss;", type, template->t_vec[j].ds_name);
+ }
+ binbuf_addsemi(b);
}
binbuf_addsemi(b);
- /* now write out the objects themselves */
+ /* now write out the objects themselves */
for (y = x->gl_list; y; y = y->g_next)
{
- if ((pd_class(&y->g_pd) == scalar_class) &&
- (wholething || glist_isselected(x, y)))
- {
- canvas_writescalar(((t_scalar *)y)->sc_template,
- ((t_scalar *)y)->sc_vec, b, 0);
- }
+ if ((pd_class(&y->g_pd) == scalar_class) &&
+ (wholething || glist_isselected(x, y)))
+ {
+ canvas_writescalar(((t_scalar *)y)->sc_template,
+ ((t_scalar *)y)->sc_vec, b, 0);
+ }
}
return (b);
}
@@ -541,16 +541,16 @@ static void glist_write(t_glist *x, t_symbol *filename, t_symbol *format)
t_canvas *canvas = glist_getcanvas(x);
canvas_makefilename(canvas, filename->s_name, buf, MAXPDSTRING);
if (!strcmp(format->s_name, "cr"))
- cr = 1;
+ cr = 1;
else if (*format->s_name)
- error("qlist_read: unknown flag: %s", format->s_name);
+ error("qlist_read: unknown flag: %s", format->s_name);
b = glist_writetobinbuf(x, 1);
if (b)
{
- if (binbuf_write(b, buf, "", cr))
- error("%s: write failed", filename->s_name);
- binbuf_free(b);
+ if (binbuf_write(b, buf, "", cr))
+ error("%s: write failed", filename->s_name);
+ binbuf_free(b);
}
}
@@ -563,45 +563,45 @@ static void canvas_saveto(t_canvas *x, t_binbuf *b)
t_gobj *y;
t_linetraverser t;
t_outconnect *oc;
- /* subpatch */
+ /* subpatch */
if (x->gl_owner && !x->gl_env)
{
- binbuf_addv(b, "ssiiiisi;", gensym("#N"), gensym("canvas"),
- (t_int)(x->gl_screenx1),
- (t_int)(x->gl_screeny1),
- (t_int)(x->gl_screenx2 - x->gl_screenx1),
- (t_int)(x->gl_screeny2 - x->gl_screeny1),
- (*x->gl_name->s_name ? x->gl_name: gensym("(subpatch)")),
- x->gl_mapped);
+ binbuf_addv(b, "ssiiiisi;", gensym("#N"), gensym("canvas"),
+ (int)(x->gl_screenx1),
+ (int)(x->gl_screeny1),
+ (int)(x->gl_screenx2 - x->gl_screenx1),
+ (int)(x->gl_screeny2 - x->gl_screeny1),
+ (*x->gl_name->s_name ? x->gl_name: gensym("(subpatch)")),
+ x->gl_mapped);
}
- /* root or abstraction */
+ /* root or abstraction */
else binbuf_addv(b, "ssiiiii;", gensym("#N"), gensym("canvas"),
- (t_int)(x->gl_screenx1),
- (t_int)(x->gl_screeny1),
- (t_int)(x->gl_screenx2 - x->gl_screenx1),
- (t_int)(x->gl_screeny2 - x->gl_screeny1),
- x->gl_font);
+ (int)(x->gl_screenx1),
+ (int)(x->gl_screeny1),
+ (int)(x->gl_screenx2 - x->gl_screenx1),
+ (int)(x->gl_screeny2 - x->gl_screeny1),
+ (int)x->gl_font);
for (y = x->gl_list; y; y = y->g_next)
- gobj_save(y, b);
+ gobj_save(y, b);
linetraverser_start(&t, x);
while (oc = linetraverser_next(&t))
{
- int srcno = canvas_getindex(x, &t.tr_ob->ob_g);
- int sinkno = canvas_getindex(x, &t.tr_ob2->ob_g);
- binbuf_addv(b, "ssiiii;", gensym("#X"), gensym("connect"),
- srcno, t.tr_outno, sinkno, t.tr_inno);
+ int srcno = canvas_getindex(x, &t.tr_ob->ob_g);
+ int sinkno = canvas_getindex(x, &t.tr_ob2->ob_g);
+ binbuf_addv(b, "ssiiii;", gensym("#X"), gensym("connect"),
+ srcno, t.tr_outno, sinkno, t.tr_inno);
}
- /* unless everything is the default (as in ordinary subpatches)
- print out a "coords" message to set up the coordinate systems */
+ /* unless everything is the default (as in ordinary subpatches)
+ print out a "coords" message to set up the coordinate systems */
if (x->gl_isgraph || x->gl_x1 || x->gl_y1 ||
- x->gl_x2 != 1 || x->gl_y2 != 1 || x->gl_pixwidth || x->gl_pixheight)
- binbuf_addv(b, "ssfffffff;", gensym("#X"), gensym("coords"),
- x->gl_x1, x->gl_y1,
- x->gl_x2, x->gl_y2,
- (float)x->gl_pixwidth, (float)x->gl_pixheight,
- (float)x->gl_isgraph);
+ x->gl_x2 != 1 || x->gl_y2 != 1 || x->gl_pixwidth || x->gl_pixheight)
+ binbuf_addv(b, "ssfffffff;", gensym("#X"), gensym("coords"),
+ x->gl_x1, x->gl_y1,
+ x->gl_x2, x->gl_y2,
+ (float)x->gl_pixwidth, (float)x->gl_pixheight,
+ (float)x->gl_isgraph);
}
/* call this recursively to collect all the template names for
@@ -613,14 +613,14 @@ static void canvas_collecttemplatesfor(t_canvas *x, int *ntemplatesp,
for (y = x->gl_list; y; y = y->g_next)
{
- if ((pd_class(&y->g_pd) == scalar_class) &&
- (wholething || glist_isselected(x, y)))
- canvas_addtemplatesforscalar(((t_scalar *)y)->sc_template,
- ((t_scalar *)y)->sc_vec, ntemplatesp, templatevecp);
- else if ((pd_class(&y->g_pd) == canvas_class) &&
- (wholething || glist_isselected(x, y)))
- canvas_collecttemplatesfor((t_canvas *)y,
- ntemplatesp, templatevecp, 1);
+ if ((pd_class(&y->g_pd) == scalar_class) &&
+ (wholething || glist_isselected(x, y)))
+ canvas_addtemplatesforscalar(((t_scalar *)y)->sc_template,
+ ((t_scalar *)y)->sc_vec, ntemplatesp, templatevecp);
+ else if ((pd_class(&y->g_pd) == canvas_class) &&
+ (wholething || glist_isselected(x, y)))
+ canvas_collecttemplatesfor((t_canvas *)y,
+ ntemplatesp, templatevecp, 1);
}
}
@@ -633,33 +633,33 @@ static void canvas_savetemplatesto(t_canvas *x, t_binbuf *b, int wholething)
canvas_collecttemplatesfor(x, &ntemplates, &templatevec, wholething);
for (i = 0; i < ntemplates; i++)
{
- t_template *template = template_findbyname(templatevec[i]);
- int j, m = template->t_n;
- if (!template)
- {
- bug("canvas_savetemplatesto");
- continue;
- }
- /* drop "pd-" prefix from template symbol to print */
- binbuf_addv(b, "sss", &s__N, gensym("struct"),
- gensym(templatevec[i]->s_name + 3));
- for (j = 0; j < m; j++)
- {
- t_symbol *type;
- switch (template->t_vec[j].ds_type)
- {
- case DT_FLOAT: type = &s_float; break;
- case DT_SYMBOL: type = &s_symbol; break;
- case DT_ARRAY: type = gensym("array"); break;
- case DT_LIST: type = &s_list; break;
- default: type = &s_float; bug("canvas_write");
- }
- if (template->t_vec[j].ds_type == DT_ARRAY)
- binbuf_addv(b, "sss", type, template->t_vec[j].ds_name,
- gensym(template->t_vec[j].ds_arraytemplate->s_name + 3));
- else binbuf_addv(b, "ss", type, template->t_vec[j].ds_name);
- }
- binbuf_addsemi(b);
+ t_template *template = template_findbyname(templatevec[i]);
+ int j, m = template->t_n;
+ if (!template)
+ {
+ bug("canvas_savetemplatesto");
+ continue;
+ }
+ /* drop "pd-" prefix from template symbol to print */
+ binbuf_addv(b, "sss", &s__N, gensym("struct"),
+ gensym(templatevec[i]->s_name + 3));
+ for (j = 0; j < m; j++)
+ {
+ t_symbol *type;
+ switch (template->t_vec[j].ds_type)
+ {
+ case DT_FLOAT: type = &s_float; break;
+ case DT_SYMBOL: type = &s_symbol; break;
+ case DT_ARRAY: type = gensym("array"); break;
+ case DT_LIST: type = &s_list; break;
+ default: type = &s_float; bug("canvas_write");
+ }
+ if (template->t_vec[j].ds_type == DT_ARRAY)
+ binbuf_addv(b, "sss", type, template->t_vec[j].ds_name,
+ gensym(template->t_vec[j].ds_arraytemplate->s_name + 3));
+ else binbuf_addv(b, "ss", type, template->t_vec[j].ds_name);
+ }
+ binbuf_addsemi(b);
}
}
@@ -675,12 +675,12 @@ static void canvas_savetofile(t_canvas *x, t_symbol *filename, t_symbol *dir)
if (binbuf_write(b, filename->s_name, dir->s_name, 0)) sys_ouch();
else
{
- /* if not an abstraction, reset title bar and directory */
- if (!x->gl_owner)
- canvas_rename(x, filename, dir);
- post("saved to: %s/%s", dir->s_name, filename->s_name);
- canvas_dirty(x, 0);
- canvas_reload(filename, dir, &x->gl_gobj);
+ /* if not an abstraction, reset title bar and directory */
+ if (!x->gl_owner)
+ canvas_rename(x, filename, dir);
+ post("saved to: %s/%s", dir->s_name, filename->s_name);
+ canvas_dirty(x, 0);
+ canvas_reload(filename, dir, &x->gl_gobj);
}
binbuf_free(b);
}
@@ -688,8 +688,8 @@ static void canvas_savetofile(t_canvas *x, t_symbol *filename, t_symbol *dir)
static void canvas_menusaveas(t_canvas *x)
{
t_canvas *x2 = canvas_getrootfor(x);
- sys_vgui("pdtk_canvas_saveas .x%x \"%s\" \"%s\"\n", x2,
- x2->gl_name->s_name, canvas_getdir(x2)->s_name);
+ sys_vgui("pdtk_canvas_saveas .x%lx \"%s\" \"%s\"\n", x2,
+ x2->gl_name->s_name, canvas_getdir(x2)->s_name);
}
static void canvas_menusave(t_canvas *x)
@@ -697,8 +697,8 @@ static void canvas_menusave(t_canvas *x)
t_canvas *x2 = canvas_getrootfor(x);
char *name = x2->gl_name->s_name;
if (*name && strncmp(name, "Untitled", 8)
- && (strlen(name) < 4 || strcmp(name + strlen(name)-4, ".pat")))
- canvas_savetofile(x2, x2->gl_name, canvas_getdir(x2));
+ && (strlen(name) < 4 || strcmp(name + strlen(name)-4, ".pat")))
+ canvas_savetofile(x2, x2->gl_name, canvas_getdir(x2));
else canvas_menusaveas(x2);
}
@@ -706,18 +706,18 @@ static void canvas_menusave(t_canvas *x)
void g_readwrite_setup(void)
{
class_addmethod(canvas_class, (t_method)glist_write,
- gensym("write"), A_SYMBOL, A_DEFSYM, A_NULL);
+ gensym("write"), A_SYMBOL, A_DEFSYM, A_NULL);
class_addmethod(canvas_class, (t_method)glist_read,
- gensym("read"), A_SYMBOL, A_DEFSYM, A_NULL);
+ gensym("read"), A_SYMBOL, A_DEFSYM, A_NULL);
class_addmethod(canvas_class, (t_method)glist_mergefile,
- gensym("mergefile"), A_SYMBOL, A_DEFSYM, A_NULL);
+ gensym("mergefile"), A_SYMBOL, A_DEFSYM, A_NULL);
class_addmethod(canvas_class, (t_method)canvas_savetofile,
- gensym("savetofile"), A_SYMBOL, A_SYMBOL, 0);
+ gensym("savetofile"), A_SYMBOL, A_SYMBOL, 0);
class_addmethod(canvas_class, (t_method)canvas_saveto,
- gensym("saveto"), A_CANT, 0);
+ gensym("saveto"), A_CANT, 0);
/* ------------------ from the menu ------------------------- */
class_addmethod(canvas_class, (t_method)canvas_menusave,
- gensym("menusave"), 0);
+ gensym("menusave"), 0);
class_addmethod(canvas_class, (t_method)canvas_menusaveas,
- gensym("menusaveas"), 0);
+ gensym("menusaveas"), 0);
}
diff --git a/pd/src/g_rtext.c b/pd/src/g_rtext.c
index d44f30fa..0de6903e 100644
--- a/pd/src/g_rtext.c
+++ b/pd/src/g_rtext.c
@@ -50,11 +50,11 @@ t_rtext *rtext_new(t_glist *glist, t_text *who)
x->x_glist = glist;
x->x_next = glist->gl_editor->e_rtext;
x->x_selstart = x->x_selend = x->x_active =
- x->x_drawnwidth = x->x_drawnheight = 0;
+ x->x_drawnwidth = x->x_drawnheight = 0;
binbuf_gettext(who->te_binbuf, &x->x_buf, &x->x_bufsize);
glist->gl_editor->e_rtext = x;
- sprintf(x->x_tag, ".x%x.t%x", (t_int)glist_getcanvas(x->x_glist),
- (t_int)x);
+ sprintf(x->x_tag, ".x%lx.t%lx", (t_int)glist_getcanvas(x->x_glist),
+ (t_int)x);
return (x);
}
@@ -63,18 +63,18 @@ static t_rtext *rtext_entered;
void rtext_free(t_rtext *x)
{
if (x->x_glist->gl_editor->e_textedfor == x)
- x->x_glist->gl_editor->e_textedfor = 0;
+ x->x_glist->gl_editor->e_textedfor = 0;
if (x->x_glist->gl_editor->e_rtext == x)
- x->x_glist->gl_editor->e_rtext = x->x_next;
+ x->x_glist->gl_editor->e_rtext = x->x_next;
else
{
- t_rtext *e2;
- for (e2 = x->x_glist->gl_editor->e_rtext; e2; e2 = e2->x_next)
- if (e2->x_next == x)
- {
- e2->x_next = x->x_next;
- break;
- }
+ t_rtext *e2;
+ for (e2 = x->x_glist->gl_editor->e_rtext; e2; e2 = e2->x_next)
+ if (e2->x_next == x)
+ {
+ e2->x_next = x->x_next;
+ break;
+ }
}
if (rtext_entered == x) rtext_entered = 0;
freebytes(x->x_buf, x->x_bufsize);
@@ -92,6 +92,11 @@ void rtext_gettext(t_rtext *x, char **buf, int *bufsize)
*bufsize = x->x_bufsize;
}
+void rtext_getseltext(t_rtext *x, char **buf, int *bufsize)
+{
+ *buf = x->x_buf + x->x_selstart;
+ *bufsize = x->x_selend - x->x_selstart;
+}
/* LATER deal with tcl-significant characters */
@@ -101,9 +106,9 @@ static int firstone(char *s, int c, int n)
int i = 0;
while (s != s2)
{
- if (*s == c) return (i);
- i++;
- s++;
+ if (*s == c) return (i);
+ i++;
+ s++;
}
return (-1);
}
@@ -113,18 +118,18 @@ static int lastone(char *s, int c, int n)
char *s2 = s + n;
while (s2 != s)
{
- s2--;
- n--;
- if (*s2 == c) return (n);
+ s2--;
+ n--;
+ if (*s2 == c) return (n);
}
return (-1);
}
/* the following routine computes line breaks and carries out
some action which could be:
- SEND_FIRST - draw the box for the first time
- SEND_UPDATE - redraw the updated box
- otherwise - don't draw, just calculate.
+ SEND_FIRST - draw the box for the first time
+ SEND_UPDATE - redraw the updated box
+ otherwise - don't draw, just calculate.
Called with *widthp and *heightpas coordinates of
a test point, the routine reports the index of the character found
there in *indexp. *widthp and *heightp are set to the width and height
@@ -132,125 +137,138 @@ static int lastone(char *s, int c, int n)
*/
/* LATER get this and sys_vgui to work together properly,
- breaking up messages as needed. As of now, there's
- a limit of 1950 characters, imposed by sys_vgui(). */
+ breaking up messages as needed. As of now, there's
+ a limit of 1950 characters, imposed by sys_vgui(). */
#define UPBUFSIZE 4000
#define BOXWIDTH 60
/* Older (pre-8.3.4) TCL versions handle text selection differently; this
flag is set from the GUI if this happens. LATER take this out: early 2006? */
-extern int sys_oldtclversion;
+extern int sys_oldtclversion;
static void rtext_senditup(t_rtext *x, int action, int *widthp, int *heightp,
int *indexp)
{
float dispx, dispy;
- char tempbuf[UPBUFSIZE], *tp = tempbuf, *bp = x->x_buf;
- int outchars, inchars = x->x_bufsize, nlines = 0, ncolumns = 0,
- pixwide, pixhigh;
+ char smallbuf[200], *tempbuf;
+ int outchars = 0, nlines = 0, ncolumns = 0,
+ pixwide, pixhigh;
int font = glist_getfont(x->x_glist);
int fontwidth = sys_fontwidth(font), fontheight = sys_fontheight(font);
int findx = (*widthp + (fontwidth/2)) / fontwidth,
- findy = *heightp / fontheight;
+ findy = *heightp / fontheight;
int reportedindex = 0;
t_canvas *canvas = glist_getcanvas(x->x_glist);
int widthspec = x->x_text->te_width;
int widthlimit = (widthspec ? widthspec : BOXWIDTH);
- while (inchars)
+ int inindex = 0;
+ int selstart = 0, selend = 0;
+ if (x->x_bufsize >= 100)
+ tempbuf = (char *)t_getbytes(2 * x->x_bufsize + 1);
+ else tempbuf = smallbuf;
+ while (x->x_bufsize - inindex > 0)
{
- int maxindex = (inchars > widthlimit ? widthlimit : inchars);
- int eatchar = 1;
- int foundit = firstone(bp, '\n', maxindex);
- if (foundit < 0)
- {
- if (inchars > widthlimit)
- {
- foundit = lastone(bp, ' ', maxindex);
- if (foundit < 0)
- {
- foundit = maxindex;
- eatchar = 0;
- }
- }
- else
- {
- foundit = inchars;
- eatchar = 0;
- }
- }
- if (nlines == findy)
- {
- int actualx = (findx < 0 ? 0 :
- (findx > foundit ? foundit : findx));
- *indexp = (bp - x->x_buf) + actualx;
- reportedindex = 1;
- }
- strncpy(tp, bp, foundit);
- tp += foundit;
- bp += (foundit + eatchar);
- inchars -= (foundit + eatchar);
- if (inchars) *tp++ = '\n';
- if (foundit > ncolumns) ncolumns = foundit;
- nlines++;
+ int inchars = x->x_bufsize - inindex;
+ int maxindex = (inchars > widthlimit ? widthlimit : inchars);
+ int eatchar = 1;
+ int foundit = firstone(x->x_buf + inindex, '\n', maxindex);
+ if (foundit < 0)
+ {
+ if (inchars > widthlimit)
+ {
+ foundit = lastone(x->x_buf + inindex, ' ', maxindex);
+ if (foundit < 0)
+ {
+ foundit = maxindex;
+ eatchar = 0;
+ }
+ }
+ else
+ {
+ foundit = inchars;
+ eatchar = 0;
+ }
+ }
+ if (nlines == findy)
+ {
+ int actualx = (findx < 0 ? 0 :
+ (findx > foundit ? foundit : findx));
+ *indexp = inindex + actualx;
+ reportedindex = 1;
+ }
+ strncpy(tempbuf+outchars, x->x_buf + inindex, foundit);
+ if (x->x_selstart >= inindex &&
+ x->x_selstart <= inindex + foundit + eatchar)
+ selstart = x->x_selstart + outchars - inindex;
+ if (x->x_selend >= inindex &&
+ x->x_selend <= inindex + foundit + eatchar)
+ selend = x->x_selend + outchars - inindex;
+ outchars += foundit;
+ inindex += (foundit + eatchar);
+ if (inindex < x->x_bufsize)
+ tempbuf[outchars++] = '\n';
+ if (foundit > ncolumns)
+ ncolumns = foundit;
+ nlines++;
}
- outchars = tp - tempbuf;
- if (outchars > 1950) outchars = 1950;
if (!reportedindex)
- *indexp = outchars;
+ *indexp = outchars;
dispx = text_xpix(x->x_text, x->x_glist);
dispy = text_ypix(x->x_text, x->x_glist);
if (nlines < 1) nlines = 1;
if (!widthspec)
{
- while (ncolumns < 3)
- {
- tempbuf[outchars++] = ' ';
- ncolumns++;
- }
+ while (ncolumns < 3)
+ {
+ tempbuf[outchars++] = ' ';
+ ncolumns++;
+ }
}
else ncolumns = widthspec;
pixwide = ncolumns * fontwidth + (LMARGIN + RMARGIN);
pixhigh = nlines * fontheight + (TMARGIN + BMARGIN);
if (action == SEND_FIRST)
- sys_vgui("pdtk_text_new .x%x.c %s %f %f {%.*s} %d %s\n",
- canvas, x->x_tag,
- dispx + LMARGIN, dispy + TMARGIN,
- outchars, tempbuf, sys_hostfontsize(font),
- (glist_isselected(x->x_glist,
- &x->x_glist->gl_gobj)? "blue" : "black"));
+ sys_vgui("pdtk_text_new .x%lx.c %s %f %f {%.*s} %d %s\n",
+ canvas, x->x_tag,
+ dispx + LMARGIN, dispy + TMARGIN,
+ outchars, tempbuf, sys_hostfontsize(font),
+ (glist_isselected(x->x_glist,
+ &x->x_glist->gl_gobj)? "blue" : "black"));
else if (action == SEND_UPDATE)
{
- sys_vgui("pdtk_text_set .x%x.c %s {%.*s}\n",
- canvas, x->x_tag, outchars, tempbuf);
- if (pixwide != x->x_drawnwidth || pixhigh != x->x_drawnheight)
- text_drawborder(x->x_text, x->x_glist, x->x_tag,
- pixwide, pixhigh, 0);
- if (x->x_active)
- {
- if (x->x_selend > x->x_selstart)
- {
- sys_vgui(".x%x.c select from %s %d\n", canvas,
- x->x_tag, x->x_selstart);
- sys_vgui(".x%x.c select to %s %d\n", canvas,
- x->x_tag, x->x_selend + (sys_oldtclversion ? 0 : -1));
- sys_vgui(".x%x.c focus \"\"\n", canvas);
- }
- else
- {
- sys_vgui(".x%x.c select clear\n", canvas);
- sys_vgui(".x%x.c icursor %s %d\n", canvas, x->x_tag,
- x->x_selstart);
- sys_vgui(".x%x.c focus %s\n", canvas, x->x_tag);
- }
- }
+ sys_vgui("pdtk_text_set .x%lx.c %s {%.*s}\n",
+ canvas, x->x_tag, outchars, tempbuf);
+ if (pixwide != x->x_drawnwidth || pixhigh != x->x_drawnheight)
+ text_drawborder(x->x_text, x->x_glist, x->x_tag,
+ pixwide, pixhigh, 0);
+ if (x->x_active)
+ {
+ if (selend > selstart)
+ {
+ sys_vgui(".x%lx.c select from %s %d\n", canvas,
+ x->x_tag, selstart);
+ sys_vgui(".x%lx.c select to %s %d\n", canvas,
+ x->x_tag, selend + (sys_oldtclversion ? 0 : -1));
+ sys_vgui(".x%lx.c focus \"\"\n", canvas);
+ }
+ else
+ {
+ sys_vgui(".x%lx.c select clear\n", canvas);
+ sys_vgui(".x%lx.c icursor %s %d\n", canvas, x->x_tag,
+ selstart);
+ sys_vgui(".x%lx.c focus %s\n", canvas, x->x_tag);
+ }
+ }
}
x->x_drawnwidth = pixwide;
x->x_drawnheight = pixhigh;
*widthp = pixwide;
*heightp = pixhigh;
+ if (tempbuf != smallbuf)
+ t_freebytes(tempbuf, 2 * x->x_bufsize + 1);
}
void rtext_retext(t_rtext *x)
@@ -259,51 +277,51 @@ void rtext_retext(t_rtext *x)
t_text *text = x->x_text;
t_freebytes(x->x_buf, x->x_bufsize);
binbuf_gettext(text->te_binbuf, &x->x_buf, &x->x_bufsize);
- /* special case: for number boxes, try to pare the number down
- to the specified width of the box. */
+ /* special case: for number boxes, try to pare the number down
+ to the specified width of the box. */
if (text->te_width > 0 && text->te_type == T_ATOM &&
- x->x_bufsize > text->te_width)
+ x->x_bufsize > text->te_width)
{
- t_atom *atomp = binbuf_getvec(text->te_binbuf);
- int natom = binbuf_getnatom(text->te_binbuf);
- int bufsize = x->x_bufsize;
- if (natom == 1 && atomp->a_type == A_FLOAT)
- {
- /* try to reduce size by dropping decimal digits */
- int wantreduce = bufsize - text->te_width;
- char *decimal = 0, *nextchar, *ebuf = x->x_buf + bufsize,
- *s1, *s2;
- int ndecimals;
- for (decimal = x->x_buf; decimal < ebuf; decimal++)
- if (*decimal == '.')
- break;
- if (decimal >= ebuf)
- goto giveup;
- for (nextchar = decimal + 1; nextchar < ebuf; nextchar++)
- if (*nextchar < '0' || *nextchar > '9')
- break;
- if (nextchar - decimal - 1 < wantreduce)
- goto giveup;
- for (s1 = nextchar - wantreduce, s2 = s1 + wantreduce;
- s2 < ebuf; s1++, s2++)
- *s1 = *s2;
- t_resizebytes(x->x_buf, bufsize, text->te_width);
- bufsize = text->te_width;
- goto done;
- giveup:
- /* give up and bash it to "+" or "-" */
- x->x_buf[0] = (atomp->a_w.w_float < 0 ? '-' : '+');
- t_resizebytes(x->x_buf, bufsize, 1);
- bufsize = 1;
- }
- else if (bufsize > text->te_width)
- {
- x->x_buf[text->te_width - 1] = '>';
- t_resizebytes(x->x_buf, bufsize, text->te_width);
- bufsize = text->te_width;
- }
+ t_atom *atomp = binbuf_getvec(text->te_binbuf);
+ int natom = binbuf_getnatom(text->te_binbuf);
+ int bufsize = x->x_bufsize;
+ if (natom == 1 && atomp->a_type == A_FLOAT)
+ {
+ /* try to reduce size by dropping decimal digits */
+ int wantreduce = bufsize - text->te_width;
+ char *decimal = 0, *nextchar, *ebuf = x->x_buf + bufsize,
+ *s1, *s2;
+ int ndecimals;
+ for (decimal = x->x_buf; decimal < ebuf; decimal++)
+ if (*decimal == '.')
+ break;
+ if (decimal >= ebuf)
+ goto giveup;
+ for (nextchar = decimal + 1; nextchar < ebuf; nextchar++)
+ if (*nextchar < '0' || *nextchar > '9')
+ break;
+ if (nextchar - decimal - 1 < wantreduce)
+ goto giveup;
+ for (s1 = nextchar - wantreduce, s2 = s1 + wantreduce;
+ s2 < ebuf; s1++, s2++)
+ *s1 = *s2;
+ t_resizebytes(x->x_buf, bufsize, text->te_width);
+ bufsize = text->te_width;
+ goto done;
+ giveup:
+ /* give up and bash it to "+" or "-" */
+ x->x_buf[0] = (atomp->a_w.w_float < 0 ? '-' : '+');
+ t_resizebytes(x->x_buf, bufsize, 1);
+ bufsize = 1;
+ }
+ else if (bufsize > text->te_width)
+ {
+ x->x_buf[text->te_width - 1] = '>';
+ t_resizebytes(x->x_buf, bufsize, text->te_width);
+ bufsize = text->te_width;
+ }
done:
- x->x_bufsize = bufsize;
+ x->x_bufsize = bufsize;
}
rtext_senditup(x, SEND_UPDATE, &w, &h, &indx);
}
@@ -339,21 +357,21 @@ void rtext_draw(t_rtext *x)
void rtext_erase(t_rtext *x)
{
- sys_vgui(".x%x.c delete %s\n", glist_getcanvas(x->x_glist), x->x_tag);
+ sys_vgui(".x%lx.c delete %s\n", glist_getcanvas(x->x_glist), x->x_tag);
}
void rtext_displace(t_rtext *x, int dx, int dy)
{
- sys_vgui(".x%x.c move %s %d %d\n", glist_getcanvas(x->x_glist),
- x->x_tag, dx, dy);
+ sys_vgui(".x%lx.c move %s %d %d\n", glist_getcanvas(x->x_glist),
+ x->x_tag, dx, dy);
}
void rtext_select(t_rtext *x, int state)
{
t_glist *glist = x->x_glist;
t_canvas *canvas = glist_getcanvas(glist);
- sys_vgui(".x%x.c itemconfigure %s -fill %s\n", canvas,
- x->x_tag, (state? "blue" : "black"));
+ sys_vgui(".x%lx.c itemconfigure %s -fill %s\n", canvas,
+ x->x_tag, (state? "blue" : "black"));
canvas_editing = canvas;
}
@@ -364,20 +382,20 @@ void rtext_activate(t_rtext *x, int state)
t_canvas *canvas = glist_getcanvas(glist);
if (state)
{
- sys_vgui(".x%x.c focus %s\n", canvas, x->x_tag);
- glist->gl_editor->e_textedfor = x;
- glist->gl_editor->e_textdirty = 0;
- x->x_dragfrom = x->x_selstart = 0;
- x->x_selend = x->x_bufsize;
- x->x_active = 1;
+ sys_vgui(".x%lx.c focus %s\n", canvas, x->x_tag);
+ glist->gl_editor->e_textedfor = x;
+ glist->gl_editor->e_textdirty = 0;
+ x->x_dragfrom = x->x_selstart = 0;
+ x->x_selend = x->x_bufsize;
+ x->x_active = 1;
}
else
{
- sys_vgui("selection clear .x%x.c\n", canvas);
- sys_vgui(".x%x.c focus \"\"\n", canvas);
- if (glist->gl_editor->e_textedfor == x)
- glist->gl_editor->e_textedfor = 0;
- x->x_active = 0;
+ sys_vgui("selection clear .x%lx.c\n", canvas);
+ sys_vgui(".x%lx.c focus \"\"\n", canvas);
+ if (glist->gl_editor->e_textedfor == x)
+ glist->gl_editor->e_textedfor = 0;
+ x->x_active = 0;
}
rtext_senditup(x, SEND_UPDATE, &w, &h, &indx);
}
@@ -388,76 +406,76 @@ void rtext_key(t_rtext *x, int keynum, t_symbol *keysym)
char *s1, *s2;
if (keynum)
{
- int n = keynum;
- if (n == '\r') n = '\n';
- if (n == '\b') /* backspace */
- {
- /* LATER delete the box if all text is selected...
- this causes reentrancy problems now. */
- /* if ((!x->x_selstart) && (x->x_selend == x->x_bufsize))
- {
- ....
- } */
- if (x->x_selstart && (x->x_selstart == x->x_selend))
- x->x_selstart--;
- }
- else if (n == 127) /* delete */
- {
- if (x->x_selend < x->x_bufsize && (x->x_selstart == x->x_selend))
- x->x_selend++;
- }
-
- ndel = x->x_selend - x->x_selstart;
- for (i = x->x_selend; i < x->x_bufsize; i++)
- x->x_buf[i- ndel] = x->x_buf[i];
- newsize = x->x_bufsize - ndel;
- x->x_buf = resizebytes(x->x_buf, x->x_bufsize, newsize);
- x->x_bufsize = newsize;
-
- if (n == '\n' || isprint(n))
- {
- newsize = x->x_bufsize+1;
- x->x_buf = resizebytes(x->x_buf, x->x_bufsize, newsize);
- for (i = x->x_bufsize; i > x->x_selstart; i--)
- x->x_buf[i] = x->x_buf[i-1];
- x->x_buf[x->x_selstart] = n;
- x->x_bufsize = newsize;
- x->x_selstart = x->x_selstart + 1;
- }
- x->x_selend = x->x_selstart;
- x->x_glist->gl_editor->e_textdirty = 1;
+ int n = keynum;
+ if (n == '\r') n = '\n';
+ if (n == '\b') /* backspace */
+ {
+ /* LATER delete the box if all text is selected...
+ this causes reentrancy problems now. */
+ /* if ((!x->x_selstart) && (x->x_selend == x->x_bufsize))
+ {
+ ....
+ } */
+ if (x->x_selstart && (x->x_selstart == x->x_selend))
+ x->x_selstart--;
+ }
+ else if (n == 127) /* delete */
+ {
+ if (x->x_selend < x->x_bufsize && (x->x_selstart == x->x_selend))
+ x->x_selend++;
+ }
+
+ ndel = x->x_selend - x->x_selstart;
+ for (i = x->x_selend; i < x->x_bufsize; i++)
+ x->x_buf[i- ndel] = x->x_buf[i];
+ newsize = x->x_bufsize - ndel;
+ x->x_buf = resizebytes(x->x_buf, x->x_bufsize, newsize);
+ x->x_bufsize = newsize;
+
+ if (n == '\n' || isprint(n))
+ {
+ newsize = x->x_bufsize+1;
+ x->x_buf = resizebytes(x->x_buf, x->x_bufsize, newsize);
+ for (i = x->x_bufsize; i > x->x_selstart; i--)
+ x->x_buf[i] = x->x_buf[i-1];
+ x->x_buf[x->x_selstart] = n;
+ x->x_bufsize = newsize;
+ x->x_selstart = x->x_selstart + 1;
+ }
+ x->x_selend = x->x_selstart;
+ x->x_glist->gl_editor->e_textdirty = 1;
}
else if (!strcmp(keysym->s_name, "Right"))
{
- if (x->x_selend == x->x_selstart && x->x_selstart < x->x_bufsize)
- x->x_selend = x->x_selstart = x->x_selstart + 1;
- else
- x->x_selstart = x->x_selend;
+ if (x->x_selend == x->x_selstart && x->x_selstart < x->x_bufsize)
+ x->x_selend = x->x_selstart = x->x_selstart + 1;
+ else
+ x->x_selstart = x->x_selend;
}
else if (!strcmp(keysym->s_name, "Left"))
{
- if (x->x_selend == x->x_selstart && x->x_selstart > 0)
- x->x_selend = x->x_selstart = x->x_selstart - 1;
- else
- x->x_selend = x->x_selstart;
+ if (x->x_selend == x->x_selstart && x->x_selstart > 0)
+ x->x_selend = x->x_selstart = x->x_selstart - 1;
+ else
+ x->x_selend = x->x_selstart;
}
- /* this should be improved... life's too short */
+ /* this should be improved... life's too short */
else if (!strcmp(keysym->s_name, "Up"))
{
- if (x->x_selstart)
- x->x_selstart--;
- while (x->x_selstart > 0 && x->x_buf[x->x_selstart] != '\n')
- x->x_selstart--;
- x->x_selend = x->x_selstart;
+ if (x->x_selstart)
+ x->x_selstart--;
+ while (x->x_selstart > 0 && x->x_buf[x->x_selstart] != '\n')
+ x->x_selstart--;
+ x->x_selend = x->x_selstart;
}
else if (!strcmp(keysym->s_name, "Down"))
{
- while (x->x_selend < x->x_bufsize &&
- x->x_buf[x->x_selend] != '\n')
- x->x_selend++;
- if (x->x_selend < x->x_bufsize)
- x->x_selend++;
- x->x_selstart = x->x_selend;
+ while (x->x_selend < x->x_bufsize &&
+ x->x_buf[x->x_selend] != '\n')
+ x->x_selend++;
+ if (x->x_selend < x->x_bufsize)
+ x->x_selend++;
+ x->x_selstart = x->x_selend;
}
rtext_senditup(x, SEND_UPDATE, &w, &h, &indx);
}
@@ -468,19 +486,55 @@ void rtext_mouse(t_rtext *x, int xval, int yval, int flag)
rtext_senditup(x, SEND_CHECK, &w, &h, &indx);
if (flag == RTEXT_DOWN)
{
- x->x_dragfrom = x->x_selstart = x->x_selend = indx;
+ x->x_dragfrom = x->x_selstart = x->x_selend = indx;
+ }
+ else if (flag == RTEXT_DBL)
+ {
+ int whereseparator, newseparator;
+ x->x_dragfrom = -1;
+ whereseparator = 0;
+ if ((newseparator = lastone(x->x_buf, ' ', indx)) > whereseparator)
+ whereseparator = newseparator+1;
+ if ((newseparator = lastone(x->x_buf, '\n', indx)) > whereseparator)
+ whereseparator = newseparator+1;
+ if ((newseparator = lastone(x->x_buf, ';', indx)) > whereseparator)
+ whereseparator = newseparator+1;
+ if ((newseparator = lastone(x->x_buf, ',', indx)) > whereseparator)
+ whereseparator = newseparator+1;
+ x->x_selstart = whereseparator;
+
+ whereseparator = x->x_bufsize - indx;
+ if ((newseparator =
+ firstone(x->x_buf+indx, ' ', x->x_bufsize - indx)) >= 0 &&
+ newseparator < whereseparator)
+ whereseparator = newseparator;
+ if ((newseparator =
+ firstone(x->x_buf+indx, '\n', x->x_bufsize - indx)) >= 0 &&
+ newseparator < whereseparator)
+ whereseparator = newseparator;
+ if ((newseparator =
+ firstone(x->x_buf+indx, ';', x->x_bufsize - indx)) >= 0 &&
+ newseparator < whereseparator)
+ whereseparator = newseparator;
+ if ((newseparator =
+ firstone(x->x_buf+indx, ',', x->x_bufsize - indx)) >= 0 &&
+ newseparator < whereseparator)
+ whereseparator = newseparator;
+ x->x_selend = indx + whereseparator;
}
else if (flag == RTEXT_SHIFT)
{
- if (indx * 2 > x->x_selstart + x->x_selend)
- x->x_dragfrom = x->x_selstart, x->x_selend = indx;
- else
- x->x_dragfrom = x->x_selend, x->x_selstart = indx;
+ if (indx * 2 > x->x_selstart + x->x_selend)
+ x->x_dragfrom = x->x_selstart, x->x_selend = indx;
+ else
+ x->x_dragfrom = x->x_selend, x->x_selstart = indx;
}
else if (flag == RTEXT_DRAG)
{
- x->x_selstart = (x->x_dragfrom < indx ? x->x_dragfrom : indx);
- x->x_selend = (x->x_dragfrom > indx ? x->x_dragfrom : indx);
+ if (x->x_dragfrom < 0)
+ return;
+ x->x_selstart = (x->x_dragfrom < indx ? x->x_dragfrom : indx);
+ x->x_selend = (x->x_dragfrom > indx ? x->x_dragfrom : indx);
}
rtext_senditup(x, SEND_UPDATE, &w, &h, &indx);
}
diff --git a/pd/src/g_scalar.c b/pd/src/g_scalar.c
index 63b42b4f..6c35c2d4 100644
--- a/pd/src/g_scalar.c
+++ b/pd/src/g_scalar.c
@@ -21,7 +21,7 @@ control their appearances by adding stuff to draw.
#include <stdlib.h>
#include <string.h>
-#include <stdio.h> /* for read/write to files */
+#include <stdio.h> /* for read/write to files */
#include "m_pd.h"
#include "g_canvas.h"
@@ -33,20 +33,20 @@ void word_init(t_word *wp, t_template *template, t_gpointer *gp)
t_dataslot *datatypes = template->t_vec;
for (i = 0; i < nitems; i++, datatypes++, wp++)
{
- int type = datatypes->ds_type;
- if (type == DT_FLOAT)
- wp->w_float = 0;
- else if (type == DT_SYMBOL)
- wp->w_symbol = &s_symbol;
- else if (type == DT_ARRAY)
- {
- wp->w_array = array_new(datatypes->ds_arraytemplate, gp);
- }
- else if (type == DT_LIST)
- {
- /* LATER test this and get it to work */
- wp->w_list = canvas_new(0, 0, 0, 0);
- }
+ int type = datatypes->ds_type;
+ if (type == DT_FLOAT)
+ wp->w_float = 0;
+ else if (type == DT_SYMBOL)
+ wp->w_symbol = &s_symbol;
+ else if (type == DT_ARRAY)
+ {
+ wp->w_array = array_new(datatypes->ds_arraytemplate, gp);
+ }
+ else if (type == DT_LIST)
+ {
+ /* LATER test this and get it to work */
+ wp->w_list = canvas_new(0, 0, 0, 0);
+ }
}
}
@@ -57,32 +57,32 @@ void word_restore(t_word *wp, t_template *template,
t_dataslot *datatypes = template->t_vec;
for (i = 0; i < nitems; i++, datatypes++, wp++)
{
- int type = datatypes->ds_type;
- if (type == DT_FLOAT)
- {
- float f;
- if (argc)
- {
- f = atom_getfloat(argv);
- argv++, argc--;
- }
- else f = 0;
- wp->w_float = f;
- }
- else if (type == DT_SYMBOL)
- {
- t_symbol *s;
- if (argc)
- {
- s = atom_getsymbol(argv);
- argv++, argc--;
- }
- else s = &s_;
- wp->w_symbol = s;
- }
+ int type = datatypes->ds_type;
+ if (type == DT_FLOAT)
+ {
+ float f;
+ if (argc)
+ {
+ f = atom_getfloat(argv);
+ argv++, argc--;
+ }
+ else f = 0;
+ wp->w_float = f;
+ }
+ else if (type == DT_SYMBOL)
+ {
+ t_symbol *s;
+ if (argc)
+ {
+ s = atom_getsymbol(argv);
+ argv++, argc--;
+ }
+ else s = &s_;
+ wp->w_symbol = s;
+ }
}
if (argc)
- post("warning: word_restore: extra arguments");
+ post("warning: word_restore: extra arguments");
}
void word_free(t_word *wp, t_template *template)
@@ -91,10 +91,10 @@ void word_free(t_word *wp, t_template *template)
t_dataslot *dt;
for (dt = template->t_vec, i = 0; i < template->t_n; i++, dt++)
{
- if (dt->ds_type == DT_ARRAY)
- array_free(wp[i].w_array);
- else if (dt->ds_type == DT_LIST)
- canvas_free(wp[i].w_list);
+ if (dt->ds_type == DT_ARRAY)
+ array_free(wp[i].w_array);
+ else if (dt->ds_type == DT_LIST)
+ canvas_free(wp[i].w_list);
}
}
@@ -113,11 +113,11 @@ t_scalar *scalar_new(t_glist *owner, t_symbol *templatesym)
template = template_findbyname(templatesym);
if (!template)
{
- error("scalar: couldn't find template %s", templatesym->s_name);
- return (0);
+ error("scalar: couldn't find template %s", templatesym->s_name);
+ return (0);
}
x = (t_scalar *)getbytes(sizeof(t_scalar) +
- (template->t_n - 1) * sizeof(*x->sc_vec));
+ (template->t_n - 1) * sizeof(*x->sc_vec));
x->sc_gobj.g_pd = scalar_class;
x->sc_template = templatesym;
gpointer_setglist(&gp, owner, x);
@@ -135,15 +135,15 @@ void glist_scalar(t_glist *glist,
t_symbol *classname, t_int argc, t_atom *argv)
{
t_symbol *templatesym =
- canvas_makebindsym(atom_getsymbolarg(0, argc, argv));
+ canvas_makebindsym(atom_getsymbolarg(0, argc, argv));
t_binbuf *b;
int natoms, nextmsg = 0;
t_atom *vec;
if (!template_findbyname(templatesym))
{
- pd_error(glist, "%s: no such template",
- atom_getsymbolarg(0, argc, argv)->s_name);
- return;
+ pd_error(glist, "%s: no such template",
+ atom_getsymbolarg(0, argc, argv)->s_name);
+ return;
}
b = binbuf_new();
@@ -174,35 +174,35 @@ static void scalar_getrect(t_gobj *z, t_glist *owner,
t_gobj *y;
float basex, basey;
scalar_getbasexy(x, &basex, &basey);
- /* if someone deleted the template canvas, we're just a point */
+ /* if someone deleted the template canvas, we're just a point */
if (!templatecanvas)
{
- x1 = x2 = glist_xtopixels(owner, basex);
- y1 = y2 = glist_ytopixels(owner, basey);
+ x1 = x2 = glist_xtopixels(owner, basex);
+ y1 = y2 = glist_ytopixels(owner, basey);
}
else
{
- int hit = 0;
- x1 = y1 = 0x7fffffff;
- x2 = y2 = -0x7fffffff;
- for (y = templatecanvas->gl_list; y; y = y->g_next)
- {
- t_parentwidgetbehavior *wb = pd_getparentwidget(&y->g_pd);
- int nx1, ny1, nx2, ny2;
- if (!wb) continue;
- (*wb->w_parentgetrectfn)(y, owner,
- x->sc_vec, template, basex, basey,
- &nx1, &ny1, &nx2, &ny2);
- if (hit)
- {
- if (nx1 < x1) x1 = nx1;
- if (ny1 < y1) y1 = ny1;
- if (nx2 > x2) x2 = nx2;
- if (ny2 > y2) y2 = ny2;
- }
- else x1 = nx1, y1 = ny1, x2 = nx2, y2 = ny2, hit = 1;
- }
- if (!hit) x1 = y1 = x2 = y2 = 0;
+ int hit = 0;
+ x1 = y1 = 0x7fffffff;
+ x2 = y2 = -0x7fffffff;
+ for (y = templatecanvas->gl_list; y; y = y->g_next)
+ {
+ t_parentwidgetbehavior *wb = pd_getparentwidget(&y->g_pd);
+ int nx1, ny1, nx2, ny2;
+ if (!wb) continue;
+ (*wb->w_parentgetrectfn)(y, owner,
+ x->sc_vec, template, basex, basey,
+ &nx1, &ny1, &nx2, &ny2);
+ if (hit)
+ {
+ if (nx1 < x1) x1 = nx1;
+ if (ny1 < y1) y1 = ny1;
+ if (nx2 > x2) x2 = nx2;
+ if (ny2 > y2) y2 = ny2;
+ }
+ else x1 = nx1, y1 = ny1, x2 = nx2, y2 = ny2, hit = 1;
+ }
+ if (!hit) x1 = y1 = x2 = y2 = 0;
}
/* post("scalar x1 %d y1 %d x2 %d y2 %d", x1, y1, x2, y2); */
*xp1 = x1;
@@ -218,15 +218,15 @@ static void scalar_select(t_gobj *z, t_glist *owner, int state)
/* later */
if (state)
{
- int x1, y1, x2, y2;
- scalar_getrect(z, owner, &x1, &y1, &x2, &y2);
- x1--; x2++; y1--; y2++;
- sys_vgui(".x%x.c create line %d %d %d %d %d %d %d %d %d %d \
- -width 0 -fill blue -tags select%x\n",
- glist_getcanvas(owner), x1, y1, x1, y2, x2, y2, x2, y1, x1, y1,
- x);
+ int x1, y1, x2, y2;
+ scalar_getrect(z, owner, &x1, &y1, &x2, &y2);
+ x1--; x2++; y1--; y2++;
+ sys_vgui(".x%lx.c create line %d %d %d %d %d %d %d %d %d %d \
+ -width 0 -fill blue -tags select%lx\n",
+ glist_getcanvas(owner), x1, y1, x1, y2, x2, y2, x2, y1, x1, y1,
+ x);
}
- else sys_vgui(".x%x.c delete select%x\n", glist_getcanvas(owner), x);
+ else sys_vgui(".x%lx.c delete select%lx\n", glist_getcanvas(owner), x);
}
static void scalar_displace(t_gobj *z, t_glist *glist, int dx, int dy)
@@ -238,26 +238,26 @@ static void scalar_displace(t_gobj *z, t_glist *glist, int dx, int dy)
int xonset, yonset, xtype, ytype, gotx, goty;
if (!template)
{
- error("scalar: couldn't find template %s", templatesym->s_name);
- return;
+ error("scalar: couldn't find template %s", templatesym->s_name);
+ return;
}
gotx = template_find_field(template, gensym("x"), &xonset, &xtype, &zz);
if (gotx && (xtype != DT_FLOAT))
- gotx = 0;
+ gotx = 0;
goty = template_find_field(template, gensym("y"), &yonset, &ytype, &zz);
if (goty && (ytype != DT_FLOAT))
- goty = 0;
+ goty = 0;
if (gotx)
- *(t_float *)(((char *)(x->sc_vec)) + xonset) +=
- dx * (glist_pixelstox(glist, 1) - glist_pixelstox(glist, 0));
+ *(t_float *)(((char *)(x->sc_vec)) + xonset) +=
+ dx * (glist_pixelstox(glist, 1) - glist_pixelstox(glist, 0));
if (goty)
- *(t_float *)(((char *)(x->sc_vec)) + yonset) +=
- dy * (glist_pixelstoy(glist, 1) - glist_pixelstoy(glist, 0));
+ *(t_float *)(((char *)(x->sc_vec)) + yonset) +=
+ dy * (glist_pixelstoy(glist, 1) - glist_pixelstoy(glist, 0));
glist_redrawitem(glist, z);
if (glist_isselected(glist, z))
{
- scalar_select(z, glist, 0);
- scalar_select(z, glist, 1);
+ scalar_select(z, glist, 0);
+ scalar_select(z, glist, 1);
}
}
@@ -280,26 +280,28 @@ static void scalar_vis(t_gobj *z, t_glist *owner, int vis)
t_gobj *y;
float basex, basey;
scalar_getbasexy(x, &basex, &basey);
- /* if we don't know how to draw it, make a small rectangle */
+ /* if we don't know how to draw it, make a small rectangle */
if (!templatecanvas)
{
- if (vis)
- {
- int x1 = glist_xtopixels(owner, basex);
- int y1 = glist_ytopixels(owner, basey);
- sys_vgui(".x%x.c create rectangle %d %d %d %d -tags scalar%x\n",
- glist_getcanvas(owner), x1-1, y1-1, x1+1, y1+1, x);
- }
- else sys_vgui(".x%x.c delete scalar%x\n", glist_getcanvas(owner), x);
- return;
+ if (vis)
+ {
+ int x1 = glist_xtopixels(owner, basex);
+ int y1 = glist_ytopixels(owner, basey);
+ sys_vgui(".x%lx.c create rectangle %d %d %d %d -tags scalar%lx\n",
+ glist_getcanvas(owner), x1-1, y1-1, x1+1, y1+1, x);
+ }
+ else sys_vgui(".x%lx.c delete scalar%lx\n", glist_getcanvas(owner), x);
+ return;
}
for (y = templatecanvas->gl_list; y; y = y->g_next)
{
- t_parentwidgetbehavior *wb = pd_getparentwidget(&y->g_pd);
- if (!wb) continue;
- (*wb->w_parentvisfn)(y, owner, x->sc_vec, template, basex, basey, vis);
+ t_parentwidgetbehavior *wb = pd_getparentwidget(&y->g_pd);
+ if (!wb) continue;
+ (*wb->w_parentvisfn)(y, owner, x->sc_vec, template, basex, basey, vis);
}
+ if (!vis)
+ sys_unqueuegui(x);
}
static int scalar_click(t_gobj *z, struct _glist *owner,
@@ -314,12 +316,12 @@ static int scalar_click(t_gobj *z, struct _glist *owner,
scalar_getbasexy(x, &basex, &basey);
for (y = templatecanvas->gl_list; y; y = y->g_next)
{
- t_parentwidgetbehavior *wb = pd_getparentwidget(&y->g_pd);
- if (!wb) continue;
- if (hit = (*wb->w_parentclickfn)(y, owner,
- x, template, basex, basey,
- xpix, ypix, shift, alt, dbl, doit))
- return (hit);
+ t_parentwidgetbehavior *wb = pd_getparentwidget(&y->g_pd);
+ if (!wb) continue;
+ if (hit = (*wb->w_parentclickfn)(y, owner,
+ x, template, basex, basey,
+ xpix, ypix, shift, alt, dbl, doit))
+ return (hit);
}
return (0);
}
@@ -379,13 +381,13 @@ static void scalar_free(t_scalar *x)
t_template *template = template_findbyname(templatesym);
if (!template)
{
- error("scalar: couldn't find template %s", templatesym->s_name);
- return;
+ error("scalar: couldn't find template %s", templatesym->s_name);
+ return;
}
word_free(x->sc_vec, template);
gfxstub_deleteforkey(x);
- /* the "size" field in the class is zero, so Pd doesn't try to free
- us automatically (see pd_free()) */
+ /* the "size" field in the class is zero, so Pd doesn't try to free
+ us automatically (see pd_free()) */
freebytes(x, sizeof(t_scalar) + (template->t_n - 1) * sizeof(*x->sc_vec));
}
@@ -394,7 +396,7 @@ static void scalar_free(t_scalar *x)
void g_scalar_setup(void)
{
scalar_class = class_new(gensym("scalar"), 0, (t_method)scalar_free, 0,
- CLASS_GOBJ, 0);
+ CLASS_GOBJ, 0);
class_setwidget(scalar_class, &scalar_widgetbehavior);
class_setsavefn(scalar_class, scalar_save);
class_setpropertiesfn(scalar_class, scalar_properties);
diff --git a/pd/src/g_template.c b/pd/src/g_template.c
index 52901460..086cd787 100644
--- a/pd/src/g_template.c
+++ b/pd/src/g_template.c
@@ -7,7 +7,7 @@
#include <stdio.h>
#include "m_pd.h"
-#include "s_stuff.h" /* for sys_hostfontsize */
+#include "s_stuff.h" /* for sys_hostfontsize */
#include "g_canvas.h"
/*
@@ -57,10 +57,10 @@ static t_dataslot template_float_vec =
static t_template template_float =
{
- 0, /* class -- fill in in setup routine */
- 0, /* list of "struct"/t_gtemplate objects */
- &s_float, /* name */
- 1, /* number of items */
+ 0, /* class -- fill in in setup routine */
+ 0, /* list of "struct"/t_gtemplate objects */
+ &s_float, /* name */
+ 1, /* number of items */
&template_float_vec
};
@@ -69,9 +69,9 @@ static int dataslot_matches(t_dataslot *ds1, t_dataslot *ds2,
int nametoo)
{
return ((!nametoo || ds1->ds_name == ds2->ds_name) &&
- ds1->ds_type == ds2->ds_type &&
- (ds1->ds_type != DT_ARRAY ||
- ds1->ds_arraytemplate == ds2->ds_arraytemplate));
+ ds1->ds_type == ds2->ds_type &&
+ (ds1->ds_type != DT_ARRAY ||
+ ds1->ds_arraytemplate == ds2->ds_arraytemplate));
}
/* -- templates, the active ingredient in gtemplates defined below. ------- */
@@ -83,50 +83,50 @@ t_template *template_new(t_symbol *templatesym, int argc, t_atom *argv)
x->t_vec = (t_dataslot *)t_getbytes(0);
while (argc > 0)
{
- int newtype, oldn, newn;
- t_symbol *newname, *newarraytemplate = &s_, *newtypesym;
- if (argc < 2 || argv[0].a_type != A_SYMBOL ||
- argv[1].a_type != A_SYMBOL)
- goto bad;
- newtypesym = argv[0].a_w.w_symbol;
- newname = argv[1].a_w.w_symbol;
- if (newtypesym == &s_float)
- newtype = DT_FLOAT;
- else if (newtypesym == &s_symbol)
- newtype = DT_SYMBOL;
- else if (newtypesym == &s_list)
- newtype = DT_LIST;
- else if (newtypesym == gensym("array"))
- {
- if (argc < 3 || argv[2].a_type != A_SYMBOL)
- {
- pd_error(x, "array lacks element template or name");
- goto bad;
- }
- newarraytemplate = canvas_makebindsym(argv[2].a_w.w_symbol);
- newtype = DT_ARRAY;
- argc--;
- argv++;
- }
- else
- {
- pd_error(x, "%s: no such type", newtypesym->s_name);
- return (0);
- }
- newn = (oldn = x->t_n) + 1;
- x->t_vec = (t_dataslot *)t_resizebytes(x->t_vec,
- oldn * sizeof(*x->t_vec), newn * sizeof(*x->t_vec));
- x->t_n = newn;
- x->t_vec[oldn].ds_type = newtype;
- x->t_vec[oldn].ds_name = newname;
- x->t_vec[oldn].ds_arraytemplate = newarraytemplate;
+ int newtype, oldn, newn;
+ t_symbol *newname, *newarraytemplate = &s_, *newtypesym;
+ if (argc < 2 || argv[0].a_type != A_SYMBOL ||
+ argv[1].a_type != A_SYMBOL)
+ goto bad;
+ newtypesym = argv[0].a_w.w_symbol;
+ newname = argv[1].a_w.w_symbol;
+ if (newtypesym == &s_float)
+ newtype = DT_FLOAT;
+ else if (newtypesym == &s_symbol)
+ newtype = DT_SYMBOL;
+ else if (newtypesym == &s_list)
+ newtype = DT_LIST;
+ else if (newtypesym == gensym("array"))
+ {
+ if (argc < 3 || argv[2].a_type != A_SYMBOL)
+ {
+ pd_error(x, "array lacks element template or name");
+ goto bad;
+ }
+ newarraytemplate = canvas_makebindsym(argv[2].a_w.w_symbol);
+ newtype = DT_ARRAY;
+ argc--;
+ argv++;
+ }
+ else
+ {
+ pd_error(x, "%s: no such type", newtypesym->s_name);
+ return (0);
+ }
+ newn = (oldn = x->t_n) + 1;
+ x->t_vec = (t_dataslot *)t_resizebytes(x->t_vec,
+ oldn * sizeof(*x->t_vec), newn * sizeof(*x->t_vec));
+ x->t_n = newn;
+ x->t_vec[oldn].ds_type = newtype;
+ x->t_vec[oldn].ds_name = newname;
+ x->t_vec[oldn].ds_arraytemplate = newarraytemplate;
bad:
- argc -= 2; argv += 2;
+ argc -= 2; argv += 2;
}
if (templatesym->s_name)
{
- x->t_sym = templatesym;
- pd_bind(&x->t_pdobj, x->t_sym);
+ x->t_sym = templatesym;
+ pd_bind(&x->t_pdobj, x->t_sym);
}
else x->t_sym = templatesym;
return (x);
@@ -144,17 +144,17 @@ int template_find_field(t_template *x, t_symbol *name, int *p_onset,
int i, n;
if (!x)
{
- bug("template_find_field");
- return (0);
+ bug("template_find_field");
+ return (0);
}
n = x->t_n;
for (i = 0; i < n; i++)
- if (x->t_vec[i].ds_name == name)
+ if (x->t_vec[i].ds_name == name)
{
- *p_onset = i * sizeof(t_word);
- *p_type = x->t_vec[i].ds_type;
- *p_arraytype = x->t_vec[i].ds_arraytemplate;
- return (1);
+ *p_onset = i * sizeof(t_word);
+ *p_type = x->t_vec[i].ds_type;
+ *p_arraytype = x->t_vec[i].ds_arraytemplate;
+ return (1);
}
return (0);
}
@@ -167,13 +167,13 @@ t_float template_getfloat(t_template *x, t_symbol *fieldname, t_word *wp,
float val = 0;
if (template_find_field(x, fieldname, &onset, &type, &arraytype))
{
- if (type == DT_FLOAT)
- val = *(t_float *)(((char *)wp) + onset);
- else if (loud) error("%s.%s: not a number",
- x->t_sym->s_name, fieldname->s_name);
+ if (type == DT_FLOAT)
+ val = *(t_float *)(((char *)wp) + onset);
+ else if (loud) error("%s.%s: not a number",
+ x->t_sym->s_name, fieldname->s_name);
}
else if (loud) error("%s.%s: no such field",
- x->t_sym->s_name, fieldname->s_name);
+ x->t_sym->s_name, fieldname->s_name);
return (val);
}
@@ -184,13 +184,13 @@ void template_setfloat(t_template *x, t_symbol *fieldname, t_word *wp,
t_symbol *arraytype;
if (template_find_field(x, fieldname, &onset, &type, &arraytype))
{
- if (type == DT_FLOAT)
- *(t_float *)(((char *)wp) + onset) = f;
- else if (loud) error("%s.%s: not a number",
- x->t_sym->s_name, fieldname->s_name);
+ if (type == DT_FLOAT)
+ *(t_float *)(((char *)wp) + onset) = f;
+ else if (loud) error("%s.%s: not a number",
+ x->t_sym->s_name, fieldname->s_name);
}
else if (loud) error("%s.%s: no such field",
- x->t_sym->s_name, fieldname->s_name);
+ x->t_sym->s_name, fieldname->s_name);
}
t_symbol *template_getsymbol(t_template *x, t_symbol *fieldname, t_word *wp,
@@ -201,13 +201,13 @@ t_symbol *template_getsymbol(t_template *x, t_symbol *fieldname, t_word *wp,
t_symbol *val = &s_;
if (template_find_field(x, fieldname, &onset, &type, &arraytype))
{
- if (type == DT_SYMBOL)
- val = *(t_symbol **)(((char *)wp) + onset);
- else if (loud) error("%s.%s: not a symbol",
- x->t_sym->s_name, fieldname->s_name);
+ if (type == DT_SYMBOL)
+ val = *(t_symbol **)(((char *)wp) + onset);
+ else if (loud) error("%s.%s: not a symbol",
+ x->t_sym->s_name, fieldname->s_name);
}
else if (loud) error("%s.%s: no such field",
- x->t_sym->s_name, fieldname->s_name);
+ x->t_sym->s_name, fieldname->s_name);
return (val);
}
@@ -218,34 +218,34 @@ void template_setsymbol(t_template *x, t_symbol *fieldname, t_word *wp,
t_symbol *arraytype;
if (template_find_field(x, fieldname, &onset, &type, &arraytype))
{
- if (type == DT_SYMBOL)
- *(t_symbol **)(((char *)wp) + onset) = s;
- else if (loud) error("%s.%s: not a symbol",
- x->t_sym->s_name, fieldname->s_name);
+ if (type == DT_SYMBOL)
+ *(t_symbol **)(((char *)wp) + onset) = s;
+ else if (loud) error("%s.%s: not a symbol",
+ x->t_sym->s_name, fieldname->s_name);
}
else if (loud) error("%s.%s: no such field",
- x->t_sym->s_name, fieldname->s_name);
+ x->t_sym->s_name, fieldname->s_name);
}
/* stringent check to see if a "saved" template, x2, matches the current
- one (x1). It's OK if x1 has additional scalar elements but not (yet)
- arrays or lists. This is used for reading in "data files". */
+ one (x1). It's OK if x1 has additional scalar elements but not (yet)
+ arrays or lists. This is used for reading in "data files". */
int template_match(t_template *x1, t_template *x2)
{
int i;
if (x1->t_n < x2->t_n)
- return (0);
+ return (0);
for (i = x2->t_n; i < x1->t_n; i++)
{
- if (x1->t_vec[i].ds_type == DT_ARRAY ||
- x1->t_vec[i].ds_type == DT_LIST)
- return (0);
+ if (x1->t_vec[i].ds_type == DT_ARRAY ||
+ x1->t_vec[i].ds_type == DT_LIST)
+ return (0);
}
if (x2->t_n > x1->t_n)
- post("add elements...");
+ post("add elements...");
for (i = 0; i < x2->t_n; i++)
- if (!dataslot_matches(&x1->t_vec[i], &x2->t_vec[i], 1))
- return (0);
+ if (!dataslot_matches(&x1->t_vec[i], &x2->t_vec[i], 1))
+ return (0);
return (1);
}
@@ -265,14 +265,14 @@ static void template_conformwords(t_template *tfrom, t_template *tto,
int nfrom = tfrom->t_n, nto = tto->t_n, i;
for (i = 0; i < nto; i++)
{
- if (conformaction[i] >= 0)
- {
- /* we swap the two, in case it's an array or list, so that
- when "wfrom" is deleted the old one gets cleaned up. */
- t_word wwas = wto[i];
- wto[i] = wfrom[conformaction[i]];
- wfrom[conformaction[i]] = wwas;
- }
+ if (conformaction[i] >= 0)
+ {
+ /* we swap the two, in case it's an array or list, so that
+ when "wfrom" is deleted the old one gets cleaned up. */
+ t_word wwas = wto[i];
+ wto[i] = wfrom[conformaction[i]];
+ wfrom[conformaction[i]] = wwas;
+ }
}
}
@@ -285,61 +285,61 @@ static t_scalar *template_conformscalar(t_template *tfrom, t_template *tto,
int nto = tto->t_n, nfrom = tfrom->t_n, i;
t_template *scalartemplate;
/* post("conform scalar"); */
- /* possibly replace the scalar */
+ /* possibly replace the scalar */
if (scfrom->sc_template == tfrom->t_sym)
{
- /* see scalar_new() for comment about the gpointer. */
- gpointer_init(&gp);
- x = (t_scalar *)getbytes(sizeof(t_scalar) +
- (tto->t_n - 1) * sizeof(*x->sc_vec));
- x->sc_gobj.g_pd = scalar_class;
- x->sc_template = tfrom->t_sym;
- gpointer_setglist(&gp, glist, x);
- /* Here we initialize to the new template, but array and list
- elements will still belong to old template. */
- word_init(x->sc_vec, tto, &gp);
-
- template_conformwords(tfrom, tto, conformaction,
- scfrom->sc_vec, x->sc_vec);
-
- /* replace the old one with the new one in the list */
- if (glist->gl_list == &scfrom->sc_gobj)
- {
- glist->gl_list = &x->sc_gobj;
- x->sc_gobj.g_next = scfrom->sc_gobj.g_next;
- }
- else
- {
- t_gobj *y, *y2;
- for (y = glist->gl_list; y2 = y->g_next; y = y2)
- if (y2 == &scfrom->sc_gobj)
- {
- x->sc_gobj.g_next = y2->g_next;
- y->g_next = &x->sc_gobj;
- goto nobug;
- }
- bug("template_conformscalar");
- nobug: ;
- }
- /* burn the old one */
- pd_free(&scfrom->sc_gobj.g_pd);
+ /* see scalar_new() for comment about the gpointer. */
+ gpointer_init(&gp);
+ x = (t_scalar *)getbytes(sizeof(t_scalar) +
+ (tto->t_n - 1) * sizeof(*x->sc_vec));
+ x->sc_gobj.g_pd = scalar_class;
+ x->sc_template = tfrom->t_sym;
+ gpointer_setglist(&gp, glist, x);
+ /* Here we initialize to the new template, but array and list
+ elements will still belong to old template. */
+ word_init(x->sc_vec, tto, &gp);
+
+ template_conformwords(tfrom, tto, conformaction,
+ scfrom->sc_vec, x->sc_vec);
+
+ /* replace the old one with the new one in the list */
+ if (glist->gl_list == &scfrom->sc_gobj)
+ {
+ glist->gl_list = &x->sc_gobj;
+ x->sc_gobj.g_next = scfrom->sc_gobj.g_next;
+ }
+ else
+ {
+ t_gobj *y, *y2;
+ for (y = glist->gl_list; y2 = y->g_next; y = y2)
+ if (y2 == &scfrom->sc_gobj)
+ {
+ x->sc_gobj.g_next = y2->g_next;
+ y->g_next = &x->sc_gobj;
+ goto nobug;
+ }
+ bug("template_conformscalar");
+ nobug: ;
+ }
+ /* burn the old one */
+ pd_free(&scfrom->sc_gobj.g_pd);
}
else x = scfrom;
scalartemplate = template_findbyname(x->sc_template);
- /* convert all array elements and sublists */
+ /* convert all array elements and sublists */
for (i = 0; i < scalartemplate->t_n; i++)
{
- t_dataslot *ds = scalartemplate->t_vec + i;
- if (ds->ds_type == DT_LIST)
- {
- t_glist *gl2 = x->sc_vec[i].w_list;
- template_conformglist(tfrom, tto, gl2, conformaction);
- }
- else if (ds->ds_type == DT_ARRAY)
- {
- template_conformarray(tfrom, tto, conformaction,
- x->sc_vec[i].w_array);
- }
+ t_dataslot *ds = scalartemplate->t_vec + i;
+ if (ds->ds_type == DT_LIST)
+ {
+ t_glist *gl2 = x->sc_vec[i].w_list;
+ template_conformglist(tfrom, tto, gl2, conformaction);
+ }
+ else if (ds->ds_type == DT_ARRAY)
+ {
+ template_conformarray(tfrom, tto, conformaction,
+ x->sc_vec[i].w_array);
+ }
}
return (x);
}
@@ -351,23 +351,23 @@ static void template_conformarray(t_template *tfrom, t_template *tto,
int i;
if (a->a_templatesym == tfrom->t_sym)
{
- /* the array elements must all be conformed */
- int oldelemsize = sizeof(t_word) * tfrom->t_n,
- newelemsize = sizeof(t_word) * tto->t_n;
- char *newarray = getbytes(sizeof(t_word) * tto->t_n * a->a_n);
- char *oldarray = a->a_vec;
- if (a->a_elemsize != oldelemsize)
- bug("template_conformarray");
- for (i = 0; i < a->a_n; i++)
- {
- t_word *wp = (t_word *)(newarray + newelemsize * i);
- word_init(wp, tto, &a->a_gp);
- template_conformwords(tfrom, tto, conformaction,
- (t_word *)(oldarray + oldelemsize * i), wp);
- }
+ /* the array elements must all be conformed */
+ int oldelemsize = sizeof(t_word) * tfrom->t_n,
+ newelemsize = sizeof(t_word) * tto->t_n;
+ char *newarray = getbytes(sizeof(t_word) * tto->t_n * a->a_n);
+ char *oldarray = a->a_vec;
+ if (a->a_elemsize != oldelemsize)
+ bug("template_conformarray");
+ for (i = 0; i < a->a_n; i++)
+ {
+ t_word *wp = (t_word *)(newarray + newelemsize * i);
+ word_init(wp, tto, &a->a_gp);
+ template_conformwords(tfrom, tto, conformaction,
+ (t_word *)(oldarray + oldelemsize * i), wp);
+ }
}
bug("template_conformarray: this part not written");
- /* go through item by item conforming subarrays and sublists... */
+ /* go through item by item conforming subarrays and sublists... */
}
/* this routine searches for every scalar in the glist that belongs
@@ -382,11 +382,11 @@ static void template_conformglist(t_template *tfrom, t_template *tto,
/* post("conform glist %s", glist->gl_name->s_name); */
for (g = glist->gl_list; g; g = g->g_next)
{
- if (pd_class(&g->g_pd) == scalar_class)
- g = &template_conformscalar(tfrom, tto, conformaction,
- glist, (t_scalar *)g)->sc_gobj;
- else if (pd_class(&g->g_pd) == canvas_class)
- template_conformglist(tfrom, tto, (t_glist *)g, conformaction);
+ if (pd_class(&g->g_pd) == scalar_class)
+ g = &template_conformscalar(tfrom, tto, conformaction,
+ glist, (t_scalar *)g)->sc_gobj;
+ else if (pd_class(&g->g_pd) == canvas_class)
+ template_conformglist(tfrom, tto, (t_glist *)g, conformaction);
}
}
@@ -394,52 +394,52 @@ static void template_conformglist(t_template *tfrom, t_template *tto,
void template_conform(t_template *tfrom, t_template *tto)
{
int nto = tto->t_n, nfrom = tfrom->t_n, i, j,
- *conformaction = (int *)getbytes(sizeof(int) * nto),
- *conformedfrom = (int *)getbytes(sizeof(int) * nfrom), doit = 0;
+ *conformaction = (int *)getbytes(sizeof(int) * nto),
+ *conformedfrom = (int *)getbytes(sizeof(int) * nfrom), doit = 0;
for (i = 0; i < nto; i++)
- conformaction[i] = -1;
+ conformaction[i] = -1;
for (i = 0; i < nfrom; i++)
- conformedfrom[i] = 0;
+ conformedfrom[i] = 0;
for (i = 0; i < nto; i++)
{
- t_dataslot *dataslot = &tto->t_vec[i];
- for (j = 0; j < nfrom; j++)
- {
- t_dataslot *dataslot2 = &tfrom->t_vec[j];
- if (dataslot_matches(dataslot, dataslot2, 1))
- {
- conformaction[i] = j;
- conformedfrom[j] = 1;
- }
- }
+ t_dataslot *dataslot = &tto->t_vec[i];
+ for (j = 0; j < nfrom; j++)
+ {
+ t_dataslot *dataslot2 = &tfrom->t_vec[j];
+ if (dataslot_matches(dataslot, dataslot2, 1))
+ {
+ conformaction[i] = j;
+ conformedfrom[j] = 1;
+ }
+ }
}
for (i = 0; i < nto; i++)
- if (conformaction[i] < 0)
+ if (conformaction[i] < 0)
{
- t_dataslot *dataslot = &tto->t_vec[i];
- for (j = 0; j < nfrom; j++)
- if (!conformedfrom[j] &&
- dataslot_matches(dataslot, &tfrom->t_vec[j], 1))
- {
- conformaction[i] = j;
- conformedfrom[j] = 1;
- }
+ t_dataslot *dataslot = &tto->t_vec[i];
+ for (j = 0; j < nfrom; j++)
+ if (!conformedfrom[j] &&
+ dataslot_matches(dataslot, &tfrom->t_vec[j], 1))
+ {
+ conformaction[i] = j;
+ conformedfrom[j] = 1;
+ }
}
if (nto != nfrom)
- doit = 1;
+ doit = 1;
else for (i = 0; i < nto; i++)
- if (conformaction[i] != i)
- doit = 1;
+ if (conformaction[i] != i)
+ doit = 1;
if (doit)
{
- t_glist *gl;
- /* post("conforming template '%s' to new structure",
- tfrom->t_sym->s_name);
- for (i = 0; i < nto; i++)
- post("... %d", conformaction[i]); */
- for (gl = canvas_list; gl; gl = gl->gl_next)
- template_conformglist(tfrom, tto, gl, conformaction);
+ t_glist *gl;
+ /* post("conforming template '%s' to new structure",
+ tfrom->t_sym->s_name);
+ for (i = 0; i < nto; i++)
+ post("... %d", conformaction[i]); */
+ for (gl = canvas_list; gl; gl = gl->gl_next)
+ template_conformglist(tfrom, tto, gl, conformaction);
}
freebytes(conformaction, sizeof(int) * nto);
freebytes(conformedfrom, sizeof(int) * nfrom);
@@ -449,7 +449,7 @@ t_template *template_findbyname(t_symbol *s)
{
int i;
if (s == &s_float)
- return (&template_float);
+ return (&template_float);
else return ((t_template *)pd_findbyclass(s, template_class));
}
@@ -457,9 +457,9 @@ t_canvas *template_findcanvas(t_template *template)
{
t_gtemplate *gt;
if (!template)
- bug("template_findcanvas");
+ bug("template_findcanvas");
if (!(gt = template->t_list))
- return (0);
+ return (0);
return (gt->x_owner);
/* return ((t_canvas *)pd_findbyclass(template->t_sym, canvas_class)); */
}
@@ -476,36 +476,36 @@ static void *template_usetemplate(void *dummy, t_symbol *s,
{
t_template *x;
t_symbol *templatesym =
- canvas_makebindsym(atom_getsymbolarg(0, argc, argv));
+ canvas_makebindsym(atom_getsymbolarg(0, argc, argv));
if (!argc)
- return (0);
+ return (0);
argc--; argv++;
- /* check if there's already a template by this name. */
+ /* check if there's already a template by this name. */
if ((x = (t_template *)pd_findbyclass(templatesym, template_class)))
{
- t_template *y = template_new(&s_, argc, argv);
- /* If the new template is the same as the old one,
- there's nothing to do. */
- if (!template_match(x, y))
- {
- /* Are there "struct" objects upholding this template? */
- if (x->t_list)
- {
- /* don't know what to do here! */
- error("%s: template mismatch",
- templatesym->s_name);
- }
- else
- {
- /* conform everyone to the new template */
- template_conform(x, y);
- pd_free(&x->t_pdobj);
- template_new(templatesym, argc, argv);
- }
- }
- pd_free(&y->t_pdobj);
+ t_template *y = template_new(&s_, argc, argv);
+ /* If the new template is the same as the old one,
+ there's nothing to do. */
+ if (!template_match(x, y))
+ {
+ /* Are there "struct" objects upholding this template? */
+ if (x->t_list)
+ {
+ /* don't know what to do here! */
+ error("%s: template mismatch",
+ templatesym->s_name);
+ }
+ else
+ {
+ /* conform everyone to the new template */
+ template_conform(x, y);
+ pd_free(&x->t_pdobj);
+ template_new(templatesym, argc, argv);
+ }
+ }
+ pd_free(&y->t_pdobj);
}
- /* otherwise, just make one. */
+ /* otherwise, just make one. */
else template_new(templatesym, argc, argv);
return (0);
}
@@ -514,17 +514,17 @@ static void *template_usetemplate(void *dummy, t_symbol *s,
void template_free(t_template *x)
{
if (*x->t_sym->s_name)
- pd_unbind(&x->t_pdobj, x->t_sym);
+ pd_unbind(&x->t_pdobj, x->t_sym);
t_freebytes(x->t_vec, x->t_n * sizeof(*x->t_vec));
}
static void template_setup(void)
{
template_class = class_new(gensym("template"), 0, (t_method)template_free,
- sizeof(t_template), CLASS_PD, 0);
+ sizeof(t_template), CLASS_PD, 0);
class_addmethod(pd_canvasmaker, (t_method)template_usetemplate,
- gensym("struct"), A_GIMME, 0);
-
+ gensym("struct"), A_GIMME, 0);
+
}
/* ---------------- gtemplates. One per canvas. ----------- */
@@ -547,46 +547,46 @@ static void *gtemplate_donew(t_symbol *sym, int argc, t_atom *argv)
x->x_argc = argc;
x->x_argv = (t_atom *)getbytes(argc * sizeof(t_atom));
for (i = 0; i < argc; i++)
- x->x_argv[i] = argv[i];
+ x->x_argv[i] = argv[i];
- /* already have a template by this name? */
+ /* already have a template by this name? */
if (t)
{
- x->x_template = t;
- /* if it's already got a "struct" or "gtemplate" object we
- just tack this one to the end of the list and leave it
- there. */
- if (t->t_list)
- {
- t_gtemplate *x2, *x3;
- for (x2 = x->x_template->t_list; x3 = x2->x_next; x2 = x3)
- ;
- x2->x_next = x;
- post("template %s: warning: already exists.", sym->s_name);
- }
- else
- {
- /* if there's none, we just replace the template with
- our own and conform it. */
- t_template *y = template_new(&s_, argc, argv);
- /* Unless the new template is different from the old one,
- there's nothing to do. */
- if (!template_match(t, y))
- {
- /* conform everyone to the new template */
- template_conform(t, y);
- pd_free(&t->t_pdobj);
- t = template_new(sym, argc, argv);
- }
- pd_free(&y->t_pdobj);
- t->t_list = x;
- }
+ x->x_template = t;
+ /* if it's already got a "struct" or "gtemplate" object we
+ just tack this one to the end of the list and leave it
+ there. */
+ if (t->t_list)
+ {
+ t_gtemplate *x2, *x3;
+ for (x2 = x->x_template->t_list; x3 = x2->x_next; x2 = x3)
+ ;
+ x2->x_next = x;
+ post("template %s: warning: already exists.", sym->s_name);
+ }
+ else
+ {
+ /* if there's none, we just replace the template with
+ our own and conform it. */
+ t_template *y = template_new(&s_, argc, argv);
+ /* Unless the new template is different from the old one,
+ there's nothing to do. */
+ if (!template_match(t, y))
+ {
+ /* conform everyone to the new template */
+ template_conform(t, y);
+ pd_free(&t->t_pdobj);
+ t = template_new(sym, argc, argv);
+ }
+ pd_free(&y->t_pdobj);
+ t->t_list = x;
+ }
}
else
{
- /* otherwise make a new one and we're the only struct on it. */
- x->x_template = t = template_new(sym, argc, argv);
- t->t_list = x;
+ /* otherwise make a new one and we're the only struct on it. */
+ x->x_template = t = template_new(sym, argc, argv);
+ t->t_list = x;
}
return (x);
}
@@ -596,7 +596,7 @@ static void *gtemplate_new(t_symbol *s, int argc, t_atom *argv)
t_gtemplate *x = (t_gtemplate *)pd_new(gtemplate_class);
t_symbol *sym = atom_getsymbolarg(0, argc, argv);
if (argc >= 1)
- argc--; argv++;
+ argc--; argv++;
return (gtemplate_donew(canvas_makebindsym(sym), argc, argv));
}
@@ -608,9 +608,9 @@ static void *gtemplate_new_old(t_symbol *s, int argc, t_atom *argv)
static int warned;
if (!warned)
{
- post("warning -- 'template' (%s) is obsolete; replace with 'struct'",
- sym->s_name);
- warned = 1;
+ post("warning -- 'template' (%s) is obsolete; replace with 'struct'",
+ sym->s_name);
+ warned = 1;
}
return (gtemplate_donew(sym, argc, argv));
}
@@ -622,35 +622,35 @@ t_template *gtemplate_get(t_gtemplate *x)
static void gtemplate_free(t_gtemplate *x)
{
- /* get off the template's list */
+ /* get off the template's list */
t_template *t = x->x_template;
if (x == t->t_list)
{
- if (x->x_next)
- {
- /* if we were first on the list, and there are others on
- the list, make a new template corresponding to the new
- first-on-list and replace teh existing template with it. */
- t_template *z = template_new(&s_, x->x_argc, x->x_argv);
- template_conform(t, z);
- pd_free(&t->t_pdobj);
- pd_free(&z->t_pdobj);
- z = template_new(x->x_sym, x->x_argc, x->x_argv);
- z->t_list = x->x_next;
- }
- else t->t_list = 0;
+ if (x->x_next)
+ {
+ /* if we were first on the list, and there are others on
+ the list, make a new template corresponding to the new
+ first-on-list and replace teh existing template with it. */
+ t_template *z = template_new(&s_, x->x_argc, x->x_argv);
+ template_conform(t, z);
+ pd_free(&t->t_pdobj);
+ pd_free(&z->t_pdobj);
+ z = template_new(x->x_sym, x->x_argc, x->x_argv);
+ z->t_list = x->x_next;
+ }
+ else t->t_list = 0;
}
else
{
- t_gtemplate *x2, *x3;
- for (x2 = t->t_list; x3 = x2->x_next; x2 = x3)
- {
- if (x == x3)
- {
- x2->x_next = x3->x_next;
- break;
- }
- }
+ t_gtemplate *x2, *x3;
+ for (x2 = t->t_list; x3 = x2->x_next; x2 = x3)
+ {
+ if (x == x3)
+ {
+ x2->x_next = x3->x_next;
+ break;
+ }
+ }
}
freebytes(x->x_argv, sizeof(t_atom) * x->x_argc);
}
@@ -658,10 +658,10 @@ static void gtemplate_free(t_gtemplate *x)
static void gtemplate_setup(void)
{
gtemplate_class = class_new(gensym("struct"),
- (t_newmethod)gtemplate_new, (t_method)gtemplate_free,
- sizeof(t_gtemplate), CLASS_NOINLET, A_GIMME, 0);
+ (t_newmethod)gtemplate_new, (t_method)gtemplate_free,
+ sizeof(t_gtemplate), CLASS_NOINLET, A_GIMME, 0);
class_addcreator((t_newmethod)gtemplate_new_old, gensym("template"),
- A_GIMME, 0);
+ A_GIMME, 0);
}
/* --------------- FIELD DESCRIPTORS ---------------------- */
@@ -674,13 +674,13 @@ every single time we draw the object.
typedef struct _fielddesc
{
- char fd_type; /* LATER consider removing this? */
+ char fd_type; /* LATER consider removing this? */
char fd_var;
union
{
- t_float fd_float; /* the field is a constant float */
- t_symbol *fd_symbol; /* the field is a constant symbol */
- t_symbol *fd_varsym; /* the field is variable and this is the name */
+ t_float fd_float; /* the field is a constant float */
+ t_symbol *fd_symbol; /* the field is a constant symbol */
+ t_symbol *fd_varsym; /* the field is variable and this is the name */
} fd_un;
} t_fielddesc;
@@ -693,22 +693,22 @@ typedef struct _fielddesc
#define CLOSED 1
#define BEZ 2
-#define A_ARRAY 55 /* LATER decide whether to enshrine this in m_pd.h */
+#define A_ARRAY 55 /* LATER decide whether to enshrine this in m_pd.h */
static void fielddesc_setfloatarg(t_fielddesc *fd, int argc, t_atom *argv)
{
- if (argc <= 0) FIELDDESC_SETFLOAT(fd, 0);
- else if (argv->a_type == A_SYMBOL)
- FIELDDESC_SETVAR(fd, argv->a_w.w_symbol, A_FLOAT);
- else FIELDDESC_SETFLOAT(fd, argv->a_w.w_float);
+ if (argc <= 0) FIELDDESC_SETFLOAT(fd, 0);
+ else if (argv->a_type == A_SYMBOL)
+ FIELDDESC_SETVAR(fd, argv->a_w.w_symbol, A_FLOAT);
+ else FIELDDESC_SETFLOAT(fd, argv->a_w.w_float);
}
static void fielddesc_setarrayarg(t_fielddesc *fd, int argc, t_atom *argv)
{
- if (argc <= 0) FIELDDESC_SETFLOAT(fd, 0);
- else if (argv->a_type == A_SYMBOL)
- FIELDDESC_SETVAR(fd, argv->a_w.w_symbol, A_ARRAY);
- else FIELDDESC_SETFLOAT(fd, argv->a_w.w_float);
+ if (argc <= 0) FIELDDESC_SETFLOAT(fd, 0);
+ else if (argv->a_type == A_SYMBOL)
+ FIELDDESC_SETVAR(fd, argv->a_w.w_symbol, A_ARRAY);
+ else FIELDDESC_SETFLOAT(fd, argv->a_w.w_float);
}
static t_float fielddesc_getfloat(t_fielddesc *f, t_template *template,
@@ -716,15 +716,15 @@ static t_float fielddesc_getfloat(t_fielddesc *f, t_template *template,
{
if (f->fd_type == A_FLOAT)
{
- if (f->fd_var)
- return (template_getfloat(template, f->fd_un.fd_varsym, wp, loud));
- else return (f->fd_un.fd_float);
+ if (f->fd_var)
+ return (template_getfloat(template, f->fd_un.fd_varsym, wp, loud));
+ else return (f->fd_un.fd_float);
}
else
{
- if (loud)
- error("symbolic data field used as number");
- return (0);
+ if (loud)
+ error("symbolic data field used as number");
+ return (0);
}
}
@@ -733,15 +733,15 @@ static t_symbol *fielddesc_getsymbol(t_fielddesc *f, t_template *template,
{
if (f->fd_type == A_SYMBOL)
{
- if (f->fd_var)
- return(template_getsymbol(template, f->fd_un.fd_varsym, wp, loud));
- else return (f->fd_un.fd_symbol);
+ if (f->fd_var)
+ return(template_getsymbol(template, f->fd_un.fd_varsym, wp, loud));
+ else return (f->fd_un.fd_symbol);
}
else
{
- if (loud)
- error("numeric data field used as symbol");
- return (&s_);
+ if (loud)
+ error("numeric data field used as symbol");
+ return (&s_);
}
}
@@ -758,7 +758,7 @@ t_class *curve_class;
typedef struct _curve
{
t_object x_obj;
- int x_flags; /* CLOSED and/or BEZ */
+ int x_flags; /* CLOSED and/or BEZ */
t_fielddesc x_fillcolor;
t_fielddesc x_outlinecolor;
t_fielddesc x_width;
@@ -775,10 +775,10 @@ static void *curve_new(t_symbol *classsym, t_int argc, t_atom *argv)
t_fielddesc *fd;
if (classname[0] == 'f')
{
- classname += 6;
- flags |= CLOSED;
- if (argc) fielddesc_setfloatarg(&x->x_fillcolor, argc--, argv++);
- else FIELDDESC_SETFLOAT(&x->x_outlinecolor, 0);
+ classname += 6;
+ flags |= CLOSED;
+ if (argc) fielddesc_setfloatarg(&x->x_fillcolor, argc--, argv++);
+ else FIELDDESC_SETFLOAT(&x->x_outlinecolor, 0);
}
else classname += 4;
if (classname[0] == 'c') flags |= BEZ;
@@ -792,7 +792,7 @@ static void *curve_new(t_symbol *classsym, t_int argc, t_atom *argv)
x->x_npoints = (nxy>>1);
x->x_vec = (t_fielddesc *)t_getbytes(nxy * sizeof(t_fielddesc));
for (i = 0, fd = x->x_vec; i < argc; i++, fd++, argv++)
- fielddesc_setfloatarg(fd, 1, argv);
+ fielddesc_setfloatarg(fd, 1, argv);
if (argc & 1) FIELDDESC_SETFLOAT(fd, 0);
return (x);
@@ -810,14 +810,14 @@ static void curve_getrect(t_gobj *z, t_glist *glist,
int x1 = 0x7fffffff, x2 = -0x7fffffff, y1 = 0x7fffffff, y2 = -0x7fffffff;
for (i = 0, f = x->x_vec; i < n; i++, f += 2)
{
- int xloc = glist_xtopixels(glist,
- basex + fielddesc_getfloat(f, template, data, 0));
- int yloc = glist_ytopixels(glist,
- basey + fielddesc_getfloat(f+1, template, data, 0));
- if (xloc < x1) x1 = xloc;
- if (xloc > x2) x2 = xloc;
- if (yloc < y1) y1 = yloc;
- if (yloc > y2) y2 = yloc;
+ int xloc = glist_xtopixels(glist,
+ basex + fielddesc_getfloat(f, template, data, 0));
+ int yloc = glist_ytopixels(glist,
+ basey + fielddesc_getfloat(f+1, template, data, 0));
+ if (xloc < x1) x1 = xloc;
+ if (xloc > x2) x2 = xloc;
+ if (yloc < y1) y1 = yloc;
+ if (yloc > y2) y2 = yloc;
}
*xp1 = x1;
*yp1 = y1;
@@ -846,10 +846,10 @@ static void curve_activate(t_gobj *z, t_glist *glist,
/* fill in later */
}
-static int rangecolor(int n) /* 0 to 9 in 5 steps */
+static int rangecolor(int n) /* 0 to 9 in 5 steps */
{
- int n2 = n/2; /* 0 to 4 */
- int ret = (n << 6); /* 0 to 256 in 5 steps */
+ int n2 = n/2; /* 0 to 4 */
+ int ret = (n2 << 6); /* 0 to 256 in 5 steps */
if (ret > 255) ret = 255;
return (ret);
}
@@ -862,7 +862,7 @@ static void numbertocolor(int n, char *s)
blue = ((n / 10) % 10);
green = n % 10;
sprintf(s, "#%2.2x%2.2x%2.2x", rangecolor(red), rangecolor(blue),
- rangecolor(green));
+ rangecolor(green));
}
static void curve_vis(t_gobj *z, t_glist *glist,
@@ -875,47 +875,47 @@ static void curve_vis(t_gobj *z, t_glist *glist,
if (vis)
{
- if (n > 1)
- {
- int flags = x->x_flags, closed = (flags & CLOSED);
- float width = fielddesc_getfloat(&x->x_width, template, data, 1);
- char outline[20], fill[20];
- if (width < 1) width = 1;
- numbertocolor(
- fielddesc_getfloat(&x->x_outlinecolor, template, data, 1),
- outline);
- if (flags & CLOSED)
- {
- numbertocolor(
- fielddesc_getfloat(&x->x_fillcolor, template, data, 1),
- fill);
- sys_vgui(".x%x.c create polygon\\\n",
- glist_getcanvas(glist));
- }
- else sys_vgui(".x%x.c create line\\\n",
- glist_getcanvas(glist));
- for (i = 0, f = x->x_vec; i < n; i++, f += 2)
- {
- float xloc = glist_xtopixels(glist,
- basex + fielddesc_getfloat(f, template, data, 1));
- float yloc = glist_ytopixels(glist,
- basey + fielddesc_getfloat(f+1, template, data, 1));
- sys_vgui("%d %d\\\n", (int)xloc, (int)yloc);
- }
- sys_vgui("-width %f\\\n",
- fielddesc_getfloat(&x->x_width, template, data, 1));
- if (flags & CLOSED) sys_vgui("-fill %s -outline %s\\\n",
- fill, outline);
- else sys_vgui("-fill %s\\\n", outline);
- if (flags & BEZ) sys_vgui("-smooth 1\\\n");
- sys_vgui("-tags curve%x\n", data);
- }
- else post("warning: curves need at least two points to be graphed");
+ if (n > 1)
+ {
+ int flags = x->x_flags, closed = (flags & CLOSED);
+ float width = fielddesc_getfloat(&x->x_width, template, data, 1);
+ char outline[20], fill[20];
+ if (width < 1) width = 1;
+ numbertocolor(
+ fielddesc_getfloat(&x->x_outlinecolor, template, data, 1),
+ outline);
+ if (flags & CLOSED)
+ {
+ numbertocolor(
+ fielddesc_getfloat(&x->x_fillcolor, template, data, 1),
+ fill);
+ sys_vgui(".x%lx.c create polygon\\\n",
+ glist_getcanvas(glist));
+ }
+ else sys_vgui(".x%lx.c create line\\\n",
+ glist_getcanvas(glist));
+ for (i = 0, f = x->x_vec; i < n; i++, f += 2)
+ {
+ float xloc = glist_xtopixels(glist,
+ basex + fielddesc_getfloat(f, template, data, 1));
+ float yloc = glist_ytopixels(glist,
+ basey + fielddesc_getfloat(f+1, template, data, 1));
+ sys_vgui("%d %d\\\n", (int)xloc, (int)yloc);
+ }
+ sys_vgui("-width %f\\\n",
+ fielddesc_getfloat(&x->x_width, template, data, 1));
+ if (flags & CLOSED) sys_vgui("-fill %s -outline %s\\\n",
+ fill, outline);
+ else sys_vgui("-fill %s\\\n", outline);
+ if (flags & BEZ) sys_vgui("-smooth 1\\\n");
+ sys_vgui("-tags curve%lx\n", data);
+ }
+ else post("warning: curves need at least two points to be graphed");
}
else
{
- if (n > 1) sys_vgui(".x%x.c delete curve%x\n",
- glist_getcanvas(glist), data);
+ if (n > 1) sys_vgui(".x%lx.c delete curve%lx\n",
+ glist_getcanvas(glist), data);
}
}
@@ -942,19 +942,19 @@ static void curve_motion(void *z, t_floatarg dx, t_floatarg dy)
curve_motion_ycumulative += dy;
if (f->fd_var)
{
- template_setfloat(curve_motion_template,
- f->fd_un.fd_varsym,
- curve_motion_wp,
- curve_motion_xbase + curve_motion_xcumulative * curve_motion_xper,
- 1);
+ template_setfloat(curve_motion_template,
+ f->fd_un.fd_varsym,
+ curve_motion_wp,
+ curve_motion_xbase + curve_motion_xcumulative * curve_motion_xper,
+ 1);
}
if ((f+1)->fd_var)
{
- template_setfloat(curve_motion_template,
- (f+1)->fd_un.fd_varsym,
- curve_motion_wp,
- curve_motion_ybase + curve_motion_ycumulative * curve_motion_yper,
- 1);
+ template_setfloat(curve_motion_template,
+ (f+1)->fd_un.fd_varsym,
+ curve_motion_wp,
+ curve_motion_ybase + curve_motion_ycumulative * curve_motion_yper,
+ 1);
}
glist_redrawitem(curve_motion_glist, curve_motion_gobj);
}
@@ -971,42 +971,42 @@ static int curve_click(t_gobj *z, t_glist *glist,
t_word *data = sc->sc_vec;
for (i = 0, f = x->x_vec; i < n; i++, f += 2)
{
- int xloc = glist_xtopixels(glist,
- basex + fielddesc_getfloat(f, template, data, 0));
- int yloc = glist_ytopixels(glist,
- basey + fielddesc_getfloat(f+1, template, data, 0));
- int xerr = xloc - xpix, yerr = yloc - ypix;
- if (!f->fd_var && !(f+1)->fd_var)
- continue;
- if (xerr < 0)
- xerr = -xerr;
- if (yerr < 0)
- yerr = -yerr;
- if (yerr > xerr)
- xerr = yerr;
- if (xerr < besterror)
- {
- besterror = xerr;
- bestn = i;
- curve_motion_xbase = fielddesc_getfloat(f, template, data, 0);
- curve_motion_ybase = fielddesc_getfloat(f+1, template, data, 0);
- }
+ int xloc = glist_xtopixels(glist,
+ basex + fielddesc_getfloat(f, template, data, 0));
+ int yloc = glist_ytopixels(glist,
+ basey + fielddesc_getfloat(f+1, template, data, 0));
+ int xerr = xloc - xpix, yerr = yloc - ypix;
+ if (!f->fd_var && !(f+1)->fd_var)
+ continue;
+ if (xerr < 0)
+ xerr = -xerr;
+ if (yerr < 0)
+ yerr = -yerr;
+ if (yerr > xerr)
+ xerr = yerr;
+ if (xerr < besterror)
+ {
+ besterror = xerr;
+ bestn = i;
+ curve_motion_xbase = fielddesc_getfloat(f, template, data, 0);
+ curve_motion_ybase = fielddesc_getfloat(f+1, template, data, 0);
+ }
}
if (besterror > 10)
- return (0);
+ return (0);
if (doit)
{
- curve_motion_xper = glist_pixelstox(glist, 1)
- - glist_pixelstox(glist, 0);
- curve_motion_yper = glist_pixelstoy(glist, 1)
- - glist_pixelstoy(glist, 0);
- curve_motion_xcumulative = curve_motion_ycumulative = 0;
- curve_motion_glist = glist;
- curve_motion_gobj = &sc->sc_gobj;
- curve_motion_wp = data;
- curve_motion_field = 2*bestn;
- curve_motion_template = template;
- glist_grab(glist, z, curve_motion, 0, xpix, ypix);
+ curve_motion_xper = glist_pixelstox(glist, 1)
+ - glist_pixelstox(glist, 0);
+ curve_motion_yper = glist_pixelstoy(glist, 1)
+ - glist_pixelstoy(glist, 0);
+ curve_motion_xcumulative = curve_motion_ycumulative = 0;
+ curve_motion_glist = glist;
+ curve_motion_gobj = &sc->sc_gobj;
+ curve_motion_wp = data;
+ curve_motion_field = 2*bestn;
+ curve_motion_template = template;
+ glist_grab(glist, z, curve_motion, 0, xpix, ypix);
}
return (1);
}
@@ -1029,14 +1029,14 @@ static void curve_free(t_curve *x)
static void curve_setup(void)
{
curve_class = class_new(gensym("drawpolygon"), (t_newmethod)curve_new,
- (t_method)curve_free, sizeof(t_curve), CLASS_NOINLET, A_GIMME, 0);
+ (t_method)curve_free, sizeof(t_curve), CLASS_NOINLET, A_GIMME, 0);
class_setdrawcommand(curve_class);
class_addcreator((t_newmethod)curve_new, gensym("drawcurve"),
- A_GIMME, 0);
+ A_GIMME, 0);
class_addcreator((t_newmethod)curve_new, gensym("filledpolygon"),
- A_GIMME, 0);
+ A_GIMME, 0);
class_addcreator((t_newmethod)curve_new, gensym("filledcurve"),
- A_GIMME, 0);
+ A_GIMME, 0);
class_setparentwidget(curve_class, &curve_widgetbehavior);
}
@@ -1065,8 +1065,8 @@ static void *plot_new(t_symbol *classsym, t_int argc, t_atom *argv)
t_symbol *firstarg = atom_getsymbolarg(0, argc, argv);
if (!strcmp(firstarg->s_name, "curve"))
{
- flags |= BEZ;
- argc--, argv++;
+ flags |= BEZ;
+ argc--, argv++;
}
if (argc) fielddesc_setarrayarg(&x->x_data, argc--, argv++);
else FIELDDESC_SETFLOAT(&x->x_data, 1);
@@ -1098,22 +1098,22 @@ static int plot_readownertemplate(t_plot *x,
t_symbol *elemtemplatesym;
t_array *array;
- /* find the data and verify it's an array */
+ /* find the data and verify it's an array */
if (x->x_data.fd_type != A_ARRAY || !x->x_data.fd_var)
{
- error("plot: needs an array field");
- return (-1);
+ error("plot: needs an array field");
+ return (-1);
}
if (!template_find_field(ownertemplate, x->x_data.fd_un.fd_varsym,
- &arrayonset, &type, &elemtemplatesym))
+ &arrayonset, &type, &elemtemplatesym))
{
- error("plot: %s: no such field", x->x_data.fd_un.fd_varsym->s_name);
- return (-1);
+ error("plot: %s: no such field", x->x_data.fd_un.fd_varsym->s_name);
+ return (-1);
}
if (type != DT_ARRAY)
{
- error("plot: %s: not an array", x->x_data.fd_un.fd_varsym->s_name);
- return (-1);
+ error("plot: %s: not an array", x->x_data.fd_un.fd_varsym->s_name);
+ return (-1);
}
array = *(t_array **)(((char *)data) + arrayonset);
*linewidthp = fielddesc_getfloat(&x->x_width, ownertemplate, data, 1);
@@ -1137,33 +1137,33 @@ int array_getfields(t_symbol *elemtemplatesym,
t_symbol *dummy;
t_canvas *elemtemplatecanvas = 0;
- /* the "float" template is special in not having to have a canvas;
- template_findbyname is hardwired to return a predefined
- template. */
+ /* the "float" template is special in not having to have a canvas;
+ template_findbyname is hardwired to return a predefined
+ template. */
if (!(elemtemplate = template_findbyname(elemtemplatesym)))
{
- error("plot: %s: no such template", elemtemplatesym->s_name);
- return (-1);
+ error("plot: %s: no such template", elemtemplatesym->s_name);
+ return (-1);
}
if (!((elemtemplatesym == &s_float) ||
- (elemtemplatecanvas = template_findcanvas(elemtemplate))))
+ (elemtemplatecanvas = template_findcanvas(elemtemplate))))
{
- error("plot: %s: no canvas for this template", elemtemplatesym->s_name);
- return (-1);
+ error("plot: %s: no canvas for this template", elemtemplatesym->s_name);
+ return (-1);
}
elemsize = elemtemplate->t_n * sizeof(t_word);
if (!template_find_field(elemtemplate, gensym("y"), &yonset, &type, &dummy)
- || type != DT_FLOAT)
- yonset = -1;
+ || type != DT_FLOAT)
+ yonset = -1;
if (!template_find_field(elemtemplate, gensym("x"), &xonset, &type, &dummy)
- || type != DT_FLOAT)
- xonset = -1;
+ || type != DT_FLOAT)
+ xonset = -1;
if (!template_find_field(elemtemplate, gensym("w"), &wonset, &type, &dummy)
- || type != DT_FLOAT)
- wonset = -1;
+ || type != DT_FLOAT)
+ wonset = -1;
- /* fill in slots for return values */
+ /* fill in slots for return values */
*elemtemplatecanvasp = elemtemplatecanvas;
*elemtemplatep = elemtemplate;
*elemsizep = elemsize;
@@ -1189,24 +1189,24 @@ static void plot_getrect(t_gobj *z, t_glist *glist,
float xpix, ypix, wpix;
if (!plot_readownertemplate(x, data, template,
- &elemtemplatesym, &array, &linewidth, &xloc, &xinc, &yloc) &&
- !array_getfields(elemtemplatesym, &elemtemplatecanvas,
- &elemtemplate, &elemsize, &xonset, &yonset, &wonset))
+ &elemtemplatesym, &array, &linewidth, &xloc, &xinc, &yloc) &&
+ !array_getfields(elemtemplatesym, &elemtemplatecanvas,
+ &elemtemplate, &elemsize, &xonset, &yonset, &wonset))
{
- for (i = 0; i < array->a_n; i++)
- {
- array_getcoordinate(glist, (char *)(array->a_vec) + i * elemsize,
- xonset, yonset, wonset, i, basex + xloc, basey + yloc, xinc,
- &xpix, &ypix, &wpix);
- if (xpix < x1)
- x1 = xpix;
- if (xpix > x2)
- x2 = xpix;
- if (ypix - wpix < y1)
- y1 = ypix - wpix;
- if (ypix + wpix > y2)
- y2 = ypix + wpix;
- }
+ for (i = 0; i < array->a_n; i++)
+ {
+ array_getcoordinate(glist, (char *)(array->a_vec) + i * elemsize,
+ xonset, yonset, wonset, i, basex + xloc, basey + yloc, xinc,
+ &xpix, &ypix, &wpix);
+ if (xpix < x1)
+ x1 = xpix;
+ if (xpix > x2)
+ x2 = xpix;
+ if (ypix - wpix < y1)
+ y1 = ypix - wpix;
+ if (ypix + wpix > y2)
+ y2 = ypix + wpix;
+ }
}
*xp1 = x1;
@@ -1219,7 +1219,7 @@ static void plot_displace(t_gobj *z, t_glist *glist,
t_word *data, t_template *template, float basex, float basey,
int dx, int dy)
{
- /* not yet */
+ /* not yet */
}
static void plot_select(t_gobj *z, t_glist *glist,
@@ -1233,7 +1233,7 @@ static void plot_activate(t_gobj *z, t_glist *glist,
t_word *data, t_template *template, float basex, float basey,
int state)
{
- /* not yet */
+ /* not yet */
}
static void plot_vis(t_gobj *z, t_glist *glist,
@@ -1250,171 +1250,171 @@ static void plot_vis(t_gobj *z, t_glist *glist,
int nelem;
char *elem;
if (plot_readownertemplate(x, data, template,
- &elemtemplatesym, &array, &linewidth, &xloc, &xinc, &yloc) ||
- array_getfields(elemtemplatesym, &elemtemplatecanvas,
- &elemtemplate, &elemsize, &xonset, &yonset, &wonset))
- return;
+ &elemtemplatesym, &array, &linewidth, &xloc, &xinc, &yloc) ||
+ array_getfields(elemtemplatesym, &elemtemplatecanvas,
+ &elemtemplate, &elemsize, &xonset, &yonset, &wonset))
+ return;
nelem = array->a_n;
elem = (char *)array->a_vec;
if (vis)
- {
- char outline[20];
- int lastpixel = -1, ndrawn = 0;
- float xsum, yval = 0, wval = 0, xpix;
- int ixpix = 0, i;
-
- /* draw the trace */
- numbertocolor(fielddesc_getfloat(&x->x_outlinecolor, template, data, 1),
- outline);
- if (wonset >= 0)
- {
- /* found "w" field which controls linewidth. The trace is
- a filled polygon with 2n points. */
- sys_vgui(".x%x.c create polygon \\\n",
- glist_getcanvas(glist));
-
- for (i = 0, xsum = xloc; i < nelem; i++)
- {
- float usexloc;
- if (xonset >= 0)
- usexloc = xloc + *(float *)((elem + elemsize * i) + xonset);
- else usexloc = xsum, xsum += xinc;
- if (yonset >= 0)
- yval = *(float *)((elem + elemsize * i) + yonset);
- else yval = 0;
- wval = *(float *)((elem + elemsize * i) + wonset);
- xpix = glist_xtopixels(glist, basex + usexloc);
- ixpix = xpix + 0.5;
- if (xonset >= 0 || ixpix != lastpixel)
- {
- sys_vgui("%d %f \\\n", ixpix,
- glist_ytopixels(glist,
- basey + yloc + yval - wval));
- ndrawn++;
- }
- lastpixel = ixpix;
- if (ndrawn >= 1000) goto ouch;
- }
- lastpixel = -1;
- for (i = nelem-1; i >= 0; i--)
- {
- float usexloc;
- if (xonset >= 0)
- usexloc = xloc + *(float *)((elem + elemsize * i) + xonset);
- else xsum -= xinc, usexloc = xsum;
- if (yonset >= 0)
- yval = *(float *)((elem + elemsize * i) + yonset);
- else yval = 0;
- wval = *(float *)((elem + elemsize * i) + wonset);
- xpix = glist_xtopixels(glist, basex + usexloc);
- ixpix = xpix + 0.5;
- if (xonset >= 0 || ixpix != lastpixel)
- {
- sys_vgui("%d %f \\\n", ixpix, glist_ytopixels(glist,
- basey + yloc + yval + wval));
- ndrawn++;
- }
- lastpixel = ixpix;
- if (ndrawn >= 1000) goto ouch;
- }
- /* TK will complain if there aren't at least 3 points. There
- should be at least two already. */
- if (ndrawn < 4)
- {
- sys_vgui("%d %f \\\n", ixpix + 10, glist_ytopixels(glist,
- basey + yloc + yval + wval));
- sys_vgui("%d %f \\\n", ixpix + 10, glist_ytopixels(glist,
- basey + yloc + yval - wval));
- }
- ouch:
- sys_vgui(" -width 1 -fill %s -outline %s\\\n", outline, outline);
- if (x->x_flags & BEZ) sys_vgui("-smooth 1\\\n");
-
- sys_vgui("-tags plot%x\n", data);
- }
- else if (linewidth > 0)
- {
- /* no "w" field. If the linewidth is positive, draw a
- segmented line with the requested width; otherwise don't
- draw the trace at all. */
- sys_vgui(".x%x.c create line \\\n", glist_getcanvas(glist));
-
- for (xsum = xloc, i = 0; i < nelem; i++)
- {
- float usexloc;
- if (xonset >= 0)
- usexloc = xloc + *(float *)((elem + elemsize * i) + xonset);
- else usexloc = xsum, xsum += xinc;
- if (yonset >= 0)
- yval = *(float *)((elem + elemsize * i) + yonset);
- else yval = 0;
- xpix = glist_xtopixels(glist, basex + usexloc);
- ixpix = xpix + 0.5;
- if (xonset >= 0 || ixpix != lastpixel)
- {
- sys_vgui("%d %f \\\n", ixpix,
- glist_ytopixels(glist, basey + yloc + yval));
- ndrawn++;
- }
- lastpixel = ixpix;
- if (ndrawn >= 1000) break;
- }
- /* TK will complain if there aren't at least 2 points... */
- if (ndrawn == 0) sys_vgui("0 0 0 0 \\\n");
- else if (ndrawn == 1) sys_vgui("%d %f \\\n", ixpix + 10,
- glist_ytopixels(glist, basey + yloc + yval));
-
- sys_vgui("-width %f\\\n", linewidth);
- sys_vgui("-fill %s\\\n", outline);
- if (x->x_flags & BEZ) sys_vgui("-smooth 1\\\n");
-
- sys_vgui("-tags plot%x\n", data);
- }
- /* We're done with the outline; now draw all the points.
- This code is inefficient since the template has to be
- searched for drawing instructions for every last point. */
-
- for (xsum = xloc, i = 0; i < nelem; i++)
- {
- float usexloc, useyloc;
- t_gobj *y;
- if (xonset >= 0)
- usexloc = basex + xloc +
- *(float *)((elem + elemsize * i) + xonset);
- else usexloc = basex + xsum, xsum += xinc;
- if (yonset >= 0)
- yval = *(float *)((elem + elemsize * i) + yonset);
- else yval = 0;
- useyloc = basey + yloc + yval;
- for (y = elemtemplatecanvas->gl_list; y; y = y->g_next)
- {
- t_parentwidgetbehavior *wb = pd_getparentwidget(&y->g_pd);
- if (!wb) continue;
- (*wb->w_parentvisfn)(y, glist,
- (t_word *)(elem + elemsize * i),
- elemtemplate, usexloc, useyloc, vis);
- }
- }
+ {
+ char outline[20];
+ int lastpixel = -1, ndrawn = 0;
+ float xsum, yval = 0, wval = 0, xpix;
+ int ixpix = 0, i;
+
+ /* draw the trace */
+ numbertocolor(fielddesc_getfloat(&x->x_outlinecolor, template, data, 1),
+ outline);
+ if (wonset >= 0)
+ {
+ /* found "w" field which controls linewidth. The trace is
+ a filled polygon with 2n points. */
+ sys_vgui(".x%lx.c create polygon \\\n",
+ glist_getcanvas(glist));
+
+ for (i = 0, xsum = xloc; i < nelem; i++)
+ {
+ float usexloc;
+ if (xonset >= 0)
+ usexloc = xloc + *(float *)((elem + elemsize * i) + xonset);
+ else usexloc = xsum, xsum += xinc;
+ if (yonset >= 0)
+ yval = *(float *)((elem + elemsize * i) + yonset);
+ else yval = 0;
+ wval = *(float *)((elem + elemsize * i) + wonset);
+ xpix = glist_xtopixels(glist, basex + usexloc);
+ ixpix = xpix + 0.5;
+ if (xonset >= 0 || ixpix != lastpixel)
+ {
+ sys_vgui("%d %f \\\n", ixpix,
+ glist_ytopixels(glist,
+ basey + yloc + yval - wval));
+ ndrawn++;
+ }
+ lastpixel = ixpix;
+ if (ndrawn >= 1000) goto ouch;
+ }
+ lastpixel = -1;
+ for (i = nelem-1; i >= 0; i--)
+ {
+ float usexloc;
+ if (xonset >= 0)
+ usexloc = xloc + *(float *)((elem + elemsize * i) + xonset);
+ else xsum -= xinc, usexloc = xsum;
+ if (yonset >= 0)
+ yval = *(float *)((elem + elemsize * i) + yonset);
+ else yval = 0;
+ wval = *(float *)((elem + elemsize * i) + wonset);
+ xpix = glist_xtopixels(glist, basex + usexloc);
+ ixpix = xpix + 0.5;
+ if (xonset >= 0 || ixpix != lastpixel)
+ {
+ sys_vgui("%d %f \\\n", ixpix, glist_ytopixels(glist,
+ basey + yloc + yval + wval));
+ ndrawn++;
+ }
+ lastpixel = ixpix;
+ if (ndrawn >= 1000) goto ouch;
+ }
+ /* TK will complain if there aren't at least 3 points. There
+ should be at least two already. */
+ if (ndrawn < 4)
+ {
+ sys_vgui("%d %f \\\n", ixpix + 10, glist_ytopixels(glist,
+ basey + yloc + yval + wval));
+ sys_vgui("%d %f \\\n", ixpix + 10, glist_ytopixels(glist,
+ basey + yloc + yval - wval));
+ }
+ ouch:
+ sys_vgui(" -width 1 -fill %s -outline %s\\\n", outline, outline);
+ if (x->x_flags & BEZ) sys_vgui("-smooth 1\\\n");
+
+ sys_vgui("-tags plot%lx\n", data);
+ }
+ else if (linewidth > 0)
+ {
+ /* no "w" field. If the linewidth is positive, draw a
+ segmented line with the requested width; otherwise don't
+ draw the trace at all. */
+ sys_vgui(".x%lx.c create line \\\n", glist_getcanvas(glist));
+
+ for (xsum = xloc, i = 0; i < nelem; i++)
+ {
+ float usexloc;
+ if (xonset >= 0)
+ usexloc = xloc + *(float *)((elem + elemsize * i) + xonset);
+ else usexloc = xsum, xsum += xinc;
+ if (yonset >= 0)
+ yval = *(float *)((elem + elemsize * i) + yonset);
+ else yval = 0;
+ xpix = glist_xtopixels(glist, basex + usexloc);
+ ixpix = xpix + 0.5;
+ if (xonset >= 0 || ixpix != lastpixel)
+ {
+ sys_vgui("%d %f \\\n", ixpix,
+ glist_ytopixels(glist, basey + yloc + yval));
+ ndrawn++;
+ }
+ lastpixel = ixpix;
+ if (ndrawn >= 1000) break;
+ }
+ /* TK will complain if there aren't at least 2 points... */
+ if (ndrawn == 0) sys_vgui("0 0 0 0 \\\n");
+ else if (ndrawn == 1) sys_vgui("%d %f \\\n", ixpix + 10,
+ glist_ytopixels(glist, basey + yloc + yval));
+
+ sys_vgui("-width %f\\\n", linewidth);
+ sys_vgui("-fill %s\\\n", outline);
+ if (x->x_flags & BEZ) sys_vgui("-smooth 1\\\n");
+
+ sys_vgui("-tags plot%lx\n", data);
+ }
+ /* We're done with the outline; now draw all the points.
+ This code is inefficient since the template has to be
+ searched for drawing instructions for every last point. */
+
+ for (xsum = xloc, i = 0; i < nelem; i++)
+ {
+ float usexloc, useyloc;
+ t_gobj *y;
+ if (xonset >= 0)
+ usexloc = basex + xloc +
+ *(float *)((elem + elemsize * i) + xonset);
+ else usexloc = basex + xsum, xsum += xinc;
+ if (yonset >= 0)
+ yval = *(float *)((elem + elemsize * i) + yonset);
+ else yval = 0;
+ useyloc = basey + yloc + yval;
+ for (y = elemtemplatecanvas->gl_list; y; y = y->g_next)
+ {
+ t_parentwidgetbehavior *wb = pd_getparentwidget(&y->g_pd);
+ if (!wb) continue;
+ (*wb->w_parentvisfn)(y, glist,
+ (t_word *)(elem + elemsize * i),
+ elemtemplate, usexloc, useyloc, vis);
+ }
+ }
}
else
{
- /* un-draw the individual points */
- int i;
- for (i = 0; i < nelem; i++)
- {
- t_gobj *y;
- for (y = elemtemplatecanvas->gl_list; y; y = y->g_next)
- {
- t_parentwidgetbehavior *wb = pd_getparentwidget(&y->g_pd);
- if (!wb) continue;
- (*wb->w_parentvisfn)(y, glist,
- (t_word *)(elem + elemsize * i), elemtemplate,
- 0, 0, 0);
- }
- }
- /* and then the trace */
- sys_vgui(".x%x.c delete plot%x\n",
- glist_getcanvas(glist), data);
+ /* un-draw the individual points */
+ int i;
+ for (i = 0; i < nelem; i++)
+ {
+ t_gobj *y;
+ for (y = elemtemplatecanvas->gl_list; y; y = y->g_next)
+ {
+ t_parentwidgetbehavior *wb = pd_getparentwidget(&y->g_pd);
+ if (!wb) continue;
+ (*wb->w_parentvisfn)(y, glist,
+ (t_word *)(elem + elemsize * i), elemtemplate,
+ 0, 0, 0);
+ }
+ }
+ /* and then the trace */
+ sys_vgui(".x%lx.c delete plot%lx\n",
+ glist_getcanvas(glist), data);
}
}
@@ -1430,12 +1430,12 @@ static int plot_click(t_gobj *z, t_glist *glist,
t_word *data = sc->sc_vec;
if (!plot_readownertemplate(x, data, template,
- &elemtemplatesym, &array, &linewidth, &xloc, &xinc, &yloc))
+ &elemtemplatesym, &array, &linewidth, &xloc, &xinc, &yloc))
{
- return (array_doclick(array, glist, &sc->sc_gobj,
- elemtemplatesym,
- linewidth, basex + xloc, xinc, basey + yloc,
- xpix, ypix, shift, alt, dbl, doit));
+ return (array_doclick(array, glist, &sc->sc_gobj,
+ elemtemplatesym,
+ linewidth, basex + xloc, xinc, basey + yloc,
+ xpix, ypix, shift, alt, dbl, doit));
}
else return (0);
}
@@ -1453,7 +1453,7 @@ t_parentwidgetbehavior plot_widgetbehavior =
static void plot_setup(void)
{
plot_class = class_new(gensym("plot"), (t_newmethod)plot_new, 0,
- sizeof(t_plot), CLASS_NOINLET, A_GIMME, 0);
+ sizeof(t_plot), CLASS_NOINLET, A_GIMME, 0);
class_setdrawcommand(plot_class);
class_setparentwidget(plot_class, &plot_widgetbehavior);
}
@@ -1463,7 +1463,7 @@ static void plot_setup(void)
/*
drawnumbers draw numeric fields at controllable locations, with
controllable color and label .
- invocation: (drawnumber|drawsymbol) variable x y color label
+ invocation: (drawnumber|drawsymbol) variable x y color label
*/
t_class *drawnumber_class;
@@ -1487,7 +1487,7 @@ static void *drawnumber_new(t_symbol *classsym, t_int argc, t_atom *argv)
char *classname = classsym->s_name;
int flags = 0;
if (classname[4] == 's')
- flags |= DRAW_SYMBOL;
+ flags |= DRAW_SYMBOL;
x->x_flags = flags;
if (argc) fielddesc_setfloatarg(&x->x_value, argc--, argv++);
else FIELDDESC_SETFLOAT(&x->x_value, 0);
@@ -1498,7 +1498,7 @@ static void *drawnumber_new(t_symbol *classsym, t_int argc, t_atom *argv)
if (argc) fielddesc_setfloatarg(&x->x_color, argc--, argv++);
else FIELDDESC_SETFLOAT(&x->x_color, 1);
if (argc)
- x->x_label = atom_getsymbolarg(0, argc, argv);
+ x->x_label = atom_getsymbolarg(0, argc, argv);
else x->x_label = &s_;
return (x);
@@ -1523,14 +1523,14 @@ static void drawnumber_getrect(t_gobj *z, t_glist *glist,
t_drawnumber *x = (t_drawnumber *)z;
t_atom at;
int xloc = glist_xtopixels(glist,
- basex + fielddesc_getfloat(&x->x_xloc, template, data, 0));
+ basex + fielddesc_getfloat(&x->x_xloc, template, data, 0));
int yloc = glist_ytopixels(glist,
- basey + fielddesc_getfloat(&x->x_yloc, template, data, 0));
+ basey + fielddesc_getfloat(&x->x_yloc, template, data, 0));
int font = glist_getfont(glist);
int fontwidth = sys_fontwidth(font), fontheight = sys_fontheight(font);
char buf[DRAWNUMBER_BUFSIZE];
if (x->x_flags & DRAW_SYMBOL)
- SETSYMBOL(&at, fielddesc_getsymbol(&x->x_value, template, data, 0));
+ SETSYMBOL(&at, fielddesc_getsymbol(&x->x_value, template, data, 0));
else SETFLOAT(&at, fielddesc_getfloat(&x->x_value, template, data, 0));
drawnumber_sprintf(x, buf, &at);
*xp1 = xloc;
@@ -1569,25 +1569,25 @@ static void drawnumber_vis(t_gobj *z, t_glist *glist,
if (vis)
{
- t_atom at;
- int xloc = glist_xtopixels(glist,
- basex + fielddesc_getfloat(&x->x_xloc, template, data, 0));
- int yloc = glist_ytopixels(glist,
- basey + fielddesc_getfloat(&x->x_yloc, template, data, 0));
- char colorstring[20], buf[DRAWNUMBER_BUFSIZE];
- numbertocolor(fielddesc_getfloat(&x->x_color, template, data, 1),
- colorstring);
- if (x->x_flags & DRAW_SYMBOL)
- SETSYMBOL(&at, fielddesc_getsymbol(&x->x_value, template, data, 0));
- else SETFLOAT(&at, fielddesc_getfloat(&x->x_value, template, data, 0));
- drawnumber_sprintf(x, buf, &at);
- sys_vgui(".x%x.c create text %d %d -anchor nw -fill %s -text {%s}",
- glist_getcanvas(glist), xloc, yloc, colorstring, buf);
- sys_vgui(" -font -*-courier-bold--normal--%d-*",
- sys_hostfontsize(glist_getfont(glist)));
- sys_vgui(" -tags drawnumber%x\n", data);
+ t_atom at;
+ int xloc = glist_xtopixels(glist,
+ basex + fielddesc_getfloat(&x->x_xloc, template, data, 0));
+ int yloc = glist_ytopixels(glist,
+ basey + fielddesc_getfloat(&x->x_yloc, template, data, 0));
+ char colorstring[20], buf[DRAWNUMBER_BUFSIZE];
+ numbertocolor(fielddesc_getfloat(&x->x_color, template, data, 1),
+ colorstring);
+ if (x->x_flags & DRAW_SYMBOL)
+ SETSYMBOL(&at, fielddesc_getsymbol(&x->x_value, template, data, 0));
+ else SETFLOAT(&at, fielddesc_getfloat(&x->x_value, template, data, 0));
+ drawnumber_sprintf(x, buf, &at);
+ sys_vgui(".x%lx.c create text %d %d -anchor nw -fill %s -text {%s}",
+ glist_getcanvas(glist), xloc, yloc, colorstring, buf);
+ sys_vgui(" -font -*-courier-bold--normal--%d-*",
+ sys_hostfontsize(glist_getfont(glist)));
+ sys_vgui(" -tags drawnumber%lx\n", data);
}
- else sys_vgui(".x%x.c delete drawnumber%x\n", glist_getcanvas(glist), data);
+ else sys_vgui(".x%lx.c delete drawnumber%lx\n", glist_getcanvas(glist), data);
}
static float drawnumber_motion_ycumulative;
@@ -1605,10 +1605,10 @@ static void drawnumber_motion(void *z, t_floatarg dx, t_floatarg dy)
t_fielddesc *f = &x->x_value;
drawnumber_motion_ycumulative -= dy;
template_setfloat(drawnumber_motion_template,
- f->fd_un.fd_varsym,
- drawnumber_motion_wp,
- drawnumber_motion_ycumulative,
- 1);
+ f->fd_un.fd_varsym,
+ drawnumber_motion_wp,
+ drawnumber_motion_ycumulative,
+ 1);
glist_redrawitem(drawnumber_motion_glist, drawnumber_motion_gobj);
}
@@ -1620,22 +1620,22 @@ static int drawnumber_click(t_gobj *z, t_glist *glist,
int x1, y1, x2, y2;
t_word *data = sc->sc_vec;
drawnumber_getrect(z, glist,
- sc->sc_vec, template, basex, basey,
- &x1, &y1, &x2, &y2);
+ sc->sc_vec, template, basex, basey,
+ &x1, &y1, &x2, &y2);
if (xpix >= x1 && xpix <= x2 && ypix >= y1 && ypix <= y2
- && x->x_value.fd_var)
+ && x->x_value.fd_var)
{
- if (doit)
- {
- drawnumber_motion_glist = glist;
- drawnumber_motion_gobj = &sc->sc_gobj;
- drawnumber_motion_wp = data;
- drawnumber_motion_template = template;
- drawnumber_motion_ycumulative =
- fielddesc_getfloat(&x->x_value, template, data, 0);
- glist_grab(glist, z, drawnumber_motion, 0, xpix, ypix);
- }
- return (1);
+ if (doit)
+ {
+ drawnumber_motion_glist = glist;
+ drawnumber_motion_gobj = &sc->sc_gobj;
+ drawnumber_motion_wp = data;
+ drawnumber_motion_template = template;
+ drawnumber_motion_ycumulative =
+ fielddesc_getfloat(&x->x_value, template, data, 0);
+ glist_grab(glist, z, drawnumber_motion, 0, xpix, ypix);
+ }
+ return (1);
}
else return (0);
}
@@ -1657,11 +1657,11 @@ static void drawnumber_free(t_drawnumber *x)
static void drawnumber_setup(void)
{
drawnumber_class = class_new(gensym("drawnumber"),
- (t_newmethod)drawnumber_new, (t_method)drawnumber_free,
- sizeof(t_drawnumber), CLASS_NOINLET, A_GIMME, 0);
+ (t_newmethod)drawnumber_new, (t_method)drawnumber_free,
+ sizeof(t_drawnumber), CLASS_NOINLET, A_GIMME, 0);
class_setdrawcommand(drawnumber_class);
class_addcreator((t_newmethod)drawnumber_new, gensym("drawsymbol"),
- A_GIMME, 0);
+ A_GIMME, 0);
class_setparentwidget(drawnumber_class, &drawnumber_widgetbehavior);
}
diff --git a/pd/src/g_text.c b/pd/src/g_text.c
index 1804c606..472cb1c6 100644
--- a/pd/src/g_text.c
+++ b/pd/src/g_text.c
@@ -16,7 +16,7 @@
#include <string.h>
#include <math.h>
-static t_class *text_class;
+t_class *text_class;
static t_class *message_class;
static t_class *gatom_class;
static void text_vis(t_gobj *z, t_glist *glist, int vis);
@@ -39,41 +39,41 @@ void glist_text(t_glist *gl, t_symbol *s, int argc, t_atom *argv)
{
t_text *x = (t_text *)pd_new(text_class);
t_atom at;
- x->te_width = 0; /* don't know it yet. */
+ x->te_width = 0; /* don't know it yet. */
x->te_type = T_TEXT;
x->te_binbuf = binbuf_new();
if (argc > 1)
{
- x->te_xpix = atom_getfloatarg(0, argc, argv);
- x->te_ypix = atom_getfloatarg(1, argc, argv);
- if (argc > 2) binbuf_restore(x->te_binbuf, argc-2, argv+2);
- else
- {
- SETSYMBOL(&at, gensym("comment"));
- binbuf_restore(x->te_binbuf, 1, &at);
- }
- glist_add(gl, &x->te_g);
+ x->te_xpix = atom_getfloatarg(0, argc, argv);
+ x->te_ypix = atom_getfloatarg(1, argc, argv);
+ if (argc > 2) binbuf_restore(x->te_binbuf, argc-2, argv+2);
+ else
+ {
+ SETSYMBOL(&at, gensym("comment"));
+ binbuf_restore(x->te_binbuf, 1, &at);
+ }
+ glist_add(gl, &x->te_g);
}
else
{
- int xpix, ypix;
- pd_vmess((t_pd *)glist_getcanvas(gl), gensym("editmode"), "i", 1);
- SETSYMBOL(&at, gensym("comment"));
- glist_noselect(gl);
- glist_getnextxy(gl, &xpix, &ypix);
- x->te_xpix = glist_pixelstox(gl, xpix-3);
- x->te_ypix = glist_pixelstoy(gl, ypix-3);
- binbuf_restore(x->te_binbuf, 1, &at);
- glist_add(gl, &x->te_g);
- glist_noselect(gl);
- glist_select(gl, &x->te_g);
- /* it would be nice to "activate" here, but then the second,
- "put-me-down" click changes the text selection, which is quite
- irritating, so I took this back out. It's OK in messages
- and objects though since there's no text in them at menu
- creation. */
- /* gobj_activate(&x->te_g, gl, 1); */
- canvas_startmotion(glist_getcanvas(gl));
+ int xpix, ypix;
+ pd_vmess((t_pd *)glist_getcanvas(gl), gensym("editmode"), "i", 1);
+ SETSYMBOL(&at, gensym("comment"));
+ glist_noselect(gl);
+ glist_getnextxy(gl, &xpix, &ypix);
+ x->te_xpix = glist_pixelstox(gl, xpix-3);
+ x->te_ypix = glist_pixelstoy(gl, ypix-3);
+ binbuf_restore(x->te_binbuf, 1, &at);
+ glist_add(gl, &x->te_g);
+ glist_noselect(gl);
+ glist_select(gl, &x->te_g);
+ /* it would be nice to "activate" here, but then the second,
+ "put-me-down" click changes the text selection, which is quite
+ irritating, so I took this back out. It's OK in messages
+ and objects though since there's no text in them at menu
+ creation. */
+ /* gobj_activate(&x->te_g, gl, 1); */
+ canvas_startmotion(glist_getcanvas(gl));
}
}
@@ -94,24 +94,24 @@ static void canvas_objtext(t_glist *gl, int xpix, int ypix, int selected,
binbuf_eval(b, &pd_objectmaker, argc, argv);
if (binbuf_getnatom(b))
{
- if (!newest)
- {
- binbuf_print(b);
- post("... couldn't create");
- x = 0;
- }
- else if (!(x = pd_checkobject(newest)))
- {
- binbuf_print(b);
- post("... didn't return a patchable object");
- }
+ if (!newest)
+ {
+ binbuf_print(b);
+ post("... couldn't create");
+ x = 0;
+ }
+ else if (!(x = pd_checkobject(newest)))
+ {
+ binbuf_print(b);
+ post("... didn't return a patchable object");
+ }
}
else x = 0;
if (!x)
{
-
- /* LATER make the color reflect this */
- x = (t_text *)pd_new(text_class);
+
+ /* LATER make the color reflect this */
+ x = (t_text *)pd_new(text_class);
}
x->te_binbuf = b;
x->te_xpix = xpix;
@@ -121,14 +121,14 @@ static void canvas_objtext(t_glist *gl, int xpix, int ypix, int selected,
glist_add(gl, &x->te_g);
if (selected)
{
- /* this is called if we've been created from the menu. */
- glist_select(gl, &x->te_g);
- gobj_activate(&x->te_g, gl, 1);
+ /* this is called if we've been created from the menu. */
+ glist_select(gl, &x->te_g);
+ gobj_activate(&x->te_g, gl, 1);
}
if (pd_class(&x->ob_pd) == vinlet_class)
- canvas_resortinlets(glist_getcanvas(gl));
+ canvas_resortinlets(glist_getcanvas(gl));
if (pd_class(&x->ob_pd) == voutlet_class)
- canvas_resortoutlets(glist_getcanvas(gl));
+ canvas_resortoutlets(glist_getcanvas(gl));
canvas_unsetcurrent((t_canvas *)gl);
}
@@ -141,20 +141,20 @@ void canvas_obj(t_glist *gl, t_symbol *s, int argc, t_atom *argv)
t_text *x;
if (argc >= 2)
{
- t_binbuf *b = binbuf_new();
- binbuf_restore(b, argc-2, argv+2);
- canvas_objtext(gl, atom_getintarg(0, argc, argv),
- atom_getintarg(1, argc, argv), 0, b);
+ t_binbuf *b = binbuf_new();
+ binbuf_restore(b, argc-2, argv+2);
+ canvas_objtext(gl, atom_getintarg(0, argc, argv),
+ atom_getintarg(1, argc, argv), 0, b);
}
else
{
- t_binbuf *b = binbuf_new();
- int xpix, ypix;
- pd_vmess(&gl->gl_pd, gensym("editmode"), "i", 1);
- glist_noselect(gl);
- glist_getnextxy(gl, &xpix, &ypix);
- canvas_objtext(gl, xpix, ypix, 1, b);
- canvas_startmotion(glist_getcanvas(gl));
+ t_binbuf *b = binbuf_new();
+ int xpix, ypix;
+ pd_vmess(&gl->gl_pd, gensym("editmode"), "i", 1);
+ glist_noselect(gl);
+ glist_getnextxy(gl, &xpix, &ypix);
+ canvas_objtext(gl, xpix, ypix, 1, b);
+ canvas_startmotion(glist_getcanvas(gl));
}
}
@@ -235,7 +235,7 @@ void canvas_numbox(t_glist *gl, t_symbol *s, int argc, t_atom *argv)
void canvas_objfor(t_glist *gl, t_text *x, int argc, t_atom *argv)
{
- x->te_width = 0; /* don't know it yet. */
+ x->te_width = 0; /* don't know it yet. */
x->te_type = T_OBJECT;
x->te_binbuf = binbuf_new();
x->te_xpix = atom_getfloatarg(0, argc, argv);
@@ -335,15 +335,15 @@ static void message_add(t_message *x, t_symbol *s, int argc, t_atom *argv)
static void message_click(t_message *x,
t_floatarg xpos, t_floatarg ypos, t_floatarg shift,
- t_floatarg ctrl, t_floatarg alt)
+ t_floatarg ctrl, t_floatarg alt)
{
message_float(x, 0);
if (glist_isvisible(x->m_glist))
{
- t_rtext *y = glist_findrtext(x->m_glist, &x->m_text);
- sys_vgui(".x%x.c itemconfigure %sR -width 5\n",
- glist_getcanvas(x->m_glist), rtext_gettag(y));
- clock_delay(x->m_clock, 120);
+ t_rtext *y = glist_findrtext(x->m_glist, &x->m_text);
+ sys_vgui(".x%lx.c itemconfigure %sR -width 5\n",
+ glist_getcanvas(x->m_glist), rtext_gettag(y));
+ clock_delay(x->m_clock, 120);
}
}
@@ -351,9 +351,9 @@ static void message_tick(t_message *x)
{
if (glist_isvisible(x->m_glist))
{
- t_rtext *y = glist_findrtext(x->m_glist, &x->m_text);
- sys_vgui(".x%x.c itemconfigure %sR -width 1\n",
- glist_getcanvas(x->m_glist), rtext_gettag(y));
+ t_rtext *y = glist_findrtext(x->m_glist, &x->m_text);
+ sys_vgui(".x%lx.c itemconfigure %sR -width 1\n",
+ glist_getcanvas(x->m_glist), rtext_gettag(y));
}
}
@@ -367,31 +367,31 @@ void canvas_msg(t_glist *gl, t_symbol *s, int argc, t_atom *argv)
t_message *x = (t_message *)pd_new(message_class);
x->m_messresponder.mr_pd = messresponder_class;
x->m_messresponder.mr_outlet = outlet_new(&x->m_text, &s_float);
- x->m_text.te_width = 0; /* don't know it yet. */
+ x->m_text.te_width = 0; /* don't know it yet. */
x->m_text.te_type = T_MESSAGE;
x->m_text.te_binbuf = binbuf_new();
x->m_glist = gl;
x->m_clock = clock_new(x, (t_method)message_tick);
if (argc > 1)
{
- x->m_text.te_xpix = atom_getfloatarg(0, argc, argv);
- x->m_text.te_ypix = atom_getfloatarg(1, argc, argv);
- if (argc > 2) binbuf_restore(x->m_text.te_binbuf, argc-2, argv+2);
- glist_add(gl, &x->m_text.te_g);
+ x->m_text.te_xpix = atom_getfloatarg(0, argc, argv);
+ x->m_text.te_ypix = atom_getfloatarg(1, argc, argv);
+ if (argc > 2) binbuf_restore(x->m_text.te_binbuf, argc-2, argv+2);
+ glist_add(gl, &x->m_text.te_g);
}
else
{
- int xpix, ypix;
- pd_vmess(&gl->gl_pd, gensym("editmode"), "i", 1);
- glist_noselect(gl);
- glist_getnextxy(gl, &xpix, &ypix);
- x->m_text.te_xpix = xpix-3;
- x->m_text.te_ypix = ypix-3;
- glist_add(gl, &x->m_text.te_g);
- glist_noselect(gl);
- glist_select(gl, &x->m_text.te_g);
- gobj_activate(&x->m_text.te_g, gl, 1);
- canvas_startmotion(glist_getcanvas(gl));
+ int xpix, ypix;
+ pd_vmess(&gl->gl_pd, gensym("editmode"), "i", 1);
+ glist_noselect(gl);
+ glist_getnextxy(gl, &xpix, &ypix);
+ x->m_text.te_xpix = xpix-3;
+ x->m_text.te_ypix = ypix-3;
+ glist_add(gl, &x->m_text.te_g);
+ glist_noselect(gl);
+ glist_select(gl, &x->m_text.te_g);
+ gobj_activate(&x->m_text.te_g, gl, 1);
+ canvas_startmotion(glist_getcanvas(gl));
}
}
@@ -406,17 +406,17 @@ void canvas_msg(t_glist *gl, t_symbol *s, int argc, t_atom *argv)
typedef struct _gatom
{
t_text a_text;
- t_atom a_atom; /* this holds the value and the type */
- t_glist *a_glist; /* owning glist */
- t_float a_toggle; /* value to toggle to */
- t_float a_draghi; /* high end of drag range */
- t_float a_draglo; /* low end of drag range */
- t_symbol *a_label; /* symbol to show as label next to box */
+ t_atom a_atom; /* this holds the value and the type */
+ t_glist *a_glist; /* owning glist */
+ t_float a_toggle; /* value to toggle to */
+ t_float a_draghi; /* high end of drag range */
+ t_float a_draglo; /* low end of drag range */
+ t_symbol *a_label; /* symbol to show as label next to box */
t_symbol *a_symfrom; /* "receive" name -- bind ourselvs to this */
- t_symbol *a_symto; /* "send" name -- send to this on output */
+ t_symbol *a_symto; /* "send" name -- send to this on output */
char a_buf[ATOMBUFSIZE];/* string buffer for typing */
- char a_shift; /* was shift key down when dragging started? */
- char a_wherelabel; /* 0-3 for left, right, above, below */
+ char a_shift; /* was shift key down when dragging started? */
+ char a_wherelabel; /* 0-3 for left, right, above, below */
t_symbol *a_expanded_to; /* a_symto after $0, $1, ... expansion */
} t_gatom;
@@ -427,14 +427,14 @@ typedef struct _gatom
static t_symbol *gatom_escapit(t_symbol *s)
{
if (!*s->s_name)
- return (gensym("-"));
+ return (gensym("-"));
else if (*s->s_name == '-')
{
- char shmo[100];
- shmo[0] = '-';
- strncpy(shmo+1, s->s_name, 99);
- shmo[99] = 0;
- return (gensym(shmo));
+ char shmo[100];
+ shmo[0] = '-';
+ strncpy(shmo+1, s->s_name, 99);
+ shmo[99] = 0;
+ return (gensym(shmo));
}
else return (iemgui_dollar2raute(s));
}
@@ -443,33 +443,37 @@ static t_symbol *gatom_escapit(t_symbol *s)
static t_symbol *gatom_unescapit(t_symbol *s)
{
if (*s->s_name == '-')
- return (gensym(s->s_name+1));
+ return (gensym(s->s_name+1));
else return (iemgui_raute2dollar(s));
}
-#if 0 /* ??? */
- /* expand leading $0, $1, etc. in the symbol */
-static t_symbol *gatom_realizedollar(t_gatom *x, t_symbol *s)
+static void gatom_redraw(t_gobj *client, t_glist *glist)
{
- return (canvas_realizedollar(x->a_glist, s));
+ t_gatom *x = (t_gatom *)client;
+ glist_retext(x->a_glist, &x->a_text);
+}
+
+static void gatom_retext(t_gatom *x, int senditup)
+{
+ binbuf_clear(x->a_text.te_binbuf);
+ binbuf_add(x->a_text.te_binbuf, 1, &x->a_atom);
+ if (senditup && glist_isvisible(x->a_glist))
+ sys_queuegui(x, x->a_glist, gatom_redraw);
}
-#endif
static void gatom_set(t_gatom *x, t_symbol *s, int argc, t_atom *argv)
{
t_atom oldatom = x->a_atom;
- int update = 0;
+ int changed = 0;
if (!argc) return;
if (x->a_atom.a_type == A_FLOAT)
- x->a_atom.a_w.w_float = atom_getfloat(argv),
- update = (x->a_atom.a_w.w_float != oldatom.a_w.w_float);
+ x->a_atom.a_w.w_float = atom_getfloat(argv),
+ changed = (x->a_atom.a_w.w_float != oldatom.a_w.w_float);
else if (x->a_atom.a_type == A_SYMBOL)
- x->a_atom.a_w.w_symbol = atom_getsymbol(argv),
- update = (x->a_atom.a_w.w_symbol != oldatom.a_w.w_symbol);
- binbuf_clear(x->a_text.te_binbuf);
- binbuf_add(x->a_text.te_binbuf, 1, &x->a_atom);
- if (update)
- glist_retext(x->a_glist, &x->a_text);
+ x->a_atom.a_w.w_symbol = atom_getsymbol(argv),
+ changed = (x->a_atom.a_w.w_symbol != oldatom.a_w.w_symbol);
+ if (changed)
+ gatom_retext(x, 1);
x->a_buf[0] = 0;
}
@@ -477,29 +481,29 @@ static void gatom_bang(t_gatom *x)
{
if (x->a_atom.a_type == A_FLOAT)
{
- if (x->a_text.te_outlet)
- outlet_float(x->a_text.te_outlet, x->a_atom.a_w.w_float);
- if (*x->a_expanded_to->s_name && x->a_expanded_to->s_thing)
- {
- if (x->a_symto == x->a_symfrom)
- pd_error(x,
- "%s: atom with same send/receive name (infinite loop)",
- x->a_symto->s_name);
- else pd_float(x->a_expanded_to->s_thing, x->a_atom.a_w.w_float);
- }
+ if (x->a_text.te_outlet)
+ outlet_float(x->a_text.te_outlet, x->a_atom.a_w.w_float);
+ if (*x->a_expanded_to->s_name && x->a_expanded_to->s_thing)
+ {
+ if (x->a_symto == x->a_symfrom)
+ pd_error(x,
+ "%s: atom with same send/receive name (infinite loop)",
+ x->a_symto->s_name);
+ else pd_float(x->a_expanded_to->s_thing, x->a_atom.a_w.w_float);
+ }
}
else if (x->a_atom.a_type == A_SYMBOL)
{
- if (x->a_text.te_outlet)
- outlet_symbol(x->a_text.te_outlet, x->a_atom.a_w.w_symbol);
- if (*x->a_symto->s_name && x->a_expanded_to->s_thing)
- {
- if (x->a_symto == x->a_symfrom)
- pd_error(x,
- "%s: atom with same send/receive name (infinite loop)",
- x->a_symto->s_name);
- else pd_symbol(x->a_expanded_to->s_thing, x->a_atom.a_w.w_symbol);
- }
+ if (x->a_text.te_outlet)
+ outlet_symbol(x->a_text.te_outlet, x->a_atom.a_w.w_symbol);
+ if (*x->a_symto->s_name && x->a_expanded_to->s_thing)
+ {
+ if (x->a_symto == x->a_symfrom)
+ pd_error(x,
+ "%s: atom with same send/receive name (infinite loop)",
+ x->a_symto->s_name);
+ else pd_symbol(x->a_expanded_to->s_thing, x->a_atom.a_w.w_symbol);
+ }
}
}
@@ -515,10 +519,10 @@ static void gatom_clipfloat(t_gatom *x, t_float f)
{
if (x->a_draglo != 0 || x->a_draghi != 0)
{
- if (f < x->a_draglo)
- f = x->a_draglo;
- if (f > x->a_draghi)
- f = x->a_draghi;
+ if (f < x->a_draglo)
+ f = x->a_draglo;
+ if (f > x->a_draghi)
+ f = x->a_draghi;
}
gatom_float(x, f);
}
@@ -537,22 +541,22 @@ static void gatom_motion(void *z, t_floatarg dx, t_floatarg dy)
if (dy == 0) return;
if (x->a_atom.a_type == A_FLOAT)
{
- if (x->a_shift)
- {
- double nval = x->a_atom.a_w.w_float - 0.01 * dy;
- double trunc = 0.01 * (floor(100. * nval + 0.5));
- if (trunc < nval + 0.0001 && trunc > nval - 0.0001) nval = trunc;
- gatom_clipfloat(x, nval);
- }
- else
- {
- double nval = x->a_atom.a_w.w_float - dy;
- double trunc = 0.01 * (floor(100. * nval + 0.5));
- if (trunc < nval + 0.0001 && trunc > nval - 0.0001) nval = trunc;
- trunc = floor(nval + 0.5);
- if (trunc < nval + 0.001 && trunc > nval - 0.001) nval = trunc;
- gatom_clipfloat(x, nval);
- }
+ if (x->a_shift)
+ {
+ double nval = x->a_atom.a_w.w_float - 0.01 * dy;
+ double trunc = 0.01 * (floor(100. * nval + 0.5));
+ if (trunc < nval + 0.0001 && trunc > nval - 0.0001) nval = trunc;
+ gatom_clipfloat(x, nval);
+ }
+ else
+ {
+ double nval = x->a_atom.a_w.w_float - dy;
+ double trunc = 0.01 * (floor(100. * nval + 0.5));
+ if (trunc < nval + 0.0001 && trunc > nval - 0.0001) nval = trunc;
+ trunc = floor(nval + 0.5);
+ if (trunc < nval + 0.001 && trunc > nval - 0.001) nval = trunc;
+ gatom_clipfloat(x, nval);
+ }
}
}
@@ -565,45 +569,44 @@ static void gatom_key(void *z, t_floatarg f)
char sbuf[ATOMBUFSIZE + 4];
if (c == 0)
{
- /* we're being notified that no more keys will come for this grab */
- if (x->a_buf[0])
- {
- binbuf_clear(x->a_text.te_binbuf);
- binbuf_add(x->a_text.te_binbuf, 1, &x->a_atom);
- glist_retext(x->a_glist, &x->a_text);
- }
- return;
+ /* we're being notified that no more keys will come for this grab */
+ if (x->a_buf[0])
+ gatom_retext(x, 1);
+ return;
}
else if (c == ' ') return;
else if (c == '\b')
{
- if (len > 0)
- x->a_buf[len-1] = 0;
- goto redraw;
+ if (len > 0)
+ x->a_buf[len-1] = 0;
+ goto redraw;
}
else if (c == '\n')
{
- if (x->a_atom.a_type == A_FLOAT)
- gatom_float(x, atof(x->a_buf));
- else if (x->a_atom.a_type == A_SYMBOL)
- gatom_symbol(x, gensym(x->a_buf));
- else bug("gatom_key");
+ if (x->a_atom.a_type == A_FLOAT)
+ x->a_atom.a_w.w_float = atof(x->a_buf);
+ else if (x->a_atom.a_type == A_SYMBOL)
+ x->a_atom.a_w.w_symbol = gensym(x->a_buf);
+ else bug("gatom_key");
+ gatom_bang(x);
+ gatom_retext(x, 1);
+ x->a_buf[0] = 0;
}
else if (len < (ATOMBUFSIZE-1))
{
- /* for numbers, only let reasonable characters through */
- if ((x->a_atom.a_type == A_SYMBOL) ||
- (c >= '0' && c <= '9' || c == '.' || c == '-'
- || c == 'e' || c == 'E'))
- {
- x->a_buf[len] = c;
- x->a_buf[len+1] = 0;
- goto redraw;
- }
+ /* for numbers, only let reasonable characters through */
+ if ((x->a_atom.a_type == A_SYMBOL) ||
+ (c >= '0' && c <= '9' || c == '.' || c == '-'
+ || c == 'e' || c == 'E'))
+ {
+ x->a_buf[len] = c;
+ x->a_buf[len+1] = 0;
+ goto redraw;
+ }
}
return;
redraw:
- /* LATER figure out how to avoid creating all these symbols! */
+ /* LATER figure out how to avoid creating all these symbols! */
sprintf(sbuf, "%s...", x->a_buf);
SETSYMBOL(&at, gensym(sbuf));
binbuf_clear(x->a_text.te_binbuf);
@@ -617,26 +620,26 @@ static void gatom_click(t_gatom *x,
{
if (x->a_text.te_width == 1)
{
- if (x->a_atom.a_type == A_FLOAT)
- gatom_float(x, (x->a_atom.a_w.w_float == 0));
+ if (x->a_atom.a_type == A_FLOAT)
+ gatom_float(x, (x->a_atom.a_w.w_float == 0));
}
else
{
- if (alt)
- {
- if (x->a_atom.a_type != A_FLOAT) return;
- if (x->a_atom.a_w.w_float != 0)
- {
- x->a_toggle = x->a_atom.a_w.w_float;
- gatom_float(x, 0);
- return;
- }
- else gatom_float(x, x->a_toggle);
- }
- x->a_shift = shift;
- x->a_buf[0] = 0;
- glist_grab(x->a_glist, &x->a_text.te_g, gatom_motion, gatom_key,
- xpos, ypos);
+ if (alt)
+ {
+ if (x->a_atom.a_type != A_FLOAT) return;
+ if (x->a_atom.a_w.w_float != 0)
+ {
+ x->a_toggle = x->a_atom.a_w.w_float;
+ gatom_float(x, 0);
+ return;
+ }
+ else gatom_float(x, x->a_toggle);
+ }
+ x->a_shift = shift;
+ x->a_buf[0] = 0;
+ glist_grab(x->a_glist, &x->a_text.te_g, gatom_motion, gatom_key,
+ xpos, ypos);
}
}
@@ -653,39 +656,39 @@ static void gatom_param(t_gatom *x, t_symbol *sel, int argc, t_atom *argv)
gobj_vis(&x->a_text.te_g, x->a_glist, 0);
if (!*symfrom->s_name && *x->a_symfrom->s_name)
- inlet_new(&x->a_text, &x->a_text.te_pd, 0, 0);
+ inlet_new(&x->a_text, &x->a_text.te_pd, 0, 0);
else if (*symfrom->s_name && !*x->a_symfrom->s_name && x->a_text.te_inlet)
{
- canvas_deletelinesforio(x->a_glist, &x->a_text,
- x->a_text.te_inlet, 0);
- inlet_free(x->a_text.te_inlet);
+ canvas_deletelinesforio(x->a_glist, &x->a_text,
+ x->a_text.te_inlet, 0);
+ inlet_free(x->a_text.te_inlet);
}
if (!*symto->s_name && *x->a_symto->s_name)
- outlet_new(&x->a_text, 0);
+ outlet_new(&x->a_text, 0);
else if (*symto->s_name && !*x->a_symto->s_name && x->a_text.te_outlet)
{
- canvas_deletelinesforio(x->a_glist, &x->a_text,
- 0, x->a_text.te_outlet);
- outlet_free(x->a_text.te_outlet);
+ canvas_deletelinesforio(x->a_glist, &x->a_text,
+ 0, x->a_text.te_outlet);
+ outlet_free(x->a_text.te_outlet);
}
if (draglo >= draghi)
- draglo = draghi = 0;
+ draglo = draghi = 0;
x->a_draglo = draglo;
x->a_draghi = draghi;
if (width < 0)
- width = 4;
+ width = 4;
else if (width > 80)
- width = 80;
+ width = 80;
x->a_text.te_width = width;
x->a_wherelabel = ((int)wherelabel & 3);
x->a_label = label;
if (*x->a_symfrom->s_name)
- pd_unbind(&x->a_text.te_pd,
- canvas_realizedollar(x->a_glist, x->a_symfrom));
+ pd_unbind(&x->a_text.te_pd,
+ canvas_realizedollar(x->a_glist, x->a_symfrom));
x->a_symfrom = symfrom;
if (*x->a_symfrom->s_name)
- pd_bind(&x->a_text.te_pd,
- canvas_realizedollar(x->a_glist, x->a_symfrom));
+ pd_bind(&x->a_text.te_pd,
+ canvas_realizedollar(x->a_glist, x->a_symfrom));
x->a_symto = symto;
x->a_expanded_to = canvas_realizedollar(x->a_glist, x->a_symto);
gobj_vis(&x->a_text.te_g, x->a_glist, 1);
@@ -702,25 +705,25 @@ static void gatom_getwherelabel(t_gatom *x, t_glist *glist, int *xp, int *yp)
height = y2 - y1;
if (x->a_wherelabel == ATOM_LABELLEFT)
{
- *xp = x1 - 3 -
- strlen(canvas_realizedollar(x->a_glist, x->a_label)->s_name) *
- sys_fontwidth(glist_getfont(glist));
- *yp = y1 + 2;
+ *xp = x1 - 3 -
+ strlen(canvas_realizedollar(x->a_glist, x->a_label)->s_name) *
+ sys_fontwidth(glist_getfont(glist));
+ *yp = y1 + 2;
}
else if (x->a_wherelabel == ATOM_LABELRIGHT)
{
- *xp = x2 + 2;
- *yp = y1 + 2;
+ *xp = x2 + 2;
+ *yp = y1 + 2;
}
else if (x->a_wherelabel == ATOM_LABELUP)
{
- *xp = x1 - 1;
- *yp = y1 - 1 - sys_fontheight(glist_getfont(glist));;
+ *xp = x1 - 1;
+ *yp = y1 - 1 - sys_fontheight(glist_getfont(glist));;
}
else
{
- *xp = x1 - 1;
- *yp = y2 + 3;
+ *xp = x1 - 1;
+ *yp = y2 + 3;
}
}
@@ -729,8 +732,8 @@ static void gatom_displace(t_gobj *z, t_glist *glist,
{
t_gatom *x = (t_gatom*)z;
text_displace(z, glist, dx, dy);
- sys_vgui(".x%x.c move %x.l %d %d\n", glist_getcanvas(glist),
- x, dx, dy);
+ sys_vgui(".x%lx.c move %lx.l %d %d\n", glist_getcanvas(glist),
+ x, dx, dy);
}
static void gatom_vis(t_gobj *z, t_glist *glist, int vis)
@@ -739,18 +742,22 @@ static void gatom_vis(t_gobj *z, t_glist *glist, int vis)
text_vis(z, glist, vis);
if (*x->a_label->s_name)
{
- if (vis)
- {
- int x1, y1;
- gatom_getwherelabel(x, glist, &x1, &y1);
- sys_vgui("pdtk_text_new .x%x.c %x.l %f %f {%s} %d %s\n",
- glist_getcanvas(glist), x,
- (double)x1, (double)y1,
- canvas_realizedollar(x->a_glist, x->a_label)->s_name,
- sys_hostfontsize(glist_getfont(glist)),
- "black");
- }
- else sys_vgui(".x%x.c delete %x.l\n", glist_getcanvas(glist), x);
+ if (vis)
+ {
+ int x1, y1;
+ gatom_getwherelabel(x, glist, &x1, &y1);
+ sys_vgui("pdtk_text_new .x%lx.c %lx.l %f %f {%s} %d %s\n",
+ glist_getcanvas(glist), x,
+ (double)x1, (double)y1,
+ canvas_realizedollar(x->a_glist, x->a_label)->s_name,
+ sys_hostfontsize(glist_getfont(glist)),
+ "black");
+ }
+ else
+ {
+ sys_vgui(".x%lx.c delete %lx.l\n", glist_getcanvas(glist), x);
+ sys_unqueuegui(x);
+ }
}
}
@@ -759,7 +766,7 @@ void canvas_atom(t_glist *gl, t_atomtype type,
{
t_gatom *x = (t_gatom *)pd_new(gatom_class);
t_atom at;
- x->a_text.te_width = 0; /* don't know it yet. */
+ x->a_text.te_width = 0; /* don't know it yet. */
x->a_text.te_type = T_ATOM;
x->a_text.te_binbuf = binbuf_new();
x->a_glist = gl;
@@ -773,61 +780,61 @@ void canvas_atom(t_glist *gl, t_atomtype type,
x->a_symto = x->a_expanded_to = &s_;
if (type == A_FLOAT)
{
- x->a_atom.a_w.w_float = 0;
- x->a_text.te_width = 5;
- SETFLOAT(&at, 0);
+ x->a_atom.a_w.w_float = 0;
+ x->a_text.te_width = 5;
+ SETFLOAT(&at, 0);
}
else
{
- x->a_atom.a_w.w_symbol = &s_symbol;
- x->a_text.te_width = 10;
- SETSYMBOL(&at, &s_symbol);
+ x->a_atom.a_w.w_symbol = &s_symbol;
+ x->a_text.te_width = 10;
+ SETSYMBOL(&at, &s_symbol);
}
binbuf_add(x->a_text.te_binbuf, 1, &at);
if (argc > 1)
- /* create from file. x, y, width, low-range, high-range, flags,
- label, receive-name, send-name */
+ /* create from file. x, y, width, low-range, high-range, flags,
+ label, receive-name, send-name */
{
- x->a_text.te_xpix = atom_getfloatarg(0, argc, argv);
- x->a_text.te_ypix = atom_getfloatarg(1, argc, argv);
- x->a_text.te_width = atom_getintarg(2, argc, argv);
- /* sanity check because some very old patches have trash in this
- field... remove this in 2003 or so: */
- if (x->a_text.te_width < 0 || x->a_text.te_width > 500)
- x->a_text.te_width = 4;
- x->a_draglo = atom_getfloatarg(3, argc, argv);
- x->a_draghi = atom_getfloatarg(4, argc, argv);
- x->a_wherelabel = (((int)atom_getfloatarg(5, argc, argv)) & 3);
- x->a_label = gatom_unescapit(atom_getsymbolarg(6, argc, argv));
- x->a_symfrom = gatom_unescapit(atom_getsymbolarg(7, argc, argv));
- if (*x->a_symfrom->s_name)
- pd_bind(&x->a_text.te_pd,
- canvas_realizedollar(x->a_glist, x->a_symfrom));
-
- x->a_symto = gatom_unescapit(atom_getsymbolarg(8, argc, argv));
- x->a_expanded_to = canvas_realizedollar(x->a_glist, x->a_symto);
- if (x->a_symto == &s_)
- outlet_new(&x->a_text,
- x->a_atom.a_type == A_FLOAT ? &s_float: &s_symbol);
- if (x->a_symfrom == &s_)
- inlet_new(&x->a_text, &x->a_text.te_pd, 0, 0);
- glist_add(gl, &x->a_text.te_g);
+ x->a_text.te_xpix = atom_getfloatarg(0, argc, argv);
+ x->a_text.te_ypix = atom_getfloatarg(1, argc, argv);
+ x->a_text.te_width = atom_getintarg(2, argc, argv);
+ /* sanity check because some very old patches have trash in this
+ field... remove this in 2003 or so: */
+ if (x->a_text.te_width < 0 || x->a_text.te_width > 500)
+ x->a_text.te_width = 4;
+ x->a_draglo = atom_getfloatarg(3, argc, argv);
+ x->a_draghi = atom_getfloatarg(4, argc, argv);
+ x->a_wherelabel = (((int)atom_getfloatarg(5, argc, argv)) & 3);
+ x->a_label = gatom_unescapit(atom_getsymbolarg(6, argc, argv));
+ x->a_symfrom = gatom_unescapit(atom_getsymbolarg(7, argc, argv));
+ if (*x->a_symfrom->s_name)
+ pd_bind(&x->a_text.te_pd,
+ canvas_realizedollar(x->a_glist, x->a_symfrom));
+
+ x->a_symto = gatom_unescapit(atom_getsymbolarg(8, argc, argv));
+ x->a_expanded_to = canvas_realizedollar(x->a_glist, x->a_symto);
+ if (x->a_symto == &s_)
+ outlet_new(&x->a_text,
+ x->a_atom.a_type == A_FLOAT ? &s_float: &s_symbol);
+ if (x->a_symfrom == &s_)
+ inlet_new(&x->a_text, &x->a_text.te_pd, 0, 0);
+ glist_add(gl, &x->a_text.te_g);
}
else
{
- int xpix, ypix;
- outlet_new(&x->a_text,
- x->a_atom.a_type == A_FLOAT ? &s_float: &s_symbol);
- inlet_new(&x->a_text, &x->a_text.te_pd, 0, 0);
- pd_vmess(&gl->gl_pd, gensym("editmode"), "i", 1);
- glist_noselect(gl);
- glist_getnextxy(gl, &xpix, &ypix);
- x->a_text.te_xpix = xpix;
- x->a_text.te_ypix = ypix;
- glist_add(gl, &x->a_text.te_g);
- glist_noselect(gl);
- glist_select(gl, &x->a_text.te_g);
- canvas_startmotion(glist_getcanvas(gl));
+ int xpix, ypix;
+ outlet_new(&x->a_text,
+ x->a_atom.a_type == A_FLOAT ? &s_float: &s_symbol);
+ inlet_new(&x->a_text, &x->a_text.te_pd, 0, 0);
+ pd_vmess(&gl->gl_pd, gensym("editmode"), "i", 1);
+ glist_noselect(gl);
+ glist_getnextxy(gl, &xpix, &ypix);
+ x->a_text.te_xpix = xpix;
+ x->a_text.te_ypix = ypix;
+ glist_add(gl, &x->a_text.te_g);
+ glist_noselect(gl);
+ glist_select(gl, &x->a_text.te_g);
+ canvas_startmotion(glist_getcanvas(gl));
}
}
@@ -844,8 +851,8 @@ void canvas_symbolatom(t_glist *gl, t_symbol *s, int argc, t_atom *argv)
static void gatom_free(t_gatom *x)
{
if (*x->a_symfrom->s_name)
- pd_unbind(&x->a_text.te_pd,
- canvas_realizedollar(x->a_glist, x->a_symfrom));
+ pd_unbind(&x->a_text.te_pd,
+ canvas_realizedollar(x->a_glist, x->a_symfrom));
gfxstub_deleteforkey(x);
}
@@ -854,10 +861,10 @@ static void gatom_properties(t_gobj *z, t_glist *owner)
t_gatom *x = (t_gatom *)z;
char buf[200];
sprintf(buf, "pdtk_gatom_dialog %%s %d %g %g %d %s %s %s\n",
- x->a_text.te_width, x->a_draglo, x->a_draghi,
- x->a_wherelabel, gatom_escapit(x->a_label)->s_name,
- gatom_escapit(x->a_symfrom)->s_name,
- gatom_escapit(x->a_symto)->s_name);
+ x->a_text.te_width, x->a_draglo, x->a_draghi,
+ x->a_wherelabel, gatom_escapit(x->a_label)->s_name,
+ gatom_escapit(x->a_symfrom)->s_name,
+ gatom_escapit(x->a_symto)->s_name);
gfxstub_new(&x->a_text.te_pd, x, buf);
}
@@ -871,29 +878,29 @@ static void text_getrect(t_gobj *z, t_glist *glist,
int width, height, iscomment = (x->te_type == T_TEXT);
float x1, y1, x2, y2;
- /* for number boxes, we know width and height a priori, and should
- report them here so that graphs can get swelled to fit. */
+ /* for number boxes, we know width and height a priori, and should
+ report them here so that graphs can get swelled to fit. */
if (x->te_type == T_ATOM && x->te_width > 0)
{
- int font = glist_getfont(glist);
- int fontwidth = sys_fontwidth(font), fontheight = sys_fontheight(font);
- width = (x->te_width > 0 ? x->te_width : 6) * fontwidth + 2;
- height = fontheight + 1; /* borrowed from TMARGIN, etc, in g_rtext.c */
+ int font = glist_getfont(glist);
+ int fontwidth = sys_fontwidth(font), fontheight = sys_fontheight(font);
+ width = (x->te_width > 0 ? x->te_width : 6) * fontwidth + 2;
+ height = fontheight + 1; /* borrowed from TMARGIN, etc, in g_rtext.c */
}
- /* if we're invisible we don't know our size so we just lie about
- it. This is called on invisible boxes to establish order of inlets
- and possibly other reasons.
- To find out if the box is visible we can't just check the "vis"
- flag because we might be within the vis() routine and not have set
- that yet. So we check directly whether the "rtext" list has been
- built. LATER reconsider when "vis" flag should be on and off? */
+ /* if we're invisible we don't know our size so we just lie about
+ it. This is called on invisible boxes to establish order of inlets
+ and possibly other reasons.
+ To find out if the box is visible we can't just check the "vis"
+ flag because we might be within the vis() routine and not have set
+ that yet. So we check directly whether the "rtext" list has been
+ built. LATER reconsider when "vis" flag should be on and off? */
else if (glist->gl_editor && glist->gl_editor->e_rtext)
{
- t_rtext *y = glist_findrtext(glist, x);
- width = rtext_width(y);
- height = rtext_height(y) - (iscomment << 1);
+ t_rtext *y = glist_findrtext(glist, x);
+ width = rtext_width(y);
+ height = rtext_height(y) - (iscomment << 1);
}
else width = height = 10;
x1 = text_xpix(x, glist);
@@ -915,11 +922,11 @@ static void text_displace(t_gobj *z, t_glist *glist,
x->te_ypix += dy;
if (glist_isvisible(glist))
{
- t_rtext *y = glist_findrtext(glist, x);
- rtext_displace(y, dx, dy);
- text_drawborder(x, glist, rtext_gettag(y),
- rtext_width(y), rtext_height(y), 0);
- canvas_fixlinesfor(glist_getcanvas(glist), x);
+ t_rtext *y = glist_findrtext(glist, x);
+ rtext_displace(y, dx, dy);
+ text_drawborder(x, glist, rtext_gettag(y),
+ rtext_width(y), rtext_height(y), 0);
+ canvas_fixlinesfor(glist_getcanvas(glist), x);
}
}
@@ -929,8 +936,8 @@ static void text_select(t_gobj *z, t_glist *glist, int state)
t_rtext *y = glist_findrtext(glist, x);
rtext_select(y, state);
if (glist_isvisible(glist) && text_shouldvis(x, glist))
- sys_vgui(".x%x.c itemconfigure %sR -fill %s\n", glist,
- rtext_gettag(y), (state? "blue" : "black"));
+ sys_vgui(".x%lx.c itemconfigure %sR -fill %s\n", glist,
+ rtext_gettag(y), (state? "blue" : "black"));
}
static void text_activate(t_gobj *z, t_glist *glist, int state)
@@ -951,8 +958,8 @@ static void text_delete(t_gobj *z, t_glist *glist)
int text_shouldvis(t_text *x, t_glist *glist)
{
return (glist->gl_havewindow ||
- (x->te_pd != canvas_class && x->te_pd->c_wb != &text_widgetbehavior) ||
- (x->te_pd == canvas_class && (((t_glist *)x)->gl_isgraph)));
+ (x->te_pd != canvas_class && x->te_pd->c_wb != &text_widgetbehavior) ||
+ (x->te_pd == canvas_class && (((t_glist *)x)->gl_isgraph)));
}
static void text_vis(t_gobj *z, t_glist *glist, int vis)
@@ -960,24 +967,24 @@ static void text_vis(t_gobj *z, t_glist *glist, int vis)
t_text *x = (t_text *)z;
if (vis)
{
- if (text_shouldvis(x, glist))
- {
- t_rtext *y = glist_findrtext(glist, x);
- if (x->te_type == T_ATOM)
- glist_retext(glist, x);
- text_drawborder(x, glist, rtext_gettag(y),
- rtext_width(y), rtext_height(y), 1);
- rtext_draw(y);
- }
+ if (text_shouldvis(x, glist))
+ {
+ t_rtext *y = glist_findrtext(glist, x);
+ if (x->te_type == T_ATOM)
+ glist_retext(glist, x);
+ text_drawborder(x, glist, rtext_gettag(y),
+ rtext_width(y), rtext_height(y), 1);
+ rtext_draw(y);
+ }
}
else
{
- t_rtext *y = glist_findrtext(glist, x);
- if (text_shouldvis(x, glist))
- {
- text_eraseborder(x, glist, rtext_gettag(y));
- rtext_erase(y);
- }
+ t_rtext *y = glist_findrtext(glist, x);
+ if (text_shouldvis(x, glist))
+ {
+ text_eraseborder(x, glist, rtext_gettag(y));
+ rtext_erase(y);
+ }
}
}
@@ -987,30 +994,30 @@ static int text_click(t_gobj *z, struct _glist *glist,
t_text *x = (t_text *)z;
if (x->te_type == T_OBJECT)
{
- t_symbol *clicksym = gensym("click");
- if (zgetfn(&x->te_pd, clicksym))
- {
- if (doit)
- pd_vmess(&x->te_pd, clicksym, "fffff",
- (double)xpix, (double)ypix,
- (double)shift, 0, (double)alt);
- return (1);
- }
- else return (0);
+ t_symbol *clicksym = gensym("click");
+ if (zgetfn(&x->te_pd, clicksym))
+ {
+ if (doit)
+ pd_vmess(&x->te_pd, clicksym, "fffff",
+ (double)xpix, (double)ypix,
+ (double)shift, 0, (double)alt);
+ return (1);
+ }
+ else return (0);
}
else if (x->te_type == T_ATOM)
{
- if (doit)
- gatom_click((t_gatom *)x, (t_floatarg)xpix, (t_floatarg)ypix,
- (t_floatarg)shift, 0, (t_floatarg)alt);
- return (1);
+ if (doit)
+ gatom_click((t_gatom *)x, (t_floatarg)xpix, (t_floatarg)ypix,
+ (t_floatarg)shift, 0, (t_floatarg)alt);
+ return (1);
}
else if (x->te_type == T_MESSAGE)
{
- if (doit)
- message_click((t_message *)x, (t_floatarg)xpix, (t_floatarg)ypix,
- (t_floatarg)shift, 0, (t_floatarg)alt);
- return (1);
+ if (doit)
+ message_click((t_message *)x, (t_floatarg)xpix, (t_floatarg)ypix,
+ (t_floatarg)shift, 0, (t_floatarg)alt);
+ return (1);
}
else return (0);
}
@@ -1020,55 +1027,55 @@ void text_save(t_gobj *z, t_binbuf *b)
t_text *x = (t_text *)z;
if (x->te_type == T_OBJECT)
{
- /* if we have a "saveto" method, and if we don't happen to be
- a canvas that's an abstraction, the saveto method does the work */
- if (zgetfn(&x->te_pd, gensym("saveto")) &&
- !((pd_class(&x->te_pd) == canvas_class) &&
- (canvas_isabstraction((t_canvas *)x)
- || canvas_istable((t_canvas *)x))))
- {
- mess1(&x->te_pd, gensym("saveto"), b);
- binbuf_addv(b, "ssii", gensym("#X"), gensym("restore"),
- (t_int)x->te_xpix, (t_int)x->te_ypix);
- }
- else /* otherwise just save the text */
- {
- binbuf_addv(b, "ssii", gensym("#X"), gensym("obj"),
- (t_int)x->te_xpix, (t_int)x->te_ypix);
+ /* if we have a "saveto" method, and if we don't happen to be
+ a canvas that's an abstraction, the saveto method does the work */
+ if (zgetfn(&x->te_pd, gensym("saveto")) &&
+ !((pd_class(&x->te_pd) == canvas_class) &&
+ (canvas_isabstraction((t_canvas *)x)
+ || canvas_istable((t_canvas *)x))))
+ {
+ mess1(&x->te_pd, gensym("saveto"), b);
+ binbuf_addv(b, "ssii", gensym("#X"), gensym("restore"),
+ (int)x->te_xpix, (int)x->te_ypix);
+ }
+ else /* otherwise just save the text */
+ {
+ binbuf_addv(b, "ssii", gensym("#X"), gensym("obj"),
+ (int)x->te_xpix, (int)x->te_ypix);
}
binbuf_addbinbuf(b, x->te_binbuf);
binbuf_addv(b, ";");
}
else if (x->te_type == T_MESSAGE)
{
- binbuf_addv(b, "ssii", gensym("#X"), gensym("msg"),
- (t_int)x->te_xpix, (t_int)x->te_ypix);
+ binbuf_addv(b, "ssii", gensym("#X"), gensym("msg"),
+ (int)x->te_xpix, (int)x->te_ypix);
binbuf_addbinbuf(b, x->te_binbuf);
binbuf_addv(b, ";");
}
else if (x->te_type == T_ATOM)
{
- t_atomtype t = ((t_gatom *)x)->a_atom.a_type;
- t_symbol *sel = (t == A_SYMBOL ? gensym("symbolatom") :
- (t == A_FLOAT ? gensym("floatatom") : gensym("intatom")));
- t_symbol *label = gatom_escapit(((t_gatom *)x)->a_label);
- t_symbol *symfrom = gatom_escapit(((t_gatom *)x)->a_symfrom);
- t_symbol *symto = gatom_escapit(((t_gatom *)x)->a_symto);
- binbuf_addv(b, "ssiiifffsss", gensym("#X"), sel,
- (t_int)x->te_xpix, (t_int)x->te_ypix, (t_int)x->te_width,
- (double)((t_gatom *)x)->a_draglo,
- (double)((t_gatom *)x)->a_draghi,
- (double)((t_gatom *)x)->a_wherelabel,
- label, symfrom, symto);
+ t_atomtype t = ((t_gatom *)x)->a_atom.a_type;
+ t_symbol *sel = (t == A_SYMBOL ? gensym("symbolatom") :
+ (t == A_FLOAT ? gensym("floatatom") : gensym("intatom")));
+ t_symbol *label = gatom_escapit(((t_gatom *)x)->a_label);
+ t_symbol *symfrom = gatom_escapit(((t_gatom *)x)->a_symfrom);
+ t_symbol *symto = gatom_escapit(((t_gatom *)x)->a_symto);
+ binbuf_addv(b, "ssiiifffsss", gensym("#X"), sel,
+ (int)x->te_xpix, (int)x->te_ypix, (int)x->te_width,
+ (double)((t_gatom *)x)->a_draglo,
+ (double)((t_gatom *)x)->a_draghi,
+ (double)((t_gatom *)x)->a_wherelabel,
+ label, symfrom, symto);
binbuf_addv(b, ";");
- }
- else
+ }
+ else
{
- binbuf_addv(b, "ssii", gensym("#X"), gensym("text"),
- (t_int)x->te_xpix, (t_int)x->te_ypix);
+ binbuf_addv(b, "ssii", gensym("#X"), gensym("text"),
+ (int)x->te_xpix, (int)x->te_ypix);
binbuf_addbinbuf(b, x->te_binbuf);
binbuf_addv(b, ";");
- }
+ }
}
/* this one is for everyone but "gatoms"; it's imposed in m_class.c */
@@ -1110,35 +1117,35 @@ void glist_drawiofor(t_glist *glist, t_object *ob, int firsttime,
int width = x2 - x1;
for (i = 0; i < n; i++)
{
- int onset = x1 + (width - IOWIDTH) * i / nplus;
- if (firsttime)
- sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %so%d\n",
- glist_getcanvas(glist),
- onset, y2 - 1,
- onset + IOWIDTH, y2,
- tag, i);
- else
- sys_vgui(".x%x.c coords %so%d %d %d %d %d\n",
- glist_getcanvas(glist), tag, i,
- onset, y2 - 1,
- onset + IOWIDTH, y2);
+ int onset = x1 + (width - IOWIDTH) * i / nplus;
+ if (firsttime)
+ sys_vgui(".x%lx.c create rectangle %d %d %d %d -tags %so%d\n",
+ glist_getcanvas(glist),
+ onset, y2 - 1,
+ onset + IOWIDTH, y2,
+ tag, i);
+ else
+ sys_vgui(".x%lx.c coords %so%d %d %d %d %d\n",
+ glist_getcanvas(glist), tag, i,
+ onset, y2 - 1,
+ onset + IOWIDTH, y2);
}
n = obj_ninlets(ob);
nplus = (n == 1 ? 1 : n-1);
for (i = 0; i < n; i++)
{
- int onset = x1 + (width - IOWIDTH) * i / nplus;
- if (firsttime)
- sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %si%d\n",
- glist_getcanvas(glist),
- onset, y1,
- onset + IOWIDTH, y1 + EXTRAPIX,
- tag, i);
- else
- sys_vgui(".x%x.c coords %si%d %d %d %d %d\n",
- glist_getcanvas(glist), tag, i,
- onset, y1,
- onset + IOWIDTH, y1 + EXTRAPIX);
+ int onset = x1 + (width - IOWIDTH) * i / nplus;
+ if (firsttime)
+ sys_vgui(".x%lx.c create rectangle %d %d %d %d -tags %si%d\n",
+ glist_getcanvas(glist),
+ onset, y1,
+ onset + IOWIDTH, y1 + EXTRAPIX,
+ tag, i);
+ else
+ sys_vgui(".x%lx.c coords %si%d %d %d %d %d\n",
+ glist_getcanvas(glist), tag, i,
+ onset, y1,
+ onset + IOWIDTH, y1 + EXTRAPIX);
}
}
@@ -1152,51 +1159,55 @@ void text_drawborder(t_text *x, t_glist *glist,
height = y2 - y1;
if (x->te_type == T_OBJECT)
{
- if (firsttime)
- sys_vgui(".x%x.c create line\
- %d %d %d %d %d %d %d %d %d %d -tags %sR\n",
- glist_getcanvas(glist),
- x1, y1, x2, y1, x2, y2, x1, y2, x1, y1, tag);
- else
- sys_vgui(".x%x.c coords %sR\
+ char *pattern = ((pd_class(&x->te_pd) == text_class) ? "." : "\"\"");
+ if (firsttime)
+ sys_vgui(".x%lx.c create line\
+ %d %d %d %d %d %d %d %d %d %d -dash %s -tags %sR\n",
+ glist_getcanvas(glist),
+ x1, y1, x2, y1, x2, y2, x1, y2, x1, y1, pattern, tag);
+ else
+ {
+ sys_vgui(".x%lx.c coords %sR\
%d %d %d %d %d %d %d %d %d %d\n",
- glist_getcanvas(glist), tag,
- x1, y1, x2, y1, x2, y2, x1, y2, x1, y1);
+ glist_getcanvas(glist), tag,
+ x1, y1, x2, y1, x2, y2, x1, y2, x1, y1);
+ sys_vgui(".x%lx.c itemconfigure -dash %s\n", pattern);
+ }
}
else if (x->te_type == T_MESSAGE)
{
- if (firsttime)
- sys_vgui(".x%x.c create line\
+ if (firsttime)
+ sys_vgui(".x%lx.c create line\
%d %d %d %d %d %d %d %d %d %d %d %d %d %d -tags %sR\n",
- glist_getcanvas(glist),
- x1, y1, x2+4, y1, x2, y1+4, x2, y2-4, x2+4, y2,
- x1, y2, x1, y1,
- tag);
- else
- sys_vgui(".x%x.c coords %sR\
+ glist_getcanvas(glist),
+ x1, y1, x2+4, y1, x2, y1+4, x2, y2-4, x2+4, y2,
+ x1, y2, x1, y1,
+ tag);
+ else
+ sys_vgui(".x%lx.c coords %sR\
%d %d %d %d %d %d %d %d %d %d %d %d %d %d\n",
- glist_getcanvas(glist), tag,
- x1, y1, x2+4, y1, x2, y1+4, x2, y2-4, x2+4, y2,
- x1, y2, x1, y1);
+ glist_getcanvas(glist), tag,
+ x1, y1, x2+4, y1, x2, y1+4, x2, y2-4, x2+4, y2,
+ x1, y2, x1, y1);
}
else if (x->te_type == T_ATOM)
{
- if (firsttime)
- sys_vgui(".x%x.c create line\
+ if (firsttime)
+ sys_vgui(".x%lx.c create line\
%d %d %d %d %d %d %d %d %d %d %d %d -tags %sR\n",
- glist_getcanvas(glist),
- x1, y1, x2-4, y1, x2, y1+4, x2, y2, x1, y2, x1, y1,
- tag);
- else
- sys_vgui(".x%x.c coords %sR\
+ glist_getcanvas(glist),
+ x1, y1, x2-4, y1, x2, y1+4, x2, y2, x1, y2, x1, y1,
+ tag);
+ else
+ sys_vgui(".x%lx.c coords %sR\
%d %d %d %d %d %d %d %d %d %d %d %d\n",
- glist_getcanvas(glist), tag,
- x1, y1, x2-4, y1, x2, y1+4, x2, y2, x1, y2, x1, y1);
+ glist_getcanvas(glist), tag,
+ x1, y1, x2-4, y1, x2, y1+4, x2, y2, x1, y2, x1, y1);
}
- /* draw inlets/outlets */
+ /* draw inlets/outlets */
if (ob = pd_checkobject(&x->te_pd))
- glist_drawiofor(glist, ob, firsttime, tag, x1, y1, x2, y2);
+ glist_drawiofor(glist, ob, firsttime, tag, x1, y1, x2, y2);
}
void glist_eraseiofor(t_glist *glist, t_object *ob, char *tag)
@@ -1204,19 +1215,19 @@ void glist_eraseiofor(t_glist *glist, t_object *ob, char *tag)
int i, n;
n = obj_noutlets(ob);
for (i = 0; i < n; i++)
- sys_vgui(".x%x.c delete %so%d\n",
- glist_getcanvas(glist), tag, i);
+ sys_vgui(".x%lx.c delete %so%d\n",
+ glist_getcanvas(glist), tag, i);
n = obj_ninlets(ob);
for (i = 0; i < n; i++)
- sys_vgui(".x%x.c delete %si%d\n",
- glist_getcanvas(glist), tag, i);
+ sys_vgui(".x%lx.c delete %si%d\n",
+ glist_getcanvas(glist), tag, i);
}
void text_eraseborder(t_text *x, t_glist *glist, char *tag)
{
if (x->te_type == T_TEXT) return;
- sys_vgui(".x%x.c delete %sR\n",
- glist_getcanvas(glist), tag);
+ sys_vgui(".x%lx.c delete %sR\n",
+ glist_getcanvas(glist), tag);
glist_eraseiofor(glist, x, tag);
}
@@ -1227,39 +1238,39 @@ void text_setto(t_text *x, t_glist *glist, char *buf, int bufsize)
{
if (x->te_type == T_OBJECT)
{
- t_binbuf *b = binbuf_new();
- int natom1, natom2;
- t_atom *vec1, *vec2;
- binbuf_text(b, buf, bufsize);
- natom1 = binbuf_getnatom(x->te_binbuf);
- vec1 = binbuf_getvec(x->te_binbuf);
- natom2 = binbuf_getnatom(b);
- vec2 = binbuf_getvec(b);
- /* special case: if pd args change just pass the message on. */
- if (natom1 >= 1 && natom2 >= 1 && vec1[0].a_type == A_SYMBOL
- && !strcmp(vec1[0].a_w.w_symbol->s_name, "pd") &&
- vec2[0].a_type == A_SYMBOL
- && !strcmp(vec2[0].a_w.w_symbol->s_name, "pd"))
- {
- typedmess(&x->te_pd, gensym("rename"), natom2-1, vec2+1);
- binbuf_free(x->te_binbuf);
- x->te_binbuf = b;
- }
- else /* normally, just destroy the old one and make a new one. */
- {
- int xwas = x->te_xpix, ywas = x->te_ypix;
- glist_delete(glist, &x->te_g);
- canvas_objtext(glist, xwas, ywas, 0, b);
- /* if it's an abstraction loadbang it here */
- if (newest && pd_class(newest) == canvas_class)
- canvas_loadbang((t_canvas *)newest);
- canvas_restoreconnections(glist_getcanvas(glist));
- }
- /* if we made a new "pd" or changed a window name,
- update window list */
- if (natom2 >= 1 && vec2[0].a_type == A_SYMBOL
- && !strcmp(vec2[0].a_w.w_symbol->s_name, "pd"))
- canvas_updatewindowlist();
+ t_binbuf *b = binbuf_new();
+ int natom1, natom2;
+ t_atom *vec1, *vec2;
+ binbuf_text(b, buf, bufsize);
+ natom1 = binbuf_getnatom(x->te_binbuf);
+ vec1 = binbuf_getvec(x->te_binbuf);
+ natom2 = binbuf_getnatom(b);
+ vec2 = binbuf_getvec(b);
+ /* special case: if pd args change just pass the message on. */
+ if (natom1 >= 1 && natom2 >= 1 && vec1[0].a_type == A_SYMBOL
+ && !strcmp(vec1[0].a_w.w_symbol->s_name, "pd") &&
+ vec2[0].a_type == A_SYMBOL
+ && !strcmp(vec2[0].a_w.w_symbol->s_name, "pd"))
+ {
+ typedmess(&x->te_pd, gensym("rename"), natom2-1, vec2+1);
+ binbuf_free(x->te_binbuf);
+ x->te_binbuf = b;
+ }
+ else /* normally, just destroy the old one and make a new one. */
+ {
+ int xwas = x->te_xpix, ywas = x->te_ypix;
+ glist_delete(glist, &x->te_g);
+ canvas_objtext(glist, xwas, ywas, 0, b);
+ /* if it's an abstraction loadbang it here */
+ if (newest && pd_class(newest) == canvas_class)
+ canvas_loadbang((t_canvas *)newest);
+ canvas_restoreconnections(glist_getcanvas(glist));
+ }
+ /* if we made a new "pd" or changed a window name,
+ update window list */
+ if (natom2 >= 1 && vec2[0].a_type == A_SYMBOL
+ && !strcmp(vec2[0].a_w.w_symbol->s_name, "pd"))
+ canvas_updatewindowlist();
}
else binbuf_text(x->te_binbuf, buf, bufsize);
}
@@ -1267,10 +1278,10 @@ void text_setto(t_text *x, t_glist *glist, char *buf, int bufsize)
void g_text_setup(void)
{
text_class = class_new(gensym("text"), 0, 0, sizeof(t_text),
- CLASS_NOINLET | CLASS_PATCHABLE, 0);
+ CLASS_NOINLET | CLASS_PATCHABLE, 0);
message_class = class_new(gensym("message"), 0, (t_method)message_free,
- sizeof(t_message), CLASS_PATCHABLE, 0);
+ sizeof(t_message), CLASS_PATCHABLE, 0);
class_addbang(message_class, message_bang);
class_addfloat(message_class, message_float);
class_addsymbol(message_class, message_symbol);
@@ -1278,16 +1289,16 @@ void g_text_setup(void)
class_addanything(message_class, message_list);
class_addmethod(message_class, (t_method)message_click, gensym("click"),
- A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, 0);
+ A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, 0);
class_addmethod(message_class, (t_method)message_set, gensym("set"),
- A_GIMME, 0);
+ A_GIMME, 0);
class_addmethod(message_class, (t_method)message_add, gensym("add"),
- A_GIMME, 0);
+ A_GIMME, 0);
class_addmethod(message_class, (t_method)message_add2, gensym("add2"),
- A_GIMME, 0);
+ A_GIMME, 0);
messresponder_class = class_new(gensym("messresponder"), 0, 0,
- sizeof(t_text), CLASS_PD, 0);
+ sizeof(t_text), CLASS_PD, 0);
class_addbang(messresponder_class, messresponder_bang);
class_addfloat(messresponder_class, (t_method) messresponder_float);
class_addsymbol(messresponder_class, messresponder_symbol);
@@ -1295,16 +1306,16 @@ void g_text_setup(void)
class_addanything(messresponder_class, messresponder_anything);
gatom_class = class_new(gensym("gatom"), 0, (t_method)gatom_free,
- sizeof(t_gatom), CLASS_NOINLET | CLASS_PATCHABLE, 0);
+ sizeof(t_gatom), CLASS_NOINLET | CLASS_PATCHABLE, 0);
class_addbang(gatom_class, gatom_bang);
class_addfloat(gatom_class, gatom_float);
class_addsymbol(gatom_class, gatom_symbol);
class_addmethod(gatom_class, (t_method)gatom_set, gensym("set"),
- A_GIMME, 0);
+ A_GIMME, 0);
class_addmethod(gatom_class, (t_method)gatom_click, gensym("click"),
- A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, 0);
+ A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, 0);
class_addmethod(gatom_class, (t_method)gatom_param, gensym("param"),
- A_GIMME, 0);
+ A_GIMME, 0);
class_setwidget(gatom_class, &gatom_widgetbehavior);
class_setpropertiesfn(gatom_class, gatom_properties);
}
diff --git a/pd/src/g_toggle.c b/pd/src/g_toggle.c
index 5369e468..efed91e2 100644
--- a/pd/src/g_toggle.c
+++ b/pd/src/g_toggle.c
@@ -33,12 +33,12 @@ void toggle_draw_update(t_toggle *x, t_glist *glist)
{
if(glist_isvisible(glist))
{
- t_canvas *canvas=glist_getcanvas(glist);
+ t_canvas *canvas=glist_getcanvas(glist);
- sys_vgui(".x%x.c itemconfigure %xX1 -fill #%6.6x\n", canvas, x,
- (x->x_on!=0.0)?x->x_gui.x_fcol:x->x_gui.x_bcol);
- sys_vgui(".x%x.c itemconfigure %xX2 -fill #%6.6x\n", canvas, x,
- (x->x_on!=0.0)?x->x_gui.x_fcol:x->x_gui.x_bcol);
+ sys_vgui(".x%lx.c itemconfigure %lxX1 -fill #%6.6x\n", canvas, x,
+ (x->x_on!=0.0)?x->x_gui.x_fcol:x->x_gui.x_bcol);
+ sys_vgui(".x%lx.c itemconfigure %lxX2 -fill #%6.6x\n", canvas, x,
+ (x->x_on!=0.0)?x->x_gui.x_fcol:x->x_gui.x_bcol);
}
}
@@ -48,30 +48,30 @@ void toggle_draw_new(t_toggle *x, t_glist *glist)
int w=1, xx=text_xpix(&x->x_gui.x_obj, glist), yy=text_ypix(&x->x_gui.x_obj, glist);
if(x->x_gui.x_w >= 30)
- w = 2;
+ w = 2;
if(x->x_gui.x_w >= 60)
- w = 3;
- sys_vgui(".x%x.c create rectangle %d %d %d %d -fill #%6.6x -tags %xBASE\n",
- canvas, xx, yy, xx + x->x_gui.x_w, yy + x->x_gui.x_h,
- x->x_gui.x_bcol, x);
- sys_vgui(".x%x.c create line %d %d %d %d -width %d -fill #%6.6x -tags %xX1\n",
- canvas, xx+w+1, yy+w+1, xx + x->x_gui.x_w-w, yy + x->x_gui.x_h-w, w,
- (x->x_on!=0.0)?x->x_gui.x_fcol:x->x_gui.x_bcol, x);
- sys_vgui(".x%x.c create line %d %d %d %d -width %d -fill #%6.6x -tags %xX2\n",
- canvas, xx+w+1, yy + x->x_gui.x_h-w-1, xx + x->x_gui.x_w-w, yy+w, w,
- (x->x_on!=0.0)?x->x_gui.x_fcol:x->x_gui.x_bcol, x);
- sys_vgui(".x%x.c create text %d %d -text {%s} -anchor w \
- -font {%s %d bold} -fill #%6.6x -tags %xLABEL\n",
- canvas, xx+x->x_gui.x_ldx,
- yy+x->x_gui.x_ldy,
- strcmp(x->x_gui.x_lab->s_name, "empty")?x->x_gui.x_lab->s_name:"",
- x->x_gui.x_font, x->x_gui.x_fontsize, x->x_gui.x_lcol, x);
+ w = 3;
+ sys_vgui(".x%lx.c create rectangle %d %d %d %d -fill #%6.6x -tags %lxBASE\n",
+ canvas, xx, yy, xx + x->x_gui.x_w, yy + x->x_gui.x_h,
+ x->x_gui.x_bcol, x);
+ sys_vgui(".x%lx.c create line %d %d %d %d -width %d -fill #%6.6x -tags %lxX1\n",
+ canvas, xx+w+1, yy+w+1, xx + x->x_gui.x_w-w, yy + x->x_gui.x_h-w, w,
+ (x->x_on!=0.0)?x->x_gui.x_fcol:x->x_gui.x_bcol, x);
+ sys_vgui(".x%lx.c create line %d %d %d %d -width %d -fill #%6.6x -tags %lxX2\n",
+ canvas, xx+w+1, yy + x->x_gui.x_h-w-1, xx + x->x_gui.x_w-w, yy+w, w,
+ (x->x_on!=0.0)?x->x_gui.x_fcol:x->x_gui.x_bcol, x);
+ sys_vgui(".x%lx.c create text %d %d -text {%s} -anchor w \
+ -font {%s %d bold} -fill #%6.6x -tags %lxLABEL\n",
+ canvas, xx+x->x_gui.x_ldx,
+ yy+x->x_gui.x_ldy,
+ strcmp(x->x_gui.x_lab->s_name, "empty")?x->x_gui.x_lab->s_name:"",
+ x->x_gui.x_font, x->x_gui.x_fontsize, x->x_gui.x_lcol, x);
if(!x->x_gui.x_fsf.x_snd_able)
- sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xOUT%d\n",
- canvas, xx, yy + x->x_gui.x_h-1, xx + IOWIDTH, yy + x->x_gui.x_h, x, 0);
+ sys_vgui(".x%lx.c create rectangle %d %d %d %d -tags %lxOUT%d\n",
+ canvas, xx, yy + x->x_gui.x_h-1, xx + IOWIDTH, yy + x->x_gui.x_h, x, 0);
if(!x->x_gui.x_fsf.x_rcv_able)
- sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xIN%d\n",
- canvas, xx, yy, xx + IOWIDTH, yy+1, x, 0);
+ sys_vgui(".x%lx.c create rectangle %d %d %d %d -tags %lxIN%d\n",
+ canvas, xx, yy, xx + IOWIDTH, yy+1, x, 0);
}
void toggle_draw_move(t_toggle *x, t_glist *glist)
@@ -80,56 +80,56 @@ void toggle_draw_move(t_toggle *x, t_glist *glist)
int w=1, xx=text_xpix(&x->x_gui.x_obj, glist), yy=text_ypix(&x->x_gui.x_obj, glist);
if(x->x_gui.x_w >= 30)
- w = 2;
+ w = 2;
if(x->x_gui.x_w >= 60)
- w = 3;
- sys_vgui(".x%x.c coords %xBASE %d %d %d %d\n",
- canvas, x, xx, yy, xx + x->x_gui.x_w, yy + x->x_gui.x_h);
- sys_vgui(".x%x.c itemconfigure %xX1 -width %d\n", canvas, x, w);
- sys_vgui(".x%x.c coords %xX1 %d %d %d %d\n",
- canvas, x, xx+w+1, yy+w+1, xx + x->x_gui.x_w-w, yy + x->x_gui.x_h-w);
- sys_vgui(".x%x.c itemconfigure %xX2 -width %d\n", canvas, x, w);
- sys_vgui(".x%x.c coords %xX2 %d %d %d %d\n",
- canvas, x, xx+w+1, yy + x->x_gui.x_h-w-1, xx + x->x_gui.x_w-w, yy+w);
- sys_vgui(".x%x.c coords %xLABEL %d %d\n",
- canvas, x, xx+x->x_gui.x_ldx, yy+x->x_gui.x_ldy);
+ w = 3;
+ sys_vgui(".x%lx.c coords %lxBASE %d %d %d %d\n",
+ canvas, x, xx, yy, xx + x->x_gui.x_w, yy + x->x_gui.x_h);
+ sys_vgui(".x%lx.c itemconfigure %lxX1 -width %d\n", canvas, x, w);
+ sys_vgui(".x%lx.c coords %lxX1 %d %d %d %d\n",
+ canvas, x, xx+w+1, yy+w+1, xx + x->x_gui.x_w-w, yy + x->x_gui.x_h-w);
+ sys_vgui(".x%lx.c itemconfigure %lxX2 -width %d\n", canvas, x, w);
+ sys_vgui(".x%lx.c coords %lxX2 %d %d %d %d\n",
+ canvas, x, xx+w+1, yy + x->x_gui.x_h-w-1, xx + x->x_gui.x_w-w, yy+w);
+ sys_vgui(".x%lx.c coords %lxLABEL %d %d\n",
+ canvas, x, xx+x->x_gui.x_ldx, yy+x->x_gui.x_ldy);
if(!x->x_gui.x_fsf.x_snd_able)
- sys_vgui(".x%x.c coords %xOUT%d %d %d %d %d\n",
- canvas, x, 0, xx, yy + x->x_gui.x_h-1, xx + IOWIDTH, yy + x->x_gui.x_h);
+ sys_vgui(".x%lx.c coords %lxOUT%d %d %d %d %d\n",
+ canvas, x, 0, xx, yy + x->x_gui.x_h-1, xx + IOWIDTH, yy + x->x_gui.x_h);
if(!x->x_gui.x_fsf.x_rcv_able)
- sys_vgui(".x%x.c coords %xIN%d %d %d %d %d\n",
- canvas, x, 0, xx, yy, xx + IOWIDTH, yy+1);
+ sys_vgui(".x%lx.c coords %lxIN%d %d %d %d %d\n",
+ canvas, x, 0, xx, yy, xx + IOWIDTH, yy+1);
}
void toggle_draw_erase(t_toggle* x, t_glist* glist)
{
t_canvas *canvas=glist_getcanvas(glist);
- sys_vgui(".x%x.c delete %xBASE\n", canvas, x);
- sys_vgui(".x%x.c delete %xX1\n", canvas, x);
- sys_vgui(".x%x.c delete %xX2\n", canvas, x);
- sys_vgui(".x%x.c delete %xLABEL\n", canvas, x);
+ sys_vgui(".x%lx.c delete %lxBASE\n", canvas, x);
+ sys_vgui(".x%lx.c delete %lxX1\n", canvas, x);
+ sys_vgui(".x%lx.c delete %lxX2\n", canvas, x);
+ sys_vgui(".x%lx.c delete %lxLABEL\n", canvas, x);
if(!x->x_gui.x_fsf.x_snd_able)
- sys_vgui(".x%x.c delete %xOUT%d\n", canvas, x, 0);
+ sys_vgui(".x%lx.c delete %lxOUT%d\n", canvas, x, 0);
if(!x->x_gui.x_fsf.x_rcv_able)
- sys_vgui(".x%x.c delete %xIN%d\n", canvas, x, 0);
+ sys_vgui(".x%lx.c delete %lxIN%d\n", canvas, x, 0);
}
void toggle_draw_config(t_toggle* x, t_glist* glist)
{
t_canvas *canvas=glist_getcanvas(glist);
- sys_vgui(".x%x.c itemconfigure %xLABEL -font {%s %d bold} -fill #%6.6x -text {%s} \n",
- canvas, x, x->x_gui.x_font, x->x_gui.x_fontsize,
- x->x_gui.x_fsf.x_selected?IEM_GUI_COLOR_SELECTED:x->x_gui.x_lcol,
- strcmp(x->x_gui.x_lab->s_name, "empty")?x->x_gui.x_lab->s_name:"");
- sys_vgui(".x%x.c itemconfigure %xBASE -fill #%6.6x\n", canvas, x,
- x->x_gui.x_bcol);
- sys_vgui(".x%x.c itemconfigure %xX1 -fill #%6.6x\n", canvas, x,
- x->x_on?x->x_gui.x_fcol:x->x_gui.x_bcol);
- sys_vgui(".x%x.c itemconfigure %xX2 -fill #%6.6x\n", canvas, x,
- x->x_on?x->x_gui.x_fcol:x->x_gui.x_bcol);
+ sys_vgui(".x%lx.c itemconfigure %lxLABEL -font {%s %d bold} -fill #%6.6x -text {%s} \n",
+ canvas, x, x->x_gui.x_font, x->x_gui.x_fontsize,
+ x->x_gui.x_fsf.x_selected?IEM_GUI_COLOR_SELECTED:x->x_gui.x_lcol,
+ strcmp(x->x_gui.x_lab->s_name, "empty")?x->x_gui.x_lab->s_name:"");
+ sys_vgui(".x%lx.c itemconfigure %lxBASE -fill #%6.6x\n", canvas, x,
+ x->x_gui.x_bcol);
+ sys_vgui(".x%lx.c itemconfigure %lxX1 -fill #%6.6x\n", canvas, x,
+ x->x_on?x->x_gui.x_fcol:x->x_gui.x_bcol);
+ sys_vgui(".x%lx.c itemconfigure %lxX2 -fill #%6.6x\n", canvas, x,
+ x->x_on?x->x_gui.x_fcol:x->x_gui.x_bcol);
}
void toggle_draw_io(t_toggle* x, t_glist* glist, int old_snd_rcv_flags)
@@ -139,18 +139,18 @@ void toggle_draw_io(t_toggle* x, t_glist* glist, int old_snd_rcv_flags)
t_canvas *canvas=glist_getcanvas(glist);
if((old_snd_rcv_flags & IEM_GUI_OLD_SND_FLAG) && !x->x_gui.x_fsf.x_snd_able)
- sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xOUT%d\n",
- canvas, xpos,
- ypos + x->x_gui.x_h-1, xpos + IOWIDTH,
- ypos + x->x_gui.x_h, x, 0);
+ sys_vgui(".x%lx.c create rectangle %d %d %d %d -tags %lxOUT%d\n",
+ canvas, xpos,
+ ypos + x->x_gui.x_h-1, xpos + IOWIDTH,
+ ypos + x->x_gui.x_h, x, 0);
if(!(old_snd_rcv_flags & IEM_GUI_OLD_SND_FLAG) && x->x_gui.x_fsf.x_snd_able)
- sys_vgui(".x%x.c delete %xOUT%d\n", canvas, x, 0);
+ sys_vgui(".x%lx.c delete %lxOUT%d\n", canvas, x, 0);
if((old_snd_rcv_flags & IEM_GUI_OLD_RCV_FLAG) && !x->x_gui.x_fsf.x_rcv_able)
- sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xIN%d\n",
- canvas, xpos, ypos,
- xpos + IOWIDTH, ypos+1, x, 0);
+ sys_vgui(".x%lx.c create rectangle %d %d %d %d -tags %lxIN%d\n",
+ canvas, xpos, ypos,
+ xpos + IOWIDTH, ypos+1, x, 0);
if(!(old_snd_rcv_flags & IEM_GUI_OLD_RCV_FLAG) && x->x_gui.x_fsf.x_rcv_able)
- sys_vgui(".x%x.c delete %xIN%d\n", canvas, x, 0);
+ sys_vgui(".x%lx.c delete %lxIN%d\n", canvas, x, 0);
}
void toggle_draw_select(t_toggle* x, t_glist* glist)
@@ -159,32 +159,32 @@ void toggle_draw_select(t_toggle* x, t_glist* glist)
if(x->x_gui.x_fsf.x_selected)
{
- sys_vgui(".x%x.c itemconfigure %xBASE -outline #%6.6x\n", canvas, x, IEM_GUI_COLOR_SELECTED);
- sys_vgui(".x%x.c itemconfigure %xLABEL -fill #%6.6x\n", canvas, x, IEM_GUI_COLOR_SELECTED);
+ sys_vgui(".x%lx.c itemconfigure %lxBASE -outline #%6.6x\n", canvas, x, IEM_GUI_COLOR_SELECTED);
+ sys_vgui(".x%lx.c itemconfigure %lxLABEL -fill #%6.6x\n", canvas, x, IEM_GUI_COLOR_SELECTED);
}
else
{
- sys_vgui(".x%x.c itemconfigure %xBASE -outline #%6.6x\n", canvas, x, IEM_GUI_COLOR_NORMAL);
- sys_vgui(".x%x.c itemconfigure %xLABEL -fill #%6.6x\n", canvas, x, x->x_gui.x_lcol);
+ sys_vgui(".x%lx.c itemconfigure %lxBASE -outline #%6.6x\n", canvas, x, IEM_GUI_COLOR_NORMAL);
+ sys_vgui(".x%lx.c itemconfigure %lxLABEL -fill #%6.6x\n", canvas, x, x->x_gui.x_lcol);
}
}
void toggle_draw(t_toggle *x, t_glist *glist, int mode)
{
if(mode == IEM_GUI_DRAW_MODE_UPDATE)
- toggle_draw_update(x, glist);
+ toggle_draw_update(x, glist);
else if(mode == IEM_GUI_DRAW_MODE_MOVE)
- toggle_draw_move(x, glist);
+ toggle_draw_move(x, glist);
else if(mode == IEM_GUI_DRAW_MODE_NEW)
- toggle_draw_new(x, glist);
+ toggle_draw_new(x, glist);
else if(mode == IEM_GUI_DRAW_MODE_SELECT)
- toggle_draw_select(x, glist);
+ toggle_draw_select(x, glist);
else if(mode == IEM_GUI_DRAW_MODE_ERASE)
- toggle_draw_erase(x, glist);
+ toggle_draw_erase(x, glist);
else if(mode == IEM_GUI_DRAW_MODE_CONFIG)
- toggle_draw_config(x, glist);
+ toggle_draw_config(x, glist);
else if(mode >= IEM_GUI_DRAW_MODE_IO)
- toggle_draw_io(x, glist, mode - IEM_GUI_DRAW_MODE_IO);
+ toggle_draw_io(x, glist, mode - IEM_GUI_DRAW_MODE_IO);
}
/* ------------------------ tgl widgetbehaviour----------------------------- */
@@ -207,14 +207,14 @@ static void toggle_save(t_gobj *z, t_binbuf *b)
iemgui_save(&x->x_gui, srl, bflcol);
binbuf_addv(b, "ssiisiisssiiiiiiiff", gensym("#X"),gensym("obj"),
- (t_int)x->x_gui.x_obj.te_xpix,
- (t_int)x->x_gui.x_obj.te_ypix,
- gensym("tgl"), x->x_gui.x_w,
- iem_symargstoint(&x->x_gui.x_isa),
- srl[0], srl[1], srl[2],
- x->x_gui.x_ldx, x->x_gui.x_ldy,
- iem_fstyletoint(&x->x_gui.x_fsf), x->x_gui.x_fontsize,
- bflcol[0], bflcol[1], bflcol[2], x->x_on, x->x_nonzero);
+ (int)x->x_gui.x_obj.te_xpix,
+ (int)x->x_gui.x_obj.te_ypix,
+ gensym("tgl"), x->x_gui.x_w,
+ iem_symargstoint(&x->x_gui.x_isa),
+ srl[0], srl[1], srl[2],
+ x->x_gui.x_ldx, x->x_gui.x_ldy,
+ iem_fstyletoint(&x->x_gui.x_fsf), x->x_gui.x_fontsize,
+ bflcol[0], bflcol[1], bflcol[2], x->x_on, x->x_nonzero);
binbuf_addv(b, ";");
}
@@ -226,20 +226,20 @@ static void toggle_properties(t_gobj *z, t_glist *owner)
iemgui_properties(&x->x_gui, srl);
sprintf(buf, "pdtk_iemgui_dialog %%s TOGGLE \
- ----------dimensions(pix):----------- %d %d size: 0 0 empty \
- -----------non-zero-value:----------- %g value: 0.0 empty %g \
- -1 lin log %d %d empty %d \
- %s %s \
- %s %d %d \
- %d %d \
- %d %d %d\n",
- x->x_gui.x_w, IEM_GUI_MINSIZE,
- x->x_nonzero, 1.0,/*non_zero-schedule*/
- x->x_gui.x_isa.x_loadinit, -1, -1,/*no multi*/
- srl[0]->s_name, srl[1]->s_name,
- srl[2]->s_name, x->x_gui.x_ldx, x->x_gui.x_ldy,
- x->x_gui.x_fsf.x_font_style, x->x_gui.x_fontsize,
- 0xffffff & x->x_gui.x_bcol, 0xffffff & x->x_gui.x_fcol, 0xffffff & x->x_gui.x_lcol);
+ ----------dimensions(pix):----------- %d %d size: 0 0 empty \
+ -----------non-zero-value:----------- %g value: 0.0 empty %g \
+ -1 lin log %d %d empty %d \
+ %s %s \
+ %s %d %d \
+ %d %d \
+ %d %d %d\n",
+ x->x_gui.x_w, IEM_GUI_MINSIZE,
+ x->x_nonzero, 1.0,/*non_zero-schedule*/
+ x->x_gui.x_isa.x_loadinit, -1, -1,/*no multi*/
+ srl[0]->s_name, srl[1]->s_name,
+ srl[2]->s_name, x->x_gui.x_ldx, x->x_gui.x_ldy,
+ x->x_gui.x_fsf.x_font_style, x->x_gui.x_fontsize,
+ 0xffffff & x->x_gui.x_bcol, 0xffffff & x->x_gui.x_fcol, 0xffffff & x->x_gui.x_lcol);
gfxstub_new(&x->x_gui.x_obj.ob_pd, x, buf);
}
@@ -249,7 +249,7 @@ static void toggle_bang(t_toggle *x)
(*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
outlet_float(x->x_gui.x_obj.ob_outlet, x->x_on);
if(x->x_gui.x_fsf.x_snd_able && x->x_gui.x_snd->s_thing)
- pd_float(x->x_gui.x_snd->s_thing, x->x_on);
+ pd_float(x->x_gui.x_snd->s_thing, x->x_on);
}
static void toggle_dialog(t_toggle *x, t_symbol *s, int argc, t_atom *argv)
@@ -260,10 +260,10 @@ static void toggle_dialog(t_toggle *x, t_symbol *s, int argc, t_atom *argv)
int sr_flags;
if(nonzero == 0.0)
- nonzero = 1.0;
+ nonzero = 1.0;
x->x_nonzero = nonzero;
if(x->x_on != 0.0)
- x->x_on = x->x_nonzero;
+ x->x_on = x->x_nonzero;
sr_flags = iemgui_dialog(&x->x_gui, srl, argc, argv);
x->x_gui.x_w = iemgui_clip_size(a);
x->x_gui.x_h = x->x_gui.x_w;
@@ -279,7 +279,7 @@ static void toggle_click(t_toggle *x, t_floatarg xpos, t_floatarg ypos, t_floata
static int toggle_newclick(t_gobj *z, struct _glist *glist, int xpix, int ypix, int shift, int alt, int dbl, int doit)
{
if(doit)
- toggle_click((t_toggle *)z, (t_floatarg)xpix, (t_floatarg)ypix, (t_floatarg)shift, 0, (t_floatarg)alt);
+ toggle_click((t_toggle *)z, (t_floatarg)xpix, (t_floatarg)ypix, (t_floatarg)shift, 0, (t_floatarg)alt);
return (1);
}
@@ -287,7 +287,7 @@ static void toggle_set(t_toggle *x, t_floatarg f)
{
x->x_on = f;
if(f != 0.0)
- x->x_nonzero = f;
+ x->x_nonzero = f;
(*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
}
@@ -296,9 +296,9 @@ static void toggle_float(t_toggle *x, t_floatarg f)
toggle_set(x, f);
if(x->x_gui.x_fsf.x_put_in2out)
{
- outlet_float(x->x_gui.x_obj.ob_outlet, x->x_on);
- if(x->x_gui.x_fsf.x_snd_able && x->x_gui.x_snd->s_thing)
- pd_float(x->x_gui.x_snd->s_thing, x->x_on);
+ outlet_float(x->x_gui.x_obj.ob_outlet, x->x_on);
+ if(x->x_gui.x_fsf.x_snd_able && x->x_gui.x_snd->s_thing)
+ pd_float(x->x_gui.x_snd->s_thing, x->x_on);
}
}
@@ -307,13 +307,13 @@ static void toggle_fout(t_toggle *x, t_floatarg f)
toggle_set(x, f);
outlet_float(x->x_gui.x_obj.ob_outlet, x->x_on);
if(x->x_gui.x_fsf.x_snd_able && x->x_gui.x_snd->s_thing)
- pd_float(x->x_gui.x_snd->s_thing, x->x_on);
+ pd_float(x->x_gui.x_snd->s_thing, x->x_on);
}
static void toggle_loadbang(t_toggle *x)
{
if(!sys_noloadbang && x->x_gui.x_isa.x_loadinit)
- toggle_fout(x, (float)x->x_on);
+ toggle_fout(x, (float)x->x_on);
}
static void toggle_size(t_toggle *x, t_symbol *s, int ac, t_atom *av)
@@ -355,7 +355,7 @@ static void toggle_init(t_toggle *x, t_floatarg f)
static void toggle_nonzero(t_toggle *x, t_floatarg f)
{
if(f != 0.0)
- x->x_nonzero = f;
+ x->x_nonzero = f;
}
static void *toggle_new(t_symbol *s, int argc, t_atom *argv)
@@ -380,46 +380,46 @@ static void *toggle_new(t_symbol *s, int argc, t_atom *argv)
&&IS_A_FLOAT(argv,7)&&IS_A_FLOAT(argv,8)&&IS_A_FLOAT(argv,9)
&&IS_A_FLOAT(argv,10)&&IS_A_FLOAT(argv,11)&&IS_A_FLOAT(argv,12))
{
- a = (int)atom_getintarg(0, argc, argv);
- iem_inttosymargs(&x->x_gui.x_isa, atom_getintarg(1, argc, argv));
- iemgui_new_getnames(&x->x_gui, 2, argv);
- ldx = (int)atom_getintarg(5, argc, argv);
- ldy = (int)atom_getintarg(6, argc, argv);
- iem_inttofstyle(&x->x_gui.x_fsf, atom_getintarg(7, argc, argv));
- fs = (int)atom_getintarg(8, argc, argv);
- bflcol[0] = (int)atom_getintarg(9, argc, argv);
- bflcol[1] = (int)atom_getintarg(10, argc, argv);
- bflcol[2] = (int)atom_getintarg(11, argc, argv);
- on = (float)atom_getfloatarg(12, argc, argv);
+ a = (int)atom_getintarg(0, argc, argv);
+ iem_inttosymargs(&x->x_gui.x_isa, atom_getintarg(1, argc, argv));
+ iemgui_new_getnames(&x->x_gui, 2, argv);
+ ldx = (int)atom_getintarg(5, argc, argv);
+ ldy = (int)atom_getintarg(6, argc, argv);
+ iem_inttofstyle(&x->x_gui.x_fsf, atom_getintarg(7, argc, argv));
+ fs = (int)atom_getintarg(8, argc, argv);
+ bflcol[0] = (int)atom_getintarg(9, argc, argv);
+ bflcol[1] = (int)atom_getintarg(10, argc, argv);
+ bflcol[2] = (int)atom_getintarg(11, argc, argv);
+ on = (float)atom_getfloatarg(12, argc, argv);
}
else iemgui_new_getnames(&x->x_gui, 2, 0);
if((argc == 14)&&IS_A_FLOAT(argv,13))
- nonzero = (float)atom_getfloatarg(13, argc, argv);
+ nonzero = (float)atom_getfloatarg(13, argc, argv);
x->x_gui.x_draw = (t_iemfunptr)toggle_draw;
x->x_gui.x_fsf.x_snd_able = 1;
x->x_gui.x_fsf.x_rcv_able = 1;
x->x_gui.x_glist = (t_glist *)canvas_getcurrent();
if (!strcmp(x->x_gui.x_snd->s_name, "empty"))
- x->x_gui.x_fsf.x_snd_able = 0;
+ x->x_gui.x_fsf.x_snd_able = 0;
if (!strcmp(x->x_gui.x_rcv->s_name, "empty"))
- x->x_gui.x_fsf.x_rcv_able = 0;
+ x->x_gui.x_fsf.x_rcv_able = 0;
if(x->x_gui.x_fsf.x_font_style == 1) strcpy(x->x_gui.x_font, "helvetica");
else if(x->x_gui.x_fsf.x_font_style == 2) strcpy(x->x_gui.x_font, "times");
else { x->x_gui.x_fsf.x_font_style = 0;
- strcpy(x->x_gui.x_font, "courier"); }
+ strcpy(x->x_gui.x_font, "courier"); }
x->x_nonzero = (nonzero!=0.0)?nonzero:1.0;
if(x->x_gui.x_isa.x_loadinit)
- x->x_on = (on!=0.0)?nonzero:0.0;
+ x->x_on = (on!=0.0)?nonzero:0.0;
else
- x->x_on = 0.0;
+ x->x_on = 0.0;
if (x->x_gui.x_fsf.x_rcv_able)
- pd_bind(&x->x_gui.x_obj.ob_pd, x->x_gui.x_rcv);
+ pd_bind(&x->x_gui.x_obj.ob_pd, x->x_gui.x_rcv);
x->x_gui.x_ldx = ldx;
x->x_gui.x_ldy = ldy;
if(fs < 4)
- fs = 4;
+ fs = 4;
x->x_gui.x_fontsize = fs;
x->x_gui.x_w = iemgui_clip_size(a);
x->x_gui.x_h = x->x_gui.x_w;
@@ -432,21 +432,21 @@ static void *toggle_new(t_symbol *s, int argc, t_atom *argv)
static void toggle_ff(t_toggle *x)
{
if(x->x_gui.x_fsf.x_rcv_able)
- pd_unbind(&x->x_gui.x_obj.ob_pd, x->x_gui.x_rcv);
+ pd_unbind(&x->x_gui.x_obj.ob_pd, x->x_gui.x_rcv);
gfxstub_deleteforkey(x);
}
void g_toggle_setup(void)
{
toggle_class = class_new(gensym("tgl"), (t_newmethod)toggle_new,
- (t_method)toggle_ff, sizeof(t_toggle), 0, A_GIMME, 0);
+ (t_method)toggle_ff, sizeof(t_toggle), 0, A_GIMME, 0);
class_addcreator((t_newmethod)toggle_new, gensym("toggle"), A_GIMME, 0);
class_addbang(toggle_class, toggle_bang);
class_addfloat(toggle_class, toggle_float);
class_addmethod(toggle_class, (t_method)toggle_click, gensym("click"),
- A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, 0);
+ A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, 0);
class_addmethod(toggle_class, (t_method)toggle_dialog, gensym("dialog"),
- A_GIMME, 0);
+ A_GIMME, 0);
class_addmethod(toggle_class, (t_method)toggle_loadbang, gensym("loadbang"), 0);
class_addmethod(toggle_class, (t_method)toggle_set, gensym("set"), A_FLOAT, 0);
class_addmethod(toggle_class, (t_method)toggle_size, gensym("size"), A_GIMME, 0);
diff --git a/pd/src/g_traversal.c b/pd/src/g_traversal.c
index a9e8ce03..4addeff3 100644
--- a/pd/src/g_traversal.c
+++ b/pd/src/g_traversal.c
@@ -18,7 +18,7 @@ sublist - get a pointer into a list which is an element of another scalar
#include <stdlib.h>
#include <string.h>
-#include <stdio.h> /* for read/write to files */
+#include <stdio.h> /* for read/write to files */
#include "m_pd.h"
#include "g_canvas.h"
@@ -31,13 +31,13 @@ t_gstub *gstub_new(t_glist *gl, t_array *a)
t_gstub *gs = t_getbytes(sizeof(*gs));
if (gl)
{
- gs->gs_which = GP_GLIST;
- gs->gs_un.gs_glist = gl;
+ gs->gs_which = GP_GLIST;
+ gs->gs_un.gs_glist = gl;
}
else
{
- gs->gs_which = GP_ARRAY;
- gs->gs_un.gs_array = a;
+ gs->gs_which = GP_ARRAY;
+ gs->gs_un.gs_array = a;
}
gs->gs_refcount = 0;
return (gs);
@@ -52,7 +52,7 @@ static void gstub_dis(t_gstub *gs)
{
int refcount = --gs->gs_refcount;
if ((!refcount) && gs->gs_which == GP_NONE)
- t_freebytes(gs, sizeof (*gs));
+ t_freebytes(gs, sizeof (*gs));
else if (refcount < 0) bug("gstub_dis");
}
@@ -78,14 +78,14 @@ int gpointer_check(const t_gpointer *gp, int headok)
if (!gs) return (0);
if (gs->gs_which == GP_ARRAY)
{
- if (gs->gs_un.gs_array->a_valid != gp->gp_valid) return (0);
- else return (1);
+ if (gs->gs_un.gs_array->a_valid != gp->gp_valid) return (0);
+ else return (1);
}
else if (gs->gs_which == GP_GLIST)
{
- if (!headok && !gp->gp_un.gp_scalar) return (0);
- else if (gs->gs_un.gs_glist->gl_valid != gp->gp_valid) return (0);
- else return (1);
+ if (!headok && !gp->gp_un.gp_scalar) return (0);
+ else if (gs->gs_un.gs_glist->gl_valid != gp->gp_valid) return (0);
+ else return (1);
}
else return (0);
}
@@ -110,15 +110,15 @@ static t_symbol *gpointer_gettemplatesym(const t_gpointer *gp)
t_gstub *gs = gp->gp_stub;
if (gs->gs_which == GP_GLIST)
{
- t_scalar *sc = gp->gp_un.gp_scalar;
- if (sc)
- return (sc->sc_template);
- else return (0);
+ t_scalar *sc = gp->gp_un.gp_scalar;
+ if (sc)
+ return (sc->sc_template);
+ else return (0);
}
else
{
- t_array *a = gs->gs_un.gs_array;
- return (a->a_templatesym);
+ t_array *a = gs->gs_un.gs_array;
+ return (a->a_templatesym);
}
}
@@ -128,7 +128,7 @@ void gpointer_copy(const t_gpointer *gpfrom, t_gpointer *gpto)
{
*gpto = *gpfrom;
if (gpto->gp_stub)
- gpto->gp_stub->gs_refcount++;
+ gpto->gp_stub->gs_refcount++;
else bug("gpointer_copy");
}
@@ -137,8 +137,8 @@ void gpointer_unset(t_gpointer *gp)
t_gstub *gs;
if (gs = gp->gp_stub)
{
- gstub_dis(gs);
- gp->gp_stub = 0;
+ gstub_dis(gs);
+ gp->gp_stub = 0;
}
}
@@ -199,8 +199,8 @@ static void *ptrobj_new(t_symbol *classname, int argc, t_atom *argv)
x->x_ntypedout = n = argc;
for (; n--; to++)
{
- to->to_outlet = outlet_new(&x->x_obj, &s_pointer);
- to->to_type = canvas_makebindsym(atom_getsymbol(argv++));
+ to->to_outlet = outlet_new(&x->x_obj, &s_pointer);
+ to->to_type = canvas_makebindsym(atom_getsymbol(argv++));
}
x->x_otherout = outlet_new(&x->x_obj, &s_pointer);
x->x_bangout = outlet_new(&x->x_obj, &s_bang);
@@ -225,56 +225,56 @@ static void ptrobj_vnext(t_ptrobj *x, float f)
if (!gs)
{
- pd_error(x, "ptrobj_next: no current pointer");
- return;
+ pd_error(x, "ptrobj_next: no current pointer");
+ return;
}
if (gs->gs_which != GP_GLIST)
{
- pd_error(x, "ptrobj_next: lists only, not arrays");
- return;
+ pd_error(x, "ptrobj_next: lists only, not arrays");
+ return;
}
glist = gs->gs_un.gs_glist;
if (glist->gl_valid != gp->gp_valid)
{
- pd_error(x, "ptrobj_next: stale pointer");
- return;
+ pd_error(x, "ptrobj_next: stale pointer");
+ return;
}
if (wantselected && !glist_isvisible(glist))
{
- pd_error(x,
- "ptrobj_vnext: next-selected only works for a visible window");
- return;
+ pd_error(x,
+ "ptrobj_vnext: next-selected only works for a visible window");
+ return;
}
gobj = &gp->gp_un.gp_scalar->sc_gobj;
if (!gobj) gobj = glist->gl_list;
else gobj = gobj->g_next;
while (gobj && ((pd_class(&gobj->g_pd) != scalar_class) ||
- (wantselected && !glist_isselected(glist, gobj))))
- gobj = gobj->g_next;
+ (wantselected && !glist_isselected(glist, gobj))))
+ gobj = gobj->g_next;
if (gobj)
{
- t_typedout *to;
- int n;
- t_scalar *sc = (t_scalar *)gobj;
- t_symbol *templatesym = sc->sc_template;
-
- gp->gp_un.gp_scalar = sc;
- for (n = x->x_ntypedout, to = x->x_typedout; n--; to++)
- {
- if (to->to_type == templatesym)
- {
- outlet_pointer(to->to_outlet, &x->x_gp);
- return;
- }
- }
- outlet_pointer(x->x_otherout, &x->x_gp);
+ t_typedout *to;
+ int n;
+ t_scalar *sc = (t_scalar *)gobj;
+ t_symbol *templatesym = sc->sc_template;
+
+ gp->gp_un.gp_scalar = sc;
+ for (n = x->x_ntypedout, to = x->x_typedout; n--; to++)
+ {
+ if (to->to_type == templatesym)
+ {
+ outlet_pointer(to->to_outlet, &x->x_gp);
+ return;
+ }
+ }
+ outlet_pointer(x->x_otherout, &x->x_gp);
}
else
{
- gpointer_unset(gp);
- outlet_bang(x->x_bangout);
+ gpointer_unset(gp);
+ outlet_bang(x->x_bangout);
}
}
@@ -294,22 +294,22 @@ static void ptrobj_sendwindow(t_ptrobj *x, t_symbol *s, int argc, t_atom *argv)
t_gstub *gs;
if (!gpointer_check(&x->x_gp, 1))
{
- pd_error(x, "ptrobj_bang: empty pointer");
- return;
+ pd_error(x, "ptrobj_bang: empty pointer");
+ return;
}
gs = x->x_gp.gp_stub;
if (gs->gs_which == GP_GLIST)
- glist = gs->gs_un.gs_glist;
+ glist = gs->gs_un.gs_glist;
else
{
- t_array *owner_array = gs->gs_un.gs_array;
- while (owner_array->a_gp.gp_stub->gs_which == GP_ARRAY)
- owner_array = owner_array->a_gp.gp_stub->gs_un.gs_array;
- glist = owner_array->a_gp.gp_stub->gs_un.gs_glist;
+ t_array *owner_array = gs->gs_un.gs_array;
+ while (owner_array->a_gp.gp_stub->gs_which == GP_ARRAY)
+ owner_array = owner_array->a_gp.gp_stub->gs_un.gs_array;
+ glist = owner_array->a_gp.gp_stub->gs_un.gs_glist;
}
canvas = (t_pd *)glist_getcanvas(glist);
if (argc && argv->a_type == A_SYMBOL)
- pd_typedmess(canvas, argv->a_w.w_symbol, argc-1, argv+1);
+ pd_typedmess(canvas, argv->a_w.w_symbol, argc-1, argv+1);
else pd_error(x, "send-window: no message?");
}
@@ -320,17 +320,17 @@ static void ptrobj_bang(t_ptrobj *x)
t_typedout *to;
if (!gpointer_check(&x->x_gp, 1))
{
- pd_error(x, "ptrobj_bang: empty pointer");
- return;
+ pd_error(x, "ptrobj_bang: empty pointer");
+ return;
}
templatesym = gpointer_gettemplatesym(&x->x_gp);
for (n = x->x_ntypedout, to = x->x_typedout; n--; to++)
{
- if (to->to_type == templatesym)
- {
- outlet_pointer(to->to_outlet, &x->x_gp);
- return;
- }
+ if (to->to_type == templatesym)
+ {
+ outlet_pointer(to->to_outlet, &x->x_gp);
+ return;
+ }
}
outlet_pointer(x->x_otherout, &x->x_gp);
}
@@ -352,14 +352,14 @@ static void ptrobj_free(t_ptrobj *x)
static void ptrobj_setup(void)
{
ptrobj_class = class_new(gensym("pointer"), (t_newmethod)ptrobj_new,
- (t_method)ptrobj_free, sizeof(t_ptrobj), 0, A_GIMME, 0);
+ (t_method)ptrobj_free, sizeof(t_ptrobj), 0, A_GIMME, 0);
class_addmethod(ptrobj_class, (t_method)ptrobj_traverse, gensym("traverse"),
- A_SYMBOL, 0);
+ A_SYMBOL, 0);
class_addmethod(ptrobj_class, (t_method)ptrobj_next, gensym("next"), 0);
class_addmethod(ptrobj_class, (t_method)ptrobj_vnext, gensym("vnext"),
- A_DEFFLOAT, 0);
+ A_DEFFLOAT, 0);
class_addmethod(ptrobj_class, (t_method)ptrobj_sendwindow,
- gensym("send-window"), A_GIMME, 0);
+ gensym("send-window"), A_GIMME, 0);
class_addpointer(ptrobj_class, ptrobj_pointer);
class_addbang(ptrobj_class, ptrobj_bang);
}
@@ -390,15 +390,15 @@ static void *get_new(t_symbol *why, int argc, t_atom *argv)
x->x_templatesym = canvas_makebindsym(atom_getsymbolarg(0, argc, argv));
if (argc) argc--, argv++;
x->x_variables
- = (t_getvariable *)getbytes(argc * sizeof (*x->x_variables));
+ = (t_getvariable *)getbytes(argc * sizeof (*x->x_variables));
x->x_nout = argc;
for (i = 0, sp = x->x_variables; i < argc; i++, sp++)
{
- sp->gv_sym = atom_getsymbolarg(i, argc, argv);
- sp->gv_outlet = outlet_new(&x->x_obj, 0);
- /* LATER connect with the template and set the outlet's type
- correctly. We can't yet guarantee that the template is there
- before we hit this routine. */
+ sp->gv_sym = atom_getsymbolarg(i, argc, argv);
+ sp->gv_outlet = outlet_new(&x->x_obj, 0);
+ /* LATER connect with the template and set the outlet's type
+ correctly. We can't yet guarantee that the template is there
+ before we hit this routine. */
}
return (x);
}
@@ -413,21 +413,21 @@ static void get_pointer(t_get *x, t_gpointer *gp)
t_getvariable *vp;
if (!template)
{
- pd_error(x, "get: couldn't find template %s", templatesym->s_name);
- return;
+ pd_error(x, "get: couldn't find template %s", templatesym->s_name);
+ return;
}
if (gpointer_ishead(gp))
{
- pd_error(x, "get: empty pointer");
- return;
+ pd_error(x, "get: empty pointer");
+ return;
}
if (gs->gs_which == GP_ARRAY) vec = gp->gp_un.gp_w;
else vec = gp->gp_un.gp_scalar->sc_vec;
for (i = nitems - 1, vp = x->x_variables + i; i >= 0; i--, vp--)
{
- float f = template_getfloat(template, vp->gv_sym, vec, 1);
- outlet_float(vp->gv_outlet, f);
- /* LATER deal with other types. */
+ float f = template_getfloat(template, vp->gv_sym, vec, 1);
+ outlet_float(vp->gv_outlet, f);
+ /* LATER deal with other types. */
}
}
@@ -439,7 +439,7 @@ static void get_free(t_get *x)
static void get_setup(void)
{
get_class = class_new(gensym("get"), (t_newmethod)get_new,
- (t_method)get_free, sizeof(t_get), 0, A_GIMME, 0);
+ (t_method)get_free, sizeof(t_get), 0, A_GIMME, 0);
class_addpointer(get_class, get_pointer);
}
@@ -450,7 +450,7 @@ static t_class *set_class;
typedef struct _setvariable
{
t_symbol *gv_sym;
- t_float gv_f; /* LATER take other types */
+ t_float gv_f; /* LATER take other types */
} t_setvariable;
typedef struct _set
@@ -470,17 +470,17 @@ static void *set_new(t_symbol *why, int argc, t_atom *argv)
x->x_templatesym = canvas_makebindsym(atom_getsymbolarg(0, argc, argv));
if (argc) argc--, argv++;
x->x_variables
- = (t_setvariable *)getbytes(argc * sizeof (*x->x_variables));
+ = (t_setvariable *)getbytes(argc * sizeof (*x->x_variables));
x->x_nin = argc;
if (argc)
{
- for (i = 0, sp = x->x_variables; i < argc; i++, sp++)
- {
- sp->gv_sym = atom_getsymbolarg(i, argc, argv);
- sp->gv_f = 0;
- if (i) floatinlet_new(&x->x_obj, &sp->gv_f);
- /* LATER figure out type as in "get" object. */
- }
+ for (i = 0, sp = x->x_variables; i < argc; i++, sp++)
+ {
+ sp->gv_sym = atom_getsymbolarg(i, argc, argv);
+ sp->gv_f = 0;
+ if (i) floatinlet_new(&x->x_obj, &sp->gv_f);
+ /* LATER figure out type as in "get" object. */
+ }
}
pointerinlet_new(&x->x_obj, &x->x_gp);
gpointer_init(&x->x_gp);
@@ -498,19 +498,19 @@ static void set_float(t_set *x, t_float f)
t_word *vec;
if (!template)
{
- pd_error(x, "set: couldn't find template %s", templatesym->s_name);
- return;
+ pd_error(x, "set: couldn't find template %s", templatesym->s_name);
+ return;
}
if (!gpointer_check(gp, 0))
{
- pd_error(x, "set: empty pointer");
- return;
+ pd_error(x, "set: empty pointer");
+ return;
}
if (gpointer_gettemplatesym(gp) != x->x_templatesym)
{
- pd_error(x, "set %s: got wrong template (%s)",
- x->x_templatesym->s_name, gpointer_gettemplatesym(gp)->s_name);
- return;
+ pd_error(x, "set %s: got wrong template (%s)",
+ x->x_templatesym->s_name, gpointer_gettemplatesym(gp)->s_name);
+ return;
}
if (!nitems) return;
x->x_variables[0].gv_f = f;
@@ -518,18 +518,18 @@ static void set_float(t_set *x, t_float f)
else vec = gp->gp_un.gp_scalar->sc_vec;
for (i = 0, vp = x->x_variables; i < nitems; i++, vp++)
{
- template_setfloat(template, vp->gv_sym, vec, vp->gv_f, 1);
- /* LATER deal with other types ala get_pointer. */
+ template_setfloat(template, vp->gv_sym, vec, vp->gv_f, 1);
+ /* LATER deal with other types ala get_pointer. */
}
if (gs->gs_which == GP_GLIST)
- glist_redrawitem(gs->gs_un.gs_glist, (t_gobj *)(gp->gp_un.gp_scalar));
+ glist_redrawitem(gs->gs_un.gs_glist, (t_gobj *)(gp->gp_un.gp_scalar));
else
{
- t_array *owner_array = gs->gs_un.gs_array;
- while (owner_array->a_gp.gp_stub->gs_which == GP_ARRAY)
- owner_array = owner_array->a_gp.gp_stub->gs_un.gs_array;
- glist_redrawitem(owner_array->a_gp.gp_stub->gs_un.gs_glist,
- (t_gobj *)(owner_array->a_gp.gp_un.gp_scalar));
+ t_array *owner_array = gs->gs_un.gs_array;
+ while (owner_array->a_gp.gp_stub->gs_which == GP_ARRAY)
+ owner_array = owner_array->a_gp.gp_stub->gs_un.gs_array;
+ glist_redrawitem(owner_array->a_gp.gp_stub->gs_un.gs_glist,
+ (t_gobj *)(owner_array->a_gp.gp_un.gp_scalar));
}
}
@@ -542,7 +542,7 @@ static void set_free(t_set *x)
static void set_setup(void)
{
set_class = class_new(gensym("set"), (t_newmethod)set_new,
- (t_method)set_free, sizeof(t_set), 0, A_GIMME, 0);
+ (t_method)set_free, sizeof(t_set), 0, A_GIMME, 0);
class_addfloat(set_class, set_float);
}
@@ -575,7 +575,7 @@ static void elem_float(t_elem *x, t_float f)
{
int indx = f, nitems, onset;
t_symbol *templatesym = x->x_templatesym, *fieldsym = x->x_fieldsym,
- *elemtemplatesym;
+ *elemtemplatesym;
t_template *template = template_findbyname(templatesym);
t_template *elemtemplate;
t_gpointer *gparent = &x->x_gparent;
@@ -585,38 +585,38 @@ static void elem_float(t_elem *x, t_float f)
if (!gpointer_check(gparent, 0))
{
- pd_error(x, "element: empty pointer");
- return;
+ pd_error(x, "element: empty pointer");
+ return;
}
if (gpointer_gettemplatesym(gparent) != x->x_templatesym)
{
- pd_error(x, "element %s: got wrong template (%s)",
- x->x_templatesym->s_name, gpointer_gettemplatesym(gparent)->s_name);
- return;
+ pd_error(x, "element %s: got wrong template (%s)",
+ x->x_templatesym->s_name, gpointer_gettemplatesym(gparent)->s_name);
+ return;
}
if (gparent->gp_stub->gs_which == GP_ARRAY) w = gparent->gp_un.gp_w;
else w = gparent->gp_un.gp_scalar->sc_vec;
if (!template)
{
- pd_error(x, "element: couldn't find template %s", templatesym->s_name);
- return;
+ pd_error(x, "element: couldn't find template %s", templatesym->s_name);
+ return;
}
if (!template_find_field(template, fieldsym,
- &onset, &type, &elemtemplatesym))
+ &onset, &type, &elemtemplatesym))
{
- pd_error(x, "element: couldn't find array field %s", fieldsym->s_name);
- return;
+ pd_error(x, "element: couldn't find array field %s", fieldsym->s_name);
+ return;
}
if (type != DT_ARRAY)
{
- pd_error(x, "element: field %s not of type array", fieldsym->s_name);
- return;
+ pd_error(x, "element: field %s not of type array", fieldsym->s_name);
+ return;
}
if (!(elemtemplate = template_findbyname(elemtemplatesym)))
{
- pd_error(x, "element: couldn't find field template %s",
- elemtemplatesym->s_name);
- return;
+ pd_error(x, "element: couldn't find field template %s",
+ elemtemplatesym->s_name);
+ return;
}
elemsize = elemtemplate->t_n * sizeof(t_word);
@@ -628,7 +628,7 @@ static void elem_float(t_elem *x, t_float f)
if (indx >= nitems) indx = nitems-1;
gpointer_setarray(&x->x_gp, array,
- (t_word *)((char *)(array->a_vec) + indx * elemsize));
+ (t_word *)((char *)(array->a_vec) + indx * elemsize));
outlet_pointer(x->x_obj.ob_outlet, &x->x_gp);
}
@@ -641,7 +641,7 @@ static void elem_free(t_elem *x, t_gpointer *gp)
static void elem_setup(void)
{
elem_class = class_new(gensym("element"), (t_newmethod)elem_new,
- (t_method)elem_free, sizeof(t_elem), 0, A_DEFSYM, A_DEFSYM, 0);
+ (t_method)elem_free, sizeof(t_elem), 0, A_DEFSYM, A_DEFSYM, 0);
class_addfloat(elem_class, elem_float);
}
@@ -669,7 +669,7 @@ static void getsize_pointer(t_getsize *x, t_gpointer *gp)
{
int nitems, onset, type;
t_symbol *templatesym = x->x_templatesym, *fieldsym = x->x_fieldsym,
- *elemtemplatesym;
+ *elemtemplatesym;
t_template *template = template_findbyname(templatesym);
t_word *w;
t_array *array;
@@ -677,30 +677,30 @@ static void getsize_pointer(t_getsize *x, t_gpointer *gp)
t_gstub *gs = gp->gp_stub;
if (!template)
{
- pd_error(x, "getsize: couldn't find template %s", templatesym->s_name);
- return;
+ pd_error(x, "getsize: couldn't find template %s", templatesym->s_name);
+ return;
}
if (!template_find_field(template, fieldsym,
- &onset, &type, &elemtemplatesym))
+ &onset, &type, &elemtemplatesym))
{
- pd_error(x, "getsize: couldn't find array field %s", fieldsym->s_name);
- return;
+ pd_error(x, "getsize: couldn't find array field %s", fieldsym->s_name);
+ return;
}
if (type != DT_ARRAY)
{
- pd_error(x, "getsize: field %s not of type array", fieldsym->s_name);
- return;
+ pd_error(x, "getsize: field %s not of type array", fieldsym->s_name);
+ return;
}
if (gpointer_ishead(gp))
{
- pd_error(x, "getsize: empty pointer");
- return;
+ pd_error(x, "getsize: empty pointer");
+ return;
}
if (gpointer_gettemplatesym(gp) != x->x_templatesym)
{
- pd_error(x, "getsize %s: got wrong template (%s)",
- x->x_templatesym->s_name, gpointer_gettemplatesym(gp)->s_name);
- return;
+ pd_error(x, "getsize %s: got wrong template (%s)",
+ x->x_templatesym->s_name, gpointer_gettemplatesym(gp)->s_name);
+ return;
}
if (gs->gs_which == GP_ARRAY) w = gp->gp_un.gp_w;
else w = gp->gp_un.gp_scalar->sc_vec;
@@ -712,7 +712,7 @@ static void getsize_pointer(t_getsize *x, t_gpointer *gp)
static void getsize_setup(void)
{
getsize_class = class_new(gensym("getsize"), (t_newmethod)getsize_new, 0,
- sizeof(t_getsize), 0, A_DEFSYM, A_DEFSYM, 0);
+ sizeof(t_getsize), 0, A_DEFSYM, A_DEFSYM, 0);
class_addpointer(getsize_class, getsize_pointer);
}
@@ -744,7 +744,7 @@ static void setsize_float(t_setsize *x, t_float f)
{
int nitems, onset, type;
t_symbol *templatesym = x->x_templatesym, *fieldsym = x->x_fieldsym,
- *elemtemplatesym;
+ *elemtemplatesym;
t_template *template = template_findbyname(templatesym);
t_template *elemtemplate;
t_word *w;
@@ -756,41 +756,41 @@ static void setsize_float(t_setsize *x, t_float f)
t_gstub *gs = gp->gp_stub;
if (!gpointer_check(&x->x_gp, 0))
{
- pd_error(x, "setsize: empty pointer");
- return;
+ pd_error(x, "setsize: empty pointer");
+ return;
}
if (gpointer_gettemplatesym(&x->x_gp) != x->x_templatesym)
{
- pd_error(x, "setsize %s: got wrong template (%s)",
- x->x_templatesym->s_name,
- gpointer_gettemplatesym(&x->x_gp)->s_name);
- return;
+ pd_error(x, "setsize %s: got wrong template (%s)",
+ x->x_templatesym->s_name,
+ gpointer_gettemplatesym(&x->x_gp)->s_name);
+ return;
}
if (gs->gs_which == GP_ARRAY) w = gp->gp_un.gp_w;
else w = gp->gp_un.gp_scalar->sc_vec;
if (!template)
{
- pd_error(x,"setsize: couldn't find template %s", templatesym->s_name);
- return;
+ pd_error(x,"setsize: couldn't find template %s", templatesym->s_name);
+ return;
}
if (!template_find_field(template, fieldsym,
- &onset, &type, &elemtemplatesym))
+ &onset, &type, &elemtemplatesym))
{
- pd_error(x,"setsize: couldn't find array field %s", fieldsym->s_name);
- return;
+ pd_error(x,"setsize: couldn't find array field %s", fieldsym->s_name);
+ return;
}
if (type != DT_ARRAY)
{
- pd_error(x,"setsize: field %s not of type array", fieldsym->s_name);
- return;
+ pd_error(x,"setsize: field %s not of type array", fieldsym->s_name);
+ return;
}
if (!(elemtemplate = template_findbyname(elemtemplatesym)))
{
- pd_error(x,"element: couldn't find field template %s",
- elemtemplatesym->s_name);
- return;
+ pd_error(x,"element: couldn't find field template %s",
+ elemtemplatesym->s_name);
+ return;
}
elemsize = elemtemplate->t_n * sizeof(t_word);
@@ -803,57 +803,57 @@ static void setsize_float(t_setsize *x, t_float f)
if (newsize < 1) newsize = 1;
if (newsize == nitems) return;
- /* erase the array before resizing it. If we belong to a
- scalar it's easy, but if we belong to an element of another
- array we have to search back until we get to a scalar to erase.
- When graphics updates become queueable this may fall apart... */
+ /* erase the array before resizing it. If we belong to a
+ scalar it's easy, but if we belong to an element of another
+ array we have to search back until we get to a scalar to erase.
+ When graphics updates become queueable this may fall apart... */
if (gs->gs_which == GP_GLIST)
{
- if (glist_isvisible(gs->gs_un.gs_glist))
- gobj_vis((t_gobj *)(gp->gp_un.gp_scalar), gs->gs_un.gs_glist, 0);
+ if (glist_isvisible(gs->gs_un.gs_glist))
+ gobj_vis((t_gobj *)(gp->gp_un.gp_scalar), gs->gs_un.gs_glist, 0);
}
else
{
- t_array *owner_array = gs->gs_un.gs_array;
- while (owner_array->a_gp.gp_stub->gs_which == GP_ARRAY)
- owner_array = owner_array->a_gp.gp_stub->gs_un.gs_array;
- if (glist_isvisible(owner_array->a_gp.gp_stub->gs_un.gs_glist))
- gobj_vis((t_gobj *)(owner_array->a_gp.gp_un.gp_scalar),
- owner_array->a_gp.gp_stub->gs_un.gs_glist, 0);
+ t_array *owner_array = gs->gs_un.gs_array;
+ while (owner_array->a_gp.gp_stub->gs_which == GP_ARRAY)
+ owner_array = owner_array->a_gp.gp_stub->gs_un.gs_array;
+ if (glist_isvisible(owner_array->a_gp.gp_stub->gs_un.gs_glist))
+ gobj_vis((t_gobj *)(owner_array->a_gp.gp_un.gp_scalar),
+ owner_array->a_gp.gp_stub->gs_un.gs_glist, 0);
}
- /* now do the resizing and, if growing, initialize new scalars */
+ /* now do the resizing and, if growing, initialize new scalars */
array->a_vec = (char *)resizebytes(array->a_vec,
- elemsize * nitems, elemsize * newsize);
+ elemsize * nitems, elemsize * newsize);
array->a_n = newsize;
if (newsize > nitems)
{
- char *newelem = ((char *)array->a_vec) + nitems * elemsize;
- int i = 0, nnew = newsize - nitems;
-
- while (nnew--)
- {
- word_init((t_word *)newelem, elemtemplate, gp);
- newelem += elemsize;
- /* post("new %x %x, ntypes %d", newelem, *(int *)newelem, ntypes); */
- }
+ char *newelem = ((char *)array->a_vec) + nitems * elemsize;
+ int i = 0, nnew = newsize - nitems;
+
+ while (nnew--)
+ {
+ word_init((t_word *)newelem, elemtemplate, gp);
+ newelem += elemsize;
+ /* post("new %lx %lx, ntypes %d", newelem, *(int *)newelem, ntypes); */
+ }
}
/* redraw again. */
if (gs->gs_which == GP_GLIST)
{
- if (glist_isvisible(gs->gs_un.gs_glist))
- gobj_vis((t_gobj *)(gp->gp_un.gp_scalar), gs->gs_un.gs_glist, 1);
+ if (glist_isvisible(gs->gs_un.gs_glist))
+ gobj_vis((t_gobj *)(gp->gp_un.gp_scalar), gs->gs_un.gs_glist, 1);
}
else
{
- t_array *owner_array = gs->gs_un.gs_array;
- while (owner_array->a_gp.gp_stub->gs_which == GP_ARRAY)
- owner_array = owner_array->a_gp.gp_stub->gs_un.gs_array;
- if (glist_isvisible(owner_array->a_gp.gp_stub->gs_un.gs_glist))
- gobj_vis((t_gobj *)(owner_array->a_gp.gp_un.gp_scalar),
- owner_array->a_gp.gp_stub->gs_un.gs_glist, 1);
+ t_array *owner_array = gs->gs_un.gs_array;
+ while (owner_array->a_gp.gp_stub->gs_which == GP_ARRAY)
+ owner_array = owner_array->a_gp.gp_stub->gs_un.gs_array;
+ if (glist_isvisible(owner_array->a_gp.gp_stub->gs_un.gs_glist))
+ gobj_vis((t_gobj *)(owner_array->a_gp.gp_un.gp_scalar),
+ owner_array->a_gp.gp_stub->gs_un.gs_glist, 1);
}
}
@@ -866,8 +866,8 @@ static void setsize_free(t_setsize *x)
static void setsize_setup(void)
{
setsize_class = class_new(gensym("setsize"), (t_newmethod)setsize_new,
- (t_method)setsize_free, sizeof(t_setsize), 0,
- A_DEFSYM, A_DEFSYM, A_DEFFLOAT, 0);
+ (t_method)setsize_free, sizeof(t_setsize), 0,
+ A_DEFSYM, A_DEFSYM, A_DEFFLOAT, 0);
class_addfloat(setsize_class, setsize_float);
}
@@ -898,16 +898,16 @@ static void *append_new(t_symbol *why, int argc, t_atom *argv)
x->x_templatesym = canvas_makebindsym(atom_getsymbolarg(0, argc, argv));
if (argc) argc--, argv++;
x->x_variables
- = (t_appendvariable *)getbytes(argc * sizeof (*x->x_variables));
+ = (t_appendvariable *)getbytes(argc * sizeof (*x->x_variables));
x->x_nin = argc;
if (argc)
{
- for (i = 0, sp = x->x_variables; i < argc; i++, sp++)
- {
- sp->gv_sym = atom_getsymbolarg(i, argc, argv);
- sp->gv_f = 0;
- if (i) floatinlet_new(&x->x_obj, &sp->gv_f);
- }
+ for (i = 0, sp = x->x_variables; i < argc; i++, sp++)
+ {
+ sp->gv_sym = atom_getsymbolarg(i, argc, argv);
+ sp->gv_f = 0;
+ if (i) floatinlet_new(&x->x_obj, &sp->gv_f);
+ }
}
pointerinlet_new(&x->x_obj, &x->x_gp);
outlet_new(&x->x_obj, &s_pointer);
@@ -928,24 +928,24 @@ static void append_float(t_append *x, t_float f)
t_glist *glist;
if (!template)
{
- pd_error(x, "append: couldn't find template %s", templatesym->s_name);
- return;
+ pd_error(x, "append: couldn't find template %s", templatesym->s_name);
+ return;
}
if (!gs)
{
- pd_error(x, "append: no current pointer");
- return;
+ pd_error(x, "append: no current pointer");
+ return;
}
if (gs->gs_which != GP_GLIST)
{
- pd_error(x, "append: lists only, not arrays");
- return;
+ pd_error(x, "append: lists only, not arrays");
+ return;
}
glist = gs->gs_un.gs_glist;
if (glist->gl_valid != gp->gp_valid)
{
- pd_error(x, "append: stale pointer");
- return;
+ pd_error(x, "append: stale pointer");
+ return;
}
if (!nitems) return;
x->x_variables[0].gv_f = f;
@@ -953,29 +953,29 @@ static void append_float(t_append *x, t_float f)
sc = scalar_new(glist, templatesym);
if (!sc)
{
- pd_error(x, "%s: couldn't create scalar", templatesym->s_name);
- return;
+ pd_error(x, "%s: couldn't create scalar", templatesym->s_name);
+ return;
}
oldsc = gp->gp_un.gp_scalar;
if (oldsc)
{
- sc->sc_gobj.g_next = oldsc->sc_gobj.g_next;
- oldsc->sc_gobj.g_next = &sc->sc_gobj;
+ sc->sc_gobj.g_next = oldsc->sc_gobj.g_next;
+ oldsc->sc_gobj.g_next = &sc->sc_gobj;
}
else
{
- sc->sc_gobj.g_next = glist->gl_list;
- glist->gl_list = &sc->sc_gobj;
+ sc->sc_gobj.g_next = glist->gl_list;
+ glist->gl_list = &sc->sc_gobj;
}
if (glist_isvisible(glist_getcanvas(glist)))
- gobj_vis(&sc->sc_gobj, glist, 1);
+ gobj_vis(&sc->sc_gobj, glist, 1);
gp->gp_un.gp_scalar = sc;
vec = sc->sc_vec;
for (i = 0, vp = x->x_variables; i < nitems; i++, vp++)
{
- template_setfloat(template, vp->gv_sym, vec, vp->gv_f, 1);
+ template_setfloat(template, vp->gv_sym, vec, vp->gv_f, 1);
}
glist_redrawitem(glist, (t_gobj *)sc);
@@ -992,7 +992,7 @@ static void append_free(t_append *x)
static void append_setup(void)
{
append_class = class_new(gensym("append"), (t_newmethod)append_new,
- (t_method)append_free, sizeof(t_append), 0, A_GIMME, 0);
+ (t_method)append_free, sizeof(t_append), 0, A_GIMME, 0);
class_addfloat(append_class, append_float);
}
@@ -1030,24 +1030,24 @@ static void sublist_pointer(t_sublist *x, t_gpointer *gp)
if (!template)
{
- pd_error(x, "sublist: couldn't find template %s", templatesym->s_name);
- return;
+ pd_error(x, "sublist: couldn't find template %s", templatesym->s_name);
+ return;
}
if (gpointer_ishead(gp))
{
- pd_error(x, "sublist: empty pointer");
- return;
+ pd_error(x, "sublist: empty pointer");
+ return;
}
if (!template_find_field(template, x->x_fieldsym,
- &onset, &type, &dummy))
+ &onset, &type, &dummy))
{
- pd_error(x, "sublist: couldn't find field %s", x->x_fieldsym->s_name);
- return;
+ pd_error(x, "sublist: couldn't find field %s", x->x_fieldsym->s_name);
+ return;
}
if (type != DT_LIST)
{
- pd_error(x, "sublist: field %s not of type list", x->x_fieldsym->s_name);
- return;
+ pd_error(x, "sublist: field %s not of type list", x->x_fieldsym->s_name);
+ return;
}
if (gs->gs_which == GP_ARRAY) w = gp->gp_un.gp_w;
else w = gp->gp_un.gp_scalar->sc_vec;
@@ -1065,7 +1065,7 @@ static void sublist_free(t_sublist *x, t_gpointer *gp)
static void sublist_setup(void)
{
sublist_class = class_new(gensym("sublist"), (t_newmethod)sublist_new,
- (t_method)sublist_free, sizeof(t_sublist), 0, A_DEFSYM, A_DEFSYM, 0);
+ (t_method)sublist_free, sizeof(t_sublist), 0, A_DEFSYM, A_DEFSYM, 0);
class_addpointer(sublist_class, sublist_pointer);
}
diff --git a/pd/src/g_vdial.c b/pd/src/g_vdial.c
index 8b9e210b..32d30876 100644
--- a/pd/src/g_vdial.c
+++ b/pd/src/g_vdial.c
@@ -36,14 +36,14 @@ void vradio_draw_update(t_vradio *x, t_glist *glist)
{
if(glist_isvisible(glist))
{
- t_canvas *canvas=glist_getcanvas(glist);
-
- sys_vgui(".x%x.c itemconfigure %xBUT%d -fill #%6.6x -outline #%6.6x\n",
- canvas, x, x->x_on_old,
- x->x_gui.x_bcol, x->x_gui.x_bcol);
- sys_vgui(".x%x.c itemconfigure %xBUT%d -fill #%6.6x -outline #%6.6x\n",
- canvas, x, x->x_on,
- x->x_gui.x_fcol, x->x_gui.x_fcol);
+ t_canvas *canvas=glist_getcanvas(glist);
+
+ sys_vgui(".x%lx.c itemconfigure %lxBUT%d -fill #%6.6x -outline #%6.6x\n",
+ canvas, x, x->x_on_old,
+ x->x_gui.x_bcol, x->x_gui.x_bcol);
+ sys_vgui(".x%lx.c itemconfigure %lxBUT%d -fill #%6.6x -outline #%6.6x\n",
+ canvas, x, x->x_on,
+ x->x_gui.x_fcol, x->x_gui.x_fcol);
}
}
@@ -59,30 +59,30 @@ void vradio_draw_new(t_vradio *x, t_glist *glist)
for(i=0; i<n; i++)
{
- sys_vgui(".x%x.c create rectangle %d %d %d %d -fill #%6.6x -tags %xBASE%d\n",
- canvas, xx11, yy11, xx12, yy12,
- x->x_gui.x_bcol, x, i);
- sys_vgui(".x%x.c create rectangle %d %d %d %d -fill #%6.6x -outline #%6.6x -tags %xBUT%d\n",
- canvas, xx21, yy21, xx22, yy22,
- (x->x_on==i)?x->x_gui.x_fcol:x->x_gui.x_bcol,
- (x->x_on==i)?x->x_gui.x_fcol:x->x_gui.x_bcol, x, i);
- yy11 += dy;
- yy12 += dy;
- yy21 += dy;
- yy22 += dy;
+ sys_vgui(".x%lx.c create rectangle %d %d %d %d -fill #%6.6x -tags %lxBASE%d\n",
+ canvas, xx11, yy11, xx12, yy12,
+ x->x_gui.x_bcol, x, i);
+ sys_vgui(".x%lx.c create rectangle %d %d %d %d -fill #%6.6x -outline #%6.6x -tags %lxBUT%d\n",
+ canvas, xx21, yy21, xx22, yy22,
+ (x->x_on==i)?x->x_gui.x_fcol:x->x_gui.x_bcol,
+ (x->x_on==i)?x->x_gui.x_fcol:x->x_gui.x_bcol, x, i);
+ yy11 += dy;
+ yy12 += dy;
+ yy21 += dy;
+ yy22 += dy;
}
- sys_vgui(".x%x.c create text %d %d -text {%s} -anchor w \
- -font {%s %d bold} -fill #%6.6x -tags %xLABEL\n",
- canvas, xx11+x->x_gui.x_ldx, yy11b+x->x_gui.x_ldy,
- strcmp(x->x_gui.x_lab->s_name, "empty")?x->x_gui.x_lab->s_name:"",
- x->x_gui.x_font, x->x_gui.x_fontsize,
- x->x_gui.x_lcol, x);
+ sys_vgui(".x%lx.c create text %d %d -text {%s} -anchor w \
+ -font {%s %d bold} -fill #%6.6x -tags %lxLABEL\n",
+ canvas, xx11+x->x_gui.x_ldx, yy11b+x->x_gui.x_ldy,
+ strcmp(x->x_gui.x_lab->s_name, "empty")?x->x_gui.x_lab->s_name:"",
+ x->x_gui.x_font, x->x_gui.x_fontsize,
+ x->x_gui.x_lcol, x);
if(!x->x_gui.x_fsf.x_snd_able)
- sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xOUT%d\n",
- canvas, xx11, yy11-1, xx11 + IOWIDTH, yy11, x, 0);
+ sys_vgui(".x%lx.c create rectangle %d %d %d %d -tags %lxOUT%d\n",
+ canvas, xx11, yy11-1, xx11 + IOWIDTH, yy11, x, 0);
if(!x->x_gui.x_fsf.x_rcv_able)
- sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xIN%d\n",
- canvas, xx11, yy11b, xx11 + IOWIDTH, yy11b+1, x, 0);
+ sys_vgui(".x%lx.c create rectangle %d %d %d %d -tags %lxIN%d\n",
+ canvas, xx11, yy11b, xx11 + IOWIDTH, yy11b+1, x, 0);
}
void vradio_draw_move(t_vradio *x, t_glist *glist)
@@ -97,23 +97,23 @@ void vradio_draw_move(t_vradio *x, t_glist *glist)
for(i=0; i<n; i++)
{
- sys_vgui(".x%x.c coords %xBASE%d %d %d %d %d\n",
- canvas, x, i, xx11, yy11, xx12, yy12);
- sys_vgui(".x%x.c coords %xBUT%d %d %d %d %d\n",
- canvas, x, i, xx21, yy21, xx22, yy22);
- yy11 += dy;
- yy12 += dy;
- yy21 += dy;
- yy22 += dy;
+ sys_vgui(".x%lx.c coords %lxBASE%d %d %d %d %d\n",
+ canvas, x, i, xx11, yy11, xx12, yy12);
+ sys_vgui(".x%lx.c coords %lxBUT%d %d %d %d %d\n",
+ canvas, x, i, xx21, yy21, xx22, yy22);
+ yy11 += dy;
+ yy12 += dy;
+ yy21 += dy;
+ yy22 += dy;
}
- sys_vgui(".x%x.c coords %xLABEL %d %d\n",
- canvas, x, xx11+x->x_gui.x_ldx, yy11b+x->x_gui.x_ldy);
+ sys_vgui(".x%lx.c coords %lxLABEL %d %d\n",
+ canvas, x, xx11+x->x_gui.x_ldx, yy11b+x->x_gui.x_ldy);
if(!x->x_gui.x_fsf.x_snd_able)
- sys_vgui(".x%x.c coords %xOUT%d %d %d %d %d\n",
- canvas, x, 0, xx11, yy11-1, xx11 + IOWIDTH, yy11);
+ sys_vgui(".x%lx.c coords %lxOUT%d %d %d %d %d\n",
+ canvas, x, 0, xx11, yy11-1, xx11 + IOWIDTH, yy11);
if(!x->x_gui.x_fsf.x_rcv_able)
- sys_vgui(".x%x.c coords %xIN%d %d %d %d %d\n",
- canvas, x, 0, xx11, yy11b, xx11 + IOWIDTH, yy11b+1);
+ sys_vgui(".x%lx.c coords %lxIN%d %d %d %d %d\n",
+ canvas, x, 0, xx11, yy11b, xx11 + IOWIDTH, yy11b+1);
}
void vradio_draw_erase(t_vradio* x, t_glist* glist)
@@ -123,14 +123,14 @@ void vradio_draw_erase(t_vradio* x, t_glist* glist)
for(i=0; i<n; i++)
{
- sys_vgui(".x%x.c delete %xBASE%d\n", canvas, x, i);
- sys_vgui(".x%x.c delete %xBUT%d\n", canvas, x, i);
+ sys_vgui(".x%lx.c delete %lxBASE%d\n", canvas, x, i);
+ sys_vgui(".x%lx.c delete %lxBUT%d\n", canvas, x, i);
}
- sys_vgui(".x%x.c delete %xLABEL\n", canvas, x);
+ sys_vgui(".x%lx.c delete %lxLABEL\n", canvas, x);
if(!x->x_gui.x_fsf.x_snd_able)
- sys_vgui(".x%x.c delete %xOUT%d\n", canvas, x, 0);
+ sys_vgui(".x%lx.c delete %lxOUT%d\n", canvas, x, 0);
if(!x->x_gui.x_fsf.x_rcv_able)
- sys_vgui(".x%x.c delete %xIN%d\n", canvas, x, 0);
+ sys_vgui(".x%lx.c delete %lxIN%d\n", canvas, x, 0);
}
void vradio_draw_config(t_vradio* x, t_glist* glist)
@@ -138,17 +138,17 @@ void vradio_draw_config(t_vradio* x, t_glist* glist)
t_canvas *canvas=glist_getcanvas(glist);
int n=x->x_number, i;
- sys_vgui(".x%x.c itemconfigure %xLABEL -font {%s %d bold} -fill #%6.6x -text {%s} \n",
- canvas, x, x->x_gui.x_font, x->x_gui.x_fontsize,
- x->x_gui.x_fsf.x_selected?IEM_GUI_COLOR_SELECTED:x->x_gui.x_lcol,
- strcmp(x->x_gui.x_lab->s_name, "empty")?x->x_gui.x_lab->s_name:"");
+ sys_vgui(".x%lx.c itemconfigure %lxLABEL -font {%s %d bold} -fill #%6.6x -text {%s} \n",
+ canvas, x, x->x_gui.x_font, x->x_gui.x_fontsize,
+ x->x_gui.x_fsf.x_selected?IEM_GUI_COLOR_SELECTED:x->x_gui.x_lcol,
+ strcmp(x->x_gui.x_lab->s_name, "empty")?x->x_gui.x_lab->s_name:"");
for(i=0; i<n; i++)
{
- sys_vgui(".x%x.c itemconfigure %xBASE%d -fill #%6.6x\n", canvas, x, i,
- x->x_gui.x_bcol);
- sys_vgui(".x%x.c itemconfigure %xBUT%d -fill #%6.6x -outline #%6.6x\n", canvas, x, i,
- (x->x_on==i)?x->x_gui.x_fcol:x->x_gui.x_bcol,
- (x->x_on==i)?x->x_gui.x_fcol:x->x_gui.x_bcol);
+ sys_vgui(".x%lx.c itemconfigure %lxBASE%d -fill #%6.6x\n", canvas, x, i,
+ x->x_gui.x_bcol);
+ sys_vgui(".x%lx.c itemconfigure %lxBUT%d -fill #%6.6x -outline #%6.6x\n", canvas, x, i,
+ (x->x_on==i)?x->x_gui.x_fcol:x->x_gui.x_bcol,
+ (x->x_on==i)?x->x_gui.x_fcol:x->x_gui.x_bcol);
}
}
@@ -159,20 +159,20 @@ void vradio_draw_io(t_vradio* x, t_glist* glist, int old_snd_rcv_flags)
int ypos=text_ypix(&x->x_gui.x_obj, glist);
if((old_snd_rcv_flags & IEM_GUI_OLD_SND_FLAG) && !x->x_gui.x_fsf.x_snd_able)
- sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xOUT%d\n",
- canvas, xpos,
- ypos+(x->x_number*x->x_gui.x_h)-1,
- xpos+ IOWIDTH,
- ypos+(x->x_number*x->x_gui.x_h), x, 0);
+ sys_vgui(".x%lx.c create rectangle %d %d %d %d -tags %lxOUT%d\n",
+ canvas, xpos,
+ ypos+(x->x_number*x->x_gui.x_h)-1,
+ xpos+ IOWIDTH,
+ ypos+(x->x_number*x->x_gui.x_h), x, 0);
if(!(old_snd_rcv_flags & IEM_GUI_OLD_SND_FLAG) && x->x_gui.x_fsf.x_snd_able)
- sys_vgui(".x%x.c delete %xOUT%d\n", canvas, x, 0);
+ sys_vgui(".x%lx.c delete %lxOUT%d\n", canvas, x, 0);
if((old_snd_rcv_flags & IEM_GUI_OLD_RCV_FLAG) && !x->x_gui.x_fsf.x_rcv_able)
- sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xIN%d\n",
- canvas, xpos, ypos,
- xpos+ IOWIDTH, ypos+1,
- x, 0);
+ sys_vgui(".x%lx.c create rectangle %d %d %d %d -tags %lxIN%d\n",
+ canvas, xpos, ypos,
+ xpos+ IOWIDTH, ypos+1,
+ x, 0);
if(!(old_snd_rcv_flags & IEM_GUI_OLD_RCV_FLAG) && x->x_gui.x_fsf.x_rcv_able)
- sys_vgui(".x%x.c delete %xIN%d\n", canvas, x, 0);
+ sys_vgui(".x%lx.c delete %lxIN%d\n", canvas, x, 0);
}
void vradio_draw_select(t_vradio* x, t_glist* glist)
@@ -182,41 +182,41 @@ void vradio_draw_select(t_vradio* x, t_glist* glist)
if(x->x_gui.x_fsf.x_selected)
{
- for(i=0; i<n; i++)
- {
- sys_vgui(".x%x.c itemconfigure %xBASE%d -outline #%6.6x\n", canvas, x, i,
- IEM_GUI_COLOR_SELECTED);
- }
- sys_vgui(".x%x.c itemconfigure %xLABEL -fill #%6.6x\n", canvas, x, IEM_GUI_COLOR_SELECTED);
+ for(i=0; i<n; i++)
+ {
+ sys_vgui(".x%lx.c itemconfigure %lxBASE%d -outline #%6.6x\n", canvas, x, i,
+ IEM_GUI_COLOR_SELECTED);
+ }
+ sys_vgui(".x%lx.c itemconfigure %lxLABEL -fill #%6.6x\n", canvas, x, IEM_GUI_COLOR_SELECTED);
}
else
{
- for(i=0; i<n; i++)
- {
- sys_vgui(".x%x.c itemconfigure %xBASE%d -outline #%6.6x\n", canvas, x, i,
- IEM_GUI_COLOR_NORMAL);
- }
- sys_vgui(".x%x.c itemconfigure %xLABEL -fill #%6.6x\n", canvas, x,
- x->x_gui.x_lcol);
+ for(i=0; i<n; i++)
+ {
+ sys_vgui(".x%lx.c itemconfigure %lxBASE%d -outline #%6.6x\n", canvas, x, i,
+ IEM_GUI_COLOR_NORMAL);
+ }
+ sys_vgui(".x%lx.c itemconfigure %lxLABEL -fill #%6.6x\n", canvas, x,
+ x->x_gui.x_lcol);
}
}
void vradio_draw(t_vradio *x, t_glist *glist, int mode)
{
if(mode == IEM_GUI_DRAW_MODE_UPDATE)
- vradio_draw_update(x, glist);
+ vradio_draw_update(x, glist);
else if(mode == IEM_GUI_DRAW_MODE_MOVE)
- vradio_draw_move(x, glist);
+ vradio_draw_move(x, glist);
else if(mode == IEM_GUI_DRAW_MODE_NEW)
- vradio_draw_new(x, glist);
+ vradio_draw_new(x, glist);
else if(mode == IEM_GUI_DRAW_MODE_SELECT)
- vradio_draw_select(x, glist);
+ vradio_draw_select(x, glist);
else if(mode == IEM_GUI_DRAW_MODE_ERASE)
- vradio_draw_erase(x, glist);
+ vradio_draw_erase(x, glist);
else if(mode == IEM_GUI_DRAW_MODE_CONFIG)
- vradio_draw_config(x, glist);
+ vradio_draw_config(x, glist);
else if(mode >= IEM_GUI_DRAW_MODE_IO)
- vradio_draw_io(x, glist, mode - IEM_GUI_DRAW_MODE_IO);
+ vradio_draw_io(x, glist, mode - IEM_GUI_DRAW_MODE_IO);
}
/* ------------------------ vdl widgetbehaviour----------------------------- */
@@ -239,16 +239,16 @@ static void vradio_save(t_gobj *z, t_binbuf *b)
iemgui_save(&x->x_gui, srl, bflcol);
binbuf_addv(b, "ssiisiiiisssiiiiiiii", gensym("#X"),gensym("obj"),
- (t_int)x->x_gui.x_obj.te_xpix,
- (t_int)x->x_gui.x_obj.te_ypix,
- (pd_class(&x->x_gui.x_obj.ob_pd) == vradio_old_class ?
- gensym("vdl") : gensym("vradio")),
- x->x_gui.x_w,
- x->x_change, iem_symargstoint(&x->x_gui.x_isa), x->x_number,
- srl[0], srl[1], srl[2],
- x->x_gui.x_ldx, x->x_gui.x_ldy,
- iem_fstyletoint(&x->x_gui.x_fsf), x->x_gui.x_fontsize,
- bflcol[0], bflcol[1], bflcol[2], x->x_on);
+ (int)x->x_gui.x_obj.te_xpix,
+ (int)x->x_gui.x_obj.te_ypix,
+ (pd_class(&x->x_gui.x_obj.ob_pd) == vradio_old_class ?
+ gensym("vdl") : gensym("vradio")),
+ x->x_gui.x_w,
+ x->x_change, iem_symargstoint(&x->x_gui.x_isa), x->x_number,
+ srl[0], srl[1], srl[2],
+ x->x_gui.x_ldx, x->x_gui.x_ldy,
+ iem_fstyletoint(&x->x_gui.x_fsf), x->x_gui.x_fontsize,
+ bflcol[0], bflcol[1], bflcol[2], x->x_on);
binbuf_addv(b, ";");
}
@@ -257,23 +257,26 @@ static void vradio_properties(t_gobj *z, t_glist *owner)
t_vradio *x = (t_vradio *)z;
char buf[800];
t_symbol *srl[3];
+ int hchange=-1;
iemgui_properties(&x->x_gui, srl);
+ if(pd_class(&x->x_gui.x_obj.ob_pd) == vradio_old_class)
+ hchange = x->x_change;
sprintf(buf, "pdtk_iemgui_dialog %%s vradio \
- ----------dimensions(pix):----------- %d %d size: 0 0 empty \
- empty 0.0 empty 0.0 empty %d \
- %d new-only new&old %d %d number: %d \
- %s %s \
- %s %d %d \
- %d %d \
- %d %d %d\n",
- x->x_gui.x_w, IEM_GUI_MINSIZE,
- 0,/*no_schedule*/
- x->x_change, x->x_gui.x_isa.x_loadinit, -1, x->x_number,
- srl[0]->s_name, srl[1]->s_name,
- srl[2]->s_name, x->x_gui.x_ldx, x->x_gui.x_ldy,
- x->x_gui.x_fsf.x_font_style, x->x_gui.x_fontsize,
- 0xffffff & x->x_gui.x_bcol, 0xffffff & x->x_gui.x_fcol, 0xffffff & x->x_gui.x_lcol);
+ ----------dimensions(pix):----------- %d %d size: 0 0 empty \
+ empty 0.0 empty 0.0 empty %d \
+ %d new-only new&old %d %d number: %d \
+ %s %s \
+ %s %d %d \
+ %d %d \
+ %d %d %d\n",
+ x->x_gui.x_w, IEM_GUI_MINSIZE,
+ 0,/*no_schedule*/
+ hchange, x->x_gui.x_isa.x_loadinit, -1, x->x_number,
+ srl[0]->s_name, srl[1]->s_name,
+ srl[2]->s_name, x->x_gui.x_ldx, x->x_gui.x_ldy,
+ x->x_gui.x_fsf.x_font_style, x->x_gui.x_fontsize,
+ 0xffffff & x->x_gui.x_bcol, 0xffffff & x->x_gui.x_fcol, 0xffffff & x->x_gui.x_lcol);
gfxstub_new(&x->x_gui.x_obj.ob_pd, x, buf);
}
@@ -292,21 +295,21 @@ static void vradio_dialog(t_vradio *x, t_symbol *s, int argc, t_atom *argv)
x->x_gui.x_h = x->x_gui.x_w;
if(x->x_number != num)
{
- (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_ERASE);
- x->x_number = num;
- if(x->x_on >= x->x_number)
- {
- x->x_on = x->x_number - 1;
- x->x_on_old = x->x_on;
- }
- (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_NEW);
+ (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_ERASE);
+ x->x_number = num;
+ if(x->x_on >= x->x_number)
+ {
+ x->x_on = x->x_number - 1;
+ x->x_on_old = x->x_on;
+ }
+ (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_NEW);
}
else
{
- (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_CONFIG);
+ (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_CONFIG);
(*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_IO + sr_flags);
- (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_MOVE);
- canvas_fixlinesfor(glist_getcanvas(x->x_gui.x_glist), (t_text*)x);
+ (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_MOVE);
+ canvas_fixlinesfor(glist_getcanvas(x->x_gui.x_glist), (t_text*)x);
}
}
@@ -316,49 +319,49 @@ static void vradio_set(t_vradio *x, t_floatarg f)
int old;
if(i < 0)
- i = 0;
+ i = 0;
if(i >= x->x_number)
- i = x->x_number-1;
+ i = x->x_number-1;
if(x->x_on != x->x_on_old)
{
- old = x->x_on_old;
- x->x_on_old = x->x_on;
- x->x_on = i;
- (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
- x->x_on_old = old;
+ old = x->x_on_old;
+ x->x_on_old = x->x_on;
+ x->x_on = i;
+ (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
+ x->x_on_old = old;
}
else
{
- x->x_on = i;
- (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
+ x->x_on = i;
+ (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
}
}
static void vradio_bang(t_vradio *x)
{
- /* compatibility with earlier "vdial" behavior */
+ /* compatibility with earlier "vdial" behavior */
if (pd_class(&x->x_gui.x_obj.ob_pd) == vradio_old_class)
{
- if((x->x_change)&&(x->x_on != x->x_on_old))
- {
- SETFLOAT(x->x_at, (float)x->x_on_old);
- SETFLOAT(x->x_at+1, 0.0);
- outlet_list(x->x_gui.x_obj.ob_outlet, &s_list, 2, x->x_at);
- if(x->x_gui.x_fsf.x_snd_able && x->x_gui.x_snd->s_thing)
- pd_list(x->x_gui.x_snd->s_thing, &s_list, 2, x->x_at);
- }
- x->x_on_old = x->x_on;
- SETFLOAT(x->x_at, (float)x->x_on);
- SETFLOAT(x->x_at+1, 1.0);
- outlet_list(x->x_gui.x_obj.ob_outlet, &s_list, 2, x->x_at);
- if(x->x_gui.x_fsf.x_snd_able && x->x_gui.x_snd->s_thing)
- pd_list(x->x_gui.x_snd->s_thing, &s_list, 2, x->x_at);
+ if((x->x_change)&&(x->x_on != x->x_on_old))
+ {
+ SETFLOAT(x->x_at, (float)x->x_on_old);
+ SETFLOAT(x->x_at+1, 0.0);
+ outlet_list(x->x_gui.x_obj.ob_outlet, &s_list, 2, x->x_at);
+ if(x->x_gui.x_fsf.x_snd_able && x->x_gui.x_snd->s_thing)
+ pd_list(x->x_gui.x_snd->s_thing, &s_list, 2, x->x_at);
+ }
+ x->x_on_old = x->x_on;
+ SETFLOAT(x->x_at, (float)x->x_on);
+ SETFLOAT(x->x_at+1, 1.0);
+ outlet_list(x->x_gui.x_obj.ob_outlet, &s_list, 2, x->x_at);
+ if(x->x_gui.x_fsf.x_snd_able && x->x_gui.x_snd->s_thing)
+ pd_list(x->x_gui.x_snd->s_thing, &s_list, 2, x->x_at);
}
else
{
- outlet_float(x->x_gui.x_obj.ob_outlet, x->x_on);
- if(x->x_gui.x_fsf.x_snd_able && x->x_gui.x_snd->s_thing)
- pd_float(x->x_gui.x_snd->s_thing, x->x_on);
+ outlet_float(x->x_gui.x_obj.ob_outlet, x->x_on);
+ if(x->x_gui.x_fsf.x_snd_able && x->x_gui.x_snd->s_thing)
+ pd_float(x->x_gui.x_snd->s_thing, x->x_on);
}
}
@@ -367,39 +370,40 @@ static void vradio_fout(t_vradio *x, t_floatarg f)
int i=(int)f;
if(i < 0)
- i = 0;
+ i = 0;
if(i >= x->x_number)
- i = x->x_number-1;
+ i = x->x_number-1;
if (pd_class(&x->x_gui.x_obj.ob_pd) == vradio_old_class)
{
- /* compatibility with earlier "vdial" behavior */
- if((x->x_change)&&(i != x->x_on_old))
- {
+ /* compatibility with earlier "vdial" behavior */
+ if((x->x_change)&&(i != x->x_on_old))
+ {
SETFLOAT(x->x_at, (float)x->x_on_old);
- SETFLOAT(x->x_at+1, 0.0);
- outlet_list(x->x_gui.x_obj.ob_outlet, &s_list, 2, x->x_at);
- if(x->x_gui.x_fsf.x_snd_able && x->x_gui.x_snd->s_thing)
- pd_list(x->x_gui.x_snd->s_thing, &s_list, 2, x->x_at);
- }
- if(x->x_on != x->x_on_old)
- x->x_on_old = x->x_on;
- x->x_on = i;
- (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
- x->x_on_old = x->x_on;
- SETFLOAT(x->x_at, (float)x->x_on);
- SETFLOAT(x->x_at+1, 1.0);
- outlet_list(x->x_gui.x_obj.ob_outlet, &s_list, 2, x->x_at);
- if(x->x_gui.x_fsf.x_snd_able && x->x_gui.x_snd->s_thing)
- pd_list(x->x_gui.x_snd->s_thing, &s_list, 2, x->x_at);
+ SETFLOAT(x->x_at+1, 0.0);
+ outlet_list(x->x_gui.x_obj.ob_outlet, &s_list, 2, x->x_at);
+ if(x->x_gui.x_fsf.x_snd_able && x->x_gui.x_snd->s_thing)
+ pd_list(x->x_gui.x_snd->s_thing, &s_list, 2, x->x_at);
+ }
+ if(x->x_on != x->x_on_old)
+ x->x_on_old = x->x_on;
+ x->x_on = i;
+ (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
+ x->x_on_old = x->x_on;
+ SETFLOAT(x->x_at, (float)x->x_on);
+ SETFLOAT(x->x_at+1, 1.0);
+ outlet_list(x->x_gui.x_obj.ob_outlet, &s_list, 2, x->x_at);
+ if(x->x_gui.x_fsf.x_snd_able && x->x_gui.x_snd->s_thing)
+ pd_list(x->x_gui.x_snd->s_thing, &s_list, 2, x->x_at);
}
else
{
- outlet_float(x->x_gui.x_obj.ob_outlet, x->x_on = i);
- if(x->x_gui.x_fsf.x_snd_able && x->x_gui.x_snd->s_thing)
- pd_float(x->x_gui.x_snd->s_thing, x->x_on);
- (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
- x->x_on_old = x->x_on;
+ x->x_on_old = x->x_on;
+ x->x_on = i;
+ (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
+ outlet_float(x->x_gui.x_obj.ob_outlet, x->x_on);
+ if (x->x_gui.x_fsf.x_snd_able && x->x_gui.x_snd->s_thing)
+ pd_float(x->x_gui.x_snd->s_thing, x->x_on);
}
}
@@ -408,49 +412,49 @@ static void vradio_float(t_vradio *x, t_floatarg f)
int i=(int)f;
if(i < 0)
- i = 0;
+ i = 0;
if(i >= x->x_number)
- i = x->x_number-1;
+ i = x->x_number-1;
if (pd_class(&x->x_gui.x_obj.ob_pd) == vradio_old_class)
{
- /* compatibility with earlier "vdial" behavior */
- if((x->x_change)&&(i != x->x_on_old))
- {
- if(x->x_gui.x_fsf.x_put_in2out)
- {
- SETFLOAT(x->x_at, (float)x->x_on_old);
- SETFLOAT(x->x_at+1, 0.0);
- outlet_list(x->x_gui.x_obj.ob_outlet, &s_list, 2, x->x_at);
- if(x->x_gui.x_fsf.x_snd_able && x->x_gui.x_snd->s_thing)
- pd_list(x->x_gui.x_snd->s_thing, &s_list, 2, x->x_at);
- }
- }
- if(x->x_on != x->x_on_old)
- x->x_on_old = x->x_on;
- x->x_on = i;
- (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
- x->x_on_old = x->x_on;
- if(x->x_gui.x_fsf.x_put_in2out)
- {
- SETFLOAT(x->x_at, (float)x->x_on);
+ /* compatibility with earlier "vdial" behavior */
+ if((x->x_change)&&(i != x->x_on_old))
+ {
+ if(x->x_gui.x_fsf.x_put_in2out)
+ {
+ SETFLOAT(x->x_at, (float)x->x_on_old);
+ SETFLOAT(x->x_at+1, 0.0);
+ outlet_list(x->x_gui.x_obj.ob_outlet, &s_list, 2, x->x_at);
+ if(x->x_gui.x_fsf.x_snd_able && x->x_gui.x_snd->s_thing)
+ pd_list(x->x_gui.x_snd->s_thing, &s_list, 2, x->x_at);
+ }
+ }
+ if(x->x_on != x->x_on_old)
+ x->x_on_old = x->x_on;
+ x->x_on = i;
+ (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
+ x->x_on_old = x->x_on;
+ if(x->x_gui.x_fsf.x_put_in2out)
+ {
+ SETFLOAT(x->x_at, (float)x->x_on);
SETFLOAT(x->x_at+1, 1.0);
- outlet_list(x->x_gui.x_obj.ob_outlet, &s_list, 2, x->x_at);
- if(x->x_gui.x_fsf.x_snd_able && x->x_gui.x_snd->s_thing)
- pd_list(x->x_gui.x_snd->s_thing, &s_list, 2, x->x_at);
- }
+ outlet_list(x->x_gui.x_obj.ob_outlet, &s_list, 2, x->x_at);
+ if(x->x_gui.x_fsf.x_snd_able && x->x_gui.x_snd->s_thing)
+ pd_list(x->x_gui.x_snd->s_thing, &s_list, 2, x->x_at);
+ }
}
else
{
- x->x_on = i;
- if (x->x_gui.x_fsf.x_put_in2out)
- {
- outlet_float(x->x_gui.x_obj.ob_outlet, x->x_on);
- if(x->x_gui.x_fsf.x_snd_able && x->x_gui.x_snd->s_thing)
- pd_float(x->x_gui.x_snd->s_thing, x->x_on);
- }
- (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
- x->x_on_old = x->x_on;
+ x->x_on_old = x->x_on;
+ x->x_on = i;
+ (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
+ if (x->x_gui.x_fsf.x_put_in2out)
+ {
+ outlet_float(x->x_gui.x_obj.ob_outlet, x->x_on);
+ if(x->x_gui.x_fsf.x_snd_able && x->x_gui.x_snd->s_thing)
+ pd_float(x->x_gui.x_snd->s_thing, x->x_on);
+ }
}
}
@@ -466,15 +470,15 @@ static int vradio_newclick(t_gobj *z, struct _glist *glist,
int xpix, int ypix, int shift, int alt, int dbl, int doit)
{
if(doit)
- vradio_click((t_vradio *)z, (t_floatarg)xpix, (t_floatarg)ypix,
- (t_floatarg)shift, 0, (t_floatarg)alt);
+ vradio_click((t_vradio *)z, (t_floatarg)xpix, (t_floatarg)ypix,
+ (t_floatarg)shift, 0, (t_floatarg)alt);
return (1);
}
static void vradio_loadbang(t_vradio *x)
{
if(!sys_noloadbang && x->x_gui.x_isa.x_loadinit)
- vradio_bang(x);
+ vradio_bang(x);
}
static void vradio_number(t_vradio *x, t_floatarg num)
@@ -482,17 +486,17 @@ static void vradio_number(t_vradio *x, t_floatarg num)
int n=(int)num;
if(n < 1)
- n = 1;
+ n = 1;
if(n > IEM_RADIO_MAX)
- n = IEM_RADIO_MAX;
+ n = IEM_RADIO_MAX;
if(n != x->x_number)
{
- (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_ERASE);
- x->x_number = n;
- if(x->x_on >= x->x_number)
- x->x_on = x->x_number - 1;
- x->x_on_old = x->x_on;
- (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_NEW);
+ (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_ERASE);
+ x->x_number = n;
+ if(x->x_on >= x->x_number)
+ x->x_on = x->x_number - 1;
+ x->x_on_old = x->x_on;
+ (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_NEW);
}
}
@@ -557,19 +561,19 @@ static void *vradio_donew(t_symbol *s, int argc, t_atom *argv, int old)
&&IS_A_FLOAT(argv,9)&&IS_A_FLOAT(argv,10)&&IS_A_FLOAT(argv,11)
&&IS_A_FLOAT(argv,12)&&IS_A_FLOAT(argv,13)&&IS_A_FLOAT(argv,14))
{
- a = (int)atom_getintarg(0, argc, argv);
- chg = (int)atom_getintarg(1, argc, argv);
- iem_inttosymargs(&x->x_gui.x_isa, atom_getintarg(2, argc, argv));
- num = (int)atom_getintarg(3, argc, argv);
- iemgui_new_getnames(&x->x_gui, 4, argv);
- ldx = (int)atom_getintarg(7, argc, argv);
- ldy = (int)atom_getintarg(8, argc, argv);
- iem_inttofstyle(&x->x_gui.x_fsf, atom_getintarg(9, argc, argv));
- fs = (int)atom_getintarg(10, argc, argv);
- bflcol[0] = (int)atom_getintarg(11, argc, argv);
- bflcol[1] = (int)atom_getintarg(12, argc, argv);
- bflcol[2] = (int)atom_getintarg(13, argc, argv);
- on = (int)atom_getintarg(14, argc, argv);
+ a = (int)atom_getintarg(0, argc, argv);
+ chg = (int)atom_getintarg(1, argc, argv);
+ iem_inttosymargs(&x->x_gui.x_isa, atom_getintarg(2, argc, argv));
+ num = (int)atom_getintarg(3, argc, argv);
+ iemgui_new_getnames(&x->x_gui, 4, argv);
+ ldx = (int)atom_getintarg(7, argc, argv);
+ ldy = (int)atom_getintarg(8, argc, argv);
+ iem_inttofstyle(&x->x_gui.x_fsf, atom_getintarg(9, argc, argv));
+ fs = (int)atom_getintarg(10, argc, argv);
+ bflcol[0] = (int)atom_getintarg(11, argc, argv);
+ bflcol[1] = (int)atom_getintarg(12, argc, argv);
+ bflcol[2] = (int)atom_getintarg(13, argc, argv);
+ on = (int)atom_getintarg(14, argc, argv);
}
else iemgui_new_getnames(&x->x_gui, 4, 0);
x->x_gui.x_draw = (t_iemfunptr)vradio_draw;
@@ -577,34 +581,34 @@ static void *vradio_donew(t_symbol *s, int argc, t_atom *argv, int old)
x->x_gui.x_fsf.x_rcv_able = 1;
x->x_gui.x_glist = (t_glist *)canvas_getcurrent();
if (!strcmp(x->x_gui.x_snd->s_name, "empty"))
- x->x_gui.x_fsf.x_snd_able = 0;
+ x->x_gui.x_fsf.x_snd_able = 0;
if (!strcmp(x->x_gui.x_rcv->s_name, "empty"))
- x->x_gui.x_fsf.x_rcv_able = 0;
+ x->x_gui.x_fsf.x_rcv_able = 0;
if(x->x_gui.x_fsf.x_font_style == 1) strcpy(x->x_gui.x_font, "helvetica");
else if(x->x_gui.x_fsf.x_font_style == 2) strcpy(x->x_gui.x_font, "times");
else { x->x_gui.x_fsf.x_font_style = 0;
- strcpy(x->x_gui.x_font, "courier"); }
+ strcpy(x->x_gui.x_font, "courier"); }
if(num < 1)
- num = 1;
+ num = 1;
if(num > IEM_RADIO_MAX)
- num = IEM_RADIO_MAX;
+ num = IEM_RADIO_MAX;
x->x_number = num;
if(on < 0)
- on = 0;
+ on = 0;
if(on >= x->x_number)
- on = x->x_number - 1;
+ on = x->x_number - 1;
if(x->x_gui.x_isa.x_loadinit)
- x->x_on = on;
+ x->x_on = on;
else
- x->x_on = 0;
+ x->x_on = 0;
x->x_on_old = x->x_on;
x->x_change = (chg==0)?0:1;
if (x->x_gui.x_fsf.x_rcv_able)
- pd_bind(&x->x_gui.x_obj.ob_pd, x->x_gui.x_rcv);
+ pd_bind(&x->x_gui.x_obj.ob_pd, x->x_gui.x_rcv);
x->x_gui.x_ldx = ldx;
x->x_gui.x_ldy = ldy;
if(fs < 4)
- fs = 4;
+ fs = 4;
x->x_gui.x_fontsize = fs;
x->x_gui.x_w = iemgui_clip_size(a);
x->x_gui.x_h = x->x_gui.x_w;
@@ -627,50 +631,50 @@ static void *vdial_new(t_symbol *s, int argc, t_atom *argv)
static void vradio_ff(t_vradio *x)
{
if(x->x_gui.x_fsf.x_rcv_able)
- pd_unbind(&x->x_gui.x_obj.ob_pd, x->x_gui.x_rcv);
+ pd_unbind(&x->x_gui.x_obj.ob_pd, x->x_gui.x_rcv);
gfxstub_deleteforkey(x);
}
void g_vradio_setup(void)
{
vradio_class = class_new(gensym("vradio"), (t_newmethod)vradio_new,
- (t_method)vradio_ff, sizeof(t_vradio), 0, A_GIMME, 0);
+ (t_method)vradio_ff, sizeof(t_vradio), 0, A_GIMME, 0);
class_addbang(vradio_class, vradio_bang);
class_addfloat(vradio_class, vradio_float);
class_addmethod(vradio_class, (t_method)vradio_click, gensym("click"),
- A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, 0);
+ A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, 0);
class_addmethod(vradio_class, (t_method)vradio_dialog, gensym("dialog"),
- A_GIMME, 0);
+ A_GIMME, 0);
class_addmethod(vradio_class, (t_method)vradio_loadbang,
- gensym("loadbang"), 0);
+ gensym("loadbang"), 0);
class_addmethod(vradio_class, (t_method)vradio_set,
- gensym("set"), A_FLOAT, 0);
+ gensym("set"), A_FLOAT, 0);
class_addmethod(vradio_class, (t_method)vradio_size,
- gensym("size"), A_GIMME, 0);
+ gensym("size"), A_GIMME, 0);
class_addmethod(vradio_class, (t_method)vradio_delta,
- gensym("delta"), A_GIMME, 0);
+ gensym("delta"), A_GIMME, 0);
class_addmethod(vradio_class, (t_method)vradio_pos,
- gensym("pos"), A_GIMME, 0);
+ gensym("pos"), A_GIMME, 0);
class_addmethod(vradio_class, (t_method)vradio_color,
- gensym("color"), A_GIMME, 0);
+ gensym("color"), A_GIMME, 0);
class_addmethod(vradio_class, (t_method)vradio_send,
- gensym("send"), A_DEFSYM, 0);
+ gensym("send"), A_DEFSYM, 0);
class_addmethod(vradio_class, (t_method)vradio_receive,
- gensym("receive"), A_DEFSYM, 0);
+ gensym("receive"), A_DEFSYM, 0);
class_addmethod(vradio_class, (t_method)vradio_label,
- gensym("label"), A_DEFSYM, 0);
+ gensym("label"), A_DEFSYM, 0);
class_addmethod(vradio_class, (t_method)vradio_label_pos,
- gensym("label_pos"), A_GIMME, 0);
+ gensym("label_pos"), A_GIMME, 0);
class_addmethod(vradio_class, (t_method)vradio_label_font,
- gensym("label_font"), A_GIMME, 0);
+ gensym("label_font"), A_GIMME, 0);
class_addmethod(vradio_class, (t_method)vradio_init,
- gensym("init"), A_FLOAT, 0);
+ gensym("init"), A_FLOAT, 0);
class_addmethod(vradio_class, (t_method)vradio_number,
- gensym("number"), A_FLOAT, 0);
+ gensym("number"), A_FLOAT, 0);
class_addmethod(vradio_class, (t_method)vradio_single_change,
- gensym("single_change"), 0);
+ gensym("single_change"), 0);
class_addmethod(vradio_class, (t_method)vradio_double_change,
- gensym("double_change"), 0);
+ gensym("double_change"), 0);
vradio_widgetbehavior.w_getrectfn = vradio_getrect;
vradio_widgetbehavior.w_displacefn = iemgui_displace;
vradio_widgetbehavior.w_selectfn = iemgui_select;
@@ -683,15 +687,15 @@ void g_vradio_setup(void)
class_setsavefn(vradio_class, vradio_save);
class_setpropertiesfn(vradio_class, vradio_properties);
- /* obsolete version (0.34-0.35) */
+ /* obsolete version (0.34-0.35) */
vradio_old_class = class_new(gensym("vdl"), (t_newmethod)vdial_new,
- (t_method)vradio_ff, sizeof(t_vradio), 0, A_GIMME, 0);
+ (t_method)vradio_ff, sizeof(t_vradio), 0, A_GIMME, 0);
class_addbang(vradio_old_class, vradio_bang);
class_addfloat(vradio_old_class, vradio_float);
class_addmethod(vradio_old_class, (t_method)vradio_click, gensym("click"),
- A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, 0);
+ A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, 0);
class_addmethod(vradio_old_class, (t_method)vradio_dialog, gensym("dialog"),
- A_GIMME, 0);
+ A_GIMME, 0);
class_addmethod(vradio_old_class, (t_method)vradio_loadbang, gensym("loadbang"), 0);
class_addmethod(vradio_old_class, (t_method)vradio_set, gensym("set"), A_FLOAT, 0);
class_addmethod(vradio_old_class, (t_method)vradio_size, gensym("size"), A_GIMME, 0);
diff --git a/pd/src/g_vslider.c b/pd/src/g_vslider.c
index add8388f..00dfa701 100644
--- a/pd/src/g_vslider.c
+++ b/pd/src/g_vslider.c
@@ -34,12 +34,12 @@ static void vslider_draw_update(t_vslider *x, t_glist *glist)
{
if (glist_isvisible(glist))
{
- int r = text_ypix(&x->x_gui.x_obj, glist) + x->x_gui.x_h - (x->x_val + 50)/100;
+ int r = text_ypix(&x->x_gui.x_obj, glist) + x->x_gui.x_h - (x->x_val + 50)/100;
int xpos=text_xpix(&x->x_gui.x_obj, glist);
- sys_vgui(".x%x.c coords %xKNOB %d %d %d %d\n",
- glist_getcanvas(glist), x, xpos+1, r,
- xpos + x->x_gui.x_w, r);
+ sys_vgui(".x%lx.c coords %lxKNOB %d %d %d %d\n",
+ glist_getcanvas(glist), x, xpos+1, r,
+ xpos + x->x_gui.x_w, r);
}
}
@@ -50,30 +50,30 @@ static void vslider_draw_new(t_vslider *x, t_glist *glist)
int r = ypos + x->x_gui.x_h - (x->x_val + 50)/100;
t_canvas *canvas=glist_getcanvas(glist);
- sys_vgui(".x%x.c create rectangle %d %d %d %d -fill #%6.6x -tags %xBASE\n",
- canvas, xpos, ypos-2,
- xpos + x->x_gui.x_w, ypos + x->x_gui.x_h+3,
- x->x_gui.x_bcol, x);
- sys_vgui(".x%x.c create line %d %d %d %d -width 3 -fill #%6.6x -tags %xKNOB\n",
- canvas, xpos+1, r,
- xpos + x->x_gui.x_w, r, x->x_gui.x_fcol, x);
- sys_vgui(".x%x.c create text %d %d -text {%s} -anchor w \
- -font {%s %d bold} -fill #%6.6x -tags %xLABEL\n",
- canvas, xpos+x->x_gui.x_ldx, ypos+x->x_gui.x_ldy,
- strcmp(x->x_gui.x_lab->s_name, "empty")?x->x_gui.x_lab->s_name:"",
- x->x_gui.x_font, x->x_gui.x_fontsize, x->x_gui.x_lcol, x);
+ sys_vgui(".x%lx.c create rectangle %d %d %d %d -fill #%6.6x -tags %lxBASE\n",
+ canvas, xpos, ypos-2,
+ xpos + x->x_gui.x_w, ypos + x->x_gui.x_h+3,
+ x->x_gui.x_bcol, x);
+ sys_vgui(".x%lx.c create line %d %d %d %d -width 3 -fill #%6.6x -tags %lxKNOB\n",
+ canvas, xpos+1, r,
+ xpos + x->x_gui.x_w, r, x->x_gui.x_fcol, x);
+ sys_vgui(".x%lx.c create text %d %d -text {%s} -anchor w \
+ -font {%s %d bold} -fill #%6.6x -tags %lxLABEL\n",
+ canvas, xpos+x->x_gui.x_ldx, ypos+x->x_gui.x_ldy,
+ strcmp(x->x_gui.x_lab->s_name, "empty")?x->x_gui.x_lab->s_name:"",
+ x->x_gui.x_font, x->x_gui.x_fontsize, x->x_gui.x_lcol, x);
if(!x->x_gui.x_fsf.x_snd_able)
- sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xOUT%d\n",
- canvas,
- xpos, ypos + x->x_gui.x_h+2,
- xpos+7, ypos + x->x_gui.x_h+3,
- x, 0);
+ sys_vgui(".x%lx.c create rectangle %d %d %d %d -tags %lxOUT%d\n",
+ canvas,
+ xpos, ypos + x->x_gui.x_h+2,
+ xpos+7, ypos + x->x_gui.x_h+3,
+ x, 0);
if(!x->x_gui.x_fsf.x_rcv_able)
- sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xIN%d\n",
- canvas,
- xpos, ypos-2,
- xpos+7, ypos-1,
- x, 0);
+ sys_vgui(".x%lx.c create rectangle %d %d %d %d -tags %lxIN%d\n",
+ canvas,
+ xpos, ypos-2,
+ xpos+7, ypos-1,
+ x, 0);
}
static void vslider_draw_move(t_vslider *x, t_glist *glist)
@@ -83,52 +83,52 @@ static void vslider_draw_move(t_vslider *x, t_glist *glist)
int r = ypos + x->x_gui.x_h - (x->x_val + 50)/100;
t_canvas *canvas=glist_getcanvas(glist);
- sys_vgui(".x%x.c coords %xBASE %d %d %d %d\n",
- canvas, x,
- xpos, ypos-2,
- xpos + x->x_gui.x_w, ypos + x->x_gui.x_h+3);
- sys_vgui(".x%x.c coords %xKNOB %d %d %d %d\n",
- canvas, x, xpos+1, r,
- xpos + x->x_gui.x_w, r);
- sys_vgui(".x%x.c coords %xLABEL %d %d\n",
- canvas, x, xpos+x->x_gui.x_ldx, ypos+x->x_gui.x_ldy);
+ sys_vgui(".x%lx.c coords %lxBASE %d %d %d %d\n",
+ canvas, x,
+ xpos, ypos-2,
+ xpos + x->x_gui.x_w, ypos + x->x_gui.x_h+3);
+ sys_vgui(".x%lx.c coords %lxKNOB %d %d %d %d\n",
+ canvas, x, xpos+1, r,
+ xpos + x->x_gui.x_w, r);
+ sys_vgui(".x%lx.c coords %lxLABEL %d %d\n",
+ canvas, x, xpos+x->x_gui.x_ldx, ypos+x->x_gui.x_ldy);
if(!x->x_gui.x_fsf.x_snd_able)
- sys_vgui(".x%x.c coords %xOUT%d %d %d %d %d\n",
- canvas, x, 0,
- xpos, ypos + x->x_gui.x_h+2,
- xpos+7, ypos + x->x_gui.x_h+3);
+ sys_vgui(".x%lx.c coords %lxOUT%d %d %d %d %d\n",
+ canvas, x, 0,
+ xpos, ypos + x->x_gui.x_h+2,
+ xpos+7, ypos + x->x_gui.x_h+3);
if(!x->x_gui.x_fsf.x_rcv_able)
- sys_vgui(".x%x.c coords %xIN%d %d %d %d %d\n",
- canvas, x, 0,
- xpos, ypos-2,
- xpos+7, ypos-1);
+ sys_vgui(".x%lx.c coords %lxIN%d %d %d %d %d\n",
+ canvas, x, 0,
+ xpos, ypos-2,
+ xpos+7, ypos-1);
}
static void vslider_draw_erase(t_vslider* x,t_glist* glist)
{
t_canvas *canvas=glist_getcanvas(glist);
- sys_vgui(".x%x.c delete %xBASE\n", canvas, x);
- sys_vgui(".x%x.c delete %xKNOB\n", canvas, x);
- sys_vgui(".x%x.c delete %xLABEL\n", canvas, x);
+ sys_vgui(".x%lx.c delete %lxBASE\n", canvas, x);
+ sys_vgui(".x%lx.c delete %lxKNOB\n", canvas, x);
+ sys_vgui(".x%lx.c delete %lxLABEL\n", canvas, x);
if(!x->x_gui.x_fsf.x_snd_able)
- sys_vgui(".x%x.c delete %xOUT%d\n", canvas, x, 0);
+ sys_vgui(".x%lx.c delete %lxOUT%d\n", canvas, x, 0);
if(!x->x_gui.x_fsf.x_rcv_able)
- sys_vgui(".x%x.c delete %xIN%d\n", canvas, x, 0);
+ sys_vgui(".x%lx.c delete %lxIN%d\n", canvas, x, 0);
}
static void vslider_draw_config(t_vslider* x,t_glist* glist)
{
t_canvas *canvas=glist_getcanvas(glist);
- sys_vgui(".x%x.c itemconfigure %xLABEL -font {%s %d bold} -fill #%6.6x -text {%s} \n",
- canvas, x, x->x_gui.x_font, x->x_gui.x_fontsize,
- x->x_gui.x_fsf.x_selected?IEM_GUI_COLOR_SELECTED:x->x_gui.x_lcol,
- strcmp(x->x_gui.x_lab->s_name, "empty")?x->x_gui.x_lab->s_name:"");
- sys_vgui(".x%x.c itemconfigure %xKNOB -fill #%6.6x\n", canvas,
- x, x->x_gui.x_fcol);
- sys_vgui(".x%x.c itemconfigure %xBASE -fill #%6.6x\n", canvas,
- x, x->x_gui.x_bcol);
+ sys_vgui(".x%lx.c itemconfigure %lxLABEL -font {%s %d bold} -fill #%6.6x -text {%s} \n",
+ canvas, x, x->x_gui.x_font, x->x_gui.x_fontsize,
+ x->x_gui.x_fsf.x_selected?IEM_GUI_COLOR_SELECTED:x->x_gui.x_lcol,
+ strcmp(x->x_gui.x_lab->s_name, "empty")?x->x_gui.x_lab->s_name:"");
+ sys_vgui(".x%lx.c itemconfigure %lxKNOB -fill #%6.6x\n", canvas,
+ x, x->x_gui.x_fcol);
+ sys_vgui(".x%lx.c itemconfigure %lxBASE -fill #%6.6x\n", canvas,
+ x, x->x_gui.x_bcol);
}
static void vslider_draw_io(t_vslider* x,t_glist* glist, int old_snd_rcv_flags)
@@ -138,21 +138,21 @@ static void vslider_draw_io(t_vslider* x,t_glist* glist, int old_snd_rcv_flags)
t_canvas *canvas=glist_getcanvas(glist);
if((old_snd_rcv_flags & IEM_GUI_OLD_SND_FLAG) && !x->x_gui.x_fsf.x_snd_able)
- sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xOUT%d\n",
- canvas,
- xpos, ypos + x->x_gui.x_h+2,
- xpos+7, ypos + x->x_gui.x_h+3,
- x, 0);
+ sys_vgui(".x%lx.c create rectangle %d %d %d %d -tags %lxOUT%d\n",
+ canvas,
+ xpos, ypos + x->x_gui.x_h+2,
+ xpos+7, ypos + x->x_gui.x_h+3,
+ x, 0);
if(!(old_snd_rcv_flags & IEM_GUI_OLD_SND_FLAG) && x->x_gui.x_fsf.x_snd_able)
- sys_vgui(".x%x.c delete %xOUT%d\n", canvas, x, 0);
+ sys_vgui(".x%lx.c delete %lxOUT%d\n", canvas, x, 0);
if((old_snd_rcv_flags & IEM_GUI_OLD_RCV_FLAG) && !x->x_gui.x_fsf.x_rcv_able)
- sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xIN%d\n",
- canvas,
- xpos, ypos-2,
- xpos+7, ypos-1,
- x, 0);
+ sys_vgui(".x%lx.c create rectangle %d %d %d %d -tags %lxIN%d\n",
+ canvas,
+ xpos, ypos-2,
+ xpos+7, ypos-1,
+ x, 0);
if(!(old_snd_rcv_flags & IEM_GUI_OLD_RCV_FLAG) && x->x_gui.x_fsf.x_rcv_able)
- sys_vgui(".x%x.c delete %xIN%d\n", canvas, x, 0);
+ sys_vgui(".x%lx.c delete %lxIN%d\n", canvas, x, 0);
}
static void vslider_draw_select(t_vslider *x, t_glist *glist)
@@ -161,39 +161,39 @@ static void vslider_draw_select(t_vslider *x, t_glist *glist)
if(x->x_gui.x_fsf.x_selected)
{
- sys_vgui(".x%x.c itemconfigure %xBASE -outline #%6.6x\n", canvas, x, IEM_GUI_COLOR_SELECTED);
- sys_vgui(".x%x.c itemconfigure %xLABEL -fill #%6.6x\n", canvas, x, IEM_GUI_COLOR_SELECTED);
+ sys_vgui(".x%lx.c itemconfigure %lxBASE -outline #%6.6x\n", canvas, x, IEM_GUI_COLOR_SELECTED);
+ sys_vgui(".x%lx.c itemconfigure %lxLABEL -fill #%6.6x\n", canvas, x, IEM_GUI_COLOR_SELECTED);
}
else
{
- sys_vgui(".x%x.c itemconfigure %xBASE -outline #%6.6x\n", canvas, x, IEM_GUI_COLOR_NORMAL);
- sys_vgui(".x%x.c itemconfigure %xLABEL -fill #%6.6x\n", canvas, x, x->x_gui.x_lcol);
+ sys_vgui(".x%lx.c itemconfigure %lxBASE -outline #%6.6x\n", canvas, x, IEM_GUI_COLOR_NORMAL);
+ sys_vgui(".x%lx.c itemconfigure %lxLABEL -fill #%6.6x\n", canvas, x, x->x_gui.x_lcol);
}
}
void vslider_draw(t_vslider *x, t_glist *glist, int mode)
{
if(mode == IEM_GUI_DRAW_MODE_UPDATE)
- vslider_draw_update(x, glist);
+ vslider_draw_update(x, glist);
else if(mode == IEM_GUI_DRAW_MODE_MOVE)
- vslider_draw_move(x, glist);
+ vslider_draw_move(x, glist);
else if(mode == IEM_GUI_DRAW_MODE_NEW)
- vslider_draw_new(x, glist);
+ vslider_draw_new(x, glist);
else if(mode == IEM_GUI_DRAW_MODE_SELECT)
- vslider_draw_select(x, glist);
+ vslider_draw_select(x, glist);
else if(mode == IEM_GUI_DRAW_MODE_ERASE)
- vslider_draw_erase(x, glist);
+ vslider_draw_erase(x, glist);
else if(mode == IEM_GUI_DRAW_MODE_CONFIG)
- vslider_draw_config(x, glist);
+ vslider_draw_config(x, glist);
else if(mode >= IEM_GUI_DRAW_MODE_IO)
- vslider_draw_io(x, glist, mode - IEM_GUI_DRAW_MODE_IO);
+ vslider_draw_io(x, glist, mode - IEM_GUI_DRAW_MODE_IO);
}
/* ------------------------ vsl widgetbehaviour----------------------------- */
static void vslider_getrect(t_gobj *z, t_glist *glist,
- int *xp1, int *yp1, int *xp2, int *yp2)
+ int *xp1, int *yp1, int *xp2, int *yp2)
{
t_vslider* x = (t_vslider*)z;
@@ -211,61 +211,61 @@ static void vslider_save(t_gobj *z, t_binbuf *b)
iemgui_save(&x->x_gui, srl, bflcol);
binbuf_addv(b, "ssiisiiffiisssiiiiiiiii", gensym("#X"),gensym("obj"),
- (t_int)x->x_gui.x_obj.te_xpix, (t_int)x->x_gui.x_obj.te_ypix,
- gensym("vsl"), x->x_gui.x_w, x->x_gui.x_h,
- (float)x->x_min, (float)x->x_max,
- x->x_lin0_log1, iem_symargstoint(&x->x_gui.x_isa),
- srl[0], srl[1], srl[2],
- x->x_gui.x_ldx, x->x_gui.x_ldy,
- iem_fstyletoint(&x->x_gui.x_fsf), x->x_gui.x_fontsize,
- bflcol[0], bflcol[1], bflcol[2],
- x->x_val, x->x_steady);
+ (int)x->x_gui.x_obj.te_xpix, (int)x->x_gui.x_obj.te_ypix,
+ gensym("vsl"), x->x_gui.x_w, x->x_gui.x_h,
+ (float)x->x_min, (float)x->x_max,
+ x->x_lin0_log1, iem_symargstoint(&x->x_gui.x_isa),
+ srl[0], srl[1], srl[2],
+ x->x_gui.x_ldx, x->x_gui.x_ldy,
+ iem_fstyletoint(&x->x_gui.x_fsf), x->x_gui.x_fontsize,
+ bflcol[0], bflcol[1], bflcol[2],
+ x->x_val, x->x_steady);
binbuf_addv(b, ";");
}
void vslider_check_height(t_vslider *x, int h)
{
if(h < IEM_SL_MINSIZE)
- h = IEM_SL_MINSIZE;
+ h = IEM_SL_MINSIZE;
x->x_gui.x_h = h;
if(x->x_val > (x->x_gui.x_h*100 - 100))
{
- x->x_pos = x->x_gui.x_h*100 - 100;
- x->x_val = x->x_pos;
+ x->x_pos = x->x_gui.x_h*100 - 100;
+ x->x_val = x->x_pos;
}
if(x->x_lin0_log1)
- x->x_k = log(x->x_max/x->x_min)/(double)(x->x_gui.x_h - 1);
+ x->x_k = log(x->x_max/x->x_min)/(double)(x->x_gui.x_h - 1);
else
- x->x_k = (x->x_max - x->x_min)/(double)(x->x_gui.x_h - 1);
+ x->x_k = (x->x_max - x->x_min)/(double)(x->x_gui.x_h - 1);
}
void vslider_check_minmax(t_vslider *x, double min, double max)
{
if(x->x_lin0_log1)
{
- if((min == 0.0)&&(max == 0.0))
- max = 1.0;
- if(max > 0.0)
- {
- if(min <= 0.0)
- min = 0.01*max;
- }
- else
- {
- if(min > 0.0)
- max = 0.01*min;
- }
+ if((min == 0.0)&&(max == 0.0))
+ max = 1.0;
+ if(max > 0.0)
+ {
+ if(min <= 0.0)
+ min = 0.01*max;
+ }
+ else
+ {
+ if(min > 0.0)
+ max = 0.01*min;
+ }
}
x->x_min = min;
x->x_max = max;
if(x->x_min > x->x_max) /* bugfix */
- x->x_gui.x_isa.x_reverse = 1;
+ x->x_gui.x_isa.x_reverse = 1;
else
x->x_gui.x_isa.x_reverse = 0;
if(x->x_lin0_log1)
- x->x_k = log(x->x_max/x->x_min)/(double)(x->x_gui.x_h - 1);
+ x->x_k = log(x->x_max/x->x_min)/(double)(x->x_gui.x_h - 1);
else
- x->x_k = (x->x_max - x->x_min)/(double)(x->x_gui.x_h - 1);
+ x->x_k = (x->x_max - x->x_min)/(double)(x->x_gui.x_h - 1);
}
static void vslider_properties(t_gobj *z, t_glist *owner)
@@ -277,20 +277,20 @@ static void vslider_properties(t_gobj *z, t_glist *owner)
iemgui_properties(&x->x_gui, srl);
sprintf(buf, "pdtk_iemgui_dialog %%s VSLIDER \
- --------dimensions(pix)(pix):-------- %d %d width: %d %d height: \
- -----------output-range:----------- %g bottom: %g top: %d \
- %d lin log %d %d empty %d \
- %s %s \
- %s %d %d \
- %d %d \
- %d %d %d\n",
- x->x_gui.x_w, IEM_GUI_MINSIZE, x->x_gui.x_h, IEM_SL_MINSIZE,
- x->x_min, x->x_max, 0,/*no_schedule*/
- x->x_lin0_log1, x->x_gui.x_isa.x_loadinit, x->x_steady, -1,/*no multi, but iem-characteristic*/
- srl[0]->s_name, srl[1]->s_name,
- srl[2]->s_name, x->x_gui.x_ldx, x->x_gui.x_ldy,
- x->x_gui.x_fsf.x_font_style, x->x_gui.x_fontsize,
- 0xffffff & x->x_gui.x_bcol, 0xffffff & x->x_gui.x_fcol, 0xffffff & x->x_gui.x_lcol);
+ --------dimensions(pix)(pix):-------- %d %d width: %d %d height: \
+ -----------output-range:----------- %g bottom: %g top: %d \
+ %d lin log %d %d empty %d \
+ %s %s \
+ %s %d %d \
+ %d %d \
+ %d %d %d\n",
+ x->x_gui.x_w, IEM_GUI_MINSIZE, x->x_gui.x_h, IEM_SL_MINSIZE,
+ x->x_min, x->x_max, 0,/*no_schedule*/
+ x->x_lin0_log1, x->x_gui.x_isa.x_loadinit, x->x_steady, -1,/*no multi, but iem-characteristic*/
+ srl[0]->s_name, srl[1]->s_name,
+ srl[2]->s_name, x->x_gui.x_ldx, x->x_gui.x_ldy,
+ x->x_gui.x_fsf.x_font_style, x->x_gui.x_fontsize,
+ 0xffffff & x->x_gui.x_bcol, 0xffffff & x->x_gui.x_fcol, 0xffffff & x->x_gui.x_lcol);
gfxstub_new(&x->x_gui.x_obj.ob_pd, x, buf);
}
@@ -299,15 +299,15 @@ static void vslider_bang(t_vslider *x)
double out;
if(x->x_lin0_log1)
- out = x->x_min*exp(x->x_k*(double)(x->x_val)*0.01);
+ out = x->x_min*exp(x->x_k*(double)(x->x_val)*0.01);
else
- out = (double)(x->x_val)*0.01*x->x_k + x->x_min;
+ out = (double)(x->x_val)*0.01*x->x_k + x->x_min;
if((out < 1.0e-10)&&(out > -1.0e-10))
- out = 0.0;
+ out = 0.0;
outlet_float(x->x_gui.x_obj.ob_outlet, out);
if(x->x_gui.x_fsf.x_snd_able && x->x_gui.x_snd->s_thing)
- pd_float(x->x_gui.x_snd->s_thing, out);
+ pd_float(x->x_gui.x_snd->s_thing, out);
}
static void vslider_dialog(t_vslider *x, t_symbol *s, int argc, t_atom *argv)
@@ -324,9 +324,9 @@ static void vslider_dialog(t_vslider *x, t_symbol *s, int argc, t_atom *argv)
if(lilo != 0) lilo = 1;
x->x_lin0_log1 = lilo;
if(steady)
- x->x_steady = 1;
+ x->x_steady = 1;
else
- x->x_steady = 0;
+ x->x_steady = 0;
sr_flags = iemgui_dialog(&x->x_gui, srl, argc, argv);
x->x_gui.x_w = iemgui_clip_size(w);
vslider_check_height(x, h);
@@ -342,58 +342,58 @@ static void vslider_motion(t_vslider *x, t_floatarg dx, t_floatarg dy)
int old = x->x_val;
if(x->x_gui.x_fsf.x_finemoved)
- x->x_pos -= (int)dy;
+ x->x_pos -= (int)dy;
else
- x->x_pos -= 100*(int)dy;
+ x->x_pos -= 100*(int)dy;
x->x_val = x->x_pos;
if(x->x_val > (100*x->x_gui.x_h - 100))
{
- x->x_val = 100*x->x_gui.x_h - 100;
- x->x_pos += 50;
- x->x_pos -= x->x_pos%100;
+ x->x_val = 100*x->x_gui.x_h - 100;
+ x->x_pos += 50;
+ x->x_pos -= x->x_pos%100;
}
if(x->x_val < 0)
{
- x->x_val = 0;
- x->x_pos -= 50;
- x->x_pos -= x->x_pos%100;
+ x->x_val = 0;
+ x->x_pos -= 50;
+ x->x_pos -= x->x_pos%100;
}
if(old != x->x_val)
{
- (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
- vslider_bang(x);
+ (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
+ vslider_bang(x);
}
}
static void vslider_click(t_vslider *x, t_floatarg xpos, t_floatarg ypos,
- t_floatarg shift, t_floatarg ctrl, t_floatarg alt)
+ t_floatarg shift, t_floatarg ctrl, t_floatarg alt)
{
if(!x->x_steady)
- x->x_val = (int)(100.0 * (x->x_gui.x_h + text_ypix(&x->x_gui.x_obj, x->x_gui.x_glist) - ypos));
+ x->x_val = (int)(100.0 * (x->x_gui.x_h + text_ypix(&x->x_gui.x_obj, x->x_gui.x_glist) - ypos));
if(x->x_val > (100*x->x_gui.x_h - 100))
- x->x_val = 100*x->x_gui.x_h - 100;
+ x->x_val = 100*x->x_gui.x_h - 100;
if(x->x_val < 0)
- x->x_val = 0;
+ x->x_val = 0;
x->x_pos = x->x_val;
(*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
vslider_bang(x);
glist_grab(x->x_gui.x_glist, &x->x_gui.x_obj.te_g,
- (t_glistmotionfn)vslider_motion, 0, xpos, ypos);
+ (t_glistmotionfn)vslider_motion, 0, xpos, ypos);
}
static int vslider_newclick(t_gobj *z, struct _glist *glist,
- int xpix, int ypix, int shift, int alt, int dbl, int doit)
+ int xpix, int ypix, int shift, int alt, int dbl, int doit)
{
t_vslider* x = (t_vslider *)z;
if(doit)
{
- vslider_click( x, (t_floatarg)xpix, (t_floatarg)ypix, (t_floatarg)shift,
- 0, (t_floatarg)alt);
- if(shift)
- x->x_gui.x_fsf.x_finemoved = 1;
- else
- x->x_gui.x_fsf.x_finemoved = 0;
+ vslider_click( x, (t_floatarg)xpix, (t_floatarg)ypix, (t_floatarg)shift,
+ 0, (t_floatarg)alt);
+ if(shift)
+ x->x_gui.x_fsf.x_finemoved = 1;
+ else
+ x->x_gui.x_fsf.x_finemoved = 0;
}
return (1);
}
@@ -404,22 +404,22 @@ static void vslider_set(t_vslider *x, t_floatarg f)
if(x->x_gui.x_isa.x_reverse) /* bugfix */
{
- if(f > x->x_min)
- f = x->x_min;
- if(f < x->x_max)
- f = x->x_max;
+ if(f > x->x_min)
+ f = x->x_min;
+ if(f < x->x_max)
+ f = x->x_max;
}
else
{
- if(f > x->x_max)
- f = x->x_max;
- if(f < x->x_min)
- f = x->x_min;
+ if(f > x->x_max)
+ f = x->x_max;
+ if(f < x->x_min)
+ f = x->x_min;
}
if(x->x_lin0_log1)
- g = log(f/x->x_min)/x->x_k;
+ g = log(f/x->x_min)/x->x_k;
else
- g = (f - x->x_min) / x->x_k;
+ g = (f - x->x_min) / x->x_k;
x->x_val = (int)(100.0*g + 0.49999);
x->x_pos = x->x_val;
(*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
@@ -429,14 +429,14 @@ static void vslider_float(t_vslider *x, t_floatarg f)
{
vslider_set(x, f);
if(x->x_gui.x_fsf.x_put_in2out)
- vslider_bang(x);
+ vslider_bang(x);
}
static void vslider_size(t_vslider *x, t_symbol *s, int ac, t_atom *av)
{
x->x_gui.x_w = iemgui_clip_size((int)atom_getintarg(0, ac, av));
if(ac > 1)
- vslider_check_height(x, (int)atom_getintarg(1, ac, av));
+ vslider_check_height(x, (int)atom_getintarg(1, ac, av));
iemgui_size((void *)x, &x->x_gui);
}
@@ -449,7 +449,7 @@ static void vslider_pos(t_vslider *x, t_symbol *s, int ac, t_atom *av)
static void vslider_range(t_vslider *x, t_symbol *s, int ac, t_atom *av)
{
vslider_check_minmax(x, (double)atom_getfloatarg(0, ac, av),
- (double)atom_getfloatarg(1, ac, av));
+ (double)atom_getfloatarg(1, ac, av));
}
static void vslider_color(t_vslider *x, t_symbol *s, int ac, t_atom *av)
@@ -496,8 +496,8 @@ static void vslider_loadbang(t_vslider *x)
{
if(!sys_noloadbang && x->x_gui.x_isa.x_loadinit)
{
- (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
- vslider_bang(x);
+ (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
+ vslider_bang(x);
}
}
@@ -524,33 +524,33 @@ static void *vslider_new(t_symbol *s, int argc, t_atom *argv)
&&IS_A_FLOAT(argv,11)&&IS_A_FLOAT(argv,12)&&IS_A_FLOAT(argv,13)
&&IS_A_FLOAT(argv,14)&&IS_A_FLOAT(argv,15)&&IS_A_FLOAT(argv,16))
{
- w = (int)atom_getintarg(0, argc, argv);
- h = (int)atom_getintarg(1, argc, argv);
- min = (double)atom_getfloatarg(2, argc, argv);
- max = (double)atom_getfloatarg(3, argc, argv);
- lilo = (int)atom_getintarg(4, argc, argv);
- iem_inttosymargs(&x->x_gui.x_isa, atom_getintarg(5, argc, argv));
- iemgui_new_getnames(&x->x_gui, 6, argv);
- ldx = (int)atom_getintarg(9, argc, argv);
- ldy = (int)atom_getintarg(10, argc, argv);
- iem_inttofstyle(&x->x_gui.x_fsf, atom_getintarg(11, argc, argv));
- fs = (int)atom_getintarg(12, argc, argv);
- bflcol[0] = (int)atom_getintarg(13, argc, argv);
- bflcol[1] = (int)atom_getintarg(14, argc, argv);
- bflcol[2] = (int)atom_getintarg(15, argc, argv);
- v = (int)atom_getintarg(16, argc, argv);
+ w = (int)atom_getintarg(0, argc, argv);
+ h = (int)atom_getintarg(1, argc, argv);
+ min = (double)atom_getfloatarg(2, argc, argv);
+ max = (double)atom_getfloatarg(3, argc, argv);
+ lilo = (int)atom_getintarg(4, argc, argv);
+ iem_inttosymargs(&x->x_gui.x_isa, atom_getintarg(5, argc, argv));
+ iemgui_new_getnames(&x->x_gui, 6, argv);
+ ldx = (int)atom_getintarg(9, argc, argv);
+ ldy = (int)atom_getintarg(10, argc, argv);
+ iem_inttofstyle(&x->x_gui.x_fsf, atom_getintarg(11, argc, argv));
+ fs = (int)atom_getintarg(12, argc, argv);
+ bflcol[0] = (int)atom_getintarg(13, argc, argv);
+ bflcol[1] = (int)atom_getintarg(14, argc, argv);
+ bflcol[2] = (int)atom_getintarg(15, argc, argv);
+ v = (int)atom_getintarg(16, argc, argv);
}
else iemgui_new_getnames(&x->x_gui, 6, 0);
if((argc == 18)&&IS_A_FLOAT(argv,17))
- steady = (int)atom_getintarg(17, argc, argv);
+ steady = (int)atom_getintarg(17, argc, argv);
x->x_gui.x_draw = (t_iemfunptr)vslider_draw;
x->x_gui.x_fsf.x_snd_able = 1;
x->x_gui.x_fsf.x_rcv_able = 1;
x->x_gui.x_glist = (t_glist *)canvas_getcurrent();
if(x->x_gui.x_isa.x_loadinit)
- x->x_val = v;
+ x->x_val = v;
else
- x->x_val = 0;
+ x->x_val = 0;
x->x_pos = x->x_val;
if(lilo != 0) lilo = 1;
x->x_lin0_log1 = lilo;
@@ -561,12 +561,12 @@ static void *vslider_new(t_symbol *s, int argc, t_atom *argv)
if(x->x_gui.x_fsf.x_font_style == 1) strcpy(x->x_gui.x_font, "helvetica");
else if(x->x_gui.x_fsf.x_font_style == 2) strcpy(x->x_gui.x_font, "times");
else { x->x_gui.x_fsf.x_font_style = 0;
- strcpy(x->x_gui.x_font, "courier"); }
+ strcpy(x->x_gui.x_font, "courier"); }
if(x->x_gui.x_fsf.x_rcv_able) pd_bind(&x->x_gui.x_obj.ob_pd, x->x_gui.x_rcv);
x->x_gui.x_ldx = ldx;
x->x_gui.x_ldy = ldy;
if(fs < 4)
- fs = 4;
+ fs = 4;
x->x_gui.x_fontsize = fs;
x->x_gui.x_w = iemgui_clip_size(w);
vslider_check_height(x, h);
@@ -580,23 +580,23 @@ static void *vslider_new(t_symbol *s, int argc, t_atom *argv)
static void vslider_free(t_vslider *x)
{
if(x->x_gui.x_fsf.x_rcv_able)
- pd_unbind(&x->x_gui.x_obj.ob_pd, x->x_gui.x_rcv);
+ pd_unbind(&x->x_gui.x_obj.ob_pd, x->x_gui.x_rcv);
gfxstub_deleteforkey(x);
}
void g_vslider_setup(void)
{
vslider_class = class_new(gensym("vsl"), (t_newmethod)vslider_new,
- (t_method)vslider_free, sizeof(t_vslider), 0, A_GIMME, 0);
+ (t_method)vslider_free, sizeof(t_vslider), 0, A_GIMME, 0);
class_addcreator((t_newmethod)vslider_new, gensym("vslider"), A_GIMME, 0);
class_addbang(vslider_class,vslider_bang);
class_addfloat(vslider_class,vslider_float);
class_addmethod(vslider_class, (t_method)vslider_click, gensym("click"),
- A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, 0);
+ A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, 0);
class_addmethod(vslider_class, (t_method)vslider_motion, gensym("motion"),
- A_FLOAT, A_FLOAT, 0);
+ A_FLOAT, A_FLOAT, 0);
class_addmethod(vslider_class, (t_method)vslider_dialog, gensym("dialog"),
- A_GIMME, 0);
+ A_GIMME, 0);
class_addmethod(vslider_class, (t_method)vslider_loadbang, gensym("loadbang"), 0);
class_addmethod(vslider_class, (t_method)vslider_set, gensym("set"), A_FLOAT, 0);
class_addmethod(vslider_class, (t_method)vslider_size, gensym("size"), A_GIMME, 0);
diff --git a/pd/src/g_vumeter.c b/pd/src/g_vumeter.c
index 2f77c958..983a28e4 100644
--- a/pd/src/g_vumeter.c
+++ b/pd/src/g_vumeter.c
@@ -33,12 +33,12 @@ static void vu_update_rms(t_vu *x, t_glist *glist)
{
if(glist_isvisible(glist))
{
- int w4=x->x_gui.x_w/4, off=text_ypix(&x->x_gui.x_obj, glist)-1;
- int xpos=text_xpix(&x->x_gui.x_obj, glist), quad1=xpos+w4+1, quad3=xpos+x->x_gui.x_w-w4-1;
+ int w4=x->x_gui.x_w/4, off=text_ypix(&x->x_gui.x_obj, glist)-1;
+ int xpos=text_xpix(&x->x_gui.x_obj, glist), quad1=xpos+w4+1, quad3=xpos+x->x_gui.x_w-w4-1;
- sys_vgui(".x%x.c coords %xRCOVER %d %d %d %d\n",
- glist_getcanvas(glist), x, quad1, off, quad3,
- off + (x->x_led_size+1)*(IEM_VU_STEPS-x->x_rms));
+ sys_vgui(".x%lx.c coords %lxRCOVER %d %d %d %d\n",
+ glist_getcanvas(glist), x, quad1, off, quad3,
+ off + (x->x_led_size+1)*(IEM_VU_STEPS-x->x_rms));
}
}
@@ -49,30 +49,30 @@ static void vu_update_peak(t_vu *x, t_glist *glist)
if(glist_isvisible(glist))
{
int xpos=text_xpix(&x->x_gui.x_obj, glist);
- int ypos=text_ypix(&x->x_gui.x_obj, glist);
-
- if(x->x_peak)
- {
- int i=iemgui_vu_col[x->x_peak];
- int j=ypos + (x->x_led_size+1)*(IEM_VU_STEPS+1-x->x_peak)
- - (x->x_led_size+1)/2;
-
- sys_vgui(".x%x.c coords %xPLED %d %d %d %d\n", canvas, x,
- xpos, j,
- xpos+x->x_gui.x_w+1, j);
- sys_vgui(".x%x.c itemconfigure %xPLED -fill #%6.6x\n", canvas, x,
- iemgui_color_hex[i]);
- }
- else
- {
- int mid=xpos+x->x_gui.x_w/2;
-
- sys_vgui(".x%x.c itemconfigure %xPLED -fill #%6.6x\n",
- canvas, x, x->x_gui.x_bcol);
- sys_vgui(".x%x.c coords %xPLED %d %d %d %d\n",
- canvas, x, mid, ypos+20,
- mid, ypos+20);
- }
+ int ypos=text_ypix(&x->x_gui.x_obj, glist);
+
+ if(x->x_peak)
+ {
+ int i=iemgui_vu_col[x->x_peak];
+ int j=ypos + (x->x_led_size+1)*(IEM_VU_STEPS+1-x->x_peak)
+ - (x->x_led_size+1)/2;
+
+ sys_vgui(".x%lx.c coords %lxPLED %d %d %d %d\n", canvas, x,
+ xpos, j,
+ xpos+x->x_gui.x_w+1, j);
+ sys_vgui(".x%lx.c itemconfigure %lxPLED -fill #%6.6x\n", canvas, x,
+ iemgui_color_hex[i]);
+ }
+ else
+ {
+ int mid=xpos+x->x_gui.x_w/2;
+
+ sys_vgui(".x%lx.c itemconfigure %lxPLED -fill #%6.6x\n",
+ canvas, x, x->x_gui.x_bcol);
+ sys_vgui(".x%lx.c coords %lxPLED %d %d %d %d\n",
+ canvas, x, mid, ypos+20,
+ mid, ypos+20);
+ }
}
}
@@ -83,73 +83,73 @@ static void vu_draw_new(t_vu *x, t_glist *glist)
int xpos=text_xpix(&x->x_gui.x_obj, glist);
int ypos=text_ypix(&x->x_gui.x_obj, glist);
int w4=x->x_gui.x_w/4, mid=xpos+x->x_gui.x_w/2,
- quad1=xpos+w4+1;
+ quad1=xpos+w4+1;
int quad3=xpos+x->x_gui.x_w-w4,
- end=xpos+x->x_gui.x_w+4;
+ end=xpos+x->x_gui.x_w+4;
int k1=x->x_led_size+1, k2=IEM_VU_STEPS+1, k3=k1/2;
int led_col, yyy, i, k4=ypos-k3;
- sys_vgui(".x%x.c create rectangle %d %d %d %d -fill #%6.6x -tags %xBASE\n",
- canvas, xpos-1, ypos-2,
- xpos+x->x_gui.x_w+1,
- ypos+x->x_gui.x_h+2, x->x_gui.x_bcol, x);
+ sys_vgui(".x%lx.c create rectangle %d %d %d %d -fill #%6.6x -tags %lxBASE\n",
+ canvas, xpos-1, ypos-2,
+ xpos+x->x_gui.x_w+1,
+ ypos+x->x_gui.x_h+2, x->x_gui.x_bcol, x);
for(i=1; i<=IEM_VU_STEPS; i++)
{
- led_col = iemgui_vu_col[i];
- yyy = k4 + k1*(k2-i);
- sys_vgui(".x%x.c create line %d %d %d %d -width %d -fill #%6.6x -tags %xRLED%d\n",
- canvas, quad1, yyy, quad3, yyy, x->x_led_size, iemgui_color_hex[led_col], x, i);
- if(((i+2)&3) && (x->x_scale))
- sys_vgui(".x%x.c create text %d %d -text {%s} -anchor w \
- -font {%s %d bold} -fill #%6.6x -tags %xSCALE%d\n",
- canvas, end, yyy+k3, iemgui_vu_scale_str[i], x->x_gui.x_font, x->x_gui.x_fontsize,
- x->x_gui.x_lcol, x, i);
+ led_col = iemgui_vu_col[i];
+ yyy = k4 + k1*(k2-i);
+ sys_vgui(".x%lx.c create line %d %d %d %d -width %d -fill #%6.6x -tags %lxRLED%d\n",
+ canvas, quad1, yyy, quad3, yyy, x->x_led_size, iemgui_color_hex[led_col], x, i);
+ if(((i+2)&3) && (x->x_scale))
+ sys_vgui(".x%lx.c create text %d %d -text {%s} -anchor w \
+ -font {%s %d bold} -fill #%6.6x -tags %lxSCALE%d\n",
+ canvas, end, yyy+k3, iemgui_vu_scale_str[i], x->x_gui.x_font, x->x_gui.x_fontsize,
+ x->x_gui.x_lcol, x, i);
}
if(x->x_scale)
{
- i=IEM_VU_STEPS+1;
- yyy = k4 + k1*(k2-i);
- sys_vgui(".x%x.c create text %d %d -text {%s} -anchor w \
- -font {%s %d bold} -fill #%6.6x -tags %xSCALE%d\n",
- canvas, end, yyy+k3, iemgui_vu_scale_str[i], x->x_gui.x_font, x->x_gui.x_fontsize,
- x->x_gui.x_lcol, x, i);
+ i=IEM_VU_STEPS+1;
+ yyy = k4 + k1*(k2-i);
+ sys_vgui(".x%lx.c create text %d %d -text {%s} -anchor w \
+ -font {%s %d bold} -fill #%6.6x -tags %lxSCALE%d\n",
+ canvas, end, yyy+k3, iemgui_vu_scale_str[i], x->x_gui.x_font, x->x_gui.x_fontsize,
+ x->x_gui.x_lcol, x, i);
}
- sys_vgui(".x%x.c create rectangle %d %d %d %d -fill #%6.6x -outline #%6.6x -tags %xRCOVER\n",
- canvas, quad1, ypos-1, quad3-1,
- ypos-1 + k1*IEM_VU_STEPS, x->x_gui.x_bcol, x->x_gui.x_bcol, x);
- sys_vgui(".x%x.c create line %d %d %d %d -width %d -fill #%6.6x -tags %xPLED\n",
- canvas, mid, ypos+10,
- mid, ypos+10, x->x_led_size, x->x_gui.x_bcol, x);
- sys_vgui(".x%x.c create text %d %d -text {%s} -anchor w \
- -font {%s %d bold} -fill #%6.6x -tags %xLABEL\n",
- canvas, xpos+x->x_gui.x_ldx, ypos+x->x_gui.x_ldy,
- strcmp(x->x_gui.x_lab->s_name, "empty")?x->x_gui.x_lab->s_name:"",
- x->x_gui.x_font, x->x_gui.x_fontsize, x->x_gui.x_lcol, x);
+ sys_vgui(".x%lx.c create rectangle %d %d %d %d -fill #%6.6x -outline #%6.6x -tags %lxRCOVER\n",
+ canvas, quad1, ypos-1, quad3-1,
+ ypos-1 + k1*IEM_VU_STEPS, x->x_gui.x_bcol, x->x_gui.x_bcol, x);
+ sys_vgui(".x%lx.c create line %d %d %d %d -width %d -fill #%6.6x -tags %lxPLED\n",
+ canvas, mid, ypos+10,
+ mid, ypos+10, x->x_led_size, x->x_gui.x_bcol, x);
+ sys_vgui(".x%lx.c create text %d %d -text {%s} -anchor w \
+ -font {%s %d bold} -fill #%6.6x -tags %lxLABEL\n",
+ canvas, xpos+x->x_gui.x_ldx, ypos+x->x_gui.x_ldy,
+ strcmp(x->x_gui.x_lab->s_name, "empty")?x->x_gui.x_lab->s_name:"",
+ x->x_gui.x_font, x->x_gui.x_fontsize, x->x_gui.x_lcol, x);
if(!x->x_gui.x_fsf.x_snd_able)
{
- sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xOUT%d\n",
- canvas,
- xpos-1, ypos + x->x_gui.x_h+1,
- xpos + IOWIDTH-1, ypos + x->x_gui.x_h+2,
- x, 0);
- sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xOUT%d\n",
- canvas,
- xpos+x->x_gui.x_w+1-IOWIDTH, ypos + x->x_gui.x_h+1,
- xpos+x->x_gui.x_w+1, ypos + x->x_gui.x_h+2,
- x, 1);
+ sys_vgui(".x%lx.c create rectangle %d %d %d %d -tags %lxOUT%d\n",
+ canvas,
+ xpos-1, ypos + x->x_gui.x_h+1,
+ xpos + IOWIDTH-1, ypos + x->x_gui.x_h+2,
+ x, 0);
+ sys_vgui(".x%lx.c create rectangle %d %d %d %d -tags %lxOUT%d\n",
+ canvas,
+ xpos+x->x_gui.x_w+1-IOWIDTH, ypos + x->x_gui.x_h+1,
+ xpos+x->x_gui.x_w+1, ypos + x->x_gui.x_h+2,
+ x, 1);
}
if(!x->x_gui.x_fsf.x_rcv_able)
{
- sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xIN%d\n",
- canvas,
- xpos-1, ypos-2,
- xpos + IOWIDTH-1, ypos-1,
- x, 0);
- sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xIN%d\n",
- canvas,
- xpos+x->x_gui.x_w+1-IOWIDTH, ypos-2,
- xpos+x->x_gui.x_w+1, ypos-1,
- x, 1);
+ sys_vgui(".x%lx.c create rectangle %d %d %d %d -tags %lxIN%d\n",
+ canvas,
+ xpos-1, ypos-2,
+ xpos + IOWIDTH-1, ypos-1,
+ x, 0);
+ sys_vgui(".x%lx.c create rectangle %d %d %d %d -tags %lxIN%d\n",
+ canvas,
+ xpos+x->x_gui.x_w+1-IOWIDTH, ypos-2,
+ xpos+x->x_gui.x_w+1, ypos-1,
+ x, 1);
}
}
@@ -162,55 +162,55 @@ static void vu_draw_move(t_vu *x, t_glist *glist)
int ypos=text_ypix(&x->x_gui.x_obj, glist);
int w4=x->x_gui.x_w/4, quad1=xpos+w4+1;
int quad3=xpos+x->x_gui.x_w-w4,
- end=xpos+x->x_gui.x_w+4;
+ end=xpos+x->x_gui.x_w+4;
int k1=x->x_led_size+1, k2=IEM_VU_STEPS+1, k3=k1/2;
int yyy, i, k4=ypos-k3;
- sys_vgui(".x%x.c coords %xBASE %d %d %d %d\n",
- canvas, x, xpos-1, ypos-2,
- xpos+x->x_gui.x_w+1,ypos+x->x_gui.x_h+2);
+ sys_vgui(".x%lx.c coords %lxBASE %d %d %d %d\n",
+ canvas, x, xpos-1, ypos-2,
+ xpos+x->x_gui.x_w+1,ypos+x->x_gui.x_h+2);
for(i=1; i<=IEM_VU_STEPS; i++)
{
- yyy = k4 + k1*(k2-i);
- sys_vgui(".x%x.c coords %xRLED%d %d %d %d %d\n",
- canvas, x, i, quad1, yyy, quad3, yyy);
- if(((i+2)&3) && (x->x_scale))
- sys_vgui(".x%x.c coords %xSCALE%d %d %d\n",
- canvas, x, i, end, yyy+k3);
+ yyy = k4 + k1*(k2-i);
+ sys_vgui(".x%lx.c coords %lxRLED%d %d %d %d %d\n",
+ canvas, x, i, quad1, yyy, quad3, yyy);
+ if(((i+2)&3) && (x->x_scale))
+ sys_vgui(".x%lx.c coords %lxSCALE%d %d %d\n",
+ canvas, x, i, end, yyy+k3);
}
if(x->x_scale)
{
- i=IEM_VU_STEPS+1;
- yyy = k4 + k1*(k2-i);
- sys_vgui(".x%x.c coords %xSCALE%d %d %d\n",
- canvas, x, i, end, yyy+k3);
+ i=IEM_VU_STEPS+1;
+ yyy = k4 + k1*(k2-i);
+ sys_vgui(".x%lx.c coords %lxSCALE%d %d %d\n",
+ canvas, x, i, end, yyy+k3);
}
vu_update_peak(x, glist);
vu_update_rms(x, glist);
- sys_vgui(".x%x.c coords %xLABEL %d %d\n",
- canvas, x, xpos+x->x_gui.x_ldx,
- ypos+x->x_gui.x_ldy);
+ sys_vgui(".x%lx.c coords %lxLABEL %d %d\n",
+ canvas, x, xpos+x->x_gui.x_ldx,
+ ypos+x->x_gui.x_ldy);
if(!x->x_gui.x_fsf.x_snd_able)
{
- sys_vgui(".x%x.c coords %xOUT%d %d %d %d %d\n",
- canvas, x, 0,
- xpos-1, ypos + x->x_gui.x_h+1,
- xpos + IOWIDTH-1, ypos + x->x_gui.x_h+2);
- sys_vgui(".x%x.c coords %xOUT%d %d %d %d %d\n",
- canvas, x, 1,
- xpos+x->x_gui.x_w+1-IOWIDTH, ypos + x->x_gui.x_h+1,
- xpos+x->x_gui.x_w+1, ypos + x->x_gui.x_h+2);
+ sys_vgui(".x%lx.c coords %lxOUT%d %d %d %d %d\n",
+ canvas, x, 0,
+ xpos-1, ypos + x->x_gui.x_h+1,
+ xpos + IOWIDTH-1, ypos + x->x_gui.x_h+2);
+ sys_vgui(".x%lx.c coords %lxOUT%d %d %d %d %d\n",
+ canvas, x, 1,
+ xpos+x->x_gui.x_w+1-IOWIDTH, ypos + x->x_gui.x_h+1,
+ xpos+x->x_gui.x_w+1, ypos + x->x_gui.x_h+2);
}
if(!x->x_gui.x_fsf.x_rcv_able)
{
- sys_vgui(".x%x.c coords %xIN%d %d %d %d %d\n",
- canvas, x, 0,
- xpos-1, ypos-2,
- xpos + IOWIDTH-1, ypos-1);
- sys_vgui(".x%x.c coords %xIN%d %d %d %d %d\n",
- canvas, x, 1,
- xpos+x->x_gui.x_w+1-IOWIDTH, ypos-2,
- xpos+x->x_gui.x_w+1, ypos-1);
+ sys_vgui(".x%lx.c coords %lxIN%d %d %d %d %d\n",
+ canvas, x, 0,
+ xpos-1, ypos-2,
+ xpos + IOWIDTH-1, ypos-1);
+ sys_vgui(".x%lx.c coords %lxIN%d %d %d %d %d\n",
+ canvas, x, 1,
+ xpos+x->x_gui.x_w+1-IOWIDTH, ypos-2,
+ xpos+x->x_gui.x_w+1, ypos-1);
}
}
@@ -219,30 +219,30 @@ static void vu_draw_erase(t_vu* x,t_glist* glist)
int i;
t_canvas *canvas=glist_getcanvas(glist);
- sys_vgui(".x%x.c delete %xBASE\n", canvas, x);
+ sys_vgui(".x%lx.c delete %lxBASE\n", canvas, x);
for(i=1; i<=IEM_VU_STEPS; i++)
{
- sys_vgui(".x%x.c delete %xRLED%d\n", canvas, x, i);
- if(((i+2)&3) && (x->x_scale))
- sys_vgui(".x%x.c delete %xSCALE%d\n", canvas, x, i);
+ sys_vgui(".x%lx.c delete %lxRLED%d\n", canvas, x, i);
+ if(((i+2)&3) && (x->x_scale))
+ sys_vgui(".x%lx.c delete %lxSCALE%d\n", canvas, x, i);
}
if(x->x_scale)
{
- i=IEM_VU_STEPS+1;
- sys_vgui(".x%x.c delete %xSCALE%d\n", canvas, x, i);
+ i=IEM_VU_STEPS+1;
+ sys_vgui(".x%lx.c delete %lxSCALE%d\n", canvas, x, i);
}
- sys_vgui(".x%x.c delete %xPLED\n", canvas, x);
- sys_vgui(".x%x.c delete %xRCOVER\n", canvas, x);
- sys_vgui(".x%x.c delete %xLABEL\n", canvas, x);
+ sys_vgui(".x%lx.c delete %lxPLED\n", canvas, x);
+ sys_vgui(".x%lx.c delete %lxRCOVER\n", canvas, x);
+ sys_vgui(".x%lx.c delete %lxLABEL\n", canvas, x);
if(!x->x_gui.x_fsf.x_snd_able)
{
- sys_vgui(".x%x.c delete %xOUT%d\n", canvas, x, 0);
- sys_vgui(".x%x.c delete %xOUT%d\n", canvas, x, 1);
+ sys_vgui(".x%lx.c delete %lxOUT%d\n", canvas, x, 0);
+ sys_vgui(".x%lx.c delete %lxOUT%d\n", canvas, x, 1);
}
if(!x->x_gui.x_fsf.x_rcv_able)
{
- sys_vgui(".x%x.c delete %xIN%d\n", canvas, x, 0);
- sys_vgui(".x%x.c delete %xIN%d\n", canvas, x, 1);
+ sys_vgui(".x%lx.c delete %lxIN%d\n", canvas, x, 0);
+ sys_vgui(".x%lx.c delete %lxIN%d\n", canvas, x, 1);
}
}
@@ -251,32 +251,32 @@ static void vu_draw_config(t_vu* x, t_glist* glist)
int i;
t_canvas *canvas=glist_getcanvas(glist);
- sys_vgui(".x%x.c itemconfigure %xBASE -fill #%6.6x\n", canvas, x, x->x_gui.x_bcol);
+ sys_vgui(".x%lx.c itemconfigure %lxBASE -fill #%6.6x\n", canvas, x, x->x_gui.x_bcol);
for(i=1; i<=IEM_VU_STEPS; i++)
{
- sys_vgui(".x%x.c itemconfigure %xRLED%d -width %d\n", canvas, x, i,
- x->x_led_size);
- if(((i+2)&3) && (x->x_scale))
- sys_vgui(".x%x.c itemconfigure %xSCALE%d -text {%s} -font {%s %d bold} -fill #%6.6x\n",
- canvas, x, i, iemgui_vu_scale_str[i], x->x_gui.x_font, x->x_gui.x_fontsize,
- x->x_gui.x_fsf.x_selected?IEM_GUI_COLOR_SELECTED:x->x_gui.x_lcol);
+ sys_vgui(".x%lx.c itemconfigure %lxRLED%d -width %d\n", canvas, x, i,
+ x->x_led_size);
+ if(((i+2)&3) && (x->x_scale))
+ sys_vgui(".x%lx.c itemconfigure %lxSCALE%d -text {%s} -font {%s %d bold} -fill #%6.6x\n",
+ canvas, x, i, iemgui_vu_scale_str[i], x->x_gui.x_font, x->x_gui.x_fontsize,
+ x->x_gui.x_fsf.x_selected?IEM_GUI_COLOR_SELECTED:x->x_gui.x_lcol);
}
if(x->x_scale)
{
- i=IEM_VU_STEPS+1;
- sys_vgui(".x%x.c itemconfigure %xSCALE%d -text {%s} -font {%s %d bold} -fill #%6.6x\n",
- canvas, x, i, iemgui_vu_scale_str[i], x->x_gui.x_font, x->x_gui.x_fontsize,
- x->x_gui.x_fsf.x_selected?IEM_GUI_COLOR_SELECTED:x->x_gui.x_lcol);
+ i=IEM_VU_STEPS+1;
+ sys_vgui(".x%lx.c itemconfigure %lxSCALE%d -text {%s} -font {%s %d bold} -fill #%6.6x\n",
+ canvas, x, i, iemgui_vu_scale_str[i], x->x_gui.x_font, x->x_gui.x_fontsize,
+ x->x_gui.x_fsf.x_selected?IEM_GUI_COLOR_SELECTED:x->x_gui.x_lcol);
}
- sys_vgui(".x%x.c itemconfigure %xLABEL -font {%s %d bold} -fill #%6.6x -text {%s} \n",
- canvas, x, x->x_gui.x_font, x->x_gui.x_fontsize,
- x->x_gui.x_fsf.x_selected?IEM_GUI_COLOR_SELECTED:x->x_gui.x_lcol,
- strcmp(x->x_gui.x_lab->s_name, "empty")?x->x_gui.x_lab->s_name:"");
-
- sys_vgui(".x%x.c itemconfigure %xRCOVER -fill #%6.6x -outline #%6.6x\n", canvas,
- x, x->x_gui.x_bcol, x->x_gui.x_bcol);
- sys_vgui(".x%x.c itemconfigure %xPLED -width %d\n", canvas, x,
- x->x_led_size);
+ sys_vgui(".x%lx.c itemconfigure %lxLABEL -font {%s %d bold} -fill #%6.6x -text {%s} \n",
+ canvas, x, x->x_gui.x_font, x->x_gui.x_fontsize,
+ x->x_gui.x_fsf.x_selected?IEM_GUI_COLOR_SELECTED:x->x_gui.x_lcol,
+ strcmp(x->x_gui.x_lab->s_name, "empty")?x->x_gui.x_lab->s_name:"");
+
+ sys_vgui(".x%lx.c itemconfigure %lxRCOVER -fill #%6.6x -outline #%6.6x\n", canvas,
+ x, x->x_gui.x_bcol, x->x_gui.x_bcol);
+ sys_vgui(".x%lx.c itemconfigure %lxPLED -width %d\n", canvas, x,
+ x->x_led_size);
}
static void vu_draw_io(t_vu* x, t_glist* glist, int old_snd_rcv_flags)
@@ -287,39 +287,39 @@ static void vu_draw_io(t_vu* x, t_glist* glist, int old_snd_rcv_flags)
if((old_snd_rcv_flags & IEM_GUI_OLD_SND_FLAG) && !x->x_gui.x_fsf.x_snd_able)
{
- sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xOUT%d\n",
- canvas,
- xpos-1, ypos + x->x_gui.x_h+1,
- xpos + IOWIDTH-1, ypos + x->x_gui.x_h+2,
- x, 0);
- sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xOUT%d\n",
- canvas,
- xpos+x->x_gui.x_w+1-IOWIDTH, ypos + x->x_gui.x_h+1,
- xpos+x->x_gui.x_w+1, ypos + x->x_gui.x_h+2,
- x, 1);
+ sys_vgui(".x%lx.c create rectangle %d %d %d %d -tags %lxOUT%d\n",
+ canvas,
+ xpos-1, ypos + x->x_gui.x_h+1,
+ xpos + IOWIDTH-1, ypos + x->x_gui.x_h+2,
+ x, 0);
+ sys_vgui(".x%lx.c create rectangle %d %d %d %d -tags %lxOUT%d\n",
+ canvas,
+ xpos+x->x_gui.x_w+1-IOWIDTH, ypos + x->x_gui.x_h+1,
+ xpos+x->x_gui.x_w+1, ypos + x->x_gui.x_h+2,
+ x, 1);
}
if(!(old_snd_rcv_flags & IEM_GUI_OLD_SND_FLAG) && x->x_gui.x_fsf.x_snd_able)
{
- sys_vgui(".x%x.c delete %xOUT%d\n", canvas, x, 0);
- sys_vgui(".x%x.c delete %xOUT%d\n", canvas, x, 1);
+ sys_vgui(".x%lx.c delete %lxOUT%d\n", canvas, x, 0);
+ sys_vgui(".x%lx.c delete %lxOUT%d\n", canvas, x, 1);
}
if((old_snd_rcv_flags & IEM_GUI_OLD_RCV_FLAG) && !x->x_gui.x_fsf.x_rcv_able)
{
- sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xIN%d\n",
- canvas,
- xpos-1, ypos-2,
- xpos + IOWIDTH-1, ypos-1,
- x, 0);
- sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xIN%d\n",
- canvas,
- xpos+x->x_gui.x_w+1-IOWIDTH, ypos-2,
- xpos+x->x_gui.x_w+1, ypos-1,
- x, 1);
+ sys_vgui(".x%lx.c create rectangle %d %d %d %d -tags %lxIN%d\n",
+ canvas,
+ xpos-1, ypos-2,
+ xpos + IOWIDTH-1, ypos-1,
+ x, 0);
+ sys_vgui(".x%lx.c create rectangle %d %d %d %d -tags %lxIN%d\n",
+ canvas,
+ xpos+x->x_gui.x_w+1-IOWIDTH, ypos-2,
+ xpos+x->x_gui.x_w+1, ypos-1,
+ x, 1);
}
if(!(old_snd_rcv_flags & IEM_GUI_OLD_RCV_FLAG) && x->x_gui.x_fsf.x_rcv_able)
{
- sys_vgui(".x%x.c delete %xIN%d\n", canvas, x, 0);
- sys_vgui(".x%x.c delete %xIN%d\n", canvas, x, 1);
+ sys_vgui(".x%lx.c delete %lxIN%d\n", canvas, x, 0);
+ sys_vgui(".x%lx.c delete %lxIN%d\n", canvas, x, 1);
}
}
@@ -330,61 +330,61 @@ static void vu_draw_select(t_vu* x,t_glist* glist)
if(x->x_gui.x_fsf.x_selected)
{
- sys_vgui(".x%x.c itemconfigure %xBASE -outline #%6.6x\n", canvas, x, IEM_GUI_COLOR_SELECTED);
- for(i=1; i<=IEM_VU_STEPS; i++)
- {
- if(((i+2)&3) && (x->x_scale))
- sys_vgui(".x%x.c itemconfigure %xSCALE%d -fill #%6.6x\n",
- canvas, x, i, IEM_GUI_COLOR_SELECTED);
- }
- if(x->x_scale)
- {
- i=IEM_VU_STEPS+1;
- sys_vgui(".x%x.c itemconfigure %xSCALE%d -fill #%6.6x\n",
- canvas, x, i, IEM_GUI_COLOR_SELECTED);
- }
- sys_vgui(".x%x.c itemconfigure %xLABEL -fill #%6.6x\n", canvas, x, IEM_GUI_COLOR_SELECTED);
+ sys_vgui(".x%lx.c itemconfigure %lxBASE -outline #%6.6x\n", canvas, x, IEM_GUI_COLOR_SELECTED);
+ for(i=1; i<=IEM_VU_STEPS; i++)
+ {
+ if(((i+2)&3) && (x->x_scale))
+ sys_vgui(".x%lx.c itemconfigure %lxSCALE%d -fill #%6.6x\n",
+ canvas, x, i, IEM_GUI_COLOR_SELECTED);
+ }
+ if(x->x_scale)
+ {
+ i=IEM_VU_STEPS+1;
+ sys_vgui(".x%lx.c itemconfigure %lxSCALE%d -fill #%6.6x\n",
+ canvas, x, i, IEM_GUI_COLOR_SELECTED);
+ }
+ sys_vgui(".x%lx.c itemconfigure %lxLABEL -fill #%6.6x\n", canvas, x, IEM_GUI_COLOR_SELECTED);
}
else
{
- sys_vgui(".x%x.c itemconfigure %xBASE -outline #%6.6x\n", canvas, x, IEM_GUI_COLOR_NORMAL);
- for(i=1; i<=IEM_VU_STEPS; i++)
- {
- if(((i+2)&3) && (x->x_scale))
- sys_vgui(".x%x.c itemconfigure %xSCALE%d -fill #%6.6x\n",
- canvas, x, i, x->x_gui.x_lcol);
- }
- if(x->x_scale)
- {
- i=IEM_VU_STEPS+1;
- sys_vgui(".x%x.c itemconfigure %xSCALE%d -fill #%6.6x\n",
- canvas, x, i, x->x_gui.x_lcol);
- }
- sys_vgui(".x%x.c itemconfigure %xLABEL -fill #%6.6x\n", canvas, x, x->x_gui.x_lcol);
+ sys_vgui(".x%lx.c itemconfigure %lxBASE -outline #%6.6x\n", canvas, x, IEM_GUI_COLOR_NORMAL);
+ for(i=1; i<=IEM_VU_STEPS; i++)
+ {
+ if(((i+2)&3) && (x->x_scale))
+ sys_vgui(".x%lx.c itemconfigure %lxSCALE%d -fill #%6.6x\n",
+ canvas, x, i, x->x_gui.x_lcol);
+ }
+ if(x->x_scale)
+ {
+ i=IEM_VU_STEPS+1;
+ sys_vgui(".x%lx.c itemconfigure %lxSCALE%d -fill #%6.6x\n",
+ canvas, x, i, x->x_gui.x_lcol);
+ }
+ sys_vgui(".x%lx.c itemconfigure %lxLABEL -fill #%6.6x\n", canvas, x, x->x_gui.x_lcol);
}
}
void vu_draw(t_vu *x, t_glist *glist, int mode)
{
if(mode == IEM_GUI_DRAW_MODE_MOVE)
- vu_draw_move(x, glist);
+ vu_draw_move(x, glist);
else if(mode == IEM_GUI_DRAW_MODE_NEW)
- vu_draw_new(x, glist);
+ vu_draw_new(x, glist);
else if(mode == IEM_GUI_DRAW_MODE_SELECT)
- vu_draw_select(x, glist);
+ vu_draw_select(x, glist);
else if(mode == IEM_GUI_DRAW_MODE_ERASE)
- vu_draw_erase(x, glist);
+ vu_draw_erase(x, glist);
else if(mode == IEM_GUI_DRAW_MODE_CONFIG)
- vu_draw_config(x, glist);
+ vu_draw_config(x, glist);
else if(mode >= IEM_GUI_DRAW_MODE_IO)
- vu_draw_io(x, glist, mode - IEM_GUI_DRAW_MODE_IO);
+ vu_draw_io(x, glist, mode - IEM_GUI_DRAW_MODE_IO);
}
/* ------------------------ vu widgetbehaviour----------------------------- */
static void vu_getrect(t_gobj *z, t_glist *glist,
- int *xp1, int *yp1, int *xp2, int *yp2)
+ int *xp1, int *yp1, int *xp2, int *yp2)
{
t_vu* x = (t_vu*)z;
@@ -402,13 +402,13 @@ static void vu_save(t_gobj *z, t_binbuf *b)
iemgui_save(&x->x_gui, srl, bflcol);
binbuf_addv(b, "ssiisiissiiiiiiii", gensym("#X"),gensym("obj"),
- (t_int)x->x_gui.x_obj.te_xpix, (t_int)x->x_gui.x_obj.te_ypix,
- gensym("vu"), x->x_gui.x_w, x->x_gui.x_h,
- srl[1], srl[2],
- x->x_gui.x_ldx, x->x_gui.x_ldy,
- iem_fstyletoint(&x->x_gui.x_fsf), x->x_gui.x_fontsize,
- bflcol[0], bflcol[2], x->x_scale,
- iem_symargstoint(&x->x_gui.x_isa));
+ (int)x->x_gui.x_obj.te_xpix, (int)x->x_gui.x_obj.te_ypix,
+ gensym("vu"), x->x_gui.x_w, x->x_gui.x_h,
+ srl[1], srl[2],
+ x->x_gui.x_ldx, x->x_gui.x_ldy,
+ iem_fstyletoint(&x->x_gui.x_fsf), x->x_gui.x_fontsize,
+ bflcol[0], bflcol[2], x->x_scale,
+ iem_symargstoint(&x->x_gui.x_isa));
binbuf_addv(b, ";");
}
@@ -418,7 +418,7 @@ void vu_check_height(t_vu *x, int h)
n = h / IEM_VU_STEPS;
if(n < IEM_VU_MINSIZE)
- n = IEM_VU_MINSIZE;
+ n = IEM_VU_MINSIZE;
x->x_led_size = n-1;
x->x_gui.x_h = IEM_VU_STEPS * n;
}
@@ -430,46 +430,46 @@ static void vu_scale(t_vu *x, t_floatarg fscale)
if(scale != 0) scale = 1;
if(x->x_scale && !scale)
{
- t_canvas *canvas=glist_getcanvas(x->x_gui.x_glist);
-
- x->x_scale = (int)scale;
- if(glist_isvisible(x->x_gui.x_glist))
- {
- for(i=1; i<=IEM_VU_STEPS; i++)
- {
- if((i+2)&3)
- sys_vgui(".x%x.c delete %xSCALE%d\n", canvas, x, i);
- }
- i=IEM_VU_STEPS+1;
- sys_vgui(".x%x.c delete %xSCALE%d\n", canvas, x, i);
- }
+ t_canvas *canvas=glist_getcanvas(x->x_gui.x_glist);
+
+ x->x_scale = (int)scale;
+ if(glist_isvisible(x->x_gui.x_glist))
+ {
+ for(i=1; i<=IEM_VU_STEPS; i++)
+ {
+ if((i+2)&3)
+ sys_vgui(".x%lx.c delete %lxSCALE%d\n", canvas, x, i);
+ }
+ i=IEM_VU_STEPS+1;
+ sys_vgui(".x%lx.c delete %lxSCALE%d\n", canvas, x, i);
+ }
}
if(!x->x_scale && scale)
{
- int w4=x->x_gui.x_w/4, end=text_xpix(&x->x_gui.x_obj, x->x_gui.x_glist)+x->x_gui.x_w+4;
- int k1=x->x_led_size+1, k2=IEM_VU_STEPS+1, k3=k1/2;
- int yyy, k4=text_ypix(&x->x_gui.x_obj, x->x_gui.x_glist)-k3;
- t_canvas *canvas=glist_getcanvas(x->x_gui.x_glist);
-
- x->x_scale = (int)scale;
- if(glist_isvisible(x->x_gui.x_glist))
- {
- for(i=1; i<=IEM_VU_STEPS; i++)
- {
- yyy = k4 + k1*(k2-i);
- if((i+2)&3)
- sys_vgui(".x%x.c create text %d %d -text {%s} -anchor w \
- -font {%s %d bold} -fill #%6.6x -tags %xSCALE%d\n",
- canvas, end, yyy+k3, iemgui_vu_scale_str[i], x->x_gui.x_font, x->x_gui.x_fontsize,
- x->x_gui.x_lcol, x, i);
- }
- i=IEM_VU_STEPS+1;
- yyy = k4 + k1*(k2-i);
- sys_vgui(".x%x.c create text %d %d -text {%s} -anchor w \
- -font {%s %d bold} -fill #%6.6x -tags %xSCALE%d\n",
- canvas, end, yyy+k3, iemgui_vu_scale_str[i], x->x_gui.x_font, x->x_gui.x_fontsize,
- x->x_gui.x_lcol, x, i);
- }
+ int w4=x->x_gui.x_w/4, end=text_xpix(&x->x_gui.x_obj, x->x_gui.x_glist)+x->x_gui.x_w+4;
+ int k1=x->x_led_size+1, k2=IEM_VU_STEPS+1, k3=k1/2;
+ int yyy, k4=text_ypix(&x->x_gui.x_obj, x->x_gui.x_glist)-k3;
+ t_canvas *canvas=glist_getcanvas(x->x_gui.x_glist);
+
+ x->x_scale = (int)scale;
+ if(glist_isvisible(x->x_gui.x_glist))
+ {
+ for(i=1; i<=IEM_VU_STEPS; i++)
+ {
+ yyy = k4 + k1*(k2-i);
+ if((i+2)&3)
+ sys_vgui(".x%lx.c create text %d %d -text {%s} -anchor w \
+ -font {%s %d bold} -fill #%6.6x -tags %lxSCALE%d\n",
+ canvas, end, yyy+k3, iemgui_vu_scale_str[i], x->x_gui.x_font, x->x_gui.x_fontsize,
+ x->x_gui.x_lcol, x, i);
+ }
+ i=IEM_VU_STEPS+1;
+ yyy = k4 + k1*(k2-i);
+ sys_vgui(".x%lx.c create text %d %d -text {%s} -anchor w \
+ -font {%s %d bold} -fill #%6.6x -tags %lxSCALE%d\n",
+ canvas, end, yyy+k3, iemgui_vu_scale_str[i], x->x_gui.x_font, x->x_gui.x_fontsize,
+ x->x_gui.x_lcol, x, i);
+ }
}
}
@@ -481,20 +481,20 @@ static void vu_properties(t_gobj *z, t_glist *owner)
iemgui_properties(&x->x_gui, srl);
sprintf(buf, "pdtk_iemgui_dialog %%s VU-METER \
- --------dimensions(pix)(pix):-------- %d %d width: %d %d height: \
- empty 0.0 empty 0.0 empty %d \
- %d no_scale scale %d %d empty %d \
- %s %s \
- %s %d %d \
- %d %d \
- %d %d %d\n",
- x->x_gui.x_w, IEM_GUI_MINSIZE, x->x_gui.x_h, IEM_VU_STEPS*IEM_VU_MINSIZE,
- 0,/*no_schedule*/
- x->x_scale, -1, -1, -1,/*no linlog, no init, no multi*/
- "nosndno", srl[1]->s_name,/*no send*/
- srl[2]->s_name, x->x_gui.x_ldx, x->x_gui.x_ldy,
- x->x_gui.x_fsf.x_font_style, x->x_gui.x_fontsize,
- 0xffffff & x->x_gui.x_bcol, -1/*no front-color*/, 0xffffff & x->x_gui.x_lcol);
+ --------dimensions(pix)(pix):-------- %d %d width: %d %d height: \
+ empty 0.0 empty 0.0 empty %d \
+ %d no_scale scale %d %d empty %d \
+ %s %s \
+ %s %d %d \
+ %d %d \
+ %d %d %d\n",
+ x->x_gui.x_w, IEM_GUI_MINSIZE, x->x_gui.x_h, IEM_VU_STEPS*IEM_VU_MINSIZE,
+ 0,/*no_schedule*/
+ x->x_scale, -1, -1, -1,/*no linlog, no init, no multi*/
+ "nosndno", srl[1]->s_name,/*no send*/
+ srl[2]->s_name, x->x_gui.x_ldx, x->x_gui.x_ldy,
+ x->x_gui.x_fsf.x_font_style, x->x_gui.x_fontsize,
+ 0xffffff & x->x_gui.x_bcol, -1/*no front-color*/, 0xffffff & x->x_gui.x_lcol);
gfxstub_new(&x->x_gui.x_obj.ob_pd, x, buf);
}
@@ -513,7 +513,7 @@ static void vu_dialog(t_vu *x, t_symbol *s, int argc, t_atom *argv)
x->x_gui.x_w = iemgui_clip_size(w);
vu_check_height(x, h);
if(scale != 0)
- scale = 1;
+ scale = 1;
vu_scale(x, (float)scale);
(*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_CONFIG);
(*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_IO + sr_flags);
@@ -528,9 +528,9 @@ static void vu_size(t_vu *x, t_symbol *s, int ac, t_atom *av)
vu_check_height(x, (int)atom_getintarg(1, ac, av));
if(glist_isvisible(x->x_gui.x_glist))
{
- (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_MOVE);
- (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_CONFIG);
- canvas_fixlinesfor(glist_getcanvas(x->x_gui.x_glist), (t_text*)x);
+ (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_MOVE);
+ (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_CONFIG);
+ canvas_fixlinesfor(glist_getcanvas(x->x_gui.x_glist), (t_text*)x);
}
}
@@ -560,13 +560,13 @@ static void vu_float(t_vu *x, t_floatarg rms)
int i;
if(rms <= IEM_VU_MINDB)
- x->x_rms = 0;
+ x->x_rms = 0;
else if(rms >= IEM_VU_MAXDB)
- x->x_rms = IEM_VU_STEPS;
+ x->x_rms = IEM_VU_STEPS;
else
{
- int i = (int)(2.0*(rms + IEM_VU_OFFSET));
- x->x_rms = iemgui_vu_db2i[i];
+ int i = (int)(2.0*(rms + IEM_VU_OFFSET));
+ x->x_rms = iemgui_vu_db2i[i];
}
i = (int)(100.0*rms + 10000.5);
rms = 0.01*(float)(i - 10000);
@@ -580,13 +580,13 @@ static void vu_ft1(t_vu *x, t_floatarg peak)
int i;
if(peak <= IEM_VU_MINDB)
- x->x_peak = 0;
+ x->x_peak = 0;
else if(peak >= IEM_VU_MAXDB)
- x->x_peak = IEM_VU_STEPS;
+ x->x_peak = IEM_VU_STEPS;
else
{
- int i = (int)(2.0*(peak + IEM_VU_OFFSET));
- x->x_peak = iemgui_vu_db2i[i];
+ int i = (int)(2.0*(peak + IEM_VU_OFFSET));
+ x->x_peak = iemgui_vu_db2i[i];
}
i = (int)(100.0*peak + 10000.5);
peak = 0.01*(float)(i - 10000);
@@ -622,46 +622,46 @@ static void *vu_new(t_symbol *s, int argc, t_atom *argv)
&&IS_A_FLOAT(argv,6)&&IS_A_FLOAT(argv,7)
&&IS_A_FLOAT(argv,8)&&IS_A_FLOAT(argv,9)&&IS_A_FLOAT(argv,10))
{
- w = (int)atom_getintarg(0, argc, argv);
- h = (int)atom_getintarg(1, argc, argv);
- iemgui_new_getnames(&x->x_gui, 1, argv);
- ldx = (int)atom_getintarg(4, argc, argv);
- ldy = (int)atom_getintarg(5, argc, argv);
- iem_inttofstyle(&x->x_gui.x_fsf, atom_getintarg(6, argc, argv));
- fs = (int)atom_getintarg(7, argc, argv);
- bflcol[0] = (int)atom_getintarg(8, argc, argv);
- bflcol[2] = (int)atom_getintarg(9, argc, argv);
- scale = (int)atom_getintarg(10, argc, argv);
+ w = (int)atom_getintarg(0, argc, argv);
+ h = (int)atom_getintarg(1, argc, argv);
+ iemgui_new_getnames(&x->x_gui, 1, argv);
+ ldx = (int)atom_getintarg(4, argc, argv);
+ ldy = (int)atom_getintarg(5, argc, argv);
+ iem_inttofstyle(&x->x_gui.x_fsf, atom_getintarg(6, argc, argv));
+ fs = (int)atom_getintarg(7, argc, argv);
+ bflcol[0] = (int)atom_getintarg(8, argc, argv);
+ bflcol[2] = (int)atom_getintarg(9, argc, argv);
+ scale = (int)atom_getintarg(10, argc, argv);
}
else iemgui_new_getnames(&x->x_gui, 1, 0);
if((argc == 12)&&IS_A_FLOAT(argv,11))
- iem_inttosymargs(&x->x_gui.x_isa, atom_getintarg(11, argc, argv));
+ iem_inttosymargs(&x->x_gui.x_isa, atom_getintarg(11, argc, argv));
x->x_gui.x_draw = (t_iemfunptr)vu_draw;
x->x_gui.x_fsf.x_snd_able = 0;
x->x_gui.x_fsf.x_rcv_able = 1;
x->x_gui.x_glist = (t_glist *)canvas_getcurrent();
if (!strcmp(x->x_gui.x_rcv->s_name, "empty"))
- x->x_gui.x_fsf.x_rcv_able = 0;
+ x->x_gui.x_fsf.x_rcv_able = 0;
if (x->x_gui.x_fsf.x_font_style == 1)
- strcpy(x->x_gui.x_font, "helvetica");
+ strcpy(x->x_gui.x_font, "helvetica");
else if(x->x_gui.x_fsf.x_font_style == 2)
- strcpy(x->x_gui.x_font, "times");
+ strcpy(x->x_gui.x_font, "times");
else { x->x_gui.x_fsf.x_font_style = 0;
- strcpy(x->x_gui.x_font, "courier"); }
+ strcpy(x->x_gui.x_font, "courier"); }
if(x->x_gui.x_fsf.x_rcv_able)
- pd_bind(&x->x_gui.x_obj.ob_pd, x->x_gui.x_rcv);
+ pd_bind(&x->x_gui.x_obj.ob_pd, x->x_gui.x_rcv);
x->x_gui.x_ldx = ldx;
x->x_gui.x_ldy = ldy;
if(fs < 4)
- fs = 4;
+ fs = 4;
x->x_gui.x_fontsize = fs;
x->x_gui.x_w = iemgui_clip_size(w);
vu_check_height(x, h);
iemgui_all_colfromload(&x->x_gui, bflcol);
if(scale != 0)
- scale = 1;
+ scale = 1;
x->x_scale = scale;
x->x_peak = 0;
x->x_rms = 0;
@@ -677,19 +677,19 @@ static void *vu_new(t_symbol *s, int argc, t_atom *argv)
static void vu_free(t_vu *x)
{
if(x->x_gui.x_fsf.x_rcv_able)
- pd_unbind(&x->x_gui.x_obj.ob_pd, x->x_gui.x_rcv);
+ pd_unbind(&x->x_gui.x_obj.ob_pd, x->x_gui.x_rcv);
gfxstub_deleteforkey(x);
}
void g_vumeter_setup(void)
{
vu_class = class_new(gensym("vu"), (t_newmethod)vu_new, (t_method)vu_free,
- sizeof(t_vu), 0, A_GIMME, 0);
+ sizeof(t_vu), 0, A_GIMME, 0);
class_addbang(vu_class,vu_bang);
class_addfloat(vu_class,vu_float);
class_addmethod(vu_class, (t_method)vu_ft1, gensym("ft1"), A_FLOAT, 0);
class_addmethod(vu_class, (t_method)vu_dialog, gensym("dialog"),
- A_GIMME, 0);
+ A_GIMME, 0);
class_addmethod(vu_class, (t_method)vu_size, gensym("size"), A_GIMME, 0);
class_addmethod(vu_class, (t_method)vu_scale, gensym("scale"), A_DEFFLOAT, 0);
class_addmethod(vu_class, (t_method)vu_delta, gensym("delta"), A_GIMME, 0);
diff --git a/pd/src/m_atom.c b/pd/src/m_atom.c
index 7e30c82f..8ba13131 100644
--- a/pd/src/m_atom.c
+++ b/pd/src/m_atom.c
@@ -7,8 +7,8 @@
#include <string.h>
/* convenience routines for checking and getting values of
- atoms. There's no "pointer" version since there's nothing
- safe to return if there's an error. */
+ atoms. There's no "pointer" version since there's nothing
+ safe to return if there's an error. */
t_float atom_getfloat(t_atom *a)
{
@@ -33,7 +33,7 @@ t_symbol *atom_gensym(t_atom *a) /* this works better for graph labels */
char buf[30];
if (a->a_type == A_SYMBOL) return (a->a_w.w_symbol);
else if (a->a_type == A_FLOAT)
- sprintf(buf, "%g", a->a_w.w_float);
+ sprintf(buf, "%g", a->a_w.w_float);
else strcpy(buf, "???");
return (gensym(buf));
}
@@ -73,57 +73,57 @@ void atom_string(t_atom *a, char *buf, unsigned int bufsize)
case A_SEMI: strcpy(buf, ";"); break;
case A_COMMA: strcpy(buf, ","); break;
case A_POINTER:
- strcpy(buf, "(pointer)");
- break;
+ strcpy(buf, "(pointer)");
+ break;
case A_FLOAT:
- sprintf(tbuf, "%g", a->a_w.w_float);
- if (strlen(tbuf) < bufsize-1) strcpy(buf, tbuf);
- else if (a->a_w.w_float < 0) strcpy(buf, "-");
- else strcat(buf, "+");
- break;
+ sprintf(tbuf, "%g", a->a_w.w_float);
+ if (strlen(tbuf) < bufsize-1) strcpy(buf, tbuf);
+ else if (a->a_w.w_float < 0) strcpy(buf, "-");
+ else strcat(buf, "+");
+ break;
case A_SYMBOL:
{
- char *sp;
- unsigned int len;
- int quote;
- for (sp = a->a_w.w_symbol->s_name, len = 0, quote = 0; *sp; sp++, len++)
- if (*sp == ';' || *sp == ',' || *sp == '\\' ||
- (*sp == '$' && sp == a->a_w.w_symbol->s_name && sp[1] >= '0'
- && sp[1] <= '9'))
- quote = 1;
- if (quote)
- {
- char *bp = buf, *ep = buf + (bufsize-2);
- sp = a->a_w.w_symbol->s_name;
- while (bp < ep && *sp)
- {
- if (*sp == ';' || *sp == ',' || *sp == '\\' ||
- (*sp == '$' && bp == buf && sp[1] >= '0' && sp[1] <= '9'))
- *bp++ = '\\';
- *bp++ = *sp++;
- }
- if (*sp) *bp++ = '*';
- *bp = 0;
- /* post("quote %s -> %s", a->a_w.w_symbol->s_name, buf); */
- }
- else
- {
- if (len < bufsize-1) strcpy(buf, a->a_w.w_symbol->s_name);
- else
- {
- strncpy(buf, a->a_w.w_symbol->s_name, bufsize - 2);
- strcpy(buf + (bufsize - 2), "*");
- }
- }
+ char *sp;
+ unsigned int len;
+ int quote;
+ for (sp = a->a_w.w_symbol->s_name, len = 0, quote = 0; *sp; sp++, len++)
+ if (*sp == ';' || *sp == ',' || *sp == '\\' ||
+ (*sp == '$' && sp == a->a_w.w_symbol->s_name && sp[1] >= '0'
+ && sp[1] <= '9'))
+ quote = 1;
+ if (quote)
+ {
+ char *bp = buf, *ep = buf + (bufsize-2);
+ sp = a->a_w.w_symbol->s_name;
+ while (bp < ep && *sp)
+ {
+ if (*sp == ';' || *sp == ',' || *sp == '\\' ||
+ (*sp == '$' && bp == buf && sp[1] >= '0' && sp[1] <= '9'))
+ *bp++ = '\\';
+ *bp++ = *sp++;
+ }
+ if (*sp) *bp++ = '*';
+ *bp = 0;
+ /* post("quote %s -> %s", a->a_w.w_symbol->s_name, buf); */
+ }
+ else
+ {
+ if (len < bufsize-1) strcpy(buf, a->a_w.w_symbol->s_name);
+ else
+ {
+ strncpy(buf, a->a_w.w_symbol->s_name, bufsize - 2);
+ strcpy(buf + (bufsize - 2), "*");
+ }
+ }
}
- break;
+ break;
case A_DOLLAR:
- sprintf(buf, "$%d", a->a_w.w_index);
- break;
+ sprintf(buf, "$%d", a->a_w.w_index);
+ break;
case A_DOLLSYM:
- sprintf(buf, "$%s", a->a_w.w_symbol->s_name);
- break;
+ sprintf(buf, "$%s", a->a_w.w_symbol->s_name);
+ break;
default:
- bug("atom_string");
+ bug("atom_string");
}
}
diff --git a/pd/src/m_binbuf.c b/pd/src/m_binbuf.c
index 1936b2fa..fa8864b4 100644
--- a/pd/src/m_binbuf.c
+++ b/pd/src/m_binbuf.c
@@ -12,8 +12,9 @@
#include <stdlib.h>
#include "m_pd.h"
+#include "s_stuff.h"
#include <stdio.h>
-#ifdef UNIX
+#ifdef UNISTD
#include <unistd.h>
#endif
#ifdef MSW
@@ -71,125 +72,125 @@ void binbuf_text(t_binbuf *x, char *text, size_t size)
x->b_n = 0;
while (1)
{
- int type;
- /* skip leading space */
- while ((textp != etext) && (*textp == ' ' || *textp == '\n'
- || *textp == '\r' || *textp == '\t')) textp++;
- if (textp == etext) break;
- if (*textp == ';') SETSEMI(ap), textp++;
- else if (*textp == ',') SETCOMMA(ap), textp++;
- else
- {
- /* it's an atom other than a comma or semi */
- char c;
- int floatstate = 0, slash = 0, lastslash = 0,
- firstslash = (*textp == '\\');
- bufp = buf;
- do
- {
- c = *bufp = *textp++;
- lastslash = slash;
- slash = (c == '\\');
+ int type;
+ /* skip leading space */
+ while ((textp != etext) && (*textp == ' ' || *textp == '\n'
+ || *textp == '\r' || *textp == '\t')) textp++;
+ if (textp == etext) break;
+ if (*textp == ';') SETSEMI(ap), textp++;
+ else if (*textp == ',') SETCOMMA(ap), textp++;
+ else
+ {
+ /* it's an atom other than a comma or semi */
+ char c;
+ int floatstate = 0, slash = 0, lastslash = 0,
+ firstslash = (*textp == '\\');
+ bufp = buf;
+ do
+ {
+ c = *bufp = *textp++;
+ lastslash = slash;
+ slash = (c == '\\');
- if (floatstate >= 0)
- {
- int digit = (c >= '0' && c <= '9'),
- dot = (c == '.'), minus = (c == '-'),
- plusminus = (minus || (c == '+')),
- expon = (c == 'e' || c == 'E');
- if (floatstate == 0) /* beginning */
- {
- if (minus) floatstate = 1;
- else if (digit) floatstate = 2;
- else if (dot) floatstate = 3;
- else floatstate = -1;
- }
- else if (floatstate == 1) /* got minus */
- {
- if (digit) floatstate = 2;
- else if (dot) floatstate = 3;
- else floatstate = -1;
- }
- else if (floatstate == 2) /* got digits */
- {
- if (dot) floatstate = 4;
- else if (expon) floatstate = 6;
- else if (!digit) floatstate = -1;
- }
- else if (floatstate == 3) /* got '.' without digits */
- {
- if (digit) floatstate = 5;
- else floatstate = -1;
- }
- else if (floatstate == 4) /* got '.' after digits */
- {
- if (digit) floatstate = 5;
- else if (expon) floatstate = 6;
- else floatstate = -1;
- }
- else if (floatstate == 5) /* got digits after . */
- {
- if (expon) floatstate = 6;
- else if (!digit) floatstate = -1;
- }
- else if (floatstate == 6) /* got 'e' */
- {
- if (plusminus) floatstate = 7;
- else if (digit) floatstate = 8;
- else floatstate = -1;
- }
- else if (floatstate == 7) /* got plus or minus */
- {
- if (digit) floatstate = 8;
- else floatstate = -1;
- }
- else if (floatstate == 8) /* got digits */
- {
- if (!digit) floatstate = -1;
- }
- }
- if (!slash) bufp++;
- }
- while (textp != etext && bufp != ebuf &&
- (slash || (*textp != ' ' && *textp != '\n' && *textp != '\r'
- && *textp != '\t' &&*textp != ',' && *textp != ';')));
- *bufp = 0;
+ if (floatstate >= 0)
+ {
+ int digit = (c >= '0' && c <= '9'),
+ dot = (c == '.'), minus = (c == '-'),
+ plusminus = (minus || (c == '+')),
+ expon = (c == 'e' || c == 'E');
+ if (floatstate == 0) /* beginning */
+ {
+ if (minus) floatstate = 1;
+ else if (digit) floatstate = 2;
+ else if (dot) floatstate = 3;
+ else floatstate = -1;
+ }
+ else if (floatstate == 1) /* got minus */
+ {
+ if (digit) floatstate = 2;
+ else if (dot) floatstate = 3;
+ else floatstate = -1;
+ }
+ else if (floatstate == 2) /* got digits */
+ {
+ if (dot) floatstate = 4;
+ else if (expon) floatstate = 6;
+ else if (!digit) floatstate = -1;
+ }
+ else if (floatstate == 3) /* got '.' without digits */
+ {
+ if (digit) floatstate = 5;
+ else floatstate = -1;
+ }
+ else if (floatstate == 4) /* got '.' after digits */
+ {
+ if (digit) floatstate = 5;
+ else if (expon) floatstate = 6;
+ else floatstate = -1;
+ }
+ else if (floatstate == 5) /* got digits after . */
+ {
+ if (expon) floatstate = 6;
+ else if (!digit) floatstate = -1;
+ }
+ else if (floatstate == 6) /* got 'e' */
+ {
+ if (plusminus) floatstate = 7;
+ else if (digit) floatstate = 8;
+ else floatstate = -1;
+ }
+ else if (floatstate == 7) /* got plus or minus */
+ {
+ if (digit) floatstate = 8;
+ else floatstate = -1;
+ }
+ else if (floatstate == 8) /* got digits */
+ {
+ if (!digit) floatstate = -1;
+ }
+ }
+ if (!slash) bufp++;
+ }
+ while (textp != etext && bufp != ebuf &&
+ (slash || (*textp != ' ' && *textp != '\n' && *textp != '\r'
+ && *textp != '\t' &&*textp != ',' && *textp != ';')));
+ *bufp = 0;
#if 0
- post("buf %s", buf);
+ post("buf %s", buf);
#endif
- if (*buf == '$' && buf[1] >= '0' && buf[1] <= '9' && !firstslash)
- {
- for (bufp = buf+2; *bufp; bufp++)
- if (*bufp < '0' || *bufp > '9')
- {
- SETDOLLSYM(ap, gensym(buf+1));
- goto didit;
- }
- SETDOLLAR(ap, atoi(buf+1));
- didit: ;
- }
- else
- {
- if (floatstate == 2 || floatstate == 4 || floatstate == 5 ||
- floatstate == 8)
- SETFLOAT(ap, atof(buf));
- else SETSYMBOL(ap, gensym(buf));
- }
- }
- ap++;
- natom++;
- if (natom == nalloc)
- {
- x->b_vec = t_resizebytes(x->b_vec, nalloc * sizeof(*x->b_vec),
- nalloc * (2*sizeof(*x->b_vec)));
- nalloc = nalloc * 2;
- ap = x->b_vec + natom;
- }
- if (textp == etext) break;
+ if (*buf == '$' && buf[1] >= '0' && buf[1] <= '9' && !firstslash)
+ {
+ for (bufp = buf+2; *bufp; bufp++)
+ if (*bufp < '0' || *bufp > '9')
+ {
+ SETDOLLSYM(ap, gensym(buf+1));
+ goto didit;
+ }
+ SETDOLLAR(ap, atoi(buf+1));
+ didit: ;
+ }
+ else
+ {
+ if (floatstate == 2 || floatstate == 4 || floatstate == 5 ||
+ floatstate == 8)
+ SETFLOAT(ap, atof(buf));
+ else SETSYMBOL(ap, gensym(buf));
+ }
+ }
+ ap++;
+ natom++;
+ if (natom == nalloc)
+ {
+ x->b_vec = t_resizebytes(x->b_vec, nalloc * sizeof(*x->b_vec),
+ nalloc * (2*sizeof(*x->b_vec)));
+ nalloc = nalloc * 2;
+ ap = x->b_vec + natom;
+ }
+ if (textp == etext) break;
}
/* reallocate the vector to exactly the right size */
x->b_vec = t_resizebytes(x->b_vec, nalloc * sizeof(*x->b_vec),
- natom * sizeof(*x->b_vec));
+ natom * sizeof(*x->b_vec));
x->b_n = natom;
}
@@ -204,25 +205,25 @@ void binbuf_gettext(t_binbuf *x, char **bufp, int *lengthp)
for (ap = x->b_vec, indx = x->b_n; indx--; ap++)
{
- int newlength;
- if ((ap->a_type == A_SEMI || ap->a_type == A_COMMA) &&
- length && buf[length-1] == ' ') length--;
- atom_string(ap, string, MAXPDSTRING);
- newlength = length + strlen(string) + 1;
- if (!(newbuf = resizebytes(buf, length, newlength))) break;
- buf = newbuf;
- strcpy(buf + length, string);
- length = newlength;
- if (ap->a_type == A_SEMI) buf[length-1] = '\n';
- else buf[length-1] = ' ';
+ int newlength;
+ if ((ap->a_type == A_SEMI || ap->a_type == A_COMMA) &&
+ length && buf[length-1] == ' ') length--;
+ atom_string(ap, string, MAXPDSTRING);
+ newlength = length + strlen(string) + 1;
+ if (!(newbuf = resizebytes(buf, length, newlength))) break;
+ buf = newbuf;
+ strcpy(buf + length, string);
+ length = newlength;
+ if (ap->a_type == A_SEMI) buf[length-1] = '\n';
+ else buf[length-1] = ' ';
}
if (length && buf[length-1] == ' ')
{
- if (newbuf = t_resizebytes(buf, length, length-1))
- {
- buf = newbuf;
- length--;
- }
+ if (newbuf = t_resizebytes(buf, length, length-1))
+ {
+ buf = newbuf;
+ length--;
+ }
}
*bufp = buf;
*lengthp = length;
@@ -236,12 +237,12 @@ void binbuf_add(t_binbuf *x, int argc, t_atom *argv)
int newsize = x->b_n + argc, i;
t_atom *ap;
if (ap = t_resizebytes(x->b_vec, x->b_n * sizeof(*x->b_vec),
- newsize * sizeof(*x->b_vec)))
- x->b_vec = ap;
+ newsize * sizeof(*x->b_vec)))
+ x->b_vec = ap;
else
{
- error("binbuf_addmessage: out of space");
- return;
+ error("binbuf_addmessage: out of space");
+ return;
}
#if 0
startpost("binbuf_add: ");
@@ -249,7 +250,7 @@ void binbuf_add(t_binbuf *x, int argc, t_atom *argv)
endpost();
#endif
for (ap = x->b_vec + x->b_n, i = argc; i--; ap++)
- *ap = *(argv++);
+ *ap = *(argv++);
x->b_n = newsize;
}
@@ -264,22 +265,22 @@ void binbuf_addv(t_binbuf *x, char *fmt, ...)
va_start(ap, fmt);
while (1)
{
- if (nargs >= MAXADDMESSV)
- {
- error("binbuf_addmessv: only %d allowed", MAXADDMESSV);
- break;
- }
- switch(*fp++)
- {
- case 'i': SETFLOAT(at, va_arg(ap, t_int)); break;
- case 'f': SETFLOAT(at, va_arg(ap, double)); break;
- case 's': SETSYMBOL(at, va_arg(ap, t_symbol *)); break;
- case ';': SETSEMI(at); break;
- case ',': SETCOMMA(at); break;
- default: goto done;
- }
- at++;
- nargs++;
+ if (nargs >= MAXADDMESSV)
+ {
+ error("binbuf_addmessv: only %d allowed", MAXADDMESSV);
+ break;
+ }
+ switch(*fp++)
+ {
+ case 'i': SETFLOAT(at, va_arg(ap, int)); break;
+ case 'f': SETFLOAT(at, va_arg(ap, double)); break;
+ case 's': SETSYMBOL(at, va_arg(ap, t_symbol *)); break;
+ case ';': SETSEMI(at); break;
+ case ',': SETCOMMA(at); break;
+ default: goto done;
+ }
+ at++;
+ nargs++;
}
done:
va_end(ap);
@@ -297,35 +298,35 @@ void binbuf_addbinbuf(t_binbuf *x, t_binbuf *y)
binbuf_add(z, y->b_n, y->b_vec);
for (i = 0, ap = z->b_vec; i < z->b_n; i++, ap++)
{
- char tbuf[MAXPDSTRING];
- switch (ap->a_type)
- {
- case A_FLOAT:
- break;
- case A_SEMI:
- SETSYMBOL(ap, gensym(";"));
- break;
- case A_COMMA:
- SETSYMBOL(ap, gensym(","));
- break;
- case A_DOLLAR:
- sprintf(tbuf, "$%d", ap->a_w.w_index);
- SETSYMBOL(ap, gensym(tbuf));
- break;
- case A_DOLLSYM:
- sprintf(tbuf, "$%s", ap->a_w.w_symbol->s_name);
- SETSYMBOL(ap, gensym(tbuf));
- break;
- case A_SYMBOL:
- /* FIXME make this general */
- if (!strcmp(ap->a_w.w_symbol->s_name, ";"))
- SETSYMBOL(ap, gensym(";"));
- else if (!strcmp(ap->a_w.w_symbol->s_name, ","))
- SETSYMBOL(ap, gensym(","));
- break;
- default:
- bug("binbuf_addbinbuf");
- }
+ char tbuf[MAXPDSTRING];
+ switch (ap->a_type)
+ {
+ case A_FLOAT:
+ break;
+ case A_SEMI:
+ SETSYMBOL(ap, gensym(";"));
+ break;
+ case A_COMMA:
+ SETSYMBOL(ap, gensym(","));
+ break;
+ case A_DOLLAR:
+ sprintf(tbuf, "$%d", ap->a_w.w_index);
+ SETSYMBOL(ap, gensym(tbuf));
+ break;
+ case A_DOLLSYM:
+ sprintf(tbuf, "$%s", ap->a_w.w_symbol->s_name);
+ SETSYMBOL(ap, gensym(tbuf));
+ break;
+ case A_SYMBOL:
+ /* FIXME make this general */
+ if (!strcmp(ap->a_w.w_symbol->s_name, ";"))
+ SETSYMBOL(ap, gensym(";"));
+ else if (!strcmp(ap->a_w.w_symbol->s_name, ","))
+ SETSYMBOL(ap, gensym(","));
+ break;
+ default:
+ bug("binbuf_addbinbuf");
+ }
}
binbuf_add(x, z->b_n, z->b_vec);
@@ -346,41 +347,41 @@ void binbuf_restore(t_binbuf *x, int argc, t_atom *argv)
int newsize = x->b_n + argc, i;
t_atom *ap;
if (ap = t_resizebytes(x->b_vec, x->b_n * sizeof(*x->b_vec),
- newsize * sizeof(*x->b_vec)))
- x->b_vec = ap;
+ newsize * sizeof(*x->b_vec)))
+ x->b_vec = ap;
else
{
- error("binbuf_addmessage: out of space");
- return;
+ error("binbuf_addmessage: out of space");
+ return;
}
for (ap = x->b_vec + x->b_n, i = argc; i--; ap++)
{
- if (argv->a_type == A_SYMBOL)
- {
- char *str = argv->a_w.w_symbol->s_name;
- if (!strcmp(str, ";")) SETSEMI(ap);
- else if (!strcmp(str, ",")) SETCOMMA(ap);
- else if (str[0] == '$' && str[1] >= '0' && str[1] <= '9')
- {
- int dollsym = 0;
- char *str2;
- for (str2 = str + 2; *str2; str2++)
- if (*str2 < '0' || *str2 > '9')
- dollsym = 1;
- if (dollsym)
- SETDOLLSYM(ap, gensym(str + 1));
- else
- {
- int dollar = 0;
- sscanf(argv->a_w.w_symbol->s_name + 1, "%d", &dollar);
- SETDOLLAR(ap, dollar);
- }
- }
- else *ap = *argv;
- argv++;
- }
- else *ap = *(argv++);
+ if (argv->a_type == A_SYMBOL)
+ {
+ char *str = argv->a_w.w_symbol->s_name;
+ if (!strcmp(str, ";")) SETSEMI(ap);
+ else if (!strcmp(str, ",")) SETCOMMA(ap);
+ else if (str[0] == '$' && str[1] >= '0' && str[1] <= '9')
+ {
+ int dollsym = 0;
+ char *str2;
+ for (str2 = str + 2; *str2; str2++)
+ if (*str2 < '0' || *str2 > '9')
+ dollsym = 1;
+ if (dollsym)
+ SETDOLLSYM(ap, gensym(str + 1));
+ else
+ {
+ int dollar = 0;
+ sscanf(argv->a_w.w_symbol->s_name + 1, "%d", &dollar);
+ SETDOLLAR(ap, dollar);
+ }
+ }
+ else *ap = *argv;
+ argv++;
+ }
+ else *ap = *(argv++);
}
x->b_n = newsize;
}
@@ -393,16 +394,16 @@ void binbuf_print(t_binbuf *x)
int i, startedpost = 0, newline = 1;
for (i = 0; i < x->b_n; i++)
{
- if (newline)
- {
- if (startedpost) endpost();
- startpost("");
- startedpost = 1;
- }
- postatom(1, x->b_vec + i);
- if (x->b_vec[i].a_type == A_SEMI)
- newline = 1;
- else newline = 0;
+ if (newline)
+ {
+ if (startedpost) endpost();
+ startpost("");
+ startedpost = 1;
+ }
+ postatom(1, x->b_vec + i);
+ if (x->b_vec[i].a_type == A_SEMI)
+ newline = 1;
+ else newline = 0;
}
if (startedpost) endpost();
}
@@ -424,17 +425,17 @@ t_symbol *binbuf_realizedollsym(t_symbol *s, int ac, t_atom *av, int tonew)
int argno = atol(s->s_name), lastnum;
char buf[MAXPDSTRING], c, *sp;
for (lastnum = 0, sp = s->s_name; ((c = *sp) && c >= '0' && c <= '9');
- sp++, lastnum++)
+ sp++, lastnum++)
if (!c || argno < 0 || argno > ac)
{
- if (!tonew)
- return (0);
- else sprintf(buf, "$%d", argno);
+ if (!tonew)
+ return (0);
+ else sprintf(buf, "$%d", argno);
}
else if (argno == 0)
- sprintf(buf, "%d", canvas_getdollarzero());
+ sprintf(buf, "%d", canvas_getdollarzero());
else
- atom_string(av+(argno-1), buf, MAXPDSTRING/2-1);
+ atom_string(av+(argno-1), buf, MAXPDSTRING/2-1);
strncat(buf, sp, MAXPDSTRING/2-1);
return (gensym(buf));
}
@@ -448,146 +449,146 @@ void binbuf_eval(t_binbuf *x, t_pd *target, int argc, t_atom *argv)
int nargs;
while (1)
{
- t_pd *nexttarget;
- /* get a target. */
- while (!target)
- {
- t_symbol *s;
- while (ac && (at->a_type == A_SEMI || at->a_type == A_COMMA))
- ac--, at++;
- if (!ac) break;
- if (at->a_type == A_DOLLAR)
- {
- if (at->a_w.w_index <= 0 || at->a_w.w_index > argc)
- {
- error("$%d: not enough arguments supplied",
- at->a_w.w_index);
- goto cleanup;
- }
- else if (argv[at->a_w.w_index-1].a_type != A_SYMBOL)
- {
- error("$%d: symbol needed as message destination",
- at->a_w.w_index);
- goto cleanup;
- }
- else s = argv[at->a_w.w_index-1].a_w.w_symbol;
- }
- else if (at->a_type == A_DOLLSYM)
- {
- if (!(s = binbuf_realizedollsym(at->a_w.w_symbol,
- argc, argv, 0)))
- {
- error("$%s: not enough arguments supplied",
- at->a_w.w_symbol->s_name);
- goto cleanup;
- }
- }
- else s = atom_getsymbol(at);
- if (!(target = s->s_thing))
- {
- error("%s: no such object", s->s_name);
- cleanup:
- do at++, ac--;
- while (ac && at->a_type != A_SEMI);
- /* LATER eat args until semicolon and continue */
- continue;
- }
- else
- {
- at++, ac--;
- break;
- }
- }
- if (!ac) break;
- nargs = 0;
- nexttarget = target;
- while (1)
- {
- t_symbol *s9;
- if (!ac) goto gotmess;
- if (msp >= ems)
- {
- error("message stack overflow");
- goto broken;
- }
- switch (at->a_type)
- {
- case A_SEMI:
- /* semis and commas in new message just get bashed to
- a symbol. This is needed so you can pass them to "expr." */
- if (target == &pd_objectmaker)
- {
- SETSYMBOL(msp, gensym(";"));
- break;
- }
- else
- {
- nexttarget = 0;
- goto gotmess;
- }
- case A_COMMA:
- if (target == &pd_objectmaker)
- {
- SETSYMBOL(msp, gensym(","));
- break;
- }
- else goto gotmess;
- case A_FLOAT:
- case A_SYMBOL:
- *msp = *at;
- break;
- case A_DOLLAR:
- if (at->a_w.w_index > 0 && at->a_w.w_index <= argc)
- *msp = argv[at->a_w.w_index-1];
- else if (at->a_w.w_index == 0)
- SETFLOAT(msp, canvas_getdollarzero());
- else
- {
- if (target == &pd_objectmaker)
- SETFLOAT(msp, 0);
- else
- {
- error("$%d: argument number out of range",
- at->a_w.w_index);
- SETFLOAT(msp, 0);
- }
- }
- break;
- case A_DOLLSYM:
- s9 = binbuf_realizedollsym(at->a_w.w_symbol, argc, argv,
- target == &pd_objectmaker);
- if (!s9)
- goto broken;
- SETSYMBOL(msp, s9);
- break;
- default:
- bug("bad item in binbuf");
- goto broken;
- }
- msp++;
- ac--;
- at++;
- nargs++;
- }
+ t_pd *nexttarget;
+ /* get a target. */
+ while (!target)
+ {
+ t_symbol *s;
+ while (ac && (at->a_type == A_SEMI || at->a_type == A_COMMA))
+ ac--, at++;
+ if (!ac) break;
+ if (at->a_type == A_DOLLAR)
+ {
+ if (at->a_w.w_index <= 0 || at->a_w.w_index > argc)
+ {
+ error("$%d: not enough arguments supplied",
+ at->a_w.w_index);
+ goto cleanup;
+ }
+ else if (argv[at->a_w.w_index-1].a_type != A_SYMBOL)
+ {
+ error("$%d: symbol needed as message destination",
+ at->a_w.w_index);
+ goto cleanup;
+ }
+ else s = argv[at->a_w.w_index-1].a_w.w_symbol;
+ }
+ else if (at->a_type == A_DOLLSYM)
+ {
+ if (!(s = binbuf_realizedollsym(at->a_w.w_symbol,
+ argc, argv, 0)))
+ {
+ error("$%s: not enough arguments supplied",
+ at->a_w.w_symbol->s_name);
+ goto cleanup;
+ }
+ }
+ else s = atom_getsymbol(at);
+ if (!(target = s->s_thing))
+ {
+ error("%s: no such object", s->s_name);
+ cleanup:
+ do at++, ac--;
+ while (ac && at->a_type != A_SEMI);
+ /* LATER eat args until semicolon and continue */
+ continue;
+ }
+ else
+ {
+ at++, ac--;
+ break;
+ }
+ }
+ if (!ac) break;
+ nargs = 0;
+ nexttarget = target;
+ while (1)
+ {
+ t_symbol *s9;
+ if (!ac) goto gotmess;
+ if (msp >= ems)
+ {
+ error("message stack overflow");
+ goto broken;
+ }
+ switch (at->a_type)
+ {
+ case A_SEMI:
+ /* semis and commas in new message just get bashed to
+ a symbol. This is needed so you can pass them to "expr." */
+ if (target == &pd_objectmaker)
+ {
+ SETSYMBOL(msp, gensym(";"));
+ break;
+ }
+ else
+ {
+ nexttarget = 0;
+ goto gotmess;
+ }
+ case A_COMMA:
+ if (target == &pd_objectmaker)
+ {
+ SETSYMBOL(msp, gensym(","));
+ break;
+ }
+ else goto gotmess;
+ case A_FLOAT:
+ case A_SYMBOL:
+ *msp = *at;
+ break;
+ case A_DOLLAR:
+ if (at->a_w.w_index > 0 && at->a_w.w_index <= argc)
+ *msp = argv[at->a_w.w_index-1];
+ else if (at->a_w.w_index == 0)
+ SETFLOAT(msp, canvas_getdollarzero());
+ else
+ {
+ if (target == &pd_objectmaker)
+ SETFLOAT(msp, 0);
+ else
+ {
+ error("$%d: argument number out of range",
+ at->a_w.w_index);
+ SETFLOAT(msp, 0);
+ }
+ }
+ break;
+ case A_DOLLSYM:
+ s9 = binbuf_realizedollsym(at->a_w.w_symbol, argc, argv,
+ target == &pd_objectmaker);
+ if (!s9)
+ goto broken;
+ SETSYMBOL(msp, s9);
+ break;
+ default:
+ bug("bad item in binbuf");
+ goto broken;
+ }
+ msp++;
+ ac--;
+ at++;
+ nargs++;
+ }
gotmess:
- if (nargs)
- {
- switch (stackwas->a_type)
- {
- case A_SYMBOL:
- typedmess(target, stackwas->a_w.w_symbol, nargs-1, stackwas+1);
- break;
- case A_FLOAT:
- if (nargs == 1) pd_float(target, stackwas->a_w.w_float);
- else pd_list(target, 0, nargs, stackwas);
- break;
- }
- }
- msp = stackwas;
- if (!ac) break;
- target = nexttarget;
- at++;
- ac--;
+ if (nargs)
+ {
+ switch (stackwas->a_type)
+ {
+ case A_SYMBOL:
+ typedmess(target, stackwas->a_w.w_symbol, nargs-1, stackwas+1);
+ break;
+ case A_FLOAT:
+ if (nargs == 1) pd_float(target, stackwas->a_w.w_float);
+ else pd_list(target, 0, nargs, stackwas);
+ break;
+ }
+ }
+ msp = stackwas;
+ if (!ac) break;
+ target = nexttarget;
+ at++;
+ ac--;
}
return;
@@ -622,38 +623,38 @@ int binbuf_read(t_binbuf *b, char *filename, char *dirname, int crflag)
namebuf[0] = 0;
if (*dirname)
- strcat(namebuf, dirname), strcat(namebuf, "/");
+ strcat(namebuf, dirname), strcat(namebuf, "/");
strcat(namebuf, filename);
if ((fd = binbuf_doopen(namebuf, 0)) < 0)
{
- fprintf(stderr, "open: ");
- perror(namebuf);
- return (1);
+ fprintf(stderr, "open: ");
+ perror(namebuf);
+ return (1);
}
if ((length = lseek(fd, 0, SEEK_END)) < 0 || lseek(fd, 0, SEEK_SET) < 0
- || !(buf = t_getbytes(length)))
+ || !(buf = t_getbytes(length)))
{
- fprintf(stderr, "lseek: ");
- perror(namebuf);
- close(fd);
- return(1);
+ fprintf(stderr, "lseek: ");
+ perror(namebuf);
+ close(fd);
+ return(1);
}
if ((readret = read(fd, buf, length)) < length)
{
- fprintf(stderr, "read (%d %ld) -> %d\n", fd, length, readret);
- perror(namebuf);
- close(fd);
- t_freebytes(buf, length);
- return(1);
+ fprintf(stderr, "read (%d %ld) -> %d\n", fd, length, readret);
+ perror(namebuf);
+ close(fd);
+ t_freebytes(buf, length);
+ return(1);
}
- /* optionally map carriage return to semicolon */
+ /* optionally map carriage return to semicolon */
if (crflag)
{
- int i;
- for (i = 0; i < length; i++)
- if (buf[i] == '\n')
- buf[i] = ';';
+ int i;
+ for (i = 0; i < length; i++)
+ if (buf[i] == '\n')
+ buf[i] = ';';
}
binbuf_text(b, buf, length);
@@ -672,14 +673,14 @@ int binbuf_read_via_path(t_binbuf *b, char *filename, char *dirname,
int filedesc;
char buf[MAXPDSTRING], *bufptr;
if ((filedesc = open_via_path(
- dirname, filename, "", buf, &bufptr, MAXPDSTRING, 0)) < 0)
+ dirname, filename, "", buf, &bufptr, MAXPDSTRING, 0)) < 0)
{
- error("%s: can't open", filename);
- return (1);
+ error("%s: can't open", filename);
+ return (1);
}
else close (filedesc);
if (binbuf_read(b, bufptr, buf, crflag))
- return (1);
+ return (1);
else return (0);
}
@@ -698,71 +699,71 @@ int binbuf_write(t_binbuf *x, char *filename, char *dir, int crflag)
fbuf[0] = 0;
if (*dir)
- strcat(fbuf, dir), strcat(fbuf, "/");
+ strcat(fbuf, dir), strcat(fbuf, "/");
strcat(fbuf, filename);
if (!strcmp(filename + strlen(filename) - 4, ".pat"))
{
- x = binbuf_convert(x, 0);
- deleteit = 1;
+ x = binbuf_convert(x, 0);
+ deleteit = 1;
}
if (!(f = binbuf_dofopen(fbuf, "w")))
{
- fprintf(stderr, "open: ");
- sys_unixerror(fbuf);
- goto fail;
+ fprintf(stderr, "open: ");
+ sys_unixerror(fbuf);
+ goto fail;
}
for (ap = x->b_vec, indx = x->b_n; indx--; ap++)
{
- int length;
- /* estimate how many characters will be needed. Printing out
- symbols may need extra characters for inserting backslashes. */
- if (ap->a_type == A_SYMBOL || ap->a_type == A_DOLLSYM)
- length = 80 + strlen(ap->a_w.w_symbol->s_name);
- else length = 40;
- if (ep - bp < length)
- {
- if (fwrite(sbuf, bp-sbuf, 1, f) < 1)
- {
- sys_unixerror(fbuf);
- goto fail;
- }
- bp = sbuf;
- }
- if ((ap->a_type == A_SEMI || ap->a_type == A_COMMA) &&
- bp > sbuf && bp[-1] == ' ') bp--;
- if (!crflag || ap->a_type != A_SEMI)
- {
- atom_string(ap, bp, (ep-bp)-2);
- length = strlen(bp);
- bp += length;
- ncolumn += length;
- }
- if (ap->a_type == A_SEMI || (!crflag && ncolumn > 65))
- {
- *bp++ = '\n';
- ncolumn = 0;
- }
- else
- {
- *bp++ = ' ';
- ncolumn++;
- }
+ int length;
+ /* estimate how many characters will be needed. Printing out
+ symbols may need extra characters for inserting backslashes. */
+ if (ap->a_type == A_SYMBOL || ap->a_type == A_DOLLSYM)
+ length = 80 + strlen(ap->a_w.w_symbol->s_name);
+ else length = 40;
+ if (ep - bp < length)
+ {
+ if (fwrite(sbuf, bp-sbuf, 1, f) < 1)
+ {
+ sys_unixerror(fbuf);
+ goto fail;
+ }
+ bp = sbuf;
+ }
+ if ((ap->a_type == A_SEMI || ap->a_type == A_COMMA) &&
+ bp > sbuf && bp[-1] == ' ') bp--;
+ if (!crflag || ap->a_type != A_SEMI)
+ {
+ atom_string(ap, bp, (ep-bp)-2);
+ length = strlen(bp);
+ bp += length;
+ ncolumn += length;
+ }
+ if (ap->a_type == A_SEMI || (!crflag && ncolumn > 65))
+ {
+ *bp++ = '\n';
+ ncolumn = 0;
+ }
+ else
+ {
+ *bp++ = ' ';
+ ncolumn++;
+ }
}
if (fwrite(sbuf, bp-sbuf, 1, f) < 1)
{
- sys_unixerror(fbuf);
- goto fail;
+ sys_unixerror(fbuf);
+ goto fail;
}
if (deleteit)
- binbuf_free(x);
+ binbuf_free(x);
fclose(f);
return (0);
fail:
if (deleteit)
- binbuf_free(x);
+ binbuf_free(x);
if (f)
- fclose(f);
+ fclose(f);
return (1);
}
@@ -781,361 +782,364 @@ static t_binbuf *binbuf_convert(t_binbuf *oldb, int maxtopd)
t_binbuf *newb = binbuf_new();
t_atom *vec = oldb->b_vec;
t_int n = oldb->b_n, nextindex, stackdepth = 0, stack[MAXSTACK],
- nobj = 0, i;
+ nobj = 0, i;
t_atom outmess[MAXSTACK], *nextmess;
if (!maxtopd)
- binbuf_addv(newb, "ss;", gensym("max"), gensym("v2"));
+ binbuf_addv(newb, "ss;", gensym("max"), gensym("v2"));
for (nextindex = 0; nextindex < n; )
{
- int endmess, natom;
- char *first, *second;
- for (endmess = nextindex; endmess < n && vec[endmess].a_type != A_SEMI;
- endmess++)
- ;
- if (endmess == n) break;
- if (endmess == nextindex || endmess == nextindex + 1
- || vec[nextindex].a_type != A_SYMBOL ||
- vec[nextindex+1].a_type != A_SYMBOL)
- {
- nextindex = endmess + 1;
- continue;
- }
- natom = endmess - nextindex;
- if (natom > MAXSTACK-10) natom = MAXSTACK-10;
- nextmess = vec + nextindex;
- first = nextmess->a_w.w_symbol->s_name;
- second = (nextmess+1)->a_w.w_symbol->s_name;
- if (maxtopd)
- {
- /* case 1: importing a ".pat" file into Pd. */
-
- /* dollar signs in file translate to symbols */
- for (i = 0; i < natom; i++)
- {
- if (nextmess[i].a_type == A_DOLLAR)
- {
- char buf[100];
- sprintf(buf, "$%d", nextmess[i].a_w.w_index);
- SETSYMBOL(nextmess+i, gensym(buf));
- }
- else if (nextmess[i].a_type == A_DOLLSYM)
- {
- char buf[100];
- sprintf(buf, "$%s", nextmess[i].a_w.w_symbol->s_name);
- SETSYMBOL(nextmess+i, gensym(buf));
- }
- }
- if (!strcmp(first, "#N"))
- {
- if (!strcmp(second, "vpatcher"))
- {
- if (stackdepth >= MAXSTACK)
- {
- post("too many embedded patches");
- return (newb);
- }
- stack[stackdepth] = nobj;
- stackdepth++;
- nobj = 0;
- binbuf_addv(newb, "ssfffff;",
- gensym("#N"), gensym("canvas"),
- atom_getfloatarg(2, natom, nextmess),
- atom_getfloatarg(3, natom, nextmess),
- atom_getfloatarg(4, natom, nextmess) -
- atom_getfloatarg(2, natom, nextmess),
- atom_getfloatarg(5, natom, nextmess) -
- atom_getfloatarg(3, natom, nextmess),
- 12.);
- }
- }
- if (!strcmp(first, "#P"))
- {
- /* drop initial "hidden" flag */
- if (!strcmp(second, "hidden"))
- {
- nextmess++;
- natom--;
- second = (nextmess+1)->a_w.w_symbol->s_name;
- }
- if (natom >= 7 && !strcmp(second, "newobj")
- && (ISSYMBOL(&nextmess[6], "patcher") ||
- ISSYMBOL(&nextmess[6], "p")))
- {
- binbuf_addv(newb, "ssffss;",
- gensym("#X"), gensym("restore"),
- atom_getfloatarg(2, natom, nextmess),
- atom_getfloatarg(3, natom, nextmess),
- gensym("pd"), atom_getsymbolarg(7, natom, nextmess));
- if (stackdepth) stackdepth--;
- nobj = stack[stackdepth];
- nobj++;
- }
- else if (!strcmp(second, "newex") || !strcmp(second, "newobj"))
- {
- t_symbol *classname =
- atom_getsymbolarg(6, natom, nextmess);
- if (classname == gensym("trigger") ||
- classname == gensym("t"))
- {
- for (i = 7; i < natom; i++)
- if (nextmess[i].a_type == A_SYMBOL &&
- nextmess[i].a_w.w_symbol == gensym("i"))
- nextmess[i].a_w.w_symbol = gensym("f");
- }
- SETSYMBOL(outmess, gensym("#X"));
- SETSYMBOL(outmess + 1, gensym("obj"));
- outmess[2] = nextmess[2];
- outmess[3] = nextmess[3];
- for (i = 6; i < natom; i++)
- outmess[i-2] = nextmess[i];
- SETSEMI(outmess + natom - 2);
- binbuf_add(newb, natom - 1, outmess);
- nobj++;
- }
- else if (!strcmp(second, "message") ||
- !strcmp(second, "comment"))
- {
- SETSYMBOL(outmess, gensym("#X"));
- SETSYMBOL(outmess + 1, gensym(
- (strcmp(second, "message") ? "text" : "msg")));
- outmess[2] = nextmess[2];
- outmess[3] = nextmess[3];
- for (i = 6; i < natom; i++)
- outmess[i-2] = nextmess[i];
- SETSEMI(outmess + natom - 2);
- binbuf_add(newb, natom - 1, outmess);
- nobj++;
- }
- else if (!strcmp(second, "button"))
- {
- binbuf_addv(newb, "ssffs;",
- gensym("#X"), gensym("obj"),
- atom_getfloatarg(2, natom, nextmess),
- atom_getfloatarg(3, natom, nextmess),
- gensym("bng"));
- nobj++;
- }
- else if (!strcmp(second, "number") || !strcmp(second, "flonum"))
- {
- binbuf_addv(newb, "ssff;",
- gensym("#X"), gensym("floatatom"),
- atom_getfloatarg(2, natom, nextmess),
- atom_getfloatarg(3, natom, nextmess));
- nobj++;
- }
- else if (!strcmp(second, "slider"))
- {
- float inc = atom_getfloatarg(7, natom, nextmess);
- if (inc <= 0)
- inc = 1;
- binbuf_addv(newb, "ssffsffffffsssfffffffff;",
- gensym("#X"), gensym("obj"),
- atom_getfloatarg(2, natom, nextmess),
- atom_getfloatarg(3, natom, nextmess),
- gensym("vsl"),
- atom_getfloatarg(4, natom, nextmess),
- atom_getfloatarg(5, natom, nextmess),
- atom_getfloatarg(6, natom, nextmess),
- atom_getfloatarg(6, natom, nextmess)
- + (atom_getfloatarg(5, natom, nextmess) - 1) * inc,
- 0., 0.,
- gensym("empty"), gensym("empty"), gensym("empty"),
- 0., -8., 0., 8., -262144., -1., -1., 0., 1.);
- nobj++;
- }
- else if (!strcmp(second, "toggle"))
- {
- binbuf_addv(newb, "ssffs;",
- gensym("#X"), gensym("obj"),
- atom_getfloatarg(2, natom, nextmess),
- atom_getfloatarg(3, natom, nextmess),
- gensym("tgl"));
- nobj++;
- }
- else if (!strcmp(second, "inlet"))
- {
- binbuf_addv(newb, "ssffs;",
- gensym("#X"), gensym("obj"),
- atom_getfloatarg(2, natom, nextmess),
- atom_getfloatarg(3, natom, nextmess),
- gensym((natom > 5 ? "inlet~" : "inlet")));
- nobj++;
- }
- else if (!strcmp(second, "outlet"))
- {
- binbuf_addv(newb, "ssffs;",
- gensym("#X"), gensym("obj"),
- atom_getfloatarg(2, natom, nextmess),
- atom_getfloatarg(3, natom, nextmess),
- gensym((natom > 5 ? "outlet~" : "outlet")));
- nobj++;
- }
- else if (!strcmp(second, "user"))
- {
- binbuf_addv(newb, "ssffs;",
- gensym("#X"), gensym("obj"),
- atom_getfloatarg(3, natom, nextmess),
- atom_getfloatarg(4, natom, nextmess),
- atom_getsymbolarg(2, natom, nextmess));
- nobj++;
- }
- else if (!strcmp(second, "connect")||
- !strcmp(second, "fasten"))
- {
- binbuf_addv(newb, "ssffff;",
- gensym("#X"), gensym("connect"),
- nobj - atom_getfloatarg(2, natom, nextmess) - 1,
- atom_getfloatarg(3, natom, nextmess),
- nobj - atom_getfloatarg(4, natom, nextmess) - 1,
- atom_getfloatarg(5, natom, nextmess));
- }
- }
- }
- else /* Pd to Max */
- {
- if (!strcmp(first, "#N"))
- {
- if (!strcmp(second, "canvas"))
- {
- if (stackdepth >= MAXSTACK)
- {
- post("too many embedded patches");
- return (newb);
- }
- stack[stackdepth] = nobj;
- stackdepth++;
- nobj = 0;
- binbuf_addv(newb, "ssffff;",
- gensym("#N"), gensym("vpatcher"),
- atom_getfloatarg(2, natom, nextmess),
- atom_getfloatarg(3, natom, nextmess),
- atom_getfloatarg(4, natom, nextmess),
- atom_getfloatarg(5, natom, nextmess));
- }
- }
- if (!strcmp(first, "#X"))
- {
- if (natom >= 5 && !strcmp(second, "restore")
- && (ISSYMBOL (&nextmess[4], "pd")))
- {
- binbuf_addv(newb, "ss;", gensym("#P"), gensym("pop"));
- binbuf_addv(newb, "ssffffss;",
- gensym("#P"), gensym("newobj"),
- atom_getfloatarg(2, natom, nextmess),
- atom_getfloatarg(3, natom, nextmess), 50., 1.,
- gensym("patcher"),
- atom_getsymbolarg(5, natom, nextmess));
- if (stackdepth) stackdepth--;
- nobj = stack[stackdepth];
- nobj++;
- }
- else if (!strcmp(second, "obj"))
- {
- t_symbol *classname =
- atom_getsymbolarg(4, natom, nextmess);
- if (classname == gensym("inlet"))
- binbuf_addv(newb, "ssfff;", gensym("#P"),
- gensym("inlet"),
- atom_getfloatarg(2, natom, nextmess),
- atom_getfloatarg(3, natom, nextmess),
- 15.);
- else if (classname == gensym("inlet~"))
- binbuf_addv(newb, "ssffff;", gensym("#P"),
- gensym("inlet"),
- atom_getfloatarg(2, natom, nextmess),
- atom_getfloatarg(3, natom, nextmess),
- 15., 1.);
- else if (classname == gensym("outlet"))
- binbuf_addv(newb, "ssfff;", gensym("#P"),
- gensym("outlet"),
- atom_getfloatarg(2, natom, nextmess),
- atom_getfloatarg(3, natom, nextmess),
- 15.);
- else if (classname == gensym("outlet~"))
- binbuf_addv(newb, "ssffff;", gensym("#P"),
- gensym("outlet"),
- atom_getfloatarg(2, natom, nextmess),
- atom_getfloatarg(3, natom, nextmess),
- 15., 1.);
- else if (classname == gensym("bng"))
- binbuf_addv(newb, "ssffff;", gensym("#P"),
- gensym("button"),
- atom_getfloatarg(2, natom, nextmess),
- atom_getfloatarg(3, natom, nextmess),
- atom_getfloatarg(5, natom, nextmess), 0.);
- else if (classname == gensym("tgl"))
- binbuf_addv(newb, "ssffff;", gensym("#P"),
- gensym("toggle"),
- atom_getfloatarg(2, natom, nextmess),
- atom_getfloatarg(3, natom, nextmess),
- atom_getfloatarg(5, natom, nextmess), 0.);
- else if (classname == gensym("vsl"))
- binbuf_addv(newb, "ssffffff;", gensym("#P"),
- gensym("slider"),
- atom_getfloatarg(2, natom, nextmess),
- atom_getfloatarg(3, natom, nextmess),
- atom_getfloatarg(5, natom, nextmess),
- atom_getfloatarg(6, natom, nextmess),
- (atom_getfloatarg(8, natom, nextmess) -
- atom_getfloatarg(7, natom, nextmess)) /
- (atom_getfloatarg(6, natom, nextmess) == 1? 1 :
- atom_getfloatarg(6, natom, nextmess) - 1),
- atom_getfloatarg(7, natom, nextmess));
- else
- {
- SETSYMBOL(outmess, gensym("#P"));
- SETSYMBOL(outmess + 1, gensym("newex"));
- outmess[2] = nextmess[2];
- outmess[3] = nextmess[3];
- SETFLOAT(outmess + 4, 50);
- SETFLOAT(outmess + 5, 1);
- for (i = 4; i < natom; i++)
- outmess[i+2] = nextmess[i];
- SETSEMI(outmess + natom + 2);
- binbuf_add(newb, natom + 3, outmess);
- }
- nobj++;
-
- }
- else if (!strcmp(second, "msg") ||
- !strcmp(second, "text"))
- {
- SETSYMBOL(outmess, gensym("#P"));
- SETSYMBOL(outmess + 1, gensym(
- (strcmp(second, "msg") ? "comment" : "message")));
- outmess[2] = nextmess[2];
- outmess[3] = nextmess[3];
- SETFLOAT(outmess + 4, 50);
- SETFLOAT(outmess + 5, 1);
- for (i = 4; i < natom; i++)
- outmess[i+2] = nextmess[i];
- SETSEMI(outmess + natom + 2);
- binbuf_add(newb, natom + 3, outmess);
- nobj++;
- }
- else if (!strcmp(second, "floatatom"))
- {
- binbuf_addv(newb, "ssfff;",
- gensym("#P"), gensym("flonum"),
- atom_getfloatarg(2, natom, nextmess),
- atom_getfloatarg(3, natom, nextmess), 35);
- nobj++;
- }
- else if (!strcmp(second, "connect"))
- {
- binbuf_addv(newb, "ssffff;",
- gensym("#P"), gensym("connect"),
- nobj - atom_getfloatarg(2, natom, nextmess) - 1,
- atom_getfloatarg(3, natom, nextmess),
- nobj - atom_getfloatarg(4, natom, nextmess) - 1,
- atom_getfloatarg(5, natom, nextmess));
- }
- }
- }
- nextindex = endmess + 1;
+ int endmess, natom;
+ char *first, *second;
+ for (endmess = nextindex; endmess < n && vec[endmess].a_type != A_SEMI;
+ endmess++)
+ ;
+ if (endmess == n) break;
+ if (endmess == nextindex || endmess == nextindex + 1
+ || vec[nextindex].a_type != A_SYMBOL ||
+ vec[nextindex+1].a_type != A_SYMBOL)
+ {
+ nextindex = endmess + 1;
+ continue;
+ }
+ natom = endmess - nextindex;
+ if (natom > MAXSTACK-10) natom = MAXSTACK-10;
+ nextmess = vec + nextindex;
+ first = nextmess->a_w.w_symbol->s_name;
+ second = (nextmess+1)->a_w.w_symbol->s_name;
+ if (maxtopd)
+ {
+ /* case 1: importing a ".pat" file into Pd. */
+
+ /* dollar signs in file translate to symbols */
+ for (i = 0; i < natom; i++)
+ {
+ if (nextmess[i].a_type == A_DOLLAR)
+ {
+ char buf[100];
+ sprintf(buf, "$%d", nextmess[i].a_w.w_index);
+ SETSYMBOL(nextmess+i, gensym(buf));
+ }
+ else if (nextmess[i].a_type == A_DOLLSYM)
+ {
+ char buf[100];
+ sprintf(buf, "$%s", nextmess[i].a_w.w_symbol->s_name);
+ SETSYMBOL(nextmess+i, gensym(buf));
+ }
+ }
+ if (!strcmp(first, "#N"))
+ {
+ if (!strcmp(second, "vpatcher"))
+ {
+ if (stackdepth >= MAXSTACK)
+ {
+ post("too many embedded patches");
+ return (newb);
+ }
+ stack[stackdepth] = nobj;
+ stackdepth++;
+ nobj = 0;
+ binbuf_addv(newb, "ssfffff;",
+ gensym("#N"), gensym("canvas"),
+ atom_getfloatarg(2, natom, nextmess),
+ atom_getfloatarg(3, natom, nextmess),
+ atom_getfloatarg(4, natom, nextmess) -
+ atom_getfloatarg(2, natom, nextmess),
+ atom_getfloatarg(5, natom, nextmess) -
+ atom_getfloatarg(3, natom, nextmess),
+ (float)sys_defaultfont);
+ }
+ }
+ if (!strcmp(first, "#P"))
+ {
+ /* drop initial "hidden" flag */
+ if (!strcmp(second, "hidden"))
+ {
+ nextmess++;
+ natom--;
+ second = (nextmess+1)->a_w.w_symbol->s_name;
+ }
+ if (natom >= 7 && !strcmp(second, "newobj")
+ && (ISSYMBOL(&nextmess[6], "patcher") ||
+ ISSYMBOL(&nextmess[6], "p")))
+ {
+ binbuf_addv(newb, "ssffss;",
+ gensym("#X"), gensym("restore"),
+ atom_getfloatarg(2, natom, nextmess),
+ atom_getfloatarg(3, natom, nextmess),
+ gensym("pd"), atom_getsymbolarg(7, natom, nextmess));
+ if (stackdepth) stackdepth--;
+ nobj = stack[stackdepth];
+ nobj++;
+ }
+ else if (!strcmp(second, "newex") || !strcmp(second, "newobj"))
+ {
+ t_symbol *classname =
+ atom_getsymbolarg(6, natom, nextmess);
+ if (classname == gensym("trigger") ||
+ classname == gensym("t"))
+ {
+ for (i = 7; i < natom; i++)
+ if (nextmess[i].a_type == A_SYMBOL &&
+ nextmess[i].a_w.w_symbol == gensym("i"))
+ nextmess[i].a_w.w_symbol = gensym("f");
+ }
+ if (classname == gensym("table"))
+ classname = gensym("TABLE");
+ SETSYMBOL(outmess, gensym("#X"));
+ SETSYMBOL(outmess + 1, gensym("obj"));
+ outmess[2] = nextmess[2];
+ outmess[3] = nextmess[3];
+ SETSYMBOL(outmess+4, classname);
+ for (i = 7; i < natom; i++)
+ outmess[i-2] = nextmess[i];
+ SETSEMI(outmess + natom - 2);
+ binbuf_add(newb, natom - 1, outmess);
+ nobj++;
+ }
+ else if (!strcmp(second, "message") ||
+ !strcmp(second, "comment"))
+ {
+ SETSYMBOL(outmess, gensym("#X"));
+ SETSYMBOL(outmess + 1, gensym(
+ (strcmp(second, "message") ? "text" : "msg")));
+ outmess[2] = nextmess[2];
+ outmess[3] = nextmess[3];
+ for (i = 6; i < natom; i++)
+ outmess[i-2] = nextmess[i];
+ SETSEMI(outmess + natom - 2);
+ binbuf_add(newb, natom - 1, outmess);
+ nobj++;
+ }
+ else if (!strcmp(second, "button"))
+ {
+ binbuf_addv(newb, "ssffs;",
+ gensym("#X"), gensym("obj"),
+ atom_getfloatarg(2, natom, nextmess),
+ atom_getfloatarg(3, natom, nextmess),
+ gensym("bng"));
+ nobj++;
+ }
+ else if (!strcmp(second, "number") || !strcmp(second, "flonum"))
+ {
+ binbuf_addv(newb, "ssff;",
+ gensym("#X"), gensym("floatatom"),
+ atom_getfloatarg(2, natom, nextmess),
+ atom_getfloatarg(3, natom, nextmess));
+ nobj++;
+ }
+ else if (!strcmp(second, "slider"))
+ {
+ float inc = atom_getfloatarg(7, natom, nextmess);
+ if (inc <= 0)
+ inc = 1;
+ binbuf_addv(newb, "ssffsffffffsssfffffffff;",
+ gensym("#X"), gensym("obj"),
+ atom_getfloatarg(2, natom, nextmess),
+ atom_getfloatarg(3, natom, nextmess),
+ gensym("vsl"),
+ atom_getfloatarg(4, natom, nextmess),
+ atom_getfloatarg(5, natom, nextmess),
+ atom_getfloatarg(6, natom, nextmess),
+ atom_getfloatarg(6, natom, nextmess)
+ + (atom_getfloatarg(5, natom, nextmess) - 1) * inc,
+ 0., 0.,
+ gensym("empty"), gensym("empty"), gensym("empty"),
+ 0., -8., 0., 8., -262144., -1., -1., 0., 1.);
+ nobj++;
+ }
+ else if (!strcmp(second, "toggle"))
+ {
+ binbuf_addv(newb, "ssffs;",
+ gensym("#X"), gensym("obj"),
+ atom_getfloatarg(2, natom, nextmess),
+ atom_getfloatarg(3, natom, nextmess),
+ gensym("tgl"));
+ nobj++;
+ }
+ else if (!strcmp(second, "inlet"))
+ {
+ binbuf_addv(newb, "ssffs;",
+ gensym("#X"), gensym("obj"),
+ atom_getfloatarg(2, natom, nextmess),
+ atom_getfloatarg(3, natom, nextmess),
+ gensym((natom > 5 ? "inlet~" : "inlet")));
+ nobj++;
+ }
+ else if (!strcmp(second, "outlet"))
+ {
+ binbuf_addv(newb, "ssffs;",
+ gensym("#X"), gensym("obj"),
+ atom_getfloatarg(2, natom, nextmess),
+ atom_getfloatarg(3, natom, nextmess),
+ gensym((natom > 5 ? "outlet~" : "outlet")));
+ nobj++;
+ }
+ else if (!strcmp(second, "user"))
+ {
+ binbuf_addv(newb, "ssffs;",
+ gensym("#X"), gensym("obj"),
+ atom_getfloatarg(3, natom, nextmess),
+ atom_getfloatarg(4, natom, nextmess),
+ atom_getsymbolarg(2, natom, nextmess));
+ nobj++;
+ }
+ else if (!strcmp(second, "connect")||
+ !strcmp(second, "fasten"))
+ {
+ binbuf_addv(newb, "ssffff;",
+ gensym("#X"), gensym("connect"),
+ nobj - atom_getfloatarg(2, natom, nextmess) - 1,
+ atom_getfloatarg(3, natom, nextmess),
+ nobj - atom_getfloatarg(4, natom, nextmess) - 1,
+ atom_getfloatarg(5, natom, nextmess));
+ }
+ }
+ }
+ else /* Pd to Max */
+ {
+ if (!strcmp(first, "#N"))
+ {
+ if (!strcmp(second, "canvas"))
+ {
+ if (stackdepth >= MAXSTACK)
+ {
+ post("too many embedded patches");
+ return (newb);
+ }
+ stack[stackdepth] = nobj;
+ stackdepth++;
+ nobj = 0;
+ binbuf_addv(newb, "ssffff;",
+ gensym("#N"), gensym("vpatcher"),
+ atom_getfloatarg(2, natom, nextmess),
+ atom_getfloatarg(3, natom, nextmess),
+ atom_getfloatarg(4, natom, nextmess),
+ atom_getfloatarg(5, natom, nextmess));
+ }
+ }
+ if (!strcmp(first, "#X"))
+ {
+ if (natom >= 5 && !strcmp(second, "restore")
+ && (ISSYMBOL (&nextmess[4], "pd")))
+ {
+ binbuf_addv(newb, "ss;", gensym("#P"), gensym("pop"));
+ binbuf_addv(newb, "ssffffss;",
+ gensym("#P"), gensym("newobj"),
+ atom_getfloatarg(2, natom, nextmess),
+ atom_getfloatarg(3, natom, nextmess), 50., 1.,
+ gensym("patcher"),
+ atom_getsymbolarg(5, natom, nextmess));
+ if (stackdepth) stackdepth--;
+ nobj = stack[stackdepth];
+ nobj++;
+ }
+ else if (!strcmp(second, "obj"))
+ {
+ t_symbol *classname =
+ atom_getsymbolarg(4, natom, nextmess);
+ if (classname == gensym("inlet"))
+ binbuf_addv(newb, "ssfff;", gensym("#P"),
+ gensym("inlet"),
+ atom_getfloatarg(2, natom, nextmess),
+ atom_getfloatarg(3, natom, nextmess),
+ 15.);
+ else if (classname == gensym("inlet~"))
+ binbuf_addv(newb, "ssffff;", gensym("#P"),
+ gensym("inlet"),
+ atom_getfloatarg(2, natom, nextmess),
+ atom_getfloatarg(3, natom, nextmess),
+ 15., 1.);
+ else if (classname == gensym("outlet"))
+ binbuf_addv(newb, "ssfff;", gensym("#P"),
+ gensym("outlet"),
+ atom_getfloatarg(2, natom, nextmess),
+ atom_getfloatarg(3, natom, nextmess),
+ 15.);
+ else if (classname == gensym("outlet~"))
+ binbuf_addv(newb, "ssffff;", gensym("#P"),
+ gensym("outlet"),
+ atom_getfloatarg(2, natom, nextmess),
+ atom_getfloatarg(3, natom, nextmess),
+ 15., 1.);
+ else if (classname == gensym("bng"))
+ binbuf_addv(newb, "ssffff;", gensym("#P"),
+ gensym("button"),
+ atom_getfloatarg(2, natom, nextmess),
+ atom_getfloatarg(3, natom, nextmess),
+ atom_getfloatarg(5, natom, nextmess), 0.);
+ else if (classname == gensym("tgl"))
+ binbuf_addv(newb, "ssffff;", gensym("#P"),
+ gensym("toggle"),
+ atom_getfloatarg(2, natom, nextmess),
+ atom_getfloatarg(3, natom, nextmess),
+ atom_getfloatarg(5, natom, nextmess), 0.);
+ else if (classname == gensym("vsl"))
+ binbuf_addv(newb, "ssffffff;", gensym("#P"),
+ gensym("slider"),
+ atom_getfloatarg(2, natom, nextmess),
+ atom_getfloatarg(3, natom, nextmess),
+ atom_getfloatarg(5, natom, nextmess),
+ atom_getfloatarg(6, natom, nextmess),
+ (atom_getfloatarg(8, natom, nextmess) -
+ atom_getfloatarg(7, natom, nextmess)) /
+ (atom_getfloatarg(6, natom, nextmess) == 1? 1 :
+ atom_getfloatarg(6, natom, nextmess) - 1),
+ atom_getfloatarg(7, natom, nextmess));
+ else
+ {
+ SETSYMBOL(outmess, gensym("#P"));
+ SETSYMBOL(outmess + 1, gensym("newex"));
+ outmess[2] = nextmess[2];
+ outmess[3] = nextmess[3];
+ SETFLOAT(outmess + 4, 50);
+ SETFLOAT(outmess + 5, 1);
+ for (i = 4; i < natom; i++)
+ outmess[i+2] = nextmess[i];
+ SETSEMI(outmess + natom + 2);
+ binbuf_add(newb, natom + 3, outmess);
+ }
+ nobj++;
+
+ }
+ else if (!strcmp(second, "msg") ||
+ !strcmp(second, "text"))
+ {
+ SETSYMBOL(outmess, gensym("#P"));
+ SETSYMBOL(outmess + 1, gensym(
+ (strcmp(second, "msg") ? "comment" : "message")));
+ outmess[2] = nextmess[2];
+ outmess[3] = nextmess[3];
+ SETFLOAT(outmess + 4, 50);
+ SETFLOAT(outmess + 5, 1);
+ for (i = 4; i < natom; i++)
+ outmess[i+2] = nextmess[i];
+ SETSEMI(outmess + natom + 2);
+ binbuf_add(newb, natom + 3, outmess);
+ nobj++;
+ }
+ else if (!strcmp(second, "floatatom"))
+ {
+ binbuf_addv(newb, "ssfff;",
+ gensym("#P"), gensym("flonum"),
+ atom_getfloatarg(2, natom, nextmess),
+ atom_getfloatarg(3, natom, nextmess), 35);
+ nobj++;
+ }
+ else if (!strcmp(second, "connect"))
+ {
+ binbuf_addv(newb, "ssffff;",
+ gensym("#P"), gensym("connect"),
+ nobj - atom_getfloatarg(2, natom, nextmess) - 1,
+ atom_getfloatarg(3, natom, nextmess),
+ nobj - atom_getfloatarg(4, natom, nextmess) - 1,
+ atom_getfloatarg(5, natom, nextmess));
+ }
+ }
+ }
+ nextindex = endmess + 1;
}
if (!maxtopd)
- binbuf_addv(newb, "ss;", gensym("#P"), gensym("pop"));
+ binbuf_addv(newb, "ss;", gensym("#P"), gensym("pop"));
#if 0
binbuf_write(newb, "import-result.pd", "/tmp", 0);
#endif
@@ -1148,21 +1152,21 @@ int binbuf_match(t_binbuf *inbuf, t_binbuf *searchbuf)
int indexin, nmatched;
for (indexin = 0; indexin <= inbuf->b_n - searchbuf->b_n; indexin++)
{
- for (nmatched = 0; nmatched < searchbuf->b_n; nmatched++)
- {
- t_atom *a1 = &inbuf->b_vec[indexin + nmatched],
- *a2 = &searchbuf->b_vec[nmatched];
- if (a1->a_type != a2->a_type ||
- a1->a_type == A_SYMBOL && a1->a_w.w_symbol != a2->a_w.w_symbol
- ||
- a1->a_type == A_FLOAT && a1->a_w.w_float != a2->a_w.w_float
- ||
- a1->a_type == A_DOLLAR && a1->a_w.w_index != a2->a_w.w_index
- ||
- a1->a_type == A_DOLLSYM && a1->a_w.w_symbol != a2->a_w.w_symbol)
- goto nomatch;
- }
- return (1);
+ for (nmatched = 0; nmatched < searchbuf->b_n; nmatched++)
+ {
+ t_atom *a1 = &inbuf->b_vec[indexin + nmatched],
+ *a2 = &searchbuf->b_vec[nmatched];
+ if (a1->a_type != a2->a_type ||
+ a1->a_type == A_SYMBOL && a1->a_w.w_symbol != a2->a_w.w_symbol
+ ||
+ a1->a_type == A_FLOAT && a1->a_w.w_float != a2->a_w.w_float
+ ||
+ a1->a_type == A_DOLLAR && a1->a_w.w_index != a2->a_w.w_index
+ ||
+ a1->a_type == A_DOLLSYM && a1->a_w.w_symbol != a2->a_w.w_symbol)
+ goto nomatch;
+ }
+ return (1);
nomatch: ;
}
return (0);
@@ -1176,24 +1180,24 @@ void binbuf_evalfile(t_symbol *name, t_symbol *dir)
{
t_binbuf *b = binbuf_new();
int import = !strcmp(name->s_name + strlen(name->s_name) - 4, ".pat");
- /* set filename so that new canvases can pick them up */
+ /* set filename so that new canvases can pick them up */
int dspstate = canvas_suspend_dsp();
glob_setfilename(0, name, dir);
if (binbuf_read(b, name->s_name, dir->s_name, 0))
{
- perror(name->s_name);
+ perror(name->s_name);
}
else
{
- if (import)
- {
- t_binbuf *newb = binbuf_convert(b, 1);
- binbuf_free(b);
- b = newb;
- }
- binbuf_eval(b, 0, 0, 0);
+ if (import)
+ {
+ t_binbuf *newb = binbuf_convert(b, 1);
+ binbuf_free(b);
+ b = newb;
+ }
+ binbuf_eval(b, 0, 0, 0);
}
- glob_setfilename(0, &s_, &s_); /* bug fix by Krzysztof Czaja */
+ glob_setfilename(0, &s_, &s_); /* bug fix by Krzysztof Czaja */
binbuf_free(b);
canvas_resume_dsp(dspstate);
}
@@ -1201,15 +1205,15 @@ void binbuf_evalfile(t_symbol *name, t_symbol *dir)
void glob_evalfile(t_pd *ignore, t_symbol *name, t_symbol *dir)
{
t_pd *x = 0;
- /* even though binbuf_evalfile appears to take care of dspstate,
- we have to do it again here, because canvas_startdsp() assumes
- that all toplevel canvases are visible. LATER check if this
- is still necessary -- probably not. */
+ /* even though binbuf_evalfile appears to take care of dspstate,
+ we have to do it again here, because canvas_startdsp() assumes
+ that all toplevel canvases are visible. LATER check if this
+ is still necessary -- probably not. */
int dspstate = canvas_suspend_dsp();
binbuf_evalfile(name, dir);
while ((x != s__X.s_thing) && (x = s__X.s_thing))
- vmess(x, gensym("pop"), "i", 1);
+ vmess(x, gensym("pop"), "i", 1);
pd_doloadbang();
canvas_resume_dsp(dspstate);
}
diff --git a/pd/src/m_class.c b/pd/src/m_class.c
index 15610b23..c605ae89 100644
--- a/pd/src/m_class.c
+++ b/pd/src/m_class.c
@@ -7,7 +7,7 @@
#include "m_imp.h"
#include "s_stuff.h"
#include <stdlib.h>
-#ifdef UNIX
+#ifdef UNISTD
#include <unistd.h>
#endif
#ifdef MSW
@@ -20,8 +20,8 @@
static t_symbol *class_loadsym; /* name under which an extern is invoked */
static void pd_defaultfloat(t_pd *x, t_float f);
static void pd_defaultlist(t_pd *x, t_symbol *s, int argc, t_atom *argv);
-t_pd pd_objectmaker; /* factory for creating "object" boxes */
-t_pd pd_canvasmaker; /* factory for creating canvases */
+t_pd pd_objectmaker; /* factory for creating "object" boxes */
+t_pd pd_canvasmaker; /* factory for creating canvases */
static t_symbol *class_extern_dir = &s_;
@@ -33,7 +33,7 @@ static void pd_defaultanything(t_pd *x, t_symbol *s, int argc, t_atom *argv)
static void pd_defaultbang(t_pd *x)
{
if (*(*x)->c_listmethod != pd_defaultlist)
- (*(*x)->c_listmethod)(x, 0, 0, 0);
+ (*(*x)->c_listmethod)(x, 0, 0, 0);
else (*(*x)->c_anymethod)(x, &s_bang, 0, 0);
}
@@ -41,15 +41,15 @@ static void pd_defaultpointer(t_pd *x, t_gpointer *gp)
{
if (*(*x)->c_listmethod != pd_defaultlist)
{
- t_atom at;
- SETPOINTER(&at, gp);
- (*(*x)->c_listmethod)(x, 0, 1, &at);
+ t_atom at;
+ SETPOINTER(&at, gp);
+ (*(*x)->c_listmethod)(x, 0, 1, &at);
}
else
{
- t_atom at;
- SETPOINTER(&at, gp);
- (*(*x)->c_anymethod)(x, &s_pointer, 1, &at);
+ t_atom at;
+ SETPOINTER(&at, gp);
+ (*(*x)->c_anymethod)(x, &s_pointer, 1, &at);
}
}
@@ -57,15 +57,15 @@ static void pd_defaultfloat(t_pd *x, t_float f)
{
if (*(*x)->c_listmethod != pd_defaultlist)
{
- t_atom at;
- SETFLOAT(&at, f);
- (*(*x)->c_listmethod)(x, 0, 1, &at);
+ t_atom at;
+ SETFLOAT(&at, f);
+ (*(*x)->c_listmethod)(x, 0, 1, &at);
}
else
{
- t_atom at;
- SETFLOAT(&at, f);
- (*(*x)->c_anymethod)(x, &s_float, 1, &at);
+ t_atom at;
+ SETFLOAT(&at, f);
+ (*(*x)->c_anymethod)(x, &s_float, 1, &at);
}
}
@@ -73,15 +73,15 @@ static void pd_defaultsymbol(t_pd *x, t_symbol *s)
{
if (*(*x)->c_listmethod != pd_defaultlist)
{
- t_atom at;
- SETSYMBOL(&at, s);
- (*(*x)->c_listmethod)(x, 0, 1, &at);
+ t_atom at;
+ SETSYMBOL(&at, s);
+ (*(*x)->c_listmethod)(x, 0, 1, &at);
}
else
{
- t_atom at;
- SETSYMBOL(&at, s);
- (*(*x)->c_anymethod)(x, &s_symbol, 1, &at);
+ t_atom at;
+ SETSYMBOL(&at, s);
+ (*(*x)->c_anymethod)(x, &s_symbol, 1, &at);
}
}
@@ -91,38 +91,45 @@ static void class_nosavefn(t_gobj *z, t_binbuf *b);
/* handle "list" messages to Pds without explicit list methods defined. */
static void pd_defaultlist(t_pd *x, t_symbol *s, int argc, t_atom *argv)
{
- /* a list with one element which is a number can be handled by a
- "float" method if any is defined; same for "symbol", "pointer". */
+ /* a list with no elements is handled by the 'bang' method if
+ one exists. */
+ if (argc == 0 && *(*x)->c_bangmethod != pd_defaultbang)
+ {
+ (*(*x)->c_bangmethod)(x);
+ return;
+ }
+ /* a list with one element which is a number can be handled by a
+ "float" method if any is defined; same for "symbol", "pointer". */
if (argc == 1)
{
- if (argv->a_type == A_FLOAT &&
- *(*x)->c_floatmethod != pd_defaultfloat)
- {
- (*(*x)->c_floatmethod)(x, argv->a_w.w_float);
- return;
- }
- else if (argv->a_type == A_SYMBOL &&
- *(*x)->c_symbolmethod != pd_defaultsymbol)
- {
- (*(*x)->c_symbolmethod)(x, argv->a_w.w_symbol);
- return;
- }
- else if (argv->a_type == A_POINTER &&
- *(*x)->c_pointermethod != pd_defaultpointer)
- {
- (*(*x)->c_pointermethod)(x, argv->a_w.w_gpointer);
- return;
- }
+ if (argv->a_type == A_FLOAT &&
+ *(*x)->c_floatmethod != pd_defaultfloat)
+ {
+ (*(*x)->c_floatmethod)(x, argv->a_w.w_float);
+ return;
+ }
+ else if (argv->a_type == A_SYMBOL &&
+ *(*x)->c_symbolmethod != pd_defaultsymbol)
+ {
+ (*(*x)->c_symbolmethod)(x, argv->a_w.w_symbol);
+ return;
+ }
+ else if (argv->a_type == A_POINTER &&
+ *(*x)->c_pointermethod != pd_defaultpointer)
+ {
+ (*(*x)->c_pointermethod)(x, argv->a_w.w_gpointer);
+ return;
+ }
}
- /* Next try for an "anything" method */
+ /* Next try for an "anything" method */
if ((*x)->c_anymethod != pd_defaultanything)
- (*(*x)->c_anymethod)(x, &s_list, argc, argv);
+ (*(*x)->c_anymethod)(x, &s_list, argc, argv);
- /* if the object is patchable (i.e., can have proper inlets)
- send it on to obj_list which will unpack the list into the inlets */
+ /* if the object is patchable (i.e., can have proper inlets)
+ send it on to obj_list which will unpack the list into the inlets */
else if ((*x)->c_patchable)
- obj_list((t_object *)x, s, argc, argv);
- /* otherwise gove up and complain. */
+ obj_list((t_object *)x, s, argc, argv);
+ /* otherwise gove up and complain. */
else pd_defaultanything(x, &s_list, argc, argv);
}
@@ -158,34 +165,34 @@ t_class *class_new(t_symbol *s, t_newmethod newmethod, t_method freemethod,
va_start(ap, type1);
while (*vp)
{
- if (count == MAXPDARG)
- {
- error("class %s: sorry: only %d creation args allowed",
- s->s_name, MAXPDARG);
- break;
- }
- vp++;
- count++;
- *vp = va_arg(ap, t_atomtype);
+ if (count == MAXPDARG)
+ {
+ error("class %s: sorry: only %d creation args allowed",
+ s->s_name, MAXPDARG);
+ break;
+ }
+ vp++;
+ count++;
+ *vp = va_arg(ap, t_atomtype);
}
va_end(ap);
if (pd_objectmaker && newmethod)
{
- /* add a "new" method by the name specified by the object */
- class_addmethod(pd_objectmaker, (t_method)newmethod, s,
- vec[0], vec[1], vec[2], vec[3], vec[4], vec[5]);
- if (class_loadsym)
- {
- /* if we're loading an extern it might have been invoked by a
- longer file name; in this case, make this an admissible name
- too. */
- char *loadstring = class_loadsym->s_name,
- l1 = strlen(s->s_name), l2 = strlen(loadstring);
- if (l2 > l1 && !strcmp(s->s_name, loadstring + (l2 - l1)))
- class_addmethod(pd_objectmaker, (t_method)newmethod,
- class_loadsym,
- vec[0], vec[1], vec[2], vec[3], vec[4], vec[5]);
- }
+ /* add a "new" method by the name specified by the object */
+ class_addmethod(pd_objectmaker, (t_method)newmethod, s,
+ vec[0], vec[1], vec[2], vec[3], vec[4], vec[5]);
+ if (class_loadsym)
+ {
+ /* if we're loading an extern it might have been invoked by a
+ longer file name; in this case, make this an admissible name
+ too. */
+ char *loadstring = class_loadsym->s_name,
+ l1 = strlen(s->s_name), l2 = strlen(loadstring);
+ if (l2 > l1 && !strcmp(s->s_name, loadstring + (l2 - l1)))
+ class_addmethod(pd_objectmaker, (t_method)newmethod,
+ class_loadsym,
+ vec[0], vec[1], vec[2], vec[3], vec[4], vec[5]);
+ }
}
c = (t_class *)t_getbytes(sizeof(*c));
c->c_name = c->c_helpname = s;
@@ -230,19 +237,19 @@ void class_addcreator(t_newmethod newmethod, t_symbol *s,
va_start(ap, type1);
while (*vp)
{
- if (count == MAXPDARG)
- {
- error("class %s: sorry: only %d creation args allowed",
- s->s_name, MAXPDARG);
- break;
- }
- vp++;
- count++;
- *vp = va_arg(ap, t_atomtype);
+ if (count == MAXPDARG)
+ {
+ error("class %s: sorry: only %d creation args allowed",
+ s->s_name, MAXPDARG);
+ break;
+ }
+ vp++;
+ count++;
+ *vp = va_arg(ap, t_atomtype);
}
va_end(ap);
class_addmethod(pd_objectmaker, (t_method)newmethod, s,
- vec[0], vec[1], vec[2], vec[3], vec[4], vec[5]);
+ vec[0], vec[1], vec[2], vec[3], vec[4], vec[5]);
}
void class_addmethod(t_class *c, t_method fn, t_symbol *sel,
@@ -254,67 +261,67 @@ void class_addmethod(t_class *c, t_method fn, t_symbol *sel,
int nargs;
va_start(ap, arg1);
- /* "signal" method specifies that we take audio signals but
- that we don't want automatic float to signal conversion. This
- is obsolete; you should now use the CLASS_MAINSIGNALIN macro. */
+ /* "signal" method specifies that we take audio signals but
+ that we don't want automatic float to signal conversion. This
+ is obsolete; you should now use the CLASS_MAINSIGNALIN macro. */
if (sel == &s_signal)
{
- if (c->c_floatsignalin)
- post("warning: signal method overrides class_mainsignalin");
- c->c_floatsignalin = -1;
+ if (c->c_floatsignalin)
+ post("warning: signal method overrides class_mainsignalin");
+ c->c_floatsignalin = -1;
}
- /* check for special cases. "Pointer" is missing here so that
- pd_objectmaker's pointer method can be typechecked differently. */
+ /* check for special cases. "Pointer" is missing here so that
+ pd_objectmaker's pointer method can be typechecked differently. */
if (sel == &s_bang)
{
- if (argtype) goto phooey;
- class_addbang(c, fn);
+ if (argtype) goto phooey;
+ class_addbang(c, fn);
}
else if (sel == &s_float)
{
- if (argtype != A_FLOAT || va_arg(ap, t_atomtype)) goto phooey;
- class_doaddfloat(c, fn);
+ if (argtype != A_FLOAT || va_arg(ap, t_atomtype)) goto phooey;
+ class_doaddfloat(c, fn);
}
else if (sel == &s_symbol)
{
- if (argtype != A_SYMBOL || va_arg(ap, t_atomtype)) goto phooey;
- class_addsymbol(c, fn);
+ if (argtype != A_SYMBOL || va_arg(ap, t_atomtype)) goto phooey;
+ class_addsymbol(c, fn);
}
else if (sel == &s_list)
{
- if (argtype != A_GIMME) goto phooey;
- class_addlist(c, fn);
+ if (argtype != A_GIMME) goto phooey;
+ class_addlist(c, fn);
}
else if (sel == &s_anything)
{
- if (argtype != A_GIMME) goto phooey;
- class_addanything(c, fn);
+ if (argtype != A_GIMME) goto phooey;
+ class_addanything(c, fn);
}
else
{
- c->c_methods = t_resizebytes(c->c_methods,
- c->c_nmethod * sizeof(*c->c_methods),
- (c->c_nmethod + 1) * sizeof(*c->c_methods));
- m = c->c_methods + c->c_nmethod;
- c->c_nmethod++;
- m->me_name = sel;
- m->me_fun = (t_gotfn)fn;
- nargs = 0;
- while (argtype != A_NULL && nargs < MAXPDARG)
- {
- m->me_arg[nargs++] = argtype;
- argtype = va_arg(ap, t_atomtype);
- }
- if (argtype != A_NULL)
- error("%s_%s: only 5 arguments are typecheckable; use A_GIMME",
- c->c_name->s_name, sel->s_name);
- va_end(ap);
- m->me_arg[nargs] = A_NULL;
+ c->c_methods = t_resizebytes(c->c_methods,
+ c->c_nmethod * sizeof(*c->c_methods),
+ (c->c_nmethod + 1) * sizeof(*c->c_methods));
+ m = c->c_methods + c->c_nmethod;
+ c->c_nmethod++;
+ m->me_name = sel;
+ m->me_fun = (t_gotfn)fn;
+ nargs = 0;
+ while (argtype != A_NULL && nargs < MAXPDARG)
+ {
+ m->me_arg[nargs++] = argtype;
+ argtype = va_arg(ap, t_atomtype);
+ }
+ if (argtype != A_NULL)
+ error("%s_%s: only 5 arguments are typecheckable; use A_GIMME",
+ c->c_name->s_name, sel->s_name);
+ va_end(ap);
+ m->me_arg[nargs] = A_NULL;
}
return;
phooey:
bug("class_addmethod: %s_%s: bad argument types\n",
- c->c_name->s_name, sel->s_name);
+ c->c_name->s_name, sel->s_name);
}
/* Instead of these, see the "class_addfloat", etc., macros in m_pd.h */
@@ -392,10 +399,10 @@ static void pd_floatforsignal(t_pd *x, t_float f)
{
int offset = (*x)->c_floatsignalin;
if (offset > 0)
- *(t_sample *)(((char *)x) + offset) = f;
+ *(t_sample *)(((char *)x) + offset) = f;
else
- pd_error(x, "%s: float unexpected for signal input",
- (*x)->c_name->s_name);
+ pd_error(x, "%s: float unexpected for signal input",
+ (*x)->c_name->s_name);
}
void class_domainsignalin(t_class *c, int onset)
@@ -403,9 +410,9 @@ void class_domainsignalin(t_class *c, int onset)
if (onset <= 0) onset = -1;
else
{
- if (c->c_floatmethod != pd_defaultfloat)
- post("warning: %s: float method overwritten", c->c_name->s_name);
- c->c_floatmethod = (t_floatmethod)pd_floatforsignal;
+ if (c->c_floatmethod != pd_defaultfloat)
+ post("warning: %s: float method overwritten", c->c_name->s_name);
+ c->c_floatmethod = (t_floatmethod)pd_floatforsignal;
}
c->c_floatsignalin = onset;
}
@@ -459,25 +466,25 @@ t_symbol *dogensym(char *s, t_symbol *oldsym)
char *s2 = s;
while (*s2)
{
- hash1 += *s2;
- hash2 += hash1;
- length++;
- s2++;
+ hash1 += *s2;
+ hash2 += hash1;
+ length++;
+ s2++;
}
sym1 = symhash + (hash2 & (HASHSIZE-1));
while (sym2 = *sym1)
{
- if (!strcmp(sym2->s_name, s)) return(sym2);
- sym1 = &sym2->s_next;
+ if (!strcmp(sym2->s_name, s)) return(sym2);
+ sym1 = &sym2->s_next;
}
if (oldsym) sym2 = oldsym;
else
{
- sym2 = (t_symbol *)t_getbytes(sizeof(*sym2));
- sym2->s_name = t_getbytes(length+1);
- sym2->s_next = 0;
- sym2->s_thing = 0;
- strcpy(sym2->s_name, s);
+ sym2 = (t_symbol *)t_getbytes(sizeof(*sym2));
+ sym2->s_name = t_getbytes(length+1);
+ sym2->s_next = 0;
+ sym2->s_thing = 0;
+ strcpy(sym2->s_name, s);
}
*sym1 = sym2;
return (sym2);
@@ -507,7 +514,7 @@ t_symbol* pathsearch(t_symbol *s,char* ext);
int pd_setloadingabstraction(t_symbol *sym);
/* this routine is called when a new "object" is requested whose class Pd
- doesn't know. Pd tries to load it as an extern, then as an absteaction. */
+ doesn't know. Pd tries to load it as an extern, then as an abstraction. */
void new_anything(void *dummy, t_symbol *s, int argc, t_atom *argv)
{
t_pd *current;
@@ -519,42 +526,44 @@ void new_anything(void *dummy, t_symbol *s, int argc, t_atom *argv)
class_loadsym = s;
if (sys_load_lib(dir->s_name, s->s_name))
{
- tryingalready = 1;
- typedmess(dummy, s, argc, argv);
- tryingalready = 0;
- return;
+ tryingalready = 1;
+ typedmess(dummy, s, argc, argv);
+ tryingalready = 0;
+ return;
}
class_loadsym = 0;
current = s__X.s_thing;
if ((fd = open_via_path(dir->s_name, s->s_name, ".pd",
- dirbuf, &nameptr, MAXPDSTRING, 0)) >= 0)
+ dirbuf, &nameptr, MAXPDSTRING, 0)) >= 0 ||
+ (fd = open_via_path(dir->s_name, s->s_name, ".pat",
+ dirbuf, &nameptr, MAXPDSTRING, 0)) >= 0)
{
- close (fd);
- if (!pd_setloadingabstraction(s))
- {
- canvas_setargs(argc, argv); /* bug fix by Krzysztof Czaja */
- binbuf_evalfile(gensym(nameptr), gensym(dirbuf));
- if (s__X.s_thing != current)
- canvas_popabstraction((t_canvas *)(s__X.s_thing));
- canvas_setargs(0, 0);
- }
- else error("%s: can't load abstraction within itself\n", s->s_name);
+ close (fd);
+ if (!pd_setloadingabstraction(s))
+ {
+ canvas_setargs(argc, argv); /* bug fix by Krzysztof Czaja */
+ binbuf_evalfile(gensym(nameptr), gensym(dirbuf));
+ if (s__X.s_thing != current)
+ canvas_popabstraction((t_canvas *)(s__X.s_thing));
+ canvas_setargs(0, 0);
+ }
+ else error("%s: can't load abstraction within itself\n", s->s_name);
}
else newest = 0;
}
t_symbol s_pointer = {"pointer", 0, 0};
-t_symbol s_float = {"float", 0, 0};
+t_symbol s_float = {"float", 0, 0};
t_symbol s_symbol = {"symbol", 0, 0};
-t_symbol s_bang = {"bang", 0, 0};
-t_symbol s_list = {"list", 0, 0};
-t_symbol s_anything = {"anything", 0, 0};
-t_symbol s_signal = {"signal", 0, 0};
-t_symbol s__N = {"#N", 0, 0};
-t_symbol s__X = {"#X", 0, 0};
-t_symbol s_x = {"x", 0, 0};
-t_symbol s_y = {"y", 0, 0};
-t_symbol s_ = {"", 0, 0};
+t_symbol s_bang = {"bang", 0, 0};
+t_symbol s_list = {"list", 0, 0};
+t_symbol s_anything = {"anything", 0, 0};
+t_symbol s_signal = {"signal", 0, 0};
+t_symbol s__N = {"#N", 0, 0};
+t_symbol s__X = {"#X", 0, 0};
+t_symbol s_x = {"x", 0, 0};
+t_symbol s_y = {"y", 0, 0};
+t_symbol s_ = {"", 0, 0};
static t_symbol *symlist[] = { &s_pointer, &s_float, &s_symbol, &s_bang,
&s_list, &s_anything, &s_signal, &s__N, &s__X, &s_x, &s_y, &s_};
@@ -566,11 +575,11 @@ void mess_init(void)
if (pd_objectmaker) return;
for (i = sizeof(symlist)/sizeof(*symlist), sp = symlist; i--; sp++)
- (void) dogensym((*sp)->s_name, *sp);
+ (void) dogensym((*sp)->s_name, *sp);
pd_objectmaker = class_new(gensym("objectmaker"), 0, 0, sizeof(t_pd),
- CLASS_DEFAULT, A_NULL);
+ CLASS_DEFAULT, A_NULL);
pd_canvasmaker = class_new(gensym("classmaker"), 0, 0, sizeof(t_pd),
- CLASS_DEFAULT, A_NULL);
+ CLASS_DEFAULT, A_NULL);
pd_bind(&pd_canvasmaker, &s__N);
class_addanything(pd_objectmaker, (t_method)new_anything);
}
@@ -616,132 +625,132 @@ void pd_typedmess(t_pd *x, t_symbol *s, int argc, t_atom *argv)
int narg = 0;
t_pd *bonzo;
- /* check for messages that are handled by fixed slots in the class
- structure. We don't catch "pointer" though so that sending "pointer"
- to pd_objectmaker doesn't require that we supply a pointer value. */
+ /* check for messages that are handled by fixed slots in the class
+ structure. We don't catch "pointer" though so that sending "pointer"
+ to pd_objectmaker doesn't require that we supply a pointer value. */
if (s == &s_float)
{
- if (!argc) (*c->c_floatmethod)(x, 0.);
- else if (argv->a_type == A_FLOAT)
- (*c->c_floatmethod)(x, argv->a_w.w_float);
- else goto badarg;
- return;
+ if (!argc) (*c->c_floatmethod)(x, 0.);
+ else if (argv->a_type == A_FLOAT)
+ (*c->c_floatmethod)(x, argv->a_w.w_float);
+ else goto badarg;
+ return;
}
if (s == &s_bang)
{
- (*c->c_bangmethod)(x);
- return;
+ (*c->c_bangmethod)(x);
+ return;
}
if (s == &s_list)
{
- (*c->c_listmethod)(x, s, argc, argv);
- return;
+ (*c->c_listmethod)(x, s, argc, argv);
+ return;
}
if (s == &s_symbol)
{
- if (argc && argv->a_type == A_SYMBOL)
- (*c->c_symbolmethod)(x, argv->a_w.w_symbol);
- else
- (*c->c_symbolmethod)(x, &s_);
- return;
+ if (argc && argv->a_type == A_SYMBOL)
+ (*c->c_symbolmethod)(x, argv->a_w.w_symbol);
+ else
+ (*c->c_symbolmethod)(x, &s_);
+ return;
}
for (i = c->c_nmethod, m = c->c_methods; i--; m++)
- if (m->me_name == s)
+ if (m->me_name == s)
{
- wp = m->me_arg;
- if (*wp == A_GIMME)
- {
- if (x == &pd_objectmaker)
- newest = (*((t_newgimme)(m->me_fun)))(s, argc, argv);
- else (*((t_messgimme)(m->me_fun)))(x, s, argc, argv);
- return;
- }
- if (argc > MAXPDARG) argc = MAXPDARG;
- if (x != &pd_objectmaker) *(ap++) = (t_int)x, narg++;
- while (wanttype = *wp++)
- {
- switch (wanttype)
- {
- case A_POINTER:
- if (!argc) goto badarg;
- else
- {
- if (argv->a_type == A_POINTER)
- *ap = (t_int)(argv->a_w.w_gpointer);
- else goto badarg;
- argc--;
- argv++;
- }
- narg++;
- ap++;
- break;
- case A_FLOAT:
- if (!argc) goto badarg;
- case A_DEFFLOAT:
- if (!argc) *dp = 0;
- else
- {
- if (argv->a_type == A_FLOAT)
- *dp = argv->a_w.w_float;
- else goto badarg;
- argc--;
- argv++;
- }
- dp++;
- break;
- case A_SYMBOL:
- if (!argc) goto badarg;
- case A_DEFSYM:
- if (!argc) *ap = (t_int)(&s_);
- else
- {
- if (argv->a_type == A_SYMBOL)
- *ap = (t_int)(argv->a_w.w_symbol);
- /* if it's an unfilled "dollar" argument it appears
- as zero here; cheat and bash it to the null
- symbol. Unfortunately, this lets real zeros
- pass as symbols too, which seems wrong... */
- else if (x == &pd_objectmaker && argv->a_type == A_FLOAT
- && argv->a_w.w_float == 0)
- *ap = (t_int)(&s_);
- else goto badarg;
- argc--;
- argv++;
- }
- narg++;
- ap++;
- }
- }
- switch (narg)
- {
- case 0 : bonzo = (*(t_fun0)(m->me_fun))
- (ad[0], ad[1], ad[2], ad[3], ad[4]); break;
- case 1 : bonzo = (*(t_fun1)(m->me_fun))
- (ai[0], ad[0], ad[1], ad[2], ad[3], ad[4]); break;
- case 2 : bonzo = (*(t_fun2)(m->me_fun))
- (ai[0], ai[1], ad[0], ad[1], ad[2], ad[3], ad[4]); break;
- case 3 : bonzo = (*(t_fun3)(m->me_fun))
- (ai[0], ai[1], ai[2], ad[0], ad[1], ad[2], ad[3], ad[4]); break;
- case 4 : bonzo = (*(t_fun4)(m->me_fun))
- (ai[0], ai[1], ai[2], ai[3],
- ad[0], ad[1], ad[2], ad[3], ad[4]); break;
- case 5 : bonzo = (*(t_fun5)(m->me_fun))
- (ai[0], ai[1], ai[2], ai[3], ai[4],
- ad[0], ad[1], ad[2], ad[3], ad[4]); break;
- case 6 : bonzo = (*(t_fun6)(m->me_fun))
- (ai[0], ai[1], ai[2], ai[3], ai[4], ai[5],
- ad[0], ad[1], ad[2], ad[3], ad[4]); break;
- default: bonzo = 0;
- }
- if (x == &pd_objectmaker)
- newest = bonzo;
- return;
+ wp = m->me_arg;
+ if (*wp == A_GIMME)
+ {
+ if (x == &pd_objectmaker)
+ newest = (*((t_newgimme)(m->me_fun)))(s, argc, argv);
+ else (*((t_messgimme)(m->me_fun)))(x, s, argc, argv);
+ return;
+ }
+ if (argc > MAXPDARG) argc = MAXPDARG;
+ if (x != &pd_objectmaker) *(ap++) = (t_int)x, narg++;
+ while (wanttype = *wp++)
+ {
+ switch (wanttype)
+ {
+ case A_POINTER:
+ if (!argc) goto badarg;
+ else
+ {
+ if (argv->a_type == A_POINTER)
+ *ap = (t_int)(argv->a_w.w_gpointer);
+ else goto badarg;
+ argc--;
+ argv++;
+ }
+ narg++;
+ ap++;
+ break;
+ case A_FLOAT:
+ if (!argc) goto badarg;
+ case A_DEFFLOAT:
+ if (!argc) *dp = 0;
+ else
+ {
+ if (argv->a_type == A_FLOAT)
+ *dp = argv->a_w.w_float;
+ else goto badarg;
+ argc--;
+ argv++;
+ }
+ dp++;
+ break;
+ case A_SYMBOL:
+ if (!argc) goto badarg;
+ case A_DEFSYM:
+ if (!argc) *ap = (t_int)(&s_);
+ else
+ {
+ if (argv->a_type == A_SYMBOL)
+ *ap = (t_int)(argv->a_w.w_symbol);
+ /* if it's an unfilled "dollar" argument it appears
+ as zero here; cheat and bash it to the null
+ symbol. Unfortunately, this lets real zeros
+ pass as symbols too, which seems wrong... */
+ else if (x == &pd_objectmaker && argv->a_type == A_FLOAT
+ && argv->a_w.w_float == 0)
+ *ap = (t_int)(&s_);
+ else goto badarg;
+ argc--;
+ argv++;
+ }
+ narg++;
+ ap++;
+ }
+ }
+ switch (narg)
+ {
+ case 0 : bonzo = (*(t_fun0)(m->me_fun))
+ (ad[0], ad[1], ad[2], ad[3], ad[4]); break;
+ case 1 : bonzo = (*(t_fun1)(m->me_fun))
+ (ai[0], ad[0], ad[1], ad[2], ad[3], ad[4]); break;
+ case 2 : bonzo = (*(t_fun2)(m->me_fun))
+ (ai[0], ai[1], ad[0], ad[1], ad[2], ad[3], ad[4]); break;
+ case 3 : bonzo = (*(t_fun3)(m->me_fun))
+ (ai[0], ai[1], ai[2], ad[0], ad[1], ad[2], ad[3], ad[4]); break;
+ case 4 : bonzo = (*(t_fun4)(m->me_fun))
+ (ai[0], ai[1], ai[2], ai[3],
+ ad[0], ad[1], ad[2], ad[3], ad[4]); break;
+ case 5 : bonzo = (*(t_fun5)(m->me_fun))
+ (ai[0], ai[1], ai[2], ai[3], ai[4],
+ ad[0], ad[1], ad[2], ad[3], ad[4]); break;
+ case 6 : bonzo = (*(t_fun6)(m->me_fun))
+ (ai[0], ai[1], ai[2], ai[3], ai[4], ai[5],
+ ad[0], ad[1], ad[2], ad[3], ad[4]); break;
+ default: bonzo = 0;
+ }
+ if (x == &pd_objectmaker)
+ newest = bonzo;
+ return;
}
(*c->c_anymethod)(x, s, argc, argv);
return;
badarg:
pd_error(x, "Bad arguments for message '%s' to object '%s'",
- s->s_name, c->c_name->s_name);
+ s->s_name, c->c_name->s_name);
}
void pd_vmess(t_pd *x, t_symbol *sel, char *fmt, ...)
@@ -754,21 +763,21 @@ void pd_vmess(t_pd *x, t_symbol *sel, char *fmt, ...)
va_start(ap, fmt);
while (1)
{
- if (nargs > MAXPDARG)
- {
- pd_error(x, "pd_vmess: only %d allowed", MAXPDARG);
- break;
- }
- switch(*fp++)
- {
- case 'f': SETFLOAT(at, va_arg(ap, double)); break;
- case 's': SETSYMBOL(at, va_arg(ap, t_symbol *)); break;
- case 'i': SETFLOAT(at, va_arg(ap, t_int)); break;
- case 'p': SETPOINTER(at, va_arg(ap, t_gpointer *)); break;
- default: goto done;
- }
- at++;
- nargs++;
+ if (nargs > MAXPDARG)
+ {
+ pd_error(x, "pd_vmess: only %d allowed", MAXPDARG);
+ break;
+ }
+ switch(*fp++)
+ {
+ case 'f': SETFLOAT(at, va_arg(ap, double)); break;
+ case 's': SETSYMBOL(at, va_arg(ap, t_symbol *)); break;
+ case 'i': SETFLOAT(at, va_arg(ap, t_int)); break;
+ case 'p': SETPOINTER(at, va_arg(ap, t_gpointer *)); break;
+ default: goto done;
+ }
+ at++;
+ nargs++;
}
done:
va_end(ap);
@@ -779,19 +788,19 @@ void pd_forwardmess(t_pd *x, int argc, t_atom *argv)
{
if (argc)
{
- t_atomtype t = argv->a_type;
- if (t == A_SYMBOL) pd_typedmess(x, argv->a_w.w_symbol, argc-1, argv+1);
- else if (t == A_POINTER)
- {
- if (argc == 1) pd_pointer(x, argv->a_w.w_gpointer);
- else pd_list(x, &s_list, argc, argv);
- }
- else if (t == A_FLOAT)
- {
- if (argc == 1) pd_float(x, argv->a_w.w_float);
- else pd_list(x, &s_list, argc, argv);
- }
- else bug("pd_forwardmess");
+ t_atomtype t = argv->a_type;
+ if (t == A_SYMBOL) pd_typedmess(x, argv->a_w.w_symbol, argc-1, argv+1);
+ else if (t == A_POINTER)
+ {
+ if (argc == 1) pd_pointer(x, argv->a_w.w_gpointer);
+ else pd_list(x, &s_list, argc, argv);
+ }
+ else if (t == A_FLOAT)
+ {
+ if (argc == 1) pd_float(x, argv->a_w.w_float);
+ else pd_list(x, &s_list, argc, argv);
+ }
+ else bug("pd_forwardmess");
}
}
@@ -805,7 +814,7 @@ t_gotfn getfn(t_pd *x, t_symbol *s)
int i;
for (i = c->c_nmethod, m = c->c_methods; i--; m++)
- if (m->me_name == s) return(m->me_fun);
+ if (m->me_name == s) return(m->me_fun);
pd_error(x, "%s: no method for message '%s'", c->c_name->s_name, s->s_name);
return((t_gotfn)nullfn);
}
@@ -817,6 +826,6 @@ t_gotfn zgetfn(t_pd *x, t_symbol *s)
int i;
for (i = c->c_nmethod, m = c->c_methods; i--; m++)
- if (m->me_name == s) return(m->me_fun);
+ if (m->me_name == s) return(m->me_fun);
return(0);
}
diff --git a/pd/src/m_glob.c b/pd/src/m_glob.c
index 6c91feef..12cfb9b6 100644
--- a/pd/src/m_glob.c
+++ b/pd/src/m_glob.c
@@ -25,7 +25,11 @@ void glob_midi_properties(t_pd *dummy, t_floatarg flongform);
void glob_midi_dialog(t_pd *dummy, t_symbol *s, int argc, t_atom *argv);
void glob_start_path_dialog(t_pd *dummy, t_floatarg flongform);
void glob_path_dialog(t_pd *dummy, t_symbol *s, int argc, t_atom *argv);
+void glob_start_startup_dialog(t_pd *dummy, t_floatarg flongform);
+void glob_startup_dialog(t_pd *dummy, t_symbol *s, int argc, t_atom *argv);
void glob_ping(t_pd *dummy);
+void glob_watchdog(t_pd *dummy);
+void glob_savepreferences(t_pd *dummy);
void alsa_resync( void);
@@ -49,11 +53,11 @@ void max_default(t_pd *x, t_symbol *s, int argc, t_atom *argv)
int i;
char str[80];
startpost("%s: unknown message %s ", class_getname(pd_class(x)),
- s->s_name);
+ s->s_name);
for (i = 0; i < argc; i++)
{
- atom_string(argv+i, str, 80);
- poststring(str);
+ atom_string(argv+i, str, 80);
+ poststring(str);
}
endpost();
}
@@ -61,44 +65,52 @@ void max_default(t_pd *x, t_symbol *s, int argc, t_atom *argv)
void glob_init(void)
{
maxclass = class_new(gensym("max"), 0, 0, sizeof(t_pd),
- CLASS_DEFAULT, A_NULL);
+ CLASS_DEFAULT, A_NULL);
class_addanything(maxclass, max_default);
pd_bind(&maxclass, gensym("max"));
glob_pdobject = class_new(gensym("pd"), 0, 0, sizeof(t_pd),
- CLASS_DEFAULT, A_NULL);
+ CLASS_DEFAULT, A_NULL);
class_addmethod(glob_pdobject, (t_method)glob_initfromgui, gensym("init"),
- A_GIMME, 0);
+ A_GIMME, 0);
class_addmethod(glob_pdobject, (t_method)glob_setfilename, gensym("filename"),
- A_SYMBOL, A_SYMBOL, 0);
+ A_SYMBOL, A_SYMBOL, 0);
class_addmethod(glob_pdobject, (t_method)glob_evalfile, gensym("open"),
- A_SYMBOL, A_SYMBOL, 0);
+ A_SYMBOL, A_SYMBOL, 0);
class_addmethod(glob_pdobject, (t_method)glob_quit, gensym("quit"), 0);
class_addmethod(glob_pdobject, (t_method)glob_foo, gensym("foo"), A_GIMME, 0);
class_addmethod(glob_pdobject, (t_method)glob_dsp, gensym("dsp"), A_GIMME, 0);
class_addmethod(glob_pdobject, (t_method)glob_meters, gensym("meters"),
- A_FLOAT, 0);
+ A_FLOAT, 0);
class_addmethod(glob_pdobject, (t_method)glob_key, gensym("key"), A_GIMME, 0);
class_addmethod(glob_pdobject, (t_method)glob_audiostatus,
- gensym("audiostatus"), 0);
+ gensym("audiostatus"), 0);
class_addmethod(glob_pdobject, (t_method)glob_finderror,
- gensym("finderror"), 0);
+ gensym("finderror"), 0);
class_addmethod(glob_pdobject, (t_method)glob_audio_properties,
- gensym("audio-properties"), A_DEFFLOAT, 0);
+ gensym("audio-properties"), A_DEFFLOAT, 0);
class_addmethod(glob_pdobject, (t_method)glob_audio_dialog,
- gensym("audio-dialog"), A_GIMME, 0);
+ gensym("audio-dialog"), A_GIMME, 0);
class_addmethod(glob_pdobject, (t_method)glob_audio_setapi,
- gensym("audio-setapi"), A_FLOAT, 0);
+ gensym("audio-setapi"), A_FLOAT, 0);
class_addmethod(glob_pdobject, (t_method)glob_midi_properties,
- gensym("midi-properties"), A_DEFFLOAT, 0);
+ gensym("midi-properties"), A_DEFFLOAT, 0);
class_addmethod(glob_pdobject, (t_method)glob_midi_dialog,
- gensym("midi-dialog"), A_GIMME, 0);
+ gensym("midi-dialog"), A_GIMME, 0);
class_addmethod(glob_pdobject, (t_method)glob_start_path_dialog,
- gensym("start-path-dialog"), A_DEFFLOAT, 0);
+ gensym("start-path-dialog"), 0);
class_addmethod(glob_pdobject, (t_method)glob_path_dialog,
- gensym("path-dialog"), A_GIMME, 0);
-#ifdef __linux__
+ gensym("path-dialog"), A_GIMME, 0);
+ class_addmethod(glob_pdobject, (t_method)glob_start_startup_dialog,
+ gensym("start-startup-dialog"), 0);
+ class_addmethod(glob_pdobject, (t_method)glob_startup_dialog,
+ gensym("startup-dialog"), A_GIMME, 0);
class_addmethod(glob_pdobject, (t_method)glob_ping, gensym("ping"), 0);
+ class_addmethod(glob_pdobject, (t_method)glob_savepreferences,
+ gensym("save-preferences"), 0);
+#ifdef UNIX
+ class_addmethod(glob_pdobject, (t_method)glob_watchdog,
+ gensym("watchdog"), 0);
#endif
class_addanything(glob_pdobject, max_default);
pd_bind(&glob_pdobject, gensym("pd"));
diff --git a/pd/src/m_imp.h b/pd/src/m_imp.h
index f6724f9c..e82d103a 100644
--- a/pd/src/m_imp.h
+++ b/pd/src/m_imp.h
@@ -9,6 +9,7 @@ Pd, but not shared with Pd objects. */
in future releases. The public (stable) API is in m_pd.h. */
/* LATER consider whether to use 'char' for method arg types to save space */
+#ifndef __m_imp_h_
/* the structure for a method handler ala Max */
typedef struct _methodentry
@@ -29,28 +30,28 @@ typedef void (*t_anymethod)(t_pd *x, t_symbol *s, int argc, t_atom *argv);
struct _class
{
- t_symbol *c_name; /* name (mostly for error reporting) */
- t_symbol *c_helpname; /* name of help file */
- t_symbol *c_externdir; /* directory extern was loaded from */
- size_t c_size; /* size of an instance */
- t_methodentry *c_methods; /* methods other than bang, etc below */
- int c_nmethod; /* number of methods */
- t_method c_freemethod; /* function to call before freeing */
- t_bangmethod c_bangmethod; /* common methods */
+ t_symbol *c_name; /* name (mostly for error reporting) */
+ t_symbol *c_helpname; /* name of help file */
+ t_symbol *c_externdir; /* directory extern was loaded from */
+ size_t c_size; /* size of an instance */
+ t_methodentry *c_methods; /* methods other than bang, etc below */
+ int c_nmethod; /* number of methods */
+ t_method c_freemethod; /* function to call before freeing */
+ t_bangmethod c_bangmethod; /* common methods */
t_pointermethod c_pointermethod;
t_floatmethod c_floatmethod;
t_symbolmethod c_symbolmethod;
t_listmethod c_listmethod;
t_anymethod c_anymethod;
- struct _widgetbehavior *c_wb; /* "gobjs" only */
+ struct _widgetbehavior *c_wb; /* "gobjs" only */
struct _parentwidgetbehavior *c_pwb;/* widget behavior in parent */
- t_savefn c_savefn; /* function to call when saving */
- t_propertiesfn c_propertiesfn; /* function to start prop dialog */
- int c_floatsignalin; /* onset to float for signal input */
- char c_gobj; /* true if is a gobj */
- char c_patchable; /* true if we have a t_object header */
- char c_firstin; /* if patchable, true if draw first inlet */
- char c_drawcommand; /* a drawing command for a template */
+ t_savefn c_savefn; /* function to call when saving */
+ t_propertiesfn c_propertiesfn; /* function to start prop dialog */
+ int c_floatsignalin; /* onset to float for signal input */
+ char c_gobj; /* true if is a gobj */
+ char c_patchable; /* true if we have a t_object header */
+ char c_firstin; /* if patchable, true if draw first inlet */
+ char c_drawcommand; /* a drawing command for a template */
};
@@ -76,3 +77,6 @@ EXTERN int obj_sigoutletindex(t_object *x, int m);
/* misc */
EXTERN void glob_evalfile(t_pd *ignore, t_symbol *name, t_symbol *dir);
EXTERN void glob_initfromgui(void *dummy, t_symbol *s, int argc, t_atom *argv);
+
+#define __m_imp_h_
+#endif /* __m_imp_h_ */
diff --git a/pd/src/m_memory.c b/pd/src/m_memory.c
index bb5d79c6..f598e4f8 100644
--- a/pd/src/m_memory.c
+++ b/pd/src/m_memory.c
@@ -23,17 +23,17 @@ void *getbytes(size_t nbytes)
if (nbytes < 1) nbytes = 1;
ret = (void *)calloc(nbytes, 1);
#ifdef LOUD
- fprintf(stderr, "new %x %d\n", (int)ret, nbytes);
+ fprintf(stderr, "new %lx %d\n", (int)ret, nbytes);
#endif /* LOUD */
#ifdef DEBUGMEM
totalmem += nbytes;
#endif
if (!ret)
- post("pd: getbytes() failed -- out of memory");
+ post("pd: getbytes() failed -- out of memory");
return (ret);
}
-void *getzbytes(size_t nbytes) /* obsolete name */
+void *getzbytes(size_t nbytes) /* obsolete name */
{
return (getbytes(nbytes));
}
@@ -43,7 +43,7 @@ void *copybytes(void *src, size_t nbytes)
void *ret;
ret = getbytes(nbytes);
if (nbytes)
- memcpy(ret, src, nbytes);
+ memcpy(ret, src, nbytes);
return (ret);
}
@@ -54,24 +54,24 @@ void *resizebytes(void *old, size_t oldsize, size_t newsize)
if (oldsize < 1) oldsize = 1;
ret = (void *)realloc((char *)old, newsize);
if (newsize > oldsize && ret)
- memset(((char *)ret) + oldsize, 0, newsize - oldsize);
+ memset(((char *)ret) + oldsize, 0, newsize - oldsize);
#ifdef LOUD
- fprintf(stderr, "resize %x %d --> %x %d\n", (int)old, oldsize, (int)ret, newsize);
+ fprintf(stderr, "resize %lx %d --> %lx %d\n", (int)old, oldsize, (int)ret, newsize);
#endif /* LOUD */
#ifdef DEBUGMEM
totalmem += (newsize - oldsize);
#endif
if (!ret)
- post("pd: resizebytes() failed -- out of memory");
+ post("pd: resizebytes() failed -- out of memory");
return (ret);
}
void freebytes(void *fatso, size_t nbytes)
{
if (nbytes == 0)
- nbytes = 1;
+ nbytes = 1;
#ifdef LOUD
- fprintf(stderr, "free %x %d\n", (int)fatso, nbytes);
+ fprintf(stderr, "free %lx %d\n", (int)fatso, nbytes);
#endif /* LOUD */
#ifdef DEBUGMEM
totalmem -= nbytes;
diff --git a/pd/src/m_obj.c b/pd/src/m_obj.c
index e1f0f54a..611c7d7c 100644
--- a/pd/src/m_obj.c
+++ b/pd/src/m_obj.c
@@ -9,6 +9,10 @@ behavior for "gobjs" appears at the end of this file. */
#include "m_pd.h"
#include "m_imp.h"
+/* T.Grill - define for a modified, more portable method to detect stack overflows */
+#define NEWSTACKMETH
+
+
union inletunion
{
t_symbol *iu_symto;
@@ -49,14 +53,14 @@ t_inlet *inlet_new(t_object *owner, t_pd *dest, t_symbol *s1, t_symbol *s2)
x->i_owner = owner;
x->i_dest = dest;
if (s1 == &s_signal)
- x->i_un.iu_floatsignalvalue = 0;
+ x->i_un.iu_floatsignalvalue = 0;
else x->i_symto = s2;
x->i_symfrom = s1;
x->i_next = 0;
if (y = owner->ob_inlet)
{
- while (y2 = y->i_next) y = y2;
- y->i_next = x;
+ while (y2 = y->i_next) y = y2;
+ y->i_next = x;
}
else owner->ob_inlet = x;
return (x);
@@ -65,14 +69,14 @@ t_inlet *inlet_new(t_object *owner, t_pd *dest, t_symbol *s1, t_symbol *s2)
static void inlet_wrong(t_inlet *x, t_symbol *s)
{
pd_error(x->i_owner, "inlet: expected '%s' but got '%s'",
- x->i_symfrom->s_name, s->s_name);
+ x->i_symfrom->s_name, s->s_name);
}
/* LATER figure out how to make these efficient: */
static void inlet_bang(t_inlet *x)
{
if (x->i_symfrom == &s_bang)
- pd_vmess(x->i_dest, x->i_symto, "");
+ pd_vmess(x->i_dest, x->i_symto, "");
else if (!x->i_symfrom) pd_bang(x->i_dest);
else inlet_wrong(x, &s_bang);
}
@@ -80,7 +84,7 @@ static void inlet_bang(t_inlet *x)
static void inlet_pointer(t_inlet *x, t_gpointer *gp)
{
if (x->i_symfrom == &s_pointer)
- pd_vmess(x->i_dest, x->i_symto, "p", gp);
+ pd_vmess(x->i_dest, x->i_symto, "p", gp);
else if (!x->i_symfrom) pd_pointer(x->i_dest, gp);
else inlet_wrong(x, &s_pointer);
}
@@ -88,18 +92,18 @@ static void inlet_pointer(t_inlet *x, t_gpointer *gp)
static void inlet_float(t_inlet *x, t_float f)
{
if (x->i_symfrom == &s_float)
- pd_vmess(x->i_dest, x->i_symto, "f", (t_floatarg)f);
+ pd_vmess(x->i_dest, x->i_symto, "f", (t_floatarg)f);
else if (x->i_symfrom == &s_signal)
- x->i_un.iu_floatsignalvalue = f;
+ x->i_un.iu_floatsignalvalue = f;
else if (!x->i_symfrom)
- pd_float(x->i_dest, f);
+ pd_float(x->i_dest, f);
else inlet_wrong(x, &s_float);
}
static void inlet_symbol(t_inlet *x, t_symbol *s)
{
if (x->i_symfrom == &s_symbol)
- pd_vmess(x->i_dest, x->i_symto, "s", s);
+ pd_vmess(x->i_dest, x->i_symto, "s", s);
else if (!x->i_symfrom) pd_symbol(x->i_dest, s);
else inlet_wrong(x, &s_symbol);
}
@@ -108,8 +112,8 @@ static void inlet_list(t_inlet *x, t_symbol *s, int argc, t_atom *argv)
{
t_atom at;
if (x->i_symfrom == &s_list || x->i_symfrom == &s_float
- || x->i_symfrom == &s_symbol || x->i_symfrom == &s_pointer)
- typedmess(x->i_dest, x->i_symto, argc, argv);
+ || x->i_symfrom == &s_symbol || x->i_symfrom == &s_pointer)
+ typedmess(x->i_dest, x->i_symto, argc, argv);
else if (!x->i_symfrom) pd_list(x->i_dest, s, argc, argv);
else inlet_wrong(x, &s_list);
}
@@ -117,9 +121,9 @@ static void inlet_list(t_inlet *x, t_symbol *s, int argc, t_atom *argv)
static void inlet_anything(t_inlet *x, t_symbol *s, int argc, t_atom *argv)
{
if (x->i_symfrom == s)
- typedmess(x->i_dest, x->i_symto, argc, argv);
+ typedmess(x->i_dest, x->i_symto, argc, argv);
else if (!x->i_symfrom)
- typedmess(x->i_dest, s, argc, argv);
+ typedmess(x->i_dest, s, argc, argv);
else inlet_wrong(x, s);
}
@@ -129,10 +133,10 @@ void inlet_free(t_inlet *x)
t_inlet *x2;
if (y->ob_inlet == x) y->ob_inlet = x->i_next;
else for (x2 = y->ob_inlet; x2; x2 = x2->i_next)
- if (x2->i_next == x)
+ if (x2->i_next == x)
{
- x2->i_next = x->i_next;
- break;
+ x2->i_next = x->i_next;
+ break;
}
t_freebytes(x, sizeof(*x));
}
@@ -156,8 +160,8 @@ t_inlet *pointerinlet_new(t_object *owner, t_gpointer *gp)
x->i_next = 0;
if (y = owner->ob_inlet)
{
- while (y2 = y->i_next) y = y2;
- y->i_next = x;
+ while (y2 = y->i_next) y = y2;
+ y->i_next = x;
}
else owner->ob_inlet = x;
return (x);
@@ -178,8 +182,8 @@ t_inlet *floatinlet_new(t_object *owner, t_float *fp)
x->i_next = 0;
if (y = owner->ob_inlet)
{
- while (y2 = y->i_next) y = y2;
- y->i_next = x;
+ while (y2 = y->i_next) y = y2;
+ y->i_next = x;
}
else owner->ob_inlet = x;
return (x);
@@ -200,8 +204,8 @@ t_inlet *symbolinlet_new(t_object *owner, t_symbol **sp)
x->i_next = 0;
if (y = owner->ob_inlet)
{
- while (y2 = y->i_next) y = y2;
- y->i_next = x;
+ while (y2 = y->i_next) y = y2;
+ y->i_next = x;
}
else owner->ob_inlet = x;
return (x);
@@ -220,9 +224,9 @@ void obj_list(t_object *x, t_symbol *s, int argc, t_atom *argv)
if (!argc) return;
for (count = argc-1, ap = argv+1; ip && count--; ap++, ip = ip->i_next)
{
- if (ap->a_type == A_POINTER) pd_pointer(&ip->i_pd, ap->a_w.w_gpointer);
- else if (ap->a_type == A_FLOAT) pd_float(&ip->i_pd, ap->a_w.w_float);
- else pd_symbol(&ip->i_pd, ap->a_w.w_symbol);
+ if (ap->a_type == A_POINTER) pd_pointer(&ip->i_pd, ap->a_w.w_gpointer);
+ else if (ap->a_type == A_FLOAT) pd_float(&ip->i_pd, ap->a_w.w_float);
+ else pd_symbol(&ip->i_pd, ap->a_w.w_symbol);
}
if (argv->a_type == A_POINTER) pd_pointer(&x->ob_pd, argv->a_w.w_gpointer);
else if (argv->a_type == A_FLOAT) pd_float(&x->ob_pd, argv->a_w.w_float);
@@ -232,7 +236,7 @@ void obj_list(t_object *x, t_symbol *s, int argc, t_atom *argv)
void obj_init(void)
{
inlet_class = class_new(gensym("inlet"), 0, 0,
- sizeof(t_inlet), CLASS_PD, 0);
+ sizeof(t_inlet), CLASS_PD, 0);
class_addbang(inlet_class, inlet_bang);
class_addpointer(inlet_class, inlet_pointer);
class_addfloat(inlet_class, inlet_float);
@@ -241,33 +245,43 @@ void obj_init(void)
class_addanything(inlet_class, inlet_anything);
pointerinlet_class = class_new(gensym("inlet"), 0, 0,
- sizeof(t_inlet), CLASS_PD, 0);
+ sizeof(t_inlet), CLASS_PD, 0);
class_addpointer(pointerinlet_class, pointerinlet_pointer);
floatinlet_class = class_new(gensym("inlet"), 0, 0,
- sizeof(t_inlet), CLASS_PD, 0);
+ sizeof(t_inlet), CLASS_PD, 0);
class_addfloat(floatinlet_class, (t_method)floatinlet_float);
symbolinlet_class = class_new(gensym("inlet"), 0, 0,
- sizeof(t_inlet), CLASS_PD, 0);
+ sizeof(t_inlet), CLASS_PD, 0);
class_addsymbol(symbolinlet_class, symbolinlet_symbol);
}
/* --------------------------- outlets ------------------------------ */
+#ifdef NEWSTACKMETH
+/* T.Grill - count iterations rather than watch the stack pointer */
+static int stackcount = 0; /* iteration counter */
+#define STACKITER 1000 /* maximum iterations allowed */
+#else
static char *stacklimit, *topstack;
#define STACKSIZE 1000000
+#endif
+
static int outlet_eventno;
/* set a stack limit (on each incoming event that can set off messages)
for the outlet functions to check to prevent stack overflow from message
recursion */
+
void outlet_setstacklim(void)
{
+#ifndef NEWSTACKMETH
char c;
topstack = &c;
stacklimit = (&c) - STACKSIZE;
+#endif
outlet_eventno++;
}
@@ -298,8 +312,8 @@ t_outlet *outlet_new(t_object *owner, t_symbol *s)
x->o_next = 0;
if (y = owner->ob_outlet)
{
- while (y2 = y->o_next) y = y2;
- y->o_next = x;
+ while (y2 = y->o_next) y = y2;
+ y->o_next = x;
}
else owner->ob_outlet = x;
x->o_connections = 0;
@@ -310,79 +324,128 @@ t_outlet *outlet_new(t_object *owner, t_symbol *s)
static void outlet_stackerror(t_outlet *x)
{
pd_error(x->o_owner, "stack overflow");
+#ifndef NEWSTACKMETH
stacklimit = topstack;
+#endif
}
void outlet_bang(t_outlet *x)
{
t_outconnect *oc;
- char c;
+#ifdef NEWSTACKMETH
+ if(++stackcount >= STACKITER)
+#else
+ char c;
if (&c < stacklimit)
- outlet_stackerror(x);
- else for (oc = x->o_connections; oc; oc = oc->oc_next)
- pd_bang(oc->oc_to);
+#endif
+ outlet_stackerror(x);
+ else
+ for (oc = x->o_connections; oc; oc = oc->oc_next)
+ pd_bang(oc->oc_to);
+#ifdef NEWSTACKMETH
+ --stackcount;
+#endif
}
void outlet_pointer(t_outlet *x, t_gpointer *gp)
{
t_outconnect *oc;
t_gpointer gpointer;
- char c;
+#ifdef NEWSTACKMETH
+ if(++stackcount >= STACKITER)
+#else
+ char c;
if (&c < stacklimit)
- outlet_stackerror(x);
+#endif
+ outlet_stackerror(x);
else
{
#if 0
- gpointer_copy(gp, &gpointer);
- for (oc = x->o_connections; oc; oc = oc->oc_next)
- pd_pointer(oc->oc_to, &gpointer);
- gpointer_unset(&gpointer);
+ gpointer_copy(gp, &gpointer);
+ for (oc = x->o_connections; oc; oc = oc->oc_next)
+ pd_pointer(oc->oc_to, &gpointer);
+ gpointer_unset(&gpointer);
#else
- gpointer = *gp;
- for (oc = x->o_connections; oc; oc = oc->oc_next)
- pd_pointer(oc->oc_to, &gpointer);
+ gpointer = *gp;
+ for (oc = x->o_connections; oc; oc = oc->oc_next)
+ pd_pointer(oc->oc_to, &gpointer);
#endif
}
+#ifdef NEWSTACKMETH
+ --stackcount;
+#endif
}
void outlet_float(t_outlet *x, t_float f)
{
t_outconnect *oc;
- char c;
+#ifdef NEWSTACKMETH
+ if(++stackcount >= STACKITER)
+#else
+ char c;
if (&c < stacklimit)
- outlet_stackerror(x);
- else for (oc = x->o_connections; oc; oc = oc->oc_next)
- pd_float(oc->oc_to, f);
+#endif
+ outlet_stackerror(x);
+ else
+ for (oc = x->o_connections; oc; oc = oc->oc_next)
+ pd_float(oc->oc_to, f);
+#ifdef NEWSTACKMETH
+ --stackcount;
+#endif
}
void outlet_symbol(t_outlet *x, t_symbol *s)
{
t_outconnect *oc;
- char c;
+#ifdef NEWSTACKMETH
+ if(++stackcount >= STACKITER)
+#else
+ char c;
if (&c < stacklimit)
- outlet_stackerror(x);
- else for (oc = x->o_connections; oc; oc = oc->oc_next)
- pd_symbol(oc->oc_to, s);
+#endif
+ outlet_stackerror(x);
+ else
+ for (oc = x->o_connections; oc; oc = oc->oc_next)
+ pd_symbol(oc->oc_to, s);
+#ifdef NEWSTACKMETH
+ --stackcount;
+#endif
}
void outlet_list(t_outlet *x, t_symbol *s, int argc, t_atom *argv)
{
t_outconnect *oc;
- char c;
+#ifdef NEWSTACKMETH
+ if(++stackcount >= STACKITER)
+#else
+ char c;
if (&c < stacklimit)
- outlet_stackerror(x);
- else for (oc = x->o_connections; oc; oc = oc->oc_next)
- pd_list(oc->oc_to, s, argc, argv);
+#endif
+ outlet_stackerror(x);
+ else
+ for (oc = x->o_connections; oc; oc = oc->oc_next)
+ pd_list(oc->oc_to, s, argc, argv);
+#ifdef NEWSTACKMETH
+ --stackcount;
+#endif
}
void outlet_anything(t_outlet *x, t_symbol *s, int argc, t_atom *argv)
{
t_outconnect *oc;
- char c;
+#ifdef NEWSTACKMETH
+ if(++stackcount >= STACKITER)
+#else
+ char c;
if (&c < stacklimit)
- outlet_stackerror(x);
- else for (oc = x->o_connections; oc; oc = oc->oc_next)
- typedmess(oc->oc_to, s, argc, argv);
+#endif
+ outlet_stackerror(x);
+ else
+ for (oc = x->o_connections; oc; oc = oc->oc_next)
+ typedmess(oc->oc_to, s, argc, argv);
+#ifdef NEWSTACKMETH
+ --stackcount;
+#endif
}
/* get the outlet's declared symbol */
@@ -397,10 +460,10 @@ void outlet_free(t_outlet *x)
t_outlet *x2;
if (y->ob_outlet == x) y->ob_outlet = x->o_next;
else for (x2 = y->ob_outlet; x2; x2 = x2->o_next)
- if (x2->o_next == x)
+ if (x2->o_next == x)
{
- x2->o_next = x->o_next;
- break;
+ x2->o_next = x->o_next;
+ break;
}
t_freebytes(x, sizeof(*x));
}
@@ -418,12 +481,12 @@ t_outconnect *obj_connect(t_object *source, int outno,
if (sink->ob_pd->c_firstin)
{
- if (!inno)
- {
- to = &sink->ob_pd;
- goto doit;
- }
- else inno--;
+ if (!inno)
+ {
+ to = &sink->ob_pd;
+ goto doit;
+ }
+ else inno--;
}
for (i = sink->ob_inlet; i && inno; i = i->i_next, inno--) ;
if (!i) return (0);
@@ -432,12 +495,12 @@ doit:
oc = (t_outconnect *)t_getbytes(sizeof(*oc));
oc->oc_next = 0;
oc->oc_to = to;
- /* append it to the end of the list */
- /* LATER we might cache the last "oc" to make this faster. */
+ /* append it to the end of the list */
+ /* LATER we might cache the last "oc" to make this faster. */
if ((oc2 = o->o_connections))
{
- while (oc2->oc_next) oc2 = oc2->oc_next;
- oc2->oc_next = oc;
+ while (oc2->oc_next) oc2 = oc2->oc_next;
+ oc2->oc_next = oc;
}
else o->o_connections = oc;
if (o->o_sym == &s_signal) canvas_update_dsp();
@@ -456,12 +519,12 @@ void obj_disconnect(t_object *source, int outno, t_object *sink, int inno)
if (!o) return;
if (sink->ob_pd->c_firstin)
{
- if (!inno)
- {
- to = &sink->ob_pd;
- goto doit;
- }
- else inno--;
+ if (!inno)
+ {
+ to = &sink->ob_pd;
+ goto doit;
+ }
+ else inno--;
}
for (i = sink->ob_inlet; i && inno; i = i->i_next, inno--) ;
if (!i) return;
@@ -470,19 +533,19 @@ doit:
if (!(oc = o->o_connections)) return;
if (oc->oc_to == to)
{
- o->o_connections = oc->oc_next;
- freebytes(oc, sizeof(*oc));
- goto done;
+ o->o_connections = oc->oc_next;
+ freebytes(oc, sizeof(*oc));
+ goto done;
}
while (oc2 = oc->oc_next)
{
- if (oc2->oc_to == to)
- {
- oc->oc_next = oc2->oc_next;
- freebytes(oc2, sizeof(*oc2));
- goto done;
- }
- oc = oc2;
+ if (oc2->oc_to == to)
+ {
+ oc->oc_next = oc2->oc_next;
+ freebytes(oc2, sizeof(*oc2));
+ goto done;
+ }
+ oc = oc2;
}
done:
if (o->o_sym == &s_signal) canvas_update_dsp();
@@ -523,20 +586,20 @@ t_outconnect *obj_nexttraverseoutlet(t_outconnect *lastconnect,
y = lastconnect->oc_to;
if (ISINLET(y))
{
- int n;
- t_inlet *i = (t_inlet *)y, *i2;
- t_object *dest = i->i_owner;
- for (n = dest->ob_pd->c_firstin, i2 = dest->ob_inlet;
- i2 && i2 != i; i2 = i2->i_next) n++;
- *whichp = n;
- *destp = dest;
- *inletp = i;
+ int n;
+ t_inlet *i = (t_inlet *)y, *i2;
+ t_object *dest = i->i_owner;
+ for (n = dest->ob_pd->c_firstin, i2 = dest->ob_inlet;
+ i2 && i2 != i; i2 = i2->i_next) n++;
+ *whichp = n;
+ *destp = dest;
+ *inletp = i;
}
else
{
- *whichp = 0;
- *inletp = 0;
- *destp = ((t_object *)y);
+ *whichp = 0;
+ *inletp = 0;
+ *destp = ((t_object *)y);
}
return (lastconnect->oc_next);
}
@@ -555,12 +618,12 @@ void obj_moveinletfirst(t_object *x, t_inlet *i)
t_inlet *i2;
if (x->ob_inlet == i) return;
else for (i2 = x->ob_inlet; i2; i2 = i2->i_next)
- if (i2->i_next == i)
+ if (i2->i_next == i)
{
- i2->i_next = i->i_next;
- i->i_next = x->ob_inlet;
- x->ob_inlet = i;
- return;
+ i2->i_next = i->i_next;
+ i->i_next = x->ob_inlet;
+ x->ob_inlet = i;
+ return;
}
}
@@ -569,12 +632,12 @@ void obj_moveoutletfirst(t_object *x, t_outlet *o)
t_outlet *o2;
if (x->ob_outlet == o) return;
else for (o2 = x->ob_outlet; o2; o2 = o2->o_next)
- if (o2->o_next == o)
+ if (o2->o_next == o)
{
- o2->o_next = o->o_next;
- o->o_next = x->ob_outlet;
- x->ob_outlet = o;
- return;
+ o2->o_next = o->o_next;
+ o->o_next = x->ob_outlet;
+ x->ob_outlet = o;
+ return;
}
}
@@ -586,7 +649,7 @@ int obj_nsiginlets(t_object *x)
int n;
t_inlet *i;
for (i = x->ob_inlet, n = 0; i; i = i->i_next)
- if (i->i_symfrom == &s_signal) n++;
+ if (i->i_symfrom == &s_signal) n++;
if (x->ob_pd->c_firstin && x->ob_pd->c_floatsignalin) n++;
return (n);
}
@@ -598,14 +661,14 @@ int obj_siginletindex(t_object *x, int m)
t_inlet *i;
if (x->ob_pd->c_firstin && x->ob_pd->c_floatsignalin)
{
- if (!m--) return (0);
- n++;
+ if (!m--) return (0);
+ n++;
}
for (i = x->ob_inlet; i; i = i->i_next, m--)
- if (i->i_symfrom == &s_signal)
+ if (i->i_symfrom == &s_signal)
{
- if (m == 0) return (n);
- n++;
+ if (m == 0) return (n);
+ n++;
}
return (-1);
}
@@ -615,12 +678,12 @@ int obj_issignalinlet(t_object *x, int m)
t_inlet *i;
if (x->ob_pd->c_firstin)
{
- if (!m)
- return (x->ob_pd->c_firstin && x->ob_pd->c_floatsignalin);
- else m--;
+ if (!m)
+ return (x->ob_pd->c_firstin && x->ob_pd->c_floatsignalin);
+ else m--;
}
for (i = x->ob_inlet; i && m; i = i->i_next, m--)
- ;
+ ;
return (i && (i->i_symfrom == &s_signal));
}
@@ -629,7 +692,7 @@ int obj_nsigoutlets(t_object *x)
int n;
t_outlet *o;
for (o = x->ob_outlet, n = 0; o; o = o->o_next)
- if (o->o_sym == &s_signal) n++;
+ if (o->o_sym == &s_signal) n++;
return (n);
}
@@ -638,10 +701,10 @@ int obj_sigoutletindex(t_object *x, int m)
int n;
t_outlet *o2;
for (o2 = x->ob_outlet, n = 0; o2; o2 = o2->o_next, m--)
- if (o2->o_sym == &s_signal)
+ if (o2->o_sym == &s_signal)
{
- if (m == 0) return (n);
- n++;
+ if (m == 0) return (n);
+ n++;
}
return (-1);
}
@@ -660,17 +723,17 @@ t_sample *obj_findsignalscalar(t_object *x, int m)
t_inlet *i;
if (x->ob_pd->c_firstin && x->ob_pd->c_floatsignalin)
{
- if (!m--)
- return (x->ob_pd->c_floatsignalin > 0 ?
- (t_sample *)(((char *)x) + x->ob_pd->c_floatsignalin) : 0);
- n++;
+ if (!m--)
+ return (x->ob_pd->c_floatsignalin > 0 ?
+ (t_sample *)(((char *)x) + x->ob_pd->c_floatsignalin) : 0);
+ n++;
}
for (i = x->ob_inlet; i; i = i->i_next, m--)
- if (i->i_symfrom == &s_signal)
+ if (i->i_symfrom == &s_signal)
{
- if (m == 0)
- return (&i->i_un.iu_floatsignalvalue);
- n++;
+ if (m == 0)
+ return (&i->i_un.iu_floatsignalvalue);
+ n++;
}
return (0);
}
@@ -682,7 +745,7 @@ int inlet_getsignalindex(t_inlet *x)
int n = 0;
t_inlet *i;
for (i = x->i_owner->ob_inlet, n = 0; i && i != x; i = i->i_next)
- if (i->i_symfrom == &s_signal) n++;
+ if (i->i_symfrom == &s_signal) n++;
return (n);
}
@@ -691,7 +754,7 @@ int outlet_getsignalindex(t_outlet *x)
int n = 0;
t_outlet *o;
for (o = x->o_owner->ob_outlet, n = 0; o && o != x; o = o->o_next)
- if (o->o_sym == &s_signal) n++;
+ if (o->o_sym == &s_signal) n++;
return (n);
}
diff --git a/pd/src/m_pd.c b/pd/src/m_pd.c
index 7ae53082..429799ef 100644
--- a/pd/src/m_pd.c
+++ b/pd/src/m_pd.c
@@ -12,13 +12,13 @@ t_pd *pd_new(t_class *c)
{
t_pd *x;
if (!c)
- bug ("pd_new: apparently called before setup routine");
+ bug ("pd_new: apparently called before setup routine");
x = (t_pd *)t_getbytes(c->c_size);
*x = c;
if (c->c_patchable)
{
- ((t_object *)x)->ob_inlet = 0;
- ((t_object *)x)->ob_outlet = 0;
+ ((t_object *)x)->ob_inlet = 0;
+ ((t_object *)x)->ob_outlet = 0;
}
return (x);
}
@@ -29,12 +29,12 @@ void pd_free(t_pd *x)
if (c->c_freemethod) (*(t_gotfn)(c->c_freemethod))(x);
if (c->c_patchable)
{
- while (((t_object *)x)->ob_outlet)
- outlet_free(((t_object *)x)->ob_outlet);
- while (((t_object *)x)->ob_inlet)
- inlet_free(((t_object *)x)->ob_inlet);
- if (((t_object *)x)->ob_binbuf)
- binbuf_free(((t_object *)x)->ob_binbuf);
+ while (((t_object *)x)->ob_outlet)
+ outlet_free(((t_object *)x)->ob_outlet);
+ while (((t_object *)x)->ob_inlet)
+ inlet_free(((t_object *)x)->ob_inlet);
+ if (((t_object *)x)->ob_binbuf)
+ binbuf_free(((t_object *)x)->ob_binbuf);
}
if (c->c_size) t_freebytes(x, c->c_size);
}
@@ -43,12 +43,12 @@ void gobj_save(t_gobj *x, t_binbuf *b)
{
t_class *c = x->g_pd;
if (c->c_savefn)
- (c->c_savefn)(x, b);
+ (c->c_savefn)(x, b);
}
/* deal with several objects bound to the same symbol. If more than one, we
actually bind a collection object to the symbol, which forwards messages sent
-to the symbol. */
+to the symbol. */
static t_class *bindlist_class;
@@ -68,28 +68,28 @@ static void bindlist_bang(t_bindlist *x)
{
t_bindelem *e;
for (e = x->b_list; e; e = e->e_next)
- pd_bang(e->e_who);
+ pd_bang(e->e_who);
}
static void bindlist_float(t_bindlist *x, t_float f)
{
t_bindelem *e;
for (e = x->b_list; e; e = e->e_next)
- pd_float(e->e_who, f);
+ pd_float(e->e_who, f);
}
static void bindlist_symbol(t_bindlist *x, t_symbol *s)
{
t_bindelem *e;
for (e = x->b_list; e; e = e->e_next)
- pd_symbol(e->e_who, s);
+ pd_symbol(e->e_who, s);
}
static void bindlist_pointer(t_bindlist *x, t_gpointer *gp)
{
t_bindelem *e;
for (e = x->b_list; e; e = e->e_next)
- pd_pointer(e->e_who, gp);
+ pd_pointer(e->e_who, gp);
}
static void bindlist_list(t_bindlist *x, t_symbol *s,
@@ -97,7 +97,7 @@ static void bindlist_list(t_bindlist *x, t_symbol *s,
{
t_bindelem *e;
for (e = x->b_list; e; e = e->e_next)
- pd_list(e->e_who, s, argc, argv);
+ pd_list(e->e_who, s, argc, argv);
}
static void bindlist_anything(t_bindlist *x, t_symbol *s,
@@ -105,13 +105,13 @@ static void bindlist_anything(t_bindlist *x, t_symbol *s,
{
t_bindelem *e;
for (e = x->b_list; e; e = e->e_next)
- pd_typedmess(e->e_who, s, argc, argv);
+ pd_typedmess(e->e_who, s, argc, argv);
}
void m_pd_setup(void)
{
bindlist_class = class_new(gensym("bindlist"), 0, 0,
- sizeof(t_bindlist), CLASS_PD, 0);
+ sizeof(t_bindlist), CLASS_PD, 0);
class_addbang(bindlist_class, bindlist_bang);
class_addfloat(bindlist_class, (t_method)bindlist_float);
class_addsymbol(bindlist_class, bindlist_symbol);
@@ -124,26 +124,26 @@ void pd_bind(t_pd *x, t_symbol *s)
{
if (s->s_thing)
{
- if (*s->s_thing == bindlist_class)
- {
- t_bindlist *b = (t_bindlist *)s->s_thing;
- t_bindelem *e = (t_bindelem *)getbytes(sizeof(t_bindelem));
- e->e_next = b->b_list;
- e->e_who = x;
- b->b_list = e;
- }
- else
- {
- t_bindlist *b = (t_bindlist *)pd_new(bindlist_class);
- t_bindelem *e1 = (t_bindelem *)getbytes(sizeof(t_bindelem));
- t_bindelem *e2 = (t_bindelem *)getbytes(sizeof(t_bindelem));
- b->b_list = e1;
- e1->e_who = x;
- e1->e_next = e2;
- e2->e_who = s->s_thing;
- e2->e_next = 0;
- s->s_thing = &b->b_pd;
- }
+ if (*s->s_thing == bindlist_class)
+ {
+ t_bindlist *b = (t_bindlist *)s->s_thing;
+ t_bindelem *e = (t_bindelem *)getbytes(sizeof(t_bindelem));
+ e->e_next = b->b_list;
+ e->e_who = x;
+ b->b_list = e;
+ }
+ else
+ {
+ t_bindlist *b = (t_bindlist *)pd_new(bindlist_class);
+ t_bindelem *e1 = (t_bindelem *)getbytes(sizeof(t_bindelem));
+ t_bindelem *e2 = (t_bindelem *)getbytes(sizeof(t_bindelem));
+ b->b_list = e1;
+ e1->e_who = x;
+ e1->e_next = e2;
+ e2->e_who = s->s_thing;
+ e2->e_next = 0;
+ s->s_thing = &b->b_pd;
+ }
}
else s->s_thing = x;
}
@@ -153,30 +153,30 @@ void pd_unbind(t_pd *x, t_symbol *s)
if (s->s_thing == x) s->s_thing = 0;
else if (s->s_thing && *s->s_thing == bindlist_class)
{
- /* bindlists always have at least two elements... if the number
- goes down to one, get rid of the bindlist and bind the symbol
- straight to the remaining element. */
-
- t_bindlist *b = (t_bindlist *)s->s_thing;
- t_bindelem *e, *e2;
- if ((e = b->b_list)->e_who == x)
- {
- b->b_list = e->e_next;
- freebytes(e, sizeof(t_bindelem));
- }
- else for (e = b->b_list; e2 = e->e_next; e = e2)
- if (e2->e_who == x)
- {
- e->e_next = e2->e_next;
- freebytes(e2, sizeof(t_bindelem));
- break;
- }
- if (!b->b_list->e_next)
- {
- s->s_thing = b->b_list->e_who;
- freebytes(b->b_list, sizeof(t_bindelem));
- pd_free(&b->b_pd);
- }
+ /* bindlists always have at least two elements... if the number
+ goes down to one, get rid of the bindlist and bind the symbol
+ straight to the remaining element. */
+
+ t_bindlist *b = (t_bindlist *)s->s_thing;
+ t_bindelem *e, *e2;
+ if ((e = b->b_list)->e_who == x)
+ {
+ b->b_list = e->e_next;
+ freebytes(e, sizeof(t_bindelem));
+ }
+ else for (e = b->b_list; e2 = e->e_next; e = e2)
+ if (e2->e_who == x)
+ {
+ e->e_next = e2->e_next;
+ freebytes(e2, sizeof(t_bindelem));
+ break;
+ }
+ if (!b->b_list->e_next)
+ {
+ s->s_thing = b->b_list->e_who;
+ freebytes(b->b_list, sizeof(t_bindelem));
+ pd_free(&b->b_pd);
+ }
}
else pd_error(x, "%s: couldn't unbind", s->s_name);
}
@@ -191,20 +191,20 @@ t_pd *pd_findbyclass(t_symbol *s, t_class *c)
if (*s->s_thing == c) return (s->s_thing);
if (*s->s_thing == bindlist_class)
{
- t_bindlist *b = (t_bindlist *)s->s_thing;
- t_bindelem *e, *e2;
- int warned = 0;
- for (e = b->b_list; e; e = e->e_next)
- if (*e->e_who == c)
- {
- if (x && !warned)
- {
- zz();
- post("warning: %s: multiply defined", s->s_name);
- warned = 1;
- }
- x = e->e_who;
- }
+ t_bindlist *b = (t_bindlist *)s->s_thing;
+ t_bindelem *e, *e2;
+ int warned = 0;
+ for (e = b->b_list; e; e = e->e_next)
+ if (*e->e_who == c)
+ {
+ if (x && !warned)
+ {
+ zz();
+ post("warning: %s: multiply defined", s->s_name);
+ warned = 1;
+ }
+ x = e->e_who;
+ }
}
return x;
}
@@ -227,8 +227,8 @@ int pd_setloadingabstraction(t_symbol *sym)
{
t_gstack *foo = gstack_head;
for (foo = gstack_head; foo; foo = foo->g_next)
- if (foo->g_loadingabstraction == sym)
- return (1);
+ if (foo->g_loadingabstraction == sym)
+ return (1);
pd_loadingabstraction = sym;
return (0);
}
@@ -249,18 +249,18 @@ void pd_popsym(t_pd *x)
if (!gstack_head || s__X.s_thing != x) bug("gstack_pop");
else
{
- t_gstack *headwas = gstack_head;
- s__X.s_thing = headwas->g_what;
- gstack_head = headwas->g_next;
- t_freebytes(headwas, sizeof(*headwas));
- lastpopped = x;
+ t_gstack *headwas = gstack_head;
+ s__X.s_thing = headwas->g_what;
+ gstack_head = headwas->g_next;
+ t_freebytes(headwas, sizeof(*headwas));
+ lastpopped = x;
}
}
void pd_doloadbang(void)
{
if (lastpopped)
- pd_vmess(lastpopped, gensym("loadbang"), "");
+ pd_vmess(lastpopped, gensym("loadbang"), "");
lastpopped = 0;
}
diff --git a/pd/src/m_pd.h b/pd/src/m_pd.h
index bfae6f5b..f3af6897 100644
--- a/pd/src/m_pd.h
+++ b/pd/src/m_pd.h
@@ -8,9 +8,8 @@
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
+#define PD_MAJOR_VERSION 0
+#define PD_MINOR_VERSION 38
/* 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 */
@@ -46,20 +45,17 @@ extern "C" {
#if !defined(_SIZE_T) && !defined(_SIZE_T_)
-#include <stddef.h> /* just for size_t -- how lame! */
+#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 */
+#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__
+/* signed and unsigned integer types the size of a pointer: */
+/* GG: long is the size of a pointer */
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_float; /* a floating-point number at most the same size */
typedef float t_floatarg; /* floating-point type for function calls */
typedef struct _symbol
@@ -70,37 +66,37 @@ typedef struct _symbol
} t_symbol;
EXTERN_STRUCT _array;
-#define t_array struct _array /* g_canvas.h */
+#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 */
+#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 */
+ 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 */
+ 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 */
+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) */
+ {
+ 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 */
+ int gp_valid; /* number which must match gpointee */
+ t_gstub *gp_stub; /* stub which points to glist/array */
} t_gpointer;
typedef union word
@@ -129,7 +125,7 @@ typedef enum
A_CANT
} t_atomtype;
-#define A_DEFSYMBOL A_DEFSYM /* better name for this */
+#define A_DEFSYMBOL A_DEFSYM /* better name for this */
typedef struct _atom
{
@@ -157,39 +153,39 @@ EXTERN_STRUCT _outconnect;
EXTERN_STRUCT _glist;
#define t_glist struct _glist
-#define t_canvas struct _glist /* LATER lose this */
+#define t_canvas struct _glist /* LATER lose this */
-typedef t_class *t_pd; /* pure datum: nothing but a class pointer */
+typedef t_class *t_pd; /* pure datum: nothing but a class pointer */
-typedef struct _gobj /* a graphical object */
+typedef struct _gobj /* a graphical object */
{
- t_pd g_pd; /* pure datum header (class) */
+ 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 */
+typedef struct _scalar /* a graphical object holding data */
{
- t_gobj sc_gobj; /* header for graphical object */
+ 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_word sc_vec[1]; /* indeterminate-length array of words */
} t_scalar;
-typedef struct _text /* patchable object - graphical, with text */
+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) */
+ 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 */
+ 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 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
@@ -208,8 +204,8 @@ 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_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;
@@ -336,11 +332,6 @@ 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);
@@ -365,7 +356,7 @@ EXTERN t_object *pd_checkobject(t_pd *x);
EXTERN void glob_setfilename(void *dummy, t_symbol *name, t_symbol *dir);
EXTERN void canvas_setargs(int argc, t_atom *argv);
-EXTERN t_atom *canvas_getarg(int which);
+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,
@@ -386,7 +377,7 @@ EXTERN t_parentwidgetbehavior *pd_getparentwidget(t_pd *x);
/* -------------------- classes -------------- */
-#define CLASS_DEFAULT 0 /* flags for new classes below */
+#define CLASS_DEFAULT 0 /* flags for new classes below */
#define CLASS_PD 1
#define CLASS_GOBJ 2
#define CLASS_PATCHABLE 3
@@ -419,11 +410,11 @@ 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 */
+ /* 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 */
+ /* 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);
@@ -438,24 +429,19 @@ EXTERN t_propertiesfn class_getpropertiesfn(t_class *c);
#endif
/* ------------ printing --------------------------------- */
-EXTERN void post(char *fmt, ...);
-EXTERN void startpost(char *fmt, ...);
-EXTERN void poststring(char *s);
+EXTERN void post(const char *fmt, ...);
+EXTERN void startpost(const char *fmt, ...);
+EXTERN void poststring(const 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 error(const char *fmt, ...);
+EXTERN void bug(const char *fmt, ...);
+EXTERN void pd_error(void *object, const char *fmt, ...);
+EXTERN void sys_logerror(const char *object, const char *s);
+EXTERN void sys_unixerror(const 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);
@@ -483,14 +469,14 @@ typedef float t_sample;
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 */
+ 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;
@@ -565,7 +551,7 @@ EXTERN float dbtopow(float);
EXTERN float q8_sqrt(float);
EXTERN float q8_rsqrt(float);
-#ifndef N32
+#ifndef N32
EXTERN float qsqrt(float); /* old names kept for extern compatibility */
EXTERN float qrsqrt(float);
#endif
@@ -592,14 +578,18 @@ 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 --------- */
+typedef void (*t_guicallbackfn)(t_gobj *client, t_glist *glist);
+
EXTERN void sys_vgui(char *fmt, ...);
EXTERN void sys_gui(char *s);
-
+EXTERN void sys_pretendguibytes(int n);
+EXTERN void sys_queuegui(void *client, t_glist *glist, t_guicallbackfn f);
+EXTERN void sys_unqueuegui(void *client);
/* 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 */
+extern t_class *glob_pdobject; /* object to send "pd" messages */
/*------------- Max 0.26 compatibility --------------------*/
@@ -623,13 +613,17 @@ defined, there is a "te_xpix" field in objects, not a "te_xpos" as before: */
#define PD_USE_TE_XPIX
-/* a test for NANs and denormals. Should only be necessary on i386. */
#ifdef __i386__
+/* 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)
diff --git a/pd/src/m_sched.c b/pd/src/m_sched.c
index b431848d..b0854984 100644
--- a/pd/src/m_sched.c
+++ b/pd/src/m_sched.c
@@ -19,7 +19,7 @@
static int sys_quit;
-static double sys_time;
+double sys_time;
static double sys_time_per_msec = TIMEUNITPERSEC / 1000.;
int sys_schedblocksize = DEFDACBLKSIZE;
@@ -38,7 +38,7 @@ struct _clock
t_clock *clock_setlist;
-#ifdef UNIX
+#ifdef UNISTD
#include <unistd.h>
#endif
@@ -56,14 +56,14 @@ void clock_unset(t_clock *x)
{
if (x->c_settime >= 0)
{
- if (x == clock_setlist) clock_setlist = x->c_next;
- else
- {
- t_clock *x2 = clock_setlist;
- while (x2->c_next != x) x2 = x2->c_next;
- x2->c_next = x->c_next;
- }
- x->c_settime = -1;
+ if (x == clock_setlist) clock_setlist = x->c_next;
+ else
+ {
+ t_clock *x2 = clock_setlist;
+ while (x2->c_next != x) x2 = x2->c_next;
+ x2->c_next = x->c_next;
+ }
+ x->c_settime = -1;
}
}
@@ -75,17 +75,17 @@ void clock_set(t_clock *x, double setticks)
x->c_settime = setticks;
if (clock_setlist && clock_setlist->c_settime <= setticks)
{
- t_clock *cbefore, *cafter;
- for (cbefore = clock_setlist, cafter = clock_setlist->c_next;
- cbefore; cbefore = cafter, cafter = cbefore->c_next)
- {
- if (!cafter || cafter->c_settime > setticks)
- {
- cbefore->c_next = x;
- x->c_next = cafter;
- return;
- }
- }
+ t_clock *cbefore, *cafter;
+ for (cbefore = clock_setlist, cafter = clock_setlist->c_next;
+ cbefore; cbefore = cafter, cafter = cbefore->c_next)
+ {
+ if (!cafter || cafter->c_settime > setticks)
+ {
+ cbefore->c_next = x;
+ x->c_next = cafter;
+ return;
+ }
+ }
}
else x->c_next = clock_setlist, clock_setlist = x;
}
@@ -135,11 +135,11 @@ static int sys_histogram[NHIST][NBIN];
static double sys_histtime;
static int sched_diddsp, sched_didpoll, sched_didnothing;
-static void sys_clearhist( void)
+void sys_clearhist( void)
{
unsigned int i, j;
for (i = 0; i < NHIST; i++)
- for (j = 0; j < NBIN; j++) sys_histogram[i][j] = 0;
+ for (j = 0; j < NBIN; j++) sys_histogram[i][j] = 0;
sys_histtime = sys_getrealtime();
sched_diddsp = sched_didpoll = sched_didnothing = 0;
}
@@ -149,23 +149,23 @@ void sys_printhist( void)
unsigned int i, j;
for (i = 0; i < NHIST; i++)
{
- int doit = 0;
- for (j = 0; j < NBIN; j++) if (sys_histogram[i][j]) doit = 1;
- if (doit)
- {
- post("%2d %8d %8d %8d %8d %8d %8d %8d %8d", i,
- sys_histogram[i][0],
- sys_histogram[i][1],
- sys_histogram[i][2],
- sys_histogram[i][3],
- sys_histogram[i][4],
- sys_histogram[i][5],
- sys_histogram[i][6],
- sys_histogram[i][7]);
- }
+ int doit = 0;
+ for (j = 0; j < NBIN; j++) if (sys_histogram[i][j]) doit = 1;
+ if (doit)
+ {
+ post("%2d %8d %8d %8d %8d %8d %8d %8d %8d", i,
+ sys_histogram[i][0],
+ sys_histogram[i][1],
+ sys_histogram[i][2],
+ sys_histogram[i][3],
+ sys_histogram[i][4],
+ sys_histogram[i][5],
+ sys_histogram[i][6],
+ sys_histogram[i][7]);
+ }
}
post("dsp %d, pollgui %d, nothing %d",
- sched_diddsp, sched_didpoll, sched_didnothing);
+ sched_diddsp, sched_didpoll, sched_didnothing);
}
static int sys_histphase;
@@ -177,11 +177,11 @@ int sys_addhist(int phase)
int msec = (newtime - sys_histtime) * 1000.;
for (j = NBIN-1; j >= 0; j--)
{
- if (msec >= sys_bin[j])
- {
- sys_histogram[phasewas][j]++;
- break;
- }
+ if (msec >= sys_bin[j])
+ {
+ sys_histogram[phasewas][j]++;
+ break;
+ }
}
sys_histtime = newtime;
sys_histphase = phase;
@@ -218,18 +218,18 @@ void glob_audiostatus(void)
post("seconds ago\terror type");
for (i = 0; i < nresync; i++)
{
- int errtype;
- if (nresyncphase < 0)
- nresyncphase += NRESYNC;
- errtype = oss_resync[nresyncphase].r_error;
- if (errtype < 0 || errtype > 4)
- errtype = 0;
-
- post("%9.2f\t%s",
- (sched_diddsp - oss_resync[nresyncphase].r_ntick)
- * ((double)sys_schedblocksize) / sys_dacsr,
- oss_errornames[errtype]);
- nresyncphase--;
+ int errtype;
+ if (nresyncphase < 0)
+ nresyncphase += NRESYNC;
+ errtype = oss_resync[nresyncphase].r_error;
+ if (errtype < 0 || errtype > 4)
+ errtype = 0;
+
+ post("%9.2f\t%s",
+ (sched_diddsp - oss_resync[nresyncphase].r_ntick)
+ * ((double)sys_schedblocksize) / sys_dacsr,
+ oss_errornames[errtype]);
+ nresyncphase--;
}
}
@@ -244,78 +244,78 @@ void sys_log_error(int type)
oss_nresync++;
if (++oss_resyncphase == NRESYNC) oss_resyncphase = 0;
if (type != ERR_NOTHING && !sched_diored &&
- (sched_diddsp >= sched_dioredtime))
+ (sched_diddsp >= sched_dioredtime))
{
- sys_vgui("pdtk_pd_dio 1\n");
- sched_diored = 1;
+ sys_vgui("pdtk_pd_dio 1\n");
+ sched_diored = 1;
}
sched_dioredtime =
- sched_diddsp + (int)(sys_dacsr /(double)sys_schedblocksize);
+ sched_diddsp + (int)(sys_dacsr /(double)sys_schedblocksize);
}
static int sched_lastinclip, sched_lastoutclip,
sched_lastindb, sched_lastoutdb;
-void glob_ping(t_pd *dummy);
+void glob_watchdog(t_pd *dummy);
static void sched_pollformeters( void)
{
int inclip, outclip, indb, outdb;
static int sched_nextmeterpolltime, sched_nextpingtime;
- /* if there's no GUI but we're running in "realtime", here is
- where we arrange to ping the watchdog every 2 seconds. */
+ /* if there's no GUI but we're running in "realtime", here is
+ where we arrange to ping the watchdog every 2 seconds. */
#ifdef __linux__
if (sys_nogui && sys_hipriority && (sched_diddsp - sched_nextpingtime > 0))
{
- glob_ping(0);
- /* ping every 2 seconds */
- sched_nextpingtime = sched_diddsp +
- 2 * (int)(sys_dacsr /(double)sys_schedblocksize);
+ glob_watchdog(0);
+ /* ping every 2 seconds */
+ sched_nextpingtime = sched_diddsp +
+ 2 * (int)(sys_dacsr /(double)sys_schedblocksize);
}
#endif
if (sched_diddsp - sched_nextmeterpolltime < 0)
- return;
+ return;
if (sched_diored && (sched_diddsp - sched_dioredtime > 0))
{
- sys_vgui("pdtk_pd_dio 0\n");
- sched_diored = 0;
+ sys_vgui("pdtk_pd_dio 0\n");
+ sched_diored = 0;
}
if (sched_meterson)
{
- float inmax, outmax;
- sys_getmeters(&inmax, &outmax);
- indb = 0.5 + rmstodb(inmax);
- outdb = 0.5 + rmstodb(outmax);
- inclip = (inmax > 0.999);
- outclip = (outmax >= 1.0);
+ float inmax, outmax;
+ sys_getmeters(&inmax, &outmax);
+ indb = 0.5 + rmstodb(inmax);
+ outdb = 0.5 + rmstodb(outmax);
+ inclip = (inmax > 0.999);
+ outclip = (outmax >= 1.0);
}
else
{
- indb = outdb = 0;
- inclip = outclip = 0;
+ indb = outdb = 0;
+ inclip = outclip = 0;
}
if (inclip != sched_lastinclip || outclip != sched_lastoutclip
- || indb != sched_lastindb || outdb != sched_lastoutdb)
+ || indb != sched_lastindb || outdb != sched_lastoutdb)
{
- sys_vgui("pdtk_pd_meters %d %d %d %d\n", indb, outdb, inclip, outclip);
- sched_lastinclip = inclip;
- sched_lastoutclip = outclip;
- sched_lastindb = indb;
- sched_lastoutdb = outdb;
+ sys_vgui("pdtk_pd_meters %d %d %d %d\n", indb, outdb, inclip, outclip);
+ sched_lastinclip = inclip;
+ sched_lastoutclip = outclip;
+ sched_lastindb = indb;
+ sched_lastoutdb = outdb;
}
sched_nextmeterpolltime =
- sched_diddsp + (int)(sys_dacsr /(double)sys_schedblocksize);
+ sched_diddsp + (int)(sys_dacsr /(double)sys_schedblocksize);
}
void glob_meters(void *dummy, float f)
{
if (f == 0)
- sys_getmeters(0, 0);
+ sys_getmeters(0, 0);
sched_meterson = (f != 0);
sched_lastinclip = sched_lastoutclip = sched_lastindb = sched_lastoutdb =
- -1;
+ -1;
}
#if 0
@@ -330,38 +330,38 @@ void dsp_tick(void);
static int sched_usedacs = 1;
static double sched_referencerealtime, sched_referencelogicaltime;
-static double sys_time_per_dsp_tick;
+double sys_time_per_dsp_tick;
void sched_set_using_dacs(int flag)
{
sched_usedacs = flag;
if (!flag)
{
- sched_referencerealtime = sys_getrealtime();
- sched_referencelogicaltime = clock_getlogicaltime();
+ sched_referencerealtime = sys_getrealtime();
+ sched_referencelogicaltime = clock_getlogicaltime();
}
sys_time_per_dsp_tick = (TIMEUNITPERSEC) *
- ((double)sys_schedblocksize) / sys_dacsr;
+ ((double)sys_schedblocksize) / sys_dacsr;
}
/* take the scheduler forward one DSP tick, also handling clock timeouts */
-static void sched_tick(double next_sys_time)
+void sched_tick(double next_sys_time)
{
int countdown = 5000;
while (clock_setlist && clock_setlist->c_settime < next_sys_time)
{
- t_clock *c = clock_setlist;
- sys_time = c->c_settime;
- clock_unset(clock_setlist);
- outlet_setstacklim();
- (*c->c_fn)(c->c_owner);
- if (!countdown--)
- {
- countdown = 5000;
- sys_pollgui();
- }
- if (sys_quit)
- return;
+ t_clock *c = clock_setlist;
+ sys_time = c->c_settime;
+ clock_unset(clock_setlist);
+ outlet_setstacklim();
+ (*c->c_fn)(c->c_owner);
+ if (!countdown--)
+ {
+ countdown = 5000;
+ sys_pollgui();
+ }
+ if (sys_quit)
+ return;
}
sys_time = next_sys_time;
dsp_tick();
@@ -386,99 +386,99 @@ int m_scheduler( void)
{
int idlecount = 0;
sys_time_per_dsp_tick = (TIMEUNITPERSEC) *
- ((double)sys_schedblocksize) / sys_dacsr;
+ ((double)sys_schedblocksize) / sys_dacsr;
#ifdef THREAD_LOCKING
/* T.Grill - lock mutex */
- sys_lock();
+ sys_lock();
#endif
sys_clearhist();
if (sys_sleepgrain < 1000)
- sys_sleepgrain = sys_schedadvance/4;
+ sys_sleepgrain = sys_schedadvance/4;
if (sys_sleepgrain < 100)
- sys_sleepgrain = 100;
+ sys_sleepgrain = 100;
else if (sys_sleepgrain > 5000)
- sys_sleepgrain = 5000;
+ sys_sleepgrain = 5000;
sys_initmidiqueue();
while (!sys_quit)
{
- int didsomething = 0;
- int timeforward;
+ int didsomething = 0;
+ int timeforward;
- sys_addhist(0);
+ sys_addhist(0);
waitfortick:
- if (sched_usedacs)
- {
- timeforward = sys_send_dacs();
-
- /* if dacs remain "idle" for 1 sec, they're hung up. */
- if (timeforward != 0)
- idlecount = 0;
- else
- {
- idlecount++;
- if (!(idlecount & 31))
- {
- static double idletime;
- /* on 32nd idle, start a clock watch; every
- 32 ensuing idles, check it */
- if (idlecount == 32)
- idletime = sys_getrealtime();
- else if (sys_getrealtime() - idletime > 1.)
- {
- post("audio I/O stuck... closing audio\n");
- sys_close_audio();
- sched_set_using_dacs(0);
- goto waitfortick;
- }
- }
- }
- }
- else
- {
- if (1000. * (sys_getrealtime() - sched_referencerealtime)
- > clock_gettimesince(sched_referencelogicaltime))
- timeforward = SENDDACS_YES;
- else timeforward = SENDDACS_NO;
- }
- sys_setmiditimediff(0, 1e-6 * sys_schedadvance);
- sys_addhist(1);
- if (timeforward != SENDDACS_NO)
- sched_tick(sys_time + sys_time_per_dsp_tick);
- if (timeforward == SENDDACS_YES)
- didsomething = 1;
-
- sys_addhist(2);
- sys_pollmidiqueue();
- if (sys_pollgui())
- {
- if (!didsomething)
- sched_didpoll++;
- didsomething = 1;
- }
- sys_addhist(3);
- /* test for idle; if so, do graphics updates. */
- if (!didsomething)
- {
- sched_pollformeters();
- sys_reportidle();
+ if (sched_usedacs)
+ {
+ timeforward = sys_send_dacs();
+
+ /* if dacs remain "idle" for 1 sec, they're hung up. */
+ if (timeforward != 0)
+ idlecount = 0;
+ else
+ {
+ idlecount++;
+ if (!(idlecount & 31))
+ {
+ static double idletime;
+ /* on 32nd idle, start a clock watch; every
+ 32 ensuing idles, check it */
+ if (idlecount == 32)
+ idletime = sys_getrealtime();
+ else if (sys_getrealtime() - idletime > 1.)
+ {
+ post("audio I/O stuck... closing audio\n");
+ sys_close_audio();
+ sched_set_using_dacs(0);
+ goto waitfortick;
+ }
+ }
+ }
+ }
+ else
+ {
+ if (1000. * (sys_getrealtime() - sched_referencerealtime)
+ > clock_gettimesince(sched_referencelogicaltime))
+ timeforward = SENDDACS_YES;
+ else timeforward = SENDDACS_NO;
+ }
+ sys_setmiditimediff(0, 1e-6 * sys_schedadvance);
+ sys_addhist(1);
+ if (timeforward != SENDDACS_NO)
+ sched_tick(sys_time + sys_time_per_dsp_tick);
+ if (timeforward == SENDDACS_YES)
+ didsomething = 1;
+
+ sys_addhist(2);
+ sys_pollmidiqueue();
+ if (sys_pollgui())
+ {
+ if (!didsomething)
+ sched_didpoll++;
+ didsomething = 1;
+ }
+ sys_addhist(3);
+ /* test for idle; if so, do graphics updates. */
+ if (!didsomething)
+ {
+ sched_pollformeters();
+ sys_reportidle();
#ifdef THREAD_LOCKING
/* T.Grill - enter idle phase -> unlock thread lock */
sys_unlock();
#endif
- if (timeforward != SENDDACS_SLEPT)
- sys_microsleep(sys_sleepgrain);
+ if (timeforward != SENDDACS_SLEPT)
+ sys_microsleep(sys_sleepgrain);
#ifdef THREAD_LOCKING
/* T.Grill - leave idle phase -> lock thread lock */
- sys_lock();
+ sys_lock();
#endif
- sys_addhist(5);
- sched_didnothing++;
+ sys_addhist(5);
+ sched_didnothing++;
- }
+ }
}
#ifdef THREAD_LOCKING
@@ -522,11 +522,11 @@ int sys_trylock(void) {}
/* ------------ soft quit ------------------- */
/* added by Thomas Grill -
- just set the quit flag for the scheduler loop
- this is useful for applications using the PD shared library to signal the scheduler to terminate
+ just set the quit flag for the scheduler loop
+ this is useful for applications using the PD shared library to signal the scheduler to terminate
*/
void sys_exit(void)
{
- sys_quit = 1;
+ sys_quit = 1;
}
diff --git a/pd/src/makefile.in b/pd/src/makefile.in
index 40587b17..dbc5ec57 100644
--- a/pd/src/makefile.in
+++ b/pd/src/makefile.in
@@ -22,7 +22,7 @@ LIB = @PDLIB@
OPT_CFLAGS = @OPT_CFLAGS@
WARN_CFLAGS = -Wall -W -Wstrict-prototypes \
-Wno-unused -Wno-parentheses -Wno-switch
-ARCH_CFLAGS = -DPD -DUNIX
+ARCH_CFLAGS = -DPD
CFLAGS = @CFLAGS@ $(ARCH_CFLAGS) $(WARN_CFLAGS) $(OPT_CFLAGS) $(MORECFLAGS)
@@ -100,8 +100,8 @@ $(BIN_DIR)/pd.tk: u_main.tk
#this is for Max OSX only...
$(BIN_DIR)/pdtcl: $(GOBJ) $(GSRC)
cd ../obj; libtool -dynamic -o $(BIN_DIR)/pdtcl $(GOBJ) \
- /Library/Frameworks/Tk.framework/Versions/Current/Tk \
- /Library/Frameworks/Tcl.framework/Versions/Current/Tcl \
+ ../../Frameworks/Tk.framework/Versions/Current/Tk \
+ ../../Frameworks/Tcl.framework/Versions/Current/Tcl \
/usr/lib/libSystem.B.dylib
externs:
@@ -115,6 +115,7 @@ externs:
INSTDIR = $(DESTDIR)/$(INSTALL_PREFIX)
MANINSTDIR = $(DESTDIR)/$(INSTALL_PREFIX)/$(MANDIR)
+BINARYMODE=@binarymode@
install: all
install -d $(INSTDIR)/lib/pd/bin
@@ -122,9 +123,9 @@ install: all
install $(BIN_DIR)/pd-watchdog $(INSTDIR)/lib/pd/bin/pd-watchdog
install -m644 $(BIN_DIR)/pd.tk $(INSTDIR)/lib/pd/bin/pd.tk
install -d $(INSTDIR)/bin
- install -m755 $(PDEXEC) $(INSTDIR)/bin/pd
- install -m 755 $(BIN_DIR)/pdsend $(INSTDIR)/bin/pdsend
- install -m 755 $(BIN_DIR)/pdreceive $(INSTDIR)/bin/pdreceive
+ install $(BINARYMODE) $(PDEXEC) $(INSTDIR)/bin/pd
+ install -m755 $(BIN_DIR)/pdsend $(INSTDIR)/bin/pdsend
+ install -m755 $(BIN_DIR)/pdreceive $(INSTDIR)/bin/pdreceive
cp -pr ../doc ../extra $(INSTDIR)/lib/pd/
rm -f $(INSTDIR)/extra/*/*.o
install -d $(INSTDIR)/include
@@ -140,6 +141,7 @@ install: all
local-clean:
-rm -f ../obj/* $(BIN_DIR)/pd $(BIN_DIR)/$(GUINAME) $(BIN_DIR)/pdsend \
$(BIN_DIR)/pdreceive $(BIN_DIR)/pd-watchdog m_stamp.c
+ -rm -f `find ../portaudio ../portaudio_v18 -name "*.o"`
-rm -f *~
-(cd ../doc/6.externs; rm -f *.pd_linux)
-rm -f makefile.dependencies
diff --git a/pd/src/makefile.irix b/pd/src/makefile.irix
new file mode 100644
index 00000000..38c296a0
--- /dev/null
+++ b/pd/src/makefile.irix
@@ -0,0 +1,190 @@
+# Makefile mods by Olaf Matthes for use with GCC 3.3
+#
+# This makefile is made for r10000. You can change r10000 to your
+# processor type if you have problems. Just change and type
+# 'make'
+#
+# You will need to change the tck/tk paths if you want to recompile
+# The GUI part.
+
+# compile with GCC as n32 binary
+EXECUTABLE=../bin/pd-n32
+XF1=-mabi=n32 -mips4 -DN32 -funroll-loops -fomit-frame-pointer
+
+# compile with GCC as o32 binary
+#EXECUTABLE=../bin/pd-o32
+#XF1=-mcpu=r4000 -mips3 -funroll-loops -fomit-frame-pointer
+
+CC=gcc
+OBJ_DIR = ../obj
+BIN_DIR = ../bin
+PDEXEC = $(BIN_DIR)/pd
+EXT= pd_irix6
+GUINAME= pd-gui
+
+INSTALL_PREFIX = /usr/local
+GFLAGS = -DINSTALL_PREFIX=\"$(INSTALL_PREFIX)\"
+
+MANDIR = ${prefix}/man
+
+MORECFLAGS = -DIRIX -DDL_OPEN -DUSEAPI_SGI -I/usr/X11R6/include -Wno-error
+
+INCLUDE = -I. -I../tk/unix/include -I../tcl/unix/include
+GINCLUDE = $(INCLUDE)
+GLIB = ../tk/unix/lib/libtk8.4.a ../tcl/unix/lib/libtcl8.4.a -lm -lX11
+
+LDFLAGS = $(XF1)
+LIB = -laudio -lmd -lm -lpthread
+
+OPT_CFLAGS = -O3
+WARN_CFLAGS = -Wall -W -Werror -Wno-unused \
+ -Wno-parentheses -Wno-switch
+ARCH_CFLAGS = -DPD -DUNIX
+
+CFLAGS = $(ARCH_CFLAGS) $(WARN_CFLAGS) $(OPT_CFLAGS) $(MORECFLAGS) $(XF1)
+
+# the sources
+
+SYSSRC = s_midi_sgi.c s_audio_sgi.c
+
+SRC = g_canvas.c g_graph.c g_text.c g_rtext.c g_array.c g_template.c g_io.c \
+ g_scalar.c g_traversal.c g_guiconnect.c g_readwrite.c g_editor.c \
+ g_all_guis.c g_bang.c g_hdial.c g_hslider.c g_mycanvas.c g_numbox.c \
+ g_toggle.c g_vdial.c g_vslider.c g_vumeter.c \
+ m_pd.c m_class.c m_obj.c m_atom.c m_memory.c m_binbuf.c \
+ m_conf.c m_glob.c m_sched.c \
+ s_main.c s_inter.c s_file.c s_print.c \
+ s_loader.c s_path.c s_entry.c s_audio.c s_midi.c \
+ d_ugen.c d_ctl.c d_arithmetic.c d_osc.c d_filter.c d_dac.c d_misc.c \
+ d_math.c d_fft.c d_mayer_fft.c d_fftroutine.c d_array.c d_global.c \
+ d_delay.c d_resample.c \
+ x_arithmetic.c x_connective.c x_interface.c x_midi.c x_misc.c \
+ x_time.c x_acoustics.c x_net.c x_qlist.c x_gui.c d_soundfile.c \
+ $(SYSSRC)
+
+
+OBJ = $(SRC:.c=.o)
+
+GSRC = t_main.c t_tkcmd.c
+
+GOBJ = $(GSRC:.c=.o)
+
+#
+# ------------------ targets ------------------------------------
+#
+
+.PHONY: pd gui pd-watchdog all
+
+all: $(PDEXEC) $(BIN_DIR)/pd-watchdog $(BIN_DIR)/$(GUINAME) $(BIN_DIR)/pdsend \
+ $(BIN_DIR)/pdreceive $(BIN_DIR)/pd.tk externs
+
+bin: $(PDEXEC) $(BIN_DIR)/pd-watchdog $(BIN_DIR)/$(GUINAME) $(BIN_DIR)/pdsend \
+ $(BIN_DIR)/pdreceive $(BIN_DIR)/pd.tk
+
+.c.o:
+ gcc $(CFLAGS) $(GFLAGS) $(INCLUDE) -c -o $(OBJ_DIR)/$*.o $*.c
+
+#$(OBJ) : %.o : %.c
+# $(CC) $(CFLAGS) $(GFLAGS) $(INCLUDE) -c -o $(OBJ_DIR)/$*.o $*.c
+
+#$(GOBJ) : %.o : %.c
+# $(CC) $(CFLAGS) $(GFLAGS) $(GINCLUDE) -c -o $(OBJ_DIR)/$*.o $*.c
+
+pd: $(PDEXEC)
+
+gui: $(BIN_DIR)/$(GUINAME)
+
+pd-watchdog: $(BIN_DIR)/pd-watchdog
+
+$(BIN_DIR)/pd-watchdog: s_watchdog.c
+ gcc -O2 $(STRIPFLAG) -o $(BIN_DIR)/pd-watchdog s_watchdog.c
+
+$(BIN_DIR)/pdsend: u_pdsend.c
+ gcc $(CFLAGS) $(STRIPFLAG) -o $(BIN_DIR)/pdsend u_pdsend.c
+
+$(BIN_DIR)/pdreceive: u_pdreceive.c
+ gcc $(CFLAGS) $(STRIPFLAG) -o $(BIN_DIR)/pdreceive u_pdreceive.c
+
+$(PDEXEC): $(OBJ)
+ cd ../obj; $(CC) $(LDFLAGS) $(DBG_CFLAGS) -o $(PDEXEC) $(OBJ) \
+ $(LIB)
+
+$(BIN_DIR)/pd-gui: $(GOBJ) $(GSRC)
+ cd ../obj; $(CC) $(INCLUDE) -o $(BIN_DIR)/$(GUINAME) $(GOBJ) \
+ $(GLIB)
+
+$(BIN_DIR)/pd.tk: u_main.tk
+ echo set pd_nt 2 > $(BIN_DIR)/pd.tk
+ grep -v "set pd_nt" < u_main.tk >> $(BIN_DIR)/pd.tk
+
+INSTDIR = $(DESTDIR)/$(INSTALL_PREFIX)
+MANINSTDIR = $(DESTDIR)/$(MANDIR)
+
+install: all
+ install -d $(INSTDIR)/lib/pd/bin
+ install $(BIN_DIR)/$(GUINAME) $(INSTDIR)/lib/pd/bin/$(GUINAME)
+ install $(BIN_DIR)/pd-watchdog $(INSTDIR)/lib/pd/bin/pd-watchdog
+ install -m644 $(BIN_DIR)/pd.tk $(INSTDIR)/lib/pd/bin/pd.tk
+ install -d $(INSTDIR)/bin
+ install -m755 $(PDEXEC) $(INSTDIR)/bin/pd
+ install -m 755 $(BIN_DIR)/pdsend $(INSTDIR)/bin/pdsend
+ install -m 755 $(BIN_DIR)/pdreceive $(INSTDIR)/bin/pdreceive
+ install -d $(INSTDIR)/lib/pd/extra
+ install -d $(INSTDIR)/lib/pd/externs
+ install -m 644 $(EXTERNS) $(INSTDIR)/lib/pd/extra
+ cp -r ../doc $(INSTDIR)/lib/pd/
+ install -d $(INSTDIR)/include
+ install -m644 m_pd.h $(INSTDIR)/include/m_pd.h
+ install -d $(MANINSTDIR)/man1
+ gzip < ../man/pd.1 > $(MANINSTDIR)/man1/pd.1.gz
+ chmod 644 $(MANINSTDIR)/man1/pd.1.gz
+ gzip < ../man/pdsend.1 > $(MANINSTDIR)/man1/pdsend.1.gz
+ chmod 644 $(MANINSTDIR)/man1/pdsend.1.gz
+ gzip < ../man/pdreceive.1 > $(MANINSTDIR)/man1/pdreceive.1.gz
+ chmod 644 $(MANINSTDIR)/man1/pdreceive.1.gz
+
+local-clean:
+ -rm -f ../obj/* $(BIN_DIR)/pd $(BIN_DIR)/$(GUINAME) $(BIN_DIR)/pdsend \
+ $(BIN_DIR)/pdreceive $(BIN_DIR)/pd-watchdog m_stamp.c
+ -rm -f *~
+ -(cd ../doc/6.externs; rm -f *.pd_linux)
+ -rm -f makefile.dependencies
+ touch makefile.dependencies
+ chmod 666 makefile.dependencies
+
+extra-clean:
+ -rm -f `find ../extra/ -name "*.pd_*"`
+ -rm -f tags
+
+clean: extra-clean local-clean
+
+distclean: clean
+ rm -rf config.cache config.log config.status makefile tags \
+ autom4te-*.cache
+ echo all: > makefile
+ echo -e "\t./configure" >> makefile
+ echo -e "\tmake" >> makefile
+
+tags: $(SRC) $(GSRC); ctags *.[ch]
+
+depend:
+ $(CC) $(INCLUDE) $(CFLAGS) -M $(SRC) > makefile.dependencies
+
+uninstall:
+ -rm -r $(INSTDIR)/lib/pd
+ -rm $(INSTDIR)/bin/pd
+ -rm $(INSTDIR)/bin/pdsend
+ -rm $(INSTDIR)/bin/pdreceive
+ -rm $(INSTDIR)/include/m_pd.h
+ -rm $(MANINSTDIR)/man/man1/pd.1.gz
+ -rm $(MANINSTDIR)/man/man1/pdsend.1.gz
+ -rm $(MANINSTDIR)/man/man1/pdreceive.1.gz
+
+include makefile.dependencies
+
+
+
+
+
+
+
diff --git a/pd/src/makefile.nt b/pd/src/makefile.nt
index f149f01e..647700f9 100644
--- a/pd/src/makefile.nt
+++ b/pd/src/makefile.nt
@@ -11,14 +11,16 @@ LDIR = $(VC)\lib
LIB = /NODEFAULTLIB:libc /NODEFAULTLIB:oldnames /NODEFAULTLIB:kernel \
/NODEFAULTLIB:uuid \
$(LDIR)\libc.lib $(LDIR)\oldnames.lib $(LDIR)\kernel32.lib \
- $(LDIR)\wsock32.lib $(LDIR)\winmm.lib ..\bin\pthreadVC.lib
+ $(LDIR)\wsock32.lib $(LDIR)\winmm.lib $(LDIR)\advapi32.lib \
+ ..\bin\pthreadVC.lib
-GLIB = $(LIB) ..\bin\tcl83.lib ..\bin\tk83.lib
+GLIB = $(LIB) ..\bin\tcl84.lib ..\bin\tk84.lib
CFLAGS = /nologo /W3 /DMSW /DNT /DPD /DPD_INTERNAL /DWIN32 /DWINDOWS /Ox \
- -DPA_LITTLE_ENDIAN -DUSEAPI_MMIO -DUSEAPI_PORTAUDIO
+ -DPA_LITTLE_ENDIAN -DUSEAPI_MMIO -DUSEAPI_PORTAUDIO -D__i386__
LFLAGS = /nologo
-SYSSRC = s_audio_pa.c s_audio_mmio.c s_midi_mmio.c
+SYSSRC = s_audio_pa.c s_audio_pablio.c s_audio_paring.c \
+ s_audio_mmio.c s_midi_mmio.c
SRC = g_canvas.c g_graph.c g_text.c g_rtext.c g_array.c g_template.c g_io.c \
g_scalar.c g_traversal.c g_guiconnect.c g_readwrite.c g_editor.c \
@@ -37,8 +39,7 @@ SRC = g_canvas.c g_graph.c g_text.c g_rtext.c g_array.c g_template.c g_io.c \
PADIR = ..\portaudio
INCPA = -I$(PADIR) -I$(PADIR)\pa_common -I$(PADIR)\pablio -I..\lib\asio
-SRCPA = $(PADIR)/pa_common/pa_lib.c $(PADIR)/pa_common/pa_trace.c \
- $(PADIR)/pablio/pablio_pd.c $(PADIR)/pablio/ringbuffer_pd.c
+SRCPA = $(PADIR)/pa_common/pa_lib.c $(PADIR)/pa_common/pa_trace.c
SRCASIO = $(PADIR)/pa_asio/pa_asio.cpp
ASIOLIB = $(LDIR)\user32.lib $(LDIR)\gdi32.lib $(LDIR)\winspool.lib $(LDIR)\comdlg32.lib \
@@ -46,7 +47,7 @@ $(LDIR)\advapi32.lib $(LDIR)\shell32.lib $(LDIR)\ole32.lib $(LDIR)\oleaut32.lib
$(LDIR)\odbc32.lib $(LDIR)\odbccp32.lib ..\lib\asio\asiolib.lib
-PAOBJ = pa_lib.obj pa_trace.obj pablio_pd.obj ringbuffer_pd.obj pa_asio.obj
+PAOBJ = pa_lib.obj pa_trace.obj pa_asio.obj
OBJC = $(SRC:.c=.obj) $(PAOBJ)
diff --git a/pd/src/notes.txt b/pd/src/notes.txt
index 8d1fead9..4391cf7c 100644
--- a/pd/src/notes.txt
+++ b/pd/src/notes.txt
@@ -1,134 +1,146 @@
---------------- dolist --------------------
-
-fix for 0.37:
-read xx.txt in "bad" gives warnings
-mess with RME ALSA some more; ALSA readn doesn't work yet.
-test MIDI I/O on all platforms, inc. sysex...
-windows quit doesn't confirm on Windows?
-check Pd in OSX 10.3
-
-0.38:
-document env~ second argument (and why is it no less than 1/10 of first???)
-make watchdog work for MACOSX
-%x to %lx in all "tags" to make 64-bit safe
+done:
plug-in support
-portaudio_pd files into src
+atan2 inlets switched
+queued graphics updates for tables, number boxes
+cut/paste text (needs more testing)
+add standard bindings (ctl-o, etc) to dialogs
+separate audio on/off from nchans
+setuid flag in configure script
settings saver (registry in Windows; .pdrc in linux; defaults system in OSX?)
-text cut/copy/paste
-GOP bounding box object
-signal inlets to sense signals; fix +~ etc, vcf~, biquad~, and make a vcfb~
-
-makefile to set SETUID bit on install?
-loading e-mailed patches without removing headers crashes pd
-investigate gcc 3.3 warnings; try to reinstate -fstrict-aliasing
-message dialog not to disappear
+ audio API
+ MIDI -- fix to read MIDI on startup (rest works?)
+ path
+ startup flags
+ libs
+better params:
+ extra flag for path
+ startup flags
+ startup libraries
+printout to pd window
+startup from GUI
+%x to %lx in all "tags" to make 64-bit safe
+portaudio_pd files into src
+t_int to int in binbuf_addv
+64-bit fix to externs makefiles
+new filter objects: cpole~, fpole~, etc.
+put in Wini's RME ALSA code; there are still bugs...
+portaudio fixed for inchans != outchans, e.g., emi emagic (2/6)
sprout inlets/outlets on objects whose creation failed.
-pd $1 bug ($1 is saved as it was evaluated, not as '$1')
-why does changing the name of an explode in jupiter patch take so long?
-close-subwindows menu item
-trouble typing into number boxes
-abstraction reload doesn't have to vis everyone??
-show results of opening audio and MIDI on dialogs
-windows escape from control-C
-add standard bindings (ctl-o, etc) to dialogs
-settable netsend and netreceive port numbers
-suspend/resume graphics updates
-scheduler to handle callbacks
-scheduler to do DSP computations even if no audio
-hook to scheduler to let others get called for DSP I/O
-new: mline~, msnapshot~, abs~
-flags to defeat adding specified classes from libraries
-incorporate pddp doc
-try again to fix the font scene
-addcomma message to message
-pasting should look at current mouse location
-open/save panel to take messages to init directory
-look at prctl(2) for FP exception handling
+
+doc:
+document env~ second argument (and why is it no less than 1/10 of first???)
+update 0.intro.pd
+vibrato example
problems:
+click on minaturized subpatch fails to "vis" it
+startup flags need to handle spaces, duh.
+test MIDI I/O on all platforms, inc. sysex...
+'[' in numbox label breaks it (Yury Sept. 3)
+soundfiles with 3-byte samples buzz for the first readsf buffer (bug/x.pd)
+read xx.txt in "bad" gives warnings
+writesf -- "open" without "0" misses closing the previous file.
+Also writesf~ acts differently if DSP is off when "open" is sent?
qlist - 'next 1' seems not to work
-arrays of non-existent templates crash
-don't draw in/outlets on gui objects in graphs
-Alsa degradation after several hours running on soundblaster
+Krzysztof's qlist_next reentrancy bug
+don't draw in/outlets on gui objects in graph-on-parent
font size should depend on subpatch/abstraction
moving a bang toward top of window creates problem
-figure out O_NDELAY for linux audio?
-missed Thomas's multi-dialog trick???
check what happens when going back and forth between graph-on-parent
-deal with spaces in iemgui labels and send/receive names
get rid of messages causing renaming; try to prevent patches closing themselves.
-Krzysztof's qlist_next reentrancy bug
dac~/ adc~/ block~ incompatibility
scofo reports error on reading score1.txt
-data copy/paste doesn't check templates aren't changed
rfft~ loses nyquist bin -- see "to hell with it" comment in d_fft.c
+open_via_path() followed by close() fails in windows? [can't reproduce]
+loading e-mailed patches without removing headers crashes pd
+pd $1 bug ($1 is saved as it was evaluated, not as '$1')
+data copy/paste doesn't check templates aren't changed
+figure out why Pd sometimes crashes when you close example after adding fields
+
+next release:
+pixel font sizes
+pd to find running ones (pd -new to defeat)
+"enter" into object box to create new one (also, changing borders? forking?)
+tab to jump to a connected object (first one?) (shift-tab to back up?)
+portaudio v19?
+tables:
+ if there's just one array, don't do stringent hit check.
+ array click protection (Krzysztof's suggestion)
+ make graph labels persistent and add to dialog
+ object to get/set table size; random; quantile
+ flag to hide array names
+queued graphics updates for IEMGUIs and scalars
+document tabwrite~_start
+think of a way to embed abstractions in a patch
+make watchdog work for MACOSX
+GOP bounding box object
+IEMGUIs better default font size
+search path to include both calling patch and abstraction, if different
+abstraction reload shouldn't have to vis everyone
+addcomma message to message
+pasting should look at current mouse location
+delete-in-rectangle message to Pds
+put serial object in main dist (see rat@telecoma, Apr. 25; winfried May 22)
+open/save panel to take messages to init directory, and to set extent list
+flags to defeat pre-loading specified classes
+expr to parse exponential notation
+
data:
-allow field*2+5 etc. in drawing commands
+arrays of non-existent templates crash
+allow field(1,5,0,100) etc. in drawing commands
vget, vset traversal objects
cursor to show (x, y) location
-better hit detection (getrect is too greedy)
+better hit detection (getrect is too greedy; try tk's "current" tag for canvas)
click on points of plot
-typing at drawnumbers
+typing & dragging drawnumbers
fix templates to be loaded on demand and belong to a globally known patch
test and debug list elements of templates
sublists should display on parent if desired?
sublists seem not to handle canvas allocation right (get.pd->pointer.pd bug)
scalar hook to catch the mouse
protect against "plots" going away while you drag on them
-figure out why Pd sometimes crashes when you close example after adding fields
-features:
-command line flag to defeat loading objects
-signal inlets with initialized values...
-flag to hide array names
+more features:
+
+-Wno-unused to -Wno-unused-paramter and clean up unused automatic variables
+security module system in 2.6 - see the kernel module replacing jackstart
+signal inlets to sense signals; fix +~ etc, vcf~, biquad~, other filters
+mess with RME ALSA some more; ALSA readn doesn't work yet; use mmap?
+try to reduce startup time
+investigate gcc 3.3 warnings; try to reinstate -fstrict-aliasing
+message dialog not to disappear
+why does changing the name of an explode in jupiter patch take so long?
+close-subwindows menu item
+show results of opening audio and MIDI on dialogs
+windows escape from control-C
+settable netsend and netreceive port numbers
+new: abs~, nexttick~, extend threshold~ and snapshot~ (vthreshold~ etc)
+incorporate pddp doc
+try again to fix the font scene
+look at prctl(2) for FP exception handling
??? have a way to disambiguate externs from different libs???
-put serial object in main dist (see rat@telecoma, Apr. 25; winfried May 22)
-if there's just one array, don't do stringent hit check.
netsend separate thread
netreceive (and netsend?) message to set port number
-delete-in-rectangle message to Pds
-make selecting text grab keyboard focus
think about x and y scale preservation when changing between graph and object
show outlines of objects even when graph is "open"
-make graph labels persistent and add to dialog
-array click protection (Krzysztof's suggestion)
-increase MIDIQSIZE to at least 1024 in s_unix.c
-add nonblock to linux open calls instead of using alarm
graph_vis() to decorate graphs when they're toplevel (parent_glist == 0)
get graphs to expand to hold their contents
suita.chopin.edu.pl/~czaja/miXed/externs/xeq.html -- MIDI file reader
in glist_delete, consider why this can't be just "vis 0" -- why do we need it?
-abstraction auto-reload
closebang
-switching between dac and gettimeofday timing on dsp_start/stop
check that -blocksize really reflects in audiobuf calc for Hammerfall
--version to print version and exit; usage() also to print version
-NT and OSX: opening HTML files?
-MIDI file reading/writing?
makefile to have make install depend on make local.
-pd messages to close and reopen sound driver
Float method for random
figure out list, message objects
separate control over alsaindev and alsaoutdev
-pd -version
-make "import"/export use IEMLIB objects
-object to get/set table size; random; quantile
put in something for tilde order forcing
extensible "toolbar" so people can add external GUI objects
-text cut and paste; see XStoreBytes
-new objects: nexttick~, extend threshold~ and snapshot~
allow spaces in paths
-gem: try XSetBorderWidth, XMoveWindow, xcopyarea (/usr/share/doc/XF*)
-dialog for audio and MIDI settings
-prepend help to help filenames and add help search path
-read/writesf~ for NT
variable send and receive -- check how max/MSP does it?
number boxes to darken for typing and/or received messages
-delayed updates
-invisible toplevels
dialog to change lib flag and path
-fastedit moves
pique~ and fiddle~ unification (notice pique filtering is different!)
new message box look
figure out what to do when "pd sym" conflicts with window title as in Pluton?
@@ -137,8 +149,6 @@ MAX compatibilty:
trigger 1 (on Pd, outputs 0; on Max?)
LATER
-Hammerfall adapt to ALSA
-+~ 0 faster than +~ -- detect scalar input; also, order forcing inputs
bonk~ file path handling
unify arrays and garrays
dialog to give values of $1, ... for the canvas
diff --git a/pd/src/s_audio.c b/pd/src/s_audio.c
index 9e0c4b01..90500790 100644
--- a/pd/src/s_audio.c
+++ b/pd/src/s_audio.c
@@ -9,7 +9,7 @@
#include "m_pd.h"
#include "s_stuff.h"
#include <stdio.h>
-#ifdef UNIX
+#ifdef UNISTD
#include <unistd.h>
#include <sys/time.h>
#include <sys/resource.h>
@@ -20,7 +20,6 @@
#define SYS_DEFAULTCH 2
#define SYS_MAXCH 100
-#define SYS_DEFAULTSRATE 44100
typedef long t_pa_sample;
#define SYS_SAMPLEWIDTH sizeof(t_pa_sample)
#define SYS_BYTESPERCHAN (DEFDACBLKSIZE * SYS_SAMPLEWIDTH)
@@ -31,24 +30,18 @@ typedef long t_pa_sample;
even to zero, in the system dependent open_audio routines. */
int sys_inchannels;
int sys_outchannels;
-int sys_advance_samples; /* scheduler advance in samples */
-int sys_blocksize = 0; /* audio I/O block size in sample frames */
+int sys_advance_samples; /* scheduler advance in samples */
+int sys_blocksize = 0; /* audio I/O block size in sample frames */
int sys_audioapi = API_DEFAULT;
-static int sys_meters; /* true if we're metering */
-static float sys_inmax; /* max input amplitude */
-static float sys_outmax; /* max output amplitude */
+static int sys_meters; /* true if we're metering */
+static float sys_inmax; /* max input amplitude */
+static float sys_outmax; /* max output amplitude */
/* exported variables */
-int sys_schedadvance; /* scheduler advance in microseconds */
+int sys_schedadvance; /* scheduler advance in microseconds */
float sys_dacsr;
-#ifdef MACOSX
-int sys_hipriority = 1;
-#else
-int sys_hipriority = 0;
-#endif
-
t_sample *sys_soundout;
t_sample *sys_soundin;
@@ -58,10 +51,10 @@ t_sample *sys_soundin;
static int audio_state;
/* last requested parameters */
-static int audio_naudioindev;
+static int audio_naudioindev = -1;
static int audio_audioindev[MAXAUDIOINDEV];
static int audio_audiochindev[MAXAUDIOINDEV];
-static int audio_naudiooutdev;
+static int audio_naudiooutdev = -1;
static int audio_audiooutdev[MAXAUDIOOUTDEV];
static int audio_audiochoutdev[MAXAUDIOOUTDEV];
static int audio_rate;
@@ -70,11 +63,11 @@ static int audio_advance;
static int audio_isopen(void)
{
return (audio_state &&
- ((audio_naudioindev > 0 && audio_audiochindev[0] > 0)
- || (audio_naudiooutdev > 0 && audio_audiochoutdev[0] > 0)));
+ ((audio_naudioindev > 0 && audio_audiochindev[0] > 0)
+ || (audio_naudiooutdev > 0 && audio_audiochoutdev[0] > 0)));
}
-static void sys_get_audio_params(
+void sys_get_audio_params(
int *pnaudioindev, int *paudioindev, int *chindev,
int *pnaudiooutdev, int *paudiooutdev, int *choutdev,
int *prate, int *padvance)
@@ -82,17 +75,17 @@ static void sys_get_audio_params(
int i;
*pnaudioindev = audio_naudioindev;
for (i = 0; i < MAXAUDIOINDEV; i++)
- paudioindev[i] = audio_audioindev[i],
- chindev[i] = audio_audiochindev[i];
+ paudioindev[i] = audio_audioindev[i],
+ chindev[i] = audio_audiochindev[i];
*pnaudiooutdev = audio_naudiooutdev;
for (i = 0; i < MAXAUDIOOUTDEV; i++)
- paudiooutdev[i] = audio_audiooutdev[i],
- choutdev[i] = audio_audiochoutdev[i];
+ paudiooutdev[i] = audio_audiooutdev[i],
+ choutdev[i] = audio_audiochoutdev[i];
*prate = audio_rate;
*padvance = audio_advance;
}
-static void sys_save_audio_params(
+void sys_save_audio_params(
int naudioindev, int *audioindev, int *chindev,
int naudiooutdev, int *audiooutdev, int *choutdev,
int rate, int advance)
@@ -100,12 +93,12 @@ static void sys_save_audio_params(
int i;
audio_naudioindev = naudioindev;
for (i = 0; i < MAXAUDIOINDEV; i++)
- audio_audioindev[i] = audioindev[i],
- audio_audiochindev[i] = chindev[i];
+ audio_audioindev[i] = audioindev[i],
+ audio_audiochindev[i] = chindev[i];
audio_naudiooutdev = naudiooutdev;
for (i = 0; i < MAXAUDIOOUTDEV; i++)
- audio_audiooutdev[i] = audiooutdev[i],
- audio_audiochoutdev[i] = choutdev[i];
+ audio_audiooutdev[i] = audiooutdev[i],
+ audio_audiochoutdev[i] = choutdev[i];
audio_rate = rate;
audio_advance = advance;
}
@@ -120,7 +113,7 @@ static void audio_init( void)
{
static int initted = 0;
if (initted)
- return;
+ return;
initted = 1;
#ifdef USEAPI_OSS
oss_init();
@@ -129,7 +122,7 @@ static void audio_init( void)
/* set channels and sample rate. */
-static void sys_setchsr(int chin, int chout, int sr)
+void sys_setchsr(int chin, int chout, int sr)
{
int nblk;
int inbytes = (chin ? chin : 2) * (DEFDACBLKSIZE*sizeof(float));
@@ -140,21 +133,21 @@ static void sys_setchsr(int chin, int chout, int sr)
sys_dacsr = sr;
sys_advance_samples = (sys_schedadvance * sys_dacsr) / (1000000.);
if (sys_advance_samples < 3 * DEFDACBLKSIZE)
- sys_advance_samples = 3 * DEFDACBLKSIZE;
+ sys_advance_samples = 3 * DEFDACBLKSIZE;
if (sys_soundin)
- free(sys_soundin);
+ free(sys_soundin);
sys_soundin = (t_float *)malloc(inbytes);
memset(sys_soundin, 0, inbytes);
if (sys_soundout)
- free(sys_soundout);
+ free(sys_soundout);
sys_soundout = (t_float *)malloc(outbytes);
memset(sys_soundout, 0, outbytes);
if (sys_verbose)
- post("input channels = %d, output channels = %d",
- sys_inchannels, sys_outchannels);
+ post("input channels = %d, output channels = %d",
+ sys_inchannels, sys_outchannels);
canvas_resume_dsp(canvas_suspend_dsp());
}
@@ -172,170 +165,188 @@ void sys_open_audio(int naudioindev, int *audioindev, int nchindev,
int i, *ip;
int defaultchannels = SYS_DEFAULTCH;
int inchans, outchans;
+ int realinchans[MAXAUDIOINDEV], realoutchans[MAXAUDIOOUTDEV];
+
+ /* jsarlo { (*/
+ if (sys_externalschedlib)
+ {
+ return;
+ }
+ /* if we're already open close it */
+ if (sys_inchannels || sys_outchannels)
+ sys_close_audio();
+
+ /* } jsarlo */
if (rate < 1)
- rate = SYS_DEFAULTSRATE;
- audio_init();
- /* Since the channel vector might be longer than the
- audio device vector, or vice versa, we fill the shorter one
- in to match the longer one. Also, if both are empty, we fill in
- one device (the default) and two channels. */
+ rate = DEFAULTSRATE;
+ if (advance <= 0)
+ advance = DEFAULTADVANCE;
+ audio_init();
+ /* Since the channel vector might be longer than the
+ audio device vector, or vice versa, we fill the shorter one
+ in to match the longer one. Also, if both are empty, we fill in
+ one device (the default) and two channels. */
if (naudioindev == -1)
- { /* no input audio devices specified */
- if (nchindev == -1)
- {
- nchindev=1;
- chindev[0] = defaultchannels;
- naudioindev = 1;
- audioindev[0] = DEFAULTAUDIODEV;
- }
- else
- {
- for (i = 0; i < MAXAUDIOINDEV; i++)
- audioindev[i] = i;
- naudioindev = nchindev;
- }
+ { /* no input audio devices specified */
+ if (nchindev == -1)
+ {
+ nchindev=1;
+ chindev[0] = defaultchannels;
+ naudioindev = 1;
+ audioindev[0] = DEFAULTAUDIODEV;
+ }
+ else
+ {
+ for (i = 0; i < MAXAUDIOINDEV; i++)
+ audioindev[i] = i;
+ naudioindev = nchindev;
+ }
}
else
{
- if (nchindev == -1)
- {
- nchindev = naudioindev;
- for (i = 0; i < naudioindev; i++)
- chindev[i] = defaultchannels;
- }
- else if (nchindev > naudioindev)
- {
- for (i = naudioindev; i < nchindev; i++)
- {
- if (i == 0)
- audioindev[0] = DEFAULTAUDIODEV;
- else audioindev[i] = audioindev[i-1] + 1;
- }
- naudioindev = nchindev;
- }
- else if (nchindev < naudioindev)
- {
- for (i = nchindev; i < naudioindev; i++)
- {
- if (i == 0)
- chindev[0] = defaultchannels;
- else chindev[i] = chindev[i-1];
- }
- naudioindev = nchindev;
- }
+ if (nchindev == -1)
+ {
+ nchindev = naudioindev;
+ for (i = 0; i < naudioindev; i++)
+ chindev[i] = defaultchannels;
+ }
+ else if (nchindev > naudioindev)
+ {
+ for (i = naudioindev; i < nchindev; i++)
+ {
+ if (i == 0)
+ audioindev[0] = DEFAULTAUDIODEV;
+ else audioindev[i] = audioindev[i-1] + 1;
+ }
+ naudioindev = nchindev;
+ }
+ else if (nchindev < naudioindev)
+ {
+ for (i = nchindev; i < naudioindev; i++)
+ {
+ if (i == 0)
+ chindev[0] = defaultchannels;
+ else chindev[i] = chindev[i-1];
+ }
+ naudioindev = nchindev;
+ }
}
if (naudiooutdev == -1)
- { /* not set */
- if (nchoutdev == -1)
- {
- nchoutdev=1;
- choutdev[0]=defaultchannels;
- naudiooutdev=1;
- audiooutdev[0] = DEFAULTAUDIODEV;
- }
- else
- {
- for (i = 0; i < MAXAUDIOOUTDEV; i++)
- audiooutdev[i] = i;
- naudiooutdev = nchoutdev;
- }
+ { /* not set */
+ if (nchoutdev == -1)
+ {
+ nchoutdev=1;
+ choutdev[0]=defaultchannels;
+ naudiooutdev=1;
+ audiooutdev[0] = DEFAULTAUDIODEV;
+ }
+ else
+ {
+ for (i = 0; i < MAXAUDIOOUTDEV; i++)
+ audiooutdev[i] = i;
+ naudiooutdev = nchoutdev;
+ }
}
else
{
- if (nchoutdev == -1)
- {
- nchoutdev = naudiooutdev;
- for (i = 0; i < naudiooutdev; i++)
- choutdev[i] = defaultchannels;
- }
- else if (nchoutdev > naudiooutdev)
- {
- for (i = naudiooutdev; i < nchoutdev; i++)
- {
- if (i == 0)
- audiooutdev[0] = DEFAULTAUDIODEV;
- else audiooutdev[i] = audiooutdev[i-1] + 1;
- }
- naudiooutdev = nchoutdev;
- }
- else if (nchoutdev < naudiooutdev)
- {
- for (i = nchoutdev; i < naudiooutdev; i++)
- {
- if (i == 0)
- choutdev[0] = defaultchannels;
- else choutdev[i] = choutdev[i-1];
- }
- naudiooutdev = nchoutdev;
- }
- }
-
- /* count total number of input and output channels */
+ if (nchoutdev == -1)
+ {
+ nchoutdev = naudiooutdev;
+ for (i = 0; i < naudiooutdev; i++)
+ choutdev[i] = defaultchannels;
+ }
+ else if (nchoutdev > naudiooutdev)
+ {
+ for (i = naudiooutdev; i < nchoutdev; i++)
+ {
+ if (i == 0)
+ audiooutdev[0] = DEFAULTAUDIODEV;
+ else audiooutdev[i] = audiooutdev[i-1] + 1;
+ }
+ naudiooutdev = nchoutdev;
+ }
+ else if (nchoutdev < naudiooutdev)
+ {
+ for (i = nchoutdev; i < naudiooutdev; i++)
+ {
+ if (i == 0)
+ choutdev[0] = defaultchannels;
+ else choutdev[i] = choutdev[i-1];
+ }
+ naudiooutdev = nchoutdev;
+ }
+ }
+
+ /* count total number of input and output channels */
for (i = inchans = 0; i < naudioindev; i++)
- inchans += chindev[i];
+ inchans += (realinchans[i] = (chindev[i] > 0 ? chindev[i] : 0));
for (i = outchans = 0; i < naudiooutdev; i++)
- outchans += choutdev[i];
- /* if no input or output devices seem to have been specified,
- this really means just disable audio, which we now do. Meanwhile,
- we can set audio input and output devices to their defaults. */
+ outchans += (realoutchans[i] = (choutdev[i] > 0 ? choutdev[i] : 0));
+ /* if no input or output devices seem to have been specified,
+ this really means just disable audio, which we now do. */
if (!inchans && !outchans)
- {
- enable = 0;
- naudioindev = nchindev = naudiooutdev = nchoutdev = 1;
- audioindev[0] = audiooutdev[0] = DEFAULTAUDIODEV;
- chindev[0] = choutdev[0] = 0;
- }
+ enable = 0;
sys_schedadvance = advance * 1000;
sys_setchsr(inchans, outchans, rate);
sys_log_error(ERR_NOTHING);
-
- if (enable && (inchans > 0 || outchans > 0))
+ if (enable)
{
#ifdef USEAPI_PORTAUDIO
- if (sys_audioapi == API_PORTAUDIO)
- {
- int blksize = (sys_blocksize ? sys_blocksize : 64);
- pa_open_audio(inchans, outchans, rate, sys_soundin, sys_soundout,
- blksize, sys_advance_samples/blksize,
- (naudiooutdev > 0 ? audioindev[0] : 0),
- (naudiooutdev > 0 ? audiooutdev[0] : 0));
- }
+ if (sys_audioapi == API_PORTAUDIO)
+ {
+ int blksize = (sys_blocksize ? sys_blocksize : 64);
+ pa_open_audio(inchans, outchans, rate, sys_soundin, sys_soundout,
+ blksize, sys_advance_samples/blksize,
+ (naudiooutdev > 0 ? audioindev[0] : 0),
+ (naudiooutdev > 0 ? audiooutdev[0] : 0));
+ }
else
#endif
#ifdef USEAPI_JACK
- if (sys_audioapi == API_JACK)
- jack_open_audio((naudioindev > 0 ? chindev[0] : 0),
- (naudiooutdev > 0 ? choutdev[0] : 0), rate);
+ if (sys_audioapi == API_JACK)
+ jack_open_audio((naudioindev > 0 ? realinchans[0] : 0),
+ (naudiooutdev > 0 ? realoutchans[0] : 0), rate);
- else
-#endif
+ else
+#endif
#ifdef USEAPI_OSS
- if (sys_audioapi == API_OSS)
- oss_open_audio(naudioindev, audioindev, nchindev, chindev,
- naudiooutdev, audiooutdev, nchoutdev, choutdev, rate);
- else
+ if (sys_audioapi == API_OSS)
+ oss_open_audio(naudioindev, audioindev, nchindev, realinchans,
+ naudiooutdev, audiooutdev, nchoutdev, realoutchans, rate);
+ else
#endif
#ifdef USEAPI_ALSA
- /* for alsa, only one device is supported; it may
- be open for both input and output. */
- if (sys_audioapi == API_ALSA)
- alsa_open_audio(naudioindev, audioindev, nchindev, chindev,
- naudiooutdev, audiooutdev, nchoutdev, choutdev, rate);
- else
+ /* for alsa, only one device is supported; it may
+ be open for both input and output. */
+ if (sys_audioapi == API_ALSA)
+ alsa_open_audio(naudioindev, audioindev, nchindev, realinchans,
+ naudiooutdev, audiooutdev, nchoutdev, realoutchans, rate);
+ else
+#endif
+#ifdef USEAPI_SGI
+ if (sys_audioapi == API_SGI)
+ {
+ xtern int sgi_open_audio(int nindev, int *indev, int nchin,
+ int *chin, int noutdev, int *outdev, int nchout, int *chout,
+ int rate);
+ sgi_open_audio(naudioindev, audioindev, nchindev, chindev,
+ naudiooutdev, audiooutdev, nchoutdev, choutdev, rate);
+ }
+ else
#endif
#ifdef USEAPI_MMIO
- if (sys_audioapi == API_MMIO)
- mmio_open_audio(naudioindev, audioindev, nchindev, chindev,
- naudiooutdev, audiooutdev, nchoutdev, choutdev, rate);
- else
+ if (sys_audioapi == API_MMIO)
+ mmio_open_audio(naudioindev, audioindev, nchindev, realinchans,
+ naudiooutdev, audiooutdev, nchoutdev, realoutchans, rate);
+ else
#endif
- post("unknown audio API specified");
+ post("unknown audio API specified");
}
sys_save_audio_params(naudioindev, audioindev, chindev,
- naudiooutdev, audiooutdev, choutdev, rate, advance);
+ naudiooutdev, audiooutdev, choutdev, sys_dacsr, advance);
if (sys_inchannels == 0 && sys_outchannels == 0)
- enable = 0;
+ enable = 0;
audio_state = enable;
sys_vgui("set pd_whichapi %d\n", (audio_isopen() ? sys_audioapi : 0));
sched_set_using_dacs(enable);
@@ -343,34 +354,48 @@ else
void sys_close_audio(void)
{
+ /* jsarlo { (*/
+ if (sys_externalschedlib)
+ {
+ return;
+ }
+ /* } jsarlo */
if (!audio_isopen())
- return;
+ return;
#ifdef USEAPI_PORTAUDIO
if (sys_audioapi == API_PORTAUDIO)
- pa_close_audio();
+ pa_close_audio();
else
#endif
#ifdef USEAPI_JACK
if (sys_audioapi == API_JACK)
- jack_close_audio();
+ jack_close_audio();
else
#endif
#ifdef USEAPI_OSS
if (sys_audioapi == API_OSS)
- oss_close_audio();
+ oss_close_audio();
else
#endif
#ifdef USEAPI_ALSA
if (sys_audioapi == API_ALSA)
- alsa_close_audio();
+ alsa_close_audio();
+ else
+#endif
+#ifdef USEAPI_SGI
+ if (sys_audioapi == API_SGI)
+ {
+ extern void sgi_close_audio(void);
+ sgi_close_audio();
+ }
else
#endif
#ifdef USEAPI_MMIO
if (sys_audioapi == API_MMIO)
- mmio_close_audio();
+ mmio_close_audio();
else
#endif
- post("sys_close_audio: unknown API %d", sys_audioapi);
+ post("sys_close_audio: unknown API %d", sys_audioapi);
sys_inchannels = sys_outchannels = 0;
}
@@ -381,58 +406,66 @@ void sys_reopen_audio( void)
int naudiooutdev, audiooutdev[MAXAUDIOOUTDEV], choutdev[MAXAUDIOOUTDEV];
int rate, advance;
sys_get_audio_params(&naudioindev, audioindev, chindev,
- &naudiooutdev, audiooutdev, choutdev, &rate, &advance);
+ &naudiooutdev, audiooutdev, choutdev, &rate, &advance);
sys_open_audio(naudioindev, audioindev, naudioindev, chindev,
- naudiooutdev, audiooutdev, naudiooutdev, choutdev, rate, advance, 1);
+ naudiooutdev, audiooutdev, naudiooutdev, choutdev, rate, advance, 1);
}
int sys_send_dacs(void)
{
if (sys_meters)
{
- int i, n;
- float maxsamp;
- for (i = 0, n = sys_inchannels * DEFDACBLKSIZE, maxsamp = sys_inmax;
- i < n; i++)
- {
- float f = sys_soundin[i];
- if (f > maxsamp) maxsamp = f;
- else if (-f > maxsamp) maxsamp = -f;
- }
- sys_inmax = maxsamp;
- for (i = 0, n = sys_outchannels * DEFDACBLKSIZE, maxsamp = sys_outmax;
- i < n; i++)
- {
- float f = sys_soundout[i];
- if (f > maxsamp) maxsamp = f;
- else if (-f > maxsamp) maxsamp = -f;
- }
- sys_outmax = maxsamp;
+ int i, n;
+ float maxsamp;
+ for (i = 0, n = sys_inchannels * DEFDACBLKSIZE, maxsamp = sys_inmax;
+ i < n; i++)
+ {
+ float f = sys_soundin[i];
+ if (f > maxsamp) maxsamp = f;
+ else if (-f > maxsamp) maxsamp = -f;
+ }
+ sys_inmax = maxsamp;
+ for (i = 0, n = sys_outchannels * DEFDACBLKSIZE, maxsamp = sys_outmax;
+ i < n; i++)
+ {
+ float f = sys_soundout[i];
+ if (f > maxsamp) maxsamp = f;
+ else if (-f > maxsamp) maxsamp = -f;
+ }
+ sys_outmax = maxsamp;
}
#ifdef USEAPI_PORTAUDIO
if (sys_audioapi == API_PORTAUDIO)
- return (pa_send_dacs());
+ return (pa_send_dacs());
else
#endif
#ifdef USEAPI_JACK
if (sys_audioapi == API_JACK)
- return (jack_send_dacs());
+ return (jack_send_dacs());
else
#endif
#ifdef USEAPI_OSS
if (sys_audioapi == API_OSS)
- return (oss_send_dacs());
+ return (oss_send_dacs());
else
#endif
#ifdef USEAPI_ALSA
if (sys_audioapi == API_ALSA)
- return (alsa_send_dacs());
+ return (alsa_send_dacs());
+ else
+#endif
+#ifdef USEAPI_SGI
+ if (sys_audioapi == API_SGI)
+ {
+ extern int sgi_send_dacs(void);
+ return (sgi_send_dacs());
+ }
else
#endif
#ifdef USEAPI_MMIO
if (sys_audioapi == API_MMIO)
- return (mmio_send_dacs());
+ return (mmio_send_dacs());
else
#endif
post("unknown API");
@@ -454,24 +487,16 @@ int sys_get_inchannels(void)
return (sys_inchannels);
}
-void sys_audiobuf(int n)
-{
- /* set the size, in milliseconds, of the audio FIFO */
- if (n < 5) n = 5;
- else if (n > 5000) n = 5000;
- sys_schedadvance = n * 1000;
-}
-
void sys_getmeters(float *inmax, float *outmax)
{
if (inmax)
{
- sys_meters = 1;
- *inmax = sys_inmax;
- *outmax = sys_outmax;
+ sys_meters = 1;
+ *inmax = sys_inmax;
+ *outmax = sys_outmax;
}
else
- sys_meters = 0;
+ sys_meters = 0;
sys_inmax = sys_outmax = 0;
}
@@ -484,57 +509,76 @@ void sys_reportidle(void)
static void audio_getdevs(char *indevlist, int *nindevs,
char *outdevlist, int *noutdevs, int *canmulti,
- int maxndev, int devdescsize)
+ int maxndev, int devdescsize)
{
audio_init();
+#ifdef USEAPI_PORTAUDIO
+ if (sys_audioapi == API_PORTAUDIO)
+ {
+ pa_getdevs(indevlist, nindevs, outdevlist, noutdevs, canmulti,
+ maxndev, devdescsize);
+ }
+ else
+#endif
+#ifdef USEAPI_JACK
+ if (sys_audioapi == API_JACK)
+ {
+ jack_getdevs(indevlist, nindevs, outdevlist, noutdevs, canmulti,
+ maxndev, devdescsize);
+ }
+ else
+#endif
#ifdef USEAPI_OSS
if (sys_audioapi == API_OSS)
{
- oss_getdevs(indevlist, nindevs, outdevlist, noutdevs, canmulti,
- maxndev, devdescsize);
+ oss_getdevs(indevlist, nindevs, outdevlist, noutdevs, canmulti,
+ maxndev, devdescsize);
}
else
#endif
#ifdef USEAPI_ALSA
if (sys_audioapi == API_ALSA)
{
- alsa_getdevs(indevlist, nindevs, outdevlist, noutdevs, canmulti,
- maxndev, devdescsize);
+ alsa_getdevs(indevlist, nindevs, outdevlist, noutdevs, canmulti,
+ maxndev, devdescsize);
}
else
#endif
-#ifdef USEAPI_PORTAUDIO
- if (sys_audioapi == API_PORTAUDIO)
+#ifdef USEAPI_SGI
+ if (sys_audioapi == API_SGI)
{
- pa_getdevs(indevlist, nindevs, outdevlist, noutdevs, canmulti,
- maxndev, devdescsize);
+ extern void sgi_getdevs(char *indevlist, int *nindevs,
+ char *outdevlist, int *noutdevs, int *canmulti,
+ int maxndev, int devdescsize);
+ sgi_getdevs(indevlist, nindevs, outdevlist, noutdevs, canmulti,
+ maxndev, devdescsize);
}
else
#endif
#ifdef USEAPI_MMIO
if (sys_audioapi == API_MMIO)
{
- mmio_getdevs(indevlist, nindevs, outdevlist, noutdevs, canmulti,
- maxndev, devdescsize);
+ mmio_getdevs(indevlist, nindevs, outdevlist, noutdevs, canmulti,
+ maxndev, devdescsize);
}
else
#endif
{
- /* this shouldn't happen once all the above get filled in. */
- int i;
- *nindevs = *noutdevs = 3;
- for (i = 0; i < 3; i++)
- {
- sprintf(indevlist + i * devdescsize, "input device #%d", i+1);
- sprintf(outdevlist + i * devdescsize, "output device #%d", i+1);
- }
- *canmulti = 0;
+ /* this shouldn't happen once all the above get filled in. */
+ int i;
+ *nindevs = *noutdevs = 3;
+ for (i = 0; i < 3; i++)
+ {
+ sprintf(indevlist + i * devdescsize, "input device #%d", i+1);
+ sprintf(outdevlist + i * devdescsize, "output device #%d", i+1);
+ }
+ *canmulti = 0;
}
}
#ifdef MSW
#define DEVONSET 0 /* microsoft device list starts at 0 (the "mapper"). */
-#else /* (see also MSW ifdef in sys_parsedevlist(), s_main.c) */
+#else /* (see also MSW ifdef in sys_parsedevlist(), s_main.c) */
#define DEVONSET 1 /* To agree with command line flags, normally start at 1 */
#endif
@@ -544,23 +588,23 @@ static void sys_listaudiodevs(void )
int nindevs = 0, noutdevs = 0, i, canmulti = 0;
audio_getdevs(indevlist, &nindevs, outdevlist, &noutdevs, &canmulti,
- MAXNDEV, DEVDESCSIZE);
+ MAXNDEV, DEVDESCSIZE);
if (!nindevs)
- post("no audio input devices found");
+ post("no audio input devices found");
else
{
- post("input devices:");
- for (i = 0; i < nindevs; i++)
- post("%d. %s", i+1, indevlist + i * DEVDESCSIZE);
+ post("input devices:");
+ for (i = 0; i < nindevs; i++)
+ post("%d. %s", i+1, indevlist + i * DEVDESCSIZE);
}
if (!noutdevs)
- post("no audio output devices found");
+ post("no audio output devices found");
else
{
- post("output devices:");
- for (i = 0; i < noutdevs; i++)
- post("%d. %s", i + DEVONSET, outdevlist + i * DEVDESCSIZE);
+ post("output devices:");
+ for (i = 0; i < noutdevs; i++)
+ post("%d. %s", i + DEVONSET, outdevlist + i * DEVDESCSIZE);
}
post("API number %d\n", sys_audioapi);
}
@@ -569,49 +613,49 @@ static void sys_listaudiodevs(void )
void glob_audio_properties(t_pd *dummy, t_floatarg flongform)
{
char buf[1024 + 2 * MAXNDEV*(DEVDESCSIZE+4)];
- /* these are the devices you're using: */
+ /* these are the devices you're using: */
int naudioindev, audioindev[MAXAUDIOINDEV], chindev[MAXAUDIOINDEV];
int naudiooutdev, audiooutdev[MAXAUDIOOUTDEV], choutdev[MAXAUDIOOUTDEV];
int audioindev1, audioindev2, audioindev3, audioindev4,
- audioinchan1, audioinchan2, audioinchan3, audioinchan4,
- audiooutdev1, audiooutdev2, audiooutdev3, audiooutdev4,
- audiooutchan1, audiooutchan2, audiooutchan3, audiooutchan4;
+ audioinchan1, audioinchan2, audioinchan3, audioinchan4,
+ audiooutdev1, audiooutdev2, audiooutdev3, audiooutdev4,
+ audiooutchan1, audiooutchan2, audiooutchan3, audiooutchan4;
int rate, advance;
- /* these are all the devices on your system: */
+ /* these are all the devices on your system: */
char indevlist[MAXNDEV*DEVDESCSIZE], outdevlist[MAXNDEV*DEVDESCSIZE];
int nindevs = 0, noutdevs = 0, canmulti = 0, i;
char indevliststring[MAXNDEV*(DEVDESCSIZE+4)+80],
- outdevliststring[MAXNDEV*(DEVDESCSIZE+4)+80];
+ outdevliststring[MAXNDEV*(DEVDESCSIZE+4)+80];
audio_getdevs(indevlist, &nindevs, outdevlist, &noutdevs, &canmulti,
- MAXNDEV, DEVDESCSIZE);
+ MAXNDEV, DEVDESCSIZE);
strcpy(indevliststring, "{");
for (i = 0; i < nindevs; i++)
{
- strcat(indevliststring, "\"");
- strcat(indevliststring, indevlist + i * DEVDESCSIZE);
- strcat(indevliststring, "\" ");
+ strcat(indevliststring, "\"");
+ strcat(indevliststring, indevlist + i * DEVDESCSIZE);
+ strcat(indevliststring, "\" ");
}
strcat(indevliststring, "}");
strcpy(outdevliststring, "{");
for (i = 0; i < noutdevs; i++)
{
- strcat(outdevliststring, "\"");
- strcat(outdevliststring, outdevlist + i * DEVDESCSIZE);
- strcat(outdevliststring, "\" ");
+ strcat(outdevliststring, "\"");
+ strcat(outdevliststring, outdevlist + i * DEVDESCSIZE);
+ strcat(outdevliststring, "\" ");
}
strcat(outdevliststring, "}");
sys_get_audio_params(&naudioindev, audioindev, chindev,
- &naudiooutdev, audiooutdev, choutdev, &rate, &advance);
+ &naudiooutdev, audiooutdev, choutdev, &rate, &advance);
/* post("naudioindev %d naudiooutdev %d longform %f",
- naudioindev, naudiooutdev, flongform); */
+ naudioindev, naudiooutdev, flongform); */
if (naudioindev > 1 || naudiooutdev > 1)
- flongform = 1;
+ flongform = 1;
audioindev1 = (naudioindev > 0 && audioindev[0]>= 0 ? audioindev[0] : 0);
@@ -635,13 +679,13 @@ void glob_audio_properties(t_pd *dummy, t_floatarg flongform)
%s %d %d %d %d %d %d %d %d \
%s %d %d %d %d %d %d %d %d \
%d %d %d %d\n",
- indevliststring,
- audioindev1, audioindev2, audioindev3, audioindev4,
- audioinchan1, audioinchan2, audioinchan3, audioinchan4,
- outdevliststring,
- audiooutdev1, audiooutdev2, audiooutdev3, audiooutdev4,
- audiooutchan1, audiooutchan2, audiooutchan3, audiooutchan4,
- rate, advance, canmulti, (flongform != 0));
+ indevliststring,
+ audioindev1, audioindev2, audioindev3, audioindev4,
+ audioinchan1, audioinchan2, audioinchan3, audioinchan4,
+ outdevliststring,
+ audiooutdev1, audiooutdev2, audiooutdev3, audiooutdev4,
+ audiooutchan1, audiooutchan2, audiooutchan3, audiooutchan4,
+ rate, advance, canmulti, (flongform != 0));
gfxstub_deleteforkey(0);
gfxstub_new(&glob_pdobject, glob_audio_properties, buf);
}
@@ -654,74 +698,80 @@ void glob_audio_dialog(t_pd *dummy, t_symbol *s, int argc, t_atom *argv)
int rate, advance, audioon, i, nindev, noutdev;
int audioindev1, audioinchan1, audiooutdev1, audiooutchan1;
int newaudioindev[4], newaudioinchan[4],
- newaudiooutdev[4], newaudiooutchan[4];
- /* the new values the dialog came back with: */
+ newaudiooutdev[4], newaudiooutchan[4];
+ /* the new values the dialog came back with: */
int newrate = atom_getintarg(16, argc, argv);
int newadvance = atom_getintarg(17, argc, argv);
int statewas;
for (i = 0; i < 4; i++)
{
- newaudioindev[i] = atom_getintarg(i, argc, argv);
- newaudioinchan[i] = atom_getintarg(i+4, argc, argv);
- newaudiooutdev[i] = atom_getintarg(i+8, argc, argv);
- newaudiooutchan[i] = atom_getintarg(i+12, argc, argv);
+ newaudioindev[i] = atom_getintarg(i, argc, argv);
+ newaudioinchan[i] = atom_getintarg(i+4, argc, argv);
+ newaudiooutdev[i] = atom_getintarg(i+8, argc, argv);
+ newaudiooutchan[i] = atom_getintarg(i+12, argc, argv);
}
for (i = 0, nindev = 0; i < 4; i++)
{
- if (newaudioinchan[i] > 0)
- {
- newaudioindev[nindev] = newaudioindev[i];
- newaudioinchan[nindev] = newaudioinchan[i];
- /* post("in %d %d %d", nindev,
- newaudioindev[nindev] , newaudioinchan[nindev]); */
- nindev++;
- }
+ if (newaudioinchan[i])
+ {
+ newaudioindev[nindev] = newaudioindev[i];
+ newaudioinchan[nindev] = newaudioinchan[i];
+ /* post("in %d %d %d", nindev,
+ newaudioindev[nindev] , newaudioinchan[nindev]); */
+ nindev++;
+ }
}
for (i = 0, noutdev = 0; i < 4; i++)
{
- if (newaudiooutchan[i] > 0)
- {
- newaudiooutdev[noutdev] = newaudiooutdev[i];
- newaudiooutchan[noutdev] = newaudiooutchan[i];
- /* post("out %d %d %d", noutdev,
- newaudiooutdev[noutdev] , newaudioinchan[noutdev]); */
- noutdev++;
- }
+ if (newaudiooutchan[i])
+ {
+ newaudiooutdev[noutdev] = newaudiooutdev[i];
+ newaudiooutchan[noutdev] = newaudiooutchan[i];
+ /* post("out %d %d %d", noutdev,
+ newaudiooutdev[noutdev] , newaudioinchan[noutdev]); */
+ noutdev++;
+ }
}
sys_close_audio();
sys_open_audio(nindev, newaudioindev, nindev, newaudioinchan,
- noutdev, newaudiooutdev, noutdev, newaudiooutchan,
- newrate, newadvance, 1);
+ noutdev, newaudiooutdev, noutdev, newaudiooutchan,
+ newrate, newadvance, 1);
}
void sys_listdevs(void )
{
#ifdef USEAPI_PORTAUDIO
if (sys_audioapi == API_PORTAUDIO)
- sys_listaudiodevs();
+ sys_listaudiodevs();
else
#endif
#ifdef USEAPI_JACK
if (sys_audioapi == API_JACK)
- jack_listdevs();
+ jack_listdevs();
else
#endif
#ifdef USEAPI_OSS
if (sys_audioapi == API_OSS)
- sys_listaudiodevs();
- else
-#endif
-#ifdef USEAPI_MMIO
- if (sys_audioapi == API_MMIO)
- sys_listaudiodevs();
+ sys_listaudiodevs();
else
#endif
#ifdef USEAPI_ALSA
if (sys_audioapi == API_ALSA)
- sys_listaudiodevs();
+ sys_listaudiodevs();
+ else
+#endif
+#ifdef USEAPI_SGI
+ extern void sgi_listaudiodevs(void);
+ if (sys_audioapi == API_SGI)
+ sgi_listaudiodevs();
+ else
+#endif
+#ifdef USEAPI_MMIO
+ if (sys_audioapi == API_MMIO)
+ sys_listaudiodevs();
else
#endif
post("unknown API");
@@ -732,10 +782,10 @@ void sys_listdevs(void )
void sys_setblocksize(int n)
{
if (n < 1)
- n = 1;
+ n = 1;
if (n != (1 << ilog2(n)))
- post("warning: adjusting blocksize to power of 2: %d",
- (n = (1 << ilog2(n))));
+ post("warning: adjusting blocksize to power of 2: %d",
+ (n = (1 << ilog2(n))));
sys_blocksize = n;
}
@@ -743,7 +793,7 @@ void sys_set_audio_api(int which)
{
sys_audioapi = which;
if (sys_verbose)
- post("sys_audioapi %d", sys_audioapi);
+ post("sys_audioapi %d", sys_audioapi);
}
void glob_audio_setapi(void *dummy, t_floatarg f)
@@ -751,46 +801,46 @@ void glob_audio_setapi(void *dummy, t_floatarg f)
int newapi = f;
if (newapi)
{
- if (newapi == sys_audioapi)
- {
- if (!audio_isopen())
- sys_reopen_audio();
- }
- else
- {
- sys_close_audio();
- sys_audioapi = newapi;
- /* bash device params back to default */
- audio_naudioindev = audio_naudiooutdev = 1;
- audio_audioindev[0] = audio_audiooutdev[0] = DEFAULTAUDIODEV;
- audio_audiochindev[0] = audio_audiochoutdev[0] = SYS_DEFAULTCH;
- sys_reopen_audio();
- }
- glob_audio_properties(0, 0);
+ if (newapi == sys_audioapi)
+ {
+ if (!audio_isopen())
+ sys_reopen_audio();
+ }
+ else
+ {
+ sys_close_audio();
+ sys_audioapi = newapi;
+ /* bash device params back to default */
+ audio_naudioindev = audio_naudiooutdev = 1;
+ audio_audioindev[0] = audio_audiooutdev[0] = DEFAULTAUDIODEV;
+ audio_audiochindev[0] = audio_audiochoutdev[0] = SYS_DEFAULTCH;
+ sys_reopen_audio();
+ }
+ glob_audio_properties(0, 0);
}
else if (audio_isopen())
{
- sys_close_audio();
- audio_state = 0;
- sched_set_using_dacs(0);
+ sys_close_audio();
+ audio_state = 0;
+ sched_set_using_dacs(0);
}
}
/* start or stop the audio hardware */
void sys_set_audio_state(int onoff)
{
- if (onoff) /* start */
+ if (onoff) /* start */
{
- if (!audio_isopen())
- sys_reopen_audio();
+ if (!audio_isopen())
+ sys_reopen_audio();
}
else
{
- if (audio_isopen())
- {
- sys_close_audio();
- sched_set_using_dacs(0);
- }
+ if (audio_isopen())
+ {
+ sys_close_audio();
+ sched_set_using_dacs(0);
+ }
}
audio_state = onoff;
}
@@ -811,14 +861,17 @@ void sys_get_audio_apis(char *buf)
#ifdef USEAPI_PORTAUDIO
#ifdef MSW
sprintf(buf + strlen(buf),
- "{\"ASIO (via portaudio)\" %d} ", API_PORTAUDIO);
+ "{\"ASIO (via portaudio)\" %d} ", API_PORTAUDIO);
#else
#ifdef OSX
sprintf(buf + strlen(buf),
- "{\"standard (portaudio)\" %d} ", API_PORTAUDIO);
+ "{\"standard (portaudio)\" %d} ", API_PORTAUDIO);
#else
sprintf(buf + strlen(buf), "{portaudio %d} ", API_PORTAUDIO);
#endif
+#ifdef USEAPI_SGI
+ sprintf(buf + strlen(buf), "{SGI %d} ", API_SGI); n++;
+#endif
#endif
n++;
#endif
@@ -826,9 +879,9 @@ void sys_get_audio_apis(char *buf)
sprintf(buf + strlen(buf), "{jack %d} ", API_JACK); n++;
#endif
strcat(buf, "}");
- /* then again, if only one API (or none) we don't offer any choice. */
+ /* then again, if only one API (or none) we don't offer any choice. */
if (n < 2)
- strcpy(buf, "{}");
+ strcpy(buf, "{}");
}
@@ -843,31 +896,21 @@ void glob_foo(void *dummy, t_symbol *s, int argc, t_atom *argv)
{
t_symbol *arg = atom_getsymbolarg(0, argc, argv);
if (arg == gensym("restart"))
- {
- int naudioindev, audioindev[MAXAUDIOINDEV], chindev[MAXAUDIOINDEV];
- int naudiooutdev, audiooutdev[MAXAUDIOOUTDEV], choutdev[MAXAUDIOOUTDEV];
- int rate, advance;
- sys_get_audio_params(&naudioindev, audioindev, chindev,
- &naudiooutdev, audiooutdev, choutdev, &rate, &advance);
- sys_close_audio();
- sys_open_audio(naudioindev, audioindev, naudioindev, chindev,
- naudiooutdev, audiooutdev, naudiooutdev, choutdev, rate, advance,
- 1);
- }
+ sys_reopen_audio();
#ifdef USEAPI_ALSA
else if (arg == gensym("alsawrite"))
{
- int n = atom_getintarg(1, argc, argv);
- alsa_putzeros(n);
+ int n = atom_getintarg(1, argc, argv);
+ alsa_putzeros(n);
}
else if (arg == gensym("alsaread"))
{
- int n = atom_getintarg(1, argc, argv);
- alsa_getzeros(n);
+ int n = atom_getintarg(1, argc, argv);
+ alsa_getzeros(n);
}
else if (arg == gensym("print"))
{
- alsa_printstate();
+ alsa_printstate();
}
#endif
}
diff --git a/pd/src/s_audio_alsa.c b/pd/src/s_audio_alsa.c
index f42b6436..10577ad5 100644
--- a/pd/src/s_audio_alsa.c
+++ b/pd/src/s_audio_alsa.c
@@ -5,6 +5,9 @@
/* this file inputs and outputs audio using the ALSA API available on linux. */
+/* support for ALSA pcmv2 api by Karl MacMillan<karlmac@peabody.jhu.edu> */
+/* support for ALSA MMAP noninterleaved by Winfried Ritsch, IEM */
+
#include <alsa/asoundlib.h>
#include "m_pd.h"
@@ -21,729 +24,536 @@
#include <fcntl.h>
#include <sched.h>
#include <sys/mman.h>
-
-typedef int16_t t_alsa_sample16;
-typedef int32_t t_alsa_sample32;
-#define ALSA_SAMPLEWIDTH_16 sizeof(t_alsa_sample16)
-#define ALSA_SAMPLEWIDTH_32 sizeof(t_alsa_sample32)
-#define ALSA_XFERSIZE16 (signed int)(sizeof(t_alsa_sample16) * DEFDACBLKSIZE)
-#define ALSA_XFERSIZE32 (signed int)(sizeof(t_alsa_sample32) * DEFDACBLKSIZE)
-#define ALSA_MAXDEV 1
-#define ALSA_JITTER 1024
-#define ALSA_EXTRABUFFER 2048
-#define ALSA_DEFFRAGSIZE 64
-#define ALSA_DEFNFRAG 12
-
-#ifndef INT32_MAX
-#define INT32_MAX 0x7fffffff
-#endif
-
-#if (SND_LIB_MAJOR < 1)
-#define ALSAAPI9
-#endif
-
-typedef struct _alsa_dev
-{
- snd_pcm_t *inhandle;
- snd_pcm_t *outhandle;
- int innoninterleave; /* true if we're set for noninterleaved read */
- int outnoninterleave; /* same for write */
-} t_alsa_dev;
-
-t_alsa_dev alsa_device;
-static void *alsa_snd_buf = 0;
-static void **alsa_buf_ptrs;
-static int alsa_samplewidth;
-static snd_pcm_status_t* in_status;
-static snd_pcm_status_t* out_status;
-
-static int alsa_mode;
-static int alsa_buf_samps; /* believed actual ALSA bufsize in sample frames */
-static int alsa_inchannels;
-static int alsa_outchannels;
+#include "s_audio_alsa.h"
/* Defines */
#define DEBUG(x) x
#define DEBUG2(x) {x;}
static void alsa_checkiosync( void);
-static void alsa_numbertoname(int devno, char *devname, int nchar);
+static void alsa_numbertoname(int iodev, char *devname, int nchar);
/* don't assume we can turn all 31 bits when doing float-to-fix;
otherwise some audio drivers (e.g. Midiman/ALSA) wrap around. */
#define FMAX 0x7ffff000
#define CLIP32(x) (((x)>FMAX)?FMAX:((x) < -FMAX)?-FMAX:(x))
-/* support for ALSA pcmv2 api by Karl MacMillan<karlmac@peabody.jhu.edu> */
+static char *alsa_snd_buf;
+static int alsa_snd_bufsize;
+static int alsa_buf_samps;
+static snd_pcm_status_t *alsa_status;
+static int alsa_usemmap;
+
+t_alsa_dev alsa_indev[ALSA_MAXDEV];
+t_alsa_dev alsa_outdev[ALSA_MAXDEV];
+int alsa_nindev;
+int alsa_noutdev;
static void check_error(int err, const char *why)
{
if (err < 0)
- fprintf(stderr, "%s: %s\n", why, snd_strerror(err));
+ fprintf(stderr, "%s: %s\n", why, snd_strerror(err));
+}
+
+static int alsaio_canmmap(t_alsa_dev *dev)
+{
+ snd_pcm_hw_params_t *hw_params;
+ int err;
+
+ snd_pcm_hw_params_alloca(&hw_params);
+
+ err = snd_pcm_hw_params_any(dev->a_handle, hw_params);
+ if (err < 0) {
+ check_error(err,"Broken configuration: no configurations available");
+ return (0);
+ }
+
+ err = snd_pcm_hw_params_set_access(dev->a_handle,
+ hw_params, SND_PCM_ACCESS_MMAP_NONINTERLEAVED);
+ return (err >= 0);
+}
+
+static int alsaio_setup(t_alsa_dev *dev, int out, int *channels, int *rate,
+ int nfrags, int frag_size)
+{
+ int bufsizeforthis, err;
+ snd_pcm_hw_params_t* hw_params;
+ unsigned int tmp_uint;
+ snd_pcm_uframes_t tmp_snd_pcm_uframes;
+
+ if (sys_verbose)
+ {
+ if (out)
+ post("configuring sound output...");
+ else post("configuring sound input...");
+ }
+
+ /* set hardware parameters... */
+ snd_pcm_hw_params_alloca(&hw_params);
+
+ /* get the default params */
+ err = snd_pcm_hw_params_any(dev->a_handle, hw_params);
+ check_error(err, "snd_pcm_hw_params_any");
+
+ /* try to set interleaved access */
+ err = snd_pcm_hw_params_set_access(dev->a_handle,
+ hw_params, SND_PCM_ACCESS_RW_INTERLEAVED);
+ if (err < 0)
+ return (-1);
+ check_error(err, "snd_pcm_hw_params_set_access");
+ /* Try to set 32 bit format first */
+ err = snd_pcm_hw_params_set_format(dev->a_handle,
+ hw_params, SND_PCM_FORMAT_S32);
+ if (err < 0)
+ {
+ /* fprintf(stderr,
+ "PD-ALSA: 32 bit format not available - using 16\n"); */
+ err = snd_pcm_hw_params_set_format(dev->a_handle, hw_params,
+ SND_PCM_FORMAT_S16);
+ check_error(err, "snd_pcm_hw_params_set_format");
+ dev->a_sampwidth = 2;
+ }
+ else dev->a_sampwidth = 4;
+
+ if (sys_verbose)
+ post("Sample width set to %d bytes", dev->a_sampwidth);
+
+ /* set the subformat */
+ err = snd_pcm_hw_params_set_subformat(dev->a_handle,
+ hw_params, SND_PCM_SUBFORMAT_STD);
+ check_error(err, "snd_pcm_hw_params_set_subformat");
+
+ /* set the number of channels */
+ tmp_uint = *channels;
+ err = snd_pcm_hw_params_set_channels_min(dev->a_handle,
+ hw_params, &tmp_uint);
+ check_error(err, "snd_pcm_hw_params_set_channels");
+ if (tmp_uint != (unsigned)*channels)
+ post("ALSA: set input channels to %d", tmp_uint);
+ *channels = tmp_uint;
+ dev->a_channels = *channels;
+
+ /* set the sampling rate */
+ err = snd_pcm_hw_params_set_rate_min(dev->a_handle, hw_params, rate, 0);
+ check_error(err, "snd_pcm_hw_params_set_rate_min (input)");
+#if 0
+ err = snd_pcm_hw_params_get_rate(hw_params, &subunitdir);
+ post("input sample rate %d", err);
+#endif
+
+ /* set the period - ie frag size */
+ /* LATER try this to get a recommended period size...
+ right now, it trips an assertion failure in ALSA lib */
+ tmp_snd_pcm_uframes = frag_size;
+ err = snd_pcm_hw_params_set_period_size_near(dev->a_handle,
+ hw_params, &tmp_snd_pcm_uframes, 0);
+ check_error(err, "snd_pcm_hw_params_set_period_size_near (input)");
+
+ /* set the number of periods - ie numfrags */
+ tmp_uint = nfrags;
+ err = snd_pcm_hw_params_set_periods_near(dev->a_handle,
+ hw_params, &tmp_uint, 0);
+ check_error(err, "snd_pcm_hw_params_set_periods_near (input)");
+
+ /* set the buffer size */
+ tmp_snd_pcm_uframes = nfrags * frag_size;
+ err = snd_pcm_hw_params_set_buffer_size_near(dev->a_handle,
+ hw_params, &tmp_snd_pcm_uframes);
+ check_error(err, "snd_pcm_hw_params_set_buffer_size_near (input)");
+
+ err = snd_pcm_hw_params(dev->a_handle, hw_params);
+ check_error(err, "snd_pcm_hw_params (input)");
+
+ /* set up the buffer */
+ bufsizeforthis = DEFDACBLKSIZE * dev->a_sampwidth * *channels;
+ if (alsa_snd_buf)
+ {
+ if (alsa_snd_bufsize < bufsizeforthis)
+ {
+ if (!(alsa_snd_buf = realloc(alsa_snd_buf, bufsizeforthis)))
+ {
+ post("out of memory");
+ return (0);
+ }
+ memset(alsa_snd_buf, 0, bufsizeforthis);
+ alsa_snd_bufsize = bufsizeforthis;
+ }
+ }
+ else
+ {
+ if (!(alsa_snd_buf = (void *)malloc(bufsizeforthis)))
+ {
+ post("out of memory");
+ return (0);
+ }
+ memset(alsa_snd_buf, 0, bufsizeforthis);
+ alsa_snd_bufsize = bufsizeforthis;
+ }
+ return (1);
}
-/* was: alsa_open_audio(int wantinchans, int wantoutchans, int srate) */
+ /* return 0 on success */
int alsa_open_audio(int naudioindev, int *audioindev, int nchindev,
int *chindev, int naudiooutdev, int *audiooutdev, int nchoutdev,
int *choutdev, int rate)
{
int err, inchans = 0, outchans = 0, subunitdir;
char devname[512];
- snd_pcm_hw_params_t* hw_params;
- snd_pcm_sw_params_t* sw_params;
snd_output_t* out;
int frag_size = (sys_blocksize ? sys_blocksize : ALSA_DEFFRAGSIZE);
- int nfrags, i;
- short* tmp_buf;
- unsigned int tmp_uint;
- snd_pcm_uframes_t tmp_snd_pcm_uframes;
- int wantinchans, wantoutchans, devno;
-
- if (naudioindev >= 2 || naudiooutdev >= 2)
- post("alsa: only one input and output device allowed (extras ignored");
- if (naudioindev >= 1 && naudiooutdev >= 1 &&
- audioindev[0] != audiooutdev[0])
- post("alsa: changing output device to agree with input device");
- if (nchindev)
- wantinchans = chindev[0];
- else wantinchans = (naudioindev ? 2 : 0);
- if (nchoutdev)
- wantoutchans = choutdev[0];
- else wantoutchans = (naudiooutdev ? 2 : 0);
- devno = (naudioindev > 0 ? audioindev[0] :
- (naudiooutdev > 0 ? audiooutdev[0] : 0));
-
- alsa_numbertoname(devno, devname, 512);
+ int nfrags, i, iodev, dev2;
+ int wantinchans, wantoutchans, device;
- if (sys_verbose)
- post("device name %s; channels in %d, out %d", devname, wantinchans,
- wantoutchans);
-
nfrags = sys_schedadvance * (float)rate / (1e6 * frag_size);
- /* save our belief as to ALSA's buffer size for later */
+ /* save our belief as to ALSA's buffer size for later */
alsa_buf_samps = nfrags * frag_size;
+ alsa_nindev = alsa_noutdev = 0;
if (sys_verbose)
- post("audio buffer set to %d", (int)(0.001 * sys_schedadvance));
-
- alsa_device.innoninterleave = alsa_device.outnoninterleave = 0;
- if (wantinchans)
- {
- err = snd_pcm_open(&alsa_device.inhandle, devname,
- SND_PCM_STREAM_CAPTURE, SND_PCM_NONBLOCK);
-
- check_error(err, "snd_pcm_open (input)");
- if (err < 0)
- inchans = 0;
- else
- {
- inchans = wantinchans;
- snd_pcm_nonblock(alsa_device.inhandle, 1);
- }
- }
- if (wantoutchans)
- {
- err = snd_pcm_open(&alsa_device.outhandle, devname,
- SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK);
-
- check_error(err, "snd_pcm_open (output)");
- if (err < 0)
- outchans = 0;
- else
- {
- outchans = wantoutchans;
- snd_pcm_nonblock(alsa_device.outhandle, 1);
- }
- }
- if (inchans)
- {
- if (sys_verbose)
- post("opening sound input...");
- err = snd_pcm_hw_params_malloc(&hw_params);
- check_error(err, "snd_pcm_hw_params_malloc (input)");
-
- // get the default params
- err = snd_pcm_hw_params_any(alsa_device.inhandle, hw_params);
- check_error(err, "snd_pcm_hw_params_any (input)");
-
- /* try to set interleaved access */
- err = snd_pcm_hw_params_set_access(alsa_device.inhandle,
- hw_params, SND_PCM_ACCESS_RW_INTERLEAVED);
- if (err < 0)
- {
- /* OK, so try non-interleaved */
- err = snd_pcm_hw_params_set_access(alsa_device.inhandle,
- hw_params, SND_PCM_ACCESS_RW_NONINTERLEAVED);
- if (err >= 0)
- {
- post("using non-interleaved audio input");
- alsa_device.innoninterleave = 1;
- }
- }
- check_error(err, "snd_pcm_hw_params_set_access (input)");
- // Try to set 32 bit format first
- err = snd_pcm_hw_params_set_format(alsa_device.inhandle, hw_params,
- SND_PCM_FORMAT_S32);
- if (err < 0)
- {
- /* fprintf(stderr,
- "PD-ALSA: 32 bit format not available - using 16\n"); */
- err = snd_pcm_hw_params_set_format(alsa_device.inhandle, hw_params,
- SND_PCM_FORMAT_S16);
- check_error(err, "snd_pcm_hw_params_set_format (input)");
- alsa_samplewidth = 2;
- }
- else
- {
- alsa_samplewidth = 4;
- }
- post("Sample width set to %d bytes", alsa_samplewidth);
- // set the subformat
- err = snd_pcm_hw_params_set_subformat(alsa_device.inhandle, hw_params,
- SND_PCM_SUBFORMAT_STD);
- check_error(err, "snd_pcm_hw_params_set_subformat (input)");
- // set the number of channels
- tmp_uint = inchans;
- err = snd_pcm_hw_params_set_channels_min(alsa_device.inhandle,
- hw_params, &tmp_uint);
- check_error(err, "snd_pcm_hw_params_set_channels (input)");
- if (tmp_uint != (unsigned)inchans)
- post("ALSA: set input channels to %d", tmp_uint);
- inchans = tmp_uint;
- // set the sampling rate
- err = snd_pcm_hw_params_set_rate_min(alsa_device.inhandle, hw_params,
- &rate, 0);
- check_error(err, "snd_pcm_hw_params_set_rate_min (input)");
-#if 0
- err = snd_pcm_hw_params_get_rate(hw_params, &subunitdir);
- post("input sample rate %d", err);
-#endif
- // set the period - ie frag size
- // post("fragsize a %d", frag_size);
+ post("audio buffer set to %d", (int)(0.001 * sys_schedadvance));
- /* LATER try this to get a recommended period size...
- right now, it trips an assertion failure in ALSA lib */
-#if 0
- post("input period was %d, min %d, max %d\n",
- snd_pcm_hw_params_get_period_size(hw_params, 0),
- snd_pcm_hw_params_get_period_size_min(hw_params, 0),
- snd_pcm_hw_params_get_period_size_max(hw_params, 0));
-#endif
-#ifdef ALSAAPI9
- err = snd_pcm_hw_params_set_period_size_near(alsa_device.inhandle,
- hw_params,
- (snd_pcm_uframes_t)
- frag_size, 0);
-#else
- tmp_snd_pcm_uframes = frag_size;
- err = snd_pcm_hw_params_set_period_size_near(alsa_device.inhandle,
- hw_params, &tmp_snd_pcm_uframes, 0);
-#endif
- check_error(err, "snd_pcm_hw_params_set_period_size_near (input)");
- // post("fragsize b %d", frag_size);
- // set the number of periods - ie numfrags
- // post("nfrags a %d", nfrags);
-#ifdef ALSAAPI9
- err = snd_pcm_hw_params_set_periods_near(alsa_device.inhandle,
- hw_params, nfrags, 0);
-#else
- tmp_uint = nfrags;
- err = snd_pcm_hw_params_set_periods_near(alsa_device.inhandle,
- hw_params, &tmp_uint, 0);
-#endif
- check_error(err, "snd_pcm_hw_params_set_periods_near (input)");
- // set the buffer size
-#ifdef ALSAAPI9
- err = snd_pcm_hw_params_set_buffer_size_near(alsa_device.inhandle,
- hw_params, nfrags * frag_size);
-#else
- tmp_snd_pcm_uframes = nfrags * frag_size;
- err = snd_pcm_hw_params_set_buffer_size_near(alsa_device.inhandle,
- hw_params, &tmp_snd_pcm_uframes);
-#endif
- check_error(err, "snd_pcm_hw_params_set_buffer_size_near (input)");
-
- err = snd_pcm_hw_params(alsa_device.inhandle, hw_params);
- check_error(err, "snd_pcm_hw_params (input)");
-
- snd_pcm_hw_params_free(hw_params);
-
- err = snd_pcm_sw_params_malloc(&sw_params);
- check_error(err, "snd_pcm_sw_params_malloc (input)");
- err = snd_pcm_sw_params_current(alsa_device.inhandle, sw_params);
- check_error(err, "snd_pcm_sw_params_current (input)");
- err = snd_pcm_sw_params_set_start_threshold(alsa_device.inhandle,
- sw_params, nfrags * frag_size);
- check_error(err, "snd_pcm_sw_params_set_start_threshold (input)");
- err = snd_pcm_sw_params_set_stop_threshold(alsa_device.inhandle,
- sw_params, 0x7fffffff);
- check_error(err, "snd_pcm_sw_params_set_stop_threshold (input)");
- err = snd_pcm_sw_params_set_avail_min(alsa_device.inhandle, sw_params,
- frag_size);
- check_error(err, "snd_pcm_sw_params_set_avail_min (input)");
- err = snd_pcm_sw_params(alsa_device.inhandle, sw_params);
- check_error(err, "snd_pcm_sw_params (input)");
-
- snd_pcm_sw_params_free(sw_params);
-
- snd_output_stdio_attach(&out, stderr, 0);
-#if 0
- if (sys_verbose)
- {
- snd_pcm_dump_hw_setup(alsa_device.inhandle, out);
- snd_pcm_dump_sw_setup(alsa_device.inhandle, out);
- }
-#endif
+ for (iodev = 0; iodev < naudioindev; iodev++)
+ {
+ alsa_numbertoname(audioindev[iodev], devname, 512);
+ err = snd_pcm_open(&alsa_indev[alsa_nindev].a_handle, devname,
+ SND_PCM_STREAM_CAPTURE, SND_PCM_NONBLOCK);
+ check_error(err, "snd_pcm_open (input)");
+ if (err < 0)
+ continue;
+ alsa_indev[alsa_nindev].a_devno = audioindev[iodev];
+ snd_pcm_nonblock(alsa_indev[alsa_nindev].a_handle, 1);
+ if (sys_verbose)
+ post("opened input device name %s", devname);
+ alsa_nindev++;
}
-
- if (outchans)
+ for (iodev = 0; iodev < naudiooutdev; iodev++)
{
- int foo;
- if (sys_verbose)
- post("opening sound output...");
- err = snd_pcm_hw_params_malloc(&hw_params);
- check_error(err, "snd_pcm_sw_params (output)");
-
- // get the default params
- err = snd_pcm_hw_params_any(alsa_device.outhandle, hw_params);
- check_error(err, "snd_pcm_hw_params_any (output)");
- // set interleaved access - FIXME deal with other access types
- err = snd_pcm_hw_params_set_access(alsa_device.outhandle, hw_params,
- SND_PCM_ACCESS_RW_INTERLEAVED);
- check_error(err, "snd_pcm_hw_params_set_access (output)");
-
- /* try to set interleaved access */
- err = snd_pcm_hw_params_set_access(alsa_device.outhandle,
- hw_params, SND_PCM_ACCESS_RW_INTERLEAVED);
- if (err < 0)
- {
- /* OK, so try non-interleaved */
- err = snd_pcm_hw_params_set_access(alsa_device.outhandle,
- hw_params, SND_PCM_ACCESS_RW_NONINTERLEAVED);
- if (err >= 0)
- {
- post("using non-interleaved audio");
- alsa_device.outnoninterleave = 1;
- }
- }
- check_error(err, "snd_pcm_hw_params_set_access (output)");
-
-
- // Try to set 32 bit format first
- err = snd_pcm_hw_params_set_format(alsa_device.outhandle, hw_params,
- SND_PCM_FORMAT_S32);
- if (err < 0)
- {
- err = snd_pcm_hw_params_set_format(alsa_device.outhandle,
- hw_params,SND_PCM_FORMAT_S16);
- check_error(err, "snd_pcm_hw_params_set_format (output)");
- /* fprintf(stderr,
- "PD-ALSA: 32 bit format not available - using 16\n"); */
- alsa_samplewidth = 2;
- }
- else
- {
- alsa_samplewidth = 4;
- }
- // set the subformat
- err = snd_pcm_hw_params_set_subformat(alsa_device.outhandle, hw_params,
- SND_PCM_SUBFORMAT_STD);
- check_error(err, "snd_pcm_hw_params_set_subformat (output)");
- // set the number of channels
- tmp_uint = outchans;
- err = snd_pcm_hw_params_set_channels_min(alsa_device.outhandle,
- hw_params, &tmp_uint);
- check_error(err, "snd_pcm_hw_params_set_channels (output)");
- if (tmp_uint != (unsigned)outchans)
- post("alsa: set output channels to %d", tmp_uint);
- outchans = tmp_uint;
- // set the sampling rate
- err = snd_pcm_hw_params_set_rate_min(alsa_device.outhandle, hw_params,
- &rate, 0);
- check_error(err, "snd_pcm_hw_params_set_rate_min (output)");
-#if 0
- err = snd_pcm_hw_params_get_rate(hw_params, &subunitdir);
- post("output sample rate %d", err);
-#endif
- // set the period - ie frag size
-#if 0
- post("output period was %d, min %d, max %d\n",
- snd_pcm_hw_params_get_period_size(hw_params, 0),
- snd_pcm_hw_params_get_period_size_min(hw_params, 0),
- snd_pcm_hw_params_get_period_size_max(hw_params, 0));
-#endif
- // post("fragsize c %d", frag_size);
-#ifdef ALSAAPI9
- err = snd_pcm_hw_params_set_period_size_near(alsa_device.outhandle,
- hw_params,
- (snd_pcm_uframes_t)
- frag_size, 0);
-#else
- tmp_snd_pcm_uframes = frag_size;
- err = snd_pcm_hw_params_set_period_size_near(alsa_device.outhandle,
- hw_params, &tmp_snd_pcm_uframes, 0);
-#endif
- // post("fragsize d %d", frag_size);
- check_error(err, "snd_pcm_hw_params_set_period_size_near (output)");
- // set the number of periods - ie numfrags
-#ifdef ALSAAPI9
- err = snd_pcm_hw_params_set_periods_near(alsa_device.outhandle,
- hw_params, nfrags, 0);
-#else
- tmp_uint = nfrags;
- err = snd_pcm_hw_params_set_periods_near(alsa_device.outhandle,
- hw_params, &tmp_uint, 0);
-#endif
- check_error(err, "snd_pcm_hw_params_set_periods_near (output)");
- // set the buffer size
-#ifdef ALSAAPI9
- err = snd_pcm_hw_params_set_buffer_size_near(alsa_device.outhandle,
- hw_params, nfrags * frag_size);
-#else
- tmp_snd_pcm_uframes = nfrags * frag_size;
- err = snd_pcm_hw_params_set_buffer_size_near(alsa_device.outhandle,
- hw_params, &tmp_snd_pcm_uframes);
-#endif
- check_error(err, "snd_pcm_hw_params_set_buffer_size_near (output)");
-
- err = snd_pcm_hw_params(alsa_device.outhandle, hw_params);
- check_error(err, "snd_pcm_hw_params (output)");
-
- snd_pcm_hw_params_free(hw_params);
-
- err = snd_pcm_sw_params_malloc(&sw_params);
- check_error(err, "snd_pcm_sw_params_malloc (output)");
- err = snd_pcm_sw_params_current(alsa_device.outhandle, sw_params);
- check_error(err, "snd_pcm_sw_params_current (output)");
- err = snd_pcm_sw_params_set_start_threshold(alsa_device.outhandle,
- sw_params, nfrags * frag_size);
- check_error(err, "snd_pcm_sw_params_set_start_threshold (output)");
- err = snd_pcm_sw_params_set_stop_threshold(alsa_device.outhandle,
- sw_params, 0x7fffffff);
- check_error(err, "snd_pcm_sw_params_set_stop_threshold (output)");
- err = snd_pcm_sw_params_set_avail_min(alsa_device.outhandle, sw_params,
- frag_size);
- check_error(err, "snd_pcm_sw_params_set_avail_min (output)");
- err = snd_pcm_sw_params(alsa_device.outhandle, sw_params);
- check_error(err, "snd_pcm_sw_params (output)");
- snd_pcm_sw_params_free(sw_params);
-
- snd_output_stdio_attach(&out, stderr, 0);
-#if 0
- if (sys_verbose)
- {
- snd_pcm_dump_hw_setup(alsa_device.outhandle, out);
- snd_pcm_dump_sw_setup(alsa_device.outhandle, out);
- }
-#endif
+ alsa_numbertoname(audiooutdev[iodev], devname, 512);
+ err = snd_pcm_open(&alsa_outdev[alsa_noutdev].a_handle, devname,
+ SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK);
+ check_error(err, "snd_pcm_open (output)");
+ if (err < 0)
+ continue;
+ alsa_outdev[alsa_noutdev].a_devno = audiooutdev[iodev];
+ snd_pcm_nonblock(alsa_outdev[alsa_noutdev].a_handle, 1);
+ alsa_noutdev++;
+ }
+ if (!alsa_nindev && !alsa_noutdev)
+ goto blewit;
+
+ /* If all the open devices support mmap_noninterleaved, let's call
+ Wini's code in s_audio_alsamm.c */
+ alsa_usemmap = 1;
+ for (iodev = 0; iodev < alsa_nindev; iodev++)
+ if (!alsaio_canmmap(&alsa_indev[iodev]))
+ alsa_usemmap = 0;
+ for (iodev = 0; iodev < alsa_noutdev; iodev++)
+ if (!alsaio_canmmap(&alsa_outdev[iodev]))
+ alsa_usemmap = 0;
+ if (alsa_usemmap)
+ {
+ post("using mmap audio interface");
+ if (alsamm_open_audio(rate))
+ goto blewit;
+ else return (0);
+ }
+ for (iodev = 0; iodev < alsa_nindev; iodev++)
+ {
+ int channels = chindev[iodev];
+ if (alsaio_setup(&alsa_indev[iodev], 0, &channels, &rate,
+ nfrags, frag_size) < 0)
+ goto blewit;
+ inchans += channels;
}
+ for (iodev = 0; iodev < alsa_noutdev; iodev++)
+ {
+ int channels = choutdev[iodev];
+ if (alsaio_setup(&alsa_outdev[iodev], 1, &channels, &rate,
+ nfrags, frag_size) < 0)
+ goto blewit;
+ outchans += channels;
+ }
+ if (!inchans && !outchans)
+ goto blewit;
- if (inchans)
- snd_pcm_prepare(alsa_device.inhandle);
- if (outchans)
- snd_pcm_prepare(alsa_device.outhandle);
+ for (iodev = 0; iodev < alsa_nindev; iodev++)
+ snd_pcm_prepare(alsa_indev[iodev].a_handle);
+ for (iodev = 0; iodev < alsa_noutdev; iodev++)
+ snd_pcm_prepare(alsa_outdev[iodev].a_handle);
- // if duplex we can link the channels so they start together
- if (inchans && outchans)
- snd_pcm_link(alsa_device.inhandle, alsa_device.outhandle);
+ /* if duplex we can link the channels so they start together */
+ for (iodev = 0; iodev < alsa_nindev; iodev++)
+ for (dev2 = 0; dev2 < alsa_noutdev; dev2++)
+ {
+ if (alsa_indev[iodev].a_devno == alsa_outdev[iodev].a_devno)
+ {
+ snd_pcm_link(alsa_indev[iodev].a_handle,
+ alsa_outdev[iodev].a_handle);
+ }
+ }
+
+ /* allocate the status variables */
+ if (!alsa_status)
+ {
+ err = snd_pcm_status_malloc(&alsa_status);
+ check_error(err, "snd_pcm_status_malloc");
+ }
- // set up the status variables
- err = snd_pcm_status_malloc(&in_status);
- check_error(err, "snd_pcm_status_malloc");
- err = snd_pcm_status_malloc(&out_status);
- check_error(err, "snd_pcm_status_malloc");
+ /* fill the buffer with silence */
+ memset(alsa_snd_buf, 0, alsa_snd_bufsize);
- // set up the buffer
- if (alsa_snd_buf)
- free(alsa_snd_buf);
- alsa_snd_buf = (void *)malloc(
- sizeof(char) * alsa_samplewidth * DEFDACBLKSIZE *
- (outchans > inchans ? outchans : inchans));
- memset(alsa_snd_buf, 0, sizeof(char) * alsa_samplewidth * DEFDACBLKSIZE *
- (outchans > inchans ? outchans : inchans));
- /* make an array of pointers too in case we need them */
- if (alsa_buf_ptrs)
- free(alsa_buf_ptrs);
- alsa_buf_ptrs = (void **)malloc(
- sizeof(void *) * (outchans > inchans ? outchans : inchans));
- for (i = 0; i < (outchans > inchans ? outchans : inchans); i++)
- alsa_buf_ptrs[i] = (t_alsa_sample32 *)alsa_snd_buf + i * DEFDACBLKSIZE;
-
- // fill the buffer with silence
if (outchans)
{
- i = (frag_size * nfrags)/DEFDACBLKSIZE + 1;
- while (i--)
- {
- if (alsa_device.outnoninterleave)
- snd_pcm_writen(alsa_device.outhandle, alsa_buf_ptrs,
- DEFDACBLKSIZE);
- else snd_pcm_writei(alsa_device.outhandle, alsa_snd_buf,
- DEFDACBLKSIZE);
- }
- /* confused about this: */
- /* if ((err = snd_pcm_start(alsa_device.outhandle) < 0))
- check_error(err, "output start failed\n"); */
+ i = (frag_size * nfrags)/DEFDACBLKSIZE + 1;
+ while (i--)
+ {
+ for (iodev = 0; iodev < alsa_noutdev; iodev++)
+ snd_pcm_writei(alsa_outdev[iodev].a_handle, alsa_snd_buf,
+ DEFDACBLKSIZE);
+ }
}
else if (inchans)
{
- if (snd_pcm_start(alsa_device.inhandle) < 0)
- check_error(err, "input start failed\n");
+ for (iodev = 0; iodev < alsa_nindev; iodev++)
+ if ((err = snd_pcm_start(alsa_indev[iodev].a_handle)) < 0)
+ check_error(err, "input start failed\n");
}
- alsa_outchannels = outchans;
- alsa_inchannels = inchans;
-
- return (!(inchans || outchans));
+ return (0);
+blewit:
+ sys_inchannels = 0;
+ sys_outchannels = 0;
+ alsa_close_audio();
+ return (1);
}
void alsa_close_audio(void)
{
- int err;
- if (alsa_inchannels)
+ int err, iodev;
+ if (alsa_usemmap)
+ {
+ alsamm_close_audio();
+ return;
+ }
+ for (iodev = 0; iodev < alsa_nindev; iodev++)
{
- err = snd_pcm_close(alsa_device.inhandle);
- check_error(err, "snd_pcm_close (input)");
+ err = snd_pcm_close(alsa_indev[iodev].a_handle);
+ check_error(err, "snd_pcm_close (input)");
}
- if (alsa_outchannels)
+ for (iodev = 0; iodev < alsa_noutdev; iodev++)
{
- err = snd_pcm_close(alsa_device.outhandle);
- check_error(err, "snd_pcm_close (output)");
+ err = snd_pcm_close(alsa_outdev[iodev].a_handle);
+ check_error(err, "snd_pcm_close (output)");
}
+ alsa_nindev = alsa_noutdev = 0;
}
// #define DEBUG_ALSA_XFER
int alsa_send_dacs(void)
{
- static int16_t *sp;
+#ifdef DEBUG_ALSA_XFER
static int xferno = 0;
static int callno = 0;
+#endif
static double timenow;
double timelast;
t_sample *fp, *fp1, *fp2;
- int i, j, k, err, devno = 0;
- int inputcount = 0, outputcount = 0, inputlate = 0, outputlate = 0;
- int result;
- int inchannels = (sys_inchannels > alsa_inchannels ?
- alsa_inchannels : sys_inchannels);
- int outchannels = (sys_outchannels > alsa_outchannels ?
- alsa_outchannels : sys_outchannels);
- unsigned int intransfersize = DEFDACBLKSIZE;
- unsigned int outtransfersize = DEFDACBLKSIZE;
+ int i, j, k, err, iodev, result, ch;
+ int chansintogo, chansouttogo;
+ unsigned int transfersize;
+
+ if (alsa_usemmap)
+ return (alsamm_send_dacs());
+
+ if (!alsa_nindev && !alsa_noutdev)
+ return (SENDDACS_NO);
+
+ chansintogo = sys_inchannels;
+ chansouttogo = sys_outchannels;
+ transfersize = DEFDACBLKSIZE;
- // get the status
- if (!inchannels && !outchannels)
- {
- return SENDDACS_NO;
- }
-
timelast = timenow;
timenow = sys_getrealtime();
#ifdef DEBUG_ALSA_XFER
if (timenow - timelast > 0.050)
- fprintf(stderr, "(%d)",
- (int)(1000 * (timenow - timelast))), fflush(stderr);
-#endif
-
+ fprintf(stderr, "(%d)",
+ (int)(1000 * (timenow - timelast))), fflush(stderr);
callno++;
+#endif
alsa_checkiosync(); /* check I/O are in sync and data not late */
- if (alsa_inchannels)
+ for (iodev = 0; iodev < alsa_nindev; iodev++)
{
- snd_pcm_status(alsa_device.inhandle, in_status);
- if (snd_pcm_status_get_avail(in_status) < intransfersize)
- return SENDDACS_NO;
+ snd_pcm_status(alsa_indev[iodev].a_handle, alsa_status);
+ if (snd_pcm_status_get_avail(alsa_status) < transfersize)
+ return SENDDACS_NO;
}
- if (alsa_outchannels)
+ for (iodev = 0; iodev < alsa_noutdev; iodev++)
{
- snd_pcm_status(alsa_device.outhandle, out_status);
- if (snd_pcm_status_get_avail(out_status) < outtransfersize)
- return SENDDACS_NO;
+ snd_pcm_status(alsa_outdev[iodev].a_handle, alsa_status);
+ if (snd_pcm_status_get_avail(alsa_status) < transfersize)
+ return SENDDACS_NO;
}
/* do output */
- if (alsa_outchannels)
- {
- fp = sys_soundout;
- if (alsa_samplewidth == 4)
- {
- if (alsa_device.outnoninterleave)
- {
- int n = outchannels * DEFDACBLKSIZE;
- for (i = 0, fp1 = fp; i < n; i++)
- {
- float s1 = *fp1 * INT32_MAX;
- ((t_alsa_sample32 *)alsa_snd_buf)[i] = CLIP32(s1);
- }
- n = alsa_outchannels * DEFDACBLKSIZE;
- for (; i < n; i++)
- ((t_alsa_sample32 *)alsa_snd_buf)[i] = 0;
- }
- else
- {
- for (i = 0, fp1 = fp; i < outchannels; i++,
- fp1 += DEFDACBLKSIZE)
- {
- for (j = i, k = DEFDACBLKSIZE, fp2 = fp1; k--;
- j += alsa_outchannels, fp2++)
- {
- float s1 = *fp2 * INT32_MAX;
- ((t_alsa_sample32 *)alsa_snd_buf)[j] = CLIP32(s1);
- }
- }
- }
- }
- else
- {
- for (i = 0, fp1 = fp; i < outchannels; i++, fp1 += DEFDACBLKSIZE)
- {
- for (j = i, k = DEFDACBLKSIZE, fp2 = fp1; k--;
- j += alsa_outchannels, fp2++)
- {
- int s = *fp2 * 32767.;
- if (s > 32767)
- s = 32767;
- else if (s < -32767)
- s = -32767;
- ((t_alsa_sample16 *)alsa_snd_buf)[j] = s;
- }
- }
- }
-
- if (alsa_device.outnoninterleave)
- result = snd_pcm_writen(alsa_device.outhandle, alsa_buf_ptrs,
- outtransfersize);
- else result = snd_pcm_writei(alsa_device.outhandle, alsa_snd_buf,
- outtransfersize);
-
- if (result != (int)outtransfersize)
- {
+ for (iodev = 0, fp1 = sys_soundout, ch = 0; iodev < alsa_noutdev; iodev++)
+ {
+ int thisdevchans = alsa_outdev[iodev].a_channels;
+ int chans = (chansouttogo < thisdevchans ? chansouttogo : thisdevchans);
+ chansouttogo -= chans;
+
+ if (alsa_outdev[iodev].a_sampwidth == 4)
+ {
+ for (i = 0; i < chans; i++, ch++, fp1 += DEFDACBLKSIZE)
+ for (j = ch, k = DEFDACBLKSIZE, fp2 = fp1; k--;
+ j += thisdevchans, fp2++)
+ {
+ float s1 = *fp2 * INT32_MAX;
+ ((t_alsa_sample32 *)alsa_snd_buf)[j] = CLIP32(s1);
+ }
+ for (; i < thisdevchans; i++, ch++)
+ for (j = ch, k = DEFDACBLKSIZE; k--; j += thisdevchans)
+ ((t_alsa_sample32 *)alsa_snd_buf)[j] = 0;
+ }
+ else
+ {
+ for (i = 0; i < chans; i++, ch++, fp1 += DEFDACBLKSIZE)
+ for (j = ch, k = DEFDACBLKSIZE, fp2 = fp1; k--;
+ j += thisdevchans, fp2++)
+ {
+ int s = *fp2 * 32767.;
+ if (s > 32767)
+ s = 32767;
+ else if (s < -32767)
+ s = -32767;
+ ((t_alsa_sample16 *)alsa_snd_buf)[j] = s;
+ }
+ for (; i < thisdevchans; i++, ch++)
+ for (j = ch, k = DEFDACBLKSIZE; k--; j += thisdevchans)
+ ((t_alsa_sample16 *)alsa_snd_buf)[j] = 0;
+ }
+ result = snd_pcm_writei(alsa_outdev[iodev].a_handle, alsa_snd_buf,
+ transfersize);
+
+ if (result != (int)transfersize)
+ {
#ifdef DEBUG_ALSA_XFER
- if (result >= 0 || errno == EAGAIN)
- fprintf(stderr, "ALSA: write returned %d of %d\n",
- result, outtransfersize);
- else fprintf(stderr, "ALSA: write: %s\n",
- snd_strerror(errno));
- fprintf(stderr,
- "inputcount %d, outputcount %d, outbufsize %d\n",
- inputcount, outputcount,
- (ALSA_EXTRABUFFER + sys_advance_samples)
- * alsa_samplewidth * outchannels);
+ if (result >= 0 || errno == EAGAIN)
+ fprintf(stderr, "ALSA: write returned %d of %d\n",
+ result, transfersize);
+ else fprintf(stderr, "ALSA: write: %s\n",
+ snd_strerror(errno));
+ fprintf(stderr,
+ "inputcount %d, outputcount %d, outbufsize %d\n",
+ inputcount, outputcount,
+ (ALSA_EXTRABUFFER + sys_advance_samples)
+ * alsa_outdev[iodev].a_sampwidth * outchannels);
#endif
- sys_log_error(ERR_DACSLEPT);
- return (SENDDACS_NO);
- }
-
- /* zero out the output buffer */
- memset(sys_soundout, 0, DEFDACBLKSIZE * sizeof(*sys_soundout) *
- sys_outchannels);
- if (sys_getrealtime() - timenow > 0.002)
- {
+ sys_log_error(ERR_DACSLEPT);
+ return (SENDDACS_NO);
+ }
+
+ /* zero out the output buffer */
+ memset(sys_soundout, 0, DEFDACBLKSIZE * sizeof(*sys_soundout) *
+ sys_outchannels);
+ if (sys_getrealtime() - timenow > 0.002)
+ {
#ifdef DEBUG_ALSA_XFER
- fprintf(stderr, "output %d took %d msec\n",
- callno, (int)(1000 * (timenow - timelast))), fflush(stderr);
+ fprintf(stderr, "output %d took %d msec\n",
+ callno, (int)(1000 * (timenow - timelast))), fflush(stderr);
#endif
- timenow = sys_getrealtime();
- sys_log_error(ERR_DACSLEPT);
- }
- }
- /* do input */
- if (alsa_inchannels)
- {
- if (alsa_device.innoninterleave)
- result = snd_pcm_readn(alsa_device.inhandle, alsa_buf_ptrs,
- intransfersize);
- else result = snd_pcm_readi(alsa_device.inhandle, alsa_snd_buf,
- intransfersize);
- if (result < (int)intransfersize)
- {
+ timenow = sys_getrealtime();
+ sys_log_error(ERR_DACSLEPT);
+ }
+ }
+
+ /* do input */
+ for (iodev = 0, fp1 = sys_soundin, ch = 0; iodev < alsa_nindev; iodev++)
+ {
+ int thisdevchans = alsa_indev[iodev].a_channels;
+ int chans = (chansintogo < thisdevchans ? chansintogo : thisdevchans);
+ chansouttogo -= chans;
+ result = snd_pcm_readi(alsa_indev[iodev].a_handle, alsa_snd_buf,
+ transfersize);
+ if (result < (int)transfersize)
+ {
#ifdef DEBUG_ALSA_XFER
- if (result < 0)
- fprintf(stderr,
- "snd_pcm_read %d %d: %s\n",
- callno, xferno, snd_strerror(errno));
- else fprintf(stderr,
- "snd_pcm_read %d %d returned only %d\n",
- callno, xferno, result);
- fprintf(stderr,
- "inputcount %d, outputcount %d, inbufsize %d\n",
- inputcount, outputcount,
- (ALSA_EXTRABUFFER + sys_advance_samples)
- * alsa_samplewidth * inchannels);
+ if (result < 0)
+ fprintf(stderr,
+ "snd_pcm_read %d %d: %s\n",
+ callno, xferno, snd_strerror(errno));
+ else fprintf(stderr,
+ "snd_pcm_read %d %d returned only %d\n",
+ callno, xferno, result);
+ fprintf(stderr,
+ "inputcount %d, outputcount %d, inbufsize %d\n",
+ inputcount, outputcount,
+ (ALSA_EXTRABUFFER + sys_advance_samples)
+ * alsa_indev[iodev].a_sampwidth * inchannels);
#endif
- sys_log_error(ERR_ADCSLEPT);
- return (SENDDACS_NO);
- }
- fp = sys_soundin;
- if (alsa_samplewidth == 4)
- {
- if (alsa_device.innoninterleave)
- {
- int n = inchannels * DEFDACBLKSIZE;
- for (i = 0, fp1 = fp; i < n; i++)
- *fp1 = (float) ((t_alsa_sample32 *)alsa_snd_buf)[i]
- * (1./ INT32_MAX);
- }
- else
- {
- for (i = 0, fp1 = fp; i < inchannels;
- i++, fp1 += DEFDACBLKSIZE)
- {
- for (j = i, k = DEFDACBLKSIZE, fp2 = fp1; k--;
- j += alsa_inchannels, fp2++)
- *fp2 = (float) ((t_alsa_sample32 *)alsa_snd_buf)[j]
- * (1./ INT32_MAX);
- }
- }
- }
- else
- {
- for (i = 0, fp1 = fp; i < inchannels; i++, fp1 += DEFDACBLKSIZE)
- {
- for (j = i, k = DEFDACBLKSIZE, fp2 = fp1; k--;
- j += alsa_inchannels, fp2++)
- *fp2 = (float) ((t_alsa_sample16 *)alsa_snd_buf)[j]
- * 3.051850e-05;
- }
- }
+ sys_log_error(ERR_ADCSLEPT);
+ return (SENDDACS_NO);
+ }
+ if (alsa_indev[iodev].a_sampwidth == 4)
+ {
+ for (i = 0; i < chans; i++, ch++, fp1 += DEFDACBLKSIZE)
+ {
+ for (j = ch, k = DEFDACBLKSIZE, fp2 = fp1; k--;
+ j += thisdevchans, fp2++)
+ *fp2 = (float) ((t_alsa_sample32 *)alsa_snd_buf)[j]
+ * (1./ INT32_MAX);
+ }
+ }
+ else
+ {
+ for (i = 0; i < chans; i++, ch++, fp1 += DEFDACBLKSIZE)
+ {
+ for (j = ch, k = DEFDACBLKSIZE, fp2 = fp1; k--;
+ j += thisdevchans, fp2++)
+ *fp2 = (float) ((t_alsa_sample16 *)alsa_snd_buf)[j]
+ * 3.051850e-05;
+ }
+ }
}
+#ifdef DEBUG_ALSA_XFER
xferno++;
+#endif
if (sys_getrealtime() - timenow > 0.002)
{
#ifdef DEBUG_ALSA_XFER
- fprintf(stderr, "routine took %d msec\n",
- (int)(1000 * (sys_getrealtime() - timenow)));
+ fprintf(stderr, "routine took %d msec\n",
+ (int)(1000 * (sys_getrealtime() - timenow)));
#endif
- sys_log_error(ERR_ADCSLEPT);
+ sys_log_error(ERR_ADCSLEPT);
}
return SENDDACS_YES;
}
void alsa_printstate( void)
{
- int i, result;
+ int i, result, iodev = 0;
snd_pcm_sframes_t indelay, outdelay;
if (sys_audioapi != API_ALSA)
{
- error("restart-audio: implemented for ALSA only.");
- return;
+ error("restart-audio: implemented for ALSA only.");
+ return;
}
if (sys_inchannels)
{
- result = snd_pcm_delay(alsa_device.inhandle, &indelay);
- if (result < 0)
- post("snd_pcm_delay 1 failed");
- else post("in delay %d", indelay);
+ result = snd_pcm_delay(alsa_indev[iodev].a_handle, &indelay);
+ if (result < 0)
+ post("snd_pcm_delay 1 failed");
+ else post("in delay %d", indelay);
}
if (sys_outchannels)
{
- result = snd_pcm_delay(alsa_device.outhandle, &outdelay);
- if (result < 0)
- post("snd_pcm_delay 2 failed");
- else post("out delay %d", outdelay);
+ result = snd_pcm_delay(alsa_outdev[iodev].a_handle, &outdelay);
+ if (result < 0)
+ post("snd_pcm_delay 2 failed");
+ else post("out delay %d", outdelay);
}
post("sum %d (%d mod 64)\n", indelay + outdelay, (indelay+outdelay)%64);
@@ -753,57 +563,53 @@ void alsa_printstate( void)
void alsa_resync( void)
{
- int i, result;
+ int i, result, iodev = 0;
if (sys_audioapi != API_ALSA)
{
- error("restart-audio: implemented for ALSA only.");
- return;
+ error("restart-audio: implemented for ALSA only.");
+ return;
}
memset(alsa_snd_buf, 0,
- sizeof(char) * alsa_samplewidth * DEFDACBLKSIZE * sys_outchannels);
+ alsa_indev[iodev].a_sampwidth *
+ DEFDACBLKSIZE * sys_outchannels);
for (i = 0; i < 1000000; i++)
{
- if (alsa_device.outnoninterleave)
- result = snd_pcm_writen(alsa_device.outhandle, alsa_buf_ptrs,
- DEFDACBLKSIZE);
- else result = snd_pcm_writei(alsa_device.outhandle, alsa_snd_buf,
- DEFDACBLKSIZE);
- if (result != (int)DEFDACBLKSIZE)
- break;
+ result = snd_pcm_writei(alsa_outdev[iodev].a_handle, alsa_snd_buf,
+ DEFDACBLKSIZE);
+ if (result != (int)DEFDACBLKSIZE)
+ break;
}
post("%d written", i);
}
-void alsa_putzeros(int n)
+void alsa_putzeros(int iodev, int n)
{
int i, result;
memset(alsa_snd_buf, 0,
- sizeof(char) * alsa_samplewidth * DEFDACBLKSIZE * alsa_outchannels);
+ alsa_outdev[iodev].a_sampwidth * DEFDACBLKSIZE *
+ alsa_outdev[iodev].a_channels);
for (i = 0; i < n; i++)
{
- if (alsa_device.outnoninterleave)
- result = snd_pcm_writen(alsa_device.outhandle, alsa_buf_ptrs,
- DEFDACBLKSIZE);
- else result = snd_pcm_writei(alsa_device.outhandle, alsa_snd_buf,
- DEFDACBLKSIZE);
+ result = snd_pcm_writei(alsa_outdev[iodev].a_handle, alsa_snd_buf,
+ DEFDACBLKSIZE);
#if 0
- if (result != DEFDACBLKSIZE)
- post("result %d", result);
+ if (result != DEFDACBLKSIZE)
+ post("result %d", result);
#endif
}
/* post ("putzeros %d", n); */
}
-void alsa_getzeros(int n)
+void alsa_getzeros(int iodev, int n)
{
int i, result;
for (i = 0; i < n; i++)
{
- result = snd_pcm_readi(alsa_device.inhandle, alsa_snd_buf,
- DEFDACBLKSIZE);
+ result = snd_pcm_readi(alsa_indev[iodev].a_handle, alsa_snd_buf,
+ DEFDACBLKSIZE);
#if 0
- if (result != DEFDACBLKSIZE)
- post("result %d", result);
+ if (result != DEFDACBLKSIZE)
+ post("result %d", result);
#endif
}
/* post ("getzeros %d", n); */
@@ -812,56 +618,108 @@ void alsa_getzeros(int n)
/* call this only if both input and output are open */
static void alsa_checkiosync( void)
{
- int i, result, checkit = 1, giveup = 1000, alreadylogged = 0;
- snd_pcm_sframes_t indelay, outdelay, defect;
-
- if (!(alsa_outchannels && alsa_inchannels))
- return;
- while (checkit)
- {
- checkit = 0;
- if (giveup-- <= 0)
- return;
- result = snd_pcm_delay(alsa_device.outhandle, &outdelay);
- if (result < 0)
- {
- post("output snd_pcm_delay failed: %s", snd_strerror(result));
- if (snd_pcm_status(alsa_device.outhandle, out_status) < 0)
- post("output snd_pcm_status failed");
- else post("astate %d",
- snd_pcm_status_get_state(out_status));
- return;
- }
- if (outdelay < 0)
- sys_log_error(ERR_DATALATE), alreadylogged = 1;
-
- if (sys_inchannels)
- {
- result = snd_pcm_delay(alsa_device.inhandle, &indelay);
- if (result < 0)
- {
- post("input snd_pcm_delay failed");
- return;
- }
- defect = indelay + outdelay - alsa_buf_samps;
- if (defect < -(3 * DEFDACBLKSIZE / 2) )
- {
- checkit = 1;
- alsa_putzeros(1);
- if (!alreadylogged)
- sys_log_error(ERR_RESYNC), alreadylogged = 1;
- }
- else if (defect > 0)
- {
- checkit = 1;
- alsa_getzeros(1);
- if (!alreadylogged)
- sys_log_error(ERR_RESYNC), alreadylogged = 1;
- }
- /* if (alreadylogged)
- post("in %d out %d defect %d", indelay, outdelay, defect); */
- }
+ int i, result, giveup = 1000, alreadylogged = 0, iodev = 0;
+ snd_pcm_sframes_t minphase, maxphase, thisphase, outdelay;
+
+ while (1)
+ {
+ if (giveup-- <= 0)
+ {
+ post("tried but couldn't sync A/D/A");
+ return;
+ }
+ minphase = 0x7fffffff;
+ maxphase = -0x7fffffff;
+ for (iodev = 0; iodev < alsa_noutdev; iodev++)
+ {
+ result = snd_pcm_delay(alsa_outdev[iodev].a_handle, &outdelay);
+ if (result < 0)
+ {
+ snd_pcm_prepare(alsa_outdev[iodev].a_handle);
+ result = snd_pcm_delay(alsa_outdev[iodev].a_handle, &outdelay);
+ }
+ if (result < 0)
+ {
+ post("output snd_pcm_delay failed: %s", snd_strerror(result));
+ if (snd_pcm_status(alsa_outdev[iodev].a_handle,
+ alsa_status) < 0)
+ post("output snd_pcm_status failed");
+ else post("astate %d",
+ snd_pcm_status_get_state(alsa_status));
+ return;
+ }
+ thisphase = alsa_buf_samps - outdelay;
+ if (thisphase < minphase)
+ minphase = thisphase;
+ if (thisphase > maxphase)
+ maxphase = thisphase;
+ if (outdelay < 0)
+ sys_log_error(ERR_DATALATE), alreadylogged = 1;
+ }
+ for (iodev = 0; iodev < alsa_nindev; iodev++)
+ {
+ result = snd_pcm_delay(alsa_indev[iodev].a_handle, &thisphase);
+ if (result < 0)
+ {
+ snd_pcm_prepare(alsa_indev[iodev].a_handle);
+ result = snd_pcm_delay(alsa_indev[iodev].a_handle, &thisphase);
+ }
+ if (result < 0)
+ {
+ post("output snd_pcm_delay failed: %s", snd_strerror(result));
+ if (snd_pcm_status(alsa_outdev[iodev].a_handle,
+ alsa_status) < 0)
+ post("output snd_pcm_status failed");
+ else post("astate %d",
+ snd_pcm_status_get_state(alsa_status));
+ return;
+ }
+ if (thisphase < minphase)
+ minphase = thisphase;
+ if (thisphase > maxphase)
+ maxphase = thisphase;
+ }
+ /* the "correct" position is for all the phases to be exactly
+ equal; but since we only make corrections DEFDACBLKSIZE samples
+ at a time, we just ask that the spread be not more than 3/4
+ of a block. */
+ if (maxphase <= minphase + (3 * DEFDACBLKSIZE / 4))
+ break;
+
+ if (!alreadylogged)
+ sys_log_error(ERR_RESYNC), alreadylogged = 1;
+ for (iodev = 0; iodev < alsa_noutdev; iodev++)
+ {
+ result = snd_pcm_delay(alsa_outdev[iodev].a_handle, &outdelay);
+ if (result < 0)
+ break;
+ thisphase = alsa_buf_samps - outdelay;
+ if (thisphase > minphase + DEFDACBLKSIZE)
+ {
+ alsa_putzeros(iodev, 1);
+#if DEBUGSYNC
+ fprintf(stderr, "putz %d %d\n", (int)thisphase, (int)minphase);
+#endif
+ }
+ }
+ for (iodev = 0; iodev < alsa_nindev; iodev++)
+ {
+ result = snd_pcm_delay(alsa_indev[iodev].a_handle, &thisphase);
+ if (result < 0)
+ break;
+ if (thisphase > minphase + DEFDACBLKSIZE)
+ {
+ alsa_getzeros(iodev, 1);
+#if DEBUGSYNC
+ fprintf(stderr, "getz %d %d\n", (int)thisphase, (int)minphase);
+#endif
+ }
+ }
}
+#if DEBUGSYNC
+ if (alreadylogged)
+ fprintf(stderr, "done\n");
+#endif
}
static int alsa_nnames = 0;
@@ -870,9 +728,9 @@ static char **alsa_names = 0;
void alsa_adddev(char *name)
{
if (alsa_nnames)
- alsa_names = (char **)t_resizebytes(alsa_names,
- alsa_nnames * sizeof(char *),
- (alsa_nnames+1) * sizeof(char *));
+ alsa_names = (char **)t_resizebytes(alsa_names,
+ alsa_nnames * sizeof(char *),
+ (alsa_nnames+1) * sizeof(char *));
else alsa_names = (char **)t_getbytes(sizeof(char *));
alsa_names[alsa_nnames] = gensym(name)->s_name;
alsa_nnames++;
@@ -882,15 +740,15 @@ static void alsa_numbertoname(int devno, char *devname, int nchar)
{
int ndev = 0, cardno = -1;
while (!snd_card_next(&cardno) && cardno >= 0)
- ndev++;
+ ndev++;
if (devno < 2*ndev)
{
- if (devno & 1)
- snprintf(devname, nchar, "plughw:%d", devno/2);
- else snprintf(devname, nchar, "hw:%d", devno/2);
+ if (devno & 1)
+ snprintf(devname, nchar, "plughw:%d", devno/2);
+ else snprintf(devname, nchar, "hw:%d", devno/2);
}
else if (devno <2*ndev + alsa_nnames)
- snprintf(devname, nchar, "%s", alsa_names[devno - 2*ndev]);
+ snprintf(devname, nchar, "%s", alsa_names[devno - 2*ndev]);
else snprintf(devname, nchar, "???");
}
@@ -898,48 +756,48 @@ static void alsa_numbertoname(int devno, char *devname, int nchar)
"plug" one. The card scan is derived from portaudio code. */
void alsa_getdevs(char *indevlist, int *nindevs,
char *outdevlist, int *noutdevs, int *canmulti,
- int maxndev, int devdescsize)
+ int maxndev, int devdescsize)
{
int ndev = 0, cardno = -1, i, j;
- *canmulti = 0; /* only one device; must be the same for input&output */
+ *canmulti = 2; /* supports multiple devices */
while (!snd_card_next(&cardno) && cardno >= 0)
{
- snd_ctl_t *ctl;
- snd_ctl_card_info_t *info;
+ snd_ctl_t *ctl;
+ snd_ctl_card_info_t *info;
char devname[80];
- const char *desc;
- if (2 * ndev + 2 > maxndev)
- break;
- /* apparently, "cardno" is just a counter; but check that here */
- if (ndev != cardno)
- fprintf(stderr, "oops: ALSA cards not reported in order?\n");
+ const char *desc;
+ if (2 * ndev + 2 > maxndev)
+ break;
+ /* apparently, "cardno" is just a counter; but check that here */
+ if (ndev != cardno)
+ fprintf(stderr, "oops: ALSA cards not reported in order?\n");
sprintf(devname, "hw:%d", cardno );
/* fprintf(stderr, "\ntry %s...\n", devname); */
if (snd_ctl_open(&ctl, devname, 0) >= 0)
- {
+ {
snd_ctl_card_info_malloc(&info);
snd_ctl_card_info(ctl, info);
- desc = snd_ctl_card_info_get_name(info);
- snd_ctl_card_info_free(info);
- }
- else
- {
- fprintf(stderr, "ALSA card scan error\n");
- desc = "???";
- }
+ desc = snd_ctl_card_info_get_name(info);
+ snd_ctl_card_info_free(info);
+ }
+ else
+ {
+ fprintf(stderr, "ALSA card scan error\n");
+ desc = "???";
+ }
/* fprintf(stderr, "name: %s\n", snd_ctl_card_info_get_name(info)); */
sprintf(indevlist + 2*ndev * devdescsize, "%s (hardware)", desc);
sprintf(indevlist + (2*ndev + 1) * devdescsize, "%s (plug-in)", desc);
sprintf(outdevlist + 2*ndev * devdescsize, "%s (hardware)", desc);
sprintf(outdevlist + (2*ndev + 1) * devdescsize, "%s (plug-in)", desc);
- ndev++;
+ ndev++;
}
for (i = 0, j = 2*ndev; i < alsa_nnames; i++, j++)
{
- if (j >= maxndev)
- break;
+ if (j >= maxndev)
+ break;
snprintf(indevlist + j * devdescsize, devdescsize, "%s",
- alsa_names[i]);
+ alsa_names[i]);
}
*nindevs = *noutdevs = j;
}
diff --git a/pd/src/s_audio_alsa.h b/pd/src/s_audio_alsa.h
new file mode 100644
index 00000000..813be211
--- /dev/null
+++ b/pd/src/s_audio_alsa.h
@@ -0,0 +1,40 @@
+/* Copyright (c) 1997- Guenter Geiger, Miller Puckette, Larry Troxler,
+* Winfried Ritsch, Karl MacMillan, and others.
+* For information on usage and redistribution, and for a DISCLAIMER OF ALL
+* WARRANTIES, see the file, "LICENSE.txt," in this distribution. */
+
+
+typedef int16_t t_alsa_sample16;
+typedef int32_t t_alsa_sample32;
+#define ALSA_SAMPLEWIDTH_16 sizeof(t_alsa_sample16)
+#define ALSA_SAMPLEWIDTH_32 sizeof(t_alsa_sample32)
+#define ALSA_XFERSIZE16 (signed int)(sizeof(t_alsa_sample16) * DEFDACBLKSIZE)
+#define ALSA_XFERSIZE32 (signed int)(sizeof(t_alsa_sample32) * DEFDACBLKSIZE)
+#define ALSA_MAXDEV 4
+#define ALSA_JITTER 1024
+#define ALSA_EXTRABUFFER 2048
+#define ALSA_DEFFRAGSIZE 64
+#define ALSA_DEFNFRAG 12
+
+#ifndef INT32_MAX
+#define INT32_MAX 0x7fffffff
+#endif
+
+typedef struct _alsa_dev
+{
+ snd_pcm_t *a_handle;
+ int a_devno;
+ int a_sampwidth;
+ int a_channels;
+ char **a_addr;
+ int a_synced;
+} t_alsa_dev;
+
+extern t_alsa_dev alsa_indev[ALSA_MAXDEV];
+extern t_alsa_dev alsa_outdev[ALSA_MAXDEV];
+extern int alsa_nindev;
+extern int alsa_noutdev;
+
+int alsamm_open_audio(int rate);
+void alsamm_close_audio(void);
+int alsamm_send_dacs(void);
diff --git a/pd/src/s_audio_alsamm.c b/pd/src/s_audio_alsamm.c
new file mode 100644
index 00000000..6d140044
--- /dev/null
+++ b/pd/src/s_audio_alsamm.c
@@ -0,0 +1,1359 @@
+/* Copyright (c) 1997-2003 Guenter Geiger, Miller Puckette, Larry Troxler,
+* Winfried Ritsch, Karl MacMillan, and others.
+* For information on usage and redistribution, and for a DISCLAIMER OF ALL
+* WARRANTIES, see the file, "LICENSE.txt," in this distribution. */
+
+/*
+ this audiodriverinterface inputs and outputs audio data using
+ the ALSA MMAP API available on linux.
+ this is optimized for hammerfall cards and does not make an attempt to be general
+ now, please adapt to your needs or let me know ...
+ constrains now:
+ - audio Card with ALSA-Driver > 1.0.3,
+ - alsa-device (preferable hw) with MMAP NONINTERLEAVED SIGNED-32Bit features
+ - up to 4 cards with has to be hardwaresynced
+ (winfried)
+*/
+#include <alsa/asoundlib.h>
+
+#include "m_pd.h"
+#include "s_stuff.h"
+#include <errno.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/time.h>
+#include <sys/stat.h>
+#include <sys/ioctl.h>
+#include <fcntl.h>
+#include <sched.h>
+#include "s_audio_alsa.h"
+
+/* sample type magic ...
+ Hammerfall/HDSP/DSPMADI cards always 32Bit where lower 8Bit not used (played) in AD/DA,
+ but can have some bits set (subchannel coding)
+*/
+/* sample type magic ...
+ Hammerfall/HDSP/DSPMADI cards always 32Bit where lower 8Bit not used (played) in AD/DA,
+ but can have some bits set (subchannel coding)
+*/
+
+#define ALSAMM_SAMPLEWIDTH_32 sizeof(t_alsa_sample32)
+
+#ifndef INT32_MAX
+#define INT32_MAX 0x7fffffff
+#endif
+
+/* maybe:
+ don't assume we can turn all 31 bits when doing float-to-fix;
+ otherwise some audio drivers (e.g. Midiman/ALSA) wrap around.
+
+ but not now on hammerfall (w)
+*/
+
+/* 24 Bit are used so MAX Samplevalue not INT32_MAX ??? */
+#define F32MAX 0x7fffff00
+#define CLIP32(x) (((x)>F32MAX)?F32MAX:((x) < -F32MAX)?-F32MAX:(x))
+
+#define ALSAMM_FORMAT SND_PCM_FORMAT_S32
+/*
+ maximum of 4 devices
+ you can mix rme9632,hdsp9632 (18 chans) rme9652,hdsp9652 (26 chans), dsp-madi (64 chans)
+ if synced
+*/
+
+/* the concept is holding data for each device
+ where a device is in and output and has one name.
+
+ but since we can use only ins or only outs or both
+ on each hardware we list them in used_???device
+ for alsa seperated for inputs and outputs
+
+ due the need to link in and out-device on one card
+ and do only one mmap prepare and start for in and out
+ the concept turns out to be not very efficient,
+ so i will change it maybe in future...
+*/
+
+static int alsamm_incards = 0;
+static t_alsa_dev *alsamm_indevice[ALSA_MAXDEV];
+static int alsamm_outcards = 0;
+static t_alsa_dev *alsamm_outdevice[ALSA_MAXDEV];
+
+/*
+ we need same samplerate, buffertime and so on for
+ each card soo we use global vars...
+ time is in us, size in frames (i hope so ;-)
+*/
+static unsigned int alsamm_sr = 0;
+static unsigned int alsamm_buffertime = 0;
+static unsigned int alsamm_buffersize = 0;
+static int alsamm_transfersize = DEFDACBLKSIZE;
+
+/* bad style: we asume all cards give the same answer at init so we make this vars global
+ to have a faster access in writing reading during send_dacs */
+static snd_pcm_sframes_t alsamm_period_size;
+static unsigned int alsamm_periods;
+static snd_pcm_sframes_t alsamm_buffer_size;
+
+/* if more than this sleep detected, should be more than periodsize/samplerate ??? */
+static double sleep_time;
+
+/* now we just sum all inputs/outputs of used cards to a global count
+ and use them all
+ ... later we should just use some channels of each card for pd
+ so we reduce the overhead of using alsways all channels,
+ and zero the rest once at start,
+ because rme9652 and hdsp forces us to use all channels
+ in mmap mode...
+
+Note on why:
+ normally hdsp and dspmadi can handle channel
+ count from one to all since they can switch on/off
+ the dma for them to reduce pci load, but this is only
+ implemented in alsa low level drivers for dspmadi now and maybe fixed for hdsp in future
+*/
+
+static int alsamm_inchannels = 0;
+static int alsamm_outchannels = 0;
+
+/* Defines */
+/*#define ALSAMM_DEBUG */
+#ifdef ALSAMM_DEBUG
+
+ #define DEBUG(x) x
+ #define DEBUG2(x) {x;}
+
+ #define WATCH_PERIODS 90
+
+ static int in_avail[WATCH_PERIODS];
+ static int out_avail[WATCH_PERIODS];
+ static int in_offset[WATCH_PERIODS];
+ static int out_offset[WATCH_PERIODS];
+ static int out_cm[WATCH_PERIODS];
+ static char *outaddr[WATCH_PERIODS];
+ static char *inaddr[WATCH_PERIODS];
+ static char *outaddr2[WATCH_PERIODS];
+ static char *inaddr2[WATCH_PERIODS];
+ static int xruns_watch[WATCH_PERIODS];
+ static int broken_opipe;
+
+ static int dac_send = 0;
+ static int alsamm_xruns = 0;
+
+static void show_availist(void)
+{
+ int i;
+ for(i=1;i<WATCH_PERIODS;i++){
+ post("%2d:avail i=%7d %s o=%7d(%5d), offset i=%7d %s o=%7d, ptr i=%12p o=%12p, %d xruns ",
+ i,in_avail[i],(out_avail[i] != in_avail[i])? "!=" : "==" , out_avail[i],out_cm[i],
+ in_offset[i],(out_offset[i] != in_offset[i])? "!=" : "==" , out_offset[i],
+ inaddr[i], outaddr[i], xruns_watch[i]);
+ }
+}
+#else
+ #define DEBUG(x)
+ #define DEBUG2(x) {}
+#endif
+
+/* protos */
+static char *alsamm_getdev(int nr);
+
+static int set_hwparams(snd_pcm_t *handle,
+ snd_pcm_hw_params_t *params, int *chs);
+static int set_swparams(snd_pcm_t *handle,
+ snd_pcm_sw_params_t *swparams, int playback);
+
+static int alsamm_start(void);
+static int alsamm_stop(void);
+
+/* for debugging attach output of alsa mesages to stdout stream */
+snd_output_t* alsa_stdout;
+
+static void check_error(int err, const char *why)
+{
+ if (err < 0)
+ error("%s: %s\n", why, snd_strerror(err));
+}
+
+int alsamm_open_audio(int rate)
+{
+ int err;
+ char devname[80];
+ char *cardname;
+ snd_pcm_hw_params_t* hw_params;
+ snd_pcm_sw_params_t* sw_params;
+
+
+ /* fragsize is an old concept now use periods, used to be called fragments. */
+ /* Be aware in ALSA periodsize can be in bytes, where buffersize is in frames,
+ but sometimes buffersize is in bytes and periods in frames, crazy alsa...
+ ...we use periodsize and buffersize in frames */
+
+ int i;
+ short* tmp_buf;
+ unsigned int tmp_uint;
+
+ snd_pcm_hw_params_alloca(&hw_params);
+ snd_pcm_sw_params_alloca(&sw_params);
+
+ /* see add_devname */
+ /* first have a look which cards we can get and
+ set up device infos for them */
+
+#ifdef ALSAMM_DEBUG
+ if(sys_verbose)
+ post("naudioindev=%d, nchindev=%d, naudiooutdev=%d, nchoutdev=%d,rate=%d",
+ naudioindev, nchindev,naudiooutdev, nchoutdev, rate);
+#endif
+
+ /* init some structures */
+ for(i=0;i < ALSA_MAXDEV;i++){
+ alsa_indev[i].a_synced=alsa_outdev[i].a_synced=0;
+ alsa_indev[i].a_channels=alsa_outdev[i].a_channels=0;
+ }
+
+ /* opening alsa debug channel */
+ err = snd_output_stdio_attach(&alsa_stdout, stdout, 0);
+ if (err < 0) {
+ check_error(err,"attaching alsa debug Output to stdout failed");
+ /* return; no so bad ... and never should happe */
+ }
+
+
+ /*
+ Weak failure prevention:
+ first card found (out then in) is used as a reference for parameter,
+ so this set the globals and other cards hopefully dont change them
+ */
+ alsamm_sr = rate;
+
+ /* set the asked buffer time (alsa buffertime in us)*/
+ alsamm_buffertime = alsamm_buffersize = 0;
+ if(sys_blocksize == 0)
+ alsamm_buffertime = sys_schedadvance;
+ else
+ alsamm_buffersize = sys_blocksize;
+
+ if(sys_verbose)
+ post("syschedadvance=%d us(%d Samples)so buffertime max should be this=%d"
+ "or sys_blocksize=%d (samples) to use buffersize=%d",
+ sys_schedadvance,sys_advance_samples,alsamm_buffertime,
+ sys_blocksize,alsamm_buffersize);
+
+ alsamm_periods = 0; /* no one wants periods setting from command line ;-) */
+
+ for(i=0;i<alsa_noutdev;i++)
+ {
+
+
+ /* post("open audio out %d, of %lx, %d",i,&alsa_device[i],
+ alsa_outdev[i].a_handle); */
+ if((err = set_hwparams(alsa_outdev[i].a_handle, hw_params,
+ &(alsa_outdev[i].a_channels))) < 0)
+ {
+ check_error(err,"playback device hwparam_set error:");
+ continue;
+ }
+
+ if((err = set_swparams(alsa_outdev[i].a_handle, sw_params,1)) < 0){
+ check_error(err,"playback device swparam_set error:");
+ continue;
+ }
+
+ alsamm_outchannels += alsa_outdev[i].a_channels;
+
+ alsa_outdev[i].a_addr =
+ (char **) malloc(sizeof(char *) * alsa_outdev[i].a_channels);
+
+ if(alsa_outdev[i].a_addr == NULL){
+ check_error(errno,"playback device outaddr allocation error:");
+ continue;
+ }
+ memset(alsa_outdev[i].a_addr, 0, sizeof(char*) * alsa_outdev[i].a_channels);
+
+ post("playback device with %d channels and buffer_time %d us opened",
+ alsa_outdev[i].a_channels, alsamm_buffertime);
+ }
+
+
+ for(i=0;i<alsa_nindev;i++)
+ {
+
+ if(sys_verbose)
+ post("capture card %d:--------------------",i);
+
+ if((err = set_hwparams(alsa_indev[i].a_handle, hw_params,
+ &(alsa_indev[i].a_channels))) < 0)
+ {
+ check_error(err,"capture device hwparam_set error:");
+ continue;
+ }
+
+ alsamm_inchannels += alsa_indev[i].a_channels;
+
+ if((err = set_swparams(alsa_indev[i].a_handle,
+ sw_params,0)) < 0){
+ check_error(err,"capture device swparam_set error:");
+ continue;
+ }
+
+ alsa_indev[i].a_addr =
+ (char **) malloc (sizeof(char*) * alsa_indev[i].a_channels);
+
+ if(alsa_indev[i].a_addr == NULL){
+ check_error(errno,"capture device inaddr allocation error:");
+ continue;
+ }
+
+ memset(alsa_indev[i].a_addr, 0, sizeof(char*) * alsa_indev[i].a_channels);
+
+ if(sys_verbose)
+ post("capture device with %d channels and buffertime %d us opened\n",
+ alsa_indev[i].a_channels,alsamm_buffertime);
+ }
+
+ /* check for linked handles of input for each output*/
+
+ for(i=0; i<(alsa_noutdev < alsa_nindev ? alsa_noutdev:alsa_nindev); i++){
+ t_alsa_dev *ad = &alsa_outdev[i];
+
+ if (alsa_outdev[i].a_devno == alsa_indev[i].a_devno){
+ if ((err = snd_pcm_link (alsa_indev[i].a_handle,
+ alsa_outdev[i].a_handle)) == 0){
+ alsa_indev[i].a_synced = alsa_outdev[i].a_synced = 1;
+ if(sys_verbose)
+ post("Linking in and outs of card %d",i);
+ }
+ else
+ check_error(err,"could not link in and outs");
+ }
+ }
+
+ /* some globals */
+ sleep_time = (float) alsamm_period_size/ (float) alsamm_sr;
+
+
+#ifdef ALSAMM_DEBUG
+ /* start ---------------------------- */
+ if(sys_verbose)
+ post("open_audio: after dacsend=%d (xruns=%d)done",dac_send,alsamm_xruns);
+ alsamm_xruns = dac_send = 0; /* reset debug */
+
+ /* start alsa in open or better in send_dacs once ??? we will see */
+
+ for(i=0;i<alsa_noutdev;i++)
+ snd_pcm_dump(alsa_outdev[i].a_handle, alsa_stdout);
+
+ for(i=0;i<alsa_nindev;i++)
+ snd_pcm_dump(alsa_indev[i].inhandle, alsa_stdout);
+
+ fflush(stdout);
+#endif
+
+ alsamm_start();
+
+ /* report success */
+ return (0);
+}
+
+
+void alsamm_close_audio(void)
+{
+ int i,err;
+
+
+#ifdef ALSAMM_DEBUG
+ if(sys_verbose)
+ post("closing devices");
+#endif
+
+ alsamm_stop();
+
+ for(i=0;i< alsa_noutdev;i++){
+
+
+#ifdef ALSAMM_DEBUG
+ if(sys_verbose)
+ post("unlink audio out %d, of %lx",i,used_outdevice[i]);
+#endif
+
+ if(alsa_outdev[i].a_synced != 0){
+ if((err = snd_pcm_unlink(alsa_outdev[i].a_handle)) < 0)
+ check_error(err, "snd_pcm_unlink (output)");
+ alsa_outdev[i].a_synced = 0;
+ }
+
+ if((err = snd_pcm_close(alsa_outdev[i].a_handle)) <= 0)
+ check_error(err, "snd_pcm_close (output)");
+
+ if(alsa_outdev[i].a_addr){
+ free(alsa_outdev[i].a_addr);
+ alsa_outdev[i].a_addr = NULL;
+ }
+ alsa_outdev[i].a_channels = 0;
+ }
+
+ for(i=0;i< alsa_nindev;i++){
+
+ err = snd_pcm_close(alsa_indev[i].a_handle);
+
+ if(sys_verbose)
+ check_error(err, "snd_pcm_close (input)");
+
+ if(alsa_indev[i].a_addr){
+ free(alsa_indev[i].a_addr);
+ alsa_indev[i].a_addr = NULL;
+ }
+
+ alsa_indev[i].a_channels = 0;
+ }
+ alsa_nindev = alsa_noutdev = 0;
+#ifdef ALSAMM_DEBUG
+ if(sys_verbose)
+ post("close_audio: after dacsend=%d (xruns=%d)done",dac_send,alsamm_xruns);
+ alsamm_xruns = dac_send = 0;
+#endif
+}
+
+/* ------- PCM INITS --------------------------------- */
+static int set_hwparams(snd_pcm_t *handle, snd_pcm_hw_params_t *params,int *chs)
+{
+ unsigned int rrate;
+ int err, dir;
+ int channels_allocated = 0;
+
+ /* choose all parameters */
+ err = snd_pcm_hw_params_any(handle, params);
+ if (err < 0) {
+ check_error(err,"Broken configuration: no configurations available");
+ return err;
+ }
+
+ /* set the nointerleaved read/write format */
+ err = snd_pcm_hw_params_set_access(handle, params,
+ SND_PCM_ACCESS_MMAP_NONINTERLEAVED);
+ if (err >= 0) {
+#ifdef ALSAMM_DEBUG
+ if(sys_verbose)
+ post("Access type %s available","SND_PCM_ACCESS_MMAP_NONINTERLEAVED");
+#endif
+ }
+ else{
+ check_error(err,"No Accesstype SND_PCM_ACCESS_MMAP_NONINTERLEAVED");
+ return err;
+ }
+
+ /* set the sample format */
+ err = snd_pcm_hw_params_set_format(handle, params, ALSAMM_FORMAT);
+ if (err < 0) {
+ check_error(err,"Sample format not available for playback");
+ return err;
+ }
+
+#ifdef ALSAMM_DEBUG
+ if(sys_verbose)
+ post("Setting format to %s",snd_pcm_format_name(ALSAMM_FORMAT));
+#endif
+
+ /* first check samplerate since channels numbers
+ are samplerate dependend (double speed) */
+ /* set the stream rate */
+
+ rrate = alsamm_sr;
+
+#ifdef ALSAMM_DEBUG
+ if(sys_verbose)
+ post("Samplerate request: %i Hz",rrate);
+#endif
+
+ dir=-1;
+ err = snd_pcm_hw_params_set_rate_near(handle, params, &rrate, &dir);
+ if (err < 0) {
+ check_error(err,"Rate not available");
+ return err;
+ }
+
+ if (rrate != alsamm_sr) {
+ post("Warning: rate %iHz doesn't match requested %iHz", rrate,alsamm_sr);
+ alsamm_sr = rrate;
+ }
+ else
+ if(sys_verbose)
+ post("Samplerate is set to %iHz",alsamm_sr);
+
+ /* Info on channels */
+ {
+ int maxchs,minchs,channels = *chs;
+
+ if((err = snd_pcm_hw_params_get_channels_max(params,&maxchs)) < 0){
+ check_error(err,"Getting channels_max not available");
+ return err;
+ }
+ if((err = snd_pcm_hw_params_get_channels_min(params,&minchs)) < 0){
+ check_error(err,"Getting channels_min not available");
+ return err;
+ }
+
+#ifdef ALSAMM_DEBUG
+ if(sys_verbose)
+ post("Getting channels:min=%d, max= %d for request=%d",minchs,maxchs,channels);
+#endif
+
+ if(channels > maxchs)channels = maxchs;
+ if(channels < minchs)channels = minchs;
+
+ if(channels != *chs)
+ post("requested channels=%d but used=%d",*chs,channels);
+
+ *chs = channels;
+#ifdef ALSAMM_DEBUG
+ if(sys_verbose)
+ post("trying to use channels: %d",channels);
+#endif
+ }
+
+ /* set the count of channels */
+ err = snd_pcm_hw_params_set_channels(handle, params, *chs);
+ if (err < 0) {
+ check_error(err,"Channels count not available");
+ return err;
+ }
+
+ /* testing for channels */
+ if((err = snd_pcm_hw_params_get_channels(params,chs)) < 0)
+ check_error(err,"Get channels not available");
+#ifdef ALSAMM_DEBUG
+ else
+ if(sys_verbose)
+ post("When setting channels count and got %d",*chs);
+#endif
+
+ /* if buffersize is set use this instead buffertime */
+ if(alsamm_buffersize > 0){
+
+#ifdef ALSAMM_DEBUG
+ if(sys_verbose)
+ post("hw_params: ask for max buffersize of %d samples",
+ (unsigned int) alsamm_buffersize );
+#endif
+
+ alsamm_buffer_size = alsamm_buffersize;
+
+ err = snd_pcm_hw_params_set_buffer_size_near(handle, params, &alsamm_buffer_size);
+ if (err < 0) {
+ check_error(err,"Unable to set max buffer size");
+ return err;
+ }
+
+ }
+ else{
+ if(alsamm_buffertime <= 0) /* should never happen, but use 20ms */
+ alsamm_buffertime = 20000;
+
+#ifdef ALSAMM_DEBUG
+ if(sys_verbose)
+ post("hw_params: ask for max buffertime of %d ms",
+ (unsigned int) (alsamm_buffertime*0.001) );
+#endif
+
+ err = snd_pcm_hw_params_set_buffer_time_near(handle, params, &alsamm_buffertime, &dir);
+ if (err < 0) {
+ check_error(err,"Unable to set max buffer time");
+ return err;
+ }
+ }
+
+ err = snd_pcm_hw_params_get_buffer_time(params, &alsamm_buffertime, &dir);
+ if (err < 0) {
+ check_error(err,"Unable to get buffer time");
+ return err;
+ }
+
+#ifdef ALSAMM_DEBUG
+ if(sys_verbose)
+ post("hw_params: got buffertime to %f ms",
+ (float) (alsamm_buffertime*0.001));
+#endif
+
+ err = snd_pcm_hw_params_get_buffer_size(params, &alsamm_buffer_size);
+ if (err < 0) {
+ check_error(err,"Unable to get buffer size");
+ return err;
+ }
+
+#ifdef ALSAMM_DEBUG
+ if(sys_verbose)
+ post("hw_params: got buffersize to %d samples",(int) alsamm_buffer_size);
+#endif
+
+ err = snd_pcm_hw_params_get_period_size(params, &alsamm_period_size, &dir);
+ if (err > 0) {
+ check_error(err,"Unable to get period size");
+ return err;
+ }
+
+#ifdef ALSAMM_DEBUG
+ if(sys_verbose)
+ post("Got period size of %d", (int) alsamm_period_size);
+#endif
+ {
+ unsigned int pmin,pmax;
+
+ err = snd_pcm_hw_params_get_periods_min(params, &pmin, &dir);
+ if (err > 0) {
+ check_error(err,"Unable to get period size");
+ return err;
+ }
+ err = snd_pcm_hw_params_get_periods_min(params, &pmax, &dir);
+ if (err > 0) {
+ check_error(err,"Unable to get period size");
+ return err;
+ }
+
+ /* use maximum of periods */
+ if( alsamm_periods <= 0)
+ alsamm_periods = pmax;
+ alsamm_periods = (alsamm_periods > pmax)?pmax:alsamm_periods;
+ alsamm_periods = (alsamm_periods < pmin)?pmin:alsamm_periods;
+
+ err = snd_pcm_hw_params_set_periods(handle, params, alsamm_periods, dir);
+ if (err > 0) {
+ check_error(err,"Unable to set periods");
+ return err;
+ }
+
+
+ err = snd_pcm_hw_params_get_periods(params, &pmin, &dir);
+ if (err > 0) {
+ check_error(err,"Unable to get periods");
+ return err;
+ }
+#ifdef ALSAMM_DEBUG
+ if(sys_verbose)
+ post("Got periods of %d, where periodsmin=%d, periodsmax=%d",
+ alsamm_periods,pmin,pmax);
+#endif
+ }
+
+ /* write the parameters to device */
+ err = snd_pcm_hw_params(handle, params);
+ if (err < 0) {
+ check_error(err,"Unable to set hw params");
+ return err;
+ }
+ return 0;
+}
+
+static int set_swparams(snd_pcm_t *handle, snd_pcm_sw_params_t *swparams, int playback)
+{
+ int err;
+ snd_pcm_uframes_t ps,ops;
+ snd_pcm_uframes_t bs,obs;
+
+ /* get the current swparams */
+ err = snd_pcm_sw_params_current(handle, swparams);
+ if (err < 0) {
+ check_error(err,"Unable to determine current swparams for playback");
+ return err;
+ }
+
+ /* AUTOSTART: start the transfer on each write/commit ??? */
+ snd_pcm_sw_params_get_start_threshold(swparams, &obs);
+
+ err = snd_pcm_sw_params_set_start_threshold(handle, swparams, 0U);
+ if (err < 0) {
+ check_error(err,"Unable to set start threshold mode");
+ return err;
+ }
+
+ snd_pcm_sw_params_get_start_threshold(swparams, &bs);
+
+#ifdef ALSAMM_DEBUG
+ if(sys_verbose)
+ post("sw_params: got start_thresh_hold= %d (was %d)",(int) bs,(int)obs);
+#endif
+
+ /* AUTOSTOP: never stop the machine */
+
+ snd_pcm_sw_params_get_stop_threshold(swparams, &obs);
+
+ err = snd_pcm_sw_params_set_stop_threshold(handle, swparams, (snd_pcm_uframes_t)-1);
+ if (err < 0) {
+ check_error(err,"Unable to set stop threshold mode");
+ return err;
+ }
+
+ snd_pcm_sw_params_get_stop_threshold(swparams, &bs);
+#ifdef ALSAMM_DEBUG
+ if(sys_verbose)
+ post("sw_params: set stop_thresh_hold= %d (was %d)", (int) bs,(int)obs);
+#endif
+
+
+ /* AUTOSILENCE: silence if overrun.... */
+
+ snd_pcm_sw_params_get_silence_threshold (swparams, &ops);
+ if ((err = snd_pcm_sw_params_set_silence_threshold (handle, swparams, alsamm_period_size)) < 0) {
+ check_error (err,"cannot set silence threshold for");
+ return -1;
+ }
+ snd_pcm_sw_params_get_silence_threshold (swparams, &ps);
+#ifdef ALSAMM_DEBUG
+ if(sys_verbose)
+ post("sw_params: set silence_threshold = %d (was %d)", (int) ps,(int)ops);
+#endif
+
+ snd_pcm_sw_params_get_silence_size (swparams, &ops);
+ if ((err = snd_pcm_sw_params_set_silence_size(handle, swparams, alsamm_period_size)) < 0) {
+ check_error (err,"cannot set silence size for");
+ return -1;
+ }
+ snd_pcm_sw_params_get_silence_size (swparams, &ps);
+#ifdef ALSAMM_DEBUG
+ if(sys_verbose)
+ post("sw_params: set silence_size = %d (was %d)", (int) ps,(int)ops);
+#endif
+
+ /* AVAIL: allow the transfer when at least period_size samples can be processed */
+
+ snd_pcm_sw_params_get_avail_min(swparams, &ops);
+
+ err = snd_pcm_sw_params_set_avail_min(handle, swparams, alsamm_transfersize/2);
+ if (err < 0) {
+ check_error(err,"Unable to set avail min for");
+ return err;
+ }
+
+ snd_pcm_sw_params_get_avail_min(swparams, &ps);
+#ifdef ALSAMM_DEBUG
+ if(sys_verbose)
+ post("sw_params: set avail_min= %d (was %d)", (int) ps, (int) ops);
+#endif
+
+ /* ALIGN: align all transfers to 1 sample */
+
+ snd_pcm_sw_params_get_xfer_align(swparams, &ops);
+ err = snd_pcm_sw_params_set_xfer_align(handle, swparams, 1);
+ if (err < 0) {
+ check_error(err,"Unable to set transfer align for playback");
+ return err;
+ }
+ snd_pcm_sw_params_get_xfer_align(swparams, &ps);
+
+#ifdef ALSAMM_DEBUG
+ if(sys_verbose)
+ post("sw_params: set xfer_align = %d (was %d)", (int) ps, (int) ops);
+#endif
+
+ /* write the parameters to the playback device */
+
+ err = snd_pcm_sw_params(handle, swparams);
+ if (err < 0) {
+ check_error(err,"Unable to set sw params");
+ return err;
+ }
+
+#ifdef ALSAMM_DEBUG
+ if(sys_verbose)
+ post("set sw finished");
+#endif
+ return 0;
+}
+
+/* ALSA Transfer helps */
+
+/* xrun_recovery is called if time to late or error
+
+ Note: use outhandle if synced i/o
+ the devices are linked so prepare
+ has only be called on out,
+ hopefully resume too...
+*/
+
+static int xrun_recovery(snd_pcm_t *handle, int err)
+{
+#ifdef ALSAMM_DEBUG
+ alsamm_xruns++; /* count xruns */
+#endif
+
+ if (err == -EPIPE) { /* under-run */
+ err = snd_pcm_prepare(handle);
+ if (err < 0)
+ check_error(err,"Can't recovery from underrun, prepare failed.");
+
+ err = snd_pcm_start(handle);
+ if (err < 0)
+ check_error(err,"Can't start when recover from underrun.");
+
+ return 0;
+ } else if (err == -ESTRPIPE) {
+ while ((err = snd_pcm_resume(handle)) == -EAGAIN)
+ sleep(1); /* wait until the suspend flag is released */
+ if (err < 0) {
+ err = snd_pcm_prepare(handle);
+ if (err < 0)
+ check_error(err,"Can't recovery from suspend, prepare failed.");
+
+ err = snd_pcm_start(handle);
+ if (err < 0)
+ check_error(err,"Can't start when recover from underrun.");
+ }
+ return 0;
+ }
+
+ return err;
+}
+
+/* note that snd_pcm_avail has to be called before using this funtion */
+
+static int alsamm_get_channels(snd_pcm_t *dev,
+ snd_pcm_uframes_t *avail,
+ snd_pcm_uframes_t *offset,
+ int nchns, char **addr)
+{
+ int err = 0;
+ int chn;
+ const snd_pcm_channel_area_t *mm_areas;
+
+
+ if (nchns > 0 && avail != NULL && offset != NULL) {
+
+ if ((err = snd_pcm_mmap_begin(dev, &mm_areas, offset, avail)) < 0){
+ check_error(err,"setmems: begin_mmap failure ???");
+ return err;
+ }
+
+ for (chn = 0; chn < nchns; chn++) {
+ const snd_pcm_channel_area_t *a = &mm_areas[chn];
+ addr[chn] = (char *) a->addr + ((a->first + a->step * *offset) / 8);
+ }
+
+ return err;
+ }
+
+ return -1;
+}
+
+
+static int alsamm_start()
+{
+ int err = 0;
+ int devno;
+ int chn,nchns;
+
+ const snd_pcm_channel_area_t *mm_areas;
+
+#ifdef ALSAMM_DEBUG
+ if(sys_verbose)
+ post("start audio with %d out cards and %d incards",alsamm_outcards,alsamm_incards);
+#endif
+
+ /* first prepare for in/out */
+ for(devno = 0;devno < alsa_noutdev;devno++){
+
+ snd_pcm_uframes_t offset, avail;
+ t_alsa_dev *dev = &alsa_outdev[devno];
+
+ /* snd_pcm_prepare also in xrun, but cannot harm here */
+ if ((err = snd_pcm_prepare (dev->a_handle)) < 0) {
+ check_error (err,"outcard prepare error for playback");
+ return err;
+ }
+
+ offset = 0;
+ avail = snd_pcm_avail_update(dev->a_handle);
+
+ if (avail != (snd_pcm_uframes_t) alsamm_buffer_size) {
+ check_error (avail,"full buffer not available at start");
+ }
+
+ /* cleaning out mmap buffer before start */
+
+#ifdef ALSAMM_DEBUG
+ if(sys_verbose)
+ post("start: set mems for avail=%d,offset=%d at buffersize=%d",
+ avail,offset,alsamm_buffer_size);
+#endif
+
+ if(avail > 0){
+
+ int comitted = 0;
+
+ if ((err = alsamm_get_channels(dev->a_handle, &avail, &offset,
+ dev->a_channels,dev->a_addr)) < 0) {
+ check_error(err,"setting initial out channelspointer failure ?");
+ continue;
+ }
+
+ for (chn = 0; chn < dev->a_channels; chn++)
+ memset(dev->a_addr[chn],0,avail*ALSAMM_SAMPLEWIDTH_32);
+
+ comitted = snd_pcm_mmap_commit (dev->a_handle, offset, avail);
+
+ avail = snd_pcm_avail_update(dev->a_handle);
+
+#ifdef ALSAMM_DEBUG
+ if(sys_verbose)
+ post("start: now channels cleared, out with avail=%d, offset=%d,comitted=%d",
+ avail,offset,comitted);
+#endif
+ }
+ /* now start, should be autostarted */
+ avail = snd_pcm_avail_update(dev->a_handle);
+
+#ifdef ALSAMM_DEBUG
+ if(sys_verbose)
+ post("start: finish start, out with avail=%d, offset=%d",avail,offset);
+#endif
+
+ /* we have no autostart so anyway start*/
+ if ((err = snd_pcm_start (dev->a_handle)) < 0) {
+ check_error (err,"could not start playback");
+ }
+ }
+
+ for(devno = 0;devno < alsa_nindev;devno++){
+
+ snd_pcm_uframes_t ioffset, iavail;
+ t_alsa_dev *dev = &alsa_indev[devno];
+
+ /* if devices are synced then dont need to prepare
+ hopefully dma in aereas allready filled correct by the card */
+
+ if(dev->a_synced == 0){
+ if ((err = snd_pcm_prepare (dev->a_handle)) < 0) {
+ check_error (err,"incard prepare error for capture");
+ /* return err;*/
+ }
+ }
+
+ ioffset = 0;
+ iavail = snd_pcm_avail_update (dev->a_handle);
+
+ /* cleaning out mmap buffer before start */
+#ifdef ALSAMM_DEBUG
+ post("start in: set in mems for avail=%d,offset=%d at buffersize=%d",
+ iavail,ioffset,alsamm_buffer_size);
+#endif
+
+ if (iavail > (snd_pcm_uframes_t) 0) {
+
+#ifdef ALSAMM_DEBUG
+ post("empty buffer not available at start, since avail %d != %d buffersize",
+ iavail, alsamm_buffer_size);
+#endif
+
+ if ((err = alsamm_get_channels(dev->a_handle, &iavail, &ioffset,
+ dev->a_channels,dev->a_addr)) < 0) {
+ check_error(err,"getting in channelspointer failure ????");
+ continue;
+ }
+
+ snd_pcm_mmap_commit (dev->a_handle, ioffset, iavail);
+
+ iavail = snd_pcm_avail_update (dev->a_handle);
+#ifdef ALSAMM_DEBUG
+ post("start in now avail=%d",iavail);
+#endif
+ }
+
+#ifdef ALSAMM_DEBUG
+ post("start: init inchannels with avail=%d, offset=%d",iavail,ioffset);
+#endif
+
+ /* if devices are synced then dont need to start */
+ /* start with autostart , but anyway start */
+ if(dev->a_synced == 0){
+ if ((err = snd_pcm_start (dev->a_handle)) < 0) {
+ check_error (err,"could not start capture");
+ continue;
+ }
+ }
+
+ }
+
+ return err;
+}
+
+static int alsamm_stop()
+{
+ int err = 0;
+ int devno;
+
+ /* first stop in... */
+ for(devno = 0;devno < alsa_nindev;devno++){
+
+ t_alsa_dev *dev = &alsa_indev[devno];
+
+ if(sys_verbose)
+ post("stop in device %d",devno);
+
+ if ((err = snd_pcm_drop(dev->a_handle)) < 0) {
+ check_error (err,"channel flush for capture failed");
+ }
+
+ }
+
+ /* then outs */
+ for(devno = 0;devno < alsa_noutdev;devno++){
+
+
+ t_alsa_dev *dev = &alsa_outdev[devno];
+ if(sys_verbose)
+ post("stop out device %d",devno);
+
+ if ((err = snd_pcm_drop(dev->a_handle)) < 0) {
+ check_error (err,"channel flush for playback failed");
+ }
+
+ }
+
+#ifdef ALSAMM_DEBUG
+ show_availist();
+#endif
+
+ return err;
+}
+
+
+
+/* ---------- ADC/DAC tranfer in the main loop ------- */
+
+/* I see: (a guess as a documentation)
+
+ all DAC data is in sys_soundout array with
+ DEFDACBLKSIZE (mostly 64) for each channels which
+ if we have more channels opened then dac-channels = sys_outchannels
+ we have to zero (silence them), which should be done once.
+
+Problems to solve:
+
+ a) Since in ALSA MMAP, the MMAP reagion can change (dont ask me why)
+ we have to do it each cycle or we say on RME HAMMERFALL/HDSP/DSPMADI
+ it never changes to it once. so maybe we can do it once in open
+
+ b) we never know if inputs are synced and zero them if not,
+ except we use the control interface to check for, but this is
+ a systemcall we cannot afford in RT Loops so we just dont
+ and if not it will click... users fault ;-)))
+
+*/
+
+int alsamm_send_dacs(void)
+{
+
+ static double timenow,timelast;
+
+ t_sample *fpo, *fpi, *fp1, *fp2;
+ int i, err, devno;
+
+ const snd_pcm_channel_area_t *my_areas;
+ snd_pcm_sframes_t size;
+ snd_pcm_sframes_t commitres;
+ snd_pcm_state_t state;
+ snd_pcm_sframes_t ooffset, oavail;
+ snd_pcm_sframes_t ioffset, iavail;
+
+ /*
+ unused channels should be zeroed out on startup (open) and stay this
+ */
+ int inchannels = sys_inchannels;
+ int outchannels = sys_outchannels;
+
+ timelast = sys_getrealtime();
+
+#ifdef ALSAMM_DEBUG
+ if(dac_send++ < 0)
+ post("dac send called in %d, out %d, xrun %d",inchannels,outchannels, alsamm_xruns);
+
+ if(alsamm_xruns && (alsamm_xruns % 1000) == 0)
+ post("1000 xruns accoured");
+
+ if(dac_send < WATCH_PERIODS){
+ out_cm[dac_send] = -1;
+ in_avail[dac_send] = out_avail[dac_send] = -1;
+ in_offset[dac_send] = out_offset[dac_send] = -1;
+ outaddr[dac_send] = inaddr[dac_send] = NULL;
+ xruns_watch[dac_send] = alsamm_xruns;
+ }
+#endif
+
+ if (!inchannels && !outchannels)
+ {
+ return SENDDACS_NO;
+ }
+
+ /* here we should check if in and out samples are here.
+ but, the point is if out samples available also in sample should,
+ so we dont make a precheck of insamples here and let outsample check be the
+ the first of the forst card.
+ */
+
+
+ /* OUTPUT Transfer */
+ fpo = sys_soundout;
+ for(devno = 0;devno < alsa_noutdev;devno++){
+
+ t_alsa_dev *dev = &alsa_outdev[devno];
+ snd_pcm_t *out = dev->a_handle;
+ int ochannels =dev->a_channels;
+
+
+
+ /* how much samples available ??? */
+ oavail = snd_pcm_avail_update(out);
+
+ /* only one reason i can think about,
+ the driver stopped and says broken pipe
+ so this should not happen if we have enough stopthreshhold
+ but if try to restart with next commit
+ */
+ if (oavail < 0) {
+
+#ifdef ALSAMM_DEBUG
+ broken_opipe++;
+#endif
+ err = xrun_recovery(out, -EPIPE);
+ if (err < 0) {
+ check_error(err,"otavail<0 recovery failed");
+ return SENDDACS_NO;
+ }
+ oavail = snd_pcm_avail_update(out);
+ }
+
+ /* check if we are late and have to (able to) catch up */
+ /* xruns will be ignored since you cant do anything since already happend */
+ state = snd_pcm_state(out);
+ if (state == SND_PCM_STATE_XRUN) {
+ err = xrun_recovery(out, -EPIPE);
+ if (err < 0) {
+ check_error(err,"DAC XRUN recovery failed");
+ return SENDDACS_NO;
+ }
+ oavail = snd_pcm_avail_update(out);
+
+ } else if (state == SND_PCM_STATE_SUSPENDED) {
+ err = xrun_recovery(out, -ESTRPIPE);
+ if (err < 0) {
+ check_error(err,"DAC SUSPEND recovery failed");
+ return SENDDACS_NO;
+ }
+ oavail = snd_pcm_avail_update(out);
+ }
+
+#ifdef ALSAMM_DEBUG
+ if(dac_send < WATCH_PERIODS){
+ out_avail[dac_send] = oavail;
+ }
+#endif
+
+ /* we only transfer transfersize of bytes request,
+ this should only happen on first card otherwise we got a problem :-(()*/
+
+ if(oavail < alsamm_transfersize){
+ return SENDDACS_NO;
+ }
+
+ /* transfer now */
+ size = alsamm_transfersize;
+ fp1 = fpo;
+ ooffset = 0;
+
+ /* since this can go over a buffer boundery we maybe need two steps to
+ transfer (normally when buffersize is a multiple of transfersize
+ this should never happen) */
+
+ while (size > 0) {
+
+ int chn;
+ snd_pcm_sframes_t oframes;
+
+ oframes = size;
+
+ err = alsamm_get_channels(out, &oframes, &ooffset,ochannels,dev->a_addr);
+
+#ifdef ALSAMM_DEBUG
+ if(dac_send < WATCH_PERIODS){
+ out_offset[dac_send] = ooffset;
+ outaddr[dac_send] = (char *) dev->a_addr[0];
+ }
+#endif
+
+ if (err < 0){
+ if ((err = xrun_recovery(out, err)) < 0) {
+ check_error(err,"MMAP begins avail error");
+ break; /* next card please */
+ }
+ }
+
+ /* transfer into memory */
+ for (chn = 0; chn < ochannels; chn++) {
+
+ t_alsa_sample32 *buf = (t_alsa_sample32 *)dev->a_addr[chn];
+
+ /*
+ osc(buf, oframes, (dac_send%1000 < 500)?-100.0:-10.0,440,&(indexes[chn]));
+ */
+
+ for (i = 0, fp2 = fp1 + chn*alsamm_transfersize; i < oframes; i++,fp2++)
+ {
+ float s1 = *fp2 * F32MAX;
+ /* better but slower, better never clip ;-)
+ buf[i]= CLIP32(s1); */
+ buf[i]= ((int) s1 & 0xFFFFFF00);
+ *fp2 = 0.0;
+ }
+ }
+
+ commitres = snd_pcm_mmap_commit(out, ooffset, oframes);
+ if (commitres < 0 || commitres != oframes) {
+ if ((err = xrun_recovery(out, commitres >= 0 ? -EPIPE : commitres)) < 0) {
+ check_error(err,"MMAP commit error");
+ return SENDDACS_NO;
+ }
+ }
+
+#ifdef ALSAMM_DEBUG
+ if(dac_send < WATCH_PERIODS)
+ out_cm[dac_send] = oframes;
+#endif
+
+ fp1 += oframes;
+ size -= oframes;
+ } /* while size */
+ fpo += ochannels*alsamm_transfersize;
+
+ }/* for devno */
+
+
+ fpi = sys_soundin; /* star first card first channel */
+
+ for(devno = 0;devno < alsa_nindev;devno++){
+
+ t_alsa_dev *dev = &alsa_indev[devno];
+ snd_pcm_t *in = dev->a_handle;
+ int ichannels = dev->a_channels;
+
+ iavail = snd_pcm_avail_update(in);
+
+ if (iavail < 0) {
+ err = xrun_recovery(in, iavail);
+ if (err < 0) {
+ check_error(err,"input avail update failed");
+ return SENDDACS_NO;
+ }
+ iavail=snd_pcm_avail_update(in);
+ }
+
+ state = snd_pcm_state(in);
+
+ if (state == SND_PCM_STATE_XRUN) {
+ err = xrun_recovery(in, -EPIPE);
+ if (err < 0) {
+ check_error(err,"ADC XRUN recovery failed");
+ return SENDDACS_NO;
+ }
+ iavail=snd_pcm_avail_update(in);
+
+ } else if (state == SND_PCM_STATE_SUSPENDED) {
+ err = xrun_recovery(in, -ESTRPIPE);
+ if (err < 0) {
+ check_error(err,"ADC SUSPEND recovery failed");
+ return SENDDACS_NO;
+ }
+ iavail=snd_pcm_avail_update(in);
+ }
+
+ /* only transfer full transfersize or nothing */
+ if(iavail < alsamm_transfersize){
+ return SENDDACS_NO;
+ }
+ size = alsamm_transfersize;
+ fp1 = fpi;
+ ioffset = 0;
+
+ /* since sysdata can go over a driver buffer boundery we maybe need two steps to
+ transfer (normally when buffersize is a multiple of transfersize
+ this should never happen) */
+
+ while(size > 0){
+ int chn;
+ snd_pcm_sframes_t iframes = size;
+
+ err = alsamm_get_channels(in, &iframes, &ioffset,ichannels,dev->a_addr);
+ if (err < 0){
+ if ((err = xrun_recovery(in, err)) < 0) {
+ check_error(err,"MMAP begins avail error");
+ return SENDDACS_NO;
+ }
+ }
+
+#ifdef ALSAMM_DEBUG
+ if(dac_send < WATCH_PERIODS){
+ in_avail[dac_send] = iavail;
+ in_offset[dac_send] = ioffset;
+ inaddr[dac_send] = dev->a_addr[0];
+ }
+#endif
+ /* transfer into memory */
+
+ for (chn = 0; chn < ichannels; chn++) {
+
+ t_alsa_sample32 *buf = (t_alsa_sample32 *) dev->a_addr[chn];
+
+ for (i = 0, fp2 = fp1 + chn*alsamm_transfersize; i < iframes; i++,fp2++)
+ {
+ /* mask the lowest bits, since subchannels info can make zero samples nonzero */
+ *fp2 = (float) ((t_alsa_sample32) (buf[i] & 0xFFFFFF00))
+ * (1.0 / (float) INT32_MAX);
+ }
+ }
+
+ commitres = snd_pcm_mmap_commit(in, ioffset, iframes);
+ if (commitres < 0 || commitres != iframes) {
+ post("please never");
+ if ((err = xrun_recovery(in, commitres >= 0 ? -EPIPE : commitres)) < 0) {
+ check_error(err,"MMAP synced in commit error");
+ return SENDDACS_NO;
+ }
+ }
+ fp1 += iframes;
+ size -= iframes;
+ }
+ fpi += ichannels*alsamm_transfersize;
+ } /* for out devno < alsamm_outcards*/
+
+
+ if ((timenow = sys_getrealtime()) > (timelast + sleep_time))
+ {
+
+#ifdef ALSAMM_DEBUG
+ if(dac_send < 10 && sys_verbose)
+ post("slept %f > %f + %f (=%f)",
+ timenow,timelast,sleep_time,(timelast + sleep_time));
+#endif
+ return (SENDDACS_SLEPT);
+ }
+
+ return SENDDACS_YES;
+}
+
+
+/* extra debug info */
+
+void alsamm_showstat(snd_pcm_t *handle)
+{
+ int err;
+ snd_pcm_status_t *status;
+ snd_output_t *output = NULL;
+
+ snd_pcm_status_alloca(&status);
+ if ((err = snd_pcm_status(handle, status)) < 0) {
+ check_error(err, "Get Stream status error");
+ return;
+ }
+ snd_pcm_status_dump(status, alsa_stdout);
+}
diff --git a/pd/src/s_audio_jack.c b/pd/src/s_audio_jack.c
index 1e79b43b..7ab3a3f6 100644
--- a/pd/src/s_audio_jack.c
+++ b/pd/src/s_audio_jack.c
@@ -28,6 +28,8 @@ static jack_port_t *output_port[NUM_JACK_PORTS];
static int outport_count = 0;
static jack_client_t *jack_client = NULL;
char *jack_client_names[MAX_CLIENTS];
+static int jack_dio_error;
+
pthread_mutex_t jack_mutex;
pthread_cond_t jack_sem;
@@ -36,42 +38,42 @@ pthread_cond_t jack_sem;
static int
process (jack_nframes_t nframes, void *arg)
{
- int j;
- float *out;
- float *in;
-
-
+ int j;
+ float *out;
+ float *in;
+
+
if (nframes > JACK_OUT_MAX) jack_out_max = nframes;
- else jack_out_max = JACK_OUT_MAX;
- if (jack_filled >= nframes) {
- if (jack_filled != nframes) fprintf(stderr,"Partial read");
-
- for (j = 0; j < sys_outchannels; j++) {
- out = jack_port_get_buffer (output_port[j], nframes);
- memcpy(out, jack_outbuf + (j * BUF_JACK), sizeof (float) * nframes);
- }
- for (j = 0; j < sys_inchannels; j++) {
- in = jack_port_get_buffer( input_port[j], nframes);
- memcpy(jack_inbuf + (j * BUF_JACK), in, sizeof (float) * nframes);
- }
- jack_filled -= nframes;
- } else { /* PD could not keep up ! */
- if (jack_started) sys_log_error(ERR_RESYNC);
- for (j = 0; j < outport_count; j++) {
- out = jack_port_get_buffer (output_port[j], nframes);
- memset(out, 0, sizeof (float) * nframes);
- }
- memset(jack_outbuf,0,sizeof(jack_outbuf));
- jack_filled = 0;
- }
- pthread_cond_broadcast(&jack_sem);
- return 0;
+ else jack_out_max = JACK_OUT_MAX;
+ if (jack_filled >= nframes) {
+ if (jack_filled != nframes) fprintf(stderr,"Partial read");
+
+ for (j = 0; j < sys_outchannels; j++) {
+ out = jack_port_get_buffer (output_port[j], nframes);
+ memcpy(out, jack_outbuf + (j * BUF_JACK), sizeof (float) * nframes);
+ }
+ for (j = 0; j < sys_inchannels; j++) {
+ in = jack_port_get_buffer( input_port[j], nframes);
+ memcpy(jack_inbuf + (j * BUF_JACK), in, sizeof (float) * nframes);
+ }
+ jack_filled -= nframes;
+ } else { /* PD could not keep up ! */
+ if (jack_started) jack_dio_error = 1;
+ for (j = 0; j < outport_count; j++) {
+ out = jack_port_get_buffer (output_port[j], nframes);
+ memset(out, 0, sizeof (float) * nframes);
+ }
+ memset(jack_outbuf,0,sizeof(jack_outbuf));
+ jack_filled = 0;
+ }
+ pthread_cond_broadcast(&jack_sem);
+ return 0;
}
static int
jack_srate (jack_nframes_t srate, void *arg)
{
- sys_dacsr = srate;
+ sys_dacsr = srate;
return 0;
}
@@ -79,11 +81,11 @@ static void
jack_shutdown (void *arg)
{
/* Ignore for now */
- // exit (1);
+ // exit (1);
}
static int jack_xrun(void* arg) {
- sys_log_error(ERR_DACSLEPT);
+ jack_dio_error = 1;
return 0;
}
@@ -131,19 +133,19 @@ static char** jack_get_clients(void)
if( strcmp( "alsa_pcm", tmp_client_name ) == 0 && num_clients > 0 )
{
- char* tmp;
+ char* tmp;
/* alsa_pcm goes in spot 0 */
- tmp = jack_client_names[ num_clients ];
- jack_client_names[ num_clients ] = jack_client_names[0];
- jack_client_names[0] = tmp;
- strcpy( jack_client_names[0], tmp_client_name);
+ tmp = jack_client_names[ num_clients ];
+ jack_client_names[ num_clients ] = jack_client_names[0];
+ jack_client_names[0] = tmp;
+ strcpy( jack_client_names[0], tmp_client_name);
}
else
{
/* put the new client at the end of the client list */
strcpy( jack_client_names[ num_clients ], tmp_client_name );
}
- num_clients++;
+ num_clients++;
}
}
@@ -170,20 +172,20 @@ static int jack_connect_ports(char* client)
sprintf( regex_pattern, "%s:.*", client );
jack_ports = jack_get_ports( jack_client, regex_pattern,
- NULL, JackPortIsOutput);
+ NULL, JackPortIsOutput);
if (jack_ports)
for (i=0;jack_ports[i] != NULL && i < sys_inchannels;i++)
if (jack_connect (jack_client, jack_ports[i], jack_port_name (input_port[i])))
- fprintf (stderr, "cannot connect input ports %s -> %s\n", jack_ports[i],jack_port_name (input_port[i]));
+ fprintf (stderr, "cannot connect input ports %s -> %s\n", jack_ports[i],jack_port_name (input_port[i]));
jack_ports = jack_get_ports( jack_client, regex_pattern,
- NULL, JackPortIsInput);
+ NULL, JackPortIsInput);
if (jack_ports)
for (i=0;jack_ports[i] != NULL && i < sys_outchannels;i++)
if (jack_connect (jack_client, jack_port_name (output_port[i]), jack_ports[i]))
- fprintf (stderr, "cannot connect output ports %s -> %s\n", jack_port_name (output_port[i]),jack_ports[i]);
+ fprintf (stderr, "cannot connect output ports %s -> %s\n", jack_port_name (output_port[i]),jack_ports[i]);
@@ -201,168 +203,176 @@ int
jack_open_audio(int inchans, int outchans, int rate)
{
- int j;
- char port_name[80] = "";
- int client_iterator = 0;
- int new_jack = 0;
- int srate;
-
- if ((inchans == 0) && (outchans == 0)) return 0;
-
- if (outchans > NUM_JACK_PORTS) {
- fprintf(stderr,"%d output ports not supported, setting to %d\n",outchans, NUM_JACK_PORTS);
- outchans = NUM_JACK_PORTS;
- }
+ int j;
+ char port_name[80] = "";
+ int client_iterator = 0;
+ int new_jack = 0;
+ int srate;
+
+ jack_dio_error = 0;
+
+ if ((inchans == 0) && (outchans == 0)) return 0;
+
+ if (outchans > NUM_JACK_PORTS) {
+ fprintf(stderr,"%d output ports not supported, setting to %d\n",outchans, NUM_JACK_PORTS);
+ outchans = NUM_JACK_PORTS;
+ }
- if (inchans > NUM_JACK_PORTS) {
+ if (inchans > NUM_JACK_PORTS) {
fprintf(stderr,"%d input ports not supported, setting to %d\n",inchans, NUM_JACK_PORTS);
inchans = NUM_JACK_PORTS;
}
- /* try to become a client of the JACK server (we allow two pd's)*/
- if (!jack_client) {
- do {
- sprintf(port_name,"pure_data_%d",client_iterator);
- client_iterator++;
- } while (((jack_client = jack_client_new (port_name)) == 0) && client_iterator < 2);
-
-
- if (!jack_client) { // jack spits out enough messages already, do not warn
- return 1;
- }
-
- jack_get_clients();
-
- /* tell the JACK server to call `process()' whenever
- there is work to be done.
- */
-
- jack_set_process_callback (jack_client, process, 0);
-
- jack_set_error_function (jack_error);
-
+ /* try to become a client of the JACK server (we allow two pd's)*/
+ if (!jack_client) {
+ do {
+ sprintf(port_name,"pure_data_%d",client_iterator);
+ client_iterator++;
+ } while (((jack_client = jack_client_new (port_name)) == 0) && client_iterator < 2);
+
+
+ if (!jack_client) { // jack spits out enough messages already, do not warn
+ sys_inchannels = sys_outchannels = 0;
+ return 1;
+ }
+
+ jack_get_clients();
+
+ /* tell the JACK server to call `process()' whenever
+ there is work to be done.
+ */
+
+ jack_set_process_callback (jack_client, process, 0);
+
+ jack_set_error_function (jack_error);
+
#ifdef JACK_XRUN
- jack_set_xrun_callback (jack_client, jack_xrun, NULL);
+ jack_set_xrun_callback (jack_client, jack_xrun, NULL);
#endif
-
- /* tell the JACK server to call `srate()' whenever
- the sample rate of the system changes.
- */
-
- jack_set_sample_rate_callback (jack_client, jack_srate, 0);
-
-
- /* tell the JACK server to call `jack_shutdown()' if
- it ever shuts down, either entirely, or if it
- just decides to stop calling us.
- */
-
- jack_on_shutdown (jack_client, jack_shutdown, 0);
-
- for (j=0;j<NUM_JACK_PORTS;j++) {
- input_port[j]=NULL;
- output_port[j] = NULL;
- }
-
- new_jack = 1;
- }
-
- /* display the current sample rate. once the client is activated
- (see below), you should rely on your own sample rate
- callback (see above) for this value.
- */
-
- srate = jack_get_sample_rate (jack_client);
- sys_dacsr = srate;
-
- /* create the ports */
-
- for (j = 0; j < inchans; j++) {
- sprintf(port_name, "input%d", j);
- if (!input_port[j]) input_port[j] = jack_port_register (jack_client, port_name, JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0);
- }
+
+ /* tell the JACK server to call `srate()' whenever
+ the sample rate of the system changes.
+ */
+
+ jack_set_sample_rate_callback (jack_client, jack_srate, 0);
+
+
+ /* tell the JACK server to call `jack_shutdown()' if
+ it ever shuts down, either entirely, or if it
+ just decides to stop calling us.
+ */
+
+ jack_on_shutdown (jack_client, jack_shutdown, 0);
+
+ for (j=0;j<NUM_JACK_PORTS;j++) {
+ input_port[j]=NULL;
+ output_port[j] = NULL;
+ }
+
+ new_jack = 1;
+ }
+
+ /* display the current sample rate. once the client is activated
+ (see below), you should rely on your own sample rate
+ callback (see above) for this value.
+ */
+
+ srate = jack_get_sample_rate (jack_client);
+ sys_dacsr = srate;
+
+ /* create the ports */
+
+ for (j = 0; j < inchans; j++) {
+ sprintf(port_name, "input%d", j);
+ if (!input_port[j]) input_port[j] = jack_port_register (jack_client, port_name, JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0);
+ }
for (j = 0; j < outchans; j++) {
- sprintf(port_name, "output%d", j);
- if (!output_port[j]) output_port[j] = jack_port_register (jack_client, port_name, JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0);
- }
- outport_count = outchans;
+ sprintf(port_name, "output%d", j);
+ if (!output_port[j]) output_port[j] = jack_port_register (jack_client, port_name, JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0);
+ }
+ outport_count = outchans;
/* tell the JACK server that we are ready to roll */
- if (new_jack) {
- if (jack_activate (jack_client)) {
- fprintf (stderr, "cannot activate client");
- return 1;
- }
-
- memset(jack_outbuf,0,sizeof(jack_outbuf));
-
- if (jack_client_names[0])
- jack_connect_ports(jack_client_names[0]);
-
- pthread_mutex_init(&jack_mutex,NULL);
- pthread_cond_init(&jack_sem,NULL);
- }
- return 0;
+ if (new_jack) {
+ if (jack_activate (jack_client)) {
+ fprintf (stderr, "cannot activate client\n");
+ sys_inchannels = sys_outchannels = 0;
+ return 1;
+ }
+
+ memset(jack_outbuf,0,sizeof(jack_outbuf));
+
+ if (jack_client_names[0])
+ jack_connect_ports(jack_client_names[0]);
+
+ pthread_mutex_init(&jack_mutex,NULL);
+ pthread_cond_init(&jack_sem,NULL);
+ }
+ return 0;
}
void jack_close_audio(void)
{
- jack_started = 0;
+ jack_started = 0;
}
int jack_send_dacs(void)
{
- float * fp;
- int j;
- int rtnval = SENDDACS_YES;
- int timenow;
- int timeref = sys_getrealtime();
-
- if (!jack_client) return SENDDACS_NO;
-
- if (!sys_inchannels && !sys_outchannels) return (SENDDACS_NO);
-
- if (jack_filled >= jack_out_max)
- pthread_cond_wait(&jack_sem,&jack_mutex);
-
- jack_started = 1;
-
- fp = sys_soundout;
- for (j = 0; j < sys_outchannels; j++) {
- memcpy(jack_outbuf + (j * BUF_JACK) + jack_filled,fp, DEFDACBLKSIZE*sizeof(float));
- fp += DEFDACBLKSIZE;
- }
- fp = sys_soundin;
- for (j = 0; j < sys_inchannels; j++) {
- memcpy(fp, jack_inbuf + (j * BUF_JACK) + jack_filled, DEFDACBLKSIZE*sizeof(float));
- fp += DEFDACBLKSIZE;
- }
-
- if ((timenow = sys_getrealtime()) - timeref > 0.002)
- {
- rtnval = SENDDACS_SLEPT;
- }
-
- memset(sys_soundout,0,DEFDACBLKSIZE*sizeof(float)*sys_outchannels);
- jack_filled += DEFDACBLKSIZE;
- return rtnval;
+ float * fp;
+ int j;
+ int rtnval = SENDDACS_YES;
+ int timenow;
+ int timeref = sys_getrealtime();
+
+ if (!jack_client) return SENDDACS_NO;
+
+ if (!sys_inchannels && !sys_outchannels) return (SENDDACS_NO);
+
+ if (jack_dio_error) {
+ sys_log_error(ERR_RESYNC);
+ jack_dio_error = 0;
+ }
+ if (jack_filled >= jack_out_max)
+ pthread_cond_wait(&jack_sem,&jack_mutex);
+
+ jack_started = 1;
+
+ fp = sys_soundout;
+ for (j = 0; j < sys_outchannels; j++) {
+ memcpy(jack_outbuf + (j * BUF_JACK) + jack_filled,fp, DEFDACBLKSIZE*sizeof(float));
+ fp += DEFDACBLKSIZE;
+ }
+ fp = sys_soundin;
+ for (j = 0; j < sys_inchannels; j++) {
+ memcpy(fp, jack_inbuf + (j * BUF_JACK) + jack_filled, DEFDACBLKSIZE*sizeof(float));
+ fp += DEFDACBLKSIZE;
+ }
+
+ if ((timenow = sys_getrealtime()) - timeref > 0.002)
+ {
+ rtnval = SENDDACS_SLEPT;
+ }
+
+ memset(sys_soundout,0,DEFDACBLKSIZE*sizeof(float)*sys_outchannels);
+ jack_filled += DEFDACBLKSIZE;
+ return rtnval;
}
void jack_getdevs(char *indevlist, int *nindevs,
char *outdevlist, int *noutdevs, int *canmulti,
- int maxndev, int devdescsize)
+ int maxndev, int devdescsize)
{
int i, ndev;
*canmulti = 0; /* supports multiple devices */
ndev = 1;
for (i = 0; i < ndev; i++)
{
- sprintf(indevlist + i * devdescsize, "JACK");
- sprintf(outdevlist + i * devdescsize, "JACK");
+ sprintf(indevlist + i * devdescsize, "JACK");
+ sprintf(outdevlist + i * devdescsize, "JACK");
}
*nindevs = *noutdevs = ndev;
}
diff --git a/pd/src/s_audio_mmio.c b/pd/src/s_audio_mmio.c
index 03fcaf69..30aa4d1c 100644
--- a/pd/src/s_audio_mmio.c
+++ b/pd/src/s_audio_mmio.c
@@ -30,7 +30,7 @@ int nt_realdacblksize;
#define DEFREALDACBLKSIZE (4 * DEFDACBLKSIZE) /* larger underlying bufsize */
#define MAXBUFFER 100 /* number of buffers in use at maximum advance */
-#define DEFBUFFER 30 /* default is about 30x6 = 180 msec! */
+#define DEFBUFFER 30 /* default is about 30x6 = 180 msec! */
static int nt_naudiobuffer = DEFBUFFER;
float sys_dacsr = DEFAULTSRATE;
@@ -38,7 +38,7 @@ static int nt_whichapi = API_MMIO;
static int nt_meters; /* true if we're metering */
static float nt_inmax; /* max input amplitude */
static float nt_outmax; /* max output amplitude */
-static int nt_nwavein, nt_nwaveout; /* number of WAVE devices in and out */
+static int nt_nwavein, nt_nwaveout; /* number of WAVE devices in and out */
typedef struct _sbuf
{
@@ -49,12 +49,12 @@ typedef struct _sbuf
} t_sbuf;
t_sbuf ntsnd_outvec[NAPORTS][MAXBUFFER]; /* circular buffer array */
-HWAVEOUT ntsnd_outdev[NAPORTS]; /* output device */
-static int ntsnd_outphase[NAPORTS]; /* index of next buffer to send */
+HWAVEOUT ntsnd_outdev[NAPORTS]; /* output device */
+static int ntsnd_outphase[NAPORTS]; /* index of next buffer to send */
-t_sbuf ntsnd_invec[NAPORTS][MAXBUFFER]; /* circular buffer array */
-HWAVEIN ntsnd_indev[NAPORTS]; /* input device */
-static int ntsnd_inphase[NAPORTS]; /* index of next buffer to read */
+t_sbuf ntsnd_invec[NAPORTS][MAXBUFFER]; /* circular buffer array */
+HWAVEIN ntsnd_indev[NAPORTS]; /* input device */
+static int ntsnd_inphase[NAPORTS]; /* index of next buffer to read */
static void nt_waveinerror(char *s, int err)
{
@@ -70,7 +70,7 @@ static void nt_waveouterror(char *s, int err)
fprintf(stderr, s, t);
}
-static void wave_prep(t_sbuf *bp)
+static void wave_prep(t_sbuf *bp, int setdone)
{
WAVEHDR *wh;
short *sp;
@@ -82,27 +82,27 @@ static void wave_prep(t_sbuf *bp)
*/
if (!(bp->hData =
- GlobalAlloc(GMEM_MOVEABLE | GMEM_SHARE,
- (DWORD) (CHANNELS_PER_DEVICE * SAMPSIZE * nt_realdacblksize))))
- printf("alloc 1 failed\n");
+ GlobalAlloc(GMEM_MOVEABLE | GMEM_SHARE,
+ (DWORD) (CHANNELS_PER_DEVICE * SAMPSIZE * nt_realdacblksize))))
+ printf("alloc 1 failed\n");
if (!(bp->lpData =
- (HPSTR) GlobalLock(bp->hData)))
- printf("lock 1 failed\n");
+ (HPSTR) GlobalLock(bp->hData)))
+ printf("lock 1 failed\n");
/* Allocate and lock memory for the header. */
if (!(bp->hWaveHdr =
- GlobalAlloc(GMEM_MOVEABLE | GMEM_SHARE, (DWORD) sizeof(WAVEHDR))))
- printf("alloc 2 failed\n");
+ GlobalAlloc(GMEM_MOVEABLE | GMEM_SHARE, (DWORD) sizeof(WAVEHDR))))
+ printf("alloc 2 failed\n");
if (!(wh = bp->lpWaveHdr =
- (WAVEHDR *) GlobalLock(bp->hWaveHdr)))
- printf("lock 2 failed\n");
+ (WAVEHDR *) GlobalLock(bp->hWaveHdr)))
+ printf("lock 2 failed\n");
for (i = CHANNELS_PER_DEVICE * nt_realdacblksize,
- sp = (short *)bp->lpData; i--; )
- *sp++ = 0;
+ sp = (short *)bp->lpData; i--; )
+ *sp++ = 0;
wh->lpData = bp->lpData;
wh->dwBufferLength = (CHANNELS_PER_DEVICE * SAMPSIZE * nt_realdacblksize);
@@ -110,6 +110,9 @@ static void wave_prep(t_sbuf *bp)
wh->dwLoops = 0L;
wh->lpNext = 0;
wh->reserved = 0;
+ /* optionally (for writing) set DONE flag as if we had queued them */
+ if (setdone)
+ wh->dwFlags = WHDR_DONE;
}
static UINT nt_whichdac = WAVE_MAPPER, nt_whichadc = WAVE_MAPPER;
@@ -122,8 +125,8 @@ int mmio_do_open_audio(void)
int nad, nda;
static int naudioprepped = 0, nindevsprepped = 0, noutdevsprepped = 0;
if (sys_verbose)
- post("%d devices in, %d devices out",
- nt_nwavein, nt_nwaveout);
+ post("%d devices in, %d devices out",
+ nt_nwavein, nt_nwaveout);
form.wf.wFormatTag = WAVE_FORMAT_PCM;
form.wf.nChannels = CHANNELS_PER_DEVICE;
@@ -133,84 +136,84 @@ int mmio_do_open_audio(void)
form.wBitsPerSample = 8 * SAMPSIZE;
if (nt_nwavein <= 1 && nt_nwaveout <= 1)
- nt_noresync();
+ nt_noresync();
if (nindevsprepped < nt_nwavein)
{
- for (i = nindevsprepped; i < nt_nwavein; i++)
- for (j = 0; j < nt_naudiobuffer; j++)
- wave_prep(&ntsnd_invec[i][j]);
- nindevsprepped = nt_nwavein;
+ for (i = nindevsprepped; i < nt_nwavein; i++)
+ for (j = 0; j < naudioprepped; j++)
+ wave_prep(&ntsnd_invec[i][j], 0);
+ nindevsprepped = nt_nwavein;
}
if (noutdevsprepped < nt_nwaveout)
{
- for (i = noutdevsprepped; i < nt_nwaveout; i++)
- for (j = 0; j < nt_naudiobuffer; j++)
- wave_prep(&ntsnd_outvec[i][j]);
- noutdevsprepped = nt_nwaveout;
+ for (i = noutdevsprepped; i < nt_nwaveout; i++)
+ for (j = 0; j < naudioprepped; j++)
+ wave_prep(&ntsnd_outvec[i][j], 1);
+ noutdevsprepped = nt_nwaveout;
}
if (naudioprepped < nt_naudiobuffer)
{
- for (j = naudioprepped; j < nt_naudiobuffer; j++)
- {
- for (i = 0; i < nt_nwavein; i++)
- wave_prep(&ntsnd_invec[i][j]);
- for (i = 0; i < nt_nwaveout; i++)
- wave_prep(&ntsnd_outvec[i][j]);
- }
- naudioprepped = nt_naudiobuffer;
+ for (j = naudioprepped; j < nt_naudiobuffer; j++)
+ {
+ for (i = 0; i < nt_nwavein; i++)
+ wave_prep(&ntsnd_invec[i][j], 0);
+ for (i = 0; i < nt_nwaveout; i++)
+ wave_prep(&ntsnd_outvec[i][j], 1);
+ }
+ naudioprepped = nt_naudiobuffer;
}
for (nad=0; nad < nt_nwavein; nad++)
{
- /* Open waveform device(s), sucessively numbered, for input */
-
- mmresult = waveInOpen(&ntsnd_indev[nad], nt_whichadc+nad,
- (WAVEFORMATEX *)(&form), 0L, 0L, CALLBACK_NULL);
-
- if (sys_verbose)
- printf("opened adc device %d with return %d\n",
- nt_whichadc+nad,mmresult);
-
- if (mmresult != MMSYSERR_NOERROR)
- {
- nt_waveinerror("waveInOpen: %s\n", mmresult);
- nt_nwavein = nad; /* nt_nwavein = 0 wini */
- }
- else
- {
- for (i = 0; i < nt_naudiobuffer; i++)
- {
- mmresult = waveInPrepareHeader(ntsnd_indev[nad],
- ntsnd_invec[nad][i].lpWaveHdr, sizeof(WAVEHDR));
- if (mmresult != MMSYSERR_NOERROR)
- nt_waveinerror("waveinprepareheader: %s\n", mmresult);
- mmresult = waveInAddBuffer(ntsnd_indev[nad],
- ntsnd_invec[nad][i].lpWaveHdr, sizeof(WAVEHDR));
- if (mmresult != MMSYSERR_NOERROR)
- nt_waveinerror("waveInAddBuffer: %s\n", mmresult);
- }
- }
+ /* Open waveform device(s), sucessively numbered, for input */
+
+ mmresult = waveInOpen(&ntsnd_indev[nad], nt_whichadc+nad,
+ (WAVEFORMATEX *)(&form), 0L, 0L, CALLBACK_NULL);
+
+ if (sys_verbose)
+ printf("opened adc device %d with return %d\n",
+ nt_whichadc+nad,mmresult);
+
+ if (mmresult != MMSYSERR_NOERROR)
+ {
+ nt_waveinerror("waveInOpen: %s\n", mmresult);
+ nt_nwavein = nad; /* nt_nwavein = 0 wini */
+ }
+ else
+ {
+ for (i = 0; i < nt_naudiobuffer; i++)
+ {
+ mmresult = waveInPrepareHeader(ntsnd_indev[nad],
+ ntsnd_invec[nad][i].lpWaveHdr, sizeof(WAVEHDR));
+ if (mmresult != MMSYSERR_NOERROR)
+ nt_waveinerror("waveinprepareheader: %s\n", mmresult);
+ mmresult = waveInAddBuffer(ntsnd_indev[nad],
+ ntsnd_invec[nad][i].lpWaveHdr, sizeof(WAVEHDR));
+ if (mmresult != MMSYSERR_NOERROR)
+ nt_waveinerror("waveInAddBuffer: %s\n", mmresult);
+ }
+ }
}
- /* quickly start them all together */
+ /* quickly start them all together */
for (nad = 0; nad < nt_nwavein; nad++)
- waveInStart(ntsnd_indev[nad]);
+ waveInStart(ntsnd_indev[nad]);
for (nda = 0; nda < nt_nwaveout; nda++)
- {
- /* Open a waveform device for output in sucessiv device numbering*/
- mmresult = waveOutOpen(&ntsnd_outdev[nda], nt_whichdac + nda,
- (WAVEFORMATEX *)(&form), 0L, 0L, CALLBACK_NULL);
-
- if (sys_verbose)
- fprintf(stderr,"opened dac device %d, with return %d\n",
- nt_whichdac +nda, mmresult);
-
- if (mmresult != MMSYSERR_NOERROR)
- {
- fprintf(stderr,"Wave out open device %d + %d\n",nt_whichdac,nda);
+ {
+ /* Open a waveform device for output in sucessiv device numbering*/
+ mmresult = waveOutOpen(&ntsnd_outdev[nda], nt_whichdac + nda,
+ (WAVEFORMATEX *)(&form), 0L, 0L, CALLBACK_NULL);
+
+ if (sys_verbose)
+ fprintf(stderr,"opened dac device %d, with return %d\n",
+ nt_whichdac +nda, mmresult);
+
+ if (mmresult != MMSYSERR_NOERROR)
+ {
+ fprintf(stderr,"Wave out open device %d + %d\n",nt_whichdac,nda);
nt_waveouterror("waveOutOpen device: %s\n", mmresult);
nt_nwaveout = nda;
- }
+ }
}
return (0);
@@ -221,33 +224,33 @@ void mmio_close_audio( void)
int errcode;
int nda, nad;
if (sys_verbose)
- post("closing audio...");
+ post("closing audio...");
for (nda=0; nda < nt_nwaveout; nda++) /*if (nt_nwaveout) wini */
{
errcode = waveOutReset(ntsnd_outdev[nda]);
if (errcode != MMSYSERR_NOERROR)
- printf("error resetting output %d: %d\n", nda, errcode);
+ printf("error resetting output %d: %d\n", nda, errcode);
errcode = waveOutClose(ntsnd_outdev[nda]);
if (errcode != MMSYSERR_NOERROR)
- printf("error closing output %d: %d\n",nda , errcode);
+ printf("error closing output %d: %d\n",nda , errcode);
}
nt_nwaveout = 0;
for(nad=0; nad < nt_nwavein;nad++) /* if (nt_nwavein) wini */
{
- errcode = waveInReset(ntsnd_indev[nad]);
- if (errcode != MMSYSERR_NOERROR)
- printf("error resetting input: %d\n", errcode);
- errcode = waveInClose(ntsnd_indev[nad]);
- if (errcode != MMSYSERR_NOERROR)
- printf("error closing input: %d\n", errcode);
+ errcode = waveInReset(ntsnd_indev[nad]);
+ if (errcode != MMSYSERR_NOERROR)
+ printf("error resetting input: %d\n", errcode);
+ errcode = waveInClose(ntsnd_indev[nad]);
+ if (errcode != MMSYSERR_NOERROR)
+ printf("error closing input: %d\n", errcode);
}
nt_nwavein = 0;
}
-#define ADCJITTER 10 /* We tolerate X buffers of jitter by default */
+#define ADCJITTER 10 /* We tolerate X buffers of jitter by default */
#define DACJITTER 10
static int nt_adcjitterbufsallowed = ADCJITTER;
@@ -277,25 +280,25 @@ static void nt_midisync(void)
if (initsystime == -1) nt_resetmidisync();
jittersec = (nt_dacjitterbufsallowed > nt_adcjitterbufsallowed ?
- nt_dacjitterbufsallowed : nt_adcjitterbufsallowed)
- * nt_realdacblksize / sys_getsr();
+ nt_dacjitterbufsallowed : nt_adcjitterbufsallowed)
+ * nt_realdacblksize / sys_getsr();
diff = sys_getrealtime() - 0.001 * clock_gettimesince(initsystime);
if (diff > nt_hibuftime) nt_hibuftime = diff;
if (diff < nt_hibuftime - jittersec)
{
- post("jitter excess %d %f", dac, diff);
- nt_resetmidisync();
+ post("jitter excess %d %f", dac, diff);
+ nt_resetmidisync();
}
}
static double nt_midigettimefor(LARGE_INTEGER timestamp)
{
/* this is broken now... used to work when "timestamp" was derived from
- QueryPerformanceCounter() instead of the gates approved
- timeGetSystemTime() call in the MIDI callback routine below. */
+ QueryPerformanceCounter() instead of the gates approved
+ timeGetSystemTime() call in the MIDI callback routine below. */
return (nt_tixtotime(timestamp) - nt_hibuftime);
}
-#endif /* MIDI_TIMESTAMP */
+#endif /* MIDI_TIMESTAMP */
static int nt_fill = 0;
@@ -303,87 +306,87 @@ static int nt_fill = 0;
#define WRAPBACK(x) ((x) < 0 ? (x) + nt_naudiobuffer: (x))
#define MAXRESYNC 500
-#if 0 /* this is used for debugging */
+#if 0 /* this is used for debugging */
static void nt_printaudiostatus(void)
{
int nad, nda;
for (nad = 0; nad < nt_nwavein; nad++)
{
- int phase = ntsnd_inphase[nad];
- int phase2 = phase, phase3 = WRAPFWD(phase2), count, ntrans = 0;
- int firstphasedone = -1, firstphasebusy = -1;
- for (count = 0; count < nt_naudiobuffer; count++)
- {
- int donethis =
- (ntsnd_invec[nad][phase2].lpWaveHdr->dwFlags & WHDR_DONE);
- int donenext =
- (ntsnd_invec[nad][phase3].lpWaveHdr->dwFlags & WHDR_DONE);
- if (donethis && !donenext)
- {
- if (firstphasebusy >= 0) goto multipleadc;
- firstphasebusy = count;
- }
- if (!donethis && donenext)
- {
- if (firstphasedone >= 0) goto multipleadc;
- firstphasedone = count;
- }
- phase2 = phase3;
- phase3 = WRAPFWD(phase2 + 1);
- }
- post("nad %d phase %d busy %d done %d", nad, phase, firstphasebusy,
- firstphasedone);
- continue;
+ int phase = ntsnd_inphase[nad];
+ int phase2 = phase, phase3 = WRAPFWD(phase2), count, ntrans = 0;
+ int firstphasedone = -1, firstphasebusy = -1;
+ for (count = 0; count < nt_naudiobuffer; count++)
+ {
+ int donethis =
+ (ntsnd_invec[nad][phase2].lpWaveHdr->dwFlags & WHDR_DONE);
+ int donenext =
+ (ntsnd_invec[nad][phase3].lpWaveHdr->dwFlags & WHDR_DONE);
+ if (donethis && !donenext)
+ {
+ if (firstphasebusy >= 0) goto multipleadc;
+ firstphasebusy = count;
+ }
+ if (!donethis && donenext)
+ {
+ if (firstphasedone >= 0) goto multipleadc;
+ firstphasedone = count;
+ }
+ phase2 = phase3;
+ phase3 = WRAPFWD(phase2 + 1);
+ }
+ post("nad %d phase %d busy %d done %d", nad, phase, firstphasebusy,
+ firstphasedone);
+ continue;
multipleadc:
- startpost("nad %d phase %d: oops:", nad, phase);
- for (count = 0; count < nt_naudiobuffer; count++)
- {
- char buf[80];
- sprintf(buf, " %d",
- (ntsnd_invec[nad][count].lpWaveHdr->dwFlags & WHDR_DONE));
- poststring(buf);
- }
- endpost();
+ startpost("nad %d phase %d: oops:", nad, phase);
+ for (count = 0; count < nt_naudiobuffer; count++)
+ {
+ char buf[80];
+ sprintf(buf, " %d",
+ (ntsnd_invec[nad][count].lpWaveHdr->dwFlags & WHDR_DONE));
+ poststring(buf);
+ }
+ endpost();
}
for (nda = 0; nda < nt_nwaveout; nda++)
{
- int phase = ntsnd_outphase[nad];
- int phase2 = phase, phase3 = WRAPFWD(phase2), count, ntrans = 0;
- int firstphasedone = -1, firstphasebusy = -1;
- for (count = 0; count < nt_naudiobuffer; count++)
- {
- int donethis =
- (ntsnd_outvec[nda][phase2].lpWaveHdr->dwFlags & WHDR_DONE);
- int donenext =
- (ntsnd_outvec[nda][phase3].lpWaveHdr->dwFlags & WHDR_DONE);
- if (donethis && !donenext)
- {
- if (firstphasebusy >= 0) goto multipledac;
- firstphasebusy = count;
- }
- if (!donethis && donenext)
- {
- if (firstphasedone >= 0) goto multipledac;
- firstphasedone = count;
- }
- phase2 = phase3;
- phase3 = WRAPFWD(phase2 + 1);
- }
- if (firstphasebusy < 0) post("nda %d phase %d all %d",
- nda, phase, (ntsnd_outvec[nad][0].lpWaveHdr->dwFlags & WHDR_DONE));
- else post("nda %d phase %d busy %d done %d", nda, phase, firstphasebusy,
- firstphasedone);
- continue;
+ int phase = ntsnd_outphase[nad];
+ int phase2 = phase, phase3 = WRAPFWD(phase2), count, ntrans = 0;
+ int firstphasedone = -1, firstphasebusy = -1;
+ for (count = 0; count < nt_naudiobuffer; count++)
+ {
+ int donethis =
+ (ntsnd_outvec[nda][phase2].lpWaveHdr->dwFlags & WHDR_DONE);
+ int donenext =
+ (ntsnd_outvec[nda][phase3].lpWaveHdr->dwFlags & WHDR_DONE);
+ if (donethis && !donenext)
+ {
+ if (firstphasebusy >= 0) goto multipledac;
+ firstphasebusy = count;
+ }
+ if (!donethis && donenext)
+ {
+ if (firstphasedone >= 0) goto multipledac;
+ firstphasedone = count;
+ }
+ phase2 = phase3;
+ phase3 = WRAPFWD(phase2 + 1);
+ }
+ if (firstphasebusy < 0) post("nda %d phase %d all %d",
+ nda, phase, (ntsnd_outvec[nad][0].lpWaveHdr->dwFlags & WHDR_DONE));
+ else post("nda %d phase %d busy %d done %d", nda, phase, firstphasebusy,
+ firstphasedone);
+ continue;
multipledac:
- startpost("nda %d phase %d: oops:", nda, phase);
- for (count = 0; count < nt_naudiobuffer; count++)
- {
- char buf[80];
- sprintf(buf, " %d",
- (ntsnd_outvec[nad][count].lpWaveHdr->dwFlags & WHDR_DONE));
- poststring(buf);
- }
- endpost();
+ startpost("nda %d phase %d: oops:", nda, phase);
+ for (count = 0; count < nt_naudiobuffer; count++)
+ {
+ char buf[80];
+ sprintf(buf, " %d",
+ (ntsnd_outvec[nad][count].lpWaveHdr->dwFlags & WHDR_DONE));
+ poststring(buf);
+ }
+ endpost();
}
}
#endif /* 0 */
@@ -403,54 +406,54 @@ static void nt_resyncaudio(void)
UINT mmresult;
int nad, nda, count;
if (nt_resync_cancelled)
- return;
- /* for each open input device, eat all buffers which are marked
- ready. The next one will thus be "busy". */
+ return;
+ /* for each open input device, eat all buffers which are marked
+ ready. The next one will thus be "busy". */
post("resyncing audio");
for (nad = 0; nad < nt_nwavein; nad++)
{
- int phase = ntsnd_inphase[nad];
- for (count = 0; count < MAXRESYNC; count++)
- {
- WAVEHDR *inwavehdr = ntsnd_invec[nad][phase].lpWaveHdr;
- if (!(inwavehdr->dwFlags & WHDR_DONE)) break;
- if (inwavehdr->dwFlags & WHDR_PREPARED)
- waveInUnprepareHeader(ntsnd_indev[nad],
- inwavehdr, sizeof(WAVEHDR));
- inwavehdr->dwFlags = 0L;
- waveInPrepareHeader(ntsnd_indev[nad], inwavehdr, sizeof(WAVEHDR));
- mmresult = waveInAddBuffer(ntsnd_indev[nad], inwavehdr,
- sizeof(WAVEHDR));
- if (mmresult != MMSYSERR_NOERROR)
- nt_waveinerror("waveInAddBuffer: %s\n", mmresult);
- ntsnd_inphase[nad] = phase = WRAPFWD(phase + 1);
- }
- if (count == MAXRESYNC) post("resync error 1");
+ int phase = ntsnd_inphase[nad];
+ for (count = 0; count < MAXRESYNC; count++)
+ {
+ WAVEHDR *inwavehdr = ntsnd_invec[nad][phase].lpWaveHdr;
+ if (!(inwavehdr->dwFlags & WHDR_DONE)) break;
+ if (inwavehdr->dwFlags & WHDR_PREPARED)
+ waveInUnprepareHeader(ntsnd_indev[nad],
+ inwavehdr, sizeof(WAVEHDR));
+ inwavehdr->dwFlags = 0L;
+ waveInPrepareHeader(ntsnd_indev[nad], inwavehdr, sizeof(WAVEHDR));
+ mmresult = waveInAddBuffer(ntsnd_indev[nad], inwavehdr,
+ sizeof(WAVEHDR));
+ if (mmresult != MMSYSERR_NOERROR)
+ nt_waveinerror("waveInAddBuffer: %s\n", mmresult);
+ ntsnd_inphase[nad] = phase = WRAPFWD(phase + 1);
+ }
+ if (count == MAXRESYNC) post("resync error 1");
}
- /* Each output buffer which is "ready" is filled with zeros and
- queued. */
+ /* Each output buffer which is "ready" is filled with zeros and
+ queued. */
for (nda = 0; nda < nt_nwaveout; nda++)
{
- int phase = ntsnd_outphase[nda];
- for (count = 0; count < MAXRESYNC; count++)
- {
- WAVEHDR *outwavehdr = ntsnd_outvec[nda][phase].lpWaveHdr;
- if (!(outwavehdr->dwFlags & WHDR_DONE)) break;
- if (outwavehdr->dwFlags & WHDR_PREPARED)
- waveOutUnprepareHeader(ntsnd_outdev[nda],
- outwavehdr, sizeof(WAVEHDR));
- outwavehdr->dwFlags = 0L;
- memset((char *)(ntsnd_outvec[nda][phase].lpData),
- 0, (CHANNELS_PER_DEVICE * SAMPSIZE * nt_realdacblksize));
- waveOutPrepareHeader(ntsnd_outdev[nda], outwavehdr,
- sizeof(WAVEHDR));
- mmresult = waveOutWrite(ntsnd_outdev[nda], outwavehdr,
- sizeof(WAVEHDR));
- if (mmresult != MMSYSERR_NOERROR)
- nt_waveouterror("waveOutAddBuffer: %s\n", mmresult);
- ntsnd_outphase[nda] = phase = WRAPFWD(phase + 1);
- }
- if (count == MAXRESYNC) post("resync error 2");
+ int phase = ntsnd_outphase[nda];
+ for (count = 0; count < MAXRESYNC; count++)
+ {
+ WAVEHDR *outwavehdr = ntsnd_outvec[nda][phase].lpWaveHdr;
+ if (!(outwavehdr->dwFlags & WHDR_DONE)) break;
+ if (outwavehdr->dwFlags & WHDR_PREPARED)
+ waveOutUnprepareHeader(ntsnd_outdev[nda],
+ outwavehdr, sizeof(WAVEHDR));
+ outwavehdr->dwFlags = 0L;
+ memset((char *)(ntsnd_outvec[nda][phase].lpData),
+ 0, (CHANNELS_PER_DEVICE * SAMPSIZE * nt_realdacblksize));
+ waveOutPrepareHeader(ntsnd_outdev[nda], outwavehdr,
+ sizeof(WAVEHDR));
+ mmresult = waveOutWrite(ntsnd_outdev[nda], outwavehdr,
+ sizeof(WAVEHDR));
+ if (mmresult != MMSYSERR_NOERROR)
+ nt_waveouterror("waveOutAddBuffer: %s\n", mmresult);
+ ntsnd_outphase[nda] = phase = WRAPFWD(phase + 1);
+ }
+ if (count == MAXRESYNC) post("resync error 2");
}
#ifdef MIDI_TIMESTAMP
@@ -474,11 +477,11 @@ void nt_logerror(int which)
if (which == RESYNC) nt_resynccount++;
if (sys_getrealtime() > nt_nextreporttime)
{
- post("%d audio I/O error%s", nt_errorcount,
- (nt_errorcount > 1 ? "s" : ""));
- if (nt_resynccount) post("DAC/ADC sync error");
- nt_errorcount = nt_resynccount = 0;
- nt_nextreporttime = sys_getrealtime() - 5;
+ post("%d audio I/O error%s", nt_errorcount,
+ (nt_errorcount > 1 ? "s" : ""));
+ if (nt_resynccount) post("DAC/ADC sync error");
+ nt_errorcount = nt_resynccount = 0;
+ nt_nextreporttime = sys_getrealtime() - 5;
}
#endif
}
@@ -523,126 +526,126 @@ int mmio_send_dacs(void)
nt_outmax = maxsamp;
}
- /* the "fill pointer" nt_fill controls where in the next
- I/O buffers we will write and/or read. If it's zero, we
- first check whether the buffers are marked "done". */
+ /* the "fill pointer" nt_fill controls where in the next
+ I/O buffers we will write and/or read. If it's zero, we
+ first check whether the buffers are marked "done". */
if (!nt_fill)
{
- for (nad = 0; nad < nt_nwavein; nad++)
- {
- int phase = ntsnd_inphase[nad];
- WAVEHDR *inwavehdr = ntsnd_invec[nad][phase].lpWaveHdr;
- if (!(inwavehdr->dwFlags & WHDR_DONE)) goto idle;
- }
- for (nda = 0; nda < nt_nwaveout; nda++)
- {
- int phase = ntsnd_outphase[nda];
- WAVEHDR *outwavehdr =
- ntsnd_outvec[nda][phase].lpWaveHdr;
- if (!(outwavehdr->dwFlags & WHDR_DONE)) goto idle;
- }
- for (nad = 0; nad < nt_nwavein; nad++)
- {
- int phase = ntsnd_inphase[nad];
- WAVEHDR *inwavehdr =
- ntsnd_invec[nad][phase].lpWaveHdr;
- if (inwavehdr->dwFlags & WHDR_PREPARED)
- waveInUnprepareHeader(ntsnd_indev[nad],
- inwavehdr, sizeof(WAVEHDR));
- }
- for (nda = 0; nda < nt_nwaveout; nda++)
- {
- int phase = ntsnd_outphase[nda];
- WAVEHDR *outwavehdr = ntsnd_outvec[nda][phase].lpWaveHdr;
- if (outwavehdr->dwFlags & WHDR_PREPARED)
- waveOutUnprepareHeader(ntsnd_outdev[nda],
- outwavehdr, sizeof(WAVEHDR));
- }
+ for (nad = 0; nad < nt_nwavein; nad++)
+ {
+ int phase = ntsnd_inphase[nad];
+ WAVEHDR *inwavehdr = ntsnd_invec[nad][phase].lpWaveHdr;
+ if (!(inwavehdr->dwFlags & WHDR_DONE)) goto idle;
+ }
+ for (nda = 0; nda < nt_nwaveout; nda++)
+ {
+ int phase = ntsnd_outphase[nda];
+ WAVEHDR *outwavehdr =
+ ntsnd_outvec[nda][phase].lpWaveHdr;
+ if (!(outwavehdr->dwFlags & WHDR_DONE)) goto idle;
+ }
+ for (nad = 0; nad < nt_nwavein; nad++)
+ {
+ int phase = ntsnd_inphase[nad];
+ WAVEHDR *inwavehdr =
+ ntsnd_invec[nad][phase].lpWaveHdr;
+ if (inwavehdr->dwFlags & WHDR_PREPARED)
+ waveInUnprepareHeader(ntsnd_indev[nad],
+ inwavehdr, sizeof(WAVEHDR));
+ }
+ for (nda = 0; nda < nt_nwaveout; nda++)
+ {
+ int phase = ntsnd_outphase[nda];
+ WAVEHDR *outwavehdr = ntsnd_outvec[nda][phase].lpWaveHdr;
+ if (outwavehdr->dwFlags & WHDR_PREPARED)
+ waveOutUnprepareHeader(ntsnd_outdev[nda],
+ outwavehdr, sizeof(WAVEHDR));
+ }
}
- /* Convert audio output to fixed-point and put it in the output
- buffer. */
+ /* Convert audio output to fixed-point and put it in the output
+ buffer. */
for (nda = 0, fp1 = sys_soundout; nda < nt_nwaveout; nda++)
{
- int phase = ntsnd_outphase[nda];
-
- for (i = 0, sp1 = (short *)(ntsnd_outvec[nda][phase].lpData) +
- CHANNELS_PER_DEVICE * nt_fill;
- i < 2; i++, fp1 += DEFDACBLKSIZE, sp1++)
- {
- for (j = 0, fp2 = fp1, sp2 = sp1; j < DEFDACBLKSIZE;
- j++, fp2++, sp2 += CHANNELS_PER_DEVICE)
- {
- int x1 = 32767.f * *fp2;
- if (x1 > 32767) x1 = 32767;
- else if (x1 < -32767) x1 = -32767;
- *sp2 = x1;
- }
- }
+ int phase = ntsnd_outphase[nda];
+
+ for (i = 0, sp1 = (short *)(ntsnd_outvec[nda][phase].lpData) +
+ CHANNELS_PER_DEVICE * nt_fill;
+ i < 2; i++, fp1 += DEFDACBLKSIZE, sp1++)
+ {
+ for (j = 0, fp2 = fp1, sp2 = sp1; j < DEFDACBLKSIZE;
+ j++, fp2++, sp2 += CHANNELS_PER_DEVICE)
+ {
+ int x1 = 32767.f * *fp2;
+ if (x1 > 32767) x1 = 32767;
+ else if (x1 < -32767) x1 = -32767;
+ *sp2 = x1;
+ }
+ }
}
memset(sys_soundout, 0,
- (DEFDACBLKSIZE *sizeof(t_sample)*CHANNELS_PER_DEVICE)*nt_nwaveout);
+ (DEFDACBLKSIZE *sizeof(t_sample)*CHANNELS_PER_DEVICE)*nt_nwaveout);
- /* vice versa for the input buffer */
+ /* vice versa for the input buffer */
for (nad = 0, fp1 = sys_soundin; nad < nt_nwavein; nad++)
{
- int phase = ntsnd_inphase[nad];
-
- for (i = 0, sp1 = (short *)(ntsnd_invec[nad][phase].lpData) +
- CHANNELS_PER_DEVICE * nt_fill;
- i < 2; i++, fp1 += DEFDACBLKSIZE, sp1++)
- {
- for (j = 0, fp2 = fp1, sp2 = sp1; j < DEFDACBLKSIZE;
- j++, fp2++, sp2 += CHANNELS_PER_DEVICE)
- {
- *fp2 = ((float)(1./32767.)) * (float)(*sp2);
- }
- }
+ int phase = ntsnd_inphase[nad];
+
+ for (i = 0, sp1 = (short *)(ntsnd_invec[nad][phase].lpData) +
+ CHANNELS_PER_DEVICE * nt_fill;
+ i < 2; i++, fp1 += DEFDACBLKSIZE, sp1++)
+ {
+ for (j = 0, fp2 = fp1, sp2 = sp1; j < DEFDACBLKSIZE;
+ j++, fp2++, sp2 += CHANNELS_PER_DEVICE)
+ {
+ *fp2 = ((float)(1./32767.)) * (float)(*sp2);
+ }
+ }
}
nt_fill = nt_fill + DEFDACBLKSIZE;
if (nt_fill == nt_realdacblksize)
{
- nt_fill = 0;
-
- for (nad = 0; nad < nt_nwavein; nad++)
- {
- int phase = ntsnd_inphase[nad];
- HWAVEIN device = ntsnd_indev[nad];
- WAVEHDR *inwavehdr = ntsnd_invec[nad][phase].lpWaveHdr;
- waveInPrepareHeader(device, inwavehdr, sizeof(WAVEHDR));
- mmresult = waveInAddBuffer(device, inwavehdr, sizeof(WAVEHDR));
- if (mmresult != MMSYSERR_NOERROR)
- nt_waveinerror("waveInAddBuffer: %s\n", mmresult);
- ntsnd_inphase[nad] = WRAPFWD(phase + 1);
- }
- for (nda = 0; nda < nt_nwaveout; nda++)
- {
- int phase = ntsnd_outphase[nda];
- HWAVEOUT device = ntsnd_outdev[nda];
- WAVEHDR *outwavehdr = ntsnd_outvec[nda][phase].lpWaveHdr;
- waveOutPrepareHeader(device, outwavehdr, sizeof(WAVEHDR));
- mmresult = waveOutWrite(device, outwavehdr, sizeof(WAVEHDR));
+ nt_fill = 0;
+
+ for (nad = 0; nad < nt_nwavein; nad++)
+ {
+ int phase = ntsnd_inphase[nad];
+ HWAVEIN device = ntsnd_indev[nad];
+ WAVEHDR *inwavehdr = ntsnd_invec[nad][phase].lpWaveHdr;
+ waveInPrepareHeader(device, inwavehdr, sizeof(WAVEHDR));
+ mmresult = waveInAddBuffer(device, inwavehdr, sizeof(WAVEHDR));
if (mmresult != MMSYSERR_NOERROR)
- nt_waveouterror("waveOutWrite: %s\n", mmresult);
- ntsnd_outphase[nda] = WRAPFWD(phase + 1);
- }
-
- /* check for DAC underflow or ADC overflow. */
- for (nad = 0; nad < nt_nwavein; nad++)
- {
- int phase = WRAPBACK(ntsnd_inphase[nad] - 2);
- WAVEHDR *inwavehdr = ntsnd_invec[nad][phase].lpWaveHdr;
- if (inwavehdr->dwFlags & WHDR_DONE) goto late;
- }
- for (nda = 0; nda < nt_nwaveout; nda++)
- {
- int phase = WRAPBACK(ntsnd_outphase[nda] - 2);
- WAVEHDR *outwavehdr = ntsnd_outvec[nda][phase].lpWaveHdr;
- if (outwavehdr->dwFlags & WHDR_DONE) goto late;
- }
+ nt_waveinerror("waveInAddBuffer: %s\n", mmresult);
+ ntsnd_inphase[nad] = WRAPFWD(phase + 1);
+ }
+ for (nda = 0; nda < nt_nwaveout; nda++)
+ {
+ int phase = ntsnd_outphase[nda];
+ HWAVEOUT device = ntsnd_outdev[nda];
+ WAVEHDR *outwavehdr = ntsnd_outvec[nda][phase].lpWaveHdr;
+ waveOutPrepareHeader(device, outwavehdr, sizeof(WAVEHDR));
+ mmresult = waveOutWrite(device, outwavehdr, sizeof(WAVEHDR));
+ if (mmresult != MMSYSERR_NOERROR)
+ nt_waveouterror("waveOutWrite: %s\n", mmresult);
+ ntsnd_outphase[nda] = WRAPFWD(phase + 1);
+ }
+
+ /* check for DAC underflow or ADC overflow. */
+ for (nad = 0; nad < nt_nwavein; nad++)
+ {
+ int phase = WRAPBACK(ntsnd_inphase[nad] - 2);
+ WAVEHDR *inwavehdr = ntsnd_invec[nad][phase].lpWaveHdr;
+ if (inwavehdr->dwFlags & WHDR_DONE) goto late;
+ }
+ for (nda = 0; nda < nt_nwaveout; nda++)
+ {
+ int phase = WRAPBACK(ntsnd_outphase[nda] - 2);
+ WAVEHDR *outwavehdr = ntsnd_outvec[nda][phase].lpWaveHdr;
+ if (outwavehdr->dwFlags & WHDR_DONE) goto late;
+ }
}
return (1);
@@ -659,29 +662,29 @@ idle:
for (nad = 0; nad < nt_nwavein; nad++)
{
- int phase = ntsnd_inphase[nad];
- WAVEHDR *inwavehdr =
- ntsnd_invec[nad]
- [WRAPFWD(phase + nt_adcjitterbufsallowed)].lpWaveHdr;
- if (inwavehdr->dwFlags & WHDR_DONE)
- {
- nt_resyncaudio();
- return (0);
- }
+ int phase = ntsnd_inphase[nad];
+ WAVEHDR *inwavehdr =
+ ntsnd_invec[nad]
+ [WRAPFWD(phase + nt_adcjitterbufsallowed)].lpWaveHdr;
+ if (inwavehdr->dwFlags & WHDR_DONE)
+ {
+ nt_resyncaudio();
+ return (0);
+ }
}
- /* test dac sync the same way */
+ /* test dac sync the same way */
for (nda = 0; nda < nt_nwaveout; nda++)
{
- int phase = ntsnd_outphase[nda];
- WAVEHDR *outwavehdr =
- ntsnd_outvec[nda]
- [WRAPFWD(phase + nt_dacjitterbufsallowed)].lpWaveHdr;
- if (outwavehdr->dwFlags & WHDR_DONE)
- {
- nt_resyncaudio();
- return (0);
- }
+ int phase = ntsnd_outphase[nda];
+ WAVEHDR *outwavehdr =
+ ntsnd_outvec[nda]
+ [WRAPFWD(phase + nt_dacjitterbufsallowed)].lpWaveHdr;
+ if (outwavehdr->dwFlags & WHDR_DONE)
+ {
+ nt_resyncaudio();
+ return (0);
+ }
}
#ifdef MIDI_TIMESTAMP
nt_midisync();
@@ -701,24 +704,24 @@ void mmio_open_audio(int naudioindev, int *audioindev,
nbuf = sys_advance_samples/nt_realdacblksize;
if (nbuf >= MAXBUFFER)
{
- fprintf(stderr, "pd: audio buffering maxed out to %d\n",
- (int)(MAXBUFFER * ((nt_realdacblksize * 1000.)/44100.)));
- nbuf = MAXBUFFER;
+ fprintf(stderr, "pd: audio buffering maxed out to %d\n",
+ (int)(MAXBUFFER * ((nt_realdacblksize * 1000.)/44100.)));
+ nbuf = MAXBUFFER;
}
else if (nbuf < 4) nbuf = 4;
fprintf(stderr, "%d audio buffers\n", nbuf);
nt_naudiobuffer = nbuf;
if (nt_adcjitterbufsallowed > nbuf - 2)
- nt_adcjitterbufsallowed = nbuf - 2;
+ nt_adcjitterbufsallowed = nbuf - 2;
if (nt_dacjitterbufsallowed > nbuf - 2)
- nt_dacjitterbufsallowed = nbuf - 2;
+ nt_dacjitterbufsallowed = nbuf - 2;
nt_nwavein = sys_inchannels / 2;
nt_nwaveout = sys_outchannels / 2;
nt_whichadc = (naudioindev < 1 ?
- (nt_nwavein > 1 ? WAVE_MAPPER : -1) : audioindev[0]);
+ (nt_nwavein > 1 ? WAVE_MAPPER : -1) : audioindev[0]);
nt_whichdac = (naudiooutdev < 1 ?
- (nt_nwaveout > 1 ? WAVE_MAPPER : -1) : audiooutdev[0]);
+ (nt_nwaveout > 1 ? WAVE_MAPPER : -1) : audiooutdev[0]);
if (naudiooutdev > 1 || naudioindev > 1)
post("separate audio device choice not supported; using sequential devices.");
mmio_do_open_audio();
@@ -739,53 +742,53 @@ void mmio_listdevs(void)
ndevices = waveInGetNumDevs();
for (i = 0; i < ndevices; i++)
{
- WAVEINCAPS wicap;
- wRtn = waveInGetDevCaps(i, (LPWAVEINCAPS) &wicap,
+ WAVEINCAPS wicap;
+ wRtn = waveInGetDevCaps(i, (LPWAVEINCAPS) &wicap,
sizeof(wicap));
if (wRtn) nt_waveinerror("waveInGetDevCaps: %s\n", wRtn);
- else fprintf(stderr,
- "audio input device #%d: %s\n", i+1, wicap.szPname);
+ else fprintf(stderr,
+ "audio input device #%d: %s\n", i+1, wicap.szPname);
}
ndevices = waveOutGetNumDevs();
for (i = 0; i < ndevices; i++)
{
- WAVEOUTCAPS wocap;
- wRtn = waveOutGetDevCaps(i, (LPWAVEOUTCAPS) &wocap,
+ WAVEOUTCAPS wocap;
+ wRtn = waveOutGetDevCaps(i, (LPWAVEOUTCAPS) &wocap,
sizeof(wocap));
if (wRtn) nt_waveouterror("waveOutGetDevCaps: %s\n", wRtn);
- else fprintf(stderr,
- "audio output device #%d: %s\n", i+1, wocap.szPname);
+ else fprintf(stderr,
+ "audio output device #%d: %s\n", i+1, wocap.szPname);
}
}
#endif
void mmio_getdevs(char *indevlist, int *nindevs,
char *outdevlist, int *noutdevs, int *canmulti,
- int maxndev, int devdescsize)
+ int maxndev, int devdescsize)
{
int wRtn, ndev, i;
*canmulti = 2; /* supports multiple devices */
ndev = waveInGetNumDevs();
if (ndev > maxndev)
- ndev = maxndev;
+ ndev = maxndev;
*nindevs = ndev;
for (i = 0; i < ndev; i++)
{
- WAVEINCAPS wicap;
- wRtn = waveInGetDevCaps(i, (LPWAVEINCAPS) &wicap, sizeof(wicap));
- sprintf(indevlist + i * devdescsize, (wRtn ? "???" : wicap.szPname));
+ WAVEINCAPS wicap;
+ wRtn = waveInGetDevCaps(i, (LPWAVEINCAPS) &wicap, sizeof(wicap));
+ sprintf(indevlist + i * devdescsize, (wRtn ? "???" : wicap.szPname));
}
ndev = waveOutGetNumDevs();
if (ndev > maxndev)
- ndev = maxndev;
+ ndev = maxndev;
*noutdevs = ndev;
for (i = 0; i < ndev; i++)
{
- WAVEOUTCAPS wocap;
- wRtn = waveOutGetDevCaps(i, (LPWAVEOUTCAPS) &wocap, sizeof(wocap));
- sprintf(outdevlist + i * devdescsize, (wRtn ? "???" : wocap.szPname));
+ WAVEOUTCAPS wocap;
+ wRtn = waveOutGetDevCaps(i, (LPWAVEOUTCAPS) &wocap, sizeof(wocap));
+ sprintf(outdevlist + i * devdescsize, (wRtn ? "???" : wocap.szPname));
}
}
diff --git a/pd/src/s_audio_oss.c b/pd/src/s_audio_oss.c
index f0a86a45..21927f68 100644
--- a/pd/src/s_audio_oss.c
+++ b/pd/src/s_audio_oss.c
@@ -27,9 +27,9 @@
#define DEBUG(x) x
#define DEBUG2(x) {x;}
-#define OSS_MAXCHPERDEV 32 /* max channels per OSS device */
-#define OSS_MAXDEV 4 /* maximum number of input or output devices */
-#define OSS_DEFFRAGSIZE 256 /* default log fragment size (frames) */
+#define OSS_MAXCHPERDEV 32 /* max channels per OSS device */
+#define OSS_MAXDEV 4 /* maximum number of input or output devices */
+#define OSS_DEFFRAGSIZE 256 /* default log fragment size (frames) */
#define OSS_DEFAUDIOBUF 40000 /* default audiobuffer, microseconds */
#define OSS_DEFAULTCH 2
#define RME_DEFAULTCH 8 /* need this even if RME undefined */
@@ -41,10 +41,10 @@ typedef int32_t t_oss_int32;
#define OSS_XFERSIZE(chans, width) (DEFDACBLKSIZE * (chans) * (width))
/* GLOBALS */
-static int linux_meters; /* true if we're metering */
-static float linux_inmax; /* max input amplitude */
-static float linux_outmax; /* max output amplitude */
-static int linux_fragsize = 0; /* for block mode; block size (sample frames) */
+static int linux_meters; /* true if we're metering */
+static float linux_inmax; /* max input amplitude */
+static float linux_outmax; /* max output amplitude */
+static int linux_fragsize = 0; /* for block mode; block size (sample frames) */
/* our device handles */
@@ -52,9 +52,9 @@ typedef struct _oss_dev
{
int d_fd;
unsigned int d_space; /* bytes available for writing/reading */
- int d_bufsize; /* total buffer size in blocks for this device */
- int d_dropcount; /* # of buffers to drop for resync (output only) */
- unsigned int d_nchannels; /* number of channels for this device */
+ int d_bufsize; /* total buffer size in blocks for this device */
+ int d_dropcount; /* # of buffers to drop for resync (output only) */
+ unsigned int d_nchannels; /* number of channels for this device */
unsigned int d_bytespersamp; /* bytes per sample (2 for 16 bit, 4 for 32) */
} t_oss_dev;
@@ -69,8 +69,8 @@ t_sample *sys_soundout;
t_sample *sys_soundin;
/* OSS-specific private variables */
-static int oss_blockmode = 1; /* flag to use "blockmode" */
-static int oss_32bit = 0; /* allow 23 bit transfers in OSS */
+static int oss_blockmode = 1; /* flag to use "blockmode" */
+static int oss_32bit = 0; /* allow 23 bit transfers in OSS */
static char ossdsp[] = "/dev/dsp%d";
/* don't assume we can turn all 31 bits when doing float-to-fix;
@@ -92,19 +92,19 @@ void oss_init(void)
int fd, i;
static int countedthem = 0;
if (countedthem)
- return;
+ return;
for (i = 0; i < 10; i++)
{
- char devname[100];
- if (i == 0)
- strcpy(devname, "/dev/dsp");
- else sprintf(devname, "/dev/dsp%d", i);
- if ( (fd = open(devname, O_WRONLY|O_NONBLOCK)) != -1)
- {
- oss_ndev++;
- close(fd);
- }
- else break;
+ char devname[100];
+ if (i == 0)
+ strcpy(devname, "/dev/dsp");
+ else sprintf(devname, "/dev/dsp%d", i);
+ if ( (fd = open(devname, O_WRONLY|O_NONBLOCK)) != -1)
+ {
+ oss_ndev++;
+ close(fd);
+ }
+ else break;
}
countedthem = 1;
}
@@ -124,7 +124,7 @@ typedef struct _multidev {
int oss_reset(int fd) {
int err;
if ((err = ioctl(fd,SNDCTL_DSP_RESET)) < 0)
- error("OSS: Could not reset");
+ error("OSS: Could not reset");
return err;
}
@@ -150,101 +150,101 @@ void oss_configure(t_oss_dev *dev, int srate, int dac, int skipblocksize)
multiple soundcards
*/
- /* set resolution - first try 4 byte samples */
+ /* set resolution - first try 4 byte samples */
if (oss_32bit && (ioctl(fd,SNDCTL_DSP_GETFMTS,&param) >= 0) &&
- (param & AFMT_S32_BLOCKED))
+ (param & AFMT_S32_BLOCKED))
{
- wantformat = AFMT_S32_BLOCKED;
- dev->d_bytespersamp = 4;
+ wantformat = AFMT_S32_BLOCKED;
+ dev->d_bytespersamp = 4;
}
else
{
- wantformat = AFMT_S16_NE;
- dev->d_bytespersamp = 2;
+ wantformat = AFMT_S16_NE;
+ dev->d_bytespersamp = 2;
}
param = wantformat;
if (sys_verbose)
- post("bytes per sample = %d", dev->d_bytespersamp);
+ post("bytes per sample = %d", dev->d_bytespersamp);
if (ioctl(fd, SNDCTL_DSP_SETFMT, &param) == -1)
- fprintf(stderr,"OSS: Could not set DSP format\n");
+ fprintf(stderr,"OSS: Could not set DSP format\n");
else if (wantformat != param)
- fprintf(stderr,"OSS: DSP format: wanted %d, got %d\n",
- wantformat, param);
+ fprintf(stderr,"OSS: DSP format: wanted %d, got %d\n",
+ wantformat, param);
/* sample rate */
orig = param = srate;
if (ioctl(fd, SNDCTL_DSP_SPEED, &param) == -1)
- fprintf(stderr,"OSS: Could not set sampling rate for device\n");
+ fprintf(stderr,"OSS: Could not set sampling rate for device\n");
else if( orig != param )
- fprintf(stderr,"OSS: sampling rate: wanted %d, got %d\n",
- orig, param );
+ fprintf(stderr,"OSS: sampling rate: wanted %d, got %d\n",
+ orig, param );
if (oss_blockmode && !skipblocksize)
{
- int fragbytes, logfragsize, nfragment;
- /* setting fragment count and size. */
- linux_fragsize = sys_blocksize;
- if (!linux_fragsize)
- {
- linux_fragsize = OSS_DEFFRAGSIZE;
- while (linux_fragsize > DEFDACBLKSIZE
- && linux_fragsize * 6 > sys_advance_samples)
- linux_fragsize = linux_fragsize/2;
- }
- /* post("adv_samples %d", sys_advance_samples); */
- nfragment = (sys_schedadvance * (44100. * 1.e-6)) / linux_fragsize;
-
- fragbytes = linux_fragsize * (dev->d_bytespersamp * nchannels);
- logfragsize = ilog2(fragbytes);
-
- if (fragbytes != (1 << logfragsize))
- post("warning: OSS takes only power of 2 blocksize; using %d",
- (1 << logfragsize)/(dev->d_bytespersamp * nchannels));
- if (sys_verbose)
- post("setting nfrags = %d, fragsize %d\n", nfragment, fragbytes);
-
- param = orig = (nfragment<<16) + logfragsize;
- if (ioctl(fd,SNDCTL_DSP_SETFRAGMENT, &param) == -1)
- error("OSS: Could not set or read fragment size\n");
- if (param != orig)
- {
- nfragment = ((param >> 16) & 0xffff);
- logfragsize = (param & 0xffff);
- post("warning: actual fragments %d, blocksize %d",
- nfragment, (1 << logfragsize));
- }
- if (sys_verbose)
- post("audiobuffer set to %d msec", (int)(0.001 * sys_schedadvance));
+ int fragbytes, logfragsize, nfragment;
+ /* setting fragment count and size. */
+ linux_fragsize = sys_blocksize;
+ if (!linux_fragsize)
+ {
+ linux_fragsize = OSS_DEFFRAGSIZE;
+ while (linux_fragsize > DEFDACBLKSIZE
+ && linux_fragsize * 6 > sys_advance_samples)
+ linux_fragsize = linux_fragsize/2;
+ }
+ /* post("adv_samples %d", sys_advance_samples); */
+ nfragment = (sys_schedadvance * (44100. * 1.e-6)) / linux_fragsize;
+
+ fragbytes = linux_fragsize * (dev->d_bytespersamp * nchannels);
+ logfragsize = ilog2(fragbytes);
+
+ if (fragbytes != (1 << logfragsize))
+ post("warning: OSS takes only power of 2 blocksize; using %d",
+ (1 << logfragsize)/(dev->d_bytespersamp * nchannels));
+ if (sys_verbose)
+ post("setting nfrags = %d, fragsize %d\n", nfragment, fragbytes);
+
+ param = orig = (nfragment<<16) + logfragsize;
+ if (ioctl(fd,SNDCTL_DSP_SETFRAGMENT, &param) == -1)
+ error("OSS: Could not set or read fragment size\n");
+ if (param != orig)
+ {
+ nfragment = ((param >> 16) & 0xffff);
+ logfragsize = (param & 0xffff);
+ post("warning: actual fragments %d, blocksize %d",
+ nfragment, (1 << logfragsize));
+ }
+ if (sys_verbose)
+ post("audiobuffer set to %d msec", (int)(0.001 * sys_schedadvance));
}
if (dac)
{
- /* use "free space" to learn the buffer size. Normally you
- should set this to your own desired value; but this seems not
- to be implemented uniformly across different sound cards. LATER
- we should figure out what to do if the requested scheduler advance
- is greater than this buffer size; for now, we just print something
- out. */
-
- int defect;
- if (ioctl(fd, SOUND_PCM_GETOSPACE,&ainfo) < 0)
- fprintf(stderr,"OSS: ioctl on output device failed");
- dev->d_bufsize = ainfo.bytes;
-
- defect = sys_advance_samples * (dev->d_bytespersamp * nchannels)
- - dev->d_bufsize - OSS_XFERSIZE(nchannels, dev->d_bytespersamp);
- if (defect > 0)
- {
- if (sys_verbose || defect > (dev->d_bufsize >> 2))
- fprintf(stderr,
- "OSS: requested audio buffer size %d limited to %d\n",
- sys_advance_samples * (dev->d_bytespersamp * nchannels),
- dev->d_bufsize);
- sys_advance_samples =
- (dev->d_bufsize - OSS_XFERSAMPS(nchannels)) /
- (dev->d_bytespersamp *nchannels);
- }
+ /* use "free space" to learn the buffer size. Normally you
+ should set this to your own desired value; but this seems not
+ to be implemented uniformly across different sound cards. LATER
+ we should figure out what to do if the requested scheduler advance
+ is greater than this buffer size; for now, we just print something
+ out. */
+
+ int defect;
+ if (ioctl(fd, SOUND_PCM_GETOSPACE,&ainfo) < 0)
+ fprintf(stderr,"OSS: ioctl on output device failed");
+ dev->d_bufsize = ainfo.bytes;
+
+ defect = sys_advance_samples * (dev->d_bytespersamp * nchannels)
+ - dev->d_bufsize - OSS_XFERSIZE(nchannels, dev->d_bytespersamp);
+ if (defect > 0)
+ {
+ if (sys_verbose || defect > (dev->d_bufsize >> 2))
+ fprintf(stderr,
+ "OSS: requested audio buffer size %d limited to %d\n",
+ sys_advance_samples * (dev->d_bytespersamp * nchannels),
+ dev->d_bufsize);
+ sys_advance_samples =
+ (dev->d_bufsize - OSS_XFERSAMPS(nchannels)) /
+ (dev->d_bytespersamp *nchannels);
+ }
}
}
@@ -254,11 +254,11 @@ static int oss_setchannels(int fd, int wantchannels, char *devname)
while (param > 1)
{
- int save = param;
- if (ioctl(fd, SNDCTL_DSP_CHANNELS, &param) == -1)
- error("OSS: SNDCTL_DSP_CHANNELS failed %s",devname);
- else if (param == save)
- return (param);
+ int save = param;
+ if (ioctl(fd, SNDCTL_DSP_CHANNELS, &param) == -1)
+ error("OSS: SNDCTL_DSP_CHANNELS failed %s",devname);
+ else if (param == save)
+ return (param);
param = save - 1;
}
@@ -281,108 +281,108 @@ int oss_open_audio(int nindev, int *indev, int nchin, int *chin,
audio_buf_info ainfo;
linux_nindevs = linux_noutdevs = 0;
- /* mark devices unopened */
+ /* mark devices unopened */
for (i = 0; i < OSS_MAXDEV; i++)
- linux_adcs[i].d_fd = linux_dacs[i].d_fd = -1;
+ linux_adcs[i].d_fd = linux_dacs[i].d_fd = -1;
/* open output devices */
wantmore=0;
if (noutdev < 0 || nindev < 0)
- bug("linux_open_audio");
+ bug("linux_open_audio");
for (n = 0; n < noutdev; n++)
{
- int gotchans, j, inindex = -1;
- int thisdevice = (outdev[n] >= 0 ? outdev[n] : 0);
- int wantchannels = (nchout>n) ? chout[n] : wantmore;
- fd = -1;
- if (!wantchannels)
- goto end_out_loop;
-
- if (thisdevice > 0)
- sprintf(devname, "/dev/dsp%d", thisdevice);
- else sprintf(devname, "/dev/dsp");
- /* search for input request for same device. Succeed only
- if the number of channels matches. */
- for (j = 0; j < nindev; j++)
- if (indev[j] == thisdevice && chin[j] == wantchannels)
- inindex = j;
-
- /* if the same device is requested for input and output,
- try to open it read/write */
- if (inindex >= 0)
- {
- sys_setalarm(1000000);
- if ((fd = open(devname, O_RDWR | O_AUDIOFLAG)) == -1)
- {
- post("%s (read/write): %s", devname, strerror(errno));
- post("(now will try write-only...)");
- }
- else
- {
- if (fcntl(fd, F_SETFD, 1) < 0)
- post("couldn't set close-on-exec flag on audio");
- if ((flags = fcntl(fd, F_GETFL)) < 0)
- post("couldn't get audio device flags");
- else if (fcntl(fd, F_SETFL, flags & (!O_NDELAY)) < 0)
- post("couldn't set audio device flags");
- if (sys_verbose)
- post("opened %s for reading and writing\n", devname);
- linux_adcs[inindex].d_fd = fd;
- }
- }
- /* if that didn't happen or if it failed, try write-only */
- if (fd == -1)
- {
- sys_setalarm(1000000);
- if ((fd = open(devname, O_WRONLY | O_AUDIOFLAG)) == -1)
- {
- post("%s (writeonly): %s",
- devname, strerror(errno));
- break;
- }
- if (fcntl(fd, F_SETFD, 1) < 0)
- post("couldn't set close-on-exec flag on audio");
- if ((flags = fcntl(fd, F_GETFL)) < 0)
- post("couldn't get audio device flags");
- else if (fcntl(fd, F_SETFL, flags & (!O_NDELAY)) < 0)
- post("couldn't set audio device flags");
- if (sys_verbose)
- post("opened %s for writing only\n", devname);
- }
- if (ioctl(fd, SNDCTL_DSP_GETCAPS, &capabilities) == -1)
- error("OSS: SNDCTL_DSP_GETCAPS failed %s", devname);
-
- gotchans = oss_setchannels(fd,
- (wantchannels>OSS_MAXCHPERDEV)?OSS_MAXCHPERDEV:wantchannels,
- devname);
-
- if (sys_verbose)
- post("opened audio output on %s; got %d channels",
- devname, gotchans);
-
- if (gotchans < 2)
- {
- /* can't even do stereo? just give up. */
- close(fd);
- }
- else
- {
- linux_dacs[linux_noutdevs].d_nchannels = gotchans;
- linux_dacs[linux_noutdevs].d_fd = fd;
- oss_configure(linux_dacs+linux_noutdevs, rate, 1, 0);
-
- linux_noutdevs++;
- outchannels += gotchans;
- if (inindex >= 0)
- {
- linux_adcs[inindex].d_nchannels = gotchans;
- chin[inindex] = gotchans;
- }
- }
- /* LATER think about spreading large numbers of channels over
- various dsp's and vice-versa */
- wantmore = wantchannels - gotchans;
+ int gotchans, j, inindex = -1;
+ int thisdevice = (outdev[n] >= 0 ? outdev[n] : 0);
+ int wantchannels = (nchout>n) ? chout[n] : wantmore;
+ fd = -1;
+ if (!wantchannels)
+ goto end_out_loop;
+
+ if (thisdevice > 0)
+ sprintf(devname, "/dev/dsp%d", thisdevice);
+ else sprintf(devname, "/dev/dsp");
+ /* search for input request for same device. Succeed only
+ if the number of channels matches. */
+ for (j = 0; j < nindev; j++)
+ if (indev[j] == thisdevice && chin[j] == wantchannels)
+ inindex = j;
+
+ /* if the same device is requested for input and output,
+ try to open it read/write */
+ if (inindex >= 0)
+ {
+ sys_setalarm(1000000);
+ if ((fd = open(devname, O_RDWR | O_AUDIOFLAG)) == -1)
+ {
+ post("%s (read/write): %s", devname, strerror(errno));
+ post("(now will try write-only...)");
+ }
+ else
+ {
+ if (fcntl(fd, F_SETFD, 1) < 0)
+ post("couldn't set close-on-exec flag on audio");
+ if ((flags = fcntl(fd, F_GETFL)) < 0)
+ post("couldn't get audio device flags");
+ else if (fcntl(fd, F_SETFL, flags & (!O_NDELAY)) < 0)
+ post("couldn't set audio device flags");
+ if (sys_verbose)
+ post("opened %s for reading and writing\n", devname);
+ linux_adcs[inindex].d_fd = fd;
+ }
+ }
+ /* if that didn't happen or if it failed, try write-only */
+ if (fd == -1)
+ {
+ sys_setalarm(1000000);
+ if ((fd = open(devname, O_WRONLY | O_AUDIOFLAG)) == -1)
+ {
+ post("%s (writeonly): %s",
+ devname, strerror(errno));
+ break;
+ }
+ if (fcntl(fd, F_SETFD, 1) < 0)
+ post("couldn't set close-on-exec flag on audio");
+ if ((flags = fcntl(fd, F_GETFL)) < 0)
+ post("couldn't get audio device flags");
+ else if (fcntl(fd, F_SETFL, flags & (!O_NDELAY)) < 0)
+ post("couldn't set audio device flags");
+ if (sys_verbose)
+ post("opened %s for writing only\n", devname);
+ }
+ if (ioctl(fd, SNDCTL_DSP_GETCAPS, &capabilities) == -1)
+ error("OSS: SNDCTL_DSP_GETCAPS failed %s", devname);
+
+ gotchans = oss_setchannels(fd,
+ (wantchannels>OSS_MAXCHPERDEV)?OSS_MAXCHPERDEV:wantchannels,
+ devname);
+
+ if (sys_verbose)
+ post("opened audio output on %s; got %d channels",
+ devname, gotchans);
+
+ if (gotchans < 2)
+ {
+ /* can't even do stereo? just give up. */
+ close(fd);
+ }
+ else
+ {
+ linux_dacs[linux_noutdevs].d_nchannels = gotchans;
+ linux_dacs[linux_noutdevs].d_fd = fd;
+ oss_configure(linux_dacs+linux_noutdevs, rate, 1, 0);
+
+ linux_noutdevs++;
+ outchannels += gotchans;
+ if (inindex >= 0)
+ {
+ linux_adcs[inindex].d_nchannels = gotchans;
+ chin[inindex] = gotchans;
+ }
+ }
+ /* LATER think about spreading large numbers of channels over
+ various dsp's and vice-versa */
+ wantmore = wantchannels - gotchans;
end_out_loop: ;
}
@@ -390,67 +390,67 @@ int oss_open_audio(int nindev, int *indev, int nchin, int *chin,
wantmore = 0;
for (n = 0; n < nindev; n++)
{
- int gotchans=0;
- int thisdevice = (indev[n] >= 0 ? indev[n] : 0);
- int wantchannels = (nchin>n)?chin[n]:wantmore;
- int alreadyopened = 0;
- if (!wantchannels)
- goto end_in_loop;
-
- if (thisdevice > 0)
- sprintf(devname, "/dev/dsp%d", thisdevice);
- else sprintf(devname, "/dev/dsp");
-
- sys_setalarm(1000000);
-
- /* perhaps it's already open from the above? */
- if (linux_dacs[n].d_fd >= 0)
- {
- fd = linux_adcs[n].d_fd;
- alreadyopened = 1;
- }
- else
- {
- /* otherwise try to open it here. */
- if ((fd = open(devname, O_RDONLY | O_AUDIOFLAG)) == -1)
- {
- post("%s (readonly): %s", devname, strerror(errno));
- goto end_in_loop;
- }
- if (fcntl(fd, F_SETFD, 1) < 0)
- post("couldn't set close-on-exec flag on audio");
- if ((flags = fcntl(fd, F_GETFL)) < 0)
- post("couldn't get audio device flags");
- else if (fcntl(fd, F_SETFL, flags & (!O_NDELAY)) < 0)
- post("couldn't set audio device flags");
- if (sys_verbose)
- post("opened %s for reading only\n", devname);
- }
- linux_adcs[linux_nindevs].d_fd = fd;
-
- gotchans = oss_setchannels(fd,
- (wantchannels>OSS_MAXCHPERDEV)?OSS_MAXCHPERDEV:wantchannels,
- devname);
- if (sys_verbose)
- post("opened audio input device %s; got %d channels",
- devname, gotchans);
-
- if (gotchans < 1)
- {
- close(fd);
- goto end_in_loop;
- }
-
- linux_adcs[linux_nindevs].d_nchannels = gotchans;
-
- oss_configure(linux_adcs+linux_nindevs, rate, 0, alreadyopened);
-
- inchannels += gotchans;
- linux_nindevs++;
-
- wantmore = wantchannels-gotchans;
- /* LATER think about spreading large numbers of channels over
- various dsp's and vice-versa */
+ int gotchans=0;
+ int thisdevice = (indev[n] >= 0 ? indev[n] : 0);
+ int wantchannels = (nchin>n)?chin[n]:wantmore;
+ int alreadyopened = 0;
+ if (!wantchannels)
+ goto end_in_loop;
+
+ if (thisdevice > 0)
+ sprintf(devname, "/dev/dsp%d", thisdevice);
+ else sprintf(devname, "/dev/dsp");
+
+ sys_setalarm(1000000);
+
+ /* perhaps it's already open from the above? */
+ if (linux_dacs[n].d_fd >= 0)
+ {
+ fd = linux_adcs[n].d_fd;
+ alreadyopened = 1;
+ }
+ else
+ {
+ /* otherwise try to open it here. */
+ if ((fd = open(devname, O_RDONLY | O_AUDIOFLAG)) == -1)
+ {
+ post("%s (readonly): %s", devname, strerror(errno));
+ goto end_in_loop;
+ }
+ if (fcntl(fd, F_SETFD, 1) < 0)
+ post("couldn't set close-on-exec flag on audio");
+ if ((flags = fcntl(fd, F_GETFL)) < 0)
+ post("couldn't get audio device flags");
+ else if (fcntl(fd, F_SETFL, flags & (!O_NDELAY)) < 0)
+ post("couldn't set audio device flags");
+ if (sys_verbose)
+ post("opened %s for reading only\n", devname);
+ }
+ linux_adcs[linux_nindevs].d_fd = fd;
+
+ gotchans = oss_setchannels(fd,
+ (wantchannels>OSS_MAXCHPERDEV)?OSS_MAXCHPERDEV:wantchannels,
+ devname);
+ if (sys_verbose)
+ post("opened audio input device %s; got %d channels",
+ devname, gotchans);
+
+ if (gotchans < 1)
+ {
+ close(fd);
+ goto end_in_loop;
+ }
+
+ linux_adcs[linux_nindevs].d_nchannels = gotchans;
+
+ oss_configure(linux_adcs+linux_nindevs, rate, 0, alreadyopened);
+
+ inchannels += gotchans;
+ linux_nindevs++;
+
+ wantmore = wantchannels-gotchans;
+ /* LATER think about spreading large numbers of channels over
+ various dsp's and vice-versa */
end_in_loop: ;
}
@@ -463,24 +463,24 @@ int oss_open_audio(int nindev, int *indev, int nchin, int *chin,
if (linux_nindevs)
{
- if (sys_verbose)
- fprintf(stderr,("OSS: issuing first ADC 'read' ... "));
- read(linux_adcs[0].d_fd, buf,
- linux_adcs[0].d_bytespersamp *
- linux_adcs[0].d_nchannels * DEFDACBLKSIZE);
- if (sys_verbose)
- fprintf(stderr, "...done.\n");
+ if (sys_verbose)
+ fprintf(stderr,("OSS: issuing first ADC 'read' ... "));
+ read(linux_adcs[0].d_fd, buf,
+ linux_adcs[0].d_bytespersamp *
+ linux_adcs[0].d_nchannels * DEFDACBLKSIZE);
+ if (sys_verbose)
+ fprintf(stderr, "...done.\n");
}
- /* now go and fill all the output buffers. */
+ /* now go and fill all the output buffers. */
for (i = 0; i < linux_noutdevs; i++)
{
- int j;
- memset(buf, 0, linux_dacs[i].d_bytespersamp *
- linux_dacs[i].d_nchannels * DEFDACBLKSIZE);
- for (j = 0; j < sys_advance_samples/DEFDACBLKSIZE; j++)
- write(linux_dacs[i].d_fd, buf,
- linux_dacs[i].d_bytespersamp *
- linux_dacs[i].d_nchannels * DEFDACBLKSIZE);
+ int j;
+ memset(buf, 0, linux_dacs[i].d_bytespersamp *
+ linux_dacs[i].d_nchannels * DEFDACBLKSIZE);
+ for (j = 0; j < sys_advance_samples/DEFDACBLKSIZE; j++)
+ write(linux_dacs[i].d_fd, buf,
+ linux_dacs[i].d_bytespersamp *
+ linux_dacs[i].d_nchannels * DEFDACBLKSIZE);
}
sys_setalarm(0);
sys_inchannels = inchannels;
@@ -492,7 +492,7 @@ void oss_close_audio( void)
{
int i;
for (i=0;i<linux_nindevs;i++)
- close(linux_adcs[i].d_fd);
+ close(linux_adcs[i].d_fd);
for (i=0;i<linux_noutdevs;i++)
close(linux_dacs[i].d_fd);
@@ -517,17 +517,17 @@ static void oss_calcspace(void)
audio_buf_info ainfo;
for (dev=0; dev < linux_noutdevs; dev++)
{
- if (ioctl(linux_dacs[dev].d_fd, SOUND_PCM_GETOSPACE, &ainfo) < 0)
- fprintf(stderr,"OSS: ioctl on output device %d failed",dev);
- linux_dacs[dev].d_space = ainfo.bytes;
+ if (ioctl(linux_dacs[dev].d_fd, SOUND_PCM_GETOSPACE, &ainfo) < 0)
+ fprintf(stderr,"OSS: ioctl on output device %d failed",dev);
+ linux_dacs[dev].d_space = ainfo.bytes;
}
for (dev = 0; dev < linux_nindevs; dev++)
{
- if (ioctl(linux_adcs[dev].d_fd, SOUND_PCM_GETISPACE,&ainfo) < 0)
- fprintf(stderr, "OSS: ioctl on input device %d, fd %d failed",
- dev, linux_adcs[dev].d_fd);
- linux_adcs[dev].d_space = ainfo.bytes;
+ if (ioctl(linux_adcs[dev].d_fd, SOUND_PCM_GETISPACE,&ainfo) < 0)
+ fprintf(stderr, "OSS: ioctl on input device %d, fd %d failed",
+ dev, linux_adcs[dev].d_fd);
+ linux_adcs[dev].d_space = ainfo.bytes;
}
}
@@ -536,12 +536,12 @@ void linux_audiostatus(void)
int dev;
if (!oss_blockmode)
{
- oss_calcspace();
- for (dev=0; dev < linux_noutdevs; dev++)
- fprintf(stderr, "dac %d space %d\n", dev, linux_dacs[dev].d_space);
+ oss_calcspace();
+ for (dev=0; dev < linux_noutdevs; dev++)
+ fprintf(stderr, "dac %d space %d\n", dev, linux_dacs[dev].d_space);
- for (dev = 0; dev < linux_nindevs; dev++)
- fprintf(stderr, "adc %d space %d\n", dev, linux_adcs[dev].d_space);
+ for (dev = 0; dev < linux_nindevs; dev++)
+ fprintf(stderr, "adc %d space %d\n", dev, linux_adcs[dev].d_space);
}
}
@@ -555,75 +555,75 @@ static void oss_doresync( void)
char buf[OSS_MAXSAMPLEWIDTH * DEFDACBLKSIZE * OSS_MAXCHPERDEV];
audio_buf_info ainfo;
- /* 1. if any input devices are ahead (have more than 1 buffer stored),
- drop one or more buffers worth */
+ /* 1. if any input devices are ahead (have more than 1 buffer stored),
+ drop one or more buffers worth */
for (dev = 0; dev < linux_nindevs; dev++)
{
- if (linux_adcs[dev].d_space == 0)
- {
- linux_adcs_read(linux_adcs[dev].d_fd, buf,
- OSS_XFERSIZE(linux_adcs[dev].d_nchannels,
- linux_adcs[dev].d_bytespersamp));
- }
- else while (linux_adcs[dev].d_space >
- OSS_XFERSIZE(linux_adcs[dev].d_nchannels,
- linux_adcs[dev].d_bytespersamp))
- {
- linux_adcs_read(linux_adcs[dev].d_fd, buf,
- OSS_XFERSIZE(linux_adcs[dev].d_nchannels,
- linux_adcs[dev].d_bytespersamp));
- if (ioctl(linux_adcs[dev].d_fd, SOUND_PCM_GETISPACE, &ainfo) < 0)
- {
- fprintf(stderr, "OSS: ioctl on input device %d, fd %d failed",
- dev, linux_adcs[dev].d_fd);
- break;
- }
- linux_adcs[dev].d_space = ainfo.bytes;
- }
+ if (linux_adcs[dev].d_space == 0)
+ {
+ linux_adcs_read(linux_adcs[dev].d_fd, buf,
+ OSS_XFERSIZE(linux_adcs[dev].d_nchannels,
+ linux_adcs[dev].d_bytespersamp));
+ }
+ else while (linux_adcs[dev].d_space >
+ OSS_XFERSIZE(linux_adcs[dev].d_nchannels,
+ linux_adcs[dev].d_bytespersamp))
+ {
+ linux_adcs_read(linux_adcs[dev].d_fd, buf,
+ OSS_XFERSIZE(linux_adcs[dev].d_nchannels,
+ linux_adcs[dev].d_bytespersamp));
+ if (ioctl(linux_adcs[dev].d_fd, SOUND_PCM_GETISPACE, &ainfo) < 0)
+ {
+ fprintf(stderr, "OSS: ioctl on input device %d, fd %d failed",
+ dev, linux_adcs[dev].d_fd);
+ break;
+ }
+ linux_adcs[dev].d_space = ainfo.bytes;
+ }
}
- /* 2. if any output devices are behind, feed them zeros to catch them
- up */
+ /* 2. if any output devices are behind, feed them zeros to catch them
+ up */
for (dev = 0; dev < linux_noutdevs; dev++)
{
- while (linux_dacs[dev].d_space > linux_dacs[dev].d_bufsize -
- sys_advance_samples * (linux_dacs[dev].d_nchannels *
- linux_dacs[dev].d_bytespersamp))
- {
- if (!zeroed)
- {
- unsigned int i;
- for (i = 0; i < OSS_XFERSAMPS(linux_dacs[dev].d_nchannels);
- i++)
- buf[i] = 0;
- zeroed = 1;
- }
- linux_dacs_write(linux_dacs[dev].d_fd, buf,
- OSS_XFERSIZE(linux_dacs[dev].d_nchannels,
- linux_dacs[dev].d_bytespersamp));
- if (ioctl(linux_dacs[dev].d_fd, SOUND_PCM_GETOSPACE, &ainfo) < 0)
- {
- fprintf(stderr, "OSS: ioctl on output device %d, fd %d failed",
- dev, linux_dacs[dev].d_fd);
- break;
- }
- linux_dacs[dev].d_space = ainfo.bytes;
- }
+ while (linux_dacs[dev].d_space > linux_dacs[dev].d_bufsize -
+ sys_advance_samples * (linux_dacs[dev].d_nchannels *
+ linux_dacs[dev].d_bytespersamp))
+ {
+ if (!zeroed)
+ {
+ unsigned int i;
+ for (i = 0; i < OSS_XFERSAMPS(linux_dacs[dev].d_nchannels);
+ i++)
+ buf[i] = 0;
+ zeroed = 1;
+ }
+ linux_dacs_write(linux_dacs[dev].d_fd, buf,
+ OSS_XFERSIZE(linux_dacs[dev].d_nchannels,
+ linux_dacs[dev].d_bytespersamp));
+ if (ioctl(linux_dacs[dev].d_fd, SOUND_PCM_GETOSPACE, &ainfo) < 0)
+ {
+ fprintf(stderr, "OSS: ioctl on output device %d, fd %d failed",
+ dev, linux_dacs[dev].d_fd);
+ break;
+ }
+ linux_dacs[dev].d_space = ainfo.bytes;
+ }
}
- /* 3. if any DAC devices are too far ahead, plan to drop the
- number of frames which will let the others catch up. */
+ /* 3. if any DAC devices are too far ahead, plan to drop the
+ number of frames which will let the others catch up. */
for (dev = 0; dev < linux_noutdevs; dev++)
{
- if (linux_dacs[dev].d_space > linux_dacs[dev].d_bufsize -
- (sys_advance_samples - 1) * linux_dacs[dev].d_nchannels *
- linux_dacs[dev].d_bytespersamp)
- {
- linux_dacs[dev].d_dropcount = sys_advance_samples - 1 -
- (linux_dacs[dev].d_space - linux_dacs[dev].d_bufsize) /
- (linux_dacs[dev].d_nchannels *
- linux_dacs[dev].d_bytespersamp) ;
- }
- else linux_dacs[dev].d_dropcount = 0;
+ if (linux_dacs[dev].d_space > linux_dacs[dev].d_bufsize -
+ (sys_advance_samples - 1) * linux_dacs[dev].d_nchannels *
+ linux_dacs[dev].d_bytespersamp)
+ {
+ linux_dacs[dev].d_dropcount = sys_advance_samples - 1 -
+ (linux_dacs[dev].d_space - linux_dacs[dev].d_bufsize) /
+ (linux_dacs[dev].d_nchannels *
+ linux_dacs[dev].d_bytespersamp) ;
+ }
+ else linux_dacs[dev].d_dropcount = 0;
}
}
@@ -635,188 +635,188 @@ int oss_send_dacs(void)
char buf[OSS_MAXSAMPLEWIDTH * DEFDACBLKSIZE * OSS_MAXCHPERDEV];
t_oss_int16 *sp;
t_oss_int32 *lp;
- /* the maximum number of samples we should have in the ADC buffer */
+ /* the maximum number of samples we should have in the ADC buffer */
int idle = 0;
int thischan;
double timeref, timenow;
if (!linux_nindevs && !linux_noutdevs)
- return (SENDDACS_NO);
+ return (SENDDACS_NO);
if (!oss_blockmode)
{
- /* determine whether we're idle. This is true if either (1)
- some input device has less than one buffer to read or (2) some
- output device has fewer than (sys_advance_samples) blocks buffered
- already. */
- oss_calcspace();
+ /* determine whether we're idle. This is true if either (1)
+ some input device has less than one buffer to read or (2) some
+ output device has fewer than (sys_advance_samples) blocks buffered
+ already. */
+ oss_calcspace();
- for (dev=0; dev < linux_noutdevs; dev++)
- if (linux_dacs[dev].d_dropcount ||
- (linux_dacs[dev].d_bufsize - linux_dacs[dev].d_space >
- sys_advance_samples * linux_dacs[dev].d_bytespersamp *
- linux_dacs[dev].d_nchannels))
- idle = 1;
- for (dev=0; dev < linux_nindevs; dev++)
- if (linux_adcs[dev].d_space <
- OSS_XFERSIZE(linux_adcs[dev].d_nchannels,
- linux_adcs[dev].d_bytespersamp))
- idle = 1;
+ for (dev=0; dev < linux_noutdevs; dev++)
+ if (linux_dacs[dev].d_dropcount ||
+ (linux_dacs[dev].d_bufsize - linux_dacs[dev].d_space >
+ sys_advance_samples * linux_dacs[dev].d_bytespersamp *
+ linux_dacs[dev].d_nchannels))
+ idle = 1;
+ for (dev=0; dev < linux_nindevs; dev++)
+ if (linux_adcs[dev].d_space <
+ OSS_XFERSIZE(linux_adcs[dev].d_nchannels,
+ linux_adcs[dev].d_bytespersamp))
+ idle = 1;
}
if (idle && !oss_blockmode)
{
- /* sometimes---rarely---when the ADC available-byte-count is
- zero, it's genuine, but usually it's because we're so
- late that the ADC has overrun its entire kernel buffer. We
- distinguish between the two by waiting 2 msec and asking again.
- There should be an error flag we could check instead; look for this
- someday... */
- for (dev = 0;dev < linux_nindevs; dev++)
- if (linux_adcs[dev].d_space == 0)
- {
- audio_buf_info ainfo;
- sys_microsleep(2000);
- oss_calcspace();
- if (linux_adcs[dev].d_space != 0) continue;
-
- /* here's the bad case. Give up and resync. */
- sys_log_error(ERR_DATALATE);
- oss_doresync();
- return (SENDDACS_NO);
- }
- /* check for slippage between devices, either because
- data got lost in the driver from a previous late condition, or
- because the devices aren't synced. When we're idle, no
- input device should have more than one buffer readable and
- no output device should have less than sys_advance_samples-1
- */
-
- for (dev=0; dev < linux_noutdevs; dev++)
- if (!linux_dacs[dev].d_dropcount &&
- (linux_dacs[dev].d_bufsize - linux_dacs[dev].d_space <
- (sys_advance_samples - 2) *
- (linux_dacs[dev].d_bytespersamp *
- linux_dacs[dev].d_nchannels)))
- goto badsync;
- for (dev=0; dev < linux_nindevs; dev++)
- if (linux_adcs[dev].d_space > 3 *
- OSS_XFERSIZE(linux_adcs[dev].d_nchannels,
- linux_adcs[dev].d_bytespersamp))
- goto badsync;
-
- /* return zero to tell the scheduler we're idle. */
- return (SENDDACS_NO);
+ /* sometimes---rarely---when the ADC available-byte-count is
+ zero, it's genuine, but usually it's because we're so
+ late that the ADC has overrun its entire kernel buffer. We
+ distinguish between the two by waiting 2 msec and asking again.
+ There should be an error flag we could check instead; look for this
+ someday... */
+ for (dev = 0;dev < linux_nindevs; dev++)
+ if (linux_adcs[dev].d_space == 0)
+ {
+ audio_buf_info ainfo;
+ sys_microsleep(2000);
+ oss_calcspace();
+ if (linux_adcs[dev].d_space != 0) continue;
+
+ /* here's the bad case. Give up and resync. */
+ sys_log_error(ERR_DATALATE);
+ oss_doresync();
+ return (SENDDACS_NO);
+ }
+ /* check for slippage between devices, either because
+ data got lost in the driver from a previous late condition, or
+ because the devices aren't synced. When we're idle, no
+ input device should have more than one buffer readable and
+ no output device should have less than sys_advance_samples-1
+ */
+
+ for (dev=0; dev < linux_noutdevs; dev++)
+ if (!linux_dacs[dev].d_dropcount &&
+ (linux_dacs[dev].d_bufsize - linux_dacs[dev].d_space <
+ (sys_advance_samples - 2) *
+ (linux_dacs[dev].d_bytespersamp *
+ linux_dacs[dev].d_nchannels)))
+ goto badsync;
+ for (dev=0; dev < linux_nindevs; dev++)
+ if (linux_adcs[dev].d_space > 3 *
+ OSS_XFERSIZE(linux_adcs[dev].d_nchannels,
+ linux_adcs[dev].d_bytespersamp))
+ goto badsync;
+
+ /* return zero to tell the scheduler we're idle. */
+ return (SENDDACS_NO);
badsync:
- sys_log_error(ERR_RESYNC);
- oss_doresync();
- return (SENDDACS_NO);
-
+ sys_log_error(ERR_RESYNC);
+ oss_doresync();
+ return (SENDDACS_NO);
+
}
- /* do output */
+ /* do output */
timeref = sys_getrealtime();
for (dev=0, thischan = 0; dev < linux_noutdevs; dev++)
{
- int nchannels = linux_dacs[dev].d_nchannels;
- if (linux_dacs[dev].d_dropcount)
- linux_dacs[dev].d_dropcount--;
- else
- {
- if (linux_dacs[dev].d_bytespersamp == 4)
- {
- for (i = DEFDACBLKSIZE * nchannels, fp1 = sys_soundout +
- DEFDACBLKSIZE*thischan,
- lp = (t_oss_int32 *)buf; i--; fp1++, lp++)
- {
- float f = *fp1 * 2147483648.;
- *lp = (f >= 2147483647. ? 2147483647. :
- (f < -2147483648. ? -2147483648. : f));
- }
- }
- else
- {
- for (i = DEFDACBLKSIZE, fp1 = sys_soundout +
- DEFDACBLKSIZE*thischan,
- sp = (t_oss_int16 *)buf; i--; fp1++, sp += nchannels)
- {
- for (j=0, fp2 = fp1; j<nchannels; j++, fp2 += DEFDACBLKSIZE)
- {
- int s = *fp2 * 32767.;
- if (s > 32767) s = 32767;
- else if (s < -32767) s = -32767;
- sp[j] = s;
- }
- }
- }
- linux_dacs_write(linux_dacs[dev].d_fd, buf,
- OSS_XFERSIZE(nchannels, linux_dacs[dev].d_bytespersamp));
- if ((timenow = sys_getrealtime()) - timeref > 0.002)
- {
- if (!oss_blockmode)
- sys_log_error(ERR_DACSLEPT);
- else rtnval = SENDDACS_SLEPT;
- }
- timeref = timenow;
- }
- thischan += nchannels;
+ int nchannels = linux_dacs[dev].d_nchannels;
+ if (linux_dacs[dev].d_dropcount)
+ linux_dacs[dev].d_dropcount--;
+ else
+ {
+ if (linux_dacs[dev].d_bytespersamp == 4)
+ {
+ for (i = DEFDACBLKSIZE * nchannels, fp1 = sys_soundout +
+ DEFDACBLKSIZE*thischan,
+ lp = (t_oss_int32 *)buf; i--; fp1++, lp++)
+ {
+ float f = *fp1 * 2147483648.;
+ *lp = (f >= 2147483647. ? 2147483647. :
+ (f < -2147483648. ? -2147483648. : f));
+ }
+ }
+ else
+ {
+ for (i = DEFDACBLKSIZE, fp1 = sys_soundout +
+ DEFDACBLKSIZE*thischan,
+ sp = (t_oss_int16 *)buf; i--; fp1++, sp += nchannels)
+ {
+ for (j=0, fp2 = fp1; j<nchannels; j++, fp2 += DEFDACBLKSIZE)
+ {
+ int s = *fp2 * 32767.;
+ if (s > 32767) s = 32767;
+ else if (s < -32767) s = -32767;
+ sp[j] = s;
+ }
+ }
+ }
+ linux_dacs_write(linux_dacs[dev].d_fd, buf,
+ OSS_XFERSIZE(nchannels, linux_dacs[dev].d_bytespersamp));
+ if ((timenow = sys_getrealtime()) - timeref > 0.002)
+ {
+ if (!oss_blockmode)
+ sys_log_error(ERR_DACSLEPT);
+ else rtnval = SENDDACS_SLEPT;
+ }
+ timeref = timenow;
+ }
+ thischan += nchannels;
}
memset(sys_soundout, 0,
- sys_outchannels * (sizeof(float) * DEFDACBLKSIZE));
+ sys_outchannels * (sizeof(float) * DEFDACBLKSIZE));
- /* do input */
+ /* do input */
for (dev = 0, thischan = 0; dev < linux_nindevs; dev++)
{
- int nchannels = linux_adcs[dev].d_nchannels;
- linux_adcs_read(linux_adcs[dev].d_fd, buf,
- OSS_XFERSIZE(nchannels, linux_adcs[dev].d_bytespersamp));
-
- if ((timenow = sys_getrealtime()) - timeref > 0.002)
- {
- if (!oss_blockmode)
- sys_log_error(ERR_ADCSLEPT);
- else
- rtnval = SENDDACS_SLEPT;
- }
- timeref = timenow;
-
- if (linux_adcs[dev].d_bytespersamp == 4)
- {
- for (i = DEFDACBLKSIZE*nchannels,
- fp1 = sys_soundin + thischan*DEFDACBLKSIZE,
- lp = (t_oss_int32 *)buf; i--; fp1++, lp++)
- {
- *fp1 = ((float)(*lp))*(float)(1./2147483648.);
- }
- }
- else
- {
- for (i = DEFDACBLKSIZE,fp1 = sys_soundin + thischan*DEFDACBLKSIZE,
- sp = (t_oss_int16 *)buf; i--; fp1++, sp += nchannels)
- {
- for (j=0;j<nchannels;j++)
- fp1[j*DEFDACBLKSIZE] = (float)sp[j]*(float)3.051850e-05;
- }
- }
- thischan += nchannels;
+ int nchannels = linux_adcs[dev].d_nchannels;
+ linux_adcs_read(linux_adcs[dev].d_fd, buf,
+ OSS_XFERSIZE(nchannels, linux_adcs[dev].d_bytespersamp));
+
+ if ((timenow = sys_getrealtime()) - timeref > 0.002)
+ {
+ if (!oss_blockmode)
+ sys_log_error(ERR_ADCSLEPT);
+ else
+ rtnval = SENDDACS_SLEPT;
+ }
+ timeref = timenow;
+
+ if (linux_adcs[dev].d_bytespersamp == 4)
+ {
+ for (i = DEFDACBLKSIZE*nchannels,
+ fp1 = sys_soundin + thischan*DEFDACBLKSIZE,
+ lp = (t_oss_int32 *)buf; i--; fp1++, lp++)
+ {
+ *fp1 = ((float)(*lp))*(float)(1./2147483648.);
+ }
+ }
+ else
+ {
+ for (i = DEFDACBLKSIZE,fp1 = sys_soundin + thischan*DEFDACBLKSIZE,
+ sp = (t_oss_int16 *)buf; i--; fp1++, sp += nchannels)
+ {
+ for (j=0;j<nchannels;j++)
+ fp1[j*DEFDACBLKSIZE] = (float)sp[j]*(float)3.051850e-05;
+ }
+ }
+ thischan += nchannels;
}
return (rtnval);
}
void oss_getdevs(char *indevlist, int *nindevs,
char *outdevlist, int *noutdevs, int *canmulti,
- int maxndev, int devdescsize)
+ int maxndev, int devdescsize)
{
int i, ndev;
*canmulti = 2; /* supports multiple devices */
if ((ndev = oss_ndev) > maxndev)
- ndev = maxndev;
+ ndev = maxndev;
for (i = 0; i < ndev; i++)
{
- sprintf(indevlist + i * devdescsize, "OSS device #%d", i+1);
- sprintf(outdevlist + i * devdescsize, "OSS device #%d", i+1);
+ sprintf(indevlist + i * devdescsize, "OSS device #%d", i+1);
+ sprintf(outdevlist + i * devdescsize, "OSS device #%d", i+1);
}
*nindevs = *noutdevs = ndev;
}
diff --git a/pd/src/s_audio_pa.c b/pd/src/s_audio_pa.c
index c74c6649..92f0e8bf 100644
--- a/pd/src/s_audio_pa.c
+++ b/pd/src/s_audio_pa.c
@@ -11,17 +11,12 @@
#include "s_stuff.h"
#include <stdio.h>
#include <stdlib.h>
-#include "portaudio.h"
-#include "pablio_pd.h"
+#include <portaudio.h>
+#include "s_audio_pablio.h"
/* LATER try to figure out how to handle default devices in portaudio;
the way s_audio.c handles them isn't going to work here. */
-#if defined(MACOSX) || defined(MSW)
-#define Pa_GetDefaultInputDevice Pa_GetDefaultInputDeviceID
-#define Pa_GetDefaultOutputDevice Pa_GetDefaultOutputDeviceID
-#endif
-
/* public interface declared in m_imp.h */
/* implementation */
@@ -32,6 +27,10 @@ static float *pa_soundin, *pa_soundout;
#define MAX_PA_CHANS 32
#define MAX_SAMPLES_PER_FRAME MAX_PA_CHANS * DEFDACBLKSIZE
+#ifndef PA19
+#define Pa_GetDeviceCount Pa_CountDevices
+#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)
@@ -42,96 +41,86 @@ int pa_open_audio(int inchans, int outchans, int rate, t_sample *soundin,
if (!initialized)
{
- /* Initialize PortAudio */
- int err = Pa_Initialize();
- if ( err != paNoError )
- {
- fprintf( stderr,
- "Error number %d occured initializing portaudio\n",
- err);
- fprintf( stderr, "Error message: %s\n", Pa_GetErrorText( err ) );
- return (1);
- }
- initialized = 1;
+ /* Initialize PortAudio */
+ int err = Pa_Initialize();
+ if ( err != paNoError )
+ {
+ fprintf( stderr,
+ "Error number %d occured initializing portaudio\n",
+ err);
+ fprintf( stderr, "Error message: %s\n", Pa_GetErrorText( err ) );
+ return (1);
+ }
+ initialized = 1;
}
/* post("in %d out %d rate %d device %d", inchans, outchans, rate, deviceno); */
- if (inchans != 0 && outchans != 0 && inchans != outchans)
- error("portaudio: number of input and output channels must match");
if (inchans > MAX_PA_CHANS)
{
- post("input channels reduced to maximum %d", MAX_PA_CHANS);
- inchans = MAX_PA_CHANS;
+ post("input channels reduced to maximum %d", MAX_PA_CHANS);
+ inchans = MAX_PA_CHANS;
}
if (outchans > MAX_PA_CHANS)
{
- post("output channels reduced to maximum %d", MAX_PA_CHANS);
- outchans = MAX_PA_CHANS;
+ post("output channels reduced to maximum %d", MAX_PA_CHANS);
+ outchans = MAX_PA_CHANS;
}
if (inchans > 0)
{
- for (j = 0, devno = 0; j < Pa_CountDevices(); j++)
- {
- const PaDeviceInfo *info = Pa_GetDeviceInfo(j);
- if (info->maxInputChannels > 0)
- {
- if (devno == indeviceno)
- {
- pa_indev = j;
- break;
- }
- devno++;
- }
- }
- }
+ for (j = 0, devno = 0; j < Pa_GetDeviceCount(); j++)
+ {
+ const PaDeviceInfo *info = Pa_GetDeviceInfo(j);
+ if (info->maxInputChannels > 0)
+ {
+ if (devno == indeviceno)
+ {
+ pa_indev = j;
+ break;
+ }
+ devno++;
+ }
+ }
+ }
if (outchans > 0)
{
- for (j = 0, devno = 0; j < Pa_CountDevices(); j++)
- {
- const PaDeviceInfo *info = Pa_GetDeviceInfo(j);
- if (info->maxOutputChannels > 0)
- {
- if (devno == outdeviceno)
- {
- pa_outdev = j;
- break;
- }
- devno++;
- }
- }
- }
+ for (j = 0, devno = 0; j < Pa_GetDeviceCount(); j++)
+ {
+ const PaDeviceInfo *info = Pa_GetDeviceInfo(j);
+ if (info->maxOutputChannels > 0)
+ {
+ if (devno == outdeviceno)
+ {
+ pa_outdev = j;
+ break;
+ }
+ devno++;
+ }
+ }
+ }
if (sys_verbose)
{
- post("input device %d, channels %d", pa_indev, inchans);
- post("output device %d, channels %d", pa_outdev, outchans);
+ post("input device %d, channels %d", pa_indev, inchans);
+ post("output device %d, channels %d", pa_outdev, outchans);
post("framesperbuf %d, nbufs %d", framesperbuf, nbuffers);
}
- if (inchans && outchans)
- err = OpenAudioStream( &pa_stream, rate, paFloat32,
- PABLIO_READ_WRITE, inchans, framesperbuf, nbuffers,
- pa_indev, pa_outdev);
- else if (inchans)
+ if (inchans || outchans)
err = OpenAudioStream( &pa_stream, rate, paFloat32,
- PABLIO_READ, inchans, framesperbuf, nbuffers,
- pa_indev, pa_outdev);
- else if (outchans)
- err = OpenAudioStream( &pa_stream, rate, paFloat32,
- PABLIO_WRITE, outchans, framesperbuf, nbuffers,
- pa_indev, pa_outdev);
+ inchans, outchans, framesperbuf, nbuffers,
+ pa_indev, pa_outdev);
else err = 0;
if ( err != paNoError )
{
- fprintf( stderr, "Error number %d occured opening portaudio stream\n",
- err);
- fprintf( stderr, "Error message: %s\n", Pa_GetErrorText( err ) );
- Pa_Terminate();
- sys_inchannels = sys_outchannels = 0;
- return (1);
+ fprintf( stderr, "Error number %d occured opening portaudio stream\n",
+ err);
+ fprintf( stderr, "Error message: %s\n", Pa_GetErrorText( err ) );
+ Pa_Terminate();
+ sys_inchannels = sys_outchannels = 0;
+ return (1);
}
else if (sys_verbose)
- post("... opened OK.");
+ post("... opened OK.");
pa_inchans = inchans;
pa_outchans = outchans;
pa_soundin = soundin;
@@ -142,7 +131,7 @@ int pa_open_audio(int inchans, int outchans, int rate, t_sample *soundin,
void pa_close_audio( void)
{
if (pa_inchans || pa_outchans)
- CloseAudioStream( pa_stream );
+ CloseAudioStream( pa_stream );
pa_inchans = pa_outchans = 0;
}
@@ -182,43 +171,43 @@ int pa_send_dacs(void)
}
if (pa_inchans)
{
- ReadAudioStream(pa_stream, samples, DEFDACBLKSIZE);
- for (j = 0, fp1 = pa_soundin; j < pa_inchans; j++, fp1 += DEFDACBLKSIZE)
- for (i = 0, fp2 = samples + j; i < DEFDACBLKSIZE; i++,
- fp2 += pa_inchans)
- {
- fp1[i] = *fp2;
- }
+ ReadAudioStream(pa_stream, samples, DEFDACBLKSIZE);
+ for (j = 0, fp1 = pa_soundin; j < pa_inchans; j++, fp1 += DEFDACBLKSIZE)
+ for (i = 0, fp2 = samples + j; i < DEFDACBLKSIZE; i++,
+ fp2 += pa_inchans)
+ {
+ fp1[i] = *fp2;
+ }
}
#if 0
- {
- static int nread;
- if (nread == 0)
- {
- post("it's %f %f %f %f",
- pa_soundin[0], pa_soundin[1], pa_soundin[2], pa_soundin[3]);
- nread = 1000;
- }
- nread--;
- }
+ {
+ static int nread;
+ if (nread == 0)
+ {
+ post("it's %f %f %f %f",
+ pa_soundin[0], pa_soundin[1], pa_soundin[2], pa_soundin[3]);
+ nread = 1000;
+ }
+ nread--;
+ }
#endif
if (pa_outchans)
{
- for (j = 0, fp1 = pa_soundout; j < pa_outchans; j++,
- fp1 += DEFDACBLKSIZE)
- for (i = 0, fp2 = samples + j; i < DEFDACBLKSIZE; i++,
- fp2 += pa_outchans)
- {
- *fp2 = fp1[i];
+ for (j = 0, fp1 = pa_soundout; j < pa_outchans; j++,
+ fp1 += DEFDACBLKSIZE)
+ for (i = 0, fp2 = samples + j; i < DEFDACBLKSIZE; i++,
+ fp2 += pa_outchans)
+ {
+ *fp2 = fp1[i];
fp1[i] = 0;
- }
- WriteAudioStream(pa_stream, samples, DEFDACBLKSIZE);
+ }
+ WriteAudioStream(pa_stream, samples, DEFDACBLKSIZE);
}
if (sys_getrealtime() > timebefore + 0.002)
{
/* post("slept"); */
- return (SENDDACS_SLEPT);
+ return (SENDDACS_SLEPT);
}
else return (SENDDACS_YES);
}
@@ -231,26 +220,33 @@ void pa_listdevs(void) /* lifted from pa_devs.c in portaudio */
const PaDeviceInfo *pdi;
PaError err;
Pa_Initialize();
- numDevices = Pa_CountDevices();
+ numDevices = Pa_GetDeviceCount();
if( numDevices < 0 )
{
- fprintf(stderr, "ERROR: Pa_CountDevices returned 0x%x\n", numDevices );
- err = numDevices;
- goto error;
+ fprintf(stderr, "ERROR: Pa_GetDeviceCount returned %d\n", numDevices );
+ err = numDevices;
+ goto error;
}
fprintf(stderr, "Audio Devices:\n");
for( i=0; i<numDevices; i++ )
{
- pdi = Pa_GetDeviceInfo( i );
- fprintf(stderr, "device %d:", i+1 );
- fprintf(stderr, " %s;", pdi->name );
- fprintf(stderr, "%d inputs, ", pdi->maxInputChannels );
- fprintf(stderr, "%d outputs", pdi->maxOutputChannels );
- if ( i == Pa_GetDefaultInputDevice() )
- fprintf(stderr, " (Default Input)");
- if ( i == Pa_GetDefaultOutputDevice() )
- fprintf(stderr, " (Default Output)");
- fprintf(stderr, "\n");
+ pdi = Pa_GetDeviceInfo( i );
+ fprintf(stderr, "device %d:", i+1 );
+ fprintf(stderr, " %s;", pdi->name );
+ fprintf(stderr, "%d inputs, ", pdi->maxInputChannels );
+ fprintf(stderr, "%d outputs", pdi->maxOutputChannels );
+#ifdef PA19
+ if ( i == Pa_GetDefaultInputDevice() )
+ fprintf(stderr, " (Default Input)");
+ if ( i == Pa_GetDefaultOutputDevice() )
+ fprintf(stderr, " (Default Output)");
+#else
+ if ( i == Pa_GetDefaultInputDeviceID() )
+ fprintf(stderr, " (Default Input)");
+ if ( i == Pa_GetDefaultOutputDeviceID() )
+ fprintf(stderr, " (Default Output)");
+#endif
+ fprintf(stderr, "\n");
}
fprintf(stderr, "\n");
@@ -266,26 +262,26 @@ error:
/* scanning for devices */
void pa_getdevs(char *indevlist, int *nindevs,
char *outdevlist, int *noutdevs, int *canmulti,
- int maxndev, int devdescsize)
+ int maxndev, int devdescsize)
{
int i, nin = 0, nout = 0, ndev;
*canmulti = 1; /* one dev each for input and output */
Pa_Initialize();
- ndev = Pa_CountDevices();
+ ndev = Pa_GetDeviceCount();
for (i = 0; i < ndev; i++)
{
- const PaDeviceInfo *pdi = Pa_GetDeviceInfo(i);
- if (pdi->maxInputChannels > 0 && nin < maxndev)
- {
- strcpy(indevlist + nin * devdescsize, pdi->name);
- nin++;
- }
- if (pdi->maxOutputChannels > 0 && nout < maxndev)
- {
- strcpy(outdevlist + nout * devdescsize, pdi->name);
- nout++;
- }
+ const PaDeviceInfo *pdi = Pa_GetDeviceInfo(i);
+ if (pdi->maxInputChannels > 0 && nin < maxndev)
+ {
+ strcpy(indevlist + nin * devdescsize, pdi->name);
+ nin++;
+ }
+ if (pdi->maxOutputChannels > 0 && nout < maxndev)
+ {
+ strcpy(outdevlist + nout * devdescsize, pdi->name);
+ nout++;
+ }
}
*nindevs = nin;
*noutdevs = nout;
diff --git a/pd/src/s_audio_pablio.c b/pd/src/s_audio_pablio.c
new file mode 100644
index 00000000..d0438b0f
--- /dev/null
+++ b/pd/src/s_audio_pablio.c
@@ -0,0 +1,404 @@
+/*
+ * $Id: s_audio_pablio.c,v 1.1 2004-09-06 20:20:35 millerpuckette Exp $
+ * pablio.c
+ * Portable Audio Blocking Input/Output utility.
+ *
+ * Author: Phil Burk, http://www.softsynth.com
+ *
+ * This program uses the PortAudio Portable Audio Library.
+ * For more information see: http://www.audiomulch.com/portaudio/
+ * Copyright (c) 1999-2000 Ross Bencina and Phil Burk
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * Any person wishing to distribute modifications to the Software is
+ * requested to send the modifications to the original developer so that
+ * they can be incorporated into the canonical version.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
+ * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ */
+
+ /* changes by Miller Puckette to support Pd: device selection,
+ settable audio buffer size, and settable number of channels.
+ LATER also fix it to poll for input and output fifo fill points. */
+#include <stdio.h>
+#include <stdlib.h>
+#include <math.h>
+#include "portaudio.h"
+#include "s_audio_paring.h"
+#include "s_audio_pablio.h" /* MSP */
+#include <string.h>
+
+ /* MSP -- FRAMES_PER_BUFFER constant removed */
+static void NPa_Sleep(int n) /* MSP wrapper to check we never stall... */
+{
+#if 0
+ fprintf(stderr, "sleep\n");
+#endif
+ Pa_Sleep(n);
+}
+
+/************************************************************************/
+/******** Prototypes ****************************************************/
+/************************************************************************/
+
+#ifdef PA19
+static int blockingIOCallback( const void *inputBuffer, void *outputBuffer, /*MSP */
+ unsigned long framesPerBuffer,
+ const PaStreamCallbackTimeInfo *outTime,
+ PaStreamCallbackFlags myflags,
+ void *userData );
+#else
+static int blockingIOCallback( void *inputBuffer, void *outputBuffer,
+ unsigned long framesPerBuffer,
+ PaTimestamp outTime, void *userData );
+#endif
+static PaError PABLIO_InitFIFO( RingBuffer *rbuf, long numFrames, long bytesPerFrame );
+static PaError PABLIO_TermFIFO( RingBuffer *rbuf );
+
+/************************************************************************/
+/******** Functions *****************************************************/
+/************************************************************************/
+
+/* Called from PortAudio.
+ * Read and write data only if there is room in FIFOs.
+ */
+#ifdef PA19
+static int blockingIOCallback( const void *inputBuffer, void *outputBuffer, /* MSP */
+ unsigned long framesPerBuffer,
+ const PaStreamCallbackTimeInfo *outTime,
+ PaStreamCallbackFlags myflags,
+ void *userData )
+#else
+static int blockingIOCallback( void *inputBuffer, void *outputBuffer,
+ unsigned long framesPerBuffer,
+ PaTimestamp outTime, void *userData )
+#endif
+{
+ PABLIO_Stream *data = (PABLIO_Stream*)userData;
+ (void) outTime;
+
+ /* This may get called with NULL inputBuffer during initial setup. */
+ if( inputBuffer != NULL )
+ {
+ RingBuffer_Write( &data->inFIFO, inputBuffer,
+ data->inbytesPerFrame * framesPerBuffer );
+ }
+ if( outputBuffer != NULL )
+ {
+ int i;
+ int numBytes = data->outbytesPerFrame * framesPerBuffer;
+ int numRead = RingBuffer_Read( &data->outFIFO, outputBuffer,
+ numBytes);
+ /* Zero out remainder of buffer if we run out of data. */
+ for( i=numRead; i<numBytes; i++ )
+ {
+ ((char *)outputBuffer)[i] = 0;
+ }
+ }
+
+ return 0;
+}
+
+/* Allocate buffer. */
+static PaError PABLIO_InitFIFO( RingBuffer *rbuf, long numFrames, long bytesPerFrame )
+{
+ long numBytes = numFrames * bytesPerFrame;
+ char *buffer = (char *) malloc( numBytes );
+ if( buffer == NULL ) return paInsufficientMemory;
+ memset( buffer, 0, numBytes );
+ return (PaError) RingBuffer_Init( rbuf, numBytes, buffer );
+}
+
+/* Free buffer. */
+static PaError PABLIO_TermFIFO( RingBuffer *rbuf )
+{
+ if( rbuf->buffer ) free( rbuf->buffer );
+ rbuf->buffer = NULL;
+ return paNoError;
+}
+
+/************************************************************
+ * Write data to ring buffer.
+ * Will not return until all the data has been written.
+ */
+long WriteAudioStream( PABLIO_Stream *aStream, void *data, long numFrames )
+{
+ long bytesWritten;
+ char *p = (char *) data;
+ long numBytes = aStream->outbytesPerFrame * numFrames;
+ while( numBytes > 0)
+ {
+ bytesWritten = RingBuffer_Write( &aStream->outFIFO, p, numBytes );
+ numBytes -= bytesWritten;
+ p += bytesWritten;
+ if( numBytes > 0) NPa_Sleep(10); /* MSP */
+ }
+ return numFrames;
+}
+
+/************************************************************
+ * Read data from ring buffer.
+ * Will not return until all the data has been read.
+ */
+long ReadAudioStream( PABLIO_Stream *aStream, void *data, long numFrames )
+{
+ long bytesRead;
+ char *p = (char *) data;
+ long numBytes = aStream->inbytesPerFrame * numFrames;
+ while( numBytes > 0)
+ {
+ bytesRead = RingBuffer_Read( &aStream->inFIFO, p, numBytes );
+ numBytes -= bytesRead;
+ p += bytesRead;
+ if( numBytes > 0) NPa_Sleep(10); /* MSP */
+ }
+ return numFrames;
+}
+
+/************************************************************
+ * Return the number of frames that could be written to the stream without
+ * having to wait.
+ */
+long GetAudioStreamWriteable( PABLIO_Stream *aStream )
+{
+ int bytesEmpty = RingBuffer_GetWriteAvailable( &aStream->outFIFO );
+ return bytesEmpty / aStream->outbytesPerFrame;
+}
+
+/************************************************************
+ * Return the number of frames that are available to be read from the
+ * stream without having to wait.
+ */
+long GetAudioStreamReadable( PABLIO_Stream *aStream )
+{
+ int bytesFull = RingBuffer_GetReadAvailable( &aStream->inFIFO );
+ return bytesFull / aStream->inbytesPerFrame;
+}
+
+/************************************************************/
+static unsigned long RoundUpToNextPowerOf2( unsigned long n )
+{
+ long numBits = 0;
+ if( ((n-1) & n) == 0) return n; /* Already Power of two. */
+ while( n > 0 )
+ {
+ n= n>>1;
+ numBits++;
+ }
+ return (1<<numBits);
+}
+
+/************************************************************
+ * Opens a PortAudio stream with default characteristics.
+ * Allocates PABLIO_Stream structure.
+ *
+ * flags parameter can be an ORed combination of:
+ * PABLIO_READ, PABLIO_WRITE, or PABLIO_READ_WRITE
+ */
+PaError OpenAudioStream( PABLIO_Stream **rwblPtr, double sampleRate,
+ PaSampleFormat format, int inchannels,
+ int outchannels, int framesperbuf, int nbuffers,
+ int indeviceno, int outdeviceno) /* MSP */
+{
+ long bytesPerSample;
+ long doRead = 0;
+ long doWrite = 0;
+ PaError err;
+ PABLIO_Stream *aStream;
+ long minNumBuffers;
+ long numFrames;
+#ifdef PA19
+ PaStreamParameters instreamparams, outstreamparams; /* MSP */
+#endif
+
+ /* fprintf(stderr,
+ "open %lf fmt %d flags %d ch: %d fperbuf: %d nbuf: %d devs: %d %d\n",
+ sampleRate, format, flags, nchannels,
+ framesperbuf, nbuffers, indeviceno, outdeviceno); */
+
+ if (indeviceno < 0) /* MSP... */
+ {
+#ifdef PA19
+ indeviceno = Pa_GetDefaultInputDevice();
+#else
+ indeviceno = Pa_GetDefaultInputDeviceID();
+#endif
+ fprintf(stderr, "using default input device number: %d\n", indeviceno);
+ }
+ if (outdeviceno < 0)
+ {
+#ifdef PA19
+ outdeviceno = Pa_GetDefaultOutputDevice();
+#else
+ outdeviceno = Pa_GetDefaultOutputDeviceID();
+#endif
+ fprintf(stderr, "using default output device number: %d\n", outdeviceno);
+ }
+ /* fprintf(stderr, "nchan %d, flags %d, bufs %d, framesperbuf %d\n",
+ nchannels, flags, nbuffers, framesperbuf); */
+ /* ...MSP */
+
+ /* Allocate PABLIO_Stream structure for caller. */
+ aStream = (PABLIO_Stream *) malloc( sizeof(PABLIO_Stream) );
+ if( aStream == NULL ) return paInsufficientMemory;
+ memset( aStream, 0, sizeof(PABLIO_Stream) );
+
+ /* Determine size of a sample. */
+ bytesPerSample = Pa_GetSampleSize( format );
+ if( bytesPerSample < 0 )
+ {
+ err = (PaError) bytesPerSample;
+ goto error;
+ }
+ aStream->insamplesPerFrame = inchannels; /* MSP */
+ aStream->inbytesPerFrame = bytesPerSample * aStream->insamplesPerFrame;
+ aStream->outsamplesPerFrame = outchannels;
+ aStream->outbytesPerFrame = bytesPerSample * aStream->outsamplesPerFrame;
+
+ /* Initialize PortAudio */
+ err = Pa_Initialize();
+ if( err != paNoError ) goto error;
+
+#ifdef PA19
+ numFrames = nbuffers * framesperbuf; /* ...MSP */
+
+ instreamparams.device = indeviceno; /* MSP... */
+ instreamparams.channelCount = inchannels;
+ instreamparams.sampleFormat = format;
+ instreamparams.suggestedLatency = nbuffers*framesperbuf/sampleRate;
+ instreamparams.hostApiSpecificStreamInfo = 0;
+
+ outstreamparams.device = outdeviceno;
+ outstreamparams.channelCount = outchannels;
+ outstreamparams.sampleFormat = format;
+ outstreamparams.suggestedLatency = nbuffers*framesperbuf/sampleRate;
+ outstreamparams.hostApiSpecificStreamInfo = 0; /* ... MSP */
+
+#else
+/* Warning: numFrames must be larger than amount of data processed per
+ interrupt inside PA to prevent glitches. */ /* MSP */
+ minNumBuffers = Pa_GetMinNumBuffers(framesperbuf, sampleRate);
+ if (minNumBuffers > nbuffers)
+ fprintf(stderr,
+ "warning: number of buffers %d less than recommended minimum %d\n",
+ (int)nbuffers, (int)minNumBuffers);
+#endif
+
+
+ numFrames = nbuffers * framesperbuf;
+ /* fprintf(stderr, "numFrames %d\n", numFrames); */
+ /* Initialize Ring Buffers */
+ doRead = (inchannels != 0);
+ doWrite = (outchannels != 0);
+ if(doRead)
+ {
+ err = PABLIO_InitFIFO( &aStream->inFIFO, numFrames,
+ aStream->inbytesPerFrame );
+ if( err != paNoError ) goto error;
+ }
+ if(doWrite)
+ {
+ long numBytes;
+ err = PABLIO_InitFIFO( &aStream->outFIFO, numFrames,
+ aStream->outbytesPerFrame );
+ if( err != paNoError ) goto error;
+ /* Make Write FIFO appear full initially. */
+ numBytes = RingBuffer_GetWriteAvailable( &aStream->outFIFO );
+ RingBuffer_AdvanceWriteIndex( &aStream->outFIFO, numBytes );
+ }
+
+ /* Open a PortAudio stream that we will use to communicate with the underlying
+ * audio drivers. */
+#ifdef PA19
+ err = Pa_OpenStream(
+ &aStream->stream,
+ (doRead ? &instreamparams : 0), /* MSP */
+ (doWrite ? &outstreamparams : 0), /* MSP */
+ sampleRate,
+ framesperbuf, /* MSP */
+ paNoFlag, /* MSP -- portaudio will clip for us */
+ blockingIOCallback,
+ aStream );
+#else
+ err = Pa_OpenStream(
+ &aStream->stream,
+ (doRead ? indeviceno : paNoDevice), /* MSP */
+ (doRead ? aStream->insamplesPerFrame : 0 ),
+ format,
+ NULL,
+ (doWrite ? outdeviceno : paNoDevice), /* MSP */
+ (doWrite ? aStream->outsamplesPerFrame : 0 ),
+ format,
+ NULL,
+ sampleRate,
+ framesperbuf, /* MSP */
+ nbuffers, /* MSP */
+ paNoFlag, /* MSP -- portaudio will clip for us */
+ blockingIOCallback,
+ aStream );
+#endif
+ if( err != paNoError ) goto error;
+
+ err = Pa_StartStream( aStream->stream );
+ if( err != paNoError ) /* MSP */
+ {
+ fprintf(stderr, "Pa_StartStream failed; closing audio stream...\n");
+ CloseAudioStream( aStream );
+ goto error;
+ }
+
+ *rwblPtr = aStream;
+ return paNoError;
+
+error:
+ *rwblPtr = NULL;
+ return err;
+}
+
+/************************************************************/
+PaError CloseAudioStream( PABLIO_Stream *aStream )
+{
+ PaError err;
+ int bytesEmpty;
+ int byteSize = aStream->outFIFO.bufferSize;
+
+ /* If we are writing data, make sure we play everything written. */
+ if( byteSize > 0 )
+ {
+ bytesEmpty = RingBuffer_GetWriteAvailable( &aStream->outFIFO );
+ while( bytesEmpty < byteSize )
+ {
+ NPa_Sleep( 10 ); /* MSP */
+ bytesEmpty = RingBuffer_GetWriteAvailable( &aStream->outFIFO );
+ }
+ }
+
+ err = Pa_StopStream( aStream->stream );
+ if( err != paNoError ) goto error;
+ err = Pa_CloseStream( aStream->stream );
+ if( err != paNoError ) goto error;
+ Pa_Terminate();
+
+error:
+ PABLIO_TermFIFO( &aStream->inFIFO );
+ PABLIO_TermFIFO( &aStream->outFIFO );
+ free( aStream );
+ return err;
+}
diff --git a/pd/src/s_audio_pablio.h b/pd/src/s_audio_pablio.h
new file mode 100644
index 00000000..052ffedb
--- /dev/null
+++ b/pd/src/s_audio_pablio.h
@@ -0,0 +1,112 @@
+#ifndef _PABLIO_H
+#define _PABLIO_H
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif /* __cplusplus */
+
+/*
+ * $Id: s_audio_pablio.h,v 1.1 2004-09-06 20:20:35 millerpuckette Exp $
+ * PABLIO.h
+ * Portable Audio Blocking read/write utility.
+ *
+ * Author: Phil Burk, http://www.softsynth.com/portaudio/
+ *
+ * Include file for PABLIO, the Portable Audio Blocking I/O Library.
+ * PABLIO is built on top of PortAudio, the Portable Audio Library.
+ * For more information see: http://www.audiomulch.com/portaudio/
+ * Copyright (c) 1999-2000 Ross Bencina and Phil Burk
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * Any person wishing to distribute modifications to the Software is
+ * requested to send the modifications to the original developer so that
+ * they can be incorporated into the canonical version.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
+ * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ */
+#include <stdio.h>
+#include <stdlib.h>
+#include <math.h>
+#include "portaudio.h"
+#include "ringbuffer.h"
+#include <string.h>
+
+typedef struct
+{
+ RingBuffer inFIFO;
+ RingBuffer outFIFO;
+ PaStream *stream;
+ int inbytesPerFrame;
+ int insamplesPerFrame;
+ int outbytesPerFrame;
+ int outsamplesPerFrame;
+}
+PABLIO_Stream;
+
+/* Values for flags for OpenAudioStream(). */
+#define PABLIO_READ (1<<0)
+#define PABLIO_WRITE (1<<1)
+#define PABLIO_READ_WRITE (PABLIO_READ|PABLIO_WRITE)
+#define PABLIO_MONO (1<<2)
+#define PABLIO_STEREO (1<<3)
+
+/************************************************************
+ * Write data to ring buffer.
+ * Will not return until all the data has been written.
+ */
+long WriteAudioStream( PABLIO_Stream *aStream, void *data, long numFrames );
+
+/************************************************************
+ * Read data from ring buffer.
+ * Will not return until all the data has been read.
+ */
+long ReadAudioStream( PABLIO_Stream *aStream, void *data, long numFrames );
+
+/************************************************************
+ * Return the number of frames that could be written to the stream without
+ * having to wait.
+ */
+long GetAudioStreamWriteable( PABLIO_Stream *aStream );
+
+/************************************************************
+ * Return the number of frames that are available to be read from the
+ * stream without having to wait.
+ */
+long GetAudioStreamReadable( PABLIO_Stream *aStream );
+
+/************************************************************
+ * Opens a PortAudio stream with default characteristics.
+ * Allocates PABLIO_Stream structure.
+ *
+ * flags parameter can be an ORed combination of:
+ * PABLIO_READ, PABLIO_WRITE, or PABLIO_READ_WRITE,
+ */
+PaError OpenAudioStream( PABLIO_Stream **rwblPtr, double sampleRate,
+ PaSampleFormat format, int inchannels,
+ int outchannels, int framesperbuf, int nbuffers,
+ int indeviceno, int outdeviceno); /* MSP */
+
+PaError CloseAudioStream( PABLIO_Stream *aStream );
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+#endif /* _PABLIO_H */
diff --git a/pd/src/s_audio_paring.c b/pd/src/s_audio_paring.c
new file mode 100644
index 00000000..cbb999e8
--- /dev/null
+++ b/pd/src/s_audio_paring.c
@@ -0,0 +1,217 @@
+/*
+ * $Id: s_audio_paring.c,v 1.1 2004-09-06 20:20:35 millerpuckette Exp $
+ * ringbuffer.c
+ * Ring Buffer utility..
+ *
+ * Author: Phil Burk, http://www.softsynth.com
+ *
+ * This program uses the PortAudio Portable Audio Library.
+ * For more information see: http://www.audiomulch.com/portaudio/
+ * Copyright (c) 1999-2000 Ross Bencina and Phil Burk
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * Any person wishing to distribute modifications to the Software is
+ * requested to send the modifications to the original developer so that
+ * they can be incorporated into the canonical version.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
+ * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ */
+/*
+ * modified 2002/07/13 by olaf.matthes@gmx.de to allow any number if channels
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <math.h>
+#include "s_audio_paring.h"
+#include <string.h>
+
+/***************************************************************************
+ * Initialize FIFO.
+ */
+long RingBuffer_Init( RingBuffer *rbuf, long numBytes, void *dataPtr )
+{
+ rbuf->bufferSize = numBytes;
+ rbuf->buffer = (char *)dataPtr;
+ RingBuffer_Flush( rbuf );
+ return 0;
+}
+/***************************************************************************
+** Return number of bytes available for reading. */
+long RingBuffer_GetReadAvailable( RingBuffer *rbuf )
+{
+ long ret = rbuf->writeIndex - rbuf->readIndex;
+ if (ret < 0)
+ ret += 2 * rbuf->bufferSize;
+ if (ret < 0 || ret > rbuf->bufferSize)
+ fprintf(stderr,
+ "consistency check failed: RingBuffer_GetReadAvailable\n");
+ return ( ret );
+}
+/***************************************************************************
+** Return number of bytes available for writing. */
+long RingBuffer_GetWriteAvailable( RingBuffer *rbuf )
+{
+ return ( rbuf->bufferSize - RingBuffer_GetReadAvailable(rbuf));
+}
+
+/***************************************************************************
+** Clear buffer. Should only be called when buffer is NOT being read. */
+void RingBuffer_Flush( RingBuffer *rbuf )
+{
+ rbuf->writeIndex = rbuf->readIndex = 0;
+}
+
+/***************************************************************************
+** Get address of region(s) to which we can write data.
+** If the region is contiguous, size2 will be zero.
+** If non-contiguous, size2 will be the size of second region.
+** Returns room available to be written or numBytes, whichever is smaller.
+*/
+long RingBuffer_GetWriteRegions( RingBuffer *rbuf, long numBytes,
+ void **dataPtr1, long *sizePtr1,
+ void **dataPtr2, long *sizePtr2 )
+{
+ long index;
+ long available = RingBuffer_GetWriteAvailable( rbuf );
+ if( numBytes > available ) numBytes = available;
+ /* Check to see if write is not contiguous. */
+ index = rbuf->writeIndex;
+ while (index >= rbuf->bufferSize)
+ index -= rbuf->bufferSize;
+ if( (index + numBytes) > rbuf->bufferSize )
+ {
+ /* Write data in two blocks that wrap the buffer. */
+ long firstHalf = rbuf->bufferSize - index;
+ *dataPtr1 = &rbuf->buffer[index];
+ *sizePtr1 = firstHalf;
+ *dataPtr2 = &rbuf->buffer[0];
+ *sizePtr2 = numBytes - firstHalf;
+ }
+ else
+ {
+ *dataPtr1 = &rbuf->buffer[index];
+ *sizePtr1 = numBytes;
+ *dataPtr2 = NULL;
+ *sizePtr2 = 0;
+ }
+ return numBytes;
+}
+
+
+/***************************************************************************
+*/
+long RingBuffer_AdvanceWriteIndex( RingBuffer *rbuf, long numBytes )
+{
+ long ret = (rbuf->writeIndex + numBytes);
+ if ( ret >= 2 * rbuf->bufferSize)
+ ret -= 2 * rbuf->bufferSize; /* check for end of buffer */
+ return rbuf->writeIndex = ret;
+}
+
+/***************************************************************************
+** Get address of region(s) from which we can read data.
+** If the region is contiguous, size2 will be zero.
+** If non-contiguous, size2 will be the size of second region.
+** Returns room available to be written or numBytes, whichever is smaller.
+*/
+long RingBuffer_GetReadRegions( RingBuffer *rbuf, long numBytes,
+ void **dataPtr1, long *sizePtr1,
+ void **dataPtr2, long *sizePtr2 )
+{
+ long index;
+ long available = RingBuffer_GetReadAvailable( rbuf );
+ if( numBytes > available ) numBytes = available;
+ /* Check to see if read is not contiguous. */
+ index = rbuf->readIndex;
+ while (index >= rbuf->bufferSize)
+ index -= rbuf->bufferSize;
+
+ if( (index + numBytes) > rbuf->bufferSize )
+ {
+ /* Write data in two blocks that wrap the buffer. */
+ long firstHalf = rbuf->bufferSize - index;
+ *dataPtr1 = &rbuf->buffer[index];
+ *sizePtr1 = firstHalf;
+ *dataPtr2 = &rbuf->buffer[0];
+ *sizePtr2 = numBytes - firstHalf;
+ }
+ else
+ {
+ *dataPtr1 = &rbuf->buffer[index];
+ *sizePtr1 = numBytes;
+ *dataPtr2 = NULL;
+ *sizePtr2 = 0;
+ }
+ return numBytes;
+}
+/***************************************************************************
+*/
+long RingBuffer_AdvanceReadIndex( RingBuffer *rbuf, long numBytes )
+{
+ long ret = (rbuf->readIndex + numBytes);
+ if( ret >= 2 * rbuf->bufferSize)
+ ret -= 2 * rbuf->bufferSize;
+ return rbuf->readIndex = ret;
+}
+
+/***************************************************************************
+** Return bytes written. */
+long RingBuffer_Write( RingBuffer *rbuf, const void *data, long numBytes )
+{
+ long size1, size2, numWritten;
+ void *data1, *data2;
+ numWritten = RingBuffer_GetWriteRegions( rbuf, numBytes, &data1, &size1, &data2, &size2 );
+ if( size2 > 0 )
+ {
+
+ memcpy( data1, data, size1 );
+ data = ((char *)data) + size1;
+ memcpy( data2, data, size2 );
+ }
+ else
+ {
+ memcpy( data1, data, size1 );
+ }
+ RingBuffer_AdvanceWriteIndex( rbuf, numWritten );
+ return numWritten;
+}
+
+/***************************************************************************
+** Return bytes read. */
+long RingBuffer_Read( RingBuffer *rbuf, void *data, long numBytes )
+{
+ long size1, size2, numRead;
+ void *data1, *data2;
+ numRead = RingBuffer_GetReadRegions( rbuf, numBytes, &data1, &size1, &data2, &size2 );
+ if( size2 > 0 )
+ {
+ memcpy( data, data1, size1 );
+ data = ((char *)data) + size1;
+ memcpy( data, data2, size2 );
+ }
+ else
+ {
+ memcpy( data, data1, size1 );
+ }
+ RingBuffer_AdvanceReadIndex( rbuf, numRead );
+ return numRead;
+}
diff --git a/pd/src/s_audio_paring.h b/pd/src/s_audio_paring.h
new file mode 100644
index 00000000..9eca10b1
--- /dev/null
+++ b/pd/src/s_audio_paring.h
@@ -0,0 +1,102 @@
+#ifndef _RINGBUFFER_H
+#define _RINGBUFFER_H
+#ifdef __cplusplus
+extern "C"
+{
+#endif /* __cplusplus */
+
+/*
+ * $Id: s_audio_paring.h,v 1.1 2004-09-06 20:20:35 millerpuckette Exp $
+ * ringbuffer.h
+ * Ring Buffer utility..
+ *
+ * Author: Phil Burk, http://www.softsynth.com
+ *
+ * This program is distributed with the PortAudio Portable Audio Library.
+ * For more information see: http://www.audiomulch.com/portaudio/
+ * Copyright (c) 1999-2000 Ross Bencina and Phil Burk
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * Any person wishing to distribute modifications to the Software is
+ * requested to send the modifications to the original developer so that
+ * they can be incorporated into the canonical version.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
+ * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ */
+#include <stdio.h>
+#include <stdlib.h>
+#include <math.h>
+#include "ringbuffer.h"
+#include <string.h>
+
+typedef struct
+{
+ long bufferSize; /* Number of bytes in FIFO. Power of 2. Set by RingBuffer_Init. */
+/* These are declared volatile because they are written by a different thread than the reader. */
+ volatile long writeIndex; /* Index of next writable byte. Set by RingBuffer_AdvanceWriteIndex. */
+ volatile long readIndex; /* Index of next readable byte. Set by RingBuffer_AdvanceReadIndex. */
+ long bigMask; /* Used for wrapping indices with extra bit to distinguish full/empty. */
+ long smallMask; /* Used for fitting indices to buffer. */
+ char *buffer;
+}
+RingBuffer;
+/*
+ * Initialize Ring Buffer.
+ * numBytes must be power of 2, returns -1 if not.
+ */
+long RingBuffer_Init( RingBuffer *rbuf, long numBytes, void *dataPtr );
+
+/* Clear buffer. Should only be called when buffer is NOT being read. */
+void RingBuffer_Flush( RingBuffer *rbuf );
+
+/* Return number of bytes available for writing. */
+long RingBuffer_GetWriteAvailable( RingBuffer *rbuf );
+/* Return number of bytes available for read. */
+long RingBuffer_GetReadAvailable( RingBuffer *rbuf );
+/* Return bytes written. */
+long RingBuffer_Write( RingBuffer *rbuf, const void *data, long numBytes );
+/* Return bytes read. */
+long RingBuffer_Read( RingBuffer *rbuf, void *data, long numBytes );
+
+/* Get address of region(s) to which we can write data.
+** If the region is contiguous, size2 will be zero.
+** If non-contiguous, size2 will be the size of second region.
+** Returns room available to be written or numBytes, whichever is smaller.
+*/
+long RingBuffer_GetWriteRegions( RingBuffer *rbuf, long numBytes,
+ void **dataPtr1, long *sizePtr1,
+ void **dataPtr2, long *sizePtr2 );
+long RingBuffer_AdvanceWriteIndex( RingBuffer *rbuf, long numBytes );
+
+/* Get address of region(s) from which we can read data.
+** If the region is contiguous, size2 will be zero.
+** If non-contiguous, size2 will be the size of second region.
+** Returns room available to be read or numBytes, whichever is smaller.
+*/
+long RingBuffer_GetReadRegions( RingBuffer *rbuf, long numBytes,
+ void **dataPtr1, long *sizePtr1,
+ void **dataPtr2, long *sizePtr2 );
+
+long RingBuffer_AdvanceReadIndex( RingBuffer *rbuf, long numBytes );
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+#endif /* _RINGBUFFER_H */
diff --git a/pd/src/s_audio_sgi.c b/pd/src/s_audio_sgi.c
new file mode 100644
index 00000000..26ebdc81
--- /dev/null
+++ b/pd/src/s_audio_sgi.c
@@ -0,0 +1,460 @@
+
+/* ----------------------- Experimental routines for SGI -------------- */
+
+/* written by Olaf Matthes <olaf.matthes@gmx.de> */
+
+#ifdef USEAPI_SGI
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <m_pd.h>
+#include <s_stuff.h>
+
+#include <dmedia/audio.h>
+#include <dmedia/midi.h>
+#include <sys/fpu.h>
+#include <errno.h>
+
+#define SGI_MAXDEV 4 /* it's just 3, but default counts as well... */
+#define SGI_MAXCH 12 /* max. number of channels - is this enough? */
+
+static ALport sgi_iport[SGI_MAXDEV];
+static ALport sgi_oport[SGI_MAXDEV];
+static ALconfig sgi_inconfig;
+static ALconfig sgi_outconfig;
+static int sgi_nindevs, sgi_noutdevs;
+static int sgi_inchannels, sgi_outchannels;
+static int sgi_ninchans[SGI_MAXDEV], sgi_noutchans[SGI_MAXDEV];
+
+
+ /*
+ set the special "flush zero" but (FS, bit 24) in the
+ Control Status Register of the FPU of R4k and beyond
+ so that the result of any underflowing operation will
+ be clamped to zero, and no exception of any kind will
+ be generated on the CPU.
+
+ thanks to cpirazzi@cp.esd.sgi.com (Chris Pirazzi).
+ */
+
+static void sgi_flush_all_underflows_to_zero(void)
+{
+ union fpc_csr f;
+ f.fc_word = get_fpc_csr();
+ f.fc_struct.flush = 1;
+ set_fpc_csr(f.fc_word);
+}
+
+
+ /* convert the most common errors into readable strings */
+static char *sgi_get_error_message(int err)
+{
+ switch (err)
+ {
+ case AL_BAD_CONFIG:
+ return "Invalid config";
+
+ case AL_BAD_DIRECTION:
+ return "Invalid direction (neither \"r\" nor \"w\")";
+
+ case AL_BAD_OUT_OF_MEM:
+ return "Not enough memory";
+
+ case AL_BAD_DEVICE_ACCESS:
+ return "Audio hardware is not available or is improperly configured";
+
+ case AL_BAD_DEVICE:
+ return "Invalid device";
+
+ case AL_BAD_NO_PORTS:
+ return "No audio ports available";
+
+ case AL_BAD_QSIZE:
+ return "Invalid fifo size";
+
+ case AL_BAD_SAMPFMT:
+ return "Invalid sample format";
+
+ case AL_BAD_FLOATMAX:
+ return "Invalid float maximum";
+
+ case AL_BAD_WIDTH:
+ return "Invalid sample width";
+
+ default:
+ return "Unknown error";
+ }
+}
+
+
+int sgi_open_audio(int nindev, int *indev, int nchin, int *chin,
+ int noutdev, int *outdev, int nchout, int *chout, int rate)
+{
+ ALpv pvbuf[2];
+ int num_devs = 0;
+ int in_dev = 0;
+ int out_dev = 0;
+ int inchans = 0;
+ int outchans = 0;
+ int err, n, gotchannels;
+ char *indevnames[4] = {"DefaultIn", "AnalogIn", "AESIn", "ADATIn"};
+ char *outdevnames[4] = {"DefaultOut", "AnalogOut", "AESOut", "ADATOut"};
+
+ sgi_flush_all_underflows_to_zero();
+
+ if (sys_verbose)
+ post("opening sound input...");
+
+ for (n = 0; n < nindev; n++)
+ {
+ int gotchannels = 0;
+
+ if (indev[n] >= 0 && indev[n] < SGI_MAXDEV) /* open specified defice by name */
+ {
+ if (sys_verbose)
+ post("opening %s", indevnames[indev[n]]);
+ in_dev = alGetResourceByName(AL_SYSTEM,
+ indevnames[indev[n]], AL_DEVICE_TYPE);
+ }
+ else /* open default device */
+ {
+ if(sys_verbose)post("opening %s", indevnames[0]);
+ in_dev = AL_DEFAULT_INPUT;
+ }
+ if (!in_dev)
+ {
+ error("%s\n", sgi_get_error_message(in_dev));
+ continue; /* try next device, if any */
+ }
+
+ sgi_inconfig = alNewConfig();
+ alSetSampFmt(sgi_inconfig, AL_SAMPFMT_FLOAT);
+ alSetFloatMax(sgi_outconfig, 1.1f);
+ alSetChannels(sgi_outconfig, chin[n]);
+ alSetQueueSize(sgi_inconfig, sys_advance_samples * chin[n]);
+ alSetDevice(sgi_inconfig, in_dev);
+ sgi_iport[n] = alOpenPort("Pd input port", "r", sgi_inconfig);
+ if (!sgi_iport[n])
+ fprintf(stderr,"Pd: failed to open audio read port\n");
+
+ /* try to set samplerate */
+ pvbuf[0].param = AL_RATE;
+ pvbuf[0].value.ll = alDoubleToFixed(rate);
+ if ((err = alSetParams(in_dev, pvbuf, 1)) < 0)
+ {
+ post("could not set specified sample rate for input (%s)\n",
+ sgi_get_error_message(err));
+ if(pvbuf[0].sizeOut < 0)
+ post("rate was invalid\n");
+ }
+ /* check how many channels we actually got */
+ pvbuf[0].param = AL_CHANNELS;
+ if (alGetParams(in_dev, pvbuf, 1) < 0)
+ {
+ post("could not figure out how many input channels we got");
+ gotchannels = chin[n]; /* assume we got them all */
+ }
+ else
+ {
+ gotchannels = pvbuf[0].value.i;
+ }
+ inchans += gotchannels; /* count total number of channels */
+ sgi_ninchans[n] = gotchannels; /* remember channels for this device */
+ }
+
+ if (sys_verbose)
+ post("opening sound output...");
+
+ for (n = 0; n < noutdev; n++)
+ {
+ if (outdev[n] >= 0 && outdev[n] < SGI_MAXDEV) /* open specified defice by name */
+ {
+ if(sys_verbose)post("opening %s", outdevnames[outdev[n]]);
+ out_dev = alGetResourceByName(AL_SYSTEM,
+ outdevnames[outdev[n]], AL_DEVICE_TYPE);
+ }
+ else /* open default device */
+ {
+ if (sys_verbose)
+ post("opening %s", outdevnames[0]);
+ out_dev = AL_DEFAULT_OUTPUT;
+ }
+ if (!out_dev)
+ {
+ error("%s\n", sgi_get_error_message(out_dev));
+ continue; /* try next device, if any */
+ }
+
+ /* configure the port before opening it */
+ sgi_outconfig = alNewConfig();
+ alSetSampFmt(sgi_outconfig, AL_SAMPFMT_FLOAT);
+ alSetFloatMax(sgi_outconfig, 1.1f);
+ alSetChannels(sgi_outconfig, chout[n]);
+ alSetQueueSize(sgi_outconfig, sys_advance_samples * chout[n]);
+ alSetDevice(sgi_outconfig, out_dev);
+
+ /* open the port */
+ sgi_oport[n] = alOpenPort("Pd ouput port", "w", sgi_outconfig);
+ if (!sgi_oport[n])
+ fprintf(stderr,"Pd: failed to open audio write port\n");
+
+ /* now try to set sample rate */
+ pvbuf[0].param = AL_RATE;
+ pvbuf[0].value.ll = alDoubleToFixed(rate);
+ if ((err = alSetParams(out_dev, pvbuf, 1)) < 0)
+ {
+ post("could not set specified sample rate for output (%s)\n",
+ sgi_get_error_message(err));
+ if(pvbuf[0].sizeOut < 0)
+ post("rate was invalid\n");
+ }
+ /* check how many channels we actually got */
+ pvbuf[0].param = AL_CHANNELS;
+ if (alGetParams(out_dev, pvbuf, 1) < 0)
+ {
+ post("could not figure out how many output channels we got");
+ gotchannels = chout[n];
+ }
+ else
+ {
+ gotchannels = pvbuf[0].value.i;
+ }
+ outchans += gotchannels;
+ sgi_noutchans[n] = gotchannels;
+ }
+
+ sgi_noutdevs = noutdev;
+ sgi_nindevs = nindev;
+
+ sgi_inchannels = inchans;
+ sgi_outchannels = outchans;
+
+ return (!(inchans || outchans));
+}
+
+
+void sgi_close_audio(void)
+{
+ int err, n;
+ for (n = 0; n < sgi_nindevs; n++)
+ {
+ if (sgi_iport[n])
+ {
+ err = alClosePort(sgi_iport[n]);
+ if (err < 0)
+ error("closing input %d: %s (%d)", n + 1,
+ alGetErrorString(oserror()), err);
+ }
+ }
+ for (n = 0; n < sgi_noutdevs; n++)
+ {
+ if (sgi_oport[n])
+ {
+ err = alClosePort(sgi_oport[n]);
+ if (err < 0)
+ error("closing output %d: %s (%d)", n + 1,
+ alGetErrorString(oserror()), err);
+ }
+ }
+}
+
+
+ /* call this only if both input and output are open */
+static void sgi_checkiosync(void)
+{
+ int i, result, checkit = 1, giveup = 1000, alreadylogged = 0;
+ long indelay, outdelay, defect;
+
+ if (!(sgi_outchannels && sgi_inchannels))
+ return;
+}
+
+
+int sgi_send_dacs(void)
+{
+ float buf[SGI_MAXCH * DEFDACBLKSIZE], *fp1, *fp2, *fp3, *fp4;
+ static int xferno = 0;
+ static int callno = 0;
+ static double timenow;
+ double timelast;
+ int inchannels = (sys_inchannels > sgi_inchannels ?
+ sgi_inchannels : sys_inchannels);
+ int outchannels = (sys_outchannels > sgi_outchannels ?
+ sgi_outchannels : sys_outchannels);
+ long outfill[SGI_MAXDEV], infill[SGI_MAXDEV];
+ int outdevchannels, indevchannels;
+ int i, n, channel;
+ int result;
+ unsigned int outtransfersize = DEFDACBLKSIZE;
+ unsigned int intransfersize = DEFDACBLKSIZE;
+
+ /* no audio channels open, return */
+ if (!inchannels && !outchannels)
+ return (SENDDACS_NO);
+
+ timelast = timenow;
+ timenow = sys_getrealtime();
+
+#ifdef DEBUG_SGI_XFER
+ if (timenow - timelast > 0.050)
+ fprintf(stderr, "(%d)",
+ (int)(1000 * (timenow - timelast))), fflush(stderr);
+#endif
+
+ callno++;
+
+ sgi_checkiosync(); /* check I/O are in sync and data not late */
+
+ /* check whether there is enough space in buffers */
+ if (sgi_nindevs)
+ {
+ for (n = 0; n < sgi_nindevs; n++)
+ {
+ if (alGetFilled(sgi_iport[n]) < intransfersize)
+ return SENDDACS_NO;
+ }
+ }
+ if (sgi_noutdevs)
+ {
+ for(n = 0; n < sgi_noutdevs; n++)
+ {
+ if (alGetFillable(sgi_oport[n]) < outtransfersize)
+ return SENDDACS_NO;
+ }
+ }
+
+ /* output audio data, if we use audio out */
+ if (sgi_noutdevs)
+ {
+ fp2 = sys_soundout; /* point to current output position in buffer */
+ for(n = 0; n < sgi_noutdevs; n++)
+ {
+ outdevchannels = sgi_noutchans[n]; /* channels supported by this device */
+
+ for (channel = 0, fp1 = buf;
+ channel < outdevchannels; channel++, fp1++, fp2 += DEFDACBLKSIZE)
+ {
+ for (i = 0, fp3 = fp1, fp4 = fp2; i < DEFDACBLKSIZE;
+ i++, fp3 += outdevchannels, fp4++)
+ *fp3 = *fp4, *fp4 = 0;
+ }
+ alWriteFrames(sgi_oport[n], buf, DEFDACBLKSIZE);
+ }
+ }
+
+ /* zero out the output buffer */
+ memset(sys_soundout, 0, DEFDACBLKSIZE * sizeof(*sys_soundout) * sys_outchannels);
+ if (sys_getrealtime() - timenow > 0.002)
+ {
+ #ifdef DEBUG_SGI_XFER
+ fprintf(stderr, "output %d took %d msec\n",
+ callno, (int)(1000 * (timenow - timelast))), fflush(stderr);
+ #endif
+ timenow = sys_getrealtime();
+ sys_log_error(ERR_DACSLEPT);
+ }
+
+ /* get audio data from input, if we use audio in */
+ if (sgi_nindevs)
+ {
+ fp2 = sys_soundin; /* point to current input position in buffer */
+ for (n = 0; n < sgi_nindevs; n++)
+ {
+ indevchannels = sgi_ninchans[n]; /* channels supported by this device */
+
+ if (alGetFilled(sgi_iport[n]) > DEFDACBLKSIZE)
+ {
+ alReadFrames(sgi_iport[n], buf, DEFDACBLKSIZE);
+ }
+ else /* have to read but nothing's there... */
+ {
+ // if (sys_verbose) post("extra ADC buf");
+ /* set buffer to silence */
+ memset(buf, 0, intransfersize * sizeof(*sys_soundout) * sgi_ninchans[n]);
+ }
+ for (channel = 0, fp1 = buf;
+ channel < indevchannels; channel++, fp1++, fp2 += DEFDACBLKSIZE)
+ {
+ for (i = 0, fp3 = fp1, fp4 = fp2; i < DEFDACBLKSIZE;
+ i++, fp3 += indevchannels, fp4++)
+ *fp4 = *fp3;
+ }
+ }
+ }
+
+ xferno++;
+
+ if (sys_getrealtime() - timenow > 0.002)
+ {
+#ifdef DEBUG_SGI_XFER
+ fprintf(stderr, "routine took %d msec\n",
+ (int)(1000 * (sys_getrealtime() - timenow)));
+#endif
+ sys_log_error(ERR_ADCSLEPT);
+ }
+ return (SENDDACS_YES);
+}
+
+void sgi_getdevs(char *indevlist, int *nindevs,
+ char *outdevlist, int *noutdevs, int *canmulti,
+ int maxndev, int devdescsize)
+{
+#if 0
+ ALpv pvs[1];
+ char name[32];
+ int i, ndev, err;
+ *canmulti = 3; /* supports multiple devices */
+
+ /* get max. number of audio ports from system */
+ pvs[0].param = AL_DEVICES;
+ err = alGetParams(AL_SYSTEM, pvs, 1);
+ if (err < 0)
+ {
+ sprintf("alGetParams failed: %s\n", alGetErrorString(oserror()));
+ }
+ ndev = pvs[0].value.i;
+
+ for (i = 0; i < ndev; i++)
+ {
+ pvs[0].param = AL_NAME; /* a string parameter */
+ pvs[0].value.ptr = name; /* the string we've allocated */
+ pvs[0].sizeIn = 32; /* the array size, in characters,
+ including space for NULL */
+ if (alGetParams(i, pvs, 1) < 0)
+ {
+ sprintf("alGetParams failed: %s\n", alGetErrorString(oserror()));
+ }
+ sprintf(indevlist + i * devdescsize, "%d: %s", i + 1, name);
+ sprintf(outdevlist + i * devdescsize, "%d: %s", i + 1, name);
+ }
+ *nindevs = ndev;
+ *noutdevs = ndev;
+#else
+ sprintf(indevlist + 0 * devdescsize, "Default In");
+ sprintf(outdevlist + 0 * devdescsize, "Default Out");
+ sprintf(indevlist + 1 * devdescsize, "Analog In");
+ sprintf(outdevlist + 1 * devdescsize, "Analog Out");
+ sprintf(indevlist + 2 * devdescsize, "AES In");
+ sprintf(outdevlist + 2 * devdescsize, "AES Out");
+ sprintf(indevlist + 3 * devdescsize, "ADAT In");
+ sprintf(outdevlist + 3 * devdescsize, "ADAT Out");
+
+ *nindevs = 4;
+ *noutdevs = 4;
+ *canmulti = 3; /* supports multiple devices */
+#endif
+}
+
+
+/* list devices: only reflect the most common setup (Octane) */
+void sgi_listaudiodevs(void)
+{
+ post("common devices on SGI machines:");
+ post("#-1 - Default In/Out selected in Audio Panel");
+ post("#1 - Analog In/Out");
+ post("#2 - AES In/Out");
+ post("#3 - ADAT I/O");
+}
+
+#endif /* SGI */
diff --git a/pd/src/s_entry.c b/pd/src/s_entry.c
index ad1e28fa..e81e45c6 100644
--- a/pd/src/s_entry.c
+++ b/pd/src/s_entry.c
@@ -5,47 +5,79 @@ that externs can link back to functions defined in pd. */
int sys_main(int argc, char **argv);
- /* WINBASEAPI PVOID WINAPI AddVectoredExceptionHandler(
- ULONG FirstHandler,
- PVECTORED_EXCEPTION_HANDLER VectoredHandler ); */
-
#ifdef MSW
-#if 0
-#incldue "winbase.h"
-
-LONG NTAPI VectoredExceptionHandler(void *PEXCEPTION_POINTERS)
-{
- fprintf(stderr, "caught exception\n");
- return(EXCEPTION_CONTINUE_SEARCH);
-}
+#include <windows.h>
+#include <stdio.h>
+#include <malloc.h>
+#define MAXARGS 1024
+#define MAXARGLEN 1024
-int main(int argc, char **argv)
+/* jsarlo { */
+int tokenizeCommandLineString(char *clString, char **tokens)
{
- printf("Pd entry point\n");
- AddVectoredExceptionHandler(
- ULONG FirstHandler,
- PVECTORED_EXCEPTION_HANDLER VectoredHandler );
-
+ int i, charCount = 0;
+ int tokCount= 0;
+ int quoteOpen = 0;
-#endif
+ for (i = 0; i < (int)strlen(clString); i++)
+ {
+ if (clString[i] == '"')
+ {
+ quoteOpen = !quoteOpen;
+ }
+ else if (clString[i] == ' ' && !quoteOpen)
+ {
+ tokens[tokCount][charCount] = 0;
+ tokCount++;
+ charCount = 0;
+ }
+ else
+ {
+ tokens[tokCount][charCount] = clString[i];
+ charCount++;
+ }
+ }
+ tokens[tokCount][charCount] = 0;
+ tokCount++;
+ return tokCount;
+}
-#if 1
-int main(int argc, char **argv)
+int WINAPI WinMain(HINSTANCE hInstance,
+ HINSTANCE hPrevInstance,
+ LPSTR lpCmdLine,
+ int nCmdShow)
{
- __try
+ int i, argc;
+ char *argv[MAXARGS];
+
+ __try
{
+ for (i = 0; i < MAXARGS; i++)
+ {
+ argv[i] = (char *)malloc(MAXARGLEN * sizeof(char));
+ }
+ GetModuleFileName(NULL, argv[0], MAXARGLEN);
+ argc = tokenizeCommandLineString(lpCmdLine, argv + 1) + 1;
sys_main(argc, argv);
+ for (i = 0; i < MAXARGS; i++)
+ {
+ free(argv[i]);
+ }
}
__finally
{
printf("caught an exception; stopping\n");
}
}
-#endif
+
+/* } jsarlo */
+
#else /* not MSW */
int main(int argc, char **argv)
{
return (sys_main(argc, argv));
}
#endif
+
+
diff --git a/pd/src/s_file.c b/pd/src/s_file.c
index 27825d59..ca0512fc 100644
--- a/pd/src/s_file.c
+++ b/pd/src/s_file.c
@@ -1,55 +1,473 @@
-/* Copyright (c) 1997-1999 Miller Puckette.
+/* Copyright (c) 1997-2004 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 contains file-handling routines.
+ * this file implements a mechanism for storing and retrieving preferences.
+ * Should later be renamed "preferences.c" or something.
+ *
+ * In unix this is handled by the "~/.pdsettings" file, in windows by
+ * the registry, and in MacOS by the Preferences system.
*/
#include "m_pd.h"
#include "s_stuff.h"
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <errno.h>
+#ifdef UNISTD
#include <sys/types.h>
#include <sys/stat.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#endif
+#ifdef MSW
+#include <windows.h>
+#include <tchar.h>
+#endif
+
+int sys_defeatrt;
+t_symbol *sys_flags = &s_;
+void sys_doflags( void);
- /* LATER delete this? -- replaced by find_via_path() in s_path.c */
-int sys_isreadablefile(const char *s)
-{
- struct stat statbuf;
- int mode;
- if (stat(s, &statbuf) < 0) return (0);
#ifdef UNIX
- mode = statbuf.st_mode;
- if (S_ISDIR(mode)) return (0);
-#endif
+
+static char *sys_prefbuf;
+static int sys_prefbufsize;
+
+static void sys_initloadpreferences( void)
+{
+ char filenamebuf[MAXPDSTRING], *homedir = getenv("HOME");
+ int fd, length;
+
+ if (!homedir)
+ return;
+ snprintf(filenamebuf, MAXPDSTRING, "%s/.pdsettings", homedir);
+ filenamebuf[MAXPDSTRING-1] = 0;
+ if ((fd = open(filenamebuf, 0)) < 0)
+ {
+ if (sys_verbose)
+ perror(filenamebuf);
+ return;
+ }
+ length = lseek(fd, 0, 2);
+ if (length < 0)
+ {
+ if (sys_verbose)
+ perror(filenamebuf);
+ close(fd);
+ return;
+ }
+ lseek(fd, 0, 0);
+ if (!(sys_prefbuf = malloc(length + 2)))
+ {
+ error("couldn't allocate memory for preferences buffer");
+ close(fd);
+ return;
+ }
+ sys_prefbuf[0] = '\n';
+ if (read(fd, sys_prefbuf+1, length) < length)
+ {
+ perror(filenamebuf);
+ sys_prefbuf[0] = 0;
+ close(fd);
+ return;
+ }
+ sys_prefbuf[length+1] = 0;
+ close(fd);
+ if (sys_verbose)
+ post("success reading preferences from: %s", filenamebuf);
+}
+
+static int sys_getpreference(const char *key, char *value, int size)
+{
+ if (!sys_prefbuf)
+ return (0);
+ char searchfor[80], *where, *whereend;
+ sprintf(searchfor, "\n%s:", key);
+ where = strstr(sys_prefbuf, searchfor);
+ if (!where)
+ return (0);
+ where += strlen(searchfor);
+ while (*where == ' ' || *where == '\t')
+ where++;
+ for (whereend = where; *whereend && *whereend != '\n'; whereend++)
+ ;
+ if (*whereend == '\n')
+ whereend--;
+ if (whereend > where + size - 1)
+ whereend = where + size - 1;
+ strncpy(value, where, whereend+1-where);
+ value[whereend+1-where] = 0;
return (1);
}
- /* change '/' characters to the system's native file separator */
-void sys_bashfilename(const char *from, char *to)
+static void sys_doneloadpreferences( void)
+{
+ if (sys_prefbuf)
+ free(sys_prefbuf);
+}
+
+static FILE *sys_prefsavefp;
+
+static void sys_initsavepreferences( void)
{
- char c;
- while (c = *from++)
+ char filenamebuf[MAXPDSTRING], errbuf[MAXPDSTRING],
+ *homedir = getenv("HOME");
+ FILE *fp;
+
+ if (!homedir)
+ return;
+ snprintf(filenamebuf, MAXPDSTRING, "%s/.pdsettings", homedir);
+ filenamebuf[MAXPDSTRING-1] = 0;
+ if ((sys_prefsavefp = fopen(filenamebuf, "w")) == NULL)
{
+ snprintf(errbuf, MAXPDSTRING, "%s: %s",filenamebuf, strerror(errno));
+ pd_error(0, errbuf);
+ }
+}
+
+static void sys_putpreference(const char *key, const char *value)
+{
+ if (sys_prefsavefp)
+ fprintf(sys_prefsavefp, "%s: %s\n",
+ key, value);
+}
+
+static void sys_donesavepreferences( void)
+{
+ if (sys_prefsavefp)
+ {
+ fclose(sys_prefsavefp);
+ sys_prefsavefp = 0;
+ }
+}
+
+#endif /* UNIX */
+
#ifdef MSW
- if (c == '/') c = '\\';
-#endif
- *to++ = c;
+
+static void sys_initloadpreferences( void)
+{
+ fprintf(stderr, "here 1\n");
+}
+
+static int sys_getpreference(const char *key, char *value, int size)
+{
+ HKEY *hkey;
+ DWORD bigsize = size;
+ char *val2 = value;
+ LONG err = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
+ "Software\\Pd", 0, KEY_QUERY_VALUE, &hkey);
+ if (err != ERROR_SUCCESS)
+ {
+ fprintf(stderr, "here 3\n");
+ return (0);
}
- *to = 0;
+ err = RegQueryValueEx(hkey, key, 0, 0, value, &bigsize);
+ if (err != ERROR_SUCCESS)
+ {
+ fprintf(stderr, "here 4\n");
+ RegCloseKey(hkey);
+ return (0);
+ }
+ fprintf(stderr, "here 5\n");
+ if (val2 != value)
+ fprintf(stderr, "string moved for registry key %s", key);
+ RegCloseKey(hkey);
+ return (1);
+}
+
+static void sys_doneloadpreferences( void)
+{
+ fprintf(stderr, "here 2\n");
}
+static void sys_initsavepreferences( void)
+{
+}
- /* change the system's native file separator to '/' characters */
-void sys_unbashfilename(const char *from, char *to)
+static void sys_putpreference(const char *key, const char *value)
{
- char c;
- while (c = *from++)
+ HKEY *hkey;
+ LONG err = RegCreateKeyEx(HKEY_LOCAL_MACHINE,
+ "Software\\Pd", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_SET_VALUE,
+ NULL, &hkey, NULL);
+ if (err != ERROR_SUCCESS)
{
+ post("unable to create registry entry: %s\n", key);
+ return;
+ }
+ err = RegSetValueEx(hkey, key, 0, REG_SZ, value, strlen(value)+1);
+ if (err != ERROR_SUCCESS)
+ post("unable to set registry entry: %s\n", key);
+ RegCloseKey(hkey);
+}
+
+static void sys_donesavepreferences( void)
+{
+}
+
+#endif /* MSW */
+
+#ifdef MACOSX
+
+static void sys_initloadpreferences( void)
+{
+}
+
+static int sys_getpreference(const char *key, char *value, int size)
+{
+ char cmdbuf[256];
+ int nread = 0, nleft = size;
+ snprintf(cmdbuf, 256, "defaults read com.ucsd.pd %s 2> /dev/null\n", key);
+ FILE *fp = popen(cmdbuf, "r");
+ while (nread < size)
+ {
+ int newread = fread(value+nread, 1, size-nread, fp);
+ if (newread <= 0)
+ break;
+ nread += newread;
+ }
+ pclose(fp);
+ if (!nread)
+ return (0);
+ if (nread >= size)
+ nread = size-1;
+ value[nread] = 0;
+ return(1);
+}
+
+static void sys_doneloadpreferences( void)
+{
+}
+
+static void sys_initsavepreferences( void)
+{
+}
+
+static void sys_putpreference(const char *key, const char *value)
+{
+ char cmdbuf[MAXPDSTRING];
+ snprintf(cmdbuf, MAXPDSTRING,
+ "defaults write com.ucsd.pd %s \"%s\" 2> /dev/null\n", key, value);
+ system(cmdbuf);
+}
+
+static void sys_donesavepreferences( void)
+{
+}
+
+#endif /* MACOSX */
+
+void sys_loadpreferences( void)
+{
+ int naudioindev, audioindev[MAXAUDIOINDEV], chindev[MAXAUDIOINDEV];
+ int naudiooutdev, audiooutdev[MAXAUDIOOUTDEV], choutdev[MAXAUDIOOUTDEV];
+ int nmidiindev, midiindev[MAXMIDIINDEV];
+ int nmidioutdev, midioutdev[MAXMIDIOUTDEV];
+ int i, rate = 0, advance = 0, api, nolib;
+ char prefbuf[MAXPDSTRING], keybuf[80];
+ sys_initloadpreferences();
+ /* load audio preferences */
+ if (sys_getpreference("audioapi", prefbuf, MAXPDSTRING)
+ && sscanf(prefbuf, "%d", &api) > 0)
+ sys_set_audio_api(api);
+ if (sys_getpreference("noaudioin", prefbuf, MAXPDSTRING))
+ naudioindev = 0;
+ else
+ {
+ for (i = 0, naudioindev = 0; i < MAXAUDIOINDEV; i++)
+ {
+ sprintf(keybuf, "audioindev%d", i+1);
+ if (!sys_getpreference(keybuf, prefbuf, MAXPDSTRING))
+ break;
+ if (sscanf(prefbuf, "%d %d", &audioindev[i], &chindev[i]) < 2)
+ break;
+ naudioindev++;
+ }
+ /* if no preferences at all, set -1 for default behavior */
+ if (naudioindev == 0)
+ naudioindev = -1;
+ }
+ if (sys_getpreference("noaudioout", prefbuf, MAXPDSTRING))
+ naudiooutdev = 0;
+ else
+ {
+ for (i = 0, naudiooutdev = 0; i < MAXAUDIOOUTDEV; i++)
+ {
+ sprintf(keybuf, "audiooutdev%d", i+1);
+ if (!sys_getpreference(keybuf, prefbuf, MAXPDSTRING))
+ break;
+ if (sscanf(prefbuf, "%d %d", &audiooutdev[i], &choutdev[i]) < 2)
+ break;
+ naudiooutdev++;
+ }
+ if (naudiooutdev == 0)
+ naudiooutdev = -1;
+ }
+ if (sys_getpreference("rate", prefbuf, MAXPDSTRING))
+ sscanf(prefbuf, "%d", &rate);
+ if (sys_getpreference("audiobuf", prefbuf, MAXPDSTRING))
+ sscanf(prefbuf, "%d", &advance);
+ sys_open_audio(naudioindev, audioindev, naudioindev, chindev,
+ naudiooutdev, audiooutdev, naudiooutdev, choutdev, rate, advance, 0);
+
+ /* load MIDI preferences */
+ for (i = 0, nmidiindev = 0; i < MAXMIDIINDEV; i++)
+ {
+ sprintf(keybuf, "midiindev%d", i+1);
+ if (!sys_getpreference(keybuf, prefbuf, MAXPDSTRING))
+ break;
+ if (sscanf(prefbuf, "%d %d", &midiindev[i], &chindev[i]) < 2)
+ break;
+ nmidiindev++;
+ }
+ for (i = 0, nmidioutdev = 0; i < MAXMIDIOUTDEV; i++)
+ {
+ sprintf(keybuf, "midioutdev%d", i+1);
+ if (!sys_getpreference(keybuf, prefbuf, MAXPDSTRING))
+ break;
+ if (sscanf(prefbuf, "%d %d", &midioutdev[i], &choutdev[i]) < 2)
+ break;
+ nmidioutdev++;
+ }
+ sys_open_midi(nmidiindev, midiindev, nmidioutdev, midioutdev, 0);
+ /* search path */
+ for (i = 0; 1; i++)
+ {
+ sprintf(keybuf, "path%d", i+1);
+ if (!sys_getpreference(keybuf, prefbuf, MAXPDSTRING))
+ break;
+ sys_searchpath = namelist_append_files(sys_searchpath, prefbuf);
+ }
+ if (sys_getpreference("standardpath", prefbuf, MAXPDSTRING))
+ sscanf(prefbuf, "%d", &sys_usestdpath);
+ if (sys_getpreference("verbose", prefbuf, MAXPDSTRING))
+ sscanf(prefbuf, "%d", &sys_verbose);
+
+ /* startup settings */
+ for (i = 0; 1; i++)
+ {
+ sprintf(keybuf, "loadlib%d", i+1);
+ if (!sys_getpreference(keybuf, prefbuf, MAXPDSTRING))
+ break;
+ sys_externlist = namelist_append_files(sys_externlist, prefbuf);
+ }
+ if (sys_getpreference("defeatrt", prefbuf, MAXPDSTRING))
+ sscanf(prefbuf, "%d", &sys_defeatrt);
+ if (sys_getpreference("flags", prefbuf, MAXPDSTRING))
+ {
+ if (strcmp(prefbuf, "."))
+ sys_flags = gensym(prefbuf);
+ }
+ sys_doflags();
+
+ if (sys_defeatrt)
+ sys_hipriority = 0;
+ else
+#ifdef UNIX
+ sys_hipriority = !geteuid();
+#else
#ifdef MSW
- if (c == '\\') c = '/';
+ sys_hipriority = 0;
+#else
+ sys_hipriority = 1;
+#endif
#endif
- *to++ = c;
- }
- *to = 0;
}
+void glob_savepreferences(t_pd *dummy)
+{
+ int naudioindev, audioindev[MAXAUDIOINDEV], chindev[MAXAUDIOINDEV];
+ int naudiooutdev, audiooutdev[MAXAUDIOOUTDEV], choutdev[MAXAUDIOOUTDEV];
+ int i, rate, advance;
+ char buf1[MAXPDSTRING], buf2[MAXPDSTRING];
+ int nmidiindev, midiindev[MAXMIDIINDEV];
+ int nmidioutdev, midioutdev[MAXMIDIOUTDEV];
+
+ sys_initsavepreferences();
+
+
+ /* audio settings */
+ sprintf(buf1, "%d", sys_audioapi);
+ sys_putpreference("audioapi", buf1);
+
+ sys_get_audio_params(&naudioindev, audioindev, chindev,
+ &naudiooutdev, audiooutdev, choutdev, &rate, &advance);
+
+ if (naudioindev <= 0)
+ sys_putpreference("noaudioin", ".");
+ for (i = 0; i < naudioindev; i++)
+ {
+ sprintf(buf1, "audioindev%d", i+1);
+ sprintf(buf2, "%d %d", audioindev[i], chindev[i]);
+ sys_putpreference(buf1, buf2);
+ }
+ if (naudiooutdev <= 0)
+ sys_putpreference("noaudioout", ".");
+ for (i = 0; i < naudiooutdev; i++)
+ {
+ sprintf(buf1, "audiooutdev%d", i+1);
+ sprintf(buf2, "%d %d", audiooutdev[i], choutdev[i]);
+ sys_putpreference(buf1, buf2);
+ }
+
+ sprintf(buf1, "%d", advance);
+ sys_putpreference("audiobuf", buf1);
+
+ sprintf(buf1, "%d", rate);
+ sys_putpreference("rate", buf1);
+
+ /* MIDI settings */
+ sys_get_midi_params(&nmidiindev, midiindev, &nmidioutdev, midioutdev);
+ if (nmidiindev <= 0)
+ sys_putpreference("nomidiin", ".");
+ for (i = 0; i < nmidiindev; i++)
+ {
+ sprintf(buf1, "midiindev%d", i+1);
+ sprintf(buf2, "%d", midiindev[i]);
+ sys_putpreference(buf1, buf2);
+ }
+ if (nmidioutdev <= 0)
+ sys_putpreference("nomidiout", ".");
+ for (i = 0; i < nmidioutdev; i++)
+ {
+ sprintf(buf1, "midioutdev%d", i+1);
+ sprintf(buf2, "%d", midioutdev[i]);
+ sys_putpreference(buf1, buf2);
+ }
+ /* file search path */
+
+ for (i = 0; 1; i++)
+ {
+ char *pathelem = namelist_get(sys_searchpath, i);
+ if (!pathelem)
+ break;
+ sprintf(buf1, "path%d", i+1);
+ sys_putpreference(buf1, pathelem);
+ }
+ sprintf(buf1, "%d", sys_usestdpath);
+ sys_putpreference("standardpath", buf1);
+ sprintf(buf1, "%d", sys_verbose);
+ sys_putpreference("verbose", buf1);
+
+ /* startup */
+ for (i = 0; 1; i++)
+ {
+ char *pathelem = namelist_get(sys_externlist, i);
+ if (!pathelem)
+ break;
+ sprintf(buf1, "loadlib%d", i+1);
+ sys_putpreference(buf1, pathelem);
+ }
+ sprintf(buf1, "%d", sys_defeatrt);
+ sys_putpreference("defeatrt", buf1);
+ sys_putpreference("flags",
+ (sys_flags ? sys_flags->s_name : ""));
+ sys_donesavepreferences();
+
+}
diff --git a/pd/src/s_inter.c b/pd/src/s_inter.c
index cd6096bb..05232d59 100644
--- a/pd/src/s_inter.c
+++ b/pd/src/s_inter.c
@@ -8,7 +8,8 @@ that didn't really belong anywhere. */
#include "m_pd.h"
#include "s_stuff.h"
#include "m_imp.h"
-#ifdef UNIX
+#include "g_canvas.h" /* for GUI queueing stuff */
+#ifndef MSW
#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h>
@@ -44,7 +45,7 @@ typedef int pid_t;
#include <stdlib.h>
#endif
-#define DEBUG_MESSUP 1 /* messages up from pd to pd-gui */
+#define DEBUG_MESSUP 1 /* messages up from pd to pd-gui */
#define DEBUG_MESSDOWN 2 /* messages down from pd-gui to pd */
/* T.Grill - make it a _little_ more adaptable... */
@@ -53,10 +54,14 @@ typedef int pid_t;
#endif
#ifndef WISHAPP
-#define WISHAPP "wish83.exe"
+#define WISHAPP "wish84.exe"
#endif
-extern char pd_version[];
+#ifdef __linux__
+#define LOCALHOST "127.0.0.1"
+#else
+#define LOCALHOST "localhost"
+#endif
typedef struct _fdpoll
{
@@ -78,6 +83,9 @@ struct _socketreceiver
t_socketreceivefn sr_socketreceivefn;
};
+extern char pd_version[];
+extern int sys_guisetportnumber;
+
static int sys_nfdpoll;
static t_fdpoll *sys_fdpoll;
static int sys_maxfd;
@@ -87,6 +95,8 @@ static t_binbuf *inbinbuf;
static t_socketreceiver *sys_socketreceiver;
extern int sys_addhist(int phase);
+/* ----------- functions for timing, signals, priorities, etc --------- */
+
#ifdef MSW
static LARGE_INTEGER nt_inittime;
static double nt_freq = 0;
@@ -120,17 +130,16 @@ double nt_tixtotime(LARGE_INTEGER *dumbass)
/* get "real time" in seconds; take the
first time we get called as a reference time of zero. */
-double sys_getrealtime(void)
+double sys_getrealtime(void)
{
-#ifdef UNIX
+#ifndef MSW
static struct timeval then;
struct timeval now;
gettimeofday(&now, 0);
if (then.tv_sec == 0 && then.tv_usec == 0) then = now;
return ((now.tv_sec - then.tv_sec) +
- (1./1000000.) * (now.tv_usec - then.tv_usec));
-#endif
-#ifdef MSW
+ (1./1000000.) * (now.tv_usec - then.tv_usec));
+#else
LARGE_INTEGER now;
QueryPerformanceCounter(&now);
if (nt_freq == 0) sys_initntclock();
@@ -138,6 +147,164 @@ double sys_getrealtime(void)
#endif
}
+static int sys_domicrosleep(int microsec, int pollem)
+{
+ struct timeval timout;
+ int i, didsomething = 0;
+ t_fdpoll *fp;
+ timout.tv_sec = 0;
+ timout.tv_usec = microsec;
+ if (pollem)
+ {
+ fd_set readset, writeset, exceptset;
+ FD_ZERO(&writeset);
+ FD_ZERO(&readset);
+ FD_ZERO(&exceptset);
+ for (fp = sys_fdpoll, i = sys_nfdpoll; i--; fp++)
+ FD_SET(fp->fdp_fd, &readset);
+ select(sys_maxfd+1, &readset, &writeset, &exceptset, &timout);
+ for (i = 0; i < sys_nfdpoll; i++)
+ if (FD_ISSET(sys_fdpoll[i].fdp_fd, &readset))
+ {
+ (*sys_fdpoll[i].fdp_fn)(sys_fdpoll[i].fdp_ptr, sys_fdpoll[i].fdp_fd);
+ didsomething = 1;
+ }
+ return (didsomething);
+ }
+ else
+ {
+ select(0, 0, 0, 0, &timout);
+ return (0);
+ }
+}
+
+void sys_microsleep(int microsec)
+{
+ sys_domicrosleep(microsec, 1);
+}
+
+#ifdef UNISTD
+typedef void (*sighandler_t)(int);
+
+static void sys_signal(int signo, sighandler_t sigfun)
+{
+ struct sigaction action;
+ action.sa_flags = 0;
+ action.sa_handler = sigfun;
+ memset(&action.sa_mask, 0, sizeof(action.sa_mask));
+#if 0 /* GG says: don't use that */
+ action.sa_restorer = 0;
+#endif
+ if (sigaction(signo, &action, 0) < 0)
+ perror("sigaction");
+}
+
+static void sys_exithandler(int n)
+{
+ static int trouble = 0;
+ if (!trouble)
+ {
+ trouble = 1;
+ fprintf(stderr, "Pd: signal %d\n", n);
+ sys_bail(1);
+ }
+ else _exit(1);
+}
+
+static void sys_alarmhandler(int n)
+{
+ fprintf(stderr, "Pd: system call timed out\n");
+}
+
+static void sys_huphandler(int n)
+{
+ struct timeval timout;
+ timout.tv_sec = 0;
+ timout.tv_usec = 30000;
+ select(1, 0, 0, 0, &timout);
+}
+
+void sys_setalarm(int microsec)
+{
+ struct itimerval gonzo;
+#if 0
+ fprintf(stderr, "timer %d\n", microsec);
+#endif
+ gonzo.it_interval.tv_sec = 0;
+ gonzo.it_interval.tv_usec = 0;
+ gonzo.it_value.tv_sec = 0;
+ gonzo.it_value.tv_usec = microsec;
+ if (microsec)
+ sys_signal(SIGALRM, sys_alarmhandler);
+ else sys_signal(SIGALRM, SIG_IGN);
+ setitimer(ITIMER_REAL, &gonzo, 0);
+}
+
+#endif
+
+#ifdef __linux
+
+#if defined(_POSIX_PRIORITY_SCHEDULING) || defined(_POSIX_MEMLOCK)
+#include <sched.h>
+#endif
+
+void sys_set_priority(int higher)
+{
+#ifdef _POSIX_PRIORITY_SCHEDULING
+ struct sched_param par;
+ int p1 ,p2, p3;
+ p1 = sched_get_priority_min(SCHED_FIFO);
+ p2 = sched_get_priority_max(SCHED_FIFO);
+#ifdef USEAPI_JACK
+ p3 = (higher ? p1 + 7 : p1 + 5);
+#else
+ p3 = (higher ? p2 - 1 : p2 - 3);
+#endif
+ par.sched_priority = p3;
+ if (sched_setscheduler(0,SCHED_FIFO,&par) != -1)
+ fprintf(stderr, "priority %d scheduling enabled.\n", p3);
+#endif
+
+#ifdef _POSIX_MEMLOCK
+ if (mlockall(MCL_FUTURE) != -1)
+ fprintf(stderr, "memory locking enabled.\n");
+#endif
+
+}
+
+#endif /* __linux__ */
+
+#ifdef IRIX /* hack by <olaf.matthes@gmx.de> at 2003/09/21 */
+
+#if defined(_POSIX_PRIORITY_SCHEDULING) || defined(_POSIX_MEMLOCK)
+#include <sched.h>
+#endif
+
+void sys_set_priority(int higher)
+{
+#ifdef _POSIX_PRIORITY_SCHEDULING
+ struct sched_param par;
+ /* Bearing the table found in 'man realtime' in mind, I found it a */
+ /* good idea to use 192 as the priority setting for Pd. Any thoughts? */
+ if (higher)
+ par.sched_priority = 250; /* priority for watchdog */
+ else
+ par.sched_priority = 192; /* priority for pd (DSP) */
+
+ if (sched_setscheduler(0, SCHED_FIFO, &par) != -1)
+ fprintf(stderr, "priority %d scheduling enabled.\n", par.sched_priority);
+#endif
+
+#ifdef _POSIX_MEMLOCK
+ if (mlockall(MCL_FUTURE) != -1)
+ fprintf(stderr, "memory locking enabled.\n");
+#endif
+}
+/* end of hack */
+#endif /* IRIX */
+
+/* ------------------ receiving incoming messages over sockets ------------- */
+
void sys_sockerror(char *s)
{
#ifdef MSW
@@ -145,12 +312,11 @@ void sys_sockerror(char *s)
if (err == 10054) return;
else if (err == 10044)
{
- fprintf(stderr,
- "Warning: you might not have TCP/IP \"networking\" turned on\n");
- fprintf(stderr, "which is needed for Pd to talk to its GUI layer.\n");
+ fprintf(stderr,
+ "Warning: you might not have TCP/IP \"networking\" turned on\n");
+ fprintf(stderr, "which is needed for Pd to talk to its GUI layer.\n");
}
-#endif
-#ifdef UNIX
+#else
int err = errno;
#endif
fprintf(stderr, "%s: %s (%d)\n", s, strerror(err), err);
@@ -162,7 +328,7 @@ void sys_addpollfn(int fd, t_fdpollfn fn, void *ptr)
int size = nfd * sizeof(t_fdpoll);
t_fdpoll *fp;
sys_fdpoll = (t_fdpoll *)t_resizebytes(sys_fdpoll, size,
- size + sizeof(t_fdpoll));
+ size + sizeof(t_fdpoll));
fp = sys_fdpoll + nfd;
fp->fdp_fd = fd;
fp->fdp_fn = fn;
@@ -178,58 +344,22 @@ void sys_rmpollfn(int fd)
t_fdpoll *fp;
for (i = nfd, fp = sys_fdpoll; i--; fp++)
{
- if (fp->fdp_fd == fd)
- {
- while (i--)
- {
- fp[0] = fp[1];
- fp++;
- }
- sys_fdpoll = (t_fdpoll *)t_resizebytes(sys_fdpoll, size,
- size - sizeof(t_fdpoll));
- sys_nfdpoll = nfd - 1;
- return;
- }
+ if (fp->fdp_fd == fd)
+ {
+ while (i--)
+ {
+ fp[0] = fp[1];
+ fp++;
+ }
+ sys_fdpoll = (t_fdpoll *)t_resizebytes(sys_fdpoll, size,
+ size - sizeof(t_fdpoll));
+ sys_nfdpoll = nfd - 1;
+ return;
+ }
}
post("warning: %d removed from poll list but not found", fd);
}
-static int sys_domicrosleep(int microsec, int pollem)
-{
- struct timeval timout;
- int i, didsomething = 0;
- t_fdpoll *fp;
- timout.tv_sec = 0;
- timout.tv_usec = microsec;
- if (pollem)
- {
- fd_set readset, writeset, exceptset;
- FD_ZERO(&writeset);
- FD_ZERO(&readset);
- FD_ZERO(&exceptset);
- for (fp = sys_fdpoll, i = sys_nfdpoll; i--; fp++)
- FD_SET(fp->fdp_fd, &readset);
- select(sys_maxfd+1, &readset, &writeset, &exceptset, &timout);
- for (i = 0; i < sys_nfdpoll; i++)
- if (FD_ISSET(sys_fdpoll[i].fdp_fd, &readset))
- {
- (*sys_fdpoll[i].fdp_fn)(sys_fdpoll[i].fdp_ptr, sys_fdpoll[i].fdp_fd);
- didsomething = 1;
- }
- return (didsomething);
- }
- else
- {
- select(0, 0, 0, 0, &timout);
- return (0);
- }
-}
-
-void sys_microsleep(int microsec)
-{
- sys_domicrosleep(microsec, 1);
-}
-
t_socketreceiver *socketreceiver_new(void *owner, t_socketnotifier notifier,
t_socketreceivefn socketreceivefn, int udp)
{
@@ -261,23 +391,23 @@ static int socketreceiver_doread(t_socketreceiver *x)
if (intail == inhead) return (0);
for (indx = intail; indx != inhead; indx = (indx+1)&(INBUFSIZE-1))
{
- /* if we hit a semi that isn't preceeded by a \, it's a message
- boundary. LATER we should deal with the possibility that the
- preceeding \ might itself be escaped! */
- char c = *bp++ = inbuf[indx];
- if (c == ';' && (!indx || inbuf[indx-1] != '\\'))
- {
- intail = (indx+1)&(INBUFSIZE-1);
- binbuf_text(inbinbuf, messbuf, bp - messbuf);
- if (sys_debuglevel & DEBUG_MESSDOWN)
- {
- write(2, messbuf, bp - messbuf);
- write(2, "\n", 1);
- }
- x->sr_inhead = inhead;
- x->sr_intail = intail;
- return (1);
- }
+ /* if we hit a semi that isn't preceeded by a \, it's a message
+ boundary. LATER we should deal with the possibility that the
+ preceeding \ might itself be escaped! */
+ char c = *bp++ = inbuf[indx];
+ if (c == ';' && (!indx || inbuf[indx-1] != '\\'))
+ {
+ intail = (indx+1)&(INBUFSIZE-1);
+ binbuf_text(inbinbuf, messbuf, bp - messbuf);
+ if (sys_debuglevel & DEBUG_MESSDOWN)
+ {
+ write(2, messbuf, bp - messbuf);
+ write(2, "\n", 1);
+ }
+ x->sr_inhead = inhead;
+ x->sr_intail = intail;
+ return (1);
+ }
}
return (0);
}
@@ -288,104 +418,104 @@ static void socketreceiver_getudp(t_socketreceiver *x, int fd)
int ret = recv(fd, buf, INBUFSIZE, 0);
if (ret < 0)
{
- sys_sockerror("recv");
- sys_rmpollfn(fd);
- sys_closesocket(fd);
+ sys_sockerror("recv");
+ sys_rmpollfn(fd);
+ sys_closesocket(fd);
}
else if (ret > 0)
{
- buf[ret] = 0;
+ buf[ret] = 0;
#if 0
- post("%s", buf);
+ post("%s", buf);
#endif
- if (buf[ret-1] != '\n')
- {
+ if (buf[ret-1] != '\n')
+ {
#if 0
- buf[ret] = 0;
- error("dropped bad buffer %s\n", buf);
-#endif
- }
- else
- {
- char *semi = strchr(buf, ';');
- if (semi)
- *semi = 0;
- binbuf_text(inbinbuf, buf, strlen(buf));
- outlet_setstacklim();
- if (x->sr_socketreceivefn)
- (*x->sr_socketreceivefn)(x->sr_owner, inbinbuf);
- else bug("socketreceiver_getudp");
- }
+ buf[ret] = 0;
+ error("dropped bad buffer %s\n", buf);
+#endif
+ }
+ else
+ {
+ char *semi = strchr(buf, ';');
+ if (semi)
+ *semi = 0;
+ binbuf_text(inbinbuf, buf, strlen(buf));
+ outlet_setstacklim();
+ if (x->sr_socketreceivefn)
+ (*x->sr_socketreceivefn)(x->sr_owner, inbinbuf);
+ else bug("socketreceiver_getudp");
+ }
}
}
void socketreceiver_read(t_socketreceiver *x, int fd)
{
if (x->sr_udp) /* UDP ("datagram") socket protocol */
- socketreceiver_getudp(x, fd);
+ socketreceiver_getudp(x, fd);
else /* TCP ("streaming") socket protocol */
{
- char *semi;
- int readto =
- (x->sr_inhead >= x->sr_intail ? INBUFSIZE : x->sr_intail-1);
- int ret;
-
- /* the input buffer might be full. If so, drop the whole thing */
- if (readto == x->sr_inhead)
- {
- fprintf(stderr, "pd: dropped message from gui\n");
- x->sr_inhead = x->sr_intail = 0;
- readto = INBUFSIZE;
- }
- else
- {
- ret = recv(fd, x->sr_inbuf + x->sr_inhead,
- readto - x->sr_inhead, 0);
- if (ret < 0)
- {
- sys_sockerror("recv");
- if (x == sys_socketreceiver) sys_bail(1);
- else
- {
- if (x->sr_notifier) (*x->sr_notifier)(x->sr_owner);
- sys_rmpollfn(fd);
- sys_closesocket(fd);
- }
- }
- else if (ret == 0)
- {
- if (x == sys_socketreceiver)
- {
- fprintf(stderr, "pd: exiting\n");
- sys_bail(0);
- }
- else
- {
- post("EOF on socket %d\n", fd);
- if (x->sr_notifier) (*x->sr_notifier)(x->sr_owner);
- sys_rmpollfn(fd);
- sys_closesocket(fd);
- }
- }
- else
- {
- x->sr_inhead += ret;
- if (x->sr_inhead >= INBUFSIZE) x->sr_inhead = 0;
- while (socketreceiver_doread(x))
- {
- outlet_setstacklim();
- if (x->sr_socketreceivefn)
- (*x->sr_socketreceivefn)(x->sr_owner, inbinbuf);
- else binbuf_eval(inbinbuf, 0, 0, 0);
- }
- }
- }
+ char *semi;
+ int readto =
+ (x->sr_inhead >= x->sr_intail ? INBUFSIZE : x->sr_intail-1);
+ int ret;
+
+ /* the input buffer might be full. If so, drop the whole thing */
+ if (readto == x->sr_inhead)
+ {
+ fprintf(stderr, "pd: dropped message from gui\n");
+ x->sr_inhead = x->sr_intail = 0;
+ readto = INBUFSIZE;
+ }
+ else
+ {
+ ret = recv(fd, x->sr_inbuf + x->sr_inhead,
+ readto - x->sr_inhead, 0);
+ if (ret < 0)
+ {
+ sys_sockerror("recv");
+ if (x == sys_socketreceiver) sys_bail(1);
+ else
+ {
+ if (x->sr_notifier) (*x->sr_notifier)(x->sr_owner);
+ sys_rmpollfn(fd);
+ sys_closesocket(fd);
+ }
+ }
+ else if (ret == 0)
+ {
+ if (x == sys_socketreceiver)
+ {
+ fprintf(stderr, "pd: exiting\n");
+ sys_bail(0);
+ }
+ else
+ {
+ post("EOF on socket %d\n", fd);
+ if (x->sr_notifier) (*x->sr_notifier)(x->sr_owner);
+ sys_rmpollfn(fd);
+ sys_closesocket(fd);
+ }
+ }
+ else
+ {
+ x->sr_inhead += ret;
+ if (x->sr_inhead >= INBUFSIZE) x->sr_inhead = 0;
+ while (socketreceiver_doread(x))
+ {
+ outlet_setstacklim();
+ if (x->sr_socketreceivefn)
+ (*x->sr_socketreceivefn)(x->sr_owner, inbinbuf);
+ else binbuf_eval(inbinbuf, 0, 0, 0);
+ }
+ }
+ }
}
}
void sys_closesocket(int fd)
{
-#ifdef UNIX
+#ifdef UNISTD
close(fd);
#endif
#ifdef MSW
@@ -393,156 +523,290 @@ void sys_closesocket(int fd)
#endif
}
+/* ---------------------- sending messages to the GUI ------------------ */
+#define GUI_ALLOCCHUNK 8192
+#define GUI_UPDATESLICE 512 /* how much we try to do in one idle period */
+#define GUI_BYTESPERPING 1024 /* how much we send up per ping */
-void sys_gui(char *s)
+typedef struct _guiqueue
{
- int length = strlen(s), written = 0, res, histwas = sys_addhist(4);
- if (sys_debuglevel & DEBUG_MESSUP)
- fprintf(stderr, "%s", s);
- if (sys_nogui)
- return;
- while (1)
+ void *gq_client;
+ t_glist *gq_glist;
+ t_guicallbackfn gq_fn;
+ struct _guiqueue *gq_next;
+} t_guiqueue;
+
+static t_guiqueue *sys_guiqueuehead;
+static char *sys_guibuf;
+static int sys_guibufhead;
+static int sys_guibuftail;
+static int sys_guibufsize;
+static int sys_waitingforping;
+static int sys_bytessincelastping;
+
+static void sys_trytogetmoreguibuf(int newsize)
+{
+ char *newbuf = realloc(sys_guibuf, newsize);
+#if 0
+ static int sizewas;
+ if (newsize > 70000 && sizewas < 70000)
{
- res = send(sys_guisock, s + written, length, 0);
- if (res < 0)
- {
- perror("pd output pipe");
- sys_bail(1);
- }
- else
- {
- written += res;
- if (written >= length)
- break;
- }
+ int i;
+ for (i = sys_guibuftail; i < sys_guibufhead; i++)
+ fputc(sys_guibuf[i], stderr);
}
- sys_addhist(histwas);
-}
+ sizewas = newsize;
+#endif
+#if 0
+ fprintf(stderr, "new size %d (head %d, tail %d)\n",
+ newsize, sys_guibufhead, sys_guibuftail);
+#endif
-/* LATER should do a bounds check -- but how do you get printf to do that?
- See also rtext_senditup() in this regard */
+ /* if realloc fails, make a last-ditch attempt to stay alive by
+ synchronously writing out the existing contents. LATER test
+ this by intentionally setting newbuf to zero */
+ if (!newbuf)
+ {
+ int bytestowrite = sys_guibuftail - sys_guibufhead;
+ int written = 0;
+ while (1)
+ {
+ int res = send(sys_guisock,
+ sys_guibuf + sys_guibuftail + written, bytestowrite, 0);
+ if (res < 0)
+ {
+ perror("pd output pipe");
+ sys_bail(1);
+ }
+ else
+ {
+ written += res;
+ if (written >= bytestowrite)
+ break;
+ }
+ }
+ sys_guibufhead = sys_guibuftail = 0;
+ }
+ else
+ {
+ sys_guibufsize = newsize;
+ sys_guibuf = newbuf;
+ }
+}
void sys_vgui(char *fmt, ...)
{
- int result, i;
- char buf[2048];
+ int msglen, bytesleft, headwas, nwrote;
va_list ap;
+ if (sys_nogui)
+ return;
+ if (!sys_guibuf)
+ {
+ if (!(sys_guibuf = malloc(GUI_ALLOCCHUNK)))
+ {
+ fprintf(stderr, "Pd: couldn't allocate GUI buffer\n");
+ sys_bail(1);
+ }
+ sys_guibufsize = GUI_ALLOCCHUNK;
+ sys_guibufhead = sys_guibuftail = 0;
+ }
+ if (sys_guibufhead > sys_guibufsize - 50)
+ sys_trytogetmoreguibuf(sys_guibufsize + GUI_ALLOCCHUNK);
va_start(ap, fmt);
- vsprintf(buf, fmt, ap);
- sys_gui(buf);
+ msglen = vsnprintf(sys_guibuf + sys_guibufhead,
+ sys_guibufsize - sys_guibufhead, fmt, ap);
va_end(ap);
+ if (msglen >= sys_guibufsize - sys_guibufhead)
+ {
+ int newsize = sys_guibufsize + 1 +
+ (msglen > GUI_ALLOCCHUNK ? msglen : GUI_ALLOCCHUNK);
+ sys_trytogetmoreguibuf(newsize);
+
+ va_start(ap, fmt);
+ msglen = vsnprintf(sys_guibuf + sys_guibufhead,
+ sys_guibufsize + 1 - sys_guibufhead, fmt, ap);
+ va_end(ap);
+ if (msglen >= sys_guibufsize - sys_guibufhead)
+ msglen = sys_guibufsize - sys_guibufhead - 1;
+ }
+ if (sys_debuglevel & DEBUG_MESSUP)
+ fprintf(stderr, "%s", sys_guibuf + sys_guibufhead);
+ sys_guibufhead += msglen;
+ sys_bytessincelastping += msglen;
}
+void sys_gui(char *s)
+{
+ sys_vgui("%s", s);
+}
-#define FIRSTPORTNUM 5400
+static int sys_flushtogui( void)
+{
+ int writesize = sys_guibufhead - sys_guibuftail, nwrote = 0;
+ if (writesize > 0)
+ nwrote = send(sys_guisock, sys_guibuf + sys_guibuftail, writesize, 0);
-/* -------------- signal handling for UNIX -------------- */
+#if 0
+ if (writesize)
+ fprintf(stderr, "wrote %d of %d\n", nwrote, writesize);
+#endif
-#ifdef UNIX
-typedef void (*sighandler_t)(int);
+ if (nwrote < 0)
+ {
+ perror("pd-to-gui socket");
+ sys_bail(1);
+ }
+ else if (!nwrote)
+ return (0);
+ else if (nwrote >= sys_guibufhead - sys_guibuftail)
+ sys_guibufhead = sys_guibuftail = 0;
+ else if (nwrote)
+ {
+ sys_guibuftail += nwrote;
+ if (sys_guibuftail > (sys_guibufsize >> 2))
+ {
+ memmove(sys_guibuf, sys_guibuf + sys_guibuftail,
+ sys_guibufhead - sys_guibuftail);
+ sys_guibufhead = sys_guibufhead - sys_guibuftail;
+ sys_guibuftail = 0;
+ }
+ }
+ return (1);
+}
-static void sys_signal(int signo, sighandler_t sigfun)
+void glob_ping(t_pd *dummy)
{
- struct sigaction action;
- action.sa_flags = 0;
- action.sa_handler = sigfun;
- memset(&action.sa_mask, 0, sizeof(action.sa_mask));
-#if 0 /* GG says: don't use that */
- action.sa_restorer = 0;
-#endif
- if (sigaction(signo, &action, 0) < 0)
- perror("sigaction");
+ sys_waitingforping = 0;
}
-static void sys_exithandler(int n)
+static int sys_flushqueue(void )
{
- static int trouble = 0;
- if (!trouble)
+ int wherestop = sys_bytessincelastping + GUI_UPDATESLICE;
+ if (wherestop + (GUI_UPDATESLICE >> 1) > GUI_BYTESPERPING)
+ wherestop = 0x7fffffff;
+ if (sys_waitingforping)
+ return (0);
+ if (!sys_guiqueuehead)
+ return (0);
+ while (1)
{
- trouble = 1;
- fprintf(stderr, "Pd: signal %d\n", n);
- sys_bail(1);
-
+ if (sys_bytessincelastping >= GUI_BYTESPERPING)
+ {
+ sys_gui("pdtk_ping\n");
+ sys_bytessincelastping = 0;
+ sys_waitingforping = 1;
+ return (1);
+ }
+ if (sys_guiqueuehead)
+ {
+ t_guiqueue *headwas = sys_guiqueuehead;
+ sys_guiqueuehead = headwas->gq_next;
+ (*headwas->gq_fn)(headwas->gq_client, headwas->gq_glist);
+ t_freebytes(headwas, sizeof(*headwas));
+ if (sys_bytessincelastping >= wherestop)
+ break;
+ }
+ else break;
}
- else _exit(1);
+ sys_flushtogui();
+ return (1);
}
-static void sys_alarmhandler(int n)
+ /* flush output buffer and update queue to gui in small time slices */
+static int sys_poll_togui(void) /* returns 1 if did anything */
{
- fprintf(stderr, "Pd: system call timed out\n");
+ if (sys_nogui)
+ return (0);
+ /* see if there is stuff still in the buffer, if so we
+ must have fallen behind, so just try to clear that. */
+ if (sys_flushtogui())
+ return (1);
+ /* if the flush wasn't complete, wait. */
+ if (sys_guibufhead > sys_guibuftail)
+ return (0);
+
+ /* check for queued updates */
+ if (sys_flushqueue())
+ return (1);
+
+ return (0);
}
-static void sys_huphandler(int n)
+ /* if some GUI object is having to do heavy computations, it can tell
+ us to back off from doing more updates by faking a big one itself. */
+void sys_pretendguibytes(int n)
{
- struct timeval timout;
- timout.tv_sec = 0;
- timout.tv_usec = 30000;
- select(1, 0, 0, 0, &timout);
+ sys_bytessincelastping += n;
}
-void sys_setalarm(int microsec)
+void sys_queuegui(void *client, t_glist *glist, t_guicallbackfn f)
{
- struct itimerval gonzo;
-#if 0
- fprintf(stderr, "timer %d\n", microsec);
-#endif
- gonzo.it_interval.tv_sec = 0;
- gonzo.it_interval.tv_usec = 0;
- gonzo.it_value.tv_sec = 0;
- gonzo.it_value.tv_usec = microsec;
- if (microsec)
- sys_signal(SIGALRM, sys_alarmhandler);
- else sys_signal(SIGALRM, SIG_IGN);
- setitimer(ITIMER_REAL, &gonzo, 0);
+ t_guiqueue **gqnextptr, *gq;
+ if (!sys_guiqueuehead)
+ gqnextptr = &sys_guiqueuehead;
+ else
+ {
+ for (gq = sys_guiqueuehead; gq->gq_next; gq = gq->gq_next)
+ if (gq->gq_client == client)
+ return;
+ gqnextptr = &gq->gq_next;
+ }
+ gq = t_getbytes(sizeof(*gq));
+ gq->gq_next = 0;
+ gq->gq_client = client;
+ gq->gq_glist = glist;
+ gq->gq_fn = f;
+ gq->gq_next = 0;
+ *gqnextptr = gq;
}
-#endif
-
-#ifdef __linux
-
-#if defined(_POSIX_PRIORITY_SCHEDULING) || defined(_POSIX_MEMLOCK)
-#include <sched.h>
-#endif
+void sys_unqueuegui(void *client)
+{
+ t_guiqueue *gq, *gq2;
+ if (!sys_guiqueuehead)
+ return;
+ if (sys_guiqueuehead->gq_client == client)
+ {
+ t_freebytes(sys_guiqueuehead, sizeof(*sys_guiqueuehead));
+ sys_guiqueuehead = 0;
+ }
+ else for (gq = sys_guiqueuehead; gq2 = gq->gq_next; gq = gq2)
+ if (gq2->gq_client == client)
+ {
+ gq->gq_next = gq2->gq_next;
+ t_freebytes(gq, sizeof(*gq));
+ break;
+ }
+}
-void sys_set_priority(int higher)
+int sys_pollgui(void)
{
-#ifdef _POSIX_PRIORITY_SCHEDULING
- struct sched_param par;
- int p1 ,p2, p3;
- p1 = sched_get_priority_min(SCHED_FIFO);
- p2 = sched_get_priority_max(SCHED_FIFO);
- p3 = (higher ? p2 - 1 : p2 - 3);
- par.sched_priority = p3;
- if (sched_setscheduler(0,SCHED_FIFO,&par) != -1)
- fprintf(stderr, "priority %d scheduling enabled.\n", p3);
-#endif
+ return (sys_domicrosleep(0, 1) || sys_poll_togui());
+}
-#ifdef _POSIX_MEMLOCK
- if (mlockall(MCL_FUTURE) != -1)
- fprintf(stderr, "memory locking enabled.\n");
-#endif
-}
-#endif /* __linux */
+/* --------------------- starting up the GUI connection ------------- */
static int sys_watchfd;
#ifdef __linux__
-void glob_ping(t_pd *dummy)
+void glob_watchdog(t_pd *dummy)
{
if (write(sys_watchfd, "\n", 1) < 1)
{
- fprintf(stderr, "pd: watchdog process died\n");
- sys_bail(1);
+ fprintf(stderr, "pd: watchdog process died\n");
+ sys_bail(1);
}
}
#endif
+#define FIRSTPORTNUM 5400
+
static int defaultfontshit[] = {
8, 5, 9, 10, 6, 10, 12, 7, 13, 14, 9, 17, 16, 10, 19, 24, 15, 28,
- 24, 15, 28};
+ 24, 15, 28};
int sys_startgui(const char *guidir)
{
@@ -558,15 +822,16 @@ int sys_startgui(const char *guidir)
short version = MAKEWORD(2, 0);
WSADATA nobby;
#endif
-#ifdef UNIX
+#ifdef UNISTD
int stdinpipe[2];
#endif
+
/* create an empty FD poll list */
sys_fdpoll = (t_fdpoll *)t_getbytes(0);
sys_nfdpoll = 0;
inbinbuf = binbuf_new();
-#ifdef UNIX
+#ifdef UNISTD
signal(SIGHUP, sys_huphandler);
signal(SIGINT, sys_exithandler);
signal(SIGQUIT, sys_exithandler);
@@ -576,9 +841,8 @@ int sys_startgui(const char *guidir)
/* signal(SIGILL, sys_exithandler);
signal(SIGBUS, sys_exithandler);
signal(SIGSEGV, sys_exithandler); */
- signal(SIGPIPE, sys_exithandler);
+ signal(SIGPIPE, SIG_IGN);
signal(SIGALRM, SIG_IGN);
- signal(SIGTERM, SIG_IGN);
#if 0 /* GG says: don't use that */
signal(SIGSTKFLT, sys_exithandler);
#endif
@@ -589,122 +853,153 @@ int sys_startgui(const char *guidir)
if (sys_nogui)
{
- /* fake the GUI's message giving cwd and font sizes; then
- skip starting the GUI up. */
- t_atom zz[19];
- int i;
+ /* fake the GUI's message giving cwd and font sizes; then
+ skip starting the GUI up. */
+ t_atom zz[19];
+ int i;
#ifdef MSW
- if (GetCurrentDirectory(MAXPDSTRING, cmdbuf) == 0)
- strcpy(cmdbuf, ".");
-#endif
-#ifdef UNIX
- if (!getcwd(cmdbuf, MAXPDSTRING))
- strcpy(cmdbuf, ".");
-
-#endif
- SETSYMBOL(zz, gensym(cmdbuf));
- for (i = 1; i < 22; i++)
- SETFLOAT(zz + i, defaultfontshit[i-1]);
- SETFLOAT(zz+22,0);
- glob_initfromgui(0, 0, 23, zz);
+ if (GetCurrentDirectory(MAXPDSTRING, cmdbuf) == 0)
+ strcpy(cmdbuf, ".");
+#endif
+#ifdef UNISTD
+ if (!getcwd(cmdbuf, MAXPDSTRING))
+ strcpy(cmdbuf, ".");
+
+#endif
+ SETSYMBOL(zz, gensym(cmdbuf));
+ for (i = 1; i < 22; i++)
+ SETFLOAT(zz + i, defaultfontshit[i-1]);
+ SETFLOAT(zz+22,0);
+ glob_initfromgui(0, 0, 23, zz);
}
- else
+ else if (sys_guisetportnumber) /* GUI exists and sent us a port number */
+ {
+ struct sockaddr_in server;
+ struct hostent *hp;
+ /* create a socket */
+ sys_guisock = socket(AF_INET, SOCK_STREAM, 0);
+ if (sys_guisock < 0)
+ sys_sockerror("socket");
+
+ /* connect socket using hostname provided in command line */
+ server.sin_family = AF_INET;
+
+ hp = gethostbyname(LOCALHOST);
+
+ if (hp == 0)
+ {
+ fprintf(stderr,
+ "localhost not found (inet protocol not installed?)\n");
+ exit(1);
+ }
+ memcpy((char *)&server.sin_addr, (char *)hp->h_addr, hp->h_length);
+
+ /* assign client port number */
+ server.sin_port = htons((unsigned short)sys_guisetportnumber);
+
+ /* try to connect */
+ if (connect(sys_guisock, (struct sockaddr *) &server, sizeof (server))
+ < 0)
+ {
+ sys_sockerror("connecting stream socket");
+ exit(1);
+ }
+ }
+ else /* default behavior: start up the GUI ourselves. */
{
#ifdef MSW
- char scriptbuf[MAXPDSTRING+30], wishbuf[MAXPDSTRING+30], portbuf[80];
- int spawnret;
+ char scriptbuf[MAXPDSTRING+30], wishbuf[MAXPDSTRING+30], portbuf[80];
+ int spawnret;
#endif
#ifdef MSW
- char intarg;
+ char intarg;
#else
- int intarg;
+ int intarg;
#endif
- /* create a socket */
- xsock = socket(AF_INET, SOCK_STREAM, 0);
- if (xsock < 0) sys_sockerror("socket");
+ /* create a socket */
+ xsock = socket(AF_INET, SOCK_STREAM, 0);
+ if (xsock < 0) sys_sockerror("socket");
#if 0
- intarg = 0;
- if (setsockopt(xsock, SOL_SOCKET, SO_SNDBUF,
- &intarg, sizeof(intarg)) < 0)
- post("setsockopt (SO_RCVBUF) failed\n");
- intarg = 0;
- if (setsockopt(xsock, SOL_SOCKET, SO_RCVBUF,
- &intarg, sizeof(intarg)) < 0)
- post("setsockopt (SO_RCVBUF) failed\n");
-#endif
- intarg = 1;
- if (setsockopt(xsock, IPPROTO_TCP, TCP_NODELAY,
- &intarg, sizeof(intarg)) < 0)
+ intarg = 0;
+ if (setsockopt(xsock, SOL_SOCKET, SO_SNDBUF,
+ &intarg, sizeof(intarg)) < 0)
+ post("setsockopt (SO_RCVBUF) failed\n");
+ intarg = 0;
+ if (setsockopt(xsock, SOL_SOCKET, SO_RCVBUF,
+ &intarg, sizeof(intarg)) < 0)
+ post("setsockopt (SO_RCVBUF) failed\n");
+#endif
+ intarg = 1;
+ if (setsockopt(xsock, IPPROTO_TCP, TCP_NODELAY,
+ &intarg, sizeof(intarg)) < 0)
#ifndef MSW
- post("setsockopt (TCP_NODELAY) failed\n")
+ post("setsockopt (TCP_NODELAY) failed\n")
#endif
- ;
-
-
- server.sin_family = AF_INET;
- server.sin_addr.s_addr = INADDR_ANY;
-
- /* assign server port number */
- server.sin_port = htons((unsigned short)portno);
-
- /* name the socket */
- while (bind(xsock, (struct sockaddr *)&server, sizeof(server)) < 0)
- {
+ ;
+
+
+ server.sin_family = AF_INET;
+ server.sin_addr.s_addr = INADDR_ANY;
+
+ /* assign server port number */
+ server.sin_port = htons((unsigned short)portno);
+
+ /* name the socket */
+ while (bind(xsock, (struct sockaddr *)&server, sizeof(server)) < 0)
+ {
#ifdef MSW
- int err = WSAGetLastError();
-#endif
-#ifdef UNIX
- int err = errno;
-#endif
- if ((ntry++ > 20) || (err != EADDRINUSE))
- {
- perror("bind");
- fprintf(stderr,
- "Pd needs your machine to be configured with\n");
- fprintf(stderr,
- "'networking' turned on (see Pd's html doc for details.)\n");
- exit(1);
- }
- portno++;
- server.sin_port = htons((unsigned short)(portno));
- }
-
- if (sys_verbose) fprintf(stderr, "port %d\n", portno);
-
- sys_socketreceiver = socketreceiver_new(0, 0, 0, 0);
-
-#ifdef UNIX
- childpid = fork();
- if (childpid < 0)
- {
+ int err = WSAGetLastError();
+#else
+ int err = errno;
+#endif
+ if ((ntry++ > 20) || (err != EADDRINUSE))
+ {
+ perror("bind");
+ fprintf(stderr,
+ "Pd needs your machine to be configured with\n");
+ fprintf(stderr,
+ "'networking' turned on (see Pd's html doc for details.)\n");
+ exit(1);
+ }
+ portno++;
+ server.sin_port = htons((unsigned short)(portno));
+ }
+
+ if (sys_verbose) fprintf(stderr, "port %d\n", portno);
+
+
+#ifdef UNISTD
+ childpid = fork();
+ if (childpid < 0)
+ {
if (errno) perror("sys_startgui");
- else fprintf(stderr, "sys_startgui failed\n");
- return (1);
- }
- else if (!childpid) /* we're the child */
- {
- seteuid(getuid()); /* lose setuid priveliges */
+ else fprintf(stderr, "sys_startgui failed\n");
+ return (1);
+ }
+ else if (!childpid) /* we're the child */
+ {
+ seteuid(getuid()); /* lose setuid priveliges */
#ifndef MACOSX
- /* the wish process in Unix will make a wish shell and
- read/write standard in and out unless we close the
- file descriptors. Somehow this doesn't make the MAC OSX
- version of Wish happy...*/
- if (pipe(stdinpipe) < 0)
- sys_sockerror("pipe");
- else
- {
- if (stdinpipe[0] != 0)
- {
- close (0);
- dup2(stdinpipe[0], 0);
- close(stdinpipe[0]);
- }
- }
-#endif
- if (!sys_guicmd)
- {
+ /* the wish process in Unix will make a wish shell and
+ read/write standard in and out unless we close the
+ file descriptors. Somehow this doesn't make the MAC OSX
+ version of Wish happy...*/
+ if (pipe(stdinpipe) < 0)
+ sys_sockerror("pipe");
+ else
+ {
+ if (stdinpipe[0] != 0)
+ {
+ close (0);
+ dup2(stdinpipe[0], 0);
+ close(stdinpipe[0]);
+ }
+ }
+#endif
+ if (!sys_guicmd)
+ {
#ifdef MACOSX
char *homedir = getenv("HOME"), filename[250];
struct stat statbuf;
@@ -728,117 +1023,116 @@ int sys_startgui(const char *guidir)
strcpy(filename,
"/Applications/Wish Shell.app/Contents/MacOS/Wish Shell");
foundit:
- sprintf(cmdbuf, "\"%s\" %s/pd.tk %d\n", filename, guidir, portno);
+ sprintf(cmdbuf, "\"%s\" %s/pd.tk %d\n", filename, guidir, portno);
#else
- sprintf(cmdbuf,
+ sprintf(cmdbuf,
"TCL_LIBRARY=\"%s/tcl/library\" TK_LIBRARY=\"%s/tk/library\" \
\"%s/pd-gui\" %d\n",
- sys_libdir->s_name, sys_libdir->s_name, guidir, portno);
+ sys_libdir->s_name, sys_libdir->s_name, guidir, portno);
#endif
- sys_guicmd = cmdbuf;
- }
- if (sys_verbose) fprintf(stderr, "%s", sys_guicmd);
- execl("/bin/sh", "sh", "-c", sys_guicmd, 0);
- perror("pd: exec");
- _exit(1);
- }
-#endif /* UNIX */
+ sys_guicmd = cmdbuf;
+ }
+ if (sys_verbose) fprintf(stderr, "%s", sys_guicmd);
+ execl("/bin/sh", "sh", "-c", sys_guicmd, 0);
+ perror("pd: exec");
+ _exit(1);
+ }
+#endif /* UNISTD */
#ifdef MSW
- /* in MSW land "guipath" is unused; we just do everything from
- the libdir. */
- /* fprintf(stderr, "%s\n", sys_libdir->s_name); */
-
- strcpy(scriptbuf, "\"");
- strcat(scriptbuf, sys_libdir->s_name);
- strcat(scriptbuf, "/" PDBINDIR "pd.tk\"");
- sys_bashfilename(scriptbuf, scriptbuf);
-
- sprintf(portbuf, "%d", portno);
-
- strcpy(wishbuf, sys_libdir->s_name);
- strcat(wishbuf, "/" PDBINDIR WISHAPP);
- sys_bashfilename(wishbuf, wishbuf);
-
- spawnret = _spawnl(P_NOWAIT, wishbuf, WISHAPP, scriptbuf, portbuf, 0);
- if (spawnret < 0)
- {
- perror("spawnl");
- fprintf(stderr, "%s: couldn't load TCL\n", wishbuf);
- exit(1);
- }
+ /* in MSW land "guipath" is unused; we just do everything from
+ the libdir. */
+ /* fprintf(stderr, "%s\n", sys_libdir->s_name); */
+
+ strcpy(scriptbuf, "\"");
+ strcat(scriptbuf, sys_libdir->s_name);
+ strcat(scriptbuf, "/" PDBINDIR "pd.tk\"");
+ sys_bashfilename(scriptbuf, scriptbuf);
+
+ sprintf(portbuf, "%d", portno);
+
+ strcpy(wishbuf, sys_libdir->s_name);
+ strcat(wishbuf, "/" PDBINDIR WISHAPP);
+ sys_bashfilename(wishbuf, wishbuf);
+
+ spawnret = _spawnl(P_NOWAIT, wishbuf, WISHAPP, scriptbuf, portbuf, 0);
+ if (spawnret < 0)
+ {
+ perror("spawnl");
+ fprintf(stderr, "%s: couldn't load TCL\n", wishbuf);
+ exit(1);
+ }
#endif /* MSW */
}
-#ifdef __linux__
- /* now that we've spun off the child process we can promote
- our process's priority, if we happen to be root. */
+#if defined(__linux__) || defined(IRIX)
+ /* now that we've spun off the child process we can promote
+ our process's priority, if we can and want to. If not specfied
+ (-1), we check root status. This misses the case where we might
+ have permission from a "security module" (linux 2.6) -- I don't
+ know how to test for that. The "-rt" flag must b eset in that
+ case. */
+ if (sys_hipriority == -1)
+ sys_hipriority = (!getuid() || !geteuid());
+
if (sys_hipriority)
{
- if (!getuid() || !geteuid())
- {
- /* To prevent lockup, we fork off a watchdog process with
- higher real-time priority than ours. The GUI has to send
- a stream of ping messages to the watchdog THROUGH the Pd
- process which has to pick them up from the GUI and forward
- them. If any of these things aren't happening the watchdog
- starts sending "stop" and "cont" signals to the Pd process
- to make it timeshare with the rest of the system. (Version
- 0.33P2 : if there's no GUI, the watchdog pinging is done
- from the scheduler idle routine in this process instead.) */
-
- int pipe9[2], watchpid;
- if (pipe(pipe9) < 0)
- {
- seteuid(getuid()); /* lose setuid priveliges */
- sys_sockerror("pipe");
- return (1);
- }
- watchpid = fork();
- if (watchpid < 0)
- {
- seteuid(getuid()); /* lose setuid priveliges */
- if (errno)
- perror("sys_startgui");
- else fprintf(stderr, "sys_startgui failed\n");
- return (1);
- }
- else if (!watchpid) /* we're the child */
- {
- sys_set_priority(1);
- seteuid(getuid()); /* lose setuid priveliges */
- if (pipe9[1] != 0)
- {
- dup2(pipe9[0], 0);
- close(pipe9[0]);
- }
- close(pipe9[1]);
-
- sprintf(cmdbuf, "%s/pd-watchdog\n", guidir);
- if (sys_verbose) fprintf(stderr, "%s", cmdbuf);
- execl("/bin/sh", "sh", "-c", cmdbuf, 0);
- perror("pd: exec");
- _exit(1);
- }
- else /* we're the parent */
- {
- sys_set_priority(0);
- seteuid(getuid()); /* lose setuid priveliges */
- close(pipe9[0]);
- sys_watchfd = pipe9[1];
- /* We also have to start the ping loop in the GUI;
- this is done later when the socket is open. */
- }
- }
- else
- {
- post("realtime setting failed because not root\n");
- sys_hipriority = 0;
- }
+ /* To prevent lockup, we fork off a watchdog process with
+ higher real-time priority than ours. The GUI has to send
+ a stream of ping messages to the watchdog THROUGH the Pd
+ process which has to pick them up from the GUI and forward
+ them. If any of these things aren't happening the watchdog
+ starts sending "stop" and "cont" signals to the Pd process
+ to make it timeshare with the rest of the system. (Version
+ 0.33P2 : if there's no GUI, the watchdog pinging is done
+ from the scheduler idle routine in this process instead.) */
+
+ int pipe9[2], watchpid;
+ if (pipe(pipe9) < 0)
+ {
+ seteuid(getuid()); /* lose setuid priveliges */
+ sys_sockerror("pipe");
+ return (1);
+ }
+ watchpid = fork();
+ if (watchpid < 0)
+ {
+ seteuid(getuid()); /* lose setuid priveliges */
+ if (errno)
+ perror("sys_startgui");
+ else fprintf(stderr, "sys_startgui failed\n");
+ return (1);
+ }
+ else if (!watchpid) /* we're the child */
+ {
+ sys_set_priority(1);
+ seteuid(getuid()); /* lose setuid priveliges */
+ if (pipe9[1] != 0)
+ {
+ dup2(pipe9[0], 0);
+ close(pipe9[0]);
+ }
+ close(pipe9[1]);
+
+ sprintf(cmdbuf, "%s/pd-watchdog\n", guidir);
+ if (sys_verbose) fprintf(stderr, "%s", cmdbuf);
+ execl("/bin/sh", "sh", "-c", cmdbuf, 0);
+ perror("pd: exec");
+ _exit(1);
+ }
+ else /* we're the parent */
+ {
+ sys_set_priority(0);
+ seteuid(getuid()); /* lose setuid priveliges */
+ close(pipe9[0]);
+ sys_watchfd = pipe9[1];
+ /* We also have to start the ping loop in the GUI;
+ this is done later when the socket is open. */
+ }
}
- seteuid(getuid()); /* lose setuid priveliges */
+ seteuid(getuid()); /* lose setuid priveliges */
#endif /* __linux__ */
#ifdef MSW
@@ -848,60 +1142,51 @@ int sys_startgui(const char *guidir)
#ifdef MACOSX
if (sys_hipriority)
{
- struct sched_param param;
- int policy = SCHED_RR;
- int err;
- param.sched_priority = 80; // adjust 0 : 100
-
- err = pthread_setschedparam(pthread_self(), policy, &param);
- if (err)
- post("warning: high priority scheduling failed\n");
+ struct sched_param param;
+ int policy = SCHED_RR;
+ int err;
+ param.sched_priority = 80; // adjust 0 : 100
+
+ err = pthread_setschedparam(pthread_self(), policy, &param);
+ if (err)
+ post("warning: high priority scheduling failed\n");
}
#endif /* MACOSX */
- if (!sys_nogui)
+ if (!sys_nogui && !sys_guisetportnumber)
{
- char buf[256];
- if (sys_verbose)
- fprintf(stderr, "Waiting for connection request... \n");
- if (listen(xsock, 5) < 0) sys_sockerror("listen");
+ if (sys_verbose)
+ fprintf(stderr, "Waiting for connection request... \n");
+ if (listen(xsock, 5) < 0) sys_sockerror("listen");
- sys_guisock = accept(xsock, (struct sockaddr *) &server, &len);
+ sys_guisock = accept(xsock, (struct sockaddr *) &server, &len);
#ifdef OOPS
- close(xsock);
+ close(xsock);
#endif
- if (sys_guisock < 0) sys_sockerror("accept");
- sys_addpollfn(sys_guisock, (t_fdpollfn)socketreceiver_read,
- sys_socketreceiver);
-
- if (sys_verbose)
- fprintf(stderr, "... connected\n");
-
- /* here is where we start the pinging. */
-#ifdef __linux__
- if (sys_hipriority)
- sys_gui("pdtk_watchdog\n");
+ if (sys_guisock < 0) sys_sockerror("accept");
+ if (sys_verbose)
+ fprintf(stderr, "... connected\n");
+ }
+ if (!sys_nogui)
+ {
+ char buf[256];
+ sys_socketreceiver = socketreceiver_new(0, 0, 0, 0);
+ sys_addpollfn(sys_guisock, (t_fdpollfn)socketreceiver_read,
+ sys_socketreceiver);
+
+ /* here is where we start the pinging. */
+#if defined(__linux__) || defined(IRIX)
+ if (sys_hipriority)
+ sys_gui("pdtk_watchdog\n");
#endif
- sys_get_audio_apis(buf);
- sys_vgui("pdtk_pd_startup {%s} %s\n", pd_version, buf);
+ sys_get_audio_apis(buf);
+ sys_vgui("pdtk_pd_startup {%s} %s\n", pd_version, buf);
}
return (0);
}
-static int sys_poll_togui(void)
-{
- /* LATER use this to flush output buffer to gui */
- return (0);
-}
-
-int sys_pollgui(void)
-{
- return (sys_domicrosleep(0, 1) || sys_poll_togui());
-}
-
-
/* T.Grill - import clean quit function */
extern void sys_exit(void);
@@ -913,15 +1198,15 @@ void sys_bail(int n)
static int reentered = 0;
if (!reentered)
{
- reentered = 1;
-#ifndef __linux /* sys_close_audio() hangs if you're in a signal? */
- fprintf(stderr, "closing audio...\n");
- sys_close_audio();
- fprintf(stderr, "closing MIDI...\n");
- sys_close_midi();
- fprintf(stderr, "... done.\n");
-#endif
- exit(1);
+ reentered = 1;
+#ifndef __linux__ /* sys_close_audio() hangs if you're in a signal? */
+ fprintf(stderr, "closing audio...\n");
+ sys_close_audio();
+ fprintf(stderr, "closing MIDI...\n");
+ sys_close_midi();
+ fprintf(stderr, "... done.\n");
+#endif
+ exit(1);
}
else _exit(n);
}
@@ -931,8 +1216,8 @@ void glob_quit(void *dummy)
sys_vgui("exit\n");
if (!sys_nogui)
{
- close(sys_guisock);
- sys_rmpollfn(sys_guisock);
+ close(sys_guisock);
+ sys_rmpollfn(sys_guisock);
}
sys_bail(0);
}
diff --git a/pd/src/s_loader.c b/pd/src/s_loader.c
index c210206c..75f638f1 100644
--- a/pd/src/s_loader.c
+++ b/pd/src/s_loader.c
@@ -5,7 +5,7 @@
#ifdef DL_OPEN
#include <dlfcn.h>
#endif
-#ifdef UNIX
+#ifdef UNISTD
#include <stdlib.h>
#include <unistd.h>
#endif
@@ -49,7 +49,7 @@ void class_set_extern_dir(t_symbol *s);
int sys_load_lib(char *dirname, char *classname)
{
char symname[MAXPDSTRING], filename[MAXPDSTRING], dirbuf[MAXPDSTRING],
- classname2[MAXPDSTRING], *nameptr, *lastdot;
+ classname2[MAXPDSTRING], *nameptr, *lastdot;
void *dlobj;
t_xxx makeout = NULL;
int fd;
@@ -59,36 +59,36 @@ int sys_load_lib(char *dirname, char *classname)
#if 0
fprintf(stderr, "lib %s %s\n", dirname, classname);
#endif
- /* try looking in the path for (classname).(sys_dllextent) ... */
+ /* try looking in the path for (classname).(sys_dllextent) ... */
if ((fd = open_via_path(dirname, classname, sys_dllextent,
- dirbuf, &nameptr, MAXPDSTRING, 1)) < 0)
+ dirbuf, &nameptr, MAXPDSTRING, 1)) < 0)
{
- /* next try (classname)/(classname).(sys_dllextent) ... */
- strncpy(classname2, classname, MAXPDSTRING);
- filename[MAXPDSTRING-2] = 0;
- strcat(classname2, "/");
- strncat(classname2, classname, MAXPDSTRING-strlen(classname2));
- filename[MAXPDSTRING-1] = 0;
- if ((fd = open_via_path(dirname, classname2, sys_dllextent,
- dirbuf, &nameptr, MAXPDSTRING, 1)) < 0)
- {
- return (0);
- }
+ /* next try (classname)/(classname).(sys_dllextent) ... */
+ strncpy(classname2, classname, MAXPDSTRING);
+ filename[MAXPDSTRING-2] = 0;
+ strcat(classname2, "/");
+ strncat(classname2, classname, MAXPDSTRING-strlen(classname2));
+ filename[MAXPDSTRING-1] = 0;
+ if ((fd = open_via_path(dirname, classname2, sys_dllextent,
+ dirbuf, &nameptr, MAXPDSTRING, 1)) < 0)
+ {
+ return (0);
+ }
}
close(fd);
class_set_extern_dir(gensym(dirbuf));
- /* refabricate the pathname */
+ /* refabricate the pathname */
strncpy(filename, dirbuf, MAXPDSTRING);
filename[MAXPDSTRING-2] = 0;
strcat(filename, "/");
strncat(filename, nameptr, MAXPDSTRING-strlen(filename));
filename[MAXPDSTRING-1] = 0;
- /* extract the setup function name */
+ /* extract the setup function name */
if (lastdot = strrchr(nameptr, '.'))
- *lastdot = 0;
+ *lastdot = 0;
#ifdef MACOSX
strcpy(symname, "_");
@@ -96,18 +96,18 @@ int sys_load_lib(char *dirname, char *classname)
#else
strcpy(symname, nameptr);
#endif
- /* if the last character is a tilde, replace with "_tilde" */
+ /* if the last character is a tilde, replace with "_tilde" */
if (symname[strlen(symname) - 1] == '~')
- strcpy(symname + (strlen(symname) - 1), "_tilde");
- /* and append _setup to form the C setup function name */
+ strcpy(symname + (strlen(symname) - 1), "_tilde");
+ /* and append _setup to form the C setup function name */
strcat(symname, "_setup");
#ifdef DL_OPEN
dlobj = dlopen(filename, RTLD_NOW | RTLD_GLOBAL);
if (!dlobj)
{
- post("%s: %s", filename, dlerror());
- class_set_extern_dir(&s_);
- return (0);
+ post("%s: %s", filename, dlerror());
+ class_set_extern_dir(&s_);
+ return (0);
}
makeout = (t_xxx)dlsym(dlobj, symname);
#endif
@@ -116,9 +116,9 @@ int sys_load_lib(char *dirname, char *classname)
ntdll = LoadLibrary(filename);
if (!ntdll)
{
- post("%s: couldn't load", filename);
- class_set_extern_dir(&s_);
- return (0);
+ post("%s: couldn't load", filename);
+ class_set_extern_dir(&s_);
+ return (0);
}
makeout = (t_xxx)GetProcAddress(ntdll, symname);
#endif
@@ -130,11 +130,11 @@ int sys_load_lib(char *dirname, char *classname)
if ( NSCreateObjectFileImageFromFile( filename, &image) != NSObjectFileImageSuccess )
{
post("%s: couldn't load", filename);
- class_set_extern_dir(&s_);
+ class_set_extern_dir(&s_);
return 0;
}
- ret = NSLinkModule( image, filename,
- NSLINKMODULE_OPTION_BINDNOW + NSLINKMODULE_OPTION_PRIVATE);
+ ret = NSLinkModule( image, filename,
+ NSLINKMODULE_OPTION_BINDNOW + NSLINKMODULE_OPTION_PRIVATE);
s = NSLookupSymbolInModule(ret, symname);
@@ -146,9 +146,9 @@ int sys_load_lib(char *dirname, char *classname)
if (!makeout)
{
- post("load_object: Symbol \"%s\" not found", symname);
- class_set_extern_dir(&s_);
- return 0;
+ post("load_object: Symbol \"%s\" not found", symname);
+ class_set_extern_dir(&s_);
+ return 0;
}
(*makeout)();
class_set_extern_dir(&s_);
diff --git a/pd/src/s_main.c b/pd/src/s_main.c
index cc8bcc20..2af36f0d 100644
--- a/pd/src/s_main.c
+++ b/pd/src/s_main.c
@@ -7,7 +7,7 @@
* 1311:forum::für::umläute:2001
*/
-char pd_version[] = "Pd version 0.37.1 TEST6\n";
+char pd_version[] = "Pd version 0.38 TEST 4\n";
char pd_compiletime[] = __TIME__;
char pd_compiledate[] = __DATE__;
@@ -22,7 +22,7 @@ char pd_compiledate[] = __DATE__;
#include <fcntl.h>
#include <stdlib.h>
-#ifdef UNIX
+#ifdef UNISTD
#include <unistd.h>
#endif
#ifdef MSW
@@ -44,14 +44,17 @@ int sys_debuglevel;
int sys_verbose;
int sys_noloadbang;
int sys_nogui;
+int sys_hipriority = -1; /* -1 = don't care; 0 = no; 1 = yes */
+int sys_guisetportnumber; /* if started from the GUI, this is the port # */
+
char *sys_guicmd;
t_symbol *sys_libdir;
static t_symbol *sys_guidir;
-static t_namelist *sys_externlist;
+t_namelist *sys_externlist;
static t_namelist *sys_openlist;
static t_namelist *sys_messagelist;
static int sys_version;
-int sys_oldtclversion; /* hack to warn g_rtext.c about old text sel */
+int sys_oldtclversion; /* hack to warn g_rtext.c about old text sel */
int sys_nmidiout = 1;
#ifdef MSW
@@ -62,25 +65,46 @@ int sys_nmidiin = 1;
int sys_midiindevlist[MAXMIDIINDEV] = {1};
int sys_midioutdevlist[MAXMIDIOUTDEV] = {1};
-static int sys_main_srate = DEFAULTSRATE;
-static int sys_main_advance = DEFAULTADVANCE;
+static int sys_main_srate;
+static int sys_main_advance;
+
+/* jsarlo { */
+int sys_externalschedlib;
+char sys_externalschedlibname[MAXPDSTRING];
+int sys_extraflags;
+char sys_extraflagsstring[MAXPDSTRING];
+/* } jsarlo */
+
/* IOhannes { */
/* here the "-1" counts signify that the corresponding vector hasn't been
specified in command line arguments; sys_open_audio will detect this
and fill things in. */
-int sys_nsoundin = -1;
-int sys_nsoundout = -1;
-int sys_soundindevlist[MAXAUDIOINDEV];
-int sys_soundoutdevlist[MAXAUDIOOUTDEV];
-
-int sys_nchin = -1;
-int sys_nchout = -1;
-int sys_chinlist[MAXAUDIOINDEV];
-int sys_choutlist[MAXAUDIOOUTDEV];
+static int sys_nsoundin = -1;
+static int sys_nsoundout = -1;
+static int sys_soundindevlist[MAXAUDIOINDEV];
+static int sys_soundoutdevlist[MAXAUDIOOUTDEV];
+
+static int sys_nchin = -1;
+static int sys_nchout = -1;
+static int sys_chinlist[MAXAUDIOINDEV];
+static int sys_choutlist[MAXAUDIOOUTDEV];
/* } IOhannes */
+/* jsarlo { */
+t_sample* get_sys_soundout() { return sys_soundout; }
+t_sample* get_sys_soundin() { return sys_soundin; }
+int* get_sys_main_advance() { return &sys_main_advance; }
+double* get_sys_time_per_dsp_tick() { return &sys_time_per_dsp_tick; }
+int* get_sys_schedblocksize() { return &sys_schedblocksize; }
+double* get_sys_time() { return &sys_time; }
+float* get_sys_dacsr() { return &sys_dacsr; }
+int* get_sys_sleepgrain() { return &sys_sleepgrain; }
+int* get_sys_schedadvance() { return &sys_schedadvance; }
+/* } jsarlo */
+
+
typedef struct _fontinfo
{
@@ -123,7 +147,7 @@ static t_fontinfo *sys_findfont(int fontsize)
unsigned int i;
t_fontinfo *fi;
for (i = 0, fi = sys_fontlist; i < (NFONT-1); i++, fi++)
- if (fontsize < fi[1].fi_fontsize) return (fi);
+ if (fontsize < fi[1].fi_fontsize) return (fi);
return (sys_fontlist + (NFONT-1));
}
@@ -158,14 +182,14 @@ static void openit(const char *dirname, const char *filename)
{
char dirbuf[MAXPDSTRING], *nameptr;
int fd = open_via_path(dirname, filename, "", dirbuf, &nameptr,
- MAXPDSTRING, 0);
+ MAXPDSTRING, 0);
if (fd)
{
- close (fd);
- glob_evalfile(0, gensym(nameptr), gensym(dirbuf));
+ close (fd);
+ glob_evalfile(0, gensym(nameptr), gensym(dirbuf));
}
else
- error("%s: can't open", filename);
+ error("%s: can't open", filename);
}
#define NHOSTFONT 7
@@ -186,44 +210,42 @@ void glob_initfromgui(void *dummy, t_symbol *s, int argc, t_atom *argv)
if (argc != 2 + 3 * NHOSTFONT) bug("glob_initfromgui");
for (i = 0; i < NFONT; i++)
{
- int wantheight = sys_fontlist[i].fi_maxheight;
- for (j = 0; j < NHOSTFONT-1; j++)
- {
- if (atom_getintarg(3 * (j + 1) + 3, argc, argv) > wantheight)
- break;
- }
- /* j is now the "real" font index for the desired font index i. */
- sys_fontlist[i].fi_hostfontsize = atom_getintarg(3 * j + 1, argc, argv);
- sys_fontlist[i].fi_width = atom_getintarg(3 * j + 2, argc, argv);
- sys_fontlist[i].fi_height = atom_getintarg(3 * j + 3, argc, argv);
+ int wantheight = sys_fontlist[i].fi_maxheight;
+ for (j = 0; j < NHOSTFONT-1; j++)
+ {
+ if (atom_getintarg(3 * (j + 1) + 3, argc, argv) > wantheight)
+ break;
+ }
+ /* j is now the "real" font index for the desired font index i. */
+ sys_fontlist[i].fi_hostfontsize = atom_getintarg(3 * j + 1, argc, argv);
+ sys_fontlist[i].fi_width = atom_getintarg(3 * j + 2, argc, argv);
+ sys_fontlist[i].fi_height = atom_getintarg(3 * j + 3, argc, argv);
}
#if 0
for (i = 0; i < 6; i++)
- fprintf(stderr, "font %d %d %d %d %d\n",
- sys_fontlist[i].fi_fontsize,
- sys_fontlist[i].fi_maxheight,
- sys_fontlist[i].fi_hostfontsize,
- sys_fontlist[i].fi_width,
- sys_fontlist[i].fi_height);
+ fprintf(stderr, "font %d %d %d %d %d\n",
+ sys_fontlist[i].fi_fontsize,
+ sys_fontlist[i].fi_maxheight,
+ sys_fontlist[i].fi_hostfontsize,
+ sys_fontlist[i].fi_width,
+ sys_fontlist[i].fi_height);
#endif
- /* load dynamic libraries specified with "-lib" args */
+ /* load dynamic libraries specified with "-lib" args */
for (nl = sys_externlist; nl; nl = nl->nl_next)
- if (!sys_load_lib(cwd, nl->nl_string))
- post("%s: can't load library", nl->nl_string);
- namelist_free(sys_externlist);
- sys_externlist = 0;
- /* open patches specifies with "-open" args */
+ if (!sys_load_lib(cwd, nl->nl_string))
+ post("%s: can't load library", nl->nl_string);
+ /* open patches specifies with "-open" args */
for (nl = sys_openlist; nl; nl = nl->nl_next)
- openit(cwd, nl->nl_string);
+ openit(cwd, nl->nl_string);
namelist_free(sys_openlist);
sys_openlist = 0;
- /* send messages specified with "-send" args */
+ /* send messages specified with "-send" args */
for (nl = sys_messagelist; nl; nl = nl->nl_next)
{
- t_binbuf *b = binbuf_new();
- binbuf_text(b, nl->nl_string, strlen(nl->nl_string));
- binbuf_eval(b, 0, 0, 0);
- binbuf_free(b);
+ t_binbuf *b = binbuf_new();
+ binbuf_text(b, nl->nl_string, strlen(nl->nl_string));
+ binbuf_eval(b, 0, 0, 0);
+ binbuf_free(b);
}
namelist_free(sys_messagelist);
sys_messagelist = 0;
@@ -235,32 +257,61 @@ static void sys_afterargparse(void);
/* this is called from main() in s_entry.c */
int sys_main(int argc, char **argv)
{
+ /* jsarlo { */
+ sys_externalschedlib = 0;
+ sys_extraflags = 0;
+ /* } jsarlo */
#ifdef PD_DEBUG
fprintf(stderr, "Pd: COMPILED FOR DEBUGGING\n");
#endif
- pd_init(); /* start the message system */
- sys_findprogdir(argv[0]); /* set sys_progname, guipath */
-#ifdef UNIX
+ pd_init(); /* start the message system */
+ sys_findprogdir(argv[0]); /* set sys_progname, guipath */
+ sys_loadpreferences(); /* load default settings */
+#ifndef MSW
sys_rcfile(); /* parse the startup file */
#endif
- if (sys_argparse(argc, argv)) /* parse cmd line */
- return (1);
- sys_afterargparse(); /* post-argparse settings */
+ if (sys_argparse(argc, argv)) /* parse cmd line */
+ return (1);
+ sys_afterargparse(); /* post-argparse settings */
if (sys_verbose || sys_version) fprintf(stderr, "%scompiled %s %s\n",
- pd_version, pd_compiletime, pd_compiledate);
- if (sys_version) /* if we were just asked our version, exit here. */
- return (0);
- if (sys_startgui(sys_guidir->s_name)) /* start the gui */
- return(1);
- /* open audio and MIDI */
- sys_open_midi(sys_nmidiin, sys_midiindevlist,
- sys_nmidiout, sys_midioutdevlist);
- sys_open_audio(sys_nsoundin, sys_soundindevlist, sys_nchin, sys_chinlist,
- sys_nsoundout, sys_soundoutdevlist, sys_nchout, sys_choutlist,
- sys_main_srate, sys_main_advance, 1);
-
- /* run scheduler until it quits */
- return (m_scheduler());
+ pd_version, pd_compiletime, pd_compiledate);
+ if (sys_version) /* if we were just asked our version, exit here. */
+ return (0);
+ if (sys_startgui(sys_guidir->s_name)) /* start the gui */
+ return(1);
+ /* jsarlo { */
+ if (sys_externalschedlib)
+ {
+#ifdef MSW
+ typedef int (*t_externalschedlibmain)(char *);
+ t_externalschedlibmain externalmainfunc;
+ HINSTANCE ntdll;
+ char filename[MAXPDSTRING];
+
+ sprintf(filename, "%s.dll", sys_externalschedlibname);
+ sys_bashfilename(filename, filename);
+ ntdll = LoadLibrary(filename);
+ if (!ntdll)
+ {
+ post("%s: couldn't load external scheduler lib ", filename);
+ return (0);
+ }
+ externalmainfunc = (t_externalschedlibmain)GetProcAddress(ntdll,
+ "main");
+ return((*externalmainfunc)(sys_extraflagsstring));
+#else
+ return (0);
+#endif
+ }
+ else
+ {
+ /* open audio and MIDI */
+ sys_reopen_midi();
+ sys_reopen_audio();
+ /* run scheduler until it quits */
+ return (m_scheduler());
+ }
+ /* } jsarlo */
}
static char *(usagemessage[]) = {
@@ -282,14 +333,13 @@ static char *(usagemessage[]) = {
"-listdev -- list audio and MIDI devices\n",
#ifdef USEAPI_OSS
-"-oss -- use OSS audio API\n",
-"-32bit ----- allow 32 bit OSS audio (for RME Hammerfall)\n",
+"-oss -- use OSS audio API\n",
+"-32bit ----- allow 32 bit OSS audio (for RME Hammerfall)\n",
#endif
#ifdef USEAPI_ALSA
"-alsa -- use ALSA audio API\n",
"-alsaadd <name> -- add an ALSA device name to list\n",
-"-alsadev <n> ----- obsolete: use -audiodev\n",
#endif
#ifdef USEAPI_JACK
@@ -306,7 +356,7 @@ static char *(usagemessage[]) = {
#endif
#ifdef USEAPI_MMIO
-"-mmio -- use MMIO audio API (default for Windows)\n",
+"-mmio -- use MMIO audio API (default for Windows)\n",
#endif
" (default audio API for this platform: ", API_DEFSTRING, ")\n\n",
@@ -320,6 +370,8 @@ static char *(usagemessage[]) = {
"\nother flags:\n",
"-path <path> -- add to file search path\n",
+"-nostdpath -- don't search standard (\"extra\") directory\n",
+"-stdpath -- search standard directory (true by default)\n",
"-helppath <path> -- add to help file search path\n",
"-open <file> -- open file(s) on startup\n",
"-lib <file> -- load object library(s)\n",
@@ -328,10 +380,12 @@ static char *(usagemessage[]) = {
"-version -- don't run Pd; just print out which version it is \n",
"-d <n> -- specify debug level\n",
"-noloadbang -- suppress all loadbangs\n",
+"-stderr -- send printout to standard error instead of GUI\n",
"-nogui -- suppress starting the GUI\n",
-"-guicmd \"cmd...\" -- substitute another GUI program (e.g., rsh)\n",
-"-send \"msg...\" -- send a message at startup (after patches are loaded)\n",
-#ifdef UNIX
+"-guiport <n> -- connect to pre-existing GUI over port <n>\n",
+"-guicmd \"cmd...\" -- start alternatve GUI program (e.g., remote via ssh)\n",
+"-send \"msg...\" -- send a message at startup, after patches are loaded\n",
+#ifdef UNISTD
"-rt or -realtime -- use real-time priority\n",
"-nrt -- don't use real-time priority\n",
#endif
@@ -342,18 +396,18 @@ static void sys_parsedevlist(int *np, int *vecp, int max, char *str)
int n = 0;
while (n < max)
{
- if (!*str) break;
- else
- {
- char *endp;
- vecp[n] = strtol(str, &endp, 10);
- if (endp == str)
- break;
- n++;
- if (!endp)
- break;
- str = endp + 1;
- }
+ if (!*str) break;
+ else
+ {
+ char *endp;
+ vecp[n] = strtol(str, &endp, 10);
+ if (endp == str)
+ break;
+ n++;
+ if (!endp)
+ break;
+ str = endp + 1;
+ }
}
*np = n;
}
@@ -376,7 +430,7 @@ void sys_findprogdir(char *progname)
{
char sbuf[MAXPDSTRING], sbuf2[MAXPDSTRING], *sp;
char *lastslash;
-#ifdef UNIX
+#ifdef UNISTD
struct stat statbuf;
#endif
@@ -386,80 +440,79 @@ void sys_findprogdir(char *progname)
sbuf2[MAXPDSTRING-1] = 0;
sys_unbashfilename(sbuf2, sbuf);
#endif /* MSW */
-#ifdef UNIX
+#ifdef UNISTD
strncpy(sbuf, progname, MAXPDSTRING);
sbuf[MAXPDSTRING-1] = 0;
#endif
lastslash = strrchr(sbuf, '/');
if (lastslash)
{
- /* bash last slash to zero so that sbuf is directory pd was in,
- e.g., ~/pd/bin */
- *lastslash = 0;
- /* go back to the parent from there, e.g., ~/pd */
- lastslash = strrchr(sbuf, '/');
- if (lastslash)
- {
- strncpy(sbuf2, sbuf, lastslash-sbuf);
- sbuf2[lastslash-sbuf] = 0;
- }
- else strcpy(sbuf2, "..");
+ /* bash last slash to zero so that sbuf is directory pd was in,
+ e.g., ~/pd/bin */
+ *lastslash = 0;
+ /* go back to the parent from there, e.g., ~/pd */
+ lastslash = strrchr(sbuf, '/');
+ if (lastslash)
+ {
+ strncpy(sbuf2, sbuf, lastslash-sbuf);
+ sbuf2[lastslash-sbuf] = 0;
+ }
+ else strcpy(sbuf2, "..");
}
else
{
- /* no slashes found. Try INSTALL_PREFIX. */
+ /* no slashes found. Try INSTALL_PREFIX. */
#ifdef INSTALL_PREFIX
- strcpy(sbuf2, INSTALL_PREFIX);
+ strcpy(sbuf2, INSTALL_PREFIX);
#else
- strcpy(sbuf2, ".");
+ strcpy(sbuf2, ".");
#endif
}
- /* now we believe sbuf2 holds the parent directory of the directory
- pd was found in. We now want to infer the "lib" directory and the
- "gui" directory. In "simple" UNIX installations, the layout is
- .../bin/pd
- .../bin/pd-gui
- .../doc
- and in "complicated" UNIX installations, it's:
- .../bin/pd
- .../lib/pd/bin/pd-gui
- .../lib/pd/doc
- To decide which, we stat .../lib/pd; if that exists, we assume it's
- the complicated layout. In MSW, it's the "simple" layout, but
- the gui program is straight wish80:
- .../bin/pd
- .../bin/wish80.exe
- .../doc
- */
-#ifdef UNIX
+ /* now we believe sbuf2 holds the parent directory of the directory
+ pd was found in. We now want to infer the "lib" directory and the
+ "gui" directory. In "simple" unix installations, the layout is
+ .../bin/pd
+ .../bin/pd-gui
+ .../doc
+ and in "complicated" unix installations, it's:
+ .../bin/pd
+ .../lib/pd/bin/pd-gui
+ .../lib/pd/doc
+ To decide which, we stat .../lib/pd; if that exists, we assume it's
+ the complicated layout. In MSW, it's the "simple" layout, but
+ the gui program is straight wish80:
+ .../bin/pd
+ .../bin/wish80.exe
+ .../doc
+ */
+#ifdef MSW
+ sys_libdir = gensym(sbuf2);
+ sys_guidir = &s_; /* in MSW the guipath just depends on the libdir */
+#else
strncpy(sbuf, sbuf2, MAXPDSTRING-30);
sbuf[MAXPDSTRING-30] = 0;
strcat(sbuf, "/lib/pd");
if (stat(sbuf, &statbuf) >= 0)
{
- /* complicated layout: lib dir is the one we just stat-ed above */
- sys_libdir = gensym(sbuf);
- /* gui lives in .../lib/pd/bin */
- strncpy(sbuf, sbuf2, MAXPDSTRING-30);
- sbuf[MAXPDSTRING-30] = 0;
- strcat(sbuf, "/lib/pd/bin");
- sys_guidir = gensym(sbuf);
+ /* complicated layout: lib dir is the one we just stat-ed above */
+ sys_libdir = gensym(sbuf);
+ /* gui lives in .../lib/pd/bin */
+ strncpy(sbuf, sbuf2, MAXPDSTRING-30);
+ sbuf[MAXPDSTRING-30] = 0;
+ strcat(sbuf, "/lib/pd/bin");
+ sys_guidir = gensym(sbuf);
}
else
{
- /* simple layout: lib dir is the parent */
- sys_libdir = gensym(sbuf2);
- /* gui lives in .../bin */
- strncpy(sbuf, sbuf2, MAXPDSTRING-30);
- sbuf[MAXPDSTRING-30] = 0;
- strcat(sbuf, "/bin");
- sys_guidir = gensym(sbuf);
+ /* simple layout: lib dir is the parent */
+ sys_libdir = gensym(sbuf2);
+ /* gui lives in .../bin */
+ strncpy(sbuf, sbuf2, MAXPDSTRING-30);
+ sbuf[MAXPDSTRING-30] = 0;
+ strcat(sbuf, "/bin");
+ sys_guidir = gensym(sbuf);
}
#endif
-#ifdef MSW
- sys_libdir = gensym(sbuf2);
- sys_guidir = &s_; /* in MSW the guipath just depends on the libdir */
-#endif
}
#ifdef MSW
@@ -475,309 +528,329 @@ int sys_argparse(int argc, char **argv)
argc--; argv++;
while ((argc > 0) && **argv == '-')
{
- if (!strcmp(*argv, "-r") && argc > 1 &&
- sscanf(argv[1], "%d", &sys_main_srate) >= 1)
- {
- argc -= 2;
- argv += 2;
- }
- else if (!strcmp(*argv, "-inchannels"))
- { /* IOhannes */
- sys_parsedevlist(&sys_nchin,
- sys_chinlist, MAXAUDIOINDEV, argv[1]);
-
- if (!sys_nchin)
- goto usage;
-
- argc -= 2; argv += 2;
- }
- else if (!strcmp(*argv, "-outchannels"))
- { /* IOhannes */
- sys_parsedevlist(&sys_nchout, sys_choutlist,
- MAXAUDIOOUTDEV, argv[1]);
-
- if (!sys_nchout)
- goto usage;
-
- argc -= 2; argv += 2;
- }
- else if (!strcmp(*argv, "-channels"))
- {
- sys_parsedevlist(&sys_nchin, sys_chinlist,MAXAUDIOINDEV,
- argv[1]);
- sys_parsedevlist(&sys_nchout, sys_choutlist,MAXAUDIOOUTDEV,
- argv[1]);
-
- if (!sys_nchout)
- goto usage;
-
- argc -= 2; argv += 2;
- }
- else if (!strcmp(*argv, "-soundbuf") || !strcmp(*argv, "-audiobuf"))
- {
- sys_main_advance = atoi(argv[1]);
- argc -= 2; argv += 2;
- }
- else if (!strcmp(*argv, "-blocksize"))
- {
- sys_setblocksize(atoi(argv[1]));
- argc -= 2; argv += 2;
- }
- else if (!strcmp(*argv, "-sleepgrain"))
- {
- sys_sleepgrain = 1000 * atoi(argv[1]);
- argc -= 2; argv += 2;
- }
- else if (!strcmp(*argv, "-nodac"))
- { /* IOhannes */
- sys_nsoundout=0;
- sys_nchout = 0;
- argc--; argv++;
- }
- else if (!strcmp(*argv, "-noadc"))
- { /* IOhannes */
- sys_nsoundin=0;
- sys_nchin = 0;
- argc--; argv++;
- }
- else if (!strcmp(*argv, "-nosound") || !strcmp(*argv, "-noaudio"))
- { /* IOhannes */
- sys_nsoundin=sys_nsoundout = 0;
- sys_nchin = sys_nchout = 0;
- argc--; argv++;
- }
+ if (!strcmp(*argv, "-r") && argc > 1 &&
+ sscanf(argv[1], "%d", &sys_main_srate) >= 1)
+ {
+ argc -= 2;
+ argv += 2;
+ }
+ else if (!strcmp(*argv, "-inchannels"))
+ { /* IOhannes */
+ sys_parsedevlist(&sys_nchin,
+ sys_chinlist, MAXAUDIOINDEV, argv[1]);
+
+ if (!sys_nchin)
+ goto usage;
+
+ argc -= 2; argv += 2;
+ }
+ else if (!strcmp(*argv, "-outchannels"))
+ { /* IOhannes */
+ sys_parsedevlist(&sys_nchout, sys_choutlist,
+ MAXAUDIOOUTDEV, argv[1]);
+
+ if (!sys_nchout)
+ goto usage;
+
+ argc -= 2; argv += 2;
+ }
+ else if (!strcmp(*argv, "-channels"))
+ {
+ sys_parsedevlist(&sys_nchin, sys_chinlist,MAXAUDIOINDEV,
+ argv[1]);
+ sys_parsedevlist(&sys_nchout, sys_choutlist,MAXAUDIOOUTDEV,
+ argv[1]);
+
+ if (!sys_nchout)
+ goto usage;
+
+ argc -= 2; argv += 2;
+ }
+ else if (!strcmp(*argv, "-soundbuf") || !strcmp(*argv, "-audiobuf"))
+ {
+ sys_main_advance = atoi(argv[1]);
+ argc -= 2; argv += 2;
+ }
+ else if (!strcmp(*argv, "-blocksize"))
+ {
+ sys_setblocksize(atoi(argv[1]));
+ argc -= 2; argv += 2;
+ }
+ else if (!strcmp(*argv, "-sleepgrain"))
+ {
+ sys_sleepgrain = 1000 * atoi(argv[1]);
+ argc -= 2; argv += 2;
+ }
+ else if (!strcmp(*argv, "-nodac"))
+ { /* IOhannes */
+ sys_nsoundout=0;
+ sys_nchout = 0;
+ argc--; argv++;
+ }
+ else if (!strcmp(*argv, "-noadc"))
+ { /* IOhannes */
+ sys_nsoundin=0;
+ sys_nchin = 0;
+ argc--; argv++;
+ }
+ else if (!strcmp(*argv, "-nosound") || !strcmp(*argv, "-noaudio"))
+ { /* IOhannes */
+ sys_nsoundin=sys_nsoundout = 0;
+ sys_nchin = sys_nchout = 0;
+ argc--; argv++;
+ }
#ifdef USEAPI_OSS
- else if (!strcmp(*argv, "-oss"))
- {
- sys_set_audio_api(API_OSS);
- argc--; argv++;
- }
- else if (!strcmp(*argv, "-32bit"))
- {
- sys_set_audio_api(API_OSS);
- oss_set32bit();
- argc--; argv++;
- }
+ else if (!strcmp(*argv, "-oss"))
+ {
+ sys_set_audio_api(API_OSS);
+ argc--; argv++;
+ }
+ else if (!strcmp(*argv, "-32bit"))
+ {
+ sys_set_audio_api(API_OSS);
+ oss_set32bit();
+ argc--; argv++;
+ }
#endif
#ifdef USEAPI_ALSA
- else if (!strcmp(*argv, "-alsa"))
- {
- sys_set_audio_api(API_ALSA);
- argc--; argv++;
- }
- else if (!strcmp(*argv, "-alsaadd"))
- {
- if (argc > 1)
- alsa_adddev(argv[1]);
- else goto usage;
- argc -= 2; argv +=2;
- }
- /* obsolete flag for setting ALSA device number or name */
- else if (!strcmp(*argv, "-alsadev"))
- {
- int devno = 0;
- if (argv[1][0] >= '1' && argv[1][0] <= '9')
- devno = 1 + 2 * (atoi(argv[1]) - 1);
- else if (!strncmp(argv[1], "hw:", 3))
- devno = 1 + 2 * atoi(argv[1]+3);
- else if (!strncmp(argv[1], "plughw:", 7))
- devno = 2 + 2 * atoi(argv[1]+7);
- else goto usage;
- post("devno %d", devno);
- sys_nsoundin = sys_nsoundout = 1;
- sys_soundindevlist[0] = sys_soundoutdevlist[0] = devno;
- sys_set_audio_api(API_ALSA);
- argc -= 2; argv +=2;
- }
+ else if (!strcmp(*argv, "-alsa"))
+ {
+ sys_set_audio_api(API_ALSA);
+ argc--; argv++;
+ }
+ else if (!strcmp(*argv, "-alsaadd"))
+ {
+ if (argc > 1)
+ alsa_adddev(argv[1]);
+ else goto usage;
+ argc -= 2; argv +=2;
+ }
#endif
#ifdef USEAPI_JACK
- else if (!strcmp(*argv, "-jack"))
- {
- sys_set_audio_api(API_JACK);
- argc--; argv++;
- }
+ else if (!strcmp(*argv, "-jack"))
+ {
+ sys_set_audio_api(API_JACK);
+ argc--; argv++;
+ }
#endif
#ifdef USEAPI_PORTAUDIO
- else if (!strcmp(*argv, "-pa") || !strcmp(*argv, "-portaudio")
+ else if (!strcmp(*argv, "-pa") || !strcmp(*argv, "-portaudio")
#ifdef MSW
- || !strcmp(*argv, "-asio")
+ || !strcmp(*argv, "-asio")
#endif
- )
- {
- sys_set_audio_api(API_PORTAUDIO);
- sys_mmio = 0;
- argc--; argv++;
- }
+ )
+ {
+ sys_set_audio_api(API_PORTAUDIO);
+ sys_mmio = 0;
+ argc--; argv++;
+ }
#endif
#ifdef USEAPI_MMIO
- else if (!strcmp(*argv, "-mmio"))
- {
- sys_set_audio_api(API_MMIO);
- sys_mmio = 1;
- argc--; argv++;
- }
+ else if (!strcmp(*argv, "-mmio"))
+ {
+ sys_set_audio_api(API_MMIO);
+ sys_mmio = 1;
+ argc--; argv++;
+ }
#endif
- else if (!strcmp(*argv, "-nomidiin"))
- {
- sys_nmidiin = 0;
- argc--; argv++;
- }
- else if (!strcmp(*argv, "-nomidiout"))
- {
- sys_nmidiout = 0;
- argc--; argv++;
- }
- else if (!strcmp(*argv, "-nomidi"))
- {
- sys_nmidiin = sys_nmidiout = 0;
- argc--; argv++;
- }
- else if (!strcmp(*argv, "-midiindev"))
- {
- sys_parsedevlist(&sys_nmidiin, sys_midiindevlist, MAXMIDIINDEV,
- argv[1]);
- if (!sys_nmidiin)
- goto usage;
- argc -= 2; argv += 2;
- }
- else if (!strcmp(*argv, "-midioutdev"))
- {
- sys_parsedevlist(&sys_nmidiout, sys_midioutdevlist, MAXMIDIOUTDEV,
- argv[1]);
- if (!sys_nmidiout)
- goto usage;
- argc -= 2; argv += 2;
- }
- else if (!strcmp(*argv, "-mididev"))
- {
- sys_parsedevlist(&sys_nmidiin, sys_midiindevlist, MAXMIDIINDEV,
- argv[1]);
- sys_parsedevlist(&sys_nmidiout, sys_midioutdevlist, MAXMIDIOUTDEV,
- argv[1]);
- if (!sys_nmidiout)
- goto usage;
- argc -= 2; argv += 2;
- }
- else if (!strcmp(*argv, "-path"))
- {
- sys_addpath(argv[1]);
- argc -= 2; argv += 2;
- }
- else if (!strcmp(*argv, "-helppath"))
- {
- sys_addhelppath(argv[1]);
- argc -= 2; argv += 2;
- }
- else if (!strcmp(*argv, "-open") && argc > 1)
- {
- sys_openlist = namelist_append(sys_openlist, argv[1]);
- argc -= 2; argv += 2;
- }
+ else if (!strcmp(*argv, "-nomidiin"))
+ {
+ sys_nmidiin = 0;
+ argc--; argv++;
+ }
+ else if (!strcmp(*argv, "-nomidiout"))
+ {
+ sys_nmidiout = 0;
+ argc--; argv++;
+ }
+ else if (!strcmp(*argv, "-nomidi"))
+ {
+ sys_nmidiin = sys_nmidiout = 0;
+ argc--; argv++;
+ }
+ else if (!strcmp(*argv, "-midiindev"))
+ {
+ sys_parsedevlist(&sys_nmidiin, sys_midiindevlist, MAXMIDIINDEV,
+ argv[1]);
+ if (!sys_nmidiin)
+ goto usage;
+ argc -= 2; argv += 2;
+ }
+ else if (!strcmp(*argv, "-midioutdev"))
+ {
+ sys_parsedevlist(&sys_nmidiout, sys_midioutdevlist, MAXMIDIOUTDEV,
+ argv[1]);
+ if (!sys_nmidiout)
+ goto usage;
+ argc -= 2; argv += 2;
+ }
+ else if (!strcmp(*argv, "-mididev"))
+ {
+ sys_parsedevlist(&sys_nmidiin, sys_midiindevlist, MAXMIDIINDEV,
+ argv[1]);
+ sys_parsedevlist(&sys_nmidiout, sys_midioutdevlist, MAXMIDIOUTDEV,
+ argv[1]);
+ if (!sys_nmidiout)
+ goto usage;
+ argc -= 2; argv += 2;
+ }
+ else if (!strcmp(*argv, "-path"))
+ {
+ sys_searchpath = namelist_append_files(sys_searchpath, argv[1]);
+ argc -= 2; argv += 2;
+ }
+ else if (!strcmp(*argv, "-nostdpath"))
+ {
+ sys_usestdpath = 0;
+ argc--; argv++;
+ }
+ else if (!strcmp(*argv, "-stdpath"))
+ {
+ sys_usestdpath = 1;
+ argc--; argv++;
+ }
+ else if (!strcmp(*argv, "-helppath"))
+ {
+ sys_helppath = namelist_append_files(sys_helppath, argv[1]);
+ argc -= 2; argv += 2;
+ }
+ else if (!strcmp(*argv, "-open") && argc > 1)
+ {
+ sys_openlist = namelist_append_files(sys_openlist, argv[1]);
+ argc -= 2; argv += 2;
+ }
else if (!strcmp(*argv, "-lib") && argc > 1)
{
- sys_externlist = namelist_append(sys_externlist, argv[1]);
- argc -= 2; argv += 2;
- }
- else if (!strcmp(*argv, "-font") && argc > 1)
- {
- sys_defaultfont = sys_nearestfontsize(atoi(argv[1]));
- argc -= 2;
- argv += 2;
- }
- else if (!strcmp(*argv, "-verbose"))
- {
- sys_verbose = 1;
- argc--; argv++;
- }
- else if (!strcmp(*argv, "-version"))
- {
- sys_version = 1;
- argc--; argv++;
- }
- else if (!strcmp(*argv, "-d") && argc > 1 &&
- sscanf(argv[1], "%d", &sys_debuglevel) >= 1)
- {
- argc -= 2;
- argv += 2;
- }
- else if (!strcmp(*argv, "-noloadbang"))
- {
- sys_noloadbang = 1;
- argc--; argv++;
- }
- else if (!strcmp(*argv, "-nogui"))
- {
- sys_nogui = 1;
- argc--; argv++;
- }
- else if (!strcmp(*argv, "-guicmd") && argc > 1)
- {
- sys_guicmd = argv[1];
- argc -= 2; argv += 2;
- }
- else if (!strcmp(*argv, "-send") && argc > 1)
- {
- sys_messagelist = namelist_append(sys_messagelist, argv[1]);
- argc -= 2; argv += 2;
- }
- else if (!strcmp(*argv, "-listdev"))
- {
- sys_listdevs();
- argc--; argv++;
- }
-#ifdef UNIX
- else if (!strcmp(*argv, "-rt") || !strcmp(*argv, "-realtime"))
- {
- sys_hipriority = 1;
- argc--; argv++;
- }
- else if (!strcmp(*argv, "-nrt"))
- {
- sys_hipriority = 0;
- argc--; argv++;
- }
+ sys_externlist = namelist_append_files(sys_externlist, argv[1]);
+ argc -= 2; argv += 2;
+ }
+ else if (!strcmp(*argv, "-font") && argc > 1)
+ {
+ sys_defaultfont = sys_nearestfontsize(atoi(argv[1]));
+ argc -= 2;
+ argv += 2;
+ }
+ else if (!strcmp(*argv, "-verbose"))
+ {
+ sys_verbose = 1;
+ argc--; argv++;
+ }
+ else if (!strcmp(*argv, "-version"))
+ {
+ sys_version = 1;
+ argc--; argv++;
+ }
+ else if (!strcmp(*argv, "-d") && argc > 1 &&
+ sscanf(argv[1], "%d", &sys_debuglevel) >= 1)
+ {
+ argc -= 2;
+ argv += 2;
+ }
+ else if (!strcmp(*argv, "-noloadbang"))
+ {
+ sys_noloadbang = 1;
+ argc--; argv++;
+ }
+ else if (!strcmp(*argv, "-nogui"))
+ {
+ sys_printtostderr = sys_nogui = 1;
+ argc--; argv++;
+ }
+ else if (!strcmp(*argv, "-guiport") && argc > 1 &&
+ sscanf(argv[1], "%d", &sys_guisetportnumber) >= 1)
+ {
+ argc -= 2;
+ argv += 2;
+ }
+ else if (!strcmp(*argv, "-stderr"))
+ {
+ sys_printtostderr = 1;
+ argc--; argv++;
+ }
+ else if (!strcmp(*argv, "-guicmd") && argc > 1)
+ {
+ sys_guicmd = argv[1];
+ argc -= 2; argv += 2;
+ }
+ else if (!strcmp(*argv, "-send") && argc > 1)
+ {
+ sys_messagelist = namelist_append(sys_messagelist, argv[1], 1);
+ argc -= 2; argv += 2;
+ }
+ else if (!strcmp(*argv, "-listdev"))
+ {
+ sys_listdevs();
+ argc--; argv++;
+ }
+ /* jsarlo { */
+ else if (!strcmp(*argv, "-schedlib"))
+ {
+ sys_externalschedlib = 1;
+ strcpy(sys_externalschedlibname, argv[1]);
+ argv += 2;
+ argc -= 2;
+ }
+ else if (!strcmp(*argv, "-extraflags"))
+ {
+ sys_extraflags = 1;
+ strcpy(sys_extraflagsstring, argv[1]);
+ argv += 2;
+ argc -= 2;
+ }
+ /* } jsarlo */
+#ifdef UNISTD
+ else if (!strcmp(*argv, "-rt") || !strcmp(*argv, "-realtime"))
+ {
+ sys_hipriority = 1;
+ argc--; argv++;
+ }
+ else if (!strcmp(*argv, "-nrt"))
+ {
+ sys_hipriority = 0;
+ argc--; argv++;
+ }
#endif
- else if (!strcmp(*argv, "-soundindev") ||
- !strcmp(*argv, "-audioindev"))
- { /* IOhannes */
- sys_parsedevlist(&sys_nsoundin, sys_soundindevlist,
- MAXAUDIOINDEV, argv[1]);
- if (!sys_nsoundin)
- goto usage;
- argc -= 2; argv += 2;
- }
- else if (!strcmp(*argv, "-soundoutdev") ||
- !strcmp(*argv, "-audiooutdev"))
- { /* IOhannes */
- sys_parsedevlist(&sys_nsoundout, sys_soundoutdevlist,
- MAXAUDIOOUTDEV, argv[1]);
- if (!sys_nsoundout)
- goto usage;
- argc -= 2; argv += 2;
- }
- else if (!strcmp(*argv, "-sounddev") || !strcmp(*argv, "-audiodev"))
- {
- sys_parsedevlist(&sys_nsoundin, sys_soundindevlist,
- MAXAUDIOINDEV, argv[1]);
- sys_parsedevlist(&sys_nsoundout, sys_soundoutdevlist,
- MAXAUDIOOUTDEV, argv[1]);
- if (!sys_nsoundout)
- goto usage;
- argc -= 2; argv += 2;
- }
- else
- {
- unsigned int i;
- usage:
- for (i = 0; i < sizeof(usagemessage)/sizeof(*usagemessage); i++)
- fprintf(stderr, "%s", usagemessage[i]);
- return (1);
- }
+ else if (!strcmp(*argv, "-soundindev") ||
+ !strcmp(*argv, "-audioindev"))
+ { /* IOhannes */
+ sys_parsedevlist(&sys_nsoundin, sys_soundindevlist,
+ MAXAUDIOINDEV, argv[1]);
+ if (!sys_nsoundin)
+ goto usage;
+ argc -= 2; argv += 2;
+ }
+ else if (!strcmp(*argv, "-soundoutdev") ||
+ !strcmp(*argv, "-audiooutdev"))
+ { /* IOhannes */
+ sys_parsedevlist(&sys_nsoundout, sys_soundoutdevlist,
+ MAXAUDIOOUTDEV, argv[1]);
+ if (!sys_nsoundout)
+ goto usage;
+ argc -= 2; argv += 2;
+ }
+ else if (!strcmp(*argv, "-sounddev") || !strcmp(*argv, "-audiodev"))
+ {
+ sys_parsedevlist(&sys_nsoundin, sys_soundindevlist,
+ MAXAUDIOINDEV, argv[1]);
+ sys_parsedevlist(&sys_nsoundout, sys_soundoutdevlist,
+ MAXAUDIOOUTDEV, argv[1]);
+ if (!sys_nsoundout)
+ goto usage;
+ argc -= 2; argv += 2;
+ }
+ else
+ {
+ unsigned int i;
+ usage:
+ for (i = 0; i < sizeof(usagemessage)/sizeof(*usagemessage); i++)
+ fprintf(stderr, "%s", usagemessage[i]);
+ return (1);
+ }
}
if (!sys_defaultfont)
- sys_defaultfont = DEFAULTFONT;
+ sys_defaultfont = DEFAULTFONT;
for (; argc > 0; argc--, argv++)
- sys_openlist = namelist_append(sys_openlist, *argv);
+ sys_openlist = namelist_append_files(sys_openlist, *argv);
return (0);
@@ -789,36 +862,95 @@ int sys_getblksize(void)
}
/* stuff to do, once, after calling sys_argparse() -- which may itself
- be called twice because of the .pdrc hack. */
+ be called more than once (first from "settings, second from .pdrc, then
+ from command-line arguments */
static void sys_afterargparse(void)
{
char sbuf[MAXPDSTRING];
int i;
- /* add "extra" library to path */
+ int naudioindev, audioindev[MAXAUDIOINDEV], chindev[MAXAUDIOINDEV];
+ int naudiooutdev, audiooutdev[MAXAUDIOOUTDEV], choutdev[MAXAUDIOOUTDEV];
+ int nchindev, nchoutdev, rate, advance;
+ int nmidiindev = 0, midiindev[MAXMIDIINDEV];
+ int nmidioutdev = 0, midioutdev[MAXMIDIOUTDEV];
+ /* add "extra" library to path */
strncpy(sbuf, sys_libdir->s_name, MAXPDSTRING-30);
sbuf[MAXPDSTRING-30] = 0;
strcat(sbuf, "/extra");
- sys_addpath(sbuf);
- /* add "doc/5.reference" library to helppath */
+ sys_setextrapath(sbuf);
+ /* add "doc/5.reference" library to helppath */
strncpy(sbuf, sys_libdir->s_name, MAXPDSTRING-30);
sbuf[MAXPDSTRING-30] = 0;
strcat(sbuf, "/doc/5.reference");
- sys_addhelppath(sbuf);
- /* correct to make audio and MIDI device lists zero based. On
- MMIO, however, "1" really means the second device (the first one
- is "mapper" which is was not included when the command args were
- set up, so we leave it that way for compatibility. */
+ sys_helppath = namelist_append_files(sys_helppath, sbuf);
+ /* correct to make audio and MIDI device lists zero based. On
+ MMIO, however, "1" really means the second device (the first one
+ is "mapper" which is was not included when the command args were
+ set up, so we leave it that way for compatibility. */
if (!sys_mmio)
{
- for (i = 0; i < sys_nsoundin; i++)
- sys_soundindevlist[i]--;
- for (i = 0; i < sys_nsoundout; i++)
- sys_soundoutdevlist[i]--;
+ for (i = 0; i < sys_nsoundin; i++)
+ sys_soundindevlist[i]--;
+ for (i = 0; i < sys_nsoundout; i++)
+ sys_soundoutdevlist[i]--;
}
for (i = 0; i < sys_nmidiin; i++)
- sys_midiindevlist[i]--;
+ sys_midiindevlist[i]--;
for (i = 0; i < sys_nmidiout; i++)
- sys_midioutdevlist[i]--;
+ sys_midioutdevlist[i]--;
+
+ /* get the current audio parameters. These are set
+ by the preferences mechanism (sys_loadpreferences()) or
+ else are the default. Overwrite them with any results
+ of argument parsing, and store them again. */
+ sys_get_audio_params(&naudioindev, audioindev, chindev,
+ &naudiooutdev, audiooutdev, choutdev, &rate, &advance);
+ if (sys_nchin >= 0)
+ {
+ nchindev = sys_nchin;
+ for (i = 0; i < nchindev; i++)
+ chindev[i] = sys_chinlist[i];
+ }
+ else nchindev = naudioindev;
+ if (sys_nsoundin >= 0)
+ {
+ naudioindev = sys_nsoundin;
+ for (i = 0; i < naudioindev; i++)
+ audioindev[i] = sys_soundindevlist[i];
+ }
+
+ if (sys_nchout >= 0)
+ {
+ nchoutdev = sys_nchout;
+ for (i = 0; i < nchoutdev; i++)
+ choutdev[i] = sys_choutlist[i];
+ }
+ else nchoutdev = naudiooutdev;
+ if (sys_nsoundout >= 0)
+ {
+ naudiooutdev = sys_nsoundout;
+ for (i = 0; i < naudiooutdev; i++)
+ audiooutdev[i] = sys_soundoutdevlist[i];
+ }
+ if (sys_nmidiin >= 0)
+ {
+ nmidiindev = sys_nmidiin;
+ for (i = 0; i < nmidiindev; i++)
+ midiindev[i] = sys_midiindevlist[i];
+ }
+ if (sys_nmidiout >= 0)
+ {
+ nmidioutdev = sys_nmidiout;
+ for (i = 0; i < nmidioutdev; i++)
+ midioutdev[i] = sys_midioutdevlist[i];
+ }
+ if (sys_main_advance)
+ advance = sys_main_advance;
+ if (sys_main_srate)
+ rate = sys_main_srate;
+ sys_open_audio(naudioindev, audioindev, naudioindev, chindev,
+ naudiooutdev, audiooutdev, naudiooutdev, choutdev, rate, advance, 0);
+ sys_open_midi(nmidiindev, midiindev, nmidioutdev, midioutdev, 0);
}
static void sys_addreferencepath(void)
diff --git a/pd/src/s_midi.c b/pd/src/s_midi.c
index aac80f03..0cde64d7 100644
--- a/pd/src/s_midi.c
+++ b/pd/src/s_midi.c
@@ -7,7 +7,7 @@
#include "m_pd.h"
#include "s_stuff.h"
#include "m_imp.h"
-#ifdef UNIX
+#ifdef UNISTD
#include <unistd.h>
#include <sys/time.h>
#ifdef HAVE_BSTRING_H
@@ -64,22 +64,22 @@ void sys_initmidiqueue( void)
void sys_setmiditimediff(double inbuftime, double outbuftime)
{
double dactimeminusrealtime =
- .001 * clock_gettimesince(sys_midiinittime)
- - outbuftime - sys_getrealtime();
+ .001 * clock_gettimesince(sys_midiinittime)
+ - outbuftime - sys_getrealtime();
double adctimeminusrealtime =
- .001 * clock_gettimesince(sys_midiinittime)
- + inbuftime - sys_getrealtime();
+ .001 * clock_gettimesince(sys_midiinittime)
+ + inbuftime - sys_getrealtime();
if (dactimeminusrealtime > sys_newdactimeminusrealtime)
- sys_newdactimeminusrealtime = dactimeminusrealtime;
+ sys_newdactimeminusrealtime = dactimeminusrealtime;
if (adctimeminusrealtime > sys_newadctimeminusrealtime)
- sys_newadctimeminusrealtime = adctimeminusrealtime;
+ sys_newadctimeminusrealtime = adctimeminusrealtime;
if (sys_getrealtime() > sys_whenupdate)
{
- sys_dactimeminusrealtime = sys_newdactimeminusrealtime;
- sys_adctimeminusrealtime = sys_newadctimeminusrealtime;
- sys_newdactimeminusrealtime = -1e20;
- sys_newadctimeminusrealtime = -1e20;
- sys_whenupdate = sys_getrealtime() + 1;
+ sys_dactimeminusrealtime = sys_newdactimeminusrealtime;
+ sys_adctimeminusrealtime = sys_newadctimeminusrealtime;
+ sys_newdactimeminusrealtime = -1e20;
+ sys_newadctimeminusrealtime = -1e20;
+ sys_whenupdate = sys_getrealtime() + 1;
}
}
@@ -100,10 +100,10 @@ static void sys_putnext( void)
{
int portno = midi_outqueue[midi_outtail].q_portno;
if (midi_outqueue[midi_outtail].q_onebyte)
- sys_putmidibyte(portno, midi_outqueue[midi_outtail].q_byte1);
+ sys_putmidibyte(portno, midi_outqueue[midi_outtail].q_byte1);
else sys_putmidimess(portno, midi_outqueue[midi_outtail].q_byte1,
- midi_outqueue[midi_outtail].q_byte2,
- midi_outqueue[midi_outtail].q_byte3);
+ midi_outqueue[midi_outtail].q_byte2,
+ midi_outqueue[midi_outtail].q_byte3);
midi_outtail = (midi_outtail + 1 == MIDIQSIZE ? 0 : midi_outtail + 1);
}
@@ -117,23 +117,23 @@ void sys_pollmidioutqueue( void)
double midirealtime = sys_getmidioutrealtime();
#ifdef TEST_DEJITTER
if (midi_outhead == midi_outtail)
- db = 0;
+ db = 0;
#endif
while (midi_outhead != midi_outtail)
{
#ifdef TEST_DEJITTER
- if (!db)
- {
- post("out: del %f, midiRT %f logicaltime %f, RT %f dacminusRT %f",
- (midi_outqueue[midi_outtail].q_time - midirealtime),
- midirealtime, .001 * clock_gettimesince(sys_midiinittime),
- sys_getrealtime(), sys_dactimeminusrealtime);
- db = 1;
- }
+ if (!db)
+ {
+ post("out: del %f, midiRT %f logicaltime %f, RT %f dacminusRT %f",
+ (midi_outqueue[midi_outtail].q_time - midirealtime),
+ midirealtime, .001 * clock_gettimesince(sys_midiinittime),
+ sys_getrealtime(), sys_dactimeminusrealtime);
+ db = 1;
+ }
#endif
- if (midi_outqueue[midi_outtail].q_time <= midirealtime)
- sys_putnext();
- else break;
+ if (midi_outqueue[midi_outtail].q_time <= midirealtime)
+ sys_putnext();
+ else break;
}
}
@@ -142,17 +142,17 @@ static void sys_queuemidimess(int portno, int onebyte, int a, int b, int c)
t_midiqelem *midiqelem;
int newhead = midi_outhead +1;
if (newhead == MIDIQSIZE)
- newhead = 0;
- /* if FIFO is full flush an element to make room */
+ newhead = 0;
+ /* if FIFO is full flush an element to make room */
if (newhead == midi_outtail)
- sys_putnext();
+ sys_putnext();
midi_outqueue[midi_outhead].q_portno = portno;
midi_outqueue[midi_outhead].q_onebyte = onebyte;
midi_outqueue[midi_outhead].q_byte1 = a;
midi_outqueue[midi_outhead].q_byte2 = b;
midi_outqueue[midi_outhead].q_byte3 = c;
midi_outqueue[midi_outhead].q_time =
- .001 * clock_gettimesince(sys_midiinittime);
+ .001 * clock_gettimesince(sys_midiinittime);
midi_outhead = newhead;
sys_pollmidioutqueue();
}
@@ -180,7 +180,7 @@ void outmidi_controlchange(int portno, int channel, int ctl, int value)
if (value < 0) value = 0;
else if (value > 127) value = 127;
sys_queuemidimess(portno, 0, MIDI_CONTROLCHANGE + (channel & 0xf),
- ctl, value);
+ ctl, value);
}
void outmidi_programchange(int portno, int channel, int value)
@@ -188,7 +188,7 @@ void outmidi_programchange(int portno, int channel, int value)
if (value < 0) value = 0;
else if (value > 127) value = 127;
sys_queuemidimess(portno, 0,
- MIDI_PROGRAMCHANGE + (channel & 0xf), value, 0);
+ MIDI_PROGRAMCHANGE + (channel & 0xf), value, 0);
}
void outmidi_pitchbend(int portno, int channel, int value)
@@ -196,7 +196,7 @@ void outmidi_pitchbend(int portno, int channel, int value)
if (value < 0) value = 0;
else if (value > 16383) value = 16383;
sys_queuemidimess(portno, 0, MIDI_PITCHBEND + (channel & 0xf),
- (value & 127), ((value>>7) & 127));
+ (value & 127), ((value>>7) & 127));
}
void outmidi_aftertouch(int portno, int channel, int value)
@@ -213,7 +213,7 @@ void outmidi_polyaftertouch(int portno, int channel, int pitch, int value)
if (value < 0) value = 0;
else if (value > 127) value = 127;
sys_queuemidimess(portno, 0, MIDI_POLYAFTERTOUCH + (channel & 0xf),
- pitch, value);
+ pitch, value);
}
void outmidi_mclk(int portno)
@@ -229,28 +229,28 @@ typedef struct midiparser
int mp_byte1;
} t_midiparser;
-#define MIDINOTEOFF 0x80 /* 2 following 'data bytes' */
-#define MIDINOTEON 0x90 /* 2 */
-#define MIDIPOLYTOUCH 0xa0 /* 2 */
-#define MIDICONTROLCHANGE 0xb0 /* 2 */
-#define MIDIPROGRAMCHANGE 0xc0 /* 1 */
-#define MIDICHANNELTOUCH 0xd0 /* 1 */
-#define MIDIPITCHBEND 0xe0 /* 2 */
-#define MIDISTARTSYSEX 0xf0 /* (until F7) */
-#define MIDITIMECODE 0xf1 /* 1 */
-#define MIDISONGPOS 0xf2 /* 2 */
-#define MIDISONGSELECT 0xf3 /* 1 */
-#define MIDIRESERVED1 0xf4 /* ? */
-#define MIDIRESERVED2 0xf5 /* ? */
-#define MIDITUNEREQUEST 0xf6 /* 0 */
-#define MIDIENDSYSEX 0xf7 /* 0 */
-#define MIDICLOCK 0xf8 /* 0 */
-#define MIDITICK 0xf9 /* 0 */
-#define MIDISTART 0xfa /* 0 */
-#define MIDICONT 0xfb /* 0 */
-#define MIDISTOP 0xfc /* 0 */
-#define MIDIACTIVESENSE 0xfe /* 0 */
-#define MIDIRESET 0xff /* 0 */
+#define MIDINOTEOFF 0x80 /* 2 following 'data bytes' */
+#define MIDINOTEON 0x90 /* 2 */
+#define MIDIPOLYTOUCH 0xa0 /* 2 */
+#define MIDICONTROLCHANGE 0xb0 /* 2 */
+#define MIDIPROGRAMCHANGE 0xc0 /* 1 */
+#define MIDICHANNELTOUCH 0xd0 /* 1 */
+#define MIDIPITCHBEND 0xe0 /* 2 */
+#define MIDISTARTSYSEX 0xf0 /* (until F7) */
+#define MIDITIMECODE 0xf1 /* 1 */
+#define MIDISONGPOS 0xf2 /* 2 */
+#define MIDISONGSELECT 0xf3 /* 1 */
+#define MIDIRESERVED1 0xf4 /* ? */
+#define MIDIRESERVED2 0xf5 /* ? */
+#define MIDITUNEREQUEST 0xf6 /* 0 */
+#define MIDIENDSYSEX 0xf7 /* 0 */
+#define MIDICLOCK 0xf8 /* 0 */
+#define MIDITICK 0xf9 /* 0 */
+#define MIDISTART 0xfa /* 0 */
+#define MIDICONT 0xfb /* 0 */
+#define MIDISTOP 0xfc /* 0 */
+#define MIDIACTIVESENSE 0xfe /* 0 */
+#define MIDIRESET 0xff /* 0 */
/* functions in x_midi.c */
void inmidi_realtimein(int portno, int cmd);
@@ -267,99 +267,99 @@ static void sys_dispatchnextmidiin( void)
{
static t_midiparser parser[MAXMIDIINDEV], *parserp;
int portno = midi_inqueue[midi_intail].q_portno,
- byte = midi_inqueue[midi_intail].q_byte1;
+ byte = midi_inqueue[midi_intail].q_byte1;
if (!midi_inqueue[midi_intail].q_onebyte)
- bug("sys_dispatchnextmidiin");
+ bug("sys_dispatchnextmidiin");
if (portno < 0 || portno >= MAXMIDIINDEV)
- bug("sys_dispatchnextmidiin 2");
+ bug("sys_dispatchnextmidiin 2");
parserp = parser + portno;
outlet_setstacklim();
if (byte >= 0xf8)
- inmidi_realtimein(portno, byte);
+ inmidi_realtimein(portno, byte);
else
{
- inmidi_byte(portno, byte);
- if (byte & 0x80)
- {
- if (byte == MIDITUNEREQUEST || byte == MIDIRESERVED1 ||
- byte == MIDIRESERVED2)
- parserp->mp_status = 0;
- else if (byte == MIDISTARTSYSEX)
- {
- inmidi_sysex(portno, byte);
- parserp->mp_status = byte;
- }
- else if (byte == MIDIENDSYSEX)
- {
- inmidi_sysex(portno, byte);
- parserp->mp_status = 0;
- }
- else
- {
- parserp->mp_status = byte;
- }
- parserp->mp_gotbyte1 = 0;
- }
- else
- {
- int cmd = (parserp->mp_status >= 0xf0 ? parserp->mp_status :
- (parserp->mp_status & 0xf0));
- int chan = (parserp->mp_status & 0xf);
- int byte1 = parserp->mp_byte1, gotbyte1 = parserp->mp_gotbyte1;
- switch (cmd)
- {
- case MIDINOTEOFF:
- if (gotbyte1)
- inmidi_noteon(portno, chan, byte1, 0),
- parserp->mp_gotbyte1 = 0;
- else parserp->mp_byte1 = byte, parserp->mp_gotbyte1 = 1;
- break;
- case MIDINOTEON:
- if (gotbyte1)
- inmidi_noteon(portno, chan, byte1, byte),
- parserp->mp_gotbyte1 = 0;
- else parserp->mp_byte1 = byte, parserp->mp_gotbyte1 = 1;
- break;
- case MIDIPOLYTOUCH:
- if (gotbyte1)
- inmidi_polyaftertouch(portno, chan, byte1, byte),
- parserp->mp_gotbyte1 = 0;
- else parserp->mp_byte1 = byte, parserp->mp_gotbyte1 = 1;
- break;
- case MIDICONTROLCHANGE:
- if (gotbyte1)
- inmidi_controlchange(portno, chan, byte1, byte),
- parserp->mp_gotbyte1 = 0;
- else parserp->mp_byte1 = byte, parserp->mp_gotbyte1 = 1;
- break;
- case MIDIPROGRAMCHANGE:
- inmidi_programchange(portno, chan, byte);
- break;
- case MIDICHANNELTOUCH:
- inmidi_aftertouch(portno, chan, byte);
- break;
- case MIDIPITCHBEND:
- if (gotbyte1)
- inmidi_pitchbend(portno, chan, ((byte << 7) + byte1)),
- parserp->mp_gotbyte1 = 0;
- else parserp->mp_byte1 = byte, parserp->mp_gotbyte1 = 1;
- break;
- case MIDISTARTSYSEX:
- inmidi_sysex(portno, byte);
- break;
-
- /* other kinds of messages are just dropped here. We'll
- need another status byte before we start letting MIDI in
- again (no running status across "system" messages). */
- case MIDITIMECODE: /* 1 data byte*/
- break;
- case MIDISONGPOS: /* 2 */
- break;
- case MIDISONGSELECT: /* 1 */
- break;
- }
- }
+ inmidi_byte(portno, byte);
+ if (byte & 0x80)
+ {
+ if (byte == MIDITUNEREQUEST || byte == MIDIRESERVED1 ||
+ byte == MIDIRESERVED2)
+ parserp->mp_status = 0;
+ else if (byte == MIDISTARTSYSEX)
+ {
+ inmidi_sysex(portno, byte);
+ parserp->mp_status = byte;
+ }
+ else if (byte == MIDIENDSYSEX)
+ {
+ inmidi_sysex(portno, byte);
+ parserp->mp_status = 0;
+ }
+ else
+ {
+ parserp->mp_status = byte;
+ }
+ parserp->mp_gotbyte1 = 0;
+ }
+ else
+ {
+ int cmd = (parserp->mp_status >= 0xf0 ? parserp->mp_status :
+ (parserp->mp_status & 0xf0));
+ int chan = (parserp->mp_status & 0xf);
+ int byte1 = parserp->mp_byte1, gotbyte1 = parserp->mp_gotbyte1;
+ switch (cmd)
+ {
+ case MIDINOTEOFF:
+ if (gotbyte1)
+ inmidi_noteon(portno, chan, byte1, 0),
+ parserp->mp_gotbyte1 = 0;
+ else parserp->mp_byte1 = byte, parserp->mp_gotbyte1 = 1;
+ break;
+ case MIDINOTEON:
+ if (gotbyte1)
+ inmidi_noteon(portno, chan, byte1, byte),
+ parserp->mp_gotbyte1 = 0;
+ else parserp->mp_byte1 = byte, parserp->mp_gotbyte1 = 1;
+ break;
+ case MIDIPOLYTOUCH:
+ if (gotbyte1)
+ inmidi_polyaftertouch(portno, chan, byte1, byte),
+ parserp->mp_gotbyte1 = 0;
+ else parserp->mp_byte1 = byte, parserp->mp_gotbyte1 = 1;
+ break;
+ case MIDICONTROLCHANGE:
+ if (gotbyte1)
+ inmidi_controlchange(portno, chan, byte1, byte),
+ parserp->mp_gotbyte1 = 0;
+ else parserp->mp_byte1 = byte, parserp->mp_gotbyte1 = 1;
+ break;
+ case MIDIPROGRAMCHANGE:
+ inmidi_programchange(portno, chan, byte);
+ break;
+ case MIDICHANNELTOUCH:
+ inmidi_aftertouch(portno, chan, byte);
+ break;
+ case MIDIPITCHBEND:
+ if (gotbyte1)
+ inmidi_pitchbend(portno, chan, ((byte << 7) + byte1)),
+ parserp->mp_gotbyte1 = 0;
+ else parserp->mp_byte1 = byte, parserp->mp_gotbyte1 = 1;
+ break;
+ case MIDISTARTSYSEX:
+ inmidi_sysex(portno, byte);
+ break;
+
+ /* other kinds of messages are just dropped here. We'll
+ need another status byte before we start letting MIDI in
+ again (no running status across "system" messages). */
+ case MIDITIMECODE: /* 1 data byte*/
+ break;
+ case MIDISONGPOS: /* 2 */
+ break;
+ case MIDISONGSELECT: /* 1 */
+ break;
+ }
+ }
}
midi_intail = (midi_intail + 1 == MIDIQSIZE ? 0 : midi_intail + 1);
}
@@ -372,33 +372,33 @@ void sys_pollmidiinqueue( void)
double logicaltime = .001 * clock_gettimesince(sys_midiinittime);
#ifdef TEST_DEJITTER
if (midi_inhead == midi_intail)
- db = 0;
+ db = 0;
#endif
while (midi_inhead != midi_intail)
{
#ifdef TEST_DEJITTER
- if (!db)
- {
- post("in del %f, logicaltime %f, RT %f adcminusRT %f",
- (midi_inqueue[midi_intail].q_time - logicaltime),
- logicaltime, sys_getrealtime(), sys_adctimeminusrealtime);
- db = 1;
- }
+ if (!db)
+ {
+ post("in del %f, logicaltime %f, RT %f adcminusRT %f",
+ (midi_inqueue[midi_intail].q_time - logicaltime),
+ logicaltime, sys_getrealtime(), sys_adctimeminusrealtime);
+ db = 1;
+ }
#endif
#if 0
- if (midi_inqueue[midi_intail].q_time <= logicaltime - 0.007)
- post("late %f",
- 1000 * (logicaltime - midi_inqueue[midi_intail].q_time));
+ if (midi_inqueue[midi_intail].q_time <= logicaltime - 0.007)
+ post("late %f",
+ 1000 * (logicaltime - midi_inqueue[midi_intail].q_time));
#endif
- if (midi_inqueue[midi_intail].q_time <= logicaltime)
- {
+ if (midi_inqueue[midi_intail].q_time <= logicaltime)
+ {
#if 0
- post("diff %f",
- 1000* (logicaltime - midi_inqueue[midi_intail].q_time));
+ post("diff %f",
+ 1000* (logicaltime - midi_inqueue[midi_intail].q_time));
#endif
- sys_dispatchnextmidiin();
- }
- else break;
+ sys_dispatchnextmidiin();
+ }
+ else break;
}
}
@@ -413,16 +413,16 @@ void sys_midibytein(int portno, int byte)
t_midiqelem *midiqelem;
int newhead = midi_inhead +1;
if (newhead == MIDIQSIZE)
- newhead = 0;
- /* if FIFO is full flush an element to make room */
+ newhead = 0;
+ /* if FIFO is full flush an element to make room */
if (newhead == midi_intail)
{
- if (!warned)
- {
- post("warning: MIDI timing FIFO overflowed");
- warned = 1;
- }
- sys_dispatchnextmidiin();
+ if (!warned)
+ {
+ post("warning: MIDI timing FIFO overflowed");
+ warned = 1;
+ }
+ sys_dispatchnextmidiin();
}
midi_inqueue[midi_inhead].q_portno = portno;
midi_inqueue[midi_inhead].q_onebyte = 1;
@@ -438,10 +438,10 @@ void sys_pollmidiqueue( void)
static double lasttime;
double newtime = sys_getrealtime();
if (newtime - lasttime > 0.007)
- post("delay %d", (int)(1000 * (newtime - lasttime)));
+ post("delay %d", (int)(1000 * (newtime - lasttime)));
lasttime = newtime;
#endif
- sys_poll_midi(); /* OS dependent poll for MIDI input */
+ sys_poll_midi(); /* OS dependent poll for MIDI input */
sys_pollmidioutqueue();
sys_pollmidiinqueue();
}
@@ -458,16 +458,16 @@ static int midi_midiindev[MAXMIDIINDEV];
static int midi_nmidioutdev;
static int midi_midioutdev[MAXMIDIOUTDEV];
-static void sys_get_midi_params(int *pnmidiindev, int *pmidiindev,
+void sys_get_midi_params(int *pnmidiindev, int *pmidiindev,
int *pnmidioutdev, int *pmidioutdev)
{
int i;
*pnmidiindev = midi_nmidiindev;
for (i = 0; i < MAXMIDIINDEV; i++)
- pmidiindev[i] = midi_midiindev[i];
+ pmidiindev[i] = midi_midiindev[i];
*pnmidioutdev = midi_nmidioutdev;
for (i = 0; i < MAXMIDIOUTDEV; i++)
- pmidioutdev[i] = midi_midioutdev[i];
+ pmidioutdev[i] = midi_midioutdev[i];
}
static void sys_save_midi_params(
@@ -477,21 +477,22 @@ static void sys_save_midi_params(
int i;
midi_nmidiindev = nmidiindev;
for (i = 0; i < MAXMIDIINDEV; i++)
- midi_midiindev[i] = midiindev[i];
+ midi_midiindev[i] = midiindev[i];
midi_nmidioutdev = nmidioutdev;
for (i = 0; i < MAXMIDIOUTDEV; i++)
- midi_midioutdev[i] = midioutdev[i];
+ midi_midioutdev[i] = midioutdev[i];
}
void sys_open_midi(int nmidiindev, int *midiindev,
- int nmidioutdev, int *midioutdev)
+ int nmidioutdev, int *midioutdev, int enable)
{
#ifdef USEAPI_OSS
midi_oss_init();
#endif
- sys_do_open_midi(nmidiindev, midiindev, nmidioutdev, midioutdev);
+ if (enable)
+ sys_do_open_midi(nmidiindev, midiindev, nmidioutdev, midioutdev);
sys_save_midi_params(nmidiindev, midiindev,
- nmidioutdev, midioutdev);
+ nmidioutdev, midioutdev);
}
/* open midi using whatever parameters were last used */
@@ -500,7 +501,7 @@ void sys_reopen_midi( void)
int nmidiindev, midiindev[MAXMIDIINDEV];
int nmidioutdev, midioutdev[MAXMIDIOUTDEV];
sys_get_midi_params(&nmidiindev, midiindev, &nmidioutdev, midioutdev);
- sys_open_midi(nmidiindev, midiindev, nmidioutdev, midioutdev);
+ sys_open_midi(nmidiindev, midiindev, nmidioutdev, midioutdev, 1);
}
#define MAXNDEV 20
@@ -508,7 +509,7 @@ void sys_reopen_midi( void)
#ifdef MSW
#define DEVONSET 0 /* microsoft device list starts at 0 (the "mapper"). */
-#else /* (see also MSW ifdef in sys_parsedevlist(), s_main.c) */
+#else /* (see also MSW ifdef in sys_parsedevlist(), s_main.c) */
#define DEVONSET 1 /* To agree with command line flags, normally start at 1 */
#endif
@@ -518,23 +519,23 @@ void sys_listmididevs(void )
int nindevs = 0, noutdevs = 0, i;
midi_getdevs(indevlist, &nindevs, outdevlist, &noutdevs,
- MAXNDEV, DEVDESCSIZE);
+ MAXNDEV, DEVDESCSIZE);
if (!nindevs)
- post("no midi input devices found");
+ post("no midi input devices found");
else
{
- post("input devices:");
- for (i = 0; i < nindevs; i++)
- post("%d. %s", i+1, indevlist + i * DEVDESCSIZE);
+ post("input devices:");
+ for (i = 0; i < nindevs; i++)
+ post("%d. %s", i+1, indevlist + i * DEVDESCSIZE);
}
if (!noutdevs)
- post("no midi output devices found");
+ post("no midi output devices found");
else
{
- post("output devices:");
- for (i = 0; i < noutdevs; i++)
- post("%d. %s", i+DEVONSET, outdevlist + i * DEVDESCSIZE);
+ post("output devices:");
+ for (i = 0; i < noutdevs; i++)
+ post("%d. %s", i+DEVONSET, outdevlist + i * DEVDESCSIZE);
}
}
@@ -544,44 +545,44 @@ extern t_class *glob_pdobject;
void glob_midi_properties(t_pd *dummy, t_floatarg flongform)
{
char buf[1024 + 2 * MAXNDEV*(DEVDESCSIZE+4)];
- /* these are the devices you're using: */
+ /* these are the devices you're using: */
int nindev, midiindev[MAXMIDIINDEV];
int noutdev, midioutdev[MAXMIDIOUTDEV];
int midiindev1, midiindev2, midiindev3, midiindev4,
- midioutdev1, midioutdev2, midioutdev3, midioutdev4;
+ midioutdev1, midioutdev2, midioutdev3, midioutdev4;
- /* these are all the devices on your system: */
+ /* these are all the devices on your system: */
char indevlist[MAXNDEV*DEVDESCSIZE], outdevlist[MAXNDEV*DEVDESCSIZE];
int nindevs = 0, noutdevs = 0, i;
char indevliststring[MAXNDEV*(DEVDESCSIZE+4)+80],
- outdevliststring[MAXNDEV*(DEVDESCSIZE+4)+80];
+ outdevliststring[MAXNDEV*(DEVDESCSIZE+4)+80];
midi_getdevs(indevlist, &nindevs, outdevlist, &noutdevs,
- MAXNDEV, DEVDESCSIZE);
+ MAXNDEV, DEVDESCSIZE);
strcpy(indevliststring, "{ {none} ");
for (i = 0; i < nindevs; i++)
{
- strcat(indevliststring, "\"");
- strcat(indevliststring, indevlist + i * DEVDESCSIZE);
- strcat(indevliststring, "\" ");
+ strcat(indevliststring, "\"");
+ strcat(indevliststring, indevlist + i * DEVDESCSIZE);
+ strcat(indevliststring, "\" ");
}
strcat(indevliststring, "}");
strcpy(outdevliststring, "{ {none} ");
for (i = 0; i < noutdevs; i++)
{
- strcat(outdevliststring, "\"");
- strcat(outdevliststring, outdevlist + i * DEVDESCSIZE);
- strcat(outdevliststring, "\" ");
+ strcat(outdevliststring, "\"");
+ strcat(outdevliststring, outdevlist + i * DEVDESCSIZE);
+ strcat(outdevliststring, "\" ");
}
strcat(outdevliststring, "}");
sys_get_midi_params(&nindev, midiindev, &noutdev, midioutdev);
if (nindev > 1 || noutdev > 1)
- flongform = 1;
+ flongform = 1;
midiindev1 = (nindev > 0 && midiindev[0]>= 0 ? midiindev[0]+1 : 0);
midiindev2 = (nindev > 1 && midiindev[1]>= 0 ? midiindev[1]+1 : 0);
@@ -596,11 +597,11 @@ void glob_midi_properties(t_pd *dummy, t_floatarg flongform)
"pdtk_midi_dialog %%s \
%s %d %d %d %d %s %d %d %d %d \
%d\n",
- indevliststring,
- midiindev1, midiindev2, midiindev3, midiindev4,
- outdevliststring,
- midioutdev1, midioutdev2, midioutdev3, midioutdev4,
- (flongform != 0));
+ indevliststring,
+ midiindev1, midiindev2, midiindev3, midiindev4,
+ outdevliststring,
+ midioutdev1, midioutdev2, midioutdev3, midioutdev4,
+ (flongform != 0));
gfxstub_deleteforkey(0);
gfxstub_new(&glob_pdobject, glob_midi_properties, buf);
}
@@ -615,27 +616,27 @@ void glob_midi_dialog(t_pd *dummy, t_symbol *s, int argc, t_atom *argv)
for (i = 0; i < 4; i++)
{
- newmidiindev[i] = atom_getintarg(i, argc, argv);
- newmidioutdev[i] = atom_getintarg(i+4, argc, argv);
+ newmidiindev[i] = atom_getintarg(i, argc, argv);
+ newmidioutdev[i] = atom_getintarg(i+4, argc, argv);
}
for (i = 0, nindev = 0; i < 4; i++)
{
- if (newmidiindev[i] > 0)
- {
- newmidiindev[nindev] = newmidiindev[i]-1;
- nindev++;
- }
+ if (newmidiindev[i] > 0)
+ {
+ newmidiindev[nindev] = newmidiindev[i]-1;
+ nindev++;
+ }
}
for (i = 0, noutdev = 0; i < 4; i++)
{
- if (newmidioutdev[i] > 0)
- {
- newmidioutdev[noutdev] = newmidioutdev[i]-1;
- noutdev++;
- }
+ if (newmidioutdev[i] > 0)
+ {
+ newmidioutdev[noutdev] = newmidioutdev[i]-1;
+ noutdev++;
+ }
}
sys_close_midi();
- sys_open_midi(nindev, newmidiindev, noutdev, newmidioutdev);
+ sys_open_midi(nindev, newmidiindev, noutdev, newmidioutdev, 1);
}
diff --git a/pd/src/s_midi_mmio.c b/pd/src/s_midi_mmio.c
index 99b38906..91b724fa 100644
--- a/pd/src/s_midi_mmio.c
+++ b/pd/src/s_midi_mmio.c
@@ -33,25 +33,25 @@ static void msw_midisync(void)
if (initsystime == -1) msw_resetmidisync();
jittersec = (msw_dacjitterbufsallowed > msw_adcjitterbufsallowed ?
- msw_dacjitterbufsallowed : msw_adcjitterbufsallowed)
- * REALDACBLKSIZE / sys_getsr();
+ msw_dacjitterbufsallowed : msw_adcjitterbufsallowed)
+ * REALDACBLKSIZE / sys_getsr();
diff = sys_getrealtime() - 0.001 * clock_gettimesince(initsystime);
if (diff > msw_hibuftime) msw_hibuftime = diff;
if (diff < msw_hibuftime - jittersec)
{
- post("jitter excess %d %f", dac, diff);
- msw_resetmidisync();
+ post("jitter excess %d %f", dac, diff);
+ msw_resetmidisync();
}
}
static double msw_midigettimefor(LARGE_INTEGER timestamp)
{
/* this is broken now... used to work when "timestamp" was derived from
- QueryPerformanceCounter() instead of the gates approved
- timeGetSystemTime() call in the MIDI callback routine below. */
+ QueryPerformanceCounter() instead of the gates approved
+ timeGetSystemTime() call in the MIDI callback routine below. */
return (msw_tixtotime(timestamp) - msw_hibuftime);
}
-#endif /* MIDI_TIMESTAMP */
+#endif /* MIDI_TIMESTAMP */
/* ------------------------- MIDI output -------------------------- */
@@ -63,7 +63,7 @@ static void msw_midiouterror(char *s, int err)
}
static HMIDIOUT hMidiOut[MAXMIDIOUTDEV]; /* output device */
-static int msw_nmidiout; /* number of devices */
+static int msw_nmidiout; /* number of devices */
static void msw_open_midiout(int nmidiout, int *midioutvec)
{
@@ -72,30 +72,30 @@ static void msw_open_midiout(int nmidiout, int *midioutvec)
int dev;
MIDIOUTCAPS midioutcaps;
if (nmidiout > MAXMIDIOUTDEV)
- nmidiout = MAXMIDIOUTDEV;
+ nmidiout = MAXMIDIOUTDEV;
dev = 0;
for (i = 0; i < nmidiout; i++)
{
- MIDIOUTCAPS mocap;
- int devno = midioutvec[i];
- result = midiOutOpen(&hMidiOut[dev], devno, 0, 0,
- CALLBACK_NULL);
- wRtn = midiOutGetDevCaps(i, (LPMIDIOUTCAPS) &mocap,
+ MIDIOUTCAPS mocap;
+ int devno = midioutvec[i];
+ result = midiOutOpen(&hMidiOut[dev], devno, 0, 0,
+ CALLBACK_NULL);
+ wRtn = midiOutGetDevCaps(i, (LPMIDIOUTCAPS) &mocap,
sizeof(mocap));
- if (result != MMSYSERR_NOERROR)
- {
- fprintf(stderr,"midiOutOpen: %s\n",midioutcaps.szPname);
- msw_midiouterror("midiOutOpen: %s\n", result);
- }
- else
- {
- if (sys_verbose)
- fprintf(stderr,"midiOutOpen: Open %s as Port %d\n",
- midioutcaps.szPname, dev);
- dev++;
- }
+ if (result != MMSYSERR_NOERROR)
+ {
+ fprintf(stderr,"midiOutOpen: %s\n",midioutcaps.szPname);
+ msw_midiouterror("midiOutOpen: %s\n", result);
+ }
+ else
+ {
+ if (sys_verbose)
+ fprintf(stderr,"midiOutOpen: Open %s as Port %d\n",
+ midioutcaps.szPname, dev);
+ dev++;
+ }
}
msw_nmidiout = dev;
}
@@ -105,8 +105,8 @@ static void msw_close_midiout(void)
int i;
for (i = 0; i < msw_nmidiout; i++)
{
- midiOutReset(hMidiOut[i]);
- midiOutClose(hMidiOut[i]);
+ midiOutReset(hMidiOut[i]);
+ midiOutClose(hMidiOut[i]);
}
msw_nmidiout = 0;
}
@@ -177,9 +177,9 @@ WORD FAR PASCAL GetEvent(LPCIRCULARBUFFER lpBuf, LPEVENT lpEvent);
// Callback instance data pointers
LPCALLBACKINSTANCEDATA lpCallbackInstanceData[MAXMIDIINDEV];
-UINT wNumDevices = 0; // Number of MIDI input devices opened
+UINT wNumDevices = 0; // Number of MIDI input devices opened
BOOL bRecordingEnabled = 1; // Enable/disable recording flag
-int nNumBufferLines = 0; // Number of lines in display buffer
+int nNumBufferLines = 0; // Number of lines in display buffer
RECT rectScrollClip; // Clipping rectangle for scrolling
LPCIRCULARBUFFER lpInputBuffer; // Input buffer structure
@@ -386,7 +386,7 @@ void FreeCircularBuffer(LPCIRCULARBUFFER lpBuf)
*/
WORD FAR PASCAL GetEvent(LPCIRCULARBUFFER lpBuf, LPEVENT lpEvent)
{
- /* If no event available, return */
+ /* If no event available, return */
if (!wNumDevices || lpBuf->dwCount <= 0) return (0);
/* Get the event.
@@ -542,7 +542,7 @@ void msw_open_midiin(int nmidiin, int *midiinvec)
FreeCallbackInstanceData(lpCallbackInstanceData[ndev]);
msw_midiinerror("midiInOpen: %s\n", wRtn);
}
- else ndev++;
+ else ndev++;
}
/* Start MIDI input.
@@ -564,9 +564,9 @@ static void msw_close_midiin(void)
for (i=0; (i<wNumDevices) && (i<MAXMIDIINDEV); i++)
{
if (hMidiIn[i])
- {
- if (sys_verbose)
- post("closing MIDI input %d...", i);
+ {
+ if (sys_verbose)
+ post("closing MIDI input %d...", i);
midiInStop(hMidiIn[i]);
midiInReset(hMidiIn[i]);
midiInClose(hMidiIn[i]);
@@ -577,10 +577,10 @@ static void msw_close_midiin(void)
/* Free input buffer.
*/
if (lpInputBuffer)
- FreeCircularBuffer(lpInputBuffer);
+ FreeCircularBuffer(lpInputBuffer);
if (sys_verbose)
- post("...done");
+ post("...done");
wNumDevices = 0;
}
@@ -592,10 +592,10 @@ void sys_putmidimess(int portno, int a, int b, int c)
MMRESULT res;
if (portno >= 0 && portno < msw_nmidiout)
{
- foo = (a & 0xff) | ((b & 0xff) << 8) | ((c & 0xff) << 16);
- res = midiOutShortMsg(hMidiOut[portno], foo);
- if (res != MMSYSERR_NOERROR)
- post("MIDI out error %d", res);
+ foo = (a & 0xff) | ((b & 0xff) << 8) | ((c & 0xff) << 16);
+ res = midiOutShortMsg(hMidiOut[portno], foo);
+ if (res != MMSYSERR_NOERROR)
+ post("MIDI out error %d", res);
}
}
@@ -604,9 +604,9 @@ void sys_putmidibyte(int portno, int byte)
MMRESULT res;
if (portno >= 0 && portno < msw_nmidiout)
{
- res = midiOutShortMsg(hMidiOut[portno], byte);
- if (res != MMSYSERR_NOERROR)
- post("MIDI out error %d", res);
+ res = midiOutShortMsg(hMidiOut[portno], byte);
+ if (res != MMSYSERR_NOERROR)
+ post("MIDI out error %d", res);
}
}
@@ -618,45 +618,45 @@ void sys_poll_midi(void)
while (1)
{
- if (!msw_isnextevent)
- {
- if (!GetEvent(lpInputBuffer, &msw_nextevent)) break;
- msw_isnextevent = 1;
+ if (!msw_isnextevent)
+ {
+ if (!GetEvent(lpInputBuffer, &msw_nextevent)) break;
+ msw_isnextevent = 1;
#ifdef MIDI_TIMESTAMP
- msw_nexteventtime = msw_midigettimefor(&foo.timestamp);
+ msw_nexteventtime = msw_midigettimefor(&foo.timestamp);
#endif
- }
+ }
#ifdef MIDI_TIMESTAMP
- if (0.001 * clock_gettimesince(initsystime) >= msw_nexteventtime)
+ if (0.001 * clock_gettimesince(initsystime) >= msw_nexteventtime)
#endif
- {
- int msgtype = ((msw_nextevent.data & 0xf0) >> 4) - 8;
- int commandbyte = msw_nextevent.data & 0xff;
- int byte1 = (msw_nextevent.data >> 8) & 0xff;
- int byte2 = (msw_nextevent.data >> 16) & 0xff;
- int portno = msw_nextevent.dwDevice;
- switch (msgtype)
- {
- case 0:
- case 1:
- case 2:
- case 3:
- case 6:
- sys_midibytein(portno, commandbyte);
- sys_midibytein(portno, byte1);
- sys_midibytein(portno, byte2);
- break;
- case 4:
- case 5:
- sys_midibytein(portno, commandbyte);
- sys_midibytein(portno, byte1);
- break;
- case 7:
- sys_midibytein(portno, commandbyte);
- break;
- }
- msw_isnextevent = 0;
- }
+ {
+ int msgtype = ((msw_nextevent.data & 0xf0) >> 4) - 8;
+ int commandbyte = msw_nextevent.data & 0xff;
+ int byte1 = (msw_nextevent.data >> 8) & 0xff;
+ int byte2 = (msw_nextevent.data >> 16) & 0xff;
+ int portno = msw_nextevent.dwDevice;
+ switch (msgtype)
+ {
+ case 0:
+ case 1:
+ case 2:
+ case 3:
+ case 6:
+ sys_midibytein(portno, commandbyte);
+ sys_midibytein(portno, byte1);
+ sys_midibytein(portno, byte2);
+ break;
+ case 4:
+ case 5:
+ sys_midibytein(portno, commandbyte);
+ sys_midibytein(portno, byte1);
+ break;
+ case 7:
+ sys_midibytein(portno, commandbyte);
+ break;
+ }
+ msw_isnextevent = 0;
+ }
}
}
@@ -664,14 +664,13 @@ void sys_do_open_midi(int nmidiin, int *midiinvec,
int nmidiout, int *midioutvec)
{
if (nmidiout)
- msw_open_midiout(nmidiout, midioutvec);
+ msw_open_midiout(nmidiout, midioutvec);
if (nmidiin)
{
- post(
- "midi input enabled; warning, don't close the DOS window directly!");
- msw_open_midiin(nmidiin, midiinvec);
+ post(
+ "Warning: midi input is dangerous in Microsoft Windows; see Pd manual)");
+ msw_open_midiin(nmidiin, midiinvec);
}
- else post("not using MIDI input (use 'pd -midiindev 1' to override)");
}
void sys_close_midi( void)
@@ -688,28 +687,28 @@ void sys_listmididevs(void)
unsigned int i;
/* for MIDI and audio in and out, get the number of devices.
- Then get the capabilities of each device and print its description. */
+ Then get the capabilities of each device and print its description. */
ndevices = midiInGetNumDevs();
for (i = 0; i < ndevices; i++)
{
- MIDIINCAPS micap;
- wRtn = midiInGetDevCaps(i, (LPMIDIINCAPS) &micap,
+ MIDIINCAPS micap;
+ wRtn = midiInGetDevCaps(i, (LPMIDIINCAPS) &micap,
sizeof(micap));
if (wRtn) msw_midiinerror("midiInGetDevCaps: %s\n", wRtn);
- else fprintf(stderr,
- "MIDI input device #%d: %s\n", i+1, micap.szPname);
+ else fprintf(stderr,
+ "MIDI input device #%d: %s\n", i+1, micap.szPname);
}
ndevices = midiOutGetNumDevs();
for (i = 0; i < ndevices; i++)
{
- MIDIOUTCAPS mocap;
- wRtn = midiOutGetDevCaps(i, (LPMIDIOUTCAPS) &mocap,
+ MIDIOUTCAPS mocap;
+ wRtn = midiOutGetDevCaps(i, (LPMIDIOUTCAPS) &mocap,
sizeof(mocap));
if (wRtn) msw_midiouterror("midiOutGetDevCaps: %s\n", wRtn);
- else fprintf(stderr,
- "MIDI output device #%d: %s\n", i+1, mocap.szPname);
+ else fprintf(stderr,
+ "MIDI output device #%d: %s\n", i+1, mocap.szPname);
}
}
@@ -721,23 +720,23 @@ void midi_getdevs(char *indevlist, int *nindevs,
int i, nin = midiInGetNumDevs(), nout = midiOutGetNumDevs();
UINT wRtn;
if (nin > maxndev)
- nin = maxndev;
+ nin = maxndev;
for (i = 0; i < nin; i++)
{
- MIDIINCAPS micap;
- wRtn = midiInGetDevCaps(i, (LPMIDIINCAPS) &micap, sizeof(micap));
- strncpy(indevlist + i * devdescsize,
- (wRtn ? "???" : micap.szPname), devdescsize);
+ MIDIINCAPS micap;
+ wRtn = midiInGetDevCaps(i, (LPMIDIINCAPS) &micap, sizeof(micap));
+ strncpy(indevlist + i * devdescsize,
+ (wRtn ? "???" : micap.szPname), devdescsize);
indevlist[(i+1) * devdescsize - 1] = 0;
}
if (nout > maxndev)
- nout = maxndev;
+ nout = maxndev;
for (i = 0; i < nout; i++)
{
- MIDIOUTCAPS mocap;
- wRtn = midiOutGetDevCaps(i, (LPMIDIOUTCAPS) &mocap, sizeof(mocap));
- strncpy(outdevlist + i * devdescsize,
- (wRtn ? "???" : mocap.szPname), devdescsize);
+ MIDIOUTCAPS mocap;
+ wRtn = midiOutGetDevCaps(i, (LPMIDIOUTCAPS) &mocap, sizeof(mocap));
+ strncpy(outdevlist + i * devdescsize,
+ (wRtn ? "???" : mocap.szPname), devdescsize);
outdevlist[(i+1) * devdescsize - 1] = 0;
}
*nindevs = nin;
diff --git a/pd/src/s_midi_oss.c b/pd/src/s_midi_oss.c
index 4d77e412..354dc0d5 100644
--- a/pd/src/s_midi_oss.c
+++ b/pd/src/s_midi_oss.c
@@ -6,7 +6,7 @@
/* MIDI I/O for Linux using OSS */
#include <stdio.h>
-#ifdef UNIX
+#ifdef UNISTD
#include <unistd.h>
#endif
#include <stdlib.h>
@@ -26,7 +26,7 @@ static void oss_midiout(int fd, int n)
{
char b = n;
if ((write(fd, (char *) &b, 1)) != 1)
- perror("midi write");
+ perror("midi write");
}
#define O_MIDIFLAG O_NDELAY
@@ -36,120 +36,120 @@ void sys_do_open_midi(int nmidiin, int *midiinvec,
{
int i;
for (i = 0; i < nmidiout; i++)
- oss_midioutfd[i] = -1;
+ oss_midioutfd[i] = -1;
for (i = 0, oss_nmidiin = 0; i < nmidiin; i++)
{
- int fd = -1, j, outdevindex = -1;
- char namebuf[80];
- int devno = midiinvec[i];
+ int fd = -1, j, outdevindex = -1;
+ char namebuf[80];
+ int devno = midiinvec[i];
- for (j = 0; j < nmidiout; j++)
- if (midioutvec[j] == midiinvec[i])
- outdevindex = j;
-
- /* try to open the device for read/write. */
- if (devno == 0 && fd < 0 && outdevindex >= 0)
- {
- sys_setalarm(1000000);
- fd = open("/dev/midi", O_RDWR | O_MIDIFLAG);
- if (sys_verbose)
- fprintf(stderr,
- "device 1: tried /dev/midi READ/WRITE; returned %d\n", fd);
- if (outdevindex >= 0 && fd >= 0)
- oss_midioutfd[outdevindex] = fd;
- }
- if (fd < 0 && outdevindex >= 0)
- {
- sys_setalarm(1000000);
- sprintf(namebuf, "/dev/midi%2.2d", devno);
- fd = open(namebuf, O_RDWR | O_MIDIFLAG);
- if (sys_verbose)
- fprintf(stderr,
- "device %d: tried %s READ/WRITE; returned %d\n",
- devno, namebuf, fd);
- if (outdevindex >= 0 && fd >= 0)
- oss_midioutfd[outdevindex] = fd;
- }
- if (fd < 0 && outdevindex >= 0)
- {
- sys_setalarm(1000000);
- sprintf(namebuf, "/dev/midi%d", devno);
- fd = open(namebuf, O_RDWR | O_MIDIFLAG);
- if (sys_verbose)
- fprintf(stderr, "device %d: tried %s READ/WRITE; returned %d\n",
- devno, namebuf, fd);
- if (outdevindex >= 0 && fd >= 0)
- oss_midioutfd[outdevindex] = fd;
- }
- if (devno == 1 && fd < 0)
- {
- sys_setalarm(1000000);
- fd = open("/dev/midi", O_RDONLY | O_MIDIFLAG);
- if (sys_verbose)
- fprintf(stderr,
- "device 1: tried /dev/midi READONLY; returned %d\n", fd);
- }
- if (fd < 0)
- {
- sys_setalarm(1000000);
- sprintf(namebuf, "/dev/midi%2.2d", devno);
- fd = open(namebuf, O_RDONLY | O_MIDIFLAG);
- if (sys_verbose)
- fprintf(stderr, "device %d: tried %s READONLY; returned %d\n",
- devno, namebuf, fd);
- }
- if (fd < 0)
- {
- sys_setalarm(1000000);
- sprintf(namebuf, "/dev/midi%d", devno);
- fd = open(namebuf, O_RDONLY | O_MIDIFLAG);
- if (sys_verbose)
- fprintf(stderr, "device %d: tried %s READONLY; returned %d\n",
- devno, namebuf, fd);
- }
- if (fd >= 0)
- oss_midiinfd[oss_nmidiin++] = fd;
- else post("couldn't open MIDI input device %d", devno);
+ for (j = 0; j < nmidiout; j++)
+ if (midioutvec[j] == midiinvec[i])
+ outdevindex = j;
+
+ /* try to open the device for read/write. */
+ if (devno == 0 && fd < 0 && outdevindex >= 0)
+ {
+ sys_setalarm(1000000);
+ fd = open("/dev/midi", O_RDWR | O_MIDIFLAG);
+ if (sys_verbose)
+ fprintf(stderr,
+ "device 1: tried /dev/midi READ/WRITE; returned %d\n", fd);
+ if (outdevindex >= 0 && fd >= 0)
+ oss_midioutfd[outdevindex] = fd;
+ }
+ if (fd < 0 && outdevindex >= 0)
+ {
+ sys_setalarm(1000000);
+ sprintf(namebuf, "/dev/midi%2.2d", devno);
+ fd = open(namebuf, O_RDWR | O_MIDIFLAG);
+ if (sys_verbose)
+ fprintf(stderr,
+ "device %d: tried %s READ/WRITE; returned %d\n",
+ devno, namebuf, fd);
+ if (outdevindex >= 0 && fd >= 0)
+ oss_midioutfd[outdevindex] = fd;
+ }
+ if (fd < 0 && outdevindex >= 0)
+ {
+ sys_setalarm(1000000);
+ sprintf(namebuf, "/dev/midi%d", devno);
+ fd = open(namebuf, O_RDWR | O_MIDIFLAG);
+ if (sys_verbose)
+ fprintf(stderr, "device %d: tried %s READ/WRITE; returned %d\n",
+ devno, namebuf, fd);
+ if (outdevindex >= 0 && fd >= 0)
+ oss_midioutfd[outdevindex] = fd;
+ }
+ if (devno == 1 && fd < 0)
+ {
+ sys_setalarm(1000000);
+ fd = open("/dev/midi", O_RDONLY | O_MIDIFLAG);
+ if (sys_verbose)
+ fprintf(stderr,
+ "device 1: tried /dev/midi READONLY; returned %d\n", fd);
+ }
+ if (fd < 0)
+ {
+ sys_setalarm(1000000);
+ sprintf(namebuf, "/dev/midi%2.2d", devno);
+ fd = open(namebuf, O_RDONLY | O_MIDIFLAG);
+ if (sys_verbose)
+ fprintf(stderr, "device %d: tried %s READONLY; returned %d\n",
+ devno, namebuf, fd);
+ }
+ if (fd < 0)
+ {
+ sys_setalarm(1000000);
+ sprintf(namebuf, "/dev/midi%d", devno);
+ fd = open(namebuf, O_RDONLY | O_MIDIFLAG);
+ if (sys_verbose)
+ fprintf(stderr, "device %d: tried %s READONLY; returned %d\n",
+ devno, namebuf, fd);
+ }
+ if (fd >= 0)
+ oss_midiinfd[oss_nmidiin++] = fd;
+ else post("couldn't open MIDI input device %d", devno);
}
for (i = 0, oss_nmidiout = 0; i < nmidiout; i++)
{
- int fd = oss_midioutfd[i];
- char namebuf[80];
- int devno = midioutvec[i];
- if (devno == 1 && fd < 0)
- {
- sys_setalarm(1000000);
- fd = open("/dev/midi", O_WRONLY | O_MIDIFLAG);
- if (sys_verbose)
- fprintf(stderr,
- "device 1: tried /dev/midi WRITEONLY; returned %d\n", fd);
- }
- if (fd < 0)
- {
- sys_setalarm(1000000);
- sprintf(namebuf, "/dev/midi%2.2d", devno);
- fd = open(namebuf, O_WRONLY | O_MIDIFLAG);
- if (sys_verbose)
- fprintf(stderr, "device %d: tried %s WRITEONLY; returned %d\n",
- devno, namebuf, fd);
- }
- if (fd < 0)
- {
- sys_setalarm(1000000);
- sprintf(namebuf, "/dev/midi%d", devno);
- fd = open(namebuf, O_WRONLY | O_MIDIFLAG);
- if (sys_verbose)
- fprintf(stderr, "device %d: tried %s WRITEONLY; returned %d\n",
- devno, namebuf, fd);
- }
- if (fd >= 0)
- oss_midioutfd[oss_nmidiout++] = fd;
- else post("couldn't open MIDI output device %d", devno);
+ int fd = oss_midioutfd[i];
+ char namebuf[80];
+ int devno = midioutvec[i];
+ if (devno == 1 && fd < 0)
+ {
+ sys_setalarm(1000000);
+ fd = open("/dev/midi", O_WRONLY | O_MIDIFLAG);
+ if (sys_verbose)
+ fprintf(stderr,
+ "device 1: tried /dev/midi WRITEONLY; returned %d\n", fd);
+ }
+ if (fd < 0)
+ {
+ sys_setalarm(1000000);
+ sprintf(namebuf, "/dev/midi%2.2d", devno);
+ fd = open(namebuf, O_WRONLY | O_MIDIFLAG);
+ if (sys_verbose)
+ fprintf(stderr, "device %d: tried %s WRITEONLY; returned %d\n",
+ devno, namebuf, fd);
+ }
+ if (fd < 0)
+ {
+ sys_setalarm(1000000);
+ sprintf(namebuf, "/dev/midi%d", devno);
+ fd = open(namebuf, O_WRONLY | O_MIDIFLAG);
+ if (sys_verbose)
+ fprintf(stderr, "device %d: tried %s WRITEONLY; returned %d\n",
+ devno, namebuf, fd);
+ }
+ if (fd >= 0)
+ oss_midioutfd[oss_nmidiout++] = fd;
+ else post("couldn't open MIDI output device %d", devno);
}
if (oss_nmidiin < nmidiin || oss_nmidiout < nmidiout || sys_verbose)
- post("opened %d MIDI input device(s) and %d MIDI output device(s).",
- oss_nmidiin, oss_nmidiout);
+ post("opened %d MIDI input device(s) and %d MIDI output device(s).",
+ oss_nmidiin, oss_nmidiout);
sys_setalarm(0);
}
@@ -164,17 +164,17 @@ void sys_putmidimess(int portno, int a, int b, int c)
switch (md_msglen(a))
{
case 2:
- oss_midiout(oss_midioutfd[portno],a);
- oss_midiout(oss_midioutfd[portno],b);
- oss_midiout(oss_midioutfd[portno],c);
- return;
+ oss_midiout(oss_midioutfd[portno],a);
+ oss_midiout(oss_midioutfd[portno],b);
+ oss_midiout(oss_midioutfd[portno],c);
+ return;
case 1:
- oss_midiout(oss_midioutfd[portno],a);
- oss_midiout(oss_midioutfd[portno],b);
- return;
+ oss_midiout(oss_midioutfd[portno],a);
+ oss_midiout(oss_midioutfd[portno],b);
+ return;
case 0:
- oss_midiout(oss_midioutfd[portno],a);
- return;
+ oss_midiout(oss_midioutfd[portno],a);
+ return;
};
}
}
@@ -182,11 +182,11 @@ void sys_putmidimess(int portno, int a, int b, int c)
void sys_putmidibyte(int portno, int byte)
{
if (portno >= 0 && portno < oss_nmidiout)
- oss_midiout(oss_midioutfd[portno], byte);
+ oss_midiout(oss_midioutfd[portno], byte);
}
-#if 0 /* this is the "select" version which doesn't work with OSS
- driver for emu10k1 (it doesn't implement select.) */
+#if 0 /* this is the "select" version which doesn't work with OSS
+ driver for emu10k1 (it doesn't implement select.) */
void sys_poll_midi(void)
{
int i, throttle = 100;
@@ -194,33 +194,33 @@ void sys_poll_midi(void)
int did = 1, maxfd = 0;
while (did)
{
- fd_set readset, writeset, exceptset;
- did = 0;
- if (throttle-- < 0)
- break;
- timout.tv_sec = 0;
- timout.tv_usec = 0;
+ fd_set readset, writeset, exceptset;
+ did = 0;
+ if (throttle-- < 0)
+ break;
+ timout.tv_sec = 0;
+ timout.tv_usec = 0;
- FD_ZERO(&writeset);
- FD_ZERO(&readset);
- FD_ZERO(&exceptset);
- for (i = 0; i < oss_nmidiin; i++)
- {
- if (oss_midiinfd[i] > maxfd)
- maxfd = oss_midiinfd[i];
- FD_SET(oss_midiinfd[i], &readset);
- }
- select(maxfd+1, &readset, &writeset, &exceptset, &timout);
- for (i = 0; i < oss_nmidiin; i++)
- if (FD_ISSET(oss_midiinfd[i], &readset))
- {
- char c;
- int ret = read(oss_midiinfd[i], &c, 1);
- if (ret <= 0)
- fprintf(stderr, "Midi read error\n");
- else sys_midibytein(i, (c & 0xff));
- did = 1;
- }
+ FD_ZERO(&writeset);
+ FD_ZERO(&readset);
+ FD_ZERO(&exceptset);
+ for (i = 0; i < oss_nmidiin; i++)
+ {
+ if (oss_midiinfd[i] > maxfd)
+ maxfd = oss_midiinfd[i];
+ FD_SET(oss_midiinfd[i], &readset);
+ }
+ select(maxfd+1, &readset, &writeset, &exceptset, &timout);
+ for (i = 0; i < oss_nmidiin; i++)
+ if (FD_ISSET(oss_midiinfd[i], &readset))
+ {
+ char c;
+ int ret = read(oss_midiinfd[i], &c, 1);
+ if (ret <= 0)
+ fprintf(stderr, "Midi read error\n");
+ else sys_midibytein(i, (c & 0xff));
+ did = 1;
+ }
}
}
#else
@@ -233,25 +233,25 @@ void sys_poll_midi(void)
int did = 1, maxfd = 0;
while (did)
{
- fd_set readset, writeset, exceptset;
- did = 0;
- if (throttle-- < 0)
- break;
- for (i = 0; i < oss_nmidiin; i++)
- {
- char c;
- int ret = read(oss_midiinfd[i], &c, 1);
- if (ret < 0)
- {
- if (errno != EAGAIN)
- perror("MIDI");
- }
- else if (ret != 0)
- {
- sys_midibytein(i, (c & 0xff));
- did = 1;
- }
- }
+ fd_set readset, writeset, exceptset;
+ did = 0;
+ if (throttle-- < 0)
+ break;
+ for (i = 0; i < oss_nmidiin; i++)
+ {
+ char c;
+ int ret = read(oss_midiinfd[i], &c, 1);
+ if (ret < 0)
+ {
+ if (errno != EAGAIN)
+ perror("MIDI");
+ }
+ else if (ret != 0)
+ {
+ sys_midibytein(i, (c & 0xff));
+ did = 1;
+ }
+ }
}
}
#endif
@@ -260,9 +260,9 @@ void sys_close_midi()
{
int i;
for (i = 0; i < oss_nmidiin; i++)
- close(oss_midiinfd[i]);
+ close(oss_midiinfd[i]);
for (i = 0; i < oss_nmidiout; i++)
- close(oss_midioutfd[i]);
+ close(oss_midioutfd[i]);
oss_nmidiin = oss_nmidiout = 0;
}
@@ -273,71 +273,71 @@ void midi_oss_init(void)
{
int i;
if (oss_initted)
- return;
+ return;
oss_initted = 1;
for (i = 0; i < NSEARCH; i++)
{
- int fd;
- char namebuf[80];
-
- oss_nmidiindevs = i;
- /* try to open the device for reading */
- if (i == 0)
- {
- fd = open("/dev/midi", O_RDONLY | O_NDELAY);
- if (fd >= 0)
- {
- close(fd);
- continue;
- }
- }
- sprintf(namebuf, "/dev/midi%2.2d", i);
- fd = open(namebuf, O_RDONLY | O_NDELAY);
- if (fd >= 0)
- {
- close(fd);
- continue;
- }
- sprintf(namebuf, "/dev/midi%d", i);
- fd = open(namebuf, O_RDONLY | O_NDELAY);
- if (fd >= 0)
- {
- close(fd);
- continue;
- }
- break;
+ int fd;
+ char namebuf[80];
+
+ oss_nmidiindevs = i;
+ /* try to open the device for reading */
+ if (i == 0)
+ {
+ fd = open("/dev/midi", O_RDONLY | O_NDELAY);
+ if (fd >= 0)
+ {
+ close(fd);
+ continue;
+ }
+ }
+ sprintf(namebuf, "/dev/midi%2.2d", i);
+ fd = open(namebuf, O_RDONLY | O_NDELAY);
+ if (fd >= 0)
+ {
+ close(fd);
+ continue;
+ }
+ sprintf(namebuf, "/dev/midi%d", i);
+ fd = open(namebuf, O_RDONLY | O_NDELAY);
+ if (fd >= 0)
+ {
+ close(fd);
+ continue;
+ }
+ break;
}
for (i = 0; i < NSEARCH; i++)
{
- int fd;
- char namebuf[80];
-
- oss_nmidioutdevs = i;
- /* try to open the device for writing */
- if (i == 0)
- {
- fd = open("/dev/midi", O_WRONLY | O_NDELAY);
- if (fd >= 0)
- {
- close(fd);
- continue;
- }
- }
- sprintf(namebuf, "/dev/midi%2.2d", i);
- fd = open(namebuf, O_WRONLY | O_NDELAY);
- if (fd >= 0)
- {
- close(fd);
- continue;
- }
- sprintf(namebuf, "/dev/midi%d", i);
- fd = open(namebuf, O_WRONLY | O_NDELAY);
- if (fd >= 0)
- {
- close(fd);
- continue;
- }
- break;
+ int fd;
+ char namebuf[80];
+
+ oss_nmidioutdevs = i;
+ /* try to open the device for writing */
+ if (i == 0)
+ {
+ fd = open("/dev/midi", O_WRONLY | O_NDELAY);
+ if (fd >= 0)
+ {
+ close(fd);
+ continue;
+ }
+ }
+ sprintf(namebuf, "/dev/midi%2.2d", i);
+ fd = open(namebuf, O_WRONLY | O_NDELAY);
+ if (fd >= 0)
+ {
+ close(fd);
+ continue;
+ }
+ sprintf(namebuf, "/dev/midi%d", i);
+ fd = open(namebuf, O_WRONLY | O_NDELAY);
+ if (fd >= 0)
+ {
+ close(fd);
+ continue;
+ }
+ break;
}
}
@@ -346,14 +346,14 @@ void midi_getdevs(char *indevlist, int *nindevs,
{
int i, ndev;
if ((ndev = oss_nmidiindevs) > maxndev)
- ndev = maxndev;
+ ndev = maxndev;
for (i = 0; i < ndev; i++)
- sprintf(indevlist + i * devdescsize, "OSS MIDI device #%d", i+1);
+ sprintf(indevlist + i * devdescsize, "OSS MIDI device #%d", i+1);
*nindevs = ndev;
if ((ndev = oss_nmidioutdevs) > maxndev)
- ndev = maxndev;
+ ndev = maxndev;
for (i = 0; i < ndev; i++)
- sprintf(outdevlist + i * devdescsize, "OSS MIDI device #%d", i+1);
+ sprintf(outdevlist + i * devdescsize, "OSS MIDI device #%d", i+1);
*noutdevs = ndev;
}
diff --git a/pd/src/s_midi_pm.c b/pd/src/s_midi_pm.c
index 59882fe6..1f3f11c8 100644
--- a/pd/src/s_midi_pm.c
+++ b/pd/src/s_midi_pm.c
@@ -10,7 +10,7 @@
#include "m_pd.h"
#include "s_stuff.h"
#include <stdio.h>
-#ifdef UNIX
+#ifdef UNISTD
#include <unistd.h>
#include <sys/time.h>
#include <sys/resource.h>
@@ -37,14 +37,14 @@ void sys_do_open_midi(int nmidiin, int *midiinvec,
Pt_Start(1, 0, 0); /* start a timer with millisecond accuracy */
- /* protect the unwary from having MIDI inputs open; they're
- bad news if you close Pd's terminal window. see sys_nmidiin
- in s_main.c too. */
+ /* protect the unwary from having MIDI inputs open; they're
+ bad news if you close Pd's terminal window. see sys_nmidiin
+ in s_main.c too. */
#ifdef MSW
if (nmidiin)
{
- post(
- "midi input enabled; warning, don't close the DOS window directly!");
+ post(
+ "midi input enabled; warning, don't close the DOS window directly!");
}
else post("not using MIDI input (use 'pd -midiindev 1' to override)");
#endif
@@ -52,70 +52,70 @@ void sys_do_open_midi(int nmidiin, int *midiinvec,
mac_nmidiindev = 0;
for (i = 0; i < nmidiin; i++)
{
- for (j = 0, devno = 0; j < Pm_CountDevices(); j++)
- {
- const PmDeviceInfo *info = Pm_GetDeviceInfo(j);
- if (info->input)
- {
- if (devno == midiinvec[i])
- {
- err = Pm_OpenInput(&mac_midiindevlist[mac_nmidiindev],
- j, NULL, 100, NULL, NULL, NULL);
- if (err)
- post("could not open midi input %d (%s): %s",
- j, info->name, Pm_GetErrorText(err));
-
- else
- {
- if (sys_verbose)
- post("Midi Input (%s) opened.",
- info->name);
- mac_nmidiindev++;
- }
- }
- devno++;
- }
- }
- }
+ for (j = 0, devno = 0; j < Pm_CountDevices(); j++)
+ {
+ const PmDeviceInfo *info = Pm_GetDeviceInfo(j);
+ if (info->input)
+ {
+ if (devno == midiinvec[i])
+ {
+ err = Pm_OpenInput(&mac_midiindevlist[mac_nmidiindev],
+ j, NULL, 100, NULL, NULL, NULL);
+ if (err)
+ post("could not open midi input %d (%s): %s",
+ j, info->name, Pm_GetErrorText(err));
+
+ else
+ {
+ if (sys_verbose)
+ post("Midi Input (%s) opened.",
+ info->name);
+ mac_nmidiindev++;
+ }
+ }
+ devno++;
+ }
+ }
+ }
mac_nmidioutdev = 0;
for (i = 0; i < nmidiout; i++)
{
- for (j = 0, devno = 0; j < Pm_CountDevices(); j++)
- {
- const PmDeviceInfo *info = Pm_GetDeviceInfo(j);
- if (info->output)
- {
- if (devno == midioutvec[i])
- {
- err = Pm_OpenOutput(
- &mac_midioutdevlist[mac_nmidioutdev],
- j, NULL, 0, NULL, NULL, 0);
- if (err)
- post("could not open midi output %d (%s): %s",
- j, info->name, Pm_GetErrorText(err));
- else
- {
- if (sys_verbose)
- post("Midi Output (%s) opened.",
- info->name);
- mac_nmidioutdev++;
- }
- }
- devno++;
- }
- }
- }
+ for (j = 0, devno = 0; j < Pm_CountDevices(); j++)
+ {
+ const PmDeviceInfo *info = Pm_GetDeviceInfo(j);
+ if (info->output)
+ {
+ if (devno == midioutvec[i])
+ {
+ err = Pm_OpenOutput(
+ &mac_midioutdevlist[mac_nmidioutdev],
+ j, NULL, 0, NULL, NULL, 0);
+ if (err)
+ post("could not open midi output %d (%s): %s",
+ j, info->name, Pm_GetErrorText(err));
+ else
+ {
+ if (sys_verbose)
+ post("Midi Output (%s) opened.",
+ info->name);
+ mac_nmidioutdev++;
+ }
+ }
+ devno++;
+ }
+ }
+ }
}
void sys_close_midi( void)
{
int i;
for (i = 0; i < mac_nmidiindev; i++)
- Pm_Close(mac_midiindevlist[i]);
+ Pm_Close(mac_midiindevlist[i]);
mac_nmidiindev = 0;
for (i = 0; i < mac_nmidioutdev; i++)
- Pm_Close(mac_midioutdevlist[i]);
+ Pm_Close(mac_midioutdevlist[i]);
mac_nmidioutdev = 0;
}
@@ -125,8 +125,8 @@ void sys_putmidimess(int portno, int a, int b, int c)
/* fprintf(stderr, "put 1 msg %d %d\n", portno, mac_nmidioutdev); */
if (portno >= 0 && portno < mac_nmidioutdev)
{
- buffer.message = Pm_Message(a, b, c);
- buffer.timestamp = 0;
+ buffer.message = Pm_Message(a, b, c);
+ buffer.timestamp = 0;
/* fprintf(stderr, "put msg\n"); */
Pm_Write(mac_midioutdevlist[portno], &buffer, 1);
}
@@ -137,87 +137,87 @@ static void writemidi4(PortMidiStream* stream, int a, int b, int c, int d)
PmEvent buffer;
buffer.timestamp = 0;
buffer.message = ((a & 0xff) | ((b & 0xff) << 8)
- | ((c & 0xff) << 16) | ((d & 0xff) << 24));
+ | ((c & 0xff) << 16) | ((d & 0xff) << 24));
Pm_Write(stream, &buffer, 1);
}
void sys_putmidibyte(int portno, int byte)
{
- /* try to parse the bytes into MIDI messages so they can
- fit into PortMidi buffers. */
+ /* try to parse the bytes into MIDI messages so they can
+ fit into PortMidi buffers. */
static int mess[4];
static int nbytes = 0, sysex = 0, i;
- if (byte >= 0xf8) /* MIDI real time */
+ if (byte >= 0xf8) /* MIDI real time */
writemidi4(mac_midioutdevlist[portno], byte, 0, 0, 0);
else if (byte == 0xf0)
{
- mess[0] = 0xf7;
- nbytes = 1;
- sysex = 1;
+ mess[0] = 0xf7;
+ nbytes = 1;
+ sysex = 1;
}
else if (byte == 0xf7)
{
- mess[nbytes] = byte;
- for (i = nbytes+1; i < 4; i++)
- mess[i] = 0;
- writemidi4(mac_midioutdevlist[portno],
- mess[0], mess[1], mess[2], mess[3]);
- sysex = 0;
- nbytes = 0;
+ mess[nbytes] = byte;
+ for (i = nbytes+1; i < 4; i++)
+ mess[i] = 0;
+ writemidi4(mac_midioutdevlist[portno],
+ mess[0], mess[1], mess[2], mess[3]);
+ sysex = 0;
+ nbytes = 0;
}
else if (byte >= 0x80)
{
- sysex = 0;
- if (byte == 0xf4 || byte == 0xf5 || byte == 0xf6)
- {
- writemidi4(mac_midioutdevlist[portno], byte, 0, 0, 0);
- nbytes = 0;
- }
- else
- {
- mess[0] = byte;
- nbytes = 1;
- }
+ sysex = 0;
+ if (byte == 0xf4 || byte == 0xf5 || byte == 0xf6)
+ {
+ writemidi4(mac_midioutdevlist[portno], byte, 0, 0, 0);
+ nbytes = 0;
+ }
+ else
+ {
+ mess[0] = byte;
+ nbytes = 1;
+ }
}
else if (sysex)
{
- mess[nbytes] = byte;
- nbytes++;
- if (nbytes == 4)
- {
- writemidi4(mac_midioutdevlist[portno],
- mess[0], mess[1], mess[2], mess[3]);
- nbytes = 0;
- }
+ mess[nbytes] = byte;
+ nbytes++;
+ if (nbytes == 4)
+ {
+ writemidi4(mac_midioutdevlist[portno],
+ mess[0], mess[1], mess[2], mess[3]);
+ nbytes = 0;
+ }
}
else if (nbytes)
{
- int status = mess[0];
- if (status < 0xf0)
- status &= 0xf0;
- /* 2 byte messages: */
- if (status == 0xc0 || status == 0xd0 ||
- status == 0xf1 || status == 0xf3)
- {
- writemidi4(mac_midioutdevlist[portno],
- mess[0], byte, 0, 0);
- nbytes = (status < 0xf0 ? 1 : 0);
- }
- else
- {
- if (nbytes == 1)
- {
- mess[1] = byte;
- nbytes = 2;
- }
- else
- {
- writemidi4(mac_midioutdevlist[portno],
- mess[0], mess[1], byte, 0);
- nbytes = (status < 0xf0 ? 1 : 0);
- }
- }
+ int status = mess[0];
+ if (status < 0xf0)
+ status &= 0xf0;
+ /* 2 byte messages: */
+ if (status == 0xc0 || status == 0xd0 ||
+ status == 0xf1 || status == 0xf3)
+ {
+ writemidi4(mac_midioutdevlist[portno],
+ mess[0], byte, 0, 0);
+ nbytes = (status < 0xf0 ? 1 : 0);
+ }
+ else
+ {
+ if (nbytes == 1)
+ {
+ mess[1] = byte;
+ nbytes = 2;
+ }
+ else
+ {
+ writemidi4(mac_midioutdevlist[portno],
+ mess[0], mess[1], byte, 0);
+ nbytes = (status < 0xf0 ? 1 : 0);
+ }
+ }
}
}
@@ -227,41 +227,41 @@ void sys_poll_midi(void)
PmEvent buffer;
for (i = 0; i < mac_nmidiindev; i++)
{
- int nmess = Pm_Read(mac_midiindevlist[i], &buffer, 1);
- if (nmess > 0)
- {
+ int nmess = Pm_Read(mac_midiindevlist[i], &buffer, 1);
+ if (nmess > 0)
+ {
int status = Pm_MessageStatus(buffer.message);
int data1 = Pm_MessageData1(buffer.message);
int data2 = Pm_MessageData2(buffer.message);
int msgtype = (status >> 4) - 8;
- switch (msgtype)
- {
- case 0:
- case 1:
- case 2:
- case 3:
- case 6:
- sys_midibytein(i, status);
- sys_midibytein(i, data1);
- sys_midibytein(i, data2);
- break;
- case 4:
- case 5:
- sys_midibytein(i, status);
- sys_midibytein(i, data1);
- break;
- case 7:
- sys_midibytein(i, status);
- break;
- }
- }
+ switch (msgtype)
+ {
+ case 0:
+ case 1:
+ case 2:
+ case 3:
+ case 6:
+ sys_midibytein(i, status);
+ sys_midibytein(i, data1);
+ sys_midibytein(i, data2);
+ break;
+ case 4:
+ case 5:
+ sys_midibytein(i, status);
+ sys_midibytein(i, data1);
+ break;
+ case 7:
+ sys_midibytein(i, status);
+ break;
+ }
+ }
}
}
#if 0
void sys_listmididevs(void) /* lifted from pa_devs.c in portaudio */
{
- int i,j;
+ int i,j;
for (i = 0; i < Pm_CountDevices(); i++)
{
const PmDeviceInfo *info = Pm_GetDeviceInfo(i);
@@ -281,17 +281,17 @@ void midi_getdevs(char *indevlist, int *nindevs,
{
const PmDeviceInfo *info = Pm_GetDeviceInfo(i);
/* post("%d: %s, %s (%d,%d)", i, info->interf, info->name,
- info->input, info->output); */
- if (info->input && nindev < maxndev)
- {
- strcpy(indevlist + nindev * devdescsize, info->name);
- nindev++;
- }
- if (info->output && noutdev < maxndev)
- {
- strcpy(outdevlist + noutdev * devdescsize, info->name);
- noutdev++;
- }
+ info->input, info->output); */
+ if (info->input && nindev < maxndev)
+ {
+ strcpy(indevlist + nindev * devdescsize, info->name);
+ nindev++;
+ }
+ if (info->output && noutdev < maxndev)
+ {
+ strcpy(outdevlist + noutdev * devdescsize, info->name);
+ noutdev++;
+ }
}
*nindevs = nindev;
*noutdevs = noutdev;
diff --git a/pd/src/s_midi_sgi.c b/pd/src/s_midi_sgi.c
index 7e58dbe3..4634b571 100644
--- a/pd/src/s_midi_sgi.c
+++ b/pd/src/s_midi_sgi.c
@@ -2,6 +2,7 @@
* For information on usage and redistribution, and for a DISCLAIMER OF ALL
* WARRANTIES, see the file, "LICENSE.txt," in this distribution. */
+#include "m_pd.h"
#include "s_stuff.h"
#include <stdio.h>
#include <stdlib.h>
@@ -16,7 +17,7 @@
#include <dmedia/audio.h>
#include <sys/fpu.h>
#include <dmedia/midi.h>
-int mdInit(void); /* prototype was messed up in midi.h */
+int mdInit(void); /* prototype was messed up in midi.h */
/* #include "sys/select.h" */
@@ -51,33 +52,33 @@ void sgi_open_midi(int midiin, int midiout)
else if (sgi_nports > NPORT) sgi_nports = NPORT;
if (sys_verbose)
{
- if (!sgi_nports)
- {
- post("no serial ports are configured for MIDI;");
- post("if you want to use MIDI, try exiting Pd, typing");
- post("'startmidi -d /dev/ttyd2' to a shell, and restarting Pd.");
- }
- else if (sgi_nports == 1)
- post("Found one MIDI port on %s", mdGetName(0));
- else if (sgi_nports == 2)
- post("Found MIDI ports on %s and %s",
- mdGetName(0), mdGetName(1));
+ if (!sgi_nports)
+ {
+ post("no serial ports are configured for MIDI;");
+ post("if you want to use MIDI, try exiting Pd, typing");
+ post("'startmidi -d /dev/ttyd2' to a shell, and restarting Pd.");
+ }
+ else if (sgi_nports == 1)
+ post("Found one MIDI port on %s", mdGetName(0));
+ else if (sgi_nports == 2)
+ post("Found MIDI ports on %s and %s",
+ mdGetName(0), mdGetName(1));
}
if (midiin)
{
- for (i = 0; i < sgi_nports; i++)
- {
- if (!(sgi_inport[i] = mdOpenInPort(mdGetName(i))))
- error("MIDI input port %d: open failed", i+1);;
- }
+ for (i = 0; i < sgi_nports; i++)
+ {
+ if (!(sgi_inport[i] = mdOpenInPort(mdGetName(i))))
+ error("MIDI input port %d: open failed", i+1);;
+ }
}
if (midiout)
{
- for (i = 0; i < sgi_nports; i++)
- {
- if (!(sgi_outport[i] = mdOpenOutPort(mdGetName(i))))
- error("MIDI output port %d: open failed", i+1);;
- }
+ for (i = 0; i < sgi_nports; i++)
+ {
+ if (!(sgi_outport[i] = mdOpenOutPort(mdGetName(i))))
+ error("MIDI output port %d: open failed", i+1);;
+ }
}
return;
}
@@ -94,7 +95,7 @@ void sys_putmidimess(int portno, int a, int b, int c)
mdv.stamp = 0;
mdv.msglen = 0;
if (mdSend(sgi_outport[portno], &mdv, 1) < 0)
- error("MIDI output error\n");
+ error("MIDI output error\n");
post("msg out %d %d %d", a, b, c);
}
@@ -116,60 +117,60 @@ void sys_poll_midi(void)
MDport *mp;
for (i = 0, mp = sgi_inport; i < NPORT; i++, mp++)
{
- int ret, status, b1, b2, nfds;
- MDevent mdv;
- fd_set inports;
- struct timeval timeout;
- timeout.tv_sec = 0;
- timeout.tv_usec = 0;
- if (!*mp) continue;
- FD_ZERO(&inports);
- FD_SET(mdGetFd(*mp), &inports);
-
- if (select(mdGetFd(*mp)+1 , &inports, 0, 0, &timeout) < 0)
- perror("midi select");
- if (FD_ISSET(mdGetFd(*mp),&inports))
- {
- if (mdReceive(*mp, &mdv, 1) < 0)
- error("failure receiving message\n");
- else if (mdv.msg[0] == MD_SYSEX) mdFree(mdv.sysexmsg);
-
- else
- {
- int status = mdv.msg[0];
- int channel = (status & 0xf) + 1;
- int b1 = mdv.msg[1];
- int b2 = mdv.msg[2];
- switch(status & 0xf0)
- {
- case MD_NOTEOFF:
- inmidi_noteon(i, channel, b1, 0);
- break;
- case MD_NOTEON:
- inmidi_noteon(i, channel, b1, b2);
- break;
- case MD_POLYKEYPRESSURE:
- inmidi_polyaftertouch(i, channel, b1, b2);
- break;
- case MD_CONTROLCHANGE:
- inmidi_controlchange(i, channel, b1, b2);
- break;
- case MD_PITCHBENDCHANGE:
- inmidi_pitchbend(i, channel, ((b2 << 7) + b1));
- break;
- case MD_PROGRAMCHANGE:
- inmidi_programchange(i, channel, b1);
- break;
- case MD_CHANNELPRESSURE:
- inmidi_aftertouch(i, channel, b1);
- break;
- }
- }
- }
+ int ret, status, b1, b2, nfds;
+ MDevent mdv;
+ fd_set inports;
+ struct timeval timeout;
+ timeout.tv_sec = 0;
+ timeout.tv_usec = 0;
+ if (!*mp) continue;
+ FD_ZERO(&inports);
+ FD_SET(mdGetFd(*mp), &inports);
+
+ if (select(mdGetFd(*mp)+1 , &inports, 0, 0, &timeout) < 0)
+ perror("midi select");
+ if (FD_ISSET(mdGetFd(*mp),&inports))
+ {
+ if (mdReceive(*mp, &mdv, 1) < 0)
+ error("failure receiving message\n");
+ else if (mdv.msg[0] == MD_SYSEX) mdFree(mdv.sysexmsg);
+
+ else
+ {
+ int status = mdv.msg[0];
+ int channel = (status & 0xf) + 1;
+ int b1 = mdv.msg[1];
+ int b2 = mdv.msg[2];
+ switch(status & 0xf0)
+ {
+ case MD_NOTEOFF:
+ inmidi_noteon(i, channel, b1, 0);
+ break;
+ case MD_NOTEON:
+ inmidi_noteon(i, channel, b1, b2);
+ break;
+ case MD_POLYKEYPRESSURE:
+ inmidi_polyaftertouch(i, channel, b1, b2);
+ break;
+ case MD_CONTROLCHANGE:
+ inmidi_controlchange(i, channel, b1, b2);
+ break;
+ case MD_PITCHBENDCHANGE:
+ inmidi_pitchbend(i, channel, ((b2 << 7) + b1));
+ break;
+ case MD_PROGRAMCHANGE:
+ inmidi_programchange(i, channel, b1);
+ break;
+ case MD_CHANNELPRESSURE:
+ inmidi_aftertouch(i, channel, b1);
+ break;
+ }
+ }
+ }
}
}
-void sys_open_midi(int nmidiin, int *midiinvec,
+void sys_do_open_midi(int nmidiin, int *midiinvec,
int nmidiout, int *midioutvec)
{
sgi_open_midi(nmidiin!=0, nmidiout!=0);
@@ -181,8 +182,22 @@ void sys_close_midi( void)
/* ??? */
}
-void sys_set_priority(int foo)
+
+void midi_getdevs(char *indevlist, int *nindevs,
+ char *outdevlist, int *noutdevs, int maxndev, int devdescsize)
{
- fprintf(stderr,
- "warning: priority boosting in IRIX not implemented yet\n");
+ int i, nindev = 0, noutdev = 0;
+ for (i = 0; i < mdInit(); i++)
+ {
+ if (nindev < maxndev)
+ {
+ strcpy(indevlist + nindev * devdescsize, mdGetName(i));
+ nindev++;
+
+ strcpy(outdevlist + noutdev * devdescsize, mdGetName(i));
+ noutdev++;
+ }
+ }
+ *nindevs = nindev;
+ *noutdevs = noutdev;
}
diff --git a/pd/src/s_path.c b/pd/src/s_path.c
index 456be94f..90d1fa51 100644
--- a/pd/src/s_path.c
+++ b/pd/src/s_path.c
@@ -15,7 +15,7 @@
void readsf_banana( void); /* debugging */
#include <stdlib.h>
-#ifdef UNIX
+#ifdef UNISTD
#include <unistd.h>
#include <sys/stat.h>
#endif
@@ -29,10 +29,41 @@ void readsf_banana( void); /* debugging */
#include "s_stuff.h"
#include <stdio.h>
#include <fcntl.h>
+#include <ctype.h>
-static t_namelist *pd_path, *pd_helppath;
+t_namelist *sys_externlist;
+t_namelist *sys_searchpath;
+t_namelist *sys_helppath;
-/* Utility functions */
+ /* change '/' characters to the system's native file separator */
+void sys_bashfilename(const char *from, char *to)
+{
+ char c;
+ while (c = *from++)
+ {
+#ifdef MSW
+ if (c == '/') c = '\\';
+#endif
+ *to++ = c;
+ }
+ *to = 0;
+}
+
+ /* change the system's native file separator to '/' characters */
+void sys_unbashfilename(const char *from, char *to)
+{
+ char c;
+ while (c = *from++)
+ {
+#ifdef MSW
+ if (c == '\\') c = '/';
+#endif
+ *to++ = c;
+ }
+ *to = 0;
+}
+
+/******************* Utility functions used below ******************/
/* copy until delimiter and return position after delimiter in string */
/* if it was the last substring, return NULL */
@@ -42,7 +73,7 @@ static const char* strtokcpy(char *to, const char *from, int delim)
int size = 0;
while (from[size] != (char)delim && from[size] != '\0')
- size++;
+ size++;
strncpy(to,from,size);
to[size] = '\0';
@@ -51,35 +82,43 @@ static const char* strtokcpy(char *to, const char *from, int delim)
else return NULL;
}
-/* add a colon-separated list of names to a namelist */
-
-#ifdef MSW
-#define SEPARATOR ';'
-#else
-#define SEPARATOR ':'
-#endif
-
-static t_namelist *namelist_doappend(t_namelist *listwas, const char *s)
+/* add a single item to a namelist. If "allowdup" is true, duplicates
+may be added; othewise they're dropped. */
+
+t_namelist *namelist_append(t_namelist *listwas, const char *s, int allowdup)
{
- t_namelist *nl = listwas, *rtn = listwas, *nl2;
+ t_namelist *nl, *nl2;
nl2 = (t_namelist *)(getbytes(sizeof(*nl)));
nl2->nl_next = 0;
nl2->nl_string = (char *)getbytes(strlen(s) + 1);
strcpy(nl2->nl_string, s);
sys_unbashfilename(nl2->nl_string, nl2->nl_string);
- if (!nl)
- nl = rtn = nl2;
+ if (!listwas)
+ return (nl2);
else
{
- while (nl->nl_next)
- nl = nl->nl_next;
+ for (nl = listwas; ;)
+ {
+ if (!allowdup && !strcmp(nl->nl_string, s))
+ return (listwas);
+ if (!nl->nl_next)
+ break;
+ nl = nl->nl_next;
+ }
nl->nl_next = nl2;
}
- return (rtn);
-
+ return (listwas);
}
-t_namelist *namelist_append(t_namelist *listwas, const char *s)
+/* add a colon-separated list of names to a namelist */
+
+#ifdef MSW
+#define SEPARATOR ';' /* in MSW the natural separator is semicolon instead */
+#else
+#define SEPARATOR ':'
+#endif
+
+t_namelist *namelist_append_files(t_namelist *listwas, const char *s)
{
const char *npos;
char temp[MAXPDSTRING];
@@ -88,11 +127,11 @@ t_namelist *namelist_append(t_namelist *listwas, const char *s)
npos = s;
do
{
- npos = strtokcpy(temp, npos, SEPARATOR);
- if (! *temp) continue;
- nl = namelist_doappend(nl, temp);
+ npos = strtokcpy(temp, npos, SEPARATOR);
+ if (! *temp) continue;
+ nl = namelist_append(nl, temp, 0);
}
- while (npos);
+ while (npos);
return (nl);
}
@@ -101,20 +140,29 @@ void namelist_free(t_namelist *listwas)
t_namelist *nl, *nl2;
for (nl = listwas; nl; nl = nl2)
{
- nl2 = nl->nl_next;
- t_freebytes(nl->nl_string, strlen(nl->nl_string) + 1);
- t_freebytes(nl, sizeof(*nl));
+ nl2 = nl->nl_next;
+ t_freebytes(nl->nl_string, strlen(nl->nl_string) + 1);
+ t_freebytes(nl, sizeof(*nl));
}
}
-void sys_addpath(const char *p)
+char *namelist_get(t_namelist *namelist, int n)
{
- pd_path = namelist_append(pd_path, p);
+ int i;
+ t_namelist *nl;
+ for (i = 0, nl = namelist; i < n && nl; i++, nl = nl->nl_next)
+ ;
+ return (nl ? nl->nl_string : 0);
}
-void sys_addhelppath(const char *p)
+static t_namelist *pd_extrapath;
+
+int sys_usestdpath = 1;
+
+void sys_setextrapath(const char *p)
{
- pd_helppath = namelist_append(pd_helppath, p);
+ namelist_free(pd_extrapath);
+ pd_extrapath = namelist_append(0, p, 0);
}
#ifdef MSW
@@ -140,72 +188,77 @@ int open_via_path(const char *dir, const char *name, const char* ext,
if (name[0] == '/'
#ifdef MSW
- || (name[1] == ':' && name[2] == '/')
+ || (name[1] == ':' && name[2] == '/')
#endif
- )
+ )
{
- thislist.nl_next = 0;
- thislist.nl_string = listbuf;
- listbuf[0] = 0;
+ thislist.nl_next = 0;
+ thislist.nl_string = listbuf;
+ listbuf[0] = 0;
}
else
{
- thislist.nl_string = listbuf;
- thislist.nl_next = pd_path;
- strncpy(listbuf, dir, MAXPDSTRING);
- listbuf[MAXPDSTRING-1] = 0;
- sys_unbashfilename(listbuf, listbuf);
+ thislist.nl_string = listbuf;
+ thislist.nl_next = sys_searchpath;
+ strncpy(listbuf, dir, MAXPDSTRING);
+ listbuf[MAXPDSTRING-1] = 0;
+ sys_unbashfilename(listbuf, listbuf);
}
- for (nl = &thislist; nl; nl = nl->nl_next)
+ /* search, first, through the search path (to which we prepended the
+ current directory), then, if enabled, look in the "extra" dir */
+ for (nl = &thislist; nl;
+ nl = (nl->nl_next ? nl->nl_next :
+ (nl == pd_extrapath ? 0 :
+ (sys_usestdpath ? pd_extrapath : 0))))
{
- if (strlen(nl->nl_string) + strlen(name) + strlen(ext) + 4 >
- size)
- continue;
- strcpy(dirresult, nl->nl_string);
- if (*dirresult && dirresult[strlen(dirresult)-1] != '/')
- strcat(dirresult, "/");
- strcat(dirresult, name);
- strcat(dirresult, ext);
- sys_bashfilename(dirresult, dirresult);
-
- DEBUG(post("looking for %s",dirresult));
- /* see if we can open the file for reading */
- if ((fd=open(dirresult,O_RDONLY | MSWOPENFLAG(bin))) >= 0)
- {
- /* in UNIX, further check that it's not a directory */
-#ifdef UNIX
- struct stat statbuf;
- int ok = ((fstat(fd, &statbuf) >= 0) &&
- !S_ISDIR(statbuf.st_mode));
- if (!ok)
- {
- if (sys_verbose) post("tried %s; stat failed or directory",
- dirresult);
- close (fd);
- fd = -1;
- }
- else
+ if (strlen(nl->nl_string) + strlen(name) + strlen(ext) + 4 >
+ size)
+ continue;
+ strcpy(dirresult, nl->nl_string);
+ if (*dirresult && dirresult[strlen(dirresult)-1] != '/')
+ strcat(dirresult, "/");
+ strcat(dirresult, name);
+ strcat(dirresult, ext);
+ sys_bashfilename(dirresult, dirresult);
+
+ DEBUG(post("looking for %s",dirresult));
+ /* see if we can open the file for reading */
+ if ((fd=open(dirresult,O_RDONLY | MSWOPENFLAG(bin))) >= 0)
+ {
+ /* in unix, further check that it's not a directory */
+#ifdef UNISTD
+ struct stat statbuf;
+ int ok = ((fstat(fd, &statbuf) >= 0) &&
+ !S_ISDIR(statbuf.st_mode));
+ if (!ok)
+ {
+ if (sys_verbose) post("tried %s; stat failed or directory",
+ dirresult);
+ close (fd);
+ fd = -1;
+ }
+ else
#endif
- {
- char *slash;
- if (sys_verbose) post("tried %s and succeeded", dirresult);
- sys_unbashfilename(dirresult, dirresult);
- slash = strrchr(dirresult, '/');
- if (slash)
- {
- *slash = 0;
- *nameresult = slash + 1;
- }
- else *nameresult = dirresult;
-
- return (fd);
- }
- }
- else
- {
- if (sys_verbose) post("tried %s and failed", dirresult);
- }
+ {
+ char *slash;
+ if (sys_verbose) post("tried %s and succeeded", dirresult);
+ sys_unbashfilename(dirresult, dirresult);
+ slash = strrchr(dirresult, '/');
+ if (slash)
+ {
+ *slash = 0;
+ *nameresult = slash + 1;
+ }
+ else *nameresult = dirresult;
+
+ return (fd);
+ }
+ }
+ else
+ {
+ if (sys_verbose) post("tried %s and failed", dirresult);
+ }
}
*dirresult = 0;
*nameresult = dirresult;
@@ -219,44 +272,44 @@ static int do_open_via_helppath(const char *realname, t_namelist *listp)
char dirresult[MAXPDSTRING], realdir[MAXPDSTRING];
for (nl = listp; nl; nl = nl->nl_next)
{
- strcpy(dirresult, nl->nl_string);
- strcpy(realdir, dirresult);
- if (*dirresult && dirresult[strlen(dirresult)-1] != '/')
- strcat(dirresult, "/");
- strcat(dirresult, realname);
- sys_bashfilename(dirresult, dirresult);
-
- DEBUG(post("looking for %s",dirresult));
- /* see if we can open the file for reading */
- if ((fd=open(dirresult,O_RDONLY | MSWOPENFLAG(0))) >= 0)
- {
- /* in UNIX, further check that it's not a directory */
-#ifdef UNIX
- struct stat statbuf;
- int ok = ((fstat(fd, &statbuf) >= 0) &&
- !S_ISDIR(statbuf.st_mode));
- if (!ok)
- {
- if (sys_verbose) post("tried %s; stat failed or directory",
- dirresult);
- close (fd);
- fd = -1;
- }
- else
+ strcpy(dirresult, nl->nl_string);
+ strcpy(realdir, dirresult);
+ if (*dirresult && dirresult[strlen(dirresult)-1] != '/')
+ strcat(dirresult, "/");
+ strcat(dirresult, realname);
+ sys_bashfilename(dirresult, dirresult);
+
+ DEBUG(post("looking for %s",dirresult));
+ /* see if we can open the file for reading */
+ if ((fd=open(dirresult,O_RDONLY | MSWOPENFLAG(0))) >= 0)
+ {
+ /* in unix, further check that it's not a directory */
+#ifdef UNISTD
+ struct stat statbuf;
+ int ok = ((fstat(fd, &statbuf) >= 0) &&
+ !S_ISDIR(statbuf.st_mode));
+ if (!ok)
+ {
+ if (sys_verbose) post("tried %s; stat failed or directory",
+ dirresult);
+ close (fd);
+ fd = -1;
+ }
+ else
#endif
- {
- char *slash;
- if (sys_verbose) post("tried %s and succeeded", dirresult);
- sys_unbashfilename(dirresult, dirresult);
- close (fd);
- glob_evalfile(0, gensym((char*)realname), gensym(realdir));
- return (1);
- }
- }
- else
- {
- if (sys_verbose) post("tried %s and failed", dirresult);
- }
+ {
+ char *slash;
+ if (sys_verbose) post("tried %s and succeeded", dirresult);
+ sys_unbashfilename(dirresult, dirresult);
+ close (fd);
+ glob_evalfile(0, gensym((char*)realname), gensym(realdir));
+ return (1);
+ }
+ }
+ else
+ {
+ if (sys_verbose) post("tried %s and failed", dirresult);
+ }
}
return (0);
}
@@ -270,44 +323,43 @@ void open_via_helppath(const char *name, const char *dir)
int fd = -1;
char dirbuf2[MAXPDSTRING], realname[MAXPDSTRING];
- /* if directory is supplied, put it at head of search list. */
+ /* if directory is supplied, put it at head of search list. */
if (*dir)
{
thislist.nl_string = dirbuf2;
- thislist.nl_next = pd_helppath;
- strncpy(dirbuf2, dir, MAXPDSTRING);
- dirbuf2[MAXPDSTRING-1] = 0;
- sys_unbashfilename(dirbuf2, dirbuf2);
- listp = &thislist;
+ thislist.nl_next = sys_helppath;
+ strncpy(dirbuf2, dir, MAXPDSTRING);
+ dirbuf2[MAXPDSTRING-1] = 0;
+ sys_unbashfilename(dirbuf2, dirbuf2);
+ listp = &thislist;
}
- else listp = pd_helppath;
- /* 1. "objectname-help.pd" */
+ else listp = sys_helppath;
+ /* 1. "objectname-help.pd" */
strncpy(realname, name, MAXPDSTRING-10);
realname[MAXPDSTRING-10] = 0;
if (strlen(realname) > 3 && !strcmp(realname+strlen(realname)-3, ".pd"))
- realname[strlen(realname)-3] = 0;
+ realname[strlen(realname)-3] = 0;
strcat(realname, "-help.pd");
if (do_open_via_helppath(realname, listp))
- return;
- /* 2. "help-objectname.pd" */
+ return;
+ /* 2. "help-objectname.pd" */
strcpy(realname, "help-");
strncat(realname, name, MAXPDSTRING-10);
realname[MAXPDSTRING-1] = 0;
if (do_open_via_helppath(realname, listp))
- return;
- /* 3. "objectname.pd" */
+ return;
+ /* 3. "objectname.pd" */
if (do_open_via_helppath(name, listp))
- return;
+ return;
post("sorry, couldn't find help patch for \"%s\"", name);
return;
}
-/* Startup file reading for linux and MACOSX. This should be replaced by
-a better mechanism. This should be integrated with the audio, MIDI, and
-path dialog system. */
+/* Startup file reading for linux and MACOSX. As of 0.38 this will be
+deprecated in favor of the "settings" mechanism */
-#ifdef UNIX
+#ifndef MSW
#define STARTUPNAME ".pdrc"
#define NUMARGS 1000
@@ -334,23 +386,23 @@ int sys_rcfile(void)
strcat(fname, STARTUPNAME);
if (!(file = fopen(fname, "r")))
- return 1;
+ return 1;
post("reading startup file: %s", fname);
- rcargv[0] = "."; /* this no longer matters to sys_argparse() */
+ rcargv[0] = "."; /* this no longer matters to sys_argparse() */
for (i = 1; i < NUMARGS-1; i++)
{
- if (fscanf(file, "%999s", buf) < 0)
- break;
- buf[1000] = 0;
- if (!(rcargv[i] = malloc(strlen(buf) + 1)))
- return (1);
- strcpy(rcargv[i], buf);
+ if (fscanf(file, "%999s", buf) < 0)
+ break;
+ buf[1000] = 0;
+ if (!(rcargv[i] = malloc(strlen(buf) + 1)))
+ return (1);
+ strcpy(rcargv[i], buf);
}
if (i >= NUMARGS-1)
- fprintf(stderr, "startup file too long; extra args dropped\n");
+ fprintf(stderr, "startup file too long; extra args dropped\n");
rcargv[i] = 0;
rcargc = i;
@@ -360,36 +412,78 @@ int sys_rcfile(void)
fclose(file);
if (sys_verbose)
{
- if (rcargv)
- {
- post("startup args from RC file:");
- for (i = 1; i < rcargc; i++)
- post("%s", rcargv[i]);
- }
- else post("no RC file arguments found");
+ if (rcargv)
+ {
+ post("startup args from RC file:");
+ for (i = 1; i < rcargc; i++)
+ post("%s", rcargv[i]);
+ }
+ else post("no RC file arguments found");
}
if (sys_argparse(rcargc, rcargv))
{
- post("error parsing RC arguments");
- return (1);
+ post("error parsing RC arguments");
+ return (1);
}
return (0);
}
-#endif /* UNIX */
+#endif /* MSW */
- /* start an audio settings dialog window */
-void glob_start_path_dialog(t_pd *dummy, t_floatarg flongform)
+void sys_doflags( void)
+{
+ int i, beginstring = 0, state = 0, len = strlen(sys_flags->s_name);
+ int rcargc = 0;
+ char *rcargv[MAXPDSTRING];
+
+ if (len > MAXPDSTRING)
+ {
+ post("flags: %s: too long", sys_flags->s_name);
+ return;
+ }
+ for (i = 0; i < len; i++)
+ {
+ int c = sys_flags->s_name[i];
+ if (state == 0)
+ {
+ if (c && !isspace(c))
+ {
+ beginstring = i;
+ state = 1;
+ }
+ }
+ else
+ {
+ if (!c || isspace(c))
+ {
+ char *foo = malloc(i - beginstring + 1);
+ if (!foo)
+ return;
+ strncpy(foo, sys_flags->s_name + beginstring, i - beginstring);
+ foo[i - beginstring] = 0;
+ rcargv[rcargc] = foo;
+ rcargc++;
+ if (rcargc >= MAXPDSTRING)
+ break;
+ }
+ }
+ }
+ if (sys_argparse(rcargc, rcargv))
+ post("error parsing RC arguments");
+}
+
+ /* start a search path dialog window */
+void glob_start_path_dialog(t_pd *dummy)
{
char buf[MAXPDSTRING];
int i;
t_namelist *nl;
- for (nl = pd_path, i = 0; nl && i < 10; nl = nl->nl_next, i++)
- sys_vgui("pd_set pd_path%d \"%s\"\n", i, nl->nl_string);
+ for (nl = sys_searchpath, i = 0; nl && i < 10; nl = nl->nl_next, i++)
+ sys_vgui("pd_set pd_path%d \"%s\"\n", i, nl->nl_string);
for (; i < 10; i++)
- sys_vgui("pd_set pd_path%d \"\"\n", i);
+ sys_vgui("pd_set pd_path%d \"\"\n", i);
- sprintf(buf, "pdtk_path_dialog %%s\n");
+ sprintf(buf, "pdtk_path_dialog %%s %d %d\n", sys_usestdpath, sys_verbose);
gfxstub_new(&glob_pdobject, glob_start_path_dialog, buf);
}
@@ -397,13 +491,48 @@ void glob_start_path_dialog(t_pd *dummy, t_floatarg flongform)
void glob_path_dialog(t_pd *dummy, t_symbol *s, int argc, t_atom *argv)
{
int i;
- namelist_free(pd_path);
- pd_path = 0;
+ namelist_free(sys_searchpath);
+ sys_searchpath = 0;
+ sys_usestdpath = atom_getintarg(0, argc, argv);
+ sys_verbose = atom_getintarg(1, argc, argv);
+ for (i = 0; i < argc; i++)
+ {
+ t_symbol *s = atom_getsymbolarg(i+2, argc, argv);
+ if (*s->s_name)
+ sys_searchpath = namelist_append_files(sys_searchpath, s->s_name);
+ }
+}
+
+ /* start a startup dialog window */
+void glob_start_startup_dialog(t_pd *dummy)
+{
+ char buf[MAXPDSTRING];
+ int i;
+ t_namelist *nl;
+
+ for (nl = sys_externlist, i = 0; nl && i < 10; nl = nl->nl_next, i++)
+ sys_vgui("pd_set pd_startup%d \"%s\"\n", i, nl->nl_string);
+ for (; i < 10; i++)
+ sys_vgui("pd_set pd_startup%d \"\"\n", i);
+
+ sprintf(buf, "pdtk_startup_dialog %%s %d \"%s\"\n", sys_defeatrt,
+ sys_flags->s_name);
+ gfxstub_new(&glob_pdobject, glob_start_startup_dialog, buf);
+}
+
+ /* new values from dialog window */
+void glob_startup_dialog(t_pd *dummy, t_symbol *s, int argc, t_atom *argv)
+{
+ int i;
+ namelist_free(sys_externlist);
+ sys_externlist = 0;
+ sys_defeatrt = atom_getintarg(0, argc, argv);
+ sys_flags = atom_getsymbolarg(1, argc, argv);
for (i = 0; i < argc; i++)
{
- t_symbol *s = atom_getsymbolarg(i, argc, argv);
- if (*s->s_name)
- sys_addpath(s->s_name);
+ t_symbol *s = atom_getsymbolarg(i+2, argc, argv);
+ if (*s->s_name)
+ sys_externlist = namelist_append_files(sys_externlist, s->s_name);
}
}
diff --git a/pd/src/s_print.c b/pd/src/s_print.c
index 33944286..aefd89ba 100644
--- a/pd/src/s_print.c
+++ b/pd/src/s_print.c
@@ -8,34 +8,68 @@
#include <stdarg.h>
#include <string.h>
#include <errno.h>
+#include "s_stuff.h"
-void post(char *fmt, ...)
+t_printhook sys_printhook;
+int sys_printtostderr;
+
+static void dopost(const char *s)
+{
+ if (sys_printhook)
+ (*sys_printhook)(s);
+ else if (sys_printtostderr)
+ fprintf(stderr, "%s", s);
+ else
+ {
+ char upbuf[MAXPDSTRING];
+ int ptin = 0, ptout = 0, len = strlen(s);
+ static int heldcr = 0;
+ if (heldcr)
+ upbuf[ptout++] = '\n', heldcr = 0;
+ for (; ptin < len && ptout < MAXPDSTRING-3;
+ ptin++, ptout++)
+ {
+ int c = s[ptin];
+ if (c == '\\' || c == '{' || c == '}' || c == ';')
+ upbuf[ptout++] = '\\';
+ upbuf[ptout] = s[ptin];
+ }
+ if (ptout && upbuf[ptout-1] == '\n')
+ upbuf[--ptout] = 0, heldcr = 1;
+ upbuf[ptout] = 0;
+ sys_vgui("pdtk_post {%s}\n", upbuf);
+ }
+}
+
+void post(const char *fmt, ...)
{
+ char buf[MAXPDSTRING];
va_list ap;
t_int arg[8];
int i;
va_start(ap, fmt);
- vfprintf(stderr, fmt, ap);
+ vsnprintf(buf, MAXPDSTRING-1, fmt, ap);
va_end(ap);
- putc('\n', stderr);
+ strcat(buf, "\n");
+ dopost(buf);
}
-void startpost(char *fmt, ...)
+void startpost(const char *fmt, ...)
{
+ char buf[MAXPDSTRING];
va_list ap;
t_int arg[8];
int i;
va_start(ap, fmt);
-
- for (i = 0 ; i < 8; i++) arg[i] = va_arg(ap, t_int);
+ vsnprintf(buf, MAXPDSTRING-1, fmt, ap);
va_end(ap);
- fprintf(stderr, fmt, arg[0], arg[1], arg[2], arg[3],
- arg[4], arg[5], arg[6], arg[7]);
+ dopost(buf);
}
-void poststring(char *s)
+void poststring(const char *s)
{
- fprintf(stderr, " %s", s);
+ dopost(" ");
+ dopost(s);
}
void postatom(int argc, t_atom *argv)
@@ -43,9 +77,9 @@ void postatom(int argc, t_atom *argv)
int i;
for (i = 0; i < argc; i++)
{
- char buf[80];
- atom_string(argv+i, buf, 80);
- poststring(buf);
+ char buf[80];
+ atom_string(argv+i, buf, 80);
+ poststring(buf);
}
}
@@ -59,19 +93,21 @@ void postfloat(float f)
void endpost(void)
{
- fprintf(stderr, "\n");
+ dopost("\n");
}
-void error(char *fmt, ...)
+void error(const char *fmt, ...)
{
+ char buf[MAXPDSTRING];
va_list ap;
t_int arg[8];
int i;
+ dopost("error: ");
va_start(ap, fmt);
- fprintf(stderr, "error: ");
- vfprintf(stderr, fmt, ap);
+ vsnprintf(buf, MAXPDSTRING-1, fmt, ap);
va_end(ap);
- putc('\n', stderr);
+ strcat(buf, "\n");
+ dopost(buf);
}
/* here's the good way to log errors -- keep a pointer to the
@@ -82,62 +118,64 @@ static void *error_object;
static char error_string[256];
void canvas_finderror(void *object);
-void pd_error(void *object, char *fmt, ...)
+void pd_error(void *object, const char *fmt, ...)
{
+ char buf[MAXPDSTRING];
va_list ap;
t_int arg[8];
int i;
- static int saidit = 0;
+ static int saidit;
+ dopost("error: ");
va_start(ap, fmt);
- vsprintf(error_string, fmt, ap);
+ vsnprintf(buf, MAXPDSTRING-1, fmt, ap);
va_end(ap);
- fprintf(stderr, "error: %s\n", error_string);
+ strcat(buf, "\n");
+ dopost(buf);
error_object = object;
if (!saidit)
{
- post("... you might be able to track this down from the Find menu.");
- saidit = 1;
+ post("... you might be able to track this down from the Find menu.");
+ saidit = 1;
}
}
void glob_finderror(t_pd *dummy)
{
if (!error_object)
- post("no findable error yet.");
+ post("no findable error yet.");
else
{
- post("last trackable error:");
- post("%s", error_string);
- canvas_finderror(error_object);
+ post("last trackable error:");
+ post("%s", error_string);
+ canvas_finderror(error_object);
}
}
-void bug(char *fmt, ...)
+void bug(const char *fmt, ...)
{
+ char buf[MAXPDSTRING];
va_list ap;
t_int arg[8];
int i;
+ dopost("consistency check failed: ");
va_start(ap, fmt);
-
- for (i = 0 ; i < 8; i++) arg[i] = va_arg(ap, t_int);
+ vsnprintf(buf, MAXPDSTRING-1, fmt, ap);
va_end(ap);
- fprintf(stderr, "Consistency check failed: ");
- fprintf(stderr, fmt, arg[0], arg[1], arg[2], arg[3],
- arg[4], arg[5], arg[6], arg[7]);
- putc('\n', stderr);
+ strcat(buf, "\n");
+ dopost(buf);
}
/* this isn't worked out yet. */
-static char *errobject;
-static char *errstring;
+static const char *errobject;
+static const char *errstring;
-void sys_logerror(char *object, char *s)
+void sys_logerror(const char *object, const char *s)
{
errobject = object;
errstring = s;
}
-void sys_unixerror(char *object)
+void sys_unixerror(const char *object)
{
errobject = object;
errstring = strerror(errno);
diff --git a/pd/src/s_stuff.h b/pd/src/s_stuff.h
index 7a827b8b..87d6596b 100644
--- a/pd/src/s_stuff.h
+++ b/pd/src/s_stuff.h
@@ -7,15 +7,30 @@
/* 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 */
+/* in s_path.c */
+
typedef struct _namelist
{
struct _namelist *nl_next;
char *nl_string;
} t_namelist;
-t_namelist *namelist_append(t_namelist *listwas, const char *s);
+t_namelist *namelist_append(t_namelist *listwas, const char *s, int allowdup);
+t_namelist *namelist_append_files(t_namelist *listwas, const char *s);
void namelist_free(t_namelist *listwas);
+char *namelist_get(t_namelist *namelist, int n);
+void sys_setextrapath(const char *p);
+extern int sys_usestdpath;
+extern t_namelist *sys_externlist;
+extern t_namelist *sys_searchpath;
+extern t_namelist *sys_helppath;
+
+/* s_file.c */
+
+void sys_loadpreferences( void);
+void sys_savepreferences( void);
+extern int sys_defeatrt;
+extern t_symbol *sys_flags;
/* s_main.c */
extern int sys_debuglevel;
@@ -28,26 +43,26 @@ 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 */
+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_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 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 int sys_blocksize; /* audio I/O block size in sample frames */
extern float sys_dacsr;
extern int sys_schedadvance;
extern int sys_sleepgrain;
@@ -55,17 +70,9 @@ 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_reopen_audio( void);
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);
@@ -76,19 +83,32 @@ 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 */
+#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[];
+void sys_open_midi(int nmidiin, int *midiinvec,
+ int nmidiout, int *midioutvec, int enable);
+void sys_get_midi_params(int *pnmidiindev, int *pmidiindev,
+ int *pnmidioutdev, int *pmidioutdev);
+
+void sys_reopen_midi( void);
+void sys_close_midi( void);
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);
+ /* implemented in the system dependent MIDI code (s_midi_pm.c, etc. ) */
+void midi_getdevs(char *indevlist, int *nindevs,
+ char *outdevlist, int *noutdevs, int maxndev, int devdescsize);
+void sys_do_open_midi(int nmidiindev, int *midiindev,
+ int nmidioutdev, int *midioutdev);
+
/* m_sched.c */
EXTERN void sys_log_error(int type);
#define ERR_NOTHING 0
@@ -130,6 +150,7 @@ void sys_setvirtualalarm( void);
#define API_MMIO 3
#define API_PORTAUDIO 4
#define API_JACK 5
+#define API_SGI 6
#ifdef __linux__
#define API_DEFAULT API_OSS
@@ -143,6 +164,10 @@ void sys_setvirtualalarm( void);
#define API_DEFAULT API_PORTAUDIO
#define API_DEFSTRING "portaudio"
#endif
+#ifdef IRIX
+#define API_DEFAULT API_SGI
+#define API_DEFSTRING "SGI Digital Media"
+#endif
#define DEFAULTAUDIODEV 0
#define MAXAUDIOINDEV 4
@@ -166,7 +191,7 @@ 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 maxndev, int devdescsize);
int oss_open_audio(int naudioindev, int *audioindev, int nchindev,
int *chindev, int naudiooutdev, int *audiooutdev, int nchoutdev,
@@ -176,7 +201,7 @@ 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 maxndev, int devdescsize);
int alsa_open_audio(int naudioindev, int *audioindev, int nchindev,
int *chindev, int naudiooutdev, int *audiooutdev, int nchoutdev,
@@ -186,12 +211,15 @@ 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 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_getdevs(char *indevlist, int *nindevs,
+ char *outdevlist, int *noutdevs, int *canmulti,
+ int maxndev, int devdescsize);
void jack_listdevs(void);
void mmio_open_audio(int naudioindev, int *audioindev,
@@ -202,7 +230,7 @@ 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);
+ int maxndev, int devdescsize);
void sys_listmididevs(void);
void sys_set_audio_api(int whichapi);
@@ -213,3 +241,60 @@ void sys_set_audio_state(int onoff);
/* API dependent audio flags and settings */
void oss_set32bit( void);
void linux_alsa_devname(char *devname);
+
+void sys_get_audio_params(
+ int *pnaudioindev, int *paudioindev, int *chindev,
+ int *pnaudiooutdev, int *paudiooutdev, int *choutdev,
+ int *prate, int *padvance);
+void sys_save_audio_params(
+ int naudioindev, int *audioindev, int *chindev,
+ int naudiooutdev, int *audiooutdev, int *choutdev,
+ int rate, int advance);
+
+/* s_file.c */
+
+typedef void (*t_printhook)(const char *s);
+extern t_printhook sys_printhook; /* set this to override printing */
+extern int sys_printtostderr;
+#ifdef MSW
+#define vsnprintf _vsnprintf /* jsarlo -- alias this name for msw */
+#endif
+
+/* jsarlo { */
+
+EXTERN double sys_time;
+EXTERN double sys_time_per_dsp_tick;
+EXTERN int sys_externalschedlib;
+
+EXTERN t_sample* get_sys_soundout(void ) ;
+EXTERN t_sample* get_sys_soundin(void ) ;
+EXTERN int* get_sys_main_advance(void ) ;
+EXTERN double* get_sys_time_per_dsp_tick(void ) ;
+EXTERN int* get_sys_schedblocksize(void ) ;
+EXTERN double* get_sys_time(void ) ;
+EXTERN float* get_sys_dacsr(void ) ;
+EXTERN int* get_sys_sleepgrain(void ) ;
+EXTERN int* get_sys_schedadvance(void ) ;
+
+EXTERN void sys_clearhist(void );
+EXTERN void sys_initmidiqueue(void );
+EXTERN int sys_addhist(int phase);
+EXTERN void sys_setmiditimediff(double inbuftime, double outbuftime);
+EXTERN void sched_tick(double next_sys_time);
+EXTERN void sys_pollmidiqueue(void );
+EXTERN int sys_pollgui(void );
+EXTERN void sys_setchsr(int chin, int chout, int sr);
+
+EXTERN void inmidi_noteon(int portno, int channel, int pitch, int velo);
+EXTERN void inmidi_controlchange(int portno,
+ int channel,
+ int ctlnumber,
+ int value);
+EXTERN void inmidi_programchange(int portno, int channel, int value);
+EXTERN void inmidi_pitchbend(int portno, int channel, int value);
+EXTERN void inmidi_aftertouch(int portno, int channel, int value);
+EXTERN void inmidi_polyaftertouch(int portno,
+ int channel,
+ int pitch,
+ int value);
+/* } jsarlo */
diff --git a/pd/src/s_watchdog.c b/pd/src/s_watchdog.c
index a2122824..2602334d 100644
--- a/pd/src/s_watchdog.c
+++ b/pd/src/s_watchdog.c
@@ -17,31 +17,31 @@ int main(int argc, char **argv)
int happy = 1;
while (1)
{
- struct timeval timout;
- fd_set readset;
- if (happy)
- {
- timout.tv_sec = 5;
- timout.tv_usec = 0;
- }
- else
- {
- timout.tv_sec = 2;
- timout.tv_usec = 0;
- }
- FD_ZERO(&readset);
- FD_SET(0, &readset);
- select(1, &readset, 0, 0, &timout);
- if (FD_ISSET(0, &readset))
- {
- char buf[100];
- happy = 1;
- if (read(0, &buf, 100) <= 0)
- return (0);
- else continue;
- }
- happy = 0;
- kill(getppid(), SIGHUP);
- fprintf(stderr, "watchdog: signaling pd...\n");
+ struct timeval timout;
+ fd_set readset;
+ if (happy)
+ {
+ timout.tv_sec = 5;
+ timout.tv_usec = 0;
+ }
+ else
+ {
+ timout.tv_sec = 2;
+ timout.tv_usec = 0;
+ }
+ FD_ZERO(&readset);
+ FD_SET(0, &readset);
+ select(1, &readset, 0, 0, &timout);
+ if (FD_ISSET(0, &readset))
+ {
+ char buf[100];
+ happy = 1;
+ if (read(0, &buf, 100) <= 0)
+ return (0);
+ else continue;
+ }
+ happy = 0;
+ kill(getppid(), SIGHUP);
+ fprintf(stderr, "watchdog: signaling pd...\n");
}
}
diff --git a/pd/src/t_main.c b/pd/src/t_main.c
index d4d48c63..76bbb707 100644
--- a/pd/src/t_main.c
+++ b/pd/src/t_main.c
@@ -19,26 +19,18 @@
#include <stdlib.h>
/*
- * The following variable is a special hack that is needed in order for
- * Sun shared libraries to be used for Tcl.
- */
-
-extern int matherr(void);
-int *tclDummyMathPtr = (int *) matherr;
-
-/*
*----------------------------------------------------------------------
*
* main --
*
- * This is the main program for the application.
+ * This is the main program for the application.
*
* Results:
- * None: Tk_Main never returns here, so this procedure never
- * returns either.
+ * None: Tk_Main never returns here, so this procedure never
+ * returns either.
*
* Side effects:
- * Whatever the application does.
+ * Whatever the application does.
*
*----------------------------------------------------------------------
*/
@@ -54,18 +46,18 @@ main(int argc, char **argv)
pdgui_setname(argv[0]);
if (argc >= 2)
{
- pdgui_setsock(atoi(argv[1]));
- argc--; argv++;
- argv[0] = "Pd";
+ pdgui_setsock(atoi(argv[1]));
+ argc--; argv++;
+ argv[0] = "Pd";
}
if (argc >= 2)
{
- pdgui_sethost(argv[1]);
- argc--; argv++;
- argv[0] = "Pd";
+ pdgui_sethost(argv[1]);
+ argc--; argv++;
+ argv[0] = "Pd";
}
Tk_Main(argc, argv, Tcl_AppInit);
- return 0; /* Needed only to prevent compiler warning. */
+ return 0; /* Needed only to prevent compiler warning. */
}
@@ -74,16 +66,16 @@ main(int argc, char **argv)
*
* Tcl_AppInit --
*
- * This procedure performs application-specific initialization.
- * Most applications, especially those that incorporate additional
- * packages, will have their own version of this procedure.
+ * This procedure performs application-specific initialization.
+ * Most applications, especially those that incorporate additional
+ * packages, will have their own version of this procedure.
*
* Results:
- * Returns a standard Tcl completion code, and leaves an error
- * message in interp->result if an error occurs.
+ * Returns a standard Tcl completion code, and leaves an error
+ * message in interp->result if an error occurs.
*
* Side effects:
- * Depends on the startup script.
+ * Depends on the startup script.
*
*----------------------------------------------------------------------
*/
@@ -91,15 +83,15 @@ main(int argc, char **argv)
int
Tcl_AppInit(interp)
- Tcl_Interp *interp; /* Interpreter for application. */
+ Tcl_Interp *interp; /* Interpreter for application. */
{
Tk_Window mainwindow;
if (Tcl_Init(interp) == TCL_ERROR) {
- return TCL_ERROR;
+ return TCL_ERROR;
}
if (Tk_Init(interp) == TCL_ERROR) {
- return TCL_ERROR;
+ return TCL_ERROR;
}
/* setup specific to pd-gui: */
@@ -114,7 +106,7 @@ Tcl_AppInit(interp)
*/
#if 0
- tcl_RcFileName = "~/.pdrc";
+ tcl_RcFileName = "~/.apprc";
#endif
return TCL_OK;
diff --git a/pd/src/t_tkcmd.c b/pd/src/t_tkcmd.c
index ff12a284..23e53572 100644
--- a/pd/src/t_tkcmd.c
+++ b/pd/src/t_tkcmd.c
@@ -2,7 +2,7 @@
* For information on usage and redistribution, and for a DISCLAIMER OF ALL
* WARRANTIES, see the file, "LICENSE.txt," in this distribution. */
-#ifdef UNIX /* in unix this only works first; in NT it only works last. */
+#ifndef MSW /* in unix this only works first; in MSW it only works last. */
#include "tk.h"
#endif
@@ -12,16 +12,19 @@
#include <stdio.h>
#include <stdarg.h>
#include <sys/types.h>
-#ifdef UNIX
+
+#ifndef MSW
#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h>
+#include <netinet/tcp.h>
#include <netdb.h>
#ifdef HAVE_BSTRING_H
#include <bstring.h>
#endif
#include <sys/time.h>
#include <errno.h>
+#include <fcntl.h>
#endif
#ifdef MSW
#include <winsock.h>
@@ -37,15 +40,30 @@
#include "tk.h"
#endif
+#ifdef MACOSX
+#define STARTGUI
+#endif
+
+#ifdef __linux__
+#define STARTGUI
+#endif
+
+#define FIRSTPORTNUM 5600
+
void tcl_mess(char *s);
+static Tcl_Interp *tk_pdinterp;
+static int pd_portno = 0;
+
/***************** the socket setup code ********************/
-static int portno = 5400;
+/* If this is reset by pdgui_setsock(), it's the port number Pd will try to
+connect to; but if zero, that means we should set it and start Pd ourselves. */
+
- /* some installations of linux don't know about "localhost" so give
- the loopback address; NT, on the other hand, can't understand the
- hostname "127.0.0.1". */
+ /* some installations of linux don't know about "localhost" so give
+ the loopback address; NT, on the other hand, can't understand the
+ hostname "127.0.0.1". */
char hostname[100] =
#ifdef __linux__
"127.0.0.1";
@@ -55,9 +73,10 @@ char hostname[100] =
void pdgui_setsock(int port)
{
- portno = port;
+ pd_portno = port;
}
+ /* why is this here??? probably never used (see t_main.c). */
void pdgui_sethost(char *name)
{
strncpy(hostname, name, 100);
@@ -69,7 +88,7 @@ static void pdgui_sockerror(char *s)
#ifdef MSW
int err = WSAGetLastError();
#endif
-#ifdef UNIX
+#ifndef MSW
int err = errno;
#endif
@@ -80,14 +99,14 @@ static void pdgui_sockerror(char *s)
static int sockfd;
-/* The "pd_suck" command, which polls the socket.
- FIXME: if Pd sends something bigger than SOCKSIZE we're in trouble!
- This has to be set bigger than any array update message for instance.
-*/
-#define SOCKSIZE 20000
+/* The "pd_suck" command, which polls the socket. */
-static char pd_tkbuf[SOCKSIZE+1];
-int pd_spillbytes = 0;
+#define CHUNKSIZE 20000 /* chunks to allocate memory for reading socket */
+#define READSIZE 10000 /* size of read to issue */
+
+static char *pd_tkbuf = 0; /* buffer for reading */
+static int pd_tkbufsize = 0; /* current buffer size */
+static int pd_tkgotbytes = 0; /* number of bytes already in buffer */
static void pd_readsocket(ClientData cd, int mask)
{
@@ -102,59 +121,89 @@ static void pd_readsocket(ClientData cd, int mask)
FD_ZERO(&exceptset);
FD_SET(sockfd, &readset);
FD_SET(sockfd, &exceptset);
-
+ if (!pd_tkbuf)
+ {
+ if (!(pd_tkbuf = malloc(CHUNKSIZE)))
+ {
+ fprintf(stderr, "pd-gui: out of memory\n");
+ tcl_mess("exit\n");
+ }
+ pd_tkbufsize = CHUNKSIZE;
+ }
+ if (pd_tkgotbytes + READSIZE + 1 > pd_tkbufsize)
+ {
+ int newsize = pd_tkbufsize + CHUNKSIZE;
+ char *newbuf = realloc(pd_tkbuf, newsize);
+ if (!newbuf)
+ {
+ fprintf(stderr, "pd-gui: out of memory\n");
+ tcl_mess("exit\n");
+ }
+ pd_tkbuf = newbuf;
+ pd_tkbufsize = newsize;
+ }
if (select(sockfd+1, &readset, &writeset, &exceptset, &timout) < 0)
- perror("select");
+ perror("select");
if (FD_ISSET(sockfd, &exceptset) || FD_ISSET(sockfd, &readset))
{
- int ret;
- ret = recv(sockfd, pd_tkbuf + pd_spillbytes,
- SOCKSIZE - pd_spillbytes, 0);
- if (ret < 0) pdgui_sockerror("socket receive error");
- else if (ret == 0)
- {
- /* fprintf(stderr, "read %d\n", SOCKSIZE - pd_spillbytes); */
- fprintf(stderr, "pd_gui: pd process exited\n");
- tcl_mess("exit\n");
- }
- else
- {
- char *lastcr = 0, *bp = pd_tkbuf, *ep = bp + (pd_spillbytes + ret);
- int brace = 0;
- char lastc = 0;
- while (bp < ep)
- {
- char c = *bp;
- if (c == '}' && brace) brace--;
- else if (c == '{') brace++;
- else if (!brace && c == '\n' && lastc != '\\') lastcr = bp;
- lastc = c;
- bp++;
- }
- if (lastcr)
- {
- int xtra = pd_tkbuf + pd_spillbytes + ret - (lastcr+1);
- char bashwas = lastcr[1];
- lastcr[1] = 0;
- tcl_mess(pd_tkbuf);
- lastcr[1] = bashwas;
- if (xtra)
- {
- /* fprintf(stderr, "x %d\n", xtra); */
- memmove(pd_tkbuf, lastcr+1, xtra);
- }
- pd_spillbytes = xtra;
- }
- else
- {
- pd_spillbytes += ret;
- }
- }
+ int ret;
+ ret = recv(sockfd, pd_tkbuf + pd_tkgotbytes, READSIZE, 0);
+ if (ret < 0)
+ pdgui_sockerror("socket receive error");
+ else if (ret == 0)
+ {
+ /* fprintf(stderr, "read %d\n", SOCKSIZE - pd_tkgotbytes); */
+ fprintf(stderr, "pd_gui: pd process exited\n");
+ tcl_mess("exit\n");
+ }
+ else
+ {
+ char *lastcr = 0, *bp = pd_tkbuf, *ep = bp + (pd_tkgotbytes + ret);
+ int brace = 0;
+ char lastc = 0;
+ /* search for locations that terminate a complete TK
+ command. These are carriage returns which are not inside
+ any braces. Braces can be escaped with backslashes (but
+ backslashes themselves can't.) */
+ while (bp < ep)
+ {
+ char c = *bp;
+ if (c == '}' && brace)
+ brace--;
+ else if (c == '{')
+ brace++;
+ else if (!brace && c == '\n' && lastc != '\\')
+ lastcr = bp;
+ lastc = c;
+ bp++;
+ }
+ /* if lastcr is set there is at least one complete TK
+ command in the buffer. Execute it or them, and slide any
+ extra bytes to beginning of the buffer. */
+ if (lastcr)
+ {
+ int xtra = pd_tkbuf + pd_tkgotbytes + ret - (lastcr+1);
+ char bashwas = lastcr[1];
+ lastcr[1] = 0;
+ tcl_mess(pd_tkbuf);
+ lastcr[1] = bashwas;
+ if (xtra)
+ {
+ /* fprintf(stderr, "x %d\n", xtra); */
+ memmove(pd_tkbuf, lastcr+1, xtra);
+ }
+ pd_tkgotbytes = xtra;
+ }
+ else
+ {
+ pd_tkgotbytes += ret;
+ }
+ }
}
}
-#ifndef UNIX
- /* if we aren't UNIX, we add a tcl command to poll the
+#ifdef MSW
+ /* if we're in Gatesland, we add a tcl command to poll the
socket for data. */
static int pd_pollsocketCmd(ClientData cd, Tcl_Interp *interp,
int argc, char **argv)
@@ -164,11 +213,28 @@ static int pd_pollsocketCmd(ClientData cd, Tcl_Interp *interp,
}
#endif
-void pdgui_setupsocket(void)
+static void pd_sockerror(char *s)
+{
+#ifdef MSW
+ int err = WSAGetLastError();
+ if (err == 10054) return;
+ else if (err == 10044)
+ {
+ fprintf(stderr,
+ "Warning: you might not have TCP/IP \"networking\" turned on\n");
+ fprintf(stderr, "which is needed for Pd to talk to its GUI layer.\n");
+ }
+#else
+ int err = errno;
+#endif
+ fprintf(stderr, "%s: %s (%d)\n", s, strerror(err), err);
+}
+
+static void pdgui_connecttosocket(void)
{
struct sockaddr_in server;
struct hostent *hp;
-#ifdef UNIX
+#ifndef MSW
int retry = 10;
#else
int retry = 1;
@@ -191,51 +257,217 @@ void pdgui_setupsocket(void)
if (hp == 0)
{
- fprintf(stderr,
- "localhost not found (inet protocol not installed?)\n");
- exit(1);
+ fprintf(stderr,
+ "localhost not found (inet protocol not installed?)\n");
+ exit(1);
}
memcpy((char *)&server.sin_addr, (char *)hp->h_addr, hp->h_length);
/* assign client port number */
- server.sin_port = htons((unsigned short)portno);
+ server.sin_port = htons((unsigned short)pd_portno);
- /* try to connect */
+ /* try to connect */
while (1)
{
- if (connect(sockfd, (struct sockaddr *) &server, sizeof (server)) >= 0)
- goto gotit;
- retry--;
- if (retry <= 0)
- break;
- /* In UNIX there's a race condition; the child won't be
- able to connect before the parent (pd) has shed its
- setuid-ness. In case this is the problem, sleep and
- retry. */
- else
- {
-#ifdef UNIX
- fd_set readset, writeset, exceptset;
- struct timeval timout;
-
- timout.tv_sec = 0;
- timout.tv_usec = 100000;
- FD_ZERO(&writeset);
- FD_ZERO(&readset);
- FD_ZERO(&exceptset);
- fprintf(stderr, "retrying connect...\n");
- if (select(1, &readset, &writeset, &exceptset, &timout) < 0)
- perror("select");
-#endif /* UNIX */
- }
+ if (connect(sockfd, (struct sockaddr *) &server, sizeof (server)) >= 0)
+ goto gotit;
+ retry--;
+ if (retry <= 0)
+ break;
+ /* In unix there's a race condition; the child won't be
+ able to connect before the parent (pd) has shed its
+ setuid-ness. In case this is the problem, sleep and
+ retry. */
+ else
+ {
+#ifndef MSW
+ fd_set readset, writeset, exceptset;
+ struct timeval timout;
+
+ timout.tv_sec = 0;
+ timout.tv_usec = 100000;
+ FD_ZERO(&writeset);
+ FD_ZERO(&readset);
+ FD_ZERO(&exceptset);
+ fprintf(stderr, "retrying connect...\n");
+ if (select(1, &readset, &writeset, &exceptset, &timout) < 0)
+ perror("select");
+#endif /* !MSW */
+ }
}
pdgui_sockerror("connecting stream socket");
gotit: ;
-#ifdef UNIX
- /* in unix we ask TK to call us back. In NT we have to poll. */
+#ifndef MSW
+ /* normally we ask TK to call us back; but in MSW we have to poll. */
+ Tk_CreateFileHandler(sockfd, TK_READABLE | TK_EXCEPTION,
+ pd_readsocket, 0);
+#endif /* !MSW */
+}
+
+#ifdef STARTGUI
+
+/* #define DEBUGCONNECT */
+
+#ifdef DEBUGCONNECT
+static FILE *debugfd;
+#endif
+
+
+static void pd_startfromgui( void)
+{
+ pid_t childpid;
+ char cmdbuf[1000], pdbuf[1000], *lastchar;
+ const char *arg0;
+ struct sockaddr_in server;
+ int msgsock;
+ int len = sizeof(server), nchar;
+ int ntry = 0, portno = FIRSTPORTNUM;
+ int xsock = -1;
+ char morebuf[256];
+#ifdef MSW
+ short version = MAKEWORD(2, 0);
+ WSADATA nobby;
+ char scriptbuf[1000], wishbuf[1000], portbuf[80];
+ int spawnret;
+ char intarg;
+#else
+ int intarg;
+#endif
+
+ arg0 = Tcl_GetVar(tk_pdinterp, "argv0", 0);
+ if (!arg0)
+ {
+ fprintf(stderr, "Pd-gui: can't get arg 0\n");
+ return;
+ }
+ lastchar = strrchr(arg0, '/');
+ if (lastchar)
+ snprintf(pdbuf, lastchar - arg0 + 1, "%s", arg0);
+ else strcpy(pdbuf, ".");
+ strcat(pdbuf, "/../bin/pd");
+#ifdef DEBUGCONNECT
+ fprintf(stderr, "pdbuf is %s\n", pdbuf);
+#endif
+
+#ifdef MSW
+ if (WSAStartup(version, &nobby))
+ pd_sockerror("WSAstartup");
+#endif
+
+ /* create a socket */
+ xsock = socket(AF_INET, SOCK_STREAM, 0);
+ if (xsock < 0) pd_sockerror("socket");
+ intarg = 1;
+ if (setsockopt(xsock, IPPROTO_TCP, TCP_NODELAY,
+ &intarg, sizeof(intarg)) < 0)
+ fprintf(stderr, "setsockopt (TCP_NODELAY) failed\n");
+
+ server.sin_family = AF_INET;
+ server.sin_addr.s_addr = INADDR_ANY;
+
+ /* assign server port number */
+ server.sin_port = htons((unsigned short)portno);
+
+ /* name the socket */
+ while (bind(xsock, (struct sockaddr *)&server, sizeof(server)) < 0)
+ {
+#ifdef MSW
+ int err = WSAGetLastError();
+#else
+ int err = errno;
+#endif
+ if ((ntry++ > 20) || (err != EADDRINUSE))
+ {
+ perror("bind");
+ fprintf(stderr,
+ "couldn't open GUI-to-pd network connection\n");
+ return;
+ }
+ portno++;
+ server.sin_port = htons((unsigned short)(portno));
+ }
+
+#ifdef DEBUGCONNECT
+ fprintf(debugfd, "port %d\n", portno);
+ fflush(debugfd);
+#endif
+
+#ifdef UNISTD
+ childpid = fork();
+ if (childpid < 0)
+ {
+ if (errno) perror("sys_startgui");
+ else fprintf(stderr, "sys_startgui failed\n");
+ return;
+ }
+ else if (!childpid) /* we're the child */
+ {
+ sprintf(cmdbuf, "\"%s\" -guiport %d\n", pdbuf, portno);
+#ifdef DEBUGCONNECT
+ fprintf(debugfd, "%s", cmdbuf);
+ fflush(debugfd);
+#endif
+ execl("/bin/sh", "sh", "-c", cmdbuf, 0);
+ perror("pd: exec");
+ _exit(1);
+ }
+#endif /* UNISTD */
+
+#ifdef MSW
+
+#error not yet used.... sys_bashfilename() not filled in here
+
+ strcpy(cmdbuf, pdcmd);
+ strcat(cmdbuf, "/pd.exe");
+ sys_bashfilename(scriptbuf, scriptbuf);
+
+ sprintf(portbuf, "%d", portno);
+
+ spawnret = _spawnl(P_NOWAIT, cmdbuf, "pd.exe", "-port", portbuf, 0);
+ if (spawnret < 0)
+ {
+ perror("spawnl");
+ fprintf(stderr, "%s: couldn't start\n", cmdbuf);
+ return;
+ }
+
+#endif /* MSW */
+
+#ifdef DEBUGCONNECT
+ fprintf(stderr, "Waiting for connection request... \n");
+#endif
+ if (listen(xsock, 5) < 0) pd_sockerror("listen");
+ sockfd = accept(xsock, (struct sockaddr *) &server, &len);
+ if (sockfd < 0) pd_sockerror("accept");
+#ifdef DEBUGCONNECT
+ fprintf(stderr, "... connected\n");
+#endif
+
+#ifndef MSW
+ /* normally we ask TK to call us back; but in MSW we have to poll. */
Tk_CreateFileHandler(sockfd, TK_READABLE | TK_EXCEPTION,
- pd_readsocket, 0);
-#endif /* UNIX */
+ pd_readsocket, 0);
+#endif /* !MSW */
+}
+
+#endif /* STARTGUI */
+
+static void pdgui_setupsocket(void)
+{
+#ifdef DEBUGCONNECT
+ debugfd = fopen("/Users/msp/bratwurst", "w");
+ fprintf(debugfd, "turning stderr back on\n");
+ fflush(debugfd);
+ dup2(fileno(debugfd), 2);
+ fprintf(stderr, "duped to stderr?\n");
+#endif
+#ifdef MSW
+ pdgui_connecttosocket();
+#else
+ if (pd_portno)
+ pdgui_connecttosocket();
+ else pd_startfromgui() ;
+#endif
}
/**************************** commands ************************/
@@ -250,70 +482,53 @@ static int pdCmd(ClientData cd, Tcl_Interp *interp, int argc, char **argv)
{
if (argc == 2)
{
- int n = strlen(argv[1]);
- if (send(sockfd, argv[1], n, 0) < n)
- {
- perror("stdout");
- tcl_mess("exit\n");
- }
+ int n = strlen(argv[1]);
+ if (send(sockfd, argv[1], n, 0) < n)
+ {
+ perror("stdout");
+ tcl_mess("exit\n");
+ }
}
else
{
- int i;
- char buf[MAXWRITE];
- buf[0] = 0;
- for (i = 1; i < argc; i++)
- {
- if (strlen(argv[i]) + strlen(buf) + 2 > MAXWRITE)
- {
- interp->result = "pd: arg list too long";
- return (TCL_ERROR);
- }
- if (i > 1) strcat(buf, " ");
- strcat(buf, argv[i]);
- }
- if (send(sockfd, buf, strlen(buf), 0) < 0)
- {
- perror("stdout");
- tcl_mess("exit\n");
- }
+ int i;
+ char buf[MAXWRITE];
+ buf[0] = 0;
+ for (i = 1; i < argc; i++)
+ {
+ if (strlen(argv[i]) + strlen(buf) + 2 > MAXWRITE)
+ {
+ interp->result = "pd: arg list too long";
+ return (TCL_ERROR);
+ }
+ if (i > 1) strcat(buf, " ");
+ strcat(buf, argv[i]);
+ }
+ if (send(sockfd, buf, strlen(buf), 0) < 0)
+ {
+ perror("stdout");
+ tcl_mess("exit\n");
+ }
}
return (TCL_OK);
}
/*********** "c" level access to tk functions. ******************/
-static Tcl_Interp *tk_myinterp;
-
void tcl_mess(char *s)
{
int result;
- result = Tcl_Eval(tk_myinterp, s);
+ result = Tcl_Eval(tk_pdinterp, s);
if (result != TCL_OK)
{
- if (*tk_myinterp->result) printf("%s\n", tk_myinterp->result);
+ if (*tk_pdinterp->result) printf("%s\n", tk_pdinterp->result);
}
}
-/* LATER should do a bounds check -- but how do you get printf to do that? */
-void tcl_vmess(char *fmt, ...)
-{
- int result, i;
- char buf[MAXWRITE];
- va_list ap;
-
- va_start(ap, fmt);
-
- vsprintf(buf, fmt, ap);
- result = Tcl_Eval(tk_myinterp, buf);
- if (result != TCL_OK)
- {
- if (*tk_myinterp->result) printf("%s\n", tk_myinterp->result);
- }
- va_end(ap);
-}
-
-#ifdef UNIX
+ /* in linux, we load the tk code from here (in MSW and MACOS, this
+ is done by passing the name of the file as a startup argument to
+ the wish shell.) */
+#if !defined(MSW) && !defined(MACOSX)
void pdgui_doevalfile(Tcl_Interp *interp, char *s)
{
char buf[GUISTRING];
@@ -324,42 +539,39 @@ void pdgui_doevalfile(Tcl_Interp *interp, char *s)
strcat(buf, s);
if (Tcl_EvalFile(interp, buf) != TCL_OK)
{
- char buf2[1000];
- sprintf(buf2, "puts [concat tcl: %s: can't open script]\n",
- buf);
- tcl_mess(buf2);
+ char buf2[1000];
+ sprintf(buf2, "puts [concat tcl: %s: can't open script]\n",
+ buf);
+ tcl_mess(buf2);
}
}
void pdgui_evalfile(char *s)
{
- pdgui_doevalfile(tk_myinterp, s);
+ pdgui_doevalfile(tk_pdinterp, s);
}
#endif
void pdgui_startup(Tcl_Interp *interp)
{
+ /* save pointer to the main interpreter */
+ tk_pdinterp = interp;
- /* save pointer to the main interpreter */
- tk_myinterp = interp;
-
-
- /* add our own TK commands */
+ /* add our own TK commands */
Tcl_CreateCommand(interp, "pd", (Tcl_CmdProc*)pdCmd, (ClientData)NULL,
- (Tcl_CmdDeleteProc *)NULL);
-#ifndef UNIX
+ (Tcl_CmdDeleteProc *)NULL);
+#ifdef MSW
Tcl_CreateCommand(interp, "pd_pollsocket",(Tcl_CmdProc*) pd_pollsocketCmd,
- (ClientData)NULL, (Tcl_CmdDeleteProc *)NULL);
+ (ClientData)NULL, (Tcl_CmdDeleteProc *)NULL);
#endif
pdgui_setupsocket();
-
- /* read in the startup file */
+ /* read in the startup file */
#if !defined(MSW) && !defined(MACOSX)
pdgui_evalfile("pd.tk");
#endif
}
-#ifdef UNIX
+#ifndef MSW
void pdgui_setname(char *s)
{
char *t;
@@ -372,27 +584,34 @@ void pdgui_setname(char *s)
strncpy(pdgui_path, str, n);
while (strlen(pdgui_path) > 0 && pdgui_path[strlen(pdgui_path)-1] == '/')
- pdgui_path[strlen(pdgui_path)-1] = 0;
+ pdgui_path[strlen(pdgui_path)-1] = 0;
if (t = strrchr(pdgui_path, '/'))
- *t = 0;
+ *t = 0;
}
#endif
+ /* this is called when an off-the-shelf "wish" has to "load" this module
+ at runtime. In Linux, this module is linked in and Pdtcl_Init() is not
+ called; instead, the code in t_main.c calls pdgui_setsock() and
+ pdgui_startup(). */
+
int Pdtcl_Init(Tcl_Interp *interp)
{
- const char *myvalue = Tcl_GetVar(interp, "argv", 0);
- int myportno;
- if (myvalue && (myportno = atoi(myvalue)) > 1)
- pdgui_setsock(myportno);
- tk_myinterp = interp;
- pdgui_startup(interp);
- interp->result = "loaded pdtcl_init";
-
- return (TCL_OK);
+ const char *argv = Tcl_GetVar(interp, "argv", 0);
+ int portno, argno = 0;
+ if (argv && (portno = atoi(argv)) > 1)
+ pdgui_setsock(portno);
+ tk_pdinterp = interp;
+ pdgui_startup(interp);
+ interp->result = "loaded pdtcl_init";
+
+ return (TCL_OK);
}
+#if 0
int Pdtcl_SafeInit(Tcl_Interp *interp) {
fprintf(stderr, "Pdtcl_Safeinit 51\n");
- return (TCL_OK);
+ return (TCL_OK);
}
+#endif
diff --git a/pd/src/u_main.tk b/pd/src/u_main.tk
index 6140c714..b07c7d16 100644
--- a/pd/src/u_main.tk
+++ b/pd/src/u_main.tk
@@ -1,4 +1,6 @@
-set pd_nt 1
+#!/usr/bin/wish
+
+set pd_nt 0
# (The above is 0 for unix, 1 for microsoft, and 2 for Mac OSX. The first
# line is automatically munged by the relevant makefiles.)
@@ -96,7 +98,7 @@ checkbutton .controls.switches.meterbutton -text {peak meters} \
-anchor w \
-command {pd [concat pd meters $ctrls_meter_on \;]}
-pack .controls.switches.meterbutton .controls.switches.audiobutton -side left
+pack .controls.switches.audiobutton .controls.switches.meterbutton -side top
frame .controls.inout
frame .controls.inout.in
@@ -116,18 +118,37 @@ pack .controls.inout.out.label .controls.inout.out.level \
button .controls.dio -text "DIO\nerrors" \
-command {pd [concat pd audiostatus \;]}
-pack .controls.switches -side bottom -pady 12
pack .controls.inout.in .controls.inout.out -side left -padx 6
pack .controls.inout -side left -padx 14
+pack .controls.switches -side right
pack .controls.dio -side right -padx 20
-bind . <Control-Key> {pdtk_pd_ctrlkey %W %K 0}
-bind . <Control-Shift-Key> {pdtk_pd_ctrlkey %W %K 1}
-if {$pd_nt == 2} {
- bind . <Mod1-Key> {pdtk_canvas_ctrlkey %W %K 0}
- bind . <Mod1-Shift-Key> {pdtk_canvas_ctrlkey %W %K 1}
+
+frame .printout
+text .printout.text -relief raised -bd 2 -font -*-courier-bold--normal--12-* \
+ -yscrollcommand ".printout.scroll set" -width 80
+# .printout.text insert end "\n\n\n\n\n\n\n\n\n\n"
+scrollbar .printout.scroll -command ".printout.text yview"
+pack .printout.scroll -side right -fill y
+pack .printout.text -side left -fill both -expand 1
+pack .printout -side bottom -fill both -expand 1
+
+proc pdtk_post {stuff} {
+ .printout.text insert end $stuff
+ .printout.text yview end-2char
+}
+
+proc pdtk_standardkeybindings {id} {
+ global pd_nt
+ bind $id <Control-Key> {pdtk_pd_ctrlkey %W %K 0}
+ bind $id <Control-Shift-Key> {pdtk_pd_ctrlkey %W %K 1}
+ if {$pd_nt == 2} {
+ bind $id <Mod1-Key> {pdtk_canvas_ctrlkey %W %K 0}
+ bind $id <Mod1-Shift-Key> {pdtk_canvas_ctrlkey %W %K 1}
+ }
}
+pdtk_standardkeybindings .
wm title . "Pd"
. configure -menu .mbar -width 200 -height 150
@@ -155,10 +176,14 @@ proc pdtk_debug {x} {
}
proc pdtk_watchdog {} {
- pd [concat pd ping \;]
+ pd [concat pd watchdog \;]
after 2000 {pdtk_watchdog}
}
+proc pdtk_ping {} {
+ pd [concat pd ping \;]
+}
+
proc pdtk_check {x message} {
set answer [tk_messageBox \-message $x \-type yesno \-icon question]
switch $answer {
@@ -241,8 +266,8 @@ proc menu_send {} {
.sendpanel.entry select adjust end
bind .sendpanel.entry <KeyPress-Return> {
pd [concat $send_textvariable \;]
- after 50 {destroy .sendpanel}
}
+ pdtk_standardkeybindings .sendpanel.entry
focus .sendpanel.entry
}
@@ -377,6 +402,8 @@ proc menu_addstd {mbar} {
-accelerator [accel_munge "Ctrl+m"]
.mbar.file add command -label Path... \
-command {pd pd start-path-dialog \;}
+.mbar.file add command -label Startup... \
+ -command {pd pd start-startup-dialog \;}
.mbar.file add separator
.mbar.file add command -label Quit -command {menu_quit} \
-accelerator [accel_munge "Ctrl+q"]
@@ -650,6 +677,7 @@ proc menu_findobject {canvas} {
$name.entry select from 0
$name.entry select adjust end
bind $name.entry <KeyPress-Return> [ concat find_apply $name]
+ pdtk_standardkeybindings $name.entry
focus $name.entry
}
@@ -696,6 +724,9 @@ proc pdtk_canvas_new {name width height geometry editable} {
$name.m.file add command -label Path... \
-command {pd pd start-path-dialog \;}
+ $name.m.file add command -label Startup... \
+ -command {pd pd start-startup-dialog \;}
+
$name.m.file add separator
$name.m.file add command -label Close \
-command [concat menu_close $name] \
@@ -915,14 +946,21 @@ proc pdtk_canvas_new {name width height geometry editable} {
bind $name.c <Alt-Control-Button> {pdtk_canvas_click %W %x %y %b 6}
bind $name.c <Alt-Control-Shift-Button> {pdtk_canvas_click %W %x %y %b 7}
global pd_nt
+# button 2 is the right button on Mac; on other platforms it's button 3.
if {$pd_nt == 2} {
bind $name.c <Button-2> {pdtk_canvas_click %W %x %y %b 8}
bind $name.c <Control-Button> {pdtk_canvas_click %W %x %y %b 8}
} else {
bind $name.c <Button-3> {pdtk_canvas_click %W %x %y %b 8}
bind $name.c <Control-Button> {pdtk_canvas_click %W %x %y %b 2}
- }
-# change mac to right-click, not middle click -atl 2002.09.02
+ }
+#on linux, button 2 "pastes" from the X windows clipboard
+ if {$pd_nt == 0} {
+ bind $name.c <Button-2> {\
+ pdtk_canvas_click %W %x %y %b 0;\
+ pdtk_canvas_mouseup %W %x %y %b;\
+ pdtk_pastetext}
+ }
bind $name.c <ButtonRelease> {pdtk_canvas_mouseup %W %x %y %b}
bind $name.c <Control-Key> {pdtk_canvas_ctrlkey %W %K 0}
@@ -1000,11 +1038,9 @@ set pdtk_canvas_mouseup_ymaxval 0
proc pdtk_canvas_mouseup {name x y b} {
pd [concat [canvastosym $name] mouseup [$name canvasx $x] \
[$name canvasy $y] $b \;]
+}
-# we use the mouseup event to update scrollbar ranges and recheck the
-# geometry of the window since I haven't taken the time to figure out
-# how to do it right.
-
+proc pdtk_canvas_getscroll {name} {
global pdtk_canvas_mouseup_name
global pdtk_canvas_mouseup_xminval
global pdtk_canvas_mouseup_xmaxval
@@ -1456,6 +1492,9 @@ proc pdtk_gatom_dialog {id initwidth initlo inithi \
bind $id.paramhi.entry <KeyPress-Return> [concat dogatom_ok $id]
bind $id.paramlo.entry <KeyPress-Return> [concat dogatom_ok $id]
bind $id.params.entry <KeyPress-Return> [concat dogatom_ok $id]
+ pdtk_standardkeybindings $id.paramhi.entry
+ pdtk_standardkeybindings $id.paramlo.entry
+ pdtk_standardkeybindings $id.params.entry
$id.params.entry select from 0
$id.params.entry select adjust end
focus $id.params.entry
@@ -1610,6 +1649,12 @@ proc pdtk_graph_dialog {id x1 y1 x2 y2 xpix ypix} {
bind $id.yrangef.y1 <KeyPress-Return> [concat graph_ok $id]
bind $id.yrangef.y2 <KeyPress-Return> [concat graph_ok $id]
bind $id.yrangef.ypix <KeyPress-Return> [concat graph_ok $id]
+ pdtk_standardkeybindings $id.xrangef.x1
+ pdtk_standardkeybindings $id.xrangef.x2
+ pdtk_standardkeybindings $id.xrangef.xpix
+ pdtk_standardkeybindings $id.xrangef.y1
+ pdtk_standardkeybindings $id.xrangef.y2
+ pdtk_standardkeybindings $id.xrangef.ypix
$id.xrangef.x2 select from 0
$id.xrangef.x2 select adjust end
focus $id.xrangef.x2
@@ -1958,6 +2003,10 @@ proc iemgui_apply {id} {
if {[string index $hhhgui_nam 0] == "$"} {
set hhhgui_nam [string replace $hhhgui_nam 0 0 #] }
+ set hhhsnd [string map {" " _} $hhhsnd]
+ set hhhrcv [string map {" " _} $hhhrcv]
+ set hhhgui_nam [string map {" " _} $hhhgui_nam]
+
pd [concat $id dialog \
[eval concat $$var_iemgui_wdt] \
[eval concat $$var_iemgui_hgt] \
@@ -2320,6 +2369,18 @@ proc pdtk_iemgui_dialog {id mainheader \
bind $id.gnxy.y_ent <KeyPress-Return> [concat iemgui_ok $id]
bind $id.gnfs.fs_ent <KeyPress-Return> [concat iemgui_ok $id]
bind $id.cao.ok <KeyPress-Return> [concat iemgui_ok $id]
+ pdtk_standardkeybindings $id.dim.w_ent
+ pdtk_standardkeybindings $id.dim.h_ent
+ pdtk_standardkeybindings $id.rng.min_ent
+ pdtk_standardkeybindings $id.rng.max_ent
+ pdtk_standardkeybindings $id.para.num_ent
+ pdtk_standardkeybindings $id.snd.ent
+ pdtk_standardkeybindings $id.rcv.ent
+ pdtk_standardkeybindings $id.gnam.ent
+ pdtk_standardkeybindings $id.gnxy.x_ent
+ pdtk_standardkeybindings $id.gnxy.y_ent
+ pdtk_standardkeybindings $id.gnfs.fs_ent
+ pdtk_standardkeybindings $id.cao.ok
$id.dim.w_ent select from 0
$id.dim.w_ent select adjust end
@@ -2338,15 +2399,20 @@ proc array_apply {id} {
global $var_array_n
set var_array_saveit [concat array_saveit_$vid]
global $var_array_saveit
+ set var_array_drawasrects [concat array_drawasrects_$vid]
+ global $var_array_drawasrects
set var_array_otherflag [concat array_otherflag_$vid]
global $var_array_otherflag
set mofo [eval concat $$var_array_name]
if {[string index $mofo 0] == "$"} {
set mofo [string replace $mofo 0 0 #] }
+ set saveit [eval concat $$var_array_saveit]
+ set drawasrects [eval concat $$var_array_drawasrects]
+
pd [concat $id arraydialog $mofo \
[eval concat $$var_array_n] \
- [eval concat $$var_array_saveit] \
+ [expr $saveit + 2 * $drawasrects] \
[eval concat $$var_array_otherflag] \
\;]
}
@@ -2361,7 +2427,7 @@ proc array_ok {id} {
array_cancel $id
}
-proc pdtk_array_dialog {id name n saveit newone} {
+proc pdtk_array_dialog {id name n flags newone} {
set vid [string trimleft $id .]
set var_array_name [concat array_name_$vid]
@@ -2370,12 +2436,15 @@ proc pdtk_array_dialog {id name n saveit newone} {
global $var_array_n
set var_array_saveit [concat array_saveit_$vid]
global $var_array_saveit
+ set var_array_drawasrects [concat array_drawasrects_$vid]
+ global $var_array_drawasrects
set var_array_otherflag [concat array_otherflag_$vid]
global $var_array_otherflag
set $var_array_name $name
set $var_array_n $n
- set $var_array_saveit $saveit
+ set $var_array_saveit [expr ( $flags & 1 ) != 0]
+ set $var_array_drawasrects [expr ( $flags & 2 ) != 0]
set $var_array_otherflag 0
toplevel $id
@@ -2398,6 +2467,17 @@ proc pdtk_array_dialog {id name n saveit newone} {
-anchor w
pack $id.saveme -side top
+ frame $id.drawasrects
+ pack $id.drawasrects -side top
+ radiobutton $id.drawasrects.drawasrects0 -value 0 \
+ -variable $var_array_drawasrects \
+ -text "draw as polygon"
+ radiobutton $id.drawasrects.drawasrects1 -value 1 \
+ -variable $var_array_drawasrects \
+ -text "draw as points"
+ pack $id.drawasrects.drawasrects0 -side top -anchor w
+ pack $id.drawasrects.drawasrects1 -side top -anchor w
+
if {$newone != 0} {
frame $id.radio
pack $id.radio -side top
@@ -2428,6 +2508,8 @@ proc pdtk_array_dialog {id name n saveit newone} {
bind $id.name.entry <KeyPress-Return> [concat array_ok $id]
bind $id.n.entry <KeyPress-Return> [concat array_ok $id]
+ pdtk_standardkeybindings $id.name.entry
+ pdtk_standardkeybindings $id.n.entry
$id.name.entry select from 0
$id.name.entry select adjust end
focus $id.name.entry
@@ -2519,6 +2601,8 @@ proc pdtk_canvas_dialog {id xscale yscale graphme stretch} {
bind $id.xscale.entry <KeyPress-Return> [concat canvas_ok $id]
bind $id.yscale.entry <KeyPress-Return> [concat canvas_ok $id]
+ pdtk_standardkeybindings $id.xscale.entry
+ pdtk_standardkeybindings $id.yscale.entry
$id.xscale.entry select from 0
$id.xscale.entry select adjust end
focus $id.xscale.entry
@@ -2759,6 +2843,19 @@ proc pdtk_pd_texteditor {stuff} {
bind $name.text <Control-s> {texteditor_send %W}
}
+# paste text into a text box
+proc pdtk_pastetext {} {
+ global pdtk_pastebuffer
+ set pdtk_pastebuffer ""
+ catch {global pdtk_pastebuffer; set pdtk_pastebuffer [selection get]}
+# puts stderr [concat paste $pdtk_pastebuffer]
+ for {set i 0} {$i < [string length $pdtk_pastebuffer]} {incr i 1} {
+ set cha [string index $pdtk_pastebuffer $i]
+ scan $cha %c keynum
+ pd [concat pd key 1 $keynum 0 \;]
+ }
+}
+
############# open and save dialogs for objects in Pd ##########
proc pdtk_openpanel {target} {
@@ -2820,8 +2917,10 @@ if {$pd_nt == 1} {
proc audio_apply {id} {
global audio_indev1 audio_indev2 audio_indev3 audio_indev4
global audio_inchan1 audio_inchan2 audio_inchan3 audio_inchan4
+ global audio_inenable1 audio_inenable2 audio_inenable3 audio_inenable4
global audio_outdev1 audio_outdev2 audio_outdev3 audio_outdev4
global audio_outchan1 audio_outchan2 audio_outchan3 audio_outchan4
+ global audio_outenable1 audio_outenable2 audio_outenable3 audio_outenable4
global audio_sr audio_advance
pd [concat pd audio-dialog \
@@ -2829,18 +2928,18 @@ proc audio_apply {id} {
$audio_indev2 \
$audio_indev3 \
$audio_indev4 \
- $audio_inchan1 \
- $audio_inchan2 \
- $audio_inchan3 \
- $audio_inchan4 \
+ [expr $audio_inchan1 * ( $audio_inenable1 ? 1 : -1 ) ]\
+ [expr $audio_inchan2 * ( $audio_inenable2 ? 1 : -1 ) ]\
+ [expr $audio_inchan3 * ( $audio_inenable3 ? 1 : -1 ) ]\
+ [expr $audio_inchan4 * ( $audio_inenable4 ? 1 : -1 ) ]\
$audio_outdev1 \
$audio_outdev2 \
$audio_outdev3 \
$audio_outdev4 \
- $audio_outchan1 \
- $audio_outchan2 \
- $audio_outchan3 \
- $audio_outchan4 \
+ [expr $audio_outchan1 * ( $audio_outenable1 ? 1 : -1 ) ]\
+ [expr $audio_outchan2 * ( $audio_outenable2 ? 1 : -1 ) ]\
+ [expr $audio_outchan3 * ( $audio_outenable3 ? 1 : -1 ) ]\
+ [expr $audio_outchan4 * ( $audio_outenable4 ? 1 : -1 ) ]\
$audio_sr \
$audio_advance \
\;]
@@ -2889,8 +2988,10 @@ proc pdtk_audio_dialog {id indevlist indev1 indev2 indev3 indev4 \
outchan1 outchan2 outchan3 outchan4 sr advance multi longform} {
global audio_indev1 audio_indev2 audio_indev3 audio_indev4
global audio_inchan1 audio_inchan2 audio_inchan3 audio_inchan4
+ global audio_inenable1 audio_inenable2 audio_inenable3 audio_inenable4
global audio_outdev1 audio_outdev2 audio_outdev3 audio_outdev4
global audio_outchan1 audio_outchan2 audio_outchan3 audio_outchan4
+ global audio_outenable1 audio_outenable2 audio_outenable3 audio_outenable4
global audio_sr audio_advance
global audio_indevlist audio_outdevlist
@@ -2898,18 +2999,30 @@ proc pdtk_audio_dialog {id indevlist indev1 indev2 indev3 indev4 \
set audio_indev2 $indev2
set audio_indev3 $indev3
set audio_indev4 $indev4
- set audio_inchan1 $inchan1
- set audio_inchan2 $inchan2
- set audio_inchan3 $inchan3
- set audio_inchan4 $inchan4
+
+ set audio_inchan1 [expr ( $inchan1 > 0 ? $inchan1 : -$inchan1 ) ]
+ set audio_inenable1 [expr $inchan1 > 0 ]
+ set audio_inchan2 [expr ( $inchan2 > 0 ? $inchan2 : -$inchan2 ) ]
+ set audio_inenable2 [expr $inchan2 > 0 ]
+ set audio_inchan3 [expr ( $inchan3 > 0 ? $inchan3 : -$inchan3 ) ]
+ set audio_inenable3 [expr $inchan3 > 0 ]
+ set audio_inchan4 [expr ( $inchan4 > 0 ? $inchan4 : -$inchan4 ) ]
+ set audio_inenable4 [expr $inchan4 > 0 ]
+
set audio_outdev1 $outdev1
set audio_outdev2 $outdev2
set audio_outdev3 $outdev3
set audio_outdev4 $outdev4
- set audio_outchan1 $outchan1
- set audio_outchan2 $outchan2
- set audio_outchan3 $outchan3
- set audio_outchan4 $outchan4
+
+ set audio_outchan1 [expr ( $outchan1 > 0 ? $outchan1 : -$outchan1 ) ]
+ set audio_outenable1 [expr $outchan1 > 0 ]
+ set audio_outchan2 [expr ( $outchan2 > 0 ? $outchan2 : -$outchan2 ) ]
+ set audio_outenable2 [expr $outchan2 > 0 ]
+ set audio_outchan3 [expr ( $outchan3 > 0 ? $outchan3 : -$outchan3 ) ]
+ set audio_outenable3 [expr $outchan3 > 0 ]
+ set audio_outchan4 [expr ( $outchan4 > 0 ? $outchan4 : -$outchan4 ) ]
+ set audio_outenable4 [expr $outchan4 > 0 ]
+
set audio_sr $sr
set audio_advance $advance
set audio_indevlist $indevlist
@@ -2945,24 +3058,26 @@ proc pdtk_audio_dialog {id indevlist indev1 indev2 indev3 indev4 \
frame $id.in1f
pack $id.in1f -side top
- label $id.in1f.l1 -text "input device 1:"
+ checkbutton $id.in1f.x0 -variable audio_inenable1 \
+ -text {input device 1} -anchor e
button $id.in1f.x1 -text [lindex $indevlist $audio_indev1] \
-command [list audio_popup $id $id.in1f.x1 audio_indev1 $indevlist]
label $id.in1f.l2 -text "channels:"
entry $id.in1f.x2 -textvariable audio_inchan1 -width 3
- pack $id.in1f.l1 $id.in1f.x1 $id.in1f.l2 $id.in1f.x2 -side left
+ pack $id.in1f.x0 $id.in1f.x1 $id.in1f.l2 $id.in1f.x2 -side left
# input device 2
if {$longform && $multi > 1 && [llength $indevlist] > 1} {
frame $id.in2f
pack $id.in2f -side top
- label $id.in2f.l1 -text "input device 2:"
+ checkbutton $id.in2f.x0 -variable audio_inenable2 \
+ -text {input device 2} -anchor e
button $id.in2f.x1 -text [lindex $indevlist $audio_indev2] \
-command [list audio_popup $id $id.in2f.x1 audio_indev2 $indevlist]
label $id.in2f.l2 -text "channels:"
entry $id.in2f.x2 -textvariable audio_inchan2 -width 3
- pack $id.in2f.l1 $id.in2f.x1 $id.in2f.l2 $id.in2f.x2 -side left
+ pack $id.in2f.x0 $id.in2f.x1 $id.in2f.l2 $id.in2f.x2 -side left
}
# input device 3
@@ -2970,12 +3085,13 @@ proc pdtk_audio_dialog {id indevlist indev1 indev2 indev3 indev4 \
frame $id.in3f
pack $id.in3f -side top
- label $id.in3f.l1 -text "input device 3:"
+ checkbutton $id.in3f.x0 -variable audio_inenable3 \
+ -text {input device 3} -anchor e
button $id.in3f.x1 -text [lindex $indevlist $audio_indev3] \
-command [list audio_popup $id $id.in3f.x1 audio_indev3 $indevlist]
label $id.in3f.l2 -text "channels:"
entry $id.in3f.x2 -textvariable audio_inchan3 -width 3
- pack $id.in3f.l1 $id.in3f.x1 $id.in3f.l2 $id.in3f.x2 -side left
+ pack $id.in3f.x0 $id.in3f.x1 $id.in3f.l2 $id.in3f.x2 -side left
}
# input device 4
@@ -2983,23 +3099,25 @@ proc pdtk_audio_dialog {id indevlist indev1 indev2 indev3 indev4 \
frame $id.in4f
pack $id.in4f -side top
- label $id.in4f.l1 -text "input device 4:"
+ checkbutton $id.in4f.x0 -variable audio_inenable4 \
+ -text {input device 4} -anchor e
button $id.in4f.x1 -text [lindex $indevlist $audio_indev4] \
-command [list audio_popup $id $id.in4f.x1 audio_indev4 $indevlist]
label $id.in4f.l2 -text "channels:"
entry $id.in4f.x2 -textvariable audio_inchan4 -width 3
- pack $id.in4f.l1 $id.in4f.x1 $id.in4f.l2 $id.in4f.x2 -side left
+ pack $id.in4f.x0 $id.in4f.x1 $id.in4f.l2 $id.in4f.x2 -side left
}
# output device 1
frame $id.out1f
pack $id.out1f -side top
+ checkbutton $id.out1f.x0 -variable audio_outenable1 -text {output device 1} \
+ -anchor e
if {$multi == 0} {
label $id.out1f.l1 \
- -text "(output device same as input device) .............. "
+ -text "(same as input device) .............. "
} else {
- label $id.out1f.l1 -text "output device 1:"
button $id.out1f.x1 -text [lindex $outdevlist $audio_outdev1] \
-command \
[list audio_popup $id $id.out1f.x1 audio_outdev1 $outdevlist]
@@ -3007,48 +3125,54 @@ proc pdtk_audio_dialog {id indevlist indev1 indev2 indev3 indev4 \
label $id.out1f.l2 -text "channels:"
entry $id.out1f.x2 -textvariable audio_outchan1 -width 3
if {$multi == 0} {
- pack $id.out1f.l1 $id.out1f.l2 $id.out1f.x2 -side left
+ pack $id.out1f.x0 $id.out1f.l1 $id.out1f.x2 -side left
} else {
- pack $id.out1f.l1 $id.out1f.x1 $id.out1f.l2 $id.out1f.x2 -side left
+ pack $id.out1f.x0 $id.out1f.x1 $id.out1f.l2 $id.out1f.x2 -side left
}
# output device 2
if {$longform && $multi > 1 && [llength $indevlist] > 1} {
frame $id.out2f
pack $id.out2f -side top
- label $id.out2f.l1 -text "output device 2:"
+
+ checkbutton $id.out2f.x0 -variable audio_outenable2 \
+ -text {output device 2} -anchor e
button $id.out2f.x1 -text [lindex $outdevlist $audio_outdev2] \
-command \
[list audio_popup $id $id.out2f.x1 audio_outdev2 $outdevlist]
label $id.out2f.l2 -text "channels:"
entry $id.out2f.x2 -textvariable audio_outchan2 -width 3
- pack $id.out2f.l1 $id.out2f.x1 $id.out2f.l2 $id.out2f.x2 -side left
+ pack $id.out2f.x0 $id.out2f.x1 $id.out2f.l2 $id.out2f.x2 -side left
}
# output device 3
if {$longform && $multi > 1 && [llength $indevlist] > 2} {
frame $id.out3f
pack $id.out3f -side top
- label $id.out3f.l1 -text "output device 3:"
+
+ checkbutton $id.out3f.x0 -variable audio_outenable3 \
+ -text {output device 3} -anchor e
button $id.out3f.x1 -text [lindex $outdevlist $audio_outdev3] \
-command \
[list audio_popup $id $id.out3f.x1 audio_outdev3 $outdevlist]
label $id.out3f.l2 -text "channels:"
entry $id.out3f.x2 -textvariable audio_outchan3 -width 3
- pack $id.out3f.l1 $id.out3f.x1 $id.out3f.l2 $id.out3f.x2 -side left
+ pack $id.out3f.x0 $id.out3f.x1 $id.out3f.l2 $id.out3f.x2 -side left
}
# output device 4
if {$longform && $multi > 1 && [llength $indevlist] > 3} {
frame $id.out4f
pack $id.out4f -side top
- label $id.out4f.l1 -text "output device 4:"
+
+ checkbutton $id.out4f.x0 -variable audio_outenable4 \
+ -text {output device 4} -anchor e
button $id.out4f.x1 -text [lindex $outdevlist $audio_outdev4] \
-command \
[list audio_popup $id $id.out4f.x1 audio_outdev4 $outdevlist]
label $id.out4f.l2 -text "channels:"
entry $id.out4f.x2 -textvariable audio_outchan4 -width 3
- pack $id.out4f.l1 $id.out4f.x1 $id.out4f.l2 $id.out4f.x2 -side left
+ pack $id.out4f.x0 $id.out4f.x1 $id.out4f.l2 $id.out4f.x2 -side left
}
# if not the "long form" but if "multi" is 2, make a button to
@@ -3064,9 +3188,14 @@ proc pdtk_audio_dialog {id indevlist indev1 indev2 indev3 indev4 \
bind $id.srf.x1 <KeyPress-Return> [concat audio_ok $id]
bind $id.srf.x2 <KeyPress-Return> [concat audio_ok $id]
bind $id.in1f.x2 <KeyPress-Return> [concat audio_ok $id]
+ bind $id.out1f.x2 <KeyPress-Return> [concat audio_ok $id]
$id.srf.x1 select from 0
$id.srf.x1 select adjust end
focus $id.srf.x1
+ pdtk_standardkeybindings $id.srf.x1
+ pdtk_standardkeybindings $id.srf.x2
+ pdtk_standardkeybindings $id.in1f.x2
+ pdtk_standardkeybindings $id.out1f.x2
}
####################### midi dialog ##################3
@@ -3253,13 +3382,16 @@ proc pdtk_midi_dialog {id indevlist indev1 indev2 indev3 indev4 \
############ pdtk_path_dialog -- dialog window for search path #########
proc path_apply {id} {
+ global pd_extrapath pd_verbose
global pd_path0 pd_path1 pd_path2 pd_path3 pd_path4
global pd_path5 pd_path6 pd_path7 pd_path8 pd_path9
- pd [concat pd path-dialog \
- $pd_path0 $pd_path1 $pd_path2 $pd_path3 $pd_path4 \
- $pd_path5 $pd_path6 $pd_path7 $pd_path8 $pd_path9 \
- \;]
+ pd [concat pd path-dialog $pd_extrapath $pd_verbose \
+ [pdtk_enquote $pd_path0] [pdtk_enquote $pd_path1] \
+ [pdtk_enquote $pd_path2] [pdtk_enquote $pd_path3] \
+ [pdtk_enquote $pd_path4] [pdtk_enquote $pd_path5] \
+ [pdtk_enquote $pd_path6] [pdtk_enquote $pd_path7] \
+ [pdtk_enquote $pd_path8] [pdtk_enquote $pd_path9] \;]
}
proc path_cancel {id} {
@@ -3270,12 +3402,14 @@ proc path_ok {id} {
path_apply $id
path_cancel $id
}
-set pd_path0 sdfgh
-proc pdtk_path_dialog {id} {
+proc pdtk_path_dialog {id extrapath verbose} {
+ global pd_extrapath pd_verbose
global pd_path0 pd_path1 pd_path2 pd_path3 pd_path4
global pd_path5 pd_path6 pd_path7 pd_path8 pd_path9
+ set pd_extrapath $extrapath
+ set pd_verbose $verbose
toplevel $id
wm title $id {PD search path for patches and other files}
wm protocol $id WM_DELETE_WINDOW [concat path_cancel $id]
@@ -3292,10 +3426,21 @@ proc pdtk_path_dialog {id} {
pack $id.buttonframe.apply -side left -expand 1
pack $id.buttonframe.ok -side left -expand 1
+ frame $id.extraframe
+ pack $id.extraframe -side bottom -fill x -pady 2m
+ checkbutton $id.extraframe.extra -text {use standard extensions} \
+ -variable pd_extrapath -anchor w
+ checkbutton $id.extraframe.verbose -text {verbose} \
+ -variable pd_verbose -anchor w
+ button $id.extraframe.save -text {Save all settings}\
+ -command "path_apply $id \; pd pd save-preferences \\;"
+ pack $id.extraframe.extra $id.extraframe.verbose $id.extraframe.save \
+ -side left -expand 1
+
for {set x 0} {$x < 10} {incr x} {
- # input device 1
entry $id.f$x -textvariable pd_path$x -width 80
bind $id.f$x <KeyPress-Return> [concat path_ok $id]
+ pdtk_standardkeybindings $id.f$x
pack $id.f$x -side top
}
@@ -3306,3 +3451,83 @@ proc pd_set {var value} {
global $var
set $var $value
}
+
+########## pdtk_startup_dialog -- dialog window for startup options #########
+
+proc startup_apply {id} {
+ global pd_nort pd_flags
+ global pd_startup0 pd_startup1 pd_startup2 pd_startup3 pd_startup4
+ global pd_startup5 pd_startup6 pd_startup7 pd_startup8 pd_startup9
+
+ pd [concat pd startup-dialog $pd_nort [pdtk_enquote $pd_flags] \
+ [pdtk_enquote $pd_startup0] [pdtk_enquote $pd_startup1] \
+ [pdtk_enquote $pd_startup2] [pdtk_enquote $pd_startup3] \
+ [pdtk_enquote $pd_startup4] [pdtk_enquote $pd_startup5] \
+ [pdtk_enquote $pd_startup6] [pdtk_enquote $pd_startup7] \
+ [pdtk_enquote $pd_startup8] [pdtk_enquote $pd_startup9] \;]
+
+}
+
+proc startup_cancel {id} {
+ pd [concat $id cancel \;]
+}
+
+proc startup_ok {id} {
+ startup_apply $id
+ startup_cancel $id
+}
+
+proc pdtk_startup_dialog {id nort flags} {
+ global pd_nort pd_nt pd_flags
+ global pd_startup0 pd_startup1 pd_startup2 pd_startup3 pd_startup4
+ global pd_startup5 pd_startup6 pd_startup7 pd_startup8 pd_startup9
+
+ set pd_nort $nort
+ set pd_flags $flags
+ toplevel $id
+ wm title $id {Pd binaries to load (on next startup)}
+ wm protocol $id WM_DELETE_WINDOW [concat startup_cancel $id]
+
+ frame $id.buttonframe
+ pack $id.buttonframe -side bottom -fill x -pady 2m
+ button $id.buttonframe.cancel -text {Cancel}\
+ -command "startup_cancel $id"
+ button $id.buttonframe.apply -text {Apply}\
+ -command "startup_apply $id"
+ button $id.buttonframe.ok -text {OK}\
+ -command "startup_ok $id"
+ pack $id.buttonframe.cancel -side left -expand 1
+ pack $id.buttonframe.apply -side left -expand 1
+ pack $id.buttonframe.ok -side left -expand 1
+
+ frame $id.flags
+ pack $id.flags -side bottom
+ label $id.flags.entryname -text {startup flags}
+ entry $id.flags.entry -textvariable pd_flags -width 80
+ bind $id.flags.entry <KeyPress-Return> [concat startup_ok $id]
+ pdtk_standardkeybindings $id.flags.entry
+ pack $id.flags.entryname $id.flags.entry -side left
+
+ frame $id.nortframe
+ pack $id.nortframe -side bottom -fill x -pady 2m
+ if {$pd_nt != 1} {
+ checkbutton $id.nortframe.nort -text {defeat real-time scheduling} \
+ -variable pd_nort -anchor w
+ }
+ button $id.nortframe.save -text {Save all settings}\
+ -command "startup_apply $id \; pd pd save-preferences \\;"
+ if {$pd_nt != 1} {
+ pack $id.nortframe.nort $id.nortframe.save -side left -expand 1
+ } else {
+ pack $id.nortframe.save -side left -expand 1
+ }
+
+ for {set x 0} {$x < 10} {incr x} {
+ entry $id.f$x -textvariable pd_startup$x -width 80
+ bind $id.f$x <KeyPress-Return> [concat startup_ok $id]
+ pdtk_standardkeybindings $id.f$x
+ pack $id.f$x -side top
+ }
+
+ focus $id.f0
+}
diff --git a/pd/src/u_pdreceive.c b/pd/src/u_pdreceive.c
index ad71f506..1feac305 100644
--- a/pd/src/u_pdreceive.c
+++ b/pd/src/u_pdreceive.c
@@ -11,15 +11,16 @@ standard output. */
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
-#ifdef UNIX
-#include <sys/time.h>
-#include <unistd.h>
+#ifdef MSW
+#include <winsock.h>
+#else
#include <sys/socket.h>
#include <netinet/in.h>
+#include <netinet/tcp.h>
#include <netdb.h>
+#include <stdio.h>
+#include <unistd.h>
#define SOCKET_ERROR -1
-#else
-#include <winsock.h>
#endif
typedef struct _fdpoll
@@ -52,14 +53,14 @@ int main(int argc, char **argv)
WSADATA nobby;
#endif
if (argc < 2 || sscanf(argv[1], "%d", &portno) < 1 || portno <= 0)
- goto usage;
+ goto usage;
if (argc >= 3)
{
- if (!strcmp(argv[2], "tcp"))
- protocol = SOCK_STREAM;
- else if (!strcmp(argv[2], "udp"))
- protocol = SOCK_DGRAM;
- else goto usage;
+ if (!strcmp(argv[2], "tcp"))
+ protocol = SOCK_STREAM;
+ else if (!strcmp(argv[2], "udp"))
+ protocol = SOCK_DGRAM;
+ else goto usage;
}
else protocol = SOCK_STREAM;
#ifdef MSW
@@ -68,42 +69,42 @@ int main(int argc, char **argv)
sockfd = socket(AF_INET, protocol, 0);
if (sockfd < 0)
{
- sockerror("socket()");
- exit(1);
+ sockerror("socket()");
+ exit(1);
}
maxfd = sockfd + 1;
server.sin_family = AF_INET;
server.sin_addr.s_addr = INADDR_ANY;
#ifdef IRIX
- /* this seems to work only in IRIX but is unnecessary in
- Linux. Not sure what MSW needs in place of this. */
+ /* this seems to work only in IRIX but is unnecessary in
+ Linux. Not sure what MSW needs in place of this. */
if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, 0, 0) < 0)
- post("setsockopt failed\n");
+ fprintf(stderr, "setsockopt failed\n");
#endif
- /* assign client port number */
+ /* assign client port number */
server.sin_port = htons((unsigned short)portno);
- /* name the socket */
+ /* name the socket */
if (bind(sockfd, (struct sockaddr *)&server, sizeof(server)) < 0)
{
- sockerror("bind");
- x_closesocket(sockfd);
- return (0);
+ sockerror("bind");
+ x_closesocket(sockfd);
+ return (0);
}
if (protocol == SOCK_STREAM)
{
- if (listen(sockfd, 5) < 0)
- {
- sockerror("listen");
- x_closesocket(sockfd);
- exit(1);
- }
+ if (listen(sockfd, 5) < 0)
+ {
+ sockerror("listen");
+ x_closesocket(sockfd);
+ exit(1);
+ }
}
- /* now loop forever selecting on sockets */
+ /* now loop forever selecting on sockets */
while (1)
- dopoll();
+ dopoll();
usage:
fprintf(stderr, "usage: pdreceive <portnumber> [udp|tcp]\n");
@@ -116,7 +117,7 @@ static void addport(int fd)
int nfd = nfdpoll;
t_fdpoll *fp;
fdpoll = (t_fdpoll *)realloc(fdpoll,
- (nfdpoll+1) * sizeof(t_fdpoll));
+ (nfdpoll+1) * sizeof(t_fdpoll));
fp = fdpoll + nfdpoll;
fp->fdp_fd = fd;
nfdpoll++;
@@ -124,8 +125,8 @@ static void addport(int fd)
fp->fdp_inhead = fp->fdp_intail = 0;
if (!(fp->fdp_inbuf = malloc(BUFSIZE)))
{
- fprintf(stderr, "out of memory");
- exit(1);
+ fprintf(stderr, "out of memory");
+ exit(1);
}
printf("number_connected %d;\n", nfdpoll);
}
@@ -137,21 +138,21 @@ static void rmport(t_fdpoll *x)
t_fdpoll *fp;
for (i = nfdpoll, fp = fdpoll; i--; fp++)
{
- if (fp == x)
- {
- x_closesocket(fp->fdp_fd);
- free(fp->fdp_inbuf);
- while (i--)
- {
- fp[0] = fp[1];
- fp++;
- }
- fdpoll = (t_fdpoll *)realloc(fdpoll,
- (nfdpoll-1) * sizeof(t_fdpoll));
- nfdpoll--;
- printf("number_connected %d;\n", nfdpoll);
- return;
- }
+ if (fp == x)
+ {
+ x_closesocket(fp->fdp_fd);
+ free(fp->fdp_inbuf);
+ while (i--)
+ {
+ fp[0] = fp[1];
+ fp++;
+ }
+ fdpoll = (t_fdpoll *)realloc(fdpoll,
+ (nfdpoll-1) * sizeof(t_fdpoll));
+ nfdpoll--;
+ printf("number_connected %d;\n", nfdpoll);
+ return;
+ }
}
fprintf(stderr, "warning: item removed from poll list but not found");
}
@@ -160,7 +161,7 @@ static void doconnect(void)
{
int fd = accept(sockfd, 0, 0);
if (fd < 0)
- perror("accept");
+ perror("accept");
else addport(fd);
}
@@ -170,22 +171,22 @@ static void udpread(void)
int ret = recv(sockfd, buf, BUFSIZE, 0);
if (ret < 0)
{
- sockerror("recv (udp)");
- x_closesocket(sockfd);
- exit(1);
+ sockerror("recv (udp)");
+ x_closesocket(sockfd);
+ exit(1);
}
else if (ret > 0)
{
-#ifdef UNIX
- if (write(1, buf, ret) < ret)
- {
- perror("write");
- exit(1);
- }
+#ifdef MSW
+ int j;
+ for (j = 0; j < ret; j++)
+ putchar(buf[j]);
#else
- int j;
- for (j = 0; j < ret; j++)
- putchar(buf[j]);
+ if (write(1, buf, ret) < ret)
+ {
+ perror("write");
+ exit(1);
+ }
#endif
}
}
@@ -198,30 +199,30 @@ static int tcpmakeoutput(t_fdpoll *x)
int intail = x->fdp_intail;
char *inbuf = x->fdp_inbuf;
if (intail == inhead)
- return (0);
+ return (0);
for (indx = intail; indx != inhead; indx = (indx+1)&(BUFSIZE-1))
{
- /* search for a semicolon. */
- char c = *bp++ = inbuf[indx];
- if (c == ';')
- {
- intail = (indx+1)&(BUFSIZE-1);
- if (inbuf[intail] == '\n')
- intail = (intail+1)&(BUFSIZE-1);
- *bp++ = '\n';
-#ifdef UNIX
- write(1, messbuf, bp - messbuf);
+ /* search for a semicolon. */
+ char c = *bp++ = inbuf[indx];
+ if (c == ';')
+ {
+ intail = (indx+1)&(BUFSIZE-1);
+ if (inbuf[intail] == '\n')
+ intail = (intail+1)&(BUFSIZE-1);
+ *bp++ = '\n';
+#ifdef MSW
+ {
+ int j;
+ for (j = 0; j < bp - messbuf; j++)
+ putchar(messbuf[j]);
+ }
#else
- {
- int j;
- for (j = 0; j < bp - messbuf; j++)
- putchar(messbuf[j]);
- }
+ write(1, messbuf, bp - messbuf);
#endif
- x->fdp_inhead = inhead;
- x->fdp_intail = intail;
- return (1);
- }
+ x->fdp_inhead = inhead;
+ x->fdp_intail = intail;
+ return (1);
+ }
}
return (0);
}
@@ -229,35 +230,35 @@ static int tcpmakeoutput(t_fdpoll *x)
static void tcpread(t_fdpoll *x)
{
int readto =
- (x->fdp_inhead >= x->fdp_intail ? BUFSIZE : x->fdp_intail-1);
+ (x->fdp_inhead >= x->fdp_intail ? BUFSIZE : x->fdp_intail-1);
int ret;
- /* the input buffer might be full. If so, drop the whole thing */
+ /* the input buffer might be full. If so, drop the whole thing */
if (readto == x->fdp_inhead)
{
- fprintf(stderr, "pd: dropped message from gui\n");
- x->fdp_inhead = x->fdp_intail = 0;
- readto = BUFSIZE;
+ fprintf(stderr, "pd: dropped message from gui\n");
+ x->fdp_inhead = x->fdp_intail = 0;
+ readto = BUFSIZE;
}
else
{
- ret = recv(x->fdp_fd, x->fdp_inbuf + x->fdp_inhead,
- readto - x->fdp_inhead, 0);
- if (ret < 0)
- {
- sockerror("recv (tcp)");
- rmport(x);
- }
- else if (ret == 0)
- rmport(x);
- else
- {
- x->fdp_inhead += ret;
- if (x->fdp_inhead >= BUFSIZE)
- x->fdp_inhead = 0;
- while (tcpmakeoutput(x))
- ;
- }
+ ret = recv(x->fdp_fd, x->fdp_inbuf + x->fdp_inhead,
+ readto - x->fdp_inhead, 0);
+ if (ret < 0)
+ {
+ sockerror("recv (tcp)");
+ rmport(x);
+ }
+ else if (ret == 0)
+ rmport(x);
+ else
+ {
+ x->fdp_inhead += ret;
+ if (x->fdp_inhead >= BUFSIZE)
+ x->fdp_inhead = 0;
+ while (tcpmakeoutput(x))
+ ;
+ }
}
}
@@ -273,26 +274,26 @@ static void dopoll(void)
FD_SET(sockfd, &readset);
if (protocol == SOCK_STREAM)
{
- for (fp = fdpoll, i = nfdpoll; i--; fp++)
- FD_SET(fp->fdp_fd, &readset);
+ for (fp = fdpoll, i = nfdpoll; i--; fp++)
+ FD_SET(fp->fdp_fd, &readset);
}
if (select(maxfd+1, &readset, &writeset, &exceptset, 0) < 0)
{
- perror("select");
- exit(1);
+ perror("select");
+ exit(1);
}
if (protocol == SOCK_STREAM)
{
- for (i = 0; i < nfdpoll; i++)
- if (FD_ISSET(fdpoll[i].fdp_fd, &readset))
- tcpread(&fdpoll[i]);
- if (FD_ISSET(sockfd, &readset))
- doconnect();
+ for (i = 0; i < nfdpoll; i++)
+ if (FD_ISSET(fdpoll[i].fdp_fd, &readset))
+ tcpread(&fdpoll[i]);
+ if (FD_ISSET(sockfd, &readset))
+ doconnect();
}
else
{
- if (FD_ISSET(sockfd, &readset))
- udpread();
+ if (FD_ISSET(sockfd, &readset))
+ udpread();
}
}
@@ -304,11 +305,10 @@ static void sockerror(char *s)
if (err == 10054) return;
else if (err == 10044)
{
- fprintf(stderr,
- "Warning: you might not have TCP/IP \"networking\" turned on\n");
+ fprintf(stderr,
+ "Warning: you might not have TCP/IP \"networking\" turned on\n");
}
-#endif
-#ifdef UNIX
+#else
int err = errno;
#endif
fprintf(stderr, "%s: %s (%d)\n", s, strerror(err), err);
@@ -316,10 +316,9 @@ static void sockerror(char *s)
static void x_closesocket(int fd)
{
-#ifdef UNIX
- close(fd);
-#endif
#ifdef MSW
closesocket(fd);
+#else
+ close(fd);
#endif
}
diff --git a/pd/src/u_pdsend.c b/pd/src/u_pdsend.c
index de9488b0..7b464cad 100644
--- a/pd/src/u_pdsend.c
+++ b/pd/src/u_pdsend.c
@@ -10,14 +10,16 @@ from its standard input to Pd via the netsend/netreceive ("FUDI") protocol. */
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
-#ifdef UNIX
-#include <unistd.h>
+#ifdef MSW
+#include <winsock.h>
+#else
#include <sys/socket.h>
#include <netinet/in.h>
+#include <netinet/tcp.h>
#include <netdb.h>
+#include <stdio.h>
+#include <unistd.h>
#define SOCKET_ERROR -1
-#else
-#include <winsock.h>
#endif
void sockerror(char *s);
@@ -36,17 +38,17 @@ int main(int argc, char **argv)
WSADATA nobby;
#endif
if (argc < 2 || sscanf(argv[1], "%d", &portno) < 1 || portno <= 0)
- goto usage;
+ goto usage;
if (argc >= 3)
- hostname = argv[2];
+ hostname = argv[2];
else hostname = "127.0.0.1";
if (argc >= 4)
{
- if (!strcmp(argv[3], "tcp"))
- protocol = SOCK_STREAM;
- else if (!strcmp(argv[3], "udp"))
- protocol = SOCK_DGRAM;
- else goto usage;
+ if (!strcmp(argv[3], "tcp"))
+ protocol = SOCK_STREAM;
+ else if (!strcmp(argv[3], "udp"))
+ protocol = SOCK_DGRAM;
+ else goto usage;
}
else protocol = SOCK_STREAM;
#ifdef MSW
@@ -56,37 +58,37 @@ int main(int argc, char **argv)
sockfd = socket(AF_INET, protocol, 0);
if (sockfd < 0)
{
- sockerror("socket()");
- exit(1);
+ sockerror("socket()");
+ exit(1);
}
- /* connect socket using hostname provided in command line */
+ /* connect socket using hostname provided in command line */
server.sin_family = AF_INET;
hp = gethostbyname(hostname);
if (hp == 0)
{
- fprintf(stderr, "%s: unknown host\n", hostname);
- x_closesocket(sockfd);
- exit(1);
+ fprintf(stderr, "%s: unknown host\n", hostname);
+ x_closesocket(sockfd);
+ exit(1);
}
memcpy((char *)&server.sin_addr, (char *)hp->h_addr, hp->h_length);
- /* assign client port number */
+ /* assign client port number */
server.sin_port = htons((unsigned short)portno);
-#if 0 /* try this again for 4.0; this crashed my RH 6.2 machine!) */
+#if 0 /* try this again for 4.0; this crashed my RH 6.2 machine!) */
- /* try to connect. */
+ /* try to connect. */
for (nretry = 0; nretry < (protocol == SOCK_STREAM ? 10 : 1); nretry++)
{
- if (nretry > 0)
- {
- sleep (nretry < 5 ? 1 : 5);
- fprintf(stderr, "retrying...");
- }
- if (connect(sockfd, (struct sockaddr *) &server, sizeof (server)) >= 0)
- goto connected;
- sockerror("connect");
+ if (nretry > 0)
+ {
+ sleep (nretry < 5 ? 1 : 5);
+ fprintf(stderr, "retrying...");
+ }
+ if (connect(sockfd, (struct sockaddr *) &server, sizeof (server)) >= 0)
+ goto connected;
+ sockerror("connect");
}
x_closesocket(sockfd);
exit(1);
@@ -95,33 +97,33 @@ connected: ;
/* try to connect. */
if (connect(sockfd, (struct sockaddr *) &server, sizeof (server)) < 0)
{
- sockerror("connect");
- x_closesocket(sockfd);
- exit(1);
+ sockerror("connect");
+ x_closesocket(sockfd);
+ exit(1);
}
#endif
- /* now loop reading stdin and sending it to socket */
+ /* now loop reading stdin and sending it to socket */
while (1)
{
- char buf[BUFSIZE], *bp, nsent, nsend;
- if (!fgets(buf, BUFSIZE, stdin))
- break;
- nsend = strlen(buf);
- for (bp = buf, nsent = 0; nsent < nsend;)
- {
- int res = send(sockfd, buf, nsend-nsent, 0);
- if (res < 0)
- {
- sockerror("send");
- goto done;
- }
- nsent += res;
- bp += res;
- }
+ char buf[BUFSIZE], *bp, nsent, nsend;
+ if (!fgets(buf, BUFSIZE, stdin))
+ break;
+ nsend = strlen(buf);
+ for (bp = buf, nsent = 0; nsent < nsend;)
+ {
+ int res = send(sockfd, buf, nsend-nsent, 0);
+ if (res < 0)
+ {
+ sockerror("send");
+ goto done;
+ }
+ nsent += res;
+ bp += res;
+ }
}
done:
if (ferror(stdin))
- perror("stdin");
+ perror("stdin");
exit (0);
usage:
fprintf(stderr, "usage: pdsend <portnumber> [host] [udp|tcp]\n");
@@ -136,11 +138,10 @@ void sockerror(char *s)
if (err == 10054) return;
else if (err == 10044)
{
- fprintf(stderr,
- "Warning: you might not have TCP/IP \"networking\" turned on\n");
+ fprintf(stderr,
+ "Warning: you might not have TCP/IP \"networking\" turned on\n");
}
-#endif
-#ifdef UNIX
+#else
int err = errno;
#endif
fprintf(stderr, "%s: %s (%d)\n", s, strerror(err), err);
@@ -148,10 +149,9 @@ void sockerror(char *s)
void x_closesocket(int fd)
{
-#ifdef UNIX
- close(fd);
-#endif
#ifdef MSW
closesocket(fd);
+#else
+ close(fd);
#endif
}
diff --git a/pd/src/x_acoustics.c b/pd/src/x_acoustics.c
index ee7250df..eca2d32b 100644
--- a/pd/src/x_acoustics.c
+++ b/pd/src/x_acoustics.c
@@ -26,8 +26,8 @@ float powtodb(float f)
if (f <= 0) return (0);
else
{
- float val = 100 + 10./LOGTEN * log(f);
- return (val < 0 ? 0 : val);
+ float val = 100 + 10./LOGTEN * log(f);
+ return (val < 0 ? 0 : val);
}
}
@@ -36,31 +36,31 @@ float rmstodb(float f)
if (f <= 0) return (0);
else
{
- float val = 100 + 20./LOGTEN * log(f);
- return (val < 0 ? 0 : val);
+ float val = 100 + 20./LOGTEN * log(f);
+ return (val < 0 ? 0 : val);
}
}
float dbtopow(float f)
{
if (f <= 0)
- return(0);
+ return(0);
else
{
- if (f > 870)
- f = 870;
- return (exp((LOGTEN * 0.1) * (f-100.)));
+ if (f > 870)
+ f = 870;
+ return (exp((LOGTEN * 0.1) * (f-100.)));
}
}
float dbtorms(float f)
{
if (f <= 0)
- return(0);
+ return(0);
else
{
- if (f > 485)
- f = 485;
+ if (f > 485)
+ f = 485;
}
return (exp((LOGTEN * 0.05) * (f-100.)));
}
@@ -161,32 +161,32 @@ void x_acoustics_setup(void)
{
t_symbol *s = gensym("acoustics.pd");
mtof_class = class_new(gensym("mtof"), mtof_new, 0,
- sizeof(t_object), 0, 0);
+ sizeof(t_object), 0, 0);
class_addfloat(mtof_class, (t_method)mtof_float);
class_sethelpsymbol(mtof_class, s);
ftom_class = class_new(gensym("ftom"), ftom_new, 0,
- sizeof(t_object), 0, 0);
+ sizeof(t_object), 0, 0);
class_addfloat(ftom_class, (t_method)ftom_float);
class_sethelpsymbol(ftom_class, s);
powtodb_class = class_new(gensym("powtodb"), powtodb_new, 0,
- sizeof(t_object), 0, 0);
+ sizeof(t_object), 0, 0);
class_addfloat(powtodb_class, (t_method)powtodb_float);
class_sethelpsymbol(powtodb_class, s);
rmstodb_class = class_new(gensym("rmstodb"), rmstodb_new, 0,
- sizeof(t_object), 0, 0);
+ sizeof(t_object), 0, 0);
class_addfloat(rmstodb_class, (t_method)rmstodb_float);
class_sethelpsymbol(rmstodb_class, s);
dbtopow_class = class_new(gensym("dbtopow"), dbtopow_new, 0,
- sizeof(t_object), 0, 0);
+ sizeof(t_object), 0, 0);
class_addfloat(dbtopow_class, (t_method)dbtopow_float);
class_sethelpsymbol(dbtopow_class, s);
dbtorms_class = class_new(gensym("dbtorms"), dbtorms_new, 0,
- sizeof(t_object), 0, 0);
+ sizeof(t_object), 0, 0);
class_addfloat(dbtorms_class, (t_method)dbtorms_float);
class_sethelpsymbol(dbtorms_class, s);
}
diff --git a/pd/src/x_arithmetic.c b/pd/src/x_arithmetic.c
index b7a94a2d..095e2c7d 100644
--- a/pd/src/x_arithmetic.c
+++ b/pd/src/x_arithmetic.c
@@ -111,14 +111,14 @@ static void *binop1_div_new(t_floatarg f)
static void binop1_div_bang(t_binop *x)
{
outlet_float(x->x_obj.ob_outlet,
- (x->x_f2 != 0 ? x->x_f1 / x->x_f2 : 0));
+ (x->x_f2 != 0 ? x->x_f1 / x->x_f2 : 0));
}
static void binop1_div_float(t_binop *x, t_float f)
{
x->x_f1 = f;
outlet_float(x->x_obj.ob_outlet,
- (x->x_f2 != 0 ? x->x_f1 / x->x_f2 : 0));
+ (x->x_f2 != 0 ? x->x_f1 / x->x_f2 : 0));
}
/* ------------------------ pow -------------------------------- */
@@ -133,14 +133,14 @@ static void *binop1_pow_new(t_floatarg f)
static void binop1_pow_bang(t_binop *x)
{
outlet_float(x->x_obj.ob_outlet,
- (x->x_f1 > 0 ? powf(x->x_f1, x->x_f2) : 0));
+ (x->x_f1 > 0 ? powf(x->x_f1, x->x_f2) : 0));
}
static void binop1_pow_float(t_binop *x, t_float f)
{
x->x_f1 = f;
outlet_float(x->x_obj.ob_outlet,
- (x->x_f1 > 0 ? powf(x->x_f1, x->x_f2) : 0));
+ (x->x_f1 > 0 ? powf(x->x_f1, x->x_f2) : 0));
}
/* ------------------------ max -------------------------------- */
@@ -155,14 +155,14 @@ static void *binop1_max_new(t_floatarg f)
static void binop1_max_bang(t_binop *x)
{
outlet_float(x->x_obj.ob_outlet,
- (x->x_f1 > x->x_f2 ? x->x_f1 : x->x_f2));
+ (x->x_f1 > x->x_f2 ? x->x_f1 : x->x_f2));
}
static void binop1_max_float(t_binop *x, t_float f)
{
x->x_f1 = f;
outlet_float(x->x_obj.ob_outlet,
- (x->x_f1 > x->x_f2 ? x->x_f1 : x->x_f2));
+ (x->x_f1 > x->x_f2 ? x->x_f1 : x->x_f2));
}
/* ------------------------ min -------------------------------- */
@@ -177,14 +177,14 @@ static void *binop1_min_new(t_floatarg f)
static void binop1_min_bang(t_binop *x)
{
outlet_float(x->x_obj.ob_outlet,
- (x->x_f1 < x->x_f2 ? x->x_f1 : x->x_f2));
+ (x->x_f1 < x->x_f2 ? x->x_f1 : x->x_f2));
}
static void binop1_min_float(t_binop *x, t_float f)
{
x->x_f1 = f;
outlet_float(x->x_obj.ob_outlet,
- (x->x_f1 < x->x_f2 ? x->x_f1 : x->x_f2));
+ (x->x_f1 < x->x_f2 ? x->x_f1 : x->x_f2));
}
/* ------------------ binop2: ==, !=, >, <, >=, <=. -------------------- */
@@ -512,7 +512,7 @@ static void binop3_div_float(t_binop *x, t_float f)
/* -------------------- mathematical functions ------------------ */
-static t_class *sin_class; /* ----------- sin --------------- */
+static t_class *sin_class; /* ----------- sin --------------- */
static void *sin_new(void)
{
@@ -526,7 +526,7 @@ static void sin_float(t_object *x, t_float f)
outlet_float(x->ob_outlet, sinf(f));
}
-static t_class *cos_class; /* ----------- cos --------------- */
+static t_class *cos_class; /* ----------- cos --------------- */
static void *cos_new(void)
{
@@ -540,7 +540,7 @@ static void cos_float(t_object *x, t_float f)
outlet_float(x->ob_outlet, cosf(f));
}
-static t_class *tan_class; /* ----------- tan --------------- */
+static t_class *tan_class; /* ----------- tan --------------- */
static void *tan_new(void)
{
@@ -556,7 +556,7 @@ static void tan_float(t_object *x, t_float f)
outlet_float(x->ob_outlet, t);
}
-static t_class *atan_class; /* ----------- atan --------------- */
+static t_class *atan_class; /* ----------- atan --------------- */
static void *atan_new(void)
{
@@ -570,29 +570,33 @@ static void atan_float(t_object *x, t_float f)
outlet_float(x->ob_outlet, atanf(f));
}
-static t_class *atan2_class; /* ----------- atan2 --------------- */
+static t_class *atan2_class; /* ----------- atan2 --------------- */
typedef struct _atan2
{
t_object x_ob;
- float x_y;
+ float x_f;
} t_atan2;
static void *atan2_new(void)
{
t_atan2 *x = (t_atan2 *)pd_new(atan2_class);
- floatinlet_new(&x->x_ob, &x->x_y);
+ static int warned;
+ if (!warned)
+ post("warning: atan2 inlets switched from Pd 0.37 to 0.38"), warned=1;
+ floatinlet_new(&x->x_ob, &x->x_f);
+ x->x_f = 0;
outlet_new(&x->x_ob, &s_float);
return (x);
}
static void atan2_float(t_atan2 *x, t_float f)
{
- float r = (f == 0 && x->x_y == 0 ? 0 : atan2f(x->x_y, f));
+ float r = (f == 0 && x->x_f == 0 ? 0 : atan2f(f, x->x_f));
outlet_float(x->x_ob.ob_outlet, r);
}
-static t_class *sqrt_class; /* ----------- sqrt --------------- */
+static t_class *sqrt_class; /* ----------- sqrt --------------- */
static void *sqrt_new(void)
{
@@ -607,7 +611,7 @@ static void sqrt_float(t_object *x, t_float f)
outlet_float(x->ob_outlet, r);
}
-static t_class *log_class; /* ----------- log --------------- */
+static t_class *log_class; /* ----------- log --------------- */
static void *log_new(void)
{
@@ -623,7 +627,7 @@ static void log_float(t_object *x, t_float f)
}
-static t_class *exp_class; /* ----------- exp --------------- */
+static t_class *exp_class; /* ----------- exp --------------- */
static void *exp_new(void)
{
@@ -644,7 +648,7 @@ static void exp_float(t_object *x, t_float f)
outlet_float(x->ob_outlet, g);
}
-static t_class *abs_class; /* ----------- abs --------------- */
+static t_class *abs_class; /* ----------- abs --------------- */
static void *abs_new(void)
{
@@ -683,13 +687,13 @@ static void *clip_new(t_floatarg f1, t_floatarg f2)
static void clip_float(t_clip *x, t_float f)
{
outlet_float(x->x_ob.ob_outlet, (f < x->x_f1 ? x->x_f1 : (
- f > x->x_f2 ? x->x_f2 : f)));
+ f > x->x_f2 ? x->x_f2 : f)));
}
static void clip_setup(void)
{
clip_class = class_new(gensym("clip"), (t_newmethod)clip_new, 0,
- sizeof(t_clip), 0, A_DEFFLOAT, A_DEFFLOAT, 0);
+ sizeof(t_clip), 0, A_DEFFLOAT, A_DEFFLOAT, 0);
class_addfloat(clip_class, clip_float);
}
@@ -700,191 +704,191 @@ void x_arithmetic_setup(void)
t_symbol *math_sym = gensym("math");
binop1_plus_class = class_new(gensym("+"), (t_newmethod)binop1_plus_new, 0,
- sizeof(t_binop), 0, A_DEFFLOAT, 0);
+ sizeof(t_binop), 0, A_DEFFLOAT, 0);
class_addbang(binop1_plus_class, binop1_plus_bang);
class_addfloat(binop1_plus_class, (t_method)binop1_plus_float);
class_sethelpsymbol(binop1_plus_class, binop1_sym);
binop1_minus_class = class_new(gensym("-"),
- (t_newmethod)binop1_minus_new, 0,
- sizeof(t_binop), 0, A_DEFFLOAT, 0);
+ (t_newmethod)binop1_minus_new, 0,
+ sizeof(t_binop), 0, A_DEFFLOAT, 0);
class_addbang(binop1_minus_class, binop1_minus_bang);
class_addfloat(binop1_minus_class, (t_method)binop1_minus_float);
class_sethelpsymbol(binop1_minus_class, binop1_sym);
binop1_times_class = class_new(gensym("*"),
- (t_newmethod)binop1_times_new, 0,
- sizeof(t_binop), 0, A_DEFFLOAT, 0);
+ (t_newmethod)binop1_times_new, 0,
+ sizeof(t_binop), 0, A_DEFFLOAT, 0);
class_addbang(binop1_times_class, binop1_times_bang);
class_addfloat(binop1_times_class, (t_method)binop1_times_float);
class_sethelpsymbol(binop1_times_class, binop1_sym);
binop1_div_class = class_new(gensym("/"),
- (t_newmethod)binop1_div_new, 0,
- sizeof(t_binop), 0, A_DEFFLOAT, 0);
+ (t_newmethod)binop1_div_new, 0,
+ sizeof(t_binop), 0, A_DEFFLOAT, 0);
class_addbang(binop1_div_class, binop1_div_bang);
class_addfloat(binop1_div_class, (t_method)binop1_div_float);
class_sethelpsymbol(binop1_div_class, binop1_sym);
binop1_pow_class = class_new(gensym("pow"),
- (t_newmethod)binop1_pow_new, 0,
- sizeof(t_binop), 0, A_DEFFLOAT, 0);
+ (t_newmethod)binop1_pow_new, 0,
+ sizeof(t_binop), 0, A_DEFFLOAT, 0);
class_addbang(binop1_pow_class, binop1_pow_bang);
class_addfloat(binop1_pow_class, (t_method)binop1_pow_float);
class_sethelpsymbol(binop1_pow_class, binop1_sym);
binop1_max_class = class_new(gensym("max"),
- (t_newmethod)binop1_max_new, 0,
- sizeof(t_binop), 0, A_DEFFLOAT, 0);
+ (t_newmethod)binop1_max_new, 0,
+ sizeof(t_binop), 0, A_DEFFLOAT, 0);
class_addbang(binop1_max_class, binop1_max_bang);
class_addfloat(binop1_max_class, (t_method)binop1_max_float);
class_sethelpsymbol(binop1_max_class, binop1_sym);
binop1_min_class = class_new(gensym("min"),
- (t_newmethod)binop1_min_new, 0,
- sizeof(t_binop), 0, A_DEFFLOAT, 0);
+ (t_newmethod)binop1_min_new, 0,
+ sizeof(t_binop), 0, A_DEFFLOAT, 0);
class_addbang(binop1_min_class, binop1_min_bang);
class_addfloat(binop1_min_class, (t_method)binop1_min_float);
class_sethelpsymbol(binop1_min_class, binop1_sym);
- /* ------------------ binop2 ----------------------- */
+ /* ------------------ binop2 ----------------------- */
binop2_ee_class = class_new(gensym("=="), (t_newmethod)binop2_ee_new, 0,
- sizeof(t_binop), 0, A_DEFFLOAT, 0);
+ sizeof(t_binop), 0, A_DEFFLOAT, 0);
class_addbang(binop2_ee_class, binop2_ee_bang);
class_addfloat(binop2_ee_class, (t_method)binop2_ee_float);
class_sethelpsymbol(binop2_ee_class, binop23_sym);
binop2_ne_class = class_new(gensym("!="), (t_newmethod)binop2_ne_new, 0,
- sizeof(t_binop), 0, A_DEFFLOAT, 0);
+ sizeof(t_binop), 0, A_DEFFLOAT, 0);
class_addbang(binop2_ne_class, binop2_ne_bang);
class_addfloat(binop2_ne_class, (t_method)binop2_ne_float);
class_sethelpsymbol(binop2_ne_class, binop23_sym);
binop2_gt_class = class_new(gensym(">"), (t_newmethod)binop2_gt_new, 0,
- sizeof(t_binop), 0, A_DEFFLOAT, 0);
+ sizeof(t_binop), 0, A_DEFFLOAT, 0);
class_addbang(binop2_gt_class, binop2_gt_bang);
class_addfloat(binop2_gt_class, (t_method)binop2_gt_float);
class_sethelpsymbol(binop2_gt_class, binop23_sym);
binop2_lt_class = class_new(gensym("<"), (t_newmethod)binop2_lt_new, 0,
- sizeof(t_binop), 0, A_DEFFLOAT, 0);
+ sizeof(t_binop), 0, A_DEFFLOAT, 0);
class_addbang(binop2_lt_class, binop2_lt_bang);
class_addfloat(binop2_lt_class, (t_method)binop2_lt_float);
class_sethelpsymbol(binop2_lt_class, binop23_sym);
binop2_ge_class = class_new(gensym(">="), (t_newmethod)binop2_ge_new, 0,
- sizeof(t_binop), 0, A_DEFFLOAT, 0);
+ sizeof(t_binop), 0, A_DEFFLOAT, 0);
class_addbang(binop2_ge_class, binop2_ge_bang);
class_addfloat(binop2_ge_class, (t_method)binop2_ge_float);
class_sethelpsymbol(binop2_ge_class, binop23_sym);
binop2_le_class = class_new(gensym("<="), (t_newmethod)binop2_le_new, 0,
- sizeof(t_binop), 0, A_DEFFLOAT, 0);
+ sizeof(t_binop), 0, A_DEFFLOAT, 0);
class_addbang(binop2_le_class, binop2_le_bang);
class_addfloat(binop2_le_class, (t_method)binop2_le_float);
class_sethelpsymbol(binop2_le_class, binop23_sym);
- /* ------------------ binop3 ----------------------- */
+ /* ------------------ binop3 ----------------------- */
binop3_ba_class = class_new(gensym("&"), (t_newmethod)binop3_ba_new, 0,
- sizeof(t_binop), 0, A_DEFFLOAT, 0);
+ sizeof(t_binop), 0, A_DEFFLOAT, 0);
class_addbang(binop3_ba_class, binop2_ba_bang);
class_addfloat(binop3_ba_class, (t_method)binop2_ba_float);
class_sethelpsymbol(binop3_ba_class, binop23_sym);
binop3_la_class = class_new(gensym("&&"), (t_newmethod)binop3_la_new, 0,
- sizeof(t_binop), 0, A_DEFFLOAT, 0);
+ sizeof(t_binop), 0, A_DEFFLOAT, 0);
class_addbang(binop3_la_class, binop2_la_bang);
class_addfloat(binop3_la_class, (t_method)binop2_la_float);
class_sethelpsymbol(binop3_la_class, binop23_sym);
binop3_bo_class = class_new(gensym("|"), (t_newmethod)binop3_bo_new, 0,
- sizeof(t_binop), 0, A_DEFFLOAT, 0);
+ sizeof(t_binop), 0, A_DEFFLOAT, 0);
class_addbang(binop3_bo_class, binop2_bo_bang);
class_addfloat(binop3_bo_class, (t_method)binop2_bo_float);
class_sethelpsymbol(binop3_bo_class, binop23_sym);
binop3_lo_class = class_new(gensym("||"), (t_newmethod)binop3_lo_new, 0,
- sizeof(t_binop), 0, A_DEFFLOAT, 0);
+ sizeof(t_binop), 0, A_DEFFLOAT, 0);
class_addbang(binop3_lo_class, binop2_lo_bang);
class_addfloat(binop3_lo_class, (t_method)binop2_lo_float);
class_sethelpsymbol(binop3_lo_class, binop23_sym);
binop3_ls_class = class_new(gensym("<<"), (t_newmethod)binop3_ls_new, 0,
- sizeof(t_binop), 0, A_DEFFLOAT, 0);
+ sizeof(t_binop), 0, A_DEFFLOAT, 0);
class_addbang(binop3_ls_class, binop2_ls_bang);
class_addfloat(binop3_ls_class, (t_method)binop2_ls_float);
class_sethelpsymbol(binop3_ls_class, binop23_sym);
binop3_rs_class = class_new(gensym(">>"), (t_newmethod)binop3_rs_new, 0,
- sizeof(t_binop), 0, A_DEFFLOAT, 0);
+ sizeof(t_binop), 0, A_DEFFLOAT, 0);
class_addbang(binop3_rs_class, binop2_rs_bang);
class_addfloat(binop3_rs_class, (t_method)binop2_rs_float);
class_sethelpsymbol(binop3_rs_class, binop23_sym);
binop3_pc_class = class_new(gensym("%"), (t_newmethod)binop3_pc_new, 0,
- sizeof(t_binop), 0, A_DEFFLOAT, 0);
+ sizeof(t_binop), 0, A_DEFFLOAT, 0);
class_addbang(binop3_pc_class, binop2_pc_bang);
class_addfloat(binop3_pc_class, (t_method)binop2_pc_float);
class_sethelpsymbol(binop3_pc_class, binop23_sym);
binop3_mod_class = class_new(gensym("mod"), (t_newmethod)binop3_mod_new, 0,
- sizeof(t_binop), 0, A_DEFFLOAT, 0);
+ sizeof(t_binop), 0, A_DEFFLOAT, 0);
class_addbang(binop3_mod_class, binop3_mod_bang);
class_addfloat(binop3_mod_class, (t_method)binop3_mod_float);
class_sethelpsymbol(binop3_mod_class, binop23_sym);
binop3_div_class = class_new(gensym("div"), (t_newmethod)binop3_div_new, 0,
- sizeof(t_binop), 0, A_DEFFLOAT, 0);
+ sizeof(t_binop), 0, A_DEFFLOAT, 0);
class_addbang(binop3_div_class, binop3_div_bang);
class_addfloat(binop3_div_class, (t_method)binop3_div_float);
class_sethelpsymbol(binop3_div_class, binop23_sym);
- /* ------------------- math functions --------------- */
+ /* ------------------- math functions --------------- */
sin_class = class_new(gensym("sin"), sin_new, 0,
- sizeof(t_object), 0, 0);
+ sizeof(t_object), 0, 0);
class_addfloat(sin_class, (t_method)sin_float);
class_sethelpsymbol(sin_class, math_sym);
cos_class = class_new(gensym("cos"), cos_new, 0,
- sizeof(t_object), 0, 0);
+ sizeof(t_object), 0, 0);
class_addfloat(cos_class, (t_method)cos_float);
class_sethelpsymbol(cos_class, math_sym);
tan_class = class_new(gensym("tan"), tan_new, 0,
- sizeof(t_object), 0, 0);
+ sizeof(t_object), 0, 0);
class_addfloat(tan_class, (t_method)tan_float);
class_sethelpsymbol(tan_class, math_sym);
atan_class = class_new(gensym("atan"), atan_new, 0,
- sizeof(t_object), 0, 0);
+ sizeof(t_object), 0, 0);
class_addfloat(atan_class, (t_method)atan_float);
class_sethelpsymbol(atan_class, math_sym);
atan2_class = class_new(gensym("atan2"), atan2_new, 0,
- sizeof(t_atan2), 0, 0);
+ sizeof(t_atan2), 0, 0);
class_addfloat(atan2_class, (t_method)atan2_float);
class_sethelpsymbol(atan2_class, math_sym);
sqrt_class = class_new(gensym("sqrt"), sqrt_new, 0,
- sizeof(t_object), 0, 0);
+ sizeof(t_object), 0, 0);
class_addfloat(sqrt_class, (t_method)sqrt_float);
class_sethelpsymbol(sqrt_class, math_sym);
log_class = class_new(gensym("log"), log_new, 0,
- sizeof(t_object), 0, 0);
+ sizeof(t_object), 0, 0);
class_addfloat(log_class, (t_method)log_float);
class_sethelpsymbol(log_class, math_sym);
exp_class = class_new(gensym("exp"), exp_new, 0,
- sizeof(t_object), 0, 0);
+ sizeof(t_object), 0, 0);
class_addfloat(exp_class, (t_method)exp_float);
class_sethelpsymbol(exp_class, math_sym);
abs_class = class_new(gensym("abs"), abs_new, 0,
- sizeof(t_object), 0, 0);
+ sizeof(t_object), 0, 0);
class_addfloat(abs_class, (t_method)abs_float);
class_sethelpsymbol(abs_class, math_sym);
diff --git a/pd/src/x_connective.c b/pd/src/x_connective.c
index f5173d6e..4dfacb90 100644
--- a/pd/src/x_connective.c
+++ b/pd/src/x_connective.c
@@ -41,7 +41,7 @@ static void pdint_float(t_pdint *x, t_float f)
void pdint_setup(void)
{
pdint_class = class_new(gensym("int"), (t_newmethod)pdint_new, 0,
- sizeof(t_pdint), 0, A_DEFFLOAT, 0);
+ sizeof(t_pdint), 0, A_DEFFLOAT, 0);
class_addcreator((t_newmethod)pdint_new, gensym("i"), A_DEFFLOAT, 0);
class_addbang(pdint_class, pdint_bang);
class_addfloat(pdint_class, pdint_float);
@@ -88,7 +88,7 @@ static void pdfloat_float(t_pdfloat *x, t_float f)
void pdfloat_setup(void)
{
pdfloat_class = class_new(gensym("float"), (t_newmethod)pdfloat_new, 0,
- sizeof(t_pdfloat), 0, A_FLOAT, 0);
+ sizeof(t_pdfloat), 0, A_FLOAT, 0);
class_addcreator((t_newmethod)pdfloat_new2, gensym("f"), A_DEFFLOAT, 0);
class_addbang(pdfloat_class, pdfloat_bang);
class_addfloat(pdfloat_class, (t_method)pdfloat_float);
@@ -138,16 +138,16 @@ static void pdsymbol_anything(t_pdsymbol *x, t_symbol *s, int ac, t_atom *av)
static void pdsymbol_list(t_pdsymbol *x, t_symbol *s, int ac, t_atom *av)
{
if (!ac)
- pdsymbol_bang(x);
+ pdsymbol_bang(x);
else if (av->a_type == A_SYMBOL)
- pdsymbol_symbol(x, av->a_w.w_symbol);
+ pdsymbol_symbol(x, av->a_w.w_symbol);
else pdsymbol_anything(x, s, ac, av);
}
void pdsymbol_setup(void)
{
pdsymbol_class = class_new(gensym("symbol"), (t_newmethod)pdsymbol_new, 0,
- sizeof(t_pdsymbol), 0, A_SYMBOL, 0);
+ sizeof(t_pdsymbol), 0, A_SYMBOL, 0);
class_addbang(pdsymbol_class, pdsymbol_bang);
class_addsymbol(pdsymbol_class, pdsymbol_symbol);
class_addanything(pdsymbol_class, pdsymbol_anything);
@@ -182,7 +182,7 @@ static void bang_bang(t_bang *x)
void bang_setup(void)
{
bang_class = class_new(gensym("bang"), (t_newmethod)bang_new, 0,
- sizeof(t_bang), 0, 0);
+ sizeof(t_bang), 0, 0);
class_addcreator((t_newmethod)bang_new2, gensym("b"), 0);
class_addbang(bang_class, bang_bang);
class_addfloat(bang_class, bang_bang);
@@ -241,7 +241,7 @@ static void *send_new(t_symbol *s)
static void send_setup(void)
{
send_class = class_new(gensym("send"), (t_newmethod)send_new, 0,
- sizeof(t_send), 0, A_DEFSYM, 0);
+ sizeof(t_send), 0, A_DEFSYM, 0);
class_addcreator((t_newmethod)send_new, gensym("s"), A_DEFSYM, 0);
class_addbang(send_class, send_bang);
class_addfloat(send_class, send_float);
@@ -307,7 +307,7 @@ static void receive_free(t_receive *x)
static void receive_setup(void)
{
receive_class = class_new(gensym("receive"), (t_newmethod)receive_new,
- (t_method)receive_free, sizeof(t_receive), CLASS_NOINLET, A_DEFSYM, 0);
+ (t_method)receive_free, sizeof(t_receive), CLASS_NOINLET, A_DEFSYM, 0);
class_addcreator((t_newmethod)receive_new, gensym("r"), A_DEFSYM, 0);
class_addbang(receive_class, receive_bang);
class_addfloat(receive_class, (t_method)receive_float);
@@ -332,14 +332,14 @@ typedef struct _sel1
static void sel1_float(t_sel1 *x, t_float f)
{
if (x->x_atom.a_type == A_FLOAT && f == x->x_atom.a_w.w_float)
- outlet_bang(x->x_outlet1);
+ outlet_bang(x->x_outlet1);
else outlet_float(x->x_outlet2, f);
}
static void sel1_symbol(t_sel1 *x, t_symbol *s)
{
if (x->x_atom.a_type == A_SYMBOL && s == x->x_atom.a_w.w_symbol)
- outlet_bang(x->x_outlet1);
+ outlet_bang(x->x_outlet1);
else outlet_symbol(x->x_outlet2, s);
}
@@ -366,12 +366,12 @@ static void sel2_float(t_sel2 *x, t_float f)
int nelement;
if (x->x_type == A_FLOAT)
{
- for (nelement = x->x_nelement, e = x->x_vec; nelement--; e++)
- if (e->e_w.w_float == f)
- {
- outlet_bang(e->e_outlet);
- return;
- }
+ for (nelement = x->x_nelement, e = x->x_vec; nelement--; e++)
+ if (e->e_w.w_float == f)
+ {
+ outlet_bang(e->e_outlet);
+ return;
+ }
}
outlet_float(x->x_rejectout, f);
}
@@ -382,12 +382,12 @@ static void sel2_symbol(t_sel2 *x, t_symbol *s)
int nelement;
if (x->x_type == A_SYMBOL)
{
- for (nelement = x->x_nelement, e = x->x_vec; nelement--; e++)
- if (e->e_w.w_symbol == s)
- {
- outlet_bang(e->e_outlet);
- return;
- }
+ for (nelement = x->x_nelement, e = x->x_vec; nelement--; e++)
+ if (e->e_w.w_symbol == s)
+ {
+ outlet_bang(e->e_outlet);
+ return;
+ }
}
outlet_symbol(x->x_rejectout, s);
}
@@ -402,44 +402,44 @@ static void *select_new(t_symbol *s, int argc, t_atom *argv)
t_atom a;
if (argc == 0)
{
- argc = 1;
- SETFLOAT(&a, 0);
- argv = &a;
+ argc = 1;
+ SETFLOAT(&a, 0);
+ argv = &a;
}
if (argc == 1)
{
- t_sel1 *x = (t_sel1 *)pd_new(sel1_class);
- x->x_atom = *argv;
- x->x_outlet1 = outlet_new(&x->x_obj, &s_bang);
- if (argv->a_type == A_FLOAT)
- {
- floatinlet_new(&x->x_obj, &x->x_atom.a_w.w_float);
- x->x_outlet2 = outlet_new(&x->x_obj, &s_float);
- }
- else
- {
- symbolinlet_new(&x->x_obj, &x->x_atom.a_w.w_symbol);
- x->x_outlet2 = outlet_new(&x->x_obj, &s_symbol);
- }
- return (x);
+ t_sel1 *x = (t_sel1 *)pd_new(sel1_class);
+ x->x_atom = *argv;
+ x->x_outlet1 = outlet_new(&x->x_obj, &s_bang);
+ if (argv->a_type == A_FLOAT)
+ {
+ floatinlet_new(&x->x_obj, &x->x_atom.a_w.w_float);
+ x->x_outlet2 = outlet_new(&x->x_obj, &s_float);
+ }
+ else
+ {
+ symbolinlet_new(&x->x_obj, &x->x_atom.a_w.w_symbol);
+ x->x_outlet2 = outlet_new(&x->x_obj, &s_symbol);
+ }
+ return (x);
}
else
{
- int n;
- t_selectelement *e;
- t_sel2 *x = (t_sel2 *)pd_new(sel2_class);
- x->x_nelement = argc;
- x->x_vec = (t_selectelement *)getbytes(argc * sizeof(*x->x_vec));
- x->x_type = argv[0].a_type;
- for (n = 0, e = x->x_vec; n < argc; n++, e++)
- {
- e->e_outlet = outlet_new(&x->x_obj, &s_bang);
- if ((x->x_type = argv->a_type) == A_FLOAT)
- e->e_w.w_float = atom_getfloatarg(n, argc, argv);
- else e->e_w.w_symbol = atom_getsymbolarg(n, argc, argv);
- }
- x->x_rejectout = outlet_new(&x->x_obj, &s_float);
- return (x);
+ int n;
+ t_selectelement *e;
+ t_sel2 *x = (t_sel2 *)pd_new(sel2_class);
+ x->x_nelement = argc;
+ x->x_vec = (t_selectelement *)getbytes(argc * sizeof(*x->x_vec));
+ x->x_type = argv[0].a_type;
+ for (n = 0, e = x->x_vec; n < argc; n++, e++)
+ {
+ e->e_outlet = outlet_new(&x->x_obj, &s_bang);
+ if ((x->x_type = argv->a_type) == A_FLOAT)
+ e->e_w.w_float = atom_getfloatarg(n, argc, argv);
+ else e->e_w.w_symbol = atom_getsymbolarg(n, argc, argv);
+ }
+ x->x_rejectout = outlet_new(&x->x_obj, &s_float);
+ return (x);
}
}
@@ -447,12 +447,12 @@ static void *select_new(t_symbol *s, int argc, t_atom *argv)
void select_setup(void)
{
sel1_class = class_new(gensym("select"), 0, 0,
- sizeof(t_sel1), 0, 0);
+ sizeof(t_sel1), 0, 0);
class_addfloat(sel1_class, sel1_float);
class_addsymbol(sel1_class, sel1_symbol);
sel2_class = class_new(gensym("select"), 0, (t_method)sel2_free,
- sizeof(t_sel2), 0, 0);
+ sizeof(t_sel2), 0, 0);
class_addfloat(sel2_class, sel2_float);
class_addsymbol(sel2_class, sel2_symbol);
@@ -485,15 +485,15 @@ static void route_anything(t_route *x, t_symbol *sel, int argc, t_atom *argv)
int nelement;
if (x->x_type == A_SYMBOL)
{
- for (nelement = x->x_nelement, e = x->x_vec; nelement--; e++)
- if (e->e_w.w_symbol == sel)
- {
- if (argc > 0 && argv[0].a_type == A_SYMBOL)
- outlet_anything(e->e_outlet, argv[0].a_w.w_symbol,
- argc-1, argv+1);
- else outlet_list(e->e_outlet, 0, argc, argv);
- return;
- }
+ for (nelement = x->x_nelement, e = x->x_vec; nelement--; e++)
+ if (e->e_w.w_symbol == sel)
+ {
+ if (argc > 0 && argv[0].a_type == A_SYMBOL)
+ outlet_anything(e->e_outlet, argv[0].a_w.w_symbol,
+ argc-1, argv+1);
+ else outlet_list(e->e_outlet, 0, argc, argv);
+ return;
+ }
}
outlet_anything(x->x_rejectout, sel, argc, argv);
}
@@ -504,68 +504,68 @@ static void route_list(t_route *x, t_symbol *sel, int argc, t_atom *argv)
int nelement;
if (x->x_type == A_FLOAT)
{
- float f;
- if (!argc) return;
- f = atom_getfloat(argv);
- for (nelement = x->x_nelement, e = x->x_vec; nelement--; e++)
- if (e->e_w.w_float == f)
- {
- if (argc > 1 && argv[1].a_type == A_SYMBOL)
- outlet_anything(e->e_outlet, argv[1].a_w.w_symbol,
- argc-2, argv+2);
- else outlet_list(e->e_outlet, 0, argc-1, argv+1);
- return;
- }
+ float f;
+ if (!argc) return;
+ f = atom_getfloat(argv);
+ for (nelement = x->x_nelement, e = x->x_vec; nelement--; e++)
+ if (e->e_w.w_float == f)
+ {
+ if (argc > 1 && argv[1].a_type == A_SYMBOL)
+ outlet_anything(e->e_outlet, argv[1].a_w.w_symbol,
+ argc-2, argv+2);
+ else outlet_list(e->e_outlet, 0, argc-1, argv+1);
+ return;
+ }
}
else /* symbol arguments */
{
- if (argc > 1) /* 2 or more args: treat as "list" */
- {
- for (nelement = x->x_nelement, e = x->x_vec; nelement--; e++)
- {
- if (e->e_w.w_symbol == &s_list)
- {
- if (argc > 0 && argv[0].a_type == A_SYMBOL)
- outlet_anything(e->e_outlet, argv[0].a_w.w_symbol,
- argc-1, argv+1);
- else outlet_list(e->e_outlet, 0, argc, argv);
- return;
- }
- }
- }
- else if (argc == 0) /* no args: treat as "bang" */
- {
- for (nelement = x->x_nelement, e = x->x_vec; nelement--; e++)
- {
- if (e->e_w.w_symbol == &s_bang)
- {
- outlet_bang(e->e_outlet);
- return;
- }
- }
- }
- else if (argv[0].a_type == A_FLOAT) /* one float arg */
- {
- for (nelement = x->x_nelement, e = x->x_vec; nelement--; e++)
- {
- if (e->e_w.w_symbol == &s_float)
- {
- outlet_float(e->e_outlet, argv[0].a_w.w_float);
- return;
- }
- }
- }
- else
- {
- for (nelement = x->x_nelement, e = x->x_vec; nelement--; e++)
- {
- if (e->e_w.w_symbol == &s_symbol)
- {
- outlet_symbol(e->e_outlet, argv[0].a_w.w_symbol);
- return;
- }
- }
- }
+ if (argc > 1) /* 2 or more args: treat as "list" */
+ {
+ for (nelement = x->x_nelement, e = x->x_vec; nelement--; e++)
+ {
+ if (e->e_w.w_symbol == &s_list)
+ {
+ if (argc > 0 && argv[0].a_type == A_SYMBOL)
+ outlet_anything(e->e_outlet, argv[0].a_w.w_symbol,
+ argc-1, argv+1);
+ else outlet_list(e->e_outlet, 0, argc, argv);
+ return;
+ }
+ }
+ }
+ else if (argc == 0) /* no args: treat as "bang" */
+ {
+ for (nelement = x->x_nelement, e = x->x_vec; nelement--; e++)
+ {
+ if (e->e_w.w_symbol == &s_bang)
+ {
+ outlet_bang(e->e_outlet);
+ return;
+ }
+ }
+ }
+ else if (argv[0].a_type == A_FLOAT) /* one float arg */
+ {
+ for (nelement = x->x_nelement, e = x->x_vec; nelement--; e++)
+ {
+ if (e->e_w.w_symbol == &s_float)
+ {
+ outlet_float(e->e_outlet, argv[0].a_w.w_float);
+ return;
+ }
+ }
+ }
+ else
+ {
+ for (nelement = x->x_nelement, e = x->x_vec; nelement--; e++)
+ {
+ if (e->e_w.w_symbol == &s_symbol)
+ {
+ outlet_symbol(e->e_outlet, argv[0].a_w.w_symbol);
+ return;
+ }
+ }
+ }
}
outlet_list(x->x_rejectout, 0, argc, argv);
}
@@ -584,19 +584,19 @@ static void *route_new(t_symbol *s, int argc, t_atom *argv)
t_atom a;
if (argc == 0)
{
- argc = 1;
- SETFLOAT(&a, 0);
- argv = &a;
+ argc = 1;
+ SETFLOAT(&a, 0);
+ argv = &a;
}
x->x_type = argv[0].a_type;
x->x_nelement = argc;
x->x_vec = (t_routeelement *)getbytes(argc * sizeof(*x->x_vec));
for (n = 0, e = x->x_vec; n < argc; n++, e++)
{
- e->e_outlet = outlet_new(&x->x_obj, &s_list);
- if (x->x_type == A_FLOAT)
- e->e_w.w_float = atom_getfloatarg(n, argc, argv);
- else e->e_w.w_symbol = atom_getsymbolarg(n, argc, argv);
+ e->e_outlet = outlet_new(&x->x_obj, &s_list);
+ if (x->x_type == A_FLOAT)
+ e->e_w.w_float = atom_getfloatarg(n, argc, argv);
+ else e->e_w.w_symbol = atom_getsymbolarg(n, argc, argv);
}
x->x_rejectout = outlet_new(&x->x_obj, &s_list);
return (x);
@@ -605,7 +605,7 @@ static void *route_new(t_symbol *s, int argc, t_atom *argv)
void route_setup(void)
{
route_class = class_new(gensym("route"), (t_newmethod)route_new,
- (t_method)route_free, sizeof(t_route), 0, A_GIMME, 0);
+ (t_method)route_free, sizeof(t_route), 0, A_GIMME, 0);
class_addlist(route_class, route_list);
class_addanything(route_class, route_anything);
}
@@ -617,11 +617,11 @@ static t_class *pack_class;
typedef struct _pack
{
t_object x_obj;
- t_int x_n; /* number of args */
- t_atom *x_vec; /* input values */
- t_int x_nptr; /* number of pointers */
+ t_int x_n; /* number of args */
+ t_atom *x_vec; /* input values */
+ t_int x_nptr; /* number of pointers */
t_gpointer *x_gpointer; /* the pointers */
- t_atom *x_outvec; /* space for output values */
+ t_atom *x_outvec; /* space for output values */
} t_pack;
static void *pack_new(t_symbol *s, int argc, t_atom *argv)
@@ -633,10 +633,10 @@ static void *pack_new(t_symbol *s, int argc, t_atom *argv)
int i;
if (!argc)
{
- argv = defarg;
- argc = 2;
- SETFLOAT(&defarg[0], 0);
- SETFLOAT(&defarg[1], 0);
+ argv = defarg;
+ argc = 2;
+ SETFLOAT(&defarg[0], 0);
+ SETFLOAT(&defarg[1], 0);
}
x->x_n = argc;
@@ -644,43 +644,43 @@ static void *pack_new(t_symbol *s, int argc, t_atom *argv)
x->x_outvec = (t_atom *)getbytes(argc * sizeof(*x->x_outvec));
for (i = argc, ap = argv; i--; ap++)
- if (ap->a_type == A_SYMBOL && *ap->a_w.w_symbol->s_name == 'p')
- nptr++;
+ if (ap->a_type == A_SYMBOL && *ap->a_w.w_symbol->s_name == 'p')
+ nptr++;
gp = x->x_gpointer = (t_gpointer *)t_getbytes(nptr * sizeof (*gp));
x->x_nptr = nptr;
for (i = 0, vp = x->x_vec, ap = argv; i < argc; i++, ap++, vp++)
{
- if (ap->a_type == A_FLOAT)
- {
- *vp = *ap;
- if (i) floatinlet_new(&x->x_obj, &vp->a_w.w_float);
- }
- else if (ap->a_type == A_SYMBOL)
- {
- char c = *ap->a_w.w_symbol->s_name;
- if (c == 's')
- {
- SETSYMBOL(vp, &s_symbol);
- if (i) symbolinlet_new(&x->x_obj, &vp->a_w.w_symbol);
- }
- else if (c == 'p')
- {
- vp->a_type = A_POINTER;
- vp->a_w.w_gpointer = gp;
- gpointer_init(gp);
- if (i) pointerinlet_new(&x->x_obj, gp);
- gp++;
- }
- else
- {
- if (c != 'f') pd_error(x, "pack: %s: bad type",
- ap->a_w.w_symbol->s_name);
- SETFLOAT(vp, 0);
- if (i) floatinlet_new(&x->x_obj, &vp->a_w.w_float);
- }
- }
+ if (ap->a_type == A_FLOAT)
+ {
+ *vp = *ap;
+ if (i) floatinlet_new(&x->x_obj, &vp->a_w.w_float);
+ }
+ else if (ap->a_type == A_SYMBOL)
+ {
+ char c = *ap->a_w.w_symbol->s_name;
+ if (c == 's')
+ {
+ SETSYMBOL(vp, &s_symbol);
+ if (i) symbolinlet_new(&x->x_obj, &vp->a_w.w_symbol);
+ }
+ else if (c == 'p')
+ {
+ vp->a_type = A_POINTER;
+ vp->a_w.w_gpointer = gp;
+ gpointer_init(gp);
+ if (i) pointerinlet_new(&x->x_obj, gp);
+ gp++;
+ }
+ else
+ {
+ if (c != 'f') pd_error(x, "pack: %s: bad type",
+ ap->a_w.w_symbol->s_name);
+ SETFLOAT(vp, 0);
+ if (i) floatinlet_new(&x->x_obj, &vp->a_w.w_float);
+ }
+ }
}
outlet_new(&x->x_obj, &s_list);
return (x);
@@ -692,30 +692,30 @@ static void pack_bang(t_pack *x)
t_gpointer *gp;
t_atom *outvec;
for (i = x->x_nptr, gp = x->x_gpointer; i--; gp++)
- if (!gpointer_check(gp, 1))
+ if (!gpointer_check(gp, 1))
{
- pd_error(x, "pack: stale pointer");
- return;
+ pd_error(x, "pack: stale pointer");
+ return;
}
- /* reentrancy protection. The first time through use the pre-allocated
- x_outvec; if we're reentered we have to allocate new memory. */
+ /* reentrancy protection. The first time through use the pre-allocated
+ x_outvec; if we're reentered we have to allocate new memory. */
if (!x->x_outvec)
{
- /* LATER figure out how to deal with reentrancy and pointers... */
- if (x->x_nptr)
- post("pack_bang: warning: reentry with pointers unprotected");
- outvec = t_getbytes(size);
- reentered = 1;
+ /* LATER figure out how to deal with reentrancy and pointers... */
+ if (x->x_nptr)
+ post("pack_bang: warning: reentry with pointers unprotected");
+ outvec = t_getbytes(size);
+ reentered = 1;
}
else
{
- outvec = x->x_outvec;
- x->x_outvec = 0;
+ outvec = x->x_outvec;
+ x->x_outvec = 0;
}
memcpy(outvec, x->x_vec, size);
outlet_list(x->x_obj.ob_outlet, &s_list, x->x_n, outvec);
if (reentered)
- t_freebytes(outvec, size);
+ t_freebytes(outvec, size);
else x->x_outvec = outvec;
}
@@ -723,10 +723,10 @@ static void pack_pointer(t_pack *x, t_gpointer *gp)
{
if (x->x_vec->a_type == A_POINTER)
{
- gpointer_unset(x->x_gpointer);
- *x->x_gpointer = *gp;
- if (gp->gp_stub) gp->gp_stub->gs_refcount++;
- pack_bang(x);
+ gpointer_unset(x->x_gpointer);
+ *x->x_gpointer = *gp;
+ if (gp->gp_stub) gp->gp_stub->gs_refcount++;
+ pack_bang(x);
}
else pd_error(x, "pack_pointer: wrong type");
}
@@ -735,8 +735,8 @@ static void pack_float(t_pack *x, t_float f)
{
if (x->x_vec->a_type == A_FLOAT)
{
- x->x_vec->a_w.w_float = f;
- pack_bang(x);
+ x->x_vec->a_w.w_float = f;
+ pack_bang(x);
}
else pd_error(x, "pack_float: wrong type");
}
@@ -745,8 +745,8 @@ static void pack_symbol(t_pack *x, t_symbol *s)
{
if (x->x_vec->a_type == A_SYMBOL)
{
- x->x_vec->a_w.w_symbol = s;
- pack_bang(x);
+ x->x_vec->a_w.w_symbol = s;
+ pack_bang(x);
}
else pd_error(x, "pack_symbol: wrong type");
}
@@ -761,7 +761,7 @@ static void pack_anything(t_pack *x, t_symbol *s, int ac, t_atom *av)
t_atom *av2 = (t_atom *)getbytes((ac + 1) * sizeof(t_atom));
int i;
for (i = 0; i < ac; i++)
- av2[i + 1] = av[i];
+ av2[i + 1] = av[i];
SETSYMBOL(av2, s);
obj_list(&x->x_obj, 0, ac+1, av2);
freebytes(av2, (ac + 1) * sizeof(t_atom));
@@ -772,7 +772,7 @@ static void pack_free(t_pack *x)
t_gpointer *gp;
int i;
for (gp = x->x_gpointer, i = x->x_nptr; i--; gp++)
- gpointer_unset(gp);
+ gpointer_unset(gp);
freebytes(x->x_vec, x->x_n * sizeof(*x->x_vec));
freebytes(x->x_outvec, x->x_n * sizeof(*x->x_outvec));
freebytes(x->x_gpointer, x->x_nptr * sizeof(*x->x_gpointer));
@@ -781,7 +781,7 @@ static void pack_free(t_pack *x)
static void pack_setup(void)
{
pack_class = class_new(gensym("pack"), (t_newmethod)pack_new,
- (t_method)pack_free, sizeof(t_pack), 0, A_GIMME, 0);
+ (t_method)pack_free, sizeof(t_pack), 0, A_GIMME, 0);
class_addbang(pack_class, pack_bang);
class_addpointer(pack_class, pack_pointer);
class_addfloat(pack_class, pack_float);
@@ -815,42 +815,42 @@ static void *unpack_new(t_symbol *s, int argc, t_atom *argv)
int i;
if (!argc)
{
- argv = defarg;
- argc = 2;
- SETFLOAT(&defarg[0], 0);
- SETFLOAT(&defarg[1], 0);
+ argv = defarg;
+ argc = 2;
+ SETFLOAT(&defarg[0], 0);
+ SETFLOAT(&defarg[1], 0);
}
x->x_n = argc;
x->x_vec = (t_unpackout *)getbytes(argc * sizeof(*x->x_vec));
for (i = 0, ap = argv, u = x->x_vec; i < argc; u++, ap++, i++)
{
- t_atomtype type = ap->a_type;
- if (type == A_SYMBOL)
- {
- char c = *ap->a_w.w_symbol->s_name;
- if (c == 's')
- {
- u->u_type = A_SYMBOL;
- u->u_outlet = outlet_new(&x->x_obj, &s_symbol);
- }
- else if (c == 'p')
- {
- u->u_type = A_POINTER;
- u->u_outlet = outlet_new(&x->x_obj, &s_pointer);
- }
- else
- {
- if (c != 'f') pd_error(x, "unpack: %s: bad type",
- ap->a_w.w_symbol->s_name);
- u->u_type = A_FLOAT;
- u->u_outlet = outlet_new(&x->x_obj, &s_float);
- }
- }
- else
- {
- u->u_type = A_FLOAT;
- u->u_outlet = outlet_new(&x->x_obj, &s_float);
- }
+ t_atomtype type = ap->a_type;
+ if (type == A_SYMBOL)
+ {
+ char c = *ap->a_w.w_symbol->s_name;
+ if (c == 's')
+ {
+ u->u_type = A_SYMBOL;
+ u->u_outlet = outlet_new(&x->x_obj, &s_symbol);
+ }
+ else if (c == 'p')
+ {
+ u->u_type = A_POINTER;
+ u->u_outlet = outlet_new(&x->x_obj, &s_pointer);
+ }
+ else
+ {
+ if (c != 'f') pd_error(x, "unpack: %s: bad type",
+ ap->a_w.w_symbol->s_name);
+ u->u_type = A_FLOAT;
+ u->u_outlet = outlet_new(&x->x_obj, &s_float);
+ }
+ }
+ else
+ {
+ u->u_type = A_FLOAT;
+ u->u_outlet = outlet_new(&x->x_obj, &s_float);
+ }
}
return (x);
}
@@ -863,14 +863,14 @@ static void unpack_list(t_unpack *x, t_symbol *s, int argc, t_atom *argv)
if (argc > x->x_n) argc = x->x_n;
for (i = argc, u = x->x_vec + i, ap = argv + i; u--, ap--, i--;)
{
- t_atomtype type = u->u_type;
- if (type != ap->a_type)
- pd_error(x, "unpack: type mismatch");
- else if (type == A_FLOAT)
- outlet_float(u->u_outlet, ap->a_w.w_float);
- else if (type == A_SYMBOL)
- outlet_symbol(u->u_outlet, ap->a_w.w_symbol);
- else outlet_pointer(u->u_outlet, ap->a_w.w_gpointer);
+ t_atomtype type = u->u_type;
+ if (type != ap->a_type)
+ pd_error(x, "unpack: type mismatch");
+ else if (type == A_FLOAT)
+ outlet_float(u->u_outlet, ap->a_w.w_float);
+ else if (type == A_SYMBOL)
+ outlet_symbol(u->u_outlet, ap->a_w.w_symbol);
+ else outlet_pointer(u->u_outlet, ap->a_w.w_gpointer);
}
}
@@ -879,7 +879,7 @@ static void unpack_anything(t_unpack *x, t_symbol *s, int ac, t_atom *av)
t_atom *av2 = (t_atom *)getbytes((ac + 1) * sizeof(t_atom));
int i;
for (i = 0; i < ac; i++)
- av2[i + 1] = av[i];
+ av2[i + 1] = av[i];
SETSYMBOL(av2, s);
unpack_list(x, 0, ac+1, av2);
freebytes(av2, (ac + 1) * sizeof(t_atom));
@@ -893,7 +893,7 @@ static void unpack_free(t_unpack *x)
static void unpack_setup(void)
{
unpack_class = class_new(gensym("unpack"), (t_newmethod)unpack_new,
- (t_method)unpack_free, sizeof(t_unpack), 0, A_GIMME, 0);
+ (t_method)unpack_free, sizeof(t_unpack), 0, A_GIMME, 0);
class_addlist(unpack_class, unpack_list);
class_addanything(unpack_class, unpack_anything);
}
@@ -910,7 +910,7 @@ static t_class *trigger_class;
typedef struct triggerout
{
- int u_type; /* outlet type from above */
+ int u_type; /* outlet type from above */
t_outlet *u_outlet;
} t_triggerout;
@@ -929,40 +929,40 @@ static void *trigger_new(t_symbol *s, int argc, t_atom *argv)
int i;
if (!argc)
{
- argv = defarg;
- argc = 2;
- SETSYMBOL(&defarg[0], &s_bang);
- SETSYMBOL(&defarg[1], &s_bang);
+ argv = defarg;
+ argc = 2;
+ SETSYMBOL(&defarg[0], &s_bang);
+ SETSYMBOL(&defarg[1], &s_bang);
}
x->x_n = argc;
x->x_vec = (t_triggerout *)getbytes(argc * sizeof(*x->x_vec));
for (i = 0, ap = argv, u = x->x_vec; i < argc; u++, ap++, i++)
{
- t_atomtype thistype = ap->a_type;
- char c;
- if (thistype == TR_SYMBOL) c = ap->a_w.w_symbol->s_name[0];
- else if (thistype == TR_FLOAT) c = 'f';
- else c = 0;
- if (c == 'p')
- u->u_type = TR_POINTER,
- u->u_outlet = outlet_new(&x->x_obj, &s_pointer);
- else if (c == 'f')
- u->u_type = TR_FLOAT, u->u_outlet = outlet_new(&x->x_obj, &s_float);
- else if (c == 'b')
- u->u_type = TR_BANG, u->u_outlet = outlet_new(&x->x_obj, &s_bang);
- else if (c == 'l')
- u->u_type = TR_LIST, u->u_outlet = outlet_new(&x->x_obj, &s_list);
- else if (c == 's')
- u->u_type = TR_SYMBOL,
- u->u_outlet = outlet_new(&x->x_obj, &s_symbol);
- else if (c == 'a')
- u->u_type = TR_ANYTHING,
- u->u_outlet = outlet_new(&x->x_obj, &s_symbol);
- else
- {
- pd_error(x, "trigger: %s: bad type", ap->a_w.w_symbol->s_name);
- u->u_type = TR_FLOAT, u->u_outlet = outlet_new(&x->x_obj, &s_float);
- }
+ t_atomtype thistype = ap->a_type;
+ char c;
+ if (thistype == TR_SYMBOL) c = ap->a_w.w_symbol->s_name[0];
+ else if (thistype == TR_FLOAT) c = 'f';
+ else c = 0;
+ if (c == 'p')
+ u->u_type = TR_POINTER,
+ u->u_outlet = outlet_new(&x->x_obj, &s_pointer);
+ else if (c == 'f')
+ u->u_type = TR_FLOAT, u->u_outlet = outlet_new(&x->x_obj, &s_float);
+ else if (c == 'b')
+ u->u_type = TR_BANG, u->u_outlet = outlet_new(&x->x_obj, &s_bang);
+ else if (c == 'l')
+ u->u_type = TR_LIST, u->u_outlet = outlet_new(&x->x_obj, &s_list);
+ else if (c == 's')
+ u->u_type = TR_SYMBOL,
+ u->u_outlet = outlet_new(&x->x_obj, &s_symbol);
+ else if (c == 'a')
+ u->u_type = TR_ANYTHING,
+ u->u_outlet = outlet_new(&x->x_obj, &s_symbol);
+ else
+ {
+ pd_error(x, "trigger: %s: bad type", ap->a_w.w_symbol->s_name);
+ u->u_type = TR_FLOAT, u->u_outlet = outlet_new(&x->x_obj, &s_float);
+ }
}
return (x);
}
@@ -974,25 +974,25 @@ static void trigger_list(t_trigger *x, t_symbol *s, int argc, t_atom *argv)
t_atom at;
if (!argc)
{
- argc = 1;
- SETFLOAT(&at, 0);
- argv = &at;
+ argc = 1;
+ SETFLOAT(&at, 0);
+ argv = &at;
}
for (i = x->x_n, u = x->x_vec + i; u--, i--;)
{
- if (u->u_type == TR_FLOAT)
- outlet_float(u->u_outlet, atom_getfloat(argv));
- else if (u->u_type == TR_BANG)
- outlet_bang(u->u_outlet);
- else if (u->u_type == TR_SYMBOL)
- outlet_symbol(u->u_outlet, atom_getsymbol(argv));
- else if (u->u_type == TR_POINTER)
- {
- if (argv->a_type != TR_POINTER)
- pd_error(x, "unpack: bad pointer");
- else outlet_pointer(u->u_outlet, argv->a_w.w_gpointer);
- }
- else outlet_list(u->u_outlet, &s_list, argc, argv);
+ if (u->u_type == TR_FLOAT)
+ outlet_float(u->u_outlet, atom_getfloat(argv));
+ else if (u->u_type == TR_BANG)
+ outlet_bang(u->u_outlet);
+ else if (u->u_type == TR_SYMBOL)
+ outlet_symbol(u->u_outlet, atom_getsymbol(argv));
+ else if (u->u_type == TR_POINTER)
+ {
+ if (argv->a_type != TR_POINTER)
+ pd_error(x, "unpack: bad pointer");
+ else outlet_pointer(u->u_outlet, argv->a_w.w_gpointer);
+ }
+ else outlet_list(u->u_outlet, &s_list, argc, argv);
}
}
@@ -1002,12 +1002,12 @@ static void trigger_anything(t_trigger *x, t_symbol *s, int argc, t_atom *argv)
int i;
for (i = x->x_n, u = x->x_vec + i; u--, i--;)
{
- if (u->u_type == TR_BANG)
- outlet_bang(u->u_outlet);
- else if (u->u_type == TR_ANYTHING)
- outlet_anything(u->u_outlet, s, argc, argv);
- else pd_error(x, "trigger: can only convert 's' to 'b' or 'a'",
- s->s_name);
+ if (u->u_type == TR_BANG)
+ outlet_bang(u->u_outlet);
+ else if (u->u_type == TR_ANYTHING)
+ outlet_anything(u->u_outlet, s, argc, argv);
+ else pd_error(x, "trigger: can only convert 's' to 'b' or 'a'",
+ s->s_name);
}
}
@@ -1045,7 +1045,7 @@ static void trigger_free(t_trigger *x)
static void trigger_setup(void)
{
trigger_class = class_new(gensym("trigger"), (t_newmethod)trigger_new,
- (t_method)trigger_free, sizeof(t_trigger), 0, A_GIMME, 0);
+ (t_method)trigger_free, sizeof(t_trigger), 0, A_GIMME, 0);
class_addcreator((t_newmethod)trigger_new, gensym("t"), A_GIMME, 0);
class_addlist(trigger_class, trigger_list);
class_addbang(trigger_class, trigger_bang);
@@ -1106,7 +1106,7 @@ static void spigot_anything(t_spigot *x, t_symbol *s, int argc, t_atom *argv)
static void spigot_setup(void)
{
spigot_class = class_new(gensym("spigot"), (t_newmethod)spigot_new, 0,
- sizeof(t_spigot), 0, A_DEFSYM, 0);
+ sizeof(t_spigot), 0, A_DEFSYM, 0);
class_addbang(spigot_class, spigot_bang);
class_addpointer(spigot_class, spigot_pointer);
class_addfloat(spigot_class, spigot_float);
@@ -1144,7 +1144,7 @@ static void moses_float(t_moses *x, t_float f)
static void moses_setup(void)
{
moses_class = class_new(gensym("moses"), (t_newmethod)moses_new, 0,
- sizeof(t_moses), 0, A_DEFFLOAT, 0);
+ sizeof(t_moses), 0, A_DEFFLOAT, 0);
class_addfloat(moses_class, moses_float);
}
@@ -1173,7 +1173,7 @@ static void until_bang(t_until *x)
x->x_run = 1;
x->x_count = -1;
while (x->x_run && x->x_count)
- x->x_count--, outlet_bang(x->x_obj.ob_outlet);
+ x->x_count--, outlet_bang(x->x_obj.ob_outlet);
}
static void until_float(t_until *x, t_float f)
@@ -1181,7 +1181,7 @@ static void until_float(t_until *x, t_float f)
x->x_run = 1;
x->x_count = f;
while (x->x_run && x->x_count)
- x->x_count--, outlet_bang(x->x_obj.ob_outlet);
+ x->x_count--, outlet_bang(x->x_obj.ob_outlet);
}
static void until_bang2(t_until *x)
@@ -1192,7 +1192,7 @@ static void until_bang2(t_until *x)
static void until_setup(void)
{
until_class = class_new(gensym("until"), (t_newmethod)until_new, 0,
- sizeof(t_until), 0, 0);
+ sizeof(t_until), 0, 0);
class_addbang(until_class, until_bang);
class_addfloat(until_class, until_float);
class_addmethod(until_class, (t_method)until_bang2, gensym("bang2"), 0);
@@ -1240,11 +1240,11 @@ static void makefilename_setup(void)
{
makefilename_class = class_new(gensym("makefilename"),
(t_newmethod)makefilename_new, 0,
- sizeof(t_makefilename), 0, A_DEFSYM, 0);
+ sizeof(t_makefilename), 0, A_DEFSYM, 0);
class_addfloat(makefilename_class, makefilename_float);
class_addsymbol(makefilename_class, makefilename_symbol);
class_addmethod(makefilename_class, (t_method)makefilename_set,
- gensym("set"), A_SYMBOL, 0);
+ gensym("set"), A_SYMBOL, 0);
}
/* -------------------------- swap ------------------------------ */
@@ -1284,7 +1284,7 @@ static void swap_float(t_swap *x, t_float f)
void swap_setup(void)
{
swap_class = class_new(gensym("swap"), (t_newmethod)swap_new, 0,
- sizeof(t_swap), 0, A_DEFFLOAT, 0);
+ sizeof(t_swap), 0, A_DEFFLOAT, 0);
class_addcreator((t_newmethod)swap_new, gensym("fswap"), A_DEFFLOAT, 0);
class_addbang(swap_class, swap_bang);
class_addfloat(swap_class, swap_float);
@@ -1316,8 +1316,8 @@ static void change_float(t_change *x, t_float f)
{
if (f != x->x_f)
{
- x->x_f = f;
- outlet_float(x->x_obj.ob_outlet, x->x_f);
+ x->x_f = f;
+ outlet_float(x->x_obj.ob_outlet, x->x_f);
}
}
@@ -1329,11 +1329,11 @@ static void change_set(t_change *x, t_float f)
void change_setup(void)
{
change_class = class_new(gensym("change"), (t_newmethod)change_new, 0,
- sizeof(t_change), 0, A_DEFFLOAT, 0);
+ sizeof(t_change), 0, A_DEFFLOAT, 0);
class_addbang(change_class, change_bang);
class_addfloat(change_class, change_float);
class_addmethod(change_class, (t_method)change_set, gensym("set"),
- A_DEFFLOAT, 0);
+ A_DEFFLOAT, 0);
}
/* -------------------- value ------------------------------ */
@@ -1361,10 +1361,10 @@ t_float *value_get(t_symbol *s)
t_vcommon *c = (t_vcommon *)pd_findbyclass(s, vcommon_class);
if (!c)
{
- c = (t_vcommon *)pd_new(vcommon_class);
- c->c_f = 0;
- c->c_refcount = 0;
- pd_bind(&c->c_pd, s);
+ c = (t_vcommon *)pd_new(vcommon_class);
+ c->c_f = 0;
+ c->c_refcount = 0;
+ pd_bind(&c->c_pd, s);
}
c->c_refcount++;
return (&c->c_f);
@@ -1377,11 +1377,11 @@ void value_release(t_symbol *s)
t_vcommon *c = (t_vcommon *)pd_findbyclass(s, vcommon_class);
if (c)
{
- if (!--c->c_refcount)
- {
- pd_unbind(&c->c_pd, s);
- pd_free(&c->c_pd);
- }
+ if (!--c->c_refcount)
+ {
+ pd_unbind(&c->c_pd, s);
+ pd_free(&c->c_pd);
+ }
}
else bug("value_release");
}
@@ -1441,13 +1441,13 @@ static void value_ff(t_value *x)
static void value_setup(void)
{
value_class = class_new(gensym("value"), (t_newmethod)value_new,
- (t_method)value_ff,
- sizeof(t_value), 0, A_DEFSYM, 0);
+ (t_method)value_ff,
+ sizeof(t_value), 0, A_DEFSYM, 0);
class_addcreator((t_newmethod)value_new, gensym("v"), A_DEFSYM, 0);
class_addbang(value_class, value_bang);
class_addfloat(value_class, value_float);
vcommon_class = class_new(gensym("value"), 0, 0,
- sizeof(t_vcommon), CLASS_PD, 0);
+ sizeof(t_vcommon), CLASS_PD, 0);
}
/* -------------- overall setup routine for this file ----------------- */
diff --git a/pd/src/x_gui.c b/pd/src/x_gui.c
index b469467a..9538fedc 100644
--- a/pd/src/x_gui.c
+++ b/pd/src/x_gui.c
@@ -8,7 +8,7 @@ away before the panel does... */
#include "m_pd.h"
#include <stdio.h>
#include <string.h>
-#ifdef UNIX
+#ifdef UNISTD
#include <unistd.h>
#endif
@@ -48,17 +48,17 @@ void gfxstub_new(t_pd *owner, void *key, const char *cmd)
char namebuf[80];
t_gfxstub *x;
t_symbol *s;
- /* if any exists with matching key, burn it. */
+ /* if any exists with matching key, burn it. */
for (x = gfxstub_list; x; x = x->x_next)
- if (x->x_key == key)
- gfxstub_deleteforkey(key);
+ if (x->x_key == key)
+ gfxstub_deleteforkey(key);
if (strlen(cmd) + 50 > MAXPDSTRING)
{
- bug("audio dialog too long");
- return;
+ bug("audio dialog too long");
+ return;
}
x = (t_gfxstub *)pd_new(gfxstub_class);
- sprintf(namebuf, ".gfxstub%x", (t_int)x);
+ sprintf(namebuf, ".gfxstub%lx", (t_int)x);
s = gensym(namebuf);
pd_bind(&x->x_pd, s);
@@ -75,12 +75,12 @@ static void gfxstub_offlist(t_gfxstub *x)
{
t_gfxstub *y1, *y2;
if (gfxstub_list == x)
- gfxstub_list = x->x_next;
+ gfxstub_list = x->x_next;
else for (y1 = gfxstub_list; y2 = y1->x_next; y1 = y2)
- if (y2 == x)
+ if (y2 == x)
{
- y1->x_next = y2->x_next;
- break;
+ y1->x_next = y2->x_next;
+ break;
}
}
@@ -93,18 +93,18 @@ void gfxstub_deleteforkey(void *key)
int didit = 1;
while (didit)
{
- didit = 0;
- for (y = gfxstub_list; y; y = y->x_next)
- {
- if (y->x_key == key)
- {
- sys_vgui("destroy .gfxstub%x\n", y);
- y->x_owner = 0;
- gfxstub_offlist(y);
- didit = 1;
- break;
- }
- }
+ didit = 0;
+ for (y = gfxstub_list; y; y = y->x_next)
+ {
+ if (y->x_key == key)
+ {
+ sys_vgui("destroy .gfxstub%lx\n", y);
+ y->x_owner = 0;
+ gfxstub_offlist(y);
+ didit = 1;
+ break;
+ }
+ }
}
}
@@ -129,7 +129,7 @@ static t_binbuf *gfxstub_binbuf;
static void gfxstub_data(t_gfxstub *x, t_symbol *s, int argc, t_atom *argv)
{
if (!gfxstub_binbuf)
- gfxstub_binbuf = binbuf_new();
+ gfxstub_binbuf = binbuf_new();
binbuf_add(gfxstub_binbuf, argc, argv);
binbuf_addsemi(gfxstub_binbuf);
}
@@ -137,7 +137,7 @@ static void gfxstub_data(t_gfxstub *x, t_symbol *s, int argc, t_atom *argv)
static void gfxstub_end(t_gfxstub *x)
{
canvas_dataproperties((t_canvas *)x->x_owner,
- (t_scalar *)x->x_key, gfxstub_binbuf);
+ (t_scalar *)x->x_key, gfxstub_binbuf);
binbuf_free(gfxstub_binbuf);
gfxstub_binbuf = 0;
}
@@ -147,7 +147,7 @@ static void gfxstub_end(t_gfxstub *x)
static void gfxstub_anything(t_gfxstub *x, t_symbol *s, int argc, t_atom *argv)
{
if (x->x_owner)
- pd_typedmess(x->x_owner, s, argc, argv);
+ pd_typedmess(x->x_owner, s, argc, argv);
}
static void gfxstub_free(t_gfxstub *x)
@@ -158,17 +158,17 @@ static void gfxstub_free(t_gfxstub *x)
static void gfxstub_setup(void)
{
gfxstub_class = class_new(gensym("gfxstub"), (t_newmethod)gfxstub_new,
- (t_method)gfxstub_free,
- sizeof(t_gfxstub), CLASS_PD, 0);
+ (t_method)gfxstub_free,
+ sizeof(t_gfxstub), CLASS_PD, 0);
class_addanything(gfxstub_class, gfxstub_anything);
class_addmethod(gfxstub_class, (t_method)gfxstub_signoff,
- gensym("signoff"), 0);
+ gensym("signoff"), 0);
class_addmethod(gfxstub_class, (t_method)gfxstub_data,
- gensym("data"), A_GIMME, 0);
+ gensym("data"), A_GIMME, 0);
class_addmethod(gfxstub_class, (t_method)gfxstub_end,
- gensym("end"), 0);
+ gensym("end"), 0);
class_addmethod(gfxstub_class, (t_method)gfxstub_cancel,
- gensym("cancel"), 0);
+ gensym("cancel"), 0);
}
/* -------------------------- openpanel ------------------------------ */
@@ -185,7 +185,7 @@ static void *openpanel_new(void)
{
char buf[50];
t_openpanel *x = (t_openpanel *)pd_new(openpanel_class);
- sprintf(buf, "d%x", (t_int)x);
+ sprintf(buf, "d%lx", (t_int)x);
x->x_s = gensym(buf);
pd_bind(&x->x_obj.ob_pd, x->x_s);
outlet_new(&x->x_obj, &s_symbol);
@@ -210,8 +210,8 @@ static void openpanel_free(t_openpanel *x)
static void openpanel_setup(void)
{
openpanel_class = class_new(gensym("openpanel"),
- (t_newmethod)openpanel_new, (t_method)openpanel_free,
- sizeof(t_openpanel), 0, A_DEFFLOAT, 0);
+ (t_newmethod)openpanel_new, (t_method)openpanel_free,
+ sizeof(t_openpanel), 0, A_DEFFLOAT, 0);
class_addbang(openpanel_class, openpanel_bang);
class_addsymbol(openpanel_class, openpanel_symbol);
}
@@ -230,7 +230,7 @@ static void *savepanel_new(void)
{
char buf[50];
t_savepanel *x = (t_savepanel *)pd_new(savepanel_class);
- sprintf(buf, "d%x", (t_int)x);
+ sprintf(buf, "d%lx", (t_int)x);
x->x_s = gensym(buf);
pd_bind(&x->x_obj.ob_pd, x->x_s);
outlet_new(&x->x_obj, &s_symbol);
@@ -255,8 +255,8 @@ static void savepanel_free(t_savepanel *x)
static void savepanel_setup(void)
{
savepanel_class = class_new(gensym("savepanel"),
- (t_newmethod)savepanel_new, (t_method)savepanel_free,
- sizeof(t_savepanel), 0, A_DEFFLOAT, 0);
+ (t_newmethod)savepanel_new, (t_method)savepanel_free,
+ sizeof(t_savepanel), 0, A_DEFFLOAT, 0);
class_addbang(savepanel_class, savepanel_bang);
class_addsymbol(savepanel_class, savepanel_symbol);
}
@@ -342,21 +342,21 @@ static void keyname_free(t_keyname *x)
static void key_setup(void)
{
key_class = class_new(gensym("key"),
- (t_newmethod)key_new, (t_method)key_free,
- sizeof(t_key), CLASS_NOINLET, 0);
+ (t_newmethod)key_new, (t_method)key_free,
+ sizeof(t_key), CLASS_NOINLET, 0);
class_addfloat(key_class, key_float);
key_sym = gensym("#key");
keyup_class = class_new(gensym("keyup"),
- (t_newmethod)keyup_new, (t_method)keyup_free,
- sizeof(t_keyup), CLASS_NOINLET, 0);
+ (t_newmethod)keyup_new, (t_method)keyup_free,
+ sizeof(t_keyup), CLASS_NOINLET, 0);
class_addfloat(keyup_class, keyup_float);
keyup_sym = gensym("#keyup");
class_sethelpsymbol(keyup_class, gensym("key"));
keyname_class = class_new(gensym("keyname"),
- (t_newmethod)keyname_new, (t_method)keyname_free,
- sizeof(t_keyname), CLASS_NOINLET, 0);
+ (t_newmethod)keyname_new, (t_method)keyname_free,
+ sizeof(t_keyname), CLASS_NOINLET, 0);
class_addlist(keyname_class, keyname_list);
keyname_sym = gensym("#keyname");
class_sethelpsymbol(keyname_class, gensym("key"));
diff --git a/pd/src/x_interface.c b/pd/src/x_interface.c
index 068b0bbc..19c44962 100644
--- a/pd/src/x_interface.c
+++ b/pd/src/x_interface.c
@@ -44,8 +44,8 @@ static void print_list(t_print *x, t_symbol *s, int argc, t_atom *argv)
char buf[80];
if (argc && argv->a_type != A_SYMBOL) startpost("%s:", x->x_sym->s_name);
else startpost("%s: %s", x->x_sym->s_name,
- (argc > 1 ? s_list.s_name : (argc == 1 ? s_symbol.s_name :
- s_bang.s_name)));
+ (argc > 1 ? s_list.s_name : (argc == 1 ? s_symbol.s_name :
+ s_bang.s_name)));
postatom(argc, argv);
endpost();
}
@@ -62,7 +62,7 @@ static void print_anything(t_print *x, t_symbol *s, int argc, t_atom *argv)
static void print_setup(void)
{
print_class = class_new(gensym("print"), (t_newmethod)print_new, 0,
- sizeof(t_print), 0, A_DEFSYM, 0);
+ sizeof(t_print), 0, A_DEFSYM, 0);
class_addbang(print_class, print_bang);
class_addfloat(print_class, print_float);
class_addpointer(print_class, print_pointer);
diff --git a/pd/src/x_midi.c b/pd/src/x_midi.c
index 1ff0e4b3..6b2fd60c 100644
--- a/pd/src/x_midi.c
+++ b/pd/src/x_midi.c
@@ -69,15 +69,15 @@ static void sysexin_free(t_midiin *x)
static void midiin_setup(void)
{
midiin_class = class_new(gensym("midiin"), (t_newmethod)midiin_new,
- (t_method)midiin_free, sizeof(t_midiin),
- CLASS_NOINLET, A_DEFFLOAT, 0);
+ (t_method)midiin_free, sizeof(t_midiin),
+ CLASS_NOINLET, A_DEFFLOAT, 0);
class_addlist(midiin_class, midiin_list);
class_sethelpsymbol(midiin_class, gensym("midi"));
midiin_sym = gensym("#midiin");
sysexin_class = class_new(gensym("sysexin"), (t_newmethod)sysexin_new,
- (t_method)sysexin_free, sizeof(t_midiin),
- CLASS_NOINLET, A_DEFFLOAT, 0);
+ (t_method)sysexin_free, sizeof(t_midiin),
+ CLASS_NOINLET, A_DEFFLOAT, 0);
class_addlist(sysexin_class, midiin_list);
class_sethelpsymbol(sysexin_class, gensym("midi"));
sysexin_sym = gensym("#sysexin");
@@ -88,9 +88,9 @@ void inmidi_byte(int portno, int byte)
t_atom at[2];
if (midiin_sym->s_thing)
{
- SETFLOAT(at, byte);
- SETFLOAT(at+1, portno + 1);
- pd_list(midiin_sym->s_thing, 0, 2, at);
+ SETFLOAT(at, byte);
+ SETFLOAT(at+1, portno + 1);
+ pd_list(midiin_sym->s_thing, 0, 2, at);
}
}
@@ -99,9 +99,9 @@ void inmidi_sysex(int portno, int byte)
t_atom at[2];
if (sysexin_sym->s_thing)
{
- SETFLOAT(at, byte);
- SETFLOAT(at+1, portno + 1);
- pd_list(sysexin_sym->s_thing, 0, 2, at);
+ SETFLOAT(at, byte);
+ SETFLOAT(at+1, portno + 1);
+ pd_list(sysexin_sym->s_thing, 0, 2, at);
}
}
@@ -138,15 +138,15 @@ static void notein_list(t_notein *x, t_symbol *s, int argc, t_atom *argv)
float channel = atom_getfloatarg(2, argc, argv);
if (x->x_channel != 0)
{
- if (channel != x->x_channel) return;
- outlet_float(x->x_outlet2, velo);
- outlet_float(x->x_outlet1, pitch);
+ if (channel != x->x_channel) return;
+ outlet_float(x->x_outlet2, velo);
+ outlet_float(x->x_outlet1, pitch);
}
else
{
- outlet_float(x->x_outlet3, channel);
- outlet_float(x->x_outlet2, velo);
- outlet_float(x->x_outlet1, pitch);
+ outlet_float(x->x_outlet3, channel);
+ outlet_float(x->x_outlet2, velo);
+ outlet_float(x->x_outlet1, pitch);
}
}
@@ -158,7 +158,7 @@ static void notein_free(t_notein *x)
static void notein_setup(void)
{
notein_class = class_new(gensym("notein"), (t_newmethod)notein_new,
- (t_method)notein_free, sizeof(t_notein), CLASS_NOINLET, A_DEFFLOAT, 0);
+ (t_method)notein_free, sizeof(t_notein), CLASS_NOINLET, A_DEFFLOAT, 0);
class_addlist(notein_class, notein_list);
class_sethelpsymbol(notein_class, gensym("midi"));
notein_sym = gensym("#notein");
@@ -168,11 +168,11 @@ void inmidi_noteon(int portno, int channel, int pitch, int velo)
{
if (notein_sym->s_thing)
{
- t_atom at[3];
- SETFLOAT(at, pitch);
- SETFLOAT(at+1, velo);
- SETFLOAT(at+2, (channel + (portno << 4) + 1));
- pd_list(notein_sym->s_thing, &s_list, 3, at);
+ t_atom at[3];
+ SETFLOAT(at, pitch);
+ SETFLOAT(at+1, velo);
+ SETFLOAT(at+2, (channel + (portno << 4) + 1));
+ pd_list(notein_sym->s_thing, &s_list, 3, at);
}
}
@@ -204,8 +204,8 @@ static void *ctlin_new(t_symbol *s, int argc, t_atom *argv)
x->x_outlet1 = outlet_new(&x->x_obj, &s_float);
if (!channel)
{
- if (x->x_ctlno < 0) x->x_outlet2 = outlet_new(&x->x_obj, &s_float);
- x->x_outlet3 = outlet_new(&x->x_obj, &s_float);
+ if (x->x_ctlno < 0) x->x_outlet2 = outlet_new(&x->x_obj, &s_float);
+ x->x_outlet3 = outlet_new(&x->x_obj, &s_float);
}
pd_bind(&x->x_obj.ob_pd, ctlin_sym);
return (x);
@@ -231,8 +231,8 @@ static void ctlin_free(t_ctlin *x)
static void ctlin_setup(void)
{
ctlin_class = class_new(gensym("ctlin"), (t_newmethod)ctlin_new,
- (t_method)ctlin_free, sizeof(t_ctlin),
- CLASS_NOINLET, A_GIMME, 0);
+ (t_method)ctlin_free, sizeof(t_ctlin),
+ CLASS_NOINLET, A_GIMME, 0);
class_addlist(ctlin_class, ctlin_list);
class_sethelpsymbol(ctlin_class, gensym("midi"));
ctlin_sym = gensym("#ctlin");
@@ -242,11 +242,11 @@ void inmidi_controlchange(int portno, int channel, int ctlnumber, int value)
{
if (ctlin_sym->s_thing)
{
- t_atom at[3];
- SETFLOAT(at, ctlnumber);
- SETFLOAT(at+1, value);
- SETFLOAT(at+2, (channel + (portno << 4) + 1));
- pd_list(ctlin_sym->s_thing, &s_list, 3, at);
+ t_atom at[3];
+ SETFLOAT(at, ctlnumber);
+ SETFLOAT(at+1, value);
+ SETFLOAT(at+2, (channel + (portno << 4) + 1));
+ pd_list(ctlin_sym->s_thing, &s_list, 3, at);
}
}
@@ -280,13 +280,13 @@ static void pgmin_list(t_pgmin *x, t_symbol *s, int argc, t_atom *argv)
float channel = atom_getfloatarg(1, argc, argv);
if (x->x_channel != 0)
{
- if (channel != x->x_channel) return;
- outlet_float(x->x_outlet1, value);
+ if (channel != x->x_channel) return;
+ outlet_float(x->x_outlet1, value);
}
else
{
- outlet_float(x->x_outlet2, channel);
- outlet_float(x->x_outlet1, value);
+ outlet_float(x->x_outlet2, channel);
+ outlet_float(x->x_outlet1, value);
}
}
@@ -298,8 +298,8 @@ static void pgmin_free(t_pgmin *x)
static void pgmin_setup(void)
{
pgmin_class = class_new(gensym("pgmin"), (t_newmethod)pgmin_new,
- (t_method)pgmin_free, sizeof(t_pgmin),
- CLASS_NOINLET, A_DEFFLOAT, 0);
+ (t_method)pgmin_free, sizeof(t_pgmin),
+ CLASS_NOINLET, A_DEFFLOAT, 0);
class_addlist(pgmin_class, pgmin_list);
class_sethelpsymbol(pgmin_class, gensym("midi"));
pgmin_sym = gensym("#pgmin");
@@ -309,10 +309,10 @@ void inmidi_programchange(int portno, int channel, int value)
{
if (pgmin_sym->s_thing)
{
- t_atom at[2];
- SETFLOAT(at, value + 1);
- SETFLOAT(at+1, (channel + (portno << 4) + 1));
- pd_list(pgmin_sym->s_thing, &s_list, 2, at);
+ t_atom at[2];
+ SETFLOAT(at, value + 1);
+ SETFLOAT(at+1, (channel + (portno << 4) + 1));
+ pd_list(pgmin_sym->s_thing, &s_list, 2, at);
}
}
@@ -346,13 +346,13 @@ static void bendin_list(t_bendin *x, t_symbol *s, int argc, t_atom *argv)
t_float channel = atom_getfloatarg(1, argc, argv);
if (x->x_channel != 0)
{
- if (channel != x->x_channel) return;
- outlet_float(x->x_outlet1, value);
+ if (channel != x->x_channel) return;
+ outlet_float(x->x_outlet1, value);
}
else
{
- outlet_float(x->x_outlet2, channel);
- outlet_float(x->x_outlet1, value);
+ outlet_float(x->x_outlet2, channel);
+ outlet_float(x->x_outlet1, value);
}
}
@@ -364,7 +364,7 @@ static void bendin_free(t_bendin *x)
static void bendin_setup(void)
{
bendin_class = class_new(gensym("bendin"), (t_newmethod)bendin_new,
- (t_method)bendin_free, sizeof(t_bendin), CLASS_NOINLET, A_DEFFLOAT, 0);
+ (t_method)bendin_free, sizeof(t_bendin), CLASS_NOINLET, A_DEFFLOAT, 0);
class_addlist(bendin_class, bendin_list);
class_sethelpsymbol(bendin_class, gensym("midi"));
bendin_sym = gensym("#bendin");
@@ -374,10 +374,10 @@ void inmidi_pitchbend(int portno, int channel, int value)
{
if (bendin_sym->s_thing)
{
- t_atom at[2];
- SETFLOAT(at, value);
- SETFLOAT(at+1, (channel + (portno << 4) + 1));
- pd_list(bendin_sym->s_thing, &s_list, 2, at);
+ t_atom at[2];
+ SETFLOAT(at, value);
+ SETFLOAT(at+1, (channel + (portno << 4) + 1));
+ pd_list(bendin_sym->s_thing, &s_list, 2, at);
}
}
@@ -411,13 +411,13 @@ static void touchin_list(t_touchin *x, t_symbol *s, int argc, t_atom *argv)
t_float channel = atom_getfloatarg(1, argc, argv);
if (x->x_channel)
{
- if (channel != x->x_channel) return;
- outlet_float(x->x_outlet1, value);
+ if (channel != x->x_channel) return;
+ outlet_float(x->x_outlet1, value);
}
else
{
- outlet_float(x->x_outlet2, channel);
- outlet_float(x->x_outlet1, value);
+ outlet_float(x->x_outlet2, channel);
+ outlet_float(x->x_outlet1, value);
}
}
@@ -429,8 +429,8 @@ static void touchin_free(t_touchin *x)
static void touchin_setup(void)
{
touchin_class = class_new(gensym("touchin"), (t_newmethod)touchin_new,
- (t_method)touchin_free, sizeof(t_touchin),
- CLASS_NOINLET, A_DEFFLOAT, 0);
+ (t_method)touchin_free, sizeof(t_touchin),
+ CLASS_NOINLET, A_DEFFLOAT, 0);
class_addlist(touchin_class, touchin_list);
class_sethelpsymbol(touchin_class, gensym("midi"));
touchin_sym = gensym("#touchin");
@@ -440,10 +440,10 @@ void inmidi_aftertouch(int portno, int channel, int value)
{
if (touchin_sym->s_thing)
{
- t_atom at[2];
- SETFLOAT(at, value);
- SETFLOAT(at+1, (channel + (portno << 4) + 1));
- pd_list(touchin_sym->s_thing, &s_list, 2, at);
+ t_atom at[2];
+ SETFLOAT(at, value);
+ SETFLOAT(at+1, (channel + (portno << 4) + 1));
+ pd_list(touchin_sym->s_thing, &s_list, 2, at);
}
}
@@ -481,15 +481,15 @@ static void polytouchin_list(t_polytouchin *x, t_symbol *s, int argc,
t_float channel = atom_getfloatarg(2, argc, argv);
if (x->x_channel != 0)
{
- if (channel != x->x_channel) return;
- outlet_float(x->x_outlet2, pitch);
- outlet_float(x->x_outlet1, value);
+ if (channel != x->x_channel) return;
+ outlet_float(x->x_outlet2, pitch);
+ outlet_float(x->x_outlet1, value);
}
else
{
- outlet_float(x->x_outlet3, channel);
- outlet_float(x->x_outlet2, pitch);
- outlet_float(x->x_outlet1, value);
+ outlet_float(x->x_outlet3, channel);
+ outlet_float(x->x_outlet2, pitch);
+ outlet_float(x->x_outlet1, value);
}
}
@@ -501,8 +501,8 @@ static void polytouchin_free(t_polytouchin *x)
static void polytouchin_setup(void)
{
polytouchin_class = class_new(gensym("polytouchin"),
- (t_newmethod)polytouchin_new, (t_method)polytouchin_free,
- sizeof(t_polytouchin), CLASS_NOINLET, A_DEFFLOAT, 0);
+ (t_newmethod)polytouchin_new, (t_method)polytouchin_free,
+ sizeof(t_polytouchin), CLASS_NOINLET, A_DEFFLOAT, 0);
class_addlist(polytouchin_class, polytouchin_list);
class_sethelpsymbol(polytouchin_class, gensym("midi"));
polytouchin_sym = gensym("#polytouchin");
@@ -512,11 +512,11 @@ void inmidi_polyaftertouch(int portno, int channel, int pitch, int value)
{
if (polytouchin_sym->s_thing)
{
- t_atom at[3];
- SETFLOAT(at, pitch);
- SETFLOAT(at+1, value);
- SETFLOAT(at+2, (channel + (portno << 4) + 1));
- pd_list(polytouchin_sym->s_thing, &s_list, 3, at);
+ t_atom at[3];
+ SETFLOAT(at, pitch);
+ SETFLOAT(at+1, value);
+ SETFLOAT(at+2, (channel + (portno << 4) + 1));
+ pd_list(polytouchin_sym->s_thing, &s_list, 3, at);
}
}
@@ -558,10 +558,10 @@ static void midiclkin_free(t_midiclkin *x)
static void midiclkin_setup(void)
{
midiclkin_class = class_new(gensym("midiclkin"),
- (t_newmethod)midiclkin_new, (t_method)midiclkin_free,
- sizeof(t_midiclkin), CLASS_NOINLET, A_DEFFLOAT, 0);
+ (t_newmethod)midiclkin_new, (t_method)midiclkin_free,
+ sizeof(t_midiclkin), CLASS_NOINLET, A_DEFFLOAT, 0);
class_addlist(midiclkin_class, midiclkin_list);
- class_sethelpsymbol(midiclkin_class, gensym("midi"));
+ class_sethelpsymbol(midiclkin_class, gensym("midi"));
midiclkin_sym = gensym("#midiclkin");
}
@@ -574,20 +574,20 @@ void inmidi_clk(double timing)
if (midiclkin_sym->s_thing)
{
- t_atom at[2];
- diff =timing - prev;
- count++;
+ t_atom at[2];
+ diff =timing - prev;
+ count++;
- if (count == 3)
- { /* 24 count per quoter note */
- SETFLOAT(at, 1 );
- count = 0;
- }
- else SETFLOAT(at, 0);
-
- SETFLOAT(at+1, diff);
- pd_list(midiclkin_sym->s_thing, &s_list, 2, at);
- prev = timing;
+ if (count == 3)
+ { /* 24 count per quoter note */
+ SETFLOAT(at, 1 );
+ count = 0;
+ }
+ else SETFLOAT(at, 0);
+
+ SETFLOAT(at+1, diff);
+ pd_list(midiclkin_sym->s_thing, &s_list, 2, at);
+ prev = timing;
}
}
@@ -634,10 +634,10 @@ static void midirealtimein_free(t_midirealtimein *x)
static void midirealtimein_setup(void)
{
midirealtimein_class = class_new(gensym("midirealtimein"),
- (t_newmethod)midirealtimein_new, (t_method)midirealtimein_free,
- sizeof(t_midirealtimein), CLASS_NOINLET, A_DEFFLOAT, 0);
+ (t_newmethod)midirealtimein_new, (t_method)midirealtimein_free,
+ sizeof(t_midirealtimein), CLASS_NOINLET, A_DEFFLOAT, 0);
class_addlist(midirealtimein_class, midirealtimein_list);
- class_sethelpsymbol(midirealtimein_class, gensym("midi"));
+ class_sethelpsymbol(midirealtimein_class, gensym("midi"));
midirealtimein_sym = gensym("#midirealtimein");
}
@@ -645,10 +645,10 @@ void inmidi_realtimein(int portno, int SysMsg)
{
if (midirealtimein_sym->s_thing)
{
- t_atom at[2];
- SETFLOAT(at, portno);
- SETFLOAT(at+1, SysMsg);
- pd_list(midirealtimein_sym->s_thing, &s_list, 1, at);
+ t_atom at[2];
+ SETFLOAT(at, portno);
+ SETFLOAT(at+1, SysMsg);
+ pd_list(midirealtimein_sym->s_thing, &s_list, 1, at);
}
}
@@ -684,7 +684,7 @@ static void midiout_float(t_midiout *x, t_floatarg f)
static void midiout_setup(void)
{
midiout_class = class_new(gensym("midiout"), (t_newmethod)midiout_new, 0,
- sizeof(t_midiout), 0, A_DEFFLOAT, A_DEFFLOAT, 0);
+ sizeof(t_midiout), 0, A_DEFFLOAT, A_DEFFLOAT, 0);
class_addfloat(midiout_class, midiout_float);
class_sethelpsymbol(midiout_class, gensym("midi"));
}
@@ -715,15 +715,15 @@ static void noteout_float(t_noteout *x, t_float f)
{
int binchan = x->x_channel - 1;
if (binchan < 0)
- binchan = 0;
+ binchan = 0;
outmidi_noteon((binchan >> 4),
- (binchan & 15), (int)f, (int)x->x_velo);
+ (binchan & 15), (int)f, (int)x->x_velo);
}
static void noteout_setup(void)
{
noteout_class = class_new(gensym("noteout"), (t_newmethod)noteout_new, 0,
- sizeof(t_noteout), 0, A_DEFFLOAT, 0);
+ sizeof(t_noteout), 0, A_DEFFLOAT, 0);
class_addfloat(noteout_class, noteout_float);
class_sethelpsymbol(noteout_class, gensym("midi"));
}
@@ -755,15 +755,15 @@ static void ctlout_float(t_ctlout *x, t_float f)
{
int binchan = x->x_channel - 1;
if (binchan < 0)
- binchan = 0;
+ binchan = 0;
outmidi_controlchange((binchan >> 4),
- (binchan & 15), (int)(x->x_ctl), (int)f);
+ (binchan & 15), (int)(x->x_ctl), (int)f);
}
static void ctlout_setup(void)
{
ctlout_class = class_new(gensym("ctlout"), (t_newmethod)ctlout_new, 0,
- sizeof(t_ctlout), 0, A_DEFFLOAT, A_DEFFLOAT, 0);
+ sizeof(t_ctlout), 0, A_DEFFLOAT, A_DEFFLOAT, 0);
class_addfloat(ctlout_class, ctlout_float);
class_sethelpsymbol(ctlout_class, gensym("midi"));
}
@@ -793,17 +793,17 @@ static void pgmout_float(t_pgmout *x, t_floatarg f)
int binchan = x->x_channel - 1;
int n = f - 1;
if (binchan < 0)
- binchan = 0;
+ binchan = 0;
if (n < 0) n = 0;
else if (n > 127) n = 127;
outmidi_programchange((binchan >> 4),
- (binchan & 15), n);
+ (binchan & 15), n);
}
static void pgmout_setup(void)
{
pgmout_class = class_new(gensym("pgmout"), (t_newmethod)pgmout_new, 0,
- sizeof(t_pgmout), 0, A_DEFFLOAT, 0);
+ sizeof(t_pgmout), 0, A_DEFFLOAT, 0);
class_addfloat(pgmout_class, pgmout_float);
class_sethelpsymbol(pgmout_class, gensym("midi"));
}
@@ -833,14 +833,14 @@ static void bendout_float(t_bendout *x, t_float f)
int binchan = x->x_channel - 1;
int n = (int)f + 8192;
if (binchan < 0)
- binchan = 0;
+ binchan = 0;
outmidi_pitchbend((binchan >> 4), (binchan & 15), n);
}
static void bendout_setup(void)
{
bendout_class = class_new(gensym("bendout"), (t_newmethod)bendout_new, 0,
- sizeof(t_bendout), 0, A_DEFFLOAT, 0);
+ sizeof(t_bendout), 0, A_DEFFLOAT, 0);
class_addfloat(bendout_class, bendout_float);
class_sethelpsymbol(bendout_class, gensym("midi"));
}
@@ -868,14 +868,14 @@ static void touchout_float(t_touchout *x, t_float f)
{
int binchan = x->x_channel - 1;
if (binchan < 0)
- binchan = 0;
+ binchan = 0;
outmidi_aftertouch((binchan >> 4), (binchan & 15), (int)f);
}
static void touchout_setup(void)
{
touchout_class = class_new(gensym("touchout"), (t_newmethod)touchout_new, 0,
- sizeof(t_touchout), 0, A_DEFFLOAT, 0);
+ sizeof(t_touchout), 0, A_DEFFLOAT, 0);
class_addfloat(touchout_class, touchout_float);
class_sethelpsymbol(touchout_class, gensym("midi"));
}
@@ -906,15 +906,15 @@ static void polytouchout_float(t_polytouchout *x, t_float n)
{
int binchan = x->x_channel - 1;
if (binchan < 0)
- binchan = 0;
+ binchan = 0;
outmidi_polyaftertouch((binchan >> 4), (binchan & 15), x->x_pitch, n);
}
static void polytouchout_setup(void)
{
polytouchout_class = class_new(gensym("polytouchout"),
- (t_newmethod)polytouchout_new, 0,
- sizeof(t_polytouchout), 0, A_DEFFLOAT, 0);
+ (t_newmethod)polytouchout_new, 0,
+ sizeof(t_polytouchout), 0, A_DEFFLOAT, 0);
class_addfloat(polytouchout_class, polytouchout_float);
class_sethelpsymbol(polytouchout_class, gensym("midi"));
}
@@ -963,11 +963,11 @@ static void makenote_tick(t_hang *hang)
if (x->x_hang == hang) x->x_hang = hang->h_next;
else for (h2 = x->x_hang; h3 = h2->h_next; h2 = h3)
{
- if (h3 == hang)
- {
- h2->h_next = h3->h_next;
- break;
- }
+ if (h3 == hang)
+ {
+ h2->h_next = h3->h_next;
+ break;
+ }
}
clock_free(hang->h_clock);
freebytes(hang, sizeof(*hang));
@@ -993,11 +993,11 @@ static void makenote_stop(t_makenote *x)
t_hang *hang;
while (hang = x->x_hang)
{
- outlet_float(x->x_velout, 0);
- outlet_float(x->x_pitchout, hang->h_pitch);
- x->x_hang = hang->h_next;
- clock_free(hang->h_clock);
- freebytes(hang, sizeof(*hang));
+ outlet_float(x->x_velout, 0);
+ outlet_float(x->x_pitchout, hang->h_pitch);
+ x->x_hang = hang->h_next;
+ clock_free(hang->h_clock);
+ freebytes(hang, sizeof(*hang));
}
}
@@ -1006,22 +1006,22 @@ static void makenote_clear(t_makenote *x)
t_hang *hang;
while (hang = x->x_hang)
{
- x->x_hang = hang->h_next;
- clock_free(hang->h_clock);
- freebytes(hang, sizeof(*hang));
+ x->x_hang = hang->h_next;
+ clock_free(hang->h_clock);
+ freebytes(hang, sizeof(*hang));
}
}
static void makenote_setup(void)
{
makenote_class = class_new(gensym("makenote"),
- (t_newmethod)makenote_new, (t_method)makenote_clear,
- sizeof(t_makenote), 0, A_DEFFLOAT, A_DEFFLOAT, 0);
+ (t_newmethod)makenote_new, (t_method)makenote_clear,
+ sizeof(t_makenote), 0, A_DEFFLOAT, A_DEFFLOAT, 0);
class_addfloat(makenote_class, makenote_float);
class_addmethod(makenote_class, (t_method)makenote_stop, gensym("stop"),
- 0);
+ 0);
class_addmethod(makenote_class, (t_method)makenote_clear, gensym("clear"),
- 0);
+ 0);
}
/* -------------------------- stripnote -------------------------- */
@@ -1056,7 +1056,7 @@ static void stripnote_float(t_stripnote *x, t_float f)
static void stripnote_setup(void)
{
stripnote_class = class_new(gensym("stripnote"),
- (t_newmethod)stripnote_new, 0, sizeof(t_stripnote), 0, 0);
+ (t_newmethod)stripnote_new, 0, sizeof(t_stripnote), 0, 0);
class_addfloat(stripnote_class, stripnote_float);
}
@@ -1092,7 +1092,7 @@ static void *poly_new(float fnvoice, float fsteal)
x->x_n = n;
x->x_vec = (t_voice *)getbytes(n * sizeof(*x->x_vec));
for (v = x->x_vec, i = n; i--; v++)
- v->v_pitch = v->v_used = v->v_serial = 0;
+ v->v_pitch = v->v_used = v->v_serial = 0;
x->x_vel = 0;
x->x_steal = (fsteal != 0);
floatinlet_new(&x->x_obj, &x->x_vel);
@@ -1111,49 +1111,49 @@ static void poly_float(t_poly *x, t_float f)
unsigned int serialon, serialoff, onindex = 0, offindex = 0;
if (x->x_vel > 0)
{
- /* note on. Look for a vacant voice */
- for (v = x->x_vec, i = 0, firston = firstoff = 0,
- serialon = serialoff = 0xffffffff; i < x->x_n; v++, i++)
- {
- if (v->v_used && v->v_serial < serialon)
- firston = v, serialon = v->v_serial, onindex = i;
- else if (!v->v_used && v->v_serial < serialoff)
- firstoff = v, serialoff = v->v_serial, offindex = i;
- }
- if (firstoff)
- {
- outlet_float(x->x_velout, x->x_vel);
- outlet_float(x->x_pitchout, firstoff->v_pitch = f);
- outlet_float(x->x_obj.ob_outlet, offindex+1);
- firstoff->v_used = 1;
- firstoff->v_serial = x->x_serial++;
- }
- /* if none, steal one */
- else if (firston && x->x_steal)
- {
- outlet_float(x->x_velout, 0);
- outlet_float(x->x_pitchout, firston->v_pitch);
- outlet_float(x->x_obj.ob_outlet, onindex+1);
- outlet_float(x->x_velout, x->x_vel);
- outlet_float(x->x_pitchout, firston->v_pitch = f);
- outlet_float(x->x_obj.ob_outlet, onindex+1);
- firston->v_serial = x->x_serial++;
- }
+ /* note on. Look for a vacant voice */
+ for (v = x->x_vec, i = 0, firston = firstoff = 0,
+ serialon = serialoff = 0xffffffff; i < x->x_n; v++, i++)
+ {
+ if (v->v_used && v->v_serial < serialon)
+ firston = v, serialon = v->v_serial, onindex = i;
+ else if (!v->v_used && v->v_serial < serialoff)
+ firstoff = v, serialoff = v->v_serial, offindex = i;
+ }
+ if (firstoff)
+ {
+ outlet_float(x->x_velout, x->x_vel);
+ outlet_float(x->x_pitchout, firstoff->v_pitch = f);
+ outlet_float(x->x_obj.ob_outlet, offindex+1);
+ firstoff->v_used = 1;
+ firstoff->v_serial = x->x_serial++;
+ }
+ /* if none, steal one */
+ else if (firston && x->x_steal)
+ {
+ outlet_float(x->x_velout, 0);
+ outlet_float(x->x_pitchout, firston->v_pitch);
+ outlet_float(x->x_obj.ob_outlet, onindex+1);
+ outlet_float(x->x_velout, x->x_vel);
+ outlet_float(x->x_pitchout, firston->v_pitch = f);
+ outlet_float(x->x_obj.ob_outlet, onindex+1);
+ firston->v_serial = x->x_serial++;
+ }
}
else /* note off. Turn off oldest match */
{
- for (v = x->x_vec, i = 0, firston = 0, serialon = 0xffffffff;
- i < x->x_n; v++, i++)
- if (v->v_used && v->v_pitch == f && v->v_serial < serialon)
- firston = v, serialon = v->v_serial, onindex = i;
- if (firston)
- {
- firston->v_used = 0;
- firston->v_serial = x->x_serial++;
- outlet_float(x->x_velout, 0);
- outlet_float(x->x_pitchout, firston->v_pitch);
- outlet_float(x->x_obj.ob_outlet, onindex+1);
- }
+ for (v = x->x_vec, i = 0, firston = 0, serialon = 0xffffffff;
+ i < x->x_n; v++, i++)
+ if (v->v_used && v->v_pitch == f && v->v_serial < serialon)
+ firston = v, serialon = v->v_serial, onindex = i;
+ if (firston)
+ {
+ firston->v_used = 0;
+ firston->v_serial = x->x_serial++;
+ outlet_float(x->x_velout, 0);
+ outlet_float(x->x_pitchout, firston->v_pitch);
+ outlet_float(x->x_obj.ob_outlet, onindex+1);
+ }
}
}
@@ -1162,13 +1162,13 @@ static void poly_stop(t_poly *x)
int i;
t_voice *v;
for (i = 0, v = x->x_vec; i < x->x_n; i++, v++)
- if (v->v_used)
+ if (v->v_used)
{
- outlet_float(x->x_velout, 0L);
- outlet_float(x->x_pitchout, v->v_pitch);
- outlet_float(x->x_obj.ob_outlet, i+1);
- v->v_used = 0;
- v->v_serial = x->x_serial++;
+ outlet_float(x->x_velout, 0L);
+ outlet_float(x->x_pitchout, v->v_pitch);
+ outlet_float(x->x_obj.ob_outlet, i+1);
+ v->v_used = 0;
+ v->v_serial = x->x_serial++;
}
}
@@ -1187,8 +1187,8 @@ static void poly_free(t_poly *x)
static void poly_setup(void)
{
poly_class = class_new(gensym("poly"),
- (t_newmethod)poly_new, (t_method)poly_clear,
- sizeof(t_poly), 0, A_DEFFLOAT, A_DEFFLOAT, 0);
+ (t_newmethod)poly_new, (t_method)poly_clear,
+ sizeof(t_poly), 0, A_DEFFLOAT, A_DEFFLOAT, 0);
class_addfloat(poly_class, poly_float);
class_addmethod(poly_class, (t_method)poly_stop, gensym("stop"), 0);
class_addmethod(poly_class, (t_method)poly_clear, gensym("clear"), 0);
@@ -1226,34 +1226,34 @@ static void bag_float(t_bag *x, t_float f)
t_bagelem *bagelem, *e2, *e3;
if (x->x_velo != 0)
{
- bagelem = (t_bagelem *)getbytes(sizeof *bagelem);
- bagelem->e_next = 0;
- bagelem->e_value = f;
- if (!x->x_first) x->x_first = bagelem;
- else /* LATER replace with a faster algorithm */
- {
- for (e2 = x->x_first; e3 = e2->e_next; e2 = e3)
- ;
- e2->e_next = bagelem;
- }
+ bagelem = (t_bagelem *)getbytes(sizeof *bagelem);
+ bagelem->e_next = 0;
+ bagelem->e_value = f;
+ if (!x->x_first) x->x_first = bagelem;
+ else /* LATER replace with a faster algorithm */
+ {
+ for (e2 = x->x_first; e3 = e2->e_next; e2 = e3)
+ ;
+ e2->e_next = bagelem;
+ }
}
else
{
- if (!x->x_first) return;
- if (x->x_first->e_value == f)
- {
- bagelem = x->x_first;
- x->x_first = x->x_first->e_next;
- freebytes(bagelem, sizeof(*bagelem));
- return;
- }
- for (e2 = x->x_first; e3 = e2->e_next; e2 = e3)
- if (e3->e_value == f)
- {
- e2->e_next = e3->e_next;
- freebytes(e3, sizeof(*e3));
- return;
- }
+ if (!x->x_first) return;
+ if (x->x_first->e_value == f)
+ {
+ bagelem = x->x_first;
+ x->x_first = x->x_first->e_next;
+ freebytes(bagelem, sizeof(*bagelem));
+ return;
+ }
+ for (e2 = x->x_first; e3 = e2->e_next; e2 = e3)
+ if (e3->e_value == f)
+ {
+ e2->e_next = e3->e_next;
+ freebytes(e3, sizeof(*e3));
+ return;
+ }
}
}
@@ -1262,9 +1262,9 @@ static void bag_flush(t_bag *x)
t_bagelem *bagelem;
while (bagelem = x->x_first)
{
- outlet_float(x->x_obj.ob_outlet, bagelem->e_value);
- x->x_first = bagelem->e_next;
- freebytes(bagelem, sizeof(*bagelem));
+ outlet_float(x->x_obj.ob_outlet, bagelem->e_value);
+ x->x_first = bagelem->e_next;
+ freebytes(bagelem, sizeof(*bagelem));
}
}
@@ -1273,16 +1273,16 @@ static void bag_clear(t_bag *x)
t_bagelem *bagelem;
while (bagelem = x->x_first)
{
- x->x_first = bagelem->e_next;
- freebytes(bagelem, sizeof(*bagelem));
+ x->x_first = bagelem->e_next;
+ freebytes(bagelem, sizeof(*bagelem));
}
}
static void bag_setup(void)
{
bag_class = class_new(gensym("bag"),
- (t_newmethod)bag_new, (t_method)bag_clear,
- sizeof(t_bag), 0, 0);
+ (t_newmethod)bag_new, (t_method)bag_clear,
+ sizeof(t_bag), 0, 0);
class_addfloat(bag_class, bag_float);
class_addmethod(bag_class, (t_method)bag_flush, gensym("flush"), 0);
class_addmethod(bag_class, (t_method)bag_clear, gensym("clear"), 0);
diff --git a/pd/src/x_misc.c b/pd/src/x_misc.c
index cd9771b0..0facd6b8 100644
--- a/pd/src/x_misc.c
+++ b/pd/src/x_misc.c
@@ -9,11 +9,12 @@
#include <math.h>
#include <stdio.h>
#include <string.h>
-#ifdef UNIX
+#ifdef UNISTD
#include <sys/types.h>
#include <sys/time.h>
#include <sys/times.h>
#include <sys/param.h>
+#include <unistd.h>
#endif
#ifdef MSW
#include <wtypes.h>
@@ -61,7 +62,7 @@ static void random_bang(t_random *x)
unsigned int randval = x->x_state;
x->x_state = randval = randval * 472940017 + 832416023;
nval = ((double)range) * ((double)randval)
- * (1./4294967296.);
+ * (1./4294967296.);
if (nval >= range) nval = range-1;
outlet_float(x->x_obj.ob_outlet, nval);
}
@@ -74,10 +75,10 @@ static void random_seed(t_random *x, float f, float glob)
static void random_setup(void)
{
random_class = class_new(gensym("random"), (t_newmethod)random_new, 0,
- sizeof(t_random), 0, A_DEFFLOAT, 0);
+ sizeof(t_random), 0, A_DEFFLOAT, 0);
class_addbang(random_class, random_bang);
class_addmethod(random_class, (t_method)random_seed,
- gensym("seed"), A_FLOAT, 0);
+ gensym("seed"), A_FLOAT, 0);
}
@@ -99,15 +100,15 @@ static void *loadbang_new(void)
static void loadbang_loadbang(t_loadbang *x)
{
if (!sys_noloadbang)
- outlet_bang(x->x_obj.ob_outlet);
+ outlet_bang(x->x_obj.ob_outlet);
}
static void loadbang_setup(void)
{
loadbang_class = class_new(gensym("loadbang"), (t_newmethod)loadbang_new, 0,
- sizeof(t_loadbang), 0, 0);
+ sizeof(t_loadbang), CLASS_NOINLET, 0);
class_addmethod(loadbang_class, (t_method)loadbang_loadbang,
- gensym("loadbang"), 0);
+ gensym("loadbang"), 0);
}
/* ------------- namecanvas (delete this later) --------------------- */
@@ -137,8 +138,8 @@ static void namecanvas_free(t_namecanvas *x)
static void namecanvas_setup(void)
{
namecanvas_class = class_new(gensym("namecanvas"),
- (t_newmethod)namecanvas_new, (t_method)namecanvas_free,
- sizeof(t_namecanvas), CLASS_NOINLET, A_DEFSYM, 0);
+ (t_newmethod)namecanvas_new, (t_method)namecanvas_free,
+ sizeof(t_namecanvas), CLASS_NOINLET, A_DEFSYM, 0);
}
/* ---------------serial ports (MSW only -- hack) ------------------------- */
@@ -159,8 +160,8 @@ static void serial_float(t_serial *x, t_float f)
char message[MAXSERIAL * 4 + 100];
if (!x->x_open)
{
- sys_vgui("com%d_open\n", x->x_portno);
- x->x_open = 1;
+ sys_vgui("com%d_open\n", x->x_portno);
+ x->x_open = 1;
}
sprintf(message, "com%d_send \"\\%3.3o\"\n", x->x_portno, n);
sys_gui(message);
@@ -179,7 +180,7 @@ static void *serial_new(t_floatarg fportno)
static void serial_setup(void)
{
serial_class = class_new(gensym("serial"), (t_newmethod)serial_new, 0,
- sizeof(t_serial), 0, A_DEFFLOAT, 0);
+ sizeof(t_serial), 0, A_DEFFLOAT, 0);
class_addfloat(serial_class, serial_float);
}
@@ -190,7 +191,7 @@ static t_class *cputime_class;
typedef struct _cputime
{
t_object x_obj;
-#ifdef UNIX
+#ifdef UNISTD
struct tms x_setcputime;
#endif
#ifdef MSW
@@ -202,34 +203,34 @@ typedef struct _cputime
static void cputime_bang(t_cputime *x)
{
-#ifdef UNIX
+#ifdef UNISTD
times(&x->x_setcputime);
#endif
#ifdef MSW
FILETIME ignorethis, ignorethat;
BOOL retval;
retval = GetProcessTimes(GetCurrentProcess(), &ignorethis, &ignorethat,
- (FILETIME *)&x->x_kerneltime, (FILETIME *)&x->x_usertime);
+ (FILETIME *)&x->x_kerneltime, (FILETIME *)&x->x_usertime);
if (!retval)
{
- if (!x->x_warned)
- post("cputime is apparently not supported on your platform");
- x->x_warned = 1;
- x->x_kerneltime.QuadPart = 0;
- x->x_usertime.QuadPart = 0;
+ if (!x->x_warned)
+ post("cputime is apparently not supported on your platform");
+ x->x_warned = 1;
+ x->x_kerneltime.QuadPart = 0;
+ x->x_usertime.QuadPart = 0;
}
#endif
}
static void cputime_bang2(t_cputime *x)
{
-#ifdef UNIX
+#ifdef UNISTD
float elapsedcpu;
struct tms newcputime;
times(&newcputime);
elapsedcpu = 1000 * (
- newcputime.tms_utime + newcputime.tms_stime -
- x->x_setcputime.tms_utime - x->x_setcputime.tms_stime) / HZ;
+ newcputime.tms_utime + newcputime.tms_stime -
+ x->x_setcputime.tms_utime - x->x_setcputime.tms_stime) / HZ;
outlet_float(x->x_obj.ob_outlet, elapsedcpu);
#endif
#ifdef MSW
@@ -239,11 +240,11 @@ static void cputime_bang2(t_cputime *x)
BOOL retval;
retval = GetProcessTimes(GetCurrentProcess(), &ignorethis, &ignorethat,
- (FILETIME *)&kerneltime, (FILETIME *)&usertime);
+ (FILETIME *)&kerneltime, (FILETIME *)&usertime);
if (retval)
- elapsedcpu = 0.0001 *
- ((kerneltime.QuadPart - x->x_kerneltime.QuadPart) +
- (usertime.QuadPart - x->x_usertime.QuadPart));
+ elapsedcpu = 0.0001 *
+ ((kerneltime.QuadPart - x->x_kerneltime.QuadPart) +
+ (usertime.QuadPart - x->x_usertime.QuadPart));
else elapsedcpu = 0;
outlet_float(x->x_obj.ob_outlet, elapsedcpu);
#endif
@@ -265,7 +266,7 @@ static void *cputime_new(void)
static void cputime_setup(void)
{
cputime_class = class_new(gensym("cputime"), (t_newmethod)cputime_new, 0,
- sizeof(t_cputime), 0, 0);
+ sizeof(t_cputime), 0, 0);
class_addbang(cputime_class, cputime_bang);
class_addmethod(cputime_class, (t_method)cputime_bang2, gensym("bang2"), 0);
}
@@ -288,7 +289,7 @@ static void realtime_bang(t_realtime *x)
static void realtime_bang2(t_realtime *x)
{
outlet_float(x->x_obj.ob_outlet,
- (sys_getrealtime() - x->x_setrealtime) * 1000.);
+ (sys_getrealtime() - x->x_setrealtime) * 1000.);
}
static void *realtime_new(void)
@@ -303,10 +304,10 @@ static void *realtime_new(void)
static void realtime_setup(void)
{
realtime_class = class_new(gensym("realtime"), (t_newmethod)realtime_new, 0,
- sizeof(t_realtime), 0, 0);
+ sizeof(t_realtime), 0, 0);
class_addbang(realtime_class, realtime_bang);
class_addmethod(realtime_class, (t_method)realtime_bang2, gensym("bang2"),
- 0);
+ 0);
}
void x_misc_setup(void)
diff --git a/pd/src/x_net.c b/pd/src/x_net.c
index 416b5bc6..7fc7ce6a 100644
--- a/pd/src/x_net.c
+++ b/pd/src/x_net.c
@@ -9,15 +9,15 @@
#include <sys/types.h>
#include <string.h>
-#ifdef UNIX
+#ifdef MSW
+#include <winsock.h>
+#else
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <netdb.h>
#include <stdio.h>
#define SOCKET_ERROR -1
-#else
-#include <winsock.h>
#endif
static t_class *netsend_class;
@@ -48,41 +48,41 @@ static void netsend_connect(t_netsend *x, t_symbol *hostname,
int intarg;
if (x->x_fd >= 0)
{
- error("netsend_connect: already connected");
- return;
+ error("netsend_connect: already connected");
+ return;
}
- /* create a socket */
+ /* create a socket */
sockfd = socket(AF_INET, x->x_protocol, 0);
#if 0
fprintf(stderr, "send socket %d\n", sockfd);
#endif
if (sockfd < 0)
{
- sys_sockerror("socket");
- return;
+ sys_sockerror("socket");
+ return;
}
/* connect socket using hostname provided in command line */
server.sin_family = AF_INET;
hp = gethostbyname(hostname->s_name);
if (hp == 0)
{
- post("bad host?\n");
- return;
+ post("bad host?\n");
+ return;
}
#if 0
intarg = 0;
if (setsockopt(sockfd, SOL_SOCKET, SO_SNDBUF,
- &intarg, sizeof(intarg)) < 0)
- post("setsockopt (SO_RCVBUF) failed\n");
+ &intarg, sizeof(intarg)) < 0)
+ post("setsockopt (SO_RCVBUF) failed\n");
#endif
- /* for stream (TCP) sockets, specify "nodelay" */
+ /* for stream (TCP) sockets, specify "nodelay" */
if (x->x_protocol == SOCK_STREAM)
{
- intarg = 1;
- if (setsockopt(sockfd, IPPROTO_TCP, TCP_NODELAY,
- &intarg, sizeof(intarg)) < 0)
- post("setsockopt (TCP_NODELAY) failed\n");
+ intarg = 1;
+ if (setsockopt(sockfd, IPPROTO_TCP, TCP_NODELAY,
+ &intarg, sizeof(intarg)) < 0)
+ post("setsockopt (TCP_NODELAY) failed\n");
}
memcpy((char *)&server.sin_addr, (char *)hp->h_addr, hp->h_length);
@@ -90,13 +90,13 @@ static void netsend_connect(t_netsend *x, t_symbol *hostname,
server.sin_port = htons((u_short)portno);
post("connecting to port %d", portno);
- /* try to connect. LATER make a separate thread to do this
- because it might block */
+ /* try to connect. LATER make a separate thread to do this
+ because it might block */
if (connect(sockfd, (struct sockaddr *) &server, sizeof (server)) < 0)
{
- sys_sockerror("connecting stream socket");
- sys_closesocket(sockfd);
- return;
+ sys_sockerror("connecting stream socket");
+ sys_closesocket(sockfd);
+ return;
}
x->x_fd = sockfd;
outlet_float(x->x_obj.ob_outlet, 1);
@@ -106,9 +106,9 @@ static void netsend_disconnect(t_netsend *x)
{
if (x->x_fd >= 0)
{
- sys_closesocket(x->x_fd);
- x->x_fd = -1;
- outlet_float(x->x_obj.ob_outlet, 0);
+ sys_closesocket(x->x_fd);
+ x->x_fd = -1;
+ outlet_float(x->x_obj.ob_outlet, 0);
}
}
@@ -116,47 +116,47 @@ static void netsend_send(t_netsend *x, t_symbol *s, int argc, t_atom *argv)
{
if (x->x_fd >= 0)
{
- t_binbuf *b = binbuf_new();
- char *buf, *bp;
- int length, sent;
- t_atom at;
- binbuf_add(b, argc, argv);
- SETSEMI(&at);
- binbuf_add(b, 1, &at);
- binbuf_gettext(b, &buf, &length);
- for (bp = buf, sent = 0; sent < length;)
- {
- static double lastwarntime;
- static double pleasewarn;
- double timebefore = sys_getrealtime();
- int res = send(x->x_fd, buf, length-sent, 0);
- double timeafter = sys_getrealtime();
- int late = (timeafter - timebefore > 0.005);
- if (late || pleasewarn)
- {
- if (timeafter > lastwarntime + 2)
- {
- post("netsend blocked %d msec",
- (int)(1000 * ((timeafter - timebefore) + pleasewarn)));
- pleasewarn = 0;
- lastwarntime = timeafter;
- }
- else if (late) pleasewarn += timeafter - timebefore;
- }
- if (res <= 0)
- {
- sys_sockerror("netsend");
- netsend_disconnect(x);
- break;
- }
- else
- {
- sent += res;
- bp += res;
- }
- }
- t_freebytes(buf, length);
- binbuf_free(b);
+ t_binbuf *b = binbuf_new();
+ char *buf, *bp;
+ int length, sent;
+ t_atom at;
+ binbuf_add(b, argc, argv);
+ SETSEMI(&at);
+ binbuf_add(b, 1, &at);
+ binbuf_gettext(b, &buf, &length);
+ for (bp = buf, sent = 0; sent < length;)
+ {
+ static double lastwarntime;
+ static double pleasewarn;
+ double timebefore = sys_getrealtime();
+ int res = send(x->x_fd, buf, length-sent, 0);
+ double timeafter = sys_getrealtime();
+ int late = (timeafter - timebefore > 0.005);
+ if (late || pleasewarn)
+ {
+ if (timeafter > lastwarntime + 2)
+ {
+ post("netsend blocked %d msec",
+ (int)(1000 * ((timeafter - timebefore) + pleasewarn)));
+ pleasewarn = 0;
+ lastwarntime = timeafter;
+ }
+ else if (late) pleasewarn += timeafter - timebefore;
+ }
+ if (res <= 0)
+ {
+ sys_sockerror("netsend");
+ netsend_disconnect(x);
+ break;
+ }
+ else
+ {
+ sent += res;
+ bp += res;
+ }
+ }
+ t_freebytes(buf, length);
+ binbuf_free(b);
}
else error("netsend: not connected");
}
@@ -169,14 +169,14 @@ static void netsend_free(t_netsend *x)
static void netsend_setup(void)
{
netsend_class = class_new(gensym("netsend"), (t_newmethod)netsend_new,
- (t_method)netsend_free,
- sizeof(t_netsend), 0, A_DEFFLOAT, 0);
+ (t_method)netsend_free,
+ sizeof(t_netsend), 0, A_DEFFLOAT, 0);
class_addmethod(netsend_class, (t_method)netsend_connect,
- gensym("connect"), A_SYMBOL, A_FLOAT, 0);
+ gensym("connect"), A_SYMBOL, A_FLOAT, 0);
class_addmethod(netsend_class, (t_method)netsend_disconnect,
- gensym("disconnect"), 0);
+ gensym("disconnect"), 0);
class_addmethod(netsend_class, (t_method)netsend_send, gensym("send"),
- A_GIMME, 0);
+ A_GIMME, 0);
}
/* ----------------------------- netreceive ------------------------- */
@@ -206,31 +206,31 @@ static void netreceive_doit(void *z, t_binbuf *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_msgout, 0, emsg-msg, at + msg);
- else outlet_float(x->x_msgout, at[msg].a_w.w_float);
- }
- else if (at[msg].a_type == A_SYMBOL)
- outlet_anything(x->x_msgout, at[msg].a_w.w_symbol,
- emsg-msg-1, at + msg + 1);
- }
+ 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_msgout, 0, emsg-msg, at + msg);
+ else outlet_float(x->x_msgout, at[msg].a_w.w_float);
+ }
+ else if (at[msg].a_type == A_SYMBOL)
+ outlet_anything(x->x_msgout, at[msg].a_w.w_symbol,
+ emsg-msg-1, at + msg + 1);
+ }
nodice:
- msg = emsg + 1;
+ msg = emsg + 1;
}
}
@@ -240,11 +240,11 @@ static void netreceive_connectpoll(t_netreceive *x)
if (fd < 0) post("netreceive: accept failed");
else
{
- t_socketreceiver *y = socketreceiver_new((void *)x,
- (t_socketnotifier)netreceive_notify,
- (x->x_msgout ? netreceive_doit : 0), 0);
- sys_addpollfn(fd, (t_fdpollfn)socketreceiver_read, y);
- outlet_float(x->x_connectout, ++x->x_nconnections);
+ t_socketreceiver *y = socketreceiver_new((void *)x,
+ (t_socketnotifier)netreceive_notify,
+ (x->x_msgout ? netreceive_doit : 0), 0);
+ sys_addpollfn(fd, (t_fdpollfn)socketreceiver_read, y);
+ outlet_float(x->x_connectout, ++x->x_nconnections);
}
}
@@ -256,79 +256,79 @@ static void *netreceive_new(t_symbol *compatflag,
int sockfd, portno = fportno, udp = (udpflag != 0);
int old = !strcmp(compatflag->s_name , "old");
int intarg;
- /* create a socket */
+ /* create a socket */
sockfd = socket(AF_INET, (udp ? SOCK_DGRAM : SOCK_STREAM), 0);
#if 0
fprintf(stderr, "receive socket %d\n", sockfd);
#endif
if (sockfd < 0)
{
- sys_sockerror("socket");
- return (0);
+ sys_sockerror("socket");
+ return (0);
}
server.sin_family = AF_INET;
server.sin_addr.s_addr = INADDR_ANY;
#if 1
- /* ask OS to allow another Pd to repoen this port after we close it. */
+ /* ask OS to allow another Pd to repoen this port after we close it. */
intarg = 1;
if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR,
- &intarg, sizeof(intarg)) < 0)
- post("setsockopt (SO_REUSEADDR) failed\n");
+ &intarg, sizeof(intarg)) < 0)
+ post("setsockopt (SO_REUSEADDR) failed\n");
#endif
#if 0
intarg = 0;
if (setsockopt(sockfd, SOL_SOCKET, SO_RCVBUF,
- &intarg, sizeof(intarg)) < 0)
- post("setsockopt (SO_RCVBUF) failed\n");
+ &intarg, sizeof(intarg)) < 0)
+ post("setsockopt (SO_RCVBUF) failed\n");
#endif
- /* Stream (TCP) sockets are set NODELAY */
+ /* Stream (TCP) sockets are set NODELAY */
if (!udp)
{
- intarg = 1;
- if (setsockopt(sockfd, IPPROTO_TCP, TCP_NODELAY,
- &intarg, sizeof(intarg)) < 0)
- post("setsockopt (TCP_NODELAY) failed\n");
+ intarg = 1;
+ if (setsockopt(sockfd, IPPROTO_TCP, TCP_NODELAY,
+ &intarg, sizeof(intarg)) < 0)
+ post("setsockopt (TCP_NODELAY) failed\n");
}
- /* assign server port number */
+ /* assign server port number */
server.sin_port = htons((u_short)portno);
- /* name the socket */
+ /* name the socket */
if (bind(sockfd, (struct sockaddr *)&server, sizeof(server)) < 0)
{
- sys_sockerror("bind");
- sys_closesocket(sockfd);
- return (0);
+ sys_sockerror("bind");
+ sys_closesocket(sockfd);
+ return (0);
}
x = (t_netreceive *)pd_new(netreceive_class);
if (old)
{
- /* old style, nonsecure version */
- x->x_msgout = 0;
+ /* old style, nonsecure version */
+ x->x_msgout = 0;
}
else x->x_msgout = outlet_new(&x->x_obj, &s_anything);
- if (udp) /* datagram protocol */
+ if (udp) /* datagram protocol */
{
- t_socketreceiver *y = socketreceiver_new((void *)x,
- (t_socketnotifier)netreceive_notify,
- (x->x_msgout ? netreceive_doit : 0), 1);
- sys_addpollfn(sockfd, (t_fdpollfn)socketreceiver_read, y);
- x->x_connectout = 0;
+ t_socketreceiver *y = socketreceiver_new((void *)x,
+ (t_socketnotifier)netreceive_notify,
+ (x->x_msgout ? netreceive_doit : 0), 1);
+ sys_addpollfn(sockfd, (t_fdpollfn)socketreceiver_read, y);
+ x->x_connectout = 0;
}
- else /* streaming protocol */
+ else /* streaming protocol */
{
- if (listen(sockfd, 5) < 0)
- {
- sys_sockerror("listen");
- sys_closesocket(sockfd);
- sockfd = -1;
- }
- else
- {
- sys_addpollfn(sockfd, (t_fdpollfn)netreceive_connectpoll, x);
- x->x_connectout = outlet_new(&x->x_obj, &s_float);
- }
+ if (listen(sockfd, 5) < 0)
+ {
+ sys_sockerror("listen");
+ sys_closesocket(sockfd);
+ sockfd = -1;
+ }
+ else
+ {
+ sys_addpollfn(sockfd, (t_fdpollfn)netreceive_connectpoll, x);
+ x->x_connectout = outlet_new(&x->x_obj, &s_float);
+ }
}
x->x_connectsocket = sockfd;
x->x_nconnections = 0;
@@ -339,20 +339,20 @@ static void *netreceive_new(t_symbol *compatflag,
static void netreceive_free(t_netreceive *x)
{
- /* LATER make me clean up open connections */
+ /* LATER make me clean up open connections */
if (x->x_connectsocket >= 0)
{
- sys_rmpollfn(x->x_connectsocket);
- sys_closesocket(x->x_connectsocket);
+ sys_rmpollfn(x->x_connectsocket);
+ sys_closesocket(x->x_connectsocket);
}
}
static void netreceive_setup(void)
{
netreceive_class = class_new(gensym("netreceive"),
- (t_newmethod)netreceive_new, (t_method)netreceive_free,
- sizeof(t_netreceive), CLASS_NOINLET, A_DEFFLOAT, A_DEFFLOAT,
- A_DEFSYM, 0);
+ (t_newmethod)netreceive_new, (t_method)netreceive_free,
+ sizeof(t_netreceive), CLASS_NOINLET, A_DEFFLOAT, A_DEFFLOAT,
+ A_DEFSYM, 0);
}
void x_net_setup(void)
diff --git a/pd/src/x_qlist.c b/pd/src/x_qlist.c
index 7dbec5e7..4b6a393b 100644
--- a/pd/src/x_qlist.c
+++ b/pd/src/x_qlist.c
@@ -4,7 +4,7 @@
#include "m_pd.h"
#include <string.h>
-#ifdef UNIX
+#ifdef UNISTD
#include <unistd.h>
#endif
#ifdef MSW
@@ -16,7 +16,7 @@ typedef struct _qlist
t_object x_ob;
t_outlet *x_bangout;
void *x_binbuf;
- int x_onset; /* playback position */
+ int x_onset; /* playback position */
t_clock *x_clock;
float x_tempo;
double x_whenclockset;
@@ -60,70 +60,70 @@ static void qlist_donext(t_qlist *x, int drop, int automatic)
t_pd *target = 0;
while (1)
{
- int argc = binbuf_getnatom(x->x_binbuf),
- count, onset = x->x_onset, onset2, wasreentered;
- t_atom *argv = binbuf_getvec(x->x_binbuf);
- t_atom *ap = argv + onset, *ap2;
- if (onset >= argc) goto end;
- while (ap->a_type == A_SEMI || ap->a_type == A_COMMA)
- {
- if (ap->a_type == A_SEMI) target = 0;
- onset++, ap++;
- if (onset >= argc) goto end;
- }
+ int argc = binbuf_getnatom(x->x_binbuf),
+ count, onset = x->x_onset, onset2, wasreentered;
+ t_atom *argv = binbuf_getvec(x->x_binbuf);
+ t_atom *ap = argv + onset, *ap2;
+ if (onset >= argc) goto end;
+ while (ap->a_type == A_SEMI || ap->a_type == A_COMMA)
+ {
+ if (ap->a_type == A_SEMI) target = 0;
+ onset++, ap++;
+ if (onset >= argc) goto end;
+ }
- if (!target && ap->a_type == A_FLOAT)
- {
- ap2 = ap + 1;
- onset2 = onset + 1;
- while (onset2 < argc && ap2->a_type == A_FLOAT)
- onset2++, ap2++;
- x->x_onset = onset2;
- if (automatic)
- {
- clock_delay(x->x_clock,
- x->x_clockdelay = ap->a_w.w_float * x->x_tempo);
- x->x_whenclockset = clock_getsystime();
- }
- else outlet_list(x->x_ob.ob_outlet, 0, onset2-onset, ap);
- return;
- }
- ap2 = ap + 1;
- onset2 = onset + 1;
- while (onset2 < argc &&
- (ap2->a_type == A_FLOAT || ap2->a_type == A_SYMBOL))
- onset2++, ap2++;
- x->x_onset = onset2;
- count = onset2 - onset;
- if (!target)
- {
- if (ap->a_type != A_SYMBOL) continue;
- else if (!(target = ap->a_w.w_symbol->s_thing))
- {
- error("qlist: %s: no such object", ap->a_w.w_symbol->s_name);
- continue;
- }
- ap++;
- onset++;
- count--;
- if (!count)
- {
- x->x_onset = onset2;
- continue;
- }
- }
- wasreentered = x->x_reentered;
- x->x_reentered = 0;
- if (!drop)
- {
- if (ap->a_type == A_FLOAT)
- typedmess(target, &s_list, count, ap);
- else if (ap->a_type == A_SYMBOL)
- typedmess(target, ap->a_w.w_symbol, count-1, ap+1);
- }
- if (x->x_reentered)
- return;
- x->x_reentered = wasreentered;
+ if (!target && ap->a_type == A_FLOAT)
+ {
+ ap2 = ap + 1;
+ onset2 = onset + 1;
+ while (onset2 < argc && ap2->a_type == A_FLOAT)
+ onset2++, ap2++;
+ x->x_onset = onset2;
+ if (automatic)
+ {
+ clock_delay(x->x_clock,
+ x->x_clockdelay = ap->a_w.w_float * x->x_tempo);
+ x->x_whenclockset = clock_getsystime();
+ }
+ else outlet_list(x->x_ob.ob_outlet, 0, onset2-onset, ap);
+ return;
+ }
+ ap2 = ap + 1;
+ onset2 = onset + 1;
+ while (onset2 < argc &&
+ (ap2->a_type == A_FLOAT || ap2->a_type == A_SYMBOL))
+ onset2++, ap2++;
+ x->x_onset = onset2;
+ count = onset2 - onset;
+ if (!target)
+ {
+ if (ap->a_type != A_SYMBOL) continue;
+ else if (!(target = ap->a_w.w_symbol->s_thing))
+ {
+ error("qlist: %s: no such object", ap->a_w.w_symbol->s_name);
+ continue;
+ }
+ ap++;
+ onset++;
+ count--;
+ if (!count)
+ {
+ x->x_onset = onset2;
+ continue;
+ }
+ }
+ wasreentered = x->x_reentered;
+ x->x_reentered = 0;
+ if (!drop)
+ {
+ if (ap->a_type == A_FLOAT)
+ typedmess(target, &s_list, count, ap);
+ else if (ap->a_type == A_SYMBOL)
+ typedmess(target, ap->a_w.w_symbol, count-1, ap+1);
+ }
+ if (x->x_reentered)
+ return;
+ x->x_reentered = wasreentered;
} /* while (1); never falls through */
end:
@@ -178,13 +178,13 @@ static void qlist_read(t_qlist *x, t_symbol *filename, t_symbol *format)
{
int cr = 0;
if (!strcmp(format->s_name, "cr"))
- cr = 1;
+ cr = 1;
else if (*format->s_name)
- error("qlist_read: unknown flag: %s", format->s_name);
-
+ error("qlist_read: unknown flag: %s", format->s_name);
+
if (binbuf_read_via_path(x->x_binbuf, filename->s_name,
- canvas_getdir(x->x_canvas)->s_name, cr))
- error("%s: read failed", filename->s_name);
+ canvas_getdir(x->x_canvas)->s_name, cr))
+ error("%s: read failed", filename->s_name);
x->x_onset = 0x7fffffff;
x->x_reentered = 1;
}
@@ -194,13 +194,13 @@ static void qlist_write(t_qlist *x, t_symbol *filename, t_symbol *format)
int cr = 0;
char buf[MAXPDSTRING];
canvas_makefilename(x->x_canvas, filename->s_name,
- buf, MAXPDSTRING);
+ buf, MAXPDSTRING);
if (!strcmp(format->s_name, "cr"))
- cr = 1;
+ cr = 1;
else if (*format->s_name)
- error("qlist_read: unknown flag: %s", format->s_name);
+ error("qlist_read: unknown flag: %s", format->s_name);
if (binbuf_write(x->x_binbuf, buf, "", cr))
- error("%s: write failed", filename->s_name);
+ error("%s: write failed", filename->s_name);
}
static void qlist_print(t_qlist *x)
@@ -217,11 +217,11 @@ static void qlist_tempo(t_qlist *x, t_float f)
newtempo = 1./f;
if (x->x_whenclockset != 0)
{
- float elapsed = clock_gettimesince(x->x_whenclockset);
- float left = x->x_clockdelay - elapsed;
- if (left < 0) left = 0;
- left *= newtempo / x->x_tempo;
- clock_delay(x->x_clock, left);
+ float elapsed = clock_gettimesince(x->x_whenclockset);
+ float left = x->x_clockdelay - elapsed;
+ if (left < 0) left = 0;
+ left *= newtempo / x->x_tempo;
+ clock_delay(x->x_clock, left);
}
x->x_tempo = newtempo;
}
@@ -257,29 +257,29 @@ static void *textfile_new( void)
static void textfile_bang(t_textfile *x)
{
int argc = binbuf_getnatom(x->x_binbuf),
- count, onset = x->x_onset, onset2;
+ count, onset = x->x_onset, onset2;
t_atom *argv = binbuf_getvec(x->x_binbuf);
t_atom *ap = argv + onset, *ap2;
while (onset < argc &&
- (ap->a_type == A_SEMI || ap->a_type == A_COMMA))
- onset++, ap++;
+ (ap->a_type == A_SEMI || ap->a_type == A_COMMA))
+ onset++, ap++;
onset2 = onset;
ap2 = ap;
while (onset2 < argc &&
- (ap2->a_type != A_SEMI && ap2->a_type != A_COMMA))
- onset2++, ap2++;
+ (ap2->a_type != A_SEMI && ap2->a_type != A_COMMA))
+ onset2++, ap2++;
if (onset2 > onset)
{
- x->x_onset = onset2;
- if (ap->a_type == A_SYMBOL)
- outlet_anything(x->x_ob.ob_outlet, ap->a_w.w_symbol,
- onset2-onset-1, ap+1);
- else outlet_list(x->x_ob.ob_outlet, 0, onset2-onset, ap);
+ x->x_onset = onset2;
+ if (ap->a_type == A_SYMBOL)
+ outlet_anything(x->x_ob.ob_outlet, ap->a_w.w_symbol,
+ onset2-onset-1, ap+1);
+ else outlet_list(x->x_ob.ob_outlet, 0, onset2-onset, ap);
}
else
{
- x->x_onset = 0x7fffffff;
- outlet_bang(x->x_bangout);
+ x->x_onset = 0x7fffffff;
+ outlet_bang(x->x_bangout);
}
}
@@ -298,48 +298,48 @@ static void textfile_free(t_textfile *x)
void x_qlist_setup(void )
{
qlist_class = class_new(gensym("qlist"), (t_newmethod)qlist_new,
- (t_method)qlist_free, sizeof(t_qlist), 0, 0);
+ (t_method)qlist_free, sizeof(t_qlist), 0, 0);
class_addmethod(qlist_class, (t_method)qlist_rewind, gensym("rewind"), 0);
class_addmethod(qlist_class, (t_method)qlist_next,
- gensym("next"), A_DEFFLOAT, 0);
+ gensym("next"), A_DEFFLOAT, 0);
class_addmethod(qlist_class, (t_method)qlist_set, gensym("set"),
- A_GIMME, 0);
+ A_GIMME, 0);
class_addmethod(qlist_class, (t_method)qlist_clear, gensym("clear"), 0);
class_addmethod(qlist_class, (t_method)qlist_add, gensym("add"),
- A_GIMME, 0);
+ A_GIMME, 0);
class_addmethod(qlist_class, (t_method)qlist_add2, gensym("add2"),
- A_GIMME, 0);
+ A_GIMME, 0);
class_addmethod(qlist_class, (t_method)qlist_add, gensym("append"),
- A_GIMME, 0);
+ A_GIMME, 0);
class_addmethod(qlist_class, (t_method)qlist_read, gensym("read"),
- A_SYMBOL, A_DEFSYM, 0);
+ A_SYMBOL, A_DEFSYM, 0);
class_addmethod(qlist_class, (t_method)qlist_write, gensym("write"),
- A_SYMBOL, A_DEFSYM, 0);
+ A_SYMBOL, A_DEFSYM, 0);
class_addmethod(qlist_class, (t_method)qlist_print, gensym("print"),
- A_DEFSYM, 0);
+ A_DEFSYM, 0);
class_addmethod(qlist_class, (t_method)qlist_tempo,
- gensym("tempo"), A_FLOAT, 0);
+ gensym("tempo"), A_FLOAT, 0);
class_addbang(qlist_class, qlist_bang);
textfile_class = class_new(gensym("textfile"), (t_newmethod)textfile_new,
- (t_method)textfile_free, sizeof(t_textfile), 0, 0);
+ (t_method)textfile_free, sizeof(t_textfile), 0, 0);
class_addmethod(textfile_class, (t_method)textfile_rewind, gensym("rewind"),
- 0);
+ 0);
class_addmethod(textfile_class, (t_method)qlist_set, gensym("set"),
- A_GIMME, 0);
+ A_GIMME, 0);
class_addmethod(textfile_class, (t_method)qlist_clear, gensym("clear"), 0);
class_addmethod(textfile_class, (t_method)qlist_add, gensym("add"),
- A_GIMME, 0);
+ A_GIMME, 0);
class_addmethod(textfile_class, (t_method)qlist_add2, gensym("add2"),
- A_GIMME, 0);
+ A_GIMME, 0);
class_addmethod(textfile_class, (t_method)qlist_add, gensym("append"),
- A_GIMME, 0);
+ A_GIMME, 0);
class_addmethod(textfile_class, (t_method)qlist_read, gensym("read"),
- A_SYMBOL, A_DEFSYM, 0);
+ A_SYMBOL, A_DEFSYM, 0);
class_addmethod(textfile_class, (t_method)qlist_write, gensym("write"),
- A_SYMBOL, A_DEFSYM, 0);
+ A_SYMBOL, A_DEFSYM, 0);
class_addmethod(textfile_class, (t_method)qlist_print, gensym("print"),
- A_DEFSYM, 0);
+ A_DEFSYM, 0);
class_addbang(textfile_class, textfile_bang);
}
diff --git a/pd/src/x_time.c b/pd/src/x_time.c
index 2ea17fd3..70285455 100644
--- a/pd/src/x_time.c
+++ b/pd/src/x_time.c
@@ -61,12 +61,12 @@ static void *delay_new(t_floatarg f)
static void delay_setup(void)
{
delay_class = class_new(gensym("delay"), (t_newmethod)delay_new,
- (t_method)delay_free, sizeof(t_delay), 0, A_DEFFLOAT, 0);
+ (t_method)delay_free, sizeof(t_delay), 0, A_DEFFLOAT, 0);
class_addcreator((t_newmethod)delay_new, gensym("del"), A_DEFFLOAT, 0);
class_addbang(delay_class, delay_bang);
class_addmethod(delay_class, (t_method)delay_stop, gensym("stop"), 0);
class_addmethod(delay_class, (t_method)delay_ft1,
- gensym("ft1"), A_FLOAT, 0);
+ gensym("ft1"), A_FLOAT, 0);
class_addfloat(delay_class, (t_method)delay_float);
}
@@ -130,11 +130,11 @@ static void *metro_new(t_floatarg f)
static void metro_setup(void)
{
metro_class = class_new(gensym("metro"), (t_newmethod)metro_new,
- (t_method)metro_free, sizeof(t_metro), 0, A_DEFFLOAT, 0);
+ (t_method)metro_free, sizeof(t_metro), 0, A_DEFFLOAT, 0);
class_addbang(metro_class, metro_bang);
class_addmethod(metro_class, (t_method)metro_stop, gensym("stop"), 0);
class_addmethod(metro_class, (t_method)metro_ft1, gensym("ft1"),
- A_FLOAT, 0);
+ A_FLOAT, 0);
class_addfloat(metro_class, (t_method)metro_float);
}
@@ -161,15 +161,15 @@ static void line_tick(t_line *x)
double msectogo = - clock_gettimesince(x->x_targettime);
if (msectogo < 1E-9)
{
- outlet_float(x->x_obj.ob_outlet, x->x_targetval);
+ outlet_float(x->x_obj.ob_outlet, x->x_targetval);
}
else
{
- outlet_float(x->x_obj.ob_outlet,
- x->x_setval + x->x_1overtimediff * (timenow - x->x_prevtime)
- * (x->x_targetval - x->x_setval));
- clock_delay(x->x_clock,
- (x->x_grain > msectogo ? msectogo : x->x_grain));
+ outlet_float(x->x_obj.ob_outlet,
+ x->x_setval + x->x_1overtimediff * (timenow - x->x_prevtime)
+ * (x->x_targetval - x->x_setval));
+ clock_delay(x->x_clock,
+ (x->x_grain > msectogo ? msectogo : x->x_grain));
}
}
@@ -178,25 +178,25 @@ static void line_float(t_line *x, t_float f)
double timenow = clock_getsystime();
if (x->x_gotinlet && x->x_in1val > 0)
{
- if (timenow > x->x_targettime) x->x_setval = x->x_targetval;
- else x->x_setval = x->x_setval + x->x_1overtimediff *
- (timenow - x->x_prevtime)
- * (x->x_targetval - x->x_setval);
- x->x_prevtime = timenow;
- x->x_targettime = clock_getsystimeafter(x->x_in1val);
- x->x_targetval = f;
- line_tick(x);
- x->x_gotinlet = 0;
- x->x_1overtimediff = 1./ (x->x_targettime - timenow);
- clock_delay(x->x_clock,
- (x->x_grain > x->x_in1val ? x->x_in1val : x->x_grain));
+ if (timenow > x->x_targettime) x->x_setval = x->x_targetval;
+ else x->x_setval = x->x_setval + x->x_1overtimediff *
+ (timenow - x->x_prevtime)
+ * (x->x_targetval - x->x_setval);
+ x->x_prevtime = timenow;
+ x->x_targettime = clock_getsystimeafter(x->x_in1val);
+ x->x_targetval = f;
+ line_tick(x);
+ x->x_gotinlet = 0;
+ x->x_1overtimediff = 1./ (x->x_targettime - timenow);
+ clock_delay(x->x_clock,
+ (x->x_grain > x->x_in1val ? x->x_in1val : x->x_grain));
}
else
{
- clock_unset(x->x_clock);
- x->x_targetval = x->x_setval = f;
- outlet_float(x->x_obj.ob_outlet, f);
+ clock_unset(x->x_clock);
+ x->x_targetval = x->x_setval = f;
+ outlet_float(x->x_obj.ob_outlet, f);
}
x->x_gotinlet = 0;
}
@@ -213,6 +213,12 @@ static void line_stop(t_line *x)
clock_unset(x->x_clock);
}
+static void line_set(t_line *x, t_floatarg f)
+{
+ clock_unset(x->x_clock);
+ x->x_targetval = x->x_setval = f;
+}
+
static void line_free(t_line *x)
{
clock_free(x->x_clock);
@@ -236,11 +242,13 @@ static void *line_new(t_floatarg f, t_floatarg grain)
static void line_setup(void)
{
line_class = class_new(gensym("line"), (t_newmethod)line_new,
- (t_method)line_free, sizeof(t_line), 0, A_DEFFLOAT, A_DEFFLOAT, 0);
+ (t_method)line_free, sizeof(t_line), 0, A_DEFFLOAT, A_DEFFLOAT, 0);
class_addmethod(line_class, (t_method)line_ft1,
- gensym("ft1"), A_FLOAT, 0);
+ gensym("ft1"), A_FLOAT, 0);
class_addmethod(line_class, (t_method)line_stop,
- gensym("stop"), 0);
+ gensym("stop"), 0);
+ class_addmethod(line_class, (t_method)line_set,
+ gensym("set"), A_FLOAT, 0);
class_addfloat(line_class, (t_method)line_float);
}
@@ -275,7 +283,7 @@ static void *timer_new(t_floatarg f)
static void timer_setup(void)
{
timer_class = class_new(gensym("timer"), (t_newmethod)timer_new, 0,
- sizeof(t_timer), 0, A_DEFFLOAT, 0);
+ sizeof(t_timer), 0, A_DEFFLOAT, 0);
class_addbang(timer_class, timer_bang);
class_addmethod(timer_class, (t_method)timer_bang2, gensym("bang2"), 0);
}
@@ -291,7 +299,7 @@ typedef struct _hang
struct _hang *h_next;
struct _pipe *h_owner;
t_gpointer *h_gp;
- union word h_vec[1]; /* not the actual number. */
+ union word h_vec[1]; /* not the actual number. */
} t_hang;
typedef struct pipeout
@@ -322,68 +330,68 @@ static void *pipe_new(t_symbol *s, int argc, t_atom *argv)
float deltime;
if (argc)
{
- if (argv[argc-1].a_type != A_FLOAT)
- {
- char stupid[80];
- atom_string(&argv[argc-1], stupid, 79);
- post("pipe: %s: bad time delay value", stupid);
- deltime = 0;
- }
- else deltime = argv[argc-1].a_w.w_float;
- argc--;
+ if (argv[argc-1].a_type != A_FLOAT)
+ {
+ char stupid[80];
+ atom_string(&argv[argc-1], stupid, 79);
+ post("pipe: %s: bad time delay value", stupid);
+ deltime = 0;
+ }
+ else deltime = argv[argc-1].a_w.w_float;
+ argc--;
}
else deltime = 0;
if (!argc)
{
- argv = &defarg;
- argc = 1;
- SETFLOAT(&defarg, 0);
+ argv = &defarg;
+ argc = 1;
+ SETFLOAT(&defarg, 0);
}
x->x_n = argc;
vec = x->x_vec = (t_pipeout *)getbytes(argc * sizeof(*x->x_vec));
for (i = argc, ap = argv; i--; ap++)
- if (ap->a_type == A_SYMBOL && *ap->a_w.w_symbol->s_name == 'p')
- nptr++;
+ if (ap->a_type == A_SYMBOL && *ap->a_w.w_symbol->s_name == 'p')
+ nptr++;
gp = x->x_gp = (t_gpointer *)t_getbytes(nptr * sizeof (*gp));
x->x_nptr = nptr;
for (i = 0, vp = vec, ap = argv; i < argc; i++, ap++, vp++)
{
- if (ap->a_type == A_FLOAT)
- {
- vp->p_atom = *ap;
- vp->p_outlet = outlet_new(&x->x_obj, &s_float);
- if (i) floatinlet_new(&x->x_obj, &vp->p_atom.a_w.w_float);
- }
- else if (ap->a_type == A_SYMBOL)
- {
- char c = *ap->a_w.w_symbol->s_name;
- if (c == 's')
- {
- SETSYMBOL(&vp->p_atom, &s_symbol);
- vp->p_outlet = outlet_new(&x->x_obj, &s_symbol);
- if (i) symbolinlet_new(&x->x_obj, &vp->p_atom.a_w.w_symbol);
- }
- else if (c == 'p')
- {
- vp->p_atom.a_type = A_POINTER;
- vp->p_atom.a_w.w_gpointer = gp;
- gpointer_init(gp);
- vp->p_outlet = outlet_new(&x->x_obj, &s_pointer);
- if (i) pointerinlet_new(&x->x_obj, gp);
- gp++;
- }
- else
- {
- if (c != 'f') error("pack: %s: bad type",
- ap->a_w.w_symbol->s_name);
- SETFLOAT(&vp->p_atom, 0);
- vp->p_outlet = outlet_new(&x->x_obj, &s_float);
- if (i) floatinlet_new(&x->x_obj, &vp->p_atom.a_w.w_float);
- }
- }
+ if (ap->a_type == A_FLOAT)
+ {
+ vp->p_atom = *ap;
+ vp->p_outlet = outlet_new(&x->x_obj, &s_float);
+ if (i) floatinlet_new(&x->x_obj, &vp->p_atom.a_w.w_float);
+ }
+ else if (ap->a_type == A_SYMBOL)
+ {
+ char c = *ap->a_w.w_symbol->s_name;
+ if (c == 's')
+ {
+ SETSYMBOL(&vp->p_atom, &s_symbol);
+ vp->p_outlet = outlet_new(&x->x_obj, &s_symbol);
+ if (i) symbolinlet_new(&x->x_obj, &vp->p_atom.a_w.w_symbol);
+ }
+ else if (c == 'p')
+ {
+ vp->p_atom.a_type = A_POINTER;
+ vp->p_atom.a_w.w_gpointer = gp;
+ gpointer_init(gp);
+ vp->p_outlet = outlet_new(&x->x_obj, &s_pointer);
+ if (i) pointerinlet_new(&x->x_obj, gp);
+ gp++;
+ }
+ else
+ {
+ if (c != 'f') error("pack: %s: bad type",
+ ap->a_w.w_symbol->s_name);
+ SETFLOAT(&vp->p_atom, 0);
+ vp->p_outlet = outlet_new(&x->x_obj, &s_float);
+ if (i) floatinlet_new(&x->x_obj, &vp->p_atom.a_w.w_float);
+ }
+ }
}
floatinlet_new(&x->x_obj, &x->x_deltime);
x->x_hang = 0;
@@ -397,7 +405,7 @@ static void hang_free(t_hang *h)
t_gpointer *gp;
int i;
for (gp = h->h_gp, i = x->x_nptr; i--; gp++)
- gpointer_unset(gp);
+ gpointer_unset(gp);
freebytes(h->h_gp, x->x_nptr * sizeof(*h->h_gp));
clock_free(h->h_clock);
freebytes(h, sizeof(*h) + (x->x_n - 1) * sizeof(*h->h_vec));
@@ -413,25 +421,25 @@ static void hang_tick(t_hang *h)
if (x->x_hang == h) x->x_hang = h->h_next;
else for (h2 = x->x_hang; h3 = h2->h_next; h2 = h3)
{
- if (h3 == h)
- {
- h2->h_next = h3->h_next;
- break;
- }
+ if (h3 == h)
+ {
+ h2->h_next = h3->h_next;
+ break;
+ }
}
for (i = x->x_n, p = x->x_vec + (x->x_n - 1), w = h->h_vec + (x->x_n - 1);
- i--; p--, w--)
+ i--; p--, w--)
{
- switch (p->p_atom.a_type)
- {
- case A_FLOAT: outlet_float(p->p_outlet, w->w_float); break;
- case A_SYMBOL: outlet_symbol(p->p_outlet, w->w_symbol); break;
- case A_POINTER:
- if (gpointer_check(w->w_gpointer, 1))
- outlet_pointer(p->p_outlet, w->w_gpointer);
- else post("pipe: stale pointer");
- break;
- }
+ switch (p->p_atom.a_type)
+ {
+ case A_FLOAT: outlet_float(p->p_outlet, w->w_float); break;
+ case A_SYMBOL: outlet_symbol(p->p_outlet, w->w_symbol); break;
+ case A_POINTER:
+ if (gpointer_check(w->w_gpointer, 1))
+ outlet_pointer(p->p_outlet, w->w_gpointer);
+ else post("pipe: stale pointer");
+ break;
+ }
}
hang_free(h);
}
@@ -439,7 +447,7 @@ static void hang_tick(t_hang *h)
static void pipe_list(t_pipe *x, t_symbol *s, int ac, t_atom *av)
{
t_hang *h = (t_hang *)
- getbytes(sizeof(*h) + (x->x_n - 1) * sizeof(*h->h_vec));
+ getbytes(sizeof(*h) + (x->x_n - 1) * sizeof(*h->h_vec));
t_gpointer *gp, *gp2;
t_pipeout *p;
int i, n = x->x_n;
@@ -448,34 +456,34 @@ static void pipe_list(t_pipe *x, t_symbol *s, int ac, t_atom *av)
h->h_gp = (t_gpointer *)getbytes(x->x_nptr * sizeof(t_gpointer));
if (ac > n) ac = n;
for (i = 0, gp = x->x_gp, p = x->x_vec, ap = av; i < ac;
- i++, p++, ap++)
+ i++, p++, ap++)
{
- switch (p->p_atom.a_type)
- {
- case A_FLOAT: p->p_atom.a_w.w_float = atom_getfloat(ap); break;
- case A_SYMBOL: p->p_atom.a_w.w_symbol = atom_getsymbol(ap); break;
- case A_POINTER:
- gpointer_unset(gp);
- if (ap->a_type != A_POINTER)
- post("pipe: bad pointer");
- else
- {
- *gp = *(ap->a_w.w_gpointer);
- if (gp->gp_stub) gp->gp_stub->gs_refcount++;
- }
- gp++;
- }
+ switch (p->p_atom.a_type)
+ {
+ case A_FLOAT: p->p_atom.a_w.w_float = atom_getfloat(ap); break;
+ case A_SYMBOL: p->p_atom.a_w.w_symbol = atom_getsymbol(ap); break;
+ case A_POINTER:
+ gpointer_unset(gp);
+ if (ap->a_type != A_POINTER)
+ post("pipe: bad pointer");
+ else
+ {
+ *gp = *(ap->a_w.w_gpointer);
+ if (gp->gp_stub) gp->gp_stub->gs_refcount++;
+ }
+ gp++;
+ }
}
for (i = 0, gp = x->x_gp, gp2 = h->h_gp, p = x->x_vec, w = h->h_vec;
- i < n; i++, p++, w++)
+ i < n; i++, p++, w++)
{
- if (p->p_atom.a_type == A_POINTER)
- {
- if (gp->gp_stub) gp->gp_stub->gs_refcount++;
- w->w_gpointer = gp2;
- *gp2++ = *gp++;
- }
- else *w = p->p_atom.a_w;
+ if (p->p_atom.a_type == A_POINTER)
+ {
+ if (gp->gp_stub) gp->gp_stub->gs_refcount++;
+ w->w_gpointer = gp2;
+ *gp2++ = *gp++;
+ }
+ else *w = p->p_atom.a_w;
}
h->h_next = x->x_hang;
x->x_hang = h;
@@ -494,16 +502,16 @@ static void pipe_clear(t_pipe *x)
t_hang *hang;
while (hang = x->x_hang)
{
- x->x_hang = hang->h_next;
- hang_free(hang);
+ x->x_hang = hang->h_next;
+ hang_free(hang);
}
}
static void pipe_setup(void)
{
pipe_class = class_new(gensym("pipe"),
- (t_newmethod)pipe_new, (t_method)pipe_clear,
- sizeof(t_pipe), 0, A_GIMME, 0);
+ (t_newmethod)pipe_new, (t_method)pipe_clear,
+ sizeof(t_pipe), 0, A_GIMME, 0);
class_addlist(pipe_class, pipe_list);
class_addmethod(pipe_class, (t_method)pipe_flush, gensym("flush"), 0);
class_addmethod(pipe_class, (t_method)pipe_clear, gensym("clear"), 0);