Tabula Sonora 0.1.0
A native C++20 implementation of the Roland Sound Canvas VA synth voice
Loading...
Searching...
No Matches
partial_parameters.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <cstdint>
4#include <span>
5#include <utility>
6
7namespace ts {
8
21public:
23 static constexpr int stride = 0x6E;
24
26 static constexpr int no_multisample = 0xFFFF;
27
29 PartialParameters() = default;
30
32 explicit PartialParameters(const std::uint8_t* block) noexcept : block_(block) {}
33
35 [[nodiscard]] std::span<const std::uint8_t> raw() const noexcept
36 {
37 return {block_, static_cast<std::size_t>(stride)};
38 }
39
41 [[nodiscard]] bool is_present() const noexcept
42 {
43 return block_ != nullptr && multisample() != no_multisample;
44 }
45
47 [[nodiscard]] int multisample() const noexcept { return u16(0x02); }
48
50 [[nodiscard]] int key_center() const noexcept { return block_[0x04]; }
51
53 [[nodiscard]] int pan() const noexcept { return block_[0x0F]; }
54
56 [[nodiscard]] int key_transpose() const noexcept { return block_[0x10]; }
57
59 [[nodiscard]] int coarse_tune_raw() const noexcept { return block_[0x11]; }
60
62 [[nodiscard]] int coarse_tune_milli_semitones() const noexcept
63 {
64 return (coarse_tune_raw() - 0x40) * 10;
65 }
66
68 [[nodiscard]] int pitch_key_follow() const noexcept { return block_[0x13]; }
69
71 [[nodiscard]] int cutoff_base() const noexcept { return block_[0x2F]; }
72
74 [[nodiscard]] int resonance() const noexcept { return block_[0x30]; }
75
77 [[nodiscard]] int filter_type() const noexcept { return block_[0x31]; }
78
84 [[nodiscard]] int velocity_curve() const noexcept { return block_[0x2E] & 0x0F; }
85
87 [[nodiscard]] int velocity_crossfade_curve() const noexcept { return block_[0x4E] & 0x0F; }
88
90 [[nodiscard]] int velocity_low() const noexcept { return block_[0x4F]; }
91
93 [[nodiscard]] int velocity_high() const noexcept { return block_[0x51]; }
94
96 [[nodiscard]] int level_at_low() const noexcept { return block_[0x50]; }
97
99 [[nodiscard]] int level_at_high() const noexcept { return block_[0x52]; }
100
102 [[nodiscard]] int tva_base_level() const noexcept { return block_[0x53]; }
103
108 [[nodiscard]] std::pair<int, int> velocity_window() const noexcept
109 {
110 return velocity_low() <= velocity_high() ? std::pair{velocity_low(), velocity_high()}
111 : std::pair{velocity_high(), velocity_low()};
112 }
113
115 [[nodiscard]] bool accepts_velocity(int velocity) const noexcept
116 {
117 const auto [low, high] = velocity_window();
118 return velocity >= low && velocity <= high;
119 }
120
127 [[nodiscard]] int transposed_key(int note) const noexcept;
128
130 [[nodiscard]] friend bool operator==(const PartialParameters& left,
131 const PartialParameters& right) noexcept
132 {
133 return left.block_ == right.block_;
134 }
135
136private:
137 [[nodiscard]] int u16(int offset) const noexcept
138 {
139 return block_[offset] | (block_[offset + 1] << 8);
140 }
141
142 const std::uint8_t* block_ = nullptr;
143};
144
145} // namespace ts
int pitch_key_follow() const noexcept
Pitch key-follow amount: 0x40 is 0%, 0x4a is 100%. Block +0x13.
Definition partial_parameters.hpp:68
PartialParameters()=default
An absent partial.
int velocity_curve() const noexcept
Velocity response curve selector for the filter envelope's depth; low nibble only.
Definition partial_parameters.hpp:84
int resonance() const noexcept
TVF resonance, 0x40 neutral. Block +0x30.
Definition partial_parameters.hpp:74
bool is_present() const noexcept
True when this slot holds a real partial.
Definition partial_parameters.hpp:41
int velocity_low() const noexcept
One edge of the velocity window. Block +0x4f.
Definition partial_parameters.hpp:90
bool accepts_velocity(int velocity) const noexcept
True when a velocity falls inside this partial's window.
Definition partial_parameters.hpp:115
std::span< const std::uint8_t > raw() const noexcept
The block's raw bytes.
Definition partial_parameters.hpp:35
int transposed_key(int note) const noexcept
The key handed to the multisample zone lookup, clamped to 0–127.
int cutoff_base() const noexcept
TVF cutoff base, scaled by 0x100 into the runtime domain. Block +0x2f.
Definition partial_parameters.hpp:71
friend bool operator==(const PartialParameters &left, const PartialParameters &right) noexcept
Whether two views refer to the same block.
Definition partial_parameters.hpp:130
int tva_base_level() const noexcept
TVA base level. Block +0x53.
Definition partial_parameters.hpp:102
int multisample() const noexcept
Multisample index, or no_multisample when the slot is empty. Block +0x02.
Definition partial_parameters.hpp:47
int key_transpose() const noexcept
Key transpose in whole semitones, 0x40 neutral. Block +0x10.
Definition partial_parameters.hpp:56
int level_at_high() const noexcept
Partial level at the velocity_high edge. Block +0x52.
Definition partial_parameters.hpp:99
int level_at_low() const noexcept
Partial level at the velocity_low edge. Block +0x50.
Definition partial_parameters.hpp:96
PartialParameters(const std::uint8_t *block) noexcept
Creates a view over a partial block's first byte.
Definition partial_parameters.hpp:32
std::pair< int, int > velocity_window() const noexcept
The velocity window as an ordered range.
Definition partial_parameters.hpp:108
int pan() const noexcept
Per-partial pan, 0x40 centre. Block +0x0f.
Definition partial_parameters.hpp:53
int coarse_tune_milli_semitones() const noexcept
Coarse tune in milli-semitones: (raw - 0x40) * 10. Block +0x11.
Definition partial_parameters.hpp:62
int coarse_tune_raw() const noexcept
Raw coarse-tune byte, 0x40 neutral. Block +0x11.
Definition partial_parameters.hpp:59
static constexpr int no_multisample
Value of multisample meaning the partial is absent.
Definition partial_parameters.hpp:26
static constexpr int stride
Bytes per partial block.
Definition partial_parameters.hpp:23
int velocity_crossfade_curve() const noexcept
Velocity-crossfade curve selector; only the low nibble is used. Block +0x4e.
Definition partial_parameters.hpp:87
int key_center() const noexcept
Key centre — the origin the multisample's key zones are measured from. Block +0x04.
Definition partial_parameters.hpp:50
int velocity_high() const noexcept
The other edge of the velocity window. Block +0x51.
Definition partial_parameters.hpp:93
int filter_type() const noexcept
TVF filter type selector. Block +0x31.
Definition partial_parameters.hpp:77
Definition control_decode.hpp:7