BeatTimeMapping.hpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /* Copyright 2025, 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. #pragma once
  20. #include <ableton/link/Beats.hpp>
  21. #include <ableton/link/Phase.hpp>
  22. #include <ableton/link/Timeline.hpp>
  23. namespace ableton
  24. {
  25. namespace link_audio
  26. {
  27. static inline link::Beats globalBeatAtBeat(const link::Timeline& timeline,
  28. link::Beats targetBeat,
  29. link::Beats quantum)
  30. {
  31. const auto beatsDiff =
  32. link::toPhaseEncodedBeats(timeline, timeline.timeOrigin, quantum);
  33. return targetBeat - beatsDiff;
  34. }
  35. static inline link::Beats beatAtGlobalBeat(const link::Timeline& timeline,
  36. link::Beats globalBeat,
  37. link::Beats quantum)
  38. {
  39. const auto beatsDiff =
  40. link::toPhaseEncodedBeats(timeline, timeline.timeOrigin, quantum);
  41. return globalBeat + beatsDiff;
  42. }
  43. } // namespace link_audio
  44. } // namespace ableton