1
// -------------------------------------------------------------------------
3
// Copyright (C) 2006-2009 Fons Adriaensen <fons@kokkinizita.net>
5
// This program is free software; you can redistribute it and/or modify
6
// it under the terms of the GNU General Public License as published by
7
// the Free Software Foundation; either version 2 of the License, or
8
// (at your option) any later version.
10
// This program is distributed in the hope that it will be useful,
11
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
// GNU General Public License for more details.
15
// You should have received a copy of the GNU General Public License
16
// along with this program; if not, write to the Free Software
17
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19
// -------------------------------------------------------------------------
31
Sgenwin::Sgenwin (X_window *parw, X_resman *resman, X_callback *callb) :
32
X_window (parw, XPOS, YPOS, XDEF, YDEF, XftColors.main_bg->pixel),
39
_xatom = XInternAtom (dpy (), "WM_DELETE_WINDOW", True);
40
XSetWMProtocols (dpy (), win (), &_xatom, 1);
41
_xatom = XInternAtom (dpy (), "WM_PROTOCOLS", True);
44
H.minsize (XDEF, YDEF);
45
H.maxsize (XDEF, YDEF);
46
H.position (XPOS, YPOS);
47
H.rname (resman->rname ());
48
H.rclas (resman->rclas ());
51
sprintf (s, "%s-%s [%s] Sweep", PROGNAME, VERSION, resman->rname ());
53
x_add_events (ExposureMask);
55
_ready = new X_textip (this, 0, &Tst0, 330, 10, 50, 17, 7);
56
_ready->set_text ("Ready");
57
_tname = new X_textip (this, this, &Tst1, 100, 10, 220, 17, 256);
59
_trate = new X_textip (this, this, &Tst1, 100, 34, 80, 17, 256, _tname);
61
_ttim1 = new X_textip (this, this, &Tst1, 100, 58, 80, 17, 256, _trate);
62
_ttim1->set_text ("0.1");
64
_tfmin = new X_textip (this, this, &Tst1, 100, 82, 80, 17, 256, _ttim1);
65
_tfmin->set_text ("20");
67
_ttim2 = new X_textip (this, this, &Tst1, 100, 106, 80, 17, 256, _tfmin);
68
_ttim2->set_text ("10");
70
_tfmax = new X_textip (this, this, &Tst1, 100, 130, 80, 17, 256, _ttim2);
71
_tfmax->set_text ("20e3");
73
_ttim3 = new X_textip (this, this, &Tst1, 100, 154, 80, 17, 256, _tfmax);
74
_ttim3->set_text ("0.03");
78
_blin = new X_tbutton (this, this, &Bst0, 240, 106, "Lin", 0, B_LIN);
80
_blog = new X_tbutton (this, this, &Bst0, 277, 106, "Log", 0, B_LOG);
85
_bsgen = new X_tbutton (this, this, &Bst0, 355, 130, "Create", 0, B_SGEN);
88
_bcanc = new X_tbutton (this, this, &Bst0, 355, 154, "Close", 0, B_CANC);
91
add_text ( 10, 10, 80, 17, "Name", 1);
92
add_text ( 10, 34, 80, 17, "Rate", 1);
93
add_text ( 10, 58, 80, 17, "Fade in", 1);
94
add_text ( 10, 82, 80, 17, "Start freq", 1);
95
add_text ( 10, 106, 80, 17, "Sweep time", 1);
96
add_text ( 10, 130, 80, 17, "End freq", 1);
97
add_text ( 10, 154, 80, 17, "Fade out", 1);
98
add_text (185, 106, 45, 17, "Type", 1);
104
Sgenwin::~Sgenwin (void)
109
void Sgenwin::handle_callb (int type, X_window *W, _XEvent *E)
113
case TEXTIP | X_textip::BUT:
114
XSetInputFocus (dpy (), W->win (), RevertToPointerRoot, CurrentTime);
118
case TEXTIP | X_textip::KEY:
121
case BUTTON | X_button::RELSE:
123
X_button *B = (X_button *) W;
152
void Sgenwin::handle_event (XEvent *E)
157
xcmesg ((XClientMessageEvent *) E);
163
void Sgenwin::xcmesg (XClientMessageEvent *E)
165
if (E->message_type == _xatom) hide ();
169
void Sgenwin::show (void)
173
sprintf (s, "%d", _rate);
174
_trate->set_text (s);
175
_tname->set_text ("");
181
void Sgenwin::hide (void)
187
void Sgenwin::add_text (int xp, int yp, int xs, int ys, const char *text, int align)
189
(new X_textln (this, &Tst0, xp, yp, xs, ys, text, align))->x_map ();
193
void Sgenwin::askdata (X_textip *T)
196
XSetInputFocus (dpy (), T->win (), RevertToPointerRoot, CurrentTime);
200
void Sgenwin::gensweep (void)
207
if ((sscanf (_tname->text (), "%s", name) != 1) || (*name == '?'))
212
if ((sscanf (_trate->text (), "%d", &rate) != 1) || (rate < 8000) || (rate > 96000))
218
if ((sscanf (_ttim1->text (), "%f", &t0) != 1) || (t0 < 0.0) || (t0 > 1.0f))
223
if ((sscanf (_tfmin->text (), "%f", &_fmin) != 1) || (_fmin < 1.0f) || (_fmin > 0.25f * rate))
228
if ((sscanf (_ttim2->text (), "%f", &t1) != 1) || (t1 < 1.0f) || (t1 > 100.0f))
233
if ((sscanf (_tfmax->text (), "%f", &_fmax) != 1) || (_fmax < 2 * _fmin) || (_fmax > 0.50f *rate))
238
if ((sscanf (_ttim3->text (), "%f", &t2) != 1) || (t2 < 0.0f) || (t2 > 1.0f))
244
_k0 = (int)(t0 * rate);
245
_k1 = (int)(t1 * rate);
246
_k2 = (int)(t2 * rate);
249
sprintf (path, "%s/sweep/%s", _sess, name);
250
Impdata::checkext (path);
251
_impd.set_type (Impdata::TYPE_SWEEP);
252
_impd.set_rate (rate, 1);
253
_impd.set_n_sect (1);
254
_impd.set_n_fram (k);
256
if (_impd.open_write (path))
258
fprintf (stderr, "Can't create '%s'\n", path);
261
if (_blog->stat ()) genlogsweep ();
263
_impd.write_sect (0);
270
void Sgenwin::genlogsweep (void)
273
double a, b, g, q, q0, p, r, x;
276
b = log (_fmax / _fmin) / _k1;
277
a = _fmin / (b * _rate);
278
r = 0.5 * a * (_fmax / _fmin) * (_k1 + 0.5 * (_k0 + _k2)) / (b * _k1);
280
s2 = _impd.data (1) + 2 * (_impd.n_fram () - 1);
281
q0 = a * exp (-b * _k0);
282
for (i = -_k0; i < _k1 + _k2; i++)
284
if (i < 0) g = cos (0.5 * M_PI * i / _k0);
285
else if (i < _k1) g = 1.0;
286
else g = sin (0.5 * M_PI * (_k1 + _k2 - i) / _k2);
289
x = g * sin (2 * M_PI * (p - floor (p)));
291
*s2 = (float)(x * q / r);
298
void Sgenwin::genlinsweep (void)
301
double a, b, g, p, r, x;
305
b = (_fmax - _fmin) / (2.0 * _rate * _k1);
306
r = 2.0 / (_k1 + 0.5 * (_k0 + _k2));
308
s2 = _impd.data (1) + 2 * (_impd.n_fram () - 1);
310
for (i = 0; i < _k0 + _k1 + _k2; i++)
312
if (i < _k0) g = sin (0.5 * M_PI * i / _k0);
313
else if (i < _k0 + _k1) g = 1.0;
314
else g = sin (0.5 * M_PI * (_k0 + _k1 + _k2 - i) / _k2);
316
x = g * sin (2 * M_PI * (p - floor (p)));
318
*s2 = (float)(x * r);