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.2KB

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