Skip to content

Commit

Permalink
Add ARA regions to renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
FangCunWuChang committed Sep 15, 2024
1 parent 268a33c commit 66b49cf
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 29 deletions.
3 changes: 2 additions & 1 deletion src/audioCore/graph/PluginDecorator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ void PluginDecorator::setARA(

/** Create ARA Virtual Document */
this->araVirtualDocument = std::make_unique<ARAVirtualDocument>(
this->seq, this->araDocumentController->getDocumentController());
this->seq, this->araDocumentController->getDocumentController(),
this->araEditorRenderer, this->araPlaybackRenderer);
this->araVirtualDocument->update();
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/audioCore/misc/ARAController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ bool ARAContentAccessController::isMusicalContextContentAvailable(
ARA::ARAMusicalContextHostRef musicalContextHostRef,
ARA::ARAContentType type) noexcept {
auto midiContext = ContextConverter::fromHostRef(musicalContextHostRef);

return midiContext->getType() == (ARAExtension::ARAContentType)type
&& this->allowedContentTypes.contains((ARAExtension::ARAContentType)type);
}
Expand Down Expand Up @@ -127,6 +128,7 @@ ARA::ARAInt32 ARAContentAccessController::getContentReaderEventCount(
auto contextReader = Converter::fromHostRef(contentReaderHostRef);
if (contextReader->contextHostRef) {
auto midiContext = ContextConverter::fromHostRef(contextReader->contextHostRef);

return midiContext->getEventCount();
}

Expand Down
36 changes: 19 additions & 17 deletions src/audioCore/misc/ARAObjects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,8 @@ ARAVirtualMusicalContextRegionSequence::createProperties(
auto properties = juce::ARAHostModel::RegionSequence::getEmptyProperties();

if (seq) {
properties.name = seq->getTrackName().toRawUTF8();
auto trackName = seq->getTrackName();
properties.name = trackName.isNotEmpty() ? trackName.toRawUTF8() : "Untitled Track";

auto seqColor = seq->getTrackColor();
color->r = seqColor.getFloatRed();
Expand All @@ -622,34 +623,29 @@ ARAVirtualMusicalContextRegionSequence::createProperties(
ARAVirtualAudioSourceRegionSequence::ARAVirtualAudioSourceRegionSequence(
ARA::Host::DocumentController& dc,
SeqSourceProcessor* seq,
ARAVirtualAudioModification& modification,
ARAVirtualMusicalContext& emptyContext)
: ARAVirtualRegionSequence(dc, seq,
ARAVirtualAudioSourceRegionSequence::createProperties(
seq, &(this->color), modification, emptyContext)),
modification(modification), emptyContext(emptyContext) {}
seq, &(this->color), emptyContext)),
emptyContext(emptyContext) {}

void ARAVirtualAudioSourceRegionSequence::update() {
this->regionSequence.update(
ARAVirtualAudioSourceRegionSequence::createProperties(
this->seq, &(this->color), this->modification, this->emptyContext));
}

ARAVirtualAudioModification& ARAVirtualAudioSourceRegionSequence::getModification() {
return this->modification;
this->seq, &(this->color), this->emptyContext));
}

ARAVirtualMusicalContext& ARAVirtualAudioSourceRegionSequence::getEmptyContext() {
return this->emptyContext;
}

const ARA::ARARegionSequenceProperties ARAVirtualAudioSourceRegionSequence::createProperties(
SeqSourceProcessor* seq, ARA::ARAColor* color,
ARAVirtualAudioModification& /*modification*/, ARAVirtualMusicalContext& emptyContext) {
SeqSourceProcessor* seq, ARA::ARAColor* color, ARAVirtualMusicalContext& emptyContext) {
auto properties = juce::ARAHostModel::RegionSequence::getEmptyProperties();

if (seq) {
properties.name = seq->getTrackName().toRawUTF8();
auto trackName = seq->getTrackName();
properties.name = trackName.isNotEmpty() ? trackName.toRawUTF8() : "Untitled Track";

auto seqColor = seq->getTrackColor();
color->r = seqColor.getFloatRed();
Expand All @@ -668,9 +664,13 @@ ARAVirtualPlaybackRegion::ARAVirtualPlaybackRegion(
ARAVirtualRegionSequence& sequence,
ARAVirtualAudioModification& modification,
const ARA::ARAPlaybackRegionProperties& properties)
: sequence(sequence),
: sequence(sequence), modification(modification),
playbackRegion(Converter::toHostRef(this), dc, modification.getProperties(), properties) {}

ARAVirtualAudioModification& ARAVirtualPlaybackRegion::getModification() {
return this->modification;
}

juce::ARAHostModel::PlaybackRegion& ARAVirtualPlaybackRegion::getProperties() {
return this->playbackRegion;
}
Expand All @@ -681,19 +681,21 @@ ARAVirtualAudioPlaybackRegion::ARAVirtualAudioPlaybackRegion(
ARAVirtualAudioModification& modification)
: ARAVirtualPlaybackRegion(dc, sequence, modification,
ARAVirtualAudioPlaybackRegion::createProperties(
dynamic_cast<ARAVirtualAudioSourceRegionSequence&>(sequence))) {}
dynamic_cast<ARAVirtualAudioSourceRegionSequence&>(sequence), modification)) {}

