|
18 | 18 | /// barely::Engine engine(/*sample_rate=*/48000, /*max_frame_count=*/512); |
19 | 19 | /// |
20 | 20 | /// // Set the tempo. |
21 | | -/// engine.SetControl(barely::EngineControlType::kTempo, 124.0f); |
| 21 | +/// engine.SetTempo(/*tempo=*/124.0); |
22 | 22 | /// |
23 | 23 | /// // Update the timestamp. |
24 | 24 | /// // |
|
97 | 97 | /// BARELY_DEFAULT_REFERENCE_FREQUENCY, &engine); |
98 | 98 | /// |
99 | 99 | /// // Set the tempo. |
100 | | -/// BarelyEngine_SetControl(engine, BarelyEngineControlType_kTempo, /*tempo=*/124.0f); |
| 100 | +/// BarelyEngine_SetTempo(engine, /*tempo=*/124.0); |
101 | 101 | /// |
102 | 102 | /// // Update the timestamp. |
103 | 103 | /// // |
@@ -237,10 +237,8 @@ typedef enum BarelyArpMode { |
237 | 237 |
|
238 | 238 | /// Engine control types. |
239 | 239 | typedef enum BarelyEngineControlType { |
240 | | - /// Tempo in beats per minute. |
241 | | - BarelyEngineControlType_kTempo = 0, |
242 | 240 | /// Compressor mix. |
243 | | - BarelyEngineControlType_kCompressorMix, |
| 241 | + BarelyEngineControlType_kCompressorMix = 0, |
244 | 242 | /// Compressor attack in seconds. |
245 | 243 | BarelyEngineControlType_kCompressorAttack, |
246 | 244 | /// Compressor release in seconds. |
@@ -528,6 +526,13 @@ BARELY_API bool BarelyEngine_GetControl(BarelyEngineHandle engine, BarelyEngineC |
528 | 526 | /// @return True if successful, false otherwise. |
529 | 527 | BARELY_API bool BarelyEngine_GetSeed(BarelyEngineHandle engine, int32_t* out_seed); |
530 | 528 |
|
| 529 | +/// Gets the tempo of an engine. |
| 530 | +/// |
| 531 | +/// @param engine Engine handle. |
| 532 | +/// @param out_tempo Output tempo in beats per minute. |
| 533 | +/// @return True if successful, false otherwise. |
| 534 | +BARELY_API bool BarelyEngine_GetTempo(BarelyEngineHandle engine, double* out_tempo); |
| 535 | + |
531 | 536 | /// Gets the timestamp of an engine. |
532 | 537 | /// |
533 | 538 | /// @param engine Engine handle. |
@@ -563,6 +568,13 @@ BARELY_API bool BarelyEngine_SetControl(BarelyEngineHandle engine, BarelyEngineC |
563 | 568 | /// @return True if successful, false otherwise. |
564 | 569 | BARELY_API bool BarelyEngine_SetSeed(BarelyEngineHandle engine, int32_t seed); |
565 | 570 |
|
| 571 | +/// Sets the tempo of an engine. |
| 572 | +/// |
| 573 | +/// @param engine Engine handle. |
| 574 | +/// @param tempo Tempo in beats per minute. |
| 575 | +/// @return True if successful, false otherwise. |
| 576 | +BARELY_API bool BarelyEngine_SetTempo(BarelyEngineHandle engine, double tempo); |
| 577 | + |
566 | 578 | /// Updates an engine at timestamp. |
567 | 579 | /// |
568 | 580 | /// @param engine Engine handle. |
@@ -962,8 +974,6 @@ enum class InstrumentControlType { |
962 | 974 |
|
963 | 975 | /// Engine control types. |
964 | 976 | enum class EngineControlType { |
965 | | - /// Tempo in beats per minute. |
966 | | - kTempo = BarelyEngineControlType_kTempo, |
967 | 977 | /// Compressor mix. |
968 | 978 | kCompressorMix = BarelyEngineControlType_kCompressorMix, |
969 | 979 | /// Compressor attack in seconds. |
@@ -1806,6 +1816,16 @@ class Engine : public HandleWrapper<BarelyEngineHandle> { |
1806 | 1816 | return static_cast<int>(seed); |
1807 | 1817 | } |
1808 | 1818 |
|
| 1819 | + /// Returns the tempo. |
| 1820 | + /// |
| 1821 | + /// @return Tempo in beats per minute. |
| 1822 | + [[nodiscard]] double GetTempo() const noexcept { |
| 1823 | + double tempo = 0.0; |
| 1824 | + [[maybe_unused]] const bool success = BarelyEngine_GetTempo(*this, &tempo); |
| 1825 | + assert(success); |
| 1826 | + return tempo; |
| 1827 | + } |
| 1828 | + |
1809 | 1829 | /// Returns the timestamp. |
1810 | 1830 | /// |
1811 | 1831 | /// @return Timestamp in seconds. |
@@ -1849,6 +1869,14 @@ class Engine : public HandleWrapper<BarelyEngineHandle> { |
1849 | 1869 | assert(success); |
1850 | 1870 | } |
1851 | 1871 |
|
| 1872 | + /// Sets the tempo. |
| 1873 | + /// |
| 1874 | + /// @param tempo Tempo in beats per minute. |
| 1875 | + void SetTempo(double tempo) noexcept { |
| 1876 | + [[maybe_unused]] const bool success = BarelyEngine_SetTempo(*this, tempo); |
| 1877 | + assert(success); |
| 1878 | + } |
| 1879 | + |
1852 | 1880 | /// Updates the engine at timestamp. |
1853 | 1881 | /// |
1854 | 1882 | /// @param timestamp Timestamp in seconds. |
|
0 commit comments