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.

200 lines
7.1KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2022 - 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 7 End-User License
  8. Agreement and JUCE Privacy Policy.
  9. End User License Agreement: www.juce.com/juce-7-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. //==============================================================================
  21. size_t ARADocument::getNumChildren() const noexcept
  22. {
  23. return getMusicalContexts().size() + getRegionSequences().size() + getAudioSources().size();
  24. }
  25. ARAObject* ARADocument::getChild (size_t index)
  26. {
  27. auto& musicalContexts = getMusicalContexts();
  28. if (index < musicalContexts.size())
  29. return musicalContexts[index];
  30. const auto numMusicalContexts = musicalContexts.size();
  31. auto& regionSequences = getRegionSequences();
  32. if (index < numMusicalContexts + regionSequences.size())
  33. return regionSequences[index - numMusicalContexts];
  34. const auto numMusicalContextsAndRegionSequences = numMusicalContexts + regionSequences.size();
  35. auto& audioSources = getAudioSources();
  36. if (index < numMusicalContextsAndRegionSequences + audioSources.size())
  37. return getAudioSources()[index - numMusicalContextsAndRegionSequences];
  38. return nullptr;
  39. }
  40. //==============================================================================
  41. size_t ARARegionSequence::getNumChildren() const noexcept
  42. {
  43. return 0;
  44. }
  45. ARAObject* ARARegionSequence::getChild (size_t)
  46. {
  47. return nullptr;
  48. }
  49. Range<double> ARARegionSequence::getTimeRange (ARAPlaybackRegion::IncludeHeadAndTail includeHeadAndTail) const
  50. {
  51. if (getPlaybackRegions().empty())
  52. return {};
  53. auto startTime = std::numeric_limits<double>::max();
  54. auto endTime = std::numeric_limits<double>::lowest();
  55. for (const auto& playbackRegion : getPlaybackRegions())
  56. {
  57. const auto regionTimeRange = playbackRegion->getTimeRange (includeHeadAndTail);
  58. startTime = jmin (startTime, regionTimeRange.getStart());
  59. endTime = jmax (endTime, regionTimeRange.getEnd());
  60. }
  61. return { startTime, endTime };
  62. }
  63. double ARARegionSequence::getCommonSampleRate() const
  64. {
  65. const auto getSampleRate = [] (auto* playbackRegion)
  66. {
  67. return playbackRegion->getAudioModification()->getAudioSource()->getSampleRate();
  68. };
  69. const auto range = getPlaybackRegions();
  70. const auto sampleRate = range.size() > 0 ? getSampleRate (range.front()) : 0.0;
  71. if (std::any_of (range.begin(), range.end(), [&] (auto& x) { return getSampleRate (x) != sampleRate; }))
  72. return 0.0;
  73. return sampleRate;
  74. }
  75. //==============================================================================
  76. size_t ARAAudioSource::getNumChildren() const noexcept
  77. {
  78. return getAudioModifications().size();
  79. }
  80. ARAObject* ARAAudioSource::getChild (size_t index)
  81. {
  82. return getAudioModifications()[index];
  83. }
  84. void ARAAudioSource::notifyAnalysisProgressStarted()
  85. {
  86. getDocumentController<ARADocumentController>()->internalNotifyAudioSourceAnalysisProgressStarted (this);
  87. }
  88. void ARAAudioSource::notifyAnalysisProgressUpdated (float progress)
  89. {
  90. getDocumentController<ARADocumentController>()->internalNotifyAudioSourceAnalysisProgressUpdated (this, progress);
  91. }
  92. void ARAAudioSource::notifyAnalysisProgressCompleted()
  93. {
  94. getDocumentController<ARADocumentController>()->internalNotifyAudioSourceAnalysisProgressCompleted (this);
  95. }
  96. void ARAAudioSource::notifyContentChanged (ARAContentUpdateScopes scopeFlags, bool notifyARAHost)
  97. {
  98. getDocumentController<ARADocumentController>()->internalNotifyAudioSourceContentChanged (this,
  99. scopeFlags,
  100. notifyARAHost);
  101. }
  102. //==============================================================================
  103. size_t ARAAudioModification::getNumChildren() const noexcept
  104. {
  105. return getPlaybackRegions().size();
  106. }
  107. ARAObject* ARAAudioModification::getChild (size_t index)
  108. {
  109. return getPlaybackRegions()[index];
  110. }
  111. void ARAAudioModification::notifyContentChanged (ARAContentUpdateScopes scopeFlags, bool notifyARAHost)
  112. {
  113. getDocumentController<ARADocumentController>()->internalNotifyAudioModificationContentChanged (this,
  114. scopeFlags,
  115. notifyARAHost);
  116. }
  117. //==============================================================================
  118. ARAObject* ARAPlaybackRegion::getParent() { return getAudioModification(); }
  119. Range<double> ARAPlaybackRegion::getTimeRange (IncludeHeadAndTail includeHeadAndTail) const
  120. {
  121. auto startTime = getStartInPlaybackTime();
  122. auto endTime = getEndInPlaybackTime();
  123. if (includeHeadAndTail == IncludeHeadAndTail::yes)
  124. {
  125. ARA::ARATimeDuration headTime {}, tailTime {};
  126. getDocumentController()->getPlaybackRegionHeadAndTailTime (toRef (this), &headTime, &tailTime);
  127. startTime -= headTime;
  128. endTime += tailTime;
  129. }
  130. return { startTime, endTime };
  131. }
  132. Range<int64> ARAPlaybackRegion::getSampleRange (double sampleRate, IncludeHeadAndTail includeHeadAndTail) const
  133. {
  134. const auto timeRange = getTimeRange (includeHeadAndTail);
  135. return { ARA::samplePositionAtTime (timeRange.getStart(), sampleRate),
  136. ARA::samplePositionAtTime (timeRange.getEnd(), sampleRate) };
  137. }
  138. double ARAPlaybackRegion::getHeadTime() const
  139. {
  140. ARA::ARATimeDuration headTime {}, tailTime {};
  141. getDocumentController()->getPlaybackRegionHeadAndTailTime (toRef (this), &headTime, &tailTime);
  142. return headTime;
  143. }
  144. double ARAPlaybackRegion::getTailTime() const
  145. {
  146. ARA::ARATimeDuration headTime {}, tailTime {};
  147. getDocumentController()->getPlaybackRegionHeadAndTailTime (toRef (this), &headTime, &tailTime);
  148. return tailTime;
  149. }
  150. void ARAPlaybackRegion::notifyContentChanged (ARAContentUpdateScopes scopeFlags, bool notifyARAHost)
  151. {
  152. getDocumentController<ARADocumentController>()->internalNotifyPlaybackRegionContentChanged (this,
  153. scopeFlags,
  154. notifyARAHost);
  155. }
  156. } // namespace juce