void ARAVirtualAudioPlaybackRegion::update() {
this->playbackRegion.update(
ARAVirtualAudioPlaybackRegion::createProperties(
dynamic_cast<ARAVirtualAudioSourceRegionSequence&>(this->sequence)));
dynamic_cast<ARAVirtualAudioSourceRegionSequence&>(this->sequence), this->modification));
}

const ARA::ARAPlaybackRegionProperties
ARAVirtualAudioPlaybackRegion::createProperties(ARAVirtualAudioSourceRegionSequence& sequence) {
ARAVirtualAudioPlaybackRegion::createProperties(
ARAVirtualAudioSourceRegionSequence& sequence,
ARAVirtualAudioModification& modification) {
auto properties = juce::ARAHostModel::PlaybackRegion::getEmptyProperties();

double totalTime = sequence.getModification().getSource().getLength();
double totalTime = modification.getSource().getLength();

properties.transformationFlags = ARA::kARAPlaybackTransformationNoChanges;
properties.startInModificationTime = 0.0;
Expand Down
12 changes: 6 additions & 6 deletions src/audioCore/misc/ARAObjects.h
Original file line number Diff line number Diff line change
Expand Up @@ -354,21 +354,17 @@ class ARAVirtualAudioSourceRegionSequence : public ARAVirtualRegionSequence {
ARAVirtualAudioSourceRegionSequence(
ARA::Host::DocumentController& dc,
SeqSourceProcessor* seq,
ARAVirtualAudioModification& modification,
ARAVirtualMusicalContext& emptyContext);

void update() override;

ARAVirtualAudioModification& getModification();
ARAVirtualMusicalContext& getEmptyContext();

private:
ARAVirtualAudioModification& modification;
ARAVirtualMusicalContext& emptyContext;

static const ARA::ARARegionSequenceProperties createProperties(
SeqSourceProcessor* seq, ARA::ARAColor* color,
ARAVirtualAudioModification& modification, ARAVirtualMusicalContext& emptyContext);
SeqSourceProcessor* seq, ARA::ARAColor* color, ARAVirtualMusicalContext& emptyContext);

JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(ARAVirtualAudioSourceRegionSequence)
};
Expand All @@ -383,6 +379,8 @@ class ARAVirtualPlaybackRegion {
const ARA::ARAPlaybackRegionProperties& properties);
virtual ~ARAVirtualPlaybackRegion() = default;

ARAVirtualAudioModification& getModification();

virtual void update() = 0;

juce::ARAHostModel::PlaybackRegion& getProperties();
Expand All @@ -391,6 +389,7 @@ class ARAVirtualPlaybackRegion {

protected:
ARAVirtualRegionSequence& sequence;
ARAVirtualAudioModification& modification;

juce::ARAHostModel::PlaybackRegion playbackRegion;

Expand All @@ -409,7 +408,8 @@ class ARAVirtualAudioPlaybackRegion : public ARAVirtualPlaybackRegion {

private:
static const ARA::ARAPlaybackRegionProperties createProperties(
ARAVirtualAudioSourceRegionSequence& sequence);
ARAVirtualAudioSourceRegionSequence& sequence,
ARAVirtualAudioModification& modification);

JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(ARAVirtualAudioPlaybackRegion)
};
Expand Down
40 changes: 36 additions & 4 deletions src/audioCore/misc/ARAVirtualDocument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

ARAVirtualDocument::ARAVirtualDocument(
SeqSourceProcessor* seq,
ARA::Host::DocumentController& controller)
: seq(seq), controller(controller) {}
ARA::Host::DocumentController& controller,
juce::ARAHostModel::EditorRendererInterface& araEditorRenderer,
juce::ARAHostModel::PlaybackRendererInterface& araPlaybackRenderer)
: seq(seq), controller(controller),
araEditorRenderer(araEditorRenderer), araPlaybackRenderer(araPlaybackRenderer) {}

