Package: musescore2 / 2.3.2+dfsg4-16

experiments/revert-restriking-patch.diff Patch series | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
Description: Revert the unison restriking patch
 The restriking patch went into 2.2 (and up), 3.x, and master,
 while it is not unquestioned. It was never meant to last; MIDI
 channel assignment to individual voices must be made user-friendly,
 but then, a reversal was intended by upstream. This diff implements
 said reversal, in preparation of those other (UI, mostly) changes.
Author: mirabilos <m@mirbsd.org>
Bug: https://musescore.org/en/node/12971
Forwarded: https://github.com/musescore/MuseScore/pull/3797
 except reversal of commit d5a81add16497f9b4b7fac5717ea005c31dcc1cf

--- a/libmscore/rendermidi.cpp
+++ b/libmscore/rendermidi.cpp
@@ -166,7 +166,7 @@ static void playNote(EventMap* events, c
       NPlayEvent ev(ME_NOTEON, channel, pitch, velo);
       ev.setOriginatingStaff(staffIdx);
       ev.setTuning(note->tuning());
-      ev.setNote(note);
+      ev.notes.push_back(note);
       if (offTime < onTime)
             offTime = onTime;
       events->insert(std::pair<int, NPlayEvent>(onTime, ev));
--- a/mscore/exportaudio.cpp
+++ b/mscore/exportaudio.cpp
@@ -23,8 +23,6 @@
 #include "libmscore/score.h"
 #include "libmscore/note.h"
 #include "libmscore/part.h"
-#include "libmscore/staff.h"
-#include "libmscore/chord.h"
 #include "libmscore/mscore.h"
 #include "synthesizer/msynthesizer.h"
 #include "musescore.h"
@@ -133,35 +131,13 @@ bool MuseScore::saveAudio(Score* score,
 
                       playTime  += n;
                       frames    -= n;
-                      const NPlayEvent& event = playPos->second;
-                      if (event.isChannelEvent()) {
-                              int channelIdx = event.channel();
-                              Channel* c = score->midiMapping(channelIdx)->articulation;
-                              int type = event.type();
-                              int syntiIndex = synti->index(c->synti);
-                              if (type == ME_NOTEON) {
-                                    bool mute;
-                                    const Note* note = event.note();
-                                    if (note) {
-                                          Instrument* instr = note->staff()->part()->instrument(note->chord()->tick());
-                                          const Channel* a = instr->channel(note->subchannel());
-                                          mute = a->mute || a->soloMute;
-                                          }
-                                    else
-                                          mute = false;
-
-                                    if (!mute) {
-                                          if (event.discard()) { // ignore noteoff but restrike noteon
-                                                if (event.velo() > 0)
-                                                      synti->play(NPlayEvent(ME_NOTEON, event.channel(), event.pitch(), 0), syntiIndex);
-                                                else
-                                                      continue;
-                                                }
-                                          synti->play(event, syntiIndex);
-                                          }
-                                    }
-                              else if (type == ME_CONTROLLER || type == ME_PITCHBEND)
-                                    synti->play(event, syntiIndex);
+                      const NPlayEvent& e = playPos->second;
+                      if (e.isChannelEvent()) {
+                            int channelIdx = e.channel();
+                            Channel* c = score->midiMapping(channelIdx)->articulation;
+                            if (!c->mute) {
+                                  synti->play(e, synti->index(c->synti));
+                                  }
                             }
                       }
                 if (frames) {
--- a/mscore/exportmidi.cpp
+++ b/mscore/exportmidi.cpp
@@ -289,18 +289,9 @@ bool ExportMidi::write(const QString& na
                         for (auto i = events.begin(); i != events.end(); ++i) {
                               const NPlayEvent& event = i->second;
 
-                              if (event.discard() == staffIdx + 1 && event.velo() > 0)
-                                    // turn note off so we can restrike it in another track
-                                    track.insert(pauseMap.addPauseTicks(i->first), MidiEvent(ME_NOTEON, channel,
-                                                                     event.pitch(), 0));
-
                               if (event.getOriginatingStaff() != staffIdx)
                                     continue;
 
-                              if (event.discard() && event.velo() == 0)
-                                    // ignore noteoff but restrike noteon
-                                    continue;
-
                               char eventPort    = cs->midiPort(event.channel());
                               char eventChannel = cs->midiChannel(event.channel());
                               if (port != eventPort || channel != eventChannel)
--- a/mscore/musescore.cpp
+++ b/mscore/musescore.cpp
@@ -5661,36 +5661,14 @@ bool MuseScore::saveMp3(Score* score, co
                               playTime  += n;
                               frames    -= n;
                               }
-                        const NPlayEvent& event = playPos->second;
-                        if (event.isChannelEvent()) {
-                              int channelIdx = event.channel();
+                        const NPlayEvent& e = playPos->second;
+                        if (e.isChannelEvent()) {
+                              int channelIdx = e.channel();
                               Channel* c = score->midiMapping(channelIdx)->articulation;
-                              int type = event.type();
-                              int syntiIndex = synti->index(c->synti);
-                              if (type == ME_NOTEON) {
-                                    bool mute;
-                                    const Note* note = event.note();
-                                    if (note) {
-                                          Instrument* instr = note->staff()->part()->instrument(note->chord()->tick());
-                                          const Channel* a = instr->channel(note->subchannel());
-                                          mute = a->mute || a->soloMute;
-                                          }
-                                    else
-                                          mute = false;
-
-                                    if (!mute) {
-                                          if (event.discard()) { // ignore noteoff but restrike noteon
-                                                if (event.velo() > 0)
-                                                      synti->play(NPlayEvent(ME_NOTEON, event.channel(), event.pitch(), 0), syntiIndex);
-                                                else
-                                                      continue;
-                                                }
-                                          synti->play(event, syntiIndex);
-                                          }
+                              if (!c->mute) {
+                                    synti->play(e, synti->index(c->synti));
                                     }
-                              else if (type == ME_CONTROLLER || type == ME_PITCHBEND)
-                                    synti->play(event, syntiIndex);
-                            }
+                              }
                         }
                   if (frames) {
                         float bu[frames * 2];
--- a/mscore/seq.cpp
+++ b/mscore/seq.cpp
@@ -512,8 +512,9 @@ void Seq::playEvent(const NPlayEvent& ev
       int type = event.type();
       if (type == ME_NOTEON) {
             bool mute;
-            const Note* note = event.note();
-            if (note) {
+
+            if (!event.notes.empty()) {
+                  const Note* note = event.notes[0];
                   Instrument* instr = note->staff()->part()->instrument(note->chord()->tick());
                   const Channel* a = instr->channel(note->subchannel());
                   mute = a->mute || a->soloMute;
@@ -521,15 +522,8 @@ void Seq::playEvent(const NPlayEvent& ev
             else
                   mute = false;
 
-            if (!mute) {
-                  if (event.discard()) { // ignore noteoff but restrike noteon
-                        if (event.velo() > 0)
-                              putEvent(NPlayEvent(ME_NOTEON, event.channel(), event.pitch(), 0) ,framePos);
-                        else
-                              return;
-                        }
+            if (!mute)
                   putEvent(event, framePos);
-                  }
             }
       else if (type == ME_CONTROLLER || type == ME_PITCHBEND)
             putEvent(event, framePos);
@@ -1494,20 +1488,18 @@ void Seq::heartBeatTimeout()
                         break;
             const NPlayEvent& n = guiPos->second;
             if (n.type() == ME_NOTEON) {
-                  const Note* note1 = n.note();
-                  if (n.velo()) {
+                  for (auto it = n.notes.cbegin(); it != n.notes.cend(); ++it) {
+                        const Note* note1 = *it;
                         while (note1) {
-                              note1->setMark(true);
-                              markedNotes.append(note1);
-                              r |= note1->canvasBoundingRect();
-                              note1 = note1->tieFor() ? note1->tieFor()->endNote() : 0;
-                              }
-                        }
-                  else {
-                        while (note1) {
-                              note1->setMark(false);
+                              if (n.velo()) {
+                                    note1->setMark(true);
+                                    markedNotes.append(note1);
+                                    }
+                              else {
+                                    note1->setMark(false);
+                                    markedNotes.removeOne(note1);
+                                    }
                               r |= note1->canvasBoundingRect();
-                              markedNotes.removeOne(note1);
                               note1 = note1->tieFor() ? note1->tieFor()->endNote() : 0;
                               }
                         }
--- a/mtest/libmscore/midi/tst_midi.cpp
+++ b/mtest/libmscore/midi/tst_midi.cpp
@@ -378,7 +378,6 @@ void TestMidi::events()
       QTextStream out(&filehandler);
       multimap<int, NPlayEvent> ::iterator iter;
       for (auto iter = events.begin(); iter!= events.end(); ++iter){
-            if (iter->second.discard()) continue;
             out << qSetFieldWidth(5) << "Tick  =  ";
             out << qSetFieldWidth(5) << iter->first;
             out << qSetFieldWidth(5) << "   Type  = ";
--- a/synthesizer/event.cpp
+++ b/synthesizer/event.cpp
@@ -390,28 +390,37 @@ void EventMap::fixupMIDI()
 
       auto it = begin();
       while (it != end()) {
+            bool discard = false;
+
             /* ME_NOTEOFF is never emitted, no need to check for it */
             if (it->second.type() == ME_NOTEON) {
                   unsigned short np = info[it->second.channel()].nowPlaying[it->second.pitch()];
                   if (it->second.velo() == 0) {
                         /* already off (should not happen) or still playing? */
                         if (np == 0 || --np > 0)
-                              it->second.setDiscard(1);
+                              discard = true;
                         else {
                               /* hoist NOTEOFF to same track as NOTEON */
                               it->second.setOriginatingStaff(info[it->second.channel()].event[it->second.pitch()]->getOriginatingStaff());
+                              /* copy linked Notes */
+                              it->second.notes = info[it->second.channel()].event[it->second.pitch()]->notes;
                               }
                         }
-                  else {
-                        if (++np > 1)
-                              /* restrike, possibly on different track */
-                              it->second.setDiscard(info[it->second.channel()].event[it->second.pitch()]->getOriginatingStaff() + 1);
-                        info[it->second.channel()].event[it->second.pitch()] = &(it->second);
+                  else if (++np > 1) {
+                        /* already playing */
+                        discard = true;
+                        /* carry over the corresponding score notes */
+                        info[it->second.channel()].event[it->second.pitch()]->notes.insert(info[it->second.channel()].event[it->second.pitch()]->notes.end(), it->second.notes.begin(), it->second.notes.end());
                         }
+                  else
+                        info[it->second.channel()].event[it->second.pitch()] = &(it->second);
                   info[it->second.channel()].nowPlaying[it->second.pitch()] = np;
                   }
 
-            ++it;
+            if (discard)
+                  it = erase(it);
+            else
+                  ++it;
             }
 
             free((void *)info);
--- a/synthesizer/event.h
+++ b/synthesizer/event.h
@@ -234,9 +234,7 @@ class PlayEvent : public MidiCoreEvent {
 //---------------------------------------------------------
 
 class NPlayEvent : public PlayEvent {
-      const Note* _note = 0;
       int _origin = -1;
-      int _discard = 0;
 
    public:
       NPlayEvent() : PlayEvent() {}
@@ -245,13 +243,10 @@ class NPlayEvent : public PlayEvent {
       NPlayEvent(const MidiCoreEvent& e) : PlayEvent(e) {}
       NPlayEvent(BeatType beatType);
 
-      const Note* note() const       { return _note; }
-      void setNote(const Note* v)    { _note = v; }
+      std::vector<const Note*> notes;
 
       int getOriginatingStaff() const { return _origin; }
       void setOriginatingStaff(int i) { _origin = i; }
-      void setDiscard(int d) { _discard = d; }
-      int discard() const { return _discard; }
       };
 
 //---------------------------------------------------------