Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

100 lines
3.2KB

  1. /*
  2. ZynAddSubFX - a software synthesizer
  3. Control.h - Defines a variable that can be controled from a frontend
  4. Copyright (C) 2009 Harald Hvaal
  5. Author: Harald Hvaal
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of version 2 of the GNU General Public License
  8. as published by the Free Software Foundation.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License (version 2 or later) for more details.
  13. You should have received a copy of the GNU General Public License (version 2)
  14. along with this program; if not, write to the Free Software Foundation,
  15. Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16. */
  17. #ifndef _CONTROL_H_
  18. #define _CONTROL_H_
  19. #include <string>
  20. class Control
  21. {
  22. public:
  23. /**
  24. * The parent is the logical owner of this control. Parent should only
  25. * be null for the root node.
  26. * The id is a string uniquely identifying this control within the
  27. * context of the parent control. No spaces or dots are allowed in this
  28. * id.
  29. * Children id's are denoted by <parent-id>.<children-id>, so that one
  30. * can refer to any control in the hierarchy by separating them with
  31. * dots. Example: Main.AddSynth.FrequencyLFO.Amplitude
  32. */
  33. Control(Control *parent, string id);
  34. /**
  35. * Will recursively get the XML representation for all the subcontrols.
  36. * Used for saving to file and copy-pasting settings
  37. */
  38. string getXMLRepresentation();
  39. /**
  40. * Set the value of this (and possibly subcomponents as well) based on
  41. * a xml description.
  42. */
  43. void restoreFromXML(string xml);
  44. /**
  45. * Register a controluser. This will cause this user to be notified
  46. * whenever the contents of the control changes.
  47. */
  48. void registerControlUser(ControlUser *user);
  49. /**
  50. * This should return a string representation of the controls internal
  51. * value
  52. */
  53. virtual string getStringRepresentation() = 0;
  54. };
  55. class FloatControl:public Control
  56. {
  57. public:
  58. /**
  59. * Set the value of this control. If the ControlUser variable is set,
  60. * then this user will not be updated with the new value. This is to
  61. * avoid setting a value being set back to the source that set it
  62. * (which would be redundant, or possibly causing infinite setValue
  63. * loops).
  64. * NOTE: this function is thread-safe (using a mutex internally)
  65. */
  66. void setValue(float value, ControlUser *user = NULL);
  67. /**
  68. * Reimplemented from Control
  69. */
  70. virtual string getStringRepresentation();
  71. float value();
  72. };
  73. class ControlUser
  74. {
  75. public:
  76. /**
  77. * Pure virtual method, to notify the controluser that the value has
  78. * been changed internally, and needs to be read again.
  79. */
  80. virtual void controlUpdated(Control *control) = 0;
  81. };
  82. #endif /* _CONTROL_H_ */