/
monitor.c
184 lines (154 loc) · 4.86 KB
/
monitor.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
/*
* Flickernoise
* Copyright (C) 2010, 2011, 2012 Sebastien Bourdeauducq
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <stdlib.h>
#include <rtems.h>
#include <mtklib.h>
#include "../input.h"
#include "resmgr.h"
#include "../renderer/framedescriptor.h"
#include "../renderer/sampler.h"
#include "monitor.h"
static int appid;
static int w_open;
static float time2, frame;
static float bass, mid, treb;
static float bass_att, mid_att, treb_att;
static float idmx[IDMX_COUNT];
static float osc[OSC_COUNT];
static void sampler_callback(struct frame_descriptor *frd)
{
int i;
time2 = frd->time;
frame = frd->frame;
bass = frd->bass;
mid = frd->mid;
treb = frd->treb;
bass_att = frd->bass_att;
mid_att = frd->mid_att;
treb_att = frd->treb_att;
for(i=0;i<IDMX_COUNT;i++)
idmx[i] = frd->idmx[i];
for(i=0;i<OSC_COUNT;i++)
osc[i] = frd->osc[i];
sampler_return(frd);
}
static float *get_variable(const char *name)
{
if(strcmp(name, "time") == 0) return &time2;
if(strcmp(name, "frame") == 0) return &frame;
else if(strcmp(name, "bass") == 0) return &bass;
else if(strcmp(name, "mid") == 0) return ∣
else if(strcmp(name, "treb") == 0) return &treb;
else if(strcmp(name, "bass_att") == 0) return &bass_att;
else if(strcmp(name, "mid_att") == 0) return &mid_att;
else if(strcmp(name, "treb_att") == 0) return &treb_att;
else if(strcmp(name, "idmx1") == 0) return &idmx[0];
else if(strcmp(name, "idmx2") == 0) return &idmx[1];
else if(strcmp(name, "idmx3") == 0) return &idmx[2];
else if(strcmp(name, "idmx4") == 0) return &idmx[3];
else if(strcmp(name, "idmx5") == 0) return &idmx[4];
else if(strcmp(name, "idmx6") == 0) return &idmx[5];
else if(strcmp(name, "idmx7") == 0) return &idmx[6];
else if(strcmp(name, "idmx8") == 0) return &idmx[7];
else if(strcmp(name, "osc1") == 0) return &osc[0];
else if(strcmp(name, "osc2") == 0) return &osc[1];
else if(strcmp(name, "osc3") == 0) return &osc[2];
else if(strcmp(name, "osc4") == 0) return &osc[3];
else return NULL;
}
#define UPDATE_PERIOD 10
static rtems_interval next_update;
static void monitor_update(mtk_event *e, int count)
{
int i;
float *var;
char str[16];
rtems_interval t;
t = rtems_clock_get_ticks_since_boot();
if(t >= next_update) {
for(i=0;i<8;i++) {
mtk_reqf(appid, str, sizeof(str), "var%d.text", i);
var = get_variable(str);
if(var == NULL)
mtk_cmdf(appid, "val%d.set(-text \"\e--\")", i);
else
mtk_cmdf(appid, "val%d.set(-text \"\e%.2f\")", i, *var);
}
next_update = t + UPDATE_PERIOD;
}
}
static void close_callback(mtk_event *e, void *arg)
{
mtk_cmd(appid, "w.close()");
sampler_stop();
input_delete_callback(monitor_update);
resmgr_release(RESOURCE_AUDIO);
resmgr_release(RESOURCE_DMX_IN);
resmgr_release(RESOURCE_SAMPLER);
w_open = 0;
}
void init_monitor(void)
{
int i;
int column;
int brow;
appid = mtk_init_app("Variable monitor");
mtk_cmd(appid, "g = new Grid()");
for(i=0;i<8;i++) {
column = i > 3 ? 3 : 1;
brow = i & 3;
mtk_cmdf(appid, "var%d = new Entry()", i);
mtk_cmdf(appid, "val%d = new Label(-text \"\e--\")", i);
mtk_cmdf(appid, "g.place(var%d, -column %d -row %d)", i, column, 3*brow+1);
mtk_cmdf(appid, "g.place(val%d, -column %d -row %d)", i, column, 3*brow+2);
/* Put a horizontal separator everywhere except for the last row */
if(brow != 3) {
mtk_cmdf(appid, "sep%d = new Separator(-vertical no)", i);
mtk_cmdf(appid, "g.place(sep%d, -column %d -row %d)", i, column, 3*brow+3);
}
}
for(i=0;i<11;i++) {
mtk_cmdf(appid, "vsep%d = new Separator(-vertical yes)", i);
mtk_cmdf(appid, "g.place(vsep%d, -column 2 -row %d)", i, i+1);
}
mtk_cmd(appid, "g.columnconfig(1, -weight 1 -size 100)");
mtk_cmd(appid, "g.columnconfig(3, -weight 1 -size 100)");
mtk_cmd(appid, "w = new Window(-content g -title \"Variable monitor\")");
mtk_bind(appid, "w", "close", close_callback, NULL);
}
void open_monitor_window(void)
{
if(w_open) return;
if(!resmgr_acquire_multiple("Variable monitor",
RESOURCE_AUDIO,
RESOURCE_DMX_IN,
RESOURCE_SAMPLER,
INVALID_RESOURCE))
return;
w_open = 1;
mtk_cmd(appid, "w.open()");
next_update = rtems_clock_get_ticks_since_boot() + UPDATE_PERIOD;
input_add_callback(monitor_update);
sampler_start(sampler_callback);
}
void monitor_notify_changed(void)
{
if(!w_open) return;
sampler_stop();
sampler_start(sampler_callback);
}