2 Copyright (C) 2006-2015 Paul Davis
3 Author: David Robillard
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #ifndef __ardour_channel_filter_h__
21 #define __ardour_channel_filter_h__
27 #include "ardour/types.h"
28 #include "pbd/signals.h"
35 /** Filter/mapper for MIDI channels.
37 * Channel mapping is configured by setting a mode and "mask", where the
38 * meaning of the mask depends on the mode.
40 * If mode is FilterChannels, each mask bit represents a midi channel (bit 0 =
41 * channel 0, bit 1 = channel 1, ...). Only events whose channel corresponds
42 * to a 1 bit will be passed.
44 * If mode is ForceChannel, mask is simply a channel number which all events
47 class LIBARDOUR_API MidiChannelFilter
52 /** Filter `bufs` in-place. */
53 void filter(BufferSet& bufs);
55 /** Filter/map a MIDI message by channel.
57 * May modify the channel in `buf` if necessary.
59 * @return true if this event should be filtered out.
61 bool filter(uint8_t* buf, uint32_t len);
63 /** Atomically set the channel mode and corresponding mask.
64 * @return true iff configuration changed.
66 bool set_channel_mode(ChannelMode mode, uint16_t mask);
68 /** Atomically set the channel mask for the current mode.
69 * @return true iff configuration changed.
71 bool set_channel_mask(uint16_t mask);
73 /** Atomically get both the channel mode and mask. */
74 void get_mode_and_mask(ChannelMode* mode, uint16_t* mask) const {
75 const uint32_t mm = g_atomic_int_get(&_mode_mask);
76 *mode = static_cast<ChannelMode>((mm & 0xFFFF0000) >> 16);
77 *mask = (mm & 0x0000FFFF);
80 ChannelMode get_channel_mode() const {
81 return static_cast<ChannelMode>((g_atomic_int_get(&_mode_mask) & 0xFFFF0000) >> 16);
84 uint16_t get_channel_mask() const {
85 return g_atomic_int_get(&_mode_mask) & 0x0000FFFF;
88 PBD::Signal0<void> ChannelMaskChanged;
89 PBD::Signal0<void> ChannelModeChanged;
92 uint32_t _mode_mask; ///< 16 bits mode, 16 bits mask
95 } /* namespace ARDOUR */
97 #endif /* __ardour_channel_filter_h__ */