MuseScore  3.4
Music composition and notation
importmidi_inner.h
Go to the documentation of this file.
1 #ifndef IMPORTMIDI_INNER_H
2 #define IMPORTMIDI_INNER_H
3 
4 #include "importmidi_chord.h"
5 #include "importmidi_fraction.h"
6 #include "importmidi_tuplet.h"
7 #include "importmidi_operation.h"
8 
9 #include <vector>
10 #include <cstddef>
11 #include <utility>
12 
13 // ---------------------------------------------------------------------------------------
14 // These inner classes definitions are used in cpp files only
15 // Include this header to link tests
16 // ---------------------------------------------------------------------------------------
17 
18 
19 namespace Ms {
20 
21 enum class Key;
22 struct MidiTimeSig;
23 
24 namespace Meter {
25 
26  // max level for tuplets: duration cannot go over the tuplet boundary
27  // this level should be greater than any other level
28 const int TUPLET_BOUNDARY_LEVEL = 10;
29 
30 struct MaxLevel
31  {
32  int level = 0; // 0 - the biggest, whole bar level; other: -1, -2, ...
33  int levelCount = 0; // number of positions with 'level' value
34  ReducedFraction pos = {-1, 1}; // first position with value 'level'; -1 - undefined pos
35  };
36 
38  {
40  int level;
41  };
42 
44  {
45  ReducedFraction onTime; // division start tick (tick is counted from the beginning of bar)
46  ReducedFraction len; // length of this whole division
47  bool isTuplet = false;
48  std::vector<DivLengthInfo> divLengths; // lengths of 'len' subdivisions
49  };
50 
51 enum class DurationType : char;
52 
54  MidiOperations::TimeSigNumerator timeSigNumerator,
55  MidiOperations::TimeSigDenominator timeSigDenominator);
58 
59 } // namespace Meter
60 
61 class Staff;
62 class Score;
63 class MidiTrack;
64 class DurationElement;
65 class MidiChord;
66 class MidiEvent;
67 class TDuration;
68 class Measure;
69 class KeyList;
70 
71 class MTrack {
72  public: // chords store tuplet iterators, so we need to copy class explicitly
73  MTrack();
74  MTrack(const MTrack &other);
75  MTrack& operator=(MTrack other);
76 
77  int program;
79  const MidiTrack* mtrack;
80  QString name;
81  bool hasKey;
83  int division;
84  bool isDivisionInTps; // ticks per second
86 
87  std::multimap<ReducedFraction, int> volumes;
88  std::multimap<ReducedFraction, MidiChord> chords;
89  std::multimap<ReducedFraction, MidiTuplet::TupletData> tuplets; // <tupletOnTime, ...>
90 
91  void createNotes(const ReducedFraction &lastTick);
92  void processPendingNotes(QList<MidiChord>& midiChords,
93  int voice,
94  const ReducedFraction &startChordTickFrac,
95  const ReducedFraction &nextChordTick);
96  void processMeta(int tick, const MidiEvent& mm);
97  void fillGapWithRests(Score *score, int voice, const ReducedFraction &startChordTickFrac,
98  const ReducedFraction &restLength, int track);
99  QList<std::pair<ReducedFraction, TDuration> >
100  toDurationList(const Measure *measure, int voice, const ReducedFraction &startTick,
101  const ReducedFraction &len, Meter::DurationType durationType);
102  void createKeys(Key defaultKey, const Ms::KeyList &allKeyList);
103  void updateTupletsFromChords();
104 
105  private:
106  void updateTuplet(std::multimap<ReducedFraction, MidiTuplet::TupletData>::iterator &);
107  };
108 
109 namespace MidiTuplet {
110 
112  {
113  int id;
114  ReducedFraction onTime = {-1, 1}; // invalid
115  ReducedFraction len = {-1, 1};
116  int tupletNumber = -1;
117  // <chord onTime, chord iterator>
118  std::map<ReducedFraction, std::multimap<ReducedFraction, MidiChord>::iterator> chords;
122  int firstChordIndex = -1;
123  std::map<ReducedFraction, int> staccatoChords; // <onTime, note index>
124  };
125 
126 bool haveIntersection(const std::pair<ReducedFraction, ReducedFraction> &interval1,
127  const std::pair<ReducedFraction, ReducedFraction> &interval2,
128  bool strictComparison = true);
129 bool haveIntersection(const std::pair<ReducedFraction, ReducedFraction> &interval,
130  const std::vector<std::pair<ReducedFraction, ReducedFraction>> &intervals,
131  bool strictComparison = true);
132 
133 } // namespace MidiTuplet
134 
135 namespace MidiCharset {
136 
137 QString convertToCharset(const std::string &text);
138 QString defaultCharset();
139 std::string fromUchar(const uchar *text);
140 
141 } // namespace MidiCharset
142 
143 namespace MidiBar {
144 
145 ReducedFraction findBarStart(const ReducedFraction &time, const TimeSigMap *sigmap);
146 
147 } // namespace MidiBar
148 
149 namespace MidiDuration {
150 
151 double durationCount(const QList<std::pair<ReducedFraction, TDuration> > &durations);
152 
153 } // namespace MidiDuration
154 } // namespace Ms
155 
156 
157 #endif // IMPORTMIDI_INNER_H
DurationType
Definition: importmidi_meter.h:16
const MidiTrack * mtrack
Definition: importmidi_inner.h:79
Definition: durationtype.h:28
Global staff data not directly related to drawing.
Definition: staff.h:62
bool hadInitialNotes
Definition: importmidi_inner.h:85
int program
Definition: importmidi_inner.h:77
Key
Definition: key.h:28
std::multimap< ReducedFraction, int > volumes
Definition: importmidi_inner.h:87
std::multimap< ReducedFraction, MidiTuplet::TupletData > tuplets
Definition: importmidi_inner.h:89
Definition: importmidi_chord.h:31
one measure in a system
Definition: measure.h:65
bool haveIntersection(const std::pair< ReducedFraction, ReducedFraction > &interval1, const std::pair< ReducedFraction, ReducedFraction > &interval2, bool strictComparison)
Definition: importmidi_inner.cpp:210
QString convertToCharset(const std::string &text)
Definition: importmidi_inner.cpp:235
Staff * staff
Definition: importmidi_inner.h:78
Definition: importmidi_inner.h:43
MidiOperations::TimeSigNumerator fractionNumeratorToUserValue(int n)
Definition: importmidi_inner.cpp:156
Definition: midifile.h:38
ReducedFraction sumLengthOfRests
Definition: importmidi_inner.h:121
int indexOfOperation
Definition: importmidi_inner.h:82
ReducedFraction regularSumError
Definition: importmidi_inner.h:120
void createKeys(QList< MTrack > &tracks)
Definition: importmidi.cpp:983
std::map< ReducedFraction, std::multimap< ReducedFraction, MidiChord >::iterator > chords
Definition: importmidi_inner.h:118
Definition: score.h:391
Definition: keylist.h:28
bool isDivisionInTps
Definition: importmidi_inner.h:84
Definition: importmidi_inner.h:37
ReducedFraction tupletSumError
Definition: importmidi_inner.h:119
ReducedFraction len
Definition: importmidi_inner.h:46
Definition: importmidi_inner.h:111
std::vector< DivLengthInfo > divLengths
Definition: importmidi_inner.h:48
int levelCount
Definition: importmidi_inner.h:33
ReducedFraction len
Definition: importmidi_inner.h:39
Definition: aeolus.cpp:26
int division
Definition: importmidi_inner.h:83
ReducedFraction pos
Definition: importmidi_inner.h:34
int level
Definition: importmidi_inner.h:32
TimeSigNumerator
Definition: importmidi_operation.h:38
Definition: importmidi_inner.h:30
QList< std::pair< ReducedFraction, TDuration > > toDurationList(const ReducedFraction &startTickInBar, const ReducedFraction &endTickInBar, const ReducedFraction &barFraction, const std::vector< MidiTuplet::TupletData > &tupletsInBar, DurationType durationType, bool useDots, bool printRestRemains)
Definition: importmidi_meter.cpp:472
Virtual base class for Chord, Rest and Tuplet.
Definition: duration.h:34
void createNotes(const ReducedFraction &lastTick, QList< MTrack > &tracks)
Definition: importmidi.cpp:948
ReducedFraction onTime
Definition: importmidi_inner.h:45
QString defaultCharset()
Definition: importmidi_inner.cpp:246
bool hasKey
Definition: importmidi_inner.h:81
double durationCount(const QList< std::pair< ReducedFraction, TDuration > > &durations)
Definition: importmidi_inner.cpp:270
std::string fromUchar(const uchar *text)
Definition: importmidi_inner.cpp:251
int level
Definition: importmidi_inner.h:40
Definition: importmidi_inner.h:71
TimeSigDenominator
Definition: importmidi_operation.h:51
ReducedFraction findBarStart(const ReducedFraction &time, const TimeSigMap *sigmap)
Definition: importmidi_inner.cpp:260
Definition: importmidi_fraction.h:9
ReducedFraction userTimeSigToFraction(MidiOperations::TimeSigNumerator timeSigNumerator, MidiOperations::TimeSigDenominator timeSigDenominator)
Definition: importmidi_inner.cpp:91
Definition: event.h:194
int id
Definition: importmidi_inner.h:113
std::map< ReducedFraction, int > staccatoChords
Definition: importmidi_inner.h:123
std::multimap< ReducedFraction, MidiChord > chords
Definition: importmidi_inner.h:88
MidiOperations::TimeSigDenominator fractionDenominatorToUserValue(int z)
Definition: importmidi_inner.cpp:186
const int TUPLET_BOUNDARY_LEVEL
Definition: importmidi_inner.h:28
Definition: sig.h:127
void processMeta(MTrack &mt, bool isLyric)
Definition: importmidi.cpp:924
QString name
Definition: importmidi_inner.h:80