/usr/include/faust/gui/JuceGUI.h is in faust-common 0.9.95~repack1-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 | /************************************************************************
FAUST Architecture File
Copyright (C) 2016 GRAME, Centre National de Creation Musicale
---------------------------------------------------------------------
This Architecture section 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; either version 3 of
the License, or (at your option) any later version.
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/>.
EXCEPTION : As a special exception, you may create a larger work
that contains this FAUST architecture section and distribute
that work under terms of your choice, so long as this FAUST
architecture section is not modified.
************************************************************************
************************************************************************/
#ifndef FAUSTFLOAT
#define FAUSTFLOAT float
#endif
#define kKnobWidth 100
#define kKnobHeight 100
#define kVSliderWidth 80
#define kVSliderHeight 250
#define kHSliderWidth 350
#define kHSliderHeight 50
#define kButtonWidth 100
#define kButtonHeight 50
#define kCheckButtonWidth 100
#define kCheckButtonHeight 40
#define kMenuWidth 100
#define kMenuHeight 50
#define kRadioButtonWidth 100
#define kRadioButtonHeight 55
#define kNumEntryWidth 100
#define kNumEntryHeight 50
#define kNumDisplayWidth 75
#define kNumDisplayHeight 50
#define kVBargraphWidth 60
#define kVBargraphHeight 250
#define kHBargraphWidth 350
#define kHBargraphHeight 50
#define kLedWidth 50
#define kLedHeight 50
#include "../JuceLibraryCode/JuceHeader.h"
#include "faust/gui/GUI.h"
#include "faust/gui/MetaDataUI.h"
#include "faust/gui/ValueConverter.h"
struct CustomLookAndFeel : public LookAndFeel_V3
{
void drawRoundThumb (Graphics& g, const float x, const float y,
const float diameter, const Colour& colour, float outlineThickness)
{
const Rectangle<float> a (x, y, diameter, diameter);
const float halfThickness = outlineThickness * 0.5f;
Path p;
p.addEllipse (x + halfThickness, y + halfThickness, diameter - outlineThickness, diameter - outlineThickness);
const DropShadow ds (Colours::black, 1, Point<int> (0, 0));
ds.drawForPath (g, p);
g.setColour (colour);
g.fillPath (p);
g.setColour (colour.brighter());
g.strokePath (p, PathStrokeType (outlineThickness));
}
void drawButtonBackground (Graphics& g, Button& button, const Colour& backgroundColour,
bool isMouseOverButton, bool isButtonDown) override
{
Colour baseColour (backgroundColour.withMultipliedSaturation (button.hasKeyboardFocus (true) ? 1.3f : 0.9f)
.withMultipliedAlpha (button.isEnabled() ? 0.9f : 0.5f));
if (isButtonDown || isMouseOverButton)
baseColour = baseColour.contrasting (isButtonDown ? 0.2f : 0.1f);
const bool flatOnLeft = button.isConnectedOnLeft();
const bool flatOnRight = button.isConnectedOnRight();
const bool flatOnTop = button.isConnectedOnTop();
const bool flatOnBottom = button.isConnectedOnBottom();
const float width = button.getWidth() - 1.0f;
const float height = button.getHeight() - 1.0f;
if (width > 0 && height > 0)
{
const float cornerSize = jmin (15.0f, jmin (width, height) * 0.45f);
const float lineThickness = cornerSize * 0.1f;
const float halfThickness = lineThickness * 0.5f;
Path outline;
outline.addRoundedRectangle (0.5f + halfThickness, 0.5f + halfThickness, width - lineThickness, height - lineThickness,
cornerSize, cornerSize,
! (flatOnLeft || flatOnTop),
! (flatOnRight || flatOnTop),
! (flatOnLeft || flatOnBottom),
! (flatOnRight || flatOnBottom));
const Colour outlineColour (button.findColour (button.getToggleState() ? TextButton::textColourOnId
: TextButton::textColourOffId));
g.setColour (baseColour);
g.fillPath (outline);
if (! button.getToggleState()) {
g.setColour (outlineColour);
g.strokePath (outline, PathStrokeType (lineThickness));
}
}
}
void drawTickBox (Graphics& g, Component& component,
float x, float y, float w, float h,
bool ticked,
bool isEnabled,
bool isMouseOverButton,
bool isButtonDown) override
{
const float boxSize = w * 0.7f;
bool isDownOrDragging = component.isEnabled() && (component.isMouseOverOrDragging() || component.isMouseButtonDown());
const Colour colour (component.findColour (TextButton::buttonColourId).withMultipliedSaturation ((component.hasKeyboardFocus (false) || isDownOrDragging) ? 1.3f : 0.9f)
.withMultipliedAlpha (component.isEnabled() ? 1.0f : 0.7f));
drawRoundThumb (g, x, y + (h - boxSize) * 0.5f, boxSize, colour,
isEnabled ? ((isButtonDown || isMouseOverButton) ? 1.1f : 0.5f) : 0.3f);
if (ticked) {
const Path tick (LookAndFeel_V2::getTickShape (6.0f));
g.setColour (isEnabled ? findColour (TextButton::buttonOnColourId) : Colours::grey);
const float scale = 9.0f;
const AffineTransform trans (AffineTransform::scale (w / scale, h / scale)
.translated (x - 2.5f, y + 1.0f));
g.fillPath (tick, trans);
}
}
void drawLinearSliderThumb (Graphics& g, int x, int y, int width, int height,
float sliderPos, float minSliderPos, float maxSliderPos,
const Slider::SliderStyle style, Slider& slider) override
{
const float sliderRadius = (float) (getSliderThumbRadius (slider) - 2);
bool isDownOrDragging = slider.isEnabled() && (slider.isMouseOverOrDragging() || slider.isMouseButtonDown());
Colour knobColour (slider.findColour (Slider::thumbColourId).withMultipliedSaturation ((slider.hasKeyboardFocus (false) || isDownOrDragging) ? 1.3f : 0.9f)
.withMultipliedAlpha (slider.isEnabled() ? 1.0f : 0.7f));
if (style == Slider::LinearHorizontal || style == Slider::LinearVertical) {
float kx, ky;
if (style == Slider::LinearVertical) {
kx = x + width * 0.5f;
ky = sliderPos;
} else {
kx = sliderPos;
ky = y + height * 0.5f;
}
const float outlineThickness = slider.isEnabled() ? 0.8f : 0.3f;
drawRoundThumb (g,
kx - sliderRadius,
ky - sliderRadius,
sliderRadius * 2.0f,
knobColour, outlineThickness);
} else {
// Just call the base class for the demo
LookAndFeel_V2::drawLinearSliderThumb (g, x, y, width, height, sliderPos, minSliderPos, maxSliderPos, style, slider);
}
}
void drawLinearSlider (Graphics& g, int x, int y, int width, int height,
float sliderPos, float minSliderPos, float maxSliderPos,
const Slider::SliderStyle style, Slider& slider) override
{
g.fillAll (slider.findColour (Slider::backgroundColourId));
if (style == Slider::LinearBar || style == Slider::LinearBarVertical) {
const float fx = (float) x, fy = (float) y, fw = (float) width, fh = (float) height;
Path p;
if (style == Slider::LinearBarVertical)
p.addRectangle (fx, sliderPos, fw, 1.0f + fh - sliderPos);
else
p.addRectangle (fx, fy, sliderPos - fx, fh);
Colour baseColour (slider.findColour (Slider::rotarySliderFillColourId)
.withMultipliedSaturation (slider.isEnabled() ? 1.0f : 0.5f)
.withMultipliedAlpha (0.8f));
g.setColour (baseColour);
g.fillPath (p);
const float lineThickness = jmin (15.0f, jmin (width, height) * 0.45f) * 0.1f;
g.drawRect (slider.getLocalBounds().toFloat(), lineThickness);
} else {
drawLinearSliderBackground (g, x, y, width, height, sliderPos, minSliderPos, maxSliderPos, style, slider);
drawLinearSliderThumb (g, x, y, width, height, sliderPos, minSliderPos, maxSliderPos, style, slider);
}
}
void drawLinearSliderBackground (Graphics& g, int x, int y, int width, int height,
float /*sliderPos*/,
float /*minSliderPos*/,
float /*maxSliderPos*/,
const Slider::SliderStyle /*style*/, Slider& slider) override
{
const float sliderRadius = getSliderThumbRadius (slider) - 5.0f;
Path on, off;
if (slider.isHorizontal()) {
const float iy = y + height * 0.5f - sliderRadius * 0.5f;
Rectangle<float> r (x - sliderRadius * 0.5f, iy, width + sliderRadius, sliderRadius);
const float onW = r.getWidth() * ((float) slider.valueToProportionOfLength (slider.getValue()));
on.addRectangle (r.removeFromLeft (onW));
off.addRectangle (r);
} else {
const float ix = x + width * 0.5f - sliderRadius * 0.5f;
Rectangle<float> r (ix, y - sliderRadius * 0.5f, sliderRadius, height + sliderRadius);
const float onH = r.getHeight() * ((float) slider.valueToProportionOfLength (slider.getValue()));
on.addRectangle (r.removeFromBottom (onH));
off.addRectangle (r);
}
g.setColour (slider.findColour (Slider::rotarySliderFillColourId));
g.fillPath (on);
g.setColour (slider.findColour (Slider::trackColourId));
g.fillPath (off);
}
void drawRotarySlider (Graphics& g, int x, int y, int width, int height, float sliderPos,
float rotaryStartAngle, float rotaryEndAngle, Slider& slider) override
{
const float radius = jmin (width / 2, height / 2) - 4.0f;
const float centreX = x + width * 0.5f;
const float centreY = y + height * 0.5f;
const float rx = centreX - radius;
const float ry = centreY - radius;
const float rw = radius * 2.0f;
const float angle = rotaryStartAngle + sliderPos * (rotaryEndAngle - rotaryStartAngle);
const bool isMouseOver = slider.isMouseOverOrDragging() && slider.isEnabled();
//Background
{
g.setColour(Colours::lightgrey.withAlpha (isMouseOver ? 1.0f : 0.7f));
Path intFilledArc;
intFilledArc.addPieSegment(rx, ry, rw, rw, rotaryStartAngle, rotaryEndAngle, 0.8);
g.fillPath(intFilledArc);
}
if (slider.isEnabled())
g.setColour (slider.findColour (Slider::rotarySliderFillColourId).withAlpha (isMouseOver ? 1.0f : 0.7f));
else
g.setColour (Colour (0x80808080));
//Render knob value
{
Path pathArc;
pathArc.addPieSegment(rx, ry, rw, rw, rotaryStartAngle, angle, 0.8);
g.fillPath(pathArc);
Path cursor, cursorShadow;
float rectWidth = radius*0.4;
float rectHeight = rectWidth/2;
float rectX = centreX + radius*0.9 - rectHeight/2;
float rectY = centreY - rectWidth/2;
cursor.addRectangle (rectX, rectY, rectWidth, rectHeight);
cursorShadow.addRectangle(rectX-1, rectY-1, rectWidth+2, rectHeight+2);
AffineTransform t = AffineTransform::translation(-rectWidth + 2, rectHeight/2);
t = t.rotated((angle - float_Pi/2), centreX, centreY);
cursor.applyTransform(t);
cursorShadow.applyTransform(t);
g.setColour(Colours::black);
g.fillPath(cursor);
g.setColour(Colours::black .withAlpha(0.15f));
g.fillPath(cursorShadow);
}
}
};
enum SliderType{
HSlider,
VSlider,
NumEntry,
Knob
};
enum VUMeterType{
HVUMeter,
VVUMeter,
Led,
NumDisplay
};
class layoutComponent: public Component
{
private:
bool isBox;
public:
layoutComponent(bool box) : isBox(box){}
virtual int getRecommendedHeight() = 0;
virtual int getRecommendedWidth() = 0;
virtual void setRatio() = 0;
virtual void setVRatio() = 0;
virtual void setHRatio() = 0;
virtual float getHRatio() = 0;
virtual float getVRatio() = 0;
virtual void setLayoutComponentSize(Rectangle<int> r) = 0;
virtual void setCompLookAndFeel(LookAndFeel* laf) = 0;
};
class uiComponent: public layoutComponent, public uiItem, public SettableTooltipClient
{
public:
float vRatio, hRatio;
int recomWidth, recomHeight;
String fTooltipText;
uiComponent(GUI* gui, FAUSTFLOAT* zone, int w, int h, String tooltip): layoutComponent(false), uiItem(gui,zone), recomWidth(w), recomHeight(h), fTooltipText(tooltip) { }
// Debug output
void setLayoutComponentSize(Rectangle<int> r) override{
std::cout<<"New bounds of Component : {"<<r.toString()<<"}";
std::cout<<", for parent : "<<getParentComponent()<<", "<<getParentComponent()->getBounds().toString()<<std::endl;
std::cout<<"Ratios : "<<hRatio<<" "<<vRatio<<", Recommended Size : "<<recomWidth<<"x"<<recomHeight<<std::endl;
Component::setSize(r.getWidth(), r.getHeight());
setTopLeftPosition(r.getX() - getParentComponent()->getX(), r.getY() - getParentComponent()->getY());
}
float getHRatio() override{ return hRatio; }
float getVRatio() override{ return vRatio; }
int getRecommendedHeight() override{ return recomHeight; }
int getRecommendedWidth() override{ return recomWidth; }
void setRatio() override{
setVRatio();
setHRatio();
}
void setVRatio() override{
vRatio = (float)recomHeight/(float)findParentComponentOfClass<layoutComponent>()->getRecommendedHeight();
}
void setHRatio() override{
hRatio = (float)recomWidth/(float)findParentComponentOfClass<layoutComponent>()->getRecommendedWidth();
}
};
class uiSlider: public uiComponent,
private juce::Slider::Listener
{
private:
Slider::SliderStyle fStyle;
Label fLabel;
String fName;
ScopedPointer<ValueConverter> fConverter;
int x, y, width, height;
SliderType fType;
Slider fSlider;
public:
uiSlider(GUI* gui, FAUSTFLOAT* zone, FAUSTFLOAT w, FAUSTFLOAT h, FAUSTFLOAT min, FAUSTFLOAT max, FAUSTFLOAT cur, FAUSTFLOAT step, String name, String unit, String tooltip, MetaDataUI::Scale scale, SliderType type) : uiComponent(gui, zone, w, h, tooltip), fName(name), fType(type)
{
if (scale == MetaDataUI::kLog) {
fConverter = new LogValueConverter(min, max, min, max);
fSlider.setSkewFactor(0.5);
} else if (scale == MetaDataUI::kExp) {
fConverter = new ExpValueConverter(min, max, min, max);
fSlider.setSkewFactor(2.0);
} else {
fConverter = new LinearValueConverter(min, max, min, max);
}
switch(fType){
case HSlider:
fStyle = Slider::SliderStyle::LinearHorizontal;
break;
case VSlider:
fStyle = Slider::SliderStyle::LinearVertical;
fSlider.setTextBoxStyle(juce::Slider::TextBoxBelow, false, 60, 20);
break;
case NumEntry:
fSlider.setIncDecButtonsMode(Slider::incDecButtonsDraggable_AutoDirection);
fStyle = Slider::SliderStyle::IncDecButtons;
break;
case Knob:
fStyle = Slider::SliderStyle::Rotary;
fSlider.setTextBoxStyle(juce::Slider::TextBoxBelow, false, 60, 20);
break;
default:
break;
}
addAndMakeVisible(fSlider);
//Slider settings
fSlider.setBounds(getBounds());
fSlider.setRange(min, max, step);
fSlider.setValue(fConverter->faust2ui(cur));
fSlider.addListener(this);
fSlider.setSliderStyle(fStyle);
fSlider.setTextValueSuffix(unit);
if(fTooltipText.isNotEmpty()){ fSlider.setTooltip(fTooltipText); }
//Label settings
if(fType == HSlider || fType == NumEntry){
fLabel.setText(fName, dontSendNotification);
fLabel.attachToComponent(&fSlider, true);
addAndMakeVisible (fLabel);
if(fTooltipText.isNotEmpty()){ fLabel.setTooltip(fTooltipText); }
}
}
virtual void paint(Graphics& g) override{
if(fType == VSlider || fType == Knob) {
g.setColour (Colours::black);
g.drawText(fName, getLocalBounds(), Justification::centredTop);
}
}
void reflectZone() override
{
FAUSTFLOAT v = *fZone;
fCache = v;
fSlider.setValue(fConverter->faust2ui(v));
}
void sliderValueChanged(Slider* slider) override
{
float value = slider->getValue();
std::cout<<fName<<" : "<<value<<std::endl;
modifyZone(value);
}
virtual void setCompLookAndFeel(LookAndFeel* laf) override{
fSlider.setLookAndFeel(laf);
}
virtual void resized() override{
std::cout<<fName<<", ";
if(fType == HSlider) {
x = getLocalBounds().reduced(3).getX() + 60; y = getLocalBounds().reduced(3).getY();
width = getLocalBounds().reduced(3).getWidth()-60; height = getLocalBounds().reduced(3).getHeight();
} else if(fType == NumEntry) {
width = kNumEntryWidth-10; height = kNumEntryHeight-15;
x = (getLocalBounds().reduced(3).getWidth()-width)/2; y = (getLocalBounds().reduced(3).getHeight()-height)/2;
} else if(fType == VSlider) {
x = getLocalBounds().reduced(3).getX(); y = getLocalBounds().reduced(3).getY()+11;
height = getLocalBounds().reduced(3).getHeight()-12; width = getLocalBounds().reduced(3).getWidth();
} else if(fType == Knob){
width = jmin(getLocalBounds().reduced(3).getWidth(), kKnobWidth-6);
height = jmin(getLocalBounds().reduced(3).getHeight()-12, kKnobHeight-6);
x = jmax((getLocalBounds().getWidth() - width)/2, getLocalBounds().reduced(3).getX());
y = jmax((getLocalBounds().getHeight() - height)/2, y = getLocalBounds().reduced(3).getY()+11);
}
fSlider.setBounds(x, y, width, height);
}
};
class uiButton: public uiComponent,
private juce::Button::Listener
{
private:
String fName;
int x, y, width, height;
TextButton fButton;
public:
uiButton(GUI* gui, FAUSTFLOAT* zone, FAUSTFLOAT w, FAUSTFLOAT h, String label, String tooltip) : uiComponent(gui, zone, w, h, tooltip), fName(label), width(w), height(h)
{
x = getLocalBounds().getX()+10;
width = kCheckButtonWidth;
height = kCheckButtonHeight;
y = (getLocalBounds().getHeight()-height)/2;
fButton.setButtonText(label);
fButton.setBounds(x, y, width, height);
fButton.addListener(this);
if(fTooltipText.isNotEmpty()){ fButton.setTooltip(fTooltipText); }
addAndMakeVisible(fButton);
}
void buttonClicked (Button* button) override
{
}
void buttonStateChanged (Button* button) override
{
if(button->isDown()) { modifyZone(1.0); }
else { modifyZone(0.0); }
}
void reflectZone() override
{
FAUSTFLOAT v = *fZone;
fCache = v;
}
virtual void setCompLookAndFeel(LookAndFeel* laf) override{
fButton.setLookAndFeel(laf);
}
virtual void paint(Graphics& g) override { }
virtual void resized() override
{
x = getLocalBounds().getX()+10;
width = getLocalBounds().getWidth()-20;
height = jmin(getLocalBounds().getHeight(), kButtonHeight);
y = (getLocalBounds().getHeight()-height)/2;
fButton.setBounds(x, y, width, height);
}
};
class uiCheckButton: public uiComponent,
private juce::Button::Listener
{
private:
String fName;
int x, y, width, height;
ToggleButton fCheckButton;
public:
uiCheckButton(GUI* gui, FAUSTFLOAT* zone, FAUSTFLOAT w, FAUSTFLOAT h, String label, String tooltip) : uiComponent(gui, zone, w, h, tooltip), fName(label), width(w), height(h)
{
x = getLocalBounds().getX() + 10;
y = (getLocalBounds().getHeight()-height)/2;
if(fTooltipText.isNotEmpty()){ setTooltip(fTooltipText); }
fCheckButton.setButtonText(label);
fCheckButton.setBounds(x, y, width, height);
fCheckButton.addListener(this);
if(fTooltipText.isNotEmpty()){ fCheckButton.setTooltip(fTooltipText); }
addAndMakeVisible(fCheckButton);
}
void buttonClicked(Button* button) override
{
std::cout<<fName<<" : "<<button->getToggleState()<<std::endl;
modifyZone(button->getToggleState());
}
void reflectZone() override
{
FAUSTFLOAT v = *fZone;
fCache = v;
}
virtual void setCompLookAndFeel(LookAndFeel* laf) override{
fCheckButton.setLookAndFeel(laf);
}
virtual void paint(Graphics& g) override { }
virtual void resized() override
{
std::cout<<"RESIZING CHECKBUTTON"<<std::endl;
x = getLocalBounds().getX();
y = getLocalBounds().getY();
fCheckButton.setBounds(x, y, jmin(getLocalBounds().getWidth(), width), jmin(getLocalBounds().getHeight(), height));
}
};
class uiMenu: public uiComponent,
private juce::ComboBox::Listener
{
private:
ComboBox fComboBox;
String fName;
int x, y, width, height;
int nbItem;
vector<double> fValues;
public:
uiMenu(GUI* gui, FAUSTFLOAT* zone, String label, FAUSTFLOAT w, FAUSTFLOAT h, FAUSTFLOAT cur, FAUSTFLOAT lo, FAUSTFLOAT hi, String tooltip, const char* mdescr) : uiComponent(gui, zone, w, h, tooltip), fName(label), width(w), height(h)
{
//Init ComboBox parameters
fComboBox.setEditableText(false);
fComboBox.setJustificationType(Justification::centred);
fComboBox.addListener(this);
addAndMakeVisible(fComboBox);
vector<string> names;
vector<double> values;
if (parseMenuList(mdescr, names, values)) {
int defaultitem = -1;
double mindelta = FLT_MAX;
for (int i = 0; i < names.size(); i++) {
double v = values[i];
if ( (v >= lo) && (v <= hi) ) {
// It is a valid value : add corresponding menu item
fComboBox.addItem(String(names[i].c_str()), v+1);
fValues.push_back(v);
// Check if this item is a good candidate to represent the current value
double delta = fabs(cur-v);
if (delta < mindelta) {
mindelta = delta;
defaultitem = fComboBox.getNumItems();
}
}
}
// check the best candidate to represent the current value
if (defaultitem > -1) { fComboBox.setSelectedItemIndex(defaultitem); }
}
*fZone = cur;
}
void comboBoxChanged (ComboBox* cb) override
{
std::cout<<fName<<" : "<<cb->getSelectedId() - 1<<std::endl;
modifyZone(cb->getSelectedId() - 1);
}
virtual void reflectZone() override
{
FAUSTFLOAT v = *fZone;
fCache = v;
// search closest value
int defaultitem = -1;
double mindelta = FLT_MAX;
for (unsigned int i=0; i<fValues.size(); i++) {
double delta = fabs(fValues[i]-v);
if (delta < mindelta) {
mindelta = delta;
defaultitem = i;
}
}
if (defaultitem > -1) { fComboBox.setSelectedItemIndex(defaultitem); }
}
virtual void setCompLookAndFeel(LookAndFeel* laf) override{
fComboBox.setLookAndFeel(laf);
}
virtual void resized() override{
fComboBox.setBounds(1, getLocalBounds().getY() + 15, getWidth()-2, height/2);
}
virtual void paint(Graphics& g) override{
g.setColour(Colours::black);
g.drawText(fName, getLocalBounds().withHeight(getLocalBounds().getHeight()/2), Justification::centredTop);
}
};
class uiRadioButton: public uiComponent,
private juce::Button::Listener
{
private:
String name;
int x, y, width, height;
int nbButtons;
bool isVertical;
OwnedArray<ToggleButton> fButtons;
vector<double> fValues;
public:
uiRadioButton(GUI* gui, FAUSTFLOAT* zone, String label, FAUSTFLOAT w, FAUSTFLOAT h, FAUSTFLOAT cur, FAUSTFLOAT lo, FAUSTFLOAT hi, bool vert, vector<string>& names, vector<double>& values, String tooltip, const char* mdescr, int radioGroupID) : uiComponent(gui, zone, w, h, tooltip), name(label), width(w), height(h), isVertical(vert)
{
x = getLocalBounds().getX() + 10;
y = (getLocalBounds().getHeight()-kCheckButtonHeight)/2;
{
ToggleButton* defaultbutton = 0;
double mindelta = FLT_MAX;
nbButtons = names.size();
for(int i = 0; i < nbButtons; i++){
double v = values[i];
if ((v >= lo) && (v <= hi)) {
// It is a valid value included in slider's range
ToggleButton* tb = new ToggleButton(names[i]);
addAndMakeVisible(tb);
tb->setRadioGroupId (radioGroupID);
tb->addListener(this);
fValues.push_back(v);
fButtons.add(tb);
if(fTooltipText.isNotEmpty()){ tb->setTooltip(fTooltipText); }
// Check if this item is a good candidate to represent the current value
double delta = fabs(cur-v);
if (delta < mindelta) {
mindelta = delta;
defaultbutton = tb;
}
}
}
// check the best candidate to represent the current value
if (defaultbutton) { defaultbutton->setToggleState (true, dontSendNotification); }
}
}
void setVRatio(float ratio)
{
if(isVertical){ vRatio = ratio * nbButtons; }
else{ vRatio = ratio; }
}
void setHRatio(float ratio)
{
if(!isVertical){ hRatio = ratio * nbButtons; }
else{ hRatio = ratio; }
}
virtual void setCompLookAndFeel(LookAndFeel* laf){
for(int i = 0; i<nbButtons; i++)
fButtons[i]->setLookAndFeel(laf);
}
virtual void reflectZone()
{
FAUSTFLOAT v = *fZone;
fCache = v;
// select closest value
int defaultitem = -1;
double mindelta = FLT_MAX;
for (unsigned int i=0; i<fValues.size(); i++) {
double delta = fabs(fValues[i]-v);
if (delta < mindelta) {
mindelta = delta;
defaultitem = i;
}
}
if (defaultitem > -1) { fButtons.operator[](defaultitem)->setToggleState (true, dontSendNotification); }
}
virtual void resized(){
isVertical ? height = (getLocalBounds().getHeight()-25) / nbButtons
: width = getLocalBounds().getWidth() / nbButtons;
for(int i = 0; i < nbButtons; i++){
if(isVertical){ fButtons.operator[](i)->setBounds(0, i * height + 25, 100, height); }
else{ fButtons.operator[](i)->setBounds(i * width, 25, width, 30); }
}
}
virtual void paint(Graphics& g){
g.setColour(Colours::black);
g.drawText(name, getLocalBounds().withHeight(25), Justification::centredTop);
}
void buttonClicked(Button* button)
{
ToggleButton* checkButton = dynamic_cast<ToggleButton*>(button);
std::cout<<name<<" : "<<fButtons.indexOf(checkButton)<<std::endl;
modifyZone(fButtons.indexOf(checkButton));
}
};
class uiVUMeter : public uiComponent, public Timer
{
public:
uiVUMeter (GUI* gui, FAUSTFLOAT* zone, FAUSTFLOAT w, FAUSTFLOAT h, String label, FAUSTFLOAT mini, FAUSTFLOAT maxi, String unit, String tooltip, VUMeterType style, bool vert)
: uiComponent(gui, zone, w, h, tooltip), fMin(mini), fMax(maxi), fStyle(style), fName(label)
{
setOpaque(true);
fLevel = 0;
startTimer (50);
this->fUnit = unit;
(unit == "dB") ? db = true : db = false;
if(db){
fScaleMin = dB2Scale(fMin);
fScaleMax = dB2Scale(fMax);
}
(!(fName.startsWith("0x")) && fName.isNotEmpty()) ? isBargraphNameShown = true : isBargraphNameShown = false;
if(fTooltipText.isNotEmpty()){ setTooltip(fTooltipText); }
if(fStyle != Led){ setupTextEditor(); }
}
//Moyenne de 60% au repos, ~110% en pic, non saccadé
void timerCallback() override
{
if (isShowing()) {
if(fLevel == 0){ forceRepaint = true; } //Force painting at the initialisation
else{ forceRepaint = false; }
float lastLevel = fLevel; //t-1
setLevel(); //t
if(db){
if(fStyle == VVUMeter) {
if (((int)dB2y(lastLevel) != (int)dB2y(fLevel) && fLevel >= fMin && fLevel <= fMax) || forceRepaint){
repaint(); }
} else if(fStyle == HVUMeter) {
if (((int)dB2x(lastLevel) != (int)dB2x(fLevel) && fLevel >= fMin && fLevel <= fMax) || forceRepaint){ repaint(); }
} else if(fStyle == NumDisplay) {
if (((int)lastLevel != (int)fLevel && fLevel >= fMin && fLevel <= fMax) || forceRepaint){ repaint(); }
} else if(fStyle == Led) {
// TODO
}
} else {
if(fStyle == VVUMeter){
if (((int)lin2y(lastLevel) != (int)lin2y(fLevel) && fLevel >= fMin && fLevel <= fMax) || forceRepaint){ repaint(); }
} else if(fStyle == HVUMeter) {
// TODO
} else if(fStyle == Led) {
if ((std::abs(lastLevel-fLevel)>0.01 && fLevel >= fMin && fLevel <= fMax) || forceRepaint){ repaint(); }
} else if(fStyle == NumDisplay) {
if (((int)lastLevel != (int)fLevel && fLevel >= fMin && fLevel <= fMax) || forceRepaint){ repaint(); }
}
}
} else {
fLevel = 0;
}
}
/* // Moyenne de 60% au repos, ~110% en pic, "saccadé"
void timerCallback() override
{
if (isShowing())
{
float newLevel = (*fZone-fMin)/(fMax-fMin);
float level;
if(db){ level = (fLevel-fMin)/(fMax-fMin); }
else{ level = fLevel; }
if ((std::abs (level - newLevel) > 0.01f) || fLevel == 0){
if(fLevel == 0){ forceRepaint = true; }
else{ forceRepaint = false; }
if((newLevel >= 0 && newLevel <= 1) || forceRepaint){
setLevel();
repaint();
}
else{
fLabel.setText(String((int)*fZone)+fUnit, dontSendNotification);
}
}
}
else
{
fLevel = 0;
}
}*/
virtual void setCompLookAndFeel(LookAndFeel* laf) override{ }
void paint (Graphics& g) override
{
g.setColour(Colours::darkgrey);
g.fillRect(getLocalBounds());
if (fStyle == Led) { drawLed (g, kLedWidth/2, kLedHeight/2, fLevel); }
else if(fStyle == NumDisplay){ drawNumDisplay(g, kNumDisplayWidth, kNumDisplayHeight/2, fLevel); }
else if(fStyle == VVUMeter) { drawVBargraph (g, kVBargraphWidth/2 , getHeight(), fLevel, db); }
else if(fStyle == HVUMeter) { drawHBargraph (g, getWidth(), kHBargraphHeight/2, fLevel, db); }
}
void resized() override{ setTextEditorPos(); }
void reflectZone() override
{
FAUSTFLOAT v = *fZone;
fCache = v;
}
private:
float fLevel;
float fMin, fMax;
float fScaleMin, fScaleMax;
bool db;
VUMeterType fStyle;
String fUnit;
Label fLabel;
String fName;
bool isBargraphNameShown;
bool forceRepaint;
void setTextEditorPos(){
if (fStyle == VVUMeter) { fLabel.setBounds((getWidth()-50)/2, getHeight()-22, 50, 20); }
else if(fStyle == HVUMeter) { isBargraphNameShown ? fLabel.setBounds(63, (getHeight()-20)/2, 50, 20)
: fLabel.setBounds(3, (getHeight()-20)/2, 50, 20); }
else if(fStyle == NumDisplay) { fLabel.setBounds(getLocalBounds().getX(), getLocalBounds().getY(), jmax(1,jmin(kNumDisplayWidth, getWidth()))-2, jmax(1,jmin(kNumDisplayHeight/2, getHeight()))-2); }
// LED Label ?
}
void setupTextEditor(){
setTextEditorPos();
fLabel.setEditable(false, false, false);
fLabel.setJustificationType(Justification::centred);
fLabel.setText(String((int)*fZone) + fUnit, dontSendNotification);
if(fTooltipText.isNotEmpty()){ fLabel.setTooltip(fTooltipText); }
addAndMakeVisible(fLabel);
}
void drawHBargraph(Graphics& g, int width, int height, float level, bool dB){
float x;
float y = (float)(getHeight()-height)/2;
if(isBargraphNameShown){
x = 120;
width -= x;
// VUMeter Name
g.setColour(Colours::black);
g.drawText(fName, 0, y, 60, height, Justification::centredRight);
} else {
x = 60;
width -= x;
}
// VUMeter Background
g.setColour(Colours::lightgrey);
g.fillRect(x, y, (float) width, (float) height);
g.setColour(Colours::black);
g.fillRect(x+1.0f, y+1.0f, (float) width-2, (float) height-2);
// Label Window
g.setColour(Colours::darkgrey);
g.fillRect((int)x-58, (getHeight()-22)/2, 52, 22);
g.setColour(Colours::white.withAlpha(0.8f));
g.fillRect((int)x-57, (getHeight()-20)/2, 50, 20);
dB ? drawHBargraphDB (g, y, height, level)
: drawHBargraphLin(g, x, y, width, height, level);
}
void drawHBargraphDB(Graphics& g, int y, int height, float level){
// Drawing Scale
g.setFont(9.0f);
g.setColour(Colours::white);
for(int i = -10; i > fMin; i -= 10){ paintScale(g, i); }
for(int i = -6; i < fMax; i += 3) { paintScale(g, i); }
int alpha = 200;
g.setColour(Colour((uint8)40, (uint8)160, (uint8)40, (uint8)alpha));
g.fillRect(dB2x(fMin), y+1.0f, jmin(dB2x(level)-dB2x(fMin), dB2x(-10)-dB2x(fMin)), (float) height-2);
if(dB2Scale(level) > dB2Scale(-10)){
g.setColour(Colour((uint8)160, (uint8)220, (uint8)20, (uint8)alpha));
g.fillRect(dB2x(-10), y+1.0f, jmin(dB2x(level)-dB2x(-10), dB2x(-6)-dB2x(-10)), (float) height-2);
}
if(dB2Scale(level) > dB2Scale(-6)){
g.setColour(Colour((uint8)220, (uint8)220, (uint8)20, (uint8)alpha));
g.fillRect(dB2x(-6), y+1.0f, jmin(dB2x(level)-dB2x(-6), dB2x(-3)-dB2x(-6)), (float) height-2);
}
if(dB2Scale(level) > dB2Scale(-3)){
g.setColour(Colour((uint8)240, (uint8)160, (uint8)20, (uint8)alpha));
g.fillRect(dB2x(-3), y+1.0f, jmin(dB2x(level)-dB2x(-3), dB2x(0)-dB2x(-3)), (float) height-2);
}
if(dB2Scale(level) > dB2Scale(0)){
g.setColour(Colour((uint8)240, (uint8)0, (uint8)20, (uint8)alpha));
g.fillRect(dB2x(0), y+1.0f, jmin(dB2x(level)-dB2x(0), dB2x(fMax)-dB2x(0)), (float) height-2);
}
}
void drawHBargraphLin(Graphics& g, int x, int y, int width, int height, float level){
int alpha = 200;
Colour c = juce::Colour((uint8)255, (uint8)165, (uint8)0, (uint8)alpha);
g.setColour(c.brighter());
g.fillRect(x+1.0f, y+1.0f, jmin(level*(width-2), 0.2f*(width-2)), (float) height-2);
if(level > 0.2f){
g.setColour(c);
g.fillRect(x+1.0f + 0.2f*(width-2), y+1.0f, jmin((level-0.2f) * (width-2), (0.9f-0.2f) * (width-2)), (float) height-2);
}
if(level > 0.9f){
g.setColour(c.darker());
g.fillRect(x+1.0f + 0.9f*(width-2), y+1.0f, jmin((level-0.9f) * (width-2), (1.0f-0.9f) * (width-2)), (float) height-2);
}
}
void drawVBargraph(Graphics& g, int width, int height, float level, bool dB){
float x = (float)(getLocalBounds().getWidth()-width)/2;
float y;
if(isBargraphNameShown) {
y = (float) getLocalBounds().getHeight()-height+15;
height -= 40;
// VUMeter Name
g.setColour(Colours::black);
g.drawText(fName, getLocalBounds(), Justification::centredTop);
} else {
y = (float) getLocalBounds().getHeight()-height; height -= 25;
}
// VUMeter Background
g.setColour(Colours::lightgrey);
g.fillRect(x, y, (float) width, (float) height);
g.setColour(Colours::black);
g.fillRect(x+1.0f, y+1.0f, (float) width-2, (float) height-2);
// Label window
g.setColour(Colours::darkgrey);
g.fillRect(jmax((getWidth()-50)/2, 0), getHeight()-23, jmin(getWidth(), 50), 22);
g.setColour(Colours::white.withAlpha(0.8f));
g.fillRect(jmax((getWidth()-48)/2, 1), getHeight()-22, jmin(getWidth()-2, 48), 20);
dB ? drawVBargraphDB (g, x, width, level)
: drawVBargraphLin(g, x, width, level);
}
void drawVBargraphDB(Graphics& g, int x, int width, float level){
// Drawing Scale
g.setFont(9.0f);
g.setColour(Colours::white);
for(int i = -10; i > fMin; i -= 10){ paintScale(g, i); }
for(int i = -6; i < fMax; i += 3) { paintScale(g, i); }
int alpha = 200;
g.setColour(Colour((uint8)40, (uint8)160, (uint8)40, (uint8)alpha));
g.fillRect(x+1.0f, jmax(dB2y(level), dB2y(-10)), (float) width-2, dB2y(fMin)-jmax(dB2y(level), dB2y(-10)));
if(dB2Scale(level) > dB2Scale(-10)){
g.setColour(Colour((uint8)160, (uint8)220, (uint8)20, (uint8)alpha));
g.fillRect(x+1.0f, jmax(dB2y(level), dB2y(-6)), (float) width-2, dB2y(-10)-jmax(dB2y(level), dB2y(-6)));
}
if(dB2Scale(level) > dB2Scale(-6)){
g.setColour(Colour((uint8)220, (uint8)220, (uint8)20, (uint8)alpha));
g.fillRect(x+1.0f, jmax(dB2y(level), dB2y(-3)), (float) width-2, dB2y(-6)-jmax(dB2y(level), dB2y(-3)));
}
if(dB2Scale(level) > dB2Scale(-3)){
g.setColour(Colour((uint8)240, (uint8)160, (uint8)20, (uint8)alpha));
g.fillRect(x+1.0f, jmax(dB2y(level), dB2y(0)), (float) width-2, dB2y(-3)-jmax(dB2y(level), dB2y(0)));
}
if(dB2Scale(level) > dB2Scale(0)){
g.setColour(Colour((uint8)240, (uint8)0, (uint8)20, (uint8)alpha));
g.fillRect(x+1.0f, jmax(dB2y(level), dB2y(fMax)), (float) width-2, dB2y(0)-jmax(dB2y(level), dB2y(fMax)));
}
}
void drawVBargraphLin(Graphics& g, int x, int width, float level){
int alpha = 200;
Colour c = juce::Colour((uint8)255, (uint8)165, (uint8)0, (uint8)alpha);
g.setColour(c.brighter());
g.fillRect(x+1.0f, jmax(lin2y(level), lin2y(0.2f)), (float) width-2, lin2y(fMin)-jmax(lin2y(level), lin2y(0.2f)));
if(level > 0.2f) {
g.setColour(c);
g.fillRect(x+1.0f, jmax(lin2y(level), lin2y(0.9f)), (float) width-2, lin2y(0.2f)-jmax(lin2y(level), lin2y(0.9f)));
}
if(level > 0.9f) {
g.setColour(c.darker());
g.fillRect(x+1.0f, jmax(lin2y(level), lin2y(fMax)), (float) width-2, lin2y(0.9)-jmax(lin2y(level), lin2y(fMax)));
}
}
void drawLed(Graphics& g, int width, int height, float level){
width -= 2;
height -= 2;
float x = (float) (getLocalBounds().getWidth() - width)/2;
float y = (float) (getLocalBounds().getHeight() - height)/2;
g.setColour(Colours::black);
g.fillEllipse(x, y, width, height);
if(db) {
int alpha = 200;
g.setColour(Colour((uint8)40, (uint8)160, (uint8)40, (uint8)alpha));
if(dB2Scale(level) > dB2Scale(-10)){ g.setColour(Colour((uint8)160, (uint8)220, (uint8)20, (uint8)alpha)); }
if(dB2Scale(level) > dB2Scale(-6)) { g.setColour(Colour((uint8)220, (uint8)220, (uint8)20, (uint8)alpha)); }
if(dB2Scale(level) > dB2Scale(-3)) { g.setColour(Colour((uint8)240, (uint8)160, (uint8)20, (uint8)alpha)); }
if(dB2Scale(level) > dB2Scale(0)) { g.setColour(Colour((uint8)240, (uint8)0, (uint8)20, (uint8)alpha)); }
g.fillEllipse(x+1, y+1, width-2, height-2);
} else {
g.setColour(Colours::red.withAlpha((float)level));
g.fillEllipse(x+1, y+1, width-2, height-2);
}
}
void drawNumDisplay(Graphics& g, int width, int height, float level){
int x = getLocalBounds().getX();
int y = getLocalBounds().getY();
height -= 5;
//Draw box
g.setColour(Colours::darkgrey);
g.fillRect(x, y, jmax(1,jmin(kNumDisplayWidth, getWidth())), jmax(1,jmin(height, getHeight())));
g.setColour(Colours::white.withAlpha(0.8f));
g.fillRect(x+1, y+1, jmax(1,jmin(kNumDisplayWidth, getWidth()))-2, jmax(1,jmin(height, getHeight()))-2);
}
float dB2Scale(float dB)
{
float fScale = 1.0;
if (dB < -60.0)
fScale = (dB + 70.0) * 0.0025;
else if (dB < -50.0)
fScale = (dB + 60.0) * 0.005 + 0.025;
else if (dB < -40.0)
fScale = (dB + 50.0) * 0.0075 + 0.075;
else if (dB < -30.0)
fScale = (dB + 40.0) * 0.015 + 0.15;
else if (dB < -20.0)
fScale = (dB + 30.0) * 0.02 + 0.3;
else if (dB < -0.001 || dB > 0.001) /* if (dB < 0.0) */
fScale = (dB + 20.0f) * 0.025 + 0.5;
return fScale;
}
float dB2y(float dB)
{
FAUSTFLOAT s0 = fScaleMin;
FAUSTFLOAT s1 = fScaleMax;
FAUSTFLOAT sx = dB2Scale(dB);
int h;
int treshold;
if(isBargraphNameShown) {
h = getHeight()-42; treshold = 16;
} else {
h = getHeight()-27; treshold = 1;
}
return (h - h*(s0-sx)/(s0-s1)) + treshold;
}
float lin2y(float level){
int h;
int treshold;
if(isBargraphNameShown) {
h = getHeight()-32; treshold = 16;
} else {
h = getHeight()-27; treshold = 1;
}
return h * (1 - level) + treshold;
}
float dB2x(float dB)
{
FAUSTFLOAT s0 = fScaleMin;
FAUSTFLOAT s1 = fScaleMax;
FAUSTFLOAT sx = dB2Scale(dB);
int w;
int treshold;
if(isBargraphNameShown){
w = getWidth()-122; treshold = 120;
} else {
w = getWidth()-62; treshold = 60;
}
return treshold + w - w*(s1-sx)/(s1-s0)+1;
}
void paintScale(Graphics& g, float num){
Rectangle<int> r;
if(fStyle == VVUMeter){
r = Rectangle<int>((getWidth()-(kVBargraphWidth/2))/2, dB2y(num)-10, (kVBargraphWidth/2)-2, 20);
g.drawText(String(num), r, Justification::centredRight, false);
} else {
r = Rectangle<int>(dB2x(num)-10,(getHeight()-kHBargraphHeight/2)/2 +1, 20, (kHBargraphHeight/2)-2);
g.drawText(String(num), r, Justification::centredTop, false);
}
}
void setLevel(){
float rawLevel = *fZone;
if(db) {
fLevel = rawLevel;
if (fLevel > fMax){ fLevel = fMax; }
else if(fLevel < fMin){ fLevel = fMin; }
} else {
fLevel = (rawLevel-fMin)/(fMax-fMin);
if (fLevel > 1) { fLevel = 1; }
else if(fLevel < 0) { fLevel = 0; }
}
fLabel.setText(String((int)rawLevel)+fUnit, dontSendNotification);
}
};
class faustBox : public layoutComponent
{
public:
faustBox(bool vert, String boxName, int boxOrder, bool tab): layoutComponent(true), fOrder(boxOrder), fName(boxName), isVertical(vert), tabLayout(tab)
{
recommendedHeight = 0;
recommendedWidth = 0;
if(fOrder == 0){ hRatio = 1; vRatio = 1; }
}
void setCompLookAndFeel(LookAndFeel* laf) override{
for(int i = 0; i<getNumChildComponents(); i++){
dynamic_cast<layoutComponent*> (getChildComponent(i))->setCompLookAndFeel(laf);
}
}
int getRecommendedWidth() override{ return recommendedWidth; }
int getRecommendedHeight() override{ return recommendedHeight; }
float getHRatio() override{ return hRatio; }
float getVRatio() override{ return vRatio; }
void setHRatio() override{
if(findParentComponentOfClass<faustBox>() != nullptr){
hRatio = (float)recommendedWidth/(float)findParentComponentOfClass<faustBox>()->recommendedWidth;
}
}
void setVRatio() override{
if(findParentComponentOfClass<faustBox>() != nullptr){
vRatio = (float)recommendedHeight/(float)findParentComponentOfClass<faustBox>()->recommendedHeight;
}
}
void setLayoutComponentSize(Rectangle<int> r) override{
rect.setSize(r.getWidth(), r.getHeight());
Component::setSize(r.getWidth(), r.getHeight());
if(findParentComponentOfClass<faustBox>() != nullptr) {
rect.setPosition(r.getX() - getParentComponent()->getX(), r.getY() - getParentComponent()->getY());
setTopLeftPosition(r.getX() - getParentComponent()->getX(), r.getY() - getParentComponent()->getY());
} else {
if(tabLayout) {
rect.setPosition(r.getX()+1, r.getY()+30);
setTopLeftPosition(r.getX()+1, r.getY()+30);
} else {
rect.setPosition(r.getX(), r.getY());
setTopLeftPosition(r.getX(), r.getY());
}
}
}
void layoutComponents()
{
for(int i = 0; i<getNumChildComponents(); i++){
layoutComponent* tempComp = dynamic_cast<layoutComponent*>(getChildComponent(i));
if(isVertical){
int heightToRemove = getSpaceToRemove(tempComp->getVRatio());
if(!(fName.startsWith("0x")) && fName.isNotEmpty() && i == 0){
tempComp->setLayoutComponentSize(rect.removeFromTop(heightToRemove).withTrimmedTop(11).reduced(3));
} else {
tempComp->setLayoutComponentSize(rect.removeFromTop(heightToRemove).reduced(3));
}
} else {
int WidthToRemove = getSpaceToRemove(tempComp->getHRatio());
if(!(fName.startsWith("0x")) && fName.isNotEmpty()){
tempComp->setLayoutComponentSize(rect.removeFromLeft(WidthToRemove).withTrimmedTop(11).reduced(3));
} else {
tempComp->setLayoutComponentSize(rect.removeFromLeft(WidthToRemove).reduced(3));
}
}
}
}
// Debug Output
void writeBox(){
std::cout<<fName<<" : "<<this<<std::endl;
std::cout<<"order : "<<fOrder<<", itemCount : "<<getNumChildComponents()<<", parentIndex : "<<getParentComponent()<<std::endl;
std::cout<<"Rect : {"<<rect.toString()<<"}"<<std::endl;
std::cout<<"CompBounds : {"<<getBounds().toString()<<"}"<<std::endl;
std::cout<<"Recommended size : "<<recommendedWidth<<"x"<<recommendedHeight<<std::endl;
std::cout<<"Ratios : "<<vRatio<<", "<<hRatio<<std::endl;
std::cout<<"isVisible ? "<<isVisible()<<std::endl;
std::cout<<"Childs : ";
for(int j = 0; j<getNumChildComponents(); j++){
std::cout<<getChildComponent(j)<<", ";
}
std::cout<<std::endl<<std::endl;
}
int getSpaceToRemove(float ratio){
if(isVertical) {
return floor((float)getBounds().getHeight()*ratio);
} else {
return floor((float)getBounds().getWidth()*ratio);
}
}
void addChildBox(faustBox* box){ addAndMakeVisible(box); }
void addChildUiComponent(uiComponent* comp){ addAndMakeVisible(comp); }
void calculRecommendedSize() {
for(int j = 0; j<getNumChildComponents(); j++){
if(isVertical){
recommendedHeight += (getChildComponent(j)->Component::getHeight());
recommendedWidth = jmax(recommendedWidth, getChildComponent(j)->Component::getWidth());
} else {
recommendedWidth += (getChildComponent(j)->Component::getWidth());
recommendedHeight = jmax(recommendedHeight, getChildComponent(j)->Component::getHeight());
}
}
Component::setSize(recommendedWidth, recommendedHeight);
}
void setRatio() override{
setHRatio();
setVRatio();
for(int i = 0; i<getNumChildComponents(); i++){
dynamic_cast<layoutComponent*>(getChildComponent(i))->setRatio();
}
}
void resized() override{
setLayoutComponentSize(getLocalBounds());
layoutComponents();
writeBox();
}
void paint(Graphics& g) override
{
Colour col = Colours::darkgrey;
/* // Debug coloring for boxes
if (fOrder == 3){ col = Colours::white;}
else if (fOrder == 2){ col = Colours::lightgrey;}
else if (fOrder == 1){ col = Colours::grey; }
else if (fOrder == 0){ col = Colours::darkgrey; }*/
g.setColour(col);
g.fillRect(getLocalBounds());
g.setColour(Colours::black);
if(!fName.startsWith("0x")){ g.drawText(fName, getLocalBounds() .withHeight(10), Justification::centred); }
}
~faustBox(){
int numChild = getNumChildComponents();
std::cout<<"order : "<<fOrder<<", numChilds : "<<numChild<<std::endl;
for(int i = numChild-1; i>=0; i--){
if(dynamic_cast<faustBox*> (getChildComponent(i)) != nullptr) {
delete dynamic_cast<faustBox*> (getChildComponent(i));
}
}
}
float hRatio, vRatio;
int recommendedWidth, recommendedHeight;
int fOrder;
String fName;
bool isVertical;
bool tabLayout;
Rectangle<int> rect;
};
class Faust_tabs : public TabbedComponent
{
public:
Faust_tabs()
: TabbedComponent (TabbedButtonBar::TabsAtTop)
{
recommendedHeight = 0;
recommendedWidth = 0;
}
void init(){
for(int i = 0; i < getNumTabs(); i++){
dynamic_cast<faustBox*>(getTabContentComponent(i))->setRatio();
dynamic_cast<faustBox*>(getTabContentComponent(i))->setCompLookAndFeel(laf);
recommendedHeight = jmax(recommendedHeight, dynamic_cast<faustBox*>(getTabContentComponent(i))->recommendedHeight);
recommendedWidth = jmax(recommendedWidth, dynamic_cast<faustBox*>(getTabContentComponent(i))->recommendedWidth);
}
}
static Colour getRandomTabBackgroundColour()
{
return Colour (Random::getSystemRandom().nextFloat(), 0.1f, 0.97f, 1.0f);
}
void addTabs(String label, Component* comp){
TabbedComponent::addTab(label, Colours::darkgrey, comp, true);
for(int i = 0; i<getNumChildComponents(); i++){
faustBox* box = dynamic_cast<faustBox*>(getChildComponent(i));
if(box !=0) {
std::cout<<"childs : "<<box->fName<<", ";
}
}
std::cout<<std::endl;
}
int recommendedWidth, recommendedHeight;
ScopedPointer<LookAndFeel> laf = new CustomLookAndFeel();
};
class Juce_GUI: public GUI, public MetaDataUI, public Component
{
public:
Juce_GUI()
{
order = 0;
radioGroup = 0;
}
Rectangle<int> getSize(){
if(!tabLayout){
return Rectangle<int>(0, 0, dynamic_cast<faustBox*>(getChildComponent(0))->recommendedWidth, dynamic_cast<faustBox*>(getChildComponent(0))->recommendedHeight);
} else {
return Rectangle<int>(0, 0, dynamic_cast<Faust_tabs*>(getChildComponent(0))->recommendedWidth, dynamic_cast<Faust_tabs*>(getChildComponent(0))->recommendedHeight+30);
}
}
virtual void openTabBox(const char* label){
tabLayout = true;
}
virtual void openVerticalBox(const char* label){
if(order == 0) {
if(tabLayout){ tabName = String(label); label = nullptr; }
currentBox = new faustBox(true, String(label), order, tabLayout);
parentBox = nullptr;
if(!tabLayout){ addAndMakeVisible(currentBox); }
} else {
parentBox = currentBox;
currentBox = new faustBox(true, String(label), order, tabLayout);
parentBox->addChildBox(currentBox);
}
order++;
}
virtual void openHorizontalBox(const char* label){
if(order == 0) {
if(tabLayout){ tabName = String(label); label = nullptr; }
currentBox = new faustBox(false, String(label), order, tabLayout);
parentBox = nullptr;
if(!tabLayout){ addAndMakeVisible(currentBox); }
} else {
parentBox = currentBox;
currentBox = new faustBox(false, String(label), order, tabLayout);
parentBox->addChildBox(currentBox);
}
order++;
}
virtual void closeBox(){
order--;
//if(currentBox != nullptr)
currentBox->calculRecommendedSize();
if(dynamic_cast<faustBox*>(currentBox->getParentComponent()) != 0) {
currentBox = parentBox;
parentBox = currentBox->findParentComponentOfClass<faustBox>(); // Return comp parent of type 'faustBox'
}
if(tabLayout && order == 0){
std::cout<<"Adding Box "<<currentBox->fName<<" to tab "<<tabName<<std::endl;
tabs.addTabs(tabName, currentBox);
tabName.clear();
addAndMakeVisible(tabs);
} else if(tabLayout && order == -1) {
init();
} else if(!tabLayout && order == 0) {
init();
}
}
virtual void addHorizontalSlider(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT init, FAUSTFLOAT min, FAUSTFLOAT max, FAUSTFLOAT step)
{
if(isKnob(zone)){
addKnob(label, zone, init, min, max, step);
} else if(isRadio(zone)){
addRadioButtons(label, zone, init, min, max, step, fRadioDescription[zone].c_str(), false);
} else if(isMenu(zone)) {
addMenu(label, zone, init, min, max, step, fMenuDescription[zone].c_str());
} else {
if(currentBox->isVertical) {
currentBox->recommendedHeight += kHSliderHeight;
currentBox->recommendedWidth = jmax(currentBox->recommendedWidth, kHSliderWidth);
} else {
currentBox->recommendedWidth += kHSliderWidth;
currentBox->recommendedHeight = jmax(currentBox->recommendedHeight, kHSliderHeight);
}
currentBox->addChildUiComponent(new uiSlider(this, zone, kHSliderWidth, kHSliderHeight, min, max, init, step, String(label), String(fUnit[zone]), String(fTooltip[zone]), getScale(zone), HSlider));
}
}
virtual void addVerticalSlider(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT init, FAUSTFLOAT min, FAUSTFLOAT max, FAUSTFLOAT step){
if(isKnob(zone)){
addKnob(label, zone, init, min, max, step);
} else if(isRadio(zone)) {
addRadioButtons(label, zone, init, min, max, step, fRadioDescription[zone].c_str(), true);
} else if(isMenu(zone)) {
addMenu(label, zone, init, min, max, step, fMenuDescription[zone].c_str());
} else {
if(currentBox->isVertical) {
currentBox->recommendedHeight += kVSliderHeight;
currentBox->recommendedWidth = jmax(currentBox->recommendedWidth, kVSliderWidth);
} else {
currentBox->recommendedWidth += kVSliderWidth;
currentBox->recommendedHeight = jmax(currentBox->recommendedHeight, kVSliderHeight);
}
currentBox->addChildUiComponent(new uiSlider(this, zone, kVSliderWidth, kVSliderHeight, min, max, init, step, String(label), String(fUnit[zone]), String(fTooltip[zone]), getScale(zone), VSlider));
}
}
void addMenu(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT init, FAUSTFLOAT min, FAUSTFLOAT max, FAUSTFLOAT step, const char* mdescr){
if(currentBox->isVertical) {
currentBox->recommendedHeight += kMenuHeight;
currentBox->recommendedWidth = jmax(currentBox->recommendedWidth, kMenuWidth);
} else {
currentBox->recommendedWidth += kMenuWidth;
currentBox->recommendedHeight = jmax(currentBox->recommendedHeight, kMenuHeight);
}
currentBox->addChildUiComponent(new uiMenu(this, zone, String(label), kMenuWidth, kMenuHeight, init, min, max, String(fTooltip[zone]), mdescr));
}
void addRadioButtons(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT init, FAUSTFLOAT min, FAUSTFLOAT max, FAUSTFLOAT step, const char* mdescr, bool vert){
vector<string> names;
vector<double> values;
parseMenuList(mdescr, names, values);
int nbButtons = names.size();
radioGroup++;
if(currentBox->isVertical) {
if(vert){
currentBox->recommendedHeight += nbButtons * (kRadioButtonHeight - 25) + 25;
currentBox->recommendedWidth = jmax(currentBox->recommendedWidth, kCheckButtonWidth);
} else {
currentBox->recommendedHeight += kRadioButtonHeight;
currentBox->recommendedWidth = jmax(currentBox->recommendedWidth, nbButtons * kCheckButtonWidth);
}
} else {
if(vert){
currentBox->recommendedWidth += kCheckButtonWidth;
currentBox->recommendedHeight = jmax(currentBox->recommendedHeight, nbButtons * (kRadioButtonHeight - 25) + 25);
} else {
currentBox->recommendedWidth += nbButtons * kCheckButtonWidth;
currentBox->recommendedHeight = jmax(currentBox->recommendedHeight, kRadioButtonHeight);
}
}
if(vert){
currentBox->addChildUiComponent(new uiRadioButton(this, zone, String(label), kCheckButtonWidth, nbButtons * (kRadioButtonHeight - 25) + 25, init, min, max, true, names, values, String(fTooltip[zone]), mdescr, radioGroup));
} else {
currentBox->addChildUiComponent(new uiRadioButton(this, zone, String(label), kCheckButtonWidth, kRadioButtonHeight, init, min, max, false, names, values, String(fTooltip[zone]), mdescr, radioGroup));
}
}
void addKnob(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT init, FAUSTFLOAT min, FAUSTFLOAT max, FAUSTFLOAT step){
if(currentBox->isVertical) {
currentBox->recommendedHeight += kKnobHeight;
currentBox->recommendedWidth = jmax(currentBox->recommendedWidth, kKnobWidth);
} else {
currentBox->recommendedWidth += kKnobWidth;
currentBox->recommendedHeight = jmax(currentBox->recommendedHeight, kKnobHeight);
}
currentBox->addChildUiComponent(new uiSlider(this, zone, kKnobWidth, kKnobHeight, min, max, init, step, String(label), String(fUnit[zone]), String(fTooltip[zone]), getScale(zone), Knob));
}
virtual void addButton(const char* label, FAUSTFLOAT* zone){
if(currentBox->isVertical) {
currentBox->recommendedHeight += kButtonHeight;
currentBox->recommendedWidth = jmax(currentBox->recommendedWidth, kButtonWidth);
} else {
currentBox->recommendedWidth += kButtonWidth;
currentBox->recommendedHeight = jmax(currentBox->recommendedHeight, kButtonHeight);
}
currentBox->addChildUiComponent(new uiButton(this, zone, kButtonWidth, kButtonHeight, String(label), String(fTooltip[zone])));
}
virtual void addCheckButton(const char* label, FAUSTFLOAT* zone){
if(currentBox->isVertical) {
currentBox->recommendedHeight += kCheckButtonHeight;
currentBox->recommendedWidth = jmax(currentBox->recommendedWidth, kCheckButtonWidth);
} else {
currentBox->recommendedWidth += kCheckButtonWidth;
currentBox->recommendedHeight = jmax(currentBox->recommendedHeight, kCheckButtonHeight);
}
currentBox->addChildUiComponent(new uiCheckButton(this, zone, kCheckButtonWidth, kCheckButtonHeight, String(label), String(fTooltip[zone])));
}
virtual void addNumEntry(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT init, FAUSTFLOAT min, FAUSTFLOAT max, FAUSTFLOAT step)
{
if(currentBox->isVertical){
currentBox->recommendedHeight += kNumEntryHeight;
currentBox->recommendedWidth = jmax(currentBox->recommendedWidth, kNumEntryWidth);
} else {
currentBox->recommendedWidth += kNumEntryWidth;
currentBox->recommendedHeight = jmax(currentBox->recommendedHeight, kNumEntryHeight);
}
currentBox->addChildUiComponent(new uiSlider(this, zone, kNumEntryWidth, kNumEntryHeight, min, max, init, step, String(label), String(fUnit[zone]), String(fTooltip[zone]), getScale(zone), NumEntry));
}
virtual void addHorizontalBargraph(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT min, FAUSTFLOAT max)
{
if(isLed(zone)) {
addLed(String(label), zone, min, max);
} else if(isNumerical(zone)) {
addNumericalDisplay(String(label), zone, min, max);
} else {
if(currentBox->isVertical){
currentBox->recommendedHeight += kHBargraphHeight;
currentBox->recommendedWidth = jmax(currentBox->recommendedWidth, kHBargraphWidth);
} else {
currentBox->recommendedWidth += kHBargraphWidth;
currentBox->recommendedHeight = jmax(currentBox->recommendedHeight, kHBargraphHeight);
}
currentBox->addChildUiComponent(new uiVUMeter (this, zone, kHBargraphWidth, kHBargraphHeight, String(label), min, max, String(fUnit[zone]), String(fTooltip[zone]), HVUMeter, false));
}
}
virtual void addVerticalBargraph(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT min, FAUSTFLOAT max)
{
if(isLed(zone)){
addLed(String(label), zone, min, max);
} else if(isNumerical(zone)) {
addNumericalDisplay(String(label), zone, min, max);
} else {
if(currentBox->isVertical){
currentBox->recommendedHeight += kVBargraphHeight;
currentBox->recommendedWidth = jmax(currentBox->recommendedWidth, kVBargraphWidth);
} else {
currentBox->recommendedWidth += kVBargraphWidth;
currentBox->recommendedHeight = jmax(currentBox->recommendedHeight, kVBargraphHeight);
}
currentBox->addChildUiComponent(new uiVUMeter (this, zone, kVBargraphWidth, kVBargraphHeight, String(label), min, max, String(fUnit[zone]), String(fTooltip[zone]), VVUMeter, true));
}
}
void addLed (String label, FAUSTFLOAT* zone, FAUSTFLOAT min, FAUSTFLOAT max){
if(currentBox->isVertical){
currentBox->recommendedHeight += kLedHeight;
currentBox->recommendedWidth = jmax(currentBox->recommendedWidth, kLedWidth);
} else {
currentBox->recommendedWidth += kLedWidth;
currentBox->recommendedHeight = jmax(currentBox->recommendedHeight, kLedHeight);
}
currentBox->addChildUiComponent(new uiVUMeter (this, zone, kLedWidth, kLedHeight, label, min, max, String(fUnit[zone]), String(fTooltip[zone]), Led, false));
}
void addNumericalDisplay(String label, FAUSTFLOAT* zone, FAUSTFLOAT min, FAUSTFLOAT max){
if(currentBox->isVertical){
currentBox->recommendedHeight += kNumDisplayHeight;
currentBox->recommendedWidth = jmax(currentBox->recommendedWidth, kNumDisplayWidth);
} else {
currentBox->recommendedWidth += kNumDisplayWidth;
currentBox->recommendedHeight = jmax(currentBox->recommendedHeight, kNumDisplayHeight);
}
currentBox->addChildUiComponent(new uiVUMeter (this, zone, kNumDisplayWidth, kNumDisplayHeight, label, min, max, String(fUnit[zone]), String(fTooltip[zone]), NumDisplay, false));
}
virtual void declare(FAUSTFLOAT* zone, const char* key, const char* value)
{
MetaDataUI::declare(zone, key, value);
}
void init(){
if(tabLayout){
tabs.init();
} else {
dynamic_cast<faustBox*> (getChildComponent(0))->setRatio();
dynamic_cast<faustBox*> (getChildComponent(0))->setLayoutComponentSize(getLocalBounds());
dynamic_cast<faustBox*> (getChildComponent(0))->setCompLookAndFeel(laf);
}
}
void resized(){
if(tabLayout) {
tabs.setBounds(getLocalBounds());
} else {
dynamic_cast<faustBox*> (getChildComponent(0))->setLayoutComponentSize(getLocalBounds());
}
}
~Juce_GUI(){
std::cout<<std::endl<<"Destructing boxes"<<std::endl;
delete currentBox;
delete parentBox;
}
int order;
int radioGroup;
faustBox* currentBox;
faustBox* parentBox;
bool tabLayout = false;
Faust_tabs tabs;
String tabName;
ScopedPointer<LookAndFeel> laf = new CustomLookAndFeel();
};
|