2 * Copyright (C) 2014 David Robillard <d@drobilla.net>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 #ifndef __ardour_item_counts_h__
20 #define __ardour_item_counts_h__
26 #include "ardour/data_type.h"
27 #include "evoral/Parameter.hpp"
29 /** A count of various GUI items.
31 * This is used to keep track of 'consumption' of a selection when pasting, but
32 * may be useful elsewhere.
37 ItemCounts() : _notes(0) {}
39 size_t n_playlists(ARDOUR::DataType t) const { return get_n(t, _playlists); }
40 size_t n_regions(ARDOUR::DataType t) const { return get_n(t, _regions); }
41 size_t n_lines(Evoral::Parameter t) const { return get_n(t, _lines); }
42 size_t n_notes() const { return _notes; }
44 void increase_n_playlists(ARDOUR::DataType t, size_t delta=1) {
45 increase_n(t, _playlists, delta);
48 void increase_n_regions(ARDOUR::DataType t, size_t delta=1) {
49 increase_n(t, _regions, delta);
52 void increase_n_lines(Evoral::Parameter t, size_t delta=1) {
53 increase_n(t, _lines, delta);
56 void increase_n_notes(size_t delta=1) { _notes += delta; }
59 template<typename Key>
61 get_n(const Key& key, const typename std::map<Key, size_t>& counts) const {
62 typename std::map<Key, size_t>::const_iterator i = counts.find(key);
63 return (i == counts.end()) ? 0 : i->second;
66 template<typename Key>
68 increase_n(const Key& key, typename std::map<Key, size_t>& counts, size_t delta) {
69 typename std::map<Key, size_t>::iterator i = counts.find(key);
70 if (i != counts.end()) {
73 counts.insert(std::make_pair(key, delta));
77 std::map<ARDOUR::DataType, size_t> _playlists;
78 std::map<ARDOUR::DataType, size_t> _regions;
79 std::map<Evoral::Parameter, size_t> _lines;
83 #endif /* __ardour_item_counts_h__ */