summaryrefslogtreecommitdiff
path: root/libs/ardour/ardour
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2015-03-28 23:24:41 -0400
committerDavid Robillard <d@drobilla.net>2015-03-29 00:51:56 -0400
commitc9023ae73d6d70fead3e827811b384e2b171e4d6 (patch)
tree3a6cb5a0a7d436bed457f961afb272b82f1626be /libs/ardour/ardour
parent050c9c3f7d695ea8736d050f3eac5c4f0a3158ca (diff)
Fix mute of MIDI tracks with channel forcing.
This moves MIDI channel filtering into a reusable class and moves filtering to the source, rather than modifying the buffer afterwards. This is necessary so that the playlist trackers reflect the emitted notes (and thus are able to stop them in situations like mute). As a perk, this is also faster because events are just dropped on read, rather than pushed into a buffer then later removed (which is very slow). Really hammering on mute or solo still seems to produce stuck notes occasionally (perhaps related to multiple-on warnings). I am not yet sure why, but occasional beats always.
Diffstat (limited to 'libs/ardour/ardour')
-rw-r--r--libs/ardour/ardour/midi_channel_filter.h97
-rw-r--r--libs/ardour/ardour/midi_playlist.h4
-rw-r--r--libs/ardour/ardour/midi_playlist_source.h3
-rw-r--r--libs/ardour/ardour/midi_region.h13
-rw-r--r--libs/ardour/ardour/midi_source.h5
-rw-r--r--libs/ardour/ardour/midi_track.h67
-rw-r--r--libs/ardour/ardour/smf_source.h3
7 files changed, 128 insertions, 64 deletions
diff --git a/libs/ardour/ardour/midi_channel_filter.h b/libs/ardour/ardour/midi_channel_filter.h
new file mode 100644
index 0000000000..934b369b8c
--- /dev/null
+++ b/libs/ardour/ardour/midi_channel_filter.h
@@ -0,0 +1,97 @@
+/*
+ Copyright (C) 2006-2015 Paul Davis
+ Author: David Robillard
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+#ifndef __ardour_channel_filter_h__
+#define __ardour_channel_filter_h__
+
+#include <stdint.h>
+
+#include <glib.h>
+
+#include "ardour/types.h"
+#include "pbd/signals.h"
+
+namespace ARDOUR
+{
+
+class BufferSet;
+
+/** Filter/mapper for MIDI channels.
+ *
+ * Channel mapping is configured by setting a mode and "mask", where the
+ * meaning of the mask depends on the mode.
+ *
+ * If mode is FilterChannels, each mask bit represents a midi channel (bit 0 =
+ * channel 0, bit 1 = channel 1, ...). Only events whose channel corresponds
+ * to a 1 bit will be passed.
+ *
+ * If mode is ForceChannel, mask is simply a channel number which all events
+ * will be forced to.
+ */
+class LIBARDOUR_API MidiChannelFilter
+{
+public:
+ MidiChannelFilter();
+
+ /** Filter `bufs` in-place. */
+ void filter(BufferSet& bufs);
+
+ /** Filter/map a MIDI message by channel.
+ *
+ * May modify the channel in `buf` if necessary.
+ *
+ * @return true if this event should be filtered out.
+ */
+ bool filter(uint8_t* buf, uint32_t len);
+
+ /** Atomically set the channel mode and corresponding mask.
+ * @return true iff configuration changed.
+ */
+ bool set_channel_mode(ChannelMode mode, uint16_t mask);
+
+ /** Atomically set the channel mask for the current mode.
+ * @return true iff configuration changed.
+ */
+ bool set_channel_mask(uint16_t mask);
+
+ /** Atomically get both the channel mode and mask. */
+ void get_mode_and_mask(ChannelMode* mode, uint16_t* mask) const {
+ const uint32_t mm = g_atomic_int_get(&_mode_mask);
+ *mode = static_cast<ChannelMode>((mm & 0xFFFF0000) >> 16);
+ *mask = (mm & 0x0000FFFF);
+ }
+
+ ChannelMode get_channel_mode() const {
+ return static_cast<ChannelMode>((g_atomic_int_get(&_mode_mask) & 0xFFFF0000) >> 16);
+ }
+
+ uint16_t get_channel_mask() const {
+ return g_atomic_int_get(&_mode_mask) & 0x0000FFFF;
+ }
+
+ PBD::Signal0<void> ChannelMaskChanged;
+ PBD::Signal0<void> ChannelModeChanged;
+
+private:
+ uint32_t _mode_mask; ///< 16 bits mode, 16 bits mask
+};
+
+} /* namespace ARDOUR */
+
+#endif /* __ardour_channel_filter_h__ */
diff --git a/libs/ardour/ardour/midi_playlist.h b/libs/ardour/ardour/midi_playlist.h
index 614a5e1c1f..cb07bc1820 100644
--- a/libs/ardour/ardour/midi_playlist.h
+++ b/libs/ardour/ardour/midi_playlist.h
@@ -42,6 +42,7 @@ namespace ARDOUR
{
class BeatsFramesConverter;
+class MidiChannelFilter;
class MidiRegion;
class Session;
class Source;
@@ -77,7 +78,8 @@ public:
framecnt_t read (Evoral::EventSink<framepos_t>& buf,
framepos_t start,
framecnt_t cnt,
- uint32_t chan_n = 0);
+ uint32_t chan_n = 0,
+ MidiChannelFilter* filter = NULL);
int set_state (const XMLNode&, int version);
diff --git a/libs/ardour/ardour/midi_playlist_source.h b/libs/ardour/ardour/midi_playlist_source.h
index 6633be3c9e..12c184d7b5 100644
--- a/libs/ardour/ardour/midi_playlist_source.h
+++ b/libs/ardour/ardour/midi_playlist_source.h
@@ -65,7 +65,8 @@ protected:
framepos_t position,
framepos_t start,
framecnt_t cnt,
- MidiStateTracker* tracker) const;
+ MidiStateTracker* tracker,
+ MidiChannelFilter* filter) const;
framecnt_t write_unlocked (const Lock& lock,
MidiRingBuffer<framepos_t>& dst,
diff --git a/libs/ardour/ardour/midi_region.h b/libs/ardour/ardour/midi_region.h
index f7e6c97ea0..87e89c695b 100644
--- a/libs/ardour/ardour/midi_region.h
+++ b/libs/ardour/ardour/midi_region.h
@@ -43,13 +43,14 @@ template<typename Time> class EventSink;
namespace ARDOUR {
-class Route;
-class Playlist;
-class Session;
+class MidiChannelFilter;
class MidiFilter;
class MidiModel;
class MidiSource;
class MidiStateTracker;
+class Playlist;
+class Route;
+class Session;
template<typename T> class MidiRingBuffer;
@@ -74,7 +75,8 @@ class LIBARDOUR_API MidiRegion : public Region
framecnt_t dur,
uint32_t chan_n = 0,
NoteMode mode = Sustained,
- MidiStateTracker* tracker = 0) const;
+ MidiStateTracker* tracker = 0,
+ MidiChannelFilter* filter = 0) const;
framecnt_t master_read_at (MidiRingBuffer<framepos_t>& dst,
framepos_t position,
@@ -121,7 +123,8 @@ class LIBARDOUR_API MidiRegion : public Region
framecnt_t dur,
uint32_t chan_n = 0,
NoteMode mode = Sustained,
- MidiStateTracker* tracker = 0) const;
+ MidiStateTracker* tracker = 0,
+ MidiChannelFilter* filter = 0) const;
void register_properties ();
void post_set (const PBD::PropertyChange&);
diff --git a/libs/ardour/ardour/midi_source.h b/libs/ardour/ardour/midi_source.h
index 156f3dbfa0..6a55398ca9 100644
--- a/libs/ardour/ardour/midi_source.h
+++ b/libs/ardour/ardour/midi_source.h
@@ -34,6 +34,7 @@
namespace ARDOUR {
+class MidiChannelFilter;
class MidiStateTracker;
class MidiModel;
@@ -77,6 +78,7 @@ class LIBARDOUR_API MidiSource : virtual public Source, public boost::enable_sha
framepos_t start,
framecnt_t cnt,
MidiStateTracker* tracker,
+ MidiChannelFilter* filter,
const std::set<Evoral::Parameter>& filtered) const;
/** Write data from a MidiRingBuffer to this source.
@@ -192,7 +194,8 @@ class LIBARDOUR_API MidiSource : virtual public Source, public boost::enable_sha
framepos_t position,
framepos_t start,
framecnt_t cnt,
- MidiStateTracker* tracker) const = 0;
+ MidiStateTracker* tracker,
+ MidiChannelFilter* filter) const = 0;
/** Write data to this source from a MidiRingBuffer.
* @param source Buffer to read from.
diff --git a/libs/ardour/ardour/midi_track.h b/libs/ardour/ardour/midi_track.h
index a12a0c6087..f2542f0f6b 100644
--- a/libs/ardour/ardour/midi_track.h
+++ b/libs/ardour/ardour/midi_track.h
@@ -20,10 +20,9 @@
#ifndef __ardour_midi_track_h__
#define __ardour_midi_track_h__
-#include "pbd/ffs.h"
-
-#include "ardour/track.h"
+#include "ardour/midi_channel_filter.h"
#include "ardour/midi_ring_buffer.h"
+#include "ardour/track.h"
namespace ARDOUR
{
@@ -109,38 +108,22 @@ public:
boost::shared_ptr<SMFSource> write_source (uint32_t n = 0);
- /** Channel filtering mode.
- * @param mask If mode is FilterChannels, each bit represents a midi channel:
- * bit 0 = channel 0, bit 1 = channel 1 etc. the read and write methods will only
- * process events whose channel bit is 1.
- * If mode is ForceChannel, mask is simply a channel number which all events will
- * be forced to while reading.
- */
+ /* Configure capture/playback channels (see MidiChannelFilter). */
void set_capture_channel_mode (ChannelMode mode, uint16_t mask);
void set_playback_channel_mode (ChannelMode mode, uint16_t mask);
void set_playback_channel_mask (uint16_t mask);
void set_capture_channel_mask (uint16_t mask);
- ChannelMode get_playback_channel_mode() const {
- return static_cast<ChannelMode>((g_atomic_int_get(&_playback_channel_mask) & 0xffff0000) >> 16);
- }
- uint16_t get_playback_channel_mask() const {
- return g_atomic_int_get(&_playback_channel_mask) & 0x0000ffff;
- }
- ChannelMode get_capture_channel_mode() const {
- return static_cast<ChannelMode>((g_atomic_int_get(&_capture_channel_mask) & 0xffff0000) >> 16);
- }
- uint16_t get_capture_channel_mask() const {
- return g_atomic_int_get(&_capture_channel_mask) & 0x0000ffff;
- }
+ ChannelMode get_playback_channel_mode() const { return _playback_filter.get_channel_mode(); }
+ ChannelMode get_capture_channel_mode() const { return _capture_filter.get_channel_mode(); }
+ uint16_t get_playback_channel_mask() const { return _playback_filter.get_channel_mask(); }
+ uint16_t get_capture_channel_mask() const { return _capture_filter.get_channel_mask(); }
+
+ MidiChannelFilter& playback_filter() { return _playback_filter; }
+ MidiChannelFilter& capture_filter() { return _capture_filter; }
boost::shared_ptr<MidiPlaylist> midi_playlist ();
- PBD::Signal0<void> PlaybackChannelMaskChanged;
- PBD::Signal0<void> PlaybackChannelModeChanged;
- PBD::Signal0<void> CaptureChannelMaskChanged;
- PBD::Signal0<void> CaptureChannelModeChanged;
-
PBD::Signal1<void, boost::weak_ptr<MidiSource> > DataRecorded;
boost::shared_ptr<MidiBuffer> get_gui_feed_buffer () const;
@@ -162,8 +145,8 @@ private:
NoteMode _note_mode;
bool _step_editing;
bool _input_active;
- uint32_t _playback_channel_mask; // 16 bits mode, 16 bits mask
- uint32_t _capture_channel_mask; // 16 bits mode, 16 bits mask
+ MidiChannelFilter _playback_filter;
+ MidiChannelFilter _capture_filter;
virtual boost::shared_ptr<Diskstream> diskstream_factory (XMLNode const &);
@@ -186,32 +169,6 @@ private:
/** Update automation controls to reflect any changes in buffers. */
void update_controls (const BufferSet& bufs);
-
- void filter_channels (BufferSet& bufs, ChannelMode mode, uint32_t mask);
-
-/* if mode is ForceChannel, force mask to the lowest set channel or 1 if no
- * channels are set.
- */
-#define force_mask(mode,mask) (((mode) == ForceChannel) ? (((mask) ? (1<<(PBD::ffs((mask))-1)) : 1)) : mask)
-
- void _set_playback_channel_mode(ChannelMode mode, uint16_t mask) {
- mask = force_mask (mode, mask);
- g_atomic_int_set(&_playback_channel_mask, (uint32_t(mode) << 16) | uint32_t(mask));
- }
- void _set_playback_channel_mask (uint16_t mask) {
- mask = force_mask (get_playback_channel_mode(), mask);
- g_atomic_int_set(&_playback_channel_mask, (uint32_t(get_playback_channel_mode()) << 16) | uint32_t(mask));
- }
- void _set_capture_channel_mode(ChannelMode mode, uint16_t mask) {
- mask = force_mask (mode, mask);
- g_atomic_int_set(&_capture_channel_mask, (uint32_t(mode) << 16) | uint32_t(mask));
- }
- void _set_capture_channel_mask (uint16_t mask) {
- mask = force_mask (get_capture_channel_mode(), mask);
- g_atomic_int_set(&_capture_channel_mask, (uint32_t(get_capture_channel_mode()) << 16) | uint32_t(mask));
- }
-
-#undef force_mask
};
} /* namespace ARDOUR*/
diff --git a/libs/ardour/ardour/smf_source.h b/libs/ardour/ardour/smf_source.h
index 29c6403694..d088f2d867 100644
--- a/libs/ardour/ardour/smf_source.h
+++ b/libs/ardour/ardour/smf_source.h
@@ -93,7 +93,8 @@ public:
framepos_t position,
framepos_t start,
framecnt_t cnt,
- MidiStateTracker* tracker) const;
+ MidiStateTracker* tracker,
+ MidiChannelFilter* filter) const;
framecnt_t write_unlocked (const Lock& lock,
MidiRingBuffer<framepos_t>& src,