The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
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.

168 lines
6.3KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2015 - ROLI Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. #pragma once
  18. #if JUCE_USE_CDBURNER || DOXYGEN
  19. //==============================================================================
  20. /**
  21. */
  22. class AudioCDBurner : public ChangeBroadcaster
  23. {
  24. public:
  25. //==============================================================================
  26. /** Returns a list of available optical drives.
  27. Use openDevice() to open one of the items from this list.
  28. */
  29. static StringArray findAvailableDevices();
  30. /** Tries to open one of the optical drives.
  31. The deviceIndex is an index into the array returned by findAvailableDevices().
  32. */
  33. static AudioCDBurner* openDevice (const int deviceIndex);
  34. /** Destructor. */
  35. ~AudioCDBurner();
  36. //==============================================================================
  37. enum DiskState
  38. {
  39. unknown, /**< An error condition, if the device isn't responding. */
  40. trayOpen, /**< The drive is currently open. Note that a slot-loading drive
  41. may seem to be permanently open. */
  42. noDisc, /**< The drive has no disk in it. */
  43. writableDiskPresent, /**< The drive contains a writeable disk. */
  44. readOnlyDiskPresent /**< The drive contains a read-only disk. */
  45. };
  46. /** Returns the current status of the device.
  47. To get informed when the drive's status changes, attach a ChangeListener to
  48. the AudioCDBurner.
  49. */
  50. DiskState getDiskState() const;
  51. /** Returns true if there's a writable disk in the drive. */
  52. bool isDiskPresent() const;
  53. /** Sends an eject signal to the drive.
  54. The eject will happen asynchronously, so you can use getDiskState() and
  55. waitUntilStateChange() to monitor its progress.
  56. */
  57. bool openTray();
  58. /** Blocks the current thread until the drive's state changes, or until the timeout expires.
  59. @returns the device's new state
  60. */
  61. DiskState waitUntilStateChange (int timeOutMilliseconds);
  62. //==============================================================================
  63. /** Returns the set of possible write speeds that the device can handle.
  64. These are as a multiple of 'normal' speed, so e.g. '24x' returns 24, etc.
  65. Note that if there's no media present in the drive, this value may be unavailable!
  66. @see setWriteSpeed, getWriteSpeed
  67. */
  68. Array<int> getAvailableWriteSpeeds() const;
  69. //==============================================================================
  70. /** Tries to enable or disable buffer underrun safety on devices that support it.
  71. @returns true if it's now enabled. If the device doesn't support it, this
  72. will always return false.
  73. */
  74. bool setBufferUnderrunProtection (bool shouldBeEnabled);
  75. //==============================================================================
  76. /** Returns the number of free blocks on the disk.
  77. There are 75 blocks per second, at 44100Hz.
  78. */
  79. int getNumAvailableAudioBlocks() const;
  80. /** Adds a track to be written.
  81. The source passed-in here will be kept by this object, and it will
  82. be used and deleted at some point in the future, either during the
  83. burn() method or when this AudioCDBurner object is deleted. Your caller
  84. method shouldn't keep a reference to it or use it again after passing
  85. it in here.
  86. */
  87. bool addAudioTrack (AudioSource* source, int numSamples);
  88. //==============================================================================
  89. /** Receives progress callbacks during a cd-burn operation.
  90. @see AudioCDBurner::burn()
  91. */
  92. class BurnProgressListener
  93. {
  94. public:
  95. BurnProgressListener() noexcept {}
  96. virtual ~BurnProgressListener() {}
  97. /** Called at intervals to report on the progress of the AudioCDBurner.
  98. To cancel the burn, return true from this method.
  99. */
  100. virtual bool audioCDBurnProgress (float proportionComplete) = 0;
  101. };
  102. /** Runs the burn process.
  103. This method will block until the operation is complete.
  104. @param listener the object to receive callbacks about progress
  105. @param ejectDiscAfterwards whether to eject the disk after the burn completes
  106. @param performFakeBurnForTesting if true, no data will actually be written to the disk
  107. @param writeSpeed one of the write speeds from getAvailableWriteSpeeds(), or
  108. 0 or less to mean the fastest speed.
  109. */
  110. String burn (BurnProgressListener* listener,
  111. bool ejectDiscAfterwards,
  112. bool performFakeBurnForTesting,
  113. int writeSpeed);
  114. /** If a burn operation is currently in progress, this tells it to stop
  115. as soon as possible.
  116. It's also possible to stop the burn process by returning true from
  117. BurnProgressListener::audioCDBurnProgress()
  118. */
  119. void abortBurn();
  120. private:
  121. //==============================================================================
  122. AudioCDBurner (const int deviceIndex);
  123. class Pimpl;
  124. friend struct ContainerDeletePolicy<Pimpl>;
  125. ScopedPointer<Pimpl> pimpl;
  126. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (AudioCDBurner)
  127. };
  128. #endif