ARAVirtualDocument::~ARAVirtualDocument() {
this->clear();
Expand All @@ -18,7 +21,7 @@ void ARAVirtualDocument::update() {

/** Audio Source */
this->audioSource = std::make_unique<ARAVirtualAudioSource>(
this->controller, this->seq);/**< TODO At Least 2 Samples In Audio Source */
this->controller, this->seq);

/** Audio Modification */
this->audioModification = std::make_unique<ARAVirtualAudioModification>(
Expand Down Expand Up @@ -58,7 +61,7 @@ void ARAVirtualDocument::update() {
for (auto i : this->musicalContexts) {
if (auto p = dynamic_cast<ARAVirtualEmptyContext*>(i)) {
this->regionSequences.add(std::make_unique<ARAVirtualAudioSourceRegionSequence>(
this->controller, this->seq, *(this->audioModification), *i));
this->controller, this->seq, *i));
}
else {
this->regionSequences.add(std::make_unique<ARAVirtualMusicalContextRegionSequence>(
Expand All @@ -77,6 +80,9 @@ void ARAVirtualDocument::update() {
this->controller, *i, *(this->audioModification)));
}
}

/** Add Regions To Renderer */
this->addRegions();
}

void ARAVirtualDocument::clear() {
Expand All @@ -85,9 +91,35 @@ void ARAVirtualDocument::clear() {
}

void ARAVirtualDocument::clearUnsafe() {
/** Remove Regions From Renderer */
this->removeRegions();

/** Clear Objects */
this->playbackRegions.clear();
this->regionSequences.clear();
this->musicalContexts.clear();
this->audioModification = nullptr;
this->audioSource = nullptr;
}

void ARAVirtualDocument::removeRegions() {
for (auto i : this->playbackRegions) {
if (this->araEditorRenderer.isValid()) {
this->araEditorRenderer.remove(i->getProperties());
}
if (this->araPlaybackRenderer.isValid()) {
this->araPlaybackRenderer.remove(i->getProperties());
}
}
}

void ARAVirtualDocument::addRegions() {
for (auto i : this->playbackRegions) {
if (this->araEditorRenderer.isValid()) {
this->araEditorRenderer.add(i->getProperties());
}
if (this->araPlaybackRenderer.isValid()) {
this->araPlaybackRenderer.add(i->getProperties());
}
}
}
8 changes: 7 additions & 1 deletion src/audioCore/misc/ARAVirtualDocument.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ class ARAVirtualDocument {
public:
ARAVirtualDocument() = delete;
ARAVirtualDocument(SeqSourceProcessor* seq,
ARA::Host::DocumentController& controller);
ARA::Host::DocumentController& controller,
juce::ARAHostModel::EditorRendererInterface& araEditorRenderer,
juce::ARAHostModel::PlaybackRendererInterface& araPlaybackRenderer);
~ARAVirtualDocument();

void update();
Expand All @@ -18,6 +20,8 @@ class ARAVirtualDocument {
private:
SeqSourceProcessor* const seq = nullptr;
ARA::Host::DocumentController& controller;
juce::ARAHostModel::EditorRendererInterface& araEditorRenderer;
juce::ARAHostModel::PlaybackRendererInterface& araPlaybackRenderer;

std::unique_ptr<ARAVirtualAudioSource> audioSource = nullptr;
std::unique_ptr<ARAVirtualAudioModification> audioModification = nullptr;
Expand All @@ -26,6 +30,8 @@ class ARAVirtualDocument {
juce::OwnedArray<ARAVirtualPlaybackRegion> playbackRegions;

void clearUnsafe();
void removeRegions();
void addRegions();

JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(ARAVirtualDocument)
};

0 comments on commit 66b49cf

Please sign in to comment.