/usr/include/ableton/Link.ipp is in ableton-link-dev 1.0.0+dfsg-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 | /* Copyright 2016, Ableton AG, Berlin. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* If you would like to incorporate Link into a proprietary software application,
* please contact <link-devs@ableton.com>.
*/
#pragma once
#include <ableton/link/Phase.hpp>
namespace ableton
{
inline Link::Link(const double bpm)
: mPeerCountCallback([](std::size_t)
{
})
, mTempoCallback([](link::Tempo)
{
})
, mClock{}
, mController(link::Tempo(bpm),
[this](const std::size_t peers)
{
std::lock_guard<std::mutex> lock(mCallbackMutex);
mPeerCountCallback(peers);
},
[this](const link::Tempo tempo)
{
std::lock_guard<std::mutex> lock(mCallbackMutex);
mTempoCallback(tempo);
},
mClock,
util::injectVal(link::platform::IoContext{}))
{
}
inline bool Link::isEnabled() const
{
return mController.isEnabled();
}
inline void Link::enable(const bool bEnable)
{
mController.enable(bEnable);
}
inline std::size_t Link::numPeers() const
{
return mController.numPeers();
}
template <typename Callback>
void Link::setNumPeersCallback(Callback callback)
{
std::lock_guard<std::mutex> lock(mCallbackMutex);
mPeerCountCallback = [callback](const std::size_t numPeers)
{
callback(numPeers);
};
}
template <typename Callback>
void Link::setTempoCallback(Callback callback)
{
std::lock_guard<std::mutex> lock(mCallbackMutex);
mTempoCallback = [callback](const link::Tempo tempo)
{
callback(tempo.bpm());
};
}
inline Link::Clock Link::clock() const
{
return mClock;
}
inline Link::Timeline Link::captureAudioTimeline() const
{
return Link::Timeline{mController.timelineRtSafe(), numPeers() > 0};
}
inline void Link::commitAudioTimeline(const Link::Timeline timeline)
{
if (timeline.mOriginalTimeline != timeline.mTimeline)
{
mController.setTimelineRtSafe(timeline.mTimeline, mClock.micros());
}
}
inline Link::Timeline Link::captureAppTimeline() const
{
return Link::Timeline{mController.timeline(), numPeers() > 0};
}
inline void Link::commitAppTimeline(const Link::Timeline timeline)
{
if (timeline.mOriginalTimeline != timeline.mTimeline)
{
mController.setTimeline(timeline.mTimeline, mClock.micros());
}
}
// Link::Timeline
inline Link::Timeline::Timeline(const link::Timeline timeline, const bool bRespectQuantum)
: mOriginalTimeline(timeline)
, mbRespectQuantum(bRespectQuantum)
, mTimeline(timeline)
{
}
inline double Link::Timeline::tempo() const
{
return mTimeline.tempo.bpm();
}
inline void Link::Timeline::setTempo(
const double bpm, const std::chrono::microseconds atTime)
{
const auto desiredTl =
link::clampTempo(link::Timeline{link::Tempo(bpm), mTimeline.toBeats(atTime), atTime});
mTimeline.tempo = desiredTl.tempo;
mTimeline.timeOrigin = desiredTl.fromBeats(mTimeline.beatOrigin);
}
inline double Link::Timeline::beatAtTime(
const std::chrono::microseconds time, const double quantum) const
{
return link::toPhaseEncodedBeats(mTimeline, time, link::Beats{quantum}).floating();
}
inline double Link::Timeline::phaseAtTime(
const std::chrono::microseconds time, const double quantum) const
{
return link::phase(link::Beats{beatAtTime(time, quantum)}, link::Beats{quantum})
.floating();
}
inline std::chrono::microseconds Link::Timeline::timeAtBeat(
const double beat, const double quantum) const
{
return link::fromPhaseEncodedBeats(mTimeline, link::Beats{beat}, link::Beats{quantum});
}
inline void Link::Timeline::requestBeatAtTime(
const double beat, std::chrono::microseconds time, const double quantum)
{
if (mbRespectQuantum)
{
time = timeAtBeat(link::nextPhaseMatch(link::Beats{beatAtTime(time, quantum)},
link::Beats{beat}, link::Beats{quantum})
.floating(),
quantum);
}
forceBeatAtTime(beat, time, quantum);
}
inline void Link::Timeline::forceBeatAtTime(
const double beat, const std::chrono::microseconds time, const double quantum)
{
// There are two components to the beat adjustment: a phase shift
// and a beat magnitude adjustment.
const auto curBeatAtTime = link::Beats{beatAtTime(time, quantum)};
const auto closestInPhase =
link::closestPhaseMatch(curBeatAtTime, link::Beats{beat}, link::Beats{quantum});
mTimeline = shiftClientTimeline(mTimeline, closestInPhase - curBeatAtTime);
// Now adjust the magnitude
mTimeline.beatOrigin = mTimeline.beatOrigin + (link::Beats{beat} - closestInPhase);
}
} // ableton
|