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 "InsertTriggerNoteCommand.h"
20 
21 #include "base/Event.h"
22 #include "base/NotationTypes.h"
23 #include "base/Segment.h"
24 #include "base/SegmentNotationHelper.h"
25 #include "base/Composition.h"
26 #include "base/TriggerSegment.h"
27 #include "document/BasicCommand.h"
28 #include "gui/editors/notation/NotationProperties.h"
29 #include "gui/editors/notation/NoteStyleFactory.h"
30 #include "base/BaseProperties.h"
31 #include "misc/Strings.h"
32 
33 namespace Rosegarden
34 {
35 
36 using namespace BaseProperties;
37 
38 InsertTriggerNoteCommand::InsertTriggerNoteCommand(Segment &segment,
39         timeT time,
40         timeT duration,
41         int pitch,
42         int velocity,
43         NoteStyleName noteStyle,
44         TriggerSegmentId id,
45         bool retune,
46         std::string timeAdjust,
47         Mark mark) :
48         BasicCommand(tr("Insert Trigger Note"), segment,
49                      time, time + duration),
50         m_time(time),
51         m_duration(duration),
52         m_pitch(pitch),
53         m_velocity(velocity),
54         m_noteStyle(noteStyle),
55         m_id(id),
56         m_retune(retune),
57         m_timeAdjust(timeAdjust),
58         m_mark(mark)
59 {
60     // nothing
61 }
62 
63 InsertTriggerNoteCommand::~InsertTriggerNoteCommand()
64 {
65     // nothing
66 }
67 
68 void
69 InsertTriggerNoteCommand::modifySegment()
70 {
71     // Insert via a model event, so as to apply the note style.
72     // This is a subset of the work done by NoteInsertionCommand
73 
74     Event *e = new Event(Note::EventType, m_time, m_duration);
75 
setProgressDialog(QPointer<QProgressDialog> progressDialog)76     // Could
77     e->set<Int>(PITCH, m_pitch);
setProgressTotal(int total,int perCall)78     e->set<Int>(VELOCITY, m_velocity);
79     e->set<Bool>(TRIGGER_EXPAND, true);
80 
81     if (m_noteStyle != NoteStyleFactory::DefaultStyle) {
82         e->set<String>(NotationProperties::NOTE_STYLE, qstrtostr(m_noteStyle));
83     }
84 
85     Segment &s(getSegment());
86     Segment::iterator i = s.insert(e);
87     SegmentNotationHelper(s).makeThisNoteViable(i);
88     s.normalizeRests(m_time, m_time + m_duration);
89 
90     // Add these properties only after the note is possibly
91     // split-and-tied.
92     e->set<Int>(TRIGGER_SEGMENT_ID, m_id);
93     e->set<Bool>(TRIGGER_SEGMENT_RETUNE, m_retune);
94     e->set<String>(TRIGGER_SEGMENT_ADJUST_TIMES, m_timeAdjust);
95 
96     if (m_mark != Marks::NoMark) {
97         Marks::addMark(*e, m_mark, true);
98     }
99 
100 
101     TriggerSegmentRec *rec =
102         s.getComposition()->getTriggerSegmentRec(m_id);
103 
104     if (rec)
105         rec->updateReferences();
106 }
107 
108 }
109