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.

185 lines
6.3KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-9 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. #ifndef __JUCE_AUDIOCDREADER_JUCEHEADER__
  19. #define __JUCE_AUDIOCDREADER_JUCEHEADER__
  20. #if JUCE_USE_CDREADER
  21. #include "juce_AudioFormatReader.h"
  22. #include "../../containers/juce_Array.h"
  23. #include "../../text/juce_StringArray.h"
  24. #if JUCE_MAC
  25. #include "../../io/files/juce_File.h"
  26. #endif
  27. //==============================================================================
  28. /**
  29. A type of AudioFormatReader that reads from an audio CD.
  30. One of these can be used to read a CD as if it's one big audio stream. Use the
  31. getPositionOfTrackStart() method to find where the individual tracks are
  32. within the stream.
  33. @see AudioFormatReader
  34. */
  35. class JUCE_API AudioCDReader : public AudioFormatReader
  36. {
  37. public:
  38. //==============================================================================
  39. /** Returns a list of names of Audio CDs currently available for reading.
  40. If there's a CD drive but no CD in it, this might return an empty list, or
  41. possibly a device that can be opened but which has no tracks, depending
  42. on the platform.
  43. @see createReaderForCD
  44. */
  45. static const StringArray getAvailableCDNames();
  46. /** Tries to create an AudioFormatReader that can read from an Audio CD.
  47. @param index the index of one of the available CDs - use getAvailableCDNames()
  48. to find out how many there are.
  49. @returns a new AudioCDReader object, or 0 if it couldn't be created. The
  50. caller will be responsible for deleting the object returned.
  51. */
  52. static AudioCDReader* createReaderForCD (const int index);
  53. //==============================================================================
  54. /** Destructor. */
  55. ~AudioCDReader();
  56. /** Implementation of the AudioFormatReader method. */
  57. bool readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  58. int64 startSampleInFile, int numSamples);
  59. /** Checks whether the CD has been removed from the drive.
  60. */
  61. bool isCDStillPresent() const;
  62. /** Returns the total number of tracks (audio + data).
  63. */
  64. int getNumTracks() const;
  65. /** Finds the sample offset of the start of a track.
  66. @param trackNum the track number, where 0 is the first track.
  67. */
  68. int getPositionOfTrackStart (int trackNum) const;
  69. /** Returns true if a given track is an audio track.
  70. @param trackNum the track number, where 0 is the first track.
  71. */
  72. bool isTrackAudio (int trackNum) const;
  73. /** Refreshes the object's table of contents.
  74. If the disc has been ejected and a different one put in since this
  75. object was created, this will cause it to update its idea of how many tracks
  76. there are, etc.
  77. */
  78. void refreshTrackLengths();
  79. /** Enables scanning for indexes within tracks.
  80. @see getLastIndex
  81. */
  82. void enableIndexScanning (bool enabled);
  83. /** Returns the index number found during the last read() call.
  84. Index scanning is turned off by default - turn it on with enableIndexScanning().
  85. Then when the read() method is called, if it comes across an index within that
  86. block, the index number is stored and returned by this method.
  87. Some devices might not support indexes, of course.
  88. (If you don't know what CD indexes are, it's unlikely you'll ever need them).
  89. @see enableIndexScanning
  90. */
  91. int getLastIndex() const;
  92. /** Scans a track to find the position of any indexes within it.
  93. @param trackNumber the track to look in, where 0 is the first track on the disc
  94. @returns an array of sample positions of any index points found (not including
  95. the index that marks the start of the track)
  96. */
  97. const Array <int> findIndexesInTrack (const int trackNumber);
  98. /** Returns the CDDB id number for the CD.
  99. It's not a great way of identifying a disc, but it's traditional.
  100. */
  101. int getCDDBId();
  102. /** Tries to eject the disk.
  103. Of course this might not be possible, if some other process is using it.
  104. */
  105. void ejectDisk();
  106. //==============================================================================
  107. juce_UseDebuggingNewOperator
  108. private:
  109. #if JUCE_MAC
  110. File volumeDir;
  111. OwnedArray<File> tracks;
  112. Array <int> trackStartSamples;
  113. int currentReaderTrack;
  114. ScopedPointer <AudioFormatReader> reader;
  115. AudioCDReader (const File& volume);
  116. public:
  117. static int compareElements (const File* const, const File* const) throw();
  118. private:
  119. #elif JUCE_WINDOWS
  120. int numTracks;
  121. int trackStarts[100];
  122. bool audioTracks [100];
  123. void* handle;
  124. bool indexingEnabled;
  125. int lastIndex, firstFrameInBuffer, samplesInBuffer;
  126. MemoryBlock buffer;
  127. AudioCDReader (void* handle);
  128. int getIndexAt (int samplePos);
  129. #elif JUCE_LINUX
  130. AudioCDReader();
  131. #endif
  132. AudioCDReader (const AudioCDReader&);
  133. const AudioCDReader& operator= (const AudioCDReader&);
  134. };
  135. #endif
  136. #endif // __JUCE_AUDIOCDREADER_JUCEHEADER__