diff options
author | N.N. <nimon@users.sourceforge.net> | 2012-08-09 10:17:29 +0000 |
---|---|---|
committer | N.N. <nimon@users.sourceforge.net> | 2012-08-09 10:17:29 +0000 |
commit | 0aaec8774e0b0d327572343abf51cf35d4a12c4c (patch) | |
tree | 81197c9f817e3d9300fa2c0f39094c8fb1c13e5a | |
parent | 02ba30b42ffc1f8591b25f5a22fecb515c6b972d (diff) |
adding closestMass function to pmpd
svn path=/trunk/externals/pmpd/; revision=16162
-rw-r--r-- | pmpd.c | 28 |
1 files changed, 27 insertions, 1 deletions
@@ -18,7 +18,7 @@ GNU General Public License for more details.
You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. + along with this program. If not, see <http://www.gnu.org/licenses/>.
Based on PureData by Miller Puckette and others.
@@ -1765,6 +1765,31 @@ void pmpd_grabMass(t_pmpd *x, t_float posX, t_float grab) }
}
+void pmpd_closestMass(t_pmpd *x, t_float posX)
+{
+ t_float dist, tmp;
+ t_int i;
+ t_atom std_out[2];
+
+ if ((x->nb_mass > 0))
+ {
+ dist = x->mass[0].posX - posX;
+ for (i=1; i<x->nb_mass; i++)
+ {
+ tmp = x->mass[i].posX - posX;
+ if (tmp < dist)
+ {
+ dist = tmp;
+ x->grab_nb= i;
+ }
+ }
+ }
+ SETFLOAT(&(std_out[0]),x->grab_nb);
+ SETFLOAT(&(std_out[1]), x->mass[x->grab_nb].posX);
+ outlet_anything(x->main_outlet, gensym("closestMass"),2,std_out);
+
+}
+
void *pmpd_new()
{
t_pmpd *x = (t_pmpd *)pd_new(pmpd_class);
@@ -1868,5 +1893,6 @@ void pmpd_setup(void) */
class_addmethod(pmpd_class, (t_method)pmpd_grabMass, gensym("grabMass"), A_DEFFLOAT, A_DEFFLOAT, 0);
+ class_addmethod(pmpd_class, (t_method)pmpd_closestMass, gensym("closestMass"), A_DEFFLOAT, 0);
}
|