getSequenceLooped() vs getSequence() and selection

Hi !

How do one should approach the selection of notes through te::SelectedMidiEvents when using a looped sequence of notes ? I can loop clips in my app, and while using getSequenceLooped() works fine to draw repeated events, the drawing of selected notes is a bit more complex…

I use a juce::LassoComponent to find the notes. I can’t use the looped sequence of notes to search for matching notes, since, when added to the selection through te::SelectedMidiEvents::setSelected, the call to clipForEvent will assert since it iterates on the regular sequence and not the looped sequence :

//==============================================================================
MidiClip* SelectedMidiEvents::clipForEvent (MidiNote* note) const
{
    for (auto* c : clips)
        if (c->getSequence().getNotes().contains (note))
            return c;

    // SelectedMidiEvents must never have events without the parent clip
    jassertfalse;
    return {};
}

In my note drawing function, if I use the looped sequence, then the te::MidiNote’s won’t match as their state is different (as te::SelectedMidiEvents::isSelected() will never match since I added note from the non-looped sequence…).

Should I simply only rely on getSequence() to represent the selected notes ?

Or, is there another approach for this ?

Thanks in advance,

Best,

E.

I think in Waveform we just use the midi note/start/end beats to go between looped/unlooped notes. E.g.

bool isNoteSelected (const Array<MidiNote*>& selectedNotes, const MidiClip& c, const MidiNote& note)
{
    if (c.isLooping())
    {
        const auto loopStartBeats = c.getLoopStartBeats();

        for (auto n : selectedNotes)
        {
            const auto startBeat = note.getStartBeat() + toDuration (loopStartBeats);
            const auto endBeat = note.getEndBeat() + toDuration (loopStartBeats);

            if ((n->getStartBeat() == startBeat || n->getEndBeat() == endBeat) && n->getNoteNumber() == note.getNoteNumber())
            {
                auto& seq = c.getSequence();
                if (seq.getNotes().contains (n))
                    return true;
            }
        }

        return false;
    }
    //...
1 Like

Thanks !