Debian Codegraph @

faudiostream/architecture/faust/gui/faustqt.h

raw symbols SCIP
1 /************************************************************************
2 ************************************************************************
3 FAUST Architecture File
4 Copyright (C) 2003-2011 GRAME, Centre National de Creation Musicale
5 ---------------------------------------------------------------------
6 This Architecture section is free software; you can redistribute it
7 and/or modify it under the terms of the GNU General Public License
8 as published by the Free Software Foundation; either version 3 of
9 the License, or (at your option) any later version.
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 for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; If not, see <http://www.gnu.org/licenses/>.
18
19 ************************************************************************
20 ************************************************************************/
21 #ifndef __faustqt__
22 #define __faustqt__
23
24 #include <cassert>
25 #include <cmath>
26 #include <fstream>
27 #include <iostream>
28 #include <list>
29 #include <map>
30 #include <set>
31 #include <vector>
32 #include <stack>
33
34 #include <QApplication>
35 #include <QCheckBox>
36 #include <QColormap>
37 #include <QDial>
38 #include <QDoubleSpinBox>
39 #include <QGroupBox>
40 #include <QHBoxLayout>
41 #include <QLayout>
42 #include <QMouseEvent>
43 #include <QObject>
44 #include <QPainter>
45 #include <QProgressBar>
46 #include <QPushButton>
47 #include <QRadialGradient>
48 #include <QSlider>
49 #include <QStyle>
50 #include <QTabWidget>
51 #include <QTimer>
52 #include <QToolTip>
53 #include <QVBoxLayout>
54 #include <QWheelEvent>
55 #include <QWidget>
56
57 #include <QStyle>
58 #include <QCommonStyle>
59 #include <QStyleOptionSlider>
60 //#include <QtGui>
61
62 #include "faust/gui/GUI.h"
63
64 //----------------------------------
65
66 // for compatibility
67 #define minValue minimum
68 #define maxValue maximum
69
70
71 using namespace std;
72
73
74 //==============================BEGIN QSYNTHKNOB=====================================
75 //
76 // qsynthknob and qsynthDialVokiStyle borrowed from qsynth-0.3.3 by Rui Nuno Capela
77 // This widget is based on a design by Thorsten Wilms,
78 // implemented by Chris Cannam in Rosegarden,
79 // adapted for QSynth by Pedro Lopez-Cabanillas,
80 // improved for Qt4 by David Garcia Garzon.
81 //
82
83 #define DIAL_MIN (0.25 * M_PI)
84 #define DIAL_MAX (1.75 * M_PI)
85 #define DIAL_RANGE (DIAL_MAX - DIAL_MIN)
86
87 class qsynthDialVokiStyle : public QCommonStyle
88 {
89 public:
90 qsynthDialVokiStyle() {};
91 virtual ~qsynthDialVokiStyle() {};
92
93 virtual void drawComplexControl(ComplexControl cc, const QStyleOptionComplex *opt, QPainter *p, const QWidget *widget = 0) const
94 {
95 if (cc != QStyle::CC_Dial)
96 {
97 QCommonStyle::drawComplexControl(cc, opt, p, widget);
98 return;
99 }
100
101 const QStyleOptionSlider *dial = qstyleoption_cast<const QStyleOptionSlider *>(opt);
102 if (dial == NULL)
103 return;
104
105 double angle = DIAL_MIN // offset
106 + (DIAL_RANGE *
107 (double(dial->sliderValue - dial->minimum) /
108 (double(dial->maximum - dial->minimum))));
109 int degrees = int(angle * 180.0 / M_PI);
110 int side = dial->rect.width() < dial->rect.height() ? dial->rect.width() : dial->rect.height();
111 int xcenter = dial->rect.width() / 2;
112 int ycenter = dial->rect.height() / 2;
113 int notchWidth = 1 + side / 400;
114 int pointerWidth = 2 + side / 30;
115 int scaleShadowWidth = 1 + side / 100;
116 int knobBorderWidth = 0;
117 int ns = dial->tickInterval;
118 int numTicks = 1 + (dial->maximum + ns - dial->minimum) / ns;
119 int indent = int(0.15 * side) + 2;
120 int knobWidth = side - 2 * indent;
121 int shineFocus = knobWidth / 4;
122 int shineCenter = knobWidth / 5;
123 int shineExtension = shineCenter * 4;
124 int shadowShift = shineCenter * 2;
125 int meterWidth = side - 2 * scaleShadowWidth;
126
127 QPalette pal = opt->palette;
128 QColor knobColor = pal.mid().color();
129 QColor borderColor = knobColor.light();
130 QColor meterColor = (dial->state & State_Enabled) ?
131 QColor("orange") : pal.mid().color();
132 // pal.highlight().color() : pal.mid().color();
133 QColor background = pal.window().color();
134
135 p->save();
136 p->setRenderHint(QPainter::Antialiasing, true);
137
138 // The bright metering bit...
139
140 QConicalGradient meterShadow(xcenter, ycenter, -90);
141 meterShadow.setColorAt(0, meterColor.dark());
142 meterShadow.setColorAt(0.5, meterColor);
143 meterShadow.setColorAt(1.0, meterColor.light().light());
144 p->setBrush(meterShadow);
145 p->setPen(Qt::transparent);
146 p->drawPie(xcenter - meterWidth / 2, ycenter - meterWidth / 2,
147 meterWidth, meterWidth, (180 + 45) * 16, -(degrees - 45) * 16);
148
149 // Knob projected shadow
150 QRadialGradient projectionGradient(
151 xcenter + shineCenter, ycenter + shineCenter,
152 shineExtension, xcenter + shadowShift, ycenter + shadowShift);
153 projectionGradient.setColorAt(0, QColor( 0, 0, 0, 100));
154 projectionGradient.setColorAt(1, QColor(200, 0, 0, 10));
155 QBrush shadowBrush(projectionGradient);
156 p->setBrush(shadowBrush);
157 p->drawEllipse(xcenter - shadowShift, ycenter - shadowShift,
158 knobWidth, knobWidth);
159
160 // Knob body and face...
161
162 QPen pen;
163 pen.setColor(knobColor);
164 pen.setWidth(knobBorderWidth);
165 p->setPen(pen);
166
167 QRadialGradient gradient(
168 xcenter - shineCenter, ycenter - shineCenter,
169 shineExtension, xcenter - shineFocus, ycenter - shineFocus);
170 gradient.setColorAt(0.2, knobColor.light().light());
171 gradient.setColorAt(0.5, knobColor);
172 gradient.setColorAt(1.0, knobColor.dark(150));
173 QBrush knobBrush(gradient);
174 p->setBrush(knobBrush);
175 p->drawEllipse(xcenter - knobWidth / 2, ycenter - knobWidth / 2,
176 knobWidth, knobWidth);
177
178 // Tick notches...
179
180 p->setBrush(Qt::NoBrush);
181
182 if (dial->subControls & QStyle::SC_DialTickmarks)
183 {
184 pen.setColor(pal.dark().color());
185 pen.setWidth(notchWidth);
186 p->setPen(pen);
187 double hyp = double(side - scaleShadowWidth) / 2.0;
188 double len = hyp / 4;
189 for (int i = 0; i < numTicks; ++i) {
190 int div = numTicks;
191 if (div > 1) --div;
192 bool internal = (i != 0 && i != numTicks - 1);
193 double angle = DIAL_MIN
194 + (DIAL_MAX - DIAL_MIN) * i / div;
195 double dir = (internal ? -1 : len);
196 double sinAngle = sin(angle);
197 double cosAngle = cos(angle);
198 double x0 = xcenter - (hyp - len) * sinAngle;
199 double y0 = ycenter + (hyp - len) * cosAngle;
200 double x1 = xcenter - (hyp + dir) * sinAngle;
201 double y1 = ycenter + (hyp + dir) * cosAngle;
202 p->drawLine(QLineF(x0, y0, x1, y1));
203 }
204 }
205
206 // Shadowing...
207
208 // Knob shadow...
209 if (knobBorderWidth > 0) {
210 QLinearGradient inShadow(xcenter - side / 4, ycenter - side / 4,
211 xcenter + side / 4, ycenter + side / 4);
212 inShadow.setColorAt(0.0, borderColor.light());
213 inShadow.setColorAt(1.0, borderColor.dark());
214 p->setPen(QPen(QBrush(inShadow), knobBorderWidth * 7 / 8));
215 p->drawEllipse(xcenter - side / 2 + indent,
216 ycenter - side / 2 + indent,
217 side - 2 * indent, side - 2 * indent);
218 }
219
220 // Scale shadow...
221 QLinearGradient outShadow(xcenter - side / 3, ycenter - side / 3,
222 xcenter + side / 3, ycenter + side / 3);
223 outShadow.setColorAt(0.0, background.dark().dark());
224 outShadow.setColorAt(1.0, background.light().light());
225 p->setPen(QPen(QBrush(outShadow), scaleShadowWidth));
226 p->drawArc(xcenter - side / 2 + scaleShadowWidth / 2,
227 ycenter - side / 2 + scaleShadowWidth / 2,
228 side - scaleShadowWidth, side - scaleShadowWidth, -45 * 16, 270 * 16);
229
230 // Pointer notch...
231
232 double hyp = double(side) / 2.0;
233 double len = hyp - indent - 1;
234
235 double x = xcenter - len * sin(angle);
236 double y = ycenter + len * cos(angle);
237
238 QColor pointerColor = pal.dark().color();
239 pen.setColor((dial->state & State_Enabled) ? pointerColor.dark(140) : pointerColor);
240 pen.setWidth(pointerWidth + 2);
241 p->setPen(pen);
242 p->drawLine(QLineF(xcenter, ycenter, x, y));
243 pen.setColor((dial->state & State_Enabled) ? pointerColor.light() : pointerColor.light(140));
244 pen.setWidth(pointerWidth);
245 p->setPen(pen);
246 p->drawLine(QLineF(xcenter - 1, ycenter - 1, x - 1, y - 1));
247
248 // done
249 p->restore();
250 }
251
252 };
253
254 //
255 //===============================END QSYNTHKNOB======================================
256
257
258 //==============================BEGIN DISPLAYS===================================
259 //
260 // This section constains displays, passive QT widgets that displays values in
261 // different ways, in particular bargraphs
262 //
263
264 /**
265 * An abstract widget that display a value in a range
266 */
267 class AbstractDisplay : public QWidget
268 {
269 protected :
270
271 FAUSTFLOAT fMin;
272 FAUSTFLOAT fMax;
273 FAUSTFLOAT fValue;
274
275 public:
276
277 AbstractDisplay(FAUSTFLOAT lo, FAUSTFLOAT hi) : fMin(lo), fMax(hi), fValue(lo)
278 {}
279
280 /**
281 * set the range of displayed values
282 */
283 virtual void setRange(FAUSTFLOAT lo, FAUSTFLOAT hi)
284 {
285 fMin = lo;
286 fMax = hi;
287 }
288
289 /**
290 * set the value to be displayed
291 */
292 virtual void setValue(FAUSTFLOAT v)
293 {
294 if (v < fMin) v = fMin;
295 else if (v > fMax) v = fMax;
296
297 if (v != fValue) {
298 fValue = v;
299 update();
300 }
301 }
302 };
303
304 /**
305 * Displays dB values using a scale of colors
306 */
307 class dbAbstractDisplay : public AbstractDisplay
308 {
309 protected :
310
311 FAUSTFLOAT fScaleMin;
312 FAUSTFLOAT fScaleMax;
313 vector<int> fLevel;
314 vector<QBrush> fBrush;
315
316
317 /**
318 * Convert a dB value into a scale between 0 and 1 (following IEC standard ?)
319 */
320 FAUSTFLOAT dB2Scale(FAUSTFLOAT dB) const
321 {
322 FAUSTFLOAT fScale = 1.0;
323
324 /*if (dB < -70.0f)
325 fScale = 0.0f;
326 else*/ if (dB < -60.0)
327 fScale = (dB + 70.0) * 0.0025;
328 else if (dB < -50.0)
329 fScale = (dB + 60.0) * 0.005 + 0.025;
330 else if (dB < -40.0)
331 fScale = (dB + 50.0) * 0.0075 + 0.075;
332 else if (dB < -30.0)
333 fScale = (dB + 40.0) * 0.015 + 0.15;
334 else if (dB < -20.0)
335 fScale = (dB + 30.0) * 0.02 + 0.3;
336 else if (dB < -0.001 || dB > 0.001) /* if (dB < 0.0) */
337 fScale = (dB + 20.0f) * 0.025 + 0.5;
338
339 return fScale;
340 }
341
342 /**
343 * Create the scale of colors used to paint the bargraph in relation to the levels
344 * The parameter x indicates the direction of the gradient. x=1 means an horizontal
345 * gradient typically used by a vertical bargraph, and x=0 a vertical gradient.
346 */
347 void initLevelsColors(int x)
348 {
349 int alpha = 200;
350 { // level until -10 dB
351 QColor c(40, 160, 40, alpha);
352 QLinearGradient g(0,0,x,1-x);
353 g.setCoordinateMode(QGradient::ObjectBoundingMode);
354 g.setColorAt(0.0, c.lighter());
355 g.setColorAt(0.2, c);
356 g.setColorAt(0.8, c);
357 g.setColorAt(0.9, c.darker(120));
358
359 fLevel.push_back(-10);
360 fBrush.push_back(QBrush(g));
361 }
362
363 { // level until -6 dB
364 QColor c(160, 220, 20, alpha);
365 QLinearGradient g(0,0,x,1-x);
366 g.setCoordinateMode(QGradient::ObjectBoundingMode);
367 g.setColorAt(0.0, c.lighter());
368 g.setColorAt(0.2, c);
369 g.setColorAt(0.8, c);
370 g.setColorAt(0.9, c.darker(120));
371
372 fLevel.push_back(-6);
373 fBrush.push_back(QBrush(g));
374 }
375
376 { // level until -3 dB
377 QColor c(220, 220, 20, alpha);
378 QLinearGradient g(0,0,x,1-x);
379 g.setCoordinateMode(QGradient::ObjectBoundingMode);
380 g.setColorAt(0.0, c.lighter());
381 g.setColorAt(0.2, c);
382 g.setColorAt(0.8, c);
383 g.setColorAt(0.9, c.darker(120));
384
385 fLevel.push_back(-3);
386 fBrush.push_back(QBrush(g));
387 }
388
389 { // level until -0 dB
390 QColor c(240, 160, 20, alpha);
391 QLinearGradient g(0,0,x,1-x);
392 g.setCoordinateMode(QGradient::ObjectBoundingMode);
393 g.setColorAt(0.0, c.lighter());
394 g.setColorAt(0.2, c);
395 g.setColorAt(0.8, c);
396 g.setColorAt(0.9, c.darker(120));
397
398 fLevel.push_back(0);
399 fBrush.push_back(QBrush(g));
400 }
401
402 { // until 10 dB (and over because last one)
403 QColor c(240, 0, 20, alpha); // ColorOver
404 QLinearGradient g(0,0,x,1-x);
405 g.setCoordinateMode(QGradient::ObjectBoundingMode);
406 g.setColorAt(0.0, c.lighter());
407 g.setColorAt(0.2, c);
408 g.setColorAt(0.8, c);
409 g.setColorAt(0.9, c.darker(120));
410
411 fLevel.push_back(+10);
412 fBrush.push_back(QBrush(g));
413 }
414
415 }
416
417 public:
418
419 dbAbstractDisplay(FAUSTFLOAT lo, FAUSTFLOAT hi) : AbstractDisplay(lo, hi)
420 {}
421
422 /**
423 * set the range of displayed values
424 */
425 virtual void setRange(FAUSTFLOAT lo, FAUSTFLOAT hi)
426 {
427 AbstractDisplay::setRange(lo, hi);
428 fScaleMin = dB2Scale(fMin);
429 fScaleMax = dB2Scale(fMax);
430 }
431 };
432
433 /**
434 * Small rectangular LED display which color changes with the level in dB
435 */
436 class dbLED : public dbAbstractDisplay
437 {
438 protected:
439
440 /**
441 * Draw the LED using a color depending of its value in dB
442 */
443 virtual void paintEvent ( QPaintEvent *)
444 {
445 QPainter painter(this);
446 painter.drawRect(rect());
447
448 if (fValue <= fLevel[0]) {
449
450 // interpolate the first color on the alpha channel
451 QColor c(40, 160, 40) ;
452 FAUSTFLOAT a = (fValue-fMin)/(fLevel[0]-fMin);
453 c.setAlphaF(a);
454 painter.fillRect(rect(), c);
455
456 } else {
457
458 // find the minimal level > value
459 int l = fLevel.size()-1; while (fValue < fLevel[l] && l > 0) l--;
460 painter.fillRect(rect(), fBrush[l]);
461 }
462 }
463
464 public:
465
466 dbLED(FAUSTFLOAT lo, FAUSTFLOAT hi) : dbAbstractDisplay(lo,hi)
467 {
468 setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
469 initLevelsColors(1);
470 }
471
472 virtual QSize sizeHint () const
473 {
474 return QSize(16, 8);
475 }
476 };
477
478 /**
479 * Small rectangular LED display which intensity (alpha channel) changes according to the value
480 */
481 class LED : public AbstractDisplay
482 {
483 QColor fColor;
484
485 protected:
486
487 /**
488 * Draw the LED using a transparency depending of its value
489 */
490 virtual void paintEvent ( QPaintEvent *)
491 {
492 QPainter painter(this);
493 painter.drawRect(rect());
494 // interpolate the first color on the alpha channel
495 QColor c = fColor ;
496 FAUSTFLOAT a = (fValue-fMin)/(fMax-fMin);
497 c.setAlphaF(a);
498 painter.fillRect(rect(), c);
499 }
500
501 public:
502
503 LED(FAUSTFLOAT lo, FAUSTFLOAT hi) : AbstractDisplay(lo,hi), fColor("yellow")
504 {
505 setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
506 }
507
508 virtual QSize sizeHint () const
509 {
510 return QSize(16, 8);
511 }
512 };
513
514 /**
515 * A simple bargraph that detect automatically its direction
516 */
517 class linBargraph : public AbstractDisplay
518 {
519 protected :
520 QBrush fBrush;
521
522 /**
523 * No scale implemented yet
524 */
525 void paintScale(QPainter* painter) const
526 {
527 painter->drawRect(0,0,width(),height());
528 }
529
530 /**
531 * The length of the rectangle is proportional to the value
532 */
533 void paintContent (QPainter* painter) const
534 {
535 int w = width();
536 int h = height();
537 FAUSTFLOAT v = (fValue-fMin)/(fMax-fMin);
538
539 if (h>w) {
540 // draw vertical rectangle
541 painter->fillRect(0,(1-v)*h,w, v*h, fBrush);
542 } else {
543 // draw horizontal rectangle
544 painter->fillRect(0, 0, h, v*w, fBrush);
545 }
546
547 }
548
549 virtual void paintEvent ( QPaintEvent *)
550 {
551 QPainter painter(this);
552 paintContent(&painter);
553 paintScale(&painter);
554 }
555
556 public:
557
558 linBargraph(FAUSTFLOAT lo, FAUSTFLOAT hi) : AbstractDisplay(lo,hi)
559 {
560 // compute the brush that will be used to
561 // paint the value
562 QColor c(0xffa500); // orange
563 int x = int(height() < width()); // gradient direction
564 QLinearGradient g(0,0,x,1-x);
565 g.setCoordinateMode(QGradient::ObjectBoundingMode);
566 g.setColorAt(0.0, c.lighter());
567 g.setColorAt(0.2, c);
568 g.setColorAt(0.8, c);
569 g.setColorAt(0.9, c.darker(120));
570 fBrush = QBrush(g);
571 }
572 };
573
574 /**
575 * A simple vertical bargraph
576 */
577 class linVerticalBargraph : public linBargraph
578 {
579 public:
580
581 linVerticalBargraph(FAUSTFLOAT lo, FAUSTFLOAT hi) : linBargraph(lo,hi)
582 {
583 setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
584 }
585
586 virtual QSize sizeHint () const
587 {
588 return QSize(16, 128);
589 }
590 };
591
592 /**
593 * A simple horizontal bargraph
594 */
595 class linHorizontalBargraph : public linBargraph
596 {
597 public:
598
599 linHorizontalBargraph(FAUSTFLOAT lo, FAUSTFLOAT hi) : linBargraph(lo,hi)
600 {
601 setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
602 }
603
604 virtual QSize sizeHint () const
605 {
606 return QSize(128, 16);
607 }
608 };
609
610 /**
611 * A dB Bargraph with a scale of colors
612 */
613 class dbBargraph : public dbAbstractDisplay
614 {
615 QBrush fBackColor;
616
617 protected :
618
619 // These two abstract methods are implemented
620 // according to the vertical or horizontal direction
621 // in dbVerticalBargraph and dbHorizontalBargraph
622 virtual void paintMark(QPainter* painter, FAUSTFLOAT v) const = 0;
623 virtual int paintSegment (QPainter* painter, int pos, FAUSTFLOAT v, const QBrush& b) const = 0;
624
625 /**
626 * Draw the logarithmic scale
627 */
628 void paintScale(QPainter* painter) const
629 {
630 painter->fillRect(0,0,width(),height(), fBackColor);
631 painter->save();
632 painter->setPen(QColor(0x6699aa)); //0xffa500));
633 for (FAUSTFLOAT v = -10; v > fMin; v -= 10) paintMark(painter, v);
634 for (FAUSTFLOAT v = -6; v < fMax; v += 3) paintMark(painter, v);
635 painter->restore();
636 }
637
638 /**
639 * Draw the content using colored segments
640 */
641 void paintContent (QPainter* painter) const
642 {
643 int l = fLevel.size();
644
645 FAUSTFLOAT p = -1; // fake value indicates to start from border
646 int n = 0;
647 // paint all the full segments < fValue
648 for (n=0; (n < l) && (fValue > fLevel[n]); n++) {
649 p = paintSegment(painter, p, fLevel[n], fBrush[n]);
650 }
651 // paint the last segment
652 if (n == l) n = n-1;
653 p=paintSegment(painter, p, fValue, fBrush[n]);
654
655 painter->drawRect(0,0,width(),height());
656 }
657
658
659 virtual void paintEvent ( QPaintEvent *)
660 {
661 QPainter painter(this);
662 paintScale(&painter);
663 paintContent(&painter);
664 }
665
666 public:
667
668 dbBargraph(FAUSTFLOAT lo, FAUSTFLOAT hi) : dbAbstractDisplay(lo,hi)
669 {
670
671 QFont f = this->font();
672 f.setPointSize(6);
673 this->setFont(f);
674
675 fBackColor = QBrush(QColor(20,20,20));
676 }
677 };
678
679 /**
680 * Vertical dB Bargraph
681 */
682 class dbVerticalBargraph : public dbBargraph
683 {
684 protected:
685 /**
686 * Convert a dB value into a vertical position
687 */
688 FAUSTFLOAT dB2y(FAUSTFLOAT dB) const
689 {
690 FAUSTFLOAT s0 = fScaleMin;
691 FAUSTFLOAT s1 = fScaleMax;
692 FAUSTFLOAT sx = dB2Scale(dB);
693 int h = height();
694
695 return h - h*(s0-sx)/(s0-s1);
696 }
697
698 /**
699 * Paint a vertical graduation mark
700 */
701 virtual void paintMark(QPainter* painter, FAUSTFLOAT v) const
702 {
703 int n = 10;
704 int y = dB2y(v);
705 QRect r(0,y-n,width()-1,2*n);
706 if (v > 0.0) {
707 painter->drawText(r, Qt::AlignRight|Qt::AlignVCenter, QString::number(v).prepend('+'));
708 } else {
709 painter->drawText(r, Qt::AlignRight|Qt::AlignVCenter, QString::number(v));
710 }
711 }
712
713 /**
714 * Paint a color segment
715 */
716 virtual int paintSegment(QPainter* painter, int pos, FAUSTFLOAT v, const QBrush& b) const
717 {
718 if (pos == -1) pos = height();
719 FAUSTFLOAT y = dB2y(v);
720 painter->fillRect(0, y, width(), pos-y+1, b);
721 return y;
722 }
723
724
725 public:
726
727 dbVerticalBargraph(FAUSTFLOAT lo, FAUSTFLOAT hi) : dbBargraph(lo,hi)
728 {
729 setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
730 initLevelsColors(1);
731 }
732
733 virtual QSize sizeHint () const
734 {
735 return QSize(18, 256);
736 }
737 };
738
739 /**
740 * Horizontal dB Bargraph
741 */
742 class dbHorizontalBargraph : public dbBargraph
743 {
744
745 protected:
746
747 /**
748 * Convert a dB value into an horizontal position
749 */
750 FAUSTFLOAT dB2x(FAUSTFLOAT dB) const
751 {
752 FAUSTFLOAT s0 = fScaleMin;
753 FAUSTFLOAT s1 = fScaleMax;
754 FAUSTFLOAT sx = dB2Scale(dB);
755 int w = width();
756
757 return w - w*(s1-sx)/(s1-s0);
758 }
759
760 /**
761 * Paint an horizontal graduation mark
762 */
763 void paintMark(QPainter* painter, FAUSTFLOAT v) const
764 {
765 int n = 10;
766 int x = dB2x(v);
767 QRect r(x-n,0,2*n, height());
768 painter->drawText(r, Qt::AlignHCenter|Qt::AlignVCenter, QString::number(v));
769 }
770
771 /**
772 * Paint a horizontal color segment
773 */
774 int paintSegment (QPainter* painter, int pos, FAUSTFLOAT v, const QBrush& b) const
775 {
776 if (pos == -1) pos = 0;
777 FAUSTFLOAT x = dB2x(v);
778 painter->fillRect(pos, 0, x-pos, height(), b);
779 return x;
780 }
781
782
783 public:
784
785 dbHorizontalBargraph(FAUSTFLOAT lo, FAUSTFLOAT hi) : dbBargraph(lo,hi)
786 {
787 setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
788 initLevelsColors(0);
789 }
790
791 virtual QSize sizeHint () const
792 {
793 return QSize(256, 18);
794 }
795
796 };
797
798 //
799 //===============================END DISPLAYS====================================
800
801 //============================= BEGIN GROUP LABEL METADATA===========================
802 // Unlike widget's label, metadata inside group's label are not extracted directly by
803 // the Faust compiler. Therefore they must be extracted within the architecture file
804 //-----------------------------------------------------------------------------------
805 //
806
807 /**
808 * rmWhiteSpaces(): Remove the leading and trailing white spaces of a string
809 * (but not those in the middle of the string)
810 */
811 static string rmWhiteSpaces(const string& s)
812 {
813 size_t i = s.find_first_not_of(" \t");
814 size_t j = s.find_last_not_of(" \t");
815 if ( (i != string::npos) && (j != string::npos) ) {
816 return s.substr(i, 1+j-i);
817 } else {
818 return "";
819 }
820 }
821
822 /**
823 * Extracts metdata from a label : 'vol [unit: dB]' -> 'vol' + metadata(unit=dB)
824 */
825 static void extractMetadata(const string& fulllabel, string& label, map<string, string>& metadata)
826 {
827 enum {kLabel, kEscape1, kEscape2, kEscape3, kKey, kValue};
828 int state = kLabel; int deep = 0;
829 string key, value;
830
831 for (unsigned int i=0; i < fulllabel.size(); i++) {
832 char c = fulllabel[i];
833 switch (state) {
834 case kLabel :
835 assert (deep == 0);
836 switch (c) {
837 case '\\' : state = kEscape1; break;
838 case '[' : state = kKey; deep++; break;
839 default : label += c;
840 }
841 break;
842
843 case kEscape1 :
844 label += c;
845 state = kLabel;
846 break;
847
848 case kEscape2 :
849 key += c;
850 state = kKey;
851 break;
852
853 case kEscape3 :
854 value += c;
855 state = kValue;
856 break;
857
858 case kKey :
859 assert (deep > 0);
860 switch (c) {
861 case '\\' : state = kEscape2;
862 break;
863
864 case '[' : deep++;
865 key += c;
866 break;
867
868 case ':' : if (deep == 1) {
869 state = kValue;
870 } else {
871 key += c;
872 }
873 break;
874 case ']' : deep--;
875 if (deep < 1) {
876 metadata[rmWhiteSpaces(key)] = "";
877 state = kLabel;
878 key="";
879 value="";
880 } else {
881 key += c;
882 }
883 break;
884 default : key += c;
885 }
886 break;
887
888 case kValue :
889 assert (deep > 0);
890 switch (c) {
891 case '\\' : state = kEscape3;
892 break;
893
894 case '[' : deep++;
895 value += c;
896 break;
897
898 case ']' : deep--;
899 if (deep < 1) {
900 metadata[rmWhiteSpaces(key)]=rmWhiteSpaces(value);
901 state = kLabel;
902 key="";
903 value="";
904 } else {
905 value += c;
906 }
907 break;
908 default : value += c;
909 }
910 break;
911
912 default :
913 cerr << "ERROR unrecognized state " << state << endl;
914 }
915 }
916 label = rmWhiteSpaces(label);
917 }
918
919 //
920 //============================= END GROUP LABEL METADATA===========================
921
922
923 /******************************************************************************
924 *******************************************************************************
925
926 IMPLEMENTATION OF GUI ITEMS
927 (QT 4.3 for FAUST)
928
929 *******************************************************************************
930 *******************************************************************************/
931
932 class uiButton : public QObject, public uiItem
933 {
934 Q_OBJECT
935
936 public :
937 QAbstractButton* fButton;
938
939 uiButton (GUI* ui, FAUSTFLOAT* zone, QAbstractButton* b) : uiItem(ui, zone), fButton(b) {}
940
941
942 virtual void reflectZone()
943 {
944 FAUSTFLOAT v = *fZone;
945 fCache = v;
946 fButton->setDown( v > 0.0 );
947 }
948
949 public slots :
950 void pressed() { modifyZone(1.0); }
951 void released() { modifyZone(0.0); }
952 };
953
954 class uiCheckButton : public QObject, public uiItem
955 {
956 Q_OBJECT
957
958 public :
959 QCheckBox* fCheckBox;
960
961 uiCheckButton (GUI* ui, FAUSTFLOAT* zone, QCheckBox* b) : uiItem(ui, zone), fCheckBox(b) {}
962
963 virtual void reflectZone()
964 {
965 FAUSTFLOAT v = *fZone;
966 fCache = v;
967 fCheckBox->setCheckState( (v < 0.5) ? Qt::Unchecked : Qt::Checked );
968 }
969
970 public slots :
971 void setState(int v) { modifyZone(FAUSTFLOAT(v>0)); }
972 };
973
974 class uiSlider : public QObject, public uiItem
975 {
976 Q_OBJECT
977
978 int faust2qt(FAUSTFLOAT x) { return int(0.5 + (x-fMin)/fStep); }
979 FAUSTFLOAT qt2faust (int v) { return fMin + v*fStep; }
980 int optimalTick() {
981 FAUSTFLOAT x = fStep;
982 while ((fMax-fMin)/x > 50) x*=10;
983 while ((fMax-fMin)/x < 10) x/=2;
984 return faust2qt(fMin+x);
985 }
986
987 public :
988 QSlider* fSlider;
989 FAUSTFLOAT fCur;
990 FAUSTFLOAT fMin;
991 FAUSTFLOAT fMax;
992 FAUSTFLOAT fStep;
993
994 uiSlider (GUI* ui, FAUSTFLOAT* zone, QSlider* slider, FAUSTFLOAT cur, FAUSTFLOAT lo, FAUSTFLOAT hi, FAUSTFLOAT step)
995 : uiItem(ui, zone), fSlider(slider), fCur(cur), fMin(lo), fMax(hi), fStep(step)
996 {
997 fSlider->setMinimum(0);
998 fSlider->setMaximum(faust2qt(fMax));
999 fSlider->setValue(faust2qt(fCur));
1000 fSlider->setTickInterval(optimalTick());
1001 *fZone = fCur;
1002 }
1003
1004 virtual void reflectZone()
1005 {
1006 FAUSTFLOAT v = *fZone;
1007 fCache = v;
1008 fSlider->setValue(faust2qt(v));
1009 }
1010
1011 public slots :
1012 void setValue(int v) { modifyZone(qt2faust(v)); }
1013 };
1014
1015 class uiKnob : public QObject, public uiItem
1016 {
1017 Q_OBJECT
1018
1019 int faust2qt(FAUSTFLOAT x) { return int(0.5 + (x-fMin)/fStep); }
1020 FAUSTFLOAT qt2faust (int v) { return fMin + v*fStep; }
1021 int optimalTick() {
1022 FAUSTFLOAT x = fStep;
1023 while ((fMax-fMin)/x > 50) x*=10;
1024 while ((fMax-fMin)/x < 10) x/=2;
1025 return faust2qt(fMin+x);
1026 }
1027
1028 public :
1029 QAbstractSlider* fSlider;
1030 FAUSTFLOAT fCur;
1031 FAUSTFLOAT fMin;
1032 FAUSTFLOAT fMax;
1033 FAUSTFLOAT fStep;
1034
1035 uiKnob (GUI* ui, FAUSTFLOAT* zone, QAbstractSlider* slider, FAUSTFLOAT cur, FAUSTFLOAT lo, FAUSTFLOAT hi, FAUSTFLOAT step)
1036 : uiItem(ui, zone), fSlider(slider), fCur(cur), fMin(lo), fMax(hi), fStep(step)
1037 {
1038 fSlider->setMinimum(0);
1039 fSlider->setMaximum(faust2qt(fMax));
1040 fSlider->setValue(faust2qt(fCur));
1041 //fSlider->setTickInterval(optimalTick());
1042 *fZone = fCur;
1043 }
1044
1045 virtual void reflectZone()
1046 {
1047 FAUSTFLOAT v = *fZone;
1048 fCache = v;
1049 fSlider->setValue(faust2qt(v));
1050 }
1051
1052 public slots :
1053 void setValue(int v) { modifyZone(qt2faust(v)); }
1054 };
1055
1056 class uiBargraph : public QObject, public uiItem
1057 {
1058 Q_OBJECT
1059
1060 int faust2qt(FAUSTFLOAT x) { return int(0.5 + (x-fMin)/(fMax-fMin)*fStep); }
1061
1062 public :
1063 QProgressBar* fBar;
1064 FAUSTFLOAT fMin;
1065 FAUSTFLOAT fMax;
1066 int fStep;
1067
1068 uiBargraph (GUI* ui, FAUSTFLOAT* zone, QProgressBar* bar, FAUSTFLOAT lo, FAUSTFLOAT hi)
1069 : uiItem(ui, zone), fBar(bar), fMin(lo), fMax(hi), fStep(1024)
1070 {
1071 fBar->setRange(0, fStep);
1072 fBar->setValue(0);
1073 *fZone = 0;
1074 }
1075
1076 virtual void reflectZone()
1077 {
1078 FAUSTFLOAT v = *fZone;
1079 fCache = v;
1080 int x = faust2qt(v);
1081 //std::cout << "update *" << fBar << " = " << x << std::endl;
1082 fBar->setValue(x);
1083 }
1084 };
1085
1086 class uiBargraph2 : public QObject, public uiItem
1087 {
1088 Q_OBJECT
1089
1090 public :
1091 AbstractDisplay* fBar;
1092
1093 uiBargraph2 (GUI* ui, FAUSTFLOAT* zone, AbstractDisplay* bar, FAUSTFLOAT lo, FAUSTFLOAT hi)
1094 : uiItem(ui, zone), fBar(bar)
1095 {
1096 fBar->setRange(lo, hi);
1097 fBar->setValue(lo);
1098 *fZone = lo;
1099 }
1100
1101 virtual void reflectZone()
1102 {
1103 FAUSTFLOAT v = *fZone;
1104 fCache = v;
1105 fBar->setValue(v);
1106 }
1107 };
1108
1109 class uiNumEntry : public QObject, public uiItem
1110 {
1111 Q_OBJECT
1112
1113 public :
1114 QDoubleSpinBox* fNumEntry;
1115 FAUSTFLOAT fCur;
1116 FAUSTFLOAT fMin;
1117 FAUSTFLOAT fMax;
1118 FAUSTFLOAT fStep;
1119 int fDecimals;
1120
1121 uiNumEntry (GUI* ui, FAUSTFLOAT* zone, QDoubleSpinBox* numEntry, FAUSTFLOAT cur, FAUSTFLOAT lo, FAUSTFLOAT hi, FAUSTFLOAT step)
1122 : uiItem(ui, zone), fNumEntry(numEntry), fCur(cur), fMin(lo), fMax(hi), fStep(step)
1123 {
1124 fDecimals = (fStep >= 1.0) ? 0 : int(0.5+log10(1.0/fStep));
1125
1126 fNumEntry->setMinimum(fMin);
1127 fNumEntry->setMaximum(fMax);
1128 fNumEntry->setSingleStep(fStep);
1129 fNumEntry->setDecimals(fDecimals);
1130 fNumEntry->setValue(fCur);
1131 *fZone = fCur;
1132 }
1133
1134
1135 virtual void reflectZone()
1136 {
1137 FAUSTFLOAT v = *fZone;
1138 fCache = v;
1139 fNumEntry->setValue(v);
1140 }
1141
1142 public slots :
1143 void setValue(double v) {
1144 modifyZone(FAUSTFLOAT(v));
1145 }
1146 };
1147
1148 /******************************************************************************
1149 *******************************************************************************
1150
1151 IMPLEMENTATION OF THE USER INTERFACE
1152 (QT 4.3 for FAUST)
1153
1154 *******************************************************************************
1155 *******************************************************************************/
1156
1157 class QTGUI : public QObject, public GUI
1158 {
1159 Q_OBJECT
1160 QApplication fAppl;
1161 QTimer* fTimer;
1162 QStyle* fStyle;
1163 string gGroupTooltip;
1164 stack<QWidget* > fGroupStack;
1165
1166 map<FAUSTFLOAT*, FAUSTFLOAT> fGuiSize; // map widget zone with widget size coef
1167 map<FAUSTFLOAT*, string> fTooltip; // map widget zone with tooltip strings
1168 map<FAUSTFLOAT*, string> fUnit; // map widget zone to unit string (i.e. "dB")
1169 set<FAUSTFLOAT*> fKnobSet; // set of widget zone to be knobs
1170 set<FAUSTFLOAT*> fLedSet; // set of widget zone to be LEDs
1171
1172
1173 /**
1174 * Format tooltip string by replacing some white spaces by
1175 * return characters so that line width doesn't exceed n.
1176 * Limitation : long words exceeding n are not cut
1177 */
1178 virtual string formatTooltip(int n, const string& tt)
1179 {
1180 string ss = tt; // ss string we are going to format
1181 int lws = 0; // last white space encountered
1182 int lri = 0; // last return inserted
1183 for (int i=0; i< (int)tt.size(); i++) {
1184 if (tt[i] == ' ') lws = i;
1185 if (((i-lri) >= n) && (lws > lri)) {
1186 // insert return here
1187 ss[lws] = '\n';
1188 lri = lws;
1189 }
1190 }
1191 return ss;
1192 }
1193
1194 /**
1195 * Analyses the widget zone metadata declarations and takes
1196 * appropriate actions
1197 */
1198 virtual void declare(FAUSTFLOAT* zone, const char* key, const char* value)
1199 {
1200 if (zone == 0) {
1201 // special zone 0 means group metadata
1202 if (strcmp(key,"tooltip")==0) {
1203 // only group tooltip are currently implemented
1204 gGroupTooltip = formatTooltip(30, value);
1205 }
1206 } else {
1207 if (strcmp(key,"size")==0) {
1208 fGuiSize[zone]=atof(value);
1209 }
1210 else if (strcmp(key,"tooltip")==0) {
1211 fTooltip[zone] = formatTooltip(30, value) ;
1212 }
1213 else if (strcmp(key,"unit")==0) {
1214 fUnit[zone] = value ;
1215 }
1216 else if (strcmp(key,"style")==0) {
1217 // else if ((strcmp(key,"style")==0) || (strcmp(key,"type")==0)) {
1218 if (strcmp(value,"knob") == 0) {
1219 fKnobSet.insert(zone);
1220 } else if (strcmp(value,"led") == 0) {
1221 fLedSet.insert(zone);
1222 }
1223 }
1224 }
1225 }
1226
1227 bool isTabContext()
1228 {
1229 //return fGroupStack.empty() || ((!fGroupStack.empty()) && (dynamic_cast<QTabWidget*>(fGroupStack.top()) != 0));
1230 return ((!fGroupStack.empty()) && (dynamic_cast<QTabWidget*>(fGroupStack.top()) != 0));
1231 }
1232
1233 void insert(const char* label, QWidget* widget)
1234 {
1235 if (fStyle) widget->setStyle(fStyle);
1236 if (!fGroupStack.empty()) {
1237 QWidget* mother = fGroupStack.top();
1238 QTabWidget* tab = dynamic_cast<QTabWidget*>(mother);
1239 if (tab) {
1240 tab->addTab(widget,label);
1241 } else {
1242 widget->setParent(mother);
1243 mother->layout()->addWidget(widget);
1244 }
1245 }
1246 }
1247
1248 /**
1249 * Analyses a full label and activates the relevant options. returns a simplified
1250 * label (without options) and an amount of stack adjustement (in case additional
1251 * containers were pushed on the stack).
1252 */
1253
1254 int checkLabelOptions(QWidget* widget, const string& fullLabel, string& simplifiedLabel)
1255 {
1256 map<string, string> metadata;
1257 extractMetadata(fullLabel, simplifiedLabel, metadata);
1258
1259 if (metadata.count("tooltip")) {
1260 widget->setToolTip(metadata["tooltip"].c_str());
1261 }
1262 if (metadata["option"] == "detachable") {
1263 //openHandleBox(simplifiedLabel.c_str());
1264 return 1;
1265 }
1266
1267 // no adjustement of the stack needed
1268 return 0;
1269 }
1270
1271 /**
1272 * Check if a tooltip is associated to a zone and add it to the corresponding widget
1273 */
1274 void checkForTooltip(FAUSTFLOAT* zone, QWidget* widget)
1275 {
1276 if (fTooltip.count(zone)) {
1277 widget->setToolTip(fTooltip[zone].c_str());
1278 }
1279 }
1280
1281 /**
1282 * Check if a knob is required
1283 */
1284 bool isKnob(FAUSTFLOAT* zone)
1285 {
1286 return fKnobSet.count(zone) > 0;
1287 }
1288
1289 void openBox(const char* fulllabel, QLayout* layout)
1290 {
1291 map<string, string> metadata;
1292 string label;
1293 extractMetadata(fulllabel, label, metadata);
1294 layout->setMargin(5);
1295 QWidget* box;
1296
1297
1298 if (isTabContext()) {
1299 box = new QWidget();
1300 // set background color
1301 QPalette pal = box->palette();
1302 pal.setColor(box->backgroundRole(), QColor::fromRgb(150, 150, 150) );
1303 box->setPalette(pal);
1304
1305 } else if (label.size()>0) {
1306 QGroupBox* group = new QGroupBox();
1307 group->setTitle(label.c_str());
1308 box = group;
1309 } else {
1310 // no label here we use simple widget
1311 layout->setMargin(0);
1312 box = new QWidget();
1313 }
1314
1315 box->setLayout(layout);
1316 /* if (metadata.count("tooltip")) {
1317 box->setToolTip(metadata["tooltip"].c_str());
1318 }*/
1319 if (gGroupTooltip != string()) {
1320 box->setToolTip(gGroupTooltip.c_str());
1321 gGroupTooltip = string();
1322 }
1323 insert(label.c_str(), box);
1324 fGroupStack.push(box);
1325 }
1326
1327 void openTab(const char* label)
1328 {
1329 QTabWidget* group = new QTabWidget();
1330 if (fStyle) group->setStyle(fStyle);
1331 insert(label, group);
1332 fGroupStack.push(group);
1333 }
1334
1335 public slots :
1336
1337 void update() {
1338 //std::cout << '.' << std::endl;
1339 updateAllZones();
1340 }
1341
1342 public:
1343
1344 QTGUI(int &argc, char* argv[], QStyle* style = 0) : fAppl(argc, argv), fTimer(0), fStyle(style){
1345 //fGroupStack.push(new QMainWindow());
1346 }
1347
1348 virtual ~QTGUI() {}
1349
1350 virtual void run()
1351 {
1352 if (fTimer == 0) {
1353 fTimer = new QTimer(this);
1354 QObject::connect(fTimer, SIGNAL(timeout()), this, SLOT(update()));
1355 fTimer->start(100);
1356 }
1357 #if 0
1358 fAppl.setStyleSheet(
1359
1360 // BUTTONS
1361 "QPushButton {"
1362 "background-color: qlineargradient(x1: 0, y1: 0, x2: 1, y2: 1,"
1363 "stop: 0 #B0B0B0, stop: 1 #404040);"
1364 "border: 2px solid grey;"
1365 "border-radius: 6px;"
1366 "margin-top: 1ex;"
1367 "}"
1368
1369 "QPushButton:hover {"
1370 "border: 2px solid orange;"
1371 "}"
1372
1373 "QPushButton:pressed {"
1374 //"border: 1px solid orange;"
1375 "background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,"
1376 "stop: 0 #404040, stop: 1 #B0B0B0);"
1377 "}"
1378 // GROUPS
1379 "QGroupBox {"
1380 "background-color: qlineargradient(x1: 0, y1: 0, x2: 1, y2: 1,"
1381 "stop: 0 #A0A0A0, stop: 1 #202020);"
1382 "border: 2px solid gray;"
1383 "border-radius: 5px;"
1384 "margin-top: 3ex;"
1385 "font-size:10pt;"
1386 "font-weight:bold;"
1387 //"color: dark grey;"
1388 "color: white;"
1389 "}"
1390
1391 "QGroupBox::title {"
1392 "subcontrol-origin: margin;"
1393 "subcontrol-position: top center;" /* position at the top center */
1394 "padding: 0 5px;"
1395 "}"
1396 // SLIDERS
1397 // horizontal sliders
1398 "QSlider::groove:vertical {"
1399 "background: red;"
1400 "position: absolute;" /* absolutely position 4px from the left and right of the widget. setting margins on the widget should work too... */
1401 "left: 13px; right: 13px;"
1402 "}"
1403
1404 "QSlider::handle:vertical {"
1405 "height: 40px;"
1406 "width: 30px;"
1407 "background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,"
1408 "stop: 0 #AAAAAA, stop : 0.05 #0A0A0A, stop: 0.3 #101010, stop : 0.90 #AAAAAA, stop: 0.91 #000000);"
1409 "margin: 0 -5px; /* expand outside the groove */"
1410 "border-radius: 5px;"
1411 "}"
1412
1413 "QSlider::add-page:vertical {"
1414 "background: qlineargradient(x1: 0, y1: 0, x2: 1, y2: 0,"
1415 "stop: 0 yellow, stop : 0.5 orange);"
1416 "}"
1417
1418 "QSlider::sub-page:vertical {"
1419 "background: grey;"
1420 "}"
1421
1422 // horizontal sliders
1423
1424 "QSlider::groove:horizontal {"
1425 "background: red;"
1426 "position: absolute;" /* absolutely position 4px from the left and right of the widget. setting margins on the widget should work too... */
1427 "top: 14px; bottom: 14px;"
1428 "}"
1429
1430 "QSlider::handle:horizontal {"
1431 "width: 40px;"
1432 "background: qlineargradient(x1: 0, y1: 0, x2: 1, y2: 0,"
1433 "stop: 0 #AAAAAA, stop : 0.05 #0A0A0A, stop: 0.3 #101010, stop : 0.90 #AAAAAA, stop: 0.91 #000000);"
1434 "margin: -5px 0; /* expand outside the groove */"
1435 "border-radius: 5px;"
1436 "}"
1437
1438 "QSlider::sub-page:horizontal {"
1439 "background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,"
1440 "stop: 0 yellow, stop : 0.5 orange);"
1441 "}"
1442
1443 "QSlider::add-page:horizontal {"
1444 "background: grey;"
1445 "}"
1446
1447 // TABS
1448 //TabWidget and TabBar
1449 "QTabWidget::pane {" /* The tab widget frame */
1450 //"border-top: 2px solid #C2C7CB;"
1451 "border-top: 2px solid orange;"
1452 "background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,"
1453 "stop: 0 #A0A0A0, stop: 1 #202020);"
1454 "}"
1455
1456 "QTabWidget::tab-bar {"
1457 "left: 5px;" /* move to the right by 5px */
1458 "}"
1459
1460 /* Style the tab using the tab sub-control. Note that
1461 it reads QTabBar _not_ QTabWidget */
1462 "QTabBar::tab {"
1463 "background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,"
1464 "stop: 0 #909090, stop: 0.4 #888888,"
1465 "stop: 0.5 #808080, stop: 1.0 #909090);"
1466 "border: 2px solid #808080;"
1467 //"border-bottom-color: #C2C7CB;" /* same as the pane color */
1468 "border-bottom-color: orange;" /* same as the pane color */
1469 "border-top-left-radius: 4px;"
1470 "border-top-right-radius: 4px;"
1471 "min-width: 8ex;"
1472 "padding: 2px;"
1473 "}"
1474
1475 "QTabBar::tab:selected, QTabBar::tab:hover {"
1476 "background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,"
1477 "stop: 0 #D0D0D0, stop: 0.4 #A0A0A0,"
1478 "stop: 0.5 #808080, stop: 1.0 #A0A0A0);"
1479 //"stop: 0.5 #A0A0A0, stop: 1.0 #C0C0C0);"
1480 //"stop: 0 #fafafa, stop: 0.4 #f4f4f4,"
1481 //"stop: 0.5 #e7e7e7, stop: 1.0 #fafafa);"
1482 //"border-bottom-color: orange;" /* same as the pane color */
1483 "}"
1484
1485 "QTabBar::tab:selected {"
1486 "border-color: orange;"
1487 "border-bottom-color: #A0A0A0;" /* same as pane color */
1488 "}"
1489
1490 "QTabBar::tab:!selected {"
1491 " margin-top: 2px;" /* make non-selected tabs look smaller */
1492 "}"
1493 );
1494 #endif
1495 fAppl.exec();
1496 stop();
1497
1498 }
1499
1500 // ------------------------- Groups -----------------------------------
1501
1502 virtual void openHorizontalBox(const char* label) {
1503 openBox(label, new QHBoxLayout());
1504 }
1505
1506 virtual void openVerticalBox(const char* label) {
1507 openBox(label, new QVBoxLayout());
1508 }
1509
1510 virtual void openFrameBox(const char* ) { }
1511 virtual void openTabBox(const char* label) {
1512 openTab(label);
1513 }
1514
1515 virtual void closeBox()
1516 {
1517 QWidget* group = fGroupStack.top();
1518 fGroupStack.pop();
1519 if (fGroupStack.empty()) { group->show(); group->adjustSize();}
1520 }
1521
1522 // ------------------------- active widgets -----------------------------------
1523
1524 virtual void addButton(const char* label, FAUSTFLOAT* zone)
1525 {
1526 QAbstractButton* w = new QPushButton(label);
1527 uiButton* c = new uiButton(this, zone, w);
1528
1529 insert(label, w);
1530 QObject::connect(w, SIGNAL(pressed()), c, SLOT(pressed()));
1531 QObject::connect(w, SIGNAL(released()), c, SLOT(released()));
1532 checkForTooltip(zone, w);
1533 }
1534
1535 virtual void addToggleButton(const char*, FAUSTFLOAT*)
1536 {}
1537
1538 virtual void addCheckButton(const char* label, FAUSTFLOAT* zone)
1539 {
1540 QCheckBox* w = new QCheckBox(label);
1541 uiCheckButton* c = new uiCheckButton(this, zone, w);
1542
1543 insert(label, w);
1544 QObject::connect(w, SIGNAL(stateChanged(int)), c, SLOT(setState(int)));
1545 checkForTooltip(zone, w);
1546 }
1547
1548 virtual void addNumEntry(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT init, FAUSTFLOAT min, FAUSTFLOAT max, FAUSTFLOAT step)
1549 {
1550 if (isKnob(zone)) {
1551 addVerticalKnob(label, zone, init, min, max, step);
1552 return;
1553 }
1554 //insert(label, new QDoubleSpinBox());
1555 if (label && label[0]) openVerticalBox(label);
1556 QDoubleSpinBox* w = new QDoubleSpinBox();
1557 uiNumEntry* c = new uiNumEntry(this, zone, w, init, min, max, step);
1558 insert(label, w);
1559 w->setSuffix(fUnit[zone].c_str());
1560 QObject::connect(w, SIGNAL(valueChanged(double)), c, SLOT(setValue(double)));
1561 if (label && label[0]) closeBox();
1562 checkForTooltip(zone, w);
1563 }
1564
1565 // special num entry without buttons
1566 virtual void addNumDisplay(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT init, FAUSTFLOAT min, FAUSTFLOAT max, FAUSTFLOAT step)
1567 {
1568 //insert(label, new QDoubleSpinBox());
1569 if (label && label[0]) openVerticalBox(label);
1570 QDoubleSpinBox* w = new QDoubleSpinBox();
1571 w->setAlignment(Qt::AlignHCenter);
1572 #if 1
1573 w->setStyleSheet(
1574 "QDoubleSpinBox {"
1575 "border: 2px solid orange;"
1576 "border-radius: 5px;"
1577 "font-size: 8pt;"
1578 "}"
1579 );
1580 #endif
1581 uiNumEntry* c = new uiNumEntry(this, zone, w, init, min, max, step);
1582 insert(label, w);
1583 w->setButtonSymbols(QAbstractSpinBox::NoButtons);
1584 w->setSuffix(fUnit[zone].c_str());
1585 QObject::connect(w, SIGNAL(valueChanged(double)), c, SLOT(setValue(double)));
1586 if (label && label[0]) closeBox();
1587 checkForTooltip(zone, w);
1588 }
1589
1590 //////////////////////////////////////////////////////////////////////////////////////////////////////////
1591 //
1592 // KNOBS
1593 //
1594 //////////////////////////////////////////////////////////////////////////////////////////////////////////
1595
1596 virtual void addVerticalKnob(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT init, FAUSTFLOAT min, FAUSTFLOAT max, FAUSTFLOAT step)
1597 {
1598 openHorizontalBox(label);
1599 QAbstractSlider* w = new QDial(); //qsynthKnob();
1600 uiKnob* c = new uiKnob(this, zone, w, init, min, max, step);
1601 insert(label, w);
1602 w->setStyle(new qsynthDialVokiStyle());
1603 QObject::connect(w, SIGNAL(valueChanged(int)), c, SLOT(setValue(int)));
1604 addNumDisplay(0, zone, init, min, max, step);
1605
1606 // compute the size of the knob+display
1607 int width = int(64*pow(2,fGuiSize[zone]));
1608 int height = int(100*pow(2,fGuiSize[zone]));
1609 fGroupStack.top()->setMinimumSize(width,height);
1610 fGroupStack.top()->setMaximumSize(width,height);
1611
1612 closeBox();
1613 checkForTooltip(zone, w);
1614 }
1615
1616 virtual void addHorizontalKnob(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT init, FAUSTFLOAT min, FAUSTFLOAT max, FAUSTFLOAT step)
1617 {
1618 openHorizontalBox(label);
1619 QAbstractSlider* w = new QDial(); //new qsynthKnob();
1620 uiKnob* c = new uiKnob(this, zone, w, init, min, max, step);
1621 insert(label, w);
1622 w->setStyle(new qsynthDialVokiStyle());
1623 QObject::connect(w, SIGNAL(valueChanged(int)), c, SLOT(setValue(int)));
1624 addNumDisplay(0, zone, init, min, max, step);
1625 closeBox();
1626 checkForTooltip(zone, w);
1627 }
1628
1629 //////////////////////////////////////////////////////////////////////////////////////////////////////////
1630 //
1631 // SLIDERS
1632 //
1633 //////////////////////////////////////////////////////////////////////////////////////////////////////////
1634
1635 virtual void addVerticalSlider(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT init, FAUSTFLOAT min, FAUSTFLOAT max, FAUSTFLOAT step)
1636 {
1637 if (isKnob(zone)) {
1638 addVerticalKnob(label, zone, init, min, max, step);
1639 return;
1640 }
1641 openVerticalBox(label);
1642 QSlider* w = new QSlider(Qt::Vertical);
1643 w->setMinimumHeight(160);
1644 w->setMinimumWidth(34);
1645 //w->setTickPosition(QSlider::TicksBothSides);
1646 uiSlider* c = new uiSlider(this, zone, w, init, min, max, step);
1647 insert(label, w);
1648 QObject::connect(w, SIGNAL(valueChanged(int)), c, SLOT(setValue(int)));
1649 addNumDisplay(0, zone, init, min, max, step);
1650 closeBox();
1651 checkForTooltip(zone, w);
1652 }
1653
1654 virtual void addHorizontalSlider(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT init, FAUSTFLOAT min, FAUSTFLOAT max, FAUSTFLOAT step)
1655 {
1656 if (isKnob(zone)) {
1657 addHorizontalKnob(label, zone, init, min, max, step);
1658 return;
1659 }
1660 openHorizontalBox(label);
1661 QSlider* w = new QSlider(Qt::Horizontal);
1662 w->setMinimumHeight(34);
1663 w->setMinimumWidth(160);
1664 //w->setTickPosition(QSlider::TicksBothSides);
1665 uiSlider* c = new uiSlider(this, zone, w, init, min, max, step);
1666 insert(label, w);
1667 QObject::connect(w, SIGNAL(valueChanged(int)), c, SLOT(setValue(int)));
1668 addNumDisplay(0, zone, init, min, max, step);
1669 closeBox();
1670 checkForTooltip(zone, w);
1671 }
1672
1673 // ------------------------- passive widgets -----------------------------------
1674
1675 virtual void addNumDisplay(const char*, FAUSTFLOAT*, int)
1676 {}
1677
1678 virtual void addTextDisplay(const char*, FAUSTFLOAT*, const char* [], FAUSTFLOAT, FAUSTFLOAT)
1679 {}
1680
1681 virtual void addHorizontalBargraph(const char* label , FAUSTFLOAT* zone, FAUSTFLOAT min, FAUSTFLOAT max)
1682 {
1683 AbstractDisplay* bargraph;
1684 openVerticalBox(label);
1685 bool db = (fUnit[zone] == "dB");
1686
1687 if (fLedSet.count(zone)) {
1688 if (db) {
1689 bargraph = new dbLED(min, max);
1690 } else {
1691 bargraph = new LED(min,max);
1692 }
1693 } else {
1694 if (db) {
1695 bargraph = new dbHorizontalBargraph(min, max);
1696 } else {
1697 bargraph = new linHorizontalBargraph(min, max);
1698 }
1699 }
1700
1701 new uiBargraph2(this, zone, bargraph, min, max);
1702 insert(label, bargraph);
1703 closeBox();
1704 checkForTooltip(zone, bargraph);
1705 }
1706
1707 virtual void addVerticalBargraph(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT min, FAUSTFLOAT max)
1708 {
1709 AbstractDisplay* bargraph;
1710 openVerticalBox(label);
1711 bool db = (fUnit[zone] == "dB");
1712
1713 if (fLedSet.count(zone)) {
1714 if (db) {
1715 bargraph = new dbLED(min, max);
1716 } else {
1717 bargraph = new LED(min,max);
1718 }
1719 } else {
1720 if (db) {
1721 bargraph = new dbVerticalBargraph(min, max);
1722 } else {
1723 bargraph = new linVerticalBargraph(min, max);
1724 }
1725 }
1726 new uiBargraph2(this, zone, bargraph, min, max);
1727 insert(label, bargraph);
1728 closeBox();
1729 checkForTooltip(zone, bargraph);
1730 }
1731
1732 };
1733
1734 #endif