Analyzer.cpp 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * Analyzer.cpp - definition of Analyzer class.
  3. *
  4. * Copyright (c) 2019 Martin Pavelek <he29/dot/HS/at/gmail/dot/com>
  5. *
  6. * Based partially on Eq plugin code,
  7. * Copyright (c) 2014-2017, David French <dave/dot/french3/at/googlemail/dot/com>
  8. *
  9. * This file is part of LMMS - https://lmms.io
  10. *
  11. * This program is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU General Public
  13. * License as published by the Free Software Foundation; either
  14. * version 2 of the License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  19. * General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public
  22. * License along with this program (see COPYING); if not, write to the
  23. * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  24. * Boston, MA 02110-1301 USA.
  25. *
  26. */
  27. #include "Analyzer.h"
  28. #include "embed.h"
  29. #include "plugin_export.h"
  30. extern "C" {
  31. Plugin::Descriptor PLUGIN_EXPORT analyzer_plugin_descriptor =
  32. {
  33. "spectrumanalyzer",
  34. "Spectrum Analyzer",
  35. QT_TRANSLATE_NOOP("pluginBrowser", "A graphical spectrum analyzer."),
  36. "Martin Pavelek <he29/dot/HS/at/gmail/dot/com>",
  37. 0x0100,
  38. Plugin::Effect,
  39. new PluginPixmapLoader("logo"),
  40. NULL,
  41. NULL
  42. };
  43. }
  44. Analyzer::Analyzer(Model *parent, const Plugin::Descriptor::SubPluginFeatures::Key *key) :
  45. Effect(&analyzer_plugin_descriptor, parent, key),
  46. m_processor(&m_controls),
  47. m_controls(this)
  48. {
  49. }
  50. // Take audio data and pass them to the spectrum processor.
  51. // Skip processing if the controls dialog isn't visible, it would only waste CPU cycles.
  52. bool Analyzer::processAudioBuffer(sampleFrame *buffer, const fpp_t frame_count)
  53. {
  54. if (!isEnabled() || !isRunning ()) {return false;}
  55. if (m_controls.isViewVisible()) {m_processor.analyse(buffer, frame_count);}
  56. return isRunning();
  57. }
  58. extern "C" {
  59. // needed for getting plugin out of shared lib
  60. PLUGIN_EXPORT Plugin *lmms_plugin_main(Model *parent, void *data)
  61. {
  62. return new Analyzer(parent, static_cast<const Plugin::Descriptor::SubPluginFeatures::Key *>(data));
  63. }
  64. }