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
19 #include "MatrixInsertionCommand.h"
20
21 #include "base/Event.h"
22 #include "base/Segment.h"
23 #include "base/SegmentMatrixHelper.h"
24 #include "document/BasicCommand.h"
25 #include "base/BaseProperties.h"
26 #include "misc/Debug.h"
27
28
29 namespace Rosegarden
30 {
31
32 using namespace BaseProperties;
33
MatrixInsertionCommand(Segment & segment,timeT time,timeT endTime,Event * event)34 MatrixInsertionCommand::MatrixInsertionCommand(Segment &segment,
35 timeT time,
36 timeT endTime,
37 Event *event) :
38 BasicCommand(tr("Insert Note"), segment, time, endTime),
39 m_event(new Event(*event,
40 std::min(time, endTime),
41 (time < endTime) ? endTime - time : time - endTime))
42 {
43 // nothing
44 }
45
~MatrixInsertionCommand()46 MatrixInsertionCommand::~MatrixInsertionCommand()
47 {
48 delete m_event;
49 // don't want to delete m_lastInsertedEvent, it's just an alias
50 }
51
modifySegment()52 void MatrixInsertionCommand::modifySegment()
53 {
54 MATRIX_DEBUG << "MatrixInsertionCommand::modifySegment()\n";
55
56 if (!m_event->has(VELOCITY)) {
57 m_event->set
58 <Int>(VELOCITY, 100);
59 }
60
61 SegmentMatrixHelper helper(getSegment());
62 m_lastInsertedEvent = new Event(*m_event);
63 helper.insertNote(m_lastInsertedEvent);
64 }
65
66 }
67