# Questions about the new clip launcher

**URL:** <https://forum.juce.com/t/questions-about-the-new-clip-launcher/60324>\
**Category:** Tracktion Engine\
**Created:** [March 6, 2024, 11:10am UTC](https://forum.juce.com/t/questions-about-the-new-clip-launcher/60324 "2024-03-06T11:10:00Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![ToxVox](https://avatars.discourse-cdn.com/v4/letter/t/76d3ee/32.png) [@ToxVox](https://forum.juce.com/u/ToxVox)\
**Post date:** [March 6, 2024, 11:10am UTC](https://forum.juce.com/t/questions-about-the-new-clip-launcher/60324/1 "2024-03-06T11:10:00Z")

</div>

I’m trying to figure out the new feature clip launcher feature at the develop-branch. Maybe I’m too early with my questions…

I checked classes like `ClipSlotList`, `ClipSlot`, `SceneList`, `Scene`, `LaunchHandle`  
and came up with this structure:

 ![ClipLauncher](https://us1.discourse-cdn.com/flex026/uploads/juce/original/3X/0/8/086ed4b880de96dfb9dff8863bb03c58b31dcba5.png)

Here is my interpretation of it:  
Scene is managed by SceneList. Scene creates ClipSlots to all available AudioTracks. A Clip lives in a ClipSlot and is managed by the ClipSlotList. An AudioTrack owns the ClipSlotList. If I want to launch a clip, I should use the LaunchHandle thats belongs to the Clip.

For a simple test I wrote this code:

```auto
edit->getSceneList().insertScene(0);
audioTrack1->getClipSlotList().getClipSlots()[0]->setClip(audioClip1);
audioTrack1->getClipSlotList().getClipSlots()[0]->getClip()->getLaunchHandle()->play( tracktion::MonotonicBeat( { 0_bp } ) );

```

Is this the right direction? Did I miss something?

---

<div class="post-metadata">

**Author:** ![dave96](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/dave96/32/8487_2.png) [@dave96](https://forum.juce.com/u/dave96)\
**Post date:** [March 6, 2024, 11:45am UTC](https://forum.juce.com/t/questions-about-the-new-clip-launcher/60324/2 "2024-03-06T11:45:30Z")

</div>

No, that’s correct.  
The `MonotonicBeat` is the point in the future that you want to launch it though. If you want to launch it immediately, just pass an empty optional i.e. `play ({})`.  
Although a `MonotonicBeat (0_bp)` will probably do the same thing as 0\_bp is likely to be in the past and hence launched immediately.

It is a bit early to rely on the exact APIs and behaviour though. It won’t be fixed until we release v3.0 of the Engine.

Also note that the `feature/launcher` branch is a technical preview so can’t be commercially licensed yet.

---

<div class="post-metadata">

**Author:** ![ToxVox](https://avatars.discourse-cdn.com/v4/letter/t/76d3ee/32.png) [@ToxVox](https://forum.juce.com/u/ToxVox)\
**Post date:** [March 7, 2024, 7:35pm UTC](https://forum.juce.com/t/questions-about-the-new-clip-launcher/60324/3 "2024-03-07T19:35:47Z")

</div>

> [@dave96](#):
>
> No, that’s correct.  
> The `MonotonicBeat` is the point in the future that you want to launch it though. If you want to launch it immediately, just pass an empty optional i.e. `play ({})`.  
> Although a `MonotonicBeat (0_bp)` will probably do the same thing as 0\_bp is likely to be in the past and hence launched immediately.

Thanks for the hint @dave96!  
In my code example the `->getClip()` doesn’t work correct. I’m getting an error  
`JUCE Message Thread (1): EXC_BAD_ACCESS (code=1, address=0x0)`  
Should I call something between `->setClip()` and `->getClip` ?

> [@dave96](#):
>
> It is a bit early to rely on the exact APIs and behaviour though. It won’t be fixed until we release v3.0 of the Engine.

Do you have a rough roadmap or schedule for v3.0?

> [@dave96](#):
>
> Also note that the `feature/launcher` branch is a technical preview so can’t be commercially licensed yet.

For my project, I will publish it open source.

---

<div class="post-metadata">

**Author:** ![dave96](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/dave96/32/8487_2.png) [@dave96](https://forum.juce.com/u/dave96)\
**Post date:** [March 8, 2024, 1:26pm UTC](https://forum.juce.com/t/questions-about-the-new-clip-launcher/60324/4 "2024-03-08T13:26:09Z")

</div>

Can you step through the `SceneList::insertScene` and see if it’s actually adding the slots to the `ClipSlotList`s?

Can you call `auto clipSlots = audioTrack1->getClipSlotList().getClipSlots()` and see what it’s contents is?

---

<div class="post-metadata">

**Author:** ![ToxVox](https://avatars.discourse-cdn.com/v4/letter/t/76d3ee/32.png) [@ToxVox](https://forum.juce.com/u/ToxVox)\
**Post date:** [March 13, 2024, 1:36pm UTC](https://forum.juce.com/t/questions-about-the-new-clip-launcher/60324/5 "2024-03-13T13:36:21Z")

</div>

> [@dave96](#):
>
> Can you step through the `SceneList::insertScene` and see if it’s actually adding the slots to the `ClipSlotList`s?

@dave96 Yes, I think this part is ok…

> [@dave96](#):
>
> Can you call `auto clipSlots = audioTrack1->getClipSlotList().getClipSlots()` and see what it’s contents is?

Here is the result:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/juce/original/3X/6/8/688b82415c8f3ea725fb617bbbef9432f1b75b79.png)

Below is the complete code:

> <https://github.com/toxvox/BentoClipLauncher/blob/master/BentoClipLauncher/Source/BentoClipLauncher.h>

---

<div class="post-metadata">

**Author:** ![dave96](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/dave96/32/8487_2.png) [@dave96](https://forum.juce.com/u/dave96)\
**Post date:** [March 14, 2024, 10:17am UTC](https://forum.juce.com/t/questions-about-the-new-clip-launcher/60324/6 "2024-03-14T10:17:43Z")

</div>

Can you step in to the `setClip` call and see if it’s adding the clip state?

---

<div class="post-metadata">

**Author:** ![ToxVox](https://avatars.discourse-cdn.com/v4/letter/t/76d3ee/32.png) [@ToxVox](https://forum.juce.com/u/ToxVox)\
**Post date:** [March 14, 2024, 10:50am UTC](https://forum.juce.com/t/questions-about-the-new-clip-launcher/60324/7 "2024-03-14T10:50:51Z")

</div>

Do you mean this spot here?

 ![image](https://us1.discourse-cdn.com/flex026/uploads/juce/original/3X/4/d/4da1902724f2427f6a50298291571a1eb743cc1a.jpeg)

---

<div class="post-metadata">

**Author:** ![ToxVox](https://avatars.discourse-cdn.com/v4/letter/t/76d3ee/32.png) [@ToxVox](https://forum.juce.com/u/ToxVox)\
**Post date:** [March 18, 2024, 10:16am UTC](https://forum.juce.com/t/questions-about-the-new-clip-launcher/60324/8 "2024-03-18T10:16:17Z")

</div>

@dave96 I checked the `setClip`-section again. Seems like `dynamic_cast<ClipTrack*> (&newParent)` fails in my case…

```cpp
bool Clip::moveTo (ClipOwner& newParent)
{
    if (auto to = dynamic_cast<ClipTrack*> (&newParent))
    {
        if (canBeAddedTo (*to))
        {
            if (parent != to)
            {
                if (! to->isFrozen (Track::anyFreeze))
                {
                    Clip::Ptr refHolder (this);
                    to->addClip (this);
                }
            }
            return true;
        }
    }
    return false;
}

```

I’m getting `true` if I check it with `tracktion::Clip::isClipState(stepClip1->state)`;

---

<div class="post-metadata">

**Author:** ![dave96](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/dave96/32/8487_2.png) [@dave96](https://forum.juce.com/u/dave96)\
**Post date:** [March 20, 2024, 3:59pm UTC](https://forum.juce.com/t/questions-about-the-new-clip-launcher/60324/9 "2024-03-20T15:59:39Z")

</div>

Does this work for you:

> <https://github.com/Tracktion/tracktion_engine/commit/7a9a5ac72fe8ef1b2bf7cc6c7a0c32467b482d45>

---

<div class="post-metadata">

**Author:** ![ToxVox](https://avatars.discourse-cdn.com/v4/letter/t/76d3ee/32.png) [@ToxVox](https://forum.juce.com/u/ToxVox)\
**Post date:** [March 20, 2024, 10:41pm UTC](https://forum.juce.com/t/questions-about-the-new-clip-launcher/60324/10 "2024-03-20T22:41:24Z")

</div>

Yes, it works better. But I have another issue here:

```cpp
void ClipSlot::setClip (Clip* c)
{
    if (c == nullptr)
        return;

    if (auto existingClip = getClip())
        existingClip->removeFromParent();

    jassert (findClipForID (c->itemID) == nullptr); <== No matching function for call to 'findClipForID'

    auto um = c->getUndoManager();
    c->state.getParent().removeChild (c->state, um);
    state.addChild (c->state, -1, um);
}

```

It works when I comment this out: `jassert (findClipForID (c->itemID) == nullptr); `

Now I’m playing around with the `LaunchHandle`. If I start a clip (while the transport is playing) I hear a very short part (like a short click sound) of it. My approach is to launch and stop a clip with a quantisation of 1 bar. The clip should loop until I stop it. This is my code:

```auto
switch(launchHandle->getPlayingStatus())
{
    case tracktion::LaunchHandle::PlayState::playing:
    {
        launchHandle->stop( tracktion::MonotonicBeat( {} ) );
        break;
    }
    case tracktion::LaunchHandle::PlayState::stopped:
    {
        launchHandle->play( tracktion::MonotonicBeat( {} ) );
        break;
    }
}

```

Should I use other function like the `FollowActions`?

---

<div class="post-metadata">

**Author:** ![dave96](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/dave96/32/8487_2.png) [@dave96](https://forum.juce.com/u/dave96)\
**Post date:** [March 25, 2024, 1:56pm UTC](https://forum.juce.com/t/questions-about-the-new-clip-launcher/60324/11 "2024-03-25T13:56:26Z")

</div>

`jassert (findClipForID (c->itemID) == nullptr); <== No matching function for call to 'findClipForID`  
I thought this was fixed? Can you grab the latest and try again please?

* * *

`tracktion::MonotonicBeat( {} ) ` means, “as soon as possible”, i.e. not in the future so it sounds like you’re starting and stopping it straight away.

You probably want to look at `Edit::getLaunchQuantisation()`

---

<div class="post-metadata">

**Author:** ![ToxVox](https://avatars.discourse-cdn.com/v4/letter/t/76d3ee/32.png) [@ToxVox](https://forum.juce.com/u/ToxVox)\
**Post date:** [April 2, 2024, 10:02pm UTC](https://forum.juce.com/t/questions-about-the-new-clip-launcher/60324/12 "2024-04-02T22:02:18Z")

</div>

@dave96 Congratulation to the Tracktion 13 launch! The new clip launcher works well!

* * *

> [@dave96](#):
>
> `jassert (findClipForID (c->itemID) == nullptr); <== No matching function for call to 'findClipForID`  
> I thought this was fixed? Can you grab the latest and try again please?

I got the latest version but didn’t help:

> <https://github.com/Tracktion/tracktion_engine/commit/f760909ef82053a35189070591c01b95908eea19>

As I mentioned, it works for me if I comment the line out.

* * *

> [@dave96](#):
>
> `tracktion::MonotonicBeat( {} ) ` means, “as soon as possible”, i.e. not in the future so it sounds like you’re starting and stopping it straight away.
> 
> You probably want to look at `Edit::getLaunchQuantisation()`

I think I figure it out how the new `tracktion::MonotonicBeat` works. It’s like a parallel beat based timeline - right? And the clip launcher syncs the clip start and stop to it.

With this code I can synced launch / stop the clip with 1 bar quantisation (4\_bd) :

```auto
auto& ts = edit->tempoSequence;
auto& tc = edit->getTransport();            
tracktion::MonotonicBeat startSyncBeat;
tracktion::MonotonicBeat endSyncBeat;

const auto currentBarsBeats = ts.toBarsAndBeats (tc.getPosition());
const auto barStartBeat = ts.toBeats (tracktion::tempo::BarsAndBeats { .bars = currentBarsBeats.bars });
startSyncBeat = tracktion::MonotonicBeat { barStartBeat + 4_bd };
endSyncBeat = tracktion::MonotonicBeat { barStartBeat + 4_bd }; 
.
.
.
switch(launchHandle->getPlayingStatus())
{
    case tracktion::LaunchHandle::PlayState::playing:
    {
        DBG("barStartBeat - Stop:" + juce::String( endSyncBeat.v.inBeats() ) );
        launchHandle->stop( endSyncBeat );
        break;
    }
    case tracktion::LaunchHandle::PlayState::stopped:
    {
        DBG("barStartBeat - Start:" + juce::String( startSyncBeat.v.inBeats() ) );
        launchHandle->play( startSyncBeat );
        break;
    }
}
                        

```

* * *

Currently the clips are played as one shots. How can I loop it? This function didn’t help:  
`stepClip->setLoopRangeBeats( {0_bp, 4_bp} );`

---

<div class="post-metadata">

**Author:** ![ToxVox](https://avatars.discourse-cdn.com/v4/letter/t/76d3ee/32.png) [@ToxVox](https://forum.juce.com/u/ToxVox)\
**Post date:** [April 9, 2024, 11:41am UTC](https://forum.juce.com/t/questions-about-the-new-clip-launcher/60324/13 "2024-04-09T11:41:31Z")

</div>

I’m exploring the Waveform 13. I can’t find the right place to set clips in a loop mode.

@dave96 Can you give me a hint where the “Loop” checkbox activate the loop, please?

![image](https://us1.discourse-cdn.com/flex026/uploads/juce/original/3X/2/4/248f6f8dc81b1206e15af3224a12ac70e9f1ec71.png)

Thanks!

---

<div class="post-metadata">

**Author:** ![dave96](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/dave96/32/8487_2.png) [@dave96](https://forum.juce.com/u/dave96)\
**Post date:** [April 9, 2024, 3:52pm UTC](https://forum.juce.com/t/questions-about-the-new-clip-launcher/60324/14 "2024-04-09T15:52:15Z")

</div>

“Loop” is just if the loop length is non-zero.  
If you set the loop length in beats, you also need to enable “auto-tempo”.

Sorry I’m being slow to respond but the clip launcher branch isn’t really ready for public consumption yet so I can’t really prioritise it this soon after a major app launch I’m afraid.

---

<div class="post-metadata">

**Author:** ![ToxVox](https://avatars.discourse-cdn.com/v4/letter/t/76d3ee/32.png) [@ToxVox](https://forum.juce.com/u/ToxVox)\
**Post date:** [April 9, 2024, 9:09pm UTC](https://forum.juce.com/t/questions-about-the-new-clip-launcher/60324/15 "2024-04-09T21:09:13Z")

</div>

> [@dave96](#):
>
> “Loop” is just if the loop length is non-zero.  
> If you set the loop length in beats, you also need to enable “auto-tempo”.

If I understand you correctly, does ‘non-zero’ mean a value greater than zero?.  
My code ( `stepClip->setLoopRangeBeats( {0_bp, 4_bp} );` ) should work - right?  
I can’t set up “auto-tempo” for `StepClip`. I only found it for `AudioClipBase`.

No worries about the delayed response, I’m grateful for your insight and guidance. 🙂

---

<div class="post-metadata">

**Author:** ![dave96](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/dave96/32/8487_2.png) [@dave96](https://forum.juce.com/u/dave96)\
**Post date:** [April 11, 2024, 3:41pm UTC](https://forum.juce.com/t/questions-about-the-new-clip-launcher/60324/16 "2024-04-11T15:41:52Z")

</div>

I think that should work… Maybe debug in LoopingMidiNode to see if it’s not getting the correct loop region?

---

<div class="post-metadata">

**Author:** ![ToxVox](https://avatars.discourse-cdn.com/v4/letter/t/76d3ee/32.png) [@ToxVox](https://forum.juce.com/u/ToxVox)\
**Post date:** [April 11, 2024, 10:22pm UTC](https://forum.juce.com/t/questions-about-the-new-clip-launcher/60324/17 "2024-04-11T22:22:24Z")

</div>

Finally it works! 😀

This is my quick’n’dirty solution for a clip launch button:

```auto
clipLaunchButton2.onClick = [this]
{
    auto& ts = edit->tempoSequence;
    auto& tc = edit->getTransport();
    
    tracktion::MonotonicBeat startSyncBeat;
    tracktion::MonotonicBeat endSyncBeat;
    const auto currentBarsBeats = ts.toBarsAndBeats (tc.getPosition());
    const auto barStartBeat = ts.toBeats (tracktion::tempo::BarsAndBeats { .bars = currentBarsBeats.bars });
    startSyncBeat = tracktion::MonotonicBeat { barStartBeat + 4_bd };
    endSyncBeat = tracktion::MonotonicBeat { barStartBeat + 4_bd };

    stopAllClips(endSyncBeat);
    audioTrack1->getClipSlotList().getClipSlots()[1]->getClip()->setLoopRangeBeats( { 0_bp, 4_bp } );
    audioTrack1->getClipSlotList().getClipSlots()[1]->getClip()->getLaunchHandle()->play( startSyncBeat );
};

```

I schedule a stop clip for every clip in the ClipSlotList before launching another clip in the slot list. Or is there a build in function for this clip launch behaviour?

```auto
void stopAllClips(std::optional<tracktion::MonotonicBeat> endSyncBeat)
{
    for( auto clipSlot : audioTrack1->getClipSlotList().getClipSlots() )
    {
        if(clipSlot)
        {
            if(auto clip = clipSlot->getClip())
            {
                if(auto launchHandle = clip->getLaunchHandle())
                {
                    launchHandle->stop( endSyncBeat) ;
                }
            }
        }
    }
}

```

---

<div class="post-metadata">

**Author:** ![dave96](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/dave96/32/8487_2.png) [@dave96](https://forum.juce.com/u/dave96)\
**Post date:** [April 15, 2024, 10:41am UTC](https://forum.juce.com/t/questions-about-the-new-clip-launcher/60324/18 "2024-04-15T10:41:45Z")

</div>

That’s pretty good, just a few quick comments.

1. Rather than doing your manual `toBarsAndBeats ` calculation, you can use the `LaunchQuantisation` class which effectively does this for you.

2. This is just the same calculation so no point in doing it twice.

```auto
    startSyncBeat = tracktion::MonotonicBeat { barStartBeat + 4_bd };
    endSyncBeat = tracktion::MonotonicBeat { barStartBeat + 4_bd };

```

1. No that’s what we do currently. You could optimise by keeping track of all the playing or queued clips but it wouldn’t be much more efficient.

> Or is there a build in function for this clip launch behaviour?

1. What you’ve got will probably only work once when play starts from the beginning. The `MonotonicBeat` continues during playback so you need to find the “current” MonotonicBeat and use that as a reference. In Waveform what we do is get the current sync point from the current sync point from the `EditPlaybackContext::getSyncPoint()`, find the next `BeatPosition` to launch at using `LaunchQuantisation` and `SyncPoint::beat`. Find the duration number of beats between the current beat position and the launch position, then add that on to the `SyncPoint::MonotonicBeat` to find out where to launch/stop the clips.

---

<div class="post-metadata">

**Author:** ![ToxVox](https://avatars.discourse-cdn.com/v4/letter/t/76d3ee/32.png) [@ToxVox](https://forum.juce.com/u/ToxVox)\
**Post date:** [April 23, 2024, 10:40am UTC](https://forum.juce.com/t/questions-about-the-new-clip-launcher/60324/19 "2024-04-23T10:40:05Z")

</div>

It seams there was little bit refactoring in case of targeting a track to send midi data.

In my scenario we have two audio tracks and I want to switch between this tracks and send send midi notes via GUI to the selected one. But I can reach audioTrackB with midi data only. Did I miss something @dave96 ?

This are my steps:

- **Create a virtual midi device**

- **Prepare a button to send midi notes**

```auto
sendMidiNoteButton.onClick = [this]
{
        auto midiNote = juce::MidiMessage::noteOff(1, 36, 100);
        virtualMidiInputDevice->handleIncomingMidiMessage(nullptr, midiNote);  
};
  
sendMidiNoteButton.onStateChange = [this]
{
    if(sendMidiNoteButton.isDown())
    {
        auto midiNote = juce::MidiMessage::noteOn(1, 36, 100);
        virtualMidiInputDevice->handleIncomingMidiMessage(nullptr, midiNote); 
    }
};

```

- **Switch between audioTrackA and audioTrackB**

```auto
selectButtonTrackA.onClick = [this]
{
    for (auto instance : edit->getAllInputDevices())
    {
        if("myVirtualMidiDevice" == instance->getInputDevice().getName())
        {
            auto result = instance->setTarget(audioTrackA->itemID, true, nullptr, 0);
            auto removeTargetResult = instance->removeTarget(audioTrackB->itemID, nullptr);          
        }
    }
};

```

```auto
selectButtonTrackB.onClick = [this]
{
    for (auto instance : edit->getAllInputDevices())
    {
        if("myVirtualMidiDevice" == instance->getInputDevice().getName())
        {
            auto result = instance->setTarget(audioTrackB->itemID, true, nullptr, 0);
            auto removeTargetResult = instance->removeTarget(audioTrackA->itemID, nullptr);          
        }
    }
};

```

---

<div class="post-metadata">

**Author:** ![RolandMR](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/rolandmr/32/641_2.png) [@RolandMR](https://forum.juce.com/u/RolandMR)\
**Post date:** [April 23, 2024, 12:17pm UTC](https://forum.juce.com/t/questions-about-the-new-clip-launcher/60324/20 "2024-04-23T12:17:23Z")

</div>

Is your input armed? We added a new input monitoring mode “auto”, where midi only processed when input armed. Either arm your input or set monitor mode to “on”.

[Next page](https://forum.juce.com/t/questions-about-the-new-clip-launcher/60324.md?page=2)
