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.

193 lines
6.8KB

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