summaryrefslogtreecommitdiff
path: root/gtk2_ardour/item_counts.h
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2014-11-16 17:04:27 -0500
committerDavid Robillard <d@drobilla.net>2014-11-16 22:35:45 -0500
commit2fa6caad95d81f058326d931532f687a157361be (patch)
tree2981806b2bfec9351d62ccfc7e5d0e7dfe3581aa /gtk2_ardour/item_counts.h
parent5393982c8022d4117a6fe29340f8ecf2d115648d (diff)
Support cut/copy/paste of several regions and lines at once.
The idea here is to do the reasonable thing, and copy objects of some type (e.g. MIDI region, gain line) to tracks with a matching type. The user can override this with a track selection, which will be used straight-up. Lost: ability to copy/paste lines across types, e.g. gain to pan. This is often questionable, but sometimes useful, so we will need to implement some sort of "greedy mode" to make it possible. Implementation simple, but not sure what to do. Perhaps this should only be possible if one automation track is explicitly (i.e. via track selection) involved, and the types are at least compatible-ish?
Diffstat (limited to 'gtk2_ardour/item_counts.h')
-rw-r--r--gtk2_ardour/item_counts.h78
1 files changed, 78 insertions, 0 deletions
diff --git a/gtk2_ardour/item_counts.h b/gtk2_ardour/item_counts.h
new file mode 100644
index 0000000000..b7c6dbd9c6
--- /dev/null
+++ b/gtk2_ardour/item_counts.h
@@ -0,0 +1,78 @@
+/*
+ Copyright (C) 2014 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_item_counts_h__
+#define __ardour_item_counts_h__
+
+#include <cstddef>
+#include <map>
+#include <utility>
+
+#include "ardour/data_type.h"
+#include "evoral/Parameter.hpp"
+
+/** A count of various GUI items.
+ *
+ * This is used to keep track of 'consumption' of a selection when pasting, but
+ * may be useful elsewhere.
+ */
+class ItemCounts
+{
+public:
+ size_t n_playlists(ARDOUR::DataType t) const { return get_n(t, _playlists); }
+ size_t n_regions(ARDOUR::DataType t) const { return get_n(t, _regions); }
+ size_t n_lines(Evoral::Parameter t) const { return get_n(t, _lines); }
+
+ void increase_n_playlists(ARDOUR::DataType t, size_t delta=1) {
+ increase_n(t, _playlists, delta);
+ }
+
+ void increase_n_regions(ARDOUR::DataType t, size_t delta=1) {
+ increase_n(t, _regions, delta);
+ }
+
+ void increase_n_lines(Evoral::Parameter t, size_t delta=1) {
+ increase_n(t, _lines, delta);
+ }
+
+private:
+ template<typename Key>
+ size_t
+ get_n(const Key& key, const typename std::map<Key, size_t>& counts) const {
+ typename std::map<Key, size_t>::const_iterator i = counts.find(key);
+ return (i == counts.end()) ? 0 : i->second;
+ }
+
+ template<typename Key>
+ void
+ increase_n(const Key& key, typename std::map<Key, size_t>& counts, size_t delta) {
+ typename std::map<Key, size_t>::iterator i = counts.find(key);
+ if (i != counts.end()) {
+ i->second += delta;
+ } else {
+ counts.insert(std::make_pair(key, delta));
+ }
+ }
+
+ std::map<ARDOUR::DataType, size_t> _playlists;
+ std::map<ARDOUR::DataType, size_t> _regions;
+ std::map<Evoral::Parameter, size_t> _lines;
+};
+
+#endif /* __ardour_item_counts_h__ */