2 Copyright (C) 2014 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_item_counts_h__
21 #define __ardour_item_counts_h__
27 #include "ardour/data_type.h"
28 #include "evoral/Parameter.hpp"
30 /** A count of various GUI items.
32 * This is used to keep track of 'consumption' of a selection when pasting, but
33 * may be useful elsewhere.
38 size_t n_playlists(ARDOUR::DataType t) const { return get_n(t, _playlists); }
39 size_t n_regions(ARDOUR::DataType t) const { return get_n(t, _regions); }
40 size_t n_lines(Evoral::Parameter t) const { return get_n(t, _lines); }
42 void increase_n_playlists(ARDOUR::DataType t, size_t delta=1) {
43 increase_n(t, _playlists, delta);
46 void increase_n_regions(ARDOUR::DataType t, size_t delta=1) {
47 increase_n(t, _regions, delta);
50 void increase_n_lines(Evoral::Parameter t, size_t delta=1) {
51 increase_n(t, _lines, delta);
55 template<typename Key>
57 get_n(const Key& key, const typename std::map<Key, size_t>& counts) const {
58 typename std::map<Key, size_t>::const_iterator i = counts.find(key);
59 return (i == counts.end()) ? 0 : i->second;
62 template<typename Key>
64 increase_n(const Key& key, typename std::map<Key, size_t>& counts, size_t delta) {
65 typename std::map<Key, size_t>::iterator i = counts.find(key);
66 if (i != counts.end()) {
69 counts.insert(std::make_pair(key, delta));
73 std::map<ARDOUR::DataType, size_t> _playlists;
74 std::map<ARDOUR::DataType, size_t> _regions;
75 std::map<Evoral::Parameter, size_t> _lines;
78 #endif /* __ardour_item_counts_h__ */