File: spannermap.cpp

package info (click to toggle)
musescore3 3.2.3%2Bdfsg2-19
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 218,192 kB
  • sloc: cpp: 291,369; xml: 200,226; sh: 3,779; ansic: 1,447; python: 393; makefile: 249; perl: 82; pascal: 79
file content (122 lines) | stat: -rw-r--r-- 3,471 bytes parent folder | 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
//=============================================================================
//  MuseScore
//  Music Composition & Notation
//
//  Copyright (C) 2013 Werner Schweer
//
//  This program is free software; you can redistribute it and/or modify
//  it under the terms of the GNU General Public License version 2
//  as published by the Free Software Foundation and appearing in
//  the file LICENCE.GPL
//=============================================================================

#include "spannermap.h"
#include "spanner.h"

namespace Ms {

//---------------------------------------------------------
//   SpannerMap
//---------------------------------------------------------

SpannerMap::SpannerMap()
      : std::multimap<int, Spanner*>()
      {
      dirty = true;
      }

//---------------------------------------------------------
//   update
//   updates the internal lookup tree, not the map itself
//---------------------------------------------------------

void SpannerMap::update() const
      {
      std::vector< ::Interval<Spanner*> > intervals;
      for (auto i : *this)
            intervals.push_back(Interval<Spanner*>(i.second->tick().ticks(), i.second->tick2().ticks(), i.second));
      tree = IntervalTree<Spanner*>(intervals);
      dirty = false;
      }

//---------------------------------------------------------
//   findContained
//---------------------------------------------------------

const std::vector<Interval<Spanner*>>& SpannerMap::findContained(int start, int stop)
      {
      if (dirty)
            update();
      results.clear();
      tree.findContained(start, stop, results);
      return results;
      }

//---------------------------------------------------------
//   findOverlapping
//---------------------------------------------------------

const std::vector<Interval<Spanner*>>& SpannerMap::findOverlapping(int start, int stop)
      {
      if (dirty)
            update();
      results.clear();
      tree.findOverlapping(start, stop, results);
      return results;
      }

//---------------------------------------------------------
//   addSpanner
//---------------------------------------------------------

void SpannerMap::addSpanner(Spanner* s)
      {
#if 0
#ifndef NDEBUG
      // check if spanner already in list
      for (auto i = begin(); i != end(); ++i) {
            if (i->second == s) {
                  qFatal("SpannerMap::addSpanner: %s already in list %p", s->name(), s);
                  }
            }
#endif
#endif
      insert(std::pair<int,Spanner*>(s->tick().ticks(), s));
      dirty = true;
      }

//---------------------------------------------------------
//   removeSpanner
//---------------------------------------------------------

bool SpannerMap::removeSpanner(Spanner* s)
      {
      for (auto i = begin(); i != end(); ++i) {
            if (i->second == s) {
                  erase(i);
                  dirty = true;
                  return true;
                  }
            }
#if 0
      qDebug("%s (%p) not found", s->name(), s);
#endif
      return false;
      }

#ifndef NDEBUG
//---------------------------------------------------------
//   dump
//---------------------------------------------------------

void SpannerMap::dump() const
      {
      qDebug("SpannerMap::dump");
      for (auto i = begin(); i != end(); ++i)
            qDebug("   %5d: %s %p", i->first, i->second->name(), i->second);
      }

#endif

}     // namespace Ms