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.

337 lines
11KB

  1. /*
  2. ===============================================================================
  3. LUFSMeterAudioProcessor.cpp
  4. This file is part of the LUFS Meter audio measurement plugin.
  5. Copyright 2011-12 by Klangfreund, Samuel Gaehwiler.
  6. -------------------------------------------------------------------------------
  7. The LUFS Meter can be redistributed and/or modified under the terms of the GNU
  8. General Public License Version 2, as published by the Free Software Foundation.
  9. A copy of the license is included with these source files. It can also be found
  10. at www.gnu.org/licenses.
  11. The LUFS Meter is distributed WITHOUT ANY WARRANTY.
  12. See the GNU General Public License for more details.
  13. -------------------------------------------------------------------------------
  14. To release a closed-source product which uses the LUFS Meter or parts of it,
  15. a commercial license is available. Visit www.klangfreund.com/lufsmeter for more
  16. information.
  17. ===============================================================================
  18. */
  19. #include "LUFSMeterAudioProcessor.h"
  20. #include "LUFSMeterAudioProcessorEditor.h"
  21. AudioProcessor* JUCE_CALLTYPE createPluginFilter();
  22. //==============================================================================
  23. LUFSMeterAudioProcessor::LUFSMeterAudioProcessor()
  24. :
  25. // Set up some default values:
  26. lastUIWidth (600),
  27. lastUIHeight (300),
  28. loudnessBarWidth (var(-50)),
  29. loudnessBarMinValue (var(-41)),
  30. loudnessBarMaxValue (var(-14)),
  31. showIntegratedLoudnessHistory (var(true)),
  32. showLoudnessRangeHistory (var(true)),
  33. showShortTermLoudnessHistory (var(true)),
  34. showMomentaryLoudnessHistory (var(true)),
  35. numberOfInputChannels (var(2))
  36. {
  37. }
  38. LUFSMeterAudioProcessor::~LUFSMeterAudioProcessor()
  39. {
  40. }
  41. //==============================================================================
  42. const String LUFSMeterAudioProcessor::getName() const
  43. {
  44. return JucePlugin_Name;
  45. }
  46. int LUFSMeterAudioProcessor::getNumParameters()
  47. {
  48. return 0;
  49. }
  50. float LUFSMeterAudioProcessor::getParameter (int index)
  51. {
  52. return 0.0f;
  53. }
  54. void LUFSMeterAudioProcessor::setParameter (int index, float newValue)
  55. {
  56. }
  57. const String LUFSMeterAudioProcessor::getParameterName (int index)
  58. {
  59. return String();
  60. }
  61. const String LUFSMeterAudioProcessor::getParameterText (int index)
  62. {
  63. return String();
  64. }
  65. const String LUFSMeterAudioProcessor::getInputChannelName (int channelIndex) const
  66. {
  67. return String (channelIndex + 1);
  68. }
  69. const String LUFSMeterAudioProcessor::getOutputChannelName (int channelIndex) const
  70. {
  71. return String (channelIndex + 1);
  72. }
  73. bool LUFSMeterAudioProcessor::isInputChannelStereoPair (int index) const
  74. {
  75. return true;
  76. }
  77. bool LUFSMeterAudioProcessor::isOutputChannelStereoPair (int index) const
  78. {
  79. return true;
  80. }
  81. bool LUFSMeterAudioProcessor::acceptsMidi() const
  82. {
  83. #if JucePlugin_WantsMidiInput
  84. return true;
  85. #else
  86. return false;
  87. #endif
  88. }
  89. bool LUFSMeterAudioProcessor::producesMidi() const
  90. {
  91. #if JucePlugin_ProducesMidiOutput
  92. return true;
  93. #else
  94. return false;
  95. #endif
  96. }
  97. bool LUFSMeterAudioProcessor::silenceInProducesSilenceOut() const
  98. {
  99. return false;
  100. }
  101. double LUFSMeterAudioProcessor::getTailLengthSeconds() const
  102. {
  103. return 0.0;
  104. }
  105. int LUFSMeterAudioProcessor::getNumPrograms()
  106. {
  107. return 0;
  108. }
  109. int LUFSMeterAudioProcessor::getCurrentProgram()
  110. {
  111. return 0;
  112. }
  113. void LUFSMeterAudioProcessor::setCurrentProgram (int index)
  114. {
  115. }
  116. const String LUFSMeterAudioProcessor::getProgramName (int index)
  117. {
  118. return String();
  119. }
  120. void LUFSMeterAudioProcessor::changeProgramName (int index, const String& newName)
  121. {
  122. }
  123. //==============================================================================
  124. void LUFSMeterAudioProcessor::prepareToPlay (double sampleRate, int samplesPerBlock)
  125. {
  126. DEB("prepareToPlay called")
  127. //TODO
  128. int expectedRequestRate = 20;
  129. ebu128LoudnessMeter.prepareToPlay(sampleRate,
  130. getTotalNumInputChannels(),
  131. samplesPerBlock,
  132. expectedRequestRate);
  133. // Array<var>* theArrayInside = momentaryLoudnessValues.getValue().getArray();
  134. // theArrayInside->clear();
  135. // double TODO_minimalLoudness = -300;
  136. // int numberOfInputChannels = getTotalNumInputChannels();
  137. // theArrayInside->insertMultiple (0, var (TODO_minimalLoudness), numberOfInputChannels);
  138. }
  139. void LUFSMeterAudioProcessor::releaseResources()
  140. {
  141. // When playback stops, you can use this as an opportunity to free up any
  142. // spare memory, etc.
  143. DEB("releaseResources called")
  144. }
  145. void LUFSMeterAudioProcessor::reset()
  146. {
  147. // Use this method as the place to clear any delay lines, buffers, etc, as it
  148. // means there's been a break in the audio's continuity.
  149. }
  150. void LUFSMeterAudioProcessor::processBlock (AudioSampleBuffer& buffer, MidiBuffer& midiMessages)
  151. {
  152. ebu128LoudnessMeter.processBlock(buffer);
  153. // In case we have more outputs than inputs, we'll clear any output
  154. // channels that didn't contain input data, (because these aren't
  155. // guaranteed to be empty - they may contain garbage).
  156. for (int i = getTotalNumInputChannels(); i < getTotalNumOutputChannels(); ++i)
  157. {
  158. buffer.clear (i, 0, buffer.getNumSamples());
  159. }
  160. // ask the host for the current time so we can display it...
  161. AudioPlayHead::CurrentPositionInfo newTime;
  162. if (getPlayHead() != 0 && getPlayHead()->getCurrentPosition (newTime))
  163. {
  164. // Successfully got the current time from the host..
  165. lastPosInfo = newTime;
  166. }
  167. else
  168. {
  169. // If the host fails to fill-in the current time, we'll just clear it to a default..
  170. lastPosInfo.resetToDefault();
  171. }
  172. }
  173. //==============================================================================
  174. bool LUFSMeterAudioProcessor::hasEditor() const
  175. {
  176. return true; // (change this to false if you choose to not supply an editor)
  177. }
  178. AudioProcessorEditor* LUFSMeterAudioProcessor::createEditor()
  179. {
  180. return new LUFSMeterAudioProcessorEditor (this);
  181. }
  182. //==============================================================================
  183. void LUFSMeterAudioProcessor::getStateInformation (MemoryBlock& destData)
  184. {
  185. // You should use this method to store your parameters in the memory block.
  186. // You could do that either as raw data, or use the XML or ValueTree classes
  187. // as intermediaries to make it easy to save and load complex data.
  188. // Create an outer XML element..
  189. XmlElement xml ("MYPLUGINSETTINGS");
  190. // add some attributes to it..
  191. xml.setAttribute ("uiWidth", lastUIWidth);
  192. xml.setAttribute ("uiHeight", lastUIHeight);
  193. xml.setAttribute ("loudnessBarWidth", int (loudnessBarWidth.getValue()));
  194. xml.setAttribute ("loudnessBarMinValue", int (loudnessBarMinValue.getValue()));
  195. xml.setAttribute ("loudnessBarMaxValue", int (loudnessBarMaxValue.getValue()));
  196. xml.setAttribute("showIntegratedLoudnessHistory", bool (showIntegratedLoudnessHistory.getValue()));
  197. xml.setAttribute("showLoudnessRangeHistory", bool (showLoudnessRangeHistory.getValue()));
  198. xml.setAttribute("showShortTermLoudnessHistory", bool (showShortTermLoudnessHistory.getValue()));
  199. xml.setAttribute("showMomentaryLoudnessHistory", bool (showMomentaryLoudnessHistory.getValue()));
  200. // then use this helper function to stuff it into the binary blob and return it..
  201. copyXmlToBinary (xml, destData);
  202. }
  203. void LUFSMeterAudioProcessor::setStateInformation (const void* data, int sizeInBytes)
  204. {
  205. // You should use this method to restore your parameters from this memory block,
  206. // whose contents will have been created by the getStateInformation() call.
  207. // This getXmlFromBinary() helper function retrieves our XML from the binary blob..
  208. ScopedPointer<XmlElement> xmlState (getXmlFromBinary (data, sizeInBytes));
  209. if (xmlState != 0)
  210. {
  211. // make sure that it's actually our type of XML object..
  212. if (xmlState->hasTagName ("MYPLUGINSETTINGS"))
  213. {
  214. // ok, now pull out our parameters..
  215. lastUIWidth = xmlState->getIntAttribute ("uiWidth", lastUIWidth);
  216. lastUIHeight = xmlState->getIntAttribute ("uiHeight", lastUIHeight);
  217. loudnessBarWidth.setValue (var(xmlState->getIntAttribute("loudnessBarWidth")));
  218. loudnessBarMinValue.setValue (var(xmlState->getIntAttribute("loudnessBarMinValue")));
  219. loudnessBarMaxValue.setValue (var(xmlState->getIntAttribute("loudnessBarMaxValue")));
  220. showIntegratedLoudnessHistory.setValue (var(xmlState->getBoolAttribute("showIntegratedLoudnessHistory")));
  221. showLoudnessRangeHistory.setValue (var(xmlState->getBoolAttribute("showLoudnessRangeHistory")));
  222. showShortTermLoudnessHistory.setValue (var(xmlState->getBoolAttribute("showShortTermLoudnessHistory")));
  223. showMomentaryLoudnessHistory.setValue (var(xmlState->getBoolAttribute("showMomentaryLoudnessHistory")));
  224. }
  225. }
  226. }
  227. void LUFSMeterAudioProcessor::numChannelsChanged()
  228. {
  229. numberOfInputChannels = getTotalNumInputChannels();
  230. DEB("number of input channels = " + String( int(numberOfInputChannels.getValue()) ))
  231. }
  232. float LUFSMeterAudioProcessor::getShortTermLoudness()
  233. {
  234. return ebu128LoudnessMeter.getShortTermLoudness();
  235. }
  236. vector<float>& LUFSMeterAudioProcessor::getMomentaryLoudnessForIndividualChannels()
  237. {
  238. return ebu128LoudnessMeter.getMomentaryLoudnessForIndividualChannels();
  239. }
  240. float LUFSMeterAudioProcessor::getMomentaryLoudness()
  241. {
  242. return ebu128LoudnessMeter.getMomentaryLoudness();
  243. }
  244. float LUFSMeterAudioProcessor::getIntegratedLoudness()
  245. {
  246. return ebu128LoudnessMeter.getIntegratedLoudness();
  247. }
  248. float LUFSMeterAudioProcessor::getLoudnessRangeStart()
  249. {
  250. return ebu128LoudnessMeter.getLoudnessRangeStart();
  251. }
  252. float LUFSMeterAudioProcessor::getLoudnessRangeEnd()
  253. {
  254. return ebu128LoudnessMeter.getLoudnessRangeEnd();
  255. }
  256. float LUFSMeterAudioProcessor::getLoudnessRange()
  257. {
  258. return ebu128LoudnessMeter.getLoudnessRange();
  259. }
  260. //==============================================================================
  261. // This creates new instances of the plugin..
  262. AudioProcessor* JUCE_CALLTYPE createPluginFilter()
  263. {
  264. return new LUFSMeterAudioProcessor();
  265. }
  266. //#ifdef LUFSMETER_STANDALONE
  267. //AudioProcessor* JUCE_CALLTYPE createPluginFilterOfType (AudioProcessor::WrapperType)
  268. //{
  269. // return new LUFSMeterAudioProcessor();
  270. //}
  271. //#endif