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.

149 lines
6.0KB

  1. /*
  2. ==============================================================================
  3. This file is part of the dRowAudio JUCE module
  4. Copyright 2004-13 by dRowAudio.
  5. ------------------------------------------------------------------------------
  6. dRowAudio is provided under the terms of The MIT License (MIT):
  7. Permission is hereby granted, free of charge, to any person obtaining a copy
  8. of this software and associated documentation files (the "Software"), to deal
  9. in the Software without restriction, including without limitation the rights
  10. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. copies of the Software, and to permit persons to whom the Software is
  12. furnished to do so, subject to the following conditions:
  13. The above copyright notice and this permission notice shall be included in all
  14. copies or substantial portions of the Software.
  15. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  21. SOFTWARE.
  22. ==============================================================================
  23. */
  24. #ifndef __DROWAUDIO_ITUNESLIBRARY_H__
  25. #define __DROWAUDIO_ITUNESLIBRARY_H__
  26. #include "dRowAudio_ITunesLibraryParser.h"
  27. //==============================================================================
  28. /** An ITunesLibrary manages the parsing of an iTunes library into a ValueTree.
  29. You can register yourselves as a listener to recieve callbacks when its
  30. content has changed. You can also load a previously generated library tree
  31. for data to me merged into if it is newer.
  32. For an example of its use see the MusicLibraryTable class.
  33. */
  34. class ITunesLibrary : public Timer,
  35. public DeletedAtShutdown
  36. {
  37. public:
  38. //==============================================================================
  39. juce_DeclareSingleton (ITunesLibrary, false);
  40. /** Creates an ITunesLibrary.
  41. This class can also be used as a singleton which may be more appropriate.
  42. To start the parsing use the setLibraryFile method.
  43. */
  44. ITunesLibrary();
  45. /** Destructor. */
  46. ~ITunesLibrary();
  47. /** Sets a new library to base the ValueTree on and starts the parse.
  48. This will merge new data into the tree if a valid tree has been set with
  49. the setLibraryTree method. This will preseve any child trees that may have
  50. been added e.g. those holding loop or cue data.
  51. */
  52. void setLibraryFile (File newFile);
  53. /** Returns the file that this library was generated from.
  54. */
  55. const File& getLibraryFile() { return libraryFile; }
  56. /** This can be used to load a previously saved iTuneLibarary.
  57. This has to be in the same format as that generated by this class.
  58. If the tree passed in is invalid, it will create a new, valid one.
  59. */
  60. void setLibraryTree (ValueTree& newTreeToUse);
  61. /** Returns the ValueTree that is being filled.
  62. */
  63. ValueTree getLibraryTree() { return libraryTree; }
  64. /** Returns the lock being used in the parser.
  65. Bear in mind that if the parser has finished and been deleted this will be
  66. an unused lock so is not worth using it.
  67. */
  68. inline const CriticalSection& getParserLock() { return parserLock; }
  69. //==============================================================================
  70. /** This returns the default iTunes library file.
  71. E.g. on Mac this will be something like:
  72. "/Users/username/Music/iTunes/iTunes Music Library.xml"
  73. */
  74. static const File getDefaultITunesLibraryFile();
  75. //==============================================================================
  76. /** A class for receiving callbacks from an ITunesLibrary.
  77. This will repeatedly call libraryUpdated so you can respond to any changes
  78. that may have happened until a single call to libraryFinished() where you
  79. may want to do some additional set-up.
  80. @see ITunesLibrary::addListener, ITunesLibrary::removeListener
  81. */
  82. class Listener
  83. {
  84. public:
  85. //==============================================================================
  86. /** Destructor. */
  87. virtual ~Listener() {}
  88. //==============================================================================
  89. /** Called when the library file has changed, before it starts updating itself.
  90. Use this callback to initialise any data storage you may be holding.
  91. */
  92. virtual void libraryChanged (ITunesLibrary* /*library*/) {};
  93. /** Called when the library has been updated.
  94. */
  95. virtual void libraryUpdated (ITunesLibrary* library) = 0;
  96. /** Called when the library has finished updating.
  97. */
  98. virtual void libraryFinished (ITunesLibrary* /*library*/) {}
  99. };
  100. /** Adds a listener to be called when this slider's value changes. */
  101. void addListener (Listener* listener);
  102. /** Removes a previously-registered listener. */
  103. void removeListener (Listener* listener);
  104. //==============================================================================
  105. /** @internal */
  106. void timerCallback();
  107. private:
  108. //==============================================================================
  109. const CriticalSection parserLock;
  110. ListenerList <Listener> listeners;
  111. File libraryFile;
  112. ScopedPointer<ITunesLibraryParser> parser;
  113. ValueTree libraryTree;
  114. //==============================================================================
  115. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ITunesLibrary);
  116. };
  117. #endif // __DROWAUDIO_ITUNESLIBRARY_H__