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.

178 lines
6.1KB

  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_CDREADER || DOXYGEN
  21. //==============================================================================
  22. /**
  23. A type of AudioFormatReader that reads from an audio CD.
  24. One of these can be used to read a CD as if it's one big audio stream. Use the
  25. getPositionOfTrackStart() method to find where the individual tracks are
  26. within the stream.
  27. @see AudioFormatReader
  28. @tags{Audio}
  29. */
  30. class JUCE_API AudioCDReader : public AudioFormatReader
  31. {
  32. public:
  33. //==============================================================================
  34. /** Returns a list of names of Audio CDs currently available for reading.
  35. If there's a CD drive but no CD in it, this might return an empty list, or
  36. possibly a device that can be opened but which has no tracks, depending
  37. on the platform.
  38. @see createReaderForCD
  39. */
  40. static StringArray getAvailableCDNames();
  41. /** Tries to create an AudioFormatReader that can read from an Audio CD.
  42. @param index the index of one of the available CDs - use getAvailableCDNames()
  43. to find out how many there are.
  44. @returns a new AudioCDReader object, or nullptr if it couldn't be created. The
  45. caller will be responsible for deleting the object returned.
  46. */
  47. static AudioCDReader* createReaderForCD (const int index);
  48. //==============================================================================
  49. /** Destructor. */
  50. ~AudioCDReader() override;
  51. /** Implementation of the AudioFormatReader method. */
  52. bool readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  53. int64 startSampleInFile, int numSamples) override;
  54. /** Checks whether the CD has been removed from the drive. */
  55. bool isCDStillPresent() const;
  56. /** Returns the total number of tracks (audio + data). */
  57. int getNumTracks() const;
  58. /** Finds the sample offset of the start of a track.
  59. @param trackNum the track number, where trackNum = 0 is the first track
  60. and trackNum = getNumTracks() means the end of the CD.
  61. */
  62. int getPositionOfTrackStart (int trackNum) const;
  63. /** Returns true if a given track is an audio track.
  64. @param trackNum the track number, where 0 is the first track.
  65. */
  66. bool isTrackAudio (int trackNum) const;
  67. /** Returns an array of sample offsets for the start of each track, followed by
  68. the sample position of the end of the CD.
  69. */
  70. const Array<int>& getTrackOffsets() const;
  71. /** Refreshes the object's table of contents.
  72. If the disc has been ejected and a different one put in since this
  73. object was created, this will cause it to update its idea of how many tracks
  74. there are, etc.
  75. */
  76. void refreshTrackLengths();
  77. /** Enables scanning for indexes within tracks.
  78. @see getLastIndex
  79. */
  80. void enableIndexScanning (bool enabled);
  81. /** Returns the index number found during the last read() call.
  82. Index scanning is turned off by default - turn it on with enableIndexScanning().
  83. Then when the read() method is called, if it comes across an index within that
  84. block, the index number is stored and returned by this method.
  85. Some devices might not support indexes, of course.
  86. (If you don't know what CD indexes are, it's unlikely you'll ever need them).
  87. @see enableIndexScanning
  88. */
  89. int getLastIndex() const;
  90. /** Scans a track to find the position of any indexes within it.
  91. @param trackNumber the track to look in, where 0 is the first track on the disc
  92. @returns an array of sample positions of any index points found (not including
  93. the index that marks the start of the track)
  94. */
  95. Array<int> findIndexesInTrack (const int trackNumber);
  96. /** Returns the CDDB id number for the CD.
  97. It's not a great way of identifying a disc, but it's traditional.
  98. */
  99. int getCDDBId();
  100. /** Tries to eject the disk.
  101. Ejecting the disk might not actually be possible, e.g. if some other process is using it.
  102. */
  103. void ejectDisk();
  104. //==============================================================================
  105. enum
  106. {
  107. framesPerSecond = 75,
  108. samplesPerFrame = 44100 / framesPerSecond
  109. };
  110. private:
  111. //==============================================================================
  112. Array<int> trackStartSamples;
  113. #if JUCE_MAC
  114. File volumeDir;
  115. Array<File> tracks;
  116. int currentReaderTrack;
  117. std::unique_ptr<AudioFormatReader> reader;
  118. AudioCDReader (const File& volume);
  119. #elif JUCE_WINDOWS
  120. bool audioTracks [100];
  121. void* handle;
  122. MemoryBlock buffer;
  123. bool indexingEnabled;
  124. int lastIndex, firstFrameInBuffer, samplesInBuffer;
  125. AudioCDReader (void* handle);
  126. int getIndexAt (int samplePos);
  127. #elif JUCE_LINUX || JUCE_BSD
  128. AudioCDReader();
  129. #endif
  130. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (AudioCDReader)
  131. };
  132. #endif
  133. } // namespace juce