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.

158 lines
7.2KB

  1. /*
  2. ==============================================================================
  3. This file is part of the dRowAudio JUCE module
  4. Copyright 2004-13 by dRowAudio.
  5. ------------------------------------------------------------------------------
  6. dRowAudio is provided under the terms of The MIT License (MIT):
  7. Permission is hereby granted, free of charge, to any person obtaining a copy
  8. of this software and associated documentation files (the "Software"), to deal
  9. in the Software without restriction, including without limitation the rights
  10. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. copies of the Software, and to permit persons to whom the Software is
  12. furnished to do so, subject to the following conditions:
  13. The above copyright notice and this permission notice shall be included in all
  14. copies or substantial portions of the Software.
  15. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  21. SOFTWARE.
  22. ==============================================================================
  23. */
  24. #ifndef __DROWAUDIO_PLUGINPARAMETER_H__
  25. #define __DROWAUDIO_PLUGINPARAMETER_H__
  26. #include "../utility/dRowAudio_Utility.h"
  27. //==============================================================================
  28. /** Parameter Units - currently values are the same as the AudioUnit enums
  29. */
  30. enum ParameterUnit
  31. {
  32. UnitGeneric = 0, /* untyped value generally between 0.0 and 1.0 */
  33. UnitIndexed = 1, /* takes an integer value (good for menu selections) */
  34. UnitBoolean = 2, /* 0.0 means FALSE, non-zero means TRUE */
  35. UnitPercent = 3, /* usually from 0 -> 100, sometimes -50 -> +50 */
  36. UnitSeconds = 4, /* absolute or relative time */
  37. UnitSampleFrames = 5, /* one sample frame equals (1.0/sampleRate) seconds */
  38. UnitPhase = 6, /* -180 to 180 degrees */
  39. UnitRate = 7, /* rate multiplier, for playback speed, etc. (e.g. 2.0 == twice as fast) */
  40. UnitHertz = 8, /* absolute frequency/pitch in cycles/second */
  41. UnitCents = 9, /* unit of relative pitch */
  42. UnitRelativeSemiTones = 10, /* useful for coarse detuning */
  43. UnitMIDINoteNumber = 11, /* absolute pitch as defined in the MIDI spec (exact freq may depend on tuning table) */
  44. UnitMIDIController = 12, /* a generic MIDI controller value from 0 -> 127 */
  45. UnitDecibels = 13, /* logarithmic relative gain */
  46. UnitLinearGain = 14, /* linear relative gain */
  47. UnitDegrees = 15, /* -180 to 180 degrees, similar to phase but more general (good for 3D coord system) */
  48. UnitEqualPowerCrossfade = 16, /* 0 -> 100, crossfade mix two sources according to sqrt(x) and sqrt(1.0 - x) */
  49. UnitMixerFaderCurve1 = 17, /* 0.0 -> 1.0, pow(x, 3.0) -> linear gain to simulate a reasonable mixer channel fader response */
  50. UnitPan = 18, /* standard left to right mixer pan */
  51. UnitMeters = 19, /* distance measured in meters */
  52. UnitAbsoluteCents = 20, /* absolute frequency measurement : if f is freq in hertz then */
  53. /* absoluteCents = 1200 * log2(f / 440) + 6900 */
  54. UnitOctaves = 21, /* octaves in relative pitch where a value of 1 is equal to 1200 cents*/
  55. UnitBPM = 22, /* beats per minute, ie tempo */
  56. UnitBeats = 23, /* time relative to tempo, ie. 1.0 at 120 BPM would equal 1/2 a second */
  57. UnitMilliseconds = 24, /* parameter is expressed in milliseconds */
  58. UnitRatio = 25, /* for compression, expansion ratio, etc. */
  59. UnitCustomUnit = 26 /* this is the parameter unit type for parameters that present a custom unit name */
  60. };
  61. //==============================================================================
  62. /** This file defines a parameter used in an application.
  63. Both full-scale and normalised values must be present for
  64. AU and VST host campatability.
  65. */
  66. class PluginParameter
  67. {
  68. public:
  69. //==============================================================================
  70. /** Create a default parameter.
  71. This just uses some standard default values so it can be used as a placeholder.
  72. Call init() once you know the parameter values.
  73. @see init()
  74. */
  75. PluginParameter();
  76. /** Creates a copy of another parameter.
  77. */
  78. PluginParameter (const PluginParameter& other);
  79. /** Initialise the parameter.
  80. Used to set up the parameter as required.
  81. */
  82. void init (const String& name_, ParameterUnit unit_ = UnitGeneric, String description_ = String(),
  83. double value_ = 0.0f, double min_ =0.0f, double max_ =1.0f, double default_ =0.0f,
  84. double skewFactor_ =1.0f, double smoothCoeff_ =0.1f, double step_ =0.01, String unitSuffix_ =String());
  85. inline Value& getValueObject() { return valueObject; }
  86. inline double getValue() { return double (valueObject.getValue()); }
  87. inline double getNormalisedValue() { return normaliseValue (getValue()); }
  88. void setValue (double value_);
  89. void setNormalisedValue (double normalisedValue);
  90. inline double getSmoothedValue() { return smoothValue; }
  91. inline double getSmoothedNormalisedValue() { return normaliseValue (smoothValue); }
  92. inline double getMin() { return min; }
  93. inline double getMax() { return max; }
  94. inline double getDefault() { return defaultValue; }
  95. void smooth();
  96. void setSmoothCoeff (double newSmoothCoef);
  97. inline double getSmoothCoeff() { return smoothCoeff; }
  98. void setSkewFactor (const double newSkewFactor);
  99. void setSkewFactorFromMidPoint (const double valueToShowAtMidPoint);
  100. inline double getSkewFactor() { return skewFactor; }
  101. void setStep (double newStep);
  102. inline double getStep() { return step; }
  103. inline const String getName() { return name; }
  104. inline ParameterUnit getUnit() { return unit; }
  105. inline const String getUnitSuffix() { return unitSuffix; }
  106. void setUnitSuffix (String newSuffix);
  107. void writeXml (XmlElement& xmlState);
  108. void readXml (const XmlElement* xmlState);
  109. /** Sets up a given slider with the parmeters properties.
  110. */
  111. #if ! JUCE_AUDIOPROCESSOR_NO_GUI
  112. void setupSlider (Slider& slider);
  113. #endif
  114. double normaliseValue (double scaledValue);
  115. private:
  116. //==============================================================================
  117. Value valueObject;
  118. String name, description, unitSuffix;
  119. double min, max, defaultValue;
  120. double smoothCoeff, smoothValue;
  121. double skewFactor, step;
  122. ParameterUnit unit;
  123. //==============================================================================
  124. JUCE_LEAK_DETECTOR (PluginParameter);
  125. };
  126. #endif //__DROWAUDIO_PLUGINPARAMETER_H__