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.

93 lines
2.2KB

  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. #include <ableton/platforms/asio/AsioWrapper.hpp>
  21. #include <ableton/test/serial_io/Context.hpp>
  22. #include <chrono>
  23. #include <memory>
  24. namespace ableton
  25. {
  26. namespace test
  27. {
  28. namespace serial_io
  29. {
  30. class Fixture
  31. {
  32. public:
  33. Fixture()
  34. : mpScheduler(std::make_shared<SchedulerTree>())
  35. , mNow(std::chrono::milliseconds{123456789})
  36. {
  37. }
  38. ~Fixture()
  39. {
  40. flush();
  41. }
  42. Fixture(const Fixture&) = delete;
  43. Fixture& operator=(const Fixture&) = delete;
  44. Fixture(Fixture&&) = delete;
  45. Fixture& operator=(Fixture&&) = delete;
  46. void setNetworkInterfaces(std::vector<::asio::ip::address> ifAddrs)
  47. {
  48. mIfAddrs = std::move(ifAddrs);
  49. }
  50. Context makeIoContext()
  51. {
  52. return {mNow, mIfAddrs, mpScheduler};
  53. }
  54. void flush()
  55. {
  56. mpScheduler->run();
  57. }
  58. template <typename T, typename Rep>
  59. void advanceTime(std::chrono::duration<T, Rep> duration)
  60. {
  61. const auto target = mNow + duration;
  62. mpScheduler->run();
  63. auto nextTimer = mpScheduler->nextTimerExpiration();
  64. while (nextTimer <= target)
  65. {
  66. mNow = nextTimer;
  67. mpScheduler->triggerTimersUntil(mNow);
  68. mpScheduler->run();
  69. nextTimer = mpScheduler->nextTimerExpiration();
  70. }
  71. mNow = target;
  72. }
  73. private:
  74. std::shared_ptr<SchedulerTree> mpScheduler;
  75. SchedulerTree::TimePoint mNow;
  76. std::vector<::asio::ip::address> mIfAddrs;
  77. };
  78. } // namespace serial_io
  79. } // namespace test
  80. } // namespace ableton