2#include <Process/Process.hpp>
4#include <Patternist/PatternMetadata.hpp>
6#include <score_plugin_midi_export.h>
18enum class Note : uint8_t
26Q_DECLARE_METATYPE(Patternist::Note)
27W_REGISTER_ARGTYPE(Patternist::Note)
33enum class Condition : uint8_t
77 Condition condition{Condition::Always};
81 bool operator==(
const StepParams&)
const noexcept =
default;
82 bool isDefault() const noexcept {
return *
this == StepParams{}; }
87inline bool euclidHit(
int i,
int steps,
int pulses,
int rotation)
noexcept
89 if(steps <= 0 || pulses <= 0)
93 const int j = (((i - rotation) % steps) + steps) % steps;
94 return (j * pulses) % steps < pulses;
99 std::vector<Patternist::Note> pattern;
121 uint8_t randomPerHit{};
123 bool operator==(
const Lane& other)
const noexcept =
default;
131inline constexpr uint8_t accentLane = 255;
132inline constexpr uint8_t slideLane = 254;
133inline bool isControlLane(
const Lane& l)
noexcept
135 return l.note == accentLane || l.note == slideLane;
140 static const constexpr int maxLength = 128;
141 static const constexpr int maxLanes = 128;
147 std::vector<Lane> lanes;
149 bool operator==(
const Pattern& other)
const noexcept
151 return length == other.length && division == other.division && lanes == other.lanes;
158SCORE_PLUGIN_MIDI_TEST_EXPORT
void normalize(Pattern& p)
noexcept;
160inline bool anySolo(
const Pattern& p)
noexcept
162 for(
const Lane& l : p.lanes)
168inline int laneLength(
const Pattern& p,
const Lane& l)
noexcept
170 return l.length > 0 ? l.length : p.length;
173inline int laneDivision(
const Pattern& p,
const Lane& l)
noexcept
175 return l.division > 0 ? l.division : p.division;
179inline Note writtenNote(
const Pattern& p,
const Lane& l,
int step)
noexcept
181 return (step >= 0 && step <
int(l.pattern.size())) ? l.pattern[step] : Note::Rest;
184inline const StepParams& stepParams(
const Lane& l,
int step)
noexcept
186 static const StepParams defaults;
187 return (step >= 0 && step <
int(l.params.size())) ? l.params[step] : defaults;
193inline bool tieStrikes(
const Pattern& p,
const Lane& l,
int step)
noexcept
195 const int len = laneLength(p, l);
198 const int prev = ((step - 1) % len + len) % len;
199 if(writtenNote(p, l, prev) == Note::Rest)
201 const StepParams& sp = stepParams(l, step);
202 const StepParams& pp = stepParams(l, prev);
204 = !(l.randomPerHit & Lane::PitchPerHit) && (sp.pitchRandom > 0 || pp.pitchRandom > 0);
205 return sp.ratchet > 1 || sp.pitch != pp.pitch || spread;
210inline int struckStep(
const Pattern& p,
const Lane& l,
int step)
noexcept
212 const int len = laneLength(p, l);
213 for(
int k = 0; k < len; k++)
215 if(writtenNote(p, l, step) != Note::Legato || tieStrikes(p, l, step))
217 step = ((step - 1) % len + len) % len;
223inline Note audibleNote(
const Pattern& p,
const Lane& l,
int step,
bool anySolo)
noexcept
225 if(l.mute || (anySolo && !l.solo))
227 return writtenNote(p, l, step);
231enum class LaneLabels : uint8_t
240Q_DECLARE_METATYPE(Patternist::LaneLabels)
241W_REGISTER_ARGTYPE(Patternist::LaneLabels)
248 SCORE_SERIALIZE_FRIENDS
253 static const constexpr int maxPatterns = 128;
259 const TimeVal& duration,
const QString& custom,
262 template <
typename Impl>
276 void setChannel(
int n);
277 int channel() const noexcept;
279 void setCurrentPattern(
int n);
280 int currentPattern() const noexcept;
282 void setLaneLabels(LaneLabels l);
283 LaneLabels laneLabels() const noexcept;
287 const
std::vector<int64_t>& execSteps() const noexcept {
return m_execSteps; }
288 void setExecSteps(std::vector<int64_t> s) { m_execSteps = std::move(s); }
290 void setPattern(
int n, Pattern p);
291 void setPatterns(
const std::vector<Pattern>& n);
292 const std::vector<Pattern>& patterns() const noexcept;
297 void loadPreset(const
Process::Preset& preset) override;
298 Process::Preset savePreset() const noexcept override;
300 std::unique_ptr<
Process::ControlInlet> patternSelect;
301 std::unique_ptr<
Process::ControlInlet> switchQuantification;
321 void channelChanged(
int arg_1) W_SIGNAL(channelChanged, arg_1);
322 void currentPatternChanged(
int arg_1) W_SIGNAL(currentPatternChanged, arg_1);
324 void execStepsChanged() W_SIGNAL(execStepsChanged);
327 void execPattern(
int current,
int pending) W_SIGNAL(execPattern, current, pending);
328 void patternsChanged() W_SIGNAL(patternsChanged);
329 void laneLabelsChanged(LaneLabels arg_1) W_SIGNAL(laneLabelsChanged, arg_1);
331 void timeGridChanged() W_SIGNAL(timeGridChanged);
333 PROPERTY(
int, channel READ channel WRITE setChannel NOTIFY channelChanged, W_Final)
336 currentPattern READ currentPattern WRITE setCurrentPattern NOTIFY
337 currentPatternChanged,
341 laneLabels READ laneLabels WRITE setLaneLabels NOTIFY laneLabelsChanged, W_Final)
343 void ancestorStartDateChanged() override;
344 void ancestorTempoChanged() override;
345 void setDurationAndScale(const
TimeVal& newDuration) noexcept override;
346 void setDurationAndGrow(const
TimeVal& newDuration) noexcept override;
347 void setDurationAndShrink(const
TimeVal& newDuration) noexcept override;
350 int m_currentPattern{};
351 LaneLabels m_laneLabels{LaneLabels::NameAndNumber};
352 std::vector<int64_t> m_execSteps;
354 std::vector<bool> m_grown;
355 std::vector<Pattern> m_patterns;
Definition PatternModel.hpp:247
The Process class.
Definition score-lib-process/Process/Process.hpp:82
The id_base_t class.
Definition Identifier.hpp:59
Base classes and tools to implement processes and layers.
Definition JSONVisitor.hpp:1115
Definition PatternModel.hpp:98
std::vector< StepParams > params
Same size as pattern.
Definition PatternModel.hpp:111
uint8_t note
A MIDI note, or accentLane or slideLane.
Definition PatternModel.hpp:101
RandomPerHit
Definition PatternModel.hpp:115
int division
Steps per whole note; 0 follows the pattern.
Definition PatternModel.hpp:107
int length
Steps before the lane loops; 0 follows the pattern.
Definition PatternModel.hpp:105
float velocity
0 - 1.
Definition PatternModel.hpp:109
Definition PatternModel.hpp:139
static const constexpr int maxDivision
Steps per whole note, at most.
Definition PatternModel.hpp:143
Definition PatternModel.hpp:49
float chance
0 - 1, scaled by the Density input.
Definition PatternModel.hpp:56
uint8_t ratchet
Notes played within the step, 1 - 8.
Definition PatternModel.hpp:68
float gate
0 - 1 of a step; a tie, or 1, holds the note until the next step.
Definition PatternModel.hpp:63
float pace
Definition PatternModel.hpp:71
int8_t pitch
Semitones added to the lane's note.
Definition PatternModel.hpp:73
float gateRandom
Definition PatternModel.hpp:66
uint8_t pitchRandom
Definition PatternModel.hpp:76
float velocity
0 - 1, scaled by the lane's velocity and the Velocity input.
Definition PatternModel.hpp:51
float velocityRandom
Definition PatternModel.hpp:54
float offsetRandom
Definition PatternModel.hpp:61
float offset
-0.5 - 0.5 of a step: early or late.
Definition PatternModel.hpp:58
Definition TimeValue.hpp:21