Copy clips

Thank you! That works great.

I just made an educated guess at the lambda snap in your example.

auto notesAdded = midiNotes->pasteIntoClip (*midiClip, {}, transportControl.position, snap);

I did it like so,

auto notesAdded = midiNotes->pasteIntoClip(*midiClip, {}, transport.position, [](double a) {return a; });

It works. But what would the proper snap lambda look like?

And I should mention, I do not use snap-to-grid in my DAW.

That’s fine if you don’t want snap.
Ours looks like this:

            auto snap = [&, this] (double beats) -> double
            {
                if (! transportControl.snapToTimecode)
                    return beats;

                return beats >= 0 ?  snapMidiBeat (*midiClip,  beats, false)
                                  : -snapMidiBeat (*midiClip, -beats, false);
            };
1 Like

Thank you!..much appreciated.

I include the functional copy/paste for midi notes here for the benefit of others.
Copy:

te::Clipboard::getInstance()->clear();
for (auto midiNote : midiList.getNotes())
	midiContent->notes.emplace_back(midiNote->state.createCopy());
te::Clipboard::getInstance()->setContent(std::move(midiContent));

Paste:

if (auto midiNotes = te::Clipboard::getInstance()->getContentWithType<te::Clipboard::MIDINotes>())
	auto notesAdded = midiNotes->pasteIntoClip(*midiClip, {}, transport.position, [](double a) {return a; });

This works if you are not using snap-to-grid. The previous message shows the lambda to use for snap-to-grid to work.

3 Likes

With the most recent commit of tracktionEngine the copy paste code has changed slightly.
Copy:

midiContent = std::make_unique<te::Clipboard::MIDIEvents>();
te::Clipboard::getInstance()->clear();
for (auto midiNote : midiList.getNotes())
	midiContent->notes.emplace_back(midiNote->state.createCopy());
te::Clipboard::getInstance()->setContent(std::move(midiContent));

Paste:

if (auto midiEvents{ te::Clipboard::getInstance()->getContentWithType<te::Clipboard::MIDIEvents>() })
	auto notesAdded{ midiEvents->pasteIntoClip(*midiClip, {}, {}, (transport.position + (i * repeatDelta)), [](double a) {return a; }) };

This works if you are not using snap-to-grid in the lambda. See Dave’s comment above for an example with snap-to-grid.

The reason for the change is that you can now copy midi cc data to the clipboard. You can also select midi notes and midi cc data at the same time.

Awesome! Thank you!