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.

130 lines
4.7KB

  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_POSITIONALWAVEDISPLAY_H__
  25. #define __DROWAUDIO_POSITIONALWAVEDISPLAY_H__
  26. //====================================================================================
  27. /**
  28. A class to display the entire waveform of an audio file.
  29. This will load an audio file and display its waveform. Clicking on the waveform will
  30. reposition the transport source.
  31. */
  32. class PositionableWaveDisplay : public Component,
  33. public AudioThumbnailImage::Listener,
  34. public TimeSliceClient,
  35. public AsyncUpdater
  36. {
  37. public:
  38. //====================================================================================
  39. /** Creates the display.
  40. The AudioThumbnailImage associated with the display must be passed in.
  41. */
  42. explicit PositionableWaveDisplay (AudioThumbnailImage& sourceToBeUsed,
  43. TimeSliceThread& threadToUse);
  44. /** Destructor.
  45. */
  46. ~PositionableWaveDisplay();
  47. //====================================================================================
  48. /** Sets whether or not the transport cursor should be displayed;
  49. */
  50. void setCursorDisplayed (bool shoudldDisplayCursor);
  51. /** Sets the colour to use for the background.
  52. */
  53. void setBackgroundColour (const Colour& newBackgroundColour);
  54. /** Sets the colour to use for the waveform.
  55. */
  56. void setWaveformColour (const Colour& newWaveformColour);
  57. /** Sets the current horizontal zoom.
  58. 1.0 displays the whole waveform, 0.5 will show half etc.
  59. */
  60. void setZoomRatio (double newZoomRatio);
  61. /** Sets an offset used to start the waveform at a faction of the display.
  62. A value of 0.5 will show the waveform starting at the halfway point etc.
  63. */
  64. void setStartOffsetRatio (double newStartOffsetRatio);
  65. /** Sets a new vertical zoom ratio.
  66. Values greater than 1.0 will expand the waveform vertically, less will contract it.
  67. */
  68. void setVerticalZoomRatio (double newVerticalZoomRatio);
  69. //====================================================================================
  70. /** @internal */
  71. void imageChanged (AudioThumbnailImage* audioThumbnailImage);
  72. //====================================================================================
  73. /** @internal */
  74. void resized ();
  75. /** @internal */
  76. void paint (Graphics &g);
  77. /** @internal */
  78. int useTimeSlice();
  79. /** @internal */
  80. void handleAsyncUpdate();
  81. private:
  82. //==============================================================================
  83. AudioThumbnailImage& audioThumbnailImage;
  84. TimeSliceThread& threadToUse;
  85. CriticalSection imageLock;
  86. AudioFilePlayer& audioFilePlayer;
  87. double fileLength, oneOverFileLength, currentSampleRate;
  88. double zoomRatio, startOffsetRatio, verticalZoomRatio;
  89. Colour backgroundColour, waveformColour;
  90. Image cachedImage, cursorImage;
  91. StateVariable<double> drawTimes;
  92. AudioTransportCursor audioTransportCursor;
  93. //==============================================================================
  94. void refreshCachedImage();
  95. //==============================================================================
  96. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (PositionableWaveDisplay);
  97. };
  98. #endif //__DROWAUDIO_POSITIONALWAVEDISPLAY_H__