changeset 79:9fd4075b8f9e

Added on and off message responders to max external
author Adam Stark <adamstark.uk@gmail.com>
date Mon, 24 Nov 2014 17:17:26 +0000
parents 866024f9f95a
children d812bf72d928
files modules-and-plug-ins/max-external/btrack~.cpp
diffstat 1 files changed, 52 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/modules-and-plug-ins/max-external/btrack~.cpp	Mon Nov 24 11:48:08 2014 +0000
+++ b/modules-and-plug-ins/max-external/btrack~.cpp	Mon Nov 24 17:17:26 2014 +0000
@@ -39,6 +39,9 @@
     // An instance of the BTrack beat tracker
     BTrack			*b;
     
+    // Indicates whether the beat tracker should output beats
+    bool            should_output_beats;
+    
     // An outlet for beats
     void            *beat_outlet;
     
@@ -61,6 +64,10 @@
 
 //===========================================================================
 void btrack_process(t_btrack *x,double* audioFrame);
+
+void btrack_on(t_btrack *x);
+void btrack_off(t_btrack *x);
+
 void outlet_beat(t_btrack *x, t_symbol *s, long argc, t_atom *argv);
 
 // global class pointer variable
@@ -83,6 +90,9 @@
 	class_addmethod(c, (method)btrack_dsp64,		"dsp64",	A_CANT, 0);		// New 64-bit MSP dsp chain compilation for Max 6
 	class_addmethod(c, (method)btrack_assist,	"assist",	A_CANT, 0);
 	
+    class_addmethod(c, (method)btrack_on,	"on", 0);
+    class_addmethod(c, (method)btrack_off,	"off", 0);
+    
 	class_dspinit(c);
 	class_register(CLASS_BOX, c);
 	btrack_class = c;
@@ -91,6 +101,9 @@
 }
 
 
+
+
+
 //===========================================================================
 void *btrack_new(t_symbol *s, long argc, t_atom *argv)
 {
@@ -108,13 +121,15 @@
         x->tempo_outlet = floatout(x);
         x->beat_outlet = bangout(x);
         
+        
+        x->should_output_beats = true;
+        
         /*
-        
-        
+    
         x->mode = 0;
         x->lastbang = 0;
         
-        x->dobeats = 1;
+        
         x->countin = 4;
         
         x->counttempi[0] = 120;
@@ -137,12 +152,23 @@
 //===========================================================================
 void btrack_assist(t_btrack *x, void *b, long m, long a, char *s)
 {
-	if (m == ASSIST_INLET) { //inlet
-		sprintf(s, "I am inlet %ld", a);
-	} 
-	else {	// outlet
-		sprintf(s, "I am outlet %ld", a); 			
-	}
+    if (m == ASSIST_INLET) { //inlet
+        if (a == 0)
+        {
+            sprintf(s, "(signal) Audio In");
+        }
+    }
+    else {	// outlet
+        if (a == 0)
+        {
+            sprintf(s, "Beats Out");
+        }
+        if (a == 1)
+        {
+            sprintf(s, "Tempo (bpm)");
+        }
+        
+    }
 }
 
 
@@ -237,15 +263,28 @@
 //===========================================================================
 void outlet_beat(t_btrack *x, t_symbol *s, long argc, t_atom *argv)
 {
-    // send a bang out of the beat outlet
-    outlet_bang(x->beat_outlet);
+    if (x->should_output_beats)
+    {
+        // send a bang out of the beat outlet
+        outlet_bang(x->beat_outlet);
     
-    // send the tempo out of the tempo outlet
-    outlet_float(x->tempo_outlet, (float) x->b->getCurrentTempoEstimate());
+        // send the tempo out of the tempo outlet
+        outlet_float(x->tempo_outlet, (float) x->b->getCurrentTempoEstimate());
+    }
 }
 
 
+//===========================================================================
+void btrack_on(t_btrack *x)
+{
+    x->should_output_beats = true;
+}
 
+//===========================================================================
+void btrack_off(t_btrack *x)
+{
+    x->should_output_beats = false;
+}
 
 
 
@@ -253,4 +292,3 @@
 
 
 
-