1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
2 
3 /*
4     Rosegarden
5     A MIDI and audio sequencer and musical notation editor.
6     Copyright 2000-2021 the Rosegarden development team.
7 
8     Other copyrights also apply to some parts of this work.  Please
9     see the AUTHORS file and individual file headers for details.
10 
11     This program is free software; you can redistribute it and/or
12     modify it under the terms of the GNU General Public License as
13     published by the Free Software Foundation; either version 2 of the
14     License, or (at your option) any later version.  See the file
15     COPYING included with this distribution for more information.
16 */
17 
18 #define RG_MODULE_STRING "[MatrixViewSegment]"
19 
20 #include "MatrixViewSegment.h"
21 
22 #include "MatrixScene.h"
23 #include "MatrixElement.h"
24 
25 #include "base/NotationTypes.h"
26 #include "base/SnapGrid.h"
27 #include "base/MidiProgram.h"
28 #include "base/SnapGrid.h"
29 #include "base/SnapGrid.h"
30 
31 #include "misc/Debug.h"
32 
33 namespace Rosegarden
34 {
35 
36 MatrixViewSegment::MatrixViewSegment(MatrixScene *scene,
37 				     Segment *segment,
38                                      bool drum) :
39     ViewSegment(*segment),
40     m_scene(scene),
41     m_drum(drum),
42     m_refreshStatusId(segment->getNewRefreshStatusId())
43 {
44 }
45 
46 MatrixViewSegment::~MatrixViewSegment()
47 {
48 }
49 
50 SegmentRefreshStatus &
51 MatrixViewSegment::getRefreshStatus() const
52 {
53     return m_segment.getRefreshStatus(m_refreshStatusId);
54 }
55 
56 void
57 MatrixViewSegment::resetRefreshStatus()
58 {
59     m_segment.getRefreshStatus(m_refreshStatusId).setNeedsRefresh(false);
60 }
61 
62 bool
63 MatrixViewSegment::wrapEvent(Event* e)
64 {
65     return e->isa(Note::EventType) && ViewSegment::wrapEvent(e);
66 }
67 
68 void
69 MatrixViewSegment::eventAdded(const Segment *segment,
70                               Event *event)
71 {
72     ViewSegment::eventAdded(segment, event);
73     m_scene->handleEventAdded(event);
74 }
75 
76 void
77 MatrixViewSegment::eventRemoved(const Segment *segment,
78                                 Event *event)
79 {
80     // !!! This deletes the associated MatrixElement.
81     ViewSegment::eventRemoved(segment, event);
82 
83     // At this point, the MatrixElement is gone.  See ViewElement::erase().
84     // Any clients that respond to the following and any handlers of
85     // signals emitted by the following must not try to use the MatrixElement.
86     m_scene->handleEventRemoved(event);
87 }
88 
89 ViewElement *
90 MatrixViewSegment::makeViewElement(Event* e)
91 {
92     //RG_DEBUG << "makeViewElement(): event at " << e->getAbsoluteTime();
93 
94     // transpose bits
95     long pitchOffset = getSegment().getTranspose();
96 
97     //RG_DEBUG << "  I am segment \"" << getSegment().getLabel() << "\"";
98 
99     return new MatrixElement(m_scene, e, m_drum, pitchOffset);
100 }
101 
102 void
103 MatrixViewSegment::endMarkerTimeChanged(const Segment *s, bool shorten)
104 {
105     ViewSegment::endMarkerTimeChanged(s, shorten);
106     if (m_scene) m_scene->segmentEndMarkerTimeChanged(s, shorten);
107 }
108 
109 void
110 MatrixViewSegment::updateElements(timeT from, timeT to)
111 {
112     if (!m_viewElementList) return;
113     ViewElementList::iterator i = m_viewElementList->findTime(from);
114     ViewElementList::iterator j = m_viewElementList->findTime(to);
115     while (i != m_viewElementList->end()) {
116         MatrixElement *e = static_cast<MatrixElement *>(*i);
117         e->reconfigure();
118         if (i == j) break;
119         ++i;
120     }
121 }
122 
123 }
124 
125