lenmus / lomse

A C++ library for rendering, editing and playing back music scores.
MIT License
117 stars 28 forks source link

How to mute/exclude notes from playback? #360

Closed AndreasKoettl95 closed 2 years ago

AndreasKoettl95 commented 2 years ago

Hi, following issue:

I have implemented basic playback functionalities in my project, including visual tracking, midi output etc. and this works as expected.

I am also modifying the score by simply hiding/showing certain notes by using lomse::ImoNote::set_visible(). However, these hidden notes are still "played" by the midi-system.

Is there a way to mute these notes, or exclude them from being played at all? Note, that the visibility status changes dynamically, so as soon as the note is visible again, it should also be played again.

Or if there is no built in way, would it be sufficient to modify SoundEventsTable::add_noterest_events() in lomse_midi_table.cpp? I guess that's where the sound events are created, so adding the condition to only create these events, if the note is visible should do the trick right? Or maybe add a flag to the lomse::ImoNote class, something like exclude_from_playback, and check that before creating events?

cecilios commented 2 years ago

Thanks for raising this.

Visibility status only affects to display (GM). And as display and playback should be independently controllable I would not mute non-visible notes. Instead, as you suggest, I would add a flag to ImoNote class to mute the note, and would modify SoundEventsTable::add_noterest_events() to create the event only when the note is not muted.

This should be a simple change so please feel free to sent a PR.But if you don't feel confident I could try to do it this weekend. Just let me know.

AndreasKoettl95 commented 2 years ago

Well, I'm not very familiar with PR, and I would like to avoid digging into it right now, because I have a lot going. I will still change it myself in the code locally and rebuilt, because it's a university project and I have deadlines coming up.

cecilios commented 2 years ago

Ok, thank you. I will do it as soon as possible.

cecilios commented 2 years ago

PR#362 implements methods ImoNote::mute() and ImoNote::is_muted() to control notes playback. and takes that information into account to suppress MIDI events.