examples/utils.c: change send_noteon to accept floating point midi note number
authorPaul Brossier <piem@piem.org>
Fri, 22 Jul 2016 19:30:31 +0000 (21:30 +0200)
committerPaul Brossier <piem@piem.org>
Fri, 22 Jul 2016 19:30:31 +0000 (21:30 +0200)
examples/aubionotes.c
examples/utils.c
examples/utils.h

index 31e5251..7541098 100644 (file)
 #include "parse_args.h"
 
 aubio_notes_t *notes;
 #include "parse_args.h"
 
 aubio_notes_t *notes;
-uint_t lastnote = 0;
+smpl_t lastmidi = 0.;
 
 void process_block (fvec_t *ibuf, fvec_t *obuf)
 {
   aubio_notes_do (notes, ibuf, obuf);
   // did we get a note off?
   if (obuf->data[2] != 0) {
 
 void process_block (fvec_t *ibuf, fvec_t *obuf)
 {
   aubio_notes_do (notes, ibuf, obuf);
   // did we get a note off?
   if (obuf->data[2] != 0) {
-    send_noteon(obuf->data[2], 0);
+    lastmidi = aubio_freqtomidi (obuf->data[2]) + .5;
+    send_noteon(lastmidi, 0);
   }
   // did we get a note on?
   if (obuf->data[0] != 0) {
   }
   // did we get a note on?
   if (obuf->data[0] != 0) {
-    send_noteon(obuf->data[0], obuf->data[1]);
-    lastnote = (uint_t) floor(obuf->data[0]);
+    lastmidi = aubio_freqtomidi (obuf->data[0]) + .5;
+    send_noteon(lastmidi, obuf->data[1]);
   }
 }
 
   }
 }
 
@@ -67,7 +68,7 @@ int main(int argc, char **argv) {
   examples_common_process((aubio_process_func_t)process_block, process_print);
 
   // send a last note off
   examples_common_process((aubio_process_func_t)process_block, process_print);
 
   // send a last note off
-  send_noteon (lastnote, 0);
+  send_noteon (lastmidi, 0);
 
   del_aubio_notes (notes);
 
 
   del_aubio_notes (notes);
 
index 39d46bb..dc27386 100644 (file)
@@ -181,9 +181,8 @@ void examples_common_process (aubio_process_func_t process_func,
 }
 
 void
 }
 
 void
-send_noteon (int pitch, int velo)
+send_noteon (smpl_t pitch, smpl_t velo)
 {
 {
-  smpl_t mpitch = floor (aubio_freqtomidi (pitch) + .5);
 #ifdef HAVE_JACK
   jack_midi_event_t ev;
   ev.size = 3;
 #ifdef HAVE_JACK
   jack_midi_event_t ev;
   ev.size = 3;
@@ -191,7 +190,7 @@ send_noteon (int pitch, int velo)
   ev.time = 0;
   if (usejack) {
     ev.buffer[2] = velo;
   ev.time = 0;
   if (usejack) {
     ev.buffer[2] = velo;
-    ev.buffer[1] = mpitch;
+    ev.buffer[1] = pitch;
     if (velo == 0) {
       ev.buffer[0] = 0x80;      /* note off */
     } else {
     if (velo == 0) {
       ev.buffer[0] = 0x80;      /* note off */
     } else {
@@ -204,7 +203,7 @@ send_noteon (int pitch, int velo)
     print_time (blocks * hop_size);
     outmsg ("\n");
   } else {
     print_time (blocks * hop_size);
     outmsg ("\n");
   } else {
-    outmsg ("%f\t", mpitch);
+    outmsg ("%f\t", pitch);
     print_time (blocks * hop_size);
     outmsg ("\t");
   }
     print_time (blocks * hop_size);
     outmsg ("\t");
   }
index c9587dd..e911bef 100644 (file)
@@ -63,7 +63,7 @@
 #endif
 
 typedef void (aubio_print_func_t) (void);
 #endif
 
 typedef void (aubio_print_func_t) (void);
-void send_noteon (int pitch, int velo);
+void send_noteon (smpl_t pitch, smpl_t velo);
 
 /** common process function */
 typedef int (*aubio_process_func_t) (fvec_t * input, fvec_t * output);
 
 /** common process function */
 typedef int (*aubio_process_func_t) (fvec_t * input, fvec_t * output);