PatternModel.hpp
1 #pragma once
2 #include <Process/Process.hpp>
3 
4 #include <Patternist/PatternMetadata.hpp>
5 
6 #include <score_plugin_midi_export.h>
7 
8 #include <verdigris>
9 
10 namespace Patternist
11 {
12 struct Lane
13 {
14  std::vector<bool> pattern;
15  uint8_t note{};
16 
17  bool operator==(const Lane& other) const noexcept
18  {
19  return note == other.note && pattern == other.pattern;
20  }
21 };
22 
23 struct Pattern
24 {
25  int length{16};
26  int division{16};
27  std::vector<Lane> lanes;
28 
29  bool operator==(const Pattern& other) const noexcept
30  {
31  return length == other.length && division == other.division && lanes == other.lanes;
32  }
33 };
34 
35 class SCORE_PLUGIN_MIDI_EXPORT ProcessModel final : public Process::ProcessModel
36 {
37  SCORE_SERIALIZE_FRIENDS
38  W_OBJECT(ProcessModel)
39 
40 public:
41  PROCESS_METADATA_IMPL(Patternist::ProcessModel)
42  explicit ProcessModel(
43  const TimeVal& duration, const Id<Process::ProcessModel>& id, QObject* parent);
44  explicit ProcessModel(
45  const TimeVal& duration, const QString& custom,
46  const Id<Process::ProcessModel>& id, QObject* parent);
47 
48  template <typename Impl>
49  explicit ProcessModel(Impl& vis, QObject* parent)
50  : Process::ProcessModel{vis, parent}
51  {
52  vis.writeTo(*this);
53  init();
54  }
55 
56  void init();
57 
58  ~ProcessModel() override;
59 
60  void setChannel(int n);
61  int channel() const noexcept;
62 
63  void setCurrentPattern(int n);
64  int currentPattern() const noexcept;
65 
66  void setPattern(int n, Pattern p);
67  void setPatterns(const std::vector<Pattern>& n);
68  const std::vector<Pattern>& patterns() const noexcept;
69 
70  std::unique_ptr<Process::MidiOutlet> outlet;
71 
72 public:
73  void channelChanged(int arg_1) W_SIGNAL(channelChanged, arg_1);
74  void currentPatternChanged(int arg_1) W_SIGNAL(currentPatternChanged, arg_1);
75  void execPosition(int arg_1) W_SIGNAL(execPosition, arg_1);
76  void patternsChanged() W_SIGNAL(patternsChanged);
77 
78  PROPERTY(int, channel READ channel WRITE setChannel NOTIFY channelChanged, W_Final)
79  PROPERTY(
80  int,
81  currentPattern READ currentPattern WRITE setCurrentPattern NOTIFY
82  currentPatternChanged,
83  W_Final)
84 private:
85  void setDurationAndScale(const TimeVal& newDuration) noexcept override;
86  void setDurationAndGrow(const TimeVal& newDuration) noexcept override;
87  void setDurationAndShrink(const TimeVal& newDuration) noexcept override;
88 
89  int m_channel{1};
90  int m_currentPattern{};
91  std::vector<Pattern> m_patterns;
92 };
93 }
Definition: PatternModel.hpp:36
The Process class.
Definition: score-lib-process/Process/Process.hpp:61
The id_base_t class.
Definition: Identifier.hpp:57
Definition: PatternModel.hpp:13
Definition: PatternModel.hpp:24
Definition: TimeValue.hpp:21