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
|
// qtractorPlugin.h
//
/****************************************************************************
Copyright (C) 2005-2022, rncbc aka Rui Nuno Capela. All rights reserved.
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, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*****************************************************************************/
#ifndef __qtractorPlugin_h
#define __qtractorPlugin_h
#include "qtractorEngine.h"
#include "qtractorMidiControlObserver.h"
#include "qtractorDocument.h"
#include <QStringList>
#include <QPoint>
#include <QSize>
#include <QMap>
#include <QVariant>
// Forward declarations.
class qtractorPluginList;
class qtractorPluginForm;
class qtractorPlugin;
class qtractorPluginListView;
class qtractorPluginListItem;
class qtractorMidiManager;
class qtractorCurveList;
class qtractorCurveFile;
//----------------------------------------------------------------------------
// qtractorPluginFile -- Plugin file library instance.
//
class qtractorPluginFile
{
public:
// Constructor.
qtractorPluginFile(const QString& sFilename, bool bAutoUnload = true)
: m_sFilename(sFilename), m_module(nullptr),
m_bAutoUnload(bAutoUnload), m_iOpenCount(0), m_iRefCount(0) {}
// Destructor.
~qtractorPluginFile()
{ close(); }
// Helper property accessors.
const QString& filename() const { return m_sFilename; }
void *module() const { return m_module; }
// Executive methods.
bool open();
void close();
// Symbol resolver.
void *resolve(const char *symbol);
// Auto-unload flag accessors.
void setAutoUnload(bool bAutoUnload)
{ m_bAutoUnload = bAutoUnload; }
bool isAutoUnload() const
{ return m_bAutoUnload; }
// Ref-counting methods.
void addRef()
{ ++m_iRefCount; }
bool removeRef()
{ return (--m_iRefCount < 1); }
// Plugin file resgistry.
typedef QHash<QString, qtractorPluginFile *> Files;
// Plugin file resgistry methods.
static qtractorPluginFile *addFile(const QString& sFilename);
static void removeFile(qtractorPluginFile *pFile);
private:
// Instance variables.
QString m_sFilename;
void *m_module;
bool m_bAutoUnload;
unsigned int m_iOpenCount;
unsigned int m_iRefCount;
// Global plugin-files.
static Files g_files;
};
//----------------------------------------------------------------------------
// qtractorPluginType -- Plugin type instance.
//
class qtractorPluginType
{
public:
// Have hints for plugin paths.
enum Hint { Any = 0, Ladspa, Dssi, Vst2, Vst3, Clap, Lv2, Insert, AuxSend };
// Constructor.
qtractorPluginType(qtractorPluginFile *pFile, unsigned long iIndex,
Hint typeHint) : m_iUniqueID(0), m_iControlIns(0), m_iControlOuts(0),
m_iAudioIns(0), m_iAudioOuts(0), m_iMidiIns(0), m_iMidiOuts(0),
m_bRealtime(false), m_bConfigure(false), m_bEditor(false),
m_pFile(pFile), m_iIndex(iIndex), m_typeHint(typeHint) {}
// Destructor (virtual)
virtual ~qtractorPluginType()
{ qtractorPluginFile::removeFile(m_pFile); }
// Main properties accessors.
qtractorPluginFile *file() const { return m_pFile; }
unsigned long index() const { return m_iIndex; }
Hint typeHint() const { return m_typeHint; }
// Plugin filename accessor (default virtual).
virtual QString filename() const;
// Must be derived methods.
virtual bool open() = 0;
virtual void close() = 0;
// Cache accessors.
const QString& name() const { return m_sName; }
const QString& label() const { return m_sLabel; }
unsigned long uniqueID() const { return m_iUniqueID; }
// Port count accessors..
unsigned short controlIns() const { return m_iControlIns; }
unsigned short controlOuts() const { return m_iControlOuts; }
unsigned short audioIns() const { return m_iAudioIns; }
unsigned short audioOuts() const { return m_iAudioOuts; }
unsigned short midiIns() const { return m_iMidiIns; }
unsigned short midiOuts() const { return m_iMidiOuts; }
// Attribute accessors.
bool isRealtime() const { return m_bRealtime; }
bool isConfigure() const { return m_bConfigure; }
bool isEditor() const { return m_bEditor; }
bool isMidi() const { return m_iMidiIns + m_iMidiOuts > 0; }
// Compute the number of instances needed
// for the given input/output audio channels.
virtual unsigned short instances(
unsigned short iChannels, bool bMidi) const;
// Plugin factory method.
static qtractorPlugin *createPlugin(qtractorPluginList *pList,
const QString& sFilename, unsigned long iIndex, Hint typeHint);
// Plugin type(hint) textual helpers.
static Hint hintFromText(const QString& sText);
static QString textFromHint(Hint typeHint);
// Instance cached-deferred methods.
virtual const QString& aboutText() { return m_sAboutText; }
protected:
// Cached name strings.
QString m_sName;
QString m_sLabel;
// Cache unique identifier.
unsigned long m_iUniqueID;
// Cached port counts.
unsigned short m_iControlIns;
unsigned short m_iControlOuts;
unsigned short m_iAudioIns;
unsigned short m_iAudioOuts;
unsigned short m_iMidiIns;
unsigned short m_iMidiOuts;
// Cached flags.
bool m_bRealtime;
bool m_bConfigure;
bool m_bEditor;
// Instance cached-deferred variables.
QString m_sAboutText;
private:
// Instance variables.
qtractorPluginFile *m_pFile;
unsigned long m_iIndex;
Hint m_typeHint;
};
//----------------------------------------------------------------------------
// qtractorPlugin -- Plugin instance.
//
class qtractorPlugin : public qtractorList<qtractorPlugin>::Link
{
public:
// Constructors.
qtractorPlugin(qtractorPluginList *pList, qtractorPluginType *pType);
// Destructor.
virtual ~qtractorPlugin();
// DANGER: This one should be used by qtractorPluginList class only!
void setPluginList(qtractorPluginList *pList) { m_pList = pList; }
// Main properties accessors.
qtractorPluginList *list() const { return m_pList; }
qtractorPluginType *type() const { return m_pType; }
unsigned short instances() const { return m_iInstances; }
// Chain helper ones.
unsigned short channels() const;
// Unique ID methods.
void setUniqueID(unsigned long iUniqueID)
{ m_iUniqueID = iUniqueID; }
unsigned long uniqueID() const
{ return m_iUniqueID; }
// Activation methods.
void setActivated(bool bActivated);
void setActivatedEx(bool bActivated);
bool isActivated() const;
bool isActivatedEx() const;
// Activate subject accessors.
qtractorSubject *activateSubject()
{ return &m_activateSubject; }
qtractorMidiControlObserver *activateObserver()
{ return &m_activateObserver; }
// Activate pseudo-parameter port index.
void setActivateSubjectIndex (unsigned long iIndex)
{ m_iActivateSubjectIndex = iIndex; }
unsigned long activateSubjectIndex() const
{ return m_iActivateSubjectIndex; }
// An accessible list of parameters.
class Param;
typedef QMap<unsigned long, Param *> Params;
const Params& params() const
{ return m_params; }
typedef QHash<QString, Param *> ParamNames;
const ParamNames& paramNames() const
{ return m_paramNames; }
// Parameters list accessors.
void addParam(Param *pParam);
void removeParam(Param *pParam);
void clearParams();
Param *findParam(unsigned long iIndex) const
{ return m_params.value(iIndex, nullptr); }
// Properties registry.
class Property;
typedef QHash<unsigned long, Property *> Properties;
const Properties& properties() const
{ return m_properties; }
typedef QMap<QString, Property *> PropertyKeys;
const PropertyKeys& propertyKeys() const
{ return m_propertyKeys; }
// Properties registry accessors.
void addProperty(Property *pProp);
void removeProperty(Property *pProp);
void clearProperties();
Property *findProperty(unsigned long iProperty) const
{ return m_properties.value(iProperty, nullptr); }
// Instance capped number of audio ports.
unsigned short audioIns() const
{ return m_pType->audioIns(); }
unsigned short audioOuts() const
{ return m_pType->audioOuts(); }
// Instance capped number of MIDI ports.
unsigned short midiIns() const
{ return m_pType->midiIns(); }
unsigned short midiOuts() const
{ return m_pType->midiOuts(); }
// Plugin state serialization methods.
void setValueList(const QStringList& vlist);
QStringList valueList() const;
// Reset-to-default method.
void reset();
// Channel/instance number settler.
virtual void setChannels(unsigned short iChannels) = 0;
// Do the actual (de)activation.
virtual void activate() = 0;
virtual void deactivate() = 0;
// The main plugin processing procedure.
virtual void process(
float **ppIBuffer, float **ppOBuffer, unsigned int nframes) = 0;
// Parameter update method.
virtual void updateParam(
Param */*pParam*/, float /*fValue*/, bool /*bUpdate*/) {}
// Specific MIDI instrument selector.
virtual void selectProgram(int /*iBank*/, int /*iProg*/) {}
// Program (patch) descriptor.
struct Program
{
int bank;
int prog;
QString name;
};
// Provisional program/patch accessor.
virtual bool getProgram(int /*iIndex*/, Program& /*program*/) const
{ return false; }
// Note name descriptor.
struct NoteName
{
int bank;
int prog;
int note;
QString name;
};
// Provisional note name accessor.
virtual bool getNoteName(int /*iIndex*/, NoteName& /*note*/) const
{ return false; }
// MIDI continuous controller handler.
virtual void setController(int /*iController*/, int /*iValue*/) {}
// Plugin configuration handlers.
virtual void configure(
const QString& /*sKey*/, const QString& /*sValue*/) {}
// Plugin configuration/state snapshot.
virtual void freezeConfigs();
virtual void releaseConfigs();
// Plugin configure realization.
virtual void realizeConfigs();
// Plugin current latency (in frames);
virtual unsigned long latency() const
{ return 0; }
// GUI Editor stuff.
virtual void openEditor(QWidget */*pParent*/= nullptr) {}
virtual void closeEditor() {};
virtual void idleEditor() {};
// GUI editor visibility state.
virtual void setEditorVisible(bool /*bVisible*/) {}
virtual bool isEditorVisible() const
{ return false; }
virtual void setEditorTitle(const QString& sTitle)
{ m_sEditorTitle = sTitle; }
const QString& editorTitle() const
{ return m_sEditorTitle; }
void updateEditorTitle();
void setEditorPos(const QPoint& pos)
{ m_posEditor = pos; }
const QPoint& editorPos() const
{ return m_posEditor; }
// Move widget to alleged parent center or else...
void moveWidgetPos(QWidget *pWidget, const QPoint& pos) const;
// Custom GUI editor type index preference.
void setEditorType(int iEditorType)
{ m_iEditorType = iEditorType; }
int editorType() const
{ return m_iEditorType; }
// An accessible list of observers.
const QList<qtractorPluginListItem *>& items() const
{ return m_items; }
// List of observers management.
void addItem(qtractorPluginListItem *pItem);
void removeItem(qtractorPluginListItem *pItem);
void clearItems();
// Special plugin form methods.
void openForm(QWidget *pParent = nullptr);
void closeForm(bool bForce = false);
bool isFormVisible() const;
void toggleFormEditor(bool bOn);
void updateFormDirtyCount();
void updateFormAuxSendBusName();
void refreshForm();
void freezeFormPos();
void setFormPos(const QPoint& pos)
{ m_posForm = pos; }
const QPoint& formPos() const
{ return m_posForm; }
// Provisional preset accessors.
virtual QStringList presetList() const;
virtual bool loadPreset(const QString& /*sPreset*/)
{ return false; }
virtual bool savePreset(const QString& /*sPreset*/)
{ return false; }
virtual bool deletePreset(const QString& /*sPreset*/)
{ return false; }
virtual bool isReadOnlyPreset(const QString& /*sPreset*/) const
{ return false; }
// Plugin default preset name accessor (informational)
void setPreset(const QString& sPreset);
const QString& preset() const;
// Plugin preset group - common identification prefix.
QString presetGroup() const;
QString presetPrefix() const;
// Default preset name (global).
static const QString& defPreset()
{ return g_sDefPreset; }
// Plugin configuration from/to xml file.
virtual bool loadPresetFile(const QString& sFilename);
virtual bool savePresetFile(const QString& sFilename);
// Load an existing preset by name/file.
bool loadPresetEx(const QString& sPreset);
bool loadPresetFileEx(const QString& sFilename);
// Plugin parameter lookup.
Param *paramFromName(const QString& sName) const;
// Plugin configuration (CLOB) stuff.
typedef QHash<QString, QString> Configs;
void setConfigs(const Configs& configs)
{ m_configs = configs; }
const Configs& configs() const
{ return m_configs; }
void setConfig(const QString& sKey, const QString& sValue)
{ m_configs[sKey] = sValue; }
const QString& config(const QString& sKey)
{ return m_configs[sKey]; }
// Plugin configuration (types) stuff.
typedef QHash<QString, QString> ConfigTypes;
void setConfigTypes(const ConfigTypes& ctypes)
{ m_ctypes = ctypes; }
const ConfigTypes& configTypes() const
{ return m_ctypes; }
void setConfigType(const QString& sKey, const QString& sType)
{ m_ctypes[sKey] = sType; }
const QString& configType(const QString& sKey)
{ return m_ctypes[sKey]; }
// Plugin parameter values stuff.
typedef QHash<unsigned long, QString> ValueNames;
typedef QHash<unsigned long, float> ValueIndex;
typedef struct
{
ValueNames names;
ValueIndex index;
} Values;
void setValues(const Values& values)
{ m_values = values; }
const Values& values() const
{ return m_values; }
// Plugin parameter/state snapshot.
void freezeValues();
void releaseValues();
// Plugin parameter/state realization.
void realizeValues();
// Save partial/complete plugin state...
bool savePlugin(qtractorDocument *pDocument, QDomElement *pElement);
bool savePluginEx(qtractorDocument *pDocument, QDomElement *pElement);
// Load plugin configuration/parameter values stuff.
static void loadConfigs(
QDomElement *pElement, Configs& configs, ConfigTypes& ctypes);
static void loadValues(QDomElement *pElement, Values& values);
// Save plugin configuration/parameter values stuff.
void saveConfigs(QDomDocument *pDocument, QDomElement *pElement);
void saveValues(QDomDocument *pDocument, QDomElement *pElement);
// Load/save plugin parameter controllers (MIDI).
static void loadControllers(
QDomElement *pElement, qtractorMidiControl::Controllers& controllers);
void saveControllers(
qtractorDocument *pDocument, QDomElement *pElement);
// Map/realize plugin parameter controllers (MIDI).
void mapControllers(const qtractorMidiControl::Controllers& controllers);
// Plugin automation curve serialization methods.
static void loadCurveFile(
QDomElement *pElement, qtractorCurveFile *pCurveFile);
void saveCurveFile(qtractorDocument *pDocument,
QDomElement *pElement, qtractorCurveFile *pCurveFile);
void applyCurveFile (qtractorCurveFile *pCurveFile);
// Direct access parameter accessors.
Param *directAccessParam() const;
void setDirectAccessParamIndex(long iDirectAccessParamIndex);
long directAccessParamIndex() const;
bool isDirectAccessParam() const;
void updateDirectAccessParam();
// Parameter update executive.
void updateParamValue(unsigned long iIndex, float fValue, bool bUpdate);
// Auto-plugin-deactivation
void autoDeactivatePlugin(bool bDeactivated);
bool canBeConnectedToOtherTracks() const;
protected:
// Instance number settler.
void setInstances(unsigned short iInstances);
// Internal activation methods.
void setChannelsActivated(unsigned short iChannels, bool bActivated);
// Activation stabilizers.
void updateActivated(bool bActivated);
void updateActivatedEx(bool bActivated);
// Internal deactivation cleanup.
void cleanup();
// Plugin configure and parameter/state clearance.
void clearConfigs() { m_configs.clear(); m_ctypes.clear(); }
void clearValues() { m_values.names.clear(); m_values.index.clear(); }
private:
// Instance variables.
qtractorPluginList *m_pList;
qtractorPluginType *m_pType;
// Unique identifier in chain.
unsigned long m_iUniqueID;
// Number of instances in chain node.
unsigned short m_iInstances;
// Activation flag.
bool m_bActivated;
// Auto-plugin-deactivation flag
bool m_bAutoDeactivated;
// Activate subject value.
qtractorSubject m_activateSubject;
// Activate observer manager.
class ActivateObserver : public qtractorMidiControlObserver
{
public:
// Constructor.
ActivateObserver(qtractorPlugin *pPlugin);
protected:
// Virtual observer updater.
void update(bool bUpdate);
private:
// Instance members.
qtractorPlugin *m_pPlugin;
} m_activateObserver;
// Activate pseudo-parameter port index.
unsigned long m_iActivateSubjectIndex;
// List of input control ports (parameters).
Params m_params;
// List of parameters (by name).
ParamNames m_paramNames;
// List of properties (also parameters).
Properties m_properties;
// List of parameters (by name).
PropertyKeys m_propertyKeys;
// An accessible list of observers.
QList<qtractorPluginListItem *> m_items;
// The plugin form reference.
qtractorPluginForm *m_pForm;
QString m_sPreset;
QPoint m_posForm;
// GUI editor stuff.
QString m_sEditorTitle;
QPoint m_posEditor;
// Custom GUI editor type index preference.
int m_iEditorType;
// Plugin configuration (CLOB) stuff.
Configs m_configs;
// Plugin configuration (type) stuff.
ConfigTypes m_ctypes;
// Plugin parameter values (part of configuration).
Values m_values;
// Direct access parameter, if any.
long m_iDirectAccessParamIndex;
// Default preset name.
static QString g_sDefPreset;
};
//----------------------------------------------------------------------------
// qtractorPlugin::Param -- Plugin parameter (control input port) instance.
//
class qtractorPlugin::Param
{
public:
// Constructor.
Param(qtractorPlugin *pPlugin, unsigned long iIndex)
: m_pPlugin(pPlugin), m_iIndex(iIndex),
m_subject(0.0f), m_observer(this), m_iDecimals(-1) {}
// Virtual destructor.
virtual ~Param() {}
// Main properties accessors.
qtractorPlugin *plugin() const { return m_pPlugin; }
unsigned long index() const { return m_iIndex; }
// Parameter name accessors.
void setName(const QString& sName)
{ m_subject.setName(sName); }
const QString& name() const
{ return m_subject.name(); }
// Parameter range hints predicate methods.
virtual bool isBoundedBelow() const = 0;
virtual bool isBoundedAbove() const = 0;
virtual bool isDefaultValue() const = 0;
virtual bool isLogarithmic() const = 0;
virtual bool isSampleRate() const = 0;
virtual bool isInteger() const = 0;
virtual bool isToggled() const = 0;
virtual bool isDisplay() const = 0;
// Current display value.
virtual QString display() const
{ return QString::number(value(), 'f', decimals()); }
// Bounding range values.
void setMinValue(float fMinValue)
{ m_subject.setMinValue(fMinValue); }
float minValue() const
{ return m_subject.minValue(); }
void setMaxValue(float fMaxValue)
{ m_subject.setMaxValue(fMaxValue); }
float maxValue() const
{ return m_subject.maxValue(); }
// Default value
void setDefaultValue(float fDefaultValue)
{ m_subject.setDefaultValue(fDefaultValue); }
float defaultValue() const
{ return m_subject.defaultValue(); }
// Current parameter value.
void setValue(float fValue, bool bUpdate);
float value() const
{ return m_observer.value(); }
float prevValue() const
{ return m_observer.prevValue(); }
// Parameter update executive method.
void updateValue(float fValue, bool bUpdate);
// Reset-to-default method.
void reset() { setValue(defaultValue(), true); }
// Direct parameter subject value.
qtractorSubject *subject() { return &m_subject; }
// Specialized observer value.
qtractorMidiControlObserver *observer() { return &m_observer; }
// Parameter decimals helper (cached).
int decimals() const
{ return m_iDecimals; }
protected:
// Virtual observer updater.
virtual void update(float fValue, bool bUpdate);
private:
// Instance variables.
qtractorPlugin *m_pPlugin;
unsigned long m_iIndex;
// Port subject value.
qtractorSubject m_subject;
// Port observer manager.
class Observer : public qtractorMidiControlObserver
{
public:
// Constructor.
Observer(Param *pParam);
protected:
// Virtual observer updater.
void update(bool bUpdate);
private:
// Instance members.
Param *m_pParam;
} m_observer;
// Decimals cache.
int m_iDecimals;
};
//----------------------------------------------------------------------------
// qtractorPlugin::Property -- Plugin property (aka. parameter) instance.
//
class qtractorPlugin::Property : public qtractorPlugin::Param
{
public:
// Constructor.
Property(qtractorPlugin *pPlugin, unsigned long iProperty)
: Param(pPlugin , iProperty),
m_sKey(QString::number(iProperty)) {}
// Property key/id accessors.
void setKey(const QString& sKey)
{ m_sKey = sKey; }
const QString& key() const
{ return m_sKey; }
// Property index/hash-key accessor.
unsigned long key_index() const { return qHash(m_sKey); }
// Property range hints predicate methods.
virtual bool isString() const = 0;
virtual bool isPath() const = 0;
// Property special predicate methods.
virtual bool isAutomatable () const
{ return !isString() && !isPath(); }
// Main property value.
void setVariant(const QVariant& value, bool bUpdate = false);
const QVariant& variant() const
{ return m_value; }
protected:
// Virtual observer updater.
void update(float fValue, bool bUpdate);
private:
// Property key id..
QString m_sKey;
// Propery value.
QVariant m_value;
};
//----------------------------------------------------------------------------
// qtractorPluginList -- Plugin chain list instance.
//
class qtractorPluginList : public qtractorList<qtractorPlugin>
{
public:
// Plugin-list type flags.
enum Flags {
// Basic flags.
Audio = 0, Midi = 1,
Track = 0, Bus = 2,
Out = 0, In = 4,
// Composite helper flags.
AudioTrack = Audio | Track,
AudioBus = Audio | Bus,
AudioInBus = Audio | Bus | In,
AudioOutBus = Audio | Bus | Out,
MidiTrack = Midi | Track,
MidiBus = Midi | Bus,
MidiInBus = Midi | Bus | In,
MidiOutBus = Midi | Bus | Out
};
// Constructor.
qtractorPluginList(unsigned short iChannels, unsigned int iFlags);
// Destructor.
~qtractorPluginList();
// The title to show up on plugin forms...
void setName(const QString& sName);
const QString& name() const
{ return m_sName; }
// Set all plugin chain number of channels.
void setChannels(unsigned short iChannels, unsigned int iFlags);
void setChannelsEx(unsigned short iChannels);
// Reset all plugin chain number of channels.
bool resetChannels(unsigned short iChannels, bool bReset = false);
// Reset and (re)activate all plugin chain.
void resetBuffers();
// Brainless accessors.
unsigned short channels() const { return m_iChannels; }
unsigned int flags() const { return m_iFlags; }
// Brainless helpers.
bool isMidi() const { return (m_iFlags & Midi); }
bool isMidiBus() const { return (m_iFlags & MidiBus) == MidiBus; }
// Specific automation curve list accessor.
qtractorCurveList *curveList() const
{ return m_pCurveList; }
// Specific MIDI manager accessor.
qtractorMidiManager *midiManager() const
{ return m_pMidiManager; }
// Special activation methods.
void updateActivated(bool bActivated)
{
if (bActivated)
++m_iActivated;
else
if (m_iActivated > 0)
--m_iActivated;
}
bool isActivatedAll() const
{ return (m_iActivated > 0 && m_iActivated >= (unsigned int) count()); }
unsigned int isActivated() const
{ return (m_iActivated > 0); }
// Guarded plugin methods.
void addPlugin(qtractorPlugin *pPlugin);
void insertPlugin(qtractorPlugin *pPlugin, qtractorPlugin *pNextPlugin);
void movePlugin(qtractorPlugin *pPlugin, qtractorPlugin *pNextPlugin);
void removePlugin(qtractorPlugin *pPlugin);
// Clone/copy plugin method.
qtractorPlugin *copyPlugin(qtractorPlugin *pPlugin);
// An accessible list of views.
const QList<qtractorPluginListView *>& views() const
{ return m_views; }
// list of views management.
void addView(qtractorPluginListView *pView);
void removeView(qtractorPluginListView *pView);
// The meta-main audio-processing plugin-chain procedure.
void process(float **ppBuffer, unsigned int nframes);
// Forward declarations.
class Document;
class WaitCursor;
// Create/load plugin state.
qtractorPlugin *loadPlugin(QDomElement *pElement);
// Document element methods.
bool loadElement(qtractorDocument *pDocument, QDomElement *pElement);
bool saveElement(qtractorDocument *pDocument, QDomElement *pElement);
// MIDI manager deferred load/cache specifics.
void setMidiBank(int iMidiBank)
{ m_iMidiBank = iMidiBank; }
int midiBank() const
{ return m_iMidiBank; }
void setMidiProg(int iMidiProg)
{ m_iMidiProg = iMidiProg; }
int midiProg() const
{ return m_iMidiProg; }
void setAudioOutputBus(bool bAudioOutputBus)
{ m_bAudioOutputBus = bAudioOutputBus; }
bool isAudioOutputBus() const
{ return m_bAudioOutputBus; }
void setAudioOutputAutoConnect(bool bAudioOutputAutoConnect)
{ m_bAudioOutputAutoConnect = bAudioOutputAutoConnect; }
bool isAudioOutputAutoConnect() const
{ return m_bAudioOutputAutoConnect; }
void setAudioOutputBusName(const QString& sAudioOutputBusName)
{ m_sAudioOutputBusName = sAudioOutputBusName; }
const QString& audioOutputBusName() const
{ return m_sAudioOutputBusName; }
void setAudioOutputMonitor(bool bAudioOutputMonitor)
{ m_bAudioOutputMonitor = bAudioOutputMonitor; }
bool isAudioOutputMonitor() const
{ return m_bAudioOutputMonitor; }
// MIDI bank/program observable subject.
class MidiProgramSubject : public qtractorSubject
{
public:
// Constructor.
MidiProgramSubject(int iBank, int iProg)
: qtractorSubject(valueFromProgram(iBank, iProg))
{ setMaxValue(valueFromProgram(0x3fff, 0x7f)); }
// Bank/program setter.
void setProgram(int iBank, int iProg)
{ setValue(valueFromProgram(iBank, iProg)); }
// Bank/program getters.
int bank() const { return bankFromValue(value()); }
int prog() const { return progFromValue(value()); }
protected:
// Bank/program value helpers.
static float valueFromProgram(int iBank, int iProg)
{
if (iBank < 0) iBank = 0;
if (iProg < 0) iProg = 0;
return float((iBank << 7) | (iProg & 0x7f));
}
static int bankFromValue(float fValue)
{ return ((int(fValue) >> 7) & 0x3fff); }
static int progFromValue(float fValue)
{ return (int(fValue) & 0x7f); }
};
MidiProgramSubject *midiProgramSubject() const
{ return m_pMidiProgramSubject; }
// Acquire a unique plugin identifier in chain.
unsigned long createUniqueID(qtractorPluginType *pType);
// Whether unique plugin identifiers are in chain.
bool isUniqueID(qtractorPluginType *pType) const;
// Special audio inserts activation state methods.
void setAudioInsertActivated(bool bAudioInsertActivated)
{
if (bAudioInsertActivated)
++m_iAudioInsertActivated;
else
if (m_iAudioInsertActivated > 0)
--m_iAudioInsertActivated;
}
bool isAudioInsertActivated() const
{ return (m_iAudioInsertActivated > 0); }
// Special auto-deactivate methods
void autoDeactivatePlugins(bool bDeactivated, bool bForce = false);
bool isAutoDeactivated() const;
// Plugin chain total latency (in frames) methods...
void setLatency(bool bLatency)
{ m_bLatency = bLatency; }
bool isLatency() const
{ return m_bLatency; }
unsigned long latency() const
{ return m_iLatency; }
void resetLatency();
// Plugin editors (GUI) visibility (auto-focus).
void setEditorVisibleAll(bool bVisible);
protected:
// Check/sanitize plugin file-path.
bool checkPluginFile(QString& sFilename,
qtractorPluginType::Hint typeHint) const;
private:
// Instance variables.
unsigned short m_iChannels;
unsigned int m_iFlags;
// Activation state.
unsigned int m_iActivated;
// Plugin-chain name.
QString m_sName;
// An accessible list of observers.
QList<qtractorPluginListView *> m_views;
// Specific automation curve list accessor.
qtractorCurveList *m_pCurveList;
// Specific MIDI manager.
qtractorMidiManager *m_pMidiManager;
int m_iMidiBank;
int m_iMidiProg;
bool m_bAudioOutputBus;
bool m_bAudioOutputAutoConnect;
QString m_sAudioOutputBusName;
qtractorBus::ConnectList m_audioOutputs;
// Audio inserts activation state.
unsigned int m_iAudioInsertActivated;
// Internal running buffer chain references.
float **m_pppBuffers[2];
// MIDI bank/program observable subject.
MidiProgramSubject *m_pMidiProgramSubject;
// Plugin registry (chain unique ids.)
QHash<unsigned long, unsigned int> m_uniqueIDs;
// Auto-plugin-deactivation.
bool m_bAutoDeactivated;
// Audio output monitor/meters.
bool m_bAudioOutputMonitor;
// Plugin chain total latency (in frames);
bool m_bLatency;
unsigned long m_iLatency;
};
//-------------------------------------------------------------------------
// qtractorPluginList::Document -- Plugins file import/export helper class.
//
class qtractorPluginList::Document : public qtractorDocument
{
public:
// Constructor.
Document(QDomDocument *pDocument, qtractorPluginList *pPluginList);
// Default destructor.
~Document();
// Property accessors.
qtractorPluginList *pluginList() const;
// External storage simple methods.
bool load(const QString& sFilename);
bool save(const QString& sFilename);
protected:
// Elemental loader/savers...
bool loadElement(QDomElement *pElement);
bool saveElement(QDomElement *pElement);
private:
// Instance variables.
qtractorPluginList *m_pPluginList;
};
//-------------------------------------------------------------------------
// qtractorPluginList::WaitCursor -- A waiting (hour-glass) helper.
//
class qtractorPluginList::WaitCursor
{
public:
// Constructor.
WaitCursor();
// Destructor.
~WaitCursor();
};
#endif // __qtractorPlugin_h
// end of qtractorPlugin.h
|