Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

AudioEngine.hpp 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. #pragma once
  20. #ifdef LINK_PLATFORM_WINDOWS
  21. #define _USE_MATH_DEFINES
  22. #if __BIG_ENDIAN__
  23. # define htonll(x) (x)
  24. # define ntohll(x) (x)
  25. #else
  26. # define htonll(x) ((uint64_t)htonl(((x) & 0xFFFFFFFF) << 32) | htonl((x) >> 32))
  27. # define ntohll(x) ((uint64_t)ntohl(((x) & 0xFFFFFFFF) << 32) | ntohl((x) >> 32))
  28. #endif
  29. #endif
  30. #include <cmath>
  31. #include "ableton/Link.hpp"
  32. struct LinkTimeInfo {
  33. double beatsPerBar, beatsPerMinute, beat, phase;
  34. bool playing;
  35. };
  36. namespace ableton
  37. {
  38. namespace link
  39. {
  40. class AudioEngine
  41. {
  42. public:
  43. AudioEngine(Link& link);
  44. void startPlaying();
  45. void stopPlaying();
  46. bool isPlaying() const;
  47. double beatTime() const;
  48. void setTempo(double tempo);
  49. double quantum() const;
  50. void setQuantum(double quantum);
  51. bool isStartStopSyncEnabled() const;
  52. void setStartStopSyncEnabled(bool enabled);
  53. void timelineCallback(const std::chrono::microseconds hostTime, LinkTimeInfo* const info);
  54. private:
  55. struct EngineData
  56. {
  57. double requestedTempo;
  58. bool requestStart;
  59. bool requestStop;
  60. double quantum;
  61. bool startStopSyncOn;
  62. };
  63. EngineData pullEngineData();
  64. Link& mLink;
  65. EngineData mSharedEngineData;
  66. EngineData mLockfreeEngineData;
  67. bool mIsPlaying;
  68. std::mutex mEngineDataGuard;
  69. };
  70. } // namespace link
  71. } // namespace ableton