MuseScore  3.4
Music composition and notation
rendermidi.h
Go to the documentation of this file.
1 //=============================================================================
2 // MuseScore
3 // Music Composition & Notation
4 //
5 // Copyright (C) 2019 Werner Schweer and others
6 //
7 // This program is free software; you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License version 2.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 //=============================================================================
19 
20 #ifndef __RENDERMIDI_H__
21 #define __RENDERMIDI_H__
22 
23 #include "fraction.h"
24 #include "measure.h"
25 
26 namespace Ms {
27 
28 class EventMap;
29 class MasterScore;
30 class Staff;
31 class SynthesizerState;
32 
33 enum class DynamicsRenderMethod : signed char {
34  FIXED_MAX,
35  SEG_START,
36  SIMPLE
37  };
38 
39 //---------------------------------------------------------
40 // RangeMap
43 //---------------------------------------------------------
44 
45 class RangeMap {
46  enum class Range { BEGIN, END };
47  std::map<int, Range> status;
48 
49  public:
50  void setOccupied(int tick1, int tick2);
51  void setOccupied(std::pair<int, int> range) { setOccupied(range.first, range.second); }
52 
53  int occupiedRangeEnd(int tick) const;
54 
55  void clear() { status.clear(); }
56  };
57 
58 //---------------------------------------------------------
59 // MidiRenderer
61 //---------------------------------------------------------
62 
63 class MidiRenderer {
65  bool needUpdate = true;
66  int minChunkSize = 0;
67 
68  public:
69  class Chunk {
73 
74  public:
75  Chunk(int tickOffset, Measure* fst, Measure* lst)
76  : _tickOffset(tickOffset), first(fst), last(lst) {}
77 
78  Chunk() // "invalid chunk" constructor
79  : _tickOffset(0), first(nullptr), last(nullptr) {}
80 
81  operator bool() const { return bool(first); }
82  int tickOffset() const { return _tickOffset; }
83  Measure* startMeasure() const { return first; }
84  Measure* endMeasure() const { return last ? last->nextMeasure() : nullptr; }
85  Measure* lastMeasure() const { return last; }
86  int tick1() const { return first->tick().ticks(); }
87  int tick2() const { return last ? last->endTick().ticks() : tick1(); }
88  int utick1() const { return tick1() + tickOffset(); }
89  int utick2() const { return tick2() + tickOffset(); }
90  };
91 
92  private:
93  std::vector<Chunk> chunks;
94 
95  void updateChunksPartition();
96  static bool canBreakChunk(const Measure* last);
97  void updateState();
98 
99  void renderStaffChunk(const Chunk&, EventMap* events, Staff*, DynamicsRenderMethod method, int cc);
100  void renderSpanners(const Chunk&, EventMap* events);
101  void renderMetronome(const Chunk&, EventMap* events);
102  void renderMetronome(EventMap* events, Measure* m, const Fraction& tickOffset);
103 
104  public:
105  explicit MidiRenderer(Score* s) : score(s) {}
106 
107  void renderScore(EventMap* events, const SynthesizerState& synthState, bool metronome = true);
108  void renderChunk(const Chunk&, EventMap* events, const SynthesizerState& synthState, bool metronome = true);
109 
110  void setScoreChanged() { needUpdate = true; }
111  void setMinChunkSize(int sizeMeasures) { minChunkSize = sizeMeasures; needUpdate = true; }
112 
113  Chunk getChunkAt(int utick);
114  };
115 
116 } // namespace Ms
117 
118 #endif
void clear()
Definition: rendermidi.h:55
Global staff data not directly related to drawing.
Definition: staff.h:62
int tick1() const
Definition: rendermidi.h:86
Chunk(int tickOffset, Measure *fst, Measure *lst)
Definition: rendermidi.h:75
Measure * lastMeasure() const
Definition: rendermidi.h:85
Range
Definition: rendermidi.h:46
one measure in a system
Definition: measure.h:65
MidiRenderer(Score *s)
Definition: rendermidi.h:105
std::vector< Chunk > chunks
Definition: rendermidi.h:93
Score * score
Definition: rendermidi.h:64
Helper class to keep track of status of status of certain parts of score or MIDI representation.
Definition: rendermidi.h:45
int tickOffset() const
Definition: rendermidi.h:82
Definition: score.h:391
Definition: synthesizerstate.h:55
DynamicsRenderMethod
Definition: rendermidi.h:33
Fraction endTick() const
Definition: measurebase.h:128
Measure * startMeasure() const
Definition: rendermidi.h:83
int utick2() const
Definition: rendermidi.h:89
Chunk()
Definition: rendermidi.h:78
Definition of class Measure.
Definition: aeolus.cpp:26
MIDI renderer for a score.
Definition: rendermidi.h:63
int utick1() const
Definition: rendermidi.h:88
void setMinChunkSize(int sizeMeasures)
Definition: rendermidi.h:111
int ticks() const
Definition: fraction.h:228
void setOccupied(std::pair< int, int > range)
Definition: rendermidi.h:51
Definition: rendermidi.h:69
Measure * first
Definition: rendermidi.h:71
Measure * last
Definition: rendermidi.h:72
Fraction tick() const
Definition: measurebase.h:122
Definition: fraction.h:46
Ms::Measure * nextMeasure() const
Definition: measurebase.cpp:198
Definition: event.h:325
int _tickOffset
Definition: rendermidi.h:70
Measure * endMeasure() const
Definition: rendermidi.h:84
int tick2() const
Definition: rendermidi.h:87
std::map< int, Range > status
Definition: rendermidi.h:47
void setScoreChanged()
Definition: rendermidi.h:110