1 /*
2  * Hydrogen
3  * Copyright(c) 2015-2016 by Przemysław Sitek
4  *
5  * http://www.hydrogen-music.org
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY, without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  *
21  */
22 #ifndef H2C_AUTOMATION_PATH_H
23 #define H2C_AUTOMATION_PATH_H
24 
25 #include <hydrogen/object.h>
26 
27 #include <map>
28 
29 #if __cplusplus <= 199711L
30 #  define noexcept
31 #endif
32 
33 namespace H2Core
34 {
35 
36 class AutomationPath : private Object
37 {
38 	H2_OBJECT
39 
40 	public:
41 	typedef std::map<float,float>::iterator iterator;
42 	typedef std::map<float,float>::const_iterator const_iterator;
43 
44 	private:
45 
46 	float _min;
47 	float _max;
48 	float _def;
49 
50 	std::map<float,float> _points;
51 
52 	public:
53 
54 	AutomationPath(float min, float max, float def);
55 
empty()56 	bool empty() const noexcept { return _points.empty(); }
get_min()57 	float get_min() const noexcept { return _min; }
get_max()58 	float get_max() const noexcept { return _max; }
get_default()59 	float get_default() const noexcept { return _def; }
60 
61 	float get_value(float x) const noexcept;
62 
63 	void add_point(float x, float y);
64 	void remove_point(float x);
65 
66 	friend bool operator==(const AutomationPath &lhs, const AutomationPath &rhs);
67 	friend bool operator!=(const AutomationPath &lhs, const AutomationPath &rhs);
68 
begin()69 	iterator begin() { return _points.begin(); }
end()70 	iterator end() { return _points.end(); }
begin()71 	const_iterator begin() const { return _points.begin(); }
end()72 	const_iterator end() const { return _points.end(); }
73 
74 	iterator find(float x);
75 	iterator move(iterator &in, float x, float y);
76 };
77 
78 std::ostream &operator<< (std::ostream &o, const AutomationPath &p);
79 
80 };
81 
82 #endif
83