Vectorscope.cpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * Vectorscope.cpp - definition of Vectorscope class.
  3. *
  4. * Copyright (c) 2019 Martin Pavelek <he29/dot/HS/at/gmail/dot/com>
  5. *
  6. * This file is part of LMMS - https://lmms.io
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2 of the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public
  19. * License along with this program (see COPYING); if not, write to the
  20. * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  21. * Boston, MA 02110-1301 USA.
  22. *
  23. */
  24. #include "Vectorscope.h"
  25. #include "embed.h"
  26. #include "plugin_export.h"
  27. extern "C" {
  28. Plugin::Descriptor PLUGIN_EXPORT vectorscope_plugin_descriptor =
  29. {
  30. STRINGIFY(PLUGIN_NAME),
  31. "Vectorscope",
  32. QT_TRANSLATE_NOOP("PluginBrowser", "A stereo field visualizer."),
  33. "Martin Pavelek <he29/dot/HS/at/gmail/dot/com>",
  34. 0x0100,
  35. Plugin::Effect,
  36. new PluginPixmapLoader("logo"),
  37. NULL,
  38. NULL
  39. };
  40. }
  41. Vectorscope::Vectorscope(Model *parent, const Plugin::Descriptor::SubPluginFeatures::Key *key) :
  42. Effect(&vectorscope_plugin_descriptor, parent, key),
  43. m_controls(this),
  44. // Buffer is sized to cover 4* the current maximum LMMS audio buffer size,
  45. // so that it has some reserve space in case GUI thresd is busy.
  46. m_inputBuffer(4 * m_maxBufferSize)
  47. {
  48. }
  49. // Take audio data and store them for processing and display in the GUI thread.
  50. bool Vectorscope::processAudioBuffer(sampleFrame *buffer, const fpp_t frame_count)
  51. {
  52. if (!isEnabled() || !isRunning ()) {return false;}
  53. // Skip processing if the controls dialog isn't visible, it would only waste CPU cycles.
  54. if (m_controls.isViewVisible())
  55. {
  56. // To avoid processing spikes on audio thread, data are stored in
  57. // a lockless ringbuffer and processed in a separate thread.
  58. m_inputBuffer.write(buffer, frame_count);
  59. }
  60. return isRunning();
  61. }
  62. extern "C" {
  63. // needed for getting plugin out of shared lib
  64. PLUGIN_EXPORT Plugin *lmms_plugin_main(Model *parent, void *data)
  65. {
  66. return new Vectorscope(parent, static_cast<const Plugin::Descriptor::SubPluginFeatures::Key *>(data));
  67. }
  68. }