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.

170 lines
6.3KB

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