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 ItemCounts() : _notes(0) {}
40 size_t n_playlists(ARDOUR::DataType t) const { return get_n(t, _playlists); }
41 size_t n_regions(ARDOUR::DataType t) const { return get_n(t, _regions); }
42 size_t n_lines(Evoral::Parameter t) const { return get_n(t, _lines); }
43 size_t n_notes() const { return _notes; }
45 void increase_n_playlists(ARDOUR::DataType t, size_t delta=1) {
46 increase_n(t, _playlists, delta);
49 void increase_n_regions(ARDOUR::DataType t, size_t delta=1) {
50 increase_n(t, _regions, delta);
53 void increase_n_lines(Evoral::Parameter t, size_t delta=1) {
54 increase_n(t, _lines, delta);
57 void increase_n_notes(size_t delta=1) { _notes += delta; }
60 template<typename Key>
62 get_n(const Key& key, const typename std::map<Key, size_t>& counts) const {
63 typename std::map<Key, size_t>::const_iterator i = counts.find(key);
64 return (i == counts.end()) ? 0 : i->second;
67 template<typename Key>
69 increase_n(const Key& key, typename std::map<Key, size_t>& counts, size_t delta) {
70 typename std::map<Key, size_t>::iterator i = counts.find(key);
71 if (i != counts.end()) {
74 counts.insert(std::make_pair(key, delta));
78 std::map<ARDOUR::DataType, size_t> _playlists;
79 std::map<ARDOUR::DataType, size_t> _regions;
80 std::map<Evoral::Parameter, size_t> _lines;
84 #endif /* __ardour_item_counts_h__ */