LMMS
Loading...
Searching...
No Matches
WatchPoint.cpp
Go to the documentation of this file.
1/*
2 ZynAddSubFX - a software synthesizer
3
4 WatchPoint.cpp - Synthesis State Watcher
5 Copyright (C) 2015-2015 Mark McCurry
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of version 2 of the GNU General Public License
9 as published by the Free Software Foundation.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License (version 2 or later) for more details.
15
16 You should have received a copy of the GNU General Public License (version 2)
17 along with this program; if not, write to the Free Software Foundation,
18 Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
20*/
21
22#include "WatchPoint.h"
23#include <cstring>
24#include <rtosc/thread-link.h>
25
26namespace zyncarla {
27
28WatchPoint::WatchPoint(WatchManager *ref, const char *prefix, const char *id)
30{
31 identity[0] = 0;
32 if(prefix)
33 strncpy(identity, prefix, 128);
34 if(id)
35 strncat(identity, id, 128);
36}
37
39{
40 //Either the watchpoint is already active or the watchpoint manager has
41 //received another activation this frame
42 if(active)
43 return true;
44
45 if(reference && reference->active(identity)) {
46 active = true;
47 samples_left = 1;
48 return true;
49 }
50
51 return false;
52}
53
54FloatWatchPoint::FloatWatchPoint(WatchManager *ref, const char *prefix, const char *id)
55 :WatchPoint(ref, prefix, id)
56{}
57
58VecWatchPoint::VecWatchPoint(WatchManager *ref, const char *prefix, const char *id)
59 :WatchPoint(ref, prefix, id)
60{}
61
64{
65 memset(active_list, 0, sizeof(active_list));
66 memset(sample_list, 0, sizeof(sample_list));
67 memset(data_list, 0, sizeof(data_list));
68 memset(deactivate, 0, sizeof(deactivate));
69}
70
71void WatchManager::add_watch(const char *id)
72{
73 //Don't add duplicate watchs
74 for(int i=0; i<MAX_WATCH; ++i)
75 if(!strcmp(active_list[i], id))
76 return;
77
78 //Apply to a free slot
79 for(int i=0; i<MAX_WATCH; ++i) {
80 if(!active_list[i][0]) {
81 strncpy(active_list[i], id, 128);
82 new_active = true;
83 sample_list[i] = 0;
84 break;
85 }
86 }
87}
88
89void WatchManager::del_watch(const char *id)
90{
91 //Queue up the delete
92 for(int i=0; i<MAX_WATCH; ++i)
93 if(!strcmp(active_list[i], id))
94 return (void) (deactivate[i] = true);
95}
96
98{
99 //Try to send out any vector stuff
100 for(int i=0; i<MAX_WATCH; ++i) {
101 if(sample_list[i]) {
102 char arg_types[MAX_SAMPLE+1] = {0};
103 rtosc_arg_t arg_val[MAX_SAMPLE];
104 for(int j=0; j<sample_list[i]; ++j) {
105 arg_types[j] = 'f';
106 arg_val[j].f = data_list[i][j];
107 }
108
109 write_back->writeArray(active_list[i], arg_types, arg_val);
110 deactivate[i] = true;
111 }
112 }
113
114 //Cleanup internal data
115 new_active = false;
116
117 //Clear deleted slots
118 for(int i=0; i<MAX_WATCH; ++i) {
119 if(deactivate[i]) {
120 memset(active_list[i], 0, 128);
121 sample_list[i] = 0;
122 deactivate[i] = false;
123 }
124 }
125
126}
127
128bool WatchManager::active(const char *id) const
129{
130 assert(this);
131 assert(id);
132 if(new_active || true)
133 for(int i=0; i<MAX_WATCH; ++i)
134 if(!strcmp(active_list[i], id))
135 return true;
136
137 return false;
138}
139
140int WatchManager::samples(const char *id) const
141{
142 for(int i=0; i<MAX_WATCH; ++i)
143 if(!strcmp(active_list[i], id))
144 return sample_list[i];
145 return 0;
146}
147
148void WatchManager::satisfy(const char *id, float f)
149{
150 //printf("trying to satisfy '%s'\n", id);
151 if(write_back)
152 write_back->write(id, "f", f);
153 del_watch(id);
154}
155
156void WatchManager::satisfy(const char *id, float *f, int n)
157{
158 int selected = -1;
159 for(int i=0; i<MAX_WATCH; ++i)
160 if(!strcmp(active_list[i], id))
161 selected = i;
162
163 if(selected == -1)
164 return;
165
166 //FIXME buffer overflow
167 for(int i=0; i<n; ++i)
168 data_list[selected][sample_list[selected]++] = f[i];
169}
170
171}
assert(0)
#define MAX_WATCH
Definition WatchPoint.h:33
#define MAX_SAMPLE
Definition WatchPoint.h:35
register unsigned j
Definition inflate.c:1576
register unsigned i
Definition inflate.c:1575
unsigned f
Definition inflate.c:1572
Definition zynaddsubfx-src.cpp:569
#define false
Definition ordinals.h:83
FloatWatchPoint(WatchManager *ref, const char *prefix, const char *id)
Definition WatchPoint.cpp:54
VecWatchPoint(WatchManager *ref, const char *prefix, const char *id)
Definition WatchPoint.cpp:58
Definition WatchPoint.h:37
void add_watch(const char *)
Definition WatchPoint.cpp:71
void satisfy(const char *, float)
Definition WatchPoint.cpp:148
char active_list[MAX_WATCH][MAX_WATCH_PATH]
Definition WatchPoint.h:41
bool active(const char *) const
Definition WatchPoint.cpp:128
WatchManager(thrlnk *link=0)
Definition WatchPoint.cpp:62
rtosc::ThreadLink thrlnk
Definition WatchPoint.h:38
void tick(void)
Definition WatchPoint.cpp:97
thrlnk * write_back
Definition WatchPoint.h:39
float data_list[MAX_SAMPLE][MAX_WATCH]
Definition WatchPoint.h:42
bool new_active
Definition WatchPoint.h:40
int samples(const char *) const
Definition WatchPoint.cpp:140
void del_watch(const char *)
Definition WatchPoint.cpp:89
int sample_list[MAX_WATCH]
Definition WatchPoint.h:43
bool deactivate[MAX_WATCH]
Definition WatchPoint.h:44
WatchPoint(WatchManager *ref, const char *prefix, const char *id)
Definition WatchPoint.cpp:28
WatchManager * reference
Definition WatchPoint.h:26
bool active
Definition WatchPoint.h:24
bool is_active(void)
Definition WatchPoint.cpp:38
char identity[128]
Definition WatchPoint.h:27
int samples_left
Definition WatchPoint.h:25
Definition rtosc.h:46
float f
Definition rtosc.h:49
int n
Definition crypt.c:458