Merge branch 'rochade' into master
[alioth/musescore.git] / debian / patches / experiments / log-collisions.diff
1 Description: Log unison collisions (that would otherwise be restruck)
2 Author: mirabilos <m@mirbsd.org>
3 Forwarded: not-yet
4 Justification: depends on experiments/revert-restriking-patch.diff
5
6 --- a/synthesizer/event.cpp
7 +++ b/synthesizer/event.cpp
8 @@ -13,6 +13,7 @@
9  #include "libmscore/xml.h"
10  #include "libmscore/note.h"
11  #include "libmscore/sig.h"
12 +#include "libmscore/tie.h"
13  #include "event.h"
14  #include "libmscore/staff.h"
15  #include "libmscore/instrument.h"
16 @@ -396,6 +397,30 @@ void EventList::insert(const Event& e)
17  //   class EventMap::fixupMIDI
18  //---------------------------------------------------------
19  
20 +static void logCollisionNote(const Note* note, unsigned int indent)
21 +      {
22 +      QString info = note->accessibleInfo() + note->accessibleBarbeat();
23 +      fprintf(stderr, " %*s%s\n", indent, "- ", qPrintable(info));
24 +      }
25 +
26 +static void logCollisionNotes(const NPlayEvent* event)
27 +      {
28 +      for (auto it = event->notes.cbegin(); it != event->notes.cend(); ++it) {
29 +            const Note* note1 = *it;
30 +            unsigned int indent = /* initial */ 2;
31 +            while (note1) {
32 +                  logCollisionNote(note1, indent);
33 +                  indent += /* linked */ 4;
34 +                  for (ScoreElement* se : note1->linkList()) {
35 +                        if (se != note1 && se->isNote())
36 +                              logCollisionNote(toNote(se), indent);
37 +                        }
38 +                  indent -= /* linked */ 4 - /* next level */ 2;
39 +                  note1 = note1->tieFor() ? note1->tieFor()->endNote() : 0;
40 +                  }
41 +            }
42 +      }
43 +
44  void EventMap::fixupMIDI()
45        {
46        /* track info for each of the 128 possible MIDI notes */
47 @@ -431,6 +456,12 @@ void EventMap::fixupMIDI()
48                    else if (++np > 1) {
49                          /* already playing */
50                          discard = true;
51 +                        /* log the collision */
52 +                        fprintf(stderr, "MIDI collision detected: newly played...\n");
53 +                        logCollisionNotes(&event);
54 +                        fprintf(stderr, " ... interferes with already playing...\n");
55 +                        logCollisionNotes(info[event.channel()].event[event.pitch()]);
56 +                        fprintf(stderr, " ... which will continue to sound.\n");
57                          /* carry over the corresponding score notes */
58                          info[event.channel()].event[event.pitch()]->notes.insert(info[event.channel()].event[event.pitch()]->notes.end(), event.notes.begin(), event.notes.end());
59                          }