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 "SetTriggerSegmentBaseVelocityCommand.h"
20 
21 #include "base/Composition.h"
22 #include "base/TriggerSegment.h"
23 
24 
25 namespace Rosegarden
26 {
27 
28 SetTriggerSegmentBaseVelocityCommand::SetTriggerSegmentBaseVelocityCommand(Composition *composition,
29         TriggerSegmentId id,
30         int newVelocity) :
31         NamedCommand(tr("Set Base Velocity")),
32         m_composition(composition),
33         m_id(id),
34         m_newVelocity(newVelocity),
35         m_oldVelocity( -1)
36 {
37     // nothing
38 }
39 
40 SetTriggerSegmentBaseVelocityCommand::~SetTriggerSegmentBaseVelocityCommand()
41 {
42     // nothing
43 }
44 
45 void
46 SetTriggerSegmentBaseVelocityCommand::execute()
47 {
48     TriggerSegmentRec *rec = m_composition->getTriggerSegmentRec(m_id);
49     if (!rec)
50         return ;
51     if (m_oldVelocity == -1) {
52         m_oldVelocity = rec->getBaseVelocity();
53     }
54     rec->setBaseVelocity(m_newVelocity);
55 }
56 
57 void
58 SetTriggerSegmentBaseVelocityCommand::unexecute()
59 {
60     TriggerSegmentRec *rec = m_composition->getTriggerSegmentRec(m_id);
61     if (!rec)
62         return ;
63     rec->setBaseVelocity(m_oldVelocity);
64 }
65 
66 }
67