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 "AddTriggerSegmentCommand.h"
20
21 #include "base/Composition.h"
22 #include "base/Segment.h"
23 #include "base/TriggerSegment.h"
24 #include "document/RosegardenDocument.h"
25
26
27 namespace Rosegarden
28 {
29
30 AddTriggerSegmentCommand::AddTriggerSegmentCommand(RosegardenDocument *doc,
31 timeT duration,
32 int basePitch,
33 int baseVelocity) :
34 NamedCommand(tr("Add Triggered Segment")),
35 m_composition(&doc->getComposition()),
36 m_duration(duration),
AddTracksCommand(Composition * composition,unsigned int nbTracks,InstrumentId id,int position)37 m_basePitch(basePitch),
38 m_baseVelocity(baseVelocity),
39 m_id(0),
40 m_segment(nullptr),
41 m_detached(false)
42 {
43 // nothing else
44 }
45
46 AddTriggerSegmentCommand::~AddTriggerSegmentCommand()
47 {
48 if (m_detached)
49 delete m_segment;
50 }
~AddTracksCommand()51
52 TriggerSegmentId
53 AddTriggerSegmentCommand::getId() const
54 {
55 return m_id;
56 }
57
58 void
execute()59 AddTriggerSegmentCommand::execute()
60 {
61 if (m_segment) {
62 m_composition->addTriggerSegment(m_segment, m_id, m_basePitch, m_baseVelocity);
63 } else {
64 m_segment = new Segment();
65 m_segment->setEndMarkerTime(m_duration);
66 TriggerSegmentRec *rec = m_composition->addTriggerSegment
67 (m_segment, m_basePitch, m_baseVelocity);
68 if (rec)
69 m_id = rec->getId();
70 }
71 m_detached = false;
72 }
73
74 void
75 AddTriggerSegmentCommand::unexecute()
76 {
77 if (m_segment)
78 m_composition->detachTriggerSegment(m_id);
79 m_detached = true;
80 }
81
82 }
83