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.

111 lines
4.4KB

  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_GRAPHICALCOMPONENT_H__
  25. #define __DROWAUDIO_GRAPHICALCOMPONENT_H__
  26. //==============================================================================
  27. /** This class is an abstract base blass for some kind of graphical component
  28. that requires some intenisve processing.
  29. Inherit your class from this then register it with a TimeSliceThread
  30. to continually call the process() method where you can do your required
  31. processing on a background thread to avoid blocking the Message thread for too long.
  32. @see SegmentedMeter
  33. */
  34. class GraphicalComponent : public Component,
  35. public TimeSliceClient,
  36. public Timer
  37. {
  38. protected:
  39. //==============================================================================
  40. /** Creates a GraphicalComponent.
  41. Don't instantiate directly, use as a base class.
  42. */
  43. GraphicalComponent();
  44. public:
  45. //==============================================================================
  46. /** Destructor.
  47. */
  48. ~GraphicalComponent();
  49. /** Overload to do your processing.
  50. Once registered with a GraphicalComponentManager this will repeatedly get called.
  51. To save CPU cycles this will only get called if paused is false and some new data
  52. has been set with copySamples(). The idea is that you push some new data to your
  53. class with copySamples() then do whatever processing you require here.
  54. */
  55. virtual void process() = 0;
  56. /** Pauses the processing of the GraphicalComponent.
  57. */
  58. void pause (bool shouldPause) { paused = shouldPause; }
  59. /** Returns true if the processing is currently suspended.
  60. */
  61. bool isPaused() { return paused; }
  62. //==============================================================================
  63. /** Copies data to the component to use.
  64. This should be as quick as possible as is accessed from what
  65. ever thread calls it so could cause blocking.
  66. By default this just copys the values passed to it into the samples heap block,
  67. extending the memory if needed. You can overide this for more specialised behaviour.
  68. */
  69. virtual void copySamples (const float* values, int numSamples);
  70. /** Copies data from a number of channels to the component to use.
  71. This is a lot slower than copySamples(float *values, int numSamples) but if the
  72. number of channels is 2 it will use the maximum sample from the pair of channels.
  73. */
  74. virtual void copySamples (float** values, int numSamples, int numChannels);
  75. /** @internal */
  76. int useTimeSlice();
  77. /** @internal */
  78. void timerCallback() {}
  79. protected:
  80. //==============================================================================
  81. CriticalSection lock;
  82. bool paused;
  83. bool needToProcess;
  84. int sleepTime, numSamples;
  85. HeapBlock<float> samples;
  86. //==============================================================================
  87. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (GraphicalComponent);
  88. };
  89. #endif // __DROWAUDIO_GRAPHICALCOMPONENT_H__