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 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077
|
/************************************************************************
IMPORTANT NOTE : this file contains two clearly delimited sections :
the ARCHITECTURE section (in two parts) and the USER section. Each section
is governed by its own copyright and license. Please check individually
each section for license and copyright information.
*************************************************************************/
/******************* BEGIN bela.cpp ****************/
/************************************************************************
Bela FAUST Architecture file
Oli Larkin 2016
www.olilarkin.co.uk
Based on owl.cpp
FAUST Architecture File
Copyright (C) 2003-2019 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.
************************************************************************
************************************************************************/
/************************************************************************
Evolution (2022): Trill Sensors support
type of sensors supported :
BAR : Position, Pressure, Touched. (Multitouch not supported)
SQUARE : Position X & Y, Pressure, Touched. (Multitouch not supported)
CRAFT : Pressure or index of (first or last) active pin (depend on mode)
RING : Position, Pressure, Touched. (Multitouch not supported)
HEX : Position, Pressure, Touched. (Multitouch not supported)
usage : add in Meta data in UI widget of the Faust Code
TRILL:BAR_POS_n
TRILL:BAR_LVL_n
TRILL:BAR_TOUCH_n
TRILL:SQUARE_XPOS_n
TRILL:SQUARE_YPOS_n
TRILL:SQUARE_LVL_n
TRILL:SQUARE_TOUCH_n
TRILL:CRAFT_n PIN no_pin
TRILL:CRAFT_n UP lo_pin-hi_pin (return the index of the higher pin active in the array of pin defined or -1 if no pin active)
TRILL:CRAFT_n DOWN lo_pin-hi_pin (return the index of the lower pin active in the array of pin defined or -1 if no pin active)
TRILL:CRAFT_n SLIDER down_pin-up_pin (return a buffered value. press the down_pin décraise the value, press the up_pin incraise the value)
TRILL:RING_POS_n
TRILL:RING_POS_n MULTITURN nbr (the range oh value is extended on 'nbr' turn)
TRILL:RING_LVL_n
TRILL:RING_TOUCH_n
TRILL:HEX_POS_n
TRILL:HEX_LVL_n
TRILL:HEX_TOUCH_n
where n is the sensors index. index suported are 0 to 7 for each type of sensor.
for the sensors BAR, SQUARE and HEX they are a buffered value option (for RING_POS sensors the value is buffered in MULTITURN mode).
if BUFFERED is set, the value are persistent when the sensor is not touched. If not set, the value return to default value.
(This option as no effect for the TOUCH value of the sensors)
usage : [ TRILL:XXXX_n BUFFERED ]
sensibility settings for craft :
declare trill_settings "{ 'CRAFT_n' : { 'prescaler' : 4 ; 'threshold' : 0.15 } ; CRAFT_m ... }"
mapping of the sensors i2c adresses (required) :
declare trill_mappings "{'BAR' : {'0' : 32 ; '1' : 33 ...} ; 'SQUARE' : {'0' : 40 ; '1' : 41 ...} ; 'CRAFT' : {'0' : 48 ...} ; 'RING' : { '0' : 56 ... } ; 'HEX' : { '0' : 56 ... } }"
keyboard for polyphony :
declare trill_keyboard "{'CRAFT_n' : {'start_pin' : 0 ; 'end_pin' : 29 ; 'start_note' : {'C' : 4} ; 'scale' : {1 ; 0.5 ; 1 ; 1 ; 1 ; 1 ; 0.5 } }; CRAFT_m : {'start_pin' : 0 ; 'end_pin' : 12 ...} ...}"
'start_pin' and 'end_pin' are the limits of the array of pin used for a craft sensor.
'start_note' is note of the first keyboard's pin in the forme : { 'Note' : octave }.
'scale' is an optional argument. if not present the scale of the keyboard is chromatic. The scale is defined by the values of spaces betwen the note. The resolution is the semi-tone. ex of scale : { 1 ; 1 ; 1.5 ; 1 ; 1.5 }
The trill_keyboard update the sliders defined as freq, gain and gate (via the mydsp_poly key_On and key_Off functions).
************************************************************************/
#ifndef __FaustBela_H__
#define __FaustBela_H__
#include <cstddef>
#include <string>
#include <iostream>
#include <math.h>
#include <strings.h>
#include <cstdlib>
#include <Bela.h>
#include <Utilities.h>
#include <libraries/Trill/Trill.h>
using namespace std;
#include "faust/gui/SimpleParser.h"
#include "faust/dsp/timed-dsp.h"
#include "faust/gui/DecoratorUI.h"
#include "faust/gui/MidiUI.h"
// for MIDI support
#ifdef MIDICTRL
#include "faust/midi/bela-midi.h"
#endif
// for OSC support
#ifdef OSCCTRL
#include "faust/gui/BelaOSCUI.h"
#endif
// for HTTPDGUI support
#ifdef HTTPDGUI
#include "faust/gui/httpdUI.h"
#endif
// for soundfile support
#ifdef SOUNDFILE
#include "faust/gui/SoundUI.h"
#endif
// for polyphonic synths
#include "faust/dsp/poly-dsp.h"
// for polyphonic synths with FX
#ifdef POLY2
#include "faust/dsp/dsp-combiner.h"
#include "effect.h"
#endif
const unsigned int i2cBus = 1;
const char* const pinNamesStrings[] =
{
"ANALOG_0",
"ANALOG_1",
"ANALOG_2",
"ANALOG_3",
"ANALOG_4",
"ANALOG_5",
"ANALOG_6",
"ANALOG_7",
"ANALOG_8",
"DIGITAL_0",
"DIGITAL_1",
"DIGITAL_2",
"DIGITAL_3",
"DIGITAL_4",
"DIGITAL_5",
"DIGITAL_6",
"DIGITAL_7",
"DIGITAL_8",
"DIGITAL_9",
"DIGITAL_10",
"DIGITAL_11",
"DIGITAL_12",
"DIGITAL_13",
"DIGITAL_14",
"DIGITAL_15",
"ANALOG_OUT_0", // outputs
"ANALOG_OUT_1",
"ANALOG_OUT_2",
"ANALOG_OUT_3",
"ANALOG_OUT_4",
"ANALOG_OUT_5",
"ANALOG_OUT_6",
"ANALOG_OUT_7",
"ANALOG_OUT_8",
"BAR_POS_0", // Trill sensors
"BAR_LVL_0",
"BAR_TOUCH_0",
"BAR_POS_1",
"BAR_LVL_1",
"BAR_TOUCH_1",
"BAR_POS_2",
"BAR_LVL_2",
"BAR_TOUCH_2",
"BAR_POS_3",
"BAR_LVL_3",
"BAR_TOUCH_3",
"BAR_POS_4",
"BAR_LVL_4",
"BAR_TOUCH_4",
"BAR_POS_5",
"BAR_LVL_5",
"BAR_TOUCH_5",
"BAR_POS_6",
"BAR_LVL_6",
"BAR_TOUCH_6",
"BAR_POS_7",
"BAR_LVL_7",
"BAR_TOUCH_7",
"SQUARE_XPOS_0",
"SQUARE_YPOS_0",
"SQUARE_LVL_0",
"SQUARE_TOUCH_0",
"SQUARE_XPOS_1",
"SQUARE_YPOS_1",
"SQUARE_LVL_1",
"SQUARE_TOUCH_1",
"SQUARE_XPOS_2",
"SQUARE_YPOS_2",
"SQUARE_LVL_2",
"SQUARE_TOUCH_2",
"SQUARE_XPOS_3",
"SQUARE_YPOS_3",
"SQUARE_LVL_3",
"SQUARE_TOUCH_3",
"SQUARE_XPOS_4",
"SQUARE_YPOS_4",
"SQUARE_LVL_4",
"SQUARE_TOUCH_4",
"SQUARE_XPOS_5",
"SQUARE_YPOS_5",
"SQUARE_LVL_5",
"SQUARE_TOUCH_5",
"SQUARE_XPOS_6",
"SQUARE_YPOS_6",
"SQUARE_LVL_6",
"SQUARE_TOUCH_6",
"SQUARE_XPOS_7",
"SQUARE_YPOS_7",
"SQUARE_LVL_7",
"SQUARE_TOUCH_7",
"CRAFT_0",
"CRAFT_1",
"CRAFT_2",
"CRAFT_3",
"CRAFT_4",
"CRAFT_5",
"CRAFT_6",
"CRAFT_7",
"RING_POS_0",
"RING_LVL_0",
"RING_TOUCH_0",
"RING_POS_1",
"RING_LVL_1",
"RING_TOUCH_1",
"RING_POS_2",
"RING_LVL_2",
"RING_TOUCH_2",
"RING_POS_3",
"RING_LVL_3",
"RING_TOUCH_3",
"RING_POS_4",
"RING_LVL_4",
"RING_TOUCH_4",
"RING_POS_5",
"RING_LVL_5",
"RING_TOUCH_5",
"RING_POS_6",
"RING_LVL_6",
"RING_TOUCH_6",
"RING_POS_7",
"RING_LVL_7",
"RING_TOUCH_7",
"HEX_XPOS_0",
"HEX_YPOS_0",
"HEX_LVL_0",
"HEX_TOUCH_0",
"HEX_XPOS_1",
"HEX_YPOS_1",
"HEX_LVL_1",
"HEX_TOUCH_1",
"HEX_XPOS_2",
"HEX_YPOS_2",
"HEX_LVL_2",
"HEX_TOUCH_2",
"HEX_XPOS_3",
"HEX_YPOS_3",
"HEX_LVL_3",
"HEX_TOUCH_3",
"HEX_XPOS_4",
"HEX_YPOS_4",
"HEX_LVL_4",
"HEX_TOUCH_4",
"HEX_XPOS_5",
"HEX_YPOS_5",
"HEX_LVL_5",
"HEX_TOUCH_5",
"HEX_XPOS_6",
"HEX_YPOS_6",
"HEX_LVL_6",
"HEX_TOUCH_6",
"HEX_XPOS_7",
"HEX_YPOS_7",
"HEX_LVL_7",
"HEX_TOUCH_7"
};
enum EInOutPin
{
kNoPin = -1,
kANALOG_0 = 0,
kANALOG_1,
kANALOG_2,
kANALOG_3,
kANALOG_4,
kANALOG_5,
kANALOG_6,
kANALOG_7,
kANALOG_8,
kDIGITAL_0,
kDIGITAL_1,
kDIGITAL_2,
kDIGITAL_3,
kDIGITAL_4,
kDIGITAL_5,
kDIGITAL_6,
kDIGITAL_7,
kDIGITAL_8,
kDIGITAL_9,
kDIGITAL_10,
kDIGITAL_11,
kDIGITAL_12,
kDIGITAL_13,
kDIGITAL_14,
kDIGITAL_15,
kANALOG_OUT_0,
kANALOG_OUT_1,
kANALOG_OUT_2,
kANALOG_OUT_3,
kANALOG_OUT_4,
kANALOG_OUT_5,
kANALOG_OUT_6,
kANALOG_OUT_7,
kANALOG_OUT_8,
kBAR_POS_0,
kBAR_LVL_0,
kBAR_TOUCH_0,
kBAR_POS_1,
kBAR_LVL_1,
kBAR_TOUCH_1,
kBAR_POS_2,
kBAR_LVL_2,
kBAR_TOUCH_2,
kBAR_POS_3,
kBAR_LVL_3,
kBAR_TOUCH_3,
kBAR_POS_4,
kBAR_LVL_4,
kBAR_TOUCH_4,
kBAR_POS_5,
kBAR_LVL_5,
kBAR_TOUCH_5,
kBAR_POS_6,
kBAR_LVL_6,
kBAR_TOUCH_6,
kBAR_POS_7,
kBAR_LVL_7,
kBAR_TOUCH_7,
kSQUARE_XPOS_0,
kSQUARE_YPOS_0,
kSQUARE_LVL_0,
kSQUARE_TOUCH_0,
kSQUARE_XPOS_1,
kSQUARE_YPOS_1,
kSQUARE_LVL_1,
kSQUARE_TOUCH_1,
kSQUARE_XPOS_2,
kSQUARE_YPOS_2,
kSQUARE_LVL_2,
kSQUARE_TOUCH_2,
kSQUARE_XPOS_3,
kSQUARE_YPOS_3,
kSQUARE_LVL_3,
kSQUARE_TOUCH_3,
kSQUARE_XPOS_4,
kSQUARE_YPOS_4,
kSQUARE_LVL_4,
kSQUARE_TOUCH_4,
kSQUARE_XPOS_5,
kSQUARE_YPOS_5,
kSQUARE_LVL_5,
kSQUARE_TOUCH_5,
kSQUARE_XPOS_6,
kSQUARE_YPOS_6,
kSQUARE_LVL_6,
kSQUARE_TOUCH_6,
kSQUARE_XPOS_7,
kSQUARE_YPOS_7,
kSQUARE_LVL_7,
kSQUARE_TOUCH_7,
kCRAFT_0,
kCRAFT_1,
kCRAFT_2,
kCRAFT_3,
kCRAFT_4,
kCRAFT_5,
kCRAFT_6,
kCRAFT_7,
kRING_POS_0,
kRING_LVL_0,
kRING_TOUCH_0,
kRING_POS_1,
kRING_LVL_1,
kRING_TOUCH_1,
kRING_POS_2,
kRING_LVL_2,
kRING_TOUCH_2,
kRING_POS_3,
kRING_LVL_3,
kRING_TOUCH_3,
kRING_POS_4,
kRING_LVL_4,
kRING_TOUCH_4,
kRING_POS_5,
kRING_LVL_5,
kRING_TOUCH_5,
kRING_POS_6,
kRING_LVL_6,
kRING_TOUCH_6,
kRING_POS_7,
kRING_LVL_7,
kRING_TOUCH_7,
kHEX_XPOS_0,
kHEX_YPOS_0,
kHEX_LVL_0,
kHEX_TOUCH_0,
kHEX_XPOS_1,
kHEX_YPOS_1,
kHEX_LVL_1,
kHEX_TOUCH_1,
kHEX_XPOS_2,
kHEX_YPOS_2,
kHEX_LVL_2,
kHEX_TOUCH_2,
kHEX_XPOS_3,
kHEX_YPOS_3,
kHEX_LVL_3,
kHEX_TOUCH_3,
kHEX_XPOS_4,
kHEX_YPOS_4,
kHEX_LVL_4,
kHEX_TOUCH_4,
kHEX_XPOS_5,
kHEX_YPOS_5,
kHEX_LVL_5,
kHEX_TOUCH_5,
kHEX_XPOS_6,
kHEX_YPOS_6,
kHEX_LVL_6,
kHEX_TOUCH_6,
kHEX_XPOS_7,
kHEX_YPOS_7,
kHEX_LVL_7,
kHEX_TOUCH_7,
kNumInputPins
};
const char* const NoteStrings[] =
{
"A",
"A#",
"B",
"C",
"C#",
"D",
"D#",
"E",
"F",
"F#",
"G",
"G#"
};
/**
* @brief parseBracketString, parse an arbitrary {} string {...} and store the result in s
* @param p the string to parse, then the remaining string
* @param quote the character used to quote the string
* @param s the string found if any
* @return true if a string was found at the begin of p
*/
static bool parseBracketString(const char*& p, string& s)
{
string str;
skipBlank(p);
int level = 0;
const char* saved = p; // to restore position if we fail
if (*p++ == '{') {
level++;
while (*p != 0) {
if (*p == '{') level ++;
else if (*p == '}') {
if (level > 1) {
level--;
} else {
*p++;
break;
}
}
str += *p++;
}
if (level == 1) {
s = "{" + str + "}";
return true;
}
}
p = saved;
return false;
}
/**
* @brief parseMenuItemStr, parse a menu item ...'low':{...}...
* @param p the string to parse, then the remaining string
* @param name the name found
* @param value the value found as String
* @return true if a nemu item was found
*/
static bool parseMenuItemStr(const char*& p, string& name, string& value)
{
const char* saved = p; // to restore position if we fail
if (parseSQString(p, name) && parseChar(p, ':') && parseBracketString(p, value)) {
return true;
} else {
p = saved;
return false;
}
}
/**
* @brief parseMenuListMenu, parse a menu list { 'setting1' : { 'param1' : 40 ; 'param2' : 880.0 ...} ; 'setting2' : { 'param1' : 40 ; 'param2' : 880.0 ...}...}
* @param p the string to parse, then the remaining string
* @param names the vector of names found
* @param values the vector of menus found
* @return true if a menu list was found
*/
static bool parseMenuListMenu(const char*& p, vector<string>& names, vector<string>& values)
{
vector<string> tmpnames;
vector<string> tmpvalues;
const char* saved = p; // to restore position if we fail
if (parseChar(p, '{')) {
do {
string n;
string v;
if (parseMenuItemStr(p, n, v)) {
tmpnames.push_back(n);
tmpvalues.push_back(v);
} else {
p = saved;
return false;
}
} while (parseChar(p, ';'));
if (parseChar(p, '}')) {
// we suceeded
names = tmpnames;
values = tmpvalues;
return true;
}
}
p = saved;
return false;
}
/// ---------------------------------------------------------------------
// Parse list of double
/// ---------------------------------------------------------------------
static bool parseListDouble(const char*& p, vector<double>& items)
{
const char* saved = p; // to restore position if we fail
if (parseChar(p, '{')) {
do {
double item;
if (!parseDouble(p, item)) {
p = saved;
return false;
}
items.push_back(item);
} while (tryChar(p, ';'));
return parseChar(p, '}');
}
return false;
}
class CheckBoxLogic
{
protected:
bool fOldState;
bool fOut;
public:
CheckBoxLogic()
:fOldState(false)
,fOut(false)
{}
bool getOutState(bool state)
{
if (!fOldState && state) {
fOut = !fOut;
}
fOldState = state;
return fOut;
}
};
class UpDownKeyLogic
{
protected:
bool fOldStateUp;
bool fOldStateDown;
int fOut;
public:
UpDownKeyLogic()
:fOldStateUp(false)
,fOldStateDown(false)
,fOut(0)
{}
int getOutState(bool stateUp, bool stateDown)
{
if ((!fOldStateUp && stateUp)) {
fOut = 1;
} else if ((!fOldStateDown && stateDown)) {
fOut = -1;
} else {
fOut = 0;
}
fOldStateUp = stateUp;
fOldStateDown = stateDown;
return fOut;
}
};
static dsp* gDSP = NULL;
/**************************************************************************************
BelaWidget : object used by BelaUI to ensures the connection between a Bela parameter
and a Faust widget
***************************************************************************************/
class BelaWidget
{
protected:
EInOutPin fBelaPin;
FAUSTFLOAT* fZone; // zone
const char* fLabel; // label
FAUSTFLOAT fMin; // minimal value
FAUSTFLOAT fRange; // value range (max-min)
FAUSTFLOAT fStep; // precision of the value
public:
BelaWidget()
:fBelaPin(kNoPin)
,fZone(0)
,fLabel("")
,fMin(0)
,fRange(1)
,fStep(0)
{}
BelaWidget(const BelaWidget& w)
:fBelaPin(w.fBelaPin)
,fZone(w.fZone)
,fLabel(w.fLabel)
,fMin(w.fMin)
,fRange(w.fRange)
,fStep(0)
{}
BelaWidget(EInOutPin pin, FAUSTFLOAT* z, const char* l, FAUSTFLOAT lo, FAUSTFLOAT hi, FAUSTFLOAT step)
:fBelaPin(pin)
,fZone(z)
,fLabel(l)
,fMin(lo)
,fRange(hi-lo)
,fStep(step)
{}
virtual ~BelaWidget() {}
virtual bool setParameters(const char* parameters)
{
return false;
}
virtual void update(BelaContext* context)
{
switch(fBelaPin) {
case kANALOG_0:
case kANALOG_1:
case kANALOG_2:
case kANALOG_3:
case kANALOG_4:
case kANALOG_5:
case kANALOG_6:
case kANALOG_7:
*fZone = fMin + fRange * analogReadNI(context, 0, (int)fBelaPin);
break;
case kDIGITAL_0:
case kDIGITAL_1:
case kDIGITAL_2:
case kDIGITAL_3:
case kDIGITAL_4:
case kDIGITAL_5:
case kDIGITAL_6:
case kDIGITAL_7:
case kDIGITAL_8:
case kDIGITAL_9:
case kDIGITAL_10:
case kDIGITAL_11:
case kDIGITAL_12:
case kDIGITAL_13:
case kDIGITAL_14:
case kDIGITAL_15:
*fZone = digitalRead(context, 0, ((int)fBelaPin - kDIGITAL_0)) == 0 ? fMin : fMin+fRange;
break;
case kANALOG_OUT_0:
case kANALOG_OUT_1:
case kANALOG_OUT_2:
case kANALOG_OUT_3:
case kANALOG_OUT_4:
case kANALOG_OUT_5:
case kANALOG_OUT_6:
case kANALOG_OUT_7:
analogWriteNI(context, 0, ((int)fBelaPin) - kANALOG_OUT_0, (*fZone - fMin)/(fRange+fMin));
break;
default:
break;
};
}
virtual EInOutPin getBelaPin()
{
return fBelaPin;
}
};
class BelaWidgetCheckBox : public BelaWidget
{
protected:
CheckBoxLogic fChkBoxSystem;
public:
BelaWidgetCheckBox():BelaWidget() {}
BelaWidgetCheckBox(const BelaWidgetCheckBox& w):BelaWidget((BelaWidget) w) {}
BelaWidgetCheckBox(EInOutPin pin, FAUSTFLOAT* z, const char* l, FAUSTFLOAT lo, FAUSTFLOAT hi, FAUSTFLOAT step)
{
fBelaPin = pin;
fZone = z; // zone
fLabel = l; // label
fMin = lo; // minimal value
fRange = hi - lo;
fStep = step;
}
virtual ~BelaWidgetCheckBox() {}
virtual void update(BelaContext* context)
{
switch(fBelaPin) {
case kDIGITAL_0:
case kDIGITAL_1:
case kDIGITAL_2:
case kDIGITAL_3:
case kDIGITAL_4:
case kDIGITAL_5:
case kDIGITAL_6:
case kDIGITAL_7:
case kDIGITAL_8:
case kDIGITAL_9:
case kDIGITAL_10:
case kDIGITAL_11:
case kDIGITAL_12:
case kDIGITAL_13:
case kDIGITAL_14:
case kDIGITAL_15:
bool value = (bool) digitalRead(context, 0, ((int)fBelaPin - kDIGITAL_0));
*fZone = fMin+fRange * ((double)fChkBoxSystem.getOutState(value));
break;
};
}
};
/**************************************************************************************
TrillWidget : object used by BelaUI to ensures the connection between a Trill sensors values
and a Faust widget.
***************************************************************************************/
class TrillWidget : public BelaWidget
{
protected:
Trill* fSensor;
Trill::Device fType;
FAUSTFLOAT fDefaultValue;
bool fBuffered;
public:
TrillWidget():BelaWidget()
{
fSensor = NULL;
fType = Trill::NONE;
fDefaultValue = 0;
fBuffered = false;
}
TrillWidget(const TrillWidget& w):BelaWidget((BelaWidget)w)
{
fSensor = NULL;
fType = Trill::NONE;
fDefaultValue = w.fDefaultValue;
fBuffered = w.fBuffered;
}
TrillWidget(EInOutPin pin, FAUSTFLOAT* z, const char* l, FAUSTFLOAT init, FAUSTFLOAT lo, FAUSTFLOAT hi, FAUSTFLOAT step)
{
fBelaPin = pin;
fZone = z; // zone
fLabel = l; // label
fMin = lo; // minimal value
fRange = hi - lo;
fStep = step;
fSensor = NULL;
fDefaultValue = init;
*fZone = fDefaultValue;
if (strstr(pinNamesStrings[fBelaPin], "BAR")) {
fType = Trill::BAR;
} else if (strstr(pinNamesStrings[fBelaPin], "SQUARE")) {
fType = Trill::SQUARE;
} else if (strstr(pinNamesStrings[fBelaPin], "HEX")) {
fType = Trill::HEX;
} else {
fType = Trill::NONE;
}
fBuffered = false;
}
virtual ~TrillWidget() {}
virtual void setSensor(Trill* nSensor)
{
if (nSensor) fSensor = nSensor;
}
/* set the parameters defined in the declare directive or in the widget's metadata */
virtual bool setParameters(const char* parameters)
{
const char* saved = parameters; // to restore position if we fail
bool result = false;
if (parseWord(parameters, "BUFFERED")) {
fBuffered = true;
result = true;
}
else if (parseChar(parameters, '{')) {
do {
string n;
string v;
double vd;
if (parseMenuItemStr(parameters, n, v)) {
setParameter(n, v);
result = true;
} else if (parseMenuItem(parameters, n, vd)) {
setParameter(n, vd);
result = true;
}
else {
parameters = saved;
return result;
}
} while (parseChar(parameters, ';'));
if (parseChar(parameters, '}')) {
// we suceeded
return result;
}
}
parameters = saved;
return result;
}
virtual void setParameter(const string& name, double value) { }
virtual void setParameter(const string& name, const string& value) { }
virtual void update(BelaContext* context)
{
if (!fSensor)
return;
float val = 0.f;
switch (fBelaPin) {
case kBAR_POS_0:
case kBAR_POS_1:
case kBAR_POS_2:
case kBAR_POS_3:
case kBAR_POS_4:
case kBAR_POS_5:
case kBAR_POS_6:
case kBAR_POS_7:
if (fSensor->getNumTouches() > 0) {
val = fSensor->compoundTouchLocation();
*fZone = fMin + fRange * val;
} else if (!fBuffered) {
*fZone = fDefaultValue;
}
break;
case kBAR_LVL_0:
case kBAR_LVL_1:
case kBAR_LVL_2:
case kBAR_LVL_3:
case kBAR_LVL_4:
case kBAR_LVL_5:
case kBAR_LVL_6:
case kBAR_LVL_7:
if (fSensor->getNumTouches() > 0) {
val = fSensor->compoundTouchSize();
*fZone = fMin + fRange * val;
} else if (!fBuffered) {
*fZone = fDefaultValue;
}
break;
case kBAR_TOUCH_0:
case kBAR_TOUCH_1:
case kBAR_TOUCH_2:
case kBAR_TOUCH_3:
case kBAR_TOUCH_4:
case kBAR_TOUCH_5:
case kBAR_TOUCH_6:
case kBAR_TOUCH_7:
val = fSensor->getNumTouches();
*fZone = min(fRange,val);
break;
case kSQUARE_XPOS_0:
case kSQUARE_XPOS_1:
case kSQUARE_XPOS_2:
case kSQUARE_XPOS_3:
case kSQUARE_XPOS_4:
case kSQUARE_XPOS_5:
case kSQUARE_XPOS_6:
case kSQUARE_XPOS_7:
if (fSensor->getNumTouches() > 0) {
val = fSensor->compoundTouchHorizontalLocation();
*fZone = fMin + fRange * val;
} else if (!fBuffered) {
*fZone = fDefaultValue;
}
break;
case kSQUARE_YPOS_0:
case kSQUARE_YPOS_1:
case kSQUARE_YPOS_2:
case kSQUARE_YPOS_3:
case kSQUARE_YPOS_4:
case kSQUARE_YPOS_5:
case kSQUARE_YPOS_6:
case kSQUARE_YPOS_7:
if (fSensor->getNumTouches() > 0) {
val = fSensor->compoundTouchLocation();
*fZone = fMin + fRange * val;
} else if (!fBuffered) {
*fZone = fDefaultValue;
}
break;
case kSQUARE_LVL_0:
case kSQUARE_LVL_1:
case kSQUARE_LVL_2:
case kSQUARE_LVL_3:
case kSQUARE_LVL_4:
case kSQUARE_LVL_5:
case kSQUARE_LVL_6:
case kSQUARE_LVL_7:
if (fSensor->getNumTouches() > 0) {
val = fSensor->compoundTouchSize();
*fZone = fMin + fRange * val;
} else if (!fBuffered) {
*fZone = fDefaultValue;
}
break;
case kSQUARE_TOUCH_0:
case kSQUARE_TOUCH_1:
case kSQUARE_TOUCH_2:
case kSQUARE_TOUCH_3:
case kSQUARE_TOUCH_4:
case kSQUARE_TOUCH_5:
case kSQUARE_TOUCH_6:
case kSQUARE_TOUCH_7:
val = fSensor->getNumTouches();
*fZone = min(fRange,val);
break;
case kRING_LVL_0:
case kRING_LVL_1:
case kRING_LVL_2:
case kRING_LVL_3:
case kRING_LVL_4:
case kRING_LVL_5:
case kRING_LVL_6:
case kRING_LVL_7:
if (fSensor->getNumTouches() > 0) {
val = fSensor->compoundTouchSize();
*fZone = fMin + fRange * val;
} else if (!fBuffered) {
*fZone = fDefaultValue;
}
break;
case kRING_TOUCH_0:
case kRING_TOUCH_1:
case kRING_TOUCH_2:
case kRING_TOUCH_3:
case kRING_TOUCH_4:
case kRING_TOUCH_5:
case kRING_TOUCH_6:
case kRING_TOUCH_7:
val = fSensor->getNumTouches();
*fZone = min(fRange,val);
break;
case kHEX_XPOS_0:
case kHEX_XPOS_1:
case kHEX_XPOS_2:
case kHEX_XPOS_3:
case kHEX_XPOS_4:
case kHEX_XPOS_5:
case kHEX_XPOS_6:
case kHEX_XPOS_7:
if (fSensor->getNumTouches() > 0) {
val = fSensor->compoundTouchHorizontalLocation();
*fZone = fMin + fRange * val;
} else if (!fBuffered) {
*fZone = fDefaultValue;
}
break;
case kHEX_YPOS_0:
case kHEX_YPOS_1:
case kHEX_YPOS_2:
case kHEX_YPOS_3:
case kHEX_YPOS_4:
case kHEX_YPOS_5:
case kHEX_YPOS_6:
case kHEX_YPOS_7:
if (fSensor->getNumTouches() > 0) {
val = fSensor->compoundTouchLocation();
*fZone = fMin + fRange * val;
} else if (!fBuffered) {
*fZone = fDefaultValue;
}
break;
case kHEX_LVL_0:
case kHEX_LVL_1:
case kHEX_LVL_2:
case kHEX_LVL_3:
case kHEX_LVL_4:
case kHEX_LVL_5:
case kHEX_LVL_6:
case kHEX_LVL_7:
if (fSensor->getNumTouches() > 0) {
val = fSensor->compoundTouchSize();
*fZone = fMin + fRange * val;
} else if (!fBuffered) {
*fZone = fDefaultValue;
}
break;
case kHEX_TOUCH_0:
case kHEX_TOUCH_1:
case kHEX_TOUCH_2:
case kHEX_TOUCH_3:
case kHEX_TOUCH_4:
case kHEX_TOUCH_5:
case kHEX_TOUCH_6:
case kHEX_TOUCH_7:
val = fSensor->getNumTouches();
*fZone = min(fRange,val);
break;
default:
break;
};
}
Trill::Device getType() { return fType; }
Trill* getSensor() { return fSensor; }
};
/**************************************************************************************
TrillCraftWidget : object used by BelaUI to ensures the connection between a Trill Craft sensors values
and a Faust widget.
***************************************************************************************/
typedef struct {
int note;
double state;
} TrillNote;
class TrillCraftWidget : public TrillWidget
{
protected:
int fLopin;
int fHipin;
string fMode;
int fPrescaler;
double fThreshold;
vector<TrillNote*> fKeyboard; // list of keys in the trillkeyboard (polyphony mode)
int fStartNote;
vector<int> fScale; // in semitone
int noteToMidiNumber(const string& note, int octave) // return the midi number of the note at the octave defined
{
if (octave >= 0) {
int deltaoct = octave*12;
int deltanote = 0;
for (int i = 0; i < 12 ; i++) {
if (strcasecmp(note.c_str(),NoteStrings[i]) == 0) {
deltanote = i;
}
}
return deltaoct+deltanote+21;
} else {
return 69;
}
}
public:
TrillCraftWidget():TrillWidget()
{
fSensor = NULL;
fType = Trill::CRAFT;
fLopin = -1;
fHipin = -1;
fMode = "PIN";
fPrescaler = 2;
fThreshold = 0.10;
fStartNote = 0;
fScale.push_back(1); // default chromatic scale
fDefaultValue = 0;
}
TrillCraftWidget(const TrillCraftWidget& w):TrillWidget((TrillWidget)w)
{
fSensor = NULL;
fType = Trill::CRAFT;
fLopin = -1;
fHipin = -1;
fMode = "PIN";
fPrescaler = 2;
fThreshold = 0.10;
fStartNote = 0;
fScale.push_back(1); // default chromatic scale
fDefaultValue = 0;
}
TrillCraftWidget(EInOutPin pin, FAUSTFLOAT* z, const char* l, FAUSTFLOAT init, FAUSTFLOAT lo, FAUSTFLOAT hi, FAUSTFLOAT step)
{
fBelaPin = pin;
fZone = z; // zone
fLabel = l; // label
fMin = lo; // minimal value
fRange = hi - lo;
fStep = step;
fSensor = NULL;
fType = Trill::CRAFT;
fLopin = -1;
fHipin = -1;
fMode = "PIN";
fPrescaler = 2;
fThreshold = 0.10;
fStartNote = 0;
fScale.push_back(1); //default chromatic scale
fDefaultValue = init;
}
virtual ~TrillCraftWidget()
{
for (auto t : fKeyboard) {
delete t;
}
}
virtual void setSensor(Trill* nSensor)
{
TrillWidget::setSensor(nSensor);
if (fSensor) {
fSensor->setPrescaler(fPrescaler);
fSensor->setNoiseThreshold(fThreshold);
}
}
virtual bool setParameters(const char* parameters)
{
if (parameters && !TrillWidget::setParameters(parameters)) {
if (parseWord(parameters, "PIN")) {
fMode = "PIN";
} else if (parseWord(parameters, "UP")) {
fMode = "UP";
} else if (parseWord(parameters, "DOWN")) {
fMode = "DOWN";
} else if (parseWord(parameters, "SLIDER")) {
fMode = "SLIDER";
}
double tmpval = 0.;
if (parameters && parseDouble(parameters, tmpval)) {
fLopin = (int)tmpval;
} else {
fLopin = -1;
}
if (parameters && parseChar(parameters, '-') && parseDouble(parameters, tmpval)) {
fHipin = (int)tmpval;
} else {
fHipin = -1;
}
}
return true;
}
virtual void setParameter(const string& name, const double value)
{
TrillWidget::setParameter(name,value);
if (name == "fPrescaler") fPrescaler = (int)value;
else if (name == "fThreshold") fThreshold = (int)value;
else if (name == "start_pin") fLopin = (int)value;
else if (name == "end_pin") fHipin = (int)value;
}
virtual void setParameter(const string& name, const string& value)
{
const char* tmpval = value.c_str();
if (name == "start_note") {
vector<string> names;
vector<double> values;
if (parseMenuList(tmpval,names,values) && names.size() > 0) {
fStartNote = noteToMidiNumber(names[0],(int) values[0]);
}
} else if (name == "scale") {
vector<double> values;
if (parseListDouble(tmpval,values) && values.size() > 0) {
fScale.clear();
for (int i = 0 ; i<values.size() ; i++) {
fScale.push_back( (int) (values[i]*2));
}
}
}
}
virtual void update(BelaContext* context)
{
if (fSensor && fLopin >= 0) {
float val = -1.f;
if (fMode == "PIN") {
*fZone = fMin + fRange * fSensor->rawData[fLopin];
}
else if (fMode == "UP") {
float sval = 0.f;
for (int i = fHipin; i >= fLopin; i--) {
sval = fSensor->rawData[i];
if (sval > 0.f)
{
val = i-fLopin;
break;
}
}
*fZone = val;
}
else if (fMode == "DOWN") {
float sval = 0.f;
for (int i = fLopin; i <= fHipin; i++) {
sval = fSensor->rawData[i];
if (sval > 0.f)
{
val = i-fLopin;
break;
}
}
*fZone = val;
} else if (fMode == "KEYBOARD") {
mydsp_poly* TmpDsp = (mydsp_poly*) gDSP;
for (int i = fLopin ; i <= fHipin ; i++) { //Call all keyOff
TrillNote* CurKey = fKeyboard[i-fLopin];
double sval = fSensor->rawData[i];
if (sval == 0 && CurKey->state > 0) {
TmpDsp->keyOff(0,CurKey->note);
CurKey->state=0;
}
}
for (int i = fLopin ; i <= fHipin ; i++) { //Call all keyOn
TrillNote* CurKey = fKeyboard[i-fLopin];
double sval = fSensor->rawData[i];
if (sval > 0 && CurKey->state == 0) {
TmpDsp->keyOn(0,CurKey->note, (int) (sval*127));
CurKey->state=sval;
}
}
}
}
}
void setMode(const string& mo)
{
fMode = mo;
if (fMode == "KEYBOARD" && fLopin >= 0 && fHipin >= fLopin && fStartNote > 0) { // create the array of trill keyboard
double curnote = fStartNote;
int scalecounter = 0;
for (int i = fLopin ; i <= fHipin ; i++) {
TrillNote* newkey = new TrillNote;
newkey->note = curnote;
newkey->state = 0;
fKeyboard.push_back(newkey);
if (scalecounter >= fScale.size()) {
scalecounter = 0;
}
curnote = curnote + fScale[scalecounter];
scalecounter++;
}
}
}
void setLopin(int pin) { fLopin = pin; }
void setHipin(int pin) { fHipin = pin; }
};
class TrillCraftWidgetCheckBox : public TrillCraftWidget
{
protected:
CheckBoxLogic fChkBoxSystem;
public:
TrillCraftWidgetCheckBox(): TrillCraftWidget() {}
TrillCraftWidgetCheckBox(const TrillCraftWidgetCheckBox& w): TrillCraftWidget((TrillCraftWidget) w) {}
TrillCraftWidgetCheckBox(EInOutPin pin, FAUSTFLOAT* z, const char* l, FAUSTFLOAT init, FAUSTFLOAT lo, FAUSTFLOAT hi, FAUSTFLOAT step): TrillCraftWidget(pin, z, l, init, lo, hi, step) {}
virtual ~TrillCraftWidgetCheckBox() {}
virtual void update(BelaContext* context)
{
if (fSensor && fLopin >= 0 && fMode == "PIN")
{
double value = fSensor->rawData[fLopin];
bool value_state = fChkBoxSystem.getOutState((bool) value);
*fZone = fMin + fRange * value_state;
}
}
};
class TrillCraftWidgetSlider : public TrillCraftWidget
{
protected:
UpDownKeyLogic fSliderSystem;
public:
TrillCraftWidgetSlider(): TrillCraftWidget() {}
TrillCraftWidgetSlider(const TrillCraftWidgetSlider& w): TrillCraftWidget((TrillCraftWidget) w) {}
TrillCraftWidgetSlider(EInOutPin pin, FAUSTFLOAT* z, const char* l,FAUSTFLOAT init, FAUSTFLOAT lo, FAUSTFLOAT hi, FAUSTFLOAT step ): TrillCraftWidget(pin, z, l, init, lo, hi, step) {
*fZone = init;
}
virtual ~TrillCraftWidgetSlider() {}
virtual void update(BelaContext* context)
{
if (fSensor && fLopin >= 0 && fMode == "SLIDER") {
double downKey = fSensor->rawData[fLopin];
double upKey = fSensor->rawData[fHipin];
double value_state = (double) fSliderSystem.getOutState(downKey, upKey);
double tmpval = *fZone + fStep * value_state;
if (tmpval >= fMin && tmpval <= (fRange+fMin)) {
*fZone=tmpval;
}
}
}
};
class TrillRingPosWidget : public TrillWidget
{
protected:
int fTurnLimit;
int fTurnNumber;
bool fMultiTurn;
float fTurnDetectZone;
int ChangeTurnDetect(float oldpos, float newpos)
{
if (oldpos <= (fTurnDetectZone/2) && newpos >= (1 - fTurnDetectZone/2)) {
return -1;
} else if (oldpos >= (1 - fTurnDetectZone/2) && newpos <= (fTurnDetectZone/2)) {
return 1;
}
return 0;
}
public:
TrillRingPosWidget(): TrillWidget()
{
fTurnLimit = 1;
fTurnNumber = 0;
fMultiTurn = false;
fTurnDetectZone = 0.2f;
fType = Trill::RING;
}
TrillRingPosWidget(const TrillRingPosWidget& w): TrillWidget((TrillWidget) w)
{
fTurnLimit = w.fTurnLimit;
fTurnNumber = w.fTurnNumber;
fMultiTurn = w.fMultiTurn;
fTurnDetectZone = w.fTurnDetectZone;
fType = Trill::RING;
}
TrillRingPosWidget(EInOutPin pin, FAUSTFLOAT* z, const char* l,FAUSTFLOAT init, FAUSTFLOAT lo, FAUSTFLOAT hi, FAUSTFLOAT step, float turndetectsensitivity = 0.2f ): TrillWidget(pin, z, l, init, lo, hi, step)
{
fTurnLimit = 1;
fTurnNumber = 0;
fMultiTurn = false;
fTurnDetectZone = turndetectsensitivity;
fType = Trill::RING;
}
virtual ~TrillRingPosWidget() {}
virtual bool setParameters(const char* parameters)
{
if (parameters && !TrillWidget::setParameters(parameters)) {
if (parseWord(parameters, "MULTITURN")) {
fMultiTurn = true;
}
double tmpval = 0.f;
if (parameters && parseDouble(parameters, tmpval) && fMultiTurn) {
fTurnLimit = (int)tmpval;
} else {
fTurnLimit = 1;
}
}
if (fMultiTurn && fTurnLimit > 1 && fDefaultValue != fMin) // if multiturn mode, calculate the current turn
{
float turnrange = fRange / fTurnLimit;
fTurnNumber = floor((fDefaultValue - fMin) / turnrange);
}
return true;
}
virtual void update(BelaContext* context)
{
if (!fSensor)
return;
float val = 0.f;
switch (fBelaPin) {
case kRING_POS_0:
case kRING_POS_1:
case kRING_POS_2:
case kRING_POS_3:
case kRING_POS_4:
case kRING_POS_5:
case kRING_POS_6:
case kRING_POS_7:
if (fSensor->getNumTouches() > 0) {
val = fSensor->compoundTouchLocation();
if (fMultiTurn) {
float turnrange = fRange / fTurnLimit;
float oldfZone = *fZone;
float oldsensorPos = (oldfZone - fMin - turnrange * fTurnNumber) / turnrange;
int turnincrement = ChangeTurnDetect(oldsensorPos, val);
float newval = fMin + turnrange * val + turnrange * (fTurnNumber+turnincrement);
if (newval > (fMin + fRange)) {
*fZone = fMin + fRange;
} else if (newval < fMin) {
*fZone = fMin;
} else {
*fZone = newval;
}
fTurnNumber += turnincrement;
} else {
*fZone = fMin + fRange * val;
}
}
else if (!fMultiTurn) {
*fZone = fDefaultValue;
}
break;
default:
break;
};
}
};
/**************************************************************************************
BelaUI : Faust User Interface builder. Passed to buildUserInterface BelaUI allows
the mapping between BELA pins and Faust widgets. It relies on specific
metadata "...[BELA:DIGITAL_0]..." in the widget's label for that. For example any
Faust widget with metadata [BELA:DIGITAL_0] will be controlled by DIGITAL_0
(the second knob).
***************************************************************************************/
// The maximum number of mappings between Bela parameters and Faust widgets
// To be modified: We can have 8 inputs, 8 outputs, and 16 digital In or Out.
#define MAXBELAWIDGETS 16
// Max number of trill sensors parameters mapped.
// max of 8 BAR sensors with 3 parameters (Position,Pressure,Touch), 8 SQUARE sensors with 4 parameters
// (Position X, Position Y, Pressure, Touch), 8 CRAFT sensors with 1 parameter
#define MAXTRILLWIDGETS 64
class BelaUI : public GenericUI, public Meta
{
private:
int fIndex; // number of BelaWidgets collected so far
EInOutPin fBelaPin; // current pin id
BelaWidget fTable[MAXBELAWIDGETS]; // list of BelaWidgets
EInOutPin fTrillPin; // current trill pin id
vector<TrillWidget*> fTrillTable; // list of TrillWidget
const char* fTrillParams;
vector<Trill*> fTouchSensors; // list of Trill sensors
// Check if the widget is linked to a Bela parameter and, if so, add the corresponding BelaWidget
void addBelaWidget(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT lo, FAUSTFLOAT hi, FAUSTFLOAT step)
{
if (fBelaPin != kNoPin && (fIndex < MAXBELAWIDGETS)) {
fTable[fIndex] = BelaWidget(fBelaPin, zone, label, lo, hi, step);
fIndex++;
}
fBelaPin = kNoPin;
}
void addBelaWidgetCheckBox(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT lo, FAUSTFLOAT hi)
{
if (fBelaPin != kNoPin && (fIndex < MAXBELAWIDGETS)) {
fTable[fIndex] = BelaWidgetCheckBox(fBelaPin, zone, label, lo, hi, 0);
fIndex++;
}
fBelaPin = kNoPin;
}
void addTrillWidget(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT init, FAUSTFLOAT lo, FAUSTFLOAT hi, FAUSTFLOAT step)
{
if (fTrillPin != kNoPin) {
if (strstr(pinNamesStrings[fTrillPin], "CRAFT"))
{
TrillCraftWidget* newcraft = new TrillCraftWidget(fTrillPin, zone, label, init, lo, hi, step);
newcraft->setParameters(fTrillParams);
fTrillTable.push_back(newcraft);
}
else if (strstr(pinNamesStrings[fTrillPin], "RING_POS"))
{
TrillRingPosWidget* newringpos = new TrillRingPosWidget(fTrillPin, zone, label, init, lo, hi, step);
newringpos->setParameters(fTrillParams);
fTrillTable.push_back(newringpos);
}
else
{
TrillWidget* newtrill = new TrillWidget(fTrillPin, zone, label, init, lo, hi, step);
newtrill->setParameters(fTrillParams);
fTrillTable.push_back(newtrill);
}
}
fTrillPin = kNoPin;
fTrillParams = NULL;
}
void addTrillWidgetCheckBox(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT init, FAUSTFLOAT lo, FAUSTFLOAT hi)
{
if (fTrillPin != kNoPin) {
if (strstr(pinNamesStrings[fTrillPin], "CRAFT"))
{
TrillCraftWidgetCheckBox* newcraft = new TrillCraftWidgetCheckBox(fTrillPin, zone, label, init, lo, hi, 0);
newcraft->setParameters(fTrillParams);
fTrillTable.push_back(newcraft);
}
}
fTrillPin = kNoPin;
fTrillParams = NULL;
}
void addTrillWidgetSlider(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT init, FAUSTFLOAT lo, FAUSTFLOAT hi, FAUSTFLOAT step)
{
if (fTrillPin != kNoPin) {
TrillCraftWidget* newcraft;
if (strstr(pinNamesStrings[fTrillPin], "CRAFT"))
{
if (strstr(fTrillParams, "SLIDER")) {
TrillCraftWidgetSlider* newcraftslider = new TrillCraftWidgetSlider(fTrillPin, zone, label, init, lo, hi, step);
newcraft = (TrillCraftWidget*) newcraftslider;
} else {
TrillCraftWidget* newcraftsensor = new TrillCraftWidget(fTrillPin, zone, label, init, lo, hi, step);
newcraft = newcraftsensor;
}
newcraft->setParameters(fTrillParams);
fTrillTable.push_back(newcraft);
}
else if (strstr(pinNamesStrings[fTrillPin], "RING_POS"))
{
TrillRingPosWidget* newringpos = new TrillRingPosWidget(fTrillPin, zone, label, init, lo, hi, step);
newringpos->setParameters(fTrillParams);
fTrillTable.push_back(newringpos);
}
else
{
TrillWidget* newtrill = new TrillWidget(fTrillPin, zone, label, init, lo, hi, step);
newtrill->setParameters(fTrillParams);
fTrillTable.push_back(newtrill);
}
}
fTrillPin = kNoPin;
fTrillParams = NULL;
}
TrillWidget* findTrillbyid(int id)
{
for (int i = 0; i < fTrillTable.size(); i++) {
if (fTrillTable[i]->getBelaPin() == id)
return fTrillTable[i];
}
return NULL;
}
public:
BelaUI()
: fIndex(0)
, fBelaPin(kNoPin)
, fTrillPin(kNoPin)
, fTrillParams(NULL)
{}
virtual ~BelaUI()
{
for (auto t : fTrillTable) {
delete t;
}
for (auto t : fTouchSensors) {
delete t;
}
}
// Should be called before compute() to update widget's zones registered as Bela parameters
void update(BelaContext* context)
{
for (int i = 0; i < fIndex; i++) {
fTable[i].update(context);
}
for (size_t i = 0; i < fTrillTable.size(); i++) {
fTrillTable[i]->update(context);
}
}
// Should be called in auxiliary loop to read de sensor's values
void updateSensors()
{
for (size_t n = 0; n < fTouchSensors.size(); ++n) {
Trill* t = fTouchSensors[n];
t->readI2C();
}
}
// -- active widgets
virtual void addButton(const char* label, FAUSTFLOAT* zone)
{
if (fBelaPin != kNoPin)
addBelaWidget(label, zone, FAUSTFLOAT(0), FAUSTFLOAT(1),0);
else
addTrillWidget(label, zone, 0, FAUSTFLOAT(0), FAUSTFLOAT(1),0);
}
virtual void addCheckButton(const char* label, FAUSTFLOAT* zone)
{
if (fBelaPin != kNoPin)
addBelaWidgetCheckBox(label, zone, FAUSTFLOAT(0), FAUSTFLOAT(1));
else
addTrillWidgetCheckBox(label, zone, 0, FAUSTFLOAT(0), FAUSTFLOAT(1));
}
virtual void addVerticalSlider(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT init, FAUSTFLOAT lo, FAUSTFLOAT hi, FAUSTFLOAT step)
{
if (fBelaPin != kNoPin)
addBelaWidget(label, zone, lo, hi, step);
else
addTrillWidgetSlider(label, zone, init, lo, hi, step);
}
virtual void addHorizontalSlider(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT init, FAUSTFLOAT lo, FAUSTFLOAT hi, FAUSTFLOAT step)
{
if (fBelaPin != kNoPin)
addBelaWidget(label, zone, lo, hi, step);
else
addTrillWidgetSlider(label, zone, init, lo, hi, step);
}
virtual void addNumEntry(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT init, FAUSTFLOAT lo, FAUSTFLOAT hi, FAUSTFLOAT step)
{
if (fBelaPin != kNoPin)
addBelaWidget(label, zone, lo, hi, step);
else
addTrillWidget(label, zone, init, lo, hi, step);
}
// -- passive widgets
virtual void addHorizontalBargraph(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT lo, FAUSTFLOAT hi)
{ addBelaWidget(label, zone, lo, hi, 0); }
virtual void addVerticalBargraph(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT lo, FAUSTFLOAT hi)
{ addBelaWidget(label, zone, lo, hi, 0); }
// -- metadata declarations
virtual void declare(FAUSTFLOAT* z, const char* k, const char* id)
{
if (strcasecmp(k, "BELA") == 0) {
for (int i = 0; i < kNumInputPins; i++) {
if (strcasecmp(id, pinNamesStrings[i]) == 0) {
fBelaPin = (EInOutPin)i;
}
}
}
else if (strcasecmp(k, "TRILL") == 0) {
for (int i = 0; i < kNumInputPins; i++) {
if (strstr(id, pinNamesStrings[i])) {
fTrillPin = (EInOutPin)i;
const char* tmp = id;
if (parseWord(tmp, pinNamesStrings[i])) {
fTrillParams = tmp;
}
}
}
}
}
virtual void declare(const char* k, const char* id) // assumes that ui metadata are already parsed
{
if (strcasecmp(k, "trill_settings") == 0) {
vector<string> names;
vector<string> values;
if (parseMenuListMenu(id, names, values)) {
for (int i = 0; i < names.size(); i++) {
for (int j = 0; j < kNumInputPins; j++) {
if (strcasecmp(names[i].c_str(),pinNamesStrings[j] ) == 0) {
TrillWidget* curwidget = findTrillbyid(j); // find the right widget
if (curwidget) {
curwidget->setParameters(values[i].c_str());
}
}
}
}
}
} else if (strcasecmp(k, "trill_mappings") == 0) {
vector<string> names;
vector<string> values;
if (parseMenuListMenu(id, names, values)) {
for (int i = 0; i<names.size();i++) {
if (names[i] == "BAR") {
initSensorWidgets(Trill::BAR, values[i]);
} else if (names[i] == "SQUARE") {
initSensorWidgets(Trill::SQUARE, values[i]);
} else if (names[i] == "CRAFT") {
initSensorWidgets(Trill::CRAFT, values[i]);
} else if (names[i] == "RING") {
initSensorWidgets(Trill::RING, values[i]);
} else if (names[i] == "HEX") {
initSensorWidgets(Trill::HEX, values[i]);
}
}
}
#ifdef NVOICES
} else if (strcasecmp(k, "trill_keyboard") == 0) {
vector<string> names;
vector<string> values;
if (parseMenuListMenu(id, names, values)) {
for (int i = 0; i<names.size(); i++) {
EInOutPin found_pin = kNoPin;
for (int j = 0; j < kNumInputPins; j++) {
if (strstr(names[i].c_str(), pinNamesStrings[j])) {
found_pin = (EInOutPin)j;
break;
}
}
if (found_pin != kNoPin) {
TrillCraftWidget* newcraft = new TrillCraftWidget(found_pin, 0, "Keyboard", 0, 0, 0);
newcraft->setParameters(values[i].c_str());
newcraft->setMode("KEYBOARD");
fTrillTable.push_back(newcraft);
}
}
}
#endif
}
}
// Initialize the sensors and affect there to the right widgets
void initSensorWidgets(Trill::Device device, const string& mapping)
{
vector<string> names;
vector<double> values;
Trill* curSensor = NULL;
bool affected = false;
const char* tmpmapping = mapping.c_str();
if (parseMenuList(tmpmapping, names, values)) {
for (int i = 0; i < names.size(); i++) {
Trill::Device typedevice = Trill::probe(i2cBus, (uint8_t)values[i]);
if (typedevice == device) { // is the right sensor type
curSensor = new Trill(i2cBus, device, (uint8_t)values[i]);
for (int j = 0; j < fTrillTable.size(); j++) { // find the right widgets
TrillWidget* CurWidget = fTrillTable[j];
if (CurWidget && device == CurWidget->getType() && strstr(pinNamesStrings[CurWidget->getBelaPin()], names[i].c_str())) {
affected = true;
CurWidget->setSensor(curSensor);
}
}
if (affected) {
fTouchSensors.push_back(curSensor); // preserve the sensor affected to the widget(s)
}
else if (curSensor) { // delete if not affected
delete curSensor;
}
}
affected = false;
curSensor = NULL;
}
}
}
int getNbTrill()
{
return fTrillTable.size();
}
};
#endif // __FaustCommonInfrastructure__
/******************************************************************************
*******************************************************************************
VECTOR INTRINSICS
*******************************************************************************
*******************************************************************************/
<<includeIntrinsic>>
/********************END ARCHITECTURE SECTION (part 1/2)****************/
/**************************BEGIN USER SECTION **************************/
<<includeclass>>
/***************************END USER SECTION ***************************/
/*******************BEGIN ARCHITECTURE SECTION (part 2/2)***************/
list<GUI*> GUI::fGuiList;
ztimedmap GUI::gTimedZoneMap;
/**************************************************************************************
Bela render.cpp that calls FAUST generated code
***************************************************************************************/
#ifdef MIDICTRL
static bela_midi gMIDI;
static MidiUI* gMidiInterface = NULL;
#endif
#ifdef OSCCTRL
#define OSC_IP_ADDRESS "192.168.7.1"
#define OSC_IN_PORT 5510
#define OSC_OUT_PORT 5511
static BelaOSCUI gOSCUI(OSC_IP_ADDRESS, OSC_IN_PORT, OSC_OUT_PORT);
#endif
#ifdef HTTPDGUI
static httpdUI* gHttpdInterface = NULL;
#endif
#ifdef SOUNDFILE
// Use bundle path
static SoundUI gSoundInterface(SoundUI::getBinaryPath());
#endif
static FAUSTFLOAT** gInputs = NULL; // array of pointers to context->audioIn data
static FAUSTFLOAT** gOutputs = NULL; // array of pointers to context->audioOut data
static BelaUI gControlUI;
const int DELAYTRILLLOOP = 5000;
// This is the auxilary task function which will read our Trill sensors loop
static void trillLoop(void*)
{
while (!Bela_stopRequested())
{
// Read all Trill sensors
gControlUI.updateSensors();
// Put the process to sleep when finished
usleep(DELAYTRILLLOOP);
}
}
//*******************************************************************************
void Bela_userSettings(BelaInitSettings* settings)
{
// Faust code needs non-interleaved data
settings->uniformSampleRate = 1;
settings->interleave = 0;
settings->analogOutputsPersist = 0;
}
bool setup(BelaContext* context, void* userData)
{
int nvoices = 0;
bool midi_sync = false;
bool midi = false;
mydsp* tmp_dsp = new mydsp();
MidiMeta::analyse(tmp_dsp, midi, midi_sync, nvoices);
delete tmp_dsp;
// Routing the stderr stream to a file (some code part in the mydsp_poly are too talkative and generate mode switch during the execution)
freopen ("stderr_file.txt", "w", stderr);
// Access deinterleaded inputs
gInputs = new FAUSTFLOAT*[context->audioInChannels];
for (unsigned int ch = 0; ch < context->audioInChannels; ch++) {
gInputs[ch] = (float*)&context->audioIn[ch * context->audioFrames];
}
// Access deinterleaded outputs
gOutputs = new FAUSTFLOAT*[context->audioOutChannels];
for (unsigned int ch = 0; ch < context->audioOutChannels; ch++) {
gOutputs[ch] = (float*)&context->audioOut[ch * context->audioFrames];
}
// Polyphonic with effect
#ifdef POLY2
int group = 1;
cout << "Started with " << nvoices << " voices" << endl;
gDSP = new mydsp_poly(new mydsp(), nvoices, true, group);
#ifdef MIDICTRL
if (midi_sync) {
gDSP = new timed_dsp(new dsp_sequencer(gDSP, new effect()));
} else {
gDSP = new dsp_sequencer(gDSP, new effect());
}
#else
gDSP = new dsp_sequencer(gDSP, new effect());
#endif
#else
int group = 1;
if (nvoices > 0) {
cout << "Started with " << nvoices << " voices" << endl;
gDSP = new mydsp_poly(new mydsp(), nvoices, true, group);
#ifdef MIDICTRL
if (midi_sync) {
gDSP = new timed_dsp(gDSP);
}
#endif
} else {
#ifdef MIDICTRL
if (midi_sync) {
gDSP = new timed_dsp(new mydsp());
} else {
gDSP = new mydsp();
}
#else
gDSP = new mydsp();
#endif
}
#endif
if (gDSP == NULL) {
cerr << "Unable to allocate Faust DSP object" << endl;
return false;
}
// Using dsp_adapter when the number of bela Audio IO channels are less than the DSP
if (gDSP->getNumInputs() > context->audioInChannels || gDSP->getNumOutputs() > context->audioOutChannels) {
gDSP = new dsp_adapter(gDSP, context->audioInChannels, context->audioOutChannels, context->audioFrames);
}
gDSP->init(context->audioSampleRate);
gDSP->buildUserInterface(&gControlUI); // Maps Bela Analog/Digital IO, Trill sensors and Faust widgets
gDSP->metadata(&gControlUI); // Get the extra settings for Trill sensors
#ifdef HTTPDGUI
gHttpdInterface = new httpdUI("Bela-UI", gDSP->getNumInputs(), gDSP->getNumOutputs(), 0, NULL);
gDSP->buildUserInterface(gHttpdInterface);
gHttpdInterface->run();
#endif /* HTTPD GUI */
#ifdef MIDICTRL
gMidiInterface = new MidiUI(&gMIDI);
gDSP->buildUserInterface(gMidiInterface);
gMidiInterface->run();
#endif
// OSC
#ifdef OSCCTRL
gDSP->buildUserInterface(&gOSCUI);
gOSCUI.run();
#endif
#ifdef SOUNDFILE
// SoundUI has to be dispatched on all internal voices
gDSP->buildUserInterface(&gSoundInterface);
#endif
// Setup the trill sensors only if needed
if (gControlUI.getNbTrill() > 0) {
Bela_runAuxiliaryTask(trillLoop);
}
return true;
}
void render(BelaContext* context, void* userData)
{
// Reads Bela pins and updates corresponding Faust Widgets zones
gControlUI.update(context);
// Synchronize all GUI controllers
GUI::updateAllGuis();
// Process Faust DSP
gDSP->compute(context->audioFrames, gInputs, gOutputs);
}
void cleanup(BelaContext* context, void* userData)
{
#ifdef HTTPDGUI
delete gHttpdInterface;
#endif /* HTTPDGUI */
delete [] gInputs;
delete [] gOutputs;
delete gDSP;
#ifdef MIDICTRL
delete gMidiInterface;
#endif
}
/******************** END bela.cpp ****************/
|