|
| 1 | +#pragma once |
| 2 | +#include <halp/audio.hpp> |
| 3 | + |
| 4 | +#include <optional> |
| 5 | +namespace examples |
| 6 | +{ |
| 7 | +struct TimingSplitter |
| 8 | +{ |
| 9 | + static consteval auto name() { return "Beat metronome"; } |
| 10 | + static consteval auto c_name() { return "avnd_timing_splitter"; } |
| 11 | + static consteval auto author() { return "Jean-Michaël Celerier"; } |
| 12 | + static consteval auto category() { return "Control/Timing"; } |
| 13 | + static consteval auto manual_url() |
| 14 | + { |
| 15 | + return "https://ossia.io/score-docs/processes/" |
| 16 | + "control-utilities.html#impulse-metronome"; |
| 17 | + } |
| 18 | + static consteval auto description() |
| 19 | + { |
| 20 | + return "Outputs various musical timing subdivisions"; |
| 21 | + } |
| 22 | + static consteval auto uuid() { return "4c9e6ca5-96c5-4df4-bca4-1e9693b98c9f"; } |
| 23 | + |
| 24 | + /* |
| 25 | + struct |
| 26 | + { |
| 27 | + struct |
| 28 | + { |
| 29 | + enum E |
| 30 | + { |
| 31 | + Parent, |
| 32 | + Custom |
| 33 | + } value{}; |
| 34 | + enum widget |
| 35 | + { |
| 36 | + enumeration |
| 37 | + }; |
| 38 | + struct range |
| 39 | + { |
| 40 | + std::string_view values[2]{"Parent", "Custom"}; |
| 41 | + E init{}; |
| 42 | + }; |
| 43 | + } sync_mode; |
| 44 | +
|
| 45 | + struct |
| 46 | + { |
| 47 | + enum widget |
| 48 | + { |
| 49 | + time_chooser |
| 50 | + }; |
| 51 | +
|
| 52 | + struct range |
| 53 | + { |
| 54 | + const float min = 0.0; |
| 55 | + const float max = 10.0; |
| 56 | + const float init = 1.0; |
| 57 | + }; |
| 58 | +
|
| 59 | + static constexpr auto name() { return "Time"; } |
| 60 | +
|
| 61 | + float value = range{}.init; |
| 62 | + } duration; |
| 63 | +
|
| 64 | + } inputs; |
| 65 | + */ |
| 66 | + struct |
| 67 | + { |
| 68 | + struct |
| 69 | + { |
| 70 | + static constexpr auto name() { return "tick"; } |
| 71 | + std::optional<float> value; |
| 72 | + } tick; |
| 73 | + struct |
| 74 | + { |
| 75 | + static constexpr auto name() { return "tock"; } |
| 76 | + std::optional<float> value; |
| 77 | + } tock; |
| 78 | + struct |
| 79 | + { |
| 80 | + static constexpr auto name() { return "4 bars"; } |
| 81 | + std::optional<float> value; |
| 82 | + } bar_4; |
| 83 | + struct |
| 84 | + { |
| 85 | + static constexpr auto name() { return "2 bars"; } |
| 86 | + std::optional<float> value; |
| 87 | + } bar_2; |
| 88 | + struct |
| 89 | + { |
| 90 | + static constexpr auto name() { return "1 bar"; } |
| 91 | + std::optional<float> value; |
| 92 | + } bar_1; |
| 93 | + struct |
| 94 | + { |
| 95 | + static constexpr auto name() { return "half note"; } |
| 96 | + std::optional<float> value; |
| 97 | + } half; |
| 98 | + struct |
| 99 | + { |
| 100 | + static constexpr auto name() { return "4th note"; } |
| 101 | + std::optional<float> value; |
| 102 | + } quarter; |
| 103 | + struct |
| 104 | + { |
| 105 | + static constexpr auto name() { return "8th note"; } |
| 106 | + std::optional<float> value; |
| 107 | + } quaver; |
| 108 | + struct |
| 109 | + { |
| 110 | + static constexpr auto name() { return "16th note"; } |
| 111 | + std::optional<float> value; |
| 112 | + } semiquaver; |
| 113 | + } outputs; |
| 114 | + |
| 115 | + using tick = halp::tick_flicks; |
| 116 | + void operator()(halp::tick_flicks t) |
| 117 | + { |
| 118 | + t.metronome([&](int sample) { outputs.tick.value = 1.; }, [&](int sample) { |
| 119 | + outputs.tock.value = 1.; |
| 120 | + }); |
| 121 | + for(auto r : t.get_quantification_date(16.)) |
| 122 | + outputs.semiquaver.value = r.second; |
| 123 | + for(auto r : t.get_quantification_date(8.)) |
| 124 | + outputs.quaver.value = r.second; |
| 125 | + for(auto r : t.get_quantification_date(4.)) |
| 126 | + outputs.quarter.value = r.second; |
| 127 | + for(auto r : t.get_quantification_date(2.)) |
| 128 | + outputs.half.value = r.second; |
| 129 | + for(auto r : t.get_quantification_date(1.)) |
| 130 | + outputs.bar_1.value = r.second; |
| 131 | + for(auto r : t.get_quantification_date(0.5)) |
| 132 | + outputs.bar_2.value = r.second; |
| 133 | + for(auto r : t.get_quantification_date(0.25)) |
| 134 | + outputs.bar_4.value = r.second; |
| 135 | + } |
| 136 | +}; |
| 137 | +} |
0 commit comments