[d4435e]: jack-dssi-host / jack-dssi-host.c Maximize Restore History

Download this file

jack-dssi-host.c    1906 lines (1552 with data), 61.6 kB

   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
/* -*- c-basic-offset: 4 -*- vi:set ts=8 sts=4 sw=4: */
/* jack-dssi-host.c
*
* Disposable Soft Synth Interface
*
* This is a host for DSSI plugins. It listens for MIDI events on an
* ALSA sequencer port, delivers them to DSSI synths and outputs the
* result via JACK. It does not currently support audio input (e.g.
* for DSSI effects plugins).
*
* This program expects the names of up to 16 DSSI synth plugins, in
* the form '<dll-name>:<label>',* to be provided on the command line.
* If just '<dll-name>' is provided, the first plugin in the DLL is
* is used. MIDI channels are assigned to each plugin instance, in
* order, beginning with channel 0 (zero-based). A plugin may be
* easily instantiated multiple times by preceding its name and label
* with a dash followed immediately by the desired number of instances,
* e.g. '-3 my_plugins.so:zoomy' would create three instances of the
* 'zoomy' plugin.
*/
/*
* Copyright 2004 Chris Cannam, Steve Harris and Sean Bolton.
*
* Permission to use, copy, modify, distribute, and sell this software
* for any purpose is hereby granted without fee, provided that the
* above copyright notice and this permission notice are included in
* all copies or substantial portions of the software.
*/
#define _BSD_SOURCE 1
#define _SVID_SOURCE 1
#define _ISOC99_SOURCE 1
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <ladspa.h>
#include "dssi.h"
#include <alsa/asoundlib.h>
#include <alsa/seq.h>
#include <jack/jack.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <dlfcn.h>
#include <unistd.h>
#include <math.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/wait.h>
#include <signal.h>
#include <dirent.h>
#include <time.h>
#include <libgen.h>
#include <lo/lo.h>
#include "jack-dssi-host.h"
#include "../message_buffer/message_buffer.h"
#ifdef MIDI_ALSA
static snd_seq_t *alsaClient;
#endif
static jack_client_t *jackClient;
static jack_port_t **inputPorts, **outputPorts;
static d3h_dll_t *dlls;
static d3h_plugin_t *plugins;
static int plugin_count = 0;
static float sample_rate;
static d3h_instance_t instances[D3H_MAX_INSTANCES];
static int instance_count = 0;
static LADSPA_Handle *instanceHandles;
static snd_seq_event_t **instanceEventBuffers;
static unsigned long *instanceEventCounts;
static int insTotal, outsTotal;
static float **pluginInputBuffers, **pluginOutputBuffers;
static int controlInsTotal, controlOutsTotal;
static float *pluginControlIns, *pluginControlOuts;
static d3h_instance_t *channel2instance[D3H_MAX_CHANNELS]; /* maps MIDI channel to instance */
static d3h_instance_t **pluginControlInInstances; /* maps global control in # to instance */
static unsigned long *pluginControlInPortNumbers; /* maps global control in # to instance LADSPA port # */
static int *pluginPortUpdated; /* indexed by global control in # */
static char osc_path_tmp[1024];
static char *projectDirectory;
lo_server_thread serverThread;
static sigset_t _signals;
int exiting = 0;
static int verbose = 0;
static int load_guis = 1;
const char *myName = NULL;
#define EVENT_BUFFER_SIZE 1024
static snd_seq_event_t midiEventBuffer[EVENT_BUFFER_SIZE]; /* ring buffer */
static int midiEventReadIndex = 0, midiEventWriteIndex = 0;
static pthread_mutex_t midiEventBufferMutex = PTHREAD_MUTEX_INITIALIZER;
LADSPA_Data get_port_default(const LADSPA_Descriptor *plugin, int port);
void osc_error(int num, const char *m, const char *path);
int osc_message_handler(const char *path, const char *types, lo_arg **argv, int
argc, void *data, void *user_data) ;
int osc_debug_handler(const char *path, const char *types, lo_arg **argv, int
argc, void *data, void *user_data) ;
void
signalHandler(int sig)
{
fprintf(stderr, "%s: signal %d caught, trying to clean up and exit\n",
myName, sig);
exiting = 1;
}
void
midi_callback()
{
snd_seq_event_t *ev = 0;
struct timeval tv;
pthread_mutex_lock(&midiEventBufferMutex);
#ifdef MIDI_ALSA
do {
if (snd_seq_event_input(alsaClient, &ev) > 0) {
if (midiEventReadIndex == midiEventWriteIndex + 1) {
fprintf(stderr, "%s: Warning: MIDI event buffer overflow! ignoring incoming event\n", myName);
continue;
}
midiEventBuffer[midiEventWriteIndex] = *ev;
ev = &midiEventBuffer[midiEventWriteIndex];
/* At this point we change the event timestamp so that its
real-time field contains the actual time at which it was
received and processed (i.e. now). Then in the audio
callback we use that to calculate frame offset. */
gettimeofday(&tv, NULL);
ev->time.time.tv_sec = tv.tv_sec;
ev->time.time.tv_nsec = tv.tv_usec * 1000L;
if (ev->type == SND_SEQ_EVENT_NOTEON && ev->data.note.velocity == 0) {
ev->type = SND_SEQ_EVENT_NOTEOFF;
}
/* We don't need to handle EVENT_NOTE here, because ALSA
won't ever deliver them on the sequencer queue -- it
unbundles them into NOTE_ON and NOTE_OFF when they're
dispatched. We would only need worry about them when
retrieving MIDI events from some other source. */
midiEventWriteIndex = (midiEventWriteIndex + 1) % EVENT_BUFFER_SIZE;
}
} while (snd_seq_event_input_pending(alsaClient, 0) > 0);
#endif
pthread_mutex_unlock(&midiEventBufferMutex);
}
void
setControl(d3h_instance_t *instance, long controlIn, snd_seq_event_t *event)
{
long port = pluginControlInPortNumbers[controlIn];
const LADSPA_Descriptor *p = instance->plugin->descriptor->LADSPA_Plugin;
LADSPA_PortRangeHintDescriptor d = p->PortRangeHints[port].HintDescriptor;
LADSPA_Data lb = p->PortRangeHints[port].LowerBound *
(LADSPA_IS_HINT_SAMPLE_RATE(p->PortRangeHints[port].HintDescriptor) ?
sample_rate : 1.0f);
LADSPA_Data ub = p->PortRangeHints[port].UpperBound *
(LADSPA_IS_HINT_SAMPLE_RATE(p->PortRangeHints[port].HintDescriptor) ?
sample_rate : 1.0f);
float value = (float)event->data.control.value;
if (!LADSPA_IS_HINT_BOUNDED_BELOW(d)) {
if (!LADSPA_IS_HINT_BOUNDED_ABOVE(d)) {
/* unbounded: might as well leave the value alone. */
return;
} else {
/* bounded above only. just shift the range. */
value = ub - 127.0f + value;
}
} else {
if (!LADSPA_IS_HINT_BOUNDED_ABOVE(d)) {
/* bounded below only. just shift the range. */
value = lb + value;
} else {
/* bounded both ends. more interesting. */
if (LADSPA_IS_HINT_LOGARITHMIC(d) && lb > 0.0f && ub > 0.0f) {
const float llb = logf(lb);
const float lub = logf(ub);
value = expf(llb + ((lub - llb) * value / 127.0f));
} else {
value = lb + ((ub - lb) * value / 127.0f);
}
}
}
if (LADSPA_IS_HINT_INTEGER(d)) {
value = lrintf(value);
}
if (verbose) {
printf("%s: %s MIDI controller %d=%d -> control in %ld=%f\n", myName,
instance->friendly_name, event->data.control.param,
event->data.control.value, controlIn, value);
}
pluginControlIns[controlIn] = value;
pluginPortUpdated[controlIn] = 1;
}
int
audio_callback(jack_nframes_t nframes, void *arg)
{
int i;
int outCount, inCount;
d3h_instance_t *instance;
struct timeval tv, evtv, diff;
long framediff;
gettimeofday(&tv, NULL);
/* Not especially pretty or efficient */
for (i = 0; i < instance_count; i++) {
instanceEventCounts[i] = 0;
}
for ( ; midiEventReadIndex != midiEventWriteIndex;
midiEventReadIndex = (midiEventReadIndex + 1) % EVENT_BUFFER_SIZE) {
snd_seq_event_t *ev = &midiEventBuffer[midiEventReadIndex];
if (!snd_seq_ev_is_channel_type(ev)) {
/* discard non-channel oriented messages */
continue;
}
instance = channel2instance[ev->data.note.channel];
if (!instance
/* || instance->inactive */) /* no -- see comment in osc_exiting_handler */
{
/* discard messages intended for channels we aren't using or
absent or exited plugins */
continue;
}
i = instance->number;
/* Stop processing incoming MIDI if an instance's event buffer is
* full. */
if (instanceEventCounts[i] == EVENT_BUFFER_SIZE)
break;
/* Each event has a real-time timestamp indicating when it was
* received (set by midi_callback). We need to calculate the
* difference between then and the start of the audio callback
* (held in tv), and use that to assign a frame offset, to
* avoid jitter. We should stop processing when we reach any
* event received after the start of the audio callback. */
evtv.tv_sec = ev->time.time.tv_sec;
evtv.tv_usec = ev->time.time.tv_nsec / 1000;
if (evtv.tv_sec > tv.tv_sec ||
(evtv.tv_sec == tv.tv_sec &&
evtv.tv_usec > tv.tv_usec)) {
break;
}
diff.tv_sec = tv.tv_sec - evtv.tv_sec;
if (tv.tv_usec < evtv.tv_usec) {
--diff.tv_sec;
diff.tv_usec = tv.tv_usec + 1000000 - evtv.tv_usec;
} else {
diff.tv_usec = tv.tv_usec - evtv.tv_usec;
}
framediff =
diff.tv_sec * sample_rate +
((diff.tv_usec / 1000) * sample_rate) / 1000 +
((diff.tv_usec - 1000 * (diff.tv_usec / 1000)) * sample_rate) / 1000000;
if (framediff >= nframes) framediff = nframes - 1;
else if (framediff < 0) framediff = 0;
ev->time.tick = nframes - framediff - 1;
if (ev->type == SND_SEQ_EVENT_CONTROLLER) {
int controller = ev->data.control.param;
#ifdef DEBUG
MB_MESSAGE("%s CC %d(0x%02x) = %d\n", instance->friendly_name,
controller, controller, ev->data.control.value);
#endif
if (controller == 0) { // bank select MSB
instance->pendingBankMSB = ev->data.control.value;
} else if (controller == 32) { // bank select LSB
instance->pendingBankLSB = ev->data.control.value;
} else if (controller > 0 && controller < MIDI_CONTROLLER_COUNT) {
long controlIn = instance->controllerMap[controller];
if (controlIn >= 0) {
/* controller is mapped to LADSPA port, update the port */
setControl(instance, controlIn, ev);
} else {
/* controller is not mapped, so pass the event through to plugin */
instanceEventBuffers[i][instanceEventCounts[i]] = *ev;
instanceEventCounts[i]++;
}
}
} else if (ev->type == SND_SEQ_EVENT_PGMCHANGE) {
instance->pendingProgramChange = ev->data.control.value;
instance->uiNeedsProgramUpdate = 1;
} else {
instanceEventBuffers[i][instanceEventCounts[i]] = *ev;
instanceEventCounts[i]++;
}
}
/* process pending program changes */
for (i = 0; i < instance_count; i++) {
instance = &instances[i];
/* no -- see comment in osc_exiting_handler */
/* if (instance->inactive) continue; */
if (instance->pendingProgramChange >= 0) {
int pc = instance->pendingProgramChange;
int msb = instance->pendingBankMSB;
int lsb = instance->pendingBankLSB;
//!!! gosh, I don't know this -- need to check with the specs:
// if you only send one of MSB/LSB controllers, should the
// other go to zero or remain as it was? Assume it remains as
// it was, for now.
if (lsb >= 0) {
if (msb >= 0) {
instance->currentBank = lsb + 128 * msb;
} else {
instance->currentBank = lsb + 128 * (instance->currentBank / 128);
}
} else if (msb >= 0) {
instance->currentBank = (instance->currentBank % 128) + 128 * msb;
}
instance->currentProgram = pc;
instance->pendingProgramChange = -1;
instance->pendingBankMSB = -1;
instance->pendingBankLSB = -1;
if (instance->plugin->descriptor->select_program) {
instance->plugin->descriptor->
select_program(instanceHandles[instance->number],
instance->currentBank,
instance->currentProgram);
}
}
}
for (inCount = 0; inCount < insTotal; ++inCount) {
jack_default_audio_sample_t *buffer =
jack_port_get_buffer(inputPorts[inCount], nframes);
memcpy(pluginInputBuffers[inCount], buffer, nframes * sizeof(LADSPA_Data));
}
/* call run_synth() or run_multiple_synths() for all instances */
i = 0;
outCount = 0;
while (i < instance_count) {
/* no -- see comment in osc_exiting_handler */
/*
if (instances[i].inactive) {
int j;
for (j = 0; j < instances[i].plugin->outs; ++j) {
memset(pluginOutputBuffers[outCount + j], 0, nframes * sizeof(LADSPA_Data));
}
outCount += j;
++i;
continue;
}
*/
outCount += instances[i].plugin->outs;
if (instances[i].plugin->descriptor->run_multiple_synths) {
instances[i].plugin->descriptor->run_multiple_synths
(instances[i].plugin->instances,
instanceHandles + i,
nframes,
instanceEventBuffers + i,
instanceEventCounts + i);
i += instances[i].plugin->instances;
} else if (instances[i].plugin->descriptor->run_synth) {
instances[i].plugin->descriptor->run_synth(instanceHandles[i],
nframes,
instanceEventBuffers[i],
instanceEventCounts[i]);
i++;
} else if (instances[i].plugin->descriptor->LADSPA_Plugin->run) {
instances[i].plugin->descriptor->LADSPA_Plugin->run(instanceHandles[i],
nframes);
i++;
} else {
fprintf(stderr, "DSSI plugin %d has no run_multiple_synths, run_synth or run method!\n", i);
i++;
}
}
assert(sizeof(LADSPA_Data) == sizeof(jack_default_audio_sample_t));
for (outCount = 0; outCount < outsTotal; ++outCount) {
jack_default_audio_sample_t *buffer =
jack_port_get_buffer(outputPorts[outCount], nframes);
memcpy(buffer, pluginOutputBuffers[outCount], nframes * sizeof(LADSPA_Data));
}
return 0;
}
char *
load(const char *dllName, void **dll, int quiet) /* returns directory where dll found */
{
static char *defaultDssiPath = 0;
const char *dssiPath = getenv("DSSI_PATH");
char *path, *origPath, *element, *message;
void *handle = 0;
/* If the dllName is an absolute path */
if (*dllName == '/') {
if ((handle = dlopen(dllName, RTLD_NOW))) { /* real-time programs should not use RTLD_LAZY */
*dll = handle;
path = strdup(dllName);
return dirname(path);
} else {
if (!quiet) {
fprintf(stderr, "Cannot find DSSI or LADSPA plugin at '%s'\n", dllName);
}
return NULL;
}
}
if (!dssiPath) {
if (!defaultDssiPath) {
const char *home = getenv("HOME");
if (home) {
defaultDssiPath = malloc(strlen(home) + 60);
sprintf(defaultDssiPath, "/usr/local/lib/dssi:/usr/lib/dssi:%s/.dssi", home);
} else {
defaultDssiPath = strdup("/usr/local/lib/dssi:/usr/lib/dssi");
}
}
dssiPath = defaultDssiPath;
if (!quiet) {
fprintf(stderr, "\n%s: Warning: DSSI path not set\n%s: Defaulting to \"%s\"\n\n", myName, myName, dssiPath);
}
}
path = strdup(dssiPath);
origPath = path;
*dll = 0;
while ((element = strtok(path, ":")) != 0) {
char *filePath;
path = 0;
if (element[0] != '/') {
if (!quiet) {
fprintf(stderr, "%s: Ignoring relative element \"%s\" in path\n", myName, element);
}
continue;
}
if (!quiet && verbose) {
fprintf(stderr, "%s: Looking for library \"%s\" in %s... ", myName, dllName, element);
}
filePath = (char *)malloc(strlen(element) + strlen(dllName) + 2);
sprintf(filePath, "%s/%s", element, dllName);
if ((handle = dlopen(filePath, RTLD_NOW))) { /* real-time programs should not use RTLD_LAZY */
if (!quiet && verbose) {
fprintf(stderr, "found\n");
}
*dll = handle;
free(filePath);
path = strdup(element);
free(origPath);
return path;
}
if (!quiet && verbose) {
message = dlerror();
if (message) {
fprintf(stderr, "not found: %s\n", message);
} else {
fprintf(stderr, "not found\n");
}
}
free(filePath);
}
free(origPath);
return 0;
}
static int
instance_sort_cmp(const void *a, const void *b)
{
d3h_instance_t *ia = (d3h_instance_t *)a;
d3h_instance_t *ib = (d3h_instance_t *)b;
if (ia->plugin->number != ib->plugin->number) {
return ia->plugin->number - ib->plugin->number;
} else {
return ia->channel - ib->channel;
}
}
void
startGUI(const char *directory, const char *dllName, const char *label,
const char *oscUrl, const char *instanceTag)
{
struct dirent *entry;
char *dllBase = strdup(dllName);
char *subpath;
DIR *subdir;
char *filename;
struct stat buf;
int fuzzy;
if (strlen(dllBase) > 3 &&
!strcasecmp(dllBase + strlen(dllBase) - 3, ".so")) {
dllBase[strlen(dllBase) - 3] = '\0';
}
if (*dllBase == '/') {
subpath = dllBase;
dllBase = strdup(strrchr(subpath, '/') + 1);
} else {
subpath = (char *)malloc(strlen(directory) + strlen(dllBase) + 2);
sprintf(subpath, "%s/%s", directory, dllBase);
}
for (fuzzy = 0; fuzzy <= 1; ++fuzzy) {
if (!(subdir = opendir(subpath))) {
if (verbose) {
fprintf(stderr, "%s: can't open plugin GUI directory \"%s\"\n", myName, subpath);
}
free(subpath);
free(dllBase);
return;
}
while ((entry = readdir(subdir))) {
if (entry->d_name[0] == '.') continue;
if (!strchr(entry->d_name, '_')) continue;
if (fuzzy) {
if (verbose) {
fprintf(stderr, "checking %s against %s\n", entry->d_name, dllBase);
}
if (strlen(entry->d_name) <= strlen(dllBase) ||
strncmp(entry->d_name, dllBase, strlen(dllBase)) ||
entry->d_name[strlen(dllBase)] != '_')
continue;
} else {
if (verbose) {
fprintf(stderr, "checking %s against %s\n", entry->d_name, label);
}
if (strlen(entry->d_name) <= strlen(label) ||
strncmp(entry->d_name, label, strlen(label)) ||
entry->d_name[strlen(label)] != '_')
continue;
}
filename = (char *)malloc(strlen(subpath) + strlen(entry->d_name) + 2);
sprintf(filename, "%s/%s", subpath, entry->d_name);
if (stat(filename, &buf)) {
perror("stat failed");
free(filename);
continue;
}
if ((S_ISREG(buf.st_mode) || S_ISLNK(buf.st_mode)) &&
(buf.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH))) {
if (verbose) {
fprintf(stderr, "%s: trying to execute GUI at \"%s\"\n",
myName, filename);
}
if (fork() == 0) {
execlp(filename, filename, oscUrl, dllName, label, instanceTag, 0);
perror("exec failed");
exit(1);
}
free(filename);
free(subpath);
free(dllBase);
return;
}
free(filename);
}
}
if (verbose) {
fprintf(stderr, "%s: no GUI found for plugin \"%s\" in \"%s/\"\n",
myName, label, subpath);
}
free(subpath);
free(dllBase);
}
void
query_programs(d3h_instance_t *instance)
{
int i;
/* free old lot */
if (instance->pluginPrograms) {
for (i = 0; i < instance->pluginProgramCount; i++)
free((void *)instance->pluginPrograms[i].Name);
free((char *)instance->pluginPrograms);
instance->pluginPrograms = NULL;
instance->pluginProgramCount = 0;
}
instance->pendingBankLSB = -1;
instance->pendingBankMSB = -1;
instance->pendingProgramChange = -1;
if (instance->plugin->descriptor->get_program &&
instance->plugin->descriptor->select_program) {
/* Count the plugins first */
for (i = 0; instance->plugin->descriptor->
get_program(instanceHandles[instance->number], i); ++i);
if (i > 0) {
instance->pluginProgramCount = i;
instance->pluginPrograms = (DSSI_Program_Descriptor *)
malloc(i * sizeof(DSSI_Program_Descriptor));
while (i > 0) {
const DSSI_Program_Descriptor *descriptor;
--i;
descriptor = instance->plugin->descriptor->
get_program(instanceHandles[instance->number], i);
instance->pluginPrograms[i].Bank = descriptor->Bank;
instance->pluginPrograms[i].Program = descriptor->Program;
instance->pluginPrograms[i].Name = strdup(descriptor->Name);
if (verbose) {
printf("%s: %s program %d is MIDI bank %lu program %lu, named '%s'\n",
myName, instance->friendly_name, i,
instance->pluginPrograms[i].Bank,
instance->pluginPrograms[i].Program,
instance->pluginPrograms[i].Name);
}
}
}
}
}
int
main(int argc, char **argv)
{
int portid;
int npfd;
struct pollfd *pfd;
d3h_dll_t *dll;
d3h_plugin_t *plugin;
d3h_instance_t *instance;
void *pluginObject;
char *dllName;
char *label;
const char **ports;
char *tmp;
char *url;
int i, reps, j;
int in, out, controlIn, controlOut;
char clientName[33];
setsid();
sigemptyset (&_signals);
sigaddset(&_signals, SIGHUP);
sigaddset(&_signals, SIGINT);
sigaddset(&_signals, SIGQUIT);
sigaddset(&_signals, SIGPIPE);
sigaddset(&_signals, SIGTERM);
sigaddset(&_signals, SIGUSR1);
sigaddset(&_signals, SIGUSR2);
pthread_sigmask(SIG_BLOCK, &_signals, 0);
insTotal = outsTotal = controlInsTotal = controlOutsTotal = 0;
/* Handle run-plugin-from-executable-name special case */
if (argc == 1) {
const char *basename = strrchr(argv[0], '/');
if (!basename) basename = argv[0];
else ++basename;
if (basename[0] && strcmp(basename, "jack-dssi-host")) {
/* look for basename + .so as plugin */
dllName = malloc(strlen(basename) + 4);
sprintf(dllName, "%s.so", basename);
if (load(dllName, &pluginObject, 1)) {
dlclose(pluginObject);
argc = 2;
myName = strdup(argv[0]);
argv = (char **)malloc(2 * sizeof(char *));
argv[0] = "jack-dssi-host";
argv[1] = dllName;
}
}
}
if (!myName) myName = strdup(argv[0]);
/* Parse args and report usage */
if (argc < 2) {
fprintf(stderr, "\nUsage: %s [-v] [-n] [-p <projdir>] [-<i>] <libname>[%c<label>] [...]\n", argv[0], LABEL_SEP);
fprintf(stderr, "\n -v Verbose mode\n");
fprintf(stderr, " -n No GUIs\n");
fprintf(stderr, " <projdir> Project directory to pass to plugin and UI\n");
fprintf(stderr, " <i> Number of instances of each plugin to run (max %d total, default 1)\n", D3H_MAX_INSTANCES);
fprintf(stderr, " <libname> DSSI plugin library .so to load (searched for in $DSSI_PATH)\n");
fprintf(stderr, " <label> Label of plugin to load from library\n");
fprintf(stderr, " [...] Optionally more instance counts, plugins and labels\n");
fprintf(stderr, "\nExample: %s -2 lib1.so -1 lib2.so%cfuzzy\n", argv[0], LABEL_SEP);
fprintf(stderr, " run two instances of the first plugin found in lib1.so, assigned to MIDI\n channels 0 and 1 and connected to the first available JACK outputs, and one\n instance of the \"fuzzy\" plugin in lib2.so with MIDI channels 2 and 3 and\n connected to the next available JACK outputs.\n");
fprintf(stderr,"\nAs a special case, if this program is started with a name other than\njack-dssi-host, and if that name (plus .so suffix) can be found in the DSSI path\nas a valid plugin library, and if no further command line arguments are given,\nthen the first plugin in that library will be loaded automatically.\n\n");
return 2;
}
if (verbose) {
fprintf(stderr, "%s: Starting...\n", myName);
}
projectDirectory = NULL;
reps = 1;
for (i = 1; i < argc; i++) {
if (!strcmp(argv[i], "-v")) {
verbose = 1;
continue;
}
if (!strcmp(argv[i], "-n")) {
load_guis = 0;
continue;
}
if (!strcmp(argv[i], "-p")) {
if (i < argc - 1) {
projectDirectory = argv[++i];
} else {
fprintf(stderr, "%s: project directory expected after -p\n", myName);
return 2;
}
continue;
}
if (instance_count >= D3H_MAX_INSTANCES) {
fprintf(stderr, "%s: too many plugin instances specified (max is %d)\n", myName, D3H_MAX_INSTANCES);
return 2;
}
/* parse repetition count */
if (argv[i][0] == '-') {
reps = atoi(&argv[i][1]);
if (reps > 0) {
continue;
} else {
reps = 1;
}
}
/* parse dll name, plus a label if supplied */
tmp = strchr(argv[i], LABEL_SEP);
if (tmp) {
dllName = calloc(1, tmp - argv[i] + 1);
strncpy(dllName, argv[i], tmp - argv[i]);
label = strdup(tmp + 1);
} else {
dllName = strdup(argv[i]);
label = NULL;
}
/* check if we've seen this plugin before */
for (plugin = plugins; plugin; plugin = plugin->next) {
if (label) {
if (!strcmp(dllName, plugin->dll->name) &&
!strcmp(label, plugin->label))
break;
} else {
if (!strcmp(dllName, plugin->dll->name) &&
plugin->is_first_in_dll)
break;
}
}
if (plugin) {
/* have already seen this plugin */
free(dllName);
free(label);
} else {
/* this is a new plugin */
plugin = (d3h_plugin_t *)calloc(1, sizeof(d3h_plugin_t));
plugin->number = plugin_count;
plugin->label = label;
/* check if we've seen this dll before */
for (dll = dlls; dll; dll = dll->next) {
if (!strcmp(dllName, dll->name))
break;
}
if (!dll) {
/* this is a new dll */
dll = (d3h_dll_t *)calloc(1, sizeof(d3h_dll_t));
dll->name = dllName;
dll->directory = load(dllName, &pluginObject, 0);
if (!dll->directory || !pluginObject) {
fprintf(stderr, "\n%s: Error: Failed to load plugin library \"%s\"\n", myName, dllName);
return 1;
}
dll->descfn = (DSSI_Descriptor_Function)dlsym(pluginObject,
"dssi_descriptor");
if (dll->descfn) {
dll->is_DSSI_dll = 1;
} else {
dll->descfn = (DSSI_Descriptor_Function)dlsym(pluginObject,
"ladspa_descriptor");
if (!dll->descfn) {
fprintf(stderr, "\n%s: Error: \"%s\" is not a DSSI or LADSPA plugin library\n", myName, dllName);
return 1;
}
dll->is_DSSI_dll = 0;
}
dll->next = dlls;
dlls = dll;
}
plugin->dll = dll;
/* get the plugin descriptor */
j = 0;
if (dll->is_DSSI_dll) {
const DSSI_Descriptor *desc;
while ((desc = dll->descfn(j++))) {
if (!plugin->label ||
!strcmp(desc->LADSPA_Plugin->Label, plugin->label)) {
plugin->descriptor = desc;
break;
}
}
} else { /* LADSPA plugin; create and use a dummy DSSI descriptor */
LADSPA_Descriptor *desc;
plugin->descriptor = (const DSSI_Descriptor *)calloc(1, sizeof(DSSI_Descriptor));
((DSSI_Descriptor *)plugin->descriptor)->DSSI_API_Version = 1;
while ((desc = (LADSPA_Descriptor *)dll->descfn(j++))) {
if (!plugin->label ||
!strcmp(desc->Label, plugin->label)) {
((DSSI_Descriptor *)plugin->descriptor)->LADSPA_Plugin = desc;
break;
}
}
if (!plugin->descriptor->LADSPA_Plugin) {
free((void *)plugin->descriptor);
plugin->descriptor = NULL;
}
}
if (!plugin->descriptor) {
fprintf(stderr, "\n%s: Error: Plugin label \"%s\" not found in library \"%s\"\n",
myName, plugin->label ? plugin->label : "(none)", dllName);
return 1;
}
plugin->is_first_in_dll = (j = 1);
if (!plugin->label) {
plugin->label = strdup(plugin->descriptor->LADSPA_Plugin->Label);
}
/* Count number of i/o buffers and ports required */
plugin->ins = 0;
plugin->outs = 0;
plugin->controlIns = 0;
plugin->controlOuts = 0;
for (j = 0; j < plugin->descriptor->LADSPA_Plugin->PortCount; j++) {
LADSPA_PortDescriptor pod =
plugin->descriptor->LADSPA_Plugin->PortDescriptors[j];
if (LADSPA_IS_PORT_AUDIO(pod)) {
if (LADSPA_IS_PORT_INPUT(pod)) ++plugin->ins;
else if (LADSPA_IS_PORT_OUTPUT(pod)) ++plugin->outs;
} else if (LADSPA_IS_PORT_CONTROL(pod)) {
if (LADSPA_IS_PORT_INPUT(pod)) ++plugin->controlIns;
else if (LADSPA_IS_PORT_OUTPUT(pod)) ++plugin->controlOuts;
}
}
/* finish up new plugin */
plugin->instances = 0;
plugin->next = plugins;
plugins = plugin;
plugin_count++;
}
/* set up instances */
for (j = 0; j < reps; j++) {
if (instance_count < D3H_MAX_INSTANCES) {
instance = &instances[instance_count];
instance->plugin = plugin;
instance->channel = instance_count;
instance->inactive = 1;
tmp = (char *)malloc(strlen(plugin->dll->name) +
strlen(plugin->label) + 9);
instance->friendly_name = tmp;
strcpy(tmp, plugin->dll->name);
if (strlen(tmp) > 3 &&
!strcasecmp(tmp + strlen(tmp) - 3, ".so")) {
tmp = tmp + strlen(tmp) - 3;
} else {
tmp = tmp + strlen(tmp);
}
sprintf(tmp, "/%s/chan%02d", plugin->label, instance->channel);
instance->pluginProgramCount = 0;
instance->pluginPrograms = NULL;
instance->currentBank = 0;
instance->currentProgram = 0;
instance->pendingBankLSB = -1;
instance->pendingBankMSB = -1;
instance->pendingProgramChange = -1;
instance->uiTarget = NULL;
instance->ui_initial_show_sent = 0;
instance->uiNeedsProgramUpdate = 0;
instance->ui_osc_control_path = NULL;
instance->ui_osc_program_path = NULL;
instance->ui_osc_quit_path = NULL;
instance->ui_osc_show_path = NULL;
insTotal += plugin->ins;
outsTotal += plugin->outs;
controlInsTotal += plugin->controlIns;
controlOutsTotal += plugin->controlOuts;
plugin->instances++;
instance_count++;
} else {
fprintf(stderr, "%s: too many plugin instances specified\n", myName);
return 2;
}
}
reps = 1;
}
if (instance_count == 0) {
fprintf(stderr, "%s: No plugin specified\n", myName);
return 2;
}
/* sort array of instances to group them by plugin */
if (instance_count > 1) {
qsort(instances, instance_count, sizeof(d3h_instance_t), instance_sort_cmp);
}
/* build channel2instance[] while showing what our instances are */
for (i = 0; i < D3H_MAX_CHANNELS; i++)
channel2instance[i] = NULL;
for (i = 0; i < instance_count; i++) {
instance = &instances[i];
instance->number = i;
channel2instance[instance->channel] = instance;
if (verbose) {
fprintf(stderr, "%s: instance %2d on channel %2d, plugin %2d is \"%s\"\n",
myName, i, instance->channel, instance->plugin->number,
instance->friendly_name);
}
}
/* Create buffers and JACK client and ports */
if (instance_count > 1) strcpy(clientName, "jack-dssi-host");
else {
strncpy(clientName, instances[0].plugin->descriptor->LADSPA_Plugin->Name, 32);
clientName[32] = '\0';
}
if ((jackClient = jack_client_new(clientName)) == 0) {
clientName[22] = '\0';
sprintf(clientName + strlen(clientName), " (%d)", (int)getpid());
if ((jackClient = jack_client_new(clientName)) == 0) {
fprintf(stderr, "\n%s: Error: Failed to connect to JACK server\n",
myName);
return 1;
}
}
sample_rate = jack_get_sample_rate(jackClient);
inputPorts = (jack_port_t **)malloc(insTotal * sizeof(jack_port_t *));
pluginInputBuffers = (float **)malloc(insTotal * sizeof(float *));
pluginControlIns = (float *)calloc(controlInsTotal, sizeof(float));
pluginControlInInstances =
(d3h_instance_t **)malloc(controlInsTotal * sizeof(d3h_instance_t *));
pluginControlInPortNumbers =
(unsigned long *)malloc(controlInsTotal * sizeof(unsigned long));
pluginPortUpdated = (int *)malloc(controlInsTotal * sizeof(int));
outputPorts = (jack_port_t **)malloc(outsTotal * sizeof(jack_port_t *));
pluginOutputBuffers = (float **)malloc(outsTotal * sizeof(float *));
pluginControlOuts = (float *)calloc(controlOutsTotal, sizeof(float));
instanceHandles = (LADSPA_Handle *)malloc(instance_count *
sizeof(LADSPA_Handle));
instanceEventBuffers = (snd_seq_event_t **)malloc(instance_count *
sizeof(snd_seq_event_t *));
instanceEventCounts = (unsigned long *)malloc(instance_count *
sizeof(unsigned long));
for (i = 0; i < instance_count; i++) {
instanceEventBuffers[i] = (snd_seq_event_t *)malloc(EVENT_BUFFER_SIZE *
sizeof(snd_seq_event_t));
instances[i].pluginPortControlInNumbers =
(int *)malloc(instances[i].plugin->descriptor->LADSPA_Plugin->PortCount *
sizeof(int));
}
in = 0;
out = 0;
reps = 0;
for (i = 0; i < instance_count; i++) {
if (i > 0 &&
!strcmp(instances[i ].plugin->descriptor->LADSPA_Plugin->Name,
instances[i-1].plugin->descriptor->LADSPA_Plugin->Name)) {
++reps;
} else if (i < instance_count - 1 &&
!strcmp(instances[i ].plugin->descriptor->LADSPA_Plugin->Name,
instances[i+1].plugin->descriptor->LADSPA_Plugin->Name)) {
reps = 1;
} else {
reps = 0;
}
for (j = 0; j < instances[i].plugin->ins; ++j) {
char portName[40];
strncpy(portName, instances[i].plugin->descriptor->LADSPA_Plugin->Name, 30);
if (reps > 0) {
portName[25] = '\0';
sprintf(portName + strlen(portName), " %d in_%d", reps, j + 1);
} else {
portName[30] = '\0';
sprintf(portName + strlen(portName), " in_%d", j + 1);
}
inputPorts[in] = jack_port_register(jackClient, portName,
JACK_DEFAULT_AUDIO_TYPE,
JackPortIsInput, 0);
pluginInputBuffers[in] =
(float *)calloc(jack_get_buffer_size(jackClient), sizeof(float));
++in;
}
for (j = 0; j < instances[i].plugin->outs; ++j) {
char portName[40];
strncpy(portName, instances[i].plugin->descriptor->LADSPA_Plugin->Name, 30);
if (reps > 0) {
portName[25] = '\0';
sprintf(portName + strlen(portName), " %d out_%d", reps, j + 1);
} else {
portName[30] = '\0';
sprintf(portName + strlen(portName), " out_%d", j + 1);
}
outputPorts[out] = jack_port_register(jackClient, portName,
JACK_DEFAULT_AUDIO_TYPE,
JackPortIsOutput, 0);
pluginOutputBuffers[out] =
(float *)calloc(jack_get_buffer_size(jackClient), sizeof(float));
++out;
}
}
jack_set_process_callback(jackClient, audio_callback, 0);
/* Instantiate plugins */
for (i = 0; i < instance_count; i++) {
plugin = instances[i].plugin;
instanceHandles[i] = plugin->descriptor->LADSPA_Plugin->instantiate
(plugin->descriptor->LADSPA_Plugin, sample_rate);
if (!instanceHandles[i]) {
fprintf(stderr, "\n%s: Error: Failed to instantiate instance %d!, plugin \"%s\"\n",
myName, i, plugin->label);
return 1;
}
if (projectDirectory && plugin->descriptor->configure) {
char *rv =plugin->descriptor->configure(instanceHandles[i],
DSSI_PROJECT_DIRECTORY_KEY,
projectDirectory);
if (rv) {
fprintf(stderr, "%s: Warning: plugin doesn't like project directory: \"%s\"\n", myName, rv);
}
}
}
/* Create OSC thread */
serverThread = lo_server_thread_new(NULL, osc_error);
snprintf((char *)osc_path_tmp, 31, "/dssi");
tmp = lo_server_thread_get_url(serverThread);
url = (char *)malloc(strlen(tmp) + strlen(osc_path_tmp));
sprintf(url, "%s%s", tmp, osc_path_tmp + 1);
if (verbose) {
printf("%s: registering %s\n", myName, url);
}
free(tmp);
lo_server_thread_add_method(serverThread, NULL, NULL, osc_message_handler,
NULL);
lo_server_thread_start(serverThread);
/* Connect and activate plugins */
for (in = 0; in < controlInsTotal; in++) {
pluginPortUpdated[in] = 0;
}
in = out = controlIn = controlOut = 0;
for (i = 0; i < instance_count; i++) { /* i is instance number */
instance = &instances[i];
instance->firstControlIn = controlIn;
for (j = 0; j < MIDI_CONTROLLER_COUNT; j++) {
instance->controllerMap[j] = -1;
}
plugin = instance->plugin;
for (j = 0; j < plugin->descriptor->LADSPA_Plugin->PortCount; j++) { /* j is LADSPA port number */
LADSPA_PortDescriptor pod =
plugin->descriptor->LADSPA_Plugin->PortDescriptors[j];
instance->pluginPortControlInNumbers[j] = -1;
if (LADSPA_IS_PORT_AUDIO(pod)) {
if (LADSPA_IS_PORT_INPUT(pod)) {
plugin->descriptor->LADSPA_Plugin->connect_port
(instanceHandles[i], j, pluginInputBuffers[in++]);
} else if (LADSPA_IS_PORT_OUTPUT(pod)) {
plugin->descriptor->LADSPA_Plugin->connect_port
(instanceHandles[i], j, pluginOutputBuffers[out++]);
}
} else if (LADSPA_IS_PORT_CONTROL(pod)) {
if (LADSPA_IS_PORT_INPUT(pod)) {
if (plugin->descriptor->get_midi_controller_for_port) {
int controller = plugin->descriptor->
get_midi_controller_for_port(instanceHandles[i], j);
if (controller == 0) {
MB_MESSAGE
("Buggy plugin: wants mapping for bank MSB\n");
} else if (controller == 32) {
MB_MESSAGE
("Buggy plugin: wants mapping for bank LSB\n");
} else if (DSSI_IS_CC(controller)) {
instance->controllerMap[DSSI_CC_NUMBER(controller)]
= controlIn;
}
}
pluginControlInInstances[controlIn] = instance;
pluginControlInPortNumbers[controlIn] = j;
instance->pluginPortControlInNumbers[j] = controlIn;
pluginControlIns[controlIn] = get_port_default
(plugin->descriptor->LADSPA_Plugin, j);
plugin->descriptor->LADSPA_Plugin->connect_port
(instanceHandles[i], j, &pluginControlIns[controlIn++]);
} else if (LADSPA_IS_PORT_OUTPUT(pod)) {
plugin->descriptor->LADSPA_Plugin->connect_port
(instanceHandles[i], j, &pluginControlOuts[controlOut++]);
}
}
} /* 'for (j...' LADSPA port number */
if (plugin->descriptor->LADSPA_Plugin->activate) {
plugin->descriptor->LADSPA_Plugin->activate(instanceHandles[i]);
}
instance->inactive = 0;
} /* 'for (i...' instance number */
assert(in == insTotal);
assert(out == outsTotal);
assert(controlIn == controlInsTotal);
assert(controlOut == controlOutsTotal);
/* Look up synth programs */
for (i = 0; i < instance_count; i++) {
instance = &instances[i];
query_programs(instance);
if (instance->plugin->descriptor->select_program &&
instance->pluginProgramCount > 0) {
/* select program at index 0 */
unsigned long bank = instance->pluginPrograms[0].Bank;
instance->pendingBankMSB = bank / 128;
instance->pendingBankLSB = bank % 128;
instance->pendingProgramChange = instance->pluginPrograms[0].Program;
instance->uiNeedsProgramUpdate = 1;
}
}
/* Create ALSA MIDI port */
#ifdef MIDI_ALSA
if (snd_seq_open(&alsaClient, "hw", SND_SEQ_OPEN_DUPLEX, 0) < 0) {
fprintf(stderr, "\n%s: Error: Failed to open ALSA sequencer interface\n",
myName);
return 1;
}
snd_seq_set_client_name(alsaClient, clientName);
if ((portid = snd_seq_create_simple_port
(alsaClient, clientName,
SND_SEQ_PORT_CAP_WRITE | SND_SEQ_PORT_CAP_SUBS_WRITE, 0)) < 0) {
fprintf(stderr, "\n%s: Error: Failed to create ALSA sequencer port\n",
myName);
return 1;
}
npfd = snd_seq_poll_descriptors_count(alsaClient, POLLIN);
pfd = (struct pollfd *)alloca(npfd * sizeof(struct pollfd));
snd_seq_poll_descriptors(alsaClient, pfd, npfd, POLLIN);
#endif /* MIDI_ALSA */
mb_init("host: ");
if (jack_activate(jackClient)) {
fprintf (stderr, "cannot activate jack client");
exit(1);
}
/* activate JACK and connect ports */
/* !FIX! this to more intelligently connect ports: */
ports = jack_get_ports(jackClient, NULL, NULL,
JackPortIsPhysical|JackPortIsInput);
if (ports && ports[0]) {
for (i = 0, j = 0; i < outsTotal; ++i) {
if (jack_connect(jackClient, jack_port_name(outputPorts[i]),
ports[j])) {
fprintf (stderr, "cannot connect output port %d\n", i);
}
if (!ports[++j]) j = 0;
}
free(ports);
}
signal(SIGINT, signalHandler);
signal(SIGTERM, signalHandler);
signal(SIGHUP, signalHandler);
signal(SIGQUIT, signalHandler);
pthread_sigmask(SIG_UNBLOCK, &_signals, 0);
/* Attempt to locate and start up a GUI for the plugin -- but
* continue even if we can't */
/* -FIX- Ack! So many windows all at once! */
if (load_guis) {
for (i = 0; i < instance_count; i++) {
char tag[12];
plugin = instances[i].plugin;
snprintf(osc_path_tmp, 1024, "%s/%s", url, instances[i].friendly_name);
snprintf(tag, 12, "channel %d", instances[i].channel);
printf("\n%s: OSC URL is:\n%s\n\n", myName, osc_path_tmp);
fflush(stdout);
startGUI(plugin->dll->directory, plugin->dll->name,
plugin->descriptor->LADSPA_Plugin->Label, osc_path_tmp, tag);
}
}
MB_MESSAGE("Ready\n");
exiting = 0;
while (!exiting) {
#ifdef MIDI_ALSA
if (poll(pfd, npfd, 100) > 0) {
midi_callback();
}
#endif /* MIDI_ALSA */
/* Race conditions here, because the programs and ports are
updated from the audio thread. We at least try to minimise
trouble by copying out before the expensive OSC call */
for (i = 0; i < instance_count; i++) {
instance = &instances[i];
if (instance->uiNeedsProgramUpdate && instance->pendingProgramChange < 0) {
int bank = instance->currentBank;
int program = instance->currentProgram;
instance->uiNeedsProgramUpdate = 0;
if (instance->uiTarget) {
lo_send(instance->uiTarget, instance->ui_osc_program_path, "ii", bank, program);
}
}
}
for (i = 0; i < controlInsTotal; ++i) {
if (pluginPortUpdated[i]) {
int port = pluginControlInPortNumbers[i];
float value = pluginControlIns[i];
instance = pluginControlInInstances[i];
pluginPortUpdated[i] = 0;
if (instance->uiTarget) {
lo_send(instance->uiTarget, instance->ui_osc_control_path, "if", port, value);
}
}
}
}
jack_client_close(jackClient);
/* cleanup plugins */
for (i = 0; i < instance_count; i++) {
instance = &instances[i];
if (instance->uiTarget) {
lo_send(instance->uiTarget, instance->ui_osc_quit_path, "");
lo_address_free(instance->uiTarget);
instance->uiTarget = NULL;
}
if (instance->plugin->descriptor->LADSPA_Plugin->deactivate) {
instance->plugin->descriptor->LADSPA_Plugin->deactivate
(instanceHandles[i]);
}
if (instance->plugin->descriptor->LADSPA_Plugin->cleanup) {
instance->plugin->descriptor->LADSPA_Plugin->cleanup
(instanceHandles[i]);
}
}
sleep(1);
sigemptyset (&_signals);
sigaddset(&_signals, SIGHUP);
pthread_sigmask(SIG_BLOCK, &_signals, 0);
kill(0, SIGHUP);
return 0;
}
LADSPA_Data get_port_default(const LADSPA_Descriptor *plugin, int port)
{
LADSPA_PortRangeHint hint = plugin->PortRangeHints[port];
float lower = hint.LowerBound *
(LADSPA_IS_HINT_SAMPLE_RATE(hint.HintDescriptor) ? sample_rate : 1.0f);
float upper = hint.UpperBound *
(LADSPA_IS_HINT_SAMPLE_RATE(hint.HintDescriptor) ? sample_rate : 1.0f);
if (!LADSPA_IS_HINT_HAS_DEFAULT(hint.HintDescriptor)) {
if (!LADSPA_IS_HINT_BOUNDED_BELOW(hint.HintDescriptor) ||
!LADSPA_IS_HINT_BOUNDED_ABOVE(hint.HintDescriptor)) {
/* No hint, its not bounded, wild guess */
return 0.0f;
}
if (lower <= 0.0f && upper >= 0.0f) {
/* It spans 0.0, 0.0 is often a good guess */
return 0.0f;
}
/* No clues, return minimum */
return lower;
}
/* Try all the easy ones */
if (LADSPA_IS_HINT_DEFAULT_0(hint.HintDescriptor)) {
return 0.0f;
} else if (LADSPA_IS_HINT_DEFAULT_1(hint.HintDescriptor)) {
return 1.0f;
} else if (LADSPA_IS_HINT_DEFAULT_100(hint.HintDescriptor)) {
return 100.0f;
} else if (LADSPA_IS_HINT_DEFAULT_440(hint.HintDescriptor)) {
return 440.0f;
}
/* All the others require some bounds */
if (LADSPA_IS_HINT_BOUNDED_BELOW(hint.HintDescriptor)) {
if (LADSPA_IS_HINT_DEFAULT_MINIMUM(hint.HintDescriptor)) {
return lower;
}
}
if (LADSPA_IS_HINT_BOUNDED_ABOVE(hint.HintDescriptor)) {
if (LADSPA_IS_HINT_DEFAULT_MAXIMUM(hint.HintDescriptor)) {
return upper;
}
if (LADSPA_IS_HINT_BOUNDED_BELOW(hint.HintDescriptor)) {
if (LADSPA_IS_HINT_LOGARITHMIC(hint.HintDescriptor) &&
lower > 0.0f && upper > 0.0f) {
if (LADSPA_IS_HINT_DEFAULT_LOW(hint.HintDescriptor)) {
return expf(logf(lower) * 0.75f + logf(upper) * 0.25f);
} else if (LADSPA_IS_HINT_DEFAULT_MIDDLE(hint.HintDescriptor)) {
return expf(logf(lower) * 0.5f + logf(upper) * 0.5f);
} else if (LADSPA_IS_HINT_DEFAULT_HIGH(hint.HintDescriptor)) {
return expf(logf(lower) * 0.25f + logf(upper) * 0.75f);
}
} else {
if (LADSPA_IS_HINT_DEFAULT_LOW(hint.HintDescriptor)) {
return lower * 0.75f + upper * 0.25f;
} else if (LADSPA_IS_HINT_DEFAULT_MIDDLE(hint.HintDescriptor)) {
return lower * 0.5f + upper * 0.5f;
} else if (LADSPA_IS_HINT_DEFAULT_HIGH(hint.HintDescriptor)) {
return lower * 0.25f + upper * 0.75f;
}
}
}
}
/* fallback */
return 0.0f;
}
void osc_error(int num, const char *msg, const char *path)
{
fprintf(stderr, "%s: liblo server error %d in path %s: %s\n",
myName, num, path, msg);
}
int
osc_midi_handler(d3h_instance_t *instance, lo_arg **argv)
{
static snd_midi_event_t *alsaCoder = NULL;
static snd_seq_event_t alsaEncodeBuffer[10];
long count;
snd_seq_event_t *ev = &alsaEncodeBuffer[0];
if (verbose) {
printf("%s: OSC: got midi request for %s "
"(%02x %02x %02x %02x)\n", myName, instance->friendly_name,
argv[0]->m[0], argv[0]->m[1], argv[0]->m[2], argv[0]->m[3]);
}
if (!alsaCoder) {
if (snd_midi_event_new(10, &alsaCoder)) {
fprintf(stderr, "%s: Failed to initialise ALSA MIDI coder!\n",
myName);
return 0;
}
}
snd_midi_event_reset_encode(alsaCoder);
count = snd_midi_event_encode
(alsaCoder, (argv[0]->m) + 1, 3, alsaEncodeBuffer); /* ignore OSC "port id" in argv[0]->m[0] */
if (!count || !snd_seq_ev_is_channel_type(ev)) {
return 0;
}
/* substitute correct MIDI channel */
ev->data.note.channel = instance->channel;
if (ev->type == SND_SEQ_EVENT_NOTEON && ev->data.note.velocity == 0) {
ev->type = SND_SEQ_EVENT_NOTEOFF;
}
pthread_mutex_lock(&midiEventBufferMutex);
if (midiEventReadIndex == midiEventWriteIndex + 1) {
fprintf(stderr, "%s: Warning: MIDI event buffer overflow!\n", myName);
} else if (ev->type == SND_SEQ_EVENT_CONTROLLER &&
(ev->data.control.param == 0 || ev->data.control.param == 32)) {
fprintf(stderr, "%s: Warning: %s UI sent bank select controller (should use /program OSC call), ignoring\n", myName, instance->friendly_name);
} else if (ev->type == SND_SEQ_EVENT_PGMCHANGE) {
fprintf(stderr, "%s: Warning: %s UI sent program change (should use /program OSC call), ignoring\n", myName, instance->friendly_name);
} else {
midiEventBuffer[midiEventWriteIndex] = *ev;
midiEventWriteIndex = (midiEventWriteIndex + 1) % EVENT_BUFFER_SIZE;
}
pthread_mutex_unlock(&midiEventBufferMutex);
return 0;
}
int
osc_control_handler(d3h_instance_t *instance, lo_arg **argv)
{
int port = argv[0]->i;
LADSPA_Data value = argv[1]->f;
if (port < 0 || port > instance->plugin->descriptor->LADSPA_Plugin->PortCount) {
fprintf(stderr, "%s: OSC: %s port number (%d) is out of range\n",
myName, instance->friendly_name, port);
return 0;
}
if (instance->pluginPortControlInNumbers[port] == -1) {
fprintf(stderr, "%s: OSC: %s port %d is not a control in\n",
myName, instance->friendly_name, port);
return 0;
}
pluginControlIns[instance->pluginPortControlInNumbers[port]] = value;
if (verbose) {
printf("%s: OSC: %s port %d = %f\n",
myName, instance->friendly_name, port, value);
}
return 0;
}
int
osc_program_handler(d3h_instance_t *instance, lo_arg **argv)
{
int bank = argv[0]->i;
int program = argv[1]->i;
int i;
int found = 0;
for (i = 0; i < instance->pluginProgramCount; ++i) {
if (instance->pluginPrograms[i].Bank == bank &&
instance->pluginPrograms[i].Program == program) {
if (verbose) {
printf("%s: OSC: %s setting bank %d, program %d, name %s\n",
myName,
instance->friendly_name, bank, program,
instance->pluginPrograms[i].Name);
}
found = 1;
break;
}
}
if (!found) {
printf("%s: OSC: %s UI requested unknown program: bank %d, program %d: sending to plugin anyway (plugin should ignore it)\n",
myName, instance->friendly_name, bank, program);
}
instance->pendingBankMSB = bank / 128;
instance->pendingBankLSB = bank % 128;
instance->pendingProgramChange = program;
return 0;
}
int
osc_configure_handler(d3h_instance_t *instance, lo_arg **argv)
{
const char *key = (const char *)&argv[0]->s;
const char *value = (const char *)&argv[1]->s;
char *message;
/* This is pretty much the simplest legal implementation of
* configure in a DSSI host. */
/* The host has the option to remember the set of (key,value)
* pairs associated with a particular instance, so that if it
* wants to restore the "same" instance on another occasion it can
* just call configure() on it for each of those pairs and so
* restore state without any input from a GUI. Any real-world GUI
* host will probably want to do that. This host doesn't have any
* concept of restoring an instance from one run to the next, so
* we don't bother remembering these at all. */
if (instance->plugin->descriptor->configure) {
int n = instance->number;
int m = n;
if (!strncmp(key, DSSI_RESERVED_CONFIGURE_PREFIX,
strlen(DSSI_RESERVED_CONFIGURE_PREFIX))) {
fprintf(stderr, "%s: OSC: UI for plugin '%s' attempted to use reserved configure key \"%s\", ignoring\n", myName, instance->friendly_name, key);
return 0;
}
if (instance->plugin->instances > 1 &&
!strncmp(key, DSSI_GLOBAL_CONFIGURE_PREFIX,
strlen(DSSI_GLOBAL_CONFIGURE_PREFIX))) {
while (n > 0 && instances[n-1].plugin == instances[m].plugin) --n;
m = n + instances[n].plugin->instances - 1;
}
while (n <= m) {
message = instances[n].plugin->descriptor->configure
(instanceHandles[n], key, value);
if (message) {
printf("%s: on configure '%s' '%s', plugin '%s' returned error '%s'\n",
myName, key, value, instance->friendly_name, message);
free(message);
}
// also call back on UIs for plugins other than the one
// that requested this:
if (n != instance->number && instances[n].uiTarget) {
lo_send(instances[n].uiTarget,
instances[n].ui_osc_configure_path, "ss", key, value);
}
/* configure invalidates bank and program information, so
we should do this again now: */
query_programs(&instances[n]);
++n;
}
}
return 0;
}
int
osc_update_handler(d3h_instance_t *instance, lo_arg **argv)
{
const char *url = (char *)&argv[0]->s;
const char *path;
unsigned int i;
char *host, *port;
if (verbose) {
printf("%s: OSC: got update request from <%s>\n", myName, url);
}
if (instance->uiTarget) lo_address_free(instance->uiTarget);
host = lo_url_get_hostname(url);
port = lo_url_get_port(url);
instance->uiTarget = lo_address_new(host, port);
free(host);
free(port);
path = lo_url_get_path(url);
if (instance->ui_osc_control_path) free(instance->ui_osc_control_path);
instance->ui_osc_control_path = (char *)malloc(strlen(path) + 10);
sprintf(instance->ui_osc_control_path, "%s/control", path);
if (instance->ui_osc_configure_path) free(instance->ui_osc_configure_path);
instance->ui_osc_configure_path = (char *)malloc(strlen(path) + 12);
sprintf(instance->ui_osc_configure_path, "%s/configure", path);
if (instance->ui_osc_program_path) free(instance->ui_osc_program_path);
instance->ui_osc_program_path = (char *)malloc(strlen(path) + 10);
sprintf(instance->ui_osc_program_path, "%s/program", path);
if (instance->ui_osc_quit_path) free(instance->ui_osc_quit_path);
instance->ui_osc_quit_path = (char *)malloc(strlen(path) + 10);
sprintf(instance->ui_osc_quit_path, "%s/quit", path);
if (instance->ui_osc_show_path) free(instance->ui_osc_show_path);
instance->ui_osc_show_path = (char *)malloc(strlen(path) + 10);
sprintf(instance->ui_osc_show_path, "%s/show", path);
free((char *)path);
/* At this point a more substantial host might also call
* configure() on the UI to set any state that it had remembered
* for the plugin instance. But we don't remember state for
* plugin instances (see our own configure() implementation in
* osc_configure_handler), and so we have nothing to send except
* the optional project directory. */
if (projectDirectory) {
lo_send(instance->uiTarget, instance->ui_osc_configure_path, "ss",
DSSI_PROJECT_DIRECTORY_KEY, projectDirectory);
}
/* Send current bank/program (-FIX- another race...) */
if (instance->pendingProgramChange < 0) {
unsigned long bank = instance->currentBank;
unsigned long program = instance->currentProgram;
instance->uiNeedsProgramUpdate = 0;
if (instance->uiTarget) {
lo_send(instance->uiTarget, instance->ui_osc_program_path, "ii", bank, program);
}
}
/* Send control ports */
for (i = 0; i < instance->plugin->controlIns; i++) {
int in = i + instance->firstControlIn;
int port = pluginControlInPortNumbers[in];
lo_send(instance->uiTarget, instance->ui_osc_control_path, "if", port,
pluginControlIns[in]);
/* Avoid overloading the GUI if there are lots and lots of ports */
if ((i+1) % 50 == 0) usleep(300000);
}
/* Send 'show' */
if (!instance->ui_initial_show_sent) {
lo_send(instance->uiTarget, instance->ui_osc_show_path, "");
instance->ui_initial_show_sent = 1;
}
return 0;
}
int
osc_exiting_handler(d3h_instance_t *instance, lo_arg **argv)
{
int i;
if (verbose) {
printf("%s: OSC: got exiting notification for instance %d\n", myName,
instance->number);
}
if (instance->uiTarget) {
lo_address_free(instance->uiTarget);
instance->uiTarget = NULL;
}
if (instance->plugin) {
/*!!! No, this isn't safe -- plugins deactivated in this way
would still be included in a run_multiple_synths call unless
we re-jigged the instance array at the same time -- leave it
for now
if (instance->plugin->descriptor->LADSPA_Plugin->deactivate) {
instance->plugin->descriptor->LADSPA_Plugin->deactivate
(instanceHandles[instance->number]);
}
*/
/* Leave this flag though, as we need it to determine when to exit */
instance->inactive = 1;
}
/* Do we have any plugins left running? */
for (i = 0; i < instance_count; ++i) {
if (!instances[i].inactive) return 0;
}
if (verbose) {
printf("%s: That was the last remaining plugin, exiting...\n", myName);
}
exiting = 1;
return 0;
}
int osc_debug_handler(const char *path, const char *types, lo_arg **argv,
int argc, void *data, void *user_data)
{
int i;
printf("%s: got unhandled OSC message:\npath: <%s>\n", myName, path);
for (i=0; i<argc; i++) {
printf("%s: arg %d '%c' ", myName, i, types[i]);
lo_arg_pp(types[i], argv[i]);
printf("\n");
}
printf("%s:\n", myName);
return 1;
}
int osc_message_handler(const char *path, const char *types, lo_arg **argv,
int argc, void *data, void *user_data)
{
int i;
d3h_instance_t *instance = NULL;
const char *method;
if (strncmp(path, "/dssi/", 6))
return osc_debug_handler(path, types, argv, argc, data, user_data);
for (i = 0; i < instance_count; i++) {
if (!strncmp(path + 6, instances[i].friendly_name,
strlen(instances[i].friendly_name))) {
instance = &instances[i];
break;
}
}
if (!instance)
return osc_debug_handler(path, types, argv, argc, data, user_data);
/* no -- see comment in osc_exiting_handler */
/*
if (instance->inactive)
return 0;
*/
method = path + 6 + strlen(instance->friendly_name);
if (*method != '/' || *(method + 1) == 0)
return osc_debug_handler(path, types, argv, argc, data, user_data);
method++;
if (!strcmp(method, "configure") && argc == 2 && !strcmp(types, "ss")) {
return osc_configure_handler(instance, argv);
} else if (!strcmp(method, "control") && argc == 2 && !strcmp(types, "if")) {
return osc_control_handler(instance, argv);
} else if (!strcmp(method, "midi") && argc == 1 && !strcmp(types, "m")) {
return osc_midi_handler(instance, argv);
} else if (!strcmp(method, "program") && argc == 2 && !strcmp(types, "ii")) {
return osc_program_handler(instance, argv);
} else if (!strcmp(method, "update") && argc == 1 && !strcmp(types, "s")) {
return osc_update_handler(instance, argv);
} else if (!strcmp(method, "exiting") && argc == 0) {
return osc_exiting_handler(instance, argv);
}
return osc_debug_handler(path, types, argv, argc, data, user_data);
}