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
|
// ------------------------------------------------------------------------
// eca-control.cpp: Class for controlling the whole ecasound library
// Copyright (C) 1999-2005,2008,2009,2012 Kai Vehmanen
// Copyright (C) 2005 Stuart Allie
// Copyright (C) 2009 Adam Linson
//
// Attributes:
// eca-style-version: 3 (see Ecasound Programmer's Guide)
//
// This program 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 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
// ------------------------------------------------------------------------
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <cassert>
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <unistd.h>
#ifdef HAVE_LOCALE_H
#include <locale.h>
#endif
#include <kvu_utils.h> /* string_to_vector(), string_to_int_vector() */
#include <kvu_value_queue.h>
#include <kvu_message_item.h>
#include <kvu_dbc.h>
#include <kvu_numtostr.h>
#include "audioio.h"
#include "eca-chain.h"
#include "eca-chainop.h"
#include "eca-chainsetup.h"
#include "eca-control.h"
#include "eca-control-main.h"
#include "eca-engine.h"
#include "eca-object-factory.h"
#include "eca-object-map.h"
#include "eca-preset-map.h"
#include "eca-session.h"
#include "generic-controller.h"
#include "eca-chainop.h"
#include "audiofx_ladspa.h"
#include "audiofx_lv2.h"
#include "preset.h"
#include "sample-specs.h"
#include "jack-connections.h"
#include "eca-version.h"
#include "eca-error.h"
#include "eca-logger.h"
#include "eca-logger-wellformed.h"
/**
* Import namespaces
*/
using std::string;
using std::list;
using std::vector;
using std::cerr;
using std::endl;
using namespace ECA;
/**
* Declarations for private static functions
*/
static string eca_aio_register_sub(ECA_OBJECT_MAP& objmap);
/**
* Definitions for member functions
*/
ECA_CONTROL::ECA_CONTROL (ECA_SESSION* psession)
: ctrl_dump_rep(this),
wellformed_mode_rep(false)
{
ECA_LOG_MSG(ECA_LOGGER::system_objects, "ECA_CONTROL constructor");
session_repp = psession;
selected_chainsetup_repp = psession->selected_chainsetup_repp;
engine_repp = 0;
engine_pid_rep = -1;
engine_exited_rep.set(0);
float_to_string_precision_rep = 3;
joining_rep = false;
DBC_CHECK(is_engine_created() != true);
selected_audio_object_repp = 0;
selected_audio_input_repp = 0;
selected_audio_output_repp = 0;
}
ECA_CONTROL::~ECA_CONTROL(void)
{
ECA_LOG_MSG(ECA_LOGGER::system_objects, "ECA_CONTROL destructor");
close_engine();
}
void ECA_CONTROL::fill_command_retval(struct eci_return_value *retval) const
{
if (retval == 0)
return;
*retval = last_retval_rep;
}
void ECA_CONTROL::command(const string& cmd_and_args, struct eci_return_value *retval)
{
clear_last_values();
clear_action_arguments();
ECA_LOG_MSG(ECA_LOGGER::user_objects, "processing cmd and arg: " + cmd_and_args);
vector<string> tokens = kvu_string_to_tokens_quoted(cmd_and_args);
vector<string>::iterator cmd = tokens.begin();
if (cmd != tokens.end()) {
const std::map<std::string,int>& cmdmap = ECA_IAMODE_PARSER::registered_commands();
if (cmdmap.find(*cmd) == cmdmap.end()) {
// ---
// *p is not recognized as a iamode command
// ---
if (cmd->size() > 0 && (*cmd)[0] == '-') {
// std::cerr << "Note! Direct use of EOS-options (-prefix:arg1,...,argN)" << " as iactive-mode commands is considered deprecated. " << "\tUse the notation 'cs-option -prefix:a,b,x' instead." << std::endl;
if (*cmd == "-i")
ECA_LOG_MSG(ECA_LOGGER::info,
"WARNING: syntax variant '-i file.ext' not supported, please use 'ai-add file.ext' instead.");
else if (*cmd == "-o")
ECA_LOG_MSG(ECA_LOGGER::info,
"WARNING: syntax variant '-o file.ext' not supported, please use 'ai-add file.ext' instead.");
else {
ECA_LOG_MSG(ECA_LOGGER::user_objects, "passiong to cs-option: " + cmd_and_args);
chainsetup_option(cmd_and_args);
}
}
else {
set_last_error("Unknown command!");
}
}
else {
int action_id = ECA_IAMODE_PARSER::command_to_action_id(*cmd);
if (action_id == ec_help) {
show_controller_help();
}
else {
vector<string>::iterator args = cmd + 1;
if (args != tokens.end()) {
set_action_argument(vector<string> (args, tokens.end()));
}
action(action_id);
}
}
}
fill_command_retval(retval);
}
void ECA_CONTROL::set_action_argument(const string& s)
{
action_args_rep.resize(0);
action_args_rep.push_back(s);
action_arg_f_set_rep = false;
}
void ECA_CONTROL::set_action_argument(const std::vector<std::string>& s)
{
action_args_rep = s;
action_arg_f_set_rep = false;
}
void ECA_CONTROL::set_action_argument(double v)
{
action_arg_f_rep = v;
action_arg_f_set_rep = true;
}
void ECA_CONTROL::clear_action_arguments(void)
{
// use resize() instead of clear(); clear() was a late
// addition to C++ standard and not supported by all
// compilers (for example egcs-2.91.66)
action_args_rep.resize(0);
action_arg_f_rep = 0.0f;
action_arg_f_set_rep = false;
}
double ECA_CONTROL::first_action_argument_as_float(void) const
{
if (action_arg_f_set_rep == true)
return action_arg_f_rep;
if (action_args_rep.size() == 0)
return 0.0f;
return atof(action_args_rep[0].c_str());
}
string ECA_CONTROL::first_action_argument_as_string(void) const
{
if (action_args_rep.size() == 0)
return std::string();
return action_args_rep[0];
}
const vector<string>& ECA_CONTROL::action_arguments_as_vector(void) const
{
return action_args_rep;
}
int ECA_CONTROL::first_action_argument_as_int(void) const
{
if (action_args_rep.size() == 0)
return 0;
return atoi(action_args_rep[0].c_str());
}
long int ECA_CONTROL::first_action_argument_as_long_int(void) const
{
if (action_args_rep.size() == 0)
return 0;
return atol(action_args_rep[0].c_str());
}
SAMPLE_SPECS::sample_pos_t ECA_CONTROL::first_action_argument_as_samples(void) const
{
if (action_args_rep.size() == 0)
return 0;
#ifdef HAVE_ATOLL
return atoll(action_args_rep[0].c_str());
#else
return atol(action_args_rep[0].c_str());
#endif
}
void ECA_CONTROL::command_float_arg(const string& cmd, double arg, struct eci_return_value *retval)
{
clear_action_arguments();
set_action_argument(arg);
int action_id = ec_unknown;
action_id = ECA_IAMODE_PARSER::command_to_action_id(cmd);
action(action_id);
fill_command_retval(retval);
}
/**
* Interprets an EOS (ecasound optiont syntax) token (prefixed with '-').
*/
void ECA_CONTROL::chainsetup_option(const string& cmd)
{
string prefix = kvu_get_argument_prefix(cmd);
if (prefix == "el" || prefix == "pn") { // --- LADSPA plugins and presets
if (selected_chains().size() == 1)
add_chain_operator(cmd);
else
set_last_error("When adding chain operators, only one chain can be selected.");
}
else if (ECA_OBJECT_FACTORY::chain_operator_map().object(prefix) != 0) {
if (selected_chains().size() == 1)
add_chain_operator(cmd);
else
set_last_error("When adding chain operators, only one chain can be selected.");
}
else if (ECA_OBJECT_FACTORY::controller_map().object(prefix) != 0) {
if (selected_chains().size() == 1)
add_controller(cmd);
else
set_last_error("When adding controllers, only one chain can be selected.");
}
else {
set_action_argument(cmd);
action(ec_cs_option);
}
}
/**
* Checks action preconditions.
*
* @return Sets status of private data members 'action_ok',
* 'action_restart', and 'action_reconnect'.
*/
void ECA_CONTROL::check_action_preconditions(int action_id)
{
action_ok = true;
action_reconnect = false;
action_restart = false;
/* case 1: action requiring arguments, but not arguments available */
if (action_arg_f_set_rep == false &&
first_action_argument_as_string().size() == 0 &&
action_requires_params(action_id)) {
set_last_error("Can't perform requested action; argument omitted.");
action_ok = false;
}
/* case 2: action requires an audio input, but no input available */
else if (is_selected() == true &&
get_audio_input() == 0 &&
action_requires_selected_audio_input(action_id)) {
set_last_error("Can't perform requested action; no audio input selected.");
action_ok = false;
}
/* case 3: action requires an audio output, but no output available */
else if (is_selected() == true &&
get_audio_output() == 0 &&
action_requires_selected_audio_output(action_id)) {
set_last_error("Can't perform requested action; no audio output selected.");
action_ok = false;
}
/* case 4: action requires a select chainsetup, but none selected */
else if (is_selected() == false &&
action_requires_selected(action_id)) {
if (!is_connected()) {
set_last_error("Can't perform requested action; no chainsetup selected.");
action_ok = false;
}
else {
ECA_LOG_MSG(ECA_LOGGER::info, "WARNING: No chainsetup selected. Connected chainsetup will be selected.");
select_chainsetup(connected_chainsetup());
}
}
/* case 5: action requires a connected chainsetup, but none connected */
else if (is_connected() == false &&
action_requires_connected(action_id)) {
if (!is_selected()) {
set_last_error("Can't perform requested action; no chainsetup connected.");
action_ok = false;
}
else {
if (is_valid() == true) {
ECA_LOG_MSG(ECA_LOGGER::info,
"NOTE: No chainsetup connected. Trying to connect currently selected chainsetup \""
+ selected_chainsetup_repp->name()
+ "\"");
connect_chainsetup(0);
}
if (is_connected() != true) {
/* connect_chainsetup() sets last_error() so we just add to it */
set_last_error(last_error() + " Selected chainsetup cannot be connected. Can't perform requested action. ");
action_ok = false;
}
}
}
/* case 6: action can't be performed on a connected setup,
* but selected chainsetup is also connected */
else if (selected_chainsetup() == connected_chainsetup() &&
action_requires_selected_not_connected(action_id)) {
ECA_LOG_MSG(ECA_LOGGER::info, "WARNING: This operation requires that chainsetup is disconnected. Temporarily disconnecting...");
if (is_running()) action_restart = true;
disconnect_chainsetup();
action_reconnect = true;
}
}
void ECA_CONTROL::action(int action_id,
const vector<string>& args)
{
ECA_LOG_MSG(ECA_LOGGER::info, "WARNING: ECA_CONTROL::action() method is obsolete.\n");
clear_action_arguments();
set_action_argument(kvu_vector_to_string(args, " "));
action(action_id);
}
bool ECA_CONTROL::action_helper_check_cop_op_args(int copid, int coppid)
{
DBC_REQUIRE(is_selected() == true);
const vector<string>& selchains =
selected_chainsetup_repp->selected_chains();
bool res = false;
if (selchains.size() == 0) {
set_last_error("No chain selected, unable to identify chainop");
}
else if (selchains.size() > 1) {
set_last_error("More than one chain selected, unable to identify chainop");
}
else {
const CHAIN* selch =
selected_chainsetup_repp->get_chain_with_name(selchains[0]);
if (copid < 1 || copid > selch->number_of_chain_operators()) {
set_last_error("Invalid chainop-id, unable to identify chainop");
}
else if (coppid < 1) {
set_last_error("Invalid copp-id, indexing starts from 1.");
}
else {
res = true;
}
}
return res;
}
void ECA_CONTROL::action(int action_id)
{
clear_last_values();
check_action_preconditions(action_id);
if (action_ok != true) return;
switch(action_id) {
case ec_unknown: { set_last_error("Unknown command!"); break; }
// ---
// General
// ---
case ec_exit: { quit(); break; }
case ec_start:
{
if (is_running() != true) {
int result = start();
if (result < 0) {
set_last_error("Error, unable to start processing");
}
}
// ECA_LOG_MSG(ECA_LOGGER::info, "Can't perform requested action; no chainsetup connected.");
break;
}
case ec_stop: { if (is_engine_created()) stop(); break; }
case ec_stop_sync: { if (is_engine_created()) stop_on_condition(); break; }
case ec_run:
{
int result = run();
if (result < 0) {
set_last_error("Errors during processing");
}
break;
}
case ec_debug:
{
int level = first_action_argument_as_int();
ECA_LOGGER::instance().set_log_level_bitmask(level);
set_last_string("Debug level set to " + kvu_numtostr(level) + ".");
break;
}
case ec_resource_file:
{
session_repp->interpret_general_option(string("-R:") +
first_action_argument_as_string());
break;
}
// ---
// Chainsetups
// ---
case ec_cs_add:
{
add_chainsetup(first_action_argument_as_string());
break;
}
case ec_cs_remove: { remove_chainsetup(); break; }
case ec_cs_list: { set_last_string_list(chainsetup_names()); break; }
case ec_cs_select: { select_chainsetup(first_action_argument_as_string()); break; }
case ec_cs_selected: { set_last_string(selected_chainsetup()); break; }
case ec_cs_index_select: {
if (first_action_argument_as_string().size() > 0) {
select_chainsetup_by_index(first_action_argument_as_int());
}
break;
}
case ec_cs_edit: { edit_chainsetup(); break; }
case ec_cs_load: { load_chainsetup(first_action_argument_as_string()); break; }
case ec_cs_save: { save_chainsetup(""); break; }
case ec_cs_save_as: { save_chainsetup(first_action_argument_as_string()); break; }
case ec_cs_is_valid: {
if (is_valid() == true)
set_last_integer(1);
else
set_last_integer(0);
break;
}
case ec_cs_connect:
{
if (is_valid() != false) {
connect_chainsetup(0);
}
else {
set_last_error("Can't connect; chainsetup not valid!");
}
break;
}
case ec_cs_connected: { set_last_string(connected_chainsetup()); break; }
case ec_cs_disconnect: { disconnect_chainsetup(); break; }
case ec_cs_set_param: { set_chainsetup_parameter(first_action_argument_as_string()); break; }
case ec_cs_set_audio_format: { set_chainsetup_sample_format(first_action_argument_as_string()); break; }
case ec_cs_status: {
set_last_string(chainsetup_status());
break;
}
case ec_cs_rewind: { change_chainsetup_position(-first_action_argument_as_float()); break; }
case ec_cs_forward: { change_chainsetup_position(first_action_argument_as_float()); break; }
case ec_cs_set_position: { set_chainsetup_position(first_action_argument_as_float()); break; }
case ec_cs_set_position_samples: { set_chainsetup_position_samples(first_action_argument_as_samples()); break; }
case ec_cs_get_position: { set_last_float(position_in_seconds_exact()); break; }
case ec_cs_get_position_samples: { set_last_long_integer(selected_chainsetup_repp->position_in_samples()); break; }
case ec_cs_get_length: { set_last_float(length_in_seconds_exact()); break; }
case ec_cs_get_length_samples: { set_last_long_integer(length_in_samples()); break; }
case ec_cs_set_length:
{
set_chainsetup_processing_length_in_seconds(first_action_argument_as_float());
break;
}
case ec_cs_set_length_samples:
{
set_chainsetup_processing_length_in_samples(first_action_argument_as_samples());
break;
}
case ec_cs_toggle_loop: { toggle_chainsetup_looping(); break; }
case ec_cs_option:
{
selected_chainsetup_repp->interpret_options(action_arguments_as_vector());
if (selected_chainsetup_repp->interpret_result() != true) {
set_last_error(selected_chainsetup_repp->interpret_result_verbose());
}
break;
}
// ---
// Chains
// ---
case ec_c_add: { add_chains(kvu_string_to_vector(first_action_argument_as_string(), ',')); break; }
case ec_c_remove: { remove_chains(); break; }
case ec_c_list: { set_last_string_list(chain_names()); break; }
case ec_c_select: { select_chains(kvu_string_to_vector(first_action_argument_as_string(), ',')); break; }
case ec_c_selected: { set_last_string_list(selected_chains()); break; }
case ec_c_index_select: { select_chains_by_index(kvu_string_to_int_vector(first_action_argument_as_string(), ',')); break; }
case ec_c_deselect: { deselect_chains(kvu_string_to_vector(first_action_argument_as_string(), ',')); break; }
case ec_c_select_add:
{
select_chains(kvu_string_to_vector(first_action_argument_as_string() + "," +
kvu_vector_to_string(selected_chains(), ","), ','));
break;
}
case ec_c_select_all: { select_all_chains(); break; }
case ec_c_clear: { clear_chains(); break; }
case ec_c_rename:
{
if (selected_chains().size() != 1) {
set_last_error("When renaming chains, only one chain canbe selected.");
}
else {
rename_chain(first_action_argument_as_string());
}
break;
}
case ec_c_muting: { set_chain_muting(first_action_argument_as_string()); break; }
case ec_c_bypass: { set_chain_bypass(first_action_argument_as_string()); break; }
case ec_c_status:
{
set_last_string(chain_status());
break;
}
case ec_c_is_bypassed: { set_last_integer(chain_is_bypassed()); break; }
case ec_c_is_muted: { set_last_integer(chain_is_muted()); break; }
// ---
// Actions common to audio inputs and outputs
// ---
case ec_aio_status:
case ec_ai_status:
case ec_ao_status:
{
set_last_string(aio_status());
break;
}
case ec_aio_register: { aio_register(); break; }
// ---
// Audio input objects
// ---
case ec_ai_add: { add_audio_input(first_action_argument_as_string()); break; }
case ec_ai_describe: { set_last_string(ECA_OBJECT_FACTORY::audio_object_to_eos(selected_audio_input_repp, "i")); break; }
case ec_ai_remove: { remove_audio_input(); break; }
case ec_ai_list: { set_last_string_list(audio_input_names()); break; }
case ec_ai_select: { select_audio_input(first_action_argument_as_string()); break; }
case ec_ai_selected: { set_last_string(get_audio_input()->label()); break; }
case ec_ai_index_select: {
if (first_action_argument_as_string().size() > 0) {
select_audio_input_by_index(first_action_argument_as_int());
}
break;
}
case ec_ai_attach: { attach_audio_input(); break; }
case ec_ai_forward:
{
audio_input_as_selected();
forward_audio_object(first_action_argument_as_float());
break;
}
case ec_ai_rewind:
{
audio_input_as_selected();
rewind_audio_object(first_action_argument_as_float());
break;
}
case ec_ai_set_position: { audio_input_as_selected(); set_audio_object_position(first_action_argument_as_float()); break; }
case ec_ai_set_position_samples: { audio_input_as_selected(); set_audio_object_position_samples(first_action_argument_as_long_int()); break; }
case ec_ai_get_position: { set_last_float(get_audio_input()->position().seconds()); break; }
case ec_ai_get_position_samples: { set_last_long_integer(get_audio_input()->position().samples()); break; }
case ec_ai_get_length: { set_last_float(get_audio_input()->length().seconds()); break; }
case ec_ai_get_length_samples: { set_last_long_integer(get_audio_input()->length().samples()); break; }
case ec_ai_get_format: {
set_last_string(get_audio_input()->format_string() + "," +
kvu_numtostr(get_audio_input()->channels()) + "," +
kvu_numtostr(get_audio_input()->samples_per_second()));
break;
}
case ec_ai_wave_edit: { audio_input_as_selected(); wave_edit_audio_object(); break; }
// ---
// Audio output objects
// ---
case ec_ao_add: { if (first_action_argument_as_string().size() == 0) add_default_output(); else add_audio_output(first_action_argument_as_string()); break; }
case ec_ao_add_default: { add_default_output(); break; }
case ec_ao_describe: { set_last_string(ECA_OBJECT_FACTORY::audio_object_to_eos(selected_audio_output_repp, "o")); break; }
case ec_ao_remove: { remove_audio_output(); break; }
case ec_ao_list: { set_last_string_list(audio_output_names()); break; }
case ec_ao_select: { select_audio_output(first_action_argument_as_string()); break; }
case ec_ao_selected: { set_last_string(get_audio_output()->label()); break; }
case ec_ao_index_select: {
select_audio_output_by_index(first_action_argument_as_int());
break;
}
case ec_ao_attach: { attach_audio_output(); break; }
case ec_ao_forward:
{
audio_output_as_selected();
forward_audio_object(first_action_argument_as_float());
break;
}
case ec_ao_rewind:
{
audio_output_as_selected();
rewind_audio_object(first_action_argument_as_float());
break;
}
case ec_ao_set_position: { audio_output_as_selected(); set_audio_object_position(first_action_argument_as_float()); break; }
case ec_ao_set_position_samples: { audio_output_as_selected(); set_audio_object_position_samples(first_action_argument_as_long_int()); break; }
case ec_ao_get_position: { set_last_float(get_audio_output()->position().seconds()); break; }
case ec_ao_get_position_samples: { set_last_long_integer(get_audio_output()->position().samples()); break; }
case ec_ao_get_length: { set_last_float(get_audio_output()->length().seconds()); break; }
case ec_ao_get_length_samples: { set_last_long_integer(get_audio_output()->length().samples()); break; }
case ec_ao_get_format: {
set_last_string(get_audio_output()->format_string() + "," +
kvu_numtostr(get_audio_output()->channels()) + "," +
kvu_numtostr(get_audio_output()->samples_per_second()));
break;
}
case ec_ao_wave_edit: { audio_output_as_selected(); wave_edit_audio_object(); break; }
// ---
// Chain operators
// ---
case ec_cop_add: { add_chain_operator(first_action_argument_as_string()); break; }
case ec_cop_bypass: { bypass_chain_operator(first_action_argument_as_string()); break; }
case ec_cop_describe:
{
const CHAIN_OPERATOR *t = get_chain_operator();
set_last_string(t == 0 ? "" : ECA_OBJECT_FACTORY::chain_operator_to_eos(t));
break;
}
case ec_cop_remove: { remove_chain_operator(); break; }
case ec_cop_list: { set_last_string_list(chain_operator_names()); break; }
case ec_cop_is_bypassed: { set_last_integer(chain_operator_is_bypassed()); break; }
case ec_cop_select: { select_chain_operator(first_action_argument_as_int()); break; }
case ec_cop_selected: { set_last_integer(selected_chain_operator()); break; }
case ec_cop_set:
{
vector<string> a = kvu_string_to_vector(first_action_argument_as_string(), ',');
if (a.size() < 3) {
set_last_error("Not enough parameters!");
break;
}
int id1 = atoi(a[0].c_str());
int id2 = atoi(a[1].c_str());
CHAIN_OPERATOR::parameter_t v = atof(a[2].c_str());
bool valid =
action_helper_check_cop_op_args(id1, id2);
if (valid == true) {
select_chain_operator(id1);
select_chain_operator_parameter(id2);
set_chain_operator_parameter(v);
}
// note: helper func sets the error string if needed
break;
}
case ec_cop_get:
{
vector<string> a =
kvu_string_to_vector(first_action_argument_as_string(), ',');
if (a.size() < 2) {
set_last_error("Not enough parameters!");
break;
}
int id1 = atoi(a[0].c_str());
int id2 = atoi(a[1].c_str());
bool valid =
action_helper_check_cop_op_args(id1, id2);
if (valid == true) {
select_chain_operator(id1);
select_chain_operator_parameter(id2);
set_last_float(get_chain_operator_parameter());
}
// note: helper func sets the error string if needed
break;
}
case ec_cop_status:
{
set_last_string(chain_operator_status());
break;
}
// ---
// Chain operator parameters
// ---
case ec_copp_list: { set_last_string_list(chain_operator_parameter_names()); break; }
case ec_copp_select: { select_chain_operator_parameter(first_action_argument_as_int()); break; }
case ec_copp_selected: { set_last_integer(selected_chain_operator_parameter()); break; }
case ec_copp_set: { set_chain_operator_parameter(first_action_argument_as_float()); break; }
case ec_copp_get: { set_last_float(get_chain_operator_parameter()); break; }
// ---
// Controllers
// ---
case ec_ctrl_add: { add_controller(first_action_argument_as_string()); break; }
case ec_ctrl_describe:
{
const GENERIC_CONTROLLER *t = get_controller();
set_last_string(t == 0 ? "" : ECA_OBJECT_FACTORY::controller_to_eos(t));
break;
}
case ec_ctrl_remove: { remove_controller(); break; }
case ec_ctrl_list: { set_last_string_list(controller_names()); break; }
case ec_ctrl_select: { select_controller(first_action_argument_as_int()); break; }
case ec_ctrl_selected: { set_last_integer(selected_controller()); break; }
case ec_ctrl_status:
{
set_last_string(controller_status());
break;
}
case ec_ctrl_get_target: { set_last_integer(selected_controller_target()); break; }
// ---
// Controller parameters
// ---
case ec_ctrlp_list: { set_last_string_list(controller_parameter_names()); break; }
case ec_ctrlp_select: { select_controller_parameter(first_action_argument_as_int()); break; }
case ec_ctrlp_selected: { set_last_integer(selected_controller_parameter()); break; }
case ec_ctrlp_get: { set_last_float(get_controller_parameter()); break; }
case ec_ctrlp_set: { set_controller_parameter(first_action_argument_as_float()); break; }
case ec_cop_register: { cop_register(); break; }
case ec_preset_register: { preset_register(); break; }
case ec_ladspa_register: { ladspa_register(); break; }
case ec_lv2_register: { lv2_register(); break; }
case ec_ctrl_register: { ctrl_register(); break; }
case ec_map_cop_list: { cop_descriptions(); break; }
case ec_map_preset_list: { preset_descriptions(); break; }
case ec_map_ladspa_list: { ladspa_descriptions(false); break; }
case ec_map_ladspa_id_list: { ladspa_descriptions(true); break; }
case ec_map_lv2_list: { lv2_descriptions(); break; }
case ec_map_ctrl_list: { ctrl_descriptions(); break; }
// ---
// Engine commands
// ---
case ec_engine_launch: {
if (is_engine_ready_for_commands() != true)
engine_start();
else
set_last_error("Engine already running, use 'engine-halt' first.");
break;
}
case ec_engine_halt: {
if (is_engine_ready_for_commands() == true)
close_engine();
else
set_last_error("Engine not running, use 'engine-launch' first.");
break;
}
case ec_engine_status: { set_last_string(engine_status()); break; }
// ---
// Internal commands
// ---
case ec_int_cmd_list: { set_last_string_list(registered_commands_list()); break; }
case ec_int_log_history: { set_last_string(ECA_LOGGER::instance().log_history()); break; }
case ec_int_output_mode_wellformed: {
ECA_LOGGER::attach_logger(new ECA_LOGGER_WELLFORMED());
wellformed_mode_rep = true;
break;
}
case ec_int_set_float_to_string_precision: { set_float_to_string_precision(first_action_argument_as_int()); break; }
case ec_int_set_log_history_length: { ECA_LOGGER::instance().set_log_history_length(first_action_argument_as_int()); break; }
case ec_int_version_string: { set_last_string(ecasound_library_version); break; }
case ec_int_version_lib_current: { set_last_integer(ecasound_library_version_current); break; }
case ec_int_version_lib_revision: { set_last_integer(ecasound_library_version_revision); break; }
case ec_int_version_lib_age: { set_last_integer(ecasound_library_version_age); break; }
// ---
// Dump commands
// ---
case ec_dump_target: { ctrl_dump_rep.set_dump_target(first_action_argument_as_string()); break; }
case ec_dump_status: { ctrl_dump_rep.dump_status(); break; }
case ec_dump_position: { ctrl_dump_rep.dump_position(); break; }
case ec_dump_length: { ctrl_dump_rep.dump_length(); break; }
case ec_dump_cs_status: { ctrl_dump_rep.dump_chainsetup_status(); break; }
case ec_dump_c_selected: { ctrl_dump_rep.dump_selected_chain(); break; }
case ec_dump_ai_selected: { ctrl_dump_rep.dump_selected_audio_input(); break; }
case ec_dump_ai_position: { ctrl_dump_rep.dump_audio_input_position(); break; }
case ec_dump_ai_length: { ctrl_dump_rep.dump_audio_input_length(); break; }
case ec_dump_ai_open_state: { ctrl_dump_rep.dump_audio_input_open_state(); break; }
case ec_dump_ao_selected: { ctrl_dump_rep.dump_selected_audio_output(); break; }
case ec_dump_ao_position: { ctrl_dump_rep.dump_audio_output_position(); break; }
case ec_dump_ao_length: { ctrl_dump_rep.dump_audio_output_length(); break; }
case ec_dump_ao_open_state: { ctrl_dump_rep.dump_audio_output_open_state(); break; }
case ec_dump_cop_value:
{
vector<string> temp = kvu_string_to_vector(first_action_argument_as_string(), ',');
if (temp.size() > 1) {
ctrl_dump_rep.dump_chain_operator_value(atoi(temp[0].c_str()),
atoi(temp[1].c_str()));
}
break;
}
// ---
// Commands with external dependencies
// ---
#if ECA_COMPILE_JACK
case ec_jack_connect:
{
const vector<string>& params = action_arguments_as_vector();
if (params.size() >= 2)
JACK_CONNECTIONS::connect(params[0].c_str(), params[1].c_str());
break;
}
case ec_jack_disconnect:
{
const vector<string>& params = action_arguments_as_vector();
if (params.size() >= 2)
JACK_CONNECTIONS::disconnect(params[0].c_str(), params[1].c_str());
break;
}
case ec_jack_list_connections:
{
string foo;
if (JACK_CONNECTIONS::list_connections(&foo) == true)
set_last_string(foo);
else
set_last_error("Unable to a list of JACK connections.");
break;
}
#endif
} // <-- switch-case
if (action_reconnect == true) {
if (is_selected() == false ||
is_valid() == false) {
set_last_error("Can't reconnect chainsetup.");
}
else {
connect_chainsetup(0);
if (selected_chainsetup() != connected_chainsetup()) {
set_last_error("Can't reconnect chainsetup.");
}
else {
if (action_restart == true) {
DBC_CHECK(is_running() != true);
start();
}
}
}
}
}
/**
* Executes chainsetup edit on connect chainsetup.
*
* @pre is_connected()
*/
bool ECA_CONTROL::execute_edit_on_connected(const chainsetup_edit_t& edit)
{
DBC_REQUIRE(is_connected() == true);
bool retval = false;
if (is_engine_ready_for_commands() == true) {
ECA_ENGINE::complex_command_t engine_cmd;
engine_cmd.type = ECA_ENGINE::ep_exec_edit;
engine_cmd.cs = edit;
engine_repp->command(engine_cmd);
retval = true;
}
else {
/* note: engine not yet running, execute edit directly */
retval = session_repp->connected_chainsetup_repp->execute_edit(edit);
}
return retval;
}
/**
* Executes chainsetup edit on selected chainsetup.
*
* @param edit object specifying the edit action
* @param index if non-negative, override the chainsetup selection
*/
bool ECA_CONTROL::execute_edit_on_selected(const chainsetup_edit_t& edit, int index)
{
bool retval = false;
ECA_CHAINSETUP *csetup = 0;
if (index < 0) {
csetup = selected_chainsetup_repp;
}
else {
if (index >= 0 &&
index < static_cast<int>(session_repp->chainsetups_rep.size())) {
csetup = session_repp->chainsetups_rep[index];
}
}
/* note: make sure that if the selected chainsetup is
* in use by the engine, the edit is performed
* by the engine thread!
*/
if (csetup != 0) {
if (csetup->is_enabled() == true &&
is_engine_ready_for_commands() == true) {
execute_edit_on_connected(edit);
}
else {
csetup->execute_edit(edit);
}
}
return retval;
}
void ECA_CONTROL::print_last_value(struct eci_return_value *retval) const
{
std::string result;
if (retval->type == eci_return_value::retval_error) {
result += "ERROR: ";
}
result += ECA_CONTROL_MAIN::return_value_to_string(retval);
if (wellformed_mode_rep != true) {
if (result.size() > 0)
ECA_LOG_MSG(ECA_LOGGER::eiam_return_values, result);
}
else {
/* in wellformed-output-mode we always create return output */
ECA_LOG_MSG(ECA_LOGGER::eiam_return_values,
std::string(return_value_type_to_string(retval)) +
" " + result);
}
}
string ECA_CONTROL::chainsetup_details_to_string(const ECA_CHAINSETUP* cs) const
{
string result;
vector<CHAIN*>::const_iterator chain_citer;
result += "\n -> Objects..: " + kvu_numtostr(cs->inputs.size());
result += " inputs, " + kvu_numtostr(cs->outputs.size());
result += " outputs, " + kvu_numtostr(cs->chains.size());
result += " chains";
// FIXME: add explanations on why the chainsetup cannot be
// connected
result += "\n -> State....: ";
if (cs->is_locked()) {
result += "connected to engine (engine status: ";
result += engine_status() + ")";
}
else if (cs->is_enabled() && is_engine_created() == true) {
result += "connected (engine status: ";
result += engine_status() + ")";
}
else if (cs->is_enabled())
result += "connected (engine not yet running)";
else if (cs->is_valid())
result += "valid (can be connected)";
else
result += "not valid (cannot be connected)";
result += "\n -> Position.: ";
result += kvu_numtostr(cs->position_in_seconds_exact(), 3);
result += " / ";
if (cs->length_set())
result += kvu_numtostr(cs->length_in_seconds_exact(), 3);
else
result += "inf";
result += "\n -> Options..: ";
result += cs->options_to_string();
for(chain_citer = cs->chains.begin();
chain_citer != cs->chains.end();) {
result += "\n -> Chain \"" + (*chain_citer)->name() + "\": ";
int idx =
(*chain_citer)->connected_input();
if (idx >= 0)
result += ECA_OBJECT_FACTORY::audio_object_to_eos(cs->inputs[idx], "i");
result += " ";
result += (*chain_citer)->to_string();
idx = (*chain_citer)->connected_output();
if (idx >= 0)
result += ECA_OBJECT_FACTORY::audio_object_to_eos(cs->outputs[idx], "o");
++chain_citer;
}
return result;
}
string ECA_CONTROL::chainsetup_status(void) const
{
vector<ECA_CHAINSETUP*>::const_iterator cs_citer = session_repp->chainsetups_rep.begin();
int index = 0;
string result ("### Chainsetup status ###\n");
while(cs_citer != session_repp->chainsetups_rep.end()) {
result += "Chainsetup (" + kvu_numtostr(++index) + ") \"";
result += (*cs_citer)->name() + "\" ";
if (*cs_citer ==
selected_chainsetup_repp)
result += "[selected] ";
if (*cs_citer ==
session_repp->connected_chainsetup_repp)
result += "[connected] ";
if ((*cs_citer == selected_chainsetup_repp) ||
(*cs_citer == session_repp->connected_chainsetup_repp))
result += chainsetup_details_to_string((*cs_citer));
else
result += ": <detailed status omitted -- set as selected to see full status>";
++cs_citer;
if (cs_citer != session_repp->chainsetups_rep.end()) result += "\n";
}
return result;
}
string ECA_CONTROL::chain_status(void) const
{
// --------
DBC_REQUIRE(is_selected() == true);
// --------
MESSAGE_ITEM mitem;
vector<CHAIN*>::const_iterator chain_citer;
const vector<string>& schains = selected_chainsetup_repp->selected_chains();
mitem << "### Chain status (chainsetup '"
<< selected_chainsetup()
<< "') ###\n";
for(chain_citer = selected_chainsetup_repp->chains.begin(); chain_citer != selected_chainsetup_repp->chains.end();) {
mitem << "Chain \"" << (*chain_citer)->name() << "\" ";
if ((*chain_citer)->is_muted()) mitem << "[muted] ";
if ((*chain_citer)->is_bypassed()) mitem << "[bypassed] ";
if (find(schains.begin(), schains.end(), (*chain_citer)->name()) != schains.end()) mitem << "[selected] ";
for(int n = 0; n < (*chain_citer)->number_of_chain_operators(); n++) {
mitem << "\"" << (*chain_citer)->get_chain_operator(n)->name() << "\"";
if (n == (*chain_citer)->number_of_chain_operators()) mitem << " -> ";
}
++chain_citer;
if (chain_citer != selected_chainsetup_repp->chains.end()) mitem << "\n";
}
return mitem.to_string();
}
string ECA_CONTROL::chain_operator_status(void) const
{
// --------
DBC_REQUIRE(is_selected() == true);
// --------
MESSAGE_ITEM msg;
string st_info_string;
vector<CHAIN*>::const_iterator chain_citer = selected_chainsetup_repp->chains.begin();
msg << "### Chain operator status (chainsetup '"
<< selected_chainsetup()
<< "') ###\n";
while(chain_citer != selected_chainsetup_repp->chains.end()) {
msg << "Chain \"" << (*chain_citer)->name() << "\":\n";
for(int p = 0; p < (*chain_citer)->number_of_chain_operators(); p++) {
const CHAIN_OPERATOR* cop = (*chain_citer)->get_chain_operator(p);
msg << "\t";
msg << p + 1 << ". ";
msg << cop->name();
if ((*chain_citer)->is_operator_bypassed(p + 1))
msg << " (BYPASSED)";
for(int n = 0; n < cop->number_of_params(); n++) {
if (n == 0) msg << ": ";
msg << "[" << n + 1 << "] ";
msg << cop->get_parameter_name(n + 1);
msg << " ";
msg << float_to_string(cop->get_parameter(n + 1));
if (n + 1 < cop->number_of_params()) msg << ", ";
}
st_info_string = cop->status();
if (st_info_string.empty() == false) {
msg << "\n\tStatus info:\n" << st_info_string;
}
if (p + 1 < (*chain_citer)->number_of_chain_operators()) msg << "\n";
}
++chain_citer;
if (chain_citer != selected_chainsetup_repp->chains.end()) msg << "\n";
}
return msg.to_string();
}
string ECA_CONTROL::controller_status(void) const
{
// --------
DBC_REQUIRE(is_selected() == true);
// --------
MESSAGE_ITEM mitem;
string st_info_string;
vector<CHAIN*>::const_iterator chain_citer;
mitem << "### Controller status (chainsetup '"
<< selected_chainsetup()
<< "') ###\n";
for(chain_citer = selected_chainsetup_repp->chains.begin(); chain_citer != selected_chainsetup_repp->chains.end();) {
mitem << "Chain \"" << (*chain_citer)->name() << "\":\n";
for(int p = 0; p < (*chain_citer)->number_of_controllers(); p++) {
const GENERIC_CONTROLLER* gtrl = (*chain_citer)->get_controller(p);
mitem << "\t" << p + 1 << ". " << gtrl->name() << ": ";
for(int n = 0; n < gtrl->number_of_params(); n++) {
mitem << "\n\t\t[" << n + 1 << "] ";
mitem << gtrl->get_parameter_name(n + 1);
mitem << " ";
mitem << float_to_string(gtrl->get_parameter(n + 1));
if (n + 1 < gtrl->number_of_params()) mitem << ", ";
}
st_info_string = gtrl->status();
if (st_info_string.empty() == false) {
mitem << "\n\t -- Status info: " << st_info_string;
}
if (p + 1 < (*chain_citer)->number_of_controllers()) mitem << "\n";
}
++chain_citer;
if (chain_citer != selected_chainsetup_repp->chains.end()) mitem << "\n";
}
return mitem.to_string();
}
string ECA_CONTROL::aio_status(void) const
{
// --------
DBC_REQUIRE(is_selected() == true);
// --------
string st_info_string;
vector<AUDIO_IO*>::size_type adev_sizet = 0;
vector<AUDIO_IO*>::const_iterator adev_citer = selected_chainsetup_repp->inputs.begin();
st_info_string += "### Audio input/output status (chainsetup '" +
selected_chainsetup() + "') ###\n";
while(adev_citer != selected_chainsetup_repp->inputs.end()) {
st_info_string += "Input (" + kvu_numtostr(adev_sizet + 1) + "): \"";
for(int n = 0; n < (*adev_citer)->number_of_params(); n++) {
st_info_string += (*adev_citer)->get_parameter(n + 1);
if (n + 1 < (*adev_citer)->number_of_params()) st_info_string += ",";
}
st_info_string += "\" - [" + (*adev_citer)->name() + "]";
if ((*adev_citer) == selected_audio_input_repp) st_info_string += " [selected]";
st_info_string += "\n -> connected to chains \"";
vector<string> temp = selected_chainsetup_repp->get_attached_chains_to_input((selected_chainsetup_repp->inputs)[adev_sizet]);
vector<string>::const_iterator p = temp.begin();
while (p != temp.end()) {
st_info_string += *p;
++p;
if (p != temp.end()) st_info_string += ",";
}
st_info_string += "\": " + (*adev_citer)->status() + "\n";
++adev_sizet;
++adev_citer;
}
adev_sizet = 0;
adev_citer = selected_chainsetup_repp->outputs.begin();
while(adev_citer != selected_chainsetup_repp->outputs.end()) {
st_info_string += "Output (" + kvu_numtostr(adev_sizet + 1) + "): \"";
for(int n = 0; n < (*adev_citer)->number_of_params(); n++) {
st_info_string += (*adev_citer)->get_parameter(n + 1);
if (n + 1 < (*adev_citer)->number_of_params()) st_info_string += ",";
}
st_info_string += "\" - [" + (*adev_citer)->name() + "]";
if ((*adev_citer) == selected_audio_output_repp) st_info_string += " [selected]";
st_info_string += "\n -> connected to chains \"";
vector<string> temp = selected_chainsetup_repp->get_attached_chains_to_output((selected_chainsetup_repp->outputs)[adev_sizet]);
vector<string>::const_iterator p = temp.begin();
while (p != temp.end()) {
st_info_string += *p;
++p;
if (p != temp.end()) st_info_string += ",";
}
st_info_string += "\": ";
st_info_string += (*adev_citer)->status();
++adev_sizet;
++adev_citer;
if (adev_sizet < selected_chainsetup_repp->outputs.size()) st_info_string += "\n";
}
return st_info_string;
}
void ECA_CONTROL::aio_register(void)
{
ECA_LOG_MSG(ECA_LOGGER::info, "Registered audio object types:\n");
string result (eca_aio_register_sub(ECA_OBJECT_FACTORY::audio_io_nonrt_map()));
result += "\n";
result += eca_aio_register_sub(ECA_OBJECT_FACTORY::audio_io_rt_map());
set_last_string(result);
}
static string eca_aio_register_sub(ECA_OBJECT_MAP& objmap)
{
string result;
const list<string>& objlist = objmap.registered_objects();
list<string>::const_iterator p = objlist.begin();
int count = 1;
while(p != objlist.end()) {
string temp;
const AUDIO_IO* q = dynamic_cast<const AUDIO_IO*>(objmap.object_expr(*p));
DBC_CHECK(q != 0);
if (q != 0) {
int params = q->number_of_params();
if (params > 0) {
temp += ": ";
for(int n = 0; n < params; n++) {
temp += q->get_parameter_name(n + 1);
if (n + 1 < params) temp += ",";
}
}
result += kvu_numtostr(count) + ". " + q->name() + ", regex: " +
objmap.keyword_to_expr(*p) + ", params" + temp;
result += "\n";
++count;
}
// else std::cerr << "Failed obj: " << *p << "." << std::endl;
++p;
}
return result;
}
void ECA_CONTROL::cop_register(void)
{
ECA_LOG_MSG(ECA_LOGGER::info, "Registered chain operators:\n");
string result;
const list<string>& objlist = ECA_OBJECT_FACTORY::chain_operator_map().registered_objects();
list<string>::const_iterator p = objlist.begin();
int count = 1;
while(p != objlist.end()) {
string temp;
const CHAIN_OPERATOR* q = dynamic_cast<const CHAIN_OPERATOR*>(ECA_OBJECT_FACTORY::chain_operator_map().object(*p));
if (q != 0) {
int params = q->number_of_params();
for(int n = 0; n < params; n++) {
if (n == 0) temp += ":";
temp += q->get_parameter_name(n + 1);
if (n + 1 < params) temp += ",";
}
result += kvu_numtostr(count) + ". " + q->name() + ", -" + *p + temp;
result += "\n";
++count;
}
++p;
}
set_last_string(result);
}
void ECA_CONTROL::preset_register(void)
{
ECA_LOG_MSG(ECA_LOGGER::info, "Registered effect presets:\n");
string result;
#ifndef ECA_DISABLE_EFFECTS
const list<string>& objlist = ECA_OBJECT_FACTORY::preset_map().registered_objects();
list<string>::const_iterator p = objlist.begin();
int count = 1;
while(p != objlist.end()) {
string temp;
const PRESET* q = dynamic_cast<const PRESET*>(ECA_OBJECT_FACTORY::preset_map().object(*p));
if (q != 0) {
int params = q->number_of_params();
for(int n = 0; n < params; n++) {
if (n == 0) temp += ":";
temp += q->get_parameter_name(n + 1);
if (n + 1 < params) temp += ",";
}
result += kvu_numtostr(count) + ". " + q->name() + ", -pn:" + *p + temp;
result += "\n";
++count;
}
++p;
}
#endif
set_last_string(result);
}
void ECA_CONTROL::ladspa_register(void)
{
ECA_LOG_MSG(ECA_LOGGER::info, "Registered LADSPA plugins:\n");
string result;
#ifndef ECA_DISABLE_EFFECTS
const list<string>& objlist = ECA_OBJECT_FACTORY::ladspa_plugin_map().registered_objects();
list<string>::const_iterator p = objlist.begin();
int count = 1;
while(p != objlist.end()) {
const EFFECT_LADSPA* q = dynamic_cast<const EFFECT_LADSPA*>(ECA_OBJECT_FACTORY::ladspa_plugin_map().object(*p));
if (q != 0) {
string temp = "\n\t-el:" + q->unique() + ",";
int params = q->number_of_params();
for(int n = 0; n < params; n++) {
temp += "'" + q->get_parameter_name(n + 1) + "'";
if (n + 1 < params) temp += ",";
}
result += kvu_numtostr(count) + ". " + q->name() + "" + temp;
result += "\n";
++count;
}
++p;
}
#endif
set_last_string(result);
}
void ECA_CONTROL::lv2_register(void)
{
ECA_LOG_MSG(ECA_LOGGER::info, "Registered LV2 plugins:\n");
string result;
#if !defined(ECA_DISABLE_EFFECTS) && defined(ECA_USE_LIBLILV)
const list<string>& objlist = ECA_OBJECT_FACTORY::lv2_plugin_map().registered_objects();
list<string>::const_iterator p = objlist.begin();
int count = 1;
while(p != objlist.end()) {
const EFFECT_LV2* q = dynamic_cast<const EFFECT_LV2*>(ECA_OBJECT_FACTORY::lv2_plugin_map().object(*p));
if (q != 0) {
string temp = "\n\t-elv2:" + q->unique() + ",";
int params = q->number_of_params();
for(int n = 0; n < params; n++) {
temp += "'" + q->get_parameter_name(n + 1) + "'";
if (n + 1 < params) temp += ",";
}
result += kvu_numtostr(count) + ". " + q->name() + "" + temp;
result += "\n";
++count;
}
++p;
}
#endif
set_last_string(result);
}
void ECA_CONTROL::ctrl_register(void)
{
ECA_LOG_MSG(ECA_LOGGER::info, "Registered controllers:\n");
string result;
const list<string>& objlist = ECA_OBJECT_FACTORY::controller_map().registered_objects();
list<string>::const_iterator p = objlist.begin();
int count = 1;
while(p != objlist.end()) {
string temp;
const GENERIC_CONTROLLER* q = dynamic_cast<const GENERIC_CONTROLLER*>(ECA_OBJECT_FACTORY::controller_map().object(*p));
if (q != 0) {
int params = q->number_of_params();
for(int n = 0; n < params; n++) {
if (n == 0) temp += ":";
temp += q->get_parameter_name(n + 1);
if (n + 1 < params) temp += ",";
}
result += kvu_numtostr(count) + ". " + q->name() + ", -" + *p +
temp;
result += "\n";
++count;
}
++p;
}
set_last_string(result);
}
/**
* Print description of all chain operators and
* their parameters.
*/
void ECA_CONTROL::operator_descriptions_helper(const ECA_OBJECT_MAP& arg, string* result)
{
/* switch to "C" locale to avoid strange floating point
* presentations that could break the output format
* (for example "a,b" insteof of "a.b" */
#if defined(HAVE_LOCALE_H) && defined(HAVE_SETLOCALE)
string old_locale (setlocale(LC_ALL, "C"));
#endif
const list<string>& objlist = arg.registered_objects();
list<string>::const_iterator p = objlist.begin();
int count = 1;
while(p != objlist.end()) {
string temp;
const OPERATOR* q = dynamic_cast<const OPERATOR*>(arg.object(*p));
if (q != 0) {
/* FIXME: prefer backslash escaped over '_' to handle commas */
/* 1. keyword */
*result += kvu_string_search_and_replace(*p, ',', '_');
/* 2. name */
*result += "," + kvu_string_search_and_replace(q->name(), ',', '_');
/* 3. description */
*result += "," + kvu_string_search_and_replace(q->description(), ',', '_');
int params = q->number_of_params();
/* 4. number of params */
*result += "," + kvu_numtostr(params);
/* 5. description of params (for all params) */
for(int n = 0; n < params; n++) {
struct OPERATOR::PARAM_DESCRIPTION pd;
q->parameter_description(n + 1, &pd);
/* 5.1 name of param */
*result += "," + kvu_string_search_and_replace(q->get_parameter_name(n + 1), ',', '_');
/* 5.2 description */
*result += "," + kvu_string_search_and_replace(pd.description, ',', '_');
/* 5.3 default value */
*result += "," + float_to_string(pd.default_value);
/* 5.4 is bounded above (1=yes, 0=no) */
*result += ",above=" + kvu_numtostr(static_cast<int>(pd.bounded_above));
/* 5.5 upper bound */
*result += ",upper=" + float_to_string(pd.upper_bound);
/* 5.6 is bounded below (1=yes, 0=no) */
*result += ",below=" + kvu_numtostr(static_cast<int>(pd.bounded_below));
/* 5.7 lower bound */
*result += ",lower=" + float_to_string(pd.lower_bound);
/* 5.8. is toggled (1=yes, 0=no) */
*result += "," + kvu_numtostr(static_cast<int>(pd.toggled));
/* 5.9. is integer value (1=yes, 0=no) */
*result += "," + kvu_numtostr(static_cast<int>(pd.integer));
/* 5.10. is logarithmis value (1=yes, 0=no) */
*result += "," + kvu_numtostr(static_cast<int>(pd.logarithmic));
/* 5.11. is output value (1=yes, 0=no) */
*result += ",output=" + kvu_numtostr(static_cast<int>(pd.output));
}
*result += "\n";
++count;
}
++p;
}
/* see above */
#if defined(HAVE_LOCALE_H) && defined(HAVE_SETLOCALE)
setlocale(LC_ALL, old_locale.c_str());
#endif
}
/**
* Print the description of all chain operators and
* their parameters.
*/
void ECA_CONTROL::cop_descriptions(void)
{
string result;
operator_descriptions_helper(ECA_OBJECT_FACTORY::chain_operator_map(), &result);
set_last_string(result);
}
/**
* Prints the description of all effect presets and
* their parameters.
*/
void ECA_CONTROL::preset_descriptions(void)
{
string result;
operator_descriptions_helper(ECA_OBJECT_FACTORY::preset_map(), &result);
set_last_string(result);
}
/**
* Prints the description of all LADSPA plugins and
* their parameters.
*/
void ECA_CONTROL::ladspa_descriptions(bool use_id)
{
string result;
if (use_id) {
operator_descriptions_helper(ECA_OBJECT_FACTORY::ladspa_plugin_id_map(), &result);
}
else {
operator_descriptions_helper(ECA_OBJECT_FACTORY::ladspa_plugin_map(), &result);
}
set_last_string(result);
}
/**
* Prints the description of all LV2 plugins and
* their parameters.
*/
void ECA_CONTROL::lv2_descriptions()
{
string result;
operator_descriptions_helper(ECA_OBJECT_FACTORY::lv2_plugin_map(), &result);
set_last_string(result);
}
/**
* Print the description of all controllers and
* their parameters.
*/
void ECA_CONTROL::ctrl_descriptions(void)
{
string result;
operator_descriptions_helper(ECA_OBJECT_FACTORY::controller_map(), &result);
set_last_string(result);
}
|