Mark branch 'rochade' as merged
[alioth/musescore.git] / debian / patches / experiments / revert-restriking-patch.diff
index 34a6d60..e268ef8 100644 (file)
@@ -11,7 +11,7 @@ Forwarded: https://github.com/musescore/MuseScore/pull/3797
 
 --- a/libmscore/rendermidi.cpp
 +++ b/libmscore/rendermidi.cpp
 
 --- a/libmscore/rendermidi.cpp
 +++ b/libmscore/rendermidi.cpp
-@@ -166,7 +166,7 @@ static void playNote(EventMap* events, c
+@@ -230,7 +230,7 @@ static void playNote(EventMap* events, c
        NPlayEvent ev(ME_NOTEON, channel, pitch, velo);
        ev.setOriginatingStaff(staffIdx);
        ev.setTuning(note->tuning());
        NPlayEvent ev(ME_NOTEON, channel, pitch, velo);
        ev.setOriginatingStaff(staffIdx);
        ev.setTuning(note->tuning());
@@ -20,66 +20,12 @@ Forwarded: https://github.com/musescore/MuseScore/pull/3797
        if (offTime < onTime)
              offTime = onTime;
        events->insert(std::pair<int, NPlayEvent>(onTime, ev));
        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
 --- 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;
+@@ -295,18 +295,9 @@ bool ExportMidi::write(QIODevice* device
  
  
+                               if (event.isMuted())
+                                     continue;
 -                              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,
 -                              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,
@@ -92,163 +38,123 @@ Forwarded: https://github.com/musescore/MuseScore/pull/3797
 -                                    // ignore noteoff but restrike noteon
 -                                    continue;
 -
 -                                    // ignore noteoff but restrike noteon
 -                                    continue;
 -
-                               char eventPort    = cs->midiPort(event.channel());
-                               char eventChannel = cs->midiChannel(event.channel());
+                               char eventPort    = cs->masterScore()->midiPort(event.channel());
+                               char eventChannel = cs->masterScore()->midiChannel(event.channel());
                                if (port != eventPort || channel != eventChannel)
                                if (port != eventPort || channel != eventChannel)
---- a/mscore/musescore.cpp
-+++ b/mscore/musescore.cpp
-@@ -5662,36 +5662,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
 --- a/mscore/seq.cpp
 +++ b/mscore/seq.cpp
-@@ -512,8 +512,9 @@ void Seq::playEvent(const NPlayEvent& ev
+@@ -552,12 +552,6 @@ void Seq::playEvent(const NPlayEvent& ev
        int type = event.type();
        if (type == ME_NOTEON) {
        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.isMuted()) {
 -                  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 (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);
                    putEvent(event, framePos);
--                  }
+                   }
              }
              }
-       else if (type == ME_CONTROLLER || type == ME_PITCHBEND)
-             putEvent(event, framePos);
-@@ -1494,20 +1488,18 @@ void Seq::heartBeatTimeout()
+@@ -1611,29 +1605,22 @@ void Seq::heartBeatTimeout()
                          break;
              const NPlayEvent& n = guiPos->second;
              if (n.type() == ME_NOTEON) {
 -                  const Note* note1 = n.note();
 -                  if (n.velo()) {
                          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();
+-                        while (note1) {
+-                              for (ScoreElement* se : note1->linkList()) {
+-                                    if (!se->isNote())
+-                                          continue;
+-                                    Note* currentNote = toNote(se);
+-                                    currentNote->setMark(true);
+-                                    markedNotes.append(currentNote);
+-                                    r |= currentNote->canvasBoundingRect();
+-                                    }
 -                              note1 = note1->tieFor() ? note1->tieFor()->endNote() : 0;
 -                              }
 -                        }
 -                  else {
 -                              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);
++                  for (auto it = n.notes.cbegin(); it != n.notes.cend(); ++it) {
++                        const Note* note1 = *it;
+                         while (note1) {
+                               for (ScoreElement* se : note1->linkList()) {
+                                     if (!se->isNote())
+                                           continue;
+                                     Note* currentNote = toNote(se);
+-                                    currentNote->setMark(false);
++                                    if (n.velo()) {
++                                          currentNote->setMark(true);
++                                          markedNotes.append(currentNote);
++                                          }
++                                    else {
++                                          currentNote->setMark(false);
++                                          markedNotes.removeOne(currentNote);
++                                          }
+                                     r |= currentNote->canvasBoundingRect();
+-                                    markedNotes.removeOne(currentNote);
+                                     }
                                note1 = note1->tieFor() ? note1->tieFor()->endNote() : 0;
                                }
                                note1 = note1->tieFor() ? note1->tieFor()->endNote() : 0;
                                }
-                         }
 --- a/mtest/libmscore/midi/tst_midi.cpp
 +++ b/mtest/libmscore/midi/tst_midi.cpp
 --- a/mtest/libmscore/midi/tst_midi.cpp
 +++ b/mtest/libmscore/midi/tst_midi.cpp
-@@ -378,7 +378,6 @@ void TestMidi::events()
+@@ -548,8 +548,6 @@ void TestMidi::events()
        QTextStream out(&filehandler);
        QTextStream out(&filehandler);
-       multimap<int, NPlayEvent> ::iterator iter;
        for (auto iter = events.begin(); iter!= events.end(); ++iter){
        for (auto iter = events.begin(); iter!= events.end(); ++iter){
--            if (iter->second.discard()) continue;
+-            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
              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()
+@@ -172,8 +172,8 @@ NPlayEvent::NPlayEvent(BeatType beatType
+ bool NPlayEvent::isMuted() const
+       {
+-      const Note* n = note();
+-      if (n) {
++      if (!notes.empty()) {
++            const Note* n = notes[0];
+             MasterScore* cs = n->masterScore();
+             Staff* staff = n->staff();
+             Instrument* instr = staff->part()->instrument(n->tick());
+@@ -411,6 +411,8 @@ void EventMap::fixupMIDI()
  
        auto it = begin();
        while (it != end()) {
 +            bool discard = false;
 +
  
        auto it = begin();
        while (it != end()) {
 +            bool discard = false;
 +
+             NPlayEvent& event = it->second;
              /* ME_NOTEOFF is never emitted, no need to check for it */
              /* 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) {
+             if (event.type() == ME_NOTEON && !event.isMuted()) {
+@@ -418,22 +420,30 @@ void EventMap::fixupMIDI()
+                   if (event.velo() == 0) {
                          /* already off (should not happen) or still playing? */
                          if (np == 0 || --np > 0)
                          /* already off (should not happen) or still playing? */
                          if (np == 0 || --np > 0)
--                              it->second.setDiscard(1);
+-                              event.setDiscard(1);
 +                              discard = true;
                          else {
                                /* hoist NOTEOFF to same track as NOTEON */
 +                              discard = true;
                          else {
                                /* hoist NOTEOFF to same track as NOTEON */
-                               it->second.setOriginatingStaff(info[it->second.channel()].event[it->second.pitch()]->getOriginatingStaff());
+                               event.setOriginatingStaff(info[event.channel()].event[event.pitch()]->getOriginatingStaff());
 +                              /* copy linked Notes */
 +                              /* copy linked Notes */
-+                              it->second.notes = info[it->second.channel()].event[it->second.pitch()]->notes;
++                              event.notes = info[event.channel()].event[event.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 */
 +                  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());
++                        info[event.channel()].event[event.pitch()]->notes.insert(info[event.channel()].event[event.pitch()]->notes.end(), event.notes.begin(), event.notes.end());
++                        }
+                   else {
+-                        if (++np > 1)
+-                              /* restrike, possibly on different track */
+-                              event.setDiscard(info[event.channel()].event[event.pitch()]->getOriginatingStaff() + 1);
+                         info[event.channel()].event[event.pitch()] = &event;
                          }
                          }
-+                  else
-+                        info[it->second.channel()].event[it->second.pitch()] = &(it->second);
-                   info[it->second.channel()].nowPlaying[it->second.pitch()] = np;
+                   info[event.channel()].nowPlaying[event.pitch()] = np;
                    }
  
 -            ++it;
                    }
  
 -            ++it;
@@ -261,7 +167,7 @@ Forwarded: https://github.com/musescore/MuseScore/pull/3797
              free((void *)info);
 --- a/synthesizer/event.h
 +++ b/synthesizer/event.h
              free((void *)info);
 --- a/synthesizer/event.h
 +++ b/synthesizer/event.h
-@@ -234,9 +234,7 @@ class PlayEvent : public MidiCoreEvent {
+@@ -236,9 +236,7 @@ class PlayEvent : public MidiCoreEvent {
  //---------------------------------------------------------
  
  class NPlayEvent : public PlayEvent {
  //---------------------------------------------------------
  
  class NPlayEvent : public PlayEvent {
@@ -271,7 +177,7 @@ Forwarded: https://github.com/musescore/MuseScore/pull/3797
  
     public:
        NPlayEvent() : PlayEvent() {}
  
     public:
        NPlayEvent() : PlayEvent() {}
-@@ -245,13 +243,10 @@ class NPlayEvent : public PlayEvent {
+@@ -247,13 +245,10 @@ class NPlayEvent : public PlayEvent {
        NPlayEvent(const MidiCoreEvent& e) : PlayEvent(e) {}
        NPlayEvent(BeatType beatType);
  
        NPlayEvent(const MidiCoreEvent& e) : PlayEvent(e) {}
        NPlayEvent(BeatType beatType);
  
@@ -283,6 +189,6 @@ Forwarded: https://github.com/musescore/MuseScore/pull/3797
        void setOriginatingStaff(int i) { _origin = i; }
 -      void setDiscard(int d) { _discard = d; }
 -      int discard() const { return _discard; }
        void setOriginatingStaff(int i) { _origin = i; }
 -      void setDiscard(int d) { _discard = d; }
 -      int discard() const { return _discard; }
+       bool isMuted() const;
        };
  
        };
  
- //---------------------------------------------------------