give WindowProxy its own map/unmap signals so that other things can track map/unmap...
[ardour.git] / libs / plugins / reasonablesynth.lv2 / lv2.c
index 1fcfba868e0496cbb71614244e92aa363d6b548c..4698cb9131c795352289004d5be0fb1ac8afeba8 100644 (file)
@@ -22,6 +22,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdint.h>
+#include <time.h>
 
 /* LV2 */
 #include "lv2/lv2plug.in/ns/lv2core/lv2.h"
@@ -56,6 +57,7 @@ typedef struct {
 
   double SampleRateD;
   void *synth;
+  bool xmas;
 } RSynth;
 
 /* main LV2 */
@@ -98,6 +100,17 @@ instantiate(const LV2_Descriptor*     descriptor,
   self->synth = synth_alloc();
   synth_init(self->synth, rate);
 
+#ifndef PLATFORM_WINDOWS // easter egg is for sane platforms with native support for localtime_r only
+  struct tm date;
+  time_t now;
+  time(&now);
+  localtime_r(&now, &date);
+  if (getenv("ITSXMAS") || (date.tm_mon == 11 /*dec*/ && date.tm_mday == 25)) {
+    printf("reasonable synth.lv2 says: happy holidays!\n");
+    self->xmas = true;
+  }
+#endif
+
   return (LV2_Handle)self;
 }
 
@@ -134,7 +147,7 @@ run(LV2_Handle handle, uint32_t n_samples)
 
   /* Process incoming MIDI events */
   if (self->midiin) {
-    LV2_Atom_Event const* ev = (LV2_Atom_Event const*)((&(self->midiin)->body) + 1); // lv2_atom_sequence_begin
+    LV2_Atom_Event const* ev = (LV2_Atom_Event const*)((uintptr_t)((&(self->midiin)->body) + 1)); // lv2_atom_sequence_begin
     while( // !lv2_atom_sequence_is_end
         (const uint8_t*)ev < ((const uint8_t*) &(self->midiin)->body + (self->midiin)->atom.size)
         )
@@ -146,10 +159,14 @@ run(LV2_Handle handle, uint32_t n_samples)
           written = synth_sound(self->synth, written, ev->time.frames, audio);
         }
         /* send midi message to synth */
-        synth_parse_midi(self->synth, (const uint8_t*)(ev+1), ev->body.size);
+        if (self->xmas) {
+          synth_parse_xmas(self->synth, (const uint8_t*)(ev+1), ev->body.size);
+        } else {
+          synth_parse_midi(self->synth, (const uint8_t*)(ev+1), ev->body.size);
+        }
       }
       ev = (LV2_Atom_Event const*) // lv2_atom_sequence_next()
-        ((const uint8_t*)ev + sizeof(LV2_Atom_Event) + ((ev->body.size + 7) & ~7));
+             ((uintptr_t)((const uint8_t*)ev + sizeof(LV2_Atom_Event) + ((ev->body.size + 7) & ~7)));
     }
   }
 
@@ -183,11 +200,15 @@ static const LV2_Descriptor descriptor = {
   extension_data
 };
 
-LV2_SYMBOL_EXPORT
+#if defined(COMPILER_MSVC)
+__declspec(dllexport)
+#else
+__attribute__ ((visibility ("default")))
+#endif
 const LV2_Descriptor*
-lv2_descriptor(uint32_t index)
+lv2_descriptor(uint32_t idx)
 {
-  switch (index) {
+  switch (idx) {
   case 0:
     return &descriptor;
   default: