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 "SustainInsertionCommand.h"
20 
21 #include "base/Event.h"
22 #include "base/MidiTypes.h"
23 #include "base/Segment.h"
24 #include "document/BasicCommand.h"
25 #include "base/Selection.h"
26 #include <QString>
27 
28 
29 namespace Rosegarden
30 {
31 
32 SustainInsertionCommand::SustainInsertionCommand(Segment &segment, timeT time,
33         bool down,
34         int controllerNumber) :
35         BasicCommand(getGlobalName(down), segment, time, time),
36         m_down(down),
37         m_controllerNumber(controllerNumber),
38         m_lastInsertedEvent(nullptr)
39 {
40     // nothing
41 }
42 
43 SustainInsertionCommand::~SustainInsertionCommand()
44 {
45     // nothing
46 }
47 
48 EventSelection *
49 SustainInsertionCommand::getSubsequentSelection()
50 {
51     EventSelection *selection = new EventSelection(getSegment());
52     selection->addEvent(getLastInsertedEvent());
53     return selection;
54 }
55 
56 void
57 SustainInsertionCommand::modifySegment()
58 {
59     Event *e = new Event(Controller::EventType, getStartTime(), 0,
60                          Controller::EventSubOrdering);
61     e->set
62     <Int>(Controller::NUMBER, m_controllerNumber);
63     e->set
64     <Int>(Controller::VALUE, m_down ? 127 : 0);
65     m_lastInsertedEvent = *getSegment().insert(e);
66 }
67 
68 }
69