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 "RestInsertionCommand.h"
20 
21 #include "base/Event.h"
22 #include "base/NotationTypes.h"
23 #include "base/Segment.h"
24 #include "base/SegmentNotationHelper.h"
25 #include "document/BasicCommand.h"
26 #include "gui/editors/notation/NoteStyleFactory.h"
27 #include "NoteInsertionCommand.h"
28 
29 
30 namespace Rosegarden
31 {
32 
RestInsertionCommand(Segment & segment,timeT time,timeT endTime,Note note)33 RestInsertionCommand::RestInsertionCommand(Segment &segment, timeT time,
34                                            timeT endTime, Note note) :
35     NoteInsertionCommand(segment, time, endTime, note, 0,
36                          Accidentals::NoAccidental,
37                          AutoBeamOff, AutoTieBarlinesOn, MatrixModeOff, GraceModeOff, 0,
38                          NoteStyleFactory::DefaultStyle)
39 {
40     setName("Insert Rest");
41 }
42 
~RestInsertionCommand()43 RestInsertionCommand::~RestInsertionCommand()
44 {
45     // nothing
46 }
47 
48 void
modifySegment()49 RestInsertionCommand::modifySegment()
50 {
51     SegmentNotationHelper helper(getSegment());
52 
53     Segment::iterator i = helper.insertRest(m_insertionTime, m_note);
54     if (i != helper.segment().end())
55         m_lastInsertedEvent = *i;
56 
57     if (m_autoTieBarlines) {
58 
59         // Note: if m_lastInsertedEvent is null then no note was inserted
60         if (m_lastInsertedEvent) {
61 
62             // Do the split
63             m_lastInsertedEvent = helper.makeThisNoteViable(i);
64         }
65     }
66 
67 }
68 
69 }
70