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
|
// ------------------------------------------------------------------------
// eca-chain.cpp: Class representing an abstract audio signal chain.
// Copyright (C) 1999-2009 Kai Vehmanen
// Copyright (C) 2005 Stuart Allie
//
// 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 <cctype>
#include <string>
#include <vector>
#include <unistd.h>
#include <kvu_message_item.h>
#include <kvu_numtostr.h>
#include <kvu_dbc.h>
#include "samplebuffer.h"
#include "generic-controller.h"
#include "eca-chainop.h"
#include "audioio.h"
#include "file-preset.h"
#include "global-preset.h"
#include "audiofx_ladspa.h"
#include "eca-object-factory.h"
#include "eca-object-map.h"
#include "eca-preset-map.h"
#include "eca-chain.h"
#include "eca-chainop.h"
#include "eca-error.h"
#include "eca-logger.h"
/* Debug controller source values */
// #define DEBUG_CONTROLLERS
#ifdef DEBUG_CONTROLLERS
#define DEBUG_CTRL_STATEMENT(x) x
#else
#define DEBUG_CTRL_STATEMENT(x) ((void)0)
#endif
CHAIN::CHAIN (void)
{
ECA_LOG_MSG(ECA_LOGGER::system_objects, "constructor: CHAIN");
muted_rep = false;
bypass_rep = false;
initialized_rep = false;
input_id_rep = output_id_rep = -1;
/* FIXME: remove these and only store the index */
selected_controller_repp = 0;
selected_dynobj_repp = 0;
selected_chainop_number_rep = 0;
selected_controller_number_rep = 0;
selected_chainop_parameter_rep = 0;
selected_controller_parameter_rep = 0;
}
CHAIN::~CHAIN (void)
{
ECA_LOG_MSG(ECA_LOGGER::system_objects, "CHAIN destructor!");
if (is_initialized())
release();
for(std::vector<CHAIN::COP_CONTAINER>::iterator p = chainops_rep.begin(); p !=
chainops_rep.end(); p++) {
string tmp = (*p).cop->status();
if (tmp.size() > 0) {
ECA_LOG_MSG(ECA_LOGGER::info, tmp);
}
delete (*p).cop;
}
for(std::vector<GENERIC_CONTROLLER*>::iterator p = gcontrollers_rep.begin(); p !=
gcontrollers_rep.end(); p++) {
delete *p;
}
}
/**
* Whether chain is in a valid state (= ready for processing)?
*/
bool CHAIN::is_valid(void) const
{
if (input_id_rep == -1 ||
output_id_rep == -1) {
return false;
}
return true;
}
/**
* Connects input to chain
*/
void CHAIN::connect_input(int input) { input_id_rep = input; }
/**
* Connects output to chain
*/
void CHAIN::connect_output(int output) { output_id_rep = output; }
/**
* Disconnects input
*/
void CHAIN::disconnect_input(void) { input_id_rep = -1; initialized_rep = false; }
/**
* Disconnects output
*/
void CHAIN::disconnect_output(void) { output_id_rep = -1; initialized_rep = false; }
/**
* Disconnects the sample buffer
*/
void CHAIN::disconnect_buffer(void) { audioslot_repp = 0; initialized_rep = false; release(); }
/**
* Notifies chain that an input has been removed.
*/
void CHAIN::input_removed(int input)
{
// adjust input_id_rep in case position in input
// array has changed
if (input_id_rep > input)
--input_id_rep;
else if (input_id_rep == input)
disconnect_input();
}
/**
* Notifies chain that an output has been removed.
*/
void CHAIN::output_removed(int output)
{
// adjust output_id_rep in case position in output
// array has changed
if (output_id_rep > output)
--output_id_rep;
else if (output_id_rep == output)
disconnect_output();
}
/**
* Adds the chain operator to the end of the chain
*
* require:
* chainop != 0
*
* ensure:
* selected_chain_operator() == number_of_chain_operators()
* is_initialized() != true
*/
void CHAIN::add_chain_operator(CHAIN_OPERATOR* chainop)
{
// --------
DBC_REQUIRE(chainop != 0);
// --------
ECA_SAMPLERATE_AWARE* srateobj = dynamic_cast<ECA_SAMPLERATE_AWARE*>(chainop);
if (srateobj != 0) {
srateobj->set_samples_per_second(samples_per_second());
}
CHAIN::COP_CONTAINER container;
container.cop = chainop;
container.bypassed = false;
chainops_rep.push_back(container);
selected_chainop_number_rep = chainops_rep.size();
initialized_rep = false;
// --------
DBC_ENSURE(selected_chain_operator() == number_of_chain_operators());
DBC_ENSURE(is_initialized() != true);
// --------
}
/**
* Removes the selected chain operator
*
* @param op_index operator index (1...N), or -1 to use the selected op
*
* ensure:
* is_initialized() != true
*/
void CHAIN::remove_chain_operator(int op_index)
{
if (op_index < 0)
op_index = selected_chainop_number_rep;
CHAIN_OPERATOR *to_remove = 0;
if (op_index > 0 &&
op_index <= static_cast<int>(chainops_rep.size()))
to_remove = chainops_rep[op_index - 1].cop;
if (to_remove != 0) {
for(std::vector<CHAIN::COP_CONTAINER>::iterator p = chainops_rep.begin();
p != chainops_rep.end();
p++) {
if ((*p).cop == to_remove) {
for(std::vector<GENERIC_CONTROLLER*>::iterator q = gcontrollers_rep.begin();
q != gcontrollers_rep.end();) {
if ((*p).cop == (*q)->target_pointer()) {
/* step: if the deleted controller is selected, unselect it */
if (selected_controller_repp == *q)
selected_controller_repp = 0;
/* step: remove the related controller */
delete *q;
gcontrollers_rep.erase(q);
/* step: in case there are multiple controllers per chainop */
q = gcontrollers_rep.begin();
}
else
++q;
}
/* step: delete and remove from the list */
delete (*p).cop;
chainops_rep.erase(p);
/* step: invalidate selection if the selected cop
* was affected */
if (op_index >= selected_chainop_number_rep) {
selected_chainop_number_rep = -1;
break;
}
}
}
initialized_rep = false;
}
// --------
DBC_ENSURE(is_initialized() != true || to_remove == 0);
// --------
}
/**
* Returns the name of selected chain operator.
*
* require:
* selected_chain_operator() != 0
*/
string CHAIN::chain_operator_name(void) const
{
assert(selected_chainop_number_rep > 0);
assert(selected_chainop_number_rep <= static_cast<int>(chainops_rep.size()));
return chainops_rep[selected_chainop_number_rep - 1].cop->name();
}
/**
* Returns the name of selected chain operator parameter.
*
* require:
* selected_chain_operator() != 0
* selected_chain_operator_parameter() != 0
*/
string CHAIN::chain_operator_parameter_name(void) const
{
assert(selected_chainop_number_rep > 0);
assert(selected_chainop_number_rep <= static_cast<int>(chainops_rep.size()));
return chainops_rep[selected_chainop_number_rep - 1].cop->get_parameter_name(selected_chain_operator_parameter());
}
/**
* Returns the name of selected controller parameter.
*
* require:
* selected_controller() != 0
* selected_controller_parameter() != 0
*/
string CHAIN::controller_parameter_name(void) const
{
// --------
DBC_REQUIRE(selected_controller() > 0);
DBC_REQUIRE(selected_controller_parameter() > 0);
// --------
return selected_controller_repp->get_parameter_name(selected_controller_parameter());
}
/**
* Returns the total number of parameters for the
* selected chain operator.
*
* require:
* selected_chain_operator() != 0
*/
int CHAIN::number_of_chain_operator_parameters(void) const
{
assert(selected_chainop_number_rep > 0);
assert(selected_chainop_number_rep <= static_cast<int>(chainops_rep.size()));
return chainops_rep[selected_chainop_number_rep - 1].cop->number_of_params();
}
/**
* Returns the total number of parameters for the
* chain operator 'index' ([1...N]).
*
* require:
* index < number_of_chain_operators()
*/
int CHAIN::number_of_chain_operator_parameters(int index) const
{
DBC_REQUIRE(index > 0);
DBC_REQUIRE(index <= number_of_chain_operators());
if (index > 0 &&
index <= number_of_chain_operators())
return chainops_rep[index - 1].cop->number_of_params();
return -1;
}
/**
* Returns the total number of parameters for the selected controller.
*
* require:
* selected_controller() != 0
*/
int CHAIN::number_of_controller_parameters(void) const
{
// --------
DBC_REQUIRE(selected_controller() > 0);
// --------
return selected_controller_repp->number_of_params();
}
/**
* Returns the name of selected controller.
*
* require:
* selected_controller() != 0
*/
string CHAIN::controller_name(void) const
{
// --------
DBC_REQUIRE(selected_controller() > 0);
// --------
return selected_controller_repp->name();
}
/**
* Sets the parameter value (selected chain operator)
*
* @param op_index operator index (1...N), or -1 to use the selected op
* @param param_index param index (1...N), or -1 to use the selected param
* @param value new value
*/
void CHAIN::set_parameter(int op_index, int param_index, CHAIN_OPERATOR::parameter_t value)
{
CHAIN_OPERATOR *cop = 0;
if (op_index < 0) {
if (selected_chainop_number_rep > 0 &&
selected_chainop_number_rep <= static_cast<int>(chainops_rep.size()))
cop = chainops_rep[selected_chainop_number_rep - 1].cop;
}
else if (op_index > 0 &&
op_index <= static_cast<int>(chainops_rep.size()))
cop = chainops_rep[op_index - 1].cop;
if (param_index < 0)
param_index = selected_chainop_parameter_rep;
if (cop)
cop->set_parameter(param_index, value);
}
/**
* Returns true if op_index is valid.
*/
bool CHAIN::is_valid_op_index(int op_index) const
{
if (op_index > 0 &&
op_index <= static_cast<int>(chainops_rep.size()))
return true;
return false;
}
/**
* Sets bypass state (selected chain operator)
*
* @param op_index operator index (1...N), or -1 to use the selected op
* @param bypassed 1=bypass, 0=nobypass, -1=toggle (change state)
*/
void CHAIN::bypass_operator(int op_index, int bypassed)
{
if (is_valid_op_index(op_index)) {
if (bypassed < 0) {
// just toggle the current value
chainops_rep[op_index - 1].bypassed = !(chainops_rep[op_index - 1].bypassed);
}
else {
chainops_rep[op_index - 1].bypassed =
(bypassed > 0 ? true : false);
}
}
}
/**
* Sets muting state for the chain
*
* @param bypassed 1=mute, 0=unmute, -1=toggle (change state)
*/
void CHAIN::set_mute(int state)
{
if (state < 0)
muted_rep = !muted_rep;
else if (state > 0)
muted_rep = true;
else
muted_rep = false;
}
/**
* Sets muting state for the chain
*
* @param state 1=bypass, 0=nobypass, -1=toggle (change state)
*/
void CHAIN::set_bypass(int state)
{
if (state < 0)
bypass_rep = !bypass_rep;
else if (state > 0)
bypass_rep = true;
else
bypass_rep = false;
}
bool CHAIN::is_operator_bypassed(int op_index) const
{
if (is_valid_op_index(op_index)) {
return chainops_rep[op_index - 1].bypassed;
}
return false;
}
/**
* Gets the parameter value (selected chain operator)
*
* @param index parameter number
*
* require:
* selected_chain_operator_parameter() > 0 &&
* selected_chain_operator() != 0
*/
CHAIN_OPERATOR::parameter_t CHAIN::get_parameter(void) const
{
DBC_CHECK(selected_chainop_number_rep > 0);
DBC_CHECK(selected_chainop_number_rep <= static_cast<int>(chainops_rep.size()));
if (selected_chainop_number_rep > 0 &&
selected_chainop_number_rep <= static_cast<int>(chainops_rep.size())) {
return chainops_rep[selected_chainop_number_rep - 1].cop->get_parameter(selected_chainop_parameter_rep);
}
return 0.0f;
}
/**
* Adds a generic controller and assign it to selected dynamic object
*
* require:
* gcontroller != 0
* selected_dynobj != 0
*/
void CHAIN::add_controller(GENERIC_CONTROLLER* gcontroller)
{
// --------
DBC_REQUIRE(gcontroller != 0);
DBC_REQUIRE(selected_dynobj_repp != 0);
// --------
#ifndef ECA_DISABLE_EFFECTS
gcontroller->assign_target(selected_dynobj_repp);
ECA_LOG_MSG(ECA_LOGGER::user_objects, gcontroller->status());
#endif
gcontrollers_rep.push_back(gcontroller);
selected_controller_repp = gcontroller;
selected_controller_number_rep = gcontrollers_rep.size();
}
const CHAIN_OPERATOR* CHAIN::get_selected_chain_operator(void) const
{
if (selected_chainop_number_rep > 0 &&
selected_chainop_number_rep <= static_cast<int>(chainops_rep.size()))
return chainops_rep[selected_chainop_number_rep - 1].cop;
return 0;
}
/**
* Removes the selected controller
*
* require:
* selected_controller() <= number_of_controllers();
* selected_controller() > 0
*/
void CHAIN::remove_controller(void)
{
// --------
DBC_REQUIRE(selected_controller() > 0);
DBC_REQUIRE(selected_controller() <= number_of_controllers());
// --------
int n = 0;
for(std::vector<GENERIC_CONTROLLER*>::iterator q = gcontrollers_rep.begin();
q != gcontrollers_rep.end();
q++) {
if ((n + 1) == selected_controller()) {
delete *q;
gcontrollers_rep.erase(q);
select_controller(-1);
break;
}
++n;
}
}
/**
* Clears chain (removes all chain operators and controllers)
*/
void CHAIN::clear(void)
{
for(std::vector<CHAIN::COP_CONTAINER>::iterator p = chainops_rep.begin(); p != chainops_rep.end(); p++) {
delete (*p).cop;
(*p).cop = 0;
}
chainops_rep.resize(0);
for(std::vector<GENERIC_CONTROLLER*>::iterator p = gcontrollers_rep.begin(); p !=
gcontrollers_rep.end(); p++) {
delete *p;
*p = 0;
}
gcontrollers_rep.resize(0);
initialized_rep = false;
}
/**
* Selects a chain operator. If no chain operators
* are found with 'index', with index 'index'.
*
* @param index 1...N
*
* ensure:
* index == selected_chain_operator() ||
* selected_chain_operator() == 0
*/
void CHAIN::select_chain_operator(int index)
{
if (index > 0 &&
index <= static_cast<int>(chainops_rep.size())) {
selected_chainop_number_rep = index;
selected_chain_operator_as_target();
}
}
/**
* Selects a chain operator parameter. Index of zero clears out
* current selection.
*
* require:
* index > 0
* selected_chain_operator() != 0 || index == 0
* index <= selected_chain_operator()->number_of_params()
*
* ensure:
* index == selected_chain_operator_parameter()
*/
void CHAIN::select_chain_operator_parameter(int index)
{
DBC_REQUIRE(index > 0);
selected_chainop_parameter_rep = index;
}
/**
* Selects a controller. Index of zero clears out
* current selection.
*
* @param index 1...N, or negative to clear selection
*
* ensure:
* index == selected_controller() ||
* selected_controller() == 0
*/
void CHAIN::select_controller(int index)
{
DBC_REQUIRE(index != 0);
selected_controller_repp = 0;
selected_controller_number_rep = 0;
for(int gcontroller_sizet = 0; gcontroller_sizet != static_cast<int>(gcontrollers_rep.size()); gcontroller_sizet++) {
if (gcontroller_sizet + 1 == index) {
selected_controller_repp = gcontrollers_rep[gcontroller_sizet];
selected_controller_number_rep = index;
}
}
}
/**
* Selects a controller parameter. Index of zero clears out
* current selection.
*
* require:
* index > 0
* selected_controller() != 0 || index == 0
* index <= selected_controller()->number_of_params()
*
* ensure:
* index == selected_controller_parameter()
*/
void CHAIN::select_controller_parameter(int index)
{
selected_controller_parameter_rep = index;
}
/**
* Gets the value of the currently selected controller parameter.
*
* require:
* selected_controller() != 0
* selected_controller_parameter() != 0
*/
CHAIN_OPERATOR::parameter_t CHAIN::get_controller_parameter(void) const
{
// --------
DBC_REQUIRE(selected_controller_parameter() > 0);
DBC_REQUIRE(selected_controller() != 0);
// --------
return selected_controller_repp->get_parameter(selected_controller_parameter_rep);
}
/**
* Sets the value of the currently selected controller parameter.
*
* @param ctrl_index operator index (1...N), or -1 to use the selected ctrl
* @param param_index param index (1...N), or -1 to use the selected param
* @param value new value
*/
void CHAIN::set_controller_parameter(int ctrl_index, int param_index, CHAIN_OPERATOR::parameter_t value)
{
GENERIC_CONTROLLER *ctrl = 0;
if (ctrl_index < 0) {
if (selected_controller_number_rep > 0 &&
selected_controller_number_rep <= static_cast<int>(gcontrollers_rep.size()))
ctrl = gcontrollers_rep[selected_controller_number_rep - 1];
}
else if (ctrl_index > 0 &&
ctrl_index <= static_cast<int>(gcontrollers_rep.size()))
ctrl = gcontrollers_rep[ctrl_index - 1];
if (param_index < 0)
param_index = selected_controller_parameter_rep;
DBC_CHECK(param_index > 0);
if (ctrl)
ctrl->set_parameter(param_index, value);
}
/**
* Use current selected chain operator as
* target for parameters control.
*
* require:
* selected_chain_operator() != 0
*
* ensure:
* selected_target() == selected_chain_operator()
*/
void CHAIN::selected_chain_operator_as_target(void)
{
assert(selected_chainop_number_rep > 0);
assert(selected_chainop_number_rep <= static_cast<int>(chainops_rep.size()));
selected_dynobj_repp = chainops_rep[selected_chainop_number_rep - 1].cop;
// --------
DBC_ENSURE(selected_dynobj_repp == chainops_rep[selected_chainop_number_rep - 1].cop);
// --------
}
/**
* Use current selected controller as
* target for parameter control.
*
* require:
* selected_controller() != 0
*
* ensure:
* selected_target() == selected_controller()
*/
void CHAIN::selected_controller_as_target(void)
{
// --------
DBC_REQUIRE(selected_controller_repp != 0);
// --------
selected_dynobj_repp = selected_controller_repp;
// --------
DBC_ENSURE(selected_dynobj_repp == selected_controller_repp);
// --------
}
/**
* Prepares chain for processing. All further processing
* will be done using the buffer pointer by 'sbuf'.
* If all parameters are zero, previously specified
* parameters are used (state re-initialization).
*
* require:
* input_id != 0 || in_channels != 0
* output_id != 0 || out_channels != 0
* audioslot_repp != 0 || sbuf != 0
*
* ensure:
* is_initialized() == true
*/
void CHAIN::init(SAMPLE_BUFFER* sbuf, int in_channels, int out_channels)
{
// --------
DBC_REQUIRE(in_channels != 0 || in_channels_rep != 0);
DBC_REQUIRE(out_channels != 0 || out_channels_rep != 0);
DBC_REQUIRE(sbuf != 0 || audioslot_repp != 0);
// --------
DBC_CHECK(samples_per_second() > 0);
if (sbuf != 0) audioslot_repp = sbuf;
if (in_channels != 0) in_channels_rep = in_channels;
if (out_channels != 0) out_channels_rep = out_channels;
int channels_next = in_channels_rep;
for(size_t p = 0; p != chainops_rep.size(); p++) {
/* note: buffer must have room to store both input and
* output channels (processing in-place) */
int out_ch = chainops_rep[p].cop->output_channels(channels_next);
if (out_ch > channels_next)
channels_next = out_ch;
audioslot_repp->number_of_channels(channels_next);
chainops_rep[p].cop->init(audioslot_repp);
/* note: for the next plugin, only 'out_ch' channels contain
* valid audio */
channels_next = out_ch;
}
for(size_t p = 0; p != gcontrollers_rep.size(); p++) {
gcontrollers_rep[p]->init();
}
refresh_parameters();
initialized_rep = true;
ECA_LOG_MSG(ECA_LOGGER::system_objects,
"Initialized chain " +
name() +
" with " +
kvu_numtostr(chainops_rep.size()) +
" chainops and " +
kvu_numtostr(gcontrollers_rep.size()) +
" gcontrollers. Sbuf points to " +
kvu_numtostr(reinterpret_cast<long int>(audioslot_repp)) + ".");
// --------
DBC_ENSURE(is_initialized() == true);
// --------
}
/**
* Releases all buffers assigned to chain operators.
*/
void CHAIN::release(void)
{
for(size_t p = 0; p != chainops_rep.size(); p++) {
chainops_rep[p].cop->release();
}
initialized_rep = false;
// ---------
DBC_ENSURE(is_initialized() != true);
// ---------
}
/**
* Processes chain data with all chain operators.
*
* require:
* is_initialized() == true
*/
void CHAIN::process(void)
{
// --------
DBC_REQUIRE(is_initialized() == true);
// --------
/* step: update operator parameters */
controller_update();
/* step: run processing components */
if (muted_rep != true) {
/* note: if muted, don't bother running the chainops */
if (bypass_rep != true) {
/* note: processing enabled (no bypass) */
for(int p = 0; p != static_cast<int>(chainops_rep.size()); p++) {
if (chainops_rep[p].bypassed == true)
continue;
/* note: increase channel count if chainop needs the space */
int out_ch = chainops_rep[p].cop->output_channels(audioslot_repp->number_of_channels());
if (out_ch > audioslot_repp->number_of_channels())
audioslot_repp->number_of_channels(out_ch);
chainops_rep[p].cop->process();
}
}
}
else {
audioslot_repp->make_silent();
}
/* step: update chain position */
change_position_in_samples(audioslot_repp->length_in_samples());
}
/**
* Calculates/fetches new values for all controllers.
*/
void CHAIN::controller_update(void)
{
for(size_t n = 0; n < gcontrollers_rep.size(); n++) {
DEBUG_CTRL_STATEMENT(GENERIC_CONTROLLER* ptr = gcontrollers_rep[n]);
gcontrollers_rep[n]->value(position_in_seconds_exact());
DEBUG_CTRL_STATEMENT(std::cerr << "trace: " << ptr->name());
DEBUG_CTRL_STATEMENT(std::cerr << "; value " << ptr->source_pointer()->value() << "." << std::endl);
}
}
/**
* Re-initializes all effect parameters.
*/
void CHAIN::refresh_parameters(void)
{
for(int chainop_sizet = 0; chainop_sizet != static_cast<int>(chainops_rep.size()); chainop_sizet++) {
for(int n = 0; n < chainops_rep[chainop_sizet].cop->number_of_params(); n++) {
chainops_rep[chainop_sizet].cop->set_parameter(n + 1,
chainops_rep[chainop_sizet].cop->get_parameter(n + 1));
}
}
}
/**
* Converts chain to a formatted string.
*/
string CHAIN::to_string(void) const
{
MESSAGE_ITEM t;
FILE_PRESET* fpreset;
GLOBAL_PRESET* gpreset;
int q = 0;
while (q < static_cast<int>(chainops_rep.size())) {
#ifndef ECA_DISABLE_EFFECTS
fpreset = 0;
fpreset = dynamic_cast<FILE_PRESET*>(chainops_rep[q].cop);
if (fpreset != 0) {
t << "-pf:" << fpreset->filename();
if (fpreset->number_of_params() > 0) t << ",";
t << ECA_OBJECT_FACTORY::operator_parameters_to_eos(fpreset);
t << " ";
}
else {
gpreset = 0;
gpreset = dynamic_cast<GLOBAL_PRESET*>(chainops_rep[q].cop);
if (gpreset != 0) {
t << "-pn:" << gpreset->name();
if (gpreset->number_of_params() > 0) t << ",";
t << ECA_OBJECT_FACTORY::operator_parameters_to_eos(gpreset);
t << " ";
}
else {
t << ECA_OBJECT_FACTORY::chain_operator_to_eos(chainops_rep[q].cop) << " ";
}
}
/* check if the chainop is controlled by a gcontroller */
std::vector<GENERIC_CONTROLLER*>::size_type p = 0;
while (p < gcontrollers_rep.size()) {
if (chainops_rep[q].cop == gcontrollers_rep[p]->target_pointer()) {
t << " " << ECA_OBJECT_FACTORY::controller_to_eos(gcontrollers_rep[p]);
t << " ";
/* check if the gcontroller is controlled by another gcontroller */
std::vector<GENERIC_CONTROLLER*>::size_type r = 0;
while (r < gcontrollers_rep.size()) {
if (p != r &&
gcontrollers_rep[p] == gcontrollers_rep[r]->target_pointer()) {
t << " -kx " << ECA_OBJECT_FACTORY::controller_to_eos(gcontrollers_rep[r]);
}
++r;
}
}
++p;
}
#endif
++q;
}
return t.to_string();
}
/**
* Reimplemented from ECA_SAMPLERATE_AWARE
*/
void CHAIN::set_samples_per_second(SAMPLE_SPECS::sample_rate_t v)
{
for(size_t p = 0; p != chainops_rep.size(); p++) {
CHAIN_OPERATOR* temp = chainops_rep[p].cop;
ECA_SAMPLERATE_AWARE* srateobj = dynamic_cast<ECA_SAMPLERATE_AWARE*>(temp);
if (srateobj != 0) {
ECA_LOG_MSG(ECA_LOGGER::user_objects,
"sample rate change, chain '" +
name() + "' object '" +
temp->name() + "' rate " +
kvu_numtostr(v) + ".");
srateobj->set_samples_per_second(v);
}
}
ECA_SAMPLERATE_AWARE::set_samples_per_second(v);
}
/**
* Reimplemented from ECA_AUDIO_POSITION.
*/
SAMPLE_SPECS::sample_pos_t CHAIN::seek_position(SAMPLE_SPECS::sample_pos_t pos)
{
ECA_LOG_MSG(ECA_LOGGER::user_objects,
"seek position, to pos " +
kvu_numtostr(pos) + ".");
return pos;
}
|