Audio plugin host https://kx.studio/carla
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.

juce_AudioCDReader.h 6.2KB

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