1 /* Copyright 2016, Ableton AG, Berlin. All rights reserved.
2  *
3  *  This program is free software: you can redistribute it and/or modify
4  *  it under the terms of the GNU General Public License as published by
5  *  the Free Software Foundation, either version 2 of the License, or
6  *  (at your option) any later version.
7  *
8  *  This program is distributed in the hope that it will be useful,
9  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  *  GNU General Public License for more details.
12  *
13  *  You should have received a copy of the GNU General Public License
14  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
15  *
16  *  If you would like to incorporate Link into a proprietary software application,
17  *  please contact <link-devs@ableton.com>.
18  */
19 
20 #pragma once
21 
22 #include <chrono>
23 #include <cmath>
24 
25 namespace ableton
26 {
27 namespace link
28 {
29 
30 using std::chrono::microseconds;
31 
32 struct GhostXForm
33 {
hostToGhostableton::link::GhostXForm34   microseconds hostToGhost(const microseconds hostTime) const
35   {
36     return microseconds{llround(slope * hostTime.count())} + intercept;
37   }
38 
ghostToHostableton::link::GhostXForm39   microseconds ghostToHost(const microseconds ghostTime) const
40   {
41     return microseconds{llround((ghostTime - intercept).count() / slope)};
42   }
43 
operator ==(const GhostXForm lhs,const GhostXForm rhs)44   friend bool operator==(const GhostXForm lhs, const GhostXForm rhs)
45   {
46     return lhs.slope == rhs.slope && lhs.intercept == rhs.intercept;
47   }
48 
operator !=(const GhostXForm lhs,const GhostXForm rhs)49   friend bool operator!=(const GhostXForm lhs, const GhostXForm rhs)
50   {
51     return !(lhs == rhs);
52   }
53 
54   double slope;
55   microseconds intercept;
56 };
57 
58 } // namespace link
59 } // namespace ableton
60