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.

173 lines
6.3KB

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