Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

WatchPoint.h 2.1KB

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