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 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299
|
/* GSequencer - Advanced GTK Sequencer
* Copyright (C) 2005-2024 Joël Krähemann
*
* This file is part of GSequencer.
*
* GSequencer 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.
*
* GSequencer 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 GSequencer. If not, see <http://www.gnu.org/licenses/>.
*/
#include <ags/plugin/ags_lv2_plugin.h>
#include <lv2/lv2plug.in/ns/lv2ext/lv2_programs.h>
#include <ags/plugin/ags_lv2_plugin.h>
#include <ags/plugin/ags_lv2_preset.h>
#include <ags/plugin/ags_lv2_manager.h>
#include <ags/plugin/ags_lv2_event_manager.h>
#include <ags/plugin/ags_lv2_uri_map_manager.h>
#include <ags/plugin/ags_lv2_urid_manager.h>
#include <ags/plugin/ags_lv2_log_manager.h>
#include <ags/plugin/ags_lv2_worker_manager.h>
#include <ags/plugin/ags_lv2_worker.h>
#include <ags/plugin/ags_lv2_urid_manager.h>
#include <ags/plugin/ags_lv2_option_manager.h>
#include <ags/plugin/ags_plugin_port.h>
#include <ags/audio/midi/ags_midi_smf_util.h>
#if defined(AGS_W32API)
#include <windows.h>
#else
#include <dlfcn.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
#include <math.h>
//#define _LIBINTL_H
#include <ags/i18n.h>
void ags_lv2_plugin_class_init(AgsLv2PluginClass *lv2_plugin);
void ags_lv2_plugin_init (AgsLv2Plugin *lv2_plugin);
void ags_lv2_plugin_set_property(GObject *gobject,
guint prop_id,
const GValue *value,
GParamSpec *param_spec);
void ags_lv2_plugin_get_property(GObject *gobject,
guint prop_id,
GValue *value,
GParamSpec *param_spec);
void ags_lv2_plugin_dispose(GObject *gobject);
void ags_lv2_plugin_finalize(GObject *gobject);
gpointer ags_lv2_plugin_instantiate(AgsBasePlugin *base_plugin,
guint samplerate, guint buffer_size);
void ags_lv2_plugin_connect_port(AgsBasePlugin *base_plugin,
gpointer plugin_handle,
guint port_index,
gpointer data_location);
void ags_lv2_plugin_activate(AgsBasePlugin *base_plugin,
gpointer plugin_handle);
void ags_lv2_plugin_deactivate(AgsBasePlugin *base_plugin,
gpointer plugin_handle);
void ags_lv2_plugin_run(AgsBasePlugin *base_plugin,
gpointer plugin_handle,
snd_seq_event_t *seq_event,
guint frame_count);
void ags_lv2_plugin_load_plugin(AgsBasePlugin *base_plugin);
void ags_lv2_plugin_real_change_program(AgsLv2Plugin *lv2_plugin,
gpointer ladspa_handle,
guint bank_index,
guint program_index);
/**
* SECTION:ags_lv2_plugin
* @short_description: The lv2 plugin class
* @title: AgsLv2Plugin
* @section_id:
* @include: ags/plugin/ags_lv2_plugin.h
*
* The #AgsLv2Plugin loads/unloads a Lv2 plugin.
*/
enum{
PROP_0,
PROP_PNAME,
PROP_URI,
PROP_UI_URI,
PROP_MANIFEST,
PROP_TURTLE,
PROP_DOAP_NAME,
PROP_FOAF_NAME,
PROP_FOAF_HOMEPAGE,
PROP_FOAF_MBOX,
PROP_PRESET,
};
enum{
CHANGE_PROGRAM,
LAST_SIGNAL,
};
static gpointer ags_lv2_plugin_parent_class = NULL;
static guint lv2_plugin_signals[LAST_SIGNAL];
GType
ags_lv2_plugin_get_type (void)
{
static gsize g_define_type_id__static = 0;
if(g_once_init_enter(&g_define_type_id__static)){
GType ags_type_lv2_plugin = 0;
static const GTypeInfo ags_lv2_plugin_info = {
sizeof (AgsLv2PluginClass),
NULL, /* lv2_init */
NULL, /* lv2_finalize */
(GClassInitFunc) ags_lv2_plugin_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (AgsLv2Plugin),
0, /* n_preallocs */
(GInstanceInitFunc) ags_lv2_plugin_init,
};
ags_type_lv2_plugin = g_type_register_static(AGS_TYPE_BASE_PLUGIN,
"AgsLv2Plugin",
&ags_lv2_plugin_info,
0);
g_once_init_leave(&g_define_type_id__static, ags_type_lv2_plugin);
}
return(g_define_type_id__static);
}
GType
ags_lv2_plugin_flags_get_type()
{
static gsize g_flags_type_id__static;
if(g_once_init_enter(&g_flags_type_id__static)){
static const GFlagsValue values[] = {
{ AGS_LV2_PLUGIN_IS_SYNTHESIZER, "AGS_LV2_PLUGIN_IS_SYNTHESIZER", "lv2-plugin-is-synthesizer" },
{ AGS_LV2_PLUGIN_NEEDS_WORKER, "AGS_LV2_PLUGIN_NEEDS_WORKER", "lv2-plugin-needs-worker" },
{ AGS_LV2_PLUGIN_HAS_PROGRAM_INTERFACE, "AGS_LV2_PLUGIN_HAS_PROGRAM_INTERFACE", "lv2-plugin-has-program-interface" },
{ 0, NULL, NULL }
};
GType g_flags_type_id = g_flags_register_static(g_intern_static_string("AgsLv2PluginFlags"), values);
g_once_init_leave(&g_flags_type_id__static, g_flags_type_id);
}
return(g_flags_type_id__static);
}
void
ags_lv2_plugin_class_init(AgsLv2PluginClass *lv2_plugin)
{
AgsBasePluginClass *base_plugin;
GObjectClass *gobject;
GParamSpec *param_spec;
ags_lv2_plugin_parent_class = g_type_class_peek_parent(lv2_plugin);
/* GObjectClass */
gobject = (GObjectClass *) lv2_plugin;
gobject->set_property = ags_lv2_plugin_set_property;
gobject->get_property = ags_lv2_plugin_get_property;
gobject->dispose = ags_lv2_plugin_dispose;
gobject->finalize = ags_lv2_plugin_finalize;
/* properties */
/**
* AgsLv2Plugin:pname:
*
* The assigned pname.
*
* Since: 3.0.0
*/
param_spec = g_param_spec_string("pname",
i18n_pspec("pname of the plugin"),
i18n_pspec("The pname this plugin is associated with"),
NULL,
G_PARAM_READABLE | G_PARAM_WRITABLE);
g_object_class_install_property(gobject,
PROP_PNAME,
param_spec);
/**
* AgsLv2Plugin:uri:
*
* The assigned uri.
*
* Since: 3.0.0
*/
param_spec = g_param_spec_string("uri",
i18n_pspec("uri of the plugin"),
i18n_pspec("The uri this plugin is located in"),
NULL,
G_PARAM_READABLE | G_PARAM_WRITABLE);
g_object_class_install_property(gobject,
PROP_URI,
param_spec);
/**
* AgsLv2Plugin:ui-uri:
*
* The assigned ui-uri.
*
* Since: 3.0.0
*/
param_spec = g_param_spec_string("ui-uri",
i18n_pspec("ui-uri of the plugin"),
i18n_pspec("The ui-uri this plugin has"),
NULL,
G_PARAM_READABLE | G_PARAM_WRITABLE);
g_object_class_install_property(gobject,
PROP_UI_URI,
param_spec);
/**
* AgsLv2Plugin:manifest:
*
* The assigned manifest.
*
* Since: 3.0.0
*/
param_spec = g_param_spec_object("manifest",
i18n_pspec("manifest of the plugin"),
i18n_pspec("The manifest this plugin is located in"),
AGS_TYPE_TURTLE,
G_PARAM_READABLE | G_PARAM_WRITABLE);
g_object_class_install_property(gobject,
PROP_MANIFEST,
param_spec);
/**
* AgsLv2Plugin:turtle:
*
* The assigned turtle.
*
* Since: 3.0.0
*/
param_spec = g_param_spec_object("turtle",
i18n_pspec("turtle of the plugin"),
i18n_pspec("The turtle this plugin is located in"),
AGS_TYPE_TURTLE,
G_PARAM_READABLE | G_PARAM_WRITABLE);
g_object_class_install_property(gobject,
PROP_TURTLE,
param_spec);
/**
* AgsLv2Plugin:doap-name:
*
* The assigned doap name.
*
* Since: 3.0.0
*/
param_spec = g_param_spec_string("doap-name",
i18n_pspec("doap name"),
i18n_pspec("The doap name"),
NULL,
G_PARAM_READABLE | G_PARAM_WRITABLE);
g_object_class_install_property(gobject,
PROP_DOAP_NAME,
param_spec);
/**
* AgsLv2Plugin:foaf-name:
*
* The assigned foaf name.
*
* Since: 3.0.0
*/
param_spec = g_param_spec_string("foaf-name",
i18n_pspec("foaf name"),
i18n_pspec("The foaf name"),
NULL,
G_PARAM_READABLE | G_PARAM_WRITABLE);
g_object_class_install_property(gobject,
PROP_FOAF_NAME,
param_spec);
/**
* AgsLv2Plugin:foaf-homepage:
*
* The assigned foaf homepage.
*
* Since: 3.0.0
*/
param_spec = g_param_spec_string("foaf-homepage",
i18n_pspec("foaf homepage"),
i18n_pspec("The foaf homepage"),
NULL,
G_PARAM_READABLE | G_PARAM_WRITABLE);
g_object_class_install_property(gobject,
PROP_FOAF_HOMEPAGE,
param_spec);
/**
* AgsLv2Plugin:foaf-mbox:
*
* The assigned foaf mbox.
*
* Since: 3.0.0
*/
param_spec = g_param_spec_string("foaf-mbox",
i18n_pspec("foaf mbox"),
i18n_pspec("The foaf mbox"),
NULL,
G_PARAM_READABLE | G_PARAM_WRITABLE);
g_object_class_install_property(gobject,
PROP_FOAF_MBOX,
param_spec);
/**
* AgsLv2Plugin:preset: (type GList(AgsLv2Preset)) (transfer full)
*
* The assigned preset.
*
* Since: 3.0.0
*/
param_spec = g_param_spec_pointer("preset",
i18n_pspec("preset of the plugin"),
i18n_pspec("The preset of this plugin"),
G_PARAM_READABLE | G_PARAM_WRITABLE);
g_object_class_install_property(gobject,
PROP_PRESET,
param_spec);
/* AgsBasePluginClass */
base_plugin = (AgsBasePluginClass *) lv2_plugin;
base_plugin->instantiate = ags_lv2_plugin_instantiate;
base_plugin->connect_port = ags_lv2_plugin_connect_port;
base_plugin->activate = ags_lv2_plugin_activate;
base_plugin->deactivate = ags_lv2_plugin_deactivate;
base_plugin->run = ags_lv2_plugin_run;
base_plugin->load_plugin = ags_lv2_plugin_load_plugin;
/* AgsLv2PluginClass */
lv2_plugin->change_program = ags_lv2_plugin_real_change_program;
/**
* AgsLv2Plugin::change-program:
* @lv2_plugin: the plugin to change-program
* @lv2_handle: the Lv2 handle
* @bank: the bank number
* @program: the program number
*
* The ::change-program signal creates a new instance of plugin.
*
* Since: 3.0.0
*/
lv2_plugin_signals[CHANGE_PROGRAM] =
g_signal_new("change-program",
G_TYPE_FROM_CLASS (lv2_plugin),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (AgsLv2PluginClass, change_program),
NULL, NULL,
ags_cclosure_marshal_VOID__POINTER_UINT_UINT,
G_TYPE_NONE, 3,
G_TYPE_POINTER,
G_TYPE_UINT,
G_TYPE_UINT);
}
void
ags_lv2_plugin_init(AgsLv2Plugin *lv2_plugin)
{
lv2_plugin->flags = 0;
lv2_plugin->pname = NULL;
lv2_plugin->uri = NULL;
lv2_plugin->ui_uri = NULL;
lv2_plugin->manifest = NULL;
lv2_plugin->turtle = NULL;
lv2_plugin->doap_name = NULL;
lv2_plugin->foaf_name = NULL;
lv2_plugin->foaf_homepage = NULL;
lv2_plugin->foaf_mbox = NULL;
lv2_plugin->feature = NULL;
lv2_plugin->program = NULL;
lv2_plugin->preset = NULL;
}
void
ags_lv2_plugin_set_property(GObject *gobject,
guint prop_id,
const GValue *value,
GParamSpec *param_spec)
{
AgsLv2Plugin *lv2_plugin;
GRecMutex *base_plugin_mutex;
lv2_plugin = AGS_LV2_PLUGIN(gobject);
/* get base plugin mutex */
base_plugin_mutex = AGS_BASE_PLUGIN_GET_OBJ_MUTEX(lv2_plugin);
switch(prop_id){
case PROP_PNAME:
{
gchar *pname;
pname = (gchar *) g_value_get_string(value);
g_rec_mutex_lock(base_plugin_mutex);
if(lv2_plugin->pname == pname){
g_rec_mutex_unlock(base_plugin_mutex);
return;
}
if(lv2_plugin->pname != NULL){
g_free(lv2_plugin->pname);
}
lv2_plugin->pname = g_strdup(pname);
g_rec_mutex_unlock(base_plugin_mutex);
}
break;
case PROP_URI:
{
gchar *uri;
uri = (gchar *) g_value_get_string(value);
g_rec_mutex_lock(base_plugin_mutex);
if(lv2_plugin->uri == uri){
g_rec_mutex_unlock(base_plugin_mutex);
return;
}
if(lv2_plugin->uri != NULL){
g_free(lv2_plugin->uri);
}
lv2_plugin->uri = g_strdup(uri);
g_rec_mutex_unlock(base_plugin_mutex);
}
break;
case PROP_UI_URI:
{
gchar *ui_uri;
ui_uri = (gchar *) g_value_get_string(value);
g_rec_mutex_lock(base_plugin_mutex);
if(lv2_plugin->ui_uri == ui_uri){
g_rec_mutex_unlock(base_plugin_mutex);
return;
}
if(lv2_plugin->ui_uri != NULL){
g_free(lv2_plugin->ui_uri);
}
lv2_plugin->ui_uri = g_strdup(ui_uri);
g_rec_mutex_unlock(base_plugin_mutex);
}
break;
case PROP_MANIFEST:
{
AgsTurtle *manifest;
manifest = (AgsTurtle *) g_value_get_object(value);
g_rec_mutex_lock(base_plugin_mutex);
if(lv2_plugin->manifest == manifest){
g_rec_mutex_unlock(base_plugin_mutex);
return;
}
if(lv2_plugin->manifest != NULL){
g_object_unref(lv2_plugin->manifest);
}
if(manifest != NULL){
g_object_ref(manifest);
}
lv2_plugin->manifest = manifest;
g_rec_mutex_unlock(base_plugin_mutex);
}
break;
case PROP_TURTLE:
{
AgsTurtle *turtle;
turtle = (AgsTurtle *) g_value_get_object(value);
g_rec_mutex_lock(base_plugin_mutex);
if(lv2_plugin->turtle == turtle){
g_rec_mutex_unlock(base_plugin_mutex);
return;
}
if(lv2_plugin->turtle != NULL){
g_object_unref(lv2_plugin->turtle);
}
if(turtle != NULL){
g_object_ref(turtle);
}
lv2_plugin->turtle = turtle;
g_rec_mutex_unlock(base_plugin_mutex);
}
break;
case PROP_DOAP_NAME:
{
gchar *doap_name;
doap_name = (gchar *) g_value_get_string(value);
g_rec_mutex_lock(base_plugin_mutex);
if(lv2_plugin->doap_name == doap_name){
g_rec_mutex_unlock(base_plugin_mutex);
return;
}
if(lv2_plugin->doap_name != NULL){
g_free(lv2_plugin->doap_name);
}
lv2_plugin->doap_name = g_strdup(doap_name);
g_rec_mutex_unlock(base_plugin_mutex);
}
break;
case PROP_FOAF_NAME:
{
gchar *foaf_name;
foaf_name = (gchar *) g_value_get_string(value);
g_rec_mutex_lock(base_plugin_mutex);
if(lv2_plugin->foaf_name == foaf_name){
g_rec_mutex_unlock(base_plugin_mutex);
return;
}
if(lv2_plugin->foaf_name != NULL){
g_free(lv2_plugin->foaf_name);
}
lv2_plugin->foaf_name = g_strdup(foaf_name);
g_rec_mutex_unlock(base_plugin_mutex);
}
break;
case PROP_FOAF_HOMEPAGE:
{
gchar *foaf_homepage;
foaf_homepage = (gchar *) g_value_get_string(value);
g_rec_mutex_lock(base_plugin_mutex);
if(lv2_plugin->foaf_homepage == foaf_homepage){
g_rec_mutex_unlock(base_plugin_mutex);
return;
}
if(lv2_plugin->foaf_homepage != NULL){
g_free(lv2_plugin->foaf_homepage);
}
lv2_plugin->foaf_homepage = g_strdup(foaf_homepage);
g_rec_mutex_unlock(base_plugin_mutex);
}
break;
case PROP_FOAF_MBOX:
{
gchar *foaf_mbox;
foaf_mbox = (gchar *) g_value_get_string(value);
g_rec_mutex_lock(base_plugin_mutex);
if(lv2_plugin->foaf_mbox == foaf_mbox){
g_rec_mutex_unlock(base_plugin_mutex);
return;
}
if(lv2_plugin->foaf_mbox != NULL){
g_free(lv2_plugin->foaf_mbox);
}
lv2_plugin->foaf_mbox = g_strdup(foaf_mbox);
g_rec_mutex_unlock(base_plugin_mutex);
}
break;
case PROP_PRESET:
{
AgsLv2Preset *lv2_preset;
lv2_preset = g_value_get_pointer(value);
g_rec_mutex_lock(base_plugin_mutex);
if(lv2_preset == NULL ||
g_list_find(lv2_plugin->preset, lv2_preset) != NULL){
g_rec_mutex_unlock(base_plugin_mutex);
return;
}
lv2_plugin->preset = g_list_append(lv2_plugin->preset,
lv2_preset);
g_object_ref(lv2_preset);
g_rec_mutex_unlock(base_plugin_mutex);
}
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(gobject, prop_id, param_spec);
break;
}
}
void
ags_lv2_plugin_get_property(GObject *gobject,
guint prop_id,
GValue *value,
GParamSpec *param_spec)
{
AgsLv2Plugin *lv2_plugin;
GRecMutex *base_plugin_mutex;
lv2_plugin = AGS_LV2_PLUGIN(gobject);
/* get base plugin mutex */
base_plugin_mutex = AGS_BASE_PLUGIN_GET_OBJ_MUTEX(lv2_plugin);
switch(prop_id){
case PROP_PNAME:
{
g_rec_mutex_lock(base_plugin_mutex);
g_value_set_string(value, lv2_plugin->pname);
g_rec_mutex_unlock(base_plugin_mutex);
}
break;
case PROP_URI:
{
g_rec_mutex_lock(base_plugin_mutex);
g_value_set_string(value, lv2_plugin->uri);
g_rec_mutex_unlock(base_plugin_mutex);
}
break;
case PROP_UI_URI:
{
g_rec_mutex_lock(base_plugin_mutex);
g_value_set_string(value, lv2_plugin->ui_uri);
g_rec_mutex_unlock(base_plugin_mutex);
}
break;
case PROP_MANIFEST:
{
g_rec_mutex_lock(base_plugin_mutex);
g_value_set_object(value, lv2_plugin->manifest);
g_rec_mutex_unlock(base_plugin_mutex);
}
break;
case PROP_TURTLE:
{
g_rec_mutex_lock(base_plugin_mutex);
g_value_set_object(value, lv2_plugin->turtle);
g_rec_mutex_unlock(base_plugin_mutex);
}
break;
case PROP_DOAP_NAME:
{
g_rec_mutex_lock(base_plugin_mutex);
g_value_set_string(value, lv2_plugin->doap_name);
g_rec_mutex_unlock(base_plugin_mutex);
}
break;
case PROP_FOAF_NAME:
{
g_rec_mutex_lock(base_plugin_mutex);
g_value_set_string(value, lv2_plugin->foaf_name);
g_rec_mutex_unlock(base_plugin_mutex);
}
break;
case PROP_FOAF_HOMEPAGE:
{
g_rec_mutex_lock(base_plugin_mutex);
g_value_set_string(value, lv2_plugin->foaf_homepage);
g_rec_mutex_unlock(base_plugin_mutex);
}
break;
case PROP_FOAF_MBOX:
{
g_rec_mutex_lock(base_plugin_mutex);
g_value_set_string(value, lv2_plugin->foaf_mbox);
g_rec_mutex_unlock(base_plugin_mutex);
}
break;
case PROP_PRESET:
{
g_rec_mutex_lock(base_plugin_mutex);
g_value_set_pointer(value, g_list_copy_deep(lv2_plugin->preset,
(GCopyFunc) g_object_ref,
NULL));
g_rec_mutex_unlock(base_plugin_mutex);
}
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(gobject, prop_id, param_spec);
break;
}
}
void
ags_lv2_plugin_dispose(GObject *gobject)
{
AgsLv2Plugin *lv2_plugin;
lv2_plugin = AGS_LV2_PLUGIN(gobject);
if(lv2_plugin->manifest != NULL){
g_object_unref(lv2_plugin->manifest);
lv2_plugin->manifest = NULL;
}
if(lv2_plugin->turtle != NULL){
g_object_unref(lv2_plugin->turtle);
lv2_plugin->turtle = NULL;
}
if(lv2_plugin->preset != NULL){
g_list_free_full(lv2_plugin->preset,
g_object_unref);
lv2_plugin->preset = NULL;
}
/* call parent */
G_OBJECT_CLASS(ags_lv2_plugin_parent_class)->dispose(gobject);
}
void
ags_lv2_plugin_finalize(GObject *gobject)
{
AgsLv2Plugin *lv2_plugin;
lv2_plugin = AGS_LV2_PLUGIN(gobject);
g_free(lv2_plugin->uri);
g_free(lv2_plugin->ui_uri);
if(lv2_plugin->manifest != NULL){
g_object_unref(lv2_plugin->manifest);
}
if(lv2_plugin->turtle != NULL){
g_object_unref(lv2_plugin->turtle);
}
if(lv2_plugin->feature != NULL){
guint i;
for(i = 0; lv2_plugin->feature[i] != NULL; i++){
g_free(lv2_plugin->feature[i]->data);
g_free(lv2_plugin->feature[i]);
}
g_free(lv2_plugin->feature);
}
if(lv2_plugin->preset != NULL){
g_list_free_full(lv2_plugin->preset,
g_object_unref);
}
/* call parent */
G_OBJECT_CLASS(ags_lv2_plugin_parent_class)->finalize(gobject);
}
gpointer
ags_lv2_plugin_instantiate(AgsBasePlugin *base_plugin,
guint samplerate, guint buffer_size)
{
AgsLv2Plugin *lv2_plugin;
AgsConfig *config;
void *plugin_so;
LV2_Descriptor_Function lv2_descriptor;
LV2_Descriptor *plugin_descriptor;
LV2_Handle *lv2_handle;
LV2_URI_Map_Feature *uri_map_feature;
LV2_Worker_Schedule_Handle worker_handle;
LV2_Worker_Schedule *worker_schedule;
LV2_Log_Log *log_feature;
LV2_Event_Feature *event_feature;
LV2_URID_Map *urid_map;
LV2_URID_Unmap *urid_unmap;
LV2_Options_Interface *options_interface;
LV2_Options_Option *options;
LV2_Programs_Interface *program_interface;
LV2_Feature **feature;
gchar *filename;
char *path;
gchar *str;
float *ptr_samplerate;
float *ptr_buffer_size;
uint32_t effect_index;
guint conf_buffer_size;
guint conf_samplerate;
double rate;
guint total_feature;
guint options_feature_position;
guint nth;
guint i;
gboolean initial_call;
LV2_Handle (*instantiate)(const LV2_Descriptor *descriptor,
double sample_rate,
const char *bundle_path,
const LV2_Feature *const *features);
GRecMutex *base_plugin_mutex;
lv2_plugin = AGS_LV2_PLUGIN(base_plugin);
/* get base plugin mutex */
base_plugin_mutex = AGS_BASE_PLUGIN_GET_OBJ_MUTEX(base_plugin);
// xmlSaveFormatFileEnc("-", lv2_plugin->turtle->doc, "UTF-8", 1);
/* get some fields */
g_rec_mutex_lock(base_plugin_mutex);
plugin_so = base_plugin->plugin_so;
if(plugin_so == NULL){
gboolean success;
g_message("open %s", base_plugin->filename);
#ifdef AGS_W32API
plugin_so = LoadLibrary(base_plugin->filename);
#else
plugin_so = dlopen(base_plugin->filename,
RTLD_NOW|RTLD_GLOBAL);
#endif
g_object_set(lv2_plugin,
"plugin-so", plugin_so,
NULL);
success = FALSE;
#ifdef AGS_W32API
base_plugin->plugin_handle =
lv2_descriptor = (LV2_Descriptor_Function) GetProcAddress(plugin_so,
"lv2_descriptor");
success = (!lv2_descriptor) ? FALSE: TRUE;
#else
base_plugin->plugin_handle =
lv2_descriptor = (LV2_Descriptor_Function) dlsym(plugin_so,
"lv2_descriptor");
success = (dlerror() == NULL) ? TRUE: FALSE;
#endif
if(success && lv2_descriptor){
for(i = 0; (plugin_descriptor = lv2_descriptor((unsigned long) i)) != NULL; i++){
if(!g_ascii_strcasecmp(plugin_descriptor->URI,
lv2_plugin->uri)){
base_plugin->plugin_descriptor = plugin_descriptor;
effect_index = i;
g_object_set(lv2_plugin,
"effect-index", effect_index,
NULL);
break;
}
}
}
}
lv2_descriptor = base_plugin->plugin_handle;
plugin_descriptor = base_plugin->plugin_descriptor;
feature = lv2_plugin->feature;
path = g_path_get_dirname(base_plugin->filename);
effect_index = base_plugin->effect_index;
g_rec_mutex_unlock(base_plugin_mutex);
if(plugin_so == NULL){
g_free(path);
return(NULL);
}
/* get some config values */
initial_call = FALSE;
config = ags_config_get_instance();
conf_samplerate = ags_soundcard_helper_config_get_samplerate(config);
conf_buffer_size = ags_soundcard_helper_config_get_buffer_size(config);
worker_handle = NULL;
options_feature_position = 0;
if(feature == NULL){
initial_call = TRUE;
/**/
total_feature = 8;
nth = 0;
feature =
lv2_plugin->feature = (LV2_Feature **) g_malloc(total_feature * sizeof(LV2_Feature *));
/* URI map feature */
uri_map_feature = (LV2_URI_Map_Feature *) g_malloc(sizeof(LV2_URI_Map_Feature));
uri_map_feature->callback_data = NULL;
uri_map_feature->uri_to_id = (uint32_t (*)(LV2_URI_Map_Callback_Data, const char *, const char *)) ags_lv2_uri_map_manager_uri_to_id;
feature[nth] = (LV2_Feature *) g_malloc(sizeof(LV2_Feature));
feature[nth]->URI = LV2_URI_MAP_URI;
feature[nth]->data = uri_map_feature;
nth++;
/* worker feature */
if(ags_lv2_plugin_test_flags(lv2_plugin, AGS_LV2_PLUGIN_NEEDS_WORKER)){
worker_handle = ags_lv2_worker_manager_pull_worker(ags_lv2_worker_manager_get_instance());
worker_schedule = (LV2_Worker_Schedule *) g_malloc(sizeof(LV2_Worker_Schedule));
worker_schedule->handle = worker_handle;
worker_schedule->schedule_work = ags_lv2_worker_schedule_work;
feature[nth] = (LV2_Feature *) g_malloc(sizeof(LV2_Feature));
feature[nth]->URI = LV2_WORKER__schedule;
feature[nth]->data = worker_schedule;
nth++;
}
/* log feature */
#if 0
{
log_feature = (LV2_Log_Log *) g_malloc(sizeof(LV2_Log_Log));
log_feature->handle = NULL;
log_feature->printf = ags_lv2_log_manager_printf;
log_feature->vprintf = ags_lv2_log_manager_vprintf;
feature[nth] = (LV2_Feature *) g_malloc(sizeof(LV2_Feature));
feature[nth]->URI = LV2_LOG__log;
feature[nth]->data = log_feature;
nth++;
}
#endif
/* event feature */
event_feature = (LV2_Event_Feature *) g_malloc(sizeof(LV2_Event_Feature));
event_feature->callback_data = NULL;
event_feature->lv2_event_ref = ags_lv2_event_manager_lv2_event_ref;
event_feature->lv2_event_unref = ags_lv2_event_manager_lv2_event_unref;
feature[nth] = (LV2_Feature *) g_malloc(sizeof(LV2_Feature));
feature[nth]->URI = LV2_EVENT_URI;
feature[nth]->data = event_feature;
nth++;
/* URID map feature */
urid_map = (LV2_URID_Map *) g_malloc(sizeof(LV2_URID_Map));
urid_map->handle = NULL;
urid_map->map = (LV2_URID (*)(LV2_URID_Map_Handle, const char *)) ags_lv2_urid_manager_map;
feature[nth] = (LV2_Feature *) g_malloc(sizeof(LV2_Feature));
feature[nth]->URI = LV2_URID_MAP_URI;
feature[nth]->data = urid_map;
nth++;
/* URID unmap feature */
urid_unmap = (LV2_URID_Unmap *) g_malloc(sizeof(LV2_URID_Unmap));
urid_unmap->handle = NULL;
urid_unmap->unmap = ags_lv2_urid_manager_unmap;
feature[nth] = (LV2_Feature *) g_malloc(sizeof(LV2_Feature));
feature[nth]->URI = LV2_URID_UNMAP_URI;
feature[nth]->data = urid_unmap;
nth++;
/* Options interface */
options_interface = (LV2_Options_Interface *) g_malloc(sizeof(LV2_Options_Interface));
options_interface->set = (uint32_t (*)(LV2_Handle, const LV2_Options_Option *)) ags_lv2_option_manager_lv2_options_set;
options_interface->get = ags_lv2_option_manager_lv2_options_get;
feature[nth] = (LV2_Feature *) g_malloc(sizeof(LV2_Feature));
feature[nth]->URI = LV2_OPTIONS__interface;
feature[nth]->data = options_interface;
nth++;
/* Options options */
options_feature_position = nth;
feature[nth] = (LV2_Feature *) g_malloc(sizeof(LV2_Feature));
feature[nth]->URI = LV2_OPTIONS__options;
feature[nth]->data = NULL;
nth++;
/* terminate */
for(; nth < total_feature; nth++){
feature[nth] = NULL;
}
g_rec_mutex_lock(base_plugin_mutex);
lv2_plugin->feature = feature;
g_rec_mutex_unlock(base_plugin_mutex);
}
instantiate = NULL;
if(plugin_so != NULL){
gboolean success;
success = FALSE;
#ifdef AGS_W32API
lv2_descriptor = (LV2_Descriptor_Function) GetProcAddress(plugin_so,
"lv2_descriptor");
success = (!lv2_descriptor) ? FALSE: TRUE;
#else
lv2_descriptor = (LV2_Descriptor_Function) dlsym(plugin_so,
"lv2_descriptor");
success = (dlerror() == NULL) ? TRUE: FALSE;
#endif
if(success && lv2_descriptor){
g_rec_mutex_lock(base_plugin_mutex);
base_plugin->plugin_descriptor =
plugin_descriptor = lv2_descriptor(effect_index);
instantiate = (LV2_Handle (*)(const LV2_Descriptor *, double, const char *, const LV2_Feature *const *)) plugin_descriptor->instantiate;
g_rec_mutex_unlock(base_plugin_mutex);
}
}
lv2_handle = NULL;
options = NULL;
/* instantiate */
rate = (double) samplerate;
if(initial_call){
/* some options */
options = (LV2_Options_Option *) g_malloc(7 * sizeof(LV2_Options_Option));
/* samplerate */
options[0].context = LV2_OPTIONS_INSTANCE;
options[0].subject = 0;
//FIXME:JK: bad cast
options[0].key = (uint32_t) ags_lv2_urid_manager_map(ags_lv2_urid_manager_get_instance(),
LV2_PARAMETERS__sampleRate);
ptr_samplerate = (float *) g_malloc(sizeof(float));
ptr_samplerate[0] = conf_samplerate;
options[0].size = sizeof(float);
//FIXME:JK: bad cast
options[0].type = (uint32_t) ags_lv2_urid_manager_map(ags_lv2_urid_manager_get_instance(),
LV2_ATOM__Float);
options[0].value = ptr_samplerate;
/* min-block-length */
options[1].context = LV2_OPTIONS_INSTANCE;
options[1].subject = 0;
//FIXME:JK: bad cast
options[1].key = (uint32_t) ags_lv2_urid_manager_map(ags_lv2_urid_manager_get_instance(),
LV2_BUF_SIZE__minBlockLength);
ptr_buffer_size = (float *) g_malloc(sizeof(float));
ptr_buffer_size[0] = conf_buffer_size;
options[1].size = sizeof(float);
//FIXME:JK: bad cast
options[1].type = (uint32_t) ags_lv2_urid_manager_map(ags_lv2_urid_manager_get_instance(),
LV2_ATOM__Int);
options[1].value = ptr_buffer_size;
/* max-block-length */
options[2].context = LV2_OPTIONS_INSTANCE;
options[2].subject = 0;
//FIXME:JK: bad cast
options[2].key = (uint32_t) ags_lv2_urid_manager_map(ags_lv2_urid_manager_get_instance(),
LV2_BUF_SIZE__maxBlockLength);
ptr_buffer_size = (float *) g_malloc(sizeof(float));
ptr_buffer_size[0] = conf_buffer_size;
options[2].size = sizeof(float);
//FIXME:JK: bad cast
options[2].type = (uint32_t) ags_lv2_urid_manager_map(ags_lv2_urid_manager_get_instance(),
LV2_ATOM__Int);
options[2].value = ptr_buffer_size;
/* bounded-block-length */
options[3].context = LV2_OPTIONS_INSTANCE;
options[3].subject = 0;
//FIXME:JK: bad cast
options[3].key = (uint32_t) ags_lv2_urid_manager_map(ags_lv2_urid_manager_get_instance(),
LV2_BUF_SIZE__boundedBlockLength);
ptr_buffer_size = (float *) g_malloc(sizeof(float));
ptr_buffer_size[0] = conf_buffer_size;
options[3].size = sizeof(float);
//FIXME:JK: bad cast
options[3].type = (uint32_t) ags_lv2_urid_manager_map(ags_lv2_urid_manager_get_instance(),
LV2_ATOM__Int);
options[3].value = ptr_buffer_size;
/* fixed-block-length */
options[4].context = LV2_OPTIONS_INSTANCE;
options[4].subject = 0;
//FIXME:JK: bad cast
options[4].key = (uint32_t) ags_lv2_urid_manager_map(ags_lv2_urid_manager_get_instance(),
LV2_BUF_SIZE__fixedBlockLength);
ptr_buffer_size = (float *) g_malloc(sizeof(float));
ptr_buffer_size[0] = conf_buffer_size;
options[4].size = sizeof(float);
//FIXME:JK: bad cast
options[4].type = (uint32_t) ags_lv2_urid_manager_map(ags_lv2_urid_manager_get_instance(),
LV2_ATOM__Int);
options[4].value = ptr_buffer_size;
/* instance */
options[5].context = LV2_OPTIONS_INSTANCE;
options[5].subject = 0;
options[5].key = 0;
options[5].size = 0;
options[5].type = 0;
options[5].value = NULL;
/* zeroed */
options[6].context = 0;
options[6].subject = 0;
options[6].key = 0;
options[6].size = 0;
options[6].type = 0;
options[6].value = NULL;
feature[options_feature_position]->data = options;
}
if(instantiate != NULL){
/* alloc handle */
lv2_handle = (LV2_Handle *) g_malloc(sizeof(LV2_Handle));
lv2_handle[0] = instantiate(plugin_descriptor,
rate,
path,
(const LV2_Feature * const *) feature);
/* set options */
if(lv2_handle[0] != NULL &&
options != NULL){
ags_lv2_option_manager_lv2_options_set(lv2_handle[0],
options);
}
}
/* */
if(worker_handle != NULL){
if(plugin_descriptor->extension_data != NULL){
AGS_LV2_WORKER(worker_handle)->worker_interface = plugin_descriptor->extension_data("http://lv2plug.in/ns/ext/worker#interface");
}
g_object_set(worker_handle,
"handle", lv2_handle[0],
NULL);
}
if(plugin_descriptor != NULL &&
plugin_descriptor->extension_data != NULL &&
(program_interface = plugin_descriptor->extension_data(LV2_PROGRAMS__Interface)) != NULL){
ags_lv2_plugin_set_flags(lv2_plugin,
AGS_LV2_PLUGIN_HAS_PROGRAM_INTERFACE);
}
g_free(path);
return(lv2_handle);
}
void
ags_lv2_plugin_connect_port(AgsBasePlugin *base_plugin,
gpointer plugin_handle,
guint port_index,
gpointer data_location)
{
void (*connect_port)(LV2_Handle instance,
uint32_t port,
void *data_location);
GRecMutex *base_plugin_mutex;
/* get base plugin mutex */
base_plugin_mutex = AGS_BASE_PLUGIN_GET_OBJ_MUTEX(base_plugin);
/* get some fields */
g_rec_mutex_lock(base_plugin_mutex);
connect_port = AGS_LV2_PLUGIN_DESCRIPTOR(base_plugin->plugin_descriptor)->connect_port;
g_rec_mutex_unlock(base_plugin_mutex);
/* connect port */
if(plugin_handle != NULL &&
connect_port != NULL){
connect_port((LV2_Handle) plugin_handle,
(uint32_t) port_index,
(float *) data_location);
}
}
void
ags_lv2_plugin_activate(AgsBasePlugin *base_plugin,
gpointer plugin_handle)
{
void (*activate)(LV2_Handle instance);
GRecMutex *base_plugin_mutex;
/* get base plugin mutex */
base_plugin_mutex = AGS_BASE_PLUGIN_GET_OBJ_MUTEX(base_plugin);
/* get some fields */
g_rec_mutex_lock(base_plugin_mutex);
activate = AGS_LV2_PLUGIN_DESCRIPTOR(base_plugin->plugin_descriptor)->activate;
g_rec_mutex_unlock(base_plugin_mutex);
/* activate */
if(plugin_handle != NULL &&
activate != NULL){
activate((LV2_Handle) plugin_handle);
}
}
void
ags_lv2_plugin_deactivate(AgsBasePlugin *base_plugin,
gpointer plugin_handle)
{
void (*deactivate)(LV2_Handle instance);
GRecMutex *base_plugin_mutex;
/* get base plugin mutex */
base_plugin_mutex = AGS_BASE_PLUGIN_GET_OBJ_MUTEX(base_plugin);
/* get some fields */
g_rec_mutex_lock(base_plugin_mutex);
deactivate = AGS_LV2_PLUGIN_DESCRIPTOR(base_plugin->plugin_descriptor)->deactivate;
g_rec_mutex_unlock(base_plugin_mutex);
/* deactivate */
if(plugin_handle != NULL &&
deactivate != NULL){
deactivate((LV2_Handle) plugin_handle);
}
}
void
ags_lv2_plugin_run(AgsBasePlugin *base_plugin,
gpointer plugin_handle,
snd_seq_event_t *seq_event,
guint frame_count)
{
void (*run)(LV2_Handle instance,
uint32_t sample_count);
GRecMutex *base_plugin_mutex;
/* get base plugin mutex */
base_plugin_mutex = AGS_BASE_PLUGIN_GET_OBJ_MUTEX(base_plugin);
/* get some fields */
g_rec_mutex_lock(base_plugin_mutex);
run = AGS_LV2_PLUGIN_DESCRIPTOR(base_plugin->plugin_descriptor)->run;
g_rec_mutex_unlock(base_plugin_mutex);
/* run */
if(plugin_handle != NULL &&
run != NULL){
run((LV2_Handle) plugin_handle,
(uint32_t) frame_count);
}
}
void
ags_lv2_plugin_load_plugin(AgsBasePlugin *base_plugin)
{
//NOTE:JK: deprecated
}
/**
* ags_lv2_plugin_test_flags:
* @lv2_plugin: the #AgsLv2Plugin
* @flags: the flags
*
* Test @flags to be set on @recall.
*
* Returns: %TRUE if flags are set, else %FALSE
*
* Since: 3.0.0
*/
gboolean
ags_lv2_plugin_test_flags(AgsLv2Plugin *lv2_plugin, AgsLv2PluginFlags flags)
{
gboolean retval;
GRecMutex *base_plugin_mutex;
if(!AGS_IS_LV2_PLUGIN(lv2_plugin)){
return(FALSE);
}
/* get base plugin mutex */
base_plugin_mutex = AGS_BASE_PLUGIN_GET_OBJ_MUTEX(lv2_plugin);
/* test flags */
g_rec_mutex_lock(base_plugin_mutex);
retval = ((flags & (lv2_plugin->flags)) != 0) ? TRUE: FALSE;
g_rec_mutex_unlock(base_plugin_mutex);
return(retval);
}
/**
* ags_lv2_plugin_set_flags:
* @lv2_plugin: the #AgsLv2Plugin
* @flags: the flags
*
* Set flags.
*
* Since: 3.0.0
*/
void
ags_lv2_plugin_set_flags(AgsLv2Plugin *lv2_plugin, AgsLv2PluginFlags flags)
{
GRecMutex *base_plugin_mutex;
if(!AGS_IS_LV2_PLUGIN(lv2_plugin)){
return;
}
/* get base plugin mutex */
base_plugin_mutex = AGS_BASE_PLUGIN_GET_OBJ_MUTEX(lv2_plugin);
/* set flags */
g_rec_mutex_lock(base_plugin_mutex);
lv2_plugin->flags |= flags;
g_rec_mutex_unlock(base_plugin_mutex);
}
/**
* ags_lv2_plugin_unset_flags:
* @lv2_plugin: the #AgsLv2Plugin
* @flags: the flags
*
* Unset flags.
*
* Since: 3.0.0
*/
void
ags_lv2_plugin_unset_flags(AgsLv2Plugin *lv2_plugin, AgsLv2PluginFlags flags)
{
GRecMutex *base_plugin_mutex;
if(!AGS_IS_LV2_PLUGIN(lv2_plugin)){
return;
}
/* get base plugin mutex */
base_plugin_mutex = AGS_BASE_PLUGIN_GET_OBJ_MUTEX(lv2_plugin);
/* unset flags */
g_rec_mutex_lock(base_plugin_mutex);
lv2_plugin->flags &= (~flags);
g_rec_mutex_unlock(base_plugin_mutex);
}
/**
* ags_lv2_plugin_event_buffer_alloc:
* @buffer_size: the data's buffer size
*
* Allocate LV2_Event_Buffer struct.
*
* Returns: (type gpointer) (transfer none): a new allocated LV2_Event_Buffer
*
* Since: 3.0.0
*/
LV2_Event_Buffer*
ags_lv2_plugin_event_buffer_alloc(guint buffer_size)
{
LV2_Event_Buffer *event_buffer;
void *data;
uint32_t padded_buffer_size;
if(buffer_size > G_MAXUINT16){
return(NULL);
}
if(buffer_size < 8){
padded_buffer_size = 8;
}else{
padded_buffer_size = buffer_size;
}
event_buffer = (LV2_Event_Buffer *) g_malloc(sizeof(LV2_Event_Buffer));
data = (void *) g_malloc(sizeof(LV2_Event) + padded_buffer_size * sizeof(uint8_t));
memset(data, 0, sizeof(LV2_Event) + padded_buffer_size * sizeof(uint8_t));
event_buffer->data = data;
event_buffer->header_size = sizeof(LV2_Event_Buffer);
event_buffer->stamp_type = 0;
event_buffer->capacity = padded_buffer_size;
event_buffer->event_count = 0;
event_buffer->size = 0;
return(event_buffer);
}
/**
* ags_lv2_plugin_event_buffer_free:
* @event_buffer: (type gpointer) (transfer none): the LV2_Event_Buffer struct
*
* Free LV2_Event_Buffer struct.
*
* Since: 3.3.0
*/
void
ags_lv2_plugin_event_buffer_free(gpointer event_buffer)
{
if(event_buffer == NULL){
return;
}
g_free(event_buffer);
}
/**
* ags_lv2_plugin_event_buffer_realloc_data:
* @event_buffer: (type gpointer) (transfer none): the LV2_Event_Buffer struct
* @buffer_size: the data's buffer size
*
* Reallocate LV2_Event_Buffer struct's data field.
*
* Since: 3.0.0
*/
void
ags_lv2_plugin_event_buffer_realloc_data(LV2_Event_Buffer *event_buffer,
guint buffer_size)
{
void *data;
uint32_t padded_buffer_size;
if(buffer_size > G_MAXUINT16){
return;
}
if(buffer_size < 8){
padded_buffer_size = 8;
}else{
padded_buffer_size = buffer_size;
}
data = event_buffer->data;
data = (void *) g_realloc(data,
sizeof(LV2_Event) + padded_buffer_size * sizeof(uint8_t));
event_buffer->data = data;
}
/**
* ags_lv2_plugin_event_buffer_concat:
* @event_buffer: (type gpointer) (transfer none): the first buffer
* @...: %NULL terminated variadict arguments
*
* Concats the event buffers.
*
* Returns: (type gpointer) (transfer none): The newly allocated event buffer
*
* Since: 3.0.0
*/
LV2_Event_Buffer*
ags_lv2_plugin_event_buffer_concat(LV2_Event_Buffer *event_buffer, ...)
{
LV2_Event_Buffer *buffer;
LV2_Event_Buffer *current;
void *offset;
va_list ap;
guint i;
buffer = (LV2_Event_Buffer *) g_malloc(sizeof(LV2_Event_Buffer));
memcpy(buffer, event_buffer, sizeof(LV2_Event_Buffer));
va_start(ap, event_buffer);
i = 1;
while(TRUE){
current = va_arg(ap, LV2_Event_Buffer *);
if(current == NULL){
break;
}
buffer = (LV2_Event_Buffer *) g_realloc(buffer,
(i + 1) * sizeof(LV2_Event_Buffer));
offset = buffer;
offset += (i * sizeof(LV2_Event_Buffer));
memcpy(offset, current, sizeof(LV2_Event_Buffer));
i++;
}
va_end(ap);
return(buffer);
}
/**
* ags_lv2_plugin_event_buffer_append_midi:
* @event_buffer: the event buffer
* @buffer_size: the event buffer size
* @events: (type gpointer) (transfer none): the events to write
* @event_count: the number of events to write
*
* Append MIDI data to event buffer.
*
* Returns: %TRUE on success otherwise %FALSE
*
* Since: 3.0.0
*/
gboolean
ags_lv2_plugin_event_buffer_append_midi(gpointer event_buffer,
guint buffer_size,
snd_seq_event_t *events,
guint event_count)
{
AgsMidiSmfUtil midi_smf_util;
void *offset;
unsigned char midi_buffer[8];
guint padded_buffer_size;
guint count;
guint i;
gboolean success;
if(event_buffer == NULL){
return(FALSE);
}
midi_smf_util.major = 1;
midi_smf_util.minor = 0;
/* find offset */
offset = AGS_LV2_EVENT_BUFFER(event_buffer)->data;
offset += AGS_LV2_EVENT_BUFFER(event_buffer)->size;
/* append midi */
success = TRUE;
for(i = 0; i < event_count; i++){
if(offset >= (void *) AGS_LV2_EVENT_BUFFER(event_buffer)->data + buffer_size){
return(FALSE);
}
/* decode midi sequencer event */
count = ags_midi_smf_util_decode(&midi_smf_util,
midi_buffer,
&(events[i]));
if(count < 8){
padded_buffer_size = 8;
}else{
padded_buffer_size = count;
}
if(AGS_LV2_EVENT_BUFFER(event_buffer)->size + padded_buffer_size >= buffer_size){
return(FALSE);
}
AGS_LV2_EVENT_BUFFER(event_buffer)->size += (padded_buffer_size + sizeof(LV2_Event));
AGS_LV2_EVENT_BUFFER(event_buffer)->event_count += 1;
AGS_LV2_EVENT(offset)->frames = 0;
AGS_LV2_EVENT(offset)->subframes = 0;
AGS_LV2_EVENT(offset)->type = ags_lv2_uri_map_manager_uri_to_id(NULL,
LV2_EVENT_URI,
LV2_MIDI__MidiEvent);
AGS_LV2_EVENT(offset)->size = count;
memcpy(offset + sizeof(LV2_Event), midi_buffer, count * sizeof(unsigned char));
offset += (padded_buffer_size + sizeof(LV2_Event));
}
return(success);
}
/**
* ags_lv2_plugin_event_buffer_remove_midi:
* @event_buffer: the event buffer
* @buffer_size: the event buffer size
* @note: the key to remove
*
* Remove MIDI data from event buffer.
*
* Returns: %TRUE on success otherwise %FALSE
*
* Since: 3.0.0
*/
gboolean
ags_lv2_plugin_event_buffer_remove_midi(gpointer event_buffer,
guint buffer_size,
guint note)
{
void *offset;
guint padded_buffer_size;
guint count;
guint i;
gboolean success;
if(event_buffer == NULL){
return(FALSE);
}
/* find offset */
offset = AGS_LV2_EVENT_BUFFER(event_buffer)->data;
/* append midi */
success = FALSE;
while(offset < offset + AGS_LV2_EVENT_BUFFER(event_buffer)->size){
if(((unsigned char *) (offset + sizeof(LV2_Event)))[1] == (0x7f & note)){
success = TRUE;
break;
}
count = AGS_LV2_EVENT(offset)->size;
if(count < 8){
padded_buffer_size = 8;
}else{
padded_buffer_size = count;
}
offset += (padded_buffer_size + sizeof(LV2_Event));
}
if(success){
count = AGS_LV2_EVENT(offset)->size;
if(count < 8){
padded_buffer_size = 8;
}else{
padded_buffer_size = count;
}
memmove(offset,
offset + (padded_buffer_size + sizeof(LV2_Event)),
((void *) AGS_LV2_EVENT_BUFFER(event_buffer)->data + buffer_size) - (offset + padded_buffer_size + sizeof(LV2_Event)));
memset(AGS_LV2_EVENT_BUFFER(event_buffer)->data + buffer_size - (padded_buffer_size + sizeof(LV2_Event)),
0,
(padded_buffer_size + sizeof(LV2_Event)));
AGS_LV2_EVENT_BUFFER(event_buffer)->size -= (padded_buffer_size + sizeof(LV2_Event));
AGS_LV2_EVENT_BUFFER(event_buffer)->event_count -= 1;
}
return(success);
}
/**
* ags_lv2_plugin_clear_event_buffer:
* @event_buffer: the event buffer
* @buffer_size: size of @event_buffer
*
* Clear the event buffer.
*
* Since: 3.0.0
*/
void
ags_lv2_plugin_clear_event_buffer(gpointer event_buffer,
guint buffer_size)
{
void *offset;
guint padded_buffer_size;
if(event_buffer == NULL){
return;
}
offset = AGS_LV2_EVENT_BUFFER(event_buffer)->data;
if(buffer_size < 8){
padded_buffer_size = 8;
}else{
padded_buffer_size = buffer_size;
}
memset(offset, 0, padded_buffer_size);
}
/**
* ags_lv2_plugin_alloc_atom_sequence:
* @sequence_size: the requested size
*
* Allocates a LV2_Atom_Sequence
*
* Returns: the new atom sequence
*
* Since: 3.0.0
*/
gpointer
ags_lv2_plugin_alloc_atom_sequence(guint sequence_size)
{
LV2_Atom_Sequence *aseq;
LV2_Atom_Event *aev;
guint atom_sequence_size;
atom_sequence_size = sizeof(LV2_Atom_Sequence);
aseq = (LV2_Atom_Sequence *) g_malloc(sizeof(LV2_Atom_Sequence) + sequence_size);
memset(aseq, 0, (atom_sequence_size + sequence_size) * sizeof(uint8_t));
aseq->atom.size = sizeof(LV2_Atom_Sequence_Body);
aseq->atom.type = ags_lv2_urid_manager_map(NULL,
LV2_ATOM__Sequence);
aseq->body.unit = ags_lv2_urid_manager_map(NULL,
LV2_MIDI__MidiEvent);
aseq->body.pad = 0;
aev = lv2_atom_sequence_begin(&(aseq->body));
aev->time.frames = 0;
aev->body.size = 0;
aev->body.type = 0;
return(aseq);
}
/**
* ags_lv2_plugin_atom_sequence_free:
* @atom_sequence: the atom sequence
*
* Free atom sequence.
*
* Since: 3.3.0
*/
void
ags_lv2_plugin_atom_sequence_free(gpointer atom_sequence)
{
if(atom_sequence == NULL){
return;
}
g_free(atom_sequence);
}
/**
* ags_lv2_plugin_atom_sequence_append_midi:
* @atom_sequence: the atom sequence
* @sequence_size: the atom sequence size
* @events: (type gpointer) (transfer none): the events to write
* @event_count: the number of events to write
*
* Append MIDI data to atom sequence.
*
* Returns: %TRUE on success otherwise %FALSE
*
* Since: 3.0.0
*/
gboolean
ags_lv2_plugin_atom_sequence_append_midi(gpointer atom_sequence,
guint sequence_size,
snd_seq_event_t *events,
guint event_count)
{
AgsLv2UriMapManager *uri_map_manager;
LV2_Atom_Sequence *aseq;
LV2_Atom_Event *start_aev, *aev;
AgsMidiSmfUtil midi_smf_util;
guchar midi_buffer[8];
guint count, size;
guint padded_size;
guint i;
gboolean success;
if(atom_sequence == NULL){
return(FALSE);
}
midi_smf_util.major = 1;
midi_smf_util.minor = 0;
aseq = (LV2_Atom_Sequence *) atom_sequence;
/* find last */
aev =
start_aev = lv2_atom_sequence_begin(&(aseq->body));
aev = lv2_atom_sequence_end(&(aseq->body), (uint32_t) aseq->atom.size);
/* append midi */
success = FALSE;
for(i = 0; i < event_count; i++){
if((uint8_t *) aev + (sizeof(LV2_Atom_Event) + 8) >= (((uint8_t *) aseq) + sizeof(LV2_Atom_Sequence)) + sequence_size){
success = FALSE;
break;
}
/* decode midi sequencer event */
if((count = ags_midi_smf_util_decode(&midi_smf_util,
midi_buffer,
&(events[i]))) <= 8){
// g_message("add MIDI[%d] 0x%x 0x%x 0x%x 0x%x", count, midi_buffer[0], midi_buffer[1], midi_buffer[2], midi_buffer[3]);
aev->time.frames = 0;
aev->body.size = count;
aev->body.type = ags_lv2_urid_manager_map(NULL,
LV2_MIDI__MidiEvent);
memcpy((uint8_t *) LV2_ATOM_BODY(&(aev->body)), midi_buffer, count * sizeof(uint8_t));
if(count < lv2_atom_pad_size(count)){
memset((uint8_t *) LV2_ATOM_BODY(&(aev->body)) + count, 0, lv2_atom_pad_size(count) - count);
}
aseq->atom.size += (sizeof(LV2_Atom_Event) + lv2_atom_pad_size(count));
/* iterate */
aev = lv2_atom_sequence_next(aev);
if(i + 1 >= event_count){
success = TRUE;
}
}else{
success = FALSE;
break;
}
}
/* set last empty */
// g_message("aseq = %d ; aev = %d; sequence_size = %d", aseq, aev, sequence_size);
if(success &&
(uint8_t *) aev < (((uint8_t *) aseq) + sizeof(LV2_Atom_Sequence)) + sequence_size){
aev->body.size = 0;
aev->body.type = 0;
}
return(success);
}
/**
* ags_lv2_plugin_atom_sequence_remove_midi:
* @atom_sequence: the atom sequence
* @sequence_size: the atom sequence size
* @note: the key to remove
*
* Remove MIDI data from atom sequence.
*
* Returns: %TRUE on success otherwise %FALSE
*
* Since: 3.0.0
*/
gboolean
ags_lv2_plugin_atom_sequence_remove_midi(gpointer atom_sequence,
guint sequence_size,
guint note)
{
AgsLv2UriMapManager *uri_map_manager;
LV2_Atom_Sequence *aseq;
LV2_Atom_Event *start_aev, *end_aev, *aev, *current_aev;
unsigned char midi_buffer[8];
guint count, size, current_size;
guint padded_size;
guint i;
gboolean success;
if(atom_sequence == NULL){
return(FALSE);
}
aseq = (LV2_Atom_Sequence *) atom_sequence;
/* find offset and last */
aev =
start_aev = lv2_atom_sequence_begin(&(aseq->body));
end_aev = lv2_atom_sequence_end(&(aseq->body), (uint32_t) aseq->atom.size);
success = FALSE;
while((uint8_t *) aev < (uint8_t *) &(aseq->body) + aseq->atom.size &&
!lv2_atom_sequence_is_end(&(aseq->body),
(uint32_t) aseq->atom.size,
aev)){
if(!success &&
(0x7f & ((guchar *) LV2_ATOM_BODY(&(aev->body)))[1]) == (0x7f & note)){
current_aev = aev;
current_size = aev->body.size;
success = TRUE;
break;
}
/* iterate */
aev = lv2_atom_sequence_next(aev);
}
/* remove midi */
if(success){
/* set empty */
current_aev->body.size = 0;
current_aev->body.type = 0;
if(((uint8_t *) end_aev - (uint8_t *) current_aev) - (sizeof(LV2_Atom_Event) + lv2_atom_pad_size(current_size)) >= 0 &&
((uint8_t *) end_aev - (uint8_t *) current_aev) - (sizeof(LV2_Atom_Event) + lv2_atom_pad_size(current_size)) < sequence_size){
#if 0
g_message("current size %d", ((current_size + 7U) & (~7U)));
g_message("current index %d", (uint8_t *) current_aev - (uint8_t *) start_aev);
g_message("sequence size %d", sequence_size);
g_message("count %d", ((uint8_t *) end_aev - (uint8_t *) current_aev) - (sizeof(LV2_Atom_Event) + lv2_atom_pad_size(current_size)));
#endif
memmove(current_aev,
current_aev + (sizeof(LV2_Atom_Event) + lv2_atom_pad_size(current_size)),
((uint8_t *) end_aev - (uint8_t *) current_aev) - (sizeof(LV2_Atom_Event) + lv2_atom_pad_size(current_size)));
}
if(((uint8_t *) end_aev) - (sizeof(LV2_Atom_Event) + lv2_atom_pad_size(current_size)) >= (uint8_t *) start_aev &&
((uint8_t *) end_aev) - (sizeof(LV2_Atom_Event) + lv2_atom_pad_size(current_size)) < start_aev + sequence_size){
memset(end_aev - (sizeof(LV2_Atom_Event) + lv2_atom_pad_size(current_size)),
0,
(sizeof(LV2_Atom_Event) + lv2_atom_pad_size(current_size)));
}
aseq->atom.size -= (sizeof(LV2_Atom_Event) + lv2_atom_pad_size(current_size));
}
return(success);
}
/**
* ags_lv2_plugin_clear_atom_sequence:
* @atom_sequence: the atom sequence
* @sequence_size: size of @atom_sequence
*
* Clear the atom sequence.
*
* Since: 3.0.0
*/
void
ags_lv2_plugin_clear_atom_sequence(gpointer atom_sequence,
guint sequence_size)
{
if(atom_sequence == NULL){
return;
}
memset(atom_sequence, 0, sequence_size);
}
/**
* ags_lv2_plugin_find_uri:
* @lv2_plugin: (element-type AgsAudio.Lv2Plugin) (transfer none): a #GList-struct containig #AgsLv2Plugin
* @uri: the uri to find
*
* Find uri in @lv2_plugin #GList-struct
*
* Returns: (element-type AgsAudio.Lv2Plugin) (transfer none): the matching #GList-struct containing #AgsLv2Plugin
*
* Since: 3.0.0
*/
GList*
ags_lv2_plugin_find_uri(GList *lv2_plugin,
gchar *uri)
{
gboolean success;
GRecMutex *base_plugin_mutex;
if(uri == NULL){
return(NULL);
}
while(lv2_plugin != NULL){
/* get base plugin mutex */
base_plugin_mutex = AGS_BASE_PLUGIN_GET_OBJ_MUTEX(lv2_plugin->data);
/* check uri */
g_rec_mutex_lock(base_plugin_mutex);
success = (AGS_LV2_PLUGIN(lv2_plugin->data)->uri != NULL &&
!g_ascii_strcasecmp(uri,
AGS_LV2_PLUGIN(lv2_plugin->data)->uri)) ? TRUE: FALSE;
g_rec_mutex_unlock(base_plugin_mutex);
if(success){
return(lv2_plugin);
}
lv2_plugin = lv2_plugin->next;
}
return(NULL);
}
/**
* ags_lv2_plugin_find_pname:
* @lv2_plugin: (element-type AgsAudio.Lv2Plugin) (transfer none): a #GList-struct containig #AgsLv2Plugin
* @pname: the pname to find
*
* Find pname in @lv2_plugin #GList-struct
*
* Returns: (element-type AgsAudio.Lv2Plugin) (transfer none): the matching #GList-struct containing #AgsLv2Plugin
*
* Since: 3.0.0
*/
GList*
ags_lv2_plugin_find_pname(GList *lv2_plugin,
gchar *pname)
{
gboolean success;
GRecMutex *base_plugin_mutex;
if(pname == NULL){
return(NULL);
}
while(lv2_plugin != NULL){
/* get base plugin mutex */
base_plugin_mutex = AGS_BASE_PLUGIN_GET_OBJ_MUTEX(lv2_plugin->data);
/* check pname */
g_rec_mutex_lock(base_plugin_mutex);
success = (AGS_LV2_PLUGIN(lv2_plugin->data)->pname != NULL &&
!g_ascii_strcasecmp(pname,
AGS_LV2_PLUGIN(lv2_plugin->data)->pname)) ? TRUE: FALSE;
g_rec_mutex_unlock(base_plugin_mutex);
if(success){
return(lv2_plugin);
}
lv2_plugin = lv2_plugin->next;
}
return(NULL);
}
void
ags_lv2_plugin_real_change_program(AgsLv2Plugin *lv2_plugin,
gpointer lv2_handle,
guint bank_index,
guint program_index)
{
LV2_Descriptor *plugin_descriptor;
LV2_Programs_Interface *program_interface;
plugin_descriptor = AGS_BASE_PLUGIN(lv2_plugin)->plugin_descriptor;
if(plugin_descriptor != NULL &&
plugin_descriptor->extension_data != NULL &&
(program_interface = plugin_descriptor->extension_data(LV2_PROGRAMS__Interface)) != NULL){
program_interface->select_program(((LV2_Handle *) lv2_handle)[0],
(uint32_t) bank_index,
(uint32_t) program_index);
}
}
/**
* ags_lv2_plugin_change_program:
* @lv2_plugin: the #AgsLv2Plugin
* @lv2_handle: the lv2 handle
* @bank_index: the bank index
* @program_index: the program index
*
* Change program of @lv2_handle.
*
* Since: 3.0.0
*/
void
ags_lv2_plugin_change_program(AgsLv2Plugin *lv2_plugin,
gpointer lv2_handle,
guint bank_index,
guint program_index)
{
g_return_if_fail(AGS_IS_LV2_PLUGIN(lv2_plugin));
g_object_ref(G_OBJECT(lv2_plugin));
g_signal_emit(G_OBJECT(lv2_plugin),
lv2_plugin_signals[CHANGE_PROGRAM], 0,
lv2_handle,
bank_index,
program_index);
g_object_unref(G_OBJECT(lv2_plugin));
}
/**
* ags_lv2_plugin_new:
* @turtle: the #AgsTurtle
* @filename: the plugin .so
* @effect: the effect's string representation
* @uri: the effect's uri
* @effect_index: the effect's index
*
* Creates an #AgsLv2Plugin
*
* Returns: a new #AgsLv2Plugin
*
* Since: 3.0.0
*/
AgsLv2Plugin*
ags_lv2_plugin_new(AgsTurtle *turtle, gchar *filename, gchar *effect, gchar *uri, guint effect_index)
{
AgsLv2Plugin *lv2_plugin;
lv2_plugin = (AgsLv2Plugin *) g_object_new(AGS_TYPE_LV2_PLUGIN,
"turtle", turtle,
"filename", filename,
"effect", effect,
"uri", uri,
"effect-index", effect_index,
NULL);
return(lv2_plugin);
}
|