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.

172 lines
5.8KB

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