Skip to content
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

Mute Midi-Channels while playback is running #39

Closed
FischertBilligheim opened this issue Oct 3, 2019 · 17 comments
Closed

Mute Midi-Channels while playback is running #39

FischertBilligheim opened this issue Oct 3, 2019 · 17 comments
Labels
question Just question about the library
Projects

Comments

@FischertBilligheim
Copy link
Contributor

How can I mute/unmute midi-channels, while the Playback is running?

@melanchall
Copy link
Owner

melanchall commented Oct 3, 2019

If you use release version of the library, there is no way to do this. But you can take develop sources and then you can use EventCallback and NoteCallback properties of the Playback class to set callbacks to filter out those events and notes with muted channels.

playback.NoteCallback = (d, rt, rl, t) => mutedChannels.Contains(d.Channel) ? null : d;

playback.EventCallback = (e, rt, t) =>
{
    var channelEvent = e as ChannelEvent;
    if (channelEvent == null)
        return e;

    return mutedChannels.Contains(channelEvent.Channel) ? null : e;
};

You can set these callbacks before playback start and they will be automatically applied to all events and notes during playback.

@FischertBilligheim
Copy link
Contributor Author

Hello melanchall,

Thanks really a lot for your fast response to my 3 issues!!
And thanks really a lot for your great work and the possibility to use „DryWetMidi“!!

With best regards
Thomas

@melanchall
Copy link
Owner

melanchall commented Oct 3, 2019

Thomas,

You are welcome! :) Thanks for using the library. Please close issues if they are resolved.

Max

@FischertBilligheim
Copy link
Contributor Author

Thanks a lot, Max.

@FischertBilligheim
Copy link
Contributor Author

I have one additional comment or proposal:
I locally changed the source of "Playback.cs" and added a new property with an Array of bool - for every midi channel ("channelEnabled[16]") to mute or Play.

In "TryPlayNoteEvent " I changed a small part of Code:

        if (midiEvent != null)
        {
            // TF: Realize "Mute"
            if (midiEvent is NoteOnEvent)
            {
                int channel = ((NoteOnEvent)midiEvent).Channel;

                if (channelEnabled[channel])
                    SendEvent(midiEvent);
            }
            else
                SendEvent(midiEvent);

That's simpler and faster than using events.....

@FischertBilligheim
Copy link
Contributor Author

Mixer
This is the current status of the mixer with mute and solo-buttons...

@melanchall
Copy link
Owner

Hi Thomas,

Hmm, it seems reasonable to implement this feature. I'll do it :)

Your implementation slightly incomplete since there are other channel events except NoteOn. You should check if an event is an instance of ChannelEvent.

@FischertBilligheim
Copy link
Contributor Author

FischertBilligheim commented Oct 19, 2019

Hi Max,
Important is, that the mute/solo can be used while the midi-file is playing.
If you are now muting a channel - and the note-off will not be send anymore - you have not the expected behaviour... :-)
(Another situation: a program change event is not sent, and the channel is switched on again....)

Because of that I think Note_On seems to be ok for muting....

Regards
Thomas

@FischertBilligheim
Copy link
Contributor Author

Hi Max,
I never worked in a Github-Repository....
Would you generally accept proposals for changes from others than you?
I copied the Developer-Repository to my machine - and did locally changes.
How can you see my proposal - and accept or reject?

Greetings
Thomas

@melanchall
Copy link
Owner

Hi Thomas,

Recently I've merged PR from @zivillian (#36). So yes, I accept changes from users :)
To create PR you need to fork my repo, push your changes to your fork and create PR from your branch to the develop branch of my repo.

But array of bools is not good. Index should be of type FourBitNumber and the check for out of range should exist. I think it would be better to create methods like MuteChannel/UnmuteChannel/IsChannelMuted with all required checks and proper arguments types.

Please do PR and we'll discuss it :)

@FischertBilligheim
Copy link
Contributor Author

PR was created - issue can be closed… :-)

@melanchall
Copy link
Owner

I reopen the issue. Please clarify your requirement according to your last comment on #45.

Do you in fact mute channels on TrackChunk instead of Playback? What does it mean? There is no concept of muting on track chunk level since MIDI spec hasn't such thing.

@melanchall melanchall reopened this Oct 22, 2019
@FischertBilligheim
Copy link
Contributor Author

As I mentioned in the PR: It‘s fine and sufficient for me to have the mute functionality on the level of midi Channels.
What I‘m currently implementing is a midi- editor inclusive midi-Sequenzer functionality. The base of all sequencers is typically a track - you call it track-chunk. So if the sequencer plays all tracks - and these can be more than 16, even the Midi-Standard supports only 16 Channels(Devices) - it would be a good thing to be able to mute these tracks.... A typical example can be the drum-tracks, for which all drum parts can be splittet - the base-drum on a track, the HiHat on a separate track etc. Nevertheless all tracks are using midi-channel 10... It would be helpful to mute the base-drum, but to mute the drums on channel 10 is currently sufficient for me...

@melanchall
Copy link
Owner

OK, I've got it. Interesting case. I'll think how it can be implemented.

@melanchall
Copy link
Owner

Well, I've investigated efforts needed for this task and it seems new class Sequencer should be implemented. But I'm going to create such class in one of new versions of the library in the future. At now I recommend to use approach suggested in my first reply.

Thanks for using the library and for sharing your experience!

@FischertBilligheim
Copy link
Contributor Author

Ooh - that means my simple solution for the Midi-Channels will not be integrated and also not your method-call solution ?

@melanchall
Copy link
Owner

It's just unncecessary since there is a way to achieve what you want (and it's not so complex as you think). You just need to manage array of bools on your side. Also you can easily replace all array at once and callbacks will use new array automatically.

Also inside callback you can check what track note or event belongs to and mute/unmute it. So you can arrange your data into logical tracks, not by channels.

@melanchall melanchall added the question Just question about the library label Feb 2, 2020
@melanchall melanchall added this to Done in DryWetMIDI Mar 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Just question about the library
Projects
DryWetMIDI
  
Done
Development

No branches or pull requests

2 participants