Support cut/copy/paste of several regions and lines at once.
[ardour.git] / gtk2_ardour / item_counts.h
1 /*
2     Copyright (C) 2014 Paul Davis
3     Author: David Robillard
4
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.
9
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.
14
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.
18 */
19
20 #ifndef __ardour_item_counts_h__
21 #define __ardour_item_counts_h__
22
23 #include <cstddef>
24 #include <map>
25 #include <utility>
26
27 #include "ardour/data_type.h"
28 #include "evoral/Parameter.hpp"
29
30 /** A count of various GUI items.
31  *
32  * This is used to keep track of 'consumption' of a selection when pasting, but
33  * may be useful elsewhere.
34  */
35 class ItemCounts
36 {
37 public:
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); }
41
42         void increase_n_playlists(ARDOUR::DataType t, size_t delta=1) {
43                 increase_n(t, _playlists, delta);
44         }
45
46         void increase_n_regions(ARDOUR::DataType t, size_t delta=1) {
47                 increase_n(t, _regions, delta);
48         }
49
50         void increase_n_lines(Evoral::Parameter t, size_t delta=1) {
51                 increase_n(t, _lines, delta);
52         }
53
54 private:
55         template<typename Key>
56         size_t
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;
60         }
61
62         template<typename Key>
63         void
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()) {
67                         i->second += delta;
68                 } else {
69                         counts.insert(std::make_pair(key, delta));
70                 }
71         }
72
73         std::map<ARDOUR::DataType,  size_t> _playlists;
74         std::map<ARDOUR::DataType,  size_t> _regions;
75         std::map<Evoral::Parameter, size_t> _lines;
76 };
77
78 #endif /* __ardour_item_counts_h__ */