zynaddsubfx

ZynAddSubFX open source synthesizer
Log | Files | Refs | Submodules | LICENSE

WatchPoint.h (2448B)


      1 /*
      2   ZynAddSubFX - a software synthesizer
      3 
      4   WatchPoint.h - Synthesis State Watcher
      5   Copyright (C) 2015-2015 Mark McCurry
      6   Author: Mark McCurry
      7 
      8   This program is free software; you can redistribute it and/or
      9   modify it under the terms of the GNU General Public License
     10   as published by the Free Software Foundation; either version 2
     11   of the License, or (at your option) any later version.
     12 */
     13 
     14 #pragma once
     15 
     16 namespace rtosc {class ThreadLink;}
     17 
     18 namespace zyn {
     19 
     20 struct WatchManager;
     21 
     22 struct WatchPoint
     23 {
     24     bool          active;
     25     int           samples_left;
     26     WatchManager *reference;
     27     char          identity[128];
     28 
     29     WatchPoint(WatchManager *ref, const char *prefix, const char *id);
     30     bool is_active(void);
     31     bool is_empty(void);
     32 };
     33 
     34 #define MAX_WATCH 16
     35 #define MAX_WATCH_PATH 128
     36 #define MAX_SAMPLE 128
     37 struct WatchManager
     38 {
     39     typedef rtosc::ThreadLink thrlnk;
     40     thrlnk *write_back;
     41     bool    new_active;
     42     char    active_list[MAX_WATCH][MAX_WATCH_PATH];
     43     float   data_list[MAX_WATCH][MAX_SAMPLE];
     44     float   prebuffer[MAX_WATCH][MAX_SAMPLE/2];
     45     int     sample_list[MAX_WATCH];
     46     int     prebuffer_sample[MAX_WATCH];
     47     bool    deactivate[MAX_WATCH];
     48     bool trigger[MAX_WATCH];
     49     bool prebuffer_done[MAX_WATCH];
     50     int call_count[MAX_WATCH];
     51     char countID_list[MAX_WATCH][MAX_WATCH_PATH];
     52 
     53     //External API
     54     WatchManager(thrlnk *link=0);
     55     void add_watch(const char *);
     56     void del_watch(const char *);
     57     void tick(void);
     58     bool trigger_active(const char *) const;
     59     void trigger_other(int);
     60 
     61     //Watch Point Query API
     62     bool active(const char *) const;
     63     int  samples(const char *) const;
     64 
     65     //Watch Point Response API
     66     void satisfy(const char *, float);
     67     void satisfy(const char *, float*, int);
     68 };
     69 
     70 struct FloatWatchPoint:public WatchPoint
     71 {
     72     FloatWatchPoint(WatchManager *ref, const char *prefix, const char *id);
     73     inline void operator()(float f)
     74     {
     75         if(is_active() && reference) {
     76             reference->satisfy(identity, f);
     77             active = false;
     78         }
     79     }
     80 };
     81 
     82 //basically the same as the float watch point, only it consumes tuples
     83 struct VecWatchPoint : public WatchPoint
     84 {
     85     VecWatchPoint(WatchManager *ref, const char *prefix, const char *id);
     86     inline void operator()(float *f, int n)
     87     {
     88         if(is_active() && reference) {
     89             reference->satisfy(identity, f, n);
     90             active = false;
     91         }
     92     }
     93 };
     94 
     95 }