Skip to content

Commit

Permalink
Tweaked RackType to make it inherit from EditItem and be consistent w…
Browse files Browse the repository at this point in the history
…ith other EditItem classes. Added a utility function `findEditItemForID()`
  • Loading branch information
julianstorer committed Jul 28, 2024
1 parent 1093c2e commit a2c7a3e
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace tracktion { inline namespace engine
{

AutomatableEditItem::AutomatableEditItem (Edit& ed, const juce::ValueTree& v)
: EditItem (EditItemID::readOrCreateNewID (ed, v), ed),
: EditItem (ed, v),
elementState (v)
{
remapOnTempoChange.referTo (elementState, IDs::remapOnTempoChange, &edit.getUndoManager(), false);
Expand Down
6 changes: 6 additions & 0 deletions modules/tracktion_engine/model/edit/tracktion_EditItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ EditItem::EditItem (EditItemID id, Edit& ed)
{
}

EditItem::EditItem (Edit& ed, const juce::ValueTree& v)
: edit (ed), itemID (EditItemID::readOrCreateNewID (ed, v))
{
}


//==============================================================================
EditItemID EditItemID::fromVar (const juce::var& v)
{
Expand Down
1 change: 1 addition & 0 deletions modules/tracktion_engine/model/edit/tracktion_EditItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ class EditItem
{
public:
EditItem (EditItemID, Edit&);
EditItem (Edit&, const juce::ValueTree&);
virtual ~EditItem() = default;

//==============================================================================
Expand Down
23 changes: 23 additions & 0 deletions modules/tracktion_engine/model/edit/tracktion_EditUtilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,29 @@ void insertSpaceIntoEditFromBeatRange (Edit& edit, BeatRange beatRange)
insertSpaceIntoEdit (edit, TimeRange (timeToInsertAt, lengthInTimeToInsert));
}

EditItem* findEditItemForID (Edit& edit, EditItemID itemID)
{
if (auto item = findTrackForID (edit, itemID))
return item;

if (auto item = findClipForID (edit, itemID))
return item;

if (auto item = findPluginForID (edit, itemID))
return item.get();

if (auto item = findModifierForID (edit, itemID))
return item.get();

if (auto item = findClipSlotForID (edit, itemID))
return item;

if (auto item = edit.getRackList().getRackTypeForID (itemID))
return item.get();

return {};
}

//==============================================================================
juce::Array<Track*> getAllTracks (const Edit& edit)
{
Expand Down
7 changes: 5 additions & 2 deletions modules/tracktion_engine/model/edit/tracktion_EditUtilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,15 @@ bool referencesProjectItem (Edit&, ProjectItemID);
// Edit
//==============================================================================

/** Inserts blank space in to an Edit, splitting clips if necessary. */
/// Inserts blank space in to an Edit, splitting clips if necessary.
void insertSpaceIntoEdit (Edit&, TimeRange timeRangeToInsert);

/** Inserts a number of blank beats in to the Edit. */
/// Inserts a number of blank beats in to the Edit.
void insertSpaceIntoEditFromBeatRange (Edit&, BeatRange);

/// Looks for an item in an edit with a given ID
EditItem* findEditItemForID (Edit&, EditItemID);

//==============================================================================
// Tracks
//==============================================================================
Expand Down
3 changes: 1 addition & 2 deletions modules/tracktion_engine/model/tracks/tracktion_ClipSlot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ namespace tracktion { inline namespace engine
{

ClipSlot::ClipSlot (const juce::ValueTree& v, Track& t)
: EditItem (EditItemID::fromID (v), t.edit),
state (v), track (t)
: EditItem (t.edit, v), state (v), track (t)
{
assert (state.hasType (IDs::CLIPSLOT));
assert (itemID.isValid());
Expand Down
4 changes: 1 addition & 3 deletions modules/tracktion_engine/model/tracks/tracktion_Track.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ namespace tracktion { inline namespace engine
{

Track::Track (Edit& ed, const juce::ValueTree& v, bool hasModifierList)
: EditItem (EditItemID::readOrCreateNewID (ed, v), ed),
state (v),
pluginList (ed)
: EditItem (ed, v), state (v), pluginList (ed)
{
edit.trackCache.addItem (*this);
auto um = &edit.getUndoManager();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1597,8 +1597,8 @@ std::unique_ptr<tracktion::graph::Node> createNodeForTrack (Track& track, const
//==============================================================================
std::unique_ptr<Node> createNodeForRackType (RackType& rackType, const CreateNodeParams& params)
{
const auto rackInputID = getRackInputBusID (rackType.rackID);
const auto rackOutputID = getRackOutputBusID (rackType.rackID);
const auto rackInputID = getRackInputBusID (rackType.itemID);
const auto rackOutputID = getRackOutputBusID (rackType.itemID);

auto rackInputNode = makeNode<ReturnNode> (rackInputID);
auto rackNode = RackNodeBuilder::createRackNode (rackType, params.sampleRate, params.blockSize, std::move (rackInputNode),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ juce::ValueTree RackInstance::create (RackType& type)
{
return createValueTree (IDs::PLUGIN,
IDs::type, RackInstance::xmlTypeName,
IDs::rackType, type.rackID);
IDs::rackType, type.itemID);
}

juce::String RackInstance::getTooltip()
Expand Down
14 changes: 7 additions & 7 deletions modules/tracktion_engine/plugins/internal/tracktion_RackType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,10 @@ struct RackType::WindowStateList : public ValueTreeObjectList<WindowState>
};

//==============================================================================
RackType::RackType (const juce::ValueTree& v, Edit& owner)
: MacroParameterElement (owner, v),
edit (owner), state (v),
rackID (EditItemID::readOrCreateNewID (edit, state))
RackType::RackType (Edit& ed, const juce::ValueTree& v)
: EditItem (ed, v),
MacroParameterElement (ed, v),
state (v)
{
CRASH_TRACER

Expand Down Expand Up @@ -300,7 +300,7 @@ juce::Result RackType::restoreStateFromValueTree (const juce::ValueTree& vt)
if (! v.hasType (IDs::RACK))
return juce::Result::fail (TRANS("Invalid or corrupted preset"));

rackID.writeID (v, nullptr);
itemID.writeID (v, nullptr);

{
auto um = getUndoManager();
Expand Down Expand Up @@ -1213,7 +1213,7 @@ struct RackTypeList::ValueTreeList : public ValueTreeObjectList<RackType>

RackType* createNewObject (const juce::ValueTree& v) override
{
auto t = new RackType (v, list.edit);
auto t = new RackType (list.edit, v);
t->incReferenceCount();
return t;
}
Expand Down Expand Up @@ -1281,7 +1281,7 @@ RackType::Ptr RackTypeList::getRackType (int index) const
RackType::Ptr RackTypeList::getRackTypeForID (EditItemID rackID) const
{
for (auto r : list->objects)
if (r->rackID == rackID)
if (r->itemID == rackID)
return *r;

return {};
Expand Down
13 changes: 6 additions & 7 deletions modules/tracktion_engine/plugins/internal/tracktion_RackType.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,14 @@ struct RackConnection


//==============================================================================
class RackType : public Selectable,
class RackType : public EditItem,
public Selectable,
public juce::ReferenceCountedObject,
public MacroParameterElement,
private juce::ValueTree::Listener
{
public:
RackType (const juce::ValueTree&, Edit&);
RackType (Edit&, const juce::ValueTree&);
~RackType() override;

using Ptr = juce::ReferenceCountedObjectPtr<RackType>;
Expand Down Expand Up @@ -91,6 +92,8 @@ class RackType : public Selectable,
EditItemID pluginID, int pinIndex);

//==============================================================================
juce::String getName() const override { return rackName; }

juce::StringArray getInputNames() const;
juce::StringArray getOutputNames() const;

Expand Down Expand Up @@ -137,11 +140,7 @@ class RackType : public Selectable,
void saveWindowPosition();
void hideWindowForShutdown();

Edit& edit;

juce::ValueTree state; // do not change the order of
EditItemID rackID; // these two members!

juce::ValueTree state;
juce::CachedValue<juce::String> rackName;

private:
Expand Down

0 comments on commit a2c7a3e

Please sign in to comment.