Skip to content

Fix empty MIDI clips not displaying name #7836

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

TimovVeen
Copy link

Beat clips don't render titles. checkType() always sets type to beat when there are no notes, so titles don't render on empty MIDI clips either.
I changed the default type of MidiClips on construction to MelodyClip, otherwise the name would still not show until you start adding notes. I tested to make sure this doesn't cause the opposite issue for beat clips. If you name a new beat clip before adding any notes, it will still correctly not show the name title.

Fixes #7808

@sakertooth
Copy link
Contributor

Why exactly do beat clips not render titles?

@TimovVeen
Copy link
Author

My guess is because it would obscure the clip, which is not a problem for melody clips since you edit them by opening the piano roll.

@TimovVeen
Copy link
Author

I should add that beat clips not rendering titles is explicitly defined in MidiClipView. So at least it's not a bug, though afaik it's not documented what the reasoning is.

@sakertooth
Copy link
Contributor

I find it a bit strange. Why can't a beat clip (a MIDI clip) show titles? All clips are meant to have titles, hence their name parameter. Many of the clips also have functions to change the title, like MidiClipView::changeName, which I would expect would change the title of the MIDI clip, whether its a beat clip or not.

Maybe it might be worth investigating this sometime later, but I suppose it is fine for now if for some reason this was the intention. @bratpeki can you test this PR to see if it fixes the issue you reported?

@bratpeki
Copy link
Member

Hi, sorry, been busy! I can checks, yes.

@bratpeki
Copy link
Member

Code-wise question, what the **** is a MelodyClip? 🤣

@bratpeki bratpeki self-assigned this Apr 21, 2025
@bratpeki bratpeki self-requested a review April 21, 2025 16:19
@bratpeki
Copy link
Member

This seems to have broken BB clips:
image


Furthermore, empty MIDI clips are no longer grey:
image

@TimovVeen
Copy link
Author

I reverted the change that causes this, thank you for testing. I missed it because it doesn't happen to the kicker plugin for some reason. The thing is, I made the change because empty midi clips being grey is also a bug. It happens because new clips are beat clips by default, until a note gets added and the type is checked. This can be checked by trying to name a newly created clip, the name will not render. This doesn't happen with other clips.

@bratpeki
Copy link
Member

I'd argue the gray clips are a nifty functionality, helping us differentiate between empty clips and clips with content.


...thank you for testing.

My pleasure! Thank you for writing the PR. We'll get to the bottom of this, for sure.

The thing is, I made the change because empty midi clips being grey is also a bug. It happens because new clips are beat clips by default, until a note gets added and the type is checked.

Very odd. Why do they turn gray after deleting all notes then? Do they turn back into BeatClips?

Code-wise question, what the **** is a MelodyClip? 🤣

Still curious about this! 🤔

@bratpeki
Copy link
Member

@sakertooth:

Why exactly do beat clips not render titles?

My question as well. Does this mean the fix is actually moving that logic into the parent Clip class, or something like that?

@TimovVeen
Copy link
Author

Code-wise question, what the **** is a MelodyClip? 🤣

The clips in the song editor are "melody" clips, the ones you edit with the piano roll.
The clips in the pattern editor are "beat" clips (see image).
image
In the code both types use MidiClip classes for rendering and logic, so to differentiate between them, there is an enum type that is either BeatClip or MelodyClip. MidiClips have default type BeatClip on construction, and the type is checked and updated with the following method

void MidiClip::checkType()
{
	// If all notes are StepNotes, we have a BeatClip
	const auto beatClip = std::all_of(m_notes.begin(), m_notes.end(), [](auto note) { return note->type() == Note::Type::Step; });

	setType(beatClip ? Type::BeatClip : Type::MelodyClip);
}

The issue with this method is that if there are no notes to differentiate the type, it is still assumed to be a BeatClip.

At some point someone decided that beat clips should not show their name. (See image for how it would look)
image

However, since checkType() sets melody clips to type BeatClip when there are no notes, it also doesn't show the name and is colored gray, causing your issue. The change I made to checkType() fixes this, but since newly created melody clips have type BeatClip on construction, they show up gray with no name rendered, until the first note is added and the type is updated.

I'd argue the gray clips are a nifty functionality, helping us differentiate between empty clips and clips with content.

Yes I agree it should stay as a feature, but right now it's unintended behavior caused by the tight code coupling of melody and beat clips. As you mentioned, it happens because they turn into beat clips.
A better solution would be to set the correct clip type on creation, so you don't have to rely on continuously checking the type of the notes. But that's probably out of scope for this PR.

I hope this explains it a bit better, let me know if anything is unclear

Beat clips don't render titles. checkType() always
sets type to beat when there are no notes, so titles
don't render on empty MIDI clips either.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Empty MIDI clips don't display the clip name
3 participants