Copy clips

Hi,

is there a convenient approach to copy clips? I have tried to use the seletionManager::copy and paste. But it doesn’t seem to work. It only throws the known: JUCE Assertion failure in tracktion_SelectionManager.cpp:255 but nothing happens.

The assertion is telling you that you haven’t registered a SelectableClass for the type of object you’re trying to select. The SelectableClass interface is a fairly high level class designed to perform operations on groups of objects and defines logic for selecting different types of object (for example, if you have a MIDI clip selected, and you add an audio clip to the selection, there might be a common set of properties you can expose but not all the properties of an audio and MIDI clip. Similarly, you probably won’t want to be able to select a Track and Clip at the same time).

So you can implement SelectableClasses for all your objects if you want to, but you might simply get away with using the Clipboard class itself. You can add content of various types and then paste it in to an Edit.

Does that help?

2 Likes

Hi, Dave. Thank you for your help. I don’t really get how to use the Clipboard Class. Do I have to derive from it?

No, it is a singleton so you can just call Clipboard::getInstance().

You then add content to the clipboard e.g.

auto clipContent = std::make_unique<Clipboard::Clips>();
clipContent->addClip (trackOffset, clip->getState());
Clipboard::getInstance()->setContent (std::move (clipContent));

Then elsewhere you can paste that in to an Edit:

Clipboard::getInstance()->pasteIntoEdit (Clipboard::ContentType::EditPastingOptions (edit, editInsertPoint));

Does that cover what you need?

1 Like

Thank you so much! I will give it a try.

It works! Thank you! :star_struck:

Will a similar technique to this work for copy/paste of midi notes?

What would that look like?

            auto content = std::make_unique<Clipboard::MIDINotes>();

            for (auto* mn : events->getSelectedNotes())
            {
                jassert (mn->state.isValid());
                content->notes.emplace_back (mn->state.createCopy());
            }

            params.clipboard.setContent (std::move (content));

Thank you! …very helpful.